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