Inject field trials in NetEqTest instead of setting global.

We can avoid using the global now that field trials from Environment are
used in NetEq. This allows running multiple instances in parallel with
different settings.

Bug: webrtc:42220378
Change-Id: Icff8539e3ae9b61c86bb393d9a313e786e032b93
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359720
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42894}
This commit is contained in:
Jakob Ivarsson 2024-08-15 11:50:43 +00:00 committed by WebRTC LUCI CQ
parent 8d478ddaed
commit b5f4006589
7 changed files with 16 additions and 16 deletions

View File

@ -784,6 +784,7 @@ rtc_library("neteq_tools_minimal") {
":default_neteq_factory",
":neteq",
"../../api:array_view",
"../../api:field_trials",
"../../api:neteq_simulator_api",
"../../api:rtp_headers",
"../../api/audio:audio_frame_api",

View File

@ -15,6 +15,7 @@
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "api/field_trials.h"
#include "api/units/timestamp.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/rtp_rtcp/source/byte_io.h"
@ -69,10 +70,13 @@ NetEqTest::NetEqTest(const NetEq::Config& config,
NetEqFactory* neteq_factory,
std::unique_ptr<NetEqInput> input,
std::unique_ptr<AudioSink> output,
Callbacks callbacks)
Callbacks callbacks,
absl::string_view field_trials)
: input_(std::move(input)),
clock_(Timestamp::Millis(input_->NextEventTime().value_or(0))),
env_(CreateEnvironment(&clock_)),
env_(CreateEnvironment(
&clock_,
FieldTrials::CreateNoGlobal(std::string(field_trials)))),
neteq_(
neteq_factory
? neteq_factory->Create(env_, config, std::move(decoder_factory))

View File

@ -88,7 +88,8 @@ class NetEqTest : public NetEqSimulator {
NetEqFactory* neteq_factory,
std::unique_ptr<NetEqInput> input,
std::unique_ptr<AudioSink> output,
Callbacks callbacks);
Callbacks callbacks,
absl::string_view field_trials = "");
~NetEqTest() override;

View File

@ -172,11 +172,6 @@ std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTest(
return nullptr;
}
if (!config.field_trial_string.empty()) {
field_trials_ =
std::make_unique<ScopedFieldTrials>(config.field_trial_string);
}
// Skip some initial events/packets if requested.
if (config.skip_get_audio_events > 0) {
std::cout << "Skipping " << config.skip_get_audio_events
@ -345,9 +340,10 @@ std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTest(
neteq_config.sample_rate_hz = *sample_rate_hz;
neteq_config.max_packets_in_buffer = config.max_nr_packets_in_buffer;
neteq_config.enable_fast_accelerate = config.enable_fast_accelerate;
return std::make_unique<NetEqTest>(
neteq_config, decoder_factory, codecs, std::move(text_log), factory,
std::move(input), std::move(output), callbacks);
return std::make_unique<NetEqTest>(neteq_config, decoder_factory, codecs,
std::move(text_log), factory,
std::move(input), std::move(output),
callbacks, config.field_trial_string);
}
} // namespace test

View File

@ -17,7 +17,6 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/neteq_test.h"
#include "test/field_trial.h"
namespace webrtc {
namespace test {
@ -161,9 +160,6 @@ class NetEqTestFactory {
const Config& config);
std::unique_ptr<SsrcSwitchDetector> ssrc_switch_detector_;
std::unique_ptr<NetEqStatsPlotter> stats_plotter_;
// The field trials are stored in the test factory, because neteq_test is not
// in a testonly target, and therefore cannot use ScopedFieldTrials.
std::unique_ptr<ScopedFieldTrials> field_trials_;
};
} // namespace test

View File

@ -405,6 +405,7 @@ if (!build_with_chromium) {
"../rtc_base:stringutils",
"../rtc_base/network:sent_packet",
"../system_wrappers",
"../system_wrappers:field_trial",
"../test:explicit_key_value_config",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/base:core_headers",

View File

@ -43,6 +43,7 @@
#include "rtc_base/checks.h"
#include "rtc_tools/rtc_event_log_visualizer/analyzer_common.h"
#include "rtc_tools/rtc_event_log_visualizer/plot_base.h"
#include "system_wrappers/include/field_trial.h"
namespace webrtc {
@ -275,7 +276,7 @@ std::unique_ptr<test::NetEqStatsGetter> CreateNetEqTestAndRun(
NetEq::Config config;
test::NetEqTest test(config, decoder_factory, codecs, /*text_log=*/nullptr,
/*factory=*/nullptr, std::move(input), std::move(output),
callbacks);
callbacks, field_trial::GetFieldTrialString());
test.Run();
return neteq_stats_getter;
}