From 418bcf2acbb4a8f947a513b3a8b5a7a34a047b11 Mon Sep 17 00:00:00 2001 From: Tony Herre Date: Mon, 17 Jun 2024 17:28:40 +0200 Subject: [PATCH] Expose a PeerConnection's NetworkControllerInterface instance Allow API users to access the NetworkControllerInterface instance that a given PC ended up with, to allow integrators who have provided a PeerConnectionFactoryDependencies.network_controller_factory to associate a created instance of their custom network controller with the PC using it. Eg for the RTCRtpTransport Chromium implementation as in crrev.com/c/5607744. Bug: chromium:345101934 Change-Id: Ia712ca4f45b90d5078f4e8e5977622d3e9f9aa6f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/353980 Commit-Queue: Tony Herre Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#42506} --- api/peer_connection_interface.h | 4 ++++ api/test/mock_peerconnectioninterface.h | 4 ++++ call/rtp_transport_controller_send.h | 5 +++++ call/rtp_transport_controller_send_interface.h | 2 ++ call/test/mock_rtp_transport_controller_send.h | 4 ++++ pc/peer_connection.h | 10 ++++++++++ pc/peer_connection_proxy.h | 1 + pc/test/fake_peer_connection_base.h | 4 ++++ pc/test/mock_peer_connection_internal.h | 4 ++++ 9 files changed, 38 insertions(+) diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index ca6baacd0d..628a9f30ed 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -1221,6 +1221,10 @@ class RTC_EXPORT PeerConnectionInterface : public webrtc::RefCountInterface { // pointers. virtual rtc::Thread* signaling_thread() const = 0; + // NetworkController instance being used by this PeerConnection, to be used + // to identify instances when using a custom NetworkControllerFactory. + virtual NetworkControllerInterface* GetNetworkController() = 0; + protected: // Dtor protected as objects shouldn't be deleted via this interface. ~PeerConnectionInterface() override = default; diff --git a/api/test/mock_peerconnectioninterface.h b/api/test/mock_peerconnectioninterface.h index 814d1b1420..30822930bb 100644 --- a/api/test/mock_peerconnectioninterface.h +++ b/api/test/mock_peerconnectioninterface.h @@ -215,6 +215,10 @@ class MockPeerConnectionInterface : public webrtc::PeerConnectionInterface { MOCK_METHOD(void, StopRtcEventLog, (), (override)); MOCK_METHOD(void, Close, (), (override)); MOCK_METHOD(rtc::Thread*, signaling_thread, (), (const override)); + MOCK_METHOD(NetworkControllerInterface*, + GetNetworkController, + (), + (override)); }; static_assert( diff --git a/call/rtp_transport_controller_send.h b/call/rtp_transport_controller_send.h index eada78ee0e..9b91d9acbf 100644 --- a/call/rtp_transport_controller_send.h +++ b/call/rtp_transport_controller_send.h @@ -120,6 +120,11 @@ class RtpTransportControllerSend final // Implements NetworkStateEstimateObserver interface void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override; + NetworkControllerInterface* GetNetworkController() override { + RTC_DCHECK_RUN_ON(&sequence_checker_); + return controller_.get(); + } + private: void MaybeCreateControllers() RTC_RUN_ON(sequence_checker_); void UpdateNetworkAvailability() RTC_RUN_ON(sequence_checker_); diff --git a/call/rtp_transport_controller_send_interface.h b/call/rtp_transport_controller_send_interface.h index 3fa6df55bb..bb995f9cb4 100644 --- a/call/rtp_transport_controller_send_interface.h +++ b/call/rtp_transport_controller_send_interface.h @@ -25,6 +25,7 @@ #include "api/frame_transformer_interface.h" #include "api/transport/bandwidth_estimation_settings.h" #include "api/transport/bitrate_settings.h" +#include "api/transport/network_control.h" #include "api/units/timestamp.h" #include "call/rtp_config.h" #include "common_video/frame_counts.h" @@ -160,6 +161,7 @@ class RtpTransportControllerSendInterface { virtual void IncludeOverheadInPacedSender() = 0; virtual void EnsureStarted() = 0; + virtual NetworkControllerInterface* GetNetworkController() = 0; }; } // namespace webrtc diff --git a/call/test/mock_rtp_transport_controller_send.h b/call/test/mock_rtp_transport_controller_send.h index 70b851f07b..d1e1d64aff 100644 --- a/call/test/mock_rtp_transport_controller_send.h +++ b/call/test/mock_rtp_transport_controller_send.h @@ -105,6 +105,10 @@ class MockRtpTransportControllerSend MOCK_METHOD(void, IncludeOverheadInPacedSender, (), (override)); MOCK_METHOD(void, OnReceivedPacket, (const ReceivedPacket&), (override)); MOCK_METHOD(void, EnsureStarted, (), (override)); + MOCK_METHOD(NetworkControllerInterface*, + GetNetworkController, + (), + (override)); }; } // namespace webrtc #endif // CALL_TEST_MOCK_RTP_TRANSPORT_CONTROLLER_SEND_H_ diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 3c923139dc..ef543a227f 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -439,6 +439,16 @@ class PeerConnection : public PeerConnectionInternal, } void RequestUsagePatternReportForTesting(); + NetworkControllerInterface* GetNetworkController() override { + if (!worker_thread()->IsCurrent()) { + return worker_thread()->BlockingCall( + [this]() { return GetNetworkController(); }); + } + RTC_DCHECK_RUN_ON(worker_thread()); + RTC_DCHECK(call_); + return call_->GetTransportControllerSend()->GetNetworkController(); + } + protected: // Available for rtc::scoped_refptr creation PeerConnection(const Environment& env, diff --git a/pc/peer_connection_proxy.h b/pc/peer_connection_proxy.h index aaccfe45d0..898f24d343 100644 --- a/pc/peer_connection_proxy.h +++ b/pc/peer_connection_proxy.h @@ -166,6 +166,7 @@ PROXY_METHOD2(bool, PROXY_METHOD1(bool, StartRtcEventLog, std::unique_ptr) PROXY_METHOD0(void, StopRtcEventLog) PROXY_METHOD0(void, Close) +PROXY_METHOD0(NetworkControllerInterface*, GetNetworkController) BYPASS_PROXY_CONSTMETHOD0(rtc::Thread*, signaling_thread) END_PROXY_MAP(PeerConnection) diff --git a/pc/test/fake_peer_connection_base.h b/pc/test/fake_peer_connection_base.h index 8422f0b749..6f996700fb 100644 --- a/pc/test/fake_peer_connection_base.h +++ b/pc/test/fake_peer_connection_base.h @@ -369,6 +369,10 @@ class FakePeerConnectionBase : public PeerConnectionInternal { const FieldTrialsView& trials() const override { return field_trials_; } + NetworkControllerInterface* GetNetworkController() override { + return nullptr; + } + protected: test::ScopedKeyValueConfig field_trials_; }; diff --git a/pc/test/mock_peer_connection_internal.h b/pc/test/mock_peer_connection_internal.h index c9f896b8bb..78b6755b3b 100644 --- a/pc/test/mock_peer_connection_internal.h +++ b/pc/test/mock_peer_connection_internal.h @@ -330,6 +330,10 @@ class MockPeerConnectionInternal : public PeerConnectionInternal { OnSctpDataChannelStateChanged, (int channel_id, DataChannelInterface::DataState), (override)); + MOCK_METHOD(NetworkControllerInterface*, + GetNetworkController, + (), + (override)); }; } // namespace webrtc