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}
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index cb98266..a28152b 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -784,6 +784,7 @@
":default_neteq_factory",
":neteq",
"../../api:array_view",
+ "../../api:field_trials",
"../../api:neteq_simulator_api",
"../../api:rtp_headers",
"../../api/audio:audio_frame_api",
diff --git a/modules/audio_coding/neteq/tools/neteq_test.cc b/modules/audio_coding/neteq/tools/neteq_test.cc
index 2555082..4487ac5 100644
--- a/modules/audio_coding/neteq/tools/neteq_test.cc
+++ b/modules/audio_coding/neteq/tools/neteq_test.cc
@@ -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 @@
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))
diff --git a/modules/audio_coding/neteq/tools/neteq_test.h b/modules/audio_coding/neteq/tools/neteq_test.h
index 925b3c8..89506a8 100644
--- a/modules/audio_coding/neteq/tools/neteq_test.h
+++ b/modules/audio_coding/neteq/tools/neteq_test.h
@@ -88,7 +88,8 @@
NetEqFactory* neteq_factory,
std::unique_ptr<NetEqInput> input,
std::unique_ptr<AudioSink> output,
- Callbacks callbacks);
+ Callbacks callbacks,
+ absl::string_view field_trials = "");
~NetEqTest() override;
diff --git a/modules/audio_coding/neteq/tools/neteq_test_factory.cc b/modules/audio_coding/neteq/tools/neteq_test_factory.cc
index 64a8152..766a092 100644
--- a/modules/audio_coding/neteq/tools/neteq_test_factory.cc
+++ b/modules/audio_coding/neteq/tools/neteq_test_factory.cc
@@ -172,11 +172,6 @@
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 @@
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
diff --git a/modules/audio_coding/neteq/tools/neteq_test_factory.h b/modules/audio_coding/neteq/tools/neteq_test_factory.h
index 96ce0b4..6091749 100644
--- a/modules/audio_coding/neteq/tools/neteq_test_factory.h
+++ b/modules/audio_coding/neteq/tools/neteq_test_factory.h
@@ -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 @@
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
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 379b4ed..50a42f6 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -405,6 +405,7 @@
"../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",
diff --git a/rtc_tools/rtc_event_log_visualizer/analyze_audio.cc b/rtc_tools/rtc_event_log_visualizer/analyze_audio.cc
index af6e2ee..cba8998 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyze_audio.cc
+++ b/rtc_tools/rtc_event_log_visualizer/analyze_audio.cc
@@ -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 @@
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;
}