blob: 3fc03f07eb031342ac563b6bde107fea58660431 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:031/*
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 12:24:5810#ifndef TEST_TEST_VIDEO_CAPTURER_H_
11#define TEST_TEST_VIDEO_CAPTURER_H_
pbos@webrtc.org29d58392013-05-16 12:08:0312
pbos@webrtc.org26d12102013-05-29 13:41:0313#include <stddef.h>
14
sprangc5d62e22017-04-03 06:53:0415#include <memory>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/video/video_frame.h"
Niels Möller0327c2d2018-05-21 12:09:3118#include "api/video/video_source_interface.h"
Steve Anton10542f22019-01-11 17:11:0019#include "media/base/video_adapter.h"
20#include "media/base/video_broadcaster.h"
Markus Handella5a4be12020-07-08 14:09:2121#include "rtc_base/synchronization/mutex.h"
sprangc5d62e22017-04-03 06:53:0422
pbos@webrtc.org29d58392013-05-16 12:08:0323namespace webrtc {
pbos@webrtc.org29d58392013-05-16 12:08:0324namespace test {
25
Sebastian Janssonf1f363f2018-08-13 12:24:5826class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
pbos@webrtc.org29d58392013-05-16 12:08:0327 public:
Artem Titov9afdddf2019-10-10 11:29:0328 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 09:34:0935 ~TestVideoCapturer() override;
pbos@webrtc.org29d58392013-05-16 12:08:0336
sprangc5d62e22017-04-03 06:53:0437 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
38 const rtc::VideoSinkWants& wants) override;
Niels Möller3793bb42018-12-20 12:46:0639 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
Artem Titov9afdddf2019-10-10 11:29:0340 void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) {
Markus Handella5a4be12020-07-08 14:09:2141 MutexLock lock(&lock_);
Artem Titov9afdddf2019-10-10 11:29:0342 preprocessor_ = std::move(preprocessor);
43 }
Artem Titov6a78e932023-03-21 12:46:4744 void SetDisableAdaptation(bool disable_adaptation) {
45 MutexLock lock(&lock_);
46 disable_adaptation_ = disable_adaptation;
47 }
Asa Persson42eec3d2022-01-13 16:51:1848 void OnOutputFormatRequest(int width,
49 int height,
50 const absl::optional<int>& max_fps);
sprangc5d62e22017-04-03 06:53:0451
52 protected:
Niels Möller3793bb42018-12-20 12:46:0653 void OnFrame(const VideoFrame& frame);
sprangc5d62e22017-04-03 06:53:0454 rtc::VideoSinkWants GetSinkWants();
55
56 private:
Niels Möller3793bb42018-12-20 12:46:0657 void UpdateVideoAdapter();
Artem Titov9afdddf2019-10-10 11:29:0358 VideoFrame MaybePreprocess(const VideoFrame& frame);
Niels Möller3793bb42018-12-20 12:46:0659
Markus Handella5a4be12020-07-08 14:09:2160 Mutex lock_;
Artem Titov9afdddf2019-10-10 11:29:0361 std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
Artem Titov6a78e932023-03-21 12:46:4762 bool disable_adaptation_ RTC_GUARDED_BY(lock_) = false;
Niels Möller3793bb42018-12-20 12:46:0663 rtc::VideoBroadcaster broadcaster_;
64 cricket::VideoAdapter video_adapter_;
pbos@webrtc.org29d58392013-05-16 12:08:0365};
sprangc5d62e22017-04-03 06:53:0466} // namespace test
67} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:0368
Sebastian Janssonf1f363f2018-08-13 12:24:5869#endif // TEST_TEST_VIDEO_CAPTURER_H_