1
2/*
3 * Copyright (C) Texas Instruments - http://www.ti.com/
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21/* ==============================================================================
22*             Texas Instruments OMAP (TM) Platform Software
23*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
24*
25*  Use of this software is controlled by the terms and conditions found
26*  in the license agreement under which this software has been supplied.
27* ============================================================================ */
28/**
29* @file OMX_JpegDecoder.c
30*
31* This file implements OMX Component for JPEG decoder
32*
33* @patth $(CSLPATH)\jpeg_dec\src\OMX_JpegDecoder.c
34*
35* @rev 0.2
36*/
37
38/****************************************************************
39 *  INCLUDE FILES
40*****************************************************************/
41
42/* -----------System and Platform Files ------------------------*/
43
44#ifdef UNDER_CE
45    #include <windows.h>
46    #include <oaf_osal.h>
47    #include <omx_core.h>
48#else
49    #include <wchar.h>
50    #include <unistd.h>
51    #include <sys/time.h>
52    #include <sys/types.h>
53    #include <sys/ioctl.h>
54    #include <sys/select.h>
55    #include <errno.h>
56    #include <pthread.h>
57#endif
58
59#include <string.h>
60#include <fcntl.h>
61#include <stdlib.h>
62#include <stdio.h>
63#include <dbapi.h>
64
65/* -----------------Program Header Files ---------------------------*/
66
67#include "OMX_JpegDec_Utils.h"
68
69#ifdef RESOURCE_MANAGER_ENABLED
70    #include <ResourceManagerProxyAPI.h>
71#endif
72
73/*----------------------Global-----------------------------------*/
74OMX_STRING cJPEGdecName = "OMX.TI.JPEG.decoder";
75
76
77/* ---------------------------- Fucntion prototypes -----------------*/
78
79static OMX_ERRORTYPE SetCallbacks_JPEGDec(OMX_HANDLETYPE hComp,
80                                          OMX_CALLBACKTYPE* pCallBacks,
81                                          OMX_PTR pAppData);
82static OMX_ERRORTYPE GetComponentVersion_JPEGDec(OMX_HANDLETYPE hComp,
83                                                 OMX_STRING pComponentName,
84                                                 OMX_VERSIONTYPE* pComponentVersion,
85                                                 OMX_VERSIONTYPE* pSpecVersion,
86                                                 OMX_UUIDTYPE* pComponentUUID);
87static OMX_ERRORTYPE SendCommand_JPEGDec(OMX_HANDLETYPE hComponent,
88                                         OMX_COMMANDTYPE Cmd,
89                                         OMX_U32 nParam,
90                                         OMX_PTR pCmdData);
91static OMX_ERRORTYPE GetParameter_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
92                                          OMX_IN OMX_INDEXTYPE nParamIndex,
93                                          OMX_INOUT OMX_PTR ComponentParameterStructure);
94static OMX_ERRORTYPE SetParameter_JPEGDec(OMX_HANDLETYPE hComp,
95                                          OMX_INDEXTYPE nParamIndex,
96                                          OMX_PTR ComponentParameterStructure);
97static OMX_ERRORTYPE GetConfig_JPEGDec(OMX_HANDLETYPE hComp,
98                                       OMX_INDEXTYPE nConfigIndex,
99                                       OMX_PTR ComponentConfigStructure);
100static OMX_ERRORTYPE SetConfig_JPEGDec(OMX_HANDLETYPE hComp,
101                                       OMX_INDEXTYPE nConfigIndex,
102                                       OMX_PTR ComponentConfigStructure);
103static OMX_ERRORTYPE EmptyThisBuffer(OMX_HANDLETYPE hComp,
104                                     OMX_BUFFERHEADERTYPE* pBuffer);
105
106static OMX_ERRORTYPE FillThisBuffer_JPEGDec(OMX_HANDLETYPE hComp,
107                                            OMX_BUFFERHEADERTYPE* pBuffer);
108
109static OMX_ERRORTYPE GetState(OMX_HANDLETYPE hComp,
110                              OMX_STATETYPE* pState);
111static OMX_ERRORTYPE ComponentTunnelRequest_JPEGDec(OMX_IN OMX_HANDLETYPE hComp,
112                                                    OMX_IN OMX_U32 nPort,
113                                                    OMX_IN OMX_HANDLETYPE hTunneledComp,
114                                                    OMX_IN OMX_U32 nTunneledPort,
115                                                    OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup);
116static OMX_ERRORTYPE UseBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
117                                                   OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
118                                                   OMX_IN OMX_U32 nPortIndex,
119                                                   OMX_IN OMX_PTR pAppPrivate,
120                                                   OMX_IN OMX_U32 nSizeBytes,
121                                                   OMX_IN OMX_U8* pBuffer) ;
122static OMX_ERRORTYPE FreeBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
123                                        OMX_IN OMX_U32 nPortIndex,
124                                        OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
125static OMX_ERRORTYPE Allocate_DSPResources_JPEGDec(OMX_IN JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
126                                                   OMX_IN OMX_U32 nPortIndex);
127static OMX_ERRORTYPE VerifyTunnelConnection_JPEGDec(JPEGDEC_PORT_TYPE *pPort,
128                                                    OMX_HANDLETYPE hTunneledComp,
129                                                    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef);
130static  OMX_ERRORTYPE AllocateBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
131                                             OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
132                                             OMX_IN OMX_U32 nPortIndex,
133                                             OMX_IN OMX_PTR pAppPrivate,
134                                             OMX_IN OMX_U32 nSizeBytes);
135static void JPEGDEC_InitBufferFlagTrack(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
136										OMX_U32 nPortIndex);
137#ifdef KHRONOS_1_1
138static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
139                                       OMX_OUT OMX_U8 *cRole,
140                                       OMX_IN OMX_U32 nIndex);
141#endif
142
143static OMX_ERRORTYPE GetExtensionIndex_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
144                                                OMX_IN OMX_STRING cParameterName,
145                                                OMX_OUT OMX_INDEXTYPE* pIndexType);
146
147/* -------------------------- Function Implementation ------------------ */
148
149
150/* ========================================================================== */
151/**
152 * @fn AllocateBuffer_JPEGDec - Implements allocatebuffer functionality
153 * @param hComponent - Component handle.
154 * @param pBuffHead - pointer to buffer header structure
155 * @param nPortIndex - Port index
156 * @param pAppPrivate - pointer to application private data
157 * @param nSizeBytes - size of the buffer to allocate
158 * @return: OMX_ERRORTYPE
159 *          OMX_ErrorNone on success
160 *          !OMX_ErrorNone on any failure
161 */
162/* ========================================================================== */
163static OMX_ERRORTYPE AllocateBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
164                                            OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffHead,
165                                            OMX_IN OMX_U32 nPortIndex,
166                                            OMX_IN OMX_PTR pAppPrivate,
167                                            OMX_IN OMX_U32 nSizeBytes)
168{
169    /*VALIDATE INPUT ARGUMENTS*/
170    OMX_COMPONENTTYPE *pHandle = NULL;
171    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
172    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
173    JPEGDEC_PORT_TYPE* pCompPort;
174    OMX_U8 nBufferCount = -1;
175    OMX_ERRORTYPE eError = OMX_ErrorNone;
176
177    OMX_CHECK_PARAM(hComponent);
178    pHandle = (OMX_COMPONENTTYPE *)hComponent;
179    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
180    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
181
182    pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
183    nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
184    pCompPort = pComponentPrivate->pCompPort[nPortIndex];
185
186    OMX_PRINT1(pComponentPrivate->dbg, "Entering function AllocateBuffer_JPEGDec\n");
187
188    OMX_PRBUFFER1(pComponentPrivate->dbg, "In AllocateBuffer_JPEGDec %d %lu %lu\n",
189	    nBufferCount, pPortDef->nBufferCountActual, nPortIndex);
190
191    if (nBufferCount >= pPortDef->nBufferCountActual) {
192        eError = OMX_ErrorInsufficientResources;
193        OMX_PRBUFFER4(pComponentPrivate->dbg, " try to allocate more buffers that the port supports\n");
194	goto EXIT;
195    }
196
197    if (nPortIndex == JPEGDEC_INPUT_PORT) {
198        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, sizeof(OMX_BUFFERHEADERTYPE));
199        OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, OMX_BUFFERHEADERTYPE);
200        OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr = %p\n", pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr);
201        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nOutputPortIndex = OMX_NOPORT;
202        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nInputPortIndex = pPortDef->nPortIndex;
203        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
204        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nVersion = pPortDef->nVersion;
205        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pAppPrivate = pAppPrivate;
206        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nAllocLen = nSizeBytes;
207        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->bAllocbyComponent = OMX_TRUE;
208
209        *pBuffHead = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr;
210
211    }
212    else if (nPortIndex == JPEGDEC_OUTPUT_PORT) {
213
214        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, sizeof(OMX_BUFFERHEADERTYPE));
215        OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, OMX_BUFFERHEADERTYPE);
216        OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBuffCount]->pBufferHdr = %p\n", pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr);
217        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nOutputPortIndex = pPortDef->nPortIndex;
218        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nInputPortIndex = OMX_NOPORT;
219        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nSize = sizeof(OMX_BUFFERHEADERTYPE);
220        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nVersion = pPortDef->nVersion;
221        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pAppPrivate = pAppPrivate;
222        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->nAllocLen = nSizeBytes;
223        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->bAllocbyComponent = OMX_TRUE;
224
225        *pBuffHead = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr;
226
227    }
228    else {
229	eError = OMX_ErrorBadPortIndex;
230	goto EXIT;
231    }
232
233    if (nPortIndex == JPEGDEC_INPUT_PORT) {
234        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer, nSizeBytes + 256);
235        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer = (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer) + 128;
236
237#ifdef __PERF_INSTRUMENTATION__
238        PERF_ReceivedFrame(pComponentPrivate->pPERF,
239                           pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer,
240                           nSizeBytes,
241                           PERF_ModuleMemory);
242#endif
243
244    }
245    else if (nPortIndex == JPEGDEC_OUTPUT_PORT) {
246        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer, nSizeBytes + 256);
247        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer + 128;
248
249#ifdef __PERF_INSTRUMENTATION__
250        PERF_ReceivedFrame(pComponentPrivate->pPERF,
251                           pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr->pBuffer,
252                           nSizeBytes,
253                           PERF_ModuleMemory);
254#endif
255
256    }
257    else {
258	eError = OMX_ErrorBadPortIndex;
259	goto EXIT;
260    }
261
262    eError = Allocate_DSPResources_JPEGDec(pComponentPrivate, nPortIndex);
263    if (eError != OMX_ErrorNone)    {
264	OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorInsufficientResources\n");
265	eError = OMX_ErrorInsufficientResources;
266	goto EXIT;
267    }
268
269    if (nPortIndex == JPEGDEC_INPUT_PORT) {
270        pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->pInputPortPrivate =
271            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount];
272   }
273    else {
274        pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->pOutputPortPrivate =
275            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount];
276    }
277
278    if (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent != NULL) {
279            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->eBufferOwner = JPEGDEC_BUFFER_TUNNEL_COMPONENT;
280        }
281    else {
282            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
283        }
284
285    pComponentPrivate->pCompPort[nPortIndex]->nBuffCount++;
286    if (pComponentPrivate->pCompPort[nPortIndex]->nBuffCount == pPortDef->nBufferCountActual) {
287            pPortDef->bPopulated = OMX_TRUE;
288            JPEGDEC_InitBufferFlagTrack(pComponentPrivate, nPortIndex);
289            pthread_mutex_lock(&(pComponentPrivate->mJpegDecMutex));
290            pthread_cond_signal(&(pComponentPrivate->sPortPopulated_cond));
291            pthread_mutex_unlock(&(pComponentPrivate->mJpegDecMutex));
292	    OMX_PRINT2(pComponentPrivate->dbg, " Port [%lu] Populated!\n", nPortIndex);
293    }
294
295EXIT:
296    return eError;
297}   /* End of AllocateBuffer_JPEGDec */
298
299
300/* ========================================================================== */
301/**
302 * @fn FreeBuffer_JPEGDec - Implements freebuffer functionality
303 * @param hComponent - Component handle.
304 * @param nPortIndex - Port index
305 * @param pBuffHead - pointer to buffer header structure
306 * @return: OMX_ERRORTYPE
307 *          OMX_ErrorNone on success
308 *          !OMX_ErrorNone on any failure
309 */
310/* ========================================================================== */
311static OMX_ERRORTYPE FreeBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
312                                        OMX_IN OMX_U32 nPortIndex,
313                                        OMX_IN OMX_BUFFERHEADERTYPE* pBuffHead)
314{
315    OMX_ERRORTYPE eError = OMX_ErrorNone;
316    OMX_COMPONENTTYPE *pHandle = NULL;
317    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
318    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
319    JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
320    OMX_U8* pTemp;
321    OMX_U8 nBufferCount = -1;
322
323    OMX_CHECK_PARAM(hComponent);
324    OMX_CHECK_PARAM(pBuffHead);
325
326    pHandle = (OMX_COMPONENTTYPE *)hComponent;
327    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
328
329    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
330
331    if (nPortIndex != 1 && nPortIndex != 0) {
332	    eError = OMX_ErrorBadPortIndex;
333	    goto PRINT_EXIT;
334    }
335
336    OMX_PRBUFFER2(pComponentPrivate->dbg, "JPEG-D: Entering funtion FreeBuffer_JPEGDec %lu %p\n", nPortIndex, pBuffHead);
337
338    if(pComponentPrivate->nCurState == OMX_StateLoaded){
339        eError = OMX_ErrorIncorrectStateOperation;
340	goto PRINT_EXIT;
341    }
342    pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
343    nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
344    OMX_PRBUFFER1(pComponentPrivate->dbg, "Trying to Free Header %p\nBuffer %p\n", pBuffHead, pBuffHead->pBuffer);
345
346    if (nPortIndex == JPEGDEC_INPUT_PORT) {
347
348        pBuffPrivate = pBuffHead->pInputPortPrivate;
349        if (pBuffPrivate->pUALGParams) {
350            pTemp = (OMX_U8*)(pBuffPrivate->pUALGParams);
351            pTemp -= 128;
352            (pBuffPrivate->pUALGParams) = (JPEGDEC_UAlgInBufParamStruct *)pTemp;
353            OMX_FREE(pBuffPrivate->pUALGParams);
354            pBuffPrivate->pUALGParams = NULL;
355        }
356    }
357    else if (nPortIndex == JPEGDEC_OUTPUT_PORT) {
358
359        pBuffPrivate = pBuffHead->pOutputPortPrivate;
360        if (pBuffPrivate->pUALGParams) {
361            pTemp = (OMX_U8*)(pBuffPrivate->pUALGParams);
362            pTemp -= 128;
363            (pBuffPrivate->pUALGParams) = (JPEGDEC_UAlgOutBufParamStruct *)pTemp;
364            OMX_FREE(pBuffPrivate->pUALGParams);
365            pBuffPrivate->pUALGParams = NULL;
366        }
367    }
368    else {
369        eError = OMX_ErrorBadPortIndex;
370	goto PRINT_EXIT;
371    }
372
373    if (pBuffPrivate->bAllocbyComponent == OMX_TRUE) {
374        if (pBuffHead->pBuffer) {
375
376#ifdef __PERF_INSTRUMENTATION__
377            PERF_SendingFrame(pComponentPrivate->pPERF,
378                              pBuffHead->pBuffer,
379                              pBuffHead->nFilledLen,
380                              PERF_ModuleMemory);
381#endif
382
383            OMX_PRBUFFER1(pComponentPrivate->dbg, "INTERNAL BUFFER USED , trying to free it.\n");
384            pBuffHead->pBuffer -= 128;
385            OMX_FREE(pBuffHead->pBuffer);
386            pBuffHead->pBuffer = NULL;
387        }
388    }
389
390    if (pBuffHead) {
391        OMX_FREE(pBuffHead);
392        pBuffHead = NULL;
393    }
394
395
396    OMX_PRSTATE2(pComponentPrivate->dbg, "Current state is %d and To State is %d\n", pComponentPrivate->nCurState, pComponentPrivate->nToState);
397        if ( pPortDef->bEnabled &&
398            ((pComponentPrivate->nCurState == OMX_StateIdle && pComponentPrivate->nToState != OMX_StateLoaded) ||
399            (pComponentPrivate->nCurState == OMX_StateExecuting  ||
400            pComponentPrivate->nCurState == OMX_StatePause)) ) {
401
402            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
403                                                    pComponentPrivate->pHandle->pApplicationPrivate,
404                                                    OMX_EventError,
405                                                    OMX_ErrorPortUnpopulated,
406                                                    OMX_TI_ErrorMinor,
407                                                    "Port Unpopulated");
408        }
409
410    nBufferCount = --pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
411
412    OMX_PRBUFFER1(pComponentPrivate->dbg, "nBufferCount %d\n", nBufferCount);
413    if (nBufferCount == 0) {
414        pComponentPrivate->pCompPort[nPortIndex]->pPortDef->bPopulated = OMX_FALSE;
415        OMX_PRBUFFER2(pComponentPrivate->dbg, "port %lu is %u\n", nPortIndex, pComponentPrivate->pCompPort[nPortIndex]->pPortDef->bPopulated);
416        pthread_mutex_lock(&(pComponentPrivate->mJpegDecMutex));
417        pthread_cond_signal(&(pComponentPrivate->sPortPopulated_cond));
418        pthread_mutex_unlock(&(pComponentPrivate->mJpegDecMutex));
419    }
420
421    if ((!pPortDef->bEnabled) &&
422        (!pComponentPrivate->pCompPort[nPortIndex]->pPortDef->bPopulated)) {
423        if ((nPortIndex == 0) && (!pComponentPrivate->bInportDisableComplete)) {
424            pComponentPrivate->bInportDisableComplete = OMX_TRUE;
425            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
426                                                pComponentPrivate->pHandle->pApplicationPrivate,
427                                                OMX_EventCmdComplete,
428                                                OMX_CommandPortDisable,
429                                                0,
430                                                NULL);
431        }
432        if ((nPortIndex == 1) && (!pComponentPrivate->bOutportDisableComplete)) {
433            pComponentPrivate->bOutportDisableComplete = OMX_TRUE;
434            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
435                                                pComponentPrivate->pHandle->pApplicationPrivate,
436                                                OMX_EventCmdComplete,
437                                                OMX_CommandPortDisable,
438                                                1,
439                                                NULL);
440        }
441    }
442PRINT_EXIT:
443    OMX_PRINT1(pComponentPrivate->dbg, "Exit from FreeBuffer function error = %x\n", eError);
444EXIT:
445    return eError;
446}   /* End of FreeBuffer_JPEGDec */
447
448
449/* ========================================================================== */
450/**
451 * @fn UseBuffer_JPEGDec - Implements usebuffer functionality
452 * @param hComponent - Component handle.
453 * @param pBuffHead - pointer to buffer header structure
454 * @param nPortIndex - Port index
455 * @param pAppPrivate - pointer to application private data
456 * @param nSizeBytes - size of the buffer
457 * @param pBuffer - pointer to the buffer
458 * @return: OMX_ERRORTYPE
459 *          OMX_ErrorNone on success
460 *          !OMX_ErrorNone on any failure
461 */
462/* ========================================================================== */
463static OMX_ERRORTYPE UseBuffer_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
464                                        OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
465                                        OMX_IN OMX_U32 nPortIndex,
466                                        OMX_IN OMX_PTR pAppPrivate,
467                                        OMX_IN OMX_U32 nSizeBytes,
468                                        OMX_IN OMX_U8* pBuffer)
469{
470    OMX_COMPONENTTYPE *pHandle = NULL;
471    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
472    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
473    OMX_ERRORTYPE eError = OMX_ErrorNone;
474    OMX_HANDLETYPE hTunnelComponent;
475    OMX_U8 nBufferCount = -1;
476
477    pHandle = (OMX_COMPONENTTYPE *)hComponent;
478    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
479    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
480
481    pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
482    nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
483    hTunnelComponent = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent;
484
485    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion UseBuffer_JPEGDec\n");
486
487#ifdef __PERF_INSTRUMENTATION__
488    PERF_ReceivedFrame(pComponentPrivate->pPERF,
489                       pBuffer,
490                       nSizeBytes,
491                       PERF_ModuleHLMM);
492#endif
493
494
495    if (nPortIndex == JPEGDEC_INPUT_PORT) {
496        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, sizeof(OMX_BUFFERHEADERTYPE));
497        *ppBufferHdr = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr;
498    }
499    else if (nPortIndex == JPEGDEC_OUTPUT_PORT) {
500        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr, sizeof(OMX_BUFFERHEADERTYPE));
501        *ppBufferHdr = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pBufferHdr;
502    }
503    else {
504	eError = OMX_ErrorBadPortIndex;
505	goto EXIT;
506    }
507    pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->bAllocbyComponent = OMX_FALSE;
508
509    /* set relevant fields */
510    (*ppBufferHdr)->nSize = sizeof(OMX_BUFFERHEADERTYPE);
511    (*ppBufferHdr)->nVersion = pPortDef->nVersion;
512    (*ppBufferHdr)->pBuffer = pBuffer;
513    (*ppBufferHdr)->nAllocLen = nSizeBytes;
514    (*ppBufferHdr)->pAppPrivate = pAppPrivate;
515
516    if (hTunnelComponent != NULL) {
517        /* set direction dependent fields */
518        if (pPortDef->eDir == OMX_DirInput) {
519            (*ppBufferHdr)->nInputPortIndex = nPortIndex;
520            (*ppBufferHdr)->nOutputPortIndex = pComponentPrivate->pCompPort[nPortIndex]->nTunnelPort;
521
522            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr = (*ppBufferHdr);
523        }
524        else {
525            (*ppBufferHdr)->nOutputPortIndex   = nPortIndex;
526            (*ppBufferHdr)->nInputPortIndex    = pComponentPrivate->pCompPort[nPortIndex]->nTunnelPort;
527
528            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr = (*ppBufferHdr);
529        }
530    }
531    else {
532        if (nPortIndex == JPEGDEC_INPUT_PORT) {
533            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->nInputPortIndex  = JPEGDEC_INPUT_PORT;
534            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->nOutputPortIndex = OMX_NOPORT;
535        }
536        else {
537            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->nInputPortIndex  = OMX_NOPORT;
538            pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->nOutputPortIndex = JPEGDEC_OUTPUT_PORT;
539        }
540    }
541    if (nPortIndex == JPEGDEC_INPUT_PORT) {
542        pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->pInputPortPrivate =
543                                                     pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount];
544    }
545    else {
546        pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount]->pBufferHdr->pOutputPortPrivate =
547                                                     pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCount];
548    }
549
550    eError = Allocate_DSPResources_JPEGDec(pComponentPrivate, nPortIndex);
551    if (eError != OMX_ErrorNone) {
552	OMX_PRDSP4(pComponentPrivate->dbg, "Error: Allocate_DSPResources_JPEGDec failed\n");
553	eError = OMX_ErrorInsufficientResources;
554	goto EXIT;
555    }
556    /* increment buffer count */
557
558    pComponentPrivate->pCompPort[nPortIndex]->nBuffCount++;
559    if (pComponentPrivate->pCompPort[nPortIndex]->nBuffCount == pPortDef->nBufferCountActual) {
560        pPortDef->bPopulated = OMX_TRUE;
561        JPEGDEC_InitBufferFlagTrack(pComponentPrivate, nPortIndex);
562        pthread_mutex_lock(&(pComponentPrivate->mJpegDecMutex));
563        pthread_cond_signal(&(pComponentPrivate->sPortPopulated_cond));
564        pthread_mutex_unlock(&(pComponentPrivate->mJpegDecMutex));
565    }
566EXIT:
567    return eError;
568}   /* end of UseBuffer_JPEGDec */
569
570
571
572/* ========================================================================== */
573/**
574 * @fn OMX_ComponentInit - Updates the component function pointer to the handle.
575 *  Sets default parameters.
576 * @param hComponent - Component handle.
577 * @return: OMX_ERRORTYPE
578 *          OMX_ErrorNone on success
579 *          !OMX_ErrorNone on any failure
580 */
581/* ========================================================================== */
582OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent)
583{
584
585    OMX_COMPONENTTYPE *pHandle = NULL;
586    OMX_ERRORTYPE eError = OMX_ErrorNone;
587    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
588    OMX_U8 i = 0;
589    OMX_CHECK_PARAM(hComponent);
590    pHandle = (OMX_COMPONENTTYPE *)hComponent;
591
592    LinkedList_Create(&AllocList);
593
594    OMX_MALLOC(pHandle->pComponentPrivate, sizeof(JPEGDEC_COMPONENT_PRIVATE));
595
596    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
597
598    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
599
600    OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_JPEGDEC");
601
602    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion OMX_ComponentInit\n");
603
604#ifdef __PERF_INSTRUMENTATION__
605    pComponentPrivate->pPERF = PERF_Create(PERF_FOURS("JPD "), PERF_ModuleLLMM | PERF_ModuleImageDecode);
606    pComponentPrivate->pPERFcomp = NULL;
607#endif
608
609    ((JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
610    pComponentPrivate->nCurState = OMX_StateLoaded;
611    pComponentPrivate->ComponentVersion.s.nVersionMajor = 0x01;
612    pComponentPrivate->ComponentVersion.s.nVersionMinor = 0x00;
613    pComponentPrivate->ComponentVersion.s.nRevision = 0x00;
614    pComponentPrivate->ComponentVersion.s.nStep = 0x00;
615    OMX_MALLOC(pComponentPrivate->cComponentName, COMP_MAX_NAMESIZE + 1);
616    strncpy(pComponentPrivate->cComponentName, cJPEGdecName, COMP_MAX_NAMESIZE);
617
618    pHandle->SetCallbacks = SetCallbacks_JPEGDec;
619    pHandle->GetComponentVersion = GetComponentVersion_JPEGDec;
620    pHandle->SendCommand = SendCommand_JPEGDec;
621    pHandle->GetParameter = GetParameter_JPEGDec;
622    pHandle->SetParameter = SetParameter_JPEGDec;
623    pHandle->GetConfig = GetConfig_JPEGDec;
624    pHandle->SetConfig = SetConfig_JPEGDec;
625    pHandle->GetState = GetState;
626    pHandle->EmptyThisBuffer = EmptyThisBuffer;
627    pHandle->FillThisBuffer = FillThisBuffer_JPEGDec;
628    pHandle->ComponentTunnelRequest = ComponentTunnelRequest_JPEGDec;
629    pHandle->ComponentDeInit = ComponentDeInit;
630    pHandle->UseBuffer = UseBuffer_JPEGDec;
631    pHandle->FreeBuffer =  FreeBuffer_JPEGDec;
632    pHandle->AllocateBuffer = AllocateBuffer_JPEGDec;
633    pHandle->GetExtensionIndex      = GetExtensionIndex_JPEGDec;
634#ifdef KHRONOS_1_1
635    pHandle->ComponentRoleEnum = ComponentRoleEnum;
636#endif
637
638    /* Allocate memory for component data structures */
639    OMX_MALLOC(pComponentPrivate->pPortParamType, sizeof(OMX_PORT_PARAM_TYPE));
640    OMX_MALLOC(pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
641    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT], sizeof(JPEGDEC_PORT_TYPE));
642    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT], sizeof(JPEGDEC_PORT_TYPE));
643    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pParamBufSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
644    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pParamBufSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
645    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
646    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
647    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
648    OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
649    OMX_MALLOC(pComponentPrivate->pScalePrivate, sizeof(OMX_CONFIG_SCALEFACTORTYPE)); /* Scale Factor */
650    OMX_MALLOC(pComponentPrivate->pSectionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SECTION));
651    OMX_MALLOC(pComponentPrivate->pSubRegionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SUBREGION));
652
653#ifdef KHRONOS_1_1
654    OMX_MALLOC(pComponentPrivate->pAudioPortType, sizeof(OMX_PORT_PARAM_TYPE));
655    OMX_CONF_INIT_STRUCT(pComponentPrivate->pAudioPortType, OMX_PORT_PARAM_TYPE);
656    OMX_MALLOC(pComponentPrivate->pVideoPortType, sizeof(OMX_PORT_PARAM_TYPE));
657    OMX_CONF_INIT_STRUCT(pComponentPrivate->pVideoPortType, OMX_PORT_PARAM_TYPE);
658    OMX_MALLOC(pComponentPrivate->pOtherPortType, sizeof(OMX_PORT_PARAM_TYPE));
659    OMX_CONF_INIT_STRUCT(pComponentPrivate->pOtherPortType, OMX_PORT_PARAM_TYPE);
660    OMX_MALLOC(pComponentPrivate->pCompRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
661    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompRole,OMX_PARAM_COMPONENTROLETYPE);
662    OMX_MALLOC(pComponentPrivate->pQuantTable, sizeof(OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE));
663    OMX_CONF_INIT_STRUCT(pComponentPrivate->pQuantTable,OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE);
664    pComponentPrivate->pQuantTable->eQuantizationTable = OMX_IMAGE_QuantizationTableLuma;
665    OMX_MALLOC(pComponentPrivate->pHuffmanTable, sizeof(OMX_IMAGE_PARAM_HUFFMANTTABLETYPE));
666    OMX_CONF_INIT_STRUCT(pComponentPrivate->pHuffmanTable,OMX_IMAGE_PARAM_HUFFMANTTABLETYPE);
667    pComponentPrivate->pHuffmanTable->eHuffmanTable = OMX_IMAGE_HuffmanTableAC;
668
669    pComponentPrivate->pAudioPortType->nPorts = 0;
670    pComponentPrivate->pAudioPortType->nStartPortNumber = -1;
671    pComponentPrivate->pVideoPortType->nPorts = 0;
672    pComponentPrivate->pVideoPortType->nStartPortNumber = -1;
673    pComponentPrivate->pOtherPortType->nPorts = 0;
674    pComponentPrivate->pOtherPortType->nStartPortNumber = -1;
675
676#endif
677    for (i = 0;i<NUM_OF_BUFFERS;i++) {
678        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[i], sizeof(JPEGDEC_BUFFER_PRIVATE));
679        pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr = NULL;
680    }
681
682    for (i = 0;i<NUM_OF_BUFFERS;i++) {
683        OMX_MALLOC(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[i], sizeof(JPEGDEC_BUFFER_PRIVATE));
684        pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr = NULL;
685    }
686
687    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->hTunnelComponent = NULL;
688    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent = NULL;
689    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->nBuffCount = 0;
690    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->nBuffCount = 0;
691    pComponentPrivate->nProgressive = 0;
692    pComponentPrivate->nInputFrameWidth = 1600;
693    pComponentPrivate->nOutputColorFormat = OMX_COLOR_Format32bitARGB8888;
694    pComponentPrivate->nProfileID = 0;
695    pComponentPrivate->nIsLCMLActive = 0;
696    pComponentPrivate->pDllHandle = NULL;
697    pComponentPrivate->pLCML = NULL;
698    pComponentPrivate->pMarkData = NULL;
699    pComponentPrivate->pMarkBuf = NULL;
700    pComponentPrivate->hMarkTargetComponent = NULL;
701    pComponentPrivate->pHandle->pApplicationPrivate = (OMX_PTR *)200;
702    pComponentPrivate->nInPortIn = 0;
703    pComponentPrivate->nOutPortOut = 0;
704    pComponentPrivate->bPreempted = OMX_FALSE;
705
706/*Slide decoding defaults*/
707    OMX_CONF_INIT_STRUCT(pComponentPrivate->pSectionDecode, OMX_CUSTOM_IMAGE_DECODE_SECTION);
708    pComponentPrivate->pSectionDecode->nMCURow = 0;
709    pComponentPrivate->pSectionDecode->nAU = 0;
710    pComponentPrivate->pSectionDecode->bSectionsInput = 0;
711    pComponentPrivate->pSectionDecode->bSectionsOutput = 0;
712
713    OMX_CONF_INIT_STRUCT(pComponentPrivate->pSubRegionDecode, OMX_CUSTOM_IMAGE_DECODE_SUBREGION);
714    pComponentPrivate->pSubRegionDecode->nXOrg = 0;
715    pComponentPrivate->pSubRegionDecode->nYOrg = 0;
716    pComponentPrivate->pSubRegionDecode->nXLength = 0;
717    pComponentPrivate->pSubRegionDecode->nYLength = 0;
718
719
720    /* Set pPortParamType defaults */
721    OMX_CONF_INIT_STRUCT(pComponentPrivate->pPortParamType, OMX_PORT_PARAM_TYPE);
722    pComponentPrivate->pPortParamType->nPorts = NUM_OF_PORTS;
723    pComponentPrivate->pPortParamType->nStartPortNumber = 0x0;
724
725    /* Set pInPortDef defaults */
726    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
727    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nPortIndex = JPEGDEC_INPUT_PORT;
728    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->eDir = OMX_DirInput;
729    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual = NUM_OF_BUFFERS;
730    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountMin         = 1;
731    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferSize             = 70532;
732    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bEnabled = OMX_TRUE;
733    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bPopulated = OMX_FALSE;
734    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->eDomain = OMX_PortDomainImage;
735    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.cMIMEType = "JPEGDEC";
736    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.pNativeRender = NULL;
737    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.nFrameWidth        = 640 ; /* 128*/
738    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.nFrameHeight       = 480;  /*96 */
739    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.nStride = -1;
740    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.nSliceHeight = -1;
741    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.bFlagErrorConcealment = OMX_FALSE;
742    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.eCompressionFormat         =  OMX_IMAGE_CodingJPEG;
743    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->format.image.eColorFormat           =  OMX_COLOR_FormatUnused;
744
745    /* Set pOutPortDef defaults */
746    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
747    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nPortIndex = JPEGDEC_OUTPUT_PORT;
748    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->eDir = OMX_DirOutput;
749    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountMin        =  1;
750    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual         = NUM_OF_BUFFERS;
751    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferSize            =  (640*480*2);
752    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bEnabled = OMX_TRUE;
753    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bPopulated = OMX_FALSE;
754    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->eDomain = OMX_PortDomainImage;
755    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.cMIMEType = "JPEGDEC";
756    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.pNativeRender = NULL;
757    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.nFrameWidth       =    640;
758    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.nFrameHeight  = 480;
759    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.nStride = -1;
760    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.nSliceHeight = -1;
761    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.bFlagErrorConcealment = OMX_FALSE;
762    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.eCompressionFormat = OMX_IMAGE_CodingUnused;
763    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.image.eColorFormat          =  OMX_COLOR_FormatYUV420PackedPlanar;
764    /* added for vpp tunneling */
765    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYCbYCr;
766
767
768    /* Set pInPortFormat defaults */
769    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, OMX_IMAGE_PARAM_PORTFORMATTYPE);
770    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex = JPEGDEC_INPUT_PORT;
771    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nIndex = 0x0;
772    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->eCompressionFormat   =OMX_IMAGE_CodingJPEG;
773    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->eColorFormat         = OMX_COLOR_FormatUnused;
774
775    /* Set pOutPortFormat defaults */
776    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, OMX_IMAGE_PARAM_PORTFORMATTYPE);
777    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex = JPEGDEC_OUTPUT_PORT;
778    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nIndex = 0x0;
779    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->eCompressionFormat = OMX_IMAGE_CodingUnused;
780    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->eColorFormat        = OMX_COLOR_FormatYUV420PackedPlanar;
781
782    /* Set pPriorityMgmt defaults */
783    OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
784    pComponentPrivate->pPriorityMgmt->nGroupPriority = -1;
785    pComponentPrivate->pPriorityMgmt->nGroupID = -1;
786
787
788    /* Set pInBufSupplier defaults */
789    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pParamBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
790    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pParamBufSupplier->nPortIndex = JPEGDEC_INPUT_PORT;
791    pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pParamBufSupplier->eBufferSupplier = OMX_BufferSupplyInput;
792
793    /* Set pOutBufSupplier defaults */
794    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pParamBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
795    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pParamBufSupplier->nPortIndex = JPEGDEC_OUTPUT_PORT;
796    pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pParamBufSupplier->eBufferSupplier = OMX_BufferSupplyInput;
797
798	/* Set default value for Max width & Height*/
799	pComponentPrivate->sMaxResolution.nWidth = JPGDEC_SNTEST_MAX_WIDTH;
800	pComponentPrivate->sMaxResolution.nHeight = JPGDEC_SNTEST_MAX_HEIGHT;
801
802    /*Initialize Component mutex*/
803    if (pthread_mutex_init(&(pComponentPrivate->mJpegDecMutex), NULL) != 0)
804    {
805	OMX_TRACE4(pComponentPrivate->dbg, "Error at Initialize fill this buffer mutex condition");
806	eError = OMX_ErrorHardware;
807	goto EXIT;
808    }
809
810    /* initialize a condition variable to its default value */
811    if (pthread_cond_init(&(pComponentPrivate->sStop_cond), NULL) != 0)
812    {
813	OMX_TRACE4(pComponentPrivate->dbg, "Error at Initialize fill this buffer mutex condition");
814	eError = OMX_ErrorHardware;
815	goto EXIT;
816    }
817
818#ifdef KHRONOS_1_1
819    strcpy((char *)pComponentPrivate->componentRole.cRole, "image_decoder.jpeg");
820#endif
821
822
823#ifdef RESOURCE_MANAGER_ENABLED
824    /* load the ResourceManagerProxy thread */
825    eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_IMAGE);
826    if (eError != OMX_ErrorNone) {
827	OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from loading ResourceManagerProxy thread: %x\n", eError);
828	goto EXIT;
829    }
830#endif
831
832    eError= Start_ComponentThreadJpegDec(pHandle);
833
834
835EXIT:
836    if(eError != OMX_ErrorNone){
837        /* LinkedList_DisplayAll (&AllocList); */
838        OMX_FREEALL();
839        LinkedList_Destroy(&AllocList);
840    }
841    return eError;
842}   /* End of OMX_ComponentInit */
843/* ========================================================================== */
844/**
845 * @fn SetCallbacks_JPEGDec - Sets application callbacks to the component
846 * @param hComponent - Component handle.
847 * @param pCallBacks - application callbacks
848 * @param pAppData - pointer to application Data
849 * @return: OMX_ERRORTYPE
850 *          OMX_ErrorNone on success
851 *          !OMX_ErrorNone on any failure
852 */
853/* ========================================================================== */
854static OMX_ERRORTYPE SetCallbacks_JPEGDec(OMX_HANDLETYPE pComponent,
855                                          OMX_CALLBACKTYPE* pCallBacks,
856                                          OMX_PTR pAppData)
857{
858    OMX_ERRORTYPE eError = OMX_ErrorNone;
859    OMX_COMPONENTTYPE *pHandle = NULL;
860    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
861
862    OMX_CHECK_PARAM(pComponent);
863
864    pHandle = (OMX_COMPONENTTYPE*)pComponent;
865    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
866
867    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
868
869    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion SetCallbacks_JPEGDec\n");
870
871    if (pCallBacks == NULL) {
872        eError = OMX_ErrorBadParameter;
873        OMX_ERROR5(pComponentPrivate->dbg, "Entering funtion SetCallbacks_JPEGDec\n");
874        goto EXIT;
875    }
876
877    /* Copy the callbacks of the application to the component private  */
878    OMX_MEMCPY_CHECK(&(pComponentPrivate->cbInfo));
879    memcpy(&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
880
881
882    /* copy the application private data to component memory */
883    pHandle->pApplicationPrivate = pAppData;
884    pComponentPrivate->nCurState = OMX_StateLoaded;
885
886EXIT:
887    return eError;
888}   /* End of SetCallbacks_JPEGDec */
889
890
891
892/* ========================================================================== */
893/**
894 * @fn GetComponentVersion_JPEGDec - This method will get the component Version.
895 * @param hComp - handle for this instance of the component
896 * @param pComponentName  - component name
897 * @param pComponentVersion - component version
898 * @param pSpecVersion - OMX specification version
899 * @param pComponentUUID - UUID of the component
900 * @return: OMX_ERRORTYPE
901 *          OMX_ErrorNone on success
902 *          !OMX_ErrorNone on any failure
903 */
904/* ========================================================================== */
905static OMX_ERRORTYPE GetComponentVersion_JPEGDec(OMX_HANDLETYPE hComp,
906                                                 OMX_STRING szComponentName,
907                                                 OMX_VERSIONTYPE* pComponentVersion,
908                                                 OMX_VERSIONTYPE* pSpecVersion,
909                                                 OMX_UUIDTYPE* pComponentUUID)
910{
911    OMX_ERRORTYPE          eError            = OMX_ErrorNone;
912    OMX_COMPONENTTYPE    * pHandle           = NULL;
913    JPEGDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
914    OMX_U8 *pTemp = NULL;
915
916    if (!hComp || !szComponentName || !pComponentVersion || !pSpecVersion || !pComponentUUID) {
917        eError = OMX_ErrorBadParameter;
918        goto EXIT;
919    }
920    pHandle = (OMX_COMPONENTTYPE*)hComp;
921    if (!pHandle->pComponentPrivate) {
922        eError = OMX_ErrorBadParameter;
923        goto EXIT;
924    }
925    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
926
927    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
928
929    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion GetComponentVersion_JPEGDec\n");
930
931    strncpy(szComponentName, pComponentPrivate->cComponentName, COMP_MAX_NAMESIZE);
932    pTemp = memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), sizeof(pComponentPrivate->ComponentVersion.s));
933    if(pTemp == NULL){
934        eError = OMX_ErrorUndefined;
935        goto EXIT;
936    }
937    pTemp = memcpy(pSpecVersion, &(pComponentPrivate->SpecVersion.s), sizeof(pComponentPrivate->SpecVersion.s));
938    if(pTemp == NULL){
939        eError = OMX_ErrorUndefined;
940        goto EXIT;
941    }
942EXIT:
943    return eError;
944}/* End of GetComponentVersion_JPEGDec */
945
946/* ========================================================================== */
947/**
948 * @fn SendCommand_JPEGDec - Sends command from application to component
949 * @param hComponent - handle for this instance of the component
950 * @param Cmd - Command to be sent
951 * @param nParam - Command parameters
952 * @param pCmdData - Additional Command data
953 * @return: OMX_ERRORTYPE
954 *          OMX_ErrorNone on success
955 *          !OMX_ErrorNone on any failure
956 */
957/* ========================================================================== */
958static OMX_ERRORTYPE SendCommand_JPEGDec(OMX_HANDLETYPE hComponent,
959                                         OMX_COMMANDTYPE Cmd,
960                                         OMX_U32 nParam,
961                                         OMX_PTR pCmdData)
962{
963    OMX_ERRORTYPE eError = OMX_ErrorNone;
964    OMX_COMPONENTTYPE *pHandle = NULL;
965    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
966    OMX_PARAM_PORTDEFINITIONTYPE *pPortDefIn= NULL;
967    OMX_PARAM_PORTDEFINITIONTYPE *pPortDefOut = NULL;
968    OMX_MARKTYPE* pMarkType = NULL;
969    OMX_COMMANDTYPE eCmd = OMX_CustomCommandStopThread;
970    int nRet = 0;
971
972    OMX_CHECK_PARAM(hComponent);
973    pHandle = (OMX_COMPONENTTYPE *)hComponent;
974    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
975    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
976
977    pPortDefIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef;
978    pPortDefOut = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef;
979
980    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion SendCommand_JPEGDec %u %lu\n", Cmd, nParam);
981
982    if (pComponentPrivate->nCurState == OMX_StateInvalid) {
983	OMX_PRSTATE4(pComponentPrivate->dbg, "INVALID STATE\n");
984        eError = OMX_ErrorInvalidState;
985        goto EXIT;
986    }
987    switch (Cmd) {
988
989    case OMX_CommandStateSet:
990        eCmd = OMX_CommandStateSet;
991            pComponentPrivate->nToState = nParam;
992            OMX_PRSTATE2(pComponentPrivate->dbg, "To state %d\n", pComponentPrivate->nToState);
993        break;
994
995    case OMX_CommandFlush:
996        if ((nParam != JPEGDEC_INPUT_PORT) &&
997            (nParam != JPEGDEC_OUTPUT_PORT) &&
998	    ((int)nParam != -1)) {
999            eError = OMX_ErrorBadPortIndex;
1000            goto EXIT;
1001        }
1002        eCmd = OMX_CommandFlush;
1003        OMX_PRBUFFER2(pComponentPrivate->dbg, "get OMX_CommandFlush\n");
1004        break;
1005
1006    case OMX_CommandPortDisable:
1007	    OMX_PRBUFFER2(pComponentPrivate->dbg, "Get port disable command %lu\n", nParam);
1008	if (nParam == JPEGDEC_INPUT_PORT  || (int)nParam == -1) {
1009            pPortDefIn->bEnabled = OMX_FALSE;
1010            pComponentPrivate->bInportDisableComplete = OMX_FALSE;
1011            OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDefIn->bEnabled %d\n", pPortDefIn->bEnabled);
1012        }
1013        if (nParam == JPEGDEC_OUTPUT_PORT  || (int)nParam == -1) {
1014                pPortDefOut->bEnabled = OMX_FALSE;
1015                pComponentPrivate->bOutportDisableComplete = OMX_FALSE;
1016                OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDefIn->bEnabled %d\n", pPortDefIn->bEnabled);
1017        }
1018        if ((nParam != JPEGDEC_INPUT_PORT) && (nParam != JPEGDEC_OUTPUT_PORT) && ((int)nParam != -1)) {
1019            eError = OMX_ErrorBadParameter;
1020            OMX_PRBUFFER4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
1021            goto EXIT;
1022        }
1023
1024        if (!pPortDefIn->bPopulated) {
1025            pComponentPrivate->bInportDisableComplete = OMX_TRUE;
1026            OMX_PRBUFFER2(pComponentPrivate->dbg, "JPEGDEC_INPUT_PORT: OMX_CommandPortDisable\n");
1027            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
1028                                               pComponentPrivate->pHandle->pApplicationPrivate,
1029                                               OMX_EventCmdComplete,
1030                                               OMX_CommandPortDisable,
1031                                               JPEGDEC_INPUT_PORT,
1032                                               NULL);
1033        }
1034
1035        if (!pPortDefOut->bPopulated) {
1036            pComponentPrivate->bOutportDisableComplete = OMX_TRUE;
1037            OMX_PRBUFFER1(pComponentPrivate->dbg, "JPEGDEC_OUTPUT_PORT : OMX_CommandPortDisable\n");
1038            pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
1039                            pComponentPrivate->pHandle->pApplicationPrivate,
1040                            OMX_EventCmdComplete,
1041                            OMX_CommandPortDisable,
1042                            JPEGDEC_OUTPUT_PORT,
1043                            NULL);
1044        }
1045        eCmd = OMX_CommandPortDisable;
1046        break;
1047
1048    case OMX_CommandPortEnable:
1049	if (nParam == JPEGDEC_INPUT_PORT  || (int)nParam == -1) {
1050                pPortDefIn->bEnabled = OMX_TRUE;
1051        }
1052        if (nParam == JPEGDEC_OUTPUT_PORT  || (int)nParam == -1) {
1053                    pPortDefOut->bEnabled = OMX_TRUE;
1054        }
1055        if ((nParam != JPEGDEC_INPUT_PORT) && (nParam != JPEGDEC_OUTPUT_PORT) && ((int)nParam != -1)) {
1056            eError = OMX_ErrorBadParameter;
1057            goto EXIT;
1058        }
1059        eCmd = OMX_CommandPortEnable;
1060        break;
1061
1062    case OMX_CommandMarkBuffer:
1063	    OMX_PRBUFFER2(pComponentPrivate->dbg, "JPEGDEC: Entered switch - Command Mark Buffer\n");
1064        eCmd = OMX_CommandMarkBuffer;
1065        /* we can only mark buffers on input port */
1066        if ( nParam != JPEGDEC_INPUT_PORT && nParam != JPEGDEC_OUTPUT_PORT){
1067            eError = OMX_ErrorBadPortIndex;
1068            goto EXIT;
1069        }
1070        pMarkType =(OMX_MARKTYPE*)pCmdData;
1071        pComponentPrivate->pMarkData = pMarkType->pMarkData;
1072        pComponentPrivate->hMarkTargetComponent = pMarkType->hMarkTargetComponent;
1073        pComponentPrivate->nMarkPort = nParam;
1074        break;
1075
1076    default:
1077        break;
1078    }
1079
1080    OMX_PRINT1(pComponentPrivate->dbg, "JPEGDEC: eCmd = %d\n",(int)eCmd);
1081
1082#ifdef __PERF_INSTRUMENTATION__
1083    PERF_SendingCommand(pComponentPrivate->pPERF,
1084                        eCmd, (eCmd == OMX_CommandMarkBuffer) ? (OMX_U32) pCmdData : nParam,
1085                        PERF_ModuleComponent);
1086#endif
1087
1088    nRet = write(pComponentPrivate->nCmdPipe[1], &eCmd, sizeof(eCmd));
1089    if (nRet == -1) {
1090	    OMX_PRCOMM4(pComponentPrivate->dbg, "Failed to write into nCmdPipe\n");
1091    }
1092
1093    /* this needs to be fixed */
1094    /* port index is redundant for mark buffer as we have 1 input port */
1095    if (eCmd == OMX_CommandMarkBuffer) {
1096        nRet = write(pComponentPrivate->nCmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
1097        if (nRet == -1) {
1098		OMX_PRCOMM4(pComponentPrivate->dbg, "Failed to write into nCmdDataPipe, eCmd = MarkBuf\n");
1099        }
1100    }
1101    else {
1102        nRet = write(pComponentPrivate->nCmdDataPipe[1], &nParam, sizeof(nParam));
1103        OMX_PRCOMM2(pComponentPrivate->dbg, "write param %lu to pipe\n", nParam);
1104        if (nRet == -1) {
1105		OMX_PRCOMM4(pComponentPrivate->dbg, "Failed to write into nCmdDataPipe\n");
1106        }
1107    }
1108
1109EXIT:
1110    return eError;
1111}   /* End of SendCommand_JPEGDec*/
1112
1113
1114
1115/* ========================================================================== */
1116/**
1117 * @fn GetParameter_JPEGDec - Gets Parameters from the Component.
1118 *  This method will update parameters from the component to the app.
1119 * @param hComponent - handle for this instance of the component
1120 * @param nParamIndex - Component Index Port
1121 * @param ComponentParameterStructure - Component Parameter Structure
1122 * @return: OMX_ERRORTYPE
1123 *          OMX_ErrorNone on success
1124 *          !OMX_ErrorNone on any failure
1125 */
1126/* ========================================================================== */
1127static OMX_ERRORTYPE GetParameter_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
1128                                          OMX_IN OMX_INDEXTYPE nParamIndex,
1129                                          OMX_INOUT OMX_PTR ComponentParameterStructure)
1130{
1131    OMX_ERRORTYPE eError = OMX_ErrorNone;
1132    OMX_COMPONENTTYPE *pComp = NULL;
1133    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1134
1135    OMX_CHECK_PARAM(hComponent);
1136    OMX_CHECK_PARAM(ComponentParameterStructure);
1137    pComp = (OMX_COMPONENTTYPE *)hComponent;
1138    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pComp->pComponentPrivate;
1139
1140    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1141
1142    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion GetParameter_JPEGDec\n");
1143
1144    if (pComponentPrivate->nCurState == OMX_StateInvalid) {
1145        eError = OMX_ErrorIncorrectStateOperation;
1146        goto PRINT_EXIT;
1147    }
1148
1149    switch (nParamIndex) {
1150#ifdef KHRONOS_1_1
1151        case OMX_IndexParamAudioInit:
1152            memcpy(ComponentParameterStructure, pComponentPrivate->pAudioPortType, sizeof(OMX_PORT_PARAM_TYPE));
1153            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1154
1155            break;
1156
1157        case OMX_IndexParamVideoInit:
1158            memcpy(ComponentParameterStructure, pComponentPrivate->pVideoPortType, sizeof(OMX_PORT_PARAM_TYPE));
1159            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1160
1161            break;
1162
1163        case OMX_IndexParamOtherInit:
1164            memcpy(ComponentParameterStructure, pComponentPrivate->pOtherPortType, sizeof(OMX_PORT_PARAM_TYPE));
1165            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1166
1167            break;
1168#endif
1169    case OMX_IndexParamImageInit:
1170        memcpy(ComponentParameterStructure, pComponentPrivate->pPortParamType, sizeof(OMX_PORT_PARAM_TYPE));
1171        OMX_MEMCPY_CHECK(ComponentParameterStructure);
1172        break;
1173
1174    case OMX_IndexParamPortDefinition:
1175		OMX_PRINT1(pComponentPrivate->dbg, "get param %lu\n", ((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex);
1176		OMX_PRINT1(pComponentPrivate->dbg, " port 0 enable: %d\n", pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bEnabled);
1177        OMX_PRINT1(pComponentPrivate->dbg, " port 1 enable: %d\n", pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bEnabled);
1178       if (((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nPortIndex) {
1179            memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1180        }
1181        else if (((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nPortIndex) {
1182            memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1183        }
1184        else {
1185            eError = OMX_ErrorBadPortIndex;
1186        }
1187        break;
1188
1189    case OMX_IndexParamImagePortFormat:
1190        if (((OMX_IMAGE_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==  pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex) {
1191            if (((OMX_IMAGE_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nIndex) {
1192                eError = OMX_ErrorNoMore;
1193            }
1194            else {
1195                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
1196            }
1197        }
1198        else if (((OMX_IMAGE_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex) {
1199            if (((OMX_IMAGE_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nIndex) {
1200                eError = OMX_ErrorNoMore;
1201            }
1202            else {
1203                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
1204
1205            }
1206        }
1207        else {
1208            eError = OMX_ErrorBadPortIndex;
1209        }
1210        break;
1211
1212    case OMX_IndexParamPriorityMgmt:
1213        memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
1214        break;
1215
1216    case OMX_IndexParamCompBufferSupplier:
1217    {
1218        OMX_PARAM_BUFFERSUPPLIERTYPE *pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
1219        if (pBuffSupplierParam->nPortIndex == 1) {
1220            pBuffSupplierParam->eBufferSupplier = pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->pParamBufSupplier->eBufferSupplier;
1221        }
1222        else if (pBuffSupplierParam->nPortIndex == 0) {
1223            pBuffSupplierParam->eBufferSupplier = pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->pParamBufSupplier->eBufferSupplier;
1224        }
1225        else {
1226            eError = OMX_ErrorBadPortIndex;
1227        }
1228        break;
1229    }
1230
1231#ifdef KHRONOS_1_1
1232
1233    case OMX_IndexParamQuantizationTable:
1234            {
1235                memcpy(ComponentParameterStructure, pComponentPrivate->pQuantTable, sizeof(OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE));
1236                OMX_MEMCPY_CHECK(ComponentParameterStructure);
1237        }
1238    break;
1239
1240    case OMX_IndexParamHuffmanTable:
1241                    {
1242                memcpy(ComponentParameterStructure, pComponentPrivate->pHuffmanTable, sizeof(OMX_IMAGE_PARAM_HUFFMANTTABLETYPE));
1243                OMX_MEMCPY_CHECK(ComponentParameterStructure);
1244        }
1245    break;
1246
1247#endif
1248    case OMX_IndexCustomSectionDecode:
1249        {
1250            memcpy(ComponentParameterStructure, pComponentPrivate->pSectionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SECTION));
1251            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1252        }
1253    break;
1254
1255    case OMX_IndexCustomSubRegionDecode:
1256        {
1257            memcpy(ComponentParameterStructure, pComponentPrivate->pSubRegionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SUBREGION));
1258            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1259        }
1260    break;
1261
1262	case OMX_IndexCustomSetMaxResolution:
1263		{
1264            memcpy(ComponentParameterStructure, &(pComponentPrivate->sMaxResolution), sizeof(OMX_CUSTOM_RESOLUTION));
1265            OMX_MEMCPY_CHECK(ComponentParameterStructure);
1266		}
1267		break;
1268
1269    default:
1270        eError = OMX_ErrorUnsupportedIndex;
1271        break;
1272    }
1273
1274PRINT_EXIT:
1275    OMX_PRINT1(pComponentPrivate->dbg, "EXIT\n");
1276EXIT:
1277    return eError;
1278}   /* End of GetParameter_JPEGDec */
1279
1280
1281
1282/* ========================================================================== */
1283/**
1284 * @fn SetParameter_JPEGDec - Sets the parameters sent by the Application and
1285 *  sets it to the component
1286 * @param hComponent - handle for this instance of the component
1287 * @param nParamIndex - Component Index Port
1288 * @param ComponentParameterStructure - Component Parameter Structure to set
1289 * @return: OMX_ERRORTYPE
1290 *          OMX_ErrorNone on success
1291 *          !OMX_ErrorNone on any failure
1292 */
1293/* ========================================================================== */
1294static OMX_ERRORTYPE SetParameter_JPEGDec(OMX_HANDLETYPE hComponent,
1295                                          OMX_INDEXTYPE nParamIndex,
1296                                          OMX_PTR pCompParam)
1297{
1298    OMX_COMPONENTTYPE* pHandle = NULL;
1299    OMX_ERRORTYPE eError = OMX_ErrorNone;
1300    JPEGDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1301
1302    OMX_CHECK_PARAM(hComponent);
1303    OMX_CHECK_PARAM(pCompParam);
1304
1305    pHandle = (OMX_COMPONENTTYPE*)hComponent;
1306    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
1307
1308    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1309
1310    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion SetParameter_JPEGDec\n");
1311
1312    if (pComponentPrivate->nCurState != OMX_StateLoaded) {
1313        eError = OMX_ErrorIncorrectStateOperation;
1314        goto EXIT;
1315    }
1316
1317    switch (nParamIndex) {
1318#ifdef KHRONOS_1_1
1319    case OMX_IndexParamAudioPortFormat:
1320        {
1321            OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
1322            if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex ) {
1323                memcpy(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
1324                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat);
1325            }
1326            else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
1327                memcpy(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
1328                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat);
1329            }
1330            else {
1331                eError = OMX_ErrorBadPortIndex;
1332            }
1333
1334            break;
1335        }
1336
1337    case OMX_IndexParamVideoPortFormat:
1338        {
1339            OMX_VIDEO_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pCompParam;
1340            if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex ) {
1341                memcpy(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1342                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat);
1343            }
1344            else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
1345                memcpy(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
1346                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat);
1347            }
1348            else {
1349                eError = OMX_ErrorBadPortIndex;
1350            }
1351
1352            break;
1353        }
1354
1355    case OMX_IndexParamOtherPortFormat:
1356        {
1357            OMX_OTHER_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_OTHER_PARAM_PORTFORMATTYPE *)pCompParam;
1358            if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex ) {
1359                memcpy(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
1360                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat);
1361            }
1362            else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
1363                memcpy(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
1364                OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat);
1365            }
1366            else {
1367                eError = OMX_ErrorBadPortIndex;
1368            }
1369
1370            break;
1371        }
1372#endif
1373    case OMX_IndexParamImagePortFormat:
1374    {
1375        OMX_IMAGE_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_IMAGE_PARAM_PORTFORMATTYPE *)pCompParam;
1376        if (pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat->nPortIndex) {
1377            OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat);
1378            memcpy(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
1379        }
1380        else if (pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat->nPortIndex) {
1381            OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat);
1382            memcpy(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
1383        }
1384        else {
1385            eError = OMX_ErrorBadPortIndex;
1386        }
1387        break;
1388    }
1389
1390    case OMX_IndexParamImageInit:
1391        OMX_MEMCPY_CHECK(pComponentPrivate->pPortParamType);
1392        memcpy(pComponentPrivate->pPortParamType, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
1393        break;
1394
1395    case OMX_IndexParamPortDefinition:
1396    {
1397        OMX_PARAM_PORTDEFINITIONTYPE* pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
1398        if (pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nPortIndex) {
1399            OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef);
1400            memcpy(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef, pComponentParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1401        }
1402        else if (pComponentParam->nPortIndex == pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nPortIndex) {
1403            OMX_MEMCPY_CHECK(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef);
1404            memcpy(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef, pComponentParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
1405        }
1406        else {
1407            eError = OMX_ErrorBadPortIndex;
1408        }
1409        break;
1410    }
1411
1412    case OMX_IndexParamPriorityMgmt:
1413        OMX_MEMCPY_CHECK(pComponentPrivate->pPriorityMgmt);
1414        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
1415        break;
1416
1417    case OMX_IndexParamCompBufferSupplier:
1418    {
1419        OMX_PARAM_BUFFERSUPPLIERTYPE *pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE *)pCompParam;
1420
1421        if (pBuffSupplierParam->nPortIndex == 1)    {
1422            /* Copy parameters to input port buffer supplier type */
1423            pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->pParamBufSupplier->eBufferSupplier= pBuffSupplierParam->eBufferSupplier;
1424        }
1425        else if (pBuffSupplierParam->nPortIndex == 0) {
1426            pComponentPrivate->pCompPort[pBuffSupplierParam->nPortIndex]->pParamBufSupplier->eBufferSupplier = pBuffSupplierParam->eBufferSupplier;
1427        }
1428        else {
1429            eError = OMX_ErrorBadPortIndex;
1430            break;
1431        }
1432        break;
1433    }
1434#ifdef KHRONOS_1_1
1435
1436    case OMX_IndexParamQuantizationTable:
1437            {
1438                OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE* pQuantizationTable = (OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE*)pCompParam;
1439                OMX_MEMCPY_CHECK(pQuantizationTable);
1440                OMX_MEMCPY_CHECK(pComponentPrivate->pQuantTable);
1441                memcpy(pComponentPrivate->pQuantTable, pQuantizationTable, sizeof(OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE));
1442        }
1443    break;
1444
1445    case OMX_IndexParamStandardComponentRole:
1446            {
1447                OMX_PARAM_COMPONENTROLETYPE* pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
1448                OMX_MEMCPY_CHECK(pRole);
1449                OMX_MEMCPY_CHECK(pComponentPrivate->pCompRole);
1450                memcpy(pComponentPrivate->pCompRole, pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE ));
1451        }
1452    break;
1453
1454
1455    case OMX_IndexParamHuffmanTable:
1456                    {
1457                OMX_IMAGE_PARAM_HUFFMANTTABLETYPE* pHuffmanTable = (OMX_IMAGE_PARAM_HUFFMANTTABLETYPE *)pCompParam;
1458                OMX_MEMCPY_CHECK(pHuffmanTable);
1459                OMX_MEMCPY_CHECK(pComponentPrivate->pHuffmanTable);
1460                memcpy(pComponentPrivate->pHuffmanTable, pHuffmanTable, sizeof(OMX_IMAGE_PARAM_HUFFMANTTABLETYPE ));
1461        }
1462    break;
1463
1464#endif
1465
1466    case OMX_IndexCustomSectionDecode:
1467        {
1468            OMX_CUSTOM_IMAGE_DECODE_SECTION* pSectionDecode = pCompParam;
1469            OMX_MEMCPY_CHECK(pSectionDecode);
1470            OMX_MEMCPY_CHECK(pComponentPrivate->pSectionDecode);
1471            memcpy(pComponentPrivate->pSectionDecode, pSectionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SECTION));
1472        }
1473    break;
1474
1475    case OMX_IndexCustomSubRegionDecode:
1476        {
1477            OMX_CUSTOM_IMAGE_DECODE_SUBREGION* pSubRegionDecode = pCompParam;
1478            OMX_MEMCPY_CHECK(pSubRegionDecode);
1479            OMX_MEMCPY_CHECK(pComponentPrivate->pSubRegionDecode);
1480            memcpy(pComponentPrivate->pSubRegionDecode, pSubRegionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SUBREGION));
1481        }
1482    break;
1483
1484	case OMX_IndexCustomSetMaxResolution:
1485		{
1486			OMX_MEMCPY_CHECK(pCompParam);
1487            memcpy(&(pComponentPrivate->sMaxResolution), pCompParam, sizeof(OMX_CUSTOM_RESOLUTION));
1488		}
1489		break;
1490
1491
1492    default:
1493        eError = OMX_ErrorUnsupportedIndex;
1494        break;
1495    }
1496
1497EXIT:
1498    return eError;
1499}   /* End of SetParameter_JPEGDec */
1500
1501
1502
1503/* ========================================================================== */
1504/**
1505 * @fn GetConfig_JPEGDec - Gets Configuration data from the Component
1506 * @param hComp - handle for this instance of the component
1507 * @param nConfigIndex - Component Config Index Port
1508 * @param ComponentConfigStructure - Component Config Structure
1509 * @return: OMX_ERRORTYPE
1510 *          OMX_ErrorNone on success
1511 *          !OMX_ErrorNone on any failure
1512 */
1513/* ========================================================================== */
1514static OMX_ERRORTYPE GetConfig_JPEGDec(OMX_HANDLETYPE hComp,
1515                                       OMX_INDEXTYPE nConfigIndex,
1516                                       OMX_PTR ComponentConfigStructure)
1517{
1518    OMX_ERRORTYPE eError = OMX_ErrorNone;
1519    OMX_COMPONENTTYPE* pHandle = NULL;
1520    JPEGDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1521
1522    OMX_CHECK_PARAM(hComp);
1523    OMX_CHECK_PARAM(ComponentConfigStructure);
1524    pHandle = (OMX_COMPONENTTYPE*)hComp;
1525    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
1526
1527    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1528
1529    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion GetConfig_JPEGDec\n");
1530
1531    switch (nConfigIndex) {
1532
1533    case OMX_IndexConfigCommonScale:
1534    {
1535        int scale=0;
1536        OMX_CONFIG_SCALEFACTORTYPE* pScaleFactor = (OMX_CONFIG_SCALEFACTORTYPE *)ComponentConfigStructure;
1537        memcpy(pScaleFactor, pComponentPrivate->pScalePrivate, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
1538
1539        scale =(int)pScaleFactor->xWidth;
1540
1541        switch (scale)
1542        {
1543        case (0):
1544            pScaleFactor->xWidth = 100;
1545            break;
1546
1547        case (1):
1548            pScaleFactor->xWidth = 50;
1549            break;
1550
1551        case (2):
1552            pScaleFactor->xWidth = 25;
1553            break;
1554
1555        case (3):
1556            pScaleFactor->xWidth = 12;
1557            break;
1558
1559        case (4):
1560            pScaleFactor->xWidth = 200;
1561            break;
1562
1563        case (5):
1564            pScaleFactor->xWidth = 400;
1565            break;
1566
1567        case (6):
1568            pScaleFactor->xWidth = 800;
1569            break;
1570
1571        default:
1572            pScaleFactor->xWidth = 100;
1573            break;
1574        }
1575        break;
1576    }
1577
1578    case OMX_IndexCustomProgressiveFactor:
1579    {
1580        int *pnProgressiveFlag = (int*)ComponentConfigStructure;
1581        pnProgressiveFlag = (int*)pComponentPrivate->nProgressive;
1582        break;
1583    }
1584
1585    case OMX_IndexCustomDebug:
1586    {
1587	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1588	break;
1589    }
1590
1591    default:
1592        eError = OMX_ErrorUnsupportedIndex;
1593        break;
1594    }
1595
1596EXIT:
1597    return eError;
1598}   /* End of GetConfig_JPEGDec */
1599
1600
1601
1602/* ========================================================================== */
1603/**
1604 * @fn SetConfig_JPEGDec - Sends command to set new configuration
1605 * @param hComp - handle for this instance of the component
1606 * @param nConfigIndex - Component Config Index Port
1607 * @param ComponentConfigStructure - Component Config Structure
1608 * @return: OMX_ERRORTYPE
1609 *          OMX_ErrorNone on success
1610 *          !OMX_ErrorNone on any failure
1611 */
1612/* ========================================================================== */
1613static OMX_ERRORTYPE SetConfig_JPEGDec(OMX_HANDLETYPE hComp,
1614                                       OMX_INDEXTYPE nConfigIndex,
1615                                       OMX_PTR ComponentConfigStructure)
1616{
1617    OMX_ERRORTYPE eError = OMX_ErrorNone;
1618    OMX_COMPONENTTYPE* pHandle = NULL;
1619    JPEGDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1620
1621    OMX_CHECK_PARAM(hComp);
1622    OMX_CHECK_PARAM(ComponentConfigStructure);
1623    pHandle = (OMX_COMPONENTTYPE*)hComp;
1624    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
1625
1626    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1627
1628    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion SetConfig_JPEGDec\n");
1629
1630    switch (nConfigIndex) {
1631
1632    case OMX_IndexConfigCommonScale:
1633    {
1634        int scale=0;
1635        OMX_CONFIG_SCALEFACTORTYPE* pScaleFactor = (OMX_CONFIG_SCALEFACTORTYPE *)ComponentConfigStructure;
1636        scale =(int)pScaleFactor->xWidth;
1637
1638        switch (scale)
1639        {
1640        case (800):
1641            pScaleFactor->xWidth = 6;
1642            break;
1643
1644        case (400):
1645            pScaleFactor->xWidth = 5;
1646            break;
1647
1648        case (200):
1649            pScaleFactor->xWidth = 4;
1650            break;
1651
1652        case (100):
1653            pScaleFactor->xWidth = 0;
1654            break;
1655
1656        case (50):
1657            pScaleFactor->xWidth = 1;
1658            break;
1659
1660        case (25):
1661            pScaleFactor->xWidth = 2;
1662            break;
1663
1664        case (12):
1665            pScaleFactor->xWidth = 3;
1666            break;
1667
1668        default:
1669            pScaleFactor->xWidth = 0;
1670            break;
1671        }
1672
1673        OMX_MEMCPY_CHECK(pComponentPrivate->pScalePrivate);
1674        memcpy(pComponentPrivate->pScalePrivate, pScaleFactor, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
1675        break;
1676    }
1677
1678    case OMX_IndexCustomProgressiveFactor:
1679    {
1680        int *pnProgressive = (int*)ComponentConfigStructure;
1681        pComponentPrivate->nProgressive = (int)*pnProgressive;
1682        break;
1683    }
1684
1685    case OMX_IndexCustomInputFrameWidth:
1686    {
1687        int *pnInputFrameWidth = (int*)ComponentConfigStructure;
1688        pComponentPrivate->nInputFrameWidth = (int)*pnInputFrameWidth;
1689        break;
1690    }
1691
1692    case OMX_IndexCustomOutputColorFormat:
1693    {
1694        int *pnOutputColorFormat = (int*)ComponentConfigStructure;
1695        pComponentPrivate->nOutputColorFormat = (int)*pnOutputColorFormat;
1696        break;
1697    }
1698
1699    case OMX_IndexCustomDebug:
1700    {
1701	OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1702	break;
1703    }
1704    default:
1705        eError = OMX_ErrorUnsupportedIndex;
1706        break;
1707    }
1708EXIT:
1709    return eError;
1710}   /* End of SetConfig_JPEGDec */
1711
1712
1713
1714/* ========================================================================== */
1715/**
1716 * @fn GetState - Gets OMX Component State
1717 * @param hComp - handle for this instance of the component
1718 * @param pState - pointer to store State
1719 * @return: OMX_ERRORTYPE
1720 *          OMX_ErrorNone on success
1721 *          !OMX_ErrorNone on any failure
1722 */
1723/* ========================================================================== */
1724static OMX_ERRORTYPE GetState(OMX_HANDLETYPE pComponent,
1725                              OMX_STATETYPE* pState)
1726{
1727    OMX_ERRORTYPE eError = 80001012;
1728    OMX_COMPONENTTYPE *pHandle = NULL;
1729    OMX_CHECK_PARAM(pComponent);
1730    pHandle = (OMX_COMPONENTTYPE *)pComponent;
1731    JPEGDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1732    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
1733
1734    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1735
1736    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion GetState\n");
1737
1738    if (!pState) {
1739        eError = OMX_ErrorBadParameter;
1740        goto EXIT;
1741    }
1742    if (pHandle && pHandle->pComponentPrivate) {
1743        *pState = ((JPEGDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->nCurState;
1744    }
1745    else {
1746        *pState = OMX_StateLoaded;
1747    }
1748
1749    eError = OMX_ErrorNone;
1750
1751EXIT:
1752    return eError;
1753}   /* End of GetState */
1754
1755
1756/* ========================================================================== */
1757/**
1758 * @fn EmptyThisBuffer - Send Input Buffers.   * The application uses this to
1759 *  send the input buffers filled with data to the input port of the component.
1760 * @param hComponent - handle for this instance of the component
1761 * @param pBuffHead - Pointer to data filled
1762 * @return: OMX_ERRORTYPE
1763 *          OMX_ErrorNone on success
1764 *          !OMX_ErrorNone on any failure
1765 */
1766/* ========================================================================== */
1767static OMX_ERRORTYPE EmptyThisBuffer(OMX_HANDLETYPE hComponent,
1768                                     OMX_BUFFERHEADERTYPE* pBuffHead)
1769{
1770    OMX_ERRORTYPE eError = OMX_ErrorNone;
1771    OMX_COMPONENTTYPE *pHandle = NULL;
1772    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1773    JPEGDEC_BUFFER_PRIVATE* pBuffPrivate;
1774    int nRet;
1775    int i;
1776
1777    OMX_CHECK_PARAM(hComponent);
1778    pHandle = (OMX_COMPONENTTYPE *)hComponent;
1779    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1780
1781    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1782
1783    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion EmptyThisBuffer %p\n", pBuffHead);
1784
1785    if ( pComponentPrivate->nCurState != OMX_StateExecuting &&
1786        pComponentPrivate->nCurState != OMX_StatePause &&
1787        pComponentPrivate->nCurState != OMX_StateIdle) {
1788        eError= OMX_ErrorIncorrectStateOperation;
1789        goto EXIT;
1790    }
1791
1792    if (pBuffHead == NULL) {
1793        eError = OMX_ErrorBadParameter;
1794        goto EXIT;
1795    }
1796
1797    if (pBuffHead->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1798        eError = OMX_ErrorBadParameter;
1799        goto EXIT;
1800    }
1801    if (!pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bEnabled) {
1802        eError = OMX_ErrorIncorrectStateOperation;
1803        goto EXIT;
1804    }
1805
1806    pBuffPrivate = pBuffHead->pInputPortPrivate;
1807
1808    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nAllocLen = %d\n",(int)pBuffHead->nAllocLen);
1809    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen = %d\n",(int)pBuffHead->nFilledLen);
1810    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFlags = %d\n",(int)pBuffHead->nFlags);
1811
1812    if ((pBuffHead->nVersion.s.nVersionMajor != 0x1) ||
1813        (pBuffHead->nVersion.s.nVersionMinor != 0x0) ||
1814        (pBuffHead->nVersion.s.nRevision != 0x0) ||
1815        (pBuffHead->nVersion.s.nStep != 0x0)) {
1816
1817        eError= OMX_ErrorVersionMismatch;
1818        goto EXIT;
1819    }
1820
1821    if (pBuffHead->nInputPortIndex != 0x0) {
1822        eError= OMX_ErrorBadPortIndex;
1823        goto EXIT;
1824    }
1825    pComponentPrivate->nInPortIn ++;
1826
1827    if (pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) {
1828	for (i = 0; i < (int)pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual; i ++) {
1829            if (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->sBufferFlagTrack[i].buffer_id == 0xFFFFFFFF)
1830            {
1831	      OMX_PRBUFFER1(pComponentPrivate->dbg, "record buffer id in array %d\n", i);
1832              pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->sBufferFlagTrack[i].flag = pBuffHead->nFlags;
1833              pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->sBufferFlagTrack[i].buffer_id = pComponentPrivate->nInPortIn;
1834              break;
1835            }
1836        }
1837    }
1838
1839     /* mark the first buffer from input port after receiving mark buffer command */
1840     if (pComponentPrivate->nMarkPort == JPEGDEC_INPUT_PORT) {
1841         if (pComponentPrivate->pMarkData) {
1842	    OMX_PRBUFFER2(pComponentPrivate->dbg, "get mark buffer command, mark buffer %p\n", pBuffHead);
1843            pBuffHead->pMarkData = pComponentPrivate->pMarkData;
1844            pBuffHead->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1845            pComponentPrivate->pMarkData = NULL;
1846            pComponentPrivate->hMarkTargetComponent = NULL;
1847         }
1848     }
1849
1850     /* if a buffer from input port is marked, record this port # in the buffer queue */
1851     if (pBuffHead->pMarkData) {
1852	 for (i = 0; i < (int)pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual; i ++) {
1853             if (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->sBufferMarkTrack[i].buffer_id == 0xFFFFFFFF)
1854             {
1855                JPEGDEC_BUFFERMARK_TRACK *pMarkTrack;
1856                pMarkTrack = &(pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->sBufferMarkTrack[i]);
1857                pMarkTrack->buffer_id = pComponentPrivate->nInPortIn;
1858                pMarkTrack->pMarkData = pBuffHead->pMarkData;
1859                pMarkTrack->hMarkTargetComponent = pBuffHead->hMarkTargetComponent;
1860                OMX_PRBUFFER2(pComponentPrivate->dbg, "mark buffer at ID %lu\n", pComponentPrivate->nInPortIn);
1861                break;
1862             }
1863         }
1864     }
1865
1866
1867     pBuffPrivate->bReadFromPipe = OMX_FALSE;
1868#ifdef __PERF_INSTRUMENTATION__
1869    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1870                       pBuffHead->pBuffer,
1871                       pBuffHead->nFilledLen,
1872                       PERF_ModuleHLMM);
1873#endif
1874
1875
1876    pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_COMPONENT_IN;
1877
1878    nRet = write (pComponentPrivate->nFilled_inpBuf_Q[1], &(pBuffHead), sizeof(pBuffHead));
1879    if (nRet == -1) {
1880	    OMX_PRCOMM4(pComponentPrivate->dbg, "Error while writing to the nFilled_inpBuf_Q pipe\n");
1881    }
1882
1883EXIT:
1884    return eError;
1885}   /* End of EmptyThisBuffer */
1886
1887
1888
1889/* ========================================================================== */
1890/**
1891 * @fn FillThisBuffer_JPEGDec - Send Output Buffers. The application uses this
1892 *  to send the empty output buffers to the output port of the component.
1893 * @param hComponent - handle for this instance of the component
1894 * @param pBuffHead - Pointer to buffer header
1895 * @return: OMX_ERRORTYPE
1896 *          OMX_ErrorNone on success
1897 *          !OMX_ErrorNone on any failure
1898 */
1899/* ========================================================================== */
1900static OMX_ERRORTYPE FillThisBuffer_JPEGDec(OMX_HANDLETYPE pComponent,
1901                                            OMX_BUFFERHEADERTYPE* pBuffHead)
1902{
1903    OMX_ERRORTYPE eError = OMX_ErrorNone;
1904    OMX_COMPONENTTYPE *pHandle = NULL;
1905    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1906    JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
1907    int nRet;
1908
1909    if (pBuffHead == NULL) {
1910        eError = OMX_ErrorBadParameter;
1911        goto EXIT;
1912    }
1913
1914    OMX_CHECK_PARAM(pComponent);
1915    pHandle = (OMX_COMPONENTTYPE *)pComponent;
1916    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1917    pBuffPrivate = pBuffHead->pOutputPortPrivate;
1918
1919    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1920
1921    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion FillThisBuffer_JPEGDec\n");
1922
1923    if ( pBuffHead->nSize != sizeof(OMX_BUFFERHEADERTYPE) ) {
1924
1925        eError = OMX_ErrorBadParameter;
1926        goto EXIT;
1927    }
1928
1929    if (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bEnabled == OMX_FALSE) {
1930        eError = OMX_ErrorIncorrectStateOperation;
1931        OMX_PRSTATE4(pComponentPrivate->dbg, "eError = OMX_ErrorIncorrectStateOperation\n");
1932        goto EXIT;
1933        }
1934
1935
1936
1937    if ((pBuffHead->nVersion.s.nVersionMajor != 0x1) ||
1938        (pBuffHead->nVersion.s.nVersionMinor != 0x0) ||
1939        (pBuffHead->nVersion.s.nRevision != 0x0) ||
1940        (pBuffHead->nVersion.s.nStep != 0x0)) {
1941
1942        eError= OMX_ErrorVersionMismatch;
1943        goto EXIT;
1944    }
1945
1946    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nOutputPortIndex %lu\n", pBuffHead->nOutputPortIndex);
1947
1948    if (pBuffHead->nOutputPortIndex != 0x1) {
1949            eError = OMX_ErrorBadPortIndex;
1950            goto EXIT;
1951    }
1952
1953    pBuffHead->nFilledLen = 0;
1954
1955    if ( pComponentPrivate->nCurState != OMX_StateExecuting &&
1956        pComponentPrivate->nCurState != OMX_StatePause &&
1957        pComponentPrivate->nCurState != OMX_StateIdle) {
1958        eError= OMX_ErrorIncorrectStateOperation;
1959        goto EXIT;
1960
1961    }
1962
1963#ifdef __PERF_INSTRUMENTATION__
1964    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1965                       pBuffHead->pBuffer,
1966                       pBuffHead->nFilledLen,
1967                       PERF_ModuleHLMM);
1968#endif
1969
1970        pBuffPrivate->bReadFromPipe = OMX_FALSE;
1971    pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_COMPONENT_IN;
1972    nRet = write (pComponentPrivate->nFree_outBuf_Q[1], &(pBuffHead), sizeof (pBuffHead));
1973    if (nRet == -1) {
1974	    OMX_PRCOMM4(pComponentPrivate->dbg, "Error while writing in nFree_outBuf_Q pipe\n");
1975    }
1976
1977EXIT:
1978    return eError;
1979}   /* End of FillThisBuffer_JPEGDec */
1980
1981
1982/* ========================================================================== */
1983/**
1984 * @fn ComponentDeInit - Deinitialize Component. This method will clean all
1985 *  resources in the component
1986 * @param hComponent - handle for this instance of the component
1987 * @return: OMX_ERRORTYPE
1988 *          OMX_ErrorNone on success
1989 *          !OMX_ErrorNone on any failure
1990 */
1991/* ========================================================================== */
1992OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE hComponent)
1993{
1994    OMX_ERRORTYPE eError = OMX_ErrorNone;
1995    OMX_COMPONENTTYPE *pHandle = NULL;
1996    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1997    struct OMX_TI_Debug dbg;
1998
1999    OMX_DBG_INIT_BASE(dbg);
2000    OMX_CHECK_PARAM(hComponent);
2001    pHandle = (OMX_COMPONENTTYPE *)hComponent;
2002
2003    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
2004    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
2005
2006    dbg = pComponentPrivate->dbg;
2007
2008    OMX_PRINT1(dbg, "Entering funtion ComponentDeInit\n");
2009
2010#ifdef __PERF_INSTRUMENTATION__
2011    PERF_Boundary(pComponentPrivate->pPERF,
2012	    PERF_BoundaryComplete | PERF_BoundaryCleanup);
2013    PERF_Done(pComponentPrivate->pPERF);
2014#endif
2015
2016    Free_ComponentResourcesJpegDec(pHandle->pComponentPrivate);
2017
2018#ifdef RESOURCE_MANAGER_ENABLED
2019    eError= RMProxy_NewSendCommand(pHandle,  RMProxy_FreeResource, OMX_JPEG_Decoder_COMPONENT, 0, 3456, NULL);
2020    if (eError != OMX_ErrorNone) {
2021        OMX_PRMGR4(dbg, "Cannot Free RMProxy Resources\n");
2022    }
2023    eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_IMAGE);
2024    if (eError != OMX_ErrorNone) {
2025	OMX_PRMGR4(dbg, "Error returned from destroy ResourceManagerProxy thread\n");
2026    }
2027#endif
2028
2029EXIT:
2030    OMX_PRINT1(dbg, "Error from Component DeInit = %d\n",eError);
2031    OMX_DBG_CLOSE(dbg);
2032    return eError;
2033} /* End of ComponentDeInit */
2034
2035
2036
2037/* ========================================================================== */
2038/**
2039 * @fn VerifyTunnelConnection_JPEGDec - This function verifies the tunnel connection
2040 * @param pPort - port info
2041 * @param hTunneledComp - handle of the component to tunnel
2042 * @param pPortDef - pointer to the port definition.
2043 * @return: OMX_ERRORTYPE
2044 *          OMX_ErrorNone on success
2045 *          !OMX_ErrorNone on any failure
2046 */
2047/* ========================================================================== */
2048static OMX_ERRORTYPE VerifyTunnelConnection_JPEGDec(JPEGDEC_PORT_TYPE *pPort,
2049                                                    OMX_HANDLETYPE hTunneledComp,
2050                                                    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef)
2051{
2052    /* 1.4 Check if input port is compatible with output port */
2053    OMX_PARAM_PORTDEFINITIONTYPE sPortDef;
2054    OMX_ERRORTYPE eError = OMX_ErrorNone;
2055    OMX_COMPONENTTYPE *pHandle = NULL;
2056    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
2057    pHandle = (OMX_COMPONENTTYPE *)hTunneledComp;
2058    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
2059
2060    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
2061    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion VerifyTunnelConnection_JPEGDec\n");
2062
2063    sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
2064    sPortDef.nVersion.s.nVersionMajor = 0x01;
2065    sPortDef.nVersion.s.nVersionMinor = 0x00;
2066    sPortDef.nPortIndex = pPort->nTunnelPort;
2067
2068    eError = OMX_GetParameter(hTunneledComp, OMX_IndexParamPortDefinition, &sPortDef);
2069
2070    if (eError != OMX_ErrorNone) {
2071	    OMX_PRCOMM4(pComponentPrivate->dbg, "Error \n");
2072        return eError;
2073    }
2074
2075    switch (pPortDef->eDomain) {
2076
2077    case OMX_PortDomainOther:
2078        if (sPortDef.format.other.eFormat!= pPortDef->format.other.eFormat) {
2079            pPort->hTunnelComponent = 0;
2080            pPort->nTunnelPort = 0;
2081            return OMX_ErrorPortsNotCompatible;
2082        }
2083        break;
2084
2085    case OMX_PortDomainAudio:
2086        if (sPortDef.format.audio.eEncoding != pPortDef->format.audio.eEncoding) {
2087            pPort->hTunnelComponent = 0;
2088            pPort->nTunnelPort = 0;
2089            return OMX_ErrorPortsNotCompatible;
2090        }
2091        break;
2092
2093    case OMX_PortDomainVideo:
2094        if (sPortDef.format.video.eCompressionFormat != pPortDef->format.video.eCompressionFormat) {
2095            pPort->hTunnelComponent = 0;
2096            pPort->nTunnelPort = 0;
2097            return OMX_ErrorPortsNotCompatible;
2098        }
2099        break;
2100
2101    case OMX_PortDomainImage:
2102        if (sPortDef.format.image.eCompressionFormat != pPortDef->format.image.eCompressionFormat) {
2103            pPort->hTunnelComponent = 0;
2104            pPort->nTunnelPort = 0;
2105            return OMX_ErrorPortsNotCompatible;
2106        }
2107        break;
2108
2109    default:
2110        pPort->hTunnelComponent = 0;
2111        pPort->nTunnelPort = 0;
2112        return OMX_ErrorPortsNotCompatible; /* Our current port is not set up correctly */
2113    }
2114EXIT:
2115    return eError;
2116}   /* End of VerifyTunnelConnection_JPEGDec */
2117
2118
2119
2120/* ========================================================================== */
2121/**
2122 * @fn ComponentTunnelRequest_JPEGDec - Set a tunnel between two OMx components
2123 * @param hComponent - handle for this instance of the component
2124 * @param nPort - Index Port
2125 * @param hTunneledComp - handle for the istance of the tunneled component
2126 * @param nTunneledPort - index port of the tunneled component
2127 * @param pTunnelSetup - Tunnel setup type
2128 * @return: OMX_ERRORTYPE
2129 *          OMX_ErrorNone on success
2130 *          !OMX_ErrorNone on any failure
2131 */
2132/* ========================================================================== */
2133static OMX_ERRORTYPE ComponentTunnelRequest_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent,
2134                                                    OMX_IN OMX_U32 nPort,
2135                                                    OMX_IN OMX_HANDLETYPE hTunneledComp,
2136                                                    OMX_IN OMX_U32 nTunneledPort,
2137                                                    OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup)
2138{
2139    OMX_ERRORTYPE eError = OMX_ErrorNone;
2140    OMX_COMPONENTTYPE *pHandle = NULL;
2141    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
2142    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
2143    JPEGDEC_PORT_TYPE *pPort = NULL;
2144
2145    OMX_CHECK_PARAM(hComponent);
2146    pHandle = (OMX_COMPONENTTYPE *)hComponent;
2147    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
2148
2149    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
2150
2151    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion ComponentTunnelRequest_JPEGDec\n");
2152    OMX_PRINT1(pComponentPrivate->dbg, "nPort = %lu\n",nPort);
2153
2154    pPort = pComponentPrivate->pCompPort[nPort];
2155    if (pTunnelSetup == NULL || hTunneledComp == 0) {
2156        /* cancel previous tunnel */
2157        pPort->hTunnelComponent = 0;
2158        pPort->nTunnelPort = 0;
2159        OMX_PRBUFFER2(pComponentPrivate->dbg, "OMX_BufferSupplyUnspecified\n");
2160        pPort->pParamBufSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified;
2161    }
2162    else {
2163        if (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->eDir != OMX_DirInput && pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->eDir != OMX_DirOutput) {
2164
2165	    OMX_PRBUFFER4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
2166            return OMX_ErrorBadParameter;
2167        }
2168
2169        /* Check if the other component is developed by TI */
2170        if(IsTIOMXComponent(hTunneledComp) != OMX_TRUE)
2171        {
2172	    OMX_PRCOMM4(pComponentPrivate->dbg, "OMX_ErrorTunnelingUnsupported\n");
2173        eError = OMX_ErrorTunnelingUnsupported;
2174        goto EXIT;
2175        }
2176
2177        pPort->hTunnelComponent = hTunneledComp;
2178        pPort->nTunnelPort = nTunneledPort;
2179
2180        if (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef && pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nPortIndex == nPort) {
2181            /* Component is the output (source of data) */
2182            pTunnelSetup->eSupplier = pPort->pParamBufSupplier->eBufferSupplier;
2183        }
2184        else {
2185            /* Component is the input (sink of data) */
2186            eError = VerifyTunnelConnection_JPEGDec(pPort, hTunneledComp, pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef);
2187            if (OMX_ErrorNone != eError)    {
2188		OMX_PRCOMM5(pComponentPrivate->dbg, "########### Error !! PP VerifyTunnelConnection_JPEGDec failed\n");
2189                /* Invalid connection formats. Return eError */
2190                return OMX_ErrorPortsNotCompatible;
2191            }
2192            /* If specified obey output port's preferences. Otherwise choose output */
2193            pPort->pParamBufSupplier->eBufferSupplier = pTunnelSetup->eSupplier;
2194            if (OMX_BufferSupplyUnspecified == pPort->pParamBufSupplier->eBufferSupplier) {
2195                pPort->pParamBufSupplier->eBufferSupplier = pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
2196            }
2197
2198            /* Tell the output port who the supplier is */
2199            sBufferSupplier.nSize = sizeof(sBufferSupplier);
2200            sBufferSupplier.nVersion.s.nVersionMajor = 0x01;
2201            sBufferSupplier.nVersion.s.nVersionMinor = 0x00;
2202            sBufferSupplier.nPortIndex = nTunneledPort;
2203            sBufferSupplier.eBufferSupplier = pPort->pParamBufSupplier->eBufferSupplier;
2204            eError = OMX_SetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &sBufferSupplier);
2205            eError = OMX_GetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &sBufferSupplier);
2206
2207            if (sBufferSupplier.eBufferSupplier != pPort->pParamBufSupplier->eBufferSupplier) {
2208
2209                return OMX_ErrorUndefined;
2210            }
2211        }
2212    }
2213EXIT:
2214    return eError;
2215}   /* End of ComponentTunnelRequest_JPEGDec */
2216
2217
2218/* ========================================================================== */
2219/**
2220 * @fn Allocate_DSPResources_JPEGDec - Allocate the Ialg structure for each port's
2221 * buffer header.
2222 * @param hComponent - handle for this instance of the component
2223 * @param nPort - Index Port
2224 * @return: OMX_ERRORTYPE
2225 *          OMX_ErrorNone on success
2226 *          !OMX_ErrorNone on any failure
2227 */
2228/* ========================================================================== */
2229static OMX_ERRORTYPE Allocate_DSPResources_JPEGDec(OMX_IN JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
2230                                                   OMX_IN OMX_U32 nPortIndex)
2231{
2232    OMX_ERRORTYPE eError = OMX_ErrorNone;
2233    void *pUalgOutParams;
2234    void *pUalgInpParams;
2235    OMX_U8* pTemp;
2236    OMX_U8 nBufferCount = -1;
2237
2238    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
2239
2240    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion Allocate_DSPResources_JPEGDec\n");
2241
2242    nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
2243    if (nPortIndex == JPEGDEC_INPUT_PORT) {
2244        OMX_MALLOC(pUalgInpParams, sizeof(JPEGDEC_UAlgInBufParamStruct) + 256);
2245        pTemp = (OMX_U8*)pUalgInpParams;
2246        pTemp += 128;
2247        pUalgInpParams = pTemp;
2248        (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nBufferCount]->pUALGParams) = (JPEGDEC_UAlgInBufParamStruct *)(pUalgInpParams);
2249    }
2250    else if (nPortIndex == JPEGDEC_OUTPUT_PORT) {
2251        OMX_MALLOC(pUalgOutParams, sizeof(JPEGDEC_UAlgOutBufParamStruct) + 256);
2252        pTemp = (OMX_U8*)pUalgOutParams;
2253        pTemp += 128;
2254        pUalgOutParams = pTemp;
2255        (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nBufferCount]->pUALGParams) = (JPEGDEC_UAlgOutBufParamStruct *)(pUalgOutParams);
2256    }
2257    else {
2258        eError = OMX_ErrorBadPortIndex;
2259        goto EXIT;
2260    }
2261
2262EXIT:
2263    return eError;
2264} /* End of Allocate_DSPResources_JPEGDec */
2265
2266
2267
2268
2269static void JPEGDEC_InitBufferFlagTrack(
2270    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
2271    OMX_U32 nPortIndex)
2272
2273{
2274    JPEGDEC_PORT_TYPE *pPortType = NULL;
2275    int i;
2276
2277     pPortType = pComponentPrivate->pCompPort[nPortIndex];
2278
2279    /* assume  pPortType->pPortDef->nBufferCountActual <= NUM_OF_BUFFERSJPEG */
2280     for (i = 0; i < (int)pPortType->pPortDef->nBufferCountActual; i ++) {
2281        pPortType->sBufferFlagTrack[i].flag = 0;
2282        pPortType->sBufferFlagTrack[i].buffer_id = 0xFFFFFFFF;
2283        pPortType->sBufferMarkTrack[i].buffer_id = 0xFFFFFFFF;
2284        pPortType->sBufferMarkTrack[i].pMarkData = NULL;
2285    }
2286}
2287
2288
2289
2290#ifdef KHRONOS_1_1
2291/* ========================================================================== */
2292/**
2293 * @fn ComponentRoleEnum -
2294 * @param hComponent - handle for this instance of the component
2295 * @param cRole - role performed by the component
2296 * @param nIndex - Index
2297 * @return: OMX_ERRORTYPE
2298 *          OMX_ErrorNone on success
2299 *          !OMX_ErrorNone on any failure
2300 */
2301/* ========================================================================== */
2302static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
2303                                       OMX_OUT OMX_U8 *cRole,
2304                                       OMX_IN OMX_U32 nIndex)
2305{
2306    JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate;
2307    OMX_ERRORTYPE eError = OMX_ErrorNone;
2308    pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2309
2310    if(nIndex == 0){
2311        strncpy((char *)cRole, (char *)pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
2312    }
2313    else {
2314        eError = OMX_ErrorNoMore;
2315    }
2316
2317    return eError;
2318}
2319#endif
2320
2321
2322
2323/*-------------------------------------------------------------------*/
2324/**
2325  * GetExtensionIndex_JpegDec()
2326  *
2327  * Free a video driver buffer.
2328  *
2329  * @retval OMX_ErrorNone                    Successful operation.
2330  *         OMX_ErrorBadParameter            Invalid operation.
2331  *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
2332  **/
2333/*-------------------------------------------------------------------*/
2334OMX_ERRORTYPE GetExtensionIndex_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType)
2335{
2336    OMX_U16 nIndex;
2337    OMX_ERRORTYPE eError = OMX_ErrorUndefined;
2338    JPEGDEC_CUSTOM_PARAM_DEFINITION sJpegDecCustomParams[] = {
2339    {"OMX.TI.JPEG.decoder.Config.ProgressiveFactor", OMX_IndexCustomProgressiveFactor},
2340    {"OMX.TI.JPEG.decoder.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
2341    {"OMX.TI.JPEG.decoder.Config.OutputColorFormat", OMX_IndexCustomOutputColorFormat},
2342    {"OMX.TI.JPEG.decoder.Param.SectionDecode", OMX_IndexCustomSectionDecode},
2343    {"OMX.TI.JPEG.decoder.Param.SubRegionDecode", OMX_IndexCustomSubRegionDecode},
2344    {"OMX.TI.JPEG.decoder.Param.SetMaxResolution", OMX_IndexCustomSetMaxResolution},
2345    {"OMX.TI.JPEG.decoder.Debug", OMX_IndexCustomDebug},
2346    {"",0x0}
2347    };
2348
2349    /* Check parameter validity */
2350    OMX_CHECK_PARAM(hComponent);
2351    OMX_CHECK_PARAM(pIndexType);
2352    *pIndexType = OMX_IndexMax;
2353
2354    for (nIndex = 0; strlen((const char*)sJpegDecCustomParams[nIndex].cCustomParamName); nIndex++){
2355        if (!strcmp((const char*)cParameterName, (const char*)(&(sJpegDecCustomParams[nIndex].cCustomParamName)))){
2356            *pIndexType = sJpegDecCustomParams[nIndex].nCustomParamIndex;
2357            eError = OMX_ErrorNone;
2358            break;
2359        }
2360    }
2361
2362    if(*pIndexType == OMX_IndexMax){
2363         eError = OMX_ErrorUnsupportedIndex;
2364    }
2365
2366
2367EXIT:
2368    return eError;
2369}
2370