blob: 31543bc6d1b189e098bf784a25fc2a48ddeac7f0 [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"
Niels Möller0327c2d2018-05-21 14:09:31 +020018#include "api/video/video_source_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/critical_section.h"
andresp@webrtc.orgab654952013-09-19 12:14:03 +000020
21namespace webrtc {
sprangd6358952015-07-29 07:58:13 -070022class Clock;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000023namespace test {
24
perkja49cbd32016-09-16 07:53:41 -070025// 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.
29class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> {
30 public:
31 FrameForwarder();
Artem Titovf50c6c22019-01-24 16:54:03 +010032 ~FrameForwarder() override;
perkja49cbd32016-09-16 07:53:41 -070033 // Forwards |video_frame| to the registered |sink_|.
sprangb1ca0732017-02-01 08:38:12 -080034 virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
perkj803d97f2016-11-01 11:45:46 -070035 rtc::VideoSinkWants sink_wants() const;
36 bool has_sinks() const;
perkja49cbd32016-09-16 07:53:41 -070037
sprangb1ca0732017-02-01 08:38:12 -080038 protected:
perkja49cbd32016-09-16 07:53:41 -070039 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_;
danilchapa37de392017-09-09 04:17:22 -070044 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
45 rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
perkja49cbd32016-09-16 07:53:41 -070046};
47
andresp@webrtc.orgab654952013-09-19 12:14:03 +000048class FrameGenerator {
49 public:
perkja8ba1952017-02-27 06:52:10 -080050 virtual ~FrameGenerator() = default;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000051
52 // Returns video frame that remains valid until next call.
Johannes Kronf7f13e02018-12-12 11:17:43 +010053 // TODO(kron): Return rtc::scoped_refptr<VideoFrameBuffer> instead of
54 // VideoFrame* and populate the VideoFrame struct in FrameGeneratorCapturer
55 // using VideoFrame::Builder.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070056 virtual VideoFrame* NextFrame() = 0;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000057
perkjfa10b552016-10-02 23:45:26 -070058 // Change the capture resolution.
Artem Titovf50c6c22019-01-24 16:54:03 +010059 virtual void ChangeResolution(size_t width, size_t height);
perkjfa10b552016-10-02 23:45:26 -070060
Sebastian Janssoned0febf2019-07-26 15:58:11 +020061 enum class OutputType {
62 kI420,
63 // TODO(srte): Remove alias when downstream is updated.
64 I420 = kI420,
65 kI420A,
66 kI010
67 };
Emircan Uysaler207a75d2018-03-12 14:12:14 -070068
perkja8ba1952017-02-27 06:52:10 -080069 // Creates a frame generator that produces frames with small squares that
70 // move randomly towards the lower right corner.
Emircan Uysaler207a75d2018-03-12 14:12:14 -070071 // |type| has the default value OutputType::I420. |num_squares| has the
72 // default value 10.
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080073 static std::unique_ptr<FrameGenerator> CreateSquareGenerator(
74 int width,
75 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +020076 absl::optional<OutputType> type,
77 absl::optional<int> num_squares);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000078
79 // Creates a frame generator that repeatedly plays a set of yuv files.
80 // The frame_repeat_count determines how many times each frame is shown,
sprang@webrtc.org25dd1db2015-03-02 11:55:45 +000081 // with 1 = show each frame once, etc.
perkja8ba1952017-02-27 06:52:10 -080082 static std::unique_ptr<FrameGenerator> CreateFromYuvFile(
83 std::vector<std::string> files,
84 size_t width,
85 size_t height,
86 int frame_repeat_count);
sprangd6358952015-07-29 07:58:13 -070087
88 // Creates a frame generator which takes a set of yuv files (wrapping a
89 // frame generator created by CreateFromYuvFile() above), but outputs frames
90 // that have been cropped to specified resolution: source_width/source_height
91 // is the size of the source images, target_width/target_height is the size of
92 // the cropped output. For each source image read, the cropped viewport will
93 // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
94 // After that the image will stay in place for pause_time_ms milliseconds,
95 // and then this will be repeated with the next file from the input set.
perkja8ba1952017-02-27 06:52:10 -080096 static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 07:58:13 -070097 Clock* clock,
98 std::vector<std::string> filenames,
99 size_t source_width,
100 size_t source_height,
101 size_t target_width,
102 size_t target_height,
103 int64_t scroll_time_ms,
104 int64_t pause_time_ms);
erikvarga579de6f2017-08-29 09:12:57 -0700105
106 // Creates a frame generator that produces randomly generated slides.
107 // frame_repeat_count determines how many times each slide is shown.
Yves Gerey665174f2018-06-19 15:03:05 +0200108 static std::unique_ptr<FrameGenerator>
109 CreateSlideGenerator(int width, int height, int frame_repeat_count);
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000110};
111} // namespace test
112} // namespace webrtc
113
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200114#endif // TEST_FRAME_GENERATOR_H_