Commit 84bfafcf authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu VDA unittest: Refactor thumbnail validity check part

Move Convert from RGBA to RGB part into helper files.
Change the function to read known md5s and use base::ContainsValue to verify it.

BUG=chromium:834170
TEST=VDA unittest on eve and kevin
TEST=VDA unittest on non-Chrome OS platforms in CQ.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ic965ee1668af67ecd04956bc89a29bf7a7de5f84
Reviewed-on: https://chromium-review.googlesource.com/1025535
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarPawel Osciak <posciak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555262}
parent 11e04d40
......@@ -26,7 +26,7 @@ namespace media {
namespace test {
namespace {
const int kMD5StringLength = 32;
const size_t kMD5StringLength = 32;
} // namespace
VideoDecodeAcceleratorTestEnvironment::VideoDecodeAcceleratorTestEnvironment(
......@@ -236,14 +236,16 @@ bool EncodedDataHelper::HasConfigInfo(const uint8_t* data,
}
// Read in golden MD5s for the thumbnailed rendering of this video
void ReadGoldenThumbnailMD5s(const base::FilePath& md5_file_path,
std::vector<std::string>* md5_strings) {
std::vector<std::string> ReadGoldenThumbnailMD5s(
const base::FilePath& md5_file_path) {
std::vector<std::string> golden_md5s;
std::vector<std::string> md5_strings;
std::string all_md5s;
base::ReadFileToString(md5_file_path, &all_md5s);
*md5_strings = base::SplitString(all_md5s, "\n", base::TRIM_WHITESPACE,
md5_strings = base::SplitString(all_md5s, "\n", base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
// Check these are legitimate MD5s.
for (const std::string& md5_string : *md5_strings) {
for (const std::string& md5_string : md5_strings) {
// Ignore the empty string added by SplitString
if (!md5_string.length())
continue;
......@@ -251,16 +253,33 @@ void ReadGoldenThumbnailMD5s(const base::FilePath& md5_file_path,
if (md5_string.at(0) == '#')
continue;
LOG_IF(ERROR, static_cast<int>(md5_string.length()) != kMD5StringLength)
<< "MD5 length error: " << md5_string;
bool valid_length = md5_string.length() == kMD5StringLength;
LOG_IF(ERROR, !valid_length) << "MD5 length error: " << md5_string;
bool hex_only = std::count_if(md5_string.begin(), md5_string.end(),
isxdigit) == kMD5StringLength;
LOG_IF(ERROR, !hex_only) << "MD5 includes non-hex char: " << md5_string;
if (valid_length && hex_only)
golden_md5s.push_back(md5_string);
}
LOG_IF(ERROR, md5_strings->empty())
LOG_IF(ERROR, md5_strings.empty())
<< " MD5 checksum file (" << md5_file_path.MaybeAsASCII()
<< ") missing or empty.";
return golden_md5s;
}
bool ConvertRGBAToRGB(const std::vector<unsigned char>& rgba,
std::vector<unsigned char>* rgb) {
size_t num_pixels = rgba.size() / 4;
rgb->resize(num_pixels * 3);
// Drop the alpha channel, but check as we go that it is all 0xff.
bool solid = true;
for (size_t i = 0; i < num_pixels; i++) {
(*rgb)[3 * i] = rgba[4 * i];
(*rgb)[3 * i + 1] = rgba[4 * i + 1];
(*rgb)[3 * i + 2] = rgba[4 * i + 2];
solid = solid && (rgba[4 * i + 3] == 0xff);
}
return solid;
}
} // namespace test
} // namespace media
......@@ -119,8 +119,14 @@ class EncodedDataHelper {
};
// Read in golden MD5s for the thumbnailed rendering of this video
void ReadGoldenThumbnailMD5s(const base::FilePath& md5_file_path,
std::vector<std::string>* md5_strings);
std::vector<std::string> ReadGoldenThumbnailMD5s(
const base::FilePath& md5_file_path);
// Convert from RGBA to RGB.
// Return false if any alpha channel is not 0xff, otherwise true.
bool ConvertRGBAToRGB(const std::vector<unsigned char>& rgba,
std::vector<unsigned char>* rgb);
} // namespace test
} // namespace media
#endif // MEDIA_GPU_TEST_VIDEO_DECODE_ACCELERATOR_UNITTEST_HELPERS_H_
......@@ -1251,32 +1251,15 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
done.Wait();
std::vector<unsigned char> rgb;
size_t num_pixels = rgba.size() / 4;
rgb.resize(num_pixels * 3);
// Drop the alpha channel, but check as we go that it is all 0xff.
bool solid = true;
unsigned char* rgb_ptr = &rgb[0];
unsigned char* rgba_ptr = &rgba[0];
for (size_t i = 0; i < num_pixels; i++) {
*rgb_ptr++ = *rgba_ptr++;
*rgb_ptr++ = *rgba_ptr++;
*rgb_ptr++ = *rgba_ptr++;
solid = solid && (*rgba_ptr == 0xff);
rgba_ptr++;
}
EXPECT_EQ(solid, true) << "RGBA frame had incorrect alpha";
EXPECT_EQ(media::test::ConvertRGBAToRGB(rgba, &rgb), true)
<< "RGBA frame had incorrect alpha";
std::vector<std::string> golden_md5s;
std::string md5_string = base::MD5String(
base::StringPiece(reinterpret_cast<char*>(&rgb[0]), rgb.size()));
base::FilePath filepath(test_video_files_[0]->file_name);
media::test::ReadGoldenThumbnailMD5s(
filepath.AddExtension(FILE_PATH_LITERAL(".md5")), &golden_md5s);
std::vector<std::string>::iterator match =
find(golden_md5s.begin(), golden_md5s.end(), md5_string);
if (match == golden_md5s.end()) {
auto golden_md5s = media::test::ReadGoldenThumbnailMD5s(
filepath.AddExtension(FILE_PATH_LITERAL(".md5")));
if (!base::ContainsValue(golden_md5s, md5_string)) {
// Convert raw RGBA into PNG for export.
std::vector<unsigned char> png;
gfx::PNGCodec::Encode(&rgba[0], gfx::PNGCodec::FORMAT_RGBA,
......@@ -1284,9 +1267,6 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
kThumbnailsPageSize.width() * 4, true,
std::vector<gfx::PNGCodec::Comment>(), &png);
LOG(ERROR) << "Unknown thumbnails MD5: " << md5_string;
base::FilePath filepath(test_video_files_[0]->file_name);
if (!g_thumbnail_output_dir.empty() &&
base::DirectoryExists(g_thumbnail_output_dir)) {
// Write bad thumbnails image to where --thumbnail_output_dir assigned.
......@@ -1298,15 +1278,15 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
// directory.
filepath = GetTestDataFile(filepath);
}
filepath = filepath.AddExtension(FILE_PATH_LITERAL(".bad_thumbnails"));
filepath = filepath.AddExtension(FILE_PATH_LITERAL(".png"));
filepath =
filepath.AddExtension(FILE_PATH_LITERAL(".bad_thumbnails.png"));
LOG(INFO) << "Write bad thumbnails image to: "
<< filepath.value().c_str();
int num_bytes = base::WriteFile(
filepath, reinterpret_cast<char*>(&png[0]), png.size());
EXPECT_EQ(num_bytes, static_cast<int>(png.size()));
LOG(FATAL) << "Unknown thumbnails MD5: " << md5_string;
}
EXPECT_NE(match, golden_md5s.end());
}
// Output the frame delivery time to file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment