APM fuzzer: add SetConfig() to test builder

Also stop using ApplyConfig() and in [1] fix the build errors when
WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE is defined.

[1] modules/audio_processing/test/audio_processing_builder_for_testing.cc

Bug: webrtc:5298
Change-Id: I50dc5668b952e7ca7fa83c7a5182c013e928c450
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235365
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35228}
diff --git a/modules/audio_processing/test/audio_processing_builder_for_testing.cc b/modules/audio_processing/test/audio_processing_builder_for_testing.cc
index adf0c5d..72f75ed 100644
--- a/modules/audio_processing/test/audio_processing_builder_for_testing.cc
+++ b/modules/audio_processing/test/audio_processing_builder_for_testing.cc
@@ -25,9 +25,9 @@
 
 rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
   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_));
 }
 
 #else
@@ -35,7 +35,7 @@
 rtc::scoped_refptr<AudioProcessing> AudioProcessingBuilderForTesting::Create() {
   AudioProcessingBuilder builder;
   TransferOwnershipsToBuilder(&builder);
-  return builder.Create();
+  return builder.SetConfig(config_).Create();
 }
 
 #endif
@@ -44,9 +44,9 @@
     AudioProcessingBuilder* builder) {
   builder->SetCapturePostProcessing(std::move(capture_post_processing_));
   builder->SetRenderPreProcessing(std::move(render_pre_processing_));
-  builder->SetCaptureAnalyzer(std::move(capture_analyzer_));
   builder->SetEchoControlFactory(std::move(echo_control_factory_));
   builder->SetEchoDetector(std::move(echo_detector_));
+  builder->SetCaptureAnalyzer(std::move(capture_analyzer_));
 }
 
 }  // namespace webrtc
diff --git a/modules/audio_processing/test/audio_processing_builder_for_testing.h b/modules/audio_processing/test/audio_processing_builder_for_testing.h
index 2d21248..e73706c 100644
--- a/modules/audio_processing/test/audio_processing_builder_for_testing.h
+++ b/modules/audio_processing/test/audio_processing_builder_for_testing.h
@@ -24,50 +24,65 @@
 class AudioProcessingBuilderForTesting {
  public:
   AudioProcessingBuilderForTesting();
+  AudioProcessingBuilderForTesting(const AudioProcessingBuilderForTesting&) =
+      delete;
+  AudioProcessingBuilderForTesting& operator=(
+      const AudioProcessingBuilderForTesting&) = delete;
   ~AudioProcessingBuilderForTesting();
-  // The AudioProcessingBuilderForTesting takes ownership of the
-  // echo_control_factory.
+
+  // 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;
   }
-  // The AudioProcessingBuilderForTesting takes ownership of the
-  // capture_post_processing.
+
+  // 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;
   }
-  // The AudioProcessingBuilderForTesting takes ownership of the
-  // render_pre_processing.
+
+  // 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;
   }
-  // The AudioProcessingBuilderForTesting takes ownership of the echo_detector.
+
+  // 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;
   }
-  // The AudioProcessingBuilderForTesting takes ownership of the
-  // capture_analyzer.
+
+  // 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;
   }
-  // This creates an APM instance using the previously set components. Calling
-  // the Create function resets the AudioProcessingBuilderForTesting 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:
   // 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_;
diff --git a/test/fuzzers/audio_processing_configs_fuzzer.cc b/test/fuzzers/audio_processing_configs_fuzzer.cc
index 9bed5c1..996a4a0 100644
--- a/test/fuzzers/audio_processing_configs_fuzzer.cc
+++ b/test/fuzzers/audio_processing_configs_fuzzer.cc
@@ -99,15 +99,6 @@
     echo_control_factory.reset(new EchoCanceller3Factory());
   }
 
-  rtc::scoped_refptr<AudioProcessing> apm =
-      AudioProcessingBuilderForTesting()
-          .SetEchoControlFactory(std::move(echo_control_factory))
-          .Create();
-
-#ifdef WEBRTC_LINUX
-  apm->AttachAecDump(AecDumpFactory::Create("/dev/null", -1, worker_queue));
-#endif
-
   webrtc::AudioProcessing::Config apm_config;
   apm_config.pipeline.multi_channel_render = true;
   apm_config.pipeline.multi_channel_capture = true;
@@ -125,7 +116,16 @@
   apm_config.transient_suppression.enabled = use_ts;
   apm_config.voice_detection.enabled = use_vad;
   apm_config.level_estimation.enabled = use_le;
-  apm->ApplyConfig(apm_config);
+
+  rtc::scoped_refptr<AudioProcessing> apm =
+      AudioProcessingBuilderForTesting()
+          .SetEchoControlFactory(std::move(echo_control_factory))
+          .SetConfig(apm_config)
+          .Create();
+
+#ifdef WEBRTC_LINUX
+  apm->AttachAecDump(AecDumpFactory::Create("/dev/null", -1, worker_queue));
+#endif
 
   return apm;
 }