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

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: 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..b1067c7f80f1e0c239fb716cd3cd6dc5e994d256
--- /dev/null
+++ b/content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc
@@ -0,0 +1,143 @@
+// Copyright 2015 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"
+#include "media/filters/jpeg_parser.h"
+
+namespace content {
+namespace {
+
+const char* kTestFilename = "pixel-1280x720.jpg";
+const char* kExpectedMd5Sum = "451f28cc874a2206fc5c5a9213b212bd";
+
+base::FilePath GetDataDir() {
+ base::FilePath data_dir;
+ PathService::Get(base::DIR_SOURCE_ROOT, &data_dir);
+ return data_dir.AppendASCII("media").AppendASCII("test").AppendASCII("data");
+}
+
+void LogOnError() {
+ LOG(FATAL) << "Oh noes! Decoder failed";
+}
+
+class VaapiJpegDecoderTest : public ::testing::Test {
+ protected:
+ VaapiJpegDecoderTest() {}
+
+ void SetUp() override {
+ base::Closure report_error_cb = base::Bind(&LogOnError);
+ wrapper_ = VaapiWrapper::Create(VaapiWrapper::kDecode,
+ VAProfileJPEGBaseline, report_error_cb);
+ ASSERT_TRUE(wrapper_);
wuchengli 2015/01/20 07:55:53 This should be CHECK. ASSERT_TRUE doesn't fail the
kcwu 2015/01/21 12:23:48 No. CHECK will crash. ASSERT_* will fail the test
+ decoder_.reset(new VaapiJpegDecoder(wrapper_.get()));
+ }
+
+ void TearDown() override {
+ decoder_.reset();
+ wrapper_.reset();
+ }
+
+ bool VerifyDecode(const media::JpegParseResult& parse_result,
+ const std::string& md5sum);
+
+ private:
+ scoped_ptr<VaapiWrapper> wrapper_;
+ scoped_ptr<VaapiJpegDecoder> decoder_;
+};
+
+bool VaapiJpegDecoderTest::VerifyDecode(
+ const media::JpegParseResult& parse_result,
+ const std::string& expected_md5sum) {
+ gfx::Size size(parse_result.frame_header.visible_width,
+ parse_result.frame_header.visible_height);
+
+ std::vector<VASurfaceID> va_surfaces;
+ if (!wrapper_->CreateSurfaces(size, 1, &va_surfaces))
+ return false;
+
+ if (!decoder_->Decode(parse_result, va_surfaces[0])) {
+ LOG(ERROR) << "Decode failed";
+ return false;
+ }
+
+ VAImage image;
+ VAImageFormat format;
+ const uint32_t kI420_fourcc = VA_FOURCC('I', '4', '2', '0');
+ 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;
wuchengli 2015/01/20 07:55:53 We can use this. for (size_t i = 0; i < media::V
kcwu 2015/01/21 12:23:48 I'm wondering should we make it complicated here.
+
+ void* mem;
+ if (!wrapper_->GetVaImage(va_surfaces[0], &format, size, &image, &mem)) {
+ LOG(ERROR) << "Cannot get VAImage";
+ return false;
+ }
+ EXPECT_EQ(kI420_fourcc, image.format.fourcc);
+
+ base::StringPiece result(reinterpret_cast<const char*>(mem),
+ size.width() * size.height() * 2);
wuchengli 2015/01/20 07:55:53 use media::AllocationSize.
kcwu 2015/01/21 12:23:48 Done.
+ EXPECT_EQ(expected_md5sum, base::MD5String(result));
+
+ wrapper_->ReturnVaImage(&image);
+
+ return true;
+}
+
+TEST_F(VaapiJpegDecoderTest, DecodeSuccess) {
+ base::FilePath input_file = GetDataDir().AppendASCII(kTestFilename);
+
+ std::string data;
+ ASSERT_TRUE(base::ReadFileToString(input_file, &data))
+ << "failed to read input data from " << input_file.value();
+
+ media::JpegParseResult parse_result;
+ ASSERT_TRUE(
+ media::ParseJpegPicture(reinterpret_cast<const uint8_t*>(data.data()),
+ data.size(), &parse_result));
+
+ EXPECT_TRUE(VerifyDecode(parse_result, kExpectedMd5Sum));
+}
+
+TEST_F(VaapiJpegDecoderTest, DecodeFail) {
+ base::FilePath input_file = GetDataDir().AppendASCII(kTestFilename);
+
+ std::string data;
+ ASSERT_TRUE(base::ReadFileToString(input_file, &data))
+ << "failed to read input data from " << input_file.value();
wuchengli 2015/01/20 07:55:53 input_file and data creation can be done in SetUp.
kcwu 2015/01/21 12:23:48 Done.
+
+ media::JpegParseResult parse_result;
+ ASSERT_TRUE(
+ media::ParseJpegPicture(reinterpret_cast<const uint8_t*>(data.data()),
+ data.size(), &parse_result));
+
+ // Not supported by VAAPI.
+ parse_result.frame_header.num_components = 1;
+ parse_result.scan.num_components = 1;
+
+ EXPECT_FALSE(VerifyDecode(parse_result, ""));
wuchengli 2015/01/20 07:55:53 This should call wrapper_->CreateSurfaces and deco
kcwu 2015/01/21 12:23:48 Done.
+}
+
+} // 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