diff options
Diffstat (limited to 'domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c')
-rwxr-xr-x | domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c | 352 |
1 files changed, 276 insertions, 76 deletions
diff --git a/domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c b/domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c index 729c190..f411d28 100755 --- a/domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c +++ b/domx/omx_proxy_component/omx_camera/src/omx_proxy_camera.c @@ -65,6 +65,7 @@ #include <pthread.h> #include <sys/time.h> #include <stdlib.h> +#include <errno.h> #include <timm_osal_interfaces.h> #include <OMX_TI_IVCommon.h> @@ -74,15 +75,12 @@ #ifdef USE_ION #include <unistd.h> -#include <ion.h> +#include <ion/ion.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/eventfd.h> #include <fcntl.h> - -#else -/* Tiler APIs */ -#include <memmgr.h> +#include <errno.h> #endif #define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.CAMERA" @@ -92,11 +90,7 @@ #define LOG_TAG "CameraHAL" #define DEFAULT_DCC 1 -#ifdef _Android -#define DCC_PATH "/data/misc/camera/" -#else -#define DCC_PATH "/usr/share/omapcam/" -#endif + #define LINUX_PAGE_SIZE (4 * 1024) #define _PROXY_OMX_INIT_PARAM(param,type) do { \ @@ -106,6 +100,21 @@ (param)->nVersion.s.nVersionMinor = 1; \ } while(0) +/* VTC specific changes */ +#define MAX_NUM_INTERNAL_BUFFERS 4 +#define MAX_VTC_WIDTH 1920 +#define MAX_VTC_HEIGHT 1080 +#define BORDER_WIDTH 32 +#define BORDER_HEIGHT 32 +#define MAX_VTC_WIDTH_WITH_VNF (MAX_VTC_WIDTH + BORDER_WIDTH) +#define MAX_VTC_HEIGHT_WITH_VNF (MAX_VTC_HEIGHT + BORDER_HEIGHT) +OMX_PTR gCamIonHdl[MAX_NUM_INTERNAL_BUFFERS][2]; + +/* Tiler heap resservation specific */ +#define OMAP_ION_HEAP_TILER_ALLOCATION_MASK (1<<4) +/* store handles for tracking and freeing */ +OMX_PTR gComponentBufferAllocation[PROXY_MAXNUMOFPORTS][MAX_NUM_INTERNAL_BUFFERS]; + /* Incase of multiple instance, making sure DCC is initialized only for first instance */ static OMX_S16 numofInstance = 0; @@ -122,9 +131,6 @@ OMX_PTR DCC_Buff = NULL; OMX_PTR DCC_Buff_ptr = NULL; int ion_fd; int mmap_fd; - -#else -MemAllocBlock *MemReqDescTiler; #endif OMX_S32 read_DCCdir(OMX_PTR, OMX_STRING *, OMX_U16); @@ -137,9 +143,11 @@ OMX_ERRORTYPE __PROXY_SetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE, OMX_ERRORTYPE __PROXY_GetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE, OMX_PTR, OMX_PTR); OMX_ERRORTYPE __PROXY_SetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE, - OMX_PTR, OMX_PTR); + OMX_PTR, OMX_PTR, OMX_U32); OMX_ERRORTYPE __PROXY_GetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE, OMX_PTR, OMX_PTR); +OMX_ERRORTYPE PROXY_SendCommand(OMX_HANDLETYPE, OMX_COMMANDTYPE, + OMX_U32,OMX_PTR); OMX_ERRORTYPE CameraMaptoTilerDuc(OMX_TI_CONFIG_SHAREDBUFFER *, OMX_PTR *); //COREID TARGET_CORE_ID = CORE_APPM3; @@ -147,6 +155,11 @@ static OMX_ERRORTYPE ComponentPrivateDeInit(OMX_IN OMX_HANDLETYPE hComponent) { OMX_ERRORTYPE eError = OMX_ErrorNone; TIMM_OSAL_ERRORTYPE eOsalError = TIMM_OSAL_ERR_NONE; + PROXY_COMPONENT_PRIVATE *pCompPrv; + OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; + OMX_U32 i, j; + + pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; if (dcc_flag) { @@ -163,6 +176,26 @@ static OMX_ERRORTYPE ComponentPrivateDeInit(OMX_IN OMX_HANDLETYPE hComponent) PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, OMX_ErrorInsufficientResources, "Mutex release failed"); } + for(i=0; i < MAX_NUM_INTERNAL_BUFFERS; i++) { + if (gCamIonHdl[i][0] != NULL) { + ion_free(pCompPrv->ion_fd, gCamIonHdl[i][0]); + gCamIonHdl[i][0] = NULL; + } + if (gCamIonHdl[i][1] != NULL) { + ion_free(pCompPrv->ion_fd, gCamIonHdl[i][1]); + gCamIonHdl[i][1] = NULL; + } + + } + + for (i = 0; i < PROXY_MAXNUMOFPORTS; i++) { + for (j = 0; j < MAX_NUM_INTERNAL_BUFFERS; j++) { + if (gComponentBufferAllocation[i][j]) { + ion_free(pCompPrv->ion_fd, gComponentBufferAllocation[i][j]); + } + gComponentBufferAllocation[i][j] = NULL; + } + } eError = PROXY_ComponentDeInit(hComponent); @@ -170,6 +203,73 @@ static OMX_ERRORTYPE ComponentPrivateDeInit(OMX_IN OMX_HANDLETYPE hComponent) return eError; } +static OMX_ERRORTYPE Camera_SendCommand(OMX_IN OMX_HANDLETYPE hComponent, + OMX_IN OMX_COMMANDTYPE eCmd, + OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData) + +{ + OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn; + RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone; + PROXY_COMPONENT_PRIVATE *pCompPrv; + OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; + static OMX_BOOL dcc_loaded = OMX_FALSE; + + OMX_ERRORTYPE dcc_eError = OMX_ErrorNone; + TIMM_OSAL_ERRORTYPE eOsalError = TIMM_OSAL_ERR_NONE; + OMX_U32 i; + + pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; + + if ((eCmd == OMX_CommandStateSet) && + (nParam == (OMX_STATETYPE) OMX_StateIdle)) + { + if (!dcc_loaded) + { + dcc_eError = DCC_Init(hComponent); + if (dcc_eError != OMX_ErrorNone) + { + DOMX_ERROR(" Error in DCC Init"); + } + /* Configure Ducati to use DCC buffer from A9 side + *ONLY* if DCC_Init is successful. */ + if (dcc_eError == OMX_ErrorNone) + { + dcc_eError = send_DCCBufPtr(hComponent); + if (dcc_eError != OMX_ErrorNone) + { + DOMX_ERROR(" Error in Sending DCC Buf ptr"); + } + DCC_DeInit(); + } + dcc_loaded = OMX_TRUE; + } + } else if (eCmd == OMX_CommandPortDisable) { + int i, j; + for (i = 0; i < MAX_NUM_INTERNAL_BUFFERS; i++) { + for (j = 0; j < PROXY_MAXNUMOFPORTS; j++) { + if (((j == nParam) || (nParam == OMX_ALL)) && + gComponentBufferAllocation[i][j]) + { + ion_free(pCompPrv->ion_fd, gComponentBufferAllocation[i][j]); + gComponentBufferAllocation[i][j] = NULL; + } + } + } + + } + + + eError = + PROXY_SendCommand(hComponent,eCmd,nParam,pCmdData); + + +EXIT: + + DOMX_EXIT("eError: %d", eError); + return eError; + +} + /* ===========================================================================*/ /** * @name CameraGetConfig() @@ -292,12 +392,141 @@ static OMX_ERRORTYPE CameraSetConfig(OMX_IN OMX_HANDLETYPE return eError; } +static OMX_ERRORTYPE CameraSetParam(OMX_IN OMX_HANDLETYPE + hComponent, OMX_IN OMX_INDEXTYPE nParamIndex, + OMX_INOUT OMX_PTR pComponentParameterStructure) +{ + OMX_ERRORTYPE eError = OMX_ErrorNone; + struct ion_handle *handle; + OMX_U32 i =0; + OMX_S32 ret = 0; + PROXY_COMPONENT_PRIVATE *pCompPrv; + OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *)hComponent; + OMX_U32 stride_Y = 0, stride_UV = 0; + OMX_TI_PARAM_VTCSLICE *pVtcConfig;// = (OMX_TI_PARAM_VTCSLICE *)pComponentParameterStructure; + OMX_TI_PARAM_COMPONENTBUFALLOCTYPE *bufferalloc = NULL; + int size = 0; + int fd1 = -1, fd2 = -1; + + pCompPrv = (PROXY_COMPONENT_PRIVATE *)hComp->pComponentPrivate; + //fprintf(stdout, "DOMX: CameraSetParam: called!!!\n"); + switch (nParamIndex) + { + case OMX_TI_IndexParamVtcSlice: + pVtcConfig = (OMX_TI_PARAM_VTCSLICE *)pComponentParameterStructure; + fprintf(stdout, "DOMX: CameraSetParam: OMX_TI_IndexParamVtcSlice is called!!!\n"); + DOMX_ERROR("CameraSetParam Called for Vtc Slice index\n"); + + //fprintf(stdout, "CameraSetParam Called for Vtc Slice height = %d\n", ((OMX_TI_PARAM_VTCSLICE *)pComponentParameterStructure)->nSliceHeight); + // MAX_NUM_INTERNAL_BUFFERS; + + for(i=0; i < MAX_NUM_INTERNAL_BUFFERS; i++) { + pVtcConfig->nInternalBuffers = i; + ret = ion_alloc_tiler(pCompPrv->ion_fd, MAX_VTC_WIDTH_WITH_VNF, MAX_VTC_HEIGHT_WITH_VNF, TILER_PIXEL_FMT_8BIT, OMAP_ION_HEAP_TILER_MASK, &handle, (size_t *)&stride_Y); + if (ret < 0) { + DOMX_ERROR ("ION allocation failed - %s", strerror(errno)); + goto EXIT; + } + + ret = ion_share(pCompPrv->ion_fd, handle, &fd1); + if (ret < 0) { + DOMX_ERROR("ION share failed"); + ion_free(pCompPrv->ion_fd, handle); + goto EXIT; + } + + pVtcConfig->IonBufhdl[0] = (OMX_PTR)(fd1); + + //fprintf(stdout, "DOMX: ION Buffer#%d: Y: 0x%x\n", i, pVtcConfig->IonBufhdl[0]); + + ret = ion_alloc_tiler(pCompPrv->ion_fd, MAX_VTC_WIDTH_WITH_VNF/2, MAX_VTC_HEIGHT_WITH_VNF/2, TILER_PIXEL_FMT_16BIT, OMAP_ION_HEAP_TILER_MASK, &handle, (size_t *)&stride_UV); + if (ret < 0) { + DOMX_ERROR ("ION allocation failed - %s", strerror(errno)); + goto EXIT; + } + + ret = ion_share(pCompPrv->ion_fd, handle, &fd2); + if (ret < 0) { + DOMX_ERROR("ION share failed"); + ion_free(pCompPrv->ion_fd, handle); + goto EXIT; + } + + pVtcConfig->IonBufhdl[1] = (OMX_PTR)(fd2); + gCamIonHdl[i][0] = pVtcConfig->IonBufhdl[0]; + gCamIonHdl[i][1] = pVtcConfig->IonBufhdl[1]; + //fprintf(stdout, "DOMX: ION Buffer#%d: UV: 0x%x\n", i, pVtcConfig->IonBufhdl[1]); + eError = __PROXY_SetParameter(hComponent, + OMX_TI_IndexParamVtcSlice, + pVtcConfig, + pVtcConfig->IonBufhdl, 2); + close(fd1); + close(fd2); + } + goto EXIT; + case OMX_TI_IndexParamComponentBufferAllocation: { + OMX_U32 port = 0, index = 0; + int fd; + bufferalloc = (OMX_TI_PARAM_COMPONENTBUFALLOCTYPE *) + pComponentParameterStructure; + + port = bufferalloc->nPortIndex; + index = bufferalloc->nIndex; + + size = bufferalloc->nAllocWidth * bufferalloc->nAllocLines; + ret = ion_alloc_tiler (pCompPrv->ion_fd, size, 1, + TILER_PIXEL_FMT_PAGE, + OMAP_ION_HEAP_TILER_ALLOCATION_MASK, + &handle, &stride_Y); + if (ret < 0) { + DOMX_ERROR ("ION allocation failed - %s", strerror(errno)); + goto EXIT; + } + + ret = ion_share(pCompPrv->ion_fd, handle, &fd); + if (ret < 0) { + DOMX_ERROR("ION share failed"); + ion_free(pCompPrv->ion_fd, handle); + goto EXIT; + } + + bufferalloc->pBuf[0] = fd; + eError = __PROXY_SetParameter(hComponent, + OMX_TI_IndexParamComponentBufferAllocation, + bufferalloc, &bufferalloc->pBuf[0], 1); + if (eError != OMX_ErrorNone) { + ion_free(pCompPrv->ion_fd, handle); + } else { + if (gComponentBufferAllocation[port][index]) { + ion_free(pCompPrv->ion_fd, gComponentBufferAllocation[port][index]); + } + gComponentBufferAllocation[port][index] = handle; + } + close (fd); + } + goto EXIT; + break; + default: + break; + } + eError = __PROXY_SetParameter(hComponent, + nParamIndex, + pComponentParameterStructure, + NULL, 0); + + if (eError != OMX_ErrorNone) { + DOMX_ERROR(" CameraSetParam: Error in SetParam 0x%x", eError); + } +EXIT: + return eError; +} OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) { OMX_ERRORTYPE eError = OMX_ErrorNone; OMX_ERRORTYPE dcc_eError = OMX_ErrorNone; OMX_COMPONENTTYPE *pHandle = NULL; PROXY_COMPONENT_PRIVATE *pComponentPrivate; + OMX_U32 i = 0, j = 0; pHandle = (OMX_COMPONENTTYPE *) hComponent; TIMM_OSAL_ERRORTYPE eOsalError = TIMM_OSAL_ERR_NONE; DOMX_ENTER("_____________________INSIDE CAMERA PROXY" @@ -335,46 +564,23 @@ OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) TIMM_OSAL_Free(pComponentPrivate); goto EXIT; } + for(i=0; i < MAX_NUM_INTERNAL_BUFFERS; i++) { + gCamIonHdl[i][0] = NULL; + gCamIonHdl[i][1] = NULL; + } + + for (i = 0; i < PROXY_MAXNUMOFPORTS; i++) { + for (j = 0; j < MAX_NUM_INTERNAL_BUFFERS; j++) { + gComponentBufferAllocation[i][j] = NULL; + } + } pHandle->ComponentDeInit = ComponentPrivateDeInit; pHandle->GetConfig = CameraGetConfig; pHandle->SetConfig = CameraSetConfig; - char *val = getenv("SET_DCC"); - dcc_flag = val ? strtol(val, NULL, 0) : DEFAULT_DCC; - DOMX_DEBUG(" DCC: 0 - disabled 1 - enabled : val: %d", dcc_flag); + pHandle->SendCommand = Camera_SendCommand; + pHandle->SetParameter = CameraSetParam; - if (dcc_flag) - { - eOsalError = - TIMM_OSAL_MutexObtain(cam_mutex, TIMM_OSAL_SUSPEND); - PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, - OMX_ErrorInsufficientResources, "Mutex lock failed"); - - if (numofInstance == 0) - { - dcc_eError = DCC_Init(hComponent); - if (dcc_eError != OMX_ErrorNone) - { - DOMX_DEBUG(" Error in DCC Init"); - } - - /* Configure Ducati to use DCC buffer from A9 side - *ONLY* if DCC_Init is successful. */ - if (dcc_eError == OMX_ErrorNone) - { - dcc_eError = send_DCCBufPtr(hComponent); - if (dcc_eError != OMX_ErrorNone) - { - DOMX_DEBUG(" Error in Sending DCC Buf ptr"); - } - DCC_DeInit(); - } - } - numofInstance = numofInstance + 1; - eOsalError = TIMM_OSAL_MutexRelease(cam_mutex); - PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, - OMX_ErrorInsufficientResources, "Mutex release failed"); - } EXIT: return eError; } @@ -397,6 +603,7 @@ OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE hComponent) OMX_ERRORTYPE eError = OMX_ErrorNone; #ifdef USE_ION int ret; + size_t stride; #endif OMX_S32 status = 0; @@ -454,32 +661,27 @@ OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE hComponent) return OMX_ErrorInsufficientResources; } dccbuf_size = (dccbuf_size + LINUX_PAGE_SIZE -1) & ~(LINUX_PAGE_SIZE - 1); - ret = ion_alloc(ion_fd, dccbuf_size, 0x1000, 1 << ION_HEAP_TYPE_CARVEOUT, &DCC_Buff); - if (ret) - return OMX_ErrorInsufficientResources; + ret = ion_alloc(ion_fd, dccbuf_size, 0x1000, 1 << ION_HEAP_TYPE_CARVEOUT, + (struct ion_handle **)&DCC_Buff); + + if (ret || ((int)DCC_Buff == -ENOMEM)) { + ret = ion_alloc_tiler(ion_fd, dccbuf_size, 1, TILER_PIXEL_FMT_PAGE, + OMAP_ION_HEAP_TILER_MASK, &DCC_Buff, &stride); + } + + if (ret || ((int)DCC_Buff == -ENOMEM)) { + DOMX_ERROR("FAILED to allocate DCC buffer of size=%d. ret=0x%x", + dccbuf_size, ret); + return OMX_ErrorInsufficientResources; + } if (ion_map(ion_fd, DCC_Buff, dccbuf_size, PROT_READ | PROT_WRITE, MAP_SHARED, 0, - &DCC_Buff_ptr,&mmap_fd) < 0) + (unsigned char **)&DCC_Buff_ptr, &mmap_fd) < 0) { DOMX_ERROR("userspace mapping of ION buffers returned error"); return OMX_ErrorInsufficientResources; } ptempbuf = DCC_Buff_ptr; -#else - MemReqDescTiler = - (MemAllocBlock *) TIMM_OSAL_Malloc((sizeof(MemAllocBlock) * 2), - TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_EXT); - PROXY_assert(MemReqDescTiler != NULL, - OMX_ErrorInsufficientResources, "Malloc failed"); - - /* Allocate 1D Tiler buffer for 'N'DCC files */ - MemReqDescTiler[0].fmt = PIXEL_FMT_PAGE; - MemReqDescTiler[0].dim.len = dccbuf_size; - MemReqDescTiler[0].stride = 0; - DCC_Buff = MemMgr_Alloc(MemReqDescTiler, 1); - PROXY_assert(DCC_Buff != NULL, - OMX_ErrorInsufficientResources, "ERROR Allocating 1D TILER BUF"); - ptempbuf = DCC_Buff; #endif dccbuf_size = read_DCCdir(ptempbuf, dcc_dir, nIndex); @@ -518,7 +720,11 @@ OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent) DOMX_ENTER("ENTER"); uribufparam.nSharedBuffSize = dccbuf_size; - uribufparam.pSharedBuff = (OMX_U8 *) DCC_Buff; +#ifdef USE_ION + uribufparam.pSharedBuff = (OMX_PTR) mmap_fd; +#else + uribufparam.pSharedBuff = (OMX_PTR) DCC_Buff; +#endif DOMX_DEBUG("SYSLINK MAPPED ADDR: 0x%x sizeof buffer %d", uribufparam.pSharedBuff, uribufparam.nSharedBuffSize); @@ -526,7 +732,7 @@ OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent) eError = __PROXY_SetParameter(hComponent, OMX_TI_IndexParamDccUriBuffer, &uribufparam, - &(uribufparam.pSharedBuff)); + &(uribufparam.pSharedBuff), 1); if (eError != OMX_ErrorNone) { DOMX_ERROR(" Error in SetParam for DCC Uri Buffer 0x%x", eError); @@ -646,14 +852,8 @@ void DCC_DeInit() ion_free(ion_fd, DCC_Buff); ion_close(ion_fd); DCC_Buff = NULL; -#else - MemMgr_Free(DCC_Buff); #endif } -#ifndef USE_ION - if (MemReqDescTiler) - TIMM_OSAL_Free(MemReqDescTiler); -#endif DOMX_EXIT("EXIT"); } |