/* ARGSUSED - this line tells the compiler not to warn about unused args. */
IRES_Status IRES_ALGORITHM_initResources(IALG_Handle handle,
    IRES_ResourceDescriptor * resourceDescriptor, IRES_YieldFxn  yieldFxn,
    IRES_YieldArgs yieldArgs)
{
    Int i = 0;
    Int j = 0;
    unsigned int addr;
    unsigned int numBufs;
    IRES_VICP2_Handle res;
    DUMRES_TI_Handle algHandle = (DUMRES_TI_Handle)handle;
#ifdef xdc_target__os_Linux
    unsigned int tempAddr = 0x0;

    CMEM_init();
#endif

    /* Store information about resources received in the alg handle */
    for (i = 0; i < NUM_RESOURCES; i++) {

        res = ((IRES_VICP2_Handle)resourceDescriptor[i].handle);
        algHandle->resourceState[i] = 0;
        algHandle->resourceHandles[i] = res;

        for (j = 0; j < IRES_VICP2_NUMBUFFERS; j++) {

            addr = res->assignedIMCOPBuffers[j];
            /* An address of 0xFFFFFFFF is equivalent to a buffer not granted */
            if (addr != 0xFFFFFFFF) {

                printf("Resource #%d: VICP2 Buffer #%d: Addr 0x%x\n",i,j,addr);

#ifdef xdc_target__os_Linux
                tempAddr = (unsigned long)CMEM_getPhys((void *)addr);
                printf("Resource #%d: VICP2 Buffer #%d: PHY Addr 0x%x\n",i,j,
                        tempAddr);
#endif
            }
        }

        numBufs = res->numMemBufs;
        for (j = 0; j < numBufs; j++) {

            printf("Resource #%d: Mem Buffer #%d: Addr 0x%x Size 0x%x\n", i, j, 
                    res->assignedMemAddrs[j], res->assignedMemSizes[j]); 
#ifdef xdc_target__os_Linux
            tempAddr = (unsigned long) CMEM_getPhys((void *)
                    (res->assignedMemAddrs[j]));
            printf("Resource #%d: VICP2 Buffer #%d: PHY Addr 0x%x\n",
                    i,j, tempAddr);
#endif
        } 
    }
#ifdef xdc_target__os_Linux
    CMEM_exit();
#endif
    return (IRES_OK);
}
/*******************************************************************************
 * allocate_user_buffers() allocate buffer using CMEM
 ******************************************************************************/
int allocate_user_buffers(void)
{
	void *pool;
	int i;

	CMEM_AllocParams  alloc_params;
	printf("calling cmem utilities for allocating frame buffers\n");
	CMEM_init();

	alloc_params.type = CMEM_POOL;
	alloc_params.flags = CMEM_NONCACHED;
	alloc_params.alignment = 32;
	pool = CMEM_allocPool(0, &alloc_params);

	if (NULL == pool) {
		printf("Failed to allocate cmem pool\n");
		return -1;
	}
	printf("Allocating capture buffers :buf size = %d \n", buf_size);
	
	for (i=0; i < APP_NUM_BUFS/2; i++) {
		capture_buffers[i].user_addr = CMEM_alloc(buf_size, &alloc_params);
		if (capture_buffers[i].user_addr) {
			capture_buffers[i].phy_addr = CMEM_getPhys(capture_buffers[i].user_addr);
			if (0 == capture_buffers[i].phy_addr) {
				printf("Failed to get phy cmem buffer address\n");
				return -1;
			}
		} else {
			printf("Failed to allocate cmem buffer\n");
			return -1;
		}
		printf("Got %p from CMEM, phy = %p\n", capture_buffers[i].user_addr,
			(void *)capture_buffers[i].phy_addr);
	}

	printf("Allocating display buffers :buf size = %d \n", buf_size);
	for (i=0; i < APP_NUM_BUFS/2; i++) {
		display_buffers[i].user_addr = CMEM_alloc(buf_size, &alloc_params);
		if (display_buffers[i].user_addr) {
			display_buffers[i].phy_addr = CMEM_getPhys(display_buffers[i].user_addr);
			if (0 == display_buffers[i].phy_addr) {
				printf("Failed to get phy cmem buffer address\n");
				return -1;
			}
		} else {
			printf("Failed to allocate cmem buffer\n");
			return -1;
		}
		printf("Got %p from CMEM, phy = %p\n", display_buffers[i].user_addr,
			(void *)display_buffers[i].phy_addr);
	}

	return 0;
}
Exemplo n.º 3
0
/**
 * @brief	Memory manager initialization
 * @param	"MEM_MNG_INFO *pInfo"
 * @return	0 : success ; -1 : fail
 */
int MemMng_Init( MEM_MNG_INFO *pInfo )
{
	int mem_layout = pInfo->mem_layout;
	memset( pInfo, 0 , sizeof(MEM_MNG_INFO) );

	pInfo->totalsize		= MemMng_Mem_layout(mem_layout);
	pInfo->start_addr		= (unsigned long)STREAM_CMEM_ALLOC(pInfo->totalsize, 32);

	if( pInfo->start_addr == 0 )
		goto MEM_INIT_FAIL;

	pInfo->start_phyAddr	= CMEM_getPhys((void *)pInfo->start_addr);
	if(pInfo->start_phyAddr == 0)
		fprintf(stderr, "Failed to get physical address of %#x\n",
                    (unsigned int) pInfo->start_phyAddr);
	pInfo->freesize			= pInfo->totalsize;
	pInfo->offset			= 0;
	pInfo->video_info_nums	= 0;

	if(Video_Mem_Malloc( pInfo )==0)
	__D(" MEM_INIT Success \n");
	else
        return -1;

  	MemMng_memcpy_open();

	return 0;

MEM_INIT_FAIL:
	__E(" MEM_INIT_FAIL \n");
	return -1;
}
Exemplo n.º 4
0
/* ARGSUSED - this line tells the compiler not to warn about unused args. */
Int DUMALG_TI_useHDVICP(IDUMALG_Handle handle, unsigned int Id)
{
    Int i;
    DUMALG_TI_Obj * dumalg = (DUMALG_TI_Handle)handle;
    IRES_HDVICP_Handle hdvicp = NULL;

    if (dumalg->yieldFlag) {
        for (i = 0; i < NUM_RESOURCES; i++) {
            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: Yielding HDVICP resource "
                    "%d\n", Id, (Int)(dumalg->hdvicp[i]));
        }

        /* Yield resource now */
        dumalg->yieldFxn((IRES_YieldResourceType)IRES_ALL,&dumalg->yieldContext,
                dumalg->yieldArgs);

            for (i = 0; i < NUM_RESOURCES; i++) {
            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: HDVICP resource %d "
                    "re-acquired\n", Id, (Int)(dumalg->hdvicp[i]));
            }
    }
    else {

        /* Alg doesn't yield the resource */

#ifdef xdc_target__os_Linux
        CMEM_init();
#endif
        for (i = 0; i < NUM_RESOURCES; i++) {

            hdvicp = dumalg->resourceHandles[i];

            GT_2trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Task #%d: Not yielding HDVICP "
                    "resource %d\n", Id, (Int)(hdvicp->id));

#ifdef xdc_target__os_Linux

            GT_3trace(ti_sdo_fc_rman_examples_hdvicp, GT_4CLASS,
                    "_DUMALG_TI_useHDVICP> Register space address 0x%x, Memory "
                    "base address 0x%x, Phy register base address 0x%x\n",
                    (unsigned int)(hdvicp->registerBaseAddress),
                    (unsigned int)(hdvicp->memoryBaseAddress),
                    (void *) CMEM_getPhys((void *)
                    (hdvicp->registerBaseAddress)));

#endif
        }
#ifdef xdc_target__os_Linux
        CMEM_exit();
#endif
    }

    return 0;
}
/*
 *  ======== SCPY_configure ========
 *  Configure a transfer on the SDMA handle
 */
void SCPY_configure(IRES_SDMA_Handle handle, SCPY_Params * params)
{
    /* SCPY_configure should be called with only one logicalChannel */ 
    int logicalChannel = handle->channel->chanNum; 
    unsigned int dmaAddr = (unsigned int)(handle->channel->addr);

    CMEM_init();
    
    omap_set_dma_transfer_params(logicalChannel, dmaAddr, 
            params->transfer->dataType, params->transfer->elemCount, 
            params->transfer->frameCount);


    omap_set_dma_src_params(logicalChannel, dmaAddr, 
            params->src->addr_mode, CMEM_getPhys((void *)(params->src->addr)),
            params->src->elem_index, params->src->frame_index);

    omap_set_dma_dest_params(logicalChannel, dmaAddr, 
            params->dst->addr_mode, CMEM_getPhys((void *)(params->dst->addr)),
            params->dst->elem_index, params->dst->frame_index);

    CMEM_exit();
}
Exemplo n.º 6
0
int DM365MM_memcpy (void *dst, void *src, unsigned int srcwidth,unsigned int width,
    unsigned int height, unsigned int dstwidth)
{
  edma_params edmaparams;
//  printf("CPY");
  if (dm365mm_fd == -1)
    {
      __E ("memcpy: You must initialize DM365MM before making API calls.\n");
      return -1;
    }
//	printf("src = %x,dst = %x srcwidth= %d src height= %d dstwidth= %d\n",src,dst,srcwidth,height,dstwidth);
  edmaparams.srcmode = 0; //INC mode
  edmaparams.srcfifowidth = 0;  //Don't care
  edmaparams.srcbidx = srcwidth;
  edmaparams.srccidx = srcwidth * height;
  edmaparams.dstmode = 0; //INC mode
  edmaparams.dstfifowidth = 0;  //Don't care
  edmaparams.dstbidx = dstwidth;
  edmaparams.dstcidx = dstwidth * height;
  edmaparams.src = CMEM_getPhys (src);
  edmaparams.dst = CMEM_getPhys (dst);
//  edmaparams.src = Memory_getBufferPhysicalAddress (src,srcwidth * height);
//  edmaparams.dst = Memory_getBufferPhysicalAddress (dst,dstwidth * height);
  edmaparams.acnt = width;// Anand 1215 srcwidth;
  edmaparams.bcnt = height;
  edmaparams.ccnt = 1;
  edmaparams.bcntrld = height;  //important setting
  edmaparams.syncmode = 1;  //AB-Sync

  if (ioctl (dm365mm_fd, DM365MMAP_IOCMEMCPY, &edmaparams) == -1)
    {
      __E ("memcpy: Failed to do memcpy\n");
      return -1;
    }
  return 0;
}
Exemplo n.º 7
0
void common_create_native_pixmap(
								 unsigned long pixmapFormat,
								 unsigned long pixmapwidth,
								 unsigned long pixmapHeight,
								 NATIVE_PIXMAP_STRUCT **pNativePixmapPtr
								 )
{
#ifdef _ENABLE_CMEM
	//The cmem module should be inserted before running this application
	//Create a contiguous buffer of required size for texture, and get userspace address
	*pNativePixmapPtr = (NATIVE_PIXMAP_STRUCT*)malloc(sizeof(NATIVE_PIXMAP_STRUCT));

  if(pixmapFormat == SGXPERF_RGB565)
    (*pNativePixmapPtr)->ePixelFormat = 0;
  else if(pixmapFormat == SGXPERF_ARGB8888)
    (*pNativePixmapPtr)->ePixelFormat = 2;
  else           
  {  
		SGXPERF_ERR_printf("Invalid pixmap format type %ld\n", pixmapFormat);
		exit(-1);
  }
    (*pNativePixmapPtr)->eRotation = 0;
    (*pNativePixmapPtr)->lWidth = pixmapwidth;//480;
    (*pNativePixmapPtr)->lHeight = pixmapHeight;//640; 
	if(pixmapFormat == SGXPERF_RGB565)    
		(*pNativePixmapPtr)->lStride = (*pNativePixmapPtr)->lWidth* 16/8; //bitwidth/8
	else if(pixmapFormat == SGXPERF_ARGB8888)
		(*pNativePixmapPtr)->lStride = (*pNativePixmapPtr)->lWidth* 32/8; //bitwidth/8
    (*pNativePixmapPtr)->lSizeInBytes = (*pNativePixmapPtr)->lHeight * (*pNativePixmapPtr)->lStride;
    (*pNativePixmapPtr)->lAddress = (long) CMEM_alloc((*pNativePixmapPtr)->lSizeInBytes, NULL);
	if(!(*pNativePixmapPtr)->lAddress)
	{
		SGXPERF_ERR_printf("CMEM_alloc returned NULL\n");
		exit(-1);
	}
    //Get the physical page corresponding to the above cmem buffer
    (*pNativePixmapPtr)->pvAddress = CMEM_getPhys((void*)(*pNativePixmapPtr)->lAddress);
	SGXPERF_printf("Physical address = %x\n", (*pNativePixmapPtr)->pvAddress);
	if((*pNativePixmapPtr)->pvAddress & 0xFFF)
		SGXPERF_printf("PVR2DMemWrap may have issues with this non-aligned address!\n");
#endif
}
/*
 *  ======== MEMUTILS_getPhysicalAddr ========
 *  Converts user virtual address to physical address,
 *  Returns 0 on failure, physical address on success.
 */
Void * MEMUTILS_getPhysicalAddr(Ptr addr)
{
    UInt32 physicalAddress = 0;

    if (!regInit) {
        addModule();
    }

    CMEM_init();

    physicalAddress = CMEM_getPhys(addr);
    Log_print2(Diags_USER1, "[+1] MEMUTILS_getPhysicalAddr> "
            "CMEM_getPhys(0x%x) = 0x%x.", (IArg)addr, (IArg)physicalAddress);

    Log_print1(Diags_ENTRY, "[+E] MEMUTILS_getPhysicalAddr> return (0x%x)",
            (IArg)physicalAddress);

    CMEM_exit();

    return ((Void *)physicalAddress);
}
Exemplo n.º 9
0
/**
 * @brief	Memory manager initialization
 * @param	"MEM_MNG_INFO *pInfo"
 * @return	0 : success ; -1 : fail
 */
int MemMng_Init( MEM_MNG_INFO *pInfo )
{
	#ifdef VANLINK_DVR_DM365_DEBUG //add by sxh
	OSA_printf("----vl MemMng_Init Enter!!\n");    
	#endif

	int mem_layout = pInfo->mem_layout;
	memset( pInfo, 0 , sizeof(MEM_MNG_INFO) );

	pInfo->totalsize		= MemMng_Mem_layout(mem_layout);
	pInfo->start_addr		= (unsigned long)OSA_cmemAlloc( pInfo->totalsize, 32);

	if( pInfo->start_addr == 0 )
		goto MEM_INIT_FAIL;

	pInfo->start_phyAddr	= CMEM_getPhys((void *)pInfo->start_addr);
	if(pInfo->start_phyAddr == 0)
		fprintf(stderr, "Failed to get physical address of %#x\n",
                    (unsigned int) pInfo->start_phyAddr);
	pInfo->freesize			= pInfo->totalsize;
	pInfo->offset			= 0;
	pInfo->video_info_nums	= 0;

	if(Video_Mem_Malloc( pInfo )==0)
	__D(" MEM_INIT Success \n");
	else
        return -1;

  	MemMng_memcpy_open();
	#ifdef VANLINK_DVR_DM365_DEBUG //add by sxh
	OSA_printf("----vl MemMng_Init Enter!!\n");    
	#endif

	return 0;

MEM_INIT_FAIL:
	__E(" MEM_INIT_FAIL \n");
	return -1;
}
Exemplo n.º 10
0
main()
{
	void *pool;
	int i;

	CMEM_AllocParams  alloc_params;

	printf("calling cmem utilities\n");
	CMEM_init();

	alloc_params.type = CMEM_POOL;
	alloc_params.flags = CMEM_NONCACHED;
	alloc_params.alignment = 32;
	pool = CMEM_allocPool(0, &alloc_params);

	if (NULL == pool) {
		printf("Failed to allocate cmem pool\n");
		exit(1);
	}

	
	for (i=0; i < NUM_BUFFERS; i++) {
		buffers[i].user_addr = CMEM_alloc(BUF_SIZE, &alloc_params);
		if (buffers[i].user_addr) {
			buffers[i].phy_addr = CMEM_getPhys(buffers[i].user_addr);
			if (0 == buffers[i].phy_addr) {
				printf("Failed to get phy cmem buffer address\n");
				exit(1);
			}
		} else {
			printf("Failed to allocate cmem buffer\n");
			exit(1);
		}
		printf("Got %p from CMEM, phy = %p\n", buffers[i].user_addr,
			(void *)buffers[i].phy_addr);
	}
	printf("exiting \n");
}
/*******************************************************************************
 * allocate_user_buffers() allocate buffer using CMEM
 ******************************************************************************/
int allocate_user_buffers(void)
{
	void *pool;
	int i;

	CMEM_AllocParams  alloc_params;
	printf("calling cmem utilities for allocating frame buffers\n");
	CMEM_init();

	alloc_params.type = CMEM_POOL;
	alloc_params.flags = CMEM_NONCACHED;
	alloc_params.alignment = 32;
	pool = CMEM_allocPool(0, &alloc_params);

	if (NULL == pool) {
		printf("Failed to allocate cmem pool\n");
		return -1;
	}
	 printf("the buf size = %d \n", buf_size);
	
	for (i=0; i < MIN_BUFFERS; i++) {
		user_io_buffers[i].user_addr = CMEM_alloc(buf_size, &alloc_params);
		if (user_io_buffers[i].user_addr) {
			user_io_buffers[i].phy_addr = CMEM_getPhys(user_io_buffers[i].user_addr);
			if (0 == user_io_buffers[i].phy_addr) {
				printf("Failed to get phy cmem buffer address\n");
				return -1;
			}
		} else {
			printf("Failed to allocate cmem buffer\n");
			return -1;
		}
		printf("Got %p from CMEM, phy = %p\n", user_io_buffers[i].user_addr,
			(void *)user_io_buffers[i].phy_addr);
	}
	return 0;
}
/*
 *  ======== MEMUTILS_getPhysicalAddr ========
 *  Converts user virtual address to physical address,
 *  Returns 0 on failure, physical address on success.
 */
Void * MEMUTILS_getPhysicalAddr(Ptr addr)
{
    UInt32 physicalAddress = 0;
#if GT_TRACE
    if (!(gtInit)) {
        GT_init();
        GT_create(&curTrace, "ti.sdo.fc.memutils");
        gtInit = 1;
    }    
#endif

    CMEM_init();

    physicalAddress = CMEM_getPhys(addr);
    GT_2trace(curTrace, GT_1CLASS, "MEMUTILS_getPhysicalAddr> "
            "CMEM_getPhys(0x%x) = 0x%x.\n", addr, physicalAddress);

    GT_1trace(curTrace, GT_ENTER, "MEMUTILS_getPhysicalAddr> "
            "return (0x%x)\n", physicalAddress);

    CMEM_exit();

    return ((Void *)physicalAddress);
}
Exemplo n.º 13
0
Capture_Handle Capture_init(CaptureAttr *attr)
{
	Capture_Handle phandle = NULL;
	CaptureBuffer *capBufs = NULL;
	struct v4l2_capability cap;
	struct v4l2_format fmt;
	struct v4l2_fmtdesc fmtdesc;
	struct v4l2_streamparm setfps;
	struct v4l2_requestbuffers req;
	struct v4l2_buffer *v4l2buf = NULL;
	struct v4l2_input  input;
	struct v4l2_standard  std;
	v4l2_std_id id;
	enum v4l2_buf_type type;
	int  BufNum;
	int userAlloc;
	int ret = 0;
	int index;
	int queryinput = 0;
	unsigned int bufindex = 0;
	unsigned int failCount = 0;

	if(attr == NULL)
	{
		SYS_WARNING("The CaptureAttr is null, use default attr.\r\n");
		SYS_WARNING("BufNum is %d, userAlloc is %s.\r\n", CAP_BUF_NUM, "false");
		BufNum = CAP_BUF_NUM;
		userAlloc = 0;
	}
	else
	{
		if(attr->bufNum <=0 || attr->bufNum >=10)
		{
			SYS_ERROR("attr->bufNum %d is not legal, use default attr\r\n",attr->bufNum);
			BufNum = CAP_BUF_NUM;
			userAlloc = attr->userAlloc;
		}
		else
		{
			BufNum = attr->bufNum;
			userAlloc = attr->userAlloc;
		}
	}

	phandle = malloc(sizeof(Capture_Object));

	if(phandle == NULL)
	{
		SYS_ERROR("malloc Capture_Object failed.\r\n");
		goto error;
	}

	phandle->capture_fd = open(VIDEO_DEVICE, O_RDWR);
	if (phandle->capture_fd <= 0)
	{
		SYS_ERROR("open device /dev/video0 failed.\r\n");
		goto error;
	}

	if (ioctl(phandle->capture_fd, VIDIOC_G_INPUT, &index) < 0)
	{
		SYS_ERROR("VIDIOC_G_INPUT failed.\r\n");
		goto error;
	}
	//SYS_INFO("VIdeoc_G_Input index = %d.\r\n", index);
	for (index=0;; index++) {

		input.index = index;
		if (ioctl(phandle->capture_fd, VIDIOC_ENUMINPUT, &input) < 0) {
			//SYS_ERROR("VIDIOC_ENUMINPUT failed\r\n");
			break;
		}

		//SYS_INFO(" name=%s, index = %d\n", input.name, index);
	}
#if 0	
	index = 0;
	if (ioctl(phandle->capture_fd, VIDIOC_S_INPUT, &index) < 0) {
		SYS_ERROR("Failed VIDIOC_S_INPUT to index %d \n", 
				index);
		goto error;
	}
#endif
	for (index=0;; index++) {

		std.frameperiod.numerator = 1;
		std.frameperiod.denominator = 0;
		std.index = index;

		if (ioctl(phandle->capture_fd, VIDIOC_ENUMSTD, &std) < 0) {
			break;
		}
		//SYS_INFO(" name=%s, fps=%d/%d\n", std.name, 
				//std.frameperiod.denominator, std.frameperiod.numerator);
	}
	/* Detect the standard in the input detected */ 
#if 0
	if (ioctl(phandle->capture_fd, VIDIOC_QUERYSTD, &id) < 0) {
		SYS_ERROR("VIDIOC_QUERYSTD failed\r\n");
		goto error;
	}
#endif
	/* Get current video standard */
	if (ioctl(phandle->capture_fd, VIDIOC_G_STD, &id) < 0) {
		SYS_ERROR("Failed VIDIOC_G_STD\n");
		goto error;
	}

	if (id & V4L2_STD_NTSC) {
		//SYS_INFO("in ntsc................\r\n");
	}
	else if (id & V4L2_STD_PAL) {
		//SYS_INFO("in pal................\r\n");
	}
	else if (id & V4L2_STD_525_60) {
		//SYS_INFO("Found 525_60 std input\n");
	}
	else if (id & V4L2_STD_625_50) {
		//SYS_INFO("Found 625_50 std input\n");
	}
	else {
		SYS_ERROR("Unknown video standard on capture device \n");
	}


	if(ioctl(phandle->capture_fd, VIDIOC_QUERYCAP, &cap) == -1)
	{
		SYS_ERROR("Error opening device %s: unable to query device.\r\n", VIDEO_DEVICE);
		goto error;
	}
	else
	{
		//SYS_INFO("driver:\t\t%s\n",cap.driver);
		//SYS_INFO("card:\t\t%s\n",cap.card);
		//SYS_INFO("bus_info:\t%s\n",cap.bus_info);
		//SYS_INFO("version:\t%d\n",cap.version);
		//SYS_INFO("capabilities:\t%x\n",cap.capabilities);

		if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE) 
		{
			//SYS_INFO("Device %s: supports capture.\n",VIDEO_DEVICE);
		}

		if ((cap.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING) 
		{
			//SYS_INFO("Device %s: supports streaming.\n",VIDEO_DEVICE);
		}
	} 
#if 0

	//emu all support fmt
	fmtdesc.index = 0;
	fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	//SYS_INFO("Support format:\n");
	while(ioctl(phandle->capture_fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
	{
		//SYS_INFO("\t%d.%s\n",fmtdesc.index+1,fmtdesc.description);
		fmtdesc.index++;
	}
#endif
	//set fmt
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
	fmt.fmt.pix.height = HEIGHT;
	fmt.fmt.pix.width = WIDTH;
	fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
	fmt.fmt.pix.bytesperline = WIDTH * 2;

	if(ioctl(phandle->capture_fd, VIDIOC_S_FMT, &fmt) == -1)
	{
		SYS_ERROR("Unable to set format.1\n");
		goto error;
	} 	
	if(ioctl(phandle->capture_fd, VIDIOC_G_FMT, &fmt) == -1)
	{
		SYS_ERROR("Unable to get format\n");
		goto error;
	} 
	{
		//SYS_INFO("fmt.type:\t\t%d\n",fmt.type);
		//SYS_INFO("pix.pixelformat:\t%c%c%c%c\n",fmt.fmt.pix.pixelformat & 0xFF, (fmt.fmt.pix.pixelformat >> 8) & 0xFF,(fmt.fmt.pix.pixelformat >> 16) & 0xFF, (fmt.fmt.pix.pixelformat >> 24) & 0xFF);
		//SYS_INFO("..........pix.height:\t\t%d\n",fmt.fmt.pix.height);
		//SYS_INFO("............pix.width:\t\t%d\n",fmt.fmt.pix.width);
		//SYS_INFO("..........pix.field:\t\t%d\n",fmt.fmt.pix.field);
	}
	//set fps
	setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	setfps.parm.capture.timeperframe.numerator = 10;
	setfps.parm.capture.timeperframe.denominator = 10;

	//SYS_INFO("init %s \t[OK]\n",VIDEO_DEVICE);


	if(!userAlloc)
	{
		//SYS_INFO("Driver alloc the capture buffer. BufNum = %d\r\n", BufNum);
		phandle->userAlloc = 0;
		memset(&req, 0x00, sizeof(req));
		req.count = BufNum;
		req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		req.memory = V4L2_MEMORY_MMAP;
		if (ioctl(phandle->capture_fd, VIDIOC_REQBUFS, &req) < 0 )
		{
			SYS_ERROR("VIDIOC_REQDQBUFS failed.\r\n");
			goto error;
		}

		if (req.count < BufNum)
		{
			if(!req.count)
			{
				SYS_ERROR("req.count is 0.\r\n", req.count);
				goto error;
			}
			else
			{
				SYS_WARNING("req.count = %d < %d\r\n", req.count, BufNum);
			}
		}

		capBufs = calloc(req.count, sizeof(CaptureBuffer));
		v4l2buf = calloc(req.count, sizeof(struct v4l2_buffer));

		if (capBufs == NULL || v4l2buf == NULL)
		{
			SYS_ERROR("malloc capbufs failed.\r\n");
			goto error;
		}

		for(bufindex = 0; bufindex < req.count; bufindex++)
		{
			memset(&v4l2buf[bufindex], 0x00, sizeof(struct v4l2_buffer));
			v4l2buf[bufindex].type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
			v4l2buf[bufindex].memory = V4L2_MEMORY_MMAP;
			v4l2buf[bufindex].index = bufindex;

			if (ioctl(phandle->capture_fd, VIDIOC_QUERYBUF, &v4l2buf[bufindex]) < 0)
			{
				SYS_ERROR("VIDIOC_QUERYBUF failed. index = %d.\r\n", bufindex);
				goto error;
			}

			capBufs[bufindex].length = v4l2buf[bufindex].length;
			capBufs[bufindex].physaddr = v4l2buf[bufindex].m.offset;
			capBufs[bufindex].index = bufindex;
			capBufs[bufindex].virtaddr = mmap(NULL, v4l2buf[bufindex].length, PROT_READ|PROT_WRITE, MAP_SHARED, phandle->capture_fd, v4l2buf[bufindex].m.offset);

			//SYS_INFO("index %d length %d physaddr %x virtaddr %x.\r\n",
					//bufindex,v4l2buf[bufindex].length, v4l2buf[bufindex].m.offset, capBufs[bufindex].virtaddr);
			memset(capBufs[bufindex].virtaddr, 0x55, 720*480 );
			if (capBufs[bufindex].virtaddr == MAP_FAILED)
			{
				SYS_ERROR("mmap failed. index = %d.\r\n", bufindex);
				goto error;
			}

			if (ioctl(phandle->capture_fd, VIDIOC_QBUF, &v4l2buf[bufindex]) < 0 )
			{
				SYS_ERROR("VIDIOC_QBUF failed.\r\n");
				goto error;
			}
		}
	}
	else
	{

		if(ioctl(phandle->capture_fd, VIDIOC_G_FMT, &fmt) == -1)
		{
			SYS_ERROR("Unable to get format\n");
			goto error;
		} 
		//SYS_INFO("User alloc the capture buffer.\r\n");
		phandle->userAlloc = 1;
		if(CMEM_init() < 0)
		{
			SYS_ERROR("CMEM_init error.\r\n");
			goto error;
		}
		memset(&req, 0x00, sizeof(req));
		req.count = BufNum;
		req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		req.memory = V4L2_MEMORY_USERPTR;
		if (ioctl(phandle->capture_fd, VIDIOC_REQBUFS, &req) < 0 )
		{
			SYS_ERROR("VIDIOC_REQDQBUFS failed.\r\n");
			goto error;
		}

		if (req.count < BufNum)
		{
			if(!req.count)
			{
				SYS_ERROR("req.count is 0.\r\n", req.count);
				goto error;
			}
			else
			{
				SYS_WARNING("req.count = %d < %d\r\n", req.count, BufNum);
			}
		}

		capBufs = calloc(req.count, sizeof(CaptureBuffer));
		v4l2buf = calloc(req.count, sizeof(struct v4l2_buffer));

		if (capBufs == NULL || v4l2buf == NULL)
		{
			SYS_ERROR("malloc capbufs failed.\r\n");
			goto error;
		}

		for(bufindex = 0; bufindex < req.count; bufindex++)
		{
			memset(&v4l2buf[bufindex], 0x00, sizeof(struct v4l2_buffer));
			//char *data = CMEM_alloc((720*480*2 + 4*1024) & (~0xFFF), &cmem_param);
			char *data = CMEM_alloc(831488, &cap_cmem_param);
			if(data == NULL)
			{
				SYS_ERROR("CMEM_alloc error.");
				goto error;
			}

			v4l2buf[bufindex].index		= bufindex;
			v4l2buf[bufindex].type		= V4L2_BUF_TYPE_VIDEO_CAPTURE;
			v4l2buf[bufindex].memory	= V4L2_MEMORY_USERPTR;
			v4l2buf[bufindex].m.userptr = (int)data;
			//v4l2buf[bufindex].length	=  (720*480*2 + 4*1024) & (~0xFFF);
			v4l2buf[bufindex].length	=  831488;
			//int len	=  (720*480*2 + 4*1024) & (~0xFFF);

			capBufs[bufindex].length	= v4l2buf[bufindex].length;
			capBufs[bufindex].physaddr	= CMEM_getPhys(data);
			capBufs[bufindex].index		= v4l2buf[bufindex].index;
			capBufs[bufindex].virtaddr	= (void*)v4l2buf[bufindex].m.userptr;

			////SYS_INFO("len %d\r\n",len);
			//SYS_INFO("index %d length %d physaddr %x virtaddr %x.\r\n",
			//		bufindex,v4l2buf[bufindex].length, v4l2buf[bufindex].m.offset, capBufs[bufindex].virtaddr);
			if (ioctl(phandle->capture_fd, VIDIOC_QBUF, &v4l2buf[bufindex]) < 0 )
			{
				SYS_ERROR("VIDIOC_QBUF failed.\r\n");
				goto error;
			}
		}

	}

	type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
#if 1
	if (ioctl(phandle->capture_fd, VIDIOC_STREAMON, &type) < 0 )
	{
		SYS_ERROR("stream on failed.\r\n");
		goto error;
	}
#endif

	phandle->capBufsPtr = capBufs;
	phandle->v4l2buf = v4l2buf;
	phandle->capBufsNum = req.count;
	return phandle;

error:
	SYS_ERROR("Capture_init error.\r\n");
	if(phandle != NULL)
	{
		if(phandle->capture_fd > 0)
		{
			close(phandle->capture_fd);
		}
		free(phandle);
	}
	if(capBufs != NULL)
	{
		free(capBufs);
	}
	return NULL;
}
Exemplo n.º 14
0
bool GLPowerVRWidget::loadNewTexture(int vidIx)
{
    bool texLoaded = false;

    unsigned long currentVidBufferAddress = (unsigned long)CMEM_getPhys(this->m_vidPipelines[vidIx]->bufToVidDataStart(this->m_vidTextures[vidIx].buffer));

    LOG(LOG_GL, Logger::Debug2, "vid %d, CMEM phys=%lx", vidIx, currentVidBufferAddress);

    if(m_vidBufferAddressesSet.contains(false))
    {
        bool gotThisBuffer = false;
        QVector<bc_buf_ptr_t>::iterator bufPtr;
        for(bufPtr = m_vidBufferAddresses[vidIx].begin(); bufPtr != m_vidBufferAddresses[vidIx].end(); ++bufPtr)
        {
            if(bufPtr->pa == currentVidBufferAddress)
            {
                // Already recorded this buffer address
                LOG(LOG_GL, Logger::Debug2, "vid %d, already saved phys addr %lx", vidIx, currentVidBufferAddress);
                gotThisBuffer = true;

                // If we've got the same buffer a second time,
                // assume that means we have all the buffer addresses
                m_vidBufferAddressesSet[vidIx] = true;
            }
        }

        if(!gotThisBuffer)
        {
            // A new buffer has come through, record the details:
            bc_buf_ptr_t bc_buf;
            bc_buf.index = totalVidBuffers(); // Multiple buffers per possibly multiple videos
            // Size parameter isn't actually used in the driver just yet but fill in anyway for
            // future proofing:
            switch(this->m_vidTextures[vidIx].colourFormat)
            {
            case ColFmt_I420:
                bc_buf.size = this->m_vidTextures[vidIx].width * this->m_vidTextures[vidIx].height * 1.5f;
                break;
            case ColFmt_UYVY:
            default:
                bc_buf.size = this->m_vidTextures[vidIx].width * this->m_vidTextures[vidIx].height * 2;
                break;
            }
            bc_buf.pa = currentVidBufferAddress;
            LOG(LOG_GL, Logger::Debug1, "vid %d, saving bc_buf_ptr_t: index=%d, size=%d, pa=%lx",
                vidIx, bc_buf.index, bc_buf.size, bc_buf.pa);
            m_vidBufferAddresses[vidIx].push_back(bc_buf);
        }

        // Have we got all the buffer addresses we are waiting for, for all videos?
        if(!m_vidBufferAddressesSet.contains(false))
        {
            LOG(LOG_GL, Logger::Debug1, "got all the bc_buf_ptr_t entries for all vids");

            for(int currentVidIx = 0; currentVidIx < m_vidPipelines.size(); currentVidIx++)
            {
                // We now definitely have the size information needed to prep the driver:
                bc_buf_params_t bufParams;
                bufParams.count = m_vidBufferAddresses[currentVidIx].size();
                bufParams.width = this->m_vidTextures[currentVidIx].width;
                bufParams.height = this->m_vidTextures[currentVidIx].height;

                bufParams.fourcc = COLFMT_TO_BC_FOURCC(this->m_vidPipelines[currentVidIx]->getColourFormat());
                bufParams.type = BC_MEMORY_USERPTR;

                LOG(LOG_GL, Logger::Debug1, "vid %d, calling BCIOREQ_BUFFERS, count=%d, fourCC=0x%08X, width=%d, height=%d, type=%d",
                    currentVidIx, bufParams.count, bufParams.fourcc, bufParams.width, bufParams.height, bufParams.type);
                int retVal;
                if((retVal = ioctl(m_bcFds[currentVidIx], BCIOREQ_BUFFERS, &bufParams)) != 0)
                {
                    LOG(LOG_GL, Logger::Error, "ERROR: BCIOREQ_BUFFERS on fd %d failed, retVal=%d, errno=%d:%s",
                        m_bcFds[currentVidIx], retVal, errno, strerror(errno));
                    return false;
                }

                LOG(LOG_GL, Logger::Debug1, "vid %d, calling BCIOGET_BUFFERCOUNT", currentVidIx);
                BCIO_package ioctlVar;
                if (ioctl(m_bcFds[currentVidIx], BCIOGET_BUFFERCOUNT, &ioctlVar) != 0)
                {
                    LOG(LOG_GL, Logger::Error, "ERROR: BCIOGET_BUFFERCOUNT failed");
                    return false;
                }

                if (ioctlVar.output == 0)
                {
                    LOG(LOG_GL, Logger::Error, "ERROR: no texture buffers available");
                    return false;
                }

                for(bufPtr = m_vidBufferAddresses[currentVidIx].begin(); bufPtr != m_vidBufferAddresses[currentVidIx].end(); ++bufPtr)
                {
                    if (ioctl(m_bcFds[currentVidIx], BCIOSET_BUFFERPHYADDR, bufPtr) != 0)
                    {
                        LOG(LOG_GL, Logger::Error, "ERROR: BCIOSET_BUFFERADDR[%d]: failed (0x%lx)",
                            bufPtr->index, bufPtr->pa);
                    }
                }
            }

            printOpenGLError(__FILE__, __LINE__);

            // Should be able to set up the GLES side now:
            const GLubyte *imgDevName;
            imgDevName = this->glGetTexDeviceIMG(vidIx);

            printOpenGLError(__FILE__, __LINE__);

            GLint numImgBufs, imgBufWidth, imgBufHeight, imgBufFmt;
            this->glGetTexAttrIMG(vidIx, GL_TEXTURE_STREAM_DEVICE_NUM_BUFFERS_IMG, &numImgBufs);
            this->glGetTexAttrIMG(vidIx, GL_TEXTURE_STREAM_DEVICE_WIDTH_IMG, &imgBufWidth);
            this->glGetTexAttrIMG(vidIx, GL_TEXTURE_STREAM_DEVICE_HEIGHT_IMG, &imgBufHeight);
            this->glGetTexAttrIMG(vidIx, GL_TEXTURE_STREAM_DEVICE_FORMAT_IMG, &imgBufFmt);

            LOG(LOG_GL, Logger::Debug1, "GLES IMG attrs: dev name: %s, numbufs=%d, width=%d, height=%d, format=%d",
                   imgDevName, numImgBufs, imgBufWidth, imgBufHeight, imgBufFmt);

            printOpenGLError(__FILE__, __LINE__);

            /* do stuff from setup_shaders() in bc_cat example common.c code here */
            glActiveTexture(GL_TEXTURE0);


            for(int currentVidIx = 0; currentVidIx < m_vidPipelines.size(); currentVidIx++)
            {
                // Delete the single texture ID created in superclass,
                // ready to create the pool of texture IDs for each video instead
                glDeleteTextures (1, &m_vidTextures[currentVidIx].texId);

                // Loop through all the buffers, link buf index to tex IDs:
                QVector<bc_buf_ptr_t>::iterator bufPtr;
                for(bufPtr = m_vidBufferAddresses[currentVidIx].begin(); bufPtr != m_vidBufferAddresses[currentVidIx].end(); ++bufPtr)
                {
                    GLuint newTexId;
                    glGenTextures(1, &newTexId);

                    LOG(LOG_GL, Logger::Debug1, "calling glBindTexture texId=%d",
                        newTexId);
                    glBindTexture(GL_TEXTURE_STREAM_IMG, newTexId);
                    printOpenGLError(__FILE__, __LINE__);

                    LOG(LOG_GL, Logger::Debug1, "setting texture filters");
                    // specify filters
                    //glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                    //glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                    // cmem examples use:
                    glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                    glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                    printOpenGLError(__FILE__, __LINE__);

                    // assign the buffer
                    LOG(LOG_GL, Logger::Debug1, "calling glTexBindStreamIMG buf index=%d", bufPtr->index);
                    glTexBindStreamIMG(vidIx, bufPtr->index);
                    printOpenGLError(__FILE__, __LINE__);

                    m_bcBufIxToTexId[bufPtr->index] = newTexId;

                    // When the loop exits, take last buffer captured for vid as active texture
                    this->m_vidTextures[currentVidIx].texId = newTexId;
                }
            }
            texLoaded = true;
        }

    }
    else
    {
        LOG(LOG_GL, Logger::Debug2, "vid %d, looking up bc_buf_ptr_t index for buf pa=%lx",
            vidIx, currentVidBufferAddress);

        bool bufAdrFound = false;
        QVector<bc_buf_ptr_t>::iterator bufPtr;
        for(bufPtr = m_vidBufferAddresses[vidIx].begin(); bufPtr != m_vidBufferAddresses[vidIx].end(); ++bufPtr)
        {
            if(bufPtr->pa == currentVidBufferAddress)
            {
                LOG(LOG_GL, Logger::Debug2, "vid %d, setting texture to bc_buf_ptr_t index %d, texId %d",
                    vidIx, bufPtr->index, m_bcBufIxToTexId[bufPtr->index]);
                this->m_vidTextures[vidIx].texId = m_bcBufIxToTexId[bufPtr->index];
                bufAdrFound = true;
                break;
            }
        }

        if(bufAdrFound)
        {
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_STREAM_IMG, this->m_vidTextures[vidIx].texId);

            texLoaded = true;
        }
        else
        {
            LOG(LOG_GL, Logger::Error, "new vid buffer arrived after all expected buffers have been setup, pa=%lx",
                currentVidBufferAddress);
        }
    }

    return texLoaded;
}
Exemplo n.º 15
0
/*
 *  ======== Memory_getBufferPhysicalAddress ========
 *  Converts user virtual address to physical address,
 *  but also verifies that the buffer is really contiguous
 *  and does some bookkeeping so that reverse mapping is possible.
 *  Returns 0 on failure, physical address on success.
 *  *isContiguous is set to TRUE or FALSE if isContiguous!=NULL.
 */
UInt32 Memory_getBufferPhysicalAddress(
           Ptr virtualAddress, Int sizeInBytes,    /* input */
           Bool *isContiguous                      /* output */
      )
{
    UInt32 physicalAddress = 0;
    UInt32 physicalAddressOfLastByte;

    Lock_acquire(moduleLock);

    Log_print2(Diags_ENTRY, "[+E] Memory_getBufferPhysicalAddress> "
            "Enter(virtAddr=0x%x, size=0x%x)",
            (IArg)virtualAddress, (IArg)sizeInBytes);

    if (Memory_skipVirtualAddressTranslation == TRUE) {
        if (isContiguous != NULL) {
            *isContiguous = TRUE;
        }
        physicalAddress = (UInt32)virtualAddress;
        goto Memory_getBufferPhysicalAddress_return;
    }

    if (sizeInBytes == 0) {
        Log_print0(Diags_USER6, "[+6] Memory_getBufferPhysicalAddress> "
                "invalid buffer size provided (0)");

        /* Note that physicalAddress is already initialized to zero */
        goto Memory_getBufferPhysicalAddress_return;
    }

    /* first try to find the buffer in our tables */
    physicalAddress = getPhysicalAddress((UInt32)virtualAddress, sizeInBytes);

    if (physicalAddress != 0) {
        if (isContiguous != NULL) {
            *isContiguous = TRUE;
        }
    }
    else {

#if 0  /* TODO:M - should we re-enable this as a warning? */
        /* [cr]TODO:H this is DaVinci specific; should the caller check it? */
        /* Ensure the buffer destined for the DSP is cache aligned. */
        if ((((UInt32)virtualAddress) & 0x7F) != 0) {
            Log_print1(Diags_USER7, "[+7] Memory_getBufferPhysicalAddress> "
                    "ERROR: buffer (0x%x) is not cache aligned on 128 byte "
                    "boundary.", (IArg)virtualAddress);
            Lock_release(moduleLock);

            return (0);
        }
#endif

        /* ask CMEM to convert addresses of the first and the last byte */
        physicalAddress = CMEM_getPhys(virtualAddress);
        Log_print2(Diags_USER1, "[+1] Memory_getBufferPhysicalAddress> "
                "CMEM_getPhys(0x%x) = 0x%x.",
                (IArg)virtualAddress, (IArg)physicalAddress);
        physicalAddressOfLastByte = CMEM_getPhys(
            (Ptr)((UInt32)virtualAddress + sizeInBytes - 1));
        if (physicalAddress != 0) {
            if (physicalAddressOfLastByte == physicalAddress + sizeInBytes - 1)
            {
                if (isContiguous != NULL) {
                    *isContiguous = TRUE;
                }
            }
            else {
                if (isContiguous != NULL) {
                    *isContiguous = FALSE;
                }
                else {
                    Log_print2(Diags_USER7,
                            "[+7] Memory_getBufferPhysicalAddress> "
                            "ERROR: user buffer at addr=0x%x, size=0x%x "
                            "is NOT contiguous",
                            (IArg)virtualAddress, (IArg)sizeInBytes);
                }

                /* invalid buffer - it's not contiguous. */
                physicalAddress = 0;
            }
        }
    }

Memory_getBufferPhysicalAddress_return:

    Log_print1(Diags_EXIT, "[+X] Memory_getBufferPhysicalAddress> "
            "return (0x%x)", (IArg)physicalAddress);

    Lock_release(moduleLock);

    return (physicalAddress);
}
Exemplo n.º 16
0
/*
 *  ======== contigAlloc ========
 */
static Ptr contigAlloc(UInt size, UInt align, Bool cacheable, Bool heap)
{
    Ptr    addr = NULL;
    UInt32 physAddr;
    CMEM_AllocParams cmemParams;

    /* lock acquire should be after the trace, but it's unlikely to fail
     * and we get a more consistent/less confusing output this way.
     */
    Lock_acquire(moduleLock);

    Log_print4(Diags_ENTRY, "[+E] Memory_contigAlloc> "
            "Enter(size=0x%x, align=0x%x, cached=%s, heap=%s)", (IArg)size,
            (IArg)align, (IArg)(cacheable ? "TRUE" : "FALSE"),
            (IArg)(heap ? "TRUE" : "FALSE"));

    if (!cmemInitialized) {
        Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> "
                "ERROR: request for size=0x%x failed -- CMEM has not been "
                "initialized.", (IArg)size);
        goto contigAlloc_return;
    }

    if (!heap && (Int)align > CMEMPOOLALIGN) {
        Log_print2(Diags_USER6, "[+6] Memory_contigAlloc> "
                "Warning: alignment %#x not supported for pool-based allocations,"
                " using fixed alignment %#x.",
                (IArg)align, (IArg)CMEMPOOLALIGN);
        /* align is not used for pool-based allocs, but set it anyway */
        align = CMEMPOOLALIGN;
    }

    cmemParams.type = heap ? CMEM_HEAP : CMEM_POOL;
    cmemParams.flags = cacheable ? CMEM_CACHED : CMEM_NONCACHED;
    cmemParams.alignment = align;
    addr = CMEM_alloc(size, &cmemParams);

    Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> CMEM_alloc(0x%x) = 0x%x.",
            (IArg)size, (IArg)addr);

    if (addr != NULL) {

        /* since the allocation succeeded, get physical address now and add the
         * description for this buffer in our list of contiguous buffers.
         */
        physAddr = CMEM_getPhys(addr);
        if (physAddr != 0) {
            Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> "
                    "CMEM_getPhys(0x%x) = 0x%x.", (IArg)addr, (IArg)physAddr);
            addContigBuf((Uint32)addr, size, physAddr);
        } else {
            Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> "
                    "ERROR: CMEM_getPhys(0x%x) (virt-to-phys) failed; "
                    "releasing the block.", (IArg)addr);
            CMEM_free(addr, &cmemParams);
            addr = NULL;
        }
    } else {
        Log_print0(Diags_USER7, "[+7] Memory_contigAlloc> "
                "ERROR: CMEM alloc failed");
    }

contigAlloc_return:

    Log_print1(Diags_EXIT, "[+X] Memory_contigAlloc> return (0x%x)",
            (IArg)addr);

    Lock_release(moduleLock);

    return addr;
}
/*  ARGSUSED - this line tells the compiler not to warn about unused args */
IRES_Status IRESMAN_MEMTCM_freeHandle(IALG_Handle algHandle, IRES_Handle
        algResourceHandle, IRES_ProtocolArgs * protocolArgs, 
        Int scratchGroupId) 
{
    IALG_MemRec resourceMemRecs[1];
    Int numMemRecs;
    IRES_Status status = IRES_OK;
    Int resourceId = -1;
    unsigned int numResources = 0;
    unsigned int addr = 0x0;
    unsigned int size = 0x0;
    Bool smg_status = FALSE;


    GT_assert(CURTRACE, protocolArgs);
    GT_assert(CURTRACE, algResourceHandle);

    GT_3trace(CURTRACE, GT_ENTER, 
            "IRESMAN_MEMTCM_freeHandles> Enter (handle=0x%x, "
            "protocolArgs=0x%x, scratchGroupId=%d)\n", algResourceHandle, 
            protocolArgs, scratchGroupId); 

    if (_initialized != 1) {
        status =  IRES_ENORESOURCE;

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_MEMTCM_getHandles> RMAN register for MEMTCM "
                "resource not happened successfully. Please call RMAN_register "
                "before trying to assign or release resources\n");

        return (status);
    }


    /*
     * Obtain memory resources to free and free them
     */
    numMemRecs = IRESMAN_MEMTCM_CONSTRUCTFXNS.getNumMemRecs
        ( (IRES_ProtocolArgs *)protocolArgs);

    IRESMAN_MEMTCM_CONSTRUCTFXNS.getMemRecs((IRES_Handle)NULL,
            (IRES_ProtocolArgs *) protocolArgs, resourceMemRecs);

    /* Set Base address of Memory location to free */
    resourceMemRecs[0].base = algResourceHandle;

    /* Free other things allocated */
    addr = CMEM_getPhys(((IRES_MEMTCM_Handle)algResourceHandle)->memAddr);

    size = ((IRES_MEMTCM_Handle)algResourceHandle)->memSize;

    resourceId = ((unsigned int)addr - 
            (unsigned int)_resmanInternalState->armtcmAddr)/MEMTCM_RESSIZE; 

    numResources = (size + (MEMTCM_RESSIZE -1))/MEMTCM_RESSIZE;

    smg_status = SMGRMP_free(smgr, algHandle, resourceId, numResources,
            scratchGroupId);

    if (smg_status == FALSE) {

        GT_1trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_MEMTCM_freeHandles> Error trying to free "
                "memory 0x%x\n",
                ((IRES_MEMTCM_Handle)algResourceHandle)->memAddr);

        return (IRES_EFAIL);
    }

    /*
     * Use IRES_MEMTCM_RESOURCEPROTOCOL to de-init the resource protocol
     * if required
     */
    IRESMAN_MEMTCM_CONSTRUCTFXNS.destructHandle(algResourceHandle);

    /*
     * Free the memory for the handles
     */
    _freeFxn(resourceMemRecs, numMemRecs); 

    GT_0trace(CURTRACE, GT_ENTER, 
            "IRESMAN_MEMTCM_freeHandles> Exit (status=IRES_OK)\n"); 

    return (IRES_OK);
}
int clear_plane(int index,jpegdec_config_t *config)
{
	int fd_ge2d=-1;
	config_para_t ge2d_config;
    int format;
    ge2d_op_para_t op_para;
    memset((char*)&ge2d_config,0,sizeof(config_para_t));
    fd_ge2d= open(FILE_NAME_GE2D, O_RDWR);
	if(fd_ge2d<0)
	{
#ifdef JPEG_DBG 	    
		printf("can't open framebuffer device" );  	
#endif		
		goto exit;
	}
    format = Format_RGB32;
#ifdef JPEG_DBG 
	printf("start clean plane buffer %d!!!!!\n", index);
#endif	
	ge2d_config.src_dst_type = ALLOC_ALLOC;

//	qCritical("planes[3]addr : 0x%x-0x%x" ,planes[3],ge2d_config.dst_planes[0].addr);		
    
    switch(index){
        case 0:
        op_para.color=0x008080ff;
        ge2d_config.src_format = GE2D_FORMAT_S8_Y;
	    ge2d_config.dst_format = GE2D_FORMAT_S8_Y;
    	ge2d_config.dst_planes[0].addr = config->addr_y;
    	ge2d_config.dst_planes[0].w = config->canvas_width;
    	ge2d_config.dst_planes[0].h = config->dec_h;     
    	op_para.src1_rect.x = config->dec_x;
    	op_para.src1_rect.y = config->dec_y;
    	op_para.src1_rect.w = config->dec_w;
    	op_para.src1_rect.h = config->dec_h;      	   
    	op_para.dst_rect.x = config->dec_x;
    	op_para.dst_rect.y = config->dec_y;
    	op_para.dst_rect.w = config->dec_w;
    	op_para.dst_rect.h = config->dec_h;        	
        break;
        case 1:
        op_para.color=0x008080ff;
        ge2d_config.src_format = GE2D_FORMAT_S8_CB;
	    ge2d_config.dst_format = GE2D_FORMAT_S8_CB;
    	ge2d_config.dst_planes[0].addr = config->addr_u;
    	ge2d_config.dst_planes[0].w = config->canvas_width/2;
    	ge2d_config.dst_planes[0].h = config->dec_h / 2;      
    	op_para.src1_rect.x = config->dec_x/2;
    	op_para.src1_rect.y = config->dec_y/2;
    	op_para.src1_rect.w = config->dec_w/2;
    	op_para.src1_rect.h = config->dec_h/2;       	
    	op_para.dst_rect.x = config->dec_x/2;
    	op_para.dst_rect.y = config->dec_y/2;
    	op_para.dst_rect.w = config->dec_w/2;
    	op_para.dst_rect.h = config->dec_h/2;        	
        break;
        case 2:
        op_para.color=0x008080ff;
        ge2d_config.src_format = GE2D_FORMAT_S8_CR;
	    ge2d_config.dst_format = GE2D_FORMAT_S8_CR;    
    	ge2d_config.dst_planes[0].addr = config->addr_v;
    	ge2d_config.dst_planes[0].w = config->canvas_width/2;
    	ge2d_config.dst_planes[0].h = config->dec_h / 2;
    	op_para.src1_rect.x = config->dec_x/2;    
    	op_para.src1_rect.y = config->dec_y/2;    
    	op_para.src1_rect.w = config->dec_w/2;    
    	op_para.src1_rect.h = config->dec_h/2;    
    	op_para.dst_rect.x = config->dec_x/2;
    	op_para.dst_rect.y = config->dec_y/2;
    	op_para.dst_rect.w = config->dec_w/2;
    	op_para.dst_rect.h = config->dec_h/2;        		    
        break;
        case 3:
        op_para.color=0x000000ff;
        ge2d_config.src_format = ImgFormat2Ge2dFormat(format);
        ge2d_config.dst_format = ImgFormat2Ge2dFormat(format);
    	ge2d_config.dst_planes[0].addr=CMEM_getPhys(planes[3]);
    	ge2d_config.dst_planes[0].w= scale_w;
    	ge2d_config.dst_planes[0].h = scale_h;    
    	op_para.src1_rect.x = scale_x; 
    	op_para.src1_rect.y = scale_y; 
    	op_para.src1_rect.w = scale_w; 
    	op_para.src1_rect.h = scale_h;       	
    	op_para.dst_rect.x = scale_x;  
    	op_para.dst_rect.y = scale_y;  
    	op_para.dst_rect.w = scale_w;  
    	op_para.dst_rect.h = scale_h;    	    
        break;
        case 4:
        ge2d_config.src_dst_type = OSD0_OSD0;
        op_para.color=0x000000ff;
        ge2d_config.src_format = ImgFormat2Ge2dFormat(format);
        ge2d_config.dst_format = ImgFormat2Ge2dFormat(format);
    	op_para.src1_rect.x = scale_x; 
    	op_para.src1_rect.y = scale_y; 
    	op_para.src1_rect.w = scale_w; 
    	op_para.src1_rect.h = scale_h;       	
    	op_para.dst_rect.x = scale_x;  
    	op_para.dst_rect.y = scale_y;  
    	op_para.dst_rect.w = scale_w;  
    	op_para.dst_rect.h = scale_h;            
        break;
        default:
        break;                            
    }
	ioctl(fd_ge2d, FBIOPUT_GE2D_CONFIG, &ge2d_config);
   ioctl(fd_ge2d, FBIOPUT_GE2D_FILLRECTANGLE, &op_para);     
exit:       
	if(fd_ge2d >=0){
	    close(fd_ge2d);		
	    fd_ge2d = -1;
    }     
#ifdef JPEG_DBG       
    printf("finish clean plane buffer %d!!!!!\n", index);
#endif
    return 0;     
}
Exemplo n.º 19
0
void testCache(int size, int block)
{
    unsigned int *ptr1_nocache = NULL;
    unsigned int *ptr1_cache = NULL;
    unsigned int *ptr1_dma = NULL;
    unsigned int *ptr2 = NULL;
    unsigned long physp;
    unsigned long physp_dma;
    unsigned long physp_nocache;
    unsigned long physp_cache;
    int poolid;
    int i, j;
    struct timeval start_tv, end_tv;
    unsigned long diff;
    int foo, bar;
    CMEM_AllocParams params;

    printf("Allocating first noncached buffer.\n");

    /* First allocate a buffer from the pool that best fits */
    ptr1_nocache = CMEM_alloc(size, NULL);

    if (ptr1_nocache == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_nocache);

    /* Find out and print the physical address of this buffer */
    physp_nocache = CMEM_getPhys(ptr1_nocache);

    if (physp_nocache == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_nocache);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_nocache);

    /* Write some data into this buffer */
    for (i=0; i < size / sizeof(int) ; i++) {
        ptr1_nocache[i] = 0xbeefbeef;
    }

    printf("Allocating first cached buffer.\n");

    /* First allocate a buffer from the pool that best fits */
    params = CMEM_DEFAULTPARAMS;
    params.flags = CMEM_CACHED;
    ptr1_cache = CMEM_alloc2(block, size, &params);

    if (ptr1_cache == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_cache);

    /* Find out and print the physical address of this buffer */
    physp_cache = CMEM_getPhys(ptr1_cache);

    if (physp_cache == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_cache);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_cache);

    /* Write some data into this buffer */
    for (i = 0; i < size / sizeof(int); i++) {
        ptr1_cache[i] = 0x0dead1ce;
    }

    printf("Allocating noncached DMA source buffer.\n");

    /* Allocate a noncached buffer for the DMA source */
    ptr1_dma = CMEM_alloc(size, NULL);

    if (ptr1_dma == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_dma);

    /* Find out and print the physical address of this buffer */
    physp_dma = CMEM_getPhys(ptr1_dma);

    if (physp_dma == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_dma);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_dma);

    /* Initialize DMA source buffer */
    for (i = 0; i < size / sizeof(int); i++) {
        ptr1_cache[i] = 0x0dead1ce;
    }

    /*
     * Measure the write performance of each buffer to check that one
     * is cached and the other isn't.
     */
    printf("Measuring R-M-W performance (cached should be quicker).\n");
    for (j = 0; j < 3; j++) {
        printf("R-M-W noncached buffer %lx\n", physp_nocache);
        gettimeofday(&start_tv, NULL);
        for (i = 0; i < (size / sizeof(int)); i += 1) {
            ptr1_nocache[i] += 1;
        }
        gettimeofday(&end_tv, NULL);
        diff = end_tv.tv_usec - start_tv.tv_usec;
        if (end_tv.tv_sec > start_tv.tv_sec) {
            diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
        }
        printf("  diff=%ld\n", diff);

        printf("R-M-W cached buffer %lx\n", physp_cache);
        gettimeofday(&start_tv, NULL);
        for (i = 0; i < (size / sizeof(int)); i += 1) {
            ptr1_cache[i] += 1;
        }
        gettimeofday(&end_tv, NULL);
        diff = end_tv.tv_usec - start_tv.tv_usec;
        if (end_tv.tv_sec > start_tv.tv_sec) {
            diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
        }
        printf("  diff=%ld\n", diff);
    }

    printf("Invalidate cached buffer %p\n", ptr1_cache);

    foo = *ptr1_cache;
    bar = foo;
    bar++;
    *ptr1_cache = bar;
    CMEM_cacheInv(ptr1_cache, size);
    printf("post-flush *ptr1_cache=0x%x\n", foo);
    printf("wrote 0x%x to *ptr1_cache\n", bar);
    printf("post-inv *ptr1_cache=0x%x\n", *ptr1_cache);

    printf("R-M-W cached buffer %lx\n", physp_cache);
    gettimeofday(&start_tv, NULL);
    for (i = 0; i < (size / sizeof(int)); i += 1) {
        ptr1_cache[i] += 1;
    }
    gettimeofday(&end_tv, NULL);
    diff = end_tv.tv_usec - start_tv.tv_usec;
    if (end_tv.tv_sec > start_tv.tv_sec) {
        diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
    }
    printf("  diff=%ld\n", diff);

    /* 
     * Now allocate another buffer by first finding out which pool that fits
     * best, and then explicitly allocating from that pool. This gives more
     * control at the cost of an extra function call, but essentially does
     * the same thing as the above CMEM_alloc() call.
     */
    printf("Allocating second buffer.\n");

    poolid = CMEM_getPool(size);

    if (poolid == -1) {
        fprintf(stderr, "Failed to get a pool which fits size %d\n", size);
        goto cleanup;
    }

    printf("Got a pool (%d) that fits the size %d\n", poolid, size);

    ptr2 = CMEM_allocPool(poolid, NULL);

    if (ptr2 == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr2);

    /* Find out and print the physical address of this buffer */
    physp = CMEM_getPhys(ptr2);

    if (physp == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr2);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp);

    /* Write some data into this buffer */
    for (i=0; i < size / sizeof(int); i++) {
        ptr2[i] = 0xfeebfeeb;
    }

    printf("Inspect your memory map in /proc/%d/maps.\n", getpid());
    printf("Also look at your pool info under /proc/cmem\n");
    printf("Press ENTER to exit (after 'cat /proc/cmem' if desired).\n");
    getchar();

cleanup:
    if (ptr1_nocache != NULL) {
        if (CMEM_free(ptr1_nocache, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_nocache);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_nocache);
    }

    if (ptr1_cache != NULL) {
        if (CMEM_free(ptr1_cache, &params) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_cache);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_cache);
    }

    if (ptr1_dma != NULL) {
        if (CMEM_free(ptr1_dma, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_dma);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_dma);
    }

    if (ptr2 != NULL) {
        if (CMEM_free(ptr2, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr2);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr2);
    }
}
/*
 * Construct new bufferpool and allocate buffers from driver
 *
 * @elem      the parent element that owns this buffer
 * @fd        the file descriptor of the device file
 * @count     the requested number of buffers in the pool
 * @caps      the requested buffer caps
 * @return the bufferpool or <code>NULL</code> if error
 */
GstBufferClassBufferPool *
gst_buffer_manager_new (GstElement * elem, int fd, int count, GstCaps * caps)
{
  GstBufferClassBufferPool *pool = NULL;
  GstVideoFormat format;
  gint width, height ;
  void          *vidStreamBufVa;
  unsigned long vidStreamBufPa;
  int n, i;
  gst_initpacket pack_info;
  if (gst_video_format_parse_caps(caps, &format, &width, &height)) {
    bc_buf_params_t param;

/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
    CMEM_init();

    vidStreamBufVa = CMEM_alloc((width*height*2*MAX_FCOUNT), &cmem_params);
    if (!vidStreamBufVa)
    {
        printf ("CMEM_alloc for Video Stream buffer returned NULL \n");
        return NULL; 
    }

    vidStreamBufPa = CMEM_getPhys(vidStreamBufVa);
    for (i = 0; i < count; i++)
    {
        TextureBufsPa[i] = vidStreamBufPa + (width*height*2*i);
    }
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
    param.count = count;
    param.width = width;     /* width should be multiple of 32 */
    param.height = height;
    
    switch(format)
    {
        case 3 :   param.fourcc = BC_PIX_FMT_YUYV;
                   break;

	case 22:   param.fourcc = BC_PIX_FMT_NV12;
		   break;

	case 4 :    param.fourcc = BC_PIX_FMT_UYVY;
                   break;

	default:   /* Uknown Format */
                   return -1;

    }
    param.type = BC_MEMORY_USERPTR;

    pack_info.params = param;
    pack_info.phyaddr = vidStreamBufPa;

    n = write(fd_bcinit_fifo, &pack_info, sizeof(gst_initpacket));

   if(n != sizeof(gst_initpacket))
   {
	printf("Error in writing to queue\n");
   }
	
  /* We no longer need this pipe */
   close(fd_bcinit_fifo);

    /* construct bufferpool */
    pool = (GstBufferClassBufferPool *)
        gst_mini_object_new (GST_TYPE_BCBUFFERPOOL);

//TODO: Remove fd from pool -not required any more.
    pool->fd = -1;
    pool->elem = elem;
    pool->num_buffers = param.count;


    GST_DEBUG_OBJECT (pool->elem, "orig caps: %" GST_PTR_FORMAT, caps);
    GST_DEBUG_OBJECT (pool->elem, "requested %d buffers, got %d buffers", count,
        param.count);
    
    pool->caps = caps;

    /* and allocate buffers:
     */
    pool->num_buffers = param.count;
    pool->buffers = g_new0 (GstBufferClassBuffer *, param.count);
    pool->avail_buffers = g_async_queue_new_full (
        (GDestroyNotify) gst_mini_object_unref);

    for (i = 0; i < param.count; i++) {
     // TODO: Find correct size here
      GstBufferClassBuffer *buf = gst_bcbuffer_new (pool, i, param.width*param.height*2, TextureBufsPa[i]);
  GST_BUFFER_DATA (buf) = (vidStreamBufVa +  param.width*param.height*2*i);
  GST_BUFFER_SIZE (buf) = param.width*param.height*2;

      if (G_UNLIKELY (!buf)) {
        GST_WARNING_OBJECT (pool->elem, "Buffer %d allocation failed", i);
        goto fail;
      }
      gst_buffer_set_caps (GST_BUFFER (buf), caps);
      pool->buffers[i] = buf;
      g_async_queue_push (pool->avail_buffers, buf);
    }

    return pool;
  } else {
Exemplo n.º 21
0
Void *deiThrFxn(Void *arg)
{
	DeiEnv *envp = (DeiEnv *) arg;
	Void *status = THREAD_SUCCESS;

	Uint32 sysRegBase = 0;

	VIDENC1_Handle hDei = NULL;
	IDEI_Params deiParams;

	Uint16 frame_width = 0, frame_height = 0;
	Uint16 threshold_low = 0, threshold_high = 0;

	IVIDEO1_BufDescIn inBufDesc;	
	XDM_BufDesc outBufDesc;	
	XDAS_Int8 *outbufs[2];	
	XDAS_Int32 outBufSizeArray[2];
	VIDENC1_InArgs inArgs;
	IDEI_OutArgs outArgs;	
	Uint32 bufferSize;

	CMEM_AllocParams cmemPrm;
	Uint32 prevBufAddr, outBufAddr;

	Buffer_Handle cBuf, dBuf;

	Int ret = 0;

	int fd = -1;
	dm365mmap_params_t dm365mmap_params;
	pthread_mutex_t Dmai_DM365dmaLock = PTHREAD_MUTEX_INITIALIZER;

	/* ▼▼▼▼▼ Initialization ▼▼▼▼▼ */
	DM365MM_init(); printf("\n"); /* dm365mm issue */
	sysRegBase = DM365MM_mmap(0x01C40000, 0x4000);

	CMEM_init();
	cmemPrm.type = CMEM_HEAP;
	cmemPrm.flags = CMEM_NONCACHED;
	cmemPrm.alignment = 32;
	prevBufAddr = (Uint32)CMEM_alloc(IN_OUT_BUF_SIZE, &cmemPrm);
	outBufAddr = (Uint32)CMEM_alloc(IN_OUT_BUF_SIZE, &cmemPrm);

	frame_width = 720;
	frame_height = 576;
	threshold_low = 16;
	threshold_high = 20;

	/* Create DEI instance */	
	deiParams.videncParams.size = sizeof(IDEI_Params);
	deiParams.frameHeight = frame_height;
	deiParams.frameWidth = frame_width; 
	deiParams.inLineOffset = frame_width;
	deiParams.outLineOffset = (frame_width - 8);	
	deiParams.threshold_low = threshold_low;
	deiParams.threshold_high = threshold_high;

	deiParams.inputFormat = XDM_YUV_422ILE;	
	deiParams.outputFormat = XDM_YUV_420SP;
	
	deiParams.q_num = 1;
	deiParams.askIMCOPRes = 0; 
	deiParams.sysBaseAddr = sysRegBase;

	hDei = VIDENC1_create(envp->hEngine, "dei", (VIDENC1_Params *)&deiParams);						  
    if(hDei == NULL)
	{
		ERR("DEI alg creation failed\n");
        cleanup(THREAD_FAILURE);		
	}

	fd = open("/dev/dm365mmap", O_RDWR | O_SYNC);

	

	Rendezvous_meet(envp->hRendezvousInit);
	/* ▲▲▲▲▲ Initialization ▲▲▲▲▲ */
	while (1) {

		if (Fifo_get(envp->hFromCaptureFifo, &cBuf) < 0) {
			ERR("Failed to get buffer from capture thread\n");
			cleanup(THREAD_FAILURE);
		}

		if (Fifo_get(envp->hFromDisplayFifo, &dBuf) < 0) {
			ERR("Failed to get buffer from display thread\n");
			cleanup(THREAD_FAILURE);
		}

		inBufDesc.numBufs = 4;

		bufferSize = (frame_width * frame_height);
		
		inBufDesc.bufDesc[0].bufSize = bufferSize;
		inBufDesc.bufDesc[0].buf = (XDAS_Int8 *)Buffer_getUserPtr(cBuf);
		inBufDesc.bufDesc[0].accessMask = 0;

		inBufDesc.bufDesc[1].bufSize = bufferSize;
		inBufDesc.bufDesc[1].buf = (XDAS_Int8 *)(Buffer_getUserPtr(cBuf) + bufferSize);
		inBufDesc.bufDesc[1].accessMask = 0;

		inBufDesc.bufDesc[2].bufSize = bufferSize;
		inBufDesc.bufDesc[2].buf = (XDAS_Int8 *)prevBufAddr;
		inBufDesc.bufDesc[2].accessMask = 0;

		inBufDesc.bufDesc[3].bufSize = bufferSize;
		inBufDesc.bufDesc[3].buf = (XDAS_Int8 *)(prevBufAddr + bufferSize);
		inBufDesc.bufDesc[3].accessMask = 0;	
		
		/* Output buffers */
		outBufDesc.numBufs = 2;
		outbufs[0] = (XDAS_Int8*)outBufAddr;
		outbufs[1] = (XDAS_Int8*)(outBufAddr + bufferSize);
		outBufSizeArray[0] = bufferSize;
		outBufSizeArray[1] = bufferSize / 2;

		outBufDesc.bufSizes = outBufSizeArray;
		outBufDesc.bufs = outbufs;

		inArgs.size = sizeof(VIDENC1_InArgs);
		outArgs.videncOutArgs.size = sizeof(IDEI_OutArgs);

		ret = VIDENC1_process((VIDENC1_Handle)hDei,
								 &inBufDesc,
								 &outBufDesc,
								 &inArgs,
								 (IVIDENC1_OutArgs *)&outArgs);
		if (ret != VIDENC1_EOK) {
			ERR("DEI process failed\n");
			cleanup(THREAD_FAILURE);
		}

		dm365mmap_params.src = CMEM_getPhys(outbufs[0]);
		dm365mmap_params.srcmode = 0;
		dm365mmap_params.dst = Buffer_getPhysicalPtr(dBuf);
		dm365mmap_params.dstmode = 0;
		dm365mmap_params.srcbidx = 712;
		dm365mmap_params.dstbidx = 704;
		dm365mmap_params.acnt = 704;
		dm365mmap_params.bcnt = 576;
		dm365mmap_params.ccnt = 1;
		dm365mmap_params.bcntrld = dm365mmap_params.bcnt;
		dm365mmap_params.syncmode = 1;

		pthread_mutex_lock(&Dmai_DM365dmaLock);
		if (ioctl(fd, DM365MMAP_IOCMEMCPY, &dm365mmap_params) == -1) {
        	ERR("memcpy: Failed to do memcpy\n");
        	cleanup(THREAD_FAILURE);
    	}
		pthread_mutex_unlock(&Dmai_DM365dmaLock);

    	dm365mmap_params.src = CMEM_getPhys(outbufs[1]);
    	dm365mmap_params.srcmode = 0;
    	dm365mmap_params.dst = Buffer_getPhysicalPtr(dBuf) + (Buffer_getSize(dBuf) * 2 / 3);
    	dm365mmap_params.dstmode = 0;
    	dm365mmap_params.srcbidx = 712;
		dm365mmap_params.dstbidx = 704;
    	dm365mmap_params.acnt = 712;
    	dm365mmap_params.bcnt = 570 / 2;
    	dm365mmap_params.ccnt = 1;
    	dm365mmap_params.bcntrld = dm365mmap_params.bcnt;
    	dm365mmap_params.syncmode = 1;

		pthread_mutex_lock(&Dmai_DM365dmaLock);
		if (ioctl(fd, DM365MMAP_IOCMEMCPY, &dm365mmap_params) == -1) {
        	ERR("memcpy: Failed to do memcpy\n");
        	cleanup(THREAD_FAILURE);
    	}
		pthread_mutex_unlock(&Dmai_DM365dmaLock);
    	Buffer_setNumBytesUsed(dBuf, 704 * 576 * 3 / 2);

    	dm365mmap_params.src = Buffer_getPhysicalPtr(cBuf);
    	dm365mmap_params.srcmode = 0;
    	dm365mmap_params.dst = prevBufAddr;
    	dm365mmap_params.dstmode = 0;
    	dm365mmap_params.srcbidx = 1440;
		dm365mmap_params.dstbidx = 1440;
    	dm365mmap_params.acnt = 1440;
    	dm365mmap_params.bcnt = 576;
    	dm365mmap_params.ccnt = 1;
    	dm365mmap_params.bcntrld = dm365mmap_params.bcnt;
    	dm365mmap_params.syncmode = 1;

    	pthread_mutex_lock(&Dmai_DM365dmaLock);
		if (ioctl(fd, DM365MMAP_IOCMEMCPY, &dm365mmap_params) == -1) {
        	ERR("memcpy: Failed to do memcpy\n");
        	cleanup(THREAD_FAILURE);
    	}
		pthread_mutex_unlock(&Dmai_DM365dmaLock);

		/* Send buffer to display thread */
		if (Fifo_put(envp->hToDisplayFifo, dBuf) < 0) {
			ERR("Failed to send buffer to dei thread\n");
			cleanup(THREAD_FAILURE);
		}

		/* Send buffer to display thread */
		if (Fifo_put(envp->hToCaptureFifo, cBuf) < 0) {
			ERR("Failed to send buffer to dei thread\n");
			cleanup(THREAD_FAILURE);
		}

	}

cleanup:
	Rendezvous_force(envp->hRendezvousInit);
	Rendezvous_meet(envp->hRendezvousCleanup);

	/* Delete DEI ALG instance */
	VIDENC1_delete(hDei);

	DM365MM_ummap(sysRegBase,0x4000);

	DM365MM_exit();

	if (fd > 0) {   
        close(fd);
    }

	return status;
}
int rebuild_jpg_config_para(jpeg_data_t  *jpeg_data,jpegdec_config_t *config)
{
	int ret = 0;
	if((scale_w*jpeg_data->info.height)!= (scale_h*jpeg_data->info.width)){
	    sMode =  IGNOREASPECTRATIO;   	        
    }else{
        sMode =  KEEPASPECTRATIO;   	 
    }
#ifdef JPEG_DBG    
    printf("current sMode is %d\n",sMode);	
#endif    
	switch(sMode){
	    case KEEPASPECTRATIO:
	    ret = compute_keep_ratio(jpeg_data,config);
	    break;
	    case IGNOREASPECTRATIO:
	    ret = compute_keep_ratio_by_expanding(jpeg_data,config);
	    if(ret < 0){
	        ret = compute_keep_ratio(jpeg_data,config);    
	    }
	    break;
	    case KEEPASPECTRATIOBYEXPANDING:
	    ret = compute_keep_ratio_by_expanding(jpeg_data,config);
	    if(ret < 0){
	        ret = compute_keep_ratio(jpeg_data,config);    
	    }
	    break;
	    default:
	    break;    
	}  
	if(config->dec_h<2) {
		printf("too small to decode with hwjpeg decoder.\n");
		return -1;
	}	
	config->canvas_width = CANVAS_ALIGNED(config->dec_w);	
	planes[0] = (unsigned char *)CMEM_alloc(0, 
				 config->canvas_width * config->dec_h, &cmemParm);
	planes[1] = (unsigned char *)CMEM_alloc(0,
				CANVAS_ALIGNED((config->canvas_width/2)) *config->dec_h/2, &cmemParm);
	planes[2] = (unsigned char *)CMEM_alloc(0,
				CANVAS_ALIGNED((config->canvas_width/2)) * config->dec_h/2, &cmemParm);
	if ((!planes[0]) || (!planes[1]) || (!planes[2])) {
		printf("Not enough memory\n");
		if (planes[0])
			CMEM_free(planes[0], &cmemParm);
		if (planes[1])
			CMEM_free(planes[1], &cmemParm);
		if (planes[2])
			CMEM_free(planes[2], &cmemParm);
		return -1;
	}
	config->addr_y = CMEM_getPhys(planes[0]);
	config->addr_u = CMEM_getPhys(planes[1]);
	config->addr_v = CMEM_getPhys(planes[2]);
	
	if(config->dec_w==0 ||config->dec_h==0)
	{
		config->dec_w= jpeg_data->info.width;
		config->dec_h= jpeg_data->info.height;
	}
//	scaleSize(config->dec_w, config->dec_h, jpeg_data->info.width, jpeg_data->info.height, (Qt::AspectRatioMode)config->opt);
	config->opt = 0;
	config->dec_x = 0;
	config->dec_y = 0;
	config->angle = CLKWISE_0;
	clear_plane(0,config);
	clear_plane(1,config);
	clear_plane(2,config);
	return 0;	
}
aml_image_info_t* read_jpeg_image_rgb_test(char* url , int width, int height,int mode , int flag)
{    
    aml_image_info_t* output_image_info;
    output_image_info = (aml_image_info_t*)malloc(sizeof(aml_image_info_t));
    memset((char*)output_image_info , 0 , sizeof(aml_image_info_t));   
/*default para*/	
    if((width <= 0)||(height <=0)||(mode > 2) ){
    	 width = 1280;
    	 height = 720;		
    	 mode = KEEPASPECTRATIO;
	}

     int wait_timeout = 0 ;
     char* outimage = NULL; 

     int fd = open(url,O_RDWR ) ; 
     if(fd < 0){
        goto exit;   
     }
     printf("open 15.jpeg sucessfuly\n");
	//we need some step to decompress jpeg image to output 
	// 1  request yuv space from cmem to store decompressed data
	// 2  config and decompress jpg picture.
	// 3	 request  new rgb space from cmem to store output rgb data.
	// 4  ge2d move yuv data to rgb space.
	// 5  release request mem to cmem module.
	jpegdec_config_t  config;
	jpeg_data_t  jpeg_data;
	int fd_ge2d=-1;
	config_para_t ge2d_config;
	int format;
    	ge2d_op_para_t op_para;
	int bpl 	 ;

	memset((char*)&ge2d_config,0,sizeof(config_para_t));	
	scale_x = 0;
	scale_y = 0;
	scale_w = width;
	scale_h = height;	
/*default value for no scaler input*/	
#if 1
	if(scale_w>0 && scale_w<=200 && scale_h>0 && scale_h<=200)  {
		decoder_opt=JPEGDEC_OPT_THUMBNAIL_PREFERED;
	} else {
		decoder_opt=0;
	}
#else
	decoder_opt=0;
#endif
	if((scale_w == 0)||(scale_h ==0)){
	    scale_w  = 160 ;
	    scale_h  = 100;     
	}
	config.opt=(unsigned)sMode ;
	jpeg_data.fd_amport=fd_amport;
	if(!(JPEGDEC_STAT_DONE&read_jpeg_data(fd,&jpeg_data,DEC_STAT_MAX,&config)))
	{
#ifdef JPEG_DBG 	    
		printf("can't decode jpg pic");	
#endif			
		goto exit;
	}

#ifdef JPEG_DBG 	
	printf("deocde jpg pic completed");
#endif
	planes[3]=(unsigned char *)CMEM_alloc(0,CANVAS_ALIGNED(scale_w)*scale_h*4,&cmemParm);
	if(!planes[3])
	{
#ifdef JPEG_DBG 	    
		printf("can't get rgb memory from heap");
#endif		
		goto exit;
	}
#ifdef JPEG_DBG 	
	printf("planes[3]=(unsigned char *)CMEM_alloc(0,%d * %d *4,&cmemParm)\n",scale_w ,scale_h); 
#endif	
 	clear_plane(3,&config);

	//open fb device to handle ge2d op FILE_NAME_GE2D
    fd_ge2d= open(FILE_NAME_GE2D, O_RDWR);
//#ifdef JPEG_DBG     
//    printf("fd_ge2d= open(%s, O_RDWR)\n",dev.toLatin1().constData());
//#endif    
	if(fd_ge2d<0)
	{
#ifdef JPEG_DBG 	    
		printf("can't open framebuffer device" );  	
#endif			
		goto exit;
	}
/*antiflicking setting*/	
    if(flag){
	    ioctl(fd_ge2d,FBIOPUT_GE2D_ANTIFLICKER_ENABLE,1);    
	}else{
	    ioctl(fd_ge2d,FBIOPUT_GE2D_ANTIFLICKER_ENABLE,0);   
	}
	if(jpeg_data.info.comp_num==3 ||jpeg_data.info.comp_num==4)
	{
		format = Format_RGB32;
	}else{
#ifdef JPEG_DBG 	
		printf("unsupported color format" );  	
#endif		
		goto exit;
	}
#ifdef JPEG_DBG 	
	printf("start ge2d image format convert!!!!!\n");
#endif	
	ge2d_config.src_dst_type = ALLOC_ALLOC;
//    ge2d_config.src_dst_type = ALLOC_OSD1;        //only for test
	ge2d_config.alu_const_color=0xff0000ff;
	ge2d_config.src_format = GE2D_FORMAT_M24_YUV420;
	ge2d_config.dst_format = ImgFormat2Ge2dFormat(format);
	if(0xffffffff==ge2d_config.dst_format)
	{
#ifdef JPEG_DBG 	    
		printf("can't get proper ge2d format" );  	
#endif			
		goto exit;
	}

	ge2d_config.src_planes[0].addr = config.addr_y;
	ge2d_config.src_planes[0].w =    config.canvas_width;
	ge2d_config.src_planes[0].h =    config.dec_h;
	ge2d_config.src_planes[1].addr = config.addr_u;
	ge2d_config.src_planes[1].w =    config.canvas_width/2;
	ge2d_config.src_planes[1].h =    config.dec_h / 2;

	ge2d_config.src_planes[2].addr = config.addr_v;
	ge2d_config.src_planes[2].w = config.canvas_width/2;
	ge2d_config.src_planes[2].h = config.dec_h / 2;
	ge2d_config.dst_planes[0].addr=CMEM_getPhys(planes[3]);	
	ge2d_config.dst_planes[0].w=  scale_w;
	ge2d_config.dst_planes[0].h = scale_h;
//#ifdef JPEG_DBG 	
//	printf("planes[3]addr : 0x%x-0x%x" ,planes[3],ge2d_config.dst_planes[0].addr);		
//#endif	
	ioctl(fd_ge2d, FBIOPUT_GE2D_CONFIG, &ge2d_config);
/*crop case*/	
	if((config.dec_w > scale_w )||(config.dec_h > scale_h)){
    	op_para.src1_rect.x = (config.dec_w - scale_w)>>1;
    	op_para.src1_rect.y = (config.dec_h - scale_h)>>1;
    	op_para.src1_rect.w = scale_w;
    	op_para.src1_rect.h = scale_h;
    	op_para.dst_rect.x = 0;
    	op_para.dst_rect.y = 0;
    	op_para.dst_rect.w = scale_w;
    	op_para.dst_rect.h = scale_h;		    
	}else{	
Exemplo n.º 24
0
int testMap(size_t size)
{
    unsigned int *ptr;
    unsigned int *map_ptr;
#if defined(LINUXUTILS_BUILDOS_ANDROID)
    off64_t physp;
#else
    off_t physp;
#endif
    int ret = 0;

    ptr = CMEM_alloc(size, NULL);
    printf("testMap: ptr = %p\n", ptr);

    if (ptr == NULL) {
	printf("testMap: CMEM_alloc() failed\n");
	return 1;
    }

    printf("    writing 0xdadaface to *ptr\n");
    *ptr = 0xdadaface;

#if defined(LINUXUTILS_BUILDOS_ANDROID)
    physp = CMEM_getPhys64(ptr);
    map_ptr = CMEM_map64(physp, size);
#else
    physp = CMEM_getPhys(ptr);
    map_ptr = CMEM_map(physp, size);
#endif
    if (map_ptr == NULL) {
	printf("testMap: CMEM_map() failed\n");
	ret = 1;
	goto cleanup;
    }
    else {
	printf("testMap: remapped physp %#llx to %p\n",
		physp, map_ptr);
	printf("    *map_ptr = 0x%x\n", *map_ptr);
    }

    if (*map_ptr != 0xdadaface) {
	printf("testMap: failed, read didn't match write\n");
	ret = 1;
    }

    CMEM_unmap(map_ptr, size);

    if (*ptr != 0xdadaface) {
	printf("testMap: after unmap *ptr != 0xdadaface\n");
	ret = 1;
	goto cleanup;
    }
    else {
	printf("testMap: original pointer still good\n");
    }

    printf("testMap: trying to map too much (0x%x)...\n", size * 0x10);
#if defined(LINUXUTILS_BUILDOS_ANDROID)
    map_ptr = CMEM_map64(physp, size * 0x10);
#else
    map_ptr = CMEM_map(physp, size * 0x10);
#endif
    if (map_ptr != NULL) {
	printf("testMap: CMEM_map() should've failed but didn't\n");
	CMEM_unmap(map_ptr, size * 0x10);
	ret = 1;
    }

cleanup:
    CMEM_free(ptr, NULL);

    return ret;
}
/* ARGSUSED - this line tells the compiler not to warn about unused args. */
IRES_Status IRESMAN_MEMTCM_init(IRESMAN_Params * initArgs) 
{

    SMGRMP_Attrs attrs;
    IRESMAN_MemTcmParams * resmanArgs = (IRESMAN_MemTcmParams *)initArgs;
    /* CMEM_AllocParams params; */
    
    GT_assert(ti_sdo_fc_ires_memtcm, initArgs != NULL);

    /* 
     *  Check if already initialized
     */
    if (_initialized) {

        GT_0trace(CURTRACE, GT_ENTER, 
                "IRESMAN_MEMTCM_init> Exit (status=IRES_EEXISTS)\n"); 

        return (IRES_EEXISTS); 

    }

    if (gtInit == 0) {

        GT_init();

        GT_create(&CURTRACE, "ti.sdo.fc.ires.memtcm");
    
        gtInit = 1;
    }

    GT_1trace(CURTRACE, GT_ENTER, 
            "IRESMAN_MEMTCM_init> Enter (initArgs=0x%x)\n", initArgs); 
    
    /*
     * Information regarding the memory allocation/free functions
     * is stored as part of the internal state of the resource
     * manager
     */
    if (NULL == _MEMTCM_lock) {

        /* Create a lock for protecting MEMTCM internal state object */
        _MEMTCM_lock = LockMP_create(_MEMTCM_LOCKID);
 
        if (_MEMTCM_lock == NULL) {
 
            GT_1trace(CURTRACE, GT_7CLASS,
                    "IRESMAN_MEMTCM_init> Failed to create IPC lock, "
                    "key = 0x%x\n", _MEMTCM_LOCKID);

            GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status="
                    "IRES_EFAIL)\n");
 
            return (IRES_EFAIL);
        }
    }

    getInternalState();

    if (NULL == _resmanInternalState) {

        GT_0trace(CURTRACE, GT_7CLASS,
                "IRESMAN_MEMTCM_init>Failed to obtain Internal state Object\n");

        GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status="
                "IRES_EFAIL)\n");

        LockMP_delete(_MEMTCM_lock);

        return (IRES_EFAIL);
    }

    /*
     * Information regarding the memory allocation/free functions
     */
    _allocFxn = resmanArgs->baseConfig.allocFxn;

    _freeFxn = resmanArgs->baseConfig.freeFxn;


    if (0 != CMEM_init()) {

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_MEMTCM_init> Could not initialize CMEM\n"); 

        GT_0trace(CURTRACE, GT_ENTER, 
                "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); 

        freeInternalState();

        LockMP_delete(_MEMTCM_lock);

        return (IRES_EFAIL);
    }

/* TODO: Figure out how to populate the params */ 
    if (_resmanInternalState->numOpens == 0) {

        armtcmAddr = CMEM_alloc2(MEMTCM_blockId, MEMTCM_size, NULL);

        _resmanInternalState->armtcmAddr = (void *)CMEM_getPhys(armtcmAddr);
    }
    else {

        armtcmAddr = CMEM_registerAlloc(
                (unsigned long)_resmanInternalState->armtcmAddr);
    }

    if (NULL == armtcmAddr) {

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_MEMTCM_init> Could not allocate TCM memory from CMEM"
                "\n"); 

        GT_0trace(CURTRACE, GT_ENTER, 
                "IRESMAN_MEMTCM_init> Exit (status=IRES_EFAIL)\n"); 

        freeInternalState();

        LockMP_delete(_MEMTCM_lock);

        return (IRES_EFAIL);
    }

    if (NULL == smgr) {

        attrs.numScratchGroups = MEMTCM_NUM_GROUPS;
        attrs.numResources = (MEMTCM_NUMRES);
                                     /* One resource corresponds to a 1/2 K
                                        chunk of memory (0x200), Manage memory
                                        in chunks of 0x200
                                      */
        attrs.lock = _MEMTCM_lock;

        attrs.key = (void *)_MEMTCM_MEMID;    /* A key specific to the resource 
                                                being managed */ 

        /* This will create a new resource manager or return a process-specific 
           handle to an existing smgr */ 
        smgr = SMGRMP_create(&attrs);

        if (NULL == smgr) {

            GT_0trace(CURTRACE, GT_7CLASS, "IRESMAN_MEMTCM_init> Error creating"
                    " scratch resource manager.\n");

            GT_0trace(CURTRACE, GT_ENTER, "IRESMAN_MEMTCM_init> Exit (status="
                    "IRES_EFAIL)\n");

            freeInternalState();

            LockMP_delete(_MEMTCM_lock);

            return (IRES_EFAIL);
        }
    }

    _resmanInternalState->numOpens++;

    /*
     * Set Initalized flag to 1 if successful
     */
     _initialized = 1;

     GT_0trace(CURTRACE, GT_ENTER, 
            "IRESMAN_MEMTCM_init> Exit (status=IRES_OK)\n"); 

     return (IRES_OK);
}