Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 // This has to be included first. | |
| 8 // See http://code.google.com/p/googletest/issues/detail?id=371 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 #include "base/at_exit.h" | |
| 12 #include "base/bind.h" | |
| 13 #include "base/files/file_util.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/md5.h" | |
| 16 #include "base/path_service.h" | |
| 17 #include "base/strings/string_piece.h" | |
| 18 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" | |
| 19 #include "media/base/video_frame.h" | |
| 20 #include "media/filters/jpeg_parser.h" | |
| 21 | |
| 22 namespace content { | |
| 23 namespace { | |
| 24 | |
| 25 const char* kTestFilename = "pixel-1280x720.jpg"; | |
| 26 const char* kExpectedMd5Sum = "6e9e1716073c9a9a1282e3f0e0dab743"; | |
| 27 | |
| 28 base::FilePath GetDataDir() { | |
| 29 base::FilePath data_dir; | |
| 30 PathService::Get(base::DIR_SOURCE_ROOT, &data_dir); | |
| 31 return data_dir.AppendASCII("media").AppendASCII("test").AppendASCII("data"); | |
| 32 } | |
| 33 | |
| 34 void LogOnError() { | |
| 35 LOG(FATAL) << "Oh noes! Decoder failed"; | |
| 36 } | |
| 37 | |
| 38 class VaapiJpegDecoderTest : public ::testing::Test { | |
| 39 protected: | |
| 40 VaapiJpegDecoderTest() {} | |
| 41 | |
| 42 void SetUp() override { | |
| 43 base::Closure report_error_cb = base::Bind(&LogOnError); | |
| 44 wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode, | |
| 45 VAProfileJPEGBaseline, report_error_cb); | |
| 46 ASSERT_TRUE(wrapper_); | |
| 47 | |
| 48 base::FilePath input_file = GetDataDir().AppendASCII(kTestFilename); | |
| 49 | |
| 50 ASSERT_TRUE(base::ReadFileToString(input_file, &jpeg_data_)) | |
| 51 << "failed to read input data from " << input_file.value(); | |
| 52 } | |
| 53 | |
| 54 void TearDown() override { wrapper_.reset(); } | |
| 55 | |
| 56 bool VerifyDecode(const media::JpegParseResult& parse_result, | |
| 57 const std::string& md5sum); | |
| 58 | |
| 59 protected: | |
| 60 scoped_ptr<VaapiWrapper> wrapper_; | |
| 61 std::string jpeg_data_; | |
| 62 }; | |
| 63 | |
| 64 bool VaapiJpegDecoderTest::VerifyDecode( | |
| 65 const media::JpegParseResult& parse_result, | |
| 66 const std::string& expected_md5sum) { | |
| 67 gfx::Size size(parse_result.frame_header.visible_width, | |
| 68 parse_result.frame_header.visible_height); | |
| 69 | |
| 70 std::vector<VASurfaceID> va_surfaces; | |
| 71 if (!wrapper_->CreateSurfaces(size, 1, &va_surfaces)) | |
| 72 return false; | |
| 73 | |
| 74 if (!VaapiJpegDecoder::Decode(wrapper_.get(), parse_result, va_surfaces[0])) { | |
| 75 LOG(ERROR) << "Decode failed"; | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 VAImage image; | |
| 80 VAImageFormat format; | |
| 81 const uint32_t kI420_fourcc = VA_FOURCC('I', '4', '2', '0'); | |
|
wuchengli
2015/01/21 13:19:58
s/kI420_fourcc/kI420Fourcc/
kcwu
2015/01/23 07:51:33
Done.
| |
| 82 memset(&image, 0, sizeof(image)); | |
| 83 memset(&format, 0, sizeof(format)); | |
| 84 format.fourcc = kI420_fourcc; | |
| 85 format.byte_order = VA_LSB_FIRST; | |
| 86 format.bits_per_pixel = 12; // 12 for I420 | |
| 87 | |
| 88 void* mem; | |
| 89 if (!wrapper_->GetVaImage(va_surfaces[0], &format, size, &image, &mem)) { | |
| 90 LOG(ERROR) << "Cannot get VAImage"; | |
| 91 return false; | |
| 92 } | |
| 93 EXPECT_EQ(kI420_fourcc, image.format.fourcc); | |
| 94 | |
| 95 base::StringPiece result( | |
| 96 reinterpret_cast<const char*>(mem), | |
| 97 media::VideoFrame::AllocationSize(media::VideoFrame::I420, size)); | |
| 98 EXPECT_EQ(expected_md5sum, base::MD5String(result)); | |
| 99 | |
| 100 wrapper_->ReturnVaImage(&image); | |
| 101 | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 TEST_F(VaapiJpegDecoderTest, DecodeSuccess) { | |
| 106 media::JpegParseResult parse_result; | |
| 107 ASSERT_TRUE(media::ParseJpegPicture( | |
| 108 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(), | |
| 109 &parse_result)); | |
| 110 | |
| 111 EXPECT_TRUE(VerifyDecode(parse_result, kExpectedMd5Sum)); | |
| 112 } | |
| 113 | |
| 114 TEST_F(VaapiJpegDecoderTest, DecodeFail) { | |
| 115 media::JpegParseResult parse_result; | |
| 116 ASSERT_TRUE(media::ParseJpegPicture( | |
| 117 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(), | |
| 118 &parse_result)); | |
| 119 | |
| 120 // Not supported by VAAPI. | |
| 121 parse_result.frame_header.num_components = 1; | |
| 122 parse_result.scan.num_components = 1; | |
| 123 | |
| 124 gfx::Size size(parse_result.frame_header.visible_width, | |
| 125 parse_result.frame_header.visible_height); | |
| 126 | |
| 127 std::vector<VASurfaceID> va_surfaces; | |
| 128 ASSERT_TRUE(wrapper_->CreateSurfaces(size, 1, &va_surfaces)); | |
| 129 | |
| 130 EXPECT_FALSE( | |
| 131 VaapiJpegDecoder::Decode(wrapper_.get(), parse_result, va_surfaces[0])); | |
| 132 } | |
| 133 | |
| 134 } // namespace | |
| 135 } // namespace content | |
| 136 | |
| 137 int main(int argc, char** argv) { | |
| 138 testing::InitGoogleTest(&argc, argv); | |
| 139 base::AtExitManager exit_manager; | |
| 140 return RUN_ALL_TESTS(); | |
| 141 } | |
| OLD | NEW |