| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 // Store current audio in |last_audio_buffer_| for next time. | 173 // Store current audio in |last_audio_buffer_| for next time. |
| 174 memcpy(last_audio_buffer_.get(), audio_frame->data_, | 174 memcpy(last_audio_buffer_.get(), audio_frame->data_, |
| 175 sizeof(int16_t) * audio_frame->samples_per_channel_ * | 175 sizeof(int16_t) * audio_frame->samples_per_channel_ * |
| 176 audio_frame->num_channels_); | 176 audio_frame->num_channels_); |
| 177 | 177 |
| 178 call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted); | 178 call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted); |
| 179 return 0; | 179 return 0; |
| 180 } | 180 } |
| 181 | 181 |
| 182 int32_t AcmReceiver::AddCodec(int acm_codec_id, | |
| 183 uint8_t payload_type, | |
| 184 size_t channels, | |
| 185 int /*sample_rate_hz*/, | |
| 186 AudioDecoder* audio_decoder, | |
| 187 const std::string& name) { | |
| 188 // TODO(kwiberg): This function has been ignoring the |sample_rate_hz| | |
| 189 // argument for a long time. Arguably, it should simply be removed. | |
| 190 | |
| 191 const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder { | |
| 192 if (acm_codec_id == -1) | |
| 193 return NetEqDecoder::kDecoderArbitrary; // External decoder. | |
| 194 const rtc::Optional<RentACodec::CodecId> cid = | |
| 195 RentACodec::CodecIdFromIndex(acm_codec_id); | |
| 196 RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id; | |
| 197 const rtc::Optional<NetEqDecoder> ned = | |
| 198 RentACodec::NetEqDecoderFromCodecId(*cid, channels); | |
| 199 RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast<int>(*cid); | |
| 200 return *ned; | |
| 201 }(); | |
| 202 const rtc::Optional<SdpAudioFormat> new_format = | |
| 203 RentACodec::NetEqDecoderToSdpAudioFormat(neteq_decoder); | |
| 204 | |
| 205 rtc::CritScope lock(&crit_sect_); | |
| 206 | |
| 207 const auto old_format = neteq_->GetDecoderFormat(payload_type); | |
| 208 if (old_format && new_format && *old_format == *new_format) { | |
| 209 // Re-registering the same codec. Do nothing and return. | |
| 210 return 0; | |
| 211 } | |
| 212 | |
| 213 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK && | |
| 214 neteq_->LastError() != NetEq::kDecoderNotFound) { | |
| 215 LOG(LERROR) << "Cannot remove payload " << static_cast<int>(payload_type); | |
| 216 return -1; | |
| 217 } | |
| 218 | |
| 219 int ret_val; | |
| 220 if (!audio_decoder) { | |
| 221 ret_val = neteq_->RegisterPayloadType(neteq_decoder, name, payload_type); | |
| 222 } else { | |
| 223 ret_val = neteq_->RegisterExternalDecoder( | |
| 224 audio_decoder, neteq_decoder, name, payload_type); | |
| 225 } | |
| 226 if (ret_val != NetEq::kOK) { | |
| 227 LOG(LERROR) << "AcmReceiver::AddCodec " << acm_codec_id | |
| 228 << static_cast<int>(payload_type) | |
| 229 << " channels: " << channels; | |
| 230 return -1; | |
| 231 } | |
| 232 return 0; | |
| 233 } | |
| 234 | |
| 235 bool AcmReceiver::AddCodec(int rtp_payload_type, | 182 bool AcmReceiver::AddCodec(int rtp_payload_type, |
| 236 const SdpAudioFormat& audio_format) { | 183 const SdpAudioFormat& audio_format) { |
| 237 const auto old_format = neteq_->GetDecoderFormat(rtp_payload_type); | 184 const auto old_format = neteq_->GetDecoderFormat(rtp_payload_type); |
| 238 if (old_format && *old_format == audio_format) { | 185 if (old_format && *old_format == audio_format) { |
| 239 // Re-registering the same codec. Do nothing and return. | 186 // Re-registering the same codec. Do nothing and return. |
| 240 return true; | 187 return true; |
| 241 } | 188 } |
| 242 | 189 |
| 243 if (neteq_->RemovePayloadType(rtp_payload_type) != NetEq::kOK && | 190 if (neteq_->RemovePayloadType(rtp_payload_type) != NetEq::kOK && |
| 244 neteq_->LastError() != NetEq::kDecoderNotFound) { | 191 neteq_->LastError() != NetEq::kDecoderNotFound) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 335 |
| 389 void AcmReceiver::GetDecodingCallStatistics( | 336 void AcmReceiver::GetDecodingCallStatistics( |
| 390 AudioDecodingCallStats* stats) const { | 337 AudioDecodingCallStats* stats) const { |
| 391 rtc::CritScope lock(&crit_sect_); | 338 rtc::CritScope lock(&crit_sect_); |
| 392 *stats = call_stats_.GetDecodingStatistics(); | 339 *stats = call_stats_.GetDecodingStatistics(); |
| 393 } | 340 } |
| 394 | 341 |
| 395 } // namespace acm2 | 342 } // namespace acm2 |
| 396 | 343 |
| 397 } // namespace webrtc | 344 } // namespace webrtc |
| OLD | NEW |