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