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 #ifndef RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_
11 #define RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_
12 
13 #include "absl/types/optional.h"
14 #include "api/video_codecs/video_encoder.h"
15 
16 namespace webrtc {
17 class QualityScalingExperiment {
18  public:
19   struct Settings {
20     int vp8_low;       // VP8: low QP threshold.
21     int vp8_high;      // VP8: high QP threshold.
22     int vp9_low;       // VP9: low QP threshold.
23     int vp9_high;      // VP9: high QP threshold.
24     int h264_low;      // H264: low QP threshold.
25     int h264_high;     // H264: high QP threshold.
26     int generic_low;   // Generic: low QP threshold.
27     int generic_high;  // Generic: high QP threshold.
28     float alpha_high;  // |alpha_| for ExpFilter used when checking high QP.
29     float alpha_low;   // |alpha_| for ExpFilter used when checking low QP.
30     int drop;          // >0 sets |use_all_drop_reasons| to true.
31   };
32 
33   // Used by QualityScaler.
34   struct Config {
35     float alpha_high = 0.9995f;
36     float alpha_low = 0.9999f;
37     // If set, all type of dropped frames are used.
38     // Otherwise only dropped frames by MediaOptimization are used.
39     bool use_all_drop_reasons = false;
40   };
41 
42   // Returns true if the experiment is enabled.
43   static bool Enabled();
44 
45   // Returns settings from field trial.
46   static absl::optional<Settings> ParseSettings();
47 
48   // Returns QpThresholds for the |codec_type|.
49   static absl::optional<VideoEncoder::QpThresholds> GetQpThresholds(
50       VideoCodecType codec_type);
51 
52   // Returns parsed values. If the parsing fails, default values are returned.
53   static Config GetConfig();
54 };
55 
56 }  // namespace webrtc
57 
58 #endif  // RTC_BASE_EXPERIMENTS_QUALITY_SCALING_EXPERIMENT_H_
59