diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 21:35:37 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 21:35:37 +0000 |
commit | b5c37c06811e605d37c5ba5b29210ded0fc76e1d (patch) | |
tree | 4e6f756a275e3f5c9e9c4aacb1f1245dbf8c6ec8 /media | |
parent | 8f021982530c36e1aa86f246cc0a820505d6b9e5 (diff) | |
download | chromium_src-b5c37c06811e605d37c5ba5b29210ded0fc76e1d.zip chromium_src-b5c37c06811e605d37c5ba5b29210ded0fc76e1d.tar.gz chromium_src-b5c37c06811e605d37c5ba5b29210ded0fc76e1d.tar.bz2 |
Fix failing Valgrind builds for media_unittests.
Did some minor clean up as well.
Review URL: http://codereview.chromium.org/113298
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/yuv_convert_unittest.cc | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc index 729efa2..28e1f1c 100644 --- a/media/base/yuv_convert_unittest.cc +++ b/media/base/yuv_convert_unittest.cc @@ -23,7 +23,18 @@ static const int kWidth = 640; static const int kHeight = 360; static const int kBpp = 4; -TEST(YuvConvertTest, Basic) { +// Surface sizes. +static const size_t kYUV12Size = kWidth * kHeight * 12 / 8; +static const size_t kYUV16Size = kWidth * kHeight * 16 / 8; +static const size_t kRGBSize = kWidth * kHeight * kBpp; +static const size_t kRGBSizeConverted = kWidth * kHeight * kBpp; + +TEST(YUVConvertTest, YV12) { + // Allocate all surfaces. + scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); + scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); + scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); + // Read YUV reference data from file. FilePath yuv_url; EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); @@ -31,12 +42,10 @@ TEST(YuvConvertTest, Basic) { .Append(FILE_PATH_LITERAL("test")) .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("bali.yv12.640_360.yuv")); - const size_t size_of_yuv = kWidth * kHeight * 12 / 8; // 12 bpp. - uint8* yuv_bytes = new uint8[size_of_yuv]; - EXPECT_EQ(static_cast<int>(size_of_yuv), + EXPECT_EQ(static_cast<int>(kYUV12Size), file_util::ReadFile(yuv_url, - reinterpret_cast<char*>(yuv_bytes), - static_cast<int>(size_of_yuv))); + reinterpret_cast<char*>(yuv_bytes.get()), + static_cast<int>(kYUV12Size))); // Read RGB reference data from file. FilePath rgb_url; @@ -45,33 +54,33 @@ TEST(YuvConvertTest, Basic) { .Append(FILE_PATH_LITERAL("test")) .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("bali.yv12.640_360.rgb")); - const size_t size_of_rgb = kWidth * kHeight * kBpp; - uint8* rgb_bytes = new uint8[size_of_rgb]; - EXPECT_EQ(static_cast<int>(size_of_rgb), + EXPECT_EQ(static_cast<int>(kRGBSize), file_util::ReadFile(rgb_url, - reinterpret_cast<char*>(rgb_bytes), - static_cast<int>(size_of_rgb))); + reinterpret_cast<char*>(rgb_bytes.get()), + static_cast<int>(kRGBSize))); // Convert a frame of YUV to 32 bit ARGB. - const size_t size_of_rgb_converted = kWidth * kHeight * kBpp; - uint8* rgb_converted_bytes = new uint8[size_of_rgb_converted]; - - media::ConvertYV12ToRGB32(yuv_bytes, // Y plane - yuv_bytes + kWidth * kHeight, // U plane - yuv_bytes + kWidth * kHeight * 5 / 4, // V plane - rgb_converted_bytes, // Rgb output + media::ConvertYV12ToRGB32(yuv_bytes.get(), // Y + yuv_bytes.get() + kWidth * kHeight, // U + yuv_bytes.get() + kWidth * kHeight * 5 / 4, // V + rgb_converted_bytes.get(), // RGB output kWidth, kHeight, // Dimensions kWidth, // YStride - kWidth / 2, // UvStride - kWidth * kBpp); // RgbStride + kWidth / 2, // UVStride + kWidth * kBpp); // RGBStride // Compare converted YUV to reference conversion file. - int rgb_diff = memcmp(rgb_converted_bytes, rgb_bytes, size_of_rgb); + int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); EXPECT_EQ(rgb_diff, 0); } -TEST(YV16ConvertTest, Basic) { +TEST(YUVConvertTest, YV16) { + // Allocate all surfaces. + scoped_array<uint8> yuv_bytes(new uint8[kYUV16Size]); + scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); + scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); + // Read YV16 reference data from file. FilePath yuv_url; EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); @@ -79,12 +88,10 @@ TEST(YV16ConvertTest, Basic) { .Append(FILE_PATH_LITERAL("test")) .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("bali.yv16.640_360.yuv")); - const size_t size_of_yuv = kWidth * kHeight * 16 / 8; // 16 bpp. - uint8* yuv_bytes = new uint8[size_of_yuv]; - EXPECT_EQ(static_cast<int>(size_of_yuv), + EXPECT_EQ(static_cast<int>(kYUV16Size), file_util::ReadFile(yuv_url, - reinterpret_cast<char*>(yuv_bytes), - static_cast<int>(size_of_yuv))); + reinterpret_cast<char*>(yuv_bytes.get()), + static_cast<int>(kYUV16Size))); // Read RGB reference data from file. FilePath rgb_url; @@ -93,28 +100,23 @@ TEST(YV16ConvertTest, Basic) { .Append(FILE_PATH_LITERAL("test")) .Append(FILE_PATH_LITERAL("data")) .Append(FILE_PATH_LITERAL("bali.yv16.640_360.rgb")); - const size_t size_of_rgb = kWidth * kHeight * kBpp; - uint8* rgb_bytes = new uint8[size_of_rgb]; - EXPECT_EQ(static_cast<int>(size_of_rgb), + EXPECT_EQ(static_cast<int>(kRGBSize), file_util::ReadFile(rgb_url, - reinterpret_cast<char*>(rgb_bytes), - static_cast<int>(size_of_rgb))); + reinterpret_cast<char*>(rgb_bytes.get()), + static_cast<int>(kRGBSize))); // Convert a frame of YUV to 32 bit ARGB. - const size_t size_of_rgb_converted = kWidth * kHeight * kBpp; - uint8* rgb_converted_bytes = new uint8[size_of_rgb_converted]; - - media::ConvertYV16ToRGB32(yuv_bytes, // Y plane - yuv_bytes + kWidth * kHeight, // U plane - yuv_bytes + kWidth * kHeight * 3 / 2, // V plane - rgb_converted_bytes, // Rgb output + media::ConvertYV16ToRGB32(yuv_bytes.get(), // Y + yuv_bytes.get() + kWidth * kHeight, // U + yuv_bytes.get() + kWidth * kHeight * 3 / 2, // V + rgb_converted_bytes.get(), // RGB output kWidth, kHeight, // Dimensions kWidth, // YStride - kWidth / 2, // UvStride - kWidth * kBpp); // RgbStride + kWidth / 2, // UVStride + kWidth * kBpp); // RGBStride // Compare converted YUV to reference conversion file. - int rgb_diff = memcmp(rgb_converted_bytes, rgb_bytes, size_of_rgb); + int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); EXPECT_EQ(rgb_diff, 0); } |