blob: acd63f931220b58836b1f5cbb03e6dcf4da6b060 [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#include "test/frame_generator.h"
andresp@webrtc.orgab654952013-09-19 12:14:0311
pbos@webrtc.org266c7b32013-10-15 09:15:4712#include <math.h>
andresp@webrtc.orgab654952013-09-19 12:14:0313#include <stdio.h>
pbos@webrtc.org266c7b32013-10-15 09:15:4714#include <string.h>
andresp@webrtc.orgab654952013-09-19 12:14:0315
kwibergbfefb032016-05-01 21:53:4616#include <memory>
17
Emircan Uysaler0823eec2018-07-14 00:10:0018#include "api/video/i010_buffer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "api/video/i420_buffer.h"
20#include "common_video/include/video_frame_buffer.h"
21#include "common_video/libyuv/include/webrtc_libyuv.h"
22#include "rtc_base/checks.h"
23#include "rtc_base/keep_ref_until_done.h"
24#include "rtc_base/random.h"
25#include "system_wrappers/include/clock.h"
26#include "test/frame_utils.h"
andresp@webrtc.orgab654952013-09-19 12:14:0327
28namespace webrtc {
29namespace test {
30namespace {
31
Emircan Uysaler03e6ec92018-03-09 23:03:2632// Helper method for keeping a reference to passed pointers.
33void KeepBufferRefs(rtc::scoped_refptr<webrtc::VideoFrameBuffer>,
34 rtc::scoped_refptr<webrtc::VideoFrameBuffer>) {}
35
erikvarga@webrtc.orgc774d5d2017-10-10 12:34:3836// SquareGenerator is a FrameGenerator that draws a given amount of randomly
37// sized and colored squares. Between each new generated frame, the squares
38// are moved slightly towards the lower right corner.
perkja8ba1952017-02-27 14:52:1039class SquareGenerator : public FrameGenerator {
pbos@webrtc.org266c7b32013-10-15 09:15:4740 public:
Emircan Uysaler03e6ec92018-03-09 23:03:2641 SquareGenerator(int width, int height, OutputType type, int num_squares)
42 : type_(type) {
perkjfa10b552016-10-03 06:45:2643 ChangeResolution(width, height);
erikvarga@webrtc.orgc774d5d2017-10-10 12:34:3844 for (int i = 0; i < num_squares; ++i) {
perkja8ba1952017-02-27 14:52:1045 squares_.emplace_back(new Square(width, height, i + 1));
46 }
perkjfa10b552016-10-03 06:45:2647 }
48
49 void ChangeResolution(size_t width, size_t height) override {
50 rtc::CritScope lock(&crit_);
perkja8ba1952017-02-27 14:52:1051 width_ = static_cast<int>(width);
52 height_ = static_cast<int>(height);
nisse1996e3f2016-09-19 07:34:4653 RTC_CHECK(width_ > 0);
54 RTC_CHECK(height_ > 0);
pbos@webrtc.org266c7b32013-10-15 09:15:4755 }
56
Emircan Uysaler03e6ec92018-03-09 23:03:2657 rtc::scoped_refptr<I420Buffer> CreateI420Buffer(int width, int height) {
58 rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create(width, height));
59 memset(buffer->MutableDataY(), 127, height * buffer->StrideY());
Magnus Jedvert90e31902017-06-07 09:32:5060 memset(buffer->MutableDataU(), 127,
61 buffer->ChromaHeight() * buffer->StrideU());
62 memset(buffer->MutableDataV(), 127,
63 buffer->ChromaHeight() * buffer->StrideV());
Emircan Uysaler03e6ec92018-03-09 23:03:2664 return buffer;
65 }
66
67 VideoFrame* NextFrame() override {
68 rtc::CritScope lock(&crit_);
69
70 rtc::scoped_refptr<VideoFrameBuffer> buffer = nullptr;
71 switch (type_) {
Emircan Uysaler0823eec2018-07-14 00:10:0072 case OutputType::I420:
73 case OutputType::I010: {
Emircan Uysaler03e6ec92018-03-09 23:03:2674 buffer = CreateI420Buffer(width_, height_);
75 break;
76 }
77 case OutputType::I420A: {
78 rtc::scoped_refptr<I420Buffer> yuv_buffer =
79 CreateI420Buffer(width_, height_);
80 rtc::scoped_refptr<I420Buffer> axx_buffer =
81 CreateI420Buffer(width_, height_);
82 buffer = WrapI420ABuffer(
83 yuv_buffer->width(), yuv_buffer->height(), yuv_buffer->DataY(),
84 yuv_buffer->StrideY(), yuv_buffer->DataU(), yuv_buffer->StrideU(),
85 yuv_buffer->DataV(), yuv_buffer->StrideV(), axx_buffer->DataY(),
86 axx_buffer->StrideY(),
87 rtc::Bind(&KeepBufferRefs, yuv_buffer, axx_buffer));
88 break;
89 }
90 }
nisse1996e3f2016-09-19 07:34:4691
perkja8ba1952017-02-27 14:52:1092 for (const auto& square : squares_)
93 square->Draw(buffer);
nisse1996e3f2016-09-19 07:34:4694
Emircan Uysaler0823eec2018-07-14 00:10:0095 if (type_ == OutputType::I010) {
96 buffer = I010Buffer::Copy(*buffer->ToI420());
97 }
98
Niels Möller2ac64462018-06-11 09:14:3299 frame_.reset(
100 new VideoFrame(buffer, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 07:34:46101 return frame_.get();
pbos@webrtc.org266c7b32013-10-15 09:15:47102 }
103
104 private:
perkja8ba1952017-02-27 14:52:10105 class Square {
106 public:
107 Square(int width, int height, int seed)
108 : random_generator_(seed),
109 x_(random_generator_.Rand(0, width)),
110 y_(random_generator_.Rand(0, height)),
111 length_(random_generator_.Rand(1, width > 4 ? width / 4 : 1)),
112 yuv_y_(random_generator_.Rand(0, 255)),
113 yuv_u_(random_generator_.Rand(0, 255)),
Emircan Uysaler03e6ec92018-03-09 23:03:26114 yuv_v_(random_generator_.Rand(0, 255)),
115 yuv_a_(random_generator_.Rand(0, 255)) {}
perkja8ba1952017-02-27 14:52:10116
Emircan Uysaler03e6ec92018-03-09 23:03:26117 void Draw(const rtc::scoped_refptr<VideoFrameBuffer>& frame_buffer) {
118 RTC_DCHECK(frame_buffer->type() == VideoFrameBuffer::Type::kI420 ||
119 frame_buffer->type() == VideoFrameBuffer::Type::kI420A);
120 rtc::scoped_refptr<I420BufferInterface> buffer = frame_buffer->ToI420();
perkja8ba1952017-02-27 14:52:10121 x_ = (x_ + random_generator_.Rand(0, 4)) % (buffer->width() - length_);
122 y_ = (y_ + random_generator_.Rand(0, 4)) % (buffer->height() - length_);
Emircan Uysaler03e6ec92018-03-09 23:03:26123 for (int y = y_; y < y_ + length_; ++y) {
124 uint8_t* pos_y = (const_cast<uint8_t*>(buffer->DataY()) + x_ +
125 y * buffer->StrideY());
126 memset(pos_y, yuv_y_, length_);
127 }
perkjc8b08652017-03-22 11:57:53128
Emircan Uysaler03e6ec92018-03-09 23:03:26129 for (int y = y_; y < y_ + length_; y = y + 2) {
130 uint8_t* pos_u = (const_cast<uint8_t*>(buffer->DataU()) + x_ / 2 +
131 y / 2 * buffer->StrideU());
132 memset(pos_u, yuv_u_, length_ / 2);
133 uint8_t* pos_v = (const_cast<uint8_t*>(buffer->DataV()) + x_ / 2 +
134 y / 2 * buffer->StrideV());
135 memset(pos_v, yuv_v_, length_ / 2);
136 }
137
138 if (frame_buffer->type() == VideoFrameBuffer::Type::kI420)
139 return;
140
141 // Optionally draw on alpha plane if given.
142 const webrtc::I420ABufferInterface* yuva_buffer =
143 frame_buffer->GetI420A();
144 for (int y = y_; y < y_ + length_; ++y) {
145 uint8_t* pos_y = (const_cast<uint8_t*>(yuva_buffer->DataA()) + x_ +
146 y * yuva_buffer->StrideA());
147 memset(pos_y, yuv_a_, length_);
148 }
perkja8ba1952017-02-27 14:52:10149 }
150
151 private:
152 Random random_generator_;
153 int x_;
154 int y_;
155 const int length_;
156 const uint8_t yuv_y_;
157 const uint8_t yuv_u_;
158 const uint8_t yuv_v_;
Emircan Uysaler03e6ec92018-03-09 23:03:26159 const uint8_t yuv_a_;
perkja8ba1952017-02-27 14:52:10160 };
161
perkjfa10b552016-10-03 06:45:26162 rtc::CriticalSection crit_;
Emircan Uysaler03e6ec92018-03-09 23:03:26163 const OutputType type_;
danilchapa37de392017-09-09 11:17:22164 int width_ RTC_GUARDED_BY(&crit_);
165 int height_ RTC_GUARDED_BY(&crit_);
166 std::vector<std::unique_ptr<Square>> squares_ RTC_GUARDED_BY(&crit_);
167 std::unique_ptr<VideoFrame> frame_ RTC_GUARDED_BY(&crit_);
pbos@webrtc.org266c7b32013-10-15 09:15:47168};
169
andresp@webrtc.orgab654952013-09-19 12:14:03170class YuvFileGenerator : public FrameGenerator {
171 public:
sprang@webrtc.org131bea82015-02-18 12:46:06172 YuvFileGenerator(std::vector<FILE*> files,
173 size_t width,
174 size_t height,
175 int frame_repeat_count)
176 : file_index_(0),
177 files_(files),
178 width_(width),
179 height_(height),
nisseeb44b392017-04-28 14:18:05180 frame_size_(CalcBufferSize(VideoType::kI420,
sprang@webrtc.org131bea82015-02-18 12:46:06181 static_cast<int>(width_),
182 static_cast<int>(height_))),
183 frame_buffer_(new uint8_t[frame_size_]),
184 frame_display_count_(frame_repeat_count),
185 current_display_count_(0) {
kwibergb890c95c2016-11-29 13:30:40186 RTC_DCHECK_GT(width, 0);
187 RTC_DCHECK_GT(height, 0);
188 RTC_DCHECK_GT(frame_repeat_count, 0);
andresp@webrtc.orgab654952013-09-19 12:14:03189 }
190
191 virtual ~YuvFileGenerator() {
sprang@webrtc.org131bea82015-02-18 12:46:06192 for (FILE* file : files_)
193 fclose(file);
andresp@webrtc.orgab654952013-09-19 12:14:03194 }
195
Miguel Casas-Sanchez47650702015-05-30 00:21:40196 VideoFrame* NextFrame() override {
sprang@webrtc.org25dd1db2015-03-02 11:55:45197 if (current_display_count_ == 0)
198 ReadNextFrame();
199 if (++current_display_count_ >= frame_display_count_)
200 current_display_count_ = 0;
andresp@webrtc.orgab654952013-09-19 12:14:03201
Niels Möller2ac64462018-06-11 09:14:32202 temp_frame_.reset(new VideoFrame(
203 last_read_buffer_, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 07:34:46204 return temp_frame_.get();
sprang@webrtc.org131bea82015-02-18 12:46:06205 }
pbos@webrtc.org724947b2013-12-11 16:26:16206
sprang@webrtc.org131bea82015-02-18 12:46:06207 void ReadNextFrame() {
nisse115bd152016-09-30 11:14:07208 last_read_buffer_ =
209 test::ReadI420Buffer(static_cast<int>(width_),
210 static_cast<int>(height_),
211 files_[file_index_]);
212 if (!last_read_buffer_) {
sprang@webrtc.org131bea82015-02-18 12:46:06213 // No more frames to read in this file, rewind and move to next file.
214 rewind(files_[file_index_]);
215 file_index_ = (file_index_ + 1) % files_.size();
nisse115bd152016-09-30 11:14:07216 last_read_buffer_ =
217 test::ReadI420Buffer(static_cast<int>(width_),
218 static_cast<int>(height_),
219 files_[file_index_]);
220 RTC_CHECK(last_read_buffer_);
sprang@webrtc.org131bea82015-02-18 12:46:06221 }
andresp@webrtc.orgab654952013-09-19 12:14:03222 }
223
224 private:
sprang@webrtc.org131bea82015-02-18 12:46:06225 size_t file_index_;
226 const std::vector<FILE*> files_;
227 const size_t width_;
228 const size_t height_;
229 const size_t frame_size_;
kwibergbfefb032016-05-01 21:53:46230 const std::unique_ptr<uint8_t[]> frame_buffer_;
sprang@webrtc.org131bea82015-02-18 12:46:06231 const int frame_display_count_;
232 int current_display_count_;
nisse1996e3f2016-09-19 07:34:46233 rtc::scoped_refptr<I420Buffer> last_read_buffer_;
234 std::unique_ptr<VideoFrame> temp_frame_;
andresp@webrtc.orgab654952013-09-19 12:14:03235};
sprangd6358952015-07-29 14:58:13236
erikvarga579de6f2017-08-29 16:12:57237// SlideGenerator works similarly to YuvFileGenerator but it fills the frames
238// with randomly sized and colored squares instead of reading their content
239// from files.
240class SlideGenerator : public FrameGenerator {
241 public:
242 SlideGenerator(int width, int height, int frame_repeat_count)
243 : width_(width),
244 height_(height),
245 frame_display_count_(frame_repeat_count),
246 current_display_count_(0),
247 random_generator_(1234) {
248 RTC_DCHECK_GT(width, 0);
249 RTC_DCHECK_GT(height, 0);
250 RTC_DCHECK_GT(frame_repeat_count, 0);
251 }
252
253 VideoFrame* NextFrame() override {
254 if (current_display_count_ == 0)
255 GenerateNewFrame();
256 if (++current_display_count_ >= frame_display_count_)
257 current_display_count_ = 0;
258
Niels Möller2ac64462018-06-11 09:14:32259 frame_.reset(new VideoFrame(buffer_, webrtc::kVideoRotation_0,
260 0 /* timestamp_us */));
erikvarga579de6f2017-08-29 16:12:57261 return frame_.get();
262 }
263
264 // Generates some randomly sized and colored squares scattered
265 // over the frame.
266 void GenerateNewFrame() {
267 // The squares should have a varying order of magnitude in order
268 // to simulate variation in the slides' complexity.
Erik Språng3fed5db2017-11-16 09:39:25269 const int kSquareNum = 1 << (4 + (random_generator_.Rand(0, 3) * 2));
erikvarga579de6f2017-08-29 16:12:57270
271 buffer_ = I420Buffer::Create(width_, height_);
272 memset(buffer_->MutableDataY(), 127, height_ * buffer_->StrideY());
273 memset(buffer_->MutableDataU(), 127,
274 buffer_->ChromaHeight() * buffer_->StrideU());
275 memset(buffer_->MutableDataV(), 127,
276 buffer_->ChromaHeight() * buffer_->StrideV());
277
278 for (int i = 0; i < kSquareNum; ++i) {
279 int length = random_generator_.Rand(1, width_ > 4 ? width_ / 4 : 1);
280 // Limit the length of later squares so that they don't overwrite the
281 // previous ones too much.
282 length = (length * (kSquareNum - i)) / kSquareNum;
283
284 int x = random_generator_.Rand(0, width_ - length);
285 int y = random_generator_.Rand(0, height_ - length);
286 uint8_t yuv_y = random_generator_.Rand(0, 255);
287 uint8_t yuv_u = random_generator_.Rand(0, 255);
288 uint8_t yuv_v = random_generator_.Rand(0, 255);
289
290 for (int yy = y; yy < y + length; ++yy) {
291 uint8_t* pos_y =
292 (buffer_->MutableDataY() + x + yy * buffer_->StrideY());
293 memset(pos_y, yuv_y, length);
294 }
295 for (int yy = y; yy < y + length; yy += 2) {
296 uint8_t* pos_u =
297 (buffer_->MutableDataU() + x / 2 + yy / 2 * buffer_->StrideU());
298 memset(pos_u, yuv_u, length / 2);
299 uint8_t* pos_v =
300 (buffer_->MutableDataV() + x / 2 + yy / 2 * buffer_->StrideV());
301 memset(pos_v, yuv_v, length / 2);
302 }
303 }
304 }
305
306 private:
307 const int width_;
308 const int height_;
309 const int frame_display_count_;
310 int current_display_count_;
311 Random random_generator_;
312 rtc::scoped_refptr<I420Buffer> buffer_;
313 std::unique_ptr<VideoFrame> frame_;
314};
315
sprangd6358952015-07-29 14:58:13316class ScrollingImageFrameGenerator : public FrameGenerator {
317 public:
318 ScrollingImageFrameGenerator(Clock* clock,
319 const std::vector<FILE*>& files,
320 size_t source_width,
321 size_t source_height,
322 size_t target_width,
323 size_t target_height,
324 int64_t scroll_time_ms,
325 int64_t pause_time_ms)
326 : clock_(clock),
327 start_time_(clock->TimeInMilliseconds()),
328 scroll_time_(scroll_time_ms),
329 pause_time_(pause_time_ms),
330 num_frames_(files.size()),
nissef122a852016-10-05 06:27:30331 target_width_(static_cast<int>(target_width)),
332 target_height_(static_cast<int>(target_height)),
sprangd6358952015-07-29 14:58:13333 current_frame_num_(num_frames_ - 1),
334 current_source_frame_(nullptr),
335 file_generator_(files, source_width, source_height, 1) {
henrikg91d6ede2015-09-17 07:24:34336 RTC_DCHECK(clock_ != nullptr);
kwibergaf476c72016-11-28 23:21:39337 RTC_DCHECK_GT(num_frames_, 0);
henrikg91d6ede2015-09-17 07:24:34338 RTC_DCHECK_GE(source_height, target_height);
339 RTC_DCHECK_GE(source_width, target_width);
340 RTC_DCHECK_GE(scroll_time_ms, 0);
341 RTC_DCHECK_GE(pause_time_ms, 0);
342 RTC_DCHECK_GT(scroll_time_ms + pause_time_ms, 0);
sprangd6358952015-07-29 14:58:13343 }
344
345 virtual ~ScrollingImageFrameGenerator() {}
346
347 VideoFrame* NextFrame() override {
348 const int64_t kFrameDisplayTime = scroll_time_ + pause_time_;
349 const int64_t now = clock_->TimeInMilliseconds();
350 int64_t ms_since_start = now - start_time_;
351
352 size_t frame_num = (ms_since_start / kFrameDisplayTime) % num_frames_;
353 UpdateSourceFrame(frame_num);
354
355 double scroll_factor;
356 int64_t time_into_frame = ms_since_start % kFrameDisplayTime;
357 if (time_into_frame < scroll_time_) {
358 scroll_factor = static_cast<double>(time_into_frame) / scroll_time_;
359 } else {
360 scroll_factor = 1.0;
361 }
362 CropSourceToScrolledImage(scroll_factor);
363
nissedf2ceb82016-12-15 14:29:53364 return current_frame_ ? &*current_frame_ : nullptr;
sprangd6358952015-07-29 14:58:13365 }
366
367 void UpdateSourceFrame(size_t frame_num) {
368 while (current_frame_num_ != frame_num) {
369 current_source_frame_ = file_generator_.NextFrame();
370 current_frame_num_ = (current_frame_num_ + 1) % num_frames_;
371 }
henrikg91d6ede2015-09-17 07:24:34372 RTC_DCHECK(current_source_frame_ != nullptr);
sprangd6358952015-07-29 14:58:13373 }
374
375 void CropSourceToScrolledImage(double scroll_factor) {
nissef122a852016-10-05 06:27:30376 int scroll_margin_x = current_source_frame_->width() - target_width_;
sprangd6358952015-07-29 14:58:13377 int pixels_scrolled_x =
378 static_cast<int>(scroll_margin_x * scroll_factor + 0.5);
nissef122a852016-10-05 06:27:30379 int scroll_margin_y = current_source_frame_->height() - target_height_;
sprangd6358952015-07-29 14:58:13380 int pixels_scrolled_y =
381 static_cast<int>(scroll_margin_y * scroll_factor + 0.5);
382
Magnus Jedvert90e31902017-06-07 09:32:50383 rtc::scoped_refptr<I420BufferInterface> i420_buffer =
384 current_source_frame_->video_frame_buffer()->ToI420();
385 int offset_y =
386 (i420_buffer->StrideY() * pixels_scrolled_y) + pixels_scrolled_x;
387 int offset_u = (i420_buffer->StrideU() * (pixels_scrolled_y / 2)) +
sprangd6358952015-07-29 14:58:13388 (pixels_scrolled_x / 2);
Magnus Jedvert90e31902017-06-07 09:32:50389 int offset_v = (i420_buffer->StrideV() * (pixels_scrolled_y / 2)) +
sprangd6358952015-07-29 14:58:13390 (pixels_scrolled_x / 2);
391
Oskar Sundbom3f6804d2017-11-16 09:54:58392 current_frame_ = webrtc::VideoFrame(
nissef0a7c5a2016-10-31 12:48:07393 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
Magnus Jedvert90e31902017-06-07 09:32:50394 target_width_, target_height_, &i420_buffer->DataY()[offset_y],
395 i420_buffer->StrideY(), &i420_buffer->DataU()[offset_u],
396 i420_buffer->StrideU(), &i420_buffer->DataV()[offset_v],
397 i420_buffer->StrideV(), KeepRefUntilDone(i420_buffer)),
Oskar Sundbom3f6804d2017-11-16 09:54:58398 kVideoRotation_0, 0);
sprangd6358952015-07-29 14:58:13399 }
400
401 Clock* const clock_;
402 const int64_t start_time_;
403 const int64_t scroll_time_;
404 const int64_t pause_time_;
405 const size_t num_frames_;
nissef122a852016-10-05 06:27:30406 const int target_width_;
407 const int target_height_;
408
sprangd6358952015-07-29 14:58:13409 size_t current_frame_num_;
410 VideoFrame* current_source_frame_;
Danil Chapovalov431abd92018-06-18 10:54:17411 absl::optional<VideoFrame> current_frame_;
sprangd6358952015-07-29 14:58:13412 YuvFileGenerator file_generator_;
413};
414
andresp@webrtc.orgab654952013-09-19 12:14:03415} // namespace
416
perkja49cbd32016-09-16 14:53:41417FrameForwarder::FrameForwarder() : sink_(nullptr) {}
sprangb1ca0732017-02-01 16:38:12418FrameForwarder::~FrameForwarder() {}
perkja49cbd32016-09-16 14:53:41419
420void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) {
421 rtc::CritScope lock(&crit_);
422 if (sink_)
423 sink_->OnFrame(video_frame);
424}
425
426void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
427 const rtc::VideoSinkWants& wants) {
428 rtc::CritScope lock(&crit_);
429 RTC_DCHECK(!sink_ || sink_ == sink);
430 sink_ = sink;
perkj803d97f2016-11-01 18:45:46431 sink_wants_ = wants;
perkja49cbd32016-09-16 14:53:41432}
433
434void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
435 rtc::CritScope lock(&crit_);
436 RTC_DCHECK_EQ(sink, sink_);
437 sink_ = nullptr;
438}
439
perkj803d97f2016-11-01 18:45:46440rtc::VideoSinkWants FrameForwarder::sink_wants() const {
441 rtc::CritScope lock(&crit_);
442 return sink_wants_;
443}
444
445bool FrameForwarder::has_sinks() const {
446 rtc::CritScope lock(&crit_);
447 return sink_ != nullptr;
448}
449
perkja8ba1952017-02-27 14:52:10450std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator(
451 int width,
Emircan Uysaler03e6ec92018-03-09 23:03:26452 int height,
Danil Chapovalov431abd92018-06-18 10:54:17453 absl::optional<OutputType> type,
454 absl::optional<int> num_squares) {
erikvarga@webrtc.orgc774d5d2017-10-10 12:34:38455 return std::unique_ptr<FrameGenerator>(
Emircan Uysaler03e6ec92018-03-09 23:03:26456 new SquareGenerator(width, height, type.value_or(OutputType::I420),
457 num_squares.value_or(10)));
pbos@webrtc.org266c7b32013-10-15 09:15:47458}
459
erikvarga579de6f2017-08-29 16:12:57460std::unique_ptr<FrameGenerator> FrameGenerator::CreateSlideGenerator(
461 int width, int height, int frame_repeat_count) {
462 return std::unique_ptr<FrameGenerator>(new SlideGenerator(
463 width, height, frame_repeat_count));
464}
465
perkja8ba1952017-02-27 14:52:10466std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile(
sprang@webrtc.org131bea82015-02-18 12:46:06467 std::vector<std::string> filenames,
468 size_t width,
469 size_t height,
470 int frame_repeat_count) {
kwibergb890c95c2016-11-29 13:30:40471 RTC_DCHECK(!filenames.empty());
sprang@webrtc.org131bea82015-02-18 12:46:06472 std::vector<FILE*> files;
473 for (const std::string& filename : filenames) {
474 FILE* file = fopen(filename.c_str(), "rb");
Sebastian Jansson9eda3272018-09-13 14:23:03475 RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n";
sprang@webrtc.org131bea82015-02-18 12:46:06476 files.push_back(file);
477 }
478
perkja8ba1952017-02-27 14:52:10479 return std::unique_ptr<FrameGenerator>(
480 new YuvFileGenerator(files, width, height, frame_repeat_count));
andresp@webrtc.orgab654952013-09-19 12:14:03481}
482
perkja8ba1952017-02-27 14:52:10483std::unique_ptr<FrameGenerator>
484FrameGenerator::CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 14:58:13485 Clock* clock,
486 std::vector<std::string> filenames,
487 size_t source_width,
488 size_t source_height,
489 size_t target_width,
490 size_t target_height,
491 int64_t scroll_time_ms,
492 int64_t pause_time_ms) {
kwibergb890c95c2016-11-29 13:30:40493 RTC_DCHECK(!filenames.empty());
sprangd6358952015-07-29 14:58:13494 std::vector<FILE*> files;
495 for (const std::string& filename : filenames) {
496 FILE* file = fopen(filename.c_str(), "rb");
henrikg91d6ede2015-09-17 07:24:34497 RTC_DCHECK(file != nullptr);
sprangd6358952015-07-29 14:58:13498 files.push_back(file);
499 }
500
perkja8ba1952017-02-27 14:52:10501 return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator(
sprangd6358952015-07-29 14:58:13502 clock, files, source_width, source_height, target_width, target_height,
perkja8ba1952017-02-27 14:52:10503 scroll_time_ms, pause_time_ms));
sprangd6358952015-07-29 14:58:13504}
505
andresp@webrtc.orgab654952013-09-19 12:14:03506} // namespace test
507} // namespace webrtc