1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" 12 13 #include <memory> 14 #include <utility> 15 16 #include "modules/audio_processing/audio_processing_impl.h" 17 #include "rtc_base/ref_counted_object.h" 18 19 namespace webrtc { 20 21 AudioProcessingBuilderForTesting::AudioProcessingBuilderForTesting() = default; 22 AudioProcessingBuilderForTesting::~AudioProcessingBuilderForTesting() = default; 23 24 #ifdef WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE 25 Create()26AudioProcessing* AudioProcessingBuilderForTesting::Create() { 27 webrtc::Config config; 28 return Create(config); 29 } 30 Create(const webrtc::Config & config)31AudioProcessing* AudioProcessingBuilderForTesting::Create( 32 const webrtc::Config& config) { 33 AudioProcessingImpl* apm = new rtc::RefCountedObject<AudioProcessingImpl>( 34 config, std::move(capture_post_processing_), 35 std::move(render_pre_processing_), std::move(echo_control_factory_), 36 std::move(echo_detector_), std::move(capture_analyzer_)); 37 int error = apm->Initialize(); 38 RTC_CHECK_EQ(error, AudioProcessing::kNoError); 39 return apm; 40 } 41 42 #else 43 Create()44AudioProcessing* AudioProcessingBuilderForTesting::Create() { 45 AudioProcessingBuilder builder; 46 TransferOwnershipsToBuilder(&builder); 47 return builder.Create(); 48 } 49 Create(const webrtc::Config & config)50AudioProcessing* AudioProcessingBuilderForTesting::Create( 51 const webrtc::Config& config) { 52 AudioProcessingBuilder builder; 53 TransferOwnershipsToBuilder(&builder); 54 return builder.Create(config); 55 } 56 57 #endif 58 TransferOwnershipsToBuilder(AudioProcessingBuilder * builder)59void AudioProcessingBuilderForTesting::TransferOwnershipsToBuilder( 60 AudioProcessingBuilder* builder) { 61 builder->SetCapturePostProcessing(std::move(capture_post_processing_)); 62 builder->SetRenderPreProcessing(std::move(render_pre_processing_)); 63 builder->SetCaptureAnalyzer(std::move(capture_analyzer_)); 64 builder->SetEchoControlFactory(std::move(echo_control_factory_)); 65 builder->SetEchoDetector(std::move(echo_detector_)); 66 } 67 68 } // namespace webrtc 69