OMX_Mp3Decoder.c revision 36733d62c0d4c565da10b34978e587d0fda0f1ad
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
1824
1825
1826/* ================================================================================= * */
1827/**
1828* @fn AllocateBuffer() This function allocated the memory for the buffer onm
1829* request from application.
1830*
1831* @param hComponent  Handle of this component.
1832*
1833* @param pBuffer  Pointer to the buffer header.
1834*
1835* @param nPortIndex  Input port or Output port
1836*
1837* @param pAppPrivate Application private data.
1838*
1839* @param nSizeBytes Size of the buffer that is to be allocated.
1840*
1841* @pre          None
1842*
1843* @post        Requested buffer should get the memory allocated.
1844*
1845* @return      OMX_ErrorNone = On Success
1846*              OMX_ErrorBadPortIndex = Bad port index from app
1847*/
1848/* ================================================================================ * */
1849static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1850                   OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1851                   OMX_IN OMX_U32 nPortIndex,
1852                   OMX_IN OMX_PTR pAppPrivate,
1853                   OMX_IN OMX_U32 nSizeBytes)
1854{
1855    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1856    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1857    OMX_ERRORTYPE eError = OMX_ErrorNone;
1858    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1859
1860
1861    MP3D_OMX_CONF_CHECK_CMD(hComponent,1,1);
1862    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1863    OMX_PRINT1 (pComponentPrivate->dbg,"Entering AllocateBuffer\n");
1864
1865    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
1866#ifdef _ERROR_PROPAGATION__
1867    if (pComponentPrivate->curState == OMX_StateInvalid){
1868        eError = OMX_ErrorInvalidState;
1869        goto EXIT;
1870    }
1871#endif
1872
1873    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1874
1875    MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1);
1876
1877    if(!pPortDef->bEnabled){
1878        pComponentPrivate->AlloBuf_waitingsignal = 1;
1879#ifndef UNDER_CE
1880        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1881        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
1882        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1883#else
1884        OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1885#endif
1886    }
1887
1888    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1889    memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
1890
1891    /* This extra 256 bytes memory is required to avoid DSP caching issues */
1892    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
1893    OMX_PRBUFFER2(pComponentPrivate->dbg, ": Malloced = %p\n",pBufferHeader->pBuffer);
1894    pBufferHeader->nVersion.nVersion = MP3DEC_BUFHEADER_VERSION;
1895
1896    OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
1897    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Allocated BufHeader %p Buffer = %p, on port %ld\n",pBufferHeader,
1898                  pBufferHeader->pBuffer, nPortIndex);
1899
1900    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Ip Num = %ld\n", pComponentPrivate->pInputBufferList->numBuffers);
1901    OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Op Num = %ld\n", pComponentPrivate->pOutputBufferList->numBuffers);
1902    OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
1903
1904    pBufferHeader->pAppPrivate = pAppPrivate;
1905    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1906    pBufferHeader->nAllocLen = nSizeBytes;
1907
1908#ifdef __PERF_INSTRUMENTATION__
1909    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
1910                        (*pBuffer)->pBuffer, nSizeBytes,
1911                        PERF_ModuleMemory);
1912#endif
1913
1914    if (nPortIndex == MP3D_INPUT_PORT) {
1915        pBufferHeader->nInputPortIndex = nPortIndex;
1916        pBufferHeader->nOutputPortIndex = -1;
1917        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1918        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1919
1920        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->pBufHdr[%ld] = %p\n", pComponentPrivate->pInputBufferList->numBuffers,
1921                      pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1922
1923        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1924
1925        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %ld\n",pComponentPrivate->pInputBufferList->numBuffers);
1926        OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDef->nBufferCountMin = %ld\n",pPortDef->nBufferCountMin);
1927
1928        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1929            pPortDef->bPopulated = 1;
1930        }
1931    } else if (nPortIndex == MP3D_OUTPUT_PORT) {
1932        pBufferHeader->nInputPortIndex = -1;
1933        pBufferHeader->nOutputPortIndex = nPortIndex;
1934        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
1935        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1936
1937        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1938
1939
1940        OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->pBufHdr[%ld] = %p\n",pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1941
1942        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1943
1944        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1945            pPortDef->bPopulated = 1;
1946        }
1947
1948    } else {
1949        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1950    }
1951
1952    if((pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled)&&
1953       (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) &&
1954       (pComponentPrivate->InLoaded_readytoidle))
1955        {
1956            pComponentPrivate->InLoaded_readytoidle = 0;
1957#ifndef UNDER_CE
1958
1959            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1960            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1961            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1962#else
1963            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1964#endif
1965        }
1966
1967    pBufferHeader->pAppPrivate = pAppPrivate;
1968    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1969    pBufferHeader->nAllocLen = nSizeBytes;
1970    pBufferHeader->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER;
1971    pBufferHeader->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER;
1972    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1973
1974
1975    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1976
1977    *pBuffer = pBufferHeader;
1978    pComponentPrivate->bufAlloced = 1;
1979
1980    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
1981        SendCommand (pComponentPrivate->pHandle,
1982                     OMX_CommandPortEnable,
1983                     pComponentPrivate->bEnableCommandParam,NULL);
1984    }
1985
1986 EXIT:
1987    if(OMX_ErrorNone != eError) {
1988	 if (pComponentPrivate != NULL) {
1989	     OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n", __LINE__);
1990	}
1991	if (pBufferHeader != NULL) {
1992	     OMX_MEMFREE_STRUCT_DSPALIGN(pBufferHeader->pBuffer, OMX_U8);
1993	     OMX_MEMFREE_STRUCT(pBufferHeader);
1994	}
1995    }
1996    return eError;
1997}
1998
1999/* ================================================================================= * */
2000/**
2001* @fn FreeBuffer() This function newfrees the meomory of the buffer specified.
2002*
2003* @param hComponent  Handle of this component.
2004*
2005* @param nPortIndex  Input port or Output port
2006*
2007* @param pBuffer  Pointer to the buffer header.
2008*
2009* @pre          None
2010*
2011* @post        Requested buffer should get the memory allocated.
2012*
2013* @return      OMX_ErrorNone = On Success
2014*              OMX_ErrorBadPortIndex = Bad port index from app
2015*/
2016/* ================================================================================ * */
2017static OMX_ERRORTYPE FreeBuffer(
2018            OMX_IN  OMX_HANDLETYPE hComponent,
2019            OMX_IN  OMX_U32 nPortIndex,
2020            OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
2021{
2022    OMX_ERRORTYPE eError = OMX_ErrorNone;
2023    MP3DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
2024    OMX_U8* buff;
2025    int i;
2026    int inputIndex = -1;
2027    int outputIndex = -1;
2028    OMX_COMPONENTTYPE *pHandle;
2029
2030
2031    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *) (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2032    OMX_PRINT1(pComponentPrivate->dbg, ":: Entering FreeBuffer\n");
2033
2034    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
2035    OMX_PRINT2(pComponentPrivate->dbg, ":: pComponentPrivate = %p\n",pComponentPrivate);
2036    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
2037        buff = (OMX_U8 *)pComponentPrivate->pInputBufferList->pBufHdr[i];
2038        if (buff == (OMX_U8 *)pBuffer) {
2039            OMX_PRINT2(pComponentPrivate->dbg, "Found matching input buffer\n");
2040            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
2041            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2042            inputIndex = i;
2043            break;
2044        }
2045    }
2046
2047    for (i=0; i < MP3D_MAX_NUM_OF_BUFS; i++) {
2048        buff = (OMX_U8 *)pComponentPrivate->pOutputBufferList->pBufHdr[i];
2049        if (buff == (OMX_U8 *)pBuffer) {
2050            OMX_PRINT2(pComponentPrivate->dbg, "Found matching output buffer\n");
2051            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff);
2052            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
2053            outputIndex = i;
2054            break;
2055        }
2056    }
2057
2058    if (inputIndex != -1) {
2059        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
2060            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
2061        }
2062#ifdef __PERF_INSTRUMENTATION__
2063        PERF_SendingBuffer(pComponentPrivate->pPERF,
2064                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,
2065                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
2066                           PERF_ModuleMemory);
2067#endif
2068        OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: %p IP Buf Header\n\n",
2069                        pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
2070
2071        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
2072        pComponentPrivate->pInputBufferList->pBufHdr[inputIndex] = NULL;
2073        pComponentPrivate->pInputBufferList->numBuffers--;
2074
2075        if (pComponentPrivate->pInputBufferList->numBuffers <
2076            pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nBufferCountMin) {
2077            pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated = OMX_FALSE;
2078        }
2079
2080#ifndef UNDER_CE
2081        if(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled &&
2082           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
2083           !pComponentPrivate->reconfigInputPort &&
2084           (pComponentPrivate->curState == OMX_StateIdle ||
2085            pComponentPrivate->curState == OMX_StateExecuting ||
2086            pComponentPrivate->curState == OMX_StatePause)) {
2087
2088            pComponentPrivate->cbInfo.EventHandler(pHandle,
2089                                                   pHandle->pApplicationPrivate,
2090                                                   OMX_EventError,
2091                                                   OMX_ErrorPortUnpopulated,
2092                                                   nPortIndex,
2093                                                   NULL);
2094        }
2095
2096#else
2097        if(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled &&
2098           pComponentPrivate->bLoadedCommandPending == OMX_TRUE &&
2099           (pComponentPrivate->curState == OMX_StateIdle ||
2100            pComponentPrivate->curState == OMX_StateExecuting ||
2101            pComponentPrivate->curState == OMX_StatePause)) {
2102
2103            pComponentPrivate->cbInfo.EventHandler(pHandle,
2104                                                   pHandle->pApplicationPrivate,
2105                                                   OMX_EventError,
2106                                                   OMX_ErrorPortUnpopulated,
2107                                                   nPortIndex,
2108                                                   NULL);
2109        }
2110#endif
2111    } else if (outputIndex != -1) {
2112        if (pComponentPrivate->pOutputBufferList->bBufferPending[outputIndex]) {
2113            pComponentPrivate->numPendingBuffers++;
2114        }
2115
2116        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
2117            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
2118        }
2119#ifdef __PERF_INSTRUMENTATION__
2120        PERF_SendingBuffer(pComponentPrivate->pPERF,
2121                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,
2122                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen,
2123                           PERF_ModuleMemory);
2124#endif
2125        OMX_PRBUFFER2(pComponentPrivate->dbg, " Freeing: %p OP Buf Header\n\n",
2126                        pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
2127        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
2128        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
2129        pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
2130        pComponentPrivate->pOutputBufferList->numBuffers--;
2131
2132        if (pComponentPrivate->pOutputBufferList->numBuffers <
2133            pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nBufferCountMin) {
2134            pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated = OMX_FALSE;
2135        }
2136#ifndef UNDER_CE
2137        if(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled &&
2138           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
2139           !pComponentPrivate->reconfigOutputPort &&
2140           (pComponentPrivate->curState == OMX_StateIdle ||
2141            pComponentPrivate->curState == OMX_StateExecuting ||
2142            pComponentPrivate->curState == OMX_StatePause)) {
2143
2144            pComponentPrivate->cbInfo.EventHandler(pHandle,
2145                                                   pHandle->pApplicationPrivate,
2146                                                   OMX_EventError,
2147                                                   OMX_ErrorPortUnpopulated,
2148                                                   nPortIndex,
2149                                                   NULL);
2150        }
2151#else
2152        if(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled &&
2153           pComponentPrivate->bLoadedCommandPending == OMX_TRUE &&
2154           (pComponentPrivate->curState == OMX_StateIdle ||
2155            pComponentPrivate->curState == OMX_StateExecuting ||
2156            pComponentPrivate->curState == OMX_StatePause)) {
2157            pComponentPrivate->cbInfo.EventHandler(pHandle,
2158                                                   pHandle->pApplicationPrivate,
2159                                                   OMX_EventError,
2160                                                   OMX_ErrorPortUnpopulated,
2161                                                   nPortIndex,
2162                                                   NULL);
2163        }
2164#endif
2165    } else {
2166        OMX_ERROR4(pComponentPrivate->dbg, ":Returning OMX_ErrorBadParameter\n");
2167        eError = OMX_ErrorBadParameter;
2168    }
2169
2170    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
2171         !pComponentPrivate->pOutputBufferList->numBuffers) &&
2172        pComponentPrivate->InIdle_goingtoloaded){
2173        pComponentPrivate->InIdle_goingtoloaded = 0;
2174
2175        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
2176        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
2177        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
2178
2179    }
2180
2181///
2182   if ((pComponentPrivate->bDisableCommandPending) &&
2183         (pComponentPrivate->pInputBufferList->numBuffers == 0))
2184    {
2185        OMX_PRCOMM2(pComponentPrivate->dbg, "calling command completed for input port disable\n");
2186        pComponentPrivate->bDisableCommandPending = 0;
2187        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2188                                                pComponentPrivate->pHandle->pApplicationPrivate,
2189                                                        OMX_EventCmdComplete,
2190                                                        OMX_CommandPortDisable,
2191                                                        INPUT_PORT_MP3DEC,
2192                                                        NULL);
2193    }
2194
2195
2196  if ((pComponentPrivate->bDisableCommandPending) &&
2197         (pComponentPrivate->pOutputBufferList->numBuffers == 0))
2198    {
2199        OMX_PRCOMM2(pComponentPrivate->dbg, "calling command completed for output port disable\n");
2200        pComponentPrivate->bDisableCommandPending = 0;
2201        pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2202                                                pComponentPrivate->pHandle->pApplicationPrivate,
2203                                                OMX_EventCmdComplete,
2204                                                OMX_CommandPortDisable,
2205                                                OUTPUT_PORT_MP3DEC,
2206                                                NULL);
2207    }
2208
2209
2210
2211    pComponentPrivate->bufAlloced = 0;
2212    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting FreeBuffer\n");
2213    return eError;
2214}
2215
2216
2217/* ================================================================================= * */
2218/**
2219* @fn UseBuffer() This function is called by application when app allocated the
2220* memory for the buffer and sends it to application for use of component.
2221*
2222* @param hComponent  Handle of this component.
2223*
2224* @param ppBufferHdr  Double pointer to the buffer header.
2225*
2226* @param nPortIndex  Input port or Output port
2227*
2228* @param pAppPrivate Application private data.
2229*
2230* @param nSizeBytes Size of the buffer that is to be allocated.
2231*
2232* @param pBuffer    Pointer to data buffer which was allocated by the
2233* application.
2234*
2235* @pre          None
2236*
2237* @post        None
2238*
2239* @return      OMX_ErrorNone = On Success
2240*              OMX_ErrorBadPortIndex = Bad port index from app
2241*/
2242/* ================================================================================ * */
2243static OMX_ERRORTYPE UseBuffer (
2244            OMX_IN OMX_HANDLETYPE hComponent,
2245            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
2246            OMX_IN OMX_U32 nPortIndex,
2247            OMX_IN OMX_PTR pAppPrivate,
2248            OMX_IN OMX_U32 nSizeBytes,
2249            OMX_IN OMX_U8* pBuffer)
2250{
2251    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
2252    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
2253    OMX_ERRORTYPE eError = OMX_ErrorNone;
2254    OMX_BUFFERHEADERTYPE *pBufferHeader;
2255
2256    OMXDBG_PRINT(stderr, PRINT, 1, 0, ":: Entering UseBuffer\n");
2257
2258    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2259
2260#ifdef _ERROR_PROPAGATION__
2261    if (pComponentPrivate->curState == OMX_StateInvalid){
2262        eError = OMX_ErrorInvalidState;
2263        goto EXIT;
2264    }
2265#endif
2266#ifdef __PERF_INSTRUMENTATION__
2267    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
2268                        pBuffer, nSizeBytes,
2269                        PERF_ModuleHLMM);
2270#endif
2271
2272    pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)
2273                pComponentPrivate)->pPortDef[nPortIndex];
2274
2275    MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1);
2276    if(!pPortDef->bEnabled){
2277        pComponentPrivate->AlloBuf_waitingsignal = 1;
2278        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
2279        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
2280        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
2281    }
2282    OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef = %p\n",pPortDef);
2283    OMX_PRCOMM2(pComponentPrivate->dbg, ":: pPortDef->bEnabled = %d\n",pPortDef->bEnabled);
2284
2285    if(!pPortDef->bEnabled) {
2286        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
2287                            "Port is Disabled: OMX_ErrorIncorrectStateOperation");
2288    }
2289#ifndef UNDER_CE
2290    if(pPortDef->bPopulated) {
2291        MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,
2292                            "Bad Size or Port Disabled : OMX_ErrorBadParameter");
2293    }
2294#endif
2295
2296    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
2297    memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
2298
2299    if (nPortIndex == MP3D_OUTPUT_PORT) {
2300        pBufferHeader->nInputPortIndex = -1;
2301        pBufferHeader->nOutputPortIndex = nPortIndex;
2302        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
2303        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
2304        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
2305        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
2306        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2307            pPortDef->bPopulated = OMX_TRUE;
2308        }
2309    }
2310    else {
2311        pBufferHeader->nInputPortIndex = nPortIndex;
2312        pBufferHeader->nOutputPortIndex = -1;
2313        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
2314        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
2315        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
2316        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2317            pPortDef->bPopulated = OMX_TRUE;
2318        }
2319    }
2320
2321    if((pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled)&&
2322       (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) &&
2323       (pComponentPrivate->InLoaded_readytoidle))
2324        {
2325            pComponentPrivate->InLoaded_readytoidle = 0;
2326#ifndef UNDER_CE
2327            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2328            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2329            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2330#else
2331            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2332#endif
2333
2334        }
2335
2336    pBufferHeader->pAppPrivate = pAppPrivate;
2337    pBufferHeader->pPlatformPrivate = pComponentPrivate;
2338    pBufferHeader->nAllocLen = nSizeBytes;
2339    pBufferHeader->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER;
2340    pBufferHeader->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER;
2341    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2342    pBufferHeader->pBuffer = pBuffer;
2343    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2344    *ppBufferHdr = pBufferHeader;
2345    pComponentPrivate->bufAlloced = 1;
2346
2347    if (pComponentPrivate->bEnableCommandPending){
2348        SendCommand (pComponentPrivate->pHandle,
2349                     OMX_CommandPortEnable,
2350                     pComponentPrivate->bEnableCommandParam,NULL);
2351    }
2352
2353    OMX_PRINT1(pComponentPrivate->dbg, "pBufferHeader = %p\n",pBufferHeader);
2354 EXIT:
2355    return eError;
2356}
2357
2358/* ================================================================================= */
2359/**
2360* @fn GetExtensionIndex() description for GetExtensionIndex
2361GetExtensionIndex().
2362Returns index for vendor specific settings.
2363*
2364*  @see         OMX_Core.h
2365*/
2366/* ================================================================================ */
2367static OMX_ERRORTYPE GetExtensionIndex(
2368            OMX_IN  OMX_HANDLETYPE hComponent,
2369            OMX_IN  OMX_STRING cParameterName,
2370            OMX_OUT OMX_INDEXTYPE *pIndexType)
2371{
2372    OMX_ERRORTYPE eError = OMX_ErrorNone;
2373
2374    if(!(strcmp(cParameterName,"OMX.TI.index.config.mp3headerinfo"))) {
2375        *pIndexType = OMX_IndexCustomMp3DecHeaderInfoConfig;
2376    }
2377    else if (!(strcmp(cParameterName,"OMX.TI.index.config.mp3streamIDinfo"))) {
2378        *pIndexType = OMX_IndexCustomMp3DecStreamInfoConfig;
2379    }
2380    else if(!(strcmp(cParameterName,"OMX.TI.index.config.mp3.datapath"))){
2381        *pIndexType = OMX_IndexCustomMp3DecDataPath;
2382    }
2383    else if(!(strcmp(cParameterName,"OMX.TI.MP3.Decode.Debug"))){
2384        *pIndexType = OMX_IndexCustomDebug;
2385    }
2386    else {
2387        eError = OMX_ErrorBadParameter;
2388    }
2389    return eError;
2390}
2391
2392/* ================================================================================= */
2393/**
2394* @fn ComponentRoleEnum() description for ComponentRoleEnum()
2395
2396Returns the role at the given index
2397*
2398*  @see         OMX_Core.h
2399*/
2400/* ================================================================================ */
2401static OMX_ERRORTYPE ComponentRoleEnum(
2402         OMX_IN OMX_HANDLETYPE hComponent,
2403      OMX_OUT OMX_U8 *cRole,
2404         OMX_IN OMX_U32 nIndex)
2405{
2406    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
2407
2408    OMX_ERRORTYPE eError = OMX_ErrorNone;
2409    pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2410    if (cRole == NULL){
2411        eError = OMX_ErrorBadParameter;
2412    }
2413    else if(nIndex == 0){
2414        memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
2415        OMX_PRINT1(pComponentPrivate->dbg, "[ComponenetRoleEnum] cRole = %s\n",cRole);
2416    }
2417    else {
2418        eError = OMX_ErrorNoMore;
2419    }
2420
2421    return eError;
2422}
2423
2424#ifdef UNDER_CE
2425/* ================================================================================= */
2426/**
2427* @fns Sleep replace for WIN CE
2428*/
2429/* ================================================================================ */
2430int OMX_CreateEvent(OMX_Event *event){
2431    int ret = OMX_ErrorNone;
2432    HANDLE createdEvent = NULL;
2433    if(event == NULL){
2434        ret = OMX_ErrorBadParameter;
2435        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2436        goto EXIT;
2437    }
2438    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2439    if(event->event == NULL)
2440        ret = (int)GetLastError();
2441 EXIT:
2442    return ret;
2443}
2444
2445int OMX_SignalEvent(OMX_Event *event){
2446     int ret = OMX_ErrorNone;
2447     if(event == NULL){
2448        ret = OMX_ErrorBadParameter;
2449        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2450        goto EXIT;
2451     }
2452     SetEvent(event->event);
2453     ret = (int)GetLastError();
2454EXIT:
2455    return ret;
2456}
2457
2458int OMX_WaitForEvent(OMX_Event *event) {
2459     int ret = OMX_ErrorNone;
2460     if(event == NULL){
2461        ret = OMX_ErrorBadParameter;
2462        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2463        goto EXIT;
2464     }
2465     WaitForSingleObject(event->event, INFINITE);
2466     ret = (int)GetLastError();
2467EXIT:
2468     return ret;
2469}
2470
2471int OMX_DestroyEvent(OMX_Event *event) {
2472     int ret = OMX_ErrorNone;
2473     if(event == NULL){
2474        ret = OMX_ErrorBadParameter;
2475        OMXDBG_PRINT(stderr, ERROR, 4, 0, "OMX_CreateEvent: OMX_ErrorBadParameter\n");
2476        goto EXIT;
2477     }
2478     CloseHandle(event->event);
2479EXIT:
2480     return ret;
2481}
2482#endif
2483
2484