blob: 45d5f2f76ed742e09c1f42a2895b9f80c986ce08 [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
Emircan Uysaler0823eec2018-07-13 17:10:00 -070018#include "api/video/i010_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#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:03 +000027
28namespace webrtc {
29namespace test {
30namespace {
31
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080032// 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 14:34:38 +020036// 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 06:52:10 -080039class SquareGenerator : public FrameGenerator {
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000040 public:
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080041 SquareGenerator(int width, int height, OutputType type, int num_squares)
42 : type_(type) {
perkjfa10b552016-10-02 23:45:26 -070043 ChangeResolution(width, height);
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020044 for (int i = 0; i < num_squares; ++i) {
perkja8ba1952017-02-27 06:52:10 -080045 squares_.emplace_back(new Square(width, height, i + 1));
46 }
perkjfa10b552016-10-02 23:45:26 -070047 }
48
49 void ChangeResolution(size_t width, size_t height) override {
50 rtc::CritScope lock(&crit_);
perkja8ba1952017-02-27 06:52:10 -080051 width_ = static_cast<int>(width);
52 height_ = static_cast<int>(height);
nisse1996e3f2016-09-19 00:34:46 -070053 RTC_CHECK(width_ > 0);
54 RTC_CHECK(height_ > 0);
pbos@webrtc.org266c7b32013-10-15 09:15:47 +000055 }
56
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080057 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 11:32:50 +020060 memset(buffer->MutableDataU(), 127,
61 buffer->ChromaHeight() * buffer->StrideU());
62 memset(buffer->MutableDataV(), 127,
63 buffer->ChromaHeight() * buffer->StrideV());
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080064 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-13 17:10:00 -070072 case OutputType::I420:
73 case OutputType::I010: {
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080074 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 00:34:46 -070091
perkja8ba1952017-02-27 06:52:10 -080092 for (const auto& square : squares_)
93 square->Draw(buffer);
nisse1996e3f2016-09-19 00:34:46 -070094
Emircan Uysaler0823eec2018-07-13 17:10:00 -070095 if (type_ == OutputType::I010) {
96 buffer = I010Buffer::Copy(*buffer->ToI420());
97 }
98
Niels Möller2ac64462018-06-11 11:14:32 +020099 frame_.reset(
100 new VideoFrame(buffer, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 00:34:46 -0700101 return frame_.get();
pbos@webrtc.org266c7b32013-10-15 09:15:47 +0000102 }
103
104 private:
perkja8ba1952017-02-27 06:52:10 -0800105 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 15:03:26 -0800114 yuv_v_(random_generator_.Rand(0, 255)),
115 yuv_a_(random_generator_.Rand(0, 255)) {}
perkja8ba1952017-02-27 06:52:10 -0800116
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800117 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 06:52:10 -0800121 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 15:03:26 -0800123 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 04:57:53 -0700128
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800129 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 06:52:10 -0800149 }
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 15:03:26 -0800159 const uint8_t yuv_a_;
perkja8ba1952017-02-27 06:52:10 -0800160 };
161
perkjfa10b552016-10-02 23:45:26 -0700162 rtc::CriticalSection crit_;
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800163 const OutputType type_;
danilchapa37de392017-09-09 04:17:22 -0700164 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:47 +0000168};
169
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000170class YuvFileGenerator : public FrameGenerator {
171 public:
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000172 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 07:18:05 -0700180 frame_size_(CalcBufferSize(VideoType::kI420,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000181 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 05:30:40 -0800186 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:03 +0000189 }
190
191 virtual ~YuvFileGenerator() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000192 for (FILE* file : files_)
193 fclose(file);
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000194 }
195
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700196 VideoFrame* NextFrame() override {
sprang@webrtc.org25dd1db2015-03-02 11:55:45 +0000197 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:03 +0000201
Niels Möller2ac64462018-06-11 11:14:32 +0200202 temp_frame_.reset(new VideoFrame(
203 last_read_buffer_, webrtc::kVideoRotation_0, 0 /* timestamp_us */));
nisse1996e3f2016-09-19 00:34:46 -0700204 return temp_frame_.get();
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000205 }
pbos@webrtc.org724947b2013-12-11 16:26:16 +0000206
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000207 void ReadNextFrame() {
nisse115bd152016-09-30 04:14:07 -0700208 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:06 +0000213 // 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 04:14:07 -0700216 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:06 +0000221 }
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000222 }
223
224 private:
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000225 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 14:53:46 -0700230 const std::unique_ptr<uint8_t[]> frame_buffer_;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000231 const int frame_display_count_;
232 int current_display_count_;
nisse1996e3f2016-09-19 00:34:46 -0700233 rtc::scoped_refptr<I420Buffer> last_read_buffer_;
234 std::unique_ptr<VideoFrame> temp_frame_;
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000235};
sprangd6358952015-07-29 07:58:13 -0700236
erikvarga579de6f2017-08-29 09:12:57 -0700237// 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 11:14:32 +0200259 frame_.reset(new VideoFrame(buffer_, webrtc::kVideoRotation_0,
260 0 /* timestamp_us */));
erikvarga579de6f2017-08-29 09:12:57 -0700261 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 10:39:25 +0100269 const int kSquareNum = 1 << (4 + (random_generator_.Rand(0, 3) * 2));
erikvarga579de6f2017-08-29 09:12:57 -0700270
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 07:58:13 -0700316class 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-04 23:27:30 -0700331 target_width_(static_cast<int>(target_width)),
332 target_height_(static_cast<int>(target_height)),
sprangd6358952015-07-29 07:58:13 -0700333 current_frame_num_(num_frames_ - 1),
334 current_source_frame_(nullptr),
335 file_generator_(files, source_width, source_height, 1) {
henrikg91d6ede2015-09-17 00:24:34 -0700336 RTC_DCHECK(clock_ != nullptr);
kwibergaf476c72016-11-28 15:21:39 -0800337 RTC_DCHECK_GT(num_frames_, 0);
henrikg91d6ede2015-09-17 00:24:34 -0700338 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 07:58:13 -0700343 }
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 06:29:53 -0800364 return current_frame_ ? &*current_frame_ : nullptr;
sprangd6358952015-07-29 07:58:13 -0700365 }
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 00:24:34 -0700372 RTC_DCHECK(current_source_frame_ != nullptr);
sprangd6358952015-07-29 07:58:13 -0700373 }
374
375 void CropSourceToScrolledImage(double scroll_factor) {
nissef122a852016-10-04 23:27:30 -0700376 int scroll_margin_x = current_source_frame_->width() - target_width_;
sprangd6358952015-07-29 07:58:13 -0700377 int pixels_scrolled_x =
378 static_cast<int>(scroll_margin_x * scroll_factor + 0.5);
nissef122a852016-10-04 23:27:30 -0700379 int scroll_margin_y = current_source_frame_->height() - target_height_;
sprangd6358952015-07-29 07:58:13 -0700380 int pixels_scrolled_y =
381 static_cast<int>(scroll_margin_y * scroll_factor + 0.5);
382
Magnus Jedvert90e31902017-06-07 11:32:50 +0200383 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 07:58:13 -0700388 (pixels_scrolled_x / 2);
Magnus Jedvert90e31902017-06-07 11:32:50 +0200389 int offset_v = (i420_buffer->StrideV() * (pixels_scrolled_y / 2)) +
sprangd6358952015-07-29 07:58:13 -0700390 (pixels_scrolled_x / 2);
391
Oskar Sundbom3f6804d2017-11-16 10:54:58 +0100392 current_frame_ = webrtc::VideoFrame(
nissef0a7c5a2016-10-31 05:48:07 -0700393 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
Magnus Jedvert90e31902017-06-07 11:32:50 +0200394 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 10:54:58 +0100398 kVideoRotation_0, 0);
sprangd6358952015-07-29 07:58:13 -0700399 }
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-04 23:27:30 -0700406 const int target_width_;
407 const int target_height_;
408
sprangd6358952015-07-29 07:58:13 -0700409 size_t current_frame_num_;
410 VideoFrame* current_source_frame_;
Danil Chapovalov431abd92018-06-18 12:54:17 +0200411 absl::optional<VideoFrame> current_frame_;
sprangd6358952015-07-29 07:58:13 -0700412 YuvFileGenerator file_generator_;
413};
414
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000415} // namespace
416
perkja49cbd32016-09-16 07:53:41 -0700417FrameForwarder::FrameForwarder() : sink_(nullptr) {}
sprangb1ca0732017-02-01 08:38:12 -0800418FrameForwarder::~FrameForwarder() {}
perkja49cbd32016-09-16 07:53:41 -0700419
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 11:45:46 -0700431 sink_wants_ = wants;
perkja49cbd32016-09-16 07:53:41 -0700432}
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 11:45:46 -0700440rtc::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 06:52:10 -0800450std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator(
451 int width,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800452 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +0200453 absl::optional<OutputType> type,
454 absl::optional<int> num_squares) {
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +0200455 return std::unique_ptr<FrameGenerator>(
Emircan Uysaler03e6ec92018-03-09 15:03:26 -0800456 new SquareGenerator(width, height, type.value_or(OutputType::I420),
457 num_squares.value_or(10)));
pbos@webrtc.org266c7b32013-10-15 09:15:47 +0000458}
459
erikvarga579de6f2017-08-29 09:12:57 -0700460std::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 06:52:10 -0800466std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile(
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000467 std::vector<std::string> filenames,
468 size_t width,
469 size_t height,
470 int frame_repeat_count) {
kwibergb890c95c2016-11-29 05:30:40 -0800471 RTC_DCHECK(!filenames.empty());
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000472 std::vector<FILE*> files;
473 for (const std::string& filename : filenames) {
474 FILE* file = fopen(filename.c_str(), "rb");
henrikg91d6ede2015-09-17 00:24:34 -0700475 RTC_DCHECK(file != nullptr);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000476 files.push_back(file);
477 }
478
perkja8ba1952017-02-27 06:52:10 -0800479 return std::unique_ptr<FrameGenerator>(
480 new YuvFileGenerator(files, width, height, frame_repeat_count));
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000481}
482
perkja8ba1952017-02-27 06:52:10 -0800483std::unique_ptr<FrameGenerator>
484FrameGenerator::CreateScrollingInputFromYuvFiles(
sprangd6358952015-07-29 07:58:13 -0700485 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 05:30:40 -0800493 RTC_DCHECK(!filenames.empty());
sprangd6358952015-07-29 07:58:13 -0700494 std::vector<FILE*> files;
495 for (const std::string& filename : filenames) {
496 FILE* file = fopen(filename.c_str(), "rb");
henrikg91d6ede2015-09-17 00:24:34 -0700497 RTC_DCHECK(file != nullptr);
sprangd6358952015-07-29 07:58:13 -0700498 files.push_back(file);
499 }
500
perkja8ba1952017-02-27 06:52:10 -0800501 return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator(
sprangd6358952015-07-29 07:58:13 -0700502 clock, files, source_width, source_height, target_width, target_height,
perkja8ba1952017-02-27 06:52:10 -0800503 scroll_time_ms, pause_time_ms));
sprangd6358952015-07-29 07:58:13 -0700504}
505
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000506} // namespace test
507} // namespace webrtc