APM: add `AudioProcessingBuilder::SetConfig()`

Bug: webrtc:5298
Change-Id: If3468ebb841c49dcd410a8bea2f9f8111ee8bc06
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/234842
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35199}
diff --git a/modules/audio_processing/audio_processing_builder_impl.cc b/modules/audio_processing/audio_processing_builder_impl.cc
index 40be2a5..79c6fbf 100644
--- a/modules/audio_processing/audio_processing_builder_impl.cc
+++ b/modules/audio_processing/audio_processing_builder_impl.cc
@@ -26,9 +26,9 @@
   return nullptr;
 #else  // WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE
   return rtc::make_ref_counted<AudioProcessingImpl>(
-      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 d7fbfb6..318314b 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -235,7 +235,8 @@
 }
 
 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 @@
 int AudioProcessingImpl::instance_count_ = 0;
 
 AudioProcessingImpl::AudioProcessingImpl(
+    const AudioProcessing::Config& config,
     std::unique_ptr<CustomProcessing> capture_post_processor,
     std::unique_ptr<CustomProcessing> render_pre_processor,
     std::unique_ptr<EchoControlFactory> echo_control_factory,
@@ -260,6 +262,7 @@
       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 7c54173..026152b 100644
--- a/modules/audio_processing/audio_processing_impl.h
+++ b/modules/audio_processing/audio_processing_impl.h
@@ -56,8 +56,8 @@
   // 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<CustomProcessing> capture_post_processor,
+  AudioProcessingImpl(const AudioProcessing::Config& config,
+                      std::unique_ptr<CustomProcessing> capture_post_processor,
                       std::unique_ptr<CustomProcessing> render_pre_processor,
                       std::unique_ptr<EchoControlFactory> echo_control_factory,
                       rtc::scoped_refptr<EchoDetector> echo_detector,
diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h
index 5905401..8f64274 100644
--- a/modules/audio_processing/include/audio_processing.h
+++ b/modules/audio_processing/include/audio_processing.h
@@ -743,48 +743,64 @@
 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<EchoControlFactory> 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<CustomProcessing> 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<CustomProcessing> 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<EchoDetector> 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<CustomAudioAnalyzer> 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<AudioProcessing> Create();
 
  private:
+  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_;
-  RTC_DISALLOW_COPY_AND_ASSIGN(AudioProcessingBuilder);
 };
 
 class StreamConfig {