blob: e7e2c121e1c47676df273dfbd30c1b1db5cc2a94 [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"
Patrik Höglund9e194032018-01-04 14:58:2018#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "rtc_base/criticalsection.h"
Mirko Bonadei71207422017-09-15 11:58:0920#include "typedefs.h" // NOLINT(build/include)
andresp@webrtc.orgab654952013-09-19 12:14:0321
22namespace webrtc {
sprangd6358952015-07-29 14:58:1323class Clock;
andresp@webrtc.orgab654952013-09-19 12:14:0324namespace test {
25
perkja49cbd32016-09-16 14:53:4126// 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 16:38:1233 virtual ~FrameForwarder();
perkja49cbd32016-09-16 14:53:4134 // Forwards |video_frame| to the registered |sink_|.
sprangb1ca0732017-02-01 16:38:1235 virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
perkj803d97f2016-11-01 18:45:4636 rtc::VideoSinkWants sink_wants() const;
37 bool has_sinks() const;
perkja49cbd32016-09-16 14:53:4138
sprangb1ca0732017-02-01 16:38:1239 protected:
perkja49cbd32016-09-16 14:53:4140 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 11:17:2245 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
46 rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
perkja49cbd32016-09-16 14:53:4147};
48
andresp@webrtc.orgab654952013-09-19 12:14:0349class FrameGenerator {
50 public:
perkja8ba1952017-02-27 14:52:1051 virtual ~FrameGenerator() = default;
andresp@webrtc.orgab654952013-09-19 12:14:0352
53 // Returns video frame that remains valid until next call.
Miguel Casas-Sanchez47650702015-05-30 00:21:4054 virtual VideoFrame* NextFrame() = 0;
andresp@webrtc.orgab654952013-09-19 12:14:0355
perkjfa10b552016-10-03 06:45:2656 // Change the capture resolution.
57 virtual void ChangeResolution(size_t width, size_t height) {
58 RTC_NOTREACHED();
59 }
60
perkja8ba1952017-02-27 14:52:1061 // 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 12:34:3865 static std::unique_ptr<FrameGenerator> CreateSquareGenerator(int width,
66 int height,
67 int num_squares);
sprang@webrtc.org131bea82015-02-18 12:46:0668
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:4571 // with 1 = show each frame once, etc.
perkja8ba1952017-02-27 14:52:1072 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 14:58:1377
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 14:52:1086 static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 14:58:1387 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 16:12:5795
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:03100};
101} // namespace test
102} // namespace webrtc
103
Mirko Bonadei92ea95e2017-09-15 04:47:31104#endif // TEST_FRAME_GENERATOR_H_