andresp@webrtc.org | ab65495 | 2013-09-19 12:14: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_H_ |
| 11 | #define TEST_FRAME_GENERATOR_H_ |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 12 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 13 | #include <memory> |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/video/video_frame.h" |
Niels Möller | 0327c2d | 2018-05-21 14:09:31 +0200 | [diff] [blame] | 18 | #include "api/video/video_source_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/critical_section.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 22 | class Clock; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 23 | namespace test { |
| 24 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 25 | // FrameForwarder can be used as an implementation |
| 26 | // of rtc::VideoSourceInterface<VideoFrame> where the caller controls when |
| 27 | // a frame should be forwarded to its sink. |
| 28 | // Currently this implementation only support one sink. |
| 29 | class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> { |
| 30 | public: |
| 31 | FrameForwarder(); |
Artem Titov | f50c6c2 | 2019-01-24 16:54:03 +0100 | [diff] [blame] | 32 | ~FrameForwarder() override; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 33 | // Forwards |video_frame| to the registered |sink_|. |
sprang | b1ca073 | 2017-02-01 08:38:12 -0800 | [diff] [blame] | 34 | virtual void IncomingCapturedFrame(const VideoFrame& video_frame); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 35 | rtc::VideoSinkWants sink_wants() const; |
| 36 | bool has_sinks() const; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 37 | |
sprang | b1ca073 | 2017-02-01 08:38:12 -0800 | [diff] [blame] | 38 | protected: |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 39 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 40 | const rtc::VideoSinkWants& wants) override; |
| 41 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
| 42 | |
| 43 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 44 | rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_); |
| 45 | rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 48 | class FrameGenerator { |
| 49 | public: |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 50 | virtual ~FrameGenerator() = default; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 51 | |
| 52 | // Returns video frame that remains valid until next call. |
Johannes Kron | f7f13e0 | 2018-12-12 11:17:43 +0100 | [diff] [blame] | 53 | // TODO(kron): Return rtc::scoped_refptr<VideoFrameBuffer> instead of |
| 54 | // VideoFrame* and populate the VideoFrame struct in FrameGeneratorCapturer |
| 55 | // using VideoFrame::Builder. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 56 | virtual VideoFrame* NextFrame() = 0; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 57 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 58 | // Change the capture resolution. |
Artem Titov | f50c6c2 | 2019-01-24 16:54:03 +0100 | [diff] [blame] | 59 | virtual void ChangeResolution(size_t width, size_t height); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 60 | |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 61 | enum class OutputType { I420, I420A, I010 }; |
Emircan Uysaler | 207a75d | 2018-03-12 14:12:14 -0700 | [diff] [blame] | 62 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 63 | // Creates a frame generator that produces frames with small squares that |
| 64 | // move randomly towards the lower right corner. |
Emircan Uysaler | 207a75d | 2018-03-12 14:12:14 -0700 | [diff] [blame] | 65 | // |type| has the default value OutputType::I420. |num_squares| has the |
| 66 | // default value 10. |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 67 | static std::unique_ptr<FrameGenerator> CreateSquareGenerator( |
| 68 | int width, |
| 69 | int height, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 70 | absl::optional<OutputType> type, |
| 71 | absl::optional<int> num_squares); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 72 | |
| 73 | // Creates a frame generator that repeatedly plays a set of yuv files. |
| 74 | // The frame_repeat_count determines how many times each frame is shown, |
sprang@webrtc.org | 25dd1db | 2015-03-02 11:55:45 +0000 | [diff] [blame] | 75 | // with 1 = show each frame once, etc. |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 76 | static std::unique_ptr<FrameGenerator> CreateFromYuvFile( |
| 77 | std::vector<std::string> files, |
| 78 | size_t width, |
| 79 | size_t height, |
| 80 | int frame_repeat_count); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 81 | |
| 82 | // Creates a frame generator which takes a set of yuv files (wrapping a |
| 83 | // frame generator created by CreateFromYuvFile() above), but outputs frames |
| 84 | // that have been cropped to specified resolution: source_width/source_height |
| 85 | // is the size of the source images, target_width/target_height is the size of |
| 86 | // the cropped output. For each source image read, the cropped viewport will |
| 87 | // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds. |
| 88 | // After that the image will stay in place for pause_time_ms milliseconds, |
| 89 | // and then this will be repeated with the next file from the input set. |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 90 | static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles( |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 91 | Clock* clock, |
| 92 | std::vector<std::string> filenames, |
| 93 | size_t source_width, |
| 94 | size_t source_height, |
| 95 | size_t target_width, |
| 96 | size_t target_height, |
| 97 | int64_t scroll_time_ms, |
| 98 | int64_t pause_time_ms); |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 99 | |
| 100 | // Creates a frame generator that produces randomly generated slides. |
| 101 | // frame_repeat_count determines how many times each slide is shown. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 102 | static std::unique_ptr<FrameGenerator> |
| 103 | CreateSlideGenerator(int width, int height, int frame_repeat_count); |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 104 | }; |
| 105 | } // namespace test |
| 106 | } // namespace webrtc |
| 107 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 108 | #endif // TEST_FRAME_GENERATOR_H_ |