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:
@ -60,4 +60,7 @@ void AudioEncoder::SetProjectedPacketLossRate(double fraction) {}
|
||||
|
||||
void AudioEncoder::SetTargetBitrate(int target_bps) {}
|
||||
|
||||
rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
||||
AudioEncoder::ReclaimContainedEncoders() { return nullptr; }
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -149,6 +149,15 @@ class AudioEncoder {
|
||||
// implementation does the latter).
|
||||
virtual void SetTargetBitrate(int target_bps);
|
||||
|
||||
// Causes this encoder to let go of any other encoders it contains, and
|
||||
// returns a pointer to an array where they are stored (which is required to
|
||||
// live as long as this encoder). Unless the returned array is empty, you may
|
||||
// not call any methods on this encoder afterwards, except for the
|
||||
// destructor. The default implementation just returns an empty array.
|
||||
// NOTE: This method is subject to change. Do not call or override it.
|
||||
virtual rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
||||
ReclaimContainedEncoders();
|
||||
|
||||
protected:
|
||||
// Subclasses implement this to perform the actual encoding. Called by
|
||||
// Encode().
|
||||
|
||||
@ -187,6 +187,11 @@ void AudioEncoderCng::SetTargetBitrate(int bits_per_second) {
|
||||
speech_encoder_->SetTargetBitrate(bits_per_second);
|
||||
}
|
||||
|
||||
rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
||||
AudioEncoderCng::ReclaimContainedEncoders() {
|
||||
return rtc::ArrayView<std::unique_ptr<AudioEncoder>>(&speech_encoder_, 1);
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
|
||||
size_t frames_to_encode,
|
||||
rtc::Buffer* encoded) {
|
||||
|
||||
@ -63,6 +63,8 @@ class AudioEncoderCng 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;
|
||||
|
||||
private:
|
||||
EncodedInfo EncodePassive(size_t frames_to_encode,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user