Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (c) 2010, Texas Instruments Incorporated
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  * *  Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  *
     12  * *  Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * *  Neither the name of Texas Instruments Incorporated nor the names of
     17  *    its contributors may be used to endorse or promote products derived
     18  *    from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /**
     34  *  @file  omx_proxy_common.c
     35  *         This file contains methods that provides the functionality for
     36  *         the OpenMAX1.1 DOMX Framework OMX Common Proxy .
     37  *
     38  *  @path \WTSD_DucatiMMSW\framework\domx\omx_proxy_common\src
     39  *
     40  *  @rev 1.0
     41  */
     42 
     43 /*==============================================================
     44  *! Revision History
     45  *! ============================
     46  *! 29-Mar-2010 Abhishek Ranka : Revamped DOMX implementation
     47  *!
     48  *! 19-August-2009 B Ravi Kiran ravi.kiran (at) ti.com: Initial Version
     49  *================================================================*/
     50 
     51 /* ------compilation control switches ----------------------------------------*/
     52 #define TILER_BUFF
     53 #define ALLOCATE_TILER_BUFFER_IN_PROXY
     54 // This has been enabled enbled only in Android.mk
     55 // #define ENABLE_GRALLOC_BUFFER
     56 /******************************************************************
     57  *   INCLUDE FILES
     58  ******************************************************************/
     59 /* ----- system and platform files ----------------------------*/
     60 #include <string.h>
     61 
     62 #include "timm_osal_memory.h"
     63 #include "timm_osal_mutex.h"
     64 #include "OMX_TI_Common.h"
     65 #include "OMX_TI_Index.h"
     66 #include "OMX_TI_Core.h"
     67 /*-------program files ----------------------------------------*/
     68 #include "omx_proxy_common.h"
     69 #include "omx_rpc.h"
     70 #include "omx_rpc_stub.h"
     71 #include "omx_rpc_utils.h"
     72 #include "OMX_TI_IVCommon.h"
     73 
     74 #ifdef ALLOCATE_TILER_BUFFER_IN_PROXY
     75 
     76 #ifdef USE_ION
     77 #include <unistd.h>
     78 #include <ion.h>
     79 #include <sys/ioctl.h>
     80 #include <sys/mman.h>
     81 #include <sys/eventfd.h>
     82 #include <fcntl.h>
     83 
     84 #else
     85 #include "memmgr.h"
     86 #include "tiler.h"
     87 #endif
     88 
     89 #endif
     90 
     91 #ifdef  ENABLE_GRALLOC_BUFFERS
     92 #include "native_handle.h"
     93 #include "hal_public.h"
     94 #endif
     95 
     96 #ifdef TILER_BUFF
     97 #define PortFormatIsNotYUV 0
     98 
     99 #if 0
    100 static OMX_ERRORTYPE RPC_PrepareBuffer_Remote(PROXY_COMPONENT_PRIVATE *
    101     pCompPrv, OMX_COMPONENTTYPE * hRemoteComp, OMX_U32 nPortIndex,
    102     OMX_U32 nSizeBytes, OMX_BUFFERHEADERTYPE * pChironBuf,
    103     OMX_BUFFERHEADERTYPE * pDucBuf, OMX_PTR pBufToBeMapped);
    104 static OMX_ERRORTYPE RPC_PrepareBuffer_Chiron(PROXY_COMPONENT_PRIVATE *
    105     pCompPrv, OMX_COMPONENTTYPE * hRemoteComp, OMX_U32 nPortIndex,
    106     OMX_U32 nSizeBytes, OMX_BUFFERHEADERTYPE * pDucBuf,
    107     OMX_BUFFERHEADERTYPE * pChironBuf);
    108 static OMX_ERRORTYPE RPC_UnMapBuffer_Ducati(OMX_PTR pBuffer);
    109 static OMX_ERRORTYPE RPC_MapBuffer_Ducati(OMX_U8 * pBuf, OMX_U32 nBufLineSize,
    110     OMX_U32 nBufLines, OMX_U8 ** pMappedBuf, OMX_PTR pBufToBeMapped);
    111 
    112 static OMX_ERRORTYPE RPC_MapMetaData_Host(OMX_BUFFERHEADERTYPE * pBufHdr);
    113 static OMX_ERRORTYPE RPC_UnMapMetaData_Host(OMX_BUFFERHEADERTYPE * pBufHdr);
    114 #endif
    115 
    116 static OMX_ERRORTYPE _RPC_IsProxyComponent(OMX_HANDLETYPE hComponent,
    117     OMX_BOOL * bIsProxy);
    118 OMX_ERRORTYPE RPC_UTIL_GetStride(OMX_COMPONENTTYPE * hRemoteComp,
    119     OMX_U32 nPortIndex, OMX_U32 * nStride);
    120 OMX_ERRORTYPE RPC_UTIL_GetNumLines(OMX_COMPONENTTYPE * hComp,
    121     OMX_U32 nPortIndex, OMX_U32 * nNumOfLines);
    122 
    123 #endif
    124 
    125 #ifdef ALLOCATE_TILER_BUFFER_IN_PROXY
    126 
    127 static OMX_ERRORTYPE PROXY_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    128     OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,
    129     OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_PTR pAppPrivate,
    130     OMX_IN OMX_U32 nSizeBytes, OMX_IN OMX_U8 * pBuffer);
    131 #endif
    132 
    133 #define LINUX_PAGE_SIZE 4096
    134 #define MAXNAMESIZE 128
    135 
    136 #define CORE_MAX 4
    137 #define CORE_CHIRON 3
    138 #define CORE_SYSM3 2
    139 #define CORE_APPM3 1
    140 #define CORE_TESLA 0
    141 
    142 #define MAX_CORENAME_LENGTH 32
    143 char Core_Array[][MAX_CORENAME_LENGTH] =
    144     { "TESLA", "DUCATI1", "DUCATI0", "CHIRON" };
    145 
    146 /******************************************************************
    147  *   MACROS - LOCAL
    148  ******************************************************************/
    149 
    150 #define PROXY_checkRpcError() do { \
    151     if (eRPCError == RPC_OMX_ErrorNone) \
    152     { \
    153         DOMX_DEBUG("Corresponding RPC function executed successfully"); \
    154         eError = eCompReturn; \
    155         PROXY_assert((eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore), eError, "Error returned from OMX API in ducati"); \
    156     } else \
    157     { \
    158         DOMX_ERROR("RPC function returned error 0x%x", eRPCError); \
    159         switch (eRPCError) \
    160         { \
    161             case RPC_OMX_ErrorHardware: \
    162                 eError = OMX_ErrorHardware; \
    163             break; \
    164             case RPC_OMX_ErrorInsufficientResources: \
    165                 eError = OMX_ErrorInsufficientResources; \
    166             break; \
    167             case RPC_OMX_ErrorBadParameter: \
    168                 eError = OMX_ErrorBadParameter; \
    169             break; \
    170             case RPC_OMX_ErrorUnsupportedIndex: \
    171                 eError = OMX_ErrorUnsupportedIndex; \
    172             break; \
    173             case RPC_OMX_ErrorTimeout: \
    174                 eError = OMX_ErrorTimeout; \
    175             break; \
    176             default: \
    177                 eError = OMX_ErrorUndefined; \
    178         } \
    179     } \
    180 } while(0)
    181 
    182 #ifdef USE_ION
    183 
    184 RPC_OMX_ERRORTYPE RPC_RegisterBuffer(OMX_HANDLETYPE hRPCCtx, int fd,
    185 				     struct ion_handle **handle)
    186 {
    187 	int status;
    188 	struct ion_fd_data data;
    189 	RPC_OMX_CONTEXT *pRPCCtx = (RPC_OMX_CONTEXT *) hRPCCtx;
    190 
    191 	data.fd = fd;
    192 	status = ioctl(pRPCCtx->fd_omx, ION_IOC_IMPORT, &data);
    193 	if (status < 0)
    194 		return RPC_OMX_ErrorInsufficientResources;
    195 	*handle = data.handle;
    196 	return RPC_OMX_ErrorNone;
    197 }
    198 
    199 static OMX_ERRORTYPE PROXY_AllocateBufferIonCarveout(PROXY_COMPONENT_PRIVATE *pCompPrv,
    200 						 size_t len, struct ion_handle **handle)
    201 {
    202 	int fd;
    203 	int ret;
    204 	struct ion_handle *temp;
    205 
    206 	ret = ion_alloc(pCompPrv->ion_fd, len, 0x1000, 1 << ION_HEAP_TYPE_CARVEOUT, &temp);
    207 	DOMX_DEBUG("ION being USED for allocation!!!!! handle = %x, ret =%x",temp,ret);
    208 	if (ret)
    209 			return OMX_ErrorInsufficientResources;
    210 	/*
    211 	ret = ion_share(pCompPrv->ion_fd, temp, &fd);
    212 	if (ret) {
    213 		ion_free(pCompPrv->ion_fd, temp);
    214 		return OMX_ErrorHardware;
    215 	}
    216 	RPC_RegisterBuffer(pCompPrv->hRemoteComp, fd, handle);
    217 	close(fd);
    218 	ion_free(pCompPrv->ion_fd, temp);
    219 	*/
    220 	*handle = temp;
    221 	return OMX_ErrorNone;
    222 }
    223 
    224 #endif
    225 
    226 /* ===========================================================================*/
    227 /**
    228  * @name PROXY_EventHandler()
    229  * @brief
    230  * @param void
    231  * @return OMX_ErrorNone = Successful
    232  * @sa TBD
    233  *
    234  */
    235 /* ===========================================================================*/
    236 OMX_ERRORTYPE PROXY_EventHandler(OMX_HANDLETYPE hComponent,
    237     OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
    238     OMX_PTR pEventData)
    239 {
    240 	OMX_ERRORTYPE eError = OMX_ErrorNone;
    241 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
    242 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    243 	OMX_PTR pTmpData = NULL;
    244 
    245 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    246 
    247 	PROXY_require((hComp->pComponentPrivate != NULL),
    248 	    OMX_ErrorBadParameter,
    249 	    "This is fatal error, processing cant proceed - please debug");
    250 
    251 	DOMX_ENTER
    252 	    ("hComponent=%p, pCompPrv=%p, eEvent=%p, nData1=%p, nData2=%p, pEventData=%p",
    253 	    hComponent, pCompPrv, eEvent, nData1, nData2, pEventData);
    254 
    255 	switch (eEvent)
    256 	{
    257 #if 0
    258 	case OMX_TI_EventBufferRefCount:
    259 		DOMX_DEBUG("Received Ref Count Event");
    260 		/*nData1 will be pBufferHeader, nData2 will be present count. Need to find local
    261 		   buffer header for nData1 which is remote buffer header */
    262 
    263 		PROXY_assert((nData1 != 0), OMX_ErrorBadParameter,
    264 		    "Received NULL buffer header from OMX component");
    265 
    266 		/*find local buffer header equivalent */
    267 		for (count = 0; count < pCompPrv->nTotalBuffers; ++count)
    268 		{
    269 			if (pCompPrv->tBufList[count].pBufHeaderRemote ==
    270 			    nData1)
    271 			{
    272 				pLocalBufHdr =
    273 				    pCompPrv->tBufList[count].pBufHeader;
    274 				pLocalBufHdr->pBuffer =
    275 				    (OMX_U8 *) pCompPrv->tBufList[count].
    276 				    pBufferActual;
    277 				break;
    278 			}
    279 		}
    280 		PROXY_assert((count != pCompPrv->nTotalBuffers),
    281 		    OMX_ErrorBadParameter,
    282 		    "Received invalid-buffer header from OMX component");
    283 
    284 		/*update local buffer header */
    285 		nData1 = (OMX_U32) pLocalBufHdr;
    286 		break;
    287 #endif
    288 	case OMX_EventMark:
    289 		DOMX_DEBUG("Received Mark Event");
    290 		PROXY_assert((pEventData != NULL), OMX_ErrorUndefined,
    291 		    "MarkData corrupted");
    292 		pTmpData = pEventData;
    293 		pEventData =
    294 		    ((PROXY_MARK_DATA *) pEventData)->pMarkDataActual;
    295 		TIMM_OSAL_Free(pTmpData);
    296 		break;
    297 
    298 	default:
    299 		break;
    300 	}
    301 
    302       EXIT:
    303 	if (eError == OMX_ErrorNone)
    304 	{
    305 		pCompPrv->tCBFunc.EventHandler(hComponent,
    306 		    pCompPrv->pILAppData, eEvent, nData1, nData2, pEventData);
    307 	} else if (pCompPrv)
    308 	{
    309 		pCompPrv->tCBFunc.EventHandler(hComponent,
    310 		    pCompPrv->pILAppData, OMX_EventError, eError, 0, NULL);
    311 	}
    312 
    313 	DOMX_EXIT("eError: %d", eError);
    314 	return OMX_ErrorNone;
    315 }
    316 
    317 /* ===========================================================================*/
    318 /**
    319  * @name PROXY_EmptyBufferDone()
    320  * @brief
    321  * @param
    322  * @return OMX_ErrorNone = Successful
    323  * @sa TBD
    324  *
    325  */
    326 /* ===========================================================================*/
    327 static OMX_ERRORTYPE PROXY_EmptyBufferDone(OMX_HANDLETYPE hComponent,
    328     OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags)
    329 {
    330 	OMX_ERRORTYPE eError = OMX_ErrorNone;
    331 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
    332 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    333 	OMX_U16 count;
    334 	OMX_BUFFERHEADERTYPE *pBufHdr = NULL;
    335 
    336 	PROXY_require((hComp->pComponentPrivate != NULL),
    337 	    OMX_ErrorBadParameter,
    338 	    "This is fatal error, processing cant proceed - please debug");
    339 
    340 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    341 
    342 	DOMX_ENTER
    343 	    ("hComponent=%p, pCompPrv=%p, remoteBufHdr=%p, nFilledLen=%d, nOffset=%d, nFlags=%08x",
    344 	    hComponent, pCompPrv, remoteBufHdr, nfilledLen, nOffset, nFlags);
    345 
    346 	for (count = 0; count < pCompPrv->nTotalBuffers; ++count)
    347 	{
    348 		if (pCompPrv->tBufList[count].pBufHeaderRemote ==
    349 		    remoteBufHdr)
    350 		{
    351 			pBufHdr = pCompPrv->tBufList[count].pBufHeader;
    352 			pBufHdr->nFilledLen = nfilledLen;
    353 			pBufHdr->nOffset = nOffset;
    354 			pBufHdr->nFlags = nFlags;
    355 			/* Setting mark info to NULL. This would always be
    356 			   NULL in EBD, whether component has propagated the
    357 			   mark or has generated mark event */
    358 			pBufHdr->hMarkTargetComponent = NULL;
    359 			pBufHdr->pMarkData = NULL;
    360 			break;
    361 		}
    362 	}
    363 	PROXY_assert((count != pCompPrv->nTotalBuffers),
    364 	    OMX_ErrorBadParameter,
    365 	    "Received invalid-buffer header from OMX component");
    366 
    367       EXIT:
    368 	if (eError == OMX_ErrorNone)
    369 	{
    370 		pCompPrv->tCBFunc.EmptyBufferDone(hComponent,
    371 		    pCompPrv->pILAppData, pBufHdr);
    372 	} else if (pCompPrv)
    373 	{
    374 		pCompPrv->tCBFunc.EventHandler(hComponent,
    375 		    pCompPrv->pILAppData, OMX_EventError, eError, 0, NULL);
    376 	}
    377 
    378 	DOMX_EXIT("eError: %d", eError);
    379 	return OMX_ErrorNone;
    380 }
    381 
    382 /* ===========================================================================*/
    383 /**
    384  * @name PROXY_FillBufferDone()
    385  * @brief
    386  * @param
    387  * @return OMX_ErrorNone = Successful
    388  * @sa TBD
    389  *
    390  */
    391 /* ===========================================================================*/
    392 OMX_ERRORTYPE PROXY_FillBufferDone(OMX_HANDLETYPE hComponent,
    393     OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags,
    394     OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent,
    395     OMX_PTR pMarkData)
    396 {
    397 
    398 	OMX_ERRORTYPE eError = OMX_ErrorNone;
    399 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
    400 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    401 	OMX_U16 count;
    402 	OMX_BUFFERHEADERTYPE *pBufHdr = NULL;
    403 
    404 	PROXY_require((hComp->pComponentPrivate != NULL),
    405 	    OMX_ErrorBadParameter,
    406 	    "This is fatal error, processing cant proceed - please debug");
    407 
    408 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    409 
    410 	DOMX_ENTER
    411 	    ("hComponent=%p, pCompPrv=%p, remoteBufHdr=%p, nFilledLen=%d, nOffset=%d, nFlags=%08x",
    412 	    hComponent, pCompPrv, remoteBufHdr, nfilledLen, nOffset, nFlags);
    413 
    414 	for (count = 0; count < pCompPrv->nTotalBuffers; ++count)
    415 	{
    416 		if (pCompPrv->tBufList[count].pBufHeaderRemote ==
    417 		    remoteBufHdr)
    418 		{
    419 			pBufHdr = pCompPrv->tBufList[count].pBufHeader;
    420 			pBufHdr->nFilledLen = nfilledLen;
    421 			pBufHdr->nOffset = nOffset;
    422 			pBufHdr->nFlags = nFlags;
    423 			pBufHdr->nTimeStamp = nTimeStamp;
    424 			if (pMarkData != NULL)
    425 			{
    426 				/*Update mark info in the buffer header */
    427 				pBufHdr->pMarkData =
    428 				    ((PROXY_MARK_DATA *)
    429 				    pMarkData)->pMarkDataActual;
    430 				pBufHdr->hMarkTargetComponent =
    431 				    ((PROXY_MARK_DATA *)
    432 				    pMarkData)->hComponentActual;
    433 				TIMM_OSAL_Free(pMarkData);
    434 			}
    435 			break;
    436 		}
    437 	}
    438 	PROXY_assert((count != pCompPrv->nTotalBuffers),
    439 	    OMX_ErrorBadParameter,
    440 	    "Received invalid-buffer header from OMX component");
    441 
    442       EXIT:
    443 	if (eError == OMX_ErrorNone)
    444 	{
    445 		pCompPrv->tCBFunc.FillBufferDone(hComponent,
    446 		    pCompPrv->pILAppData, pBufHdr);
    447 	} else if (pCompPrv)
    448 	{
    449 		pCompPrv->tCBFunc.EventHandler(hComponent,
    450 		    pCompPrv->pILAppData, OMX_EventError, eError, 0, NULL);
    451 	}
    452 
    453 	DOMX_EXIT("eError: %d", eError);
    454 	return OMX_ErrorNone;
    455 }
    456 
    457 /* ===========================================================================*/
    458 /**
    459  * @name PROXY_EmptyThisBuffer()
    460  * @brief
    461  * @param void
    462  * @return OMX_ErrorNone = Successful
    463  * @sa TBD
    464  *
    465  */
    466 /* ===========================================================================*/
    467 OMX_ERRORTYPE PROXY_EmptyThisBuffer(OMX_HANDLETYPE hComponent,
    468     OMX_BUFFERHEADERTYPE * pBufferHdr)
    469 {
    470 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
    471 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    472 	PROXY_COMPONENT_PRIVATE *pCompPrv;
    473 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    474 	OMX_U32 count = 0;
    475 	OMX_COMPONENTTYPE *pMarkComp = NULL;
    476 	PROXY_COMPONENT_PRIVATE *pMarkCompPrv = NULL;
    477 	OMX_PTR pMarkData = NULL;
    478 	OMX_BOOL bFreeMarkIfError = OMX_FALSE;
    479 	OMX_BOOL bIsProxy = OMX_FALSE , bMapBuffer;
    480 
    481 	PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL);
    482 	PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter,
    483 	    NULL);
    484 	PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE);
    485 
    486 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    487 
    488 	DOMX_ENTER
    489 	    ("hComponent=%p, pCompPrv=%p, nFilledLen=%d, nOffset=%d, nFlags=%08x",
    490 	    hComponent, pCompPrv, pBufferHdr->nFilledLen,
    491 	    pBufferHdr->nOffset, pBufferHdr->nFlags);
    492 
    493 	/*First find the index of this buffer header to retrieve remote buffer header */
    494 	for (count = 0; count < pCompPrv->nTotalBuffers; count++)
    495 	{
    496 		if (pCompPrv->tBufList[count].pBufHeader == pBufferHdr)
    497 		{
    498 			DOMX_DEBUG("Buffer Index of Match %d ", count);
    499 			break;
    500 		}
    501 	}
    502 	PROXY_assert((count != pCompPrv->nTotalBuffers),
    503 	    OMX_ErrorBadParameter,
    504 	    "Could not find the remote header in buffer list");
    505 
    506 	if (pBufferHdr->hMarkTargetComponent != NULL)
    507 	{
    508 		pMarkComp =
    509 		    (OMX_COMPONENTTYPE *) (pBufferHdr->hMarkTargetComponent);
    510 		/* Check is mark comp is proxy */
    511 		eError = _RPC_IsProxyComponent(pMarkComp, &bIsProxy);
    512 		PROXY_assert(eError == OMX_ErrorNone, eError, "");
    513 
    514 		/*Replacing original mark data with proxy specific structure */
    515 		pMarkData = pBufferHdr->pMarkData;
    516 		pBufferHdr->pMarkData =
    517 		    TIMM_OSAL_Malloc(sizeof(PROXY_MARK_DATA), TIMM_OSAL_TRUE,
    518 		    0, TIMMOSAL_MEM_SEGMENT_INT);
    519 		PROXY_assert(pBufferHdr->pMarkData != NULL,
    520 		    OMX_ErrorInsufficientResources, "Malloc failed");
    521 		bFreeMarkIfError = OMX_TRUE;
    522 		((PROXY_MARK_DATA *) (pBufferHdr->
    523 			pMarkData))->hComponentActual = pMarkComp;
    524 		((PROXY_MARK_DATA *) (pBufferHdr->
    525 			pMarkData))->pMarkDataActual = pMarkData;
    526 
    527 		/* If proxy comp then replace hMarkTargetComponent with remote
    528 		   handle */
    529 		if (bIsProxy)
    530 		{
    531 			pMarkCompPrv = pMarkComp->pComponentPrivate;
    532 			PROXY_assert(pMarkCompPrv != NULL,
    533 			    OMX_ErrorBadParameter, NULL);
    534 
    535 			/* Replacing with remote component handle */
    536 			pBufferHdr->hMarkTargetComponent =
    537 			    ((RPC_OMX_CONTEXT *) pMarkCompPrv->hRemoteComp)->
    538 			    hActualRemoteCompHandle;
    539 		}
    540 	}
    541 
    542 	bMapBuffer =
    543 		pCompPrv->proxyPortBuffers[pBufferHdr->nInputPortIndex].proxyBufferType ==
    544 			EncoderMetadataPointers;
    545 	eRPCError =
    546 	    RPC_EmptyThisBuffer(pCompPrv->hRemoteComp, pBufferHdr,
    547 	    pCompPrv->tBufList[count].pBufHeaderRemote, &eCompReturn,bMapBuffer);
    548 
    549 	PROXY_checkRpcError();
    550 
    551       EXIT:
    552 	/*If ETB is about to return an error then this means that buffer has not
    553 	   been accepted by the component. Thus the allocated mark data will be
    554 	   lost so free it here. Also replace original mark data in the header */
    555 	if ((eError != OMX_ErrorNone) && bFreeMarkIfError)
    556 	{
    557 		pBufferHdr->hMarkTargetComponent =
    558 		    ((PROXY_MARK_DATA *) (pBufferHdr->
    559 			pMarkData))->hComponentActual;
    560 		pMarkData =
    561 		    ((PROXY_MARK_DATA *) (pBufferHdr->
    562 			pMarkData))->pMarkDataActual;
    563 		TIMM_OSAL_Free(pBufferHdr->pMarkData);
    564 		pBufferHdr->pMarkData = pMarkData;
    565 	}
    566 
    567 	DOMX_EXIT("eError: %d", eError);
    568 	return eError;
    569 }
    570 
    571 
    572 /* ===========================================================================*/
    573 /**
    574  * @name PROXY_FillThisBuffer()
    575  * @brief
    576  * @param void
    577  * @return OMX_ErrorNone = Successful
    578  * @sa TBD
    579  *
    580  */
    581 /* ===========================================================================*/
    582 OMX_ERRORTYPE PROXY_FillThisBuffer(OMX_HANDLETYPE hComponent,
    583     OMX_BUFFERHEADERTYPE * pBufferHdr)
    584 {
    585 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
    586 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    587 	PROXY_COMPONENT_PRIVATE *pCompPrv;
    588 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    589 	OMX_U32 count = 0;
    590 
    591 	PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL);
    592 	PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter,
    593 	    NULL);
    594 	PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE);
    595 
    596 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    597 
    598 	DOMX_ENTER
    599 	    ("hComponent = %p, pCompPrv = %p, nFilledLen = %d, nOffset = %d, nFlags = %08x",
    600 	    hComponent, pCompPrv, pBufferHdr->nFilledLen,
    601 	    pBufferHdr->nOffset, pBufferHdr->nFlags);
    602 
    603 	/*First find the index of this buffer header to retrieve remote buffer header */
    604 	for (count = 0; count < pCompPrv->nTotalBuffers; count++)
    605 	{
    606 		if (pCompPrv->tBufList[count].pBufHeader == pBufferHdr)
    607 		{
    608 			DOMX_DEBUG("Buffer Index of Match %d ", count);
    609 			break;
    610 		}
    611 	}
    612 	PROXY_assert((count != pCompPrv->nTotalBuffers),
    613 	    OMX_ErrorBadParameter,
    614 	    "Could not find the remote header in buffer list");
    615 
    616 	eRPCError = RPC_FillThisBuffer(pCompPrv->hRemoteComp, pBufferHdr,
    617 	    pCompPrv->tBufList[count].pBufHeaderRemote, &eCompReturn);
    618 
    619 	PROXY_checkRpcError();
    620 
    621       EXIT:
    622 	DOMX_EXIT("eError: %d", eError);
    623 	return eError;
    624 }
    625 
    626 
    627 /* ===========================================================================*/
    628 /**
    629  * @name PROXY_AllocateBuffer()
    630  * @brief
    631  * @param void
    632  * @return OMX_ErrorNone = Successful
    633  * @sa TBD
    634  *
    635  */
    636 /* ===========================================================================*/
    637 OMX_ERRORTYPE PROXY_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    638     OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,
    639     OMX_IN OMX_U32 nPortIndex,
    640     OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes)
    641 {
    642 	OMX_ERRORTYPE eError = OMX_ErrorNone;
    643 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
    644 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    645 	OMX_U32 currentBuffer = 0, i = 0;
    646 	OMX_BOOL bSlotFound = OMX_FALSE;
    647 #ifdef USE_ION
    648 	struct ion_handle *handle = NULL;
    649 #else
    650      	MemAllocBlock block;
    651         MemAllocBlock blocks[2];
    652 #endif
    653 
    654 #ifdef ALLOCATE_TILER_BUFFER_IN_PROXY
    655 	// Do the tiler allocations in Proxy and call use buffers on Ducati.
    656 
    657 	//Round Off the size to allocate and map to next page boundary.
    658 	OMX_U32 nSize = (nSizeBytes + LINUX_PAGE_SIZE - 1) & ~(LINUX_PAGE_SIZE - 1);
    659 	OMX_U32 nStride = 0;
    660 	OMX_U8* pMemptr = NULL;
    661 	OMX_CONFIG_RECTTYPE tParamRect;
    662 	OMX_PARAM_PORTDEFINITIONTYPE tParamPortDef;
    663 
    664 	PROXY_require((hComp->pComponentPrivate != NULL),
    665 	    OMX_ErrorBadParameter, NULL);
    666 	PROXY_require(ppBufferHdr != NULL, OMX_ErrorBadParameter,
    667 	    "Pointer to buffer header is NULL");
    668 
    669 #ifndef USE_ION
    670     	memset(&block, 0, sizeof(MemAllocBlock));
    671         memset(blocks, 0, sizeof(MemAllocBlock)*2);
    672 #endif
    673 
    674 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    675 
    676 	DOMX_ENTER
    677 	    ("hComponent = %p, pCompPrv = %p, nPortIndex = %p, pAppPrivate = %p, nSizeBytes = %d",
    678 	    hComponent, pCompPrv, nPortIndex, pAppPrivate, nSizeBytes);
    679 
    680 	/*To find whether buffer is 2D or 1D */
    681 	eError =
    682 	    RPC_UTIL_GetStride(pCompPrv->hRemoteComp, nPortIndex, &nStride);
    683 	PROXY_assert(eError == OMX_ErrorNone, eError,
    684 	    "Failed to get stride of component");
    685 
    686 	if (nStride == LINUX_PAGE_SIZE && \
    687 			pCompPrv->proxyPortBuffers[nPortIndex].proxyBufferType != EncoderMetadataPointers) //Allocate 2D buffer
    688 	{
    689 #if USE_ION
    690 		DOMX_ERROR ("Tiler 2d port buffers not implemented");
    691 		eError = OMX_ErrorNotImplemented;
    692 		goto EXIT;
    693 #else
    694 	    	tParamRect.nSize = sizeof(OMX_CONFIG_RECTTYPE);
    695 	    	tParamRect.nVersion.s.nVersionMajor = 1;
    696 	    	tParamRect.nVersion.s.nVersionMinor = 1;
    697 	    	tParamRect.nVersion.s.nRevision = 0;
    698 	    	tParamRect.nVersion.s.nStep = 0;
    699 		tParamRect.nPortIndex = nPortIndex;
    700 
    701 		eError = PROXY_GetParameter(hComponent, (OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension, &tParamRect);
    702 		if(eError == OMX_ErrorNone)
    703 		{
    704 			blocks[0].fmt = PIXEL_FMT_8BIT;
    705 			blocks[0].dim.area.width  = tParamRect.nWidth;
    706 			blocks[0].dim.area.height = tParamRect.nHeight;
    707 			blocks[0].stride = 0;
    708 
    709 			blocks[1].fmt = PIXEL_FMT_16BIT;
    710 			blocks[1].dim.area.width  = tParamRect.nWidth >> 1;
    711 			blocks[1].dim.area.height = tParamRect.nHeight >> 1;
    712 			blocks[1].stride = 0;
    713 
    714 		}
    715 		else if(eError == OMX_ErrorUnsupportedIndex)
    716 		{
    717 			DOMX_ERROR("Component does not support OMX_TI_IndexParam2DBufferAllocDimension, \
    718 					reverting to OMX_PARAM_PORTDEFINITIONTYPE");
    719 			tParamPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
    720 		    	tParamPortDef.nVersion.s.nVersionMajor = 1;
    721 		    	tParamPortDef.nVersion.s.nVersionMinor = 1;
    722 		    	tParamPortDef.nVersion.s.nRevision = 0;
    723 		    	tParamPortDef.nVersion.s.nStep = 0;
    724 			tParamPortDef.nPortIndex = nPortIndex;
    725 
    726 			eError = PROXY_GetParameter(hComponent, OMX_IndexParamPortDefinition, &tParamPortDef);
    727 			if(eError != OMX_ErrorNone)
    728 			{
    729 				DOMX_ERROR("PROXY_GetParameter returns err %d (0x%x)", eError, eError);
    730 				return eError;
    731 			}
    732 
    733 			blocks[0].fmt = PIXEL_FMT_8BIT;
    734 			blocks[0].dim.area.width  = tParamPortDef.format.video.nFrameWidth;
    735 			blocks[0].dim.area.height = tParamPortDef.format.video.nFrameHeight;
    736 			blocks[0].stride = 0;
    737 
    738 			blocks[1].fmt = PIXEL_FMT_16BIT;
    739 			blocks[1].dim.area.width  = tParamPortDef.format.video.nFrameWidth >> 1;
    740 			blocks[1].dim.area.height = tParamPortDef.format.video.nFrameHeight >> 1;
    741 			blocks[1].stride = 0;
    742 		}
    743 		if(eError != OMX_ErrorNone)
    744 		{
    745 			DOMX_ERROR("PROXY_GetParameter returns err %d (0x%x)", eError, eError);
    746 			return eError;
    747 		}
    748 
    749 		pMemptr = (OMX_U8*) MemMgr_Alloc(blocks, 2);
    750 		PROXY_assert((pMemptr != NULL), OMX_ErrorInsufficientResources, "MemMgr_Alloc returns NULL, abort,");
    751 
    752 		DOMX_DEBUG(" Y Buffer : Allocated Width:%d, Height:%d",blocks[0].dim.area.width, blocks[0].dim.area.height);
    753 #endif
    754 	}
    755 #ifdef USE_ION
    756 	else if (pCompPrv->bUseIon == OMX_TRUE)
    757 	{
    758 		eError = PROXY_AllocateBufferIonCarveout(pCompPrv, nSize, &handle);
    759 		pMemptr = handle;
    760 		DOMX_DEBUG ("Ion handle recieved = %x",handle);
    761 		if (eError != OMX_ErrorNone)
    762 			return eError;
    763 	}
    764 #else
    765 	else //Allocate 1D buffer
    766 	{
    767 		block.fmt = PIXEL_FMT_PAGE;
    768     		block.dim.len = nSize;
    769     	        block.stride = 0;
    770 
    771     	        pMemptr = (OMX_U8*) MemMgr_Alloc(&block, 1);
    772                 PROXY_assert((pMemptr != NULL), OMX_ErrorInsufficientResources,"MemMgr_Alloc returns NULL, abort,");
    773     	}
    774 #endif
    775 	/*Pick up 1st empty slot */
    776 	/*The same empty spot will be picked up by the subsequent
    777 	Use buffer call to fill in the corresponding buffer
    778 	Buffer header in the list */
    779 
    780         for (i = 0; i < pCompPrv->nTotalBuffers; i++)
    781         {
    782                 if (pCompPrv->tBufList[i].pBufHeader == NULL)
    783                 {
    784                         currentBuffer = i;
    785                         bSlotFound = OMX_TRUE;
    786                         break;
    787 		}
    788         }
    789 
    790 	if (!bSlotFound)
    791 	{
    792 		currentBuffer = pCompPrv->nTotalBuffers;
    793 	}
    794 
    795 	/*No need to increment Allocated buffers here.
    796 	It will be done in the subsequent use buffer call below*/
    797 
    798 	eError = PROXY_UseBuffer(hComponent, ppBufferHdr, nPortIndex, pAppPrivate, nSize, pMemptr);
    799 
    800 	if(eError != OMX_ErrorNone) {
    801 		DOMX_ERROR("PROXY_UseBuffer in PROXY_AllocateBuffer failed with error %d (0x%08x)", eError, eError);
    802 #ifdef USE_ION
    803 		ion_free(pCompPrv->ion_fd, pMemptr);
    804 #else
    805 		MemMgr_Free(pMemptr);
    806 #endif
    807 		goto EXIT;
    808 	}
    809 	else {
    810 		pCompPrv->tBufList[currentBuffer].pYBuffer = pMemptr;
    811 	}
    812 
    813 #ifdef USE_ION
    814 	if (pCompPrv->bUseIon == OMX_TRUE && pCompPrv->bMapIonBuffers == OMX_TRUE)
    815 	{
    816 		DOMX_DEBUG("before mapping, handle = %x, nSize = %d",handle,nSize);
    817         	if (ion_map(pCompPrv->ion_fd, handle, nSize, PROT_READ | PROT_WRITE, MAP_SHARED, 0,
    818                           &((*ppBufferHdr)->pBuffer),
    819                                     &(pCompPrv->tBufList[currentBuffer].mmap_fd)) < 0)
    820 		{
    821 			DOMX_ERROR("userspace mapping of ION buffers returned error");
    822 			return OMX_ErrorInsufficientResources;
    823 		}
    824 		//ion_free(pCompPrv->ion_fd, handleToMap);
    825 	}
    826 #endif
    827 
    828 #else
    829 	//This code is the un-changed version of original implementation.
    830 	OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
    831 	OMX_U32 pBufHeaderRemote = 0;
    832 	OMX_U32 currentBuffer = 0, i = 0;
    833 	OMX_U8 *pBuffer = NULL;
    834 	OMX_TI_PLATFORMPRIVATE *pPlatformPrivate = NULL;
    835 	OMX_BOOL bSlotFound = OMX_FALSE;
    836 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    837 	OMX_ERRORTYPE eCompReturn = OMX_ErrorNone;
    838 
    839 	PROXY_require((hComp->pComponentPrivate != NULL),
    840 	    OMX_ErrorBadParameter, NULL);
    841 	PROXY_require(ppBufferHdr != NULL, OMX_ErrorBadParameter,
    842 	    "Pointer to buffer header is NULL");
    843 
    844 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    845 
    846 	DOMX_ENTER
    847 	    ("hComponent = %p, pCompPrv = %p, nPortIndex = %p, pAppPrivate = %p, nSizeBytes = %d",
    848 	    hComponent, pCompPrv, nPortIndex, pAppPrivate, nSizeBytes);
    849 
    850 	/*Pick up 1st empty slot */
    851 	for (i = 0; i < pCompPrv->nTotalBuffers; i++)
    852 	{
    853 		if (pCompPrv->tBufList[i].pBufHeader == 0)
    854 		{
    855 			currentBuffer = i;
    856 			bSlotFound = OMX_TRUE;
    857 			break;
    858 		}
    859 	}
    860 	if (!bSlotFound)
    861 	{
    862 		currentBuffer = pCompPrv->nTotalBuffers;
    863 	}
    864 
    865 	DOMX_DEBUG("In AB, no. of buffers = %d", pCompPrv->nTotalBuffers);
    866 	PROXY_assert((pCompPrv->nTotalBuffers < MAX_NUM_PROXY_BUFFERS),
    867 	    OMX_ErrorInsufficientResources,
    868 	    "Proxy cannot handle more than MAX buffers");
    869 
    870 	//Allocating Local bufferheader to be maintained locally within proxy
    871 	pBufferHeader =
    872 	    (OMX_BUFFERHEADERTYPE *)
    873 	    TIMM_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE), TIMM_OSAL_TRUE, 0,
    874 	    TIMMOSAL_MEM_SEGMENT_INT);
    875 	PROXY_assert((pBufferHeader != NULL), OMX_ErrorInsufficientResources,
    876 	    "Allocation of Buffer Header structure failed");
    877 
    878 	pPlatformPrivate =
    879 	    (OMX_TI_PLATFORMPRIVATE *)
    880 	    TIMM_OSAL_Malloc(sizeof(OMX_TI_PLATFORMPRIVATE), TIMM_OSAL_TRUE,
    881 	    0, TIMMOSAL_MEM_SEGMENT_INT);
    882 	PROXY_assert(pPlatformPrivate != NULL, OMX_ErrorInsufficientResources,
    883 	    "Allocation of platform private structure failed");
    884 	pBufferHeader->pPlatformPrivate = pPlatformPrivate;
    885 
    886 	DOMX_DEBUG(" Calling RPC ");
    887 
    888 	eRPCError =
    889 	    RPC_AllocateBuffer(pCompPrv->hRemoteComp, &pBufferHeader,
    890 	    nPortIndex, &pBufHeaderRemote, pAppPrivate, nSizeBytes,
    891 	    &eCompReturn);
    892 
    893 	PROXY_checkRpcError();
    894 
    895 	DOMX_DEBUG("Allocate Buffer Successful");
    896 	DOMX_DEBUG("Value of pBufHeaderRemote: %p   LocalBufferHdr :%p",
    897 	    pBufHeaderRemote, pBufferHeader);
    898 
    899 	pCompPrv->tBufList[currentBuffer].pBufHeader = pBufferHeader;
    900 	pCompPrv->tBufList[currentBuffer].pBufHeaderRemote = pBufHeaderRemote;
    901 
    902 
    903 	//keeping track of number of Buffers
    904 	pCompPrv->nAllocatedBuffers++;
    905 
    906 	if (pCompPrv->nTotalBuffers < pCompPrv->nAllocatedBuffers)
    907 	{
    908 		pCompPrv->nTotalBuffers = pCompPrv->nAllocatedBuffers;
    909 	}
    910 
    911 	*ppBufferHdr = pBufferHeader;
    912 
    913       EXIT:
    914 	if (eError != OMX_ErrorNone)
    915 	{
    916 		if (pPlatformPrivate)
    917 			TIMM_OSAL_Free(pPlatformPrivate);
    918 		if (pBufferHeader)
    919 			TIMM_OSAL_Free(pBufferHeader);
    920 	}
    921 	DOMX_EXIT("eError: %d", eError);
    922 	return eError;
    923 #endif //ALLOCATE_TILER_BUFFER_IN_PROXY
    924 
    925       EXIT:
    926 	DOMX_EXIT("eError: %d", eError);
    927 	return eError;
    928 }
    929 
    930 
    931 /* ===========================================================================*/
    932 /**
    933  * @name PROXY_UseBuffer()
    934  * @brief
    935  * @param void
    936  * @return OMX_ErrorNone = Successful
    937  * @sa TBD
    938  *
    939  */
    940 /* ===========================================================================*/
    941 static OMX_ERRORTYPE PROXY_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    942     OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,
    943     OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_PTR pAppPrivate,
    944     OMX_IN OMX_U32 nSizeBytes, OMX_IN OMX_U8 * pBuffer)
    945 {
    946 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
    947 	OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
    948 	OMX_U32 pBufHeaderRemote = 0;
    949 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
    950 	OMX_U32 currentBuffer = 0, i = 0, nStride = 0, nNumLines = 0;
    951 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
    952 	OMX_TI_PLATFORMPRIVATE *pPlatformPrivate = NULL;
    953 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
    954 	OMX_BOOL bSlotFound = OMX_FALSE;
    955 	OMX_PTR pAuxBuf0 = pBuffer;
    956 	OMX_TI_PARAM_METADATABUFFERINFO tMetaDataBuffer;
    957 	OMX_U32 nBufferHeight = 0;
    958 	OMX_CONFIG_RECTTYPE tParamRect;
    959 	OMX_PARAM_PORTDEFINITIONTYPE tParamPortDef;
    960 
    961 #ifdef USE_ION
    962 	OMX_PTR pMetadataBuffer = NULL;
    963 #else
    964 	MemAllocBlock block;
    965 #endif
    966 
    967 	PROXY_require((hComp->pComponentPrivate != NULL),
    968 	    OMX_ErrorBadParameter, NULL);
    969 	PROXY_require(ppBufferHdr != NULL, OMX_ErrorBadParameter,
    970 	    "Pointer to buffer header is NULL");
    971 
    972 #ifndef USE_ION
    973 	memset(&block, 0, sizeof(MemAllocBlock));
    974 #endif
    975 
    976 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
    977 
    978 	DOMX_ENTER
    979 	    ("hComponent = %p, pCompPrv = %p, nPortIndex = %p, pAppPrivate = %p, nSizeBytes = %d, pBuffer = %p",
    980 	    hComponent, pCompPrv, nPortIndex, pAppPrivate, nSizeBytes,
    981 	    pBuffer);
    982 
    983 	/*Pick up 1st empty slot */
    984 	for (i = 0; i < pCompPrv->nTotalBuffers; i++)
    985 	{
    986 		if (pCompPrv->tBufList[i].pBufHeader == 0)
    987 		{
    988 			currentBuffer = i;
    989 			bSlotFound = OMX_TRUE;
    990 			break;
    991 		}
    992 	}
    993 	if (!bSlotFound)
    994 	{
    995 		currentBuffer = pCompPrv->nTotalBuffers;
    996 	}
    997 	DOMX_DEBUG("In UB, no. of buffers = %d", pCompPrv->nTotalBuffers);
    998 
    999 	PROXY_assert((pCompPrv->nTotalBuffers < MAX_NUM_PROXY_BUFFERS),
   1000 	    OMX_ErrorInsufficientResources,
   1001 	    "Proxy cannot handle more than MAX buffers");
   1002 
   1003 	//Allocating Local bufferheader to be maintained locally within proxy
   1004 	pBufferHeader =
   1005 	    (OMX_BUFFERHEADERTYPE *)
   1006 	    TIMM_OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE), TIMM_OSAL_TRUE, 0,
   1007 	    TIMMOSAL_MEM_SEGMENT_INT);
   1008 	PROXY_assert((pBufferHeader != NULL), OMX_ErrorInsufficientResources,
   1009 	    "Allocation of Buffer Header structure failed");
   1010 
   1011 	pPlatformPrivate =
   1012 	    (OMX_TI_PLATFORMPRIVATE *)
   1013 	    TIMM_OSAL_Malloc(sizeof(OMX_TI_PLATFORMPRIVATE), TIMM_OSAL_TRUE,
   1014 	    0, TIMMOSAL_MEM_SEGMENT_INT);
   1015 	PROXY_assert(pPlatformPrivate != NULL, OMX_ErrorInsufficientResources,
   1016 	    "Allocation of platform private structure failed");
   1017 	TIMM_OSAL_Memset(pPlatformPrivate, 0, sizeof(OMX_TI_PLATFORMPRIVATE));
   1018 
   1019 	pBufferHeader->pPlatformPrivate = pPlatformPrivate;
   1020 	((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->nSize = sizeof(OMX_TI_PLATFORMPRIVATE);
   1021 
   1022 #ifdef ENABLE_GRALLOC_BUFFERS
   1023 
   1024 	if(pCompPrv->proxyPortBuffers[nPortIndex].proxyBufferType == GrallocPointers)
   1025 	{
   1026 		//Extracting buffer pointer from the gralloc buffer
   1027 		pAuxBuf0 = (OMX_U8 *)(((IMG_native_handle_t*)pBuffer)->fd[0]);
   1028 	}
   1029 #endif
   1030 
   1031 	DOMX_DEBUG("Preparing buffer to Remote Core...");
   1032 	pBufferHeader->pBuffer = pBuffer;
   1033 	/*To find whether buffer is 2D or 1D */
   1034 	eError =
   1035 	    RPC_UTIL_GetStride(pCompPrv->hRemoteComp, nPortIndex, &nStride);
   1036 	PROXY_assert(eError == OMX_ErrorNone, eError,
   1037 	    "Failed to get stride of component");
   1038 	if (nStride == LINUX_PAGE_SIZE)
   1039 	{
   1040 		// Change this to extract UV pointer from gralloc handle once new gralloc interface is available
   1041 		/*2D buffer, assume NV12 format */
   1042 		eError =
   1043 		    RPC_UTIL_GetNumLines(pCompPrv->hRemoteComp, nPortIndex,
   1044 		    &nNumLines);
   1045 		PROXY_assert(eError == OMX_ErrorNone, eError,
   1046 		    "Failed to get num of lines");
   1047 
   1048 		if(pCompPrv->proxyPortBuffers[nPortIndex].proxyBufferType == GrallocPointers)
   1049 		{
   1050 			((OMX_TI_PLATFORMPRIVATE *) pBufferHeader->pPlatformPrivate)->
   1051 				pAuxBuf1 = (OMX_U8 *)(((IMG_native_handle_t*)pBuffer)->fd[1]);
   1052 		}
   1053 #if 0
   1054 		else
   1055 		{
   1056 		    	tParamRect.nSize = sizeof(OMX_CONFIG_RECTTYPE);
   1057 		    	tParamRect.nVersion.s.nVersionMajor = 1;
   1058 		    	tParamRect.nVersion.s.nVersionMinor = 1;
   1059 		    	tParamRect.nVersion.s.nRevision = 0;
   1060 		    	tParamRect.nVersion.s.nStep = 0;
   1061 			tParamRect.nPortIndex = nPortIndex;
   1062 
   1063 			eError = PROXY_GetParameter(hComponent, (OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension, &tParamRect);
   1064 			if(eError == OMX_ErrorNone)
   1065 			{
   1066 				nBufferHeight = tParamRect.nHeight;
   1067 			}
   1068 			else if(eError == OMX_ErrorUnsupportedIndex)
   1069 			{
   1070 				DOMX_ERROR("Component does not support OMX_TI_IndexParam2DBufferAllocDimension, \
   1071 						reverting to OMX_PARAM_PORTDEFINITIONTYPE");
   1072 				tParamPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
   1073 			    	tParamPortDef.nVersion.s.nVersionMajor = 1;
   1074 			    	tParamPortDef.nVersion.s.nVersionMinor = 1;
   1075 			    	tParamPortDef.nVersion.s.nRevision = 0;
   1076 			    	tParamPortDef.nVersion.s.nStep = 0;
   1077 				tParamPortDef.nPortIndex = nPortIndex;
   1078 
   1079 				eError = PROXY_GetParameter(hComponent, OMX_IndexParamPortDefinition, &tParamPortDef);
   1080 				if(eError != OMX_ErrorNone)
   1081 				{
   1082 					DOMX_ERROR("PROXY_GetParameter returns err %d (0x%x)", eError, eError);
   1083 					return eError;
   1084 				}
   1085 
   1086 				nBufferHeight = tParamPortDef.format.video.nFrameHeight;
   1087 			}
   1088 			if(eError != OMX_ErrorNone)
   1089 			{
   1090 				DOMX_ERROR("PROXY_GetParameter returns err %d (0x%x)", eError, eError);
   1091 				return eError;
   1092 			}
   1093 
   1094 			((OMX_TI_PLATFORMPRIVATE *) pBufferHeader->pPlatformPrivate)->
   1095 				pAuxBuf1 = (OMX_U8*) ((OMX_U32)pBuffer + (LINUX_PAGE_SIZE*nBufferHeight));
   1096 		}
   1097 #endif
   1098 		if(pCompPrv->proxyPortBuffers[nPortIndex].proxyBufferType == EncoderMetadataPointers)
   1099 		{
   1100 			((OMX_TI_PLATFORMPRIVATE *) pBufferHeader->pPlatformPrivate)->
   1101 				pAuxBuf1 = NULL;
   1102 		}
   1103 	}
   1104 
   1105 	/*Initializing Structure */
   1106 	tMetaDataBuffer.nSize = sizeof(OMX_TI_PARAM_METADATABUFFERINFO);
   1107 	tMetaDataBuffer.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
   1108 	tMetaDataBuffer.nVersion.s.nVersionMinor = OMX_VER_MINOR;
   1109 	tMetaDataBuffer.nVersion.s.nRevision = 0x0;
   1110 	tMetaDataBuffer.nVersion.s.nStep = 0x0;
   1111 	tMetaDataBuffer.nPortIndex = nPortIndex;
   1112 	eError = PROXY_GetParameter(hComponent, (OMX_INDEXTYPE)OMX_TI_IndexParamMetaDataBufferInfo, (OMX_PTR)&tMetaDataBuffer);
   1113 	PROXY_assert(eError == OMX_ErrorNone, eError,
   1114 	    "Get Parameter for Metadata infor failed");
   1115 
   1116 	DOMX_DEBUG("Metadata size = %d",tMetaDataBuffer.nMetaDataSize);
   1117 
   1118 	if(tMetaDataBuffer.bIsMetaDataEnabledOnPort)
   1119 	{
   1120 #ifdef USE_ION
   1121 		((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->nMetaDataSize =
   1122 			(tMetaDataBuffer.nMetaDataSize + LINUX_PAGE_SIZE - 1) & ~(LINUX_PAGE_SIZE -1);
   1123 		eError = PROXY_AllocateBufferIonCarveout(pCompPrv, ((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->nMetaDataSize,
   1124 			&(((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer));
   1125 		pCompPrv->tBufList[currentBuffer].pMetaDataBuffer = ((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->
   1126 			pPlatformPrivate)->pMetaDataBuffer;
   1127 		DOMX_DEBUG("Metadata buffer ion handle = %d",((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer);
   1128 #else
   1129 		block.fmt = PIXEL_FMT_PAGE;
   1130 		block.dim.len = tMetaDataBuffer.nMetaDataSize;
   1131 		((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->
   1132 			pPlatformPrivate)->pMetaDataBuffer = MemMgr_Alloc(&block, 1);
   1133 		PROXY_assert(((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->
   1134 			pPlatformPrivate)->pMetaDataBuffer != NULL,OMX_ErrorInsufficientResources,
   1135 				"MemMngr alloc call for allocating metadata buffers failed");
   1136 		((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->nMetaDataSize = tMetaDataBuffer.nMetaDataSize;
   1137 		DOMX_DEBUG("Metadata buffer = %d",((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer);
   1138 #endif
   1139 	}
   1140 
   1141 	eRPCError = RPC_UseBuffer(pCompPrv->hRemoteComp, &pBufferHeader, nPortIndex,
   1142 		pAppPrivate, nSizeBytes, pAuxBuf0, &pBufHeaderRemote, &eCompReturn);
   1143 
   1144 	PROXY_checkRpcError();
   1145 
   1146 	DOMX_DEBUG("Use Buffer Successful");
   1147 	DOMX_DEBUG
   1148 	    ("Value of pBufHeaderRemote: %p LocalBufferHdr :%p, LocalBuffer :%p",
   1149 	    pBufHeaderRemote, pBufferHeader, pBufferHeader->pBuffer);
   1150 
   1151 #ifdef USE_ION
   1152 	if (pCompPrv->bUseIon == OMX_TRUE && pCompPrv->bMapIonBuffers == OMX_TRUE && tMetaDataBuffer.bIsMetaDataEnabledOnPort)
   1153 	{
   1154 		DOMX_DEBUG("Metadata buffer ion handle given to ion map = %d",
   1155 			((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer);
   1156         	if (ion_map(pCompPrv->ion_fd, ((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer,
   1157 			((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->nMetaDataSize, PROT_READ | PROT_WRITE, MAP_SHARED, 0,
   1158 				&pMetadataBuffer,&(pCompPrv->tBufList[currentBuffer].mmap_fd_metadata_buff)) < 0)
   1159 		{
   1160 			DOMX_ERROR("userspace mapping of ION metadata buffers returned error");
   1161 			return OMX_ErrorInsufficientResources;
   1162 		}
   1163 		((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer = pMetadataBuffer;
   1164 		//ion_free(pCompPrv->ion_fd, handleToMap);
   1165 		memset(((OMX_TI_PLATFORMPRIVATE *)pBufferHeader->pPlatformPrivate)->pMetaDataBuffer,
   1166 			0x0, tMetaDataBuffer.nMetaDataSize);
   1167 	}
   1168 #endif
   1169 
   1170 	//Storing details of pBufferHeader/Mapped/Actual buffer address locally.
   1171 	pCompPrv->tBufList[currentBuffer].pBufHeader = pBufferHeader;
   1172 	pCompPrv->tBufList[currentBuffer].pBufHeaderRemote = pBufHeaderRemote;
   1173 
   1174 	//keeping track of number of Buffers
   1175 	pCompPrv->nAllocatedBuffers++;
   1176 	if (pCompPrv->nTotalBuffers < pCompPrv->nAllocatedBuffers)
   1177 		pCompPrv->nTotalBuffers = pCompPrv->nAllocatedBuffers;
   1178 
   1179 	DOMX_DEBUG("Updating no. of buffer to %d", pCompPrv->nTotalBuffers);
   1180 
   1181 	*ppBufferHdr = pBufferHeader;
   1182 
   1183       EXIT:
   1184 	if (eError != OMX_ErrorNone)
   1185 	{
   1186 		if (pPlatformPrivate)
   1187 			TIMM_OSAL_Free(pPlatformPrivate);
   1188 		if (pBufferHeader)
   1189 			TIMM_OSAL_Free(pBufferHeader);
   1190 	}
   1191 	DOMX_EXIT("eError: %d", eError);
   1192 	return eError;
   1193 }
   1194 
   1195 /* ===========================================================================*/
   1196 /**
   1197  * @name PROXY_FreeBuffer()
   1198  * @brief
   1199  * @param void
   1200  * @return OMX_ErrorNone = Successful
   1201  * @sa TBD
   1202  *
   1203  */
   1204 /* ===========================================================================*/
   1205 OMX_ERRORTYPE PROXY_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,
   1206     OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr)
   1207 {
   1208 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1209 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1210 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1211 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone, eTmpRPCError =
   1212 	    RPC_OMX_ErrorNone;
   1213 	OMX_U32 count = 0, nStride = 0;
   1214 	OMX_U32 pBuffer = 0;
   1215 	OMX_PTR pMetaDataBuffer = NULL;
   1216 
   1217 	PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL);
   1218 	PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter,
   1219 	    NULL);
   1220 	PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE);
   1221 
   1222 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1223 
   1224 	DOMX_ENTER
   1225 	    ("hComponent = %p, pCompPrv = %p, nPortIndex = %p, pBufferHdr = %p, pBuffer = %p",
   1226 	    hComponent, pCompPrv, nPortIndex, pBufferHdr,
   1227 	    pBufferHdr->pBuffer);
   1228 
   1229 	for (count = 0; count < pCompPrv->nTotalBuffers; count++)
   1230 	{
   1231 		if (pCompPrv->tBufList[count].pBufHeader == pBufferHdr)
   1232 		{
   1233 			DOMX_DEBUG("Buffer Index of Match %d", count);
   1234 			break;
   1235 		}
   1236 	}
   1237 	PROXY_assert((count != pCompPrv->nTotalBuffers),
   1238 	    OMX_ErrorBadParameter,
   1239 	    "Could not find the mapped address in component private buffer list");
   1240 
   1241 	pBuffer = pBufferHdr->pBuffer;
   1242 	/*Not having asserts from this point since even if error occurs during
   1243 	   unmapping/freeing, still trying to clean up as much as possible */
   1244 
   1245 	eRPCError =
   1246 	    RPC_FreeBuffer(pCompPrv->hRemoteComp, nPortIndex,
   1247 	    pCompPrv->tBufList[count].pBufHeaderRemote, pBuffer,
   1248 	    &eCompReturn);
   1249 
   1250 	if (eRPCError != RPC_OMX_ErrorNone)
   1251 		eTmpRPCError = eRPCError;
   1252 
   1253 	if (pCompPrv->tBufList[count].pBufHeader)
   1254 	{
   1255 #ifdef ALLOCATE_TILER_BUFFER_IN_PROXY
   1256 #ifdef USE_ION
   1257 		if(pCompPrv->tBufList[count].pYBuffer)
   1258 		{
   1259         		if (pCompPrv->bUseIon == OMX_TRUE)
   1260 			{
   1261 				if(pCompPrv->bMapIonBuffers == OMX_TRUE)
   1262 				{
   1263 	                                munmap(pBufferHdr->pBuffer, pBufferHdr->nAllocLen);
   1264         				close(pCompPrv->tBufList[count].mmap_fd);
   1265 				}
   1266 				ion_free(pCompPrv->ion_fd, pCompPrv->tBufList[count].pYBuffer);
   1267 				pCompPrv->tBufList[count].pYBuffer = NULL;
   1268 			}
   1269 		}
   1270 #else
   1271 		if(pCompPrv->tBufList[count].pYBuffer)
   1272 		{
   1273 			MemMgr_Free(pCompPrv->tBufList[count].pYBuffer);
   1274 			pCompPrv->tBufList[count].pYBuffer = NULL;
   1275 		}
   1276 #endif
   1277 #endif
   1278 		pMetaDataBuffer = ((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1279 			pPlatformPrivate)->pMetaDataBuffer;
   1280 		if (pMetaDataBuffer)
   1281 		{
   1282 #ifdef USE_ION
   1283         		if (pCompPrv->bUseIon == OMX_TRUE)
   1284 			{
   1285 				if(pCompPrv->bMapIonBuffers == OMX_TRUE)
   1286 				{
   1287 	                                munmap(pMetaDataBuffer, ((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1288 							pPlatformPrivate)->nMetaDataSize);
   1289         				close(pCompPrv->tBufList[count].mmap_fd_metadata_buff);
   1290 				}
   1291 				ion_free(pCompPrv->ion_fd, pCompPrv->tBufList[count].pMetaDataBuffer);
   1292 				((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1293 					pPlatformPrivate)->pMetaDataBuffer = NULL;
   1294 			}
   1295 #else
   1296 			MemMgr_Free(pMetaDataBuffer);
   1297 #endif
   1298 		}
   1299 		if (pCompPrv->tBufList[count].pBufHeader->pPlatformPrivate)
   1300 		{
   1301 			TIMM_OSAL_Free(pCompPrv->tBufList[count].pBufHeader->
   1302 			    pPlatformPrivate);
   1303 		}
   1304 		TIMM_OSAL_Free(pCompPrv->tBufList[count].pBufHeader);
   1305 		TIMM_OSAL_Memset(&(pCompPrv->tBufList[count]), 0,
   1306 		    sizeof(PROXY_BUFFER_INFO));
   1307 	}
   1308 	pCompPrv->nAllocatedBuffers--;
   1309 
   1310 	PROXY_checkRpcError();
   1311 
   1312       EXIT:
   1313 	DOMX_EXIT("eError: %d", eError);
   1314 	return eError;
   1315 }
   1316 
   1317 
   1318 /* ===========================================================================*/
   1319 /**
   1320  * @name PROXY_SetParameter()
   1321  * @brief
   1322  * @param void
   1323  * @return OMX_ErrorNone = Successful
   1324  * @sa TBD
   1325  *
   1326  */
   1327 /* ===========================================================================*/
   1328 OMX_ERRORTYPE __PROXY_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
   1329 	OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct,
   1330 	OMX_PTR pLocBufNeedMap)
   1331 {
   1332 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1333 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1334 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1335 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1336 #ifdef ENABLE_GRALLOC_BUFFERS
   1337 	OMX_TI_PARAMUSENATIVEBUFFER *pParamNativeBuffer = NULL;
   1338 #endif
   1339 
   1340 	PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL);
   1341 	PROXY_require((hComp->pComponentPrivate != NULL),
   1342 	    OMX_ErrorBadParameter, NULL);
   1343 
   1344 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1345 
   1346 	DOMX_ENTER
   1347 		("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p",
   1348 		hComponent, pCompPrv, nParamIndex, pParamStruct);
   1349 #ifdef ENABLE_GRALLOC_BUFFERS
   1350 	switch(nParamIndex)
   1351 	{
   1352 		case OMX_TI_IndexUseNativeBuffers:
   1353 		{
   1354 			//Add check version.
   1355 			pParamNativeBuffer = (OMX_TI_PARAMUSENATIVEBUFFER* )pParamStruct;
   1356 			if(pParamNativeBuffer->bEnable == OMX_TRUE)
   1357 			{
   1358 				pCompPrv->proxyPortBuffers[pParamNativeBuffer->nPortIndex].proxyBufferType = GrallocPointers;
   1359 				pCompPrv->proxyPortBuffers[pParamNativeBuffer->nPortIndex].IsBuffer2D = OMX_TRUE;
   1360 			}
   1361 			break;
   1362 		}
   1363 		default:
   1364 			eRPCError =
   1365 				RPC_SetParameter(pCompPrv->hRemoteComp, nParamIndex, pParamStruct,
   1366 					pLocBufNeedMap, &eCompReturn);
   1367 	}
   1368 #else
   1369 	eRPCError =
   1370 		RPC_SetParameter(pCompPrv->hRemoteComp, nParamIndex, pParamStruct,
   1371 			pLocBufNeedMap, &eCompReturn);
   1372 #endif
   1373 
   1374 	PROXY_checkRpcError();
   1375 
   1376  EXIT:
   1377 	DOMX_EXIT("eError: %d", eError);
   1378 	return eError;
   1379 }
   1380 
   1381 /* ===========================================================================*/
   1382 /**
   1383  * @name PROXY_SetParameter()
   1384  * @brief
   1385  * @param void
   1386  * @return OMX_ErrorNone = Successful
   1387  * @sa TBD
   1388  *
   1389  */
   1390 /* ===========================================================================*/
   1391 OMX_ERRORTYPE PROXY_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
   1392     OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct)
   1393 {
   1394 	return __PROXY_SetParameter(hComponent, nParamIndex, pParamStruct, NULL);
   1395 }
   1396 
   1397 
   1398 /* ===========================================================================*/
   1399 /**
   1400  * @name __PROXY_GetParameter()
   1401  * @brief
   1402  * @param void
   1403  * @return OMX_ErrorNone = Successful
   1404  * @sa TBD
   1405  *
   1406  */
   1407 /* ===========================================================================*/
   1408 OMX_ERRORTYPE __PROXY_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
   1409 		OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct,
   1410 		OMX_PTR pLocBufNeedMap)
   1411 {
   1412 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1413 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1414 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1415 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1416 
   1417 	PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL);
   1418 	PROXY_assert((hComp->pComponentPrivate != NULL),
   1419 			OMX_ErrorBadParameter, NULL);
   1420 
   1421 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1422 
   1423 	DOMX_ENTER
   1424 		("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p",
   1425 		 hComponent, pCompPrv, nParamIndex, pParamStruct);
   1426 
   1427 	eRPCError =
   1428 		RPC_GetParameter(pCompPrv->hRemoteComp, nParamIndex, pParamStruct,
   1429 				pLocBufNeedMap, &eCompReturn);
   1430 
   1431 	PROXY_checkRpcError();
   1432 
   1433 EXIT:
   1434 	DOMX_EXIT("eError: %d index: 0x%x", eError, nParamIndex);
   1435 	return eError;
   1436 }
   1437 
   1438 /* ===========================================================================*/
   1439 /**
   1440  * @name PROXY_GetParameter()
   1441  * @brief
   1442  * @param void
   1443  * @return OMX_ErrorNone = Successful
   1444  * @sa TBD
   1445  *
   1446  */
   1447 /* ===========================================================================*/
   1448 OMX_ERRORTYPE PROXY_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
   1449     OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct)
   1450 {
   1451 	return __PROXY_GetParameter(hComponent, nParamIndex, pParamStruct, NULL);
   1452 }
   1453 
   1454 /* ===========================================================================*/
   1455 /**
   1456  * @name __PROXY_GetConfig()
   1457  * @brief
   1458  * @param void
   1459  * @return OMX_ErrorNone = Successful
   1460  * @sa TBD
   1461  *
   1462  */
   1463 /* ===========================================================================*/
   1464 OMX_ERRORTYPE __PROXY_GetConfig(OMX_HANDLETYPE hComponent,
   1465 	OMX_INDEXTYPE nConfigIndex, OMX_PTR pConfigStruct, OMX_PTR pLocBufNeedMap)
   1466 {
   1467 
   1468 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1469 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1470 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1471 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1472 
   1473 	PROXY_require((pConfigStruct != NULL), OMX_ErrorBadParameter, NULL);
   1474 	PROXY_require((hComp->pComponentPrivate != NULL),
   1475 		OMX_ErrorBadParameter, NULL);
   1476 
   1477 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1478 
   1479 	DOMX_ENTER("hComponent = %p, pCompPrv = %p, nConfigIndex = %d, "
   1480 				"pConfigStruct = %p",
   1481 				hComponent, pCompPrv, nConfigIndex,
   1482 				pConfigStruct);
   1483 
   1484 	eRPCError =
   1485 		RPC_GetConfig(pCompPrv->hRemoteComp, nConfigIndex, pConfigStruct,
   1486 			pLocBufNeedMap, &eCompReturn);
   1487 
   1488 	PROXY_checkRpcError();
   1489 
   1490  EXIT:
   1491 	DOMX_EXIT("eError: %d", eError);
   1492 	return eError;
   1493 }
   1494 
   1495 /* ===========================================================================*/
   1496 /**
   1497  * @name PROXY_GetConfig()
   1498  * @brief
   1499  * @param void
   1500  * @return OMX_ErrorNone = Successful
   1501  * @sa TBD
   1502  *
   1503  */
   1504 /* ===========================================================================*/
   1505 OMX_ERRORTYPE PROXY_GetConfig(OMX_HANDLETYPE hComponent,
   1506 	OMX_INDEXTYPE nConfigIndex, OMX_PTR pConfigStruct)
   1507 {
   1508 	return __PROXY_GetConfig(hComponent, nConfigIndex, pConfigStruct, NULL);
   1509 }
   1510 
   1511 /* ===========================================================================*/
   1512 /**
   1513  * @name __PROXY_SetConfig()
   1514  * @brief
   1515  * @param void
   1516  * @return OMX_ErrorNone = Successful
   1517  * @sa TBD
   1518  *
   1519  */
   1520 /* ===========================================================================*/
   1521 OMX_ERRORTYPE __PROXY_SetConfig(OMX_IN OMX_HANDLETYPE hComponent,
   1522 	OMX_IN OMX_INDEXTYPE nConfigIndex, OMX_IN OMX_PTR pConfigStruct,
   1523 	OMX_PTR pLocBufNeedMap)
   1524 {
   1525 
   1526 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1527 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1528 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1529 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1530 
   1531 	PROXY_require((pConfigStruct != NULL), OMX_ErrorBadParameter, NULL);
   1532 
   1533 	PROXY_assert((hComp->pComponentPrivate != NULL),
   1534 		OMX_ErrorBadParameter, NULL);
   1535 
   1536 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1537 
   1538 	DOMX_ENTER("hComponent = %p, pCompPrv = %p, nConfigIndex = %d, "
   1539 				"pConfigStruct = %p",
   1540 				hComponent, pCompPrv, nConfigIndex,
   1541 				pConfigStruct);
   1542 
   1543 	eRPCError =
   1544 		RPC_SetConfig(pCompPrv->hRemoteComp, nConfigIndex, pConfigStruct,
   1545 			pLocBufNeedMap, &eCompReturn);
   1546 
   1547 	PROXY_checkRpcError();
   1548 
   1549       EXIT:
   1550 	DOMX_EXIT("eError: %d", eError);
   1551 	return eError;
   1552 }
   1553 
   1554 /* ===========================================================================*/
   1555 /**
   1556  * @name PROXY_SetConfig()
   1557  * @brief
   1558  * @param void
   1559  * @return OMX_ErrorNone = Successful
   1560  * @sa TBD
   1561  *
   1562  */
   1563 /* ===========================================================================*/
   1564 OMX_ERRORTYPE PROXY_SetConfig(OMX_IN OMX_HANDLETYPE hComponent,
   1565     OMX_IN OMX_INDEXTYPE nConfigIndex, OMX_IN OMX_PTR pConfigStruct)
   1566 {
   1567 	return __PROXY_SetConfig(hComponent, nConfigIndex, pConfigStruct, NULL);
   1568 }
   1569 
   1570 
   1571 /* ===========================================================================*/
   1572 /**
   1573  * @name PROXY_GetState()
   1574  * @brief
   1575  * @param void
   1576  * @return OMX_ErrorNone = Successful
   1577  * @sa TBD
   1578  *
   1579  */
   1580 /* ===========================================================================*/
   1581 static OMX_ERRORTYPE PROXY_GetState(OMX_IN OMX_HANDLETYPE hComponent,
   1582     OMX_OUT OMX_STATETYPE * pState)
   1583 {
   1584 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1585 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1586 	OMX_COMPONENTTYPE *hComp = hComponent;
   1587 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1588 
   1589 	PROXY_require((pState != NULL), OMX_ErrorBadParameter, NULL);
   1590 	PROXY_require((hComp->pComponentPrivate != NULL),
   1591 	    OMX_ErrorBadParameter, NULL);
   1592 
   1593 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1594 
   1595 	DOMX_ENTER("hComponent = %p, pCompPrv = %p", hComponent, pCompPrv);
   1596 
   1597 	eRPCError = RPC_GetState(pCompPrv->hRemoteComp, pState, &eCompReturn);
   1598 
   1599 	DOMX_DEBUG("Returned from RPC_GetState, state: ", *pState);
   1600 
   1601 	PROXY_checkRpcError();
   1602 
   1603       EXIT:
   1604 	DOMX_EXIT("eError: %d", eError);
   1605 	return eError;
   1606 }
   1607 
   1608 
   1609 
   1610 /* ===========================================================================*/
   1611 /**
   1612  * @name PROXY_SendCommand()
   1613  * @brief
   1614  * @param void
   1615  * @return OMX_ErrorNone = Successful
   1616  * @sa TBD
   1617  *
   1618  */
   1619 /* ===========================================================================*/
   1620 OMX_ERRORTYPE PROXY_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,
   1621     OMX_IN OMX_COMMANDTYPE eCmd,
   1622     OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData)
   1623 {
   1624 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1625 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1626 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1627 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1628 	OMX_COMPONENTTYPE *pMarkComp = NULL;
   1629 	PROXY_COMPONENT_PRIVATE *pMarkCompPrv = NULL;
   1630 	OMX_PTR pMarkData = NULL, pMarkToBeFreedIfError = NULL;
   1631 	OMX_BOOL bIsProxy = OMX_FALSE;
   1632 
   1633 	PROXY_require((hComp->pComponentPrivate != NULL),
   1634 	    OMX_ErrorBadParameter, NULL);
   1635 
   1636 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1637 
   1638 	DOMX_ENTER
   1639 	    ("hComponent = %p, pCompPrv = %p, eCmd = %d, nParam = %d, pCmdData = %p",
   1640 	    hComponent, pCompPrv, eCmd, nParam, pCmdData);
   1641 
   1642 	if (eCmd == OMX_CommandMarkBuffer)
   1643 	{
   1644 		PROXY_require(pCmdData != NULL, OMX_ErrorBadParameter, NULL);
   1645 		pMarkComp = (OMX_COMPONENTTYPE *)
   1646 		    (((OMX_MARKTYPE *) pCmdData)->hMarkTargetComponent);
   1647 		PROXY_require(pMarkComp != NULL, OMX_ErrorBadParameter, NULL);
   1648 
   1649 		/* To check if mark comp is a proxy or a real component */
   1650 		eError = _RPC_IsProxyComponent(pMarkComp, &bIsProxy);
   1651 		PROXY_assert(eError == OMX_ErrorNone, eError, "");
   1652 
   1653 		/*Replacing original mark data with proxy specific structure */
   1654 		pMarkData = ((OMX_MARKTYPE *) pCmdData)->pMarkData;
   1655 		((OMX_MARKTYPE *) pCmdData)->pMarkData =
   1656 		    TIMM_OSAL_Malloc(sizeof(PROXY_MARK_DATA), TIMM_OSAL_TRUE,
   1657 		    0, TIMMOSAL_MEM_SEGMENT_INT);
   1658 		PROXY_assert(((OMX_MARKTYPE *) pCmdData)->pMarkData != NULL,
   1659 		    OMX_ErrorInsufficientResources, "Malloc failed");
   1660 		pMarkToBeFreedIfError =
   1661 		    ((OMX_MARKTYPE *) pCmdData)->pMarkData;
   1662 		((PROXY_MARK_DATA *) (((OMX_MARKTYPE *)
   1663 			    pCmdData)->pMarkData))->hComponentActual =
   1664 		    pMarkComp;
   1665 		((PROXY_MARK_DATA *) (((OMX_MARKTYPE *)
   1666 			    pCmdData)->pMarkData))->pMarkDataActual =
   1667 		    pMarkData;
   1668 
   1669 		/* If it is proxy component then replace hMarkTargetComponent
   1670 		   with remote handle */
   1671 		if (bIsProxy)
   1672 		{
   1673 			pMarkCompPrv = pMarkComp->pComponentPrivate;
   1674 			PROXY_assert(pMarkCompPrv != NULL,
   1675 			    OMX_ErrorBadParameter, NULL);
   1676 
   1677 			/* Replacing with remote component handle */
   1678 			((OMX_MARKTYPE *) pCmdData)->hMarkTargetComponent =
   1679 			    ((RPC_OMX_CONTEXT *) pMarkCompPrv->hRemoteComp)->
   1680 			    hActualRemoteCompHandle;
   1681 		}
   1682 	}
   1683 
   1684 	eRPCError =
   1685 	    RPC_SendCommand(pCompPrv->hRemoteComp, eCmd, nParam, pCmdData,
   1686 	    &eCompReturn);
   1687 
   1688 	if (eCmd == OMX_CommandMarkBuffer && bIsProxy)
   1689 	{
   1690 		/*Resetting to original values */
   1691 		((OMX_MARKTYPE *) pCmdData)->hMarkTargetComponent = pMarkComp;
   1692 		((OMX_MARKTYPE *) pCmdData)->pMarkData = pMarkData;
   1693 	}
   1694 
   1695 	PROXY_checkRpcError();
   1696 
   1697       EXIT:
   1698 	/*If SendCommand is about to return an error then this means that the
   1699 	   command has not been accepted by the component. Thus the allocated mark data
   1700 	   will be lost so free it here */
   1701 	if ((eError != OMX_ErrorNone) && pMarkToBeFreedIfError)
   1702 	{
   1703 		TIMM_OSAL_Free(pMarkToBeFreedIfError);
   1704 	}
   1705 	DOMX_EXIT("eError: %d", eError);
   1706 	return eError;
   1707 }
   1708 
   1709 
   1710 
   1711 /* ===========================================================================*/
   1712 /**
   1713  * @name PROXY_GetComponentVersion()
   1714  * @brief
   1715  * @param void
   1716  * @return OMX_ErrorNone = Successful
   1717  * @sa TBD
   1718  *
   1719  */
   1720 /* ===========================================================================*/
   1721 static OMX_ERRORTYPE PROXY_GetComponentVersion(OMX_IN OMX_HANDLETYPE
   1722     hComponent, OMX_OUT OMX_STRING pComponentName,
   1723     OMX_OUT OMX_VERSIONTYPE * pComponentVersion,
   1724     OMX_OUT OMX_VERSIONTYPE * pSpecVersion,
   1725     OMX_OUT OMX_UUIDTYPE * pComponentUUID)
   1726 {
   1727 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1728 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1729 	OMX_COMPONENTTYPE *hComp = hComponent;
   1730 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1731 
   1732 	DOMX_ENTER("hComponent = %p, pCompPrv = %p", hComponent, pCompPrv);
   1733 
   1734 	PROXY_require((hComp->pComponentPrivate != NULL),
   1735 	    OMX_ErrorBadParameter, NULL);
   1736 	PROXY_require(pComponentName != NULL, OMX_ErrorBadParameter, NULL);
   1737 	PROXY_require(pComponentVersion != NULL, OMX_ErrorBadParameter, NULL);
   1738 	PROXY_require(pSpecVersion != NULL, OMX_ErrorBadParameter, NULL);
   1739 	PROXY_require(pComponentUUID != NULL, OMX_ErrorBadParameter, NULL);
   1740 
   1741 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1742 
   1743 	eRPCError = RPC_GetComponentVersion(pCompPrv->hRemoteComp,
   1744 	    pComponentName,
   1745 	    pComponentVersion, pSpecVersion, pComponentUUID, &eCompReturn);
   1746 
   1747 	PROXY_checkRpcError();
   1748 
   1749       EXIT:
   1750 	DOMX_EXIT("eError: %d", eError);
   1751 	return eError;
   1752 }
   1753 
   1754 
   1755 
   1756 /* ===========================================================================*/
   1757 /**
   1758  * @name PROXY_GetExtensionIndex()
   1759  * @brief
   1760  * @param void
   1761  * @return OMX_ErrorNone = Successful
   1762  * @sa TBD
   1763  *
   1764  */
   1765 /* ===========================================================================*/
   1766 OMX_ERRORTYPE PROXY_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
   1767     OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType)
   1768 {
   1769 
   1770 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1771 	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
   1772 	OMX_COMPONENTTYPE *hComp = hComponent;
   1773 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   1774 
   1775 	PROXY_require((hComp->pComponentPrivate != NULL),
   1776 	    OMX_ErrorBadParameter, NULL);
   1777 	PROXY_require(cParameterName != NULL, OMX_ErrorBadParameter, NULL);
   1778 	PROXY_require(pIndexType != NULL, OMX_ErrorBadParameter, NULL);
   1779 
   1780 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1781 
   1782 	DOMX_ENTER("hComponent = %p, pCompPrv = %p, cParameterName = %s",
   1783 	    hComponent, pCompPrv, cParameterName);
   1784 
   1785 
   1786 #ifdef ENABLE_GRALLOC_BUFFERS
   1787 	// Check for NULL Parameters
   1788 	PROXY_require((cParameterName != NULL && pIndexType != NULL),
   1789 	    OMX_ErrorBadParameter, NULL);
   1790 
   1791 	// Ensure that String length is not greater than Max allowed length
   1792 	PROXY_require(strlen(cParameterName) <= 127, OMX_ErrorBadParameter, NULL);
   1793 
   1794 	if(strcmp(cParameterName, "OMX.google.android.index.enableAndroidNativeBuffers") == 0)
   1795 	{
   1796 		// If Index type is 2D Buffer Allocated Dimension
   1797 		*pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexUseNativeBuffers;
   1798 		goto EXIT;
   1799 	}
   1800 	else if (strcmp(cParameterName, "OMX.google.android.index.useAndroidNativeBuffer2") == 0)
   1801 	{
   1802 		//This is call just a dummy for android to support backward compatibility
   1803 		*pIndexType = (OMX_INDEXTYPE) NULL;
   1804 		goto EXIT;
   1805 	}
   1806 	else
   1807 	{
   1808 		eRPCError = RPC_GetExtensionIndex(pCompPrv->hRemoteComp,
   1809                    cParameterName, pIndexType, &eCompReturn);
   1810 
   1811 		PROXY_checkRpcError();
   1812 	}
   1813 #else
   1814 	eRPCError = RPC_GetExtensionIndex(pCompPrv->hRemoteComp,
   1815 	    cParameterName, pIndexType, &eCompReturn);
   1816 
   1817 	PROXY_checkRpcError();
   1818 #endif
   1819 
   1820       EXIT:
   1821 	DOMX_EXIT("eError: %d", eError);
   1822 	return eError;
   1823 }
   1824 
   1825 
   1826 
   1827 
   1828 /* ===========================================================================*/
   1829 /**
   1830  * @name PROXY_ComponentRoleEnum()
   1831  * @brief
   1832  * @param void
   1833  * @return OMX_ErrorNone = Successful
   1834  * @sa TBD
   1835  *
   1836  */
   1837 /* ===========================================================================*/
   1838 static OMX_ERRORTYPE PROXY_ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
   1839     OMX_OUT OMX_U8 * cRole, OMX_IN OMX_U32 nIndex)
   1840 {
   1841 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   1842 
   1843 	DOMX_ENTER("hComponent = %p", hComponent);
   1844 	DOMX_DEBUG(" EMPTY IMPLEMENTATION ");
   1845 
   1846 	DOMX_EXIT("eError: %d", eError);
   1847 	return eError;
   1848 }
   1849 
   1850 
   1851 /* ===========================================================================*/
   1852 /**
   1853  * @name PROXY_ComponentTunnelRequest()
   1854  * @brief
   1855  * @param void
   1856  * @return OMX_ErrorNone = Successful
   1857  * @sa TBD
   1858  *
   1859  */
   1860 /* ===========================================================================*/
   1861 static OMX_ERRORTYPE PROXY_ComponentTunnelRequest(OMX_IN OMX_HANDLETYPE
   1862     hComponent, OMX_IN OMX_U32 nPort, OMX_IN OMX_HANDLETYPE hTunneledComp,
   1863     OMX_IN OMX_U32 nTunneledPort,
   1864     OMX_INOUT OMX_TUNNELSETUPTYPE * pTunnelSetup)
   1865 {
   1866 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   1867 
   1868 	DOMX_ENTER("hComponent = %p", hComponent);
   1869 	DOMX_DEBUG(" EMPTY IMPLEMENTATION ");
   1870 
   1871 	DOMX_EXIT("eError: %d", eError);
   1872 	return eError;
   1873 }
   1874 
   1875 
   1876 /* ===========================================================================*/
   1877 /**
   1878  * @name PROXY_SetCallbacks()
   1879  * @brief
   1880  * @param void
   1881  * @return OMX_ErrorNone = Successful
   1882  * @sa TBD
   1883  *
   1884  */
   1885 /* ===========================================================================*/
   1886 static OMX_ERRORTYPE PROXY_SetCallbacks(OMX_HANDLETYPE hComponent,
   1887     OMX_CALLBACKTYPE * pCallBacks, OMX_PTR pAppData)
   1888 {
   1889 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   1890 	PROXY_COMPONENT_PRIVATE *pCompPrv;
   1891 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1892 
   1893 	PROXY_require((pCallBacks != NULL), OMX_ErrorBadParameter, NULL);
   1894 
   1895 	PROXY_assert((hComp->pComponentPrivate != NULL),
   1896 	    OMX_ErrorBadParameter, NULL);
   1897 
   1898 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1899 
   1900 	DOMX_ENTER("hComponent = %p, pCompPrv = %p", hComponent, pCompPrv);
   1901 
   1902 	/*Store App callback and data to proxy- managed by proxy */
   1903 	pCompPrv->tCBFunc = *pCallBacks;
   1904 	pCompPrv->pILAppData = pAppData;
   1905 
   1906       EXIT:
   1907 	DOMX_EXIT("eError: %d", eError);
   1908 	return eError;
   1909 }
   1910 
   1911 
   1912 /* ===========================================================================*/
   1913 /**
   1914  * @name PROXY_UseEGLImage()
   1915  * @brief : This returns error not implemented by default as no component
   1916  *          implements this. In case there is a requiremet, support for this
   1917  *          can be added later.
   1918  *
   1919  */
   1920 /* ===========================================================================*/
   1921 static OMX_ERRORTYPE PROXY_UseEGLImage(OMX_HANDLETYPE hComponent,
   1922     OMX_BUFFERHEADERTYPE ** ppBufferHdr,
   1923     OMX_U32 nPortIndex, OMX_PTR pAppPrivate, void *pBuffer)
   1924 {
   1925 	return OMX_ErrorNotImplemented;
   1926 }
   1927 
   1928 
   1929 /* ===========================================================================*/
   1930 /**
   1931  * @name PROXY_ComponentDeInit()
   1932  * @brief
   1933  * @param void
   1934  * @return OMX_ErrorNone = Successful
   1935  * @sa TBD
   1936  *
   1937  */
   1938 /* ===========================================================================*/
   1939 OMX_ERRORTYPE PROXY_ComponentDeInit(OMX_HANDLETYPE hComponent)
   1940 {
   1941 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   1942 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone, eTmpRPCError =
   1943 	    RPC_OMX_ErrorNone;
   1944 	PROXY_COMPONENT_PRIVATE *pCompPrv;
   1945 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   1946 	OMX_U32 count = 0, nStride = 0;
   1947 	OMX_PTR pMetaDataBuffer = NULL;
   1948 
   1949 	DOMX_ENTER("hComponent = %p", hComponent);
   1950 
   1951 	PROXY_assert((hComp->pComponentPrivate != NULL),
   1952 	    OMX_ErrorBadParameter, NULL);
   1953 
   1954 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   1955 
   1956 	ion_close(pCompPrv->ion_fd);
   1957 
   1958 	for (count = 0; count < pCompPrv->nTotalBuffers; count++)
   1959 	{
   1960 		if (pCompPrv->tBufList[count].pBufHeader)
   1961 		{
   1962 #ifdef ALLOCATE_TILER_BUFFER_IN_PROXY
   1963 			if(pCompPrv->tBufList[count].pYBuffer)
   1964 			{
   1965 #ifdef USE_ION
   1966 				if(pCompPrv->tBufList[count].pYBuffer)
   1967 				{
   1968 					if (pCompPrv->bUseIon == OMX_TRUE)
   1969 					{
   1970 						if(pCompPrv->bMapIonBuffers == OMX_TRUE)
   1971 						{
   1972 					                munmap(pCompPrv->tBufList[count].pBufHeader->pBuffer, pCompPrv->tBufList[count].pBufHeader->nAllocLen);
   1973 							close(pCompPrv->tBufList[count].mmap_fd);
   1974 						}
   1975 						ion_free(pCompPrv->ion_fd, pCompPrv->tBufList[count].pYBuffer);
   1976 						pCompPrv->tBufList[count].pYBuffer = NULL;
   1977 					}
   1978 				}
   1979 #else
   1980 				MemMgr_Free(pCompPrv->tBufList[count].pYBuffer);
   1981 #endif
   1982 			}
   1983 #endif
   1984 			pMetaDataBuffer = ((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1985 				pPlatformPrivate)->pMetaDataBuffer;
   1986 			if (pMetaDataBuffer)
   1987 			{
   1988 #ifdef USE_ION
   1989 				if (pCompPrv->bUseIon == OMX_TRUE)
   1990 				{
   1991 					if(pCompPrv->bMapIonBuffers == OMX_TRUE)
   1992 					{
   1993 			                        munmap(pMetaDataBuffer, ((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1994 								pPlatformPrivate)->nMetaDataSize);
   1995 						close(pCompPrv->tBufList[count].mmap_fd_metadata_buff);
   1996 					}
   1997 					ion_free(pCompPrv->ion_fd, pMetaDataBuffer);
   1998 					((OMX_TI_PLATFORMPRIVATE *)(pCompPrv->tBufList[count].pBufHeader)->
   1999 						pPlatformPrivate)->pMetaDataBuffer = NULL;
   2000 				}
   2001 #else
   2002 				MemMgr_Free(pMetaDataBuffer);
   2003 #endif
   2004 			}
   2005 			if (pCompPrv->tBufList[count].pBufHeader->pPlatformPrivate)
   2006 			{
   2007 				TIMM_OSAL_Free(pCompPrv->tBufList[count].pBufHeader->
   2008 				    pPlatformPrivate);
   2009 			}
   2010 			TIMM_OSAL_Free(pCompPrv->tBufList[count].pBufHeader);
   2011 			TIMM_OSAL_Memset(&(pCompPrv->tBufList[count]), 0,
   2012 			    sizeof(PROXY_BUFFER_INFO));
   2013 		}
   2014 	}
   2015 
   2016 	eRPCError = RPC_FreeHandle(pCompPrv->hRemoteComp, &eCompReturn);
   2017 	if (eRPCError != RPC_OMX_ErrorNone)
   2018 		eTmpRPCError = eRPCError;
   2019 
   2020 	eRPCError = RPC_InstanceDeInit(pCompPrv->hRemoteComp);
   2021 	if (eRPCError != RPC_OMX_ErrorNone)
   2022 		eTmpRPCError = eRPCError;
   2023 
   2024 	if (pCompPrv->cCompName)
   2025 	{
   2026 		TIMM_OSAL_Free(pCompPrv->cCompName);
   2027 	}
   2028 
   2029 	if (pCompPrv)
   2030 	{
   2031 		TIMM_OSAL_Free(pCompPrv);
   2032 	}
   2033 
   2034 	eRPCError = eTmpRPCError;
   2035 	PROXY_checkRpcError();
   2036 
   2037       EXIT:
   2038 	DOMX_EXIT("eError: %d", eError);
   2039 	return eError;
   2040 }
   2041 
   2042 
   2043 /* ===========================================================================*/
   2044 /**
   2045  * @name OMX_ProxyCommonInit()
   2046  * @brief
   2047  * @param void
   2048  * @return OMX_ErrorNone = Successful
   2049  * @sa TBD
   2050  *
   2051  */
   2052 /* ===========================================================================*/
   2053 OMX_ERRORTYPE OMX_ProxyCommonInit(OMX_HANDLETYPE hComponent)
   2054 {
   2055 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   2056 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   2057 	PROXY_COMPONENT_PRIVATE *pCompPrv;
   2058 	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
   2059 	OMX_HANDLETYPE hRemoteComp = NULL;
   2060         OMX_U32 i = 0;
   2061 
   2062 	DOMX_ENTER("hComponent = %p", hComponent);
   2063 
   2064 	PROXY_require((hComp->pComponentPrivate != NULL),
   2065 	    OMX_ErrorBadParameter, NULL);
   2066 
   2067 	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
   2068 
   2069 	pCompPrv->nTotalBuffers = 0;
   2070 	pCompPrv->nAllocatedBuffers = 0;
   2071 	pCompPrv->proxyEmptyBufferDone = PROXY_EmptyBufferDone;
   2072 	pCompPrv->proxyFillBufferDone = PROXY_FillBufferDone;
   2073 	pCompPrv->proxyEventHandler = PROXY_EventHandler;
   2074 
   2075         for (i=0; i<PROXY_MAXNUMOFPORTS ; i++)
   2076         {
   2077               pCompPrv->proxyPortBuffers[i].proxyBufferType = VirtualPointers;
   2078         }
   2079 
   2080 	eRPCError = RPC_InstanceInit(pCompPrv->cCompName, &hRemoteComp);
   2081 	PROXY_assert(eRPCError == RPC_OMX_ErrorNone,
   2082 	    OMX_ErrorUndefined, "Error initializing RPC");
   2083 	PROXY_assert(hRemoteComp != NULL,
   2084 	    OMX_ErrorUndefined, "Error initializing RPC");
   2085 
   2086 	//Send the proxy component handle for pAppData
   2087 	eRPCError =
   2088 	    RPC_GetHandle(hRemoteComp, pCompPrv->cCompName,
   2089 	    (OMX_PTR) hComponent, NULL, &eCompReturn);
   2090 
   2091 	PROXY_checkRpcError();
   2092 
   2093 	hComp->SetCallbacks = PROXY_SetCallbacks;
   2094 	hComp->ComponentDeInit = PROXY_ComponentDeInit;
   2095 	hComp->UseBuffer = PROXY_UseBuffer;
   2096 	hComp->GetParameter = PROXY_GetParameter;
   2097 	hComp->SetParameter = PROXY_SetParameter;
   2098 	hComp->EmptyThisBuffer = PROXY_EmptyThisBuffer;
   2099 	hComp->FillThisBuffer = PROXY_FillThisBuffer;
   2100 	hComp->GetComponentVersion = PROXY_GetComponentVersion;
   2101 	hComp->SendCommand = PROXY_SendCommand;
   2102 	hComp->GetConfig = PROXY_GetConfig;
   2103 	hComp->SetConfig = PROXY_SetConfig;
   2104 	hComp->GetState = PROXY_GetState;
   2105 	hComp->GetExtensionIndex = PROXY_GetExtensionIndex;
   2106 	hComp->FreeBuffer = PROXY_FreeBuffer;
   2107 	hComp->ComponentRoleEnum = PROXY_ComponentRoleEnum;
   2108 	hComp->AllocateBuffer = PROXY_AllocateBuffer;
   2109 	hComp->ComponentTunnelRequest = PROXY_ComponentTunnelRequest;
   2110 	hComp->UseEGLImage = PROXY_UseEGLImage;
   2111 
   2112 	pCompPrv->hRemoteComp = hRemoteComp;
   2113 
   2114 #ifdef USE_ION
   2115 	pCompPrv->bUseIon = OMX_TRUE;
   2116 	pCompPrv->bMapIonBuffers = OMX_TRUE;
   2117 
   2118 	pCompPrv->ion_fd = ion_open();
   2119 	if(pCompPrv->ion_fd == 0)
   2120 	{
   2121 		DOMX_ERROR("ion_open failed!!!");
   2122 		return OMX_ErrorInsufficientResources;
   2123 	}
   2124 #endif
   2125 
   2126       EXIT:
   2127 	if (eError != OMX_ErrorNone)
   2128 		RPC_InstanceDeInit(hRemoteComp);
   2129 	DOMX_EXIT("eError: %d", eError);
   2130 
   2131 	return eError;
   2132 }
   2133 
   2134 
   2135 
   2136 /* ===========================================================================*/
   2137 /**
   2138  * @name RPC_UTIL_GetStride()
   2139  * @brief Gets stride on this port. Used to determine whether buffer is 1D or 2D
   2140  * @param hRemoteComp [IN]  : Remote component handle.
   2141  * @param nPortIndex [IN]   : Port index.
   2142  * @param nStride [OUT]     : Stride returned by the component.
   2143  * @return OMX_ErrorNone = Successful
   2144  */
   2145 /* ===========================================================================*/
   2146 OMX_ERRORTYPE RPC_UTIL_GetStride(OMX_COMPONENTTYPE * hRemoteComp,
   2147     OMX_U32 nPortIndex, OMX_U32 * nStride)
   2148 {
   2149 	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
   2150 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   2151 	OMX_PARAM_PORTDEFINITIONTYPE sPortDef = { 0 };
   2152 
   2153 	/*Initializing Structure */
   2154 	sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
   2155 	sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
   2156 	sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR;
   2157 	sPortDef.nVersion.s.nRevision = 0x0;
   2158 	sPortDef.nVersion.s.nStep = 0x0;
   2159 	sPortDef.nPortIndex = nPortIndex;
   2160 
   2161 	eRPCError =
   2162 	    RPC_GetParameter(hRemoteComp, OMX_IndexParamPortDefinition,
   2163 	    (OMX_PTR) (&sPortDef), NULL, &eCompReturn);
   2164 	PROXY_checkRpcError();
   2165 
   2166 	if (sPortDef.eDomain == OMX_PortDomainVideo)
   2167 	{
   2168 		*nStride = sPortDef.format.video.nStride;
   2169 	} else if (sPortDef.eDomain == OMX_PortDomainImage)
   2170 	{
   2171 		*nStride = sPortDef.format.image.nStride;
   2172 	} else if (sPortDef.eDomain == OMX_PortDomainMax && nPortIndex == 0)
   2173 	{
   2174 		/*Temp - just for testing sample */
   2175 		*nStride = LINUX_PAGE_SIZE;
   2176 	} else
   2177 	{
   2178 		*nStride = 0;
   2179 	}
   2180 
   2181       EXIT:
   2182 	return eError;
   2183 }
   2184 
   2185 
   2186 
   2187 /* ===========================================================================*/
   2188 /**
   2189  * @name RPC_UTIL_GetNumLines()
   2190  * @brief
   2191  * @param void
   2192  * @return OMX_ErrorNone = Successful
   2193  * @sa TBD
   2194  *
   2195  */
   2196 /* ===========================================================================*/
   2197 OMX_ERRORTYPE RPC_UTIL_GetNumLines(OMX_COMPONENTTYPE * hRemoteComp,
   2198     OMX_U32 nPortIndex, OMX_U32 * nNumOfLines)
   2199 {
   2200 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2201 	OMX_ERRORTYPE eCompReturn;
   2202 	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
   2203 	OMX_BOOL bUseEnhancedPortReconfig = OMX_FALSE;
   2204 
   2205 	OMX_PARAM_PORTDEFINITIONTYPE portDef;
   2206 	OMX_CONFIG_RECTTYPE sRect;
   2207 
   2208 	DOMX_ENTER("");
   2209 
   2210 	/*initializing Structure */
   2211 	portDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
   2212 	portDef.nVersion.s.nVersionMajor = 0x1;
   2213 	portDef.nVersion.s.nVersionMinor = 0x1;
   2214 	portDef.nVersion.s.nRevision = 0x0;
   2215 	portDef.nVersion.s.nStep = 0x0;
   2216 
   2217 	portDef.nPortIndex = nPortIndex;
   2218 
   2219 	sRect.nSize = sizeof(OMX_CONFIG_RECTTYPE);
   2220 	sRect.nVersion.s.nVersionMajor = 0x1;
   2221 	sRect.nVersion.s.nVersionMinor = 0x1;
   2222 	sRect.nVersion.s.nRevision = 0x0;
   2223 	sRect.nVersion.s.nStep = 0x0;
   2224 
   2225 	sRect.nPortIndex = nPortIndex;
   2226 	sRect.nLeft = 0;
   2227 	sRect.nTop = 0;
   2228 	sRect.nHeight = 0;
   2229 	sRect.nWidth = 0;
   2230 
   2231 #ifdef USE_ENHANCED_PORTRECONFIG
   2232 	bUseEnhancedPortReconfig = OMX_TRUE;
   2233 #endif
   2234 	eRPCError = RPC_GetParameter(hRemoteComp,
   2235 	    OMX_TI_IndexParam2DBufferAllocDimension,
   2236 	    (OMX_PTR) & sRect, NULL, &eCompReturn);
   2237 	if (eRPCError == RPC_OMX_ErrorNone)
   2238 	{
   2239 		DOMX_DEBUG(" PROXY_UTIL Get Parameter Successful");
   2240 		eError = eCompReturn;
   2241 	} else
   2242 	{
   2243 		DOMX_ERROR("RPC_GetParameter returned error 0x%x", eRPCError);
   2244 		eError = OMX_ErrorUndefined;
   2245 		goto EXIT;
   2246 	}
   2247 
   2248 	if (eCompReturn == OMX_ErrorNone && bUseEnhancedPortReconfig == OMX_FALSE)
   2249 	{
   2250 		*nNumOfLines = sRect.nHeight;
   2251 	} else if (eCompReturn == OMX_ErrorUnsupportedIndex || bUseEnhancedPortReconfig == OMX_TRUE)
   2252 	{
   2253 		eRPCError =
   2254 		    RPC_GetParameter(hRemoteComp,
   2255 		    OMX_IndexParamPortDefinition, (OMX_PTR) & portDef,
   2256 		    NULL, &eCompReturn);
   2257 
   2258 		if (eRPCError == RPC_OMX_ErrorNone)
   2259 		{
   2260 			DOMX_DEBUG(" PROXY_UTIL Get Parameter Successful");
   2261 			eError = eCompReturn;
   2262 		} else
   2263 		{
   2264 			DOMX_ERROR("RPC_GetParameter returned error 0x%x",
   2265 			    eRPCError);
   2266 			eError = OMX_ErrorUndefined;
   2267 			goto EXIT;
   2268 		}
   2269 
   2270 		if (eCompReturn == OMX_ErrorNone)
   2271 		{
   2272 
   2273 			//start with 1 meaning 1D buffer
   2274 			*nNumOfLines = 1;
   2275 
   2276 			if (portDef.eDomain == OMX_PortDomainVideo)
   2277 			{
   2278 				*nNumOfLines =
   2279 				    portDef.format.video.nFrameHeight;
   2280 				//DOMX_DEBUG("Port definition Type is video...");
   2281 				//DOMX_DEBUG("&&Colorformat is:%p", portDef.format.video.eColorFormat);
   2282 				//DOMX_DEBUG("nFrameHeight is:%d", portDef.format.video.nFrameHeight);
   2283 				//*nNumOfLines = portDef.format.video.nFrameHeight;
   2284 
   2285 				//if((portDef.format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) ||
   2286 				//  (portDef.format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar))
   2287 				//{
   2288 				//DOMX_DEBUG("Setting FrameHeight as Number of lines...");
   2289 				//*nNumOfLines = portDef.format.video.nFrameHeight;
   2290 				//}
   2291 			} else if (portDef.eDomain == OMX_PortDomainImage)
   2292 			{
   2293 				DOMX_DEBUG
   2294 				    ("Image DOMAIN TILER SUPPORT for NV12 format only");
   2295 				*nNumOfLines =
   2296 				    portDef.format.image.nFrameHeight;
   2297 			} else if (portDef.eDomain == OMX_PortDomainAudio)
   2298 			{
   2299 				DOMX_DEBUG("Audio DOMAIN TILER SUPPORT");
   2300 			} else if (portDef.eDomain == OMX_PortDomainOther)
   2301 			{
   2302 				DOMX_DEBUG("Other DOMAIN TILER SUPPORT");
   2303 			} else
   2304 			{	//this is the sample component test
   2305 				//Temporary - just to get check functionality
   2306 				DOMX_DEBUG("Sample component TILER SUPPORT");
   2307 				*nNumOfLines = 4;
   2308 			}
   2309 		} else
   2310 		{
   2311 			DOMX_ERROR(" ERROR IN RECOVERING UV POINTER");
   2312 		}
   2313 	} else
   2314 	{
   2315 		DOMX_ERROR(" ERROR IN RECOVERING UV POINTER");
   2316 	}
   2317 
   2318 	DOMX_DEBUG("Port Number: %d :: NumOfLines %d", nPortIndex,
   2319 	    *nNumOfLines);
   2320 
   2321       EXIT:
   2322 	DOMX_EXIT("eError: %d", eError);
   2323 	return eError;
   2324 }
   2325 
   2326 
   2327 
   2328 #if 0
   2329 
   2330 OMX_ERRORTYPE RPC_PrepareBuffer_Chiron(PROXY_COMPONENT_PRIVATE * pCompPrv,
   2331     OMX_COMPONENTTYPE * hRemoteComp, OMX_U32 nPortIndex, OMX_U32 nSizeBytes,
   2332     OMX_BUFFERHEADERTYPE * pDucBuf, OMX_BUFFERHEADERTYPE * pChironBuf)
   2333 {
   2334 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2335 	OMX_U32 nNumOfLines = 1;
   2336 	OMX_U8 *pBuffer;
   2337 
   2338 	DSPtr dsptr[2];
   2339 	bytes_t lengths[2];
   2340 	OMX_U32 i = 0;
   2341 	OMX_U32 numBlocks = 0;
   2342 
   2343 	pBuffer = pDucBuf->pBuffer;
   2344 
   2345 	DOMX_ENTER("");
   2346 
   2347 	if (((OMX_TI_PLATFORMPRIVATE *) pDucBuf->pPlatformPrivate)->
   2348 	    pAuxBuf1 == NULL)
   2349 	{
   2350 		DOMX_DEBUG("One component buffer");
   2351 
   2352 		if (!(pCompPrv->nNumOfLines[nPortIndex]))
   2353 		{
   2354 			pCompPrv->nNumOfLines[nPortIndex] = 1;
   2355 		}
   2356 
   2357 		dsptr[0] = (OMX_U32) pBuffer;
   2358 		numBlocks = 1;
   2359 		lengths[0] =
   2360 		    LINUX_PAGE_SIZE * ((nSizeBytes + (LINUX_PAGE_SIZE -
   2361 			    1)) / LINUX_PAGE_SIZE);
   2362 	} else
   2363 	{
   2364 		DOMX_DEBUG("Two component buffers");
   2365 		dsptr[0] = (OMX_U32) pBuffer;
   2366 		dsptr[1] =
   2367 		    (OMX_U32) (((OMX_TI_PLATFORMPRIVATE *)
   2368 			pDucBuf->pPlatformPrivate)->pAuxBuf1);
   2369 
   2370 		if (!(pCompPrv->nNumOfLines[nPortIndex]))
   2371 		{
   2372 			eError =
   2373 			    RPC_UTIL_GetNumLines(hRemoteComp, nPortIndex,
   2374 			    &nNumOfLines);
   2375 			PROXY_assert((eError == OMX_ErrorNone),
   2376 			    OMX_ErrorUndefined,
   2377 			    "ERROR WHILE GETTING FRAME HEIGHT");
   2378 
   2379 			pCompPrv->nNumOfLines[nPortIndex] = nNumOfLines;
   2380 		} else
   2381 		{
   2382 			nNumOfLines = pCompPrv->nNumOfLines[nPortIndex];
   2383 		}
   2384 
   2385 		lengths[0] = nNumOfLines * LINUX_PAGE_SIZE;
   2386 		lengths[1] = nNumOfLines / 2 * LINUX_PAGE_SIZE;
   2387 		numBlocks = 2;
   2388 	}
   2389 
   2390 	//Map back to chiron
   2391 	DOMX_DEBUG("NumBlocks = %d", numBlocks);
   2392 	for (i = 0; i < numBlocks; i++)
   2393 	{
   2394 		DOMX_DEBUG("dsptr[%d] = %p", i, dsptr[i]);
   2395 		DOMX_DEBUG("length[%d] = %d", i, lengths[i]);
   2396 	}
   2397 
   2398 	pDucBuf->pBuffer =
   2399 	    tiler_assisted_phase1_D2CReMap(numBlocks, dsptr, lengths);
   2400 	PROXY_assert((pDucBuf->pBuffer != NULL), OMX_ErrorUndefined,
   2401 	    "Mapping to Chiron failed");
   2402 
   2403       EXIT:
   2404 	DOMX_EXIT("eError: %d", eError);
   2405 	return eError;
   2406 }
   2407 
   2408 
   2409 //Takes chiron buffer buffer header and updates with ducati buffer ptr and UV ptr
   2410 OMX_ERRORTYPE RPC_PrepareBuffer_Remote(PROXY_COMPONENT_PRIVATE * pCompPrv,
   2411     OMX_COMPONENTTYPE * hRemoteComp, OMX_U32 nPortIndex,
   2412     OMX_U32 nSizeBytes, OMX_BUFFERHEADERTYPE * pChironBuf,
   2413     OMX_BUFFERHEADERTYPE * pDucBuf, OMX_PTR pBufToBeMapped)
   2414 {
   2415 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2416 	OMX_U32 nNumOfLines = 1;
   2417 	OMX_U8 *pBuffer;
   2418 
   2419 	DOMX_ENTER("");
   2420 
   2421 	pBuffer = pChironBuf->pBuffer;
   2422 
   2423 	if (!MemMgr_Is2DBlock(pBuffer))
   2424 	{
   2425 
   2426 		if (!(pCompPrv->nNumOfLines[nPortIndex]))
   2427 		{
   2428 			pCompPrv->nNumOfLines[nPortIndex] = 1;
   2429 		}
   2430 
   2431 		pChironBuf->pBuffer = NULL;
   2432 		eError =
   2433 		    RPC_MapBuffer_Ducati(pBuffer, nSizeBytes, nNumOfLines,
   2434 		    &(pChironBuf->pBuffer), pBufToBeMapped);
   2435 		PROXY_assert(eError == OMX_ErrorNone, eError, "Map failed");
   2436 	} else
   2437 	{
   2438 		if (!(pCompPrv->nNumOfLines[nPortIndex]))
   2439 		{
   2440 			eError =
   2441 			    RPC_UTIL_GetNumLines(hRemoteComp, nPortIndex,
   2442 			    &nNumOfLines);
   2443 			PROXY_assert((eError == OMX_ErrorNone), eError,
   2444 			    "ERROR WHILE GETTING FRAME HEIGHT");
   2445 
   2446 			pCompPrv->nNumOfLines[nPortIndex] = nNumOfLines;
   2447 		} else
   2448 		{
   2449 			nNumOfLines = pCompPrv->nNumOfLines[nPortIndex];
   2450 		}
   2451 
   2452 		pChironBuf->pBuffer = NULL;
   2453 		((OMX_TI_PLATFORMPRIVATE *) (pChironBuf->pPlatformPrivate))->
   2454 		    pAuxBuf1 = NULL;
   2455 
   2456 		eError =
   2457 		    RPC_MapBuffer_Ducati(pBuffer, LINUX_PAGE_SIZE,
   2458 		    nNumOfLines, &(pChironBuf->pBuffer), pBufToBeMapped);
   2459 		PROXY_assert(eError == OMX_ErrorNone, eError, "Map failed");
   2460 		eError =
   2461 		    RPC_MapBuffer_Ducati((OMX_U8 *) ((OMX_U32) pBuffer +
   2462 			nNumOfLines * LINUX_PAGE_SIZE), LINUX_PAGE_SIZE,
   2463 		    nNumOfLines / 2,
   2464 		    (OMX_U8 **) (&((OMX_TI_PLATFORMPRIVATE
   2465 				*) (pChironBuf->pPlatformPrivate))->pAuxBuf1),
   2466 		    pBufToBeMapped);
   2467 		PROXY_assert(eError == OMX_ErrorNone, eError, "Map failed");
   2468 		*(OMX_U32 *) pBufToBeMapped = (OMX_U32) pBuffer;
   2469 	}
   2470 
   2471       EXIT:
   2472 	DOMX_EXIT("eError: %d", eError);
   2473 	return eError;
   2474 }
   2475 
   2476 
   2477 /* ===========================================================================*/
   2478 /**
   2479  * @name RPC_MapBuffer_Ducati()
   2480  * @brief
   2481  * @param void
   2482  * @return OMX_ErrorNone = Successful
   2483  * @sa TBD
   2484  *
   2485  */
   2486 /* ===========================================================================*/
   2487 OMX_ERRORTYPE RPC_MapBuffer_Ducati(OMX_U8 * pBuf, OMX_U32 nBufLineSize,
   2488     OMX_U32 nBufLines, OMX_U8 ** pMappedBuf, OMX_PTR pBufToBeMapped)
   2489 {
   2490 	ProcMgr_MapType mapType;
   2491 	SyslinkMemUtils_MpuAddrToMap MpuAddr_list_1D = { 0 };
   2492 	MemAllocBlock block = { 0 };
   2493 	OMX_S32 status;
   2494 	OMX_U32 nDiff = 0;
   2495 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2496 
   2497 	DOMX_ENTER("");
   2498 
   2499 	*(OMX_U32 *) pBufToBeMapped = (OMX_U32) pBuf;
   2500 
   2501 	if (!MemMgr_IsMapped(pBuf) && (nBufLines == 1))
   2502 	{
   2503 		DOMX_DEBUG
   2504 		    ("Buffer is not mapped: Mapping as 1D buffer now..");
   2505 		block.fmt = PIXEL_FMT_PAGE;
   2506 		block.ptr = (OMX_PTR) (((OMX_U32) pBuf / LINUX_PAGE_SIZE) *
   2507 		    LINUX_PAGE_SIZE);
   2508 		block.dim.len = (OMX_U32) ((((OMX_U32) pBuf + nBufLineSize +
   2509 			    LINUX_PAGE_SIZE - 1) / LINUX_PAGE_SIZE) *
   2510 		    LINUX_PAGE_SIZE) - (OMX_U32) block.ptr;
   2511 		block.stride = 0;
   2512 		nDiff = (OMX_U32) pBuf - (OMX_U32) block.ptr;
   2513 
   2514 		(*(OMX_U32 *) (pBufToBeMapped)) =
   2515 		    (OMX_U32) (MemMgr_Map(&block, 1));
   2516 		PROXY_assert(*(OMX_U32 *) pBufToBeMapped != 0,
   2517 		    OMX_ErrorInsufficientResources,
   2518 		    "Map to TILER space failed");
   2519 		//*pMappedBuf = MemMgr_Map(&block, 1);
   2520 	}
   2521 
   2522 	if (MemMgr_IsMapped((OMX_PTR) (*(OMX_U32 *) pBufToBeMapped)))
   2523 	{
   2524 		//If Tiler 1D buffer, get corresponding ducati address and send out buffer to ducati
   2525 		//For 2D buffers, in phase1, retrive the ducati address (SSPtrs) for Y and UV buffers
   2526 		//and send out buffer to ducati
   2527 		mapType = ProcMgr_MapType_Tiler;
   2528 		MpuAddr_list_1D.mpuAddr =
   2529 		    (*(OMX_U32 *) pBufToBeMapped) + nDiff;
   2530 		MpuAddr_list_1D.size = nBufLineSize * nBufLines;
   2531 
   2532 		status =
   2533 		    SysLinkMemUtils_map(&MpuAddr_list_1D, 1,
   2534 		    (UInt32 *) pMappedBuf, mapType, PROC_APPM3);
   2535 		PROXY_assert(status >= 0, OMX_ErrorInsufficientResources,
   2536 		    "Syslink map failed");
   2537 	}
   2538 
   2539       EXIT:
   2540 	DOMX_EXIT("eError: %d", eError);
   2541 	return eError;
   2542 }
   2543 
   2544 
   2545 
   2546 /* ===========================================================================*/
   2547 /**
   2548  * @name RPC_UnMapBuffer_Ducati()
   2549  * @brief
   2550  * @param
   2551  * @return
   2552  * @sa
   2553  *
   2554  */
   2555 /* ===========================================================================*/
   2556 OMX_ERRORTYPE RPC_UnMapBuffer_Ducati(OMX_PTR pBuffer)
   2557 {
   2558 	OMX_U32 status = 0;
   2559 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2560 
   2561 	DOMX_ENTER("");
   2562 
   2563 	status = MemMgr_UnMap(pBuffer);
   2564 	PROXY_assert(status == 0, OMX_ErrorUndefined,
   2565 	    "MemMgr_UnMap returned an error");
   2566 
   2567       EXIT:
   2568 	DOMX_EXIT("eError: %d", eError);
   2569 	return eError;
   2570 }
   2571 
   2572 /* ===========================================================================*/
   2573 /**
   2574  * @name RPC_MapMetaData_Host()
   2575  * @brief This utility maps metadata buffer in OMX buffer header to Chiron
   2576  * virtual address space (metadata buffer is TILER 1D buffer in Ducati Virtual
   2577  * space). It overrides the metadata buffer with Chiron address in the same
   2578  * field. Metadata buffer size represents max size (alloc size) that needs to
   2579  * be mapped
   2580  * @param void
   2581  * @return OMX_ErrorNone = Successful
   2582  * @sa TBD
   2583  *
   2584  */
   2585 /* ===========================================================================*/
   2586 OMX_ERRORTYPE RPC_MapMetaData_Host(OMX_BUFFERHEADERTYPE * pBufHdr)
   2587 {
   2588 	OMX_PTR pMappedMetaDataBuffer = NULL;
   2589 	OMX_U32 nMetaDataSize = 0;
   2590 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2591 
   2592 	DSPtr dsptr[2];
   2593 	bytes_t lengths[2];
   2594 	OMX_U32 numBlocks = 0;
   2595 
   2596 	DOMX_ENTER("");
   2597 
   2598 	if ((pBufHdr->pPlatformPrivate != NULL) &&
   2599 	    (((OMX_TI_PLATFORMPRIVATE *) pBufHdr->pPlatformPrivate)->
   2600 		pMetaDataBuffer != NULL))
   2601 	{
   2602 
   2603 		pMappedMetaDataBuffer = NULL;
   2604 
   2605 		nMetaDataSize =
   2606 		    ((OMX_TI_PLATFORMPRIVATE *) pBufHdr->pPlatformPrivate)->
   2607 		    nMetaDataSize;
   2608 		PROXY_assert((nMetaDataSize != 0), OMX_ErrorBadParameter,
   2609 		    "Received ZERO metadata size from Ducati, cannot map");
   2610 
   2611 		dsptr[0] =
   2612 		    (OMX_U32) ((OMX_TI_PLATFORMPRIVATE *)
   2613 		    pBufHdr->pPlatformPrivate)->pMetaDataBuffer;
   2614 		numBlocks = 1;
   2615 		lengths[0] =
   2616 		    LINUX_PAGE_SIZE * ((nMetaDataSize + (LINUX_PAGE_SIZE -
   2617 			    1)) / LINUX_PAGE_SIZE);
   2618 
   2619 		pMappedMetaDataBuffer =
   2620 		    tiler_assisted_phase1_D2CReMap(numBlocks, dsptr, lengths);
   2621 
   2622 		PROXY_assert((pMappedMetaDataBuffer != NULL),
   2623 		    OMX_ErrorInsufficientResources,
   2624 		    "Mapping metadata to Chiron space failed");
   2625 
   2626 		((OMX_TI_PLATFORMPRIVATE *) pBufHdr->pPlatformPrivate)->
   2627 		    pMetaDataBuffer = pMappedMetaDataBuffer;
   2628 	}
   2629 
   2630       EXIT:
   2631 	DOMX_EXIT("eError: %d", eError);
   2632 	return eError;
   2633 }
   2634 
   2635 /* ===========================================================================*/
   2636 /**
   2637  * @name RPC_UnMapMetaData_Host()
   2638  * @brief This utility unmaps the previously mapped metadata on host from remote
   2639  * components
   2640  * @param void
   2641  * @return OMX_ErrorNone = Successful
   2642  * @sa TBD
   2643  *
   2644  */
   2645 /* ===========================================================================*/
   2646 OMX_ERRORTYPE RPC_UnMapMetaData_Host(OMX_BUFFERHEADERTYPE * pBufHdr)
   2647 {
   2648 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2649 	OMX_S32 nReturn = 0;
   2650 
   2651 	DOMX_ENTER("");
   2652 
   2653 	if ((pBufHdr->pPlatformPrivate != NULL) &&
   2654 	    (((OMX_TI_PLATFORMPRIVATE *) pBufHdr->pPlatformPrivate)->
   2655 		pMetaDataBuffer != NULL))
   2656 	{
   2657 
   2658 		nReturn =
   2659 		    tiler_assisted_phase1_DeMap((((OMX_TI_PLATFORMPRIVATE *)
   2660 			    pBufHdr->pPlatformPrivate)->pMetaDataBuffer));
   2661 		PROXY_assert((nReturn == 0), OMX_ErrorUndefined,
   2662 		    "Metadata unmap failed");
   2663 	}
   2664       EXIT:
   2665 	DOMX_EXIT("eError: %d", eError);
   2666 	return eError;
   2667 }
   2668 
   2669 #endif
   2670 
   2671 /* ===========================================================================*/
   2672 /**
   2673  * @name _RPC_IsProxyComponent()
   2674  * @brief This function calls GetComponentVersion API on the component and
   2675  *        based on the component name decidec whether the component is a proxy
   2676  *        or real component. The naming component convention assumed is
   2677  *        <OMX>.<Company Name>.<Core Name>.<Domain>.<Component Details> with
   2678  *        all characters in upper case for e.g. OMX.TI.DUCATI1.VIDEO.H264E
   2679  * @param hComponent [IN] : The component handle
   2680  *        bIsProxy [OUT]  : Set to true is handle is for a proxy component
   2681  * @return OMX_ErrorNone = Successful
   2682  *
   2683  **/
   2684 /* ===========================================================================*/
   2685 OMX_ERRORTYPE _RPC_IsProxyComponent(OMX_HANDLETYPE hComponent,
   2686     OMX_BOOL * bIsProxy)
   2687 {
   2688 	OMX_ERRORTYPE eError = OMX_ErrorNone;
   2689 	OMX_S8 cComponentName[MAXNAMESIZE] = { 0 }
   2690 	, cCoreName[32] =
   2691 	{
   2692 	0};
   2693 	OMX_VERSIONTYPE sCompVer, sSpecVer;
   2694 	OMX_UUIDTYPE sCompUUID;
   2695 	OMX_U32 i = 0, ret = 0;
   2696 
   2697 	eError =
   2698 	    OMX_GetComponentVersion(hComponent, (OMX_STRING) cComponentName,
   2699 	    &sCompVer, &sSpecVer, &sCompUUID);
   2700 	PROXY_assert(eError == OMX_ErrorNone, eError, "");
   2701 	ret =
   2702 	    sscanf((char *)cComponentName, "%*[^'.'].%*[^'.'].%[^'.'].%*s",
   2703 	    cCoreName);
   2704 	PROXY_assert(ret == 1, OMX_ErrorBadParameter,
   2705 	    "Incorrect component name");
   2706 	for (i = 0; i < CORE_MAX; i++)
   2707 	{
   2708 		if (strcmp((char *)cCoreName, Core_Array[i]) == 0)
   2709 			break;
   2710 	}
   2711 	PROXY_assert(i < CORE_MAX, OMX_ErrorBadParameter,
   2712 	    "Unknown core name");
   2713 
   2714 	/* If component name indicates remote core, it means proxy
   2715 	   component */
   2716 	if ((i == CORE_SYSM3) || (i == CORE_APPM3) || (i == CORE_TESLA))
   2717 		*bIsProxy = OMX_TRUE;
   2718 	else
   2719 		*bIsProxy = OMX_FALSE;
   2720 
   2721       EXIT:
   2722 	return eError;
   2723 }
   2724