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/filters/jpeg_parser.h" |
| 20 |
| 21 namespace content { |
| 22 namespace { |
| 23 |
| 24 const char* kTestFilename = "pixel-1280x720.jpg"; |
| 25 const char* kExpectedMd5Sum = "451f28cc874a2206fc5c5a9213b212bd"; |
| 26 |
| 27 base::FilePath GetDataDir() { |
| 28 base::FilePath data_dir; |
| 29 PathService::Get(base::DIR_SOURCE_ROOT, &data_dir); |
| 30 return data_dir.AppendASCII("media").AppendASCII("test").AppendASCII("data"); |
| 31 } |
| 32 |
| 33 void LogOnError() { |
| 34 LOG(FATAL) << "Oh noes! Decoder failed"; |
| 35 } |
| 36 |
| 37 class VaapiJpegDecoderTest : public ::testing::Test { |
| 38 protected: |
| 39 VaapiJpegDecoderTest() {} |
| 40 |
| 41 void SetUp() override { |
| 42 base::Closure report_error_cb = base::Bind(&LogOnError); |
| 43 wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode, |
| 44 VAProfileJPEGBaseline, report_error_cb); |
| 45 ASSERT_TRUE(wrapper_); |
| 46 decoder_.reset(new VaapiJpegDecoder(wrapper_.get())); |
| 47 } |
| 48 |
| 49 void TearDown() override { |
| 50 decoder_.reset(); |
| 51 wrapper_.reset(); |
| 52 } |
| 53 |
| 54 bool VerifyDecode(const media::JpegParseResult& parse_result, |
| 55 const std::string& md5sum); |
| 56 |
| 57 private: |
| 58 scoped_ptr<VaapiWrapper> wrapper_; |
| 59 scoped_ptr<VaapiJpegDecoder> decoder_; |
| 60 }; |
| 61 |
| 62 bool VaapiJpegDecoderTest::VerifyDecode( |
| 63 const media::JpegParseResult& parse_result, |
| 64 const std::string& expected_md5sum) { |
| 65 gfx::Size size(parse_result.frame_header.visible_width, |
| 66 parse_result.frame_header.visible_height); |
| 67 |
| 68 std::vector<VASurfaceID> va_surfaces; |
| 69 if (!wrapper_->CreateSurfaces(size, 1, &va_surfaces)) |
| 70 return false; |
| 71 |
| 72 if (!decoder_->Decode(parse_result, va_surfaces[0])) { |
| 73 LOG(ERROR) << "Decode failed"; |
| 74 return false; |
| 75 } |
| 76 |
| 77 VAImage image; |
| 78 VAImageFormat format; |
| 79 const uint32_t kI420_fourcc = VA_FOURCC('I', '4', '2', '0'); |
| 80 memset(&image, 0, sizeof(image)); |
| 81 memset(&format, 0, sizeof(format)); |
| 82 format.fourcc = kI420_fourcc; |
| 83 format.byte_order = VA_LSB_FIRST; |
| 84 format.bits_per_pixel = 12; |
| 85 |
| 86 void* mem; |
| 87 if (!wrapper_->GetVaImage(va_surfaces[0], &format, size, &image, &mem)) { |
| 88 LOG(ERROR) << "Cannot get VAImage"; |
| 89 return false; |
| 90 } |
| 91 EXPECT_EQ(kI420_fourcc, image.format.fourcc); |
| 92 |
| 93 base::StringPiece result(reinterpret_cast<const char*>(mem), |
| 94 size.width() * size.height() * 2); |
| 95 EXPECT_EQ(expected_md5sum, base::MD5String(result)); |
| 96 |
| 97 wrapper_->ReturnVaImage(&image); |
| 98 |
| 99 return true; |
| 100 } |
| 101 |
| 102 TEST_F(VaapiJpegDecoderTest, DecodeSuccess) { |
| 103 base::FilePath input_file = GetDataDir().AppendASCII(kTestFilename); |
| 104 |
| 105 std::string data; |
| 106 ASSERT_TRUE(base::ReadFileToString(input_file, &data)) |
| 107 << "failed to read input data from " << input_file.value(); |
| 108 |
| 109 media::JpegParseResult parse_result; |
| 110 ASSERT_TRUE( |
| 111 media::ParseJpegPicture(reinterpret_cast<const uint8_t*>(data.data()), |
| 112 data.size(), &parse_result)); |
| 113 |
| 114 EXPECT_TRUE(VerifyDecode(parse_result, kExpectedMd5Sum)); |
| 115 } |
| 116 |
| 117 TEST_F(VaapiJpegDecoderTest, DecodeFail) { |
| 118 base::FilePath input_file = GetDataDir().AppendASCII(kTestFilename); |
| 119 |
| 120 std::string data; |
| 121 ASSERT_TRUE(base::ReadFileToString(input_file, &data)) |
| 122 << "failed to read input data from " << input_file.value(); |
| 123 |
| 124 media::JpegParseResult parse_result; |
| 125 ASSERT_TRUE( |
| 126 media::ParseJpegPicture(reinterpret_cast<const uint8_t*>(data.data()), |
| 127 data.size(), &parse_result)); |
| 128 |
| 129 // Not supported by VAAPI. |
| 130 parse_result.frame_header.num_components = 1; |
| 131 parse_result.scan.num_components = 1; |
| 132 |
| 133 EXPECT_FALSE(VerifyDecode(parse_result, "")); |
| 134 } |
| 135 |
| 136 } // namespace |
| 137 } // namespace content |
| 138 |
| 139 int main(int argc, char** argv) { |
| 140 testing::InitGoogleTest(&argc, argv); |
| 141 base::AtExitManager exit_manager; |
| 142 return RUN_ALL_TESTS(); |
| 143 } |
OLD | NEW |