Reland Remove the deprecated EncodeInternal interface from AudioEncoder
Remove the deprecated EncodeInternal interface from AudioEncoder
Also hid MaxEncodedBytes by making it private. It will get removed as soon as subclasses have had time to remove their overrides.
BUG=webrtc:5591
Review URL: https://codereview.webrtc.org/1881003003
Cr-Commit-Position: refs/heads/master@{#12409}
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.cc b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
index 6f793e2..fa262c4 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.cc
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
@@ -37,55 +37,6 @@
return info;
}
-AudioEncoder::EncodedInfo AudioEncoder::Encode(
- uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
- return DEPRECATED_Encode(rtp_timestamp, audio, max_encoded_bytes, encoded);
-}
-
-AudioEncoder::EncodedInfo AudioEncoder::DEPRECATED_Encode(
- uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded) {
- TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
- RTC_CHECK_EQ(audio.size(),
- static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
- EncodedInfo info =
- EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded);
- RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes);
- return info;
-}
-
-AudioEncoder::EncodedInfo AudioEncoder::EncodeImpl(
- uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- rtc::Buffer* encoded)
-{
- EncodedInfo info;
- encoded->AppendData(MaxEncodedBytes(), [&] (rtc::ArrayView<uint8_t> encoded) {
- info = EncodeInternal(rtp_timestamp, audio,
- encoded.size(), encoded.data());
- return info.encoded_bytes;
- });
- return info;
-}
-
-AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal(
- uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded)
-{
- rtc::Buffer temp_buffer;
- EncodedInfo info = EncodeImpl(rtp_timestamp, audio, &temp_buffer);
- RTC_DCHECK_LE(temp_buffer.size(), max_encoded_bytes);
- std::memcpy(encoded, temp_buffer.data(), info.encoded_bytes);
- return info;
-}
-
bool AudioEncoder::SetFec(bool enable) {
return !enable;
}
@@ -104,4 +55,9 @@
void AudioEncoder::SetTargetBitrate(int target_bps) {}
+size_t AudioEncoder::MaxEncodedBytes() const {
+ RTC_CHECK(false);
+ return 0;
+}
+
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.h b/webrtc/modules/audio_coding/codecs/audio_encoder.h
index 3fdee25..58d9fff 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.h
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.h
@@ -52,14 +52,6 @@
virtual ~AudioEncoder() = default;
- // Returns the maximum number of bytes that can be produced by the encoder
- // at each Encode() call. The caller can use the return value to determine
- // the size of the buffer that needs to be allocated. This value is allowed
- // to depend on encoder parameters like bitrate, frame size etc., so if
- // any of these change, the caller of Encode() is responsible for checking
- // that the buffer is large enough by calling MaxEncodedBytes() again.
- virtual size_t MaxEncodedBytes() const = 0;
-
// Returns the input sample rate in Hz and the number of input channels.
// These are constants set at instantiation time.
virtual int SampleRateHz() const = 0;
@@ -95,33 +87,6 @@
rtc::ArrayView<const int16_t> audio,
rtc::Buffer* encoded);
- // Deprecated interface to Encode (remove eventually, bug 5591). May incur a
- // copy. The encoder produces zero or more bytes of output in |encoded| and
- // returns additional encoding information. The caller is responsible for
- // making sure that |max_encoded_bytes| is not smaller than the number of
- // bytes actually produced by the encoder.
- RTC_DEPRECATED EncodedInfo Encode(uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded);
-
- EncodedInfo DEPRECATED_Encode(uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded);
-
- // Deprecated interface EncodeInternal (see bug 5591). May incur a copy.
- // Subclasses implement this to perform the actual encoding. Called by
- // Encode(). By default, this is implemented as a call to the newer
- // EncodeImpl() that accepts an rtc::Buffer instead of a raw pointer.
- // That version is protected, so see below. At least one of EncodeInternal
- // or EncodeImpl _must_ be implemented by a subclass.
- virtual EncodedInfo EncodeInternal(
- uint32_t rtp_timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded);
-
// Resets the encoder to its starting state, discarding any input that has
// been fed to the encoder but not yet emitted in a packet.
virtual void Reset() = 0;
@@ -162,13 +127,19 @@
protected:
// Subclasses implement this to perform the actual encoding. Called by
- // Encode(). For compatibility reasons, this is implemented by default as a
- // call to the older interface EncodeInternal(). At least one of
- // EncodeInternal or EncodeImpl _must_ be implemented by a
- // subclass. Preferably this one.
+ // Encode().
virtual EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
- rtc::Buffer* encoded);
+ rtc::Buffer* encoded) = 0;
+
+ private:
+ // This function is deprecated. It was used to return the maximum number of
+ // bytes that can be produced by the encoder at each Encode() call. Since the
+ // Encode interface was changed to use rtc::Buffer, this is no longer
+ // applicable. It is only kept in to avoid breaking subclasses that still have
+ // it implemented (with the override attribute). It will be removed as soon
+ // as these subclasses have been given a chance to change.
+ virtual size_t MaxEncodedBytes() const;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc b/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
deleted file mode 100644
index 71ffcde..0000000
--- a/webrtc/modules/audio_coding/codecs/audio_encoder_unittest.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h"
-
-using ::testing::_;
-using ::testing::Invoke;
-using ::testing::Return;
-
-namespace webrtc {
-
-TEST(AudioEncoderTest, EncodeInternalRedirectsOk) {
- const size_t kPayloadSize = 16;
- const uint8_t payload[kPayloadSize] =
- {0xf, 0xe, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8,
- 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0};
-
- MockAudioEncoderDeprecated old_impl;
- MockAudioEncoder new_impl;
- MockAudioEncoderBase* impls[] = { &old_impl, &new_impl };
- for (auto* impl : impls) {
- EXPECT_CALL(*impl, Die());
- EXPECT_CALL(*impl, MaxEncodedBytes())
- .WillRepeatedly(Return(kPayloadSize * 2));
- EXPECT_CALL(*impl, NumChannels()).WillRepeatedly(Return(1));
- EXPECT_CALL(*impl, SampleRateHz()).WillRepeatedly(Return(8000));
- }
-
- EXPECT_CALL(old_impl, EncodeInternal(_, _, _, _)).WillOnce(
- Invoke(MockAudioEncoderDeprecated::CopyEncoding(payload)));
-
- EXPECT_CALL(new_impl, EncodeImpl(_, _, _)).WillOnce(
- Invoke(MockAudioEncoder::CopyEncoding(payload)));
-
- int16_t audio[80];
- uint8_t output_array[kPayloadSize * 2];
- rtc::Buffer output_buffer;
-
- AudioEncoder* old_encoder = &old_impl;
- AudioEncoder* new_encoder = &new_impl;
- auto old_info = old_encoder->Encode(0, audio, &output_buffer);
- auto new_info = new_encoder->DEPRECATED_Encode(0, audio,
- kPayloadSize * 2,
- output_array);
-
- EXPECT_EQ(old_info.encoded_bytes, kPayloadSize);
- EXPECT_EQ(new_info.encoded_bytes, kPayloadSize);
- EXPECT_EQ(output_buffer.size(), kPayloadSize);
-
- for (size_t i = 0; i != kPayloadSize; ++i) {
- EXPECT_EQ(output_buffer.data()[i], payload[i]);
- EXPECT_EQ(output_array[i], payload[i]);
- }
-}
-
-} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
index 2f80944..04b635d 100644
--- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
+++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc
@@ -72,13 +72,6 @@
AudioEncoderCng::~AudioEncoderCng() = default;
-size_t AudioEncoderCng::MaxEncodedBytes() const {
- const size_t max_encoded_bytes_active = speech_encoder_->MaxEncodedBytes();
- const size_t max_encoded_bytes_passive =
- rtc::CheckedDivExact(kMaxFrameSizeMs, 10) * SamplesPer10msFrame();
- return std::max(max_encoded_bytes_active, max_encoded_bytes_passive);
-}
-
int AudioEncoderCng::SampleRateHz() const {
return speech_encoder_->SampleRateHz();
}
diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h
index 1384cd5..b52665d 100644
--- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h
+++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h
@@ -52,7 +52,6 @@
explicit AudioEncoderCng(Config&& config);
~AudioEncoderCng() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
int RtpTimestampRateHz() const override;
diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc
index 8f30d78..8b80d21 100644
--- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng_unittest.cc
@@ -25,7 +25,6 @@
namespace webrtc {
namespace {
-static const size_t kMockMaxEncodedBytes = 1000;
static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo.
static const size_t kMockReturnEncodedBytes = 17;
static const int kCngPayloadType = 18;
@@ -74,8 +73,6 @@
// as long as it is smaller than 10.
EXPECT_CALL(*mock_encoder_, Max10MsFramesInAPacket())
.WillOnce(Return(1u));
- EXPECT_CALL(*mock_encoder_, MaxEncodedBytes())
- .WillRepeatedly(Return(kMockMaxEncodedBytes));
}
cng_.reset(new AudioEncoderCng(std::move(config)));
}
@@ -90,8 +87,8 @@
}
// Expect |num_calls| calls to the encoder, all successful. The last call
- // claims to have encoded |kMockMaxEncodedBytes| bytes, and all the preceding
- // ones 0 bytes.
+ // claims to have encoded |kMockReturnEncodedBytes| bytes, and all the
+ // preceding ones 0 bytes.
void ExpectEncodeCalls(size_t num_calls) {
InSequence s;
AudioEncoder::EncodedInfo info;
diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
index a24b152..e4da8d7 100644
--- a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
+++ b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc
@@ -52,10 +52,6 @@
AudioEncoderPcm::~AudioEncoderPcm() = default;
-size_t AudioEncoderPcm::MaxEncodedBytes() const {
- return full_frame_samples_ * BytesPerSample();
-}
-
int AudioEncoderPcm::SampleRateHz() const {
return sample_rate_hz_;
}
@@ -93,7 +89,7 @@
info.encoded_timestamp = first_timestamp_in_buffer_;
info.payload_type = payload_type_;
info.encoded_bytes =
- encoded->AppendData(MaxEncodedBytes(),
+ encoded->AppendData(full_frame_samples_ * BytesPerSample(),
[&] (rtc::ArrayView<uint8_t> encoded) {
return EncodeCall(&speech_buffer_[0],
full_frame_samples_,
diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h
index 6b3cebfb..eb5ad02 100644
--- a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h
+++ b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h
@@ -35,7 +35,6 @@
~AudioEncoderPcm() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
size_t Num10MsFramesInNextPacket() const override;
diff --git a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
index 9256518..2560132 100644
--- a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
+++ b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
@@ -60,10 +60,6 @@
AudioEncoderG722::~AudioEncoderG722() = default;
-size_t AudioEncoderG722::MaxEncodedBytes() const {
- return SamplesPerChannel() / 2 * num_channels_;
-}
-
int AudioEncoderG722::SampleRateHz() const {
return kSampleRateHz;
}
diff --git a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h
index dec87b2..b3f6965 100644
--- a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h
+++ b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h
@@ -35,7 +35,6 @@
explicit AudioEncoderG722(const CodecInst& codec_inst);
~AudioEncoderG722() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
int RtpTimestampRateHz() const override;
@@ -44,7 +43,7 @@
int GetTargetBitrate() const override;
void Reset() override;
-protected:
+ protected:
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
rtc::Buffer* encoded) override;
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc b/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
index c7d7411..45401a1 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
+++ b/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc
@@ -56,10 +56,6 @@
RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
}
-size_t AudioEncoderIlbc::MaxEncodedBytes() const {
- return RequiredOutputSizeBytes();
-}
-
int AudioEncoderIlbc::SampleRateHz() const {
return kSampleRateHz;
}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h b/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h
index 27329bb..6363986 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h
@@ -34,7 +34,6 @@
explicit AudioEncoderIlbc(const CodecInst& codec_inst);
~AudioEncoderIlbc() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
size_t Num10MsFramesInNextPacket() const override;
diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h
index 0da8ed7..afe38d7 100644
--- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h
+++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t.h
@@ -56,7 +56,6 @@
const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo);
~AudioEncoderIsacT() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
size_t Num10MsFramesInNextPacket() const override;
diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h
index 1debbeb..1f95e59 100644
--- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h
+++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h
@@ -80,11 +80,6 @@
}
template <typename T>
-size_t AudioEncoderIsacT<T>::MaxEncodedBytes() const {
- return kSufficientEncodeBufferSizeBytes;
-}
-
-template <typename T>
int AudioEncoderIsacT<T>::SampleRateHz() const {
return T::EncSampRate(isac_state_);
}
diff --git a/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.cc b/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.cc
index 5284969..a674eba 100644
--- a/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.cc
+++ b/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.cc
@@ -49,26 +49,4 @@
return info_;
}
-MockAudioEncoderDeprecated::CopyEncoding::CopyEncoding(
- AudioEncoder::EncodedInfo info,
- rtc::ArrayView<const uint8_t> payload)
- : info_(info), payload_(payload) { }
-
-MockAudioEncoderDeprecated::CopyEncoding::CopyEncoding(
- rtc::ArrayView<const uint8_t> payload)
- : payload_(payload) {
- info_.encoded_bytes = payload_.size();
-}
-
-AudioEncoder::EncodedInfo MockAudioEncoderDeprecated::CopyEncoding::operator()(
- uint32_t timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_bytes_encoded,
- uint8_t* encoded) {
- RTC_CHECK(encoded);
- RTC_CHECK_LE(info_.encoded_bytes, payload_.size());
- std::memcpy(encoded, payload_.data(), info_.encoded_bytes);
- return info_;
-}
-
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h b/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h
index 58a1e75..f898877 100644
--- a/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h
+++ b/webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h
@@ -18,12 +18,11 @@
namespace webrtc {
-class MockAudioEncoderBase : public AudioEncoder {
+class MockAudioEncoder : public AudioEncoder {
public:
- ~MockAudioEncoderBase() override { Die(); }
+ ~MockAudioEncoder() override { Die(); }
MOCK_METHOD0(Die, void());
MOCK_METHOD1(Mark, void(std::string desc));
- MOCK_CONST_METHOD0(MaxEncodedBytes, size_t());
MOCK_CONST_METHOD0(SampleRateHz, int());
MOCK_CONST_METHOD0(NumChannels, size_t());
MOCK_CONST_METHOD0(RtpTimestampRateHz, int());
@@ -39,10 +38,7 @@
MOCK_METHOD1(SetTargetBitrate, void(int target_bps));
MOCK_METHOD1(SetMaxBitrate, void(int max_bps));
MOCK_METHOD1(SetMaxPayloadSize, void(int max_payload_size_bytes));
-};
-class MockAudioEncoder final : public MockAudioEncoderBase {
- public:
// Note, we explicitly chose not to create a mock for the Encode method.
MOCK_METHOD3(EncodeImpl,
EncodedInfo(uint32_t timestamp,
@@ -89,36 +85,6 @@
AudioEncoder::EncodedInfo info_;
rtc::ArrayView<const uint8_t> payload_;
};
-
-};
-
-class MockAudioEncoderDeprecated final : public MockAudioEncoderBase {
- public:
- // Note, we explicitly chose not to create a mock for the Encode method.
- MOCK_METHOD4(EncodeInternal,
- EncodedInfo(uint32_t timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_encoded_bytes,
- uint8_t* encoded));
-
- // A functor like MockAudioEncoder::CopyEncoding above, but which has the
- // deprecated Encode signature. Currently only used in one test and should be
- // removed once that backwards compatibility is.
- class CopyEncoding {
- public:
- CopyEncoding(AudioEncoder::EncodedInfo info,
- rtc::ArrayView<const uint8_t> payload);
-
- CopyEncoding(rtc::ArrayView<const uint8_t> payload);
-
- AudioEncoder::EncodedInfo operator()(uint32_t timestamp,
- rtc::ArrayView<const int16_t> audio,
- size_t max_bytes_encoded,
- uint8_t* encoded);
- private:
- AudioEncoder::EncodedInfo info_;
- rtc::ArrayView<const uint8_t> payload_;
- };
};
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
index a599e29..799d122 100644
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
@@ -100,16 +100,6 @@
RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
}
-size_t AudioEncoderOpus::MaxEncodedBytes() const {
- // Calculate the number of bytes we expect the encoder to produce,
- // then multiply by two to give a wide margin for error.
- const size_t bytes_per_millisecond =
- static_cast<size_t>(config_.bitrate_bps / (1000 * 8) + 1);
- const size_t approx_encoded_bytes =
- Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
- return 2 * approx_encoded_bytes;
-}
-
int AudioEncoderOpus::SampleRateHz() const {
return kSampleRateHz;
}
@@ -198,7 +188,7 @@
RTC_CHECK_EQ(input_buffer_.size(),
Num10msFramesPerPacket() * SamplesPer10msFrame());
- const size_t max_encoded_bytes = MaxEncodedBytes();
+ const size_t max_encoded_bytes = SufficientOutputBufferSize();
EncodedInfo info;
info.encoded_bytes =
encoded->AppendData(
@@ -231,6 +221,16 @@
return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels;
}
+size_t AudioEncoderOpus::SufficientOutputBufferSize() const {
+ // Calculate the number of bytes we expect the encoder to produce,
+ // then multiply by two to give a wide margin for error.
+ const size_t bytes_per_millisecond =
+ static_cast<size_t>(config_.bitrate_bps / (1000 * 8) + 1);
+ const size_t approx_encoded_bytes =
+ Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
+ return 2 * approx_encoded_bytes;
+}
+
// If the given config is OK, recreate the Opus encoder instance with those
// settings, save the config, and return true. Otherwise, do nothing and return
// false.
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h
index 3f11af1..8900659 100644
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h
@@ -54,7 +54,6 @@
explicit AudioEncoderOpus(const CodecInst& codec_inst);
~AudioEncoderOpus() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
size_t Num10MsFramesInNextPacket() const override;
@@ -79,7 +78,7 @@
ApplicationMode application() const { return config_.application; }
bool dtx_enabled() const { return config_.dtx_enabled; }
-protected:
+ protected:
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
rtc::Buffer* encoded) override;
@@ -87,6 +86,7 @@
private:
size_t Num10msFramesPerPacket() const;
size_t SamplesPer10msFrame() const;
+ size_t SufficientOutputBufferSize() const;
bool RecreateEncoderInstance(const Config& config);
Config config_;
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
index b4e95d3..7c48c0c 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
@@ -30,10 +30,6 @@
AudioEncoderCopyRed::~AudioEncoderCopyRed() = default;
-size_t AudioEncoderCopyRed::MaxEncodedBytes() const {
- return 2 * speech_encoder_->MaxEncodedBytes();
-}
-
int AudioEncoderCopyRed::SampleRateHz() const {
return speech_encoder_->SampleRateHz();
}
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
index a67ae48..06d0fde 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
@@ -37,7 +37,6 @@
~AudioEncoderCopyRed() override;
- size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
size_t NumChannels() const override;
int RtpTimestampRateHz() const override;
@@ -52,7 +51,7 @@
void SetProjectedPacketLossRate(double fraction) override;
void SetTargetBitrate(int target_bps) override;
-protected:
+ protected:
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
rtc::Buffer* encoded) override;
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
index c73cb9f..22b2ceb 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc
@@ -26,7 +26,6 @@
namespace webrtc {
namespace {
-static const size_t kMockMaxEncodedBytes = 1000;
static const size_t kMaxNumSamples = 48 * 10 * 2; // 10 ms @ 48 kHz stereo.
}
@@ -46,8 +45,6 @@
EXPECT_CALL(*mock_encoder_, NumChannels()).WillRepeatedly(Return(1U));
EXPECT_CALL(*mock_encoder_, SampleRateHz())
.WillRepeatedly(Return(sample_rate_hz_));
- EXPECT_CALL(*mock_encoder_, MaxEncodedBytes())
- .WillRepeatedly(Return(kMockMaxEncodedBytes));
}
void TearDown() override {