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

Unified Diff: media/base/yuv_convert_unittest.cc

Issue 113298: Fix failing Valgrind builds for media_unittests. (Closed)
Patch Set: Created 11 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/yuv_convert_unittest.cc
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc
index 729efa264cbfaf290cd52a3de001923cb3feb15e..28e1f1cfb9cf5d1ba74e017722489f5dc1927bea 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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698