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 | */ |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 10 | #ifndef WEBRTC_TEST_FRAME_GENERATOR_H_ |
| 11 | #define WEBRTC_TEST_FRAME_GENERATOR_H_ |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 12 | |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
| 17 | #include "webrtc/media/base/videosourceinterface.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
Thiago Farina | 9bfe3da | 2015-04-10 12:52:13 +0200 | [diff] [blame] | 19 | #include "webrtc/video_frame.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(); |
| 32 | // Forwards |video_frame| to the registered |sink_|. |
| 33 | void IncomingCapturedFrame(const VideoFrame& video_frame); |
| 34 | |
| 35 | private: |
| 36 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 37 | const rtc::VideoSinkWants& wants) override; |
| 38 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override; |
| 39 | |
| 40 | rtc::CriticalSection crit_; |
| 41 | rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(crit_); |
| 42 | }; |
| 43 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 44 | class FrameGenerator { |
| 45 | public: |
| 46 | FrameGenerator() {} |
| 47 | virtual ~FrameGenerator() {} |
| 48 | |
| 49 | // Returns video frame that remains valid until next call. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 50 | virtual VideoFrame* NextFrame() = 0; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 51 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame^] | 52 | // Change the capture resolution. |
| 53 | virtual void ChangeResolution(size_t width, size_t height) { |
| 54 | RTC_NOTREACHED(); |
| 55 | } |
| 56 | |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 57 | // Creates a test frame generator that creates fully saturated frames with |
| 58 | // varying U, V values over time. |
| 59 | static FrameGenerator* CreateChromaGenerator(size_t width, size_t height); |
| 60 | |
| 61 | // Creates a frame generator that repeatedly plays a set of yuv files. |
| 62 | // 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] | 63 | // with 1 = show each frame once, etc. |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 64 | static FrameGenerator* CreateFromYuvFile(std::vector<std::string> files, |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 65 | size_t width, |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 66 | size_t height, |
| 67 | int frame_repeat_count); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 68 | |
| 69 | // Creates a frame generator which takes a set of yuv files (wrapping a |
| 70 | // frame generator created by CreateFromYuvFile() above), but outputs frames |
| 71 | // that have been cropped to specified resolution: source_width/source_height |
| 72 | // is the size of the source images, target_width/target_height is the size of |
| 73 | // the cropped output. For each source image read, the cropped viewport will |
| 74 | // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds. |
| 75 | // After that the image will stay in place for pause_time_ms milliseconds, |
| 76 | // and then this will be repeated with the next file from the input set. |
| 77 | static FrameGenerator* CreateScrollingInputFromYuvFiles( |
| 78 | Clock* clock, |
| 79 | std::vector<std::string> filenames, |
| 80 | size_t source_width, |
| 81 | size_t source_height, |
| 82 | size_t target_width, |
| 83 | size_t target_height, |
| 84 | int64_t scroll_time_ms, |
| 85 | int64_t pause_time_ms); |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 86 | }; |
| 87 | } // namespace test |
| 88 | } // namespace webrtc |
| 89 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 90 | #endif // WEBRTC_TEST_FRAME_GENERATOR_H_ |