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