pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [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 04:47:31 | [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 | [diff] [blame] | 12 | |
kwiberg | bfefb03 | 2016-05-01 21:53:46 | [diff] [blame] | 13 | #include <memory> |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "api/video/video_frame.h" |
| 17 | #include "rtc_base/criticalsection.h" |
| 18 | #include "rtc_base/task_queue.h" |
Emircan Uysaler | 03e6ec9 | 2018-03-09 23:03:26 | [diff] [blame] | 19 | #include "test/frame_generator.h" |
Sebastian Jansson | f1f363f | 2018-08-13 12:24:58 | [diff] [blame] | 20 | #include "test/test_video_capturer.h" |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 24 | namespace test { |
| 25 | |
| 26 | class FrameGenerator; |
| 27 | |
Sebastian Jansson | f1f363f | 2018-08-13 12:24:58 | [diff] [blame] | 28 | class FrameGeneratorCapturer : public TestVideoCapturer { |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 29 | public: |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 30 | 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 Uysaler | 207a75d | 2018-03-12 21:12:14 | [diff] [blame] | 41 | // |type| has the default value OutputType::I420. |num_squares| has the |
| 42 | // default value 10. |
Emircan Uysaler | 03e6ec9 | 2018-03-09 23:03:26 | [diff] [blame] | 43 | static FrameGeneratorCapturer* Create( |
| 44 | int width, |
| 45 | int height, |
Danil Chapovalov | 431abd9 | 2018-06-18 10:54:17 | [diff] [blame] | 46 | absl::optional<FrameGenerator::OutputType> type, |
| 47 | absl::optional<int> num_squares, |
Emircan Uysaler | 03e6ec9 | 2018-03-09 23:03:26 | [diff] [blame] | 48 | int target_fps, |
| 49 | Clock* clock); |
Taylor Brandstetter | 081136f | 2018-03-08 01:54:10 | [diff] [blame] | 50 | |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 51 | static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name, |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 | [diff] [blame] | 52 | size_t width, |
| 53 | size_t height, |
| 54 | int target_fps, |
| 55 | Clock* clock); |
erikvarga | 579de6f | 2017-08-29 16:12:57 | [diff] [blame] | 56 | |
| 57 | static FrameGeneratorCapturer* CreateSlideGenerator(int width, |
| 58 | int height, |
| 59 | int frame_repeat_count, |
| 60 | int target_fps, |
| 61 | Clock* clock); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 62 | virtual ~FrameGeneratorCapturer(); |
| 63 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 64 | void Start() override; |
| 65 | void Stop() override; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 66 | void ChangeResolution(size_t width, size_t height); |
Sebastian Jansson | ba3decf | 2018-08-30 09:19:23 | [diff] [blame] | 67 | void ChangeFramerate(int target_framerate); |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 68 | |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 69 | void SetSinkWantsObserver(SinkWantsObserver* observer); |
| 70 | |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 71 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 72 | const rtc::VideoSinkWants& wants) override; |
| 73 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
| 74 | |
sprang | 867fb52 | 2015-08-03 11:38:41 | [diff] [blame] | 75 | void ForceFrame(); |
Per | ba7dc72 | 2016-04-19 13:01:23 | [diff] [blame] | 76 | void SetFakeRotation(VideoRotation rotation); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 77 | |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 78 | int64_t first_frame_capture_time() const { return first_frame_capture_time_; } |
| 79 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 | [diff] [blame] | 80 | FrameGeneratorCapturer(Clock* clock, |
perkj | a8ba195 | 2017-02-27 14:52:10 | [diff] [blame] | 81 | std::unique_ptr<FrameGenerator> frame_generator, |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 | [diff] [blame] | 82 | int target_fps); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 83 | bool Init(); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 | [diff] [blame] | 84 | |
| 85 | private: |
ilnik | baded15 | 2017-03-17 12:55:25 | [diff] [blame] | 86 | class InsertFrameTask; |
| 87 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 88 | void InsertFrame(); |
| 89 | static bool Run(void* obj); |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 90 | int GetCurrentConfiguredFramerate(); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 91 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 | [diff] [blame] | 92 | Clock* const clock_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 93 | bool sending_; |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 94 | rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_); |
| 95 | SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 96 | |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 97 | rtc::CriticalSection lock_; |
kwiberg | bfefb03 | 2016-05-01 21:53:46 | [diff] [blame] | 98 | std::unique_ptr<FrameGenerator> frame_generator_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 99 | |
Sebastian Jansson | ba3decf | 2018-08-30 09:19:23 | [diff] [blame] | 100 | int source_fps_ RTC_GUARDED_BY(&lock_); |
| 101 | int target_capture_fps_ RTC_GUARDED_BY(&lock_); |
Danil Chapovalov | 431abd9 | 2018-06-18 10:54:17 | [diff] [blame] | 102 | absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_); |
Per | ba7dc72 | 2016-04-19 13:01:23 | [diff] [blame] | 103 | VideoRotation fake_rotation_ = kVideoRotation_0; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 104 | |
| 105 | int64_t first_frame_capture_time_; |
ilnik | baded15 | 2017-03-17 12:55:25 | [diff] [blame] | 106 | // 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.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 109 | }; |
ilnik | baded15 | 2017-03-17 12:55:25 | [diff] [blame] | 110 | } // namespace test |
| 111 | } // namespace webrtc |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 | [diff] [blame] | 112 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 113 | #endif // TEST_FRAME_GENERATOR_CAPTURER_H_ |