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