blob: cea3dda1c238af42204fbb3950e316e85d9a87b4 [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
sprang@webrtc.org131bea82015-02-18 12:46:06 +000013#include <string>
14#include <vector>
15
nisseaf916892017-01-10 07:44:26 -080016#include "webrtc/api/video/video_frame.h"
perkja49cbd32016-09-16 07:53:41 -070017#include "webrtc/base/criticalsection.h"
18#include "webrtc/media/base/videosourceinterface.h"
andresp@webrtc.orgab654952013-09-19 12:14:03 +000019#include "webrtc/typedefs.h"
20
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();
32 // Forwards |video_frame| to the registered |sink_|.
33 void IncomingCapturedFrame(const VideoFrame& video_frame);
perkj803d97f2016-11-01 11:45:46 -070034 rtc::VideoSinkWants sink_wants() const;
35 bool has_sinks() const;
perkja49cbd32016-09-16 07:53:41 -070036
37 private:
38 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
39 const rtc::VideoSinkWants& wants) override;
40 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
41
42 rtc::CriticalSection crit_;
43 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(crit_);
perkj803d97f2016-11-01 11:45:46 -070044 rtc::VideoSinkWants sink_wants_ GUARDED_BY(crit_);
perkja49cbd32016-09-16 07:53:41 -070045};
46
andresp@webrtc.orgab654952013-09-19 12:14:03 +000047class FrameGenerator {
48 public:
49 FrameGenerator() {}
50 virtual ~FrameGenerator() {}
51
52 // Returns video frame that remains valid until next call.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070053 virtual VideoFrame* NextFrame() = 0;
andresp@webrtc.orgab654952013-09-19 12:14:03 +000054
perkjfa10b552016-10-02 23:45:26 -070055 // Change the capture resolution.
56 virtual void ChangeResolution(size_t width, size_t height) {
57 RTC_NOTREACHED();
58 }
59
sprang@webrtc.org131bea82015-02-18 12:46:06 +000060 // Creates a test frame generator that creates fully saturated frames with
61 // varying U, V values over time.
62 static FrameGenerator* CreateChromaGenerator(size_t width, size_t height);
63
64 // Creates a frame generator that repeatedly plays a set of yuv files.
65 // The frame_repeat_count determines how many times each frame is shown,
sprang@webrtc.org25dd1db2015-03-02 11:55:45 +000066 // with 1 = show each frame once, etc.
sprang@webrtc.org131bea82015-02-18 12:46:06 +000067 static FrameGenerator* CreateFromYuvFile(std::vector<std::string> files,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000068 size_t width,
sprang@webrtc.org131bea82015-02-18 12:46:06 +000069 size_t height,
70 int frame_repeat_count);
sprangd6358952015-07-29 07:58:13 -070071
72 // Creates a frame generator which takes a set of yuv files (wrapping a
73 // frame generator created by CreateFromYuvFile() above), but outputs frames
74 // that have been cropped to specified resolution: source_width/source_height
75 // is the size of the source images, target_width/target_height is the size of
76 // the cropped output. For each source image read, the cropped viewport will
77 // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
78 // After that the image will stay in place for pause_time_ms milliseconds,
79 // and then this will be repeated with the next file from the input set.
80 static FrameGenerator* CreateScrollingInputFromYuvFiles(
81 Clock* clock,
82 std::vector<std::string> filenames,
83 size_t source_width,
84 size_t source_height,
85 size_t target_width,
86 size_t target_height,
87 int64_t scroll_time_ms,
88 int64_t pause_time_ms);
andresp@webrtc.orgab654952013-09-19 12:14:03 +000089};
90} // namespace test
91} // namespace webrtc
92
perkja49cbd32016-09-16 07:53:41 -070093#endif // WEBRTC_TEST_FRAME_GENERATOR_H_