1 /*
2  *  Copyright 2018 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 #include "rtc_base/experiments/rtt_mult_experiment.h"
11 
12 #include <stdio.h>
13 
14 #include <algorithm>
15 #include <string>
16 
17 #include "rtc_base/logging.h"
18 #include "system_wrappers/include/field_trial.h"
19 
20 namespace webrtc {
21 
22 namespace {
23 const char kRttMultExperiment[] = "WebRTC-RttMult";
24 const float max_rtt_mult_setting = 1.0;
25 const float min_rtt_mult_setting = 0.0;
26 const float max_rtt_mult_add_cap_ms = 2000.0;
27 const float min_rtt_mult_add_cap_ms = 0.0;
28 }  // namespace
29 
RttMultEnabled()30 bool RttMultExperiment::RttMultEnabled() {
31   return field_trial::IsEnabled(kRttMultExperiment);
32 }
33 
34 absl::optional<RttMultExperiment::Settings>
GetRttMultValue()35 RttMultExperiment::GetRttMultValue() {
36   if (!RttMultExperiment::RttMultEnabled())
37     return absl::nullopt;
38   const std::string group =
39       webrtc::field_trial::FindFullName(kRttMultExperiment);
40   if (group.empty()) {
41     RTC_LOG(LS_WARNING) << "Could not find rtt_mult_experiment.";
42     return absl::nullopt;
43   }
44 
45   Settings s;
46   if (sscanf(group.c_str(), "Enabled-%f,%f", &s.rtt_mult_setting,
47              &s.rtt_mult_add_cap_ms) != 2) {
48     RTC_LOG(LS_WARNING) << "Invalid number of parameters provided.";
49     return absl::nullopt;
50   }
51   // Bounds check rtt_mult_setting and rtt_mult_add_cap_ms values.
52   s.rtt_mult_setting = std::min(s.rtt_mult_setting, max_rtt_mult_setting);
53   s.rtt_mult_setting = std::max(s.rtt_mult_setting, min_rtt_mult_setting);
54   s.rtt_mult_add_cap_ms =
55       std::min(s.rtt_mult_add_cap_ms, max_rtt_mult_add_cap_ms);
56   s.rtt_mult_add_cap_ms =
57       std::max(s.rtt_mult_add_cap_ms, min_rtt_mult_add_cap_ms);
58   RTC_LOG(LS_INFO) << "rtt_mult experiment: rtt_mult value = "
59                    << s.rtt_mult_setting
60                    << " rtt_mult addition cap = " << s.rtt_mult_add_cap_ms
61                    << " ms.";
62   return s;
63 }
64 
65 }  // namespace webrtc
66