diff --git a/api/BUILD.gn b/api/BUILD.gn index 8bb4f24a16..6847a12905 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -188,6 +188,7 @@ rtc_library("libjingle_peerconnection_api") { "transport:datagram_transport_interface", "transport:enums", "transport:network_control", + "transport:webrtc_key_value_config", "transport/media:audio_interfaces", "transport/media:media_transport_interface", "transport/media:video_interfaces", diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index f2ef336742..5047eefea7 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -104,6 +104,7 @@ #include "api/transport/enums.h" #include "api/transport/media/media_transport_interface.h" #include "api/transport/network_control.h" +#include "api/transport/webrtc_key_value_config.h" #include "api/turn_customizer.h" #include "media/base/media_config.h" #include "media/base/media_engine.h" @@ -1329,6 +1330,7 @@ struct RTC_EXPORT PeerConnectionFactoryDependencies final { std::unique_ptr network_controller_factory; std::unique_ptr media_transport_factory; std::unique_ptr neteq_factory; + std::unique_ptr trials; }; // PeerConnectionFactoryInterface is the factory interface used for creating diff --git a/api/transport/BUILD.gn b/api/transport/BUILD.gn index 3710aa57e3..d9260c5518 100644 --- a/api/transport/BUILD.gn +++ b/api/transport/BUILD.gn @@ -54,6 +54,7 @@ rtc_source_set("webrtc_key_value_config") { "webrtc_key_value_config.h", ] deps = [ + "../../rtc_base/system:rtc_export", "//third_party/abseil-cpp/absl/strings", ] } diff --git a/api/transport/webrtc_key_value_config.h b/api/transport/webrtc_key_value_config.h index 0522629906..5666a82783 100644 --- a/api/transport/webrtc_key_value_config.h +++ b/api/transport/webrtc_key_value_config.h @@ -13,6 +13,7 @@ #include #include "absl/strings/string_view.h" +#include "rtc_base/system/rtc_export.h" namespace webrtc { @@ -21,7 +22,7 @@ namespace webrtc { // particular key value mapping will be preserved over time and no announcements // will be made if they are changed. It's up to the library user to ensure that // the behavior does not break. -class WebRtcKeyValueConfig { +class RTC_EXPORT WebRtcKeyValueConfig { public: virtual ~WebRtcKeyValueConfig() = default; // The configured value for the given key. Defaults to an empty string. diff --git a/audio/test/media_transport_test.cc b/audio/test/media_transport_test.cc index 134a37b173..bee0539fed 100644 --- a/audio/test/media_transport_test.cc +++ b/audio/test/media_transport_test.cc @@ -129,10 +129,11 @@ TEST(AudioWithMediaTransport, DeliversAudio) { send_config.encoder_factory = CreateAudioEncoderFactory(); std::unique_ptr send_process_thread = ProcessThread::Create("audio send thread"); + FieldTrialBasedConfig field_trials; RtpTransportControllerSend rtp_transport( Clock::GetRealTimeClock(), &null_event_log, nullptr, nullptr, BitrateConstraints(), ProcessThread::Create("Pacer"), - task_queue_factory.get()); + task_queue_factory.get(), &field_trials); webrtc::internal::AudioSendStream send_stream( Clock::GetRealTimeClock(), send_config, audio_state, task_queue_factory.get(), send_process_thread.get(), &rtp_transport, diff --git a/call/BUILD.gn b/call/BUILD.gn index 94bb6ceeeb..882ea147f7 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -46,6 +46,7 @@ rtc_library("call_interfaces") { "../api/task_queue", "../api/transport:bitrate_settings", "../api/transport:network_control", + "../api/transport:webrtc_key_value_config", "../api/transport/media:media_transport_interface", "../api/transport/rtp:rtp_source", "../modules/audio_device", diff --git a/call/call.cc b/call/call.cc index 4402f18e81..06ccd00550 100644 --- a/call/call.cc +++ b/call/call.cc @@ -415,7 +415,7 @@ Call* Call::Create(const Call::Config& config, std::make_unique( clock, config.event_log, config.network_state_predictor_factory, config.network_controller_factory, config.bitrate_config, - std::move(pacer_thread), config.task_queue_factory), + std::move(pacer_thread), config.task_queue_factory, config.trials), std::move(call_thread), config.task_queue_factory); } diff --git a/call/call_config.h b/call/call_config.h index 69d9e59e29..cd0ef3352e 100644 --- a/call/call_config.h +++ b/call/call_config.h @@ -17,6 +17,7 @@ #include "api/task_queue/task_queue_factory.h" #include "api/transport/bitrate_settings.h" #include "api/transport/network_control.h" +#include "api/transport/webrtc_key_value_config.h" #include "call/audio_state.h" namespace webrtc { @@ -60,6 +61,10 @@ struct CallConfig { // NetEq factory to use for this call. NetEqFactory* neteq_factory = nullptr; + + // Key-value mapping of internal configurations to apply, + // e.g. field trials. + const WebRtcKeyValueConfig* trials = nullptr; }; } // namespace webrtc diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc index d412dd5202..c7ccc927ed 100644 --- a/call/rtp_transport_controller_send.cc +++ b/call/rtp_transport_controller_send.cc @@ -25,7 +25,6 @@ #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/rate_limiter.h" -#include "system_wrappers/include/field_trial.h" namespace webrtc { namespace { @@ -55,6 +54,11 @@ TargetRateConstraints ConvertConstraints(const BitrateConstraints& contraints, contraints.max_bitrate_bps, contraints.start_bitrate_bps, clock); } + +bool IsEnabled(const WebRtcKeyValueConfig* trials, absl::string_view key) { + return trials && trials->Lookup(key).find("Enabled") == 0; +} + } // namespace RtpTransportControllerSend::RtpTransportControllerSend( @@ -64,12 +68,13 @@ RtpTransportControllerSend::RtpTransportControllerSend( NetworkControllerFactoryInterface* controller_factory, const BitrateConstraints& bitrate_config, std::unique_ptr process_thread, - TaskQueueFactory* task_queue_factory) + TaskQueueFactory* task_queue_factory, + const WebRtcKeyValueConfig* trials) : clock_(clock), event_log_(event_log), bitrate_configurator_(bitrate_config), process_thread_(std::move(process_thread)), - pacer_(clock, &packet_router_, event_log, nullptr, process_thread_.get()), + pacer_(clock, &packet_router_, event_log, trials, process_thread_.get()), observer_(nullptr), controller_factory_override_(controller_factory), controller_factory_fallback_( @@ -77,11 +82,11 @@ RtpTransportControllerSend::RtpTransportControllerSend( process_interval_(controller_factory_fallback_->GetProcessInterval()), last_report_block_time_(Timestamp::ms(clock_->TimeInMilliseconds())), reset_feedback_on_route_change_( - !field_trial::IsEnabled("WebRTC-Bwe-NoFeedbackReset")), + !IsEnabled(trials, "WebRTC-Bwe-NoFeedbackReset")), send_side_bwe_with_overhead_( - webrtc::field_trial::IsEnabled("WebRTC-SendSideBwe-WithOverhead")), + IsEnabled(trials, "WebRTC-SendSideBwe-WithOverhead")), add_pacing_to_cwin_( - field_trial::IsEnabled("WebRTC-AddPacingToCongestionWindowPushback")), + IsEnabled(trials, "WebRTC-AddPacingToCongestionWindowPushback")), transport_overhead_bytes_per_packet_(0), network_available_(false), retransmission_rate_limiter_(clock, kRetransmitWindowSizeMs), diff --git a/call/rtp_transport_controller_send.h b/call/rtp_transport_controller_send.h index 82a8492466..2cadaa3d8f 100644 --- a/call/rtp_transport_controller_send.h +++ b/call/rtp_transport_controller_send.h @@ -54,7 +54,8 @@ class RtpTransportControllerSend final NetworkControllerFactoryInterface* controller_factory, const BitrateConstraints& bitrate_config, std::unique_ptr process_thread, - TaskQueueFactory* task_queue_factory); + TaskQueueFactory* task_queue_factory, + const WebRtcKeyValueConfig* trials); ~RtpTransportControllerSend() override; RtpVideoSenderInterface* CreateRtpVideoSender( diff --git a/call/rtp_video_sender_unittest.cc b/call/rtp_video_sender_unittest.cc index 7df3a474b5..d453f45211 100644 --- a/call/rtp_video_sender_unittest.cc +++ b/call/rtp_video_sender_unittest.cc @@ -128,7 +128,8 @@ class RtpVideoSenderTestFixture { nullptr, bitrate_config_, ProcessThread::Create("PacerThread"), - task_queue_factory_.get()), + task_queue_factory_.get(), + &field_trials_), process_thread_(ProcessThread::Create("test_thread")), call_stats_(&clock_, process_thread_.get()), stats_proxy_(&clock_, @@ -171,6 +172,7 @@ class RtpVideoSenderTestFixture { SendDelayStats send_delay_stats_; BitrateConstraints bitrate_config_; const std::unique_ptr task_queue_factory_; + const FieldTrialBasedConfig field_trials_; RtpTransportControllerSend transport_controller_; std::unique_ptr process_thread_; CallStats call_stats_; diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 40f3b502f7..19994ebca2 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -241,6 +241,7 @@ rtc_library("peerconnection") { "../api/rtc_event_log", "../api/task_queue", "../api/transport:datagram_transport_interface", + "../api/transport:field_trial_based_config", "../api/transport/media:media_transport_interface", "../api/units:data_rate", "../api/video:builtin_video_bitrate_allocator_factory", diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index 8909ba9bd3..1e9c24e977 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -21,6 +21,7 @@ #include "api/peer_connection_factory_proxy.h" #include "api/peer_connection_proxy.h" #include "api/rtc_event_log/rtc_event_log.h" +#include "api/transport/field_trial_based_config.h" #include "api/transport/media/media_transport_interface.h" #include "api/turn_customizer.h" #include "api/units/data_rate.h" @@ -42,7 +43,6 @@ #include "rtc_base/experiments/field_trial_units.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/system/file_wrapper.h" -#include "system_wrappers/include/field_trial.h" namespace webrtc { @@ -81,7 +81,9 @@ PeerConnectionFactory::PeerConnectionFactory( injected_network_controller_factory_( std::move(dependencies.network_controller_factory)), media_transport_factory_(std::move(dependencies.media_transport_factory)), - neteq_factory_(std::move(dependencies.neteq_factory)) { + neteq_factory_(std::move(dependencies.neteq_factory)), + trials_(dependencies.trials ? std::move(dependencies.trials) + : std::make_unique()) { if (!network_thread_) { owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); owned_network_thread_->SetName("pc_network_thread", nullptr); @@ -342,7 +344,7 @@ std::unique_ptr PeerConnectionFactory::CreateRtcEventLog_w() { RTC_DCHECK_RUN_ON(worker_thread_); auto encoding_type = RtcEventLog::EncodingType::Legacy; - if (field_trial::IsEnabled("WebRTC-RtcEventLogNewFormat")) + if (IsTrialEnabled("WebRTC-RtcEventLogNewFormat")) encoding_type = RtcEventLog::EncodingType::NewFormat; return event_log_factory_ ? event_log_factory_->CreateRtcEventLog(encoding_type) @@ -364,7 +366,7 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( FieldTrialParameter start_bandwidth("start", DataRate::kbps(300)); FieldTrialParameter max_bandwidth("max", DataRate::kbps(2000)); ParseFieldTrial({&min_bandwidth, &start_bandwidth, &max_bandwidth}, - field_trial::FindFullName("WebRTC-PcFactoryDefaultBitrates")); + trials_->Lookup("WebRTC-PcFactoryDefaultBitrates")); call_config.bitrate_config.min_bitrate_bps = rtc::saturated_cast(min_bandwidth->bps()); @@ -379,7 +381,7 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( network_state_predictor_factory_.get(); call_config.neteq_factory = neteq_factory_.get(); - if (field_trial::IsEnabled("WebRTC-Bwe-InjectedCongestionController")) { + if (IsTrialEnabled("WebRTC-Bwe-InjectedCongestionController")) { RTC_LOG(LS_INFO) << "Using injected network controller factory"; call_config.network_controller_factory = injected_network_controller_factory_.get(); @@ -387,7 +389,14 @@ std::unique_ptr PeerConnectionFactory::CreateCall_w( RTC_LOG(LS_INFO) << "Using default network controller factory"; } + call_config.trials = trials_.get(); + return std::unique_ptr(call_factory_->CreateCall(call_config)); } +bool PeerConnectionFactory::IsTrialEnabled(absl::string_view key) const { + RTC_DCHECK(trials_); + return trials_->Lookup(key).find("Enabled") == 0; +} + } // namespace webrtc diff --git a/pc/peer_connection_factory.h b/pc/peer_connection_factory.h index 5886dee8b3..962b08c7c9 100644 --- a/pc/peer_connection_factory.h +++ b/pc/peer_connection_factory.h @@ -104,6 +104,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { virtual ~PeerConnectionFactory(); private: + bool IsTrialEnabled(absl::string_view key) const; + std::unique_ptr CreateRtcEventLog_w(); std::unique_ptr CreateCall_w(RtcEventLog* event_log); @@ -128,6 +130,7 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { injected_network_controller_factory_; std::unique_ptr media_transport_factory_; std::unique_ptr neteq_factory_; + const std::unique_ptr trials_; }; } // namespace webrtc