Commit 04d2e574 authored by Jingning Han's avatar Jingning Han

Use vpx prefix for codec independent threading functions

Replace vp9_ prefix with vpx_ for common multi-threading functions.

Change-Id: I941a5ead9bfe8213fdad345511d2061b07797b55
parent 3a3b0be0
......@@ -24,27 +24,27 @@ namespace {
using std::string;
class VP9WorkerThreadTest : public ::testing::TestWithParam<bool> {
class VPxWorkerThreadTest : public ::testing::TestWithParam<bool> {
protected:
virtual ~VP9WorkerThreadTest() {}
virtual ~VPxWorkerThreadTest() {}
virtual void SetUp() {
vp9_get_worker_interface()->init(&worker_);
vpx_get_worker_interface()->init(&worker_);
}
virtual void TearDown() {
vp9_get_worker_interface()->end(&worker_);
vpx_get_worker_interface()->end(&worker_);
}
void Run(VP9Worker* worker) {
void Run(VPxWorker* worker) {
const bool synchronous = GetParam();
if (synchronous) {
vp9_get_worker_interface()->execute(worker);
vpx_get_worker_interface()->execute(worker);
} else {
vp9_get_worker_interface()->launch(worker);
vpx_get_worker_interface()->launch(worker);
}
}
VP9Worker worker_;
VPxWorker worker_;
};
int ThreadHook(void* data, void* return_value) {
......@@ -53,12 +53,12 @@ int ThreadHook(void* data, void* return_value) {
return *reinterpret_cast<int*>(return_value);
}
TEST_P(VP9WorkerThreadTest, HookSuccess) {
TEST_P(VPxWorkerThreadTest, HookSuccess) {
// should be a no-op.
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
EXPECT_NE(vpx_get_worker_interface()->sync(&worker_), 0);
for (int i = 0; i < 2; ++i) {
EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
EXPECT_NE(vpx_get_worker_interface()->reset(&worker_), 0);
int hook_data = 0;
int return_value = 1; // return successfully from the hook
......@@ -67,17 +67,17 @@ TEST_P(VP9WorkerThreadTest, HookSuccess) {
worker_.data2 = &return_value;
Run(&worker_);
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
EXPECT_NE(vpx_get_worker_interface()->sync(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
EXPECT_EQ(5, hook_data);
// should be a no-op.
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
EXPECT_NE(vpx_get_worker_interface()->sync(&worker_), 0);
}
}
TEST_P(VP9WorkerThreadTest, HookFailure) {
EXPECT_NE(vp9_get_worker_interface()->reset(&worker_), 0);
TEST_P(VPxWorkerThreadTest, HookFailure) {
EXPECT_NE(vpx_get_worker_interface()->reset(&worker_), 0);
int hook_data = 0;
int return_value = 0; // return failure from the hook
......@@ -86,29 +86,29 @@ TEST_P(VP9WorkerThreadTest, HookFailure) {
worker_.data2 = &return_value;
Run(&worker_);
EXPECT_FALSE(vp9_get_worker_interface()->sync(&worker_));
EXPECT_FALSE(vpx_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_get_worker_interface()->reset(&worker_), 0);
EXPECT_NE(vpx_get_worker_interface()->reset(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
vp9_get_worker_interface()->launch(&worker_);
EXPECT_NE(vp9_get_worker_interface()->sync(&worker_), 0);
vpx_get_worker_interface()->launch(&worker_);
EXPECT_NE(vpx_get_worker_interface()->sync(&worker_), 0);
EXPECT_FALSE(worker_.had_error);
}
TEST_P(VP9WorkerThreadTest, EndWithoutSync) {
TEST_P(VPxWorkerThreadTest, EndWithoutSync) {
// Create a large number of threads to increase the chances of detecting a
// race. Doing more work in the hook is no guarantee as any race would occur
// post hook execution in the main thread loop driver.
static const int kNumWorkers = 64;
VP9Worker workers[kNumWorkers];
VPxWorker workers[kNumWorkers];
int hook_data[kNumWorkers];
int return_value[kNumWorkers];
for (int n = 0; n < kNumWorkers; ++n) {
vp9_get_worker_interface()->init(&workers[n]);
vpx_get_worker_interface()->init(&workers[n]);
return_value[n] = 1; // return successfully from the hook
workers[n].hook = ThreadHook;
workers[n].data1 = &hook_data[n];
......@@ -117,7 +117,7 @@ TEST_P(VP9WorkerThreadTest, EndWithoutSync) {
for (int i = 0; i < 2; ++i) {
for (int n = 0; n < kNumWorkers; ++n) {
EXPECT_NE(vp9_get_worker_interface()->reset(&workers[n]), 0);
EXPECT_NE(vpx_get_worker_interface()->reset(&workers[n]), 0);
hook_data[n] = 0;
}
......@@ -126,16 +126,16 @@ TEST_P(VP9WorkerThreadTest, EndWithoutSync) {
}
for (int n = kNumWorkers - 1; n >= 0; --n) {
vp9_get_worker_interface()->end(&workers[n]);
vpx_get_worker_interface()->end(&workers[n]);
}
}
}
TEST(VP9WorkerThreadTest, TestInterfaceAPI) {
EXPECT_EQ(0, vp9_set_worker_interface(NULL));
EXPECT_TRUE(vp9_get_worker_interface() != NULL);
TEST(VPxWorkerThreadTest, TestInterfaceAPI) {
EXPECT_EQ(0, vpx_set_worker_interface(NULL));
EXPECT_TRUE(vpx_get_worker_interface() != NULL);
for (int i = 0; i < 6; ++i) {
VP9WorkerInterface winterface = *vp9_get_worker_interface();
VPxWorkerInterface winterface = *vpx_get_worker_interface();
switch (i) {
default:
case 0: winterface.init = NULL; break;
......@@ -145,7 +145,7 @@ TEST(VP9WorkerThreadTest, TestInterfaceAPI) {
case 4: winterface.execute = NULL; break;
case 5: winterface.end = NULL; break;
}
EXPECT_EQ(0, vp9_set_worker_interface(&winterface));
EXPECT_EQ(0, vpx_set_worker_interface(&winterface));
}
}
......@@ -202,21 +202,21 @@ void DecodeFiles(const FileList files[]) {
// 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 Init(VPxWorker *const worker) { memset(worker, 0, sizeof(*worker)); }
int Reset(VPxWorker *const /*worker*/) { return 1; }
int Sync(VPxWorker *const worker) { return !worker->had_error; }
void Execute(VP9Worker *const worker) {
void Execute(VPxWorker *const worker) {
worker->had_error |= !worker->hook(worker->data1, worker->data2);
}
void Launch(VP9Worker *const worker) { Execute(worker); }
void End(VP9Worker *const /*worker*/) {}
void Launch(VPxWorker *const worker) { Execute(worker); }
void End(VPxWorker *const /*worker*/) {}
} // namespace impl
TEST(VP9WorkerThreadTest, TestSerialInterface) {
static const VP9WorkerInterface serial_interface = {
TEST(VPxWorkerThreadTest, TestSerialInterface) {
static const VPxWorkerInterface 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
......@@ -225,13 +225,13 @@ TEST(VP9WorkerThreadTest, TestSerialInterface) {
// 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();
VPxWorkerInterface default_interface = *vpx_get_worker_interface();
EXPECT_NE(vp9_set_worker_interface(&serial_interface), 0);
EXPECT_NE(vpx_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_NE(vpx_set_worker_interface(&default_interface), 0);
EXPECT_EQ(expected_md5, DecodeFile(filename, 2));
}
......@@ -309,6 +309,6 @@ TEST(VP9DecodeMultiThreadedTest, Decode3) {
}
#endif // CONFIG_WEBM_IO
INSTANTIATE_TEST_CASE_P(Synchronous, VP9WorkerThreadTest, ::testing::Bool());
INSTANTIATE_TEST_CASE_P(Synchronous, VPxWorkerThreadTest, ::testing::Bool());
} // namespace
......@@ -80,7 +80,7 @@ typedef struct {
// frame_worker_owner indicates which FrameWorker owns this buffer. NULL means
// that no FrameWorker owns, or is decoding, this buffer.
VP9Worker *frame_worker_owner;
VPxWorker *frame_worker_owner;
// row and col indicate which position frame has been decoded to in real
// pixel unit. They are reset to -1 when decoding begins and set to INT_MAX
......
......@@ -157,9 +157,9 @@ static void loop_filter_rows_mt(YV12_BUFFER_CONFIG *frame,
VP9_COMMON *cm,
struct macroblockd_plane planes[MAX_MB_PLANE],
int start, int stop, int y_only,
VP9Worker *workers, int nworkers,
VPxWorker *workers, int nworkers,
VP9LfSync *lf_sync) {
const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
// Number of superblock rows and cols
const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2;
// Decoder may allocate more threads than number of tiles based on user's
......@@ -186,10 +186,10 @@ static void loop_filter_rows_mt(YV12_BUFFER_CONFIG *frame,
// because of contention. If the multithreading code changes in the future
// then the number of workers used by the loopfilter should be revisited.
for (i = 0; i < num_workers; ++i) {
VP9Worker *const worker = &workers[i];
VPxWorker *const worker = &workers[i];
LFWorkerData *const lf_data = &lf_sync->lfdata[i];
worker->hook = (VP9WorkerHook)loop_filter_row_worker;
worker->hook = (VPxWorkerHook)loop_filter_row_worker;
worker->data1 = lf_sync;
worker->data2 = lf_data;
......@@ -218,7 +218,7 @@ void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
struct macroblockd_plane planes[MAX_MB_PLANE],
int frame_filter_level,
int y_only, int partial_frame,
VP9Worker *workers, int num_workers,
VPxWorker *workers, int num_workers,
VP9LfSync *lf_sync) {
int start_mi_row, end_mi_row, mi_rows_to_filter;
......
......@@ -48,7 +48,7 @@ void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
struct macroblockd_plane planes[MAX_MB_PLANE],
int frame_filter_level,
int y_only, int partial_frame,
VP9Worker *workers, int num_workers,
VPxWorker *workers, int num_workers,
VP9LfSync *lf_sync);
void vp9_accumulate_frame_counts(struct VP9Common *cm,
......
......@@ -1259,7 +1259,7 @@ static const uint8_t *decode_tiles(VP9Decoder *pbi,
const uint8_t *data,
const uint8_t *data_end) {
VP9_COMMON *const cm = &pbi->common;
const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
const int aligned_cols = mi_cols_aligned_to_sb(cm->mi_cols);
const int tile_cols = 1 << cm->log2_tile_cols;
const int tile_rows = 1 << cm->log2_tile_rows;
......@@ -1272,7 +1272,7 @@ static const uint8_t *decode_tiles(VP9Decoder *pbi,
pbi->lf_worker.data1 == NULL) {
CHECK_MEM_ERROR(cm, pbi->lf_worker.data1,
vpx_memalign(32, sizeof(LFWorkerData)));
pbi->lf_worker.hook = (VP9WorkerHook)vp9_loop_filter_worker;
pbi->lf_worker.hook = (VPxWorkerHook)vp9_loop_filter_worker;
if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"Loop filter thread creation failed");
......@@ -1434,7 +1434,7 @@ static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
const uint8_t *data,
const uint8_t *data_end) {
VP9_COMMON *const cm = &pbi->common;
const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
const uint8_t *bit_reader_end = NULL;
const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
const int tile_cols = 1 << cm->log2_tile_cols;
......@@ -1464,7 +1464,7 @@ static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
CHECK_MEM_ERROR(cm, pbi->tile_worker_info,
vpx_malloc(num_threads * sizeof(*pbi->tile_worker_info)));
for (i = 0; i < num_threads; ++i) {
VP9Worker *const worker = &pbi->tile_workers[i];
VPxWorker *const worker = &pbi->tile_workers[i];
++pbi->num_tile_workers;
winterface->init(worker);
......@@ -1477,9 +1477,9 @@ static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
// Reset tile decoding hook
for (n = 0; n < num_workers; ++n) {
VP9Worker *const worker = &pbi->tile_workers[n];
VPxWorker *const worker = &pbi->tile_workers[n];
winterface->sync(worker);
worker->hook = (VP9WorkerHook)tile_worker_hook;
worker->hook = (VPxWorkerHook)tile_worker_hook;
worker->data1 = &pbi->tile_worker_data[n];
worker->data2 = &pbi->tile_worker_info[n];
}
......@@ -1529,7 +1529,7 @@ static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
while (n < tile_cols) {
int i;
for (i = 0; i < num_workers && n < tile_cols; ++i) {
VP9Worker *const worker = &pbi->tile_workers[i];
VPxWorker *const worker = &pbi->tile_workers[i];
TileWorkerData *const tile_data = (TileWorkerData*)worker->data1;
TileInfo *const tile = (TileInfo*)worker->data2;
TileBuffer *const buf = &tile_buffers[0][n];
......@@ -1561,7 +1561,7 @@ static const uint8_t *decode_tiles_mt(VP9Decoder *pbi,
}
for (; i > 0; --i) {
VP9Worker *const worker = &pbi->tile_workers[i - 1];
VPxWorker *const worker = &pbi->tile_workers[i - 1];
// TODO(jzern): The tile may have specific error data associated with
// its vpx_internal_error_info which could be propagated to the main info
// in cm. Additionally once the threads have been synced and an error is
......@@ -2020,7 +2020,7 @@ void vp9_decode_frame(VP9Decoder *pbi,
// If encoded in frame parallel mode, frame context is ready after decoding
// the frame header.
if (pbi->frame_parallel_decode && cm->frame_parallel_decoding_mode) {
VP9Worker *const worker = pbi->frame_worker_owner;
VPxWorker *const worker = pbi->frame_worker_owner;
FrameWorkerData *const frame_worker_data = worker->data1;
if (cm->refresh_frame_context) {
context_updated = 1;
......
......@@ -118,7 +118,7 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
cm->error.setjmp = 0;
vp9_get_worker_interface()->init(&pbi->lf_worker);
vpx_get_worker_interface()->init(&pbi->lf_worker);
return pbi;
}
......@@ -126,12 +126,12 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
void vp9_decoder_remove(VP9Decoder *pbi) {
int i;
vp9_get_worker_interface()->end(&pbi->lf_worker);
vpx_get_worker_interface()->end(&pbi->lf_worker);
vpx_free(pbi->lf_worker.data1);
vpx_free(pbi->tile_data);
for (i = 0; i < pbi->num_tile_workers; ++i) {
VP9Worker *const worker = &pbi->tile_workers[i];
vp9_get_worker_interface()->end(worker);
VPxWorker *const worker = &pbi->tile_workers[i];
vpx_get_worker_interface()->end(worker);
}
vpx_free(pbi->tile_worker_data);
vpx_free(pbi->tile_worker_info);
......@@ -311,7 +311,7 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
pbi->hold_ref_buf = 0;
if (pbi->frame_parallel_decode) {
VP9Worker *const worker = pbi->frame_worker_owner;
VPxWorker *const worker = pbi->frame_worker_owner;
vp9_frameworker_lock_stats(worker);
frame_bufs[cm->new_fb_idx].frame_worker_owner = worker;
// Reset decoding progress.
......@@ -325,7 +325,7 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
if (setjmp(cm->error.jmp)) {
const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
int i;
cm->error.setjmp = 0;
......@@ -387,7 +387,7 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
if (pbi->frame_parallel_decode) {
// Need to lock the mutex here as another thread may
// be accessing this buffer.
VP9Worker *const worker = pbi->frame_worker_owner;
VPxWorker *const worker = pbi->frame_worker_owner;
FrameWorkerData *const frame_worker_data = worker->data1;
vp9_frameworker_lock_stats(worker);
......
......@@ -57,9 +57,9 @@ typedef struct VP9Decoder {
// the same.
RefCntBuffer *cur_buf; // Current decoding frame buffer.
VP9Worker *frame_worker_owner; // frame_worker that owns this pbi.
VP9Worker lf_worker;
VP9Worker *tile_workers;
VPxWorker *frame_worker_owner; // frame_worker that owns this pbi.
VPxWorker lf_worker;
VPxWorker *tile_workers;
TileWorkerData *tile_worker_data;
TileInfo *tile_worker_info;
int num_tile_workers;
......
......@@ -17,7 +17,7 @@
// #define DEBUG_THREAD
// TODO(hkuang): Clean up all the #ifdef in this file.
void vp9_frameworker_lock_stats(VP9Worker *const worker) {
void vp9_frameworker_lock_stats(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
FrameWorkerData *const worker_data = worker->data1;
pthread_mutex_lock(&worker_data->stats_mutex);
......@@ -26,7 +26,7 @@ void vp9_frameworker_lock_stats(VP9Worker *const worker) {
#endif
}
void vp9_frameworker_unlock_stats(VP9Worker *const worker) {
void vp9_frameworker_unlock_stats(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
FrameWorkerData *const worker_data = worker->data1;
pthread_mutex_unlock(&worker_data->stats_mutex);
......@@ -35,7 +35,7 @@ void vp9_frameworker_unlock_stats(VP9Worker *const worker) {
#endif
}
void vp9_frameworker_signal_stats(VP9Worker *const worker) {
void vp9_frameworker_signal_stats(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
FrameWorkerData *const worker_data = worker->data1;
......@@ -59,7 +59,7 @@ void vp9_frameworker_signal_stats(VP9Worker *const worker) {
#endif
// TODO(hkuang): Remove worker parameter as it is only used in debug code.
void vp9_frameworker_wait(VP9Worker *const worker, RefCntBuffer *const ref_buf,
void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
int row) {
#if CONFIG_MULTITHREAD
if (!ref_buf)
......@@ -74,7 +74,7 @@ void vp9_frameworker_wait(VP9Worker *const worker, RefCntBuffer *const ref_buf,
{
// Find the worker thread that owns the reference frame. If the reference
// frame has been fully decoded, it may not have owner.
VP9Worker *const ref_worker = ref_buf->frame_worker_owner;
VPxWorker *const ref_worker = ref_buf->frame_worker_owner;
FrameWorkerData *const ref_worker_data =
(FrameWorkerData *)ref_worker->data1;
const VP9Decoder *const pbi = ref_worker_data->pbi;
......@@ -114,7 +114,7 @@ void vp9_frameworker_wait(VP9Worker *const worker, RefCntBuffer *const ref_buf,
void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row) {
#if CONFIG_MULTITHREAD
VP9Worker *worker = buf->frame_worker_owner;
VPxWorker *worker = buf->frame_worker_owner;
#ifdef DEBUG_THREAD
{
......@@ -134,8 +134,8 @@ void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row) {
#endif // CONFIG_MULTITHREAD
}
void vp9_frameworker_copy_context(VP9Worker *const dst_worker,
VP9Worker *const src_worker) {
void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
VPxWorker *const src_worker) {
#if CONFIG_MULTITHREAD
FrameWorkerData *const src_worker_data = (FrameWorkerData *)src_worker->data1;
FrameWorkerData *const dst_worker_data = (FrameWorkerData *)dst_worker->data1;
......
......@@ -44,15 +44,15 @@ typedef struct FrameWorkerData {
int frame_decoded; // Finished decoding current frame.
} FrameWorkerData;
void vp9_frameworker_lock_stats(VP9Worker *const worker);
void vp9_frameworker_unlock_stats(VP9Worker *const worker);
void vp9_frameworker_signal_stats(VP9Worker *const worker);
void vp9_frameworker_lock_stats(VPxWorker *const worker);
void vp9_frameworker_unlock_stats(VPxWorker *const worker);
void vp9_frameworker_signal_stats(VPxWorker *const worker);
// Wait until ref_buf has been decoded to row in real pixel unit.
// Note: worker may already finish decoding ref_buf and release it in order to
// start decoding next frame. So need to check whether worker is still decoding
// ref_buf.
void vp9_frameworker_wait(VP9Worker *const worker, RefCntBuffer *const ref_buf,
void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
int row);
// FrameWorker broadcasts its decoding progress so other workers that are
......@@ -60,7 +60,7 @@ void vp9_frameworker_wait(VP9Worker *const worker, RefCntBuffer *const ref_buf,
void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row);
// Copy necessary decoding context from src worker to dst worker.
void vp9_frameworker_copy_context(VP9Worker *const dst_worker,
VP9Worker *const src_worker);
void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
VPxWorker *const src_worker);
#endif // VP9_DECODER_VP9_DTHREAD_H_
......@@ -1993,11 +1993,11 @@ void vp9_remove_compressor(VP9_COMP *cpi) {
#endif
for (t = 0; t < cpi->num_workers; ++t) {
VP9Worker *const worker = &cpi->workers[t];
VPxWorker *const worker = &cpi->workers[t];
EncWorkerData *const thread_data = &cpi->tile_thr_data[t];
// Deallocate allocated threads.
vp9_get_worker_interface()->end(worker);
vpx_get_worker_interface()->end(worker);
// Deallocate allocated thread data.
if (t < cpi->num_workers - 1) {
......
......@@ -496,7 +496,7 @@ typedef struct VP9_COMP {
// Multi-threading
int num_workers;
VP9Worker *workers;
VPxWorker *workers;
struct EncWorkerData *tile_thr_data;
VP9LfSync lf_row_sync;
} VP9_COMP;
......
......@@ -69,7 +69,7 @@ static int get_max_tile_cols(VP9_COMP *cpi) {
void vp9_encode_tiles_mt(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
const int tile_cols = 1 << cm->log2_tile_cols;
const VP9WorkerInterface *const winterface = vp9_get_worker_interface();
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
const int num_workers = MIN(cpi->oxcf.max_threads, tile_cols);
int i;
......@@ -94,7 +94,7 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) {
sizeof(*cpi->tile_thr_data)));
for (i = 0; i < allocated_workers; i++) {
VP9Worker *const worker = &cpi->workers[i];
VPxWorker *const worker = &cpi->workers[i];
EncWorkerData *thread_data = &cpi->tile_thr_data[i];
++cpi->num_workers;
......@@ -132,10 +132,10 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) {
}
for (i = 0; i < num_workers; i++) {
VP9Worker *const worker = &cpi->workers[i];
VPxWorker *const worker = &cpi->workers[i];
EncWorkerData *thread_data;
worker->hook = (VP9WorkerHook)enc_worker_hook;
worker->hook = (VPxWorkerHook)enc_worker_hook;
worker->data1 = &cpi->tile_thr_data[i];
worker->data2 = NULL;
thread_data = (EncWorkerData*)worker->data1;
......@@ -170,7 +170,7 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) {
// Encode a frame
for (i = 0; i < num_workers; i++) {
VP9Worker *const worker = &cpi->workers[i];
VPxWorker *const worker = &cpi->workers[i];
EncWorkerData *const thread_data = (EncWorkerData*)worker->data1;
// Set the starting tile for each thread.
......@@ -184,12 +184,12 @@ void vp9_encode_tiles_mt(VP9_COMP *cpi) {
// Encoding ends.
for (i = 0; i < num_workers; i++) {
VP9Worker *const worker = &cpi->workers[i];
VPxWorker *const worker = &cpi->workers[i];
winterface->sync(worker);
}
for (i = 0; i < num_workers; i++) {
VP9Worker *const worker = &cpi->workers[i];
VPxWorker *const worker = &cpi->workers[i];
EncWorkerData *const thread_data = (EncWorkerData*)worker->data1;
// Accumulate counters.
......
This diff is collapsed.
......@@ -20,7 +20,7 @@
#if CONFIG_MULTITHREAD
struct VP9WorkerImpl {
struct VPxWorkerImpl {
pthread_mutex_t mutex_;
pthread_cond_t condition_;
pthread_t thread_;
......@@ -28,10 +28,10 @@ struct VP9WorkerImpl {
//------------------------------------------------------------------------------
static void execute(VP9Worker *const worker); // Forward declaration.
static void execute(VPxWorker *const worker); // Forward declaration.
static THREADFN thread_loop(void *ptr) {
VP9Worker *const worker = (VP9Worker*)ptr;
VPxWorker *const worker = (VPxWorker*)ptr;
int done = 0;
while (!done) {
pthread_mutex_lock(&worker->impl_->mutex_);
......@@ -52,8 +52,8 @@ static THREADFN thread_loop(void *ptr) {
}
// main thread state control
static void change_state(VP9Worker *const worker,
VP9WorkerStatus new_status) {
static void change_state(VPxWorker *const worker,
VPxWorkerStatus new_status) {
// No-op when attempting to change state on a thread that didn't come up.
// Checking status_ without acquiring the lock first would result in a data
// race.
......@@ -78,12 +78,12 @@ static void change_state(VP9Worker *const worker,
//------------------------------------------------------------------------------
static void init(VP9Worker *const worker) {
static void init(VPxWorker *const worker) {
memset(worker, 0, sizeof(*worker));
worker->status_ = NOT_OK;
}
static int sync(VP9Worker *const worker) {
static int sync(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
change_state(worker, OK);
#endif
......@@ -91,12 +91,12 @@ static int sync(VP9Worker *const worker) {
return !worker->had_error;
}
static int reset(VP9Worker *const worker) {
static int reset(VPxWorker *const worker) {
int ok = 1;
worker->had_error = 0;
if (worker->status_ < OK) {
#if CONFIG_MULTITHREAD
worker->impl_ = (VP9WorkerImpl*)vpx_calloc(1, sizeof(*worker->impl_));
worker->impl_ = (VPxWorkerImpl*)vpx_calloc(1, sizeof(*worker->impl_));
if (worker->impl_ == NULL) {
return 0;
}
......@@ -129,13 +129,13 @@ static int reset(VP9Worker *const worker) {
return ok;
}
static void execute(VP9Worker *const worker) {
static void execute(VPxWorker *const worker) {
if (worker->hook != NULL) {
worker->had_error |= !worker->hook(worker->data1, worker->data2);
}
}
static void launch(VP9Worker *const worker) {
static void launch(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
change_state(worker, WORK);
#else
......@@ -143,7 +143,7 @@ static void launch(VP9Worker *const worker) {
#endif
}
static void end(VP9Worker *const worker) {
static void end(VPxWorker *const worker) {
#if CONFIG_MULTITHREAD
if (worker->impl_ != NULL) {
change_state(worker, NOT_OK);
......@@ -162,11 +162,11 @@ static void end(VP9Worker *const worker) {
//------------------------------------------------------------------------------
static VP9WorkerInterface g_worker_interface = {
static VPxWorkerInterface g_worker_interface = {
init, reset, sync, launch, execute, end
};
int vp9_set_worker_interface(const VP9WorkerInterface* const winterface) {
int vpx_set_worker_interface(const VPxWorkerInterface* const winterface) {
if (winterface == NULL ||
winterface->init == NULL || winterface->reset == NULL ||
winterface->sync == NULL || winterface->launch == NULL ||
......@@ -177,7 +177,7 @@ int vp9_set_worker_interface(const VP9WorkerInterface* const winterface) {
return 1;
}
const VP9WorkerInterface *vp9_get_worker_interface(void) {
const VPxWorkerInterface *vpx_get_worker_interface(void) {
return &g_worker_interface;
}
......
......@@ -13,8 +13,8 @@
// http://git.chromium.org/webm/libwebp.git
// 100644 blob 7bd451b124ae3b81596abfbcc823e3cb129d3a38 src/utils/thread.h
#ifndef VP9_DECODER_VP9_THREAD_H_
#define VP9_DECODER_VP9_THREAD_H_
#ifndef VPX_THREAD_H_
#define VPX_THREAD_H_
#include "./vpx_config.h"
......@@ -160,59 +160,59 @@ typedef enum {
NOT_OK = 0, // object is unusable
OK, // ready to work
WORK // busy finishing the current task
} VP9WorkerStatus;
} VPxWorkerStatus;
// Function to be called by the worker thread. Takes two opaque pointers as
// arguments (data1 and data2), and should return false in case of error.
typedef int (*VP9WorkerHook)(void*, void*);
typedef int (*VPxWorkerHook)(void*, void*);
// Platform-dependent implementation details for the worker.
typedef struct VP9WorkerImpl VP9WorkerImpl;
typedef struct VPxWorkerImpl VPxWorkerImpl;
// Synchronization object used to launch job in the worker thread
typedef struct {
VP9WorkerImpl *impl_;
VP9WorkerStatus status_;
VP9WorkerHook hook; // hook to call
VPxWorkerImpl *impl_;
VPxWorkerStatus status_;
VPxWorkerHook hook; // hook to call
void *data1; // first argument passed to 'hook'
void *data2; // second argument passed to 'hook'
int had_error; // return value of the last call to 'hook'
} VP9Worker;
} VPxWorker;
// The interface for all thread-worker related functions. All these functions
// must be implemented.
typedef struct {
// Must be called first, before any other method.
void (*init)(VP9Worker *const worker);
void (*init)(VPxWorker *const worker);