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