blob: 4e156545f09e2f50d847bf91094f83f22c7b80b6 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/video/video_frame.h"
Steve Anton10542f22019-01-11 09:11:00 -080017#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/task_queue.h"
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080019#include "test/frame_generator.h"
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020020#include "test/test_video_capturer.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000021
22namespace webrtc {
23
pbos@webrtc.org26d12102013-05-29 13:41:03 +000024namespace test {
25
26class FrameGenerator;
27
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020028class FrameGeneratorCapturer : public TestVideoCapturer {
pbos@webrtc.org26d12102013-05-29 13:41:03 +000029 public:
perkj803d97f2016-11-01 11:45:46 -070030 class SinkWantsObserver {
31 public:
32 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
33 // is called.
34 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
35 const rtc::VideoSinkWants& wants) = 0;
36
37 protected:
38 virtual ~SinkWantsObserver() {}
39 };
40
Emircan Uysaler207a75d2018-03-12 14:12:14 -070041 // |type| has the default value OutputType::I420. |num_squares| has the
42 // default value 10.
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080043 static FrameGeneratorCapturer* Create(
44 int width,
45 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +020046 absl::optional<FrameGenerator::OutputType> type,
47 absl::optional<int> num_squares,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080048 int target_fps,
49 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:10 +000050
perkja49cbd32016-09-16 07:53:41 -070051 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000052 size_t width,
53 size_t height,
54 int target_fps,
55 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070056
57 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
58 int height,
59 int frame_repeat_count,
60 int target_fps,
61 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000062 virtual ~FrameGeneratorCapturer();
63
Niels Möller8eeccbe2018-12-14 13:35:32 +010064 void Start();
65 void Stop();
perkjfa10b552016-10-02 23:45:26 -070066 void ChangeResolution(size_t width, size_t height);
Sebastian Janssonba3decf2018-08-30 11:19:23 +020067 void ChangeFramerate(int target_framerate);
perkja49cbd32016-09-16 07:53:41 -070068
perkj803d97f2016-11-01 11:45:46 -070069 void SetSinkWantsObserver(SinkWantsObserver* observer);
70
perkja49cbd32016-09-16 07:53:41 -070071 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
72 const rtc::VideoSinkWants& wants) override;
73 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
74
sprang867fb522015-08-03 04:38:41 -070075 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020076 void SetFakeRotation(VideoRotation rotation);
Johannes Kronf7f13e02018-12-12 11:17:43 +010077 void SetFakeColorSpace(absl::optional<ColorSpace> color_space);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000078
wu@webrtc.orgcd701192014-04-24 22:10:24 +000079 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
80
andresp@webrtc.orgab654952013-09-19 12:14:03 +000081 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080082 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000083 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000084 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000085
86 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000087 void InsertFrame();
88 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070089 int GetCurrentConfiguredFramerate();
Niels Möller3793bb42018-12-20 13:46:06 +010090 void UpdateFps(int max_fps) RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000091
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000092 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000093 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070094 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095
Peter Boströmf2f82832015-05-01 13:00:41 +020096 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070097 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000098
Sebastian Janssonba3decf2018-08-30 11:19:23 +020099 int source_fps_ RTC_GUARDED_BY(&lock_);
100 int target_capture_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200101 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200102 VideoRotation fake_rotation_ = kVideoRotation_0;
Johannes Kronf7f13e02018-12-12 11:17:43 +0100103 absl::optional<ColorSpace> fake_color_space_ RTC_GUARDED_BY(&lock_);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000104
105 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700106 // Must be the last field, so it will be deconstructed first as tasks
107 // in the TaskQueue access other fields of the instance of this class.
108 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000109};
ilnikbaded152017-03-17 05:55:25 -0700110} // namespace test
111} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000112
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200113#endif // TEST_FRAME_GENERATOR_CAPTURER_H_