Merge changes I875ac5a7,I2b13369d,I9ceb47a9

* changes:
  update vp9_thread.[hc]
  vp9_thread_test: remove unnecessary c_str()'s
  vp9_thread_test: factorize decode loop
This commit is contained in:
James Zern
2014-07-01 20:46:53 -07:00
committed by Gerrit Code Review
6 changed files with 246 additions and 130 deletions

View File

@@ -28,11 +28,11 @@ class VP9WorkerThreadTest : public ::testing::TestWithParam<bool> {
protected:
virtual ~VP9WorkerThreadTest() {}
virtual void SetUp() {
vp9_worker_init(&worker_);
vp9_get_worker_interface()->init(&worker_);
}
virtual void TearDown() {
vp9_worker_end(&worker_);
vp9_get_worker_interface()->end(&worker_);
}
VP9Worker worker_;
@@ -45,10 +45,11 @@ int ThreadHook(void* data, void* return_value) {
}
TEST_P(VP9WorkerThreadTest, HookSuccess) {
EXPECT_NE(vp9_worker_sync(&worker_), 0); // should be a no-op.
// should be a no-op.
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
for (int i = 0; i < 2; ++i) {
EXPECT_NE(vp9_worker_reset(&worker_), 0);
EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
int hook_data = 0;
int return_value = 1; // return successfully from the hook
@@ -58,20 +59,21 @@ TEST_P(VP9WorkerThreadTest, HookSuccess) {
const bool synchronous = GetParam();
if (synchronous) {
vp9_worker_execute(&worker_);
vp9_get_worker_interface()->execute(&worker_);
} else {
vp9_worker_launch(&worker_);
vp9_get_worker_interface()->launch(&worker_);
}
EXPECT_NE(vp9_worker_sync(&worker_), 0);
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
EXPECT_EQ(5, hook_data);
EXPECT_NE(vp9_worker_sync(&worker_), 0); // should be a no-op.
// should be a no-op.
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
}
}
TEST_P(VP9WorkerThreadTest, HookFailure) {
EXPECT_NE(vp9_worker_reset(&worker_), 0);
EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
int hook_data = 0;
int return_value = 0; // return failure from the hook
@@ -81,26 +83,49 @@ TEST_P(VP9WorkerThreadTest, HookFailure) {
const bool synchronous = GetParam();
if (synchronous) {
vp9_worker_execute(&worker_);
vp9_get_worker_interface()->execute(&worker_);
} else {
vp9_worker_launch(&worker_);
vp9_get_worker_interface()->launch(&worker_);
}
EXPECT_FALSE(vp9_worker_sync(&worker_));
EXPECT_FALSE(vp9_get_worker_interface()->sync(&worker_));
EXPECT_EQ(1, worker_.had_error);
// Ensure _reset() clears the error and _launch() can be called again.
return_value = 1;
EXPECT_NE(vp9_worker_reset(&worker_), 0);
EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
vp9_worker_launch(&worker_);
EXPECT_NE(vp9_worker_sync(&worker_), 0);
vp9_get_worker_interface()->launch(&worker_);
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
}
TEST(VP9WorkerThreadTest, TestInterfaceAPI) {
EXPECT_EQ(0, vp9_set_worker_interface(NULL));
EXPECT_TRUE(vp9_get_worker_interface() != NULL);
for (int i = 0; i < 6; ++i) {
VP9WorkerInterface winterface = *vp9_get_worker_interface();
switch (i) {
default:
case 0: winterface.init = NULL; break;
case 1: winterface.reset = NULL; break;
case 2: winterface.sync = NULL; break;
case 3: winterface.launch = NULL; break;
case 4: winterface.execute = NULL; break;
case 5: winterface.end = NULL; break;
}
EXPECT_EQ(0, vp9_set_worker_interface(&winterface));
}
}
// -----------------------------------------------------------------------------
// Multi-threaded decode tests
#if CONFIG_WEBM_IO
struct FileList {
const char *name;
const char *expected_md5;
};
// Decodes |filename| with |num_threads|. Returns the md5 of the decoded frames.
string DecodeFile(const string& filename, int num_threads) {
libvpx_test::WebMVideoSource video(filename);
@@ -130,39 +155,77 @@ string DecodeFile(const string& filename, int num_threads) {
return string(md5.Get());
}
void DecodeFiles(const FileList files[]) {
for (const FileList *iter = files; iter->name != NULL; ++iter) {
SCOPED_TRACE(iter->name);
for (int t = 2; t <= 8; ++t) {
EXPECT_EQ(iter->expected_md5, DecodeFile(iter->name, t))
<< "threads = " << t;
}
}
}
// Trivial serialized thread worker interface implementation.
// Note any worker that requires synchronization between other workers will
// hang.
namespace impl {
void Init(VP9Worker *const worker) { memset(worker, 0, sizeof(*worker)); }
int Reset(VP9Worker *const /*worker*/) { return 1; }
int Sync(VP9Worker *const worker) { return !worker->had_error; }
void Execute(VP9Worker *const worker) {
worker->had_error |= worker->hook(worker->data1, worker->data2);
}
void Launch(VP9Worker *const worker) { Execute(worker); }
void End(VP9Worker *const /*worker*/) {}
} // namespace impl
TEST(VP9WorkerThreadTest, TestSerialInterface) {
static const VP9WorkerInterface serial_interface = {
impl::Init, impl::Reset, impl::Sync, impl::Launch, impl::Execute, impl::End
};
// TODO(jzern): Avoid using a file that will use the row-based thread
// loopfilter, with the simple serialized implementation it will hang. This is
// due to its expectation that rows will be run in parallel as they wait on
// progress in the row above before proceeding.
static const char expected_md5[] = "b35a1b707b28e82be025d960aba039bc";
static const char filename[] = "vp90-2-03-size-226x226.webm";
VP9WorkerInterface default_interface = *vp9_get_worker_interface();
EXPECT_NE(vp9_set_worker_interface(&serial_interface), 0);
EXPECT_EQ(expected_md5, DecodeFile(filename, 2));
// Reset the interface.
EXPECT_NE(vp9_set_worker_interface(&default_interface), 0);
EXPECT_EQ(expected_md5, DecodeFile(filename, 2));
}
TEST(VP9DecodeMultiThreadedTest, Decode) {
// no tiles or frame parallel; this exercises loop filter threading.
EXPECT_STREQ("b35a1b707b28e82be025d960aba039bc",
DecodeFile("vp90-2-03-size-226x226.webm", 2).c_str());
EXPECT_EQ("b35a1b707b28e82be025d960aba039bc",
DecodeFile("vp90-2-03-size-226x226.webm", 2));
}
TEST(VP9DecodeMultiThreadedTest, Decode2) {
static const struct {
const char *name;
const char *expected_md5;
} files[] = {
static const FileList files[] = {
{ "vp90-2-08-tile_1x2_frame_parallel.webm",
"68ede6abd66bae0a2edf2eb9232241b6" },
{ "vp90-2-08-tile_1x4_frame_parallel.webm",
"368ebc6ebf3a5e478d85b2c3149b2848" },
{ "vp90-2-08-tile_1x8_frame_parallel.webm",
"17e439da2388aff3a0f69cb22579c6c1" },
{ NULL, NULL }
};
for (int i = 0; i < static_cast<int>(sizeof(files) / sizeof(files[0])); ++i) {
for (int t = 2; t <= 8; ++t) {
EXPECT_STREQ(files[i].expected_md5, DecodeFile(files[i].name, t).c_str())
<< "threads = " << t;
}
}
DecodeFiles(files);
}
// Test tile quantity changes within one file.
TEST(VP9DecodeMultiThreadedTest, Decode3) {
static const struct {
const char *name;
const char *expected_md5;
} files[] = {
static const FileList files[] = {
{ "vp90-2-14-resize-fp-tiles-1-16.webm",
"0cd5e632c326297e975f38949c31ea94" },
{ "vp90-2-14-resize-fp-tiles-1-2-4-8-16.webm",
@@ -207,14 +270,10 @@ TEST(VP9DecodeMultiThreadedTest, Decode3) {
"ae96f21f21b6370cc0125621b441fc52" },
{ "vp90-2-14-resize-fp-tiles-8-4.webm",
"3eb4f24f10640d42218f7fd7b9fd30d4" },
{ NULL, NULL }
};
for (int i = 0; i < static_cast<int>(sizeof(files) / sizeof(files[0])); ++i) {
for (int t = 2; t <= 8; ++t) {
EXPECT_STREQ(files[i].expected_md5, DecodeFile(files[i].name, t).c_str())
<< "threads = " << t;
}
}
DecodeFiles(files);
}
#endif // CONFIG_WEBM_IO