Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 | |
| 20 namespace content { | |
| 21 namespace { | |
| 22 | |
| 23 base::FilePath GetDataDir() { | |
| 24 base::FilePath data_dir; | |
| 25 PathService::Get(base::DIR_SOURCE_ROOT, &data_dir); | |
| 26 return data_dir.AppendASCII("media").AppendASCII("test").AppendASCII("data"); | |
|
wuchengli
2015/01/12 09:08:52
pixel-1280x720.bin can be removed from this CL sin
kcwu
2015/01/16 15:12:55
Done.
| |
| 27 } | |
| 28 | |
| 29 void LogOnError(VaapiJpegDecoder::DecodeStatus error) { | |
| 30 LOG(FATAL) << "Oh noes! Decoder failed: " << error; | |
| 31 } | |
| 32 | |
| 33 class VaapiJpegDecoderTest : public ::testing::Test { | |
| 34 protected: | |
| 35 VaapiJpegDecoderTest() : x_display_(nullptr) {} | |
| 36 | |
| 37 void SetUp() override { | |
| 38 x_display_ = XOpenDisplay(nullptr); | |
|
wuchengli
2015/01/12 09:08:52
How does this work with freon?
kcwu
2015/01/16 15:12:55
Done.
| |
| 39 ASSERT_TRUE(x_display_); | |
| 40 | |
| 41 base::Closure report_error_cb = | |
| 42 base::Bind(&LogOnError, VaapiJpegDecoder::VAAPI_ERROR); | |
| 43 wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode, media::MJPEGPROFILE, | |
| 44 x_display_, report_error_cb); | |
| 45 ASSERT_TRUE(wrapper_.get()); | |
|
Owen Lin
2015/01/13 06:17:58
Do we need the get()?
kcwu
2015/01/16 15:12:55
Done.
| |
| 46 decoder_.reset( | |
| 47 new VaapiJpegDecoder(wrapper_.get(), base::Bind(&LogOnError))); | |
| 48 } | |
| 49 | |
| 50 void TearDown() override { | |
| 51 decoder_.reset(); | |
| 52 wrapper_.reset(); | |
| 53 | |
| 54 if (x_display_) { | |
| 55 XCloseDisplay(x_display_); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 VaapiJpegDecoder::DecodeStatus RunDecode(const base::StringPiece& data, | |
| 60 std::string& md5sum); | |
| 61 | |
| 62 private: | |
| 63 scoped_ptr<VaapiWrapper> wrapper_; | |
| 64 scoped_ptr<VaapiJpegDecoder> decoder_; | |
| 65 | |
| 66 // x_display need to be initialized and possibly freed manually. | |
|
wuchengli
2015/01/12 09:08:52
possibly is vague. Should we free manually or not?
kcwu
2015/01/16 15:12:55
Done.
| |
| 67 Display* x_display_; | |
| 68 }; | |
| 69 | |
| 70 VaapiJpegDecoder::DecodeStatus VaapiJpegDecoderTest::RunDecode( | |
| 71 const base::StringPiece& data, | |
| 72 std::string& md5sum) { | |
|
Owen Lin
2015/01/13 06:17:58
Why not just pass the expected md5sum and rename i
kcwu
2015/01/16 15:12:56
Done.
| |
| 73 gfx::Size size; | |
| 74 VASurfaceID surface_id; | |
| 75 VaapiJpegDecoder::DecodeStatus status = | |
| 76 decoder_->Decode(reinterpret_cast<const uint8*>(data.data()), data.size(), | |
| 77 &size, &surface_id); | |
| 78 | |
| 79 if (status != VaapiJpegDecoder::SUCCESS) { | |
| 80 LOG(ERROR) << "Decode failed"; | |
| 81 return status; | |
| 82 } | |
| 83 | |
| 84 VAImage image; | |
| 85 VAImageFormat format; | |
| 86 uint32_t kI420_fourcc = 'I' | '4' << 8 | '2' << 16 | '0' << 24; | |
|
wuchengli
2015/01/12 09:08:53
VA_FOURCC_IYUV? I420 is IYUV.
kcwu
2015/01/16 15:12:55
No. vaCreateImage failed with VA_FOURCC_IYUV
| |
| 87 memset(&image, 0, sizeof(image)); | |
| 88 memset(&format, 0, sizeof(format)); | |
| 89 format.fourcc = kI420_fourcc; | |
| 90 format.byte_order = VA_LSB_FIRST; | |
| 91 format.bits_per_pixel = 12; | |
| 92 | |
| 93 void* mem; | |
| 94 if (!wrapper_->GetVaImageWithFormat(surface_id, &format, size, &image, | |
| 95 &mem)) { | |
| 96 LOG(ERROR) << "Cannot get VAImage"; | |
| 97 return VaapiJpegDecoder::VAAPI_ERROR; | |
| 98 } | |
| 99 EXPECT_EQ(kI420_fourcc, image.format.fourcc); | |
| 100 | |
| 101 base::StringPiece result(reinterpret_cast<const char*>(mem), | |
| 102 size.width() * size.height() * 2); | |
| 103 md5sum = base::MD5String(result); | |
| 104 | |
| 105 wrapper_->ReturnVaImageForTesting(&image); | |
|
Owen Lin
2015/01/13 06:17:58
Why there is no DecodeDone() ? Is this because it
kcwu
2015/01/16 15:12:55
Yes. I added DecodeDone anyway.
| |
| 106 | |
| 107 return VaapiJpegDecoder::SUCCESS; | |
| 108 } | |
| 109 | |
| 110 TEST_F(VaapiJpegDecoderTest, DecodeSuccess) { | |
| 111 base::FilePath input_file = GetDataDir().AppendASCII("pixel-1280x720.jpg"); | |
|
wuchengli
2015/01/12 09:08:52
Make this a constant.
kcwu
2015/01/16 15:12:55
Done.
| |
| 112 | |
| 113 std::string data; | |
| 114 ASSERT_TRUE(base::ReadFileToString(input_file, &data)) | |
| 115 << "failed to read input data from " << input_file.value(); | |
| 116 | |
| 117 std::string actual_md5sum; | |
| 118 EXPECT_EQ(VaapiJpegDecoder::SUCCESS, RunDecode(data, actual_md5sum)); | |
| 119 EXPECT_EQ("451f28cc874a2206fc5c5a9213b212bd", actual_md5sum); | |
|
wuchengli
2015/01/12 09:08:53
Make this a constant.
kcwu
2015/01/16 15:12:55
Done.
| |
| 120 } | |
| 121 | |
| 122 TEST_F(VaapiJpegDecoderTest, DecodeFail) { | |
| 123 base::FilePath input_file = GetDataDir().AppendASCII("pixel-1280x720.jpg"); | |
| 124 | |
| 125 std::string data; | |
| 126 ASSERT_TRUE(base::ReadFileToString(input_file, &data)) | |
| 127 << "failed to read input data from " << input_file.value(); | |
| 128 | |
| 129 // make data corrupted to simulate parse failure | |
|
wuchengli
2015/01/12 09:08:53
Capitalize the first word and add period.
kcwu
2015/01/16 15:12:55
Done.
| |
| 130 data[0] = 0x1; | |
| 131 | |
| 132 std::string actual_md5sum; | |
| 133 EXPECT_EQ(VaapiJpegDecoder::PARSE_ERROR, RunDecode(data, actual_md5sum)); | |
| 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 |