Don't recreate the speech encoder if we don't have to

If the specification for the speech encoder hasn't changed, we should
reuse it instead of recreating it. Otherwise, we lose its state. (This
problem was originally discovered because AudioEncoderOpus instances
would forget that they were supposed to be using DTX.)

BUG=webrtc:6020, chromium:622647

Review-Url: https://codereview.webrtc.org/2089183002
Cr-Commit-Position: refs/heads/master@{#13273}
This commit is contained in:
kwiberg
2016-06-23 03:58:36 -07:00
committed by Commit bot
parent 1fdcc28b25
commit 3f81fcd2e8
9 changed files with 93 additions and 21 deletions

View File

@ -123,4 +123,9 @@ void AudioEncoderCopyRed::SetTargetBitrate(int bits_per_second) {
speech_encoder_->SetTargetBitrate(bits_per_second);
}
rtc::ArrayView<std::unique_ptr<AudioEncoder>>
AudioEncoderCopyRed::ReclaimContainedEncoders() {
return rtc::ArrayView<std::unique_ptr<AudioEncoder>>(&speech_encoder_, 1);
}
} // namespace webrtc

View File

@ -51,6 +51,8 @@ class AudioEncoderCopyRed final : public AudioEncoder {
void SetMaxPlaybackRate(int frequency_hz) override;
void SetProjectedPacketLossRate(double fraction) override;
void SetTargetBitrate(int target_bps) override;
rtc::ArrayView<std::unique_ptr<AudioEncoder>> ReclaimContainedEncoders()
override;
protected:
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,