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  * @file OMX_G726Dec_Utils.c
     30  *
     31  * This file implements various utilitiy functions for various activities
     32  * like handling command from application, callback from LCML etc.
     33  *
     34  * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g726_dec\src
     35  *
     36  * @rev  1.0
     37  */
     38 /* ----------------------------------------------------------------------------
     39  *!
     40  *! Revision History
     41  *! ===================================
     42  *! 21-sept-2006 bk: updated some review findings for alpha release
     43  *! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more
     44  *! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases
     45  *! This is newest file
     46  * =========================================================================== */
     47 /* ------compilation control switches -------------------------*/
     48 /****************************************************************
     49  *  INCLUDE FILES
     50  ****************************************************************/
     51 /* ----- system and platform files ----------------------------*/
     52 
     53 #ifdef UNDER_CE
     54 #include <windows.h>
     55 #include <oaf_osal.h>
     56 #include <omx_core.h>
     57 #include <stdlib.h>
     58 #else
     59 #include <unistd.h>
     60 #include <sys/types.h>
     61 #include <sys/stat.h>
     62 #include <dlfcn.h>
     63 #include <malloc.h>
     64 #include <memory.h>
     65 #include <fcntl.h>
     66 #endif
     67 
     68 #include <pthread.h>
     69 #include <dbapi.h>
     70 #include <string.h>
     71 #include <stdio.h>
     72 
     73 /*------- Program Header Files -----------------------------------------------*/
     74 #include "LCML_DspCodec.h"
     75 #include "OMX_G726Dec_Utils.h"
     76 #include "g726decsocket_ti.h"
     77 
     78 #ifdef RESOURCE_MANAGER_ENABLED
     79 #include <ResourceManagerProxyAPI.h>
     80 #endif
     81 
     82 
     83 #ifdef UNDER_CE
     84 #define HASHINGENABLE 1
     85 #endif
     86 
     87 #ifndef UNDER_CE
     88 #define G726DEC_DPRINT_ON(...)  fprintf(stdout, "%s %d::  ",__FUNCTION__, __LINE__); \
     89     fprintf(stdout, __VA_ARGS__);                                       \
     90     fprintf(stdout, "\n");
     91 #endif
     92 
     93 /* ================================================================================= * */
     94 /**
     95  * @fn G726DEC_Fill_LCMLInitParams() fills the LCML initialization structure.
     96  *
     97  * @param pHandle This is component handle allocated by the OMX core.
     98  *
     99  * @param plcml_Init This structure is filled and sent to LCML.
    100  *
    101  * @pre          None
    102  *
    103  * @post         None
    104  *
    105  *  @return      OMX_ErrorNone = Successful Inirialization of the LCML struct.
    106  *               OMX_ErrorInsufficientResources = Not enough memory
    107  *
    108  *  @see         None
    109  */
    110 /* ================================================================================ * */
    111 OMX_ERRORTYPE G726DEC_Fill_LCMLInitParams(OMX_HANDLETYPE pComponent,
    112                                           LCML_DSP *plcml_Init, OMX_U16 arr[])
    113 {
    114     OMX_ERRORTYPE eError = OMX_ErrorNone;
    115     OMX_U32 nIpBuf = 0,nIpBufSize = 0,nOpBuf = 0,nOpBufSize = 0;
    116     OMX_U32 i = 0;
    117     OMX_BUFFERHEADERTYPE *pTemp = NULL;
    118     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    119     G726DEC_COMPONENT_PRIVATE *pComponentPrivate =
    120         (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    121     G726D_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
    122     OMX_U32 size_lcml = 0;
    123     /*int inputPortFlag=0,outputPortFlag=0;*/
    124     LCML_STRMATTR *strmAttr = NULL;
    125     OMX_U8 *ptemp = NULL;
    126 
    127     G726DEC_DPRINT(":: Entered Fill_LCMLInitParams");
    128 
    129     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_INPUT_PORT]->bPopulated  %d \n",
    130                    __LINE__,pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated);
    131     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_INPUT_PORT]->bEnabled    %d \n",
    132                    __LINE__,pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled);
    133     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_OUTPUT_PORT]->bPopulated %d \n",
    134                    __LINE__,pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated);
    135     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_OUTPUT_PORT]->bEnabled   %d \n",
    136                    __LINE__,pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled);
    137 
    138     pComponentPrivate->strmAttr = NULL;
    139 
    140     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
    141     pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
    142     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
    143     pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
    144     nIpBufSize = pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nBufferSize;
    145     nOpBufSize = pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferSize;
    146 
    147     G726DEC_BUFPRINT("Input Buffer Count = %ld\n",nIpBuf);
    148     G726DEC_BUFPRINT("Input Buffer Size = %ld\n",nIpBufSize);
    149     G726DEC_BUFPRINT("LCML::Output Buffer Count = %ld\n",nOpBuf);
    150     G726DEC_BUFPRINT("Output Buffer Size = %ld\n",nOpBufSize);
    151 
    152     plcml_Init->In_BufInfo.nBuffers = nIpBuf;
    153     plcml_Init->In_BufInfo.nSize = nIpBufSize;
    154     plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
    155     plcml_Init->Out_BufInfo.nBuffers = nOpBuf;
    156     plcml_Init->Out_BufInfo.nSize = nOpBufSize;
    157     plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
    158 
    159     G726D_OMX_MALLOC_SIZE(pComponentPrivate->pParams,(sizeof(G726D_USN_AudioCodecParams) + 256),
    160                           G726D_USN_AudioCodecParams);
    161     ptemp = (OMX_U8*)pComponentPrivate->pParams;
    162     ptemp += 128;
    163     pComponentPrivate->pParams = (G726D_USN_AudioCodecParams*)ptemp;
    164 
    165 
    166     plcml_Init->NodeInfo.nNumOfDLLs = 3;
    167 
    168     memset(plcml_Init->NodeInfo.AllUUIDs[0].DllName,0,
    169            sizeof(plcml_Init->NodeInfo.AllUUIDs[0].DllName));
    170     memset(plcml_Init->NodeInfo.AllUUIDs[1].DllName,0,
    171            sizeof(plcml_Init->NodeInfo.AllUUIDs[1].DllName));
    172     memset(plcml_Init->NodeInfo.AllUUIDs[2].DllName,0,
    173            sizeof(plcml_Init->NodeInfo.AllUUIDs[1].DllName));
    174     memset(plcml_Init->NodeInfo.AllUUIDs[0].DllName,0,
    175            sizeof(plcml_Init->DeviceInfo.AllUUIDs[1].DllName));
    176 
    177     plcml_Init->NodeInfo.AllUUIDs[0].uuid = &G726DECSOCKET_TI_UUID;
    178     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName, G726DEC_DLL_NAME);
    179     plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
    180 
    181     plcml_Init->NodeInfo.AllUUIDs[1].uuid = &G726DECSOCKET_TI_UUID;
    182     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName, G726DEC_DLL_NAME);
    183     plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
    184 
    185     plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
    186     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName, USN_DLL_NAME);
    187     plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
    188 
    189     plcml_Init->SegID = OMX_G726DEC_DEFAULT_SEGMENT;
    190     plcml_Init->Timeout = OMX_G726DEC_SN_TIMEOUT;
    191     plcml_Init->Alignment = 0;
    192     plcml_Init->Priority = OMX_G726DEC_SN_PRIORITY;
    193     plcml_Init->ProfileID = 0;
    194 
    195 
    196 
    197     G726DEC_BUFPRINT("DLL name0 = %s\n",plcml_Init->NodeInfo.AllUUIDs[0].DllName);
    198     G726DEC_BUFPRINT("DLL name1 = %s\n",plcml_Init->NodeInfo.AllUUIDs[1].DllName);
    199     G726DEC_BUFPRINT("DLL name2 = %s\n",plcml_Init->NodeInfo.AllUUIDs[2].DllName);
    200 
    201     if(pComponentPrivate->dasfmode == 1) {
    202 #ifndef DSP_RENDERING_ON
    203         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources,
    204                              "Flag DSP_RENDERING_ON Must Be Defined To Use Rendering");
    205 #else
    206         G726D_OMX_MALLOC(strmAttr,LCML_STRMATTR);
    207         pComponentPrivate->strmAttr = strmAttr;
    208         G726DEC_DPRINT(":: G726 DECODER IS RUNNING UNDER DASF MODE \n");
    209         strmAttr->uSegid = OMX_G726DEC_DEFAULT_SEGMENT;
    210         strmAttr->uAlignment = 0;
    211         strmAttr->uTimeout = OMX_G726DEC_SN_TIMEOUT;
    212         strmAttr->uBufsize = nOpBufSize;
    213         strmAttr->uNumBufs = 2;  /*G726D_NUM_OUTPUT_BUFFERS;*/
    214         strmAttr->lMode = STRMMODE_PROCCOPY;
    215         plcml_Init->DeviceInfo.TypeofDevice = 1;
    216         plcml_Init->DeviceInfo.TypeofRender = 0;
    217         plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
    218         plcml_Init->DeviceInfo.DspStream = strmAttr;
    219 #endif
    220     } else {
    221         plcml_Init->DeviceInfo.TypeofDevice = 0;
    222     }
    223     if (pComponentPrivate->dasfmode == 0){
    224         G726DEC_DPRINT(":: FILE MODE CREATE PHASE PARAMETERS\n");
    225         arr[0] = 2;
    226         arr[1] = 0;
    227         arr[2] = 0;
    228         if(pComponentPrivate->pInputBufferList->numBuffers == 0) {
    229             arr[3] = G726D_NUM_INPUT_BUFFERS;
    230         } else {
    231             arr[3] = (OMX_U16) nIpBuf;
    232         }
    233         arr[4] = 1;
    234         arr[5] = 0;
    235         if(pComponentPrivate->pOutputBufferList->numBuffers == 0) {
    236             arr[6] = G726D_NUM_OUTPUT_BUFFERS;
    237         } else {
    238             arr[6] = (OMX_U16) nOpBuf;
    239         }
    240     } else {
    241         G726DEC_DPRINT(":: DASF MODE CREATE PHASE PARAMETERS\n");
    242         arr[0] = 2;
    243         arr[1] = 0;
    244         arr[2] = 0;
    245 
    246         if(pComponentPrivate->pInputBufferList->numBuffers == 0) {
    247             arr[3] = G726D_NUM_INPUT_BUFFERS;
    248         } else {
    249             arr[3] = (OMX_U16) nIpBuf;
    250         }
    251         arr[4] = 1;
    252         arr[5] = 2;
    253         arr[6] = 2;
    254     }
    255     /* TO DO: dynamically adjust arr[7] arr[8] for bit rate and packing mode */
    256     if (pComponentPrivate->G726Params->eG726Mode == OMX_AUDIO_G726Mode16){
    257         G726DEC_DPRINT("setting bit rate = 0\n");
    258         arr[7] = 0;
    259     }
    260     else if (pComponentPrivate->G726Params->eG726Mode == OMX_AUDIO_G726Mode24){
    261         G726DEC_DPRINT("setting bit rate = 1\n");
    262         arr[7] = 1;
    263     }
    264     else if (pComponentPrivate->G726Params->eG726Mode == OMX_AUDIO_G726Mode32){
    265         G726DEC_DPRINT("setting bit rate = 2\n");
    266         arr[7] = 2;
    267     }
    268     else if (pComponentPrivate->G726Params->eG726Mode == OMX_AUDIO_G726Mode40){
    269         G726DEC_DPRINT("setting bit rate = 3\n");
    270         arr[7] = 3;
    271     }
    272     arr[8] = pComponentPrivate->packingType; /* 0 = linear, 1 = rtp packing */
    273     G726DEC_DPRINT("Using arr[8] = %d packing type\n", arr[8]);
    274     arr[9] = END_OF_CR_PHASE_ARGS;
    275     plcml_Init->pCrPhArgs = arr;
    276     G726DEC_DPRINT(":: bufAlloced = %d\n",pComponentPrivate->bufAlloced);
    277     size_lcml = nIpBuf * sizeof(G726D_LCML_BUFHEADERTYPE);
    278     G726D_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,G726D_LCML_BUFHEADERTYPE);
    279     pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT] = pTemp_lcml;
    280 
    281     for (i=0; i<nIpBuf; i++) {
    282 
    283         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
    284 
    285         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    286         G726DEC_DPRINT("IP: pTemp->nSize = %ld\n",pTemp->nSize);
    287 
    288         /*pTemp->nAllocLen = nIpBufSize;*/
    289         pTemp->nFilledLen = nIpBufSize;
    290         pTemp->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
    291         pTemp->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
    292 
    293         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    294         pTemp->nTickCount = DONT_CARE;
    295 
    296         pTemp_lcml->pBufHdr = pTemp;
    297         pTemp_lcml->eDir = OMX_DirInput;
    298         pTemp_lcml->pOtherParams[i] = NULL;
    299 
    300         G726D_OMX_MALLOC(pTemp_lcml->pFrameParam,G726DEC_UAlgInBufParamStruct);
    301 
    302 
    303 
    304         pTemp->nFlags = NORMAL_BUFFER;
    305         ((G726DEC_COMPONENT_PRIVATE *) pTemp->pPlatformPrivate)->pHandle = pHandle;
    306 
    307         G726DEC_DPRINT("::Comp: InBuffHeader[%ld] = %p\n", i, pTemp);
    308         G726DEC_DPRINT("::Comp:  >>>> InputBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer);
    309         G726DEC_DPRINT("::Comp: Ip : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml);
    310         pTemp_lcml++;
    311     }
    312 
    313     size_lcml = nOpBuf * sizeof(G726D_LCML_BUFHEADERTYPE);
    314     G726D_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,G726D_LCML_BUFHEADERTYPE);
    315 
    316     pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT] = pTemp_lcml;
    317 
    318     for (i=0; i<nOpBuf; i++) {
    319         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
    320         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    321         pTemp->nAllocLen = nOpBufSize;
    322         pTemp->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
    323         pTemp->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
    324         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    325         pTemp->nTickCount = DONT_CARE;
    326 
    327         pTemp_lcml->pBufHdr = pTemp;
    328         pTemp_lcml->eDir = OMX_DirOutput;
    329         pTemp_lcml->pOtherParams[i] = NULL;
    330 
    331         pTemp->nFlags = NORMAL_BUFFER;
    332         ((G726DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
    333         G726DEC_DPRINT("::Comp:  >>>>>>>>>>>>> OutBuffHeader[%ld] = %p\n", i, pTemp);
    334         G726DEC_DPRINT("::Comp:  >>>> OutBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer);
    335         G726DEC_DPRINT("::Comp: Op : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml);
    336         pTemp_lcml++;
    337     }
    338 
    339     pComponentPrivate->bPortDefsAllocated = 1;
    340     pComponentPrivate->bInitParamsInitialized = 1;
    341 
    342  EXIT:
    343     if(eError == OMX_ErrorInsufficientResources || eError == OMX_ErrorBadParameter){
    344         G726D_OMX_FREE(strmAttr);
    345         G726D_OMX_FREE(pTemp_lcml);
    346     }
    347     G726DEC_DPRINT("Exiting G726DEC_Fill_LCMLInitParams\n");
    348     return eError;
    349 }
    350 
    351 /* ================================================================================= * */
    352 /**
    353  * @fn G726Dec_StartCompThread() starts the component thread. This is internal
    354  * function of the component.
    355  *
    356  * @param pHandle This is component handle allocated by the OMX core.
    357  *
    358  * @pre          None
    359  *
    360  * @post         None
    361  *
    362  *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
    363  *               OMX_ErrorInsufficientResources = Not enough memory
    364  *
    365  *  @see         None
    366  */
    367 /* ================================================================================ * */
    368 OMX_ERRORTYPE G726Dec_StartCompThread(OMX_HANDLETYPE pComponent)
    369 {
    370     OMX_ERRORTYPE eError = OMX_ErrorNone;
    371     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    372     G726DEC_COMPONENT_PRIVATE *pComponentPrivate =
    373         (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    374     int nRet = 0;
    375 #ifdef UNDER_CE
    376     pthread_attr_t attr;
    377     memset(&attr, 0, sizeof(attr));
    378     attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
    379     attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY;
    380 #endif
    381 
    382     G726DEC_DPRINT (":: Enetering  G726Dec_StartCompThread()\n");
    383 
    384     pComponentPrivate->lcml_nOpBuf = 0;
    385     pComponentPrivate->lcml_nIpBuf = 0;
    386     pComponentPrivate->app_nBuf = 0;
    387     pComponentPrivate->num_Op_Issued = 0;
    388     pComponentPrivate->num_Sent_Ip_Buff = 0;
    389     pComponentPrivate->num_Reclaimed_Op_Buff = 0;
    390     pComponentPrivate->bIsEOFSent = 0;
    391 
    392     nRet = pipe (pComponentPrivate->dataPipe);
    393     if (0 != nRet) {
    394         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources,
    395                              "Pipe Creation Failed");
    396     }
    397 
    398     nRet = pipe (pComponentPrivate->cmdPipe);
    399     if (0 != nRet) {
    400         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources,
    401                              "Pipe Creation Failed");
    402     }
    403 
    404     nRet = pipe (pComponentPrivate->cmdDataPipe);
    405     if (0 != nRet) {
    406         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources,
    407                              "Pipe Creation Failed");
    408     }
    409 
    410 #ifdef UNDER_CE
    411     nRet = pthread_create (&(pComponentPrivate->ComponentThread), &attr,
    412                            G726DEC_ComponentThread, pComponentPrivate);
    413 #else
    414     nRet = pthread_create (&(pComponentPrivate->ComponentThread), NULL,
    415                            G726DEC_ComponentThread, pComponentPrivate);
    416 #endif
    417     if ((0 != nRet) || (!pComponentPrivate->ComponentThread)) {
    418         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources,
    419                              "Thread Creation Failed");
    420     }
    421 
    422     pComponentPrivate->bCompThreadStarted = 1;
    423     G726DEC_DPRINT (":: Exiting from G726Dec_StartCompThread()\n");
    424 
    425  EXIT:
    426     return eError;
    427 }
    428 
    429 
    430 /* ================================================================================= * */
    431 /**
    432  * @fn G726DEC_FreeCompResources() function frees the component resources.
    433  *
    434  * @param pComponent This is the component handle.
    435  *
    436  * @pre          None
    437  *
    438  * @post         None
    439  *
    440  *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
    441  *               OMX_ErrorHardware = Hardware error has occured.
    442  *
    443  *  @see         None
    444  */
    445 /* ================================================================================ * */
    446 OMX_ERRORTYPE G726DEC_FreeCompResources(OMX_HANDLETYPE pComponent)
    447 {
    448     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    449     G726DEC_COMPONENT_PRIVATE *pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
    450         pHandle->pComponentPrivate;
    451     OMX_ERRORTYPE eError = OMX_ErrorNone;
    452     OMX_U32 nIpBuf=0, nOpBuf=0;
    453     int nRet=0;
    454 
    455     G726DEC_DPRINT (":: G726Dec_FreeCompResources\n");
    456 
    457     G726DEC_DPRINT(":::pComponentPrivate->bPortDefsAllocated = %ld\n",
    458                    pComponentPrivate->bPortDefsAllocated);
    459     if (pComponentPrivate->bPortDefsAllocated) {
    460         nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
    461         nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
    462     }
    463     G726DEC_DPRINT(":: Closing pipess.....\n");
    464 
    465     nRet = close (pComponentPrivate->dataPipe[0]);
    466     if (0 != nRet && OMX_ErrorNone == eError) {
    467         eError = OMX_ErrorHardware;
    468     }
    469 
    470     nRet = close (pComponentPrivate->dataPipe[1]);
    471     if (0 != nRet && OMX_ErrorNone == eError) {
    472         eError = OMX_ErrorHardware;
    473     }
    474 
    475     nRet = close (pComponentPrivate->cmdPipe[0]);
    476     if (0 != nRet && OMX_ErrorNone == eError) {
    477         eError = OMX_ErrorHardware;
    478     }
    479 
    480     nRet = close (pComponentPrivate->cmdPipe[1]);
    481     if (0 != nRet && OMX_ErrorNone == eError) {
    482         eError = OMX_ErrorHardware;
    483     }
    484 
    485     nRet = close (pComponentPrivate->cmdDataPipe[0]);
    486     if (0 != nRet && OMX_ErrorNone == eError) {
    487         eError = OMX_ErrorHardware;
    488     }
    489 
    490     nRet = close (pComponentPrivate->cmdDataPipe[1]);
    491     if (0 != nRet && OMX_ErrorNone == eError) {
    492         eError = OMX_ErrorHardware;
    493     }
    494 
    495     if (pComponentPrivate->bPortDefsAllocated) {
    496         G726D_OMX_FREE(pComponentPrivate->pPortDef[G726D_INPUT_PORT]);
    497         G726D_OMX_FREE(pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]);
    498         G726D_OMX_FREE(pComponentPrivate->G726Params);
    499         G726D_OMX_FREE(pComponentPrivate->PcmParams);
    500         G726D_OMX_FREE(pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat);
    501         G726D_OMX_FREE(pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat);
    502         G726D_OMX_FREE(pComponentPrivate->pCompPort[G726D_INPUT_PORT]);
    503         G726D_OMX_FREE(pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]);
    504         G726D_OMX_FREE(pComponentPrivate->sPortParam);
    505         G726D_OMX_FREE(pComponentPrivate->pPriorityMgmt);
    506         G726D_OMX_FREE(pComponentPrivate->pInputBufferList);
    507         G726D_OMX_FREE(pComponentPrivate->pOutputBufferList);
    508         G726D_OMX_FREE(pComponentPrivate->componentRole);
    509     }
    510 
    511     pComponentPrivate->bPortDefsAllocated = 0;
    512 
    513 #ifndef UNDER_CE
    514     G726DEC_DPRINT("\n\n FreeCompResources: Destroying mutexes.\n\n");
    515     pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
    516     pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
    517 
    518     pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
    519     pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
    520 
    521     pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
    522     pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
    523 #else
    524     OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
    525     OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
    526     OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
    527 #endif
    528 
    529     return eError;
    530 }
    531 
    532 /* ================================================================================= * */
    533 /**
    534  * @fn G726DEC_HandleCommand() function handles the command sent by the application.
    535  * All the state transitions, except from nothing to loaded state, of the
    536  * component are done by this function.
    537  *
    538  * @param pComponentPrivate  This is component's private date structure.
    539  *
    540  * @pre          None
    541  *
    542  * @post         None
    543  *
    544  *  @return      OMX_ErrorNone = Successful processing.
    545  *               OMX_ErrorInsufficientResources = Not enough memory
    546  *               OMX_ErrorHardware = Hardware error has occured lile LCML failed
    547  *               to do any said operartion.
    548  *
    549  *  @see         None
    550  */
    551 /* ================================================================================ * */
    552 OMX_U32 G726DEC_HandleCommand (G726DEC_COMPONENT_PRIVATE *pComponentPrivate)
    553 {
    554     OMX_U32 i = 0,ret = 0;
    555     OMX_ERRORTYPE eError = OMX_ErrorNone;
    556     char *pArgs = "damedesuStr";
    557     OMX_COMPONENTTYPE *pHandle =
    558         (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
    559     OMX_COMMANDTYPE command;
    560     OMX_STATETYPE commandedState = OMX_StateInvalid;
    561     OMX_U32 commandData = 0;
    562     OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
    563     OMX_U16 arr[10] = {0};
    564 
    565 #ifdef RESOURCE_MANAGER_ENABLED
    566     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
    567 #endif
    568     G726DEC_DPRINT (":: >>> Entering HandleCommand Function\n");
    569 
    570     ret = read (pComponentPrivate->cmdPipe[0], &command, sizeof (command));
    571     if(ret == -1){
    572         G726DEC_DPRINT ("%d :: Error in Reading from the Data pipe\n", __LINE__);
    573         eError = OMX_ErrorHardware;
    574         goto EXIT;
    575     }
    576     ret = read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
    577     if(ret == -1){
    578         G726DEC_DPRINT ("%d :: Error in Reading from the Data pipe\n", __LINE__);
    579         eError = OMX_ErrorHardware;
    580         goto EXIT;
    581     }
    582     G726DEC_DPRINT("---------------------------------------------\n");
    583     G726DEC_DPRINT(":: command = %d\n",command);
    584     G726DEC_DPRINT(":: commandData = %ld\n",commandData);
    585     G726DEC_DPRINT("---------------------------------------------\n");
    586 
    587     if (command == OMX_CommandStateSet) {
    588         commandedState = (OMX_STATETYPE)commandData;
    589         if (pComponentPrivate->curState == commandedState) {
    590             pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
    591                                                     OMX_EventError, OMX_ErrorSameState,0,
    592                                                     NULL);
    593             G726DEC_DPRINT(":: Error: Same State Given by Application\n");
    594         } else {
    595             switch(commandedState) {
    596             case OMX_StateIdle:
    597                 G726DEC_DPRINT(": HandleCommand: Cmd Idle \n");
    598                 if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->curState == OMX_StateWaitForResources) {
    599                     LCML_CALLBACKTYPE cb;
    600                     LCML_DSP *pLcmlDsp = NULL;
    601                     char *p = "damedesuStr";
    602                     int inputPortFlag=0,outputPortFlag=0;
    603 
    604                     if (pComponentPrivate->dasfmode == 1) {
    605                         pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled= FALSE;
    606                         pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated= FALSE;
    607                         if(pComponentPrivate->streamID == 0) {
    608                             G726DEC_DPRINT("**************************************\n");
    609                             G726DEC_DPRINT(":: Error = OMX_ErrorInsufficientResources\n");
    610                             G726DEC_DPRINT("**************************************\n");
    611                             eError = OMX_ErrorInsufficientResources;
    612                             pComponentPrivate->curState = OMX_StateInvalid;
    613                             pComponentPrivate->cbInfo.EventHandler(pHandle,
    614                                                                    pHandle->pApplicationPrivate,
    615                                                                    OMX_EventError, OMX_ErrorInvalidState,
    616                                                                    0,
    617                                                                    NULL);
    618                             goto EXIT;
    619                         }
    620                     }
    621 
    622                     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_INPUT_PORT]->bPopulated  %d \n",
    623                                    __LINE__,pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated);
    624                     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_INPUT_PORT]->bEnabled    %d \n",
    625                                    __LINE__,pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled);
    626                     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_OUTPUT_PORT]->bPopulated %d \n",
    627                                    __LINE__,pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated);
    628                     G726DEC_DPRINT("%d :: OMX_StateLoaded [G726D_OUTPUT_PORT]->bEnabled   %d \n",
    629                                    __LINE__,pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled);
    630 
    631                     if (pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated &&
    632                         pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled)  {
    633                         inputPortFlag = 1;
    634                     }
    635                     if (!pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated &&
    636                         !pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled) {
    637                         inputPortFlag = 1;
    638                     }
    639                     if (pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated &&
    640                         pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled) {
    641                         outputPortFlag = 1;
    642                     }
    643                     if (!pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated &&
    644                         !pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled) {
    645                         outputPortFlag = 1;
    646                     }
    647                     if (!(inputPortFlag && outputPortFlag)) {
    648                         pComponentPrivate->InLoaded_readytoidle = 1;
    649 #ifndef UNDER_CE
    650                         pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
    651                         pthread_cond_wait(&pComponentPrivate->InLoaded_threshold,
    652                                           &pComponentPrivate->InLoaded_mutex);
    653                         pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
    654 #else
    655                         OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
    656 #endif
    657                     }
    658 
    659                     pLcmlHandle = (OMX_HANDLETYPE) G726DEC_GetLCMLHandle(pComponentPrivate);
    660                     if (pLcmlHandle == NULL) {
    661                         G726DEC_EPRINT(":: LCML Handle is NULL........exiting..\n");
    662                         pComponentPrivate->curState = OMX_StateInvalid;
    663                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    664                                                                OMX_EventError, OMX_ErrorInvalidState,
    665                                                                0, NULL);
    666                         goto EXIT;
    667                     }
    668 
    669                     pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
    670                     eError = G726DEC_Fill_LCMLInitParams(pHandle, pLcmlDsp, arr);
    671                     if(eError != OMX_ErrorNone) {
    672                         G726DEC_EPRINT(":: Error returned from Fill_LCMLInitParams()\n");
    673                         pComponentPrivate->curState = OMX_StateInvalid;
    674                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    675                                                                OMX_EventError, OMX_ErrorInvalidState,
    676                                                                0, NULL);
    677                         goto EXIT;
    678                     }
    679 
    680                     pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
    681                     cb.LCML_Callback = (void *) G726DEC_LCML_Callback;
    682 
    683 #ifndef UNDER_CE
    684 
    685                     eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
    686                                                 p,&pLcmlHandle,(void *)p,
    687                                                 &cb,(OMX_STRING)pComponentPrivate->sDeviceString);
    688                     if (eError != OMX_ErrorNone){
    689                         G726DEC_EPRINT("%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__);
    690                         goto EXIT;
    691                     }
    692 
    693 #else
    694 
    695                     eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
    696                                               p,&pLcmlHandle,(void *)p,&cb);
    697 
    698                     if (eError != OMX_ErrorNone){
    699                         G726DEC_EPRINT("%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__);
    700                         goto EXIT;
    701                     }
    702 #endif
    703 
    704 #ifdef HASHINGENABLE
    705                     /* Enable the Hashing Code */
    706                     eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    707                                                   OMX_TRUE);
    708                     if (eError != OMX_ErrorNone) {
    709                         G726DEC_EPRINT("Failed to set Mapping State\n");
    710                         goto EXIT;
    711                     }
    712 #endif
    713 
    714 #ifdef RESOURCE_MANAGER_ENABLED
    715                     /* need check the resource with RM */
    716                     pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) G726DEC_ResourceManagerCallback;
    717                     if (pComponentPrivate->curState != OMX_StateWaitForResources) {
    718                         rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, OMX_PCM_Decoder_COMPONENT, G726DEC_CPU , 3456,&
    719                                                           (pComponentPrivate->rmproxyCallback));
    720                         if(rm_error == OMX_ErrorNone) {
    721                             /* resource is available */
    722                             pComponentPrivate->curState = OMX_StateIdle;
    723                             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
    724                         }
    725                         else if(rm_error == OMX_ErrorInsufficientResources) {
    726                             /* resource is not available, need set state to OMX_StateWaitForResources */
    727                             pComponentPrivate->curState = OMX_StateWaitForResources;
    728                             pComponentPrivate->cbInfo.EventHandler(pHandle,
    729                                                                    pHandle->pApplicationPrivate,
    730                                                                    OMX_EventCmdComplete,
    731                                                                    OMX_CommandStateSet,
    732                                                                    pComponentPrivate->curState,
    733                                                                    NULL);
    734                             G726DEC_EPRINT("%d :: OMX_AmrDec_Utils.c :: AMRDEC: Error - insufficient resources\n", __LINE__);
    735                         }
    736                     }
    737                     else {
    738                         rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
    739                     }
    740                     pComponentPrivate->curState = OMX_StateIdle;
    741 
    742                     pComponentPrivate->cbInfo.EventHandler(
    743                                                            pHandle,
    744                                                            pHandle->pApplicationPrivate,
    745                                                            OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState, NULL);
    746 
    747 #else
    748                     G726DEC_DPRINT(":: Control Came Here\n");
    749                     G726DEC_STATEPRINT("****************** Component State Set to Idle\n\n");
    750                     pComponentPrivate->curState = OMX_StateIdle;
    751                     pComponentPrivate->cbInfo.EventHandler(pHandle,
    752                                                            pHandle->pApplicationPrivate,
    753                                                            OMX_EventCmdComplete,
    754                                                            OMX_CommandStateSet,
    755                                                            pComponentPrivate->curState,
    756                                                            NULL);
    757 #endif
    758 
    759                     G726DEC_DPRINT("G726DEC: State has been Set to Idle\n");
    760 
    761                 } else if (pComponentPrivate->curState == OMX_StateExecuting) {
    762 #ifdef HASHINGENABLE
    763                     /*Hashing Change*/
    764                     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    765                     /* clear out any mappings that might have accumulated */
    766                     eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    767                     if (eError != OMX_ErrorNone) {
    768                         G726DEC_EPRINT("Error occurred in Codec mapping flush!\n");
    769                         break;
    770                     }
    771 #endif
    772                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
    773                     G726DEC_DPRINT(":: In HandleCommand: Stopping the codec\n");
    774                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    775                                                MMCodecControlStop,(void *)pArgs);
    776                     if(eError != OMX_ErrorNone) {
    777                         G726DEC_EPRINT(": Error Occurred in Codec Stop..\n");
    778                         pComponentPrivate->curState = OMX_StateInvalid;
    779                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    780                                                                OMX_EventError, OMX_ErrorInvalidState,0, NULL);
    781                         goto EXIT;
    782                     }
    783                 } else if(pComponentPrivate->curState == OMX_StatePause) {
    784                     char *pArgs = "damedesuStr";
    785 #ifdef HASHINGENABLE
    786                     /*Hashing Change*/
    787                     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    788                     /* clear out any mappings that might have accumulated */
    789                     eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    790                     if (eError != OMX_ErrorNone) {
    791                         G726DEC_EPRINT("Error occurred in Codec mapping flush!\n");
    792                         break;
    793                     }
    794 #endif
    795                     G726DEC_DPRINT(":: Comp: Stop Command Received\n");
    796                     G726DEC_DPRINT(": G726DECUTILS::About to call LCML_ControlCodec\n");
    797                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    798                                                MMCodecControlStop,(void *)pArgs);
    799                     if(eError != OMX_ErrorNone) {
    800                         G726DEC_EPRINT(": Error Occurred in Codec Stop..\n");
    801                         pComponentPrivate->curState = OMX_StateInvalid;
    802                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    803                                                                OMX_EventError, OMX_ErrorInvalidState,0, NULL);
    804                         goto EXIT;
    805                     }
    806                     G726DEC_STATEPRINT("****************** Component State Set to Idle\n\n");
    807                     pComponentPrivate->curState = OMX_StateIdle;
    808 #ifdef RESOURCE_MANAGER_ENABLED
    809                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_PCM_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
    810 #endif
    811                     G726DEC_DPRINT ("%d :: The component is stopped\n",__LINE__);
    812                     pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    813                                                            OMX_EventCmdComplete, OMX_CommandStateSet,
    814                                                            pComponentPrivate->curState, NULL);
    815                 } else {
    816                     G726DEC_DPRINT(": Comp: Sending ErrorNotification: Invalid State\n");
    817                     pComponentPrivate->cbInfo.EventHandler(pHandle,
    818                                                            pHandle->pApplicationPrivate,
    819                                                            OMX_EventError,
    820                                                            OMX_ErrorIncorrectStateTransition, 0,
    821                                                            "Invalid State Error");
    822                 }
    823                 break;
    824 
    825             case OMX_StateExecuting:
    826                 G726DEC_DPRINT(": HandleCommand: Cmd Executing \n");
    827                 if (pComponentPrivate->curState == OMX_StateIdle) {
    828                     char *pArgs = "damedesuStr";
    829                     if(pComponentPrivate->dasfmode == 1) {
    830                         OMX_U32 pValues[4];
    831                         pComponentPrivate->pParams->unUUID = pComponentPrivate->streamID;
    832                         pComponentPrivate->pParams->ulSamplingFreq =
    833                             pComponentPrivate->PcmParams->nSamplingRate;
    834                         pComponentPrivate->pParams->unAudioFormat = 1; /*MONO stream */
    835 
    836                         G726DEC_DPRINT("::pComponentPrivate->pParams->unAudioFormat = %d\n",
    837                                        pComponentPrivate->pParams->unAudioFormat);
    838                         G726DEC_DPRINT("::pComponentPrivate->pParams->ulSamplingFreq = %ld\n",
    839                                        pComponentPrivate->pParams->ulSamplingFreq);
    840                         G726DEC_DPRINT("::pComponentPrivate->pParams->unUUID = %ld\n",
    841                                        pComponentPrivate->pParams->unUUID);
    842 
    843                         pValues[0] = USN_STRMCMD_SETCODECPARAMS;
    844                         pValues[1] = (OMX_U32)pComponentPrivate->pParams;
    845                         pValues[2] = sizeof(G726D_USN_AudioCodecParams);
    846 
    847                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    848                                                    EMMCodecControlStrmCtrl,(void *)pValues);
    849                         if(eError != OMX_ErrorNone) {
    850                             G726DEC_EPRINT(": Error Occurred in Codec StreamControl..\n");
    851                             pComponentPrivate->curState = OMX_StateInvalid;
    852                             pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    853                                                                    OMX_EventError, OMX_ErrorInvalidState,0, NULL);
    854                             goto EXIT;
    855                         }
    856                     }
    857 
    858                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
    859                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    860                                                EMMCodecControlStart,(void *)pArgs);
    861                     if(eError != OMX_ErrorNone) {
    862                         G726DEC_EPRINT("Error Occurred in Codec Start..\n");
    863                         pComponentPrivate->curState = OMX_StateInvalid;
    864                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    865                                                                OMX_EventError, OMX_ErrorInvalidState,0, NULL);
    866                         goto EXIT;
    867                     }
    868                 } else if (pComponentPrivate->curState == OMX_StatePause) {
    869                     char *pArgs = "damedesuStr";
    870                     G726DEC_DPRINT(": Comp: Resume Command Came from App\n");
    871                     G726DEC_DPRINT(": G726DECUTILS::About to call LCML_ControlCodec\n");
    872                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    873                                                EMMCodecControlStart,(void *)pArgs);
    874                     if (eError != OMX_ErrorNone) {
    875                         G726DEC_EPRINT ("Error While Resuming the codec\n");
    876                         pComponentPrivate->curState = OMX_StateInvalid;
    877                         pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    878                                                                OMX_EventError, OMX_ErrorInvalidState,0, NULL);
    879                         goto EXIT;
    880                     }
    881 
    882                     for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
    883                         if (pComponentPrivate->pInputBufHdrPending[i] != NULL) {
    884                             G726D_LCML_BUFHEADERTYPE *pLcmlHdr;
    885                             G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,
    886                                                                 pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
    887                                                                 OMX_DirInput, &pLcmlHdr);
    888                             G726DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,
    889                                                __LINE__);
    890                             eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    891                                                       EMMCodecInputBuffer,
    892                                                       pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
    893                                                       pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
    894                                                       pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
    895                                                       (OMX_U8 *) pLcmlHdr->pFrameParam,
    896                                                       sizeof(G726DEC_UAlgInBufParamStruct),
    897                                                       NULL);
    898                         }
    899                     }
    900                     pComponentPrivate->nNumInputBufPending = 0;
    901 
    902                     for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
    903                         if (pComponentPrivate->pOutputBufHdrPending[i] != NULL) {
    904                             G726D_LCML_BUFHEADERTYPE *pLcmlHdr;
    905                             G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,
    906                                                                 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
    907                                                                 OMX_DirOutput, &pLcmlHdr);
    908                             if (!G726DEC_IsPending(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i],
    909                                                    OMX_DirOutput)) {
    910                                 G726DEC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],
    911                                                    OMX_DirOutput,__LINE__);
    912                                 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    913                                                           EMMCodecOuputBuffer,
    914                                                           pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
    915                                                           pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
    916                                                           pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen,
    917                                                           NULL,
    918                                                           0,
    919                                                           NULL);
    920                             }
    921                         }
    922                     }
    923                     pComponentPrivate->nNumOutputBufPending = 0;
    924                 }else {
    925                     pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
    926                                                             OMX_EventError, OMX_ErrorIncorrectStateTransition, 0,
    927                                                             "Invalid State");
    928                     G726DEC_DPRINT(":: Error: Invalid State Given by \
    929                        Application\n");
    930                     goto EXIT;
    931                 }
    932 
    933                 G726DEC_STATEPRINT("****************** Component State Set to Executing\n\n");
    934                 pComponentPrivate->curState = OMX_StateExecuting;
    935 #ifdef RESOURCE_MANAGER_ENABLED
    936                 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_PCM_Decoder_COMPONENT, OMX_StateExecuting, 3456,NULL);
    937 #endif
    938                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
    939                                                        OMX_EventCmdComplete,
    940                                                        OMX_CommandStateSet, pComponentPrivate->curState, NULL);
    941                 break;
    942 
    943             case OMX_StateLoaded:
    944                 G726DEC_DPRINT(": HandleCommand: Cmd Loaded\n");
    945                 if (pComponentPrivate->curState == OMX_StateWaitForResources ){
    946                     G726DEC_STATEPRINT("***************** Component State Set to Loaded\n\n");
    947                     pComponentPrivate->curState = OMX_StateLoaded;
    948                     pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
    949                                                             OMX_EventCmdComplete, OMX_CommandStateSet,
    950                                                             pComponentPrivate->curState,
    951                                                             NULL);
    952                     G726DEC_DPRINT(":: Tansitioning from WaitFor to Loaded\n");
    953                     break;
    954                 }
    955                 if (pComponentPrivate->curState != OMX_StateIdle) {
    956                     pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
    957                                                             OMX_EventError, OMX_ErrorIncorrectStateTransition, 0,
    958                                                             "Invalid State");
    959                     G726DEC_DPRINT(":: Error: Invalid State Given by \
    960                        Application\n");
    961                     goto EXIT;
    962                 }
    963 
    964                 G726DEC_DPRINT("Current State = %d\n",pComponentPrivate->curState);
    965                 G726DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %ld\n",
    966                                pComponentPrivate->pInputBufferList->numBuffers);
    967                 G726DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %ld\n",
    968                                pComponentPrivate->pOutputBufferList->numBuffers);
    969 
    970                 G726DEC_DPRINT(":: Loaded State - in while(1) loop: ip : %ld : op: %ld\n",
    971                                pComponentPrivate->pInputBufferList->numBuffers,
    972                                pComponentPrivate->pOutputBufferList->numBuffers);
    973                 if (pComponentPrivate->pInputBufferList->numBuffers ||
    974                     pComponentPrivate->pOutputBufferList->numBuffers) {
    975                     pComponentPrivate->InIdle_goingtoloaded = 1;
    976 #ifndef UNDER_CE
    977                     pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
    978                     pthread_cond_wait(&pComponentPrivate->InIdle_threshold,
    979                                       &pComponentPrivate->InIdle_mutex);
    980                     pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
    981 
    982 #else
    983                     OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    984 #endif
    985                     pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
    986                 }
    987                 /* Now Deinitialize the component No error should be returned from
    988                  * this function. It should clean the system as much as possible */
    989                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    990                                            EMMCodecControlDestroy,(void *)pArgs);
    991                 pComponentPrivate->bInitParamsInitialized = 0;
    992                 eError = EXIT_COMPONENT_THRD;
    993                 break;
    994 
    995             case OMX_StatePause:
    996                 G726DEC_DPRINT("Cmd Pause: Cur State = %d\n", pComponentPrivate->curState);
    997 
    998                 if ((pComponentPrivate->curState != OMX_StateExecuting) &&
    999                     (pComponentPrivate->curState != OMX_StateIdle)) {
   1000                     pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
   1001                                                             OMX_EventError, OMX_ErrorIncorrectStateTransition, 0,
   1002                                                             "Invalid State");
   1003                     G726DEC_DPRINT(":: Error: Invalid State Given by \
   1004                        Application\n");
   1005                     goto EXIT;
   1006                 }
   1007 
   1008                 G726DEC_DPRINT(": G726DECUTILS::About to call LCML_ControlCodec\n");
   1009                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1010                                            EMMCodecControlPause,(void *)pArgs);
   1011 
   1012                 if (eError != OMX_ErrorNone) {
   1013                     G726DEC_EPRINT(": Error: in Pausing the codec\n");
   1014                     pComponentPrivate->curState = OMX_StateInvalid;
   1015                     pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1016                                                            OMX_EventError, OMX_ErrorInvalidState,0, NULL);
   1017                     goto EXIT;
   1018                 }
   1019                 G726DEC_DPRINT(":: Component: Codec Is Paused\n");
   1020 
   1021                 G726DEC_STATEPRINT("****************** Component State Set to Pause\n\n");
   1022                 pComponentPrivate->curState = OMX_StatePause;
   1023                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1024                                                        OMX_EventCmdComplete, OMX_CommandStateSet,
   1025                                                        pComponentPrivate->curState, NULL);
   1026                 break;
   1027 
   1028             case OMX_StateWaitForResources:
   1029                 G726DEC_DPRINT(": HandleCommand: Cmd : OMX_StateWaitForResources\n");
   1030                 if (pComponentPrivate->curState == OMX_StateLoaded) {
   1031 #ifdef RESOURCE_MANAGER_ENABLED
   1032                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_PCM_Decoder_COMPONENT, OMX_StateWaitForResources, 3456,NULL);
   1033 #endif
   1034                     pComponentPrivate->curState = OMX_StateWaitForResources;
   1035                     G726DEC_DPRINT(": Transitioning from Loaded to OMX_StateWaitForResources\n");
   1036                     pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1037                                                            OMX_EventCmdComplete,
   1038                                                            OMX_CommandStateSet,pComponentPrivate->curState, NULL);
   1039                 } else {
   1040                     pComponentPrivate->cbInfo.EventHandler(
   1041                                                            pHandle, pHandle->pApplicationPrivate,
   1042                                                            OMX_EventError, OMX_ErrorIncorrectStateTransition,0, NULL);
   1043                 }
   1044                 break;
   1045 
   1046             case OMX_StateInvalid:
   1047                 G726DEC_DPRINT(": HandleCommand: Cmd OMX_StateInvalid:\n");
   1048                 pComponentPrivate->curState = OMX_StateInvalid;
   1049 
   1050                 pComponentPrivate->cbInfo.EventHandler(
   1051                                                        pHandle, pHandle->pApplicationPrivate,
   1052                                                        OMX_EventError, OMX_ErrorInvalidState,0, NULL);
   1053                 break;
   1054 
   1055             case OMX_StateMax:
   1056                 G726DEC_DPRINT(": HandleCommand: Cmd OMX_StateMax::\n");
   1057                 break;
   1058             } /* End of Switch */
   1059         }
   1060     }
   1061     else if (command == OMX_CommandMarkBuffer) {
   1062         G726DEC_DPRINT("command OMX_CommandMarkBuffer received\n");
   1063         if(!pComponentPrivate->pMarkBuf){
   1064             G726DEC_DPRINT("command OMX_CommandMarkBuffer received \n");
   1065             pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
   1066         }
   1067     }
   1068     else if (command == OMX_CommandPortDisable) {
   1069         if (!pComponentPrivate->bDisableCommandPending) {
   1070             if(commandData == 0x0){
   1071                 /* disable port */
   1072                 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   1073                     if (G726DEC_IsPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],
   1074                                           OMX_DirInput)) {
   1075                         /* Real solution is flush buffers from DSP.  Until we have the ability to do that
   1076                            we just call EmptyBufferDone() on any pending buffers */
   1077                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   1078                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1079                                                                    pComponentPrivate->pInputBufferList->pBufHdr[i]);
   1080                         pComponentPrivate->nEmptyBufferDoneCount++;
   1081                     }
   1082                 }
   1083                 pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled = OMX_FALSE;
   1084             }
   1085             if(commandData == -1){
   1086                 pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled = OMX_FALSE;
   1087             }
   1088             if(commandData == 0x1 || commandData == -1){
   1089                 char *pArgs = "damedesuStr";
   1090                 pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled = OMX_FALSE;
   1091                 if (pComponentPrivate->curState == OMX_StateExecuting) {
   1092                     pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
   1093                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1094                                                MMCodecControlStop,(void *)pArgs);
   1095                 }
   1096             }
   1097         }
   1098         G726DEC_DPRINT("commandData = %ld\n",commandData);
   1099         G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated = %d\n",
   1100                        pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated);
   1101         G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated = %d\n",
   1102                        pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated);
   1103         if(commandData == 0x0) {
   1104             if(!pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated){
   1105                 /* return cmdcomplete event if input unpopulated */
   1106                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1107                                                        OMX_EventCmdComplete, OMX_CommandPortDisable,
   1108                                                        G726D_INPUT_PORT, NULL);
   1109                 pComponentPrivate->bDisableCommandPending = 0;
   1110             }
   1111             else{
   1112                 pComponentPrivate->bDisableCommandPending = 1;
   1113                 pComponentPrivate->bDisableCommandParam = commandData;
   1114             }
   1115         }
   1116         if(commandData == 0x1) {
   1117             if (!pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated){
   1118                 /* return cmdcomplete event if output unpopulated */
   1119                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1120                                                        OMX_EventCmdComplete, OMX_CommandPortDisable,
   1121                                                        G726D_OUTPUT_PORT, NULL);
   1122                 pComponentPrivate->bDisableCommandPending = 0;
   1123             }
   1124             else {
   1125                 pComponentPrivate->bDisableCommandPending = 1;
   1126                 pComponentPrivate->bDisableCommandParam = commandData;
   1127             }
   1128         }
   1129         if(commandData == -1) {
   1130             if (!pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated &&
   1131                 !pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated){
   1132                 /* return cmdcomplete event if inout & output unpopulated */
   1133                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1134                                                        OMX_EventCmdComplete, OMX_CommandPortDisable,
   1135                                                        G726D_INPUT_PORT, NULL);
   1136                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1137                                                        OMX_EventCmdComplete, OMX_CommandPortDisable,
   1138                                                        G726D_OUTPUT_PORT, NULL);
   1139                 pComponentPrivate->bDisableCommandPending = 0;
   1140             }
   1141             else {
   1142                 pComponentPrivate->bDisableCommandPending = 1;
   1143                 pComponentPrivate->bDisableCommandParam = commandData;
   1144             }
   1145 #ifndef UNDER_CE
   1146             sched_yield();
   1147 #else
   1148             Sleep(0);
   1149 #endif
   1150         }
   1151     }
   1152     else if (command == OMX_CommandPortEnable) {
   1153         if(commandData == 0x0 || commandData == -1){
   1154             /* enable in port */
   1155             G726DEC_DPRINT("setting input port to enabled\n");
   1156             pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled = OMX_TRUE;
   1157             G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled = %d\n",
   1158                            pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled);
   1159 
   1160             if(pComponentPrivate->AlloBuf_waitingsignal){
   1161                 pComponentPrivate->AlloBuf_waitingsignal = 0;
   1162 #ifndef UNDER_CE
   1163                 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1164                 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1165                 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1166 #else
   1167                 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
   1168 #endif
   1169             }
   1170         }
   1171         if(commandData == 0x1 || commandData == -1){
   1172             char *pArgs = "damedesuStr";
   1173             /* enable out port */
   1174             G726DEC_DPRINT("setting output port to enabled\n");
   1175             pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled = OMX_TRUE;
   1176             if(pComponentPrivate->AlloBuf_waitingsignal){
   1177                 pComponentPrivate->AlloBuf_waitingsignal = 0;
   1178 #ifndef UNDER_CE
   1179                 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1180                 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1181                 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1182 #else
   1183                 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
   1184 #endif
   1185             }
   1186             if(pComponentPrivate->curState == OMX_StateExecuting){
   1187                 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
   1188                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1189                                            EMMCodecControlStart,(void *)pArgs);
   1190             }
   1191             G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled = %d\n",
   1192                            pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled);
   1193         }
   1194         while (1) {
   1195             G726DEC_DPRINT("commandData = %ld\n",commandData);
   1196             G726DEC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   1197             G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated = %d\n",
   1198                            pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated);
   1199 
   1200             if(commandData == 0x0 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1201                                       pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated)){
   1202 
   1203                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1204                                                        OMX_EventCmdComplete,
   1205                                                        OMX_CommandPortEnable,G726D_INPUT_PORT,
   1206                                                        NULL);
   1207                 break;
   1208             }
   1209             else if(commandData == 0x1 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1210                                            pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated)){
   1211 
   1212                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1213                                                        OMX_EventCmdComplete,
   1214                                                        OMX_CommandPortEnable,G726D_OUTPUT_PORT,
   1215                                                        NULL);
   1216                 break;
   1217             }
   1218             else if(commandData == -1 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1219                                           (pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated &&
   1220                                            pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated))) {
   1221 
   1222                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1223                                                        OMX_EventCmdComplete, OMX_CommandPortEnable,
   1224                                                        G726D_INPUT_PORT,
   1225                                                        NULL);
   1226 
   1227                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
   1228                                                        OMX_EventCmdComplete, OMX_CommandPortEnable,
   1229                                                        G726D_OUTPUT_PORT,
   1230                                                        NULL);
   1231                 G726DECFill_LCMLInitParamsEx(pComponentPrivate->pHandle);
   1232                 break;
   1233             }
   1234 #ifndef UNDER_CE
   1235             sched_yield();
   1236 #else
   1237             Sleep(0);
   1238 #endif
   1239         }
   1240     }
   1241     else if (command == OMX_CommandFlush) {
   1242         OMX_U32 aParam[3] = {0};
   1243         if(commandData == 0x0 || commandData == -1) {
   1244             if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0)  {
   1245                 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
   1246                 aParam[0] = USN_STRMCMD_FLUSH;
   1247                 aParam[1] = 0x0;
   1248                 aParam[2] = 0x0;
   1249 
   1250                 G726DEC_DPRINT("Flushing input port\n");
   1251                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1252                                            EMMCodecControlStrmCtrl, (void*)aParam);
   1253 
   1254                 if (eError != OMX_ErrorNone) {
   1255                     goto EXIT;
   1256                 }
   1257             }else {
   1258                 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
   1259             }
   1260         }
   1261         if(commandData == 0x1 || commandData == -1){
   1262             if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
   1263                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
   1264                 aParam[0] = USN_STRMCMD_FLUSH;
   1265                 aParam[1] = 0x1;
   1266                 aParam[2] = 0x0;
   1267 
   1268                 G726DEC_DPRINT("Flushing output port\n");
   1269                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1270                                            EMMCodecControlStrmCtrl, (void*)aParam);
   1271                 if (eError != OMX_ErrorNone) {
   1272                     goto EXIT;
   1273                 }
   1274             } else {
   1275                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
   1276             }
   1277         }
   1278     }
   1279  EXIT:
   1280     G726DEC_DPRINT (":: Exiting HandleCommand Function\n");
   1281     return eError;
   1282 }
   1283 
   1284 
   1285 
   1286 /* ================================================================================= * */
   1287 /**
   1288  * @fn G726DEC_HandleDataBuf_FromApp() function handles the input and output buffers
   1289  * that come from the application. It is not direct function wich gets called by
   1290  * the application rather, it gets called eventually.
   1291  *
   1292  * @param *pBufHeader This is the buffer header that needs to be processed.
   1293  *
   1294  * @param *pComponentPrivate  This is component's private date structure.
   1295  *
   1296  * @pre          None
   1297  *
   1298  * @post         None
   1299  *
   1300  *  @return      OMX_ErrorNone = Successful processing.
   1301  *               OMX_ErrorInsufficientResources = Not enough memory
   1302  *               OMX_ErrorHardware = Hardware error has occured lile LCML failed
   1303  *               to do any said operartion.
   1304  *
   1305  *  @see         None
   1306  */
   1307 /* ================================================================================ * */
   1308 OMX_ERRORTYPE G726DEC_HandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader,
   1309                                             G726DEC_COMPONENT_PRIVATE *pComponentPrivate)
   1310 {
   1311     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1312     OMX_DIRTYPE eDir;
   1313     LCML_DSP_INTERFACE * phandle = NULL;
   1314 
   1315     G726DEC_DPRINT (":: Entering HandleDataBuf_FromApp Function\n");
   1316     G726DEC_DPRINT (":: pBufHeader->pMarkData = %p\n",pBufHeader->pMarkData);
   1317 
   1318     pBufHeader->pPlatformPrivate  = pComponentPrivate;
   1319     eError = G726DEC_GetBufferDirection(pBufHeader, &eDir);
   1320     G726DEC_DPRINT (":: HandleDataBuf_FromApp Function\n");
   1321     if (eError != OMX_ErrorNone) {
   1322         G726DEC_EPRINT (":: The pBufHeader is not found in the list\n");
   1323         goto EXIT;
   1324     }
   1325 
   1326     if (eDir == OMX_DirInput) {
   1327         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
   1328         G726D_LCML_BUFHEADERTYPE *pLcmlHdr;
   1329         pComponentPrivate->nUnhandledEmptyThisBuffers--;
   1330         eError = G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,
   1331                                                      pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr);
   1332         if (eError != OMX_ErrorNone) {
   1333             G726DEC_EPRINT(":: Error: Invalid Buffer Came ...\n");
   1334             goto EXIT;
   1335         }
   1336 
   1337 
   1338         if (pBufHeader->nFilledLen > 0 || pBufHeader->nFlags == OMX_BUFFERFLAG_EOS) {
   1339             pComponentPrivate->bBypassDSP = 0;
   1340             G726DEC_DPRINT (":: HandleDataBuf_FromApp Function\n");
   1341             G726DEC_DPRINT (":::Calling LCML_QueueBuffer\n");
   1342             pLcmlHdr->pFrameParam->bLastBuffer = 0;
   1343             if(pBufHeader->nFlags == OMX_BUFFERFLAG_EOS) {
   1344                 pLcmlHdr->pFrameParam->bLastBuffer = 1;
   1345                 pComponentPrivate->bIsEOFSent = 1;
   1346                 pBufHeader->nFlags = 0;
   1347             }
   1348 
   1349             G726DEC_DPRINT ("Comp:: Sending Filled Input buffer = %p, %p\
   1350  to LCML\n",pBufHeader,pBufHeader->pBuffer);
   1351 
   1352             /* Store time stamp information */
   1353             pComponentPrivate->arrTimestamp[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
   1354             pComponentPrivate->arrTickCount[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
   1355             pComponentPrivate->IpBufindex++;
   1356             pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OMX_DirInput]->nBufferCountActual;
   1357 
   1358             if (pComponentPrivate->curState == OMX_StateExecuting) {
   1359                 if (!G726DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) {
   1360                     if(!pComponentPrivate->bDspStoppedWhileExecuting) {
   1361                         G726DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
   1362 
   1363 
   1364                         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   1365                                                   EMMCodecInputBuffer,
   1366                                                   pBufHeader->pBuffer,
   1367                                                   pBufHeader->nAllocLen,
   1368                                                   pBufHeader->nFilledLen,
   1369                                                   (OMX_U8 *) pLcmlHdr->pFrameParam,
   1370                                                   sizeof(G726DEC_UAlgInBufParamStruct),
   1371                                                   pBufHeader->pBuffer);
   1372 
   1373                         if (eError != OMX_ErrorNone) {
   1374                             G726DEC_EPRINT ("::Comp: SetBuff: IP: Error Occurred\n");
   1375                             eError = OMX_ErrorHardware;
   1376                             goto EXIT;
   1377                         }
   1378 
   1379                         pComponentPrivate->lcml_nCntIp++;
   1380                         pComponentPrivate->lcml_nIpBuf++;
   1381                         pComponentPrivate->num_Sent_Ip_Buff++;
   1382                         G726DEC_DPRINT ("Sending Input buffer to Codec\n");
   1383                     }
   1384                     else {
   1385                         G726DEC_DPRINT("Calling EmptyBufferDone from line %d\n",__LINE__);
   1386                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   1387                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1388                                                                    pBufHeader );
   1389                     }
   1390 
   1391                 }
   1392             } else if (pComponentPrivate->curState == OMX_StatePause) {
   1393                 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
   1394             }
   1395         } else {
   1396             pComponentPrivate->bBypassDSP = 1;
   1397             G726DEC_DPRINT ("Forcing EmptyBufferDone\n");
   1398             if(pComponentPrivate->dasfmode == 0) {
   1399                 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   1400                                                            pComponentPrivate->pHandle->pApplicationPrivate,
   1401                                                            pComponentPrivate->pInputBufferList->pBufHdr[0]);
   1402                 pComponentPrivate->nEmptyBufferDoneCount++;
   1403             }
   1404         }
   1405         if(pBufHeader->pMarkData){
   1406             G726DEC_DPRINT (":Detected pBufHeader->pMarkData\n");
   1407             pComponentPrivate->pMarkData = pBufHeader->pMarkData;
   1408             pComponentPrivate->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
   1409             pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
   1410             pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
   1411             if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){
   1412                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1413                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1414                                                        OMX_EventMark,
   1415                                                        0,
   1416                                                        0,
   1417                                                        pBufHeader->pMarkData);
   1418             }
   1419         }
   1420         if (pComponentPrivate->bFlushInputPortCommandPending) {
   1421             OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
   1422         }
   1423     }
   1424     else if (eDir == OMX_DirOutput) {
   1425         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
   1426         G726D_LCML_BUFHEADERTYPE *pLcmlHdr;
   1427         pComponentPrivate->nUnhandledFillThisBuffers--;
   1428         G726DEC_DPRINT(": pComponentPrivate->lcml_nOpBuf = %ld\n",
   1429                        pComponentPrivate->lcml_nOpBuf);
   1430         G726DEC_DPRINT(": pComponentPrivate->lcml_nIpBuf = %ld\n",
   1431                        pComponentPrivate->lcml_nIpBuf);
   1432 
   1433         eError = G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
   1434         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
   1435 
   1436         if (eError != OMX_ErrorNone) {
   1437             G726DEC_EPRINT(":: Error: Invalid Buffer Came ...\n");
   1438             goto EXIT;
   1439         }
   1440 
   1441 
   1442 
   1443         G726DEC_DPRINT (":::Calling LCML_QueueBuffer\n");
   1444         if (pComponentPrivate->bBypassDSP == 0) {
   1445             G726DEC_DPRINT ("Comp:: Sending Emptied Output buffer=%p to LCML\n",pBufHeader);
   1446             if (pComponentPrivate->curState == OMX_StateExecuting) {
   1447                 G726DEC_DPRINT ("Comp:: in G726DEC UTILS pLcmlHandle->pCodecinterfacehandle= %p\n",
   1448                                 pLcmlHandle->pCodecinterfacehandle);
   1449                 G726DEC_DPRINT ("Comp:: in G726DEC UTILS pBufHeader->pBuffer = %p\n",pBufHeader->pBuffer);
   1450                 G726DEC_DPRINT ("Comp:: in G726DEC UTILS pBufHeader->nAllocLen = %ld\n",pBufHeader->nAllocLen);
   1451                 if (!G726DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput) &&
   1452                     (pComponentPrivate->numPendingBuffers < pComponentPrivate->pOutputBufferList->numBuffers))  {
   1453                     G726DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
   1454                     G726DEC_DPRINT("pComponentPrivate->bDspStoppedWhileExecuting = %d\n", pComponentPrivate->bDspStoppedWhileExecuting);
   1455                     if(!pComponentPrivate->bDspStoppedWhileExecuting){
   1456                         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   1457                                                   EMMCodecOuputBuffer,
   1458                                                   pBufHeader->pBuffer,
   1459                                                   pBufHeader->nAllocLen,
   1460                                                   pBufHeader->nFilledLen,
   1461                                                   NULL,
   1462                                                   0,
   1463                                                   pBufHeader->pBuffer);
   1464 
   1465                         if (eError != OMX_ErrorNone ) {
   1466                             G726DEC_EPRINT (":: Comp:: SetBuff OP: Error Occurred\n");
   1467                             eError = OMX_ErrorHardware;
   1468                             goto EXIT;
   1469                         }
   1470                         pComponentPrivate->lcml_nCntOp++;
   1471                         pComponentPrivate->lcml_nOpBuf++;
   1472                         pComponentPrivate->num_Op_Issued++;
   1473                         G726DEC_DPRINT ("Comp:: in G726DEC UTILS \n");
   1474                     }
   1475                 }
   1476             } else {
   1477                 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
   1478             }
   1479         }
   1480         if (pComponentPrivate->bFlushOutputPortCommandPending) {
   1481             OMX_SendCommand( pComponentPrivate->pHandle, OMX_CommandFlush, 1, NULL);
   1482         }
   1483     } /* end of OMX_DirOutput if struct */
   1484     else {
   1485         G726DEC_DPRINT(": BufferHeader %p, Buffer %p Unknown ..........\n",pBufHeader, pBufHeader->pBuffer);
   1486         eError = OMX_ErrorBadParameter;
   1487     }
   1488  EXIT:
   1489     G726DEC_DPRINT(": Exiting from  HandleDataBuf_FromApp: %x \n",eError);
   1490     if(eError == OMX_ErrorBadParameter) {
   1491         G726DEC_DPRINT(": Error = OMX_ErrorBadParameter\n");
   1492     }
   1493     return eError;
   1494 }
   1495 
   1496 
   1497 /* ================================================================================= * */
   1498 /**
   1499  * @fn G726DEC_GetBufferDirection() function determines whether it is input buffer or
   1500  * output buffer.
   1501  *
   1502  * @param *pBufHeader This is pointer to buffer header whose direction needs to
   1503  *                    be determined.
   1504  *
   1505  * @param *eDir  This is output argument which stores the direction of buffer.
   1506  *
   1507  * @pre          None
   1508  *
   1509  * @post         None
   1510  *
   1511  *  @return      OMX_ErrorNone = Successful processing.
   1512  *               OMX_ErrorBadParameter = In case of invalid buffer
   1513  *
   1514  *  @see         None
   1515  */
   1516 /* ================================================================================ * */
   1517 
   1518 OMX_ERRORTYPE G726DEC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader,
   1519                                          OMX_DIRTYPE *eDir)
   1520 {
   1521     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1522     G726DEC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
   1523     OMX_U32 nBuf = pComponentPrivate->pInputBufferList->numBuffers;
   1524     OMX_BUFFERHEADERTYPE *pBuf = NULL;
   1525     int flag = 1;
   1526     OMX_U32 i=0;
   1527 
   1528     G726DEC_DPRINT (":: Entering GetBufferDirection Function\n");
   1529     for(i=0; i<nBuf; i++) {
   1530         pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
   1531         if(pBufHeader == pBuf) {
   1532             *eDir = OMX_DirInput;
   1533             G726DEC_DPRINT (":: Buffer %p is INPUT BUFFER\n", pBufHeader);
   1534             flag = 0;
   1535             goto EXIT;
   1536         }
   1537     }
   1538 
   1539     nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   1540 
   1541     for(i=0; i<nBuf; i++) {
   1542         pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   1543         if(pBufHeader == pBuf) {
   1544             *eDir = OMX_DirOutput;
   1545             G726DEC_DPRINT (":: Buffer %p is OUTPUT BUFFER\n", pBufHeader);
   1546             flag = 0;
   1547             goto EXIT;
   1548         }
   1549     }
   1550 
   1551     if (flag == 1) {
   1552         G726D_OMX_ERROR_EXIT(eError, OMX_ErrorBadParameter,
   1553                              "Buffer Not Found in List : OMX_ErrorBadParameter");
   1554     }
   1555  EXIT:
   1556     G726DEC_DPRINT (":: Exiting GetBufferDirection Function\n");
   1557     return eError;
   1558 }
   1559 
   1560 
   1561 /* ================================================================================= * */
   1562 /**
   1563  * @fn G726DEC_LCML_Callback() function is callback which is called by LCML whenever
   1564  * there is an even generated for the component.
   1565  *
   1566  * @param event  This is event that was generated.
   1567  *
   1568  * @param arg    This has other needed arguments supplied by LCML like handles
   1569  *               etc.
   1570  *
   1571  * @pre          None
   1572  *
   1573  * @post         None
   1574  *
   1575  *  @return      OMX_ErrorNone = Successful processing.
   1576  *               OMX_ErrorInsufficientResources = Not enough memory
   1577  *
   1578  *  @see         None
   1579  */
   1580 /* ================================================================================ * */
   1581 OMX_ERRORTYPE G726DEC_LCML_Callback (TUsnCodecEvent event,void * args [10])
   1582 {
   1583     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1584     OMX_U8 *pBuffer = args[1];
   1585     OMX_U32 i = 0;
   1586     G726D_LCML_BUFHEADERTYPE *pLcmlHdr = NULL;
   1587     OMX_COMPONENTTYPE *pHandle = NULL;
   1588     LCML_DSP_INTERFACE *pLcmlHandle = NULL;
   1589     G726DEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   1590 #ifdef RESOURCE_MANAGER_ENABLED
   1591     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
   1592 #endif
   1593 
   1594     pComponentPrivate = (G726DEC_COMPONENT_PRIVATE*)
   1595         ((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate;
   1596     G726DEC_DPRINT("Component private handle: pComponentPrivate = %p\n",pComponentPrivate);
   1597 
   1598     G726DEC_DPRINT (":: Entering the LCML_Callback() : event = %d\n",event);
   1599     switch(event) {
   1600 
   1601     case EMMCodecDspError:
   1602         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecDspError >>>>>>>>>>\n");
   1603         break;
   1604 
   1605     case EMMCodecInternalError:
   1606         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecInternalError >>>>>>>>>> \n");
   1607         break;
   1608 
   1609     case EMMCodecInitError:
   1610         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecInitError>>>>>>>>>> \n");
   1611         break;
   1612 
   1613     case EMMCodecDspMessageRecieved:
   1614         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved>>>>>>>>>> \n");
   1615         break;
   1616 
   1617     case EMMCodecBufferProcessed:
   1618         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecBufferProcessed>>>>>>>>>> \n");
   1619         break;
   1620 
   1621     case EMMCodecProcessingStarted:
   1622         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingStarted>>>>>>>>>> \n");
   1623         break;
   1624 
   1625     case EMMCodecProcessingPaused:
   1626         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingPaused>>>>>>>>>> \n");
   1627         break;
   1628 
   1629     case EMMCodecProcessingStoped:
   1630         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingStoped>>>>>>>>>> \n");
   1631         break;
   1632 
   1633     case EMMCodecProcessingEof:
   1634         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingEof>>>>>>>>>> \n");
   1635         break;
   1636 
   1637     case EMMCodecBufferNotProcessed:
   1638         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed>>>>>>>>>> \n");
   1639         break;
   1640 
   1641     case EMMCodecAlgCtrlAck:
   1642         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck>>>>>>>>>> \n");
   1643         break;
   1644 
   1645     case EMMCodecStrmCtrlAck:
   1646         G726DEC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck>>>>>>>>>> \n");
   1647         break;
   1648     }
   1649     if(event == EMMCodecBufferProcessed){
   1650         G726DEC_DPRINT(":: --------- EMMCodecBufferProcessed Here\n");
   1651         if( args[0] == (void *)EMMCodecInputBuffer) {
   1652             G726DEC_DPRINT (" :: Inside the LCML_Callback EMMCodecInputBuffer\n");
   1653             G726DEC_DPRINT(":: Input: pBufferr = %p\n", pBuffer);
   1654 
   1655             eError = G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,pBuffer, OMX_DirInput, &pLcmlHdr);
   1656             G726DEC_DPRINT(":: Input: pLcmlHeader = %p\n", pLcmlHdr);
   1657             G726DEC_DPRINT(":: Input: pLcmlHdr->eDir = %d\n", pLcmlHdr->eDir);
   1658             G726DEC_DPRINT(":: Input: *pLcmlHdr->eDir = %d\n", pLcmlHdr->eDir);
   1659             G726DEC_DPRINT(":: Input: Filled Len = %ld\n", pLcmlHdr->pBufHdr->nFilledLen);
   1660 
   1661             if((int)args[5] == IUALG_WARN_PLAYCOMPLETED)
   1662                 G726DEC_DPRINT("IUALG_WARN_PLAYCOMPLETED is sent from EMMCodecBufferProcessed event\n");
   1663             if (eError != OMX_ErrorNone) {
   1664                 G726DEC_EPRINT(":: Error: Invalid Buffer Came ...\n");
   1665                 goto EXIT;
   1666             }
   1667             G726DEC_DPRINT(":: Input: pLcmlHeader = %p\n", pLcmlHdr);
   1668 
   1669             pComponentPrivate->lcml_nCntIpRes++;
   1670 
   1671             G726DEC_ClearPending(pComponentPrivate,pLcmlHdr->pBufHdr,OMX_DirInput,__LINE__);
   1672             /*ret = write (pComponentPrivate->lcml_Pipe[1], &pLcmlHdr, sizeof(pLcmlHdr)); */
   1673             G726DEC_DPRINT(": Component Sending Empty Input buffer%p to App\n",pLcmlHdr->pBufHdr->pBuffer);
   1674             pLcmlHdr->pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS;
   1675             pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   1676                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1677                                                        pLcmlHdr->pBufHdr );
   1678             pComponentPrivate->nEmptyBufferDoneCount++;
   1679             pComponentPrivate->lcml_nIpBuf--;
   1680             pComponentPrivate->app_nBuf++;
   1681             /***************************************/
   1682 
   1683         } else if (args[0] == (void *)EMMCodecOuputBuffer) {
   1684             G726DEC_DPRINT (" :: Inside the LCML_Callback EMMCodecOuputBuffer\n");
   1685             G726DEC_DPRINT(":: Output: pBuffer = %p\n", pBuffer);
   1686             if (!G726DEC_IsValid(pComponentPrivate,pBuffer,OMX_DirOutput)) {
   1687                 /* If the buffer we get back from the DSP is not valid call FillBufferDone
   1688                    on a valid buffer */
   1689                 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
   1690                                                           pComponentPrivate->pHandle->pApplicationPrivate,
   1691                                                           pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->nInvalidFrameCount++]);
   1692                 pComponentPrivate->nOutStandingFillDones--;
   1693                 pComponentPrivate->numPendingBuffers--;
   1694             }
   1695             else {
   1696                 pComponentPrivate->nOutStandingFillDones++;
   1697                 eError = G726DEC_GetCorresponding_LCMLHeader(pComponentPrivate,pBuffer, OMX_DirOutput, &pLcmlHdr);
   1698                 if (eError != OMX_ErrorNone) {
   1699                     G726DEC_EPRINT(":: Error: Invalid Buffer Came ...\n");
   1700                     goto EXIT;
   1701                 }
   1702                 pLcmlHdr->pBufHdr->nFilledLen = (int)args[8];
   1703                 G726DEC_DPRINT(":: Output: pLcmlHeader = %p\n", pLcmlHdr);
   1704                 G726DEC_DPRINT(":: Output: pLcmlHdr->eDir = %d\n", pLcmlHdr->eDir);
   1705                 G726DEC_DPRINT(":: Output: Filled Len = %ld\n", pLcmlHdr->pBufHdr->nFilledLen);
   1706                 pComponentPrivate->lcml_nCntOpReceived++;
   1707                 G726DEC_ClearPending(pComponentPrivate,pLcmlHdr->pBufHdr,OMX_DirOutput,__LINE__);
   1708                 /*ret = write (pComponentPrivate->lcml_Pipe[1], &pLcmlHdr, sizeof(pLcmlHdr));*/
   1709                 G726DEC_DPRINT ("Sending Output buffer to Applcation\n");
   1710                 if (pComponentPrivate->bIsEOFSent){
   1711                     G726DEC_DPRINT ("Adding EOS flag to the output buffer\n");
   1712                     pLcmlHdr->pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS;
   1713                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1714                                                            pComponentPrivate->pHandle->pApplicationPrivate,
   1715                                                            OMX_EventBufferFlag,
   1716                                                            pLcmlHdr->pBufHdr->nOutputPortIndex,
   1717                                                            pLcmlHdr->pBufHdr->nFlags, NULL);
   1718                     pComponentPrivate->bIsEOFSent = 0;
   1719                 }
   1720                 if (pComponentPrivate->pMarkData) {
   1721                     G726DEC_DPRINT ("pComponentPrivate->pMarkData set\n");
   1722                     pLcmlHdr->pBufHdr->pMarkData = pComponentPrivate->pMarkData;
   1723                     pLcmlHdr->pBufHdr->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
   1724                 }
   1725                 pComponentPrivate->num_Reclaimed_Op_Buff++;
   1726                 G726DEC_DPRINT(": Component Sending Filled Output buffer%p to App\n",pLcmlHdr->pBufHdr);
   1727                 G726DEC_DPRINT("pLcmlHdr->pBufHdr = 0x%p\n",pLcmlHdr->pBufHdr);
   1728                 if (pComponentPrivate->curState != OMX_StatePause) {
   1729                     /* Copying time stamp information to output buffer */
   1730                     pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->arrTimestamp[pComponentPrivate->OpBufindex];
   1731                     pLcmlHdr->pBufHdr->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
   1732                     pComponentPrivate->OpBufindex++;
   1733                     pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OMX_DirInput]->nBufferCountActual;
   1734 
   1735                     pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
   1736                                                               pComponentPrivate->pHandle->pApplicationPrivate,
   1737                                                               pLcmlHdr->pBufHdr);
   1738                     pComponentPrivate->nOutStandingFillDones--;
   1739                     pComponentPrivate->lcml_nOpBuf--;
   1740                     pComponentPrivate->app_nBuf++;
   1741                     pComponentPrivate->nFillBufferDoneCount++;
   1742                 }
   1743                 /**********************************************/
   1744             }
   1745         }
   1746     } else if(event == EMMCodecProcessingStoped) {
   1747         if (!pComponentPrivate->bNoIdleOnStop) {
   1748             pComponentPrivate->curState = OMX_StateIdle;
   1749 #ifdef RESOURCE_MANAGER_ENABLED
   1750             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_PCM_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
   1751 #endif
   1752             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, pComponentPrivate->pHandle->pApplicationPrivate,
   1753                                                    OMX_EventCmdComplete, OMX_CommandStateSet,
   1754                                                    pComponentPrivate->curState, NULL);
   1755             G726DEC_DPRINT ("%d :: The component is stopped\n",__LINE__);
   1756         }
   1757         else {
   1758             pComponentPrivate->bIdleCommandPending = OMX_TRUE;
   1759             pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
   1760             pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
   1761         }
   1762         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   1763             G726DEC_ClearPending(pComponentPrivate, pComponentPrivate->pInputBufferList->pBufHdr[i], OMX_DirInput, __LINE__);
   1764         }
   1765         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   1766             G726DEC_ClearPending(pComponentPrivate, pComponentPrivate->pOutputBufferList->pBufHdr[i], OMX_DirOutput, __LINE__);
   1767         }
   1768 
   1769     } else if(event == EMMCodecAlgCtrlAck) {
   1770         G726DEC_DPRINT ("GOT MESSAGE USN_DSPACK_ALGCTRL \n");
   1771     } else if (event == EMMCodecDspError) {
   1772         G726DEC_DPRINT(":: commandedState  = %p\n",args[0]);
   1773         G726DEC_DPRINT(":: arg4 = %p\n",args[4]);
   1774         G726DEC_DPRINT(":: arg5 = %p\n",args[5]);
   1775         G726DEC_DPRINT(":: --------- EMMCodecDspError Here\n");
   1776         if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
   1777             /* add callback to application to indicate SN/USN has completed playing of current set of date */
   1778 
   1779             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1780                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1781                                                    OMX_EventBufferFlag,
   1782                                                    (OMX_U32)NULL,
   1783                                                    OMX_BUFFERFLAG_EOS,
   1784                                                    NULL);
   1785         }
   1786         if((int)args[5] == IUALG_WARN_CONCEALED) {
   1787             G726DEC_DPRINT( "Algorithm issued a warning. But can continue" );
   1788             G726DEC_DPRINT("%d :: arg5 = %p\n",__LINE__,args[5]);
   1789         }
   1790 
   1791         if((int)args[5] == IUALG_ERR_GENERAL) {
   1792             G726DEC_DPRINT( "Algorithm error. Cannot continue" );
   1793             G726DEC_DPRINT("%d :: arg5 = %p\n",__LINE__,args[5]);
   1794             G726DEC_DPRINT("%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
   1795             pHandle = pComponentPrivate->pHandle;
   1796             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
   1797         }
   1798 
   1799         if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ){
   1800             char *pArgs = "damedesuStr";
   1801             G726DEC_DPRINT("%d :: arg5 = %p\n",__LINE__,args[5]);
   1802             G726DEC_DPRINT("%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
   1803             pHandle = pComponentPrivate->pHandle;
   1804             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
   1805 
   1806             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1807                                        MMCodecControlStop,(void *)pArgs);
   1808             if(eError != OMX_ErrorNone) {
   1809                 G726DEC_EPRINT("%d: Error Occurred in Codec Stop..\n",
   1810                                __LINE__);
   1811                 goto EXIT;
   1812             }
   1813             G726DEC_DPRINT("%d :: G726DEC: Codec has been Stopped here\n",__LINE__);
   1814             pComponentPrivate->curState = OMX_StateIdle;
   1815 #ifdef RESOURCE_MANAGER_ENABLED
   1816             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_PCM_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
   1817 #endif
   1818             pComponentPrivate->cbInfo.EventHandler(
   1819                                                    pHandle, pHandle->pApplicationPrivate,
   1820                                                    OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
   1821 
   1822         }
   1823 
   1824         if( (int)args[5] == IUALG_WARN_OVERFLOW ){
   1825             G726DEC_DPRINT( "Algorithm error. Overflow" );
   1826         }
   1827         if( (int)args[5] == IUALG_WARN_UNDERFLOW ){
   1828             G726DEC_DPRINT( "Algorithm error. Underflow" );
   1829         }
   1830     } else if (event == EMMCodecStrmCtrlAck) {
   1831         G726DEC_DPRINT(":: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n");
   1832         {
   1833             pHandle = pComponentPrivate->pHandle;
   1834             if ( args[2] == (void *)EMMCodecInputBuffer) {
   1835                 if (args[0] == (void *)USN_ERR_NONE ) {
   1836                     G726DEC_DPRINT("Flushing input port %d\n",__LINE__);
   1837                     for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
   1838                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
   1839                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1840                                                                    pComponentPrivate->pInputBufHdrPending[i]);
   1841                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
   1842                     }
   1843                     pComponentPrivate->nNumInputBufPending=0;
   1844                     pComponentPrivate->cbInfo.EventHandler(pHandle,
   1845                                                            pHandle->pApplicationPrivate,
   1846                                                            OMX_EventCmdComplete,
   1847                                                            OMX_CommandFlush,G726D_INPUT_PORT, NULL);
   1848                 } else {
   1849                     G726DEC_DPRINT ("LCML reported error while flushing input port\n");
   1850                     goto EXIT;
   1851                 }
   1852             }
   1853             else if ( args[2] == (void *)EMMCodecOuputBuffer) {
   1854                 if (args[0] == (void *)USN_ERR_NONE ) {
   1855                     G726DEC_DPRINT("Flushing output port %d\n",__LINE__);
   1856                     for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
   1857                         pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
   1858                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
   1859                                                                   pComponentPrivate->pOutputBufHdrPending[i]
   1860                                                                   );
   1861                         pComponentPrivate->nOutStandingFillDones--;
   1862                         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
   1863                     }
   1864                     pComponentPrivate->nNumOutputBufPending=0;
   1865                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1866                                                            pComponentPrivate->pHandle->pApplicationPrivate,
   1867                                                            OMX_EventCmdComplete,
   1868                                                            OMX_CommandFlush,G726D_OUTPUT_PORT,
   1869                                                            NULL);
   1870                 } else {
   1871                     G726DEC_DPRINT ("LCML reported error while flushing output port\n");
   1872                     goto EXIT;
   1873                 }
   1874             }
   1875         }
   1876     }
   1877 
   1878  EXIT:
   1879     G726DEC_DPRINT (":: Exiting the LCML_Callback() \n");
   1880     return eError;
   1881 }
   1882 
   1883 
   1884 /* ================================================================================= * */
   1885 /**
   1886  * @fn G726DEC_GetCorresponding_LCMLHeader() function gets the corresponding LCML
   1887  * header from the actual data buffer for required processing.
   1888  *
   1889  * @param *pBuffer This is the data buffer pointer.
   1890  *
   1891  * @param eDir   This is direction of buffer. Input/Output.
   1892  *
   1893  * @param *G726D_LCML_BUFHEADERTYPE  This is pointer to LCML Buffer Header.
   1894  *
   1895  * @pre          None
   1896  *
   1897  * @post         None
   1898  *
   1899  *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
   1900  *               OMX_ErrorHardware = Hardware error has occured.
   1901  *
   1902  *  @see         None
   1903  */
   1904 /* ================================================================================ * */
   1905 OMX_ERRORTYPE G726DEC_GetCorresponding_LCMLHeader(G726DEC_COMPONENT_PRIVATE *pComponentPrivate,
   1906                                                   OMX_U8 *pBuffer,
   1907                                                   OMX_DIRTYPE eDir,
   1908                                                   G726D_LCML_BUFHEADERTYPE **ppLcmlHdr)
   1909 {
   1910     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1911     G726D_LCML_BUFHEADERTYPE *pLcmlBufHeader = NULL;
   1912     int nIpBuf=0, nOpBuf=0, i=0;
   1913 
   1914     G726DEC_DPRINT (":: Entering the G726DEC_GetCorresponding_LCMLHeader()\n");
   1915     G726DEC_DPRINT (":: eDir = %d\n",eDir);
   1916 
   1917     while (!pComponentPrivate->bInitParamsInitialized) {
   1918 #ifndef UNDER_CE
   1919         sched_yield();
   1920 #else
   1921         Sleep(0);
   1922 #endif
   1923     }
   1924 
   1925     if(eDir == OMX_DirInput) {
   1926         G726DEC_DPRINT (":: In GetCorresponding_LCMLHeader()\n");
   1927 
   1928         nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
   1929 
   1930         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT];
   1931 
   1932         for(i=0; i<nIpBuf; i++) {
   1933             G726DEC_DPRINT("pBuffer = %p\n",pBuffer);
   1934             G726DEC_DPRINT("pLcmlBufHeader->pBufHdr->pBuffer = %p\n",pLcmlBufHeader->pBufHdr->pBuffer);
   1935             if(pBuffer == pLcmlBufHeader->pBufHdr->pBuffer) {
   1936                 *ppLcmlHdr = pLcmlBufHeader;
   1937                 G726DEC_DPRINT("::Corresponding LCML Header Found\n");
   1938                 goto EXIT;
   1939             }
   1940             pLcmlBufHeader++;
   1941         }
   1942     } else if (eDir == OMX_DirOutput) {
   1943         i = 0;
   1944         nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   1945 
   1946         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT];
   1947         G726DEC_DPRINT (":: nOpBuf = %d\n",nOpBuf);
   1948 
   1949         for(i=0; i<nOpBuf; i++) {
   1950             G726DEC_DPRINT("pBuffer = %p\n",pBuffer);
   1951             G726DEC_DPRINT("pLcmlBufHeader->pBufHdr->pBuffer = %p\n",pLcmlBufHeader->pBufHdr->pBuffer);
   1952             if(pBuffer == pLcmlBufHeader->pBufHdr->pBuffer) {
   1953                 *ppLcmlHdr = pLcmlBufHeader;
   1954                 G726DEC_DPRINT("::Corresponding LCML Header Found\n");
   1955                 goto EXIT;
   1956             }
   1957             pLcmlBufHeader++;
   1958         }
   1959     } else {
   1960         G726DEC_DPRINT(":: Invalid Buffer Type :: exiting...\n");
   1961     }
   1962 
   1963  EXIT:
   1964     G726DEC_DPRINT (":: Exiting the GetCorresponding_LCMLHeader() \n");
   1965     return eError;
   1966 }
   1967 
   1968 
   1969 /** ========================================================================
   1970  *  OMX_DmmMap () method is used to allocate the memory using DMM.
   1971  *
   1972  *  @param ProcHandle -  Component identification number
   1973  *  @param size  - Buffer header address, that needs to be sent to codec
   1974  *  @param pArmPtr - Message used to send the buffer to codec
   1975  *  @param pDmmBuf - buffer id
   1976  *
   1977  *  @retval OMX_ErrorNone  - Success
   1978  *          OMX_ErrorHardware  -  Hardware Error
   1979  ** ==========================================================================*/
   1980 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle,
   1981                          int size,
   1982                          void* pArmPtr,
   1983                          DMM_BUFFER_OBJ* pDmmBuf)
   1984 {
   1985     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
   1986     DSP_STATUS status = DSP_SOK;
   1987     int nSizeReserved = 0;
   1988 
   1989     if(pDmmBuf == NULL)
   1990     {
   1991         G726DEC_DPRINT("pBuf is NULL\n");
   1992         eError = OMX_ErrorBadParameter;
   1993         goto EXIT;
   1994     }
   1995 
   1996     if(pArmPtr == NULL)
   1997     {
   1998         G726DEC_DPRINT("pBuf is NULL\n");
   1999         eError = OMX_ErrorBadParameter;
   2000         goto EXIT;
   2001     }
   2002 
   2003     /* Allocate */
   2004     pDmmBuf->pAllocated = pArmPtr;
   2005 
   2006     /* Reserve */
   2007     nSizeReserved = ROUND_TO_PAGESIZE(size) + 2*DMM_PAGE_SIZE ;
   2008     status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved));
   2009     G726DEC_DPRINT("\nOMX Reserve DSP: %p\n",pDmmBuf->pReserved);
   2010 
   2011     if(DSP_FAILED(status))
   2012     {
   2013         G726DEC_EPRINT("DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
   2014         eError = OMX_ErrorHardware;
   2015         goto EXIT;
   2016     }
   2017     pDmmBuf->nSize = size;
   2018     G726DEC_DPRINT(" DMM MAP Reserved: %p, size 0x%x (%d)\n", pDmmBuf->pReserved,nSizeReserved,nSizeReserved);
   2019 
   2020     /* Map */
   2021     status = DSPProcessor_Map(ProcHandle,
   2022                               pDmmBuf->pAllocated,/* Arm addres of data to Map on DSP*/
   2023                               size , /* size to Map on DSP*/
   2024                               pDmmBuf->pReserved, /* reserved space */
   2025                               &(pDmmBuf->pMapped), /* returned map pointer */
   2026                               0); /* final param is reserved.  set to zero. */
   2027     if(DSP_FAILED(status))
   2028     {
   2029         G726DEC_EPRINT("DSPProcessor_Map() failed - error 0x%x", (int)status);
   2030         eError = OMX_ErrorHardware;
   2031         goto EXIT;
   2032     }
   2033     G726DEC_DPRINT("DMM Mapped: %p, size 0x%x (%d)\n",pDmmBuf->pMapped, size,size);
   2034 
   2035     /* Issue an initial memory flush to ensure cache coherency */
   2036     status = DSPProcessor_FlushMemory(ProcHandle, pDmmBuf->pAllocated, size, 0);
   2037     if(DSP_FAILED(status))
   2038     {
   2039         G726DEC_EPRINT("Unable to flush mapped buffer: error 0x%x",(int)status);
   2040         goto EXIT;
   2041     }
   2042     eError = OMX_ErrorNone;
   2043 
   2044  EXIT:
   2045     return eError;
   2046 }
   2047 
   2048 /** ========================================================================
   2049  *  OMX_DmmUnMap () method is used to de-allocate the memory using DMM.
   2050  *
   2051  *  @param ProcHandle -  Component identification number
   2052  *  @param pMapPtr  - Map address
   2053  *  @param pResPtr - reserve adress
   2054  *
   2055  *  @retval OMX_ErrorNone  - Success
   2056  *          OMX_ErrorHardware  -  Hardware Error
   2057  ** ==========================================================================*/
   2058 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr)
   2059 {
   2060     DSP_STATUS status = DSP_SOK;
   2061     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2062     G726DEC_DPRINT("\nOMX UnReserve DSP: %p\n",pResPtr);
   2063 
   2064     if(pMapPtr == NULL)
   2065     {
   2066         G726DEC_DPRINT("pMapPtr is NULL\n");
   2067         eError = OMX_ErrorBadParameter;
   2068         goto EXIT;
   2069     }
   2070     if(pResPtr == NULL)
   2071     {
   2072         G726DEC_DPRINT("pResPtr is NULL\n");
   2073         eError = OMX_ErrorBadParameter;
   2074         goto EXIT;
   2075     }
   2076     status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
   2077     if(DSP_FAILED(status))
   2078     {
   2079         G726DEC_EPRINT("DSPProcessor_UnMap() failed - error 0x%x",(int)status);
   2080     }
   2081 
   2082     G726DEC_DPRINT("unreserving  structure =0x%p\n",pResPtr );
   2083     status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
   2084     if(DSP_FAILED(status))
   2085     {
   2086         G726DEC_EPRINT("DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
   2087     }
   2088 
   2089  EXIT:
   2090     return eError;
   2091 }
   2092 
   2093 /* ================================================================================= * */
   2094 /**
   2095  * @fn G726DEC_GetLCMLHandle() function gets the LCML handle and interacts with LCML
   2096  * by using this LCML Handle.
   2097  *
   2098  * @param *pBufHeader This is the buffer header that needs to be processed.
   2099  *
   2100  * @param *pComponentPrivate  This is component's private date structure.
   2101  *
   2102  * @pre          None
   2103  *
   2104  * @post         None
   2105  *
   2106  *  @return      OMX_HANDLETYPE = Successful loading of LCML library.
   2107  *               OMX_ErrorHardware = Hardware error has occured.
   2108  *
   2109  *  @see         None
   2110  */
   2111 /* ================================================================================ * */
   2112 #ifndef UNDER_CE
   2113 OMX_HANDLETYPE G726DEC_GetLCMLHandle(G726DEC_COMPONENT_PRIVATE *pComponentPrivate)
   2114 {
   2115     /* This must be taken care by WinCE */
   2116     OMX_HANDLETYPE pHandle = NULL;
   2117     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2118     void *handle = NULL;
   2119     OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
   2120     char *error = NULL;
   2121 
   2122     handle = dlopen("libLCML.so", RTLD_LAZY);
   2123     if (!handle) {
   2124         fputs(dlerror(), stderr);
   2125         goto EXIT;
   2126     }
   2127 
   2128     fpGetHandle = dlsym (handle, "GetHandle");
   2129     if ((error = dlerror()) != NULL) {
   2130         fputs(error, stderr);
   2131         goto EXIT;
   2132     }
   2133     eError = (*fpGetHandle)(&pHandle);
   2134     if(eError != OMX_ErrorNone) {
   2135         eError = OMX_ErrorUndefined;
   2136         G726DEC_EPRINT("eError != OMX_ErrorNone...\n");
   2137         pHandle = NULL;
   2138         goto EXIT;
   2139     }
   2140 
   2141     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
   2142  EXIT:
   2143     return pHandle;
   2144 }
   2145 #else
   2146 /* WINDOWS Explicit dll load procedure */
   2147 OMX_HANDLETYPE G726DEC_GetLCMLHandle(G726DEC_COMPONENT_PRIVATE *pComponentPrivate)
   2148 {
   2149     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
   2150     OMX_HANDLETYPE pHandle = NULL;
   2151     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2152     HINSTANCE hDLL;               /* Handle to DLL */
   2153     LPFNDLLFUNC1 fpGetHandle1;
   2154 
   2155     hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0);
   2156     if (hDLL == NULL)
   2157     {
   2158         /*fputs(dlerror(), stderr); */
   2159         G726DEC_DPRINT("BML Load Failed!!!\n");
   2160         return pHandle;
   2161     }
   2162 
   2163     fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
   2164     if (!fpGetHandle1)
   2165     {
   2166         /* handle the error */
   2167         FreeLibrary(hDLL);
   2168         return pHandle;
   2169     }
   2170 
   2171     /* call the function */
   2172     eError = fpGetHandle1(&pHandle);
   2173     if(eError != OMX_ErrorNone) {
   2174         eError = OMX_ErrorUndefined;
   2175         G726DEC_EPRINT("eError != OMX_ErrorNone...\n");
   2176         pHandle = NULL;
   2177         return pHandle;
   2178     }
   2179     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
   2180     return pHandle;
   2181 }
   2182 #endif
   2183 
   2184 void G726DEC_CleanupInitParams(OMX_HANDLETYPE pComponent)
   2185 {
   2186     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
   2187     G726DEC_COMPONENT_PRIVATE *pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
   2188         pHandle->pComponentPrivate;
   2189     G726D_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
   2190     OMX_U32 nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
   2191     OMX_U32 i=0;
   2192     OMX_U8 *ptemp = NULL;
   2193 
   2194     G726DEC_DPRINT (":: G726DEC_CleanupInitParams()\n");
   2195     G726DEC_MEMPRINT(":: Freeing:  pComponentPrivate->strmAttr = %p\n", pComponentPrivate->strmAttr);
   2196 
   2197     G726D_OMX_FREE(pComponentPrivate->strmAttr);
   2198     /*pComponentPrivate->strmAttr = NULL;*/
   2199 
   2200     /*if (pComponentPrivate->dasfmode == 1) {*/
   2201     G726DEC_MEMPRINT(":: Freeing: pComponentPrivate->pParams = %p\n",pComponentPrivate->pParams);
   2202     ptemp = (OMX_U8*)pComponentPrivate->pParams;
   2203     if(ptemp != NULL){
   2204         ptemp -= 128;
   2205     }
   2206     pComponentPrivate->pParams = (G726D_USN_AudioCodecParams *)ptemp;
   2207     G726D_OMX_FREE(pComponentPrivate->pParams);
   2208     /*}*/
   2209 
   2210     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT];
   2211     for(i=0; i<nIpBuf; i++) {
   2212         G726DEC_MEMPRINT(":: Freeing: pTemp_lcml->pFrameParam = %p\n",pTemp_lcml->pFrameParam);
   2213         if(pTemp_lcml->pFrameParam!=NULL){
   2214             G726D_OMX_FREE(pTemp_lcml->pFrameParam);
   2215         }
   2216         pTemp_lcml++;
   2217     }
   2218 
   2219     G726DEC_MEMPRINT(":: Freeing pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT] = %p\n",
   2220                      pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT]);
   2221     G726D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT]);
   2222 
   2223 
   2224     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT];
   2225 
   2226     G726DEC_MEMPRINT(":: Freeing: pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT] = %p\n",
   2227                      pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT]);
   2228     G726D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT]);
   2229     G726DEC_DPRINT ("Exiting Successfully G726DEC_CleanupInitParams()\n");
   2230 }
   2231 /* ========================================================================== */
   2232 /**
   2233  * @G726DEC_SetPending() This function marks the buffer as pending when it is sent
   2234  * to DSP/
   2235  *
   2236  * @param pComponentPrivate This is component's private date area.
   2237  *
   2238  * @param pBufHdr This is poiter to OMX Buffer header whose buffer is sent to DSP
   2239  *
   2240  * @param eDir This is direction of buffer i.e. input or output.
   2241  *
   2242  * @pre None
   2243  *
   2244  * @post None
   2245  *
   2246  * @return none
   2247  */
   2248 /* ========================================================================== */
   2249 void G726DEC_SetPending(G726DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   2250 {
   2251     OMX_U16 i = 0;
   2252 
   2253     G726DEC_DPRINT("Called G726DEC_SetPending\n");
   2254     G726DEC_DPRINT("eDir = %d\n",eDir);
   2255 
   2256     if (eDir == OMX_DirInput) {
   2257         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2258             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2259                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
   2260                 G726DEC_DPRINT("*******************INPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
   2261             }
   2262         }
   2263     }
   2264     else {
   2265         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2266             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2267                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
   2268                 G726DEC_DPRINT("*******************OUTPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
   2269             }
   2270         }
   2271     }
   2272 }
   2273 
   2274 /* ========================================================================== */
   2275 /**
   2276  * @G726DEC_ClearPending() This function clears the buffer status from pending
   2277  * when it is received back from DSP.
   2278  *
   2279  * @param pComponentPrivate This is component's private date area.
   2280  *
   2281  * @param pBufHdr This is poiter to OMX Buffer header that is received from
   2282  * DSP/LCML.
   2283  *
   2284  * @param eDir This is direction of buffer i.e. input or output.
   2285  *
   2286  * @pre None
   2287  *
   2288  * @post None
   2289  *
   2290  * @return none
   2291  */
   2292 /* ========================================================================== */
   2293 
   2294 void G726DEC_ClearPending(G726DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   2295 {
   2296     OMX_U16 i = 0;
   2297     G726DEC_DPRINT("!!!             Entering ClearPending!! eDir = %d\n\n", eDir);
   2298     if (eDir == OMX_DirInput) {
   2299         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2300             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2301                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
   2302                 G726DEC_DPRINT("*******************INPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
   2303             }
   2304         }
   2305     }
   2306     else {
   2307         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2308             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2309                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
   2310                 G726DEC_DPRINT("*******************OUTPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
   2311             }
   2312         }
   2313     }
   2314 }
   2315 
   2316 /* ========================================================================== */
   2317 /**
   2318  * @G726DEC_IsPending() This function checks whether or not a buffer is pending.
   2319  *
   2320  * @param pComponentPrivate This is component's private date area.
   2321  *
   2322  * @param pBufHdr This is poiter to OMX Buffer header of interest.
   2323  *
   2324  * @param eDir This is direction of buffer i.e. input or output.
   2325  *
   2326  * @pre None
   2327  *
   2328  * @post None
   2329  *
   2330  * @return none
   2331  */
   2332 /* ========================================================================== */
   2333 
   2334 OMX_U32 G726DEC_IsPending(G726DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
   2335 {
   2336     OMX_U16 i = 0;
   2337 
   2338     if (eDir == OMX_DirInput) {
   2339         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2340             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2341                 return pComponentPrivate->pInputBufferList->bBufferPending[i];
   2342             }
   2343         }
   2344     }
   2345     else {
   2346         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2347             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2348                 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
   2349             }
   2350         }
   2351     }
   2352     return -1;
   2353 }
   2354 
   2355 
   2356 /* ========================================================================== */
   2357 /**
   2358  * @G726DEC_IsValid() This function identifies whether or not buffer recieved from
   2359  * LCML is valid. It searches in the list of input/output buffers to do this.
   2360  *
   2361  * @param pComponentPrivate This is component's private date area.
   2362  *
   2363  * @param pBufHdr This is poiter to OMX Buffer header of interest.
   2364  *
   2365  * @param eDir This is direction of buffer i.e. input or output.
   2366  *
   2367  * @pre None
   2368  *
   2369  * @post None
   2370  *
   2371  * @return status of the buffer.
   2372  */
   2373 /* ========================================================================== */
   2374 
   2375 OMX_U32 G726DEC_IsValid(G726DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir)
   2376 {
   2377     OMX_U16 i = 0;
   2378     OMX_U32 found=0;
   2379 
   2380     if (eDir == OMX_DirInput) {
   2381         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2382             if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) {
   2383                 found = 1;
   2384             }
   2385         }
   2386     }
   2387     else {
   2388         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2389             if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) {
   2390                 found = 1;
   2391             }
   2392         }
   2393     }
   2394     return found;
   2395 }
   2396 
   2397 /* ========================================================================== */
   2398 /**
   2399  * @G726DECFill_LCMLInitParamsEx() This function initializes the init parameter of
   2400  * the LCML structure when a port is enabled and component is in idle state.
   2401  *
   2402  * @param pComponent This is component handle.
   2403  *
   2404  * @pre None
   2405  *
   2406  * @post None
   2407  *
   2408  * @return appropriate OMX Error.
   2409  */
   2410 /* ========================================================================== */
   2411 
   2412 OMX_ERRORTYPE G726DECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent)
   2413 
   2414 {
   2415     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2416     OMX_U32 nIpBuf = 0,nIpBufSize = 0,nOpBuf = 0,nOpBufSize = 0;
   2417     OMX_U32 i = 0;
   2418     OMX_BUFFERHEADERTYPE *pTemp = NULL;
   2419     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
   2420     G726DEC_COMPONENT_PRIVATE *pComponentPrivate =
   2421         (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2422     G726D_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
   2423     OMX_U32 size_lcml = 0;
   2424     OMX_U8 *ptr = NULL;
   2425 
   2426 
   2427     G726DEC_DPRINT(":: Entered Fill_LCMLInitParams");
   2428 
   2429 
   2430     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
   2431     nOpBuf = pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferCountActual;                   /* pComponentPrivate->pOutputBufferList->numBuffers; */
   2432     nIpBufSize = pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nBufferSize;
   2433     nOpBufSize = pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferSize;
   2434 
   2435 
   2436     G726DEC_BUFPRINT("Input Buffer Count = %ld\n",nIpBuf);
   2437     G726DEC_BUFPRINT("Input Buffer Size = %ld\n",nIpBufSize);
   2438     G726DEC_BUFPRINT("Output Buffer Count = %ld\n",nOpBuf);
   2439     G726DEC_BUFPRINT("Output Buffer Size = %ld\n",nOpBufSize);
   2440 
   2441 
   2442 
   2443     G726DEC_DPRINT(":: bufAlloced = %d\n",pComponentPrivate->bufAlloced);
   2444     size_lcml = nIpBuf * sizeof(G726D_LCML_BUFHEADERTYPE);
   2445 
   2446     G726D_OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8);
   2447     pTemp_lcml = (G726D_LCML_BUFHEADERTYPE *)ptr;
   2448 
   2449     pComponentPrivate->pLcmlBufHeader[G726D_INPUT_PORT] = pTemp_lcml;
   2450 
   2451     for (i=0; i<nIpBuf; i++) {
   2452         if(pComponentPrivate->bufAlloced == 0) {
   2453             G726D_OMX_MALLOC(pTemp, OMX_BUFFERHEADERTYPE);
   2454         } else {
   2455             G726DEC_DPRINT(":: IpBufferHeader %p is already there\n",
   2456                            pComponentPrivate->pInputBufferList->pBufHdr[i]);
   2457             pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
   2458         }
   2459 
   2460         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   2461 
   2462         pTemp->nAllocLen = nIpBufSize;
   2463         pTemp->nFilledLen = nIpBufSize;
   2464         pTemp->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
   2465         pTemp->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
   2466 
   2467         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   2468         pTemp->nTickCount = DONT_CARE;
   2469 
   2470         if (pComponentPrivate->bufAlloced == 0) {
   2471             G726D_OMX_MALLOC_SIZE(pTemp->pBuffer,(nIpBufSize+256),OMX_U8);
   2472             pTemp->pBuffer = pTemp->pBuffer + 128;
   2473         } else {
   2474             G726DEC_DPRINT(":: IpBuffer %p is already there\n",pTemp->pBuffer);
   2475         }
   2476 
   2477         if (pTemp->pBuffer == NULL) {
   2478             G726DEC_EPRINT(":: Malloc Failed...\n");
   2479             goto EXIT;
   2480         }
   2481 
   2482         pTemp_lcml->pBufHdr = pTemp;
   2483         pTemp_lcml->eDir = OMX_DirInput;
   2484         pTemp_lcml->pOtherParams[i] = NULL;
   2485 
   2486         G726D_OMX_MALLOC(pTemp_lcml->pFrameParam, G726DEC_UAlgInBufParamStruct);
   2487         pTemp_lcml->pFrameParam->bLastBuffer = 0;
   2488 
   2489         pTemp->nFlags = NORMAL_BUFFER;
   2490         ((G726DEC_COMPONENT_PRIVATE *) pTemp->pPlatformPrivate)->pHandle = pHandle;
   2491 
   2492         G726DEC_DPRINT("::Comp: InBuffHeader[%ld] = %p\n", i, pTemp);
   2493         G726DEC_DPRINT("::Comp:  >>>> InputBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer);
   2494         G726DEC_DPRINT("::Comp: Ip : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml);
   2495 
   2496         pTemp_lcml++;
   2497     }
   2498 
   2499     size_lcml = nOpBuf * sizeof(G726D_LCML_BUFHEADERTYPE);
   2500 
   2501     G726D_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,G726D_LCML_BUFHEADERTYPE);
   2502     pComponentPrivate->pLcmlBufHeader[G726D_OUTPUT_PORT] = pTemp_lcml;
   2503 
   2504     for (i=0; i<nOpBuf; i++) {
   2505         if(pComponentPrivate->bufAlloced == 0) {
   2506             G726D_OMX_MALLOC(pTemp, OMX_BUFFERHEADERTYPE);
   2507         } else {
   2508             G726DEC_DPRINT(":: OpBufferHeader %p is already there\n",
   2509                            pComponentPrivate->pOutputBufferList->pBufHdr[i]);
   2510             pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   2511         }
   2512 
   2513         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   2514 
   2515         pTemp->nAllocLen = nOpBufSize;
   2516         pTemp->nFilledLen = nOpBufSize;
   2517         pTemp->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
   2518         pTemp->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
   2519 
   2520         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   2521         pTemp->nTickCount = DONT_CARE;
   2522 
   2523         if (pComponentPrivate->bufAlloced == 0) {
   2524             G726D_OMX_MALLOC_SIZE(pTemp->pBuffer,(nOpBufSize+256),OMX_U8);
   2525             pTemp->pBuffer += 128;
   2526             G726DEC_DPRINT("%d:: OpBuffer %p is already there\n",__LINE__,pTemp->pBuffer);
   2527         } else {
   2528             G726DEC_DPRINT(":: OpBuffer %p is already there\n",pTemp->pBuffer);
   2529         }
   2530 
   2531         pTemp_lcml->pBufHdr = pTemp;
   2532         pTemp_lcml->eDir = OMX_DirOutput;
   2533         pTemp_lcml->pOtherParams[i] = NULL;
   2534 
   2535 
   2536         pTemp->nFlags = NORMAL_BUFFER;
   2537         ((G726DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
   2538         G726DEC_DPRINT("::Comp:  >>>>>>>>>>>>> OutBuffHeader[%ld] = %p\n", i, pTemp);
   2539         G726DEC_DPRINT("::Comp:  >>>> OutBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer);
   2540         G726DEC_DPRINT("::Comp: Op : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml);
   2541         pTemp_lcml++;
   2542     }
   2543     pComponentPrivate->bPortDefsAllocated = 1;
   2544 
   2545     G726DEC_DPRINT(":: Exiting Fill_LCMLInitParams");
   2546 
   2547     pComponentPrivate->bInitParamsInitialized = 1;
   2548 
   2549  EXIT:
   2550     return eError;
   2551 }
   2552 
   2553 #ifdef RESOURCE_MANAGER_ENABLED
   2554 /***********************************
   2555  *  Callback to the RM                                       *
   2556  ***********************************/
   2557 void G726DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
   2558 {
   2559     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   2560     OMX_STATETYPE state = OMX_StateIdle;
   2561     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
   2562     G726DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
   2563 
   2564     pCompPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2565 
   2566     if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
   2567         if (pCompPrivate->curState == OMX_StateExecuting ||
   2568             pCompPrivate->curState == OMX_StatePause) {
   2569 
   2570             write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
   2571             write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
   2572 
   2573             pCompPrivate->bPreempted = 1;
   2574         }
   2575     }
   2576     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
   2577         pCompPrivate->cbInfo.EventHandler ( pHandle,
   2578                                             pHandle->pApplicationPrivate,
   2579                                             OMX_EventResourcesAcquired,
   2580                                             0, 0, NULL);
   2581     }
   2582 }
   2583 #endif
   2584