瑞芯微Rk3288硬件编码,硬件解码

main.c,实例demo。

[cpp]  view plain   copy
  1. #include "stdio.h"  
  2. #include "vpu_global.h"  
  3. #include "utils/Log.h"  
  4.   
  5. #include "vpu_api.h"  
  6.   
  7. #undef LOG_TAG  
  8. #define LOG_TAG "vpu_api_demo"  
  9.   
  10. static RK_U32 VPU_API_DEMO_DEBUG_DISABLE = 0;  
  11.   
  12. #define VPU_API_DEMO_DEBUG 1  
  13.   
  14. #ifdef  VPU_API_DEMO_DEBUG  
  15. #ifdef AVS40  
  16. #define VPU_DEMO_LOG(...)   do { if (VPU_API_DEMO_DEBUG_DISABLE==0) LOGI(__VA_ARGS__); } while (0)  
  17. #else  
  18. #define VPU_DEMO_LOG(...)   do { if (VPU_API_DEMO_DEBUG_DISABLE==0) ALOGI(__VA_ARGS__); } while (0)  
  19. #endif  
  20. #else  
  21. #define VPU_DEMO_LOG  
  22. #endif  
  23.   
  24. #define BSWAP32(x) \  
  25.     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \  
  26.       (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))  
  27.   
  28.   
  29. #define DEMO_ERR_RET(err) do { ret = err; goto DEMO_OUT; } while (0)  
  30. #define DECODE_ERR_RET(err) do { ret = err; goto DECODE_OUT; } while (0)  
  31. #define ENCODE_ERR_RET(err) do { ret = err; goto ENCODE_OUT; } while (0)  
  32.   
  33.   
  34. typedef enum VPU_API_DEMO_RET {  
  35.     VPU_DEMO_OK = 0,  
  36.     VPU_DEMO_PARSE_HELP_OK  = 1,  
  37.   
  38.     VPU_DEMO_ERROR_BASE     = -100,  
  39.     ERROR_INVALID_PARAM     = VPU_DEMO_ERROR_BASE - 1,  
  40.     ERROR_INVALID_STREAM    = VPU_DEMO_ERROR_BASE - 2,  
  41.     ERROR_IO                = VPU_DEMO_ERROR_BASE - 3,  
  42.     ERROR_MEMORY            = VPU_DEMO_ERROR_BASE - 4,  
  43.     ERROR_INIT_VPU          = VPU_DEMO_ERROR_BASE - 5,  
  44.   
  45.     ERROR_VPU_DECODE        = VPU_DEMO_ERROR_BASE - 90,  
  46. } VPU_API_DEMO_RET;  
  47.   
  48. typedef struct VpuApiCmd {  
  49.     RK_U8* name;  
  50.     RK_U8* argname;  
  51.     RK_U8* help;  
  52. }VpuApiCmd_t;  
  53.   
  54. typedef struct VpuApiDemoCmdContext {  
  55.     RK_U32  width;  
  56.     RK_U32  height;  
  57.     CODEC_TYPE  codec_type;  
  58.     OMX_ON2_VIDEO_CODINGTYPE coding;  
  59.     RK_U8   input_file[200];  
  60.     RK_U8   output_file[200];  
  61.     RK_U8   have_input;  
  62.     RK_U8   have_output;  
  63.     RK_U8   disable_debug;  
  64.     RK_U32  record_frames;  
  65.     RK_S64  record_start_ms;  
  66. }VpuApiDemoCmdContext_t;  
  67.   
  68. typedef struct VpuApiEncInput {  
  69.     EncInputStream_t stream;  
  70.     RK_U32 capability;  
  71. }VpuApiEncInput;  
  72.   
  73. static VpuApiCmd_t vpuApiCmd[] = {  
  74.     { "i",               "input_file",           "input bitstream file"},  
  75.     { "o",               "output_file",          "output bitstream file, "},  
  76.     { "w",               "width",                "the width of input bitstream"},  
  77.     { "h",               "height",               "the height of input bitstream"},  
  78.     { "t",               "codec_type",           "the codec type, dec: deoder, enc: encoder, default: decoder"},  
  79.     { "coding",          "coding_type",          "encoding type of the bitstream"},  
  80.     { "vframes",         "number",               "set the number of video frames to record"},  
  81.     { "ss",              "time_off",             "set the start time offset, use Ms as the unit."},  
  82.     { "d",               "disable",              "disable the debug output info."},  
  83. };  
  84.   
  85. static void show_usage()  
  86. {  
  87.     VPU_DEMO_LOG("usage: vpu_apiDemo [options] input_file, \n\n");  
  88.   
  89.     VPU_DEMO_LOG("Getting help:\n");  
  90.     VPU_DEMO_LOG("-help  --print options of vpu api demo\n");  
  91. }  
  92.   
  93. static RK_S32 show_help()  
  94. {  
  95.     VPU_DEMO_LOG("usage: vpu_apiDemo [options] input_file, \n\n");  
  96.   
  97.     RK_S32 i =0;  
  98.     RK_U32 n = sizeof(vpuApiCmd)/sizeof(VpuApiCmd_t);  
  99.     for (i =0; i <n; i++) {  
  100.         VPU_DEMO_LOG("-%s  %s\t\t%s\n",  
  101.             vpuApiCmd[i].name, vpuApiCmd[i].argname, vpuApiCmd[i].help);  
  102.     }  
  103.   
  104.     return 0;  
  105. }  
  106.   
  107. static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t* cmdCxt)  
  108. {  
  109.     RK_S8 *opt;  
  110.     RK_U32 optindex, handleoptions = 1, ret =0;  
  111.   
  112.     if ((argc <2) || (cmdCxt == NULL)) {  
  113.         VPU_DEMO_LOG("vpu api demo, input parameter invalid\n");  
  114.         show_usage();  
  115.         return ERROR_INVALID_PARAM;  
  116.     }  
  117.   
  118.     /* parse options */  
  119.     optindex = 1;  
  120.     while (optindex < argc) {  
  121.         opt = argv[optindex++];  
  122.   
  123.         if (handleoptions && opt[0] == '-' && opt[1] != '\0') {  
  124.             if (opt[1] == '-') {  
  125.                 if (opt[2] != '\0') {  
  126.                     opt++;  
  127.                 } else {  
  128.                      handleoptions = 0;  
  129.                     continue;  
  130.                 }  
  131.             }  
  132.   
  133.             opt++;  
  134.   
  135.             switch (*opt) {  
  136.                 case 'i':  
  137.                     if (argv[optindex]) {  
  138.                         memcpy(cmdCxt->input_file, argv[optindex], strlen(argv[optindex]));  
  139.                         cmdCxt->input_file[strlen(argv[optindex])] = '\0';  
  140.                         cmdCxt->have_input = 1;  
  141.                     } else {  
  142.                         VPU_DEMO_LOG("input file is invalid\n");  
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值