Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 TEST_FRAME_FORWARDER_H_ |
| 11 | #define TEST_FRAME_FORWARDER_H_ |
| 12 | |
| 13 | #include "api/video/video_frame.h" |
| 14 | #include "api/video/video_source_interface.h" |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 15 | #include "rtc_base/synchronization/mutex.h" |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace test { |
| 19 | |
| 20 | // FrameForwarder can be used as an implementation |
| 21 | // of rtc::VideoSourceInterface<VideoFrame> where the caller controls when |
| 22 | // a frame should be forwarded to its sink. |
| 23 | // Currently this implementation only support one sink. |
| 24 | class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> { |
| 25 | public: |
| 26 | FrameForwarder(); |
| 27 | ~FrameForwarder() override; |
| 28 | // Forwards |video_frame| to the registered |sink_|. |
Markus Handell | 16038ab | 2020-05-28 06:37:30 | [diff] [blame] | 29 | virtual void IncomingCapturedFrame(const VideoFrame& video_frame) |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 30 | RTC_LOCKS_EXCLUDED(mutex_); |
| 31 | rtc::VideoSinkWants sink_wants() const RTC_LOCKS_EXCLUDED(mutex_); |
| 32 | bool has_sinks() const RTC_LOCKS_EXCLUDED(mutex_); |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 33 | |
| 34 | protected: |
Markus Handell | 16038ab | 2020-05-28 06:37:30 | [diff] [blame] | 35 | rtc::VideoSinkWants sink_wants_locked() const |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 36 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 37 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
Markus Handell | 16038ab | 2020-05-28 06:37:30 | [diff] [blame] | 38 | const rtc::VideoSinkWants& wants) |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 39 | RTC_LOCKS_EXCLUDED(mutex_) override; |
Markus Handell | 16038ab | 2020-05-28 06:37:30 | [diff] [blame] | 40 | void AddOrUpdateSinkLocked(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 41 | const rtc::VideoSinkWants& wants) |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 42 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Markus Handell | 16038ab | 2020-05-28 06:37:30 | [diff] [blame] | 43 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 44 | RTC_LOCKS_EXCLUDED(mutex_) override; |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 45 | |
Markus Handell | a376518 | 2020-07-08 11:13:32 | [diff] [blame] | 46 | mutable Mutex mutex_; |
| 47 | rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(mutex_); |
| 48 | rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(mutex_); |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace test |
| 52 | } // namespace webrtc |
| 53 | |
| 54 | #endif // TEST_FRAME_FORWARDER_H_ |