main.c,实例demo。
- #include "stdio.h"
- #include "vpu_global.h"
- #include "utils/Log.h"
- #include "vpu_api.h"
- #undef LOG_TAG
- #define LOG_TAG "vpu_api_demo"
- static RK_U32 VPU_API_DEMO_DEBUG_DISABLE = 0;
- #define VPU_API_DEMO_DEBUG 1
- #ifdef VPU_API_DEMO_DEBUG
- #ifdef AVS40
- #define VPU_DEMO_LOG(...) do { if (VPU_API_DEMO_DEBUG_DISABLE==0) LOGI(__VA_ARGS__); } while (0)
- #else
- #define VPU_DEMO_LOG(...) do { if (VPU_API_DEMO_DEBUG_DISABLE==0) ALOGI(__VA_ARGS__); } while (0)
- #endif
- #else
- #define VPU_DEMO_LOG
- #endif
- #define BSWAP32(x) \
- ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
- #define DEMO_ERR_RET(err) do { ret = err; goto DEMO_OUT; } while (0)
- #define DECODE_ERR_RET(err) do { ret = err; goto DECODE_OUT; } while (0)
- #define ENCODE_ERR_RET(err) do { ret = err; goto ENCODE_OUT; } while (0)
- typedef enum VPU_API_DEMO_RET {
- VPU_DEMO_OK = 0,
- VPU_DEMO_PARSE_HELP_OK = 1,
- VPU_DEMO_ERROR_BASE = -100,
- ERROR_INVALID_PARAM = VPU_DEMO_ERROR_BASE - 1,
- ERROR_INVALID_STREAM = VPU_DEMO_ERROR_BASE - 2,
- ERROR_IO = VPU_DEMO_ERROR_BASE - 3,
- ERROR_MEMORY = VPU_DEMO_ERROR_BASE - 4,
- ERROR_INIT_VPU = VPU_DEMO_ERROR_BASE - 5,
- ERROR_VPU_DECODE = VPU_DEMO_ERROR_BASE - 90,
- } VPU_API_DEMO_RET;
- typedef struct VpuApiCmd {
- RK_U8* name;
- RK_U8* argname;
- RK_U8* help;
- }VpuApiCmd_t;
- typedef struct VpuApiDemoCmdContext {
- RK_U32 width;
- RK_U32 height;
- CODEC_TYPE codec_type;
- OMX_ON2_VIDEO_CODINGTYPE coding;
- RK_U8 input_file[200];
- RK_U8 output_file[200];
- RK_U8 have_input;
- RK_U8 have_output;
- RK_U8 disable_debug;
- RK_U32 record_frames;
- RK_S64 record_start_ms;
- }VpuApiDemoCmdContext_t;
- typedef struct VpuApiEncInput {
- EncInputStream_t stream;
- RK_U32 capability;
- }VpuApiEncInput;
- static VpuApiCmd_t vpuApiCmd[] = {
- { "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"},
- { "t", "codec_type", "the codec type, dec: deoder, enc: encoder, default: decoder"},
- { "coding", "coding_type", "encoding type of the 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()
- {
- VPU_DEMO_LOG("usage: vpu_apiDemo [options] input_file, \n\n");
- VPU_DEMO_LOG("Getting help:\n");
- VPU_DEMO_LOG("-help --print options of vpu api demo\n");
- }
- static RK_S32 show_help()
- {
- VPU_DEMO_LOG("usage: vpu_apiDemo [options] input_file, \n\n");
- RK_S32 i =0;
- RK_U32 n = sizeof(vpuApiCmd)/sizeof(VpuApiCmd_t);
- for (i =0; i <n; i++) {
- VPU_DEMO_LOG("-%s %s\t\t%s\n",
- vpuApiCmd[i].name, vpuApiCmd[i].argname, vpuApiCmd[i].help);
- }
- return 0;
- }
- static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCxt)
- {
- RK_S8 *opt;
- RK_U32 optindex, handleoptions = 1, ret =0;
- if ((argc <2) || (cmdCxt == NULL)) {
- VPU_DEMO_LOG("vpu api demo, input parameter invalid\n");
- show_usage();
- return ERROR_INVALID_PARAM;
- }
- /* parse options */
- optindex = 1;
- while (optindex < argc) {
- opt = argv[optindex++];
- if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
- if (opt[1] == '-') {
- if (opt[2] != '\0') {
- opt++;
- } else {
- handleoptions = 0;
- continue;
- }
- }
- opt++;
- switch (*opt) {
- case 'i':
- if (argv[optindex]) {
- memcpy(cmdCxt->input_file, argv[optindex], strlen(argv[optindex]));
- cmdCxt->input_file[strlen(argv[optindex])] = '\0';
- cmdCxt->have_input = 1;
- } else {
- VPU_DEMO_LOG("input file is invalid\n");