Beispiel #1
0
static int _mem_free(MEM_T *_mem)
{
    MEM_T temp = {0};
    memset(&temp,0,sizeof(MEM_T));
    temp.phy_addr = _mem->phy_addr;
    temp.vir_addr = _mem->vir_addr;
    _mem->vir_addr = NULL;
	_mem->phy_addr = 0;
    _mem->size = 0;
    HI_MPI_SYS_MmzFree(temp.phy_addr, temp.vir_addr);
	_mem = NULL;
	return 0;
}
Beispiel #2
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);
}
HI_S32 TDE_DrawGraphicSample()
{
    HI_U32 u32Size;
    HI_S32 s32Fd;
    HI_U32 u32Times;
    HI_U8* pu8Screen;
    HI_U8* pu8BackGroundVir;

    HI_U32 u32PhyAddr;
    HI_S32 s32Ret = -1;
    HI_U32 i = 0;
    HI_BOOL bShow;
    HIFB_ALPHA_S stAlpha = {0};

    struct fb_fix_screeninfo stFixInfo;
    struct fb_var_screeninfo stVarInfo;
    struct fb_bitfield stR32 = {10, 5, 0};
    struct fb_bitfield stG32 = {5, 5, 0};
    struct fb_bitfield stB32 = {0, 5, 0};
    struct fb_bitfield stA32 = {15, 1, 0};

    /* 1. open tde device */
    HI_TDE2_Open();

    /* 2. framebuffer operation */
    s32Fd = open("/dev/fb0", O_RDWR);
    if (s32Fd == -1)
    {
        printf("open frame buffer device error\n");
        goto FB_OPEN_ERROR;
    }
    
    stAlpha.bAlphaChannel = HI_FALSE;
    stAlpha.bAlphaEnable = HI_FALSE;
    if (ioctl(s32Fd, FBIOPUT_ALPHA_HIFB, &stAlpha) < 0)
    {
   	    printf("Put alpha info failed!\n");
        goto FB_PROCESS_ERROR0;
    }

	/* get the variable screen info */
    if (ioctl(s32Fd, FBIOGET_VSCREENINFO, &stVarInfo) < 0)
    {
   	    printf("Get variable screen info failed!\n");
        goto FB_PROCESS_ERROR0;
    }
	
    stVarInfo.xres_virtual	 	= SCREEN_WIDTH;
    stVarInfo.yres_virtual		= SCREEN_HEIGHT*2;
    stVarInfo.xres      		= SCREEN_WIDTH;
    stVarInfo.yres      		= SCREEN_HEIGHT;
    stVarInfo.activate  		= FB_ACTIVATE_NOW;
    stVarInfo.bits_per_pixel	= 16;
    stVarInfo.xoffset = 0;
    stVarInfo.yoffset = 0;
    stVarInfo.red   = stR32;
    stVarInfo.green = stG32;
    stVarInfo.blue  = stB32;
    stVarInfo.transp = stA32;

    if (ioctl(s32Fd, FBIOPUT_VSCREENINFO, &stVarInfo) < 0)
    {
        printf("process frame buffer device error\n");
        goto FB_PROCESS_ERROR0;
    }

    if (ioctl(s32Fd, FBIOGET_FSCREENINFO, &stFixInfo) < 0)
    {
        printf("process frame buffer device error\n");
        goto FB_PROCESS_ERROR0;
    }
    
    u32Size 	= stFixInfo.smem_len;
    u32PhyAddr  = stFixInfo.smem_start;
    pu8Screen   = mmap(NULL, u32Size, PROT_READ|PROT_WRITE, MAP_SHARED, s32Fd, 0);
    if (NULL == pu8Screen)
    {
        printf("mmap fb0 failed!\n");
        goto FB_PROCESS_ERROR0;
    }
    memset(pu8Screen, 0x00, stFixInfo.smem_len);

    /* 3. create surface */
    g_stScreen[0].enColorFmt = PIXFMT;
    g_stScreen[0].u32PhyAddr = u32PhyAddr;
    g_stScreen[0].u32Width = SCREEN_WIDTH;
    g_stScreen[0].u32Height = SCREEN_HEIGHT;
    g_stScreen[0].u32Stride = stFixInfo.line_length;
    g_stScreen[0].bAlphaMax255 = HI_TRUE;
	
    g_stScreen[1] = g_stScreen[0];
    g_stScreen[1].u32PhyAddr = g_stScreen[0].u32PhyAddr + g_stScreen[0].u32Stride * g_stScreen[0].u32Height;

    /* allocate memory (720*576*2*N_IMAGES bytes) to save Images' infornation */
    if (HI_FAILURE == HI_MPI_SYS_MmzAlloc(&(g_stBackGround.u32PhyAddr), ((void**)&pu8BackGroundVir), 
            NULL, NULL, 720*576*2*N_IMAGES))
    {
        TDE_PRINT("allocate memory (720*576*2*N_IMAGES bytes) failed\n");
        goto FB_PROCESS_ERROR1;
    }
    
    TDE_CreateSurfaceByFile(BACKGROUND_NAME, &g_stBackGround, pu8BackGroundVir);

    g_stImgSur[0].u32PhyAddr = g_stBackGround.u32PhyAddr + g_stBackGround.u32Stride * g_stBackGround.u32Height;
    for(i = 0; i < N_IMAGES - 1; i++)
    {
      TDE_CreateSurfaceByFile(pszImageNames[i], &g_stImgSur[i], 
            pu8BackGroundVir + ((HI_U32)g_stImgSur[i].u32PhyAddr - g_stBackGround.u32PhyAddr));
      g_stImgSur[i+1].u32PhyAddr = g_stImgSur[i].u32PhyAddr + g_stImgSur[i].u32Stride * g_stImgSur[i].u32Height;
    }
    TDE_CreateSurfaceByFile(pszImageNames[i], &g_stImgSur[i], 
            pu8BackGroundVir + ((HI_U32)g_stImgSur[i].u32PhyAddr - g_stBackGround.u32PhyAddr));

    bShow = HI_TRUE;
    if (ioctl(s32Fd, FBIOPUT_SHOW_HIFB, &bShow) < 0)
    {
        fprintf (stderr, "Couldn't show fb\n");
        goto FB_PROCESS_ERROR2;
    }

    g_s32FrameNum = 0;

    /* 3. use tde and framebuffer to realize rotational effect */
    for (u32Times = 0; u32Times < 20; u32Times++)
    {         
        circumrotate(u32Times%2);
        stVarInfo.yoffset = (u32Times%2)?0:576;

        /*set frame buffer start position*/
        if (ioctl(s32Fd, FBIOPAN_DISPLAY, &stVarInfo) < 0)
        {
            TDE_PRINT("process frame buffer device error\n");
            goto FB_PROCESS_ERROR2;
        }
        sleep(1);
    }

    s32Ret = 0;
    
FB_PROCESS_ERROR2:    
    HI_MPI_SYS_MmzFree(g_stBackGround.u32PhyAddr, pu8BackGroundVir);
FB_PROCESS_ERROR1:
    munmap(pu8Screen, u32Size);
FB_PROCESS_ERROR0:
    close(s32Fd);
FB_OPEN_ERROR:
    HI_TDE2_Close();

    return s32Ret;
}