• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
12 #define CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
13 
14 #include <string>
15 #include <utility>
16 
17 #include "absl/types/optional.h"
18 
19 namespace webrtc {
20 
21 // Describes optional restrictions to the resolution and frame rate of a video
22 // source.
23 class VideoSourceRestrictions {
24  public:
25   // Constructs without any restrictions.
26   VideoSourceRestrictions();
27   // All values must be positive or nullopt.
28   // TODO(hbos): Support expressing "disable this stream"?
29   VideoSourceRestrictions(absl::optional<size_t> max_pixels_per_frame,
30                           absl::optional<size_t> target_pixels_per_frame,
31                           absl::optional<double> max_frame_rate);
32 
33   bool operator==(const VideoSourceRestrictions& rhs) const {
34     return max_pixels_per_frame_ == rhs.max_pixels_per_frame_ &&
35            target_pixels_per_frame_ == rhs.target_pixels_per_frame_ &&
36            max_frame_rate_ == rhs.max_frame_rate_;
37   }
38   bool operator!=(const VideoSourceRestrictions& rhs) const {
39     return !(*this == rhs);
40   }
41 
42   std::string ToString() const;
43 
44   // The source must produce a resolution less than or equal to
45   // max_pixels_per_frame().
46   const absl::optional<size_t>& max_pixels_per_frame() const;
47   // The source should produce a resolution as close to the
48   // target_pixels_per_frame() as possible, provided this does not exceed
49   // max_pixels_per_frame().
50   // The actual pixel count selected depends on the capabilities of the source.
51   // TODO(hbos): Clarify how "target" is used. One possible implementation: open
52   // the camera in the smallest resolution that is greater than or equal to the
53   // target and scale it down to the target if it is greater. Is this an
54   // accurate description of what this does today, or do we do something else?
55   const absl::optional<size_t>& target_pixels_per_frame() const;
56   const absl::optional<double>& max_frame_rate() const;
57 
58   void set_max_pixels_per_frame(absl::optional<size_t> max_pixels_per_frame);
59   void set_target_pixels_per_frame(
60       absl::optional<size_t> target_pixels_per_frame);
61   void set_max_frame_rate(absl::optional<double> max_frame_rate);
62 
63  private:
64   // These map to rtc::VideoSinkWants's |max_pixel_count| and
65   // |target_pixel_count|.
66   absl::optional<size_t> max_pixels_per_frame_;
67   absl::optional<size_t> target_pixels_per_frame_;
68   absl::optional<double> max_frame_rate_;
69 };
70 
71 bool DidRestrictionsIncrease(VideoSourceRestrictions before,
72                              VideoSourceRestrictions after);
73 bool DidRestrictionsDecrease(VideoSourceRestrictions before,
74                              VideoSourceRestrictions after);
75 bool DidIncreaseResolution(VideoSourceRestrictions restrictions_before,
76                            VideoSourceRestrictions restrictions_after);
77 bool DidDecreaseResolution(VideoSourceRestrictions restrictions_before,
78                            VideoSourceRestrictions restrictions_after);
79 bool DidIncreaseFrameRate(VideoSourceRestrictions restrictions_before,
80                           VideoSourceRestrictions restrictions_after);
81 bool DidDecreaseFrameRate(VideoSourceRestrictions restrictions_before,
82                           VideoSourceRestrictions restrictions_after);
83 
84 }  // namespace webrtc
85 
86 #endif  // CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
87