OMX_WmaDecoder.c revision 9961abce63e3f897758a99cc2e060cb68c484803
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/* ==============================================================================
23 *             Texas Instruments OMAP (TM) Platform Software
24 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
25 *
26 *  Use of this software is controlled by the terms and conditions found
27 *  in the license agreement under which this software has been supplied.
28 * ============================================================================ */
29/**
30 * @file OMX_WmaDecoder.c
31 *
32 * This file implements OMX Component for WMA decoder that
33 * is fully compliant with the OMX Audio specification 1.5.
34 *
35 * @path  $(CSLPATH)\
36 *
37 * @rev  0.1
38 */
39/* ----------------------------------------------------------------------------
40 *!
41 *! Revision History
42 *! ===================================
43 *! 12-Sept-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
44 *! to provide _________________.
45 *!
46 * ============================================================================= */
47
48
49/* ------compilation control switches -------------------------*/
50/****************************************************************
51 *  INCLUDE FILES
52 ****************************************************************/
53/* ----- system and platform files ----------------------------*/
54#ifdef UNDER_CE
55#include <windows.h>
56#include <oaf_osal.h>
57#include <omx_core.h>
58#else
59#include <unistd.h>
60#include <sys/time.h>
61#include <sys/types.h>
62#include <sys/ioctl.h>
63#include <sys/select.h>
64#include <errno.h>
65#include <pthread.h>
66#endif
67#include <string.h>
68#include <fcntl.h>
69#include <stdlib.h>
70#include <stdio.h>
71#include <dbapi.h>
72
73/*-------program files ----------------------------------------*/
74#include <OMX_Component.h>
75#include "OMX_WmaDec_Utils.h"
76/* interface with audio manager */
77#define FIFO1 "/dev/fifo.1"
78#define FIFO2 "/dev/fifo.2"
79
80#ifdef DSP_RENDERING_ON
81AM_COMMANDDATATYPE cmd_data;
82int fdwrite, fdread;
83int errno;
84OMX_U32 streamID;
85#endif
86#define WMA_DEC_ROLE "audio_decoder.wma"
87
88#ifdef WMADEC_MEMDEBUG
89void *arr[500];
90int lines[500];
91int bytes[500];
92char file[500][50];
93#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
94#define newfree(z) myfree(z,__LINE__,__FILE__)
95void * mymalloc(int line, char *s, int size);
96int myfree(void *dp, int line, char *s);
97#else
98#define newmalloc(x) malloc(x)
99#define newfree(z) free(z)
100#endif
101
102
103/*FILE *fp = NULL;  /*For dumping buffest debugging ANDROID*/
104
105
106
107/****************************************************************
108 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
109 ****************************************************************/
110/*--------data declarations -----------------------------------*/
111
112/*--------function prototypes ---------------------------------*/
113
114/****************************************************************
115 *  PUBLIC DECLARATIONS Defined here, used elsewhere
116 ****************************************************************/
117/*--------data declarations -----------------------------------*/
118
119/*--------function prototypes ---------------------------------*/
120
121/****************************************************************
122 *  PRIVATE DECLARATIONS Defined here, used only here
123 ****************************************************************/
124/*--------data declarations -----------------------------------*/
125
126/*--------function prototypes ---------------------------------*/
127
128static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
129                                   OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
130static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
131                                          OMX_STRING pComponentName,
132                                          OMX_VERSIONTYPE* pComponentVersion,
133                                          OMX_VERSIONTYPE* pSpecVersion,
134                                          OMX_UUIDTYPE* pComponentUUID);
135
136static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
137                                  OMX_U32 nParam, OMX_PTR pCmdData);
138
139static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex,
140                                  OMX_PTR ComponentParamStruct);
141static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
142                                   OMX_INDEXTYPE nParamIndex,
143                                   OMX_PTR ComponentParamStruct);
144static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
145                                OMX_INDEXTYPE nConfigIndex,
146                                OMX_PTR pComponentConfigStructure);
147static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
148                                OMX_INDEXTYPE nConfigIndex,
149                                OMX_PTR pComponentConfigStructure);
150
151static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
152static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
153
154static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
155static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
156                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
157                                             OMX_U32 nTunneledPort,
158                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
159
160static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
161static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
162                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
163                                     OMX_IN OMX_U32 nPortIndex,
164                                     OMX_IN OMX_PTR pAppPrivate,
165                                     OMX_IN OMX_U32 nSizeBytes);
166
167static OMX_ERRORTYPE FreeBuffer(
168                                OMX_IN  OMX_HANDLETYPE hComponent,
169                                OMX_IN  OMX_U32 nPortIndex,
170                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
171
172static OMX_ERRORTYPE UseBuffer (
173                                OMX_IN OMX_HANDLETYPE hComponent,
174                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
175                                OMX_IN OMX_U32 nPortIndex,
176                                OMX_IN OMX_PTR pAppPrivate,
177                                OMX_IN OMX_U32 nSizeBytes,
178                                OMX_IN OMX_U8* pBuffer);
179
180static OMX_ERRORTYPE GetExtensionIndex(
181                                       OMX_IN  OMX_HANDLETYPE hComponent,
182                                       OMX_IN  OMX_STRING cParameterName,
183                                       OMX_OUT OMX_INDEXTYPE* pIndexType);
184
185static OMX_ERRORTYPE ComponentRoleEnum(
186                                       OMX_IN OMX_HANDLETYPE hComponent,
187                                       OMX_OUT OMX_U8 *cRole,
188                                       OMX_IN OMX_U32 nIndex);
189
190/*-------------------------------------------------------------------*/
191/**
192 * OMX_ComponentInit() Set the all the function pointers of component
193 *
194 * This method will update the component function pointer to the handle
195 *
196 * @param hComp         handle for this instance of the component
197 *
198 * @retval OMX_NoError              Success, ready to roll
199 *         OMX_ErrorInsufficientResources If the malloc fails
200 **/
201/*-------------------------------------------------------------------*/
202OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
203{
204
205    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
206    WMADEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
207    OMX_AUDIO_PARAM_WMATYPE *wma_ip = NULL;
208    OMX_AUDIO_PARAM_PCMMODETYPE *wma_op = NULL;
209    RCA_HEADER *rcaheader=NULL;
210
211    OMX_ERRORTYPE eError = OMX_ErrorNone;
212    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
213    int i;
214
215    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d ::OMX_ComponentInit\n", __LINE__);
216    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d ::LINE\n", __LINE__);
217
218    /*Set the all component function pointer to the handle */
219    pHandle->SetCallbacks = SetCallbacks;
220    pHandle->GetComponentVersion = GetComponentVersion;
221    pHandle->SendCommand = SendCommand;
222    pHandle->GetParameter = GetParameter;
223    pHandle->SetParameter = SetParameter;
224    pHandle->GetConfig = GetConfig;
225    pHandle->GetState = GetState;
226    pHandle->EmptyThisBuffer = EmptyThisBuffer;
227    pHandle->FillThisBuffer = FillThisBuffer;
228    pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
229    pHandle->ComponentDeInit = ComponentDeInit;
230    pHandle->AllocateBuffer = AllocateBuffer;
231    pHandle->FreeBuffer = FreeBuffer;
232    pHandle->UseBuffer = UseBuffer;
233    pHandle->SetConfig = SetConfig;
234    pHandle->GetExtensionIndex = GetExtensionIndex;
235    pHandle->ComponentRoleEnum = ComponentRoleEnum;
236
237
238
239    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d ::LINE\n", __LINE__);
240    /*Allocate the memory for Component private data area */
241    WMAD_OMX_MALLOC(pHandle->pComponentPrivate, WMADEC_COMPONENT_PRIVATE);
242    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
243
244    /* Initialize component data structures to default values */
245    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nPorts = 0x2;
246    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nStartPortNumber = 0x0;
247
248    eError = OMX_ErrorNone;
249
250    WMAD_OMX_MALLOC(wma_ip, OMX_AUDIO_PARAM_WMATYPE);
251    WMAD_OMX_MALLOC(wma_op, OMX_AUDIO_PARAM_PCMMODETYPE);
252    WMAD_OMX_MALLOC(rcaheader, RCA_HEADER);
253
254    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wma_op=wma_op;
255    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->rcaheader=rcaheader;
256
257    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wmaParams[INPUT_PORT] = wma_ip;
258    ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wmaParams[OUTPUT_PORT] = (OMX_AUDIO_PARAM_WMATYPE*)wma_op;
259
260    OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d Malloced wmaParams[INPUT_PORT] = %p\n",__LINE__,((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wmaParams[INPUT_PORT]);
261    OMXDBG_PRINT(stderr, COMM, 2, 0, "%d Malloced wmaParams[OUTPUT_PORT] = %p\n",__LINE__,((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wmaParams[OUTPUT_PORT]);
262
263    pComponentPrivate = pHandle->pComponentPrivate;
264    WMAD_OMX_MALLOC(pComponentPrivate->pInputBufferList, BUFFERLIST);
265    OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_WMADEC");
266
267#ifdef __PERF_INSTRUMENTATION__
268    OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n", __LINE__);
269    pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('W','M','A','_'),
270                                           PERF_ModuleLLMM |
271                                           PERF_ModuleAudioDecode);
272#endif
273
274#ifdef ANDROID
275    pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE;
276    pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE;
277    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
278    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
279    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE;
280    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_TRUE;
281    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE;
282#endif
283
284    pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
285    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
286    WMAD_OMX_MALLOC(pComponentPrivate->pOutputBufferList, BUFFERLIST);
287
288    pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
289    WMAD_OMX_MALLOC(pComponentPrivate->pHeaderInfo, WMA_HeadInfo);
290    WMAD_OMX_MALLOC(pComponentPrivate->pDspDefinition, TI_OMX_DSP_DEFINITION);
291
292    /* Temporarily treat these as default values for Khronos tests */
293    pComponentPrivate->pHeaderInfo->iPackets.dwLo           =   178 ;
294    pComponentPrivate->pHeaderInfo->iPlayDuration.dwHi      =   0   ;
295    pComponentPrivate->pHeaderInfo->iPlayDuration.dwLo      =   917760000 ;
296    pComponentPrivate->pHeaderInfo->iMaxPacketSize          =   349 ;
297    pComponentPrivate->pHeaderInfo->iStreamType.Data1       =   -127295936 ;
298    pComponentPrivate->pHeaderInfo->iStreamType.Data2       =   23373 ;
299    pComponentPrivate->pHeaderInfo->iStreamType.Data3       =   4559 ;
300    pComponentPrivate->pHeaderInfo->iStreamType.Data4[0]    =   168 ;
301    pComponentPrivate->pHeaderInfo->iStreamType.Data4[1]    =   253 ;
302    pComponentPrivate->pHeaderInfo->iStreamType.Data4[2]    =   0   ;
303    pComponentPrivate->pHeaderInfo->iStreamType.Data4[3]    =   128 ;
304    pComponentPrivate->pHeaderInfo->iStreamType.Data4[4]    =   95  ;
305    pComponentPrivate->pHeaderInfo->iStreamType.Data4[5]    =   92  ;
306    pComponentPrivate->pHeaderInfo->iStreamType.Data4[6]    =   68  ;
307    pComponentPrivate->pHeaderInfo->iStreamType.Data4[7]    =   43  ;
308    pComponentPrivate->pHeaderInfo->iTypeSpecific           =   28  ;
309    pComponentPrivate->pHeaderInfo->iStreamNum              =   1   ;
310    pComponentPrivate->pHeaderInfo->iFormatTag              =   353 ;
311    pComponentPrivate->pHeaderInfo->iBlockAlign             =   40  ;
312    pComponentPrivate->pHeaderInfo->iSamplePerSec           =   8000;
313    pComponentPrivate->pHeaderInfo->iAvgBytesPerSec         =   625 ;
314    pComponentPrivate->pHeaderInfo->iChannel                =   1   ;
315    pComponentPrivate->pHeaderInfo->iValidBitsPerSample     =   16  ;
316    pComponentPrivate->pHeaderInfo->iSizeWaveHeader         =   10  ;
317    pComponentPrivate->pHeaderInfo->iEncodeOptV             =   0   ;
318    pComponentPrivate->pHeaderInfo->iValidBitsPerSample     =   16  ;
319    pComponentPrivate->pHeaderInfo->iChannelMask            =   0   ;
320    pComponentPrivate->pHeaderInfo->iSamplePerBlock         =   8704;
321
322
323    pComponentPrivate->bConfigData = 0;  /* assume the first buffer received will contain only config data, need to use bufferFlag instead */
324    pComponentPrivate->reconfigInputPort = 0;
325    pComponentPrivate->reconfigOutputPort = 0;
326
327    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
328        pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
329        pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
330    }
331    pComponentPrivate->dasfmode = 0;
332    pComponentPrivate->bPortDefsAllocated = 0;
333    pComponentPrivate->bCompThreadStarted = 0;
334    pComponentPrivate->bInitParamsInitialized = 0;
335    pComponentPrivate->pMarkBuf = NULL;
336    pComponentPrivate->pMarkData = NULL;
337    pComponentPrivate->nEmptyBufferDoneCount = 0;
338    pComponentPrivate->nEmptyThisBufferCount = 0;
339    pComponentPrivate->strmAttr = NULL;
340    pComponentPrivate->bDisableCommandParam = 0;
341    pComponentPrivate->bEnableCommandParam = 0;
342
343    pComponentPrivate->nUnhandledFillThisBuffers=0;
344    pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
345    pComponentPrivate->SendAfterEOS = 0;
346
347    pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
348    pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
349
350
351
352    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
353        pComponentPrivate->pInputBufHdrPending[i] = NULL;
354        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
355    }
356    pComponentPrivate->nInvalidFrameCount = 0;
357    pComponentPrivate->nNumInputBufPending = 0;
358    pComponentPrivate->nNumOutputBufPending = 0;
359    pComponentPrivate->bDisableCommandPending = 0;
360    pComponentPrivate->bEnableCommandPending = 0;
361    pComponentPrivate->bBypassDSP = OMX_FALSE;
362    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
363    pComponentPrivate->bIdleCommandPending = OMX_FALSE;
364    pComponentPrivate->nOutStandingFillDones = 0;
365
366    pComponentPrivate->sInPortFormat.eEncoding = OMX_AUDIO_CodingWMA;
367    pComponentPrivate->sInPortFormat.nIndex = 0;
368    pComponentPrivate->sInPortFormat.nPortIndex = INPUT_PORT;
369    pComponentPrivate->bPreempted = OMX_FALSE;
370
371    pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM;  /*chrisk*/
372    pComponentPrivate->sOutPortFormat.nIndex = 1;
373    pComponentPrivate->sOutPortFormat.nPortIndex = OUTPUT_PORT;
374
375    WMAD_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), OMX_STRING);
376
377
378    /* PCM format defaults */
379    wma_op->nPortIndex = 1;
380    wma_op->nChannels = 2;
381    wma_op->eNumData= OMX_NumericalDataSigned;
382    wma_op->nBitPerSample = 16;
383    wma_op->nSamplingRate = 44100;
384    wma_op->ePCMMode = OMX_AUDIO_PCMModeLinear;
385
386
387    /* WMA format defaults */
388    wma_ip->nPortIndex = 0;
389    wma_ip->nChannels = 2;
390    wma_ip->nBitRate = 32000;
391    wma_ip->nSamplingRate = 44100;
392
393    /* initialize role name */
394    strcpy((char *) pComponentPrivate->componentRole.cRole, WMA_DEC_ROLE);
395    /* Initialize device string to the default value */
396    strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
397
398    /* Removing sleep() calls. Initialization.*/
399#ifndef UNDER_CE
400    pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
401    pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
402    pComponentPrivate->AlloBuf_waitingsignal = 0;
403
404    pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
405    pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
406    pComponentPrivate->InLoaded_readytoidle = 0;
407
408    pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
409    pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
410    pComponentPrivate->InIdle_goingtoloaded = 0;
411
412    pthread_mutex_init(&pComponentPrivate->codecStop_mutex, NULL);
413    pthread_cond_init (&pComponentPrivate->codecStop_threshold, NULL);
414    pComponentPrivate->codecStop_waitingsignal = 0;
415
416    pthread_mutex_init(&pComponentPrivate->codecFlush_mutex, NULL);
417    pthread_cond_init (&pComponentPrivate->codecFlush_threshold, NULL);
418    pComponentPrivate->codecFlush_waitingsignal = 0;
419#else
420    OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
421    pComponentPrivate->AlloBuf_waitingsignal = 0;
422
423    OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
424    pComponentPrivate->InLoaded_readytoidle = 0;
425
426    OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
427    pComponentPrivate->InIdle_goingtoloaded = 0;
428#endif
429    /* Removing sleep() calls. Initialization.*/
430
431    WMAD_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
432    WMAD_OMX_MALLOC(pPortDef_op,OMX_PARAM_PORTDEFINITIONTYPE );
433
434    OMX_PRCOMM2(pComponentPrivate->dbg, "%d ::pPortDef_ip = %p\n", __LINE__,pPortDef_ip);
435    OMX_PRCOMM2(pComponentPrivate->dbg, "%d ::pPortDef_op = %p\n", __LINE__,pPortDef_op);
436
437    ((WMADEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[INPUT_PORT]
438        = pPortDef_ip;
439
440    ((WMADEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[OUTPUT_PORT]
441        = pPortDef_op;
442
443    pPortDef_ip->nPortIndex = 0x0;
444    pPortDef_ip->nBufferCountActual = NUM_WMADEC_INPUT_BUFFERS;
445    pPortDef_ip->nBufferCountMin = NUM_WMADEC_INPUT_BUFFERS;
446    pPortDef_ip->eDir = OMX_DirInput;
447    pPortDef_ip->bEnabled = OMX_TRUE;
448    pPortDef_ip->nBufferAlignment = WMA_CACHE_ALIGN;
449    pPortDef_ip->nBufferSize = INPUT_WMADEC_BUFFER_SIZE;
450    pPortDef_ip->bPopulated = 0;
451    pPortDef_ip->eDomain = OMX_PortDomainAudio;
452    pPortDef_ip->format.audio.eEncoding = OMX_AUDIO_CodingWMA;
453
454    pPortDef_op->nPortIndex = 0x1;
455    pPortDef_op->nBufferCountActual = NUM_WMADEC_OUTPUT_BUFFERS;
456    pPortDef_op->nBufferCountMin = NUM_WMADEC_OUTPUT_BUFFERS;
457    pPortDef_op->nBufferAlignment = WMA_CACHE_ALIGN;
458    pPortDef_op->eDir = OMX_DirOutput;
459    pPortDef_op->bEnabled = OMX_TRUE;
460    if(pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize == 0)
461    {
462        pPortDef_op->nBufferSize = OUTPUT_WMADEC_BUFFER_SIZE;
463    }
464    else
465    {
466        pPortDef_op->nBufferSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
467    }
468    pPortDef_op->bPopulated = 0;
469    pPortDef_op->eDomain = OMX_PortDomainAudio;
470    pComponentPrivate->bIsInvalidState = OMX_FALSE;
471    /*    sPortFormat->eEncoding = OMX_AUDIO_CodingPCM; */ /*chrisk*/
472    pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingPCM;  /*chrisk*/
473
474#ifdef RESOURCE_MANAGER_ENABLED
475    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: Initialize RM Proxy... \n", __LINE__);
476    eError = RMProxy_NewInitalize();
477    OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);
478    if (eError != OMX_ErrorNone) {
479        OMX_ERROR4(pComponentPrivate->dbg, "%d ::Error returned from loading ResourceManagerProxy thread\n",
480                       __LINE__);
481        goto EXIT;
482    }
483#endif
484    OMX_PRINT1(pComponentPrivate->dbg, "%d ::Start Component Thread \n", __LINE__);
485    eError = WMADEC_StartComponentThread(pHandle);
486    /*OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);*/
487    if (eError != OMX_ErrorNone) {
488        OMX_ERROR4(pComponentPrivate->dbg, "%d ::Error returned from the Component\n",
489                       __LINE__);
490        goto EXIT;
491    }
492    OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);
493
494
495
496
497#ifdef DSP_RENDERING_ON
498    OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);
499    if((fdwrite=open(FIFO1,O_WRONLY))<0) {
500        OMX_TRACE4(pComponentPrivate->dbg, "[WMA Dec Component] - failure to open WRITE pipe\n");
501        eError = OMX_ErrorHardware;
502    }
503
504    OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);
505    if((fdread=open(FIFO2,O_RDONLY))<0) {
506        OMX_TRACE4(pComponentPrivate->dbg, "[WMA Dec Component] - failure to open READ pipe\n");
507        eError = OMX_ErrorHardware;
508    }
509    OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_ComponentInit\n", __LINE__);
510
511#endif
512#ifdef __PERF_INSTRUMENTATION__
513    OMX_PRINT1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
514    PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->ComponentThread,
515                       PERF_FOURCC('W','M','A','T'));
516#endif
517 EXIT:
518
519
520
521    OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_ComponentInit - returning %d\n", __LINE__,eError);
522    if(eError == OMX_ErrorInsufficientResources)
523    {
524        OMX_WMADECMEMFREE_STRUCT(pPortDef_op);
525        OMX_WMADECMEMFREE_STRUCT(pPortDef_ip);
526        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
527        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
528        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
529        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
530        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
531        OMX_WMADECMEMFREE_STRUCT(wma_op);
532        OMX_WMADECMEMFREE_STRUCT(wma_ip);
533        OMX_WMADECMEMFREE_STRUCT(pHandle->pComponentPrivate);
534
535    }
536    return eError;
537}
538
539/*-------------------------------------------------------------------*/
540/**
541 *  SetCallbacks() Sets application callbacks to the component
542 *
543 * This method will update application callbacks
544 * to the component. So that component can make use of those call back
545 * while sending buffers to the application. And also it will copy the
546 * application private data to component memory
547 *
548 * @param pComponent    handle for this instance of the component
549 * @param pCallBacks    application callbacks
550 * @param pAppData      Application private data
551 *
552 * @retval OMX_NoError              Success, ready to roll
553 *         OMX_Error_BadParameter   The input parameter pointer is null
554 **/
555/*-------------------------------------------------------------------*/
556
557static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
558                                   OMX_CALLBACKTYPE* pCallBacks,
559                                   OMX_PTR pAppData)
560{
561
562    OMX_ERRORTYPE eError = OMX_ErrorNone;
563
564    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
565
566    WMADEC_COMPONENT_PRIVATE *pComponentPrivate =
567        (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
568
569    if (pCallBacks == NULL) {
570        OMX_PRINT1(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
571        eError = OMX_ErrorBadParameter;
572        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Received the empty callbacks from the \
573                application\n",__LINE__);
574        goto EXIT;
575    }
576
577    /*Copy the callbacks of the application to the component private */
578    memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
579
580    /*copy the application private data to component memory */
581    pHandle->pApplicationPrivate = pAppData;
582
583    pComponentPrivate->curState = OMX_StateLoaded;
584#ifdef __PERF_INSTRUMENTATION__
585    OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
586    /*               PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);*/
587#endif
588 EXIT:
589    return eError;
590}
591
592/*-------------------------------------------------------------------*/
593/**
594 *  GetComponentVersion() This will return the component version
595 *
596 * This method will retrun the component version
597 *
598 * @param hComp               handle for this instance of the component
599 * @param pCompnentName       Name of the component
600 * @param pCompnentVersion    handle for this instance of the component
601 * @param pSpecVersion        application callbacks
602 * @param pCompnentUUID
603 *
604 * @retval OMX_NoError              Success, ready to roll
605 *         OMX_Error_BadParameter   The input parameter pointer is null
606 **/
607/*-------------------------------------------------------------------*/
608
609static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
610                                          OMX_STRING pComponentName,
611                                          OMX_VERSIONTYPE* pComponentVersion,
612                                          OMX_VERSIONTYPE* pSpecVersion,
613                                          OMX_UUIDTYPE* pComponentUUID)
614{
615
616    OMX_ERRORTYPE eError = OMX_ErrorNone;
617    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
618    WMADEC_COMPONENT_PRIVATE *pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
619    eError = OMX_ErrorNotImplemented;
620#ifdef _ERROR_PROPAGATION__
621    if (pComponentPrivate->curState == OMX_StateInvalid){
622        eError = OMX_ErrorInvalidState;
623        goto EXIT;
624    }
625#endif
626
627 EXIT:
628    OMX_PRINT1(pComponentPrivate->dbg, "Inside the GetComponentVersion\n");
629    return eError;
630
631}
632
633
634/*-------------------------------------------------------------------*/
635/**
636 *  SendCommand() used to send the commands to the component
637 *
638 * This method will be used by the application.
639 *
640 * @param phandle         handle for this instance of the component
641 * @param Cmd             Command to be sent to the component
642 * @param nParam          indicates commmad is sent using this method
643 *
644 * @retval OMX_NoError              Success, ready to roll
645 *         OMX_Error_BadParameter   The input parameter pointer is null
646 **/
647/*-------------------------------------------------------------------*/
648
649static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
650                                  OMX_COMMANDTYPE Cmd,
651                                  OMX_U32 nParam,OMX_PTR pCmdData)
652{
653
654    OMX_ERRORTYPE eError = OMX_ErrorNone;
655    int nRet;
656    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
657    WMADEC_COMPONENT_PRIVATE *pCompPrivate =
658        (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
659
660#ifdef _ERROR_PROPAGATION__
661    if (pCompPrivate->curState == OMX_StateInvalid){
662        eError = OMX_ErrorInvalidState;
663        goto EXIT;
664    }
665#else
666    OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
667    if(pCompPrivate->curState == OMX_StateInvalid){
668        eError = OMX_ErrorInvalidState;
669        OMX_ERROR4(pCompPrivate->dbg, "%d :: WMADEC: Error Notofication Sent to App\n",__LINE__);
670        pCompPrivate->cbInfo.EventHandler (
671                                           pHandle, pHandle->pApplicationPrivate,
672                                           OMX_EventError, OMX_ErrorInvalidState,0,
673                                           "Invalid State");
674
675        goto EXIT;
676    }
677#endif
678
679#ifdef __PERF_INSTRUMENTATION__
680    OMX_PRDSP1(pCompPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
681    PERF_SendingCommand(pCompPrivate->pPERF,
682                        Cmd,
683                        (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam,
684                        PERF_ModuleComponent);
685#endif
686
687    switch(Cmd) {
688    case OMX_CommandStateSet:
689        OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
690        OMX_PRSTATE2(pCompPrivate->dbg, "%d:::pCompPrivate->curState = %d\n",__LINE__,pCompPrivate->curState);
691        if (nParam == OMX_StateLoaded) {
692            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
693        }
694        if(pCompPrivate->curState == OMX_StateLoaded) {
695            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
696                pCompPrivate->cbInfo.EventHandler (
697                                                   pHandle,
698                                                   pHandle->pApplicationPrivate,
699                                                   OMX_EventError,
700                                                   OMX_ErrorIncorrectStateTransition,
701                                                   0,
702                                                   NULL);
703                goto EXIT;
704            }
705
706            if(nParam == OMX_StateInvalid) {
707                OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
708                pCompPrivate->curState = OMX_StateInvalid;
709                pCompPrivate->cbInfo.EventHandler (
710                                                   pHandle,
711                                                   pHandle->pApplicationPrivate,
712                                                   OMX_EventError,
713                                                   OMX_ErrorInvalidState,
714                                                   0,
715                                                   NULL);
716                goto EXIT;
717            }
718        }
719        break;
720    case OMX_CommandFlush:
721        if(nParam > 1 && nParam != -1) {
722            eError = OMX_ErrorBadPortIndex;
723            goto EXIT;
724        }
725
726        break;
727    case OMX_CommandPortDisable:
728        break;
729    case OMX_CommandPortEnable:
730        break;
731    case OMX_CommandMarkBuffer:
732        if (nParam > 0) {
733            eError = OMX_ErrorBadPortIndex;
734            goto EXIT;
735        }
736        break;
737    default:
738        OMX_PRDSP2(pCompPrivate->dbg, "%d :: WMADEC: Command Received Default \
739                                                      error\n",__LINE__);
740        pCompPrivate->cbInfo.EventHandler (
741                                           pHandle, pHandle->pApplicationPrivate,
742                                           OMX_EventError,
743                                           OMX_ErrorUndefined,0,
744                                           "Invalid Command");
745        break;
746
747    }
748
749    OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
750    nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
751    if (nRet == -1) {
752        OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
753        eError = OMX_ErrorInsufficientResources;
754        goto EXIT;
755    }
756
757    if (Cmd == OMX_CommandMarkBuffer) {
758        nRet = write(pCompPrivate->cmdDataPipe[1],&pCmdData,sizeof(OMX_PTR));
759    }
760    else {
761        nRet = write(pCompPrivate->cmdDataPipe[1], &nParam,
762                     sizeof(OMX_U32));
763    }
764
765    OMX_PRINT1(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
766    OMX_PRINT2(pCompPrivate->dbg, "%d:::nRet = %d\n",__LINE__,nRet);
767    if (nRet == -1) {
768        OMX_ERROR4(pCompPrivate->dbg, "%d:::Inside SendCommand\n",__LINE__);
769        eError = OMX_ErrorInsufficientResources;
770        goto EXIT;
771    }
772 EXIT:
773    return eError;
774}
775/*-------------------------------------------------------------------*/
776/**
777 *  GetParameter() Gets the current configurations of the component
778 *
779 * @param hComp         handle for this instance of the component
780 * @param nParamIndex
781 * @param ComponentParameterStructure
782 *
783 * @retval OMX_NoError              Success, ready to roll
784 *         OMX_Error_BadParameter   The input parameter pointer is null
785 **/
786/*-------------------------------------------------------------------*/
787static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
788                                   OMX_INDEXTYPE nParamIndex,
789                                   OMX_PTR ComponentParameterStructure)
790{
791
792    OMX_ERRORTYPE eError = OMX_ErrorNone;
793    WMADEC_COMPONENT_PRIVATE  *pComponentPrivate;
794    OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure;
795    /*OMX_PARAM_BUFFERSUPPLIERTYPE *pBufferSupplier;*/
796
797    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
798    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
799
800    if (pParameterStructure == NULL) {
801        eError = OMX_ErrorBadParameter;
802        goto EXIT;
803
804    }
805    OMX_PRINT1(pComponentPrivate->dbg, "pParameterStructure = %p\n",pParameterStructure);
806#ifdef _ERROR_PROPAGATION__
807    if (pComponentPrivate->curState == OMX_StateInvalid){
808        eError = OMX_ErrorInvalidState;
809        goto EXIT;
810    }
811#else
812    if(pComponentPrivate->curState == OMX_StateInvalid) {
813        pComponentPrivate->cbInfo.EventHandler(
814                                               hComp,
815                                               ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate,
816                                               OMX_EventError,
817                                               OMX_ErrorIncorrectStateOperation,
818                                               0,
819                                               NULL);
820
821    }
822#endif
823    switch(nParamIndex){
824    case OMX_IndexParamAudioInit:
825
826        OMX_PRINT1(pComponentPrivate->dbg, "OMX_IndexParamAudioInit\n");
827        memcpy(ComponentParameterStructure, &pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
828        break;
829    case OMX_IndexParamPortDefinition:
830        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
831           pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) {
832
833
834            memcpy(ComponentParameterStructure,
835                   pComponentPrivate->pPortDef[INPUT_PORT],
836                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
837                   );
838        }
839        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
840                pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) {
841
842
843            memcpy(ComponentParameterStructure,
844                   pComponentPrivate->pPortDef[OUTPUT_PORT],
845                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
846                   );
847
848        }
849        else {
850            eError = OMX_ErrorBadPortIndex;
851        }
852        break;
853
854    case OMX_IndexParamAudioPortFormat:
855        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
856           pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) {
857
858            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
859               pComponentPrivate->sInPortFormat.nIndex) {
860
861                eError = OMX_ErrorNoMore;
862            }
863            else {
864                memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat,
865                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
866            }
867        }
868        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
869                pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex){
870
871
872            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
873               pComponentPrivate->sOutPortFormat.nIndex) {
874
875                eError = OMX_ErrorNoMore;
876            }
877            else {
878
879                memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat,
880                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
881            }
882        }
883        else {
884
885            eError = OMX_ErrorBadPortIndex;
886        }
887        break;
888
889    case OMX_IndexParamPriorityMgmt:
890        break;
891    case OMX_IndexParamAudioWma:
892        OMX_PRINT2(pComponentPrivate->dbg, "%d :: GetParameter OMX_IndexParamAudioWma \n",__LINE__);
893        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: GetParameter nPortIndex %ld\n",__LINE__, ((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex);
894        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: GetParameter wmaParams->nPortIndex %ld\n",__LINE__, pComponentPrivate->wmaParams[INPUT_PORT]->nPortIndex);
895        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
896           pComponentPrivate->wmaParams[INPUT_PORT]->nPortIndex)
897        {
898            memcpy(ComponentParameterStructure, pComponentPrivate->wmaParams[INPUT_PORT], sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
899        }
900        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nPortIndex ==
901                pComponentPrivate->wmaParams[OUTPUT_PORT]->nPortIndex)
902        {
903            memcpy(ComponentParameterStructure, pComponentPrivate->wmaParams[OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
904
905        }
906        else
907        {
908
909            eError = OMX_ErrorBadPortIndex;
910        }
911        break;
912    case OMX_IndexParamAudioPcm:
913        memcpy(ComponentParameterStructure,
914               (OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->wma_op,
915               sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)
916               );
917        break;
918
919    case OMX_IndexParamCompBufferSupplier:
920        if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) {
921            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamCompBufferSupplier \n");
922            /*  memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
923
924        }
925        else if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) {
926            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamCompBufferSupplier \n");
927            /*memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
928        }
929        else {
930            OMX_ERROR2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter");
931            eError = OMX_ErrorBadPortIndex;
932        }
933        break;
934
935    case OMX_IndexParamVideoInit:
936        break;
937
938    case OMX_IndexParamImageInit:
939        break;
940
941    case OMX_IndexParamOtherInit:
942        /*#ifdef ANDROID
943          OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamVideoInit\n", __LINE__);
944          OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamImageInit/OtherInit\n", __LINE__);
945          memcpy(ComponentParameterStructure,pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
946
947
948          eError = OMX_ErrorNone;
949          #else
950          eError = OMX_ErrorUnsupportedIndex;
951          #endif*/
952        break;
953
954#ifdef ANDROID
955    case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
956        {
957            OMX_PRDSP1(pComponentPrivate->dbg, "Entering PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX::%d\n", __LINE__);
958            PV_OMXComponentCapabilityFlagsType* pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
959            if (NULL == pCap_flags)
960            {
961                OMX_ERROR4(pComponentPrivate->dbg, "%d :: ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__);
962                eError =  OMX_ErrorBadParameter;
963                goto EXIT;
964            }
965            OMX_ERROR2(pComponentPrivate->dbg, "%d :: Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__);
966            memcpy(pCap_flags, &(pComponentPrivate->iPVCapabilityFlags), sizeof(PV_OMXComponentCapabilityFlagsType));
967            eError = OMX_ErrorNone;
968        }
969        break;
970#endif
971    default:
972        eError = OMX_ErrorUnsupportedIndex;
973        break;
974    }
975 EXIT:
976    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting GetParameter:: %x\n",__LINE__,nParamIndex);
977    return eError;
978}
979
980/*-------------------------------------------------------------------*/
981/**
982 *  SetParameter() Sets configuration paramets to the component
983 *
984 * @param hComp         handle for this instance of the component
985 * @param nParamIndex
986 * @param pCompParam
987 *
988 * @retval OMX_NoError              Success, ready to roll
989 *         OMX_Error_BadParameter   The input parameter pointer is null
990 **/
991/*-------------------------------------------------------------------*/
992
993static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
994                                   OMX_INDEXTYPE nParamIndex,
995                                   OMX_PTR pCompParam)
996{
997
998
999    OMX_ERRORTYPE eError = OMX_ErrorNone;
1000    OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
1001    WMADEC_COMPONENT_PRIVATE  *pComponentPrivate;
1002    OMX_PARAM_PORTDEFINITIONTYPE *pComponentParam = NULL;
1003    OMX_PARAM_COMPONENTROLETYPE  *pRole;
1004    OMX_AUDIO_PARAM_PCMMODETYPE *wma_op;
1005    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
1006    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1007
1008
1009
1010    if (pCompParam == NULL) {
1011        eError = OMX_ErrorBadParameter;
1012        goto EXIT;
1013    }
1014
1015#ifdef _ERROR_PROPAGATION__
1016    if (pComponentPrivate->curState == OMX_StateInvalid){
1017        eError = OMX_ErrorInvalidState;
1018        goto EXIT;
1019    }
1020#endif
1021
1022    switch(nParamIndex) {
1023    case OMX_IndexParamAudioPortFormat:
1024        pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
1025
1026        /* 0 means Input port */
1027        if (pComponentParam->nPortIndex == 0) {
1028            if (pComponentParam->eDir != OMX_DirInput) {
1029                OMX_PRBUFFER4(pComponentPrivate->dbg, "%d :: Invalid input buffer Direction\n",__LINE__);
1030                eError = OMX_ErrorBadParameter;
1031                OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1032                goto EXIT;
1033            }
1034
1035        }
1036        else if (pComponentParam->nPortIndex == 1) {
1037            /* 1 means Output port */
1038
1039            if (pComponentParam->eDir != OMX_DirOutput) {
1040                eError = OMX_ErrorBadParameter;
1041                OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1042                goto EXIT;
1043            }
1044            pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize = pComponentParam->nBufferSize;
1045            /*
1046              if (pComponentParam->nBufferSize != OUTPUT_WMADEC_BUFFER_SIZE) {
1047              eError = OMX_ErrorBadParameter;
1048              OMX_PRINT1(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1049              goto EXIT;
1050              }
1051
1052              if (pComponentParam->format.audio.eEncoding != OMX_AUDIO_CodingPCM) {
1053              eError = OMX_ErrorBadParameter;
1054              goto EXIT;
1055              } */
1056        }
1057        else {
1058            eError = OMX_ErrorBadParameter;
1059            goto EXIT;
1060        }
1061        break;
1062    case OMX_IndexParamAudioWma:
1063        {
1064            OMX_AUDIO_PARAM_WMATYPE *pCompWmaParam =
1065                (OMX_AUDIO_PARAM_WMATYPE *)pCompParam;
1066
1067            /* 0 means Input port */
1068            if(pCompWmaParam->nPortIndex == 0) {
1069                OMX_PRCOMM2(pComponentPrivate->dbg, "pCompWmaParam->nPortIndex == 0\n");
1070                memcpy(((WMADEC_COMPONENT_PRIVATE*)
1071                        pHandle->pComponentPrivate)->wmaParams[INPUT_PORT],
1072                       pCompWmaParam, sizeof(OMX_AUDIO_PARAM_WMATYPE));
1073
1074            } else if (pCompWmaParam->nPortIndex == 1) {
1075                pComponentPrivate->wmaParams[OUTPUT_PORT]->nSize = pCompWmaParam->nSize;
1076                pComponentPrivate->wmaParams[OUTPUT_PORT]->nPortIndex = pCompWmaParam->nPortIndex;
1077                pComponentPrivate->wmaParams[OUTPUT_PORT]->nBitRate = pCompWmaParam->nBitRate;
1078                pComponentPrivate->wmaParams[OUTPUT_PORT]->eFormat = pCompWmaParam->eFormat;
1079            }
1080            else {
1081                eError = OMX_ErrorBadPortIndex;
1082            }
1083        }
1084        break;
1085    case OMX_IndexParamPortDefinition:
1086        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1087           pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) {
1088
1089            memcpy(pComponentPrivate->pPortDef[INPUT_PORT],
1090                   pCompParam,
1091                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
1092                   );
1093
1094        }
1095        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1096                pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) {
1097
1098            memcpy(pComponentPrivate->pPortDef[OUTPUT_PORT],
1099                   pCompParam,
1100                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
1101                   );
1102
1103        }
1104        else {
1105            eError = OMX_ErrorBadPortIndex;
1106        }
1107        break;
1108    case OMX_IndexParamPriorityMgmt:
1109        if (pComponentPrivate->curState != OMX_StateLoaded) {
1110            eError = OMX_ErrorIncorrectStateOperation;
1111        }
1112        break;
1113    case OMX_IndexParamStandardComponentRole:
1114        if (pCompParam) {
1115            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
1116            memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1117        } else {
1118            eError = OMX_ErrorBadParameter;
1119        }
1120        break;
1121
1122    case OMX_IndexParamAudioPcm:
1123        if(pCompParam){
1124            wma_op = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
1125            memcpy(pComponentPrivate->wma_op, wma_op, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
1126        }
1127        else{
1128            eError = OMX_ErrorBadParameter;
1129        }
1130        break;
1131
1132    case OMX_IndexParamCompBufferSupplier:
1133        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1134           pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) {
1135            OMX_PRINT2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1136            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
1137            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1138        }
1139        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1140                pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) {
1141            OMX_PRINT2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1142            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
1143            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1144        }
1145        else {
1146            OMX_ERROR2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
1147            eError = OMX_ErrorBadPortIndex;
1148        }
1149        break;
1150    default:
1151        break;
1152
1153    }
1154 EXIT:
1155    return eError;
1156}
1157/*-------------------------------------------------------------------*/
1158/**
1159 *  GetConfig() Gets the current configuration of to the component
1160 *
1161 * @param hComp         handle for this instance of the component
1162 * @param nConfigIndex
1163 * @param ComponentConfigStructure
1164 *
1165 * @retval OMX_NoError              Success, ready to roll
1166 *         OMX_Error_BadParameter   The input parameter pointer is null
1167 **/
1168/*-------------------------------------------------------------------*/
1169
1170static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1171                                OMX_INDEXTYPE nConfigIndex,
1172                                OMX_PTR ComponentConfigStructure)
1173{
1174
1175    OMX_ERRORTYPE eError = OMX_ErrorNone;
1176
1177    WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
1178    TI_OMX_STREAM_INFO *streamInfo;
1179
1180    WMAD_OMX_MALLOC(streamInfo, TI_OMX_STREAM_INFO);
1181    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
1182        (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1183
1184    OMX_PRINT1(pComponentPrivate->dbg, "Inside   GetConfig\n");
1185
1186#ifdef _ERROR_PROPAGATION__
1187    if (pComponentPrivate->curState == OMX_StateInvalid){
1188        eError = OMX_ErrorInvalidState;
1189        goto EXIT;
1190    }
1191#endif
1192
1193    if(nConfigIndex == OMX_IndexCustomWmaDecStreamIDConfig)
1194    {
1195        /* copy component info */
1196        streamInfo->streamId = pComponentPrivate->streamID;
1197        memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO));
1198    } else if (nConfigIndex == OMX_IndexCustomDebug) {
1199	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1200    }
1201
1202 EXIT:
1203    if(streamInfo)
1204    {
1205        free(streamInfo);
1206        streamInfo = NULL;
1207    }
1208    OMX_PRINT1(pComponentPrivate->dbg, "Exiting  GetConfig\n");
1209    return eError;
1210}
1211/*-------------------------------------------------------------------*/
1212/**
1213 *  SetConfig() Sets the configraiton to the component
1214 *
1215 * @param hComp         handle for this instance of the component
1216 * @param nConfigIndex
1217 * @param ComponentConfigStructure
1218 *
1219 * @retval OMX_NoError              Success, ready to roll
1220 *         OMX_Error_BadParameter   The input parameter pointer is null
1221 **/
1222/*-------------------------------------------------------------------*/
1223
1224static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1225                                OMX_INDEXTYPE nConfigIndex,
1226                                OMX_PTR ComponentConfigStructure)
1227{
1228    OMX_ERRORTYPE eError = OMX_ErrorNone;
1229    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1230    WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
1231    WMA_HeadInfo* headerInfo = NULL;
1232    TI_OMX_DSP_DEFINITION* pDspDefinition = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1233    /*int flagValue = 0;*/
1234    OMX_S16* deviceString;
1235    TI_OMX_DATAPATH dataPath;
1236    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: Entering SetConfig\n", __LINE__);
1237    if (pHandle == NULL) {
1238        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__);
1239        eError = OMX_ErrorBadParameter;
1240        goto EXIT;
1241    }
1242    pComponentPrivate =  (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1243    OMX_PRSTATE1(pComponentPrivate->dbg, "Set Config %d\n",__LINE__);
1244
1245#ifdef _ERROR_PROPAGATION__
1246    if (pComponentPrivate->curState == OMX_StateInvalid){
1247        eError = OMX_ErrorInvalidState;
1248        goto EXIT;
1249    }
1250#endif
1251
1252    switch (nConfigIndex) {
1253    case OMX_IndexCustomWMADECHeaderInfoConfig:
1254        memcpy(pComponentPrivate->pDspDefinition,pDspDefinition,sizeof(TI_OMX_DSP_DEFINITION));
1255        headerInfo = pDspDefinition->wmaHeaderInfo;
1256        memcpy(pComponentPrivate->pHeaderInfo,headerInfo,sizeof(WMA_HeadInfo));
1257        if(pComponentPrivate->pDspDefinition->dasfMode == 0){
1258            pComponentPrivate->dasfmode = 0;
1259        }
1260        else if (pComponentPrivate->pDspDefinition->dasfMode == 1) {
1261            pComponentPrivate->dasfmode = 1;
1262        }
1263        else if(pComponentPrivate->pDspDefinition->dasfMode == 2) {
1264            pComponentPrivate->dasfmode = 1;
1265        }
1266        pComponentPrivate->streamID = pDspDefinition->streamId;
1267        break;
1268    case  OMX_IndexCustomWmaDecDataPath:
1269        deviceString = (OMX_S16*)ComponentConfigStructure;
1270        if (deviceString == NULL)
1271        {
1272            eError = OMX_ErrorBadParameter;
1273            goto EXIT;
1274        }
1275
1276        dataPath = *deviceString;
1277        switch(dataPath)
1278        {
1279        case DATAPATH_APPLICATION:
1280            OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID);
1281            break;
1282
1283        case DATAPATH_APPLICATION_RTMIXER:
1284            strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1285            break;
1286
1287        case DATAPATH_ACDN:
1288            strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1289            break;
1290
1291        default:
1292            break;
1293        }
1294        break;
1295    case OMX_IndexCustomDebug:
1296	OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1297	break;
1298    default:
1299        eError = OMX_ErrorUnsupportedIndex;
1300        break;
1301    }
1302 EXIT:
1303    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting SetConfig\n", __LINE__);
1304    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
1305    return eError;
1306
1307
1308}
1309/*-------------------------------------------------------------------*/
1310/**
1311 *  GetState() Gets the current state of the component
1312 *
1313 * @param pCompomponent handle for this instance of the component
1314 * @param pState
1315 *
1316 * @retval OMX_NoError              Success, ready to roll
1317 *         OMX_Error_BadParameter   The input parameter pointer is null
1318 **/
1319/*-------------------------------------------------------------------*/
1320
1321static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1322{
1323
1324    OMX_ERRORTYPE error = OMX_ErrorUndefined;
1325    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1326
1327    if (!pState) {
1328        error = OMX_ErrorBadParameter;
1329        OMXDBG_PRINT(stderr, ERROR, 4, 0, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1330        goto EXIT;
1331    }
1332
1333    if (pHandle && pHandle->pComponentPrivate) {
1334        *pState =  ((WMADEC_COMPONENT_PRIVATE*)
1335                    pHandle->pComponentPrivate)->curState;
1336    } else {
1337        *pState = OMX_StateLoaded;
1338    }
1339
1340    error = OMX_ErrorNone;
1341
1342 EXIT:
1343    return error;
1344}
1345
1346/*-------------------------------------------------------------------*/
1347/**
1348 *  EmptyThisBuffer() This callback is used to send the input buffer to
1349 *  component
1350 *
1351 * @param pComponent       handle for this instance of the component
1352 * @param nPortIndex       input port index
1353 * @param pBuffer          buffer to be sent to codec
1354 *
1355 * @retval OMX_NoError              Success, ready to roll
1356 *         OMX_Error_BadParameter   The input parameter pointer is null
1357 **/
1358/*-------------------------------------------------------------------*/
1359static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1360                                      OMX_BUFFERHEADERTYPE* pBuffer)
1361{
1362    OMX_ERRORTYPE eError = OMX_ErrorNone;
1363    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1364    WMADEC_COMPONENT_PRIVATE *pComponentPrivate =
1365        (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1366    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1367    int ret=0;
1368    pPortDef = ((WMADEC_COMPONENT_PRIVATE*)
1369                pComponentPrivate)->pPortDef[INPUT_PORT];
1370#ifdef _ERROR_PROPAGATION__
1371    if (pComponentPrivate->curState == OMX_StateInvalid){
1372        eError = OMX_ErrorInvalidState;
1373        goto EXIT;
1374    }
1375#endif
1376#ifdef __PERF_INSTRUMENTATION__
1377    OMX_PRINT1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1378    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1379                       pBuffer->pBuffer,
1380                       pBuffer->nFilledLen,
1381                       PERF_ModuleHLMM);
1382#endif
1383    if(!pPortDef->bEnabled) {
1384        eError = OMX_ErrorIncorrectStateOperation;
1385        goto EXIT;
1386    }
1387
1388    if (pBuffer == NULL) {
1389        eError = OMX_ErrorBadParameter;
1390        OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1391        goto EXIT;
1392    }
1393
1394    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1395        eError = OMX_ErrorBadParameter;
1396        goto EXIT;
1397    }
1398
1399    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1400        eError = OMX_ErrorVersionMismatch;
1401        goto EXIT;
1402    }
1403
1404    if (pBuffer->nInputPortIndex != INPUT_PORT) {
1405        eError  = OMX_ErrorBadPortIndex;
1406        goto EXIT;
1407    }
1408
1409    if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause
1410       && pComponentPrivate->curState != OMX_StateIdle) {
1411        eError = OMX_ErrorIncorrectStateOperation;
1412        goto EXIT;
1413    }
1414
1415    OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1416    OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Component Sending Filled ip buff %p to Component Thread\n",
1417                  __LINE__,pBuffer);
1418    OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1419
1420    if (pComponentPrivate->bBypassDSP == 0) {
1421        pComponentPrivate->app_nBuf--;
1422    }
1423
1424    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1425    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1426
1427    pComponentPrivate->nUnhandledEmptyThisBuffers++;
1428
1429    ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof(OMX_BUFFERHEADERTYPE*));
1430
1431    if (ret == -1) {
1432        OMX_TRACE4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__);
1433        eError = OMX_ErrorHardware;
1434        goto EXIT;
1435    }
1436
1437    pComponentPrivate->nEmptyThisBufferCount++;
1438 EXIT:
1439    return eError;
1440}
1441/**-------------------------------------------------------------------*
1442 *  FillThisBuffer() This callback is used to send the output buffer to
1443 *  the component
1444 *
1445 * @param pComponent    handle for this instance of the component
1446 * @param nPortIndex    output port number
1447 * @param pBuffer       buffer to be sent to codec
1448 *
1449 * @retval OMX_NoError              Success, ready to roll
1450 *         OMX_Error_BadParameter   The input parameter pointer is null
1451 **/
1452/*-------------------------------------------------------------------*/
1453
1454static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1455                                     OMX_BUFFERHEADERTYPE* pBuffer)
1456{
1457
1458    OMX_ERRORTYPE eError = OMX_ErrorNone;
1459    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1460    WMADEC_COMPONENT_PRIVATE *pComponentPrivate =
1461        (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1462    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1463    int nRet=0;
1464
1465    OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1466    OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Component Sending Emptied op buff %p to Component Thread\n",
1467                   __LINE__,pBuffer);
1468    OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1469
1470    pPortDef = ((WMADEC_COMPONENT_PRIVATE*)
1471                pComponentPrivate)->pPortDef[OUTPUT_PORT];
1472#ifdef _ERROR_PROPAGATION__
1473    if (pComponentPrivate->curState == OMX_StateInvalid){
1474        eError = OMX_ErrorInvalidState;
1475        goto EXIT;
1476    }
1477#endif
1478#ifdef __PERF_INSTRUMENTATION__
1479    OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1480    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1481                       pBuffer->pBuffer,
1482                       0,
1483                       PERF_ModuleHLMM);
1484#endif
1485
1486    if(!pPortDef->bEnabled) {
1487        eError = OMX_ErrorIncorrectStateOperation;
1488        goto EXIT;
1489    }
1490
1491    if (pBuffer == NULL) {
1492        eError = OMX_ErrorBadParameter;
1493        OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1494        goto EXIT;
1495    }
1496
1497    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1498        eError = OMX_ErrorBadParameter;
1499        goto EXIT;
1500    }
1501
1502    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1503        eError = OMX_ErrorVersionMismatch;
1504        goto EXIT;
1505    }
1506
1507    if (pBuffer->nOutputPortIndex != OUTPUT_PORT) {
1508        eError  = OMX_ErrorBadPortIndex;
1509        goto EXIT;
1510    }
1511
1512    if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
1513        eError = OMX_ErrorIncorrectStateOperation;
1514        goto EXIT;
1515    }
1516
1517    OMX_PRBUFFER1(pComponentPrivate->dbg, "FillThisBuffer Line %d\n",__LINE__);
1518    pBuffer->nFilledLen = 0;
1519    OMX_PRBUFFER1(pComponentPrivate->dbg, "FillThisBuffer Line %d\n",__LINE__);
1520    /*Filling the Output buffer with zero */
1521
1522    memset (pBuffer->pBuffer,0,pBuffer->nAllocLen);
1523    OMX_PRBUFFER1(pComponentPrivate->dbg, "FillThisBuffer Line %d\n",__LINE__);
1524
1525    OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pMarkBuf = %p\n",pComponentPrivate->pMarkBuf);
1526    OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pMarkData = %p\n",pComponentPrivate->pMarkData);
1527    if(pComponentPrivate->pMarkBuf){
1528        OMX_PRBUFFER1(pComponentPrivate->dbg, "FillThisBuffer Line %d\n",__LINE__);
1529        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1530        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1531        pComponentPrivate->pMarkBuf = NULL;
1532    }
1533
1534    if (pComponentPrivate->pMarkData) {
1535        OMX_PRBUFFER1(pComponentPrivate->dbg, "FillThisBuffer Line %d\n",__LINE__);
1536        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1537        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1538        pComponentPrivate->pMarkData = NULL;
1539    }
1540    pComponentPrivate->nUnhandledFillThisBuffers++;
1541    nRet = write (pComponentPrivate->dataPipe[1], &pBuffer,
1542                  sizeof (OMX_BUFFERHEADERTYPE*));
1543    if (nRet == -1) {
1544        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__);
1545        eError = OMX_ErrorHardware;
1546        goto EXIT;
1547    }
1548
1549 EXIT:
1550    return eError;
1551}
1552/*-------------------------------------------------------------------*/
1553/**
1554 * OMX_ComponentDeinit() this methold will de init the component
1555 *
1556 * @param pComp         handle for this instance of the component
1557 *
1558 * @retval OMX_NoError              Success, ready to roll
1559 *         OMX_Error_BadParameter   The input parameter pointer is null
1560 **/
1561/*-------------------------------------------------------------------*/
1562
1563static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1564{
1565
1566    OMX_ERRORTYPE eError = OMX_ErrorNone;
1567
1568    /* inform audio manager to remove the streamID*/
1569    /* compose the data */
1570    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1571    WMADEC_COMPONENT_PRIVATE *pComponentPrivate =
1572        (WMADEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1573    struct OMX_TI_Debug dbg;
1574    dbg = pComponentPrivate->dbg;
1575
1576
1577    OMX_PRINT1(dbg, "%d ::ComponentDeInit\n",__LINE__);
1578
1579#ifdef __PERF_INSTRUMENTATION__
1580    OMX_PRDSP1(dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1581    PERF_Boundary(pComponentPrivate->pPERF,
1582                  PERF_BoundaryStart | PERF_BoundaryCleanup);
1583#endif
1584
1585#ifdef DSP_RENDERING_ON
1586    close(fdwrite);
1587    close(fdread);
1588#endif
1589
1590#ifdef RESOURCE_MANAGER_ENABLED
1591    eError =  RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource,
1592                                     OMX_WMA_Decoder_COMPONENT, 0, 1234, NULL);
1593    if (eError != OMX_ErrorNone) {
1594        OMX_ERROR4(dbg, "%d ::OMX_AmrDecoder.c :: Error returned from destroy ResourceManagerProxy thread\n",
1595                       __LINE__);
1596    }
1597    eError = RMProxy_Deinitalize();
1598    if (eError != OMX_ErrorNone) {
1599        OMX_ERROR4(dbg, "%d ::Error returned from destroy ResourceManagerProxy thread\n",
1600                       __LINE__);
1601    }
1602#endif
1603    OMX_PRINT1(dbg, "%d ::ComponentDeInit\n",__LINE__);
1604    pComponentPrivate->bIsStopping = 1;
1605    eError = WMADEC_StopComponentThread(pHandle);
1606    OMX_PRINT1(dbg, "%d ::ComponentDeInit\n",__LINE__);
1607    /* Wait for thread to exit so we can get the status into "error" */
1608
1609    /* close the pipe handles */
1610    WMADEC_FreeCompResources(pHandle);
1611    OMX_PRINT1(dbg, "%d ::After WMADEC_FreeCompResources\n",__LINE__);
1612    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
1613    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
1614    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
1615    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
1616    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1617    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->rcaheader);
1618#ifdef __PERF_INSTRUMENTATION__
1619    OMX_PRDSP1(dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1620    PERF_Boundary(pComponentPrivate->pPERF,
1621                  PERF_BoundaryComplete | PERF_BoundaryCleanup);
1622    PERF_Done(pComponentPrivate->pPERF);
1623#endif
1624    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate);
1625    OMX_PRINT1(dbg, "%d ::After free(pComponentPrivate)\n",__LINE__);
1626    OMX_DBG_CLOSE(dbg);
1627    return eError;
1628}
1629
1630/*-------------------------------------------------------------------*/
1631/**
1632 *  ComponentTunnelRequest() this method is not implemented in 1.5
1633 *
1634 * This method will update application callbacks
1635 * the application.
1636 *
1637 * @param pComp         handle for this instance of the component
1638 * @param pCallBacks    application callbacks
1639 * @param ptr
1640 *
1641 * @retval OMX_NoError              Success, ready to roll
1642 *         OMX_Error_BadParameter   The input parameter pointer is null
1643 **/
1644/*-------------------------------------------------------------------*/
1645
1646static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1647                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1648                                             OMX_U32 nTunneledPort,
1649                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1650{
1651    OMXDBG_PRINT(stderr, PRINT, 1, 0, "===========================Inside the ComponentTunnelRequest==============================\n");
1652    OMX_ERRORTYPE eError = OMX_ErrorNone;
1653    OMXDBG_PRINT(stderr, ERROR, 4, 0, "Inside the ComponentTunnelRequest\n");
1654    eError = OMX_ErrorNotImplemented;
1655    return eError;
1656}
1657
1658/*-------------------------------------------------------------------*/
1659/**
1660 *  AllocateBuffer()
1661
1662 * @param pComp         handle for this instance of the component
1663 * @param pCallBacks    application callbacks
1664 * @param ptr
1665 *
1666 * @retval OMX_NoError              Success, ready to roll
1667 *         OMX_Error_BadParameter   The input parameter pointer is null
1668 **/
1669/*-------------------------------------------------------------------*/
1670
1671static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1672                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1673                                     OMX_IN OMX_U32 nPortIndex,
1674                                     OMX_IN OMX_PTR pAppPrivate,
1675                                     OMX_IN OMX_U32 nSizeBytes)
1676
1677{
1678    OMXDBG_PRINT(stderr, PRINT, 1, 0, "====================================OMX_ERRORTYPE AllocateBuffer ()=======================\n");
1679    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1680    WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
1681    OMX_ERRORTYPE eError = OMX_ErrorNone;
1682    OMX_BUFFERHEADERTYPE *pBufferHeader;
1683
1684    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
1685        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1686
1687    pPortDef = ((WMADEC_COMPONENT_PRIVATE*)
1688                pComponentPrivate)->pPortDef[nPortIndex];
1689
1690#ifdef _ERROR_PROPAGATION__
1691    if (pComponentPrivate->curState == OMX_StateInvalid){
1692        eError = OMX_ErrorInvalidState;
1693        goto EXIT;
1694    }
1695#endif
1696
1697    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: pPortDef = %p\n", __LINE__,pPortDef);
1698    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled);
1699
1700    OMX_PRDSP2(pComponentPrivate->dbg, "pPortDef->bEnabled = %d\n", pPortDef->bEnabled);
1701
1702    if(!pPortDef->bEnabled) {
1703        pComponentPrivate->AlloBuf_waitingsignal = 1;
1704#ifndef UNDER_CE
1705        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1706        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
1707        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1708#else
1709        OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1710#endif
1711
1712    }
1713
1714    WMAD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1715
1716    memset(pBufferHeader, 0x0, sizeof(OMX_BUFFERHEADERTYPE));
1717
1718    WMAD_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, nSizeBytes + WMA_EXTRA_BYTES, OMX_U8);
1719    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pBufferHeader->pBuffer);
1720    if(NULL == pBufferHeader->pBuffer) {
1721	    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Malloc Failed\n",__LINE__);
1722        if (pBufferHeader) {
1723            OMX_WMADECMEMFREE_STRUCT(pBufferHeader);
1724        }
1725        goto EXIT;
1726    }
1727    pBufferHeader->pBuffer += WMA_CACHE_ALIGN;
1728
1729
1730
1731    if (nPortIndex == INPUT_PORT)
1732    {
1733        pBufferHeader->nInputPortIndex = nPortIndex;
1734        pBufferHeader->nOutputPortIndex = -1;
1735        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1736        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1737        OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p\n",pComponentPrivate->pInputBufferList->numBuffers,pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1738        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1739        OMX_PRBUFFER1(pComponentPrivate->dbg, "Allocate Buffer Line %d\n",__LINE__);
1740        OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %d\n",pComponentPrivate->pInputBufferList->numBuffers);
1741        OMX_PRBUFFER1(pComponentPrivate->dbg, "pPortDef->nBufferCountMin = %ld\n",pPortDef->nBufferCountMin);
1742        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1743            pPortDef->bPopulated = OMX_TRUE;
1744        }
1745    }
1746    else if (nPortIndex == OUTPUT_PORT) {
1747        pBufferHeader->nInputPortIndex = -1;
1748        pBufferHeader->nOutputPortIndex = nPortIndex;
1749        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1750        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1751        OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p\n",pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1752        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1753        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1754            pPortDef->bPopulated = OMX_TRUE;
1755        }
1756    }
1757    else {
1758        eError = OMX_ErrorBadPortIndex;
1759        goto EXIT;
1760    }
1761
1762    if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
1763       (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) &&
1764       (pComponentPrivate->InLoaded_readytoidle))
1765
1766
1767    {
1768        pComponentPrivate->InLoaded_readytoidle = 0;
1769#ifndef UNDER_CE
1770        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1771        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1772        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1773#else
1774        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1775#endif
1776    }
1777
1778
1779    pBufferHeader->pAppPrivate = pAppPrivate;
1780    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1781    pBufferHeader->nAllocLen = nSizeBytes;
1782    pBufferHeader->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
1783    pBufferHeader->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
1784    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1785
1786
1787    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1788    OMX_PRINT2(pComponentPrivate->dbg, "Line %d\n",__LINE__);
1789    *pBuffer = pBufferHeader;
1790
1791    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
1792        SendCommand (pComponentPrivate->pHandle,
1793                     OMX_CommandPortEnable,
1794                     pComponentPrivate->bEnableCommandParam,NULL);
1795    }
1796
1797#ifdef __PERF_INSTRUMENTATION__
1798    OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1799    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
1800                        (*pBuffer)->pBuffer, nSizeBytes,
1801                        PERF_ModuleMemory);
1802#endif
1803
1804 EXIT:
1805    OMX_PRINT1(pComponentPrivate->dbg, "AllocateBuffer returning %d\n",eError);
1806    return eError;
1807}
1808
1809
1810/* ================================================================================= */
1811/**
1812 * @fn FreeBuffer() description for FreeBuffer
1813 FreeBuffer().
1814 Called by the OMX IL client to free a buffer.
1815 *
1816 *  @see         OMX_Core.h
1817 */
1818/* ================================================================================ */
1819static OMX_ERRORTYPE FreeBuffer(
1820                                OMX_IN  OMX_HANDLETYPE hComponent,
1821                                OMX_IN  OMX_U32 nPortIndex,
1822                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1823{
1824
1825    OMX_ERRORTYPE eError = OMX_ErrorNone;
1826    WMADEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1827    OMX_BUFFERHEADERTYPE* buff;
1828    OMX_U8* tempBuff;
1829    int i;
1830    int inputIndex = -1;
1831    int outputIndex = -1;
1832    OMX_COMPONENTTYPE *pHandle;
1833
1834    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
1835        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1836
1837    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
1838    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1839        buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
1840        if (buff == pBuffer) {
1841            OMX_PRBUFFER2(pComponentPrivate->dbg, "Found matching input buffer\n");
1842            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
1843            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
1844            inputIndex = i;
1845            break;
1846        }
1847        else {
1848            OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match\n");
1849            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
1850            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
1851        }
1852    }
1853
1854    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1855        buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
1856        if (buff == pBuffer) {
1857            OMX_PRBUFFER2(pComponentPrivate->dbg, "Found matching output buffer\n");
1858            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
1859            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
1860            outputIndex = i;
1861            break;
1862        }
1863        else {
1864            OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match\n");
1865            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
1866            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
1867        }
1868    }
1869
1870
1871    if (inputIndex != -1) {
1872        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
1873            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
1874            if (tempBuff != 0){
1875                tempBuff -= WMA_CACHE_ALIGN;}
1876            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,tempBuff);
1877            OMX_WMADECMEMFREE_STRUCT(tempBuff);
1878        }
1879#ifdef __PERF_INSTRUMENTATION__
1880        OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1881        PERF_SendingBuffer(pComponentPrivate->pPERF,
1882                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,
1883                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
1884                           PERF_ModuleMemory);
1885#endif
1886        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1887        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1888        pComponentPrivate->pInputBufferList->numBuffers--;
1889
1890        if (pComponentPrivate->pInputBufferList->numBuffers <
1891            pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountMin) {
1892
1893            pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = OMX_FALSE;
1894        }
1895
1896        if(pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled &&
1897           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1898           (pComponentPrivate->curState == OMX_StateIdle ||
1899            pComponentPrivate->curState == OMX_StateExecuting ||
1900            pComponentPrivate->curState == OMX_StatePause)) {
1901            pComponentPrivate->cbInfo.EventHandler(
1902                                                   pHandle, pHandle->pApplicationPrivate,
1903                                                   OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1904        }
1905    }
1906    else if (outputIndex != -1) {
1907        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
1908            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
1909            if (tempBuff != 0){
1910                tempBuff -= WMA_CACHE_ALIGN;}
1911            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,tempBuff);
1912            OMX_WMADECMEMFREE_STRUCT(tempBuff);
1913        }
1914
1915#ifdef __PERF_INSTRUMENTATION__
1916        OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
1917        PERF_SendingBuffer(pComponentPrivate->pPERF,
1918                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,
1919                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen,
1920                           PERF_ModuleMemory);
1921#endif
1922
1923        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1924        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1925        pComponentPrivate->pOutputBufferList->numBuffers--;
1926
1927        if (pComponentPrivate->pOutputBufferList->numBuffers <
1928            pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountMin) {
1929            pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated = OMX_FALSE;
1930        }
1931        if(pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled &&
1932           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1933           !pComponentPrivate->reconfigOutputPort &&
1934           (pComponentPrivate->curState == OMX_StateIdle ||
1935            pComponentPrivate->curState == OMX_StateExecuting ||
1936            pComponentPrivate->curState == OMX_StatePause)) {
1937            pComponentPrivate->cbInfo.EventHandler(
1938                                                   pHandle, pHandle->pApplicationPrivate,
1939                                                   OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1940        }
1941    }
1942    else {
1943        OMX_ERROR2(pComponentPrivate->dbg, "%d::Returning OMX_ErrorBadParameter\n",__LINE__);
1944        eError = OMX_ErrorBadParameter;
1945    }
1946
1947
1948    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
1949         !pComponentPrivate->pOutputBufferList->numBuffers) &&
1950        pComponentPrivate->InIdle_goingtoloaded)
1951    {
1952        pComponentPrivate->InIdle_goingtoloaded = 0;
1953#ifndef UNDER_CE
1954        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1955        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
1956        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1957#else
1958        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
1959#endif
1960    }
1961
1962    /* Removing sleep() calls.  There are no allocated buffers. */
1963#if 0
1964    if (pComponentPrivate->bDisableCommandPending &&
1965        (pComponentPrivate->pInputBufferList->numBuffers +
1966         pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
1967        if (pComponentPrivate->pInputBufferList->numBuffers +
1968            pComponentPrivate->pOutputBufferList->numBuffers == 0) {
1969            SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,
1970                         pComponentPrivate->bDisableCommandParam,NULL);
1971        }
1972    }
1973#else
1974    if (pComponentPrivate->bDisableCommandPending &&
1975        (pComponentPrivate->pInputBufferList->numBuffers == 0)) {
1976        pComponentPrivate->bDisableCommandPending = OMX_FALSE;
1977        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
1978                                                pComponentPrivate->pHandle->pApplicationPrivate,
1979                                                OMX_EventCmdComplete,
1980                                                OMX_CommandPortDisable,
1981                                                INPUT_PORT,
1982                                                NULL);
1983
1984    }
1985    if (pComponentPrivate->bDisableCommandPending &&
1986        (pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
1987        pComponentPrivate->bDisableCommandPending = OMX_FALSE;
1988        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
1989                                                pComponentPrivate->pHandle->pApplicationPrivate,
1990                                                OMX_EventCmdComplete,
1991                                                OMX_CommandPortDisable,
1992                                                OUTPUT_PORT,
1993                                                NULL);
1994
1995    }
1996
1997#endif
1998
1999    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting FreeBuffer\n", __LINE__);
2000    return eError;
2001}
2002
2003
2004/* ================================================================================= */
2005/**
2006 * @fn UseBuffer() description for UseBuffer
2007 UseBuffer().
2008 Called by the OMX IL client to pass a buffer to be used.
2009 *
2010 *  @see         OMX_Core.h
2011 */
2012/* ================================================================================ */
2013static OMX_ERRORTYPE UseBuffer (
2014                                OMX_IN OMX_HANDLETYPE hComponent,
2015                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
2016                                OMX_IN OMX_U32 nPortIndex,
2017                                OMX_IN OMX_PTR pAppPrivate,
2018                                OMX_IN OMX_U32 nSizeBytes,
2019                                OMX_IN OMX_U8* pBuffer)
2020{
2021
2022    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
2023    WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
2024    OMX_ERRORTYPE eError = OMX_ErrorNone;
2025    OMX_BUFFERHEADERTYPE *pBufferHeader;
2026
2027    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
2028        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2029
2030#ifdef _ERROR_PROPAGATION__
2031    if (pComponentPrivate->curState == OMX_StateInvalid){
2032        eError = OMX_ErrorInvalidState;
2033        goto EXIT;
2034    }
2035
2036#endif
2037
2038#ifdef __PERF_INSTRUMENTATION__
2039    OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
2040    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
2041                        pBuffer, nSizeBytes,
2042                        PERF_ModuleHLMM);
2043#endif
2044
2045    pPortDef = ((WMADEC_COMPONENT_PRIVATE*)
2046                pComponentPrivate)->pPortDef[nPortIndex];
2047    if(!pPortDef->bEnabled){
2048        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
2049        pComponentPrivate->AlloBuf_waitingsignal = 1;
2050        //wait for the port to be enabled before we accept buffers
2051        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
2052        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
2053    }
2054    OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: pPortDef = %p\n", __LINE__,pPortDef);
2055    OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled);
2056
2057    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2058    if(!pPortDef->bEnabled) {
2059        OMX_ERROR4(pComponentPrivate->dbg, "%d :: In AllocateBuffer\n", __LINE__);
2060        eError = OMX_ErrorIncorrectStateOperation;
2061        goto EXIT;
2062    }
2063
2064    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2065    OMX_PRINT1(pComponentPrivate->dbg, "pPortDef->bPopulated =%d\n",pPortDef->bPopulated);
2066    OMX_PRINT1(pComponentPrivate->dbg, "nSizeBytes =%ld\n",nSizeBytes);
2067    OMX_PRBUFFER1(pComponentPrivate->dbg, "pPortDef->nBufferSize =%ld\n",pPortDef->nBufferSize);
2068
2069#ifndef UNDER_CE
2070    if(pPortDef->bPopulated) {
2071        eError = OMX_ErrorBadParameter;
2072        goto EXIT;
2073    }
2074#endif
2075
2076    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2077    WMAD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
2078    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pBufferHeader);
2079
2080    if (pBufferHeader == 0) {
2081        eError = OMX_ErrorInsufficientResources;
2082        goto EXIT;
2083    }
2084    memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
2085
2086    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2087    if (nPortIndex == OUTPUT_PORT) {
2088        pBufferHeader->nInputPortIndex = -1;
2089        pBufferHeader->nOutputPortIndex = nPortIndex;
2090        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
2091        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
2092        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
2093        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2094            pPortDef->bPopulated = OMX_TRUE;
2095        }
2096    }
2097    else {
2098        pBufferHeader->nInputPortIndex = nPortIndex;
2099        pBufferHeader->nOutputPortIndex = -1;
2100        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
2101        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
2102        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
2103        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2104            pPortDef->bPopulated = OMX_TRUE;
2105        }
2106    }
2107
2108    if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
2109       (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) &&
2110       (pComponentPrivate->InLoaded_readytoidle))
2111    {
2112        pComponentPrivate->InLoaded_readytoidle = 0;
2113#ifndef UNDER_CE
2114        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2115        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2116        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2117#else
2118        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2119#endif
2120    }
2121
2122    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2123    pBufferHeader->pAppPrivate = pAppPrivate;
2124    pBufferHeader->pPlatformPrivate = pComponentPrivate;
2125    pBufferHeader->nAllocLen = nSizeBytes;
2126    pBufferHeader->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
2127    pBufferHeader->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
2128    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2129    pBufferHeader->pBuffer = pBuffer;
2130    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2131    OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__);
2132    *ppBufferHdr = pBufferHeader;
2133    OMX_PRBUFFER1(pComponentPrivate->dbg, "pBufferHeader = %p\n",pBufferHeader);
2134    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated){
2135        OMX_PRCOMM2(pComponentPrivate->dbg, "Sending command before exiting usbuffer\n");
2136        SendCommand (pComponentPrivate->pHandle,
2137                     OMX_CommandPortEnable,
2138                     pComponentPrivate->bEnableCommandParam,NULL);
2139    }
2140    OMX_PRINT1(pComponentPrivate->dbg, "exiting Use buffer\n");
2141 EXIT:
2142    return eError;
2143}
2144
2145
2146/* ================================================================================= */
2147/**
2148 * @fn GetExtensionIndex() description for GetExtensionIndex
2149 GetExtensionIndex().
2150 Returns index for vendor specific settings.
2151 *
2152 *  @see         OMX_Core.h
2153 */
2154/* ================================================================================ */
2155static OMX_ERRORTYPE GetExtensionIndex(
2156                                       OMX_IN  OMX_HANDLETYPE hComponent,
2157                                       OMX_IN  OMX_STRING cParameterName,
2158                                       OMX_OUT OMX_INDEXTYPE* pIndexType)
2159{
2160
2161    OMX_ERRORTYPE eError = OMX_ErrorNone;
2162
2163    OMXDBG_PRINT(stderr, PRINT, 1, 0, "GetExtensionIndex\n");
2164    if (!(strcmp(cParameterName,"OMX.TI.index.config.wmaheaderinfo"))) {
2165        *pIndexType = OMX_IndexCustomWMADECHeaderInfoConfig;
2166        OMXDBG_PRINT(stderr, DSP, 2, 0, "OMX_IndexCustomWMADECHeaderInfoConfig\n");
2167    }
2168    else if(!(strcmp(cParameterName,"OMX.TI.index.config.wmastreamIDinfo")))
2169    {
2170        *pIndexType = OMX_IndexCustomWmaDecStreamIDConfig;
2171
2172    }
2173    else if(!(strcmp(cParameterName,"OMX.TI.index.config.wmadec.datapath")))
2174    {
2175        *pIndexType = OMX_IndexCustomWmaDecDataPath;
2176    }
2177    else if(!(strcmp(cParameterName,"OMX.TI.WMA.Decode.Debug")))
2178    {
2179	*pIndexType = OMX_IndexCustomDebug;
2180    }
2181    else {
2182        eError = OMX_ErrorBadParameter;
2183    }
2184
2185    OMXDBG_PRINT(stderr, PRINT, 1, 0, "Exiting GetExtensionIndex\n");
2186    return eError;
2187}
2188
2189/* ================================================================================= */
2190/**
2191 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
2192
2193 Returns the role at the given index
2194 *
2195 *  @see         OMX_Core.h
2196 */
2197/* ================================================================================ */
2198static OMX_ERRORTYPE ComponentRoleEnum(
2199                                       OMX_IN OMX_HANDLETYPE hComponent,
2200                                       OMX_OUT OMX_U8 *cRole,
2201                                       OMX_IN OMX_U32 nIndex)
2202{
2203    WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
2204
2205    OMX_ERRORTYPE eError = OMX_ErrorNone;
2206    pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2207
2208    if(nIndex == 0){
2209        memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
2210        OMX_PRINT1(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
2211    }
2212    else {
2213        eError = OMX_ErrorNoMore;
2214    }
2215    return eError;
2216};
2217
2218
2219#ifdef UNDER_CE
2220/* ================================================================================= */
2221/**
2222 * @fns Sleep replace for WIN CE
2223 */
2224/* ================================================================================ */
2225int OMX_CreateEvent(OMX_Event *event){
2226
2227    int ret = OMX_ErrorNone;
2228    HANDLE createdEvent = NULL;
2229    if(event == NULL){
2230        ret = OMX_ErrorBadParameter;
2231        goto EXIT;
2232    }
2233    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2234    if(event->event == NULL)
2235    ret = (int)GetLastError();
2236 EXIT:
2237    return ret;
2238}
2239
2240int OMX_SignalEvent(OMX_Event *event){
2241
2242    int ret = OMX_ErrorNone;
2243    if(event == NULL){
2244        ret = OMX_ErrorBadParameter;
2245        goto EXIT;
2246    }
2247    SetEvent(event->event);
2248    ret = (int)GetLastError();
2249 EXIT:
2250    return ret;
2251}
2252
2253int OMX_WaitForEvent(OMX_Event *event) {
2254
2255    int ret = OMX_ErrorNone;
2256    if(event == NULL){
2257        ret = OMX_ErrorBadParameter;
2258        goto EXIT;
2259    }
2260    WaitForSingleObject(event->event, INFINITE);
2261    ret = (int)GetLastError();
2262 EXIT:
2263    return ret;
2264}
2265
2266int OMX_DestroyEvent(OMX_Event *event) {
2267
2268    int ret = OMX_ErrorNone;
2269    if(event == NULL){
2270        ret = OMX_ErrorBadParameter;
2271        goto EXIT;
2272    }
2273    CloseHandle(event->event);
2274 EXIT:
2275    return ret;
2276}
2277#endif
2278
2279#ifdef WMADEC_MEMDEBUG
2280void * mymalloc(int line, char *s, int size)
2281{
2282    void *p;
2283    int e=0;
2284    p = malloc(size);
2285    if(p==NULL){
2286        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
2287    }
2288    else{
2289        while((lines[e]!=0)&& (e<500) ){
2290            e++;
2291        }
2292        arr[e]=p;
2293        lines[e]=line;
2294        bytes[e]=size;
2295        strcpy(file[e],s);
2296        OMXDBG_PRINT(stderr, BUFFER, 2, 0, "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
2297    }
2298    return p;
2299}
2300
2301int myfree(void *dp, int line, char *s){
2302    int q;
2303    for(q=0;q<500;q++){
2304        if(arr[q]==dp){
2305            OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
2306            free(dp);
2307            dp = NULL;
2308            lines[q]=0;
2309            strcpy(file[q],"");
2310            break;
2311        }
2312    }
2313    if(500==q)
2314    OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
2315}
2316#endif
2317