blob: c762534ab3a7454bde87d082e3b101186c6bfc37 [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>
15#include <string.h>
Patrik Höglund3e113432017-12-15 14:40:10 +010016#include <string>
17#include <vector>
18
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020019#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010020#include "api/array_view.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010021#include "api/video/video_content_type.h"
22#include "api/video/video_rotation.h"
23#include "api/video/video_timing.h"
24
Yves Gerey665174f2018-06-19 15:03:05 +020025#include "common_types.h" // NOLINT(build/include)
Patrik Höglund3e113432017-12-15 14:40:10 +010026#include "rtc_base/checks.h"
27#include "rtc_base/deprecation.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010028
29namespace webrtc {
30
31// Class to represent the value of RTP header extensions that are
32// variable-length strings (e.g., RtpStreamId and RtpMid).
33// Unlike std::string, it can be copied with memcpy and cleared with memset.
34//
35// Empty value represents unset header extension (use empty() to query).
36class StringRtpHeaderExtension {
37 public:
38 // String RTP header extensions are limited to 16 bytes because it is the
39 // maximum length that can be encoded with one-byte header extensions.
40 static constexpr size_t kMaxSize = 16;
41
Joachim Bauchd3b7ec22018-08-01 10:12:00 +020042 static bool IsLegalMidName(rtc::ArrayView<const char> name);
43 static bool IsLegalRsidName(rtc::ArrayView<const char> name);
44
45 // TODO(bugs.webrtc.org/9537): Deprecate and remove when third parties have
46 // migrated to "IsLegalRsidName".
47 static bool IsLegalName(rtc::ArrayView<const char> name) {
48 return IsLegalRsidName(name);
49 }
Patrik Höglund3e113432017-12-15 14:40:10 +010050
51 StringRtpHeaderExtension() { value_[0] = 0; }
52 explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
53 Set(value.data(), value.size());
54 }
55 StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
56 StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
57 default;
58
59 bool empty() const { return value_[0] == 0; }
60 const char* data() const { return value_; }
61 size_t size() const { return strnlen(value_, kMaxSize); }
62
63 void Set(rtc::ArrayView<const uint8_t> value) {
64 Set(reinterpret_cast<const char*>(value.data()), value.size());
65 }
66 void Set(const char* data, size_t size);
67
68 friend bool operator==(const StringRtpHeaderExtension& lhs,
69 const StringRtpHeaderExtension& rhs) {
70 return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
71 }
72 friend bool operator!=(const StringRtpHeaderExtension& lhs,
73 const StringRtpHeaderExtension& rhs) {
74 return !(lhs == rhs);
75 }
76
77 private:
78 char value_[kMaxSize];
79};
80
81// StreamId represents RtpStreamId which is a string.
82typedef StringRtpHeaderExtension StreamId;
83
84// Mid represents RtpMid which is a string.
85typedef StringRtpHeaderExtension Mid;
86
87struct RTPHeaderExtension {
88 RTPHeaderExtension();
89 RTPHeaderExtension(const RTPHeaderExtension& other);
90 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
91
92 bool hasTransmissionTimeOffset;
93 int32_t transmissionTimeOffset;
94 bool hasAbsoluteSendTime;
95 uint32_t absoluteSendTime;
96 bool hasTransportSequenceNumber;
97 uint16_t transportSequenceNumber;
98
99 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
100 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
101 bool hasAudioLevel;
102 bool voiceActivity;
103 uint8_t audioLevel;
104
105 // For Coordination of Video Orientation. See
106 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
107 // ts_126114v120700p.pdf
108 bool hasVideoRotation;
109 VideoRotation videoRotation;
110
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200111 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +0100112 // a corresponding bool flag.
113 bool hasVideoContentType;
114 VideoContentType videoContentType;
115
116 bool has_video_timing;
117 VideoSendTiming video_timing;
118
119 PlayoutDelay playout_delay = {-1, -1};
120
121 // For identification of a stream when ssrc is not signaled. See
122 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
123 // TODO(danilchap): Update url from draft to release version.
124 StreamId stream_id;
125 StreamId repaired_stream_id;
126
127 // For identifying the media section used to interpret this RTP packet. See
128 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
129 Mid mid;
130};
131
132struct RTPHeader {
133 RTPHeader();
134 RTPHeader(const RTPHeader& other);
135 RTPHeader& operator=(const RTPHeader& other);
136
137 bool markerBit;
138 uint8_t payloadType;
139 uint16_t sequenceNumber;
140 uint32_t timestamp;
141 uint32_t ssrc;
142 uint8_t numCSRCs;
143 uint32_t arrOfCSRCs[kRtpCsrcSize];
144 size_t paddingLength;
145 size_t headerLength;
146 int payload_type_frequency;
147 RTPHeaderExtension extension;
148};
149
150// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
151// RTCP mode is described by RFC 5506.
152enum class RtcpMode { kOff, kCompound, kReducedSize };
153
154enum NetworkState {
155 kNetworkUp,
156 kNetworkDown,
157};
158
159struct RtpKeepAliveConfig final {
160 // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
161 // packet. The keep-alive packet is an empty (no payload) RTP packet with a
162 // payload type of 20 as long as the other end has not negotiated the use of
163 // this value. If this value has already been negotiated, then some other
164 // unused static payload type from table 5 of RFC 3551 shall be used and set
165 // in |payload_type|.
166 int64_t timeout_interval_ms = -1;
167 uint8_t payload_type = 20;
168
169 bool operator==(const RtpKeepAliveConfig& o) const {
170 return timeout_interval_ms == o.timeout_interval_ms &&
171 payload_type == o.payload_type;
172 }
173 bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
174};
175
Patrik Höglund3e113432017-12-15 14:40:10 +0100176} // namespace webrtc
177
178#endif // API_RTP_HEADERS_H_