blob: 52fdd8b943ca80356ef2113b3fce9833e1f5fb43 [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
Emircan Uysaler207a75d2018-03-12 14:12:14 -070042 // |type| has the default value OutputType::I420. |num_squares| has the
43 // default value 10.
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080044 static FrameGeneratorCapturer* Create(
45 int width,
46 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +020047 absl::optional<FrameGenerator::OutputType> type,
48 absl::optional<int> num_squares,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080049 int target_fps,
50 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:10 +000051
perkja49cbd32016-09-16 07:53:41 -070052 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000053 size_t width,
54 size_t height,
55 int target_fps,
56 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070057
58 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
59 int height,
60 int frame_repeat_count,
61 int target_fps,
62 Clock* clock);
Sebastian Janssonaa01f272019-01-30 11:28:59 +010063
Artem Titova3ed4512019-01-25 14:59:57 +010064 static FrameGeneratorCapturer* Create(
65 std::unique_ptr<FrameGenerator> frame_generator,
66 int target_fps,
67 Clock* clock);
68
pbos@webrtc.org26d12102013-05-29 13:41:03 +000069 virtual ~FrameGeneratorCapturer();
70
Niels Möller8eeccbe2018-12-14 13:35:32 +010071 void Start();
72 void Stop();
perkjfa10b552016-10-02 23:45:26 -070073 void ChangeResolution(size_t width, size_t height);
Sebastian Janssonba3decf2018-08-30 11:19:23 +020074 void ChangeFramerate(int target_framerate);
perkja49cbd32016-09-16 07:53:41 -070075
perkj803d97f2016-11-01 11:45:46 -070076 void SetSinkWantsObserver(SinkWantsObserver* observer);
77
perkja49cbd32016-09-16 07:53:41 -070078 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
79 const rtc::VideoSinkWants& wants) override;
80 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
81
sprang867fb522015-08-03 04:38:41 -070082 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020083 void SetFakeRotation(VideoRotation rotation);
Johannes Kronf7f13e02018-12-12 11:17:43 +010084 void SetFakeColorSpace(absl::optional<ColorSpace> color_space);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000085
wu@webrtc.orgcd701192014-04-24 22:10:24 +000086 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
87
andresp@webrtc.orgab654952013-09-19 12:14:03 +000088 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080089 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000090 int target_fps);
Sebastian Janssonfb14c5d2019-02-28 13:30:04 +010091 FrameGeneratorCapturer(Clock* clock,
92 std::unique_ptr<FrameGenerator> frame_generator,
93 int target_fps,
94 TaskQueueFactory& task_queue_factory);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000096
97 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000098 void InsertFrame();
99 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -0700100 int GetCurrentConfiguredFramerate();
Niels Möller3793bb42018-12-20 13:46:06 +0100101 void UpdateFps(int max_fps) RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000102
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000103 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000104 bool sending_;
danilchapa37de392017-09-09 04:17:22 -0700105 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000106
Peter Boströmf2f82832015-05-01 13:00:41 +0200107 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -0700108 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000109
Sebastian Janssonba3decf2018-08-30 11:19:23 +0200110 int source_fps_ RTC_GUARDED_BY(&lock_);
111 int target_capture_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200112 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200113 VideoRotation fake_rotation_ = kVideoRotation_0;
Johannes Kronf7f13e02018-12-12 11:17:43 +0100114 absl::optional<ColorSpace> fake_color_space_ RTC_GUARDED_BY(&lock_);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000115
116 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700117 // Must be the last field, so it will be deconstructed first as tasks
118 // in the TaskQueue access other fields of the instance of this class.
119 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000120};
ilnikbaded152017-03-17 05:55:25 -0700121} // namespace test
122} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000123
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200124#endif // TEST_FRAME_GENERATOR_CAPTURER_H_