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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" |
12 | 12 |
13 #include <assert.h> // assert | 13 #include <assert.h> // assert |
14 #include <math.h> // pow() | 14 #include <math.h> // pow() |
15 #include <string.h> // memcpy() | 15 #include <string.h> // memcpy() |
16 | 16 |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/trace_event.h" | 18 #include "webrtc/base/trace_event.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 RTPReceiverStrategy* RTPReceiverStrategy::CreateAudioStrategy( | 21 RTPReceiverStrategy* RTPReceiverStrategy::CreateAudioStrategy( |
22 RtpData* data_callback) { | 22 RtpData* data_callback) { |
23 return new RTPReceiverAudio(data_callback); | 23 return new RTPReceiverAudio(data_callback); |
24 } | 24 } |
25 | 25 |
26 RTPReceiverAudio::RTPReceiverAudio(RtpData* data_callback) | 26 RTPReceiverAudio::RTPReceiverAudio(RtpData* data_callback) |
27 : RTPReceiverStrategy(data_callback), | 27 : RTPReceiverStrategy(data_callback), |
28 TelephoneEventHandler(), | |
29 last_received_frequency_(8000), | 28 last_received_frequency_(8000), |
30 telephone_event_forward_to_decoder_(false), | |
31 telephone_event_payload_type_(-1), | 29 telephone_event_payload_type_(-1), |
32 cng_nb_payload_type_(-1), | 30 cng_nb_payload_type_(-1), |
33 cng_wb_payload_type_(-1), | 31 cng_wb_payload_type_(-1), |
34 cng_swb_payload_type_(-1), | 32 cng_swb_payload_type_(-1), |
35 cng_fb_payload_type_(-1), | 33 cng_fb_payload_type_(-1), |
36 cng_payload_type_(-1), | 34 cng_payload_type_(-1), |
37 g722_payload_type_(-1), | 35 g722_payload_type_(-1), |
38 last_received_g722_(false), | 36 last_received_g722_(false), |
39 num_energy_(0), | 37 num_energy_(0), |
40 current_remote_energy_() { | 38 current_remote_energy_() { |
41 last_payload_.Audio.channels = 1; | 39 last_payload_.Audio.channels = 1; |
42 memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); | 40 memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); |
43 } | 41 } |
44 | 42 |
45 // Outband TelephoneEvent(DTMF) detection | |
46 void RTPReceiverAudio::SetTelephoneEventForwardToDecoder( | |
47 bool forward_to_decoder) { | |
48 rtc::CritScope lock(&crit_sect_); | |
49 telephone_event_forward_to_decoder_ = forward_to_decoder; | |
50 } | |
51 | |
52 // Is forwarding of outband telephone events turned on/off? | |
53 bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const { | |
54 rtc::CritScope lock(&crit_sect_); | |
55 return telephone_event_forward_to_decoder_; | |
56 } | |
57 | |
58 bool RTPReceiverAudio::TelephoneEventPayloadType( | 43 bool RTPReceiverAudio::TelephoneEventPayloadType( |
59 int8_t payload_type) const { | 44 int8_t payload_type) const { |
60 rtc::CritScope lock(&crit_sect_); | 45 rtc::CritScope lock(&crit_sect_); |
61 return telephone_event_payload_type_ == payload_type; | 46 return telephone_event_payload_type_ == payload_type; |
62 } | 47 } |
63 | 48 |
64 bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type, | 49 bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type, |
65 uint32_t* frequency, | 50 uint32_t* frequency, |
66 bool* cng_payload_type_has_changed) { | 51 bool* cng_payload_type_has_changed) { |
67 rtc::CritScope lock(&crit_sect_); | 52 rtc::CritScope lock(&crit_sect_); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 &also_ignored)) { | 334 &also_ignored)) { |
350 rtp_header->type.Audio.isCNG = true; | 335 rtp_header->type.Audio.isCNG = true; |
351 rtp_header->frameType = kAudioFrameCN; | 336 rtp_header->frameType = kAudioFrameCN; |
352 } else { | 337 } else { |
353 rtp_header->frameType = kAudioFrameSpeech; | 338 rtp_header->frameType = kAudioFrameSpeech; |
354 rtp_header->type.Audio.isCNG = false; | 339 rtp_header->type.Audio.isCNG = false; |
355 } | 340 } |
356 | 341 |
357 // check if it's a DTMF event, hence something we can playout | 342 // check if it's a DTMF event, hence something we can playout |
358 if (telephone_event_packet) { | 343 if (telephone_event_packet) { |
359 if (!telephone_event_forward_to_decoder_) { | |
360 // don't forward event to decoder | |
361 return 0; | |
362 } | |
363 std::set<uint8_t>::iterator first = | 344 std::set<uint8_t>::iterator first = |
364 telephone_event_reported_.begin(); | 345 telephone_event_reported_.begin(); |
365 if (first != telephone_event_reported_.end() && *first > 15) { | 346 if (first != telephone_event_reported_.end() && *first > 15) { |
366 // don't forward non DTMF events | 347 // don't forward non DTMF events |
367 return 0; | 348 return 0; |
368 } | 349 } |
369 } | 350 } |
370 } | 351 } |
371 // TODO(holmer): Break this out to have RED parsing handled generically. | 352 // TODO(holmer): Break this out to have RED parsing handled generically. |
372 if (is_red && !(payload_data[0] & 0x80)) { | 353 if (is_red && !(payload_data[0] & 0x80)) { |
373 // we recive only one frame packed in a RED packet remove the RED wrapper | 354 // we recive only one frame packed in a RED packet remove the RED wrapper |
374 rtp_header->header.payloadType = payload_data[0]; | 355 rtp_header->header.payloadType = payload_data[0]; |
375 | 356 |
376 // only one frame in the RED strip the one byte to help NetEq | 357 // only one frame in the RED strip the one byte to help NetEq |
377 return data_callback_->OnReceivedPayloadData( | 358 return data_callback_->OnReceivedPayloadData( |
378 payload_data + 1, payload_length - 1, rtp_header); | 359 payload_data + 1, payload_length - 1, rtp_header); |
379 } | 360 } |
380 | 361 |
381 rtp_header->type.Audio.channel = audio_specific.channels; | 362 rtp_header->type.Audio.channel = audio_specific.channels; |
382 return data_callback_->OnReceivedPayloadData( | 363 return data_callback_->OnReceivedPayloadData( |
383 payload_data, payload_length, rtp_header); | 364 payload_data, payload_length, rtp_header); |
384 } | 365 } |
385 } // namespace webrtc | 366 } // namespace webrtc |
OLD | NEW |