From 6eb8a16dbf1e679f9c62b261da7beecbdc7a3cdd Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Fri, 16 Nov 2018 11:29:55 +0100 Subject: [PATCH] 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 Reviewed-by: Steve Anton Reviewed-by: Niels Moller Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#25673} --- media/base/mediaengine.cc | 50 --------------------- media/base/mediaengine.h | 67 ++++------------------------- pc/channelmanager.cc | 20 ++++----- pc/peerconnection.cc | 8 ++-- pc/peerconnection_media_unittest.cc | 2 +- pc/peerconnectionfactory.cc | 3 +- 6 files changed, 25 insertions(+), 125 deletions(-) diff --git a/media/base/mediaengine.cc b/media/base/mediaengine.cc index 94ebcad81b..d5198fe64f 100644 --- a/media/base/mediaengine.cc +++ b/media/base/mediaengine.cc @@ -119,56 +119,6 @@ bool CompositeMediaEngine::Init() { return true; } -rtc::scoped_refptr 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& CompositeMediaEngine::audio_send_codecs() { - return voice().send_codecs(); -} - -const std::vector& CompositeMediaEngine::audio_recv_codecs() { - return voice().recv_codecs(); -} - -RtpCapabilities CompositeMediaEngine::GetAudioCapabilities() { - return voice().GetCapabilities(); -} - -std::vector 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 1ddb36c9cd..01300d48ac 100644 --- a/media/base/mediaengine.h +++ b/media/base/mediaengine.h @@ -111,37 +111,10 @@ class MediaEngineInterface { // Initialization // Starts the engine. virtual bool Init() = 0; - // TODO(solenberg): Remove once VoE API refactoring is done. - virtual rtc::scoped_refptr 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& audio_send_codecs() = 0; - virtual const std::vector& audio_recv_codecs() = 0; - virtual RtpCapabilities GetAudioCapabilities() = 0; - virtual std::vector 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 @@ class CompositeMediaEngine : public MediaEngineInterface { ~CompositeMediaEngine() override; bool Init() override; - rtc::scoped_refptr 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& audio_send_codecs() override; - const std::vector& audio_recv_codecs() override; - RtpCapabilities GetAudioCapabilities() override; - - std::vector 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 voice_engine_; diff --git a/pc/channelmanager.cc b/pc/channelmanager.cc index 31920d973b..eda5a2dd57 100644 --- a/pc/channelmanager.cc +++ b/pc/channelmanager.cc @@ -66,7 +66,7 @@ void ChannelManager::GetSupportedAudioSendCodecs( if (!media_engine_) { return; } - *codecs = media_engine_->audio_send_codecs(); + *codecs = media_engine_->voice().send_codecs(); } void ChannelManager::GetSupportedAudioReceiveCodecs( @@ -74,7 +74,7 @@ void ChannelManager::GetSupportedAudioReceiveCodecs( if (!media_engine_) { return; } - *codecs = media_engine_->audio_recv_codecs(); + *codecs = media_engine_->voice().recv_codecs(); } void ChannelManager::GetSupportedAudioRtpHeaderExtensions( @@ -82,7 +82,7 @@ void ChannelManager::GetSupportedAudioRtpHeaderExtensions( if (!media_engine_) { return; } - *ext = media_engine_->GetAudioCapabilities().header_extensions; + *ext = media_engine_->voice().GetCapabilities().header_extensions; } void ChannelManager::GetSupportedVideoCodecs( @@ -92,7 +92,7 @@ void ChannelManager::GetSupportedVideoCodecs( } codecs->clear(); - std::vector video_codecs = media_engine_->video_codecs(); + std::vector 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 @@ void ChannelManager::GetSupportedVideoRtpHeaderExtensions( if (!media_engine_) { return; } - *ext = media_engine_->GetVideoCapabilities().header_extensions; + *ext = media_engine_->video().GetCapabilities().header_extensions; } void ChannelManager::GetSupportedDataCodecs( @@ -177,8 +177,8 @@ VoiceChannel* ChannelManager::CreateVoiceChannel( 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 @@ VideoChannel* ChannelManager::CreateVideoChannel( 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 @@ void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) { bool ChannelManager::StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) { return worker_thread_->Invoke(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(RTC_FROM_HERE, - [&] { media_engine_->StopAecDump(); }); + [&] { media_engine_->voice().StopAecDump(); }); } } // namespace cricket diff --git a/pc/peerconnection.cc b/pc/peerconnection.cc index 982e52259e..3b9b9c8290 100644 --- a/pc/peerconnection.cc +++ b/pc/peerconnection.cc @@ -1717,7 +1717,7 @@ void PeerConnection::GetStats( 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 @@ void PeerConnection::GetStats( 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 @@ void PeerConnection::SetAudioPlayout(bool playout) { 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 @@ void PeerConnection::SetAudioRecording(bool recording) { 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 dd39141a0c..6af0c9887e 100644 --- a/pc/peerconnection_media_unittest.cc +++ b/pc/peerconnection_media_unittest.cc @@ -704,7 +704,7 @@ void AddComfortNoiseCodecsToSend(cricket::FakeMediaEngine* media_engine) { 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 e039d4c7d6..37c6a0b0bc 100644 --- a/pc/peerconnectionfactory.cc +++ b/pc/peerconnectionfactory.cc @@ -470,7 +470,8 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( 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;