Pass Environment instead of just clock to AcmReceiver at construction
Passing Environment would allow to propage field trials with it further to NetEq and AudioDecoders Bug: webrtc:356878416 Change-Id: Ic68420df3b157ed341146207a2c45cb49e59a931 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358501 Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42728}
This commit is contained in:
parent
dc58bba2ed
commit
33582ea42f
@ -538,7 +538,8 @@ ChannelReceive::ChannelReceive(
|
||||
worker_thread_(TaskQueueBase::Current()),
|
||||
rtp_receive_statistics_(ReceiveStatistics::Create(&env_.clock())),
|
||||
remote_ssrc_(remote_ssrc),
|
||||
acm_receiver_(AcmConfig(neteq_factory,
|
||||
acm_receiver_(env_,
|
||||
AcmConfig(neteq_factory,
|
||||
decoder_factory,
|
||||
codec_pair_id,
|
||||
jitter_buffer_max_packets,
|
||||
|
||||
@ -51,7 +51,7 @@ AudioIngress::AudioIngress(
|
||||
first_rtp_timestamp_(-1),
|
||||
rtp_receive_statistics_(receive_statistics),
|
||||
rtp_rtcp_(rtp_rtcp),
|
||||
acm_receiver_(CreateAcmConfig(decoder_factory)),
|
||||
acm_receiver_(env_, CreateAcmConfig(decoder_factory)),
|
||||
ntp_estimator_(&env_.clock()) {}
|
||||
|
||||
AudioIngress::~AudioIngress() = default;
|
||||
|
||||
@ -46,6 +46,7 @@ rtc_library("audio_coding") {
|
||||
"../../api:function_view",
|
||||
"../../api/audio:audio_frame_api",
|
||||
"../../api/audio_codecs:audio_codecs_api",
|
||||
"../../api/environment",
|
||||
"../../api/neteq:neteq_api",
|
||||
"../../api/units:timestamp",
|
||||
"../../common_audio",
|
||||
@ -1138,6 +1139,7 @@ if (rtc_include_tests) {
|
||||
"../../api:scoped_refptr",
|
||||
"../../api/audio_codecs:audio_codecs_api",
|
||||
"../../api/audio_codecs:builtin_audio_decoder_factory",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../test:test_support",
|
||||
"//testing/gtest",
|
||||
]
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_coding/include/audio_coding_module.h"
|
||||
#include "modules/audio_coding/neteq/tools/audio_sink.h"
|
||||
#include "modules/audio_coding/neteq/tools/packet.h"
|
||||
@ -26,10 +27,8 @@ namespace test {
|
||||
|
||||
namespace {
|
||||
acm2::AcmReceiver::Config MakeAcmConfig(
|
||||
Clock& clock,
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory) {
|
||||
acm2::AcmReceiver::Config config;
|
||||
config.clock = clock;
|
||||
config.decoder_factory = std::move(decoder_factory);
|
||||
return config;
|
||||
}
|
||||
@ -43,7 +42,8 @@ AcmReceiveTestOldApi::AcmReceiveTestOldApi(
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory)
|
||||
: clock_(0),
|
||||
acm_receiver_(std::make_unique<acm2::AcmReceiver>(
|
||||
MakeAcmConfig(clock_, std::move(decoder_factory)))),
|
||||
CreateEnvironment(&clock_),
|
||||
MakeAcmConfig(std::move(decoder_factory)))),
|
||||
packet_source_(packet_source),
|
||||
audio_sink_(audio_sink),
|
||||
output_freq_hz_(output_freq_hz),
|
||||
|
||||
@ -51,17 +51,27 @@ std::unique_ptr<NetEq> CreateNetEq(
|
||||
|
||||
AcmReceiver::Config::Config(
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory)
|
||||
: clock(*Clock::GetRealTimeClock()), decoder_factory(decoder_factory) {}
|
||||
: decoder_factory(decoder_factory) {}
|
||||
|
||||
AcmReceiver::Config::Config(const Config&) = default;
|
||||
AcmReceiver::Config::~Config() = default;
|
||||
|
||||
AcmReceiver::AcmReceiver(const Config& config)
|
||||
: neteq_(CreateNetEq(config.neteq_factory,
|
||||
AcmReceiver::AcmReceiver(const Environment& env, Config config)
|
||||
: clock_(env.clock()),
|
||||
neteq_(CreateNetEq(config.neteq_factory,
|
||||
config.neteq_config,
|
||||
&config.clock,
|
||||
&clock_,
|
||||
config.decoder_factory)),
|
||||
resampled_last_output_frame_(true) {
|
||||
ClearSamples(last_audio_buffer_);
|
||||
}
|
||||
|
||||
AcmReceiver::AcmReceiver(const Config& config)
|
||||
: clock_(*Clock::GetRealTimeClock()),
|
||||
neteq_(CreateNetEq(config.neteq_factory,
|
||||
config.neteq_config,
|
||||
&clock_,
|
||||
config.decoder_factory)),
|
||||
clock_(config.clock),
|
||||
resampled_last_output_frame_(true) {
|
||||
ClearSamples(last_audio_buffer_);
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "api/neteq/neteq_factory.h"
|
||||
#include "api/units/timestamp.h"
|
||||
@ -52,13 +53,14 @@ class AcmReceiver {
|
||||
~Config();
|
||||
|
||||
NetEq::Config neteq_config;
|
||||
Clock& clock;
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
|
||||
NetEqFactory* neteq_factory = nullptr;
|
||||
};
|
||||
|
||||
// Constructor of the class
|
||||
explicit AcmReceiver(const Config& config);
|
||||
[[deprecated("bugs.webrtc.org/356878416")]] explicit AcmReceiver(
|
||||
const Config& config);
|
||||
|
||||
AcmReceiver(const Environment& env, Config config);
|
||||
|
||||
// Destructor of the class.
|
||||
~AcmReceiver();
|
||||
@ -230,12 +232,12 @@ class AcmReceiver {
|
||||
|
||||
uint32_t NowInTimestamp(int decoder_sampling_rate) const;
|
||||
|
||||
Clock& clock_;
|
||||
mutable Mutex mutex_;
|
||||
absl::optional<DecoderInfo> last_decoder_ RTC_GUARDED_BY(mutex_);
|
||||
ACMResampler resampler_ RTC_GUARDED_BY(mutex_);
|
||||
CallStatistics call_stats_ RTC_GUARDED_BY(mutex_);
|
||||
const std::unique_ptr<NetEq> neteq_; // NetEq is thread-safe; no lock needed.
|
||||
Clock& clock_;
|
||||
bool resampled_last_output_frame_ RTC_GUARDED_BY(mutex_);
|
||||
std::array<int16_t, AudioFrame::kMaxDataSizeSamples> last_audio_buffer_
|
||||
RTC_GUARDED_BY(mutex_);
|
||||
|
||||
@ -48,7 +48,7 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
|
||||
|
||||
void SetUp() override {
|
||||
acm_ = AudioCodingModule::Create();
|
||||
receiver_.reset(new AcmReceiver(config_));
|
||||
receiver_ = std::make_unique<AcmReceiver>(env_, config_);
|
||||
ASSERT_TRUE(receiver_.get() != NULL);
|
||||
ASSERT_TRUE(acm_.get() != NULL);
|
||||
acm_->RegisterTransportCallback(this);
|
||||
|
||||
@ -175,9 +175,8 @@ class AudioCodingModuleTestOldApi : public ::testing::Test {
|
||||
void SetUp() {
|
||||
acm_ = AudioCodingModule::Create();
|
||||
acm2::AcmReceiver::Config config;
|
||||
config.clock = env_.clock();
|
||||
config.decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
acm_receiver_ = std::make_unique<acm2::AcmReceiver>(config);
|
||||
acm_receiver_ = std::make_unique<acm2::AcmReceiver>(env_, config);
|
||||
|
||||
rtp_utility_->Populate(&rtp_header_);
|
||||
|
||||
|
||||
@ -52,7 +52,8 @@ int32_t TestPacketization::SendData(const AudioFrameType /* frameType */,
|
||||
Sender::Sender()
|
||||
: _acm(NULL), _pcmFile(), _audioFrame(), _packetization(NULL) {}
|
||||
|
||||
void Sender::Setup(AudioCodingModule* acm,
|
||||
void Sender::Setup(const Environment& env,
|
||||
AudioCodingModule* acm,
|
||||
RTPStream* rtpStream,
|
||||
absl::string_view in_file_name,
|
||||
int in_sample_rate,
|
||||
@ -70,7 +71,7 @@ void Sender::Setup(AudioCodingModule* acm,
|
||||
_pcmFile.FastForward(100);
|
||||
|
||||
acm->SetEncoder(CreateBuiltinAudioEncoderFactory()->Create(
|
||||
CreateEnvironment(), format, {.payload_type = payload_type}));
|
||||
env, format, {.payload_type = payload_type}));
|
||||
_packetization = new TestPacketization(rtpStream, format.clockrate_hz);
|
||||
EXPECT_EQ(0, acm->RegisterTransportCallback(_packetization));
|
||||
|
||||
@ -244,6 +245,7 @@ void EncodeDecodeTest::Perform() {
|
||||
{9, {"G722", 8000, 1}},
|
||||
#endif
|
||||
};
|
||||
const Environment env = CreateEnvironment();
|
||||
int file_num = 0;
|
||||
for (const auto& send_codec : send_codecs) {
|
||||
RTPFile rtpFile;
|
||||
@ -254,7 +256,7 @@ void EncodeDecodeTest::Perform() {
|
||||
rtpFile.Open(fileName.c_str(), "wb+");
|
||||
rtpFile.WriteHeader();
|
||||
Sender sender;
|
||||
sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000,
|
||||
sender.Setup(env, acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000,
|
||||
send_codec.first, send_codec.second);
|
||||
sender.Run();
|
||||
sender.Teardown();
|
||||
@ -262,9 +264,9 @@ void EncodeDecodeTest::Perform() {
|
||||
|
||||
rtpFile.Open(fileName.c_str(), "rb");
|
||||
rtpFile.ReadHeader();
|
||||
std::unique_ptr<acm2::AcmReceiver> acm_receiver(
|
||||
std::unique_ptr<acm2::AcmReceiver> acm_receiver =
|
||||
std::make_unique<acm2::AcmReceiver>(
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory())));
|
||||
env, acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory()));
|
||||
Receiver receiver;
|
||||
receiver.Setup(acm_receiver.get(), &rtpFile, "encodeDecode_out", 1,
|
||||
file_num);
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "modules/audio_coding/acm2/acm_receiver.h"
|
||||
#include "modules/audio_coding/include/audio_coding_module.h"
|
||||
#include "modules/audio_coding/test/PCMFile.h"
|
||||
@ -51,7 +52,8 @@ class TestPacketization : public AudioPacketizationCallback {
|
||||
class Sender {
|
||||
public:
|
||||
Sender();
|
||||
void Setup(AudioCodingModule* acm,
|
||||
void Setup(const Environment& env,
|
||||
AudioCodingModule* acm,
|
||||
RTPStream* rtpStream,
|
||||
absl::string_view in_file_name,
|
||||
int in_sample_rate,
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "test/gtest.h"
|
||||
@ -92,14 +94,15 @@ bool ReceiverWithPacketLoss::PacketLost() {
|
||||
|
||||
SenderWithFEC::SenderWithFEC() : expected_loss_rate_(0) {}
|
||||
|
||||
void SenderWithFEC::Setup(AudioCodingModule* acm,
|
||||
void SenderWithFEC::Setup(const Environment& env,
|
||||
AudioCodingModule* acm,
|
||||
RTPStream* rtpStream,
|
||||
absl::string_view in_file_name,
|
||||
int payload_type,
|
||||
SdpAudioFormat format,
|
||||
int expected_loss_rate) {
|
||||
Sender::Setup(acm, rtpStream, in_file_name, format.clockrate_hz, payload_type,
|
||||
format);
|
||||
Sender::Setup(env, acm, rtpStream, in_file_name, format.clockrate_hz,
|
||||
payload_type, format);
|
||||
EXPECT_TRUE(SetFEC(true));
|
||||
EXPECT_TRUE(SetPacketLossRate(expected_loss_rate));
|
||||
}
|
||||
@ -138,6 +141,7 @@ void PacketLossTest::Perform() {
|
||||
#ifndef WEBRTC_CODEC_OPUS
|
||||
return;
|
||||
#else
|
||||
const Environment env = CreateEnvironment();
|
||||
RTPFile rtpFile;
|
||||
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create());
|
||||
SdpAudioFormat send_format = SdpAudioFormat("opus", 48000, 2);
|
||||
@ -150,7 +154,7 @@ void PacketLossTest::Perform() {
|
||||
rtpFile.Open(fileName.c_str(), "wb+");
|
||||
rtpFile.WriteHeader();
|
||||
SenderWithFEC sender;
|
||||
sender.Setup(acm.get(), &rtpFile, in_file_name_, 120, send_format,
|
||||
sender.Setup(env, acm.get(), &rtpFile, in_file_name_, 120, send_format,
|
||||
expected_loss_rate_);
|
||||
sender.Run();
|
||||
sender.Teardown();
|
||||
@ -158,9 +162,9 @@ void PacketLossTest::Perform() {
|
||||
|
||||
rtpFile.Open(fileName.c_str(), "rb");
|
||||
rtpFile.ReadHeader();
|
||||
std::unique_ptr<acm2::AcmReceiver> acm_receiver(
|
||||
std::unique_ptr<acm2::AcmReceiver> acm_receiver =
|
||||
std::make_unique<acm2::AcmReceiver>(
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory())));
|
||||
env, acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory()));
|
||||
ReceiverWithPacketLoss receiver;
|
||||
receiver.Setup(acm_receiver.get(), &rtpFile, "packetLoss_out", channels_, 15,
|
||||
actual_loss_rate_, burst_length_);
|
||||
|
||||
@ -42,7 +42,8 @@ class ReceiverWithPacketLoss : public Receiver {
|
||||
class SenderWithFEC : public Sender {
|
||||
public:
|
||||
SenderWithFEC();
|
||||
void Setup(AudioCodingModule* acm,
|
||||
void Setup(const Environment& env,
|
||||
AudioCodingModule* acm,
|
||||
RTPStream* rtpStream,
|
||||
absl::string_view in_file_name,
|
||||
int payload_type,
|
||||
|
||||
@ -111,6 +111,7 @@ TestAllCodecs::TestAllCodecs()
|
||||
: env_(CreateEnvironment()),
|
||||
acm_a_(AudioCodingModule::Create()),
|
||||
acm_b_(std::make_unique<acm2::AcmReceiver>(
|
||||
env_,
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory()))),
|
||||
channel_a_to_b_(NULL),
|
||||
test_count_(0),
|
||||
|
||||
@ -46,6 +46,7 @@ TestRedFec::TestRedFec()
|
||||
AudioDecoderOpus>()),
|
||||
_acmA(AudioCodingModule::Create()),
|
||||
_acm_receiver(std::make_unique<acm2::AcmReceiver>(
|
||||
env_,
|
||||
acm2::AcmReceiver::Config(decoder_factory_))),
|
||||
_channelA2B(NULL),
|
||||
_testCntr(0) {}
|
||||
|
||||
@ -102,6 +102,7 @@ TestStereo::TestStereo()
|
||||
: env_(CreateEnvironment()),
|
||||
acm_a_(AudioCodingModule::Create()),
|
||||
acm_b_(std::make_unique<acm2::AcmReceiver>(
|
||||
env_,
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory()))),
|
||||
channel_a2b_(NULL),
|
||||
test_cntr_(0),
|
||||
|
||||
@ -74,6 +74,7 @@ TestVadDtx::TestVadDtx()
|
||||
CreateAudioDecoderFactory<AudioDecoderIlbc, AudioDecoderOpus>()),
|
||||
acm_send_(AudioCodingModule::Create()),
|
||||
acm_receive_(std::make_unique<acm2::AcmReceiver>(
|
||||
env_,
|
||||
acm2::AcmReceiver::Config(decoder_factory_))),
|
||||
channel_(std::make_unique<Channel>()),
|
||||
packetization_callback_(
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
||||
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
|
||||
#include "modules/audio_coding/test/TestStereo.h"
|
||||
@ -23,6 +24,7 @@ namespace webrtc {
|
||||
|
||||
OpusTest::OpusTest()
|
||||
: acm_receiver_(std::make_unique<acm2::AcmReceiver>(
|
||||
CreateEnvironment(),
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory()))),
|
||||
channel_a2b_(NULL),
|
||||
counter_(0),
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/audio_coding/acm2/acm_receiver.h"
|
||||
@ -26,6 +27,7 @@ class TargetDelayTest : public ::testing::Test {
|
||||
protected:
|
||||
TargetDelayTest()
|
||||
: receiver_(
|
||||
CreateEnvironment(),
|
||||
acm2::AcmReceiver::Config(CreateBuiltinAudioDecoderFactory())) {}
|
||||
|
||||
~TargetDelayTest() {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user