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

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

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update android capture and decoder code. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 446 }
447 r1 += pitch1; 447 r1 += pitch1;
448 r2 += pitch2; 448 r2 += pitch2;
449 } 449 }
450 return true; 450 return true;
451 } 451 }
452 452
453 static bool IsEqual(const cricket::VideoFrame& frame, 453 static bool IsEqual(const cricket::VideoFrame& frame,
454 int width, 454 int width,
455 int height, 455 int height,
456 int64_t time_stamp,
457 const uint8_t* y, 456 const uint8_t* y,
458 uint32_t ypitch, 457 uint32_t ypitch,
459 const uint8_t* u, 458 const uint8_t* u,
460 uint32_t upitch, 459 uint32_t upitch,
461 const uint8_t* v, 460 const uint8_t* v,
462 uint32_t vpitch, 461 uint32_t vpitch,
463 int max_error) { 462 int max_error) {
464 return IsSize(frame, width, height) && frame.GetTimeStamp() == time_stamp && 463 return IsSize(frame, width, height) &&
465 IsPlaneEqual("y", frame.video_frame_buffer()->DataY(), 464 IsPlaneEqual("y", frame.video_frame_buffer()->DataY(),
466 frame.video_frame_buffer()->StrideY(), y, ypitch, 465 frame.video_frame_buffer()->StrideY(), y, ypitch,
467 static_cast<uint32_t>(width), 466 static_cast<uint32_t>(width),
468 static_cast<uint32_t>(height), max_error) && 467 static_cast<uint32_t>(height), max_error) &&
469 IsPlaneEqual("u", frame.video_frame_buffer()->DataU(), 468 IsPlaneEqual("u", frame.video_frame_buffer()->DataU(),
470 frame.video_frame_buffer()->StrideU(), u, upitch, 469 frame.video_frame_buffer()->StrideU(), u, upitch,
471 static_cast<uint32_t>((width + 1) / 2), 470 static_cast<uint32_t>((width + 1) / 2),
472 static_cast<uint32_t>((height + 1) / 2), max_error) && 471 static_cast<uint32_t>((height + 1) / 2), max_error) &&
473 IsPlaneEqual("v", frame.video_frame_buffer()->DataV(), 472 IsPlaneEqual("v", frame.video_frame_buffer()->DataV(),
474 frame.video_frame_buffer()->StrideV(), v, vpitch, 473 frame.video_frame_buffer()->StrideV(), v, vpitch,
475 static_cast<uint32_t>((width + 1) / 2), 474 static_cast<uint32_t>((width + 1) / 2),
476 static_cast<uint32_t>((height + 1) / 2), max_error); 475 static_cast<uint32_t>((height + 1) / 2), max_error);
477 } 476 }
478 477
479 static bool IsEqual(const cricket::VideoFrame& frame1, 478 static bool IsEqual(const cricket::VideoFrame& frame1,
480 const cricket::VideoFrame& frame2, 479 const cricket::VideoFrame& frame2,
481 int max_error) { 480 int max_error) {
482 return IsEqual(frame1, 481 return frame1.GetTimeStamp() == frame2.GetTimeStamp() &&
482 IsEqual(frame1,
483 frame2.width(), frame2.height(), 483 frame2.width(), frame2.height(),
484 frame2.GetTimeStamp(),
485 frame2.video_frame_buffer()->DataY(), 484 frame2.video_frame_buffer()->DataY(),
486 frame2.video_frame_buffer()->StrideY(), 485 frame2.video_frame_buffer()->StrideY(),
487 frame2.video_frame_buffer()->DataU(), 486 frame2.video_frame_buffer()->DataU(),
488 frame2.video_frame_buffer()->StrideU(), 487 frame2.video_frame_buffer()->StrideU(),
489 frame2.video_frame_buffer()->DataV(), 488 frame2.video_frame_buffer()->DataV(),
490 frame2.video_frame_buffer()->StrideV(), 489 frame2.video_frame_buffer()->StrideV(),
491 max_error); 490 max_error);
492 } 491 }
493 492
493 static bool IsEqual(
494 const cricket::VideoFrame& frame1,
495 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
496 int max_error) {
497 return IsEqual(frame1,
498 buffer->width(), buffer->height(),
499 buffer->DataY(), buffer->StrideY(),
500 buffer->DataU(), buffer->StrideU(),
501 buffer->DataV(), buffer->StrideV(),
502 max_error);
503 }
504
494 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1, 505 static bool IsEqualWithCrop(const cricket::VideoFrame& frame1,
495 const cricket::VideoFrame& frame2, 506 const cricket::VideoFrame& frame2,
496 int hcrop, int vcrop, int max_error) { 507 int hcrop, int vcrop, int max_error) {
497 return frame1.width() <= frame2.width() && 508 return frame1.width() <= frame2.width() &&
498 frame1.height() <= frame2.height() && 509 frame1.height() <= frame2.height() &&
510 frame1.GetTimeStamp() == frame2.GetTimeStamp() &&
499 IsEqual(frame1, 511 IsEqual(frame1,
500 frame2.width() - hcrop * 2, 512 frame2.width() - hcrop * 2,
501 frame2.height() - vcrop * 2, 513 frame2.height() - vcrop * 2,
502 frame2.GetTimeStamp(),
503 frame2.video_frame_buffer()->DataY() 514 frame2.video_frame_buffer()->DataY()
504 + vcrop * frame2.video_frame_buffer()->StrideY() 515 + vcrop * frame2.video_frame_buffer()->StrideY()
505 + hcrop, 516 + hcrop,
506 frame2.video_frame_buffer()->StrideY(), 517 frame2.video_frame_buffer()->StrideY(),
507 frame2.video_frame_buffer()->DataU() 518 frame2.video_frame_buffer()->DataU()
508 + vcrop * frame2.video_frame_buffer()->StrideU() / 2 519 + vcrop * frame2.video_frame_buffer()->StrideU() / 2
509 + hcrop / 2, 520 + hcrop / 2,
510 frame2.video_frame_buffer()->StrideU(), 521 frame2.video_frame_buffer()->StrideU(),
511 frame2.video_frame_buffer()->DataV() 522 frame2.video_frame_buffer()->DataV()
512 + vcrop * frame2.video_frame_buffer()->StrideV() / 2 523 + vcrop * frame2.video_frame_buffer()->StrideV() / 2
(...skipping 18 matching lines...) Expand all
531 T frame; 542 T frame;
532 EXPECT_TRUE(IsNull(frame)); 543 EXPECT_TRUE(IsNull(frame));
533 std::unique_ptr<rtc::MemoryStream> ms( 544 std::unique_ptr<rtc::MemoryStream> ms(
534 CreateYuvSample(kWidth, kHeight, 12)); 545 CreateYuvSample(kWidth, kHeight, 12));
535 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, 546 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420,
536 kWidth, kHeight, &frame)); 547 kWidth, kHeight, &frame));
537 548
538 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); 549 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer());
539 const uint8_t* u = y + kWidth * kHeight; 550 const uint8_t* u = y + kWidth * kHeight;
540 const uint8_t* v = u + kWidth * kHeight / 4; 551 const uint8_t* v = u + kWidth * kHeight / 4;
541 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, 552 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, y, kWidth, u, kWidth / 2, v,
542 kWidth / 2, v, kWidth / 2, 0)); 553 kWidth / 2, 0));
543 } 554 }
544 555
545 // Test constructing an image from a YV12 buffer. 556 // Test constructing an image from a YV12 buffer.
546 void ConstructYV12() { 557 void ConstructYV12() {
547 T frame; 558 T frame;
548 std::unique_ptr<rtc::MemoryStream> ms( 559 std::unique_ptr<rtc::MemoryStream> ms(
549 CreateYuvSample(kWidth, kHeight, 12)); 560 CreateYuvSample(kWidth, kHeight, 12));
550 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12, 561 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_YV12,
551 kWidth, kHeight, &frame)); 562 kWidth, kHeight, &frame));
552 563
553 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer()); 564 const uint8_t* y = reinterpret_cast<uint8_t*>(ms.get()->GetBuffer());
554 const uint8_t* v = y + kWidth * kHeight; 565 const uint8_t* v = y + kWidth * kHeight;
555 const uint8_t* u = v + kWidth * kHeight / 4; 566 const uint8_t* u = v + kWidth * kHeight / 4;
556 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, 0, y, kWidth, u, 567 EXPECT_TRUE(IsEqual(frame, kWidth, kHeight, y, kWidth, u, kWidth / 2, v,
557 kWidth / 2, v, kWidth / 2, 0)); 568 kWidth / 2, 0));
558 } 569 }
559 570
560 // Test constructing an image from a I422 buffer. 571 // Test constructing an image from a I422 buffer.
561 void ConstructI422() { 572 void ConstructI422() {
562 T frame1, frame2; 573 T frame1, frame2;
563 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); 574 ASSERT_TRUE(LoadFrameNoRepeat(&frame1));
564 size_t buf_size = kWidth * kHeight * 2; 575 size_t buf_size = kWidth * kHeight * 2;
565 std::unique_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]); 576 std::unique_ptr<uint8_t[]> buf(new uint8_t[buf_size + kAlignment]);
566 uint8_t* y = ALIGNP(buf.get(), kAlignment); 577 uint8_t* y = ALIGNP(buf.get(), kAlignment);
567 uint8_t* u = y + kWidth * kHeight; 578 uint8_t* u = y + kWidth * kHeight;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 out, 823 out,
813 out_size, kWidth * 2)); 824 out_size, kWidth * 2));
814 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_R444, 825 EXPECT_TRUE(LoadFrame(out, out_size, cricket::FOURCC_R444,
815 kWidth, kHeight, &frame2)); 826 kWidth, kHeight, &frame2));
816 EXPECT_TRUE(IsEqual(frame1, frame2, 20)); 827 EXPECT_TRUE(IsEqual(frame1, frame2, 20));
817 } 828 }
818 829
819 // Macro to help test different rotations 830 // Macro to help test different rotations
820 #define TEST_MIRROR(FOURCC, BPP) \ 831 #define TEST_MIRROR(FOURCC, BPP) \
821 void Construct##FOURCC##Mirror() { \ 832 void Construct##FOURCC##Mirror() { \
822 T frame1, frame2, frame3; \ 833 T frame1, frame2; \
834 rtc::scoped_refptr<webrtc::I420Buffer> res_buffer; \
823 std::unique_ptr<rtc::MemoryStream> ms( \ 835 std::unique_ptr<rtc::MemoryStream> ms( \
824 CreateYuvSample(kWidth, kHeight, BPP)); \ 836 CreateYuvSample(kWidth, kHeight, BPP)); \
825 ASSERT_TRUE(ms.get() != NULL); \ 837 ASSERT_TRUE(ms.get() != NULL); \
826 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \ 838 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, \
827 -kHeight, kWidth, kHeight, \ 839 -kHeight, kWidth, kHeight, \
828 webrtc::kVideoRotation_180, &frame1)); \ 840 webrtc::kVideoRotation_180, &frame1)); \
829 size_t data_size; \ 841 size_t data_size; \
830 bool ret = ms->GetSize(&data_size); \ 842 bool ret = ms->GetSize(&data_size); \
831 EXPECT_TRUE(ret); \ 843 EXPECT_TRUE(ret); \
832 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ 844 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \
833 kHeight, \ 845 kHeight, \
834 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ 846 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \
835 data_size, 0, webrtc::kVideoRotation_0)); \ 847 data_size, 0, webrtc::kVideoRotation_0)); \
836 int width_rotate = frame1.width(); \ 848 int width_rotate = frame1.width(); \
837 int height_rotate = frame1.height(); \ 849 int height_rotate = frame1.height(); \
838 frame3.InitToEmptyBuffer(width_rotate, height_rotate); \ 850 res_buffer = webrtc::I420Buffer::Create(width_rotate, height_rotate); \
839 libyuv::I420Mirror(frame2.video_frame_buffer()->DataY(), \ 851 libyuv::I420Mirror(frame2.video_frame_buffer()->DataY(), \
840 frame2.video_frame_buffer()->StrideY(), \ 852 frame2.video_frame_buffer()->StrideY(), \
841 frame2.video_frame_buffer()->DataU(), \ 853 frame2.video_frame_buffer()->DataU(), \
842 frame2.video_frame_buffer()->StrideU(), \ 854 frame2.video_frame_buffer()->StrideU(), \
843 frame2.video_frame_buffer()->DataV(), \ 855 frame2.video_frame_buffer()->DataV(), \
844 frame2.video_frame_buffer()->StrideV(), \ 856 frame2.video_frame_buffer()->StrideV(), \
845 frame3.video_frame_buffer()->MutableDataY(), \ 857 res_buffer->MutableDataY(), res_buffer->StrideY(), \
846 frame3.video_frame_buffer()->StrideY(), \ 858 res_buffer->MutableDataU(), res_buffer->StrideU(), \
847 frame3.video_frame_buffer()->MutableDataU(), \ 859 res_buffer->MutableDataV(), res_buffer->StrideV(), \
848 frame3.video_frame_buffer()->StrideU(), \ 860 kWidth, kHeight); \
849 frame3.video_frame_buffer()->MutableDataV(), \ 861 EXPECT_TRUE(IsEqual(frame1, res_buffer, 0)); \
850 frame3.video_frame_buffer()->StrideV(), kWidth, \
851 kHeight); \
852 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \
853 } 862 }
854 863
855 TEST_MIRROR(I420, 420) 864 TEST_MIRROR(I420, 420)
856 865
857 // Macro to help test different rotations 866 // Macro to help test different rotations
858 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \ 867 #define TEST_ROTATE(FOURCC, BPP, ROTATE) \
859 void Construct##FOURCC##Rotate##ROTATE() { \ 868 void Construct##FOURCC##Rotate##ROTATE() { \
860 T frame1, frame2, frame3; \ 869 T frame1, frame2; \
870 rtc::scoped_refptr<webrtc::I420Buffer> res_buffer; \
861 std::unique_ptr<rtc::MemoryStream> ms( \ 871 std::unique_ptr<rtc::MemoryStream> ms( \
862 CreateYuvSample(kWidth, kHeight, BPP)); \ 872 CreateYuvSample(kWidth, kHeight, BPP)); \
863 ASSERT_TRUE(ms.get() != NULL); \ 873 ASSERT_TRUE(ms.get() != NULL); \
864 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \ 874 EXPECT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_##FOURCC, kWidth, kHeight, \
865 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \ 875 kWidth, kHeight, webrtc::kVideoRotation_##ROTATE, \
866 &frame1)); \ 876 &frame1)); \
867 size_t data_size; \ 877 size_t data_size; \
868 bool ret = ms->GetSize(&data_size); \ 878 bool ret = ms->GetSize(&data_size); \
869 EXPECT_TRUE(ret); \ 879 EXPECT_TRUE(ret); \
870 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \ 880 EXPECT_TRUE(frame2.Init(cricket::FOURCC_##FOURCC, kWidth, kHeight, kWidth, \
871 kHeight, \ 881 kHeight, \
872 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \ 882 reinterpret_cast<uint8_t*>(ms->GetBuffer()), \
873 data_size, 0, webrtc::kVideoRotation_0)); \ 883 data_size, 0, webrtc::kVideoRotation_0)); \
874 int width_rotate = frame1.width(); \ 884 int width_rotate = frame1.width(); \
875 int height_rotate = frame1.height(); \ 885 int height_rotate = frame1.height(); \
876 frame3.InitToEmptyBuffer(width_rotate, height_rotate); \ 886 res_buffer = webrtc::I420Buffer::Create(width_rotate, height_rotate); \
877 libyuv::I420Rotate(frame2.video_frame_buffer()->DataY(), \ 887 libyuv::I420Rotate(frame2.video_frame_buffer()->DataY(), \
878 frame2.video_frame_buffer()->StrideY(), \ 888 frame2.video_frame_buffer()->StrideY(), \
879 frame2.video_frame_buffer()->DataU(), \ 889 frame2.video_frame_buffer()->DataU(), \
880 frame2.video_frame_buffer()->StrideU(), \ 890 frame2.video_frame_buffer()->StrideU(), \
881 frame2.video_frame_buffer()->DataV(), \ 891 frame2.video_frame_buffer()->DataV(), \
882 frame2.video_frame_buffer()->StrideV(), \ 892 frame2.video_frame_buffer()->StrideV(), \
883 frame3.video_frame_buffer()->MutableDataY(), \ 893 res_buffer->MutableDataY(), res_buffer->StrideY(), \
884 frame3.video_frame_buffer()->StrideY(), \ 894 res_buffer->MutableDataU(), res_buffer->StrideU(), \
885 frame3.video_frame_buffer()->MutableDataU(), \ 895 res_buffer->MutableDataV(), res_buffer->StrideV(), \
886 frame3.video_frame_buffer()->StrideU(), \ 896 kWidth, kHeight, libyuv::kRotate##ROTATE); \
887 frame3.video_frame_buffer()->MutableDataV(), \ 897 EXPECT_TRUE(IsEqual(frame1, res_buffer, 0)); \
888 frame3.video_frame_buffer()->StrideV(), kWidth, \
889 kHeight, libyuv::kRotate##ROTATE); \
890 EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \
891 } 898 }
892 899
893 // Test constructing an image with rotation. 900 // Test constructing an image with rotation.
894 TEST_ROTATE(I420, 12, 0) 901 TEST_ROTATE(I420, 12, 0)
895 TEST_ROTATE(I420, 12, 90) 902 TEST_ROTATE(I420, 12, 90)
896 TEST_ROTATE(I420, 12, 180) 903 TEST_ROTATE(I420, 12, 180)
897 TEST_ROTATE(I420, 12, 270) 904 TEST_ROTATE(I420, 12, 270)
898 TEST_ROTATE(YV12, 12, 0) 905 TEST_ROTATE(YV12, 12, 0)
899 TEST_ROTATE(YV12, 12, 90) 906 TEST_ROTATE(YV12, 12, 90)
900 TEST_ROTATE(YV12, 12, 180) 907 TEST_ROTATE(YV12, 12, 180)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 void ConstructI4201Pixel() { 991 void ConstructI4201Pixel() {
985 T frame; 992 T frame;
986 uint8_t pixel[3] = {1, 2, 3}; 993 uint8_t pixel[3] = {1, 2, 3};
987 for (int i = 0; i < repeat_; ++i) { 994 for (int i = 0; i < repeat_; ++i) {
988 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel, 995 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel,
989 sizeof(pixel), 0, webrtc::kVideoRotation_0)); 996 sizeof(pixel), 0, webrtc::kVideoRotation_0));
990 } 997 }
991 const uint8_t* y = pixel; 998 const uint8_t* y = pixel;
992 const uint8_t* u = y + 1; 999 const uint8_t* u = y + 1;
993 const uint8_t* v = u + 1; 1000 const uint8_t* v = u + 1;
994 EXPECT_TRUE(IsEqual(frame, 1, 1, 0, y, 1, u, 1, v, 1, 0)); 1001 EXPECT_TRUE(IsEqual(frame, 1, 1, y, 1, u, 1, v, 1, 0));
995 } 1002 }
996 1003
997 // Test 5 pixel edge case image. 1004 // Test 5 pixel edge case image.
998 void ConstructI4205Pixel() { 1005 void ConstructI4205Pixel() {
999 T frame; 1006 T frame;
1000 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2]; 1007 uint8_t pixels5x5[5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2];
1001 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2); 1008 memset(pixels5x5, 1, 5 * 5 + ((5 + 1) / 2 * (5 + 1) / 2) * 2);
1002 for (int i = 0; i < repeat_; ++i) { 1009 for (int i = 0; i < repeat_; ++i) {
1003 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5, 1010 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 5, 5, 5, 5, pixels5x5,
1004 sizeof(pixels5x5), 0, 1011 sizeof(pixels5x5), 0,
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 int (*RGBToI420)(const uint8_t* src_frame, 1458 int (*RGBToI420)(const uint8_t* src_frame,
1452 int src_stride_frame, 1459 int src_stride_frame,
1453 uint8_t* dst_y, 1460 uint8_t* dst_y,
1454 int dst_stride_y, 1461 int dst_stride_y,
1455 uint8_t* dst_u, 1462 uint8_t* dst_u,
1456 int dst_stride_u, 1463 int dst_stride_u,
1457 uint8_t* dst_v, 1464 uint8_t* dst_v,
1458 int dst_stride_v, 1465 int dst_stride_v,
1459 int width, 1466 int width,
1460 int height)) { 1467 int height)) {
1461 T frame1, frame2; 1468 T frame1;
1469 rtc::scoped_refptr<webrtc::I420Buffer> res_buffer;
1462 int repeat_to = (to_from == TO) ? repeat_ : 1; 1470 int repeat_to = (to_from == TO) ? repeat_ : 1;
1463 int repeat_from = (to_from == FROM) ? repeat_ : 1; 1471 int repeat_from = (to_from == FROM) ? repeat_ : 1;
1464 1472
1465 int astride = kWidth * bpp + rowpad; 1473 int astride = kWidth * bpp + rowpad;
1466 size_t out_size = astride * kHeight; 1474 size_t out_size = astride * kHeight;
1467 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment + 1]); 1475 std::unique_ptr<uint8_t[]> outbuf(new uint8_t[out_size + kAlignment + 1]);
1468 memset(outbuf.get(), 0, out_size + kAlignment + 1); 1476 memset(outbuf.get(), 0, out_size + kAlignment + 1);
1469 uint8_t* outtop = ALIGNP(outbuf.get(), kAlignment); 1477 uint8_t* outtop = ALIGNP(outbuf.get(), kAlignment);
1470 uint8_t* out = outtop; 1478 uint8_t* out = outtop;
1471 int stride = astride; 1479 int stride = astride;
1472 if (invert) { 1480 if (invert) {
1473 out += (kHeight - 1) * stride; // Point to last row. 1481 out += (kHeight - 1) * stride; // Point to last row.
1474 stride = -stride; 1482 stride = -stride;
1475 } 1483 }
1476 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); 1484 ASSERT_TRUE(LoadFrameNoRepeat(&frame1));
1477 1485
1478 for (int i = 0; i < repeat_to; ++i) { 1486 for (int i = 0; i < repeat_to; ++i) {
1479 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc, 1487 EXPECT_EQ(out_size, frame1.ConvertToRgbBuffer(fourcc,
1480 out, 1488 out,
1481 out_size, stride)); 1489 out_size, stride));
1482 } 1490 }
1483 frame2.InitToEmptyBuffer(kWidth, kHeight); 1491 res_buffer = webrtc::I420Buffer::Create(kWidth, kHeight);
1484 for (int i = 0; i < repeat_from; ++i) { 1492 for (int i = 0; i < repeat_from; ++i) {
1485 EXPECT_EQ(0, RGBToI420(out, stride, 1493 EXPECT_EQ(0, RGBToI420(out, stride,
1486 frame2.video_frame_buffer()->MutableDataY(), 1494 res_buffer->MutableDataY(), res_buffer->StrideY(),
1487 frame2.video_frame_buffer()->StrideY(), 1495 res_buffer->MutableDataU(), res_buffer->StrideU(),
1488 frame2.video_frame_buffer()->MutableDataU(), 1496 res_buffer->MutableDataV(), res_buffer->StrideV(),
1489 frame2.video_frame_buffer()->StrideU(),
1490 frame2.video_frame_buffer()->MutableDataV(),
1491 frame2.video_frame_buffer()->StrideV(),
1492 kWidth, kHeight)); 1497 kWidth, kHeight));
1493 } 1498 }
1494 if (rowpad) { 1499 if (rowpad) {
1495 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.
1496 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.
1497 } else { 1502 } else {
1498 EXPECT_NE(0, outtop[kWidth * bpp]); // Expect something to be here. 1503 EXPECT_NE(0, outtop[kWidth * bpp]); // Expect something to be here.
1499 } 1504 }
1500 EXPECT_EQ(0, outtop[out_size]); // Ensure no overrun. 1505 EXPECT_EQ(0, outtop[out_size]); // Ensure no overrun.
1501 EXPECT_TRUE(IsEqual(frame1, frame2, error)); 1506 EXPECT_TRUE(IsEqual(frame1, res_buffer, error));
1502 } 1507 }
1503 1508
1504 static const int kError = 20; 1509 static const int kError = 20;
1505 static const int kErrorHigh = 40; 1510 static const int kErrorHigh = 40;
1506 static const int kOddStride = 23; 1511 static const int kOddStride = 23;
1507 1512
1508 // Tests ConvertToRGBBuffer formats. 1513 // Tests ConvertToRGBBuffer formats.
1509 void ConvertToARGBBuffer() { 1514 void ConvertToARGBBuffer() {
1510 ConvertToBuffer(4, 0, false, TO, kError, 1515 ConvertToBuffer(4, 0, false, TO, kError,
1511 cricket::FOURCC_ARGB, libyuv::ARGBToI420); 1516 cricket::FOURCC_ARGB, libyuv::ARGBToI420);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 target.reset(source->Copy()); 1835 target.reset(source->Copy());
1831 EXPECT_TRUE(IsEqual(*source, *target, 0)); 1836 EXPECT_TRUE(IsEqual(*source, *target, 0));
1832 const T* const_source = source.get(); 1837 const T* const_source = source.get();
1833 EXPECT_EQ(const_source->video_frame_buffer(), target->video_frame_buffer()); 1838 EXPECT_EQ(const_source->video_frame_buffer(), target->video_frame_buffer());
1834 } 1839 }
1835 1840
1836 int repeat_; 1841 int repeat_;
1837 }; 1842 };
1838 1843
1839 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ 1844 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698