Chromium Code Reviews| Index: webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
| diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
| index a7d9df457c1133c79db9752116a106837ed99bf7..34bf87f0f2407706449fefa0128f9abe3133cd21 100644 |
| --- a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
| +++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
| @@ -221,16 +221,28 @@ void AudioCodingModuleImpl::RegisterExternalSendCodec( |
| encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); |
| } |
| +void AudioCodingModuleImpl::VisitEncoder(const EncoderVisitor& ev) { |
|
hlundin-webrtc
2016/02/10 09:45:46
Rename function to ModifyEncoder, or something sim
|
| + rtc::CritScope lock(&acm_crit_sect_); |
| + |
| + // Wipe the encoder factory, so that everything that relies on it will fail. |
| + // We don't want the complexity of supporting swapping back and forth. |
| + encoder_factory_.reset(); |
| + |
| + encoder_stack_ = ev(encoder_stack_); |
| +} |
| + |
| // Get current send codec. |
| rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const { |
| rtc::CritScope lock(&acm_crit_sect_); |
| - auto* ci = encoder_factory_->codec_manager.GetCodecInst(); |
| - if (ci) { |
| - return rtc::Optional<CodecInst>(*ci); |
| + if (encoder_factory_) { |
| + auto* ci = encoder_factory_->codec_manager.GetCodecInst(); |
| + if (ci) { |
| + return rtc::Optional<CodecInst>(*ci); |
| + } |
| } |
| - auto* enc = encoder_factory_->codec_manager.GetStackParams()->speech_encoder; |
| - if (enc) { |
| - return rtc::Optional<CodecInst>(CodecManager::ForgeCodecInst(enc)); |
| + if (encoder_stack_) { |
| + return rtc::Optional<CodecInst>( |
| + CodecManager::ForgeCodecInst(encoder_stack_)); |
| } |
| return rtc::Optional<CodecInst>(); |
| } |
| @@ -580,10 +592,22 @@ int AudioCodingModuleImpl::PlayoutFrequency() const { |
| return receiver_.last_output_sample_rate_hz(); |
| } |
| -// Register possible receive codecs, can be called multiple times, |
| -// for codecs, CNG (NB, WB and SWB), DTMF, RED. |
| int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { |
| rtc::CritScope lock(&acm_crit_sect_); |
| + auto* ef = encoder_factory_.get(); |
| + return RegisterReceiveCodecUnlocked( |
| + codec, [ef] { return ef->rent_a_codec.RentIsacDecoder(); }); |
| +} |
| + |
| +int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec, |
| + const DecoderFactory& df) { |
| + rtc::CritScope lock(&acm_crit_sect_); |
| + return RegisterReceiveCodecUnlocked(codec, df); |
| +} |
| + |
| +int AudioCodingModuleImpl::RegisterReceiveCodecUnlocked( |
| + const CodecInst& codec, |
| + const DecoderFactory& df) { |
| RTC_DCHECK(receiver_initialized_); |
| if (codec.channels > 2) { |
| LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; |
| @@ -610,10 +634,7 @@ int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { |
| // not own its decoder. |
| return receiver_.AddCodec( |
| *codec_index, codec.pltype, codec.channels, codec.plfreq, |
| - STR_CASE_CMP(codec.plname, "isac") == 0 |
| - ? encoder_factory_->rent_a_codec.RentIsacDecoder() |
| - : nullptr, |
| - codec.plname); |
| + STR_CASE_CMP(codec.plname, "isac") == 0 ? df() : nullptr, codec.plname); |
| } |
| int AudioCodingModuleImpl::RegisterExternalReceiveCodec( |