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