diff --git a/test/mpi_dec_test.c b/test/mpi_dec_test.c index 22beed0a..bace4ceb 100644 --- a/test/mpi_dec_test.c +++ b/test/mpi_dec_test.c @@ -499,7 +499,7 @@ void *thread_decode(void *arg) 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); + mpp_err("Failed to set output format 0x%x\n", cmd->format); return NULL; } } diff --git a/utils/mpi_dec_utils.c b/utils/mpi_dec_utils.c index 9b6fe21c..ce8da77b 100644 --- a/utils/mpi_dec_utils.c +++ b/utils/mpi_dec_utils.c @@ -514,15 +514,21 @@ RK_S32 mpi_dec_opt_f(void *ctx, const char *next) MpiDecTestCmd *cmd = (MpiDecTestCmd *)ctx; if (next) { - cmd->format = (MppFrameFormat)atoi(next); + long number = 0; + MppFrameFormat format = MPP_FMT_BUTT; - if (MPP_FRAME_FMT_IS_YUV(cmd->format) || - MPP_FRAME_FMT_IS_RGB(cmd->format)) - return 1; + if (MPP_OK == str_to_frm_fmt(next, &number)) { + format = (MppFrameFormat)number; + + if (MPP_FRAME_FMT_IS_YUV(format) || MPP_FRAME_FMT_IS_RGB(format)) { + cmd->format = format; + return 1; + } + } } mpp_err("invalid output format\n"); - cmd->format = MPP_FMT_BUTT; + cmd->format = MPP_FMT_YUV420SP; return 0; } diff --git a/utils/mpi_enc_utils.c b/utils/mpi_enc_utils.c index 61ccdfe3..4ede6454 100644 --- a/utils/mpi_enc_utils.c +++ b/utils/mpi_enc_utils.c @@ -195,32 +195,23 @@ RK_S32 mpi_enc_opt_vstride(void *ctx, const char *next) RK_S32 mpi_enc_opt_f(void *ctx, const char *next) { MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx; - MppFrameFormat format = MPP_FMT_BUTT; if (next) { - if (strstr(next, "x") || strstr(next, "X")) { - /* hex value with 0x prefix, use sscanf */ - sscanf(next, "0x%x", &format); - } else if (strstr(next, "a") || strstr(next, "A") || - strstr(next, "b") || strstr(next, "B") || - strstr(next, "c") || strstr(next, "C") || - strstr(next, "d") || strstr(next, "D") || - strstr(next, "e") || strstr(next, "E") || - strstr(next, "f") || strstr(next, "F")) { - /* hex value without 0x prefix, use sscanf */ - sscanf(next, "%x", &format); - } else { - /* decimal value, use atoi */ - format = (MppFrameFormat)atoi(next); - } - if (MPP_FRAME_FMT_IS_BE(format) && - (MPP_FRAME_FMT_IS_YUV(format) || MPP_FRAME_FMT_IS_RGB(format))) { - cmd->format = format; - return 1; + long number = 0; + MppFrameFormat format = MPP_FMT_BUTT; + + if (MPP_OK == str_to_frm_fmt(next, &number)) { + format = (MppFrameFormat)number; + + if (MPP_FRAME_FMT_IS_BE(format) && + (MPP_FRAME_FMT_IS_YUV(format) || MPP_FRAME_FMT_IS_RGB(format))) { + cmd->format = format; + return 1; + } } } - mpp_err("invalid input format %x\n", format); + mpp_err("invalid input format\n"); cmd->format = MPP_FMT_YUV420SP; return 0; } diff --git a/utils/utils.c b/utils/utils.c index 016d7715..e00cc4fd 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -17,6 +17,7 @@ #define MODULE_TAG "utils" #include +#include #include #include @@ -233,6 +234,16 @@ void dump_mpp_frame_to_file(MppFrame frame, FILE *fp) mpp_free(tmp); } break; + case MPP_FMT_RGB888: { + RK_U32 i; + RK_U8 *base_y = base; + RK_U8 *tmp = mpp_malloc(RK_U8, width * height * 3); + + for (i = 0; i < height; i++, base_y += h_stride) + fwrite(base_y, 1, width * 3, fp); + + mpp_free(tmp); + } break; default : { mpp_err("not supported format %d\n", fmt); } break; @@ -1511,3 +1522,54 @@ MPP_RET fps_calc_inc(FpsCalc ctx) return MPP_OK; } + +/* + * @brief convert a string that discribes decimal, octal and hexadecimal + * number to a long integer. + * @param[in] nptr - a string to convert to long integer + * @param[out] number - long integer converted from a string + */ +MPP_RET str_to_frm_fmt(const char *nptr, long *number) +{ + MPP_RET ret = MPP_NOK; + + if (NULL == nptr || NULL == number) { + mpp_err_f("invalid input nptr %p number %p is_valid %p\n", nptr, number); + ret = MPP_ERR_NULL_PTR; + goto RET; + } + + if (nptr) { + char *endptr = NULL; /* pointer to additional chars */ + long tmp = 0; + + /* reset errno to 0 before call */ + errno = 0; + + tmp = strtol(nptr, &endptr, 0); + + if (nptr == endptr) + mpp_err("format: 0x%lx invalid (no digits found, 0 returned)", tmp); + else if (errno == ERANGE && tmp == LONG_MIN) + mpp_err("format: 0x%lx invalid (underflow occurred)", tmp); + else if (errno == ERANGE && tmp == LONG_MAX) + mpp_err("format: 0x%lx invalid (overflow occurred)", tmp); + else if (errno == EINVAL) /* not in all c99 implementations - gcc OK */ + mpp_err("format: 0x%lx invalid (base contains unsupported value)", tmp); + else if (errno != 0 && tmp == 0) + mpp_err("format: 0x%lx invalid (unspecified error occurred)", tmp); + else if (errno == 0 && nptr && *endptr != 0) + mpp_err("format: 0x%lx invalid (additional characters remain)", tmp); + else if (errno == 0 && nptr && !*endptr) { + if (tmp < UINT_MAX && tmp >= 0) { + *number = tmp; + ret = MPP_OK; + } else { + mpp_err("format: 0x%lx invalid (not format value)", tmp); + } + } + } + +RET: + return ret; +} diff --git a/utils/utils.h b/utils/utils.h index 4996293d..5a091ea3 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -92,6 +92,8 @@ MPP_RET fps_calc_deinit(FpsCalc ctx); MPP_RET fps_calc_set_cb(FpsCalc ctx, FpsCalcCb cb); MPP_RET fps_calc_inc(FpsCalc ctx); +MPP_RET str_to_frm_fmt(const char *nptr, long *number); + #ifdef __cplusplus } #endif