Implement AudioEncoder::GetFrameLengthRange() for all audio encoders.
The WebRTC-SendSideBwe-WithOverhead field trial requires audio encoders to properly implement the AudioEncoder::GetFrameLengthRange() function. Thic CL implements the function for all audio encoders in WebRTC in preparation for making that function pure virtual in the interface. Bug: webrtc:11427 Change-Id: Ieab6b6c72c62af6ac9525a20fcb39bd477079551 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/171503 Reviewed-by: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Minyue Li <minyue@webrtc.org> Commit-Queue: Minyue Li <minyue@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30890}
This commit is contained in:
@ -14,6 +14,8 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/audio_coding/codecs/cng/webrtc_cng.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
@ -55,6 +57,8 @@ class AudioEncoderCng final : public AudioEncoder {
|
||||
void OnReceivedUplinkBandwidth(
|
||||
int target_audio_bitrate_bps,
|
||||
absl::optional<int64_t> bwe_period_ms) override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
private:
|
||||
EncodedInfo EncodePassive(size_t frames_to_encode, rtc::Buffer* encoded);
|
||||
@ -225,6 +229,11 @@ void AudioEncoderCng::OnReceivedUplinkBandwidth(
|
||||
bwe_period_ms);
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderCng::GetFrameLengthRange() const {
|
||||
return speech_encoder_->GetFrameLengthRange();
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
|
||||
size_t frames_to_encode,
|
||||
rtc::Buffer* encoded) {
|
||||
|
@ -21,8 +21,11 @@
|
||||
#include "test/testsupport/rtc_expect_death.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Eq;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Not;
|
||||
using ::testing::Optional;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
|
||||
@ -233,6 +236,15 @@ TEST_F(AudioEncoderCngTest, CheckPacketLossFractionPropagation) {
|
||||
cng_->OnReceivedUplinkPacketLossFraction(0.5);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, CheckGetFrameLengthRangePropagation) {
|
||||
CreateCng(MakeCngConfig());
|
||||
auto expected_range =
|
||||
std::make_pair(TimeDelta::Millis(20), TimeDelta::Millis(20));
|
||||
EXPECT_CALL(*mock_encoder_, GetFrameLengthRange())
|
||||
.WillRepeatedly(Return(absl::make_optional(expected_range)));
|
||||
EXPECT_THAT(cng_->GetFrameLengthRange(), Optional(Eq(expected_range)));
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCngTest, EncodeCallsVad) {
|
||||
EXPECT_CALL(*mock_encoder_, Num10MsFramesInNextPacket())
|
||||
.WillRepeatedly(Return(1U));
|
||||
|
@ -89,6 +89,12 @@ void AudioEncoderPcm::Reset() {
|
||||
speech_buffer_.clear();
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderPcm::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(num_10ms_frames_per_packet_ * 10),
|
||||
TimeDelta::Millis(num_10ms_frames_per_packet_ * 10)}};
|
||||
}
|
||||
|
||||
size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio,
|
||||
size_t input_len,
|
||||
uint8_t* encoded) {
|
||||
|
@ -11,9 +11,12 @@
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_G711_AUDIO_ENCODER_PCM_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_G711_AUDIO_ENCODER_PCM_H_
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -41,6 +44,8 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
size_t Max10MsFramesInAPacket() const override;
|
||||
int GetTargetBitrate() const override;
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
protected:
|
||||
AudioEncoderPcm(const Config& config, int sample_rate_hz);
|
||||
|
@ -79,6 +79,12 @@ void AudioEncoderG722Impl::Reset() {
|
||||
RTC_CHECK_EQ(0, WebRtcG722_EncoderInit(encoders_[i].encoder));
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderG722Impl::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(num_10ms_frames_per_packet_ * 10),
|
||||
TimeDelta::Millis(num_10ms_frames_per_packet_ * 10)}};
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderG722Impl::EncodeImpl(
|
||||
uint32_t rtp_timestamp,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
|
@ -12,9 +12,12 @@
|
||||
#define MODULES_AUDIO_CODING_CODECS_G722_AUDIO_ENCODER_G722_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/audio_codecs/g722/audio_encoder_g722_config.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/audio_coding/codecs/g722/g722_interface.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
@ -33,6 +36,8 @@ class AudioEncoderG722Impl final : public AudioEncoder {
|
||||
size_t Max10MsFramesInAPacket() const override;
|
||||
int GetTargetBitrate() const override;
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
protected:
|
||||
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
|
||||
|
@ -127,6 +127,12 @@ void AudioEncoderIlbcImpl::Reset() {
|
||||
num_10ms_frames_buffered_ = 0;
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderIlbcImpl::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(num_10ms_frames_per_packet_ * 10),
|
||||
TimeDelta::Millis(num_10ms_frames_per_packet_ * 10)}};
|
||||
}
|
||||
|
||||
size_t AudioEncoderIlbcImpl::RequiredOutputSizeBytes() const {
|
||||
switch (num_10ms_frames_per_packet_) {
|
||||
case 2:
|
||||
|
@ -11,8 +11,12 @@
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_ILBC_AUDIO_ENCODER_ILBC_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ILBC_AUDIO_ENCODER_ILBC_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/audio_codecs/ilbc/audio_encoder_ilbc_config.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/audio_coding/codecs/ilbc/ilbc.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
@ -32,6 +36,8 @@ class AudioEncoderIlbcImpl final : public AudioEncoder {
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) override;
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
private:
|
||||
size_t RequiredOutputSizeBytes() const;
|
||||
|
@ -11,10 +11,13 @@
|
||||
#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
|
||||
#define MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -49,6 +52,8 @@ class AudioEncoderIsacT final : public AudioEncoder {
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
rtc::Buffer* encoded) override;
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
private:
|
||||
// This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and
|
||||
|
@ -119,6 +119,13 @@ void AudioEncoderIsacT<T>::Reset() {
|
||||
RecreateEncoderInstance(config_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderIsacT<T>::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(config_.frame_size_ms),
|
||||
TimeDelta::Millis(config_.frame_size_ms)}};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void AudioEncoderIsacT<T>::RecreateEncoderInstance(const Config& config) {
|
||||
RTC_CHECK(config.IsOk());
|
||||
|
@ -164,6 +164,12 @@ void AudioEncoderMultiChannelOpusImpl::Reset() {
|
||||
RTC_CHECK(RecreateEncoderInstance(config_));
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderMultiChannelOpusImpl::GetFrameLengthRange() const {
|
||||
return {{TimeDelta::Millis(config_.frame_size_ms),
|
||||
TimeDelta::Millis(config_.frame_size_ms)}};
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
@ -12,12 +12,14 @@
|
||||
#define MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_MULTI_CHANNEL_OPUS_IMPL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/audio_codecs/opus/audio_encoder_multi_channel_opus_config.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
@ -44,6 +46,8 @@ class AudioEncoderMultiChannelOpusImpl final : public AudioEncoder {
|
||||
int GetTargetBitrate() const override;
|
||||
|
||||
void Reset() override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
protected:
|
||||
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
|
||||
|
@ -132,4 +132,9 @@ void AudioEncoderCopyRed::OnReceivedUplinkBandwidth(
|
||||
bwe_period_ms);
|
||||
}
|
||||
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>>
|
||||
AudioEncoderCopyRed::GetFrameLengthRange() const {
|
||||
return speech_encoder_->GetFrameLengthRange();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -15,10 +15,12 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/audio_codecs/audio_encoder.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
@ -60,6 +62,8 @@ class AudioEncoderCopyRed final : public AudioEncoder {
|
||||
void OnReceivedUplinkBandwidth(
|
||||
int target_audio_bitrate_bps,
|
||||
absl::optional<int64_t> bwe_period_ms) override;
|
||||
absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange()
|
||||
const override;
|
||||
|
||||
protected:
|
||||
EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
|
||||
|
@ -20,9 +20,12 @@
|
||||
#include "test/testsupport/rtc_expect_death.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Eq;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::MockFunction;
|
||||
using ::testing::Not;
|
||||
using ::testing::Optional;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
|
||||
@ -107,6 +110,14 @@ TEST_F(AudioEncoderCopyRedTest, CheckPacketLossFractionPropagation) {
|
||||
red_->OnReceivedUplinkPacketLossFraction(0.5);
|
||||
}
|
||||
|
||||
TEST_F(AudioEncoderCopyRedTest, CheckGetFrameLengthRangePropagation) {
|
||||
auto expected_range =
|
||||
std::make_pair(TimeDelta::Millis(20), TimeDelta::Millis(20));
|
||||
EXPECT_CALL(*mock_encoder_, GetFrameLengthRange())
|
||||
.WillRepeatedly(Return(absl::make_optional(expected_range)));
|
||||
EXPECT_THAT(red_->GetFrameLengthRange(), Optional(Eq(expected_range)));
|
||||
}
|
||||
|
||||
// Checks that the an Encode() call is immediately propagated to the speech
|
||||
// encoder.
|
||||
TEST_F(AudioEncoderCopyRedTest, CheckImmediateEncode) {
|
||||
|
Reference in New Issue
Block a user