Simplifying audio network adaptor by moving receiver frame length range to ctor.
It turns out that that audio network adaptor can always be created with knowledge of receiver frame length range. There is no need to keep some infrastructure that is used for runtime setting of receiver frame length ranges. BUG=webrtc:6303 Review-Url: https://codereview.webrtc.org/2429503002 Cr-Commit-Position: refs/heads/master@{#14748}
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/exp_filter.h"
|
||||
@ -42,6 +43,7 @@ AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
|
||||
config.payload_type = codec_inst.pltype;
|
||||
config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip
|
||||
: AudioEncoderOpus::kAudio;
|
||||
config.supported_frame_lengths_ms.push_back(config.frame_size_ms);
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -297,11 +299,21 @@ void AudioEncoderOpus::OnReceivedRtt(int rtt_ms) {
|
||||
|
||||
void AudioEncoderOpus::SetReceiverFrameLengthRange(int min_frame_length_ms,
|
||||
int max_frame_length_ms) {
|
||||
if (!audio_network_adaptor_)
|
||||
return;
|
||||
audio_network_adaptor_->SetReceiverFrameLengthRange(min_frame_length_ms,
|
||||
max_frame_length_ms);
|
||||
ApplyAudioNetworkAdaptor();
|
||||
// Ensure that |SetReceiverFrameLengthRange| is called before
|
||||
// |EnableAudioNetworkAdaptor|, otherwise we need to recreate
|
||||
// |audio_network_adaptor_|, which is not a needed use case.
|
||||
RTC_DCHECK(!audio_network_adaptor_);
|
||||
|
||||
config_.supported_frame_lengths_ms.clear();
|
||||
std::copy_if(std::begin(kSupportedFrameLengths),
|
||||
std::end(kSupportedFrameLengths),
|
||||
std::back_inserter(config_.supported_frame_lengths_ms),
|
||||
[&](int frame_length_ms) {
|
||||
return frame_length_ms >= min_frame_length_ms &&
|
||||
frame_length_ms <= max_frame_length_ms;
|
||||
});
|
||||
RTC_DCHECK(std::is_sorted(config_.supported_frame_lengths_ms.begin(),
|
||||
config_.supported_frame_lengths_ms.end()));
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl(
|
||||
@ -447,7 +459,7 @@ AudioEncoderOpus::DefaultAudioNetworkAdaptorCreator(
|
||||
config.clock = clock;
|
||||
return std::unique_ptr<AudioNetworkAdaptor>(new AudioNetworkAdaptorImpl(
|
||||
config, ControllerManagerImpl::Create(
|
||||
config_string, NumChannels(), kSupportedFrameLengths,
|
||||
config_string, NumChannels(), supported_frame_lengths_ms(),
|
||||
num_channels_to_encode_, next_frame_length_ms_,
|
||||
GetTargetBitrate(), config_.fec_enabled, GetDtx(), clock)));
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ class AudioEncoderOpus final : public AudioEncoder {
|
||||
int max_playback_rate_hz = 48000;
|
||||
int complexity = kDefaultComplexity;
|
||||
bool dtx_enabled = false;
|
||||
std::vector<int> supported_frame_lengths_ms;
|
||||
const Clock* clock = nullptr;
|
||||
|
||||
private:
|
||||
@ -102,6 +103,9 @@ class AudioEncoderOpus final : public AudioEncoder {
|
||||
void OnReceivedRtt(int rtt_ms) override;
|
||||
void SetReceiverFrameLengthRange(int min_frame_length_ms,
|
||||
int max_frame_length_ms) override;
|
||||
rtc::ArrayView<const int> supported_frame_lengths_ms() const {
|
||||
return config_.supported_frame_lengths_ms;
|
||||
}
|
||||
|
||||
// Getters for testing.
|
||||
double packet_loss_rate() const { return packet_loss_rate_; }
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_audio_network_adaptor.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
|
||||
#include "webrtc/test/gmock.h"
|
||||
#include "webrtc/test/gtest.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
|
||||
@ -34,6 +35,7 @@ AudioEncoderOpus::Config CreateConfig(const CodecInst& codec_inst) {
|
||||
config.payload_type = codec_inst.pltype;
|
||||
config.application = config.num_channels == 1 ? AudioEncoderOpus::kVoip
|
||||
: AudioEncoderOpus::kAudio;
|
||||
config.supported_frame_lengths_ms.push_back(config.frame_size_ms);
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -222,9 +224,25 @@ TEST(AudioEncoderOpusTest, PacketLossRateOptimized) {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
TEST(AudioEncoderOpusTest, SetReceiverFrameLengthRange) {
|
||||
auto states = CreateCodec(2);
|
||||
// Before calling to |SetReceiverFrameLengthRange|,
|
||||
// |supported_frame_lengths_ms| should contain only the frame length being
|
||||
// used.
|
||||
using ::testing::ElementsAre;
|
||||
EXPECT_THAT(states.encoder->supported_frame_lengths_ms(),
|
||||
ElementsAre(states.encoder->next_frame_length_ms()));
|
||||
states.encoder->SetReceiverFrameLengthRange(0, 12345);
|
||||
EXPECT_THAT(states.encoder->supported_frame_lengths_ms(),
|
||||
ElementsAre(20, 60));
|
||||
states.encoder->SetReceiverFrameLengthRange(21, 60);
|
||||
EXPECT_THAT(states.encoder->supported_frame_lengths_ms(), ElementsAre(60));
|
||||
states.encoder->SetReceiverFrameLengthRange(20, 59);
|
||||
EXPECT_THAT(states.encoder->supported_frame_lengths_ms(), ElementsAre(20));
|
||||
}
|
||||
|
||||
TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetUplinkBandwidth) {
|
||||
auto states = CreateCodec(2);
|
||||
printf("passed!\n");
|
||||
states.encoder->EnableAudioNetworkAdaptor("", nullptr);
|
||||
|
||||
auto config = CreateEncoderRuntimeConfig();
|
||||
@ -291,24 +309,6 @@ TEST(AudioEncoderOpusTest, InvokeAudioNetworkAdaptorOnSetRtt) {
|
||||
CheckEncoderRuntimeConfig(states.encoder.get(), config);
|
||||
}
|
||||
|
||||
TEST(AudioEncoderOpusTest,
|
||||
InvokeAudioNetworkAdaptorOnSetReceiverFrameLengthRange) {
|
||||
auto states = CreateCodec(2);
|
||||
states.encoder->EnableAudioNetworkAdaptor("", nullptr);
|
||||
|
||||
auto config = CreateEncoderRuntimeConfig();
|
||||
EXPECT_CALL(**states.mock_audio_network_adaptor, GetEncoderRuntimeConfig())
|
||||
.WillOnce(Return(config));
|
||||
|
||||
constexpr int kMinFrameLength = 10;
|
||||
constexpr int kMaxFrameLength = 60;
|
||||
EXPECT_CALL(**states.mock_audio_network_adaptor,
|
||||
SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength));
|
||||
states.encoder->SetReceiverFrameLengthRange(kMinFrameLength, kMaxFrameLength);
|
||||
|
||||
CheckEncoderRuntimeConfig(states.encoder.get(), config);
|
||||
}
|
||||
|
||||
TEST(AudioEncoderOpusTest,
|
||||
PacketLossFractionSmoothedOnSetUplinkPacketLossFraction) {
|
||||
auto states = CreateCodec(2);
|
||||
|
||||
Reference in New Issue
Block a user