1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker #ifndef TEST_FRAME_FORWARDER_H_ 11*d9f75844SAndroid Build Coastguard Worker #define TEST_FRAME_FORWARDER_H_ 12*d9f75844SAndroid Build Coastguard Worker 13*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_frame.h" 14*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_source_interface.h" 15*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/synchronization/mutex.h" 16*d9f75844SAndroid Build Coastguard Worker 17*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 18*d9f75844SAndroid Build Coastguard Worker namespace test { 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker // FrameForwarder can be used as an implementation 21*d9f75844SAndroid Build Coastguard Worker // of rtc::VideoSourceInterface<VideoFrame> where the caller controls when 22*d9f75844SAndroid Build Coastguard Worker // a frame should be forwarded to its sink. 23*d9f75844SAndroid Build Coastguard Worker // Currently this implementation only support one sink. 24*d9f75844SAndroid Build Coastguard Worker class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> { 25*d9f75844SAndroid Build Coastguard Worker public: 26*d9f75844SAndroid Build Coastguard Worker FrameForwarder(); 27*d9f75844SAndroid Build Coastguard Worker ~FrameForwarder() override; 28*d9f75844SAndroid Build Coastguard Worker // Forwards `video_frame` to the registered `sink_`. 29*d9f75844SAndroid Build Coastguard Worker virtual void IncomingCapturedFrame(const VideoFrame& video_frame) 30*d9f75844SAndroid Build Coastguard Worker RTC_LOCKS_EXCLUDED(mutex_); 31*d9f75844SAndroid Build Coastguard Worker rtc::VideoSinkWants sink_wants() const RTC_LOCKS_EXCLUDED(mutex_); 32*d9f75844SAndroid Build Coastguard Worker bool has_sinks() const RTC_LOCKS_EXCLUDED(mutex_); 33*d9f75844SAndroid Build Coastguard Worker 34*d9f75844SAndroid Build Coastguard Worker protected: 35*d9f75844SAndroid Build Coastguard Worker rtc::VideoSinkWants sink_wants_locked() const 36*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 37*d9f75844SAndroid Build Coastguard Worker void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 38*d9f75844SAndroid Build Coastguard Worker const rtc::VideoSinkWants& wants) 39*d9f75844SAndroid Build Coastguard Worker RTC_LOCKS_EXCLUDED(mutex_) override; 40*d9f75844SAndroid Build Coastguard Worker void AddOrUpdateSinkLocked(rtc::VideoSinkInterface<VideoFrame>* sink, 41*d9f75844SAndroid Build Coastguard Worker const rtc::VideoSinkWants& wants) 42*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 43*d9f75844SAndroid Build Coastguard Worker void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) 44*d9f75844SAndroid Build Coastguard Worker RTC_LOCKS_EXCLUDED(mutex_) override; 45*d9f75844SAndroid Build Coastguard Worker 46*d9f75844SAndroid Build Coastguard Worker mutable Mutex mutex_; 47*d9f75844SAndroid Build Coastguard Worker rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(mutex_); 48*d9f75844SAndroid Build Coastguard Worker rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(mutex_); 49*d9f75844SAndroid Build Coastguard Worker }; 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker } // namespace test 52*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 53*d9f75844SAndroid Build Coastguard Worker 54*d9f75844SAndroid Build Coastguard Worker #endif // TEST_FRAME_FORWARDER_H_ 55