Skip to content

Commit e4fed4d

Browse files
mss-parkkpchoi
andauthored
Update param auto (#61)
* modification of default number of threads in decoder Signed-off-by: Minsoo Park <[email protected]> * modification Signed-off-by: Minsoo Park <[email protected]> * refactoring for parameter parser Signed-off-by: [email protected] <[email protected]> * normalize LF Signed-off-by: [email protected] <[email protected]> * fixed oapv_get_num_cpu_cores function for android Signed-off-by: [email protected] <[email protected]> * update to change default parameter of encoder Signed-off-by: Minsoo Park <[email protected]> * refacoring Signed-off-by: [email protected] <[email protected]> * refactoring more Signed-off-by: [email protected] <[email protected]> * fix to compile on window Signed-off-by: Minsoo Park <[email protected]> * refactor Signed-off-by: [email protected] <[email protected]> * refactor Signed-off-by: [email protected] <[email protected]> --------- Signed-off-by: Minsoo Park <[email protected]> Signed-off-by: [email protected] <[email protected]> Signed-off-by: mss-park <[email protected]> Co-authored-by: [email protected] <[email protected]>
1 parent 655d277 commit e4fed4d

File tree

8 files changed

+234
-86
lines changed

8 files changed

+234
-86
lines changed

app/oapv_app_dec.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ static const args_opt_t dec_args_opts[] = {
6969
"maximum number of access units to be decoded"
7070
},
7171
{
72-
'm', "threads", ARGS_VAL_TYPE_INTEGER, 0, NULL,
72+
'm', "threads", ARGS_VAL_TYPE_STRING, 0, NULL,
7373
"force to use a specific number of threads"
74+
" - 'auto' means that the value is internally determined"
7475
},
7576
{
7677
'd', "output-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL,
@@ -98,7 +99,7 @@ typedef struct args_var {
9899
char fname_out[256];
99100
int max_au;
100101
int hash;
101-
int threads;
102+
char threads[16];
102103
int output_depth;
103104
int output_csp;
104105
} args_var_t;
@@ -119,8 +120,8 @@ static args_var_t *args_init_vars(args_parser_t *args)
119120
args_set_variable_by_key_long(opts, "hash", &vars->hash);
120121
args_set_variable_by_key_long(opts, "verbose", &op_verbose);
121122
op_verbose = VERBOSE_SIMPLE; /* default */
122-
args_set_variable_by_key_long(opts, "threads", &vars->threads);
123-
vars->threads = OAPV_CDESC_THREADS_AUTO; /* default */
123+
args_set_variable_by_key_long(opts, "threads", vars->threads);
124+
strcpy(vars->threads, "auto");
124125
args_set_variable_by_key_long(opts, "output-depth", &vars->output_depth);
125126
args_set_variable_by_key_long(opts, "output-csp", &vars->output_csp);
126127
vars->output_csp = 0; /* default: coded CSP */
@@ -445,7 +446,12 @@ int main(int argc, const char **argv)
445446
goto ERR;
446447
}
447448
// create decoder
448-
cdesc.threads = args_var->threads;
449+
if(!strcmp(args_var->threads, "auto")){
450+
cdesc.threads = OAPV_CDESC_THREADS_AUTO;
451+
}
452+
else {
453+
cdesc.threads = atoi(args_var->threads);
454+
}
449455
did = oapvd_create(&cdesc, &ret);
450456
if(did == NULL) {
451457
logerr("ERROR: cannot create OAPV decoder (err=%d)\n", ret);

app/oapv_app_enc.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,16 @@ static const args_opt_t enc_args_opts[] = {
8282
"QP value: 0 ~ (63 + (bitdepth - 10)*6) \n"
8383
" - 10bit input: 0 ~ 63\n"
8484
" - 12bit input: 0 ~ 75"
85+
" - 'auto' means that the value is internally determined"
8586
},
8687
{
8788
'z', "fps", ARGS_VAL_TYPE_STRING | ARGS_VAL_TYPE_MANDATORY, 0, NULL,
8889
"frame rate (frame per second))"
8990
},
9091
{
91-
'm', "threads", ARGS_VAL_TYPE_INTEGER, 0, NULL,
92+
'm', "threads", ARGS_VAL_TYPE_STRING, 0, NULL,
9293
"force to use a specific number of threads\n"
93-
" - '0' means decision of the number automatically"
94+
" - 'auto' means that the value is internally determined"
9495
},
9596
{
9697
ARGS_NO_KEY, "preset", ARGS_VAL_TYPE_STRING, 0, NULL,
@@ -116,10 +117,11 @@ static const args_opt_t enc_args_opts[] = {
116117
},
117118
{
118119
ARGS_NO_KEY, "level", ARGS_VAL_TYPE_STRING, 0, NULL,
119-
"level setting (1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 6, 6.1, 7, 7.1)"
120+
"level setting (1, 1.1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 6, 6.1, 7, 7.1)\n"
121+
" - 'auto' means that the value is internally determined"
120122
},
121123
{
122-
ARGS_NO_KEY, "band", ARGS_VAL_TYPE_INTEGER, 0, NULL,
124+
ARGS_NO_KEY, "band", ARGS_VAL_TYPE_STRING, 0, NULL,
123125
"band setting (0, 1, 2, 3)"
124126
},
125127
{
@@ -193,7 +195,7 @@ typedef struct args_var {
193195
int input_depth;
194196
int input_csp;
195197
int seek;
196-
int threads;
198+
char threads[16];
197199

198200
char profile[16];
199201
char level[16];
@@ -254,7 +256,7 @@ static args_var_t *args_init_vars(args_parser_t *args, oapve_param_t *param)
254256
args_set_variable_by_key_long(opts, "profile", vars->profile);
255257
strcpy(vars->profile, "422-10");
256258
args_set_variable_by_key_long(opts, "level", vars->level);
257-
strcpy(vars->level, "4.1");
259+
strcpy(vars->level, "auto"); /* default */
258260
args_set_variable_by_key_long(opts, "band", vars->band);
259261
strcpy(vars->band, "2"); /* default */
260262

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

265267
args_set_variable_by_key_long(opts, "qp", vars->qp);
268+
strcpy(vars->qp, "auto"); /* default */
266269
args_set_variable_by_key_long(opts, "qp_offset_c1", vars->qp_offset_c1);
267270
args_set_variable_by_key_long(opts, "qp_offset_c2", vars->qp_offset_c2);
268271
args_set_variable_by_key_long(opts, "qp_offset_c3", vars->qp_offset_c3);
@@ -274,8 +277,8 @@ static args_var_t *args_init_vars(args_parser_t *args, oapve_param_t *param)
274277
args_set_variable_by_key_long(opts, "q-matrix-c2", vars->q_matrix_c2);
275278
args_set_variable_by_key_long(opts, "q-matrix-c3", vars->q_matrix_c3);
276279

277-
args_set_variable_by_key_long(opts, "threads", &vars->threads);
278-
vars->threads = OAPV_CDESC_THREADS_AUTO; /* default */
280+
args_set_variable_by_key_long(opts, "threads", vars->threads);
281+
strcpy(vars->threads, "auto");
279282

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

693696
cdesc.max_bs_buf_size = MAX_BS_BUF; /* maximum bitstream buffer size */
694697
cdesc.max_num_frms = MAX_NUM_FRMS;
695-
cdesc.threads = args_var->threads;
698+
if(!strcmp(args_var->threads, "auto")){
699+
cdesc.threads = OAPV_CDESC_THREADS_AUTO;
700+
}
701+
else {
702+
cdesc.threads = atoi(args_var->threads);
703+
}
696704

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

732740
/* create encoder */
733-
id = oapve_create(&cdesc, NULL);
741+
id = oapve_create(&cdesc, &ret);
734742
if(id == NULL) {
735743
logerr("cannot create OAPV encoder\n");
736-
ret = -1;
737744
goto ERR;
738745
}
739746

inc/oapv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern "C" {
8686
#define OAPV_ERR_OUT_OF_BS_BUF (-203) /* too small bitstream buffer */
8787
#define OAPV_ERR_NOT_FOUND (-204)
8888
#define OAPV_ERR_FAILED_SYSCALL (-301) /* failed system call */
89+
#define OAPV_ERR_INVALID_LEVEL (-401)
8990
#define OAPV_ERR_UNKNOWN (-32767) /* unknown error */
9091

9192
/* return value checking */
@@ -469,7 +470,9 @@ static const oapv_dict_str_int_t oapv_param_opts_color_matrix[] = {
469470
/*****************************************************************************
470471
* coding parameters
471472
*****************************************************************************/
472-
#define OAPV_LEVEL_TO_LEVEL_IDC(level) (int)(((level) * 30.0) + 0.5)
473+
#define OAPV_LEVEL_TO_LEVEL_IDC(level) (int)(((level) * 30.0) + 0.5)
474+
#define OAPVE_PARAM_LEVEL_IDC_AUTO (0)
475+
#define OAPVE_PARAM_QP_AUTO (255)
473476

474477
typedef struct oapve_param oapve_param_t;
475478
struct oapve_param {

src/oapv.c

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -638,44 +638,11 @@ static double enc_block_rdo_placebo(oapve_ctx_t *ctx, oapve_core_t *core, int lo
638638
return best_cost;
639639
}
640640

641-
static int enc_update_param(oapve_ctx_t* ctx, oapve_param_t* param)
642-
{
643-
/* set various value */
644-
ctx->w = oapv_div_round_up(param->w, OAPV_MB_W) * OAPV_MB_W;
645-
ctx->h = oapv_div_round_up(param->h, OAPV_MB_H) * OAPV_MB_H;
646-
647-
/* find correct tile width and height */
648-
int tile_w, tile_h;
649-
650-
oapv_assert_rv(param->tile_w >= OAPV_MIN_TILE_W && param->tile_h >= OAPV_MIN_TILE_H, OAPV_ERR_INVALID_ARGUMENT);
651-
oapv_assert_rv((param->tile_w & (OAPV_MB_W - 1)) == 0 && (param->tile_h & (OAPV_MB_H - 1)) == 0, OAPV_ERR_INVALID_ARGUMENT);
652-
653-
if (oapv_div_round_up(ctx->w, param->tile_w) > OAPV_MAX_TILE_COLS) {
654-
tile_w = oapv_div_round_up(ctx->w, OAPV_MAX_TILE_COLS);
655-
tile_w = oapv_div_round_up(tile_w, OAPV_MB_W) * OAPV_MB_W; // align to MB width
656-
}
657-
else {
658-
tile_w = param->tile_w;
659-
}
660-
param->tile_w = tile_w;
661-
662-
if (oapv_div_round_up(ctx->h, param->tile_h) > OAPV_MAX_TILE_ROWS) {
663-
tile_h = oapv_div_round_up(ctx->h, OAPV_MAX_TILE_ROWS);
664-
tile_h = oapv_div_round_up(tile_h, OAPV_MB_H) * OAPV_MB_H; // align to MB height
665-
}
666-
else {
667-
tile_h = param->tile_h;
668-
}
669-
param->tile_h = tile_h;
670-
671-
return OAPV_OK;
672-
}
673-
674641
static int enc_read_param(oapve_ctx_t *ctx, oapve_param_t *param)
675642
{
676643
/* check input parameters */
677644
oapv_assert_rv(param->w > 0 && param->h > 0, OAPV_ERR_INVALID_ARGUMENT);
678-
oapv_assert_rv(param->qp >= MIN_QUANT && param->qp <= MAX_QUANT(10), OAPV_ERR_INVALID_ARGUMENT);
645+
oapv_assert_rv((param->qp >= MIN_QUANT && param->qp <= MAX_QUANT(10)) || param->qp == OAPVE_PARAM_QP_AUTO, OAPV_ERR_INVALID_ARGUMENT);
679646

680647
ctx->qp_offset[Y_C] = 0;
681648
ctx->qp_offset[U_C] = param->qp_offset_c1;
@@ -732,7 +699,9 @@ static void enc_flush(oapve_ctx_t *ctx)
732699
}
733700
}
734701

735-
oapv_tpool_sync_obj_delete(&ctx->sync_obj);
702+
if (ctx->sync_obj != NULL) {
703+
oapv_tpool_sync_obj_delete(&ctx->sync_obj);
704+
}
736705
for(int i = 0; i < ctx->threads; i++) {
737706
enc_core_free(ctx->core[i]);
738707
ctx->core[i] = NULL;
@@ -747,20 +716,8 @@ static int enc_ready(oapve_ctx_t *ctx)
747716
int ret = OAPV_OK;
748717
oapv_assert(ctx->core[0] == NULL);
749718

750-
int min_num_tiles = OAPV_MAX_TILES;
751-
for (int i = 0; i < ctx->cdesc.max_num_frms; i++) {
752-
enc_update_param(ctx, &ctx->cdesc.param[i]);
753-
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);
754-
min_num_tiles = oapv_min(min_num_tiles, num_tiles);
755-
}
756-
757-
if(ctx->cdesc.threads == OAPV_CDESC_THREADS_AUTO) {
758-
int num_cores = oapv_get_num_cpu_cores();
759-
ctx->threads = oapv_min(OAPV_MAX_THREADS, oapv_min(num_cores, min_num_tiles));
760-
}
761-
else {
762-
ctx->threads = ctx->cdesc.threads;
763-
}
719+
ret = oapve_param_update(ctx);
720+
oapv_assert_g(ret == OAPV_OK, ERR);
764721

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

798755
return OAPV_OK;
799756
ERR:
800-
801757
enc_flush(ctx);
802758

803759
return ret;
@@ -1183,7 +1139,12 @@ static int enc_frame(oapve_ctx_t *ctx)
11831139
}
11841140

11851141
ctx->rc_param.lambda = oapve_rc_estimate_pic_lambda(ctx, cost_sum);
1186-
ctx->rc_param.qp = oapve_rc_estimate_pic_qp(ctx->rc_param.lambda);
1142+
if (ctx->param->qp == OAPVE_PARAM_QP_AUTO || ctx->rc_param.is_updated != 0) {
1143+
ctx->rc_param.qp = oapve_rc_estimate_pic_qp(ctx->rc_param.lambda);
1144+
}
1145+
else {
1146+
ctx->rc_param.qp = ctx->param->qp;
1147+
}
11871148

11881149
for(int c = 0; c < ctx->num_comp; c++) {
11891150
ctx->qp[c] = oapv_clip3(MIN_QUANT, MAX_QUANT(10), ctx->rc_param.qp + ctx->qp_offset[c]);

src/oapv_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ typedef struct oapve_rc_param {
199199
int qp;
200200
double lambda;
201201
double cost;
202+
unsigned char is_updated;
202203
} oapve_rc_param_t;
203204

204205
typedef struct oapve_rc_tile {

0 commit comments

Comments
 (0)