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