blob: 45cc9f0f13d078e893b0a57fcad12402db8fab96 [file] [log] [blame]
andresp@webrtc.orgab654952013-09-19 12:14:031/*
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 04:47:3110#ifndef TEST_FRAME_GENERATOR_H_
11#define TEST_FRAME_GENERATOR_H_
andresp@webrtc.orgab654952013-09-19 12:14:0312
perkja8ba1952017-02-27 14:52:1013#include <memory>
sprang@webrtc.org131bea82015-02-18 12:46:0614#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "api/video/video_frame.h"
Niels Möller0327c2d2018-05-21 12:09:3118#include "api/video/video_source_interface.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "rtc_base/criticalsection.h"
andresp@webrtc.orgab654952013-09-19 12:14:0320
21namespace webrtc {
sprangd6358952015-07-29 14:58:1322class Clock;
andresp@webrtc.orgab654952013-09-19 12:14:0323namespace test {
24
perkja49cbd32016-09-16 14:53:4125// 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();
sprangb1ca0732017-02-01 16:38:1232 virtual ~FrameForwarder();
perkja49cbd32016-09-16 14:53:4133 // Forwards |video_frame| to the registered |sink_|.
sprangb1ca0732017-02-01 16:38:1234 virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
perkj803d97f2016-11-01 18:45:4635 rtc::VideoSinkWants sink_wants() const;
36 bool has_sinks() const;
perkja49cbd32016-09-16 14:53:4137
sprangb1ca0732017-02-01 16:38:1238 protected:
perkja49cbd32016-09-16 14:53:4139 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 11:17:2244 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
45 rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
perkja49cbd32016-09-16 14:53:4146};
47
andresp@webrtc.orgab654952013-09-19 12:14:0348class FrameGenerator {
49 public:
perkja8ba1952017-02-27 14:52:1050 virtual ~FrameGenerator() = default;
andresp@webrtc.orgab654952013-09-19 12:14:0351
52 // Returns video frame that remains valid until next call.
Johannes Kronf7f13e02018-12-12 10:17:4353 // 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-30 00:21:4056 virtual VideoFrame* NextFrame() = 0;
andresp@webrtc.orgab654952013-09-19 12:14:0357
perkjfa10b552016-10-03 06:45:2658 // Change the capture resolution.
59 virtual void ChangeResolution(size_t width, size_t height) {
60 RTC_NOTREACHED();
61 }
62
Emircan Uysaler0823eec2018-07-14 00:10:0063 enum class OutputType { I420, I420A, I010 };
Emircan Uysaler207a75d2018-03-12 21:12:1464
perkja8ba1952017-02-27 14:52:1065 // Creates a frame generator that produces frames with small squares that
66 // move randomly towards the lower right corner.
Emircan Uysaler207a75d2018-03-12 21:12:1467 // |type| has the default value OutputType::I420. |num_squares| has the
68 // default value 10.
Emircan Uysaler03e6ec92018-03-09 23:03:2669 static std::unique_ptr<FrameGenerator> CreateSquareGenerator(
70 int width,
71 int height,
Danil Chapovalov431abd92018-06-18 10:54:1772 absl::optional<OutputType> type,
73 absl::optional<int> num_squares);
sprang@webrtc.org131bea82015-02-18 12:46:0674
75 // Creates a frame generator that repeatedly plays a set of yuv files.
76 // The frame_repeat_count determines how many times each frame is shown,
sprang@webrtc.org25dd1db2015-03-02 11:55:4577 // with 1 = show each frame once, etc.
perkja8ba1952017-02-27 14:52:1078 static std::unique_ptr<FrameGenerator> CreateFromYuvFile(
79 std::vector<std::string> files,
80 size_t width,
81 size_t height,
82 int frame_repeat_count);
sprangd6358952015-07-29 14:58:1383
84 // Creates a frame generator which takes a set of yuv files (wrapping a
85 // frame generator created by CreateFromYuvFile() above), but outputs frames
86 // that have been cropped to specified resolution: source_width/source_height
87 // is the size of the source images, target_width/target_height is the size of
88 // the cropped output. For each source image read, the cropped viewport will
89 // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
90 // After that the image will stay in place for pause_time_ms milliseconds,
91 // and then this will be repeated with the next file from the input set.
perkja8ba1952017-02-27 14:52:1092 static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 14:58:1393 Clock* clock,
94 std::vector<std::string> filenames,
95 size_t source_width,
96 size_t source_height,
97 size_t target_width,
98 size_t target_height,
99 int64_t scroll_time_ms,
100 int64_t pause_time_ms);
erikvarga579de6f2017-08-29 16:12:57101
102 // Creates a frame generator that produces randomly generated slides.
103 // frame_repeat_count determines how many times each slide is shown.
Yves Gerey665174f2018-06-19 13:03:05104 static std::unique_ptr<FrameGenerator>
105 CreateSlideGenerator(int width, int height, int frame_repeat_count);
andresp@webrtc.orgab654952013-09-19 12:14:03106};
107} // namespace test
108} // namespace webrtc
109
Mirko Bonadei92ea95e2017-09-15 04:47:31110#endif // TEST_FRAME_GENERATOR_H_