From 25adc8e36b4ff53fae45f33e8790ed236f6c0d9b Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Tue, 3 May 2022 13:44:34 +0000 Subject: [PATCH] Eliminate channel.h from rtp_transmission_manager.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also hides the existence of the classes VideoChannel and VoiceChannel from anything that does not include "channel.h". Bug: webrtc:13931 Change-Id: I080a692b6acfd5d2d0401ec20d59c3a684eddb05 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260944 Commit-Queue: Harald Alvestrand Reviewed-by: Henrik Boström Cr-Commit-Position: refs/heads/main@{#36746} --- pc/BUILD.gn | 15 +++++++++ pc/channel.h | 16 ++++++++++ pc/channel_factory_interface.h | 55 ++++++++++++++++++++++++++++++++ pc/channel_interface.h | 30 +++-------------- pc/channel_manager.h | 1 + pc/rtp_transmission_manager.cc | 12 +++---- pc/test/mock_channel_interface.h | 2 ++ 7 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 pc/channel_factory_interface.h diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 272e801eda..f94643daa0 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -118,6 +118,19 @@ rtc_source_set("channel_interface") { absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } +rtc_source_set("channel_factory_interface") { + visibility = [ ":*" ] + sources = [ "channel_factory_interface.h" ] + deps = [ + "../api:audio_options_api", + "../api/crypto:options", + "../api/video:video_bitrate_allocator_factory", + "../call:call_interfaces", + "../media:rtc_media_base", + "../media:rtc_media_config", + ] +} + rtc_source_set("channel_manager") { visibility = [ ":*" ] sources = [ @@ -126,6 +139,7 @@ rtc_source_set("channel_manager") { ] deps = [ ":channel", + ":channel_factory_interface", ":channel_interface", ":session_description", "../api:audio_options_api", @@ -1611,6 +1625,7 @@ rtc_library("rtp_transmission_manager") { deps = [ ":audio_rtp_receiver", ":channel", + ":channel_interface", ":channel_manager", ":rtp_receiver", ":rtp_receiver_proxy", diff --git a/pc/channel.h b/pc/channel.h index fabfe96e56..c320286f53 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -158,6 +158,14 @@ class BaseChannel : public ChannelInterface, MediaChannel* media_channel() const override { return media_channel_.get(); } + VideoMediaChannel* video_media_channel() const override { + RTC_CHECK(false) << "Attempt to fetch video channel from non-video"; + return nullptr; + } + VoiceMediaChannel* voice_media_channel() const override { + RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice"; + return nullptr; + } protected: void set_local_content_direction(webrtc::RtpTransceiverDirection direction) @@ -364,6 +372,10 @@ class VoiceChannel : public BaseChannel { return static_cast(BaseChannel::media_channel()); } + VoiceMediaChannel* voice_media_channel() const override { + return static_cast(media_channel()); + } + cricket::MediaType media_type() const override { return cricket::MEDIA_TYPE_AUDIO; } @@ -406,6 +418,10 @@ class VideoChannel : public BaseChannel { return static_cast(BaseChannel::media_channel()); } + VideoMediaChannel* video_media_channel() const override { + return static_cast(media_channel()); + } + cricket::MediaType media_type() const override { return cricket::MEDIA_TYPE_VIDEO; } diff --git a/pc/channel_factory_interface.h b/pc/channel_factory_interface.h new file mode 100644 index 0000000000..62fb1aea1f --- /dev/null +++ b/pc/channel_factory_interface.h @@ -0,0 +1,55 @@ +/* + * Copyright 2004 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef PC_CHANNEL_FACTORY_INTERFACE_H_ +#define PC_CHANNEL_FACTORY_INTERFACE_H_ + +#include +#include + +#include "api/audio_options.h" +#include "api/crypto/crypto_options.h" +#include "api/video/video_bitrate_allocator_factory.h" +#include "call/call.h" +#include "media/base/media_channel.h" +#include "media/base/media_config.h" + +namespace cricket { + +class VideoChannel; +class VoiceChannel; + +class ChannelFactoryInterface { + public: + virtual std::unique_ptr CreateVideoChannel( + webrtc::Call* call, + const MediaConfig& media_config, + const std::string& mid, + bool srtp_required, + const webrtc::CryptoOptions& crypto_options, + const VideoOptions& options, + webrtc::VideoBitrateAllocatorFactory* + video_bitrate_allocator_factory) = 0; + + virtual std::unique_ptr CreateVoiceChannel( + webrtc::Call* call, + const MediaConfig& media_config, + const std::string& mid, + bool srtp_required, + const webrtc::CryptoOptions& crypto_options, + const AudioOptions& options) = 0; + + protected: + virtual ~ChannelFactoryInterface() = default; +}; + +} // namespace cricket + +#endif // PC_CHANNEL_FACTORY_INTERFACE_H_ diff --git a/pc/channel_interface.h b/pc/channel_interface.h index a82880b5a6..3c6ca6fe6a 100644 --- a/pc/channel_interface.h +++ b/pc/channel_interface.h @@ -29,8 +29,6 @@ class VideoBitrateAllocatorFactory; namespace cricket { class MediaContentDescription; -class VideoChannel; -class VoiceChannel; struct MediaConfig; // A Channel is a construct that groups media streams of the same type @@ -50,6 +48,10 @@ class ChannelInterface { virtual cricket::MediaType media_type() const = 0; virtual MediaChannel* media_channel() const = 0; + // Typecasts of media_channel(). Will cause an exception if the + // channel is of the wrong type. + virtual VideoMediaChannel* video_media_channel() const = 0; + virtual VoiceMediaChannel* voice_media_channel() const = 0; // Returns a string view for the transport name. Fetching the transport name // must be done on the network thread only and note that the lifetime of @@ -88,30 +90,6 @@ class ChannelInterface { virtual bool SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) = 0; }; -class ChannelFactoryInterface { - public: - virtual std::unique_ptr CreateVideoChannel( - webrtc::Call* call, - const MediaConfig& media_config, - const std::string& mid, - bool srtp_required, - const webrtc::CryptoOptions& crypto_options, - const VideoOptions& options, - webrtc::VideoBitrateAllocatorFactory* - video_bitrate_allocator_factory) = 0; - - virtual std::unique_ptr CreateVoiceChannel( - webrtc::Call* call, - const MediaConfig& media_config, - const std::string& mid, - bool srtp_required, - const webrtc::CryptoOptions& crypto_options, - const AudioOptions& options) = 0; - - protected: - virtual ~ChannelFactoryInterface() = default; -}; - } // namespace cricket #endif // PC_CHANNEL_INTERFACE_H_ diff --git a/pc/channel_manager.h b/pc/channel_manager.h index 6fd27edffe..c9a54936f3 100644 --- a/pc/channel_manager.h +++ b/pc/channel_manager.h @@ -26,6 +26,7 @@ #include "media/base/media_channel.h" #include "media/base/media_config.h" #include "media/base/media_engine.h" +#include "pc/channel_factory_interface.h" #include "pc/channel_interface.h" #include "pc/session_description.h" #include "rtc_base/system/file_wrapper.h" diff --git a/pc/rtp_transmission_manager.cc b/pc/rtp_transmission_manager.cc index 0edc09963f..28508234cb 100644 --- a/pc/rtp_transmission_manager.cc +++ b/pc/rtp_transmission_manager.cc @@ -17,7 +17,7 @@ #include "api/peer_connection_interface.h" #include "api/rtp_transceiver_direction.h" #include "pc/audio_rtp_receiver.h" -#include "pc/channel.h" +#include "pc/channel_interface.h" #include "pc/stats_collector_interface.h" #include "pc/video_rtp_receiver.h" #include "rtc_base/checks.h" @@ -81,10 +81,9 @@ cricket::VoiceMediaChannel* RtpTransmissionManager::voice_media_channel() const { RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(!IsUnifiedPlan()); - auto* voice_channel = static_cast( - GetAudioTransceiver()->internal()->channel()); + auto* voice_channel = GetAudioTransceiver()->internal()->channel(); if (voice_channel) { - return voice_channel->media_channel(); + return voice_channel->voice_media_channel(); } else { return nullptr; } @@ -94,10 +93,9 @@ cricket::VideoMediaChannel* RtpTransmissionManager::video_media_channel() const { RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK(!IsUnifiedPlan()); - auto* video_channel = static_cast( - GetVideoTransceiver()->internal()->channel()); + auto* video_channel = GetVideoTransceiver()->internal()->channel(); if (video_channel) { - return video_channel->media_channel(); + return video_channel->video_media_channel(); } else { return nullptr; } diff --git a/pc/test/mock_channel_interface.h b/pc/test/mock_channel_interface.h index 844a36e2d0..97e873e724 100644 --- a/pc/test/mock_channel_interface.h +++ b/pc/test/mock_channel_interface.h @@ -26,6 +26,8 @@ class MockChannelInterface : public cricket::ChannelInterface { public: MOCK_METHOD(cricket::MediaType, media_type, (), (const, override)); MOCK_METHOD(MediaChannel*, media_channel, (), (const, override)); + MOCK_METHOD(VoiceMediaChannel*, voice_media_channel, (), (const, override)); + MOCK_METHOD(VideoMediaChannel*, video_media_channel, (), (const, override)); MOCK_METHOD(absl::string_view, transport_name, (), (const, override)); MOCK_METHOD(const std::string&, mid, (), (const, override)); MOCK_METHOD(void, Enable, (bool), (override));