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