OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/test/frame_generator.h" | 10 #include "webrtc/test/frame_generator.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 const size_t width_; | 174 const size_t width_; |
175 const size_t height_; | 175 const size_t height_; |
176 const size_t frame_size_; | 176 const size_t frame_size_; |
177 const std::unique_ptr<uint8_t[]> frame_buffer_; | 177 const std::unique_ptr<uint8_t[]> frame_buffer_; |
178 const int frame_display_count_; | 178 const int frame_display_count_; |
179 int current_display_count_; | 179 int current_display_count_; |
180 rtc::scoped_refptr<I420Buffer> last_read_buffer_; | 180 rtc::scoped_refptr<I420Buffer> last_read_buffer_; |
181 std::unique_ptr<VideoFrame> temp_frame_; | 181 std::unique_ptr<VideoFrame> temp_frame_; |
182 }; | 182 }; |
183 | 183 |
184 // SlideGenerator works similarly to YuvFileGenerator but it fills the frames | |
185 // with randomly sized and colored squares instead of reading their content | |
186 // from files. | |
187 class SlideGenerator : public FrameGenerator { | |
188 public: | |
189 SlideGenerator(size_t width, size_t height, int frame_repeat_count) | |
190 : width_(width), | |
191 height_(height), | |
192 frame_display_count_(frame_repeat_count), | |
193 current_display_count_(0), | |
194 random_generator_(1234) { | |
195 RTC_DCHECK_GT(width, 0); | |
196 RTC_DCHECK_GT(height, 0); | |
197 RTC_DCHECK_GT(frame_repeat_count, 0); | |
198 } | |
199 | |
200 VideoFrame* NextFrame() override { | |
201 if (current_display_count_ == 0) | |
202 GenerateNewFrame(); | |
203 if (++current_display_count_ >= frame_display_count_) | |
204 current_display_count_ = 0; | |
205 | |
206 frame_.reset( | |
207 new VideoFrame(buffer_, 0, 0, webrtc::kVideoRotation_0)); | |
208 return frame_.get(); | |
209 } | |
210 | |
211 // Generates some randomly sized and colored squares scattered | |
212 // over the frame. | |
213 void GenerateNewFrame() { | |
214 const int kSquareNum = 20; | |
sprang_webrtc
2017/08/23 12:59:24
I think this will not properly catch the extreme v
erikvarga1
2017/08/23 14:41:25
Done. I didn't think to take the complexity change
| |
215 | |
216 buffer_ = I420Buffer::Create(width_, height_); | |
217 memset(buffer_->MutableDataY(), 127, height_ * buffer_->StrideY()); | |
218 memset(buffer_->MutableDataU(), 127, | |
219 buffer_->ChromaHeight() * buffer_->StrideU()); | |
220 memset(buffer_->MutableDataV(), 127, | |
221 buffer_->ChromaHeight() * buffer_->StrideV()); | |
222 | |
223 for (int i = 0; i < kSquareNum; ++i) { | |
224 int length = random_generator_.Rand(1, width_ > 4 ? width_ / 4 : 1); | |
225 int x = random_generator_.Rand(0, width_ - length); | |
226 int y = random_generator_.Rand(0, height_ - length); | |
227 uint8_t yuv_y = random_generator_.Rand(0, 255); | |
228 uint8_t yuv_u = random_generator_.Rand(0, 255); | |
229 uint8_t yuv_v = random_generator_.Rand(0, 255); | |
230 | |
231 for (int yy = y; yy < y + length; ++yy) { | |
232 uint8_t* pos_y = | |
233 (buffer_->MutableDataY() + x + yy * buffer_->StrideY()); | |
234 memset(pos_y, yuv_y, length); | |
235 } | |
236 for (int yy = y; yy < y + length; yy += 2) { | |
237 uint8_t* pos_u = | |
238 (buffer_->MutableDataU() + x / 2 + yy / 2 * buffer_->StrideU()); | |
239 memset(pos_u, yuv_u, length / 2); | |
240 uint8_t* pos_v = | |
241 (buffer_->MutableDataV() + x / 2 + yy / 2 * buffer_->StrideV()); | |
242 memset(pos_v, yuv_v, length / 2); | |
243 } | |
244 } | |
245 } | |
246 | |
247 private: | |
248 const size_t width_; | |
249 const size_t height_; | |
250 const int frame_display_count_; | |
251 int current_display_count_; | |
252 Random random_generator_; | |
253 rtc::scoped_refptr<I420Buffer> buffer_; | |
254 std::unique_ptr<VideoFrame> frame_; | |
255 }; | |
256 | |
184 class ScrollingImageFrameGenerator : public FrameGenerator { | 257 class ScrollingImageFrameGenerator : public FrameGenerator { |
185 public: | 258 public: |
186 ScrollingImageFrameGenerator(Clock* clock, | 259 ScrollingImageFrameGenerator(Clock* clock, |
187 const std::vector<FILE*>& files, | 260 const std::vector<FILE*>& files, |
188 size_t source_width, | 261 size_t source_width, |
189 size_t source_height, | 262 size_t source_height, |
190 size_t target_width, | 263 size_t target_width, |
191 size_t target_height, | 264 size_t target_height, |
192 int64_t scroll_time_ms, | 265 int64_t scroll_time_ms, |
193 int64_t pause_time_ms) | 266 int64_t pause_time_ms) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 rtc::CritScope lock(&crit_); | 387 rtc::CritScope lock(&crit_); |
315 return sink_ != nullptr; | 388 return sink_ != nullptr; |
316 } | 389 } |
317 | 390 |
318 std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator( | 391 std::unique_ptr<FrameGenerator> FrameGenerator::CreateSquareGenerator( |
319 int width, | 392 int width, |
320 int height) { | 393 int height) { |
321 return std::unique_ptr<FrameGenerator>(new SquareGenerator(width, height)); | 394 return std::unique_ptr<FrameGenerator>(new SquareGenerator(width, height)); |
322 } | 395 } |
323 | 396 |
397 std::unique_ptr<FrameGenerator> FrameGenerator::CreateSlideGenerator( | |
398 int width, int height, int frame_repeat_count) { | |
399 return std::unique_ptr<FrameGenerator>(new SlideGenerator( | |
400 width, height, frame_repeat_count)); | |
401 } | |
402 | |
324 std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile( | 403 std::unique_ptr<FrameGenerator> FrameGenerator::CreateFromYuvFile( |
325 std::vector<std::string> filenames, | 404 std::vector<std::string> filenames, |
326 size_t width, | 405 size_t width, |
327 size_t height, | 406 size_t height, |
328 int frame_repeat_count) { | 407 int frame_repeat_count) { |
329 RTC_DCHECK(!filenames.empty()); | 408 RTC_DCHECK(!filenames.empty()); |
330 std::vector<FILE*> files; | 409 std::vector<FILE*> files; |
331 for (const std::string& filename : filenames) { | 410 for (const std::string& filename : filenames) { |
332 FILE* file = fopen(filename.c_str(), "rb"); | 411 FILE* file = fopen(filename.c_str(), "rb"); |
333 RTC_DCHECK(file != nullptr); | 412 RTC_DCHECK(file != nullptr); |
(...skipping 22 matching lines...) Expand all Loading... | |
356 files.push_back(file); | 435 files.push_back(file); |
357 } | 436 } |
358 | 437 |
359 return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator( | 438 return std::unique_ptr<FrameGenerator>(new ScrollingImageFrameGenerator( |
360 clock, files, source_width, source_height, target_width, target_height, | 439 clock, files, source_width, source_height, target_width, target_height, |
361 scroll_time_ms, pause_time_ms)); | 440 scroll_time_ms, pause_time_ms)); |
362 } | 441 } |
363 | 442 |
364 } // namespace test | 443 } // namespace test |
365 } // namespace webrtc | 444 } // namespace webrtc |
OLD | NEW |