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

Unified 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: rebase+revise due to parser cl Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc
diff --git a/content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc b/content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35f63a63d919a8a3954a20da6781228a04e22d93
--- /dev/null
+++ b/content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc
@@ -0,0 +1,143 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+// This has to be included first.
+// See http://code.google.com/p/googletest/issues/detail?id=371
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "base/at_exit.h"
+#include "base/bind.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/md5.h"
+#include "base/path_service.h"
+#include "base/strings/string_piece.h"
+#include "content/common/gpu/media/vaapi_jpeg_decoder.h"
+
+namespace content {
+namespace {
+
+base::FilePath GetDataDir() {
+ base::FilePath data_dir;
+ PathService::Get(base::DIR_SOURCE_ROOT, &data_dir);
+ 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.
+}
+
+void LogOnError(VaapiJpegDecoder::DecodeStatus error) {
+ LOG(FATAL) << "Oh noes! Decoder failed: " << error;
+}
+
+class VaapiJpegDecoderTest : public ::testing::Test {
+ protected:
+ VaapiJpegDecoderTest() : x_display_(nullptr) {}
+
+ void SetUp() override {
+ 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.
+ ASSERT_TRUE(x_display_);
+
+ base::Closure report_error_cb =
+ base::Bind(&LogOnError, VaapiJpegDecoder::VAAPI_ERROR);
+ wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode, media::MJPEGPROFILE,
+ x_display_, report_error_cb);
+ 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.
+ decoder_.reset(
+ new VaapiJpegDecoder(wrapper_.get(), base::Bind(&LogOnError)));
+ }
+
+ void TearDown() override {
+ decoder_.reset();
+ wrapper_.reset();
+
+ if (x_display_) {
+ XCloseDisplay(x_display_);
+ }
+ }
+
+ VaapiJpegDecoder::DecodeStatus RunDecode(const base::StringPiece& data,
+ std::string& md5sum);
+
+ private:
+ scoped_ptr<VaapiWrapper> wrapper_;
+ scoped_ptr<VaapiJpegDecoder> decoder_;
+
+ // 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.
+ Display* x_display_;
+};
+
+VaapiJpegDecoder::DecodeStatus VaapiJpegDecoderTest::RunDecode(
+ const base::StringPiece& data,
+ 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.
+ gfx::Size size;
+ VASurfaceID surface_id;
+ VaapiJpegDecoder::DecodeStatus status =
+ decoder_->Decode(reinterpret_cast<const uint8*>(data.data()), data.size(),
+ &size, &surface_id);
+
+ if (status != VaapiJpegDecoder::SUCCESS) {
+ LOG(ERROR) << "Decode failed";
+ return status;
+ }
+
+ VAImage image;
+ VAImageFormat format;
+ 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
+ memset(&image, 0, sizeof(image));
+ memset(&format, 0, sizeof(format));
+ format.fourcc = kI420_fourcc;
+ format.byte_order = VA_LSB_FIRST;
+ format.bits_per_pixel = 12;
+
+ void* mem;
+ if (!wrapper_->GetVaImageWithFormat(surface_id, &format, size, &image,
+ &mem)) {
+ LOG(ERROR) << "Cannot get VAImage";
+ return VaapiJpegDecoder::VAAPI_ERROR;
+ }
+ EXPECT_EQ(kI420_fourcc, image.format.fourcc);
+
+ base::StringPiece result(reinterpret_cast<const char*>(mem),
+ size.width() * size.height() * 2);
+ md5sum = base::MD5String(result);
+
+ 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.
+
+ return VaapiJpegDecoder::SUCCESS;
+}
+
+TEST_F(VaapiJpegDecoderTest, DecodeSuccess) {
+ 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.
+
+ std::string data;
+ ASSERT_TRUE(base::ReadFileToString(input_file, &data))
+ << "failed to read input data from " << input_file.value();
+
+ std::string actual_md5sum;
+ EXPECT_EQ(VaapiJpegDecoder::SUCCESS, RunDecode(data, actual_md5sum));
+ EXPECT_EQ("451f28cc874a2206fc5c5a9213b212bd", actual_md5sum);
wuchengli 2015/01/12 09:08:53 Make this a constant.
kcwu 2015/01/16 15:12:55 Done.
+}
+
+TEST_F(VaapiJpegDecoderTest, DecodeFail) {
+ base::FilePath input_file = GetDataDir().AppendASCII("pixel-1280x720.jpg");
+
+ std::string data;
+ ASSERT_TRUE(base::ReadFileToString(input_file, &data))
+ << "failed to read input data from " << input_file.value();
+
+ // 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.
+ data[0] = 0x1;
+
+ std::string actual_md5sum;
+ EXPECT_EQ(VaapiJpegDecoder::PARSE_ERROR, RunDecode(data, actual_md5sum));
+}
+
+} // namespace
+} // namespace content
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ base::AtExitManager exit_manager;
+ return RUN_ALL_TESTS();
+}

Powered by Google App Engine
This is Rietveld 408576698