Replace AudioProcessingBuilderForTesting with the BuiltinAudioProcessingFactory
Bug: webrtc:369904700 Change-Id: Ie96dc1a9c052cb5340b10bf834d95f88f0a96a14 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365801 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43247}
This commit is contained in:
parent
db1c618fa1
commit
9c21f6386f
@ -460,6 +460,8 @@ if (rtc_include_tests) {
|
||||
":audio_processing",
|
||||
":audioproc_test_utils",
|
||||
"../../api:array_view",
|
||||
"../../api/audio:builtin_audio_processing_factory",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../api/numerics",
|
||||
"../../api/test/metrics:global_metrics_logger_and_exporter",
|
||||
"../../api/test/metrics:metric",
|
||||
@ -586,8 +588,6 @@ rtc_library("audioproc_test_utils") {
|
||||
sources = [
|
||||
"test/audio_buffer_tools.cc",
|
||||
"test/audio_buffer_tools.h",
|
||||
"test/audio_processing_builder_for_testing.cc",
|
||||
"test/audio_processing_builder_for_testing.h",
|
||||
"test/bitexactness_tools.cc",
|
||||
"test/bitexactness_tools.h",
|
||||
"test/performance_timer.cc",
|
||||
|
||||
@ -48,6 +48,8 @@ if (rtc_include_tests) {
|
||||
"..:audioproc_test_utils",
|
||||
"../",
|
||||
"../../../api/audio:audio_processing",
|
||||
"../../../api/audio:builtin_audio_processing_factory",
|
||||
"../../../api/environment:environment_factory",
|
||||
"//testing/gtest",
|
||||
]
|
||||
}
|
||||
|
||||
@ -13,9 +13,10 @@
|
||||
#include <utility>
|
||||
|
||||
#include "api/audio/audio_processing.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_processing/aec_dump/mock_aec_dump.h"
|
||||
#include "modules/audio_processing/audio_processing_impl.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
@ -23,9 +24,10 @@ using ::testing::Exactly;
|
||||
using ::testing::StrictMock;
|
||||
|
||||
namespace {
|
||||
rtc::scoped_refptr<webrtc::AudioProcessing> CreateAudioProcessing() {
|
||||
rtc::scoped_refptr<webrtc::AudioProcessing> apm(
|
||||
webrtc::AudioProcessingBuilderForTesting().Create());
|
||||
webrtc::scoped_refptr<webrtc::AudioProcessing> CreateAudioProcessing() {
|
||||
webrtc::scoped_refptr<webrtc::AudioProcessing> apm =
|
||||
webrtc::BuiltinAudioProcessingFactory().Create(
|
||||
webrtc::CreateEnvironment());
|
||||
RTC_DCHECK(apm);
|
||||
return apm;
|
||||
}
|
||||
|
||||
@ -13,8 +13,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_processing/audio_processing_impl.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "modules/audio_processing/test/test_utils.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/platform_thread.h"
|
||||
@ -488,9 +489,9 @@ AudioProcessing::Config GetApmTestConfig(AecType aec_type) {
|
||||
|
||||
AudioProcessingImplLockTest::AudioProcessingImplLockTest()
|
||||
: test_config_(GetParam()),
|
||||
apm_(AudioProcessingBuilderForTesting()
|
||||
apm_(BuiltinAudioProcessingFactory()
|
||||
.SetConfig(GetApmTestConfig(test_config_.aec_type))
|
||||
.Create()),
|
||||
.Create(CreateEnvironment())),
|
||||
render_thread_state_(kMaxFrameSize,
|
||||
&rand_gen_,
|
||||
&render_call_event_,
|
||||
|
||||
@ -16,11 +16,12 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/numerics/samples_stats_counter.h"
|
||||
#include "api/test/metrics/global_metrics_logger_and_exporter.h"
|
||||
#include "api/test/metrics/metric.h"
|
||||
#include "modules/audio_processing/audio_processing_impl.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "modules/audio_processing/test/test_utils.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
@ -448,31 +449,31 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
|
||||
int num_capture_channels = 1;
|
||||
switch (simulation_config_.simulation_settings) {
|
||||
case SettingsType::kDefaultApmMobile: {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
ASSERT_TRUE(!!apm_);
|
||||
set_default_mobile_apm_runtime_settings(apm_.get());
|
||||
break;
|
||||
}
|
||||
case SettingsType::kDefaultApmDesktop: {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
ASSERT_TRUE(!!apm_);
|
||||
set_default_desktop_apm_runtime_settings(apm_.get());
|
||||
break;
|
||||
}
|
||||
case SettingsType::kAllSubmodulesTurnedOff: {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
ASSERT_TRUE(!!apm_);
|
||||
turn_off_default_apm_runtime_settings(apm_.get());
|
||||
break;
|
||||
}
|
||||
case SettingsType::kDefaultApmDesktopWithoutDelayAgnostic: {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
ASSERT_TRUE(!!apm_);
|
||||
set_default_desktop_apm_runtime_settings(apm_.get());
|
||||
break;
|
||||
}
|
||||
case SettingsType::kDefaultApmDesktopWithoutExtendedFilter: {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
ASSERT_TRUE(!!apm_);
|
||||
set_default_desktop_apm_runtime_settings(apm_.get());
|
||||
break;
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/audio/echo_detector_creator.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/make_ref_counted.h"
|
||||
#include "common_audio/include/audio_util.h"
|
||||
#include "common_audio/resampler/include/push_resampler.h"
|
||||
@ -31,7 +33,6 @@
|
||||
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
|
||||
#include "modules/audio_processing/audio_processing_impl.h"
|
||||
#include "modules/audio_processing/include/mock_audio_processing.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "modules/audio_processing/test/protobuf_utils.h"
|
||||
#include "modules/audio_processing/test/test_utils.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
@ -475,7 +476,7 @@ ApmTest::ApmTest()
|
||||
far_file_(NULL),
|
||||
near_file_(NULL),
|
||||
out_file_(NULL) {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
AudioProcessing::Config apm_config = apm_->GetConfig();
|
||||
apm_config.gain_controller1.analog_gain_controller.enabled = false;
|
||||
apm_config.pipeline.maximum_internal_processing_rate = 48000;
|
||||
@ -1333,7 +1334,7 @@ TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabledFloat) {
|
||||
auto src_channels = &src[0];
|
||||
auto dest_channels = &dest[0];
|
||||
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
EXPECT_NOERR(apm_->ProcessStream(&src_channels, StreamConfig(sample_rate, 1),
|
||||
StreamConfig(sample_rate, 1),
|
||||
&dest_channels));
|
||||
@ -1754,9 +1755,9 @@ TEST_F(ApmTest, Process) {
|
||||
if (test->num_input_channels() != test->num_output_channels())
|
||||
continue;
|
||||
|
||||
apm_ = AudioProcessingBuilderForTesting()
|
||||
apm_ = BuiltinAudioProcessingFactory()
|
||||
.SetEchoDetector(CreateEchoDetector())
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
AudioProcessing::Config apm_config = apm_->GetConfig();
|
||||
apm_config.gain_controller1.analog_gain_controller.enabled = false;
|
||||
apm_->ApplyConfig(apm_config);
|
||||
@ -1993,8 +1994,9 @@ class AudioProcessingTest
|
||||
absl::string_view output_file_prefix) {
|
||||
AudioProcessing::Config apm_config;
|
||||
apm_config.gain_controller1.analog_gain_controller.enabled = false;
|
||||
rtc::scoped_refptr<AudioProcessing> ap =
|
||||
AudioProcessingBuilderForTesting().SetConfig(apm_config).Create();
|
||||
scoped_refptr<AudioProcessing> ap = BuiltinAudioProcessingFactory()
|
||||
.SetConfig(apm_config)
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
EnableAllAPComponents(ap.get());
|
||||
|
||||
@ -2419,8 +2421,8 @@ void RunApmRateAndChannelTest(
|
||||
apm_config.pipeline.multi_channel_render = true;
|
||||
apm_config.pipeline.multi_channel_capture = true;
|
||||
apm_config.echo_canceller.enabled = true;
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting().SetConfig(apm_config).Create();
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory(apm_config).Create(CreateEnvironment());
|
||||
|
||||
StreamConfig render_input_stream_config;
|
||||
StreamConfig render_output_stream_config;
|
||||
@ -2529,10 +2531,10 @@ TEST(ApmConfiguration, EnablePostProcessing) {
|
||||
new ::testing::NiceMock<test::MockCustomProcessing>();
|
||||
auto mock_post_processor =
|
||||
std::unique_ptr<CustomProcessing>(mock_post_processor_ptr);
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetCapturePostProcessing(std::move(mock_post_processor))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
Int16FrameData audio;
|
||||
audio.num_channels = 1;
|
||||
@ -2551,10 +2553,10 @@ TEST(ApmConfiguration, EnablePreProcessing) {
|
||||
new ::testing::NiceMock<test::MockCustomProcessing>();
|
||||
auto mock_pre_processor =
|
||||
std::unique_ptr<CustomProcessing>(mock_pre_processor_ptr);
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetRenderPreProcessing(std::move(mock_pre_processor))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
Int16FrameData audio;
|
||||
audio.num_channels = 1;
|
||||
@ -2573,10 +2575,10 @@ TEST(ApmConfiguration, EnableCaptureAnalyzer) {
|
||||
new ::testing::NiceMock<test::MockCustomAudioAnalyzer>();
|
||||
auto mock_capture_analyzer =
|
||||
std::unique_ptr<CustomAudioAnalyzer>(mock_capture_analyzer_ptr);
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetCaptureAnalyzer(std::move(mock_capture_analyzer))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
Int16FrameData audio;
|
||||
audio.num_channels = 1;
|
||||
@ -2594,10 +2596,10 @@ TEST(ApmConfiguration, PreProcessingReceivesRuntimeSettings) {
|
||||
new ::testing::NiceMock<test::MockCustomProcessing>();
|
||||
auto mock_pre_processor =
|
||||
std::unique_ptr<CustomProcessing>(mock_pre_processor_ptr);
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetRenderPreProcessing(std::move(mock_pre_processor))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
apm->SetRuntimeSetting(
|
||||
AudioProcessing::RuntimeSetting::CreateCustomRenderSetting(0));
|
||||
|
||||
@ -2638,10 +2640,10 @@ TEST(ApmConfiguration, EchoControlInjection) {
|
||||
std::unique_ptr<EchoControlFactory> echo_control_factory(
|
||||
new MyEchoControlFactory());
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetEchoControlFactory(std::move(echo_control_factory))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
Int16FrameData audio;
|
||||
audio.num_channels = 1;
|
||||
@ -2668,10 +2670,9 @@ TEST(ApmConfiguration, EchoDetectorInjection) {
|
||||
Initialize(/*capture_sample_rate_hz=*/16000, _,
|
||||
/*render_sample_rate_hz=*/16000, _))
|
||||
.Times(1);
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
.SetEchoDetector(mock_echo_detector)
|
||||
.Create();
|
||||
scoped_refptr<AudioProcessing> apm = BuiltinAudioProcessingFactory()
|
||||
.SetEchoDetector(mock_echo_detector)
|
||||
.Create(CreateEnvironment());
|
||||
|
||||
// The echo detector is included in processing when enabled.
|
||||
EXPECT_CALL(*mock_echo_detector, AnalyzeRenderAudio(_))
|
||||
@ -2725,10 +2726,10 @@ TEST(ApmConfiguration, EchoDetectorInjection) {
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> CreateApm(bool mobile_aec) {
|
||||
// Enable residual echo detection, for stats.
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetEchoDetector(CreateEchoDetector())
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
if (!apm) {
|
||||
return apm;
|
||||
}
|
||||
@ -2871,8 +2872,8 @@ TEST(ApmStatistics, DoNotReportVoiceDetectedStat) {
|
||||
ptr[i] = 10000 * ((i % 3) - 1);
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
apm->Initialize(processing_config);
|
||||
|
||||
// No metric should be reported.
|
||||
@ -2886,8 +2887,8 @@ TEST(ApmStatistics, DoNotReportVoiceDetectedStat) {
|
||||
}
|
||||
|
||||
TEST(ApmStatistics, GetStatisticsReportsNoEchoDetectorStatsWhenDisabled) {
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
Int16FrameData frame;
|
||||
frame.num_channels = 1;
|
||||
SetFrameSampleRate(&frame, AudioProcessing::NativeRate::kSampleRate32kHz);
|
||||
@ -2905,10 +2906,10 @@ TEST(ApmStatistics, GetStatisticsReportsNoEchoDetectorStatsWhenDisabled) {
|
||||
|
||||
TEST(ApmStatistics, GetStatisticsReportsEchoDetectorStatsWhenEnabled) {
|
||||
// Create APM with an echo detector injected.
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetEchoDetector(CreateEchoDetector())
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
Int16FrameData frame;
|
||||
frame.num_channels = 1;
|
||||
SetFrameSampleRate(&frame, AudioProcessing::NativeRate::kSampleRate32kHz);
|
||||
@ -3282,8 +3283,8 @@ TEST_P(ApmFormatHandlingTest, IntApi) {
|
||||
}
|
||||
|
||||
// Call APM.
|
||||
rtc::scoped_refptr<AudioProcessing> ap =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
scoped_refptr<AudioProcessing> ap =
|
||||
BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
int error;
|
||||
if (stream_direction_ == kForward) {
|
||||
error = ap->ProcessStream(input_block.data(), test_params_.input_config,
|
||||
@ -3361,8 +3362,8 @@ TEST_P(ApmFormatHandlingTest, FloatApi) {
|
||||
}
|
||||
|
||||
// Call APM.
|
||||
rtc::scoped_refptr<AudioProcessing> ap =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
scoped_refptr<AudioProcessing> ap =
|
||||
BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
int error;
|
||||
if (stream_direction_ == kForward) {
|
||||
error =
|
||||
@ -3437,8 +3438,8 @@ TEST(ApmAnalyzeReverseStreamFormatTest, AnalyzeReverseStream) {
|
||||
input_config.num_channels());
|
||||
|
||||
// Call APM.
|
||||
rtc::scoped_refptr<AudioProcessing> ap =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
scoped_refptr<AudioProcessing> ap =
|
||||
BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
int error = ap->AnalyzeReverseStream(input_block.channels(), input_config);
|
||||
|
||||
// Check output.
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "modules/audio_processing/audio_processing_impl.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
AudioProcessingBuilderForTesting::AudioProcessingBuilderForTesting() = default;
|
||||
AudioProcessingBuilderForTesting::~AudioProcessingBuilderForTesting() = default;
|
||||
|
||||
#ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
|
||||
return rtc::make_ref_counted<AudioProcessingImpl>(
|
||||
config_, std::move(capture_post_processing_),
|
||||
std::move(render_pre_processing_), std::move(echo_control_factory_),
|
||||
std::move(echo_detector_), std::move(capture_analyzer_));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
|
||||
AudioProcessingBuilder builder;
|
||||
TransferOwnershipsToBuilder(&builder);
|
||||
return builder.SetConfig(config_).Create();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void AudioProcessingBuilderForTesting::TransferOwnershipsToBuilder(
|
||||
AudioProcessingBuilder* builder) {
|
||||
builder->SetCapturePostProcessing(std::move(capture_post_processing_));
|
||||
builder->SetRenderPreProcessing(std::move(render_pre_processing_));
|
||||
builder->SetEchoControlFactory(std::move(echo_control_factory_));
|
||||
builder->SetEchoDetector(std::move(echo_detector_));
|
||||
builder->SetCaptureAnalyzer(std::move(capture_analyzer_));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
|
||||
#define MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio/audio_processing.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Facilitates building of AudioProcessingImp for the tests.
|
||||
class AudioProcessingBuilderForTesting {
|
||||
public:
|
||||
AudioProcessingBuilderForTesting();
|
||||
AudioProcessingBuilderForTesting(const AudioProcessingBuilderForTesting&) =
|
||||
delete;
|
||||
AudioProcessingBuilderForTesting& operator=(
|
||||
const AudioProcessingBuilderForTesting&) = delete;
|
||||
~AudioProcessingBuilderForTesting();
|
||||
|
||||
// Sets the APM configuration.
|
||||
AudioProcessingBuilderForTesting& SetConfig(
|
||||
const AudioProcessing::Config& config) {
|
||||
config_ = config;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sets the echo controller factory to inject when APM is created.
|
||||
AudioProcessingBuilderForTesting& SetEchoControlFactory(
|
||||
std::unique_ptr<EchoControlFactory> echo_control_factory) {
|
||||
echo_control_factory_ = std::move(echo_control_factory);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sets the capture post-processing sub-module to inject when APM is created.
|
||||
AudioProcessingBuilderForTesting& SetCapturePostProcessing(
|
||||
std::unique_ptr<CustomProcessing> capture_post_processing) {
|
||||
capture_post_processing_ = std::move(capture_post_processing);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sets the render pre-processing sub-module to inject when APM is created.
|
||||
AudioProcessingBuilderForTesting& SetRenderPreProcessing(
|
||||
std::unique_ptr<CustomProcessing> render_pre_processing) {
|
||||
render_pre_processing_ = std::move(render_pre_processing);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sets the echo detector to inject when APM is created.
|
||||
AudioProcessingBuilderForTesting& SetEchoDetector(
|
||||
rtc::scoped_refptr<EchoDetector> echo_detector) {
|
||||
echo_detector_ = std::move(echo_detector);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Sets the capture analyzer sub-module to inject when APM is created.
|
||||
AudioProcessingBuilderForTesting& SetCaptureAnalyzer(
|
||||
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer) {
|
||||
capture_analyzer_ = std::move(capture_analyzer);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Creates an APM instance with the specified config or the default one if
|
||||
// unspecified. Injects the specified components transferring the ownership
|
||||
// to the newly created APM instance - i.e., except for the config, the
|
||||
// builder is reset to its initial state.
|
||||
rtc::scoped_refptr<AudioProcessing> Create();
|
||||
|
||||
private:
|
||||
// Transfers the ownership to a non-testing builder.
|
||||
void TransferOwnershipsToBuilder(AudioProcessingBuilder* builder);
|
||||
|
||||
AudioProcessing::Config config_;
|
||||
std::unique_ptr<EchoControlFactory> echo_control_factory_;
|
||||
std::unique_ptr<CustomProcessing> capture_post_processing_;
|
||||
std::unique_ptr<CustomProcessing> render_pre_processing_;
|
||||
rtc::scoped_refptr<EchoDetector> echo_detector_;
|
||||
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_BUILDER_FOR_TESTING_H_
|
||||
@ -13,7 +13,8 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_processing/test/protobuf_utils.h"
|
||||
#include "modules/audio_processing/test/runtime_setting_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
@ -188,8 +189,8 @@ void DebugDumpReplayer::MaybeRecreateApm(const audioproc::Config& msg) {
|
||||
|
||||
// We only create APM once, since changes on these fields should not
|
||||
// happen in current implementation.
|
||||
if (!apm_.get()) {
|
||||
apm_ = AudioProcessingBuilderForTesting().Create();
|
||||
if (apm_ == nullptr) {
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,10 +15,11 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/audio/echo_canceller3_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
|
||||
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "modules/audio_processing/test/debug_dump_replayer.h"
|
||||
#include "modules/audio_processing/test/test_utils.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
@ -140,8 +141,7 @@ DebugDumpGenerator::DebugDumpGenerator(absl::string_view input_file_name,
|
||||
enable_pre_amplifier_(enable_pre_amplifier),
|
||||
worker_queue_("debug_dump_generator_worker_queue"),
|
||||
dump_file_name_(dump_file_name) {
|
||||
AudioProcessingBuilderForTesting apm_builder;
|
||||
apm_ = apm_builder.Create();
|
||||
apm_ = BuiltinAudioProcessingFactory().Create(CreateEnvironment());
|
||||
}
|
||||
|
||||
DebugDumpGenerator::DebugDumpGenerator(
|
||||
|
||||
@ -2580,6 +2580,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
||||
"../api/audio:audio_device",
|
||||
"../api/audio:audio_mixer_api",
|
||||
"../api/audio:audio_processing",
|
||||
"../api/audio:builtin_audio_processing_factory",
|
||||
"../api/crypto:frame_decryptor_interface",
|
||||
"../api/crypto:frame_encryptor_interface",
|
||||
"../api/crypto:options",
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#include "pc/test/integration_test_helpers.h"
|
||||
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() {
|
||||
@ -225,6 +227,11 @@ bool PeerConnectionIntegrationWrapper::Init(
|
||||
|
||||
pc_factory_dependencies.adm = fake_audio_capture_module_;
|
||||
if (create_media_engine) {
|
||||
// Standard creation method for APM may return a null pointer when
|
||||
// AudioProcessing is disabled with a build flag. Bypass that flag by
|
||||
// explicitly injecting the factory.
|
||||
pc_factory_dependencies.audio_processing_factory =
|
||||
std::make_unique<BuiltinAudioProcessingFactory>();
|
||||
EnableMediaWithDefaults(pc_factory_dependencies);
|
||||
}
|
||||
|
||||
@ -235,17 +242,6 @@ bool PeerConnectionIntegrationWrapper::Init(
|
||||
pc_factory_dependencies.video_decoder_factory.reset();
|
||||
}
|
||||
|
||||
// TODO: bugs.webrtc.org/369904700 - inject test specific
|
||||
// audio_processing_factory right away when `EnableMediaWithDefault` would
|
||||
// always keep audio_processing unchanged and thus can postpone
|
||||
// AudioProcessing construction.
|
||||
if (!pc_factory_dependencies.audio_processing) {
|
||||
// If the standard Creation method for APM returns a null pointer, instead
|
||||
// use the builder for testing to create an APM object.
|
||||
pc_factory_dependencies.audio_processing =
|
||||
AudioProcessingBuilderForTesting().Create();
|
||||
}
|
||||
|
||||
if (event_log_factory) {
|
||||
event_log_factory_ = event_log_factory.get();
|
||||
pc_factory_dependencies.event_log_factory = std::move(event_log_factory);
|
||||
|
||||
@ -70,7 +70,6 @@
|
||||
#include "media/base/media_engine.h"
|
||||
#include "media/base/stream_params.h"
|
||||
#include "media/engine/fake_webrtc_video_engine.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "p2p/base/fake_ice_transport.h"
|
||||
#include "p2p/base/ice_transport_internal.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
|
||||
@ -512,7 +512,10 @@ webrtc_fuzzer_test("audio_processing_fuzzer") {
|
||||
"../../api:scoped_refptr",
|
||||
"../../api/audio:aec3_factory",
|
||||
"../../api/audio:audio_processing",
|
||||
"../../api/audio:builtin_audio_processing_factory",
|
||||
"../../api/audio:echo_detector_creator",
|
||||
"../../api/environment",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../api/task_queue",
|
||||
"../../api/task_queue:default_task_queue_factory",
|
||||
"../../modules/audio_processing",
|
||||
@ -536,6 +539,8 @@ webrtc_fuzzer_test("audio_processing_sample_rate_fuzzer") {
|
||||
"../../api:scoped_refptr",
|
||||
"../../api/audio:audio_frame_api",
|
||||
"../../api/audio:audio_processing",
|
||||
"../../api/audio:builtin_audio_processing_factory",
|
||||
"../../api/environment:environment_factory",
|
||||
"../../modules/audio_processing",
|
||||
"../../modules/audio_processing:audio_frame_proxies",
|
||||
"../../modules/audio_processing:audioproc_test_utils",
|
||||
|
||||
@ -14,12 +14,14 @@
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/audio/audio_processing.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.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/task_queue/default_task_queue_factory.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/numerics/safe_minmax.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
@ -34,6 +36,11 @@ const std::string kFieldTrialNames[] = {
|
||||
"WebRTC-Aec3ShortHeadroomKillSwitch",
|
||||
};
|
||||
|
||||
const Environment& GetEnvironment() {
|
||||
static const Environment* const env = new Environment(CreateEnvironment());
|
||||
return *env;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> CreateApm(
|
||||
test::FuzzDataHelper* fuzz_data,
|
||||
std::string* field_trial_string,
|
||||
@ -105,12 +112,12 @@ rtc::scoped_refptr<AudioProcessing> CreateApm(
|
||||
apm_config.noise_suppression.enabled = use_ns;
|
||||
apm_config.transient_suppression.enabled = use_ts;
|
||||
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetEchoControlFactory(std::move(echo_control_factory))
|
||||
.SetEchoDetector(use_red ? CreateEchoDetector() : nullptr)
|
||||
.SetConfig(apm_config)
|
||||
.Create();
|
||||
.Create(GetEnvironment());
|
||||
|
||||
#ifdef WEBRTC_LINUX
|
||||
apm->AttachAecDump(AecDumpFactory::Create("/dev/null", -1, worker_queue));
|
||||
@ -119,12 +126,6 @@ rtc::scoped_refptr<AudioProcessing> CreateApm(
|
||||
return apm;
|
||||
}
|
||||
|
||||
TaskQueueFactory* GetTaskQueueFactory() {
|
||||
static TaskQueueFactory* const factory =
|
||||
CreateDefaultTaskQueueFactory().release();
|
||||
return factory;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
@ -137,8 +138,8 @@ void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
std::string field_trial_string = "";
|
||||
|
||||
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> worker_queue =
|
||||
GetTaskQueueFactory()->CreateTaskQueue("rtc-low-prio",
|
||||
TaskQueueFactory::Priority::LOW);
|
||||
GetEnvironment().task_queue_factory().CreateTaskQueue(
|
||||
"rtc-low-prio", TaskQueueFactory::Priority::LOW);
|
||||
auto apm = CreateApm(&fuzz_data, &field_trial_string, worker_queue.get());
|
||||
|
||||
if (apm) {
|
||||
|
||||
@ -14,7 +14,8 @@
|
||||
#include <limits>
|
||||
|
||||
#include "api/audio/audio_processing.h"
|
||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||
#include "api/audio/builtin_audio_processing_factory.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "test/fuzzers/fuzz_data_helper.h"
|
||||
|
||||
@ -89,13 +90,13 @@ void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
fuzz_data.ReadOrDefaultValue(true)
|
||||
? std::make_unique<NoopCustomProcessing>()
|
||||
: nullptr;
|
||||
rtc::scoped_refptr<AudioProcessing> apm =
|
||||
AudioProcessingBuilderForTesting()
|
||||
scoped_refptr<AudioProcessing> apm =
|
||||
BuiltinAudioProcessingFactory()
|
||||
.SetConfig({.pipeline = {.multi_channel_render = true,
|
||||
.multi_channel_capture = true}})
|
||||
.SetCapturePostProcessing(std::move(capture_processor))
|
||||
.SetRenderPreProcessing(std::move(render_processor))
|
||||
.Create();
|
||||
.Create(CreateEnvironment());
|
||||
RTC_DCHECK(apm);
|
||||
|
||||
std::array<int16_t, kMaxSamplesPerChannel * kMaxNumChannels> fixed_frame;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user