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