blob: 6d5650acc812d809e5646f637859d58dd201f4f9 [file] [log] [blame]
Åsa Perssonf8ba95e2018-11-02 11:38:46 +01001/*
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
11#include "rtc_base/experiments/cpu_speed_experiment.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stdio.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010015#include <string>
16
17#include "rtc_base/logging.h"
18#include "system_wrappers/include/field_trial.h"
19
20namespace webrtc {
21namespace {
22constexpr char kFieldTrial[] = "WebRTC-VP8-CpuSpeed-Arm";
23constexpr int kMinSetting = -16;
24constexpr int kMaxSetting = -1;
25} // namespace
26
27absl::optional<std::vector<CpuSpeedExperiment::Config>>
28CpuSpeedExperiment::GetConfigs() {
29 if (!webrtc::field_trial::IsEnabled(kFieldTrial))
30 return absl::nullopt;
31
32 const std::string group = webrtc::field_trial::FindFullName(kFieldTrial);
33 if (group.empty())
34 return absl::nullopt;
35
36 std::vector<Config> configs(3);
37 if (sscanf(group.c_str(), "Enabled-%d,%d,%d,%d,%d,%d", &(configs[0].pixels),
38 &(configs[0].cpu_speed), &(configs[1].pixels),
39 &(configs[1].cpu_speed), &(configs[2].pixels),
40 &(configs[2].cpu_speed)) != 6) {
41 RTC_LOG(LS_WARNING) << "Too few parameters provided.";
42 return absl::nullopt;
43 }
44
45 for (const auto& config : configs) {
46 if (config.cpu_speed < kMinSetting || config.cpu_speed > kMaxSetting) {
47 RTC_LOG(LS_WARNING) << "Unsupported cpu speed setting, value ignored.";
48 return absl::nullopt;
49 }
50 }
51
52 for (size_t i = 1; i < configs.size(); ++i) {
53 if (configs[i].pixels < configs[i - 1].pixels ||
54 configs[i].cpu_speed > configs[i - 1].cpu_speed) {
55 RTC_LOG(LS_WARNING) << "Invalid parameter value provided.";
56 return absl::nullopt;
57 }
58 }
59
60 return absl::optional<std::vector<Config>>(configs);
61}
62
63int CpuSpeedExperiment::GetValue(int pixels,
64 const std::vector<Config>& configs) {
65 for (const auto& config : configs) {
66 if (pixels <= config.pixels)
67 return config.cpu_speed;
68 }
69 return kMinSetting;
70}
71
72} // namespace webrtc