blob: 8ab560c95c6aaebd473ba592239a18f72a95f59e [file] [log] [blame]
Patrik Höglund3e113432017-12-15 14:40:10 +01001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_RTP_HEADERS_H_
12#define API_RTP_HEADERS_H_
13
14#include <stddef.h>
Yves Gerey988cc082018-10-23 12:03:01 +020015#include <stdint.h>
Patrik Höglund3e113432017-12-15 14:40:10 +010016#include <string.h>
Patrik Höglund3e113432017-12-15 14:40:10 +010017
Johannes Kronad1d9f02018-11-09 11:12:36 +010018#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010019#include "api/array_view.h"
Johannes Kron09d65882018-11-27 14:36:41 +010020#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010021#include "api/video/video_content_type.h"
Johnny Leee0c8b232018-09-11 16:50:49 -040022#include "api/video/video_frame_marking.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010023#include "api/video/video_rotation.h"
24#include "api/video/video_timing.h"
Yves Gerey665174f2018-06-19 15:03:05 +020025#include "common_types.h" // NOLINT(build/include)
Patrik Höglund3e113432017-12-15 14:40:10 +010026
27namespace webrtc {
28
29// Class to represent the value of RTP header extensions that are
30// variable-length strings (e.g., RtpStreamId and RtpMid).
31// Unlike std::string, it can be copied with memcpy and cleared with memset.
32//
33// Empty value represents unset header extension (use empty() to query).
34class StringRtpHeaderExtension {
35 public:
36 // String RTP header extensions are limited to 16 bytes because it is the
37 // maximum length that can be encoded with one-byte header extensions.
38 static constexpr size_t kMaxSize = 16;
39
Joachim Bauchd3b7ec22018-08-01 10:12:00 +020040 static bool IsLegalMidName(rtc::ArrayView<const char> name);
41 static bool IsLegalRsidName(rtc::ArrayView<const char> name);
42
43 // TODO(bugs.webrtc.org/9537): Deprecate and remove when third parties have
44 // migrated to "IsLegalRsidName".
45 static bool IsLegalName(rtc::ArrayView<const char> name) {
46 return IsLegalRsidName(name);
47 }
Patrik Höglund3e113432017-12-15 14:40:10 +010048
49 StringRtpHeaderExtension() { value_[0] = 0; }
50 explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
51 Set(value.data(), value.size());
52 }
53 StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
54 StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
55 default;
56
57 bool empty() const { return value_[0] == 0; }
58 const char* data() const { return value_; }
59 size_t size() const { return strnlen(value_, kMaxSize); }
60
61 void Set(rtc::ArrayView<const uint8_t> value) {
62 Set(reinterpret_cast<const char*>(value.data()), value.size());
63 }
64 void Set(const char* data, size_t size);
65
66 friend bool operator==(const StringRtpHeaderExtension& lhs,
67 const StringRtpHeaderExtension& rhs) {
68 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
69 }
70 friend bool operator!=(const StringRtpHeaderExtension& lhs,
71 const StringRtpHeaderExtension& rhs) {
72 return !(lhs == rhs);
73 }
74
75 private:
76 char value_[kMaxSize];
77};
78
79// StreamId represents RtpStreamId which is a string.
80typedef StringRtpHeaderExtension StreamId;
81
82// Mid represents RtpMid which is a string.
83typedef StringRtpHeaderExtension Mid;
84
Johannes Kron075f6872019-02-14 14:41:05 +010085struct FeedbackRequest {
86 // Determines whether the recv delta as specified in
87 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
88 // should be included.
89 bool include_timestamps;
90 // Include feedback of received packets in the range [sequence_number -
Johannes Kron0da25a12019-03-06 09:34:13 +010091 // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
92 // sequence_count is zero.
Johannes Kron075f6872019-02-14 14:41:05 +010093 int sequence_count;
94};
95
Patrik Höglund3e113432017-12-15 14:40:10 +010096struct RTPHeaderExtension {
97 RTPHeaderExtension();
98 RTPHeaderExtension(const RTPHeaderExtension& other);
99 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
100
101 bool hasTransmissionTimeOffset;
102 int32_t transmissionTimeOffset;
103 bool hasAbsoluteSendTime;
104 uint32_t absoluteSendTime;
105 bool hasTransportSequenceNumber;
106 uint16_t transportSequenceNumber;
Johannes Kron075f6872019-02-14 14:41:05 +0100107 absl::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 14:40:10 +0100108
109 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
110 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
111 bool hasAudioLevel;
112 bool voiceActivity;
113 uint8_t audioLevel;
114
115 // For Coordination of Video Orientation. See
116 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
117 // ts_126114v120700p.pdf
118 bool hasVideoRotation;
119 VideoRotation videoRotation;
120
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200121 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +0100122 // a corresponding bool flag.
123 bool hasVideoContentType;
124 VideoContentType videoContentType;
125
126 bool has_video_timing;
127 VideoSendTiming video_timing;
128
Johnny Leee0c8b232018-09-11 16:50:49 -0400129 bool has_frame_marking;
130 FrameMarking frame_marking;
131
Patrik Höglund3e113432017-12-15 14:40:10 +0100132 PlayoutDelay playout_delay = {-1, -1};
133
134 // For identification of a stream when ssrc is not signaled. See
135 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
136 // TODO(danilchap): Update url from draft to release version.
137 StreamId stream_id;
138 StreamId repaired_stream_id;
139
140 // For identifying the media section used to interpret this RTP packet. See
141 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
142 Mid mid;
Johannes Kronad1d9f02018-11-09 11:12:36 +0100143
Johannes Kron09d65882018-11-27 14:36:41 +0100144 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 14:40:10 +0100145};
146
147struct RTPHeader {
148 RTPHeader();
149 RTPHeader(const RTPHeader& other);
150 RTPHeader& operator=(const RTPHeader& other);
151
152 bool markerBit;
153 uint8_t payloadType;
154 uint16_t sequenceNumber;
155 uint32_t timestamp;
156 uint32_t ssrc;
157 uint8_t numCSRCs;
158 uint32_t arrOfCSRCs[kRtpCsrcSize];
159 size_t paddingLength;
160 size_t headerLength;
161 int payload_type_frequency;
162 RTPHeaderExtension extension;
163};
164
165// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
166// RTCP mode is described by RFC 5506.
167enum class RtcpMode { kOff, kCompound, kReducedSize };
168
169enum NetworkState {
170 kNetworkUp,
171 kNetworkDown,
172};
173
174struct RtpKeepAliveConfig final {
175 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
176 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
177 // payload type of 20 as long as the other end has not negotiated the use of
178 // this value. If this value has already been negotiated, then some other
179 // unused static payload type from table 5 of RFC 3551 shall be used and set
180 // in |payload_type|.
181 int64_t timeout_interval_ms = -1;
182 uint8_t payload_type = 20;
183
184 bool operator==(const RtpKeepAliveConfig& o) const {
185 return timeout_interval_ms == o.timeout_interval_ms &&
186 payload_type == o.payload_type;
187 }
188 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
189};
190
Patrik Höglund3e113432017-12-15 14:40:10 +0100191} // namespace webrtc
192
193#endif // API_RTP_HEADERS_H_