From 24c35756f467cf4e0bca324268ee7f2543a3596f Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Thu, 31 Oct 2024 14:06:45 +0100 Subject: [PATCH] Change audioproc float test utility api to pass AudioProcessing with builder. New api ensures field trials are available at construction time of the AudioProcessing object. This would allow AudioProcessing implementation to use propagated field trials during construction. Also, short term, it ensures AudioProcessing is constructed after global field trials are set. Bug: webrtc:369904700 Change-Id: If3d00c8a3a509299cd0915d55f13a9a3ce4a7140 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/367201 Reviewed-by: Sam Zackrisson Reviewed-by: Harald Alvestrand Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#43340} --- api/BUILD.gn | 2 + api/test/audioproc_float.cc | 19 ++++++ api/test/audioproc_float.h | 40 +++++++++++-- modules/audio_processing/BUILD.gn | 3 + .../test/audioproc_float_impl.cc | 58 ++++++++++++++++--- .../test/audioproc_float_impl.h | 11 ++++ rtc_tools/audioproc_f/audioproc_float_main.cc | 6 +- 7 files changed, 121 insertions(+), 18 deletions(-) diff --git a/api/BUILD.gn b/api/BUILD.gn index b38e6b0e05..f9aad9108f 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -1021,6 +1021,8 @@ if (rtc_include_tests) { "../modules/audio_processing", "../modules/audio_processing:audioproc_f_impl", "audio:audio_processing", + "audio:builtin_audio_processing_builder", + "//third_party/abseil-cpp/absl/base:nullability", ] } diff --git a/api/test/audioproc_float.cc b/api/test/audioproc_float.cc index 84d100a99a..b52d78e503 100644 --- a/api/test/audioproc_float.cc +++ b/api/test/audioproc_float.cc @@ -32,5 +32,24 @@ int AudioprocFloat(std::unique_ptr ap_builder, return AudioprocFloatImpl(std::move(ap_builder), argc, argv); } +int AudioprocFloat(int argc, char* argv[]) { + return AudioprocFloatImpl(std::make_unique(), + argc, argv); +} + +int AudioprocFloat( + absl::Nonnull> ap_builder, + int argc, + char* argv[]) { + return AudioprocFloatImpl(std::move(ap_builder), argc, argv); +} + +int AudioprocFloat( + absl::Nonnull> ap_builder, + int argc, + char* argv[]) { + return AudioprocFloatImpl(std::move(ap_builder), argc, argv); +} + } // namespace test } // namespace webrtc diff --git a/api/test/audioproc_float.h b/api/test/audioproc_float.h index 3c2175351b..98f35faf14 100644 --- a/api/test/audioproc_float.h +++ b/api/test/audioproc_float.h @@ -13,12 +13,38 @@ #include +#include "absl/base/nullability.h" #include "api/audio/audio_processing.h" +#include "api/audio/builtin_audio_processing_builder.h" #include "api/scoped_refptr.h" namespace webrtc { namespace test { +// This is an interface for the audio processing simulation utility. This +// utility can be used to simulate the audioprocessing module using a recording +// (either an AEC dump or wav files), and generate the output as a wav file. +// +// It is needed to pass the command line flags as `argc` and `argv`, so these +// can be interpreted properly by the utility. To see a list of all supported +// command line flags, run the executable with the '--helpfull' flag. +// +// The optional `ap_builder` object will be used to create the AudioProcessing +// instance that is used during the simulation. BuiltinAudioProcessingBuilder +// `ap_builder` supports setting of injectable components, which will be passed +// on to the created AudioProcessing instance. When generic +// `AudioProcessingBuilderInterface` is used, all functionality that relies on +// using the BuiltinAudioProcessingBuilder is deactivated. +int AudioprocFloat(int argc, char* argv[]); +int AudioprocFloat( + absl::Nonnull> ap_builder, + int argc, + char* argv[]); +int AudioprocFloat( + absl::Nonnull> ap_builder, + int argc, + char* argv[]); + // This is an interface for the audio processing simulation utility. This // utility can be used to simulate the audioprocessing module using a recording // (either an AEC dump or wav files), and generate the output as a wav file. @@ -31,9 +57,10 @@ namespace test { // is needed to pass the command line flags as `argc` and `argv`, so these can // be interpreted properly by the utility. To see a list of all supported // command line flags, run the executable with the '--help' flag. -int AudioprocFloat(rtc::scoped_refptr audio_processing, - int argc, - char* argv[]); +[[deprecated]] int AudioprocFloat( + rtc::scoped_refptr audio_processing, + int argc, + char* argv[]); // This is an interface for the audio processing simulation utility. This // utility can be used to simulate the audioprocessing module using a recording @@ -49,9 +76,10 @@ int AudioprocFloat(rtc::scoped_refptr audio_processing, // line arguments into this function. // To see a list of all supported command line flags, run the executable with // the '--help' flag. -int AudioprocFloat(std::unique_ptr ap_builder, - int argc, - char* argv[]); +[[deprecated]] int AudioprocFloat( + std::unique_ptr ap_builder, + int argc, + char* argv[]); } // namespace test } // namespace webrtc diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn index 988183f3dc..e4bb0c7aff 100644 --- a/modules/audio_processing/BUILD.gn +++ b/modules/audio_processing/BUILD.gn @@ -522,7 +522,10 @@ if (rtc_include_tests) { "../../api/audio:aec3_config", "../../api/audio:aec3_factory", "../../api/audio:audio_processing", + "../../api/audio:builtin_audio_processing_builder", "../../api/audio:echo_detector_creator", + "../../api/environment", + "../../api/environment:environment_factory", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:logging", diff --git a/modules/audio_processing/test/audioproc_float_impl.cc b/modules/audio_processing/test/audioproc_float_impl.cc index 4f86651780..5814544999 100644 --- a/modules/audio_processing/test/audioproc_float_impl.cc +++ b/modules/audio_processing/test/audioproc_float_impl.cc @@ -29,6 +29,8 @@ #include "api/audio/echo_canceller3_config.h" #include "api/audio/echo_canceller3_factory.h" #include "api/audio/echo_detector_creator.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "api/field_trials.h" #include "api/scoped_refptr.h" #include "common_audio/wav_file.h" @@ -773,8 +775,12 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(absl::string_view filename) { return cfg; } -void SetDependencies(const SimulationSettings& settings, - AudioProcessingBuilder& builder) { +// `Builder` is either AudioProcessingBuilder or BuiltinAudioProcessingBuilder +// TODO: bugs.webrtc.org/369904700 - inline this function when usages of +// the AudioProcessingBuilder are removed, and thus two version of this function +// are no longer needed. +template +void SetDependencies(const SimulationSettings& settings, Builder& builder) { // Create and set an EchoCanceller3Factory if needed. if (settings.use_aec && *settings.use_aec) { EchoCanceller3Config cfg; @@ -805,6 +811,31 @@ void SetDependencies(const SimulationSettings& settings, } absl::Nonnull> Provide( + const Environment& env, + const SimulationSettings& settings, + absl::Nonnull> ap_builder) { + PerformBasicParameterSanityChecks(settings, + /*pre_constructed_ap_provided=*/false); + SetDependencies(settings, *ap_builder); + scoped_refptr ap = ap_builder->Build(env); + RTC_CHECK(ap); + return ap; +} + +absl::Nonnull> Provide( + const Environment& env, + const SimulationSettings& settings, + absl::Nonnull> + ap_builder) { + PerformBasicParameterSanityChecks(settings, + /*pre_constructed_ap_provided=*/true); + scoped_refptr ap = ap_builder->Build(env); + RTC_CHECK(ap); + return ap; +} + +absl::Nonnull> Provide( + const Environment& /*env*/, const SimulationSettings& settings, absl::Nullable> ap_builder) { PerformBasicParameterSanityChecks(settings, @@ -819,10 +850,11 @@ absl::Nonnull> Provide( } absl::Nonnull> Provide( + const Environment& env, const SimulationSettings& settings, absl::Nullable> ap_provider) { if (ap_provider == nullptr) { - return Provide(settings, std::make_unique()); + return Provide(env, settings, std::make_unique()); } PerformBasicParameterSanityChecks(settings, @@ -837,14 +869,12 @@ int RunSimulation(AudioProcessingProvider ap_provider, int argc, char* argv[]) { printf("%s", kUsageDescription); return 1; } - // TODO: bugs.webrtc.org/369904700 - Propagate these field trials to construct - // audio_processing when AudioProcessingImpl will be able to accept propagated - // field trials through Environment. FieldTrials field_trials(absl::GetFlag(FLAGS_force_fieldtrials)); + const Environment env = CreateEnvironment(&field_trials); SimulationSettings settings = CreateSettings(); absl::Nonnull> audio_processing = - Provide(settings, std::move(ap_provider)); + Provide(env, settings, std::move(ap_provider)); std::unique_ptr processor; if (settings.aec_dump_input_filename || settings.aec_dump_input_string) { @@ -895,5 +925,19 @@ int AudioprocFloatImpl( return RunSimulation(std::move(ap_builder), argc, argv); } +int AudioprocFloatImpl( + absl::Nonnull> ap_builder, + int argc, + char* argv[]) { + return RunSimulation(std::move(ap_builder), argc, argv); +} + +int AudioprocFloatImpl( + absl::Nonnull> ap_builder, + int argc, + char* argv[]) { + return RunSimulation(std::move(ap_builder), argc, argv); +} + } // namespace test } // namespace webrtc diff --git a/modules/audio_processing/test/audioproc_float_impl.h b/modules/audio_processing/test/audioproc_float_impl.h index 6afa89ff4e..1406287d67 100644 --- a/modules/audio_processing/test/audioproc_float_impl.h +++ b/modules/audio_processing/test/audioproc_float_impl.h @@ -15,6 +15,7 @@ #include "absl/base/nullability.h" #include "api/audio/audio_processing.h" +#include "api/audio/builtin_audio_processing_builder.h" #include "api/scoped_refptr.h" namespace webrtc { @@ -30,6 +31,16 @@ int AudioprocFloatImpl( int argc, char* argv[]); +int AudioprocFloatImpl( + absl::Nonnull> ap_builder, + int argc, + char* argv[]); + +int AudioprocFloatImpl( + absl::Nonnull> ap_builder, + int argc, + char* argv[]); + } // namespace test } // namespace webrtc diff --git a/rtc_tools/audioproc_f/audioproc_float_main.cc b/rtc_tools/audioproc_f/audioproc_float_main.cc index 3acf8fa33c..aa3e0ef485 100644 --- a/rtc_tools/audioproc_f/audioproc_float_main.cc +++ b/rtc_tools/audioproc_f/audioproc_float_main.cc @@ -8,12 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include - -#include "api/audio/audio_processing.h" #include "api/test/audioproc_float.h" int main(int argc, char* argv[]) { - return webrtc::test::AudioprocFloat( - std::make_unique(), argc, argv); + return webrtc::test::AudioprocFloat(argc, argv); }