Stop using deprecated audio processing module ptr-to-submodule API

This CL does not change any functionality.

Bug: webrtc:9878
Change-Id: I55309aea7db79d0c42d075b852bdb6b33b1d059d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1619812
Reviewed-by: Max Morin <maxmorin@chromium.org>
Commit-Queue: Sam Zackrisson <saza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662110}
diff --git a/content/renderer/media/stream/media_stream_audio_processor.cc b/content/renderer/media/stream/media_stream_audio_processor.cc
index d2a130b..4aa075d 100644
--- a/content/renderer/media/stream/media_stream_audio_processor.cc
+++ b/content/renderer/media/stream/media_stream_audio_processor.cc
@@ -768,19 +768,13 @@
   ap->set_stream_delay_ms(total_delay_ms);
 
   DCHECK_LE(volume, WebRtcAudioDeviceImpl::kMaxVolumeLevel);
-  webrtc::GainControl* agc = ap->gain_control();
-  int err = agc->set_stream_analog_level(volume);
-  DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err;
-
+  ap->set_stream_analog_level(volume);
   ap->set_stream_key_pressed(key_pressed);
 
-  err = ap->ProcessStream(process_ptrs,
-                          process_frames,
-                          input_format_.sample_rate(),
-                          MapLayout(input_format_.channel_layout()),
-                          output_format_.sample_rate(),
-                          MapLayout(output_format_.channel_layout()),
-                          output_ptrs);
+  int err = ap->ProcessStream(
+      process_ptrs, process_frames, input_format_.sample_rate(),
+      MapLayout(input_format_.channel_layout()), output_format_.sample_rate(),
+      MapLayout(output_format_.channel_layout()), output_ptrs);
   DCHECK_EQ(err, 0) << "ProcessStream() error: " << err;
 
   if (typing_detector_) {
@@ -799,8 +793,8 @@
                      rtc::scoped_refptr<MediaStreamAudioProcessor>(this)));
 
   // Return 0 if the volume hasn't been changed, and otherwise the new volume.
-  return (agc->stream_analog_level() == volume) ?
-      0 : agc->stream_analog_level();
+  const int recommended_volume = ap->recommended_stream_analog_level();
+  return (recommended_volume == volume) ? 0 : recommended_volume;
 }
 
 void MediaStreamAudioProcessor::UpdateAecStats() {
diff --git a/content/renderer/media/stream/media_stream_audio_processor_unittest.cc b/content/renderer/media/stream/media_stream_audio_processor_unittest.cc
index 5e5d9b7..cbc1034 100644
--- a/content/renderer/media/stream/media_stream_audio_processor_unittest.cc
+++ b/content/renderer/media/stream/media_stream_audio_processor_unittest.cc
@@ -157,25 +157,20 @@
     const webrtc::AudioProcessing::Config config =
         audio_processing->GetConfig();
     EXPECT_TRUE(config.echo_canceller.enabled);
+    EXPECT_TRUE(config.gain_controller1.enabled);
+    EXPECT_TRUE(config.high_pass_filter.enabled);
+    EXPECT_TRUE(config.noise_suppression.enabled);
+    EXPECT_EQ(config.noise_suppression.level, config.noise_suppression.kHigh);
 #if defined(OS_ANDROID)
     EXPECT_TRUE(config.echo_canceller.mobile_mode);
     EXPECT_FALSE(config.voice_detection.enabled);
+    EXPECT_EQ(config.gain_controller1.mode,
+              config.gain_controller1.kFixedDigital);
 #else
     EXPECT_FALSE(config.echo_canceller.mobile_mode);
     EXPECT_TRUE(config.voice_detection.enabled);
-#endif
-    EXPECT_TRUE(config.high_pass_filter.enabled);
-
-    EXPECT_TRUE(audio_processing->noise_suppression()->is_enabled());
-    EXPECT_TRUE(audio_processing->noise_suppression()->level() ==
-        webrtc::NoiseSuppression::kHigh);
-    EXPECT_TRUE(audio_processing->gain_control()->is_enabled());
-#if defined(OS_ANDROID)
-    EXPECT_TRUE(audio_processing->gain_control()->mode() ==
-        webrtc::GainControl::kFixedDigital);
-#else
-    EXPECT_TRUE(audio_processing->gain_control()->mode() ==
-        webrtc::GainControl::kAdaptiveAnalog);
+    EXPECT_EQ(config.gain_controller1.mode,
+              config.gain_controller1.kAdaptiveAnalog);
 #endif
   }
 
diff --git a/media/webrtc/audio_processor.cc b/media/webrtc/audio_processor.cc
index fb90511..cb5f43f 100644
--- a/media/webrtc/audio_processor.cc
+++ b/media/webrtc/audio_processor.cc
@@ -240,22 +240,6 @@
   // Audio processing module construction.
   audio_processing_ = base::WrapUnique(ap_builder.Create(ap_config));
 
-  // Noise suppression setup part 2.
-  if (settings_.noise_suppression != NoiseSuppressionType::kDisabled) {
-    int err = audio_processing_->noise_suppression()->set_level(
-        webrtc::NoiseSuppression::kHigh);
-    err |= audio_processing_->noise_suppression()->Enable(true);
-    DCHECK_EQ(err, 0);
-  }
-
-  // AGC setup part 2.
-  if (settings_.automatic_gain_control != AutomaticGainControlType::kDisabled) {
-    int err = audio_processing_->gain_control()->set_mode(
-        webrtc::GainControl::kAdaptiveAnalog);
-    err |= audio_processing_->gain_control()->Enable(true);
-    DCHECK_EQ(err, 0);
-  }
-
   webrtc::AudioProcessing::Config apm_config = audio_processing_->GetConfig();
 
   // Typing detection setup.
@@ -275,7 +259,17 @@
   // High-pass filter setup.
   apm_config.high_pass_filter.enabled = settings_.high_pass_filter;
 
-  // AGC setup part 3.
+  // Noise suppression setup part 2.
+  apm_config.noise_suppression.enabled =
+      settings_.noise_suppression != NoiseSuppressionType::kDisabled;
+  apm_config.noise_suppression.level =
+      webrtc::AudioProcessing::Config::NoiseSuppression::kHigh;
+
+  // AGC setup part 2.
+  apm_config.gain_controller1.enabled =
+      settings_.automatic_gain_control != AutomaticGainControlType::kDisabled;
+  apm_config.gain_controller1.mode =
+      webrtc::AudioProcessing::Config::GainController1::kAdaptiveAnalog;
   if (settings_.automatic_gain_control ==
           AutomaticGainControlType::kExperimental ||
       settings_.automatic_gain_control ==
@@ -324,9 +318,7 @@
   DCHECK_LE(volume, 1.0);
   constexpr double kWebRtcMaxVolume = 255;
   const int webrtc_volume = volume * kWebRtcMaxVolume;
-  int err =
-      audio_processing_->gain_control()->set_stream_analog_level(webrtc_volume);
-  DCHECK_EQ(err, 0) << "set_stream_analog_level() error: " << err;
+  audio_processing_->set_stream_analog_level(webrtc_volume);
 }
 
 void AudioProcessor::FeedDataToAPM(const AudioBus& source) {
@@ -360,7 +352,7 @@
   constexpr double kWebRtcMaxVolume = 255;
   const int webrtc_volume = volume * kWebRtcMaxVolume;
   const int new_webrtc_volume =
-      audio_processing_->gain_control()->stream_analog_level();
+      audio_processing_->recommended_stream_analog_level();
 
   return new_webrtc_volume == webrtc_volume
              ? base::nullopt
diff --git a/media/webrtc/audio_processor_unittest.cc b/media/webrtc/audio_processor_unittest.cc
index acfb1ac..31d5d1e 100644
--- a/media/webrtc/audio_processor_unittest.cc
+++ b/media/webrtc/audio_processor_unittest.cc
@@ -133,14 +133,13 @@
     EXPECT_TRUE(ap_config.echo_canceller.enabled);
     EXPECT_FALSE(ap_config.echo_canceller.mobile_mode);
     EXPECT_TRUE(ap_config.high_pass_filter.enabled);
+    EXPECT_TRUE(ap_config.gain_controller1.enabled);
+    EXPECT_EQ(ap_config.gain_controller1.mode,
+              ap_config.gain_controller1.kAdaptiveAnalog);
+    EXPECT_TRUE(ap_config.noise_suppression.enabled);
+    EXPECT_EQ(ap_config.noise_suppression.level,
+              ap_config.noise_suppression.kHigh);
     EXPECT_TRUE(ap_config.voice_detection.enabled);
-
-    EXPECT_TRUE(audio_processing->noise_suppression()->is_enabled());
-    EXPECT_TRUE(audio_processing->noise_suppression()->level() ==
-                webrtc::NoiseSuppression::kHigh);
-    EXPECT_TRUE(audio_processing->gain_control()->is_enabled());
-    EXPECT_TRUE(audio_processing->gain_control()->mode() ==
-                webrtc::GainControl::kAdaptiveAnalog);
   }
 
   AudioProcessingSettings GetEnabledAudioProcessingSettings() const {