andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
pbos@webrtc.org | 724947b | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 10 | #include "webrtc/test/frame_generator.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 11 | |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 12 | #include <math.h> |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 13 | #include <stdio.h> |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 14 | #include <string.h> |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 15 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 18 | #include "webrtc/api/video/i420_buffer.h" |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 19 | #include "webrtc/base/checks.h" |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 20 | #include "webrtc/base/keep_ref_until_done.h" |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 21 | #include "webrtc/base/random.h" |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 22 | #include "webrtc/common_video/include/video_frame_buffer.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 23 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 24 | #include "webrtc/system_wrappers/include/clock.h" |
nisse | 115bd15 | 2016-09-30 04:14:07 -0700 | [diff] [blame] | 25 | #include "webrtc/test/frame_utils.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace test { |
| 29 | namespace { |
| 30 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 31 | // SquareGenerator is a FrameGenerator that draws 10 randomly sized and colored |
| 32 | // squares. Between each new generated frame, the squares are moved slightly |
| 33 | // towards the lower right corner. |
| 34 | class SquareGenerator : public FrameGenerator { |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 35 | public: |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 36 | SquareGenerator(int width, int height) { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 37 | ChangeResolution(width, height); |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 38 | for (int i = 0; i < 10; ++i) { |
| 39 | squares_.emplace_back(new Square(width, height, i + 1)); |
| 40 | } |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void ChangeResolution(size_t width, size_t height) override { |
| 44 | rtc::CritScope lock(&crit_); |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 45 | width_ = static_cast<int>(width); |
| 46 | height_ = static_cast<int>(height); |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 47 | RTC_CHECK(width_ > 0); |
| 48 | RTC_CHECK(height_ > 0); |
| 49 | half_width_ = (width_ + 1) / 2; |
| 50 | y_size_ = width_ * height_; |
| 51 | uv_size_ = half_width_ * ((height_ + 1) / 2); |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 54 | VideoFrame* NextFrame() override { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 55 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 56 | |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 57 | // Ensure stride == width. |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 58 | rtc::scoped_refptr<I420Buffer> buffer( |
| 59 | I420Buffer::Create(width_, height_, width_, half_width_, half_width_)); |
| 60 | memset(buffer->MutableDataY(), 127, y_size_); |
| 61 | memset(buffer->MutableDataU(), 127, uv_size_); |
| 62 | memset(buffer->MutableDataV(), 127, uv_size_); |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 63 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 64 | for (const auto& square : squares_) |
| 65 | square->Draw(buffer); |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 66 | |
| 67 | frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
| 68 | return frame_.get(); |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | private: |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 72 | class Square { |
| 73 | public: |
| 74 | Square(int width, int height, int seed) |
| 75 | : random_generator_(seed), |
| 76 | x_(random_generator_.Rand(0, width)), |
| 77 | y_(random_generator_.Rand(0, height)), |
| 78 | length_(random_generator_.Rand(1, width > 4 ? width / 4 : 1)), |
| 79 | yuv_y_(random_generator_.Rand(0, 255)), |
| 80 | yuv_u_(random_generator_.Rand(0, 255)), |
| 81 | yuv_v_(random_generator_.Rand(0, 255)) {} |
| 82 | |
| 83 | void Draw(const rtc::scoped_refptr<I420Buffer>& buffer) { |
| 84 | x_ = (x_ + random_generator_.Rand(0, 4)) % (buffer->width() - length_); |
| 85 | y_ = (y_ + random_generator_.Rand(0, 4)) % (buffer->height() - length_); |
| 86 | for (int x = x_; x < x_ + length_; ++x) { |
| 87 | for (int y = y_; y < y_ + length_; ++y) { |
| 88 | uint8_t* pos_y = (buffer->MutableDataY() + x + y * buffer->StrideY()); |
| 89 | *pos_y = yuv_y_; |
| 90 | uint8_t* pos_u = |
| 91 | (buffer->MutableDataU() + x / 2 + y / 2 * buffer->StrideU()); |
| 92 | *pos_u = yuv_u_; |
| 93 | uint8_t* pos_v = |
| 94 | (buffer->MutableDataV() + x / 2 + y / 2 * buffer->StrideV()); |
| 95 | *pos_v = yuv_v_; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | private: |
| 101 | Random random_generator_; |
| 102 | int x_; |
| 103 | int y_; |
| 104 | const int length_; |
| 105 | const uint8_t yuv_y_; |
| 106 | const uint8_t yuv_u_; |
| 107 | const uint8_t yuv_v_; |
| 108 | }; |
| 109 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 110 | rtc::CriticalSection crit_; |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 111 | int width_ GUARDED_BY(&crit_); |
| 112 | int height_ GUARDED_BY(&crit_); |
| 113 | int half_width_ GUARDED_BY(&crit_); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 114 | size_t y_size_ GUARDED_BY(&crit_); |
| 115 | size_t uv_size_ GUARDED_BY(&crit_); |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 116 | std::vector<std::unique_ptr<Square>> squares_ GUARDED_BY(&crit_); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 117 | std::unique_ptr<VideoFrame> frame_ GUARDED_BY(&crit_); |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 120 | class YuvFileGenerator : public FrameGenerator { |
| 121 | public: |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 122 | YuvFileGenerator(std::vector<FILE*> files, |
| 123 | size_t width, |
| 124 | size_t height, |
| 125 | int frame_repeat_count) |
| 126 | : file_index_(0), |
| 127 | files_(files), |
| 128 | width_(width), |
| 129 | height_(height), |
| 130 | frame_size_(CalcBufferSize(kI420, |
| 131 | static_cast<int>(width_), |
| 132 | static_cast<int>(height_))), |
| 133 | frame_buffer_(new uint8_t[frame_size_]), |
| 134 | frame_display_count_(frame_repeat_count), |
| 135 | current_display_count_(0) { |
kwiberg | b890c95c | 2016-11-29 05:30:40 -0800 | [diff] [blame] | 136 | RTC_DCHECK_GT(width, 0); |
| 137 | RTC_DCHECK_GT(height, 0); |
| 138 | RTC_DCHECK_GT(frame_repeat_count, 0); |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | virtual ~YuvFileGenerator() { |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 142 | for (FILE* file : files_) |
| 143 | fclose(file); |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 146 | VideoFrame* NextFrame() override { |
sprang@webrtc.org | 25dd1db | 2015-03-02 11:55:45 +0000 | [diff] [blame] | 147 | if (current_display_count_ == 0) |
| 148 | ReadNextFrame(); |
| 149 | if (++current_display_count_ >= frame_display_count_) |
| 150 | current_display_count_ = 0; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 151 | |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 152 | temp_frame_.reset( |
| 153 | new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0)); |
| 154 | return temp_frame_.get(); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 155 | } |
pbos@webrtc.org | 724947b | 2013-12-11 16:26:16 +0000 | [diff] [blame] | 156 | |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 157 | void ReadNextFrame() { |
nisse | 115bd15 | 2016-09-30 04:14:07 -0700 | [diff] [blame] | 158 | last_read_buffer_ = |
| 159 | test::ReadI420Buffer(static_cast<int>(width_), |
| 160 | static_cast<int>(height_), |
| 161 | files_[file_index_]); |
| 162 | if (!last_read_buffer_) { |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 163 | // No more frames to read in this file, rewind and move to next file. |
| 164 | rewind(files_[file_index_]); |
| 165 | file_index_ = (file_index_ + 1) % files_.size(); |
nisse | 115bd15 | 2016-09-30 04:14:07 -0700 | [diff] [blame] | 166 | last_read_buffer_ = |
| 167 | test::ReadI420Buffer(static_cast<int>(width_), |
| 168 | static_cast<int>(height_), |
| 169 | files_[file_index_]); |
| 170 | RTC_CHECK(last_read_buffer_); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 171 | } |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | private: |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 175 | size_t file_index_; |
| 176 | const std::vector<FILE*> files_; |
| 177 | const size_t width_; |
| 178 | const size_t height_; |
| 179 | const size_t frame_size_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 180 | const std::unique_ptr<uint8_t[]> frame_buffer_; |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 181 | const int frame_display_count_; |
| 182 | int current_display_count_; |
nisse | 1996e3f | 2016-09-19 00:34:46 -0700 | [diff] [blame] | 183 | rtc::scoped_refptr<I420Buffer> last_read_buffer_; |
| 184 | std::unique_ptr<VideoFrame> temp_frame_; |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 185 | }; |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 186 | |
| 187 | class ScrollingImageFrameGenerator : public FrameGenerator { |
| 188 | public: |
| 189 | ScrollingImageFrameGenerator(Clock* clock, |
| 190 | const std::vector<FILE*>& files, |
| 191 | size_t source_width, |
| 192 | size_t source_height, |
| 193 | size_t target_width, |
| 194 | size_t target_height, |
| 195 | int64_t scroll_time_ms, |
| 196 | int64_t pause_time_ms) |
| 197 | : clock_(clock), |
| 198 | start_time_(clock->TimeInMilliseconds()), |
| 199 | scroll_time_(scroll_time_ms), |
| 200 | pause_time_(pause_time_ms), |
| 201 | num_frames_(files.size()), |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 202 | target_width_(static_cast<int>(target_width)), |
| 203 | target_height_(static_cast<int>(target_height)), |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 204 | current_frame_num_(num_frames_ - 1), |
| 205 | current_source_frame_(nullptr), |
| 206 | file_generator_(files, source_width, source_height, 1) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 207 | RTC_DCHECK(clock_ != nullptr); |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 208 | RTC_DCHECK_GT(num_frames_, 0); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 209 | RTC_DCHECK_GE(source_height, target_height); |
| 210 | RTC_DCHECK_GE(source_width, target_width); |
| 211 | RTC_DCHECK_GE(scroll_time_ms, 0); |
| 212 | RTC_DCHECK_GE(pause_time_ms, 0); |
| 213 | RTC_DCHECK_GT(scroll_time_ms + pause_time_ms, 0); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | virtual ~ScrollingImageFrameGenerator() {} |
| 217 | |
| 218 | VideoFrame* NextFrame() override { |
| 219 | const int64_t kFrameDisplayTime = scroll_time_ + pause_time_; |
| 220 | const int64_t now = clock_->TimeInMilliseconds(); |
| 221 | int64_t ms_since_start = now - start_time_; |
| 222 | |
| 223 | size_t frame_num = (ms_since_start / kFrameDisplayTime) % num_frames_; |
| 224 | UpdateSourceFrame(frame_num); |
| 225 | |
| 226 | double scroll_factor; |
| 227 | int64_t time_into_frame = ms_since_start % kFrameDisplayTime; |
| 228 | if (time_into_frame < scroll_time_) { |
| 229 | scroll_factor = static_cast<double>(time_into_frame) / scroll_time_; |
| 230 | } else { |
| 231 | scroll_factor = 1.0; |
| 232 | } |
| 233 | CropSourceToScrolledImage(scroll_factor); |
| 234 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 235 | return current_frame_ ? &*current_frame_ : nullptr; |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void UpdateSourceFrame(size_t frame_num) { |
| 239 | while (current_frame_num_ != frame_num) { |
| 240 | current_source_frame_ = file_generator_.NextFrame(); |
| 241 | current_frame_num_ = (current_frame_num_ + 1) % num_frames_; |
| 242 | } |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 243 | RTC_DCHECK(current_source_frame_ != nullptr); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void CropSourceToScrolledImage(double scroll_factor) { |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 247 | int scroll_margin_x = current_source_frame_->width() - target_width_; |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 248 | int pixels_scrolled_x = |
| 249 | static_cast<int>(scroll_margin_x * scroll_factor + 0.5); |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 250 | int scroll_margin_y = current_source_frame_->height() - target_height_; |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 251 | int pixels_scrolled_y = |
| 252 | static_cast<int>(scroll_margin_y * scroll_factor + 0.5); |
| 253 | |
nisse | c9c142f | 2016-05-17 04:05:47 -0700 | [diff] [blame] | 254 | int offset_y = (current_source_frame_->video_frame_buffer()->StrideY() * |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 255 | pixels_scrolled_y) + |
| 256 | pixels_scrolled_x; |
nisse | c9c142f | 2016-05-17 04:05:47 -0700 | [diff] [blame] | 257 | int offset_u = (current_source_frame_->video_frame_buffer()->StrideU() * |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 258 | (pixels_scrolled_y / 2)) + |
| 259 | (pixels_scrolled_x / 2); |
nisse | c9c142f | 2016-05-17 04:05:47 -0700 | [diff] [blame] | 260 | int offset_v = (current_source_frame_->video_frame_buffer()->StrideV() * |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 261 | (pixels_scrolled_y / 2)) + |
| 262 | (pixels_scrolled_x / 2); |
| 263 | |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 264 | rtc::scoped_refptr<VideoFrameBuffer> frame_buffer( |
| 265 | current_source_frame_->video_frame_buffer()); |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 266 | current_frame_ = rtc::Optional<webrtc::VideoFrame>(webrtc::VideoFrame( |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 267 | new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
| 268 | target_width_, target_height_, |
| 269 | &frame_buffer->DataY()[offset_y], frame_buffer->StrideY(), |
| 270 | &frame_buffer->DataU()[offset_u], frame_buffer->StrideU(), |
| 271 | &frame_buffer->DataV()[offset_v], frame_buffer->StrideV(), |
| 272 | KeepRefUntilDone(frame_buffer)), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 273 | kVideoRotation_0, 0)); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | Clock* const clock_; |
| 277 | const int64_t start_time_; |
| 278 | const int64_t scroll_time_; |
| 279 | const int64_t pause_time_; |
| 280 | const size_t num_frames_; |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 281 | const int target_width_; |
| 282 | const int target_height_; |
| 283 | |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 284 | size_t current_frame_num_; |
| 285 | VideoFrame* current_source_frame_; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 286 | rtc::Optional<VideoFrame> current_frame_; |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 287 | YuvFileGenerator file_generator_; |
| 288 | }; |
| 289 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 290 | } // namespace |
| 291 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 292 | FrameForwarder::FrameForwarder() : sink_(nullptr) {} |
sprang | b1ca073 | 2017-02-01 08:38:12 -0800 | [diff] [blame] | 293 | FrameForwarder::~FrameForwarder() {} |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 294 | |
| 295 | void FrameForwarder::IncomingCapturedFrame(const VideoFrame& video_frame) { |
| 296 | rtc::CritScope lock(&crit_); |
| 297 | if (sink_) |
| 298 | sink_->OnFrame(video_frame); |
| 299 | } |
| 300 | |
| 301 | void FrameForwarder::AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 302 | const rtc::VideoSinkWants& wants) { |
| 303 | rtc::CritScope lock(&crit_); |
| 304 | RTC_DCHECK(!sink_ || sink_ == sink); |
| 305 | sink_ = sink; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 306 | sink_wants_ = wants; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void FrameForwarder::RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 310 | rtc::CritScope lock(&crit_); |
| 311 | RTC_DCHECK_EQ(sink, sink_); |
| 312 | sink_ = nullptr; |
| 313 | } |
| 314 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 315 | rtc::VideoSinkWants FrameForwarder::sink_wants() const { |
| 316 | rtc::CritScope lock(&crit_); |
| 317 | return sink_wants_; |
| 318 | } |
| 319 | |
| 320 | bool FrameForwarder::has_sinks() const { |
| 321 | rtc::CritScope lock(&crit_); |
| 322 | return sink_ != nullptr; |
| 323 | } |
| 324 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 325 | std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator( |
| 326 | int width, |
| 327 | int height) { |
| 328 | return std::unique_ptr<FrameGenerator>(new SquareGenerator(width, height)); |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 329 | } |
| 330 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 331 | std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile( |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 332 | std::vector<std::string> filenames, |
| 333 | size_t width, |
| 334 | size_t height, |
| 335 | int frame_repeat_count) { |
kwiberg | b890c95c | 2016-11-29 05:30:40 -0800 | [diff] [blame] | 336 | RTC_DCHECK(!filenames.empty()); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 337 | std::vector<FILE*> files; |
| 338 | for (const std::string& filename : filenames) { |
| 339 | FILE* file = fopen(filename.c_str(), "rb"); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 340 | RTC_DCHECK(file != nullptr); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 341 | files.push_back(file); |
| 342 | } |
| 343 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 344 | return std::unique_ptr<FrameGenerator>( |
| 345 | new YuvFileGenerator(files, width, height, frame_repeat_count)); |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 346 | } |
| 347 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 348 | std::unique_ptr<FrameGenerator> |
| 349 | FrameGenerator::CreateScrollingInputFromYuvFiles( |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 350 | Clock* clock, |
| 351 | std::vector<std::string> filenames, |
| 352 | size_t source_width, |
| 353 | size_t source_height, |
| 354 | size_t target_width, |
| 355 | size_t target_height, |
| 356 | int64_t scroll_time_ms, |
| 357 | int64_t pause_time_ms) { |
kwiberg | b890c95c | 2016-11-29 05:30:40 -0800 | [diff] [blame] | 358 | RTC_DCHECK(!filenames.empty()); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 359 | std::vector<FILE*> files; |
| 360 | for (const std::string& filename : filenames) { |
| 361 | FILE* file = fopen(filename.c_str(), "rb"); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 362 | RTC_DCHECK(file != nullptr); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 363 | files.push_back(file); |
| 364 | } |
| 365 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 366 | return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator( |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 367 | clock, files, source_width, source_height, target_width, target_height, |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame^] | 368 | scroll_time_ms, pause_time_ms)); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 369 | } |
| 370 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 371 | } // namespace test |
| 372 | } // namespace webrtc |