[test]: cleanup test code

Change-Id: I6bf234c25b2d6709aaf095ce641812d58ad0ab68
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2021-10-21 17:36:31 +08:00
parent 8ae47457a0
commit fd20cf4740
4 changed files with 204 additions and 217 deletions

View File

@@ -49,7 +49,6 @@ typedef struct {
size_t packet_size; size_t packet_size;
MppFrame frame; MppFrame frame;
FILE *fp_input;
FILE *fp_output; FILE *fp_output;
RK_S32 frame_count; RK_S32 frame_count;
RK_S32 frame_num; RK_S32 frame_num;
@@ -71,7 +70,6 @@ void *thread_input(void *arg)
mpp_log_q(quiet, "put packet thread start\n"); mpp_log_q(quiet, "put packet thread start\n");
do { do {
RK_U32 pkt_done = 0;
RK_U32 pkt_eos = 0; RK_U32 pkt_eos = 0;
FileBufSlot *slot = NULL; FileBufSlot *slot = NULL;
MPP_RET ret = reader_read(reader, &slot); MPP_RET ret = reader_read(reader, &slot);
@@ -100,13 +98,13 @@ void *thread_input(void *arg)
do { do {
ret = mpi->decode_put_packet(ctx, packet); ret = mpi->decode_put_packet(ctx, packet);
if (MPP_OK == ret) { if (MPP_OK == ret) {
pkt_done = 1;
mpp_assert(0 == mpp_packet_get_length(packet)); mpp_assert(0 == mpp_packet_get_length(packet));
} else { break;
// if failed wait a moment and retry
msleep(5);
} }
} while (!pkt_done && !data->loop_end); // if failed wait a moment and retry
msleep(1);
} while (!data->loop_end);
if (pkt_eos) if (pkt_eos)
break; break;
@@ -123,7 +121,6 @@ void *thread_output(void *arg)
MpiDecTestCmd *cmd = data->cmd; MpiDecTestCmd *cmd = data->cmd;
MppCtx ctx = data->ctx; MppCtx ctx = data->ctx;
MppApi *mpi = data->mpi; MppApi *mpi = data->mpi;
MppFrame frame = NULL;
RK_U32 quiet = data->quiet; RK_U32 quiet = data->quiet;
mpp_log_q(quiet, "get frame thread start\n"); mpp_log_q(quiet, "get frame thread start\n");
@@ -131,115 +128,105 @@ void *thread_output(void *arg)
// then get all available frame and release // then get all available frame and release
do { do {
RK_U32 frm_eos = 0; RK_U32 frm_eos = 0;
RK_S32 times = 5; MppFrame frame = NULL;
MPP_RET ret = MPP_OK; MPP_RET ret = mpi->decode_get_frame(ctx, &frame);
GET_AGAIN:
ret = mpi->decode_get_frame(ctx, &frame);
if (MPP_ERR_TIMEOUT == ret) {
if (times > 0) {
times--;
msleep(2);
goto GET_AGAIN;
}
mpp_err("decode_get_frame failed too much time\n");
}
if (ret) { if (ret) {
mpp_err("decode_get_frame failed ret %d\n", ret); mpp_err("decode_get_frame failed ret %d\n", ret);
continue; continue;
} }
if (frame) { if (NULL == frame) {
if (mpp_frame_get_info_change(frame)) { msleep(1);
// found info change and create buffer group for decoding continue;
RK_U32 width = mpp_frame_get_width(frame); }
RK_U32 height = mpp_frame_get_height(frame);
RK_U32 hor_stride = mpp_frame_get_hor_stride(frame);
RK_U32 ver_stride = mpp_frame_get_ver_stride(frame);
RK_U32 buf_size = mpp_frame_get_buf_size(frame);
mpp_log_q(quiet, "decode_get_frame get info changed found\n"); if (mpp_frame_get_info_change(frame)) {
mpp_log_q(quiet, "decoder require buffer w:h [%d:%d] stride [%d:%d] size %d\n", // found info change and create buffer group for decoding
width, height, hor_stride, ver_stride, buf_size); RK_U32 width = mpp_frame_get_width(frame);
RK_U32 height = mpp_frame_get_height(frame);
RK_U32 hor_stride = mpp_frame_get_hor_stride(frame);
RK_U32 ver_stride = mpp_frame_get_ver_stride(frame);
RK_U32 buf_size = mpp_frame_get_buf_size(frame);
if (NULL == data->frm_grp) { mpp_log_q(quiet, "decode_get_frame get info changed found\n");
/* If buffer group is not set create one and limit it */ mpp_log_q(quiet, "decoder require buffer w:h [%d:%d] stride [%d:%d] size %d\n",
ret = mpp_buffer_group_get_internal(&data->frm_grp, MPP_BUFFER_TYPE_ION); width, height, hor_stride, ver_stride, buf_size);
if (ret) {
mpp_err("get mpp buffer group failed ret %d\n", ret);
break;
}
/* Set buffer to mpp decoder */ if (NULL == data->frm_grp) {
ret = mpi->control(ctx, MPP_DEC_SET_EXT_BUF_GROUP, data->frm_grp); /* If buffer group is not set create one and limit it */
if (ret) { ret = mpp_buffer_group_get_internal(&data->frm_grp, MPP_BUFFER_TYPE_ION);
mpp_err("set buffer group failed ret %d\n", ret);
break;
}
} else {
/* If old buffer group exist clear it */
ret = mpp_buffer_group_clear(data->frm_grp);
if (ret) {
mpp_err("clear buffer group failed ret %d\n", ret);
break;
}
}
/* Use limit config to limit buffer count to 24 */
ret = mpp_buffer_group_limit_config(data->frm_grp, buf_size, 24);
if (ret) { if (ret) {
mpp_err("limit buffer group failed ret %d\n", ret); mpp_err("get mpp buffer group failed ret %d\n", ret);
break; break;
} }
ret = mpi->control(ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL); /* Set buffer to mpp decoder */
ret = mpi->control(ctx, MPP_DEC_SET_EXT_BUF_GROUP, data->frm_grp);
if (ret) { if (ret) {
mpp_err("info change ready failed ret %d\n", ret); mpp_err("set buffer group failed ret %d\n", ret);
break; break;
} }
} else { } else {
char log_buf[256]; /* If old buffer group exist clear it */
RK_S32 log_size = sizeof(log_buf) - 1; ret = mpp_buffer_group_clear(data->frm_grp);
RK_S32 log_len = 0; if (ret) {
RK_U32 err_info = mpp_frame_get_errinfo(frame); mpp_err("clear buffer group failed ret %d\n", ret);
RK_U32 discard = mpp_frame_get_discard(frame); break;
log_len += snprintf(log_buf + log_len, log_size - log_len,
"decode get frame %d", data->frame_count);
if (mpp_frame_has_meta(frame)) {
MppMeta meta = mpp_frame_get_meta(frame);
RK_S32 temporal_id = 0;
mpp_meta_get_s32(meta, KEY_TEMPORAL_ID, &temporal_id);
log_len += snprintf(log_buf + log_len, log_size - log_len,
" tid %d", temporal_id);
} }
if (err_info || discard) {
log_len += snprintf(log_buf + log_len, log_size - log_len,
" err %x discard %x", err_info, discard);
}
mpp_log_q(quiet, "%p %s\n", ctx, log_buf);
data->frame_count++;
if (data->fp_output && !err_info)
dump_mpp_frame_to_file(frame, data->fp_output);
fps_calc_inc(cmd->fps);
} }
frm_eos = mpp_frame_get_eos(frame); /* Use limit config to limit buffer count to 24 */
mpp_frame_deinit(&frame); ret = mpp_buffer_group_limit_config(data->frm_grp, buf_size, 24);
frame = NULL; if (ret) {
mpp_err("limit buffer group failed ret %d\n", ret);
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
((data->frame_num == 0) && frm_eos)) {
data->loop_end = 1;
break; break;
} }
ret = mpi->control(ctx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
if (ret) {
mpp_err("info change ready failed ret %d\n", ret);
break;
}
} else {
char log_buf[256];
RK_S32 log_size = sizeof(log_buf) - 1;
RK_S32 log_len = 0;
RK_U32 err_info = mpp_frame_get_errinfo(frame);
RK_U32 discard = mpp_frame_get_discard(frame);
log_len += snprintf(log_buf + log_len, log_size - log_len,
"decode get frame %d", data->frame_count);
if (mpp_frame_has_meta(frame)) {
MppMeta meta = mpp_frame_get_meta(frame);
RK_S32 temporal_id = 0;
mpp_meta_get_s32(meta, KEY_TEMPORAL_ID, &temporal_id);
log_len += snprintf(log_buf + log_len, log_size - log_len,
" tid %d", temporal_id);
}
if (err_info || discard) {
log_len += snprintf(log_buf + log_len, log_size - log_len,
" err %x discard %x", err_info, discard);
}
mpp_log_q(quiet, "%p %s\n", ctx, log_buf);
data->frame_count++;
if (data->fp_output && !err_info)
dump_mpp_frame_to_file(frame, data->fp_output);
fps_calc_inc(cmd->fps);
} }
frm_eos = mpp_frame_get_eos(frame);
mpp_frame_deinit(&frame);
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
((data->frame_num == 0) && frm_eos))
data->loop_end = 1;
} while (!data->loop_end); } while (!data->loop_end);
mpp_log_q(quiet, "get frame thread end\n"); mpp_log_q(quiet, "get frame thread end\n");
@@ -260,25 +247,21 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
MppPacket packet = NULL; MppPacket packet = NULL;
MppFrame frame = NULL; MppFrame frame = NULL;
MpiCmd mpi_cmd = MPP_CMD_BASE; // config for runtime mode
MppParam param = NULL; MppDecCfg cfg = NULL;
RK_U32 need_split = 1; RK_U32 need_split = 1;
MppPollType timeout = cmd->timeout;
// paramter for resource malloc // paramter for resource malloc
RK_U32 width = cmd->width; RK_U32 width = cmd->width;
RK_U32 height = cmd->height; RK_U32 height = cmd->height;
MppCodingType type = cmd->type; MppCodingType type = cmd->type;
// resources
size_t packet_size = MPI_DEC_STREAM_SIZE;
pthread_t thd_in; pthread_t thd_in;
pthread_t thd_out; pthread_t thd_out;
pthread_attr_t attr; pthread_attr_t attr;
MpiDecMtLoopData data; MpiDecMtLoopData data;
mpp_log("mpi_dec_test start\n"); mpp_log("mpi_dec_mt_test start\n");
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
if (cmd->have_output) { if (cmd->have_output) {
@@ -295,7 +278,7 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
mpp_log("mpi_dec_test decoder test start w %d h %d type %d\n", width, height, type); mpp_log("mpi_dec_mt_test decoder test start w %d h %d type %d\n", width, height, type);
// decoder demo // decoder demo
ret = mpp_create(&ctx, &mpi); ret = mpp_create(&ctx, &mpi);
@@ -304,12 +287,9 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
// NOTE: decoder split mode need to be set before init ret = mpp_init(ctx, MPP_CTX_DEC, type);
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
param = &need_split;
ret = mpi->control(ctx, mpi_cmd, param);
if (ret) { if (ret) {
mpp_err("mpi->control failed\n"); mpp_err("mpp_init failed\n");
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
@@ -317,8 +297,10 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
// 0 - non-block call (default) // 0 - non-block call (default)
// -1 - block call // -1 - block call
// +val - timeout value in ms // +val - timeout value in ms
if (timeout) { {
param = &timeout; MppPollType timeout = MPP_POLL_BLOCK;
MppParam param = &timeout;
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param); ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
if (ret) { if (ret) {
mpp_err("Failed to set output timeout %d ret %d\n", timeout, ret); mpp_err("Failed to set output timeout %d ret %d\n", timeout, ret);
@@ -326,9 +308,28 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
} }
} }
ret = mpp_init(ctx, MPP_CTX_DEC, type); mpp_dec_cfg_init(&cfg);
/* get default config from decoder context */
ret = mpi->control(ctx, MPP_DEC_GET_CFG, cfg);
if (ret) { if (ret) {
mpp_err("mpp_init failed\n"); mpp_err("%p failed to get decoder cfg ret %d\n", ctx, ret);
goto MPP_TEST_OUT;
}
/*
* split_parse is to enable mpp internal frame spliter when the input
* packet is not aplited into frames.
*/
ret = mpp_dec_cfg_set_u32(cfg, "base:split_parse", need_split);
if (ret) {
mpp_err("%p failed to set split_parse ret %d\n", ctx, ret);
goto MPP_TEST_OUT;
}
ret = mpi->control(ctx, MPP_DEC_SET_CFG, cfg);
if (ret) {
mpp_err("%p failed to set cfg %p ret %d\n", ctx, cfg, ret);
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
@@ -337,7 +338,6 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
data.mpi = mpi; data.mpi = mpi;
data.loop_end = 0; data.loop_end = 0;
data.packet = packet; data.packet = packet;
data.packet_size = packet_size;
data.frame = frame; data.frame = frame;
data.frame_count = 0; data.frame_count = 0;
data.frame_num = cmd->frame_num; data.frame_num = cmd->frame_num;
@@ -407,9 +407,9 @@ MPP_TEST_OUT:
data.fp_output = NULL; data.fp_output = NULL;
} }
if (data.fp_input) { if (cfg) {
fclose(data.fp_input); mpp_dec_cfg_deinit(cfg);
data.fp_input = NULL; cfg = NULL;
} }
return ret; return ret;

View File

@@ -46,15 +46,13 @@ typedef struct {
MppPacket packet; MppPacket packet;
MppFrame frame; MppFrame frame;
FILE *fp_input;
FILE *fp_output; FILE *fp_output;
RK_S32 packet_count; RK_S32 packet_count;
RK_S32 frame_count; RK_S32 frame_count;
RK_S32 frame_num;
RK_S64 first_pkt; RK_S64 first_pkt;
RK_S64 first_frm; RK_S64 first_frm;
RK_S32 frame_num;
FileReader reader;
/* runtime flag */ /* runtime flag */
RK_U32 quiet; RK_U32 quiet;
@@ -81,15 +79,11 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
MpiDecTestCmd *cmd = data->cmd; MpiDecTestCmd *cmd = data->cmd;
RK_U32 pkt_done = 0; RK_U32 pkt_done = 0;
RK_U32 pkt_eos = 0; RK_U32 pkt_eos = 0;
RK_U32 err_info = 0;
MppCtx ctx = data->ctx; MppCtx ctx = data->ctx;
MppApi *mpi = data->mpi; MppApi *mpi = data->mpi;
char *buf = NULL;
MppPacket packet = data->packet; MppPacket packet = data->packet;
MppFrame frame = NULL; FileReader reader = cmd->reader;
FileReader reader = data->reader;
FileBufSlot *slot = NULL; FileBufSlot *slot = NULL;
size_t read_size = 0;
RK_U32 quiet = data->quiet; RK_U32 quiet = data->quiet;
MPP_RET ret = reader_index_read(reader, data->packet_count++, &slot); MPP_RET ret = reader_index_read(reader, data->packet_count++, &slot);
@@ -97,8 +91,6 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
mpp_assert(slot); mpp_assert(slot);
pkt_eos = slot->eos; pkt_eos = slot->eos;
buf = slot->data;
read_size = slot->size;
if (pkt_eos) { if (pkt_eos) {
if (data->frame_num < 0 || data->frame_num > data->frame_count) { if (data->frame_num < 0 || data->frame_num > data->frame_count) {
@@ -111,11 +103,10 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
} }
} }
mpp_packet_set_data(packet, buf); mpp_packet_set_data(packet, slot->data);
if (read_size > mpp_packet_get_size(packet)) mpp_packet_set_size(packet, slot->size);
mpp_packet_set_size(packet, read_size); mpp_packet_set_pos(packet, slot->data);
mpp_packet_set_pos(packet, buf); mpp_packet_set_length(packet, slot->size);
mpp_packet_set_length(packet, read_size);
// setup eos flag // setup eos flag
if (pkt_eos) if (pkt_eos)
mpp_packet_set_eos(packet); mpp_packet_set_eos(packet);
@@ -136,6 +127,7 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
// then get all available frame and release // then get all available frame and release
do { do {
RK_S32 get_frm = 0; RK_S32 get_frm = 0;
MppFrame frame = NULL;
try_again: try_again:
ret = mpi->decode_get_frame(ctx, &frame); ret = mpi->decode_get_frame(ctx, &frame);
@@ -204,6 +196,8 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
break; break;
} }
} else { } else {
RK_U32 err_info = 0;
if (!data->first_frm) if (!data->first_frm)
data->first_frm = mpp_time(); data->first_frm = mpp_time();
@@ -225,7 +219,6 @@ static int multi_dec_simple(MpiDecMultiCtx *data)
} }
frm_eos = mpp_frame_get_eos(frame); frm_eos = mpp_frame_get_eos(frame);
mpp_frame_deinit(&frame); mpp_frame_deinit(&frame);
frame = NULL;
get_frm = 1; get_frm = 1;
} }
@@ -311,6 +304,9 @@ static int multi_dec_advanced(MpiDecMultiCtx *data)
return ret; return ret;
} }
if (!data->first_pkt)
data->first_pkt = mpp_time();
/* poll and wait here */ /* poll and wait here */
ret = mpi->poll(ctx, MPP_PORT_OUTPUT, MPP_POLL_BLOCK); ret = mpi->poll(ctx, MPP_PORT_OUTPUT, MPP_POLL_BLOCK);
if (ret) { if (ret) {
@@ -332,6 +328,9 @@ static int multi_dec_advanced(MpiDecMultiCtx *data)
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out); mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
if (frame) { if (frame) {
if (!data->first_frm)
data->first_frm = mpp_time();
if (data->fp_output) if (data->fp_output)
dump_mpp_frame_to_file(frame, data->fp_output); dump_mpp_frame_to_file(frame, data->fp_output);
@@ -399,7 +398,6 @@ void* multi_dec_decode(void *cmd_ctx)
MpiDecMultiCtx *dec_ctx = &info->ctx; MpiDecMultiCtx *dec_ctx = &info->ctx;
MpiDecMultiCtxRet *rets = &info->ret; MpiDecMultiCtxRet *rets = &info->ret;
MpiDecTestCmd *cmd = info->cmd; MpiDecTestCmd *cmd = info->cmd;
FileReader reader = cmd->reader;
MPP_RET ret = MPP_OK; MPP_RET ret = MPP_OK;
// base flow context // base flow context
@@ -410,10 +408,9 @@ void* multi_dec_decode(void *cmd_ctx)
MppPacket packet = NULL; MppPacket packet = NULL;
MppFrame frame = NULL; MppFrame frame = NULL;
MpiCmd mpi_cmd = MPP_CMD_BASE; // config for runtime mode
MppParam param = NULL; MppDecCfg cfg = NULL;
RK_U32 need_split = 1; RK_U32 need_split = 1;
MppPollType timeout = cmd->timeout;
// paramter for resource malloc // paramter for resource malloc
RK_U32 width = cmd->width; RK_U32 width = cmd->width;
@@ -479,34 +476,37 @@ void* multi_dec_decode(void *cmd_ctx)
mpp_log("%p mpi_dec_test decoder test start w %d h %d type %d\n", mpp_log("%p mpi_dec_test decoder test start w %d h %d type %d\n",
ctx, width, height, type); ctx, width, height, type);
// NOTE: decoder split mode need to be set before init
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
param = &need_split;
ret = mpi->control(ctx, mpi_cmd, param);
if (ret) {
mpp_err("mpi->control failed\n");
goto MPP_TEST_OUT;
}
// NOTE: timeout value please refer to MppPollType definition
// 0 - non-block call (default)
// -1 - block call
// +val - timeout value in ms
if (timeout) {
param = &timeout;
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
if (ret) {
mpp_err("Failed to set output timeout %d ret %d\n", timeout, ret);
goto MPP_TEST_OUT;
}
}
ret = mpp_init(ctx, MPP_CTX_DEC, type); ret = mpp_init(ctx, MPP_CTX_DEC, type);
if (ret) { if (ret) {
mpp_err("mpp_init failed\n"); mpp_err("mpp_init failed\n");
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
mpp_dec_cfg_init(&cfg);
/* get default config from decoder context */
ret = mpi->control(ctx, MPP_DEC_GET_CFG, cfg);
if (ret) {
mpp_err("%p failed to get decoder cfg ret %d\n", ctx, ret);
goto MPP_TEST_OUT;
}
/*
* split_parse is to enable mpp internal frame spliter when the input
* packet is not aplited into frames.
*/
ret = mpp_dec_cfg_set_u32(cfg, "base:split_parse", need_split);
if (ret) {
mpp_err("%p failed to set split_parse ret %d\n", ctx, ret);
goto MPP_TEST_OUT;
}
ret = mpi->control(ctx, MPP_DEC_SET_CFG, cfg);
if (ret) {
mpp_err("%p failed to set cfg %p ret %d\n", ctx, cfg, ret);
goto MPP_TEST_OUT;
}
dec_ctx->cmd = cmd; dec_ctx->cmd = cmd;
dec_ctx->ctx = ctx; dec_ctx->ctx = ctx;
dec_ctx->mpi = mpi; dec_ctx->mpi = mpi;
@@ -515,7 +515,6 @@ void* multi_dec_decode(void *cmd_ctx)
dec_ctx->packet_count = 0; dec_ctx->packet_count = 0;
dec_ctx->frame_count = 0; dec_ctx->frame_count = 0;
dec_ctx->frame_num = cmd->frame_num; dec_ctx->frame_num = cmd->frame_num;
dec_ctx->reader = reader;
dec_ctx->quiet = cmd->quiet; dec_ctx->quiet = cmd->quiet;
RK_S64 t_s, t_e; RK_S64 t_s, t_e;
@@ -574,9 +573,9 @@ MPP_TEST_OUT:
dec_ctx->fp_output = NULL; dec_ctx->fp_output = NULL;
} }
if (dec_ctx->fp_input) { if (cfg) {
fclose(dec_ctx->fp_input); mpp_dec_cfg_deinit(cfg);
dec_ctx->fp_input = NULL; cfg = NULL;
} }
return NULL; return NULL;

View File

@@ -44,11 +44,17 @@ typedef struct {
MppPacket packet; MppPacket packet;
MppFrame frame; MppFrame frame;
FILE *fp_input;
FILE *fp_output; FILE *fp_output;
RK_S32 frame_count; RK_S32 frame_count;
RK_S32 frame_num; RK_S32 frame_num;
RK_S64 first_pkt;
RK_S64 first_frm;
size_t max_usage; size_t max_usage;
float frame_rate;
RK_S64 elapsed_time;
RK_S64 delay;
} MpiDecLoopData; } MpiDecLoopData;
static int dec_simple(MpiDecLoopData *data) static int dec_simple(MpiDecLoopData *data)
@@ -60,7 +66,6 @@ static int dec_simple(MpiDecLoopData *data)
MppCtx ctx = data->ctx; MppCtx ctx = data->ctx;
MppApi *mpi = data->mpi; MppApi *mpi = data->mpi;
MppPacket packet = data->packet; MppPacket packet = data->packet;
MppFrame frame = NULL;
FileBufSlot *slot = NULL; FileBufSlot *slot = NULL;
RK_U32 quiet = data->quiet; RK_U32 quiet = data->quiet;
@@ -93,24 +98,29 @@ static int dec_simple(MpiDecLoopData *data)
do { do {
RK_U32 frm_eos = 0; RK_U32 frm_eos = 0;
RK_S32 times = 5; RK_S32 times = 30;
// send the packet first if packet is not done // send the packet first if packet is not done
if (!pkt_done) { if (!pkt_done) {
ret = mpi->decode_put_packet(ctx, packet); ret = mpi->decode_put_packet(ctx, packet);
if (MPP_OK == ret) if (MPP_OK == ret) {
pkt_done = 1; pkt_done = 1;
if (!data->first_pkt)
data->first_pkt = mpp_time();
}
} }
// then get all available frame and release // then get all available frame and release
do { do {
RK_S32 get_frm = 0; RK_S32 get_frm = 0;
MppFrame frame = NULL;
try_again: try_again:
ret = mpi->decode_get_frame(ctx, &frame); ret = mpi->decode_get_frame(ctx, &frame);
if (MPP_ERR_TIMEOUT == ret) { if (MPP_ERR_TIMEOUT == ret) {
if (times > 0) { if (times > 0) {
times--; times--;
msleep(2); msleep(1);
goto try_again; goto try_again;
} }
mpp_err("%p decode_get_frame failed too much time\n", ctx); mpp_err("%p decode_get_frame failed too much time\n", ctx);
@@ -238,6 +248,9 @@ static int dec_simple(MpiDecLoopData *data)
RK_U32 err_info = mpp_frame_get_errinfo(frame); RK_U32 err_info = mpp_frame_get_errinfo(frame);
RK_U32 discard = mpp_frame_get_discard(frame); RK_U32 discard = mpp_frame_get_discard(frame);
if (!data->first_frm)
data->first_frm = mpp_time();
log_len += snprintf(log_buf + log_len, log_size - log_len, log_len += snprintf(log_buf + log_len, log_size - log_len,
"decode get frame %d", data->frame_count); "decode get frame %d", data->frame_count);
@@ -265,7 +278,6 @@ static int dec_simple(MpiDecLoopData *data)
} }
frm_eos = mpp_frame_get_eos(frame); frm_eos = mpp_frame_get_eos(frame);
mpp_frame_deinit(&frame); mpp_frame_deinit(&frame);
frame = NULL;
get_frm = 1; get_frm = 1;
} }
@@ -278,7 +290,7 @@ static int dec_simple(MpiDecLoopData *data)
// if last packet is send but last frame is not found continue // if last packet is send but last frame is not found continue
if (pkt_eos && pkt_done && !frm_eos) { if (pkt_eos && pkt_done && !frm_eos) {
msleep(10); msleep(1);
continue; continue;
} }
@@ -309,10 +321,10 @@ static int dec_simple(MpiDecLoopData *data)
* why sleep here: * why sleep here:
* mpi->decode_put_packet will failed when packet in internal queue is * mpi->decode_put_packet will failed when packet in internal queue is
* full,waiting the package is consumed .Usually hardware decode one * full,waiting the package is consumed .Usually hardware decode one
* frame which resolution is 1080p needs 2 ms,so here we sleep 3ms * frame which resolution is 1080p needs 2 ms,so here we sleep 1ms
* * is enough. * * is enough.
*/ */
msleep(3); msleep(1);
} while (1); } while (1);
return ret; return ret;
@@ -363,6 +375,9 @@ static int dec_advanced(MpiDecLoopData *data)
return ret; return ret;
} }
if (!data->first_pkt)
data->first_pkt = mpp_time();
/* poll and wait here */ /* poll and wait here */
ret = mpi->poll(ctx, MPP_PORT_OUTPUT, MPP_POLL_BLOCK); ret = mpi->poll(ctx, MPP_PORT_OUTPUT, MPP_POLL_BLOCK);
if (ret) { if (ret) {
@@ -384,6 +399,9 @@ static int dec_advanced(MpiDecLoopData *data)
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out); mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
if (frame) { if (frame) {
if (!data->first_frm)
data->first_frm = mpp_time();
/* write frame to file here */ /* write frame to file here */
if (data->fp_output) if (data->fp_output)
dump_mpp_frame_to_file(frame, data->fp_output); dump_mpp_frame_to_file(frame, data->fp_output);
@@ -452,6 +470,9 @@ void *thread_decode(void *arg)
MpiDecTestCmd *cmd = data->cmd; MpiDecTestCmd *cmd = data->cmd;
MppCtx ctx = data->ctx; MppCtx ctx = data->ctx;
MppApi *mpi = data->mpi; MppApi *mpi = data->mpi;
RK_S64 t_s, t_e;
t_s = mpp_time();
if (cmd->simple) { if (cmd->simple) {
while (!data->loop_end) while (!data->loop_end)
@@ -470,6 +491,16 @@ void *thread_decode(void *arg)
dec_advanced(data); dec_advanced(data);
} }
t_e = mpp_time();
data->elapsed_time = t_e - t_s;
data->frame_count = data->frame_count;
data->frame_rate = (float)data->frame_count * 1000000 / data->elapsed_time;
data->delay = data->first_frm - data->first_pkt;
mpp_log("decode %d frames time %lld ms delay %3d ms fps %3.2f\n",
data->frame_count, (RK_S64)(data->elapsed_time / 1000),
(RK_S32)(data->delay / 1000), data->frame_rate);
return NULL; return NULL;
} }
@@ -483,11 +514,6 @@ int dec_decode(MpiDecTestCmd *cmd)
MppPacket packet = NULL; MppPacket packet = NULL;
MppFrame frame = NULL; MppFrame frame = NULL;
MpiCmd mpi_cmd = MPP_CMD_BASE;
MppParam param = NULL;
RK_U32 need_split = 1;
MppPollType timeout = cmd->timeout;
// paramter for resource malloc // paramter for resource malloc
RK_U32 width = cmd->width; RK_U32 width = cmd->width;
RK_U32 height = cmd->height; RK_U32 height = cmd->height;
@@ -495,6 +521,7 @@ int dec_decode(MpiDecTestCmd *cmd)
// config for runtime mode // config for runtime mode
MppDecCfg cfg = NULL; MppDecCfg cfg = NULL;
RK_U32 need_split = 1;
// resources // resources
MppBuffer frm_buf = NULL; MppBuffer frm_buf = NULL;
@@ -565,29 +592,6 @@ int dec_decode(MpiDecTestCmd *cmd)
mpp_log("%p mpi_dec_test decoder test start w %d h %d type %d\n", mpp_log("%p mpi_dec_test decoder test start w %d h %d type %d\n",
ctx, width, height, type); ctx, width, height, type);
// NOTE: decoder split mode need to be set before init
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
param = &need_split;
ret = mpi->control(ctx, mpi_cmd, param);
if (ret) {
mpp_err("%p mpi->control failed\n", ctx);
goto MPP_TEST_OUT;
}
// NOTE: timeout value please refer to MppPollType definition
// 0 - non-block call (default)
// -1 - block call
// +val - timeout value in ms
if (timeout) {
param = &timeout;
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
if (ret) {
mpp_err("%p failed to set output timeout %d ret %d\n",
ctx, timeout, ret);
goto MPP_TEST_OUT;
}
}
ret = mpp_init(ctx, MPP_CTX_DEC, type); ret = mpp_init(ctx, MPP_CTX_DEC, type);
if (ret) { if (ret) {
mpp_err("%p mpp_init failed\n", ctx); mpp_err("%p mpp_init failed\n", ctx);
@@ -650,25 +654,6 @@ int dec_decode(MpiDecTestCmd *cmd)
pthread_join(thd, NULL); pthread_join(thd, NULL);
cmd->max_usage = data.max_usage; cmd->max_usage = data.max_usage;
{
MppDecQueryCfg query;
memset(&query, 0, sizeof(query));
query.query_flag = MPP_DEC_QUERY_ALL;
ret = mpi->control(ctx, MPP_DEC_QUERY, &query);
if (ret) {
mpp_err("%p mpi->control query failed\n", ctx);
goto MPP_TEST_OUT;
}
/*
* NOTE:
* 1. Output frame count included info change frame and empty eos frame.
* 2. Hardware run count is real decoded frame count.
*/
mpp_log("%p input %d pkt output %d frm decode %d frames\n", ctx,
query.dec_in_pkt_cnt, query.dec_out_frm_cnt, query.dec_hw_run_cnt);
}
ret = mpi->reset(ctx); ret = mpi->reset(ctx);
if (ret) { if (ret) {

View File

@@ -602,6 +602,9 @@ 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)
{ {
if (cmd->quiet)
return;
mpp_log("cmd parse result:\n"); mpp_log("cmd parse result:\n");
mpp_log("input file name: %s\n", cmd->file_input); mpp_log("input file name: %s\n", cmd->file_input);
mpp_log("output file name: %s\n", cmd->file_output); mpp_log("output file name: %s\n", cmd->file_output);