blob: e7e2c121e1c47676df273dfbd30c1b1db5cc2a94 [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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_FRAME_GENERATOR_H_
11#define 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/video/video_frame.h"
Patrik Höglund9e194032018-01-04 15:58:20 +010018#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/criticalsection.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020020#include "typedefs.h" // NOLINT(build/include)
andresp@webrtc.orgab654952013-09-19 12:14:03 +000021
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_;
danilchapa37de392017-09-09 04:17:22 -070045 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
46 rtc::VideoSinkWants sink_wants_ RTC_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);
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020065 static std::unique_ptr<FrameGenerator> CreateSquareGenerator(int width,
66 int height,
67 int num_squares);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000068
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.org25dd1db2015-03-02 11:55:45 +000071 // with 1 = show each frame once, etc.
perkja8ba1952017-02-27 06:52:10 -080072 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);
sprangd6358952015-07-29 07:58:13 -070077
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.
perkja8ba1952017-02-27 06:52:10 -080086 static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 07:58:13 -070087 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);
erikvarga579de6f2017-08-29 09:12:57 -070095
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.orgab654952013-09-19 12:14:03 +0000100};
101} // namespace test
102} // namespace webrtc
103
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200104#endif // TEST_FRAME_GENERATOR_H_