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

Side by Side Diff: talk/media/base/videoframe_unittest.h

Issue 1586613002: Delete remnants of non-square pixel support from cricket::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Keep old InitToBlack and InitToEmptyBuffer methods. Created 4 years, 11 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
« no previous file with comments | « talk/media/base/videoframe.cc ('k') | talk/media/webrtc/webrtcvideoframe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 uint32_t format, 145 uint32_t format,
146 int32_t width, 146 int32_t width,
147 int32_t height, 147 int32_t height,
148 int dw, 148 int dw,
149 int dh, 149 int dh,
150 webrtc::VideoRotation rotation, 150 webrtc::VideoRotation rotation,
151 T* frame) { 151 T* frame) {
152 bool ret = false; 152 bool ret = false;
153 for (int i = 0; i < repeat_; ++i) { 153 for (int i = 0; i < repeat_; ++i) {
154 ret = frame->Init(format, width, height, dw, dh, 154 ret = frame->Init(format, width, height, dw, dh,
155 sample, sample_size, 1, 1, 0, rotation); 155 sample, sample_size, 0, rotation);
156 } 156 }
157 return ret; 157 return ret;
158 } 158 }
159 159
160 rtc::MemoryStream* LoadSample(const std::string& filename) { 160 rtc::MemoryStream* LoadSample(const std::string& filename) {
161 rtc::Pathname path(cricket::GetTestFilePath(filename)); 161 rtc::Pathname path(cricket::GetTestFilePath(filename));
162 rtc::scoped_ptr<rtc::FileStream> fs( 162 rtc::scoped_ptr<rtc::FileStream> fs(
163 rtc::Filesystem::OpenFile(path, "rb")); 163 rtc::Filesystem::OpenFile(path, "rb"));
164 if (!fs.get()) { 164 if (!fs.get()) {
165 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname() 165 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname()
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 uint32_t width, 288 uint32_t width,
289 uint32_t height, 289 uint32_t height,
290 T* frame) { 290 T* frame) {
291 int y1_pos, y2_pos, u_pos, v_pos; 291 int y1_pos, y2_pos, u_pos, v_pos;
292 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) { 292 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) {
293 return false; 293 return false;
294 } 294 }
295 295
296 const uint8_t* start = reinterpret_cast<const uint8_t*>(ms->GetBuffer()); 296 const uint8_t* start = reinterpret_cast<const uint8_t*>(ms->GetBuffer());
297 int awidth = (width + 1) & ~1; 297 int awidth = (width + 1) & ~1;
298 frame->InitToBlack(width, height, 1, 1, 0); 298 frame->InitToBlack(width, height, 0);
299 int stride_y = frame->GetYPitch(); 299 int stride_y = frame->GetYPitch();
300 int stride_u = frame->GetUPitch(); 300 int stride_u = frame->GetUPitch();
301 int stride_v = frame->GetVPitch(); 301 int stride_v = frame->GetVPitch();
302 for (uint32_t y = 0; y < height; ++y) { 302 for (uint32_t y = 0; y < height; ++y) {
303 for (uint32_t x = 0; x < width; x += 2) { 303 for (uint32_t x = 0; x < width; x += 2) {
304 const uint8_t* quad1 = start + (y * awidth + x) * 2; 304 const uint8_t* quad1 = start + (y * awidth + x) * 2;
305 frame->GetYPlane()[stride_y * y + x] = quad1[y1_pos]; 305 frame->GetYPlane()[stride_y * y + x] = quad1[y1_pos];
306 if ((x + 1) < width) { 306 if ((x + 1) < width) {
307 frame->GetYPlane()[stride_y * y + x + 1] = quad1[y2_pos]; 307 frame->GetYPlane()[stride_y * y + x + 1] = quad1[y2_pos];
308 } 308 }
(...skipping 23 matching lines...) Expand all
332 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) { 332 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) {
333 return false; 333 return false;
334 } 334 }
335 int pitch = width * bytes; 335 int pitch = width * bytes;
336 const uint8_t* start = reinterpret_cast<const uint8_t*>(ms->GetBuffer()); 336 const uint8_t* start = reinterpret_cast<const uint8_t*>(ms->GetBuffer());
337 if (height < 0) { 337 if (height < 0) {
338 height = -height; 338 height = -height;
339 start = start + pitch * (height - 1); 339 start = start + pitch * (height - 1);
340 pitch = -pitch; 340 pitch = -pitch;
341 } 341 }
342 frame->InitToBlack(width, height, 1, 1, 0); 342 frame->InitToBlack(width, height, 0);
343 int stride_y = frame->GetYPitch(); 343 int stride_y = frame->GetYPitch();
344 int stride_u = frame->GetUPitch(); 344 int stride_u = frame->GetUPitch();
345 int stride_v = frame->GetVPitch(); 345 int stride_v = frame->GetVPitch();
346 for (int32_t y = 0; y < height; y += 2) { 346 for (int32_t y = 0; y < height; y += 2) {
347 for (int32_t x = 0; x < width; x += 2) { 347 for (int32_t x = 0; x < width; x += 2) {
348 const uint8_t* rgb[4]; 348 const uint8_t* rgb[4];
349 uint8_t yuv[4][3]; 349 uint8_t yuv[4][3];
350 rgb[0] = start + y * pitch + x * bytes; 350 rgb[0] = start + y * pitch + x * bytes;
351 rgb[1] = rgb[0] + ((x + 1) < width ? bytes : 0); 351 rgb[1] = rgb[0] + ((x + 1) < width ? bytes : 0);
352 rgb[2] = rgb[0] + ((y + 1) < height ? pitch : 0); 352 rgb[2] = rgb[0] + ((y + 1) < height ? pitch : 0);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 458 }
459 r1 += pitch1; 459 r1 += pitch1;
460 r2 += pitch2; 460 r2 += pitch2;
461 } 461 }
462 return true; 462 return true;
463 } 463 }
464 464
465 static bool IsEqual(const cricket::VideoFrame& frame, 465 static bool IsEqual(const cricket::VideoFrame& frame,
466 size_t width, 466 size_t width,
467 size_t height, 467 size_t height,
468 size_t pixel_width,
469 size_t pixel_height,
470 int64_t time_stamp, 468 int64_t time_stamp,
471 const uint8_t* y, 469 const uint8_t* y,
472 uint32_t ypitch, 470 uint32_t ypitch,
473 const uint8_t* u, 471 const uint8_t* u,
474 uint32_t upitch, 472 uint32_t upitch,
475 const uint8_t* v, 473 const uint8_t* v,
476 uint32_t vpitch, 474 uint32_t vpitch,
477 int max_error) { 475 int max_error) {
478 return IsSize(frame, static_cast<uint32_t>(width), 476 return IsSize(frame, static_cast<uint32_t>(width),
479 static_cast<uint32_t>(height)) && 477 static_cast<uint32_t>(height)) &&
480 frame.GetPixelWidth() == pixel_width &&
481 frame.GetPixelHeight() == pixel_height &&
482 frame.GetTimeStamp() == time_stamp && 478 frame.GetTimeStamp() == time_stamp &&
483 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch, 479 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch,
484 static_cast<uint32_t>(width), 480 static_cast<uint32_t>(width),
485 static_cast<uint32_t>(height), max_error) && 481 static_cast<uint32_t>(height), max_error) &&
486 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch, 482 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch,
487 static_cast<uint32_t>((width + 1) / 2), 483 static_cast<uint32_t>((width + 1) / 2),
488 static_cast<uint32_t>((height + 1) / 2), max_error) && 484 static_cast<uint32_t>((height + 1) / 2), max_error) &&
489 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch, 485 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch,
490 static_cast<uint32_t>((width + 1) / 2), 486 static_cast<uint32_t>((width + 1) / 2),
491 static_cast<uint32_t>((height + 1) / 2), max_error); 487 static_cast<uint32_t>((height + 1) / 2), max_error);
492 } 488 }
493 489
494 static bool IsEqual(const cricket::VideoFrame& frame1, 490 static bool IsEqual(const cricket::VideoFrame& frame1,
495 const cricket::VideoFrame& frame2, 491 const cricket::VideoFrame& frame2,
496 int max_error) { 492 int max_error) {
497 return IsEqual(frame1, 493 return IsEqual(frame1,
498 frame2.GetWidth(), frame2.GetHeight(), 494 frame2.GetWidth(), frame2.GetHeight(),
499 frame2.GetPixelWidth(), frame2.GetPixelHeight(),
500 frame2.GetTimeStamp(), 495 frame2.GetTimeStamp(),
501 frame2.GetYPlane(), frame2.GetYPitch(), 496 frame2.GetYPlane(), frame2.GetYPitch(),
502 frame2.GetUPlane(), frame2.GetUPitch(), 497 frame2.GetUPlane(), frame2.GetUPitch(),
503 frame2.GetVPlane(), frame2.GetVPitch(), 498 frame2.GetVPlane(), frame2.GetVPitch(),
504 max_error); 499 max_error);
505 } 500 }
506 501
507 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, 502 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1,
508 const cricket::VideoFrame& frame2, 503 const cricket::VideoFrame& frame2,
509 int hcrop, int vcrop, int max_error) { 504 int hcrop, int vcrop, int max_error) {
510 return frame1.GetWidth() <= frame2.GetWidth() && 505 return frame1.GetWidth() <= frame2.GetWidth() &&
511 frame1.GetHeight() <= frame2.GetHeight() && 506 frame1.GetHeight() <= frame2.GetHeight() &&
512 IsEqual(frame1, 507 IsEqual(frame1,
513 frame2.GetWidth() - hcrop * 2, 508 frame2.GetWidth() - hcrop * 2,
514 frame2.GetHeight() - vcrop * 2, 509 frame2.GetHeight() - vcrop * 2,
515 frame2.GetPixelWidth(), frame2.GetPixelHeight(),
516 frame2.GetTimeStamp(), 510 frame2.GetTimeStamp(),
517 frame2.GetYPlane() + vcrop * frame2.GetYPitch() 511 frame2.GetYPlane() + vcrop * frame2.GetYPitch()
518 + hcrop, 512 + hcrop,
519 frame2.GetYPitch(), 513 frame2.GetYPitch(),
520 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 514 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2
521 + hcrop / 2, 515 + hcrop / 2,
522 frame2.GetUPitch(), 516 frame2.GetUPitch(),
523 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 517 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2
524 + hcrop / 2, 518 + hcrop / 2,
525 frame2.GetVPitch(), 519 frame2.GetVPitch(),
(...skipping 16 matching lines...) Expand all
542 T frame; 536 T frame;
543 EXPECT_TRUE(IsNull(frame)); 537 EXPECT_TRUE(IsNull(frame));
544 rtc::scoped_ptr<rtc::MemoryStream> ms( 538 rtc::scoped_ptr<rtc::MemoryStream> ms(
545 CreateYuvSample(kWidth, kHeight, 12)); 539 CreateYuvSample(kWidth, kHeight, 12));
546 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, 540 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420,
547 kWidth, kHeight, &frame)); 541 kWidth, kHeight, &frame));
548 542
549 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); 543 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer());
550 const uint8_t* u = y + kWidth * kHeight; 544 const uint8_t* u = y + kWidth * kHeight;
551 const uint8_t* v = u + kWidth * kHeight / 4; 545 const uint8_t* v = u + kWidth * kHeight / 4;
552 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, y, kWidth, u, 546 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u,
553 kWidth / 2, v, kWidth / 2, 0)); 547 kWidth / 2, v, kWidth / 2, 0));
554 } 548 }
555 549
556 // Test constructing an image from a YV12 buffer. 550 // Test constructing an image from a YV12 buffer.
557 void ConstructYV12() { 551 void ConstructYV12() {
558 T frame; 552 T frame;
559 rtc::scoped_ptr<rtc::MemoryStream> ms( 553 rtc::scoped_ptr<rtc::MemoryStream> ms(
560 CreateYuvSample(kWidth, kHeight, 12)); 554 CreateYuvSample(kWidth, kHeight, 12));
561 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, 555 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12,
562 kWidth, kHeight, &frame)); 556 kWidth, kHeight, &frame));
563 557
564 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); 558 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer());
565 const uint8_t* v = y + kWidth * kHeight; 559 const uint8_t* v = y + kWidth * kHeight;
566 const uint8_t* u = v + kWidth * kHeight / 4; 560 const uint8_t* u = v + kWidth * kHeight / 4;
567 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, y, kWidth, u, 561 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u,
568 kWidth / 2, v, kWidth / 2, 0)); 562 kWidth / 2, v, kWidth / 2, 0));
569 } 563 }
570 564
571 // Test constructing an image from a I422 buffer. 565 // Test constructing an image from a I422 buffer.
572 void ConstructI422() { 566 void ConstructI422() {
573 T frame1, frame2; 567 T frame1, frame2;
574 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); 568 ASSERT_TRUE(LoadFrameNoRepeat(&frame1));
575 size_t buf_size = kWidth * kHeight * 2; 569 size_t buf_size = kWidth * kHeight * 2;
576 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); 570 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]);
577 uint8_t* y = ALIGNP(buf.get(), kAlignment); 571 uint8_t* y = ALIGNP(buf.get(), kAlignment);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 ASSERT_TRUE(ms.get() != NULL); \ 815 ASSERT_TRUE(ms.get() != NULL); \
822 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ 816 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \
823 -kHeight, kWidth, kHeight, \ 817 -kHeight, kWidth, kHeight, \
824 webrtc::kVideoRotation_180, &frame1)); \ 818 webrtc::kVideoRotation_180, &frame1)); \
825 size_t data_size; \ 819 size_t data_size; \
826 bool ret = ms->GetSize(&data_size); \ 820 bool ret = ms->GetSize(&data_size); \
827 EXPECT_TRUE(ret); \ 821 EXPECT_TRUE(ret); \
828 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ 822 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \
829 kHeight, \ 823 kHeight, \
830 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ 824 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \
831 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ 825 data_size, 0, webrtc::kVideoRotation_0)); \
832 int width_rotate = static_cast<int>(frame1.GetWidth()); \ 826 int width_rotate = static_cast<int>(frame1.GetWidth()); \
833 int height_rotate = static_cast<int>(frame1.GetHeight()); \ 827 int height_rotate = static_cast<int>(frame1.GetHeight()); \
834 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ 828 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \
835 libyuv::I420Mirror( \ 829 libyuv::I420Mirror( \
836 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ 830 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \
837 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ 831 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \
838 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ 832 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \
839 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ 833 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \
840 kHeight); \ 834 kHeight); \
841 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ 835 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \
842 } 836 }
843 837
844 TEST_MIRROR(I420, 420) 838 TEST_MIRROR(I420, 420)
845 839
846 // Macro to help test different rotations 840 // Macro to help test different rotations
847 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ 841 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \
848 void Construct##FOURCC##Rotate##ROTATE() { \ 842 void Construct##FOURCC##Rotate##ROTATE() { \
849 T frame1, frame2, frame3; \ 843 T frame1, frame2, frame3; \
850 rtc::scoped_ptr<rtc::MemoryStream> ms( \ 844 rtc::scoped_ptr<rtc::MemoryStream> ms( \
851 CreateYuvSample(kWidth, kHeight, BPP)); \ 845 CreateYuvSample(kWidth, kHeight, BPP)); \
852 ASSERT_TRUE(ms.get() != NULL); \ 846 ASSERT_TRUE(ms.get() != NULL); \
853 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ 847 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \
854 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ 848 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \
855 &frame1)); \ 849 &frame1)); \
856 size_t data_size; \ 850 size_t data_size; \
857 bool ret = ms->GetSize(&data_size); \ 851 bool ret = ms->GetSize(&data_size); \
858 EXPECT_TRUE(ret); \ 852 EXPECT_TRUE(ret); \
859 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ 853 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \
860 kHeight, \ 854 kHeight, \
861 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ 855 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \
862 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ 856 data_size, 0, webrtc::kVideoRotation_0)); \
863 int width_rotate = static_cast<int>(frame1.GetWidth()); \ 857 int width_rotate = static_cast<int>(frame1.GetWidth()); \
864 int height_rotate = static_cast<int>(frame1.GetHeight()); \ 858 int height_rotate = static_cast<int>(frame1.GetHeight()); \
865 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ 859 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \
866 libyuv::I420Rotate( \ 860 libyuv::I420Rotate( \
867 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ 861 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \
868 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ 862 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \
869 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ 863 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \
870 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ 864 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \
871 kHeight, libyuv::kRotate##ROTATE); \ 865 kHeight, libyuv::kRotate##ROTATE); \
872 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ 866 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \
873 } 867 }
874 868
875 // Test constructing an image with rotation. 869 // Test constructing an image with rotation.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 kWidth, kHeight, webrtc::kVideoRotation_270, 955 kWidth, kHeight, webrtc::kVideoRotation_270,
962 &frame2)); 956 &frame2));
963 } 957 }
964 958
965 // Test 1 pixel edge case image I420 buffer. 959 // Test 1 pixel edge case image I420 buffer.
966 void ConstructI4201Pixel() { 960 void ConstructI4201Pixel() {
967 T frame; 961 T frame;
968 uint8_t pixel[3] = {1, 2, 3}; 962 uint8_t pixel[3] = {1, 2, 3};
969 for (int i = 0; i < repeat_; ++i) { 963 for (int i = 0; i < repeat_; ++i) {
970 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, 964 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel,
971 sizeof(pixel), 1, 1, 0, webrtc::kVideoRotation_0)); 965 sizeof(pixel), 0, webrtc::kVideoRotation_0));
972 } 966 }
973 const uint8_t* y = pixel; 967 const uint8_t* y = pixel;
974 const uint8_t* u = y + 1; 968 const uint8_t* u = y + 1;
975 const uint8_t* v = u + 1; 969 const uint8_t* v = u + 1;
976 EXPECT_TRUE(IsEqual(frame, 1, 1, 1, 1, 0, y, 1, u, 1, v, 1, 0)); 970 EXPECT_TRUE(IsEqual(frame, 1, 1, 0, y, 1, u, 1, v, 1, 0));
977 } 971 }
978 972
979 // Test 5 pixel edge case image. 973 // Test 5 pixel edge case image.
980 void ConstructI4205Pixel() { 974 void ConstructI4205Pixel() {
981 T frame; 975 T frame;
982 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; 976 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2];
983 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); 977 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2);
984 for (int i = 0; i < repeat_; ++i) { 978 for (int i = 0; i < repeat_; ++i) {
985 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, 979 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5,
986 sizeof(pixels5x5), 1, 1, 0, 980 sizeof(pixels5x5), 0,
987 webrtc::kVideoRotation_0)); 981 webrtc::kVideoRotation_0));
988 } 982 }
989 EXPECT_EQ(5u, frame.GetWidth()); 983 EXPECT_EQ(5u, frame.GetWidth());
990 EXPECT_EQ(5u, frame.GetHeight()); 984 EXPECT_EQ(5u, frame.GetHeight());
991 EXPECT_EQ(5, frame.GetYPitch()); 985 EXPECT_EQ(5, frame.GetYPitch());
992 EXPECT_EQ(3, frame.GetUPitch()); 986 EXPECT_EQ(3, frame.GetUPitch());
993 EXPECT_EQ(3, frame.GetVPitch()); 987 EXPECT_EQ(3, frame.GetVPitch());
994 } 988 }
995 989
996 // Test 1 pixel edge case image ARGB buffer. 990 // Test 1 pixel edge case image ARGB buffer.
997 void ConstructARGB1Pixel() { 991 void ConstructARGB1Pixel() {
998 T frame; 992 T frame;
999 uint8_t pixel[4] = {64, 128, 192, 255}; 993 uint8_t pixel[4] = {64, 128, 192, 255};
1000 for (int i = 0; i < repeat_; ++i) { 994 for (int i = 0; i < repeat_; ++i) {
1001 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, 995 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel,
1002 sizeof(pixel), 1, 1, 0, 996 sizeof(pixel), 0,
1003 webrtc::kVideoRotation_0)); 997 webrtc::kVideoRotation_0));
1004 } 998 }
1005 // Convert back to ARGB. 999 // Convert back to ARGB.
1006 size_t out_size = 4; 1000 size_t out_size = 4;
1007 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); 1001 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]);
1008 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); 1002 uint8_t* out = ALIGNP(outbuf.get(), kAlignment);
1009 1003
1010 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, 1004 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB,
1011 out, 1005 out,
1012 out_size, // buffer size 1006 out_size, // buffer size
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); 1336 EXPECT_TRUE(IsEqual(frame1, frame2, 0));
1343 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane()); 1337 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane());
1344 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane()); 1338 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane());
1345 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane()); 1339 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane());
1346 } 1340 }
1347 1341
1348 // Test creating an empty image and initing it to black. 1342 // Test creating an empty image and initing it to black.
1349 void ConstructBlack() { 1343 void ConstructBlack() {
1350 T frame; 1344 T frame;
1351 for (int i = 0; i < repeat_; ++i) { 1345 for (int i = 0; i < repeat_; ++i) {
1352 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 1, 1, 0)); 1346 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 0));
1353 } 1347 }
1354 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); 1348 EXPECT_TRUE(IsSize(frame, kWidth, kHeight));
1355 EXPECT_TRUE(IsBlack(frame)); 1349 EXPECT_TRUE(IsBlack(frame));
1356 } 1350 }
1357 1351
1358 // Test constructing an image from a YUY2 buffer with a range of sizes. 1352 // Test constructing an image from a YUY2 buffer with a range of sizes.
1359 // Only tests that conversion does not crash or corrupt heap. 1353 // Only tests that conversion does not crash or corrupt heap.
1360 void ConstructYuy2AllSizes() { 1354 void ConstructYuy2AllSizes() {
1361 T frame1, frame2; 1355 T frame1, frame2;
1362 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { 1356 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } 1402 }
1409 1403
1410 // Tests re-initing an existing image. 1404 // Tests re-initing an existing image.
1411 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { 1405 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) {
1412 T frame1, frame2; 1406 T frame1, frame2;
1413 rtc::scoped_ptr<rtc::MemoryStream> ms( 1407 rtc::scoped_ptr<rtc::MemoryStream> ms(
1414 LoadSample(kImageFilename)); 1408 LoadSample(kImageFilename));
1415 ASSERT_TRUE(ms.get() != NULL); 1409 ASSERT_TRUE(ms.get() != NULL);
1416 size_t data_size; 1410 size_t data_size;
1417 ms->GetSize(&data_size); 1411 ms->GetSize(&data_size);
1418 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 1, 1, 0)); 1412 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 0));
1419 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); 1413 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0));
1420 EXPECT_TRUE(IsBlack(frame1)); 1414 EXPECT_TRUE(IsBlack(frame1));
1421 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); 1415 EXPECT_TRUE(IsEqual(frame1, frame2, 0));
1422 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, 1416 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth,
1423 kHeight, 1417 kHeight,
1424 reinterpret_cast<uint8_t*>(ms->GetBuffer()), 1418 reinterpret_cast<uint8_t*>(ms->GetBuffer()),
1425 data_size, 1, 1, 0, rotation, apply_rotation)); 1419 data_size, 0, rotation, apply_rotation));
1426 if (apply_rotation) 1420 if (apply_rotation)
1427 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); 1421 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation());
1428 else 1422 else
1429 EXPECT_EQ(rotation, frame1.GetVideoRotation()); 1423 EXPECT_EQ(rotation, frame1.GetVideoRotation());
1430 1424
1431 // Swapp width and height if the frame is rotated 90 or 270 degrees. 1425 // Swapp width and height if the frame is rotated 90 or 270 degrees.
1432 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 1426 if (apply_rotation && (rotation == webrtc::kVideoRotation_90
1433 || rotation == webrtc::kVideoRotation_270)) { 1427 || rotation == webrtc::kVideoRotation_270)) {
1434 EXPECT_TRUE(kHeight == frame1.GetWidth()); 1428 EXPECT_TRUE(kHeight == frame1.GetWidth());
1435 EXPECT_TRUE(kWidth == frame1.GetHeight()); 1429 EXPECT_TRUE(kWidth == frame1.GetHeight());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 out += (kHeight - 1) * stride; // Point to last row. 1481 out += (kHeight - 1) * stride; // Point to last row.
1488 stride = -stride; 1482 stride = -stride;
1489 } 1483 }
1490 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); 1484 ASSERT_TRUE(LoadFrameNoRepeat(&frame1));
1491 1485
1492 for (int i = 0; i < repeat_to; ++i) { 1486 for (int i = 0; i < repeat_to; ++i) {
1493 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, 1487 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc,
1494 out, 1488 out,
1495 out_size, stride)); 1489 out_size, stride));
1496 } 1490 }
1497 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); 1491 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0));
1498 for (int i = 0; i < repeat_from; ++i) { 1492 for (int i = 0; i < repeat_from; ++i) {
1499 EXPECT_EQ(0, RGBToI420(out, stride, 1493 EXPECT_EQ(0, RGBToI420(out, stride,
1500 frame2.GetYPlane(), frame2.GetYPitch(), 1494 frame2.GetYPlane(), frame2.GetYPitch(),
1501 frame2.GetUPlane(), frame2.GetUPitch(), 1495 frame2.GetUPlane(), frame2.GetUPitch(),
1502 frame2.GetVPlane(), frame2.GetVPitch(), 1496 frame2.GetVPlane(), frame2.GetVPitch(),
1503 kWidth, kHeight)); 1497 kWidth, kHeight));
1504 } 1498 }
1505 if (rowpad) { 1499 if (rowpad) {
1506 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row. 1500 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row.
1507 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row. 1501 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row.
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size)); 1902 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size));
1909 } 1903 }
1910 1904
1911 void CopyToBuffer1Pixel() { 1905 void CopyToBuffer1Pixel() {
1912 size_t out_size = 3; 1906 size_t out_size = 3;
1913 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]); 1907 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]);
1914 memset(out.get(), 0xfb, out_size + 1); // Fill buffer 1908 memset(out.get(), 0xfb, out_size + 1); // Fill buffer
1915 uint8_t pixel[3] = {1, 2, 3}; 1909 uint8_t pixel[3] = {1, 2, 3};
1916 T frame; 1910 T frame;
1917 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, 1911 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel,
1918 sizeof(pixel), 1, 1, 0, 1912 sizeof(pixel), 0,
1919 webrtc::kVideoRotation_0)); 1913 webrtc::kVideoRotation_0));
1920 for (int i = 0; i < repeat_; ++i) { 1914 for (int i = 0; i < repeat_; ++i) {
1921 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size)); 1915 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size));
1922 } 1916 }
1923 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1. 1917 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1.
1924 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2. 1918 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2.
1925 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3. 1919 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3.
1926 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact. 1920 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact.
1927 } 1921 }
1928 1922
1929 void StretchToFrame() { 1923 void StretchToFrame() {
1930 // Create the source frame as a black frame. 1924 // Create the source frame as a black frame.
1931 T source; 1925 T source;
1932 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 1, 1, 0)); 1926 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0));
1933 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); 1927 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2));
1934 1928
1935 // Create the target frame by loading from a file. 1929 // Create the target frame by loading from a file.
1936 T target1; 1930 T target1;
1937 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); 1931 ASSERT_TRUE(LoadFrameNoRepeat(&target1));
1938 EXPECT_FALSE(IsBlack(target1)); 1932 EXPECT_FALSE(IsBlack(target1));
1939 1933
1940 // Stretch and check if the stretched target is black. 1934 // Stretch and check if the stretched target is black.
1941 source.StretchToFrame(&target1, true, false); 1935 source.StretchToFrame(&target1, true, false);
1942 EXPECT_TRUE(IsBlack(target1)); 1936 EXPECT_TRUE(IsBlack(target1));
1943 1937
1944 // Crop and stretch and check if the stretched target is black. 1938 // Crop and stretch and check if the stretched target is black.
1945 T target2; 1939 T target2;
1946 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); 1940 ASSERT_TRUE(LoadFrameNoRepeat(&target2));
1947 source.StretchToFrame(&target2, true, true); 1941 source.StretchToFrame(&target2, true, true);
1948 EXPECT_TRUE(IsBlack(target2)); 1942 EXPECT_TRUE(IsBlack(target2));
1949 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); 1943 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp());
1950 } 1944 }
1951 1945
1952 int repeat_; 1946 int repeat_;
1953 }; 1947 };
1954 1948
1955 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ 1949 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_
OLDNEW
« no previous file with comments | « talk/media/base/videoframe.cc ('k') | talk/media/webrtc/webrtcvideoframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698