| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 } | 392 } |
| 393 return true; | 393 return true; |
| 394 } | 394 } |
| 395 | 395 |
| 396 // Comparison functions for testing. | 396 // Comparison functions for testing. |
| 397 static bool IsNull(const cricket::VideoFrame& frame) { | 397 static bool IsNull(const cricket::VideoFrame& frame) { |
| 398 return !frame.GetYPlane(); | 398 return !frame.GetYPlane(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 static bool IsSize(const cricket::VideoFrame& frame, | 401 static bool IsSize(const cricket::VideoFrame& frame, |
| 402 uint32_t width, | 402 int width, |
| 403 uint32_t height) { | 403 int height) { |
| 404 return !IsNull(frame) && frame.GetYPitch() >= static_cast<int32_t>(width) && | 404 return !IsNull(frame) && frame.GetYPitch() >= width && |
| 405 frame.GetUPitch() >= static_cast<int32_t>(width) / 2 && | 405 frame.GetUPitch() >= width / 2 && |
| 406 frame.GetVPitch() >= static_cast<int32_t>(width) / 2 && | 406 frame.GetVPitch() >= width / 2 && |
| 407 frame.GetWidth() == width && frame.GetHeight() == height; | 407 frame.width() == width && frame.height() == height; |
| 408 } | 408 } |
| 409 | 409 |
| 410 static bool IsPlaneEqual(const std::string& name, | 410 static bool IsPlaneEqual(const std::string& name, |
| 411 const uint8_t* plane1, | 411 const uint8_t* plane1, |
| 412 uint32_t pitch1, | 412 uint32_t pitch1, |
| 413 const uint8_t* plane2, | 413 const uint8_t* plane2, |
| 414 uint32_t pitch2, | 414 uint32_t pitch2, |
| 415 uint32_t width, | 415 uint32_t width, |
| 416 uint32_t height, | 416 uint32_t height, |
| 417 int max_error) { | 417 int max_error) { |
| 418 const uint8_t* r1 = plane1; | 418 const uint8_t* r1 = plane1; |
| 419 const uint8_t* r2 = plane2; | 419 const uint8_t* r2 = plane2; |
| 420 for (uint32_t y = 0; y < height; ++y) { | 420 for (uint32_t y = 0; y < height; ++y) { |
| 421 for (uint32_t x = 0; x < width; ++x) { | 421 for (uint32_t x = 0; x < width; ++x) { |
| 422 if (abs(static_cast<int>(r1[x] - r2[x])) > max_error) { | 422 if (abs(static_cast<int>(r1[x] - r2[x])) > max_error) { |
| 423 LOG(LS_INFO) << "IsPlaneEqual(" << name << "): pixel[" | 423 LOG(LS_INFO) << "IsPlaneEqual(" << name << "): pixel[" |
| 424 << x << "," << y << "] differs: " | 424 << x << "," << y << "] differs: " |
| 425 << static_cast<int>(r1[x]) << " vs " | 425 << static_cast<int>(r1[x]) << " vs " |
| 426 << static_cast<int>(r2[x]); | 426 << static_cast<int>(r2[x]); |
| 427 return false; | 427 return false; |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 r1 += pitch1; | 430 r1 += pitch1; |
| 431 r2 += pitch2; | 431 r2 += pitch2; |
| 432 } | 432 } |
| 433 return true; | 433 return true; |
| 434 } | 434 } |
| 435 | 435 |
| 436 static bool IsEqual(const cricket::VideoFrame& frame, | 436 static bool IsEqual(const cricket::VideoFrame& frame, |
| 437 size_t width, | 437 int width, |
| 438 size_t height, | 438 int height, |
| 439 int64_t time_stamp, | 439 int64_t time_stamp, |
| 440 const uint8_t* y, | 440 const uint8_t* y, |
| 441 uint32_t ypitch, | 441 uint32_t ypitch, |
| 442 const uint8_t* u, | 442 const uint8_t* u, |
| 443 uint32_t upitch, | 443 uint32_t upitch, |
| 444 const uint8_t* v, | 444 const uint8_t* v, |
| 445 uint32_t vpitch, | 445 uint32_t vpitch, |
| 446 int max_error) { | 446 int max_error) { |
| 447 return IsSize(frame, static_cast<uint32_t>(width), | 447 return IsSize(frame, width, height) && |
| 448 static_cast<uint32_t>(height)) && | |
| 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_t>(width), | 450 static_cast<uint32_t>(width), |
| 452 static_cast<uint32_t>(height), max_error) && | 451 static_cast<uint32_t>(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_t>((width + 1) / 2), | 453 static_cast<uint32_t>((width + 1) / 2), |
| 455 static_cast<uint32_t>((height + 1) / 2), max_error) && | 454 static_cast<uint32_t>((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_t>((width + 1) / 2), | 456 static_cast<uint32_t>((width + 1) / 2), |
| 458 static_cast<uint32_t>((height + 1) / 2), max_error); | 457 static_cast<uint32_t>((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.width(), frame2.height(), |
| 466 frame2.GetTimeStamp(), | 465 frame2.GetTimeStamp(), |
| 467 frame2.GetYPlane(), frame2.GetYPitch(), | 466 frame2.GetYPlane(), frame2.GetYPitch(), |
| 468 frame2.GetUPlane(), frame2.GetUPitch(), | 467 frame2.GetUPlane(), frame2.GetUPitch(), |
| 469 frame2.GetVPlane(), frame2.GetVPitch(), | 468 frame2.GetVPlane(), frame2.GetVPitch(), |
| 470 max_error); | 469 max_error); |
| 471 } | 470 } |
| 472 | 471 |
| 473 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, | 472 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, |
| 474 const cricket::VideoFrame& frame2, | 473 const cricket::VideoFrame& frame2, |
| 475 int hcrop, int vcrop, int max_error) { | 474 int hcrop, int vcrop, int max_error) { |
| 476 return frame1.GetWidth() <= frame2.GetWidth() && | 475 return frame1.width() <= frame2.width() && |
| 477 frame1.GetHeight() <= frame2.GetHeight() && | 476 frame1.height() <= frame2.height() && |
| 478 IsEqual(frame1, | 477 IsEqual(frame1, |
| 479 frame2.GetWidth() - hcrop * 2, | 478 frame2.width() - hcrop * 2, |
| 480 frame2.GetHeight() - vcrop * 2, | 479 frame2.height() - vcrop * 2, |
| 481 frame2.GetTimeStamp(), | 480 frame2.GetTimeStamp(), |
| 482 frame2.GetYPlane() + vcrop * frame2.GetYPitch() | 481 frame2.GetYPlane() + vcrop * frame2.GetYPitch() |
| 483 + hcrop, | 482 + hcrop, |
| 484 frame2.GetYPitch(), | 483 frame2.GetYPitch(), |
| 485 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 | 484 frame2.GetUPlane() + vcrop * frame2.GetUPitch() / 2 |
| 486 + hcrop / 2, | 485 + hcrop / 2, |
| 487 frame2.GetUPitch(), | 486 frame2.GetUPitch(), |
| 488 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 | 487 frame2.GetVPlane() + vcrop * frame2.GetVPitch() / 2 |
| 489 + hcrop / 2, | 488 + hcrop / 2, |
| 490 frame2.GetVPitch(), | 489 frame2.GetVPitch(), |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ | 786 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ |
| 788 -kHeight, kWidth, kHeight, \ | 787 -kHeight, kWidth, kHeight, \ |
| 789 webrtc::kVideoRotation_180, &frame1)); \ | 788 webrtc::kVideoRotation_180, &frame1)); \ |
| 790 size_t data_size; \ | 789 size_t data_size; \ |
| 791 bool ret = ms->GetSize(&data_size); \ | 790 bool ret = ms->GetSize(&data_size); \ |
| 792 EXPECT_TRUE(ret); \ | 791 EXPECT_TRUE(ret); \ |
| 793 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 792 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
| 794 kHeight, \ | 793 kHeight, \ |
| 795 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ | 794 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ |
| 796 data_size, 0, webrtc::kVideoRotation_0)); \ | 795 data_size, 0, webrtc::kVideoRotation_0)); \ |
| 797 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 796 int width_rotate = frame1.width(); \ |
| 798 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 797 int height_rotate = frame1.height(); \ |
| 799 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ | 798 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ |
| 800 libyuv::I420Mirror( \ | 799 libyuv::I420Mirror( \ |
| 801 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 800 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
| 802 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 801 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
| 803 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 802 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
| 804 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 803 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
| 805 kHeight); \ | 804 kHeight); \ |
| 806 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 805 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
| 807 } | 806 } |
| 808 | 807 |
| 809 TEST_MIRROR(I420, 420) | 808 TEST_MIRROR(I420, 420) |
| 810 | 809 |
| 811 // Macro to help test different rotations | 810 // Macro to help test different rotations |
| 812 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ | 811 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ |
| 813 void Construct##FOURCC##Rotate##ROTATE() { \ | 812 void Construct##FOURCC##Rotate##ROTATE() { \ |
| 814 T frame1, frame2, frame3; \ | 813 T frame1, frame2, frame3; \ |
| 815 std::unique_ptr<rtc::MemoryStream> ms( \ | 814 std::unique_ptr<rtc::MemoryStream> ms( \ |
| 816 CreateYuvSample(kWidth, kHeight, BPP)); \ | 815 CreateYuvSample(kWidth, kHeight, BPP)); \ |
| 817 ASSERT_TRUE(ms.get() != NULL); \ | 816 ASSERT_TRUE(ms.get() != NULL); \ |
| 818 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ | 817 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ |
| 819 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ | 818 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ |
| 820 &frame1)); \ | 819 &frame1)); \ |
| 821 size_t data_size; \ | 820 size_t data_size; \ |
| 822 bool ret = ms->GetSize(&data_size); \ | 821 bool ret = ms->GetSize(&data_size); \ |
| 823 EXPECT_TRUE(ret); \ | 822 EXPECT_TRUE(ret); \ |
| 824 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ | 823 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ |
| 825 kHeight, \ | 824 kHeight, \ |
| 826 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ | 825 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ |
| 827 data_size, 0, webrtc::kVideoRotation_0)); \ | 826 data_size, 0, webrtc::kVideoRotation_0)); \ |
| 828 int width_rotate = static_cast<int>(frame1.GetWidth()); \ | 827 int width_rotate = frame1.width(); \ |
| 829 int height_rotate = static_cast<int>(frame1.GetHeight()); \ | 828 int height_rotate = frame1.height(); \ |
| 830 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ | 829 EXPECT_TRUE(frame3.InitToBlack(width_rotate, height_rotate, 0)); \ |
| 831 libyuv::I420Rotate( \ | 830 libyuv::I420Rotate( \ |
| 832 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ | 831 frame2.GetYPlane(), frame2.GetYPitch(), frame2.GetUPlane(), \ |
| 833 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ | 832 frame2.GetUPitch(), frame2.GetVPlane(), frame2.GetVPitch(), \ |
| 834 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ | 833 frame3.GetYPlane(), frame3.GetYPitch(), frame3.GetUPlane(), \ |
| 835 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ | 834 frame3.GetUPitch(), frame3.GetVPlane(), frame3.GetVPitch(), kWidth, \ |
| 836 kHeight, libyuv::kRotate##ROTATE); \ | 835 kHeight, libyuv::kRotate##ROTATE); \ |
| 837 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ | 836 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ |
| 838 } | 837 } |
| 839 | 838 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 // Test 5 pixel edge case image. | 943 // Test 5 pixel edge case image. |
| 945 void ConstructI4205Pixel() { | 944 void ConstructI4205Pixel() { |
| 946 T frame; | 945 T frame; |
| 947 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; | 946 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; |
| 948 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); | 947 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); |
| 949 for (int i = 0; i < repeat_; ++i) { | 948 for (int i = 0; i < repeat_; ++i) { |
| 950 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, | 949 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, |
| 951 sizeof(pixels5x5), 0, | 950 sizeof(pixels5x5), 0, |
| 952 webrtc::kVideoRotation_0)); | 951 webrtc::kVideoRotation_0)); |
| 953 } | 952 } |
| 954 EXPECT_EQ(5u, frame.GetWidth()); | 953 EXPECT_EQ(5, frame.width()); |
| 955 EXPECT_EQ(5u, frame.GetHeight()); | 954 EXPECT_EQ(5, frame.height()); |
| 956 EXPECT_EQ(5, frame.GetYPitch()); | 955 EXPECT_EQ(5, frame.GetYPitch()); |
| 957 EXPECT_EQ(3, frame.GetUPitch()); | 956 EXPECT_EQ(3, frame.GetUPitch()); |
| 958 EXPECT_EQ(3, frame.GetVPitch()); | 957 EXPECT_EQ(3, frame.GetVPitch()); |
| 959 } | 958 } |
| 960 | 959 |
| 961 // Test 1 pixel edge case image ARGB buffer. | 960 // Test 1 pixel edge case image ARGB buffer. |
| 962 void ConstructARGB1Pixel() { | 961 void ConstructARGB1Pixel() { |
| 963 T frame; | 962 T frame; |
| 964 uint8_t pixel[4] = {64, 128, 192, 255}; | 963 uint8_t pixel[4] = {64, 128, 192, 255}; |
| 965 for (int i = 0; i < repeat_; ++i) { | 964 for (int i = 0; i < repeat_; ++i) { |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 reinterpret_cast<uint8_t*>(ms->GetBuffer()), | 1388 reinterpret_cast<uint8_t*>(ms->GetBuffer()), |
| 1390 data_size, 0, rotation, apply_rotation)); | 1389 data_size, 0, rotation, apply_rotation)); |
| 1391 if (apply_rotation) | 1390 if (apply_rotation) |
| 1392 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); | 1391 EXPECT_EQ(webrtc::kVideoRotation_0, frame1.GetVideoRotation()); |
| 1393 else | 1392 else |
| 1394 EXPECT_EQ(rotation, frame1.GetVideoRotation()); | 1393 EXPECT_EQ(rotation, frame1.GetVideoRotation()); |
| 1395 | 1394 |
| 1396 // Swapp width and height if the frame is rotated 90 or 270 degrees. | 1395 // Swapp width and height if the frame is rotated 90 or 270 degrees. |
| 1397 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 | 1396 if (apply_rotation && (rotation == webrtc::kVideoRotation_90 |
| 1398 || rotation == webrtc::kVideoRotation_270)) { | 1397 || rotation == webrtc::kVideoRotation_270)) { |
| 1399 EXPECT_TRUE(kHeight == frame1.GetWidth()); | 1398 EXPECT_TRUE(kHeight == frame1.width()); |
| 1400 EXPECT_TRUE(kWidth == frame1.GetHeight()); | 1399 EXPECT_TRUE(kWidth == frame1.height()); |
| 1401 } else { | 1400 } else { |
| 1402 EXPECT_TRUE(kWidth == frame1.GetWidth()); | 1401 EXPECT_TRUE(kWidth == frame1.width()); |
| 1403 EXPECT_TRUE(kHeight == frame1.GetHeight()); | 1402 EXPECT_TRUE(kHeight == frame1.height()); |
| 1404 } | 1403 } |
| 1405 EXPECT_FALSE(IsBlack(frame1)); | 1404 EXPECT_FALSE(IsBlack(frame1)); |
| 1406 EXPECT_FALSE(IsEqual(frame1, frame2, 0)); | 1405 EXPECT_FALSE(IsEqual(frame1, frame2, 0)); |
| 1407 } | 1406 } |
| 1408 | 1407 |
| 1409 void ResetAndApplyRotation() { | 1408 void ResetAndApplyRotation() { |
| 1410 Reset(webrtc::kVideoRotation_90, true); | 1409 Reset(webrtc::kVideoRotation_90, true); |
| 1411 } | 1410 } |
| 1412 | 1411 |
| 1413 void ResetAndDontApplyRotation() { | 1412 void ResetAndDontApplyRotation() { |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 1857 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); |
| 1859 source.StretchToFrame(&target2, true, true); | 1858 source.StretchToFrame(&target2, true, true); |
| 1860 EXPECT_TRUE(IsBlack(target2)); | 1859 EXPECT_TRUE(IsBlack(target2)); |
| 1861 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 1860 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); |
| 1862 } | 1861 } |
| 1863 | 1862 |
| 1864 int repeat_; | 1863 int repeat_; |
| 1865 }; | 1864 }; |
| 1866 | 1865 |
| 1867 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 1866 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ |
| OLD | NEW |