Beispiel #1
1
/******************************************************************************
* function :  1D1 User send pictures for H264 encode
******************************************************************************/
HI_S32 SAMPLE_VENC_1D1_USER_SEND_PICTURES(HI_VOID)
{  
    VB_CONF_S stVbConf;
    VENC_GRP VencGrp = 0;
    VENC_CHN VencChn = 0;
    PIC_SIZE_E enSize = PIC_D1;
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    VB_POOL hPool  = VB_INVALID_POOLID;
    FILE *pfp_img = HI_NULL;  
    HI_U32 u32PicLStride            = 0;
    HI_U32 u32PicCStride            = 0;
    HI_U32 u32LumaSize              = 0;
    HI_U32 u32ChrmSize              = 0;
    HI_U32 u32Cnt                   = 0;
    HI_U32 u32ChnCnt                = 1;

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

    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.u32MaxPoolCnt = 128;

    /*ddr0 video buffer*/
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = 10;
    memset(stVbConf.astCommPool[0].acMmzName,0,
        sizeof(stVbConf.astCommPool[0].acMmzName));

    
    /******************************************
     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_USER_0;
    }

   
    /******************************************
     step 3: open yuv file
    ******************************************/
    if (pfp_img != HI_NULL)
    {
        fclose(pfp_img);
        pfp_img = HI_NULL;
    }
    

    pfp_img = fopen(SAMPLE_YUV_D1_FILEPATH, "rb" ); 
    if (pfp_img == HI_NULL)
    {
        SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n",SAMPLE_YUV_D1_FILEPATH);
        goto END_VENC_USER_0;
    }
    
    /******************************************
     step 4: create private pool on ddr0
    ******************************************/
    hPool   = HI_MPI_VB_CreatePool( u32BlkSize, 10,NULL );
    if (hPool == VB_INVALID_POOLID)
    {
        SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n");
        goto END_VENC_USER_1;
    }
    
    /******************************************
     step 5: encode process
    ******************************************/
    
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_USER_2;
    }
    
    s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, PT_H264, gs_enNorm, enSize, SAMPLE_RC_CBR);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start snap failed!\n");
        goto END_VENC_USER_2;
    }


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

    u32PicLStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
    u32PicCStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH);
    u32LumaSize = (u32PicLStride * stSize.u32Height);
    u32ChrmSize = (u32PicCStride * stSize.u32Height) >> 2;


    while(0 == feof(pfp_img))
    { 
        SAMPLE_MEMBUF_S stMem = {0};
        VIDEO_FRAME_INFO_S stFrmInfo;

        stMem.hPool = hPool;
        u32Cnt ++;
        while((stMem.hBlock = HI_MPI_VB_GetBlock(stMem.hPool, u32BlkSize,NULL)) == VB_INVALID_HANDLE)
        {
             ;
        }
  
        stMem.u32PhyAddr = HI_MPI_VB_Handle2PhysAddr(stMem.hBlock);


        stMem.pVirAddr = (HI_U8 *) HI_MPI_SYS_Mmap( stMem.u32PhyAddr, u32BlkSize );
        if(stMem.pVirAddr == NULL)
        {
            SAMPLE_PRT("Mem dev may not open\n");
            goto END_VENC_USER_4;
        }
    
        memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S));
        stFrmInfo.stVFrame.u32PhyAddr[0] = stMem.u32PhyAddr;
        stFrmInfo.stVFrame.u32PhyAddr[1] = stFrmInfo.stVFrame.u32PhyAddr[0] + u32LumaSize;
        stFrmInfo.stVFrame.u32PhyAddr[2] = stFrmInfo.stVFrame.u32PhyAddr[1] + u32ChrmSize;
        
        stFrmInfo.stVFrame.pVirAddr[0] = stMem.pVirAddr;
        stFrmInfo.stVFrame.pVirAddr[1] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[0] + u32LumaSize;
        stFrmInfo.stVFrame.pVirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[1] + u32ChrmSize;

        stFrmInfo.stVFrame.u32Width     = stSize.u32Width;
        stFrmInfo.stVFrame.u32Height    = stSize.u32Height;
        stFrmInfo.stVFrame.u32Stride[0] = u32PicLStride;
        stFrmInfo.stVFrame.u32Stride[1] = u32PicLStride;
        stFrmInfo.stVFrame.u32Stride[2] = u32PicLStride;

        stFrmInfo.stVFrame.u64pts     = (u32Cnt * 40);
        stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2);

        /*  Different channsel with different picture sequence  */
        SAMPLE_COMM_VENC_ReadOneFrame( pfp_img, stFrmInfo.stVFrame.pVirAddr[0], 
            stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.pVirAddr[2],
            stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height, 
            stFrmInfo.stVFrame.u32Stride[0], stFrmInfo.stVFrame.u32Stride[1] >> 1 );

        SAMPLE_COMM_VENC_PlanToSemi( stFrmInfo.stVFrame.pVirAddr[0], stFrmInfo.stVFrame.u32Stride[0],
        stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.u32Stride[1],
        stFrmInfo.stVFrame.pVirAddr[2], stFrmInfo.stVFrame.u32Stride[1],
        stFrmInfo.stVFrame.u32Width,    stFrmInfo.stVFrame.u32Height );

        stFrmInfo.stVFrame.enPixelFormat = SAMPLE_PIXEL_FORMAT;
        stFrmInfo.stVFrame.u32Field = VIDEO_FIELD_FRAME;
    
        stMem.u32PoolId = HI_MPI_VB_Handle2PoolId( stMem.hBlock );
        stFrmInfo.u32PoolId = stMem.u32PoolId;
        
        s32Ret = HI_MPI_VENC_SendFrame(VencGrp, &stFrmInfo);

        HI_MPI_SYS_Munmap( stMem.pVirAddr, u32BlkSize );
        HI_MPI_VB_ReleaseBlock(stMem.hBlock);

    }

    /******************************************
     step 7: exit process
    ******************************************/
END_VENC_USER_4:
    SAMPLE_COMM_VENC_StopGetStream();
END_VENC_USER_3:
    
    s32Ret = SAMPLE_COMM_VENC_Stop(VencGrp,VencChn);;
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Stop encode failed!\n");
        goto END_VENC_USER_2;
    }
END_VENC_USER_2:    
    //before destroy private pool,must stop venc
    HI_MPI_VB_DestroyPool( hPool );

END_VENC_USER_1:	
    //close the yuv file
    fclose( pfp_img );
    pfp_img = HI_NULL;
END_VENC_USER_0:	
    //system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;
}
Beispiel #2
0
/******************************************************************************
* function : Stop BT1120 720P vi/vo/venc
******************************************************************************/
HI_VOID SAMPLE_COMM_IVE_BT1120_720P_Stop(SAMPLE_IVE_VI_VO_CONFIG_S *pstViVoConfig,
	HI_BOOL bOpenVi,HI_BOOL bOpenViExt,HI_BOOL bOpenVo,HI_BOOL bOpenVenc,HI_BOOL bOpenVpss,HI_U32 u32VpssChnNum)
{
    VO_DEV VoDev = SAMPLE_VO_DEV_DSD0;
    VO_LAYER VoLayer = 0;
	SAMPLE_VO_MODE_E enVoMode = VO_MODE_1MUX;
	VI_CHN ViExtChn = 1;
	VENC_CHN VencChn = 0;
	HI_U32 u32VpssGrpCnt = 1;		
	
	if (HI_TRUE == bOpenVpss)
	{
		SAMPLE_COMM_IVE_StopVpss(u32VpssGrpCnt,u32VpssChnNum);
	}
	if (HI_TRUE == bOpenVenc)
	{
		SAMPLE_COMM_VENC_StopGetStream();
		SAMPLE_COMM_VENC_Stop(VencChn);
	}
	//Close vo
	if (HI_TRUE == bOpenVo )
	{
		SAMPLE_COMM_VO_StopChn(VoDev, enVoMode);
		SAMPLE_COMM_VO_StopLayer(VoLayer);
		SAMPLE_COMM_VO_StopDev(VoDev);
	}
	//Close vi ext chn
	if(HI_TRUE == bOpenViExt)
	{
		(HI_VOID)HI_MPI_VI_DisableChn(ViExtChn);
	}
	//Close vi
	if (HI_TRUE == bOpenVi)
	{
		SAMPLE_COMM_VI_StopVi(&(pstViVoConfig->stViConfig));
	}
	//Close sys
	SAMPLE_COMM_SYS_Exit();
}
Beispiel #3
0
/******************************************************************************
* function : Start BT1120 720P vi/vo/venc
******************************************************************************/
HI_S32 SAMPLE_COMM_IVE_BT1120_720P_PreView(SAMPLE_IVE_VI_VO_CONFIG_S *pstViVoConfig,
	HI_BOOL bOpenVi,HI_BOOL bOpenViExt,HI_BOOL bOpenVo,HI_BOOL bOpenVenc,HI_BOOL bOpenVpss,HI_U32 u32VpssChnNum)
{
    HI_U32 u32ViChnCnt = 1;
    VB_CONF_S stVbConf;
    VO_DEV VoDev = SAMPLE_VO_DEV_DSD0;
    VI_CHN ViChn = 0;
	VI_CHN ViExtChn = 1;
    VO_PUB_ATTR_S stVoPubAttr;
    SAMPLE_VO_MODE_E enVoMode = VO_MODE_1MUX;
    PIC_SIZE_E enPicSize = pstViVoConfig->enPicSize;
	VI_EXT_CHN_ATTR_S stExtChnAttr;
   
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    VO_LAYER VoLayer = 0;
    VO_VIDEO_LAYER_ATTR_S stLayerAttr;
	SAMPLE_VI_CONFIG_S *pstViConfig = &(pstViVoConfig->stViConfig);
	VENC_CHN VencChn = 0;
	HI_U32 u32ViDepth = 4;
	VI_CHN_ATTR_S stChnAttr;
	HI_U32 u32VpssGrpCnt = 1;	
	VPSS_CHN aVpssChn[2] = {VPSS_CHN0, VPSS_CHN3};
    VPSS_GRP_ATTR_S stVpssGrpAttr;
	SIZE_S astSize[2];
	
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm, enPicSize,
                            SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.u32MaxPoolCnt = 64;

    /*ddr0 video buffer*/
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 3;

	if ((HI_TRUE == bOpenViExt) || (HI_TRUE ==  bOpenVpss))
	{
		u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm,PIC_CIF, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
		stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
		stVbConf.astCommPool[1].u32BlkCnt = 3;
	}    
    // mpp system init.
    s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_Init fail,Error(%#x)\n", s32Ret);
        goto END_720P_0;
    }

	if (HI_TRUE == bOpenVi)
	{
		s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("SAMPLE_COMM_VI_StartVi fail,Error(%#x)\n",s32Ret);
			goto END_720P_0;
		}
		s32Ret = HI_MPI_VI_SetFrameDepth(ViChn,u32ViDepth);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}
		s32Ret = HI_MPI_VI_GetChnAttr(ViChn,&stChnAttr);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_GetChnAttr fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}
		//Set Vi frame rate,because vi from BT1120 is 720P@30
		stChnAttr.s32SrcFrameRate = 3;
		stChnAttr.s32DstFrameRate = 1;
		s32Ret = HI_MPI_VI_SetChnAttr(ViChn,&stChnAttr);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_SetChnAttr,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}

	}

	//Open vi ext chn
	if (HI_TRUE == bOpenViExt)
	{
	   stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT;
	   stExtChnAttr.s32BindChn = ViChn;
	   stExtChnAttr.stDestSize.u32Width = 352;
	   stExtChnAttr.stDestSize.u32Height = 288;
	   stExtChnAttr.s32DstFrameRate = -1;
	   stExtChnAttr.s32SrcFrameRate = -1;
	   stExtChnAttr.enCompressMode  = COMPRESS_MODE_NONE;
	   
	  s32Ret = HI_MPI_VI_SetExtChnAttr(ViExtChn, &stExtChnAttr);
	  if (HI_SUCCESS != s32Ret)
	  {
		  SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		  goto END_720P_1;
	  }
	  s32Ret = HI_MPI_VI_EnableChn(ViExtChn);
	  if (HI_SUCCESS != s32Ret)
	  {
		  SAMPLE_PRT("HI_MPI_VI_EnableChn fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		  goto END_720P_1;
	  }
	  s32Ret = HI_MPI_VI_SetFrameDepth(ViExtChn,u32ViDepth);
	  if (HI_SUCCESS != s32Ret)
	  {
		SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		goto END_720P_1;
	  }

	}
	//Open vo 
	if (HI_TRUE == bOpenVo)
	{
	    s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &stSize);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret);
	        goto END_720P_2;
	    }
	    stVoPubAttr.enIntfType = pstViVoConfig->enVoIntfType;
		//hi3518e Vo only suppurt pal
        //if(VO_INTF_BT1120 == pstViVoConfig->enVoIntfType)
        //{
        //    stVoPubAttr.enIntfSync = /*VO_OUTPUT_720P60*/VO_OUTPUT_1080P30;
        //}
        //       if(SAMPLE_VI_MODE_BT1120_1080P == pstViVoConfig->stViConfig.enViMode)
        //      {
        //          stVoPubAttr.enIntfSync = VO_OUTPUT_1080P30;
        //      }
        //else if(SAMPLE_VI_MODE_BT1120_720P == pstViVoConfig->stViConfig.enViMode)
        //      {
        //          stVoPubAttr.enIntfSync = VO_OUTPUT_720P60;
        //      }
        //   else
	    {
	        stVoPubAttr.enIntfSync = VO_OUTPUT_PAL;
	    }
	    stVoPubAttr.u32BgColor = 0x000000ff;
	    /* In HD, this item should be set to HI_FALSE */
	    s32Ret = SAMPLE_COMM_VO_StartDev(VoDev, &stVoPubAttr);
	    if (HI_SUCCESS != s32Ret)
	    {
	       SAMPLE_PRT("SAMPLE_COMM_VO_StartDevLayer fail,VoDev(%d),Error(%#x)!\n",VoDev,s32Ret);
	       goto END_720P_2;
	    }

	    stLayerAttr.bClusterMode = HI_FALSE;
		stLayerAttr.bDoubleFrame = HI_FALSE;
		stLayerAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	    memcpy(&stLayerAttr.stImageSize,&stSize,sizeof(stSize)); 

		stLayerAttr.u32DispFrmRt = 60 ;
		stLayerAttr.stDispRect.s32X = 0;
		stLayerAttr.stDispRect.s32Y = 0;
		if((stVoPubAttr.enIntfSync == VO_OUTPUT_720P60) || (stVoPubAttr.enIntfSync == VO_OUTPUT_1080P30))
	    {
	    	stLayerAttr.stDispRect.u32Width = stSize.u32Width;
	    	stLayerAttr.stDispRect.u32Height = stSize.u32Height;
	    }
	    else if(stVoPubAttr.enIntfSync == VO_OUTPUT_PAL)
	    {
	        stLayerAttr.stDispRect.u32Width = 720;
	    	stLayerAttr.stDispRect.u32Height = 576;
	    }     
	    s32Ret = SAMPLE_COMM_VO_StartLayer(VoLayer, &stLayerAttr, HI_TRUE);
		if (HI_SUCCESS != s32Ret)
		{		
			SAMPLE_PRT("SAMPLE_COMM_VO_StartLayer fail,VoLayer(%d),Error(%#x)\n",VoLayer,s32Ret);
			goto END_720P_3;
		}

	    s32Ret = SAMPLE_COMM_VO_StartChn(VoDev, enVoMode);
	    if (HI_SUCCESS != s32Ret)
	    {
	       SAMPLE_PRT("SAMPLE_COMM_VO_StartChn fail,VoDev(%d),Error(%#x)\n",VoDev,s32Ret);
	       goto END_720P_4;
	    }
	}

	if (HI_TRUE == bOpenVenc)
	{
		s32Ret = SAMPLE_COMM_VENC_Start(VencChn, PT_H264, pstViVoConfig->enNorm, enPicSize, SAMPLE_RC_CBR,0);
		if(s32Ret != HI_SUCCESS)
		{
			SAMPLE_PRT("SAMPLE_COMM_VENC_Start fail,VencChn(%d),Error(%#x)\n",VencChn,s32Ret);
			goto END_720P_5;
		}
         s32Ret = SAMPLE_COMM_VENC_StartGetStream(1);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("SAMPLE_COMM_VENC_StartGetStream fail,Error(%#x)\n",s32Ret);
            goto END_720P_6;
        }
	}
	if (HI_TRUE ==  bOpenVpss)
	{
		s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &astSize[0]);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret);
	        goto END_720P_6;
	    }
		astSize[1].u32Width = 352;
		astSize[1].u32Height = 288;
		SAMPLE_COMM_IVE_VpssGrpAttr(u32VpssGrpCnt, &stVpssGrpAttr, &stSize);
		s32Ret = SAMPLE_COMM_IVE_VpssStart(u32VpssGrpCnt, astSize, aVpssChn, u32VpssChnNum, &stVpssGrpAttr);
		if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_IVE_VpssStart fail,Error(%#x)\n",s32Ret);
	        goto END_720P_6;
	    }

	}
	return s32Ret;

//END_720P_7:
    //if (HI_TRUE == bOpenVpss)
    //{
    //	SAMPLE_COMM_IVE_StopVpss(u32VpssGrpCnt,u32VpssChnNum);
    //}

END_720P_6:
	if (HI_TRUE == bOpenVenc)
	{
		SAMPLE_COMM_VENC_Stop(VencChn);
	}
END_720P_5:
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopChn(VoDev, enVoMode);
	}
END_720P_4:   
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopLayer(VoLayer);
	}    
END_720P_3:
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopDev(VoDev);
	}    
END_720P_2:
	if(HI_TRUE == bOpenViExt)
	{
		(HI_VOID)HI_MPI_VI_DisableChn(ViExtChn);
	}
END_720P_1:
	if (HI_TRUE == bOpenVi)
	{
		SAMPLE_COMM_VI_StopVi(pstViConfig);
	}
END_720P_0:
    SAMPLE_COMM_SYS_Exit();

    return s32Ret;
}
Beispiel #4
0
/******************************************************************************
* function :  4D1 H264 encode
******************************************************************************/
HI_S32 SAMPLE_VENC_4D1_H264(HI_VOID)
{
    SAMPLE_VI_MODE_E enViMode = SAMPLE_VI_MODE_4_D1;

    HI_U32 u32ViChnCnt = 4;
    HI_S32 s32VpssGrpCnt = 4;
    PAYLOAD_TYPE_E enPayLoad[2]= {PT_H264, PT_H264};
    PIC_SIZE_E enSize[2] = {PIC_D1, PIC_CIF};
    
    VB_CONF_S stVbConf;
    VPSS_GRP VpssGrp;
    VPSS_CHN VpssChn;
    VPSS_GRP_ATTR_S stGrpAttr;
    VENC_GRP VencGrp;
    VENC_CHN VencChn;
    SAMPLE_RC_E enRcMode;
    
    HI_S32 i;
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    HI_CHAR ch;
    SIZE_S stSize;

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

    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                PIC_D1, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.u32MaxPoolCnt = 128;
    
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 6;
    memset(stVbConf.astCommPool[0].acMmzName,0,
        sizeof(stVbConf.astCommPool[0].acMmzName));

    /* hist buf*/
    stVbConf.astCommPool[1].u32BlkSize = (196*4);
    stVbConf.astCommPool[1].u32BlkCnt = u32ViChnCnt * 6;
    memset(stVbConf.astCommPool[1].acMmzName,0,
        sizeof(stVbConf.astCommPool[1].acMmzName));

    /******************************************
     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_8D1_0;
    }

    /******************************************
     step 3: start vi dev & chn to capture
    ******************************************/
    s32Ret = SAMPLE_COMM_VI_Start(enViMode, gs_enNorm);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("start vi failed!\n");
        goto END_VENC_8D1_0;
    }
    
    /******************************************
     step 4: start vpss and vi bind vpss
    ******************************************/
    s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, PIC_D1, &stSize);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
        goto END_VENC_8D1_0;
    }
    
    stGrpAttr.u32MaxW = stSize.u32Width;
    stGrpAttr.u32MaxH = stSize.u32Height;
    stGrpAttr.bDrEn = HI_FALSE;
    stGrpAttr.bDbEn = HI_FALSE;
    stGrpAttr.bIeEn = HI_TRUE;
    stGrpAttr.bNrEn = HI_TRUE;
    stGrpAttr.bHistEn = HI_TRUE;
    stGrpAttr.enDieMode = VPSS_DIE_MODE_AUTO;
    stGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT;

    s32Ret = SAMPLE_COMM_VPSS_Start(s32VpssGrpCnt, &stSize, VPSS_MAX_CHN_NUM,NULL);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("Start Vpss failed!\n");
        goto END_VENC_8D1_1;
    }

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

    /******************************************
     step 5: select rc mode
    ******************************************/
    while(1)
    {
        printf("please choose rc mode:\n"); 
        printf("\t0) CBR\n"); 
        printf("\t1) VBR\n"); 
        printf("\t2) FIXQP\n"); 
        ch = getchar();
        getchar();
        if ('0' == ch)
        {
            enRcMode = SAMPLE_RC_CBR;
            break;
        }
        else if ('1' == ch)
        {
            enRcMode = SAMPLE_RC_VBR;
            break;
        }
        else if ('2' == ch)
        {
            enRcMode = SAMPLE_RC_FIXQP;
            break;
        }
        else
        {
            printf("rc mode invaild! please try again.\n");
            continue;
        }
    }
    /******************************************
     step 5: start stream venc (big + little)
    ******************************************/
    for (i=0; i<u32ViChnCnt; i++)
    {
        /*** main stream **/
        VencGrp = i*2;
        VencChn = i*2;
        VpssGrp = i;
        s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, enPayLoad[0],\
                                       gs_enNorm, enSize[0], enRcMode);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("Start Venc failed!\n");
            goto END_VENC_8D1_2;
        }

        s32Ret = SAMPLE_COMM_VENC_BindVpss(VencGrp, VpssGrp, VPSS_BSTR_CHN);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("Start Venc failed!\n");
            goto END_VENC_8D1_3;
        }

        /*** Sub stream **/
        VencGrp ++;
        VencChn ++;
        s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, enPayLoad[1], \
                                        gs_enNorm, enSize[1], enRcMode);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("Start Venc failed!\n");
            goto END_VENC_8D1_3;
        }

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

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

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

    /******************************************
     step 7: exit process
    ******************************************/
    SAMPLE_COMM_VENC_StopGetStream();
    
END_VENC_8D1_3:
    for (i=0; i<u32ViChnCnt*2; i++)
    {
        VencGrp = i;
        VencChn = i;
        VpssGrp = i/2;
        VpssChn = (VpssGrp%2)?VPSS_PRE0_CHN:VPSS_BSTR_CHN;
        SAMPLE_COMM_VENC_UnBindVpss(VencGrp, VpssGrp, VpssChn);
        SAMPLE_COMM_VENC_Stop(VencGrp,VencChn);
    }
    SAMPLE_COMM_VI_UnBindVpss(enViMode);
END_VENC_8D1_2:	//vpss stop
    SAMPLE_COMM_VPSS_Stop(s32VpssGrpCnt, VPSS_MAX_CHN_NUM);
END_VENC_8D1_1:	//vi stop
    SAMPLE_COMM_VI_Stop(enViMode);
END_VENC_8D1_0:	//system exit
    SAMPLE_COMM_SYS_Exit();
    
    return s32Ret;
}
Beispiel #5
0
void SendVideoStream(int Sockfd)
{
	HI_S32 s32Ret;
	HI_S32 Vencfd, maxfd = 0;
	PAYLOAD_TYPE_E enPayLoad = PT_H264;
	SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR;
	struct timeval TimeoutVal;
	fd_set read_fds;
	int connfd;
	VENC_STREAM_S stStream;
	VENC_CHN_STAT_S stStat;
	HI_S32 i;
	int SendSockfd;

    struct sockaddr_in SendServaddr;

	SendSockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if (SendSockfd == -1)
	{
		perror("send socket error");
		exit(0);
	}
	memset(&SendServaddr, 0, sizeof(SendServaddr));
	SendServaddr.sin_family = AF_INET;
	SendServaddr.sin_addr.s_addr = inet_addr("10.1.2.60");
	SendServaddr.sin_port = htons(6666);

	while (!isThreadStop)
	{
#if 0
		if (!isChangePic)
		{
			connfd = accept(SendSockfd, NULL, NULL);
			printf("connect!\n");
		}
		isChangePic = HI_FALSE;
#endif
		s32Ret = SAMPLE_COMM_VENC_Start(SendVencGrp, SendVencChn, enPayLoad,
		                                gs_enNorm, enSize, enRcMode);
		if (HI_SUCCESS != s32Ret)
		{
			printf("SAMPLE_COMM_VENC_Start failed with err code %#x\n", s32Ret);
			continue;
		}
		s32Ret = SAMPLE_COMM_VENC_BindVpss(SendVencGrp, VpssGrp, VpssChn);
		if (HI_SUCCESS != s32Ret)
		{
			printf("SAMPLE_COMM_VENC_BindVpss failed with err code %#x\n", s32Ret);
			continue;
		}
		Vencfd = HI_MPI_VENC_GetFd(SendVencChn);
		if (Vencfd < 0)
		{
			printf("HI_MPI_VENC_GetFd faild with%#x!\n", Vencfd);
			return HI_FAILURE;
		}
		while (isSend)
		{

			FD_ZERO(&read_fds);
			FD_SET(Vencfd, &read_fds);
			TimeoutVal.tv_sec = 20000;
			TimeoutVal.tv_usec = 0;
			s32Ret = select(Vencfd + 1, &read_fds, NULL, NULL, &TimeoutVal);

			if (s32Ret < 0)
			{
				perror("select failed!\n");
				break;
			}
			else if (s32Ret == 0)
			{
				printf("get sendvenc stream time out,exit thread\n");
				continue;
			}
			else
			{
				if (FD_ISSET(Vencfd, &read_fds))
				{
					memset(&stStream, 0, sizeof(stStream));
					s32Ret = HI_MPI_VENC_Query(SendVencChn, &stStat);
					if (HI_SUCCESS != s32Ret)
					{
						printf("HI_MPI_VENC_Query failed with err code %#x!\n", s32Ret);
						break;
					}
					stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
					if (NULL == stStream.pstPack)
					{
						printf("malloc stream pack failed!\n");
						break;
					}
					stStream.u32PackCount = stStat.u32CurPacks;
					s32Ret = HI_MPI_VENC_GetStream(SendVencChn, &stStream, HI_TRUE);
					if (HI_SUCCESS != s32Ret)
					{
						free(stStream.pstPack);
						stStream.pstPack = NULL;
						printf("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
						break;
					}
					for (i = 0; i < stStream.u32PackCount; i++)
					{
						//write(connfd, stStream.pstPack[i].pu8Addr[0],
						  //    stStream.pstPack[i].u32Len[0]);

                          sendto(SendSockfd,stStream.pstPack[i].pu8Addr[0],
                                  stStream.pstPack[i].u32Len[0],0,
                                  (struct sockaddr*)&SendServaddr,
                                  sizeof(SendServaddr));


						if (stStream.pstPack[i].u32Len[1] > 0)
						{
							//write(connfd, stStream.pstPack[i].pu8Addr[1],
							  //    stStream.pstPack[i].u32Len[1]);

                          sendto(SendSockfd,stStream.pstPack[i].pu8Addr[1],
                                  stStream.pstPack[i].u32Len[1],0,
                                  (struct sockaddr*)&SendServaddr,
                                  sizeof(SendServaddr));

						}
					}
					s32Ret = HI_MPI_VENC_ReleaseStream(SendVencChn, &stStream);
					if (HI_SUCCESS != s32Ret)
					{
						free(stStream.pstPack);
						stStream.pstPack = NULL;
						break;
					}
					free(stStream.pstPack);
					stStream.pstPack = NULL;
				}
			}
		}
		SAMPLE_COMM_VENC_StopGetStream();
		SAMPLE_COMM_VENC_UnBindVpss(SendVencGrp, VpssGrp, VpssChn);
		SAMPLE_COMM_VENC_Stop(SendVencGrp, SendVencChn);
		usleep(100);
	}
}