| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, 0, rotation); | 155 sample, sample_size, 1, 1, 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 Loading... |
| 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, 0); | 298 frame->InitToBlack(width, height, 1, 1, 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 Loading... |
| 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, 0); | 342 frame->InitToBlack(width, height, 1, 1, 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 Loading... |
| 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, |
| 468 int64_t time_stamp, | 470 int64_t time_stamp, |
| 469 const uint8_t* y, | 471 const uint8_t* y, |
| 470 uint32_t ypitch, | 472 uint32_t ypitch, |
| 471 const uint8_t* u, | 473 const uint8_t* u, |
| 472 uint32_t upitch, | 474 uint32_t upitch, |
| 473 const uint8_t* v, | 475 const uint8_t* v, |
| 474 uint32_t vpitch, | 476 uint32_t vpitch, |
| 475 int max_error) { | 477 int max_error) { |
| 476 return IsSize(frame, static_cast<uint32_t>(width), | 478 return IsSize(frame, static_cast<uint32_t>(width), |
| 477 static_cast<uint32_t>(height)) && | 479 static_cast<uint32_t>(height)) && |
| 480 frame.GetPixelWidth() == pixel_width && |
| 481 frame.GetPixelHeight() == pixel_height && |
| 478 frame.GetTimeStamp() == time_stamp && | 482 frame.GetTimeStamp() == time_stamp && |
| 479 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch, | 483 IsPlaneEqual("y", frame.GetYPlane(), frame.GetYPitch(), y, ypitch, |
| 480 static_cast<uint32_t>(width), | 484 static_cast<uint32_t>(width), |
| 481 static_cast<uint32_t>(height), max_error) && | 485 static_cast<uint32_t>(height), max_error) && |
| 482 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch, | 486 IsPlaneEqual("u", frame.GetUPlane(), frame.GetUPitch(), u, upitch, |
| 483 static_cast<uint32_t>((width + 1) / 2), | 487 static_cast<uint32_t>((width + 1) / 2), |
| 484 static_cast<uint32_t>((height + 1) / 2), max_error) && | 488 static_cast<uint32_t>((height + 1) / 2), max_error) && |
| 485 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch, | 489 IsPlaneEqual("v", frame.GetVPlane(), frame.GetVPitch(), v, vpitch, |
| 486 static_cast<uint32_t>((width + 1) / 2), | 490 static_cast<uint32_t>((width + 1) / 2), |
| 487 static_cast<uint32_t>((height + 1) / 2), max_error); | 491 static_cast<uint32_t>((height + 1) / 2), max_error); |
| 488 } | 492 } |
| 489 | 493 |
| 490 static bool IsEqual(const cricket::VideoFrame& frame1, | 494 static bool IsEqual(const cricket::VideoFrame& frame1, |
| 491 const cricket::VideoFrame& frame2, | 495 const cricket::VideoFrame& frame2, |
| 492 int max_error) { | 496 int max_error) { |
| 493 return IsEqual(frame1, | 497 return IsEqual(frame1, |
| 494 frame2.GetWidth(), frame2.GetHeight(), | 498 frame2.GetWidth(), frame2.GetHeight(), |
| 499 frame2.GetPixelWidth(), frame2.GetPixelHeight(), |
| 495 frame2.GetTimeStamp(), | 500 frame2.GetTimeStamp(), |
| 496 frame2.GetYPlane(), frame2.GetYPitch(), | 501 frame2.GetYPlane(), frame2.GetYPitch(), |
| 497 frame2.GetUPlane(), frame2.GetUPitch(), | 502 frame2.GetUPlane(), frame2.GetUPitch(), |
| 498 frame2.GetVPlane(), frame2.GetVPitch(), | 503 frame2.GetVPlane(), frame2.GetVPitch(), |
| 499 max_error); | 504 max_error); |
| 500 } | 505 } |
| 501 | 506 |
| 502 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, | 507 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, |
| 503 const cricket::VideoFrame& frame2, | 508 const cricket::VideoFrame& frame2, |
| 504 int hcrop, int vcrop, int max_error) { | 509 int hcrop, int vcrop, int max_error) { |
| 505 return frame1.GetWidth() <= frame2.GetWidth() && | 510 return frame1.GetWidth() <= frame2.GetWidth() && |
| 506 frame1.GetHeight() <= frame2.GetHeight() && | 511 frame1.GetHeight() <= frame2.GetHeight() && |
| 507 IsEqual(frame1, | 512 IsEqual(frame1, |
| 508 frame2.GetWidth() - hcrop * 2, | 513 frame2.GetWidth() - hcrop * 2, |
| 509 frame2.GetHeight() - vcrop * 2, | 514 frame2.GetHeight() - vcrop * 2, |
| 515 frame2.GetPixelWidth(), frame2.GetPixelHeight(), |
| 510 frame2.GetTimeStamp(), | 516 frame2.GetTimeStamp(), |
| 511 frame2.GetYPlane() + vcrop * frame2.GetYPitch() | 517 frame2.GetYPlane() + vcrop * frame2.GetYPitch() |
| 512 + hcrop, | 518 + hcrop, |
| 513 frame2.GetYPitch(), | 519 frame2.GetYPitch(), |
| 514 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 | 520 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 |
| 515 + hcrop / 2, | 521 + hcrop / 2, |
| 516 frame2.GetUPitch(), | 522 frame2.GetUPitch(), |
| 517 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 | 523 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 |
| 518 + hcrop / 2, | 524 + hcrop / 2, |
| 519 frame2.GetVPitch(), | 525 frame2.GetVPitch(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 536 T frame; | 542 T frame; |
| 537 EXPECT_TRUE(IsNull(frame)); | 543 EXPECT_TRUE(IsNull(frame)); |
| 538 rtc::scoped_ptr<rtc::MemoryStream> ms( | 544 rtc::scoped_ptr<rtc::MemoryStream> ms( |
| 539 CreateYuvSample(kWidth, kHeight, 12)); | 545 CreateYuvSample(kWidth, kHeight, 12)); |
| 540 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, | 546 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, |
| 541 kWidth, kHeight, &frame)); | 547 kWidth, kHeight, &frame)); |
| 542 | 548 |
| 543 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); | 549 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); |
| 544 const uint8_t* u = y + kWidth * kHeight; | 550 const uint8_t* u = y + kWidth * kHeight; |
| 545 const uint8_t* v = u + kWidth * kHeight / 4; | 551 const uint8_t* v = u + kWidth * kHeight / 4; |
| 546 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, | 552 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, y, kWidth, u, |
| 547 kWidth / 2, v, kWidth / 2, 0)); | 553 kWidth / 2, v, kWidth / 2, 0)); |
| 548 } | 554 } |
| 549 | 555 |
| 550 // Test constructing an image from a YV12 buffer. | 556 // Test constructing an image from a YV12 buffer. |
| 551 void ConstructYV12() { | 557 void ConstructYV12() { |
| 552 T frame; | 558 T frame; |
| 553 rtc::scoped_ptr<rtc::MemoryStream> ms( | 559 rtc::scoped_ptr<rtc::MemoryStream> ms( |
| 554 CreateYuvSample(kWidth, kHeight, 12)); | 560 CreateYuvSample(kWidth, kHeight, 12)); |
| 555 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, | 561 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, |
| 556 kWidth, kHeight, &frame)); | 562 kWidth, kHeight, &frame)); |
| 557 | 563 |
| 558 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); | 564 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); |
| 559 const uint8_t* v = y + kWidth * kHeight; | 565 const uint8_t* v = y + kWidth * kHeight; |
| 560 const uint8_t* u = v + kWidth * kHeight / 4; | 566 const uint8_t* u = v + kWidth * kHeight / 4; |
| 561 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, | 567 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 1, 1, 0, y, kWidth, u, |
| 562 kWidth / 2, v, kWidth / 2, 0)); | 568 kWidth / 2, v, kWidth / 2, 0)); |
| 563 } | 569 } |
| 564 | 570 |
| 565 // Test constructing an image from a I422 buffer. | 571 // Test constructing an image from a I422 buffer. |
| 566 void ConstructI422() { | 572 void ConstructI422() { |
| 567 T frame1, frame2; | 573 T frame1, frame2; |
| 568 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 574 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
| 569 size_t buf_size = kWidth * kHeight * 2; | 575 size_t buf_size = kWidth * kHeight * 2; |
| 570 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); | 576 rtc::scoped_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); |
| 571 uint8_t* y = ALIGNP(buf.get(), kAlignment); | 577 uint8_t* y = ALIGNP(buf.get(), kAlignment); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 ASSERT_TRUE(ms.get() != NULL); \ | 821 ASSERT_TRUE(ms.get() != NULL); \ |
| 816 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ | 822 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ |
| 817 -kHeight, kWidth, kHeight, \ | 823 -kHeight, kWidth, kHeight, \ |
| 818 webrtc::kVideoRotation_180, &frame1)); \ | 824 webrtc::kVideoRotation_180, &frame1)); \ |
| 819 size_t data_size; \ | 825 size_t data_size; \ |
| 820 bool ret = ms->GetSize(&data_size); \ | 826 bool ret = ms->GetSize(&data_size); \ |
| 821 EXPECT_TRUE(ret); \ | 827 EXPECT_TRUE(ret); \ |
| 822 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 828 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
| 823 kHeight, \ | 829 kHeight, \ |
| 824 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ | 830 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ |
| 825 data_size, 0, webrtc::kVideoRotation_0)); \ | 831 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ |
| 826 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 832 int width_rotate = static_cast<int>(frame1.GetWidth()); \ |
| 827 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 833 int height_rotate = static_cast<int>(frame1.GetHeight()); \ |
| 828 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ | 834 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ |
| 829 libyuv::I420Mirror( \ | 835 libyuv::I420Mirror( \ |
| 830 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 836 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
| 831 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 837 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
| 832 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 838 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
| 833 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 839 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
| 834 kHeight); \ | 840 kHeight); \ |
| 835 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 841 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
| 836 } | 842 } |
| 837 | 843 |
| 838 TEST_MIRROR(I420, 420) | 844 TEST_MIRROR(I420, 420) |
| 839 | 845 |
| 840 // Macro to help test different rotations | 846 // Macro to help test different rotations |
| 841 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ | 847 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ |
| 842 void Construct##FOURCC##Rotate##ROTATE() { \ | 848 void Construct##FOURCC##Rotate##ROTATE() { \ |
| 843 T frame1, frame2, frame3; \ | 849 T frame1, frame2, frame3; \ |
| 844 rtc::scoped_ptr<rtc::MemoryStream> ms( \ | 850 rtc::scoped_ptr<rtc::MemoryStream> ms( \ |
| 845 CreateYuvSample(kWidth, kHeight, BPP)); \ | 851 CreateYuvSample(kWidth, kHeight, BPP)); \ |
| 846 ASSERT_TRUE(ms.get() != NULL); \ | 852 ASSERT_TRUE(ms.get() != NULL); \ |
| 847 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ | 853 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ |
| 848 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ | 854 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ |
| 849 &frame1)); \ | 855 &frame1)); \ |
| 850 size_t data_size; \ | 856 size_t data_size; \ |
| 851 bool ret = ms->GetSize(&data_size); \ | 857 bool ret = ms->GetSize(&data_size); \ |
| 852 EXPECT_TRUE(ret); \ | 858 EXPECT_TRUE(ret); \ |
| 853 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 859 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
| 854 kHeight, \ | 860 kHeight, \ |
| 855 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ | 861 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ |
| 856 data_size, 0, webrtc::kVideoRotation_0)); \ | 862 data_size, 1, 1, 0, webrtc::kVideoRotation_0)); \ |
| 857 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 863 int width_rotate = static_cast<int>(frame1.GetWidth()); \ |
| 858 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 864 int height_rotate = static_cast<int>(frame1.GetHeight()); \ |
| 859 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ | 865 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 1, 1, 0)); \ |
| 860 libyuv::I420Rotate( \ | 866 libyuv::I420Rotate( \ |
| 861 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 867 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
| 862 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 868 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
| 863 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 869 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
| 864 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 870 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
| 865 kHeight, libyuv::kRotate##ROTATE); \ | 871 kHeight, libyuv::kRotate##ROTATE); \ |
| 866 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 872 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
| 867 } | 873 } |
| 868 | 874 |
| 869 // Test constructing an image with rotation. | 875 // Test constructing an image with rotation. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 kWidth, kHeight, webrtc::kVideoRotation_270, | 961 kWidth, kHeight, webrtc::kVideoRotation_270, |
| 956 &frame2)); | 962 &frame2)); |
| 957 } | 963 } |
| 958 | 964 |
| 959 // Test 1 pixel edge case image I420 buffer. | 965 // Test 1 pixel edge case image I420 buffer. |
| 960 void ConstructI4201Pixel() { | 966 void ConstructI4201Pixel() { |
| 961 T frame; | 967 T frame; |
| 962 uint8_t pixel[3] = {1, 2, 3}; | 968 uint8_t pixel[3] = {1, 2, 3}; |
| 963 for (int i = 0; i < repeat_; ++i) { | 969 for (int i = 0; i < repeat_; ++i) { |
| 964 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, | 970 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, |
| 965 sizeof(pixel), 0, webrtc::kVideoRotation_0)); | 971 sizeof(pixel), 1, 1, 0, webrtc::kVideoRotation_0)); |
| 966 } | 972 } |
| 967 const uint8_t* y = pixel; | 973 const uint8_t* y = pixel; |
| 968 const uint8_t* u = y + 1; | 974 const uint8_t* u = y + 1; |
| 969 const uint8_t* v = u + 1; | 975 const uint8_t* v = u + 1; |
| 970 EXPECT_TRUE(IsEqual(frame, 1, 1, 0, y, 1, u, 1, v, 1, 0)); | 976 EXPECT_TRUE(IsEqual(frame, 1, 1, 1, 1, 0, y, 1, u, 1, v, 1, 0)); |
| 971 } | 977 } |
| 972 | 978 |
| 973 // Test 5 pixel edge case image. | 979 // Test 5 pixel edge case image. |
| 974 void ConstructI4205Pixel() { | 980 void ConstructI4205Pixel() { |
| 975 T frame; | 981 T frame; |
| 976 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; | 982 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; |
| 977 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); | 983 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); |
| 978 for (int i = 0; i < repeat_; ++i) { | 984 for (int i = 0; i < repeat_; ++i) { |
| 979 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, | 985 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, |
| 980 sizeof(pixels5x5), 0, | 986 sizeof(pixels5x5), 1, 1, 0, |
| 981 webrtc::kVideoRotation_0)); | 987 webrtc::kVideoRotation_0)); |
| 982 } | 988 } |
| 983 EXPECT_EQ(5u, frame.GetWidth()); | 989 EXPECT_EQ(5u, frame.GetWidth()); |
| 984 EXPECT_EQ(5u, frame.GetHeight()); | 990 EXPECT_EQ(5u, frame.GetHeight()); |
| 985 EXPECT_EQ(5, frame.GetYPitch()); | 991 EXPECT_EQ(5, frame.GetYPitch()); |
| 986 EXPECT_EQ(3, frame.GetUPitch()); | 992 EXPECT_EQ(3, frame.GetUPitch()); |
| 987 EXPECT_EQ(3, frame.GetVPitch()); | 993 EXPECT_EQ(3, frame.GetVPitch()); |
| 988 } | 994 } |
| 989 | 995 |
| 990 // Test 1 pixel edge case image ARGB buffer. | 996 // Test 1 pixel edge case image ARGB buffer. |
| 991 void ConstructARGB1Pixel() { | 997 void ConstructARGB1Pixel() { |
| 992 T frame; | 998 T frame; |
| 993 uint8_t pixel[4] = {64, 128, 192, 255}; | 999 uint8_t pixel[4] = {64, 128, 192, 255}; |
| 994 for (int i = 0; i < repeat_; ++i) { | 1000 for (int i = 0; i < repeat_; ++i) { |
| 995 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, | 1001 EXPECT_TRUE(frame.Init(cricket::FOURCC_ARGB, 1, 1, 1, 1, pixel, |
| 996 sizeof(pixel), 0, | 1002 sizeof(pixel), 1, 1, 0, |
| 997 webrtc::kVideoRotation_0)); | 1003 webrtc::kVideoRotation_0)); |
| 998 } | 1004 } |
| 999 // Convert back to ARGB. | 1005 // Convert back to ARGB. |
| 1000 size_t out_size = 4; | 1006 size_t out_size = 4; |
| 1001 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); | 1007 rtc::scoped_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment]); |
| 1002 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); | 1008 uint8_t* out = ALIGNP(outbuf.get(), kAlignment); |
| 1003 | 1009 |
| 1004 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, | 1010 EXPECT_EQ(out_size, frame.ConvertToRgbBuffer(cricket::FOURCC_ARGB, |
| 1005 out, | 1011 out, |
| 1006 out_size, // buffer size | 1012 out_size, // buffer size |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1342 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
| 1337 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane()); | 1343 EXPECT_EQ(frame1.GetYPlane(), frame2.GetYPlane()); |
| 1338 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane()); | 1344 EXPECT_EQ(frame1.GetUPlane(), frame2.GetUPlane()); |
| 1339 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane()); | 1345 EXPECT_EQ(frame1.GetVPlane(), frame2.GetVPlane()); |
| 1340 } | 1346 } |
| 1341 | 1347 |
| 1342 // Test creating an empty image and initing it to black. | 1348 // Test creating an empty image and initing it to black. |
| 1343 void ConstructBlack() { | 1349 void ConstructBlack() { |
| 1344 T frame; | 1350 T frame; |
| 1345 for (int i = 0; i < repeat_; ++i) { | 1351 for (int i = 0; i < repeat_; ++i) { |
| 1346 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 0)); | 1352 EXPECT_TRUE(frame.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
| 1347 } | 1353 } |
| 1348 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); | 1354 EXPECT_TRUE(IsSize(frame, kWidth, kHeight)); |
| 1349 EXPECT_TRUE(IsBlack(frame)); | 1355 EXPECT_TRUE(IsBlack(frame)); |
| 1350 } | 1356 } |
| 1351 | 1357 |
| 1352 // Test constructing an image from a YUY2 buffer with a range of sizes. | 1358 // Test constructing an image from a YUY2 buffer with a range of sizes. |
| 1353 // Only tests that conversion does not crash or corrupt heap. | 1359 // Only tests that conversion does not crash or corrupt heap. |
| 1354 void ConstructYuy2AllSizes() { | 1360 void ConstructYuy2AllSizes() { |
| 1355 T frame1, frame2; | 1361 T frame1, frame2; |
| 1356 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { | 1362 for (int height = kMinHeightAll; height <= kMaxHeightAll; ++height) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 } | 1408 } |
| 1403 | 1409 |
| 1404 // Tests re-initing an existing image. | 1410 // Tests re-initing an existing image. |
| 1405 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { | 1411 void Reset(webrtc::VideoRotation rotation, bool apply_rotation) { |
| 1406 T frame1, frame2; | 1412 T frame1, frame2; |
| 1407 rtc::scoped_ptr<rtc::MemoryStream> ms( | 1413 rtc::scoped_ptr<rtc::MemoryStream> ms( |
| 1408 LoadSample(kImageFilename)); | 1414 LoadSample(kImageFilename)); |
| 1409 ASSERT_TRUE(ms.get() != NULL); | 1415 ASSERT_TRUE(ms.get() != NULL); |
| 1410 size_t data_size; | 1416 size_t data_size; |
| 1411 ms->GetSize(&data_size); | 1417 ms->GetSize(&data_size); |
| 1412 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 0)); | 1418 EXPECT_TRUE(frame1.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
| 1413 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0)); | 1419 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
| 1414 EXPECT_TRUE(IsBlack(frame1)); | 1420 EXPECT_TRUE(IsBlack(frame1)); |
| 1415 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); | 1421 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); |
| 1416 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, | 1422 EXPECT_TRUE(frame1.Reset(cricket::FOURCC_I420, kWidth, kHeight, kWidth, |
| 1417 kHeight, | 1423 kHeight, |
| 1418 reinterpret_cast<uint8_t*>(ms->GetBuffer()), | 1424 reinterpret_cast<uint8_t*>(ms->GetBuffer()), |
| 1419 data_size, 0, rotation, apply_rotation)); | 1425 data_size, 1, 1, 0, rotation, apply_rotation)); |
| 1420 if (apply_rotation) | 1426 if (apply_rotation) |
| 1421 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); | 1427 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); |
| 1422 else | 1428 else |
| 1423 EXPECT_EQ(rotation, frame1.GetVideoRotation()); | 1429 EXPECT_EQ(rotation, frame1.GetVideoRotation()); |
| 1424 | 1430 |
| 1425 // Swapp width and height if the frame is rotated 90 or 270 degrees. | 1431 // Swapp width and height if the frame is rotated 90 or 270 degrees. |
| 1426 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 | 1432 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 |
| 1427 || rotation == webrtc::kVideoRotation_270)) { | 1433 || rotation == webrtc::kVideoRotation_270)) { |
| 1428 EXPECT_TRUE(kHeight == frame1.GetWidth()); | 1434 EXPECT_TRUE(kHeight == frame1.GetWidth()); |
| 1429 EXPECT_TRUE(kWidth == frame1.GetHeight()); | 1435 EXPECT_TRUE(kWidth == frame1.GetHeight()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 out += (kHeight - 1) * stride; // Point to last row. | 1487 out += (kHeight - 1) * stride; // Point to last row. |
| 1482 stride = -stride; | 1488 stride = -stride; |
| 1483 } | 1489 } |
| 1484 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); | 1490 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); |
| 1485 | 1491 |
| 1486 for (int i = 0; i < repeat_to; ++i) { | 1492 for (int i = 0; i < repeat_to; ++i) { |
| 1487 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, | 1493 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, |
| 1488 out, | 1494 out, |
| 1489 out_size, stride)); | 1495 out_size, stride)); |
| 1490 } | 1496 } |
| 1491 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 0)); | 1497 EXPECT_TRUE(frame2.InitToBlack(kWidth, kHeight, 1, 1, 0)); |
| 1492 for (int i = 0; i < repeat_from; ++i) { | 1498 for (int i = 0; i < repeat_from; ++i) { |
| 1493 EXPECT_EQ(0, RGBToI420(out, stride, | 1499 EXPECT_EQ(0, RGBToI420(out, stride, |
| 1494 frame2.GetYPlane(), frame2.GetYPitch(), | 1500 frame2.GetYPlane(), frame2.GetYPitch(), |
| 1495 frame2.GetUPlane(), frame2.GetUPitch(), | 1501 frame2.GetUPlane(), frame2.GetUPitch(), |
| 1496 frame2.GetVPlane(), frame2.GetVPitch(), | 1502 frame2.GetVPlane(), frame2.GetVPitch(), |
| 1497 kWidth, kHeight)); | 1503 kWidth, kHeight)); |
| 1498 } | 1504 } |
| 1499 if (rowpad) { | 1505 if (rowpad) { |
| 1500 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row. | 1506 EXPECT_EQ(0, outtop[kWidth * bpp]); // Ensure stride skipped end of row. |
| 1501 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row. | 1507 EXPECT_NE(0, outtop[astride]); // Ensure pixel at start of 2nd row. |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size)); | 1908 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size)); |
| 1903 } | 1909 } |
| 1904 | 1910 |
| 1905 void CopyToBuffer1Pixel() { | 1911 void CopyToBuffer1Pixel() { |
| 1906 size_t out_size = 3; | 1912 size_t out_size = 3; |
| 1907 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]); | 1913 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]); |
| 1908 memset(out.get(), 0xfb, out_size + 1); // Fill buffer | 1914 memset(out.get(), 0xfb, out_size + 1); // Fill buffer |
| 1909 uint8_t pixel[3] = {1, 2, 3}; | 1915 uint8_t pixel[3] = {1, 2, 3}; |
| 1910 T frame; | 1916 T frame; |
| 1911 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, | 1917 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, |
| 1912 sizeof(pixel), 0, | 1918 sizeof(pixel), 1, 1, 0, |
| 1913 webrtc::kVideoRotation_0)); | 1919 webrtc::kVideoRotation_0)); |
| 1914 for (int i = 0; i < repeat_; ++i) { | 1920 for (int i = 0; i < repeat_; ++i) { |
| 1915 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size)); | 1921 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size)); |
| 1916 } | 1922 } |
| 1917 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1. | 1923 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1. |
| 1918 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2. | 1924 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2. |
| 1919 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3. | 1925 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3. |
| 1920 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact. | 1926 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact. |
| 1921 } | 1927 } |
| 1922 | 1928 |
| 1923 void StretchToFrame() { | 1929 void StretchToFrame() { |
| 1924 // Create the source frame as a black frame. | 1930 // Create the source frame as a black frame. |
| 1925 T source; | 1931 T source; |
| 1926 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0)); | 1932 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 1, 1, 0)); |
| 1927 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); | 1933 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); |
| 1928 | 1934 |
| 1929 // Create the target frame by loading from a file. | 1935 // Create the target frame by loading from a file. |
| 1930 T target1; | 1936 T target1; |
| 1931 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); | 1937 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); |
| 1932 EXPECT_FALSE(IsBlack(target1)); | 1938 EXPECT_FALSE(IsBlack(target1)); |
| 1933 | 1939 |
| 1934 // Stretch and check if the stretched target is black. | 1940 // Stretch and check if the stretched target is black. |
| 1935 source.StretchToFrame(&target1, true, false); | 1941 source.StretchToFrame(&target1, true, false); |
| 1936 EXPECT_TRUE(IsBlack(target1)); | 1942 EXPECT_TRUE(IsBlack(target1)); |
| 1937 | 1943 |
| 1938 // Crop and stretch and check if the stretched target is black. | 1944 // Crop and stretch and check if the stretched target is black. |
| 1939 T target2; | 1945 T target2; |
| 1940 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 1946 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); |
| 1941 source.StretchToFrame(&target2, true, true); | 1947 source.StretchToFrame(&target2, true, true); |
| 1942 EXPECT_TRUE(IsBlack(target2)); | 1948 EXPECT_TRUE(IsBlack(target2)); |
| 1943 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 1949 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); |
| 1944 } | 1950 } |
| 1945 | 1951 |
| 1946 int repeat_; | 1952 int repeat_; |
| 1947 }; | 1953 }; |
| 1948 | 1954 |
| 1949 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 1955 #endif // TALK_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
| OLD | NEW |