“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | #include <stdio.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 13 | |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 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; |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 26 | const float max_rtt_mult_add_cap_ms = 2000.0; |
| 27 | const float min_rtt_mult_add_cap_ms = 0.0; |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 28 | } // namespace |
| 29 | |
| 30 | bool RttMultExperiment::RttMultEnabled() { |
| 31 | return field_trial::IsEnabled(kRttMultExperiment); |
| 32 | } |
| 33 | |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 34 | absl::optional<RttMultExperiment::Settings> |
| 35 | RttMultExperiment::GetRttMultValue() { |
| 36 | if (!RttMultExperiment::RttMultEnabled()) |
| 37 | return absl::nullopt; |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 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."; |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 42 | return absl::nullopt; |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 43 | } |
| 44 | |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 45 | Settings s; |
| 46 | if (sscanf(group.c_str(), "Enabled-%f,%f", &s.rtt_mult_setting, |
| 47 | &s.rtt_mult_add_cap_ms) != 2) { |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 48 | RTC_LOG(LS_WARNING) << "Invalid number of parameters provided."; |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 49 | return absl::nullopt; |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 50 | } |
“Michael | d3a4ebe | 2019-06-07 03:55:01 -0500 | [diff] [blame] | 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; |
“Michael | f9fc171 | 2018-08-27 10:08:58 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace webrtc |