xref: /aosp_15_r20/external/webrtc/rtc_base/experiments/quality_rampup_experiment.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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_QUALITY_RAMPUP_EXPERIMENT_H_
12 #define RTC_BASE_EXPERIMENTS_QUALITY_RAMPUP_EXPERIMENT_H_
13 
14 #include "absl/types/optional.h"
15 #include "api/field_trials_view.h"
16 #include "rtc_base/experiments/field_trial_parser.h"
17 
18 namespace webrtc {
19 
20 class QualityRampupExperiment final {
21  public:
22   static QualityRampupExperiment ParseSettings();
23 
24   absl::optional<int> MinPixels() const;
25   absl::optional<int> MinDurationMs() const;
26   absl::optional<double> MaxBitrateFactor() const;
27 
28   // Sets the max bitrate and the frame size.
29   // The call has no effect if the frame size is less than `min_pixels_`.
30   void SetMaxBitrate(int pixels, uint32_t max_bitrate_kbps);
31 
32   // Returns true if the available bandwidth is a certain percentage
33   // (max_bitrate_factor_) above `max_bitrate_kbps_` for `min_duration_ms_`.
34   bool BwHigh(int64_t now_ms, uint32_t available_bw_kbps);
35 
36   void Reset();
37   bool Enabled() const;
38 
39  private:
40   explicit QualityRampupExperiment(
41       const FieldTrialsView* const key_value_config);
42 
43   FieldTrialOptional<int> min_pixels_;
44   FieldTrialOptional<int> min_duration_ms_;
45   FieldTrialOptional<double> max_bitrate_factor_;
46 
47   absl::optional<int64_t> start_ms_;
48   absl::optional<uint32_t> max_bitrate_kbps_;
49 };
50 
51 }  // namespace webrtc
52 
53 #endif  // RTC_BASE_EXPERIMENTS_QUALITY_RAMPUP_EXPERIMENT_H_
54