Chromium Code Reviews| Index: webrtc/modules/audio_coding/acm2/codec_manager.cc |
| diff --git a/webrtc/modules/audio_coding/acm2/codec_manager.cc b/webrtc/modules/audio_coding/acm2/codec_manager.cc |
| index 81adf81a83cf46c9862fce7c371d28edb5085bf0..f028c45f99130eb205d3818ac691b348ca9946e0 100644 |
| --- a/webrtc/modules/audio_coding/acm2/codec_manager.cc |
| +++ b/webrtc/modules/audio_coding/acm2/codec_manager.cc |
| @@ -113,7 +113,7 @@ bool CodecManager::RegisterEncoder(const CodecInst& send_codec) { |
| } |
| send_codec_inst_ = rtc::Optional<CodecInst>(send_codec); |
| - codec_stack_params_.speech_encoder.reset(); // Caller must recreate it. |
| + recreate_encoder_ = true; // Caller must recreate it. |
| return true; |
| } |
| @@ -190,5 +190,67 @@ bool CodecManager::SetCodecFEC(bool enable_codec_fec) { |
| return true; |
| } |
| +bool CodecManager::MakeEncoder(RentACodec* rac, AudioCodingModule* acm) { |
| + RTC_DCHECK(rac); |
| + RTC_DCHECK(acm); |
| + |
| + if (!recreate_encoder_) { |
|
ossu
2016/06/23 08:32:07
The flow of this whole function is pretty difficul
kwiberg-webrtc
2016/06/23 10:31:51
Hmm. Yes, that's possible. We change the cng and r
hlundin-webrtc
2016/06/23 10:38:46
Speed is of importance here.
|
| + bool error = false; |
| + // Try to re-use the speech encoder we've given to the ACM. |
| + acm->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
| + if (!*encoder) { |
| + // There is no existing encoder. |
| + recreate_encoder_ = true; |
| + return; |
| + } |
| + |
| + // Extract the speech encoder from the ACM. |
| + std::unique_ptr<AudioEncoder> enc = std::move(*encoder); |
| + while (true) { |
| + auto sub_enc = enc->ReclaimContainedEncoders(); |
| + if (sub_enc.empty()) { |
| + break; |
| + } |
| + RTC_CHECK_EQ(1u, sub_enc.size()); |
| + |
| + // Replace enc with its sub encoder. We need to put the sub encoder in |
| + // a temporary first, since otherwise the old value of enc would be |
| + // destroyed before the new value got assigned, which would be bad |
| + // since the new value is a part of the old value. |
| + auto tmp_enc = std::move(sub_enc[0]); |
| + enc = std::move(tmp_enc); |
| + } |
| + |
| + // Wrap it in a new encoder stack and put it back. |
| + codec_stack_params_.speech_encoder = std::move(enc); |
| + *encoder = rac->RentEncoderStack(&codec_stack_params_); |
| + if (!*encoder) { |
| + error = true; |
| + } |
| + }); |
| + if (error) { |
| + return false; |
| + } |
| + if (!recreate_encoder_) { |
| + return true; |
| + } |
| + } |
| + |
| + if (!send_codec_inst_) { |
| + // We don't have the information we need to create a new speech encoder. |
| + // (This is not an error.) |
| + return true; |
|
hlundin-webrtc
2016/06/23 07:46:36
Should recreate_encoder_ be modified here?
kwiberg-webrtc
2016/06/23 10:31:51
No. It's currently true, and should be true becaus
hlundin-webrtc
2016/06/23 10:38:46
Acknowledged.
|
| + } |
| + |
| + codec_stack_params_.speech_encoder = rac->RentEncoder(*send_codec_inst_); |
| + auto stack = rac->RentEncoderStack(&codec_stack_params_); |
| + if (!stack) { |
| + return false; |
|
hlundin-webrtc
2016/06/23 07:46:36
.. and here?
kwiberg-webrtc
2016/06/23 10:31:51
Same reasoning as above. We should only set it on
hlundin-webrtc
2016/06/23 10:38:47
Acknowledged.
|
| + } |
| + acm->SetEncoder(std::move(stack)); |
| + recreate_encoder_ = false; |
| + return true; |
| +} |
| + |
| } // namespace acm2 |
| } // namespace webrtc |