blob: dfe35b832e7baa1f324db0f7dbb1cf899b8899ee [file] [log] [blame]
andresp@webrtc.orgab654952013-09-19 12:14:03 +00001/*
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 */
perkja49cbd32016-09-16 07:53:41 -070010#ifndef WEBRTC_TEST_FRAME_GENERATOR_H_
11#define WEBRTC_TEST_FRAME_GENERATOR_H_
andresp@webrtc.orgab654952013-09-19 12:14:03 +000012
perkja8ba1952017-02-27 06:52:10 -080013#include <memory>
sprang@webrtc.org131bea82015-02-18 12:46:06 +000014#include <string>
15#include <vector>
16
nisseaf916892017-01-10 07:44:26 -080017#include "webrtc/api/video/video_frame.h"
perkja49cbd32016-09-16 07:53:41 -070018#include "webrtc/media/base/videosourceinterface.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020019#include "webrtc/rtc_base/criticalsection.h"
andresp@webrtc.orgab654952013-09-19 12:14:03 +000020#include "webrtc/typedefs.h"
21
22namespace webrtc {
sprangd6358952015-07-29 07:58:13 -070023class Clock;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000024namespace test {
25
perkja49cbd32016-09-16 07:53:41 -070026// 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.
30class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> {
31 public:
32 FrameForwarder();
sprangb1ca0732017-02-01 08:38:12 -080033 virtual ~FrameForwarder();
perkja49cbd32016-09-16 07:53:41 -070034 // Forwards |video_frame| to the registered |sink_|.
sprangb1ca0732017-02-01 08:38:12 -080035 virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
perkj803d97f2016-11-01 11:45:46 -070036 rtc::VideoSinkWants sink_wants() const;
37 bool has_sinks() const;
perkja49cbd32016-09-16 07:53:41 -070038
sprangb1ca0732017-02-01 08:38:12 -080039 protected:
perkja49cbd32016-09-16 07:53:41 -070040 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_;
45 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(crit_);
perkj803d97f2016-11-01 11:45:46 -070046 rtc::VideoSinkWants sink_wants_ GUARDED_BY(crit_);
perkja49cbd32016-09-16 07:53:41 -070047};
48
andresp@webrtc.orgab654952013-09-19 12:14:03 +000049class FrameGenerator {
50 public:
perkja8ba1952017-02-27 06:52:10 -080051 virtual ~FrameGenerator() = default;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000052
53 // Returns video frame that remains valid until next call.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070054 virtual VideoFrame* NextFrame() = 0;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000055
perkjfa10b552016-10-02 23:45:26 -070056 // Change the capture resolution.
57 virtual void ChangeResolution(size_t width, size_t height) {
58 RTC_NOTREACHED();
59 }
60
perkja8ba1952017-02-27 06:52:10 -080061 // 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);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000065
66 // Creates a frame generator that repeatedly plays a set of yuv files.
67 // The frame_repeat_count determines how many times each frame is shown,
sprang@webrtc.org25dd1db2015-03-02 11:55:45 +000068 // with 1 = show each frame once, etc.
perkja8ba1952017-02-27 06:52:10 -080069 static std::unique_ptr<FrameGenerator> CreateFromYuvFile(
70 std::vector<std::string> files,
71 size_t width,
72 size_t height,
73 int frame_repeat_count);
sprangd6358952015-07-29 07:58:13 -070074
75 // Creates a frame generator which takes a set of yuv files (wrapping a
76 // frame generator created by CreateFromYuvFile() above), but outputs frames
77 // that have been cropped to specified resolution: source_width/source_height
78 // is the size of the source images, target_width/target_height is the size of
79 // the cropped output. For each source image read, the cropped viewport will
80 // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
81 // After that the image will stay in place for pause_time_ms milliseconds,
82 // and then this will be repeated with the next file from the input set.
perkja8ba1952017-02-27 06:52:10 -080083 static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 07:58:13 -070084 Clock* clock,
85 std::vector<std::string> filenames,
86 size_t source_width,
87 size_t source_height,
88 size_t target_width,
89 size_t target_height,
90 int64_t scroll_time_ms,
91 int64_t pause_time_ms);
erikvarga579de6f2017-08-29 09:12:57 -070092
93 // Creates a frame generator that produces randomly generated slides.
94 // frame_repeat_count determines how many times each slide is shown.
95 static std::unique_ptr<FrameGenerator> CreateSlideGenerator(
96 int width, int height, int frame_repeat_count);
andresp@webrtc.orgab654952013-09-19 12:14:03 +000097};
98} // namespace test
99} // namespace webrtc
100
perkja49cbd32016-09-16 07:53:41 -0700101#endif // WEBRTC_TEST_FRAME_GENERATOR_H_