blob: 025c1ea8c9d4e2bbac49c8c0e8d68f80c720ede1 [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#ifndef RTC_BASE_EXPERIMENTS_CPU_SPEED_EXPERIMENT_H_
12#define RTC_BASE_EXPERIMENTS_CPU_SPEED_EXPERIMENT_H_
13
14#include <vector>
15
16#include "absl/types/optional.h"
17
Åsa Perssonceab7542020-09-21 14:57:04 +020018#include "rtc_base/experiments/field_trial_parser.h"
19
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010020namespace webrtc {
21
22class CpuSpeedExperiment {
23 public:
Åsa Persson869e9fb2020-07-28 12:49:49 +020024 CpuSpeedExperiment();
25 ~CpuSpeedExperiment();
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010026
Åsa Persson869e9fb2020-07-28 12:49:49 +020027 // Example:
28 // WebRTC-VP8-CpuSpeed-Arm/pixels:100|200|300,cpu_speed:-1|-2|-3/
29 // pixels <= 100 -> cpu speed: -1
30 // pixels <= 200 -> cpu speed: -2
31 // pixels <= 300 -> cpu speed: -3
32
Åsa Perssonceab7542020-09-21 14:57:04 +020033 // WebRTC-VP8-CpuSpeed-Arm/pixels:100|200|300,cpu_speed:-1|-2|-3/,
34 // cpu_speed_le_cores:-4|-5|-6,cores:3/
Artem Titov96e3b992021-07-26 16:03:14 +020035 // If `num_cores` > 3
Åsa Perssonceab7542020-09-21 14:57:04 +020036 // pixels <= 100 -> cpu speed: -1
37 // pixels <= 200 -> cpu speed: -2
38 // pixels <= 300 -> cpu speed: -3
39 // else
40 // pixels <= 100 -> cpu speed: -4
41 // pixels <= 200 -> cpu speed: -5
42 // pixels <= 300 -> cpu speed: -6
43
Åsa Persson869e9fb2020-07-28 12:49:49 +020044 struct Config {
45 int pixels = 0; // The video frame size.
Artem Titov96e3b992021-07-26 16:03:14 +020046 int cpu_speed = 0; // The `cpu_speed` to be used if the frame size is less
47 // than or equal to `pixels`.
Åsa Perssonceab7542020-09-21 14:57:04 +020048 // Optional.
Artem Titov96e3b992021-07-26 16:03:14 +020049 int cpu_speed_le_cores = 0; // Same as `cpu_speed` above but only used if
50 // `num_cores` <= `cores_`.
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010051 };
52
Artem Titov96e3b992021-07-26 16:03:14 +020053 // Gets the cpu speed based on `pixels` and `num_cores`.
Åsa Perssonceab7542020-09-21 14:57:04 +020054 absl::optional<int> GetValue(int pixels, int num_cores) const;
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010055
Åsa Persson869e9fb2020-07-28 12:49:49 +020056 private:
57 std::vector<Config> configs_;
Åsa Perssonceab7542020-09-21 14:57:04 +020058
Artem Titov96e3b992021-07-26 16:03:14 +020059 // Threshold for when to use `cpu_speed_le_cores`.
Åsa Perssonceab7542020-09-21 14:57:04 +020060 FieldTrialOptional<int> cores_;
Åsa Perssonf8ba95e2018-11-02 11:38:46 +010061};
62
63} // namespace webrtc
64
65#endif // RTC_BASE_EXPERIMENTS_CPU_SPEED_EXPERIMENT_H_