OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 204 } |
205 return 0; | 205 return 0; |
206 } | 206 } |
207 | 207 |
208 // We are not allowed to have any critsects when calling data_callback. | 208 // We are not allowed to have any critsects when calling data_callback. |
209 int32_t RTPReceiverAudio::ParseAudioCodecSpecific( | 209 int32_t RTPReceiverAudio::ParseAudioCodecSpecific( |
210 WebRtcRTPHeader* rtp_header, | 210 WebRtcRTPHeader* rtp_header, |
211 const uint8_t* payload_data, | 211 const uint8_t* payload_data, |
212 size_t payload_length, | 212 size_t payload_length, |
213 const AudioPayload& audio_specific, | 213 const AudioPayload& audio_specific, |
214 bool is_red) { | 214 bool is_red) { |
minyue-webrtc
2017/05/09 21:04:06
I'd like to see explicit treatment of 0 and early
hlundin-webrtc
2017/05/10 08:57:23
We must forward the actual WebRtcRTPHeader, can't
minyue-webrtc
2017/05/10 09:44:12
I still prefer early return, since no need to read
hlundin-webrtc
2017/05/10 11:19:30
Done.
| |
215 | |
216 if (payload_length == 0) { | |
217 return 0; | |
218 } | |
219 | |
220 bool telephone_event_packet = | 215 bool telephone_event_packet = |
221 TelephoneEventPayloadType(rtp_header->header.payloadType); | 216 TelephoneEventPayloadType(rtp_header->header.payloadType); |
222 if (telephone_event_packet) { | 217 if (telephone_event_packet) { |
223 rtc::CritScope lock(&crit_sect_); | 218 rtc::CritScope lock(&crit_sect_); |
224 | 219 |
225 // RFC 4733 2.3 | 220 // RFC 4733 2.3 |
226 // 0 1 2 3 | 221 // 0 1 2 3 |
227 // 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 | 222 // 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 |
228 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 223 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
229 // | event |E|R| volume | duration | | 224 // | event |E|R| volume | duration | |
230 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 225 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
231 // | 226 // |
232 if (payload_length % 4 != 0) { | 227 if (payload_length % 4 != 0) { |
233 return -1; | 228 return -1; |
234 } | 229 } |
235 size_t number_of_events = payload_length / 4; | 230 size_t number_of_events = payload_length / 4; |
236 | 231 |
237 // sanity | 232 // sanity |
238 if (number_of_events >= MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS) { | 233 if (number_of_events >= MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS) { |
239 number_of_events = MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS; | 234 number_of_events = MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS; |
240 } | 235 } |
241 for (size_t n = 0; n < number_of_events; ++n) { | 236 for (size_t n = 0; n < number_of_events; ++n) { |
237 RTC_DCHECK_GE(payload_length, (4 * n) + 2); | |
minyue-webrtc
2017/05/09 21:04:06
check (not dcheck) outside the loop
RTC_CHECK_GE(
hlundin-webrtc
2017/05/10 08:57:23
The DCHECK is for documentation purposes, since it
kwiberg-webrtc
2017/05/10 09:22:50
I agree that having a simple DCHECK inside the loo
hlundin-webrtc
2017/05/10 11:19:30
Acknowledged.
| |
242 bool end = (payload_data[(4 * n) + 1] & 0x80) ? true : false; | 238 bool end = (payload_data[(4 * n) + 1] & 0x80) ? true : false; |
243 | 239 |
244 std::set<uint8_t>::iterator event = | 240 std::set<uint8_t>::iterator event = |
245 telephone_event_reported_.find(payload_data[4 * n]); | 241 telephone_event_reported_.find(payload_data[4 * n]); |
246 | 242 |
247 if (event != telephone_event_reported_.end()) { | 243 if (event != telephone_event_reported_.end()) { |
248 // we have already seen this event | 244 // we have already seen this event |
249 if (end) { | 245 if (end) { |
250 telephone_event_reported_.erase(payload_data[4 * n]); | 246 telephone_event_reported_.erase(payload_data[4 * n]); |
251 } | 247 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 } | 280 } |
285 std::set<uint8_t>::iterator first = | 281 std::set<uint8_t>::iterator first = |
286 telephone_event_reported_.begin(); | 282 telephone_event_reported_.begin(); |
287 if (first != telephone_event_reported_.end() && *first > 15) { | 283 if (first != telephone_event_reported_.end() && *first > 15) { |
288 // don't forward non DTMF events | 284 // don't forward non DTMF events |
289 return 0; | 285 return 0; |
290 } | 286 } |
291 } | 287 } |
292 } | 288 } |
293 // TODO(holmer): Break this out to have RED parsing handled generically. | 289 // TODO(holmer): Break this out to have RED parsing handled generically. |
294 if (is_red && !(payload_data[0] & 0x80)) { | 290 if (payload_length > 0 && is_red && !(payload_data[0] & 0x80)) { |
minyue-webrtc
2017/05/09 21:04:06
payload_length != 0 feels to me easier to read
bu
hlundin-webrtc
2017/05/10 08:57:23
Done.
| |
295 // we recive only one frame packed in a RED packet remove the RED wrapper | 291 // we recive only one frame packed in a RED packet remove the RED wrapper |
296 rtp_header->header.payloadType = payload_data[0]; | 292 rtp_header->header.payloadType = payload_data[0]; |
297 | 293 |
298 // only one frame in the RED strip the one byte to help NetEq | 294 // only one frame in the RED strip the one byte to help NetEq |
299 return data_callback_->OnReceivedPayloadData( | 295 return data_callback_->OnReceivedPayloadData( |
300 payload_data + 1, payload_length - 1, rtp_header); | 296 payload_data + 1, payload_length - 1, rtp_header); |
301 } | 297 } |
302 | 298 |
303 rtp_header->type.Audio.channel = audio_specific.channels; | 299 rtp_header->type.Audio.channel = audio_specific.channels; |
304 return data_callback_->OnReceivedPayloadData( | 300 return data_callback_->OnReceivedPayloadData( |
305 payload_data, payload_length, rtp_header); | 301 payload_data, payload_length, rtp_header); |
306 } | 302 } |
307 } // namespace webrtc | 303 } // namespace webrtc |
OLD | NEW |