blob: 040192db01a70fbdee3165789c4fd548fe5a1b7f [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#include "test/frame_generator.h"
andresp@webrtc.orgab654952013-09-19 12:14:03 +000011
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000012#include <math.h>
andresp@webrtc.orgab654952013-09-19 12:14:03 +000013#include <stdio.h>
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000014#include <string.h>
andresp@webrtc.orgab654952013-09-19 12:14:03 +000015
kwibergbfefb032016-05-01 14:53:46 -070016#include <memory>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/video/i420_buffer.h"
19#include "common_video/include/video_frame_buffer.h"
20#include "common_video/libyuv/include/webrtc_libyuv.h"
21#include "rtc_base/checks.h"
22#include "rtc_base/keep_ref_until_done.h"
23#include "rtc_base/random.h"
24#include "system_wrappers/include/clock.h"
25#include "test/frame_utils.h"
andresp@webrtc.orgab654952013-09-19 12:14:03 +000026
27namespace webrtc {
28namespace test {
29namespace {
30
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080031// Helper method for keeping a reference to passed pointers.
32void KeepBufferRefs(rtc::scoped_refptr<webrtc::VideoFrameBuffer>,
33 rtc::scoped_refptr<webrtc::VideoFrameBuffer>) {}
34
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020035// SquareGenerator is a FrameGenerator that draws a given amount of randomly
36// sized and colored squares. Between each new generated frame, the squares
37// are moved slightly towards the lower right corner.
perkja8ba1952017-02-27 06:52:10 -080038class SquareGenerator : public FrameGenerator {
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000039 public:
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080040 SquareGenerator(int width, int height, OutputType type, int num_squares)
41 : type_(type) {
perkjfa10b552016-10-02 23:45:26 -070042 ChangeResolution(width, height);
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020043 for (int i = 0; i < num_squares; ++i) {
perkja8ba1952017-02-27 06:52:10 -080044 squares_.emplace_back(new Square(width, height, i + 1));
45 }
perkjfa10b552016-10-02 23:45:26 -070046 }
47
48 void ChangeResolution(size_t width, size_t height) override {
49 rtc::CritScope lock(&crit_);
perkja8ba1952017-02-27 06:52:10 -080050 width_ = static_cast<int>(width);
51 height_ = static_cast<int>(height);
nisse1996e3f2016-09-19 00:34:46 -070052 RTC_CHECK(width_ > 0);
53 RTC_CHECK(height_ > 0);
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000054 }
55
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080056 rtc::scoped_refptr<I420Buffer> CreateI420Buffer(int width, int height) {
57 rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create(width, height));
58 memset(buffer->MutableDataY(), 127, height * buffer->StrideY());
Magnus Jedvert90e31902017-06-07 11:32:50 +020059 memset(buffer->MutableDataU(), 127,
60 buffer->ChromaHeight() * buffer->StrideU());
61 memset(buffer->MutableDataV(), 127,
62 buffer->ChromaHeight() * buffer->StrideV());
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080063 return buffer;
64 }
65
66 VideoFrame* NextFrame() override {
67 rtc::CritScope lock(&crit_);
68
69 rtc::scoped_refptr<VideoFrameBuffer> buffer = nullptr;
70 switch (type_) {
71 case OutputType::I420: {
72 buffer = CreateI420Buffer(width_, height_);
73 break;
74 }
75 case OutputType::I420A: {
76 rtc::scoped_refptr<I420Buffer> yuv_buffer =
77 CreateI420Buffer(width_, height_);
78 rtc::scoped_refptr<I420Buffer> axx_buffer =
79 CreateI420Buffer(width_, height_);
80 buffer = WrapI420ABuffer(
81 yuv_buffer->width(), yuv_buffer->height(), yuv_buffer->DataY(),
82 yuv_buffer->StrideY(), yuv_buffer->DataU(), yuv_buffer->StrideU(),
83 yuv_buffer->DataV(), yuv_buffer->StrideV(), axx_buffer->DataY(),
84 axx_buffer->StrideY(),
85 rtc::Bind(&KeepBufferRefs, yuv_buffer, axx_buffer));
86 break;
87 }
88 }
nisse1996e3f2016-09-19 00:34:46 -070089
perkja8ba1952017-02-27 06:52:10 -080090 for (const auto& square : squares_)
91 square->Draw(buffer);
nisse1996e3f2016-09-19 00:34:46 -070092
Niels Möller2ac64462018-06-11 11:14:32 +020093 frame_.reset(
94 new VideoFrame(buffer, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 00:34:46 -070095 return frame_.get();
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000096 }
97
98 private:
perkja8ba1952017-02-27 06:52:10 -080099 class Square {
100 public:
101 Square(int width, int height, int seed)
102 : random_generator_(seed),
103 x_(random_generator_.Rand(0, width)),
104 y_(random_generator_.Rand(0, height)),
105 length_(random_generator_.Rand(1, width > 4 ? width / 4 : 1)),
106 yuv_y_(random_generator_.Rand(0, 255)),
107 yuv_u_(random_generator_.Rand(0, 255)),
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800108 yuv_v_(random_generator_.Rand(0, 255)),
109 yuv_a_(random_generator_.Rand(0, 255)) {}
perkja8ba1952017-02-27 06:52:10 -0800110
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800111 void Draw(const rtc::scoped_refptr<VideoFrameBuffer>& frame_buffer) {
112 RTC_DCHECK(frame_buffer->type() == VideoFrameBuffer::Type::kI420 ||
113 frame_buffer->type() == VideoFrameBuffer::Type::kI420A);
114 rtc::scoped_refptr<I420BufferInterface> buffer = frame_buffer->ToI420();
perkja8ba1952017-02-27 06:52:10 -0800115 x_ = (x_ + random_generator_.Rand(0, 4)) % (buffer->width() - length_);
116 y_ = (y_ + random_generator_.Rand(0, 4)) % (buffer->height() - length_);
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800117 for (int y = y_; y < y_ + length_; ++y) {
118 uint8_t* pos_y = (const_cast<uint8_t*>(buffer->DataY()) + x_ +
119 y * buffer->StrideY());
120 memset(pos_y, yuv_y_, length_);
121 }
perkjc8b08652017-03-22 04:57:53 -0700122
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800123 for (int y = y_; y < y_ + length_; y = y + 2) {
124 uint8_t* pos_u = (const_cast<uint8_t*>(buffer->DataU()) + x_ / 2 +
125 y / 2 * buffer->StrideU());
126 memset(pos_u, yuv_u_, length_ / 2);
127 uint8_t* pos_v = (const_cast<uint8_t*>(buffer->DataV()) + x_ / 2 +
128 y / 2 * buffer->StrideV());
129 memset(pos_v, yuv_v_, length_ / 2);
130 }
131
132 if (frame_buffer->type() == VideoFrameBuffer::Type::kI420)
133 return;
134
135 // Optionally draw on alpha plane if given.
136 const webrtc::I420ABufferInterface* yuva_buffer =
137 frame_buffer->GetI420A();
138 for (int y = y_; y < y_ + length_; ++y) {
139 uint8_t* pos_y = (const_cast<uint8_t*>(yuva_buffer->DataA()) + x_ +
140 y * yuva_buffer->StrideA());
141 memset(pos_y, yuv_a_, length_);
142 }
perkja8ba1952017-02-27 06:52:10 -0800143 }
144
145 private:
146 Random random_generator_;
147 int x_;
148 int y_;
149 const int length_;
150 const uint8_t yuv_y_;
151 const uint8_t yuv_u_;
152 const uint8_t yuv_v_;
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800153 const uint8_t yuv_a_;
perkja8ba1952017-02-27 06:52:10 -0800154 };
155
perkjfa10b552016-10-02 23:45:26 -0700156 rtc::CriticalSection crit_;
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800157 const OutputType type_;
danilchapa37de392017-09-09 04:17:22 -0700158 int width_ RTC_GUARDED_BY(&crit_);
159 int height_ RTC_GUARDED_BY(&crit_);
160 std::vector<std::unique_ptr<Square>> squares_ RTC_GUARDED_BY(&crit_);
161 std::unique_ptr<VideoFrame> frame_ RTC_GUARDED_BY(&crit_);
pbos@webrtc.org266c7b32013-10-15 09:15:47 +0000162};
163
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000164class YuvFileGenerator : public FrameGenerator {
165 public:
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000166 YuvFileGenerator(std::vector<FILE*> files,
167 size_t width,
168 size_t height,
169 int frame_repeat_count)
170 : file_index_(0),
171 files_(files),
172 width_(width),
173 height_(height),
nisseeb44b392017-04-28 07:18:05 -0700174 frame_size_(CalcBufferSize(VideoType::kI420,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000175 static_cast<int>(width_),
176 static_cast<int>(height_))),
177 frame_buffer_(new uint8_t[frame_size_]),
178 frame_display_count_(frame_repeat_count),
179 current_display_count_(0) {
kwibergb890c95c2016-11-29 05:30:40 -0800180 RTC_DCHECK_GT(width, 0);
181 RTC_DCHECK_GT(height, 0);
182 RTC_DCHECK_GT(frame_repeat_count, 0);
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000183 }
184
185 virtual ~YuvFileGenerator() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000186 for (FILE* file : files_)
187 fclose(file);
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000188 }
189
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700190 VideoFrame* NextFrame() override {
sprang@webrtc.org25dd1db2015-03-02 11:55:45 +0000191 if (current_display_count_ == 0)
192 ReadNextFrame();
193 if (++current_display_count_ >= frame_display_count_)
194 current_display_count_ = 0;
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000195
Niels Möller2ac64462018-06-11 11:14:32 +0200196 temp_frame_.reset(new VideoFrame(
197 last_read_buffer_, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 00:34:46 -0700198 return temp_frame_.get();
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000199 }
pbos@webrtc.org724947b2013-12-11 16:26:16 +0000200
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000201 void ReadNextFrame() {
nisse115bd152016-09-30 04:14:07 -0700202 last_read_buffer_ =
203 test::ReadI420Buffer(static_cast<int>(width_),
204 static_cast<int>(height_),
205 files_[file_index_]);
206 if (!last_read_buffer_) {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000207 // No more frames to read in this file, rewind and move to next file.
208 rewind(files_[file_index_]);
209 file_index_ = (file_index_ + 1) % files_.size();
nisse115bd152016-09-30 04:14:07 -0700210 last_read_buffer_ =
211 test::ReadI420Buffer(static_cast<int>(width_),
212 static_cast<int>(height_),
213 files_[file_index_]);
214 RTC_CHECK(last_read_buffer_);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000215 }
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000216 }
217
218 private:
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000219 size_t file_index_;
220 const std::vector<FILE*> files_;
221 const size_t width_;
222 const size_t height_;
223 const size_t frame_size_;
kwibergbfefb032016-05-01 14:53:46 -0700224 const std::unique_ptr<uint8_t[]> frame_buffer_;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000225 const int frame_display_count_;
226 int current_display_count_;
nisse1996e3f2016-09-19 00:34:46 -0700227 rtc::scoped_refptr<I420Buffer> last_read_buffer_;
228 std::unique_ptr<VideoFrame> temp_frame_;
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000229};
sprangd6358952015-07-29 07:58:13 -0700230
erikvarga579de6f2017-08-29 09:12:57 -0700231// SlideGenerator works similarly to YuvFileGenerator but it fills the frames
232// with randomly sized and colored squares instead of reading their content
233// from files.
234class SlideGenerator : public FrameGenerator {
235 public:
236 SlideGenerator(int width, int height, int frame_repeat_count)
237 : width_(width),
238 height_(height),
239 frame_display_count_(frame_repeat_count),
240 current_display_count_(0),
241 random_generator_(1234) {
242 RTC_DCHECK_GT(width, 0);
243 RTC_DCHECK_GT(height, 0);
244 RTC_DCHECK_GT(frame_repeat_count, 0);
245 }
246
247 VideoFrame* NextFrame() override {
248 if (current_display_count_ == 0)
249 GenerateNewFrame();
250 if (++current_display_count_ >= frame_display_count_)
251 current_display_count_ = 0;
252
Niels Möller2ac64462018-06-11 11:14:32 +0200253 frame_.reset(new VideoFrame(buffer_, webrtc::kVideoRotation_0,
254 0 /* timestamp_us */));
erikvarga579de6f2017-08-29 09:12:57 -0700255 return frame_.get();
256 }
257
258 // Generates some randomly sized and colored squares scattered
259 // over the frame.
260 void GenerateNewFrame() {
261 // The squares should have a varying order of magnitude in order
262 // to simulate variation in the slides' complexity.
Erik Språng3fed5db2017-11-16 10:39:25 +0100263 const int kSquareNum = 1 << (4 + (random_generator_.Rand(0, 3) * 2));
erikvarga579de6f2017-08-29 09:12:57 -0700264
265 buffer_ = I420Buffer::Create(width_, height_);
266 memset(buffer_->MutableDataY(), 127, height_ * buffer_->StrideY());
267 memset(buffer_->MutableDataU(), 127,
268 buffer_->ChromaHeight() * buffer_->StrideU());
269 memset(buffer_->MutableDataV(), 127,
270 buffer_->ChromaHeight() * buffer_->StrideV());
271
272 for (int i = 0; i < kSquareNum; ++i) {
273 int length = random_generator_.Rand(1, width_ > 4 ? width_ / 4 : 1);
274 // Limit the length of later squares so that they don't overwrite the
275 // previous ones too much.
276 length = (length * (kSquareNum - i)) / kSquareNum;
277
278 int x = random_generator_.Rand(0, width_ - length);
279 int y = random_generator_.Rand(0, height_ - length);
280 uint8_t yuv_y = random_generator_.Rand(0, 255);
281 uint8_t yuv_u = random_generator_.Rand(0, 255);
282 uint8_t yuv_v = random_generator_.Rand(0, 255);
283
284 for (int yy = y; yy < y + length; ++yy) {
285 uint8_t* pos_y =
286 (buffer_->MutableDataY() + x + yy * buffer_->StrideY());
287 memset(pos_y, yuv_y, length);
288 }
289 for (int yy = y; yy < y + length; yy += 2) {
290 uint8_t* pos_u =
291 (buffer_->MutableDataU() + x / 2 + yy / 2 * buffer_->StrideU());
292 memset(pos_u, yuv_u, length / 2);
293 uint8_t* pos_v =
294 (buffer_->MutableDataV() + x / 2 + yy / 2 * buffer_->StrideV());
295 memset(pos_v, yuv_v, length / 2);
296 }
297 }
298 }
299
300 private:
301 const int width_;
302 const int height_;
303 const int frame_display_count_;
304 int current_display_count_;
305 Random random_generator_;
306 rtc::scoped_refptr<I420Buffer> buffer_;
307 std::unique_ptr<VideoFrame> frame_;
308};
309
sprangd6358952015-07-29 07:58:13 -0700310class ScrollingImageFrameGenerator : public FrameGenerator {
311 public:
312 ScrollingImageFrameGenerator(Clock* clock,
313 const std::vector<FILE*>& files,
314 size_t source_width,
315 size_t source_height,
316 size_t target_width,
317 size_t target_height,
318 int64_t scroll_time_ms,
319 int64_t pause_time_ms)
320 : clock_(clock),
321 start_time_(clock->TimeInMilliseconds()),
322 scroll_time_(scroll_time_ms),
323 pause_time_(pause_time_ms),
324 num_frames_(files.size()),
nissef122a852016-10-04 23:27:30 -0700325 target_width_(static_cast<int>(target_width)),
326 target_height_(static_cast<int>(target_height)),
sprangd6358952015-07-29 07:58:13 -0700327 current_frame_num_(num_frames_ - 1),
328 current_source_frame_(nullptr),
329 file_generator_(files, source_width, source_height, 1) {
henrikg91d6ede2015-09-17 00:24:34 -0700330 RTC_DCHECK(clock_ != nullptr);
kwibergaf476c72016-11-28 15:21:39 -0800331 RTC_DCHECK_GT(num_frames_, 0);
henrikg91d6ede2015-09-17 00:24:34 -0700332 RTC_DCHECK_GE(source_height, target_height);
333 RTC_DCHECK_GE(source_width, target_width);
334 RTC_DCHECK_GE(scroll_time_ms, 0);
335 RTC_DCHECK_GE(pause_time_ms, 0);
336 RTC_DCHECK_GT(scroll_time_ms + pause_time_ms, 0);
sprangd6358952015-07-29 07:58:13 -0700337 }
338
339 virtual ~ScrollingImageFrameGenerator() {}
340
341 VideoFrame* NextFrame() override {
342 const int64_t kFrameDisplayTime = scroll_time_ + pause_time_;
343 const int64_t now = clock_->TimeInMilliseconds();
344 int64_t ms_since_start = now - start_time_;
345
346 size_t frame_num = (ms_since_start / kFrameDisplayTime) % num_frames_;
347 UpdateSourceFrame(frame_num);
348
349 double scroll_factor;
350 int64_t time_into_frame = ms_since_start % kFrameDisplayTime;
351 if (time_into_frame < scroll_time_) {
352 scroll_factor = static_cast<double>(time_into_frame) / scroll_time_;
353 } else {
354 scroll_factor = 1.0;
355 }
356 CropSourceToScrolledImage(scroll_factor);
357
nissedf2ceb82016-12-15 06:29:53 -0800358 return current_frame_ ? &*current_frame_ : nullptr;
sprangd6358952015-07-29 07:58:13 -0700359 }
360
361 void UpdateSourceFrame(size_t frame_num) {
362 while (current_frame_num_ != frame_num) {
363 current_source_frame_ = file_generator_.NextFrame();
364 current_frame_num_ = (current_frame_num_ + 1) % num_frames_;
365 }
henrikg91d6ede2015-09-17 00:24:34 -0700366 RTC_DCHECK(current_source_frame_ != nullptr);
sprangd6358952015-07-29 07:58:13 -0700367 }
368
369 void CropSourceToScrolledImage(double scroll_factor) {
nissef122a852016-10-04 23:27:30 -0700370 int scroll_margin_x = current_source_frame_->width() - target_width_;
sprangd6358952015-07-29 07:58:13 -0700371 int pixels_scrolled_x =
372 static_cast<int>(scroll_margin_x * scroll_factor + 0.5);
nissef122a852016-10-04 23:27:30 -0700373 int scroll_margin_y = current_source_frame_->height() - target_height_;
sprangd6358952015-07-29 07:58:13 -0700374 int pixels_scrolled_y =
375 static_cast<int>(scroll_margin_y * scroll_factor + 0.5);
376
Magnus Jedvert90e31902017-06-07 11:32:50 +0200377 rtc::scoped_refptr<I420BufferInterface> i420_buffer =
378 current_source_frame_->video_frame_buffer()->ToI420();
379 int offset_y =
380 (i420_buffer->StrideY() * pixels_scrolled_y) + pixels_scrolled_x;
381 int offset_u = (i420_buffer->StrideU() * (pixels_scrolled_y / 2)) +
sprangd6358952015-07-29 07:58:13 -0700382 (pixels_scrolled_x / 2);
Magnus Jedvert90e31902017-06-07 11:32:50 +0200383 int offset_v = (i420_buffer->StrideV() * (pixels_scrolled_y / 2)) +
sprangd6358952015-07-29 07:58:13 -0700384 (pixels_scrolled_x / 2);
385
Oskar Sundbom3f6804d2017-11-16 10:54:58 +0100386 current_frame_ = webrtc::VideoFrame(
nissef0a7c5a2016-10-31 05:48:07 -0700387 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
Magnus Jedvert90e31902017-06-07 11:32:50 +0200388 target_width_, target_height_, &i420_buffer->DataY()[offset_y],
389 i420_buffer->StrideY(), &i420_buffer->DataU()[offset_u],
390 i420_buffer->StrideU(), &i420_buffer->DataV()[offset_v],
391 i420_buffer->StrideV(), KeepRefUntilDone(i420_buffer)),
Oskar Sundbom3f6804d2017-11-16 10:54:58 +0100392 kVideoRotation_0, 0);
sprangd6358952015-07-29 07:58:13 -0700393 }
394
395 Clock* const clock_;
396 const int64_t start_time_;
397 const int64_t scroll_time_;
398 const int64_t pause_time_;
399 const size_t num_frames_;
nissef122a852016-10-04 23:27:30 -0700400 const int target_width_;
401 const int target_height_;
402
sprangd6358952015-07-29 07:58:13 -0700403 size_t current_frame_num_;
404 VideoFrame* current_source_frame_;
nissedf2ceb82016-12-15 06:29:53 -0800405 rtc::Optional<VideoFrame> current_frame_;
sprangd6358952015-07-29 07:58:13 -0700406 YuvFileGenerator file_generator_;
407};
408
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000409} // namespace
410
perkja49cbd32016-09-16 07:53:41 -0700411FrameForwarder::FrameForwarder() : sink_(nullptr) {}
sprangb1ca0732017-02-01 08:38:12 -0800412FrameForwarder::~FrameForwarder() {}
perkja49cbd32016-09-16 07:53:41 -0700413
414void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) {
415 rtc::CritScope lock(&crit_);
416 if (sink_)
417 sink_->OnFrame(video_frame);
418}
419
420void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
421 const rtc::VideoSinkWants& wants) {
422 rtc::CritScope lock(&crit_);
423 RTC_DCHECK(!sink_ || sink_ == sink);
424 sink_ = sink;
perkj803d97f2016-11-01 11:45:46 -0700425 sink_wants_ = wants;
perkja49cbd32016-09-16 07:53:41 -0700426}
427
428void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) {
429 rtc::CritScope lock(&crit_);
430 RTC_DCHECK_EQ(sink, sink_);
431 sink_ = nullptr;
432}
433
perkj803d97f2016-11-01 11:45:46 -0700434rtc::VideoSinkWants FrameForwarder::sink_wants() const {
435 rtc::CritScope lock(&crit_);
436 return sink_wants_;
437}
438
439bool FrameForwarder::has_sinks() const {
440 rtc::CritScope lock(&crit_);
441 return sink_ != nullptr;
442}
443
perkja8ba1952017-02-27 06:52:10 -0800444std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator(
445 int width,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800446 int height,
447 rtc::Optional<OutputType> type,
448 rtc::Optional<int> num_squares) {
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +0200449 return std::unique_ptr<FrameGenerator>(
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800450 new SquareGenerator(width, height, type.value_or(OutputType::I420),
451 num_squares.value_or(10)));
pbos@webrtc.org266c7b32013-10-15 09:15:47 +0000452}
453
erikvarga579de6f2017-08-29 09:12:57 -0700454std::unique_ptr<FrameGenerator> FrameGenerator::CreateSlideGenerator(
455 int width, int height, int frame_repeat_count) {
456 return std::unique_ptr<FrameGenerator>(new SlideGenerator(
457 width, height, frame_repeat_count));
458}
459
perkja8ba1952017-02-27 06:52:10 -0800460std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile(
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000461 std::vector<std::string> filenames,
462 size_t width,
463 size_t height,
464 int frame_repeat_count) {
kwibergb890c95c2016-11-29 05:30:40 -0800465 RTC_DCHECK(!filenames.empty());
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000466 std::vector<FILE*> files;
467 for (const std::string& filename : filenames) {
468 FILE* file = fopen(filename.c_str(), "rb");
henrikg91d6ede2015-09-17 00:24:34 -0700469 RTC_DCHECK(file != nullptr);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000470 files.push_back(file);
471 }
472
perkja8ba1952017-02-27 06:52:10 -0800473 return std::unique_ptr<FrameGenerator>(
474 new YuvFileGenerator(files, width, height, frame_repeat_count));
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000475}
476
perkja8ba1952017-02-27 06:52:10 -0800477std::unique_ptr<FrameGenerator>
478FrameGenerator::CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 07:58:13 -0700479 Clock* clock,
480 std::vector<std::string> filenames,
481 size_t source_width,
482 size_t source_height,
483 size_t target_width,
484 size_t target_height,
485 int64_t scroll_time_ms,
486 int64_t pause_time_ms) {
kwibergb890c95c2016-11-29 05:30:40 -0800487 RTC_DCHECK(!filenames.empty());
sprangd6358952015-07-29 07:58:13 -0700488 std::vector<FILE*> files;
489 for (const std::string& filename : filenames) {
490 FILE* file = fopen(filename.c_str(), "rb");
henrikg91d6ede2015-09-17 00:24:34 -0700491 RTC_DCHECK(file != nullptr);
sprangd6358952015-07-29 07:58:13 -0700492 files.push_back(file);
493 }
494
perkja8ba1952017-02-27 06:52:10 -0800495 return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator(
sprangd6358952015-07-29 07:58:13 -0700496 clock, files, source_width, source_height, target_width, target_height,
perkja8ba1952017-02-27 06:52:10 -0800497 scroll_time_ms, pause_time_ms));
sprangd6358952015-07-29 07:58:13 -0700498}
499
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000500} // namespace test
501} // namespace webrtc