Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: webrtc/common_video/i420_video_frame_unittest.cc

Issue 2078943002: Rewrite CreateBlackFrame in webrtcvideoengine. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 10
(...skipping 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 23
24 int ExpectedSize(int plane_stride, int image_height, PlaneType type) { 24 int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
25 if (type == kYPlane) 25 if (type == kYPlane)
26 return plane_stride * image_height; 26 return plane_stride * image_height;
27 return plane_stride * ((image_height + 1) / 2); 27 return plane_stride * ((image_height + 1) / 2);
28 } 28 }
29 29
30 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) { 30 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) {
31 rtc::scoped_refptr<I420Buffer> buffer( 31 rtc::scoped_refptr<I420Buffer> buffer(
32 new rtc::RefCountedObject<I420Buffer>(width, height)); 32 I420Buffer::Create(width, height));
33 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h 33 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
34 for (int x = 0; x < width; x++) { 34 for (int x = 0; x < width; x++) {
35 for (int y = 0; y < height; y++) { 35 for (int y = 0; y < height; y++) {
36 buffer->MutableDataY()[x + y * width] = 36 buffer->MutableDataY()[x + y * width] =
37 128 * (x * height + y * width) / (width * height); 37 128 * (x * height + y * width) / (width * height);
38 } 38 }
39 } 39 }
40 int chroma_width = (width + 1) / 2; 40 int chroma_width = (width + 1) / 2;
41 int chroma_height = (height + 1) / 2; 41 int chroma_height = (height + 1) / 2;
42 for (int x = 0; x < chroma_width; x++) { 42 for (int x = 0; x < chroma_width; x++) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 EXPECT_EQ(handle, frame.video_frame_buffer()->native_handle()); 289 EXPECT_EQ(handle, frame.video_frame_buffer()->native_handle());
290 290
291 frame.set_timestamp(200); 291 frame.set_timestamp(200);
292 EXPECT_EQ(200u, frame.timestamp()); 292 EXPECT_EQ(200u, frame.timestamp());
293 frame.set_render_time_ms(20); 293 frame.set_render_time_ms(20);
294 EXPECT_EQ(20, frame.render_time_ms()); 294 EXPECT_EQ(20, frame.render_time_ms());
295 } 295 }
296 296
297 TEST(TestI420FrameBuffer, Copy) { 297 TEST(TestI420FrameBuffer, Copy) {
298 rtc::scoped_refptr<I420Buffer> buf1( 298 rtc::scoped_refptr<I420Buffer> buf1(
299 new rtc::RefCountedObject<I420Buffer>(20, 10)); 299 I420Buffer::Create(20, 10));
300 memset(buf1->MutableDataY(), 1, 200); 300 memset(buf1->MutableDataY(), 1, 200);
301 memset(buf1->MutableDataU(), 2, 50); 301 memset(buf1->MutableDataU(), 2, 50);
302 memset(buf1->MutableDataV(), 3, 50); 302 memset(buf1->MutableDataV(), 3, 50);
303 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 303 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1);
304 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 304 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
305 } 305 }
306 306
307 TEST(TestI420FrameBuffer, Scale) { 307 TEST(TestI420FrameBuffer, Scale) {
308 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 308 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
309 309
310 // Pure scaling, no cropping. 310 // Pure scaling, no cropping.
311 rtc::scoped_refptr<I420Buffer> scaled_buffer( 311 rtc::scoped_refptr<I420Buffer> scaled_buffer(
312 new rtc::RefCountedObject<I420Buffer>(150, 75)); 312 I420Buffer::Create(150, 75));
313 313
314 scaled_buffer->ScaleFrom(buf); 314 scaled_buffer->ScaleFrom(buf);
315 CheckCrop(scaled_buffer, 0.0, 0.0, 1.0, 1.0); 315 CheckCrop(scaled_buffer, 0.0, 0.0, 1.0, 1.0);
316 } 316 }
317 317
318 TEST(TestI420FrameBuffer, CropXCenter) { 318 TEST(TestI420FrameBuffer, CropXCenter) {
319 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 319 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
320 320
321 // Pure center cropping, no scaling. 321 // Pure center cropping, no scaling.
322 rtc::scoped_refptr<I420Buffer> scaled_buffer( 322 rtc::scoped_refptr<I420Buffer> scaled_buffer(
323 new rtc::RefCountedObject<I420Buffer>(100, 100)); 323 I420Buffer::Create(100, 100));
324 324
325 scaled_buffer->CropAndScaleFrom(buf, 50, 0, 100, 100); 325 scaled_buffer->CropAndScaleFrom(buf, 50, 0, 100, 100);
326 CheckCrop(scaled_buffer, 0.25, 0.0, 0.5, 1.0); 326 CheckCrop(scaled_buffer, 0.25, 0.0, 0.5, 1.0);
327 } 327 }
328 328
329 TEST(TestI420FrameBuffer, CropXNotCenter) { 329 TEST(TestI420FrameBuffer, CropXNotCenter) {
330 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 330 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
331 331
332 // Non-center cropping, no scaling. 332 // Non-center cropping, no scaling.
333 rtc::scoped_refptr<I420Buffer> scaled_buffer( 333 rtc::scoped_refptr<I420Buffer> scaled_buffer(
334 new rtc::RefCountedObject<I420Buffer>(100, 100)); 334 I420Buffer::Create(100, 100));
335 335
336 scaled_buffer->CropAndScaleFrom(buf, 25, 0, 100, 100); 336 scaled_buffer->CropAndScaleFrom(buf, 25, 0, 100, 100);
337 CheckCrop(scaled_buffer, 0.125, 0.0, 0.5, 1.0); 337 CheckCrop(scaled_buffer, 0.125, 0.0, 0.5, 1.0);
338 } 338 }
339 339
340 TEST(TestI420FrameBuffer, CropYCenter) { 340 TEST(TestI420FrameBuffer, CropYCenter) {
341 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 341 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
342 342
343 // Pure center cropping, no scaling. 343 // Pure center cropping, no scaling.
344 rtc::scoped_refptr<I420Buffer> scaled_buffer( 344 rtc::scoped_refptr<I420Buffer> scaled_buffer(
345 new rtc::RefCountedObject<I420Buffer>(100, 100)); 345 I420Buffer::Create(100, 100));
346 346
347 scaled_buffer->CropAndScaleFrom(buf, 0, 50, 100, 100); 347 scaled_buffer->CropAndScaleFrom(buf, 0, 50, 100, 100);
348 CheckCrop(scaled_buffer, 0.0, 0.25, 1.0, 0.5); 348 CheckCrop(scaled_buffer, 0.0, 0.25, 1.0, 0.5);
349 } 349 }
350 350
351 TEST(TestI420FrameBuffer, CropYNotCenter) { 351 TEST(TestI420FrameBuffer, CropYNotCenter) {
352 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 352 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
353 353
354 // Non-center cropping, no scaling. 354 // Non-center cropping, no scaling.
355 rtc::scoped_refptr<I420Buffer> scaled_buffer( 355 rtc::scoped_refptr<I420Buffer> scaled_buffer(
356 new rtc::RefCountedObject<I420Buffer>(100, 100)); 356 I420Buffer::Create(100, 100));
357 357
358 scaled_buffer->CropAndScaleFrom(buf, 0, 25, 100, 100); 358 scaled_buffer->CropAndScaleFrom(buf, 0, 25, 100, 100);
359 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.5); 359 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.5);
360 } 360 }
361 361
362 TEST(TestI420FrameBuffer, CropAndScale16x9) { 362 TEST(TestI420FrameBuffer, CropAndScale16x9) {
363 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480); 363 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480);
364 364
365 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. 365 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2.
366 rtc::scoped_refptr<I420Buffer> scaled_buffer( 366 rtc::scoped_refptr<I420Buffer> scaled_buffer(
367 new rtc::RefCountedObject<I420Buffer>(320, 180)); 367 I420Buffer::Create(320, 180));
368 368
369 scaled_buffer->CropAndScaleFrom(buf); 369 scaled_buffer->CropAndScaleFrom(buf);
370 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75); 370 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75);
371 } 371 }
372 372
373 } // namespace webrtc 373 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/common_video/include/video_frame_buffer.h » ('j') | webrtc/media/engine/webrtcvideoengine2.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698