Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc

Issue 825843002: Add JPEG decoder for VAAPI JPEG decode acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mjpeg-vaapi-jpeg-parser
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/test_data_util.h"
20 #include "media/base/video_frame.h"
21 #include "media/filters/jpeg_parser.h"
22
23 namespace content {
24 namespace {
25
26 const char* kTestFilename = "pixel-1280x720.jpg";
27 const char* kExpectedMd5Sum = "6e9e1716073c9a9a1282e3f0e0dab743";
28
29 void LogOnError() {
30 LOG(FATAL) << "Oh noes! Decoder failed";
31 }
32
33 class VaapiJpegDecoderTest : public ::testing::Test {
34 protected:
35 VaapiJpegDecoderTest() {}
36
37 void SetUp() override {
38 base::Closure report_error_cb = base::Bind(&LogOnError);
39 wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode,
40 VAProfileJPEGBaseline, report_error_cb);
41 ASSERT_TRUE(wrapper_);
42
43 base::FilePath input_file = media::GetTestDataFilePath(kTestFilename);
44
45 ASSERT_TRUE(base::ReadFileToString(input_file, &jpeg_data_))
46 << "failed to read input data from " << input_file.value();
47 }
48
49 void TearDown() override { wrapper_.reset(); }
50
51 bool VerifyDecode(const media::JpegParseResult& parse_result,
52 const std::string& md5sum);
53
54 protected:
55 scoped_ptr<VaapiWrapper> wrapper_;
56 std::string jpeg_data_;
57 };
58
59 bool VaapiJpegDecoderTest::VerifyDecode(
60 const media::JpegParseResult& parse_result,
61 const std::string& expected_md5sum) {
62 gfx::Size size(parse_result.frame_header.visible_width,
63 parse_result.frame_header.visible_height);
64
65 std::vector<VASurfaceID> va_surfaces;
66 if (!wrapper_->CreateSurfaces(size, 1, &va_surfaces))
67 return false;
68
69 if (!VaapiJpegDecoder::Decode(wrapper_.get(), parse_result, va_surfaces[0])) {
70 LOG(ERROR) << "Decode failed";
71 return false;
72 }
73
74 VAImage image;
75 VAImageFormat format;
76 const uint32_t kI420Fourcc = VA_FOURCC('I', '4', '2', '0');
77 memset(&image, 0, sizeof(image));
78 memset(&format, 0, sizeof(format));
79 format.fourcc = kI420Fourcc;
80 format.byte_order = VA_LSB_FIRST;
81 format.bits_per_pixel = 12; // 12 for I420
82
83 void* mem;
84 if (!wrapper_->GetVaImage(va_surfaces[0], &format, size, &image, &mem)) {
85 LOG(ERROR) << "Cannot get VAImage";
86 return false;
87 }
88 EXPECT_EQ(kI420Fourcc, image.format.fourcc);
89
90 base::StringPiece result(
91 reinterpret_cast<const char*>(mem),
92 media::VideoFrame::AllocationSize(media::VideoFrame::I420, size));
93 EXPECT_EQ(expected_md5sum, base::MD5String(result));
94
95 wrapper_->ReturnVaImage(&image);
96
97 return true;
98 }
99
100 TEST_F(VaapiJpegDecoderTest, DecodeSuccess) {
101 media::JpegParseResult parse_result;
102 ASSERT_TRUE(media::ParseJpegPicture(
103 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(),
104 &parse_result));
105
106 EXPECT_TRUE(VerifyDecode(parse_result, kExpectedMd5Sum));
107 }
108
109 TEST_F(VaapiJpegDecoderTest, DecodeFail) {
110 media::JpegParseResult parse_result;
111 ASSERT_TRUE(media::ParseJpegPicture(
112 reinterpret_cast<const uint8_t*>(jpeg_data_.data()), jpeg_data_.size(),
113 &parse_result));
114
115 // Not supported by VAAPI.
116 parse_result.frame_header.num_components = 1;
117 parse_result.scan.num_components = 1;
118
119 gfx::Size size(parse_result.frame_header.visible_width,
120 parse_result.frame_header.visible_height);
121
122 std::vector<VASurfaceID> va_surfaces;
123 ASSERT_TRUE(wrapper_->CreateSurfaces(size, 1, &va_surfaces));
124
125 EXPECT_FALSE(
126 VaapiJpegDecoder::Decode(wrapper_.get(), parse_result, va_surfaces[0]));
127 }
128
129 } // namespace
130 } // namespace content
131
132 int main(int argc, char** argv) {
133 testing::InitGoogleTest(&argc, argv);
134 base::AtExitManager exit_manager;
135 return RUN_ALL_TESTS();
136 }
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_jpeg_decoder.cc ('k') | content/common/gpu/media/vaapi_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698