[test]: Add read packet config function

When mpp output packet binary file with size config file test case
should be enable to parser the corresponding config file.
This patch implement the config file option with "-c" prefix.

Command line sample:
mpi_dec_test -t 7 -i /sdcard/in.bin -i /sdcard/ops.bin
Then the test case will read in.bin file with size division specified
in ops.bin.

Change-Id: I8b18a6475d77f0303f12614a063888dcd9505f16
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2018-10-12 09:11:45 +08:00
parent a0f76729d5
commit 4553fac11e
3 changed files with 90 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ typedef struct {
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;
@@ -62,6 +63,7 @@ typedef struct {
typedef struct { typedef struct {
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;
@@ -70,16 +72,21 @@ typedef struct {
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;
RK_S32 frame_num; RK_S32 frame_num;
size_t pkt_size;
// report information
size_t max_usage; size_t max_usage;
} MpiDecTestCmd; } MpiDecTestCmd;
static OptionInfo mpi_dec_cmd[] = { static OptionInfo mpi_dec_cmd[] = {
{"i", "input_file", "input bitstream file"}, {"i", "input_file", "input bitstream file"},
{"o", "output_file", "output bitstream file, "}, {"o", "output_file", "output bitstream file, "},
{"c", "ops_file", "input operation config file"},
{"w", "width", "the width of input bitstream"}, {"w", "width", "the width of input bitstream"},
{"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"},
@@ -101,14 +108,52 @@ static int decode_simple(MpiDecLoopData *data)
MppPacket packet = data->packet; MppPacket packet = data->packet;
MppFrame frame = NULL; MppFrame frame = NULL;
size_t read_size = 0; size_t read_size = 0;
size_t packet_size = data->packet_size;
do { do {
read_size = fread(buf, 1, data->packet_size, data->fp_input); if (data->fp_config) {
char line[MAX_FILE_NAME_LENGTH];
char *ptr = NULL;
if (read_size != data->packet_size || feof(data->fp_input)) { 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("get reset cmd\n");
packet_size = 0;
break;
}
} else {
mpp_log("get end of cfg file\n");
packet_size = 0;
break;
}
} while (1);
}
// when packet size is valid read the input binary file
if (packet_size)
read_size = fread(buf, 1, packet_size, data->fp_input);
if (!packet_size || read_size != packet_size || feof(data->fp_input)) {
mpp_log("get error and check frame_num\n");
if (data->frame_num < 0) { if (data->frame_num < 0) {
clearerr(data->fp_input); clearerr(data->fp_input);
rewind(data->fp_input); rewind(data->fp_input);
if (data->fp_config) {
clearerr(data->fp_config);
rewind(data->fp_config);
}
data->eos = pkt_eos = 0; data->eos = pkt_eos = 0;
mpp_log("loop again\n"); mpp_log("loop again\n");
} else { } else {
@@ -451,7 +496,7 @@ int mpi_dec_test_decode(MpiDecTestCmd *cmd)
// resources // resources
char *buf = NULL; char *buf = NULL;
size_t packet_size = MPI_DEC_STREAM_SIZE; size_t packet_size = cmd->pkt_size;
MppBuffer pkt_buf = NULL; MppBuffer pkt_buf = NULL;
MppBuffer frm_buf = NULL; MppBuffer frm_buf = NULL;
@@ -481,6 +526,14 @@ int mpi_dec_test_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) {
buf = mpp_malloc(char, packet_size); buf = mpp_malloc(char, packet_size);
if (NULL == buf) { if (NULL == buf) {
@@ -728,6 +781,19 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
break; break;
case 'c':
if (next) {
strncpy(cmd->file_config, next, MAX_FILE_NAME_LENGTH);
cmd->file_config[strlen(next)] = '\0';
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': case 'd':
if (next) { if (next) {
cmd->debug = atoi(next);; cmd->debug = atoi(next);;
@@ -817,6 +883,7 @@ static void mpi_dec_test_show_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 : %d\n", cmd->type);
@@ -832,6 +899,7 @@ int main(int argc, char **argv)
memset((void*)cmd, 0, sizeof(*cmd)); memset((void*)cmd, 0, sizeof(*cmd));
cmd->format = MPP_FMT_BUTT; cmd->format = MPP_FMT_BUTT;
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_parse_options(argc, argv, cmd);

View File

@@ -385,3 +385,12 @@ MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
} }
return ret; return ret;
} }
RK_S32 parse_config_line(const char *str, OpsLine *info)
{
RK_S32 cnt = sscanf(str, "%*[^,],%d,%[^,],%llu,%llu\n",
&info->index, info->cmd,
&info->value1, &info->value2);
return cnt;
}

View File

@@ -18,6 +18,7 @@
#define __UTILS_H__ #define __UTILS_H__
#include <stdio.h> #include <stdio.h>
#include "mpp_err.h" #include "mpp_err.h"
#include "mpp_frame.h" #include "mpp_frame.h"
@@ -66,6 +67,15 @@ MPP_RET fill_yuv_image(RK_U8 *buf, RK_U32 width, RK_U32 height,
RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt, RK_U32 hor_stride, RK_U32 ver_stride, MppFrameFormat fmt,
RK_U32 frame_count); RK_U32 frame_count);
typedef struct OpsLine_t {
RK_U32 index;
char cmd[8];
RK_U64 value1;
RK_U64 value2;
} OpsLine;
RK_S32 parse_config_line(const char *str, OpsLine *info);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif