OLD | NEW |
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 uint32 format, | 135 uint32 format, |
136 int32 width, | 136 int32 width, |
137 int32 height, | 137 int32 height, |
138 int dw, | 138 int dw, |
139 int dh, | 139 int dh, |
140 webrtc::VideoRotation rotation, | 140 webrtc::VideoRotation rotation, |
141 T* frame) { | 141 T* frame) { |
142 bool ret = false; | 142 bool ret = false; |
143 for (int i = 0; i < repeat_; ++i) { | 143 for (int i = 0; i < repeat_; ++i) { |
144 ret = frame->Init(format, width, height, dw, dh, | 144 ret = frame->Init(format, width, height, dw, dh, |
145 sample, sample_size, 1, 1, 0, 0, rotation); | 145 sample, sample_size, 1, 1, 0, rotation); |
146 } | 146 } |
147 return ret; | 147 return ret; |
148 } | 148 } |
149 | 149 |
150 rtc::MemoryStream* LoadSample(const std::string& filename) { | 150 rtc::MemoryStream* LoadSample(const std::string& filename) { |
151 rtc::Pathname path(cricket::GetTestFilePath(filename)); | 151 rtc::Pathname path(cricket::GetTestFilePath(filename)); |
152 rtc::scoped_ptr<rtc::FileStream> fs( | 152 rtc::scoped_ptr<rtc::FileStream> fs( |
153 rtc::Filesystem::OpenFile(path, "rb")); | 153 rtc::Filesystem::OpenFile(path, "rb")); |
154 if (!fs.get()) { | 154 if (!fs.get()) { |
155 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname() | 155 LOG(LS_ERROR) << "Could not open test file path: " << path.pathname() |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 bool ConvertYuv422(const rtc::MemoryStream* ms, | 273 bool ConvertYuv422(const rtc::MemoryStream* ms, |
274 uint32 fourcc, uint32 width, uint32 height, | 274 uint32 fourcc, uint32 width, uint32 height, |
275 T* frame) { | 275 T* frame) { |
276 int y1_pos, y2_pos, u_pos, v_pos; | 276 int y1_pos, y2_pos, u_pos, v_pos; |
277 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) { | 277 if (!GetYuv422Packing(fourcc, &y1_pos, &y2_pos, &u_pos, &v_pos)) { |
278 return false; | 278 return false; |
279 } | 279 } |
280 | 280 |
281 const uint8* start = reinterpret_cast<const uint8*>(ms->GetBuffer()); | 281 const uint8* start = reinterpret_cast<const uint8*>(ms->GetBuffer()); |
282 int awidth = (width + 1) & ~1; | 282 int awidth = (width + 1) & ~1; |
283 frame->InitToBlack(width, height, 1, 1, 0, 0); | 283 frame->InitToBlack(width, height, 1, 1, 0); |
284 int stride_y = frame->GetYPitch(); | 284 int stride_y = frame->GetYPitch(); |
285 int stride_u = frame->GetUPitch(); | 285 int stride_u = frame->GetUPitch(); |
286 int stride_v = frame->GetVPitch(); | 286 int stride_v = frame->GetVPitch(); |
287 for (uint32 y = 0; y < height; ++y) { | 287 for (uint32 y = 0; y < height; ++y) { |
288 for (uint32 x = 0; x < width; x += 2) { | 288 for (uint32 x = 0; x < width; x += 2) { |
289 const uint8* quad1 = start + (y * awidth + x) * 2; | 289 const uint8* quad1 = start + (y * awidth + x) * 2; |
290 frame->GetYPlane()[stride_y * y + x] = quad1[y1_pos]; | 290 frame->GetYPlane()[stride_y * y + x] = quad1[y1_pos]; |
291 if ((x + 1) < width) { | 291 if ((x + 1) < width) { |
292 frame->GetYPlane()[stride_y * y + x + 1] = quad1[y2_pos]; | 292 frame->GetYPlane()[stride_y * y + x + 1] = quad1[y2_pos]; |
293 } | 293 } |
(...skipping 21 matching lines...) Expand all Loading... |
315 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) { | 315 if (!GetRgbPacking(fourcc, &r_pos, &g_pos, &b_pos, &bytes)) { |
316 return false; | 316 return false; |
317 } | 317 } |
318 int pitch = width * bytes; | 318 int pitch = width * bytes; |
319 const uint8* start = reinterpret_cast<const uint8*>(ms->GetBuffer()); | 319 const uint8* start = reinterpret_cast<const uint8*>(ms->GetBuffer()); |
320 if (height < 0) { | 320 if (height < 0) { |
321 height = -height; | 321 height = -height; |
322 start = start + pitch * (height - 1); | 322 start = start + pitch * (height - 1); |
323 pitch = -pitch; | 323 pitch = -pitch; |
324 } | 324 } |
325 frame->InitToBlack(width, height, 1, 1, 0, 0); | 325 frame->InitToBlack(width, height, 1, 1, 0); |
326 int stride_y = frame->GetYPitch(); | 326 int stride_y = frame->GetYPitch(); |
327 int stride_u = frame->GetUPitch(); | 327 int stride_u = frame->GetUPitch(); |
328 int stride_v = frame->GetVPitch(); | 328 int stride_v = frame->GetVPitch(); |
329 for (int32 y = 0; y < height; y += 2) { | 329 for (int32 y = 0; y < height; y += 2) { |
330 for (int32 x = 0; x < width; x += 2) { | 330 for (int32 x = 0; x < width; x += 2) { |
331 const uint8* rgb[4]; | 331 const uint8* rgb[4]; |
332 uint8 yuv[4][3]; | 332 uint8 yuv[4][3]; |
333 rgb[0] = start + y * pitch + x * bytes; | 333 rgb[0] = start + y * pitch + x * bytes; |
334 rgb[1] = rgb[0] + ((x + 1) < width ? bytes : 0); | 334 rgb[1] = rgb[0] + ((x + 1) < width ? bytes : 0); |
335 rgb[2] = rgb[0] + ((y + 1) < height ? pitch : 0); | 335 rgb[2] = rgb[0] + ((y + 1) < height ? pitch : 0); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 428 } |
429 r1 += pitch1; | 429 r1 += pitch1; |
430 r2 += pitch2; | 430 r2 += pitch2; |
431 } | 431 } |
432 return true; | 432 return true; |
433 } | 433 } |
434 | 434 |
435 static bool IsEqual(const cricket::VideoFrame& frame, | 435 static bool IsEqual(const cricket::VideoFrame& frame, |
436 size_t width, size_t height, | 436 size_t width, size_t height, |
437 size_t pixel_width, size_t pixel_height, | 437 size_t pixel_width, size_t pixel_height, |
438 int64 elapsed_time, int64 time_stamp, | 438 int64 time_stamp, |
439 const uint8* y, uint32 ypitch, | 439 const uint8* y, uint32 ypitch, |
440 const uint8* u, uint32 upitch, | 440 const uint8* u, uint32 upitch, |
441 const uint8* v, uint32 vpitch, | 441 const uint8* v, uint32 vpitch, |
442 int max_error) { | 442 int max_error) { |
443 return IsSize(frame, | 443 return IsSize(frame, |
444 static_cast<uint32>(width), | 444 static_cast<uint32>(width), |
445 static_cast<uint32>(height)) && | 445 static_cast<uint32>(height)) && |
446 frame.GetPixelWidth() == pixel_width && | 446 frame.GetPixelWidth() == pixel_width && |
447 frame.GetPixelHeight() == pixel_height && | 447 frame.GetPixelHeight() == pixel_height && |
448 frame.GetElapsedTime() == elapsed_time && | |
449 frame.GetTimeStamp() == time_stamp && | 448 frame.GetTimeStamp() == time_stamp && |
450 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch, | 449 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch, |
451 static_cast<uint32>(width), | 450 static_cast<uint32>(width), |
452 static_cast<uint32>(height), max_error) && | 451 static_cast<uint32>(height), max_error) && |
453 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch, | 452 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch, |
454 static_cast<uint32>((width + 1) / 2), | 453 static_cast<uint32>((width + 1) / 2), |
455 static_cast<uint32>((height + 1) / 2), max_error) && | 454 static_cast<uint32>((height + 1) / 2), max_error) && |
456 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch, | 455 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch, |
457 static_cast<uint32>((width + 1) / 2), | 456 static_cast<uint32>((width + 1) / 2), |
458 static_cast<uint32>((height + 1) / 2), max_error); | 457 static_cast<uint32>((height + 1) / 2), max_error); |
459 } | 458 } |
460 | 459 |
461 static bool IsEqual(const cricket::VideoFrame& frame1, | 460 static bool IsEqual(const cricket::VideoFrame& frame1, |
462 const cricket::VideoFrame& frame2, | 461 const cricket::VideoFrame& frame2, |
463 int max_error) { | 462 int max_error) { |
464 return IsEqual(frame1, | 463 return IsEqual(frame1, |
465 frame2.GetWidth(), frame2.GetHeight(), | 464 frame2.GetWidth(), frame2.GetHeight(), |
466 frame2.GetPixelWidth(), frame2.GetPixelHeight(), | 465 frame2.GetPixelWidth(), frame2.GetPixelHeight(), |
467 frame2.GetElapsedTime(), frame2.GetTimeStamp(), | 466 frame2.GetTimeStamp(), |
468 frame2.GetYPlane(), frame2.GetYPitch(), | 467 frame2.GetYPlane(), frame2.GetYPitch(), |
469 frame2.GetUPlane(), frame2.GetUPitch(), | 468 frame2.GetUPlane(), frame2.GetUPitch(), |
470 frame2.GetVPlane(), frame2.GetVPitch(), | 469 frame2.GetVPlane(), frame2.GetVPitch(), |
471 max_error); | 470 max_error); |
472 } | 471 } |
473 | 472 |
474 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, | 473 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, |
475 const cricket::VideoFrame& frame2, | 474 const cricket::VideoFrame& frame2, |
476 int hcrop, int vcrop, int max_error) { | 475 int hcrop, int vcrop, int max_error) { |
477 return frame1.GetWidth() <= frame2.GetWidth() && | 476 return frame1.GetWidth() <= frame2.GetWidth() && |
478 frame1.GetHeight() <= frame2.GetHeight() && | 477 frame1.GetHeight() <= frame2.GetHeight() && |
479 IsEqual(frame1, | 478 IsEqual(frame1, |
480 frame2.GetWidth() - hcrop * 2, | 479 frame2.GetWidth() - hcrop * 2, |
481 frame2.GetHeight() - vcrop * 2, | 480 frame2.GetHeight() - vcrop * 2, |
482 frame2.GetPixelWidth(), frame2.GetPixelHeight(), | 481 frame2.GetPixelWidth(), frame2.GetPixelHeight(), |
483 frame2.GetElapsedTime(), frame2.GetTimeStamp(), | 482 frame2.GetTimeStamp(), |
484 frame2.GetYPlane() + vcrop * frame2.GetYPitch() | 483 frame2.GetYPlane() + vcrop * frame2.GetYPitch() |
485 + hcrop, | 484 + hcrop, |
486 frame2.GetYPitch(), | 485 frame2.GetYPitch(), |
487 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 | 486 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 |
488 + hcrop / 2, | 487 + hcrop / 2, |
489 frame2.GetUPitch(), | 488 frame2.GetUPitch(), |
490 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 | 489 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 |
491 + hcrop / 2, | 490 + hcrop / 2, |
492 frame2.GetVPitch(), | 491 frame2.GetVPitch(), |
493 max_error); | 492 max_error); |
(...skipping 15 matching lines...) Expand all Loading... |
509 T frame; | 508 T frame; |
510 EXPECT_TRUE(IsNull(frame)); | 509 EXPECT_TRUE(IsNull(frame)); |
511 rtc::scoped_ptr<rtc::MemoryStream> ms( | 510 rtc::scoped_ptr<rtc::MemoryStream> ms( |
512 CreateYuvSample(kWidth, kHeight, 12)); | 511 CreateYuvSample(kWidth, kHeight, 12)); |
513 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, | 512 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, |
514 kWidth, kHeight, &frame)); | 513 kWidth, kHeight, &frame)); |
515 | 514 |
516 const uint8* y = reinterpret_cast<uint8*>(ms.get()->GetBuffer()); | 515 const uint8* y = reinterpret_cast<uint8*>(ms.get()->GetBuffer()); |
517 const uint8* u = y + kWidth * kHeight; | 516 const uint8* u = y + kWidth * kHeight; |
518 const uint8* v = u + kWidth * kHeight / 4; | 517 const uint8* v = u + kWidth * kHeight / 4; |
519 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, 0, | 518 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, |
520 y, kWidth, u, kWidth / 2, v, kWidth / 2, 0)); | 519 y, kWidth, u, kWidth / 2, v, kWidth / 2, 0)); |
521 } | 520 } |
522 | 521 |
523 // Test constructing an image from a YV12 buffer. | 522 // Test constructing an image from a YV12 buffer. |
524 void ConstructYV12() { | 523 void ConstructYV12() { |
525 T frame; | 524 T frame; |
526 rtc::scoped_ptr<rtc::MemoryStream> ms( | 525 rtc::scoped_ptr<rtc::MemoryStream> ms( |
527 CreateYuvSample(kWidth, kHeight, 12)); | 526 CreateYuvSample(kWidth, kHeight, 12)); |
528 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, | 527 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, |
529 kWidth, kHeight, &frame)); | 528 kWidth, kHeight, &frame)); |
530 | 529 |
531 const uint8* y = reinterpret_cast<uint8*>(ms.get()->GetBuffer()); | 530 const uint8* y = reinterpret_cast<uint8*>(ms.get()->GetBuffer()); |
532 const uint8* v = y + kWidth * kHeight; | 531 const uint8* v = y + kWidth * kHeight; |
533 const uint8* u = v + kWidth * kHeight / 4; | 532 const uint8* u = v + kWidth * kHeight / 4; |
534 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, 0, | 533 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, |
535 y, kWidth, u, kWidth / 2, v, kWidth / 2, 0)); | 534 y, kWidth, u, kWidth / 2, v, kWidth / 2, 0)); |
536 } | 535 } |
537 | 536 |
538 // Test constructing an image from a I422 buffer. | 537 // Test constructing an image from a I422 buffer. |
539 void ConstructI422() { | 538 void ConstructI422() { |
540 T frame1, frame2; | 539 T frame1, frame2; |
541 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 540 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
542 size_t buf_size = kWidth * kHeight * 2; | 541 size_t buf_size = kWidth * kHeight * 2; |
543 rtc::scoped_ptr<uint8[]> buf(new uint8[buf_size + kAlignment]); | 542 rtc::scoped_ptr<uint8[]> buf(new uint8[buf_size + kAlignment]); |
544 uint8* y = ALIGNP(buf.get(), kAlignment); | 543 uint8* y = ALIGNP(buf.get(), kAlignment); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 ASSERT_TRUE(ms.get() != NULL); \ | 787 ASSERT_TRUE(ms.get() != NULL); \ |
789 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ | 788 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ |
790 -kHeight, kWidth, kHeight, \ | 789 -kHeight, kWidth, kHeight, \ |
791 webrtc::kVideoRotation_180, &frame1)); \ | 790 webrtc::kVideoRotation_180, &frame1)); \ |
792 size_t data_size; \ | 791 size_t data_size; \ |
793 bool ret = ms->GetSize(&data_size); \ | 792 bool ret = ms->GetSize(&data_size); \ |
794 EXPECT_TRUE(ret); \ | 793 EXPECT_TRUE(ret); \ |
795 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 794 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
796 kHeight, \ | 795 kHeight, \ |
797 reinterpret_cast<uint8*>(ms->GetBuffer()), \ | 796 reinterpret_cast<uint8*>(ms->GetBuffer()), \ |
798 data_size, 1, 1, 0, 0, webrtc::kVideoRotation_0)); \ | 797 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ |
799 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 798 int width_rotate = static_cast<int>(frame1.GetWidth()); \ |
800 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 799 int height_rotate = static_cast<int>(frame1.GetHeight()); \ |
801 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0, 0)); \ | 800 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ |
802 libyuv::I420Mirror( \ | 801 libyuv::I420Mirror( \ |
803 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 802 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
804 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 803 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
805 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 804 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
806 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 805 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
807 kHeight); \ | 806 kHeight); \ |
808 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 807 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
809 } | 808 } |
810 | 809 |
811 TEST_MIRROR(I420, 420) | 810 TEST_MIRROR(I420, 420) |
812 | 811 |
813 // Macro to help test different rotations | 812 // Macro to help test different rotations |
814 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ | 813 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ |
815 void Construct##FOURCC##Rotate##ROTATE() { \ | 814 void Construct##FOURCC##Rotate##ROTATE() { \ |
816 T frame1, frame2, frame3; \ | 815 T frame1, frame2, frame3; \ |
817 rtc::scoped_ptr<rtc::MemoryStream> ms( \ | 816 rtc::scoped_ptr<rtc::MemoryStream> ms( \ |
818 CreateYuvSample(kWidth, kHeight, BPP)); \ | 817 CreateYuvSample(kWidth, kHeight, BPP)); \ |
819 ASSERT_TRUE(ms.get() != NULL); \ | 818 ASSERT_TRUE(ms.get() != NULL); \ |
820 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ | 819 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ |
821 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ | 820 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ |
822 &frame1)); \ | 821 &frame1)); \ |
823 size_t data_size; \ | 822 size_t data_size; \ |
824 bool ret = ms->GetSize(&data_size); \ | 823 bool ret = ms->GetSize(&data_size); \ |
825 EXPECT_TRUE(ret); \ | 824 EXPECT_TRUE(ret); \ |
826 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 825 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
827 kHeight, \ | 826 kHeight, \ |
828 reinterpret_cast<uint8*>(ms->GetBuffer()), \ | 827 reinterpret_cast<uint8*>(ms->GetBuffer()), \ |
829 data_size, 1, 1, 0, 0, webrtc::kVideoRotation_0)); \ | 828 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ |
830 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 829 int width_rotate = static_cast<int>(frame1.GetWidth()); \ |
831 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 830 int height_rotate = static_cast<int>(frame1.GetHeight()); \ |
832 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0, 0)); \ | 831 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ |
833 libyuv::I420Rotate( \ | 832 libyuv::I420Rotate( \ |
834 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 833 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
835 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 834 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
836 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 835 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
837 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 836 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
838 kHeight, libyuv::kRotate##ROTATE); \ | 837 kHeight, libyuv::kRotate##ROTATE); \ |
839 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 838 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
840 } | 839 } |
841 | 840 |
842 // Test constructing an image with rotation. | 841 // Test constructing an image with rotation. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 kWidth, kHeight, webrtc::kVideoRotation_270, | 927 kWidth, kHeight, webrtc::kVideoRotation_270, |
929 &frame2)); | 928 &frame2)); |
930 } | 929 } |
931 | 930 |
932 // Test 1 pixel edge case image I420 buffer. | 931 // Test 1 pixel edge case image I420 buffer. |
933 void ConstructI4201Pixel() { | 932 void ConstructI4201Pixel() { |
934 T frame; | 933 T frame; |
935 uint8 pixel[3] = { 1, 2, 3 }; | 934 uint8 pixel[3] = { 1, 2, 3 }; |
936 for (int i = 0; i < repeat_; ++i) { | 935 for (int i = 0; i < repeat_; ++i) { |
937 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, | 936 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, |
938 sizeof(pixel), 1, 1, 0, 0, | 937 sizeof(pixel), 1, 1, 0, webrtc::kVideoRotation_0)); |
939 webrtc::kVideoRotation_0)); | |
940 } | 938 } |
941 const uint8* y = pixel; | 939 const uint8* y = pixel; |
942 const uint8* u = y + 1; | 940 const uint8* u = y + 1; |
943 const uint8* v = u + 1; | 941 const uint8* v = u + 1; |
944 EXPECT_TRUE(IsEqual(frame, 1, 1, 1, 1, 0, 0, | 942 EXPECT_TRUE(IsEqual(frame, 1, 1, 1, 1, 0, |
945 y, 1, u, 1, v, 1, 0)); | 943 y, 1, u, 1, v, 1, 0)); |
946 } | 944 } |
947 | 945 |
948 // Test 5 pixel edge case image. | 946 // Test 5 pixel edge case image. |
949 void ConstructI4205Pixel() { | 947 void ConstructI4205Pixel() { |
950 T frame; | 948 T frame; |
951 uint8 pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; | 949 uint8 pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; |
952 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); | 950 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); |
953 for (int i = 0; i < repeat_; ++i) { | 951 for (int i = 0; i < repeat_; ++i) { |
954 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, | 952 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, |
955 sizeof(pixels5x5), 1, 1, 0, 0, | 953 sizeof(pixels5x5), 1, 1, 0, |
956 webrtc::kVideoRotation_0)); | 954 webrtc::kVideoRotation_0)); |
957 } | 955 } |
958 EXPECT_EQ(5u, frame.GetWidth()); | 956 EXPECT_EQ(5u, frame.GetWidth()); |
959 EXPECT_EQ(5u, frame.GetHeight()); | 957 EXPECT_EQ(5u, frame.GetHeight()); |
960 EXPECT_EQ(5, frame.GetYPitch()); | 958 EXPECT_EQ(5, frame.GetYPitch()); |
961 EXPECT_EQ(3, frame.GetUPitch()); | 959 EXPECT_EQ(3, frame.GetUPitch()); |
962 EXPECT_EQ(3, frame.GetVPitch()); | 960 EXPECT_EQ(3, frame.GetVPitch()); |
963 } | 961 } |
964 | 962 |
965 // Test 1 pixel edge case image ARGB buffer. | 963 // Test 1 pixel edge case image ARGB buffer. |
966 void ConstructARGB1Pixel() { | 964 void ConstructARGB1Pixel() { |
967 T frame; | 965 T frame; |
968 uint8 pixel[4] = { 64, 128, 192, 255 }; | 966 uint8 pixel[4] = { 64, 128, 192, 255 }; |
969 for (int i = 0; i < repeat_; ++i) { | 967 for (int i = 0; i < repeat_; ++i) { |
970 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, | 968 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, |
971 sizeof(pixel), 1, 1, 0, 0, | 969 sizeof(pixel), 1, 1, 0, |
972 webrtc::kVideoRotation_0)); | 970 webrtc::kVideoRotation_0)); |
973 } | 971 } |
974 // Convert back to ARGB. | 972 // Convert back to ARGB. |
975 size_t out_size = 4; | 973 size_t out_size = 4; |
976 rtc::scoped_ptr<uint8[]> outbuf(new uint8[out_size + kAlignment]); | 974 rtc::scoped_ptr<uint8[]> outbuf(new uint8[out_size + kAlignment]); |
977 uint8* out = ALIGNP(outbuf.get(), kAlignment); | 975 uint8* out = ALIGNP(outbuf.get(), kAlignment); |
978 | 976 |
979 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, | 977 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, |
980 out, | 978 out, |
981 out_size, // buffer size | 979 out_size, // buffer size |
(...skipping 16 matching lines...) Expand all Loading... |
998 64, 64, 64, 255, | 996 64, 64, 64, 255, |
999 128, 128, 128, 255, // Grey. | 997 128, 128, 128, 255, // Grey. |
1000 128, 128, 128, 255, | 998 128, 128, 128, 255, |
1001 196, 196, 196, 255, // Light Grey. | 999 196, 196, 196, 255, // Light Grey. |
1002 196, 196, 196, 255, | 1000 196, 196, 196, 255, |
1003 255, 255, 255, 255, // White. | 1001 255, 255, 255, 255, // White. |
1004 255, 255, 255, 255 }; | 1002 255, 255, 255, 255 }; |
1005 | 1003 |
1006 for (int i = 0; i < repeat_; ++i) { | 1004 for (int i = 0; i < repeat_; ++i) { |
1007 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 10, 1, 10, 1, pixel, | 1005 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 10, 1, 10, 1, pixel, |
1008 sizeof(pixel), 1, 1, 0, 0, | 1006 sizeof(pixel), 1, 1, 0, |
1009 webrtc::kVideoRotation_0)); | 1007 webrtc::kVideoRotation_0)); |
1010 } | 1008 } |
1011 // Convert back to ARGB | 1009 // Convert back to ARGB |
1012 size_t out_size = 10 * 4; | 1010 size_t out_size = 10 * 4; |
1013 rtc::scoped_ptr<uint8[]> outbuf(new uint8[out_size + kAlignment]); | 1011 rtc::scoped_ptr<uint8[]> outbuf(new uint8[out_size + kAlignment]); |
1014 uint8* out = ALIGNP(outbuf.get(), kAlignment); | 1012 uint8* out = ALIGNP(outbuf.get(), kAlignment); |
1015 | 1013 |
1016 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, | 1014 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, |
1017 out, | 1015 out, |
1018 out_size, // buffer size. | 1016 out_size, // buffer size. |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1305 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
1308 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane()); | 1306 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane()); |
1309 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane()); | 1307 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane()); |
1310 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane()); | 1308 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane()); |
1311 } | 1309 } |
1312 | 1310 |
1313 // Test creating an empty image and initing it to black. | 1311 // Test creating an empty image and initing it to black. |
1314 void ConstructBlack() { | 1312 void ConstructBlack() { |
1315 T frame; | 1313 T frame; |
1316 for (int i = 0; i < repeat_; ++i) { | 1314 for (int i = 0; i < repeat_; ++i) { |
1317 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 1, 1, 0, 0)); | 1315 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
1318 } | 1316 } |
1319 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); | 1317 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); |
1320 EXPECT_TRUE(IsBlack(frame)); | 1318 EXPECT_TRUE(IsBlack(frame)); |
1321 } | 1319 } |
1322 | 1320 |
1323 // Test constructing an image from a YUY2 buffer with a range of sizes. | 1321 // Test constructing an image from a YUY2 buffer with a range of sizes. |
1324 // Only tests that conversion does not crash or corrupt heap. | 1322 // Only tests that conversion does not crash or corrupt heap. |
1325 void ConstructYuy2AllSizes() { | 1323 void ConstructYuy2AllSizes() { |
1326 T frame1, frame2; | 1324 T frame1, frame2; |
1327 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { | 1325 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 } | 1371 } |
1374 | 1372 |
1375 // Tests re-initing an existing image. | 1373 // Tests re-initing an existing image. |
1376 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { | 1374 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { |
1377 T frame1, frame2; | 1375 T frame1, frame2; |
1378 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1376 rtc::scoped_ptr<rtc::MemoryStream> ms( |
1379 LoadSample(kImageFilename)); | 1377 LoadSample(kImageFilename)); |
1380 ASSERT_TRUE(ms.get() != NULL); | 1378 ASSERT_TRUE(ms.get() != NULL); |
1381 size_t data_size; | 1379 size_t data_size; |
1382 ms->GetSize(&data_size); | 1380 ms->GetSize(&data_size); |
1383 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 1, 1, 0, 0)); | 1381 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
1384 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0, 0)); | 1382 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
1385 EXPECT_TRUE(IsBlack(frame1)); | 1383 EXPECT_TRUE(IsBlack(frame1)); |
1386 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1384 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
1387 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, | 1385 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, |
1388 kHeight, reinterpret_cast<uint8*>(ms->GetBuffer()), | 1386 kHeight, reinterpret_cast<uint8*>(ms->GetBuffer()), |
1389 data_size, 1, 1, 0, 0, rotation, | 1387 data_size, 1, 1, 0, rotation, |
1390 apply_rotation)); | 1388 apply_rotation)); |
1391 if (apply_rotation) | 1389 if (apply_rotation) |
1392 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); | 1390 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); |
1393 else | 1391 else |
1394 EXPECT_EQ(rotation, frame1.GetVideoRotation()); | 1392 EXPECT_EQ(rotation, frame1.GetVideoRotation()); |
1395 | 1393 |
1396 // Swapp width and height if the frame is rotated 90 or 270 degrees. | 1394 // Swapp width and height if the frame is rotated 90 or 270 degrees. |
1397 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 | 1395 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 |
1398 || rotation == webrtc::kVideoRotation_270)) { | 1396 || rotation == webrtc::kVideoRotation_270)) { |
1399 EXPECT_TRUE(kHeight == frame1.GetWidth()); | 1397 EXPECT_TRUE(kHeight == frame1.GetWidth()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 out += (kHeight - 1) * stride; // Point to last row. | 1441 out += (kHeight - 1) * stride; // Point to last row. |
1444 stride = -stride; | 1442 stride = -stride; |
1445 } | 1443 } |
1446 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 1444 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
1447 | 1445 |
1448 for (int i = 0; i < repeat_to; ++i) { | 1446 for (int i = 0; i < repeat_to; ++i) { |
1449 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, | 1447 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, |
1450 out, | 1448 out, |
1451 out_size, stride)); | 1449 out_size, stride)); |
1452 } | 1450 } |
1453 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0, 0)); | 1451 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
1454 for (int i = 0; i < repeat_from; ++i) { | 1452 for (int i = 0; i < repeat_from; ++i) { |
1455 EXPECT_EQ(0, RGBToI420(out, stride, | 1453 EXPECT_EQ(0, RGBToI420(out, stride, |
1456 frame2.GetYPlane(), frame2.GetYPitch(), | 1454 frame2.GetYPlane(), frame2.GetYPitch(), |
1457 frame2.GetUPlane(), frame2.GetUPitch(), | 1455 frame2.GetUPlane(), frame2.GetUPitch(), |
1458 frame2.GetVPlane(), frame2.GetVPitch(), | 1456 frame2.GetVPlane(), frame2.GetVPitch(), |
1459 kWidth, kHeight)); | 1457 kWidth, kHeight)); |
1460 } | 1458 } |
1461 if (rowpad) { | 1459 if (rowpad) { |
1462 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row. | 1460 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row. |
1463 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row. | 1461 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 for (int i = 0; i < repeat_; ++i) { | 1758 for (int i = 0; i < repeat_; ++i) { |
1761 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), | 1759 EXPECT_EQ(0, libyuv::I420ToI422(frame1.GetYPlane(), frame1.GetYPitch(), |
1762 frame1.GetUPlane(), frame1.GetUPitch(), | 1760 frame1.GetUPlane(), frame1.GetUPitch(), |
1763 frame1.GetVPlane(), frame1.GetVPitch(), | 1761 frame1.GetVPlane(), frame1.GetVPitch(), |
1764 y, kWidth, | 1762 y, kWidth, |
1765 u, kWidth / 2, | 1763 u, kWidth / 2, |
1766 v, kWidth / 2, | 1764 v, kWidth / 2, |
1767 kWidth, kHeight)); | 1765 kWidth, kHeight)); |
1768 } | 1766 } |
1769 EXPECT_TRUE(frame2.Init(cricket::FOURCC_I422, kWidth, kHeight, kWidth, | 1767 EXPECT_TRUE(frame2.Init(cricket::FOURCC_I422, kWidth, kHeight, kWidth, |
1770 kHeight, y, out_size, 1, 1, 0, 0, | 1768 kHeight, y, out_size, 1, 1, 0, |
1771 webrtc::kVideoRotation_0)); | 1769 webrtc::kVideoRotation_0)); |
1772 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); | 1770 EXPECT_TRUE(IsEqual(frame1, frame2, 1)); |
1773 } | 1771 } |
1774 | 1772 |
1775 /////////////////// | 1773 /////////////////// |
1776 // General tests // | 1774 // General tests // |
1777 /////////////////// | 1775 /////////////////// |
1778 | 1776 |
1779 void Copy() { | 1777 void Copy() { |
1780 rtc::scoped_ptr<T> source(new T); | 1778 rtc::scoped_ptr<T> source(new T); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size)); | 1862 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size)); |
1865 } | 1863 } |
1866 | 1864 |
1867 void CopyToBuffer1Pixel() { | 1865 void CopyToBuffer1Pixel() { |
1868 size_t out_size = 3; | 1866 size_t out_size = 3; |
1869 rtc::scoped_ptr<uint8[]> out(new uint8[out_size + 1]); | 1867 rtc::scoped_ptr<uint8[]> out(new uint8[out_size + 1]); |
1870 memset(out.get(), 0xfb, out_size + 1); // Fill buffer | 1868 memset(out.get(), 0xfb, out_size + 1); // Fill buffer |
1871 uint8 pixel[3] = { 1, 2, 3 }; | 1869 uint8 pixel[3] = { 1, 2, 3 }; |
1872 T frame; | 1870 T frame; |
1873 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, | 1871 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, |
1874 sizeof(pixel), 1, 1, 0, 0, | 1872 sizeof(pixel), 1, 1, 0, |
1875 webrtc::kVideoRotation_0)); | 1873 webrtc::kVideoRotation_0)); |
1876 for (int i = 0; i < repeat_; ++i) { | 1874 for (int i = 0; i < repeat_; ++i) { |
1877 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size)); | 1875 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size)); |
1878 } | 1876 } |
1879 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1. | 1877 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1. |
1880 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2. | 1878 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2. |
1881 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3. | 1879 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3. |
1882 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact. | 1880 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact. |
1883 } | 1881 } |
1884 | 1882 |
1885 void StretchToFrame() { | 1883 void StretchToFrame() { |
1886 // Create the source frame as a black frame. | 1884 // Create the source frame as a black frame. |
1887 T source; | 1885 T source; |
1888 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 1, 1, 0, 0)); | 1886 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 1, 1, 0)); |
1889 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); | 1887 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); |
1890 | 1888 |
1891 // Create the target frame by loading from a file. | 1889 // Create the target frame by loading from a file. |
1892 T target1; | 1890 T target1; |
1893 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); | 1891 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); |
1894 EXPECT_FALSE(IsBlack(target1)); | 1892 EXPECT_FALSE(IsBlack(target1)); |
1895 | 1893 |
1896 // Stretch and check if the stretched target is black. | 1894 // Stretch and check if the stretched target is black. |
1897 source.StretchToFrame(&target1, true, false); | 1895 source.StretchToFrame(&target1, true, false); |
1898 EXPECT_TRUE(IsBlack(target1)); | 1896 EXPECT_TRUE(IsBlack(target1)); |
1899 | 1897 |
1900 // Crop and stretch and check if the stretched target is black. | 1898 // Crop and stretch and check if the stretched target is black. |
1901 T target2; | 1899 T target2; |
1902 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 1900 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); |
1903 source.StretchToFrame(&target2, true, true); | 1901 source.StretchToFrame(&target2, true, true); |
1904 EXPECT_TRUE(IsBlack(target2)); | 1902 EXPECT_TRUE(IsBlack(target2)); |
1905 EXPECT_EQ(source.GetElapsedTime(), target2.GetElapsedTime()); | |
1906 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 1903 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); |
1907 } | 1904 } |
1908 | 1905 |
1909 int repeat_; | 1906 int repeat_; |
1910 }; | 1907 }; |
1911 | 1908 |
1912 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 1909 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
OLD | NEW |