diff --git a/modules/audio_processing/audio_processing_builder_impl.cc b/modules/audio_processing/audio_processing_builder_impl.cc index 40be2a511d..79c6fbf524 100644 --- a/modules/audio_processing/audio_processing_builder_impl.cc +++ b/modules/audio_processing/audio_processing_builder_impl.cc @@ -26,9 +26,9 @@ rtc::scoped_refptr AudioProcessingBuilder::Create() { return nullptr; #else // WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE return rtc::make_ref_counted( - std::move(capture_post_processing_), std::move(render_pre_processing_), - std::move(echo_control_factory_), std::move(echo_detector_), - std::move(capture_analyzer_)); + config_, std::move(capture_post_processing_), + std::move(render_pre_processing_), std::move(echo_control_factory_), + std::move(echo_detector_), std::move(capture_analyzer_)); #endif } diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index d7fbfb6569..318314b674 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -235,7 +235,8 @@ bool AudioProcessingImpl::SubmoduleStates::HighPassFilteringRequired() const { } AudioProcessingImpl::AudioProcessingImpl() - : AudioProcessingImpl(/*capture_post_processor=*/nullptr, + : AudioProcessingImpl(/*config=*/{}, + /*capture_post_processor=*/nullptr, /*render_pre_processor=*/nullptr, /*echo_control_factory=*/nullptr, /*echo_detector=*/nullptr, @@ -244,6 +245,7 @@ AudioProcessingImpl::AudioProcessingImpl() int AudioProcessingImpl::instance_count_ = 0; AudioProcessingImpl::AudioProcessingImpl( + const AudioProcessing::Config& config, std::unique_ptr capture_post_processor, std::unique_ptr render_pre_processor, std::unique_ptr echo_control_factory, @@ -260,6 +262,7 @@ AudioProcessingImpl::AudioProcessingImpl( capture_runtime_settings_enqueuer_(&capture_runtime_settings_), render_runtime_settings_enqueuer_(&render_runtime_settings_), echo_control_factory_(std::move(echo_control_factory)), + config_(config), submodule_states_(!!capture_post_processor, !!render_pre_processor, !!capture_analyzer), diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h index 7c54173658..026152b576 100644 --- a/modules/audio_processing/audio_processing_impl.h +++ b/modules/audio_processing/audio_processing_impl.h @@ -56,8 +56,8 @@ class AudioProcessingImpl : public AudioProcessing { // Methods forcing APM to run in a single-threaded manner. // Acquires both the render and capture locks. AudioProcessingImpl(); - // AudioProcessingImpl takes ownership of capture post processor. - AudioProcessingImpl(std::unique_ptr capture_post_processor, + AudioProcessingImpl(const AudioProcessing::Config& config, + std::unique_ptr capture_post_processor, std::unique_ptr render_pre_processor, std::unique_ptr echo_control_factory, rtc::scoped_refptr echo_detector, diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index 590540132f..8f64274bbc 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -743,48 +743,64 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { class RTC_EXPORT AudioProcessingBuilder { public: AudioProcessingBuilder(); + AudioProcessingBuilder(const AudioProcessingBuilder&) = delete; + AudioProcessingBuilder& operator=(const AudioProcessingBuilder&) = delete; ~AudioProcessingBuilder(); - // The AudioProcessingBuilder takes ownership of the echo_control_factory. + + // Sets the APM configuration. + AudioProcessingBuilder& SetConfig(const AudioProcessing::Config& config) { + config_ = config; + return *this; + } + + // Sets the echo controller factory to inject when APM is created. AudioProcessingBuilder& SetEchoControlFactory( std::unique_ptr echo_control_factory) { echo_control_factory_ = std::move(echo_control_factory); return *this; } - // The AudioProcessingBuilder takes ownership of the capture_post_processing. + + // Sets the capture post-processing sub-module to inject when APM is created. AudioProcessingBuilder& SetCapturePostProcessing( std::unique_ptr capture_post_processing) { capture_post_processing_ = std::move(capture_post_processing); return *this; } - // The AudioProcessingBuilder takes ownership of the render_pre_processing. + + // Sets the render pre-processing sub-module to inject when APM is created. AudioProcessingBuilder& SetRenderPreProcessing( std::unique_ptr render_pre_processing) { render_pre_processing_ = std::move(render_pre_processing); return *this; } - // The AudioProcessingBuilder takes ownership of the echo_detector. + + // Sets the echo detector to inject when APM is created. AudioProcessingBuilder& SetEchoDetector( rtc::scoped_refptr echo_detector) { echo_detector_ = std::move(echo_detector); return *this; } - // The AudioProcessingBuilder takes ownership of the capture_analyzer. + + // Sets the capture analyzer sub-module to inject when APM is created. AudioProcessingBuilder& SetCaptureAnalyzer( std::unique_ptr capture_analyzer) { capture_analyzer_ = std::move(capture_analyzer); return *this; } - // This creates an APM instance using the previously set components. Calling - // the Create function resets the AudioProcessingBuilder to its initial state. + + // 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 Create(); private: + AudioProcessing::Config config_; std::unique_ptr echo_control_factory_; std::unique_ptr capture_post_processing_; std::unique_ptr render_pre_processing_; rtc::scoped_refptr echo_detector_; std::unique_ptr capture_analyzer_; - RTC_DISALLOW_COPY_AND_ASSIGN(AudioProcessingBuilder); }; class StreamConfig {