| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "media/base/yuv_convert.h" | 7 #include "media/base/yuv_convert.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 // Reference images were created with the following steps | 10 // Reference images were created with the following steps |
| 11 // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv420p -an | 11 // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv420p -an |
| 12 // bali.yv12.1280_720.yuv | 12 // bali.yv12.1280_720.yuv |
| 13 // yuvhalf -yv12 -skip 24 bali.yv12.1280_720.yuv bali.yv12.640_360.yuv | 13 // yuvhalf -yv12 -skip 24 bali.yv12.1280_720.yuv bali.yv12.640_360.yuv |
| 14 // yuvtool -yv12 bali.yv12.640_360.yuv bali.yv12.640_360.rgb | 14 // yuvtool -yv12 bali.yv12.640_360.yuv bali.yv12.640_360.rgb |
| 15 | 15 |
| 16 // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv422p -an | 16 // ffmpeg -vframes 25 -i bali.mov -vcodec rawvideo -pix_fmt yuv422p -an |
| 17 // bali.yv16.1280_720.yuv | 17 // bali.yv16.1280_720.yuv |
| 18 // yuvhalf -yv16 -skip 24 bali.yv16.1280_720.yuv bali.yv16.640_360.yuv | 18 // yuvhalf -yv16 -skip 24 bali.yv16.1280_720.yuv bali.yv16.640_360.yuv |
| 19 // yuvtool -yv16 bali.yv16.640_360.yuv bali.yv16.640_360.rgb | 19 // yuvtool -yv16 bali.yv16.640_360.yuv bali.yv16.640_360.rgb |
| 20 | 20 |
| 21 // Size of raw image. | 21 // Size of raw image. |
| 22 static const int kWidth = 640; | 22 static const int kWidth = 640; |
| 23 static const int kHeight = 360; | 23 static const int kHeight = 360; |
| 24 static const int kBpp = 4; | 24 static const int kBpp = 4; |
| 25 | 25 |
| 26 TEST(YuvConvertTest, Basic) { | 26 // Surface sizes. |
| 27 static const size_t kYUV12Size = kWidth * kHeight * 12 / 8; |
| 28 static const size_t kYUV16Size = kWidth * kHeight * 16 / 8; |
| 29 static const size_t kRGBSize = kWidth * kHeight * kBpp; |
| 30 static const size_t kRGBSizeConverted = kWidth * kHeight * kBpp; |
| 31 |
| 32 TEST(YUVConvertTest, YV12) { |
| 33 // Allocate all surfaces. |
| 34 scoped_array<uint8> yuv_bytes(new uint8[kYUV12Size]); |
| 35 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| 36 scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); |
| 37 |
| 27 // Read YUV reference data from file. | 38 // Read YUV reference data from file. |
| 28 FilePath yuv_url; | 39 FilePath yuv_url; |
| 29 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 40 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 30 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 41 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 31 .Append(FILE_PATH_LITERAL("test")) | 42 .Append(FILE_PATH_LITERAL("test")) |
| 32 .Append(FILE_PATH_LITERAL("data")) | 43 .Append(FILE_PATH_LITERAL("data")) |
| 33 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.yuv")); | 44 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.yuv")); |
| 34 const size_t size_of_yuv = kWidth * kHeight * 12 / 8; // 12 bpp. | 45 EXPECT_EQ(static_cast<int>(kYUV12Size), |
| 35 uint8* yuv_bytes = new uint8[size_of_yuv]; | |
| 36 EXPECT_EQ(static_cast<int>(size_of_yuv), | |
| 37 file_util::ReadFile(yuv_url, | 46 file_util::ReadFile(yuv_url, |
| 38 reinterpret_cast<char*>(yuv_bytes), | 47 reinterpret_cast<char*>(yuv_bytes.get()), |
| 39 static_cast<int>(size_of_yuv))); | 48 static_cast<int>(kYUV12Size))); |
| 40 | 49 |
| 41 // Read RGB reference data from file. | 50 // Read RGB reference data from file. |
| 42 FilePath rgb_url; | 51 FilePath rgb_url; |
| 43 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url)); | 52 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url)); |
| 44 rgb_url = rgb_url.Append(FILE_PATH_LITERAL("media")) | 53 rgb_url = rgb_url.Append(FILE_PATH_LITERAL("media")) |
| 45 .Append(FILE_PATH_LITERAL("test")) | 54 .Append(FILE_PATH_LITERAL("test")) |
| 46 .Append(FILE_PATH_LITERAL("data")) | 55 .Append(FILE_PATH_LITERAL("data")) |
| 47 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.rgb")); | 56 .Append(FILE_PATH_LITERAL("bali.yv12.640_360.rgb")); |
| 48 const size_t size_of_rgb = kWidth * kHeight * kBpp; | 57 EXPECT_EQ(static_cast<int>(kRGBSize), |
| 49 uint8* rgb_bytes = new uint8[size_of_rgb]; | |
| 50 EXPECT_EQ(static_cast<int>(size_of_rgb), | |
| 51 file_util::ReadFile(rgb_url, | 58 file_util::ReadFile(rgb_url, |
| 52 reinterpret_cast<char*>(rgb_bytes), | 59 reinterpret_cast<char*>(rgb_bytes.get()), |
| 53 static_cast<int>(size_of_rgb))); | 60 static_cast<int>(kRGBSize))); |
| 54 | 61 |
| 55 // Convert a frame of YUV to 32 bit ARGB. | 62 // Convert a frame of YUV to 32 bit ARGB. |
| 56 const size_t size_of_rgb_converted = kWidth * kHeight * kBpp; | 63 media::ConvertYV12ToRGB32(yuv_bytes.get(), // Y |
| 57 uint8* rgb_converted_bytes = new uint8[size_of_rgb_converted]; | 64 yuv_bytes.get() + kWidth * kHeight, // U |
| 58 | 65 yuv_bytes.get() + kWidth * kHeight * 5 / 4, // V |
| 59 media::ConvertYV12ToRGB32(yuv_bytes, // Y plane | 66 rgb_converted_bytes.get(), // RGB output |
| 60 yuv_bytes + kWidth * kHeight, // U plane | |
| 61 yuv_bytes + kWidth * kHeight * 5 / 4, // V plane | |
| 62 rgb_converted_bytes, // Rgb output | |
| 63 kWidth, kHeight, // Dimensions | 67 kWidth, kHeight, // Dimensions |
| 64 kWidth, // YStride | 68 kWidth, // YStride |
| 65 kWidth / 2, // UvStride | 69 kWidth / 2, // UVStride |
| 66 kWidth * kBpp); // RgbStride | 70 kWidth * kBpp); // RGBStride |
| 67 | 71 |
| 68 // Compare converted YUV to reference conversion file. | 72 // Compare converted YUV to reference conversion file. |
| 69 int rgb_diff = memcmp(rgb_converted_bytes, rgb_bytes, size_of_rgb); | 73 int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); |
| 70 | 74 |
| 71 EXPECT_EQ(rgb_diff, 0); | 75 EXPECT_EQ(rgb_diff, 0); |
| 72 } | 76 } |
| 73 | 77 |
| 74 TEST(YV16ConvertTest, Basic) { | 78 TEST(YUVConvertTest, YV16) { |
| 79 // Allocate all surfaces. |
| 80 scoped_array<uint8> yuv_bytes(new uint8[kYUV16Size]); |
| 81 scoped_array<uint8> rgb_bytes(new uint8[kRGBSize]); |
| 82 scoped_array<uint8> rgb_converted_bytes(new uint8[kRGBSizeConverted]); |
| 83 |
| 75 // Read YV16 reference data from file. | 84 // Read YV16 reference data from file. |
| 76 FilePath yuv_url; | 85 FilePath yuv_url; |
| 77 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); | 86 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url)); |
| 78 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) | 87 yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media")) |
| 79 .Append(FILE_PATH_LITERAL("test")) | 88 .Append(FILE_PATH_LITERAL("test")) |
| 80 .Append(FILE_PATH_LITERAL("data")) | 89 .Append(FILE_PATH_LITERAL("data")) |
| 81 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.yuv")); | 90 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.yuv")); |
| 82 const size_t size_of_yuv = kWidth * kHeight * 16 / 8; // 16 bpp. | 91 EXPECT_EQ(static_cast<int>(kYUV16Size), |
| 83 uint8* yuv_bytes = new uint8[size_of_yuv]; | |
| 84 EXPECT_EQ(static_cast<int>(size_of_yuv), | |
| 85 file_util::ReadFile(yuv_url, | 92 file_util::ReadFile(yuv_url, |
| 86 reinterpret_cast<char*>(yuv_bytes), | 93 reinterpret_cast<char*>(yuv_bytes.get()), |
| 87 static_cast<int>(size_of_yuv))); | 94 static_cast<int>(kYUV16Size))); |
| 88 | 95 |
| 89 // Read RGB reference data from file. | 96 // Read RGB reference data from file. |
| 90 FilePath rgb_url; | 97 FilePath rgb_url; |
| 91 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url)); | 98 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url)); |
| 92 rgb_url = rgb_url.Append(FILE_PATH_LITERAL("media")) | 99 rgb_url = rgb_url.Append(FILE_PATH_LITERAL("media")) |
| 93 .Append(FILE_PATH_LITERAL("test")) | 100 .Append(FILE_PATH_LITERAL("test")) |
| 94 .Append(FILE_PATH_LITERAL("data")) | 101 .Append(FILE_PATH_LITERAL("data")) |
| 95 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.rgb")); | 102 .Append(FILE_PATH_LITERAL("bali.yv16.640_360.rgb")); |
| 96 const size_t size_of_rgb = kWidth * kHeight * kBpp; | 103 EXPECT_EQ(static_cast<int>(kRGBSize), |
| 97 uint8* rgb_bytes = new uint8[size_of_rgb]; | |
| 98 EXPECT_EQ(static_cast<int>(size_of_rgb), | |
| 99 file_util::ReadFile(rgb_url, | 104 file_util::ReadFile(rgb_url, |
| 100 reinterpret_cast<char*>(rgb_bytes), | 105 reinterpret_cast<char*>(rgb_bytes.get()), |
| 101 static_cast<int>(size_of_rgb))); | 106 static_cast<int>(kRGBSize))); |
| 102 | 107 |
| 103 // Convert a frame of YUV to 32 bit ARGB. | 108 // Convert a frame of YUV to 32 bit ARGB. |
| 104 const size_t size_of_rgb_converted = kWidth * kHeight * kBpp; | 109 media::ConvertYV16ToRGB32(yuv_bytes.get(), // Y |
| 105 uint8* rgb_converted_bytes = new uint8[size_of_rgb_converted]; | 110 yuv_bytes.get() + kWidth * kHeight, // U |
| 106 | 111 yuv_bytes.get() + kWidth * kHeight * 3 / 2, // V |
| 107 media::ConvertYV16ToRGB32(yuv_bytes, // Y plane | 112 rgb_converted_bytes.get(), // RGB output |
| 108 yuv_bytes + kWidth * kHeight, // U plane | |
| 109 yuv_bytes + kWidth * kHeight * 3 / 2, // V plane | |
| 110 rgb_converted_bytes, // Rgb output | |
| 111 kWidth, kHeight, // Dimensions | 113 kWidth, kHeight, // Dimensions |
| 112 kWidth, // YStride | 114 kWidth, // YStride |
| 113 kWidth / 2, // UvStride | 115 kWidth / 2, // UVStride |
| 114 kWidth * kBpp); // RgbStride | 116 kWidth * kBpp); // RGBStride |
| 115 | 117 |
| 116 // Compare converted YUV to reference conversion file. | 118 // Compare converted YUV to reference conversion file. |
| 117 int rgb_diff = memcmp(rgb_converted_bytes, rgb_bytes, size_of_rgb); | 119 int rgb_diff = memcmp(rgb_converted_bytes.get(), rgb_bytes.get(), kRGBSize); |
| 118 | 120 |
| 119 EXPECT_EQ(rgb_diff, 0); | 121 EXPECT_EQ(rgb_diff, 0); |
| 120 } | 122 } |
| OLD | NEW |