[test]: Use new option module

1. Use new option module in dec/enc test
2. Delete mpi_enc_multi_test and mpi_rc_test

Change-Id: Ib00020247386ee06cca2f560ae41aee8e88f47cc
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2021-12-16 11:13:26 +08:00
parent 7865f7f81b
commit 96d1664cd1
11 changed files with 819 additions and 2683 deletions

View File

@@ -32,15 +32,9 @@ add_mpp_test(mpi_dec_mt)
# mpi encoder unit test # mpi encoder unit test
add_mpp_test(mpi_enc) add_mpp_test(mpi_enc)
# mpi rc unit test
add_mpp_test(mpi_rc)
# new mpi rc unit test # new mpi rc unit test
add_mpp_test(mpi_rc2) add_mpp_test(mpi_rc2)
# new enc multi unit test
add_mpp_test(mpi_enc_multi)
# new dec multi unit test # new dec multi unit test
add_mpp_test(mpi_dec_multi) add_mpp_test(mpi_dec_multi)

View File

@@ -427,14 +427,8 @@ int main(int argc, char **argv)
// parse the cmd option // parse the cmd option
ret = mpi_dec_test_cmd_init(cmd, argc, argv); ret = mpi_dec_test_cmd_init(cmd, argc, argv);
if (ret) { if (ret)
if (ret < 0) {
mpp_err("mpi_dec_test_cmd_init: input parameter invalid\n");
}
mpi_dec_test_cmd_help();
goto RET; goto RET;
}
mpi_dec_test_cmd_options(cmd); mpi_dec_test_cmd_options(cmd);

View File

@@ -595,14 +595,8 @@ int main(int argc, char **argv)
// parse the cmd option // parse the cmd option
ret = mpi_dec_test_cmd_init(cmd, argc, argv); ret = mpi_dec_test_cmd_init(cmd, argc, argv);
if (ret) { if (ret)
if (ret < 0) {
mpp_err("mpi_dec_multi_test_parse_options: input parameter invalid\n");
}
mpi_dec_test_cmd_help();
goto RET; goto RET;
}
mpi_dec_test_cmd_options(cmd); mpi_dec_test_cmd_options(cmd);

View File

@@ -716,14 +716,8 @@ int main(int argc, char **argv)
// parse the cmd option // parse the cmd option
ret = mpi_dec_test_cmd_init(cmd, argc, argv); ret = mpi_dec_test_cmd_init(cmd, argc, argv);
if (ret) { if (ret)
if (ret < 0) {
mpp_err("mpi_dec_test_cmd_init: input parameter invalid\n");
}
mpi_dec_test_cmd_help();
goto RET; goto RET;
}
mpi_dec_test_cmd_options(cmd); mpi_dec_test_cmd_options(cmd);

File diff suppressed because it is too large Load Diff

View File

@@ -35,20 +35,26 @@
#include "mpp_enc_roi_utils.h" #include "mpp_enc_roi_utils.h"
typedef struct { typedef struct {
// base flow context
MppCtx ctx;
MppApi *mpi;
RK_S32 chn;
// global flow control flag // global flow control flag
RK_U32 frm_eos; RK_U32 frm_eos;
RK_U32 pkt_eos; RK_U32 pkt_eos;
RK_U32 frm_pkt_cnt; RK_U32 frm_pkt_cnt;
RK_S32 frame_num;
RK_S32 frame_count; RK_S32 frame_count;
RK_U64 stream_size; RK_U64 stream_size;
/* end of encoding flag when set quit the loop */
volatile RK_U32 loop_end;
// src and dst // src and dst
FILE *fp_input; FILE *fp_input;
FILE *fp_output; FILE *fp_output;
// base flow context /* encoder config set */
MppCtx ctx;
MppApi *mpi;
MppEncCfg cfg; MppEncCfg cfg;
MppEncPrepCfg prep_cfg; MppEncPrepCfg prep_cfg;
MppEncRcCfg rc_cfg; MppEncRcCfg rc_cfg;
@@ -74,7 +80,6 @@ typedef struct {
RK_U32 ver_stride; RK_U32 ver_stride;
MppFrameFormat fmt; MppFrameFormat fmt;
MppCodingType type; MppCodingType type;
RK_S32 num_frames;
RK_S32 loop_times; RK_S32 loop_times;
CamSource *cam_ctx; CamSource *cam_ctx;
MppEncRoiCtx roi_ctx; MppEncRoiCtx roi_ctx;
@@ -94,7 +99,6 @@ typedef struct {
RK_U32 roi_enable; RK_U32 roi_enable;
// rate control runtime parameter // rate control runtime parameter
RK_S32 fps_in_flex; RK_S32 fps_in_flex;
RK_S32 fps_in_den; RK_S32 fps_in_den;
RK_S32 fps_in_num; RK_S32 fps_in_num;
@@ -108,25 +112,37 @@ typedef struct {
RK_S32 gop_mode; RK_S32 gop_mode;
RK_S32 gop_len; RK_S32 gop_len;
RK_S32 vi_len; RK_S32 vi_len;
RK_S64 first_frm;
RK_S64 first_pkt;
} MpiEncTestData; } MpiEncTestData;
MPP_RET test_ctx_init(MpiEncTestData **data, MpiEncTestArgs *cmd) /* For each instance thread return value */
typedef struct {
float frame_rate;
RK_U64 bit_rate;
RK_S64 elapsed_time;
RK_S32 frame_count;
RK_S64 stream_size;
RK_S64 delay;
} MpiEncMultiCtxRet;
typedef struct {
MpiEncTestArgs *cmd; // pointer to global command line info
const char *name;
RK_S32 chn;
pthread_t thd; // thread for for each instance
MpiEncTestData ctx; // context of encoder
MpiEncMultiCtxRet ret; // return of encoder
} MpiEncMultiCtxInfo;
MPP_RET test_ctx_init(MpiEncMultiCtxInfo *info)
{ {
MpiEncTestData *p = NULL; MpiEncTestArgs *cmd = info->cmd;
MpiEncTestData *p = &info->ctx;
MPP_RET ret = MPP_OK; MPP_RET ret = MPP_OK;
if (!data || !cmd) {
mpp_err_f("invalid input data %p cmd %p\n", data, cmd);
return MPP_ERR_NULL_PTR;
}
p = mpp_calloc(MpiEncTestData, 1);
if (!p) {
mpp_err_f("create MpiEncTestData failed\n");
ret = MPP_ERR_MALLOC;
goto RET;
}
// get paramter from cmd // get paramter from cmd
p->width = cmd->width; p->width = cmd->width;
p->height = cmd->height; p->height = cmd->height;
@@ -140,10 +156,10 @@ MPP_RET test_ctx_init(MpiEncTestData **data, MpiEncTestArgs *cmd)
p->bps_min = cmd->bps_min; p->bps_min = cmd->bps_min;
p->bps_max = cmd->bps_max; p->bps_max = cmd->bps_max;
p->rc_mode = cmd->rc_mode; p->rc_mode = cmd->rc_mode;
p->num_frames = cmd->num_frames; p->frame_num = cmd->frame_num;
if (cmd->type == MPP_VIDEO_CodingMJPEG && p->num_frames == 0) { if (cmd->type == MPP_VIDEO_CodingMJPEG && p->frame_num == 0) {
mpp_log("jpege default encode only one frame. Use -n [num] for rc case\n"); mpp_log("jpege default encode only one frame. Use -n [num] for rc case\n");
p->num_frames = 1; p->frame_num = 1;
} }
p->gop_mode = cmd->gop_mode; p->gop_mode = cmd->gop_mode;
p->gop_len = cmd->gop_len; p->gop_len = cmd->gop_len;
@@ -212,20 +228,11 @@ MPP_RET test_ctx_init(MpiEncTestData **data, MpiEncTestArgs *cmd)
else else
p->header_size = 0; p->header_size = 0;
RET:
*data = p;
return ret; return ret;
} }
MPP_RET test_ctx_deinit(MpiEncTestData **data) MPP_RET test_ctx_deinit(MpiEncTestData *p)
{ {
MpiEncTestData *p = NULL;
if (!data) {
mpp_err_f("invalid input data %p\n", data);
return MPP_ERR_NULL_PTR;
}
p = *data;
if (p) { if (p) {
if (p->cam_ctx) { if (p->cam_ctx) {
camera_source_deinit(p->cam_ctx); camera_source_deinit(p->cam_ctx);
@@ -239,25 +246,19 @@ MPP_RET test_ctx_deinit(MpiEncTestData **data)
fclose(p->fp_output); fclose(p->fp_output);
p->fp_output = NULL; p->fp_output = NULL;
} }
MPP_FREE(p);
*data = NULL;
} }
return MPP_OK; return MPP_OK;
} }
MPP_RET test_mpp_enc_cfg_setup(MpiEncTestData *p) MPP_RET test_mpp_enc_cfg_setup(MpiEncMultiCtxInfo *info)
{ {
MpiEncTestArgs *cmd = info->cmd;
MpiEncTestData *p = &info->ctx;
MppApi *mpi = p->mpi;
MppCtx ctx = p->ctx;
MppEncCfg cfg = p->cfg;
RK_U32 quiet = cmd->quiet;
MPP_RET ret; MPP_RET ret;
MppApi *mpi;
MppCtx ctx;
MppEncCfg cfg;
if (NULL == p)
return MPP_ERR_NULL_PTR;
mpi = p->mpi;
ctx = p->ctx;
cfg = p->cfg;
/* setup default parameter */ /* setup default parameter */
if (p->fps_in_den == 0) if (p->fps_in_den == 0)
@@ -405,7 +406,7 @@ MPP_RET test_mpp_enc_cfg_setup(MpiEncTestData *p)
mpp_env_get_u32("split_arg", &p->split_arg, 0); mpp_env_get_u32("split_arg", &p->split_arg, 0);
if (p->split_mode) { if (p->split_mode) {
mpp_log("%p split_mode %d split_arg %d\n", ctx, p->split_mode, p->split_arg); mpp_log_q(quiet, "%p split_mode %d split_arg %d\n", ctx, p->split_mode, p->split_arg);
mpp_enc_cfg_set_s32(cfg, "split:mode", p->split_mode); mpp_enc_cfg_set_s32(cfg, "split:mode", p->split_mode);
mpp_enc_cfg_set_s32(cfg, "split:arg", p->split_arg); mpp_enc_cfg_set_s32(cfg, "split:arg", p->split_arg);
} }
@@ -469,18 +470,16 @@ RET:
return ret; return ret;
} }
MPP_RET test_mpp_run(MpiEncTestData *p) MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info)
{ {
MPP_RET ret = MPP_OK; MpiEncTestArgs *cmd = info->cmd;
MppApi *mpi; MpiEncTestData *p = &info->ctx;
MppCtx ctx; MppApi *mpi = p->mpi;
MppCtx ctx = p->ctx;
RK_U32 quiet = cmd->quiet;
RK_S32 chn = info->chn;
RK_U32 cap_num = 0; RK_U32 cap_num = 0;
MPP_RET ret = MPP_OK;
if (NULL == p)
return MPP_ERR_NULL_PTR;
mpi = p->mpi;
ctx = p->ctx;
if (p->type == MPP_VIDEO_CodingAVC || p->type == MPP_VIDEO_CodingHEVC) { if (p->type == MPP_VIDEO_CodingAVC || p->type == MPP_VIDEO_CodingHEVC) {
MppPacket packet = NULL; MppPacket packet = NULL;
@@ -525,14 +524,14 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
if (ret == MPP_NOK || feof(p->fp_input)) { if (ret == MPP_NOK || feof(p->fp_input)) {
p->frm_eos = 1; p->frm_eos = 1;
if (p->num_frames < 0 || p->frame_count < p->num_frames) { if (p->frame_num < 0 || p->frame_count < p->frame_num) {
clearerr(p->fp_input); clearerr(p->fp_input);
rewind(p->fp_input); rewind(p->fp_input);
p->frm_eos = 0; p->frm_eos = 0;
mpp_log("%p loop times %d\n", ctx, ++p->loop_times); mpp_log_q(quiet, "chn %d loop times %d\n", chn, ++p->loop_times);
continue; continue;
} }
mpp_log("%p found last frame. feof %d\n", ctx, feof(p->fp_input)); mpp_log_q(quiet, "chn %d found last frame. feof %d\n", chn, feof(p->fp_input));
} else if (ret == MPP_ERR_VALUE) } else if (ret == MPP_ERR_VALUE)
goto RET; goto RET;
} else { } else {
@@ -664,6 +663,8 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
} }
} }
if (!p->first_frm)
p->first_frm = mpp_time();
/* /*
* NOTE: in non-block mode the frame can be resent. * NOTE: in non-block mode the frame can be resent.
* The default input timeout mode is block. * The default input timeout mode is block.
@@ -673,16 +674,17 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
*/ */
ret = mpi->encode_put_frame(ctx, frame); ret = mpi->encode_put_frame(ctx, frame);
if (ret) { if (ret) {
mpp_err("mpp encode put frame failed\n"); mpp_err("chn %d encode put frame failed\n", chn);
mpp_frame_deinit(&frame); mpp_frame_deinit(&frame);
goto RET; goto RET;
} }
mpp_frame_deinit(&frame); mpp_frame_deinit(&frame);
do { do {
ret = mpi->encode_get_packet(ctx, &packet); ret = mpi->encode_get_packet(ctx, &packet);
if (ret) { if (ret) {
mpp_err("mpp encode get packet failed\n"); mpp_err("chn %d encode get packet failed\n", chn);
goto RET; goto RET;
} }
@@ -696,6 +698,9 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
RK_S32 log_size = sizeof(log_buf) - 1; RK_S32 log_size = sizeof(log_buf) - 1;
RK_S32 log_len = 0; RK_S32 log_len = 0;
if (!p->first_pkt)
p->first_pkt = mpp_time();
p->pkt_eos = mpp_packet_get_eos(packet); p->pkt_eos = mpp_packet_get_eos(packet);
if (p->fp_output) if (p->fp_output)
@@ -735,15 +740,16 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
" qp %d", avg_qp); " qp %d", avg_qp);
} }
mpp_log("%p %s\n", ctx, log_buf); mpp_log_q(quiet, "chn %d %s\n", chn, log_buf);
mpp_packet_deinit(&packet); mpp_packet_deinit(&packet);
fps_calc_inc(cmd->fps);
p->stream_size += len; p->stream_size += len;
p->frame_count += eoi; p->frame_count += eoi;
if (p->pkt_eos) { if (p->pkt_eos) {
mpp_log("%p found last packet\n", ctx); mpp_log_q(quiet, "chn %d found last packet\n", chn);
mpp_assert(p->frm_eos); mpp_assert(p->frm_eos);
} }
} }
@@ -752,10 +758,11 @@ MPP_RET test_mpp_run(MpiEncTestData *p)
if (cam_frm_idx >= 0) if (cam_frm_idx >= 0)
camera_source_put_frame(p->cam_ctx, cam_frm_idx); camera_source_put_frame(p->cam_ctx, cam_frm_idx);
if (p->num_frames > 0 && p->frame_count >= p->num_frames) { if (p->frame_num > 0 && p->frame_count >= p->frame_num)
mpp_log("%p encode max %d frames", ctx, p->frame_count); break;
if (p->loop_end)
break; break;
}
if (p->frm_eos && p->pkt_eos) if (p->frm_eos && p->pkt_eos)
break; break;
@@ -764,15 +771,21 @@ RET:
return ret; return ret;
} }
int mpi_enc_test(MpiEncTestArgs *cmd) void *enc_test(void *arg)
{ {
MPP_RET ret = MPP_OK; MpiEncMultiCtxInfo *info = (MpiEncMultiCtxInfo *)arg;
MpiEncTestData *p = NULL; MpiEncTestArgs *cmd = info->cmd;
MpiEncTestData *p = &info->ctx;
MpiEncMultiCtxRet *enc_ret = &info->ret;
MppPollType timeout = MPP_POLL_BLOCK; MppPollType timeout = MPP_POLL_BLOCK;
RK_U32 quiet = cmd->quiet;
MPP_RET ret = MPP_OK;
RK_S64 t_s = 0;
RK_S64 t_e = 0;
mpp_log("mpi_enc_test start\n"); mpp_log_q(quiet, "%s start\n", info->name);
ret = test_ctx_init(&p, cmd); ret = test_ctx_init(info);
if (ret) { if (ret) {
mpp_err_f("test data init failed ret %d\n", ret); mpp_err_f("test data init failed ret %d\n", ret);
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
@@ -803,7 +816,7 @@ int mpi_enc_test(MpiEncTestArgs *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
mpp_log("%p mpi_enc_test encoder test start w %d h %d type %d\n", mpp_log_q(quiet, "%p encoder test start w %d h %d type %d\n",
p->ctx, p->width, p->height, p->type); p->ctx, p->width, p->height, p->type);
ret = p->mpi->control(p->ctx, MPP_SET_OUTPUT_TIMEOUT, &timeout); ret = p->mpi->control(p->ctx, MPP_SET_OUTPUT_TIMEOUT, &timeout);
@@ -824,13 +837,15 @@ int mpi_enc_test(MpiEncTestArgs *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
ret = test_mpp_enc_cfg_setup(p); ret = test_mpp_enc_cfg_setup(info);
if (ret) { if (ret) {
mpp_err_f("test mpp setup failed ret %d\n", ret); mpp_err_f("test mpp setup failed ret %d\n", ret);
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
ret = test_mpp_run(p); t_s = mpp_time();
ret = test_mpp_run(info);
t_e = mpp_time();
if (ret) { if (ret) {
mpp_err_f("test mpp run failed ret %d\n", ret); mpp_err_f("test mpp run failed ret %d\n", ret);
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
@@ -842,14 +857,14 @@ int mpi_enc_test(MpiEncTestArgs *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
MPP_TEST_OUT: enc_ret->elapsed_time = t_e - t_s;
if (MPP_OK == ret) enc_ret->frame_count = p->frame_count;
mpp_log("%p mpi_enc_test success total frame %d bps %lld\n", enc_ret->stream_size = p->stream_size;
p->ctx, p->frame_count, enc_ret->frame_rate = (float)p->frame_count * 1000000 / enc_ret->elapsed_time;
(RK_U64)((p->stream_size * 8 * (p->fps_out_num / p->fps_out_den)) / p->frame_count)); enc_ret->bit_rate = (p->stream_size * 8 * (p->fps_out_num / p->fps_out_den)) / p->frame_count;
else enc_ret->delay = p->first_pkt - p->first_frm;
mpp_err("%p mpi_enc_test failed ret %d\n", p->ctx, ret);
MPP_TEST_OUT:
if (p->ctx) { if (p->ctx) {
mpp_destroy(p->ctx); mpp_destroy(p->ctx);
p->ctx = NULL; p->ctx = NULL;
@@ -885,7 +900,64 @@ MPP_TEST_OUT:
p->roi_ctx = NULL; p->roi_ctx = NULL;
} }
test_ctx_deinit(&p); test_ctx_deinit(p);
return NULL;
}
int enc_test_multi(MpiEncTestArgs* cmd, const char *name)
{
MpiEncMultiCtxInfo *ctxs = NULL;
float total_rate = 0.0;
RK_S32 ret = MPP_NOK;
RK_S32 i = 0;
ctxs = mpp_calloc(MpiEncMultiCtxInfo, cmd->nthreads);
if (NULL == ctxs) {
mpp_err("failed to alloc context for instances\n");
return -1;
}
for (i = 0; i < cmd->nthreads; i++) {
ctxs[i].cmd = cmd;
ctxs[i].name = name;
ctxs[i].chn = i;
ret = pthread_create(&ctxs[i].thd, NULL, enc_test, &ctxs[i]);
if (ret) {
mpp_err("failed to create thread %d\n", i);
return ret;
}
}
if (cmd->frame_num < 0) {
// wait for input then quit encoding
mpp_log("*******************************************\n");
mpp_log("**** Press Enter to stop loop encoding ****\n");
mpp_log("*******************************************\n");
getc(stdin);
for (i = 0; i < cmd->nthreads; i++)
ctxs[i].ctx.loop_end = 1;
}
for (i = 0; i < cmd->nthreads; i++)
pthread_join(ctxs[i].thd, NULL);
for (i = 0; i < cmd->nthreads; i++) {
MpiEncMultiCtxRet *enc_ret = &ctxs[i].ret;
mpp_log("chn %d encode %d frames time %lld ms delay %3d ms fps %3.2f bps %lld\n",
i, enc_ret->frame_count, (RK_S64)(enc_ret->elapsed_time / 1000),
(RK_S32)(enc_ret->delay / 1000), enc_ret->frame_rate, enc_ret->bit_rate);
total_rate += enc_ret->frame_rate;
}
MPP_FREE(ctxs);
total_rate /= cmd->nthreads;
mpp_log("%s average frame rate %.2f\n", name, total_rate);
return ret; return ret;
} }
@@ -895,20 +967,14 @@ int main(int argc, char **argv)
RK_S32 ret = MPP_NOK; RK_S32 ret = MPP_NOK;
MpiEncTestArgs* cmd = mpi_enc_test_cmd_get(); MpiEncTestArgs* cmd = mpi_enc_test_cmd_get();
memset((void*)cmd, 0, sizeof(*cmd));
// parse the cmd option // parse the cmd option
if (argc > 1)
ret = mpi_enc_test_cmd_update_by_args(cmd, argc, argv); ret = mpi_enc_test_cmd_update_by_args(cmd, argc, argv);
if (ret)
if (ret) {
mpi_enc_test_help();
goto DONE; goto DONE;
}
mpi_enc_test_cmd_show_opt(cmd); mpi_enc_test_cmd_show_opt(cmd);
ret = mpi_enc_test(cmd); ret = enc_test_multi(cmd, argv[0]);
DONE: DONE:
mpi_enc_test_cmd_put(cmd); mpi_enc_test_cmd_put(cmd);

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,7 @@
#include "mpp_common.h" #include "mpp_common.h"
#include "mpp_buffer.h" #include "mpp_buffer.h"
#include "mpp_opt.h"
#include "mpi_dec_utils.h" #include "mpi_dec_utils.h"
#define IVF_HEADER_LENGTH 32 #define IVF_HEADER_LENGTH 32
@@ -434,158 +435,233 @@ void show_dec_fps(RK_S64 total_time, RK_S64 total_count, RK_S64 last_time, RK_S6
total_count, avg_fps, ins_fps); total_count, avg_fps, ins_fps);
} }
void mpi_dec_test_cmd_help() RK_S32 mpi_dec_opt_i(void *ctx, const char *next)
{ {
mpp_log("usage: mpi_dec_test [options]\n"); MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
show_options(mpi_dec_cmd);
mpp_show_support_format();
}
RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv)
{
const char *opt;
const char *next;
RK_S32 optindex = 1;
RK_S32 handleoptions = 1;
RK_S32 err = MPP_OK;
if ((argc < 2) || (cmd == NULL)) {
err = 1;
return err;
}
/* parse options */
while (optindex < argc) {
opt = (const char*)argv[optindex++];
next = (const char*)argv[optindex];
if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
if (opt[1] == '-') {
if (opt[2] != '\0') {
opt++;
} else {
handleoptions = 0;
continue;
}
}
opt++;
switch (*opt) {
case 'i' : {
if (next) { if (next) {
strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1); strncpy(cmd->file_input, next, MAX_FILE_NAME_LENGTH - 1);
cmd->have_input = 1; cmd->have_input = 1;
name_to_coding_type(cmd->file_input, &cmd->type); name_to_coding_type(cmd->file_input, &cmd->type);
} else { return 1;
mpp_err("input file is invalid\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'o' : { mpp_err("input file is invalid\n");
return 0;
}
RK_S32 mpi_dec_opt_o(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) { if (next) {
strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1); strncpy(cmd->file_output, next, MAX_FILE_NAME_LENGTH - 1);
cmd->have_output = 1; cmd->have_output = 1;
} else { return 1;
mpp_log("output file is invalid\n");
goto PARSE_OPINIONS_OUT;
}
} break;
case 'w' : {
if (next) {
cmd->width = atoi(next);
} else {
mpp_err("invalid input width\n");
goto PARSE_OPINIONS_OUT;
}
} break;
case 'h' : {
if ((*(opt + 1) != '\0') && !strncmp(opt, "help", 4)) {
mpi_dec_test_cmd_help();
err = 1;
goto PARSE_OPINIONS_OUT;
} else if (next) {
cmd->height = atoi(next);
} else {
mpp_log("input height is invalid\n");
goto PARSE_OPINIONS_OUT;
}
} break;
case 't' : {
if (next) {
cmd->type = (MppCodingType)atoi(next);
err = mpp_check_support_format(MPP_CTX_DEC, cmd->type);
} }
if (!next || err) { mpp_log("output file is invalid\n");
mpp_err("invalid input coding type\n"); return 0;
goto PARSE_OPINIONS_OUT; }
RK_S32 mpi_dec_opt_w(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) {
cmd->width = atoi(next);
return 1;
} }
} break;
case 'f' : { mpp_err("invalid input width\n");
return 0;
}
RK_S32 mpi_dec_opt_h(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) {
cmd->height = atoi(next);
return 1;
}
mpp_err("invalid input height\n");
return 0;
}
RK_S32 mpi_dec_opt_t(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) {
MPP_RET ret;
cmd->type = (MppCodingType)atoi(next);
ret = mpp_check_support_format(MPP_CTX_DEC, cmd->type);
if (!ret)
return 1;
}
mpp_err("invalid input coding type\n");
return 0;
}
RK_S32 mpi_dec_opt_f(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) { if (next) {
cmd->format = (MppFrameFormat)atoi(next); cmd->format = (MppFrameFormat)atoi(next);
if (!MPP_FRAME_FMT_IS_YUV(cmd->format) && if (MPP_FRAME_FMT_IS_YUV(cmd->format) ||
!MPP_FRAME_FMT_IS_RGB(cmd->format)) MPP_FRAME_FMT_IS_RGB(cmd->format))
err = 1; return 1;
} }
if (!next || err) {
mpp_err("invalid output format\n"); mpp_err("invalid output format\n");
cmd->format = MPP_FMT_BUTT; cmd->format = MPP_FMT_BUTT;
goto PARSE_OPINIONS_OUT; return 0;
} }
} break;
case 'x' : { RK_S32 mpi_dec_opt_n(void *ctx, const char *next)
if (next) { {
cmd->timeout = atoi(next); MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
}
if (!next || cmd->timeout < 0) {
mpp_err("invalid output timeout interval\n");
goto PARSE_OPINIONS_OUT;
}
} break;
case 'n' : {
if (next) { if (next) {
cmd->frame_num = atoi(next); cmd->frame_num = atoi(next);
if (cmd->frame_num < 0) if (cmd->frame_num < 0)
mpp_log("infinite loop decoding mode\n"); mpp_log("infinite loop decoding mode\n");
} else {
mpp_err("invalid frame number\n"); return 1;
goto PARSE_OPINIONS_OUT;
} }
} break;
case 's' : { mpp_err("invalid frame number\n");
return 0;
}
RK_S32 mpi_dec_opt_s(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
cmd->nthreads = -1;
if (next) { if (next) {
cmd->nthreads = atoi(next); cmd->nthreads = atoi(next);
if (cmd->nthreads >= 1)
return 1;
} }
if (!next || cmd->nthreads < 0) {
mpp_err("invalid nthreads\n"); mpp_err("invalid nthreads %d\n", cmd->nthreads);
goto PARSE_OPINIONS_OUT; cmd->nthreads = 1;
} return 0;
} break; }
case 'v' : {
RK_S32 mpi_dec_opt_v(void *ctx, const char *next)
{
MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx;
if (next) { if (next) {
if (strstr(next, "q")) if (strstr(next, "q"))
cmd->quiet = 1; cmd->quiet = 1;
if (strstr(next, "f")) if (strstr(next, "f"))
cmd->trace_fps = 1; cmd->trace_fps = 1;
}
} break; return 1;
default : {
mpp_err("skip invalid opt %c\n", *opt);
} break;
} }
optindex++; return 0;
}
RK_S32 mpi_dec_opt_help(void *ctx, const char *next)
{
(void)ctx;
(void)next;
/* return invalid option to print help */
return -1;
}
static MppOptInfo dec_opts[] = {
{"i", "input_file", "input bitstream file", mpi_dec_opt_i},
{"o", "output_file", "output decoded frame file", mpi_dec_opt_o},
{"w", "width", "the width of input bitstream", mpi_dec_opt_w},
{"h", "height", "the height of input bitstream", mpi_dec_opt_h},
{"t", "type", "input stream coding type", mpi_dec_opt_t},
{"f", "format", "output frame format type", mpi_dec_opt_f},
{"n", "frame_number", "max output frame number", mpi_dec_opt_n},
{"s", "instance_nb", "number of instances", mpi_dec_opt_s},
{"v", "trace option", "q - quiet f - show fps", mpi_dec_opt_v},
{"help", "help", "show help", mpi_dec_opt_help},
};
static RK_U32 dec_opt_cnt = MPP_ARRAY_ELEMS(dec_opts);
RK_S32 mpi_dec_show_help(const char *name)
{
RK_U32 max_name = 1;
RK_U32 max_full_name = 1;
RK_U32 max_help = 1;
char logs[256];
RK_U32 len;
RK_U32 i;
mpp_log("usage: %s [options]\n", name);
for (i = 0; i < dec_opt_cnt; i++) {
MppOptInfo *opt = &dec_opts[i];
if (opt->name) {
len = strlen(opt->name);
if (len > max_name)
max_name = len;
}
if (opt->full_name) {
len = strlen(opt->full_name);
if (len > max_full_name)
max_full_name = len;
}
if (opt->help) {
len = strlen(opt->help);
if (len > max_help)
max_help = len;
} }
} }
err = 0; snprintf(logs, sizeof(logs) - 1, "-%%-%ds %%-%ds %%-%ds\n", max_name, max_full_name, max_help);
for (i = 0; i < dec_opt_cnt; i++) {
MppOptInfo *opt = &dec_opts[i];
mpp_log(logs, opt->name, opt->full_name, opt->help);
}
mpp_show_support_format();
return -1;
}
RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv)
{
MppOpt opts = NULL;
RK_S32 ret = -1;
RK_U32 i;
if ((argc < 2) || (cmd == NULL))
goto done;
mpp_opt_init(&opts);
/* should change node count when option increases */
mpp_opt_setup(opts, cmd, 18, dec_opt_cnt);
for (i = 0; i < dec_opt_cnt; i++)
mpp_opt_add(opts, &dec_opts[i]);
/* mark option end */
mpp_opt_add(opts, NULL);
ret = mpp_opt_parse(opts, argc, argv);
PARSE_OPINIONS_OUT:
if (cmd->have_input) { if (cmd->have_input) {
reader_init(&cmd->reader, cmd->file_input); reader_init(&cmd->reader, cmd->file_input);
if (cmd->reader) if (cmd->reader)
@@ -597,7 +673,16 @@ PARSE_OPINIONS_OUT:
fps_calc_set_cb(cmd->fps, show_dec_fps); fps_calc_set_cb(cmd->fps, show_dec_fps);
} }
return err; done:
if (opts) {
mpp_opt_deinit(opts);
opts = NULL;
}
if (ret)
mpi_dec_show_help(argv[0]);
return ret;
} }
RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd) RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd)

View File

@@ -61,7 +61,6 @@ typedef struct MpiDecTestCmd_t {
FpsCalc fps; FpsCalc fps;
/* runtime log flag */ /* runtime log flag */
RK_U32 debug;
RK_U32 quiet; RK_U32 quiet;
RK_U32 trace_fps; RK_U32 trace_fps;
} MpiDecTestCmd; } MpiDecTestCmd;
@@ -71,7 +70,6 @@ extern OptionInfo mpi_dec_cmd[];
RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv); RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv);
RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd); RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd);
void mpi_dec_test_cmd_options(MpiDecTestCmd* cmd); void mpi_dec_test_cmd_options(MpiDecTestCmd* cmd);
void mpi_dec_test_cmd_help();
void reader_init(FileReader* reader, char* file_in); void reader_init(FileReader* reader, char* file_in);
void reader_deinit(FileReader reader); void reader_deinit(FileReader reader);

View File

@@ -25,6 +25,8 @@
#include "rk_mpi.h" #include "rk_mpi.h"
#include "utils.h" #include "utils.h"
#include "mpp_common.h" #include "mpp_common.h"
#include "mpp_opt.h"
#include "mpi_enc_utils.h" #include "mpi_enc_utils.h"
#define MAX_FILE_NAME_LENGTH 256 #define MAX_FILE_NAME_LENGTH 256
@@ -91,39 +93,16 @@ MpiEncTestArgs *mpi_enc_test_cmd_get(void)
{ {
MpiEncTestArgs *args = mpp_calloc(MpiEncTestArgs, 1); MpiEncTestArgs *args = mpp_calloc(MpiEncTestArgs, 1);
if (args)
args->nthreads = 1;
return args; return args;
} }
MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **argv) RK_S32 mpi_enc_opt_i(void *ctx, const char *next)
{ {
const char *opt; MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
const char *next;
RK_S32 optindex = 1;
RK_S32 handleoptions = 1;
MPP_RET ret = MPP_NOK;
if ((argc < 2) || (cmd == NULL))
return ret;
/* parse options */
while (optindex < argc) {
opt = (const char*)argv[optindex++];
next = (const char*)argv[optindex];
if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
if (opt[1] == '-') {
if (opt[2] != '\0') {
opt++;
} else {
handleoptions = 0;
continue;
}
}
opt++;
switch (*opt) {
case 'i' : {
if (next) { if (next) {
size_t len = strnlen(next, MAX_FILE_NAME_LENGTH); size_t len = strnlen(next, MAX_FILE_NAME_LENGTH);
if (len) { if (len) {
@@ -131,12 +110,18 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
strcpy(cmd->file_input, next); strcpy(cmd->file_input, next);
name_to_frame_format(cmd->file_input, &cmd->format); name_to_frame_format(cmd->file_input, &cmd->format);
} }
} else {
mpp_err("input file is invalid\n"); return 1;
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'o' : { mpp_err("input file is invalid\n");
return 0;
}
RK_S32 mpi_enc_opt_o(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
size_t len = strnlen(next, MAX_FILE_NAME_LENGTH); size_t len = strnlen(next, MAX_FILE_NAME_LENGTH);
if (len) { if (len) {
@@ -144,50 +129,75 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
strcpy(cmd->file_output, next); strcpy(cmd->file_output, next);
name_to_coding_type(cmd->file_output, &cmd->type); name_to_coding_type(cmd->file_output, &cmd->type);
} }
} else {
mpp_log("output file is invalid\n"); return 1;
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'w' : { mpp_log("output file is invalid\n");
return 0;
}
RK_S32 mpi_enc_opt_w(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
cmd->width = atoi(next); cmd->width = atoi(next);
} else { return 1;
mpp_err("invalid input width\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'h' : {
if (!next)
goto PARSE_OPINIONS_OUT;
if ((*(opt + 1) != '\0') && !strncmp(opt, "help", 4)) { mpp_err("invalid input width\n");
goto PARSE_OPINIONS_OUT; return 0;
} else if (next) { }
RK_S32 mpi_enc_opt_h(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) {
cmd->height = atoi(next); cmd->height = atoi(next);
return 1;
} }
} break;
case 'u' : { mpp_err("invalid input height\n");
return 0;
}
RK_S32 mpi_enc_opt_hstride(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
cmd->hor_stride = atoi(next); cmd->hor_stride = atoi(next);
} else { return 1;
mpp_err("invalid input width\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'v' : { mpp_err("invalid input horizontal stride\n");
return 0;
}
RK_S32 mpi_enc_opt_vstride(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
cmd->ver_stride = atoi(next); cmd->ver_stride = atoi(next);
} else { return 1;
mpp_log("input height is invalid\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'f' : { mpp_err("invalid input vertical stride\n");
return 0;
}
RK_S32 mpi_enc_opt_f(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
MppFrameFormat format = MPP_FMT_BUTT;
if (next) { if (next) {
if (strstr(next, "x") || strstr(next, "X")) { if (strstr(next, "x") || strstr(next, "X")) {
/* hex value with 0x prefix, use sscanf */ /* hex value with 0x prefix, use sscanf */
sscanf(next, "0x%x", &cmd->format); sscanf(next, "0x%x", &format);
} else if (strstr(next, "a") || strstr(next, "A") || } else if (strstr(next, "a") || strstr(next, "A") ||
strstr(next, "b") || strstr(next, "B") || strstr(next, "b") || strstr(next, "B") ||
strstr(next, "c") || strstr(next, "C") || strstr(next, "c") || strstr(next, "C") ||
@@ -195,68 +205,92 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
strstr(next, "e") || strstr(next, "E") || strstr(next, "e") || strstr(next, "E") ||
strstr(next, "f") || strstr(next, "F")) { strstr(next, "f") || strstr(next, "F")) {
/* hex value without 0x prefix, use sscanf */ /* hex value without 0x prefix, use sscanf */
sscanf(next, "%x", &cmd->format); sscanf(next, "%x", &format);
} else { } else {
/* decimal value, use atoi */ /* decimal value, use atoi */
cmd->format = (MppFrameFormat)atoi(next); format = (MppFrameFormat)atoi(next);
}
if (MPP_FRAME_FMT_IS_LE(format) &&
(MPP_FRAME_FMT_IS_YUV(format) || MPP_FRAME_FMT_IS_RGB(format))) {
cmd->format = format;
return 1;
} }
ret = (!MPP_FRAME_FMT_IS_LE(cmd->format)) && ((cmd->format >= MPP_FMT_YUV_BUTT && cmd->format < MPP_FRAME_FMT_RGB) ||
cmd->format >= MPP_FMT_RGB_BUTT);
} }
if (!next || ret) { mpp_err("invalid input format %x\n", format);
mpp_err("invalid input format %d\n", cmd->format); cmd->format = MPP_FMT_YUV420SP;
goto PARSE_OPINIONS_OUT; return 0;
} }
} break;
case 't' : { RK_S32 mpi_enc_opt_t(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
MppCodingType type = MPP_VIDEO_CodingUnused;
if (next) { if (next) {
cmd->type = (MppCodingType)atoi(next); type = (MppCodingType)atoi(next);
ret = mpp_check_support_format(MPP_CTX_ENC, cmd->type); if (!mpp_check_support_format(MPP_CTX_ENC, type))
cmd->type = type;
return 1;
} }
if (!next || ret) { mpp_err("invalid input coding type %d\n", type);
mpp_err("invalid input coding type\n"); return 0;
goto PARSE_OPINIONS_OUT; }
}
} break; RK_S32 mpi_enc_opt_n(void *ctx, const char *next)
case 'n' : { {
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
cmd->num_frames = atoi(next); cmd->frame_num = atoi(next);
} else { return 1;
}
mpp_err("invalid input max number of frames\n"); mpp_err("invalid input max number of frames\n");
goto PARSE_OPINIONS_OUT; return 0;
} }
} break;
case 'g' : { RK_S32 mpi_enc_opt_g(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
RK_S32 cnt = 0; RK_S32 cnt = 0;
if (next) if (next) {
cnt = sscanf(next, "%d:%d:%d", cnt = sscanf(next, "%d:%d:%d",
&cmd->gop_mode, &cmd->gop_len, &cmd->vi_len); &cmd->gop_mode, &cmd->gop_len, &cmd->vi_len);
if (cnt)
if (!cnt) { return 1;
mpp_err("invalid gop mode use -g gop_mode:gop_len:vi_len\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'b' : { mpp_err("invalid gop mode use -g gop_mode:gop_len:vi_len\n");
return 0;
}
RK_S32 mpi_enc_opt_bps(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
RK_S32 cnt = 0; RK_S32 cnt = 0;
if (next) if (next) {
cnt = sscanf(next, "%d:%d:%d:%d", cnt = sscanf(next, "%d:%d:%d:%d",
&cmd->bps_target, &cmd->bps_min, &cmd->bps_max, &cmd->bps_target, &cmd->bps_min, &cmd->bps_max,
&cmd->rc_mode); &cmd->rc_mode);
if (cnt)
return 1;
}
if (!cnt) {
mpp_err("invalid bit rate usage -b bps_target:bps_min:bps_max:rc_mode\n"); mpp_err("invalid bit rate usage -b bps_target:bps_min:bps_max:rc_mode\n");
mpp_err("rc_mode 0:vbr 1:cbr 2:avbr 3:cvbr 4:fixqp\n"); mpp_err("rc_mode 0:vbr 1:cbr 2:avbr 3:cvbr 4:fixqp\n");
goto PARSE_OPINIONS_OUT; return 0;
} }
} break;
case 'r' : { RK_S32 mpi_enc_opt_fps(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
RK_S32 num = sscanf(next, "%d:%d:%d/%d:%d:%d", RK_U32 num = sscanf(next, "%d:%d:%d/%d:%d:%d",
&cmd->fps_in_num, &cmd->fps_in_den, &cmd->fps_in_flex, &cmd->fps_in_num, &cmd->fps_in_den, &cmd->fps_in_flex,
&cmd->fps_out_num, &cmd->fps_out_den, &cmd->fps_out_flex); &cmd->fps_out_num, &cmd->fps_out_den, &cmd->fps_out_flex);
switch (num) { switch (num) {
@@ -290,45 +324,183 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
" for set the input to the same fps as the output, such as 50:1:1\n" " for set the input to the same fps as the output, such as 50:1:1\n"
" or \"-r numerator:denominator/flex-numerator:denominator:flex\"" " or \"-r numerator:denominator/flex-numerator:denominator:flex\""
" for set input and output separately, such as 40:1:1/30:1:0\n"); " for set input and output separately, such as 40:1:1/30:1:0\n");
goto PARSE_OPINIONS_OUT;
} break; } break;
} }
} else {
return (num && num <= 6);
}
mpp_err("invalid output frame rate\n"); mpp_err("invalid output frame rate\n");
goto PARSE_OPINIONS_OUT; return 0;
}
RK_S32 mpi_enc_opt_s(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
cmd->nthreads = -1;
if (next) {
cmd->nthreads = atoi(next);
if (cmd->nthreads >= 1)
return 1;
} }
} break;
case 'l' : { mpp_err("invalid nthreads %d\n", cmd->nthreads);
cmd->nthreads = 1;
return 0;
}
RK_S32 mpi_enc_opt_l(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
cmd->loop_cnt = atoi(next); cmd->loop_cnt = atoi(next);
} else { return 1;
mpp_err("invalid loop count\n");
goto PARSE_OPINIONS_OUT;
} }
} break;
case 'x': { mpp_err("invalid loop count\n");
return 0;
}
RK_S32 mpi_enc_opt_v(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) {
if (strstr(next, "q"))
cmd->quiet = 1;
if (strstr(next, "f"))
cmd->trace_fps = 1;
return 1;
}
return 0;
}
RK_S32 mpi_enc_opt_ini(void *ctx, const char *next)
{
MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx;
if (next) { if (next) {
size_t len = strnlen(next, MAX_FILE_NAME_LENGTH); size_t len = strnlen(next, MAX_FILE_NAME_LENGTH);
if (len) { if (len) {
cmd->file_cfg = mpp_calloc(char, len + 1); cmd->file_cfg = mpp_calloc(char, len + 1);
strncpy(cmd->file_cfg, next, len); strncpy(cmd->file_cfg, next, len);
cmd->cfg_ini = iniparser_load(cmd->file_cfg); cmd->cfg_ini = iniparser_load(cmd->file_cfg);
}
} else {
mpp_err("input file is invalid\n");
goto PARSE_OPINIONS_OUT;
}
} break;
default : {
mpp_err("skip invalid opt %c\n", *opt);
} break;
}
optindex++; return 1;
} }
} }
ret = MPP_OK; mpp_err("input ini file is invalid\n");
return 0;
}
RK_S32 mpi_enc_opt_help(void *ctx, const char *next)
{
(void)ctx;
(void)next;
return -1;
}
static MppOptInfo enc_opts[] = {
{"i", "input_file", "input frame file", mpi_enc_opt_i},
{"o", "output_file", "output encoded bitstream file", mpi_enc_opt_o},
{"w", "width", "the width of input picture", mpi_enc_opt_w},
{"h", "height", "the height of input picture", mpi_enc_opt_h},
{"hstride", "hor_stride", "the horizontal stride of input picture", mpi_enc_opt_hstride},
{"vstride", "ver_stride", "the vertical stride of input picture", mpi_enc_opt_vstride},
{"f", "format", "the format of input picture", mpi_enc_opt_f},
{"t", "type", "output stream coding type", mpi_enc_opt_t},
{"n", "max frame number", "max encoding frame number", mpi_enc_opt_n},
{"g", "gop reference mode", "gop_mode:gop_len:vi_len", mpi_enc_opt_g},
{"bps", "bps target:min:max", "set tareget/min/max bps and rc_mode", mpi_enc_opt_bps},
{"fps", "in/output fps", "set input and output frame rate", mpi_enc_opt_fps},
{"s", "instance_nb", "number of instances", mpi_enc_opt_s},
{"v", "trace option", "q - quiet f - show fps", mpi_enc_opt_v},
{"l", "loop count", "loop encoding times for each frame", mpi_enc_opt_l},
{"ini", "ini file", "encoder extra ini config file", mpi_enc_opt_ini},
};
static RK_U32 enc_opt_cnt = MPP_ARRAY_ELEMS(enc_opts);
RK_S32 mpi_enc_show_help(const char *name)
{
RK_U32 max_name = 1;
RK_U32 max_full_name = 1;
RK_U32 max_help = 1;
char logs[256];
RK_U32 len;
RK_U32 i;
mpp_log("usage: %s [options]\n", name);
for (i = 0; i < enc_opt_cnt; i++) {
MppOptInfo *opt = &enc_opts[i];
if (opt->name) {
len = strlen(opt->name);
if (len > max_name)
max_name = len;
}
if (opt->full_name) {
len = strlen(opt->full_name);
if (len > max_full_name)
max_full_name = len;
}
if (opt->help) {
len = strlen(opt->help);
if (len > max_help)
max_help = len;
}
}
snprintf(logs, sizeof(logs) - 1, "-%%-%ds %%-%ds %%-%ds\n", max_name, max_full_name, max_help);
for (i = 0; i < enc_opt_cnt; i++) {
MppOptInfo *opt = &enc_opts[i];
mpp_log(logs, opt->name, opt->full_name, opt->help);
}
mpp_show_support_format();
mpp_show_color_format();
return -1;
}
void show_enc_fps(RK_S64 total_time, RK_S64 total_count, RK_S64 last_time, RK_S64 last_count)
{
float avg_fps = (float)total_count * 1000000 / total_time;
float ins_fps = (float)last_count * 1000000 / last_time;
mpp_log("encoded %10lld frame fps avg %7.2f ins %7.2f\n",
total_count, avg_fps, ins_fps);
}
MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **argv)
{
MppOpt opts = NULL;
RK_S32 ret = -1;
RK_U32 i;
if ((argc < 2) || NULL == cmd || NULL == argv)
goto done;
mpp_opt_init(&opts);
/* should change node count when option increases */
mpp_opt_setup(opts, cmd, 50, enc_opt_cnt);
for (i = 0; i < enc_opt_cnt; i++)
mpp_opt_add(opts, &enc_opts[i]);
/* mark option end */
mpp_opt_add(opts, NULL);
ret = mpp_opt_parse(opts, argc, argv);
/* check essential parameter */ /* check essential parameter */
if (cmd->type <= MPP_VIDEO_CodingAutoDetect) { if (cmd->type <= MPP_VIDEO_CodingAutoDetect) {
@@ -347,8 +519,20 @@ MPP_RET mpi_enc_test_cmd_update_by_args(MpiEncTestArgs* cmd, int argc, char **ar
cmd->width, cmd->height, cmd->hor_stride, cmd->ver_stride); cmd->width, cmd->height, cmd->hor_stride, cmd->ver_stride);
ret = MPP_NOK; ret = MPP_NOK;
} }
if (cmd->trace_fps) {
fps_calc_init(&cmd->fps);
mpp_assert(cmd->fps);
fps_calc_set_cb(cmd->fps, show_enc_fps);
}
done:
if (opts) {
mpp_opt_deinit(opts);
opts = NULL;
}
if (ret)
mpi_enc_show_help(argv[0]);
PARSE_OPINIONS_OUT:
return ret; return ret;
} }
@@ -362,6 +546,11 @@ MPP_RET mpi_enc_test_cmd_put(MpiEncTestArgs* cmd)
cmd->cfg_ini = NULL; cmd->cfg_ini = NULL;
} }
if (cmd->fps) {
fps_calc_deinit(cmd->fps);
cmd->fps = NULL;
}
MPP_FREE(cmd->file_input); MPP_FREE(cmd->file_input);
MPP_FREE(cmd->file_output); MPP_FREE(cmd->file_output);
MPP_FREE(cmd->file_cfg); MPP_FREE(cmd->file_cfg);

View File

@@ -30,19 +30,22 @@ typedef struct MpiEncTestArgs_t {
MppCodingType type; MppCodingType type;
MppFrameFormat format; MppFrameFormat format;
RK_S32 num_frames; RK_S32 frame_num;
RK_S32 loop_cnt; RK_S32 loop_cnt;
RK_S32 nthreads;
RK_S32 width; RK_S32 width;
RK_S32 height; RK_S32 height;
RK_S32 hor_stride; RK_S32 hor_stride;
RK_S32 ver_stride; RK_S32 ver_stride;
/* -bps */
RK_S32 bps_target; RK_S32 bps_target;
RK_S32 bps_max; RK_S32 bps_max;
RK_S32 bps_min; RK_S32 bps_min;
RK_S32 rc_mode; RK_S32 rc_mode;
/* -fps */
RK_S32 fps_in_flex; RK_S32 fps_in_flex;
RK_S32 fps_in_num; RK_S32 fps_in_num;
RK_S32 fps_in_den; RK_S32 fps_in_den;
@@ -50,13 +53,16 @@ typedef struct MpiEncTestArgs_t {
RK_S32 fps_out_num; RK_S32 fps_out_num;
RK_S32 fps_out_den; RK_S32 fps_out_den;
/* -g gop mode */
RK_S32 gop_mode; RK_S32 gop_mode;
RK_S32 gop_len; RK_S32 gop_len;
RK_S32 vi_len; RK_S32 vi_len;
MppEncHeaderMode header_mode; /* -v q runtime log disable flag */
RK_U32 quiet;
MppEncSliceSplit split; /* -v f runtime fps log flag */
RK_U32 trace_fps;
FpsCalc fps;
} MpiEncTestArgs; } MpiEncTestArgs;
#ifdef __cplusplus #ifdef __cplusplus