/******************************************************************************* * 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; }
XDAS_Int32 BUFFMGR_Init(XDAS_Int32 totBufSize) { XDAS_UInt32 tmpCnt; /* Memory allocation params required in linux */ CMEM_AllocParams memParams; /* Allocation params */ memParams.type=CMEM_POOL; memParams.flags=CMEM_CACHED; memParams.alignment=256; /* total buffer size allocatable is divided into three parts one part goes * to luma buffers and the other two parts go to luma buffers */ chromaGlobalBufferSize = (totBufSize/3); lumaGlobalBufferSize = (chromaGlobalBufferSize*2); if(lumaGlobalBufferHandle == NULL) { /* Allocate the global buffers */ lumaGlobalBufferHandle = CMEM_alloc(lumaGlobalBufferSize, &memParams); if(lumaGlobalBufferHandle == NULL) { return -1; } chromaGlobalBufferHandle = CMEM_alloc(chromaGlobalBufferSize, &memParams); if(chromaGlobalBufferHandle == NULL) { CMEM_free(lumaGlobalBufferHandle,&memParams); return -1; } } memset(lumaGlobalBufferHandle, 0x66, lumaGlobalBufferSize); memset(chromaGlobalBufferHandle, 0x66, chromaGlobalBufferSize); /* Initialise the elements in the global buffer array */ for(tmpCnt = 0; tmpCnt < MAX_BUFF_ELEMENTS; tmpCnt++) { buffArray[tmpCnt].bufId = tmpCnt+1; buffArray[tmpCnt].bufStatus = BUFFMGR_BUFFER_FREE; buffArray[tmpCnt].bufSize[1] = 0; buffArray[tmpCnt].bufSize[0] = 0; buffArray[tmpCnt].buf[1] = NULL; buffArray[tmpCnt].buf[0] = NULL; } /* Initialise the entire buffer space to first frame and * re-modify buffer sizes as per the picture frame sizes * after first frame decode */ buffArray[0].buf[1] = chromaGlobalBufferHandle; buffArray[0].bufSize[1] = chromaGlobalBufferSize; buffArray[0].buf[0] = lumaGlobalBufferHandle; buffArray[0].bufSize[0] = lumaGlobalBufferSize; return 0; }
static void open_video(AVFormatContext *oc, AVStream *st) { AVCodec *codec; AVCodecContext *c; c = st->codec; /* find the video encoder */ codec = avcodec_find_encoder(c->codec_id); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } /* open the codec */ if (avcodec_open(c, codec) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } if (codec->pix_fmts && codec->pix_fmts[0] != -1) { c->pix_fmt = codec->pix_fmts[0]; } video_outbuf = NULL; if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { /* allocate output buffer */ /* buffers passed into lav* can be allocated any way you prefer, as long as they're aligned enough for the architecture, and they're freed appropriately (such as using av_free for buffers allocated with av_malloc) */ video_outbuf_size = 3*1024*1024; video_outbuf = CMEM_alloc(video_outbuf_size, &alloc_params); } /* allocate the encoded raw picture */ picture = alloc_picture(c->pix_fmt, c->width, c->height); if (!picture) { fprintf(stderr, "Could not allocate picture\n"); exit(1); } /* if the output format is not YUV420P, then a temporary YUV420P picture is needed too. It is then converted to the required output format */ tmp_picture = NULL; if (c->pix_fmt != PIX_FMT_YUV420P) { tmp_picture = alloc_picture(PIX_FMT_YUV420P, c->width, c->height); if (!tmp_picture) { fprintf(stderr, "Could not allocate temporary picture\n"); exit(1); } } }
static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height) { AVFrame *picture; uint8_t *picture_buf; int size; picture = avcodec_alloc_frame(); if (!picture) return NULL; size = avpicture_get_size(pix_fmt, width, height); picture_buf = CMEM_alloc(size, &alloc_params); if (!picture_buf) { av_free(picture); return NULL; } avpicture_fill((AVPicture *)picture, picture_buf, pix_fmt, width, height); return picture; }
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 }
/* * ======== _ALG_allocMemory ======== */ Bool _ALG1_allocMemory(IALG_MemRec memTab[], Int n) { Int i; for (i = 0; i < n; i++) { memTab[i].base = (void *)CMEM_alloc( memTab[i].size, &memParams); if (memTab[i].base == NULL) { _ALG_freeMemory(memTab, i); return (FALSE); } /*------------------------------------------------------------------*/ /* Recommended to work with out memset 0. */ /*------------------------------------------------------------------*/ //memset(memTab[i].base, 0, memTab[i].size); } return (TRUE); }
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"); }
/* * ======== _ALG_allocMemory ======== */ Bool _ALG1_allocMemory(IALG_MemRec memTab[], Int n) { Int i; for (i = 0; i < n; i++) { #ifdef ON_LINUX printf("\n memTab[%d].size = %d", i, memTab[i].size); memTab[i].base = (void *)CMEM_alloc( memTab[i].size, &memParams); #else memTab[i].base = (void *)myMemalign(memTab[i].alignment, memTab[i].size); #endif if (memTab[i].base == NULL) { _ALG_freeMemory(memTab, i); return (FALSE); } /*------------------------------------------------------------------*/ /* Recommended to work with out memset 0. */ /*------------------------------------------------------------------*/ //memset(memTab[i].base, 0, memTab[i].size); } return (TRUE); }
/******************************************************************************* * 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; }
/***************************************************************************** Prototype : display_buf_alloc Description : alloc buffer for display Input : DisplayHanlde hDisplay Output : None Return Value : static Calls : Called By : History : 1.Date : 2012/8/28 Author : Sun Modification : Created function *****************************************************************************/ static Int32 display_buf_alloc(DisplayHanlde hDisplay) { Uint32 size; CMEM_AllocParams *allocAttrs = &hDisplay->memAllocParams; Int32 i, err = E_NO; allocAttrs->alignment = 256; allocAttrs->flags = CMEM_NONCACHED; allocAttrs->type = CMEM_POOL; size = DISPLAY_BUF_SIZE; for(i = 0; i < DISPLAY_BUF_NUM; i++) { hDisplay->displayBuf[i].userAddr = CMEM_alloc(size, allocAttrs); if(!hDisplay->displayBuf[i].userAddr) { ERR("Alloc buffer mem failed."); err = E_NOMEM; break; } hDisplay->displayBuf[i].index = i; hDisplay->displayBuf[i].bufSize = size; hDisplay->displayBuf[i].phyAddr = 0; } /* request buffers from driver */ struct v4l2_requestbuffers req; req.count = DISPLAY_BUF_NUM; req.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; req.memory = V4L2_MEMORY_USERPTR; err = ioctl(hDisplay->fdDisplay, VIDIOC_REQBUFS, &req); if(err < 0) { ERRSTR("cannot request buf"); return E_IO; } return err; }
/* 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 *)¶ms)) == 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 {
/* * 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 {
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; }
/* * ======== 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; }
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, ¶ms); 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, ¶ms) < 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); } }
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; }
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 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); }
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{
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; }