blob: 49660d897240bf1757461204ef29d6da4fa359d6 [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 Titov6fd5f33d2023-03-25 20:15:0944 void SetEnableAdaptation(bool enable_adaptation) {
Artem Titov6a78e932023-03-21 12:46:4745 MutexLock lock(&lock_);
Artem Titov6fd5f33d2023-03-25 20:15:0946 enable_adaptation_ = enable_adaptation;
Artem Titov6a78e932023-03-21 12:46:4747 }
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
Artem Titov5246ae22023-06-21 13:09:3352 // Starts or resumes video capturing. Can be called multiple times during
53 // lifetime of this object.
54 virtual void Start() = 0;
55 // Stops or pauses video capturing. Can be called multiple times during
56 // lifetime of this object.
57 virtual void Stop() = 0;
58
Artem Titov6fd5f33d2023-03-25 20:15:0959 virtual int GetFrameWidth() const = 0;
60 virtual int GetFrameHeight() const = 0;
61
sprangc5d62e22017-04-03 06:53:0462 protected:
Niels Möller3793bb42018-12-20 12:46:0663 void OnFrame(const VideoFrame& frame);
sprangc5d62e22017-04-03 06:53:0464 rtc::VideoSinkWants GetSinkWants();
65
66 private:
Niels Möller3793bb42018-12-20 12:46:0667 void UpdateVideoAdapter();
Artem Titov9afdddf2019-10-10 11:29:0368 VideoFrame MaybePreprocess(const VideoFrame& frame);
Niels Möller3793bb42018-12-20 12:46:0669
Markus Handella5a4be12020-07-08 14:09:2170 Mutex lock_;
Artem Titov9afdddf2019-10-10 11:29:0371 std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
Artem Titov5246ae22023-06-21 13:09:3372 bool enable_adaptation_ RTC_GUARDED_BY(lock_) = true;
Niels Möller3793bb42018-12-20 12:46:0673 rtc::VideoBroadcaster broadcaster_;
74 cricket::VideoAdapter video_adapter_;
pbos@webrtc.org29d58392013-05-16 12:08:0375};
sprangc5d62e22017-04-03 06:53:0476} // namespace test
77} // namespace webrtc
pbos@webrtc.org29d58392013-05-16 12:08:0378
Sebastian Janssonf1f363f2018-08-13 12:24:5879#endif // TEST_TEST_VIDEO_CAPTURER_H_