Provide Environment to create NetEq in tests
Bug: webrtc:356878416 Change-Id: I1d01c61ad6822fb018873fed949154f72b90a11b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358920 Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42748}
This commit is contained in:
parent
cae0aeb2b6
commit
0c4c4e6070
@ -789,6 +789,8 @@ rtc_library("neteq_tools_minimal") {
|
||||
"../../api:rtp_headers",
|
||||
"../../api/audio:audio_frame_api",
|
||||
"../../api/audio_codecs:audio_codecs_api",
|
||||
"../../api/environment",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../api/neteq:custom_neteq_factory",
|
||||
"../../api/neteq:default_neteq_controller_factory",
|
||||
"../../api/neteq:neteq_api",
|
||||
@ -1351,6 +1353,8 @@ if (rtc_include_tests) {
|
||||
"../../api/audio:audio_frame_api",
|
||||
"../../api/audio_codecs:audio_codecs_api",
|
||||
"../../api/audio_codecs:builtin_audio_decoder_factory",
|
||||
"../../api/environment",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../api/neteq:neteq_api",
|
||||
"../../rtc_base:checks",
|
||||
"../../system_wrappers",
|
||||
@ -1375,6 +1379,7 @@ if (rtc_include_tests) {
|
||||
":neteq_test_tools",
|
||||
":neteq_tools_minimal",
|
||||
"../../api/audio_codecs:builtin_audio_decoder_factory",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../api/neteq:neteq_api",
|
||||
"../../api/units:timestamp",
|
||||
"../../rtc_base:checks",
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/neteq/default_neteq_controller_factory.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "api/neteq/neteq_controller.h"
|
||||
@ -255,10 +256,8 @@ class NetEqImplTest : public ::testing::Test {
|
||||
// TODO(hlundin): Move to separate file?
|
||||
TEST(NetEq, CreateAndDestroy) {
|
||||
NetEq::Config config;
|
||||
SimulatedClock clock(0);
|
||||
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
std::unique_ptr<NetEq> neteq =
|
||||
DefaultNetEqFactory().CreateNetEq(config, decoder_factory, &clock);
|
||||
std::unique_ptr<NetEq> neteq = DefaultNetEqFactory().Create(
|
||||
CreateEnvironment(), config, CreateBuiltinAudioDecoderFactory());
|
||||
}
|
||||
|
||||
TEST_F(NetEqImplTest, RegisterPayloadType) {
|
||||
|
||||
@ -9,15 +9,15 @@
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "modules/audio_coding/neteq/default_neteq_factory.h"
|
||||
#include "modules/audio_coding/neteq/tools/rtp_generator.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/audio_decoder_proxy_factory.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
@ -28,9 +28,9 @@ namespace {
|
||||
|
||||
std::unique_ptr<NetEq> CreateNetEq(
|
||||
const NetEq::Config& config,
|
||||
Clock* clock,
|
||||
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
|
||||
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
|
||||
scoped_refptr<AudioDecoderFactory> decoder_factory) {
|
||||
return DefaultNetEqFactory().Create(CreateEnvironment(), config,
|
||||
std::move(decoder_factory));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -169,7 +169,7 @@ class NetEqNetworkStatsTest {
|
||||
packet_loss_interval_(0xffffffff) {
|
||||
NetEq::Config config;
|
||||
config.sample_rate_hz = format.clockrate_hz;
|
||||
neteq_ = CreateNetEq(config, Clock::GetRealTimeClock(), decoder_factory_);
|
||||
neteq_ = CreateNetEq(config, decoder_factory_);
|
||||
neteq_->RegisterPayloadType(kPayloadType, format);
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
||||
@ -61,6 +63,7 @@ class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
|
||||
static_cast<size_t>(frame_size_ms_ * samples_per_ms_)),
|
||||
output_size_samples_(10 * samples_per_ms_),
|
||||
clock_(0),
|
||||
env_(CreateEnvironment(&clock_)),
|
||||
rtp_generator_mono_(samples_per_ms_),
|
||||
rtp_generator_(samples_per_ms_),
|
||||
payload_size_bytes_(0),
|
||||
@ -71,8 +74,8 @@ class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
|
||||
config.sample_rate_hz = sample_rate_hz_;
|
||||
DefaultNetEqFactory neteq_factory;
|
||||
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
neteq_mono_ = neteq_factory.CreateNetEq(config, decoder_factory, &clock_);
|
||||
neteq_ = neteq_factory.CreateNetEq(config, decoder_factory, &clock_);
|
||||
neteq_mono_ = neteq_factory.Create(env_, config, decoder_factory);
|
||||
neteq_ = neteq_factory.Create(env_, config, decoder_factory);
|
||||
input_ = new int16_t[frame_size_samples_];
|
||||
encoded_ = new uint8_t[2 * frame_size_samples_];
|
||||
input_multi_channel_ = new int16_t[frame_size_samples_ * num_channels_];
|
||||
@ -213,6 +216,7 @@ class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
|
||||
const size_t frame_size_samples_;
|
||||
const size_t output_size_samples_;
|
||||
SimulatedClock clock_;
|
||||
const Environment env_;
|
||||
std::unique_ptr<NetEq> neteq_mono_;
|
||||
std::unique_ptr<NetEq> neteq_;
|
||||
test::RtpGenerator rtp_generator_mono_;
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "absl/strings/string_view.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/neteq/default_neteq_factory.h"
|
||||
@ -77,6 +78,7 @@ const int NetEqDecodingTest::kInitSampleRateHz;
|
||||
|
||||
NetEqDecodingTest::NetEqDecodingTest()
|
||||
: clock_(0),
|
||||
env_(CreateEnvironment(&clock_)),
|
||||
config_(),
|
||||
output_sample_rate_(kInitSampleRateHz),
|
||||
algorithmic_delay_ms_(0) {
|
||||
@ -84,8 +86,8 @@ NetEqDecodingTest::NetEqDecodingTest()
|
||||
}
|
||||
|
||||
void NetEqDecodingTest::SetUp() {
|
||||
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
neteq_ = DefaultNetEqFactory().CreateNetEq(config_, decoder_factory, &clock_);
|
||||
neteq_ = DefaultNetEqFactory().Create(env_, config_,
|
||||
CreateBuiltinAudioDecoderFactory());
|
||||
NetEqNetworkStatistics stat;
|
||||
ASSERT_EQ(0, neteq_->NetworkStatistics(&stat));
|
||||
algorithmic_delay_ms_ = stat.current_buffer_size_ms;
|
||||
@ -421,9 +423,8 @@ void NetEqDecodingTestTwoInstances::SetUp() {
|
||||
}
|
||||
|
||||
void NetEqDecodingTestTwoInstances::CreateSecondInstance() {
|
||||
auto decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
neteq2_ =
|
||||
DefaultNetEqFactory().CreateNetEq(config2_, decoder_factory, &clock_);
|
||||
neteq2_ = DefaultNetEqFactory().Create(env_, config2_,
|
||||
CreateBuiltinAudioDecoderFactory());
|
||||
ASSERT_TRUE(neteq2_);
|
||||
LoadDecoders(neteq2_.get());
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "api/rtp_headers.h"
|
||||
#include "modules/audio_coding/neteq/tools/packet.h"
|
||||
@ -70,6 +71,7 @@ class NetEqDecodingTest : public ::testing::Test {
|
||||
int max_time_to_speech_ms);
|
||||
|
||||
SimulatedClock clock_;
|
||||
const Environment env_;
|
||||
std::unique_ptr<NetEq> neteq_;
|
||||
NetEq::Config config_;
|
||||
std::unique_ptr<test::RtpFileSource> rtp_source_;
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
#include "api/audio/audio_frame.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
|
||||
#include "modules/audio_coding/neteq/default_neteq_factory.h"
|
||||
@ -40,10 +42,9 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
|
||||
// Initialize NetEq instance.
|
||||
NetEq::Config config;
|
||||
config.sample_rate_hz = kSampRateHz;
|
||||
webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock();
|
||||
auto audio_decoder_factory = CreateBuiltinAudioDecoderFactory();
|
||||
auto neteq =
|
||||
DefaultNetEqFactory().CreateNetEq(config, audio_decoder_factory, clock);
|
||||
Environment env = CreateEnvironment();
|
||||
auto neteq = DefaultNetEqFactory().Create(env, config,
|
||||
CreateBuiltinAudioDecoderFactory());
|
||||
// Register decoder in `neteq`.
|
||||
if (!neteq->RegisterPayloadType(kPayloadType,
|
||||
SdpAudioFormat("l16", kSampRateHz, 1)))
|
||||
@ -76,7 +77,7 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
|
||||
RTC_CHECK_EQ(sizeof(input_payload), payload_len);
|
||||
|
||||
// Main loop.
|
||||
int64_t start_time_ms = clock->TimeInMilliseconds();
|
||||
int64_t start_time_ms = env.clock().TimeInMilliseconds();
|
||||
AudioFrame out_frame;
|
||||
while (time_now_ms < runtime_ms) {
|
||||
while (packet_input_time_ms <= time_now_ms) {
|
||||
@ -121,7 +122,7 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
|
||||
drift_flipped = true;
|
||||
}
|
||||
}
|
||||
int64_t end_time_ms = clock->TimeInMilliseconds();
|
||||
int64_t end_time_ms = env.clock().TimeInMilliseconds();
|
||||
return end_time_ms - start_time_ms;
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/audio_coding/neteq/default_neteq_factory.h"
|
||||
#include "modules/audio_coding/neteq/tools/neteq_quality_test.h"
|
||||
@ -84,9 +85,9 @@ namespace {
|
||||
|
||||
std::unique_ptr<NetEq> CreateNetEq(
|
||||
const NetEq::Config& config,
|
||||
Clock* clock,
|
||||
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
|
||||
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
|
||||
scoped_refptr<AudioDecoderFactory> decoder_factory) {
|
||||
return DefaultNetEqFactory().Create(CreateEnvironment(), config,
|
||||
std::move(decoder_factory));
|
||||
}
|
||||
|
||||
const std::string& GetInFilenamePath(absl::string_view file_name) {
|
||||
@ -249,7 +250,7 @@ NetEqQualityTest::NetEqQualityTest(
|
||||
|
||||
NetEq::Config config;
|
||||
config.sample_rate_hz = out_sampling_khz_ * 1000;
|
||||
neteq_ = CreateNetEq(config, Clock::GetRealTimeClock(), decoder_factory);
|
||||
neteq_ = CreateNetEq(config, decoder_factory);
|
||||
max_payload_bytes_ = in_size_samples_ * channels_ * sizeof(int16_t);
|
||||
in_data_.reset(new int16_t[in_size_samples_ * channels_]);
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/audio_coding/neteq/default_neteq_factory.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
@ -40,10 +42,10 @@ absl::optional<NetEq::Operation> ActionToOperations(
|
||||
}
|
||||
|
||||
std::unique_ptr<NetEq> CreateNetEq(
|
||||
const Environment& env,
|
||||
const NetEq::Config& config,
|
||||
Clock* clock,
|
||||
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
|
||||
return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
|
||||
scoped_refptr<AudioDecoderFactory> decoder_factory) {
|
||||
return DefaultNetEqFactory().Create(env, config, std::move(decoder_factory));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -70,9 +72,11 @@ NetEqTest::NetEqTest(const NetEq::Config& config,
|
||||
Callbacks callbacks)
|
||||
: input_(std::move(input)),
|
||||
clock_(Timestamp::Millis(input_->NextEventTime().value_or(0))),
|
||||
neteq_(neteq_factory
|
||||
? neteq_factory->CreateNetEq(config, decoder_factory, &clock_)
|
||||
: CreateNetEq(config, &clock_, decoder_factory)),
|
||||
env_(CreateEnvironment(&clock_)),
|
||||
neteq_(
|
||||
neteq_factory
|
||||
? neteq_factory->Create(env_, config, std::move(decoder_factory))
|
||||
: CreateNetEq(env_, config, std::move(decoder_factory))),
|
||||
output_(std::move(output)),
|
||||
callbacks_(callbacks),
|
||||
sample_rate_hz_(config.sample_rate_hz),
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/neteq/neteq.h"
|
||||
#include "api/neteq/neteq_factory.h"
|
||||
#include "api/test/neteq_simulator.h"
|
||||
@ -112,6 +113,7 @@ class NetEqTest : public NetEqSimulator {
|
||||
void RegisterDecoders(const DecoderMap& codecs);
|
||||
std::unique_ptr<NetEqInput> input_;
|
||||
SimulatedClock clock_;
|
||||
const Environment env_;
|
||||
absl::optional<Action> next_action_;
|
||||
absl::optional<int> last_packet_time_ms_;
|
||||
std::unique_ptr<NetEq> neteq_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user