1. 程式人生 > 實用技巧 >視訊處理子系統 建立組/通道 範例

視訊處理子系統 建立組/通道 範例

文件範例:

/*********************************
*函式功能:建立組/通道
*輸出引數:
*返回值:成功為0 失敗非0
*********************************/
HI_S32 create_VPSS_Group()
{
    VPSS_GRP_ATTR_S stGrpVpssAttr;     //group靜態屬性
    VPSS_CHN_ATTR_S stChnAttr; 
    VPSS_CROP_INFO_S stCropInfo; 
    HI_S32 s32Ret = HI_SUCCESS;     //返回值
    VPSS_GRP VpssGrp;                 //
組號 VPSS_CHN VpssChn; //通道號 VpssGrp = 0; VpssChn = 0; stGrpVpssAttr.u32MaxW = 1920; //最大影象寬高 stGrpVpssAttr.u32MaxH = 1080; stGrpVpssAttr.bIeEn = HI_FALSE; //下面這幾個都是使能開關 stGrpVpssAttr.bDciEn = HI_FALSE; stGrpVpssAttr.bNrEn = HI_FALSE; stGrpVpssAttr.bHistEn
= HI_FALSE; stGrpVpssAttr.enDieMode = VPSS_DIE_MODE_NODIE; stGrpVpssAttr.bEsEn = HI_FALSE; stGrpVpssAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_422; //畫素格式 s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, &stGrpVpssAttr); //建立組 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret
= HI_MPI_VPSS_GetGrpAttr(VpssGrp, &stGrpVpssAttr); //獲取組屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } stGrpVpssAttr.bDciEn = HI_TRUE; stGrpVpssAttr.bNrEn = HI_TRUE; s32Ret = HI_MPI_VPSS_SetGrpAttr(VpssGrp, &stGrpVpssAttr); //設定組屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret = HI_MPI_VPSS_GetGrpCrop(VpssGrp, &stCropInfo); //獲取 VPSS CROP 功能屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } stCropInfo.bEnable = 1; //crop使能開關 stCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR; //crop起始點座標模式 stCropInfo.stCropRect.s32X = 100; //crop矩形區域 頂點座標和寬高 stCropInfo.stCropRect.s32Y = 200; stCropInfo.stCropRect.u32Width = 1280; stCropInfo.stCropRect.u32Height = 720; s32Ret = HI_MPI_VPSS_SetGrpCrop(VpssGrp, &stCropInfo); //設定組crop屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret = HI_MPI_VPSS_GetChnAttr(VpssGrp, VpssChn,&stChnAttr); //獲取通道屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } stChnAttr.bUVInvert = 0; stChnAttr.bSpEn = 1; s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn,&stChnAttr); //設定VPSS通道屬性 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn); //使能通道 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret = HI_MPI_VPSS_StartGrp (VpssGrp); //啟用組 if(s32Ret != HI_SUCCESS) { return s32Ret; } /*****************************/ /* call sys bind interface */ /*****************************/ s32Ret = HI_MPI_VPSS_StopGrp (VpssGrp); //禁用組 if(s32Ret != HI_SUCCESS) { return s32Ret; } s32Ret = HI_MPI_VPSS_DisableChn(VpssGrp, VpssChn); //關閉通道 if(s32Ret != HI_SUCCESS) { return s32Ret; } /*****************************/ /* call sys unbind interface */ /*****************************/ s32Ret = HI_MPI_VPSS_DestroyGrp(VpssGrp); //銷燬組 先禁用才能銷燬 if(s32Ret != HI_SUCCESS) { return s32Ret; } }

例項:

HI_S32 vpss_create_vpss(HI_S32 s32GrpCnt, HI_S32 s32ChnCnt)
{
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stGrpAttr;
    VPSS_CHN_ATTR_S stChnAttr;
    VPSS_GRP_PARAM_S stVpssParam;
    VPSS_CHN_MODE_S stVpssChnMode;
    HI_S32 s32Ret;
    HI_S32 i, j;
    SIZE_S stPicSize;

    VPSS_PRESCALE_INFO_S stPreScaleInfo;

    memset(&stGrpAttr,0,sizeof(VPSS_GRP_ATTR_S));
    stGrpAttr.bIeEn = HI_FALSE;
    stGrpAttr.bNrEn = HI_FALSE;
    stGrpAttr.bDciEn = HI_FALSE;
    stGrpAttr.bHistEn = HI_FALSE;
    stGrpAttr.bEsEn  = HI_FALSE;
    stGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
    stGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    //stGrpAttr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_422;
    

    for(i = 0; i < s32GrpCnt; i++)
    {
        VpssGrp = i;
        
        if(VpssGrp<vi_chn_num)
        {
            stGrpAttr.bNrEn = HI_TRUE;
            //stGrpAttr.bNrEn = HI_FALSE;

            if(Simulate_IP_mixture_mode)
            {

                 /* if((VpssGrp>=vi_chn_num*2))
                  {
                        stGrpAttr.bNrEn = HI_FALSE;
                  }
                  else*/
                 {
                        //stGrpAttr.bNrEn = HI_FALSE;
                 }
                stGrpAttr.u32MaxW = 1920;//2048;  
                stGrpAttr.u32MaxH = 1080;//1536; 
               }
               else
              {    
                  /*if((VpssGrp>=vi_chn_num*2))
                  {
                      stGrpAttr.bNrEn = HI_FALSE;
                  }
                  else*/
                 {
                       //stGrpAttr.bNrEn = HI_TRUE;
                        //stGrpAttr.bNrEn = HI_FALSE;
                 }
                stGrpAttr.u32MaxW = 1920;  
                stGrpAttr.u32MaxH = 1080; //1944;
              }
        }
        else
        {

            if(i == 13)
            {
                stGrpAttr.bNrEn = HI_TRUE;
            }
            else
            {
                stGrpAttr.bNrEn = HI_FALSE;
            }
            
            if(Simulate_IP_mixture_mode)
            {
                stGrpAttr.u32MaxW = 1920;  
                stGrpAttr.u32MaxH = 1080;
            }
            else
            {
                stGrpAttr.u32MaxW = 1920;  
                stGrpAttr.u32MaxH = 1080;            
            }
        }
        
        
        //stGrpAttr.u32MaxW = 2560;  
        //stGrpAttr.u32MaxH = 1944; 

        s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, &stGrpAttr);    //建立一個 VPSS GROUP。
        if (s32Ret != HI_SUCCESS)
        {
            SDKPRINTF("HI_MPI_VPSS_CreateGrp %d failed with %#x!\n",i,s32Ret);
            return HI_FAILURE;
        }
        
        s32Ret = HI_MPI_VPSS_GetGrpParam(VpssGrp, &stVpssParam);    //獲取 VPSS GROUP 引數
        if (s32Ret != HI_SUCCESS)
        {
            SDKPRINTF("failed with %#x!\n", s32Ret);
            return HI_FAILURE;
        }

    #if 0
        stVpssParam.u32Contrast   = 13; // 13 
        stVpssParam.u32SfStrength = 24;//36; //亮度空域去噪 26 
        stVpssParam.u32TfStrength = 18;//13; //18;//亮度時域去噪 6
        stVpssParam.u32CfStrength = 12; //色度空域去噪 12
        stVpssParam.u32CTfStrength= 10;//6;  //色度時域去噪 6
        stVpssParam.u32IeStrength = 4;//3;  // 7
        stVpssParam.u32CvbsStrength=24;
    #else
        // yqf modify 2017.7.24
        stVpssParam.u32Contrast   = 13; // 13 
        stVpssParam.u32SfStrength = 26; //亮度空域去噪 26 
        stVpssParam.u32TfStrength = 18;//亮度時域去噪 6
        stVpssParam.u32CfStrength = 12; //色度空域去噪 12
        stVpssParam.u32CTfStrength= 6;  //色度時域去噪 6
        stVpssParam.u32IeStrength = 7;  // 7
    #endif
/*
            stVpssParam.u32CfStrength = 12; //5
        stVpssParam.u32SfStrength = 26; //20
        stVpssParam.u32TfStrength = 18;  //5
         stVpssParam.u32CTfStrength =6; //5
         stVpssParam.u32Contrast =13;    //8
*/    
        s32Ret = HI_MPI_VPSS_SetGrpParam(VpssGrp, &stVpssParam);    //設定 VPSS GRUOP 引數。
        if (s32Ret != HI_SUCCESS)
        {
            SDKPRINTF("failed with %#x!\n", s32Ret);
            return HI_FAILURE;
        }


        //modify by yqf 2018.4.3
        if(vi_chn_num > VpssGrp)
        {
            s32Ret = HI_MPI_VPSS_DisableBackupFrame(VpssGrp);
            if (s32Ret != HI_SUCCESS)
            {
                SDKPRINTF("HI_MPI_VPSS_DisableBackupFrame %d failed with %#x!\n",i,s32Ret);
                return HI_FAILURE;
            }
        }
        
        for(j = 0; j < s32ChnCnt; j++)
        {
            if(vi_chn_num != 8)
            {
                if(i >=vi_chn_num )
                {
                    if(i <=g_vi_chn_num )
                    {
                        if(j>1)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if(j>0)
                        {
                            continue;
                        }
                    }
                }
            }
            else
            {
                if(i >=vi_chn_num )
                {        
                    if(j>0)
                    {
                        continue;
                    }
                }    
            }
            VpssChn = j;
            stChnAttr.bSpEn = HI_FALSE;
            stChnAttr.bUVInvert = HI_FALSE;
            stChnAttr.bBorderEn = HI_TRUE;
            
            stChnAttr.stBorder.u32BottomWidth=2;
            stChnAttr.stBorder.u32Color=0x0000;
            stChnAttr.stBorder.u32LeftWidth=2;
            stChnAttr.stBorder.u32RightWidth=2;
            stChnAttr.stBorder.u32TopWidth=2;
            
            
            //stChnAttr.bSpEn = HI_FALSE;
            //stChnAttr.bFrameEn = HI_FALSE;
            //stChnAttr.stFrame.u32Color[VPSS_FRAME_WORK_LEFT] = 0xff00;
            //stChnAttr.stFrame.u32Color[VPSS_FRAME_WORK_RIGHT] = 0xff00;
            //stChnAttr.stFrame.u32Color[VPSS_FRAME_WORK_BOTTOM] = 0xff00;
            //stChnAttr.stFrame.u32Color[VPSS_FRAME_WORK_TOP] = 0xff00;
            //stChnAttr.stFrame.u32Width[VPSS_FRAME_WORK_LEFT] = 2;
            //stChnAttr.stFrame.u32Width[VPSS_FRAME_WORK_RIGHT] = 2;
            //stChnAttr.stFrame.u32Width[VPSS_FRAME_WORK_TOP] = 2;
            //stChnAttr.stFrame.u32Width[VPSS_FRAME_WORK_BOTTOM] = 2;
            
            s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &stChnAttr);      //設定 VPSS 通道屬性。
            if (s32Ret != HI_SUCCESS)
            {
                SDKPRINTF("HI_MPI_VPSS_SetChnAttr failed with %#x grp is %d ,chn is %d \n", s32Ret,VpssGrp,VpssChn);
                return HI_FAILURE;
            }


            
#if 1
            //if (3 != VpssChn)
            {
                VPSS_CHN_MODE_S stVpssMode;
                s32Ret = HI_MPI_VPSS_GetChnMode(VpssGrp,VpssChn,&stVpssMode);       //獲取 VPSS 通道工作模式
                if(s32Ret != HI_SUCCESS) 
                {         
                    printf("HI_MPI_VPSS_GetChnMode:0x%x\n", s32Ret);
                    return s32Ret;  
                } 

                //modify by yqf 2018.3.7
                stVpssMode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;

                stVpssMode.enCompressMode =COMPRESS_MODE_NONE;
                /*
                if((VpssGrp>=g_vi_chn_num)&&(VpssGrp<g_vi_chn_num *2))
                {
                    if(VpssChn == 0) 
                    {
                        stVpssMode.enCompressMode =COMPRESS_MODE_NONE;
                        stVpssMode.u32Width = 1920; 
                        stVpssMode.u32Height = 1080; 
                        stVpssMode.enChnMode = VPSS_CHN_MODE_USER; 
                    }
                }
                */
                s32Ret = HI_MPI_VPSS_SetChnMode(VpssGrp,VpssChn,&stVpssMode);       //設定 VPSS 通道工作模式
                if(s32Ret != HI_SUCCESS) 
                { 
                    printf("HI_MPI_VPSS_SetChnMode:0x%x\n", s32Ret);
                    return s32Ret;  
                } 
            }
#endif
            s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);       //啟用 VPSS 通道
            if (s32Ret != HI_SUCCESS)
            {
                SDKPRINTF("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);
                return HI_FAILURE;
            }
        }

        s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);     //啟用 VPSS GROUP。
        if (s32Ret != HI_SUCCESS)
        {
            SDKPRINTF("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
            return HI_FAILURE;
        }
    }

    return HI_SUCCESS;
}