blob: d6faf7c82879ae11ccf58caf6eeed231fe1f18dd [file] [log] [blame]
pbos@webrtc.org26d12102013-05-29 13:41: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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_FRAME_GENERATOR_CAPTURER_H_
11#define TEST_FRAME_GENERATOR_CAPTURER_H_
pbos@webrtc.org26d12102013-05-29 13:41:03 +000012
kwibergbfefb032016-05-01 14:53:46 -070013#include <memory>
sprang@webrtc.org131bea82015-02-18 12:46:06 +000014#include <string>
15
Sebastian Janssonfb14c5d2019-02-28 13:30:04 +010016#include "api/task_queue/task_queue_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/video/video_frame.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/task_queue.h"
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080020#include "test/frame_generator.h"
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020021#include "test/test_video_capturer.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000022
23namespace webrtc {
24
pbos@webrtc.org26d12102013-05-29 13:41:03 +000025namespace test {
26
27class FrameGenerator;
28
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020029class FrameGeneratorCapturer : public TestVideoCapturer {
pbos@webrtc.org26d12102013-05-29 13:41:03 +000030 public:
perkj803d97f2016-11-01 11:45:46 -070031 class SinkWantsObserver {
32 public:
33 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
34 // is called.
35 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
36 const rtc::VideoSinkWants& wants) = 0;
37
38 protected:
39 virtual ~SinkWantsObserver() {}
40 };
41
Danil Chapovalov59b64d32019-04-23 13:45:12 +020042 FrameGeneratorCapturer(Clock* clock,
43 std::unique_ptr<FrameGenerator> frame_generator,
44 int target_fps,
45 TaskQueueFactory& task_queue_factory);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000046 virtual ~FrameGeneratorCapturer();
47
Niels Möller8eeccbe2018-12-14 13:35:32 +010048 void Start();
49 void Stop();
perkjfa10b552016-10-02 23:45:26 -070050 void ChangeResolution(size_t width, size_t height);
Sebastian Janssonba3decf2018-08-30 11:19:23 +020051 void ChangeFramerate(int target_framerate);
perkja49cbd32016-09-16 07:53:41 -070052
perkj803d97f2016-11-01 11:45:46 -070053 void SetSinkWantsObserver(SinkWantsObserver* observer);
54
perkja49cbd32016-09-16 07:53:41 -070055 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
56 const rtc::VideoSinkWants& wants) override;
57 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
58
sprang867fb522015-08-03 04:38:41 -070059 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020060 void SetFakeRotation(VideoRotation rotation);
Johannes Kronf7f13e02018-12-12 11:17:43 +010061 void SetFakeColorSpace(absl::optional<ColorSpace> color_space);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000062
wu@webrtc.orgcd701192014-04-24 22:10:24 +000063 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
64
pbos@webrtc.org26d12102013-05-29 13:41:03 +000065 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000066
67 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000068 void InsertFrame();
69 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070070 int GetCurrentConfiguredFramerate();
Niels Möller3793bb42018-12-20 13:46:06 +010071 void UpdateFps(int max_fps) RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000072
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000073 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000074 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070075 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000076
Peter Boströmf2f82832015-05-01 13:00:41 +020077 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070078 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000079
Sebastian Janssonba3decf2018-08-30 11:19:23 +020080 int source_fps_ RTC_GUARDED_BY(&lock_);
81 int target_capture_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 12:54:17 +020082 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +020083 VideoRotation fake_rotation_ = kVideoRotation_0;
Johannes Kronf7f13e02018-12-12 11:17:43 +010084 absl::optional<ColorSpace> fake_color_space_ RTC_GUARDED_BY(&lock_);
wu@webrtc.orgcd701192014-04-24 22:10:24 +000085
86 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -070087 // Must be the last field, so it will be deconstructed first as tasks
88 // in the TaskQueue access other fields of the instance of this class.
89 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000090};
ilnikbaded152017-03-17 05:55:25 -070091} // namespace test
92} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +000093
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020094#endif // TEST_FRAME_GENERATOR_CAPTURER_H_