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_G726Enc_Utils.c
     30 *
     31 * This file implements G726 Encoder Component Specific APIs and its functionality
     32 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
     33 *
     34 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g726_enc\src
     35 *
     36 * @rev  1.0
     37 */
     38 /* ----------------------------------------------------------------------------
     39 *!
     40 *! Revision History
     41 *! ===================================
     42 *! Gyancarlo Garcia: Initial Verision
     43 *! 05-Oct-2007
     44 *!
     45 * =========================================================================== */
     46 
     47 /* ------compilation control switches -------------------------*/
     48 /****************************************************************
     49 *  INCLUDE FILES
     50 ****************************************************************/
     51 /* ----- system and platform files ----------------------------*/
     52 #ifdef UNDER_CE
     53 #include <windows.h>
     54 #include <oaf_osal.h>
     55 #include <omx_core.h>
     56 #else
     57 #include <unistd.h>
     58 #include <sys/types.h>
     59 #include <sys/types.h>
     60 #include <sys/stat.h>
     61 #include <dlfcn.h>
     62 #include <malloc.h>
     63 #include <memory.h>
     64 #include <fcntl.h>
     65 #include <errno.h>
     66 #endif
     67 
     68 #include <dbapi.h>
     69 #include <string.h>
     70 #include <stdio.h>
     71 #include <stdlib.h>
     72 /*-------program files ----------------------------------------*/
     73 
     74 #ifdef RESOURCE_MANAGER_ENABLED
     75 #include <ResourceManagerProxyAPI.h>
     76 #endif
     77 
     78 #include "OMX_G726Enc_Utils.h"
     79 #include "g726enc_sn_uuid.h"
     80 #include <encode_common_ti.h>
     81 #include "usn.h"
     82 
     83 #ifdef UNDER_CE
     84 #define HASHINGENABLE 1
     85 #endif
     86 
     87 #ifdef G726ENC_DEBUGMEM
     88 extern void *arr[500] = {NULL};
     89 extern int lines[500] = {0};
     90 extern int bytes[500] = {0};
     91 extern char file[500][50] ={""};
     92 
     93 void * DebugMalloc(int line, char *s, int size);
     94 int DebugFree(void *dp, int line, char *s);
     95 
     96 #define SafeMalloc(x) DebugMalloc(__LINE__,__FILE__,x)
     97 #define SafeFree(z) DebugFree(z,__LINE__,__FILE__)
     98 
     99 void * DebugMalloc(int line, char *s, int size)
    100 {
    101    void *p = NULL;
    102    int e=0;
    103    p = calloc(1,size);
    104    if(p==NULL){
    105        printf("__ Memory not available\n");
    106        exit(1);
    107        }
    108    else{
    109          while((lines[e]!=0)&& (e<500) ){
    110               e++;
    111          }
    112          arr[e]=p;
    113          lines[e]=line;
    114          bytes[e]=size;
    115          strcpy(file[e],s);
    116          printf("__ Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s);
    117          return p;
    118    }
    119 }
    120 
    121 int DebugFree(void *dp, int line, char *s){
    122     int q = 0;
    123     if(dp==NULL){
    124                  printf("__ NULL can't be deleted\n");
    125                  return 0;
    126     }
    127     for(q=0;q<500;q++){
    128         if(arr[q]==dp){
    129            printf("__ Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
    130            lines[q]=0;
    131            strcpy(file[q],"");
    132            free(dp);
    133            dp = NULL;
    134            break;
    135         }
    136      }
    137      if(500==q)
    138          printf("\n\n__ Pointer not found. Line:%d    File%s!!\n\n",line, s);
    139 }
    140 #else
    141 #define SafeMalloc(x) calloc(1,x)
    142 #define SafeFree(z) free(z)
    143 #endif
    144 
    145 /* ========================================================================== */
    146 /**
    147 * @G726ENC_FillLCMLInitParams () This function is used by the component thread to
    148 * fill the all of its initialization parameters, buffer deatils  etc
    149 * to LCML structure,
    150 *
    151 * @param pComponent  handle for this instance of the component
    152 * @param plcml_Init  pointer to LCML structure to be filled
    153 *
    154 * @pre
    155 *
    156 * @post
    157 *
    158 * @return none
    159 */
    160 /* ========================================================================== */
    161 
    162 OMX_ERRORTYPE G726ENC_FillLCMLInitParams(OMX_HANDLETYPE pComponent,
    163                                   LCML_DSP *plcml_Init, OMX_U16 arr[])
    164 {
    165     OMX_ERRORTYPE eError = OMX_ErrorNone;
    166     OMX_U32 nIpBuf = 0,nIpBufSize = 0,nOpBuf = 0,nOpBufSize = 0;
    167     OMX_BUFFERHEADERTYPE *pTemp = NULL;
    168     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
    169     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
    170     G726ENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
    171     OMX_U32 i = 0;
    172     OMX_U32 size_lcml = 0;
    173     OMX_U8 *pstrTemp = NULL;
    174     OMX_U8 *pBufferParamTemp = NULL;
    175     G726ENC_DPRINT("%d :: Entering G726ENC_FillLCMLInitParams\n",__LINE__);
    176 
    177     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
    178     nIpBufSize = pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nBufferSize;
    179     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
    180     nOpBufSize = pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nBufferSize;
    181 
    182     pComponentPrivate->nRuntimeInputBuffers = (OMX_U8)nIpBuf;
    183     pComponentPrivate->nRuntimeOutputBuffers = (OMX_U8) nOpBuf;
    184 
    185     G726ENC_DPRINT("%d :: ------ Buffer Details -----------\n",__LINE__);
    186     G726ENC_DPRINT("%d :: Input  Buffer Count = %ld\n",__LINE__,nIpBuf);
    187     G726ENC_DPRINT("%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
    188     G726ENC_DPRINT("%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
    189     G726ENC_DPRINT("%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
    190     G726ENC_DPRINT("%d :: ------ Buffer Details ------------\n",__LINE__);
    191 
    192     /* Fill Input Buffers Info for LCML */
    193     plcml_Init->In_BufInfo.nBuffers = nIpBuf;
    194     plcml_Init->In_BufInfo.nSize = nIpBufSize;
    195     plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
    196 
    197     /* Fill Output Buffers Info for LCML */
    198     plcml_Init->Out_BufInfo.nBuffers = nOpBuf;
    199     plcml_Init->Out_BufInfo.nSize = nOpBufSize;
    200     plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
    201 
    202     /*Copy the node information*/
    203     plcml_Init->NodeInfo.nNumOfDLLs = 3;
    204 
    205     plcml_Init->NodeInfo.AllUUIDs[0].uuid = &G726ENCSOCKET_TI_UUID;
    206     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,G726ENC_DLL_NAME);
    207     plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
    208 
    209     plcml_Init->NodeInfo.AllUUIDs[1].uuid = &G726ENCSOCKET_TI_UUID;
    210     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,G726ENC_DLL_NAME);
    211     plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
    212 
    213     /*plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;*/
    214     plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
    215     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName,G726ENC_USN_DLL_NAME);
    216     plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
    217 
    218     plcml_Init->DeviceInfo.TypeofDevice = 0;
    219 
    220     if(pComponentPrivate->dasfMode == 1) {
    221         G726ENC_DPRINT("%d :: Codec is configuring to DASF mode\n",__LINE__);
    222         pstrTemp = (OMX_U8*)SafeMalloc(sizeof(LCML_STRMATTR) + 256);
    223         if(pstrTemp == NULL){
    224                         G726ENC_EPRINT("***********************************\n");
    225                         G726ENC_EPRINT("%d :: Malloc Failed\n",__LINE__);
    226                         G726ENC_EPRINT("***********************************\n");
    227                         eError = OMX_ErrorInsufficientResources;
    228                         goto EXIT;
    229         }
    230         pComponentPrivate->strmAttr = (LCML_STRMATTR*)(pstrTemp + 128);
    231         pComponentPrivate->strmAttr->uSegid = G726ENC_DEFAULT_SEGMENT;
    232         pComponentPrivate->strmAttr->uAlignment = 0;
    233         pComponentPrivate->strmAttr->uTimeout = G726ENC_SN_TIMEOUT;
    234         pComponentPrivate->strmAttr->uBufsize = nIpBufSize;
    235         pComponentPrivate->strmAttr->uNumBufs = G726ENC_NUM_INPUT_BUFFERS_DASF;
    236         pComponentPrivate->strmAttr->lMode = STRMMODE_PROCCOPY;
    237         /* Device is Configuring to DASF Mode */
    238         plcml_Init->DeviceInfo.TypeofDevice = 1;
    239         /* Device is Configuring to Record Mode */
    240         plcml_Init->DeviceInfo.TypeofRender = 1;
    241 
    242         if(pComponentPrivate->acdnMode == 1) {
    243             /* ACDN mode */
    244             plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &ACDN_TI_UUID;
    245         }
    246         else {
    247             /* DASF/TeeDN mode */
    248             plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
    249         }
    250         plcml_Init->DeviceInfo.DspStream = pComponentPrivate->strmAttr;
    251     }
    252 
    253     /*copy the other information*/
    254     plcml_Init->SegID = G726ENC_DEFAULT_SEGMENT;
    255     plcml_Init->Timeout = G726ENC_SN_TIMEOUT;
    256     plcml_Init->Alignment = 0;
    257     plcml_Init->Priority = G726ENC_SN_PRIORITY;
    258     plcml_Init->ProfileID = 0;
    259 
    260     /* Setting Creat Phase Parameters here */
    261     arr[0] = G726ENC_STREAM_COUNT;                                           /* Number of communication paths      */
    262     arr[1] = G726ENC_INPUT_PORT;                                             /* Input Path id                      */
    263 
    264     if(pComponentPrivate->dasfMode == 1) {
    265         arr[2] = G726ENC_INSTRM;                                             /* Streaming on input                 */
    266         arr[3] = G726ENC_NUM_INPUT_BUFFERS_DASF;                             /* Audio Devices are connected        */
    267     }
    268     else {
    269             arr[2] = G726ENC_DMM;                                                /* DMM buffers will be used           */                                              if (pComponentPrivate->pInputBufferList->numBuffers) {
    270             arr[3] = (OMX_U16) pComponentPrivate->pInputBufferList->numBuffers;/* #Bufs exchanged between SN and GPP */
    271         }
    272     }
    273 
    274     arr[4] = G726ENC_OUTPUT_PORT;                                            /* Output Path id                     */
    275     arr[5] = G726ENC_DMM;                                                    /* DMM buffers will be used           */
    276     if (pComponentPrivate->pOutputBufferList->numBuffers) {
    277         arr[6] = (OMX_U16) pComponentPrivate->pOutputBufferList->numBuffers;   /* #Bufs exchanged between SN and GPP */
    278     }
    279     else {
    280         arr[6] = (OMX_U16)1;                                                   /* 1 Buf exchanged between SN and GPP */
    281     }
    282 
    283     arr[7] = pComponentPrivate->G726Params[G726ENC_OUTPUT_PORT]->eG726Mode-1;    /* 0 - 16kbps  Codec Selection */
    284                                                                                  /* 1 - 24 kbps Codec Selection */
    285                                                                                  /* 2 - 32 kbps Codec Selection */
    286                                                                                  /* 3 - 40 kbps Codec Selection */
    287 
    288     arr[8] =  (OMX_U16) pComponentPrivate->rtpMode;                    /* 0 - Linear Packing Type */
    289                                                                        /* 1 - RTP Packing Type    */
    290                                                                        /*What's the right value??*/
    291     arr[9] = END_OF_CR_PHASE_ARGS;
    292 
    293     plcml_Init->pCrPhArgs = arr;
    294 
    295     /* Allocate memory for all input buffer headers..
    296      * This memory pointer will be sent to LCML */
    297     size_lcml = nIpBuf * sizeof(G726ENC_LCML_BUFHEADERTYPE);
    298     pTemp_lcml = (G726ENC_LCML_BUFHEADERTYPE *)SafeMalloc(size_lcml);
    299 
    300     G726ENC_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,pTemp_lcml);
    301     if(pTemp_lcml == NULL) {
    302         G726ENC_DPRINT("%d :: Memory Allocation Failed\n",__LINE__);
    303         eError = OMX_ErrorInsufficientResources;
    304         goto EXIT;
    305     }
    306     pComponentPrivate->pLcmlBufHeader[G726ENC_INPUT_PORT] = pTemp_lcml;
    307     for (i=0; i<nIpBuf; i++) {
    308         G726ENC_DPRINT("%d :: INPUT--------- Inside Ip Loop\n",__LINE__);
    309         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
    310         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    311         pTemp->nFilledLen = nIpBufSize;
    312         pTemp->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER;
    313         pTemp->nVersion.s.nVersionMinor = G726ENC_MINOR_VER;
    314         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    315         pTemp->nTickCount = G726ENC_NOT_USED;
    316         pTemp_lcml->buffer = pTemp;
    317         G726ENC_DPRINT("%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
    318         pTemp_lcml->eDir = OMX_DirInput;
    319 
    320         pBufferParamTemp = (OMX_U8*)SafeMalloc( sizeof(G726ENC_ParamStruct) + 256);
    321 	if (pBufferParamTemp == NULL) {
    322 	    G726ENC_DPRINT("%d :: Memory Allocation Failed\n", __LINE__);
    323 	    eError = OMX_ErrorInsufficientResources;
    324 	    goto EXIT;
    325 	}
    326         memset(pBufferParamTemp, 0x0, sizeof(G726ENC_ParamStruct) + 256);
    327         pTemp_lcml->pIpParam =  (G726ENC_ParamStruct*)(pBufferParamTemp + 128);
    328 
    329         pTemp_lcml->pIpParam->bLastBuffer = 0;
    330         /* This means, it is not a last buffer. This flag is to be modified by
    331          * the application to indicate the last buffer */
    332         pTemp->nFlags = G726ENC_NORMAL_BUFFER;
    333         pTemp++;
    334         pTemp_lcml++;
    335     }
    336 
    337     /* Allocate memory for all output buffer headers..
    338      * This memory pointer will be sent to LCML */
    339     size_lcml = nOpBuf * sizeof(G726ENC_LCML_BUFHEADERTYPE);
    340     pTemp_lcml = (G726ENC_LCML_BUFHEADERTYPE *)SafeMalloc(size_lcml);
    341     G726ENC_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,pTemp_lcml);
    342     if(pTemp_lcml == NULL) {
    343         G726ENC_DPRINT("%d :: Memory Allocation Failed\n",__LINE__);
    344         eError = OMX_ErrorInsufficientResources;
    345         goto EXIT;
    346     }
    347 
    348     pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT] = pTemp_lcml;
    349     for (i=0; i<nOpBuf; i++) {
    350         G726ENC_DPRINT("%d :: OUTPUT--------- Inside Op Loop\n",__LINE__);
    351         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
    352         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    353         pTemp->nFilledLen = nOpBufSize;
    354         pTemp->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER;
    355         pTemp->nVersion.s.nVersionMinor = G726ENC_MINOR_VER;
    356         pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
    357         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    358         pTemp->nTickCount = G726ENC_NOT_USED;
    359         pTemp_lcml->buffer = pTemp;
    360         G726ENC_DPRINT("%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
    361         pTemp_lcml->eDir = OMX_DirOutput;
    362 
    363         /* This means, it is not a last buffer. This flag is to be modified by
    364          * the application to indicate the last buffer */
    365         pTemp->nFlags = G726ENC_NORMAL_BUFFER;
    366         pTemp++;
    367         pTemp_lcml++;
    368     }
    369 
    370     pComponentPrivate->bPortDefsAllocated = 1;
    371     pComponentPrivate->bInitParamsInitialized = 1;
    372 EXIT:
    373     G726ENC_DPRINT("%d :: Exiting G726ENC_FillLCMLInitParams\n",__LINE__);
    374     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
    375     return eError;
    376 }
    377 
    378 /* ========================================================================== */
    379 /**
    380 * @G726ENC_StartComponentThread() This function is called by the component to create
    381 * the component thread, command pipes, data pipes and LCML Pipes.
    382 *
    383 * @param pComponent  handle for this instance of the component
    384 *
    385 * @pre
    386 *
    387 * @post
    388 *
    389 * @return none
    390 */
    391 /* ========================================================================== */
    392 OMX_ERRORTYPE G726ENC_StartComponentThread(OMX_HANDLETYPE pComponent)
    393 {
    394     OMX_ERRORTYPE eError = OMX_ErrorNone;
    395     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    396     G726ENC_COMPONENT_PRIVATE *pComponentPrivate =
    397                         (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    398 #ifdef UNDER_CE
    399     pthread_attr_t attr;
    400     memset(&attr, 0, sizeof(attr));
    401     attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
    402     attr.__schedparam.__sched_priority = OMX_AUDIO_ENCODER_THREAD_PRIORITY;
    403 #endif
    404 
    405     G726ENC_DPRINT ("%d :: Enetering  G726ENC_StartComponentThread\n", __LINE__);
    406     /* Initialize all the variables*/
    407     pComponentPrivate->bIsStopping = 0;
    408 
    409     /* create the pipe used to send buffers to the thread */
    410     eError = pipe (pComponentPrivate->cmdDataPipe);
    411     if (eError) {
    412        eError = OMX_ErrorInsufficientResources;
    413        G726ENC_DPRINT("%d :: Error while creating cmdDataPipe\n",__LINE__);
    414        goto EXIT;
    415     }
    416     /* create the pipe used to send buffers to the thread */
    417     eError = pipe (pComponentPrivate->dataPipe);
    418     if (eError) {
    419        eError = OMX_ErrorInsufficientResources;
    420        G726ENC_DPRINT("%d :: Error while creating dataPipe\n",__LINE__);
    421        goto EXIT;
    422     }
    423 
    424     /* create the pipe used to send commands to the thread */
    425     eError = pipe (pComponentPrivate->cmdPipe);
    426     if (eError) {
    427        eError = OMX_ErrorInsufficientResources;
    428        G726ENC_DPRINT("%d :: Error while creating cmdPipe\n",__LINE__);
    429        goto EXIT;
    430     }
    431 
    432     /* Create the Component Thread */
    433 #ifdef UNDER_CE
    434     eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr,
    435                                        G726ENC_CompThread, pComponentPrivate);
    436 #else
    437     eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL,
    438                                        G726ENC_CompThread, pComponentPrivate);
    439 #endif
    440     if (eError || !pComponentPrivate->ComponentThread) {
    441        eError = OMX_ErrorInsufficientResources;
    442        goto EXIT;
    443     }
    444 
    445     pComponentPrivate->bCompThreadStarted = 1;
    446 EXIT:
    447     G726ENC_DPRINT("%d :: Exiting G726ENC_StartComponentThread\n", __LINE__);
    448     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
    449     return eError;
    450 }
    451 
    452 /* ========================================================================== */
    453 /**
    454 * @G726ENC_FreeCompResources() This function is called by the component during
    455 * de-init , to free Command pipe, data pipe & LCML pipe.
    456 *
    457 * @param pComponent  handle for this instance of the component
    458 *
    459 * @pre
    460 *
    461 * @post
    462 *
    463 * @return none
    464 */
    465 /* ========================================================================== */
    466 
    467 OMX_ERRORTYPE G726ENC_FreeCompResources(OMX_HANDLETYPE pComponent)
    468 {
    469     OMX_ERRORTYPE eError = OMX_ErrorNone;
    470     OMX_ERRORTYPE err = OMX_ErrorNone;
    471     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    472     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)
    473                                                      pHandle->pComponentPrivate;
    474     G726ENC_DPRINT("%d :: Entering G726ENC_FreeCompResources\n",__LINE__);
    475 
    476     if (pComponentPrivate->bCompThreadStarted) {
    477         OMX_NBCLOSE_PIPE(pComponentPrivate->dataPipe[0],err);
    478         OMX_NBCLOSE_PIPE(pComponentPrivate->dataPipe[1],err);
    479         OMX_NBCLOSE_PIPE(pComponentPrivate->cmdPipe[0],err);
    480         OMX_NBCLOSE_PIPE(pComponentPrivate->cmdPipe[1],err);
    481         OMX_NBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[0],err);
    482         OMX_NBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
    483     }
    484 
    485 /*    if (pComponentPrivate->bPortDefsAllocated) {*/
    486         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]);
    487         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]);
    488         OMX_NBMEMFREE_STRUCT(pComponentPrivate->G726Params[G726ENC_INPUT_PORT]);
    489         OMX_NBMEMFREE_STRUCT(pComponentPrivate->G726Params[G726ENC_OUTPUT_PORT]);
    490 
    491         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat);
    492         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat);
    493         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]);
    494         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]);
    495 
    496         OMX_NBMEMFREE_STRUCT(pComponentPrivate->sPortParam);
    497         OMX_NBMEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
    498         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
    499         OMX_NBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
    500 
    501  /*   }*/
    502     pComponentPrivate->bPortDefsAllocated = 0;
    503 EXIT:
    504     G726ENC_DPRINT("%d :: Exiting G726ENC_FreeCompResources()\n",__LINE__);
    505     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
    506     return eError;
    507 }
    508 
    509 /* ========================================================================== */
    510 /**
    511 * @G726ENC_CleanupInitParams() This function is called by the component during
    512 * de-init to free structues that are been allocated at intialization stage
    513 *
    514 * @param pComponent  handle for this instance of the component
    515 *
    516 * @pre
    517 *
    518 * @post
    519 *
    520 * @return none
    521 */
    522 /* ========================================================================== */
    523 
    524 OMX_ERRORTYPE G726ENC_CleanupInitParams(OMX_HANDLETYPE pComponent)
    525 {
    526     OMX_ERRORTYPE eError = OMX_ErrorNone;
    527     OMX_U32 i = 0;
    528     OMX_U8 *pTemp = NULL;
    529     G726ENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
    530     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    531     OMX_U8* pBufParmsTemp = NULL;
    532     OMX_U8* pParamsTemp = NULL;
    533     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)
    534                                                      pHandle->pComponentPrivate;
    535     G726ENC_DPRINT("%d :: Entering G726ENC_CleanupInitParams()\n", __LINE__);
    536 
    537     if(pComponentPrivate->dasfMode == 1) {
    538         pTemp = (OMX_U8*)pComponentPrivate->strmAttr;
    539         if(pTemp!=NULL)
    540                pTemp -=128;
    541         OMX_NBMEMFREE_STRUCT(pTemp);
    542     }
    543 
    544     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G726ENC_INPUT_PORT];
    545 
    546     for(i=0; i<pComponentPrivate->nRuntimeInputBuffers; i++) {
    547           pBufParmsTemp = (OMX_U8*)pTemp_lcml->pIpParam;
    548           pBufParmsTemp-=128;
    549           SafeFree(pBufParmsTemp);
    550           pTemp_lcml->pIpParam = NULL;
    551           pTemp_lcml++;
    552     }
    553 
    554     pParamsTemp = (OMX_U8*)pComponentPrivate->pParams;
    555     if (pParamsTemp != NULL)
    556         pParamsTemp -= 128;
    557     OMX_NBMEMFREE_STRUCT(pParamsTemp);
    558     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT];
    559 
    560     for(i=0; i<pComponentPrivate->nRuntimeOutputBuffers; i++) {
    561 /*        OMX_NBMEMFREE_STRUCT(pTemp_lcml->pOpParam);*/ /* according to the SN guide, the params on the */
    562                                                         /* output buffer shoul not be needed                 */
    563         pTemp_lcml++;
    564     }
    565 
    566     OMX_NBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G726ENC_INPUT_PORT]);
    567     OMX_NBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT]);
    568 
    569     G726ENC_DPRINT("%d :: Exiting G726ENC_CleanupInitParams()\n",__LINE__);
    570     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
    571     return eError;
    572 }
    573 
    574 /* ========================================================================== */
    575 /**
    576 * @G726ENC_StopComponentThread() This function is called by the component during
    577 * de-init to close component thread.
    578 *
    579 * @param pComponent  handle for this instance of the component
    580 *
    581 * @pre
    582 *
    583 * @post
    584 *
    585 * @return none
    586 */
    587 /* ========================================================================== */
    588 
    589 OMX_ERRORTYPE G726ENC_StopComponentThread(OMX_HANDLETYPE pComponent)
    590 {
    591     OMX_ERRORTYPE eError = OMX_ErrorNone;
    592     OMX_ERRORTYPE threadError = OMX_ErrorNone;
    593     int pthreadError = 0;
    594     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    595     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)
    596                                                      pHandle->pComponentPrivate;
    597     G726ENC_DPRINT("%d :: Entering G726ENC_StopComponentThread\n",__LINE__);
    598     G726ENC_DPRINT("%d :: About to call pthread_join\n",__LINE__);
    599     pthreadError = pthread_join (pComponentPrivate->ComponentThread,
    600                                  (void*)&threadError);
    601     if (0 != pthreadError) {
    602         eError = OMX_ErrorHardware;
    603         G726ENC_DPRINT("%d :: Error closing ComponentThread - pthreadError = %d\n",__LINE__,pthreadError);
    604         goto EXIT;
    605     }
    606     if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) {
    607         eError = OMX_ErrorInsufficientResources;
    608         G726ENC_DPRINT("%d :: Error while closing Component Thread\n",__LINE__);
    609         goto EXIT;
    610     }
    611 EXIT:
    612    G726ENC_DPRINT("%d :: Exiting G726ENC_StopComponentThread\n",__LINE__);
    613    G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
    614    return eError;
    615 }
    616 
    617 
    618 /* ========================================================================== */
    619 /**
    620 * @G726ENC_HandleCommand() This function is called by the component when ever it
    621 * receives the command from the application
    622 *
    623 * @param pComponentPrivate  Component private data
    624 *
    625 * @pre
    626 *
    627 * @post
    628 *
    629 * @return none
    630 */
    631 /* ========================================================================== */
    632 
    633 OMX_U32 G726ENC_HandleCommand (G726ENC_COMPONENT_PRIVATE *pComponentPrivate)
    634 {
    635     OMX_ERRORTYPE eError = OMX_ErrorNone;
    636     OMX_COMMANDTYPE command;
    637     OMX_STATETYPE commandedState = OMX_StateInvalid;
    638     OMX_HANDLETYPE pLcmlHandle;
    639     LCML_CALLBACKTYPE cb;
    640     LCML_DSP *pLcmlDsp = NULL;
    641     OMX_U32 pValues[4] = {0};
    642     OMX_U32 commandData = 0;
    643     OMX_U16 arr[100] = {0};
    644     OMX_STRING p = "damedesuStr";
    645     OMX_U32 i = 0;
    646     OMX_U32 ret = 0;
    647     OMX_U32 nTimeout = 0;
    648     G726ENC_LCML_BUFHEADERTYPE *pLcmlHdr = NULL;
    649     OMX_U8 inputPortFlag=0,outputPortFlag=0;
    650     OMX_U8* pParamsTemp = NULL;
    651 
    652 #ifdef RESOURCE_MANAGER_ENABLED
    653     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
    654 #endif
    655 
    656     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
    657     pLcmlHandle = pComponentPrivate->pLcmlHandle;
    658 
    659     ret = read(pComponentPrivate->cmdPipe[0], &command, sizeof (command));
    660     if (ret == -1) {
    661         G726ENC_DPRINT("%d :: Error in Reading from the Data pipe\n", __LINE__);
    662         eError = OMX_ErrorHardware;
    663         goto EXIT;
    664     }
    665     ret = read(pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
    666     if (ret == -1) {
    667         G726ENC_DPRINT("%d :: Error in Reading from the Data pipe\n", __LINE__);
    668         eError = OMX_ErrorHardware;
    669         goto EXIT;
    670     }
    671 
    672     if (command == OMX_CommandStateSet) {
    673         commandedState = (OMX_STATETYPE)commandData;
    674         switch(commandedState) {
    675         case OMX_StateIdle:
    676             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateIdle \n",__LINE__);
    677             G726ENC_DPRINT("%d :: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
    678             if (pComponentPrivate->curState == commandedState){
    679                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
    680                                                          pHandle->pApplicationPrivate,
    681                                                          OMX_EventError,
    682                                                          OMX_ErrorSameState,
    683                                                          0,
    684                                                          NULL);
    685                 G726ENC_DPRINT("%d :: Error: Same State Given by Application\n",__LINE__);
    686             }
    687             else if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->curState == OMX_StateWaitForResources) {
    688 
    689                         if (pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated &&  pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled){
    690                                         inputPortFlag = 1;
    691                         }
    692                         if (pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled){
    693                                         outputPortFlag = 1;
    694                         }
    695                         if(( pComponentPrivate->dasfMode && !outputPortFlag) ||
    696                            (!pComponentPrivate->dasfMode && (!inputPortFlag || !outputPortFlag)))
    697                         {
    698                               /* Sleep for a while, so the application thread can allocate buffers */
    699                               G726ENC_DPRINT("%d :: Sleeping...\n",__LINE__);
    700                               pComponentPrivate->InLoaded_readytoidle = 1;
    701 #ifndef UNDER_CE
    702                               pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
    703                               pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex);
    704                               pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
    705 #endif
    706                         }
    707 
    708                 cb.LCML_Callback = (void *) G726ENC_LCMLCallback;
    709 
    710                 pLcmlHandle = (OMX_HANDLETYPE) G726ENC_GetLCMLHandle(pComponentPrivate);
    711 
    712                 if (pLcmlHandle == NULL) {
    713                     G726ENC_DPRINT("%d :: LCML Handle is NULL........exiting..\n",__LINE__);
    714                     goto EXIT;
    715                 }
    716 
    717                 /* Got handle of dsp via phandle filling information about DSP Specific things */
    718                 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
    719                 eError = G726ENC_FillLCMLInitParams(pHandle, pLcmlDsp, arr);
    720                 if(eError != OMX_ErrorNone) {
    721                     G726ENC_DPRINT("%d :: Error from G726ENCFill_LCMLInitParams()\n",__LINE__);
    722                     goto EXIT;
    723                 }
    724 
    725                 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
    726                 cb.LCML_Callback = (void *) G726ENC_LCMLCallback;
    727 
    728 #ifndef UNDER_CE
    729 				eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
    730                                           p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
    731 
    732 #else
    733 				eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    734 						                      					    p,&pLcmlHandle, (void *)p, &cb);
    735 #endif
    736 
    737                 if(eError != OMX_ErrorNone) {
    738                     G726ENC_DPRINT("%d :: Error returned from LCML_Init()\n",__LINE__);
    739                     goto EXIT;
    740                 }
    741 
    742 #ifdef RESOURCE_MANAGER_ENABLED
    743                 /* Need check the resource with RM */
    744                 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) G726ENC_ResourceManagerCallback;
    745                 if (pComponentPrivate->curState != OMX_StateWaitForResources) {
    746                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource,
    747                                                       OMX_G726_Encoder_COMPONENT,
    748                                                       G726ENC_CPU,
    749                                                       3456,
    750                                                       &(pComponentPrivate->rmproxyCallback));
    751                 if(rm_error == OMX_ErrorNone) {
    752                     /* resource is available */
    753                     pComponentPrivate->curState = OMX_StateIdle;
    754                     rm_error = RMProxy_NewSendCommand(pHandle,
    755                                                       RMProxy_StateSet,
    756                                                       OMX_G726_Encoder_COMPONENT,
    757                                                       OMX_StateIdle, 3456,NULL);
    758                 }
    759                 else if(rm_error == OMX_ErrorInsufficientResources) {
    760                     /* resource is not available, need set state to OMX_StateWaitForResources */
    761                     pComponentPrivate->curState = OMX_StateWaitForResources;
    762                     pComponentPrivate->cbInfo.EventHandler( pHandle,
    763                                                             pHandle->pApplicationPrivate,
    764                                                             OMX_EventCmdComplete,
    765                                                             OMX_CommandStateSet,
    766                                                             pComponentPrivate->curState,
    767                                                             NULL);
    768                     G726ENC_DPRINT("%d :: Comp: OMX_ErrorInsufficientResources\n", __LINE__);
    769                 }
    770               }
    771 				else {
    772                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G726_Encoder_COMPONENT, OMX_StateIdle, 3456,NULL);
    773 
    774               }
    775                 pComponentPrivate->curState = OMX_StateIdle;
    776                 pComponentPrivate->cbInfo.EventHandler( pHandle,
    777                                                         pHandle->pApplicationPrivate,
    778                                                         OMX_EventCmdComplete,
    779                                                         OMX_CommandStateSet,
    780                                                         pComponentPrivate->curState,
    781                                                         NULL);
    782 #else
    783                 pComponentPrivate->curState = OMX_StateIdle;
    784                 pComponentPrivate->cbInfo.EventHandler( pHandle,
    785                                                         pHandle->pApplicationPrivate,
    786                                                         OMX_EventCmdComplete,
    787                                                         OMX_CommandStateSet,
    788                                                         pComponentPrivate->curState,
    789                                                         NULL);
    790 #endif
    791 
    792             }
    793             else if (pComponentPrivate->curState == OMX_StateExecuting) {
    794                 G726ENC_DPRINT("%d :: Setting Component to OMX_StateIdle\n",__LINE__);
    795 
    796 #ifdef HASHINGENABLE
    797 		/*Hashing Change*/
    798 		pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    799 		eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    800 		if (eError != OMX_ErrorNone) {
    801 			G726ENC_DPRINT("Error occurred in Codec mapping flush!\n");
    802 			break;
    803 		}
    804 #endif
    805                 G726ENC_DPRINT("%d :: G726ENC: About to Call MMCodecControlStop\n", __LINE__);
    806                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    807                                                                     MMCodecControlStop,(void *)p);
    808                 if(eError != OMX_ErrorNone) {
    809                     G726ENC_DPRINT("%d :: Error from LCML_ControlCodec MMCodecControlStop..\n",__LINE__);
    810                     goto EXIT;
    811                 }
    812 
    813                 if(pComponentPrivate->dasfMode == 1) {
    814                       pParamsTemp = (OMX_U8*)pComponentPrivate->pParams;
    815                       if (pParamsTemp != NULL)
    816                             pParamsTemp -= 128;
    817                       OMX_NBMEMFREE_STRUCT(pParamsTemp);
    818                 }
    819 
    820                 if(pComponentPrivate->ptempBuffer!=NULL){
    821                       OMX_NBMEMFREE_STRUCT(pComponentPrivate->ptempBuffer);
    822                 }
    823 
    824                 if(pComponentPrivate->pHoldBuffer!=NULL){
    825                       OMX_NBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
    826                 }
    827 
    828                 pComponentPrivate->nHoldLength = 0;
    829                 pComponentPrivate->lastOutBufArrived=NULL;
    830                 pComponentPrivate->LastBufSent = 0;
    831 
    832             }
    833             else if(pComponentPrivate->curState == OMX_StatePause) {
    834 
    835 #ifdef HASHINGENABLE
    836 		/*Hashing Change*/
    837 		pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    838 		/* clear out any mappings that might have accumulated */
    839 		eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    840 		if (eError != OMX_ErrorNone) {
    841 			G726ENC_DPRINT("Error occurred in Codec mapping flush!\n");
    842 			break;
    843 		}
    844 #endif
    845 
    846                 pComponentPrivate->curState = OMX_StateIdle;
    847 
    848 #ifdef RESOURCE_MANAGER_ENABLED
    849                 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G726_Encoder_COMPONENT, OMX_StateIdle, 3456,NULL);
    850 #endif
    851                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
    852                                                          pHandle->pApplicationPrivate,
    853                                                          OMX_EventCmdComplete,
    854                                                          OMX_CommandStateSet,
    855                                                          pComponentPrivate->curState,
    856                                                          NULL);
    857             } else {    /* This means, it is invalid state from application */
    858                 pComponentPrivate->cbInfo.EventHandler( pHandle,
    859                                                         pHandle->pApplicationPrivate,
    860                                                         OMX_EventError,
    861                                                         OMX_ErrorIncorrectStateTransition,
    862                                                         0,
    863                                                         NULL);
    864                 G726ENC_DPRINT("%d :: Comp: OMX_ErrorIncorrectStateTransition\n",__LINE__);
    865             }
    866             break;
    867 
    868         case OMX_StateExecuting:
    869             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateExecuting \n",__LINE__);
    870             if (pComponentPrivate->curState == commandedState){
    871                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
    872                                                          pHandle->pApplicationPrivate,
    873                                                          OMX_EventError,
    874                                                          OMX_ErrorSameState,
    875                                                          0,
    876                                                          NULL);
    877                 G726ENC_DPRINT("%d :: Comp: OMX_ErrorSameState Given by Comp\n",__LINE__);
    878             }
    879             else if (pComponentPrivate->curState == OMX_StateIdle)
    880                 {
    881 
    882                 if(pComponentPrivate->dasfMode == 1) {
    883                     G726ENC_DPRINT("%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
    884                   	pParamsTemp = (OMX_U8*)SafeMalloc(sizeof(G726ENC_AudioCodecParams) + 256);
    885                 	if(pParamsTemp == NULL){
    886                         G726ENC_EPRINT("***********************************\n");
    887                         G726ENC_EPRINT("%d :: Malloc Failed\n",__LINE__);
    888                         G726ENC_EPRINT("***********************************\n");
    889                         eError = OMX_ErrorInsufficientResources;
    890                         goto EXIT;
    891                     }
    892 
    893                     pComponentPrivate->pParams = (G726ENC_AudioCodecParams*)(pParamsTemp + 128);
    894                     pComponentPrivate->pParams->iAudioFormat = 1;
    895                     pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
    896                     pComponentPrivate->pParams->iSamplingRate = G726ENC_SAMPLING_FREQUENCY;
    897                     pValues[0] = USN_STRMCMD_SETCODECPARAMS;
    898                     pValues[1] = (OMX_U32)pComponentPrivate->pParams;
    899                     pValues[2] = sizeof(G726ENC_AudioCodecParams);
    900                     /* Sending STRMCTRL MESSAGE to DSP via LCML_ControlCodec*/
    901                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    902                                                               EMMCodecControlStrmCtrl,(void *)pValues);
    903                     if(eError != OMX_ErrorNone) {
    904                        G726ENC_DPRINT("%d :: Error from LCML_ControlCodec EMMCodecControlStrmCtrl = %x\n",__LINE__,eError);
    905                        goto EXIT;
    906                     }
    907                 }
    908 
    909                 /* Sending START MESSAGE to DSP via LCML_ControlCodec*/
    910                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    911                                                 EMMCodecControlStart, (void *)p);
    912                 if(eError != OMX_ErrorNone) {
    913                     G726ENC_DPRINT("%d :: Error from LCML_ControlCodec EMMCodecControlStart = %x\n",__LINE__,eError);
    914                     goto EXIT;
    915                 }
    916 
    917             } else if (pComponentPrivate->curState == OMX_StatePause) {
    918                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    919                                                 EMMCodecControlStart, (void *)p);
    920                 if (eError != OMX_ErrorNone) {
    921                     G726ENC_DPRINT("%d :: Error While Resuming the codec = %x\n",__LINE__,eError);
    922                     goto EXIT;
    923                 }
    924 
    925                 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
    926                     if (pComponentPrivate->pInputBufHdrPending[i]) {
    927                         G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
    928                         G726ENC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__);
    929 
    930                         eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    931                                                     EMMCodecInputBuffer,
    932                                                     pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
    933                                                     pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
    934                                                     pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
    935                                                     (OMX_U8 *) pLcmlHdr->pIpParam,
    936                                                     sizeof(G726ENC_ParamStruct),
    937                                                     NULL);
    938                     }
    939                 }
    940                 pComponentPrivate->nNumInputBufPending = 0;
    941 
    942 
    943                 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
    944                     if (pComponentPrivate->pOutputBufHdrPending[i]) {
    945                         G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
    946                         G726ENC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput,__LINE__);
    947                         eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    948                                                     EMMCodecOuputBuffer,
    949                                                     pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
    950                                                     pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
    951                                                     /*pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen*/0,
    952                                                     /*(OMX_U8 *) pLcmlHdr->pIpParam*/NULL,
    953                                                     /*sizeof(G726ENC_ParamStruct)*/0,
    954                                                     NULL);
    955                     }
    956                 }
    957                 pComponentPrivate->nNumOutputBufPending = 0;
    958             } else {
    959                 pComponentPrivate->cbInfo.EventHandler( pHandle,
    960                                                         pHandle->pApplicationPrivate,
    961                                                         OMX_EventError,
    962                                                         OMX_ErrorIncorrectStateTransition,
    963                                                         0,
    964                                                         NULL);
    965                 G726ENC_DPRINT("%d :: Comp: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__);
    966                 goto EXIT;
    967 
    968             }
    969             pComponentPrivate->curState = OMX_StateExecuting;
    970 #ifdef RESOURCE_MANAGER_ENABLED
    971             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G726_Encoder_COMPONENT, OMX_StateExecuting, 3456,NULL);
    972 #endif
    973             pComponentPrivate->cbInfo.EventHandler( pHandle,
    974                                                     pHandle->pApplicationPrivate,
    975                                                     OMX_EventCmdComplete,
    976                                                     OMX_CommandStateSet,
    977                                                     pComponentPrivate->curState,
    978                                                     NULL);
    979             G726ENC_DPRINT("%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__);
    980             break;
    981 
    982         case OMX_StateLoaded:
    983             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateLoaded\n",__LINE__);
    984             if (pComponentPrivate->curState == commandedState){
    985                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
    986                                                          pHandle->pApplicationPrivate,
    987                                                          OMX_EventError,
    988                                                          OMX_ErrorSameState,
    989                                                          0,
    990                                                          NULL);
    991                 G726ENC_DPRINT("%d :: Comp: OMX_ErrorSameState Given by Comp\n",__LINE__);
    992                 break;
    993              }
    994             if (pComponentPrivate->curState == OMX_StateWaitForResources){
    995                 G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateWaitForResources\n",__LINE__);
    996                 pComponentPrivate->curState = OMX_StateLoaded;
    997                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
    998                                                          pHandle->pApplicationPrivate,
    999                                                          OMX_EventCmdComplete,
   1000                                                          OMX_CommandStateSet,
   1001                                                          pComponentPrivate->curState,
   1002                                                          NULL);
   1003                 G726ENC_DPRINT("%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__);
   1004                 break;
   1005             }
   1006             if (pComponentPrivate->curState != OMX_StateIdle &&
   1007                 pComponentPrivate->curState != OMX_StateWaitForResources) {
   1008                 G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateIdle && OMX_StateWaitForResources\n",__LINE__);
   1009                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
   1010                                                          pHandle->pApplicationPrivate,
   1011                                                          OMX_EventError,
   1012                                                          OMX_ErrorIncorrectStateTransition,
   1013                                                          0,
   1014                                                          NULL);
   1015                 G726ENC_DPRINT("%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__);
   1016                 goto EXIT;
   1017             }
   1018             if (pComponentPrivate->pInputBufferList->numBuffers &&
   1019                     pComponentPrivate->pOutputBufferList->numBuffers) {
   1020                          pComponentPrivate->InIdle_goingtoloaded = 1;
   1021                          pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
   1022                          pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex);
   1023                          pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
   1024 
   1025             }
   1026 
   1027             /* Now Deinitialize the component No error should be returned from
   1028             * this function. It should clean the system as much as possible */
   1029             G726ENC_CleanupInitParams(pHandle);
   1030 
   1031             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1032                                         EMMCodecControlDestroy, (void *)p);
   1033             if (eError != OMX_ErrorNone) {
   1034                 G726ENC_DPRINT("%d :: Error: LCML_ControlCodec EMMCodecControlDestroy = %x\n",__LINE__, eError);
   1035                 goto EXIT;
   1036             }
   1037             eError = G726ENC_EXIT_COMPONENT_THRD;
   1038             pComponentPrivate->bInitParamsInitialized = 0;
   1039             break;
   1040 
   1041         case OMX_StatePause:
   1042             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StatePause\n",__LINE__);
   1043             if (pComponentPrivate->curState == commandedState){
   1044                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
   1045                                                          pHandle->pApplicationPrivate,
   1046                                                          OMX_EventError,
   1047                                                          OMX_ErrorSameState,
   1048                                                          0,
   1049                                                          NULL);
   1050                 G726ENC_DPRINT("%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__);
   1051                 break;
   1052             }
   1053             if (pComponentPrivate->curState != OMX_StateExecuting &&
   1054                 pComponentPrivate->curState != OMX_StateIdle) {
   1055                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
   1056                                                          pHandle->pApplicationPrivate,
   1057                                                          OMX_EventError,
   1058                                                          OMX_ErrorIncorrectStateTransition,
   1059                                                          0,
   1060                                                          NULL);
   1061                 G726ENC_DPRINT("%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__);
   1062                 goto EXIT;
   1063             }
   1064             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1065                                         EMMCodecControlPause, (void *)p);
   1066             if (eError != OMX_ErrorNone) {
   1067                 G726ENC_DPRINT("%d :: Error: LCML_ControlCodec EMMCodecControlPause = %x\n",__LINE__,eError);
   1068                 goto EXIT;
   1069             }
   1070             pComponentPrivate->curState = OMX_StatePause;
   1071             pComponentPrivate->cbInfo.EventHandler( pHandle,
   1072                                                     pHandle->pApplicationPrivate,
   1073                                                     OMX_EventCmdComplete,
   1074                                                     OMX_CommandStateSet,
   1075                                                     pComponentPrivate->curState,
   1076                                                     NULL);
   1077             G726ENC_DPRINT("%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__);
   1078             break;
   1079 
   1080         case OMX_StateWaitForResources:
   1081             if (pComponentPrivate->curState == commandedState) {
   1082                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
   1083                                                          pHandle->pApplicationPrivate,
   1084                                                          OMX_EventError,
   1085                                                          OMX_ErrorSameState,
   1086                                                          0,
   1087                                                          NULL);
   1088                 G726ENC_DPRINT("%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__);
   1089             } else if (pComponentPrivate->curState == OMX_StateLoaded) {
   1090                 pComponentPrivate->curState = OMX_StateWaitForResources;
   1091                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1092                                                         pHandle->pApplicationPrivate,
   1093                                                         OMX_EventCmdComplete,
   1094                                                         OMX_CommandStateSet,
   1095                                                         pComponentPrivate->curState,
   1096                                                         NULL);
   1097                 G726ENC_DPRINT("%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__);
   1098             } else {
   1099                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1100                                                         pHandle->pApplicationPrivate,
   1101                                                         OMX_EventError,
   1102                                                         OMX_ErrorIncorrectStateTransition,
   1103                                                         0,
   1104                                                         NULL);
   1105                 G726ENC_DPRINT("%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__);
   1106             }
   1107             break;
   1108 
   1109         case OMX_StateInvalid:
   1110             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: OMX_StateInvalid\n",__LINE__);
   1111             if (pComponentPrivate->curState == commandedState){
   1112                 pComponentPrivate->cbInfo.EventHandler ( pHandle,
   1113                                                          pHandle->pApplicationPrivate,
   1114                                                          OMX_EventError,
   1115                                                          OMX_ErrorSameState,
   1116                                                          0,
   1117                                                          NULL);
   1118                 G726ENC_DPRINT("%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__);
   1119             } else{
   1120                 pComponentPrivate->curState = OMX_StateInvalid;
   1121                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1122                                                         pHandle->pApplicationPrivate,
   1123                                                         OMX_EventError,
   1124                                                         OMX_ErrorInvalidState,
   1125                                                         0,
   1126                                                         NULL);
   1127                 G726ENC_DPRINT("%d :: Comp: OMX_ErrorInvalidState Given by Comp\n",__LINE__);
   1128             }
   1129             break;
   1130 
   1131         case OMX_StateMax:
   1132             G726ENC_DPRINT("%d :: G726ENC_HandleCommand :: Cmd OMX_StateMax\n",__LINE__);
   1133             break;
   1134         } /* End of Switch */
   1135         } else if (command == OMX_CommandMarkBuffer) {
   1136         G726ENC_DPRINT("%d :: command OMX_CommandMarkBuffer received\n",__LINE__);
   1137         if(!pComponentPrivate->pMarkBuf){
   1138             /* TODO Need to handle multiple marks */
   1139             pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
   1140         }
   1141     } else if (command == OMX_CommandPortDisable)
   1142         {
   1143         if (!pComponentPrivate->bDisableCommandPending) {
   1144             if(commandData == 0x0 || commandData == -1){
   1145                 /* disable port */
   1146                 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled = OMX_FALSE;
   1147                 G726ENC_DPRINT("%d :: command disabled input port\n",__LINE__);
   1148             }
   1149             if(commandData == 0x1 || commandData == -1){
   1150                  /* disable output port */
   1151                 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled = OMX_FALSE;
   1152                 G726ENC_DPRINT("%d :: command disabled output port\n",__LINE__);
   1153                 if (pComponentPrivate->curState == OMX_StateExecuting) {
   1154                     pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
   1155                     eError = LCML_ControlCodec(
   1156                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1157                                       MMCodecControlStop,(void *)p);
   1158                 }
   1159             }
   1160         }
   1161         G726ENC_DPRINT("commandData = %ld\n",commandData);
   1162         G726ENC_DPRINT("pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = %d\n",pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated);
   1163         G726ENC_DPRINT("pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated = %d\n",pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated);
   1164         if(commandData == 0x0) {
   1165             if(!pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated){
   1166                 /* return cmdcomplete event if input unpopulated */
   1167                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1168                                                         pHandle->pApplicationPrivate,
   1169                                                         OMX_EventCmdComplete,
   1170                                                         OMX_CommandPortDisable,
   1171                                                         G726ENC_INPUT_PORT,
   1172                                                         NULL);
   1173                 pComponentPrivate->bDisableCommandPending = 0;
   1174             } else {
   1175                 pComponentPrivate->bDisableCommandPending = 1;
   1176                 pComponentPrivate->bDisableCommandParam = commandData;
   1177             }
   1178         }
   1179         if(commandData == 0x1) {
   1180             if (!pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated){
   1181                  /* return cmdcomplete event if output unpopulated */
   1182                  pComponentPrivate->cbInfo.EventHandler( pHandle,
   1183                                                          pHandle->pApplicationPrivate,
   1184                                                          OMX_EventCmdComplete,
   1185                                                          OMX_CommandPortDisable,
   1186                                                          G726ENC_OUTPUT_PORT,
   1187                                                          NULL);
   1188                  pComponentPrivate->bDisableCommandPending = 0;
   1189             } else {
   1190                 pComponentPrivate->bDisableCommandPending = 1;
   1191                 pComponentPrivate->bDisableCommandParam = commandData;
   1192             }
   1193         }
   1194         if(commandData == -1) {
   1195             if (!pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated &&
   1196                 !pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated){
   1197                  /* return cmdcomplete event if inout & output unpopulated */
   1198                  pComponentPrivate->cbInfo.EventHandler( pHandle,
   1199                                                          pHandle->pApplicationPrivate,
   1200                                                          OMX_EventCmdComplete,
   1201                                                          OMX_CommandPortDisable,
   1202                                                          G726ENC_INPUT_PORT,
   1203                                                          NULL);
   1204                  pComponentPrivate->cbInfo.EventHandler( pHandle,
   1205                                                          pHandle->pApplicationPrivate,
   1206                                                          OMX_EventCmdComplete,
   1207                                                          OMX_CommandPortDisable,
   1208                                                          G726ENC_OUTPUT_PORT,
   1209                                                          NULL);
   1210                  pComponentPrivate->bDisableCommandPending = 0;
   1211             } else {
   1212                 pComponentPrivate->bDisableCommandPending = 1;
   1213                 pComponentPrivate->bDisableCommandParam = commandData;
   1214             }
   1215             sched_yield();
   1216         }
   1217     } else if (command == OMX_CommandPortEnable) {
   1218         if(commandData == 0x0 || commandData == -1){
   1219             /* enable in port */
   1220             G726ENC_DPRINT("%d :: setting input port to enabled\n",__LINE__);
   1221             pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled = OMX_TRUE;
   1222             if(pComponentPrivate->AlloBuf_waitingsignal)
   1223             {
   1224                  pComponentPrivate->AlloBuf_waitingsignal = 0;
   1225 #ifndef UNDER_CE
   1226                  pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1227                  pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1228                  pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1229 #endif
   1230             }
   1231             G726ENC_DPRINT("pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled);
   1232         }
   1233         if(commandData == 0x1 || commandData == -1){
   1234             /* enable out port */
   1235             if(pComponentPrivate->AlloBuf_waitingsignal)
   1236             {
   1237                  pComponentPrivate->AlloBuf_waitingsignal = 0;
   1238 #ifndef UNDER_CE
   1239                  pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1240                  pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1241                  pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1242 #endif
   1243             }
   1244             if (pComponentPrivate->curState == OMX_StateExecuting) {
   1245                 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
   1246                 eError = LCML_ControlCodec(
   1247                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1248                                       EMMCodecControlStart,(void *)p);
   1249             }
   1250             G726ENC_DPRINT("%d :: setting output port to enabled\n",__LINE__);
   1251             pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled = OMX_TRUE;
   1252             G726ENC_DPRINT("pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled);
   1253         }
   1254 
   1255         while (1) {
   1256             G726ENC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   1257             G726ENC_DPRINT("pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated = %d\n",pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated);
   1258             if(commandData == 0x0 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1259                 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated)){
   1260                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1261                                                         pHandle->pApplicationPrivate,
   1262                                                         OMX_EventCmdComplete,
   1263                                                         OMX_CommandPortEnable,
   1264                                                         G726ENC_INPUT_PORT,
   1265                                                         NULL);
   1266                 G726ENC_DPRINT("%d :: setting Input port to enabled\n",__LINE__);
   1267                 break;
   1268             } else if(commandData == 0x1 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1269               pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated)){
   1270                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1271                                                         pHandle->pApplicationPrivate,
   1272                                                         OMX_EventCmdComplete,
   1273                                                         OMX_CommandPortEnable,
   1274                                                         G726ENC_OUTPUT_PORT,
   1275                                                         NULL);
   1276                 G726ENC_DPRINT("%d :: setting output port to enabled\n",__LINE__);
   1277                 break;
   1278             } else if(commandData == -1 && (pComponentPrivate->curState == OMX_StateLoaded ||
   1279               (pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated
   1280               && pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated))){
   1281                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1282                                                         pHandle->pApplicationPrivate,
   1283                                                         OMX_EventCmdComplete,
   1284                                                         OMX_CommandPortEnable,
   1285                                                         G726ENC_INPUT_PORT,
   1286                                                         NULL);
   1287                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1288                                                         pHandle->pApplicationPrivate,
   1289                                                         OMX_EventCmdComplete,
   1290                                                         OMX_CommandPortEnable,
   1291                                                         G726ENC_OUTPUT_PORT,
   1292                                                         NULL);
   1293                 G726ENC_FillLCMLInitParamsEx(pComponentPrivate->pHandle);
   1294                 G726ENC_DPRINT("%d :: setting Input & Output port to enabled\n",__LINE__);
   1295                 break;
   1296             }
   1297             if(nTimeout++ > G726ENC_OMX_MAX_TIMEOUTS){
   1298                 /* return error as we have waited long enough */
   1299                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1300                                                         pHandle->pApplicationPrivate,
   1301                                                         OMX_EventError,
   1302                                                         OMX_ErrorPortUnresponsiveDuringAllocation,
   1303                                                         0 ,
   1304                                                         NULL);
   1305                 break;
   1306             }
   1307             sched_yield();
   1308         }
   1309     } else if (command == OMX_CommandFlush) {
   1310 		OMX_U32 aParam[3] = {0};
   1311         if(commandData == 0x0 || commandData == -1) {
   1312 		    aParam[0] = USN_STRMCMD_FLUSH;
   1313 		    aParam[1] = 0x0;
   1314 		    aParam[2] = 0x0;
   1315 
   1316 		    G726ENC_DPRINT("Flushing input port\n");
   1317 		    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1318                                         EMMCodecControlStrmCtrl, (void*)aParam);
   1319             if (eError != OMX_ErrorNone) {
   1320                  goto EXIT;
   1321             }
   1322         }
   1323 		if(commandData == 0x1 || commandData == -1){
   1324 
   1325             aParam[0] = USN_STRMCMD_FLUSH;
   1326             aParam[1] = 0x1;
   1327             aParam[2] = 0x0;
   1328 
   1329             G726ENC_DPRINT("Flushing output port\n");
   1330             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1331 										EMMCodecControlStrmCtrl, (void*)aParam);
   1332             if (eError != OMX_ErrorNone) {
   1333                  goto EXIT;
   1334             }
   1335 
   1336 		}
   1337     }
   1338 
   1339 EXIT:
   1340     G726ENC_DPRINT("%d :: Exiting G726ENC_HandleCommand Function\n",__LINE__);
   1341     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   1342     return eError;
   1343 }
   1344 
   1345 /* ========================================================================== */
   1346 /**
   1347 * @G726ENC_HandleDataBufFromApp() This function is called by the component when ever it
   1348 * receives the buffer from the application
   1349 *
   1350 * @param pComponentPrivate  Component private data
   1351 * @param pBufHeader Buffer from the application
   1352 *
   1353 * @pre
   1354 *
   1355 * @post
   1356 *
   1357 * @return none
   1358 */
   1359 /* ========================================================================== */
   1360 OMX_ERRORTYPE G726ENC_HandleDataBufFromApp(OMX_BUFFERHEADERTYPE* pBufHeader,
   1361                                     G726ENC_COMPONENT_PRIVATE *pComponentPrivate)
   1362 {
   1363     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1364     OMX_DIRTYPE eDir;
   1365     G726ENC_LCML_BUFHEADERTYPE *pLcmlHdr=NULL;
   1366     LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *) pComponentPrivate->pLcmlHandle;
   1367 
   1368     G726ENC_DPRINT ("%d :: Entering G726ENC_HandleDataBufFromApp Function\n",__LINE__);
   1369     /*Find the direction of the received buffer from buffer list */
   1370     eError = G726ENC_GetBufferDirection(pBufHeader, &eDir);
   1371     if (eError != OMX_ErrorNone) {
   1372         G726ENC_DPRINT ("%d :: The pBufHeader is not found in the list\n", __LINE__);
   1373         goto EXIT;
   1374     }
   1375 
   1376     if (eDir == OMX_DirInput) {
   1377         if(pComponentPrivate->dasfMode == 0) {
   1378             if ((pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags == OMX_BUFFERFLAG_EOS)) {
   1379 
   1380                 eError = G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr);
   1381                 if (eError != OMX_ErrorNone) {
   1382                     G726ENC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__);
   1383                     goto EXIT;
   1384                 }
   1385 
   1386                 if(pBufHeader->nFlags == OMX_BUFFERFLAG_EOS) {
   1387                     pComponentPrivate->LastBufSent = 1;
   1388                     pLcmlHdr->pIpParam->bLastBuffer = 1;
   1389                 }
   1390                 else {
   1391                     pLcmlHdr->pIpParam->bLastBuffer = 0;
   1392                 }
   1393 
   1394                 /* Store time stamp information */
   1395                 pComponentPrivate->arrTimestamp[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
   1396                 /* Store nTickCount information */
   1397                 pComponentPrivate->arrTickCount[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
   1398                 pComponentPrivate->IpBufindex++;
   1399                 pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nBufferCountActual;
   1400 
   1401                 if (pComponentPrivate->curState == OMX_StateExecuting) {
   1402                     if(!pComponentPrivate->bDspStoppedWhileExecuting) {
   1403                         if (!G726ENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) {
   1404                             G726ENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
   1405 
   1406 
   1407                             eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle,
   1408                                                        EMMCodecInputBuffer,
   1409                                                        (OMX_U8 *)pBufHeader->pBuffer,
   1410                                                        pBufHeader->nAllocLen,
   1411                                                        pBufHeader->nFilledLen,
   1412                                                        (OMX_U8 *) pLcmlHdr->pIpParam,
   1413                                                        sizeof(G726ENC_ParamStruct),
   1414                                                        NULL);
   1415                             if (eError != OMX_ErrorNone) {
   1416                             G726ENC_DPRINT("OMX_ErrorHardware Occurred!!!!!!!!\n");
   1417                                 eError = OMX_ErrorHardware;
   1418                                 goto EXIT;
   1419                             }
   1420 
   1421                         }
   1422                     } else{
   1423                         pComponentPrivate->cbInfo.EmptyBufferDone (
   1424                                            pComponentPrivate->pHandle,
   1425                                            pComponentPrivate->pHandle->pApplicationPrivate,
   1426                                            pBufHeader
   1427                                            );
   1428                     }
   1429 
   1430                 } else {
   1431                     pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
   1432                 }
   1433             } else {
   1434 
   1435                 G726ENC_DPRINT("%d :: Calling EmptyBufferDone\n",__LINE__);
   1436                 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
   1437                                                            pComponentPrivate->pHandle->pApplicationPrivate,
   1438                                                            pComponentPrivate->pInputBufferList->pBufHdr[0]);
   1439                 pComponentPrivate->nEmptyBufferDoneCount++;
   1440             }
   1441             if(pBufHeader->nFlags == OMX_BUFFERFLAG_EOS) {
   1442               pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
   1443             }
   1444             if(pBufHeader->pMarkData){
   1445                 /* copy mark to output buffer header */
   1446                 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
   1447                 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
   1448                 /* trigger event handler if we are supposed to */
   1449                 if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){
   1450                     pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
   1451                                                             pComponentPrivate->pHandle->pApplicationPrivate,
   1452                                                             OMX_EventMark,
   1453                                                             0,
   1454                                                             0,
   1455                                                             pBufHeader->pMarkData);
   1456                 }
   1457             }
   1458         }
   1459     } else if (eDir == OMX_DirOutput) {
   1460         /* Make sure that output buffer is issued to output stream only when
   1461          * there is an outstanding input buffer already issued on input stream
   1462          */
   1463 
   1464         eError = G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
   1465         if (eError != OMX_ErrorNone) {
   1466                     G726ENC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__);
   1467                     goto EXIT;
   1468         }
   1469 /*        pLcmlHdr->pOpParam->usNbFrames =1;*/   /*<<<<<<<<<<---------------- according SN guide this is not needed!!!!!!*/
   1470                                              /*            The SN should be the one that set this Information            */
   1471                                              /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
   1472 
   1473         if (!(pComponentPrivate->bIsStopping)) {
   1474                 G726ENC_DPRINT ("%d: Sending Empty OUTPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer);
   1475 
   1476                 if (pComponentPrivate->curState == OMX_StateExecuting) {
   1477                     if (!G726ENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) {
   1478                         G726ENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
   1479 
   1480                         eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle,
   1481                                                    EMMCodecOuputBuffer,
   1482                                                    (OMX_U8 *)pBufHeader->pBuffer,
   1483                                                    pBufHeader->nAllocLen,
   1484                                                    pBufHeader->nFilledLen,
   1485                                                    NULL,
   1486                                                    0,
   1487                                                    NULL);
   1488                         if (eError != OMX_ErrorNone ) {
   1489                             G726ENC_DPRINT ("%d :: IssuingDSP OP: Error Occurred\n",__LINE__);
   1490                             eError = OMX_ErrorHardware;
   1491                             goto EXIT;
   1492                         }
   1493                     }
   1494                 } else if (pComponentPrivate->curState == OMX_StatePause) {
   1495                     pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
   1496                 }
   1497 
   1498         } else {
   1499             if (pComponentPrivate->curState == OMX_StateExecuting) {
   1500                 if (!G726ENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) {
   1501                     G726ENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
   1502 
   1503                     eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle,
   1504                                                EMMCodecOuputBuffer,
   1505                                                (OMX_U8 *)pBufHeader->pBuffer,
   1506                                                pBufHeader->nAllocLen,
   1507                                                pBufHeader->nFilledLen,
   1508                                                NULL,
   1509                                                0,
   1510                                                NULL);
   1511                     if (eError != OMX_ErrorNone ) {
   1512                         G726ENC_DPRINT ("%d :: IssuingDSP OP: Error Occurred\n",__LINE__);
   1513                           eError = OMX_ErrorHardware;
   1514                           goto EXIT;
   1515                     }
   1516 
   1517 
   1518                 }
   1519             } else if (pComponentPrivate->curState == OMX_StatePause) {
   1520                 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
   1521             }
   1522         }
   1523     } else {
   1524         eError = OMX_ErrorBadParameter;
   1525     }
   1526 
   1527 EXIT:
   1528     G726ENC_DPRINT("%d :: Exiting from  G726ENC_HandleDataBufFromApp \n",__LINE__);
   1529     G726ENC_DPRINT("%d :: Returning error %d\n",__LINE__,eError);
   1530     return eError;
   1531 }
   1532 
   1533 /*-------------------------------------------------------------------*/
   1534 /**
   1535 * G726ENC_GetBufferDirection () This function is used by the component
   1536 * to get the direction of the buffer
   1537 * @param eDir pointer will be updated with buffer direction
   1538 * @param pBufHeader pointer to the buffer to be requested to be filled
   1539 *
   1540 * @retval none
   1541 **/
   1542 /*-------------------------------------------------------------------*/
   1543 
   1544 OMX_ERRORTYPE G726ENC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader,
   1545                                                          OMX_DIRTYPE *eDir)
   1546 {
   1547     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1548     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
   1549     OMX_U32 nBuf = 0;
   1550     OMX_BUFFERHEADERTYPE *pBuf = NULL;
   1551     OMX_U32 flag = 1,i = 0;
   1552     G726ENC_DPRINT("%d :: Entering G726ENC_GetBufferDirection Function\n",__LINE__);
   1553     /*Search this buffer in input buffers list */
   1554     nBuf = pComponentPrivate->pInputBufferList->numBuffers;
   1555     for(i=0; i<nBuf; i++) {
   1556         pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
   1557         if(pBufHeader == pBuf) {
   1558             *eDir = OMX_DirInput;
   1559             G726ENC_DPRINT("%d :: pBufHeader = %p is INPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
   1560             flag = 0;
   1561             goto EXIT;
   1562         }
   1563     }
   1564     /*Search this buffer in output buffers list */
   1565     nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   1566     for(i=0; i<nBuf; i++) {
   1567         pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   1568         if(pBufHeader == pBuf) {
   1569             *eDir = OMX_DirOutput;
   1570             G726ENC_DPRINT("%d :: pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
   1571             flag = 0;
   1572             goto EXIT;
   1573         }
   1574     }
   1575 
   1576     if (flag == 1) {
   1577         G726ENC_DPRINT("%d :: Buffer %p is Not Found in the List\n",__LINE__, pBufHeader);
   1578         eError = OMX_ErrorUndefined;
   1579         goto EXIT;
   1580     }
   1581 EXIT:
   1582     G726ENC_DPRINT("%d :: Exiting G726ENC_GetBufferDirection Function\n",__LINE__);
   1583     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   1584     return eError;
   1585 }
   1586 
   1587 /* -------------------------------------------------------------------*/
   1588 /**
   1589   * G726ENC_GetCorrespondingLCMLHeader() function will be called by LCML_Callback
   1590   * component to write the msg
   1591   * @param *pBuffer,          Event which gives to details about USN status
   1592   * @param G726ENC_LCML_BUFHEADERTYPE **ppLcmlHdr
   1593   * @param  OMX_DIRTYPE eDir this gives direction of the buffer
   1594   * @retval OMX_NoError              Success, ready to roll
   1595   *         OMX_Error_BadParameter   The input parameter pointer is null
   1596  **/
   1597 /* -------------------------------------------------------------------*/
   1598 OMX_ERRORTYPE G726ENC_GetCorrespondingLCMLHeader(G726ENC_COMPONENT_PRIVATE *pComponentPrivate,
   1599                                                   OMX_U8 *pBuffer,
   1600                                                   OMX_DIRTYPE eDir,
   1601                                                   G726ENC_LCML_BUFHEADERTYPE **ppLcmlHdr)
   1602 {
   1603     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1604     G726ENC_LCML_BUFHEADERTYPE *pLcmlBufHeader = NULL;
   1605     OMX_U32 i = 0,nIpBuf = 0,nOpBuf = 0;
   1606     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
   1607     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   1608     G726ENC_DPRINT("%d :: Entering G726ENC_GetCorrespondingLCMLHeader..\n",__LINE__);
   1609     while (!pComponentPrivate->bInitParamsInitialized) {
   1610         G726ENC_DPRINT("%d :: Waiting for init to complete........\n",__LINE__);
   1611 
   1612         sched_yield();
   1613 
   1614     }
   1615     if(eDir == OMX_DirInput) {
   1616         G726ENC_DPRINT("%d :: Entering G726ENC_GetCorrespondingLCMLHeader..\n",__LINE__);
   1617         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G726ENC_INPUT_PORT];
   1618         for(i = 0; i < nIpBuf; i++) {
   1619             G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer);
   1620             G726ENC_DPRINT("%d :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer);
   1621             if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
   1622                 *ppLcmlHdr = pLcmlBufHeader;
   1623                  G726ENC_DPRINT("%d :: Corresponding Input LCML Header Found = %p\n",__LINE__,pLcmlBufHeader);
   1624                  eError = OMX_ErrorNone;
   1625                  goto EXIT;
   1626             }
   1627             pLcmlBufHeader++;
   1628         }
   1629     } else if (eDir == OMX_DirOutput) {
   1630         G726ENC_DPRINT("%d :: Entering G726ENC_GetCorrespondingLCMLHeader..\n",__LINE__);
   1631         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT];
   1632         for(i = 0; i < nOpBuf; i++) {
   1633             G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer);
   1634             G726ENC_DPRINT("%d :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer);
   1635             if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
   1636                 *ppLcmlHdr = pLcmlBufHeader;
   1637                  G726ENC_DPRINT("%d :: Corresponding Output LCML Header Found = %p\n",__LINE__,pLcmlBufHeader);
   1638                  eError = OMX_ErrorNone;
   1639                  goto EXIT;
   1640             }
   1641             pLcmlBufHeader++;
   1642         }
   1643     } else {
   1644       G726ENC_DPRINT("%d :: Invalid Buffer Type :: exiting...\n",__LINE__);
   1645       eError = OMX_ErrorUndefined;
   1646     }
   1647 
   1648 EXIT:
   1649     G726ENC_DPRINT("%d :: Exiting G726ENC_GetCorrespondingLCMLHeader..\n",__LINE__);
   1650     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   1651     return eError;
   1652 }
   1653 
   1654 /* -------------------------------------------------------------------*/
   1655 /**
   1656   *  G726ENC_LCMLCallback() will be called LCML component to write the msg
   1657   *
   1658   * @param event                 Event which gives to details about USN status
   1659   * @param void * args        //    args [0] //bufType;
   1660                               //    args [1] //arm address fpr buffer
   1661                               //    args [2] //BufferSize;
   1662                               //    args [3]  //arm address for param
   1663                               //    args [4] //ParamSize;
   1664                               //    args [6] //LCML Handle
   1665   * @retval OMX_NoError              Success, ready to roll
   1666   *         OMX_Error_BadParameter   The input parameter pointer is null
   1667  **/
   1668 /*-------------------------------------------------------------------*/
   1669 
   1670 OMX_ERRORTYPE G726ENC_LCMLCallback (TUsnCodecEvent event,void * args[10])
   1671 {
   1672     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1673     OMX_U8 *pBuffer = args[1];
   1674     G726ENC_LCML_BUFHEADERTYPE *pLcmlHdr = NULL;
   1675     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
   1676     OMX_U16 i=0;
   1677     OMX_COMPONENTTYPE* pHandle = NULL;
   1678 #ifdef RESOURCE_MANAGER_ENABLED
   1679     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
   1680 #endif
   1681 
   1682     G726ENC_DPRINT("%d :: Entering the G726ENC_LCMLCallback Function\n",__LINE__);
   1683     pComponentPrivate = (G726ENC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate;
   1684 
   1685     pHandle = pComponentPrivate->pHandle;
   1686 
   1687 #ifdef G726ENC_DEBUG
   1688     switch(event) {
   1689 
   1690         case EMMCodecDspError:
   1691             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecDspError\n");
   1692             break;
   1693 
   1694         case EMMCodecInternalError:
   1695             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecInternalError\n");
   1696             break;
   1697 
   1698         case EMMCodecInitError:
   1699             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecInitError\n");
   1700             break;
   1701 
   1702         case EMMCodecDspMessageRecieved:
   1703             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved\n");
   1704             break;
   1705 
   1706         case EMMCodecBufferProcessed:
   1707             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecBufferProcessed\n");
   1708             break;
   1709 
   1710         case EMMCodecProcessingStarted:
   1711             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingStarted\n");
   1712             break;
   1713 
   1714         case EMMCodecProcessingPaused:
   1715             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingPaused\n");
   1716             break;
   1717 
   1718         case EMMCodecProcessingStoped:
   1719             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingStoped\n");
   1720             break;
   1721 
   1722         case EMMCodecProcessingEof:
   1723             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecProcessingEof\n");
   1724             break;
   1725 
   1726         case EMMCodecBufferNotProcessed:
   1727             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed\n");
   1728             break;
   1729 
   1730         case EMMCodecAlgCtrlAck:
   1731             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck\n");
   1732             break;
   1733 
   1734         case EMMCodecStrmCtrlAck:
   1735             G726ENC_DPRINT("[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck\n");
   1736             break;
   1737     }
   1738 #endif
   1739 
   1740     if(event == EMMCodecBufferProcessed)
   1741     {
   1742         if((OMX_U32)args[0] == EMMCodecInputBuffer) {
   1743             G726ENC_DPRINT("%d :: INPUT: pBuffer = %p\n",__LINE__, pBuffer);
   1744 
   1745             eError = G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBuffer, OMX_DirInput, &pLcmlHdr);
   1746             if (eError != OMX_ErrorNone) {
   1747                 G726ENC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__);
   1748                 goto EXIT;
   1749             }
   1750             G726ENC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirInput,__LINE__);
   1751             if(pComponentPrivate->dasfMode == 0) {
   1752                 G726ENC_DPRINT("%d: Component Sending Empty Input buffer%p to App\n",__LINE__,pLcmlHdr->buffer->pBuffer);
   1753                 pComponentPrivate->cbInfo.EmptyBufferDone (
   1754                                        pHandle,
   1755                                        pHandle->pApplicationPrivate,
   1756                                        pLcmlHdr->buffer
   1757                                        );
   1758 
   1759                 pComponentPrivate->nEmptyBufferDoneCount++;
   1760             }
   1761         } else if((OMX_U32)args[0] == EMMCodecOuputBuffer) {
   1762             G726ENC_DPRINT("%d :: OUTPUT: pBuffer = %p\n",__LINE__, pBuffer);
   1763             pComponentPrivate->nOutStandingFillDones++;
   1764             eError = G726ENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBuffer, OMX_DirOutput, &pLcmlHdr);
   1765             if (eError != OMX_ErrorNone) {
   1766                 G726ENC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__);
   1767                 goto EXIT;
   1768             }
   1769             G726ENC_DPRINT("%d :: Output: pLcmlHdr->buffer->pBuffer = %p\n",__LINE__, pLcmlHdr->buffer->pBuffer);
   1770             pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
   1771 
   1772             G726ENC_DPRINT("%d :: Output: pBuffer = %ld\n",__LINE__, pLcmlHdr->buffer->nFilledLen);
   1773             pComponentPrivate->lastOutBufArrived = pLcmlHdr->buffer;
   1774             G726ENC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirOutput,__LINE__);
   1775             /* Copying time stamp information to output buffer */
   1776             pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrTimestamp[pComponentPrivate->OpBufindex];
   1777             /* Copying nTickCount information to output buffer */
   1778             pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
   1779 
   1780             pComponentPrivate->OpBufindex++;
   1781             pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nBufferCountActual;
   1782 
   1783             pComponentPrivate->cbInfo.FillBufferDone( pHandle,
   1784                                                   pHandle->pApplicationPrivate,
   1785                                                   pLcmlHdr->buffer);
   1786 
   1787             pComponentPrivate->nFillBufferDoneCount++;
   1788 
   1789             pComponentPrivate->nOutStandingFillDones--;
   1790         }
   1791     }
   1792     else if (event == EMMCodecStrmCtrlAck) {
   1793         G726ENC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL \n",__LINE__);
   1794 		if (args[1] == (void *)USN_STRMCMD_FLUSH) {
   1795                  if ( args[2] == (void *)EMMCodecInputBuffer) {
   1796                      if (args[0] == (void *)USN_ERR_NONE ) {
   1797                          G726ENC_DPRINT("Flushing input port %d\n",__LINE__);
   1798 
   1799                          for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
   1800                               G726ENC_DPRINT("%d :: Calling EmptyBufferDone\n", __LINE__);
   1801                               pComponentPrivate->cbInfo.EmptyBufferDone (
   1802                                        pComponentPrivate->pHandle,
   1803                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1804                                        pComponentPrivate->pInputBufHdrPending[i]);
   1805                               pComponentPrivate->pInputBufHdrPending[i] = NULL;
   1806                               pComponentPrivate->nEmptyBufferDoneCount++;
   1807                               G726ENC_DPRINT("%d :: Incrementing nEmptyBufferDoneCount = %ld\n",__LINE__,pComponentPrivate->nEmptyBufferDoneCount);
   1808                          }
   1809 			             pComponentPrivate->nNumInputBufPending=0;
   1810                          /* return all input buffers */
   1811                          pComponentPrivate->cbInfo.EventHandler( pHandle,
   1812                                                     pHandle->pApplicationPrivate,
   1813                                                     OMX_EventCmdComplete,
   1814                                                     OMX_CommandFlush,
   1815                                                     G726ENC_INPUT_PORT,
   1816                                                     NULL);
   1817                      } else {
   1818                          G726ENC_DPRINT ("LCML reported error while flushing input port\n");
   1819                          goto EXIT;
   1820                      }
   1821                  }
   1822                  else if ( args[2] == (void *)EMMCodecOuputBuffer) {
   1823                      if (args[0] == (void *)USN_ERR_NONE ) {
   1824                          G726ENC_DPRINT("Flushing output port %d\n",__LINE__);
   1825 
   1826                         for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
   1827                              G726ENC_DPRINT("%d :: Calling FillBufferDone\n", __LINE__);
   1828                              pComponentPrivate->cbInfo.FillBufferDone (
   1829                                        pComponentPrivate->pHandle,
   1830                                        pComponentPrivate->pHandle->pApplicationPrivate,
   1831                                        pComponentPrivate->pOutputBufHdrPending[i]);
   1832                              pComponentPrivate->pOutputBufHdrPending[i] = NULL;
   1833                              pComponentPrivate->nFillBufferDoneCount++;
   1834                              G726ENC_DPRINT("%d :: Incrementing nFillBufferDoneCount = %ld\n",__LINE__,pComponentPrivate->nFillBufferDoneCount);
   1835                         }
   1836                         pComponentPrivate->nNumOutputBufPending=0;
   1837                         /* return all output buffers */
   1838                         pComponentPrivate->cbInfo.EventHandler( pHandle,
   1839                                                     pHandle->pApplicationPrivate,
   1840                                                     OMX_EventCmdComplete,
   1841                                                     OMX_CommandFlush,
   1842                                                     G726ENC_OUTPUT_PORT,
   1843                                                     NULL);
   1844                      } else {
   1845                          G726ENC_DPRINT ("LCML reported error while flushing output port\n");
   1846                          goto EXIT;
   1847                      }
   1848                  }
   1849             }
   1850     }
   1851     else if(event == EMMCodecProcessingStoped) {
   1852 
   1853         G726ENC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STOP \n",__LINE__);
   1854         if (!pComponentPrivate->bNoIdleOnStop) {
   1855             pComponentPrivate->curState = OMX_StateIdle;
   1856 #ifdef RESOURCE_MANAGER_ENABLED
   1857             rm_error = RMProxy_NewSendCommand(pHandle,
   1858                                               RMProxy_StateSet,
   1859                                               OMX_G726_Encoder_COMPONENT,
   1860                                               OMX_StateIdle, 3456,NULL);
   1861 #endif
   1862             if (pComponentPrivate->bPreempted == 0) {
   1863                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1864                                                 pComponentPrivate->pHandle->pApplicationPrivate,
   1865                                                 OMX_EventCmdComplete,
   1866                                                 OMX_CommandStateSet,
   1867                                                 pComponentPrivate->curState,
   1868                                                 NULL);
   1869             } else {
   1870                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   1871 												pComponentPrivate->pHandle->pApplicationPrivate,
   1872 												OMX_EventError,
   1873 												OMX_ErrorResourcesPreempted,
   1874 												0,
   1875 												NULL);
   1876             }
   1877         }
   1878         else {
   1879             pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
   1880             pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
   1881         }
   1882     }
   1883     else if(event == EMMCodecDspMessageRecieved) {
   1884         G726ENC_DPRINT("%d :: commandedState  = %ld\n",__LINE__,(OMX_U32)args[0]);
   1885         G726ENC_DPRINT("%d :: arg1 = %ld\n",__LINE__,(OMX_U32)args[1]);
   1886         G726ENC_DPRINT("%d :: arg2 = %ld\n",__LINE__,(OMX_U32)args[2]);
   1887 
   1888         if(0x0500 == (OMX_U32)args[2]) {
   1889             G726ENC_DPRINT("%d :: EMMCodecDspMessageRecieved\n",__LINE__);
   1890         }
   1891     }
   1892     else if(event == EMMCodecAlgCtrlAck) {
   1893         G726ENC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_ALGCTRL \n",__LINE__);
   1894     }
   1895     else if (event == EMMCodecDspError) {
   1896         if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
   1897             G726ENC_DPRINT("%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
   1898             if(pComponentPrivate->lastOutBufArrived!=NULL && !pComponentPrivate->dasfMode){
   1899                      pComponentPrivate->lastOutBufArrived->nFlags = OMX_BUFFERFLAG_EOS;
   1900                      pComponentPrivate->LastBufSent=0;
   1901                      /*TODO: add eventhandler to report eos to application*/
   1902             }
   1903         }
   1904     }
   1905 EXIT:
   1906     G726ENC_DPRINT("%d :: Exiting the G726ENC_LCMLCallback Function\n",__LINE__);
   1907     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   1908     return eError;
   1909 }
   1910 
   1911 /* ================================================================================= */
   1912 /**
   1913   *  G726ENC_GetLCMLHandle()
   1914   *
   1915   * @retval OMX_HANDLETYPE
   1916   */
   1917 /* ================================================================================= */
   1918 #ifndef UNDER_CE
   1919 OMX_HANDLETYPE G726ENC_GetLCMLHandle(G726ENC_COMPONENT_PRIVATE *pComponentPrivate)
   1920 {
   1921     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1922     OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
   1923     OMX_HANDLETYPE pHandle = NULL;
   1924     void *handle = NULL;
   1925     char *error = NULL;
   1926     G726ENC_DPRINT("%d :: Entering G726ENC_GetLCMLHandle..\n",__LINE__);
   1927     handle = dlopen("libLCML.so", RTLD_LAZY);
   1928     if (!handle) {
   1929         fputs(dlerror(), stderr);
   1930         goto EXIT;
   1931     }
   1932     fpGetHandle = dlsym (handle, "GetHandle");
   1933     if ((error = dlerror()) != NULL) {
   1934         fputs(error, stderr);
   1935         goto EXIT;
   1936     }
   1937     eError = (*fpGetHandle)(&pHandle);
   1938     if(eError != OMX_ErrorNone) {
   1939         eError = OMX_ErrorUndefined;
   1940         G726ENC_DPRINT("%d :: OMX_ErrorUndefined...\n",__LINE__);
   1941         pHandle = NULL;
   1942         goto EXIT;
   1943     }
   1944 
   1945     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
   1946 
   1947     pComponentPrivate->ptrLibLCML=handle;			/* saving LCML lib pointer  */
   1948 
   1949 EXIT:
   1950     G726ENC_DPRINT("%d :: Exiting G726ENC_GetLCMLHandle..\n",__LINE__);
   1951     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   1952     return pHandle;
   1953 }
   1954 
   1955 #else
   1956 /*WINDOWS Explicit dll load procedure*/
   1957 OMX_HANDLETYPE G726ENC_GetLCMLHandle()
   1958 {
   1959     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
   1960     OMX_HANDLETYPE pHandle = NULL;
   1961     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1962     HINSTANCE hDLL;               // Handle to DLL
   1963     LPFNDLLFUNC1 fpGetHandle1;
   1964     hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0);
   1965     if (hDLL == NULL) {
   1966         //fputs(dlerror(), stderr);
   1967         G726ENC_DPRINT("BML Load Failed!!!\n");
   1968         return pHandle;
   1969     }
   1970     fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
   1971     if (!fpGetHandle1) {
   1972       // handle the error
   1973       FreeLibrary(hDLL);
   1974       return pHandle;
   1975     }
   1976     // call the function
   1977     eError = fpGetHandle1(&pHandle);
   1978     if(eError != OMX_ErrorNone) {
   1979         eError = OMX_ErrorUndefined;
   1980         G726ENC_DPRINT("eError != OMX_ErrorNone...\n");
   1981         pHandle = NULL;
   1982         return pHandle;
   1983     }
   1984     return pHandle;
   1985 }
   1986 #endif
   1987 
   1988 /* ================================================================================= */
   1989 /**
   1990 * @fn G726ENC_SetPending() description for G726ENC_SetPending
   1991 G726ENC_SetPending().
   1992 This component is called when a buffer is queued to the LCML
   1993 * @param pComponent  handle for this instance of the component
   1994 *
   1995 * @pre
   1996 *
   1997 * @post
   1998 *
   1999 * @return OMX_ERRORTYPE
   2000 */
   2001 /* ================================================================================ */
   2002 void G726ENC_SetPending(G726ENC_COMPONENT_PRIVATE *pComponentPrivate,
   2003                          OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   2004 {
   2005     OMX_U16 i = 0;
   2006 
   2007     if (eDir == OMX_DirInput) {
   2008         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2009             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2010                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
   2011                 G726ENC_DPRINT("****INPUT BUFFER %d IS PENDING Line %ld******\n",i,lineNumber);
   2012             }
   2013         }
   2014     }
   2015     else {
   2016         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2017             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2018                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
   2019                 G726ENC_DPRINT("****OUTPUT BUFFER %d IS PENDING Line %ld*****\n",i,lineNumber);
   2020             }
   2021         }
   2022     }
   2023 }
   2024 /* ================================================================================= */
   2025 /**
   2026 * @fn G726ENC_ClearPending() description for G726ENC_ClearPending
   2027 G726ENC_ClearPending().
   2028 This component is called when a buffer is returned from the LCML
   2029 * @param pComponent  handle for this instance of the component
   2030 *
   2031 * @pre
   2032 *
   2033 * @post
   2034 *
   2035 * @return OMX_ERRORTYPE
   2036 */
   2037 /* ================================================================================ */
   2038 void G726ENC_ClearPending(G726ENC_COMPONENT_PRIVATE *pComponentPrivate,
   2039                            OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   2040 {
   2041     OMX_U16 i = 0;
   2042 
   2043     if (eDir == OMX_DirInput) {
   2044         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2045             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2046                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
   2047                 G726ENC_DPRINT("****INPUT BUFFER %d IS RECLAIMED Line %ld*****\n",i,lineNumber);
   2048             }
   2049         }
   2050     }
   2051     else {
   2052         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2053             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2054                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
   2055                 G726ENC_DPRINT("****OUTPUT BUFFER %d IS RECLAIMED Line %ld*****\n",i,lineNumber);
   2056             }
   2057         }
   2058     }
   2059 }
   2060 /* ================================================================================= */
   2061 /**
   2062 * @fn G726ENC_IsPending() description for G726ENC_IsPending
   2063 G726ENC_IsPending().
   2064 This method returns the pending status to the buffer
   2065 * @param pComponent  handle for this instance of the component
   2066 *
   2067 * @pre
   2068 *
   2069 * @post
   2070 *
   2071 * @return OMX_ERRORTYPE
   2072 */
   2073 /* ================================================================================ */
   2074 OMX_U32 G726ENC_IsPending(G726ENC_COMPONENT_PRIVATE *pComponentPrivate,
   2075                            OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
   2076 {
   2077     OMX_U16 i = 0;
   2078 
   2079     if (eDir == OMX_DirInput) {
   2080         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2081             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2082                 return pComponentPrivate->pInputBufferList->bBufferPending[i];
   2083             }
   2084         }
   2085     }
   2086     else {
   2087         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2088             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2089                 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
   2090             }
   2091         }
   2092     }
   2093     return -1;
   2094 }
   2095 /* ================================================================================= */
   2096 /**
   2097 * @fn G726ENC_IsValid() description for G726ENC_IsValid
   2098 G726ENC_IsValid().
   2099 This method checks to see if a buffer returned from the LCML is valid.
   2100 * @param pComponent  handle for this instance of the component
   2101 *
   2102 * @pre
   2103 *
   2104 * @post
   2105 *
   2106 * @return OMX_ERRORTYPE
   2107 */
   2108 /* ================================================================================ */
   2109 OMX_U32 G726ENC_IsValid(G726ENC_COMPONENT_PRIVATE *pComponentPrivate,
   2110                          OMX_U8 *pBuffer, OMX_DIRTYPE eDir)
   2111 {
   2112     OMX_U16 i = 0;
   2113     OMX_U32 found=0;
   2114 
   2115     if (eDir == OMX_DirInput) {
   2116         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2117             if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) {
   2118                 found = 1;
   2119             }
   2120         }
   2121     }
   2122     else {
   2123         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2124             if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) {
   2125                 found = 1;
   2126             }
   2127         }
   2128     }
   2129     return found;
   2130 }
   2131 /* ========================================================================== */
   2132 /**
   2133 * @G726ENC_FillLCMLInitParamsEx() This function is used by the component thread to
   2134 * fill the all of its initialization parameters, buffer deatils  etc
   2135 * to LCML structure,
   2136 *
   2137 * @param pComponent  handle for this instance of the component
   2138 * @param plcml_Init  pointer to LCML structure to be filled
   2139 *
   2140 * @pre
   2141 *
   2142 * @post
   2143 *
   2144 * @return none
   2145 */
   2146 /* ========================================================================== */
   2147 OMX_ERRORTYPE G726ENC_FillLCMLInitParamsEx(OMX_HANDLETYPE pComponent)
   2148 {
   2149     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2150     OMX_U32 nIpBuf = 0,nIpBufSize = 0,nOpBuf = 0,nOpBufSize = 0;
   2151     OMX_BUFFERHEADERTYPE *pTemp = NULL;
   2152     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
   2153     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
   2154     G726ENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
   2155     OMX_U32 i = 0;
   2156     OMX_U32 size_lcml = 0;
   2157     G726ENC_DPRINT("%d :: G726ENC_FillLCMLInitParamsEx\n",__LINE__);
   2158     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
   2159     nIpBufSize = pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nBufferSize;
   2160     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   2161     nOpBufSize = pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nBufferSize;
   2162 
   2163     pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
   2164     pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
   2165 
   2166     G726ENC_DPRINT("%d :: ------ Buffer Details -----------\n",__LINE__);
   2167     G726ENC_DPRINT("%d :: Input  Buffer Count = %ld\n",__LINE__,nIpBuf);
   2168     G726ENC_DPRINT("%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
   2169     G726ENC_DPRINT("%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
   2170     G726ENC_DPRINT("%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
   2171     G726ENC_DPRINT("%d :: ------ Buffer Details ------------\n",__LINE__);
   2172     /* Allocate memory for all input buffer headers..
   2173      * This memory pointer will be sent to LCML */
   2174     size_lcml = nIpBuf * sizeof(G726ENC_LCML_BUFHEADERTYPE);
   2175     pTemp_lcml = (G726ENC_LCML_BUFHEADERTYPE *)SafeMalloc(size_lcml);
   2176     G726ENC_MEMPRINT("%d :: [ALLOC] %p\n",__LINE__,pTemp_lcml);
   2177     if(pTemp_lcml == NULL) {
   2178         G726ENC_DPRINT("%d :: Memory Allocation Failed\n",__LINE__);
   2179         eError = OMX_ErrorInsufficientResources;
   2180         goto EXIT;
   2181     }
   2182 
   2183     pComponentPrivate->pLcmlBufHeader[G726ENC_INPUT_PORT] = pTemp_lcml;
   2184     for (i=0; i<nIpBuf; i++) {
   2185         G726ENC_DPRINT("%d :: INPUT--------- Inside Ip Loop\n",__LINE__);
   2186         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
   2187         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   2188         pTemp->nAllocLen = nIpBufSize;
   2189         pTemp->nFilledLen = nIpBufSize;
   2190         pTemp->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER;
   2191         pTemp->nVersion.s.nVersionMinor = G726ENC_MINOR_VER;
   2192         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   2193         pTemp->nTickCount = G726ENC_NOT_USED;
   2194         pTemp_lcml->buffer = pTemp;
   2195         G726ENC_DPRINT("%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
   2196         pTemp_lcml->eDir = OMX_DirInput;
   2197         OMX_NBMALLOC_STRUCT(pTemp_lcml->pIpParam, G726ENC_ParamStruct);
   2198 
   2199 
   2200 
   2201         /*pTemp_lcml->pIpParam->usLastFrame = 0;*/
   2202         /* This means, it is not a last buffer. This flag is to be modified by
   2203          * the application to indicate the last buffer */
   2204         pTemp->nFlags = G726ENC_NORMAL_BUFFER;
   2205         pTemp++;
   2206         pTemp_lcml++;
   2207     }
   2208 
   2209     /* Allocate memory for all output buffer headers..
   2210      * This memory pointer will be sent to LCML */
   2211     size_lcml = nOpBuf * sizeof(G726ENC_LCML_BUFHEADERTYPE);
   2212     pTemp_lcml = (G726ENC_LCML_BUFHEADERTYPE *)SafeMalloc(size_lcml);
   2213     G726ENC_MEMPRINT("%d :: [ALLOC] %p\n",__LINE__,pTemp_lcml);
   2214     if(pTemp_lcml == NULL) {
   2215         G726ENC_DPRINT("%d :: Memory Allocation Failed\n",__LINE__);
   2216         eError = OMX_ErrorInsufficientResources;
   2217         goto EXIT;
   2218     }
   2219 
   2220     pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT] = pTemp_lcml;
   2221     for (i=0; i<nOpBuf; i++) {
   2222         G726ENC_DPRINT("%d :: OUTPUT--------- Inside Op Loop\n",__LINE__);
   2223         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   2224         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   2225         pTemp->nAllocLen = nOpBufSize;
   2226         pTemp->nFilledLen = nOpBufSize;
   2227         pTemp->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER;
   2228         pTemp->nVersion.s.nVersionMinor = G726ENC_MINOR_VER;
   2229         pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
   2230         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   2231         pTemp->nTickCount = G726ENC_NOT_USED;
   2232         pTemp_lcml->buffer = pTemp;
   2233         G726ENC_DPRINT("%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
   2234         pTemp_lcml->eDir = OMX_DirOutput;
   2235 /*        OMX_NBMALLOC_STRUCT(pTemp_lcml->pOpParam, G726ENC_ParamStruct);*//*According SN guide this variable should be neede*/
   2236 /*        memset(pTemp_lcml->pOpParam,0,sizeof(G726ENC_ParamStruct));*/
   2237 
   2238         /* This means, it is not a last buffer. This flag is to be modified by
   2239          * the application to indicate the last buffer */
   2240         pTemp->nFlags = G726ENC_NORMAL_BUFFER;
   2241         pTemp++;
   2242         pTemp_lcml++;
   2243     }
   2244     pComponentPrivate->bPortDefsAllocated = 1;
   2245     pComponentPrivate->bInitParamsInitialized = 1;
   2246 EXIT:
   2247     G726ENC_DPRINT("%d :: Exiting G726ENC_FillLCMLInitParamsEx\n",__LINE__);
   2248     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
   2249     return eError;
   2250 }
   2251 
   2252 #ifdef RESOURCE_MANAGER_ENABLED
   2253 /***********************************
   2254  *  Callback to the RM                                       *
   2255  ***********************************/
   2256 void G726ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
   2257 {
   2258     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   2259     OMX_STATETYPE state = OMX_StateIdle;
   2260     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
   2261     G726ENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
   2262 
   2263     pCompPrivate = (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   2264 
   2265     if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
   2266         if (pCompPrivate->curState == OMX_StateExecuting ||
   2267             pCompPrivate->curState == OMX_StatePause) {
   2268 
   2269             write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
   2270             write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
   2271 
   2272             pCompPrivate->bPreempted = 1;
   2273         }
   2274     }
   2275     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
   2276         pCompPrivate->cbInfo.EventHandler ( pHandle,
   2277                                             pHandle->pApplicationPrivate,
   2278                                             OMX_EventResourcesAcquired,
   2279                                             0, 0, NULL);
   2280     }
   2281 }
   2282 #endif
   2283