xref: /aosp_15_r20/external/webrtc/call/adaptation/video_source_restrictions.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2020 The WebRTC Project Authors. All rights reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
12*d9f75844SAndroid Build Coastguard Worker #define CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <string>
15*d9f75844SAndroid Build Coastguard Worker #include <utility>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker // Describes optional restrictions to the resolution and frame rate of a video
22*d9f75844SAndroid Build Coastguard Worker // source.
23*d9f75844SAndroid Build Coastguard Worker class VideoSourceRestrictions {
24*d9f75844SAndroid Build Coastguard Worker  public:
25*d9f75844SAndroid Build Coastguard Worker   // Constructs without any restrictions.
26*d9f75844SAndroid Build Coastguard Worker   VideoSourceRestrictions();
27*d9f75844SAndroid Build Coastguard Worker   // All values must be positive or nullopt.
28*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Support expressing "disable this stream"?
29*d9f75844SAndroid Build Coastguard Worker   VideoSourceRestrictions(absl::optional<size_t> max_pixels_per_frame,
30*d9f75844SAndroid Build Coastguard Worker                           absl::optional<size_t> target_pixels_per_frame,
31*d9f75844SAndroid Build Coastguard Worker                           absl::optional<double> max_frame_rate);
32*d9f75844SAndroid Build Coastguard Worker 
33*d9f75844SAndroid Build Coastguard Worker   bool operator==(const VideoSourceRestrictions& rhs) const {
34*d9f75844SAndroid Build Coastguard Worker     return max_pixels_per_frame_ == rhs.max_pixels_per_frame_ &&
35*d9f75844SAndroid Build Coastguard Worker            target_pixels_per_frame_ == rhs.target_pixels_per_frame_ &&
36*d9f75844SAndroid Build Coastguard Worker            max_frame_rate_ == rhs.max_frame_rate_;
37*d9f75844SAndroid Build Coastguard Worker   }
38*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const VideoSourceRestrictions& rhs) const {
39*d9f75844SAndroid Build Coastguard Worker     return !(*this == rhs);
40*d9f75844SAndroid Build Coastguard Worker   }
41*d9f75844SAndroid Build Coastguard Worker 
42*d9f75844SAndroid Build Coastguard Worker   std::string ToString() const;
43*d9f75844SAndroid Build Coastguard Worker 
44*d9f75844SAndroid Build Coastguard Worker   // The source must produce a resolution less than or equal to
45*d9f75844SAndroid Build Coastguard Worker   // max_pixels_per_frame().
46*d9f75844SAndroid Build Coastguard Worker   const absl::optional<size_t>& max_pixels_per_frame() const;
47*d9f75844SAndroid Build Coastguard Worker   // The source should produce a resolution as close to the
48*d9f75844SAndroid Build Coastguard Worker   // target_pixels_per_frame() as possible, provided this does not exceed
49*d9f75844SAndroid Build Coastguard Worker   // max_pixels_per_frame().
50*d9f75844SAndroid Build Coastguard Worker   // The actual pixel count selected depends on the capabilities of the source.
51*d9f75844SAndroid Build Coastguard Worker   // TODO(hbos): Clarify how "target" is used. One possible implementation: open
52*d9f75844SAndroid Build Coastguard Worker   // the camera in the smallest resolution that is greater than or equal to the
53*d9f75844SAndroid Build Coastguard Worker   // target and scale it down to the target if it is greater. Is this an
54*d9f75844SAndroid Build Coastguard Worker   // accurate description of what this does today, or do we do something else?
55*d9f75844SAndroid Build Coastguard Worker   const absl::optional<size_t>& target_pixels_per_frame() const;
56*d9f75844SAndroid Build Coastguard Worker   const absl::optional<double>& max_frame_rate() const;
57*d9f75844SAndroid Build Coastguard Worker 
58*d9f75844SAndroid Build Coastguard Worker   void set_max_pixels_per_frame(absl::optional<size_t> max_pixels_per_frame);
59*d9f75844SAndroid Build Coastguard Worker   void set_target_pixels_per_frame(
60*d9f75844SAndroid Build Coastguard Worker       absl::optional<size_t> target_pixels_per_frame);
61*d9f75844SAndroid Build Coastguard Worker   void set_max_frame_rate(absl::optional<double> max_frame_rate);
62*d9f75844SAndroid Build Coastguard Worker 
63*d9f75844SAndroid Build Coastguard Worker   // Update `this` with min(`this`, `other`).
64*d9f75844SAndroid Build Coastguard Worker   void UpdateMin(const VideoSourceRestrictions& other);
65*d9f75844SAndroid Build Coastguard Worker 
66*d9f75844SAndroid Build Coastguard Worker  private:
67*d9f75844SAndroid Build Coastguard Worker   // These map to rtc::VideoSinkWants's `max_pixel_count` and
68*d9f75844SAndroid Build Coastguard Worker   // `target_pixel_count`.
69*d9f75844SAndroid Build Coastguard Worker   absl::optional<size_t> max_pixels_per_frame_;
70*d9f75844SAndroid Build Coastguard Worker   absl::optional<size_t> target_pixels_per_frame_;
71*d9f75844SAndroid Build Coastguard Worker   absl::optional<double> max_frame_rate_;
72*d9f75844SAndroid Build Coastguard Worker };
73*d9f75844SAndroid Build Coastguard Worker 
74*d9f75844SAndroid Build Coastguard Worker bool DidRestrictionsIncrease(VideoSourceRestrictions before,
75*d9f75844SAndroid Build Coastguard Worker                              VideoSourceRestrictions after);
76*d9f75844SAndroid Build Coastguard Worker bool DidRestrictionsDecrease(VideoSourceRestrictions before,
77*d9f75844SAndroid Build Coastguard Worker                              VideoSourceRestrictions after);
78*d9f75844SAndroid Build Coastguard Worker bool DidIncreaseResolution(VideoSourceRestrictions restrictions_before,
79*d9f75844SAndroid Build Coastguard Worker                            VideoSourceRestrictions restrictions_after);
80*d9f75844SAndroid Build Coastguard Worker bool DidDecreaseResolution(VideoSourceRestrictions restrictions_before,
81*d9f75844SAndroid Build Coastguard Worker                            VideoSourceRestrictions restrictions_after);
82*d9f75844SAndroid Build Coastguard Worker bool DidIncreaseFrameRate(VideoSourceRestrictions restrictions_before,
83*d9f75844SAndroid Build Coastguard Worker                           VideoSourceRestrictions restrictions_after);
84*d9f75844SAndroid Build Coastguard Worker bool DidDecreaseFrameRate(VideoSourceRestrictions restrictions_before,
85*d9f75844SAndroid Build Coastguard Worker                           VideoSourceRestrictions restrictions_after);
86*d9f75844SAndroid Build Coastguard Worker 
87*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
88*d9f75844SAndroid Build Coastguard Worker 
89*d9f75844SAndroid Build Coastguard Worker #endif  // CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
90