diff --git a/api/BUILD.gn b/api/BUILD.gn index effdb5dc20..f8b282f633 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -108,6 +108,7 @@ rtc_static_library("libjingle_peerconnection_api") { "audio:audio_mixer_api", "audio_codecs:audio_codecs_api", "transport:bitrate_settings", + "transport:network_control", "video:video_frame", # Basically, don't add stuff here. You might break sensitive downstream diff --git a/api/peerconnectioninterface.h b/api/peerconnectioninterface.h index 7ec83539a4..8c0602945b 100644 --- a/api/peerconnectioninterface.h +++ b/api/peerconnectioninterface.h @@ -91,6 +91,7 @@ #include "api/stats/rtcstatscollectorcallback.h" #include "api/statstypes.h" #include "api/transport/bitrate_settings.h" +#include "api/transport/network_control.h" #include "api/turncustomizer.h" #include "api/umametrics.h" #include "logging/rtc_event_log/rtc_event_log_factory_interface.h" @@ -1424,6 +1425,8 @@ rtc::scoped_refptr CreatePeerConnectionFactory( // created and used. // If |fec_controller_factory| is null, an internal fec controller module will // be created and used. +// If |network_controller_factory| is provided, it will be used if enabled via +// field trial. rtc::scoped_refptr CreatePeerConnectionFactory( rtc::Thread* network_thread, rtc::Thread* worker_thread, @@ -1435,7 +1438,9 @@ rtc::scoped_refptr CreatePeerConnectionFactory( cricket::WebRtcVideoDecoderFactory* video_decoder_factory, rtc::scoped_refptr audio_mixer, rtc::scoped_refptr audio_processing, - std::unique_ptr fec_controller_factory); + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory = nullptr); // Create a new instance of PeerConnectionFactoryInterface with optional video // codec factories. These video factories represents all video codecs, i.e. no @@ -1536,7 +1541,9 @@ CreateModularPeerConnectionFactory( std::unique_ptr media_engine, std::unique_ptr call_factory, std::unique_ptr event_log_factory, - std::unique_ptr fec_controller_factory); + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory = nullptr); } // namespace webrtc diff --git a/call/BUILD.gn b/call/BUILD.gn index c509acedbb..d994eddffa 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -37,6 +37,7 @@ rtc_source_set("call_interfaces") { "../api:transport_api", "../api/audio:audio_mixer_api", "../api/audio_codecs:audio_codecs_api", + "../api/transport:network_control", "../modules/audio_device:audio_device", "../modules/audio_processing:audio_processing", "../modules/audio_processing:audio_processing_statistics", diff --git a/call/call.cc b/call/call.cc index 3635bf2c7a..25f1cd9b24 100644 --- a/call/call.cc +++ b/call/call.cc @@ -396,9 +396,9 @@ std::string Call::Stats::ToString(int64_t time_ms) const { Call* Call::Create(const Call::Config& config) { return new internal::Call( - config, - rtc::MakeUnique( - Clock::GetRealTimeClock(), config.event_log, config.bitrate_config)); + config, rtc::MakeUnique( + Clock::GetRealTimeClock(), config.event_log, + config.network_controller_factory, config.bitrate_config)); } Call* Call::Create( diff --git a/call/call_config.h b/call/call_config.h index 421b52464e..927ad75959 100644 --- a/call/call_config.h +++ b/call/call_config.h @@ -12,6 +12,7 @@ #include "api/fec_controller.h" #include "api/rtcerror.h" +#include "api/transport/network_control.h" #include "call/audio_state.h" #include "call/bitrate_constraints.h" #include "rtc_base/platform_file.h" @@ -45,6 +46,9 @@ struct CallConfig { // FecController to use for this call. FecControllerFactoryInterface* fec_controller_factory = nullptr; + + // Network controller factory to use for this call. + NetworkControllerFactoryInterface* network_controller_factory = nullptr; }; } // namespace webrtc diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc index 2a4a549596..76ba7f654f 100644 --- a/call/rtp_transport_controller_send.cc +++ b/call/rtp_transport_controller_send.cc @@ -33,12 +33,14 @@ std::unique_ptr CreateController( webrtc::RtcEventLog* event_log, PacedSender* pacer, const BitrateConstraints& bitrate_config, - bool task_queue_controller) { + bool task_queue_controller, + NetworkControllerFactoryInterface* controller_factory) { if (task_queue_controller) { RTC_LOG(LS_INFO) << "Using TaskQueue based SSCC"; return rtc::MakeUnique( clock, task_queue, event_log, pacer, bitrate_config.start_bitrate_bps, - bitrate_config.min_bitrate_bps, bitrate_config.max_bitrate_bps); + bitrate_config.min_bitrate_bps, bitrate_config.max_bitrate_bps, + controller_factory); } RTC_LOG(LS_INFO) << "Using Legacy SSCC"; auto cc = rtc::MakeUnique( @@ -54,6 +56,7 @@ std::unique_ptr CreateController( RtpTransportControllerSend::RtpTransportControllerSend( Clock* clock, webrtc::RtcEventLog* event_log, + NetworkControllerFactoryInterface* controller_factory, const BitrateConstraints& bitrate_config) : clock_(clock), pacer_(clock, &packet_router_, event_log), @@ -64,7 +67,7 @@ RtpTransportControllerSend::RtpTransportControllerSend( // Created after task_queue to be able to post to the task queue internally. send_side_cc_ = CreateController(clock, &task_queue_, event_log, &pacer_, bitrate_config, - TaskQueueExperimentEnabled()); + TaskQueueExperimentEnabled(), controller_factory); process_thread_->RegisterModule(&pacer_, RTC_FROM_HERE); process_thread_->RegisterModule(send_side_cc_.get(), RTC_FROM_HERE); diff --git a/call/rtp_transport_controller_send.h b/call/rtp_transport_controller_send.h index 67248b22c6..25b1127675 100644 --- a/call/rtp_transport_controller_send.h +++ b/call/rtp_transport_controller_send.h @@ -15,6 +15,7 @@ #include #include +#include "api/transport/network_control.h" #include "call/rtp_bitrate_configurator.h" #include "call/rtp_transport_controller_send_interface.h" #include "common_types.h" // NOLINT(build/include) @@ -36,9 +37,11 @@ class RtpTransportControllerSend final : public RtpTransportControllerSendInterface, public NetworkChangedObserver { public: - RtpTransportControllerSend(Clock* clock, - RtcEventLog* event_log, - const BitrateConstraints& bitrate_config); + RtpTransportControllerSend( + Clock* clock, + RtcEventLog* event_log, + NetworkControllerFactoryInterface* controller_factory, + const BitrateConstraints& bitrate_config); ~RtpTransportControllerSend() override; // Implements NetworkChangedObserver interface. diff --git a/modules/congestion_controller/bbr/bbr_network_controller.cc b/modules/congestion_controller/bbr/bbr_network_controller.cc index 0a9a1f57ff..33ba015584 100644 --- a/modules/congestion_controller/bbr/bbr_network_controller.cc +++ b/modules/congestion_controller/bbr/bbr_network_controller.cc @@ -177,6 +177,7 @@ BbrNetworkController::BbrNetworkController(NetworkControllerConfig config) congestion_window_gain_constant_(kProbeBWCongestionWindowGain), rtt_variance_weight_(kBbrRttVariationWeight), recovery_window_(max_congestion_window_) { + RTC_LOG(LS_INFO) << "Creating BBR controller"; config_ = BbrControllerConfig::ExperimentConfig(); if (config.starting_bandwidth.IsFinite()) default_bandwidth_ = config.starting_bandwidth; diff --git a/modules/congestion_controller/rtp/BUILD.gn b/modules/congestion_controller/rtp/BUILD.gn index 02c324505a..3b366914d6 100644 --- a/modules/congestion_controller/rtp/BUILD.gn +++ b/modules/congestion_controller/rtp/BUILD.gn @@ -53,7 +53,6 @@ rtc_static_library("congestion_controller") { "../../pacing", "../../remote_bitrate_estimator", "../../rtp_rtcp:rtp_rtcp_format", - "../bbr", "../goog_cc", ] diff --git a/modules/congestion_controller/rtp/include/send_side_congestion_controller.h b/modules/congestion_controller/rtp/include/send_side_congestion_controller.h index a273bbe78d..7d41e27a30 100644 --- a/modules/congestion_controller/rtp/include/send_side_congestion_controller.h +++ b/modules/congestion_controller/rtp/include/send_side_congestion_controller.h @@ -65,13 +65,16 @@ class SendSideCongestionController : public SendSideCongestionControllerInterface, public RtcpBandwidthObserver { public: - SendSideCongestionController(const Clock* clock, - rtc::TaskQueue* task_queue, - RtcEventLog* event_log, - PacedSender* pacer, - int start_bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps); + SendSideCongestionController( + const Clock* clock, + rtc::TaskQueue* task_queue, + RtcEventLog* event_log, + PacedSender* pacer, + int start_bitrate_bps, + int min_bitrate_bps, + int max_bitrate_bps, + NetworkControllerFactoryInterface* controller_factory); + ~SendSideCongestionController() override; void RegisterPacketFeedbackObserver( @@ -170,8 +173,8 @@ class SendSideCongestionController // TODO(srte): Move all access to feedback adapter to task queue. TransportFeedbackAdapter transport_feedback_adapter_; - const std::unique_ptr - controller_factory_with_feedback_ RTC_GUARDED_BY(task_queue_); + NetworkControllerFactoryInterface* const controller_factory_with_feedback_ + RTC_GUARDED_BY(task_queue_); const std::unique_ptr controller_factory_fallback_ RTC_GUARDED_BY(task_queue_); diff --git a/modules/congestion_controller/rtp/send_side_congestion_controller.cc b/modules/congestion_controller/rtp/send_side_congestion_controller.cc index 6d3f30152e..00224bd328 100644 --- a/modules/congestion_controller/rtp/send_side_congestion_controller.cc +++ b/modules/congestion_controller/rtp/send_side_congestion_controller.cc @@ -15,12 +15,10 @@ #include #include #include "api/transport/network_types.h" -#include "modules/congestion_controller/bbr/bbr_factory.h" #include "modules/congestion_controller/goog_cc/include/goog_cc_factory.h" #include "modules/remote_bitrate_estimator/include/bwe_defines.h" #include "rtc_base/bind.h" #include "rtc_base/checks.h" -#include "rtc_base/experiments/congestion_controller_experiment.h" #include "rtc_base/format_macros.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" @@ -50,16 +48,6 @@ bool IsPacerPushbackExperimentEnabled() { webrtc::runtime_enabled_features::kDualStreamModeFeatureName)); } -std::unique_ptr MaybeCreateBbrFactory() { - if (CongestionControllerExperiment::BbrControllerEnabled()) { - RTC_LOG(LS_INFO) << "Creating BBR factory"; - return rtc::MakeUnique(); - } else { - RTC_LOG(LS_INFO) << "Not creating BBR factory"; - return nullptr; - } -} - void SortPacketFeedbackVector(std::vector* input) { std::sort(input->begin(), input->end(), PacketFeedbackComparator()); } @@ -310,11 +298,12 @@ SendSideCongestionController::SendSideCongestionController( PacedSender* pacer, int start_bitrate_bps, int min_bitrate_bps, - int max_bitrate_bps) + int max_bitrate_bps, + NetworkControllerFactoryInterface* controller_factory) : clock_(clock), pacer_(pacer), transport_feedback_adapter_(clock_), - controller_factory_with_feedback_(MaybeCreateBbrFactory()), + controller_factory_with_feedback_(controller_factory), controller_factory_fallback_( rtc::MakeUnique(event_log)), pacer_controller_(MakeUnique(pacer_)), diff --git a/modules/congestion_controller/rtp/send_side_congestion_controller_unittest.cc b/modules/congestion_controller/rtp/send_side_congestion_controller_unittest.cc index 0f598082e4..136a989f78 100644 --- a/modules/congestion_controller/rtp/send_side_congestion_controller_unittest.cc +++ b/modules/congestion_controller/rtp/send_side_congestion_controller_unittest.cc @@ -77,7 +77,7 @@ class SendSideCongestionControllerTest : public ::testing::Test { task_queue_ = rtc::MakeUnique("SSCC Test"); controller_.reset(new SendSideCongestionControllerForTest( &clock_, task_queue_.get(), &event_log_, pacer_.get(), - kInitialBitrateBps, 0, 5 * kInitialBitrateBps)); + kInitialBitrateBps, 0, 5 * kInitialBitrateBps, nullptr)); controller_->DisablePeriodicTasks(); controller_->RegisterNetworkObserver(&observer_); controller_->SignalNetworkState(NetworkState::kNetworkUp); @@ -97,7 +97,7 @@ class SendSideCongestionControllerTest : public ::testing::Test { task_queue_ = rtc::MakeUnique("SSCC Test"); controller_.reset(new SendSideCongestionControllerForTest( &clock_, task_queue_.get(), &event_log_, pacer_.get(), - kInitialBitrateBps, 0, 5 * kInitialBitrateBps)); + kInitialBitrateBps, 0, 5 * kInitialBitrateBps, nullptr)); controller_->DisablePeriodicTasks(); controller_->RegisterNetworkObserver(&target_bitrate_observer_); controller_->SignalNetworkState(NetworkState::kNetworkUp); diff --git a/ortc/rtptransportcontrolleradapter.cc b/ortc/rtptransportcontrolleradapter.cc index f69edd5803..5d5bf5ed7b 100644 --- a/ortc/rtptransportcontrolleradapter.cc +++ b/ortc/rtptransportcontrolleradapter.cc @@ -657,7 +657,8 @@ void RtpTransportControllerAdapter::Init_w() { call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; std::unique_ptr controller_send = rtc::MakeUnique( - Clock::GetRealTimeClock(), event_log_, call_config.bitrate_config); + Clock::GetRealTimeClock(), event_log_, + call_config.network_controller_factory, call_config.bitrate_config); call_send_rtp_transport_controller_ = controller_send.get(); call_.reset(webrtc::Call::Create(call_config, std::move(controller_send))); } diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 15e050b228..2942d11714 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -204,11 +204,13 @@ rtc_static_library("peerconnection") { "../logging:rtc_event_log_impl_output", "../media:rtc_data", "../media:rtc_media_base", + "../modules/congestion_controller/bbr", "../p2p:rtc_p2p", "../rtc_base:checks", "../rtc_base:rtc_base", "../rtc_base:rtc_base_approved", "../rtc_base:stringutils", + "../rtc_base/experiments:congestion_controller_experiment", "../stats", "../system_wrappers", "../system_wrappers:field_trial_api", diff --git a/pc/DEPS b/pc/DEPS index 38d40a0566..1f9d15272d 100644 --- a/pc/DEPS +++ b/pc/DEPS @@ -8,6 +8,7 @@ include_rules = [ "+media", "+modules/audio_device", "+modules/audio_processing", + "+modules/congestion_controller", "+modules/rtp_rtcp", "+modules/video_coding", "+modules/video_render", diff --git a/pc/createpeerconnectionfactory.cc b/pc/createpeerconnectionfactory.cc index 72e578277d..bbc4ebbe73 100644 --- a/pc/createpeerconnectionfactory.cc +++ b/pc/createpeerconnectionfactory.cc @@ -79,7 +79,9 @@ rtc::scoped_refptr CreatePeerConnectionFactory( cricket::WebRtcVideoDecoderFactory* video_decoder_factory, rtc::scoped_refptr audio_mixer, rtc::scoped_refptr audio_processing, - std::unique_ptr fec_controller_factory) { + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory) { rtc::scoped_refptr audio_processing_use = audio_processing; if (!audio_processing_use) { audio_processing_use = AudioProcessingBuilder().Create(); @@ -99,7 +101,7 @@ rtc::scoped_refptr CreatePeerConnectionFactory( return CreateModularPeerConnectionFactory( network_thread, worker_thread, signaling_thread, std::move(media_engine), std::move(call_factory), std::move(event_log_factory), - std::move(fec_controller_factory)); + std::move(fec_controller_factory), std::move(network_controller_factory)); } #endif diff --git a/pc/peerconnectionfactory.cc b/pc/peerconnectionfactory.cc index 4889723174..0fc6af2557 100644 --- a/pc/peerconnectionfactory.cc +++ b/pc/peerconnectionfactory.cc @@ -34,6 +34,7 @@ #include "media/engine/webrtcvideodecoderfactory.h" // nogncheck #include "media/engine/webrtcvideoencoderfactory.h" // nogncheck #include "modules/audio_device/include/audio_device.h" // nogncheck +#include "modules/congestion_controller/bbr/bbr_factory.h" #include "p2p/base/basicpacketsocketfactory.h" #include "p2p/client/basicportallocator.h" #include "pc/audiotrack.h" @@ -42,6 +43,7 @@ #include "pc/peerconnection.h" #include "pc/videocapturertracksource.h" #include "pc/videotrack.h" +#include "rtc_base/experiments/congestion_controller_experiment.h" namespace webrtc { @@ -55,7 +57,7 @@ CreateModularPeerConnectionFactory( std::unique_ptr event_log_factory) { return CreateModularPeerConnectionFactory( network_thread, worker_thread, signaling_thread, std::move(media_engine), - std::move(call_factory), std::move(event_log_factory), nullptr); + std::move(call_factory), std::move(event_log_factory), nullptr, nullptr); } rtc::scoped_refptr @@ -66,12 +68,15 @@ CreateModularPeerConnectionFactory( std::unique_ptr media_engine, std::unique_ptr call_factory, std::unique_ptr event_log_factory, - std::unique_ptr fec_controller_factory) { + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory) { rtc::scoped_refptr pc_factory( new rtc::RefCountedObject( network_thread, worker_thread, signaling_thread, std::move(media_engine), std::move(call_factory), - std::move(event_log_factory), std::move(fec_controller_factory))); + std::move(event_log_factory), std::move(fec_controller_factory), + std::move(network_controller_factory))); // Call Initialize synchronously but make sure it is executed on // |signaling_thread|. @@ -99,6 +104,7 @@ PeerConnectionFactory::PeerConnectionFactory( std::move(media_engine), std::move(call_factory), std::move(event_log_factory), + nullptr, nullptr) {} PeerConnectionFactory::PeerConnectionFactory( @@ -108,7 +114,9 @@ PeerConnectionFactory::PeerConnectionFactory( std::unique_ptr media_engine, std::unique_ptr call_factory, std::unique_ptr event_log_factory, - std::unique_ptr fec_controller_factory) + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory) : wraps_current_thread_(false), network_thread_(network_thread), worker_thread_(worker_thread), @@ -116,7 +124,11 @@ PeerConnectionFactory::PeerConnectionFactory( media_engine_(std::move(media_engine)), call_factory_(std::move(call_factory)), event_log_factory_(std::move(event_log_factory)), - fec_controller_factory_(std::move(fec_controller_factory)) { + fec_controller_factory_(std::move(fec_controller_factory)), + injected_network_controller_factory_( + std::move(network_controller_factory)), + bbr_network_controller_factory_( + rtc::MakeUnique()) { if (!network_thread_) { owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); owned_network_thread_->SetName("pc_network_thread", nullptr); @@ -391,6 +403,18 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( call_config.fec_controller_factory = fec_controller_factory_.get(); + if (CongestionControllerExperiment::BbrControllerEnabled()) { + RTC_LOG(LS_INFO) << "Using BBR network controller factory"; + call_config.network_controller_factory = + bbr_network_controller_factory_.get(); + } else if (CongestionControllerExperiment::InjectedControllerEnabled()) { + RTC_LOG(LS_INFO) << "Using injected network controller factory"; + call_config.network_controller_factory = + injected_network_controller_factory_.get(); + } else { + RTC_LOG(LS_INFO) << "Using default network controller factory"; + } + return std::unique_ptr(call_factory_->CreateCall(call_config)); } diff --git a/pc/peerconnectionfactory.h b/pc/peerconnectionfactory.h index 6fb3c24f84..b566dd3e88 100644 --- a/pc/peerconnectionfactory.h +++ b/pc/peerconnectionfactory.h @@ -116,7 +116,9 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { std::unique_ptr media_engine, std::unique_ptr call_factory, std::unique_ptr event_log_factory, - std::unique_ptr fec_controller_factory); + std::unique_ptr fec_controller_factory, + std::unique_ptr + network_controller_factory); virtual ~PeerConnectionFactory(); private: @@ -137,6 +139,10 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { std::unique_ptr call_factory_; std::unique_ptr event_log_factory_; std::unique_ptr fec_controller_factory_; + std::unique_ptr + injected_network_controller_factory_; + std::unique_ptr + bbr_network_controller_factory_; }; } // namespace webrtc diff --git a/rtc_base/experiments/congestion_controller_experiment.cc b/rtc_base/experiments/congestion_controller_experiment.cc index 5733fea364..9fdaacdb49 100644 --- a/rtc_base/experiments/congestion_controller_experiment.cc +++ b/rtc_base/experiments/congestion_controller_experiment.cc @@ -16,21 +16,27 @@ namespace webrtc { namespace { -const char kBbrControllerExperiment[] = "WebRTC-BweCongestionController"; +const char kControllerExperiment[] = "WebRTC-BweCongestionController"; } // namespace bool CongestionControllerExperiment::BbrControllerEnabled() { std::string trial_string = - webrtc::field_trial::FindFullName(kBbrControllerExperiment); + webrtc::field_trial::FindFullName(kControllerExperiment); return trial_string.find("Enabled,BBR") == 0; } +bool CongestionControllerExperiment::InjectedControllerEnabled() { + std::string trial_string = + webrtc::field_trial::FindFullName(kControllerExperiment); + return trial_string.find("Enabled,Injected") == 0; +} + rtc::Optional CongestionControllerExperiment::GetBbrExperimentConfig() { if (!BbrControllerEnabled()) return rtc::nullopt; std::string trial_string = - webrtc::field_trial::FindFullName(kBbrControllerExperiment); + webrtc::field_trial::FindFullName(kControllerExperiment); BbrExperimentConfig config; if (sscanf( trial_string.c_str(), diff --git a/rtc_base/experiments/congestion_controller_experiment.h b/rtc_base/experiments/congestion_controller_experiment.h index 478d10612d..eba8926e58 100644 --- a/rtc_base/experiments/congestion_controller_experiment.h +++ b/rtc_base/experiments/congestion_controller_experiment.h @@ -33,6 +33,7 @@ class CongestionControllerExperiment { double probe_rtt_congestion_window_gain; }; static bool BbrControllerEnabled(); + static bool InjectedControllerEnabled(); static rtc::Optional GetBbrExperimentConfig(); }; diff --git a/test/call_test.cc b/test/call_test.cc index 725a17144f..c111b11fc3 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -178,7 +178,8 @@ void CallTest::CreateCalls(const Call::Config& sender_config, void CallTest::CreateSenderCall(const Call::Config& config) { std::unique_ptr controller_send = rtc::MakeUnique( - Clock::GetRealTimeClock(), config.event_log, config.bitrate_config); + Clock::GetRealTimeClock(), config.event_log, + config.network_controller_factory, config.bitrate_config); sender_call_transport_controller_ = controller_send.get(); sender_call_.reset(Call::Create(config, std::move(controller_send))); }