xref: /aosp_15_r20/external/webrtc/rtc_base/experiments/encoder_info_settings.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2021 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_ENCODER_INFO_SETTINGS_H_
12 #define RTC_BASE_EXPERIMENTS_ENCODER_INFO_SETTINGS_H_
13 
14 #include <string>
15 #include <vector>
16 
17 #include "absl/strings/string_view.h"
18 #include "absl/types/optional.h"
19 #include "api/video_codecs/video_encoder.h"
20 #include "rtc_base/experiments/field_trial_parser.h"
21 
22 namespace webrtc {
23 
24 class EncoderInfoSettings {
25  public:
26   virtual ~EncoderInfoSettings();
27 
28   // Bitrate limits per resolution.
29   struct BitrateLimit {
30     int frame_size_pixels = 0;      // The video frame size.
31     int min_start_bitrate_bps = 0;  // The minimum bitrate to start encoding.
32     int min_bitrate_bps = 0;        // The minimum bitrate.
33     int max_bitrate_bps = 0;        // The maximum bitrate.
34   };
35 
36   absl::optional<int> requested_resolution_alignment() const;
apply_alignment_to_all_simulcast_layers()37   bool apply_alignment_to_all_simulcast_layers() const {
38     return apply_alignment_to_all_simulcast_layers_.Get();
39   }
resolution_bitrate_limits()40   std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits()
41       const {
42     return resolution_bitrate_limits_;
43   }
44 
45   static std::vector<VideoEncoder::ResolutionBitrateLimits>
46   GetDefaultSinglecastBitrateLimits(VideoCodecType codec_type);
47 
48   static absl::optional<VideoEncoder::ResolutionBitrateLimits>
49   GetDefaultSinglecastBitrateLimitsForResolution(VideoCodecType codec_type,
50                                                  int frame_size_pixels);
51 
52   static std::vector<VideoEncoder::ResolutionBitrateLimits>
53   GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted();
54 
55   static absl::optional<VideoEncoder::ResolutionBitrateLimits>
56   GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
57       absl::optional<int> frame_size_pixels,
58       const std::vector<VideoEncoder::ResolutionBitrateLimits>&
59           resolution_bitrate_limits);
60 
61  protected:
62   explicit EncoderInfoSettings(absl::string_view name);
63 
64  private:
65   FieldTrialOptional<int> requested_resolution_alignment_;
66   FieldTrialFlag apply_alignment_to_all_simulcast_layers_;
67   std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits_;
68 };
69 
70 // EncoderInfo settings for SimulcastEncoderAdapter.
71 class SimulcastEncoderAdapterEncoderInfoSettings : public EncoderInfoSettings {
72  public:
73   SimulcastEncoderAdapterEncoderInfoSettings();
~SimulcastEncoderAdapterEncoderInfoSettings()74   ~SimulcastEncoderAdapterEncoderInfoSettings() override {}
75 };
76 
77 // EncoderInfo settings for LibvpxVp8Encoder.
78 class LibvpxVp8EncoderInfoSettings : public EncoderInfoSettings {
79  public:
80   LibvpxVp8EncoderInfoSettings();
~LibvpxVp8EncoderInfoSettings()81   ~LibvpxVp8EncoderInfoSettings() override {}
82 };
83 
84 // EncoderInfo settings for LibvpxVp9Encoder.
85 class LibvpxVp9EncoderInfoSettings : public EncoderInfoSettings {
86  public:
87   LibvpxVp9EncoderInfoSettings();
~LibvpxVp9EncoderInfoSettings()88   ~LibvpxVp9EncoderInfoSettings() override {}
89 };
90 
91 }  // namespace webrtc
92 
93 #endif  // RTC_BASE_EXPERIMENTS_ENCODER_INFO_SETTINGS_H_
94