xref: /aosp_15_r20/external/webrtc/video/adaptation/bitrate_constraint.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_BITRATE_CONSTRAINT_H_
12 #define VIDEO_ADAPTATION_BITRATE_CONSTRAINT_H_
13 
14 #include <string>
15 
16 #include "absl/types/optional.h"
17 #include "api/sequence_checker.h"
18 #include "call/adaptation/adaptation_constraint.h"
19 #include "call/adaptation/encoder_settings.h"
20 #include "call/adaptation/video_source_restrictions.h"
21 #include "call/adaptation/video_stream_input_state.h"
22 #include "rtc_base/system/no_unique_address.h"
23 
24 namespace webrtc {
25 
26 class BitrateConstraint : public AdaptationConstraint {
27  public:
28   BitrateConstraint();
29   ~BitrateConstraint() override = default;
30 
31   void OnEncoderSettingsUpdated(
32       absl::optional<EncoderSettings> encoder_settings);
33   void OnEncoderTargetBitrateUpdated(
34       absl::optional<uint32_t> encoder_target_bitrate_bps);
35 
36   // AdaptationConstraint implementation.
Name()37   std::string Name() const override { return "BitrateConstraint"; }
38   bool IsAdaptationUpAllowed(
39       const VideoStreamInputState& input_state,
40       const VideoSourceRestrictions& restrictions_before,
41       const VideoSourceRestrictions& restrictions_after) const override;
42 
43  private:
44   RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
45   absl::optional<EncoderSettings> encoder_settings_
46       RTC_GUARDED_BY(&sequence_checker_);
47   absl::optional<uint32_t> encoder_target_bitrate_bps_
48       RTC_GUARDED_BY(&sequence_checker_);
49 };
50 
51 }  // namespace webrtc
52 
53 #endif  // VIDEO_ADAPTATION_BITRATE_CONSTRAINT_H_
54