xref: /aosp_15_r20/external/webrtc/video/adaptation/quality_rampup_experiment_helper.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2020 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 VIDEO_ADAPTATION_QUALITY_RAMPUP_EXPERIMENT_HELPER_H_
12 #define VIDEO_ADAPTATION_QUALITY_RAMPUP_EXPERIMENT_HELPER_H_
13 
14 #include <memory>
15 
16 #include "api/scoped_refptr.h"
17 #include "api/units/data_rate.h"
18 #include "rtc_base/experiments/quality_rampup_experiment.h"
19 #include "system_wrappers/include/clock.h"
20 #include "video/adaptation/quality_scaler_resource.h"
21 
22 namespace webrtc {
23 
24 class QualityRampUpExperimentListener {
25  public:
26   virtual ~QualityRampUpExperimentListener() = default;
27   virtual void OnQualityRampUp() = 0;
28 };
29 
30 // Helper class for orchestrating the WebRTC-Video-QualityRampupSettings
31 // experiment.
32 class QualityRampUpExperimentHelper {
33  public:
34   // Returns a QualityRampUpExperimentHelper if the experiment is enabled,
35   // an nullptr otherwise.
36   static std::unique_ptr<QualityRampUpExperimentHelper> CreateIfEnabled(
37       QualityRampUpExperimentListener* experiment_listener,
38       Clock* clock);
39 
40   QualityRampUpExperimentHelper(const QualityRampUpExperimentHelper&) = delete;
41   QualityRampUpExperimentHelper& operator=(
42       const QualityRampUpExperimentHelper&) = delete;
43 
44   void cpu_adapted(bool cpu_adapted);
45   void qp_resolution_adaptations(int qp_adaptations);
46 
47   void ConfigureQualityRampupExperiment(bool reset,
48                                         absl::optional<uint32_t> pixels,
49                                         absl::optional<DataRate> max_bitrate);
50 
51   void PerformQualityRampupExperiment(
52       rtc::scoped_refptr<QualityScalerResource> quality_scaler_resource,
53       DataRate bandwidth,
54       DataRate encoder_target_bitrate,
55       absl::optional<DataRate> max_bitrate);
56 
57  private:
58   QualityRampUpExperimentHelper(
59       QualityRampUpExperimentListener* experiment_listener,
60       Clock* clock,
61       QualityRampupExperiment experiment);
62   QualityRampUpExperimentListener* const experiment_listener_;
63   Clock* clock_;
64   QualityRampupExperiment quality_rampup_experiment_;
65   bool cpu_adapted_;
66   int qp_resolution_adaptations_;
67 };
68 
69 }  // namespace webrtc
70 
71 #endif  // VIDEO_ADAPTATION_QUALITY_RAMPUP_EXPERIMENT_HELPER_H_
72