Chromium Code Reviews

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

Issue 2801733002: Move rtp header extension length check from Packet::FindExtension to ExtensionT::Parse (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 17 matching lines...)
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 constexpr const char* AbsoluteSendTime::kUri; 36 constexpr const char* AbsoluteSendTime::kUri;
37 37
38 bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* time_24bits) { 38 bool AbsoluteSendTime::Parse(rtc::ArrayView<const uint8_t> data,
39 *time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data); 39 uint32_t* time_24bits) {
40 if (data.size() != 3)
41 return false;
42 *time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data.data());
40 return true; 43 return true;
41 } 44 }
42 45
43 bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) { 46 bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) {
44 ByteWriter<uint32_t, 3>::WriteBigEndian(data, MsTo24Bits(time_ms)); 47 ByteWriter<uint32_t, 3>::WriteBigEndian(data, MsTo24Bits(time_ms));
45 return true; 48 return true;
46 } 49 }
47 50
48 // An RTP Header Extension for Client-to-Mixer Audio Level Indication 51 // An RTP Header Extension for Client-to-Mixer Audio Level Indication
49 // 52 //
50 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/ 53 // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
51 // 54 //
52 // The form of the audio level extension block: 55 // The form of the audio level extension block:
53 // 56 //
54 // 0 1 57 // 0 1
55 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 58 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
56 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 59 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 // | ID | len=0 |V| level | 60 // | ID | len=0 |V| level |
58 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 61 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 // 62 //
60 constexpr RTPExtensionType AudioLevel::kId; 63 constexpr RTPExtensionType AudioLevel::kId;
61 constexpr uint8_t AudioLevel::kValueSizeBytes; 64 constexpr uint8_t AudioLevel::kValueSizeBytes;
62 constexpr const char* AudioLevel::kUri; 65 constexpr const char* AudioLevel::kUri;
63 66
64 bool AudioLevel::Parse(const uint8_t* data, 67 bool AudioLevel::Parse(rtc::ArrayView<const uint8_t> data,
65 bool* voice_activity, 68 bool* voice_activity,
66 uint8_t* audio_level) { 69 uint8_t* audio_level) {
70 if (data.size() != 1)
71 return false;
67 *voice_activity = (data[0] & 0x80) != 0; 72 *voice_activity = (data[0] & 0x80) != 0;
68 *audio_level = data[0] & 0x7F; 73 *audio_level = data[0] & 0x7F;
69 return true; 74 return true;
70 } 75 }
71 76
72 bool AudioLevel::Write(uint8_t* data, 77 bool AudioLevel::Write(uint8_t* data,
73 bool voice_activity, 78 bool voice_activity,
74 uint8_t audio_level) { 79 uint8_t audio_level) {
75 RTC_CHECK_LE(audio_level, 0x7f); 80 RTC_CHECK_LE(audio_level, 0x7f);
76 data[0] = (voice_activity ? 0x80 : 0x00) | audio_level; 81 data[0] = (voice_activity ? 0x80 : 0x00) | audio_level;
(...skipping 13 matching lines...)
90 // 95 //
91 // 0 1 2 3 96 // 0 1 2 3
92 // 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 97 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 98 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 // | ID | len=2 | transmission offset | 99 // | ID | len=2 | transmission offset |
95 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 100 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 constexpr RTPExtensionType TransmissionOffset::kId; 101 constexpr RTPExtensionType TransmissionOffset::kId;
97 constexpr uint8_t TransmissionOffset::kValueSizeBytes; 102 constexpr uint8_t TransmissionOffset::kValueSizeBytes;
98 constexpr const char* TransmissionOffset::kUri; 103 constexpr const char* TransmissionOffset::kUri;
99 104
100 bool TransmissionOffset::Parse(const uint8_t* data, int32_t* rtp_time) { 105 bool TransmissionOffset::Parse(rtc::ArrayView<const uint8_t> data,
101 *rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data); 106 int32_t* rtp_time) {
107 if (data.size() != 3)
108 return false;
109 *rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data.data());
102 return true; 110 return true;
103 } 111 }
104 112
105 bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) { 113 bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) {
106 RTC_DCHECK_LE(rtp_time, 0x00ffffff); 114 RTC_DCHECK_LE(rtp_time, 0x00ffffff);
107 ByteWriter<int32_t, 3>::WriteBigEndian(data, rtp_time); 115 ByteWriter<int32_t, 3>::WriteBigEndian(data, rtp_time);
108 return true; 116 return true;
109 } 117 }
110 118
111 // 0 1 2 119 // 0 1 2
112 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 120 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 121 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 // | ID | L=1 |transport wide sequence number | 122 // | ID | L=1 |transport wide sequence number |
115 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 123 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116 constexpr RTPExtensionType TransportSequenceNumber::kId; 124 constexpr RTPExtensionType TransportSequenceNumber::kId;
117 constexpr uint8_t TransportSequenceNumber::kValueSizeBytes; 125 constexpr uint8_t TransportSequenceNumber::kValueSizeBytes;
118 constexpr const char* TransportSequenceNumber::kUri; 126 constexpr const char* TransportSequenceNumber::kUri;
119 127
120 bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) { 128 bool TransportSequenceNumber::Parse(rtc::ArrayView<const uint8_t> data,
121 *value = ByteReader<uint16_t>::ReadBigEndian(data); 129 uint16_t* value) {
130 if (data.size() != 2)
131 return false;
132 *value = ByteReader<uint16_t>::ReadBigEndian(data.data());
122 return true; 133 return true;
123 } 134 }
124 135
125 bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) { 136 bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) {
126 ByteWriter<uint16_t>::WriteBigEndian(data, value); 137 ByteWriter<uint16_t>::WriteBigEndian(data, value);
127 return true; 138 return true;
128 } 139 }
129 140
130 // Coordination of Video Orientation in RTP streams. 141 // Coordination of Video Orientation in RTP streams.
131 // 142 //
132 // Coordination of Video Orientation consists in signaling of the current 143 // Coordination of Video Orientation consists in signaling of the current
133 // orientation of the image captured on the sender side to the receiver for 144 // orientation of the image captured on the sender side to the receiver for
134 // appropriate rendering and displaying. 145 // appropriate rendering and displaying.
135 // 146 //
136 // 0 1 147 // 0 1
137 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 148 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
138 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 149 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
139 // | ID | len=0 |0 0 0 0 C F R R| 150 // | ID | len=0 |0 0 0 0 C F R R|
140 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 151 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 constexpr RTPExtensionType VideoOrientation::kId; 152 constexpr RTPExtensionType VideoOrientation::kId;
142 constexpr uint8_t VideoOrientation::kValueSizeBytes; 153 constexpr uint8_t VideoOrientation::kValueSizeBytes;
143 constexpr const char* VideoOrientation::kUri; 154 constexpr const char* VideoOrientation::kUri;
144 155
145 bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) { 156 bool VideoOrientation::Parse(rtc::ArrayView<const uint8_t> data,
157 VideoRotation* rotation) {
158 if (data.size() != 1)
159 return false;
146 *rotation = ConvertCVOByteToVideoRotation(data[0]); 160 *rotation = ConvertCVOByteToVideoRotation(data[0]);
147 return true; 161 return true;
148 } 162 }
149 163
150 bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) { 164 bool VideoOrientation::Write(uint8_t* data, VideoRotation rotation) {
151 data[0] = ConvertVideoRotationToCVOByte(rotation); 165 data[0] = ConvertVideoRotationToCVOByte(rotation);
152 return true; 166 return true;
153 } 167 }
154 168
155 bool VideoOrientation::Parse(const uint8_t* data, uint8_t* value) { 169 bool VideoOrientation::Parse(rtc::ArrayView<const uint8_t> data,
170 uint8_t* value) {
171 if (data.size() != 1)
172 return false;
156 *value = data[0]; 173 *value = data[0];
157 return true; 174 return true;
158 } 175 }
159 176
160 bool VideoOrientation::Write(uint8_t* data, uint8_t value) { 177 bool VideoOrientation::Write(uint8_t* data, uint8_t value) {
161 data[0] = value; 178 data[0] = value;
162 return true; 179 return true;
163 } 180 }
164 181
165 // 0 1 2 3 182 // 0 1 2 3
166 // 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 183 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 184 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
168 // | ID | len=2 | MIN delay | MAX delay | 185 // | ID | len=2 | MIN delay | MAX delay |
169 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 186 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
170 constexpr RTPExtensionType PlayoutDelayLimits::kId; 187 constexpr RTPExtensionType PlayoutDelayLimits::kId;
171 constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes; 188 constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes;
172 constexpr const char* PlayoutDelayLimits::kUri; 189 constexpr const char* PlayoutDelayLimits::kUri;
173 190
174 bool PlayoutDelayLimits::Parse(const uint8_t* data, 191 bool PlayoutDelayLimits::Parse(rtc::ArrayView<const uint8_t> data,
175 PlayoutDelay* playout_delay) { 192 PlayoutDelay* playout_delay) {
176 RTC_DCHECK(playout_delay); 193 RTC_DCHECK(playout_delay);
177 uint32_t raw = ByteReader<uint32_t, 3>::ReadBigEndian(data); 194 if (data.size() != 3)
195 return false;
196 uint32_t raw = ByteReader<uint32_t, 3>::ReadBigEndian(data.data());
178 uint16_t min_raw = (raw >> 12); 197 uint16_t min_raw = (raw >> 12);
179 uint16_t max_raw = (raw & 0xfff); 198 uint16_t max_raw = (raw & 0xfff);
180 if (min_raw > max_raw) 199 if (min_raw > max_raw)
181 return false; 200 return false;
182 playout_delay->min_ms = min_raw * kGranularityMs; 201 playout_delay->min_ms = min_raw * kGranularityMs;
183 playout_delay->max_ms = max_raw * kGranularityMs; 202 playout_delay->max_ms = max_raw * kGranularityMs;
184 return true; 203 return true;
185 } 204 }
186 205
187 bool PlayoutDelayLimits::Write(uint8_t* data, 206 bool PlayoutDelayLimits::Write(uint8_t* data,
188 const PlayoutDelay& playout_delay) { 207 const PlayoutDelay& playout_delay) {
189 RTC_DCHECK_LE(0, playout_delay.min_ms); 208 RTC_DCHECK_LE(0, playout_delay.min_ms);
190 RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms); 209 RTC_DCHECK_LE(playout_delay.min_ms, playout_delay.max_ms);
191 RTC_DCHECK_LE(playout_delay.max_ms, kMaxMs); 210 RTC_DCHECK_LE(playout_delay.max_ms, kMaxMs);
192 // Convert MS to value to be sent on extension header. 211 // Convert MS to value to be sent on extension header.
193 uint32_t min_delay = playout_delay.min_ms / kGranularityMs; 212 uint32_t min_delay = playout_delay.min_ms / kGranularityMs;
194 uint32_t max_delay = playout_delay.max_ms / kGranularityMs; 213 uint32_t max_delay = playout_delay.max_ms / kGranularityMs;
195 ByteWriter<uint32_t, 3>::WriteBigEndian(data, (min_delay << 12) | max_delay); 214 ByteWriter<uint32_t, 3>::WriteBigEndian(data, (min_delay << 12) | max_delay);
196 return true; 215 return true;
197 } 216 }
198 217
199 } // namespace webrtc 218 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_packet.h » ('j') | no next file with comments »

Powered by Google App Engine