Skip to content
16 changes: 11 additions & 5 deletions app/oapv_app_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ static const args_opt_t dec_args_opts[] = {
"maximum number of access units to be decoded"
},
{
'm', "threads", ARGS_VAL_TYPE_INTEGER, 0, NULL,
'm', "threads", ARGS_VAL_TYPE_STRING, 0, NULL,
"force to use a specific number of threads"
" - 'auto' means that the value is internally determined"
},
{
'd', "output-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL,
Expand Down Expand Up @@ -98,7 +99,7 @@ typedef struct args_var {
char fname_out[256];
int max_au;
int hash;
int threads;
char threads[16];
int output_depth;
int output_csp;
} args_var_t;
Expand All @@ -119,8 +120,8 @@ static args_var_t *args_init_vars(args_parser_t *args)
args_set_variable_by_key_long(opts, "hash", &vars->hash);
args_set_variable_by_key_long(opts, "verbose", &op_verbose);
op_verbose = VERBOSE_SIMPLE; /* default */
args_set_variable_by_key_long(opts, "threads", &vars->threads);
vars->threads = OAPV_CDESC_THREADS_AUTO; /* default */
args_set_variable_by_key_long(opts, "threads", vars->threads);
strcpy(vars->threads, "auto");
args_set_variable_by_key_long(opts, "output-depth", &vars->output_depth);
args_set_variable_by_key_long(opts, "output-csp", &vars->output_csp);
vars->output_csp = 0; /* default: coded CSP */
Expand Down Expand Up @@ -445,7 +446,12 @@ int main(int argc, const char **argv)
goto ERR;
}
// create decoder
cdesc.threads = args_var->threads;
if(!strcmp(args_var->threads, "auto")){
cdesc.threads = OAPV_CDESC_THREADS_AUTO;
}
else {
cdesc.threads = atoi(args_var->threads);
}
did = oapvd_create(&cdesc, &ret);
if(did == NULL) {
logerr("ERROR: cannot create OAPV decoder (err=%d)\n", ret);
Expand Down
29 changes: 18 additions & 11 deletions app/oapv_app_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ static const args_opt_t enc_args_opts[] = {
"QP value: 0 ~ (63 + (bitdepth - 10)*6) \n"
" - 10bit input: 0 ~ 63\n"
" - 12bit input: 0 ~ 75"
" - 'auto' means that the value is internally determined"
},
{
'z', "fps", ARGS_VAL_TYPE_STRING | ARGS_VAL_TYPE_MANDATORY, 0, NULL,
"frame rate (frame per second))"
},
{
'm', "threads", ARGS_VAL_TYPE_INTEGER, 0, NULL,
'm', "threads", ARGS_VAL_TYPE_STRING, 0, NULL,
"force to use a specific number of threads\n"
" - '0' means decision of the number automatically"
" - 'auto' means that the value is internally determined"
},
{
ARGS_NO_KEY, "preset", ARGS_VAL_TYPE_STRING, 0, NULL,
Expand All @@ -116,10 +117,11 @@ static const args_opt_t enc_args_opts[] = {
},
{
ARGS_NO_KEY, "level", ARGS_VAL_TYPE_STRING, 0, NULL,
"level setting (1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 6, 6.1, 7, 7.1)"
"level setting (1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 6, 6.1, 7, 7.1)\n"
" - 'auto' means that the value is internally determined"
},
{
ARGS_NO_KEY, "band", ARGS_VAL_TYPE_INTEGER, 0, NULL,
ARGS_NO_KEY, "band", ARGS_VAL_TYPE_STRING, 0, NULL,
"band setting (0, 1, 2, 3)"
},
{
Expand Down Expand Up @@ -193,7 +195,7 @@ typedef struct args_var {
int input_depth;
int input_csp;
int seek;
int threads;
char threads[16];

char profile[16];
char level[16];
Expand Down Expand Up @@ -254,7 +256,7 @@ static args_var_t *args_init_vars(args_parser_t *args, oapve_param_t *param)
args_set_variable_by_key_long(opts, "profile", vars->profile);
strcpy(vars->profile, "422-10");
args_set_variable_by_key_long(opts, "level", vars->level);
strcpy(vars->level, "4.1");
strcpy(vars->level, "auto"); /* default */
args_set_variable_by_key_long(opts, "band", vars->band);
strcpy(vars->band, "2"); /* default */

Expand All @@ -263,6 +265,7 @@ static args_var_t *args_init_vars(args_parser_t *args, oapve_param_t *param)
args_set_variable_by_key_long(opts, "fps", vars->fps);

args_set_variable_by_key_long(opts, "qp", vars->qp);
strcpy(vars->qp, "auto"); /* default */
args_set_variable_by_key_long(opts, "qp_offset_c1", vars->qp_offset_c1);
args_set_variable_by_key_long(opts, "qp_offset_c2", vars->qp_offset_c2);
args_set_variable_by_key_long(opts, "qp_offset_c3", vars->qp_offset_c3);
Expand All @@ -274,8 +277,8 @@ static args_var_t *args_init_vars(args_parser_t *args, oapve_param_t *param)
args_set_variable_by_key_long(opts, "q-matrix-c2", vars->q_matrix_c2);
args_set_variable_by_key_long(opts, "q-matrix-c3", vars->q_matrix_c3);

args_set_variable_by_key_long(opts, "threads", &vars->threads);
vars->threads = OAPV_CDESC_THREADS_AUTO; /* default */
args_set_variable_by_key_long(opts, "threads", vars->threads);
strcpy(vars->threads, "auto");

args_set_variable_by_key_long(opts, "tile-w", vars->tile_w);
args_set_variable_by_key_long(opts, "tile-h", vars->tile_h);
Expand Down Expand Up @@ -692,7 +695,12 @@ int main(int argc, const char **argv)

cdesc.max_bs_buf_size = MAX_BS_BUF; /* maximum bitstream buffer size */
cdesc.max_num_frms = MAX_NUM_FRMS;
cdesc.threads = args_var->threads;
if(!strcmp(args_var->threads, "auto")){
cdesc.threads = OAPV_CDESC_THREADS_AUTO;
}
else {
cdesc.threads = atoi(args_var->threads);
}

if(check_conf(&cdesc, args_var)) {
logerr("invalid configuration\n");
Expand Down Expand Up @@ -730,10 +738,9 @@ int main(int argc, const char **argv)
}

/* create encoder */
id = oapve_create(&cdesc, NULL);
id = oapve_create(&cdesc, &ret);
if(id == NULL) {
logerr("cannot create OAPV encoder\n");
ret = -1;
goto ERR;
}

Expand Down
5 changes: 4 additions & 1 deletion inc/oapv.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern "C" {
#define OAPV_ERR_OUT_OF_BS_BUF (-203) /* too small bitstream buffer */
#define OAPV_ERR_NOT_FOUND (-204)
#define OAPV_ERR_FAILED_SYSCALL (-301) /* failed system call */
#define OAPV_ERR_INVALID_LEVEL (-401)
#define OAPV_ERR_UNKNOWN (-32767) /* unknown error */

/* return value checking */
Expand Down Expand Up @@ -469,7 +470,9 @@ static const oapv_dict_str_int_t oapv_param_opts_color_matrix[] = {
/*****************************************************************************
* coding parameters
*****************************************************************************/
#define OAPV_LEVEL_TO_LEVEL_IDC(level) (int)(((level) * 30.0) + 0.5)
#define OAPV_LEVEL_TO_LEVEL_IDC(level) (int)(((level) * 30.0) + 0.5)
#define OAPVE_PARAM_LEVEL_IDC_AUTO (0)
#define OAPVE_PARAM_QP_AUTO (255)

typedef struct oapve_param oapve_param_t;
struct oapve_param {
Expand Down
63 changes: 12 additions & 51 deletions src/oapv.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,44 +638,11 @@ static double enc_block_rdo_placebo(oapve_ctx_t *ctx, oapve_core_t *core, int lo
return best_cost;
}

static int enc_update_param(oapve_ctx_t* ctx, oapve_param_t* param)
{
/* set various value */
ctx->w = oapv_div_round_up(param->w, OAPV_MB_W) * OAPV_MB_W;
ctx->h = oapv_div_round_up(param->h, OAPV_MB_H) * OAPV_MB_H;

/* find correct tile width and height */
int tile_w, tile_h;

oapv_assert_rv(param->tile_w >= OAPV_MIN_TILE_W && param->tile_h >= OAPV_MIN_TILE_H, OAPV_ERR_INVALID_ARGUMENT);
oapv_assert_rv((param->tile_w & (OAPV_MB_W - 1)) == 0 && (param->tile_h & (OAPV_MB_H - 1)) == 0, OAPV_ERR_INVALID_ARGUMENT);

if (oapv_div_round_up(ctx->w, param->tile_w) > OAPV_MAX_TILE_COLS) {
tile_w = oapv_div_round_up(ctx->w, OAPV_MAX_TILE_COLS);
tile_w = oapv_div_round_up(tile_w, OAPV_MB_W) * OAPV_MB_W; // align to MB width
}
else {
tile_w = param->tile_w;
}
param->tile_w = tile_w;

if (oapv_div_round_up(ctx->h, param->tile_h) > OAPV_MAX_TILE_ROWS) {
tile_h = oapv_div_round_up(ctx->h, OAPV_MAX_TILE_ROWS);
tile_h = oapv_div_round_up(tile_h, OAPV_MB_H) * OAPV_MB_H; // align to MB height
}
else {
tile_h = param->tile_h;
}
param->tile_h = tile_h;

return OAPV_OK;
}

static int enc_read_param(oapve_ctx_t *ctx, oapve_param_t *param)
{
/* check input parameters */
oapv_assert_rv(param->w > 0 && param->h > 0, OAPV_ERR_INVALID_ARGUMENT);
oapv_assert_rv(param->qp >= MIN_QUANT && param->qp <= MAX_QUANT(10), OAPV_ERR_INVALID_ARGUMENT);
oapv_assert_rv((param->qp >= MIN_QUANT && param->qp <= MAX_QUANT(10)) || param->qp == OAPVE_PARAM_QP_AUTO, OAPV_ERR_INVALID_ARGUMENT);

ctx->qp_offset[Y_C] = 0;
ctx->qp_offset[U_C] = param->qp_offset_c1;
Expand Down Expand Up @@ -732,7 +699,9 @@ static void enc_flush(oapve_ctx_t *ctx)
}
}

oapv_tpool_sync_obj_delete(&ctx->sync_obj);
if (ctx->sync_obj != NULL) {
oapv_tpool_sync_obj_delete(&ctx->sync_obj);
}
for(int i = 0; i < ctx->threads; i++) {
enc_core_free(ctx->core[i]);
ctx->core[i] = NULL;
Expand All @@ -747,20 +716,8 @@ static int enc_ready(oapve_ctx_t *ctx)
int ret = OAPV_OK;
oapv_assert(ctx->core[0] == NULL);

int min_num_tiles = OAPV_MAX_TILES;
for (int i = 0; i < ctx->cdesc.max_num_frms; i++) {
enc_update_param(ctx, &ctx->cdesc.param[i]);
int num_tiles = oapv_div_round_up(ctx->w, ctx->cdesc.param[i].tile_w) * oapv_div_round_up(ctx->h, ctx->cdesc.param[i].tile_h);
min_num_tiles = oapv_min(min_num_tiles, num_tiles);
}

if(ctx->cdesc.threads == OAPV_CDESC_THREADS_AUTO) {
int num_cores = oapv_get_num_cpu_cores();
ctx->threads = oapv_min(OAPV_MAX_THREADS, oapv_min(num_cores, min_num_tiles));
}
else {
ctx->threads = ctx->cdesc.threads;
}
ret = oapve_param_update(ctx);
oapv_assert_g(ret == OAPV_OK, ERR);

for(int i = 0; i < ctx->threads; i++) {
core = enc_core_alloc();
Expand Down Expand Up @@ -797,7 +754,6 @@ static int enc_ready(oapve_ctx_t *ctx)

return OAPV_OK;
ERR:

enc_flush(ctx);

return ret;
Expand Down Expand Up @@ -1183,7 +1139,12 @@ static int enc_frame(oapve_ctx_t *ctx)
}

ctx->rc_param.lambda = oapve_rc_estimate_pic_lambda(ctx, cost_sum);
ctx->rc_param.qp = oapve_rc_estimate_pic_qp(ctx->rc_param.lambda);
if (ctx->param->qp == OAPVE_PARAM_QP_AUTO || ctx->rc_param.is_updated != 0) {
ctx->rc_param.qp = oapve_rc_estimate_pic_qp(ctx->rc_param.lambda);
}
else {
ctx->rc_param.qp = ctx->param->qp;
}

for(int c = 0; c < ctx->num_comp; c++) {
ctx->qp[c] = oapv_clip3(MIN_QUANT, MAX_QUANT(10), ctx->rc_param.qp + ctx->qp_offset[c]);
Expand Down
1 change: 1 addition & 0 deletions src/oapv_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ typedef struct oapve_rc_param {
int qp;
double lambda;
double cost;
unsigned char is_updated;
} oapve_rc_param_t;

typedef struct oapve_rc_tile {
Expand Down
Loading