Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc

Issue 2452293004: Simplify and extend RtpHeaderExtensionMap (Closed)
Patch Set: make kExtensions constexpr Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 15 matching lines...) Expand all
26 // 26 //
27 // The form of the absolute send time extension block: 27 // The form of the absolute send time extension block:
28 // 28 //
29 // 0 1 2 3 29 // 0 1 2 3
30 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 30 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 // | ID | len=2 | absolute send time | 32 // | ID | len=2 | absolute send time |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 constexpr RTPExtensionType AbsoluteSendTime::kId; 34 constexpr RTPExtensionType AbsoluteSendTime::kId;
35 constexpr uint8_t AbsoluteSendTime::kValueSizeBytes; 35 constexpr uint8_t AbsoluteSendTime::kValueSizeBytes;
36 const char* const AbsoluteSendTime::kUri = 36 // constexpr char AbsoluteSendTime::kUri[59];
sprang_webrtc 2016/11/08 16:13:37 ?
danilchap 2016/11/08 17:13:41 oops, left over from my tries to make kUri constex
37 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; 37 constexpr const char* AbsoluteSendTime::kUri;
38 38
39 bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* time_24bits) { 39 bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* time_24bits) {
40 *time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data); 40 *time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data);
41 return true; 41 return true;
42 } 42 }
43 43
44 bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) { 44 bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) {
45 ByteWriter<uint32_t, 3>::WriteBigEndian(data, MsTo24Bits(time_ms)); 45 ByteWriter<uint32_t, 3>::WriteBigEndian(data, MsTo24Bits(time_ms));
46 return true; 46 return true;
47 } 47 }
48 48
49 // An RTP Header Extension for Client-to-Mixer Audio Level Indication 49 // An RTP Header Extension for Client-to-Mixer Audio Level Indication
50 // 50 //
51 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/ 51 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
52 // 52 //
53 // The form of the audio level extension block: 53 // The form of the audio level extension block:
54 // 54 //
55 // 0 1 55 // 0 1
56 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 56 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
57 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 57 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 // | ID | len=0 |V| level | 58 // | ID | len=0 |V| level |
59 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 59 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 // 60 //
61 constexpr RTPExtensionType AudioLevel::kId; 61 constexpr RTPExtensionType AudioLevel::kId;
62 constexpr uint8_t AudioLevel::kValueSizeBytes; 62 constexpr uint8_t AudioLevel::kValueSizeBytes;
63 const char* const AudioLevel::kUri = 63 constexpr const char* AudioLevel::kUri;
64 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
65 64
66 bool AudioLevel::Parse(const uint8_t* data, 65 bool AudioLevel::Parse(const uint8_t* data,
67 bool* voice_activity, 66 bool* voice_activity,
68 uint8_t* audio_level) { 67 uint8_t* audio_level) {
69 *voice_activity = (data[0] & 0x80) != 0; 68 *voice_activity = (data[0] & 0x80) != 0;
70 *audio_level = data[0] & 0x7F; 69 *audio_level = data[0] & 0x7F;
71 return true; 70 return true;
72 } 71 }
73 72
74 bool AudioLevel::Write(uint8_t* data, 73 bool AudioLevel::Write(uint8_t* data,
(...skipping 15 matching lines...) Expand all
90 // 89 //
91 // The form of the transmission offset extension block: 90 // The form of the transmission offset extension block:
92 // 91 //
93 // 0 1 2 3 92 // 0 1 2 3
94 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 93 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
95 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 94 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 // | ID | len=2 | transmission offset | 95 // | ID | len=2 | transmission offset |
97 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 96 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 constexpr RTPExtensionType TransmissionOffset::kId; 97 constexpr RTPExtensionType TransmissionOffset::kId;
99 constexpr uint8_t TransmissionOffset::kValueSizeBytes; 98 constexpr uint8_t TransmissionOffset::kValueSizeBytes;
100 const char* const TransmissionOffset::kUri = 99 constexpr const char* TransmissionOffset::kUri;
101 "urn:ietf:params:rtp-hdrext:toffset";
102 100
103 bool TransmissionOffset::Parse(const uint8_t* data, int32_t* rtp_time) { 101 bool TransmissionOffset::Parse(const uint8_t* data, int32_t* rtp_time) {
104 *rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data); 102 *rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data);
105 return true; 103 return true;
106 } 104 }
107 105
108 bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) { 106 bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) {
109 RTC_DCHECK_LE(rtp_time, 0x00ffffff); 107 RTC_DCHECK_LE(rtp_time, 0x00ffffff);
110 ByteWriter<int32_t, 3>::WriteBigEndian(data, rtp_time); 108 ByteWriter<int32_t, 3>::WriteBigEndian(data, rtp_time);
111 return true; 109 return true;
112 } 110 }
113 111
114 // 0 1 2 112 // 0 1 2
115 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 113 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
116 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 114 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 // | ID | L=1 |transport wide sequence number | 115 // | ID | L=1 |transport wide sequence number |
118 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 116 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 constexpr RTPExtensionType TransportSequenceNumber::kId; 117 constexpr RTPExtensionType TransportSequenceNumber::kId;
120 constexpr uint8_t TransportSequenceNumber::kValueSizeBytes; 118 constexpr uint8_t TransportSequenceNumber::kValueSizeBytes;
121 const char* const TransportSequenceNumber::kUri = 119 constexpr const char* TransportSequenceNumber::kUri;
122 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions";
123 120
124 bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) { 121 bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) {
125 *value = ByteReader<uint16_t>::ReadBigEndian(data); 122 *value = ByteReader<uint16_t>::ReadBigEndian(data);
126 return true; 123 return true;
127 } 124 }
128 125
129 bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) { 126 bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) {
130 ByteWriter<uint16_t>::WriteBigEndian(data, value); 127 ByteWriter<uint16_t>::WriteBigEndian(data, value);
131 return true; 128 return true;
132 } 129 }
133 130
134 // Coordination of Video Orientation in RTP streams. 131 // Coordination of Video Orientation in RTP streams.
135 // 132 //
136 // Coordination of Video Orientation consists in signaling of the current 133 // Coordination of Video Orientation consists in signaling of the current
137 // orientation of the image captured on the sender side to the receiver for 134 // orientation of the image captured on the sender side to the receiver for
138 // appropriate rendering and displaying. 135 // appropriate rendering and displaying.
139 // 136 //
140 // 0 1 137 // 0 1
141 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 138 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
142 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 139 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 // | ID | len=0 |0 0 0 0 C F R R| 140 // | ID | len=0 |0 0 0 0 C F R R|
144 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 141 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 constexpr RTPExtensionType VideoOrientation::kId; 142 constexpr RTPExtensionType VideoOrientation::kId;
146 constexpr uint8_t VideoOrientation::kValueSizeBytes; 143 constexpr uint8_t VideoOrientation::kValueSizeBytes;
147 const char* const VideoOrientation::kUri = "urn:3gpp:video-orientation"; 144 constexpr const char* VideoOrientation::kUri;
148 145
149 bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) { 146 bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) {
150 *rotation = ConvertCVOByteToVideoRotation(data[0]); 147 *rotation = ConvertCVOByteToVideoRotation(data[0]);
151 return true; 148 return true;
152 } 149 }
153 150
154 bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) { 151 bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) {
155 data[0] = ConvertVideoRotationToCVOByte(rotation); 152 data[0] = ConvertVideoRotationToCVOByte(rotation);
156 return true; 153 return true;
157 } 154 }
158 155
159 bool VideoOrientation::Parse(const uint8_t* data, uint8_t* value) { 156 bool VideoOrientation::Parse(const uint8_t* data, uint8_t* value) {
160 *value = data[0]; 157 *value = data[0];
161 return true; 158 return true;
162 } 159 }
163 160
164 bool VideoOrientation::Write(uint8_t* data, uint8_t value) { 161 bool VideoOrientation::Write(uint8_t* data, uint8_t value) {
165 data[0] = value; 162 data[0] = value;
166 return true; 163 return true;
167 } 164 }
168 165
169 // 0 1 2 3 166 // 0 1 2 3
170 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 167 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
171 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 168 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
172 // | ID | len=2 | MIN delay | MAX delay | 169 // | ID | len=2 | MIN delay | MAX delay |
173 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 170 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
174 constexpr RTPExtensionType PlayoutDelayLimits::kId; 171 constexpr RTPExtensionType PlayoutDelayLimits::kId;
175 constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes; 172 constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes;
176 const char* const PlayoutDelayLimits::kUri = 173 constexpr const char* PlayoutDelayLimits::kUri;
177 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
178 174
179 bool PlayoutDelayLimits::Parse(const uint8_t* data, 175 bool PlayoutDelayLimits::Parse(const uint8_t* data,
180 PlayoutDelay* playout_delay) { 176 PlayoutDelay* playout_delay) {
181 RTC_DCHECK(playout_delay); 177 RTC_DCHECK(playout_delay);
182 uint32_t raw = ByteReader<uint32_t, 3>::ReadBigEndian(data); 178 uint32_t raw = ByteReader<uint32_t, 3>::ReadBigEndian(data);
183 uint16_t min_raw = (raw >> 12); 179 uint16_t min_raw = (raw >> 12);
184 uint16_t max_raw = (raw & 0xfff); 180 uint16_t max_raw = (raw & 0xfff);
185 if (min_raw > max_raw) 181 if (min_raw > max_raw)
186 return false; 182 return false;
187 playout_delay->min_ms = min_raw * kGranularityMs; 183 playout_delay->min_ms = min_raw * kGranularityMs;
188 playout_delay->max_ms = max_raw * kGranularityMs; 184 playout_delay->max_ms = max_raw * kGranularityMs;
189 return true; 185 return true;
190 } 186 }
191 187
192 bool PlayoutDelayLimits::Write(uint8_t* data, 188 bool PlayoutDelayLimits::Write(uint8_t* data,
193 const PlayoutDelay& playout_delay) { 189 const PlayoutDelay& playout_delay) {
194 RTC_DCHECK_LE(0, playout_delay.min_ms); 190 RTC_DCHECK_LE(0, playout_delay.min_ms);
195 RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms); 191 RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms);
196 RTC_DCHECK_LE(playout_delay.max_ms, kMaxMs); 192 RTC_DCHECK_LE(playout_delay.max_ms, kMaxMs);
197 // Convert MS to value to be sent on extension header. 193 // Convert MS to value to be sent on extension header.
198 uint32_t min_delay = playout_delay.min_ms / kGranularityMs; 194 uint32_t min_delay = playout_delay.min_ms / kGranularityMs;
199 uint32_t max_delay = playout_delay.max_ms / kGranularityMs; 195 uint32_t max_delay = playout_delay.max_ms / kGranularityMs;
200 ByteWriter<uint32_t, 3>::WriteBigEndian(data, (min_delay << 12) | max_delay); 196 ByteWriter<uint32_t, 3>::WriteBigEndian(data, (min_delay << 12) | max_delay);
201 return true; 197 return true;
202 } 198 }
203 199
204 } // namespace webrtc 200 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698