pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef TEST_FRAME_GENERATOR_CAPTURER_H_ |
| 11 | #define TEST_FRAME_GENERATOR_CAPTURER_H_ |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 12 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 13 | #include <memory> |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Sebastian Jansson | fb14c5d | 2019-02-28 13:30:04 +0100 | [diff] [blame] | 16 | #include "api/task_queue/task_queue_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/video/video_frame.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "rtc_base/critical_section.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/task_queue.h" |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 20 | #include "test/frame_generator.h" |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 21 | #include "test/test_video_capturer.h" |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 25 | namespace test { |
| 26 | |
| 27 | class FrameGenerator; |
| 28 | |
Sebastian Jansson | f1f363f | 2018-08-13 14:24:58 +0200 | [diff] [blame] | 29 | class FrameGeneratorCapturer : public TestVideoCapturer { |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 30 | public: |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 31 | 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 Chapovalov | 59b64d3 | 2019-04-23 13:45:12 +0200 | [diff] [blame^] | 42 | FrameGeneratorCapturer(Clock* clock, |
| 43 | std::unique_ptr<FrameGenerator> frame_generator, |
| 44 | int target_fps, |
| 45 | TaskQueueFactory& task_queue_factory); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 46 | virtual ~FrameGeneratorCapturer(); |
| 47 | |
Niels Möller | 8eeccbe | 2018-12-14 13:35:32 +0100 | [diff] [blame] | 48 | void Start(); |
| 49 | void Stop(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 50 | void ChangeResolution(size_t width, size_t height); |
Sebastian Jansson | ba3decf | 2018-08-30 11:19:23 +0200 | [diff] [blame] | 51 | void ChangeFramerate(int target_framerate); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 52 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 53 | void SetSinkWantsObserver(SinkWantsObserver* observer); |
| 54 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 55 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 56 | const rtc::VideoSinkWants& wants) override; |
| 57 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
| 58 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 59 | void ForceFrame(); |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 60 | void SetFakeRotation(VideoRotation rotation); |
Johannes Kron | f7f13e0 | 2018-12-12 11:17:43 +0100 | [diff] [blame] | 61 | void SetFakeColorSpace(absl::optional<ColorSpace> color_space); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 62 | |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 63 | int64_t first_frame_capture_time() const { return first_frame_capture_time_; } |
| 64 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 65 | bool Init(); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 66 | |
| 67 | private: |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 68 | void InsertFrame(); |
| 69 | static bool Run(void* obj); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 70 | int GetCurrentConfiguredFramerate(); |
Niels Möller | 3793bb4 | 2018-12-20 13:46:06 +0100 | [diff] [blame] | 71 | void UpdateFps(int max_fps) RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 73 | Clock* const clock_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 74 | bool sending_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 75 | SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 76 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 77 | rtc::CriticalSection lock_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 78 | std::unique_ptr<FrameGenerator> frame_generator_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 79 | |
Sebastian Jansson | ba3decf | 2018-08-30 11:19:23 +0200 | [diff] [blame] | 80 | int source_fps_ RTC_GUARDED_BY(&lock_); |
| 81 | int target_capture_fps_ RTC_GUARDED_BY(&lock_); |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 82 | absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_); |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 83 | VideoRotation fake_rotation_ = kVideoRotation_0; |
Johannes Kron | f7f13e0 | 2018-12-12 11:17:43 +0100 | [diff] [blame] | 84 | absl::optional<ColorSpace> fake_color_space_ RTC_GUARDED_BY(&lock_); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 85 | |
| 86 | int64_t first_frame_capture_time_; |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame] | 87 | // 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.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 90 | }; |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame] | 91 | } // namespace test |
| 92 | } // namespace webrtc |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 93 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 94 | #endif // TEST_FRAME_GENERATOR_CAPTURER_H_ |