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_videodecoder.c
35 *         This file contains methods that provides the functionality for
36 *         the OpenMAX1.1 DOMX Framework Tunnel Proxy component.
37 *********************************************************************************************
38 This is the proxy specific wrapper that passes the component name to the generic proxy init()
39 The proxy wrapper also does some runtime/static time onfig on per proxy basis
40 This is a thin wrapper that is called when componentiit() of the proxy is called
41 static OMX_ERRORTYPE PROXY_Wrapper_init(OMX_HANDLETYPE hComponent, OMX_PTR pAppData);
42 this layer gets called first whenever a proxy's get handle is called
43 ************************************************************************************************
44 *  @path WTSD_DucatiMMSW\omx\omx_il_1_x\omx_proxy_component\src
45 *
46 *  @rev 1.0
47 */
48
49/*==============================================================
50 *! Revision History
51 *! ============================
52 *! 20-August-2010 Sarthak Aggarwal sarthak@ti.com: Initial Version
53 *================================================================*/
54
55/******************************************************************
56 *   INCLUDE FILES
57 ******************************************************************/
58#include <stdio.h>
59#include <string.h>
60#include <assert.h>
61#include "omx_proxy_common.h"
62#include <timm_osal_interfaces.h>
63#include "OMX_TI_IVCommon.h"
64#include "OMX_TI_Video.h"
65#include "OMX_TI_Index.h"
66
67#define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.DECODER"
68/* needs to be specific for every configuration wrapper */
69
70#ifdef USE_ENHANCED_PORTRECONFIG
71//Define port indices in video decoder proxy
72#define OMX_VIDEODECODER_INPUT_PORT 0
73#define OMX_VIDEODECODER_OUTPUT_PORT 1
74#endif
75
76#ifdef SET_STRIDE_PADDING_FROM_PROXY
77
78#define LINUX_PAGE_SIZE (4 * 1024)
79#define TOTAL_DEC_PORTS 2
80#define HAL_NV12_PADDED_PIXEL_FORMAT (OMX_TI_COLOR_FormatYUV420PackedSemiPlanar - OMX_COLOR_FormatVendorStartUnused)
81
82static OMX_ERRORTYPE RPC_UTIL_SetStrideAndPadding(OMX_COMPONENTTYPE * hRemoteComp, PROXY_COMPONENT_PRIVATE * pCompPrv);
83
84OMX_ERRORTYPE PROXY_VIDDEC_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,
85    OMX_IN OMX_COMMANDTYPE eCmd,
86    OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData);
87
88OMX_ERRORTYPE PROXY_VIDDEC_EventHandler(OMX_HANDLETYPE hComponent,
89    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
90    OMX_PTR pEventData);
91
92#endif //SET_STRIDE_PADDING_FROM_PROXY
93
94OMX_ERRORTYPE PROXY_VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
95    OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType);
96
97#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES
98
99OMX_ERRORTYPE PROXY_VIDDEC_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
100    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
101
102OMX_ERRORTYPE PROXY_VIDDEC_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
103    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
104
105#endif
106
107#ifdef ANDROID_QUIRK_LOCK_BUFFER
108#include <hardware/gralloc.h>
109#include <hardware/hardware.h>
110#include "hal_public.h"
111
112OMX_ERRORTYPE PROXY_VIDDEC_FillThisBuffer(OMX_HANDLETYPE hComponent, OMX_BUFFERHEADERTYPE * pBufferHdr);
113OMX_ERRORTYPE PROXY_VIDDEC_FillBufferDone(OMX_HANDLETYPE hComponent,
114    OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags,
115    OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent,
116    OMX_PTR pMarkData);
117
118#endif
119
120OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent)
121{
122	OMX_ERRORTYPE eError = OMX_ErrorNone;
123	OMX_COMPONENTTYPE *pHandle = NULL;
124	PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL;
125	pHandle = (OMX_COMPONENTTYPE *) hComponent;
126
127	DOMX_ENTER("");
128
129	DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME);
130
131	pHandle->pComponentPrivate =
132	    (PROXY_COMPONENT_PRIVATE *)
133	    TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), TIMM_OSAL_TRUE,
134	    0, TIMMOSAL_MEM_SEGMENT_INT);
135
136	PROXY_assert(pHandle->pComponentPrivate != NULL,
137	    OMX_ErrorInsufficientResources,
138	    "ERROR IN ALLOCATING PROXY COMPONENT PRIVATE STRUCTURE");
139
140	pComponentPrivate =
141	    (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
142
143	TIMM_OSAL_Memset(pComponentPrivate, 0,
144		sizeof(PROXY_COMPONENT_PRIVATE));
145
146	pComponentPrivate->cCompName =
147	    TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8),
148	    TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT);
149
150	PROXY_assert(pComponentPrivate->cCompName != NULL,
151	    OMX_ErrorInsufficientResources,
152	    " Error in Allocating space for proxy component table");
153
154	eError = OMX_ProxyViddecInit(hComponent);
155
156	EXIT:
157		return eError;
158}
159
160OMX_ERRORTYPE OMX_ProxyViddecInit(OMX_HANDLETYPE hComponent)
161{
162	OMX_ERRORTYPE eError = OMX_ErrorNone;
163	OMX_COMPONENTTYPE *pHandle = NULL;
164	PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL;
165	pHandle = (OMX_COMPONENTTYPE *) hComponent;
166        OMX_TI_PARAM_ENHANCEDPORTRECONFIG tParamStruct;
167
168#ifdef ANDROID_QUIRK_LOCK_BUFFER
169	OMX_U32 err;
170	hw_module_t const* module;
171#endif
172	DOMX_ENTER("");
173
174	DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME);
175
176        pComponentPrivate =
177            (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
178
179	// Copying component Name - this will be picked up in the proxy common
180	PROXY_assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH,
181	    OMX_ErrorInvalidComponentName,
182	    "Length of component name is longer than the max allowed");
183	TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME,
184	    strlen(COMPONENT_NAME) + 1);
185
186	eError = OMX_ProxyCommonInit(hComponent);	// Calling Proxy Common Init()
187	PROXY_assert(eError == OMX_ErrorNone, eError, "Proxy common init returned error");
188#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES
189	pHandle->SetParameter = PROXY_VIDDEC_SetParameter;
190        pHandle->GetParameter = PROXY_VIDDEC_GetParameter;
191#endif
192	pHandle->GetExtensionIndex = PROXY_VIDDEC_GetExtensionIndex;
193
194#ifdef  SET_STRIDE_PADDING_FROM_PROXY
195        pHandle->SendCommand = PROXY_VIDDEC_SendCommand;
196	pComponentPrivate->proxyEventHandler = PROXY_VIDDEC_EventHandler;
197	pComponentPrivate->IsLoadedState = OMX_TRUE;
198#endif
199
200#ifdef ANDROID_QUIRK_LOCK_BUFFER
201        pComponentPrivate->proxyFillBufferDone = PROXY_VIDDEC_FillBufferDone;
202	pHandle->FillThisBuffer = PROXY_VIDDEC_FillThisBuffer;
203
204        err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
205        if (err == 0)
206	{
207                pComponentPrivate->grallocModule = (gralloc_module_t const *)module;
208        }
209	else
210	{
211                DOMX_ERROR("FATAL: gralloc api hw_get_module() returned error: Can't find \
212		 %s module err = %x", GRALLOC_HARDWARE_MODULE_ID, err);
213		eError = OMX_ErrorInsufficientResources;
214		return eError;
215	}
216#endif
217
218#ifdef USE_ENHANCED_PORTRECONFIG
219	/*Initializing Structure */
220	tParamStruct.nSize = sizeof(OMX_TI_PARAM_ENHANCEDPORTRECONFIG);
221	tParamStruct.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
222	tParamStruct.nVersion.s.nVersionMinor = OMX_VER_MINOR;
223	tParamStruct.nVersion.s.nRevision = 0x0;
224	tParamStruct.nVersion.s.nStep = 0x0;
225	tParamStruct.nPortIndex = OMX_VIDEODECODER_OUTPUT_PORT;
226        tParamStruct.bUsePortReconfigForCrop = OMX_TRUE;
227        tParamStruct.bUsePortReconfigForPadding = OMX_TRUE;
228
229	eError = PROXY_SetParameter(hComponent,(OMX_INDEXTYPE)OMX_TI_IndexParamUseEnhancedPortReconfig,
230	   &tParamStruct);
231	PROXY_assert(eError == OMX_ErrorNone,
232	    eError," Error in Proxy SetParameter for Enhanced port reconfig usage");
233#endif
234
235      EXIT:
236	if (eError != OMX_ErrorNone)
237	{
238		DOMX_DEBUG("Error in Initializing Proxy");
239		if (pComponentPrivate->cCompName != NULL)
240		{
241			TIMM_OSAL_Free(pComponentPrivate->cCompName);
242			pComponentPrivate->cCompName = NULL;
243		}
244		if (pComponentPrivate != NULL)
245		{
246			TIMM_OSAL_Free(pComponentPrivate);
247			pComponentPrivate = NULL;
248		}
249	}
250	return eError;
251}
252
253/* ===========================================================================*/
254/**
255 * @name PROXY_VIDDEC_GetExtensionIndex()
256 * @brief
257 * @param void
258 * @return OMX_ErrorNone = Successful
259 * @sa TBD
260 *
261 */
262/* ===========================================================================*/
263OMX_ERRORTYPE PROXY_VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
264		OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType)
265{
266	OMX_ERRORTYPE eError = OMX_ErrorNone;
267	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
268	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
269
270	PROXY_require((hComp->pComponentPrivate != NULL), OMX_ErrorBadParameter, NULL);
271	PROXY_require(cParameterName != NULL, OMX_ErrorBadParameter, NULL);
272	PROXY_require(pIndexType != NULL, OMX_ErrorBadParameter, NULL);
273
274	DOMX_ENTER("hComponent = %p, cParameterName = %p", hComponent, cParameterName);
275
276#ifdef ENABLE_GRALLOC_BUFFERS
277	// Ensure that String length is not greater than Max allowed length
278	PROXY_require(strlen(cParameterName) <= 127, OMX_ErrorBadParameter, NULL);
279
280	if (strcmp(cParameterName, "OMX.google.android.index.getAndroidNativeBufferUsage") == 0)
281	{
282		*pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexAndroidNativeBufferUsage;
283	}
284	else
285	{
286		eError = PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType);
287		PROXY_assert(eError == OMX_ErrorNone,
288		    eError," Error in PROXY_GetExtensionIndex");
289	}
290#else
291	eError = PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType);
292	PROXY_assert(eError == OMX_ErrorNone,
293		eError," Error in PROXY_GetExtensionIndex");
294#endif
295	EXIT:
296	DOMX_EXIT("eError: %d", eError);
297	return eError;
298}
299
300#ifdef  ANDROID_QUIRK_CHANGE_PORT_VALUES
301
302/* ===========================================================================*/
303/**
304 * @name PROXY_GetParameter()
305 * @brief
306 * @param void
307 * @return OMX_ErrorNone = Successful
308 * @sa TBD
309 *
310 */
311/* ===========================================================================*/
312OMX_ERRORTYPE PROXY_VIDDEC_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
313    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct)
314{
315	OMX_ERRORTYPE eError = OMX_ErrorNone;
316	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
317	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
318	OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
319	OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParam = NULL;
320	OMX_TI_PARAMNATIVEBUFFERUSAGE *pUsage = NULL;
321
322	PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL);
323	PROXY_assert((hComp->pComponentPrivate != NULL),
324	    OMX_ErrorBadParameter, NULL);
325
326	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
327
328	DOMX_ENTER
329	    ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p",
330	    hComponent, pCompPrv, nParamIndex, pParamStruct);
331
332#ifdef ENABLE_GRALLOC_BUFFERS
333	if( nParamIndex == OMX_TI_IndexAndroidNativeBufferUsage)
334	{
335		pUsage = (OMX_TI_PARAMNATIVEBUFFERUSAGE*)pParamStruct;
336		if(pCompPrv->proxyPortBuffers[pUsage->nPortIndex].proxyBufferType == GrallocPointers)
337		{
338			PROXY_CHK_VERSION(pParamStruct, OMX_TI_PARAMNATIVEBUFFERUSAGE);
339			pUsage->nUsage = GRALLOC_USAGE_HW_RENDER;
340			goto EXIT;
341		}
342	}
343#endif
344	eError = PROXY_GetParameter(hComponent,nParamIndex, pParamStruct);
345	PROXY_assert((eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore),
346		    eError," Error in Proxy GetParameter");
347
348	if( nParamIndex == OMX_IndexParamPortDefinition)
349	{
350		PROXY_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE);
351		pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct;
352		if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar)
353		{
354			if(pCompPrv->proxyPortBuffers[pPortDef->nPortIndex].proxyBufferType == GrallocPointers)
355			{
356				pPortDef->format.video.eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT;
357			}
358			else
359			{
360				pPortDef->format.video.eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar;
361			}
362		}
363	}
364	else if ( nParamIndex == OMX_IndexParamVideoPortFormat)
365	{
366		PROXY_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE);
367		pPortParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct;
368		if(pPortParam->eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar)
369		{
370			if(pCompPrv->proxyPortBuffers[pPortParam->nPortIndex].proxyBufferType == GrallocPointers)
371			{
372				pPortParam->eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT;
373			}
374			else
375			{
376				pPortParam->eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar;
377			}
378		}
379	}
380
381      EXIT:
382	DOMX_EXIT("eError: %d", eError);
383	return eError;
384}
385
386/* ===========================================================================*/
387/**
388 * @name PROXY_SetParameter()
389 * @brief
390 * @param void
391 * @return OMX_ErrorNone = Successful
392 * @sa TBD
393 *
394 */
395/* ===========================================================================*/
396OMX_ERRORTYPE PROXY_VIDDEC_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
397    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct)
398{
399	OMX_ERRORTYPE eError = OMX_ErrorNone;
400	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
401	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
402	OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct;
403	OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct;
404
405	PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL);
406	PROXY_require((hComp->pComponentPrivate != NULL),
407	    OMX_ErrorBadParameter, NULL);
408
409	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
410	DOMX_ENTER
411	    ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p",
412	    hComponent, pCompPrv, nParamIndex, pParamStruct);
413	if(nParamIndex == OMX_IndexParamPortDefinition)
414	{
415		if(pPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar
416			|| pPortDef->format.video.eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT)
417		{
418			pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar;
419		}
420	}
421	else if(nParamIndex == OMX_IndexParamVideoPortFormat)
422	{
423		if(pPortParams->eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar
424			|| pPortParams->eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT)
425		{
426			pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar;
427		}
428	}
429
430	eError = PROXY_SetParameter(hComponent, nParamIndex, pParamStruct);
431	PROXY_assert(eError == OMX_ErrorNone,
432		    eError," Error in Proxy SetParameter");
433
434	EXIT:
435	DOMX_EXIT("eError: %d", eError);
436	return eError;
437}
438
439#endif
440
441#ifdef SET_STRIDE_PADDING_FROM_PROXY
442/* ===========================================================================*/
443/**
444 * @name PROXY_VIDDEC_SendCommand()
445 * @brief
446 * @return OMX_ErrorNone = Successful
447 * @sa TBD
448 *
449 */
450/* ===========================================================================*/
451OMX_ERRORTYPE PROXY_VIDDEC_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,
452    OMX_IN OMX_COMMANDTYPE eCmd,
453    OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData)
454{
455	OMX_ERRORTYPE eError = OMX_ErrorNone;
456	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
457	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
458
459	PROXY_require((hComp->pComponentPrivate != NULL),
460	    OMX_ErrorBadParameter, NULL);
461
462	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
463
464	DOMX_ENTER
465	    ("hComponent = %p, pCompPrv = %p, eCmd = %d, nParam = %d, pCmdData = %p",
466	    hComponent, pCompPrv, eCmd, nParam, pCmdData);
467
468	if(eCmd == OMX_CommandStateSet)
469	{
470		//Set appropriate stride before Loaded to Idle transition.
471		if((OMX_STATETYPE)nParam == OMX_StateIdle && pCompPrv->IsLoadedState == OMX_TRUE)
472		{
473			eError = RPC_UTIL_SetStrideAndPadding(hComponent, pCompPrv);
474			PROXY_require(eError == OMX_ErrorNone, eError,
475                               "Stride and padding setting from proxy returned");
476			pCompPrv->IsLoadedState = OMX_FALSE;
477		}
478	}
479	else if(eCmd == OMX_CommandPortEnable)
480	{
481		if(nParam == OMX_ALL || nParam == OMX_VIDEODECODER_OUTPUT_PORT)
482		{
483			eError = RPC_UTIL_SetStrideAndPadding(hComponent, pCompPrv);
484			PROXY_require(eError == OMX_ErrorNone, eError,
485                               "Stride and padding setting from proxy returned");
486		}
487	}
488
489	eError =
490	    PROXY_SendCommand(hComponent, eCmd, nParam, pCmdData);
491
492      EXIT:
493	DOMX_EXIT("eError: %d", eError);
494	return eError;
495}
496
497/* ===========================================================================*/
498/**
499 * @name PROXY_EventHandler()
500 * @brief
501 * @param void
502 * @return OMX_ErrorNone = Successful
503 * @sa TBD
504 *
505 */
506/* ===========================================================================*/
507OMX_ERRORTYPE PROXY_VIDDEC_EventHandler(OMX_HANDLETYPE hComponent,
508    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
509    OMX_PTR pEventData)
510{
511	OMX_ERRORTYPE eError = OMX_ErrorNone;
512	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
513	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
514
515	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
516
517	PROXY_require((hComp->pComponentPrivate != NULL),
518	    OMX_ErrorBadParameter,
519	    "This is fatal error, processing cant proceed - please debug");
520
521	DOMX_ENTER
522	    ("hComponent=%p, pCompPrv=%p, eEvent=%p, nData1=%p, nData2=%p, pEventData=%p",
523	    hComponent, pCompPrv, eEvent, nData1, nData2, pEventData);
524
525	if((eEvent ==  OMX_EventCmdComplete) && ((OMX_COMMANDTYPE)nData1 == OMX_CommandStateSet))
526	{
527		if((OMX_STATETYPE)nData2 == OMX_StateLoaded)
528		{
529			pCompPrv->IsLoadedState = OMX_TRUE;
530		}
531	}
532	eError = PROXY_EventHandler(hComponent, pAppData, eEvent, nData1, nData2, pEventData);
533
534	EXIT:
535		return eError;
536}
537
538/* ===========================================================================*/
539/**
540 * @name RPC_UTIL_RPC_UTIL_SetStrideAndPadding()
541 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D
542 * @param hRemoteComp [IN]  : Remote component handle.
543 * @return OMX_ErrorNone = Successful
544 */
545/* ===========================================================================*/
546OMX_ERRORTYPE RPC_UTIL_SetStrideAndPadding(OMX_COMPONENTTYPE * hComponent,PROXY_COMPONENT_PRIVATE * pCompPrv)
547{
548	OMX_ERRORTYPE eError = OMX_ErrorNone;
549	OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
550	OMX_CONFIG_RECTTYPE tParamStruct;
551	OMX_U32 nPortIndex = 0;
552
553	for(nPortIndex=0; nPortIndex < TOTAL_DEC_PORTS ;nPortIndex++ )
554	{
555		/*Initializing Structure */
556		sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
557		sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
558		sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR;
559		sPortDef.nVersion.s.nRevision = 0x0;
560		sPortDef.nVersion.s.nStep = 0x0;
561		sPortDef.nPortIndex = nPortIndex;
562
563		eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition,
564			   &sPortDef);
565		PROXY_assert(eError == OMX_ErrorNone,
566			    eError," Error in Proxy GetParameter for Port Def");
567
568		if (sPortDef.eDomain == OMX_PortDomainVideo && sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingUnused)
569		{
570			if(pCompPrv->proxyPortBuffers[nPortIndex].IsBuffer2D == OMX_TRUE)
571			{
572				sPortDef.format.video.nStride = LINUX_PAGE_SIZE;
573			}
574			else
575			{
576				tParamStruct.nSize = sizeof(OMX_CONFIG_RECTTYPE);
577				tParamStruct.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
578				tParamStruct.nVersion.s.nVersionMinor = OMX_VER_MINOR;
579				tParamStruct.nVersion.s.nRevision = 0x0;
580				tParamStruct.nVersion.s.nStep = 0x0;
581				tParamStruct.nPortIndex = nPortIndex;
582
583				eError = PROXY_GetParameter(hComponent,(OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension,
584						  &tParamStruct);
585				PROXY_assert(eError == OMX_ErrorNone,
586					    eError," Error in Proxy GetParameter for 2D index");
587
588				sPortDef.format.video.nStride = tParamStruct.nWidth;
589			}
590			eError = PROXY_SetParameter(hComponent,OMX_IndexParamPortDefinition,
591				   &sPortDef);
592			PROXY_assert(eError == OMX_ErrorNone,
593				    eError," Error in Proxy SetParameter for Port Def");
594		}
595	}
596
597      EXIT:
598	return eError;
599}
600
601#endif
602
603#ifdef ANDROID_QUIRK_LOCK_BUFFER
604/* ===========================================================================*/
605/**
606 * @name PROXY_VIDDEC_FillThisBuffer()
607 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D
608 */
609/* ===========================================================================*/
610OMX_ERRORTYPE PROXY_VIDDEC_FillThisBuffer(OMX_HANDLETYPE hComponent, OMX_BUFFERHEADERTYPE * pBufferHdr)
611{
612	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
613	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
614	PROXY_COMPONENT_PRIVATE *pCompPrv;
615	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
616	OMX_U32 count = 0;
617	IMG_native_handle_t*  grallocHandle;
618	OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
619
620	PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL);
621	PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter,
622	    NULL);
623	PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE);
624
625	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
626
627	if(pCompPrv->proxyPortBuffers[OMX_VIDEODECODER_OUTPUT_PORT].proxyBufferType
628			== GrallocPointers)
629	{
630		/* Lock the Gralloc buffer till it gets rendered completely */
631		/* Extract the Gralloc handle from the Header and then call lock on that */
632		/* Note# There is no error check for the pBufferHdr here*/
633		grallocHandle = (IMG_native_handle_t*)pBufferHdr->pBuffer;
634
635		/*Initializing Structure */
636		sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
637		sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR;
638		sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR;
639		sPortDef.nVersion.s.nRevision = 0x0;
640		sPortDef.nVersion.s.nStep = 0x0;
641		sPortDef.nPortIndex = OMX_VIDEODECODER_INPUT_PORT;
642		eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition,
643				&sPortDef);
644		PROXY_assert(eError == OMX_ErrorNone,
645				eError," Error in Proxy GetParameter for Port Def");
646
647		pCompPrv->grallocModule->lock((gralloc_module_t const *) pCompPrv->grallocModule,
648				(buffer_handle_t)grallocHandle, GRALLOC_USAGE_HW_RENDER,
649				0,0,sPortDef.format.video.nFrameWidth, sPortDef.format.video.nFrameHeight,NULL);
650	}
651
652        eRPCError = PROXY_FillThisBuffer(hComponent, pBufferHdr);
653
654	PROXY_assert(eError == OMX_ErrorNone,
655	    eError," Error in Proxy SetParameter for Port Def");
656
657      EXIT:
658	DOMX_EXIT("eError: %d", eError);
659	return eError;
660}
661
662/* ===========================================================================*/
663/**
664 * @name PROXY_VIDDEC_FillBufferDone()
665 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D
666 */
667/* ===========================================================================*/
668OMX_ERRORTYPE PROXY_VIDDEC_FillBufferDone(OMX_HANDLETYPE hComponent,
669    OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags,
670    OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent,
671    OMX_PTR pMarkData)
672{
673	OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone;
674	RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone;
675	PROXY_COMPONENT_PRIVATE *pCompPrv = NULL;
676	OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent;
677	OMX_U32 count = 0;
678	IMG_native_handle_t*  grallocHandle;
679
680	PROXY_require((hComp->pComponentPrivate != NULL),
681			OMX_ErrorBadParameter,
682			"This is fatal error, processing cant proceed - please debug");
683
684	pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate;
685
686	/* Lock the Gralloc buffer till it gets rendered completely */
687	/* Extract the Gralloc handle from the Header and then call lock on that */
688	/* Note# There is no error check for the pBufferHdr here*/
689
690	if(pCompPrv->proxyPortBuffers[OMX_VIDEODECODER_OUTPUT_PORT].proxyBufferType
691			== GrallocPointers) {
692		for (count = 0; count < pCompPrv->nTotalBuffers; ++count)
693		{
694			if (pCompPrv->tBufList[count].pBufHeaderRemote == remoteBufHdr)
695			{
696				grallocHandle = (IMG_native_handle_t*)(pCompPrv->tBufList[count].pBufHeader)->pBuffer;
697				break;
698			}
699		}
700
701		PROXY_assert((count != pCompPrv->nTotalBuffers),
702				OMX_ErrorBadParameter,
703				"Received invalid-buffer header from OMX component");
704		pCompPrv->grallocModule->unlock((gralloc_module_t const *) pCompPrv->grallocModule, (buffer_handle_t)grallocHandle);
705	}
706
707	eRPCError = PROXY_FillBufferDone(hComponent,remoteBufHdr, nfilledLen, nOffset, nFlags,
708		nTimeStamp, hMarkTargetComponent, pMarkData);
709
710	PROXY_assert(eError == OMX_ErrorNone,
711			eError," Error in PROXY FillBufferDone for Port Def");
712
713EXIT:
714	DOMX_EXIT("eError: %d", eError);
715	return eError;
716}
717
718#endif
719
720