blob: 114767a43eae67c605733f4be3084307e5939aa0 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:03 +00001/*
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 Janssonf1f363f2018-08-13 14:24:58 +020010#ifndef TEST_TEST_VIDEO_CAPTURER_H_
11#define TEST_TEST_VIDEO_CAPTURER_H_
pbos@webrtc.org29d58392013-05-16 12:08:03 +000012
pbos@webrtc.org26d12102013-05-29 13:41:03 +000013#include <stddef.h>
14
sprangc5d62e22017-04-02 23:53:04 -070015#include <memory>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/video/video_frame.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020018#include "api/video/video_source_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "media/base/video_adapter.h"
20#include "media/base/video_broadcaster.h"
Artem Titov9afdddf2019-10-10 13:29:03 +020021#include "rtc_base/critical_section.h"
sprangc5d62e22017-04-02 23:53:04 -070022
pbos@webrtc.org29d58392013-05-16 12:08:03 +000023namespace webrtc {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000024namespace test {
25
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020026class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000027 public:
Artem Titov9afdddf2019-10-10 13:29:03 +020028 class FramePreprocessor {
29 public:
30 virtual ~FramePreprocessor() = default;
31
32 virtual VideoFrame Preprocess(const VideoFrame& frame) = 0;
33 };
34
Kári Tristan Helgasonede7cb22019-03-06 10:34:09 +010035 ~TestVideoCapturer() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000036
sprangc5d62e22017-04-02 23:53:04 -070037 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
38 const rtc::VideoSinkWants& wants) override;
Niels Möller3793bb42018-12-20 13:46:06 +010039 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
Artem Titov9afdddf2019-10-10 13:29:03 +020040 void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) {
41 rtc::CritScope crit(&lock_);
42 preprocessor_ = std::move(preprocessor);
43 }
sprangc5d62e22017-04-02 23:53:04 -070044
45 protected:
Niels Möller3793bb42018-12-20 13:46:06 +010046 void OnFrame(const VideoFrame& frame);
sprangc5d62e22017-04-02 23:53:04 -070047 rtc::VideoSinkWants GetSinkWants();
48
49 private:
Niels Möller3793bb42018-12-20 13:46:06 +010050 void UpdateVideoAdapter();
Artem Titov9afdddf2019-10-10 13:29:03 +020051 VideoFrame MaybePreprocess(const VideoFrame& frame);
Niels Möller3793bb42018-12-20 13:46:06 +010052
Artem Titov9afdddf2019-10-10 13:29:03 +020053 rtc::CriticalSection lock_;
54 std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
Niels Möller3793bb42018-12-20 13:46:06 +010055 rtc::VideoBroadcaster broadcaster_;
56 cricket::VideoAdapter video_adapter_;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000057};
sprangc5d62e22017-04-02 23:53:04 -070058} // namespace test
59} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:03 +000060
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020061#endif // TEST_TEST_VIDEO_CAPTURER_H_