blob: 15a3438361076e986e6bfcd38438230794fcd065 [file] [log] [blame]
Sebastian Janssoncabe3832018-01-12 10:54:18 +01001/*
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
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <inttypes.h>
14#include <stdio.h>
Sebastian Janssoncabe3832018-01-12 10:54:18 +010015#include <string>
16
Sebastian Janssoncabe3832018-01-12 10:54:18 +010017#include "rtc_base/logging.h"
18#include "system_wrappers/include/field_trial.h"
19
20namespace webrtc {
21
22const char AlrExperimentSettings::kScreenshareProbingBweExperimentName[] =
23 "WebRTC-ProbingScreenshareBwe";
24const char AlrExperimentSettings::kStrictPacingAndProbingExperimentName[] =
25 "WebRTC-StrictPacingAndProbing";
26const char kDefaultProbingScreenshareBweSettings[] = "1.0,2875,80,40,-60,3";
27
28bool AlrExperimentSettings::MaxOneFieldTrialEnabled() {
29 return field_trial::FindFullName(kStrictPacingAndProbingExperimentName)
30 .empty() ||
31 field_trial::FindFullName(kScreenshareProbingBweExperimentName)
32 .empty();
33}
34
Danil Chapovalov0a1d1892018-06-21 11:48:25 +020035absl::optional<AlrExperimentSettings>
Sebastian Janssoncabe3832018-01-12 10:54:18 +010036AlrExperimentSettings::CreateFromFieldTrial(const char* experiment_name) {
Danil Chapovalov0a1d1892018-06-21 11:48:25 +020037 absl::optional<AlrExperimentSettings> ret;
Sebastian Janssoncabe3832018-01-12 10:54:18 +010038 std::string group_name = field_trial::FindFullName(experiment_name);
39
40 const std::string kIgnoredSuffix = "_Dogfood";
41 std::string::size_type suffix_pos = group_name.rfind(kIgnoredSuffix);
42 if (suffix_pos != std::string::npos &&
43 suffix_pos == group_name.length() - kIgnoredSuffix.length()) {
44 group_name.resize(group_name.length() - kIgnoredSuffix.length());
45 }
46
Erik Språng1c1b1ea2019-04-03 20:20:42 +020047 if (group_name.empty()) {
48 if (experiment_name == kScreenshareProbingBweExperimentName) {
49 // This experiment is now default-on with fixed settings.
50 // TODO(sprang): Remove this kill-switch and clean up experiment code.
Sebastian Janssoncabe3832018-01-12 10:54:18 +010051 group_name = kDefaultProbingScreenshareBweSettings;
Erik Språng1c1b1ea2019-04-03 20:20:42 +020052 } else {
53 return ret;
Sebastian Janssoncabe3832018-01-12 10:54:18 +010054 }
55 }
56
Sebastian Janssoncabe3832018-01-12 10:54:18 +010057 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