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 <saza@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43340}
This commit is contained in:
Danil Chapovalov 2024-10-31 14:06:45 +01:00 committed by WebRTC LUCI CQ
parent 87155fcebf
commit 24c35756f4
7 changed files with 121 additions and 18 deletions

View File

@ -1021,6 +1021,8 @@ if (rtc_include_tests) {
"../modules/audio_processing", "../modules/audio_processing",
"../modules/audio_processing:audioproc_f_impl", "../modules/audio_processing:audioproc_f_impl",
"audio:audio_processing", "audio:audio_processing",
"audio:builtin_audio_processing_builder",
"//third_party/abseil-cpp/absl/base:nullability",
] ]
} }

View File

@ -32,5 +32,24 @@ int AudioprocFloat(std::unique_ptr<AudioProcessingBuilder> ap_builder,
return AudioprocFloatImpl(std::move(ap_builder), argc, argv); return AudioprocFloatImpl(std::move(ap_builder), argc, argv);
} }
int AudioprocFloat(int argc, char* argv[]) {
return AudioprocFloatImpl(std::make_unique<BuiltinAudioProcessingBuilder>(),
argc, argv);
}
int AudioprocFloat(
absl::Nonnull<std::unique_ptr<BuiltinAudioProcessingBuilder>> ap_builder,
int argc,
char* argv[]) {
return AudioprocFloatImpl(std::move(ap_builder), argc, argv);
}
int AudioprocFloat(
absl::Nonnull<std::unique_ptr<AudioProcessingBuilderInterface>> ap_builder,
int argc,
char* argv[]) {
return AudioprocFloatImpl(std::move(ap_builder), argc, argv);
}
} // namespace test } // namespace test
} // namespace webrtc } // namespace webrtc

View File

@ -13,12 +13,38 @@
#include <memory> #include <memory>
#include "absl/base/nullability.h"
#include "api/audio/audio_processing.h" #include "api/audio/audio_processing.h"
#include "api/audio/builtin_audio_processing_builder.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
namespace webrtc { namespace webrtc {
namespace test { 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<std::unique_ptr<BuiltinAudioProcessingBuilder>> ap_builder,
int argc,
char* argv[]);
int AudioprocFloat(
absl::Nonnull<std::unique_ptr<AudioProcessingBuilderInterface>> ap_builder,
int argc,
char* argv[]);
// This is an interface for the audio processing simulation utility. This // This is an interface for the audio processing simulation utility. This
// utility can be used to simulate the audioprocessing module using a recording // 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. // (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 // 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 // be interpreted properly by the utility. To see a list of all supported
// command line flags, run the executable with the '--help' flag. // command line flags, run the executable with the '--help' flag.
int AudioprocFloat(rtc::scoped_refptr<AudioProcessing> audio_processing, [[deprecated]] int AudioprocFloat(
int argc, rtc::scoped_refptr<AudioProcessing> audio_processing,
char* argv[]); int argc,
char* argv[]);
// This is an interface for the audio processing simulation utility. This // This is an interface for the audio processing simulation utility. This
// utility can be used to simulate the audioprocessing module using a recording // utility can be used to simulate the audioprocessing module using a recording
@ -49,9 +76,10 @@ int AudioprocFloat(rtc::scoped_refptr<AudioProcessing> audio_processing,
// line arguments into this function. // line arguments into this function.
// To see a list of all supported command line flags, run the executable with // To see a list of all supported command line flags, run the executable with
// the '--help' flag. // the '--help' flag.
int AudioprocFloat(std::unique_ptr<AudioProcessingBuilder> ap_builder, [[deprecated]] int AudioprocFloat(
int argc, std::unique_ptr<AudioProcessingBuilder> ap_builder,
char* argv[]); int argc,
char* argv[]);
} // namespace test } // namespace test
} // namespace webrtc } // namespace webrtc

View File

@ -522,7 +522,10 @@ if (rtc_include_tests) {
"../../api/audio:aec3_config", "../../api/audio:aec3_config",
"../../api/audio:aec3_factory", "../../api/audio:aec3_factory",
"../../api/audio:audio_processing", "../../api/audio:audio_processing",
"../../api/audio:builtin_audio_processing_builder",
"../../api/audio:echo_detector_creator", "../../api/audio:echo_detector_creator",
"../../api/environment",
"../../api/environment:environment_factory",
"../../common_audio", "../../common_audio",
"../../rtc_base:checks", "../../rtc_base:checks",
"../../rtc_base:logging", "../../rtc_base:logging",

View File

@ -29,6 +29,8 @@
#include "api/audio/echo_canceller3_config.h" #include "api/audio/echo_canceller3_config.h"
#include "api/audio/echo_canceller3_factory.h" #include "api/audio/echo_canceller3_factory.h"
#include "api/audio/echo_detector_creator.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/field_trials.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "common_audio/wav_file.h" #include "common_audio/wav_file.h"
@ -773,8 +775,12 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(absl::string_view filename) {
return cfg; return cfg;
} }
void SetDependencies(const SimulationSettings& settings, // `Builder` is either AudioProcessingBuilder or BuiltinAudioProcessingBuilder
AudioProcessingBuilder& builder) { // 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 <typename Builder>
void SetDependencies(const SimulationSettings& settings, Builder& builder) {
// Create and set an EchoCanceller3Factory if needed. // Create and set an EchoCanceller3Factory if needed.
if (settings.use_aec && *settings.use_aec) { if (settings.use_aec && *settings.use_aec) {
EchoCanceller3Config cfg; EchoCanceller3Config cfg;
@ -805,6 +811,31 @@ void SetDependencies(const SimulationSettings& settings,
} }
absl::Nonnull<scoped_refptr<AudioProcessing>> Provide( absl::Nonnull<scoped_refptr<AudioProcessing>> Provide(
const Environment& env,
const SimulationSettings& settings,
absl::Nonnull<std::unique_ptr<BuiltinAudioProcessingBuilder>> ap_builder) {
PerformBasicParameterSanityChecks(settings,
/*pre_constructed_ap_provided=*/false);
SetDependencies(settings, *ap_builder);
scoped_refptr<AudioProcessing> ap = ap_builder->Build(env);
RTC_CHECK(ap);
return ap;
}
absl::Nonnull<scoped_refptr<AudioProcessing>> Provide(
const Environment& env,
const SimulationSettings& settings,
absl::Nonnull<std::unique_ptr<AudioProcessingBuilderInterface>>
ap_builder) {
PerformBasicParameterSanityChecks(settings,
/*pre_constructed_ap_provided=*/true);
scoped_refptr<AudioProcessing> ap = ap_builder->Build(env);
RTC_CHECK(ap);
return ap;
}
absl::Nonnull<scoped_refptr<AudioProcessing>> Provide(
const Environment& /*env*/,
const SimulationSettings& settings, const SimulationSettings& settings,
absl::Nullable<std::unique_ptr<AudioProcessingBuilder>> ap_builder) { absl::Nullable<std::unique_ptr<AudioProcessingBuilder>> ap_builder) {
PerformBasicParameterSanityChecks(settings, PerformBasicParameterSanityChecks(settings,
@ -819,10 +850,11 @@ absl::Nonnull<scoped_refptr<AudioProcessing>> Provide(
} }
absl::Nonnull<scoped_refptr<AudioProcessing>> Provide( absl::Nonnull<scoped_refptr<AudioProcessing>> Provide(
const Environment& env,
const SimulationSettings& settings, const SimulationSettings& settings,
absl::Nullable<scoped_refptr<AudioProcessing>> ap_provider) { absl::Nullable<scoped_refptr<AudioProcessing>> ap_provider) {
if (ap_provider == nullptr) { if (ap_provider == nullptr) {
return Provide(settings, std::make_unique<AudioProcessingBuilder>()); return Provide(env, settings, std::make_unique<AudioProcessingBuilder>());
} }
PerformBasicParameterSanityChecks(settings, PerformBasicParameterSanityChecks(settings,
@ -837,14 +869,12 @@ int RunSimulation(AudioProcessingProvider ap_provider, int argc, char* argv[]) {
printf("%s", kUsageDescription); printf("%s", kUsageDescription);
return 1; 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)); FieldTrials field_trials(absl::GetFlag(FLAGS_force_fieldtrials));
const Environment env = CreateEnvironment(&field_trials);
SimulationSettings settings = CreateSettings(); SimulationSettings settings = CreateSettings();
absl::Nonnull<scoped_refptr<AudioProcessing>> audio_processing = absl::Nonnull<scoped_refptr<AudioProcessing>> audio_processing =
Provide(settings, std::move(ap_provider)); Provide(env, settings, std::move(ap_provider));
std::unique_ptr<AudioProcessingSimulator> processor; std::unique_ptr<AudioProcessingSimulator> processor;
if (settings.aec_dump_input_filename || settings.aec_dump_input_string) { 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); return RunSimulation(std::move(ap_builder), argc, argv);
} }
int AudioprocFloatImpl(
absl::Nonnull<std::unique_ptr<BuiltinAudioProcessingBuilder>> ap_builder,
int argc,
char* argv[]) {
return RunSimulation(std::move(ap_builder), argc, argv);
}
int AudioprocFloatImpl(
absl::Nonnull<std::unique_ptr<AudioProcessingBuilderInterface>> ap_builder,
int argc,
char* argv[]) {
return RunSimulation(std::move(ap_builder), argc, argv);
}
} // namespace test } // namespace test
} // namespace webrtc } // namespace webrtc

View File

@ -15,6 +15,7 @@
#include "absl/base/nullability.h" #include "absl/base/nullability.h"
#include "api/audio/audio_processing.h" #include "api/audio/audio_processing.h"
#include "api/audio/builtin_audio_processing_builder.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
namespace webrtc { namespace webrtc {
@ -30,6 +31,16 @@ int AudioprocFloatImpl(
int argc, int argc,
char* argv[]); char* argv[]);
int AudioprocFloatImpl(
absl::Nonnull<std::unique_ptr<BuiltinAudioProcessingBuilder>> ap_builder,
int argc,
char* argv[]);
int AudioprocFloatImpl(
absl::Nonnull<std::unique_ptr<AudioProcessingBuilderInterface>> ap_builder,
int argc,
char* argv[]);
} // namespace test } // namespace test
} // namespace webrtc } // namespace webrtc

View File

@ -8,12 +8,8 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <memory>
#include "api/audio/audio_processing.h"
#include "api/test/audioproc_float.h" #include "api/test/audioproc_float.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
return webrtc::test::AudioprocFloat( return webrtc::test::AudioprocFloat(argc, argv);
std::make_unique<webrtc::AudioProcessingBuilder>(), argc, argv);
} }