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