From bed52a856ecbc0232d44224bfcc7447954719b19 Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Mon, 28 Sep 2015 22:31:52 +0000 Subject: [PATCH] [utils]: add show_options to utils git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@316 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/codec/dec/h265/test/CMakeLists.txt | 4 +-- mpp/codec/dec/h265/test/h265d_parser_test.c | 32 +++++++-------------- test/CMakeLists.txt | 2 +- test/vpu_api_test.c | 19 ++---------- utils/utils.c | 9 ++++++ utils/utils.h | 12 ++++++++ 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/mpp/codec/dec/h265/test/CMakeLists.txt b/mpp/codec/dec/h265/test/CMakeLists.txt index af83b033..dfdce861 100644 --- a/mpp/codec/dec/h265/test/CMakeLists.txt +++ b/mpp/codec/dec/h265/test/CMakeLists.txt @@ -14,9 +14,9 @@ if(H265D_TEST) set_target_properties(openhevcwrapper PROPERTIES IMPORTED_LOCATION "${OPENHEVCSO}/libLibOpenHevcWrapper.so") - target_link_libraries(h265d_parser_test openhevcwrapper m h265d_parse osal h265d_hal mpp_codec mpp) + target_link_libraries(h265d_parser_test openhevcwrapper m h265d_parse osal h265d_hal mpp_codec mpp utils) else() - target_link_libraries(h265d_parser_test mpp) + target_link_libraries(h265d_parser_test mpp utils) endif() endif() diff --git a/mpp/codec/dec/h265/test/h265d_parser_test.c b/mpp/codec/dec/h265/test/h265d_parser_test.c index 8f9d2dbe..cc554fbd 100644 --- a/mpp/codec/dec/h265/test/h265d_parser_test.c +++ b/mpp/codec/dec/h265/test/h265d_parser_test.c @@ -28,6 +28,7 @@ #include "h265d_api.h" #include "hal_h265d_api.h" +#include "utils.h" #include "mpp_log.h" #include #include @@ -57,11 +58,6 @@ typedef enum VPU_API_DEMO_RET { ERROR_VPU_DECODE = PARSER_DEMO_ERROR_BASE - 90, } PARSER_API_DEMO_RET; -typedef struct ParserCmd { - RK_U8* name; - RK_U8* argname; - RK_U8* help; -} ParserCmd_t; typedef struct parserDemoCmdContext { RK_U32 width; @@ -75,15 +71,14 @@ typedef struct parserDemoCmdContext { RK_S64 record_start_ms; } ParserDemoCmdContext_t; - -static ParserCmd_t parserCmd[] = { - {(RK_U8*)"i", (RK_U8*)"input_file", (RK_U8*)"input bitstream file"}, - {(RK_U8*)"o", (RK_U8*)"output_file", (RK_U8*)"output bitstream file, "}, - {(RK_U8*)"w", (RK_U8*)"width", (RK_U8*)"the width of input bitstream"}, - {(RK_U8*)"h", (RK_U8*)"height", (RK_U8*)"the height of input bitstream"}, - {(RK_U8*)"vframes", (RK_U8*)"number", (RK_U8*)"set the number of video frames to record"}, - {(RK_U8*)"ss", (RK_U8*)"time_off", (RK_U8*)"set the start time offset, use Ms as the unit."}, - {(RK_U8*)"d", (RK_U8*)"disable", (RK_U8*)"disable the debug output info."}, +static OptionInfo parserCmd[] = { + {"i", "input_file", "input bitstream file"}, + {"o", "output_file", "output bitstream file, "}, + {"w", "width", "the width of input bitstream"}, + {"h", "height", "the height of input bitstream"}, + {"vframes", "number", "set the number of video frames to record"}, + {"ss", "time_off", "set the start time offset, use Ms as the unit."}, + {"d", "disable", "disable the debug output info."}, }; static void show_usage() @@ -96,15 +91,8 @@ static void show_usage() static RK_S32 show_help() { - RK_U32 i = 0; - RK_U32 n = sizeof(parserCmd) / sizeof(ParserCmd_t); - mpp_log("usage: parserDemo [options] input_file, \n\n"); - for (i = 0; i < n; i++) { - mpp_log("-%s %s\t\t%s\n", - parserCmd[i].name, parserCmd[i].argname, parserCmd[i].help); - } - + show_options(parserCmd); return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5bd1d03a..f02ebc14 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,7 +13,7 @@ macro(add_mpp_test module) option(${test_tag} "Build mpp ${module} unit test" ON) if(${test_tag}) add_executable(${test_name} ${test_name}.c) - target_link_libraries(${test_name} mpp mpp_legacy) + target_link_libraries(${test_name} mpp mpp_legacy utils) set_target_properties(${test_name} PROPERTIES FOLDER "test") install(TARGETS ${test_name} RUNTIME DESTINATION ${TEST_INSTALL_DIR}) add_test(NAME ${test_name} COMMAND ${test_name}) diff --git a/test/vpu_api_test.c b/test/vpu_api_test.c index 2dbfcd58..329fac59 100644 --- a/test/vpu_api_test.c +++ b/test/vpu_api_test.c @@ -24,6 +24,7 @@ #include "mpp_time.h" #include "vpu_api.h" +#include "utils.h" static RK_U32 VPU_API_DEMO_DEBUG_DISABLE = 0; @@ -50,12 +51,6 @@ typedef enum VPU_API_DEMO_RET { ERROR_VPU_DECODE = VPU_DEMO_ERROR_BASE - 90, } VPU_API_DEMO_RET; -typedef struct VpuApiCmd { - char* name; - char* argname; - char* help; -} VpuApiCmd_t; - typedef struct VpuApiDemoCmdContext { RK_U32 width; RK_U32 height; @@ -75,7 +70,7 @@ typedef struct VpuApiEncInput { RK_U32 capability; } VpuApiEncInput; -static VpuApiCmd_t vpuApiCmd[] = { +static OptionInfo vpuApiCmd[] = { {"i", "input_file", "input bitstream file"}, {"o", "output_file", "output bitstream file, "}, {"w", "width", "the width of input bitstream"}, @@ -97,16 +92,8 @@ static void show_usage() static RK_S32 show_help() { - RK_S32 i = 0; - RK_S32 n = sizeof(vpuApiCmd) / sizeof(VpuApiCmd_t); - mpp_log("usage: vpu_apiDemo [options] input_file, \n\n"); - - for (i = 0; i < n; i++) { - mpp_log("-%s %s\t\t%s\n", - vpuApiCmd[i].name, vpuApiCmd[i].argname, vpuApiCmd[i].help); - } - + show_options(vpuApiCmd); return 0; } diff --git a/utils/utils.c b/utils/utils.c index 7c35ef28..7b3a4427 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -20,5 +20,14 @@ #include #include "mpp_log.h" +#include "utils.h" +void _show_options(int count, OptionInfo *options) +{ + int i; + for (i = 0; i < count; i++) { + mpp_log("-%s %s\t\t%s\n", + options[i].name, options[i].argname, options[i].help); + } +} diff --git a/utils/utils.h b/utils/utils.h index 6429a417..863b40ed 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -17,10 +17,22 @@ #ifndef __UTILS_H__ #define __UTILS_H__ +typedef struct OptionInfo_t { + const char* name; + const char* argname; + const char* help; +} OptionInfo; + +#define show_options(opt) \ + do { \ + _show_options(sizeof(opt)/sizeof(OptionInfo), opt); \ + } while (0) + #ifdef __cplusplus extern "C" { #endif +void _show_options(int count, OptionInfo *options); #ifdef __cplusplus }