Exposing audio and video engines directly.

The audio and video engine is exposed directly rather via redundant
wrapping functions. This reduces the amount of boiler plate code.

Bug: webrtc:9883
Change-Id: I203a945ee6079397e24a378966a569cd5626ac4a
Reviewed-on: https://webrtc-review.googlesource.com/c/106683
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25673}
diff --git a/media/base/mediaengine.cc b/media/base/mediaengine.cc
index 94ebcad..d5198fe 100644
--- a/media/base/mediaengine.cc
+++ b/media/base/mediaengine.cc
@@ -119,56 +119,6 @@
   return true;
 }
 
-rtc::scoped_refptr<webrtc::AudioState> CompositeMediaEngine::GetAudioState()
-    const {
-  return voice().GetAudioState();
-}
-
-VoiceMediaChannel* CompositeMediaEngine::CreateChannel(
-    webrtc::Call* call,
-    const MediaConfig& config,
-    const AudioOptions& options,
-    const webrtc::CryptoOptions& crypto_options) {
-  return voice().CreateMediaChannel(call, config, options, crypto_options);
-}
-
-VideoMediaChannel* CompositeMediaEngine::CreateVideoChannel(
-    webrtc::Call* call,
-    const MediaConfig& config,
-    const VideoOptions& options,
-    const webrtc::CryptoOptions& crypto_options) {
-  return video().CreateMediaChannel(call, config, options, crypto_options);
-}
-
-const std::vector<AudioCodec>& CompositeMediaEngine::audio_send_codecs() {
-  return voice().send_codecs();
-}
-
-const std::vector<AudioCodec>& CompositeMediaEngine::audio_recv_codecs() {
-  return voice().recv_codecs();
-}
-
-RtpCapabilities CompositeMediaEngine::GetAudioCapabilities() {
-  return voice().GetCapabilities();
-}
-
-std::vector<VideoCodec> CompositeMediaEngine::video_codecs() {
-  return video().codecs();
-}
-
-RtpCapabilities CompositeMediaEngine::GetVideoCapabilities() {
-  return video().GetCapabilities();
-}
-
-bool CompositeMediaEngine::StartAecDump(rtc::PlatformFile file,
-                                        int64_t max_size_bytes) {
-  return voice().StartAecDump(file, max_size_bytes);
-}
-
-void CompositeMediaEngine::StopAecDump() {
-  voice().StopAecDump();
-}
-
 VoiceEngineInterface& CompositeMediaEngine::voice() {
   return *voice_engine_.get();
 }
diff --git a/media/base/mediaengine.h b/media/base/mediaengine.h
index 1ddb36c..01300d4 100644
--- a/media/base/mediaengine.h
+++ b/media/base/mediaengine.h
@@ -111,37 +111,10 @@
   // Initialization
   // Starts the engine.
   virtual bool Init() = 0;
-  // TODO(solenberg): Remove once VoE API refactoring is done.
-  virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
-
-  // MediaChannel creation
-  // Creates a voice media channel. Returns NULL on failure.
-  virtual VoiceMediaChannel* CreateChannel(
-      webrtc::Call* call,
-      const MediaConfig& config,
-      const AudioOptions& options,
-      const webrtc::CryptoOptions& crypto_options) = 0;
-  // Creates a video media channel, paired with the specified voice channel.
-  // Returns NULL on failure.
-  virtual VideoMediaChannel* CreateVideoChannel(
-      webrtc::Call* call,
-      const MediaConfig& config,
-      const VideoOptions& options,
-      const webrtc::CryptoOptions& crypto_options) = 0;
-
-  virtual const std::vector<AudioCodec>& audio_send_codecs() = 0;
-  virtual const std::vector<AudioCodec>& audio_recv_codecs() = 0;
-  virtual RtpCapabilities GetAudioCapabilities() = 0;
-  virtual std::vector<VideoCodec> video_codecs() = 0;
-  virtual RtpCapabilities GetVideoCapabilities() = 0;
-
-  // Starts AEC dump using existing file, a maximum file size in bytes can be
-  // specified. Logging is stopped just before the size limit is exceeded.
-  // If max_size_bytes is set to a value <= 0, no limit will be used.
-  virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
-
-  // Stops recording AEC dump.
-  virtual void StopAecDump() = 0;
+  virtual VoiceEngineInterface& voice() = 0;
+  virtual VideoEngineInterface& video() = 0;
+  virtual const VoiceEngineInterface& voice() const = 0;
+  virtual const VideoEngineInterface& video() const = 0;
 };
 
 // CompositeMediaEngine constructs a MediaEngine from separate
@@ -153,34 +126,10 @@
   ~CompositeMediaEngine() override;
   bool Init() override;
 
-  rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const override;
-  VoiceMediaChannel* CreateChannel(
-      webrtc::Call* call,
-      const MediaConfig& config,
-      const AudioOptions& options,
-      const webrtc::CryptoOptions& crypto_options) override;
-
-  VideoMediaChannel* CreateVideoChannel(
-      webrtc::Call* call,
-      const MediaConfig& config,
-      const VideoOptions& options,
-      const webrtc::CryptoOptions& crypto_options) override;
-
-  const std::vector<AudioCodec>& audio_send_codecs() override;
-  const std::vector<AudioCodec>& audio_recv_codecs() override;
-  RtpCapabilities GetAudioCapabilities() override;
-
-  std::vector<VideoCodec> video_codecs() override;
-  RtpCapabilities GetVideoCapabilities() override;
-
-  bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
-  void StopAecDump() override;
-
- protected:
-  VoiceEngineInterface& voice();
-  VideoEngineInterface& video();
-  const VoiceEngineInterface& voice() const;
-  const VideoEngineInterface& video() const;
+  VoiceEngineInterface& voice() override;
+  VideoEngineInterface& video() override;
+  const VoiceEngineInterface& voice() const override;
+  const VideoEngineInterface& video() const override;
 
  private:
   std::unique_ptr<VoiceEngineInterface> voice_engine_;
diff --git a/pc/channelmanager.cc b/pc/channelmanager.cc
index 31920d9..eda5a2d 100644
--- a/pc/channelmanager.cc
+++ b/pc/channelmanager.cc
@@ -66,7 +66,7 @@
   if (!media_engine_) {
     return;
   }
-  *codecs = media_engine_->audio_send_codecs();
+  *codecs = media_engine_->voice().send_codecs();
 }
 
 void ChannelManager::GetSupportedAudioReceiveCodecs(
@@ -74,7 +74,7 @@
   if (!media_engine_) {
     return;
   }
-  *codecs = media_engine_->audio_recv_codecs();
+  *codecs = media_engine_->voice().recv_codecs();
 }
 
 void ChannelManager::GetSupportedAudioRtpHeaderExtensions(
@@ -82,7 +82,7 @@
   if (!media_engine_) {
     return;
   }
-  *ext = media_engine_->GetAudioCapabilities().header_extensions;
+  *ext = media_engine_->voice().GetCapabilities().header_extensions;
 }
 
 void ChannelManager::GetSupportedVideoCodecs(
@@ -92,7 +92,7 @@
   }
   codecs->clear();
 
-  std::vector<VideoCodec> video_codecs = media_engine_->video_codecs();
+  std::vector<VideoCodec> video_codecs = media_engine_->video().codecs();
   for (const auto& video_codec : video_codecs) {
     if (!enable_rtx_ &&
         absl::EqualsIgnoreCase(kRtxCodecName, video_codec.name)) {
@@ -107,7 +107,7 @@
   if (!media_engine_) {
     return;
   }
-  *ext = media_engine_->GetVideoCapabilities().header_extensions;
+  *ext = media_engine_->video().GetCapabilities().header_extensions;
 }
 
 void ChannelManager::GetSupportedDataCodecs(
@@ -177,8 +177,8 @@
     return nullptr;
   }
 
-  VoiceMediaChannel* media_channel =
-      media_engine_->CreateChannel(call, media_config, options, crypto_options);
+  VoiceMediaChannel* media_channel = media_engine_->voice().CreateMediaChannel(
+      call, media_config, options, crypto_options);
   if (!media_channel) {
     return nullptr;
   }
@@ -244,7 +244,7 @@
     return nullptr;
   }
 
-  VideoMediaChannel* media_channel = media_engine_->CreateVideoChannel(
+  VideoMediaChannel* media_channel = media_engine_->video().CreateMediaChannel(
       call, media_config, options, crypto_options);
   if (!media_channel) {
     return nullptr;
@@ -349,13 +349,13 @@
 bool ChannelManager::StartAecDump(rtc::PlatformFile file,
                                   int64_t max_size_bytes) {
   return worker_thread_->Invoke<bool>(RTC_FROM_HERE, [&] {
-    return media_engine_->StartAecDump(file, max_size_bytes);
+    return media_engine_->voice().StartAecDump(file, max_size_bytes);
   });
 }
 
 void ChannelManager::StopAecDump() {
   worker_thread_->Invoke<void>(RTC_FROM_HERE,
-                               [&] { media_engine_->StopAecDump(); });
+                               [&] { media_engine_->voice().StopAecDump(); });
 }
 
 }  // namespace cricket
diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc
index 982e522..3b9b9c8 100644
--- a/pc/peerconnection.cc
+++ b/pc/peerconnection.cc
@@ -1717,7 +1717,7 @@
         break;
     }
   }
-  // If there is no |internal_sender| then |selector| is either null or does not
+  // If there is no |internal_sender| then |selector| is either null or does not
   // belong to the PeerConnection (in Plan B, senders can be removed from the
   // PeerConnection). This means that "all the stats objects representing the
   // selector" is an empty set. Invoking GetStatsReport() with a null selector
@@ -1745,7 +1745,7 @@
         break;
     }
   }
-  // If there is no |internal_receiver| then |selector| is either null or does
+  // If there is no |internal_receiver| then |selector| is either null or does
   // not belong to the PeerConnection (in Plan B, receivers can be removed from
   // the PeerConnection). This means that "all the stats objects representing
   // the selector" is an empty set. Invoking GetStatsReport() with a null
@@ -3254,7 +3254,7 @@
     return;
   }
   auto audio_state =
-      factory_->channel_manager()->media_engine()->GetAudioState();
+      factory_->channel_manager()->media_engine()->voice().GetAudioState();
   audio_state->SetPlayout(playout);
 }
 
@@ -3266,7 +3266,7 @@
     return;
   }
   auto audio_state =
-      factory_->channel_manager()->media_engine()->GetAudioState();
+      factory_->channel_manager()->media_engine()->voice().GetAudioState();
   audio_state->SetRecording(recording);
 }
 
diff --git a/pc/peerconnection_media_unittest.cc b/pc/peerconnection_media_unittest.cc
index dd39141..6af0c98 100644
--- a/pc/peerconnection_media_unittest.cc
+++ b/pc/peerconnection_media_unittest.cc
@@ -704,7 +704,7 @@
   const cricket::AudioCodec kComfortNoiseCodec8k(102, "CN", 8000, 0, 1);
   const cricket::AudioCodec kComfortNoiseCodec16k(103, "CN", 16000, 0, 1);
 
-  auto codecs = media_engine->audio_send_codecs();
+  auto codecs = media_engine->voice().send_codecs();
   codecs.push_back(kComfortNoiseCodec8k);
   codecs.push_back(kComfortNoiseCodec16k);
   media_engine->SetAudioCodecs(codecs);
diff --git a/pc/peerconnectionfactory.cc b/pc/peerconnectionfactory.cc
index e039d4c..37c6a0b 100644
--- a/pc/peerconnectionfactory.cc
+++ b/pc/peerconnectionfactory.cc
@@ -470,7 +470,8 @@
   if (!channel_manager_->media_engine() || !call_factory_) {
     return nullptr;
   }
-  call_config.audio_state = channel_manager_->media_engine()->GetAudioState();
+  call_config.audio_state =
+      channel_manager_->media_engine()->voice().GetAudioState();
   call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
   call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
   call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;