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(), |
28 last_received_frequency_(8000), | 29 last_received_frequency_(8000), |
| 30 telephone_event_forward_to_decoder_(false), |
29 telephone_event_payload_type_(-1), | 31 telephone_event_payload_type_(-1), |
30 cng_nb_payload_type_(-1), | 32 cng_nb_payload_type_(-1), |
31 cng_wb_payload_type_(-1), | 33 cng_wb_payload_type_(-1), |
32 cng_swb_payload_type_(-1), | 34 cng_swb_payload_type_(-1), |
33 cng_fb_payload_type_(-1), | 35 cng_fb_payload_type_(-1), |
34 cng_payload_type_(-1), | 36 cng_payload_type_(-1), |
35 g722_payload_type_(-1), | 37 g722_payload_type_(-1), |
36 last_received_g722_(false), | 38 last_received_g722_(false), |
37 num_energy_(0), | 39 num_energy_(0), |
38 current_remote_energy_() { | 40 current_remote_energy_() { |
39 last_payload_.Audio.channels = 1; | 41 last_payload_.Audio.channels = 1; |
40 memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); | 42 memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); |
41 } | 43 } |
42 | 44 |
| 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 |
43 bool RTPReceiverAudio::TelephoneEventPayloadType( | 58 bool RTPReceiverAudio::TelephoneEventPayloadType( |
44 int8_t payload_type) const { | 59 int8_t payload_type) const { |
45 rtc::CritScope lock(&crit_sect_); | 60 rtc::CritScope lock(&crit_sect_); |
46 return telephone_event_payload_type_ == payload_type; | 61 return telephone_event_payload_type_ == payload_type; |
47 } | 62 } |
48 | 63 |
49 bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type, | 64 bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type, |
50 uint32_t* frequency, | 65 uint32_t* frequency, |
51 bool* cng_payload_type_has_changed) { | 66 bool* cng_payload_type_has_changed) { |
52 rtc::CritScope lock(&crit_sect_); | 67 rtc::CritScope lock(&crit_sect_); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 &also_ignored)) { | 349 &also_ignored)) { |
335 rtp_header->type.Audio.isCNG = true; | 350 rtp_header->type.Audio.isCNG = true; |
336 rtp_header->frameType = kAudioFrameCN; | 351 rtp_header->frameType = kAudioFrameCN; |
337 } else { | 352 } else { |
338 rtp_header->frameType = kAudioFrameSpeech; | 353 rtp_header->frameType = kAudioFrameSpeech; |
339 rtp_header->type.Audio.isCNG = false; | 354 rtp_header->type.Audio.isCNG = false; |
340 } | 355 } |
341 | 356 |
342 // check if it's a DTMF event, hence something we can playout | 357 // check if it's a DTMF event, hence something we can playout |
343 if (telephone_event_packet) { | 358 if (telephone_event_packet) { |
| 359 if (!telephone_event_forward_to_decoder_) { |
| 360 // don't forward event to decoder |
| 361 return 0; |
| 362 } |
344 std::set<uint8_t>::iterator first = | 363 std::set<uint8_t>::iterator first = |
345 telephone_event_reported_.begin(); | 364 telephone_event_reported_.begin(); |
346 if (first != telephone_event_reported_.end() && *first > 15) { | 365 if (first != telephone_event_reported_.end() && *first > 15) { |
347 // don't forward non DTMF events | 366 // don't forward non DTMF events |
348 return 0; | 367 return 0; |
349 } | 368 } |
350 } | 369 } |
351 } | 370 } |
352 // TODO(holmer): Break this out to have RED parsing handled generically. | 371 // TODO(holmer): Break this out to have RED parsing handled generically. |
353 if (is_red && !(payload_data[0] & 0x80)) { | 372 if (is_red && !(payload_data[0] & 0x80)) { |
354 // we recive only one frame packed in a RED packet remove the RED wrapper | 373 // we recive only one frame packed in a RED packet remove the RED wrapper |
355 rtp_header->header.payloadType = payload_data[0]; | 374 rtp_header->header.payloadType = payload_data[0]; |
356 | 375 |
357 // only one frame in the RED strip the one byte to help NetEq | 376 // only one frame in the RED strip the one byte to help NetEq |
358 return data_callback_->OnReceivedPayloadData( | 377 return data_callback_->OnReceivedPayloadData( |
359 payload_data + 1, payload_length - 1, rtp_header); | 378 payload_data + 1, payload_length - 1, rtp_header); |
360 } | 379 } |
361 | 380 |
362 rtp_header->type.Audio.channel = audio_specific.channels; | 381 rtp_header->type.Audio.channel = audio_specific.channels; |
363 return data_callback_->OnReceivedPayloadData( | 382 return data_callback_->OnReceivedPayloadData( |
364 payload_data, payload_length, rtp_header); | 383 payload_data, payload_length, rtp_header); |
365 } | 384 } |
366 } // namespace webrtc | 385 } // namespace webrtc |
OLD | NEW |