1. 程式人生 > >[36]_海思SDK編碼部分之sample_venc.c詳解

[36]_海思SDK編碼部分之sample_venc.c詳解

不多說了,直接上原始碼+分析......

/******************************************************************************
  A simple program of Hisilicon HI3531 video encode implementation.
  Copyright (C), 2010-2011, Hisilicon Tech. Co., Ltd.
 ******************************************************************************
    Modification:  2011-2 Created
******************************************************************************/
#ifdef __cplusplus 	//__cplusplus是C++中定義的一個巨集,如果這個巨集被定義,說明這個程式是C++程式
#if __cplusplus //那麼如果C++程式要呼叫C實現的函式或庫等,則需要使用extern "C"{ extern "C"{ //這是實現C++呼叫C庫或函式的一種手段,原因是因為C++和C語言的編譯器不同導致 #endif #endif /* End of #ifdef __cplusplus */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <pthread.h> #include <signal.h> #include "sample_comm.h" //VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_PAL; //PAL(德國制@25幀),中國主要也是使用這種。 VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_NTSC; //NTSC(美國製@30幀),(來自網路)更換N制的鏡頭後,VI VO的屬性都要設定成N制的 //VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_AUTO, //VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_BUTT; #ifdef hi3518ev201 HI_U32 g_u32BlkCnt = 4; #endif #ifdef hi3518ev200 HI_U32 g_u32BlkCnt = 4; //啥意思?塊大小? #endif #ifdef hi3516cv200 HI_U32 g_u32BlkCnt = 10; #endif //2018.06.02 /****************************************************************************** * function : show usage                  介紹使用方法 ******************************************************************************/ void SAMPLE_VENC_Usage(char *sPrgNm) //接收的字串為argv[0] { printf("Usage : %s <index>\n", sPrgNm); //string program number printf("index:\n"); printf("\t 0) 1*1080p H264 + 1*VGA H264.\n"); printf("\t 1) 1*1080p MJPEG encode + 1*1080p jpeg.\n"); printf("\t 2) low delay encode(only vi-vpss online).\n"); printf("\t 3) roi background framerate.\n"); printf("\t 4) Thumbnail of 1*1080p jpeg.\n"); #ifndef hi3518ev201 printf("\t 5) svc-t H264\n"); #endif return; } //2018.06.02 /****************************************************************************** * function : to process abnormal case 處理異常情況,譬如中斷處理、結束程序 ******************************************************************************/ void SAMPLE_VENC_HandleSig(HI_S32 signo) { if (SIGINT == signo || SIGTERM == signo) { SAMPLE_COMM_ISP_Stop(); SAMPLE_COMM_SYS_Exit(); printf("\033[0;31mprogram termination abnormally!\033[0;39m\n"); } exit(-1); } //2018.06.02 /****************************************************************************** * function : to process abnormal case - the case of stream venc 編碼異常處理 ******************************************************************************/ void SAMPLE_VENC_StreamHandleSig(HI_S32 signo) { if (SIGINT == signo || SIGTSTP == signo) { SAMPLE_COMM_ISP_Stop(); SAMPLE_COMM_SYS_Exit(); printf("\033[0;31mprogram exit abnormally!\033[0;39m\n"); } exit(0); } //2018.06.02 /****************************************************************************** * function :
[email protected]
@[email protected]@30fps 支援同時編碼2路碼流 ******************************************************************************/ HI_S32 SAMPLE_VENC_1080P_CLASSIC(HI_VOID) /* 最重要的函式 */ { PAYLOAD_TYPE_E enPayLoad[3]= {PT_H264, PT_H264,PT_H264}; /*列舉型別、陣列、3路碼流的編碼型別 */ PIC_SIZE_E enSize[3] = {PIC_HD1080, PIC_VGA,PIC_QVGA}; /* 3路碼流的解析度 */ HI_U32 u32Profile = 0; VB_CONF_S stVbConf; /* 視訊快取池 */ SAMPLE_VI_CONFIG_S stViConfig = {0}; VPSS_GRP VpssGrp; /* 這部分是和VPSS相關的 */ VPSS_CHN VpssChn; VPSS_GRP_ATTR_S stVpssGrpAttr; VPSS_CHN_ATTR_S stVpssChnAttr; VPSS_CHN_MODE_S stVpssChnMode; VENC_CHN VencChn; SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR; /* 恆定位元率方式進行編碼 */ /* H.264編碼方式有好種,這是其中一種 */ HI_S32 s32ChnNum=0; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; char c; /****************************************** step 1: init sys variable ## 1.這裡的sys指“mpp”,指的是初始化mpp的變數 ## ******************************************/ memset(&stVbConf,0,sizeof(VB_CONF_S)); /* 重新整理快取池*/ SAMPLE_COMM_VI_GetSizeBySensor(&enSize[0]); /* 獲取SENSOR,在這個函式裡面新增 */ if (PIC_HD1080 == enSize[0]) { enSize[1] = PIC_VGA; s32ChnNum = 2; } else if (PIC_HD720 == enSize[0]) /* 走的是這條路 */ { enSize[1] = PIC_VGA;         /* 通過對VI原始影象(720P)進行裁剪、縮放成這兩路(VGA、QVGA) */ enSize[2] = PIC_QVGA; s32ChnNum = 3; /* 這裡的3表示3路碼流,分別是720P、VGA、QVGA */ } else { printf("not support this sensor\n"); return HI_FAILURE; } #ifdef hi3518ev201 s32ChnNum = 1; #endif printf("s32ChnNum = %d\n",s32ChnNum); stVbConf.u32MaxPoolCnt = 128; /* 快取池的數量為128 */ /*video buffer*/ if(s32ChnNum >= 1) /* 走這條通道 */ { /* “enSize”表示傳進去是多少畫素的,“SAMPLE_PIXEL_FORMAT”表示畫素格式(RGB888或RGB565) “SAMPLE_SYS_ALIGN_WIDTH”表示對齊*/ u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\ enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt; } if(s32ChnNum >= 2) { u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\ enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[1].u32BlkSize = u32BlkSize; stVbConf.astCommPool[1].u32BlkCnt =g_u32BlkCnt; } if(s32ChnNum >= 3) /* */ { u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\ enSize[2], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[2].u32BlkSize = u32BlkSize; stVbConf.astCommPool[2].u32BlkCnt = g_u32BlkCnt; } /****************************************** step 2: mpp system init. ## 2.初始化MMP系統 ## ******************************************/ s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("system init failed with %d!\n", s32Ret); goto END_VENC_1080P_CLASSIC_0; /* 倒影式處理,MPP初始化失敗直接結束編碼 */ } /****************************************** step 3: start vi dev & chn to capture ## 3.啟動輸入和通道捕獲 ## ******************************************/ stViConfig.enViMode = SENSOR_TYPE; stViConfig.enRotate = ROTATE_NONE; /* 影象不旋轉 */ stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO; /* 影象制式標準 */ stViConfig.enViChnSet = VI_CHN_SET_NORMAL; /* */ stViConfig.enWDRMode = WDR_MODE_NONE; /* 不支援寬動態 */ s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("start vi failed!\n"); goto END_VENC_1080P_CLASSIC_1; } /****************************************** step 4: start vpss and vi bind vpss ##4:啟動視訊處理和繫結視訊輸入(通道)## ******************************************/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_1080P_CLASSIC_1; } if(s32ChnNum >= 1) /* 走這個通道 */ { VpssGrp = 0; stVpssGrpAttr.u32MaxW = stSize.u32Width; stVpssGrpAttr.u32MaxH = stSize.u32Height; stVpssGrpAttr.bIeEn = HI_FALSE; stVpssGrpAttr.bNrEn = HI_TRUE; stVpssGrpAttr.bHistEn = HI_FALSE; stVpssGrpAttr.bDciEn = HI_FALSE; stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE; stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420; s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Vpss failed!\n"); goto END_VENC_1080P_CLASSIC_2; } s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Vi bind Vpss failed!\n"); goto END_VENC_1080P_CLASSIC_3; } VpssChn = 0; stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER; stVpssChnMode.bDouble = HI_FALSE; stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stVpssChnMode.u32Width = stSize.u32Width; stVpssChnMode.u32Height = stSize.u32Height; stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG; memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr)); stVpssChnAttr.s32SrcFrameRate = -1; stVpssChnAttr.s32DstFrameRate = -1; s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Enable vpss chn failed!\n"); goto END_VENC_1080P_CLASSIC_4; } } if(s32ChnNum >= 2) { s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[1], &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_1080P_CLASSIC_4; } VpssChn = 1; stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER; stVpssChnMode.bDouble = HI_FALSE; stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stVpssChnMode.u32Width = stSize.u32Width; stVpssChnMode.u32Height = stSize.u32Height; stVpssChnMode.enCompressMode = COMPRESS_MODE_SEG; stVpssChnAttr.s32SrcFrameRate = -1; stVpssChnAttr.s32DstFrameRate = -1; s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Enable vpss chn failed!\n"); goto END_VENC_1080P_CLASSIC_4; } } if(s32ChnNum >= 3) { s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[2], &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_1080P_CLASSIC_4; } VpssChn = 2; stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER; stVpssChnMode.bDouble = HI_FALSE; stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stVpssChnMode.u32Width = stSize.u32Width; stVpssChnMode.u32Height = stSize.u32Height; stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE; stVpssChnAttr.s32SrcFrameRate = -1; stVpssChnAttr.s32DstFrameRate = -1; s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Enable vpss chn failed!\n"); goto END_VENC_1080P_CLASSIC_4; } } /****************************************** step 5: start stream venc # 可以在這裡疊加OSD資訊,並研究哪些碼流 # ******************************************/ /*** HD1080P **/ printf("\t c) cbr.\n"); printf("\t v) vbr.\n"); printf("\t f) fixQp\n"); printf("please input choose rc mode!\n"); c = (char)getchar(); switch(c) { case 'c': enRcMode = SAMPLE_RC_CBR; break; case 'v': enRcMode = SAMPLE_RC_VBR; break; case 'f': enRcMode = SAMPLE_RC_FIXQP; break; default: printf("rc mode! is invaild!\n"); goto END_VENC_1080P_CLASSIC_4; } /*** enSize[0] ***/ if(s32ChnNum >= 1) {     VpssGrp = 0; VpssChn = 0; /* 媒體處理通道0 */ VencChn = 0; /* 編碼通道0 */ /* 通道0、負載型別PT_H264、NTSC制式、PIC_HD1080()、恆定位元率編碼、0 */ s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[0],\ gs_enNorm, enSize[0], enRcMode,u32Profile); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } } /*** enSize[1] **/ if(s32ChnNum >= 2) {     VpssChn = 1; /* 媒體處理通道1 */ VencChn = 1; /* 編碼通道1 */     /* 通道1、負載型別PT_H264、NTSC制式、PIC_VGA(640 * 480)、恆定位元率編碼、0 */
s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[1], \ gs_enNorm, enSize[1], enRcMode,u32Profile); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } } /*** enSize[2] **/ if(s32ChnNum >= 3) { VpssChn = 2; /* 媒體處理通道2 */ VencChn = 2; /* 編碼通道2 */     /* 通道2、負載型別PT_H264、NTSC制式、PIC_QVGA(320 * 240)、恆定位元率編碼、0 */ s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[2], \ gs_enNorm, enSize[2], enRcMode,u32Profile); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } } /****************************************** step 6: stream venc process -- get stream, then save it to file.
 #在step 5中只是得到了一段裸流,並把這段碼流儲存為一個檔案#
******************************************/ s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_1080P_CLASSIC_5; } printf("please press twice ENTER to exit this sample\n"); getchar(); getchar(); /****************************************** step 7: exit process ******************************************/ SAMPLE_COMM_VENC_StopGetStream(); /* 停止去獲取碼流,不過前面產生碼流的6部分並沒有停止 */ END_VENC_1080P_CLASSIC_5: /* 倒影式處理產生碼流的前六個步驟 */ VpssGrp = 0;switch(s32ChnNum){case 3:VpssChn = 2; VencChn = 2; SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn); SAMPLE_COMM_VENC_Stop(VencChn);case 2:VpssChn = 1; VencChn = 1; SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn); SAMPLE_COMM_VENC_Stop(VencChn);case 1:VpssChn = 0; VencChn = 0; SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn); SAMPLE_COMM_VENC_Stop(VencChn);break;} SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);END_VENC_1080P_CLASSIC_4: //vpss stop VpssGrp = 0;switch(s32ChnNum){case 3:VpssChn = 2;SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);case 2:VpssChn = 1;SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);case 1:VpssChn = 0;SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);break;}END_VENC_1080P_CLASSIC_3: //vpss stop SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);END_VENC_1080P_CLASSIC_2: //vpss stop SAMPLE_COMM_VPSS_StopGroup(VpssGrp);END_VENC_1080P_CLASSIC_1: //vi stop SAMPLE_COMM_VI_StopVi(&stViConfig);END_VENC_1080P_CLASSIC_0: //system exit SAMPLE_COMM_SYS_Exit(); return s32Ret; }
/*---------end of------ [email protected]@[email protected]@[email protected]@30fps ------------------*/ /*----------------分界線:上面是一個高清編碼回合,是一種編碼情況,下面這些是另外一種情況---------------*/

/******************************************************************************
* function :  1*1080p MJPEG encode + 1*1080p jpeg
******************************************************************************/
HI_S32 SAMPLE_VENC_1080P_MJPEG_JPEG(HI_VOID)
{
    PAYLOAD_TYPE_E enPayLoad = PT_MJPEG;
    PIC_SIZE_E enSize = PIC_HD1080;

	HI_U32 u32Profile = 0;

    VB_CONF_S stVbConf;
    SAMPLE_VI_CONFIG_S stViConfig = {0};
    
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stVpssGrpAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr;
    VPSS_CHN_MODE_S stVpssChnMode;
    
    VENC_CHN VencChn;
    SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR;
    HI_S32 s32ChnNum = 1;
        
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    HI_S32 i = 0;
    char ch;

    /******************************************
     step  1: init sys variable 
    ******************************************/
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    stVbConf.u32MaxPoolCnt = 128;
    SAMPLE_COMM_VI_GetSizeBySensor(&enSize);

    /*video buffer*/
    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);

    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt;


    /******************************************
     step 2: mpp system init. 
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("system init failed with %d!\n", s32Ret);
        goto END_VENC_MJPEG_JPEG_0;
    }
 
    /******************************************
     step 3: start vi dev & chn to capture
    ******************************************/
    stViConfig.enViMode   = SENSOR_TYPE;
    stViConfig.enRotate   = ROTATE_NONE;
    stViConfig.enNorm     = VIDEO_ENCODING_MODE_AUTO;
    stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
    s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("start vi failed!\n");
        goto END_VENC_MJPEG_JPEG_1;
    }
    
    /******************************************
     step 4: start vpss and vi bind vpss
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_MJPEG_JPEG_1;
    }
	
    VpssGrp = 0;
    stVpssGrpAttr.u32MaxW = stSize.u32Width;
    stVpssGrpAttr.u32MaxH = stSize.u32Height;
    stVpssGrpAttr.bIeEn = HI_FALSE;
    stVpssGrpAttr.bNrEn = HI_TRUE;
    stVpssGrpAttr.bHistEn = HI_FALSE;
    stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stVpssGrpAttr.bDciEn = HI_FALSE;
    s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Vpss failed!\n");
        goto END_VENC_MJPEG_JPEG_2;
    }

    s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Vi bind Vpss failed!\n");
        goto END_VENC_MJPEG_JPEG_3;
    }

    
    VpssChn = 0;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
    
    memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_MJPEG_JPEG_4;
    }
    
    VpssChn = 1;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;

    memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_MJPEG_JPEG_4;
    }
    
    /******************************************
     step 5: start stream venc
    ******************************************/
    VpssGrp = 0;
    VpssChn = 0;
    VencChn = 0;
    s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad,\
                                   gs_enNorm, enSize, enRcMode,u32Profile);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }
    
    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    VpssGrp = 0;
    VpssChn = 1;
    VencChn = 1;
    s32Ret = SAMPLE_COMM_VENC_SnapStart(VencChn, &stSize, HI_FALSE);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start snap failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    
    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    /******************************************
     step 6: stream venc process -- get stream, then save it to file. 
    ******************************************/
    s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
    i = 0;
    while ((ch = (char)getchar()) != 'q')
    {
        s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn, HI_TRUE, HI_FALSE);
        if (HI_SUCCESS != s32Ret)
        {
            printf("%s: sanp process failed!\n", __FUNCTION__);
            break;
        }
        printf("snap %d success!\n", i);
        i++;
    }
 
    printf("please press ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     step 8: exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();
    
END_VENC_MJPEG_JPEG_5:
    VpssGrp = 0;
    VpssChn = 0;
    VencChn = 0;
    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
    SAMPLE_COMM_VENC_Stop(VencChn);

    VpssChn = 1;
    VencChn = 1;
    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
    SAMPLE_COMM_VENC_Stop(VencChn);
END_VENC_MJPEG_JPEG_4:    //vpss stop
    VpssGrp = 0;
    VpssChn = 0;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn); 
    VpssChn = 1;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_MJPEG_JPEG_3:    //vpss stop       
    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_MJPEG_JPEG_2:    //vpss stop   
    SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_MJPEG_JPEG_1:    //vi stop
    SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_MJPEG_JPEG_0:	//system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;
}

/******************************************************************************
* function :  low delay encode(only vi-vpss online).
******************************************************************************/
HI_S32 SAMPLE_VENC_LOW_DELAY(HI_VOID)
{
    PAYLOAD_TYPE_E enPayLoad[2]= {PT_H264, PT_H264};
    PIC_SIZE_E enSize[2] = {PIC_HD1080, PIC_VGA};
	HI_U32 u32Profile = 0;

    VB_CONF_S stVbConf;
    SAMPLE_VI_CONFIG_S stViConfig = {0};
    HI_U32 u32Priority;
    
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stVpssGrpAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr;
    VPSS_CHN_MODE_S stVpssChnMode;
    VPSS_LOW_DELAY_INFO_S stLowDelayInfo;
    
    VENC_CHN VencChn;
    SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR;
    HI_S32 s32ChnNum = 2;
    
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    char c;

    /******************************************
     step  1: init sys variable 
    ******************************************/
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    SAMPLE_COMM_VI_GetSizeBySensor(&enSize[0]);
    if (PIC_HD1080 == enSize[0])
    {
        enSize[1] = PIC_VGA;
		s32ChnNum = 2;
    }
    else if (PIC_HD720 == enSize[0])
    {
        enSize[1] = PIC_VGA;			
		s32ChnNum = 2;
    }
    else
    {
        printf("not support this sensor\n");
        return HI_FAILURE;
    }
    #ifdef hi3518ev201

		s32ChnNum = 1;

	#endif
    stVbConf.u32MaxPoolCnt = 128;

    /*video buffer*/       
    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);

	if(s32ChnNum >= 1)
    {
	    printf("u32BlkSize: %d\n", u32BlkSize);
	    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
	    stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt;
	}
	if(s32ChnNum >= 2)
    {
	    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
	                enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
	    stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
	    stVbConf.astCommPool[1].u32BlkCnt = g_u32BlkCnt;    
	}
    /******************************************
     step 2: mpp system init. 
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("system init failed with %d!\n", s32Ret);
        goto END_VENC_LOW_DELAY_0;
    }

    /******************************************
     step 3: start vi dev & chn to capture
    ******************************************/
    stViConfig.enViMode   = SENSOR_TYPE;
    stViConfig.enRotate   = ROTATE_NONE;
    stViConfig.enNorm     = VIDEO_ENCODING_MODE_AUTO;
    stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
    s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("start vi failed!\n");
        goto END_VENC_LOW_DELAY_1;
    }
    
    /******************************************
     step 4: start vpss and vi bind vpss
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_LOW_DELAY_1;
    }

    VpssGrp = 0;
    stVpssGrpAttr.u32MaxW = stSize.u32Width;
    stVpssGrpAttr.u32MaxH = stSize.u32Height;
    stVpssGrpAttr.bIeEn = HI_FALSE;
    stVpssGrpAttr.bNrEn = HI_TRUE;
    stVpssGrpAttr.bHistEn = HI_FALSE;
    stVpssGrpAttr.bDciEn = HI_FALSE;
    stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Vpss failed!\n");
        goto END_VENC_LOW_DELAY_2;
    }

    s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Vi bind Vpss failed!\n");
        goto END_VENC_LOW_DELAY_3;
    }

    VpssChn = 0;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
    memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_LOW_DELAY_4;
    }
	
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[1], &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_LOW_DELAY_4;
    }
    VpssChn = 1;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_LOW_DELAY_4;
    }

    /******************************************
     step 5: start stream venc
    ******************************************/
    /*** HD1080P **/
    printf("\t c) cbr.\n");
    printf("\t v) vbr.\n");
    printf("\t f) fixQp\n");
    printf("please input choose rc mode!\n");
    c = (char)getchar();
    switch(c)
    {
        case 'c':
            enRcMode = SAMPLE_RC_CBR;
            break;
        case 'v':
            enRcMode = SAMPLE_RC_VBR;
            break;
        case 'f':
            enRcMode = SAMPLE_RC_FIXQP;
            break;
        default:
            printf("rc mode! is invaild!\n");
            goto END_VENC_LOW_DELAY_4;
    }
	if(s32ChnNum >= 1)
	{
	    VpssGrp = 0;
	    VpssChn = 0;
	    VencChn = 0;
	    s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[0],\
	                                   gs_enNorm, enSize[0], enRcMode,u32Profile);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Start Venc failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }

	    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Start Venc failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }

	    /*set chnl Priority*/
	    s32Ret = HI_MPI_VENC_GetChnlPriority(VencChn,&u32Priority);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Get Chnl Priority failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }
	    
	    u32Priority = 1;

	    s32Ret = HI_MPI_VENC_SetChnlPriority(VencChn,u32Priority);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Set Chnl Priority failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }

	    /*set low delay*/
	    #if 1
	    s32Ret = HI_MPI_VPSS_GetLowDelayAttr(VpssGrp,VpssChn,&stLowDelayInfo);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("HI_MPI_VPSS_GetLowDelayAttr failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }
	    stLowDelayInfo.bEnable = HI_TRUE;
	    stLowDelayInfo.u32LineCnt = stVpssChnMode.u32Height/2;
	    s32Ret = HI_MPI_VPSS_SetLowDelayAttr(VpssGrp,VpssChn,&stLowDelayInfo);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("HI_MPI_VPSS_SetLowDelayAttr failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }
	    #endif
	}
	
    /*** 1080p **/
	if(s32ChnNum >= 2)
    {
	    VpssChn = 1;
	    VencChn = 1;
	    s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad[1], \
	                                    gs_enNorm, enSize[1], enRcMode,u32Profile);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Start Venc failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }

	    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("Start Venc failed!\n");
	        goto END_VENC_LOW_DELAY_5;
	    }
	}
    
    /******************************************
     step 6: stream venc process -- get stream, then save it to file. 
    ******************************************/
    s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_LOW_DELAY_5;
    }

    printf("please press twice ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     step 7: exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();
    
END_VENC_LOW_DELAY_5:
    VpssGrp = 0;

	if(s32ChnNum >= 1)
    {
	    VpssChn = 0;  
	    VencChn = 0;
	    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
	    SAMPLE_COMM_VENC_Stop(VencChn);
    }
	if(s32ChnNum >= 2)
    {
    	VpssChn = 1;   
	    VencChn = 1;
	    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
	    SAMPLE_COMM_VENC_Stop(VencChn);
	}
    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_LOW_DELAY_4:   //vpss stop
    VpssGrp = 0;
    VpssChn = 0;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
    VpssChn = 1;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_LOW_DELAY_3:    //vpss stop       
    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_LOW_DELAY_2:    //vpss stop   
    SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_LOW_DELAY_1:   //vi stop
    SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_LOW_DELAY_0:   //system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;    
}


HI_S32 SAMPLE_VENC_ROIBG_CLASSIC(HI_VOID)
{
    PAYLOAD_TYPE_E enPayLoad= PT_H264;
    PIC_SIZE_E enSize[3] = {PIC_HD1080,PIC_VGA,PIC_QVGA};
	HI_U32 u32Profile = 0;

    VB_CONF_S stVbConf;
    SAMPLE_VI_CONFIG_S stViConfig = {0};
    
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stVpssGrpAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr;
    VPSS_CHN_MODE_S stVpssChnMode;
    VENC_ROI_CFG_S  stVencRoiCfg;
    VENC_ROIBG_FRAME_RATE_S stRoiBgFrameRate;
    
    VENC_CHN VencChn;
    SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR;
    HI_S32 s32ChnNum = 1;
    
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    char c;

    /******************************************
     step  1: init sys variable 
    ******************************************/
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    SAMPLE_COMM_VI_GetSizeBySensor(&enSize[0]);
    if (PIC_HD1080 == enSize[0])
    {
		s32ChnNum = 1;
    }
    else if (PIC_HD720 == enSize[0])
    {
		s32ChnNum = 1;
    }
    else
    {
        printf("not support this sensor\n");
        return HI_FAILURE;
    }
    
    stVbConf.u32MaxPoolCnt = 128;

    /*video buffer*/
	if(s32ChnNum >= 1)
    {
	    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
	                enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
	    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
	    stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt;
	}
	if(s32ChnNum >= 2)
    {
    	u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
	    stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
	    stVbConf.astCommPool[1].u32BlkCnt = g_u32BlkCnt;
	}
	if(s32ChnNum >= 3)
    {
	    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
	                enSize[2], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
	    stVbConf.astCommPool[2].u32BlkSize = u32BlkSize;
	    stVbConf.astCommPool[2].u32BlkCnt = g_u32BlkCnt;
	}

    /******************************************
     step 2: mpp system init. 
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("system init failed with %d!\n", s32Ret);
        goto END_VENC_1080P_CLASSIC_0;
    }

    /******************************************
     step 3: start vi dev & chn to capture
    ******************************************/
    stViConfig.enViMode   = SENSOR_TYPE;
    stViConfig.enRotate   = ROTATE_NONE;
    stViConfig.enNorm     = VIDEO_ENCODING_MODE_AUTO;
    stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
    s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("start vi failed!\n");
        goto END_VENC_1080P_CLASSIC_1;
    }
    
    /******************************************
     step 4: start vpss and vi bind vpss
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_1080P_CLASSIC_1;
    }

    VpssGrp = 0;
    stVpssGrpAttr.u32MaxW = stSize.u32Width;
    stVpssGrpAttr.u32MaxH = stSize.u32Height;
    stVpssGrpAttr.bIeEn = HI_FALSE;
    stVpssGrpAttr.bNrEn = HI_TRUE;
    stVpssGrpAttr.bHistEn = HI_FALSE;
    stVpssGrpAttr.bDciEn = HI_FALSE;
    stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Vpss failed!\n");
        goto END_VENC_1080P_CLASSIC_2;
    }

    s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Vi bind Vpss failed!\n");
        goto END_VENC_1080P_CLASSIC_3;
    }

    VpssChn = 0;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
    memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_1080P_CLASSIC_4;
    }

    /******************************************
     step 5: start stream venc
    ******************************************/
    /*** HD1080P **/
    printf("\t c) cbr.\n");
    printf("\t v) vbr.\n");
    printf("\t f) fixQp\n");
    printf("please input choose rc mode!\n");
    c = (char)getchar();
    switch(c)
    {
        case 'c':
            enRcMode = SAMPLE_RC_CBR;
            break;
        case 'v':
            enRcMode = SAMPLE_RC_VBR;
            break;
        case 'f':
            enRcMode = SAMPLE_RC_FIXQP;
            break;
        default:
            printf("rc mode! is invaild!\n");
            goto END_VENC_1080P_CLASSIC_4;
    }
    VpssGrp = 0;
    VpssChn = 0;
    VencChn = 0;
    s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad,\
                                   gs_enNorm, enSize[0], enRcMode,u32Profile);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }

    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }
    stVencRoiCfg.bAbsQp   = HI_TRUE;
    stVencRoiCfg.bEnable  = HI_TRUE;
    stVencRoiCfg.s32Qp    = 30;
    stVencRoiCfg.u32Index = 0;
    stVencRoiCfg.stRect.s32X = 64;
    stVencRoiCfg.stRect.s32Y = 64;
    stVencRoiCfg.stRect.u32Height =256;
    stVencRoiCfg.stRect.u32Width =256;
    s32Ret = HI_MPI_VENC_SetRoiCfg(VencChn,&stVencRoiCfg);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }

    s32Ret = HI_MPI_VENC_GetRoiBgFrameRate(VencChn,&stRoiBgFrameRate);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("HI_MPI_VENC_GetRoiBgFrameRate failed!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }
    stRoiBgFrameRate.s32SrcFrmRate = (VIDEO_ENCODING_MODE_PAL== gs_enNorm)?25:30;   
    stRoiBgFrameRate.s32DstFrmRate = (VIDEO_ENCODING_MODE_PAL== gs_enNorm)?5:15;
    
    s32Ret = HI_MPI_VENC_SetRoiBgFrameRate(VencChn,&stRoiBgFrameRate);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("HI_MPI_VENC_SetRoiBgFrameRate!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }
    /******************************************
     step 6: stream venc process -- get stream, then save it to file. 
    ******************************************/
    s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_1080P_CLASSIC_5;
    }

    printf("please press ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     step 7: exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();
    
END_VENC_1080P_CLASSIC_5:
    VpssGrp = 0;
    
    VpssChn = 0;  
    VencChn = 0;
    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
    SAMPLE_COMM_VENC_Stop(VencChn);

    

    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_1080P_CLASSIC_4:	//vpss stop
    VpssGrp = 0;
    VpssChn = 0;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_1080P_CLASSIC_3:    //vpss stop       
    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_1080P_CLASSIC_2:    //vpss stop   
    SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_1080P_CLASSIC_1:	//vi stop
    SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_1080P_CLASSIC_0:	//system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;    
}

HI_S32 SAMPLE_VENC_SVC_H264(HI_VOID)
{
	PAYLOAD_TYPE_E enPayLoad= PT_H264;
	PIC_SIZE_E enSize[3] = {PIC_HD1080,PIC_HD720,PIC_D1};
	HI_U32 u32Profile = 3;/* Svc-t */
		
	VB_CONF_S stVbConf;
	SAMPLE_VI_CONFIG_S stViConfig = {0};
	
	VPSS_GRP VpssGrp;
	VPSS_CHN VpssChn;
	VPSS_GRP_ATTR_S stVpssGrpAttr;
	VPSS_CHN_ATTR_S stVpssChnAttr;
	VPSS_CHN_MODE_S stVpssChnMode;

	
	VENC_CHN VencChn;
	SAMPLE_RC_E enRcMode= SAMPLE_RC_CBR;
	HI_S32 s32ChnNum = 1;
	
	HI_S32 s32Ret = HI_SUCCESS;
	HI_U32 u32BlkSize;
	SIZE_S stSize;
	char c;

	/******************************************
	 step  1: init sys variable 
	******************************************/
	memset(&stVbConf,0,sizeof(VB_CONF_S));

    SAMPLE_COMM_VI_GetSizeBySensor(&enSize[0]);
    if (PIC_HD1080 == enSize[0])
    {
		s32ChnNum = 1;
    }
    else if (PIC_HD720 == enSize[0])
    {
		s32ChnNum = 1;
    }
    else
    {
        printf("not support this sensor\n");
        return HI_FAILURE;
    }
    
	stVbConf.u32MaxPoolCnt = 128;

	/*video buffer*/  
	if(s32ChnNum >= 1)
	{
		u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
					enSize[0], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
		stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
		stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt;
	}
	if(s32ChnNum >= 2)
	{
		u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
					enSize[1], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
		stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
		stVbConf.astCommPool[1].u32BlkCnt = g_u32BlkCnt;
	}
	
	if(s32ChnNum >= 1)
	{
		u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
					enSize[2], SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
		stVbConf.astCommPool[2].u32BlkSize = u32BlkSize;
		stVbConf.astCommPool[2].u32BlkCnt = g_u32BlkCnt;
	}

	/******************************************
	 step 2: mpp system init. 
	******************************************/
	s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("system init failed with %d!\n", s32Ret);
		goto END_VENC_1080P_CLASSIC_0;
	}

	/******************************************
	 step 3: start vi dev & chn to capture
	******************************************/
	stViConfig.enViMode   = SENSOR_TYPE;
	stViConfig.enRotate   = ROTATE_NONE;
	stViConfig.enNorm	  = VIDEO_ENCODING_MODE_AUTO;
	stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
	s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("start vi failed!\n");
		goto END_VENC_1080P_CLASSIC_1;
	}
	
	/******************************************
	 step 4: start vpss and vi bind vpss
	******************************************/
	s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize[0], &stSize);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
		goto END_VENC_1080P_CLASSIC_1;
	}

	VpssGrp = 0;
	stVpssGrpAttr.u32MaxW = stSize.u32Width;
	stVpssGrpAttr.u32MaxH = stSize.u32Height;
	stVpssGrpAttr.bIeEn = HI_FALSE;
	stVpssGrpAttr.bNrEn = HI_TRUE;
	stVpssGrpAttr.bHistEn = HI_FALSE;
	stVpssGrpAttr.bDciEn = HI_FALSE;
	stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
	stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Start Vpss failed!\n");
		goto END_VENC_1080P_CLASSIC_2;
	}

	s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Vi bind Vpss failed!\n");
		goto END_VENC_1080P_CLASSIC_3;
	}

	VpssChn = 0;
	stVpssChnMode.enChnMode 	= VPSS_CHN_MODE_USER;
	stVpssChnMode.bDouble		= HI_FALSE;
	stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stVpssChnMode.u32Width		= stSize.u32Width;
	stVpssChnMode.u32Height 	= stSize.u32Height;
	stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
	memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
	stVpssChnAttr.s32SrcFrameRate = -1;
	stVpssChnAttr.s32DstFrameRate = -1;
	s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Enable vpss chn failed!\n");
		goto END_VENC_1080P_CLASSIC_4;
	}

	/******************************************
	 step 5: start stream venc
	******************************************/
	/*** HD1080P **/
	printf("\t c) cbr.\n");
	printf("\t v) vbr.\n");
	printf("\t f) fixQp\n");
	printf("please input choose rc mode!\n");
	c = (char)getchar();
	switch(c)
	{
		case 'c':
			enRcMode = SAMPLE_RC_CBR;
			break;
		case 'v':
			enRcMode = SAMPLE_RC_VBR;
			break;
		case 'f':
			enRcMode = SAMPLE_RC_FIXQP;
			break;
		default:
			printf("rc mode! is invaild!\n");
			goto END_VENC_1080P_CLASSIC_4;
	}
	VpssGrp = 0;
	VpssChn = 0;
	VencChn = 0;
	s32Ret = SAMPLE_COMM_VENC_Start(VencChn, enPayLoad,\
								   gs_enNorm, enSize[0], enRcMode,u32Profile);
	
	printf("SAMPLE_COMM_VENC_Start is ok\n");
	
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Start Venc failed!\n");
		goto END_VENC_1080P_CLASSIC_5;
	}

	s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);

	printf("SAMPLE_COMM_VENC_BindVpss is ok\n");

	
	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Start Venc failed!\n");
		goto END_VENC_1080P_CLASSIC_5;
	}
	
	/******************************************
	 step 6: stream venc process -- get stream, then save it to file. 
	******************************************/
	s32Ret = SAMPLE_COMM_VENC_StartGetStream_Svc_t(s32ChnNum);

	if (HI_SUCCESS != s32Ret)
	{
		SAMPLE_PRT("Start Venc failed!\n");
		goto END_VENC_1080P_CLASSIC_5;
	}

	printf("please press ENTER to exit this sample\n");
	getchar();
	getchar();

	/******************************************
	 step 7: exit process
	******************************************/
	SAMPLE_COMM_VENC_StopGetStream();
	
	printf("SAMPLE_COMM_VENC_StopGetStream is ok\n");
END_VENC_1080P_CLASSIC_5:
	VpssGrp = 0;
	
	VpssChn = 0;  
	VencChn = 0;
	SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
	SAMPLE_COMM_VENC_Stop(VencChn);

	

	SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_1080P_CLASSIC_4:	//vpss stop
	VpssGrp = 0;
	VpssChn = 0;
	SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_VENC_1080P_CLASSIC_3:	 //vpss stop	   
	SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_1080P_CLASSIC_2:	 //vpss stop   
	SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_1080P_CLASSIC_1:	//vi stop
	SAMPLE_COMM_VI_StopVi(&stViConfig);	
END_VENC_1080P_CLASSIC_0:	//system exit
	SAMPLE_COMM_SYS_Exit();
	return s32Ret;	  
}

/******************************************************************************
* function :  Thumbnail of 1*1080p jpeg
******************************************************************************/
HI_S32 SAMPLE_VENC_1080P_JPEG_Thumb(HI_VOID)

{
    PIC_SIZE_E enSize = PIC_HD1080;
    ISP_DCF_INFO_S stIspDCF;

    VB_CONF_S stVbConf;
    SAMPLE_VI_CONFIG_S stViConfig = {0};
    
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stVpssGrpAttr;
    VPSS_CHN_ATTR_S stVpssChnAttr;
    VPSS_CHN_MODE_S stVpssChnMode;
    
    VENC_CHN VencChn;
        
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    HI_S32 i = 0;
    char ch;

    /******************************************
     step  1: init sys variable 
    ******************************************/
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    stVbConf.u32MaxPoolCnt = 128;
    SAMPLE_COMM_VI_GetSizeBySensor(&enSize);

    /*video buffer*/
    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);

    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = g_u32BlkCnt;


    /******************************************
     step 2: mpp system init. 
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_Init_With_DCF(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("system init failed with %d!\n", s32Ret);
        goto END_VENC_MJPEG_JPEG_0;
    }
 
    /******************************************
     step 3: start vi dev & chn to capture
    ******************************************/
    stViConfig.enViMode   = SENSOR_TYPE;
    stViConfig.enRotate   = ROTATE_NONE;
    stViConfig.enNorm     = VIDEO_ENCODING_MODE_AUTO;
    stViConfig.enViChnSet = VI_CHN_SET_NORMAL;
    s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("start vi failed!\n");
        goto END_VENC_MJPEG_JPEG_1;
    }
    
    /******************************************
     step 4: start vpss and vi bind vpss
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_MJPEG_JPEG_1;
    }
	
    VpssGrp = 0;
    stVpssGrpAttr.u32MaxW = stSize.u32Width;
    stVpssGrpAttr.u32MaxH = stSize.u32Height;
    stVpssGrpAttr.bIeEn = HI_FALSE;
    stVpssGrpAttr.bNrEn = HI_TRUE;
    stVpssGrpAttr.bHistEn = HI_FALSE;
    stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stVpssGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stVpssGrpAttr.bDciEn = HI_FALSE;
    s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Vpss failed!\n");
        goto END_VENC_MJPEG_JPEG_2;
    }

    s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Vi bind Vpss failed!\n");
        goto END_VENC_MJPEG_JPEG_3;
    }

    
    VpssChn = 0;
    stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
    stVpssChnMode.bDouble       = HI_FALSE;
    stVpssChnMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    stVpssChnMode.u32Width      = stSize.u32Width;
    stVpssChnMode.u32Height     = stSize.u32Height;
    stVpssChnMode.enCompressMode = COMPRESS_MODE_NONE;
    
    memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
    stVpssChnAttr.s32SrcFrameRate = -1;
    stVpssChnAttr.s32DstFrameRate = -1;
    s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Enable vpss chn failed!\n");
        goto END_VENC_MJPEG_JPEG_4;
    }
    
    /******************************************
     step 5: set CDF info
    ******************************************/
    
    HI_MPI_ISP_GetDCFInfo(&stIspDCF);
    
    //description: Thumbnail test
    memcpy(stIspDCF.au8ImageDescription,"Thumbnail test",strlen("Thumbnail test"));
    
    //manufacturer: Hisilicon
    memcpy(stIspDCF.au8Make,"Hisilicon",strlen("Hisilicon"));
    
    //model number: Hisilicon IP Camera
    memcpy(stIspDCF.au8Model,"Hisilicon IP Camera",strlen("Hisilicon IP Camera"));
    
    //firmware version: v.1.1.0 
    memcpy(stIspDCF.au8Software,"v.1.1.0",strlen("v.1.1.0"));
    
    stIspDCF.u16ISOSpeedRatings         = 500;
    stIspDCF.u32ExposureBiasValue       = 5;
    stIspDCF.u32ExposureTime            = 0x00010004;
    stIspDCF.u32FNumber                 = 0x0001000f;
    stIspDCF.u32FocalLength             = 0x00640001;
    stIspDCF.u32MaxApertureValue        = 0x00010001;
    stIspDCF.u8Contrast                 = 5;
    stIspDCF.u8CustomRendered           = 0;
    stIspDCF.u8ExposureMode             = 0;
    stIspDCF.u8ExposureProgram          = 1;
    stIspDCF.u8FocalLengthIn35mmFilm    = 1;
    stIspDCF.u8GainControl              = 1;
    stIspDCF.u8LightSource              = 1;
    stIspDCF.u8MeteringMode             = 1;
    stIspDCF.u8Saturation               = 1;
    stIspDCF.u8SceneCaptureType         = 1;
    stIspDCF.u8SceneType                = 0;
    stIspDCF.u8Sharpness                = 5;
    stIspDCF.u8WhiteBalance             = 1;
    
    HI_MPI_ISP_SetDCFInfo(&stIspDCF);
    
    /******************************************
     step 6: start stream venc
    ******************************************/
    VpssGrp = 0;
    VpssChn = 0;
    VencChn = 0;
    
    s32Ret = SAMPLE_COMM_VENC_SnapStart(VencChn, &stSize, HI_TRUE);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start snap failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    
    s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VpssChn);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Venc failed!\n");
        goto END_VENC_MJPEG_JPEG_5;
    }

    /******************************************
     step 7: stream venc process -- get stream, then save it to file. 
    ******************************************/
    printf("press 'q' to exit sample!\nperess ENTER to capture one picture to file\n");
    i = 0;
    while ((ch = (char)getchar()) != 'q')
    {
        s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencChn, HI_TRUE, HI_TRUE);
        if (HI_SUCCESS != s32Ret)
        {
            printf("%s: sanp process failed!\n", __FUNCTION__);
            break;
        }
        printf("snap %d success!\n", i);
        i++;
    }
 
    printf("please press ENTER to exit this sample\n");
    getchar();
    getchar();

    /******************************************
     step 8: exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();
    
END_VENC_MJPEG_JPEG_5:
    VpssGrp = 0;
    VpssChn = 0;
    VencChn = 0;
    SAMPLE_COMM_VENC_UnBindVpss(VencChn, VpssGrp, VpssChn);
    SAMPLE_COMM_VENC_Stop(VencChn);
END_VENC_MJPEG_JPEG_4:    //vpss stop
    VpssGrp = 0;
    VpssChn = 0;
    SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn); 
END_VENC_MJPEG_JPEG_3:    //vpss stop       
    SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_VENC_MJPEG_JPEG_2:    //vpss stop   
    SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_VENC_MJPEG_JPEG_1:    //vi stop
    SAMPLE_COMM_VI_StopVi(&stViConfig);
END_VENC_MJPEG_JPEG_0:	//system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;
}



/******************************************************************************
* function    : main()
* Description : video venc sample
******************************************************************************/
int main(int argc, char *argv[])
{
    HI_S32 s32Ret;
    if ( (argc < 2) || (1 != strlen(argv[1])))  //argc傳參校驗,引數個不能大於2個。引數2字串長度不等於1 
    {
        SAMPLE_VENC_Usage(argv[0]); //提示程式使用方法
        return HI_FAILURE;  //return -1
    }

    signal(SIGINT, SAMPLE_VENC_HandleSig);  //SIGINT=2 , 屬於中斷訊號,定義在/usr/include/i386-linux-gnu/bits/signal.h
    signal(SIGTERM, SAMPLE_VENC_HandleSig); //SIGTERM=15,屬於結束訊號,類似kill命令傳送的OS預設終止訊號
    										//SAMPLE_VENC_HandleSig這個函式主要是停止ISP和退出SYS
    switch (*argv[1])
    {
        case '0':/* [email protected]@[email protected]@[email protected]@30fps */ 
            s32Ret = SAMPLE_VENC_1080P_CLASSIC(); //實現如上三路碼流實時編碼,幀率預設設定為30,實時編碼都正常。
            break;
        case '1':/* 1*1080p mjpeg encode + 1*1080p jpeg  */
            s32Ret = SAMPLE_VENC_1080P_MJPEG_JPEG(); //1×1080p MJPEG編碼+ 1×1080p JPEG
            break;
        case '2':/* low delay */
            s32Ret = SAMPLE_VENC_LOW_DELAY(); //低延時
            break;
        case '3':/* roibg framerate */
            s32Ret = SAMPLE_VENC_ROIBG_CLASSIC();
            break;
        case '4':/* Thumbnail of 1*1080p jpeg  */
            s32Ret = SAMPLE_VENC_1080P_JPEG_Thumb();  //1×1080p JPEG縮圖
            break;
#ifndef hi3518ev201			
		case '5':/* H.264 Svc-t */
			s32Ret = SAMPLE_VENC_SVC_H264();
			break;
#endif
        default:
            printf("the index is invaild!\n");
            SAMPLE_VENC_Usage(argv[0]);
            return HI_FAILURE;
    }
    
    if (HI_SUCCESS == s32Ret)
        printf("program exit normally!\n");
    else
        printf("program exit abnormally!\n");
    exit(s32Ret);
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */

總結:1.設定視訊編碼模式(N制或P制)

           2.mian 套           

                        SAMPLE_VENC_1080P_CLASSIC
SAMPLE_COMM_VI_GetSizeBySensor(step1)
SAMPLE_COMM_SYS_CalcPicVbBlkSize
SAMPLE_COMM_SYS_GetPicSize
SAMPLE_COMM_SYS_Init(step2)
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
HI_MPI_VB_SetConf
HI_MPI_VB_Init
HI_MPI_SYS_SetConf
HI_MPI_SYS_Init
SAMPLE_COMM_VI_StartVi(step3)
IsSensorInput
SAMPLE_COMM_VI_StartIspAndVi
SAMPLE_COMM_VI_StartMIPI(1)
SAMPLE_COMM_VI_SetMipiAttr
fd = open("/dev/hi_mipi", O_RDWR);
ioctl(fd, HI_MIPI_SET_DEV_ATTR, pstcomboDevAttr)
SAMPLE_COMM_ISP_Init(2)
sensor_register_callback
HI_MPI_AE_Register
HI_MPI_AWB_Register
HI_MPI_AF_Register
HI_MPI_ISP_MemInit
HI_MPI_ISP_SetWDRMode
HI_MPI_ISP_SetPubAttr
HI_MPI_ISP_Init
SAMPLE_COMM_ISP_Run(3)
pthread_create(&gs_IspPid, &attr, (void* (*)(void*))Test_ISP_Run, NULL)
Test_ISP_Run
HI_MPI_ISP_Run
SAMPLE_COMM_VI_StartDev(4)
HI_MPI_VI_SetDevAttr
HI_MPI_ISP_GetWDRMode
HI_MPI_VI_SetWDRAttr
HI_MPI_VI_EnableDev
SAMPLE_COMM_VI_StartChn(5)
HI_MPI_VI_SetChnAttr
HI_MPI_VI_SetRotate
HI_MPI_VI_EnableChn
SAMPLE_COMM_SYS_GetPicSize(step4)----VPSS
SAMPLE_COMM_VPSS_StartGroup
SAMPLE_COMM_VI_BindVpss
SAMPLE_COMM_VPSS_EnableChn
SAMPLE_COMM_VENC_Start(step5) 
-----
-----
-----
SAMPLE_COMM_VENC_BindVpss
SAMPLE_COMM_VENC_StartGetStream(step6)
SAMPLE_COMM_VENC_StopGetStream(step7)

相關推薦

[36]_SDK編碼分之sample_venc.c

不多說了,直接上原始碼+分析....../****************************************************************************** A simple program of Hisilicon HI3531

ubuntu14編譯SDK的部分配置

 ubuntu64安裝海思需要32位系統配置apt-get intall libncurses5-dev                    &n

ubuntu SDK安裝

)Ubuntu下修改預設Shell:dash為bash 輸入 dpkg-reconfigure dash 後選 no 選項 2)解壓SDK到當前目錄後 進入目錄如: ./Hi3515_V100R001C01SPC050/software/board 解壓 tar zxvf Hi3515_SDK_V1.0.5

SDK編譯實踐 -- hi3716cv200es1

----------------------------------------------------------------------------------------------------------------------------------------

Linux 查看系統硬件信息匯總 (份實例Centoso為例)

linux 查看系統硬件信息(實例詳解 linux 查看系統硬件信息匯總 1.cpu #lscpu命令,查看的是cpu的統計信息.Architecture: x86_64CPU op-mode(s): 32-bit, 64-bitByte Order:

C++框架_之Qt的窗口部件系統的-上

同時 窗體 包含 鼠標 對象模型 種類 動態分配內存 對話框 狀態 C++框架_之Qt的窗口部件系統的詳解-上 第一部分概述 第一次建立helloworld程序時,曾看到Qt Creator提供的默認基類只有QMainWindow、QWidget和QDialog三種。是的,

[自編碼器] [稀疏自編碼器] Auto Encoder原理

alt mage auto ali 技術 14. 大牛 pca center   自編碼器是一種有效的提取特征的方法,與PCA無監督降維不同,它實際上是獨立於有監督、無監督算法外的自監督算法,Hinton大牛主要就是搞這塊的,比如被他當做寶貝的玻爾茲曼機... 下面這個PP

H264編碼器7( h264 CBP)

來自:https://blog.csdn.net/leibniz_zsu/article/details/4325324   Coded_block_pattern,即CBP,指亮度和色度分量的各小塊的殘差的編碼方案。   CBP詳解 cbp一共6bit,高2

String.getBytes()與下載時編碼為iso8859-1的

有時候,為了讓中文字元適應某些特殊要求(如http header頭要求其內容必須為iso8859-1編碼),可能會通過將中文字元按照位元組方式來編碼的情況,如 String s_iso88591 = new String("中".getBytes("UTF-8"),"ISO

Hi3559A的sdk編譯的注意事項

1.安裝交叉編譯工具鏈後,一定需要將環境變數加進來,在.bashrc檔案中增加引入環境變數的語句,可保證shell環境每次啟動時都能載入環境變數 2.ubuntu預設環境是dash,海思的程式設計環境預設是bash,將dash改為bash 3.編譯核心時,缺少生成uImage的工具mkima

3518EV200 SDK中獲取和儲存H.264碼流

1 /****************************************** 2 step 2: Start to get streams of each channel. 3 ************************************

建立live555編碼推流服務

因專案需要,這一週弄了一下live555。需求:海思編碼——>RTSP server,使用VLC可以訪問,類似於網路攝像機的需求。看了一下,live555的架構太複雜了,半桶水的C++水平還真的需要花點時間才可以明白。由於live555的例子server使用的是讀取檔案,打包成RTSP包然後傳送。例子執

Hi3518EV200 SDK分析筆記

=========================================================================================================== 1. /* We just coyp this value of payload t

HI3516A SDK以及效能應用分析

      HI3516A+IMX178 500萬30幀38攝像機模組,擁有1/1.8寸影象感測器,500萬的H.265編碼,3低3流,寬動態,變焦等特點,有“3低3流”特徵:      1.低頻寬:採用H.265視訊編碼壓縮和獨特的傳輸技術,在較窄的網路頻寬條件下,能夠傳輸流暢的高清視訊監控訊號,保持影象清

ffmpeg庫解碼G726庫編碼音訊資料

解碼流程: 1、  讀取海思g726音訊資料,海思g726音訊會多4個位元組的海思頭資訊。 2、選擇ffmpeg g726編碼器進行解碼。ffmpeg g726解碼器包括:AV_CODEC_ID_ADPCM_G726、AV_CODEC_ID_ADPCM_G726LE。如果海

編碼中新增加密函式

在\trunk\platform\ZC\DMIPC3516\HS-CIPD-12C\modules\soe目錄下的SOEproducerDemo.c新增函式。 對應的庫放到\trunk\platform\ZC\DMIPC3516\HS-CIPD-12C\modules\so

Hi3518A Hi3518C Hi3518E 這幾個芯片都有什麽區別麽

進一步 ios 區別 時鐘 用戶 宋體 16px 生產 電平 在3518A、3518C的基礎上深化完善,推出了Hi3518E。作為新一代IP民用攝像機SoC,Hi3518E集成新一代ISP,優化了編碼前圖像處理算法,采用新一代H.264編碼器。同時采用業內領先的低

HI35XX之----視頻處理單元各通道間的關系

pen sensor 模式 支持 切換 enc 心得 ann 兩種模式 最近在折騰HI3518C的芯片,應用到IPCamera上,最終獲取多路不同分辨率的視頻流供不同需求的預覽切換。此處簡單記錄一下視頻前處理元VPSS(Video Process Sub-System)的多

hi3716c機頂盒接usb攝像頭和usb無線耳機時,無線耳機有時沒有聲音

setup 出現 sea log delayed 重載 出現異常 jar action 兩個USB設備各自是: A:USB攝像頭帶錄音功能,但不帶放音功能。 B:USB無線耳機是使用USB轉2.4G的無線耳機。 詳細現象: 1, A,B兩者同一時候插

java類與對象_成員變量和局變量區別

什麽 bsp java類 臨時 對象 類變量 類與對象 保存 java 成員變量和局部變量:1.成員變量:再類中定義,用來描述對象將要有什麽。2.局部變量:在類的方法中定義,在方法中臨時保存數據。區別:1.作用域不同: 局部:僅限於定義它的方法 成員:整個類中都是可見的