pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 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 | */ |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 10 | #ifndef TEST_TEST_VIDEO_CAPTURER_H_ |
| 11 | #define TEST_TEST_VIDEO_CAPTURER_H_ |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 15 | #include <memory> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/video/video_frame.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 18 | #include "api/video/video_source_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "media/base/video_adapter.h" |
| 20 | #include "media/base/video_broadcaster.h" |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 21 | #include "rtc_base/critical_section.h" |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 22 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 23 | namespace webrtc { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 24 | namespace test { |
| 25 | |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 26 | class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 27 | public: |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 28 | class FramePreprocessor { |
| 29 | public: |
| 30 | virtual ~FramePreprocessor() = default; |
| 31 | |
| 32 | virtual VideoFrame Preprocess(const VideoFrame& frame) = 0; |
| 33 | }; |
| 34 | |
Kári Tristan Helgason | ede7cb2 | 2019-03-06 10:34:09 +0100 | [diff] [blame] | 35 | ~TestVideoCapturer() override; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 36 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 37 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 38 | const rtc::VideoSinkWants& wants) override; |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 39 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 40 | void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) { |
| 41 | rtc::CritScope crit(&lock_); |
| 42 | preprocessor_ = std::move(preprocessor); |
| 43 | } |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 44 | |
| 45 | protected: |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 46 | void OnFrame(const VideoFrame& frame); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 47 | rtc::VideoSinkWants GetSinkWants(); |
| 48 | |
| 49 | private: |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 50 | void UpdateVideoAdapter(); |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 51 | VideoFrame MaybePreprocess(const VideoFrame& frame); |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 52 | |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 53 | rtc::CriticalSection lock_; |
| 54 | std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_); |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 55 | rtc::VideoBroadcaster broadcaster_; |
| 56 | cricket::VideoAdapter video_adapter_; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 57 | }; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 58 | } // namespace test |
| 59 | } // namespace webrtc |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 60 | |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 61 | #endif // TEST_TEST_VIDEO_CAPTURER_H_ |