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 | */ |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 10 | #ifndef WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_ |
| 11 | #define WEBRTC_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 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 16 | #include "webrtc/api/video/video_frame.h" |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 17 | #include "webrtc/base/criticalsection.h" |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame^] | 18 | #include "webrtc/base/task_queue.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 19 | #include "webrtc/test/video_capturer.h" |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 20 | #include "webrtc/typedefs.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 24 | class CriticalSectionWrapper; |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 25 | class EventTimerWrapper; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 26 | |
| 27 | namespace test { |
| 28 | |
| 29 | class FrameGenerator; |
| 30 | |
| 31 | class FrameGeneratorCapturer : public VideoCapturer { |
| 32 | public: |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 33 | class SinkWantsObserver { |
| 34 | public: |
| 35 | // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink |
| 36 | // is called. |
| 37 | virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 38 | const rtc::VideoSinkWants& wants) = 0; |
| 39 | |
| 40 | protected: |
| 41 | virtual ~SinkWantsObserver() {} |
| 42 | }; |
| 43 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 44 | static FrameGeneratorCapturer* Create(int width, |
| 45 | int height, |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 46 | int target_fps, |
| 47 | Clock* clock); |
| 48 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 49 | static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name, |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 50 | size_t width, |
| 51 | size_t height, |
| 52 | int target_fps, |
| 53 | Clock* clock); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 54 | virtual ~FrameGeneratorCapturer(); |
| 55 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 56 | void Start() override; |
| 57 | void Stop() override; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 58 | void ChangeResolution(size_t width, size_t height); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 59 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 60 | void SetSinkWantsObserver(SinkWantsObserver* observer); |
| 61 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 62 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 63 | const rtc::VideoSinkWants& wants) override; |
| 64 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
| 65 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 66 | void ForceFrame(); |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 67 | void SetFakeRotation(VideoRotation rotation); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 68 | |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 69 | int64_t first_frame_capture_time() const { return first_frame_capture_time_; } |
| 70 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 71 | FrameGeneratorCapturer(Clock* clock, |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 72 | std::unique_ptr<FrameGenerator> frame_generator, |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 +0000 | [diff] [blame] | 73 | int target_fps); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 74 | bool Init(); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 75 | |
| 76 | private: |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame^] | 77 | class InsertFrameTask; |
| 78 | |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 79 | void InsertFrame(); |
| 80 | static bool Run(void* obj); |
| 81 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 82 | Clock* const clock_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 83 | bool sending_; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 84 | rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(&lock_); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 85 | SinkWantsObserver* sink_wants_observer_ GUARDED_BY(&lock_); |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 86 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 87 | rtc::CriticalSection lock_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 88 | std::unique_ptr<FrameGenerator> frame_generator_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 89 | |
| 90 | int target_fps_; |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 91 | VideoRotation fake_rotation_ = kVideoRotation_0; |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 92 | |
| 93 | int64_t first_frame_capture_time_; |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame^] | 94 | // Must be the last field, so it will be deconstructed first as tasks |
| 95 | // in the TaskQueue access other fields of the instance of this class. |
| 96 | rtc::TaskQueue task_queue_; |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 97 | }; |
ilnik | baded15 | 2017-03-17 05:55:25 -0700 | [diff] [blame^] | 98 | } // namespace test |
| 99 | } // namespace webrtc |
pbos@webrtc.org | 26d1210 | 2013-05-29 13:41:03 +0000 | [diff] [blame] | 100 | |
Peter Boström | 7623ce4 | 2015-12-09 12:13:30 +0100 | [diff] [blame] | 101 | #endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_ |