niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #include "modules/rtp_rtcp/source/rtp_receiver_audio.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> // assert |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 14 | #include <math.h> // pow() |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 15 | #include <string.h> // memcpy() |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 17 | #include "common_types.h" |
| 18 | #include "rtc_base/logging.h" |
| 19 | #include "rtc_base/trace_event.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 22 | RTPReceiverStrategy* RTPReceiverStrategy::CreateAudioStrategy( |
solenberg | 1d03139 | 2016-03-30 02:42:32 -0700 | [diff] [blame] | 23 | RtpData* data_callback) { |
| 24 | return new RTPReceiverAudio(data_callback); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 25 | } |
| 26 | |
solenberg | 1d03139 | 2016-03-30 02:42:32 -0700 | [diff] [blame] | 27 | RTPReceiverAudio::RTPReceiverAudio(RtpData* data_callback) |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 28 | : RTPReceiverStrategy(data_callback), |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 29 | TelephoneEventHandler(), |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 30 | telephone_event_forward_to_decoder_(false), |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 31 | telephone_event_payload_type_(-1), |
| 32 | cng_nb_payload_type_(-1), |
| 33 | cng_wb_payload_type_(-1), |
| 34 | cng_swb_payload_type_(-1), |
| 35 | cng_fb_payload_type_(-1), |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 36 | num_energy_(0), |
solenberg | 1d03139 | 2016-03-30 02:42:32 -0700 | [diff] [blame] | 37 | current_remote_energy_() { |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 38 | last_payload_.Audio.channels = 1; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 39 | memset(current_remote_energy_, 0, sizeof(current_remote_energy_)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 42 | // Outband TelephoneEvent(DTMF) detection |
| 43 | void RTPReceiverAudio::SetTelephoneEventForwardToDecoder( |
| 44 | bool forward_to_decoder) { |
| 45 | rtc::CritScope lock(&crit_sect_); |
| 46 | telephone_event_forward_to_decoder_ = forward_to_decoder; |
| 47 | } |
| 48 | |
| 49 | // Is forwarding of outband telephone events turned on/off? |
| 50 | bool RTPReceiverAudio::TelephoneEventForwardToDecoder() const { |
| 51 | rtc::CritScope lock(&crit_sect_); |
| 52 | return telephone_event_forward_to_decoder_; |
| 53 | } |
| 54 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 55 | bool RTPReceiverAudio::TelephoneEventPayloadType( |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 56 | int8_t payload_type) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 57 | rtc::CritScope lock(&crit_sect_); |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 58 | return telephone_event_payload_type_ == payload_type; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | } |
| 60 | |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 61 | bool RTPReceiverAudio::CNGPayloadType(int8_t payload_type) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 62 | rtc::CritScope lock(&crit_sect_); |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 63 | return payload_type == cng_nb_payload_type_ || |
| 64 | payload_type == cng_wb_payload_type_ || |
| 65 | payload_type == cng_swb_payload_type_ || |
| 66 | payload_type == cng_fb_payload_type_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 69 | bool RTPReceiverAudio::ShouldReportCsrcChanges(uint8_t payload_type) const { |
phoglund@webrtc.org | 5accd37 | 2013-01-22 12:31:01 +0000 | [diff] [blame] | 70 | // Don't do this for DTMF packets, otherwise it's fine. |
| 71 | return !TelephoneEventPayloadType(payload_type); |
| 72 | } |
| 73 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 74 | // - Sample based or frame based codecs based on RFC 3551 |
| 75 | // - |
| 76 | // - NOTE! There is one error in the RFC, stating G.722 uses 8 bits/samples. |
| 77 | // - The correct rate is 4 bits/sample. |
| 78 | // - |
| 79 | // - name of sampling default |
| 80 | // - encoding sample/frame bits/sample rate ms/frame ms/packet |
| 81 | // - |
| 82 | // - Sample based audio codecs |
| 83 | // - DVI4 sample 4 var. 20 |
| 84 | // - G722 sample 4 16,000 20 |
| 85 | // - G726-40 sample 5 8,000 20 |
| 86 | // - G726-32 sample 4 8,000 20 |
| 87 | // - G726-24 sample 3 8,000 20 |
| 88 | // - G726-16 sample 2 8,000 20 |
| 89 | // - L8 sample 8 var. 20 |
| 90 | // - L16 sample 16 var. 20 |
| 91 | // - PCMA sample 8 var. 20 |
| 92 | // - PCMU sample 8 var. 20 |
| 93 | // - |
| 94 | // - Frame based audio codecs |
| 95 | // - G723 frame N/A 8,000 30 30 |
| 96 | // - G728 frame N/A 8,000 2.5 20 |
| 97 | // - G729 frame N/A 8,000 10 20 |
| 98 | // - G729D frame N/A 8,000 10 20 |
| 99 | // - G729E frame N/A 8,000 10 20 |
| 100 | // - GSM frame N/A 8,000 20 20 |
| 101 | // - GSM-EFR frame N/A 8,000 20 20 |
| 102 | // - LPC frame N/A 8,000 20 20 |
| 103 | // - MPA frame N/A var. var. |
| 104 | // - |
| 105 | // - G7221 frame N/A |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 106 | int32_t RTPReceiverAudio::OnNewPayloadTypeCreated( |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 107 | const CodecInst& audio_codec) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 108 | rtc::CritScope lock(&crit_sect_); |
phoglund@webrtc.org | 92bb417 | 2012-12-13 10:48:24 +0000 | [diff] [blame] | 109 | |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 110 | if (RtpUtility::StringCompare(audio_codec.plname, "telephone-event", 15)) { |
| 111 | telephone_event_payload_type_ = audio_codec.pltype; |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 112 | } |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 113 | if (RtpUtility::StringCompare(audio_codec.plname, "cn", 2)) { |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 114 | // We support comfort noise at four different frequencies. |
magjed | 56124bd | 2016-11-24 09:34:46 -0800 | [diff] [blame] | 115 | if (audio_codec.plfreq == 8000) { |
| 116 | cng_nb_payload_type_ = audio_codec.pltype; |
| 117 | } else if (audio_codec.plfreq == 16000) { |
| 118 | cng_wb_payload_type_ = audio_codec.pltype; |
| 119 | } else if (audio_codec.plfreq == 32000) { |
| 120 | cng_swb_payload_type_ = audio_codec.pltype; |
| 121 | } else if (audio_codec.plfreq == 48000) { |
| 122 | cng_fb_payload_type_ = audio_codec.pltype; |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 123 | } else { |
| 124 | assert(false); |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 125 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | } |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 127 | } |
phoglund@webrtc.org | 244251a | 2013-02-04 13:23:07 +0000 | [diff] [blame] | 128 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | } |
| 130 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 131 | int32_t RTPReceiverAudio::ParseRtpPacket(WebRtcRTPHeader* rtp_header, |
| 132 | const PayloadUnion& specific_payload, |
| 133 | bool is_red, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 134 | const uint8_t* payload, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 135 | size_t payload_length, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 136 | int64_t timestamp_ms, |
| 137 | bool is_first_packet) { |
sprang@webrtc.org | 0200f70 | 2015-02-16 12:06:00 +0000 | [diff] [blame] | 138 | TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "Audio::ParseRtp", |
| 139 | "seqnum", rtp_header->header.sequenceNumber, "timestamp", |
| 140 | rtp_header->header.timestamp); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 141 | rtp_header->type.Audio.numEnergy = rtp_header->header.numCSRCs; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 142 | num_energy_ = rtp_header->type.Audio.numEnergy; |
| 143 | if (rtp_header->type.Audio.numEnergy > 0 && |
| 144 | rtp_header->type.Audio.numEnergy <= kRtpCsrcSize) { |
| 145 | memcpy(current_remote_energy_, |
| 146 | rtp_header->type.Audio.arrOfEnergy, |
| 147 | rtp_header->type.Audio.numEnergy); |
| 148 | } |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 149 | |
skvlad | 98bb664 | 2016-04-07 15:36:45 -0700 | [diff] [blame] | 150 | if (first_packet_received_()) { |
| 151 | LOG(LS_INFO) << "Received first audio RTP packet"; |
| 152 | } |
| 153 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 154 | return ParseAudioCodecSpecific(rtp_header, |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 155 | payload, |
minyue@webrtc.org | 663da0a | 2013-09-26 15:21:26 +0000 | [diff] [blame] | 156 | payload_length, |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 157 | specific_payload.Audio, |
| 158 | is_red); |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 159 | } |
| 160 | |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 161 | RTPAliveType RTPReceiverAudio::ProcessDeadOrAlive( |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 162 | uint16_t last_payload_length) const { |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 163 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 164 | // Our CNG is 9 bytes; if it's a likely CNG the receiver needs to check |
| 165 | // kRtpNoRtp against NetEq speech_type kOutputPLCtoCNG. |
| 166 | if (last_payload_length < 10) { // our CNG is 9 bytes |
| 167 | return kRtpNoRtp; |
| 168 | } else { |
| 169 | return kRtpDead; |
| 170 | } |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 171 | } |
| 172 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 173 | void RTPReceiverAudio::CheckPayloadChanged(int8_t payload_type, |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 174 | PayloadUnion* /* specific_payload */, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 175 | bool* should_discard_changes) { |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 176 | *should_discard_changes = |
| 177 | TelephoneEventPayloadType(payload_type) || CNGPayloadType(payload_type); |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 178 | } |
| 179 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 180 | int RTPReceiverAudio::Energy(uint8_t array_of_energy[kRtpCsrcSize]) const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 181 | rtc::CritScope cs(&crit_sect_); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 182 | |
| 183 | assert(num_energy_ <= kRtpCsrcSize); |
| 184 | |
| 185 | if (num_energy_ > 0) { |
| 186 | memcpy(array_of_energy, current_remote_energy_, |
| 187 | sizeof(uint8_t) * num_energy_); |
| 188 | } |
| 189 | return num_energy_; |
| 190 | } |
| 191 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 192 | int32_t RTPReceiverAudio::InvokeOnInitializeDecoder( |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 193 | RtpFeedback* callback, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 194 | int8_t payload_type, |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 195 | const char payload_name[RTP_PAYLOAD_NAME_SIZE], |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 196 | const PayloadUnion& specific_payload) const { |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 197 | if (-1 == |
| 198 | callback->OnInitializeDecoder( |
| 199 | payload_type, payload_name, specific_payload.Audio.frequency, |
| 200 | specific_payload.Audio.channels, specific_payload.Audio.rate)) { |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 +0000 | [diff] [blame] | 201 | LOG(LS_ERROR) << "Failed to create decoder for payload type: " |
pkasting@chromium.org | 026b892 | 2015-01-30 19:53:42 +0000 | [diff] [blame] | 202 | << payload_name << "/" << static_cast<int>(payload_type); |
phoglund@webrtc.org | 07bf43c | 2012-12-18 15:40:53 +0000 | [diff] [blame] | 203 | return -1; |
| 204 | } |
| 205 | return 0; |
| 206 | } |
| 207 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 208 | // We are not allowed to have any critsects when calling data_callback. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 209 | int32_t RTPReceiverAudio::ParseAudioCodecSpecific( |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 210 | WebRtcRTPHeader* rtp_header, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 211 | const uint8_t* payload_data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 212 | size_t payload_length, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 213 | const AudioPayload& audio_specific, |
| 214 | bool is_red) { |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 215 | RTC_DCHECK_GE(payload_length, rtp_header->header.paddingLength); |
| 216 | const size_t payload_data_length = |
| 217 | payload_length - rtp_header->header.paddingLength; |
| 218 | if (payload_data_length == 0) { |
| 219 | rtp_header->type.Audio.isCNG = false; |
| 220 | rtp_header->frameType = kEmptyFrame; |
| 221 | return data_callback_->OnReceivedPayloadData(nullptr, 0, rtp_header); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | bool telephone_event_packet = |
| 225 | TelephoneEventPayloadType(rtp_header->header.payloadType); |
| 226 | if (telephone_event_packet) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 227 | rtc::CritScope lock(&crit_sect_); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 228 | |
| 229 | // RFC 4733 2.3 |
| 230 | // 0 1 2 3 |
| 231 | // 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 |
| 232 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 233 | // | event |E|R| volume | duration | |
| 234 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 235 | // |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 236 | if (payload_data_length % 4 != 0) { |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 237 | return -1; |
| 238 | } |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 239 | size_t number_of_events = payload_data_length / 4; |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 240 | |
| 241 | // sanity |
| 242 | if (number_of_events >= MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS) { |
| 243 | number_of_events = MAX_NUMBER_OF_PARALLEL_TELEPHONE_EVENTS; |
| 244 | } |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 245 | for (size_t n = 0; n < number_of_events; ++n) { |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 246 | RTC_DCHECK_GE(payload_data_length, (4 * n) + 2); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 247 | bool end = (payload_data[(4 * n) + 1] & 0x80) ? true : false; |
| 248 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 249 | std::set<uint8_t>::iterator event = |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 250 | telephone_event_reported_.find(payload_data[4 * n]); |
| 251 | |
| 252 | if (event != telephone_event_reported_.end()) { |
| 253 | // we have already seen this event |
| 254 | if (end) { |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 255 | telephone_event_reported_.erase(payload_data[4 * n]); |
| 256 | } |
| 257 | } else { |
| 258 | if (end) { |
| 259 | // don't add if it's a end of a tone |
| 260 | } else { |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 261 | telephone_event_reported_.insert(payload_data[4 * n]); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // RFC 4733 2.5.1.3 & 2.5.2.3 Long-Duration Events |
| 267 | // should not be a problem since we don't care about the duration |
| 268 | |
| 269 | // RFC 4733 See 2.5.1.5. & 2.5.2.4. Multiple Events in a Packet |
| 270 | } |
| 271 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 272 | { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 273 | rtc::CritScope lock(&crit_sect_); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 274 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 275 | // Check if this is a CNG packet, receiver might want to know |
ossu | 425a6cc | 2016-10-05 08:44:22 -0700 | [diff] [blame] | 276 | if (CNGPayloadType(rtp_header->header.payloadType)) { |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 277 | rtp_header->type.Audio.isCNG = true; |
| 278 | rtp_header->frameType = kAudioFrameCN; |
| 279 | } else { |
| 280 | rtp_header->frameType = kAudioFrameSpeech; |
| 281 | rtp_header->type.Audio.isCNG = false; |
| 282 | } |
| 283 | |
| 284 | // check if it's a DTMF event, hence something we can playout |
| 285 | if (telephone_event_packet) { |
danilchap | 799a9d0 | 2016-09-22 03:36:27 -0700 | [diff] [blame] | 286 | if (!telephone_event_forward_to_decoder_) { |
| 287 | // don't forward event to decoder |
| 288 | return 0; |
| 289 | } |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 290 | std::set<uint8_t>::iterator first = |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 291 | telephone_event_reported_.begin(); |
| 292 | if (first != telephone_event_reported_.end() && *first > 15) { |
| 293 | // don't forward non DTMF events |
| 294 | return 0; |
| 295 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 296 | } |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 297 | } |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 298 | // TODO(holmer): Break this out to have RED parsing handled generically. |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 299 | RTC_DCHECK_GT(payload_data_length, 0); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 300 | if (is_red && !(payload_data[0] & 0x80)) { |
| 301 | // we recive only one frame packed in a RED packet remove the RED wrapper |
| 302 | rtp_header->header.payloadType = payload_data[0]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 304 | // only one frame in the RED strip the one byte to help NetEq |
phoglund@webrtc.org | a22a9bd | 2013-01-14 10:01:55 +0000 | [diff] [blame] | 305 | return data_callback_->OnReceivedPayloadData( |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 306 | payload_data + 1, payload_data_length - 1, rtp_header); |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | rtp_header->type.Audio.channel = audio_specific.channels; |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 310 | return data_callback_->OnReceivedPayloadData(payload_data, |
| 311 | payload_data_length, rtp_header); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 312 | } |
phoglund@webrtc.org | a7303bd | 2013-02-05 15:12:39 +0000 | [diff] [blame] | 313 | } // namespace webrtc |