mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 09:06:50 +08:00
[test]: Improve decoder tests
1. All cases use reader to improve performance. 2. Rename cmd parser and create share data on cmd parsing. 3. Add reader_size function to get file size. 4. Change test log flag to -v options. 5. Fix FileBufSlot release MppBuffer issue. 6. Use index_read in multi test to improve performance. Usage: mpi_dec_test -i xxx.h264 Decode to the end of input stream. mpi_dec_test -i xxx.h264 -n 10 Decode to the first 10 frame of input stream. If the xxx.h264 has only 5 frames then loop decoding from the beginning. mpi_dec_test -i xxx.h264 -n -1 -v qf Infinitely loop decoding xxx.h264. It is usefull for performance test. mpi_dec_multi_test -i xxx.h264 -n -1 -v qf -s 8 Parallelly infinitely loop run 8 decoders with same xxx.h264 input. It is usefull for performance test. -v q will disable each frame output log. -v f will enable fps print per second. -n -1 will enter infinite decode mode. Press <enter> will quit the loop. Change-Id: I3d54123f0e9b9a85cb35e4fea71ebf665889750a Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
@@ -34,11 +34,11 @@
|
|||||||
#include "mpi_dec_utils.h"
|
#include "mpi_dec_utils.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
MpiDecTestCmd *cmd;
|
||||||
MppCtx ctx;
|
MppCtx ctx;
|
||||||
MppApi *mpi;
|
MppApi *mpi;
|
||||||
|
|
||||||
volatile RK_U32 loop_end;
|
volatile RK_U32 loop_end;
|
||||||
sem_t sem_end;
|
|
||||||
|
|
||||||
/* buffer for stream data reading */
|
/* buffer for stream data reading */
|
||||||
char *buf;
|
char *buf;
|
||||||
@@ -51,7 +51,7 @@ typedef struct {
|
|||||||
|
|
||||||
FILE *fp_input;
|
FILE *fp_input;
|
||||||
FILE *fp_output;
|
FILE *fp_output;
|
||||||
RK_U64 frame_count;
|
RK_S32 frame_count;
|
||||||
RK_S32 frame_num;
|
RK_S32 frame_num;
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ void *thread_input(void *arg)
|
|||||||
pkt_eos = slot->eos;
|
pkt_eos = slot->eos;
|
||||||
// setup eos flag
|
// setup eos flag
|
||||||
if (pkt_eos) {
|
if (pkt_eos) {
|
||||||
if (data->frame_num < 0) {
|
if (data->frame_num < 0 || data->frame_count < data->frame_num) {
|
||||||
mpp_log_q(quiet, "%p loop again\n", ctx);
|
mpp_log_q(quiet, "%p loop again\n", ctx);
|
||||||
reader_rewind(reader);
|
reader_rewind(reader);
|
||||||
pkt_eos = 0;
|
pkt_eos = 0;
|
||||||
@@ -106,7 +106,7 @@ void *thread_input(void *arg)
|
|||||||
// if failed wait a moment and retry
|
// if failed wait a moment and retry
|
||||||
msleep(5);
|
msleep(5);
|
||||||
}
|
}
|
||||||
} while (!pkt_done);
|
} while (!pkt_done && !data->loop_end);
|
||||||
|
|
||||||
if (pkt_eos)
|
if (pkt_eos)
|
||||||
break;
|
break;
|
||||||
@@ -120,6 +120,7 @@ void *thread_input(void *arg)
|
|||||||
void *thread_output(void *arg)
|
void *thread_output(void *arg)
|
||||||
{
|
{
|
||||||
MpiDecMtLoopData *data = (MpiDecMtLoopData *)arg;
|
MpiDecMtLoopData *data = (MpiDecMtLoopData *)arg;
|
||||||
|
MpiDecTestCmd *cmd = data->cmd;
|
||||||
MppCtx ctx = data->ctx;
|
MppCtx ctx = data->ctx;
|
||||||
MppApi *mpi = data->mpi;
|
MppApi *mpi = data->mpi;
|
||||||
MppFrame frame = NULL;
|
MppFrame frame = NULL;
|
||||||
@@ -143,7 +144,7 @@ void *thread_output(void *arg)
|
|||||||
}
|
}
|
||||||
mpp_err("decode_get_frame failed too much time\n");
|
mpp_err("decode_get_frame failed too much time\n");
|
||||||
}
|
}
|
||||||
if (MPP_OK != 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;
|
||||||
}
|
}
|
||||||
@@ -197,58 +198,45 @@ void *thread_output(void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// found normal output frame
|
char log_buf[256];
|
||||||
RK_U32 err_info = mpp_frame_get_errinfo(frame) | mpp_frame_get_discard(frame);
|
RK_S32 log_size = sizeof(log_buf) - 1;
|
||||||
if (err_info)
|
RK_S32 log_len = 0;
|
||||||
mpp_log_q(quiet, "decoder_get_frame get err info:%d discard:%d.\n",
|
RK_U32 err_info = mpp_frame_get_errinfo(frame);
|
||||||
mpp_frame_get_errinfo(frame), mpp_frame_get_discard(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)
|
if (data->fp_output && !err_info)
|
||||||
dump_mpp_frame_to_file(frame, data->fp_output);
|
dump_mpp_frame_to_file(frame, data->fp_output);
|
||||||
|
|
||||||
// calculate fps here
|
fps_calc_inc(cmd->fps);
|
||||||
static RK_S64 last_time = 0;
|
|
||||||
static RK_S64 last_count = 0;
|
|
||||||
|
|
||||||
if (data->frame_count == 0) {
|
|
||||||
last_time = mpp_time();
|
|
||||||
last_count = 0;
|
|
||||||
} else {
|
|
||||||
RK_S64 now = mpp_time();
|
|
||||||
RK_S64 elapsed = now - last_time;
|
|
||||||
|
|
||||||
// print on each second
|
|
||||||
if (elapsed >= 1000000) {
|
|
||||||
RK_S64 frames = data->frame_count - last_count;
|
|
||||||
float fps = (float)frames * 1000000 / elapsed;
|
|
||||||
|
|
||||||
mpp_log("decoded %10lld frame %7.2f fps\n",
|
|
||||||
data->frame_count, fps);
|
|
||||||
|
|
||||||
last_time = now;
|
|
||||||
last_count = data->frame_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data->frame_count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frm_eos = mpp_frame_get_eos(frame);
|
frm_eos = mpp_frame_get_eos(frame);
|
||||||
mpp_frame_deinit(&frame);
|
mpp_frame_deinit(&frame);
|
||||||
frame = NULL;
|
frame = NULL;
|
||||||
|
|
||||||
if (frm_eos) {
|
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
|
||||||
mpp_log_q(quiet, "found last frame and quit\n");
|
((data->frame_num == 0) && frm_eos)) {
|
||||||
// when get a eos status mpp need a reset to restart decoding
|
|
||||||
data->loop_end = 1;
|
data->loop_end = 1;
|
||||||
mpp_log_q(quiet, "found last frame and quit ok\n");
|
|
||||||
sem_post(&data->sem_end);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->frame_num > 0 && data->frame_count >= (RK_U32)data->frame_num) {
|
|
||||||
data->loop_end = 1;
|
|
||||||
mpp_log("%p reach max frame number %d\n", ctx, data->frame_count);
|
|
||||||
sem_post(&data->sem_end);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,7 +250,7 @@ void *thread_output(void *arg)
|
|||||||
int mt_dec_decode(MpiDecTestCmd *cmd)
|
int mt_dec_decode(MpiDecTestCmd *cmd)
|
||||||
{
|
{
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
size_t file_size = 0;
|
FileReader reader = cmd->reader;
|
||||||
|
|
||||||
// base flow context
|
// base flow context
|
||||||
MppCtx ctx = NULL;
|
MppCtx ctx = NULL;
|
||||||
@@ -281,7 +269,6 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
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;
|
||||||
FileReader reader = NULL;
|
|
||||||
|
|
||||||
// resources
|
// resources
|
||||||
size_t packet_size = MPI_DEC_STREAM_SIZE;
|
size_t packet_size = MPI_DEC_STREAM_SIZE;
|
||||||
@@ -294,20 +281,6 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
mpp_log("mpi_dec_test start\n");
|
mpp_log("mpi_dec_test start\n");
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
|
|
||||||
if (cmd->have_input) {
|
|
||||||
data.fp_input = fopen(cmd->file_input, "rb");
|
|
||||||
if (NULL == data.fp_input) {
|
|
||||||
mpp_err("failed to open input file %s\n", cmd->file_input);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(data.fp_input, 0L, SEEK_END);
|
|
||||||
file_size = ftell(data.fp_input);
|
|
||||||
rewind(data.fp_input);
|
|
||||||
reader_init(&reader, cmd->file_input, data.fp_input);
|
|
||||||
mpp_log("input file size %ld\n", file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->have_output) {
|
if (cmd->have_output) {
|
||||||
data.fp_output = fopen(cmd->file_output, "w+b");
|
data.fp_output = fopen(cmd->file_output, "w+b");
|
||||||
if (NULL == data.fp_output) {
|
if (NULL == data.fp_output) {
|
||||||
@@ -326,8 +299,7 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
|
|
||||||
// decoder demo
|
// decoder demo
|
||||||
ret = mpp_create(&ctx, &mpi);
|
ret = mpp_create(&ctx, &mpi);
|
||||||
|
if (ret) {
|
||||||
if (MPP_OK != ret) {
|
|
||||||
mpp_err("mpp_create failed\n");
|
mpp_err("mpp_create failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -336,7 +308,7 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
||||||
param = &need_split;
|
param = &need_split;
|
||||||
ret = mpi->control(ctx, mpi_cmd, param);
|
ret = mpi->control(ctx, mpi_cmd, param);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpi->control failed\n");
|
mpp_err("mpi->control failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -348,18 +320,19 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
if (timeout) {
|
if (timeout) {
|
||||||
param = &timeout;
|
param = &timeout;
|
||||||
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
|
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
|
||||||
if (MPP_OK != 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);
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mpp_init(ctx, MPP_CTX_DEC, type);
|
ret = mpp_init(ctx, MPP_CTX_DEC, type);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_init failed\n");
|
mpp_err("mpp_init failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.cmd = cmd;
|
||||||
data.ctx = ctx;
|
data.ctx = ctx;
|
||||||
data.mpi = mpi;
|
data.mpi = mpi;
|
||||||
data.loop_end = 0;
|
data.loop_end = 0;
|
||||||
@@ -370,7 +343,6 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
data.frame_num = cmd->frame_num;
|
data.frame_num = cmd->frame_num;
|
||||||
data.reader = reader;
|
data.reader = reader;
|
||||||
data.quiet = cmd->quiet;
|
data.quiet = cmd->quiet;
|
||||||
sem_init(&data.sem_end, 0, 0);
|
|
||||||
|
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
@@ -395,24 +367,16 @@ int mt_dec_decode(MpiDecTestCmd *cmd)
|
|||||||
|
|
||||||
getc(stdin);
|
getc(stdin);
|
||||||
data.loop_end = 1;
|
data.loop_end = 1;
|
||||||
} else {
|
|
||||||
sem_wait(&data.sem_end);
|
|
||||||
}
|
}
|
||||||
ret = mpi->reset(ctx);
|
|
||||||
if (MPP_OK != ret)
|
|
||||||
mpp_err("mpi->reset failed\n");
|
|
||||||
|
|
||||||
THREAD_END:
|
THREAD_END:
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
mpp_log("all threads join start\n");
|
|
||||||
pthread_join(thd_in, NULL);
|
pthread_join(thd_in, NULL);
|
||||||
pthread_join(thd_out, NULL);
|
pthread_join(thd_out, NULL);
|
||||||
mpp_log("all threads join done\n");
|
|
||||||
|
|
||||||
sem_destroy(&data.sem_end);
|
|
||||||
|
|
||||||
ret = mpi->reset(ctx);
|
ret = mpi->reset(ctx);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpi->reset failed\n");
|
mpp_err("mpi->reset failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -423,8 +387,6 @@ MPP_TEST_OUT:
|
|||||||
packet = NULL;
|
packet = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader_deinit(&reader);
|
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
mpp_frame_deinit(&frame);
|
mpp_frame_deinit(&frame);
|
||||||
frame = NULL;
|
frame = NULL;
|
||||||
@@ -464,19 +426,17 @@ int main(int argc, char **argv)
|
|||||||
cmd->timeout = -1;
|
cmd->timeout = -1;
|
||||||
|
|
||||||
// parse the cmd option
|
// parse the cmd option
|
||||||
ret = mpi_dec_test_parse_options(argc, argv, cmd);
|
ret = mpi_dec_test_cmd_init(cmd, argc, argv);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mpp_err("mpi_dec_test_parse_options: input parameter invalid\n");
|
mpp_err("mpi_dec_test_cmd_init: input parameter invalid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_help();
|
mpi_dec_test_cmd_help();
|
||||||
return ret;
|
goto RET;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_show_options(cmd);
|
mpi_dec_test_cmd_options(cmd);
|
||||||
|
|
||||||
mpp_env_set_u32("mpi_debug", cmd->debug);
|
|
||||||
|
|
||||||
ret = mt_dec_decode(cmd);
|
ret = mt_dec_decode(cmd);
|
||||||
if (MPP_OK == ret)
|
if (MPP_OK == ret)
|
||||||
@@ -484,7 +444,9 @@ int main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
mpp_err("test failed ret %d\n", ret);
|
mpp_err("test failed ret %d\n", ret);
|
||||||
|
|
||||||
mpp_env_set_u32("mpi_debug", 0x0);
|
RET:
|
||||||
|
mpi_dec_test_cmd_deinit(cmd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,25 +34,22 @@
|
|||||||
|
|
||||||
/* For each instance thread setup */
|
/* For each instance thread setup */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
MpiDecTestCmd *cmd;
|
||||||
MppCtx ctx;
|
MppCtx ctx;
|
||||||
MppApi *mpi;
|
MppApi *mpi;
|
||||||
|
|
||||||
/* end of stream flag when set quit the loop */
|
/* end of stream flag when set quit the loop */
|
||||||
RK_U32 eos;
|
RK_U32 loop_end;
|
||||||
|
|
||||||
/* buffer for stream data reading */
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
/* input and output */
|
/* input and output */
|
||||||
MppBufferGroup frm_grp;
|
MppBufferGroup frm_grp;
|
||||||
MppBufferGroup pkt_grp;
|
|
||||||
MppPacket packet;
|
MppPacket packet;
|
||||||
size_t packet_size;
|
|
||||||
MppFrame frame;
|
MppFrame frame;
|
||||||
|
|
||||||
FILE *fp_input;
|
FILE *fp_input;
|
||||||
FILE *fp_output;
|
FILE *fp_output;
|
||||||
RK_U32 frame_count;
|
RK_S32 packet_count;
|
||||||
|
RK_S32 frame_count;
|
||||||
|
|
||||||
RK_S64 first_pkt;
|
RK_S64 first_pkt;
|
||||||
RK_S64 first_frm;
|
RK_S64 first_frm;
|
||||||
@@ -61,38 +58,40 @@ typedef struct {
|
|||||||
|
|
||||||
/* runtime flag */
|
/* runtime flag */
|
||||||
RK_U32 quiet;
|
RK_U32 quiet;
|
||||||
} MpiDecCtx;
|
} MpiDecMultiCtx;
|
||||||
|
|
||||||
/* For each instance thread return value */
|
/* For each instance thread return value */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile float frame_rate;
|
float frame_rate;
|
||||||
RK_S64 elapsed_time;
|
RK_S64 elapsed_time;
|
||||||
RK_S64 frame_count;
|
RK_S32 frame_count;
|
||||||
} MpiDecCtxRet;
|
RK_S64 delay;
|
||||||
|
} MpiDecMultiCtxRet;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MpiDecTestCmd *cmd; // pointer to global command line info
|
MpiDecTestCmd *cmd; // pointer to global command line info
|
||||||
|
|
||||||
pthread_t thd; // thread for for each instance
|
pthread_t thd; // thread for for each instance
|
||||||
MpiDecCtx ctx; // context of decoder
|
MpiDecMultiCtx ctx; // context of decoder
|
||||||
MpiDecCtxRet ret; // return of decoder
|
MpiDecMultiCtxRet ret; // return of decoder
|
||||||
} MpiDecCtxInfo;
|
} MpiDecMultiCtxInfo;
|
||||||
|
|
||||||
static int multi_dec_simple(MpiDecCtx *data)
|
static int multi_dec_simple(MpiDecMultiCtx *data)
|
||||||
{
|
{
|
||||||
|
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;
|
RK_U32 err_info = 0;
|
||||||
MppCtx ctx = data->ctx;
|
MppCtx ctx = data->ctx;
|
||||||
MppApi *mpi = data->mpi;
|
MppApi *mpi = data->mpi;
|
||||||
char *buf = data->buf;
|
char *buf = NULL;
|
||||||
MppPacket packet = data->packet;
|
MppPacket packet = data->packet;
|
||||||
MppFrame frame = NULL;
|
MppFrame frame = NULL;
|
||||||
FileReader reader = data->reader;
|
FileReader reader = data->reader;
|
||||||
FileBufSlot *slot = NULL;
|
FileBufSlot *slot = NULL;
|
||||||
size_t read_size = 0;
|
size_t read_size = 0;
|
||||||
RK_U32 quiet = data->quiet;
|
RK_U32 quiet = data->quiet;
|
||||||
MPP_RET ret = reader_read(reader, &slot);
|
MPP_RET ret = reader_index_read(reader, data->packet_count++, &slot);
|
||||||
|
|
||||||
mpp_assert(ret == MPP_OK);
|
mpp_assert(ret == MPP_OK);
|
||||||
mpp_assert(slot);
|
mpp_assert(slot);
|
||||||
@@ -100,15 +99,15 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
pkt_eos = slot->eos;
|
pkt_eos = slot->eos;
|
||||||
buf = slot->data;
|
buf = slot->data;
|
||||||
read_size = slot->size;
|
read_size = slot->size;
|
||||||
data->eos = pkt_eos;
|
|
||||||
|
|
||||||
if (pkt_eos) {
|
if (pkt_eos) {
|
||||||
if (data->frame_num < 0) {
|
if (data->frame_num < 0 || data->frame_num > data->frame_count) {
|
||||||
mpp_log_q(quiet, "%p loop again\n", ctx);
|
mpp_log_q(quiet, "%p loop again\n", ctx);
|
||||||
reader_rewind(reader);
|
data->packet_count = 0;
|
||||||
data->eos = pkt_eos = 0;
|
pkt_eos = 0;
|
||||||
} else {
|
} else {
|
||||||
mpp_log_q(quiet, "%p found last packet\n", ctx);
|
mpp_log_q(quiet, "%p found last packet\n", ctx);
|
||||||
|
data->loop_end = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +121,7 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
mpp_packet_set_eos(packet);
|
mpp_packet_set_eos(packet);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
RK_U32 frm_eos = 0;
|
||||||
RK_S32 times = 5;
|
RK_S32 times = 5;
|
||||||
// send the packet first if packet is not done
|
// send the packet first if packet is not done
|
||||||
if (!pkt_done) {
|
if (!pkt_done) {
|
||||||
@@ -136,7 +136,6 @@ static int multi_dec_simple(MpiDecCtx *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;
|
||||||
RK_U32 frm_eos = 0;
|
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
ret = mpi->decode_get_frame(ctx, &frame);
|
ret = mpi->decode_get_frame(ctx, &frame);
|
||||||
@@ -148,7 +147,7 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
}
|
}
|
||||||
mpp_err("decode_get_frame failed too much time\n");
|
mpp_err("decode_get_frame failed too much time\n");
|
||||||
}
|
}
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("decode_get_frame failed ret %d\n", ret);
|
mpp_err("decode_get_frame failed ret %d\n", ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -221,6 +220,8 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
data->frame_count++;
|
data->frame_count++;
|
||||||
if (data->fp_output && !err_info)
|
if (data->fp_output && !err_info)
|
||||||
dump_mpp_frame_to_file(frame, data->fp_output);
|
dump_mpp_frame_to_file(frame, data->fp_output);
|
||||||
|
|
||||||
|
fps_calc_inc(cmd->fps);
|
||||||
}
|
}
|
||||||
frm_eos = mpp_frame_get_eos(frame);
|
frm_eos = mpp_frame_get_eos(frame);
|
||||||
mpp_frame_deinit(&frame);
|
mpp_frame_deinit(&frame);
|
||||||
@@ -234,14 +235,9 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frm_eos) {
|
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
|
||||||
// mpp_log("found last frame\n");
|
((data->frame_num == 0) && frm_eos))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (data->frame_num > 0 && data->frame_count >= (RK_U32)data->frame_num) {
|
|
||||||
data->eos = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get_frm)
|
if (get_frm)
|
||||||
continue;
|
continue;
|
||||||
@@ -251,6 +247,12 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
if (pkt_done)
|
if (pkt_done)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
|
||||||
|
((data->frame_num == 0) && frm_eos)) {
|
||||||
|
data->loop_end = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
@@ -264,30 +266,26 @@ static int multi_dec_simple(MpiDecCtx *data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int multi_dec_advanced(MpiDecCtx *data)
|
static int multi_dec_advanced(MpiDecMultiCtx *data)
|
||||||
{
|
{
|
||||||
RK_U32 pkt_eos = 0;
|
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
|
MpiDecTestCmd *cmd = data->cmd;
|
||||||
MppCtx ctx = data->ctx;
|
MppCtx ctx = data->ctx;
|
||||||
MppApi *mpi = data->mpi;
|
MppApi *mpi = data->mpi;
|
||||||
char *buf = data->buf;
|
MppPacket packet = NULL;
|
||||||
MppPacket packet = data->packet;
|
|
||||||
MppFrame frame = data->frame;
|
MppFrame frame = data->frame;
|
||||||
MppTask task = NULL;
|
MppTask task = NULL;
|
||||||
size_t read_size = fread(buf, 1, data->packet_size, data->fp_input);
|
RK_U32 quiet = data->quiet;
|
||||||
|
FileBufSlot *slot = NULL;
|
||||||
|
|
||||||
if (read_size != data->packet_size || feof(data->fp_input)) {
|
ret = reader_index_read(cmd->reader, 0, &slot);
|
||||||
// mpp_log("found last packet\n");
|
mpp_assert(ret == MPP_OK);
|
||||||
|
mpp_assert(slot);
|
||||||
|
|
||||||
|
mpp_packet_init_with_buffer(&packet, slot->buf);
|
||||||
|
|
||||||
// setup eos flag
|
// setup eos flag
|
||||||
data->eos = pkt_eos = 1;
|
if (slot->eos)
|
||||||
}
|
|
||||||
|
|
||||||
// reset pos
|
|
||||||
mpp_packet_set_pos(packet, buf);
|
|
||||||
mpp_packet_set_length(packet, read_size);
|
|
||||||
// setup eos flag
|
|
||||||
if (pkt_eos)
|
|
||||||
mpp_packet_set_eos(packet);
|
mpp_packet_set_eos(packet);
|
||||||
|
|
||||||
ret = mpi->poll(ctx, MPP_PORT_INPUT, MPP_POLL_BLOCK);
|
ret = mpi->poll(ctx, MPP_PORT_INPUT, MPP_POLL_BLOCK);
|
||||||
@@ -330,26 +328,28 @@ static int multi_dec_advanced(MpiDecCtx *data)
|
|||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
MppFrame frame_out = NULL;
|
MppFrame frame_out = NULL;
|
||||||
|
|
||||||
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
|
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
|
||||||
//mpp_assert(packet_out == packet);
|
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
/* write frame to file here */
|
|
||||||
MppBuffer buf_out = mpp_frame_get_buffer(frame_out);
|
|
||||||
|
|
||||||
if (buf_out) {
|
|
||||||
void *ptr = mpp_buffer_get_ptr(buf_out);
|
|
||||||
size_t len = mpp_buffer_get_size(buf_out);
|
|
||||||
|
|
||||||
if (data->fp_output)
|
if (data->fp_output)
|
||||||
fwrite(ptr, 1, len, data->fp_output);
|
dump_mpp_frame_to_file(frame, data->fp_output);
|
||||||
|
|
||||||
mpp_log("decoded frame %d size %d\n", data->frame_count, len);
|
mpp_log_q(quiet, "%p decoded frame %d\n", ctx, data->frame_count);
|
||||||
}
|
data->frame_count++;
|
||||||
|
|
||||||
if (mpp_frame_get_eos(frame_out)) {
|
if (mpp_frame_get_eos(frame_out)) {
|
||||||
; //mpp_log("found eos frame\n");
|
mpp_log_q(quiet, "%p found eos frame\n", ctx);
|
||||||
}
|
}
|
||||||
|
fps_calc_inc(cmd->fps);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->frame_num > 0) {
|
||||||
|
if (data->frame_count >= data->frame_num)
|
||||||
|
data->loop_end = 1;
|
||||||
|
} else if (data->frame_num == 0) {
|
||||||
|
if (slot->eos)
|
||||||
|
data->loop_end = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* output queue */
|
/* output queue */
|
||||||
@@ -358,17 +358,49 @@ static int multi_dec_advanced(MpiDecCtx *data)
|
|||||||
mpp_err("mpp task output enqueue failed\n");
|
mpp_err("mpp task output enqueue failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following input port task dequeue and enqueue is to make sure that
|
||||||
|
* the input packet can be released. We can directly deinit the input packet
|
||||||
|
* after frame output in most cases.
|
||||||
|
*/
|
||||||
|
if (0) {
|
||||||
|
mpp_packet_deinit(&packet);
|
||||||
|
} else {
|
||||||
|
ret = mpi->dequeue(ctx, MPP_PORT_INPUT, &task); /* input queue */
|
||||||
|
if (ret) {
|
||||||
|
mpp_err("%p mpp task input dequeue failed\n", ctx);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpp_assert(task);
|
||||||
|
if (task) {
|
||||||
|
MppPacket packet_out = NULL;
|
||||||
|
|
||||||
|
mpp_task_meta_get_packet(task, KEY_INPUT_PACKET, &packet_out);
|
||||||
|
|
||||||
|
if (!packet_out || packet_out != packet)
|
||||||
|
mpp_err_f("mismatch packet %p -> %p\n", packet, packet_out);
|
||||||
|
|
||||||
|
mpp_packet_deinit(&packet_out);
|
||||||
|
|
||||||
|
/* input empty task back to mpp to maintain task status */
|
||||||
|
ret = mpi->enqueue(ctx, MPP_PORT_INPUT, task);
|
||||||
|
if (ret)
|
||||||
|
mpp_err("%p mpp task input enqueue failed\n", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* multi_dec_decode(void *cmd_ctx)
|
void* multi_dec_decode(void *cmd_ctx)
|
||||||
{
|
{
|
||||||
MpiDecCtxInfo *info = (MpiDecCtxInfo *)cmd_ctx;
|
MpiDecMultiCtxInfo *info = (MpiDecMultiCtxInfo *)cmd_ctx;
|
||||||
|
MpiDecMultiCtx *dec_ctx = &info->ctx;
|
||||||
|
MpiDecMultiCtxRet *rets = &info->ret;
|
||||||
MpiDecTestCmd *cmd = info->cmd;
|
MpiDecTestCmd *cmd = info->cmd;
|
||||||
MpiDecCtx *dec_ctx = &info->ctx;
|
FileReader reader = cmd->reader;
|
||||||
MpiDecCtxRet *rets = &info->ret;
|
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
size_t file_size = 0;
|
|
||||||
|
|
||||||
// base flow context
|
// base flow context
|
||||||
MppCtx ctx = NULL;
|
MppCtx ctx = NULL;
|
||||||
@@ -389,26 +421,7 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
MppCodingType type = cmd->type;
|
MppCodingType type = cmd->type;
|
||||||
|
|
||||||
// resources
|
// resources
|
||||||
char *buf = NULL;
|
|
||||||
size_t packet_size = MPI_DEC_STREAM_SIZE;
|
|
||||||
MppBuffer pkt_buf = NULL;
|
|
||||||
MppBuffer frm_buf = NULL;
|
MppBuffer frm_buf = NULL;
|
||||||
FileReader reader = NULL;
|
|
||||||
|
|
||||||
// mpp_log("mpi_dec_test start\n");
|
|
||||||
|
|
||||||
if (cmd->have_input) {
|
|
||||||
dec_ctx->fp_input = fopen(cmd->file_input, "rb");
|
|
||||||
if (NULL == dec_ctx->fp_input) {
|
|
||||||
mpp_err("failed to open input file %s\n", cmd->file_input);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(dec_ctx->fp_input, 0L, SEEK_END);
|
|
||||||
file_size = ftell(dec_ctx->fp_input);
|
|
||||||
rewind(dec_ctx->fp_input);
|
|
||||||
// mpp_log("input file size %ld\n", file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->have_output) {
|
if (cmd->have_output) {
|
||||||
dec_ctx->fp_output = fopen(cmd->file_output, "w+b");
|
dec_ctx->fp_output = fopen(cmd->file_output, "w+b");
|
||||||
@@ -419,8 +432,6 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->simple) {
|
if (cmd->simple) {
|
||||||
reader_init(&reader, cmd->file_input, dec_ctx->fp_input);
|
|
||||||
|
|
||||||
ret = mpp_packet_init(&packet, NULL, 0);
|
ret = mpp_packet_init(&packet, NULL, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_packet_init failed\n");
|
mpp_err("mpp_packet_init failed\n");
|
||||||
@@ -436,14 +447,8 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mpp_buffer_group_get_internal(&dec_ctx->pkt_grp, MPP_BUFFER_TYPE_ION);
|
|
||||||
if (ret) {
|
|
||||||
mpp_err("failed to get buffer group for output packet ret %d\n", ret);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = mpp_frame_init(&frame); /* output frame */
|
ret = mpp_frame_init(&frame); /* output frame */
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_frame_init failed\n");
|
mpp_err("mpp_frame_init failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -461,37 +466,24 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: for mjpeg decoding send the whole file
|
|
||||||
if (type == MPP_VIDEO_CodingMJPEG) {
|
|
||||||
packet_size = file_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = mpp_buffer_get(dec_ctx->pkt_grp, &pkt_buf, packet_size);
|
|
||||||
if (ret) {
|
|
||||||
mpp_err("failed to get buffer for input frame ret %d\n", ret);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
mpp_packet_init_with_buffer(&packet, pkt_buf);
|
|
||||||
buf = mpp_buffer_get_ptr(pkt_buf);
|
|
||||||
|
|
||||||
mpp_frame_set_buffer(frame, frm_buf);
|
mpp_frame_set_buffer(frame, frm_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpp_log("mpi_dec_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);
|
||||||
|
if (ret) {
|
||||||
if (MPP_OK != ret) {
|
|
||||||
mpp_err("mpp_create failed\n");
|
mpp_err("mpp_create failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpp_log("%p mpi_dec_test decoder test start w %d h %d type %d\n",
|
||||||
|
ctx, width, height, type);
|
||||||
|
|
||||||
// NOTE: decoder split mode need to be set before init
|
// NOTE: decoder split mode need to be set before init
|
||||||
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
||||||
param = &need_split;
|
param = &need_split;
|
||||||
ret = mpi->control(ctx, mpi_cmd, param);
|
ret = mpi->control(ctx, mpi_cmd, param);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpi->control failed\n");
|
mpp_err("mpi->control failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -503,25 +495,24 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
if (timeout) {
|
if (timeout) {
|
||||||
param = &timeout;
|
param = &timeout;
|
||||||
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
|
ret = mpi->control(ctx, MPP_SET_OUTPUT_TIMEOUT, param);
|
||||||
if (MPP_OK != 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);
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mpp_init(ctx, MPP_CTX_DEC, type);
|
ret = mpp_init(ctx, MPP_CTX_DEC, type);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_init failed\n");
|
mpp_err("mpp_init failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dec_ctx->cmd = cmd;
|
||||||
dec_ctx->ctx = ctx;
|
dec_ctx->ctx = ctx;
|
||||||
dec_ctx->mpi = mpi;
|
dec_ctx->mpi = mpi;
|
||||||
dec_ctx->eos = 0;
|
|
||||||
dec_ctx->buf = buf;
|
|
||||||
dec_ctx->packet = packet;
|
dec_ctx->packet = packet;
|
||||||
dec_ctx->packet_size = packet_size;
|
|
||||||
dec_ctx->frame = frame;
|
dec_ctx->frame = frame;
|
||||||
|
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->reader = reader;
|
||||||
@@ -531,27 +522,25 @@ void* multi_dec_decode(void *cmd_ctx)
|
|||||||
|
|
||||||
t_s = mpp_time();
|
t_s = mpp_time();
|
||||||
if (cmd->simple) {
|
if (cmd->simple) {
|
||||||
while (!dec_ctx->eos) {
|
while (!dec_ctx->loop_end)
|
||||||
multi_dec_simple(dec_ctx);
|
multi_dec_simple(dec_ctx);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
while (!dec_ctx->eos) {
|
while (!dec_ctx->loop_end)
|
||||||
multi_dec_advanced(dec_ctx);
|
multi_dec_advanced(dec_ctx);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
t_e = mpp_time();
|
t_e = mpp_time();
|
||||||
rets->elapsed_time = t_e - t_s;
|
|
||||||
rets->frame_count = dec_ctx->frame_count;
|
|
||||||
rets->frame_rate = (float)dec_ctx->frame_count * 1000000 / rets->elapsed_time;
|
|
||||||
mpp_log("decode %d frame use time %lld ms frm rate %.2f\n",
|
|
||||||
dec_ctx->frame_count, rets->elapsed_time / 1000, rets->frame_rate);
|
|
||||||
|
|
||||||
ret = mpi->reset(ctx);
|
ret = mpi->reset(ctx);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("mpi->reset failed\n");
|
mpp_err("mpi->reset failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rets->elapsed_time = t_e - t_s;
|
||||||
|
rets->frame_count = dec_ctx->frame_count;
|
||||||
|
rets->frame_rate = (float)dec_ctx->frame_count * 1000000 / rets->elapsed_time;
|
||||||
|
rets->delay = dec_ctx->first_frm - dec_ctx->first_pkt;
|
||||||
|
|
||||||
MPP_TEST_OUT:
|
MPP_TEST_OUT:
|
||||||
if (packet) {
|
if (packet) {
|
||||||
mpp_packet_deinit(&packet);
|
mpp_packet_deinit(&packet);
|
||||||
@@ -568,25 +557,13 @@ MPP_TEST_OUT:
|
|||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->simple) {
|
if (!cmd->simple) {
|
||||||
reader_deinit(&reader);
|
|
||||||
} else {
|
|
||||||
if (pkt_buf) {
|
|
||||||
mpp_buffer_put(pkt_buf);
|
|
||||||
pkt_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frm_buf) {
|
if (frm_buf) {
|
||||||
mpp_buffer_put(frm_buf);
|
mpp_buffer_put(frm_buf);
|
||||||
frm_buf = NULL;
|
frm_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dec_ctx->pkt_grp) {
|
|
||||||
mpp_buffer_group_put(dec_ctx->pkt_grp);
|
|
||||||
dec_ctx->pkt_grp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dec_ctx->frm_grp) {
|
if (dec_ctx->frm_grp) {
|
||||||
mpp_buffer_group_put(dec_ctx->frm_grp);
|
mpp_buffer_group_put(dec_ctx->frm_grp);
|
||||||
dec_ctx->frm_grp = NULL;
|
dec_ctx->frm_grp = NULL;
|
||||||
@@ -610,7 +587,7 @@ int main(int argc, char **argv)
|
|||||||
RK_S32 ret = 0;
|
RK_S32 ret = 0;
|
||||||
MpiDecTestCmd cmd_ctx;
|
MpiDecTestCmd cmd_ctx;
|
||||||
MpiDecTestCmd* cmd = &cmd_ctx;
|
MpiDecTestCmd* cmd = &cmd_ctx;
|
||||||
MpiDecCtxInfo *ctxs = NULL;
|
MpiDecMultiCtxInfo *ctxs = NULL;
|
||||||
RK_S32 i = 0;
|
RK_S32 i = 0;
|
||||||
float total_rate = 0.0;
|
float total_rate = 0.0;
|
||||||
|
|
||||||
@@ -618,21 +595,21 @@ int main(int argc, char **argv)
|
|||||||
cmd->nthreads = 1;
|
cmd->nthreads = 1;
|
||||||
|
|
||||||
// parse the cmd option
|
// parse the cmd option
|
||||||
ret = mpi_dec_test_parse_options(argc, argv, cmd);
|
ret = mpi_dec_test_cmd_init(cmd, argc, argv);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mpp_err("mpi_dec_multi_test_parse_options: input parameter invalid\n");
|
mpp_err("mpi_dec_multi_test_parse_options: input parameter invalid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_help();
|
mpi_dec_test_cmd_help();
|
||||||
return ret;
|
goto RET;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_show_options(cmd);
|
mpi_dec_test_cmd_options(cmd);
|
||||||
|
|
||||||
cmd->simple = (cmd->type != MPP_VIDEO_CodingMJPEG) ? (1) : (0);
|
cmd->simple = (cmd->type != MPP_VIDEO_CodingMJPEG) ? (1) : (0);
|
||||||
|
|
||||||
ctxs = mpp_calloc(MpiDecCtxInfo, cmd->nthreads);
|
ctxs = mpp_calloc(MpiDecMultiCtxInfo, cmd->nthreads);
|
||||||
if (NULL == ctxs) {
|
if (NULL == ctxs) {
|
||||||
mpp_err("failed to alloc context for instances\n");
|
mpp_err("failed to alloc context for instances\n");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -648,20 +625,37 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd->frame_num < 0) {
|
||||||
|
// wait for input then quit decoding
|
||||||
|
mpp_log("*******************************************\n");
|
||||||
|
mpp_log("**** Press Enter to stop loop decoding ****\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++)
|
for (i = 0; i < cmd->nthreads; i++)
|
||||||
pthread_join(ctxs[i].thd, NULL);
|
pthread_join(ctxs[i].thd, NULL);
|
||||||
|
|
||||||
for (i = 0; i < cmd->nthreads; i++) {
|
for (i = 0; i < cmd->nthreads; i++) {
|
||||||
total_rate += ctxs[i].ret.frame_rate;
|
MpiDecMultiCtxRet *dec_ret = &ctxs[i].ret;
|
||||||
mpp_log("payload %d frame rate: %.2f first delay %d ms\n", i,
|
|
||||||
ctxs[i].ret.frame_rate,
|
mpp_log("chn %2d decode %d frames time %lld ms delay %3d ms fps %3.2f\n", i,
|
||||||
(ctxs[i].ctx.first_frm - ctxs[i].ctx.first_pkt) / 1000);
|
dec_ret->frame_count, (RK_S64)(dec_ret->elapsed_time / 1000),
|
||||||
|
(RK_S32)(dec_ret->delay / 1000), dec_ret->frame_rate);
|
||||||
|
|
||||||
|
total_rate += dec_ret->frame_rate;
|
||||||
}
|
}
|
||||||
mpp_free(ctxs);
|
mpp_free(ctxs);
|
||||||
ctxs = NULL;
|
ctxs = NULL;
|
||||||
|
|
||||||
total_rate /= cmd->nthreads;
|
total_rate /= cmd->nthreads;
|
||||||
mpp_log("average frame rate %d\n", (int)total_rate);
|
mpp_log("average frame rate %.2f\n", total_rate);
|
||||||
|
|
||||||
|
RET:
|
||||||
|
mpi_dec_test_cmd_deinit(cmd);
|
||||||
|
|
||||||
return (int)total_rate;
|
return (int)total_rate;
|
||||||
}
|
}
|
||||||
|
@@ -31,30 +31,24 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
MpiDecTestCmd *cmd;
|
||||||
MppCtx ctx;
|
MppCtx ctx;
|
||||||
MppApi *mpi;
|
MppApi *mpi;
|
||||||
RK_U32 quiet;
|
RK_U32 quiet;
|
||||||
|
|
||||||
/* end of stream flag when set quit the loop */
|
/* end of stream flag when set quit the loop */
|
||||||
RK_U32 eos;
|
RK_U32 loop_end;
|
||||||
|
|
||||||
/* buffer for stream data reading */
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
/* input and output */
|
/* input and output */
|
||||||
MppBufferGroup frm_grp;
|
MppBufferGroup frm_grp;
|
||||||
MppBufferGroup pkt_grp;
|
|
||||||
MppPacket packet;
|
MppPacket packet;
|
||||||
size_t packet_size;
|
|
||||||
MppFrame frame;
|
MppFrame frame;
|
||||||
|
|
||||||
FILE *fp_input;
|
FILE *fp_input;
|
||||||
FILE *fp_output;
|
FILE *fp_output;
|
||||||
FILE *fp_config;
|
|
||||||
RK_S32 frame_count;
|
RK_S32 frame_count;
|
||||||
RK_S32 frame_num;
|
RK_S32 frame_num;
|
||||||
size_t max_usage;
|
size_t max_usage;
|
||||||
FileReader reader;
|
|
||||||
} MpiDecLoopData;
|
} MpiDecLoopData;
|
||||||
|
|
||||||
static int dec_simple(MpiDecLoopData *data)
|
static int dec_simple(MpiDecLoopData *data)
|
||||||
@@ -62,87 +56,43 @@ static int dec_simple(MpiDecLoopData *data)
|
|||||||
RK_U32 pkt_done = 0;
|
RK_U32 pkt_done = 0;
|
||||||
RK_U32 pkt_eos = 0;
|
RK_U32 pkt_eos = 0;
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
|
MpiDecTestCmd *cmd = data->cmd;
|
||||||
MppCtx ctx = data->ctx;
|
MppCtx ctx = data->ctx;
|
||||||
MppApi *mpi = data->mpi;
|
MppApi *mpi = data->mpi;
|
||||||
char *buf = data->buf;
|
|
||||||
MppPacket packet = data->packet;
|
MppPacket packet = data->packet;
|
||||||
MppFrame frame = NULL;
|
MppFrame frame = NULL;
|
||||||
size_t read_size = 0;
|
FileBufSlot *slot = NULL;
|
||||||
size_t packet_size = data->packet_size;
|
|
||||||
FileReader reader = data->reader;
|
|
||||||
RK_U32 quiet = data->quiet;
|
RK_U32 quiet = data->quiet;
|
||||||
|
|
||||||
do {
|
|
||||||
if (data->fp_config) {
|
|
||||||
char line[MAX_FILE_NAME_LENGTH];
|
|
||||||
char *ptr = NULL;
|
|
||||||
|
|
||||||
do {
|
|
||||||
ptr = fgets(line, MAX_FILE_NAME_LENGTH, data->fp_config);
|
|
||||||
if (ptr) {
|
|
||||||
OpsLine info;
|
|
||||||
RK_S32 cnt = parse_config_line(line, &info);
|
|
||||||
|
|
||||||
// parser for packet message
|
|
||||||
if (cnt >= 3 && 0 == strncmp("pkt", info.cmd, sizeof(info.cmd))) {
|
|
||||||
packet_size = info.value2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// parser for reset message at the end
|
|
||||||
if (0 == strncmp("rst", info.cmd, 3)) {
|
|
||||||
mpp_log("%p get reset cmd\n", ctx);
|
|
||||||
packet_size = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mpp_log("%p get end of cfg file\n", ctx);
|
|
||||||
packet_size = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// when packet size is valid read the input binary file
|
// when packet size is valid read the input binary file
|
||||||
if (packet_size) {
|
ret = reader_read(cmd->reader, &slot);
|
||||||
FileBufSlot *slot = NULL;
|
|
||||||
ret = reader_read(reader, &slot);
|
|
||||||
|
|
||||||
mpp_assert(ret == MPP_OK);
|
mpp_assert(ret == MPP_OK);
|
||||||
mpp_assert(slot);
|
mpp_assert(slot);
|
||||||
|
|
||||||
pkt_eos = slot->eos;
|
pkt_eos = slot->eos;
|
||||||
buf = slot->data;
|
|
||||||
read_size = slot->size;
|
|
||||||
data->eos = pkt_eos;
|
|
||||||
|
|
||||||
if (pkt_eos) {
|
if (pkt_eos) {
|
||||||
if (data->frame_num < 0) {
|
if (data->frame_num < 0 || data->frame_num > data->frame_count) {
|
||||||
mpp_log_q(quiet, "%p loop again\n", ctx);
|
mpp_log_q(quiet, "%p loop again\n", ctx);
|
||||||
reader_rewind(reader);
|
reader_rewind(cmd->reader);
|
||||||
if (data->fp_config) {
|
pkt_eos = 0;
|
||||||
clearerr(data->fp_config);
|
|
||||||
rewind(data->fp_config);
|
|
||||||
}
|
|
||||||
data->eos = pkt_eos = 0;
|
|
||||||
} else {
|
} else {
|
||||||
mpp_log_q(quiet, "%p found last packet\n", ctx);
|
mpp_log_q(quiet, "%p found last packet\n", ctx);
|
||||||
break;
|
data->loop_end = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} while (!read_size);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
RK_U32 frm_eos = 0;
|
||||||
RK_S32 times = 5;
|
RK_S32 times = 5;
|
||||||
// send the packet first if packet is not done
|
// send the packet first if packet is not done
|
||||||
if (!pkt_done) {
|
if (!pkt_done) {
|
||||||
@@ -154,7 +104,6 @@ static int dec_simple(MpiDecLoopData *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;
|
||||||
RK_U32 frm_eos = 0;
|
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
ret = mpi->decode_get_frame(ctx, &frame);
|
ret = mpi->decode_get_frame(ctx, &frame);
|
||||||
@@ -311,6 +260,8 @@ static int dec_simple(MpiDecLoopData *data)
|
|||||||
data->frame_count++;
|
data->frame_count++;
|
||||||
if (data->fp_output && !err_info)
|
if (data->fp_output && !err_info)
|
||||||
dump_mpp_frame_to_file(frame, data->fp_output);
|
dump_mpp_frame_to_file(frame, data->fp_output);
|
||||||
|
|
||||||
|
fps_calc_inc(cmd->fps);
|
||||||
}
|
}
|
||||||
frm_eos = mpp_frame_get_eos(frame);
|
frm_eos = mpp_frame_get_eos(frame);
|
||||||
mpp_frame_deinit(&frame);
|
mpp_frame_deinit(&frame);
|
||||||
@@ -336,19 +287,18 @@ static int dec_simple(MpiDecLoopData *data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->frame_num > 0 && data->frame_count >= data->frame_num) {
|
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
|
||||||
data->eos = 1;
|
((data->frame_num == 0) && frm_eos))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (get_frm)
|
if (get_frm)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
if (data->frame_num > 0 && data->frame_count >= data->frame_num) {
|
if ((data->frame_num > 0 && (data->frame_count >= data->frame_num)) ||
|
||||||
data->eos = 1;
|
((data->frame_num == 0) && frm_eos)) {
|
||||||
mpp_log_q(quiet, "%p reach max frame number %d\n", ctx, data->frame_count);
|
data->loop_end = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,33 +320,24 @@ static int dec_simple(MpiDecLoopData *data)
|
|||||||
|
|
||||||
static int dec_advanced(MpiDecLoopData *data)
|
static int dec_advanced(MpiDecLoopData *data)
|
||||||
{
|
{
|
||||||
RK_U32 pkt_eos = 0;
|
|
||||||
MPP_RET ret = MPP_OK;
|
MPP_RET ret = MPP_OK;
|
||||||
|
MpiDecTestCmd *cmd = data->cmd;
|
||||||
MppCtx ctx = data->ctx;
|
MppCtx ctx = data->ctx;
|
||||||
MppApi *mpi = data->mpi;
|
MppApi *mpi = data->mpi;
|
||||||
char *buf = data->buf;
|
MppPacket packet = NULL;
|
||||||
MppPacket packet = data->packet;
|
|
||||||
MppFrame frame = data->frame;
|
MppFrame frame = data->frame;
|
||||||
MppTask task = NULL;
|
MppTask task = NULL;
|
||||||
size_t read_size = fread(buf, 1, data->packet_size, data->fp_input);
|
|
||||||
RK_U32 quiet = data->quiet;
|
RK_U32 quiet = data->quiet;
|
||||||
|
FileBufSlot *slot = NULL;
|
||||||
|
|
||||||
if (read_size != data->packet_size || feof(data->fp_input)) {
|
ret = reader_index_read(cmd->reader, 0, &slot);
|
||||||
if (data->frame_num < 0) {
|
mpp_assert(ret == MPP_OK);
|
||||||
clearerr(data->fp_input);
|
mpp_assert(slot);
|
||||||
rewind(data->fp_input);
|
|
||||||
} else {
|
mpp_packet_init_with_buffer(&packet, slot->buf);
|
||||||
mpp_log_q(quiet, "%p found last packet\n", ctx);
|
|
||||||
// setup eos flag
|
|
||||||
data->eos = pkt_eos = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset pos
|
|
||||||
mpp_packet_set_pos(packet, buf);
|
|
||||||
mpp_packet_set_length(packet, read_size);
|
|
||||||
// setup eos flag
|
// setup eos flag
|
||||||
if (pkt_eos)
|
if (slot->eos)
|
||||||
mpp_packet_set_eos(packet);
|
mpp_packet_set_eos(packet);
|
||||||
|
|
||||||
ret = mpi->poll(ctx, MPP_PORT_INPUT, MPP_POLL_BLOCK);
|
ret = mpi->poll(ctx, MPP_PORT_INPUT, MPP_POLL_BLOCK);
|
||||||
@@ -439,8 +380,8 @@ static int dec_advanced(MpiDecLoopData *data)
|
|||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
MppFrame frame_out = NULL;
|
MppFrame frame_out = NULL;
|
||||||
|
|
||||||
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
|
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
|
||||||
//mpp_assert(packet_out == packet);
|
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
/* write frame to file here */
|
/* write frame to file here */
|
||||||
@@ -453,14 +394,15 @@ static int dec_advanced(MpiDecLoopData *data)
|
|||||||
if (mpp_frame_get_eos(frame_out)) {
|
if (mpp_frame_get_eos(frame_out)) {
|
||||||
mpp_log_q(quiet, "%p found eos frame\n", ctx);
|
mpp_log_q(quiet, "%p found eos frame\n", ctx);
|
||||||
}
|
}
|
||||||
|
fps_calc_inc(cmd->fps);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->frame_num > 0 && data->frame_count >= data->frame_num) {
|
if (data->frame_num > 0) {
|
||||||
data->eos = 1;
|
if (data->frame_count >= data->frame_num)
|
||||||
} else {
|
data->loop_end = 1;
|
||||||
data->eos = 0;
|
} else if (data->frame_num == 0) {
|
||||||
clearerr(data->fp_input);
|
if (slot->eos)
|
||||||
rewind(data->fp_input);
|
data->loop_end = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* output queue */
|
/* output queue */
|
||||||
@@ -469,14 +411,70 @@ static int dec_advanced(MpiDecLoopData *data)
|
|||||||
mpp_err("%p mpp task output enqueue failed\n", ctx);
|
mpp_err("%p mpp task output enqueue failed\n", ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following input port task dequeue and enqueue is to make sure that
|
||||||
|
* the input packet can be released. We can directly deinit the input packet
|
||||||
|
* after frame output in most cases.
|
||||||
|
*/
|
||||||
|
if (0) {
|
||||||
|
mpp_packet_deinit(&packet);
|
||||||
|
} else {
|
||||||
|
ret = mpi->dequeue(ctx, MPP_PORT_INPUT, &task); /* input queue */
|
||||||
|
if (ret) {
|
||||||
|
mpp_err("%p mpp task input dequeue failed\n", ctx);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpp_assert(task);
|
||||||
|
if (task) {
|
||||||
|
MppPacket packet_out = NULL;
|
||||||
|
|
||||||
|
mpp_task_meta_get_packet(task, KEY_INPUT_PACKET, &packet_out);
|
||||||
|
|
||||||
|
if (!packet_out || packet_out != packet)
|
||||||
|
mpp_err_f("mismatch packet %p -> %p\n", packet, packet_out);
|
||||||
|
|
||||||
|
mpp_packet_deinit(&packet_out);
|
||||||
|
|
||||||
|
/* input empty task back to mpp to maintain task status */
|
||||||
|
ret = mpi->enqueue(ctx, MPP_PORT_INPUT, task);
|
||||||
|
if (ret)
|
||||||
|
mpp_err("%p mpp task input enqueue failed\n", ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *thread_decode(void *arg)
|
||||||
|
{
|
||||||
|
MpiDecLoopData *data = (MpiDecLoopData *)arg;
|
||||||
|
MpiDecTestCmd *cmd = data->cmd;
|
||||||
|
MppCtx ctx = data->ctx;
|
||||||
|
MppApi *mpi = data->mpi;
|
||||||
|
|
||||||
|
if (cmd->simple) {
|
||||||
|
while (!data->loop_end)
|
||||||
|
dec_simple(data);
|
||||||
|
} else {
|
||||||
|
/* NOTE: change output format before jpeg decoding */
|
||||||
|
if (MPP_FRAME_FMT_IS_YUV(cmd->format) || MPP_FRAME_FMT_IS_RGB(cmd->format)) {
|
||||||
|
MPP_RET ret = mpi->control(ctx, MPP_DEC_SET_OUTPUT_FORMAT, &cmd->format);
|
||||||
|
if (ret) {
|
||||||
|
mpp_err("Failed to set output format %d\n", cmd->format);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!data->loop_end)
|
||||||
|
dec_advanced(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int dec_decode(MpiDecTestCmd *cmd)
|
int dec_decode(MpiDecTestCmd *cmd)
|
||||||
{
|
{
|
||||||
MPP_RET ret = MPP_OK;
|
|
||||||
size_t file_size = 0;
|
|
||||||
|
|
||||||
// base flow context
|
// base flow context
|
||||||
MppCtx ctx = NULL;
|
MppCtx ctx = NULL;
|
||||||
MppApi *mpi = NULL;
|
MppApi *mpi = NULL;
|
||||||
@@ -499,28 +497,17 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
MppDecCfg cfg = NULL;
|
MppDecCfg cfg = NULL;
|
||||||
|
|
||||||
// resources
|
// resources
|
||||||
char *buf = NULL;
|
|
||||||
size_t packet_size = cmd->pkt_size;
|
|
||||||
MppBuffer pkt_buf = NULL;
|
|
||||||
MppBuffer frm_buf = NULL;
|
MppBuffer frm_buf = NULL;
|
||||||
FileReader reader = NULL;
|
pthread_t thd;
|
||||||
|
pthread_attr_t attr;
|
||||||
MpiDecLoopData data;
|
MpiDecLoopData data;
|
||||||
|
MPP_RET ret = MPP_OK;
|
||||||
|
|
||||||
mpp_log("mpi_dec_test start\n");
|
mpp_log("mpi_dec_test start\n");
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
|
pthread_attr_init(&attr);
|
||||||
|
|
||||||
if (cmd->have_input) {
|
cmd->simple = (cmd->type != MPP_VIDEO_CodingMJPEG) ? (1) : (0);
|
||||||
data.fp_input = fopen(cmd->file_input, "rb");
|
|
||||||
if (NULL == data.fp_input) {
|
|
||||||
mpp_err("failed to open input file %s\n", cmd->file_input);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(data.fp_input, 0L, SEEK_END);
|
|
||||||
file_size = ftell(data.fp_input);
|
|
||||||
rewind(data.fp_input);
|
|
||||||
mpp_log("input file size %ld\n", file_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->have_output) {
|
if (cmd->have_output) {
|
||||||
data.fp_output = fopen(cmd->file_output, "w+b");
|
data.fp_output = fopen(cmd->file_output, "w+b");
|
||||||
@@ -530,16 +517,7 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->have_config) {
|
|
||||||
data.fp_config = fopen(cmd->file_config, "r");
|
|
||||||
if (NULL == data.fp_config) {
|
|
||||||
mpp_err("failed to open config file %s\n", cmd->file_config);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->simple) {
|
if (cmd->simple) {
|
||||||
reader_init(&reader, cmd->file_input, data.fp_input);
|
|
||||||
ret = mpp_packet_init(&packet, NULL, 0);
|
ret = mpp_packet_init(&packet, NULL, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_packet_init failed\n");
|
mpp_err("mpp_packet_init failed\n");
|
||||||
@@ -555,12 +533,6 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mpp_buffer_group_get_internal(&data.pkt_grp, MPP_BUFFER_TYPE_ION);
|
|
||||||
if (ret) {
|
|
||||||
mpp_err("failed to get buffer group for output packet ret %d\n", ret);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = mpp_frame_init(&frame); /* output frame */
|
ret = mpp_frame_init(&frame); /* output frame */
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_frame_init failed\n");
|
mpp_err("mpp_frame_init failed\n");
|
||||||
@@ -580,25 +552,11 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: for mjpeg decoding send the whole file
|
|
||||||
if (type == MPP_VIDEO_CodingMJPEG) {
|
|
||||||
packet_size = file_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = mpp_buffer_get(data.pkt_grp, &pkt_buf, packet_size);
|
|
||||||
if (ret) {
|
|
||||||
mpp_err("failed to get buffer for input frame ret %d\n", ret);
|
|
||||||
goto MPP_TEST_OUT;
|
|
||||||
}
|
|
||||||
mpp_packet_init_with_buffer(&packet, pkt_buf);
|
|
||||||
buf = mpp_buffer_get_ptr(pkt_buf);
|
|
||||||
|
|
||||||
mpp_frame_set_buffer(frame, frm_buf);
|
mpp_frame_set_buffer(frame, frm_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decoder demo
|
// decoder demo
|
||||||
ret = mpp_create(&ctx, &mpi);
|
ret = mpp_create(&ctx, &mpi);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_create failed\n");
|
mpp_err("mpp_create failed\n");
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
@@ -611,7 +569,7 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
|
||||||
param = &need_split;
|
param = &need_split;
|
||||||
ret = mpi->control(ctx, mpi_cmd, param);
|
ret = mpi->control(ctx, mpi_cmd, param);
|
||||||
if (MPP_OK != ret) {
|
if (ret) {
|
||||||
mpp_err("%p mpi->control failed\n", ctx);
|
mpp_err("%p mpi->control failed\n", ctx);
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
@@ -661,36 +619,35 @@ int dec_decode(MpiDecTestCmd *cmd)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.cmd = cmd;
|
||||||
data.ctx = ctx;
|
data.ctx = ctx;
|
||||||
data.mpi = mpi;
|
data.mpi = mpi;
|
||||||
data.eos = 0;
|
data.loop_end = 0;
|
||||||
data.buf = buf;
|
|
||||||
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;
|
||||||
data.reader = reader;
|
|
||||||
data.quiet = cmd->quiet;
|
data.quiet = cmd->quiet;
|
||||||
|
|
||||||
if (cmd->simple) {
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
while (!data.eos) {
|
|
||||||
dec_simple(&data);
|
ret = pthread_create(&thd, &attr, thread_decode, &data);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* NOTE: change output format before jpeg decoding */
|
|
||||||
if (MPP_FRAME_FMT_IS_YUV(cmd->format) || MPP_FRAME_FMT_IS_RGB(cmd->format)) {
|
|
||||||
ret = mpi->control(ctx, MPP_DEC_SET_OUTPUT_FORMAT, &cmd->format);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("Failed to set output format %d\n", cmd->format);
|
mpp_err("failed to create thread for input ret %d\n", ret);
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd->frame_num < 0) {
|
||||||
|
// wait for input then quit decoding
|
||||||
|
mpp_log("*******************************************\n");
|
||||||
|
mpp_log("**** Press Enter to stop loop decoding ****\n");
|
||||||
|
mpp_log("*******************************************\n");
|
||||||
|
|
||||||
|
getc(stdin);
|
||||||
|
data.loop_end = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!data.eos) {
|
pthread_join(thd, NULL);
|
||||||
dec_advanced(&data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd->max_usage = data.max_usage;
|
cmd->max_usage = data.max_usage;
|
||||||
{
|
{
|
||||||
@@ -735,25 +692,13 @@ MPP_TEST_OUT:
|
|||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->simple) {
|
if (!cmd->simple) {
|
||||||
reader_deinit(&reader);
|
|
||||||
} else {
|
|
||||||
if (pkt_buf) {
|
|
||||||
mpp_buffer_put(pkt_buf);
|
|
||||||
pkt_buf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frm_buf) {
|
if (frm_buf) {
|
||||||
mpp_buffer_put(frm_buf);
|
mpp_buffer_put(frm_buf);
|
||||||
frm_buf = NULL;
|
frm_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.pkt_grp) {
|
|
||||||
mpp_buffer_group_put(data.pkt_grp);
|
|
||||||
data.pkt_grp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.frm_grp) {
|
if (data.frm_grp) {
|
||||||
mpp_buffer_group_put(data.frm_grp);
|
mpp_buffer_group_put(data.frm_grp);
|
||||||
data.frm_grp = NULL;
|
data.frm_grp = NULL;
|
||||||
@@ -764,16 +709,13 @@ MPP_TEST_OUT:
|
|||||||
data.fp_output = NULL;
|
data.fp_output = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.fp_input) {
|
|
||||||
fclose(data.fp_input);
|
|
||||||
data.fp_input = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
mpp_dec_cfg_deinit(cfg);
|
mpp_dec_cfg_deinit(cfg);
|
||||||
cfg = NULL;
|
cfg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -788,21 +730,17 @@ int main(int argc, char **argv)
|
|||||||
cmd->pkt_size = MPI_DEC_STREAM_SIZE;
|
cmd->pkt_size = MPI_DEC_STREAM_SIZE;
|
||||||
|
|
||||||
// parse the cmd option
|
// parse the cmd option
|
||||||
ret = mpi_dec_test_parse_options(argc, argv, cmd);
|
ret = mpi_dec_test_cmd_init(cmd, argc, argv);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mpp_err("mpi_dec_test_parse_options: input parameter invalid\n");
|
mpp_err("mpi_dec_test_cmd_init: input parameter invalid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_help();
|
mpi_dec_test_cmd_help();
|
||||||
return ret;
|
goto RET;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpi_dec_test_show_options(cmd);
|
mpi_dec_test_cmd_options(cmd);
|
||||||
|
|
||||||
mpp_env_set_u32("mpi_debug", cmd->debug);
|
|
||||||
|
|
||||||
cmd->simple = (cmd->type != MPP_VIDEO_CodingMJPEG) ? (1) : (0);
|
|
||||||
|
|
||||||
ret = dec_decode(cmd);
|
ret = dec_decode(cmd);
|
||||||
if (MPP_OK == ret)
|
if (MPP_OK == ret)
|
||||||
@@ -810,7 +748,9 @@ int main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
mpp_err("test failed ret %d\n", ret);
|
mpp_err("test failed ret %d\n", ret);
|
||||||
|
|
||||||
mpp_env_set_u32("mpi_debug", 0x0);
|
RET:
|
||||||
|
mpi_dec_test_cmd_deinit(cmd);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,6 +59,7 @@ typedef struct FileReader_t {
|
|||||||
/* return value for each read */
|
/* return value for each read */
|
||||||
size_t read_total;
|
size_t read_total;
|
||||||
size_t read_size;
|
size_t read_size;
|
||||||
|
MppBufferGroup group;
|
||||||
|
|
||||||
pthread_t thd;
|
pthread_t thd;
|
||||||
volatile RK_U32 thd_stop;
|
volatile RK_U32 thd_stop;
|
||||||
@@ -79,10 +80,10 @@ OptionInfo mpi_dec_cmd[] = {
|
|||||||
{"h", "height", "the height of input bitstream"},
|
{"h", "height", "the height of input bitstream"},
|
||||||
{"t", "type", "input stream coding type"},
|
{"t", "type", "input stream coding type"},
|
||||||
{"f", "format", "output frame format type"},
|
{"f", "format", "output frame format type"},
|
||||||
{"d", "debug", "debug flag"},
|
|
||||||
{"x", "timeout", "output timeout interval"},
|
{"x", "timeout", "output timeout interval"},
|
||||||
{"n", "frame_number", "max output frame number"},
|
{"n", "frame_number", "max output frame number"},
|
||||||
{"s", "instance_nb", "number of instances"},
|
{"s", "instance_nb", "number of instances"},
|
||||||
|
{"v", "trace", "q - quiet f - show fps"},
|
||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,7 +138,7 @@ static RK_U32 read_jpeg_file(FileReader data)
|
|||||||
MppBuffer hw_buf = NULL;
|
MppBuffer hw_buf = NULL;
|
||||||
FileBufSlot *slot = mpp_calloc(FileBufSlot, 1);
|
FileBufSlot *slot = mpp_calloc(FileBufSlot, 1);
|
||||||
|
|
||||||
mpp_buffer_get(NULL, &hw_buf, impl->file_size);
|
mpp_buffer_get(impl->group, &hw_buf, impl->file_size);
|
||||||
mpp_assert(hw_buf);
|
mpp_assert(hw_buf);
|
||||||
|
|
||||||
slot->data = mpp_buffer_get_ptr(hw_buf);
|
slot->data = mpp_buffer_get_ptr(hw_buf);
|
||||||
@@ -212,6 +213,8 @@ static void check_file_type(FileReader data, char *file_in)
|
|||||||
impl->seek_base = 0;
|
impl->seek_base = 0;
|
||||||
impl->read_func = read_jpeg_file;
|
impl->read_func = read_jpeg_file;
|
||||||
impl->slot_max = 1;
|
impl->slot_max = 1;
|
||||||
|
mpp_buffer_group_get_internal(&impl->group, MPP_BUFFER_TYPE_ION);
|
||||||
|
mpp_assert(impl->group);
|
||||||
} else {
|
} else {
|
||||||
RK_U32 buf_size = 0;
|
RK_U32 buf_size = 0;
|
||||||
|
|
||||||
@@ -229,6 +232,17 @@ static void check_file_type(FileReader data, char *file_in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t reader_size(FileReader reader)
|
||||||
|
{
|
||||||
|
FileReaderImpl *impl = (FileReaderImpl*)reader;
|
||||||
|
size_t size = 0;
|
||||||
|
|
||||||
|
if (impl)
|
||||||
|
size = impl->file_size;
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
MPP_RET reader_read(FileReader reader, FileBufSlot **buf)
|
MPP_RET reader_read(FileReader reader, FileBufSlot **buf)
|
||||||
{
|
{
|
||||||
FileReaderImpl *impl = (FileReaderImpl*)reader;
|
FileReaderImpl *impl = (FileReaderImpl*)reader;
|
||||||
@@ -293,13 +307,19 @@ void reader_rewind(FileReader reader)
|
|||||||
impl->slot_rd_idx = 0;
|
impl->slot_rd_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader_init(FileReader* reader, char* file_in, FILE* fp_in)
|
void reader_init(FileReader* reader, char* file_in)
|
||||||
{
|
{
|
||||||
FileReaderImpl *impl = mpp_calloc(FileReaderImpl, 1);
|
|
||||||
FILE *fp_input = fopen(file_in, "rb");
|
FILE *fp_input = fopen(file_in, "rb");
|
||||||
(void) fp_in;
|
FileReaderImpl *impl = NULL;
|
||||||
|
|
||||||
mpp_assert(fp_input);
|
if (!fp_input) {
|
||||||
|
mpp_err("failed to open input file %s\n", file_in);
|
||||||
|
*reader = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl = mpp_calloc(FileReaderImpl, 1);
|
||||||
|
mpp_assert(impl);
|
||||||
|
|
||||||
impl->fp_input = fp_input;
|
impl->fp_input = fp_input;
|
||||||
fseek(fp_input, 0L, SEEK_END);
|
fseek(fp_input, 0L, SEEK_END);
|
||||||
@@ -315,9 +335,9 @@ void reader_init(FileReader* reader, char* file_in, FILE* fp_in)
|
|||||||
*reader = impl;
|
*reader = impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reader_deinit(FileReader *reader)
|
void reader_deinit(FileReader reader)
|
||||||
{
|
{
|
||||||
FileReaderImpl *impl = (FileReaderImpl*)(*reader);
|
FileReaderImpl *impl = (FileReaderImpl*)(reader);
|
||||||
RK_U32 i;
|
RK_U32 i;
|
||||||
|
|
||||||
mpp_assert(impl);
|
mpp_assert(impl);
|
||||||
@@ -334,15 +354,19 @@ void reader_deinit(FileReader *reader)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (slot->buf) {
|
if (slot->buf) {
|
||||||
mpp_buffer_put(&slot->buf);
|
mpp_buffer_put(slot->buf);
|
||||||
slot->buf = NULL;
|
slot->buf = NULL;
|
||||||
}
|
}
|
||||||
MPP_FREE(impl->slots[i]);
|
MPP_FREE(impl->slots[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (impl->group) {
|
||||||
|
mpp_buffer_group_put(impl->group);
|
||||||
|
impl->group = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
MPP_FREE(impl->slots);
|
MPP_FREE(impl->slots);
|
||||||
MPP_FREE(impl);
|
MPP_FREE(impl);
|
||||||
*reader = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* reader_worker(void *param)
|
static void* reader_worker(void *param)
|
||||||
@@ -392,14 +416,14 @@ 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_help()
|
void mpi_dec_test_cmd_help()
|
||||||
{
|
{
|
||||||
mpp_log("usage: mpi_dec_test [options]\n");
|
mpp_log("usage: mpi_dec_test [options]\n");
|
||||||
show_options(mpi_dec_cmd);
|
show_options(mpi_dec_cmd);
|
||||||
mpp_show_support_format();
|
mpp_show_support_format();
|
||||||
}
|
}
|
||||||
|
|
||||||
RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
|
RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *opt;
|
const char *opt;
|
||||||
const char *next;
|
const char *next;
|
||||||
@@ -449,26 +473,6 @@ RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
|
|||||||
goto PARSE_OPINIONS_OUT;
|
goto PARSE_OPINIONS_OUT;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case 'c' : {
|
|
||||||
if (next) {
|
|
||||||
strncpy(cmd->file_config, next, MAX_FILE_NAME_LENGTH - 1);
|
|
||||||
cmd->have_config = 1;
|
|
||||||
|
|
||||||
// enlarge packet buffer size for large input stream case
|
|
||||||
cmd->pkt_size = SZ_1M;
|
|
||||||
} else {
|
|
||||||
mpp_log("output file is invalid\n");
|
|
||||||
goto PARSE_OPINIONS_OUT;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case 'd' : {
|
|
||||||
if (next) {
|
|
||||||
cmd->debug = atoi(next);;
|
|
||||||
} else {
|
|
||||||
mpp_err("invalid debug flag\n");
|
|
||||||
goto PARSE_OPINIONS_OUT;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case 'w' : {
|
case 'w' : {
|
||||||
if (next) {
|
if (next) {
|
||||||
cmd->width = atoi(next);
|
cmd->width = atoi(next);
|
||||||
@@ -479,7 +483,7 @@ RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
|
|||||||
} break;
|
} break;
|
||||||
case 'h' : {
|
case 'h' : {
|
||||||
if ((*(opt + 1) != '\0') && !strncmp(opt, "help", 4)) {
|
if ((*(opt + 1) != '\0') && !strncmp(opt, "help", 4)) {
|
||||||
mpi_dec_test_help();
|
mpi_dec_test_cmd_help();
|
||||||
err = 1;
|
err = 1;
|
||||||
goto PARSE_OPINIONS_OUT;
|
goto PARSE_OPINIONS_OUT;
|
||||||
} else if (next) {
|
} else if (next) {
|
||||||
@@ -544,9 +548,13 @@ RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
|
|||||||
goto PARSE_OPINIONS_OUT;
|
goto PARSE_OPINIONS_OUT;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case 'q' : {
|
case 'v' : {
|
||||||
|
if (next) {
|
||||||
|
if (strstr(next, "q"))
|
||||||
cmd->quiet = 1;
|
cmd->quiet = 1;
|
||||||
optindex--;
|
if (strstr(next, "f"))
|
||||||
|
cmd->trace_fps = 1;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
default : {
|
default : {
|
||||||
mpp_err("skip invalid opt %c\n", *opt);
|
mpp_err("skip invalid opt %c\n", *opt);
|
||||||
@@ -560,18 +568,45 @@ RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
|
|||||||
err = 0;
|
err = 0;
|
||||||
|
|
||||||
PARSE_OPINIONS_OUT:
|
PARSE_OPINIONS_OUT:
|
||||||
|
if (cmd->have_input) {
|
||||||
|
reader_init(&cmd->reader, cmd->file_input);
|
||||||
|
if (cmd->reader)
|
||||||
|
mpp_log("input file %s size %ld\n", cmd->file_input, reader_size(cmd->reader));
|
||||||
|
}
|
||||||
|
if (cmd->trace_fps) {
|
||||||
|
fps_calc_init(&cmd->fps);
|
||||||
|
mpp_assert(cmd->fps);
|
||||||
|
fps_calc_set_cb(cmd->fps, show_dec_fps);
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpi_dec_test_show_options(MpiDecTestCmd* cmd)
|
RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd)
|
||||||
|
{
|
||||||
|
if (!cmd)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (cmd->reader) {
|
||||||
|
reader_deinit(cmd->reader);
|
||||||
|
cmd->reader = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd->fps) {
|
||||||
|
fps_calc_deinit(cmd->fps);
|
||||||
|
cmd->fps = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mpi_dec_test_cmd_options(MpiDecTestCmd* cmd)
|
||||||
{
|
{
|
||||||
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);
|
||||||
mpp_log("config file name: %s\n", cmd->file_config);
|
|
||||||
mpp_log("width : %4d\n", cmd->width);
|
mpp_log("width : %4d\n", cmd->width);
|
||||||
mpp_log("height : %4d\n", cmd->height);
|
mpp_log("height : %4d\n", cmd->height);
|
||||||
mpp_log("type : %d\n", cmd->type);
|
mpp_log("type : %4d\n", cmd->type);
|
||||||
mpp_log("debug flag : %x\n", cmd->debug);
|
mpp_log("max frames : %4d\n", cmd->frame_num);
|
||||||
mpp_log("max frames : %d\n", cmd->frame_num);
|
|
||||||
}
|
}
|
||||||
|
@@ -38,17 +38,14 @@ typedef struct FileBufSlot_t {
|
|||||||
typedef struct MpiDecTestCmd_t {
|
typedef struct MpiDecTestCmd_t {
|
||||||
char file_input[MAX_FILE_NAME_LENGTH];
|
char file_input[MAX_FILE_NAME_LENGTH];
|
||||||
char file_output[MAX_FILE_NAME_LENGTH];
|
char file_output[MAX_FILE_NAME_LENGTH];
|
||||||
char file_config[MAX_FILE_NAME_LENGTH];
|
|
||||||
MppCodingType type;
|
MppCodingType type;
|
||||||
MppFrameFormat format;
|
MppFrameFormat format;
|
||||||
RK_U32 width;
|
RK_U32 width;
|
||||||
RK_U32 height;
|
RK_U32 height;
|
||||||
RK_U32 debug;
|
|
||||||
RK_U32 quiet;
|
|
||||||
|
|
||||||
RK_U32 have_input;
|
RK_U32 have_input;
|
||||||
RK_U32 have_output;
|
RK_U32 have_output;
|
||||||
RK_U32 have_config;
|
|
||||||
|
|
||||||
RK_U32 simple;
|
RK_U32 simple;
|
||||||
RK_S32 timeout;
|
RK_S32 timeout;
|
||||||
@@ -58,21 +55,32 @@ typedef struct MpiDecTestCmd_t {
|
|||||||
RK_S32 nthreads;
|
RK_S32 nthreads;
|
||||||
// report information
|
// report information
|
||||||
size_t max_usage;
|
size_t max_usage;
|
||||||
|
|
||||||
|
/* data for share */
|
||||||
|
FileReader reader;
|
||||||
|
FpsCalc fps;
|
||||||
|
|
||||||
|
/* runtime log flag */
|
||||||
|
RK_U32 debug;
|
||||||
|
RK_U32 quiet;
|
||||||
|
RK_U32 trace_fps;
|
||||||
} MpiDecTestCmd;
|
} MpiDecTestCmd;
|
||||||
|
|
||||||
extern OptionInfo mpi_dec_cmd[];
|
extern OptionInfo mpi_dec_cmd[];
|
||||||
|
|
||||||
RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd);
|
RK_S32 mpi_dec_test_cmd_init(MpiDecTestCmd* cmd, int argc, char **argv);
|
||||||
void mpi_dec_test_show_options(MpiDecTestCmd* cmd);
|
RK_S32 mpi_dec_test_cmd_deinit(MpiDecTestCmd* cmd);
|
||||||
void mpi_dec_test_help();
|
void mpi_dec_test_cmd_options(MpiDecTestCmd* cmd);
|
||||||
|
void mpi_dec_test_cmd_help();
|
||||||
|
|
||||||
void reader_init(FileReader* reader, char* file_in, FILE* fp_in);
|
void reader_init(FileReader* reader, char* file_in);
|
||||||
void reader_deinit(FileReader *reader);
|
void reader_deinit(FileReader reader);
|
||||||
|
|
||||||
void reader_start(FileReader reader);
|
void reader_start(FileReader reader);
|
||||||
void reader_sync(FileReader reader);
|
void reader_sync(FileReader reader);
|
||||||
void reader_stop(FileReader reader);
|
void reader_stop(FileReader reader);
|
||||||
|
|
||||||
|
size_t reader_size(FileReader reader);
|
||||||
MPP_RET reader_read(FileReader reader, FileBufSlot **buf);
|
MPP_RET reader_read(FileReader reader, FileBufSlot **buf);
|
||||||
MPP_RET reader_index_read(FileReader reader, RK_S32 index, FileBufSlot **buf);
|
MPP_RET reader_index_read(FileReader reader, RK_S32 index, FileBufSlot **buf);
|
||||||
void reader_rewind(FileReader reader);
|
void reader_rewind(FileReader reader);
|
||||||
|
@@ -1272,6 +1272,7 @@ MPP_RET fps_calc_set_cb(FpsCalc ctx, FpsCalcCb cb)
|
|||||||
{
|
{
|
||||||
FpsCalcImpl *impl = (FpsCalcImpl *)ctx;
|
FpsCalcImpl *impl = (FpsCalcImpl *)ctx;
|
||||||
|
|
||||||
|
if (impl)
|
||||||
impl->callback = cb;
|
impl->callback = cb;
|
||||||
|
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -1285,6 +1286,9 @@ MPP_RET fps_calc_inc(FpsCalc ctx)
|
|||||||
RK_S64 last_time = 0;
|
RK_S64 last_time = 0;
|
||||||
RK_S64 last_count = 0;
|
RK_S64 last_count = 0;
|
||||||
|
|
||||||
|
if (NULL == impl)
|
||||||
|
return MPP_OK;
|
||||||
|
|
||||||
mpp_spinlock_lock(&impl->lock);
|
mpp_spinlock_lock(&impl->lock);
|
||||||
{
|
{
|
||||||
RK_S64 now = mpp_time();
|
RK_S64 now = mpp_time();
|
||||||
|
Reference in New Issue
Block a user