video_source_sink_controller.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/critical_section.h"
  19. namespace webrtc {
  20. // Responsible for configuring source/sink settings, i.e. performing
  21. // rtc::VideoSourceInterface<VideoFrame>::AddOrUpdateSink(). It does this by
  22. // storing settings internally which are converted to rtc::VideoSinkWants when
  23. // PushSourceSinkSettings() is performed.
  24. class VideoSourceSinkController {
  25. public:
  26. VideoSourceSinkController(rtc::VideoSinkInterface<VideoFrame>* sink,
  27. rtc::VideoSourceInterface<VideoFrame>* source);
  28. void SetSource(rtc::VideoSourceInterface<VideoFrame>* source);
  29. // Must be called in order for changes to settings to have an effect. This
  30. // allows you to modify multiple properties in a single push to the sink.
  31. void PushSourceSinkSettings();
  32. VideoSourceRestrictions restrictions() const;
  33. absl::optional<size_t> pixels_per_frame_upper_limit() const;
  34. absl::optional<double> frame_rate_upper_limit() const;
  35. bool rotation_applied() const;
  36. int resolution_alignment() const;
  37. // Updates the settings stored internally. In order for these settings to be
  38. // applied to the sink, PushSourceSinkSettings() must subsequently be called.
  39. void SetRestrictions(VideoSourceRestrictions restrictions);
  40. void SetPixelsPerFrameUpperLimit(
  41. absl::optional<size_t> pixels_per_frame_upper_limit);
  42. void SetFrameRateUpperLimit(absl::optional<double> frame_rate_upper_limit);
  43. void SetRotationApplied(bool rotation_applied);
  44. void SetResolutionAlignment(int resolution_alignment);
  45. private:
  46. rtc::VideoSinkWants CurrentSettingsToSinkWants() const
  47. RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
  48. mutable rtc::CriticalSection crit_;
  49. rtc::VideoSinkInterface<VideoFrame>* const sink_;
  50. rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&crit_);
  51. // Pixel and frame rate restrictions.
  52. VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&crit_);
  53. // Ensures that even if we are not restricted, the sink is never configured
  54. // above this limit. Example: We are not CPU limited (no |restrictions_|) but
  55. // our encoder is capped at 30 fps (= |frame_rate_upper_limit_|).
  56. absl::optional<size_t> pixels_per_frame_upper_limit_ RTC_GUARDED_BY(&crit_);
  57. absl::optional<double> frame_rate_upper_limit_ RTC_GUARDED_BY(&crit_);
  58. bool rotation_applied_ RTC_GUARDED_BY(&crit_) = false;
  59. int resolution_alignment_ RTC_GUARDED_BY(&crit_) = 1;
  60. };
  61. } // namespace webrtc
  62. #endif // VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_