xref: /aosp_15_r20/external/webrtc/rtc_base/experiments/cpu_speed_experiment.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
18 #include "rtc_base/experiments/field_trial_parser.h"
19 
20 namespace webrtc {
21 
22 class CpuSpeedExperiment {
23  public:
24   CpuSpeedExperiment();
25   ~CpuSpeedExperiment();
26 
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 
33   // WebRTC-VP8-CpuSpeed-Arm/pixels:100|200|300,cpu_speed:-1|-2|-3/,
34   // cpu_speed_le_cores:-4|-5|-6,cores:3/
35   // If `num_cores` > 3
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 
44   struct Config {
45     int pixels = 0;     // The video frame size.
46     int cpu_speed = 0;  // The `cpu_speed` to be used if the frame size is less
47                         // than or equal to `pixels`.
48     // Optional.
49     int cpu_speed_le_cores = 0;  // Same as `cpu_speed` above but only used if
50                                  // `num_cores` <= `cores_`.
51   };
52 
53   // Gets the cpu speed based on `pixels` and `num_cores`.
54   absl::optional<int> GetValue(int pixels, int num_cores) const;
55 
56  private:
57   std::vector<Config> configs_;
58 
59   // Threshold for when to use `cpu_speed_le_cores`.
60   FieldTrialOptional<int> cores_;
61 };
62 
63 }  // namespace webrtc
64 
65 #endif  // RTC_BASE_EXPERIMENTS_CPU_SPEED_EXPERIMENT_H_
66