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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "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 <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <cstdint> |
| 15 | #include <cstdio> |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
Emircan Uysaler | 0823eec | 2018-07-13 17:10:00 -0700 | [diff] [blame] | 18 | #include "api/video/i010_buffer.h" |
Evan Shrubsole | 55c1786 | 2020-09-28 10:16:00 +0200 | [diff] [blame] | 19 | #include "api/video/nv12_buffer.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/video/video_rotation.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "common_video/include/video_frame_buffer.h" |
| 22 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
| 23 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "test/frame_utils.h" |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | namespace test { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 28 | |
| 29 | SquareGenerator::SquareGenerator(int width, |
| 30 | int height, |
| 31 | OutputType type, |
| 32 | int num_squares) |
| 33 | : type_(type) { |
| 34 | ChangeResolution(width, height); |
| 35 | for (int i = 0; i < num_squares; ++i) { |
| 36 | squares_.emplace_back(new Square(width, height, i + 1)); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void SquareGenerator::ChangeResolution(size_t width, size_t height) { |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 41 | MutexLock lock(&mutex_); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 42 | width_ = static_cast<int>(width); |
| 43 | height_ = static_cast<int>(height); |
| 44 | RTC_CHECK(width_ > 0); |
| 45 | RTC_CHECK(height_ > 0); |
| 46 | } |
| 47 | |
| 48 | rtc::scoped_refptr<I420Buffer> SquareGenerator::CreateI420Buffer(int width, |
| 49 | int height) { |
| 50 | rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create(width, height)); |
| 51 | memset(buffer->MutableDataY(), 127, height * buffer->StrideY()); |
| 52 | memset(buffer->MutableDataU(), 127, |
| 53 | buffer->ChromaHeight() * buffer->StrideU()); |
| 54 | memset(buffer->MutableDataV(), 127, |
| 55 | buffer->ChromaHeight() * buffer->StrideV()); |
| 56 | return buffer; |
| 57 | } |
| 58 | |
| 59 | FrameGeneratorInterface::VideoFrameData SquareGenerator::NextFrame() { |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 60 | MutexLock lock(&mutex_); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 61 | |
| 62 | rtc::scoped_refptr<VideoFrameBuffer> buffer = nullptr; |
| 63 | switch (type_) { |
| 64 | case OutputType::kI420: |
Evan Shrubsole | 55c1786 | 2020-09-28 10:16:00 +0200 | [diff] [blame] | 65 | case OutputType::kI010: |
| 66 | case OutputType::kNV12: { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 67 | buffer = CreateI420Buffer(width_, height_); |
| 68 | break; |
| 69 | } |
| 70 | case OutputType::kI420A: { |
| 71 | rtc::scoped_refptr<I420Buffer> yuv_buffer = |
| 72 | CreateI420Buffer(width_, height_); |
| 73 | rtc::scoped_refptr<I420Buffer> axx_buffer = |
| 74 | CreateI420Buffer(width_, height_); |
Niels Möller | a68bfc5 | 2021-01-11 13:26:35 +0100 | [diff] [blame] | 75 | buffer = WrapI420ABuffer(yuv_buffer->width(), yuv_buffer->height(), |
| 76 | yuv_buffer->DataY(), yuv_buffer->StrideY(), |
| 77 | yuv_buffer->DataU(), yuv_buffer->StrideU(), |
| 78 | yuv_buffer->DataV(), yuv_buffer->StrideV(), |
| 79 | axx_buffer->DataY(), axx_buffer->StrideY(), |
| 80 | // To keep references alive. |
| 81 | [yuv_buffer, axx_buffer] {}); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | default: |
Artem Titov | d325196 | 2021-11-15 16:57:07 +0100 | [diff] [blame^] | 85 | RTC_DCHECK_NOTREACHED() << "The given output format is not supported."; |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | for (const auto& square : squares_) |
| 89 | square->Draw(buffer); |
| 90 | |
| 91 | if (type_ == OutputType::kI010) { |
| 92 | buffer = I010Buffer::Copy(*buffer->ToI420()); |
Evan Shrubsole | 55c1786 | 2020-09-28 10:16:00 +0200 | [diff] [blame] | 93 | } else if (type_ == OutputType::kNV12) { |
| 94 | buffer = NV12Buffer::Copy(*buffer->ToI420()); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | return VideoFrameData(buffer, absl::nullopt); |
| 98 | } |
| 99 | |
| 100 | SquareGenerator::Square::Square(int width, int height, int seed) |
| 101 | : random_generator_(seed), |
| 102 | x_(random_generator_.Rand(0, width)), |
| 103 | y_(random_generator_.Rand(0, height)), |
| 104 | length_(random_generator_.Rand(1, width > 4 ? width / 4 : 1)), |
| 105 | yuv_y_(random_generator_.Rand(0, 255)), |
| 106 | yuv_u_(random_generator_.Rand(0, 255)), |
| 107 | yuv_v_(random_generator_.Rand(0, 255)), |
| 108 | yuv_a_(random_generator_.Rand(0, 255)) {} |
| 109 | |
| 110 | void SquareGenerator::Square::Draw( |
| 111 | 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(); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 115 | int length_cap = std::min(buffer->height(), buffer->width()) / 4; |
| 116 | int length = std::min(length_, length_cap); |
| 117 | x_ = (x_ + random_generator_.Rand(0, 4)) % (buffer->width() - length); |
| 118 | y_ = (y_ + random_generator_.Rand(0, 4)) % (buffer->height() - length); |
| 119 | for (int y = y_; y < y_ + length; ++y) { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 120 | uint8_t* pos_y = |
| 121 | (const_cast<uint8_t*>(buffer->DataY()) + x_ + y * buffer->StrideY()); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 122 | memset(pos_y, yuv_y_, length); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 125 | for (int y = y_; y < y_ + length; y = y + 2) { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 126 | uint8_t* pos_u = (const_cast<uint8_t*>(buffer->DataU()) + x_ / 2 + |
| 127 | y / 2 * buffer->StrideU()); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 128 | memset(pos_u, yuv_u_, length / 2); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 129 | uint8_t* pos_v = (const_cast<uint8_t*>(buffer->DataV()) + x_ / 2 + |
| 130 | y / 2 * buffer->StrideV()); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 131 | memset(pos_v, yuv_v_, length / 2); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if (frame_buffer->type() == VideoFrameBuffer::Type::kI420) |
| 135 | return; |
| 136 | |
| 137 | // Optionally draw on alpha plane if given. |
| 138 | const webrtc::I420ABufferInterface* yuva_buffer = frame_buffer->GetI420A(); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 139 | for (int y = y_; y < y_ + length; ++y) { |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 140 | uint8_t* pos_y = (const_cast<uint8_t*>(yuva_buffer->DataA()) + x_ + |
| 141 | y * yuva_buffer->StrideA()); |
Sebastian Jansson | d35a686 | 2020-03-09 19:18:14 +0100 | [diff] [blame] | 142 | memset(pos_y, yuv_a_, length); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | YuvFileGenerator::YuvFileGenerator(std::vector<FILE*> files, |
| 147 | size_t width, |
| 148 | size_t height, |
| 149 | int frame_repeat_count) |
| 150 | : file_index_(0), |
| 151 | frame_index_(std::numeric_limits<size_t>::max()), |
| 152 | files_(files), |
| 153 | width_(width), |
| 154 | height_(height), |
| 155 | frame_size_(CalcBufferSize(VideoType::kI420, |
| 156 | static_cast<int>(width_), |
| 157 | static_cast<int>(height_))), |
| 158 | frame_buffer_(new uint8_t[frame_size_]), |
| 159 | frame_display_count_(frame_repeat_count), |
| 160 | current_display_count_(0) { |
| 161 | RTC_DCHECK_GT(width, 0); |
| 162 | RTC_DCHECK_GT(height, 0); |
| 163 | RTC_DCHECK_GT(frame_repeat_count, 0); |
| 164 | } |
| 165 | |
| 166 | YuvFileGenerator::~YuvFileGenerator() { |
| 167 | for (FILE* file : files_) |
| 168 | fclose(file); |
| 169 | } |
| 170 | |
| 171 | FrameGeneratorInterface::VideoFrameData YuvFileGenerator::NextFrame() { |
| 172 | // Empty update by default. |
| 173 | VideoFrame::UpdateRect update_rect{0, 0, 0, 0}; |
| 174 | if (current_display_count_ == 0) { |
| 175 | const bool got_new_frame = ReadNextFrame(); |
| 176 | // Full update on a new frame from file. |
| 177 | if (got_new_frame) { |
| 178 | update_rect = VideoFrame::UpdateRect{0, 0, static_cast<int>(width_), |
| 179 | static_cast<int>(height_)}; |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 180 | } |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 181 | } |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 182 | if (++current_display_count_ >= frame_display_count_) |
| 183 | current_display_count_ = 0; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 184 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 185 | return VideoFrameData(last_read_buffer_, update_rect); |
| 186 | } |
pbos@webrtc.org | 266c7b3 | 2013-10-15 09:15:47 +0000 | [diff] [blame] | 187 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 188 | bool YuvFileGenerator::ReadNextFrame() { |
| 189 | size_t prev_frame_index = frame_index_; |
| 190 | size_t prev_file_index = file_index_; |
| 191 | last_read_buffer_ = test::ReadI420Buffer( |
| 192 | static_cast<int>(width_), static_cast<int>(height_), files_[file_index_]); |
| 193 | ++frame_index_; |
| 194 | if (!last_read_buffer_) { |
| 195 | // No more frames to read in this file, rewind and move to next file. |
| 196 | rewind(files_[file_index_]); |
Emircan Uysaler | 03e6ec9 | 2018-03-09 15:03:26 -0800 | [diff] [blame] | 197 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 198 | frame_index_ = 0; |
| 199 | file_index_ = (file_index_ + 1) % files_.size(); |
nisse | 115bd15 | 2016-09-30 04:14:07 -0700 | [diff] [blame] | 200 | last_read_buffer_ = |
| 201 | test::ReadI420Buffer(static_cast<int>(width_), |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 202 | static_cast<int>(height_), files_[file_index_]); |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 203 | RTC_CHECK(last_read_buffer_); |
| 204 | } |
| 205 | return frame_index_ != prev_frame_index || file_index_ != prev_file_index; |
| 206 | } |
Ilya Nikolaevskiy | d0f3d84 | 2019-03-04 15:10:44 +0100 | [diff] [blame] | 207 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 208 | SlideGenerator::SlideGenerator(int width, int height, int frame_repeat_count) |
| 209 | : width_(width), |
| 210 | height_(height), |
| 211 | frame_display_count_(frame_repeat_count), |
| 212 | current_display_count_(0), |
| 213 | random_generator_(1234) { |
| 214 | RTC_DCHECK_GT(width, 0); |
| 215 | RTC_DCHECK_GT(height, 0); |
| 216 | RTC_DCHECK_GT(frame_repeat_count, 0); |
| 217 | } |
| 218 | |
| 219 | FrameGeneratorInterface::VideoFrameData SlideGenerator::NextFrame() { |
| 220 | if (current_display_count_ == 0) |
| 221 | GenerateNewFrame(); |
| 222 | if (++current_display_count_ >= frame_display_count_) |
| 223 | current_display_count_ = 0; |
| 224 | |
| 225 | return VideoFrameData(buffer_, absl::nullopt); |
| 226 | } |
| 227 | |
| 228 | void SlideGenerator::GenerateNewFrame() { |
| 229 | // The squares should have a varying order of magnitude in order |
| 230 | // to simulate variation in the slides' complexity. |
| 231 | const int kSquareNum = 1 << (4 + (random_generator_.Rand(0, 3) * 2)); |
| 232 | |
| 233 | buffer_ = I420Buffer::Create(width_, height_); |
| 234 | memset(buffer_->MutableDataY(), 127, height_ * buffer_->StrideY()); |
| 235 | memset(buffer_->MutableDataU(), 127, |
| 236 | buffer_->ChromaHeight() * buffer_->StrideU()); |
| 237 | memset(buffer_->MutableDataV(), 127, |
| 238 | buffer_->ChromaHeight() * buffer_->StrideV()); |
| 239 | |
| 240 | for (int i = 0; i < kSquareNum; ++i) { |
| 241 | int length = random_generator_.Rand(1, width_ > 4 ? width_ / 4 : 1); |
| 242 | // Limit the length of later squares so that they don't overwrite the |
| 243 | // previous ones too much. |
| 244 | length = (length * (kSquareNum - i)) / kSquareNum; |
| 245 | |
| 246 | int x = random_generator_.Rand(0, width_ - length); |
| 247 | int y = random_generator_.Rand(0, height_ - length); |
| 248 | uint8_t yuv_y = random_generator_.Rand(0, 255); |
| 249 | uint8_t yuv_u = random_generator_.Rand(0, 255); |
| 250 | uint8_t yuv_v = random_generator_.Rand(0, 255); |
| 251 | |
| 252 | for (int yy = y; yy < y + length; ++yy) { |
| 253 | uint8_t* pos_y = (buffer_->MutableDataY() + x + yy * buffer_->StrideY()); |
| 254 | memset(pos_y, yuv_y, length); |
sprang@webrtc.org | 131bea8 | 2015-02-18 12:46:06 +0000 | [diff] [blame] | 255 | } |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 256 | for (int yy = y; yy < y + length; yy += 2) { |
| 257 | uint8_t* pos_u = |
| 258 | (buffer_->MutableDataU() + x / 2 + yy / 2 * buffer_->StrideU()); |
| 259 | memset(pos_u, yuv_u, length / 2); |
| 260 | uint8_t* pos_v = |
| 261 | (buffer_->MutableDataV() + x / 2 + yy / 2 * buffer_->StrideV()); |
| 262 | memset(pos_v, yuv_v, length / 2); |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 267 | ScrollingImageFrameGenerator::ScrollingImageFrameGenerator( |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 268 | Clock* clock, |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 269 | const std::vector<FILE*>& files, |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 270 | size_t source_width, |
| 271 | size_t source_height, |
| 272 | size_t target_width, |
| 273 | size_t target_height, |
| 274 | int64_t scroll_time_ms, |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 275 | int64_t pause_time_ms) |
| 276 | : clock_(clock), |
| 277 | start_time_(clock->TimeInMilliseconds()), |
| 278 | scroll_time_(scroll_time_ms), |
| 279 | pause_time_(pause_time_ms), |
| 280 | num_frames_(files.size()), |
| 281 | target_width_(static_cast<int>(target_width)), |
| 282 | target_height_(static_cast<int>(target_height)), |
| 283 | current_frame_num_(num_frames_ - 1), |
| 284 | prev_frame_not_scrolled_(false), |
| 285 | current_source_frame_(nullptr, absl::nullopt), |
| 286 | current_frame_(nullptr, absl::nullopt), |
| 287 | file_generator_(files, source_width, source_height, 1) { |
| 288 | RTC_DCHECK(clock_ != nullptr); |
| 289 | RTC_DCHECK_GT(num_frames_, 0); |
| 290 | RTC_DCHECK_GE(source_height, target_height); |
| 291 | RTC_DCHECK_GE(source_width, target_width); |
| 292 | RTC_DCHECK_GE(scroll_time_ms, 0); |
| 293 | RTC_DCHECK_GE(pause_time_ms, 0); |
| 294 | RTC_DCHECK_GT(scroll_time_ms + pause_time_ms, 0); |
| 295 | } |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 296 | |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 297 | FrameGeneratorInterface::VideoFrameData |
| 298 | ScrollingImageFrameGenerator::NextFrame() { |
| 299 | const int64_t kFrameDisplayTime = scroll_time_ + pause_time_; |
| 300 | const int64_t now = clock_->TimeInMilliseconds(); |
| 301 | int64_t ms_since_start = now - start_time_; |
| 302 | |
| 303 | size_t frame_num = (ms_since_start / kFrameDisplayTime) % num_frames_; |
| 304 | UpdateSourceFrame(frame_num); |
| 305 | |
| 306 | bool cur_frame_not_scrolled; |
| 307 | |
| 308 | double scroll_factor; |
| 309 | int64_t time_into_frame = ms_since_start % kFrameDisplayTime; |
| 310 | if (time_into_frame < scroll_time_) { |
| 311 | scroll_factor = static_cast<double>(time_into_frame) / scroll_time_; |
| 312 | cur_frame_not_scrolled = false; |
| 313 | } else { |
| 314 | scroll_factor = 1.0; |
| 315 | cur_frame_not_scrolled = true; |
| 316 | } |
| 317 | CropSourceToScrolledImage(scroll_factor); |
| 318 | |
| 319 | bool same_scroll_position = |
| 320 | prev_frame_not_scrolled_ && cur_frame_not_scrolled; |
| 321 | if (!same_scroll_position) { |
| 322 | // If scrolling is not finished yet, force full frame update. |
| 323 | current_frame_.update_rect = |
| 324 | VideoFrame::UpdateRect{0, 0, target_width_, target_height_}; |
| 325 | } |
| 326 | prev_frame_not_scrolled_ = cur_frame_not_scrolled; |
| 327 | |
| 328 | return current_frame_; |
| 329 | } |
| 330 | |
| 331 | void ScrollingImageFrameGenerator::UpdateSourceFrame(size_t frame_num) { |
| 332 | VideoFrame::UpdateRect acc_update{0, 0, 0, 0}; |
| 333 | while (current_frame_num_ != frame_num) { |
| 334 | current_source_frame_ = file_generator_.NextFrame(); |
| 335 | if (current_source_frame_.update_rect) { |
| 336 | acc_update.Union(*current_source_frame_.update_rect); |
| 337 | } |
| 338 | current_frame_num_ = (current_frame_num_ + 1) % num_frames_; |
| 339 | } |
| 340 | current_source_frame_.update_rect = acc_update; |
| 341 | } |
| 342 | |
| 343 | void ScrollingImageFrameGenerator::CropSourceToScrolledImage( |
| 344 | double scroll_factor) { |
| 345 | int scroll_margin_x = current_source_frame_.buffer->width() - target_width_; |
| 346 | int pixels_scrolled_x = |
| 347 | static_cast<int>(scroll_margin_x * scroll_factor + 0.5); |
| 348 | int scroll_margin_y = current_source_frame_.buffer->height() - target_height_; |
| 349 | int pixels_scrolled_y = |
| 350 | static_cast<int>(scroll_margin_y * scroll_factor + 0.5); |
| 351 | |
| 352 | rtc::scoped_refptr<I420BufferInterface> i420_buffer = |
| 353 | current_source_frame_.buffer->ToI420(); |
| 354 | int offset_y = |
| 355 | (i420_buffer->StrideY() * pixels_scrolled_y) + pixels_scrolled_x; |
| 356 | int offset_u = (i420_buffer->StrideU() * (pixels_scrolled_y / 2)) + |
| 357 | (pixels_scrolled_x / 2); |
| 358 | int offset_v = (i420_buffer->StrideV() * (pixels_scrolled_y / 2)) + |
| 359 | (pixels_scrolled_x / 2); |
| 360 | |
| 361 | VideoFrame::UpdateRect update_rect = |
| 362 | current_source_frame_.update_rect->IsEmpty() |
| 363 | ? VideoFrame::UpdateRect{0, 0, 0, 0} |
| 364 | : VideoFrame::UpdateRect{0, 0, target_width_, target_height_}; |
| 365 | current_frame_ = VideoFrameData( |
| 366 | WrapI420Buffer(target_width_, target_height_, |
| 367 | &i420_buffer->DataY()[offset_y], i420_buffer->StrideY(), |
| 368 | &i420_buffer->DataU()[offset_u], i420_buffer->StrideU(), |
| 369 | &i420_buffer->DataV()[offset_v], i420_buffer->StrideV(), |
Niels Möller | f4e3e2b | 2021-02-02 11:37:39 +0100 | [diff] [blame] | 370 | // To keep reference alive. |
| 371 | [i420_buffer] {}), |
Artem Titov | 33f9d2b | 2019-12-05 15:59:00 +0100 | [diff] [blame] | 372 | update_rect); |
sprang | d635895 | 2015-07-29 07:58:13 -0700 | [diff] [blame] | 373 | } |
| 374 | |
andresp@webrtc.org | ab65495 | 2013-09-19 12:14:03 +0000 | [diff] [blame] | 375 | } // namespace test |
| 376 | } // namespace webrtc |