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