From 445e6b034a2d579f0ce427f619efb9aa85f8eead Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Tue, 29 Sep 2020 14:21:47 +0000 Subject: [PATCH] Break out separate compile targets for various classes This reduces the degree of interdependency among modules related to the PeerConnection class, and makes it easier to isolate inappropriate external dependencies. Bug: webrtc:11967 Change-Id: Id9777a2ab690cc349dd5842a3a95e24478144c71 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185882 Commit-Queue: Harald Alvestrand Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#32235} --- examples/BUILD.gn | 2 + pc/BUILD.gn | 131 ++++++++++++++++++++++++++++++--- pc/rtp_sender.cc | 7 +- pc/rtp_sender.h | 8 +- pc/stats_collector.cc | 1 - pc/stats_collector.h | 9 ++- pc/stats_collector_interface.h | 40 ++++++++++ test/pc/e2e/BUILD.gn | 1 + 8 files changed, 177 insertions(+), 22 deletions(-) create mode 100644 pc/stats_collector_interface.h diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 86b06cd65d..c7b113ad73 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -672,6 +672,7 @@ if (is_linux || is_chromeos || is_win) { "../api/video_codecs:video_codecs_api", "../media:rtc_media_base", "../p2p:rtc_p2p", + "../pc:video_track_source", "../rtc_base:checks", "../rtc_base/third_party/sigslot", "../system_wrappers:field_trial", @@ -822,6 +823,7 @@ if (is_win || is_android) { "../modules/video_capture:video_capture_module", "../pc:libjingle_peerconnection", "../pc:peerconnection", + "../pc:video_track_source", "../rtc_base", "../test:platform_video_capturer", "../test:video_test_common", diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 1eb77c493e..d50832d9be 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -166,8 +166,6 @@ rtc_library("peerconnection") { "data_channel_controller.h", "data_channel_utils.cc", "data_channel_utils.h", - "dtmf_sender.cc", - "dtmf_sender.h", "ice_server_parsing.cc", "ice_server_parsing.h", "jitter_buffer_delay.cc", @@ -178,8 +176,6 @@ rtc_library("peerconnection") { "jsep_session_description.cc", "local_audio_source.cc", "local_audio_source.h", - "media_stream.cc", - "media_stream.h", "media_stream_observer.cc", "media_stream_observer.h", "media_stream_track.h", @@ -198,10 +194,6 @@ rtc_library("peerconnection") { "rtp_data_channel.h", "rtp_parameters_conversion.cc", "rtp_parameters_conversion.h", - "rtp_receiver.cc", - "rtp_receiver.h", - "rtp_sender.cc", - "rtp_sender.h", "rtp_transceiver.cc", "rtp_transceiver.h", "sctp_data_channel.cc", @@ -225,8 +217,6 @@ rtc_library("peerconnection") { "video_rtp_track_source.h", "video_track.cc", "video_track.h", - "video_track_source.cc", - "video_track_source.h", "webrtc_sdp.cc", "webrtc_sdp.h", "webrtc_session_description_factory.cc", @@ -234,7 +224,13 @@ rtc_library("peerconnection") { ] deps = [ + ":dtmf_sender", + ":media_stream", ":rtc_pc_base", + ":rtp_receiver", + ":rtp_sender", + ":stats_collector_interface", + ":video_track_source", "../api:array_view", "../api:audio_options_api", "../api:call_api", @@ -294,6 +290,113 @@ rtc_library("peerconnection") { ] } +rtc_library("rtp_receiver") { + sources = [ + "rtp_receiver.cc", + "rtp_receiver.h", + ] + deps = [ + ":media_stream", + ":video_track_source", + "../api:libjingle_peerconnection_api", + "../api:media_stream_interface", + "../api:rtp_parameters", + "../api:scoped_refptr", + "../api/crypto:frame_decryptor_interface", + "../api/video:video_frame", + "../media:rtc_media_base", + "../rtc_base:checks", + "../rtc_base:logging", + "../rtc_base:rtc_base", + "../rtc_base:rtc_base_approved", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + +rtc_library("rtp_sender") { + sources = [ + "rtp_sender.cc", + "rtp_sender.h", + ] + deps = [ + ":dtmf_sender", + ":stats_collector_interface", + "../api:audio_options_api", + "../api:libjingle_peerconnection_api", + "../api:media_stream_interface", + "../media:rtc_media_base", + "../rtc_base:checks", + "../rtc_base:rtc_base", + "../rtc_base/synchronization:mutex", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + +rtc_library("dtmf_sender") { + sources = [ + "dtmf_sender.cc", + "dtmf_sender.h", + ] + deps = [ + "../api:libjingle_peerconnection_api", + "../rtc_base:checks", + "../rtc_base:rtc_base", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + +rtc_library("media_stream") { + sources = [ + "media_stream.cc", + "media_stream.h", + ] + deps = [ + "../api:libjingle_peerconnection_api", + "../api:media_stream_interface", + "../api:scoped_refptr", + "../rtc_base:checks", + "../rtc_base:refcount", + "../rtc_base:rtc_base", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + +rtc_library("video_track_source") { + sources = [ + "video_track_source.cc", + "video_track_source.h", + ] + deps = [ + "../api:media_stream_interface", + "../api/video:video_frame", + "../media:rtc_media_base", + "../rtc_base:checks", + "../rtc_base:rtc_base_approved", + "../rtc_base/system:rtc_export", + ] +} + +rtc_source_set("stats_collector_interface") { + sources = [ "stats_collector_interface.h" ] + deps = [ "../api:media_stream_interface" ] +} + rtc_source_set("libjingle_peerconnection") { visibility = [ "*" ] deps = [ @@ -472,6 +575,9 @@ if (rtc_include_tests) { ":libjingle_peerconnection", ":peerconnection", ":rtc_pc_base", + ":rtp_receiver", + ":rtp_sender", + ":video_track_source", "../api:audio_options_api", "../api:create_frame_generator", "../api:create_peerconnection_factory", @@ -569,8 +675,13 @@ if (rtc_include_tests) { } deps = [ + ":dtmf_sender", + ":media_stream", ":peerconnection", ":rtc_pc_base", + ":rtp_receiver", + ":rtp_sender", + ":video_track_source", "../api:array_view", "../api:audio_options_api", "../api:create_peerconnection_factory", diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc index 1430e299c4..0da6dfca80 100644 --- a/pc/rtp_sender.cc +++ b/pc/rtp_sender.cc @@ -17,8 +17,7 @@ #include "api/audio_options.h" #include "api/media_stream_interface.h" #include "media/base/media_engine.h" -#include "pc/peer_connection.h" -#include "pc/stats_collector.h" +#include "pc/stats_collector_interface.h" #include "rtc_base/checks.h" #include "rtc_base/helpers.h" #include "rtc_base/location.h" @@ -418,7 +417,7 @@ void LocalAudioSinkAdapter::SetSink(cricket::AudioSource::Sink* sink) { rtc::scoped_refptr AudioRtpSender::Create( rtc::Thread* worker_thread, const std::string& id, - StatsCollector* stats, + StatsCollectorInterface* stats, SetStreamsObserver* set_streams_observer) { return rtc::scoped_refptr( new rtc::RefCountedObject(worker_thread, id, stats, @@ -427,7 +426,7 @@ rtc::scoped_refptr AudioRtpSender::Create( AudioRtpSender::AudioRtpSender(rtc::Thread* worker_thread, const std::string& id, - StatsCollector* stats, + StatsCollectorInterface* stats, SetStreamsObserver* set_streams_observer) : RtpSenderBase(worker_thread, id, set_streams_observer), stats_(stats), diff --git a/pc/rtp_sender.h b/pc/rtp_sender.h index c343ff085d..c2fe91f01d 100644 --- a/pc/rtp_sender.h +++ b/pc/rtp_sender.h @@ -28,7 +28,7 @@ namespace webrtc { -class StatsCollector; +class StatsCollectorInterface; bool UnimplementedRtpParameterHasValue(const RtpParameters& parameters); @@ -257,7 +257,7 @@ class AudioRtpSender : public DtmfProviderInterface, public RtpSenderBase { static rtc::scoped_refptr Create( rtc::Thread* worker_thread, const std::string& id, - StatsCollector* stats, + StatsCollectorInterface* stats, SetStreamsObserver* set_streams_observer); virtual ~AudioRtpSender(); @@ -281,7 +281,7 @@ class AudioRtpSender : public DtmfProviderInterface, public RtpSenderBase { protected: AudioRtpSender(rtc::Thread* worker_thread, const std::string& id, - StatsCollector* stats, + StatsCollectorInterface* stats, SetStreamsObserver* set_streams_observer); void SetSend() override; @@ -303,7 +303,7 @@ class AudioRtpSender : public DtmfProviderInterface, public RtpSenderBase { } sigslot::signal0<> SignalDestroyed; - StatsCollector* stats_ = nullptr; + StatsCollectorInterface* stats_ = nullptr; rtc::scoped_refptr dtmf_sender_proxy_; bool cached_track_enabled_ = false; diff --git a/pc/stats_collector.cc b/pc/stats_collector.cc index 5f030a7464..991cc4eb2b 100644 --- a/pc/stats_collector.cc +++ b/pc/stats_collector.cc @@ -16,7 +16,6 @@ #include #include "pc/channel.h" -#include "pc/peer_connection.h" #include "rtc_base/checks.h" #include "rtc_base/third_party/base64/base64.h" #include "system_wrappers/include/field_trial.h" diff --git a/pc/stats_collector.h b/pc/stats_collector.h index 041fe2f8fe..99c8ae7025 100644 --- a/pc/stats_collector.h +++ b/pc/stats_collector.h @@ -27,6 +27,7 @@ #include "api/stats_types.h" #include "p2p/base/port.h" #include "pc/peer_connection_internal.h" +#include "pc/stats_collector_interface.h" #include "rtc_base/network_constants.h" #include "rtc_base/ssl_certificate.h" @@ -44,7 +45,7 @@ const char* AdapterTypeToStatsType(rtc::AdapterType type); // A mapping between track ids and their StatsReport. typedef std::map TrackIdMap; -class StatsCollector { +class StatsCollector : public StatsCollectorInterface { public: // The caller is responsible for ensuring that the pc outlives the // StatsCollector instance. @@ -57,11 +58,13 @@ class StatsCollector { void AddTrack(MediaStreamTrackInterface* track); // Adds a local audio track that is used for getting some voice statistics. - void AddLocalAudioTrack(AudioTrackInterface* audio_track, uint32_t ssrc); + void AddLocalAudioTrack(AudioTrackInterface* audio_track, + uint32_t ssrc) override; // Removes a local audio tracks that is used for getting some voice // statistics. - void RemoveLocalAudioTrack(AudioTrackInterface* audio_track, uint32_t ssrc); + void RemoveLocalAudioTrack(AudioTrackInterface* audio_track, + uint32_t ssrc) override; // Gather statistics from the session and store them for future use. void UpdateStats(PeerConnectionInterface::StatsOutputLevel level); diff --git a/pc/stats_collector_interface.h b/pc/stats_collector_interface.h new file mode 100644 index 0000000000..94b339ead2 --- /dev/null +++ b/pc/stats_collector_interface.h @@ -0,0 +1,40 @@ +/* + * Copyright 2020 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. + */ + +// This file contains an interface for the (obsolete) StatsCollector class that +// is used by compilation units that do not wish to depend on the StatsCollector +// implementation. + +#ifndef PC_STATS_COLLECTOR_INTERFACE_H_ +#define PC_STATS_COLLECTOR_INTERFACE_H_ + +#include + +#include "api/media_stream_interface.h" + +namespace webrtc { + +class StatsCollectorInterface { + public: + virtual ~StatsCollectorInterface() {} + + // Adds a local audio track that is used for getting some voice statistics. + virtual void AddLocalAudioTrack(AudioTrackInterface* audio_track, + uint32_t ssrc) = 0; + + // Removes a local audio tracks that is used for getting some voice + // statistics. + virtual void RemoveLocalAudioTrack(AudioTrackInterface* audio_track, + uint32_t ssrc) = 0; +}; + +} // namespace webrtc + +#endif // PC_STATS_COLLECTOR_INTERFACE_H_ diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index f9c0c9b4da..5c9e259659 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -307,6 +307,7 @@ if (!build_with_chromium) { "../../../api:peer_connection_quality_test_fixture_api", "../../../api/video:video_frame", "../../../pc:peerconnection", + "../../../pc:video_track_source", ] absl_deps = [ "//third_party/abseil-cpp/absl/types:variant" ] }