Unify AGC2 experiment field trials into one

In order to experiment with AGC2 and TS at the same time, 3 field
trials are removed and merged into `WebRTC-Audio-GainController2`,
which is existing.

New parameters for the `WebRTC-Audio-GainController2` field trial:
- `switch_to_agc2`: true by default; when true, the gain control
  switches to AGC2 (both for the input volume and for the adaptive
  digital gain);
- `min_input_volume`: minimum input volume enforced by the input
  volume controller when the applied input volume is not zero;
- `disallow_transient_suppressor_usage`: when true, TS is never
  created.

Removed field trials:
- `WebRTC-Audio-Agc2-MinInputVolume`: now a parameter of
  `WebRTC-Audio-GainController2`;
- `WebRTC-ApmTransientSuppressorKillSwitch`: now a parameter of
  `WebRTC-Audio-GainController2`;
- `WebRTC-Audio-TransientSuppressorVadMode`: automatically inferred
  from `WebRTC-Audio-GainController2`.

Bug: webrtc:7494
Change-Id: I452798c0862d71f9adae6d163fe841df05ca44d6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/287861
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Hanna Silen <silen@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38890}
diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h
index 0f74c30..8ee07ed 100644
--- a/modules/audio_processing/audio_processing_impl.h
+++ b/modules/audio_processing/audio_processing_impl.h
@@ -138,14 +138,6 @@
 
   AudioProcessing::Config GetConfig() const override;
 
-  // TODO(bugs.webrtc.org/7494): Remove when the related field trial is
-  // removed.
-  struct GainController2ConfigOverride {
-    InputVolumeController::Config input_volume_controller_config;
-    AudioProcessing::Config::GainController2::AdaptiveDigital
-        adaptive_digital_config;
-  };
-
  protected:
   // Overridden in a mock.
   virtual void InitializeLocked()
@@ -199,19 +191,47 @@
   static std::atomic<int> instance_count_;
   const bool use_setup_specific_default_aec3_config_;
 
-  // TODO(bugs.webrtc.org/7494): Remove when the linked field trial is removed.
-  // Override based on the "WebRTC-Audio-GainController2" field trial for the
-  // AGC2 input volume controller and adaptive digital controller configuration.
-  const absl::optional<GainController2ConfigOverride>
-      gain_controller2_config_override_;
+  // Parameters for the "GainController2" experiment which determines whether
+  // the following APM sub-modules are created and, if so, their configurations:
+  // AGC2 (`gain_controller2`), AGC1 (`gain_control`, `agc_manager`) and TS
+  // (`transient_suppressor`).
+  // TODO(bugs.webrtc.org/7494): Remove when the "WebRTC-Audio-GainController2"
+  // field trial is removed.
+  struct GainController2ExperimentParams {
+    struct Agc2Config {
+      InputVolumeController::Config input_volume_controller;
+      AudioProcessing::Config::GainController2::AdaptiveDigital
+          adaptive_digital_controller;
+    };
+    // When `agc2_config` is specified, all gain control switches to AGC2 and
+    // the configuration is overridden.
+    absl::optional<Agc2Config> agc2_config;
+    // When true, the transient suppressor submodule is never created regardless
+    // of the APM configuration.
+    bool disallow_transient_suppressor_usage;
+  };
+  // Specified when the "WebRTC-Audio-GainController2" field trial is specified.
+  // TODO(bugs.webrtc.org/7494): Remove when the "WebRTC-Audio-GainController2"
+  // field trial is removed.
+  const absl::optional<GainController2ExperimentParams>
+      gain_controller2_experiment_params_;
+
+  // Parses the "WebRTC-Audio-GainController2" field trial. If disabled, returns
+  // an unspecified value.
+  static absl::optional<GainController2ExperimentParams>
+  GetGainController2ExperimentParams();
+
+  // When `experiment_params` is specified, returns an APM configuration
+  // modified according to the experiment parameters. Otherwise returns
+  // `config`.
+  static AudioProcessing::Config AdjustConfig(
+      const AudioProcessing::Config& config,
+      const absl::optional<GainController2ExperimentParams>& experiment_params);
+  static TransientSuppressor::VadMode GetTransientSuppressorVadMode(
+      const absl::optional<GainController2ExperimentParams>& experiment_params);
 
   const bool use_denormal_disabler_;
 
-  // When true, the transient suppressor submodule is never created regardless
-  // of the APM configuration.
-  // TODO(bugs.webrtc.org/13663): Remove when the linked field trial is removed.
-  const bool disallow_transient_supporessor_usage_;
-
   const TransientSuppressor::VadMode transient_suppressor_vad_mode_;
 
   SwapQueue<RuntimeSetting> capture_runtime_settings_;