Use make_ref_counted in AudioProcessingBuilder

Bug: webrtc:12701
Change-Id: I51ca5a54f812a1620ee2e6605c9ff67b92e2a5f8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/224547
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34725}
This commit is contained in:
Niels Möller 2021-07-02 11:30:54 +02:00 committed by WebRTC LUCI CQ
parent 897bf9bff1
commit 4f776ac7de
15 changed files with 70 additions and 69 deletions

View File

@ -23,9 +23,9 @@ using ::testing::Exactly;
using ::testing::StrictMock; using ::testing::StrictMock;
namespace { namespace {
std::unique_ptr<webrtc::AudioProcessing> CreateAudioProcessing() { rtc::scoped_refptr<webrtc::AudioProcessing> CreateAudioProcessing() {
webrtc::Config config; webrtc::Config config;
std::unique_ptr<webrtc::AudioProcessing> apm( rtc::scoped_refptr<webrtc::AudioProcessing> apm(
webrtc::AudioProcessingBuilderForTesting().Create(config)); webrtc::AudioProcessingBuilderForTesting().Create(config));
RTC_DCHECK(apm); RTC_DCHECK(apm);
return apm; return apm;

View File

@ -20,12 +20,13 @@ namespace webrtc {
AudioProcessingBuilder::AudioProcessingBuilder() = default; AudioProcessingBuilder::AudioProcessingBuilder() = default;
AudioProcessingBuilder::~AudioProcessingBuilder() = default; AudioProcessingBuilder::~AudioProcessingBuilder() = default;
AudioProcessing* AudioProcessingBuilder::Create() { rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilder::Create() {
webrtc::Config config; webrtc::Config config;
return Create(config); return Create(config);
} }
AudioProcessing* AudioProcessingBuilder::Create(const webrtc::Config& config) { rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilder::Create(
const webrtc::Config& config) {
#ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE #ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE
// Implementation returning a null pointer for using when the APM is excluded // Implementation returning a null pointer for using when the APM is excluded
@ -35,7 +36,7 @@ AudioProcessing* AudioProcessingBuilder::Create(const webrtc::Config& config) {
#else #else
// Standard implementation. // Standard implementation.
return new rtc::RefCountedObject<AudioProcessingImpl>( return rtc::make_ref_counted<AudioProcessingImpl>(
config, std::move(capture_post_processing_), config, std::move(capture_post_processing_),
std::move(render_pre_processing_), std::move(echo_control_factory_), std::move(render_pre_processing_), std::move(echo_control_factory_),
std::move(echo_detector_), std::move(capture_analyzer_)); std::move(echo_detector_), std::move(capture_analyzer_));

View File

@ -428,7 +428,7 @@ class AudioProcessingImplLockTest
// Thread related variables. // Thread related variables.
mutable RandomGenerator rand_gen_; mutable RandomGenerator rand_gen_;
std::unique_ptr<AudioProcessing> apm_; rtc::scoped_refptr<AudioProcessing> apm_;
TestConfig test_config_; TestConfig test_config_;
FrameCounters frame_counters_; FrameCounters frame_counters_;
RenderProcessor render_thread_state_; RenderProcessor render_thread_state_;

View File

@ -173,8 +173,8 @@ TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
} }
TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) { TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) {
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.pre_amplifier.enabled = true; apm_config.pre_amplifier.enabled = true;
apm_config.pre_amplifier.fixed_gain_factor = 1.f; apm_config.pre_amplifier.fixed_gain_factor = 1.f;
@ -206,8 +206,8 @@ TEST(AudioProcessingImplTest, UpdateCapturePreGainRuntimeSetting) {
TEST(AudioProcessingImplTest, TEST(AudioProcessingImplTest,
LevelAdjustmentUpdateCapturePreGainRuntimeSetting) { LevelAdjustmentUpdateCapturePreGainRuntimeSetting) {
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.capture_level_adjustment.enabled = true; apm_config.capture_level_adjustment.enabled = true;
apm_config.capture_level_adjustment.pre_gain_factor = 1.f; apm_config.capture_level_adjustment.pre_gain_factor = 1.f;
@ -239,8 +239,8 @@ TEST(AudioProcessingImplTest,
TEST(AudioProcessingImplTest, TEST(AudioProcessingImplTest,
LevelAdjustmentUpdateCapturePostGainRuntimeSetting) { LevelAdjustmentUpdateCapturePostGainRuntimeSetting) {
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.capture_level_adjustment.enabled = true; apm_config.capture_level_adjustment.enabled = true;
apm_config.capture_level_adjustment.post_gain_factor = 1.f; apm_config.capture_level_adjustment.post_gain_factor = 1.f;
@ -277,10 +277,10 @@ TEST(AudioProcessingImplTest, EchoControllerObservesSetCaptureUsageChange) {
const MockEchoControlFactory* echo_control_factory_ptr = const MockEchoControlFactory* echo_control_factory_ptr =
echo_control_factory.get(); echo_control_factory.get();
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create()); .Create();
constexpr int16_t kAudioLevel = 10000; constexpr int16_t kAudioLevel = 10000;
constexpr int kSampleRateHz = 48000; constexpr int kSampleRateHz = 48000;
@ -359,10 +359,10 @@ TEST(AudioProcessingImplTest,
auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
const auto* echo_control_factory_ptr = echo_control_factory.get(); const auto* echo_control_factory_ptr = echo_control_factory.get();
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create()); .Create();
// Disable AGC. // Disable AGC.
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.gain_controller1.enabled = false; apm_config.gain_controller1.enabled = false;
@ -402,10 +402,10 @@ TEST(AudioProcessingImplTest,
auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
const auto* echo_control_factory_ptr = echo_control_factory.get(); const auto* echo_control_factory_ptr = echo_control_factory.get();
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create()); .Create();
// Disable AGC. // Disable AGC.
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.gain_controller1.enabled = false; apm_config.gain_controller1.enabled = false;
@ -445,10 +445,10 @@ TEST(AudioProcessingImplTest,
auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
const auto* echo_control_factory_ptr = echo_control_factory.get(); const auto* echo_control_factory_ptr = echo_control_factory.get();
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create()); .Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
// Enable AGC1. // Enable AGC1.
apm_config.gain_controller1.enabled = true; apm_config.gain_controller1.enabled = true;
@ -491,10 +491,10 @@ TEST(AudioProcessingImplTest, EchoControllerObservesPlayoutVolumeChange) {
auto echo_control_factory = std::make_unique<MockEchoControlFactory>(); auto echo_control_factory = std::make_unique<MockEchoControlFactory>();
const auto* echo_control_factory_ptr = echo_control_factory.get(); const auto* echo_control_factory_ptr = echo_control_factory.get();
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create()); .Create();
// Disable AGC. // Disable AGC.
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.gain_controller1.enabled = false; apm_config.gain_controller1.enabled = false;
@ -549,11 +549,11 @@ TEST(AudioProcessingImplTest, RenderPreProcessorBeforeEchoDetector) {
std::unique_ptr<CustomProcessing> test_render_pre_processor( std::unique_ptr<CustomProcessing> test_render_pre_processor(
new TestRenderPreProcessor()); new TestRenderPreProcessor());
// Create APM injecting the test echo detector and render pre-processor. // Create APM injecting the test echo detector and render pre-processor.
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoDetector(test_echo_detector) .SetEchoDetector(test_echo_detector)
.SetRenderPreProcessing(std::move(test_render_pre_processor)) .SetRenderPreProcessing(std::move(test_render_pre_processor))
.Create()); .Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.pre_amplifier.enabled = true; apm_config.pre_amplifier.enabled = true;
apm_config.residual_echo_detector.enabled = true; apm_config.residual_echo_detector.enabled = true;

View File

@ -476,34 +476,34 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
int num_capture_channels = 1; int num_capture_channels = 1;
switch (simulation_config_.simulation_settings) { switch (simulation_config_.simulation_settings) {
case SettingsType::kDefaultApmMobile: { case SettingsType::kDefaultApmMobile: {
apm_.reset(AudioProcessingBuilderForTesting().Create()); apm_ = AudioProcessingBuilderForTesting().Create();
ASSERT_TRUE(!!apm_); ASSERT_TRUE(!!apm_);
set_default_mobile_apm_runtime_settings(apm_.get()); set_default_mobile_apm_runtime_settings(apm_.get());
break; break;
} }
case SettingsType::kDefaultApmDesktop: { case SettingsType::kDefaultApmDesktop: {
Config config; Config config;
apm_.reset(AudioProcessingBuilderForTesting().Create(config)); apm_ = AudioProcessingBuilderForTesting().Create(config);
ASSERT_TRUE(!!apm_); ASSERT_TRUE(!!apm_);
set_default_desktop_apm_runtime_settings(apm_.get()); set_default_desktop_apm_runtime_settings(apm_.get());
break; break;
} }
case SettingsType::kAllSubmodulesTurnedOff: { case SettingsType::kAllSubmodulesTurnedOff: {
apm_.reset(AudioProcessingBuilderForTesting().Create()); apm_ = AudioProcessingBuilderForTesting().Create();
ASSERT_TRUE(!!apm_); ASSERT_TRUE(!!apm_);
turn_off_default_apm_runtime_settings(apm_.get()); turn_off_default_apm_runtime_settings(apm_.get());
break; break;
} }
case SettingsType::kDefaultApmDesktopWithoutDelayAgnostic: { case SettingsType::kDefaultApmDesktopWithoutDelayAgnostic: {
Config config; Config config;
apm_.reset(AudioProcessingBuilderForTesting().Create(config)); apm_ = AudioProcessingBuilderForTesting().Create(config);
ASSERT_TRUE(!!apm_); ASSERT_TRUE(!!apm_);
set_default_desktop_apm_runtime_settings(apm_.get()); set_default_desktop_apm_runtime_settings(apm_.get());
break; break;
} }
case SettingsType::kDefaultApmDesktopWithoutExtendedFilter: { case SettingsType::kDefaultApmDesktopWithoutExtendedFilter: {
Config config; Config config;
apm_.reset(AudioProcessingBuilderForTesting().Create(config)); apm_ = AudioProcessingBuilderForTesting().Create(config);
ASSERT_TRUE(!!apm_); ASSERT_TRUE(!!apm_);
set_default_desktop_apm_runtime_settings(apm_.get()); set_default_desktop_apm_runtime_settings(apm_.get());
break; break;
@ -544,7 +544,7 @@ class CallSimulator : public ::testing::TestWithParam<SimulationConfig> {
// Thread related variables. // Thread related variables.
Random rand_gen_; Random rand_gen_;
std::unique_ptr<AudioProcessing> apm_; rtc::scoped_refptr<AudioProcessing> apm_;
const SimulationConfig simulation_config_; const SimulationConfig simulation_config_;
FrameCounters frame_counters_; FrameCounters frame_counters_;
LockedFlag capture_call_checker_; LockedFlag capture_call_checker_;

View File

@ -415,7 +415,7 @@ class ApmTest : public ::testing::Test {
const std::string output_path_; const std::string output_path_;
const std::string ref_filename_; const std::string ref_filename_;
std::unique_ptr<AudioProcessing> apm_; rtc::scoped_refptr<AudioProcessing> apm_;
Int16FrameData frame_; Int16FrameData frame_;
Int16FrameData revframe_; Int16FrameData revframe_;
std::unique_ptr<ChannelBuffer<float> > float_cb_; std::unique_ptr<ChannelBuffer<float> > float_cb_;
@ -435,7 +435,7 @@ ApmTest::ApmTest()
far_file_(NULL), far_file_(NULL),
near_file_(NULL), near_file_(NULL),
out_file_(NULL) { out_file_(NULL) {
apm_.reset(AudioProcessingBuilderForTesting().Create()); apm_ = AudioProcessingBuilderForTesting().Create();
AudioProcessing::Config apm_config = apm_->GetConfig(); AudioProcessing::Config apm_config = apm_->GetConfig();
apm_config.gain_controller1.analog_gain_controller.enabled = false; apm_config.gain_controller1.analog_gain_controller.enabled = false;
apm_config.pipeline.maximum_internal_processing_rate = 48000; apm_config.pipeline.maximum_internal_processing_rate = 48000;
@ -1312,7 +1312,7 @@ TEST_F(ApmTest, NoProcessingWhenAllComponentsDisabledFloat) {
auto src_channels = &src[0]; auto src_channels = &src[0];
auto dest_channels = &dest[0]; auto dest_channels = &dest[0];
apm_.reset(AudioProcessingBuilderForTesting().Create()); apm_ = AudioProcessingBuilderForTesting().Create();
EXPECT_NOERR(apm_->ProcessStream(&src_channels, StreamConfig(sample_rate, 1), EXPECT_NOERR(apm_->ProcessStream(&src_channels, StreamConfig(sample_rate, 1),
StreamConfig(sample_rate, 1), StreamConfig(sample_rate, 1),
&dest_channels)); &dest_channels));
@ -1773,7 +1773,7 @@ TEST_F(ApmTest, Process) {
if (test->num_input_channels() != test->num_output_channels()) if (test->num_input_channels() != test->num_output_channels())
continue; continue;
apm_.reset(AudioProcessingBuilderForTesting().Create()); apm_ = AudioProcessingBuilderForTesting().Create();
AudioProcessing::Config apm_config = apm_->GetConfig(); AudioProcessing::Config apm_config = apm_->GetConfig();
apm_config.gain_controller1.analog_gain_controller.enabled = false; apm_config.gain_controller1.analog_gain_controller.enabled = false;
apm_->ApplyConfig(apm_config); apm_->ApplyConfig(apm_config);
@ -1942,8 +1942,8 @@ TEST_F(ApmTest, NoErrorsWithKeyboardChannel) {
{AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo}, {AudioProcessing::kStereoAndKeyboard, AudioProcessing::kStereo},
}; };
std::unique_ptr<AudioProcessing> ap( rtc::scoped_refptr<AudioProcessing> ap =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
// Enable one component just to ensure some processing takes place. // Enable one component just to ensure some processing takes place.
AudioProcessing::Config config; AudioProcessing::Config config;
config.noise_suppression.enabled = true; config.noise_suppression.enabled = true;
@ -2069,8 +2069,8 @@ class AudioProcessingTest
size_t num_reverse_input_channels, size_t num_reverse_input_channels,
size_t num_reverse_output_channels, size_t num_reverse_output_channels,
const std::string& output_file_prefix) { const std::string& output_file_prefix) {
std::unique_ptr<AudioProcessing> ap( rtc::scoped_refptr<AudioProcessing> ap =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
AudioProcessing::Config apm_config = ap->GetConfig(); AudioProcessing::Config apm_config = ap->GetConfig();
apm_config.gain_controller1.analog_gain_controller.enabled = false; apm_config.gain_controller1.analog_gain_controller.enabled = false;
ap->ApplyConfig(apm_config); ap->ApplyConfig(apm_config);
@ -2454,8 +2454,8 @@ void RunApmRateAndChannelTest(
rtc::ArrayView<const int> sample_rates_hz, rtc::ArrayView<const int> sample_rates_hz,
rtc::ArrayView<const int> render_channel_counts, rtc::ArrayView<const int> render_channel_counts,
rtc::ArrayView<const int> capture_channel_counts) { rtc::ArrayView<const int> capture_channel_counts) {
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
apm_config.echo_canceller.enabled = true; apm_config.echo_canceller.enabled = true;
apm->ApplyConfig(apm_config); apm->ApplyConfig(apm_config);
@ -2699,10 +2699,10 @@ TEST(ApmConfiguration, EchoControlInjection) {
audio.data.data()); audio.data.data());
} }
std::unique_ptr<AudioProcessing> CreateApm(bool mobile_aec) { rtc::scoped_refptr<AudioProcessing> CreateApm(bool mobile_aec) {
Config old_config; Config old_config;
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create(old_config)); AudioProcessingBuilderForTesting().Create(old_config);
if (!apm) { if (!apm) {
return apm; return apm;
} }
@ -2737,7 +2737,7 @@ std::unique_ptr<AudioProcessing> CreateApm(bool mobile_aec) {
TEST(MAYBE_ApmStatistics, AECEnabledTest) { TEST(MAYBE_ApmStatistics, AECEnabledTest) {
// Set up APM with AEC3 and process some audio. // Set up APM with AEC3 and process some audio.
std::unique_ptr<AudioProcessing> apm = CreateApm(false); rtc::scoped_refptr<AudioProcessing> apm = CreateApm(false);
ASSERT_TRUE(apm); ASSERT_TRUE(apm);
AudioProcessing::Config apm_config; AudioProcessing::Config apm_config;
apm_config.echo_canceller.enabled = true; apm_config.echo_canceller.enabled = true;
@ -2788,7 +2788,7 @@ TEST(MAYBE_ApmStatistics, AECEnabledTest) {
TEST(MAYBE_ApmStatistics, AECMEnabledTest) { TEST(MAYBE_ApmStatistics, AECMEnabledTest) {
// Set up APM with AECM and process some audio. // Set up APM with AECM and process some audio.
std::unique_ptr<AudioProcessing> apm = CreateApm(true); rtc::scoped_refptr<AudioProcessing> apm = CreateApm(true);
ASSERT_TRUE(apm); ASSERT_TRUE(apm);
// Set up an audioframe. // Set up an audioframe.
@ -2853,8 +2853,8 @@ TEST(ApmStatistics, ReportOutputRmsDbfs) {
ptr[i] = 10000 * ((i % 3) - 1); ptr[i] = 10000 * ((i % 3) - 1);
} }
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
apm->Initialize(processing_config); apm->Initialize(processing_config);
// If not enabled, no metric should be reported. // If not enabled, no metric should be reported.
@ -2907,8 +2907,8 @@ TEST(ApmStatistics, ReportHasVoice) {
ptr[i] = 10000 * ((i % 3) - 1); ptr[i] = 10000 * ((i % 3) - 1);
} }
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting().Create()); AudioProcessingBuilderForTesting().Create();
apm->Initialize(processing_config); apm->Initialize(processing_config);
// If not enabled, no metric should be reported. // If not enabled, no metric should be reported.

View File

@ -815,8 +815,8 @@ class RTC_EXPORT AudioProcessingBuilder {
} }
// This creates an APM instance using the previously set components. Calling // This creates an APM instance using the previously set components. Calling
// the Create function resets the AudioProcessingBuilder to its initial state. // the Create function resets the AudioProcessingBuilder to its initial state.
AudioProcessing* Create(); rtc::scoped_refptr<AudioProcessing> Create();
AudioProcessing* Create(const webrtc::Config& config); rtc::scoped_refptr<AudioProcessing> Create(const webrtc::Config& config);
private: private:
std::unique_ptr<EchoControlFactory> echo_control_factory_; std::unique_ptr<EchoControlFactory> echo_control_factory_;

View File

@ -23,14 +23,14 @@ AudioProcessingBuilderForTesting::~AudioProcessingBuilderForTesting() = default;
#ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE #ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE
AudioProcessing* AudioProcessingBuilderForTesting::Create() { rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
webrtc::Config config; webrtc::Config config;
return Create(config); return Create(config);
} }
AudioProcessing* AudioProcessingBuilderForTesting::Create( rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create(
const webrtc::Config& config) { const webrtc::Config& config) {
return new rtc::RefCountedObject<AudioProcessingImpl>( return rtc::make_ref_counted<AudioProcessingImpl>(
config, std::move(capture_post_processing_), config, std::move(capture_post_processing_),
std::move(render_pre_processing_), std::move(echo_control_factory_), std::move(render_pre_processing_), std::move(echo_control_factory_),
std::move(echo_detector_), std::move(capture_analyzer_)); std::move(echo_detector_), std::move(capture_analyzer_));
@ -38,13 +38,13 @@ AudioProcessing* AudioProcessingBuilderForTesting::Create(
#else #else
AudioProcessing* AudioProcessingBuilderForTesting::Create() { rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
AudioProcessingBuilder builder; AudioProcessingBuilder builder;
TransferOwnershipsToBuilder(&builder); TransferOwnershipsToBuilder(&builder);
return builder.Create(); return builder.Create();
} }
AudioProcessing* AudioProcessingBuilderForTesting::Create( rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create(
const webrtc::Config& config) { const webrtc::Config& config) {
AudioProcessingBuilder builder; AudioProcessingBuilder builder;
TransferOwnershipsToBuilder(&builder); TransferOwnershipsToBuilder(&builder);

View File

@ -62,8 +62,8 @@ class AudioProcessingBuilderForTesting {
// This creates an APM instance using the previously set components. Calling // This creates an APM instance using the previously set components. Calling
// the Create function resets the AudioProcessingBuilderForTesting to its // the Create function resets the AudioProcessingBuilderForTesting to its
// initial state. // initial state.
AudioProcessing* Create(); rtc::scoped_refptr<AudioProcessing> Create();
AudioProcessing* Create(const webrtc::Config& config); rtc::scoped_refptr<AudioProcessing> Create(const webrtc::Config& config);
private: private:
// Transfers the ownership to a non-testing builder. // Transfers the ownership to a non-testing builder.

View File

@ -185,7 +185,7 @@ void DebugDumpReplayer::MaybeRecreateApm(const audioproc::Config& msg) {
// We only create APM once, since changes on these fields should not // We only create APM once, since changes on these fields should not
// happen in current implementation. // happen in current implementation.
if (!apm_.get()) { if (!apm_.get()) {
apm_.reset(AudioProcessingBuilderForTesting().Create(config)); apm_ = AudioProcessingBuilderForTesting().Create(config);
} }
} }

View File

@ -60,7 +60,7 @@ class DebugDumpReplayer {
std::unique_ptr<ChannelBuffer<float>> reverse_; std::unique_ptr<ChannelBuffer<float>> reverse_;
std::unique_ptr<ChannelBuffer<float>> output_; std::unique_ptr<ChannelBuffer<float>> output_;
std::unique_ptr<AudioProcessing> apm_; rtc::scoped_refptr<AudioProcessing> apm_;
FILE* debug_file_; FILE* debug_file_;

View File

@ -112,7 +112,7 @@ class DebugDumpGenerator {
bool enable_pre_amplifier_; bool enable_pre_amplifier_;
TaskQueueForTest worker_queue_; TaskQueueForTest worker_queue_;
std::unique_ptr<AudioProcessing> apm_; rtc::scoped_refptr<AudioProcessing> apm_;
const std::string dump_file_name_; const std::string dump_file_name_;
}; };
@ -143,7 +143,7 @@ DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
worker_queue_("debug_dump_generator_worker_queue"), worker_queue_("debug_dump_generator_worker_queue"),
dump_file_name_(dump_file_name) { dump_file_name_(dump_file_name) {
AudioProcessingBuilderForTesting apm_builder; AudioProcessingBuilderForTesting apm_builder;
apm_.reset(apm_builder.Create(config)); apm_ = apm_builder.Create(config);
} }
DebugDumpGenerator::DebugDumpGenerator( DebugDumpGenerator::DebugDumpGenerator(

View File

@ -34,9 +34,9 @@ const std::string kFieldTrialNames[] = {
"WebRTC-Aec3ShortHeadroomKillSwitch", "WebRTC-Aec3ShortHeadroomKillSwitch",
}; };
std::unique_ptr<AudioProcessing> CreateApm(test::FuzzDataHelper* fuzz_data, rtc::scoped_refptr<AudioProcessing> CreateApm(test::FuzzDataHelper* fuzz_data,
std::string* field_trial_string, std::string* field_trial_string,
rtc::TaskQueue* worker_queue) { rtc::TaskQueue* worker_queue) {
// Parse boolean values for optionally enabling different // Parse boolean values for optionally enabling different
// configurable public components of APM. // configurable public components of APM.
bool exp_agc = fuzz_data->ReadOrDefaultValue(true); bool exp_agc = fuzz_data->ReadOrDefaultValue(true);
@ -108,10 +108,10 @@ std::unique_ptr<AudioProcessing> CreateApm(test::FuzzDataHelper* fuzz_data,
config.Set<ExperimentalAgc>(new ExperimentalAgc(exp_agc)); config.Set<ExperimentalAgc>(new ExperimentalAgc(exp_agc));
config.Set<ExperimentalNs>(new ExperimentalNs(exp_ns)); config.Set<ExperimentalNs>(new ExperimentalNs(exp_ns));
std::unique_ptr<AudioProcessing> apm( rtc::scoped_refptr<AudioProcessing> apm =
AudioProcessingBuilderForTesting() AudioProcessingBuilderForTesting()
.SetEchoControlFactory(std::move(echo_control_factory)) .SetEchoControlFactory(std::move(echo_control_factory))
.Create(config)); .Create(config);
#ifdef WEBRTC_LINUX #ifdef WEBRTC_LINUX
apm->AttachAecDump(AecDumpFactory::Create("/dev/null", -1, worker_queue)); apm->AttachAecDump(AecDumpFactory::Create("/dev/null", -1, worker_queue));

View File

@ -70,7 +70,7 @@ void GenerateFixedFrame(test::FuzzDataHelper* fuzz_data,
} // namespace } // namespace
void FuzzAudioProcessing(test::FuzzDataHelper* fuzz_data, void FuzzAudioProcessing(test::FuzzDataHelper* fuzz_data,
std::unique_ptr<AudioProcessing> apm) { rtc::scoped_refptr<AudioProcessing> apm) {
AudioFrame fixed_frame; AudioFrame fixed_frame;
// Normal usage is up to 8 channels. Allowing to fuzz one beyond this allows // Normal usage is up to 8 channels. Allowing to fuzz one beyond this allows
// us to catch implicit assumptions about normal usage. // us to catch implicit assumptions about normal usage.

View File

@ -18,7 +18,7 @@
namespace webrtc { namespace webrtc {
void FuzzAudioProcessing(test::FuzzDataHelper* fuzz_data, void FuzzAudioProcessing(test::FuzzDataHelper* fuzz_data,
std::unique_ptr<AudioProcessing> apm); rtc::scoped_refptr<AudioProcessing> apm);
} // namespace webrtc } // namespace webrtc