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