1
2/*
3 * Copyright (C) Texas Instruments - http://www.ti.com/
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21/* =============================================================================
22*             Texas Instruments OMAP (TM) Platform Software
23*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
24*
25*  Use of this software is controlled by the terms and conditions found
26*  in the license agreement under which this software has been supplied.
27* =========================================================================== */
28/**
29* @file OMX_Mp3Decoder.c
30*
31* This file implements OpenMAX (TM) 1.0 Specific APIs and its functionality
32* that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
33*
34* @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\mp3_dec\src
35*
36* @rev  1.0
37*/
38/* ----------------------------------------------------------------------------
39*!
40*! Revision History
41*! ===================================
42*! 21-sept-2006 bk: updated some review findings for alpha release
43*! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more
44*! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases
45*! This is newest file
46* =========================================================================== */
47/* ------compilation control switches -------------------------*/
48/****************************************************************
49*  INCLUDE FILES
50****************************************************************/
51/* ----- system and platform files ----------------------------*/
52
53
54#ifdef UNDER_CE
55#include <windows.h>
56#include <oaf_osal.h>
57#include <omx_core.h>
58
59#else
60#include <wchar.h>
61#include <unistd.h>
62#include <sys/time.h>
63#include <sys/types.h>
64#include <sys/ioctl.h>
65#include <sys/select.h>
66#include <errno.h>
67#endif
68#include <pthread.h>
69#include <string.h>
70#include <fcntl.h>
71#include <stdlib.h>
72#include <stdio.h>
73#include <dbapi.h>
74
75/*------- Program Header Files -----------------------------------------------*/
76
77#include "LCML_DspCodec.h"
78#include "OMX_Mp3Dec_Utils.h"
79#include <TIDspOmx.h>
80
81#ifdef DSP_RENDERING_ON
82#include <AudioManagerAPI.h>
83#endif
84
85#ifdef RESOURCE_MANAGER_ENABLED
86#include <ResourceManagerProxyAPI.h>
87#endif
88
89#ifdef DSP_RENDERING_ON
90
91#define FIFO1 "/dev/fifo.1"
92#define FIFO2 "/dev/fifo.2"
93#define PERMS 0666
94
95AM_COMMANDDATATYPE cmd_data;
96int mp3d_fdwrite, mp3d_fdread;
97int errno;
98#endif
99
100/* define component role */
101#define MP3_DEC_ROLE "audio_decoder.mp3"
102
103/****************************************************************
104*  EXTERNAL REFERENCES NOTE : only use if not found in header file
105****************************************************************/
106/*--------data declarations -----------------------------------*/
107
108/*--------function prototypes ---------------------------------*/
109
110/****************************************************************
111*  PUBLIC DECLARATIONS Defined here, used elsewhere
112****************************************************************/
113/*--------data declarations -----------------------------------*/
114
115/*--------function prototypes ---------------------------------*/
116
117/****************************************************************
118*  PRIVATE DECLARATIONS Defined here, used only here
119****************************************************************/
120/*--------data declarations -----------------------------------*/
121
122/*--------function prototypes ---------------------------------*/
123
124static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
125                                   OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
126static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
127                                          OMX_STRING pComponentName,
128                                          OMX_VERSIONTYPE* pComponentVersion,
129                                          OMX_VERSIONTYPE* pSpecVersion,
130                                          OMX_UUIDTYPE* pComponentUUID);
131
132static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
133                                  OMX_U32 nParam, OMX_PTR pCmdData);
134
135static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex,
136                                  OMX_PTR ComponentParamStruct);
137static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
138                                   OMX_INDEXTYPE nParamIndex,
139                                   OMX_PTR ComponentParamStruct);
140static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
141                                OMX_INDEXTYPE nConfigIndex,
142                                OMX_PTR pComponentConfigStructure);
143static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
144                                OMX_INDEXTYPE nConfigIndex,
145                                OMX_PTR pComponentConfigStructure);
146
147static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
148
149static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
150static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
151static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
152                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
153                                             OMX_U32 nTunneledPort,
154                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
155
156static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
157
158static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
159                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
160                                     OMX_IN OMX_U32 nPortIndex,
161                                     OMX_IN OMX_PTR pAppPrivate,
162                                     OMX_IN OMX_U32 nSizeBytes);
163
164static OMX_ERRORTYPE FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
165                                OMX_IN  OMX_U32 nPortIndex,
166                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
167
168static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
169                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
170                                OMX_IN OMX_U32 nPortIndex,
171                                OMX_IN OMX_PTR pAppPrivate,
172                                OMX_IN OMX_U32 nSizeBytes,
173                                OMX_IN OMX_U8* pBuffer);
174
175static OMX_ERRORTYPE GetExtensionIndex(OMX_IN  OMX_HANDLETYPE hComponent,
176                                       OMX_IN  OMX_STRING cParameterName,
177                                       OMX_OUT OMX_INDEXTYPE *pIndexType);
178
179static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
180                                       OMX_OUT OMX_U8 *cRole,
181                                       OMX_IN OMX_U32 nIndex);
182
183/* ================================================================================= * */
184/**
185* @fn OMX_ComponentInit() function is called by OMX Core to initialize the component
186* with default values of the component. Before calling this function OMX_Init
187* must have been called.
188*
189* @param *hComp This is component handle allocated by the OMX core.
190*
191* @pre          OMX_Init should be called by application.
192*
193* @post         Component has initialzed with default values.
194*
195*  @return      OMX_ErrorNone = Successful Inirialization of the component\n
196*               OMX_ErrorInsufficientResources = Not enough memory
197*
198*  @see          Mp3Dec_StartCompThread()
199*/
200/* ================================================================================ * */
201OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
202{
203
204
205    OMX_ERRORTYPE eError = OMX_ErrorNone;
206    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
207    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
208    OMX_AUDIO_PARAM_PORTFORMATTYPE *pPortFormat = NULL;
209    OMX_AUDIO_PARAM_MP3TYPE *mp3_ip = NULL;
210    OMX_AUDIO_PARAM_PCMMODETYPE *mp3_op = NULL;
211    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
212    MP3D_AUDIODEC_PORT_TYPE *pCompPort = NULL;
213    MP3D_BUFFERLIST *pTemp = NULL;
214    int i=0;
215
216    OMXDBG_PRINT(stderr, PRINT, 1, 0, "Entering OMX_ComponentInit\n");
217
218    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
219
220    pHandle->SetCallbacks = SetCallbacks;
221    pHandle->GetComponentVersion = GetComponentVersion;
222    pHandle->SendCommand = SendCommand;
223    pHandle->GetParameter = GetParameter;
224    pHandle->SetParameter = SetParameter;
225    pHandle->GetConfig = GetConfig;
226    pHandle->SetConfig = SetConfig;
227    pHandle->GetState = GetState;
228    pHandle->EmptyThisBuffer = EmptyThisBuffer;
229    pHandle->FillThisBuffer = FillThisBuffer;
230    pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
231    pHandle->ComponentDeInit = ComponentDeInit;
232    pHandle->AllocateBuffer =  AllocateBuffer;
233    pHandle->FreeBuffer = FreeBuffer;
234    pHandle->UseBuffer = UseBuffer;
235    pHandle->GetExtensionIndex = GetExtensionIndex;
236    pHandle->ComponentRoleEnum = ComponentRoleEnum;
237    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate,MP3DEC_COMPONENT_PRIVATE);
238
239    pComponentPrivate = pHandle->pComponentPrivate;
240    pComponentPrivate->pHandle = pHandle;
241    OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_MP3DEC");
242
243#ifdef __PERF_INSTRUMENTATION__
244    pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('M','P','3','D'),
245                                           PERF_ModuleLLMM |
246                                           PERF_ModuleAudioDecode);
247#endif
248
249    pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE;
250    pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE;
251    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
252    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
253    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE;
254    /* Next capabilities are set to false in order to ease issues
255       regarding 1 sec of audio sound repeated while FFW/RW(OMAPS00200511) */
256    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE;
257    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
258
259
260    OMX_MALLOC_GENERIC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
261    pComponentPrivate->pCompPort[MP3D_INPUT_PORT] =  pCompPort;
262
263    OMX_MALLOC_GENERIC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
264    pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT] = pCompPort;
265    OMX_MALLOC_GENERIC(pTemp, MP3D_BUFFERLIST);
266    pComponentPrivate->pInputBufferList = pTemp;
267
268    OMX_MALLOC_GENERIC(pTemp, MP3D_BUFFERLIST);
269    pComponentPrivate->pOutputBufferList = pTemp;
270
271    pComponentPrivate->pInputBufferList->numBuffers = 0;
272    pComponentPrivate->pOutputBufferList->numBuffers = 0;
273
274    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
275        pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
276        pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
277    }
278
279    pComponentPrivate->bufAlloced = 0;
280
281    OMX_MALLOC_GENERIC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
282    OMX_CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
283    OMX_MALLOC_GENERIC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
284    OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
285    pComponentPrivate->sPortParam->nPorts = NUM_OF_PORTS;
286    pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
287    pComponentPrivate->mp3Params = NULL;
288
289    pComponentPrivate->pcmParams = NULL;
290
291    OMX_MALLOC_GENERIC(mp3_ip,OMX_AUDIO_PARAM_MP3TYPE);
292    OMX_MALLOC_GENERIC(mp3_op,OMX_AUDIO_PARAM_PCMMODETYPE);
293
294
295    pComponentPrivate->mp3Params = mp3_ip;
296    pComponentPrivate->pcmParams = mp3_op;
297
298    pComponentPrivate->dasfmode = 0;
299    pComponentPrivate->frameMode = 0;
300    pComponentPrivate->bBufferIsAllocated = 0;
301    pComponentPrivate->bPortDefsAllocated = 0;
302    pComponentPrivate->bCompThreadStarted = 0;
303    pComponentPrivate->bExitCompThrd = 0;
304
305    pComponentPrivate->bInitParamsInitialized = 0;
306    pComponentPrivate->pMarkBuf = NULL;
307    pComponentPrivate->pMarkData = NULL;
308    pComponentPrivate->nEmptyBufferDoneCount = 0;
309    pComponentPrivate->nEmptyThisBufferCount = 0;
310    pComponentPrivate->nFillBufferDoneCount = 0;
311    pComponentPrivate->nFillThisBufferCount = 0;
312    pComponentPrivate->strmAttr = NULL;
313    pComponentPrivate->bDisableCommandParam = 0;
314    pComponentPrivate->bEnableCommandParam = 0;
315    pComponentPrivate->bIsInvalidState = OMX_FALSE;
316    pComponentPrivate->sDeviceString = newmalloc(100*sizeof(OMX_STRING));
317    pComponentPrivate->IpBufindex = 0;
318    pComponentPrivate->OpBufindex = 0;
319    pComponentPrivate->nNumInputBufPending = 0;
320    pComponentPrivate->nNumOutputBufPending = 0;
321    pComponentPrivate->nNumOutputBufPause = 0;
322    pComponentPrivate->SendAfterEOS = 0;
323    pComponentPrivate->nHandledFillThisBuffers=0;
324    pComponentPrivate->nHandledEmptyThisBuffers = 0;
325    pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
326    pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
327
328    pComponentPrivate->bPreempted = OMX_FALSE;
329    pComponentPrivate->first_buff = 0;
330    pComponentPrivate->first_TS = 0;
331    pComponentPrivate->temp_TS = 0;
332    pComponentPrivate->lastout = NULL;
333
334    //bConfigData flag is used to indicate if we need to parse the frame header
335    pComponentPrivate->bConfigData = 1;
336    pComponentPrivate->reconfigInputPort = 0;
337    pComponentPrivate->reconfigOutputPort = 1; //set the initial value to true if you expect to do port config...
338
339    /* Initialize device string to the default value */
340    strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
341
342    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
343        pComponentPrivate->pInputBufHdrPending[i] = NULL;
344        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
345    }
346
347
348
349    pComponentPrivate->nInvalidFrameCount = 0;
350    pComponentPrivate->bDisableCommandPending = 0;
351    pComponentPrivate->bEnableCommandPending = 0;
352
353    pComponentPrivate->numPendingBuffers = 0;
354    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
355    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
356    pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM;
357
358
359    /* initialize role name */
360    strcpy((char*)pComponentPrivate->componentRole.cRole, MP3_DEC_ROLE);
361
362#ifndef UNDER_CE
363    pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
364    pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
365    pComponentPrivate->AlloBuf_waitingsignal = 0;
366
367    pthread_mutex_init(&pComponentPrivate->codecStop_mutex, NULL);
368    pthread_cond_init (&pComponentPrivate->codecStop_threshold, NULL);
369    pComponentPrivate->codecStop_waitingsignal = 0;
370
371    pthread_mutex_init(&pComponentPrivate->codecFlush_mutex, NULL);
372    pthread_cond_init (&pComponentPrivate->codecFlush_threshold, NULL);
373    pComponentPrivate->codecFlush_waitingsignal = 0;
374
375    pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
376    pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
377    pComponentPrivate->InLoaded_readytoidle = 0;
378
379    pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
380    pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
381    pComponentPrivate->InIdle_goingtoloaded = 0;
382#else
383    OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
384    pComponentPrivate->AlloBuf_waitingsignal = 0;
385
386    OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
387    pComponentPrivate->InLoaded_readytoidle = 0;
388
389    OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
390    pComponentPrivate->InIdle_goingtoloaded = 0;
391#endif
392
393    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
394    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
395
396    pComponentPrivate->pPortDef[MP3D_INPUT_PORT] = pPortDef_ip;
397    pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT] = pPortDef_op;
398
399    /* Set input port defaults */
400    pPortDef_ip->nSize                              = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
401    pPortDef_ip->nPortIndex                         = MP3D_INPUT_PORT;
402    pPortDef_ip->eDir                               = OMX_DirInput;
403    pPortDef_ip->nBufferCountActual                 = MP3D_NUM_INPUT_BUFFERS;
404    pPortDef_ip->nBufferCountMin                    = MP3D_NUM_INPUT_BUFFERS;
405    pPortDef_ip->nBufferSize                        = MP3D_INPUT_BUFFER_SIZE;
406    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
407    pPortDef_ip->bEnabled                           = OMX_TRUE;
408    pPortDef_ip->bPopulated                         = OMX_FALSE;
409    pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
410    pPortDef_ip->format.audio.eEncoding             = OMX_AUDIO_CodingMP3;
411    pPortDef_ip->format.audio.cMIMEType             = NULL;
412    pPortDef_ip->format.audio.pNativeRender         = NULL;
413    pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
414
415
416    /* Set output port defaults */
417    pPortDef_op->nSize                              = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
418    pPortDef_op->nPortIndex                         = MP3D_OUTPUT_PORT;
419    pPortDef_op->eDir                               = OMX_DirOutput;
420    pPortDef_op->nBufferCountMin                    = MP3D_NUM_OUTPUT_BUFFERS;
421    pPortDef_op->nBufferCountActual                 = MP3D_NUM_OUTPUT_BUFFERS;
422    pPortDef_op->nBufferSize                        = MP3D_OUTPUT_BUFFER_SIZE;
423    pPortDef_op->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
424    pPortDef_op->bEnabled                           = OMX_TRUE;
425    pPortDef_op->bPopulated                         = OMX_FALSE;
426    pPortDef_op->eDomain                            = OMX_PortDomainAudio;
427    pPortDef_op->format.audio.eEncoding             = OMX_AUDIO_CodingPCM;
428    pPortDef_op->format.audio.cMIMEType             = NULL;
429    pPortDef_op->format.audio.pNativeRender         = NULL;
430    pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
431
432    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
433    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
434    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
435    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
436
437
438    /* Set input port format defaults */
439    pPortFormat = pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat;
440    OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
441    pPortFormat->nPortIndex         = MP3D_INPUT_PORT;
442    pPortFormat->nIndex             = OMX_IndexParamAudioMp3;
443    pPortFormat->eEncoding          = OMX_AUDIO_CodingMP3;
444
445    /* Set output port format defaults */
446    pPortFormat = pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat;
447    OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
448    pPortFormat->nPortIndex         = MP3D_OUTPUT_PORT;
449    pPortFormat->nIndex             = OMX_IndexParamAudioPcm;
450    pPortFormat->eEncoding          = OMX_AUDIO_CodingPCM;
451
452    /* MP3 format defaults */
453    OMX_CONF_INIT_STRUCT(mp3_ip, OMX_AUDIO_PARAM_MP3TYPE);
454    mp3_ip->nPortIndex = MP3D_INPUT_PORT;
455    mp3_ip->nSampleRate = 44100;
456    mp3_ip->nChannels = MP3D_STEREO_STREAM;
457    mp3_ip->eChannelMode = OMX_AUDIO_ChannelModeStereo;
458    mp3_ip->nAudioBandWidth = 0;
459    mp3_ip->eFormat = OMX_AUDIO_MP3StreamFormatMP1Layer3;
460
461    /* PCM format defaults */
462    OMX_CONF_INIT_STRUCT(mp3_op, OMX_AUDIO_PARAM_PCMMODETYPE);
463    mp3_op->nPortIndex = MP3D_OUTPUT_PORT;
464    mp3_op->nBitPerSample = 16;
465    mp3_op->nChannels = MP3D_STEREO_STREAM;
466    mp3_op->nSamplingRate = 44100;
467    mp3_op->eNumData= OMX_NumericalDataSigned;
468    mp3_op->ePCMMode = OMX_AUDIO_PCMModeLinear;
469    mp3_op->bInterleaved = OMX_TRUE;
470
471    pComponentPrivate->bPortDefsAllocated = 1;
472
473#ifdef DSP_RENDERING_ON
474    if((mp3d_fdwrite=open(FIFO1,O_WRONLY))<0) {
475        OMX_ERROR4(pComponentPrivate->dbg, "[MP3 Component] - failure to open WRITE pipe\n");
476        eError = OMX_ErrorHardware;
477    }
478
479    if((mp3d_fdread=open(FIFO2,O_RDONLY))<0) {
480        OMX_ERROR4(pComponentPrivate->dbg, "[MP3 Component] - failure to open READ pipe\n");
481        eError = OMX_ErrorHardware;
482
483    }
484#endif
485
486#ifdef RESOURCE_MANAGER_ENABLED
487    eError = RMProxy_NewInitalize();
488    /*eError = RMProxy_Initalize();*/
489    if (eError != OMX_ErrorNone) {
490        OMX_ERROR4(pComponentPrivate->dbg, ":Error returned from loading ResourceManagerProxy thread\n");
491        goto EXIT;
492    }
493#endif
494
495    eError = Mp3Dec_StartCompThread(pHandle);
496    if (eError != OMX_ErrorNone) {
497        OMX_ERROR4(pComponentPrivate->dbg, "::Error returned from the Component\n");
498        goto EXIT;
499    }
500#ifdef __PERF_INSTRUMENTATION__
501    PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->ComponentThread,
502                       PERF_FOURCC('M','P','3','T'));
503#endif
504 EXIT:
505    if(OMX_ErrorNone != eError) {
506        OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
507        OMX_MEMFREE_STRUCT(pPortDef_ip);
508        OMX_MEMFREE_STRUCT(pPortDef_op);
509        OMX_MEMFREE_STRUCT(mp3_ip);
510        OMX_MEMFREE_STRUCT(mp3_op);
511        OMX_MEMFREE_STRUCT(pComponentPrivate);
512        OMX_MEMFREE_STRUCT(pTemp);
513    }
514    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting OMX_ComponentInit\n");
515    return eError;
516}
517
518
519/* ================================================================================= * */
520/**
521* @fn SendCommand() function receives all the commands from the application.
522*
523* @param phandle This is component handle.
524*
525* @param Cmd    This is commnad set that came from application.
526*
527* @param nParam This is commnad of the commands set that came from application.
528*
529* @param pCmdData This is command data that came with command.
530*
531* @pre          OMX_Init should be called by application.
532*
533* @post         None
534*
535* @return      OMX_ErrorNone = Successful Inirialization of the component\n
536*              OMX_ErrorBadPortIndex = Bad port index specified by application.
537*/
538/* ================================================================================ * */
539static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
540                                  OMX_COMMANDTYPE Cmd,
541                                  OMX_U32 nParam,OMX_PTR pCmdData)
542{
543    OMX_ERRORTYPE eError = OMX_ErrorNone;
544    int nRet;
545    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
546    MP3DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
547
548    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1)
549        pCompPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
550
551#ifdef _ERROR_PROPAGATION__
552    if (pCompPrivate->curState == OMX_StateInvalid){
553        eError = OMX_ErrorInvalidState;
554        goto EXIT;
555    }
556#else
557    OMX_PRINT1(pCompPrivate->dbg, ":: MP3DEC: Entered SendCommand\n");
558    if(pCompPrivate->curState == OMX_StateInvalid){
559        MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInvalidState,"OMX_ErrorInvalidState");
560    }
561#endif
562#ifdef __PERF_INSTRUMENTATION__
563    PERF_SendingCommand(pCompPrivate->pPERF,
564                        Cmd,
565                        (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam,
566                        PERF_ModuleComponent);
567#endif
568
569    switch(Cmd) {
570    case OMX_CommandStateSet:
571        OMX_PRSTATE2(pCompPrivate->dbg, " MP3DEC: Entered switch - Command State Set\n");
572        if (nParam == OMX_StateLoaded) {
573            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
574        }
575        if(pCompPrivate->curState == OMX_StateLoaded) {
576            OMX_PRSTATE2(pCompPrivate->dbg, " MP3DEC: Entered switch - curState == OMX_StateLoaded\n");
577            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
578                OMX_PRDSP1(pCompPrivate->dbg, ":: MP3DEC: Entered switch - nParam == StatExecuting || OMX_StatePause\n");
579                pCompPrivate->cbInfo.EventHandler (pHandle,
580                                                   pHandle->pApplicationPrivate,
581                                                   OMX_EventError,
582                                                   OMX_ErrorIncorrectStateTransition,
583                                                   OMX_TI_ErrorMinor,
584                                                   NULL);
585                OMX_ERROR4(pCompPrivate->dbg, ":: Incorrect St Tr fm Loaded to Executing By App\n");
586                goto EXIT;
587            }
588
589            if(nParam == OMX_StateInvalid) {
590                pCompPrivate->curState = OMX_StateInvalid;
591                pCompPrivate->cbInfo.EventHandler (
592                                                   pHandle,
593                                                   pHandle->pApplicationPrivate,
594                                                   OMX_EventError,
595                                                   OMX_ErrorInvalidState,
596                                                   OMX_TI_ErrorMinor,
597                                                   NULL);
598                OMX_ERROR4(pCompPrivate->dbg, ":: Incorrect State Tr from Loaded to Invalid by Application\n");
599                goto EXIT;
600            }
601        }
602        break;
603    case OMX_CommandFlush:
604        if(nParam > 1 && nParam != -1) {
605            MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
606        }
607        break;
608    case OMX_CommandPortDisable:
609        break;
610    case OMX_CommandPortEnable:
611        OMX_PRDSP2(pCompPrivate->dbg, ":: MP3DEC: Entered switch - Command Port Enable/Disbale\n");
612        break;
613    case OMX_CommandMarkBuffer:
614        OMX_PRBUFFER2(pCompPrivate->dbg, ":: MP3DEC: Entered switch - Command Mark Buffer\n");
615
616        if(nParam > 0) {
617            MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
618        }
619
620        break;
621    default:
622        OMX_PRDSP2(pCompPrivate->dbg, " :: MP3DEC: Entered switch - Default\n");
623        OMX_ERROR2(pCompPrivate->dbg, ":: MP3DEC: Command Received Default \
624                                                      error\n");
625        pCompPrivate->cbInfo.EventHandler(pHandle,
626                                          pHandle->pApplicationPrivate,
627                                          OMX_EventError,
628                                          OMX_ErrorUndefined,
629                                          OMX_TI_ErrorMinor,
630                                          "Invalid Command");
631        break;
632    }
633
634
635    nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
636    if (nRet == -1) {
637        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
638    }
639
640
641    if (Cmd == OMX_CommandMarkBuffer) {
642        nRet = write (pCompPrivate->cmdDataPipe[1], &pCmdData,
643                      sizeof(OMX_PTR));
644        if (nRet == -1) {
645            MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
646        }
647    }
648    else {
649        nRet = write (pCompPrivate->cmdDataPipe[1], &nParam,
650                      sizeof(OMX_U32));
651        if (nRet == -1) {
652            MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
653        }
654    }
655    OMX_PRINT2(pCompPrivate->dbg, ":: MP3DEC:SendCommand - nRet = %d\n",nRet);
656
657
658#ifdef DSP_RENDERING_ON
659    if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting) {
660        /* enable Tee device command*/
661        cmd_data.hComponent = pHandle;
662        cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode;
663        cmd_data.param1 = 0;
664        cmd_data.param2 = 0;
665        cmd_data.streamID = 0;
666
667        if((write(mp3d_fdwrite, &cmd_data, sizeof(cmd_data)))<0) {
668            eError = OMX_ErrorHardware;
669            goto EXIT;
670        }
671    }
672#endif
673
674 EXIT:
675    return eError;
676}
677
678
679
680/* ================================================================================= * */
681/**
682* @fn GetParameter() function gets the various parameter values of the
683* component.
684*
685* @param hComp         This is component handle.
686*
687* @param nParamIndex   This is enumerate values which specifies what kind of
688*                      information is to be retreived form the component.
689*
690* @param ComponentParameterStructure      This is output argument which is
691*                                         filled by the component component
692*
693* @pre          The component should be in loaded state.
694*
695* @post         None
696*
697* @return      OMX_ErrorNone = Successful Inirialization of the component\n
698*              OMX_ErrorBadPortIndex = Bad port index specified by application.
699*/
700/* ================================================================================ * */
701static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
702                                   OMX_INDEXTYPE nParamIndex,
703                                   OMX_PTR ComponentParameterStructure)
704{
705    OMX_ERRORTYPE eError = OMX_ErrorNone;
706    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
707    OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure;
708    /*    OMX_PARAM_BUFFERSUPPLIERTYPE *pBufferSupplier;*/
709
710    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
711
712    MP3D_OMX_CONF_CHECK_CMD(hComp,1,1);
713    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
714    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, ComponentParameterStructure, 1)
715
716
717        OMX_PRINT1(pComponentPrivate->dbg, ":: Entering the GetParameter\n");
718    if (pParameterStructure == NULL) {
719        eError = OMX_ErrorBadParameter;
720        OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter");
721        goto EXIT;
722    }
723#ifdef _ERROR_PROPAGATION__
724    if (pComponentPrivate->curState == OMX_StateInvalid){
725        eError = OMX_ErrorInvalidState;
726        goto EXIT;
727    }
728#else
729    if(pComponentPrivate->curState == OMX_StateInvalid) {
730        eError = OMX_ErrorIncorrectStateOperation;
731        goto EXIT;
732    }
733#endif
734
735    switch(nParamIndex){
736    case OMX_IndexParamAudioInit:
737        OMX_PRDSP2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamAudioInit\n");
738        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
739        memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
740        break;
741    case OMX_IndexParamPortDefinition:
742        OMX_PRDSP2(pComponentPrivate->dbg, ": GetParameter OMX_IndexParamPortDefinition \n");
743        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
744           pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nPortIndex) {
745            memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[MP3D_INPUT_PORT],
746                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
747        } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
748                  pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nPortIndex) {
749            memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT],
750                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
751        } else {
752            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter \n");
753            eError = OMX_ErrorBadPortIndex;
754        }
755        break;
756    case OMX_IndexParamAudioPortFormat:
757        OMX_PRDSP2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamAudioPortFormat \n");
758        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
759           pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nPortIndex) {
760            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
761               pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat->nPortIndex) {
762                eError = OMX_ErrorNoMore;
763            }
764            else {
765                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat,
766                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
767            }
768        }
769        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
770                pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nPortIndex){
771            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
772               pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat->nPortIndex) {
773                eError = OMX_ErrorNoMore;
774            }
775            else {
776                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat,
777                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
778            }
779        }
780        else {
781            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter \n");
782            eError = OMX_ErrorBadPortIndex;
783        }
784
785        break;
786
787    case OMX_IndexParamAudioMp3:
788        OMX_PRDSP2(pComponentPrivate->dbg, " :: GetParameter OMX_IndexParamAudioMp3 \n");
789        if(((OMX_AUDIO_PARAM_MP3TYPE *)(ComponentParameterStructure))->nPortIndex ==
790           pComponentPrivate->mp3Params->nPortIndex) {
791            memcpy(ComponentParameterStructure, pComponentPrivate->mp3Params, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
792        } else {
793            OMX_ERROR4(pComponentPrivate->dbg, " :: OMX_ErrorBadPortIndex from GetParameter \n");
794            eError = OMX_ErrorBadPortIndex;
795        }
796
797        break;
798
799    case OMX_IndexParamPriorityMgmt:
800        OMX_PRDSP2(pComponentPrivate->dbg, " :: GetParameter OMX_IndexParamPriorityMgmt \n");
801        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
802        memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
803
804        break;
805
806    case OMX_IndexParamAudioPcm:
807        OMX_PRDSP2(pComponentPrivate->dbg, " :: GetParameter OMX_IndexParamAudioPcm \n");
808        if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
809           pComponentPrivate->pcmParams->nPortIndex) {
810            memcpy(ComponentParameterStructure,pComponentPrivate->pcmParams, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
811        }else{
812            OMX_PRINT1(pComponentPrivate->dbg, " :: OMX_ErrorBadPortIndex from GetParameter \n");
813            eError = OMX_ErrorBadPortIndex;
814        }
815        break;
816
817    case OMX_IndexParamCompBufferSupplier:
818        if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) {
819            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamCompBufferSupplier \n");
820            /*  memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
821        }
822        else if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) {
823            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamCompBufferSupplier \n");
824            /*memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
825        }
826        else {
827            OMX_ERROR2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter");
828            eError = OMX_ErrorBadPortIndex;
829        }
830
831        break;
832
833    case OMX_IndexParamVideoInit:
834        break;
835
836    case OMX_IndexParamImageInit:
837        break;
838
839    case OMX_IndexParamOtherInit:
840        break;
841
842#ifdef ANDROID
843   case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
844    {
845	OMX_PRDSP1(pComponentPrivate->dbg, "Entering PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX::%d\n", __LINE__);
846        PV_OMXComponentCapabilityFlagsType* pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
847        if (NULL == pCap_flags)
848        {
849            OMX_ERROR4(pComponentPrivate->dbg, "%d :: ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__);
850            eError =  OMX_ErrorBadParameter;
851            goto EXIT;
852        }
853        OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__);
854        memcpy(pCap_flags, &(pComponentPrivate->iPVCapabilityFlags), sizeof(PV_OMXComponentCapabilityFlagsType));
855	eError = OMX_ErrorNone;
856    }
857    break;
858#endif
859
860    default:
861        OMX_ERROR4(pComponentPrivate->dbg, " :: OMX_ErrorUnsupportedIndex GetParameter \n");
862        eError = OMX_ErrorUnsupportedIndex;
863        break;
864    }
865 EXIT:
866    if (pComponentPrivate != NULL) {
867	 OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting GetParameter\n");
868	 OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n", eError);
869    }
870    return eError;
871}
872
873
874/* ================================================================================= * */
875/**
876* @fn SetParameter() function sets the various parameter values of the
877* component.
878*
879* @param hComp         This is component handle.
880*
881* @param nParamIndex   This is enumerate values which specifies what kind of
882*                      information is to be set for the component.
883*
884* @param ComponentParameterStructure      This is input argument which contains
885*                                         the values to be set for the component.
886*
887* @pre          The component should be in loaded state.
888*
889* @post         None
890*
891* @return      OMX_ErrorNone = Successful Inirialization of the component\n
892*              OMX_ErrorBadPortIndex = Bad port index specified by application.
893*/
894/* ================================================================================ * */
895static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
896                                   OMX_INDEXTYPE nParamIndex,
897                                   OMX_PTR pCompParam)
898{
899    OMX_ERRORTYPE eError = OMX_ErrorNone;
900    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
901    OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
902    OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL;
903    OMX_AUDIO_PARAM_MP3TYPE *pCompMp3Param = NULL;
904    OMX_PARAM_COMPONENTROLETYPE  *pRole;
905    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
906    OMX_AUDIO_PARAM_PCMMODETYPE* pPcmPort = NULL;
907
908
909    MP3D_OMX_CONF_CHECK_CMD(hComp,1,1)
910        pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
911    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, pCompParam, 1);
912
913#ifdef _ERROR_PROPAGATION__
914    if (pComponentPrivate->curState == OMX_StateInvalid){
915        eError = OMX_ErrorInvalidState;
916        goto EXIT;
917    }
918#endif
919
920    OMX_PRINT1(pComponentPrivate->dbg, " :: Entering the SetParameter\n");
921    if (pComponentPrivate->curState != OMX_StateLoaded) {
922        eError = OMX_ErrorIncorrectStateOperation;
923        OMX_ERROR4(pComponentPrivate->dbg, " :: OMX_ErrorIncorrectStateOperation from SetParameter");
924        goto EXIT;
925    }
926
927    switch(nParamIndex) {
928    case OMX_IndexParamAudioPortFormat:
929        OMX_PRDSP1(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamAudioPortFormat \n");
930        pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
931        if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat->nPortIndex ) {
932            memcpy(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, pComponentParam,
933                   sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
934        } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
935            memcpy(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, pComponentParam,
936                   sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
937        } else {
938            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
939            eError = OMX_ErrorBadPortIndex;
940        }
941
942        break;
943    case OMX_IndexParamAudioMp3:
944        OMX_PRDSP2(pComponentPrivate->dbg, " :: SetParameter OMX_IndexParamAudioMp3 \n");
945        pCompMp3Param = (OMX_AUDIO_PARAM_MP3TYPE *)pCompParam;
946        if(pCompMp3Param->nPortIndex == MP3D_INPUT_PORT) {
947            MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->mp3Params, 1, 1);
948            memcpy(pComponentPrivate->mp3Params,pCompMp3Param,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
949        }
950        else {
951            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
952            eError = OMX_ErrorBadPortIndex;
953        }
954        break;
955    case OMX_IndexParamPortDefinition:
956        pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
957        if (pComponentParamPort->nPortIndex == 0) {
958            if (pComponentParamPort->eDir != OMX_DirInput) {
959                OMX_ERROR4(pComponentPrivate->dbg, ":: Invalid input buffer Direction\n");
960                eError = OMX_ErrorBadParameter;
961                goto EXIT;
962            }
963            if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingMP3) {
964                OMX_ERROR4(pComponentPrivate->dbg, ":: Invalid format Parameter\n");
965                eError = OMX_ErrorBadParameter;
966                goto EXIT;
967            }
968        } else if (pComponentParamPort->nPortIndex == 1) {
969            if (pComponentParamPort->eDir != OMX_DirOutput) {
970                OMX_ERROR4(pComponentPrivate->dbg, " :: Invalid Output buffer Direction\n");
971                eError = OMX_ErrorBadParameter;
972                goto EXIT;
973            }
974            if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingPCM) {
975                OMX_ERROR4(pComponentPrivate->dbg, ":: Invalid format Parameter\n");
976                eError = OMX_ErrorBadParameter;
977                goto EXIT;
978            }
979        } else {
980            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
981            eError = OMX_ErrorBadPortIndex;
982        }
983        OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamPortDefinition \n");
984        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
985           pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nPortIndex) {
986            OMX_PRINT1(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamPortDefinition \n");
987            memcpy(pComponentPrivate->pPortDef[MP3D_INPUT_PORT], pCompParam,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
988        }
989        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
990                pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nPortIndex) {
991            OMX_PRDSP1(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamPortDefinition \n");
992            memcpy(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT], pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
993        }
994        else {
995            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
996            eError = OMX_ErrorBadPortIndex;
997        }
998        break;
999    case OMX_IndexParamPriorityMgmt:
1000        OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamPriorityMgmt \n");
1001        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
1002        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
1003        break;
1004
1005    case OMX_IndexParamAudioInit:
1006        OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamAudioInit \n");
1007        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
1008        memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
1009        break;
1010
1011    case OMX_IndexParamStandardComponentRole:
1012        if (pCompParam) {
1013            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
1014            memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1015        } else {
1016            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
1017            eError = OMX_ErrorBadParameter;
1018        }
1019        break;
1020
1021    case OMX_IndexParamAudioPcm:
1022        OMX_PRDSP2(pComponentPrivate->dbg, " :: SetParameter OMX_IndexParamAudioPcm \n");
1023        pPcmPort= (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
1024        if(pPcmPort->nPortIndex == MP3D_OUTPUT_PORT){
1025            MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pcmParams, 1, 1);
1026            memcpy(pComponentPrivate->pcmParams, pPcmPort, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
1027        }else{
1028            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
1029            eError = OMX_ErrorBadParameter;
1030        }
1031        break;
1032
1033    case OMX_IndexParamCompBufferSupplier:
1034        /*  eError = OMX_ErrorBadPortIndex; *//*remove for StdAudioDecoderTest, leave for other tests*/
1035        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1036           pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nPortIndex) {
1037            OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1038            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
1039            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1040
1041        }
1042        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1043                pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nPortIndex) {
1044            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1045            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
1046            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1047        }
1048        else {
1049            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
1050            eError = OMX_ErrorBadPortIndex;
1051        }
1052        break;
1053
1054    case OMX_IndexParamVideoInit:
1055    case OMX_IndexParamImageInit:
1056    case OMX_IndexParamOtherInit:
1057        eError = OMX_ErrorNone;
1058        break;
1059
1060    default:
1061        OMX_ERROR4(pComponentPrivate->dbg, ":: SetParameter OMX_ErrorUnsupportedIndex \n");
1062        eError = OMX_ErrorUnsupportedIndex;
1063        break;
1064    }
1065 EXIT:
1066    if (pComponentPrivate != NULL) {
1067	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetParameter\n");
1068	 OMX_PRINT1(pComponentPrivate->dbg, ":: Returning = 0x%x\n", eError);
1069    }
1070    return eError;
1071}
1072
1073/*-------------------------------------------------------------------*/
1074/**
1075  *  SetConfig() Sets the configraiton to the component
1076  *
1077  * @param hComp         handle for this instance of the component
1078  * @param nConfigIndex
1079  * @param ComponentConfigStructure
1080  *
1081  * @retval OMX_NoError              Success, ready to roll
1082  *         OMX_Error_BadParameter   The input parameter pointer is null
1083  **/
1084/*-------------------------------------------------------------------*/
1085
1086static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1087                                OMX_INDEXTYPE nConfigIndex,
1088                                OMX_PTR ComponentConfigStructure)
1089{
1090    OMX_ERRORTYPE eError = OMX_ErrorNone;
1091    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1092    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1093#ifdef DSP_RENDERING_ON
1094    OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
1095    OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
1096#endif
1097    int *customFlag = NULL;
1098    TI_OMX_DSP_DEFINITION *configData;
1099    int flagValue=0;
1100    OMX_S16* deviceString = NULL;
1101    TI_OMX_DATAPATH dataPath;
1102
1103    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1)
1104        pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1105    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1106
1107#ifdef _ERROR_PROPAGATION__
1108        if (pComponentPrivate->curState == OMX_StateInvalid){
1109            eError = OMX_ErrorInvalidState;
1110            goto EXIT;
1111        }
1112#endif
1113
1114    OMX_PRINT1(pComponentPrivate->dbg, ":: Entering SetConfig\n");
1115    if (pHandle == NULL) {
1116        OMX_ERROR4(pComponentPrivate->dbg, " :: Invalid HANDLE OMX_ErrorBadParameter \n");
1117        eError = OMX_ErrorBadParameter;
1118        goto EXIT;
1119    }
1120
1121    switch (nConfigIndex) {
1122        /* set mute/unmute for playback stream */
1123    case OMX_IndexConfigAudioMute:
1124#ifdef DSP_RENDERING_ON
1125        pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure;
1126        OMX_PRDSP2(pComponentPrivate->dbg, "Set Mute/Unmute for playback stream\n");
1127        cmd_data.hComponent = hComp;
1128        if(pMuteStructure->bMute == OMX_TRUE)
1129            {
1130                OMX_PRINT2(pComponentPrivate->dbg, "Mute the playback stream\n");
1131                cmd_data.AM_Cmd = AM_CommandStreamMute;
1132            }
1133        else
1134            {
1135                OMX_PRINT2(pComponentPrivate->dbg, "unMute the playback stream\n");
1136                cmd_data.AM_Cmd = AM_CommandStreamUnMute;
1137            }
1138        cmd_data.param1 = 0;
1139        cmd_data.param2 = 0;
1140        cmd_data.streamID = pComponentPrivate->streamID;
1141
1142        if((write(mp3d_fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1143            {
1144                OMX_ERROR2(pComponentPrivate->dbg, "[MP3 decoder] - fail to send command to audio manager\n");
1145            }
1146#endif
1147        break;
1148        /* set volume for playback stream */
1149    case OMX_IndexConfigAudioVolume:
1150#ifdef DSP_RENDERING_ON
1151        pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
1152        OMX_PRDSP2(pComponentPrivate->dbg, "Set volume for playback stream\n");
1153        cmd_data.hComponent = hComp;
1154        cmd_data.AM_Cmd = AM_CommandSWGain;
1155        cmd_data.param1 = pVolumeStructure->sVolume.nValue;
1156        cmd_data.param2 = 0;
1157        cmd_data.streamID = pComponentPrivate->streamID;
1158
1159        if((write(mp3d_fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1160            {
1161                OMX_ERROR4(pComponentPrivate->dbg, "[MP3 decoder] - fail to send command to audio manager\n");
1162            }
1163#endif
1164        break;
1165    case OMX_IndexCustomMp3DecHeaderInfoConfig:
1166        configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1167
1168
1169        if (configData == NULL) {
1170            eError = OMX_ErrorBadParameter;
1171            OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1172            goto EXIT;
1173        }
1174        if (configData->dasfMode == 0) {
1175            pComponentPrivate->dasfmode = 0;
1176        }
1177        else if (configData->dasfMode == 1) {
1178            pComponentPrivate->dasfmode = 1;
1179        }
1180        else if (configData->dasfMode == 2) {
1181            pComponentPrivate->dasfmode = 1;
1182        }
1183        pComponentPrivate->frameMode = configData->framemode;
1184        pComponentPrivate->streamID = configData->streamId;
1185
1186        if(configData->mpeg1_layer2 == 1)
1187            pComponentPrivate->mpeg1_layer2 = 1;
1188        else
1189            pComponentPrivate->mpeg1_layer2 = 0;
1190
1191
1192        break;
1193    case  OMX_IndexCustomMp3DecDataPath:
1194        deviceString = (OMX_S16*)ComponentConfigStructure;
1195        if (deviceString == NULL) {
1196            eError = OMX_ErrorBadParameter;
1197            goto EXIT;
1198        }
1199        dataPath = *deviceString;
1200        switch(dataPath) {
1201        case DATAPATH_APPLICATION:
1202            /* strcpy((char*)pComponentPrivate->sDeviceString,(char*)ETEEDN_STRING);*/
1203            OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID);
1204
1205            break;
1206
1207        case DATAPATH_APPLICATION_RTMIXER:
1208            strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1209            break;
1210
1211        case DATAPATH_ACDN:
1212            strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1213            break;
1214
1215        default:
1216            break;
1217        }
1218        break;
1219    case MP3D_OMX_IndexCustomModeDasfConfig:
1220        OMX_PRDSP2(pComponentPrivate->dbg, ":: OMX_IndexCustomModeDasfConfig \n");
1221        customFlag = (int*)ComponentConfigStructure;
1222        if (customFlag == NULL) {
1223            eError = OMX_ErrorBadParameter;
1224            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadParameter from SetConfig\n");
1225            goto EXIT;
1226        }
1227        flagValue = *customFlag;
1228        if (flagValue == 0) {
1229            pComponentPrivate->dasfmode = 0;
1230        }
1231        else if (flagValue == 1) {
1232            pComponentPrivate->dasfmode = 1;
1233        }
1234        else if (flagValue == 2) {
1235            pComponentPrivate->dasfmode = 1;
1236        }
1237
1238        break;
1239    case MP3D_OMX_IndexCustomMode16_24bit:
1240        OMX_PRDSP2(pComponentPrivate->dbg, " :: OMX_IndexCustomMode16_24bit \n");
1241        customFlag = (int*)ComponentConfigStructure;
1242        if (customFlag == NULL) {
1243            eError = OMX_ErrorBadParameter;
1244            OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadParameter from SetConfig\n");
1245            goto EXIT;
1246        }
1247        pComponentPrivate->nOpBit = *customFlag;
1248        break;
1249
1250    case OMX_IndexCustomDebug:
1251	OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1252	break;
1253    default:
1254        eError = OMX_ErrorUnsupportedIndex;
1255        break;
1256    }
1257 EXIT:
1258    if (pComponentPrivate != NULL) {
1259	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetConfig\n");
1260	 OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n", eError);
1261    }
1262    return eError;
1263}
1264
1265
1266/* ================================================================================= * */
1267/**
1268* @fn SetCallbacks() Sets application callbacks to the component
1269*
1270* @param pComponent  This is component handle.
1271*
1272* @param pCallBacks  Application callbacks
1273*
1274* @param pAppData    Application specified private data.
1275*
1276* @pre          None
1277*
1278* @post         None
1279*
1280* @return      OMX_ErrorNone = Successful Inirialization of the component
1281*              OMX_ErrorBadParameter = If callback argument is NULL.
1282*/
1283/* ================================================================================ * */
1284
1285static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
1286                                   OMX_CALLBACKTYPE* pCallBacks,
1287                                   OMX_PTR pAppData)
1288{
1289    OMX_ERRORTYPE eError = OMX_ErrorNone;
1290    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
1291
1292    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1293
1294
1295    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
1296
1297    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1298
1299    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1);
1300
1301    OMX_PRINT1(pComponentPrivate->dbg, "Entering SetCallbacks\n");
1302
1303    MP3D_OMX_CONF_CHECK_CMD(pCallBacks, pCallBacks->EventHandler, pCallBacks->EmptyBufferDone);
1304    MP3D_OMX_CONF_CHECK_CMD(pCallBacks->FillBufferDone, 1, 1);
1305
1306    memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
1307    pHandle->pApplicationPrivate = pAppData;
1308    OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Loaded\n\n");
1309    pComponentPrivate->curState = OMX_StateLoaded;
1310 EXIT:
1311    if (pComponentPrivate != NULL) {
1312	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetCallbacks\n");
1313    }
1314    return eError;
1315}
1316
1317
1318/* ================================================================================= * */
1319/**
1320* @fn GetComponentVersion() Sets application callbacks to the component. Currently this
1321* function is not implemented.
1322*
1323* @param hComp  This is component handle.
1324*
1325* @param pComponentName  This is component name.
1326*
1327* @param pComponentVersion  This output argument will contain the component
1328*                           version when this function exits successfully.
1329*
1330* @param pSpecVersion    This is specification version.
1331*
1332* @param pComponentUUID  This specifies the UUID of the component.
1333*
1334* @pre          None
1335*
1336* @post         None
1337*
1338* @return      OMX_ErrorNone = Successful Inirialization of the component
1339*/
1340/* ================================================================================ * */
1341static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
1342                                          OMX_STRING pComponentName,
1343                                          OMX_VERSIONTYPE* pComponentVersion,
1344                                          OMX_VERSIONTYPE* pSpecVersion,
1345                                          OMX_UUIDTYPE* pComponentUUID)
1346{
1347    OMX_ERRORTYPE eError = OMX_ErrorNone;
1348    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
1349#ifdef _ERROR_PROPAGATION__
1350    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
1351#endif
1352    eError = OMX_ErrorNotImplemented;
1353
1354#ifdef _ERROR_PROPAGATION__
1355    if (pComponentPrivate->curState == OMX_StateInvalid){
1356        eError = OMX_ErrorInvalidState;
1357        goto EXIT;
1358    }
1359#endif
1360
1361    OMX_PRINT1(pComponentPrivate->dbg, ":: Entering GetComponentVersion\n");
1362    OMX_PRINT2(pComponentPrivate->dbg, ":: Inside  GetComponentVersion\n");
1363    OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting GetComponentVersion\n");
1364 EXIT:
1365    return eError;
1366
1367}
1368
1369
1370
1371/* ================================================================================= * */
1372/**
1373* @fn GetConfig() gets the configuration of the component depending on the value
1374* of nConfigINdex. This function is currently not implemented.
1375*
1376* @param hComp  This is component handle.
1377*
1378* @param nConfigIndex  This is config index to get the configuration of
1379*                      component.
1380*
1381* @param ComponentConfigStructure This is configuration structure that is filled
1382* by the component depending on the value of nConfigIndex.
1383*
1384* @pre          None
1385*
1386* @post         None
1387*
1388* @return      OMX_ErrorNone = Successful Inirialization of the component
1389*/
1390/* ================================================================================ * */
1391static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1392                                OMX_INDEXTYPE nConfigIndex,
1393                                OMX_PTR ComponentConfigStructure)
1394{
1395    OMX_ERRORTYPE eError = OMX_ErrorNone;
1396
1397    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
1398    TI_OMX_STREAM_INFO *streamInfo;
1399
1400    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1401
1402#ifdef _ERROR_PROPAGATION__
1403    if (pComponentPrivate->curState == OMX_StateInvalid){
1404        eError = OMX_ErrorInvalidState;
1405        goto EXIT;
1406    }
1407#endif
1408
1409    OMX_MALLOC_GENERIC(streamInfo,TI_OMX_STREAM_INFO);
1410
1411    if(nConfigIndex == OMX_IndexCustomMp3DecStreamInfoConfig) {
1412        streamInfo->streamId = pComponentPrivate->streamID;
1413        MP3D_OMX_CONF_CHECK_CMD(ComponentConfigStructure, 1, 1);
1414        memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO));
1415    } else if(nConfigIndex == OMX_IndexCustomDebug) {
1416	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1417    }
1418    OMX_MEMFREE_STRUCT(streamInfo);
1419
1420 EXIT:
1421    return eError;
1422}
1423
1424
1425/* ================================================================================= * */
1426/**
1427* @fn GetState() Gets the current state of the component.
1428*
1429* @param pComponent  This is component handle.
1430*
1431* @param pState      This is the output argument that contains the state of the
1432*                    component.
1433*
1434* @pre          None
1435*
1436* @post         None
1437*
1438* @return      OMX_ErrorNone = Successful Inirialization of the component
1439*              OMX_ErrorBadParameter = if output argument is NULL.
1440*/
1441/* ================================================================================ * */
1442static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1443{
1444    OMX_ERRORTYPE eError = OMX_ErrorUndefined;
1445    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1446
1447
1448    if (!pState) {
1449	OMXDBG_PRINT(stderr, ERROR, 4, 0, " :: About to exit with bad parameter\n");
1450        eError = OMX_ErrorBadParameter;
1451        goto EXIT;
1452    }
1453
1454    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
1455
1456    if (pHandle && pHandle->pComponentPrivate) {
1457        *pState =  ((MP3DEC_COMPONENT_PRIVATE*)
1458                    pHandle->pComponentPrivate)->curState;
1459        /*OMX_PRINT1(pComponentPrivate->dbg, " :: curState = %d\n",(int)*pState);*/
1460    } else {
1461	OMXDBG_PRINT(stderr, STATE, 2, 0, "Component State Set to Loaded\n\n");
1462        *pState = OMX_StateLoaded;
1463    }
1464
1465    eError = OMX_ErrorNone;
1466
1467 EXIT:
1468    return eError;
1469}
1470
1471/* ================================================================================= * */
1472/**
1473* @fn EmptyThisBuffer() This function is used by application to sent the filled
1474* input buffers to the component.
1475*
1476* @param pComponent  This is component handle.
1477*
1478* @param pBuffer     This is poiter to the buffer header that come from the
1479*                    application.
1480*
1481* @pre          None
1482*
1483* @post         None
1484*
1485* @return      OMX_ErrorNone = Successful exit of the function
1486*              OMX_ErrorBadParameter =  Bad input argument
1487*              OMX_ErrorBadPortIndex = Bad port index supplied by the
1488*              application
1489*/
1490/* ================================================================================ * */
1491static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1492                                      OMX_BUFFERHEADERTYPE* pBuffer)
1493{
1494    OMX_ERRORTYPE eError = OMX_ErrorNone;
1495    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1496    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1497    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1498    int ret=0;
1499
1500    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
1501    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1502    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) ;
1503
1504    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[MP3D_INPUT_PORT];
1505
1506#ifdef _ERROR_PROPAGATION__
1507    if (pComponentPrivate->curState == OMX_StateInvalid){
1508        eError = OMX_ErrorInvalidState;
1509        goto EXIT;
1510    }
1511#endif
1512#ifdef __PERF_INSTRUMENTATION__
1513    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1514                       pBuffer->pBuffer,
1515                       pBuffer->nFilledLen,
1516                       PERF_ModuleHLMM);
1517#endif
1518
1519    if(!pPortDef->bEnabled) {
1520        eError = OMX_ErrorIncorrectStateOperation;
1521        goto EXIT;
1522    }
1523
1524    if (pBuffer == NULL) {
1525        eError = OMX_ErrorBadParameter;
1526        goto EXIT;
1527    }
1528
1529    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1530        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"Bad Size");
1531    }
1532
1533    if (pBuffer->nInputPortIndex != MP3D_INPUT_PORT) {
1534        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1535    }
1536
1537
1538    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1539        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorVersionMismatch,"OMX_ErrorVersionMismatch");
1540    }
1541
1542    if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause &&
1543       pComponentPrivate->curState != OMX_StateIdle) {
1544        eError = OMX_ErrorIncorrectStateOperation;
1545        goto EXIT;
1546    }
1547
1548    OMX_PRCOMM2(pComponentPrivate->dbg, "------------------------------------------\n");
1549    OMX_PRCOMM2(pComponentPrivate->dbg, "Sending Filled IN buff %p\n",pBuffer);
1550    OMX_PRCOMM2(pComponentPrivate->dbg, "------------------------------------------\n");
1551
1552    if (pComponentPrivate->bBypassDSP == 0) {
1553        pComponentPrivate->app_nBuf--;
1554    }
1555
1556    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1557    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1558
1559    ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1560                 sizeof(OMX_BUFFERHEADERTYPE*));
1561    if (ret == -1) {
1562        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
1563    }else{
1564        pComponentPrivate->nEmptyThisBufferCount++;
1565    }
1566
1567 EXIT:
1568    if (pComponentPrivate != NULL) {
1569	 OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting EmptyThisBuffer\n");
1570    }
1571    return eError;
1572}
1573
1574/* ================================================================================= * */
1575/**
1576* @fn FillThisBuffer() This function is used by application to sent the empty
1577* output buffers to the component.
1578*
1579* @param pComponent  This is component handle.
1580*
1581* @param pBuffer     This is poiter to the output buffer header that come from the
1582*                    application.
1583*
1584* @pre          None
1585*
1586* @post         None
1587*
1588* @return      OMX_ErrorNone = Successful exit of the function
1589*              OMX_ErrorBadParameter =  Bad input argument
1590*              OMX_ErrorBadPortIndex = Bad port index supplied by the
1591*              application
1592*/
1593/* ================================================================================ * */
1594static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1595                                     OMX_BUFFERHEADERTYPE* pBuffer)
1596{
1597    OMX_ERRORTYPE eError = OMX_ErrorNone;
1598    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1599    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1600    int nRet=0;
1601    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1602
1603    MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
1604    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1605    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1);
1606
1607    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*) pComponentPrivate)->pPortDef[MP3D_OUTPUT_PORT];
1608
1609#ifdef _ERROR_PROPAGATION__
1610    if (pComponentPrivate->curState == OMX_StateInvalid){
1611        eError = OMX_ErrorInvalidState;
1612        goto EXIT;
1613    }
1614#endif
1615#ifdef __PERF_INSTRUMENTATION__
1616    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1617                       pBuffer->pBuffer,
1618                       0,
1619                       PERF_ModuleHLMM);
1620#endif
1621
1622    if(!pPortDef->bEnabled) {
1623        eError = OMX_ErrorIncorrectStateOperation;
1624        goto EXIT;
1625    }
1626
1627    if (pBuffer == NULL) {
1628        eError = OMX_ErrorBadParameter;
1629        goto EXIT;
1630    }
1631
1632    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1633        OMX_ERROR4(pComponentPrivate->dbg, " :: FillThisBuffer: Bad Size\n");
1634        eError = OMX_ErrorBadParameter;
1635        goto EXIT;
1636    }
1637
1638    if (pBuffer->nOutputPortIndex != MP3D_OUTPUT_PORT) {
1639        OMX_ERROR4(pComponentPrivate->dbg, " :: EmptyThisBuffer: BadPortIndex\n");
1640        eError  = OMX_ErrorBadPortIndex;
1641        goto EXIT;
1642    }
1643
1644    OMX_PRBUFFER2(pComponentPrivate->dbg, "::pBuffer->nVersion.nVersion:%ld\n",pBuffer->nVersion.nVersion);
1645    OMX_PRBUFFER2(pComponentPrivate->dbg, "::pComponentPrivate->nVersion:%ld\n",pComponentPrivate->nVersion);
1646
1647    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1648        OMX_ERROR4(pComponentPrivate->dbg, ":: FillThisBuffer: BufferHeader Version Mismatch\n");
1649        OMX_ERROR4(pComponentPrivate->dbg, ":pBuffer->nVersion.nVersion:%ld\n",pBuffer->nVersion.nVersion);
1650        OMX_ERROR4(pComponentPrivate->dbg, "::pComponentPrivate->nVersion:%ld\n",pComponentPrivate->nVersion);
1651
1652        eError = OMX_ErrorVersionMismatch;
1653        goto EXIT;
1654    }
1655
1656    if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
1657        eError = OMX_ErrorIncorrectStateOperation;
1658        goto EXIT;
1659    }
1660
1661    pBuffer->nFilledLen = 0;
1662
1663    if (pComponentPrivate->bBypassDSP == 0) {
1664        pComponentPrivate->app_nBuf--;
1665    }
1666
1667    if(pComponentPrivate->pMarkBuf){
1668        OMX_PRBUFFER2(pComponentPrivate->dbg, "FillThisBuffer Line \n");
1669        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1670        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1671        pComponentPrivate->pMarkBuf = NULL;
1672    }
1673
1674    if (pComponentPrivate->pMarkData) {
1675        OMX_PRBUFFER2(pComponentPrivate->dbg, "FillThisBuffer Line \n");
1676        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1677        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1678        pComponentPrivate->pMarkData = NULL;
1679    }
1680
1681    OMX_PRCOMM2(pComponentPrivate->dbg, "------------------------------------------\n");
1682    OMX_PRCOMM2(pComponentPrivate->dbg, "Sending Emptied OUT buff %p\n",pBuffer);
1683    OMX_PRCOMM2(pComponentPrivate->dbg, "------------------------------------------\n");
1684
1685    nRet = write (pComponentPrivate->dataPipe[1], &pBuffer,
1686                  sizeof (OMX_BUFFERHEADERTYPE*));
1687    if (nRet == -1) {
1688        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
1689    }else{
1690        pComponentPrivate->nFillThisBufferCount++;
1691    }
1692
1693 EXIT:
1694    if (pComponentPrivate != NULL) {
1695	 OMX_PRINT1(pComponentPrivate->dbg, ": Exiting FillThisBuffer\n");
1696    }
1697    return eError;
1698}
1699
1700/* ================================================================================= * */
1701/**
1702* @fn ComponentDeInit() This function deinitializes the component. It is called
1703* from OMX Core, not by application. Albeit, Application does call
1704* OMX_FreeHandle of OMX Core and which in turn calls this function.
1705*
1706* @param pHandle  This is component handle.
1707*
1708* @pre          None
1709*
1710* @post        This function should clean or newfree as much resources as
1711*              possible.
1712*
1713* @return      OMX_ErrorNone = On Success
1714*              Appropriate error number in case any error happens.
1715*/
1716/* ================================================================================ * */
1717static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1718{
1719    OMX_ERRORTYPE eError = OMX_ErrorNone;
1720    OMX_ERRORTYPE eError1 = OMX_ErrorNone;
1721    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1722    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1723    int k=0, k2 = 0;
1724    struct OMX_TI_Debug dbg = {0};
1725
1726    MP3D_OMX_CONF_CHECK_CMD(pComponent,1,1)
1727        pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1728    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1729    dbg = pComponentPrivate->dbg;
1730#ifdef __PERF_INSTRUMENTATION__
1731        PERF_Boundary(pComponentPrivate->pPERF,
1732                      PERF_BoundaryStart | PERF_BoundaryCleanup);
1733#endif
1734
1735#ifdef DSP_RENDERING_ON
1736    close(mp3d_fdwrite);
1737    close(mp3d_fdread);
1738#endif
1739
1740#ifdef RESOURCE_MANAGER_ENABLED
1741    /*eError1 = RMProxy_SendCommand(pHandle, RMProxy_FreeResource, OMX_MP3_Decoder_COMPONENT, 0, NULL);*/
1742    eError1 = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_MP3_Decoder_COMPONENT, 0, 3456, NULL);
1743    if (eError1 != OMX_ErrorNone) {
1744        OMX_ERROR4(dbg, "%d ::Error returned from destroy ResourceManagerProxy thread\n",__LINE__);
1745    }
1746
1747    eError1 = RMProxy_Deinitalize();
1748    if (eError1 != OMX_ErrorNone) {
1749        OMX_ERROR4(dbg, ":: First Error in ComponentDeinit: From RMProxy_Deinitalize\n");
1750        eError = eError1;
1751    }
1752#endif
1753
1754    pComponentPrivate->bExitCompThrd = 1;
1755    write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bExitCompThrd, sizeof(OMX_U16));
1756    k = pthread_join(pComponentPrivate->ComponentThread, (void*)&k2);
1757    if(0 != k) {
1758        if (OMX_ErrorNone == eError) {
1759            OMX_ERROR4(dbg, ":: First Error in ComponentDeinit: From pthread_join\n");
1760            eError = OMX_ErrorHardware;
1761        }
1762    }
1763    eError1 = MP3DEC_FreeCompResources(pHandle);
1764    if (OMX_ErrorNone != eError1) {
1765        if (OMX_ErrorNone == eError) {
1766            OMX_ERROR4(dbg, ":: First Error in ComponentDeinit: From FreeCompResources\n");
1767            eError = eError1;
1768        }
1769    }
1770
1771#ifdef __PERF_INSTRUMENTATION__
1772    PERF_Boundary(pComponentPrivate->pPERF,
1773                  PERF_BoundaryComplete | PERF_BoundaryCleanup);
1774    PERF_Done(pComponentPrivate->pPERF);
1775#endif
1776    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1777
1778    OMX_PRBUFFER2(dbg, ":: Freeing: pComponentPrivate = %p\n",pComponentPrivate);
1779    OMX_PRINT1(dbg, "::*********** ComponentDeinit is Done************** \n");
1780 EXIT:
1781    OMX_DBG_CLOSE(dbg);
1782    OMX_MEMFREE_STRUCT(pComponentPrivate);
1783    return eError;
1784}
1785
1786
1787/* ================================================================================= * */
1788/**
1789* @fn ComponentTunnelRequest() This function estabilishes the tunnel between two
1790* components. This is not implemented currently.
1791*
1792* @param hComp  Handle of this component.
1793*
1794* @param nPort Port of this component on which tunneling has to be done.
1795*
1796* @param hTunneledComp Handle of the component with which tunnel has to be
1797*                      established.
1798*
1799* @param nTunneledPort Port of the tunneling component.
1800*
1801* @param pTunnelSetup Tunnel Setuup parameters.
1802*
1803* @pre          None
1804*
1805* @post        None
1806*
1807* @return      OMX_ErrorNone = On Success
1808*              Appropriate error number in case any error happens.
1809*/
1810/* ================================================================================ * */
1811static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1812                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1813                                             OMX_U32 nTunneledPort,
1814                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1815{
1816    OMX_ERRORTYPE eError = OMX_ErrorNone;
1817    OMXDBG_PRINT(stderr, PRINT, 1, 0, ":: Entering ComponentTunnelRequest\n");
1818    OMXDBG_PRINT(stderr, PRINT, 2, 0, " :: Inside   ComponentTunnelRequest\n");
1819    eError = OMX_ErrorNotImplemented;
1820    OMXDBG_PRINT(stderr, PRINT, 1, 0, " :: Exiting ComponentTunnelRequest\n");
1821    return eError;
1822}
1823
1824static void waitForAlloBufThreshold(
1825        MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) {
1826#ifndef UNDER_CE
1827    pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1828    pComponentPrivate->AlloBuf_waitingsignal = 1;
1829    while (pComponentPrivate->AlloBuf_waitingsignal) {
1830        pthread_cond_wait(
1831                &pComponentPrivate->AlloBuf_threshold,
1832                &pComponentPrivate->AlloBuf_mutex);
1833    }
1834    pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1835#else
1836    // I am fairly sure this will suffer from similar issues without
1837    // proper mutex protection and a loop under WinCE...
1838    pComponentPrivate->AlloBuf_waitingsignal = 1;
1839    OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1840#endif
1841}
1842
1843/* ================================================================================= * */
1844/**
1845* @fn AllocateBuffer() This function allocated the memory for the buffer onm
1846* request from application.
1847*
1848* @param hComponent  Handle of this component.
1849*
1850* @param pBuffer  Pointer to the buffer header.
1851*
1852* @param nPortIndex  Input port or Output port
1853*
1854* @param pAppPrivate Application private data.
1855*
1856* @param nSizeBytes Size of the buffer that is to be allocated.
1857*
1858* @pre          None
1859*
1860* @post        Requested buffer should get the memory allocated.
1861*
1862* @return      OMX_ErrorNone = On Success
1863*              OMX_ErrorBadPortIndex = Bad port index from app
1864*/
1865/* ================================================================================ * */
1866static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1867                   OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1868                   OMX_IN OMX_U32 nPortIndex,
1869                   OMX_IN OMX_PTR pAppPrivate,
1870                   OMX_IN OMX_U32 nSizeBytes)
1871{
1872    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1873    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1874    OMX_ERRORTYPE eError = OMX_ErrorNone;
1875    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1876
1877
1878    MP3D_OMX_CONF_CHECK_CMD(hComponent,1,1);
1879    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1880    OMX_PRINT1 (pComponentPrivate->dbg,"Entering AllocateBuffer\n");
1881
1882    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1883#ifdef _ERROR_PROPAGATION__
1884    if (pComponentPrivate->curState == OMX_StateInvalid){
1885        eError = OMX_ErrorInvalidState;
1886        goto EXIT;
1887    }
1888#endif
1889
1890    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1891
1892    MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1);
1893
1894    if(!pPortDef->bEnabled){
1895        waitForAlloBufThreshold(pComponentPrivate);
1896    }
1897
1898    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1899    memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
1900
1901    /* This extra 256 bytes memory is required to avoid DSP caching issues */
1902    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
1903    OMX_PRBUFFER2(pComponentPrivate->dbg, ": Malloced = %p\n",pBufferHeader->pBuffer);
1904    pBufferHeader->nVersion.nVersion = MP3DEC_BUFHEADER_VERSION;
1905
1906    OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
1907    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Allocated BufHeader %p Buffer = %p, on port %ld\n",pBufferHeader,
1908                  pBufferHeader->pBuffer, nPortIndex);
1909
1910    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Ip Num = %ld\n", pComponentPrivate->pInputBufferList->numBuffers);
1911    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Op Num = %ld\n", pComponentPrivate->pOutputBufferList->numBuffers);
1912    OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
1913
1914    pBufferHeader->pAppPrivate = pAppPrivate;
1915    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1916    pBufferHeader->nAllocLen = nSizeBytes;
1917
1918#ifdef __PERF_INSTRUMENTATION__
1919    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
1920                        (*pBuffer)->pBuffer, nSizeBytes,
1921                        PERF_ModuleMemory);
1922#endif
1923
1924    if (nPortIndex == MP3D_INPUT_PORT) {
1925        pBufferHeader->nInputPortIndex = nPortIndex;
1926        pBufferHeader->nOutputPortIndex = -1;
1927        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1928        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1929
1930        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->pBufHdr[%ld] = %p\n", pComponentPrivate->pInputBufferList->numBuffers,
1931                      pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1932
1933        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1934
1935        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %ld\n",pComponentPrivate->pInputBufferList->numBuffers);
1936        OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDef->nBufferCountMin = %ld\n",pPortDef->nBufferCountMin);
1937
1938        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1939            pPortDef->bPopulated = 1;
1940        }
1941    } else if (nPortIndex == MP3D_OUTPUT_PORT) {
1942        pBufferHeader->nInputPortIndex = -1;
1943        pBufferHeader->nOutputPortIndex = nPortIndex;
1944        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
1945        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1946
1947        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1948
1949
1950        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->pBufHdr[%ld] = %p\n",pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1951
1952        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1953
1954        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1955            pPortDef->bPopulated = 1;
1956        }
1957
1958    } else {
1959        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1960    }
1961
1962    if((pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled)&&
1963       (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) &&
1964       (pComponentPrivate->InLoaded_readytoidle))
1965        {
1966            pComponentPrivate->InLoaded_readytoidle = 0;
1967#ifndef UNDER_CE
1968
1969            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1970            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1971            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1972#else
1973            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1974#endif
1975        }
1976
1977    pBufferHeader->pAppPrivate = pAppPrivate;
1978    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1979    pBufferHeader->nAllocLen = nSizeBytes;
1980    pBufferHeader->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER;
1981    pBufferHeader->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER;
1982    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1983
1984
1985    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1986
1987    *pBuffer = pBufferHeader;
1988    pComponentPrivate->bufAlloced = 1;
1989
1990    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
1991        SendCommand (pComponentPrivate->pHandle,
1992                     OMX_CommandPortEnable,
1993                     pComponentPrivate->bEnableCommandParam,NULL);
1994    }
1995
1996 EXIT:
1997    if(OMX_ErrorNone != eError) {
1998	 if (pComponentPrivate != NULL) {
1999	     OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n", __LINE__);
2000	}
2001	if (pBufferHeader != NULL) {
2002	     OMX_MEMFREE_STRUCT_DSPALIGN(pBufferHeader->pBuffer, OMX_U8);
2003	     OMX_MEMFREE_STRUCT(pBufferHeader);
2004	}
2005    }
2006    return eError;
2007}
2008
2009/* ================================================================================= * */
2010/**
2011* @fn FreeBuffer() This function newfrees the meomory of the buffer specified.
2012*
2013* @param hComponent  Handle of this component.
2014*
2015* @param nPortIndex  Input port or Output port
2016*
2017* @param pBuffer  Pointer to the buffer header.
2018*
2019* @pre          None
2020*
2021* @post        Requested buffer should get the memory allocated.
2022*
2023* @return      OMX_ErrorNone = On Success
2024*              OMX_ErrorBadPortIndex = Bad port index from app
2025*/
2026/* ================================================================================ * */
2027static OMX_ERRORTYPE FreeBuffer(
2028            OMX_IN  OMX_HANDLETYPE hComponent,
2029            OMX_IN  OMX_U32 nPortIndex,
2030            OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2031{
2032    OMX_ERRORTYPE eError = OMX_ErrorNone;
2033    MP3DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
2034    OMX_U8* buff;
2035    int i;
2036    int inputIndex = -1;
2037    int outputIndex = -1;
2038    OMX_COMPONENTTYPE *pHandle;
2039
2040
2041    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *) (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2042    OMX_PRINT1(pComponentPrivate->dbg, ":: Entering FreeBuffer\n");
2043
2044    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
2045    OMX_PRINT2(pComponentPrivate->dbg, ":: pComponentPrivate = %p\n",pComponentPrivate);
2046    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
2047        buff = (OMX_U8 *)pComponentPrivate->pInputBufferList->pBufHdr[i];
2048        if (buff == (OMX_U8 *)pBuffer) {
2049            OMX_PRINT2(pComponentPrivate->dbg, "Found matching input buffer\n");
2050            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
2051            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2052            inputIndex = i;
2053            break;
2054        }
2055    }
2056
2057    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
2058        buff = (OMX_U8 *)pComponentPrivate->pOutputBufferList->pBufHdr[i];
2059        if (buff == (OMX_U8 *)pBuffer) {
2060            OMX_PRINT2(pComponentPrivate->dbg, "Found matching output buffer\n");
2061            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
2062            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2063            outputIndex = i;
2064            break;
2065        }
2066    }
2067
2068    if (inputIndex != -1) {
2069        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
2070            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
2071        }
2072#ifdef __PERF_INSTRUMENTATION__
2073        PERF_SendingBuffer(pComponentPrivate->pPERF,
2074                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,
2075                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
2076                           PERF_ModuleMemory);
2077#endif
2078        OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: %p IP Buf Header\n\n",
2079                        pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
2080
2081        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
2082        pComponentPrivate->pInputBufferList->pBufHdr[inputIndex] = NULL;
2083        pComponentPrivate->pInputBufferList->numBuffers--;
2084
2085        if (pComponentPrivate->pInputBufferList->numBuffers <
2086            pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nBufferCountMin) {
2087            pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated = OMX_FALSE;
2088        }
2089
2090#ifndef UNDER_CE
2091        if(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled &&
2092           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
2093           !pComponentPrivate->reconfigInputPort &&
2094           (pComponentPrivate->curState == OMX_StateIdle ||
2095            pComponentPrivate->curState == OMX_StateExecuting ||
2096            pComponentPrivate->curState == OMX_StatePause)) {
2097
2098            pComponentPrivate->cbInfo.EventHandler(pHandle,
2099                                                   pHandle->pApplicationPrivate,
2100                                                   OMX_EventError,
2101                                                   OMX_ErrorPortUnpopulated,
2102                                                   nPortIndex,
2103                                                   NULL);
2104        }
2105
2106#else
2107        if(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled &&
2108           pComponentPrivate->bLoadedCommandPending == OMX_TRUE &&
2109           (pComponentPrivate->curState == OMX_StateIdle ||
2110            pComponentPrivate->curState == OMX_StateExecuting ||
2111            pComponentPrivate->curState == OMX_StatePause)) {
2112
2113            pComponentPrivate->cbInfo.EventHandler(pHandle,
2114                                                   pHandle->pApplicationPrivate,
2115                                                   OMX_EventError,
2116                                                   OMX_ErrorPortUnpopulated,
2117                                                   nPortIndex,
2118                                                   NULL);
2119        }
2120#endif
2121    } else if (outputIndex != -1) {
2122        if (pComponentPrivate->pOutputBufferList->bBufferPending[outputIndex]) {
2123            pComponentPrivate->numPendingBuffers++;
2124        }
2125
2126        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
2127            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
2128        }
2129#ifdef __PERF_INSTRUMENTATION__
2130        PERF_SendingBuffer(pComponentPrivate->pPERF,
2131                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,
2132                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen,
2133                           PERF_ModuleMemory);
2134#endif
2135        OMX_PRBUFFER2(pComponentPrivate->dbg, " Freeing: %p OP Buf Header\n\n",
2136                        pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
2137        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
2138        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
2139        pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
2140        pComponentPrivate->pOutputBufferList->numBuffers--;
2141
2142        if (pComponentPrivate->pOutputBufferList->numBuffers <
2143            pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nBufferCountMin) {
2144            pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated = OMX_FALSE;
2145        }
2146#ifndef UNDER_CE
2147        if(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled &&
2148           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
2149           !pComponentPrivate->reconfigOutputPort &&
2150           (pComponentPrivate->curState == OMX_StateIdle ||
2151            pComponentPrivate->curState == OMX_StateExecuting ||
2152            pComponentPrivate->curState == OMX_StatePause)) {
2153
2154            pComponentPrivate->cbInfo.EventHandler(pHandle,
2155                                                   pHandle->pApplicationPrivate,
2156                                                   OMX_EventError,
2157                                                   OMX_ErrorPortUnpopulated,
2158                                                   nPortIndex,
2159                                                   NULL);
2160        }
2161#else
2162        if(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled &&
2163           pComponentPrivate->bLoadedCommandPending == OMX_TRUE &&
2164           (pComponentPrivate->curState == OMX_StateIdle ||
2165            pComponentPrivate->curState == OMX_StateExecuting ||
2166            pComponentPrivate->curState == OMX_StatePause)) {
2167            pComponentPrivate->cbInfo.EventHandler(pHandle,
2168                                                   pHandle->pApplicationPrivate,
2169                                                   OMX_EventError,
2170                                                   OMX_ErrorPortUnpopulated,
2171                                                   nPortIndex,
2172                                                   NULL);
2173        }
2174#endif
2175    } else {
2176        OMX_ERROR4(pComponentPrivate->dbg, ":Returning OMX_ErrorBadParameter\n");
2177        eError = OMX_ErrorBadParameter;
2178    }
2179
2180    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
2181         !pComponentPrivate->pOutputBufferList->numBuffers) &&
2182        pComponentPrivate->InIdle_goingtoloaded){
2183        pComponentPrivate->InIdle_goingtoloaded = 0;
2184
2185        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
2186        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
2187        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
2188
2189    }
2190
2191///
2192   if ((pComponentPrivate->bDisableCommandPending) &&
2193         (pComponentPrivate->pInputBufferList->numBuffers == 0))
2194    {
2195        OMX_PRCOMM2(pComponentPrivate->dbg, "calling command completed for input port disable\n");
2196        pComponentPrivate->bDisableCommandPending = 0;
2197        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2198                                                pComponentPrivate->pHandle->pApplicationPrivate,
2199                                                        OMX_EventCmdComplete,
2200                                                        OMX_CommandPortDisable,
2201                                                        INPUT_PORT_MP3DEC,
2202                                                        NULL);
2203    }
2204
2205
2206  if ((pComponentPrivate->bDisableCommandPending) &&
2207         (pComponentPrivate->pOutputBufferList->numBuffers == 0))
2208    {
2209        OMX_PRCOMM2(pComponentPrivate->dbg, "calling command completed for output port disable\n");
2210        pComponentPrivate->bDisableCommandPending = 0;
2211        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2212                                                pComponentPrivate->pHandle->pApplicationPrivate,
2213                                                OMX_EventCmdComplete,
2214                                                OMX_CommandPortDisable,
2215                                                OUTPUT_PORT_MP3DEC,
2216                                                NULL);
2217    }
2218
2219
2220
2221    pComponentPrivate->bufAlloced = 0;
2222    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting FreeBuffer\n");
2223    return eError;
2224}
2225
2226
2227/* ================================================================================= * */
2228/**
2229* @fn UseBuffer() This function is called by application when app allocated the
2230* memory for the buffer and sends it to application for use of component.
2231*
2232* @param hComponent  Handle of this component.
2233*
2234* @param ppBufferHdr  Double pointer to the buffer header.
2235*
2236* @param nPortIndex  Input port or Output port
2237*
2238* @param pAppPrivate Application private data.
2239*
2240* @param nSizeBytes Size of the buffer that is to be allocated.
2241*
2242* @param pBuffer    Pointer to data buffer which was allocated by the
2243* application.
2244*
2245* @pre          None
2246*
2247* @post        None
2248*
2249* @return      OMX_ErrorNone = On Success
2250*              OMX_ErrorBadPortIndex = Bad port index from app
2251*/
2252/* ================================================================================ * */
2253static OMX_ERRORTYPE UseBuffer (
2254            OMX_IN OMX_HANDLETYPE hComponent,
2255            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
2256            OMX_IN OMX_U32 nPortIndex,
2257            OMX_IN OMX_PTR pAppPrivate,
2258            OMX_IN OMX_U32 nSizeBytes,
2259            OMX_IN OMX_U8* pBuffer)
2260{
2261    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
2262    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
2263    OMX_ERRORTYPE eError = OMX_ErrorNone;
2264    OMX_BUFFERHEADERTYPE *pBufferHeader;
2265
2266    OMXDBG_PRINT(stderr, PRINT, 1, 0, ":: Entering UseBuffer\n");
2267
2268    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2269
2270#ifdef _ERROR_PROPAGATION__
2271    if (pComponentPrivate->curState == OMX_StateInvalid){
2272        eError = OMX_ErrorInvalidState;
2273        goto EXIT;
2274    }
2275#endif
2276#ifdef __PERF_INSTRUMENTATION__
2277    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
2278                        pBuffer, nSizeBytes,
2279                        PERF_ModuleHLMM);
2280#endif
2281
2282    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)
2283                pComponentPrivate)->pPortDef[nPortIndex];
2284
2285    MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1);
2286    if(!pPortDef->bEnabled) {
2287        waitForAlloBufThreshold(pComponentPrivate);
2288    }
2289    OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef = %p\n",pPortDef);
2290    OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef->bEnabled = %d\n",pPortDef->bEnabled);
2291
2292    if(!pPortDef->bEnabled) {
2293        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
2294                            "Port is Disabled: OMX_ErrorIncorrectStateOperation");
2295    }
2296#ifndef UNDER_CE
2297    if(pPortDef->bPopulated) {
2298        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,
2299                            "Bad Size or Port Disabled : OMX_ErrorBadParameter");
2300    }
2301#endif
2302
2303    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
2304    memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
2305
2306    if (nPortIndex == MP3D_OUTPUT_PORT) {
2307        pBufferHeader->nInputPortIndex = -1;
2308        pBufferHeader->nOutputPortIndex = nPortIndex;
2309        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
2310        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
2311        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
2312        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
2313        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2314            pPortDef->bPopulated = OMX_TRUE;
2315        }
2316    }
2317    else {
2318        pBufferHeader->nInputPortIndex = nPortIndex;
2319        pBufferHeader->nOutputPortIndex = -1;
2320        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
2321        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
2322        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
2323        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2324            pPortDef->bPopulated = OMX_TRUE;
2325        }
2326    }
2327
2328    if((pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled)&&
2329       (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) &&
2330       (pComponentPrivate->InLoaded_readytoidle))
2331        {
2332            pComponentPrivate->InLoaded_readytoidle = 0;
2333#ifndef UNDER_CE
2334            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2335            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2336            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2337#else
2338            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2339#endif
2340
2341        }
2342
2343    pBufferHeader->pAppPrivate = pAppPrivate;
2344    pBufferHeader->pPlatformPrivate = pComponentPrivate;
2345    pBufferHeader->nAllocLen = nSizeBytes;
2346    pBufferHeader->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER;
2347    pBufferHeader->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER;
2348    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2349    pBufferHeader->pBuffer = pBuffer;
2350    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2351    *ppBufferHdr = pBufferHeader;
2352    pComponentPrivate->bufAlloced = 1;
2353
2354    if (pComponentPrivate->bEnableCommandPending){
2355        SendCommand (pComponentPrivate->pHandle,
2356                     OMX_CommandPortEnable,
2357                     pComponentPrivate->bEnableCommandParam,NULL);
2358    }
2359
2360    OMX_PRINT1(pComponentPrivate->dbg, "pBufferHeader = %p\n",pBufferHeader);
2361 EXIT:
2362    return eError;
2363}
2364
2365/* ================================================================================= */
2366/**
2367* @fn GetExtensionIndex() description for GetExtensionIndex
2368GetExtensionIndex().
2369Returns index for vendor specific settings.
2370*
2371*  @see         OMX_Core.h
2372*/
2373/* ================================================================================ */
2374static OMX_ERRORTYPE GetExtensionIndex(
2375            OMX_IN  OMX_HANDLETYPE hComponent,
2376            OMX_IN  OMX_STRING cParameterName,
2377            OMX_OUT OMX_INDEXTYPE *pIndexType)
2378{
2379    OMX_ERRORTYPE eError = OMX_ErrorNone;
2380
2381    if(!(strcmp(cParameterName,"OMX.TI.index.config.mp3headerinfo"))) {
2382        *pIndexType = OMX_IndexCustomMp3DecHeaderInfoConfig;
2383    }
2384    else if (!(strcmp(cParameterName,"OMX.TI.index.config.mp3streamIDinfo"))) {
2385        *pIndexType = OMX_IndexCustomMp3DecStreamInfoConfig;
2386    }
2387    else if(!(strcmp(cParameterName,"OMX.TI.index.config.mp3.datapath"))){
2388        *pIndexType = OMX_IndexCustomMp3DecDataPath;
2389    }
2390    else if(!(strcmp(cParameterName,"OMX.TI.MP3.Decode.Debug"))){
2391        *pIndexType = OMX_IndexCustomDebug;
2392    }
2393    else {
2394        eError = OMX_ErrorBadParameter;
2395    }
2396    return eError;
2397}
2398
2399/* ================================================================================= */
2400/**
2401* @fn ComponentRoleEnum() description for ComponentRoleEnum()
2402
2403Returns the role at the given index
2404*
2405*  @see         OMX_Core.h
2406*/
2407/* ================================================================================ */
2408static OMX_ERRORTYPE ComponentRoleEnum(
2409         OMX_IN OMX_HANDLETYPE hComponent,
2410      OMX_OUT OMX_U8 *cRole,
2411         OMX_IN OMX_U32 nIndex)
2412{
2413    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
2414
2415    OMX_ERRORTYPE eError = OMX_ErrorNone;
2416    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2417    if (cRole == NULL){
2418        eError = OMX_ErrorBadParameter;
2419    }
2420    else if(nIndex == 0){
2421        memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
2422        OMX_PRINT1(pComponentPrivate->dbg, "[ComponenetRoleEnum] cRole = %s\n",cRole);
2423    }
2424    else {
2425        eError = OMX_ErrorNoMore;
2426    }
2427
2428    return eError;
2429}
2430
2431#ifdef UNDER_CE
2432/* ================================================================================= */
2433/**
2434* @fns Sleep replace for WIN CE
2435*/
2436/* ================================================================================ */
2437int OMX_CreateEvent(OMX_Event *event){
2438    int ret = OMX_ErrorNone;
2439    HANDLE createdEvent = NULL;
2440    if(event == NULL){
2441        ret = OMX_ErrorBadParameter;
2442        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2443        goto EXIT;
2444    }
2445    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2446    if(event->event == NULL)
2447        ret = (int)GetLastError();
2448 EXIT:
2449    return ret;
2450}
2451
2452int OMX_SignalEvent(OMX_Event *event){
2453     int ret = OMX_ErrorNone;
2454     if(event == NULL){
2455        ret = OMX_ErrorBadParameter;
2456        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2457        goto EXIT;
2458     }
2459     SetEvent(event->event);
2460     ret = (int)GetLastError();
2461EXIT:
2462    return ret;
2463}
2464
2465int OMX_WaitForEvent(OMX_Event *event) {
2466     int ret = OMX_ErrorNone;
2467     if(event == NULL){
2468        ret = OMX_ErrorBadParameter;
2469        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2470        goto EXIT;
2471     }
2472     WaitForSingleObject(event->event, INFINITE);
2473     ret = (int)GetLastError();
2474EXIT:
2475     return ret;
2476}
2477
2478int OMX_DestroyEvent(OMX_Event *event) {
2479     int ret = OMX_ErrorNone;
2480     if(event == NULL){
2481        ret = OMX_ErrorBadParameter;
2482        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2483        goto EXIT;
2484     }
2485     CloseHandle(event->event);
2486EXIT:
2487     return ret;
2488}
2489#endif
2490
2491