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 <stdint.h> | |
6 #include <string.h> | |
7 | |
8 #include <string> | |
9 | |
10 // This has to be included first. | |
11 // See http://code.google.com/p/googletest/issues/detail?id=371 | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 #include "base/at_exit.h" | |
15 #include "base/bind.h" | |
16 #include "base/files/file_util.h" | |
17 #include "base/logging.h" | |
18 #include "base/md5.h" | |
19 #include "base/path_service.h" | |
20 #include "base/strings/string_piece.h" | |
21 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" | |
22 #include "media/base/test_data_util.h" | |
23 #include "media/base/video_frame.h" | |
24 #include "media/filters/jpeg_parser.h" | |
25 | |
26 namespace content { | |
27 namespace { | |
28 | |
29 const char* kTestFilename = "pixel-1280x720.jpg"; | |
30 const char* kExpectedMd5Sum = "6e9e1716073c9a9a1282e3f0e0dab743"; | |
31 | |
32 void LogOnError() { | |
33 LOG(FATAL) << "Oh noes! Decoder failed"; | |
34 } | |
35 | |
36 class VaapiJpegDecoderTest : public ::testing::Test { | |
37 protected: | |
38 VaapiJpegDecoderTest() {} | |
39 | |
40 void SetUp() override { | |
41 base::Closure report_error_cb = base::Bind(&LogOnError); | |
42 wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode, | |
43 VAProfileJPEGBaseline, report_error_cb); | |
44 ASSERT_TRUE(wrapper_); | |
45 | |
46 base::FilePath input_file = media::GetTestDataFilePath(kTestFilename); | |
47 | |
48 ASSERT_TRUE(base::ReadFileToString(input_file, &jpeg_data_)) | |
49 << "failed to read input data from " << input_file.value(); | |
50 } | |
51 | |
52 void TearDown() override { wrapper_ = nullptr; } | |
53 | |
54 bool VerifyDecode(const media::JpegParseResult& parse_result, | |
55 const std::string& md5sum); | |
56 | |
57 protected: | |
58 scoped_refptr<VaapiWrapper> wrapper_; | |
59 std::string jpeg_data_; | |
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.coded_width, | |
66 parse_result.frame_header.coded_height); | |
67 | |
68 std::vector<VASurfaceID> va_surfaces; | |
69 if (!wrapper_->CreateSurfaces(VA_RT_FORMAT_YUV420, size, 1, &va_surfaces)) | |
70 return false; | |
71 | |
72 if (!VaapiJpegDecoder::Decode(wrapper_.get(), 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 kI420Fourcc = VA_FOURCC('I', '4', '2', '0'); | |
80 memset(&image, 0, sizeof(image)); | |
81 memset(&format, 0, sizeof(format)); | |
82 format.fourcc = kI420Fourcc; | |
83 format.byte_order = VA_LSB_FIRST; | |
84 format.bits_per_pixel = 12; // 12 for I420 | |
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(kI420Fourcc, image.format.fourcc); | |
92 | |
93 base::StringPiece result( | |
94 reinterpret_cast<const char*>(mem), | |
95 media::VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, size)); | |
96 EXPECT_EQ(expected_md5sum, base::MD5String(result)); | |
97 | |
98 wrapper_->ReturnVaImage(&image); | |
99 | |
100 return true; | |
101 } | |
102 | |
103 TEST_F(VaapiJpegDecoderTest, DecodeSuccess) { | |
104 media::JpegParseResult parse_result; | |
105 ASSERT_TRUE(media::ParseJpegPicture( | |
106 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(), | |
107 &parse_result)); | |
108 | |
109 EXPECT_TRUE(VerifyDecode(parse_result, kExpectedMd5Sum)); | |
110 } | |
111 | |
112 TEST_F(VaapiJpegDecoderTest, DecodeFail) { | |
113 media::JpegParseResult parse_result; | |
114 ASSERT_TRUE(media::ParseJpegPicture( | |
115 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(), | |
116 &parse_result)); | |
117 | |
118 // Not supported by VAAPI. | |
119 parse_result.frame_header.num_components = 1; | |
120 parse_result.scan.num_components = 1; | |
121 | |
122 gfx::Size size(parse_result.frame_header.coded_width, | |
123 parse_result.frame_header.coded_height); | |
124 | |
125 std::vector<VASurfaceID> va_surfaces; | |
126 ASSERT_TRUE( | |
127 wrapper_->CreateSurfaces(VA_RT_FORMAT_YUV420, size, 1, &va_surfaces)); | |
128 | |
129 EXPECT_FALSE( | |
130 VaapiJpegDecoder::Decode(wrapper_.get(), parse_result, va_surfaces[0])); | |
131 } | |
132 | |
133 } // namespace | |
134 } // namespace content | |
135 | |
136 int main(int argc, char** argv) { | |
137 testing::InitGoogleTest(&argc, argv); | |
138 base::AtExitManager exit_manager; | |
139 content::VaapiWrapper::PreSandboxInitialization(); | |
140 return RUN_ALL_TESTS(); | |
141 } | |
OLD | NEW |