2013-07-31 09:46:58 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vp9/decoder/vp9_thread.h"
|
|
|
|
|
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2013-08-01 03:15:10 +04:00
|
|
|
#include "test/codec_factory.h"
|
|
|
|
#include "test/decode_test_driver.h"
|
|
|
|
#include "test/md5_helper.h"
|
|
|
|
#include "test/webm_video_source.h"
|
2013-07-31 09:46:58 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
class VP9WorkerThreadTest : public ::testing::TestWithParam<bool> {
|
2013-07-31 09:46:58 +04:00
|
|
|
protected:
|
|
|
|
virtual ~VP9WorkerThreadTest() {}
|
|
|
|
virtual void SetUp() {
|
|
|
|
vp9_worker_init(&worker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
vp9_worker_end(&worker_);
|
|
|
|
}
|
|
|
|
|
|
|
|
VP9Worker worker_;
|
|
|
|
};
|
|
|
|
|
|
|
|
int ThreadHook(void* data, void* return_value) {
|
|
|
|
int* const hook_data = reinterpret_cast<int*>(data);
|
|
|
|
*hook_data = 5;
|
|
|
|
return *reinterpret_cast<int*>(return_value);
|
|
|
|
}
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
TEST_P(VP9WorkerThreadTest, HookSuccess) {
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_sync(&worker_), 0); // should be a no-op.
|
2013-07-31 09:46:58 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_reset(&worker_), 0);
|
2013-07-31 09:46:58 +04:00
|
|
|
|
|
|
|
int hook_data = 0;
|
|
|
|
int return_value = 1; // return successfully from the hook
|
|
|
|
worker_.hook = ThreadHook;
|
|
|
|
worker_.data1 = &hook_data;
|
|
|
|
worker_.data2 = &return_value;
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
const bool synchronous = GetParam();
|
|
|
|
if (synchronous) {
|
|
|
|
vp9_worker_execute(&worker_);
|
|
|
|
} else {
|
|
|
|
vp9_worker_launch(&worker_);
|
|
|
|
}
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_sync(&worker_), 0);
|
2013-07-31 09:46:58 +04:00
|
|
|
EXPECT_FALSE(worker_.had_error);
|
|
|
|
EXPECT_EQ(5, hook_data);
|
|
|
|
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_sync(&worker_), 0); // should be a no-op.
|
2013-07-31 09:46:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
TEST_P(VP9WorkerThreadTest, HookFailure) {
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_reset(&worker_), 0);
|
2013-07-31 09:46:58 +04:00
|
|
|
|
|
|
|
int hook_data = 0;
|
|
|
|
int return_value = 0; // return failure from the hook
|
|
|
|
worker_.hook = ThreadHook;
|
|
|
|
worker_.data1 = &hook_data;
|
|
|
|
worker_.data2 = &return_value;
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
const bool synchronous = GetParam();
|
|
|
|
if (synchronous) {
|
|
|
|
vp9_worker_execute(&worker_);
|
|
|
|
} else {
|
|
|
|
vp9_worker_launch(&worker_);
|
|
|
|
}
|
2013-07-31 09:46:58 +04:00
|
|
|
EXPECT_FALSE(vp9_worker_sync(&worker_));
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_EQ(1, worker_.had_error);
|
2013-07-31 09:46:58 +04:00
|
|
|
|
|
|
|
// Ensure _reset() clears the error and _launch() can be called again.
|
|
|
|
return_value = 1;
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_reset(&worker_), 0);
|
2013-07-31 09:46:58 +04:00
|
|
|
EXPECT_FALSE(worker_.had_error);
|
|
|
|
vp9_worker_launch(&worker_);
|
2013-10-26 00:29:51 +04:00
|
|
|
EXPECT_NE(vp9_worker_sync(&worker_), 0);
|
2013-07-31 09:46:58 +04:00
|
|
|
EXPECT_FALSE(worker_.had_error);
|
|
|
|
}
|
|
|
|
|
2013-08-01 03:15:10 +04:00
|
|
|
TEST(VP9DecodeMTTest, MTDecode) {
|
|
|
|
libvpx_test::WebMVideoSource video("vp90-2-03-size-226x226.webm");
|
|
|
|
video.Init();
|
|
|
|
|
|
|
|
vpx_codec_dec_cfg_t cfg = {0};
|
|
|
|
cfg.threads = 2;
|
|
|
|
libvpx_test::VP9Decoder decoder(cfg, 0);
|
|
|
|
|
|
|
|
libvpx_test::MD5 md5;
|
|
|
|
for (video.Begin(); video.cxdata(); video.Next()) {
|
|
|
|
const vpx_codec_err_t res =
|
|
|
|
decoder.DecodeFrame(video.cxdata(), video.frame_size());
|
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
|
|
|
|
|
|
|
|
libvpx_test::DxDataIterator dec_iter = decoder.GetDxData();
|
|
|
|
const vpx_image_t *img = NULL;
|
|
|
|
|
|
|
|
// Get decompressed data
|
|
|
|
while ((img = dec_iter.Next())) {
|
|
|
|
md5.Add(img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc", md5.Get());
|
|
|
|
}
|
|
|
|
|
2013-10-16 18:10:27 +04:00
|
|
|
INSTANTIATE_TEST_CASE_P(Synchronous, VP9WorkerThreadTest, ::testing::Bool());
|
|
|
|
|
2013-07-31 09:46:58 +04:00
|
|
|
} // namespace
|