diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index 0a8e9d0824..f65715b93f 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -292,6 +292,7 @@ rtc_source_set("video_coding_utility") { "../../rtc_base:rtc_task_queue", "../../rtc_base:sequenced_task_checker", "../../rtc_base/experiments:quality_scaling_experiment", + "../../rtc_base/experiments:rate_control_settings", "../../rtc_base/system:arch", "../../rtc_base/task_utils:repeating_task", "../../system_wrappers", diff --git a/modules/video_coding/utility/simulcast_rate_allocator.cc b/modules/video_coding/utility/simulcast_rate_allocator.cc index 873f94f3d8..b6edfd1b9b 100644 --- a/modules/video_coding/utility/simulcast_rate_allocator.cc +++ b/modules/video_coding/utility/simulcast_rate_allocator.cc @@ -20,6 +20,7 @@ #include "common_types.h" // NOLINT(build/include) #include "rtc_base/checks.h" +#include "rtc_base/experiments/rate_control_settings.h" #include "system_wrappers/include/field_trial.h" namespace webrtc { @@ -40,33 +41,6 @@ static const float kBaseHeavy3TlRateAllocation[kMaxTemporalStreams] = { const uint32_t kLegacyScreenshareTl0BitrateKbps = 200; const uint32_t kLegacyScreenshareTl1BitrateKbps = 1000; - -double GetHysteresisFactor(const VideoCodec& codec) { - double factor = 1.0; - - std::string field_trial_name; - switch (codec.mode) { - case VideoCodecMode::kRealtimeVideo: - field_trial_name = "WebRTC-SimulcastUpswitchHysteresisPercent"; - // Default to no hysteresis for simulcast video. - factor = 1.0; - break; - case VideoCodecMode::kScreensharing: - field_trial_name = "WebRTC-SimulcastScreenshareUpswitchHysteresisPercent"; - // Default to 35% hysteresis for simulcast screenshare. - factor = 1.35; - break; - } - - std::string group_name = webrtc::field_trial::FindFullName(field_trial_name); - int percent = 0; - if (!group_name.empty() && sscanf(group_name.c_str(), "%d", &percent) == 1 && - percent >= 0) { - factor = 1.0 + (percent / 100.0); - } - - return factor; -} } // namespace float SimulcastRateAllocator::GetTemporalRateAllocation(int num_layers, @@ -83,7 +57,12 @@ float SimulcastRateAllocator::GetTemporalRateAllocation(int num_layers, } SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec) - : codec_(codec), hysteresis_factor_(GetHysteresisFactor(codec)) {} + : codec_(codec), + hysteresis_factor_(codec.mode == VideoCodecMode::kScreensharing + ? RateControlSettings::ParseFromFieldTrials() + .GetSimulcastScreenshareHysteresisFactor() + : RateControlSettings::ParseFromFieldTrials() + .GetSimulcastVideoHysteresisFactor()) {} SimulcastRateAllocator::~SimulcastRateAllocator() = default; diff --git a/rtc_base/experiments/rate_control_settings.cc b/rtc_base/experiments/rate_control_settings.cc index 317eb90640..6192a15b27 100644 --- a/rtc_base/experiments/rate_control_settings.cc +++ b/rtc_base/experiments/rate_control_settings.cc @@ -35,6 +35,14 @@ const char kVp8TrustedRateControllerFieldTrialName[] = const char kVp9TrustedRateControllerFieldTrialName[] = "WebRTC-LibvpxVp9TrustedRateController"; +const char* kVideoHysteresisFieldTrialname = + "WebRTC-SimulcastUpswitchHysteresisPercent"; +const double kDefaultVideoHysteresisFactor = 1.0; +const char* kScreenshareHysteresisFieldTrialname = + "WebRTC-SimulcastScreenshareUpswitchHysteresisPercent"; +// Default to 35% hysteresis for simulcast screenshare. +const double kDefaultScreenshareHysteresisFactor = 1.35; + absl::optional MaybeReadCwndExperimentParameter( const WebRtcKeyValueConfig* const key_value_config) { int64_t accepted_queue_ms; @@ -74,6 +82,18 @@ bool IsEnabled(const WebRtcKeyValueConfig* const key_value_config, return key_value_config->Lookup(key).find("Enabled") == 0; } +double ParseHysteresisFactor(const WebRtcKeyValueConfig* const key_value_config, + absl::string_view key, + double default_value) { + std::string group_name = key_value_config->Lookup(key); + int percent = 0; + if (!group_name.empty() && sscanf(group_name.c_str(), "%d", &percent) == 1 && + percent >= 0) { + return 1.0 + (percent / 100.0); + } + return default_value; +} + } // namespace RateControlSettings::RateControlSettings( @@ -89,11 +109,21 @@ RateControlSettings::RateControlSettings( trust_vp8_( "trust_vp8", IsEnabled(key_value_config, kVp8TrustedRateControllerFieldTrialName)), - trust_vp9_("trust_vp9", - IsEnabled(key_value_config, - kVp9TrustedRateControllerFieldTrialName)) { + trust_vp9_( + "trust_vp9", + IsEnabled(key_value_config, kVp9TrustedRateControllerFieldTrialName)), + video_hysteresis_("video_hysteresis", + ParseHysteresisFactor(key_value_config, + kVideoHysteresisFieldTrialname, + kDefaultVideoHysteresisFactor)), + screenshare_hysteresis_( + "screenshare_hysteresis", + ParseHysteresisFactor(key_value_config, + kScreenshareHysteresisFieldTrialname, + kDefaultScreenshareHysteresisFactor)) { ParseFieldTrial({&congestion_window_, &congestion_window_pushback_, - &pacing_factor_, &alr_probing_, &trust_vp8_, &trust_vp9_}, + &pacing_factor_, &alr_probing_, &trust_vp8_, &trust_vp9_, + &video_hysteresis_, &screenshare_hysteresis_}, key_value_config->Lookup("WebRTC-VideoRateControl")); } @@ -146,4 +176,12 @@ bool RateControlSettings::LibvpxVp9TrustedRateController() const { return trust_vp9_.Get(); } +double RateControlSettings::GetSimulcastVideoHysteresisFactor() const { + return video_hysteresis_.Get(); +} + +double RateControlSettings::GetSimulcastScreenshareHysteresisFactor() const { + return screenshare_hysteresis_.Get(); +} + } // namespace webrtc diff --git a/rtc_base/experiments/rate_control_settings.h b/rtc_base/experiments/rate_control_settings.h index 7662b08a72..ff071d8fde 100644 --- a/rtc_base/experiments/rate_control_settings.h +++ b/rtc_base/experiments/rate_control_settings.h @@ -41,6 +41,9 @@ class RateControlSettings final { bool LibvpxVp8TrustedRateController() const; bool LibvpxVp9TrustedRateController() const; + double GetSimulcastVideoHysteresisFactor() const; + double GetSimulcastScreenshareHysteresisFactor() const; + private: explicit RateControlSettings( const WebRtcKeyValueConfig* const key_value_config); @@ -51,6 +54,8 @@ class RateControlSettings final { FieldTrialParameter alr_probing_; FieldTrialParameter trust_vp8_; FieldTrialParameter trust_vp9_; + FieldTrialParameter video_hysteresis_; + FieldTrialParameter screenshare_hysteresis_; }; } // namespace webrtc