Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/oapv.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,20 +770,18 @@ static int enc_thread_tile(void *arg)
oapve_core_t *core = (oapve_core_t *)arg;
oapve_ctx_t *ctx = core->ctx;
oapve_tile_t *tile = ctx->tile;
int ret = OAPV_OK, i;
int ret = OAPV_OK;

while(1) {
// find not encoded tile
oapv_tpool_enter_cs(ctx->sync_obj);
for(i = 0; i < ctx->num_tiles; i++) {
if(tile[i].stat == ENC_TILE_STAT_NOT_ENCODED) {
tile[i].stat = ENC_TILE_STAT_ON_ENCODING;
core->tile_idx = i;
break;
}
core->tile_idx = ctx->tile_idx;
if (ctx->tile_idx < ctx->num_tiles) {
tile[core->tile_idx].stat = ENC_TILE_STAT_ON_ENCODING;
++ctx->tile_idx;
}
oapv_tpool_leave_cs(ctx->sync_obj);
if(i == ctx->num_tiles) {
if(core->tile_idx == ctx->num_tiles) {
break;
}

Expand Down Expand Up @@ -1011,6 +1009,7 @@ static int enc_frame(oapve_ctx_t *ctx, oapv_bs_t *bs)
int parallel_task = (ctx->threads > ctx->num_tiles) ? ctx->num_tiles : ctx->threads;

/* encode tiles ************************************/
ctx->tile_idx = 0;
for(tidx = 0; tidx < (parallel_task - 1); tidx++) {
tpool->run(ctx->thread_id[tidx], enc_thread_tile,
(void *)ctx->core[tidx]);
Expand Down Expand Up @@ -1597,7 +1596,7 @@ static int dec_tile(oapvd_core_t *core, oapvd_tile_t *tile)
static int dec_thread_tile(void *arg)
{
oapv_bs_t bs;
int i, ret, run, tidx = 0, thread_ret = OAPV_OK;
int ret, run, tidx = 0, thread_ret = OAPV_OK;

oapvd_core_t *core = (oapvd_core_t *)arg;
oapvd_ctx_t *ctx = core->ctx;
Expand All @@ -1606,15 +1605,13 @@ static int dec_thread_tile(void *arg)
while(1) {
// find not decoded tile
oapv_tpool_enter_cs(ctx->sync_obj);
for(i = 0; i < ctx->num_tiles; i++) {
if(tile[i].stat == DEC_TILE_STAT_NOT_DECODED) {
tile[i].stat = DEC_TILE_STAT_ON_DECODING;
tidx = i;
break;
}
tidx = ctx->tile_idx;
if (ctx->tile_idx < ctx->num_tiles) {
tile[tidx].stat = DEC_TILE_STAT_ON_DECODING;
++ctx->num_tiles;
}
oapv_tpool_leave_cs(ctx->sync_obj);
if(i == ctx->num_tiles) {
if(tidx == ctx->num_tiles) {
break;
}

Expand Down Expand Up @@ -1881,6 +1878,7 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid
parallel_task = (ctx->threads > ctx->num_tiles) ? ctx->num_tiles : ctx->threads;

/* decode tiles ************************************/
ctx->tile_idx = 0;
for(tidx = 0; tidx < (parallel_task - 1); tidx++) {
tpool->run(ctx->thread_id[tidx], dec_thread_tile,
(void *)ctx->core[tidx]);
Expand Down
2 changes: 2 additions & 0 deletions src/oapv_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ struct oapve_ctx {
int au_bs_fmt; // access unit bitstream format
int num_tiles_frms[OAPV_MAX_NUM_FRAMES];
int num_tiles;
int tile_idx;
int num_tile_cols;
int num_tile_rows;
int qp[N_C];
Expand Down Expand Up @@ -383,6 +384,7 @@ struct oapvd_ctx {
oapv_sync_obj_t sync_obj;
u8 *tile_end;
int num_tiles;
int tile_idx;
int num_tile_cols;
int num_tile_rows;
int w;
Expand Down
15 changes: 7 additions & 8 deletions src/oapv_rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,18 @@ int get_tile_cost_thread(void* arg)
oapve_core_t* core = (oapve_core_t*)arg;
oapve_ctx_t* ctx = core->ctx;
oapve_tile_t* tile = ctx->tile;
int tidx = 0, ret = OAPV_OK, i;
int tidx = 0, ret = OAPV_OK;

while (1) {
// find not processed tile
oapv_tpool_enter_cs(ctx->sync_obj);
for (i = 0; i < ctx->num_tiles; i++) {
if (tile[i].stat == ENC_TILE_STAT_NOT_ENCODED) {
tile[i].stat = ENC_TILE_STAT_ON_ENCODING;
tidx = i;
break;
}
tidx = ctx->tile_idx;
if (ctx->tile_idx < ctx->num_tiles) {
tile[tidx].stat = ENC_TILE_STAT_ON_ENCODING;
++ctx->tile_idx;
}
oapv_tpool_leave_cs(ctx->sync_obj);
if (i == ctx->num_tiles) {
if (tidx == ctx->num_tiles) {
break;
}

Expand All @@ -114,6 +112,7 @@ int oapve_rc_get_tile_cost_thread(oapve_ctx_t* ctx, u64* sum)
int parallel_task = (ctx->threads > ctx->num_tiles) ? ctx->num_tiles : ctx->threads;

// run new threads
ctx->tile_idx = 0;
int tidx = 0;
for (tidx = 0; tidx < (parallel_task - 1); tidx++) {
tpool->run(ctx->thread_id[tidx], get_tile_cost_thread, (void*)ctx->core[tidx]);
Expand Down