예제 #1
0
GLPowerVRWidget::GLPowerVRWidget(int argc, char *argv[], QWidget *parent) :
    GLWidget(argc, argv, parent)
{
    if(CMEM_init() == -1)
    {
        LOG(LOG_GL, Logger::Error, "Error calling CMEM_init");
        close();
    }
}
예제 #2
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;
}
/* 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);
}
/*
 *  ======== MEMUTILS_cacheInv ========
 */
Void MEMUTILS_cacheInv(Ptr addr, Int sizeInBytes)
{
    if (!regInit) {
        addModule();
    }

    CMEM_init();
    CMEM_cacheInv(addr, sizeInBytes);
    CMEM_exit();
}
/*******************************************************************************
 * 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;
}
/*
 *  ======== MEMUTILS_cacheInv ========
 */
Void MEMUTILS_cacheInv(Ptr addr, Int sizeInBytes)
{
#if GT_TRACE
    if (!(gtInit)) {
        GT_init();
        GT_create(&curTrace, "ti.sdo.fc.memutils");
        gtInit = 1;
    }    
#endif
    CMEM_init();
    CMEM_cacheInv(addr, sizeInBytes);
    CMEM_exit();
}
예제 #7
0
파일: apitest.c 프로젝트: black1tulip/DVSDK
int main(int argc, char *argv[])
{
    int size;
    int version;
    CMEM_BlockAttrs attrs;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of bytes to allocate>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    size = atoi(argv[1]);

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
        fprintf(stderr, "Failed to retrieve CMEM version\n");
    }
    printf("CMEM version = 0x%x\n", version);

    if (CMEM_getBlockAttrs(0, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 0 bounds\n");
    }
    printf("CMEM memory block 0: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    if (CMEM_getBlockAttrs(1, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 1 bounds\n");
    }
    printf("CMEM memory block 1: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    testHeap(size, 0);
    testHeap(size, 1);

    testCache(size, 0);
    testCache(size, 1);

    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }

    exit(EXIT_SUCCESS);
}
예제 #8
0
파일: main_host.c 프로젝트: liyaoshi/ipcdev
/*
 *  ======== main ========
 */
Int main(Int argc, Char* argv[])
{
    Int status;

    printf("--> main:\n");

    /* parse command line */
    status = Main_parseArgs(argc, argv);

    if (status < 0) {
        goto leave;
    }

    status = CMEM_init();
    if (status < 0) {
        printf("CMEM_init failed\n");
        goto leave;
    }
    else {
        printf("CMEM_init success\n");
    }

    /* configure the transport factory */
    Ipc_transportConfig(&TransportRpmsg_Factory);

    /* IPC initialization */
    status = Ipc_start();

    if (status >= 0) {
        /* application create, exec, delete */
        status = Main_main();

        /* Ipc finalization */
        Ipc_stop();
    }
    else {
        printf("Ipc_start failed: status = %d\n", status);
        goto leave;
    }

leave:
    printf("<-- main:\n");
    status = (status >= 0 ? 0 : status);

    return (status);
}
예제 #9
0
/*
 *  ======== Memory_init ========
 */
Bool Memory_init(Void)
{
    Registry_Result   result;

    /*
     *  No need to reference count for Registry_addModule(), since there
     *  is no way to remove the module.
     */
    if (regInit == 0) {
        /* Register this module for logging */
        result = Registry_addModule(&ti_sdo_ce_osal_Memory_desc,
                Memory_MODNAME);
        Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);

        if (result == Registry_SUCCESS) {
            /* Set the diags mask to the CE default */
            CESettings_init();
            CESettings_setDiags(Memory_MODNAME);
        }
        regInit = 1;
    }

    if (curInit != TRUE) {
        curInit = TRUE;
        moduleLock = Lock_create(NULL);
        if (moduleLock == NULL) {
            Log_print0(Diags_USER7, "[+7] Memory_init> "
                    "ERROR: could not create pthread mutex.");
            assert(FALSE);
        }

        if (CMEM_init() == -1) {
            Log_print0(Diags_USER7, "[+7] Memory_init> "
                    "ERROR: Failed to initialize CMEM");
        }
        else {
            cmemInitialized = TRUE;
        }

        Global_atexit((Fxn)cleanup);
    }

    return (cmemInitialized);
}
예제 #10
0
파일: ApproDrvMsg.c 프로젝트: 119/ipnc
/**
 * @brief Initiliztion of the message driver for Appro interface
 *
 *
 * @param   proc_id    message type id of the proceess, defined at ipnc_app/include/Stream_Msg_Def.h
 *
 * @return 0 is ok and -1 is error
 *
 *
 */
int ApproDrvInit(int proc_id)
{
	if(proc_id < MSG_TYPE_MSG1 || proc_id > 20){
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	gProcId = proc_id;
	fprintf(stderr, "%s: %d\n", __func__, proc_id);
#if ENABLE_CMEM
	/* CMEM only one init is allowed in each process */
	if(Testflag==0)
	{
		if(CMEM_init() < 0){
			gProcId = MSG_TYPE_MSG1;
			return -1;
		}
	}
#endif
	Testflag = 1;;
	if(hndlApproDrvSem == NULL)
		hndlApproDrvSem = MakeSem();
	if(hndlApproDrvSem == NULL){
#if ENABLE_CMEM
		CMEM_exit();
#endif
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	printf("Msg_Init Begin\n");
	if((qid=Msg_Init(MSG_KEY)) < 0){
		DestroySem(hndlApproDrvSem);
		hndlApproDrvSem = NULL;
#if ENABLE_CMEM
		CMEM_exit();
#endif
		gProcId = MSG_TYPE_MSG1;
		return -1;
	}
	printf("Msg_Init Done\n");
	return 0;
}
int amljpeg_init()
{
    int i = 0;
#ifdef JPEG_DBG     
    printf("last fd_amport is (%d).\n",fd_amport);
	printf("------------HWJpegDec Init----------------\n");
#endif    
    fd_amport = open(FILE_NAME_AMPORT, O_RDWR);
	if(fd_amport<0) {
#ifdef JPEG_DBG 	    
		printf("hw jpeg init decoder error---amport access error\n");
#endif		
		return;
	}
	cmemParm.type=CMEM_HEAP; cmemParm.flags=CMEM_NONCACHED; cmemParm.alignment=8;
	planes[0] = planes[1]= planes[2]= planes[3]=NULL;
	if(CMEM_init())
    {
#ifdef JPEG_DBG         
		printf("hw jpeg init decoder error---cmem init error\n");
#endif  		
		return;	
    }	

	
    //init amport for write device data.	
    ioctl(fd_amport, AMSTREAM_IOC_VB_SIZE, 1024*1024);
    ioctl(fd_amport, AMSTREAM_IOC_VFORMAT, VFORMAT_JPEG); 
    ioctl(fd_amport, AMSTREAM_IOC_PORT_INIT);
    while(access(FILE_NAME_JPEGDEC, R_OK|W_OK)){	 //waitting for device created.
      	i ++;
//		usleep(1000);
      	if(i>1000)
      	{
#ifdef JPEG_DBG       	    
			printf("hw jpeg init decoder error---hw jpeg device access error\n");
#endif			
			return;
      	}
    }    
}
/*
 *  ======== 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);
}
예제 #13
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");
}
/*
 *  ======== 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();
}
예제 #15
0
int main()
{
    CERuntime_init();
    CMEM_init();

#ifdef CE_TEST
    CERuntime_init();
    CERuntime_exit();
    CERuntime_init();
    CERuntime_exit();
#endif

    /* initialize libavcodec, and register all codecs and formats */
    av_register_all();

    /* TODO: can't run both yet, some problem with CE init and exit */
    ff_example("test.avi", "avi");
//    decode_example("test.mkv");

    CMEM_exit();
    CERuntime_exit();
    return 0;
}
/*******************************************************************************
 * 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);
}
예제 #18
0
DvevmStRetCode
dvtb_initApp(void)
{
	DvevmStRetCode rc = DVEVM_ST_FAIL;
	IRESMAN_MemTcmParams memTcmConfigParams;

	dvtb_ceRuntimeInit(&G->eng);

	CMEM_init( );

	rc = dvtb_initParams( );
	ASSERT(rc != DVEVM_ST_FAIL);

	if (RMAN_init( ) != IRES_OK)
	{
		SYS_ERROR("Cannot Init RMAN.\n");
		return DVEVM_ST_FAIL;
	} else
		SYS_OUT("RMAN initialized.\n");

	/*
	 * Register IRES components
	 */
	memTcmConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
	memTcmConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
	memTcmConfigParams.baseConfig.size = sizeof(IRESMAN_MemTcmParams);;

	if (RMAN_register(&IRESMAN_MEMTCM, (IRESMAN_Params *) &memTcmConfigParams) != IRES_OK)
	{
		SYS_ERROR("MEMTCM Protocol Registration Failed \n");
		return DVEVM_ST_FAIL;
	}
	SYS_DEBUG("MEMTCM Protocol Registration Success \n");

	return DVEVM_ST_SUCCESS;
}
예제 #19
0
파일: apitest.c 프로젝트: zandrey/ti-ludev
int main(int argc, char *argv[])
{
    size_t size;
    int version;
    CMEM_BlockAttrs attrs;
    int i;
    int c;
    
    non_interactive_flag = FALSE;

    while ((c = getopt(argc, argv, "n")) != -1) {
	switch (c) {
	case 'n':
	    non_interactive_flag = TRUE; 	
	    break;

	default:
	    fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
		    argv[0]);
	    fprintf(stderr,
                    "    -n: non-interactive mode (no ENTER prompts)\n");
	    exit(EXIT_FAILURE);
	}
    }

    if ((argc - optind + 1) != 2) {
	fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
	        argv[0]);
	fprintf(stderr, "    -n: non-interactive mode (no ENTER prompts)\n");
	exit(EXIT_FAILURE);
    }

    errno = 0;
    size = strtol(argv[optind], NULL, 0);

    if (errno) {
	fprintf(stderr, "Bad argument ('%s'), strtol() set errno %d\n",
	        argv[optind], errno);
        exit(EXIT_FAILURE);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
	fprintf(stderr, "Failed to retrieve CMEM version\n");
        exit(EXIT_FAILURE);
    }
    printf("CMEM version = 0x%x\n", version);

    testMap(size);
    testAllocPhys(size);

    testCMA(size);

    if (CMEM_getNumBlocks(&nblocks)) {
	fprintf(stderr, "Failed to retrieve number of blocks\n");
        exit(EXIT_FAILURE);
    }
    printf("\n# of CMEM blocks (doesn't include possible CMA global 'block'): %d\n", nblocks);

    if (nblocks) {
	for (i = 0; i < nblocks; i++) {
	    if (CMEM_getBlockAttrs(i, &attrs) == -1) {
		fprintf(stderr, "Failed to retrieve CMEM memory block %d bounds\n", i);
	    }
	    else {
		printf("CMEM memory block %d: phys start = %#llx, size = %#llx\n",
		       i, (unsigned long long)attrs.phys_base, attrs.size);
	    }

	    testHeap(size, i);
	    testHeap(size, i);
	    testPools(size, i);
	    testPools(size, i);
	    testCache(size, i);
	}
    }
    else {
	printf("    no physical block found, not performing block-based testing\n");
    }

    /* block 'nblocks' is the special CMEM CMA "block" */
    testPools(size, CMEM_CMABLOCKID);

    printf("\nexiting...\n");
    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }
    printf("...test done\n");

    exit(EXIT_SUCCESS);
}
/*
 * 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 {
예제 #21
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;
}
/* 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);
}
예제 #23
0
int main(int argc, char *argv[])
{
    unsigned int *ptr = NULL;
    pid_t newPid = 0;
    int pid = 0;
    int numProcesses;
    int r;
    int i;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of processes to fork>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    numProcesses = atoi(argv[1]);

    for (i=0; i<numProcesses; i++) {
        newPid = fork(); 

        if (newPid == -1) {
            fprintf(stderr, "Failed to fork off new process\n");
            exit(EXIT_FAILURE);
        }
        else if (newPid == 0) {
            pid = i;
            break;
        }

        printf("Forked off process %d\n", newPid);
    }

    if (newPid != 0) {
        printf("Main process exiting\n");
        exit(EXIT_SUCCESS);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Process %d: Failed to initialize CMEM\n", pid);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: CMEM initialized.\n", pid);

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

    if (ptr == NULL) {
        fprintf(stderr, "Process %d: Failed to allocate buffer of size %d\n",
                pid, BUFFER_SIZE);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: Allocated buffer at %#x\n", pid, (unsigned int) ptr);

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

#if 0
    srand(pid * 1024);

    r = 1 + (int) (DELAYSPAN * (rand() / (RAND_MAX + 1.0)));
#else
    r = (pid * 3) + 3;
#endif

    printf("Process %d: Sleeping for %d seconds\n", pid, r);

    sleep(r);

    if (pid % 2) {
        printf("Process %d: Freeing buffer at %#x\n", pid, (unsigned int) ptr);

        if (CMEM_free(ptr, NULL) < 0) {
            fprintf(stderr, "Process %d: Failed to free buffer at %#x\n",
                    pid, (unsigned int) ptr);
        }
    }
    else {
        printf("Process %d: intentionally neglecting to call CMEM_free()\n",
               pid);
    }


    if (pid != 0) {
        printf("Process %d: Exiting CMEM\n", pid);
        if (CMEM_exit() < 0) {
            fprintf(stderr, "Process %d: Failed to finalize the CMEM module\n",
                    pid);
        }
    }
    else {
        printf("Process %d: sleeping 5 ...\n", pid);
        sleep(5);
        printf("Process %d: exiting, intentionally forgetting to call "
               "CMEM_exit()\n", pid);
    }

    exit(EXIT_SUCCESS);
}
예제 #24
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;
}
예제 #25
0
/*!****************************************************************************
 @Function		main
 @Input			argc		Number of arguments
 @Input			argv		Command line arguments
 @Return		int			result code to OS
 @Description	Main function of the program
******************************************************************************/
int main(int argc, char **argv)
{
	int testID = 0, err; //default
	char *extensions;
	unsigned int delta;
	NATIVE_PIXMAP_STRUCT* pNativePixmap = NULL;


	/* Initialise all globals */
	initialise_globals(&gTest);

	/* Pre init step - check the arguments */
	if(argc < 11)
	{
		SGXPERF_ERR_printf("Error: Invalid number of operands \n\n");
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
	testID = atol(argv[1]);
	if(testID > MAX_TEST_ID || testID < 0)
	{
		SGXPERF_ERR_printf("Error: No test available with this ID %d\n\n", testID);
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
	gTest.inNumberOfObjectsPerSide = atol(argv[7]);
	gTest.inSurfaceType = atol(argv[8]);

	if(argc < 4)
	{
		if(testID > 2) //1 and 2 do not need textures
		{
			SGXPERF_ERR_printf("Error: Invalid number of operands for selected testID %d\n\n", testID);
			SGXPERF_ERR_printf("%s",helpString);
			exit(-1);
		}
	}
	else
	{
		gTest.inTextureWidth = atol(argv[2]);
		gTest.inTextureHeight = atol(argv[3]);
	}
	gTest.inRotationEnabled = 0;
	//Rotation is unused in latest version
	if(argc >= 5)
		gTest.inRotationEnabled = atol(argv[4]);
	gTest.inPixelFormat = 0;
	if(argc >= 6)
		gTest.inPixelFormat = atol(argv[5]);
	if(gTest.inPixelFormat != SGXPERF_RGB565 && gTest.inPixelFormat != SGXPERF_ARGB8888 && gTest.inPixelFormat != SGXPERF_BYTE8)
	{
		SGXPERF_ERR_printf("Error: Unsupported pixel format for texture %d \n\n", gTest.inPixelFormat);
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
  
  //read extra params
  gTest.numTestIterations = atol(argv[9]);
  gTest.inFPS =atol(argv[10]); 
  gTest.msToSleep = 1000/gTest.inFPS;
  gTest.cookie = argv[11];
    
	if((gTest.inTextureWidth > 8000) || (gTest.inTextureHeight > 8000))
	{
		SGXPERF_ERR_printf("Error: Width or Height exceeds 8000 \n\n");
		SGXPERF_ERR_printf("%s",helpString);
		exit(-1);
	}
#ifndef _ENABLE_CMEM
	if(testID == 6 || testID == 7 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || 
                                    gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run native pixmap tests without CMEM\n");
		exit(-1);
	}
#endif
#ifndef _ENABLE_BUFFERCLASS
	if(testID == 8)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run test8 without BUFFERCLASS driver\n");
		exit(-1);
	}
#endif
	//for pixmap related tests, surface cannot be pixmap
	if(testID == 6 && gTest.inSurfaceType != SGXPERF_SURFACE_TYPE_WINDOW)
	{
		SGXPERF_ERR_printf("ERROR: Cannot run native pixmap eglimage test with pixmap surface\n");
		goto cleanup;
	}

  signal(SIGINT, sgxperf_signal_handler);

#ifdef _ENABLE_CMEM
	//Initialise the CMEM module. 
	//CMEM ko should be inserted before this point
	SGXPERF_printf("Configuring CMEM\n");
	CMEM_init();
#endif
	//Allocate texture for use in GL texturing modes(can also be done from CMEM if memory permits
	gTest._textureData = (unsigned int*)malloc(gTest.inTextureWidth*gTest.inTextureHeight*4 + PAGE_SIZE);
	if(!gTest._textureData)
	{
		SGXPERF_ERR_printf("ERROR: No malloc memory for allocating texture!\n");
		goto cleanup;
	}
	delta =(PAGE_SIZE - ((unsigned int)gTest._textureData &
(PAGE_SIZE-1))); 
	gTest.textureData = (unsigned int*)((char*)gTest._textureData + delta);
	memset(gTest.textureData, 0, gTest.inTextureWidth*gTest.inTextureHeight*4);

	set_texture(gTest.inTextureWidth, gTest.inTextureHeight, (unsigned char*)gTest.textureData, gTest.inPixelFormat);

	//initialise egl
	err = common_eglinit(&gTest, testID, gTest.inSurfaceType, &pNativePixmap);
	if(err)
	{
		SGXPERF_ERR_printf("ERROR: eglinit - err = %d\n", err);
		goto cleanup;
	}

	GLuint uiFragShader, uiVertShader;		// Used to hold the fragment and vertex shader handles
	GLuint uiProgramObject;					// Used to hold the program handle (made out of the two previous shaders

	// Create the fragment shader object
	uiFragShader = glCreateShader(GL_FRAGMENT_SHADER);

	// Load the source code into it
	if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7)  || 
        (testID == 14) || (testID == 17))
		glShaderSource(uiFragShader, 1, (const char**)&pszFragTextureShader, NULL);
	else if(testID == 11) //Edge detect with RGB input
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeRGBDetectShader, NULL);
	else if(testID == 12) //Edge detect with YUV input
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeYUVDetectShader, NULL);
	else if(testID == 8) //IMG texture stream2
		glShaderSource(uiFragShader, 1, (const char**)&pszFragIMGTextureStreamShader, NULL);
	else if(testID == 16) //EGLImage streaming
		glShaderSource(uiFragShader, 1, (const char**)&pszFragEGLImageShader, NULL);
	else
		glShaderSource(uiFragShader, 1, (const char**)&pszFragNoTextureShader, NULL);

	// Compile the source code
	glCompileShader(uiFragShader);

	// Check if compilation succeeded
	GLint bShaderCompiled;
    glGetShaderiv(uiFragShader, GL_COMPILE_STATUS, &bShaderCompiled);

	if (!bShaderCompiled)
	{
		// An error happened, first retrieve the length of the log message
		int i32InfoLogLength, i32CharsWritten;
		glGetShaderiv(uiFragShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength);

		// Allocate enough space for the message and retrieve it
		char* pszInfoLog = new char[i32InfoLogLength];
        glGetShaderInfoLog(uiFragShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog);

		// Displays the error
		SGXPERF_ERR_printf("Failed to compile fragment shader: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Loads the vertex shader in the same way
	uiVertShader = glCreateShader(GL_VERTEX_SHADER);
	if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7) || 
        (testID == 8) || (testID == 11) || (testID == 12)
           || (testID == 14) || (testID == 16) || (testID == 17))
		glShaderSource(uiVertShader, 1, (const char**)&pszVertTextureShader, NULL);
	else
	{
		SGXPERF_ERR_printf("INFO: Using no-texture vertex shader\n");
		glShaderSource(uiVertShader, 1, (const char**)&pszVertNoTextureShader, NULL);
	}

	glCompileShader(uiVertShader);
    glGetShaderiv(uiVertShader, GL_COMPILE_STATUS, &bShaderCompiled);

	if (!bShaderCompiled)
	{
		int i32InfoLogLength, i32CharsWritten;
		glGetShaderiv(uiVertShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
		char* pszInfoLog = new char[i32InfoLogLength];
        glGetShaderInfoLog(uiVertShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
		SGXPERF_ERR_printf("Failed to compile vertex shader: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Create the shader program
    uiProgramObject = glCreateProgram();

	// Attach the fragment and vertex shaders to it
    glAttachShader(uiProgramObject, uiFragShader);
    glAttachShader(uiProgramObject, uiVertShader);

	// Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY
	glBindAttribLocation(uiProgramObject, VERTEX_ARRAY, "inVertex");
	glBindAttribLocation(uiProgramObject, TEXCOORD_ARRAY, "inTexCoord");

	// Link the program
    glLinkProgram(uiProgramObject);

	// Check if linking succeeded in the same way we checked for compilation success
    GLint bLinked;
    glGetProgramiv(uiProgramObject, GL_LINK_STATUS, &bLinked);

	if (!bLinked)
	{
		int ui32InfoLogLength, ui32CharsWritten;
		glGetProgramiv(uiProgramObject, GL_INFO_LOG_LENGTH, &ui32InfoLogLength);
		char* pszInfoLog = new char[ui32InfoLogLength];
		glGetProgramInfoLog(uiProgramObject, ui32InfoLogLength, &ui32CharsWritten, pszInfoLog);
		SGXPERF_ERR_printf("Failed to link program: %s\n", pszInfoLog);
		delete [] pszInfoLog;
		goto cleanup;
	}

	// Actually use the created program
	glUseProgram(uiProgramObject);
#ifdef _ENABLE_TEST16
	if(testID == 16)
	{
		int sampler = glGetUniformLocation(uiProgramObject, "yuvTexSampler");
		glUniform1i(sampler, 0);
	}
#endif
	//set rotation variables to init
	gTest.matrixLocation = glGetUniformLocation(uiProgramObject, "MVPMatrix");
	memset(gTest.mat_final, 0, sizeof(gTest.mat_final));
	gTest.mat_final[0] = gTest.mat_final[5] = gTest.mat_final[10] = gTest.mat_final[15] = 1.0;
	glUniformMatrix4fv( gTest.matrixLocation, 1, GL_FALSE, gTest.mat_final);
	
	/* Set rowsize for edge detect */
	if(testID == 11)
	{
		glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 256.0);
		glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 256.0);
	}
	else if(testID == 12)
	{
		glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 128.0);
		glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 160.0);
	}
	/* Set clear */
	glClearColor(0.2f, 0.8f, 1.0f, 1.0f); // blueish greenish red :)
	glClear(GL_COLOR_BUFFER_BIT);

		/*
		Do various tests
		*/
		switch(testID)
		{
			case 0:
				extensions = (char*)glGetString(GL_EXTENSIONS);
				SGXPERF_ERR_printf("\nTESTID = 0: GL SUPPORTED EXTENSIONS = \n%s\n", extensions);
                                extensions = (char*)eglQueryString(gTest.eglDisplay, EGL_EXTENSIONS);
                                SGXPERF_ERR_printf("\nTESTID = 0: EGL SUPPORTED EXTENSIONS = \n%s\n", extensions);
				break;
			case 1:
				/* Fill entire screen with single colour, no objects */
				test1(&gTest);
				break;
			case 2:
				/* Draw a coloured rectangle filling entire screen */
				test2(&gTest);
				break;
			case 3:
				/* Move a coloured rectangle of half screen size to another half with same parameters */
				test3(&gTest);
				break;
			case 4:
				/* Alpha blending full surface texture */
				test4(&gTest);	
				break;
			case 5:
				/* Alpha blending full surface WITHOUT texture */
				test5(&gTest);
				break;
			case 8:
#ifdef _ENABLE_TEST8
				/* GL_IMG_texture_stream */
				test8(&gTest);
#endif
				break;
			case 10:
				/* PVR2D test */
				test10(&gTest);
				break;
			case 11:
				/* Edge detection test - test3 with new shader */
				test3(&gTest);
				break;
#ifdef _ENABLE_TEST8
			case 12:
				/* Edge detection test - test8 with new shader */
				test8(&gTest);
				break;
#endif
			case 13:
				/* Line drawing */
				test13(&gTest);
				break;
#ifdef _ENABLE_TEST14				
			case 14:
				/* Context Switch */
				test14(&gTest);
				break;
#endif				
#ifdef _ENABLE_TEST15
			case 15:
				/* YUV-RGB conversion with PVR2D */
				test15(&gTest);
				break;
#endif
#ifdef _ENABLE_TEST16
			case 16:
				/* YUV-Streaming with EGLImage */
				test16(&gTest);
				break;
#endif
#ifdef _ENABLE_TEST17
			case 17:
				/* FBO */
				test17(&gTest);
				break;
#endif
			default:
				/* Sorry guys, we tried ! */
				SGXPERF_ERR_printf("No matching test code\n");
				break;
		}
#ifdef _ENABLE_CMEM
	/* PIXMAP loopback test  */
	if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) 
	{
#if 1
		/* Use this for checking out the output in the pixmap */
		/* For DEBUGGING ONLY */
		FILE *fp = fopen("pixmap.raw", "wb");
		int numbytes;
		if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) numbytes = 4; //ARGB8888
		if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16) numbytes = 2; //RGB565
		SGXPERF_ERR_printf("Writing pixmap data to file pixmap.raw\n");
		fwrite((void*)pNativePixmap->lAddress, 1, gTest.inTextureWidth*gTest.inTextureHeight*numbytes, fp);
		fclose(fp);
#endif
	}
#endif //CMEM needed for pixmap loopback
	// Frees the OpenGL handles for the program and the 2 shaders
	glDeleteProgram(uiProgramObject);
	glDeleteShader(uiFragShader);
	glDeleteShader(uiVertShader);

cleanup:
	if(gTest._textureData) 
		free(gTest._textureData);
	common_egldeinit(&gTest, testID, pNativePixmap);
#ifdef _ENABLE_CMEM
	CMEM_exit();
#endif

	return 0;
}
예제 #26
0
/* Main Function acting as a client for Image Encode Call*/
XDAS_Int32 main(int argc, char *argv[])
{

    /* File I/O variables */
    FILE *fConfigFile, /**ftestFile, *finFile,*/ *fparamsFile;

#ifdef LINUX
    CMEM_AllocParams memParams;
    memParams.type=CMEM_POOL;
    memParams.flags=CMEM_NONCACHED;
    memParams.alignment=256;
#endif

    char* colorf[]={"YUV422P", "YUV420P", "YUV422P", "YUV422IL", "YUV422IL", "YUV444", "YUV411", "GRAY", "RGB", "YUV420_LINE"};
#ifdef LINUX
    XDAS_Int8 *fname = "../TestVecs/Config/Testvecs.cfg";
#else
    XDAS_Int8 *fname = "..\\..\\Test\\TestVecs\\Config\\Testvecs_ccs.cfg";
#endif
    Int32 lTemp,countConfigSet;
    Int32 retVal;
    Uint32 numAU, totalAU,repeat;
    Uint32 bytesGenerated;
    Uint16 mbSizeX, mbSizeY,mbY;

    char *RefBuffPtr;
    FILE *fp_out;
    FILE *fp_in;
    int processTime = 0, processTimeTotal = 0,algActivateTime =0, algDeactivateTime =0,copctime=0;
    int val,queue_word,queue_num=0,i,k;
    char baseParams[STRING_SIZE];
    int baseParamsOnly;
    int Offset;
    int num_markers;
    IIMGENC1_Fxns            *iimgEncfxns;
    IIMGENC1_Status  imgencStatus;
    IIMGENC1_InArgs imgencInArgs;
    IIMGENC1_OutArgs imgencOutArgs;
    IJPEGENC_Status          status;
    IJPEGENC_InArgs          inArgs;
    IJPEGENC_OutArgs         outArgs;
    unsigned int lTemp1;

    /*Algorithm specific handle */
    IALG_Handle handle;

    /* Input/Output Buffer Descriptor variables */
    XDM1_BufDesc inputBufDesc, outputBufDesc;


#ifdef ENABLE_RMAN // IRES/RMAN Related declarations
    // temp_trace_init();
    IRES_Status iresStatus;
    Int size =0;
    Int scratchId =0;
    Bool result = TRUE;
    IRES_Fxns *resFxns = &JPEGENC_TI_IRES;
    IRESMAN_Edma3ChanParams configParams;
    IRESMAN_VicpParams iresmanConfigParams;
    IRESMAN_AddrSpaceParams addrspaceConfigParams;

    iresStatus = RMAN_init();
    if (IRES_OK != iresStatus) {
        printf("RMAN initialization Failed \n");
        return -1;
    }
    printf("RMAN initialization done \n");

#ifndef LINUX
        /* Call the functions to enable ARM926 FIQ and do some basic
         * setup to AINTC to accept KLD INTC (arm968) interupt in 
         * FIQ pin of Arm926  
         */
        ARM926_enable_FIQ();  /* SWI call to enable interrupts */
        ARM926_INTC_init();  /* Init AINTC */
#endif

    /*
     * Supply initialization information for the RESMAN while registering
     */
    size = sizeof(IRESMAN_VicpParams);

    iresmanConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    iresmanConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    iresmanConfigParams.baseConfig.size = size;

    /* Register the VICP protocol/resource manager with the
    *      * generic resource manager */

    iresStatus = RMAN_register(&IRESMAN_VICP2, (IRESMAN_Params *)&iresmanConfigParams);

    if (IRES_OK != iresStatus) {
        printf("VICP Protocol Registration Failed \n");
        return -1;
    }
    printf("VICP Protocol Registration Success \n");
    /*
     *      * Supply initialization information for the EDMA3 RESMAN while registering
     *           */
    size = sizeof(IRESMAN_Edma3ChanParams);

    configParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    configParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    configParams.baseConfig.size = size;

    iresStatus = RMAN_register(&IRESMAN_EDMA3CHAN, (IRESMAN_Params *)&configParams);

    if (IRES_OK != iresStatus) {
        printf("EDMA3 Protocol Registration Failed \n");
        return -1;
    }
    printf("EDMA3 Protocol Registration Success \n");

    /** Supply initialization information for the ADDRSPACE RESMAN while registering
    	* */
#if 1
    size = sizeof(IRESMAN_AddrSpaceParams);
    addrspaceConfigParams.baseConfig.allocFxn = RMAN_PARAMS.allocFxn;
    addrspaceConfigParams.baseConfig.freeFxn = RMAN_PARAMS.freeFxn;
    addrspaceConfigParams.baseConfig.size = size;

    iresStatus = RMAN_register(&IRESMAN_ADDRSPACE, (IRESMAN_Params *)&addrspaceConfigParams);

    if (IRES_OK != iresStatus) {
        printf("ADDRSPACE Protocol Registration Failed \n");
        return -1;
    }
#ifdef _DBG_MSG
    printf("ADDRSPACE Protocol Registration Success \n");
#endif
#endif


#endif //IRES/RMAN related code ends here  


#ifdef LINUX
    CMEM_init();

    ExternalGlobalMemPool = ExternalGlobalMemPoolBase = CMEM_alloc(EXTERNAL_DATA_MEM_SIZE,&memParams);
#ifdef ENABLE_RING_BUF_USAGE
    ringbuf = CMEM_alloc(RINGBUFSIZE, &memParams);
#endif
    OrgPictureY_0=CMEM_alloc( (LUMABUF_SIZE*2+ORGBUF_OFFSET), &memParams);
    OrgPictureCb_0=CMEM_alloc((CHROMABUF_SIZE+ORGBUF_OFFSET), &memParams);
    OrgPictureCr_0=CMEM_alloc((CHROMABUF_SIZE+ORGBUF_OFFSET), &memParams);
    media=CMEM_alloc((ENCODED_DATA_BUFFER_SIZE), &memParams);

//#ifdef LINUX
    //      DM350MM_init();
//#endif

    if (argc==2)
    {
        strncpy(baseParams,argv[1],256);
        if (!strcmp(baseParams,"-ext"))
        {
            printf("\n----- Running in extended parameter mode -----\n");
            baseParamsOnly=0;

        }
        else
        {
            printf("Argument  -ext needed to run in  extended param mode\n");
            exit(0);
        }
    }

    else
    {
        printf("\n----- Running in base parameter mode -----\n");
        baseParamsOnly=1;
    }


#else
    baseParamsOnly=0;
#endif


    //memset(ringbuf,0xaa,RINGBUFSIZE );
    memset(media, 0xaa, ENCODED_DATA_BUFFER_SIZE);
    memset(ExternalGlobalMemPool, 0xaa,EXTERNAL_DATA_MEM_SIZE );
    memset(OrgPictureY_0, 0xaa, (LUMABUF_SIZE*2+ORGBUF_OFFSET));
    memset(OrgPictureCb_0, 0xaa, (CHROMABUF_SIZE+ORGBUF_OFFSET));
    memset(OrgPictureCr_0, 0xaa, (CHROMABUF_SIZE+ORGBUF_OFFSET));

    OrgPictureY  = &OrgPictureY_0[ORGBUF_OFFSET];
    OrgPictureCb = &OrgPictureCb_0[ORGBUF_OFFSET];
    OrgPictureCr = &OrgPictureCr_0[ORGBUF_OFFSET];


    /* Open Test Config File   */
    fConfigFile = fopen(fname, "r");

    if (!fConfigFile)
    {
        printf("Couldn't open parameter file %s\n", fname);
        return XDM_EFAIL;
    }


    countConfigSet = 1;         /* Reset countConfigSet value to 1 */

    /* Read the Config File until it reaches the end of file                    */
    while (!feof(fConfigFile))
    {
        /* Read Compliance Checking parameter */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%d\n", &testCompliance);
            printf("\nTestcompliance = %d\n",testCompliance);
        } else {
            break;
        }
        /* Read Parameters file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", paramsFile);
            printf("\nParam file = %s\n",paramsFile);
        }
        else
        {
            break;
        }
        /* Read Input file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", inFile);
            printf("\nInput file = %s\n",inFile);
        }
        else
        {
            break;
        }

        /* Read Output/Reference file name */
        if (fgets(line, 254, fConfigFile))
        {
            sscanf(line, "%s", testFile);
            printf("\nOutput file = %s\n",testFile);
        }
        else
        {
            break;
        }

        printf("\n*******************************************");
        printf("\nRead Configuration Set %d", countConfigSet);
        printf("\n*******************************************");
        countConfigSet++;



        fp_out=fopen(testFile,"wb");
        fp_in = fopen(inFile,"rb");


        if ((fp_in == NULL) || (fp_out == NULL))
        {
            printf("'Input/out file cannot be opened\n");
            exit(0);
        }

        /** Set initialization parameters
         * Parameters in structure params are default image encode parameters required by XDM
         * Paraemters in extn_params are parameters specific to jpeg encoder,
         *
         */

        /* Open Parameters file */
        fparamsFile = fopen(paramsFile, "rb");
        //fparamsFile = fopen("Testparams.cfg", "rb");
        if (!fparamsFile)
        {
            printf("\nCouldn't open Parameters file...   %s\n ",
                   paramsFile);
            printf("Exiting for this configuration...\n");
            continue;
        }

        printf("\nParameter file read starts...\n");
        if (readparamfile(fparamsFile,baseParamsOnly) < 0)
        {
            printf("\nSyntax Error in %s\n ", paramsFile);
            printf("Exiting for this configuration...\n");
            continue;
        }

        /* Close Parameters File */
        fclose(fparamsFile);
        if (testCompliance)
        {
            printf("\nRunning in Compliance Mode");
        }
        else
        {
            printf("\nRunning in Output Dump Mode");
        }


        /** Call algorithm creation function
          * See file alg_create.
          * memory allocation functions are called inside alg_malloc file.
          * Modify _ALG_allocMemory in alg_malloc.c to suit the application need (static allocation vs dynamic through malloc())
          */

        if (baseParamsOnly==0)
        {
#ifdef ENABLE_RING_BUF_USAGE
            extn_params.halfBufCB =(XDAS_Void (*)(Uint32, XDAS_Void*))JPEGENC_TI_DM350_HalfBufCB;
            extn_params.halfBufCBarg= (void*)&ring2media;

#else
            extn_params.halfBufCB = (XDAS_Void (*))NULL;
#endif


            extn_params.imgencParams = params;
            extn_params.imgencParams.size = sizeof(IJPEGENC_Params);
        }
        else
        {
            params.size = sizeof(IIMGENC1_Params);
            dynamicParams.size =sizeof(IIMGENC1_DynamicParams);
        }
        if (baseParamsOnly==0)
        {
            if ((handle =  (IALG_Handle)ALG_create (
                               (IALG_Fxns *) &JPEGENC_TI_IJPEGENC,
                               (IALG_Handle) NULL,
                               (IALG_Params *)&extn_params)) == NULL)
            {
                printf("\nFailed to Create Instance... Exiting for this configuration..");
                exit(0);
            }

            printf("\nAlgorithm Instance Creation Done...\n");
        }
        else
        {
            if ((handle =  (IALG_Handle)ALG_create (
                               (IALG_Fxns *) &JPEGENC_TI_IJPEGENC,
                               (IALG_Handle) NULL,
                               (IALG_Params *)&params)) == NULL)
            {
                printf("\nFailed to Create Instance... Exiting for this configuration..");
                exit(0);
            }

            printf("\nAlgorithm Instance Creation Done...\n");
        }



#ifdef ENABLE_RMAN // IRES/RMAN Related code

        /* Create an instance of an algorithm that implements IALG and IRES_Fxns */
        iresStatus = RMAN_assignResources((IALG_Handle)handle, resFxns,scratchId);
        if (IRES_OK != iresStatus) {
            printf("Assign Resource Failed \n");
            result = FALSE;
        }

#endif //IRES/RMAN code ends here.

        /** Set up dynamic parameters (can be changed before each call to jpeg processing)
          * Parameters in structure dynamicParams are default image encode parameters required by XDM
          */
        if (baseParamsOnly==0)
        {
            extn_dynamicParams.imgencDynamicParams = dynamicParams;
            extn_dynamicParams.imgencDynamicParams.size  = sizeof(IJPEGENC_DynamicParams);
            extn_dynamicParams.disableEOI = 0;
            iimgEncfxns = (IIMGENC1_Fxns *)handle->fxns ;
            status.imgencStatus.size= sizeof(IJPEGENC_Status);
        }
        else
        {

            dynamicParams.size           = sizeof(IIMGENC1_DynamicParams);
            iimgEncfxns = (IIMGENC1_Fxns *)handle->fxns ;
            imgencStatus.size= sizeof(IIMGENC1_Status);

        }
        /** Request input and output buffer characteristics by calling control() function
         *  with command XDM_GETBUFINFO
         */


        // Call control function to setup dynamic params
        if (baseParamsOnly==0)
        {
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle,/*IJPEGENC_SETDEFAULT*/XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);

            if (retVal== XDM_EFAIL) {
                printf("\n Error control SetParams  command1\n");
                exit(0);
            }

            retVal= iimgEncfxns->control((IIMGENC1_Handle)handle,
                                         XDM_GETBUFINFO,
                                         (IIMGENC1_DynamicParams *) &extn_dynamicParams,
                                         (IIMGENC1_Status *)&status);
	    if (retVal== XDM_EFAIL) {
		printf("\n Error control Getbuffinfo  command1\n");
		exit(0);
	     }


            inputBufDesc.numBufs = status.imgencStatus.bufInfo.minNumInBufs;
            Offset = 0;

            for (i=0;i<inputBufDesc.numBufs;i++)
            {
                inputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)inputData +
                                            Offset);
                Offset +=  status.imgencStatus.bufInfo.minInBufSize[i];
                inputBufDesc.descs[i].bufSize = status.imgencStatus.bufInfo.minInBufSize[i];
            }

            outputBufDesc.numBufs = status.imgencStatus.bufInfo.minNumOutBufs;
            Offset = 0;

            for (i=0;i<outputBufDesc.numBufs;i++)
            {
                outputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)outputData +
                                             Offset);
                Offset +=  status.imgencStatus.bufInfo.minOutBufSize[i];
                outputBufDesc.descs[i].bufSize = status.imgencStatus.bufInfo.minOutBufSize[i];

            }


            if (retVal== XDM_EFAIL) {
                printf("\n Error control GetInfo command\n");
                exit(0);
            }

        }
        else
        {
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&dynamicParams, (IIMGENC1_Status *)&imgencStatus);

            if (retVal== XDM_EFAIL) {
                printf("\n Error control SetParams  command1\n");
                exit(0);
            }

            retVal= iimgEncfxns->control((IIMGENC1_Handle)handle,
                                         XDM_GETBUFINFO,
                                         (IIMGENC1_DynamicParams *)&dynamicParams,
                                         (IIMGENC1_Status *)&imgencStatus);
             if (retVal== XDM_EFAIL) 
	     {
		 printf("\n Error control GetBuffInfo  command1\n");
	         exit(0);
	      }

            inputBufDesc.numBufs = imgencStatus.bufInfo.minNumInBufs;
            Offset = 0;

            for (i=0;i<inputBufDesc.numBufs;i++)
            {
                inputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)inputData +
                                            Offset);
                Offset +=  imgencStatus.bufInfo.minInBufSize[i];
                inputBufDesc.descs[i].bufSize = imgencStatus.bufInfo.minInBufSize[i];
            }

            outputBufDesc.numBufs = imgencStatus.bufInfo.minNumOutBufs;
            Offset = 0;

            for (i=0;i<outputBufDesc.numBufs;i++)
            {
                outputBufDesc.descs[i].buf = (XDAS_Int8 *) ( (unsigned int)outputData +
                                             Offset);
                Offset +=  imgencStatus.bufInfo.minOutBufSize[i];
                outputBufDesc.descs[i].bufSize = imgencStatus.bufInfo.minOutBufSize[i];
            }

            if (retVal== XDM_EFAIL) {
                printf("\n Error control GetInfo command\n");
                exit(0);
            }




        }
        if (baseParamsOnly==0)
        {
            /** Read input file.
               */
            printf("Number of Input bufs =%d\n",status.imgencStatus.bufInfo.minNumInBufs );
            if (status.imgencStatus.bufInfo.minNumInBufs == 3)
            {
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                memset(OrgPictureCb,0,(status.imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,0,(status.imgencStatus.bufInfo.minInBufSize[2]));
                printf("Input file read starts\n" );

                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);


                lTemp = fread(OrgPictureCb,1,((status.imgencStatus.bufInfo.minInBufSize[1])),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);
                lTemp = fread(OrgPictureCr,1,((status.imgencStatus.bufInfo.minInBufSize[2])),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);


            }
            else if (status.imgencStatus.bufInfo.minNumInBufs == 1)
            {
                printf("status.imgencStatus.bufInfo.minInBufSize[0]=%d\n",status.imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);
            }
            else if (status.imgencStatus.bufInfo.minNumInBufs == 2) /* 420 semi planar*/
            {
                printf("status.imgencStatus.bufInfo.minInBufSize[0]=%d\n",status.imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(status.imgencStatus.bufInfo.minInBufSize[0]));
                printf("status.imgencStatus.bufInfo.minInBufSize[1]=%d\n",status.imgencStatus.bufInfo.minInBufSize[1]);
                memset(OrgPictureCb,'-',(status.imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,'-',(status.imgencStatus.bufInfo.minInBufSize[1]));

                lTemp = fread(OrgPictureY,1,(status.imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);

                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    lTemp = fread(OrgPictureCr,1,(status.imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);

                    lTemp += fread((OrgPictureCr+(status.imgencStatus.bufInfo.minInBufSize[1])/2),1,(status.imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);

                }
                else
                {
                    lTemp = fread(OrgPictureCr,1,(status.imgencStatus.bufInfo.minInBufSize[1]),fp_in);
                }

                printf("number of bytes read from input file = %d \n",lTemp);

                /* The input file is 420 planar, the following function converts the 420P to 420 semi planar
                   i.e CbCr will be interleaved. planar chrmoa data is read into OrgPictureCr buffer and
                   converted to interleaved. output is stored in OrgPictureCb buffer*/
                /*convert the 420 planar to 420 semi planar*/
                lTemp = Convert420Pto420Semi(OrgPictureCr,OrgPictureCb,status.imgencStatus.bufInfo.minInBufSize[1]);

            }
            else
            {
                printf("Unsupported number of input buffers \n");
            }
            fclose(fp_in);
        }
        else
        {
            /** Read input file.
               */
            printf("Number of Input bufs =%d\n",imgencStatus.bufInfo.minNumInBufs );
            if (imgencStatus.bufInfo.minNumInBufs == 3)
            {
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                memset(OrgPictureCb,0,(imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,0,(imgencStatus.bufInfo.minInBufSize[2]));
                printf("Input file read starts\n" );

                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);


                lTemp = fread(OrgPictureCb,1,((imgencStatus.bufInfo.minInBufSize[1])),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);
                lTemp = fread(OrgPictureCr,1,((imgencStatus.bufInfo.minInBufSize[2])),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);


            }
            else if (imgencStatus.bufInfo.minNumInBufs == 1)
            {
                printf("imgencStatus.bufInfo.minInBufSize[0]=%d\n",imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                printf("number of bytes read from input file = %d \n",lTemp);
            }
            else if (imgencStatus.bufInfo.minNumInBufs == 2) /* 420 semi planar*/
            {
                printf("imgencStatus.bufInfo.minInBufSize[0]=%d\n",imgencStatus.bufInfo.minInBufSize[0]);
                memset(OrgPictureY,0,(imgencStatus.bufInfo.minInBufSize[0]));
                printf("imgencStatus.bufInfo.minInBufSize[1]=%d\n",imgencStatus.bufInfo.minInBufSize[1]);
                memset(OrgPictureCb,'-',(imgencStatus.bufInfo.minInBufSize[1]));
                memset(OrgPictureCr,'-',(imgencStatus.bufInfo.minInBufSize[1]));

                lTemp = fread(OrgPictureY,1,(imgencStatus.bufInfo.minInBufSize[0]),fp_in);
                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)),SEEK_CUR);
                }
                printf("number of bytes read from input file = %d \n",lTemp);

                if (dynamicParams.inputWidth < dynamicParams.captureWidth) {
                    lTemp = fread(OrgPictureCr,1,(imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);
                    fseek(fp_in,(dynamicParams.captureWidth*(params.maxHeight-dynamicParams.inputHeight)/4),SEEK_CUR);

                    lTemp += fread((OrgPictureCr+(imgencStatus.bufInfo.minInBufSize[1])/2),1,(imgencStatus.bufInfo.minInBufSize[1])/2,fp_in);

                }
                else
                {
                    lTemp = fread(OrgPictureCr,1,(imgencStatus.bufInfo.minInBufSize[1]),fp_in);
                }

                printf("number of bytes read from input file = %d \n",lTemp);

                /* The input file is 420 planar, the following function converts the 420P to 420 semi planar
                   i.e CbCr will be interleaved. planar chrmoa data is read into OrgPictureCr buffer and
                   converted to interleaved. output is stored in OrgPictureCb buffer*/
                /*convert the 420 planar to 420 semi planar*/
                lTemp = Convert420Pto420Semi(OrgPictureCr,OrgPictureCb,imgencStatus.bufInfo.minInBufSize[1]);

                //	printf("OrgPictureCb=%x\n",OrgPictureCb);


            }
            else
            {
                printf("Unsupported number of input buffers \n");
            }
            fclose(fp_in);

        }

        /*Fill up the buffers as required by algorithm                            */
        if (baseParamsOnly==0) {
            inputBufDesc.numBufs  = status.imgencStatus.bufInfo.minNumInBufs ;
        }
        else
        {
            inputBufDesc.numBufs  = imgencStatus.bufInfo.minNumInBufs ;
        }
        inputBufDesc.descs[0].buf= (XDAS_Int8 *)OrgPictureY;

        if (dynamicParams.inputChromaFormat== IJPEGENC_YUV_420LINE)
        {
            inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureY + dynamicParams.inputWidth;
            inputBufDesc.descs[2].buf= inputBufDesc.descs[1].buf + dynamicParams.inputWidth*3/2;
        }
        else if (dynamicParams.inputChromaFormat!= XDM_YUV_422ILE)
        {
            if (dynamicParams.inputChromaFormat== XDM_YUV_420SP)
            {
                inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureCb;
            }
            else
            {
                inputBufDesc.descs[1].buf= (XDAS_Int8 *)OrgPictureCb;
                inputBufDesc.descs[2].buf= (XDAS_Int8 *)OrgPictureCr;
            }

        }
        if (baseParamsOnly==0) {
            inputBufDesc.descs[0].bufSize = status.imgencStatus.bufInfo.minInBufSize[0]; // actually ignored by codec

            outputBufDesc.numBufs     = status.imgencStatus.bufInfo.minNumOutBufs ;
        }
        else
        {
            inputBufDesc.descs[0].bufSize = imgencStatus.bufInfo.minInBufSize[0]; // actually ignored by codec

            outputBufDesc.numBufs     = imgencStatus.bufInfo.minNumOutBufs ;
        }

        if (baseParamsOnly==0)
        {
#ifdef ENABLE_RING_BUF_USAGE

            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)ringbuf;
            outputBufDesc.descs[0].bufSize =  RINGBUFSIZE; // actually ignored by codec
            ring2media.mediaPtr= media;
            ring2media.ringCurPtr= ringbuf;
            ring2media.ringStartPtr=ringbuf;
            ring2media.ringEndPtr= (Uint8*)((Uint32)ringbuf +RINGBUFSIZE) ;
            inArgs.ringBufStart= (XDAS_UInt8*)ringbuf;
            inArgs.ringBufSize= RINGBUFSIZE;
            printf("RINGBUFSIZE %x\n", RINGBUFSIZE);
#else
            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)media;
            outputBufDesc.descs[0].bufSize =  ENCODED_DATA_BUFFER_SIZE; // actually ignored by codec
            ring2media.mediaPtr= media;
            ring2media.ringCurPtr= media;
            ring2media.ringStartPtr=media;
            ring2media.ringEndPtr= (Uint8*)((Uint32)media +ENCODED_DATA_BUFFER_SIZE) ;
            inArgs.ringBufStart= (XDAS_UInt8*)media;
            inArgs.ringBufSize= ENCODED_DATA_BUFFER_SIZE;
#endif


            inArgs.imgencInArgs.size =  sizeof(IJPEGENC_InArgs);
            outArgs.imgencOutArgs.size= sizeof(IJPEGENC_OutArgs);
        }
        else
        {
            outputBufDesc.descs[0].buf     = (XDAS_Int8 *)media;
            outputBufDesc.descs[0].bufSize =  ENCODED_DATA_BUFFER_SIZE; // actually ignored by codec
            imgencInArgs.size = sizeof(IIMGENC1_InArgs);
            imgencOutArgs.size= sizeof(IIMGENC1_OutArgs);

        }

#ifdef LINUX
        algActStart.tv_sec = 0;
        algActStart.tv_usec = 0;
        gettimeofday(&algActStart, 0);
#endif

        handle->fxns->algActivate(handle);

#ifdef LINUX
        processStart.tv_sec = 0;
        processStart.tv_usec = 0;
        gettimeofday(&processStart, 0);
#endif



        if (baseParamsOnly==0)
        {
            inArgs.insertCommentMarker = 0;
            inArgs.appDataType =0;
            inArgs.commentSegLen = 0;

            retVal = iimgEncfxns->process((IIMGENC1_Handle)handle,
                                          (XDM1_BufDesc *)&inputBufDesc,
                                          (XDM1_BufDesc *)&outputBufDesc,
                                          (IIMGENC1_InArgs *)&inArgs,
                                          (IIMGENC1_OutArgs *)&outArgs);

            bytesGenerated= outArgs.imgencOutArgs.bytesGenerated;
        }
        else
        {
            retVal = iimgEncfxns->process((IIMGENC1_Handle)handle,
                                          (XDM1_BufDesc *)&inputBufDesc,
                                          (XDM1_BufDesc *)&outputBufDesc,
                                          (IIMGENC1_InArgs *)&imgencInArgs,
                                          (IIMGENC1_OutArgs *)&imgencOutArgs);
            bytesGenerated= imgencOutArgs.bytesGenerated;
        }

#ifdef SLICE_MODE_TEST
        /* SLICE_MODE_TEST*/
        // Call get status to get number of total AU
        if (baseParamsOnly==0)
        {
            
		
	    retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, IJPEGENC_GETSTATUS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);
	    
	    if (retVal== XDM_EFAIL) {
                printf("\n Error control in slice mode get status command\n");
                exit(0);
            }
            totalAU= status.imgencStatus.totalAU;

	    printf("totalAU = %d\n",totalAU);
            extn_dynamicParams.imgencDynamicParams.numAU= 50/*totalAU/5*/;
	    
            // Call control function to setup dynamic params
            retVal=iimgEncfxns->control((IIMGENC1_Handle)handle, XDM_SETPARAMS,
                                        (IIMGENC1_DynamicParams *)&extn_dynamicParams, (IIMGENC1_Status *)&status);
            numAU = status.numAU;
	    printf("numAU = %d\n",numAU);

	    if (retVal== XDM_EFAIL) {
                printf("\n Error control in slice mode SetParams command\n");
                exit(0);
            }          // Get real numAU computed by codec

            // In case of 270 rotation, must point to right most slice of the image
            
	    if (extn_dynamicParams.rotation== 90)
            {
                if (dynamicParams.inputChromaFormat==XDM_YUV_420SP)
                {
                    Uint16 sliceWidth= (numAU*16/dynamicParams.inputHeight)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                    inputBufDesc.descs[0].buf+= (dynamicParams.inputWidth - sliceWidth);
                    inputBufDesc.descs[1].buf+= (dynamicParams.inputWidth - sliceWidth);

                    //	inputBufDesc.descs[2].buf+= (dynamicParams.inputWidth - sliceWidth);//dynamicParams.inputWidth/2 - sliceWidth/2;
                }
                else
                {
                    Uint16 sliceWidth= (numAU*16/dynamicParams.inputHeight)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                    inputBufDesc.descs[0].buf+= (dynamicParams.inputChromaFormat== XDM_YUV_422ILE ? 2 : 1)*(dynamicParams.inputWidth - sliceWidth);
                    inputBufDesc.descs[1].buf+= dynamicParams.inputWidth/2 - sliceWidth/2;
                    inputBufDesc.descs[2].buf+= dynamicParams.inputWidth/2 - sliceWidth/2;
                }


            }
            else if (extn_dynamicParams.rotation== 180)
            {
                Uint16 sliceHeight = (numAU*16/dynamicParams.inputWidth)*(8<<(params.forceChromaFormat==XDM_YUV_420P));
                if (dynamicParams.inputChromaFormat != XDM_YUV_420SP)
                {
                    inputBufDesc.descs[0].buf+= dynamicParams.captureWidth*(dynamicParams.inputChromaFormat== XDM_YUV_422ILE ? 2 : 1)*(dynamicParams.inputHeight - sliceHeight);
                    inputBufDesc.descs[1].buf+= dynamicParams.captureWidth*(dynamicParams.inputHeight - sliceHeight)>>(1 + (dynamicParams.inputChromaFormat== XDM_YUV_420P));
                    inputBufDesc.descs[2].buf+= dynamicParams.captureWidth*(dynamicParams.inputHeight - sliceHeight)>>(1 + (dynamicParams.inputChromaFormat== XDM_YUV_420P));
                }
                else
                {