Å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 | #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 Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 18 | #include "rtc_base/experiments/field_trial_parser.h" |
| 19 | |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | |
| 22 | class CpuSpeedExperiment { |
| 23 | public: |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 24 | CpuSpeedExperiment(); |
| 25 | ~CpuSpeedExperiment(); |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 26 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 27 | // 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 Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 33 | // WebRTC-VP8-CpuSpeed-Arm/pixels:100|200|300,cpu_speed:-1|-2|-3/, |
| 34 | // cpu_speed_le_cores:-4|-5|-6,cores:3/ |
Artem Titov | 96e3b99 | 2021-07-26 16:03:14 +0200 | [diff] [blame] | 35 | // If `num_cores` > 3 |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 36 | // 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 Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 44 | struct Config { |
| 45 | int pixels = 0; // The video frame size. |
Artem Titov | 96e3b99 | 2021-07-26 16:03:14 +0200 | [diff] [blame] | 46 | int cpu_speed = 0; // The `cpu_speed` to be used if the frame size is less |
| 47 | // than or equal to `pixels`. |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 48 | // Optional. |
Artem Titov | 96e3b99 | 2021-07-26 16:03:14 +0200 | [diff] [blame] | 49 | int cpu_speed_le_cores = 0; // Same as `cpu_speed` above but only used if |
| 50 | // `num_cores` <= `cores_`. |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Artem Titov | 96e3b99 | 2021-07-26 16:03:14 +0200 | [diff] [blame] | 53 | // Gets the cpu speed based on `pixels` and `num_cores`. |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 54 | absl::optional<int> GetValue(int pixels, int num_cores) const; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 55 | |
Åsa Persson | 869e9fb | 2020-07-28 12:49:49 +0200 | [diff] [blame] | 56 | private: |
| 57 | std::vector<Config> configs_; |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 58 | |
Artem Titov | 96e3b99 | 2021-07-26 16:03:14 +0200 | [diff] [blame] | 59 | // Threshold for when to use `cpu_speed_le_cores`. |
Åsa Persson | ceab754 | 2020-09-21 14:57:04 +0200 | [diff] [blame] | 60 | FieldTrialOptional<int> cores_; |
Åsa Persson | f8ba95e | 2018-11-02 11:38:46 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace webrtc |
| 64 | |
| 65 | #endif // RTC_BASE_EXPERIMENTS_CPU_SPEED_EXPERIMENT_H_ |