Sebastian Jansson | cabe383 | 2018-01-12 10:54:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 | |
| 11 | #include "rtc_base/experiments/alr_experiment.h" |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | #include "rtc_base/format_macros.h" |
| 16 | #include "rtc_base/logging.h" |
| 17 | #include "system_wrappers/include/field_trial.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | const char AlrExperimentSettings::kScreenshareProbingBweExperimentName[] = |
| 22 | "WebRTC-ProbingScreenshareBwe"; |
| 23 | const char AlrExperimentSettings::kStrictPacingAndProbingExperimentName[] = |
| 24 | "WebRTC-StrictPacingAndProbing"; |
| 25 | const char kDefaultProbingScreenshareBweSettings[] = "1.0,2875,80,40,-60,3"; |
| 26 | |
| 27 | bool AlrExperimentSettings::MaxOneFieldTrialEnabled() { |
| 28 | return field_trial::FindFullName(kStrictPacingAndProbingExperimentName) |
| 29 | .empty() || |
| 30 | field_trial::FindFullName(kScreenshareProbingBweExperimentName) |
| 31 | .empty(); |
| 32 | } |
| 33 | |
| 34 | rtc::Optional<AlrExperimentSettings> |
| 35 | AlrExperimentSettings::CreateFromFieldTrial(const char* experiment_name) { |
| 36 | rtc::Optional<AlrExperimentSettings> ret; |
| 37 | std::string group_name = field_trial::FindFullName(experiment_name); |
| 38 | |
| 39 | const std::string kIgnoredSuffix = "_Dogfood"; |
| 40 | std::string::size_type suffix_pos = group_name.rfind(kIgnoredSuffix); |
| 41 | if (suffix_pos != std::string::npos && |
| 42 | suffix_pos == group_name.length() - kIgnoredSuffix.length()) { |
| 43 | group_name.resize(group_name.length() - kIgnoredSuffix.length()); |
| 44 | } |
| 45 | |
| 46 | if (experiment_name == kScreenshareProbingBweExperimentName) { |
| 47 | // This experiment is now default-on with fixed settings. |
| 48 | // TODO(sprang): Remove this kill-switch and clean up experiment code. |
| 49 | if (group_name != "Disabled") { |
| 50 | group_name = kDefaultProbingScreenshareBweSettings; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (group_name.empty()) |
| 55 | return ret; |
| 56 | |
| 57 | AlrExperimentSettings settings; |
| 58 | if (sscanf(group_name.c_str(), "%f,%" PRId64 ",%d,%d,%d,%d", |
| 59 | &settings.pacing_factor, &settings.max_paced_queue_time, |
| 60 | &settings.alr_bandwidth_usage_percent, |
| 61 | &settings.alr_start_budget_level_percent, |
| 62 | &settings.alr_stop_budget_level_percent, |
| 63 | &settings.group_id) == 6) { |
| 64 | ret.emplace(settings); |
| 65 | RTC_LOG(LS_INFO) << "Using ALR experiment settings: " |
| 66 | "pacing factor: " |
| 67 | << settings.pacing_factor << ", max pacer queue length: " |
| 68 | << settings.max_paced_queue_time |
| 69 | << ", ALR start bandwidth usage percent: " |
| 70 | << settings.alr_bandwidth_usage_percent |
| 71 | << ", ALR end budget level percent: " |
| 72 | << settings.alr_start_budget_level_percent |
| 73 | << ", ALR end budget level percent: " |
| 74 | << settings.alr_stop_budget_level_percent |
| 75 | << ", ALR experiment group ID: " << settings.group_id; |
| 76 | } else { |
| 77 | RTC_LOG(LS_INFO) << "Failed to parse ALR experiment: " << experiment_name; |
| 78 | } |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | } // namespace webrtc |