| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 cng_fb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 178 cng_fb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 thread_checker_.DetachFromThread(); | 182 thread_checker_.DetachFromThread(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 CodecManager::~CodecManager() = default; | 185 CodecManager::~CodecManager() = default; |
| 186 | 186 |
| 187 int CodecManager::RegisterEncoder(const CodecInst& send_codec) { | 187 int CodecManager::RegisterEncoder(const CodecInst& send_codec) { |
| 188 DCHECK(thread_checker_.CalledOnValidThread()); | 188 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 189 int codec_id = IsValidSendCodec(send_codec, true); | 189 int codec_id = IsValidSendCodec(send_codec, true); |
| 190 | 190 |
| 191 // Check for reported errors from function IsValidSendCodec(). | 191 // Check for reported errors from function IsValidSendCodec(). |
| 192 if (codec_id < 0) { | 192 if (codec_id < 0) { |
| 193 return -1; | 193 return -1; |
| 194 } | 194 } |
| 195 | 195 |
| 196 int dummy_id = 0; | 196 int dummy_id = 0; |
| 197 // RED can be registered with other payload type. If not registered a default | 197 // RED can be registered with other payload type. If not registered a default |
| 198 // payload type is used. | 198 // payload type is used. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 257 } |
| 258 dtx_enabled_ = false; | 258 dtx_enabled_ = false; |
| 259 } else { | 259 } else { |
| 260 stereo_send_ = false; | 260 stereo_send_ = false; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Check if the codec is already registered as send codec. | 263 // Check if the codec is already registered as send codec. |
| 264 bool new_codec = true; | 264 bool new_codec = true; |
| 265 if (codec_owner_.Encoder()) { | 265 if (codec_owner_.Encoder()) { |
| 266 int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_); | 266 int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_); |
| 267 DCHECK_GE(new_codec_id, 0); | 267 RTC_DCHECK_GE(new_codec_id, 0); |
| 268 new_codec = new_codec_id != codec_id; | 268 new_codec = new_codec_id != codec_id; |
| 269 } | 269 } |
| 270 | 270 |
| 271 if (RedPayloadType(send_codec.plfreq) == -1) { | 271 if (RedPayloadType(send_codec.plfreq) == -1) { |
| 272 red_enabled_ = false; | 272 red_enabled_ = false; |
| 273 } | 273 } |
| 274 | 274 |
| 275 encoder_is_opus_ = IsOpus(send_codec); | 275 encoder_is_opus_ = IsOpus(send_codec); |
| 276 | 276 |
| 277 if (new_codec) { | 277 if (new_codec) { |
| 278 // This is a new codec. Register it and return. | 278 // This is a new codec. Register it and return. |
| 279 DCHECK(CodecSupported(send_codec)); | 279 RTC_DCHECK(CodecSupported(send_codec)); |
| 280 if (IsOpus(send_codec)) { | 280 if (IsOpus(send_codec)) { |
| 281 // VAD/DTX not supported. | 281 // VAD/DTX not supported. |
| 282 dtx_enabled_ = false; | 282 dtx_enabled_ = false; |
| 283 } | 283 } |
| 284 codec_owner_.SetEncoders( | 284 codec_owner_.SetEncoders( |
| 285 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 285 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
| 286 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); | 286 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
| 287 DCHECK(codec_owner_.Encoder()); | 287 RTC_DCHECK(codec_owner_.Encoder()); |
| 288 | 288 |
| 289 codec_fec_enabled_ = codec_fec_enabled_ && | 289 codec_fec_enabled_ = codec_fec_enabled_ && |
| 290 codec_owner_.Encoder()->SetFec(codec_fec_enabled_); | 290 codec_owner_.Encoder()->SetFec(codec_fec_enabled_); |
| 291 | 291 |
| 292 send_codec_inst_ = send_codec; | 292 send_codec_inst_ = send_codec; |
| 293 return 0; | 293 return 0; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // This is an existing codec; re-create it if any parameters have changed. | 296 // This is an existing codec; re-create it if any parameters have changed. |
| 297 if (send_codec_inst_.plfreq != send_codec.plfreq || | 297 if (send_codec_inst_.plfreq != send_codec.plfreq || |
| 298 send_codec_inst_.pacsize != send_codec.pacsize || | 298 send_codec_inst_.pacsize != send_codec.pacsize || |
| 299 send_codec_inst_.channels != send_codec.channels) { | 299 send_codec_inst_.channels != send_codec.channels) { |
| 300 codec_owner_.SetEncoders( | 300 codec_owner_.SetEncoders( |
| 301 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 301 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
| 302 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); | 302 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
| 303 DCHECK(codec_owner_.Encoder()); | 303 RTC_DCHECK(codec_owner_.Encoder()); |
| 304 } | 304 } |
| 305 send_codec_inst_.plfreq = send_codec.plfreq; | 305 send_codec_inst_.plfreq = send_codec.plfreq; |
| 306 send_codec_inst_.pacsize = send_codec.pacsize; | 306 send_codec_inst_.pacsize = send_codec.pacsize; |
| 307 send_codec_inst_.channels = send_codec.channels; | 307 send_codec_inst_.channels = send_codec.channels; |
| 308 send_codec_inst_.pltype = send_codec.pltype; | 308 send_codec_inst_.pltype = send_codec.pltype; |
| 309 | 309 |
| 310 // Check if a change in Rate is required. | 310 // Check if a change in Rate is required. |
| 311 if (send_codec.rate != send_codec_inst_.rate) { | 311 if (send_codec.rate != send_codec_inst_.rate) { |
| 312 codec_owner_.Encoder()->SetTargetBitrate(send_codec.rate); | 312 codec_owner_.Encoder()->SetTargetBitrate(send_codec.rate); |
| 313 send_codec_inst_.rate = send_codec.rate; | 313 send_codec_inst_.rate = send_codec.rate; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 int cng_pt = dtx_enabled_ ? CngPayloadType(send_codec_inst_.plfreq) : -1; | 374 int cng_pt = dtx_enabled_ ? CngPayloadType(send_codec_inst_.plfreq) : -1; |
| 375 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; | 375 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; |
| 376 codec_owner_.ChangeCngAndRed(cng_pt, vad_mode_, red_pt); | 376 codec_owner_.ChangeCngAndRed(cng_pt, vad_mode_, red_pt); |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 return true; | 379 return true; |
| 380 } | 380 } |
| 381 | 381 |
| 382 int CodecManager::SetVAD(bool enable, ACMVADMode mode) { | 382 int CodecManager::SetVAD(bool enable, ACMVADMode mode) { |
| 383 // Sanity check of the mode. | 383 // Sanity check of the mode. |
| 384 DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr || | 384 RTC_DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr || |
| 385 mode == VADVeryAggr); | 385 mode == VADVeryAggr); |
| 386 | 386 |
| 387 // Check that the send codec is mono. We don't support VAD/DTX for stereo | 387 // Check that the send codec is mono. We don't support VAD/DTX for stereo |
| 388 // sending. | 388 // sending. |
| 389 if (enable && stereo_send_) { | 389 if (enable && stereo_send_) { |
| 390 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0, | 390 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0, |
| 391 "VAD/DTX not supported for stereo sending"); | 391 "VAD/DTX not supported for stereo sending"); |
| 392 dtx_enabled_ = false; | 392 dtx_enabled_ = false; |
| 393 return -1; | 393 return -1; |
| 394 } | 394 } |
| 395 | 395 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 420 *mode = vad_mode_; | 420 *mode = vad_mode_; |
| 421 } | 421 } |
| 422 | 422 |
| 423 int CodecManager::SetCodecFEC(bool enable_codec_fec) { | 423 int CodecManager::SetCodecFEC(bool enable_codec_fec) { |
| 424 if (enable_codec_fec == true && red_enabled_ == true) { | 424 if (enable_codec_fec == true && red_enabled_ == true) { |
| 425 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, | 425 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, |
| 426 "Codec internal FEC and RED cannot be co-enabled."); | 426 "Codec internal FEC and RED cannot be co-enabled."); |
| 427 return -1; | 427 return -1; |
| 428 } | 428 } |
| 429 | 429 |
| 430 CHECK(codec_owner_.Encoder()); | 430 RTC_CHECK(codec_owner_.Encoder()); |
| 431 codec_fec_enabled_ = | 431 codec_fec_enabled_ = |
| 432 codec_owner_.Encoder()->SetFec(enable_codec_fec) && enable_codec_fec; | 432 codec_owner_.Encoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
| 433 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; | 433 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; |
| 434 } | 434 } |
| 435 | 435 |
| 436 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 436 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
| 437 return IsIsac(codec) ? codec_owner_.GetIsacDecoder() : nullptr; | 437 return IsIsac(codec) ? codec_owner_.GetIsacDecoder() : nullptr; |
| 438 } | 438 } |
| 439 | 439 |
| 440 int CodecManager::CngPayloadType(int sample_rate_hz) const { | 440 int CodecManager::CngPayloadType(int sample_rate_hz) const { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 462 case 48000: | 462 case 48000: |
| 463 return -1; | 463 return -1; |
| 464 default: | 464 default: |
| 465 FATAL() << sample_rate_hz << " Hz is not supported"; | 465 FATAL() << sample_rate_hz << " Hz is not supported"; |
| 466 return -1; | 466 return -1; |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 | 469 |
| 470 } // namespace acm2 | 470 } // namespace acm2 |
| 471 } // namespace webrtc | 471 } // namespace webrtc |
| OLD | NEW |