video_source_sink_controller.h 3.5 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 VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
  11. #define VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
  12. #include <string>
  13. #include "absl/types/optional.h"
  14. #include "api/video/video_frame.h"
  15. #include "api/video/video_sink_interface.h"
  16. #include "api/video/video_source_interface.h"
  17. #include "call/adaptation/video_source_restrictions.h"
  18. #include "rtc_base/synchronization/sequence_checker.h"
  19. #include "rtc_base/system/no_unique_address.h"
  20. namespace webrtc {
  21. // Responsible for configuring source/sink settings, i.e. performing
  22. // rtc::VideoSourceInterface<VideoFrame>::AddOrUpdateSink(). It does this by
  23. // storing settings internally which are converted to rtc::VideoSinkWants when
  24. // PushSourceSinkSettings() is performed.
  25. class VideoSourceSinkController {
  26. public:
  27. VideoSourceSinkController(rtc::VideoSinkInterface<VideoFrame>* sink,
  28. rtc::VideoSourceInterface<VideoFrame>* source);
  29. ~VideoSourceSinkController();
  30. void SetSource(rtc::VideoSourceInterface<VideoFrame>* source);
  31. bool HasSource() const;
  32. // Must be called in order for changes to settings to have an effect. This
  33. // allows you to modify multiple properties in a single push to the sink.
  34. void PushSourceSinkSettings();
  35. VideoSourceRestrictions restrictions() const;
  36. absl::optional<size_t> pixels_per_frame_upper_limit() const;
  37. absl::optional<double> frame_rate_upper_limit() const;
  38. bool rotation_applied() const;
  39. int resolution_alignment() const;
  40. // Updates the settings stored internally. In order for these settings to be
  41. // applied to the sink, PushSourceSinkSettings() must subsequently be called.
  42. void SetRestrictions(VideoSourceRestrictions restrictions);
  43. void SetPixelsPerFrameUpperLimit(
  44. absl::optional<size_t> pixels_per_frame_upper_limit);
  45. void SetFrameRateUpperLimit(absl::optional<double> frame_rate_upper_limit);
  46. void SetRotationApplied(bool rotation_applied);
  47. void SetResolutionAlignment(int resolution_alignment);
  48. private:
  49. rtc::VideoSinkWants CurrentSettingsToSinkWants() const
  50. RTC_EXCLUSIVE_LOCKS_REQUIRED(sequence_checker_);
  51. // Used to ensure that this class is called on threads/sequences that it and
  52. // downstream implementations were designed for.
  53. // In practice, this represent's libjingle's worker thread.
  54. RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
  55. rtc::VideoSinkInterface<VideoFrame>* const sink_;
  56. rtc::VideoSourceInterface<VideoFrame>* source_
  57. RTC_GUARDED_BY(&sequence_checker_);
  58. // Pixel and frame rate restrictions.
  59. VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&sequence_checker_);
  60. // Ensures that even if we are not restricted, the sink is never configured
  61. // above this limit. Example: We are not CPU limited (no |restrictions_|) but
  62. // our encoder is capped at 30 fps (= |frame_rate_upper_limit_|).
  63. absl::optional<size_t> pixels_per_frame_upper_limit_
  64. RTC_GUARDED_BY(&sequence_checker_);
  65. absl::optional<double> frame_rate_upper_limit_
  66. RTC_GUARDED_BY(&sequence_checker_);
  67. bool rotation_applied_ RTC_GUARDED_BY(&sequence_checker_) = false;
  68. int resolution_alignment_ RTC_GUARDED_BY(&sequence_checker_) = 1;
  69. };
  70. } // namespace webrtc
  71. #endif // VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_