video_source_restrictions.h 3.6 KB

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