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