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