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