Home | History | Annotate | Download | only in src
      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 /**
     30 * @file OMX_JpegDec_Utils.c
     31 *
     32 * This file implements OMX Component for JPEG decoder
     33 *
     34 * @patth $(CSLPATH)\jpeg_dec\src\OMX_JpegDec_Utils.c
     35 *
     36 * @rev 0.2
     37 */
     38 
     39 
     40 /****************************************************************
     41  *  INCLUDE FILES
     42 *****************************************************************/
     43 
     44 /* -----------System and Platform Files ------------------------*/
     45 
     46 #ifdef UNDER_CE
     47     #include <windows.h>
     48     #include <oaf_osal.h>
     49     #include <omx_core.h>
     50     #include <stdlib.h>
     51 #else
     52     #include <unistd.h>
     53     #include <sys/types.h>
     54     #include <sys/types.h>
     55     #include <sys/stat.h>
     56     #include <dlfcn.h>
     57     #include <malloc.h>
     58     #include <memory.h>
     59     #include <fcntl.h>
     60     #include <sched.h>
     61 #endif
     62 
     63 
     64     #include <dbapi.h>
     65     #include <string.h>
     66     #include <stdio.h>
     67     #include <stdlib.h>
     68     #include <pthread.h>
     69 
     70 /*--------------------- Program Header Files ----------------------------*/
     71 
     72 #include <OMX_Types.h>
     73 #include <OMX_Component.h>
     74 #include <OMX_Core.h>
     75 #include <OMX_Index.h>
     76 #include <OMX_Image.h>
     77 #include <OMX_Audio.h>
     78 #include <OMX_Video.h>
     79 #include <OMX_IVCommon.h>
     80 #include <OMX_Other.h>
     81 #include "OMX_JpegDec_Utils.h"
     82 #include <usn.h>
     83 
     84 #ifdef RESOURCE_MANAGER_ENABLED
     85     #include <ResourceManagerProxyAPI.h>
     86 #endif
     87 
     88 #define JPEGDEC_TIMEOUT 10
     89 
     90 #ifdef UNDER_CE
     91     HINSTANCE g_hLcmlDllHandle = NULL;
     92 #endif
     93 
     94 OMX_ERRORTYPE LCML_CallbackJpegDec(TUsnCodecEvent event,
     95                                    void * args [10]);
     96 
     97 
     98 /*------------------------- Function Implementation ------------------*/
     99 
    100 /* ========================================================================== */
    101 /**
    102  * @fn GetLCMLHandleJpegDec - Implements the functionality to get LCML handle
    103  * @param pComponent - components private structure
    104  * @return: OMX_ERRORTYPE
    105  *          OMX_ErrorNone on success
    106  *          !OMX_ErrorNone on failure
    107  */
    108 /* ========================================================================== */
    109 OMX_ERRORTYPE GetLCMLHandleJpegDec(OMX_HANDLETYPE pComponent)
    110 {
    111     OMX_ERRORTYPE eError = OMX_ErrorNone;
    112 #ifndef UNDER_CE
    113     OMX_HANDLETYPE LCML_pHandle;
    114     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    115     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    116     jpegdec_fpo fpGetHandle;
    117     void *handle = NULL;
    118     char *error = NULL;
    119 
    120     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    121 
    122     handle = dlopen("libLCML.so", RTLD_LAZY);
    123     if (!handle) {
    124 	if ((error = (char *)dlerror()) != NULL) {
    125             fputs(error, stderr);
    126         }
    127         eError = OMX_ErrorComponentNotFound;
    128         goto EXIT;
    129     }
    130 
    131     fpGetHandle = dlsym(handle, "GetHandle");
    132 
    133     if ((error = (char *)dlerror()) != NULL) {
    134         fputs(error, stderr);
    135         eError = OMX_ErrorInvalidComponent;
    136         goto EXIT;
    137     }
    138 
    139     /*calling gethandle and passing phandle to be filled */
    140     if ( fpGetHandle != NULL ) {
    141         eError = (*fpGetHandle)(&LCML_pHandle);
    142     }
    143     else  {
    144         eError = OMX_ErrorInvalidComponent;
    145         goto EXIT;
    146     }
    147     if (eError != OMX_ErrorNone) {
    148         eError = OMX_ErrorUndefined;
    149         OMX_PRDSP5(pComponentPrivate->dbg, "eError != OMX_ErrorNone... in (*fpGetHandle)(&LCML_pHandle);\n");
    150         goto EXIT;
    151     }
    152 
    153     pComponentPrivate->pDllHandle = handle;
    154     pComponentPrivate->pLCML = (void *)LCML_pHandle;
    155     pComponentPrivate->pLCML->pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pComponentPrivate;
    156 
    157 EXIT:
    158 #else
    159     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
    160     LPFNDLLFUNC1 fpGetHandle1;
    161     OMX_HANDLETYPE LCML_pHandle = NULL;
    162     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    163     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    164 
    165     g_hLcmlDllHandle = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL, 0);
    166 
    167     if (g_hLcmlDllHandle == NULL)
    168     {
    169         eError = OMX_ErrorComponentNotFound;
    170         goto EXIT;
    171     }
    172 
    173     fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(g_hLcmlDllHandle,TEXT("GetHandle"));
    174     if (!fpGetHandle1) {
    175         FreeLibrary(g_hLcmlDllHandle);
    176         g_hLcmlDllHandle = NULL;
    177         eError = OMX_ErrorComponentNotFound;
    178         goto EXIT;
    179     }
    180 
    181     eError = fpGetHandle1(&LCML_pHandle);
    182     if (eError != OMX_ErrorNone) {
    183         FreeLibrary(g_hLcmlDllHandle);
    184         g_hLcmlDllHandle = NULL;
    185         eError = OMX_ErrorUndefined;
    186         LCML_pHandle = NULL;
    187         goto EXIT;
    188     }
    189 
    190     (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML = (LCML_DSP_INTERFACE *)LCML_pHandle;
    191     pComponentPrivate->pLCML->pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pComponentPrivate;
    192 
    193 EXIT:
    194 #endif
    195     return eError;
    196 
    197 }   /* End of GetLCMLHandle */
    198 
    199 /* ========================================================================== */
    200 /**
    201  * @fn DisablePortJpegDec - Implements the functionality to disable the ports
    202  * @param pComponentPrivate - components private structure
    203  * @param nParam1 - paramerer specifying the port type (Index port)
    204  * @return: OMX_ERRORTYPE
    205  *          OMX_ErrorNone on success
    206  *          !OMX_ErrorNone on failure
    207  */
    208 /* ========================================================================== */
    209 OMX_ERRORTYPE DisablePortJpegDec(JPEGDEC_COMPONENT_PRIVATE* pComponentPrivate,
    210                                  OMX_U32 nParam1)
    211 {
    212     OMX_ERRORTYPE eError = OMX_ErrorNone;
    213     OMX_CHECK_PARAM(pComponentPrivate);
    214 
    215     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    216 
    217     OMX_PRINT1(pComponentPrivate->dbg, "In DisablePortJpegDec %lu\n", nParam1);
    218 
    219     if (pComponentPrivate->nCurState == OMX_StateExecuting || pComponentPrivate->nCurState == OMX_StatePause) {
    220 	if ((nParam1 == 0) || (nParam1 == 1) || ((int)nParam1 == -1)) {
    221             eError = HandleInternalFlush(pComponentPrivate, nParam1);
    222         }
    223     }
    224 
    225 EXIT:
    226     return eError;
    227 }   /* End of DisablePort */
    228 
    229 
    230 
    231 /* ========================================================================== */
    232 /**
    233  * @fn EnablePortJpegDec - Implements the functionality to enable the ports
    234  * @param pComponentPrivate - components private structure
    235  * @param nParam1 - paramerer specifying the port type (Index port)
    236  * @return: OMX_ERRORTYPE
    237  *          OMX_ErrorNone on success
    238  *          !OMX_ErrorNone on failure
    239  */
    240 /* ========================================================================== */
    241 OMX_ERRORTYPE EnablePortJpegDec(JPEGDEC_COMPONENT_PRIVATE* pComponentPrivate,
    242                                 OMX_U32 nParam1)
    243 {
    244     OMX_ERRORTYPE eError = OMX_ErrorNone;
    245     OMX_CHECK_PARAM(pComponentPrivate);
    246 
    247     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    248 
    249     while (1) {
    250         if ((nParam1 == 0x0) &&
    251             ((pComponentPrivate->nCurState == OMX_StateLoaded) ||
    252              (pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bPopulated))) {
    253 
    254             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
    255                                                    pComponentPrivate->pHandle->pApplicationPrivate,
    256                                                    OMX_EventCmdComplete,
    257                                                    OMX_CommandPortEnable,
    258                                                    JPEGDEC_INPUT_PORT,
    259                                                    NULL);
    260             break;
    261         }
    262         else if ((nParam1 == 0x1) &&
    263                  ((pComponentPrivate->nCurState == OMX_StateLoaded) ||
    264                   (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bPopulated))) {
    265 
    266             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
    267                                                    pComponentPrivate->pHandle->pApplicationPrivate,
    268                                                    OMX_EventCmdComplete,
    269                                                    OMX_CommandPortEnable,
    270                                                    JPEGDEC_OUTPUT_PORT,
    271                                                    NULL);
    272             break;
    273         }
    274         else if (((int)nParam1 == -1) &&
    275                 ((pComponentPrivate->nCurState == OMX_StateLoaded) ||
    276                  ((pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bPopulated) &&
    277                   (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bPopulated)))) {
    278 
    279             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
    280                                                    pComponentPrivate->pHandle->pApplicationPrivate,
    281                                                    OMX_EventCmdComplete,
    282                                                    OMX_CommandPortEnable,
    283                                                    JPEGDEC_INPUT_PORT,
    284                                                    NULL);
    285 
    286             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
    287                                                    pComponentPrivate->pHandle->pApplicationPrivate,
    288                                                    OMX_EventCmdComplete,
    289                                                    OMX_CommandPortEnable,
    290                                                    JPEGDEC_OUTPUT_PORT,
    291                                                    NULL);
    292             break;
    293 
    294         }
    295         else {
    296                 JPEGDEC_WAIT_PORT_POPULATION(pComponentPrivate);
    297         }
    298     }
    299     OMX_PRINT1(pComponentPrivate->dbg, "Exiting EnablePortJpegDec(), Ports are enabled if no error\n");
    300 EXIT:
    301     return eError;
    302 }   /* End of EnablePort */
    303 
    304 
    305 /* ========================================================================== */
    306 /**
    307  * @fn Start_ComponentThreadJpegDec - Implements the functionality to start
    308  *  the component thread. Creates data pipes, commmand pipes and initializes
    309  *  Component thread.
    310  * @param pComponentPrivate - components private structure
    311  * @param nParam1 - paramerer specifying the port type (Index port)
    312  * @return: OMX_ERRORTYPE
    313  *          OMX_ErrorNone on success
    314  *          !OMX_ErrorNone on failure
    315  */
    316 /* ========================================================================== */
    317 OMX_ERRORTYPE Start_ComponentThreadJpegDec(OMX_HANDLETYPE pComponent)
    318 {
    319     OMX_ERRORTYPE eError = OMX_ErrorNone;
    320     OMX_COMPONENTTYPE *pHandle = NULL;
    321     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
    322 #ifdef UNDER_CE
    323     pthread_attr_t attr;
    324     memset(&attr, 0, sizeof(attr));
    325     attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
    326     attr.__schedparam.__sched_priority = OMX_IMAGE_DECODER_THREAD_PRIORITY;
    327 #endif
    328 
    329     OMX_CHECK_PARAM(pComponent);
    330     pHandle = (OMX_COMPONENTTYPE *)pComponent;
    331     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    332 
    333     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    334 
    335     /* create the pipe used to maintain free output buffers*/
    336     eError = pipe (pComponentPrivate->nFree_outBuf_Q);
    337     if (eError) {
    338         eError = OMX_ErrorInsufficientResources;
    339         goto EXIT;
    340     }
    341 
    342     /* create the pipe used to maintain filled input buffers*/
    343     eError = pipe (pComponentPrivate->nFilled_inpBuf_Q);
    344     if (eError) {
    345         eError = OMX_ErrorInsufficientResources;
    346         goto EXIT;
    347     }
    348 
    349     /* create the pipe used to send commands to the thread */
    350     eError = pipe (pComponentPrivate->nCmdPipe);
    351     if (eError) {
    352         eError = OMX_ErrorInsufficientResources;
    353         goto EXIT;
    354     }
    355 
    356     /* create the pipe used to send commands to the thread */
    357     eError = pipe (pComponentPrivate->nCmdDataPipe);
    358     if (eError) {
    359         eError = OMX_ErrorInsufficientResources;
    360         goto EXIT;
    361     }
    362 
    363     OMX_PRINT2(pComponentPrivate->dbg, "JPEG Start_ComponentThread\n");
    364     /* Create the Component Thread */
    365 #ifdef UNDER_CE
    366     eError = pthread_create (&(pComponentPrivate->pComponentThread), &attr, OMX_JpegDec_Thread, pComponent);
    367 #else
    368     eError = pthread_create (&(pComponentPrivate->pComponentThread), NULL, OMX_JpegDec_Thread, pComponent);
    369 #endif
    370 
    371     if (eError || !pComponentPrivate->pComponentThread) {
    372         eError = OMX_ErrorInsufficientResources;
    373         goto EXIT;
    374     }
    375 
    376 #ifdef __PERF_INSTRUMENTATION__
    377     PERF_ThreadCreated(pComponentPrivate->pPERF,
    378                        pComponentPrivate->pComponentThread,
    379                        PERF_FOURS("JPDT"));
    380 #endif
    381 
    382 EXIT:
    383     return eError;
    384 }   /* End of Start_ComponentThreadJpegDec */
    385 
    386 
    387 
    388 /* ========================================================================== */
    389 /**
    390  * @fn Free_ComponentResourcesJpegDec - Implements the functionality to de-init
    391  *  the component thread. close component thread, Command pipe, data pipe &
    392  *  LCML pipe.
    393  * @param pComponentPrivate - components private structure
    394  * @param nParam1 - paramerer specifying the port type (Index port)
    395  * @return: OMX_ERRORTYPE
    396  *          OMX_ErrorNone on success
    397  *          !OMX_ErrorNone on failure
    398  */
    399 /* ========================================================================== */
    400 OMX_ERRORTYPE Free_ComponentResourcesJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate)
    401 {
    402     OMX_ERRORTYPE eError        = OMX_ErrorNone;
    403     OMX_ERRORTYPE threadError   = OMX_ErrorNone;
    404     OMX_ERRORTYPE eErr          = OMX_ErrorNone;
    405     int pthreadError = 0, nRet = 0;
    406     OMX_COMMANDTYPE eCmd = OMX_CustomCommandStopThread;
    407     struct OMX_TI_Debug dbg;
    408 
    409     OMX_DBG_INIT_BASE(dbg);
    410     if (!pComponentPrivate) {
    411 	OMXDBG_PRINT(stderr, ERROR, 5, 0, "pComponentPrivate is NULL.\n");
    412         goto EXIT;
    413     }
    414 
    415     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    416 
    417     dbg = pComponentPrivate->dbg;
    418 
    419 #ifdef __PERF_INSTRUMENTATION__
    420     PERF_Boundary(pComponentPrivate->pPERF,
    421                   PERF_BoundaryStart | PERF_BoundaryCleanup);
    422 #endif
    423 
    424     OMX_PRINT1(pComponentPrivate->dbg, "Inside Free_ComponentResourcesJpegDec \n");
    425     /* should clean up in case of crash - implement*/
    426 
    427 
    428 
    429     if (pComponentPrivate->nIsLCMLActive ==1) {
    430 	OMX_PRINT1(pComponentPrivate->dbg, "EMMCodecControlDestroy inside Free_ComponentResourcesJpegDec\n");
    431         LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLCML)->pCodecinterfacehandle,EMMCodecControlDestroy,NULL);
    432         pComponentPrivate->nIsLCMLActive = 0;
    433 #ifdef UNDER_CE
    434         FreeLibrary(g_hLcmlDllHandle);
    435         g_hLcmlDllHandle = NULL;
    436 #else
    437         dlclose(pComponentPrivate->pDllHandle);
    438         pComponentPrivate->pDllHandle = NULL;
    439 #endif
    440     }
    441 
    442 #ifdef __PERF_INSTRUMENTATION__
    443     PERF_SendingCommand(pComponentPrivate->pPERF,
    444                         eCmd, 0, PERF_ModuleComponent);
    445 #endif
    446 
    447     OMX_PRINT2(pComponentPrivate->dbg, "Freeing resources\n");
    448 
    449     nRet = write(pComponentPrivate->nCmdPipe[1], &eCmd, sizeof(eCmd));
    450     if (nRet == -1) {
    451         OMX_PRCOMM4(pComponentPrivate->dbg, "Error while writing into nCmdPipe\n");
    452         eError = OMX_ErrorHardware;
    453     }
    454 
    455     nRet = write(pComponentPrivate->nCmdDataPipe[1], &eCmd, sizeof(eCmd));
    456     if (nRet == -1) {
    457         OMX_PRCOMM4(pComponentPrivate->dbg, "Error while writing into nCmdDataPipe\n");
    458         eError = OMX_ErrorHardware;
    459     }
    460 
    461     pthreadError = pthread_join(pComponentPrivate->pComponentThread, (void*)&threadError);
    462     if (0 != pthreadError)    {
    463         eError = OMX_ErrorHardware;
    464         OMX_TRACE4(pComponentPrivate->dbg, "Error while closing Component Thread\n");
    465     }
    466 
    467     if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) {
    468 	OMX_TRACE5(pComponentPrivate->dbg, "OMX_ErrorInsufficientResources\n");
    469         eError = OMX_ErrorInsufficientResources;
    470         OMX_TRACE4(pComponentPrivate->dbg, "Error while closing Component Thread\n");
    471     }
    472 
    473     /* close the data pipe handles*/
    474     eErr = close(pComponentPrivate->nFree_outBuf_Q[0]);
    475     if (0 != eErr && OMX_ErrorNone == eError) {
    476         eError = OMX_ErrorHardware;
    477         OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing data pipe\n");
    478     }
    479 
    480     eErr = close(pComponentPrivate->nFilled_inpBuf_Q[0]);
    481     if (0 != eErr && OMX_ErrorNone == eError) {
    482         eError = OMX_ErrorHardware;
    483         OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing data pipe\n");
    484     }
    485 
    486     eErr = close(pComponentPrivate->nFree_outBuf_Q[1]);
    487     if (0 != eErr && OMX_ErrorNone == eError) {
    488         eError = OMX_ErrorHardware;
    489         OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing data pipe\n");
    490     }
    491 
    492     eErr = close(pComponentPrivate->nFilled_inpBuf_Q[1]);
    493     if (0 != eErr && OMX_ErrorNone == eError) {
    494         eError = OMX_ErrorHardware;
    495 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing data pipe\n");
    496     }
    497 
    498     /*Close the command pipe handles*/
    499     eErr = close(pComponentPrivate->nCmdPipe[0]);
    500     if (0 != eErr && OMX_ErrorNone == eError) {
    501         eError = OMX_ErrorHardware;
    502 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing cmd pipe\n");
    503     }
    504 
    505     eErr = close(pComponentPrivate->nCmdPipe[1]);
    506     if (0 != eErr && OMX_ErrorNone == eError) {
    507         eError = OMX_ErrorHardware;
    508 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing cmd pipe\n");
    509     }
    510 
    511     /*Close the command data pipe handles*/
    512     eErr = close(pComponentPrivate->nCmdDataPipe[0]);
    513     if (0 != eErr && OMX_ErrorNone == eError) {
    514         eError = OMX_ErrorHardware;
    515 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing cmd pipe\n");
    516     }
    517 
    518     eErr = close(pComponentPrivate->nCmdDataPipe[1]);
    519     if (0 != eErr && OMX_ErrorNone == eError) {
    520         eError = OMX_ErrorHardware;
    521 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while closing cmd pipe\n");
    522     }
    523 
    524      if (pthread_mutex_destroy(&(pComponentPrivate->mJpegDecMutex)) != 0){
    525          OMX_TRACE4(pComponentPrivate->dbg, "Error with pthread_mutex_destroy");
    526     }
    527 
    528     if(pthread_cond_destroy(&(pComponentPrivate->sStop_cond)) != 0){
    529 	OMX_TRACE4(pComponentPrivate->dbg, "Error with pthread_cond_desroy");
    530     }
    531 
    532 
    533 #ifdef __PERF_INSTRUMENTATION__
    534     PERF_Boundary(pComponentPrivate->pPERF,
    535                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
    536     PERF_Done(pComponentPrivate->pPERF);
    537 #endif
    538 
    539     /*LinkedList_DisplayAll (&AllocList); */
    540     OMX_FREEALL();
    541     LinkedList_Destroy(&AllocList);
    542 
    543 EXIT:
    544     OMX_PRINT1(dbg, "Exiting Successfully After Freeing All Resources Errror %x, \n", eError);
    545     return eError;
    546 }   /* End of Free_ComponentResourcesJpegDec */
    547 
    548 
    549 
    550 /* ========================================================================== */
    551 /**
    552  * @fn Fill_LCMLInitParamsJpegDec - This function fills the create phase
    553  *  parameters used by DSP
    554  * @param lcml_dsp    handle for this instance of the LCML
    555  * @param arr[]       array with the parameters
    556  * @param pComponent  handle for this instance of component
    557  * @return: OMX_ERRORTYPE
    558  *          OMX_ErrorNone on success
    559  *          !OMX_ErrorNone on failure
    560  */
    561 /* ========================================================================== */
    562 OMX_ERRORTYPE Fill_LCMLInitParamsJpegDec(LCML_DSP *lcml_dsp,
    563                                                 OMX_U16 arr[],
    564                                                 OMX_HANDLETYPE pComponent)
    565 {
    566 
    567     OMX_ERRORTYPE eError            = OMX_ErrorNone;
    568     OMX_COMPONENTTYPE *pHandle  =  NULL;
    569     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate    = NULL;
    570     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut       = NULL;
    571     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn        = NULL;
    572     OMX_U16 nScaleFactor;
    573     OMX_U16 nFrameWidth;
    574     OMX_U16 nFrameHeight;
    575 
    576     OMX_CHECK_PARAM(pComponent);
    577     pHandle = (OMX_COMPONENTTYPE *)pComponent;
    578     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    579     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    580 
    581     pPortDefIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef;
    582     pPortDefOut = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef;
    583 
    584     lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD;
    585     lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD;
    586 
    587     lcml_dsp->NodeInfo.nNumOfDLLs = OMX_JPEGDEC_NUM_DLLS;
    588     lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&JPEGDSOCKET_TI_UUID;
    589     strcpy ((char *)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,JPEG_DEC_NODE_DLL);
    590     lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
    591 
    592     lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&JPEGDSOCKET_TI_UUID;
    593     strcpy ((char *)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,JPEG_DEC_NODE_DLL);
    594     lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
    595 
    596     lcml_dsp->NodeInfo.AllUUIDs[2].uuid =(struct DSP_UUID *) &USN_UUID;
    597     strcpy ((char *)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,USN_DLL);
    598     lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
    599 
    600     lcml_dsp->DeviceInfo.TypeofDevice = 0;
    601     lcml_dsp->SegID = 0;
    602     lcml_dsp->Timeout = -1;
    603     lcml_dsp->Alignment = 0;
    604     lcml_dsp->Priority = 5;
    605 
    606 
    607     switch(pComponentPrivate->pScalePrivate->xWidth){
    608         case (0):
    609             nScaleFactor = 100;
    610             break;
    611         case (1):
    612             nScaleFactor = 50;
    613             break;
    614         case (2):
    615             nScaleFactor = 25;
    616             break;
    617         case (3):
    618             nScaleFactor = 13; /*12.5*/
    619             break;
    620         case (4):
    621             nScaleFactor = 200;
    622             break;
    623         case (5):
    624             nScaleFactor = 400;
    625             break;
    626         case (6):
    627             nScaleFactor = 800;
    628             break;
    629         default:
    630             nScaleFactor = 100;
    631             break;
    632     }
    633 
    634     nFrameWidth = pPortDefIn->format.image.nFrameWidth * nScaleFactor / 100;
    635     nFrameHeight = pPortDefIn->format.image.nFrameHeight * nScaleFactor / 100;
    636 
    637     if (pComponentPrivate->nProgressive == 1) {
    638         if (nFrameHeight <= 144 &&
    639             nFrameWidth<= 176) {
    640             lcml_dsp->ProfileID = 0;
    641         }
    642         else if (nFrameHeight <= 288 &&
    643             nFrameWidth<= 352) {
    644             lcml_dsp->ProfileID = 1;
    645         }
    646         else if (nFrameHeight <= 480 &&
    647             nFrameWidth <= 640) {
    648             lcml_dsp->ProfileID = 2;
    649         }
    650         else if (nFrameHeight<= 1024 &&
    651             nFrameWidth <= 1280) {
    652             lcml_dsp->ProfileID = 4;
    653         }
    654         else if (nFrameHeight <= 1200 &&
    655             nFrameWidth<= 1920) {
    656             lcml_dsp->ProfileID = 5;
    657         }
    658         else if (nFrameHeight<= 1536 &&
    659             nFrameWidth<= 2048) {
    660             lcml_dsp->ProfileID = 6;
    661         }
    662         else if (nFrameHeight<= 1600 &&
    663             nFrameWidth<= 2560) {
    664             lcml_dsp->ProfileID = 7;
    665         }
    666         else if (nFrameHeight <= 2048 &&
    667             nFrameWidth<= 2560) {
    668             lcml_dsp->ProfileID = 8;
    669         }
    670         else if (nFrameHeight <= 2048 &&
    671             nFrameWidth<= 3200) {
    672             lcml_dsp->ProfileID = 9;
    673         }
    674         else {
    675             lcml_dsp->ProfileID = 3;
    676         }
    677     }
    678     else if (pComponentPrivate->nProgressive == 0) {
    679         lcml_dsp->ProfileID = -1;
    680     }
    681     pComponentPrivate->nProfileID = lcml_dsp->ProfileID;
    682 
    683     /*filling create phase params*/
    684     arr[0] = JPGDEC_SNTEST_STRMCNT;
    685     arr[1] = JPGDEC_SNTEST_INSTRMID;
    686     arr[2] = 0;
    687     arr[3] = JPGDEC_SNTEST_INBUFCNT;
    688     arr[4] = JPGDEC_SNTEST_OUTSTRMID;
    689     arr[5] = 0;
    690     arr[6] = JPGDEC_SNTEST_OUTBUFCNT;
    691 
    692     if (pComponentPrivate->nProgressive == 1) {
    693         OMX_PRINT2(pComponentPrivate->dbg, "JPEGdec:: nProgressive IMAGE");
    694         arr[7] = nFrameHeight;
    695         if ((arr[7]%2) != 0) arr[7]++;
    696         arr[8] = nFrameWidth;
    697         if ((arr[8]%2) != 0) arr[8]++;
    698 
    699         arr[9] = JPGDEC_SNTEST_PROG_FLAG;
    700     }
    701     else {
    702         OMX_PRINT2(pComponentPrivate->dbg, "****** Max Width %d Max Height %d\n",(int)pComponentPrivate->sMaxResolution.nWidth,(int)pComponentPrivate->sMaxResolution.nHeight);
    703 
    704         arr[7] = pComponentPrivate->sMaxResolution.nHeight;
    705         arr[8] = pComponentPrivate->sMaxResolution.nWidth;
    706         arr[9] = 0;
    707     }
    708 
    709     if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_FormatCbYCrY) {
    710         arr[10] = 4;
    711     }
    712     else if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_Format16bitRGB565) {
    713         arr[10] = 9;
    714     }
    715     else if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_Format24bitRGB888) {
    716         arr[10] = 10;
    717     }
    718     else if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_Format32bitARGB8888) {
    719         arr[10] = 11;
    720     }
    721     else if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_Format32bitBGRA8888) {
    722         arr[10] = 11;
    723     }
    724     else { /*Set DEFAULT (Original) color format*/
    725         arr[10] = 1;
    726     }
    727     /*arr[11] doesn't need to be filled*/
    728 
    729     if(pComponentPrivate->pSectionDecode->bSectionsInput){ /*Slide decoding enable*/
    730         arr[12] = 1;
    731     }
    732     else{
    733         arr[12] = 0;
    734     }
    735 
    736     if(pComponentPrivate->pSectionDecode->bSectionsOutput){ /*Slide decoding enable*/
    737         arr[13] = 1;
    738     }
    739     else{
    740         arr[13] = 0;
    741     }
    742 
    743 	/* RGB or ARGB output format for RGB32 images */
    744     arr[14] = 0;
    745     if (pPortDefOut->format.image.eColorFormat == OMX_COLOR_Format32bitARGB8888)
    746     {
    747     	arr[14] = 1; /* RGB32 output mode */
    748     }
    749 
    750     arr[15] = END_OF_CR_PHASE_ARGS;
    751 
    752     lcml_dsp->pCrPhArgs = arr;
    753 
    754     OMX_PRINT2(pComponentPrivate->dbg, "Image Width\t= %d\n", arr[8]);
    755     OMX_PRINT2(pComponentPrivate->dbg, "Image Height\t= %d\n", arr[7]);
    756     OMX_PRINT2(pComponentPrivate->dbg, "Progressive\t= %d\n", arr[9]);
    757     OMX_PRINT2(pComponentPrivate->dbg, "Color Format\t= %d\n", arr[10]);
    758     OMX_PRINT2(pComponentPrivate->dbg, "Section Decode(Input)\t= %d\n", arr[12]);
    759     OMX_PRINT2(pComponentPrivate->dbg, "Section Decode(Output)\t= %d\n", arr[13]);
    760 
    761 EXIT:
    762     return eError;
    763 
    764 }   /* End of Fill_LCMLInitParamsJpegDec */
    765 
    766 
    767 
    768 /*-------------------------------------------------------------------*/
    769 /**
    770   *  HandleInternalFlush() This function return request to USN to return all buffers
    771   * via USN
    772   * *
    773   *
    774   * @param pComponentPrivate
    775   * @param nParam1
    776   *
    777   * @retval OMX_NoError              Success, ready to roll
    778   *
    779   *
    780   **/
    781 /*-------------------------------------------------------------------*/
    782 OMX_ERRORTYPE HandleInternalFlush(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1)
    783 {
    784     OMX_ERRORTYPE eError = OMX_ErrorNone;
    785     OMX_U32 aParam[4];
    786     LCML_DSP_INTERFACE *pLCML = NULL;
    787     OMX_U8 nCount = 0;
    788 #ifdef UNDER_CE
    789     OMX_U32 nTimeout = 0;
    790 #endif
    791     OMX_CHECK_PARAM(pComponentPrivate);
    792 
    793     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    794 
    795     if ( nParam1 == 0x0 || (int)nParam1 == -1 ) {
    796 
    797         aParam[0] = USN_STRMCMD_FLUSH;
    798         aParam[1] = 0;
    799         aParam[2] = 0;
    800         pLCML = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
    801         pComponentPrivate->bFlushComplete = OMX_FALSE;
    802 
    803         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLCML)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
    804         if (eError != OMX_ErrorNone) {
    805             goto EXIT;
    806         }
    807 #ifdef UNDER_CE
    808         nTimeout = 0;
    809 #endif
    810         while (pComponentPrivate->bFlushComplete == OMX_FALSE) {
    811 #ifdef UNDER_CE
    812             sched_yield();
    813             if (nTimeout++ > 200000) {
    814 		OMX_PRDSP4(pComponentPrivate->dbg, "Flush input Timeout Error\n");
    815                 break;
    816             }
    817 #else
    818             JPEGDEC_WAIT_FLUSH(pComponentPrivate);
    819 #endif
    820         }
    821         for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
    822             JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nCount];
    823 
    824             if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
    825                 OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
    826                 int nRet;
    827 #ifdef __PERF_INSTRUMENTATION__
    828                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    829                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
    830                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
    831                                       PERF_ModuleLLMM);
    832 #endif
    833 
    834                 if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
    835 			OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from InDir\n", pBuffPrivate->pBufferHdr);
    836                     nRet = read(pComponentPrivate->nFilled_inpBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
    837                 }
    838                 pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
    839                 OMX_PRBUFFER2(pComponentPrivate->dbg, "return input buffer %p in idle\n", pBuffPrivate->pBufferHdr);
    840                 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
    841                                              pComponentPrivate->pHandle->pApplicationPrivate,
    842                                              pBuffPrivate->pBufferHdr);
    843             }
    844         }
    845 
    846         pComponentPrivate->bFlushComplete = OMX_FALSE;
    847     }
    848     if ( nParam1 == 0x1 || (int)nParam1 == -1 ) {
    849 
    850         aParam[0] = USN_STRMCMD_FLUSH;
    851         aParam[1] = 1;
    852         aParam[2] = 0;
    853         pLCML = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
    854         pComponentPrivate->bFlushComplete = OMX_FALSE;
    855 
    856         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLCML)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
    857         if (eError != OMX_ErrorNone) {
    858             goto EXIT;
    859         }
    860 #ifdef UNDER_CE
    861         nTimeout = 0;
    862 #endif
    863         while (pComponentPrivate->bFlushComplete == OMX_FALSE) {
    864 #ifdef UNDER_CE
    865             sched_yield();
    866             if (nTimeout++ > 200000) {
    867 		OMX_PRDSP4(pComponentPrivate->dbg, "Flush output Timeout Error\n");
    868                 break;
    869             }
    870 #else
    871             JPEGDEC_WAIT_FLUSH(pComponentPrivate);
    872 #endif
    873         }
    874 
    875         for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
    876             JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nCount];
    877 
    878             if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
    879             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
    880             int nRet;
    881 #ifdef __PERF_INSTRUMENTATION__
    882                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    883                                   PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
    884                                   PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
    885                                   PERF_ModuleLLMM);
    886 #endif
    887 
    888             if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
    889 	        OMX_PRBUFFER2(pComponentPrivate->dbg, "discard %p from InDir\n", pBuffPrivate->pBufferHdr);
    890                 pComponentPrivate->nOutPortOut ++;
    891                  nRet = read(pComponentPrivate->nFree_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
    892               }
    893 #if 0  /* since we don't have this queue anymore, there is nothing to flush.  Buffers are handled immediately */
    894             else if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_OUT) {
    895 		 OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from OutDir\n", pBuffPrivate->pBufferHdr);
    896                  nRet = read(pComponentPrivate->nFilled_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
    897               }
    898 #endif
    899 	    OMX_PRBUFFER2(pComponentPrivate->dbg, "return output buffer %p in idle (%d)\n", pBuffPrivate->pBufferHdr, pBuffPrivate->eBufferOwner);
    900               pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
    901               pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
    902                                              pComponentPrivate->pHandle->pApplicationPrivate,
    903                                              pBuffPrivate->pBufferHdr);
    904             }
    905         }
    906 
    907         pComponentPrivate->bFlushComplete = OMX_FALSE;
    908     }
    909 
    910 EXIT:
    911     return eError;
    912 
    913 }
    914 
    915 
    916 
    917 /* ========================================================================== */
    918 /**
    919  * @fn HandleCommandFlush - Implements the functionality to send flush command.
    920  * @param pComponentPrivate - components private structure
    921  * @param nParam1 - paramerer specifying the port type (Index port)
    922  * @return: OMX_ERRORTYPE
    923  *          OMX_ErrorNone on success
    924  *          !OMX_ErrorNone on failure
    925  */
    926 /* ========================================================================== */
    927 OMX_U32 HandleCommandFlush(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
    928                            OMX_U32 nParam1)
    929 {
    930     OMX_ERRORTYPE eError = OMX_ErrorNone;
    931     OMX_U8 nCount = 0;
    932     OMX_COMPONENTTYPE* pHandle = NULL;
    933     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
    934     OMX_U32 aParam[3];
    935     OMX_U8 nBuffersIn = 0;
    936     OMX_U8 nBuffersOut = 0;
    937 #ifdef UNDER_CE
    938     OMX_U32 nTimeOut = 0;
    939 #endif
    940 
    941     OMX_CHECK_PARAM(pComponentPrivate);
    942     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    943     pHandle = pComponentPrivate->pHandle;
    944 
    945     nBuffersIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual;
    946     nBuffersOut = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual;
    947 
    948     if ( nParam1 == JPEGDEC_INPUT_PORT || (int)nParam1 == -1 )   {
    949 
    950         aParam[0] = USN_STRMCMD_FLUSH;
    951         aParam[1] = 0;
    952         aParam[2] = 0;
    953         pLcmlHandle = (LCML_DSP_INTERFACE*)(pComponentPrivate->pLCML);
    954         pComponentPrivate->bFlushComplete = OMX_FALSE;
    955         OMX_PRDSP2(pComponentPrivate->dbg, "pLcmlHandle %p\n", pLcmlHandle);
    956         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
    957         OMX_PRDSP2(pComponentPrivate->dbg, "eError %x\n", eError);
    958         if (eError != OMX_ErrorNone) {
    959             goto PRINT_EXIT;
    960         }
    961 #ifdef UNDER_CE
    962     nTimeOut = 0;
    963 #endif
    964     while(pComponentPrivate->bFlushComplete == OMX_FALSE){
    965 #ifdef UNDER_CE
    966         sched_yield();
    967          if (nTimeOut++ > 200000){
    968 	    OMX_PRDSP4(pComponentPrivate->dbg, "Flushing Input port timeout Error\n");
    969             break;
    970         }
    971 #else
    972         JPEGDEC_WAIT_FLUSH(pComponentPrivate);
    973 #endif
    974     }
    975     pComponentPrivate->bFlushComplete = OMX_FALSE;
    976 
    977         for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
    978               JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nCount];
    979 
    980               if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
    981                 OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
    982                 int nRet;
    983 #ifdef __PERF_INSTRUMENTATION__
    984                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    985                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
    986                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
    987                                       PERF_ModuleLLMM);
    988 #endif
    989 
    990                 if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
    991 		     OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from InDir\n", pBuffPrivate->pBufferHdr);
    992                      nRet = read(pComponentPrivate->nFilled_inpBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
    993                   }
    994                   pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
    995 		  OMX_PRBUFFER2(pComponentPrivate->dbg, "return input buffer %p in idle\n", pBuffPrivate->pBufferHdr);
    996                   pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
    997                                                  pComponentPrivate->pHandle->pApplicationPrivate,
    998                                                  pBuffPrivate->pBufferHdr);
    999               }
   1000         }
   1001 
   1002         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1003                                                 pComponentPrivate->pHandle->pApplicationPrivate,
   1004                                                 OMX_EventCmdComplete,
   1005                                                 OMX_CommandFlush,
   1006                                                 JPEGDEC_INPUT_PORT,
   1007                                                 NULL);
   1008         }
   1009 
   1010 
   1011     if ( nParam1 == JPEGDEC_OUTPUT_PORT|| (int)nParam1 == -1 ){
   1012         /* return all output buffers */
   1013         aParam[0] = USN_STRMCMD_FLUSH;
   1014         aParam[1] = 1;
   1015         aParam[2] = 0;
   1016         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1017         pComponentPrivate->bFlushComplete = OMX_FALSE;
   1018         OMX_PRDSP2(pComponentPrivate->dbg, "pLcmlHandle %p\n", pLcmlHandle);
   1019         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
   1020 	OMX_PRDSP2(pComponentPrivate->dbg, "eError %x\n", eError);
   1021        if (eError != OMX_ErrorNone) {
   1022             goto PRINT_EXIT;
   1023         }
   1024 #ifdef UNDER_CE
   1025         nTimeOut = 0;
   1026 #endif
   1027         while (pComponentPrivate->bFlushComplete == OMX_FALSE) {
   1028 #ifdef UNDER_CE
   1029             sched_yield();
   1030             if (nTimeOut++ > 200000) {
   1031 		    OMX_PRDSP4(pComponentPrivate->dbg, "Flushing Input port timeout Error\n");
   1032                 break;
   1033             }
   1034 #else
   1035             JPEGDEC_WAIT_FLUSH(pComponentPrivate);
   1036 #endif
   1037         }
   1038 
   1039         pComponentPrivate->bFlushComplete = OMX_FALSE;
   1040 
   1041         for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
   1042             JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nCount];
   1043 
   1044         if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1045             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1046             int nRet;
   1047 #ifdef __PERF_INSTRUMENTATION__
   1048                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1049                                   PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
   1050                                   PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
   1051                                   PERF_ModuleLLMM);
   1052 #endif
   1053 
   1054             if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
   1055 		OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from InDir\n", pBuffPrivate->pBufferHdr);
   1056                 pComponentPrivate->nOutPortOut ++;
   1057                  nRet = read(pComponentPrivate->nFree_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1058             }
   1059 
   1060 #if 0  /* since we don't have this queue anymore, there is nothing to flush.  Buffers are handled immediately */
   1061             else if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_OUT) {
   1062 		 OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from OutDir\n", pBuffPrivate->pBufferHdr);
   1063                  nRet = read(pComponentPrivate->nFilled_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1064             }
   1065 #endif
   1066             OMX_PRBUFFER2(pComponentPrivate->dbg, "return output buffer %p in idle (%d)\n", pBuffPrivate->pBufferHdr, pBuffPrivate->eBufferOwner);
   1067             pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1068             pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   1069                                          pComponentPrivate->pHandle->pApplicationPrivate,
   1070                                          pBuffPrivate->pBufferHdr);
   1071             }
   1072         }
   1073 
   1074         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1075                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1076                                        OMX_EventCmdComplete,
   1077                                        OMX_CommandFlush,
   1078                                        JPEGDEC_OUTPUT_PORT,
   1079                                        NULL);
   1080     }
   1081 PRINT_EXIT:
   1082     OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand nFlush Function\n");
   1083 EXIT:
   1084     return eError;
   1085 
   1086 }   /* End of HandleCommandFlush */
   1087 
   1088 
   1089 
   1090 /* ========================================================================== */
   1091 /**
   1092  * @fn HandleCommandJpegDec - andle State type commands. Depending on the
   1093  *  State Command received it executes the corresponding code.
   1094  * @param pComponentPrivate - components private structure
   1095  * @param nParam1 - state to change.
   1096  * @return: OMX_ERRORTYPE
   1097  *          OMX_ErrorNone on success
   1098  *          !OMX_ErrorNone on failure
   1099  */
   1100 /* ========================================================================== */
   1101 OMX_U32 HandleCommandJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate,
   1102                              OMX_U32 nParam1)
   1103 {
   1104     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1105     OMX_COMPONENTTYPE *pHandle = NULL;
   1106     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1107     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   1108     OMX_HANDLETYPE pLcmlHandle = NULL;
   1109     LCML_DSP *lcml_dsp;
   1110     OMX_U16 arr[100];
   1111     LCML_CALLBACKTYPE cb;
   1112     OMX_U8 nCount = 0;
   1113     int    nBufToReturn;
   1114 #ifdef RESOURCE_MANAGER_ENABLED
   1115     OMX_U16 nMHzRM = 0;
   1116     OMX_U32 lImageResolution = 0;
   1117 #endif
   1118 
   1119     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1120 
   1121     OMX_CHECK_PARAM(pComponentPrivate);
   1122     pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
   1123     pPortDefIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef;
   1124     pPortDefOut= pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef;
   1125 
   1126 
   1127     switch ((OMX_STATETYPE)(nParam1))
   1128     {
   1129     case OMX_StateIdle:
   1130 		OMX_PRINT2(pComponentPrivate->dbg, "JPEG HandleCommand: Cmd Idle \n");
   1131         OMX_PRSTATE2(pComponentPrivate->dbg, "CURRENT STATE IS %d\n",pComponentPrivate->nCurState);
   1132         if (pComponentPrivate->nCurState == OMX_StateIdle) {
   1133             eError = OMX_ErrorSameState;
   1134             break;
   1135         }
   1136         else if ((pComponentPrivate->nCurState == OMX_StateLoaded) ||
   1137                     (pComponentPrivate->nCurState == OMX_StateWaitForResources)) {
   1138 
   1139 #ifdef __PERF_INSTRUMENTATION__
   1140             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1141                            PERF_BoundaryStart | PERF_BoundarySetup);
   1142 #endif
   1143 
   1144             OMX_PRSTATE2(pComponentPrivate->dbg, "Transition state from loaded to idle\n");
   1145 
   1146 #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
   1147             pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *)ResourceManagerCallback;
   1148             lImageResolution = pPortDefIn->format.image.nFrameWidth * pPortDefIn->format.image.nFrameHeight;
   1149             OMX_GET_RM_VALUE(lImageResolution, nMHzRM);
   1150             OMX_PRMGR2(pComponentPrivate->dbg, "Value sent to RM = %d\n", nMHzRM);
   1151             if (pComponentPrivate->nCurState != OMX_StateWaitForResources) {
   1152 
   1153                 eError = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, OMX_JPEG_Decoder_COMPONENT, nMHzRM, 3456, &(pComponentPrivate->rmproxyCallback));
   1154 
   1155                 if (eError != OMX_ErrorNone) {
   1156                     /* resource is not available, need set state to OMX_StateWaitForResources*/
   1157                     OMX_PRMGR4(pComponentPrivate->dbg, "Resource is not available\n");
   1158                     eError = OMX_ErrorInsufficientResources;
   1159                     break;
   1160                 }
   1161             }
   1162 #endif
   1163 
   1164             if ((pPortDefIn->bEnabled == OMX_TRUE) &&
   1165                 (pPortDefOut->bEnabled == OMX_TRUE)) {
   1166 
   1167                 while (1) {
   1168                     if ((pPortDefIn->bPopulated) && (pPortDefOut->bPopulated)) {
   1169                         break;
   1170                     }
   1171                     else {
   1172                         JPEGDEC_WAIT_PORT_POPULATION(pComponentPrivate);
   1173 
   1174                     }
   1175                 }
   1176                 if(eError != OMX_ErrorNone){
   1177                     OMX_PRBUFFER4(pComponentPrivate->dbg, "Port population time out\n");
   1178                     goto PRINT_EXIT;
   1179                 }
   1180             }
   1181 
   1182             eError =  GetLCMLHandleJpegDec(pHandle);
   1183             if (eError != OMX_ErrorNone) {
   1184 		OMX_PRDSP5(pComponentPrivate->dbg, "GetLCMLHandle failed...\n");
   1185                 goto PRINT_EXIT;
   1186             }
   1187 
   1188             pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1189             lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
   1190 
   1191             OMX_PRDSP2(pComponentPrivate->dbg, "Fill_LCMLInitParams in JPEG\n");
   1192             Fill_LCMLInitParamsJpegDec(lcml_dsp,arr, pHandle);
   1193 
   1194             cb.LCML_Callback = (void *) LCML_CallbackJpegDec;
   1195 
   1196             if (pComponentPrivate->nIsLCMLActive == 1) {
   1197 		OMX_PRDSP2(pComponentPrivate->dbg, "nIsLCMLActive is active\n");
   1198             }
   1199             /*calling initMMCodec to init codec with details filled earlier */
   1200             eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
   1201             if (eError != OMX_ErrorNone) {
   1202 	        OMX_PRDSP4(pComponentPrivate->dbg, "InitMMCodec failed...\n");
   1203                 goto PRINT_EXIT;
   1204             }
   1205             else {
   1206                 pComponentPrivate->nIsLCMLActive = 1;
   1207             }
   1208             OMX_PRDSP1(pComponentPrivate->dbg, "LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle %p\n" , ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
   1209             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlUsnEos, NULL);
   1210             if (eError != OMX_ErrorNone) {
   1211                 OMX_PRDSP4(pComponentPrivate->dbg, "Enable EOS at LCML failed...\n");
   1212                 goto PRINT_EXIT;
   1213             }
   1214             /* need check the resource with RM */
   1215 
   1216 #ifdef __PERF_INSTRUMENTATION__
   1217             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1218                           PERF_BoundaryComplete | PERF_BoundarySetup);
   1219 #endif
   1220 
   1221 #ifdef RESOURCE_MANAGER_ENABLED
   1222             eError= RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_JPEG_Decoder_COMPONENT, OMX_StateIdle,  3456, NULL);
   1223             if (eError != OMX_ErrorNone) {
   1224 		OMX_PRMGR4(pComponentPrivate->dbg, "Resources not available Loaded ->Idle\n");
   1225                 break;
   1226             }
   1227 #endif
   1228             pComponentPrivate->nCurState = OMX_StateIdle;
   1229 
   1230             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1231                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1232                                                    OMX_EventCmdComplete,
   1233                                                    OMX_CommandStateSet,
   1234                                                    pComponentPrivate->nCurState,
   1235                                                    NULL);
   1236             break;
   1237             OMX_PRSTATE2(pComponentPrivate->dbg, "JPEGDEC: State has been Set to Idle\n");
   1238         }
   1239         else if ((pComponentPrivate->nCurState == OMX_StateExecuting) ||
   1240                  (pComponentPrivate->nCurState == OMX_StatePause)) {
   1241 /*            if (pComponentPrivate->bPreempted == 1){
   1242                     eError = OMX_ErrorResourcesPreempted;
   1243             }
   1244 */
   1245             nCount = 0;
   1246             pComponentPrivate->ExeToIdleFlag = 0;
   1247             OMX_PRDSP2(pComponentPrivate->dbg, "OMX_StateIdle->OMX_StateExecuting-THE CODEC IS STOPPING!!!\n");
   1248             pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1249             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, MMCodecControlStop, NULL);
   1250 #ifdef __PERF_INSTRUMENTATION__
   1251             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1252                           PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1253 #endif
   1254 
   1255 	    OMX_TRACE2(pComponentPrivate->dbg, "before stop lock\n");
   1256         pthread_mutex_lock(&pComponentPrivate->mJpegDecMutex);
   1257         while ((pComponentPrivate->ExeToIdleFlag & JPEGD_DSPSTOP) == 0) {
   1258             pthread_cond_wait(&pComponentPrivate->sStop_cond, &pComponentPrivate->mJpegDecMutex);
   1259         }
   1260         pthread_mutex_unlock(&pComponentPrivate->mJpegDecMutex);
   1261 
   1262 
   1263         nBufToReturn = 0;
   1264         if ((pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent != NULL)  &&
   1265                 (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pParamBufSupplier->eBufferSupplier == OMX_BufferSupplyInput)) {
   1266                 for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual ; nCount++) {
   1267                    JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nCount];
   1268                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Jpeg Returning buffers to Display\n");
   1269 
   1270                    if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1271                        OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1272                        int nRet;
   1273 
   1274 #ifdef __PERF_INSTRUMENTATION__
   1275                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1276                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
   1277                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
   1278                                       PERF_ModuleLLMM);
   1279 #endif
   1280 
   1281                        if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
   1282 			  OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from InDir\n", pBuffPrivate->pBufferHdr);
   1283                           nRet = read(pComponentPrivate->nFree_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1284                        }
   1285 
   1286 #if 0  /* since we don't have this queue anymore, there is nothing to discard.  Buffers are handled immediately */
   1287                        else if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_OUT) {
   1288 			  OMX_PRBUFFER2(pComponentPrivate->dbg, "discard %p from OutDir\n", pBuffPrivate->pBufferHdr);
   1289                           nRet = read(pComponentPrivate->nFilled_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1290                        }
   1291 #endif
   1292                        OMX_PRBUFFER2(pComponentPrivate->dbg, "return output buffer %p in idle (%d)\n", pBuffPrivate->pBufferHdr, pBuffPrivate->eBufferOwner);
   1293                        pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1294 
   1295                        eError = OMX_EmptyThisBuffer(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent,
   1296                                     (OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nCount]->pBufferHdr);
   1297                     }
   1298                  }
   1299         }
   1300         else { /* output port is not tunneled */
   1301             for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
   1302               JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[nCount];
   1303 
   1304               if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1305                 OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1306                 int nRet;
   1307 #ifdef __PERF_INSTRUMENTATION__
   1308                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1309                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
   1310                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[1]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
   1311                                       PERF_ModuleLLMM);
   1312 #endif
   1313 
   1314                 if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
   1315 		     OMX_PRBUFFER2(pComponentPrivate->dbg, "discard %p from InDir\n", pBuffPrivate->pBufferHdr);
   1316                      pComponentPrivate->nOutPortOut ++;
   1317                      nRet = read(pComponentPrivate->nFree_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1318                 }
   1319 #if 0  /* since we don't have this queue anymore, there is nothing to discard.  Buffers are handled immediately */
   1320                 else if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_OUT) {
   1321 		     OMX_PRBUFFER2(pComponentPrivate->dbg, "discard %p from OutDir\n", pBuffPrivate->pBufferHdr);
   1322                      nRet = read(pComponentPrivate->nFilled_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1323                 }
   1324 #endif
   1325                 OMX_PRBUFFER2(pComponentPrivate->dbg, "return output buffer %p in idle (%d)\n", pBuffPrivate->pBufferHdr, pBuffPrivate->eBufferOwner);
   1326                 pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1327                 pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   1328                                                  pComponentPrivate->pHandle->pApplicationPrivate,
   1329                                                  pBuffPrivate->pBufferHdr);
   1330                }
   1331             }
   1332         }
   1333 
   1334         OMX_PRBUFFER2(pComponentPrivate->dbg, "all buffers are returned\n");
   1335 
   1336         nBufToReturn = 0;
   1337         for (nCount = 0; nCount < pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->nBufferCountActual; nCount++) {
   1338               JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pBufferPrivate[nCount];
   1339 
   1340               if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1341                 OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1342                 int nRet;
   1343 #ifdef __PERF_INSTRUMENTATION__
   1344                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1345                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), pBuffer),
   1346                                       PREF(((OMX_BUFFERHEADERTYPE*) pComponentPrivate->pCompPort[0]->pBufferPrivate[nCount]->pBufferHdr), nFilledLen),
   1347                                       PERF_ModuleLLMM);
   1348 #endif
   1349 
   1350                   nBufToReturn ++;
   1351                   if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_COMPONENT_IN) {
   1352 		     OMX_PRBUFFER2(pComponentPrivate->dbg, "disgard %p from InDir\n", pBuffPrivate->pBufferHdr);
   1353                      nRet = read(pComponentPrivate->nFilled_inpBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1354                   }
   1355                   pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1356                   OMX_PRBUFFER2(pComponentPrivate->dbg, "return input buffer %p in idle\n", pBuffPrivate->pBufferHdr);
   1357                   pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
   1358                                                  pComponentPrivate->pHandle->pApplicationPrivate,
   1359                                                  pBuffPrivate->pBufferHdr);
   1360                }
   1361         }
   1362 
   1363 #ifdef RESOURCE_MANAGER_ENABLED
   1364             eError= RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_JPEG_Decoder_COMPONENT, OMX_StateIdle, 3456, NULL);
   1365             if (eError != OMX_ErrorNone) {
   1366                 OMX_PRMGR4(pComponentPrivate->dbg, "Resources not available Executing ->Idle\n");
   1367                 pComponentPrivate->nCurState = OMX_StateWaitForResources;
   1368                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1369                                                        pHandle->pApplicationPrivate,
   1370                                                        OMX_EventCmdComplete,
   1371                                                        OMX_CommandStateSet,
   1372                                                        pComponentPrivate->nCurState,
   1373                                                        NULL);
   1374                 eError = OMX_ErrorNone;
   1375                 break;
   1376             }
   1377 #endif
   1378          pComponentPrivate->nCurState = OMX_StateIdle;
   1379          OMX_PRSTATE2(pComponentPrivate->dbg, "current state is %d\n", pComponentPrivate->nCurState);
   1380          pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1381                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1382                                                    OMX_EventCmdComplete,
   1383                                                    OMX_CommandStateSet,
   1384                                                    OMX_StateIdle,
   1385                                                    NULL);
   1386          pComponentPrivate->ExeToIdleFlag = 0;
   1387          OMX_PRSTATE2(pComponentPrivate->dbg, "JPEG-DEC in idle\n");
   1388         }
   1389         else { /* This means, it is invalid state from application */
   1390 	    OMX_PRSTATE4(pComponentPrivate->dbg, "Error: Invalid State Given by Application\n");
   1391             eError = OMX_ErrorInvalidState;
   1392         }
   1393         break;
   1394 
   1395     case OMX_StateExecuting:
   1396 	OMX_PRINT1(pComponentPrivate->dbg, "HandleCommand: Cmd Executing \n");
   1397         if (pComponentPrivate->nCurState == OMX_StateExecuting) {
   1398             eError = OMX_ErrorSameState;
   1399         }
   1400         else if (pComponentPrivate->nCurState == OMX_StateIdle ||
   1401                   pComponentPrivate->nCurState == OMX_StatePause) {
   1402 
   1403 #ifdef __PERF_INSTRUMENTATION__
   1404             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1405                           PERF_BoundaryStart | PERF_BoundarySteadyState);
   1406 #endif
   1407 
   1408             pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1409             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlStart, NULL);
   1410 
   1411             OMX_PRDSP2(pComponentPrivate->dbg, "eError is %x\n", eError);
   1412 #ifdef RESOURCE_MANAGER_ENABLED
   1413             eError= RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_JPEG_Decoder_COMPONENT, OMX_StateExecuting, 3456, NULL);
   1414             if (eError != OMX_ErrorNone) {
   1415 		OMX_PRMGR4(pComponentPrivate->dbg, "Resources not available\n");
   1416                 pComponentPrivate->nCurState = OMX_StateWaitForResources;
   1417                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1418                                                        pHandle->pApplicationPrivate,
   1419                                                        OMX_EventCmdComplete,
   1420                                                        OMX_CommandStateSet,
   1421                                                        pComponentPrivate->nCurState,
   1422                                                        NULL);
   1423                 eError = OMX_ErrorNone;
   1424                 break;
   1425             }
   1426 #endif
   1427 
   1428             pComponentPrivate->nCurState = OMX_StateExecuting;
   1429             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1430                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1431                                                    OMX_EventCmdComplete,
   1432                                                    OMX_CommandStateSet,
   1433                                                    pComponentPrivate->nCurState,
   1434                                                    NULL);
   1435 	    OMX_PRSTATE2(pComponentPrivate->dbg, "JPEG-DEC in OMX_StateExecuting\n");
   1436         }
   1437         else {
   1438             eError = OMX_ErrorIncorrectStateTransition;
   1439         }
   1440         break;
   1441 
   1442 
   1443     case OMX_StatePause:
   1444 	OMX_PRINT1(pComponentPrivate->dbg, "HandleCommand: Cmd Pause\n");
   1445         if (pComponentPrivate->nCurState == OMX_StatePause) {
   1446             eError = OMX_ErrorSameState;
   1447         }
   1448         else if ((pComponentPrivate->nCurState == OMX_StateIdle) ||
   1449                  (pComponentPrivate->nCurState == OMX_StateExecuting)) {
   1450             pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1451             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlPause, NULL);
   1452             if (eError != OMX_ErrorNone) {
   1453 		OMX_PRDSP4(pComponentPrivate->dbg, "Error during EMMCodecControlPause.. error is %d.\n", eError);
   1454                 break;
   1455             }
   1456 
   1457 #ifdef __PERF_INSTRUMENTATION__
   1458             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1459                           PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1460 #endif
   1461 
   1462             pComponentPrivate->nCurState = OMX_StatePause;
   1463         }
   1464         else {
   1465 	    OMX_PRSTATE4(pComponentPrivate->dbg, "Error: Invalid State Given by Application\n");
   1466             eError = OMX_ErrorIncorrectStateTransition;
   1467         }
   1468         break;
   1469 
   1470     case OMX_StateInvalid:
   1471 	OMX_PRINT1(pComponentPrivate->dbg, "HandleCommand: Cmd OMX_StateInvalid::\n");
   1472         if (pComponentPrivate->nCurState == OMX_StateInvalid) {
   1473             eError = OMX_ErrorSameState;
   1474             break;
   1475         }
   1476         if (pComponentPrivate->nCurState == OMX_StateExecuting
   1477                 || pComponentPrivate->nCurState == OMX_StatePause){
   1478 	    OMX_PRBUFFER2(pComponentPrivate->dbg, "HandleInternalFlush\n\n");
   1479             eError = HandleInternalFlush(pComponentPrivate, OMX_ALL); /*OMX_ALL = -1 OpenMax 1.1*/
   1480             if(eError != OMX_ErrorNone){
   1481 		OMX_PRBUFFER4(pComponentPrivate->dbg, "eError from HandleInternalFlush = %x\n", eError);
   1482                 eError = OMX_ErrorNone; /* Clean error, already sending the component to Invalid state*/
   1483             }
   1484         }
   1485         OMX_PRSTATE2(pComponentPrivate->dbg, "OMX_StateInvalid\n\n");
   1486         pComponentPrivate->nCurState = OMX_StateInvalid;
   1487 
   1488         if(pComponentPrivate->nToState == OMX_StateInvalid){ /*if the IL client call directly send to invalid state*/
   1489             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1490                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1491                                    OMX_EventCmdComplete,
   1492                                    OMX_CommandStateSet,
   1493                                    pComponentPrivate->nCurState,
   1494                                    NULL);
   1495         }
   1496         else{ /*When the component go to invalid state by it self*/
   1497             eError = OMX_ErrorInvalidState;
   1498         }
   1499         break;
   1500 
   1501     case OMX_StateLoaded:
   1502        OMX_PRSTATE2(pComponentPrivate->dbg, "go to loaded state\n");
   1503        if (pComponentPrivate->nCurState == OMX_StateLoaded) {
   1504             eError = OMX_ErrorSameState;
   1505         }
   1506         else if ((pComponentPrivate->nCurState == OMX_StateIdle) ||
   1507                  (pComponentPrivate->nCurState == OMX_StateWaitForResources)) {
   1508 
   1509 #ifdef __PERF_INSTRUMENTATION__
   1510             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1511                           PERF_BoundaryStart | PERF_BoundaryCleanup);
   1512 #endif
   1513 
   1514 #ifdef RESOURCE_MANAGER_ENABLED
   1515             if (pComponentPrivate->nCurState == OMX_StateWaitForResources) {
   1516                 eError= RMProxy_NewSendCommand(pHandle,  RMProxy_CancelWaitForResource, OMX_JPEG_Decoder_COMPONENT, 0, 3456, NULL);
   1517                 if (eError != OMX_ErrorNone) {
   1518 		    OMX_PRMGR4(pComponentPrivate->dbg, "CancelWaitForResource Failed\n");
   1519                     break;
   1520                 }
   1521             }
   1522 
   1523 #endif
   1524 
   1525             /* Ports have to be unpopulated before transition completes */
   1526             while (1) {
   1527                 if ((!pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef->bPopulated) &&
   1528                         (!pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef->bPopulated)) {
   1529                     break;
   1530                 }
   1531                 else {
   1532                     JPEGDEC_WAIT_PORT_UNPOPULATION(pComponentPrivate);
   1533                 }
   1534             }
   1535             if (eError != OMX_ErrorNone){ /*Verify if UnPopulation compleate*/
   1536                 goto PRINT_EXIT;
   1537             }
   1538 
   1539 #ifdef RESOURCE_MANAGER_ENABLED
   1540             if (pComponentPrivate->nCurState != OMX_StateWaitForResources) {
   1541                 eError= RMProxy_NewSendCommand(pHandle,  RMProxy_FreeResource, OMX_JPEG_Decoder_COMPONENT, 0, 3456, NULL);
   1542                 if (eError != OMX_ErrorNone) {
   1543 		    OMX_PRMGR4(pComponentPrivate->dbg, "Cannot Free Resources\n");
   1544                     break;
   1545                 }
   1546             }
   1547 #endif
   1548 
   1549             if ((pComponentPrivate->pLCML != NULL) &&
   1550                 (pComponentPrivate->nIsLCMLActive == 1)) {
   1551                 pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1552                 LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlDestroy, NULL);
   1553                 pComponentPrivate->pLCML = NULL;
   1554                 pComponentPrivate->nIsLCMLActive = 0;
   1555 #ifdef UNDER_CE
   1556                 FreeLibrary(g_hLcmlDllHandle);
   1557                 g_hLcmlDllHandle = NULL;
   1558 #else
   1559                 dlclose(pComponentPrivate->pDllHandle);
   1560                 pComponentPrivate->pDllHandle = NULL;
   1561 #endif
   1562             }
   1563 
   1564 
   1565 #ifdef __PERF_INSTRUMENTATION__
   1566             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1567                           PERF_BoundaryComplete | PERF_BoundaryCleanup);
   1568 #endif
   1569 
   1570             /*Restart Buffer counting*/
   1571             pComponentPrivate->nInPortIn = 0;
   1572             pComponentPrivate->nOutPortOut = 0;
   1573 
   1574             pComponentPrivate->nCurState = OMX_StateLoaded;
   1575 
   1576             if ((pComponentPrivate->nCurState == OMX_StateIdle) &&
   1577                  (pComponentPrivate->bPreempted == 1 )){
   1578                 pComponentPrivate->bPreempted = 0;
   1579                 eError = OMX_ErrorResourcesLost;
   1580             }
   1581             else {
   1582                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1583                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1584                                                        OMX_EventCmdComplete,
   1585                                                        OMX_CommandStateSet,
   1586                                                        OMX_StateLoaded,
   1587                                                        NULL);
   1588             }
   1589        }
   1590         else {
   1591             eError = OMX_ErrorIncorrectStateTransition;
   1592         }
   1593         break;
   1594 
   1595     case OMX_StateWaitForResources:
   1596 
   1597         if (pComponentPrivate->nCurState == OMX_StateWaitForResources) {
   1598             eError = OMX_ErrorSameState;
   1599         }
   1600         else if (pComponentPrivate->nCurState == OMX_StateLoaded) {
   1601 
   1602 #ifdef RESOURCE_MANAGER_ENABLED
   1603             eError= RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_JPEG_Decoder_COMPONENT, OMX_StateWaitForResources, 3456, NULL);
   1604             if (eError != OMX_ErrorNone) {
   1605 		OMX_PRMGR4(pComponentPrivate->dbg, "RMProxy_NewSendCommand(OMX_StateWaitForResources) failed\n");
   1606                 break;
   1607             }
   1608 #endif
   1609 
   1610             pComponentPrivate->nCurState = OMX_StateWaitForResources;
   1611             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1612                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1613                                                    OMX_EventCmdComplete,
   1614                                                    OMX_CommandStateSet,
   1615                                                    pComponentPrivate->nCurState,
   1616                                                    NULL);
   1617         }
   1618         else {
   1619             eError = OMX_ErrorIncorrectStateTransition;
   1620         }
   1621         break;
   1622 
   1623     case OMX_StateMax:
   1624         OMX_PRINT2(pComponentPrivate->dbg, "HandleCommand: Cmd OMX_StateMax::\n");
   1625         break;
   1626     } /* End of Switch */
   1627 
   1628 PRINT_EXIT:
   1629     OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand Function %x\n", eError);
   1630 EXIT:
   1631     return eError;
   1632 }
   1633   /* End of HandleCommandJpegDec */
   1634 
   1635 /* ========================================================================== */
   1636 /**
   1637  * @fn HandleFreeOutputBufferFromAppJpegDec - Handle free output buffer from
   1638  *  application reading in the nFree_outBuf_Q pipe, and queue to the LCML.
   1639  * @param pComponentPrivate - components private structure
   1640  * @param nParam1 - state to change.
   1641  * @return: OMX_ERRORTYPE
   1642  *          OMX_ErrorNone on success
   1643  *          !OMX_ErrorNone on failure
   1644  */
   1645 /* ========================================================================== */
   1646 OMX_ERRORTYPE HandleFreeOutputBufferFromAppJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate)
   1647 {
   1648     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1649     OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1650     JPEGDEC_UAlgOutBufParamStruct *ptJPGDecUALGOutBufParam = NULL;
   1651     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   1652     JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
   1653     int nRet;
   1654 
   1655     OMX_CHECK_PARAM(pComponentPrivate);
   1656     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1657     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1658 
   1659     OMX_PRBUFFER2(pComponentPrivate->dbg, "%s: read outport (in) buff header %p\n", __FUNCTION__, pBuffHead);
   1660 
   1661     nRet = read(pComponentPrivate->nFree_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
   1662 
   1663     if (nRet == -1) {
   1664 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   1665         goto EXIT;
   1666     }
   1667 
   1668 
   1669 
   1670     pBuffPrivate = pBuffHead->pOutputPortPrivate;
   1671 
   1672     if ((pComponentPrivate->nCurState == OMX_StateIdle) || (pComponentPrivate->nToState == OMX_StateIdle)) {
   1673         if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1674 	OMX_PRBUFFER2(pComponentPrivate->dbg, "Going to state %d, return buffer %p to client\n", pComponentPrivate->nToState, pBuffHead);
   1675         pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1676         pComponentPrivate->nOutPortOut ++;
   1677         pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   1678                     pComponentPrivate->pHandle->pApplicationPrivate,
   1679                     pBuffHead);
   1680         }
   1681         goto EXIT;
   1682     }
   1683 
   1684 
   1685     ptJPGDecUALGOutBufParam = (JPEGDEC_UAlgOutBufParamStruct *)pBuffPrivate->pUALGParams;
   1686     ptJPGDecUALGOutBufParam->lOutBufCount = 0;
   1687     ptJPGDecUALGOutBufParam->ulOutNumFrame = 1;
   1688     ptJPGDecUALGOutBufParam->ulOutFrameAlign = 4;
   1689     ptJPGDecUALGOutBufParam->ulOutFrameSize = pBuffHead->nAllocLen;
   1690 
   1691     pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_DSP;
   1692 
   1693 #ifdef __PERF_INSTRUMENTATION__
   1694     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1695                       pBuffHead->pBuffer,
   1696                       pBuffHead->nFilledLen,
   1697                       PERF_ModuleCommonLayer);
   1698 #endif
   1699 
   1700     eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1701                               EMMCodecOuputBuffer,
   1702                               pBuffHead->pBuffer,
   1703                               pBuffHead->nAllocLen,
   1704                               pBuffHead->nFilledLen,
   1705                               (OMX_U8*)ptJPGDecUALGOutBufParam,
   1706                               sizeof(JPEGDEC_UAlgOutBufParamStruct),
   1707                               (OMX_U8*)pBuffHead);
   1708     if (eError != OMX_ErrorNone) {
   1709         goto EXIT;
   1710     }
   1711 EXIT:
   1712     return eError;
   1713 }   /* end of HandleFreeOutputBufferFromAppJpegDec */
   1714 
   1715 
   1716 /* ========================================================================== */
   1717 /**
   1718  * @fn HandleDataBuf_FromAppJpegDec - Handle data to be encoded form
   1719  *  application and queue to the LCML.
   1720  * @param pComponentPrivate - components private structure
   1721  * @param nParam1 - state to change.
   1722  * @return: OMX_ERRORTYPE
   1723  *          OMX_ErrorNone on success
   1724  *          !OMX_ErrorNone on failure
   1725  */
   1726 /* ========================================================================== */
   1727 OMX_ERRORTYPE HandleDataBuf_FromAppJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate)
   1728 {
   1729     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1730     OMX_BUFFERHEADERTYPE* pBuffHead =  NULL;
   1731     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   1732     JPEGDEC_UAlgInBufParamStruct *ptJPGDecUALGInBufParam = NULL;
   1733     JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
   1734     int nRet;
   1735 
   1736     OMX_CHECK_PARAM(pComponentPrivate);
   1737     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1738     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1739 
   1740     nRet = read(pComponentPrivate->nFilled_inpBuf_Q[0], &(pBuffHead), sizeof(pBuffHead));
   1741     if (nRet == -1) {
   1742 	OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   1743     }
   1744 
   1745     OMX_PRBUFFER2(pComponentPrivate->dbg, "HandleDataBuf_FromAppJpegDec: read inport (in) buff header %p\n", pBuffHead);
   1746 
   1747     pBuffPrivate = pBuffHead->pInputPortPrivate;
   1748     if ((pComponentPrivate->nCurState == OMX_StateIdle) || (pComponentPrivate->nToState == OMX_StateIdle)) {
   1749         pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1750         OMX_PRBUFFER2(pComponentPrivate->dbg, "Going to state %d, return buffer %p to client\n", pComponentPrivate->nToState, pBuffHead);
   1751 
   1752         pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
   1753                     pComponentPrivate->pHandle->pApplicationPrivate,
   1754                     pBuffHead);
   1755         goto EXIT;
   1756     }
   1757 
   1758     ptJPGDecUALGInBufParam = (JPEGDEC_UAlgInBufParamStruct *)pBuffPrivate->pUALGParams;
   1759     ptJPGDecUALGInBufParam->ulAlphaRGB = 0xFF;
   1760     ptJPGDecUALGInBufParam->lInBufCount = 0;
   1761     ptJPGDecUALGInBufParam->ulInNumFrame = 1;
   1762     ptJPGDecUALGInBufParam->ulInFrameAlign = 4;
   1763     ptJPGDecUALGInBufParam->ulInFrameSize = pBuffHead->nFilledLen;
   1764     ptJPGDecUALGInBufParam->ulInDisplayWidth = (int)pComponentPrivate->nInputFrameWidth;
   1765     ptJPGDecUALGInBufParam->ulInResizeOption = (int)pComponentPrivate->pScalePrivate->xWidth;
   1766     /*Slide decode*/
   1767     ptJPGDecUALGInBufParam->ulNumMCURow = (int)pComponentPrivate->pSectionDecode->nMCURow;
   1768     ptJPGDecUALGInBufParam->ulnumAU = (int)pComponentPrivate->pSectionDecode->nAU;
   1769     /*Section decode*/
   1770     ptJPGDecUALGInBufParam->ulXOrg = (int)pComponentPrivate->pSubRegionDecode->nXOrg;
   1771     ptJPGDecUALGInBufParam->ulYOrg = (int)pComponentPrivate->pSubRegionDecode->nYOrg;
   1772     ptJPGDecUALGInBufParam->ulXLength = (int)pComponentPrivate->pSubRegionDecode->nXLength;
   1773     ptJPGDecUALGInBufParam->ulYLength = (int)pComponentPrivate->pSubRegionDecode->nYLength;
   1774 
   1775 
   1776     if (pComponentPrivate->nOutputColorFormat == OMX_COLOR_FormatCbYCrY) {
   1777         ptJPGDecUALGInBufParam->forceChromaFormat= 4;
   1778         ptJPGDecUALGInBufParam->RGB_Format = 9; /*RGB_Format should be set even if it's not use*/
   1779     }
   1780     else if (pComponentPrivate->nOutputColorFormat == OMX_COLOR_Format16bitRGB565) {
   1781         ptJPGDecUALGInBufParam->forceChromaFormat =  9;
   1782         ptJPGDecUALGInBufParam->RGB_Format = 9;
   1783     }
   1784     else if (pComponentPrivate->nOutputColorFormat == OMX_COLOR_Format24bitRGB888) {
   1785         ptJPGDecUALGInBufParam->forceChromaFormat = 10;
   1786         ptJPGDecUALGInBufParam->RGB_Format = 10;
   1787     }
   1788     else if (pComponentPrivate->nOutputColorFormat == OMX_COLOR_Format32bitARGB8888 ||
   1789 			pComponentPrivate->nOutputColorFormat == OMX_COLOR_Format32bitBGRA8888 ) {
   1790         ptJPGDecUALGInBufParam->forceChromaFormat = 11;
   1791         ptJPGDecUALGInBufParam->RGB_Format = 11;
   1792     }
   1793     else { /*Set DEFAULT (Original) color format*/
   1794         ptJPGDecUALGInBufParam->forceChromaFormat = 1;
   1795         ptJPGDecUALGInBufParam->RGB_Format = 9; /*RGB_Format should be set even if it's not use*/
   1796     }
   1797     OMX_PRDSP0(pComponentPrivate->dbg, "ptJPGDecUALGInBufParam->forceChromaFormat = %lu\n", ptJPGDecUALGInBufParam->forceChromaFormat );
   1798     pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_DSP;
   1799 
   1800 #ifdef __PERF_INSTRUMENTATION__
   1801     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1802                       pBuffHead->pBuffer,
   1803                       pBuffHead->nFilledLen,
   1804                       PERF_ModuleCommonLayer);
   1805 #endif
   1806 
   1807     OMX_PRDSP0(pComponentPrivate->dbg, "forceChromaFormat\t= %lu\n", ptJPGDecUALGInBufParam->forceChromaFormat);
   1808     OMX_PRDSP0(pComponentPrivate->dbg, "RGB_Format\t= %lu\n", ptJPGDecUALGInBufParam->RGB_Format);
   1809     OMX_PRDSP0(pComponentPrivate->dbg, "ulInFrameSize\t= %lu\n", ptJPGDecUALGInBufParam->ulInFrameSize);
   1810     OMX_PRDSP0(pComponentPrivate->dbg, "ulInDisplayWidth\t= %lu\n", ptJPGDecUALGInBufParam->ulInDisplayWidth);
   1811     OMX_PRDSP0(pComponentPrivate->dbg, "ulInResizeOption\t= %lu\n", ptJPGDecUALGInBufParam->ulInResizeOption);
   1812     OMX_PRDSP0(pComponentPrivate->dbg, "ulNumMCURow\t= %lu\n", ptJPGDecUALGInBufParam->ulNumMCURow);
   1813     OMX_PRDSP0(pComponentPrivate->dbg, "ulnumAU\t= %lu\n", ptJPGDecUALGInBufParam->ulnumAU);
   1814     OMX_PRDSP0(pComponentPrivate->dbg, "ulXOrg\t= %lu    ", ptJPGDecUALGInBufParam->ulXOrg);
   1815     OMX_PRDSP0(pComponentPrivate->dbg, "ulYOrg\t= %lu\n", ptJPGDecUALGInBufParam->ulYOrg);
   1816     OMX_PRDSP0(pComponentPrivate->dbg, "ulXLength\t= %lu    ", ptJPGDecUALGInBufParam->ulXLength);
   1817     OMX_PRDSP0(pComponentPrivate->dbg, "ulXLenght\t= %lu\n", ptJPGDecUALGInBufParam->ulYLength);
   1818     OMX_PRBUFFER0(pComponentPrivate->dbg, "pBuffHead->nFlags\t= %lu\n", pBuffHead->nFlags);
   1819     OMX_PRBUFFER0(pComponentPrivate->dbg, "Queue INPUT bufheader %p\n", pBuffHead);
   1820     eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   1821                               EMMCodecInputBuffer,
   1822                               pBuffHead->pBuffer,
   1823                               pBuffHead->nAllocLen,
   1824                               pBuffHead->nFilledLen,
   1825                               (OMX_U8 *) ptJPGDecUALGInBufParam,
   1826                               sizeof(JPEGDEC_UAlgInBufParamStruct),
   1827                               (OMX_U8 *)pBuffHead);
   1828 
   1829     if (eError != OMX_ErrorNone) {
   1830         goto EXIT;
   1831     }
   1832 
   1833 EXIT:
   1834     return eError;
   1835 }   /* End of HandleDataBuf_FromAppJpegDec */
   1836 
   1837 
   1838 /* ========================================================================== */
   1839 /**
   1840  * @fn HandleDataBuf_FromDspJpegDec - Handle encoded data form DSP and
   1841  *  render to application or another component.
   1842  * @param pComponentPrivate - components private structure
   1843  * @param nParam1 - state to change.
   1844  * @return: OMX_ERRORTYPE
   1845  *          OMX_ErrorNone on success
   1846  *          !OMX_ErrorNone on failure
   1847  */
   1848 /* ========================================================================== */
   1849 OMX_ERRORTYPE HandleDataBuf_FromDspJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE* pBuffHead)
   1850 {
   1851     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1852     JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
   1853 
   1854     OMX_CHECK_PARAM(pComponentPrivate);
   1855     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1856 
   1857     OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer Came From DSP (output port)\n");
   1858 
   1859     pBuffPrivate = pBuffHead->pOutputPortPrivate;
   1860 
   1861     if (pBuffHead->pMarkData && pBuffHead->hMarkTargetComponent == pComponentPrivate->pHandle) {
   1862 	OMX_PRBUFFER2(pComponentPrivate->dbg, "send OMX_MarkEvent\n");
   1863         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1864                                         pComponentPrivate->pHandle->pApplicationPrivate,
   1865                                         OMX_EventMark,
   1866                                         JPEGDEC_OUTPUT_PORT,
   1867                                         0,
   1868                                         pBuffHead->pMarkData);
   1869     }
   1870 
   1871     /*TUNNEL HERE*/
   1872     if (pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent != NULL) {
   1873 	OMX_PRBUFFER2(pComponentPrivate->dbg, "Jpeg Sending Output buffer to TUNNEL component\n");
   1874 
   1875 #ifdef __PERF_INSTRUMENTATION__
   1876         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1877                           pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[0]->pBufferHdr->pBuffer,
   1878                           pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pBufferPrivate[0]->pBufferHdr->nFilledLen,
   1879                           PERF_ModuleLLMM);
   1880 #endif
   1881 
   1882         pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_TUNNEL_COMPONENT;
   1883         eError = OMX_EmptyThisBuffer(pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent, pBuffHead);
   1884     }
   1885     else {
   1886 
   1887 #ifdef __PERF_INSTRUMENTATION__
   1888         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1889                           pBuffHead->pBuffer,
   1890                           pBuffHead->nFilledLen,
   1891                           PERF_ModuleHLMM);
   1892 #endif
   1893 
   1894 
   1895         if (pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) {
   1896 	    OMX_PRBUFFER2(pComponentPrivate->dbg, "%s::%d:Received OMX_BUFFERFLAG_EOS, nFalgs= %lx\n", __FUNCTION__, __LINE__, pBuffHead->nFlags);
   1897             pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
   1898                                                 pComponentPrivate->pHandle->pApplicationPrivate,
   1899                                                 OMX_EventBufferFlag,
   1900                                                 JPEGDEC_OUTPUT_PORT,
   1901                                                 pBuffHead->nFlags,
   1902                                                 NULL);
   1903         }
   1904 
   1905         OMX_PRBUFFER1(pComponentPrivate->dbg, "HandleDataBuf_FromDspJpegDec: buf %p pBuffPrivate->eBufferOwner %d\n", pBuffHead, pBuffPrivate->eBufferOwner);
   1906         if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1907             pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1908 
   1909             pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   1910                                                  pComponentPrivate->pHandle->pApplicationPrivate,
   1911                                                  pBuffHead);
   1912         }
   1913     }
   1914 
   1915 
   1916     OMX_PRINT1(pComponentPrivate->dbg, "Exit\n");
   1917 EXIT:
   1918     return eError;
   1919 }   /* End of HandleDataBuf_FromDspJpegDec */
   1920 
   1921 
   1922 
   1923 /* ========================================================================== */
   1924 /**
   1925  * @fn HandleFreeDataBufJpegDec - Handle emptied input data from DSP and
   1926  *  return to application or another component.
   1927  * @param pComponentPrivate - components private structure
   1928  * @param nParam1 - state to change.
   1929  * @return: OMX_ERRORTYPE
   1930  *          OMX_ErrorNone on success
   1931  *          !OMX_ErrorNone on failure
   1932  */
   1933 /* ========================================================================== */
   1934 OMX_ERRORTYPE HandleFreeDataBufJpegDec(JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE* pBuffHead )
   1935 {
   1936     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1937     JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
   1938 
   1939     OMX_CHECK_PARAM(pComponentPrivate);
   1940     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1941 
   1942     OMX_PRINT1(pComponentPrivate->dbg, "JPEG Entering HandleFreeBuf Function\n");
   1943 
   1944     pBuffPrivate = pBuffHead->pInputPortPrivate;
   1945 
   1946     if (pBuffPrivate->eBufferOwner != JPEGDEC_BUFFER_CLIENT) {
   1947         pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_CLIENT;
   1948 
   1949 #ifdef __PERF_INSTRUMENTATION__
   1950         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1951                       PREF(pBuffHead,pBuffer),
   1952                       0,
   1953                       PERF_ModuleHLMM);
   1954 #endif
   1955 
   1956         OMX_PRBUFFER2(pComponentPrivate->dbg, "emptydone buf %p\n", pBuffHead);
   1957 
   1958         pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
   1959                                               pComponentPrivate->pHandle->pApplicationPrivate,
   1960                                               pBuffHead);
   1961     }
   1962 
   1963     OMX_PRINT1(pComponentPrivate->dbg, "JPEGexiting\n");
   1964 EXIT:
   1965     return eError;
   1966 }   /* End of HandleFreeDataBufJpegDec */
   1967 
   1968 
   1969 
   1970 /* ========================================================================== */
   1971 /**
   1972  *  LCML_CallbackJpegDec() - handle callbacks from LCML
   1973  * @param pComponentPrivate    handle for this instance of the component
   1974  * @param argsCb = argument list
   1975  * @return: OMX_ERRORTYPE
   1976  *          OMX_ErrorNone on success
   1977  *          !OMX_ErrorNone on failure
   1978   **/
   1979 /* ========================================================================== */
   1980 OMX_ERRORTYPE LCML_CallbackJpegDec (TUsnCodecEvent event,
   1981                                     void * argsCb [10])
   1982 {
   1983     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1984     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1985     OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
   1986     JPEGDEC_UAlgInBufParamStruct * ptJPGDecUALGInBufParam = NULL;
   1987     JPEGDEC_PORT_TYPE *pPortType = NULL;
   1988     OMX_U8* pBuffer = NULL;
   1989     JPEGDEC_BUFFER_PRIVATE* pBuffPrivate = NULL;
   1990     int i = 0;
   1991 
   1992     if ( ((LCML_DSP_INTERFACE*)argsCb[6] ) != NULL ) {
   1993         pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)argsCb[6])->pComponentPrivate;
   1994     }
   1995     else {
   1996         OMXDBG_PRINT(stderr, ERROR, 5, 0, "wrong in LCML callback, exit\n");
   1997         goto EXIT;
   1998     }
   1999 
   2000     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2001 
   2002     if (event == EMMCodecBufferProcessed) {
   2003         if ((int)argsCb [0] == EMMCodecOuputBuffer) {
   2004             pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7];
   2005             pBuffer = (OMX_U8*)argsCb[1];
   2006             pBuffPrivate = pBuffHead->pOutputPortPrivate;
   2007             pBuffHead->nFilledLen = (int)argsCb[8];
   2008             OMX_PRDSP1(pComponentPrivate->dbg, "nFilled Len from DSP = %d\n",(int)argsCb[8]);
   2009 
   2010 #ifdef __PERF_INSTRUMENTATION__
   2011             PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
   2012                                pBuffer,
   2013                                (OMX_U32) argsCb[2],
   2014                                PERF_ModuleCommonLayer);
   2015 #endif
   2016 
   2017         if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_DSP) {
   2018             pComponentPrivate->nOutPortOut ++;
   2019         }
   2020 
   2021         OMX_PRDSP2(pComponentPrivate->dbg, "Filled Data from DSP \n");
   2022         OMX_PRBUFFER1(pComponentPrivate->dbg, "buffer summary (LCML for output buffer %p) %lu %lu\n", pBuffHead,
   2023                     pComponentPrivate->nInPortIn,
   2024                     pComponentPrivate->nOutPortOut);
   2025 
   2026         pPortType = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT];
   2027         if((pBuffHead->nFlags == OMX_FALSE) && (pComponentPrivate->pSectionDecode->nMCURow == OMX_FALSE)){
   2028 		for (i = 0; i < (int)(pPortType->pPortDef->nBufferCountActual); i ++) {
   2029                 if (pPortType->sBufferFlagTrack[i].buffer_id == pComponentPrivate->nOutPortOut) {
   2030 		    OMX_PRBUFFER1(pComponentPrivate->dbg, "JPEGdec:: %d: output buffer %lu has flag %lx\n", __LINE__,
   2031                                pPortType->sBufferFlagTrack[i].buffer_id,
   2032                                pPortType->sBufferFlagTrack[i].flag);
   2033                     pBuffHead->nFlags = pPortType->sBufferFlagTrack[i].flag;
   2034                     pPortType->sBufferFlagTrack[i].flag = 0;
   2035                     pPortType->sBufferFlagTrack[i].buffer_id = 0xFFFFFFFF;
   2036                     break;
   2037                 }
   2038             }
   2039         }else{
   2040 		for (i = 0; i < (int)pPortType->pPortDef->nBufferCountActual; i ++) {
   2041                 if (pPortType->sBufferFlagTrack[i].buffer_id == pComponentPrivate->nOutPortOut) {
   2042 		    OMX_PRBUFFER1(pComponentPrivate->dbg, "JPEGdec:: %d: OUTPUT buffer %lu has flag %lx\n", __LINE__,
   2043                                pPortType->sBufferFlagTrack[i].buffer_id,
   2044                                pPortType->sBufferFlagTrack[i].flag);
   2045                     if(pPortType->sBufferFlagTrack[i].flag & OMX_BUFFERFLAG_EOS){
   2046                         pPortType->sBufferFlagTrack[i].flag = pPortType->sBufferFlagTrack[i].flag & (!(OMX_BUFFERFLAG_EOS));
   2047                         pBuffHead->nFlags |= pPortType->sBufferFlagTrack[i].flag;
   2048                     }
   2049                     pPortType->sBufferFlagTrack[i].flag = 0;
   2050                     pPortType->sBufferFlagTrack[i].buffer_id = 0xFFFFFFFF;
   2051                     break;
   2052                 }
   2053             }
   2054         }
   2055         for (i = 0; i < (int)pPortType->pPortDef->nBufferCountActual; i ++) {
   2056             if (pPortType->sBufferMarkTrack[i].buffer_id == pComponentPrivate->nOutPortOut) {
   2057 		OMX_PRBUFFER2(pComponentPrivate->dbg, "buffer ID %lu has mark (output port)\n", pPortType->sBufferMarkTrack[i].buffer_id);
   2058                 pBuffHead->pMarkData = pPortType->sBufferMarkTrack[i].pMarkData;
   2059                 pBuffHead->hMarkTargetComponent = pPortType->sBufferMarkTrack[i].hMarkTargetComponent;
   2060                 pPortType->sBufferMarkTrack[i].buffer_id = 0xFFFFFFFF;
   2061                 break;
   2062             }
   2063         }
   2064         if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_DSP) {
   2065             pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_COMPONENT_OUT;
   2066             eError = HandleDataBuf_FromDspJpegDec(pComponentPrivate, pBuffHead);
   2067             if (eError != OMX_ErrorNone) {
   2068 		OMX_PRBUFFER4(pComponentPrivate->dbg, "Error while reading dsp out q\n");
   2069                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2070                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   2071                                                        OMX_EventError,
   2072                                                        OMX_ErrorUndefined,
   2073                                                        OMX_TI_ErrorSevere,
   2074                                                        "Error from Component Thread while processing dsp Responses");
   2075             }
   2076         }
   2077         }
   2078         if ((int) argsCb [0] == EMMCodecInputBuffer) {
   2079             pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7];
   2080             ptJPGDecUALGInBufParam = (JPEGDEC_UAlgInBufParamStruct *)argsCb[3];
   2081             pBuffer = (OMX_U8*)argsCb[1];
   2082             pBuffPrivate = pBuffHead->pInputPortPrivate;
   2083 
   2084 #ifdef __PERF_INSTRUMENTATION__
   2085             PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
   2086                                pBuffer,
   2087                                (OMX_U32) argsCb[8],
   2088                                PERF_ModuleCommonLayer);
   2089 #endif
   2090             if (pBuffPrivate->eBufferOwner == JPEGDEC_BUFFER_DSP) {
   2091                 pBuffPrivate->eBufferOwner = JPEGDEC_BUFFER_COMPONENT_OUT;
   2092                 eError = HandleFreeDataBufJpegDec(pComponentPrivate, pBuffHead);
   2093                 if (eError != OMX_ErrorNone) {
   2094 		    OMX_PRBUFFER4(pComponentPrivate->dbg, "Error while processing free input Buffers\n");
   2095                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2096                                                            pComponentPrivate->pHandle->pApplicationPrivate,
   2097                                                            OMX_EventError,
   2098                                                            OMX_ErrorUndefined,
   2099                                                            OMX_TI_ErrorSevere,
   2100                                                            "Error while processing free input buffers");
   2101                 }
   2102             }
   2103         }
   2104     }
   2105 
   2106     if (event == EMMCodecProcessingStoped) {
   2107 	OMX_PRDSP2(pComponentPrivate->dbg, "ENTERING TO EMMCodecProcessingStoped \n\n");
   2108         if (pComponentPrivate->nToState == OMX_StateIdle) {
   2109             pComponentPrivate->ExeToIdleFlag |= JPEGD_DSPSTOP;
   2110         }
   2111 
   2112         pthread_mutex_lock(&pComponentPrivate->mJpegDecMutex);
   2113         pthread_cond_signal(&pComponentPrivate->sStop_cond);
   2114         pthread_mutex_unlock(&pComponentPrivate->mJpegDecMutex);
   2115 
   2116         goto EXIT;
   2117     }
   2118     if (event == EMMCodecDspError) {
   2119 	OMX_PRDSP1(pComponentPrivate->dbg, "LCML_Callback : DSP [0]->%x, [4]->%x, [5]->%x\n", (int)argsCb[0] ,(int)argsCb[4], (int)argsCb[5]);
   2120         OMX_PRDSP1(pComponentPrivate->dbg, "Play compleated if: 0x500 = %x\n", (int)argsCb[5]);
   2121         if(!((int)argsCb[5] == 0x500)){
   2122             eError = OMX_ErrorHardware;
   2123             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2124                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2125                                                    OMX_EventError,
   2126                                                    OMX_ErrorHardware,
   2127                                                    OMX_TI_ErrorCritical,
   2128                                                    NULL);
   2129             pComponentPrivate->nCurState = OMX_StateInvalid;
   2130             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2131                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2132                                                    OMX_EventError,
   2133                                                    OMX_ErrorInvalidState,
   2134                                                    OMX_TI_ErrorCritical,
   2135                                                    "DSP Hardware Error");
   2136         }
   2137         goto EXIT;
   2138 
   2139 #ifdef DSP_MMU_FAULT_HANDLING
   2140         /* Cheking for MMU_fault */
   2141         if((argsCb[4] == (void *)NULL) && (argsCb[5] == (void*)NULL)) {
   2142             pComponentPrivate->nCurState = OMX_StateInvalid;
   2143             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2144                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2145                                                    OMX_EventError,
   2146                                                    OMX_ErrorInvalidState,
   2147                                                    OMX_TI_ErrorCritical,
   2148                                                    "DSP MMU FAULT");
   2149         }
   2150 #endif
   2151     }
   2152 
   2153     if (event == EMMCodecInternalError) {
   2154         eError = OMX_ErrorHardware;
   2155         OMX_PRDSP4(pComponentPrivate->dbg, "JPEG-D: EMMCodecInternalError\n");
   2156         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2157                                                pComponentPrivate->pHandle->pApplicationPrivate,
   2158                                                OMX_EventError,
   2159                                                OMX_ErrorHardware,
   2160                                                OMX_TI_ErrorCritical,
   2161                                                NULL);
   2162         goto EXIT;
   2163     }
   2164     if (event == EMMCodecProcessingPaused) {
   2165         pComponentPrivate->nCurState = OMX_StatePause;
   2166         /* Send StateChangeNotification to application */
   2167         OMX_PRDSP2(pComponentPrivate->dbg, "ENTERING TO EMMCodecProcessingPaused \n");
   2168         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2169                                                pComponentPrivate->pHandle->pApplicationPrivate,
   2170                                                OMX_EventCmdComplete,
   2171                                                OMX_CommandStateSet,
   2172                                                pComponentPrivate->nCurState,
   2173                                                NULL);
   2174     }
   2175     if (event == EMMCodecStrmCtrlAck) {
   2176 	OMX_PRDSP1(pComponentPrivate->dbg, "event = EMMCodecStrmCtrlAck\n");
   2177         if ((int)argsCb [0] == USN_ERR_NONE) {
   2178 	    OMX_PRDSP1(pComponentPrivate->dbg, "Callback: no error\n");
   2179             pComponentPrivate->bFlushComplete = OMX_TRUE;
   2180             pthread_mutex_lock(&(pComponentPrivate->mJpegDecFlushMutex));
   2181             pthread_cond_signal(&(pComponentPrivate->sFlush_cond));
   2182             pthread_mutex_unlock(&(pComponentPrivate->mJpegDecFlushMutex));
   2183        }
   2184     }
   2185 
   2186 
   2187     OMX_PRDSP1(pComponentPrivate->dbg, "Exiting the LCML_Callback function\n");
   2188 EXIT:
   2189     return eError;
   2190 }   /* End of LCML_CallbackJpegDec */
   2191 
   2192 
   2193 
   2194 #ifdef RESOURCE_MANAGER_ENABLED
   2195 /* ========================================================================== */
   2196 /**
   2197  *  ResourceManagerCallback() - handle callbacks from Resource Manager
   2198  * @param cbData    Resource Manager Command Data Structure
   2199  * @return: void
   2200   **/
   2201 /* ========================================================================== */
   2202 
   2203 void ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
   2204 {
   2205     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   2206     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
   2207     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   2208     OMX_ERRORTYPE eError = *(cbData.RM_Error);
   2209 
   2210     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2211 
   2212     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2213 
   2214     OMX_PRINT1(pComponentPrivate->dbg, "RM_Error = %x\n", eError);
   2215 
   2216     if (eError == OMX_RmProxyCallback_ResourcesPreempted) {
   2217 
   2218         pComponentPrivate->bPreempted = 1;
   2219 
   2220         if (pComponentPrivate->nCurState == OMX_StateExecuting ||
   2221             pComponentPrivate->nCurState == OMX_StatePause) {
   2222 
   2223             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2224                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2225                                                    OMX_EventError,
   2226                                                    OMX_ErrorResourcesPreempted,
   2227                                                    OMX_TI_ErrorSevere,
   2228                                                    NULL);
   2229 
   2230             pComponentPrivate->nToState = OMX_StateIdle;
   2231             OMX_PRMGR2(pComponentPrivate->dbg, "Component Preempted. Going to IDLE State.\n");
   2232         }
   2233         else if (pComponentPrivate->nCurState == OMX_StateIdle){
   2234             pComponentPrivate->nToState = OMX_StateLoaded;
   2235             OMX_PRMGR2(pComponentPrivate->dbg, "Component Preempted. Going to LOADED State.\n");
   2236         }
   2237 
   2238 #ifdef __PERF_INSTRUMENTATION__
   2239         PERF_SendingCommand(pComponentPrivate->pPERF, Cmd, pComponentPrivate->nToState, PERF_ModuleComponent);
   2240 #endif
   2241 
   2242         write (pComponentPrivate->nCmdPipe[1], &Cmd, sizeof(Cmd));
   2243         write (pComponentPrivate->nCmdDataPipe[1], &(pComponentPrivate->nToState) ,sizeof(OMX_U32));
   2244 
   2245     }
   2246     else if (eError == OMX_RmProxyCallback_ResourcesAcquired ){
   2247 
   2248         if (pComponentPrivate->nCurState == OMX_StateWaitForResources) /* Wait for Resource Response */
   2249         {
   2250             pComponentPrivate->cbInfo.EventHandler (
   2251     	                        pHandle, pHandle->pApplicationPrivate,
   2252     	                        OMX_EventResourcesAcquired, 0,0,
   2253     	                        NULL);
   2254 
   2255             pComponentPrivate->nToState = OMX_StateIdle;
   2256 
   2257 #ifdef __PERF_INSTRUMENTATION__
   2258             PERF_SendingCommand(pComponentPrivate->pPERF, Cmd, pComponentPrivate->nToState, PERF_ModuleComponent);
   2259 #endif
   2260 
   2261             write (pComponentPrivate->nCmdPipe[1], &Cmd, sizeof(Cmd));
   2262             write (pComponentPrivate->nCmdDataPipe[1], &(pComponentPrivate->nToState) ,sizeof(OMX_U32));
   2263             OMX_PRMGR2(pComponentPrivate->dbg, "OMX_RmProxyCallback_ResourcesAcquired.\n");
   2264         }
   2265 
   2266     }
   2267     EXIT:
   2268         OMX_PRMGR2(pComponentPrivate->dbg, "OMX_RmProxyCallback exiting.\n");
   2269 }
   2270 #endif
   2271 
   2272 
   2273 
   2274 
   2275 /*-------------------------------------------------------------------*/
   2276 /**
   2277   * IsTIOMXComponent()
   2278   *
   2279   * Check if the component is TI component.
   2280   *
   2281   * @param hTunneledComp Component Tunnel Pipe
   2282   *
   2283   * @retval OMX_TRUE   Input is a TI component.
   2284   *         OMX_FALSE  Input is a not a TI component.
   2285   *
   2286   **/
   2287 /*-------------------------------------------------------------------*/
   2288 OMX_BOOL IsTIOMXComponent(OMX_HANDLETYPE hComp)
   2289 {
   2290     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2291     OMX_STRING pTunnelcComponentName = NULL;
   2292     OMX_VERSIONTYPE* pTunnelComponentVersion = NULL;
   2293     OMX_VERSIONTYPE* pSpecVersion = NULL;
   2294     OMX_UUIDTYPE* pComponentUUID = NULL;
   2295     char *pSubstring = NULL;
   2296     OMX_BOOL bResult = OMX_TRUE;
   2297 
   2298     OMX_MALLOC(pTunnelcComponentName, 128);
   2299     OMX_MALLOC(pTunnelComponentVersion, sizeof(OMX_VERSIONTYPE));
   2300     OMX_MALLOC(pSpecVersion, sizeof(OMX_VERSIONTYPE));
   2301     OMX_MALLOC(pComponentUUID, sizeof(OMX_UUIDTYPE));
   2302 
   2303     eError = OMX_GetComponentVersion (hComp, pTunnelcComponentName, pTunnelComponentVersion, pSpecVersion, pComponentUUID);
   2304 
   2305     /* Check if tunneled component is a TI component */
   2306     pSubstring = strstr(pTunnelcComponentName, "OMX.TI.");
   2307     if(pSubstring == NULL) {
   2308         bResult = OMX_FALSE;
   2309     }
   2310 
   2311 EXIT:
   2312     OMX_FREE(pTunnelcComponentName);
   2313     OMX_FREE(pTunnelComponentVersion);
   2314     OMX_FREE(pSpecVersion);
   2315     OMX_FREE(pComponentUUID);
   2316     return bResult;
   2317 } /* End of IsTIOMXComponent */
   2318 
   2319 void LinkedList_Create(LinkedList *LinkedList) {
   2320     LinkedList->pRoot = NULL;
   2321 }
   2322 
   2323 void LinkedList_AddElement(LinkedList *LinkedList, void *pValue) {
   2324     /* create new node and fill the value */
   2325     Node *pNewNode = (Node *)malloc(sizeof(Node));
   2326     if ( pNewNode != NULL )  {
   2327         pNewNode->pValue = (void *)pValue;
   2328         /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */
   2329         /* add new node on the root to implement quick FIFO */
   2330         /* modify new node pointers */
   2331         if(LinkedList->pRoot == NULL) {
   2332             pNewNode->pNextNode = NULL;
   2333         }
   2334         else {
   2335              pNewNode->pNextNode = LinkedList->pRoot;
   2336         }
   2337         /*modify root */
   2338         LinkedList->pRoot = pNewNode;
   2339     }
   2340 }
   2341 
   2342 void LinkedList_FreeElement(LinkedList *LinkedList, void *pValue) {
   2343     Node *pNode = LinkedList->pRoot;
   2344     Node *pPastNode = NULL;
   2345     while (pNode != NULL) {
   2346         if (pNode->pValue == pValue) {
   2347             Node *pTempNode = pNode->pNextNode;
   2348             if(pPastNode == NULL) {
   2349                 LinkedList->pRoot = pTempNode;
   2350             }
   2351             else {
   2352                 pPastNode->pNextNode = pTempNode;
   2353             }
   2354             /*printf("LinkedList:::: Pointer=%p has been freed\n", pNode->pValue); */
   2355             free(pNode->pValue);
   2356             free(pNode);
   2357             break;
   2358         }
   2359         pPastNode = pNode;
   2360         pNode = pNode->pNextNode;
   2361     }
   2362 }
   2363 
   2364 void LinkedList_FreeAll(LinkedList *LinkedList) {
   2365     Node *pTempNode;
   2366     int nodes = 0;
   2367     while (LinkedList->pRoot != NULL) {
   2368         pTempNode = LinkedList->pRoot->pNextNode;
   2369         /*printf("LinkedList:::: Pointer=%p has been freed\n", LinkedList->pRoot->pValue); */
   2370         free(LinkedList->pRoot->pValue);
   2371         free(LinkedList->pRoot);
   2372         LinkedList->pRoot = pTempNode;
   2373         nodes++;
   2374     }
   2375     /*printf("==================No. of deleted nodes: %d=======================================\n\n", nodes); */
   2376 }
   2377 
   2378 void LinkedList_DisplayAll(LinkedList *LinkedList) {
   2379     Node *pNode = LinkedList->pRoot;
   2380     int nodes = 0;
   2381     printf("\n================== Displaying contents of linked list=%p=====================\n", LinkedList);
   2382     printf("root->\n");
   2383     while (pNode != NULL) {
   2384         printf("[Value=%p, NextNode=%p]->\n", pNode->pValue, pNode->pNextNode);
   2385         pNode = pNode->pNextNode;
   2386         nodes++;
   2387     }
   2388      printf("==================No. of existing nodes: %d=======================================\n\n", nodes);
   2389 }
   2390 
   2391 void LinkedList_Destroy(LinkedList *LinkedList) {
   2392     /* do nothing */
   2393 }
   2394 
   2395 
   2396