1 /* 2 * Copyright (c) 2013 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_TEST_VIDEO_CAPTURER_H_ 11 #define TEST_TEST_VIDEO_CAPTURER_H_ 12 13 #include <stddef.h> 14 15 #include <memory> 16 17 #include "api/video/video_frame.h" 18 #include "api/video/video_source_interface.h" 19 #include "media/base/video_adapter.h" 20 #include "media/base/video_broadcaster.h" 21 #include "rtc_base/synchronization/mutex.h" 22 23 namespace webrtc { 24 namespace test { 25 26 class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> { 27 public: 28 class FramePreprocessor { 29 public: 30 virtual ~FramePreprocessor() = default; 31 32 virtual VideoFrame Preprocess(const VideoFrame& frame) = 0; 33 }; 34 35 ~TestVideoCapturer() override; 36 37 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, 38 const rtc::VideoSinkWants& wants) override; 39 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor)40 void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) { 41 MutexLock lock(&lock_); 42 preprocessor_ = std::move(preprocessor); 43 } 44 45 protected: 46 void OnFrame(const VideoFrame& frame); 47 rtc::VideoSinkWants GetSinkWants(); 48 49 private: 50 void UpdateVideoAdapter(); 51 VideoFrame MaybePreprocess(const VideoFrame& frame); 52 53 Mutex lock_; 54 std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_); 55 rtc::VideoBroadcaster broadcaster_; 56 cricket::VideoAdapter video_adapter_; 57 }; 58 } // namespace test 59 } // namespace webrtc 60 61 #endif // TEST_TEST_VIDEO_CAPTURER_H_ 62