示例#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;
}
示例#2
0
/*****************************************************************************
 Prototype       : HI_MPI_ISP_SetDCFInfo
 Description     : set dcf info to isp firmware
 Input           : ISP_DCF_S *pstIspDCF
 Output          : None
 Return Value    :
 Process         :
 Note            :

  History
  1.Date         : 2014/6/13
    Author       : z00183560
    Modification : Created function

*****************************************************************************/
HI_S32 HI_MPI_ISP_SetDCFInfo(const ISP_DCF_INFO_S *pstIspDCF)
{
    ISP_DEV IspDev = 0;
    ISP_CTX_S *pstIspCtx = HI_NULL;
    HI_BOOL bTempMap = HI_FALSE;

    ISP_GET_CTX(IspDev, pstIspCtx);
    ISP_CHECK_POINTER(pstIspCtx);
    ISP_CHECK_POINTER(pstIspDCF);

    if (HI_NULL == pstIspCtx->stUpdateInfoCtrl.u32UpdateInfoPhyaddr)
    {
        pstIspCtx->stUpdateInfoCtrl.u32UpdateInfoPhyaddr = hi_ext_system_update_info_phyaddr_read();

        pstIspCtx->stUpdateInfoCtrl.pstIspUpdateInfo = HI_MPI_SYS_MmapCache(pstIspCtx->stUpdateInfoCtrl.u32UpdateInfoPhyaddr,
                                                            (sizeof(ISP_UPDATE_INFO_S) + sizeof(ISP_DCF_CONST_INFO_S)));
        if (HI_NULL == pstIspCtx->stUpdateInfoCtrl.pstIspUpdateInfo)
        {
            printf("set dcf info mmap failed!\n");
            return HI_ERR_ISP_NOMEM;
        }

        pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo = (ISP_DCF_CONST_INFO_S*)(pstIspCtx->stUpdateInfoCtrl.pstIspUpdateInfo + 1);

        bTempMap = HI_TRUE;
    }

    memcpy(pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo,
              pstIspDCF, sizeof(HI_U8)*DCF_DRSCRIPTION_LENGTH*4);

    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u32FNumber              = pstIspDCF->u32FNumber;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u32MaxApertureValue     = pstIspDCF->u32MaxApertureValue;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8LightSource           = pstIspDCF->u8LightSource;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u32FocalLength          = pstIspDCF->u32FocalLength;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8SceneType             = pstIspDCF->u8SceneType;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8CustomRendered        = pstIspDCF->u8CustomRendered;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8FocalLengthIn35mmFilm = pstIspDCF->u8FocalLengthIn35mmFilm;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8SceneCaptureType      = pstIspDCF->u8SceneCaptureType;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8GainControl           = pstIspDCF->u8GainControl;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8Contrast              = pstIspDCF->u8Contrast;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8Saturation            = pstIspDCF->u8Saturation;
    pstIspCtx->stUpdateInfoCtrl.pstIspDCFConstInfo->u8Sharpness             = pstIspDCF->u8Sharpness;

    if (bTempMap)
    {
        HI_MPI_SYS_Munmap(pstIspCtx->stUpdateInfoCtrl.pstIspUpdateInfo,
                             (sizeof(ISP_UPDATE_INFO_S) + sizeof (ISP_DCF_CONST_INFO_S)));

        pstIspCtx->stUpdateInfoCtrl.u32UpdateInfoPhyaddr = HI_NULL;
    }

    return HI_SUCCESS;
}
示例#3
0
HI_S32 ISP_DbgRunBgn(ISP_DBG_CTRL_S *pstDbg, HI_U32 u32FrmCnt)
{
    //ISP_DBG_ATTR_S   *pstDbgAttr = HI_NULL;
    ISP_DBG_STATUS_S *pstDbgStatus = HI_NULL;

    if (!pstDbg->bDebugEn)
    {
        if (HI_NULL != pstDbg->pstDbgAttr)
        {
            HI_MPI_SYS_Munmap(pstDbg->pstDbgAttr, pstDbg->u32Size);
            pstDbg->pstDbgAttr = HI_NULL;
            pstDbg->pstDbgStatus = HI_NULL;
        }
        return HI_SUCCESS;
    }

    if ((pstDbg->bDebugEn) && (HI_NULL == pstDbg->pstDbgAttr))
    {
        pstDbg->pstDbgAttr = (ISP_DBG_ATTR_S *)HI_MPI_SYS_Mmap(
            pstDbg->u32PhyAddr, pstDbg->u32Size);
        if (HI_NULL == pstDbg->pstDbgAttr)
        {
            printf("isp map debug buf failed!\n");
            return HI_FAILURE;
        }
        pstDbg->pstDbgStatus = (ISP_DBG_STATUS_S *)(pstDbg->pstDbgAttr + 1);

        //pstDbgAttr = pstDbg->pstDbgAttr;
        /* ------------- record attr ------------------ */
        
    }

    pstDbgStatus = pstDbg->pstDbgStatus + (u32FrmCnt % DIV_0_TO_1(pstDbg->u32Depth));
    
    pstDbgStatus->u32FrmNumBgn  = u32FrmCnt;
    
    return HI_SUCCESS;
}
示例#4
0
/* sp420 转存为 p420 ; sp422 转存为 p422  */
void sample_yuv_dump(VIDEO_FRAME_S * pVBuf, FILE *pfd)
{
    unsigned int w, h;
    char * pVBufVirt_Y;
    char * pVBufVirt_C;
    char * pMemContent;
    unsigned char TmpBuff[2000];                //如果这个值太小,图像很大的话存不了
    HI_U32 phy_addr,size;
	HI_CHAR *pUserPageAddr[2];
    PIXEL_FORMAT_E  enPixelFormat = pVBuf->enPixelFormat;
    HI_U32 u32UvHeight;/* 存为planar 格式时的UV分量的高度 */
    
    if (PIXEL_FORMAT_YUV_SEMIPLANAR_420 == enPixelFormat)
    {
        size = (pVBuf->u32Stride[0])*(pVBuf->u32Height)*3/2;    
        u32UvHeight = pVBuf->u32Height/2;
    }
    else
    {
        size = (pVBuf->u32Stride[0])*(pVBuf->u32Height)*2;   
        u32UvHeight = pVBuf->u32Height;
    }

    phy_addr = pVBuf->u32PhyAddr[0];

    //printf("phy_addr:%x, size:%d\n", phy_addr, size);
    pUserPageAddr[0] = (HI_CHAR *) HI_MPI_SYS_Mmap(phy_addr, size);	
    if (NULL == pUserPageAddr[0])
    {
        return;
    }
    //printf("stride: %d,%d\n",pVBuf->u32Stride[0],pVBuf->u32Stride[1] );
    
	pVBufVirt_Y = pUserPageAddr[0]; 
	pVBufVirt_C = pVBufVirt_Y + (pVBuf->u32Stride[0])*(pVBuf->u32Height);

    /* save Y ----------------------------------------------------------------*/
    fprintf(stderr, "saving......Y......");
    fflush(stderr);
    for(h=0; h<pVBuf->u32Height; h++)
    {
        pMemContent = pVBufVirt_Y + h*pVBuf->u32Stride[0];
        fwrite(pMemContent, pVBuf->u32Width, 1, pfd);
    }
    fflush(pfd);
    

    /* save U ----------------------------------------------------------------*/
    fprintf(stderr, "U......");
    fflush(stderr);
    for(h=0; h<u32UvHeight; h++)
    {
        pMemContent = pVBufVirt_C + h*pVBuf->u32Stride[1];

        pMemContent += 1;

        for(w=0; w<pVBuf->u32Width/2; w++)
        {
            TmpBuff[w] = *pMemContent;
            pMemContent += 2;
        }
        fwrite(TmpBuff, pVBuf->u32Width/2, 1, pfd);
    }
    fflush(pfd);

    /* save V ----------------------------------------------------------------*/
    fprintf(stderr, "V......");
    fflush(stderr);
    for(h=0; h<u32UvHeight; h++)    
    {
        pMemContent = pVBufVirt_C + h*pVBuf->u32Stride[1];

        for(w=0; w<pVBuf->u32Width/2; w++)
        {
            TmpBuff[w] = *pMemContent;
            pMemContent += 2;
        }
        fwrite(TmpBuff, pVBuf->u32Width/2, 1, pfd);
    }
    fflush(pfd);
    
    fprintf(stderr, "done %d!\n", pVBuf->u32TimeRef);
    fflush(stderr);
    
    HI_MPI_SYS_Munmap(pUserPageAddr[0], size);    
}
示例#5
0
int main(int argc, char const *argv[])
{
    VI_EXT_CHN_ATTR_S stExtChnAttr;
    VB_BLK hBlock;
    VB_POOL hPool = VB_INVALID_POOLID;
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize, u32DstBlkSize;
    VIDEO_FRAME_INFO_S FrameInfo;
    IVE_HANDLE IveHandle;
    IVE_SRC_IMAGE_S stSrc;
    IVE_DST_IMAGE_S stDst;
    IVE_CSC_CTRL_S stCscCtrl;
    HI_BOOL bInstant = HI_TRUE;
    HI_BOOL bFinish;
    IplImage *iplImage;
    FILE *fp,*fp2;

    int k=1;
#if 0
    memset(&stVbConf, 0, sizeof(VB_CONF_S));
    stVbConf.u32MaxPoolCnt = 128;
    SAMPLE_COMM_VI_GetSizeBySensor(&enSize);
    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = 12;

	s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
	if (HI_SUCCESS != s32Ret)
	{
		printf("system init failed with err code %#x!\n", s32Ret );
	}

	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)
	{
		printf("start vi failed with err code %#x!\n", s32Ret);
	//	goto END_1;
	}
#endif
    iplImage = cvCreateImageHeader(cvSize(WIDTH,HEIGHT), IPL_DEPTH_8U, 3);

	stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stExtChnAttr.s32BindChn = ViChn;
	stExtChnAttr.stDestSize.u32Width = WIDTH;
	stExtChnAttr.stDestSize.u32Height = HEIGHT;
	stExtChnAttr.s32DstFrameRate = -1;
	stExtChnAttr.s32SrcFrameRate = -1;
	stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE;
    HI_MPI_VI_DisableChn(ExtChn);
	s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret);
		return -1;
	}
	s32Ret = HI_MPI_VI_SetFrameDepth(ExtChn, 1);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret);
		return -1;
	}
    stSrc.enType = IVE_IMAGE_TYPE_YUV420SP;
    //stDst.enType = IVE_IMAGE_TYPE_U8C3_PLANAR;
    stDst.enType = IVE_IMAGE_TYPE_U8C3_PACKAGE;
    stCscCtrl.enMode = IVE_CSC_MODE_PIC_BT709_YUV2RGB;

#if 1
	s32Ret = HI_MPI_VI_EnableChn(ExtChn);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret);
		return -1;
	}
#endif
    printf("begin\n");
    det_t *pdet = det_open("bd_detect_trace.config");
    while(k)
    {
        s32Ret = HI_MPI_VI_GetFrame(ExtChn, &FrameInfo, -1);
        if(HI_SUCCESS != s32Ret)
        {
            printf("HI_MPI_VI_GetFrame failed with err code %#x!\n",s32Ret);
        }
        printf("get frame!\n");

        u32DstBlkSize = FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height * 3;
        s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&stDst.u32PhyAddr[0],(void**) &stDst.pu8VirAddr[0], "user", HI_NULL, u32DstBlkSize);
        HI_MPI_SYS_MmzFlushCache(stDst.u32PhyAddr[0], (void *)stDst.pu8VirAddr[0], u32DstBlkSize);
#if 0
        stDst.u32PhyAddr[1] = stDst.u32PhyAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stDst.u32PhyAddr[2] = stDst.u32PhyAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;

        stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize);
        stDst.pu8VirAddr[1] = stDst.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stDst.pu8VirAddr[2] = stDst.pu8VirAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;

        stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Stride[2] = FrameInfo.stVFrame.u32Stride[0];

        stDst.u16Width = FrameInfo.stVFrame.u32Width;
        stDst.u16Height = FrameInfo.stVFrame.u32Height;
#endif
#if 1
        stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize);
        stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Width = FrameInfo.stVFrame.u32Width;
        stDst.u16Height = FrameInfo.stVFrame.u32Height;
#endif

        stSrc.u32PhyAddr[0] = FrameInfo.stVFrame.u32PhyAddr[0];
        stSrc.u32PhyAddr[1] = FrameInfo.stVFrame.u32PhyAddr[1];
        stSrc.u32PhyAddr[2] = FrameInfo.stVFrame.u32PhyAddr[2];

        stSrc.pu8VirAddr[0] = (HI_U8*)HI_MPI_SYS_Mmap(FrameInfo.stVFrame.u32PhyAddr[0], u32DstBlkSize / 2);
        stSrc.pu8VirAddr[1] = stSrc.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stSrc.pu8VirAddr[2] = stSrc.pu8VirAddr[1] + 1;


        stSrc.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0];
        stSrc.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stSrc.u16Stride[2] = 0;

        stSrc.u16Width = FrameInfo.stVFrame.u32Width;
        stSrc.u16Height = FrameInfo.stVFrame.u32Height;

#if 0
        for(k = 0; k < 720 * 576 * 3 / 2;k++)
            *(stSrc.pu8VirAddr[0] + k) = 130;
        k = 0;
#endif
        s32Ret = HI_MPI_IVE_CSC(&IveHandle, &stSrc, &stDst, &stCscCtrl, bInstant);
        if(s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_IVE_CSC failed with error code %#x\n",s32Ret);
            continue;
        }
        s32Ret = HI_MPI_IVE_Query(IveHandle, &bFinish, HI_TRUE);
        if(s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_IVE_Query failed with error code %#x\n",s32Ret);
            continue;
        }
#if 0
        fp = fopen("image.rgb","wb");
        fwrite(stDst.pu8VirAddr[0], WIDTH * HEIGHT * 3, 1, fp);
        fclose(fp);

        fp2 = fopen("image2.yuv","wb");
        fwrite(stSrc.pu8VirAddr[0], WIDTH * HEIGHT * 3 / 2, 1, fp2);
        fclose(fp2);
#endif
        //printf("u16Width:%d,u16Height:%d\n",stDst.u16Width,stDst.u16Height);
        //printf("widthStep:%d\n",iplImage->widthStep);
        //cvSetData(iplImage, stDst.pu8VirAddr[0], iplImage->widthStep);
        //cvSaveImage("saveImage.jpg",iplImage);
        char *str = det_detect(pdet, HEIGHT, WIDTH, (char *)stDst.pu8VirAddr[0]);
        printf("%s\n",str);
        HI_MPI_SYS_Munmap(stDst.pu8VirAddr[0], u32DstBlkSize);
        HI_MPI_SYS_Munmap(stSrc.pu8VirAddr[0], u32DstBlkSize / 2);
        HI_MPI_SYS_MmzFree(stDst.u32PhyAddr[0], NULL);
        HI_MPI_VI_ReleaseFrame(ExtChn, &FrameInfo);
    }
    det_close(pdet);
}
示例#6
0
static void IMP_HiImageConvertToYUV422Image(VIDEO_FRAME_S *pVBuf, YUV_IMAGE422_S *pImage)
{
    IMP_S32 w, h;
    IMP_U8 * pVBufVirt_Y;
    IMP_U8 * pVBufVirt_C;
    IMP_U8 * pMemContent;
    IMP_U8 *pY = pImage->pu8Y;
    IMP_U8 *pU = pImage->pu8U;
    IMP_U8 *pV = pImage->pu8V;
    IMP_U8 TmpBuff[1024];
    //IMP_S32 w = 0;
    HI_U32 phy_addr,size;
	HI_CHAR *pUserPageAddr[2];
    PIXEL_FORMAT_E  enPixelFormat = pVBuf->enPixelFormat;
    HI_U32 u32UvHeight;

    pImage->u32Time = pVBuf->u64pts/(40*1000);

    if (PIXEL_FORMAT_YUV_SEMIPLANAR_420 == enPixelFormat)
    {
        size = (pVBuf->u32Stride[0])*(pVBuf->u32Height)*3/2;
        u32UvHeight = pVBuf->u32Height/2;
    }
    else
    {
        size = (pVBuf->u32Stride[0])*(pVBuf->u32Height)*2;
        u32UvHeight = pVBuf->u32Height;
    }

    phy_addr = pVBuf->u32PhyAddr[0];

    //printf("phy_addr:%x, size:%d\n", phy_addr, size);
    pUserPageAddr[0] = (HI_U8 *) HI_MPI_SYS_Mmap(phy_addr, size);
    if (NULL == pUserPageAddr[0])
    {
        return;
    }

	pVBufVirt_Y = pUserPageAddr[0];
	pVBufVirt_C = pVBufVirt_Y + (pVBuf->u32Stride[0])*(pVBuf->u32Height);
  //  printf("u32Height:%d:::::pVBuf->u32Width:%d\n",pVBuf->u32Height,pVBuf->u32Width);
    /* Y ----------------------------------------------------------------*/
//    printf("width:%d####height:%d\n",pVBuf->u32Stride[0],pVBuf->u32Height);
    if(pVBuf->u32Stride[0] == 352)
    {

#ifdef PEA_QCIF
        for(h=0; h<pVBuf->u32Height/2; h++)
        {
            pMemContent = pVBufVirt_Y + 2*h*pVBuf->u32Stride[0];
            for( w=0;w<(pVBuf->u32Width/2);w++ )
            {
                TmpBuff[w] = (IMP_U8)(*pMemContent);
                pMemContent+=2;
            }
            memcpy(pImage->pu8Y,TmpBuff,pVBuf->u32Width/2);
            pImage->pu8Y += pVBuf->u32Width/2;
        }
#else
        for(h=0; h<pVBuf->u32Height; h++)
        {
            pMemContent = pVBufVirt_Y + h*pVBuf->u32Stride[0];
            memcpy(pImage->pu8Y,pMemContent,pVBuf->u32Width);
            pImage->pu8Y += pVBuf->u32Width;
        }
#endif
        pImage->pu8Y = pY;

    }
    else if( pVBuf->u32Stride[0] == 704)
    {
        //printf("pVBuf->u32Height%d #### pVBuf->u32Width%d\n",pVBuf->u32Height,pVBuf->u32Width);
#ifdef PEA_QCIF
        for(h=0; h<(pVBuf->u32Height/4); h++)
        {
            pMemContent = pVBufVirt_Y + 4*h*(pVBuf->u32Stride[0]);
            for( w=0;w<(pVBuf->u32Width/4);w++ )
            {
                TmpBuff[w] = (IMP_U8)(*pMemContent);
                pMemContent+=4;
            }
            memcpy(pImage->pu8Y,TmpBuff,pVBuf->u32Width/4);
            pImage->pu8Y += pVBuf->u32Width/4;
        }
#else
        for(h=0; h<(pVBuf->u32Height/2); h++)
        {
            pMemContent = pVBufVirt_Y + 2*h*(pVBuf->u32Stride[0]);
            for( w=0;w<(pVBuf->u32Width/2);w++ )
            {
                TmpBuff[w] = (IMP_U8)(*pMemContent);
                pMemContent+=2;
            }
            memcpy(pImage->pu8Y,TmpBuff,pVBuf->u32Width/2);
            pImage->pu8Y += pVBuf->u32Width/2;
        }
#endif
        pImage->pu8Y = pY;
    }
    HI_MPI_SYS_Munmap(pUserPageAddr[0], size);
}
/******************************************************************************
* function : Get from YUV
******************************************************************************/
HI_S32 SAMPLE_COMM_VI_GetVFrameFromYUV(FILE *pYUVFile, HI_U32 u32Width, HI_U32 u32Height,HI_U32 u32Stride, VIDEO_FRAME_INFO_S *pstVFrameInfo)
{
    HI_U32             u32LStride;
    HI_U32             u32CStride;
    HI_U32             u32LumaSize;
    HI_U32             u32ChrmSize;
    HI_U32             u32Size;
    VB_BLK VbBlk;
    HI_U32 u32PhyAddr;
    HI_U8 *pVirAddr;

    u32LStride  = u32Stride;
    u32CStride  = u32Stride;

    u32LumaSize = (u32LStride * u32Height);
    u32ChrmSize = (u32CStride * u32Height) >> 2;/* YUV 420 */
    u32Size = u32LumaSize + (u32ChrmSize << 1);

    /* alloc video buffer block ---------------------------------------------------------- */
    VbBlk = HI_MPI_VB_GetBlock(VB_INVALID_POOLID, u32Size, NULL);
    if (VB_INVALID_HANDLE == VbBlk)
    {
        SAMPLE_PRT("HI_MPI_VB_GetBlock err! size:%d\n",u32Size);
        return -1;
    }
    u32PhyAddr = HI_MPI_VB_Handle2PhysAddr(VbBlk);
    if (0 == u32PhyAddr)
    {
        return -1;
    }

    pVirAddr = (HI_U8 *) HI_MPI_SYS_Mmap(u32PhyAddr, u32Size);
    if (NULL == pVirAddr)
    {
        return -1;
    }

    pstVFrameInfo->u32PoolId = HI_MPI_VB_Handle2PoolId(VbBlk);
    if (VB_INVALID_POOLID == pstVFrameInfo->u32PoolId)
    {
        return -1;
    }
    SAMPLE_PRT("pool id :%d, phyAddr:%x,virAddr:%x\n" ,pstVFrameInfo->u32PoolId,u32PhyAddr,(int)pVirAddr);

    pstVFrameInfo->stVFrame.u32PhyAddr[0] = u32PhyAddr;
    pstVFrameInfo->stVFrame.u32PhyAddr[1] = pstVFrameInfo->stVFrame.u32PhyAddr[0] + u32LumaSize;
    pstVFrameInfo->stVFrame.u32PhyAddr[2] = pstVFrameInfo->stVFrame.u32PhyAddr[1] + u32ChrmSize;

    pstVFrameInfo->stVFrame.pVirAddr[0] = pVirAddr;
    pstVFrameInfo->stVFrame.pVirAddr[1] = pstVFrameInfo->stVFrame.pVirAddr[0] + u32LumaSize;
    pstVFrameInfo->stVFrame.pVirAddr[2] = pstVFrameInfo->stVFrame.pVirAddr[1] + u32ChrmSize;

    pstVFrameInfo->stVFrame.u32Width  = u32Width;
    pstVFrameInfo->stVFrame.u32Height = u32Height;
    pstVFrameInfo->stVFrame.u32Stride[0] = u32LStride;
    pstVFrameInfo->stVFrame.u32Stride[1] = u32CStride;
    pstVFrameInfo->stVFrame.u32Stride[2] = u32CStride;
    pstVFrameInfo->stVFrame.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
    pstVFrameInfo->stVFrame.u32Field = VIDEO_FIELD_INTERLACED;/* Intelaced D1,otherwise VIDEO_FIELD_FRAME */

    /* read Y U V data from file to the addr ----------------------------------------------*/
    SAMPLE_COMM_VI_ReadFrame(pYUVFile, pstVFrameInfo->stVFrame.pVirAddr[0],
       pstVFrameInfo->stVFrame.pVirAddr[1], pstVFrameInfo->stVFrame.pVirAddr[2],
       pstVFrameInfo->stVFrame.u32Width, pstVFrameInfo->stVFrame.u32Height,
       pstVFrameInfo->stVFrame.u32Stride[0], pstVFrameInfo->stVFrame.u32Stride[1] >> 1 );

    /* convert planar YUV420 to sem-planar YUV420 -----------------------------------------*/
    SAMPLE_COMM_VI_PlanToSemi(pstVFrameInfo->stVFrame.pVirAddr[0], pstVFrameInfo->stVFrame.u32Stride[0],
      pstVFrameInfo->stVFrame.pVirAddr[1], pstVFrameInfo->stVFrame.u32Stride[1],
      pstVFrameInfo->stVFrame.pVirAddr[2], pstVFrameInfo->stVFrame.u32Stride[1],
      pstVFrameInfo->stVFrame.u32Width, pstVFrameInfo->stVFrame.u32Height);

    HI_MPI_SYS_Munmap(pVirAddr, u32Size);
    return 0;
}
示例#8
0
static int vin_capture(int vin, FILE* bitmap_stream)
{
	int ret = 0;
	int api_ret = SDK_FAILURE;
	if(vin < HI3520A_VIN_CH_BACKLOG_REF){
		int frame_depth = 0;
		VIDEO_FRAME_INFO_S video_frame_info;
		

		SOC_CHECK(HI_MPI_VI_GetFrameDepth(vin, &frame_depth));
		if(0 == frame_depth){
			HI_MPI_VI_SetFrameDepth(vin, 1);
		}

		if(HI_SUCCESS == HI_MPI_VI_GetFrame(vin, &video_frame_info)){
			if(PIXEL_FORMAT_YUV_SEMIPLANAR_420 == video_frame_info.stVFrame.enPixelFormat){
				int i = 0, ii = 0;
				int const width = video_frame_info.stVFrame.u32Width;
				int const height = video_frame_info.stVFrame.u32Height;
				size_t const stride = video_frame_info.stVFrame.u32Stride[0];
				size_t const yuv420_size = stride * height * 3 / 2;
				const uint8_t* yuv420_data = HI_MPI_SYS_Mmap(video_frame_info.stVFrame.u32PhyAddr[0], yuv420_size);
				// allocate the bitmap data
				size_t bitmap24_size = width * height * 3;
				uint8_t* bitmap24_data = alloca(bitmap24_size);
				uint8_t* bitmap24_pixel = bitmap24_data;

				SOC_TRACE("Frame(%d) [%dx%d] stride %d", vin, width, height, stride);
				
				if(yuv420_data){
					int y, u, v, yy, vr, ug, vg, ub;
					int r, g, b;
					const uint8_t *py = (uint8_t*)(yuv420_data);
					const uint8_t *puv = (uint8_t*)(py + width * height);

					// yuv420 to rgb888
					for(i = 0; i < height; ++i){
						for(ii = 0; ii < width; ++ii){
							y = py[0];
							yy = y * 256;
							
							u = puv[1] - 128;
							ug = 88 * u;
							ub = 454 * u;

							v = puv[0] - 128;
							vg = 183 * v;
							vr = 359 * v;

							///////////////////////////////////
							// convert
							r = (yy + vr) >> 8;
							g = (yy - ug - vg) >> 8;
							b = (yy + ub) >> 8;

							if(r < 0){
								r = 0;
							}
							if(r > 255){
								r = 255;
							}
							if(g < 0){
								g = 0;
							}
							if(g > 255){
								g = 255;
							}
							if(b < 0){
								b = 0;
							}
							if(b > 255){
								b = 255;
							}

							*bitmap24_pixel++ = (uint8_t)b;
							*bitmap24_pixel++ = (uint8_t)g;
							*bitmap24_pixel++ = (uint8_t)r;

							//SOC_TRACE("RGB[%3d,%3d,%3d] @ (%3d,%3d)", r, g, b, ii, i);

							///////////////////////////////////
							++py;
							if(0 != (ii % 2)){
								// even
								puv += 2;
							}
						}

						if(0 != (i % 2)){
							// try twice
							puv -= width;
						}
					}
					SOC_CHECK(HI_MPI_SYS_Munmap(yuv420_data, yuv420_size));

					if(0 == fseek(bitmap_stream, 0, SEEK_SET)){
						

						BIT_MAP_FILE_HEADER_t bmp_header;
						memset(&bmp_header, 0, sizeof(bmp_header));

						bmp_header.type[0] = 'B';
						bmp_header.type[1] = 'M';
						bmp_header.file_size = sizeof(bmp_header) + bitmap24_size;
						bmp_header.reserved_zero = 0;
						bmp_header.off_bits = sizeof(bmp_header);
						bmp_header.info_size = 40;
						bmp_header.width = width;
						bmp_header.height = height;
						bmp_header.planes = 1;
						bmp_header.bit_count = 24;
						bmp_header.compression = 0;
						bmp_header.size_image = bitmap24_size;
						bmp_header.xpels_per_meter = 0;
						bmp_header.ypels_per_meter = 0;
						bmp_header.clr_used = 0;
						bmp_header.clr_important = 0;

						fwrite(&bmp_header, 1, sizeof(bmp_header), bitmap_stream);
						for(i = 0; i < height; ++i){
							void* bitmap_offset = bitmap24_data + (height - i - 1) * width * 3;
							fwrite(bitmap_offset, 1, width * 3, bitmap_stream);
						}
						
						api_ret = SDK_SUCCESS;
					}
				}
			}
			SOC_CHECK(HI_MPI_VI_ReleaseFrame(vin, &video_frame_info));
		}
示例#9
0
文件: b.c 项目: thatking/hi3516c
void AnalyzePic()
{
	HI_U32 s32Ret;
	VIDEO_FRAME_INFO_S FrameInfoA;
	struct timeval ustime;
	time_t timep;
	int fd;
	struct termios options;

	getCoord();
	getLRPoi();
	getFLenformfile();
    int flag = 0;

	JSSetparam(X1, Y1, X2, Y2);

    //FILE *fb = fopen("/app/a.log","w+");
    //FILE *fc = fopen("/app/b.log","w+");

	while (1)
	{
		while (analyzeStart)
		{
			//获取图像帧
		//	time(&timep);
			//gettimeofday(&ustime,NULL);
			//printf("%ld\n",((long)ustime.tv_sec)*1000+(long)ustime.tv_usec/1000);
			// printf("%ld\n",timep);
			char *pImg;
			int size;
			char str1[20] = {};
			char num_str[4] = {};
			short YPoi = 0;
			char* str;
			s32Ret = HI_MPI_VI_GetFrameTimeOut(ExtChn, &FrameInfoA, 0);
			if (HI_SUCCESS != s32Ret)
			{
				printf("HI_MPI_VI_GetFrameTimeOut faileded with err code %#x!\n", s32Ret);
			}
			//分析图片
			size = FrameInfoA.stVFrame.u32Stride[0] * FrameInfoA.stVFrame.u32Height;
			pImg = (char*)HI_MPI_SYS_Mmap(FrameInfoA.stVFrame.u32PhyAddr[0], size);
			//printf("%s\n",JSMyTest(pImg));
			str = JSMyTest(pImg, str1);
			if (str != NULL)
			{
                //printf("%s\n", str);
				//fprintf(fc,"%s\n", str);
                //fflush(fc);
				strncpy(num_str, str, strstr(str, ",") - str);
				//YPoi = CalAngle(atoi(num_str));
				//YPoi = -233 + 670 * (((X2 - X1) * (atoi(num_str)) / 100 + X1) / 720.0);
				//if (atoi(num_str) > 0 )
				if (atoi(str) > 0 )
				{
					//printf("LPoi=%d,RPoi=%d,RPoi-LPoi:%d\n",LPoi,RPoi,RPoi-LPoi);
					YPoi = (short)LPoi + ((short)RPoi - (short)LPoi) * (((X2 - X1) * (atoi(num_str)) / 100 + X1) / 720.0);
			    	//fprintf(fb,"%d\n", YPoi);
                    //fflush(fb);
					SetPanTiltPoi(YSpeed, ZSpeed, YPoi, 0);
                    if(flag == 1)
                    {
                        SetPanTiltFLen(FLen);
                        flag = 0;
                    }
                    time(&timep);
				}
                else
                {
			        if(time(NULL) - timep > 5)
                    {
                        SetPanTiltFLen(0);
                        SetPanTiltPoi(0x99,0x99,0,0);
                        flag = 1;
                    }

                }
			}
			HI_MPI_SYS_Munmap(pImg, size);
			HI_MPI_VI_ReleaseFrame(ExtChn, &FrameInfoA);
//            usleep(50);
			//printf("============================================\n");
		}

	}
}