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 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 AudioCodingModuleImpl::AudioCodingModuleImpl( | 103 AudioCodingModuleImpl::AudioCodingModuleImpl( |
104 const AudioCodingModule::Config& config) | 104 const AudioCodingModule::Config& config) |
105 : id_(config.id), | 105 : id_(config.id), |
106 expected_codec_ts_(0xD87F3F9F), | 106 expected_codec_ts_(0xD87F3F9F), |
107 expected_in_ts_(0xD87F3F9F), | 107 expected_in_ts_(0xD87F3F9F), |
108 receiver_(config), | 108 receiver_(config), |
109 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), | 109 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), |
| 110 encoder_factory_(new EncoderFactory), |
110 encoder_stack_(nullptr), | 111 encoder_stack_(nullptr), |
111 previous_pltype_(255), | 112 previous_pltype_(255), |
112 receiver_initialized_(false), | 113 receiver_initialized_(false), |
113 first_10ms_data_(false), | 114 first_10ms_data_(false), |
114 first_frame_(true), | 115 first_frame_(true), |
115 packetization_callback_(NULL), | 116 packetization_callback_(NULL), |
116 vad_callback_(NULL) { | 117 vad_callback_(NULL) { |
117 if (InitializeReceiverSafe() < 0) { | 118 if (InitializeReceiverSafe() < 0) { |
118 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, | 119 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, |
119 "Cannot initialize receiver"); | 120 "Cannot initialize receiver"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return static_cast<int32_t>(encode_buffer_.size()); | 189 return static_cast<int32_t>(encode_buffer_.size()); |
189 } | 190 } |
190 | 191 |
191 ///////////////////////////////////////// | 192 ///////////////////////////////////////// |
192 // Sender | 193 // Sender |
193 // | 194 // |
194 | 195 |
195 // Can be called multiple times for Codec, CNG, RED. | 196 // Can be called multiple times for Codec, CNG, RED. |
196 int AudioCodingModuleImpl::RegisterSendCodec(const CodecInst& send_codec) { | 197 int AudioCodingModuleImpl::RegisterSendCodec(const CodecInst& send_codec) { |
197 rtc::CritScope lock(&acm_crit_sect_); | 198 rtc::CritScope lock(&acm_crit_sect_); |
198 if (!codec_manager_.RegisterEncoder(send_codec)) { | 199 if (!encoder_factory_->codec_manager.RegisterEncoder(send_codec)) { |
199 return -1; | 200 return -1; |
200 } | 201 } |
201 auto* sp = codec_manager_.GetStackParams(); | 202 auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
202 if (!sp->speech_encoder && codec_manager_.GetCodecInst()) { | 203 if (!sp->speech_encoder && encoder_factory_->codec_manager.GetCodecInst()) { |
203 // We have no speech encoder, but we have a specification for making one. | 204 // We have no speech encoder, but we have a specification for making one. |
204 AudioEncoder* enc = | 205 AudioEncoder* enc = encoder_factory_->rent_a_codec.RentEncoder( |
205 rent_a_codec_.RentEncoder(*codec_manager_.GetCodecInst()); | 206 *encoder_factory_->codec_manager.GetCodecInst()); |
206 if (!enc) | 207 if (!enc) |
207 return -1; | 208 return -1; |
208 sp->speech_encoder = enc; | 209 sp->speech_encoder = enc; |
209 } | 210 } |
210 if (sp->speech_encoder) | 211 if (sp->speech_encoder) |
211 encoder_stack_ = rent_a_codec_.RentEncoderStack(sp); | 212 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
212 return 0; | 213 return 0; |
213 } | 214 } |
214 | 215 |
215 void AudioCodingModuleImpl::RegisterExternalSendCodec( | 216 void AudioCodingModuleImpl::RegisterExternalSendCodec( |
216 AudioEncoder* external_speech_encoder) { | 217 AudioEncoder* external_speech_encoder) { |
217 rtc::CritScope lock(&acm_crit_sect_); | 218 rtc::CritScope lock(&acm_crit_sect_); |
218 auto* sp = codec_manager_.GetStackParams(); | 219 auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
219 sp->speech_encoder = external_speech_encoder; | 220 sp->speech_encoder = external_speech_encoder; |
220 encoder_stack_ = rent_a_codec_.RentEncoderStack(sp); | 221 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
221 } | 222 } |
222 | 223 |
223 // Get current send codec. | 224 // Get current send codec. |
224 rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const { | 225 rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const { |
225 rtc::CritScope lock(&acm_crit_sect_); | 226 rtc::CritScope lock(&acm_crit_sect_); |
226 auto* ci = codec_manager_.GetCodecInst(); | 227 auto* ci = encoder_factory_->codec_manager.GetCodecInst(); |
227 if (ci) { | 228 if (ci) { |
228 return rtc::Optional<CodecInst>(*ci); | 229 return rtc::Optional<CodecInst>(*ci); |
229 } | 230 } |
230 auto* enc = codec_manager_.GetStackParams()->speech_encoder; | 231 auto* enc = encoder_factory_->codec_manager.GetStackParams()->speech_encoder; |
231 if (enc) { | 232 if (enc) { |
232 return rtc::Optional<CodecInst>(CodecManager::ForgeCodecInst(enc)); | 233 return rtc::Optional<CodecInst>(CodecManager::ForgeCodecInst(enc)); |
233 } | 234 } |
234 return rtc::Optional<CodecInst>(); | 235 return rtc::Optional<CodecInst>(); |
235 } | 236 } |
236 | 237 |
237 // Get current send frequency. | 238 // Get current send frequency. |
238 int AudioCodingModuleImpl::SendFrequency() const { | 239 int AudioCodingModuleImpl::SendFrequency() const { |
239 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, | 240 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, |
240 "SendFrequency()"); | 241 "SendFrequency()"); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 436 |
436 return 0; | 437 return 0; |
437 } | 438 } |
438 | 439 |
439 ///////////////////////////////////////// | 440 ///////////////////////////////////////// |
440 // (RED) Redundant Coding | 441 // (RED) Redundant Coding |
441 // | 442 // |
442 | 443 |
443 bool AudioCodingModuleImpl::REDStatus() const { | 444 bool AudioCodingModuleImpl::REDStatus() const { |
444 rtc::CritScope lock(&acm_crit_sect_); | 445 rtc::CritScope lock(&acm_crit_sect_); |
445 return codec_manager_.GetStackParams()->use_red; | 446 return encoder_factory_->codec_manager.GetStackParams()->use_red; |
446 } | 447 } |
447 | 448 |
448 // Configure RED status i.e on/off. | 449 // Configure RED status i.e on/off. |
449 int AudioCodingModuleImpl::SetREDStatus(bool enable_red) { | 450 int AudioCodingModuleImpl::SetREDStatus(bool enable_red) { |
450 #ifdef WEBRTC_CODEC_RED | 451 #ifdef WEBRTC_CODEC_RED |
451 rtc::CritScope lock(&acm_crit_sect_); | 452 rtc::CritScope lock(&acm_crit_sect_); |
452 if (!codec_manager_.SetCopyRed(enable_red)) { | 453 if (!encoder_factory_->codec_manager.SetCopyRed(enable_red)) { |
453 return -1; | 454 return -1; |
454 } | 455 } |
455 auto* sp = codec_manager_.GetStackParams(); | 456 auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
456 if (sp->speech_encoder) | 457 if (sp->speech_encoder) |
457 encoder_stack_ = rent_a_codec_.RentEncoderStack(sp); | 458 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
458 return 0; | 459 return 0; |
459 #else | 460 #else |
460 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, | 461 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, |
461 " WEBRTC_CODEC_RED is undefined"); | 462 " WEBRTC_CODEC_RED is undefined"); |
462 return -1; | 463 return -1; |
463 #endif | 464 #endif |
464 } | 465 } |
465 | 466 |
466 ///////////////////////////////////////// | 467 ///////////////////////////////////////// |
467 // (FEC) Forward Error Correction (codec internal) | 468 // (FEC) Forward Error Correction (codec internal) |
468 // | 469 // |
469 | 470 |
470 bool AudioCodingModuleImpl::CodecFEC() const { | 471 bool AudioCodingModuleImpl::CodecFEC() const { |
471 rtc::CritScope lock(&acm_crit_sect_); | 472 rtc::CritScope lock(&acm_crit_sect_); |
472 return codec_manager_.GetStackParams()->use_codec_fec; | 473 return encoder_factory_->codec_manager.GetStackParams()->use_codec_fec; |
473 } | 474 } |
474 | 475 |
475 int AudioCodingModuleImpl::SetCodecFEC(bool enable_codec_fec) { | 476 int AudioCodingModuleImpl::SetCodecFEC(bool enable_codec_fec) { |
476 rtc::CritScope lock(&acm_crit_sect_); | 477 rtc::CritScope lock(&acm_crit_sect_); |
477 if (!codec_manager_.SetCodecFEC(enable_codec_fec)) { | 478 if (!encoder_factory_->codec_manager.SetCodecFEC(enable_codec_fec)) { |
478 return -1; | 479 return -1; |
479 } | 480 } |
480 auto* sp = codec_manager_.GetStackParams(); | 481 auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
481 if (sp->speech_encoder) | 482 if (sp->speech_encoder) |
482 encoder_stack_ = rent_a_codec_.RentEncoderStack(sp); | 483 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
483 if (enable_codec_fec) { | 484 if (enable_codec_fec) { |
484 return sp->use_codec_fec ? 0 : -1; | 485 return sp->use_codec_fec ? 0 : -1; |
485 } else { | 486 } else { |
486 RTC_DCHECK(!sp->use_codec_fec); | 487 RTC_DCHECK(!sp->use_codec_fec); |
487 return 0; | 488 return 0; |
488 } | 489 } |
489 } | 490 } |
490 | 491 |
491 int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) { | 492 int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) { |
492 rtc::CritScope lock(&acm_crit_sect_); | 493 rtc::CritScope lock(&acm_crit_sect_); |
493 if (HaveValidEncoder("SetPacketLossRate")) { | 494 if (HaveValidEncoder("SetPacketLossRate")) { |
494 encoder_stack_->SetProjectedPacketLossRate(loss_rate / 100.0); | 495 encoder_stack_->SetProjectedPacketLossRate(loss_rate / 100.0); |
495 } | 496 } |
496 return 0; | 497 return 0; |
497 } | 498 } |
498 | 499 |
499 ///////////////////////////////////////// | 500 ///////////////////////////////////////// |
500 // (VAD) Voice Activity Detection | 501 // (VAD) Voice Activity Detection |
501 // | 502 // |
502 int AudioCodingModuleImpl::SetVAD(bool enable_dtx, | 503 int AudioCodingModuleImpl::SetVAD(bool enable_dtx, |
503 bool enable_vad, | 504 bool enable_vad, |
504 ACMVADMode mode) { | 505 ACMVADMode mode) { |
505 // Note: |enable_vad| is not used; VAD is enabled based on the DTX setting. | 506 // Note: |enable_vad| is not used; VAD is enabled based on the DTX setting. |
506 RTC_DCHECK_EQ(enable_dtx, enable_vad); | 507 RTC_DCHECK_EQ(enable_dtx, enable_vad); |
507 rtc::CritScope lock(&acm_crit_sect_); | 508 rtc::CritScope lock(&acm_crit_sect_); |
508 if (!codec_manager_.SetVAD(enable_dtx, mode)) { | 509 if (!encoder_factory_->codec_manager.SetVAD(enable_dtx, mode)) { |
509 return -1; | 510 return -1; |
510 } | 511 } |
511 auto* sp = codec_manager_.GetStackParams(); | 512 auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
512 if (sp->speech_encoder) | 513 if (sp->speech_encoder) |
513 encoder_stack_ = rent_a_codec_.RentEncoderStack(sp); | 514 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
514 return 0; | 515 return 0; |
515 } | 516 } |
516 | 517 |
517 // Get VAD/DTX settings. | 518 // Get VAD/DTX settings. |
518 int AudioCodingModuleImpl::VAD(bool* dtx_enabled, bool* vad_enabled, | 519 int AudioCodingModuleImpl::VAD(bool* dtx_enabled, bool* vad_enabled, |
519 ACMVADMode* mode) const { | 520 ACMVADMode* mode) const { |
520 rtc::CritScope lock(&acm_crit_sect_); | 521 rtc::CritScope lock(&acm_crit_sect_); |
521 const auto* sp = codec_manager_.GetStackParams(); | 522 const auto* sp = encoder_factory_->codec_manager.GetStackParams(); |
522 *dtx_enabled = *vad_enabled = sp->use_cng; | 523 *dtx_enabled = *vad_enabled = sp->use_cng; |
523 *mode = sp->vad_mode; | 524 *mode = sp->vad_mode; |
524 return 0; | 525 return 0; |
525 } | 526 } |
526 | 527 |
527 ///////////////////////////////////////// | 528 ///////////////////////////////////////// |
528 // Receiver | 529 // Receiver |
529 // | 530 // |
530 | 531 |
531 int AudioCodingModuleImpl::InitializeReceiver() { | 532 int AudioCodingModuleImpl::InitializeReceiver() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 if (!RentACodec::IsPayloadTypeValid(codec.pltype)) { | 603 if (!RentACodec::IsPayloadTypeValid(codec.pltype)) { |
603 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " | 604 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " |
604 << codec.plname; | 605 << codec.plname; |
605 return -1; | 606 return -1; |
606 } | 607 } |
607 | 608 |
608 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does | 609 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does |
609 // not own its decoder. | 610 // not own its decoder. |
610 return receiver_.AddCodec( | 611 return receiver_.AddCodec( |
611 *codec_index, codec.pltype, codec.channels, codec.plfreq, | 612 *codec_index, codec.pltype, codec.channels, codec.plfreq, |
612 STR_CASE_CMP(codec.plname, "isac") == 0 ? rent_a_codec_.RentIsacDecoder() | 613 STR_CASE_CMP(codec.plname, "isac") == 0 |
613 : nullptr, | 614 ? encoder_factory_->rent_a_codec.RentIsacDecoder() |
| 615 : nullptr, |
614 codec.plname); | 616 codec.plname); |
615 } | 617 } |
616 | 618 |
617 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( | 619 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( |
618 int rtp_payload_type, | 620 int rtp_payload_type, |
619 AudioDecoder* external_decoder, | 621 AudioDecoder* external_decoder, |
620 int sample_rate_hz, | 622 int sample_rate_hz, |
621 int num_channels, | 623 int num_channels, |
622 const std::string& name) { | 624 const std::string& name) { |
623 rtc::CritScope lock(&acm_crit_sect_); | 625 rtc::CritScope lock(&acm_crit_sect_); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 return receiver_.LeastRequiredDelayMs(); | 816 return receiver_.LeastRequiredDelayMs(); |
815 } | 817 } |
816 | 818 |
817 void AudioCodingModuleImpl::GetDecodingCallStatistics( | 819 void AudioCodingModuleImpl::GetDecodingCallStatistics( |
818 AudioDecodingCallStats* call_stats) const { | 820 AudioDecodingCallStats* call_stats) const { |
819 receiver_.GetDecodingCallStatistics(call_stats); | 821 receiver_.GetDecodingCallStatistics(call_stats); |
820 } | 822 } |
821 | 823 |
822 } // namespace acm2 | 824 } // namespace acm2 |
823 } // namespace webrtc | 825 } // namespace webrtc |
OLD | NEW |