1 /*
2  *  Copyright 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "rtc_base/experiments/stable_target_rate_experiment.h"
12 
13 #include "api/transport/field_trial_based_config.h"
14 #include "rtc_base/experiments/rate_control_settings.h"
15 
16 namespace webrtc {
17 namespace {
18 constexpr char kFieldTrialName[] = "WebRTC-StableTargetRate";
19 }  // namespace
20 
StableTargetRateExperiment(const WebRtcKeyValueConfig * const key_value_config,double default_video_hysteresis,double default_screenshare_hysteresis)21 StableTargetRateExperiment::StableTargetRateExperiment(
22     const WebRtcKeyValueConfig* const key_value_config,
23     double default_video_hysteresis,
24     double default_screenshare_hysteresis)
25     : enabled_("enabled", false),
26       video_hysteresis_factor_("video_hysteresis_factor",
27                                default_video_hysteresis),
28       screenshare_hysteresis_factor_("screenshare_hysteresis_factor",
29                                      default_screenshare_hysteresis) {
30   ParseFieldTrial(
31       {&enabled_, &video_hysteresis_factor_, &screenshare_hysteresis_factor_},
32       key_value_config->Lookup(kFieldTrialName));
33 }
34 
35 StableTargetRateExperiment::StableTargetRateExperiment(
36     const StableTargetRateExperiment&) = default;
37 StableTargetRateExperiment::StableTargetRateExperiment(
38     StableTargetRateExperiment&&) = default;
39 
ParseFromFieldTrials()40 StableTargetRateExperiment StableTargetRateExperiment::ParseFromFieldTrials() {
41   FieldTrialBasedConfig config;
42   return ParseFromKeyValueConfig(&config);
43 }
44 
ParseFromKeyValueConfig(const WebRtcKeyValueConfig * const key_value_config)45 StableTargetRateExperiment StableTargetRateExperiment::ParseFromKeyValueConfig(
46     const WebRtcKeyValueConfig* const key_value_config) {
47   RateControlSettings rate_control =
48       RateControlSettings::ParseFromKeyValueConfig(key_value_config);
49   return StableTargetRateExperiment(
50       key_value_config,
51       rate_control.GetSimulcastHysteresisFactor(VideoCodecMode::kRealtimeVideo),
52       rate_control.GetSimulcastHysteresisFactor(
53           VideoCodecMode::kScreensharing));
54 }
55 
IsEnabled() const56 bool StableTargetRateExperiment::IsEnabled() const {
57   return enabled_.Get();
58 }
59 
GetVideoHysteresisFactor() const60 double StableTargetRateExperiment::GetVideoHysteresisFactor() const {
61   return video_hysteresis_factor_.Get();
62 }
63 
GetScreenshareHysteresisFactor() const64 double StableTargetRateExperiment::GetScreenshareHysteresisFactor() const {
65   return screenshare_hysteresis_factor_.Get();
66 }
67 
68 }  // namespace webrtc
69