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_AacEnc_Utils.c
     30 *
     31 * This file implements OMX Component for AAC encoder that
     32 * is fully compliant with the OMX Audio specification 1.0.
     33 *
     34 * @path  $(CSLPATH)\
     35 *
     36 * @rev  1.0
     37 */
     38 /* ----------------------------------------------------------------------------
     39 *!
     40 *! Revision History
     41 *! ===================================
     42 *! 13-Dec-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
     43 *! to provide _________________.
     44 *!
     45 *!
     46 *! 13-Dec-2005 mf:
     47 *! This is newest file
     48 * =========================================================================== */
     49 
     50 
     51 /* ------compilation control switches -------------------------*/
     52 /****************************************************************
     53 *  INCLUDE FILES
     54 ****************************************************************/
     55 /* ----- system and platform files ----------------------------*/
     56 #ifdef UNDER_CE
     57 #include <windows.h>
     58 #include <oaf_osal.h>
     59 #include <omx_core.h>
     60 #include <stdlib.h>
     61 #else
     62 #include <wchar.h>
     63 #include <unistd.h>
     64 #include <sys/types.h>
     65 #include <sys/wait.h>
     66 #include <sys/types.h>
     67 #include <sys/stat.h>
     68 #include <dlfcn.h>
     69 #include <malloc.h>
     70 #include <memory.h>
     71 #include <fcntl.h>
     72 #include <errno.h>
     73 #include <dlfcn.h>
     74 #endif
     75 #include <dbapi.h>
     76 #include <string.h>
     77 #include <stdio.h>
     78 #include "OMX_AacEnc_Utils.h"
     79 #include "Aacencsocket_ti.h"
     80 #include <encode_common_ti.h>
     81 #include "OMX_AacEnc_CompThread.h"
     82 #include "usn.h"
     83 #ifdef RESOURCE_MANAGER_ENABLED
     84 #include <ResourceManagerProxyAPI.h>
     85 #endif
     86 
     87 #ifdef UNDER_CE
     88 #define HASHINGENABLE 1
     89 #endif
     90 
     91 /* ========================================================================== */
     92 /**
     93 * @AACENCFill_LCMLInitParams () This function is used by the component thread to
     94 * fill the all of its initialization parameters, buffer deatils  etc
     95 * to LCML structure,
     96 *
     97 * @param pComponent  handle for this instance of the component
     98 * @param plcml_Init  pointer to LCML structure to be filled
     99 *
    100 * @pre
    101 *
    102 * @post
    103 *
    104 * @return none
    105 */
    106 /* ========================================================================== */
    107 /*static AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC;*/
    108 
    109 OMX_ERRORTYPE AACENCFill_LCMLInitParams(OMX_HANDLETYPE pComponent, LCML_DSP *plcml_Init, OMX_U16 arr[])
    110 {
    111     OMX_ERRORTYPE eError = OMX_ErrorNone;
    112     OMX_U32 nIpBuf =0 ,nIpBufSize=0 ,nOpBuf = 0 ,nOpBufSize=0;
    113     OMX_U32 i                               = 0;
    114     OMX_BUFFERHEADERTYPE *pTemp             = NULL;
    115     OMX_S32 size_lcml                       = 0;
    116     char *ptr;
    117     LCML_AACENC_BUFHEADERTYPE *pTemp_lcml   = NULL;
    118     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
    119      AACENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
    120     LCML_STRMATTR *strmAttr                 = NULL;
    121     OMX_U16 HigherBitsSamplingRate          = 0;
    122     OMX_U16 FramesPerOutBuf                 = 0;
    123     OMX_U16 Channels                        = 0;
    124 
    125 
    126     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: AACENCFill_LCMLInitParams\n ",__LINE__);
    127     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
    128     pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
    129     nIpBufSize = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferSize;
    130     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
    131     nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
    132     /*saving a copy a number of output buffers */
    133     pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
    134 
    135     /*recovering the value for the number of frames per Ouput Buffer */
    136     FramesPerOutBuf = (OMX_U16)pComponentPrivate->FramesPer_OutputBuffer;
    137     OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Frames per output buffer = %d \n\n",__LINE__, FramesPerOutBuf);
    138 
    139 
    140     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__);
    141     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Count = %ld \n",__LINE__,nIpBuf);
    142     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
    143     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
    144     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
    145     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__);
    146 
    147     /* Fill Input Buffers Info for LCML */
    148     plcml_Init->In_BufInfo.nBuffers = nIpBuf;
    149     plcml_Init->In_BufInfo.nSize = nIpBufSize;
    150     plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
    151 
    152     /* Fill Output Buffers Info for LCML */
    153     plcml_Init->Out_BufInfo.nBuffers = nOpBuf;
    154     plcml_Init->Out_BufInfo.nSize = nOpBufSize;
    155     plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
    156 
    157     /*Copy the node information*/
    158     plcml_Init->NodeInfo.nNumOfDLLs = 3;
    159 
    160     plcml_Init->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID*)&MPEG4AACENC_SN_UUID;
    161     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,AACENC_DLL_NAME);
    162     plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
    163 
    164 
    165     plcml_Init->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID*)&MPEG4AACENC_SN_UUID;
    166     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,AACENC_DLL_NAME);
    167     plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
    168 
    169 
    170     plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
    171     strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName,AACENC_USN_DLL_NAME);
    172     plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
    173 
    174     plcml_Init->DeviceInfo.TypeofDevice = 0;
    175     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
    176     if(pComponentPrivate->dasfmode == 1) {
    177         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to DASF mode\n",__LINE__);
    178         OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
    179         OMX_PRINT1(pComponentPrivate->dbg, "strmAttr %p \n",strmAttr);
    180 
    181         pComponentPrivate->strmAttr = strmAttr;
    182         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,strmAttr);
    183         strmAttr->uSegid        = 0;
    184         strmAttr->uAlignment    = 0;
    185         strmAttr->uTimeout      = 1000;
    186         strmAttr->uBufsize      = INPUT_AACENC_BUFFER_SIZE_DASF;
    187         strmAttr->uNumBufs      = NUM_AACENC_INPUT_BUFFERS_DASF;
    188         strmAttr->lMode         = STRMMODE_PROCCOPY;
    189 
    190         plcml_Init->DeviceInfo.TypeofDevice = 1;
    191         plcml_Init->DeviceInfo.TypeofRender = 1;
    192         plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
    193         plcml_Init->DeviceInfo.DspStream = strmAttr;
    194     }
    195 
    196     /*copy the other information*/
    197     plcml_Init->SegID       = OMX_AACENC_DEFAULT_SEGMENT;
    198     plcml_Init->Timeout     = -1;/*OMX_AACENC_SN_TIMEOUT;*/
    199     plcml_Init->Alignment   = 0;
    200     plcml_Init->Priority    = OMX_AACENC_SN_PRIORITY;
    201     plcml_Init->ProfileID   = -1;
    202 
    203     pComponentPrivate->unNumChannels   = (OMX_U16)pComponentPrivate->aacParams[OUTPUT_PORT]->nChannels;       /*Number of Channels*/
    204     /* splitting values for Sample rate and bit rate */
    205     pComponentPrivate->ulSamplingRate  = (OMX_U16)pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate;       /*Sampling rate*/
    206     HigherBitsSamplingRate             =(OMX_U16)((pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate >>16)& 0xFFFF);
    207     pComponentPrivate->unBitrate       = pComponentPrivate->aacParams[OUTPUT_PORT]->nBitRate;                /*Bit rate 2bytes*/
    208     pComponentPrivate->nObjectType     = pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile;            /*Object Type */
    209 
    210     /*   Remaping Number of channels for SN */
    211     /*   SN does use 0: Mono and  1: stereo      */
    212     if(pComponentPrivate->unNumChannels==2)
    213     {
    214         Channels=1;
    215     }
    216     else if (pComponentPrivate->unNumChannels==1)
    217     {
    218         Channels=0;
    219     }
    220 
    221     if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatRAW ||
    222         pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4FF){
    223         pComponentPrivate->File_Format = 0;
    224             OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatRAW \n");
    225     }
    226     else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatADIF) {
    227         pComponentPrivate->File_Format = 1;
    228             OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatADIF \n");
    229     }
    230     else if((pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4ADTS) ||
    231             (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP2ADTS) )
    232     {
    233         pComponentPrivate->File_Format = 2;
    234             OMX_PRDSP2(pComponentPrivate->dbg, "OMX_AUDIO_AACStreamFormatMP2ADTS \n");
    235     }
    236 
    237     if(pComponentPrivate->dasfmode == 1) {
    238         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AAC ENCODER RUNNING UNDER DASF MODE\n",__LINE__);
    239 
    240         arr[0]  = 2;                                                      /*Number of Streams*/
    241         arr[1]  = 0;                                                      /*ID of the Input Stream*/
    242         arr[2]  = 1;                                                      /*Type of Input Stream*/
    243         arr[3]  = NUM_AACENC_INPUT_BUFFERS_DASF;                          /*Number of buffers for Input Stream*/
    244         arr[4]  = 1;                                                      /*ID of the Output Stream*/
    245         arr[5]  = 0;                                                      /*Type of Output Stream*/
    246         arr[6]  = 2;                                                      /*Number of buffers for Output Stream*/
    247         arr[7]  = 1;                                                      /*PNS Enable*/
    248         arr[8]  = 1;                                                      /*TNS Enable*/
    249         arr[9]  = Channels;                                               /*Number of Channels*/
    250         arr[10] = pComponentPrivate->ulSamplingRate;                      /*Sampling rate- Lower bits*/
    251         arr[11] = HigherBitsSamplingRate;                                 /*Sampling rate -Higher bits */
    252         arr[12] = (OMX_U16)(pComponentPrivate->unBitrate & 0xFFFF);       /*Bit rate 2bytes*/
    253         arr[13] = (OMX_U16)(pComponentPrivate->unBitrate >> 16);          /*Bit rate 2bytes*/
    254         arr[14] = (OMX_U16)pComponentPrivate->nObjectType;                /*Object Type */
    255         arr[15] = (OMX_U16)pComponentPrivate->bitRateMode;                /*bitrateMode*/
    256         arr[16] = (OMX_U16)pComponentPrivate->File_Format;                /*FileFormat*/
    257         arr[17] = FramesPerOutBuf;                                        /*FramesPerOutBuf*/
    258         arr[18] = END_OF_CR_PHASE_ARGS;
    259 
    260     }
    261 
    262     if(pComponentPrivate->dasfmode == 0) {
    263         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AAC ENCODER RUNNING UNDER FILE MODE\n",__LINE__);
    264         arr[0]  = 2;                                                      /*Number of Streams*/
    265         arr[1]  = 0;                                                      /*ID of the Input Stream*/
    266         arr[2]  = 0;                                                      /*Type of Input Stream*/
    267         if (pComponentPrivate->pInputBufferList->numBuffers) {
    268             arr[3] = (OMX_U16) pComponentPrivate->pInputBufferList->numBuffers;     /*Number of buffers for Input Stream*/
    269             OMX_PRBUFFER1(pComponentPrivate->dbg, "arr[3] InputBuffers %d \n",arr[3]);
    270         }
    271         else {
    272             arr[3] = 1;
    273         }
    274         arr[4]  = 1;                                                      /*ID of the Output Stream*/
    275         arr[5]  = 0;                                                      /*Type of Output Stream*/
    276         if (pComponentPrivate->pOutputBufferList->numBuffers) {
    277             arr[6] = (OMX_U16) pComponentPrivate->pOutputBufferList->numBuffers;    /*Number of buffers for Output Stream*/
    278             OMX_PRBUFFER1(pComponentPrivate->dbg, "arr[6] Output Buffers%d \n",arr[6]);
    279         }
    280         else {
    281             arr[6] = 1;
    282         }
    283 
    284         arr[7]  = 1;                                                      /*PNS Enable*/
    285         arr[8]  = 1;                                                      /*TNS Enable*/
    286         /*  Adjusting the value for SN enum-type compatibility */
    287         arr[9]  = Channels;                                               /*Number of Channels*/
    288             OMX_PRCOMM2(pComponentPrivate->dbg, "arr[9] Channels %d \n",arr[9]);
    289         arr[10] = pComponentPrivate->ulSamplingRate;                      /*Sampling rate- Lower bits*/
    290         arr[11] = HigherBitsSamplingRate;                                 /*Sampling rate -Higher bits */
    291         arr[12] = (OMX_U16)(pComponentPrivate->unBitrate & 0xFFFF);       /*Bit rate 2bytes*/
    292         arr[13] = (OMX_U16)(pComponentPrivate->unBitrate >> 16);          /*Bit rate 2bytes*/
    293         arr[14] = (OMX_U16)pComponentPrivate->nObjectType;                                        /*bitsperSample;*/
    294             OMX_PRINT2(pComponentPrivate->dbg, "arr[14] Object Type %d \n",arr[14]);
    295         arr[15] = (OMX_U16)pComponentPrivate->bitRateMode;                /*bitrateMode*/
    296             OMX_PRINT2(pComponentPrivate->dbg, "arr[15] Bit Rate %d \n",arr[15]);
    297         arr[16] = pComponentPrivate->File_Format;                         /*FileFormat*/
    298             OMX_PRINT2(pComponentPrivate->dbg, "arr[16] format type %d \n",arr[16]);
    299         arr[17] = FramesPerOutBuf;                                        /*FramesPerOutBuf*/
    300         arr[18] = END_OF_CR_PHASE_ARGS;
    301 
    302     }
    303 
    304     plcml_Init->pCrPhArgs = arr;
    305 
    306     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
    307     size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
    308     OMX_MALLOC_SIZE(ptr, size_lcml,char);
    309     pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
    310     pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
    311     for (i=0; i<nIpBuf; i++)
    312     {
    313         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
    314         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    315         pTemp->nAllocLen = nIpBufSize;
    316         pTemp->nFilledLen = nIpBufSize;
    317         pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
    318         pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
    319         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    320         pTemp->nTickCount = NOT_USED;
    321         pTemp_lcml->buffer = pTemp;
    322         pTemp_lcml->eDir = OMX_DirInput;
    323 
    324         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
    325                                sizeof(AACENC_UAlgInBufParamStruct),
    326                                AACENC_UAlgInBufParamStruct);
    327         OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml->pIpParam %p \n",pTemp_lcml->pIpParam);
    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 = NORMAL_BUFFER;
    333         pTemp_lcml++;
    334     }
    335 
    336     /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
    337     size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
    338 
    339     OMX_MALLOC_SIZE(ptr, size_lcml,char);
    340     pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
    341 
    342     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
    343     for (i=0; i<nOpBuf; i++)
    344     {
    345         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
    346         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
    347         pTemp->nAllocLen = nOpBufSize;
    348         pTemp->nFilledLen = nOpBufSize;
    349         pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
    350         pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
    351         pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
    352         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
    353         pTemp->nTickCount = NOT_USED;
    354         /* This means, it is not a last buffer. This flag is to be modified by
    355                     the application to indicate the last buffer */
    356         pTemp_lcml->buffer = pTemp;
    357         pTemp_lcml->eDir = OMX_DirOutput;
    358         /* SN : Each output buffer may be accompanied by an output buffer parameters structure*/
    359 
    360         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
    361                                sizeof(AACENC_UAlgOutBufParamStruct),
    362                                AACENC_UAlgOutBufParamStruct);
    363 
    364         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: size of pOpParam: %d \n",__LINE__,sizeof(pTemp_lcml->pOpParam->unFrameSizes));
    365         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: numframes of pOpParam: %d \n\n",__LINE__,sizeof(pTemp_lcml->pOpParam->unNumFramesEncoded)) ;
    366         OMX_PRDSP1(pComponentPrivate->dbg, "UTIL: pTemp_lcml->pOpParam %p \n",pTemp_lcml->pOpParam);
    367 
    368         pTemp->nFlags = NORMAL_BUFFER;
    369         /*pTemp++;*/
    370         pTemp_lcml++;
    371     }
    372     pComponentPrivate->bPortDefsAllocated = 1;
    373     pComponentPrivate->bBypassDSP = 0;
    374     pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
    375 
    376 
    377     OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->ptAlgDynParams,
    378                                 sizeof(MPEG4AACENC_UALGParams),
    379                                 MPEG4AACENC_UALGParams);
    380 
    381     OMX_PRINT2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->ptAlgDynParams %p \n",pComponentPrivate->ptAlgDynParams);
    382 
    383 #ifdef __PERF_INSTRUMENTATION__
    384         pComponentPrivate->nLcml_nCntIp = 0;
    385         pComponentPrivate->nLcml_nCntOpReceived = 0;
    386 #endif
    387 
    388 
    389 EXIT:
    390     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting Fill_LCMLInitParams\n",__LINE__);
    391     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Returning = 0x%x\n",__LINE__,eError);
    392     return eError;
    393 }
    394 
    395 /* ========================================================================== */
    396 /**
    397 * AACENC_StartComponentThread() This function is called by the component to create
    398 * the component thread, command pipe, data pipe and LCML Pipe.
    399 *
    400 * @param pComponent  handle for this instance of the component
    401 *
    402 * @pre
    403 *
    404 * @post
    405 *
    406 * @return none
    407 */
    408 /* ========================================================================== */
    409 
    410 OMX_ERRORTYPE AACENC_StartComponentThread(OMX_HANDLETYPE pComponent)
    411 {
    412     OMX_ERRORTYPE eError = OMX_ErrorNone;
    413     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    414     AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    415 #ifdef UNDER_CE
    416     pthread_attr_t attr;
    417     memset(&attr, 0, sizeof(attr));
    418     attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
    419     attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY;
    420 #endif
    421 
    422 
    423     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering  AACENC_StartComponentThread\n", __LINE__);
    424     /* Initialize all the variables*/
    425     pComponentPrivate->bIsStopping = 0;
    426     pComponentPrivate->bIsThreadstop = 0;
    427     pComponentPrivate->lcml_nOpBuf = 0;
    428     pComponentPrivate->lcml_nIpBuf = 0;         /* Initializing counter */
    429     pComponentPrivate->app_nBuf = 0;                    /* Not Used */
    430     pComponentPrivate->num_Op_Issued = 0;
    431     pComponentPrivate->num_Sent_Ip_Buff = 0;
    432     pComponentPrivate->num_Reclaimed_Op_Buff = 0;       /* Not Used */
    433     pComponentPrivate->bIsEOFSent = 0;
    434 
    435     /* create the pipe used to send buffers to the thread */
    436     eError = pipe (pComponentPrivate->cmdDataPipe);
    437     if (eError)
    438     {
    439         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
    440         eError = OMX_ErrorInsufficientResources;
    441         goto EXIT;
    442     }
    443 
    444     /* create the pipe used to send buffers to the thread */
    445     eError = pipe (pComponentPrivate->dataPipe);
    446     if (eError)
    447     {
    448         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
    449         eError = OMX_ErrorInsufficientResources;
    450         goto EXIT;
    451     }
    452 
    453     /* create the pipe used to send commands to the thread */
    454     eError = pipe (pComponentPrivate->cmdPipe);
    455     if (eError) {
    456         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
    457         eError = OMX_ErrorInsufficientResources;
    458         goto EXIT;
    459     }
    460 
    461     /* create the pipe used to send commands to the thread */
    462 #ifdef UNDER_CE
    463     eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, AACENC_ComponentThread, pComponentPrivate);
    464 #else
    465     eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, AACENC_ComponentThread, pComponentPrivate);
    466 #endif
    467     if (eError || !pComponentPrivate->ComponentThread) {
    468         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
    469         eError = OMX_ErrorInsufficientResources;
    470         goto EXIT;
    471     }
    472 
    473     OMX_PRDSP1(pComponentPrivate->dbg, "%d :: pComponent[%x] AACENC_StartComponentThread\n", __LINE__, (int)pComponent) ;
    474     OMX_PRDSP1(pComponentPrivate->dbg, "%d :: pHandle[%x] AACENC_StartComponentThread\n", __LINE__, (int)pHandle) ;
    475     pComponentPrivate->bCompThreadStarted = 1;
    476 
    477 EXIT:
    478     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting from AACENC_StartComponentThread\n", __LINE__);
    479     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
    480     return eError;
    481 }
    482 
    483 /* ========================================================================== */
    484 /**
    485 * AACENC_FreeCompResources() This function is called by the component during
    486 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
    487 *
    488 * @param pComponent  handle for this instance of the component
    489 *
    490 * @pre
    491 *
    492 * @post
    493 *
    494 * @return none
    495 */
    496 /* ========================================================================== */
    497 
    498 OMX_ERRORTYPE AACENC_FreeCompResources(OMX_HANDLETYPE pComponent)
    499 {
    500     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    501     AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    502 
    503     OMX_ERRORTYPE eError = OMX_ErrorNone;
    504     OMX_ERRORTYPE err = OMX_ErrorNone;
    505     OMX_U32 nIpBuf = 0;
    506     OMX_U32 nOpBuf = 0;
    507 
    508     OMX_PRINT1(pComponentPrivate->dbg, " %d :: Entering AACENC_FreeCompResources\n",__LINE__);
    509     if (pComponentPrivate->bPortDefsAllocated) {
    510         nIpBuf = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountActual;
    511         nOpBuf = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
    512     }
    513 
    514     if (pComponentPrivate->bCompThreadStarted) {
    515         OMX_CLOSE_PIPE(pComponentPrivate->dataPipe[0],err);
    516         OMX_CLOSE_PIPE(pComponentPrivate->dataPipe[1],err);
    517         OMX_CLOSE_PIPE(pComponentPrivate->cmdPipe[0],err);
    518         OMX_CLOSE_PIPE(pComponentPrivate->cmdPipe[1],err);
    519         OMX_CLOSE_PIPE(pComponentPrivate->cmdDataPipe[0],err);
    520         OMX_CLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
    521     }
    522 
    523     if (pComponentPrivate->bPortDefsAllocated) {
    524         OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT]);
    525         OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT]);
    526         OMX_MEMFREE_STRUCT(pComponentPrivate->aacParams[INPUT_PORT]);
    527         OMX_MEMFREE_STRUCT(pComponentPrivate->aacParams[OUTPUT_PORT]);
    528         OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParam[INPUT_PORT]);
    529         OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParam[OUTPUT_PORT]);
    530     }
    531     pComponentPrivate->bPortDefsAllocated = 0;
    532 
    533 #ifndef UNDER_CE
    534     OMX_PRDSP1(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n\n");
    535     pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
    536     pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
    537 
    538     pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
    539     pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
    540 
    541     pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
    542     pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
    543 
    544     pthread_mutex_destroy(&bufferReturned_mutex);
    545     pthread_cond_destroy(&bufferReturned_condition);
    546 #else
    547     pComponentPrivate->bPortDefsAllocated = 0;
    548     OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
    549     OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
    550     OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
    551 #endif
    552 
    553 EXIT:
    554     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting AACENC_FreeCompResources()\n",__LINE__);
    555     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
    556 
    557     return eError;
    558 }
    559 
    560 /* ========================================================================== */
    561 /**
    562 * @AACENC_CleanupInitParams() This function is called by the component during
    563 * de-init to free structues that are been allocated at intialization stage
    564 *
    565 * @param pComponent  handle for this instance of the component
    566 *
    567 * @pre
    568 *
    569 * @post
    570 *
    571 * @return none
    572 */
    573 /* ========================================================================== */
    574 OMX_ERRORTYPE AACENC_CleanupInitParams(OMX_HANDLETYPE pComponent)
    575 {
    576     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    577     AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    578     LCML_AACENC_BUFHEADERTYPE *pTemp_lcml=NULL;
    579     OMX_ERRORTYPE eError = OMX_ErrorNone;
    580     OMX_U32 nIpBuf = 0;
    581     OMX_U32 nOpBuf = 0;
    582     OMX_U32 i      = 0;
    583 
    584     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENC_CleanupInitParams()\n", __LINE__);
    585     OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
    586 
    587     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[INPUT_PORT];
    588     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
    589     for(i=0; i<nIpBuf; i++)
    590     {
    591         OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, AACENC_UAlgInBufParamStruct);
    592         pTemp_lcml++;
    593     }
    594 
    595     /*Free ouput buffers params */
    596     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[OUTPUT_BUFFER];
    597     nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
    598     for (i=0; i<nOpBuf; i++)
    599     {
    600         OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, AACENC_UAlgOutBufParamStruct);
    601         pTemp_lcml++;
    602     }
    603 
    604     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
    605     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
    606     OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->ptAlgDynParams, MPEG4AACENC_UALGParams);
    607     if(pComponentPrivate->dasfmode == 1)
    608     {
    609         OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, AACENC_AudioCodecParams);
    610     }
    611 
    612     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting Successfully AACENC_CleanupInitParams()\n",__LINE__);
    613     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
    614     return eError;
    615 }
    616 
    617 /* ========================================================================== */
    618 /**
    619 * AACENC_StopComponentThread() This function is called by the component during
    620 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
    621 *
    622 * @param pComponent  handle for this instance of the component
    623 *
    624 * @pre
    625 *
    626 * @post
    627 *
    628 * @return none
    629 */
    630 /* ========================================================================== */
    631 
    632 OMX_ERRORTYPE AACENC_StopComponentThread(OMX_HANDLETYPE pComponent)
    633 {
    634     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
    635     AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
    636 
    637     OMX_ERRORTYPE eError = OMX_ErrorNone;
    638     OMX_ERRORTYPE threadError = OMX_ErrorNone;
    639     int pthreadError = 0;
    640 
    641     OMX_PRINT1(pComponentPrivate->dbg, " %d :: UTIL: Entering AACENC_StopComponentThread\n",__LINE__);
    642     /*Join the component thread*/
    643     pComponentPrivate->bIsThreadstop = 1;
    644     write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsThreadstop, sizeof(OMX_U16));
    645     OMX_PRSTATE1(pComponentPrivate->dbg, "UTIL: pComponentPrivate->bIsThreadstop = %ld \n",pComponentPrivate->bIsThreadstop);
    646     pthreadError = pthread_join (pComponentPrivate->ComponentThread,(void*)&threadError);
    647     if (0 != pthreadError)
    648     {
    649         eError = OMX_ErrorHardware;
    650         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error closing ComponentThread - pthreadError = %d\n",__LINE__,pthreadError);
    651         goto EXIT;
    652     }
    653 
    654     /*Check for the errors*/
    655     if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError)
    656     {
    657         eError = OMX_ErrorInsufficientResources;
    658         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while closing Component Thread\n",__LINE__);
    659         goto EXIT;
    660 
    661     }
    662 EXIT:
    663     OMX_PRINT1(pComponentPrivate->dbg, " %d :: UTIL: Exiting AACENC_StopComponentThread\n",__LINE__);
    664     return eError;
    665 }
    666 
    667 
    668 /* ========================================================================== */
    669 /**
    670 * AACENCHandleCommand() This function is called by the component when ever it
    671 * receives the command from the application
    672 *
    673 * @param pComponentPrivate  Component private data
    674 *
    675 * @pre
    676 *
    677 * @post
    678 *
    679 * @return none
    680 */
    681 /* ========================================================================== */
    682 
    683 OMX_U32 AACENCHandleCommand(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
    684 {
    685 
    686     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
    687     OMX_COMMANDTYPE command;
    688     OMX_STATETYPE commandedState;
    689     OMX_U32 commandData;
    690     OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
    691     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
    692     OMX_ERRORTYPE eError = OMX_ErrorNone;
    693     OMX_U16 arr[100]={0};
    694     OMX_S32 ret = 0;
    695     OMX_U32 i=0;
    696     char *p  = "start";
    697     char *pArgs = "damedesuStr";
    698     OMX_U32 pValues[4]={0};
    699     OMX_U32 pValues1[4]={0};
    700     LCML_CALLBACKTYPE cb;
    701     LCML_DSP *pLcmlDsp = NULL;
    702     LCML_AACENC_BUFHEADERTYPE *pLcmlHdr;
    703     int inputPortFlag = 0;
    704     int outputPortFlag = 0;
    705 
    706     OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: Entering AACENCHandleCommand Function - curState = %d\n",__LINE__,pComponentPrivate->curState);
    707     ret = read (pComponentPrivate->cmdPipe[0], &command, sizeof (command));
    708     OMX_TRACE1(pComponentPrivate->dbg, "%d :: AACENC: Command pipe has been read = %ld \n",__LINE__,ret);
    709     if (ret == -1)
    710     {
    711         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__);
    712         eError = OMX_ErrorHardware;
    713         goto EXIT;
    714     }
    715     ret = read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
    716     OMX_TRACE1(pComponentPrivate->dbg, "%d :: AACENC: Command data pipe has been read = %ld \n",__LINE__,ret);
    717     if (ret == -1)
    718     {
    719         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__);
    720         eError = OMX_ErrorHardware;
    721         goto EXIT;
    722     }
    723 
    724 #ifdef __PERF_INSTRUMENTATION__
    725     PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,command,commandData,PERF_ModuleLLMM);
    726 #endif
    727 
    728     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand :: Command is = %d\n",__LINE__,command);
    729     if (command == OMX_CommandStateSet)
    730     {
    731         commandedState = (OMX_STATETYPE)commandData;
    732         if ( pComponentPrivate->curState==commandedState)
    733         {
    734             pComponentPrivate->cbInfo.EventHandler(pHandle,
    735                                                    pHandle->pApplicationPrivate,
    736                                                    OMX_EventError,
    737                                                    OMX_ErrorSameState,
    738                                                    OMX_TI_ErrorMinor,
    739                                                    NULL);
    740             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application\n",__LINE__);
    741             OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: State Given is: %d \n", __LINE__, commandedState);
    742         }
    743         else
    744         {
    745             switch(commandedState)
    746             {
    747                 case OMX_StateIdle:
    748                     OMX_PRDSP2(pComponentPrivate->dbg, "%d: AACENCHandleCommand: Cmd Idle \n",__LINE__);
    749                     OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: curstate = %d\n",pComponentPrivate->curState);
    750                     if (pComponentPrivate->curState == OMX_StateLoaded)
    751                     {
    752 
    753 #ifdef __PERF_INSTRUMENTATION__
    754                         PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup);
    755 #endif
    756                         if(pComponentPrivate->dasfmode == 1)
    757                         {
    758                             if (pComponentPrivate->dasfmode == 1)
    759                             {
    760                                 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled= FALSE;
    761                                 pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated= FALSE;
    762                             }
    763                             if (pComponentPrivate->streamID==0)
    764                             {
    765 
    766                                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Insufficient resources\n", __LINE__);
    767                                 eError = OMX_ErrorInsufficientResources;
    768                                 OMX_ERROR4(pComponentPrivate->dbg, "AACENC: State changed to OMX_StateInvalid Line %d\n",__LINE__);
    769                                 pComponentPrivate->curState = OMX_StateInvalid;
    770                                 pComponentPrivate->cbInfo.EventHandler(pHandle,
    771                                                                         pHandle->pApplicationPrivate,
    772                                                                         OMX_EventError,
    773                                                                         eError,
    774                                                                         OMX_TI_ErrorMajor,
    775                                                                         "No Stream ID Available");
    776                                 goto EXIT;
    777                             }
    778                         }
    779 
    780                         OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [INPUT_PORT]->bPopulated  %d \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
    781                         OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [INPUT_PORT]->bEnabled    %d \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
    782                         OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [OUTPUT_PORT]->bPopulated %d \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated);
    783                         OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_StateLoaded [OUTPUT_PORT]->bEnabled   %d \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
    784 
    785                         if (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&  pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled)  {
    786                             inputPortFlag = 1;
    787                         }
    788 
    789                         if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) {
    790                             inputPortFlag = 1;
    791                         }
    792 
    793                         if (pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled) {
    794                             outputPortFlag = 1;
    795                         }
    796 
    797                         if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled) {
    798                             outputPortFlag = 1;
    799                         }
    800 
    801                         OMX_PRCOMM2(pComponentPrivate->dbg, "inputPortFlag = %d\n",inputPortFlag);
    802                         OMX_PRCOMM2(pComponentPrivate->dbg, "outputPortFlag = %d\n",outputPortFlag);
    803                         if (!(inputPortFlag && outputPortFlag))
    804                         {
    805 
    806                             pComponentPrivate->InLoaded_readytoidle = 1;
    807 #ifndef UNDER_CE
    808                             pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
    809                             pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex);
    810                             pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
    811 
    812 #else
    813                             OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
    814 #endif
    815                         }
    816 
    817                         cb.LCML_Callback = (void *) AACENCLCML_Callback;
    818                         pLcmlHandle = (OMX_HANDLETYPE) AACENCGetLCMLHandle(pComponentPrivate);
    819 
    820                         if (pLcmlHandle == NULL)
    821                         {
    822                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: LCML Handle is NULL........exiting..\n",__LINE__);
    823                             eError = OMX_ErrorHardware;
    824                             pComponentPrivate->cbInfo.EventHandler (pHandle,
    825                                                 pHandle->pApplicationPrivate,
    826                                                 OMX_EventError,
    827                                                 eError,
    828                                                 OMX_TI_ErrorSevere,
    829                                                 NULL);
    830                             goto EXIT;
    831                         }
    832 
    833                         /* Got handle of dsp via phandle filling information about DSP
    834                         specific things */
    835                         pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
    836                         eError = AACENCFill_LCMLInitParams(pHandle, pLcmlDsp, arr);
    837                         if(eError != OMX_ErrorNone)
    838                         {
    839                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from AACENCFill_LCMLInitParams()\n",__LINE__);
    840                             pComponentPrivate->cbInfo.EventHandler (pHandle,
    841                                                 pHandle->pApplicationPrivate,
    842                                                 OMX_EventError,
    843                                                 eError,
    844                                                 OMX_TI_ErrorMajor,
    845                                                 NULL);
    846                             goto EXIT;
    847                         }
    848                         pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
    849                         /*filling create phase params */
    850                         cb.LCML_Callback = (void *) AACENCLCML_Callback;
    851                         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Calling LCML_InitMMCodec...\n",__LINE__);
    852 
    853                         eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
    854                                                        p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
    855                         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: After Calling LCML_InitMMCodec...\n",__LINE__);
    856 
    857                         if(eError != OMX_ErrorNone)
    858                         {
    859                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from LCML_Init()\n",__LINE__);
    860                             /* send an event to client */
    861                             /* client should unload the component if the codec is not able to load */
    862                             eError = OMX_ErrorInvalidState;
    863                             pComponentPrivate->cbInfo.EventHandler (pHandle,
    864                                                 pHandle->pApplicationPrivate,
    865                                                 OMX_EventError,
    866                                                 eError,
    867                                                 OMX_TI_ErrorSevere,
    868                                                 NULL);
    869                             goto EXIT;
    870                         }
    871 
    872 #ifdef HASHINGENABLE
    873                         /* Enable the Hashing Code */
    874                         eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, OMX_TRUE);
    875                         if (eError != OMX_ErrorNone)
    876                         {
    877                             OMX_ERROR4(pComponentPrivate->dbg, "Error: Failed to set Mapping State\n");
    878                             goto EXIT;
    879                         }
    880 #endif
    881                         /* need check the resource with RM */
    882                         OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: About to call RMProxy_SendCommand\n", __LINE__);
    883 #ifdef RESOURCE_MANAGER_ENABLED
    884 
    885 
    886                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Returned from RMProxy_SendCommand\n", __LINE__);
    887                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: RMProxy_SendCommand returned %d\n", __LINE__,rm_error);
    888                         if(rm_error == OMX_ErrorNone)
    889                         {
    890                             /* resource is available */
    891                             pComponentPrivate->curState = OMX_StateIdle;
    892 
    893 #ifdef __PERF_INSTRUMENTATION__
    894                             PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup);
    895 #endif
    896                             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL);
    897                         }
    898                         else if(rm_error == OMX_ErrorInsufficientResources)
    899                         {
    900                             /* resource is not available, need set state to OMX_StateWaitForResources */
    901                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Insufficient resources\n", __LINE__);
    902                             pComponentPrivate->curState = OMX_StateWaitForResources;
    903                             pComponentPrivate->cbInfo.EventHandler(pHandle,
    904                                                                    pHandle->pApplicationPrivate,
    905                                                                    OMX_EventCmdComplete,
    906                                                                    OMX_CommandStateSet,
    907                                                                    pComponentPrivate->curState,
    908                                                                    NULL);
    909                             OMX_ERROR2(pComponentPrivate->dbg, "%d :: AACENC: OMX_ErrorInsufficientResources\n", __LINE__);
    910                         }
    911                         pComponentPrivate->curState = OMX_StateIdle;
    912 
    913                         /* Decrement reference count with signal enabled */
    914                         if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
    915                             return OMX_ErrorUndefined;
    916                         }
    917 
    918                         pComponentPrivate->cbInfo.EventHandler(pHandle,
    919                                                                pHandle->pApplicationPrivate,
    920                                                                OMX_EventCmdComplete,
    921                                                                OMX_CommandStateSet,
    922                                                                pComponentPrivate->curState,
    923                                                                NULL);
    924 #else
    925                 pComponentPrivate->curState = OMX_StateIdle;
    926 
    927                 /* Decrement reference count with signal enabled */
    928                 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
    929                      return OMX_ErrorUndefined;
    930                 }
    931 
    932                 pComponentPrivate->cbInfo.EventHandler( pHandle,
    933                                                         pHandle->pApplicationPrivate,
    934                                                         OMX_EventCmdComplete,
    935                                                         OMX_CommandStateSet,
    936                                                         pComponentPrivate->curState,
    937                                                         NULL);
    938 
    939 
    940 #endif
    941                     }
    942                     else if (pComponentPrivate->curState == OMX_StateExecuting)
    943                     {
    944 
    945 #ifdef __PERF_INSTRUMENTATION__
    946                         PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
    947 #endif
    948 
    949                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: Setting Component to OMX_StateIdle\n",__LINE__);
    950                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: About to Call MMCodecControlStop\n", __LINE__);
    951 
    952                         pComponentPrivate->bIsStopping = 1;
    953 
    954                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    955                                                       MMCodecControlStop,(void *)pArgs);
    956 
    957                         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
    958                         while (pComponentPrivate->codecStop_waitingsignal == 0){
    959                             pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
    960                         }
    961                         pComponentPrivate->codecStop_waitingsignal = 0;
    962                         pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
    963 
    964                         if(eError != OMX_ErrorNone)
    965                         {
    966                             OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
    967                             pComponentPrivate->cbInfo.EventHandler (pHandle,
    968                                                 pHandle->pApplicationPrivate,
    969                                                 OMX_EventError,
    970                                                 eError,
    971                                                 OMX_TI_ErrorSevere,
    972                                                 NULL);
    973                             goto EXIT;
    974                         }
    975                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After MMCodecControlStop\n", __LINE__);
    976                         pComponentPrivate->nNumOutputBufPending=0;
    977 
    978 #ifdef HASHINGENABLE
    979                         /*Hashing Change*/
    980                         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    981                         eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    982                         if (eError != OMX_ErrorNone)
    983                         {
    984                             OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n");
    985                             break;
    986                         }
    987 #endif
    988 
    989 
    990 
    991                     }
    992                     else if(pComponentPrivate->curState == OMX_StatePause)
    993                     {
    994 #ifdef HASHINGENABLE
    995                         /*Hashing Change*/
    996                         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
    997                         eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
    998                         if (eError != OMX_ErrorNone)
    999                         {
   1000                             OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n");
   1001                             break;
   1002                         }
   1003 #endif
   1004 
   1005 #ifdef __PERF_INSTRUMENTATION__
   1006                         PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1007 #endif
   1008                         pComponentPrivate->curState = OMX_StateIdle;
   1009 
   1010 #ifdef RESOURCE_MANAGER_ENABLED
   1011 
   1012                         rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL);
   1013 #endif
   1014 
   1015                         /* Decrement reference count with signal enabled */
   1016                         if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
   1017                             return OMX_ErrorUndefined;
   1018                         }
   1019 
   1020                         pComponentPrivate->cbInfo.EventHandler(pHandle,
   1021                                                                pHandle->pApplicationPrivate,
   1022                                                                OMX_EventCmdComplete,
   1023                                                                OMX_CommandStateSet,
   1024                                                                pComponentPrivate->curState,
   1025                                                                NULL);
   1026                     }
   1027                     else
   1028                     {
   1029                         /* This means, it is invalid state from application */
   1030                         OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: OMX_ErrorIncorrectStateTransition\n",__LINE__);
   1031                         pComponentPrivate->cbInfo.EventHandler(pHandle,
   1032                                                                pHandle->pApplicationPrivate,
   1033                                                                OMX_EventError,
   1034                                                                OMX_ErrorIncorrectStateTransition,
   1035                                                                OMX_TI_ErrorMinor,
   1036                                                                "Invalid State Error");
   1037                     }
   1038                     break;
   1039 
   1040 
   1041                 case OMX_StateExecuting:
   1042                     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Executing \n",__LINE__);
   1043                     if(pComponentPrivate->curState == OMX_StateIdle)
   1044                     {
   1045                         /* Sending commands to DSP via LCML_ControlCodec third argument is not used for time being */
   1046                         pComponentPrivate->bIsStopping = 0;
   1047                         if(pComponentPrivate->dasfmode == 1)
   1048                         {
   1049                             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
   1050 
   1051                             OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,
   1052                                 sizeof(AACENC_AudioCodecParams),
   1053                                 AACENC_AudioCodecParams);
   1054 
   1055                             OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pParams %p \n",pComponentPrivate->pParams);
   1056                             if(pComponentPrivate->unNumChannels == 1)   /*MONO*/
   1057                                 pComponentPrivate->pParams->iAudioFormat = 0x0001;
   1058                             else
   1059                                 pComponentPrivate->pParams->iAudioFormat = 0x0002;
   1060 
   1061                             pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
   1062                             pComponentPrivate->pParams->iSamplingRate = pComponentPrivate->ulSamplingRate;
   1063 
   1064                             pValues[0] = USN_STRMCMD_SETCODECPARAMS;
   1065                             pValues[1] = (OMX_U32)pComponentPrivate->pParams;
   1066                             pValues[2] = sizeof(AACENC_AudioCodecParams);
   1067                             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1068                                                          EMMCodecControlStrmCtrl,
   1069                                                          (void *)pValues);
   1070                             if(eError != OMX_ErrorNone)
   1071                             {
   1072                                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
   1073                                 pComponentPrivate->cbInfo.EventHandler (pHandle,
   1074                                                 pHandle->pApplicationPrivate,
   1075                                                 OMX_EventError,
   1076                                                 eError,
   1077                                                 OMX_TI_ErrorSevere,
   1078                                                 NULL);
   1079                                 goto EXIT;
   1080                             }
   1081                         }
   1082 
   1083                         pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.size                = sizeof(MPEG4AACENC_UALGParams);
   1084                         pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.bitRate             = pComponentPrivate->unBitrate;
   1085                         pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.sampleRate          = pComponentPrivate->ulSamplingRate;
   1086                         pComponentPrivate->ptAlgDynParams->audenc_dynamicparams.numChannels         = (pComponentPrivate->unNumChannels==2)?1:0;   /* Reduced */
   1087                         pComponentPrivate->ptAlgDynParams->useTns                                   = 1;
   1088                         pComponentPrivate->ptAlgDynParams->usePns                                   = 1;
   1089                         pComponentPrivate->ptAlgDynParams->outObjectType                            = pComponentPrivate->nObjectType;
   1090                         pComponentPrivate->ptAlgDynParams->outFileFormat                            = pComponentPrivate->File_Format;
   1091 
   1092                         OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.bitRate %d \n", (int)pComponentPrivate->unBitrate);
   1093                         OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.sampleRate %d \n ",pComponentPrivate->ulSamplingRate);
   1094                         OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: dynamicparams.numChannels %d \n", pComponentPrivate->unNumChannels);
   1095                         OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: ptAlgDynParams->outFileFormat %d \n",pComponentPrivate->File_Format);
   1096 
   1097                         pValues1[0] = IUALG_CMD_SETSTATUS;
   1098                         pValues1[1] = (OMX_U32)pComponentPrivate->ptAlgDynParams;
   1099                         pValues1[2] = sizeof(MPEG4AACENC_UALGParams);
   1100 
   1101                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1102                                                       EMMCodecControlAlgCtrl,(void *)pValues1);
   1103                         if(eError != OMX_ErrorNone)
   1104                         {
   1105                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
   1106                             pComponentPrivate->cbInfo.EventHandler (pHandle,
   1107                                                 pHandle->pApplicationPrivate,
   1108                                                 OMX_EventError,
   1109                                                 eError,
   1110                                                 OMX_TI_ErrorSevere,
   1111                                                 NULL);
   1112                             goto EXIT;
   1113                         }
   1114                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Algcontrol has been sent to DSP\n",__LINE__);
   1115 
   1116                         eError = LCML_ControlCodec( ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1117                                                        EMMCodecControlStart,(void *)pArgs);
   1118                         if(eError != OMX_ErrorNone)
   1119                         {
   1120                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec Start..\n", __LINE__);
   1121                             pComponentPrivate->cbInfo.EventHandler (pHandle,
   1122                                                 pHandle->pApplicationPrivate,
   1123                                                 OMX_EventError,
   1124                                                 eError,
   1125                                                 OMX_TI_ErrorSevere,
   1126                                                 NULL);
   1127                             goto EXIT;
   1128                         }
   1129                 }
   1130                 else if (pComponentPrivate->curState == OMX_StatePause)
   1131                 {
   1132                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1133                                                   EMMCodecControlStart, (void *)pArgs);
   1134                     if (eError != OMX_ErrorNone)
   1135                     {
   1136                         OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: While Resuming the codec\n",__LINE__);
   1137                         pComponentPrivate->cbInfo.EventHandler (pHandle,
   1138                                                 pHandle->pApplicationPrivate,
   1139                                                 OMX_EventError,
   1140                                                 eError,
   1141                                                 OMX_TI_ErrorSevere,
   1142                                                 NULL);
   1143                         goto EXIT;
   1144                     }
   1145                     for (i=0; i < pComponentPrivate->nNumInputBufPending; i++)
   1146                     {
   1147                         if (pComponentPrivate->pInputBufHdrPending[i]!= NULL)
   1148                         {
   1149                             OMX_PRINT2(pComponentPrivate->dbg, "i: %d \n",(int)i);
   1150                                 AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
   1151                                 AACENC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__);
   1152 
   1153                                 eError = LCML_QueueBuffer(
   1154                                             ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1155                                             EMMCodecInputBuffer,
   1156                                             pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
   1157                                             pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
   1158                                             pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
   1159                                             (OMX_U8 *) pLcmlHdr->pIpParam,
   1160                                             sizeof(AACENC_UAlgInBufParamStruct),
   1161                                             NULL);
   1162                                if(eError != OMX_ErrorNone){
   1163                                    OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
   1164                                    pComponentPrivate->cbInfo.EventHandler (pHandle,
   1165                                                 pHandle->pApplicationPrivate,
   1166                                                 OMX_EventError,
   1167                                                 eError,
   1168                                                 OMX_TI_ErrorSevere,
   1169                                                 NULL);
   1170                                    goto EXIT;
   1171                                }
   1172                         }
   1173                     }
   1174                     pComponentPrivate->nNumInputBufPending =0;
   1175 
   1176                     for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++)
   1177                     {
   1178 
   1179 
   1180                             if (pComponentPrivate->pOutputBufHdrPending[i]!= NULL)
   1181                             {
   1182                                 AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
   1183                                 AACENC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput,__LINE__);
   1184 
   1185 
   1186                                 eError = LCML_QueueBuffer(
   1187                                              ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1188                                              EMMCodecOuputBuffer,
   1189                                              pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
   1190                                              pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
   1191                                              0,
   1192                                              (OMX_U8 *) pLcmlHdr->pOpParam,
   1193                                              sizeof(AACENC_UAlgOutBufParamStruct),
   1194                                              NULL);
   1195                                 if(eError != OMX_ErrorNone){
   1196                                    OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
   1197                                    pComponentPrivate->cbInfo.EventHandler (pHandle,
   1198                                                 pHandle->pApplicationPrivate,
   1199                                                 OMX_EventError,
   1200                                                 eError,
   1201                                                 OMX_TI_ErrorSevere,
   1202                                                 NULL);
   1203                                    goto EXIT;
   1204                                }
   1205                             }
   1206                     }
   1207                     pComponentPrivate->nNumOutputBufPending = 0;
   1208 
   1209 
   1210                 }
   1211                 else
   1212                 {
   1213                     pComponentPrivate->cbInfo.EventHandler(pHandle,
   1214                                                            pHandle->pApplicationPrivate,
   1215                                                            OMX_EventError,
   1216                                                            OMX_ErrorIncorrectStateTransition,
   1217                                                            OMX_TI_ErrorMinor,
   1218                                                            "Invalid State Error");
   1219                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
   1220                     goto EXIT;
   1221                 }
   1222 
   1223 #ifdef RESOURCE_MANAGER_ENABLED
   1224                 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateExecuting, 3456, NULL);
   1225 
   1226 #endif
   1227 
   1228                 pComponentPrivate->curState = OMX_StateExecuting;
   1229 
   1230 #ifdef __PERF_INSTRUMENTATION__
   1231                 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState);
   1232 #endif
   1233 
   1234                 /* Decrement reference count with signal enabled */
   1235                 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
   1236                      return OMX_ErrorUndefined;
   1237                 }
   1238 
   1239                 /*Send state change notificaiton to Application */
   1240                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1241                                                        pHandle->pApplicationPrivate,
   1242                                                        OMX_EventCmdComplete,
   1243                                                        OMX_CommandStateSet,
   1244                                                        pComponentPrivate->curState,
   1245                                                        NULL);
   1246                 break;
   1247 
   1248 
   1249                 case OMX_StateLoaded:
   1250                         OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: AACENCHandleCommand: Cmd Loaded - curState = %d\n",__LINE__,pComponentPrivate->curState);
   1251                         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pInputBufferList->numBuffers);
   1252                         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
   1253                         if (pComponentPrivate->curState == OMX_StateWaitForResources)
   1254                         {
   1255                             OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
   1256 
   1257 #ifdef __PERF_INSTRUMENTATION__
   1258                             PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
   1259 #endif
   1260                             pComponentPrivate->curState = OMX_StateLoaded;
   1261 
   1262 #ifdef __PERF_INSTRUMENTATION__
   1263                             PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
   1264 #endif
   1265 
   1266                             /* Decrement reference count with signal enabled */
   1267                             if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
   1268                                 return OMX_ErrorUndefined;
   1269                             }
   1270 
   1271                             pComponentPrivate->cbInfo.EventHandler(pHandle,
   1272                                                                    pHandle->pApplicationPrivate,
   1273                                                                    OMX_EventCmdComplete,
   1274                                                                    OMX_CommandStateSet,
   1275                                                                    pComponentPrivate->curState,
   1276                                                                    NULL);
   1277                             pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
   1278                             break;
   1279                         }
   1280                         OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AACENC: Inside OMX_StateLoaded State: \n",__LINE__);
   1281                         if (pComponentPrivate->curState != OMX_StateIdle &&
   1282                             pComponentPrivate->curState != OMX_StateWaitForResources)
   1283                         {
   1284                             pComponentPrivate->cbInfo.EventHandler(pHandle,
   1285                                                                    pHandle->pApplicationPrivate,
   1286                                                                    OMX_EventError,
   1287                                                                    OMX_ErrorIncorrectStateTransition,
   1288                                                                    OMX_TI_ErrorMinor,
   1289                                                                    "Incorrect State Transition");
   1290                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
   1291                             goto EXIT;
   1292                         }
   1293 
   1294 #ifdef __PERF_INSTRUMENTATION__
   1295                         PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
   1296 #endif
   1297                         OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",pComponentPrivate->pInputBufferList->numBuffers);
   1298                         OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",pComponentPrivate->pOutputBufferList->numBuffers);
   1299 
   1300                         if (pComponentPrivate->pInputBufferList->numBuffers ||
   1301                             pComponentPrivate->pOutputBufferList->numBuffers)
   1302                         {
   1303                             pComponentPrivate->InIdle_goingtoloaded = 1;
   1304 
   1305 #ifndef UNDER_CE
   1306                             pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
   1307                             pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex);
   1308                             pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
   1309 
   1310 #else
   1311                             OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
   1312 #endif
   1313                         }
   1314 
   1315                         /* Now Deinitialize the component No error should be returned from this function. It should clean the system as much as possible */
   1316                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: Before CodecControlDestroy \n",__LINE__);
   1317                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1318                                                      EMMCodecControlDestroy, (void *)pArgs);
   1319 #ifdef __PERF_INSTRUMENTATION__
   1320                         PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
   1321 #endif
   1322 
   1323                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After CodecControlDestroy \n",__LINE__);
   1324                         if (eError != OMX_ErrorNone)
   1325                         {
   1326                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlDestroy: no.  %x\n",__LINE__, eError);
   1327                             goto EXIT;
   1328                         }
   1329                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
   1330 #ifndef UNDER_CE
   1331                         /*Closing LCML Lib*/
   1332                         /* This flag is used in Deinit()  function to close LCML. */
   1333                         pComponentPrivate->bCodecDestroyed = OMX_TRUE;
   1334                         if (pComponentPrivate->ptrLibLCML != NULL)
   1335                         {
   1336                             OMX_PRDSP1(pComponentPrivate->dbg, "AAC: About to Close LCML %p \n",pComponentPrivate->ptrLibLCML);
   1337                             OMX_PRDSP1(pComponentPrivate->dbg, "AAC: Closed LCML \n");
   1338                             dlclose( pComponentPrivate->ptrLibLCML  );
   1339                             pComponentPrivate->ptrLibLCML = NULL;
   1340                             OMX_PRDSP1(pComponentPrivate->dbg, "AAC: Closed LCML \n");
   1341 
   1342                         }
   1343 #endif
   1344                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After CodecControlDestroy \n",__LINE__);
   1345                         if (eError != OMX_ErrorNone)
   1346                         {
   1347                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlDestroy: no.  %x\n",__LINE__, eError);
   1348                             goto EXIT;
   1349                         }
   1350                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd Loaded\n",__LINE__);
   1351                         eError = EXIT_COMPONENT_THRD;
   1352                         /* Send StateChangeNotification to application */
   1353                         break;
   1354 
   1355 
   1356                 case OMX_StatePause:
   1357                         if (pComponentPrivate->curState != OMX_StateExecuting &&
   1358                             pComponentPrivate->curState != OMX_StateIdle)
   1359                         {
   1360                             pComponentPrivate->cbInfo.EventHandler(pHandle,
   1361                                                                    pHandle->pApplicationPrivate,
   1362                                                                    OMX_EventError,
   1363                                                                    OMX_ErrorIncorrectStateTransition,
   1364                                                                    OMX_TI_ErrorMinor,
   1365                                                                    "Incorrect State Transition");
   1366                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application\n",__LINE__);
   1367                             goto EXIT;
   1368                         }
   1369                         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: about to call LCML_ControlCodec for PAUSE \n",__LINE__);
   1370                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlPause, (void *)pArgs);
   1371                         if (eError != OMX_ErrorNone)
   1372                         {
   1373                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: in Pausing the codec\n",__LINE__);
   1374                             goto EXIT;
   1375                         }
   1376 #ifdef __PERF_INSTRUMENTATION__
   1377                         PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1378 #endif
   1379                         break;
   1380 
   1381 
   1382                 case OMX_StateWaitForResources:
   1383                         if (pComponentPrivate->curState == OMX_StateLoaded)
   1384                         {
   1385 
   1386 #ifdef RESOURCE_MANAGER_ENABLED
   1387             rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_AAC_Encoder_COMPONENT, OMX_StateWaitForResources, 3456, NULL);
   1388 #endif
   1389 
   1390                             pComponentPrivate->curState = OMX_StateWaitForResources;
   1391                             pComponentPrivate->cbInfo.EventHandler(pHandle,
   1392                                                                    pHandle->pApplicationPrivate,
   1393                                                                    OMX_EventCmdComplete,
   1394                                                                    OMX_CommandStateSet,
   1395                                                                    pComponentPrivate->curState,
   1396                                                                    NULL);
   1397                         }
   1398                         else
   1399                         {
   1400                             pComponentPrivate->cbInfo.EventHandler(pHandle,
   1401                                                                    pHandle->pApplicationPrivate,
   1402                                                                    OMX_EventError,
   1403                                                                    OMX_ErrorIncorrectStateTransition,
   1404                                                                    OMX_TI_ErrorMinor,
   1405                                                                    "Incorrect State Transition");
   1406                         }
   1407                         break;
   1408 
   1409 
   1410                 case OMX_StateInvalid:
   1411                          OMX_PRSTATE2(pComponentPrivate->dbg, "%d: HandleCommand: Cmd OMX_StateInvalid:\n",__LINE__);
   1412                          if (pComponentPrivate->curState != OMX_StateWaitForResources &&
   1413                              pComponentPrivate->curState != OMX_StateInvalid &&
   1414                              pComponentPrivate->curState != OMX_StateLoaded)
   1415                          {
   1416                              eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1417                                                          EMMCodecControlDestroy, (void *)pArgs);
   1418                          }
   1419 
   1420                          pComponentPrivate->curState = OMX_StateInvalid;
   1421                          pComponentPrivate->cbInfo.EventHandler( pHandle,
   1422                                                                  pHandle->pApplicationPrivate,
   1423                                                                  OMX_EventError,
   1424                                                                  OMX_ErrorInvalidState,
   1425                                                                  OMX_TI_ErrorSevere,
   1426                                                                  NULL);
   1427 
   1428                          AACENC_CleanupInitParams(pHandle);
   1429                          break;
   1430 
   1431                 case OMX_StateMax:
   1432                          OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENCHandleCommand: Cmd OMX_StateMax::\n",__LINE__);
   1433                          break;
   1434             } /* End of Switch */
   1435         }
   1436     }
   1437 
   1438 
   1439     else if (command == OMX_CommandMarkBuffer)
   1440     {
   1441         OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: command OMX_CommandMarkBuffer received %d\n",__LINE__);
   1442         if(!pComponentPrivate->pMarkBuf)
   1443         {
   1444             OMX_PRDSP1(pComponentPrivate->dbg, "AACENC: command OMX_CommandMarkBuffer received %d\n",__LINE__);
   1445             /* TODO Need to handle multiple marks */
   1446             pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
   1447         }
   1448     }
   1449     else if (command == OMX_CommandPortDisable)
   1450     {
   1451         if (!pComponentPrivate->bDisableCommandPending)
   1452         {
   1453             if(commandData == 0x0 || commandData == -1)
   1454             {
   1455                 /* disable port */
   1456                 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_FALSE;
   1457             }
   1458             if(commandData == 0x1 || commandData == -1)
   1459             {
   1460                 char *pArgs = "damedesuStr";
   1461                 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_FALSE;
   1462 
   1463                 if (pComponentPrivate->curState == OMX_StateExecuting)
   1464                 {
   1465                     pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
   1466                     OMX_PRINT2(pComponentPrivate->dbg, "AACENC: About to stop socket node line %d\n",__LINE__);
   1467 
   1468                     pComponentPrivate->bIsStopping = 1;
   1469                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1470                                                   MMCodecControlStop,(void *)pArgs);
   1471                     pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
   1472                     while (pComponentPrivate->codecStop_waitingsignal == 0){
   1473                         pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
   1474                     }
   1475                     pComponentPrivate->codecStop_waitingsignal = 0;
   1476                     pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
   1477                 }
   1478             }
   1479         }
   1480 
   1481         if(commandData == 0x0)
   1482         {
   1483             if(!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
   1484             {
   1485                 /* return cmdcomplete event if input unpopulated */
   1486                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1487                                                         pHandle->pApplicationPrivate,
   1488                                                         OMX_EventCmdComplete,
   1489                                                         OMX_CommandPortDisable,INPUT_PORT, NULL);
   1490                 pComponentPrivate->bDisableCommandPending = 0;
   1491             }
   1492             else
   1493             {
   1494                 pComponentPrivate->bDisableCommandPending = 1;
   1495                 pComponentPrivate->bDisableCommandParam = commandData;
   1496             }
   1497         }
   1498 
   1499         if(commandData == 0x1)
   1500         {
   1501             if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
   1502             {
   1503                 /* return cmdcomplete event if output unpopulated */
   1504                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1505                                                         pHandle->pApplicationPrivate,
   1506                                                         OMX_EventCmdComplete,
   1507                                                         OMX_CommandPortDisable,OUTPUT_PORT, NULL);
   1508                 pComponentPrivate->bDisableCommandPending = 0;
   1509             }
   1510             else
   1511             {
   1512                 pComponentPrivate->bDisableCommandPending = 1;
   1513                 pComponentPrivate->bDisableCommandParam = commandData;
   1514             }
   1515         }
   1516 
   1517         if(commandData == -1)
   1518         {
   1519             if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
   1520                 !pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
   1521             {
   1522 
   1523                 /* return cmdcomplete event if input & output unpopulated */
   1524                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1525                                                         pHandle->pApplicationPrivate,
   1526                                                         OMX_EventCmdComplete,
   1527                                                         OMX_CommandPortDisable,INPUT_PORT, NULL);
   1528 
   1529                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1530                                                         pHandle->pApplicationPrivate,
   1531                                                         OMX_EventCmdComplete,
   1532                                                         OMX_CommandPortDisable,OUTPUT_PORT, NULL);
   1533                 pComponentPrivate->bDisableCommandPending = 0;
   1534             }
   1535             else
   1536             {
   1537                 pComponentPrivate->bDisableCommandPending = 1;
   1538                 pComponentPrivate->bDisableCommandParam = commandData;
   1539             }
   1540         }
   1541     }
   1542 
   1543     else if (command == OMX_CommandPortEnable)
   1544     {
   1545         if (!pComponentPrivate->bEnableCommandPending)
   1546         {
   1547             if(commandData == 0x0 || commandData == -1)
   1548             {
   1549                 /* enable in port */
   1550                 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: setting input port to enabled\n");
   1551                 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_TRUE;
   1552                 OMX_PRCOMM2(pComponentPrivate->dbg, "WAKE UP!! HandleCommand: In utils setting output port to enabled. \n");
   1553                 if(pComponentPrivate->AlloBuf_waitingsignal)
   1554                 {
   1555                      pComponentPrivate->AlloBuf_waitingsignal = 0;
   1556                 }
   1557                 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
   1558 
   1559             }
   1560             if(commandData == 0x1 || commandData == -1)
   1561             {
   1562                 /* enable out port */
   1563                 if(pComponentPrivate->AlloBuf_waitingsignal)
   1564                 {
   1565                      pComponentPrivate->AlloBuf_waitingsignal = 0;
   1566 #ifndef UNDER_CE
   1567                      pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1568                      pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1569                      pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1570 #else
   1571                      OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
   1572 #endif
   1573                 }
   1574                 if (pComponentPrivate->curState == OMX_StateExecuting)
   1575                 {
   1576                     char *pArgs = "damedesuStr";
   1577                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
   1578 
   1579                     OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: About to start socket node line %d\n",__LINE__);
   1580                     eError = LCML_ControlCodec( ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1581                                                    EMMCodecControlStart,(void *)pArgs);
   1582                 }
   1583                 OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: setting output port to enabled\n");
   1584                 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_TRUE;
   1585                 OMX_PRCOMM1(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
   1586             }
   1587         }
   1588 
   1589         if(commandData == 0x0)
   1590         {
   1591             if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
   1592             {
   1593                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1594                                                        pHandle->pApplicationPrivate,
   1595                                                        OMX_EventCmdComplete,
   1596                                                        OMX_CommandPortEnable,
   1597                                                        INPUT_PORT,
   1598                                                        NULL);
   1599                 pComponentPrivate->bEnableCommandPending = 0;
   1600             }
   1601             else
   1602             {
   1603                 pComponentPrivate->bEnableCommandPending = 1;
   1604                 pComponentPrivate->nEnableCommandParam = commandData;
   1605             }
   1606         }
   1607 
   1608         else if(commandData == 0x1)
   1609         {
   1610             if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
   1611             {
   1612                 pComponentPrivate->cbInfo.EventHandler( pHandle,
   1613                                                         pHandle->pApplicationPrivate,
   1614                                                         OMX_EventCmdComplete,
   1615                                                         OMX_CommandPortEnable,
   1616                                                         OUTPUT_PORT,
   1617                                                         NULL);
   1618                 pComponentPrivate->bEnableCommandPending = 0;
   1619             }
   1620             else
   1621             {
   1622                 pComponentPrivate->bEnableCommandPending = 1;
   1623                 pComponentPrivate->nEnableCommandParam = commandData;
   1624             }
   1625         }
   1626 
   1627         else if(commandData == -1)
   1628         {
   1629             if (pComponentPrivate->curState == OMX_StateLoaded ||
   1630                 (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated
   1631                 && pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated))
   1632             {
   1633                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1634                                                        pHandle->pApplicationPrivate,
   1635                                                        OMX_EventCmdComplete,
   1636                                                        OMX_CommandPortEnable,
   1637                                                        INPUT_PORT,
   1638                                                        NULL);
   1639                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   1640                                                        pHandle->pApplicationPrivate,
   1641                                                        OMX_EventCmdComplete,
   1642                                                        OMX_CommandPortEnable,
   1643                                                        OUTPUT_PORT,
   1644                                                        NULL);
   1645                 pComponentPrivate->bEnableCommandPending = 0;
   1646                 AACENCFill_LCMLInitParamsEx(pHandle);
   1647                 OMX_PRDSP1(pComponentPrivate->dbg, "\nAACENC: calling fillexparams \n");
   1648             }
   1649             else
   1650             {
   1651                 pComponentPrivate->bEnableCommandPending = 1;
   1652                 pComponentPrivate->nEnableCommandParam = commandData;
   1653             }
   1654         }
   1655 
   1656 #ifndef UNDER_CE
   1657                      pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
   1658                      pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
   1659                      pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
   1660 #else
   1661                      OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
   1662 #endif
   1663 
   1664     }
   1665 
   1666 
   1667     else if (command == OMX_CommandFlush)
   1668     {
   1669 
   1670 #if 0
   1671         /*-------------- MANUAL FLUSH ----------------------------*/
   1672 
   1673         if(commandData == 0x0 || commandData == -1)
   1674         {
   1675             if(pComponentPrivate->nUnhandledEmptyThisBuffers ==0) {
   1676 
   1677                  OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
   1678                  pComponentPrivate->nOutStandingEmptyDones = 0;
   1679                  for (i=0; i < MAX_NUM_OF_BUFS; i++)
   1680                  {
   1681                     pComponentPrivate->pInputBufHdrPending[i] = NULL;
   1682                  }
   1683                  pComponentPrivate->nNumInputBufPending=0;
   1684                  for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
   1685                  {
   1686 
   1687                     pComponentPrivate->cbInfo.EmptyBufferDone (
   1688                                    pComponentPrivate->pHandle,
   1689                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1690                                    pComponentPrivate->pInputBufferList->pBufHdr[i]
   1691                                    );
   1692                  }
   1693                  pComponentPrivate->cbInfo.EventHandler(pHandle,
   1694                                                           pHandle->pApplicationPrivate,
   1695                                                           OMX_EventCmdComplete,
   1696                                                           OMX_CommandFlush,INPUT_PORT, NULL);
   1697                 }
   1698             else{
   1699                 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
   1700             }
   1701         }
   1702 
   1703         if(commandData == 0x1 || commandData == -1)
   1704         {
   1705             if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
   1706                  OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: Flushing output port \n",__LINE__);
   1707                  pComponentPrivate->nOutStandingFillDones = 0;
   1708                  for (i=0; i < MAX_NUM_OF_BUFS; i++)
   1709                  {
   1710                     pComponentPrivate->pOutputBufHdrPending[i] = NULL;
   1711                  }
   1712                  pComponentPrivate->nNumOutputBufPending=0;
   1713                  for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
   1714                  {
   1715 
   1716                     pComponentPrivate->cbInfo.FillBufferDone (
   1717                                    pComponentPrivate->pHandle,
   1718                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1719                                    pComponentPrivate->pOutputBufferList->pBufHdr[i]
   1720                                    );
   1721                  }
   1722                  pComponentPrivate->cbInfo.EventHandler(
   1723                                  pHandle, pHandle->pApplicationPrivate,
   1724                                  OMX_EventCmdComplete, OMX_CommandFlush,OUTPUT_PORT, NULL);
   1725             }
   1726             else{
   1727                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
   1728             }
   1729         }
   1730 #else
   1731 
   1732         OMX_U32 aParam[3] = {0};
   1733         if (pComponentPrivate->nNumInputBufPending)
   1734         {
   1735 
   1736             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Inside OMX_CommandFlush Command \n",__LINE__);
   1737             if(commandData == 0x0 || commandData == -1)
   1738             {
   1739                 if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0)  {
   1740                     pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
   1741                     pComponentPrivate->nOutStandingFillDones = 0;
   1742                     aParam[0] = USN_STRMCMD_FLUSH;
   1743                     aParam[1] = 0x0;
   1744                     aParam[2] = 0x0;
   1745                     OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing input port \n",__LINE__);
   1746                     eError=LCML_ControlCodec(( (LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl,(void*)aParam);
   1747                     if (eError != OMX_ErrorNone)
   1748                     {
   1749                          goto EXIT;
   1750                     }
   1751             }
   1752                 else {
   1753                     pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
   1754                     }
   1755             }
   1756         }
   1757         else
   1758         {
   1759              OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
   1760              pComponentPrivate->nOutStandingEmptyDones = 0;
   1761              for (i=0; i < MAX_NUM_OF_BUFS; i++)
   1762              {
   1763                 pComponentPrivate->pInputBufHdrPending[i] = NULL;
   1764              }
   1765              pComponentPrivate->nNumInputBufPending=0;
   1766              for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
   1767              {
   1768 
   1769                 pComponentPrivate->cbInfo.EmptyBufferDone (
   1770                                pComponentPrivate->pHandle,
   1771                                pComponentPrivate->pHandle->pApplicationPrivate,
   1772                                pComponentPrivate->pInputBufferList->pBufHdr[i]
   1773                                );
   1774                 AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
   1775                 SignalIfAllBuffersAreReturned(pComponentPrivate);
   1776              }
   1777              pComponentPrivate->cbInfo.EventHandler(pHandle,
   1778                                                     pHandle->pApplicationPrivate,
   1779                                                     OMX_EventCmdComplete,
   1780                                                     OMX_CommandFlush,INPUT_PORT, NULL);
   1781 
   1782         }
   1783 
   1784 
   1785 
   1786         if (pComponentPrivate->nNumOutputBufPending)
   1787         {
   1788             if(commandData == 0x1 || commandData == -1)
   1789             {
   1790                 if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
   1791                     pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
   1792                     pComponentPrivate->nOutStandingEmptyDones=0;
   1793                     OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing ouput queue \n",__LINE__);
   1794                     aParam[0] = USN_STRMCMD_FLUSH;
   1795                     aParam[1] = 0x1;
   1796                     aParam[2] = 0x0;
   1797 
   1798                     OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENCHandleCommand::Flushing ouput port  \n",__LINE__);
   1799                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
   1800                     if (eError != OMX_ErrorNone)
   1801                     {
   1802                         goto EXIT;
   1803                     }
   1804             }
   1805                 else {
   1806                     pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
   1807                 }
   1808             }
   1809         }
   1810         else
   1811         {
   1812             OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: Flushing output port \n",__LINE__);
   1813             pComponentPrivate->nOutStandingFillDones = 0;
   1814             for (i=0; i < MAX_NUM_OF_BUFS; i++)
   1815             {
   1816                 pComponentPrivate->pOutputBufHdrPending[i] = NULL;
   1817             }
   1818             pComponentPrivate->nNumOutputBufPending=0;
   1819             for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
   1820             {
   1821 
   1822                  pComponentPrivate->cbInfo.FillBufferDone (
   1823                                   pComponentPrivate->pHandle,
   1824                                   pComponentPrivate->pHandle->pApplicationPrivate,
   1825                                   pComponentPrivate->pOutputBufferList->pBufHdr[i]
   1826                                   );
   1827                  AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
   1828                  SignalIfAllBuffersAreReturned(pComponentPrivate);
   1829             }
   1830             pComponentPrivate->cbInfo.EventHandler( pHandle,
   1831                                                     pHandle->pApplicationPrivate,
   1832                                                     OMX_EventCmdComplete,
   1833                                                     OMX_CommandFlush,OUTPUT_PORT, NULL);
   1834         }
   1835 #endif
   1836 
   1837     }
   1838 
   1839 EXIT:
   1840     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting AACENCHandleCommand Function\n",__LINE__);
   1841     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning %d\n",__LINE__,eError);
   1842     /* report the error to the client via event */
   1843     if(eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD){
   1844         OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
   1845         pComponentPrivate->cbInfo.EventHandler (pHandle,
   1846                                                 pHandle->pApplicationPrivate,
   1847                                                 OMX_EventError,
   1848                                                 eError,
   1849                                                 OMX_TI_ErrorSevere,
   1850                                                 NULL);
   1851 
   1852     }
   1853     return eError;
   1854 }
   1855 
   1856 
   1857 /* ========================================================================== */
   1858 /**
   1859 * AACENCHandleDataBuf_FromApp() This function is called by the component when ever it
   1860 * receives the buffer from the application
   1861 *
   1862 * @param pComponentPrivate  Component private data
   1863 * @param pBufHeader Buffer from the application
   1864 *
   1865 * @pre
   1866 *
   1867 * @post
   1868 *
   1869 * @return none
   1870 */
   1871 /* ========================================================================== */
   1872 OMX_ERRORTYPE AACENCHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader, AACENC_COMPONENT_PRIVATE *pComponentPrivate)
   1873 {
   1874     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1875     OMX_DIRTYPE eDir = 0;
   1876     LCML_AACENC_BUFHEADERTYPE *pLcmlHdr = NULL;
   1877     LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
   1878     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1879 
   1880     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCHandleDataBuf_FromApp - curState = %d\n",__LINE__,pComponentPrivate->curState);
   1881 
   1882     /*Find the direction of the received buffer from buffer list*/
   1883     eError = AACENCGetBufferDirection(pBufHeader, &eDir);
   1884     if (eError != OMX_ErrorNone)
   1885     {
   1886         OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: The pBufHeader is not found in the list\n",__LINE__);
   1887         goto EXIT;
   1888     }
   1889 
   1890     if (eDir == OMX_DirInput)
   1891     {
   1892         pComponentPrivate->nUnhandledEmptyThisBuffers--;
   1893         OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL:  Buffer Dir = input\n",__LINE__);
   1894         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
   1895         if ((pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS))
   1896         {
   1897             pComponentPrivate->bBypassDSP = 0;          /* flag for buffers with data */
   1898             eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr);
   1899             if (eError != OMX_ErrorNone)
   1900             {
   1901                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Error: Invalid INPUT Buffer Came ...\n",__LINE__);
   1902                 goto EXIT;
   1903             }
   1904             pLcmlHdr->pIpParam->bLastBuffer = 0;        /* it is not the last buffer yet  */
   1905 
   1906 #ifdef __PERF_INSTRUMENTATION__
   1907             /*For Steady State Instumentation*/
   1908     #if 0
   1909             if ((pComponentPrivate->nLcml_nCntIp == 1)) {
   1910                     PERF_Boundary(pComponentPrivate->pPERFcomp,
   1911                                   PERF_BoundaryStart | PERF_BoundarySteadyState);
   1912             }
   1913     #endif
   1914             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1915                               PREF(pBufHeader,pBuffer),
   1916                               pPortDefIn->nBufferSize,
   1917                               PERF_ModuleCommonLayer);
   1918 #endif
   1919 
   1920             if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)
   1921             {
   1922                 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: UTIL: End of Stream has been reached \n",__LINE__);
   1923                 pLcmlHdr->pIpParam->bLastBuffer   = 1;  /* EOS flag for SN. - It is the last buffer with data for SN */
   1924                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pLcmlHdr->pIpParam->bLastBuffer = %d \n",__LINE__,(int)pLcmlHdr->pIpParam->bLastBuffer);
   1925             }
   1926 
   1927             /* Store time stamp information */
   1928             pComponentPrivate->timestampBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
   1929             pComponentPrivate->tickcountBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
   1930             pComponentPrivate->IpBufindex++;
   1931             pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual;
   1932 
   1933             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending input buffer header to Codec = %p to LCML\n",__LINE__,pBufHeader);
   1934             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending INPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer);
   1935             OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   1936             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
   1937 
   1938             if (pComponentPrivate->curState == OMX_StateExecuting)
   1939             {
   1940                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] The current state while sending the buffer = %d \n",__LINE__,pComponentPrivate->curState);
   1941                 if(!pComponentPrivate->bDspStoppedWhileExecuting)
   1942                 {
   1943                     if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput))
   1944                     {
   1945                         AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
   1946                         eError = LCML_QueueBuffer(  pLcmlHandle->pCodecinterfacehandle,
   1947                                                     EMMCodecInputBuffer,
   1948                                                    (OMX_U8 *)pBufHeader->pBuffer,
   1949                                                     pBufHeader->nAllocLen,
   1950                                                     pBufHeader->nFilledLen,
   1951                                                     (OMX_U8 *)pLcmlHdr->pIpParam,
   1952                                                     sizeof(AACENC_UAlgInBufParamStruct),
   1953                                                     NULL);
   1954                         if (eError != OMX_ErrorNone)
   1955                         {
   1956                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: SetBuff: IP: Error Occurred\n",__LINE__);
   1957                             eError = OMX_ErrorHardware;
   1958                             goto EXIT;
   1959                         }
   1960                         pComponentPrivate->lcml_nIpBuf++;
   1961                         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL:  [HandleData_FromApp] lcml_nIpBuf count :  %d\n",__LINE__, (int)pComponentPrivate->lcml_nIpBuf);
   1962                     }
   1963                 }
   1964                 else
   1965                 {
   1966 #ifdef __PERF_INSTRUMENTATION__
   1967                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1968                                       PREF(pBufHeader, pBuffer),
   1969                                       0,
   1970                                       PERF_ModuleHLMM);
   1971 #endif
   1972                     pComponentPrivate->cbInfo.EmptyBufferDone (
   1973                                                pComponentPrivate->pHandle,
   1974                                                pComponentPrivate->pHandle->pApplicationPrivate,
   1975                                                pBufHeader
   1976                                                );
   1977                     pComponentPrivate->nOutStandingEmptyDones--;
   1978                     AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
   1979                     SignalIfAllBuffersAreReturned(pComponentPrivate);
   1980                 }
   1981             }
   1982             else
   1983             {
   1984                 /* Save received buffers */
   1985                 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
   1986             }
   1987         }
   1988 
   1989         else
   1990         {
   1991             pComponentPrivate->bBypassDSP = 1;          /* flag :   empty buffer */
   1992             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] setting pComponentPrivate->bBypassDSP = 1 \n", __LINE__);
   1993             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] Calling FillBufferDone\n", __LINE__);
   1994 
   1995 #ifdef __PERF_INSTRUMENTATION__
   1996             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1997                             PREF(pComponentPrivate->pOutputBufferList->pBufHdr[0],pBuffer),
   1998                             PREF(pComponentPrivate->pOutputBufferList->pBufHdr[0],nFilledLen),
   1999                             PERF_ModuleHLMM);
   2000 #endif
   2001 
   2002             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] (filled <0 or EOS )Calling FillBufferDone \n",__LINE__);
   2003             pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
   2004                                        pComponentPrivate->pHandle->pApplicationPrivate,
   2005                                        pComponentPrivate->pOutputBufferList->pBufHdr[0]
   2006                                        );
   2007             pComponentPrivate->nOutStandingFillDones--;
   2008             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
   2009             SignalIfAllBuffersAreReturned(pComponentPrivate);
   2010             OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->FillbufferdoneCount = %ld \n",__LINE__,pComponentPrivate->FillbufferdoneCount);
   2011             OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->FillthisbufferCount = %ld \n",__LINE__,pComponentPrivate->FillthisbufferCount);
   2012 
   2013 
   2014 #ifdef __PERF_INSTRUMENTATION__
   2015             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   2016                             PREF(pComponentPrivate->pInputBufferList->pBufHdr[0], pBuffer),
   2017                             0,
   2018                             PERF_ModuleHLMM);
   2019 #endif
   2020 
   2021             OMX_PRINT1(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] (filled <0 or EOS )Calling EmptyBufferDone \n",__LINE__);
   2022             pComponentPrivate->cbInfo.EmptyBufferDone ( pComponentPrivate->pHandle,
   2023                                        pComponentPrivate->pHandle->pApplicationPrivate,
   2024                                        pComponentPrivate->pInputBufferList->pBufHdr[0]
   2025                                        );
   2026             pComponentPrivate->nOutStandingEmptyDones--;
   2027             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptybufferdoneCount);
   2028             SignalIfAllBuffersAreReturned(pComponentPrivate);
   2029             OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->EmptybufferdoneCount = %ld \n",__LINE__,pComponentPrivate->EmptybufferdoneCount);
   2030             OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->EmptythisbufferCount = %ld \n",__LINE__,pComponentPrivate->EmptythisbufferCount);
   2031         }
   2032 
   2033         if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)
   2034         {
   2035             OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: Component Detected EOS\n",__LINE__);
   2036             if(pComponentPrivate->dasfmode == 0)
   2037             {
   2038                 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
   2039                 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags = %d \n",__LINE__,(int)pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags);
   2040                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2041                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   2042                                                        OMX_EventBufferFlag,
   2043                                                        pComponentPrivate->pOutputBufferList->pBufHdr[0]->nOutputPortIndex,
   2044                                                        pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags, NULL);
   2045 
   2046             }
   2047             pBufHeader->nFlags = 0;
   2048         }
   2049 
   2050         OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   2051         if(pBufHeader->pMarkData)
   2052         {
   2053             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Detected pBufHeader->pMarkData\n",__LINE__);
   2054             /* copy mark to output buffer header */
   2055             OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   2056             pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
   2057             OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   2058             pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
   2059             OMX_PRSTATE2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   2060             /* trigger event handler if we are supposed to */
   2061             if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData)
   2062             {
   2063                 OMX_PRSTATE1(pComponentPrivate->dbg, "UTIL: pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
   2064                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   2065                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   2066                                                        OMX_EventMark,
   2067                                                        0,
   2068                                                        0,
   2069                                                        pBufHeader->pMarkData);
   2070             }
   2071         }
   2072 
   2073         if (pComponentPrivate->bFlushInputPortCommandPending) {
   2074             OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
   2075         }
   2076 
   2077     }
   2078 
   2079 
   2080     else if (eDir == OMX_DirOutput)
   2081     {
   2082         /* Make sure that output buffer is issued to output stream only when
   2083         * there is an outstanding input buffer already issued on input stream
   2084         */
   2085         OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Buffer Dir = output\n",__LINE__);
   2086         OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->bIsStopping = %ld\n",__LINE__, pComponentPrivate->bIsStopping);
   2087         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->bBypassDSP  = %ld\n",__LINE__, pComponentPrivate->bBypassDSP);
   2088         OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   2089 
   2090         pComponentPrivate->nUnhandledFillThisBuffers--;
   2091 
   2092 #ifdef ANDROID
   2093         if (pComponentPrivate->bFirstOutputBuffer){
   2094         // if this is the first output buffer, fill the config data, then return the buffer (skip DSP)
   2095             AACENCWriteConfigHeader(pComponentPrivate, pBufHeader);
   2096                 OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: AACENCWriteConfigHeader = %p\n",__LINE__, pBufHeader->pBuffer);
   2097             pComponentPrivate->cbInfo.FillBufferDone (
   2098                                    pComponentPrivate->pHandle,
   2099                                    pComponentPrivate->pHandle->pApplicationPrivate,
   2100                                    pBufHeader
   2101                                    );
   2102             pComponentPrivate->bFirstOutputBuffer = 0;
   2103             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillbufferdoneCount);
   2104             SignalIfAllBuffersAreReturned(pComponentPrivate);
   2105             goto EXIT;
   2106         }
   2107 #endif
   2108 
   2109         if (!(pComponentPrivate->bIsStopping))
   2110         {
   2111             if (pComponentPrivate->bBypassDSP == 0)
   2112             {
   2113                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Sending Output buffer header to Codec= %p to LCML\n",__LINE__,pBufHeader);
   2114                 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: UTIL: Sending OUTPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer);
   2115 #ifdef __PERF_INSTRUMENTATION__
   2116                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   2117                                  PREF(pBufHeader,pBuffer),
   2118                                   0,
   2119                                   PERF_ModuleCommonLayer);
   2120 #endif
   2121 
   2122                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate = %p\n",__LINE__,pComponentPrivate);
   2123                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader = %p\n",__LINE__,pBufHeader);
   2124                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader->pBuffer = %p\n",__LINE__,pBufHeader->pBuffer);
   2125                 eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
   2126                 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   2127 
   2128                 if (pComponentPrivate->bBypassDSP == 0)
   2129                 {
   2130                     OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   2131                     OMX_PRINT2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
   2132 
   2133                     if (pComponentPrivate->curState == OMX_StateExecuting)
   2134                     {
   2135                         if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput))
   2136                         {
   2137                             AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
   2138                             pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
   2139                             pLcmlHdr->pOpParam->unNumFramesEncoded=0; /* Resetting the value  for each time*/
   2140                             eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   2141                                                       EMMCodecOuputBuffer,
   2142                                                       (OMX_U8 *)pBufHeader->pBuffer,
   2143                                                       pBufHeader->nAllocLen,
   2144                                                       pBufHeader->nFilledLen,
   2145                                                       (OMX_U8 *)pLcmlHdr->pOpParam,
   2146                                                       sizeof(AACENC_UAlgOutBufParamStruct),
   2147                                                       NULL);
   2148                             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Queuing Ouput buffer buffer \n",__LINE__);
   2149                             if (eError != OMX_ErrorNone )
   2150                             {
   2151                                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Issuing DSP OP: Error Occurred\n",__LINE__);
   2152                                 eError = OMX_ErrorHardware;
   2153                                 goto EXIT;
   2154                             }
   2155                             pComponentPrivate->lcml_nOpBuf++;
   2156                             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: tlcml_nOpBuf count : %d\n",__LINE__, (int)pComponentPrivate->lcml_nOpBuf);
   2157                         }
   2158                   }
   2159                   else if (pComponentPrivate->curState == OMX_StatePause)
   2160                   {
   2161                      OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->nNumOutputBufPending++ = %d \n",__LINE__,(int)pComponentPrivate->nNumOutputBufPending++);
   2162                      OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pBufHeader = %p \n",__LINE__, pBufHeader);
   2163                      pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
   2164                   }
   2165                 }
   2166             }
   2167             else
   2168             {
   2169                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp] OMX_DirOutput - bBypassDSP = %d \n", __LINE__, (int)pComponentPrivate->bBypassDSP);
   2170                 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState);
   2171                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: [HandleData_FromApp]pComponentPrivate->bDspStoppedWhileExecuting = %ld\n",__LINE__,pComponentPrivate->bDspStoppedWhileExecuting);
   2172 
   2173                 if (pComponentPrivate->curState == OMX_StateExecuting)
   2174                 {
   2175                     if (!AACENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput))
   2176                     {
   2177                         AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
   2178                         pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
   2179 			if (pLcmlHdr != NULL) {
   2180 			    pLcmlHdr->pOpParam->unNumFramesEncoded = 0; /* Resetting the value  for each time*/
   2181 			}
   2182                         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   2183                                                   EMMCodecOuputBuffer,
   2184                                                   (OMX_U8 *)pBufHeader->pBuffer,
   2185                                                   pBufHeader->nAllocLen,
   2186                                                   pBufHeader->nFilledLen,
   2187                                                   (OMX_U8 *)pLcmlHdr->pOpParam,
   2188                                                   sizeof(AACENC_UAlgOutBufParamStruct),
   2189                                                   NULL);
   2190                         if (eError != OMX_ErrorNone )
   2191                         {
   2192                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Issuing DSP OP: Error Occurred\n",__LINE__);
   2193                             eError = OMX_ErrorHardware;
   2194                             goto EXIT;
   2195                         }
   2196                         pComponentPrivate->lcml_nOpBuf++;
   2197                         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: UTIL: lcml_nOpBuf count : %d\n",__LINE__, (int)pComponentPrivate->lcml_nOpBuf);
   2198                     }
   2199                 }
   2200                 else
   2201                 {
   2202                     pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
   2203                 }
   2204             }
   2205         }
   2206 
   2207         if (pComponentPrivate->bFlushOutputPortCommandPending) {
   2208             OMX_SendCommand( pComponentPrivate->pHandle,
   2209                                   OMX_CommandFlush,
   2210                                   1,NULL);
   2211         }
   2212     }
   2213     else
   2214     {
   2215         OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: BufferHeader  = %p, Buffer  = %p Unknown\n",__LINE__,pBufHeader, pBufHeader->pBuffer);
   2216         eError = OMX_ErrorBadParameter;
   2217     }
   2218 EXIT:
   2219     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL:Exiting from  HandleDataBuf_FromApp ..........>>>>>\n",__LINE__);
   2220     /* report the error to the client via event */
   2221     if(eError != OMX_ErrorNone){
   2222         OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
   2223         pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
   2224                                                 pComponentPrivate->pHandle->pApplicationPrivate,
   2225                                                 OMX_EventError,
   2226                                                 eError,
   2227                                                 OMX_TI_ErrorSevere,
   2228                                                 NULL);
   2229 
   2230     }
   2231     return eError;
   2232 }
   2233 
   2234 /*-------------------------------------------------------------------*/
   2235 /**
   2236 * AACENCGetBufferDirection () This function is used by the component thread to
   2237 * request a buffer from the application.  Since it was called from 2 places,
   2238 * it made sense to turn this into a small function.
   2239 *
   2240 * @param pData pointer to AAC Decoder Context Structure
   2241 * @param pCur pointer to the buffer to be requested to be filled
   2242 *
   2243 * @retval none
   2244 **/
   2245 /*-------------------------------------------------------------------*/
   2246 
   2247 OMX_ERRORTYPE AACENCGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir)
   2248 {
   2249     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2250     AACENC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
   2251     OMX_U32 nBuf=0;
   2252     OMX_BUFFERHEADERTYPE *pBuf = NULL;
   2253     OMX_U32 i=0;
   2254     OMX_S16 flag = 1;
   2255 
   2256     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCGetBufferDirection Function\n",__LINE__);
   2257     /*Search this buffer in input buffers list */
   2258 
   2259     nBuf = pComponentPrivate->pInputBufferList->numBuffers;
   2260     for(i=0; i<nBuf; i++)
   2261     {
   2262         pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
   2263         if(pBufHeader == pBuf)
   2264         {
   2265             *eDir = OMX_DirInput;
   2266             OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is INPUT BUFFER\n",__LINE__, pBufHeader);
   2267             flag = 0;
   2268             goto EXIT;
   2269         }
   2270     }
   2271 
   2272     /*Search this buffer in input buffers list */
   2273     nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   2274 
   2275     for(i=0; i<nBuf; i++)
   2276     {
   2277         pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   2278         if(pBufHeader == pBuf)
   2279         {
   2280             *eDir = OMX_DirOutput;
   2281             OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is OUTPUT BUFFER\n",__LINE__, pBufHeader);
   2282             flag = 0;
   2283             goto EXIT;
   2284         }
   2285     }
   2286 
   2287     if (flag == 1)
   2288     {
   2289         OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: Buffer %p is Not Found in the List\n",__LINE__,pBufHeader);
   2290         eError = OMX_ErrorUndefined;
   2291         goto EXIT;
   2292     }
   2293 EXIT:
   2294     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting AACENCGetBufferDirection Function\n",__LINE__);
   2295     return eError;
   2296 }
   2297 
   2298 /* -------------------------------------------------------------------*/
   2299 /**
   2300   *  AACENCLCML_Callback() function will be called LCML component to write the msg
   2301   *
   2302   * @param event                 Event which gives to details about USN status
   2303   * @param void * args        //    args [0] //bufType;
   2304                               //    args [1] //arm address fpr buffer
   2305                               //    args [2] //BufferSize;
   2306                               //    args [3]  //arm address for param
   2307                               //    args [4] //ParamSize;
   2308                               //    args [6] //LCML Handle
   2309   * @retval OMX_NoError              Success, ready to roll
   2310   *         OMX_Error_BadParameter   The input parameter pointer is null
   2311  **/
   2312 /*-------------------------------------------------------------------*/
   2313 
   2314 OMX_ERRORTYPE AACENCLCML_Callback(TUsnCodecEvent event,void * args [10])
   2315 {
   2316  /*   OMX_S16 ret = 0; */
   2317     OMX_COMPONENTTYPE *pHandle=NULL;
   2318     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2319     OMX_U8 *pBuffer = args[1];
   2320     LCML_AACENC_BUFHEADERTYPE *pLcmlHdr = NULL;;
   2321     LCML_DSP_INTERFACE *pLcmlHandle = NULL;
   2322     AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;
   2323     OMX_S16 i = 0;
   2324     int j =0, k=0 ;
   2325 
   2326 #ifdef RESOURCE_MANAGER_ENABLED
   2327     OMX_ERRORTYPE rm_error = OMX_ErrorNone;
   2328 #endif
   2329 
   2330     pComponentPrivate_CC = (AACENC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE *)args[6])->pComponentPrivate;
   2331     OMX_PRINT1(pComponentPrivate_CC->dbg, "%d:pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate_CC->curState);
   2332 
   2333 pHandle = pComponentPrivate_CC->pHandle;
   2334 
   2335     switch(event) {
   2336 
   2337         case EMMCodecDspError:
   2338             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspError\n");
   2339             break;
   2340 
   2341         case EMMCodecInternalError:
   2342             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecInternalError\n");
   2343             break;
   2344 
   2345         case EMMCodecInitError:
   2346             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecInitError\n");
   2347             break;
   2348 
   2349         case EMMCodecDspMessageRecieved:
   2350             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved\n");
   2351             break;
   2352 
   2353         case EMMCodecBufferProcessed:
   2354             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferProcessed\n");
   2355             break;
   2356 
   2357         case EMMCodecProcessingStarted:
   2358             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStarted\n");
   2359             break;
   2360 
   2361         case EMMCodecProcessingPaused:
   2362             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingPaused\n");
   2363             break;
   2364 
   2365         case EMMCodecProcessingStoped:
   2366             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStoped\n");
   2367             break;
   2368 
   2369         case EMMCodecProcessingEof:
   2370             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingEof\n");
   2371             break;
   2372 
   2373         case EMMCodecBufferNotProcessed:
   2374             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed\n");
   2375             break;
   2376 
   2377         case EMMCodecAlgCtrlAck:
   2378             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck\n");
   2379             break;
   2380 
   2381         case EMMCodecStrmCtrlAck:
   2382             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck\n");
   2383             break;
   2384 
   2385         default:
   2386             OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT]  Got event = %d\n",event);
   2387             break;
   2388     }
   2389 
   2390     OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: Entering the AACENCLCML_Callback Function\n",__LINE__);
   2391     OMX_PRINT2(pComponentPrivate_CC->dbg, "UTIL: args = %p \n",args[0]);
   2392     OMX_PRBUFFER2(pComponentPrivate_CC->dbg, " %d :: UTIL: EMMCodecInputBuffer = %p \n",__LINE__,(void *)EMMCodecInputBuffer);
   2393     OMX_PRBUFFER2(pComponentPrivate_CC->dbg, " %d :: UTIL: EMMCodecOuputBuffer = %p \n",__LINE__,(void *)EMMCodecOuputBuffer);
   2394     OMX_PRINT2(pComponentPrivate_CC->dbg, " %d :: UTIL:Entering the LCML_Callback() : event = %d\n",__LINE__,event);
   2395     OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pHandle:%p \n",__LINE__,pHandle);
   2396     OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pComponentPrivate_CC:%p \n",__LINE__,pComponentPrivate_CC);
   2397     OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr:%p \n",__LINE__,pLcmlHdr);
   2398 /*  OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr->pIpParam:%p \n",__LINE__,pLcmlHdr->pIpParam); */
   2399 
   2400 
   2401     if(event == EMMCodecBufferProcessed)
   2402     {
   2403         OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE EMMCodecBufferProcessed \n",__LINE__);
   2404         if( (OMX_U32)args [0] == EMMCodecInputBuffer)
   2405         {
   2406             OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: Input: pBuffer = %p\n",__LINE__, pBuffer);
   2407             eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate_CC, pBuffer, OMX_DirInput, &pLcmlHdr);
   2408 
   2409 #ifdef __PERF_INSTRUMENTATION__
   2410             PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
   2411                                PREF(pLcmlHdr->buffer,pBuffer),
   2412                                0,
   2413                                PERF_ModuleCommonLayer);
   2414 #endif
   2415 
   2416             AACENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirInput,__LINE__);
   2417             if (eError != OMX_ErrorNone)
   2418             {
   2419                 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: Error: Invalid Buffer Came ...\n",__LINE__);
   2420                 goto EXIT;
   2421             }
   2422             OMX_PRCOMM2(pComponentPrivate_CC->dbg, "Input CallBack %p\n", pLcmlHdr->buffer);
   2423 
   2424         if (pComponentPrivate_CC->curState != OMX_StatePause)
   2425         {
   2426 
   2427 #ifdef __PERF_INSTRUMENTATION__
   2428             PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
   2429                                   PREF(pLcmlHdr->buffer,pBuffer),
   2430                                   0,
   2431                                   PERF_ModuleHLMM);
   2432 #endif
   2433             pComponentPrivate_CC->cbInfo.EmptyBufferDone (pComponentPrivate_CC->pHandle,
   2434                                                        pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2435                                                        pLcmlHdr->buffer);
   2436             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->EmptybufferdoneCount);
   2437             SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
   2438             pComponentPrivate_CC->nOutStandingEmptyDones--;
   2439             pComponentPrivate_CC->lcml_nIpBuf--;
   2440 
   2441         }
   2442         else
   2443         {
   2444             OMX_ERROR4(pComponentPrivate_CC->dbg, "UTIL: Couldn't calling EmptyBufferDone() because pComponentPrivate->curState = %d\n",pComponentPrivate_CC->curState);
   2445             pComponentPrivate_CC->pInBufHdrPausedPending[pComponentPrivate_CC->PendingInPausedBufs++] = pLcmlHdr->buffer;
   2446         }
   2447 
   2448 
   2449             pComponentPrivate_CC->nOutStandingEmptyDones++;
   2450             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: pComponentPrivate->nOutStandingEmptyDones = %ld\n",__LINE__,pComponentPrivate_CC->nOutStandingEmptyDones);
   2451         }
   2452         else if ((OMX_U32)args [0] == EMMCodecOuputBuffer)
   2453         {
   2454             OMX_PRBUFFER1(pComponentPrivate_CC->dbg, "%d :: UTIL: Output: pBuffer = %p\n",__LINE__, pBuffer);
   2455             pComponentPrivate_CC->nOutStandingFillDones++;
   2456             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: Incrementing nOutStandingFillDones = %d\n",__LINE__, (int)pComponentPrivate_CC->nOutStandingFillDones);
   2457             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: pComponentPrivate_CC->nOutStandingFillDones = %ld\n",__LINE__, pComponentPrivate_CC->nOutStandingFillDones);
   2458             eError = AACENCGetCorresponding_LCMLHeader(pComponentPrivate_CC, pBuffer, OMX_DirOutput, &pLcmlHdr);
   2459             AACENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirOutput,__LINE__);
   2460             if (eError != OMX_ErrorNone)
   2461             {
   2462                 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: Error: Invalid Buffer Came ...\n",__LINE__);
   2463                 goto EXIT;
   2464             }
   2465             pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
   2466             OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: pLcmlHdr->buffer->nFilledLen = %ld \n",__LINE__,pLcmlHdr->buffer->nFilledLen);
   2467 
   2468 #ifdef __PERF_INSTRUMENTATION__
   2469             PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
   2470                                PREF(pLcmlHdr->buffer,pBuffer),
   2471                                PREF(pLcmlHdr->buffer,nFilledLen),
   2472                                PERF_ModuleCommonLayer);
   2473             pComponentPrivate_CC->nLcml_nCntOpReceived++;
   2474             if ((pComponentPrivate_CC->nLcml_nCntIp >= 1) && (pComponentPrivate_CC->nLcml_nCntOpReceived == 1))
   2475             {
   2476                 PERF_Boundary(pComponentPrivate_CC->pPERFcomp,
   2477                 PERF_BoundaryStart | PERF_BoundarySteadyState);
   2478             }
   2479 #endif
   2480             pComponentPrivate_CC->LastOutbuf = pLcmlHdr->buffer;    /* back up of processed buffer */
   2481             OMX_PRINT2(pComponentPrivate_CC->dbg, "Output CallBack %p\n", pLcmlHdr->buffer);
   2482             OMX_PRINT2(pComponentPrivate_CC->dbg, "size content  %d\n", (int)pLcmlHdr->buffer->nFilledLen);
   2483 
   2484 /* Previously in HandleDatabuffer form LCML */
   2485 
   2486         /* Copying time stamp information to output buffer */
   2487         pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate_CC->timestampBufIndex[pComponentPrivate_CC->OpBufindex];
   2488         pLcmlHdr->buffer->nTickCount = pComponentPrivate_CC->tickcountBufIndex[pComponentPrivate_CC->OpBufindex];
   2489         pComponentPrivate_CC->OpBufindex++;
   2490         pComponentPrivate_CC->OpBufindex %= pComponentPrivate_CC->pPortDef[OMX_DirOutput]->nBufferCountActual;
   2491 
   2492         if (pComponentPrivate_CC->curState != OMX_StatePause)
   2493         {
   2494 
   2495             OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: Component Sending Filled Output buffer%p to App\n",__LINE__,pLcmlHdr->buffer);
   2496             OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "UTIL:: Calling FillBufferDone from Line %d\n",__LINE__);
   2497 
   2498 #ifdef __PERF_INSTRUMENTATION__
   2499             PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
   2500                                 pLcmlHdr->buffer->pBuffer,
   2501                                 pLcmlHdr->buffer->nFilledLen,
   2502                                 PERF_ModuleHLMM);
   2503 #endif
   2504 
   2505 #ifdef AACENC_DEBUG
   2506             unsigned long TmpNumFrames = pLcmlHdr->pOpParam->unNumFramesEncoded;
   2507             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: Num frames: %lx \n",__LINE__,TmpNumFrames);
   2508 #endif
   2509             for(k=0; k<MPEG4AACENC_MAX_OUTPUT_FRAMES; k++)
   2510             {
   2511                 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d Frame size[%d]: %lx \n",__LINE__,k,pLcmlHdr->pOpParam->unFrameSizes[k]);
   2512             }
   2513             pLcmlHdr->buffer->pOutputPortPrivate=pLcmlHdr->pOpParam;
   2514             pComponentPrivate_CC->cbInfo.FillBufferDone (
   2515                                pHandle,
   2516                                pHandle->pApplicationPrivate,
   2517                                pLcmlHdr->buffer
   2518                                );
   2519             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->FillbufferdoneCount);
   2520             SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
   2521             pComponentPrivate_CC->nOutStandingFillDones--;
   2522             pComponentPrivate_CC->lcml_nOpBuf--;
   2523             }
   2524         else
   2525         {
   2526             OMX_ERROR4(pComponentPrivate_CC->dbg, "UTIL: Couldn't calling fillBufferDone() because pComponentPrivate->curState = %d\n",pComponentPrivate_CC->curState);
   2527             pComponentPrivate_CC->pOutBufHdrPausedPending[pComponentPrivate_CC->PendingOutPausedBufs++] = pLcmlHdr->buffer;
   2528         }
   2529 
   2530 
   2531         }
   2532     }
   2533 
   2534 
   2535     else if (event == EMMCodecStrmCtrlAck)
   2536     {
   2537           OMX_PRDSP1(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE USN_DSPACK_STRMCTRL \n",__LINE__);
   2538           if (args[1] == (void *)USN_STRMCMD_FLUSH)
   2539           {
   2540                  pHandle = pComponentPrivate_CC->pHandle;
   2541                  if ( args[2] == (void *)EMMCodecInputBuffer)
   2542                  {
   2543                      if (args[0] == (void*)USN_ERR_NONE )
   2544                      {
   2545                          OMX_PRCOMM1(pComponentPrivate_CC->dbg, "%d :: UTIL: Flushing input port \n",__LINE__);
   2546                          for (i=0; i < pComponentPrivate_CC->nNumInputBufPending; i++) {
   2547 #ifdef __PERF_INSTRUMENTATION__
   2548                             PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
   2549                                               PREF(pComponentPrivate_CC->pInputBufferList->pBufHdr[i],pBuffer),
   2550                                               0,PERF_ModuleHLMM);
   2551 #endif
   2552                             pComponentPrivate_CC->cbInfo.EmptyBufferDone (
   2553                                            pComponentPrivate_CC->pHandle,
   2554                                            pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2555                                            pComponentPrivate_CC->pInputBufHdrPending[i]);
   2556                             pComponentPrivate_CC->pInputBufHdrPending[i] = NULL;
   2557                             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->EmptybufferdoneCount);
   2558                             SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
   2559                          }
   2560                          pComponentPrivate_CC->nNumInputBufPending=0;
   2561                          pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
   2562                                                                   pHandle->pApplicationPrivate,
   2563                                                                   OMX_EventCmdComplete,
   2564                                                                   OMX_CommandFlush,INPUT_PORT, NULL);
   2565                     }
   2566                     else
   2567                     {
   2568                          OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: LCML reported error while flushing input port\n",__LINE__);
   2569                          goto EXIT;
   2570                     }
   2571                 }
   2572                 else if ( args[2] == (void *)EMMCodecOuputBuffer)
   2573                 {
   2574                     if (args[0] == (void*)USN_ERR_NONE )
   2575                     {
   2576                          OMX_PRDSP1(pComponentPrivate_CC->dbg, "\tCallback FLUSH OUT %ld\n",pComponentPrivate_CC->nNumOutputBufPending);
   2577                          pComponentPrivate_CC->nOutStandingFillDones = 0;
   2578                          for (i=0; i < pComponentPrivate_CC->nNumOutputBufPending; i++)
   2579                          {
   2580 #ifdef __PERF_INSTRUMENTATION__
   2581                             PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
   2582                             PREF(pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],pBuffer),
   2583                             PREF(pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],nFilledLen),
   2584                             PERF_ModuleHLMM);
   2585 #endif
   2586                             pComponentPrivate_CC->cbInfo.FillBufferDone (
   2587                                            pComponentPrivate_CC->pHandle,
   2588                                            pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2589                                            pComponentPrivate_CC->pOutputBufHdrPending[i]
   2590                                            );
   2591                             pComponentPrivate_CC->pOutputBufHdrPending[i] = NULL;
   2592                             AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate_CC->FillbufferdoneCount);
   2593                             SignalIfAllBuffersAreReturned(pComponentPrivate_CC);
   2594                          }
   2595                          pComponentPrivate_CC->nNumOutputBufPending=0;
   2596                          pComponentPrivate_CC->cbInfo.EventHandler(
   2597                                          pHandle, pHandle->pApplicationPrivate,
   2598                                          OMX_EventCmdComplete, OMX_CommandFlush,OUTPUT_PORT, NULL);
   2599                      }
   2600                      else
   2601                      {
   2602                         OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: LCML reported error while flushing output port\n",__LINE__);
   2603                         goto EXIT;
   2604                      }
   2605             }
   2606         }
   2607     }
   2608 
   2609 
   2610     else if(event == EMMCodecProcessingStoped)
   2611     {
   2612         ALOGI("AAC encoder received stop ack, waiting for all outstanding buffers to be returned");
   2613         pthread_mutex_lock(&bufferReturned_mutex);
   2614         while (pComponentPrivate_CC->EmptythisbufferCount != pComponentPrivate_CC->EmptybufferdoneCount ||
   2615                pComponentPrivate_CC->FillthisbufferCount  != pComponentPrivate_CC->FillbufferdoneCount) {
   2616             pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
   2617         }
   2618         pthread_mutex_unlock(&bufferReturned_mutex);
   2619         ALOGI("AAC encoder has returned all buffers");
   2620 
   2621         pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);
   2622         if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
   2623             pComponentPrivate_CC->codecStop_waitingsignal = 1;
   2624             pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
   2625             OMX_PRINT2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
   2626         }
   2627         pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
   2628 
   2629         if (!pComponentPrivate_CC->bNoIdleOnStop)
   2630         {
   2631             pComponentPrivate_CC->curState = OMX_StateIdle;
   2632 #ifdef RESOURCE_MANAGER_ENABLED
   2633 
   2634             rm_error = RMProxy_NewSendCommand(pComponentPrivate_CC->pHandle,
   2635                                            RMProxy_StateSet,
   2636                                            OMX_AAC_Encoder_COMPONENT,
   2637                                            OMX_StateIdle,
   2638                                            3456, NULL);
   2639 
   2640 #endif
   2641             if (pComponentPrivate_CC->bPreempted == 0) {
   2642 
   2643                 /* Decrement reference count with signal enabled */
   2644                 if(RemoveStateTransition(pComponentPrivate_CC, OMX_TRUE) != OMX_ErrorNone) {
   2645                       return OMX_ErrorUndefined;
   2646                 }
   2647 
   2648                 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
   2649                                                        pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2650                                                        OMX_EventCmdComplete,
   2651                                                        OMX_CommandStateSet,
   2652                                                        pComponentPrivate_CC->curState,
   2653                                                        NULL);
   2654             }
   2655             else {
   2656                 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
   2657                                                        pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2658                                                        OMX_EventError,
   2659                                                        OMX_ErrorResourcesPreempted,
   2660                                                        OMX_TI_ErrorMajor,
   2661                                                        NULL);
   2662             }
   2663 
   2664         }
   2665         else
   2666         {
   2667             OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: setting bDspStoppedWhileExecuting\n",__LINE__);
   2668             pComponentPrivate_CC->bDspStoppedWhileExecuting = OMX_TRUE;
   2669             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: bNoIdleOnStop %ld \n", __LINE__,pComponentPrivate_CC->bNoIdleOnStop);
   2670             pComponentPrivate_CC->bNoIdleOnStop= OMX_FALSE;
   2671         }
   2672 
   2673     }
   2674 
   2675 
   2676     else if(event == EMMCodecDspMessageRecieved)
   2677     {
   2678         OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE EMMCodecDspMessageRecieved \n",__LINE__);
   2679         OMX_PRSTATE1(pComponentPrivate_CC->dbg, "%d :: UTIL: commandedState  = %p\n",__LINE__,args[0]);
   2680         OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: arg1 = %p\n",__LINE__,args[1]);
   2681         OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: arg2 = %p\n",__LINE__,args[2]);
   2682         if(0x0500 == (OMX_U32)args[2])
   2683         {
   2684             OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: See Message Here\n",__LINE__);
   2685         }
   2686     }
   2687 
   2688 
   2689     else if(event == EMMCodecAlgCtrlAck)
   2690     {
   2691         OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: UTIL: GOT MESSAGE USN_DSPACK_ALGCTRL \n",__LINE__);
   2692     }
   2693 
   2694 
   2695     else if (event == EMMCodecDspError)
   2696     {
   2697         OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: commandedState  = %d\n",__LINE__,(int)args[0]);
   2698         OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg4 = %d\n",__LINE__,(int)args[4]);
   2699         OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg5 = %d\n",__LINE__,(int)args[5]);
   2700         OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d ::UTIL: EMMCodecDspError Here\n",__LINE__);
   2701         switch ( (OMX_U32) args [4])
   2702         {
   2703             /* USN_ERR_NONE,:Indicates that no error encountered during execution of the command and the command execution completed succesfully.
   2704              * USN_ERR_WARNING,:Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
   2705              * USN_ERR_PROCESS,:Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
   2706              * USN_ERR_PAUSE,:Indicates that execution of pause resulted in error.
   2707              * USN_ERR_STOP,:Indicates that execution of stop resulted in error.
   2708              * USN_ERR_ALGCTRL,:Indicates that execution of alg control resulted in error.
   2709              * USN_ERR_STRMCTRL,:Indiactes the execution of STRM control command, resulted in error.
   2710              * USN_ERR_UNKNOWN_MSG,:Indicates that USN received an unknown command. */
   2711 
   2712 #ifdef _ERROR_PROPAGATION__
   2713             case USN_ERR_PAUSE:
   2714             case USN_ERR_STOP:
   2715             case USN_ERR_ALGCTRL:
   2716             case USN_ERR_STRMCTRL:
   2717             case USN_ERR_UNKNOWN_MSG:
   2718                 {
   2719                     pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
   2720                     pComponentPrivate_CC->curState = OMX_StateInvalid;
   2721                     pHandle = pComponentPrivate_CC->pHandle;
   2722                     pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
   2723                             pHandle->pApplicationPrivate,
   2724                             OMX_EventError,
   2725                             OMX_ErrorInvalidState,
   2726                             OMX_TI_ErrorSevere,
   2727                             NULL);
   2728                 }
   2729                 break;
   2730 #endif
   2731 
   2732             case USN_ERR_WARNING:
   2733             case USN_ERR_PROCESS:
   2734                 AACENC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
   2735                 break;
   2736             default:
   2737                 break;
   2738         }
   2739 
   2740     }
   2741 
   2742 
   2743     else if (event == EMMCodecProcessingPaused)
   2744     {
   2745         pComponentPrivate_CC->bPauseCommandPending = OMX_TRUE;
   2746         AACENC_TransitionToPause(pComponentPrivate_CC);
   2747 
   2748     }
   2749 
   2750 #ifdef _ERROR_PROPAGATION__
   2751 
   2752     else if (event ==EMMCodecInitError)
   2753     {
   2754         /* Cheking for MMU_fault */
   2755         if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL))
   2756         {
   2757             OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
   2758             pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
   2759             OMX_PRINT2(pComponentPrivate_CC->dbg, "State changed to OMX_StateInvalid Line %d\n",__LINE__);
   2760 
   2761             pComponentPrivate_CC->curState = OMX_StateInvalid;
   2762             pHandle = pComponentPrivate_CC->pHandle;
   2763             pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
   2764                                                        pHandle->pApplicationPrivate,
   2765                                                        OMX_EventError,
   2766                                                        OMX_ErrorStreamCorrupt,
   2767                                                        OMX_TI_ErrorSevere,
   2768                                                        NULL);
   2769         }
   2770     }
   2771 
   2772 
   2773     else if (event ==EMMCodecInternalError)
   2774     {
   2775         /* Cheking for MMU_fault */
   2776         if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL))
   2777         {
   2778             OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
   2779             pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
   2780             OMX_PRSTATE2(pComponentPrivate_CC->dbg, "State changed to OMX_StateInvalid Line %d\n",__LINE__);
   2781 
   2782             pComponentPrivate_CC->curState = OMX_StateInvalid;
   2783             pHandle = pComponentPrivate_CC->pHandle;
   2784             pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
   2785                                                        pHandle->pApplicationPrivate,
   2786                                                        OMX_EventError,
   2787                                                        OMX_ErrorStreamCorrupt,
   2788                                                        OMX_TI_ErrorSevere,
   2789                                                        NULL);
   2790         }
   2791     }
   2792 #endif
   2793 
   2794 EXIT:
   2795     OMX_PRINT1(pComponentPrivate_CC->dbg, "%d:pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate_CC->curState);
   2796     OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: UTIL: Exiting the LCML_Callback Function\n",__LINE__);
   2797     /* report the error to the client via event */
   2798     if(eError != OMX_ErrorNone){
   2799         OMX_ERROR4(pComponentPrivate_CC->dbg, "%d:: Error: \n",__LINE__);
   2800         pComponentPrivate_CC->cbInfo.EventHandler (pComponentPrivate_CC->pHandle,
   2801                                                 pComponentPrivate_CC->pHandle->pApplicationPrivate,
   2802                                                 OMX_EventError,
   2803                                                 eError,
   2804                                                 OMX_TI_ErrorSevere,
   2805                                                 NULL);
   2806     }
   2807     return eError;
   2808 }
   2809 
   2810 /* -------------------------------------------------------------------*/
   2811 /**
   2812   *  AACENCGetCorresponding_LCMLHeader() function will be called by LCML_Callback
   2813   *                                 component to write the msg
   2814   * @param *pBuffer,          Event which gives to details about USN status
   2815   * @param LCML_AACENC_BUFHEADERTYPE **ppLcmlHdr            //  args [0] //bufType;
   2816 
   2817   * @retval OMX_NoError              Success, ready to roll
   2818   *         OMX_Error_BadParameter   The input parameter pointer is null
   2819  **/
   2820 /* -------------------------------------------------------------------*/
   2821 OMX_ERRORTYPE AACENCGetCorresponding_LCMLHeader(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir, LCML_AACENC_BUFHEADERTYPE **ppLcmlHdr)
   2822 {
   2823 
   2824     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2825     LCML_AACENC_BUFHEADERTYPE *pLcmlBufHeader = NULL;
   2826     int nIpBuf =0 ;
   2827     int nOpBuf =0;
   2828     OMX_U16 i  =0;
   2829 
   2830     AACENC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;
   2831     pComponentPrivate_CC = pComponentPrivate;
   2832 
   2833     nIpBuf=pComponentPrivate_CC->pInputBufferList->numBuffers;
   2834     nOpBuf=pComponentPrivate_CC->pOutputBufferList->numBuffers;
   2835 
   2836     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Entering AACENCGetCorresponding_LCMLHeader..\n",__LINE__);
   2837 
   2838     if(eDir == OMX_DirInput) {
   2839         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: AACENCGetCorresponding_LCMLHeader -- eDir = %d \n",__LINE__,eDir);
   2840         pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT];
   2841         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: Before corresponding LCML Header is Found \n",__LINE__);
   2842         for(i=0; i<nIpBuf; i++) {
   2843             if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
   2844                 *ppLcmlHdr = pLcmlBufHeader;
   2845                 OMX_PRDSP2(pComponentPrivate->dbg, "%d::  UTIL: Corresponding LCML Header Found\n",__LINE__);
   2846                 OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pBuffer = %p\n",pBuffer);
   2847                 OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
   2848                 OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
   2849                 goto EXIT;
   2850             }
   2851             pLcmlBufHeader++;
   2852         }
   2853     }
   2854     else if (eDir == OMX_DirOutput)
   2855     {
   2856         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: AACENCGetCorresponding_LCMLHeader -- eDir = %d \n",__LINE__,eDir);
   2857         pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[OUTPUT_PORT];
   2858         OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: Before corresponding LCML Header is Found \n",__LINE__);
   2859         OMX_PRBUFFER2(pComponentPrivate->dbg, "nOpBuf = %d\n",nOpBuf);
   2860         for(i=0; i<nOpBuf; i++)
   2861         {
   2862             OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
   2863             OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader = %p\n",pLcmlBufHeader);
   2864             OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
   2865             OMX_PRBUFFER2(pComponentPrivate->dbg, " pLcmlBufHeader->buffer->pBuffer = %p\n", pLcmlBufHeader->buffer->pBuffer);
   2866             OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
   2867             OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader = %p\n",pLcmlBufHeader);
   2868             OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
   2869             OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
   2870             if(pBuffer == pLcmlBufHeader->buffer->pBuffer)
   2871             {
   2872                 *ppLcmlHdr = pLcmlBufHeader;
   2873                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:: UTIL: Corresponding LCML Header Found\n",__LINE__);
   2874                 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: UTIL: pBuffer = %p\n",pBuffer);
   2875                 OMX_PRBUFFER2(pComponentPrivate->dbg, "::  UTIL: pLcmlBufHeader->buffer = %p\n",pLcmlBufHeader->buffer);
   2876                 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: UTIL: pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer);
   2877                 goto EXIT;
   2878             }
   2879             pLcmlBufHeader++;
   2880         }
   2881     }
   2882     else
   2883     {
   2884       OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:: UTIL: Invalid Buffer Type :: exiting...\n",__LINE__);
   2885     }
   2886 
   2887 EXIT:
   2888     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL: Exiting AACENCGetCorresponding_LCMLHeader..\n",__LINE__);
   2889     return eError;
   2890 }
   2891 
   2892 
   2893 /* -------------------------------------------------------------------*/
   2894 /**
   2895   *  AACENC_GetLCMLHandle()
   2896   *
   2897   * @retval OMX_HANDLETYPE
   2898   *
   2899  -------------------------------------------------------------------*/
   2900 OMX_HANDLETYPE AACENCGetLCMLHandle(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
   2901 {
   2902 
   2903     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2904     OMX_HANDLETYPE pHandle = NULL;
   2905 #ifndef UNDER_CE
   2906     void *handle;
   2907     char *error;
   2908     OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
   2909     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENCGetLCMLHandle..\n",__LINE__);
   2910     handle = dlopen("libLCML.so", RTLD_LAZY);
   2911     if (!handle) {
   2912         fputs(dlerror(), stderr);
   2913         goto EXIT;
   2914     }
   2915 
   2916     fpGetHandle = dlsym (handle, "GetHandle");
   2917     if ((error = dlerror()) != NULL) {
   2918         fputs(error, stderr);
   2919         goto EXIT;
   2920     }
   2921 #else
   2922     HINSTANCE hDLL;
   2923     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
   2924     LPFNDLLFUNC1 fpGetHandle;
   2925 
   2926     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENCGetLCMLHandle..\n",__LINE__);
   2927 
   2928     hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL, 0);
   2929     if (hDLL == NULL) {
   2930         OMX_ERROR4(pComponentPrivate->dbg, "BML Load Failed!!!\n");
   2931         pHandle = NULL;
   2932         goto EXIT;
   2933     }
   2934 
   2935     fpGetHandle = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
   2936     if (!fpGetHandle) {
   2937       // handle the error
   2938       FreeLibrary(hDLL);
   2939       OMX_ERROR4(pComponentPrivate->dbg, "BML GetProcAddress Failed!!!\n");
   2940       pHandle = NULL;
   2941       goto EXIT;
   2942     }
   2943 #endif
   2944     eError = (*fpGetHandle)(&pHandle);
   2945     if(eError != OMX_ErrorNone) {
   2946         eError = OMX_ErrorUndefined;
   2947         OMX_ERROR4(pComponentPrivate->dbg, "eError != OMX_ErrorNone...\n");
   2948         pHandle = NULL;
   2949 
   2950 #ifndef UNDER_CE
   2951         dlclose(handle);                            /* got error - Close LCML lib  */
   2952         OMX_ERROR4(pComponentPrivate->dbg, "AAC: [AACENCGetLCMLHandle] closing LCML \n");
   2953         handle = NULL;
   2954  #endif
   2955         goto EXIT;
   2956     }
   2957 
   2958     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate= pComponentPrivate;
   2959     pComponentPrivate->ptrLibLCML=handle;           /* saving LCML lib pointer  */
   2960     OMX_PRDSP2(pComponentPrivate->dbg, "AAC: ptrLibLCML = %p\n",pComponentPrivate->ptrLibLCML);
   2961     pComponentPrivate->bGotLCML = OMX_TRUE;
   2962 
   2963 EXIT:
   2964     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting AACENCGetLCMLHandle..\n",__LINE__);
   2965     return pHandle;
   2966 }
   2967 
   2968 /* ================================================================================= */
   2969 /**
   2970 * @fn AACENC_SetPending() description for AACENC_SetPending
   2971 AACENC_SetPending().
   2972 This component is called when a buffer is queued to the LCML
   2973 * @param pComponent  handle for this instance of the component
   2974 *
   2975 * @pre
   2976 *
   2977 * @post
   2978 *
   2979 * @return OMX_ERRORTYPE
   2980 */
   2981 /* ================================================================================ */
   2982 void AACENC_SetPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   2983 {
   2984     OMX_U16 i;
   2985 
   2986     if (eDir == OMX_DirInput) {
   2987         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   2988             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   2989                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
   2990                 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
   2991             }
   2992         }
   2993     }
   2994     else {
   2995         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   2996             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   2997                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
   2998                 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS PENDING Line %ld******************************\n",i,lineNumber);
   2999             }
   3000         }
   3001     }
   3002 }
   3003 
   3004 /* ================================================================================= */
   3005 /**
   3006 * @fn AACENC_ClearPending() description for AACENC_ClearPending
   3007 AACENC_ClearPending().
   3008 This component is called when a buffer is returned from the LCML
   3009 * @param pComponent  handle for this instance of the component
   3010 *
   3011 * @pre
   3012 *
   3013 * @post
   3014 *
   3015 * @return OMX_ERRORTYPE
   3016 */
   3017 /* ================================================================================ */
   3018 void AACENC_ClearPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
   3019 {
   3020     OMX_U16 i;
   3021 
   3022     OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate = %p\n",pComponentPrivate);
   3023     OMX_PRBUFFER1(pComponentPrivate->dbg, "pBufHdr = %p\n",pBufHdr);
   3024     OMX_PRINT2(pComponentPrivate->dbg, "eDir = %d\n",eDir);
   3025 
   3026     if (eDir == OMX_DirInput) {
   3027         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   3028             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   3029                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
   3030                 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
   3031             }
   3032         }
   3033     }
   3034     else {
   3035         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   3036             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   3037                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
   3038                 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS RECLAIMED Line %ld******************************\n",i,lineNumber);
   3039             }
   3040         }
   3041     }
   3042 }
   3043 
   3044 /* ================================================================================= */
   3045 /**
   3046 * @fn AACENC_IsPending() description for AACENC_IsPending
   3047 AACENC_IsPending().
   3048 This method returns the pending status to the buffer
   3049 * @param pComponent  handle for this instance of the component
   3050 *
   3051 * @pre
   3052 *
   3053 * @post
   3054 *
   3055 * @return OMX_ERRORTYPE
   3056 */
   3057 /* ================================================================================ */
   3058 OMX_U32 AACENC_IsPending(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
   3059 {
   3060     OMX_U16 i;
   3061 
   3062     if (eDir == OMX_DirInput) {
   3063         for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
   3064             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
   3065                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Buffer pending: pBufHdr = %p \n",__LINE__,pBufHdr);
   3066                 return pComponentPrivate->pInputBufferList->bBufferPending[i];
   3067             }
   3068         }
   3069     }
   3070     else {
   3071         for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
   3072             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
   3073                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Buffer pending: pBufHdr = %p \n",__LINE__,pBufHdr);
   3074                 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
   3075             }
   3076         }
   3077     }
   3078     return -1;
   3079 }
   3080 
   3081 OMX_ERRORTYPE AACENC_TransitionToPause(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
   3082 {
   3083     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3084 
   3085     OMX_PRINT1(pComponentPrivate->dbg, "AACENC_TransitionToPause:::pComponentPrivate->nOutStandingFillDones = %ld\n",pComponentPrivate->nOutStandingFillDones );
   3086     OMX_PRINT1(pComponentPrivate->dbg, "AACENC_TransitionToPause:::pComponentPrivate->nOutStandingEmptyDones = %ld\n",pComponentPrivate->nOutStandingEmptyDones );
   3087     if (pComponentPrivate->nOutStandingFillDones <= 0 && pComponentPrivate->nOutStandingEmptyDones <= 0)
   3088     {
   3089         pComponentPrivate->curState = OMX_StatePause;
   3090 
   3091         /* Decrement reference count with signal enabled */
   3092         if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
   3093               return OMX_ErrorUndefined;
   3094         }
   3095 
   3096         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3097                                                 pComponentPrivate->pHandle->pApplicationPrivate,
   3098                                                 OMX_EventCmdComplete,
   3099                                                 OMX_CommandStateSet,
   3100                                                 pComponentPrivate->curState,
   3101                                                 NULL);
   3102     pComponentPrivate->bPauseCommandPending = OMX_FALSE;
   3103     }
   3104     return eError;
   3105 }
   3106 
   3107 
   3108 /* ========================================================================== */
   3109 /**
   3110 * AACENCFill_LCMLInitParamsEx () This function is used by the component thread to
   3111 * fill the all of its initialization parameters, buffer deatils  etc
   3112 * to LCML structure,
   3113 *
   3114 * @param pComponent  handle for this instance of the component
   3115 * @param plcml_Init  pointer to LCML structure to be filled
   3116 *
   3117 * @pre
   3118 *
   3119 * @post
   3120 *
   3121 * @return none
   3122 */
   3123 /* ========================================================================== */
   3124 OMX_ERRORTYPE AACENCFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent)
   3125 {
   3126     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3127     OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
   3128     OMX_U16 i;
   3129     OMX_BUFFERHEADERTYPE *pTemp = NULL;
   3130     OMX_U32 size_lcml;
   3131     LCML_AACENC_BUFHEADERTYPE *pTemp_lcml = NULL;
   3132     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
   3133     AACENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
   3134 
   3135     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENCFill_LCMLInitParams\n ",__LINE__);
   3136     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
   3137     nIpBufSize = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferSize;
   3138     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
   3139     nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
   3140 
   3141     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__);
   3142     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Count = %ld \n",__LINE__,nIpBuf);
   3143     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input  Buffer Size = %ld\n",__LINE__,nIpBufSize);
   3144     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf);
   3145     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize);
   3146     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__);
   3147 
   3148     size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
   3149     OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
   3150     OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
   3151 
   3152     pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
   3153     for (i=0; i<nIpBuf; i++) {
   3154 
   3155         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
   3156         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   3157         pTemp->nAllocLen = nIpBufSize;
   3158         pTemp->nFilledLen = nIpBufSize;
   3159         pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
   3160         pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
   3161         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   3162         pTemp->nTickCount = NOT_USED;
   3163         pTemp_lcml->buffer = pTemp;
   3164         pTemp_lcml->eDir = OMX_DirInput;
   3165 
   3166         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, sizeof(AACENC_UAlgInBufParamStruct), AACENC_UAlgInBufParamStruct);
   3167         OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
   3168 
   3169         pTemp_lcml->pIpParam->bLastBuffer = 0;
   3170         /* This means, it is not a last buffer. This flag is to be modified by
   3171          * the application to indicate the last buffer */
   3172         pTemp->nFlags = NORMAL_BUFFER;
   3173         pTemp_lcml++;
   3174     }
   3175 
   3176     /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
   3177     size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
   3178 
   3179     OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
   3180     OMX_PRDSP2(pComponentPrivate->dbg, "size_lcml %d to %lx \n", (int)size_lcml,(size_lcml + sizeof(size_lcml) ));
   3181 
   3182     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
   3183 
   3184 
   3185 
   3186     OMX_PRBUFFER2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] nOpBuf = %d\n", (int)nOpBuf);
   3187     OMX_PRBUFFER2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] pComponentPrivate->pOutputBufferList->numBuffers = %d\n",pComponentPrivate->pOutputBufferList->numBuffers);
   3188     for (i=0; i<nOpBuf; i++) {
   3189            OMX_PRDSP2(pComponentPrivate->dbg, "[AACENCFill_LCMLInitParamsEx] pTemp_lcml = %p\n",pTemp_lcml);
   3190         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
   3191         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
   3192         pTemp->nAllocLen = nOpBufSize;
   3193         pTemp->nFilledLen = nOpBufSize;
   3194         pTemp->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
   3195         pTemp->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
   3196         pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
   3197         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
   3198         pTemp->nTickCount = NOT_USED;
   3199         /* This means, it is not a last buffer. This flag is to be modified by
   3200          * the application to indicate the last buffer */
   3201         pTemp_lcml->buffer = pTemp;
   3202         pTemp_lcml->eDir = OMX_DirOutput;
   3203 
   3204         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, sizeof(AACENC_UAlgOutBufParamStruct), AACENC_UAlgOutBufParamStruct);
   3205 
   3206         OMX_PRINT2(pComponentPrivate->dbg, "\n pTemp_lcml->pOpParam %p \n",pTemp_lcml->pOpParam);
   3207         pTemp->nFlags = NORMAL_BUFFER;
   3208         pTemp++;
   3209         pTemp_lcml++;
   3210     }
   3211     pComponentPrivate->bPortDefsAllocated = 1;
   3212     pComponentPrivate->bBypassDSP = 0;
   3213 
   3214 EXIT:
   3215     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting Fill_LCMLInitParams\n",__LINE__);
   3216     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
   3217     return eError;
   3218 }
   3219 
   3220 
   3221 OMX_ERRORTYPE AACENCWriteConfigHeader(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr){
   3222 
   3223     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3224     OMX_U32 nPosition = 0;
   3225     OMX_U32 nNumBitsWritten = 0;
   3226     OMX_U32 nBytePosition = 0;
   3227     OMX_U8  nBitPosition =  0;
   3228     OMX_U8  nBits = 0;
   3229     OMX_U32 tempData = 0;
   3230     OMX_U8 rateIndex = 0;
   3231     OMX_U16 nBuf = 0;
   3232 	OMX_U16 nBuf2 = 0;
   3233     //nBytePosition = nPosition / 8;  //add this back if we need to handle more than 4 bytes (U32).
   3234     //nBitPosition =  nPosition % 8;
   3235     memset(pBufHdr->pBuffer, 0x0, pBufHdr->nAllocLen); // make sure we start with zeroes
   3236 
   3237     nBits = 5; //audioObjectType
   3238     nPosition += nBits;
   3239     OMX_PRINT2(pComponentPrivate->dbg, "profile is %d\n", pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile);
   3240     if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectLC)
   3241     {
   3242         tempData = AACENC_OBJ_TYP_LC << (16-nPosition);
   3243         OMX_PRINT2(pComponentPrivate->dbg, "profile is LC, tempData = 2 << (32-5) = %ld\n", tempData);
   3244     }
   3245     else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectHE)
   3246     {
   3247         tempData = AACENC_OBJ_TYP_HEAAC << (16-nPosition);
   3248     }
   3249     else if (pComponentPrivate->aacParams[OUTPUT_PORT]->eAACProfile == OMX_AUDIO_AACObjectHE_PS)
   3250     {
   3251         tempData = AACENC_OBJ_TYP_PS << (16-nPosition);
   3252     }
   3253     nBuf = tempData;
   3254 
   3255     nBits = 4; //SamplingFrequencyIndex
   3256     nPosition += nBits;
   3257     rateIndex = AACEnc_GetSampleRateIndexL(pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate);
   3258     tempData = rateIndex << (16-nPosition);
   3259     nBuf |= tempData;
   3260     OMX_PRBUFFER2(pComponentPrivate->dbg, "CONFIG BUFFER = %d\n\n", nBuf);
   3261 
   3262     nBits = 4; //channelConfiguration
   3263     nPosition += nBits;
   3264     tempData = pComponentPrivate->aacParams[OUTPUT_PORT]->nChannels << (16-nPosition);
   3265     nBuf |= tempData;
   3266 
   3267     //@TODO add the rest of the AudioSpecificConfigData
   3268 
   3269 	nBuf2 =	(nBuf>> 8) | (nBuf << 8); /* Changing Endianess */
   3270 
   3271     OMX_PRBUFFER2(pComponentPrivate->dbg, "CONFIG BUFFER = %d\n\n", nBuf2);
   3272 
   3273     memcpy(pBufHdr->pBuffer, &nBuf2, sizeof(OMX_U16));
   3274     pBufHdr->nFlags = NORMAL_BUFFER;  // clear any other flags then add the needed ones
   3275     pBufHdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
   3276     pBufHdr->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
   3277     pBufHdr->nFilledLen = sizeof(OMX_U16); //need make this dynamic for non basic LC cases.
   3278 
   3279     return eError;
   3280 }
   3281 
   3282 /*=======================================================================*/
   3283 /*! @fn AACDec_GetSampleRateIndexL
   3284 
   3285  * @brief Gets the sample rate index
   3286 
   3287  * @param  aRate : Actual Sampling Freq
   3288 
   3289  * @Return  Index
   3290 
   3291  */
   3292 /*=======================================================================*/
   3293 int AACEnc_GetSampleRateIndexL( const int aRate)
   3294 {
   3295     int index = 0;
   3296 
   3297     switch( aRate ){
   3298     case 96000:
   3299         index = 0;
   3300         break;
   3301     case 88200:
   3302         index = 1;
   3303         break;
   3304     case 64000:
   3305         index = 2;
   3306         break;
   3307     case 48000:
   3308         index = 3;
   3309         break;
   3310     case 44100:
   3311         index = 4;
   3312         break;
   3313     case 32000:
   3314         index = 5;
   3315         break;
   3316     case 24000:
   3317         index = 6;
   3318         break;
   3319     case 22050:
   3320         index = 7;
   3321         break;
   3322     case 16000:
   3323         index = 8;
   3324         break;
   3325     case 12000:
   3326         index = 9;
   3327         break;
   3328     case 11025:
   3329         index = 10;
   3330         break;
   3331     case 8000:
   3332         index = 11;
   3333         break;
   3334     default:
   3335         break;
   3336     }
   3337 
   3338     return index;
   3339 }
   3340 
   3341 /*  =========================================================================*/
   3342 /**  func    AACENC_HandleUSNError
   3343  *
   3344  *  desc    Handles error messages returned by the dsp
   3345  *
   3346  *@return n/a
   3347  */
   3348 /*  =========================================================================*/
   3349 void AACENC_HandleUSNError (AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
   3350 {
   3351     OMX_COMPONENTTYPE *pHandle = NULL;
   3352     OMX_U32 i;
   3353     switch (arg)
   3354     {
   3355 
   3356         case IUALG_WARN_CONCEALED:
   3357         case IUALG_WARN_UNDERFLOW:
   3358         case IUALG_WARN_OVERFLOW:
   3359         case IUALG_WARN_ENDOFDATA:
   3360             OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
   3361             /* all of these are informative messages, Algo can recover, no need to notify the
   3362              * IL Client at this stage of the implementation */
   3363             break;
   3364         case IUALG_WARN_PLAYCOMPLETED:
   3365 
   3366             {
   3367                 OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: IUALG_WARN_PLAYCOMPLETED/USN_ERR_WARNING event received\n", __LINE__);
   3368                 pComponentPrivate->bPlayCompleteFlag = 1;
   3369 #ifndef UNDER_CE
   3370                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3371                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   3372                                                        OMX_EventBufferFlag,
   3373                                                        (OMX_U32)NULL,
   3374                                                        OMX_BUFFERFLAG_EOS,
   3375                                                        NULL);
   3376                 pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
   3377 #else
   3378                 /* add callback to application to indicate SN/USN has completed playing of current set of date */
   3379                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
   3380                                                        pComponentPrivate->pHandle->pApplicationPrivate,
   3381                                                        OMX_EventBufferFlag,
   3382                                                        (OMX_U32)NULL,
   3383                                                        OMX_BUFFERFLAG_EOS,
   3384                                                        NULL);
   3385 #endif
   3386             }
   3387             break;
   3388 
   3389 #ifdef _ERROR_PROPAGATION__
   3390         case IUALG_ERR_BAD_HANDLE:
   3391         case IUALG_ERR_DATA_CORRUPT:
   3392         case IUALG_ERR_NOT_SUPPORTED:
   3393         case IUALG_ERR_ARGUMENT:
   3394         case IUALG_ERR_NOT_READY:
   3395         case IUALG_ERR_GENERAL:
   3396 
   3397             {
   3398                 /* all of these are fatal messages, Algo can not recover
   3399                  * hence return an error */
   3400                 OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
   3401                 pComponentPrivate->bIsInvalidState=OMX_TRUE;
   3402                 pComponentPrivate->curState = OMX_StateInvalid;
   3403                 pHandle = pComponentPrivate->pHandle;
   3404                 pComponentPrivate->cbInfo.EventHandler(pHandle,
   3405                         pHandle->pApplicationPrivate,
   3406                         OMX_EventError,
   3407                         OMX_ErrorInvalidState,
   3408                         OMX_TI_ErrorSevere,
   3409                         NULL);
   3410             }
   3411             break;
   3412 #endif
   3413         default:
   3414             break;
   3415     }
   3416 }
   3417 
   3418 
   3419 #ifdef RESOURCE_MANAGER_ENABLED
   3420 void AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
   3421 {
   3422     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   3423     OMX_STATETYPE state = OMX_StateIdle;
   3424     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
   3425     AACENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
   3426 
   3427     pCompPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
   3428 
   3429     if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
   3430         if (pCompPrivate->curState == OMX_StateExecuting ||
   3431             pCompPrivate->curState == OMX_StatePause) {
   3432             write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
   3433             write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
   3434 
   3435             pCompPrivate->bPreempted = 1;
   3436         }
   3437     }
   3438     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
   3439         pCompPrivate->cbInfo.EventHandler (
   3440                             pHandle, pHandle->pApplicationPrivate,
   3441                             OMX_EventResourcesAcquired, 0,0,
   3442                             NULL);
   3443 
   3444 
   3445     }
   3446 
   3447 }
   3448 #endif
   3449 
   3450 OMX_ERRORTYPE AddStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate) {
   3451     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3452 
   3453     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
   3454        return OMX_ErrorUndefined;
   3455     }
   3456     /* Increment state change request reference count */
   3457     pComponentPrivate->nPendingStateChangeRequests++;
   3458     ALOGI("addstatetranstion: %ld @ %d", pComponentPrivate->nPendingStateChangeRequests, pComponentPrivate->curState);
   3459 
   3460     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   3461        return OMX_ErrorUndefined;
   3462     }
   3463     return eError;
   3464 }
   3465 
   3466 OMX_ERRORTYPE RemoveStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal) {
   3467     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3468 
   3469      /* Decrement state change request reference count*/
   3470     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
   3471        return OMX_ErrorUndefined;
   3472     }
   3473     pComponentPrivate->nPendingStateChangeRequests--;
   3474     ALOGI("removestatetranstion: %ld @ %d", pComponentPrivate->nPendingStateChangeRequests, pComponentPrivate->curState);
   3475 
   3476     /* If there are no more pending requests, signal the thread waiting on this*/
   3477     if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) {
   3478        pthread_cond_signal(&(pComponentPrivate->StateChangeCondition));
   3479     }
   3480     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   3481        return OMX_ErrorUndefined;
   3482     }
   3483 
   3484     return eError;
   3485 }
   3486 
   3487 /* ========================================================================== */
   3488 /**
   3489  * @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app
   3490  *
   3491  * @param AACENC_COMPONENT_PRIVATE *pComponentPrivate
   3492  *
   3493  * @pre None
   3494  *
   3495  * @post None
   3496  *
   3497  * @return None
   3498 */
   3499 /* ========================================================================== */
   3500 void SignalIfAllBuffersAreReturned(AACENC_COMPONENT_PRIVATE *pComponentPrivate)
   3501 {
   3502         pthread_mutex_lock(&bufferReturned_mutex);
   3503         if ((pComponentPrivate->EmptythisbufferCount == pComponentPrivate->EmptybufferdoneCount) &&
   3504             (pComponentPrivate->FillthisbufferCount ==   pComponentPrivate->FillbufferdoneCount)) {
   3505             pthread_cond_broadcast(&bufferReturned_condition);
   3506             ALOGI("Sending pthread signal that OMX has returned all buffers to app");
   3507         }
   3508         pthread_mutex_unlock(&bufferReturned_mutex);
   3509 }
   3510 
   3511 /* ====================================================================== */
   3512 /*@AACENC_IncrementBufferCounterByOne() This function is used by the component
   3513  * to atomically increment some input or output buffer counter
   3514  *
   3515  * @param mutex pointer to mutex for synchronizing the value change on
   3516  *              the counter
   3517  * @param counter the buffer counter to be incremented
   3518  *
   3519  * @post the buffer counter's value will be incremented by one.
   3520  * @return None
   3521  */
   3522 /* ====================================================================== */
   3523 void AACENC_IncrementBufferCounterByOne(pthread_mutex_t* mutex, OMX_U32 *counter)
   3524 {
   3525     pthread_mutex_lock(mutex);
   3526     (*counter)++;
   3527     pthread_mutex_unlock(mutex);
   3528 }
   3529 
   3530 
   3531