OMX_AacEncoder.c revision 44577d1f0e8d8ea13fe130fc8987035428ee021c
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        if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
1432            return OMX_ErrorUndefined;
1433        }
1434        nPendingStateChangeRequests = pComponentPrivate->nPendingStateChangeRequests;
1435        if(!nPendingStateChangeRequests) {
1436           if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
1437               return OMX_ErrorUndefined;
1438           }
1439
1440           /* No pending state transitions */
1441          *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState;
1442            eError = OMX_ErrorNone;
1443        }
1444        else {
1445                  /* Wait for component to complete state transition */
1446           clock_gettime(CLOCK_REALTIME, &abs_time);
1447           abs_time.tv_sec += mutex_timeout;
1448           abs_time.tv_nsec = 0;
1449          ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
1450           if (!ret) {
1451              /* Component has completed state transitions*/
1452              *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState;
1453              if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
1454                 return OMX_ErrorUndefined;
1455              }
1456              eError = OMX_ErrorNone;
1457           }
1458           else if(ret == ETIMEDOUT) {
1459              /* Unlock mutex in case of timeout */
1460              pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest);
1461              *pState = OMX_StateInvalid;
1462              return OMX_ErrorNone;
1463           }
1464        }
1465     }
1466     else {
1467        eError = OMX_ErrorInvalidComponent;
1468        *pState = OMX_StateInvalid;
1469     }
1470
1471    return eError;
1472
1473EXIT:
1474    OMX_PRINT1 (pComponentPrivate->dbg, "%d :: AACENC: Exiting GetState\n", __LINE__);
1475    return eError;
1476}
1477
1478/*-------------------------------------------------------------------*/
1479/**
1480  *  EmptyThisBuffer() This callback is used to send the input buffer to
1481  *  component
1482  *
1483  * @param pComponent       handle for this instance of the component
1484  * @param nPortIndex       input port index
1485  * @param pBuffer          buffer to be sent to codec
1486  *
1487  * @retval OMX_NoError              Success, ready to roll
1488  *         OMX_Error_BadParameter   The input parameter pointer is null
1489  **/
1490/*-------------------------------------------------------------------*/
1491
1492static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1493                                      OMX_BUFFERHEADERTYPE* pBuffer)
1494{
1495    OMX_ERRORTYPE eError = OMX_ErrorNone;
1496    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1497    OMX_CONF_CHECK_CMD(pComponent,pBuffer,1);
1498    int ret = 0;
1499    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1500    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1501
1502    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1503    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering EmptyThisBuffer\n", __LINE__);
1504
1505    pPortDef = ((AACENC_COMPONENT_PRIVATE*)
1506                    pComponentPrivate)->pPortDef[INPUT_PORT];
1507
1508#ifdef _ERROR_PROPAGATION__
1509    if (pComponentPrivate->curState == OMX_StateInvalid)
1510    {
1511        eError = OMX_ErrorInvalidState;
1512        goto EXIT;
1513    }
1514#endif
1515
1516#ifdef __PERF_INSTRUMENTATION__
1517        PERF_ReceivedFrame(pComponentPrivate->pPERF,pBuffer->pBuffer, pBuffer->nFilledLen,
1518                           PERF_ModuleHLMM);
1519#endif
1520
1521    OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pBuffer->nSize %d \n",(int)pBuffer->nSize);
1522    OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: size OMX_BUFFERHEADERTYPE %d \n",sizeof(OMX_BUFFERHEADERTYPE));
1523
1524    if(!pPortDef->bEnabled)
1525    {
1526        eError = OMX_ErrorIncorrectStateOperation;
1527        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__);
1528        goto EXIT;
1529    }
1530    if (pBuffer == NULL)
1531    {
1532        eError = OMX_ErrorBadParameter;
1533        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__);
1534        goto EXIT;
1535    }
1536    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE))
1537    {
1538        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__);
1539        eError = OMX_ErrorBadParameter;
1540        goto EXIT;
1541    }
1542
1543
1544    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion)
1545    {
1546        eError = OMX_ErrorVersionMismatch;
1547        goto EXIT;
1548    }
1549
1550    if (pBuffer->nInputPortIndex != INPUT_PORT)
1551    {
1552        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadPortIndex\n",__LINE__);
1553        eError  = OMX_ErrorBadPortIndex;
1554        goto EXIT;
1555    }
1556    OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1557    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Component Sending Filled ip buff %p  to Component Thread\n", __LINE__,pBuffer);
1558    OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1559
1560    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1561    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1562
1563    pComponentPrivate->nUnhandledEmptyThisBuffers++;
1564
1565    ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof(OMX_BUFFERHEADERTYPE*));
1566    if (ret == -1)
1567    {
1568        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__);
1569        eError = OMX_ErrorHardware;
1570        goto EXIT;
1571    } else{
1572        AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->EmptythisbufferCount);
1573    }
1574EXIT:
1575    if (pComponentPrivate != NULL) {
1576	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting EmptyThisBuffer\n", __LINE__);
1577    }
1578    return eError;
1579}
1580/*-------------------------------------------------------------------*/
1581/**
1582  *  FillThisBuffer() This callback is used to send the output buffer to
1583  *  the component
1584  *
1585  * @param pComponent    handle for this instance of the component
1586  * @param nPortIndex    output port number
1587  * @param pBuffer       buffer to be sent to codec
1588  *
1589  * @retval OMX_NoError              Success, ready to roll
1590  *         OMX_Error_BadParameter   The input parameter pointer is null
1591  **/
1592/*-------------------------------------------------------------------*/
1593
1594static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1595                                     OMX_BUFFERHEADERTYPE* pBuffer)
1596{
1597    OMX_ERRORTYPE eError = OMX_ErrorNone;
1598    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1599    OMX_CONF_CHECK_CMD(pComponent,pBuffer,1);
1600    int ret = 0;
1601    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1602    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1603
1604    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1605    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering FillThisBuffer\n", __LINE__);
1606
1607    OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1608    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Component Sending Emptied op buff %p to Component Thread\n",__LINE__,pBuffer);
1609    OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
1610    pPortDef = ((AACENC_COMPONENT_PRIVATE*)
1611                    pComponentPrivate)->pPortDef[OUTPUT_PORT];
1612
1613#ifdef _ERROR_PROPAGATION__
1614    if (pComponentPrivate->curState == OMX_StateInvalid)
1615    {
1616        eError = OMX_ErrorInvalidState;
1617        goto EXIT;
1618    }
1619#endif
1620
1621#ifdef __PERF_INSTRUMENTATION__
1622    PERF_ReceivedFrame(pComponentPrivate->pPERF,pBuffer->pBuffer,0,PERF_ModuleHLMM);
1623#endif
1624
1625    if(!pPortDef->bEnabled)
1626    {
1627        eError = OMX_ErrorIncorrectStateOperation;
1628        goto EXIT;
1629    }
1630    if (pBuffer == NULL)
1631    {
1632        eError = OMX_ErrorBadParameter;
1633        OMX_ERROR4(pComponentPrivate->dbg, " %d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__);
1634        goto EXIT;
1635    }
1636    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE))
1637    {
1638        eError = OMX_ErrorBadParameter;
1639        goto EXIT;
1640    }
1641
1642    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion)
1643    {
1644        eError = OMX_ErrorVersionMismatch;
1645        goto EXIT;
1646    }
1647
1648    if (pBuffer->nOutputPortIndex != OUTPUT_PORT)
1649    {
1650        eError  = OMX_ErrorBadPortIndex;
1651        goto EXIT;
1652    }
1653    pBuffer->nFilledLen = 0;
1654    /*Filling the Output buffer with zero */
1655#ifndef UNDER_CE
1656    /*memset(pBuffer->pBuffer, 0, pBuffer->nAllocLen);*/
1657#endif
1658
1659    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pMarkBuf = %p\n",__LINE__, pComponentPrivate->pMarkBuf);
1660    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pMarkData = %p\n",__LINE__, pComponentPrivate->pMarkData);
1661    if(pComponentPrivate->pMarkBuf)
1662    {
1663        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1664        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1665        pComponentPrivate->pMarkBuf = NULL;
1666    }
1667
1668    if (pComponentPrivate->pMarkData)
1669    {
1670        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1671        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1672        pComponentPrivate->pMarkData = NULL;
1673    }
1674
1675    pComponentPrivate->nUnhandledFillThisBuffers++;
1676
1677    ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof (OMX_BUFFERHEADERTYPE*));
1678    if (ret == -1)
1679    {
1680        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__);
1681        eError = OMX_ErrorHardware;
1682        goto EXIT;
1683    } else {
1684        AACENC_IncrementBufferCounterByOne(&bufferReturned_mutex, &pComponentPrivate->FillthisbufferCount);
1685    }
1686EXIT:
1687    if (pComponentPrivate != NULL) {
1688	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FillThisBuffer error= %d \n", __LINE__, eError);
1689    }
1690    return eError;
1691}
1692/*-------------------------------------------------------------------*/
1693/**
1694  * OMX_ComponentDeinit() this methold will de init the component
1695  *
1696  * @param pComp         handle for this instance of the component
1697  *
1698  * @retval OMX_NoError              Success, ready to roll
1699  *         OMX_Error_BadParameter   The input parameter pointer is null
1700  **/
1701/*-------------------------------------------------------------------*/
1702
1703static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1704{
1705    OMX_ERRORTYPE eError = OMX_ErrorNone;
1706    struct OMX_TI_Debug dbg = {0};
1707    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1708    OMX_CONF_CHECK_CMD(pHandle,1,1);
1709    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1710    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1711    dbg = pComponentPrivate->dbg;
1712
1713    OMX_PRINT1(dbg, "%d :: AACENC: ComponentDeInit\n",__LINE__);
1714    OMX_PRDSP2(dbg, "AACENC:  LCML %p \n",pComponentPrivate->ptrLibLCML);
1715
1716#ifdef __PERF_INSTRUMENTATION__
1717    PERF_Boundary(pComponentPrivate->pPERF,PERF_BoundaryStart | PERF_BoundaryCleanup);
1718#endif
1719
1720#ifndef UNDER_CE
1721#ifdef DSP_RENDERING_ON
1722    close(Aacenc_fdwrite);
1723    close(Aacenc_fdread);
1724#endif
1725#endif
1726
1727#ifdef RESOURCE_MANAGER_ENABLED
1728    eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_AAC_Encoder_COMPONENT, 0, 3456, NULL);
1729    if (eError != OMX_ErrorNone)
1730    {
1731         OMX_ERROR4(dbg, "%d :: Error returned from destroy ResourceManagerProxy thread\n",
1732                                                        __LINE__);
1733    }
1734
1735    eError = RMProxy_Deinitalize();
1736    if (eError != OMX_ErrorNone)
1737    {
1738         OMX_ERROR4(dbg, "%d :: Error returned from destroy ResourceManagerProxy thread\n",__LINE__);
1739    }
1740#endif
1741
1742#ifdef SWAT_ANALYSIS
1743    SWATAPI_ReleaseHandle(pComponentPrivate->pSwatInfo->pSwatApiHandle);
1744    SWAT_Boundary(pComponentPrivate->pSwatInfo->pSwatObjHandle,
1745                          pComponentPrivate->pSwatInfo->ctUC,
1746                          SWAT_BoundaryComplete | SWAT_BoundaryCleanup);
1747    OMX_PRINT2(dbg, "%d :: AACENC: Instrumentation: SWAT_BoundaryComplete Done\n",__LINE__);
1748    SWAT_Done(pComponentPrivate->pSwatInfo->pSwatObjHandle);
1749#endif
1750
1751    OMX_PRINT2(dbg, "%d :: AACENC: Inside ComponentDeInit point A \n",__LINE__);
1752    pComponentPrivate->bIsThreadstop = 1;
1753    eError = AACENC_StopComponentThread(pHandle);
1754    OMX_PRINT2(dbg, "%d :: AACENC: Inside ComponentDeInit Point B \n",__LINE__);
1755    /* Wait for thread to exit so we can get the status into "error" */
1756
1757    /* close the pipe handles */
1758    AACENC_FreeCompResources(pHandle);
1759
1760#ifdef __PERF_INSTRUMENTATION__
1761        PERF_Boundary(pComponentPrivate->pPERF,
1762                      PERF_BoundaryComplete | PERF_BoundaryCleanup);
1763        PERF_Done(pComponentPrivate->pPERF);
1764#endif
1765
1766    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
1767    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
1768    OMX_PRBUFFER2(dbg, "%d :: AACENC: After AACENC_FreeCompResources\n",__LINE__);
1769    OMX_PRBUFFER2(dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate);
1770
1771    pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
1772    pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
1773
1774    if (pComponentPrivate->sDeviceString != NULL)
1775    {
1776        OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1777    }
1778
1779    /* CLose LCML .      - Note:  Need to handle better - */
1780    if ((pComponentPrivate->ptrLibLCML != NULL && pComponentPrivate->bGotLCML) &&
1781        (pComponentPrivate->bCodecDestroyed))
1782    {
1783        OMX_PRDSP2(dbg, "AACENC: About to Close LCML %p \n",pComponentPrivate->ptrLibLCML);
1784        dlclose( pComponentPrivate->ptrLibLCML  );
1785        pComponentPrivate->ptrLibLCML = NULL;
1786        OMX_PRDSP2(dbg, "AACENC: Closed LCML \n");
1787
1788        pComponentPrivate->bCodecDestroyed = OMX_FALSE;     /* restoring flags */
1789        pComponentPrivate->bGotLCML        = OMX_FALSE;
1790    }
1791
1792    OMX_MEMFREE_STRUCT(pComponentPrivate);
1793    pComponentPrivate = NULL;
1794
1795EXIT:
1796    OMX_DBG_CLOSE(dbg);
1797    return eError;
1798}
1799
1800/*-------------------------------------------------------------------*/
1801/**
1802  *  ComponentTunnelRequest() this method is not implemented in 1.5
1803  *
1804  * This method will update application callbacks
1805  * the application.
1806  *
1807  * @param pComp         handle for this instance of the component
1808  * @param pCallBacks    application callbacks
1809  * @param ptr
1810  *
1811  * @retval OMX_NoError              Success, ready to roll
1812  *         OMX_Error_BadParameter   The input parameter pointer is null
1813  **/
1814/*-------------------------------------------------------------------*/
1815
1816static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1817                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1818                                             OMX_U32 nTunneledPort,
1819                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1820{
1821    OMX_ERRORTYPE eError = OMX_ErrorNone;
1822    eError = OMX_ErrorNotImplemented;
1823    return eError;
1824}
1825
1826/*-------------------------------------------------------------------*/
1827/**
1828  *  AllocateBuffer()
1829
1830  * @param pComp         handle for this instance of the component
1831  * @param pCallBacks    application callbacks
1832  * @param ptr
1833  *
1834  * @retval OMX_NoError              Success, ready to roll
1835  *         OMX_Error_BadParameter   The input parameter pointer is null
1836  **/
1837/*-------------------------------------------------------------------*/
1838
1839static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1840                   OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1841                   OMX_IN OMX_U32 nPortIndex,
1842                   OMX_IN OMX_PTR pAppPrivate,
1843                   OMX_IN OMX_U32 nSizeBytes)
1844
1845{
1846    OMX_ERRORTYPE eError = OMX_ErrorNone;
1847    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL;
1848    AACENC_COMPONENT_PRIVATE *pComponentPrivate= NULL;
1849
1850    BUFFERLIST *pBufferList = NULL;
1851    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1852    OMX_CONF_CHECK_CMD(hComponent,pBuffer,1);
1853
1854    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
1855            (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1856    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering AllocateBuffer\n", __LINE__);
1857
1858    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
1859    {
1860        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AllocateBuffer: Error - Unknown port index %ld\n",__LINE__, nPortIndex);
1861        return OMX_ErrorBadPortIndex;
1862    }
1863    pPortDef = ((AACENC_COMPONENT_PRIVATE*)
1864                    pComponentPrivate)->pPortDef[nPortIndex];
1865
1866#ifdef _ERROR_PROPAGATION__
1867    if (pComponentPrivate->curState == OMX_StateInvalid)
1868    {
1869        eError = OMX_ErrorInvalidState;
1870        goto EXIT;
1871    }
1872#endif
1873
1874#ifdef __PERF_INSTRUMENTATION__
1875    PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer,nSizeBytes,PERF_ModuleMemory);
1876#endif
1877     if (pPortDef->bPopulated)
1878    {
1879        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AllocateBuffer - Error: port (%ld) already populated\n", __LINE__, nPortIndex);
1880        eError = OMX_ErrorIncorrectStateOperation;
1881        goto EXIT;
1882    }
1883    // FIXME:
1884    // Should we remove the following while loop and just check make sure that
1885    // pPortDef->bEnabled == true, as we do in UseBuffer()?
1886    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef = %p\n", __LINE__, pPortDef);
1887    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->bEnabled = %d\n", __LINE__, pPortDef->bEnabled);
1888    while (1)
1889    {
1890        if(pPortDef->bEnabled)
1891        {
1892            break;
1893        }
1894        pComponentPrivate->AlloBuf_waitingsignal = 1;
1895
1896#ifndef UNDER_CE
1897        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1898        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
1899        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1900#else
1901        OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1902#endif
1903        break;
1904
1905    }
1906    if (nSizeBytes != pPortDef->nBufferSize)
1907    {
1908        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: nSizeBytes(%ld) != nBufferSize(%ld)\n", __LINE__, nSizeBytes, pPortDef->nBufferSize);
1909        eError = OMX_ErrorBadParameter;
1910        goto EXIT;
1911     }
1912
1913    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1914    OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader %p\n",pBufferHeader);
1915
1916    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
1917
1918    OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pbuffer %p to %p \n",pBufferHeader->pBuffer,(pBufferHeader->pBuffer + sizeof(pBufferHeader->pBuffer)) );
1919
1920    if (nPortIndex == INPUT_PORT)
1921    {
1922        pBufferList = pComponentPrivate->pInputBufferList;
1923        pBufferHeader->nInputPortIndex = nPortIndex;
1924        pBufferHeader->nOutputPortIndex = -1;
1925    }
1926    else
1927     {
1928         pBufferList = pComponentPrivate->pOutputBufferList;
1929         pBufferHeader->nInputPortIndex = -1;
1930         pBufferHeader->nOutputPortIndex = nPortIndex;
1931    }
1932    pBufferList->pBufHdr[pBufferList->numBuffers] = pBufferHeader;
1933    pBufferList->bBufferPending[pBufferList->numBuffers] = 0;
1934    pBufferList->bufferOwner[pBufferList->numBuffers++] = 1;
1935    if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
1936    {
1937       pPortDef->bPopulated = OMX_TRUE;
1938    }
1939
1940  if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
1941       (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) &&
1942       (pComponentPrivate->InLoaded_readytoidle))
1943    {
1944        pComponentPrivate->InLoaded_readytoidle = 0;
1945#ifndef UNDER_CE
1946        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1947        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1948        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1949#else
1950        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1951#endif
1952    }
1953
1954    pBufferHeader->pAppPrivate = pAppPrivate;
1955    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1956    pBufferHeader->nAllocLen = nSizeBytes;
1957    pBufferHeader->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
1958    pBufferHeader->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
1959    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1960    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1961    *pBuffer = pBufferHeader;
1962    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
1963    {
1964        SendCommand (pComponentPrivate->pHandle,OMX_CommandPortEnable,pComponentPrivate->nEnableCommandParam,NULL);
1965    }
1966
1967#ifdef __PERF_INSTRUMENTATION__
1968        PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer, nSizeBytes,PERF_ModuleMemory);
1969#endif
1970
1971EXIT:
1972    if (pComponentPrivate != NULL) {
1973	OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC:  AllocateBuffer returning eError =  %d\n", __LINE__, eError);
1974
1975	OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader = %p\n", pBufferHeader);
1976	if (pBufferHeader != NULL) {
1977	    OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pBuffer = %p\n", pBufferHeader->pBuffer);
1978	}
1979    }
1980    return eError;
1981}
1982
1983/*-------------------------------------------------------------------*/
1984/**
1985  *  FreeBuffer()
1986
1987  * @param hComponent   handle for this instance of the component
1988  * @param pCallBacks   application callbacks
1989  * @param ptr
1990  *
1991  * @retval OMX_NoError              Success, ready to roll
1992  *         OMX_Error_BadParameter   The input parameter pointer is null
1993  **/
1994/*-------------------------------------------------------------------*/
1995static OMX_ERRORTYPE FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
1996                                OMX_IN  OMX_U32 nPortIndex,
1997                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1998{
1999    OMX_ERRORTYPE eError = OMX_ErrorNone;
2000    OMX_CONF_CHECK_CMD(hComponent,1,pBuffer);
2001    OMX_BUFFERHEADERTYPE* buffHdr = NULL;
2002    OMX_U8* tempBuff = NULL;
2003    OMX_U32 i = 0;
2004    int bufferIndex = -1;
2005    BUFFERLIST *pBuffList = NULL;
2006    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
2007    AACENC_COMPONENT_PRIVATE *pComponentPrivate = ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
2008
2009    OMX_PRINT1 (pComponentPrivate->dbg, "%d :: AACENC: FreeBuffer for port index %ld\n", __LINE__, nPortIndex);
2010
2011    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
2012    {
2013        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Error - Unknown port index %ld\n",__LINE__, nPortIndex);
2014        return OMX_ErrorBadPortIndex;
2015    }
2016
2017    pBuffList = ((nPortIndex == INPUT_PORT)? pComponentPrivate->pInputBufferList: pComponentPrivate->pOutputBufferList);
2018    pPortDef = pComponentPrivate->pPortDef[nPortIndex];
2019    for (i = 0; i < pPortDef->nBufferCountActual; ++i)
2020
2021    {
2022        buffHdr = pBuffList->pBufHdr[i];
2023        if (buffHdr == pBuffer)
2024        {
2025            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching %s buffer\n",__LINE__, nPortIndex == INPUT_PORT? "input": "output");
2026            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buffHdr = %p\n",__LINE__,buffHdr);
2027            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
2028            bufferIndex = i;
2029            break;
2030        }
2031        else
2032        {
2033            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__);
2034            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buffHdr = %p\n",__LINE__,buffHdr);
2035            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
2036        }
2037    }
2038
2039
2040    if (bufferIndex == -1)
2041    {
2042        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Error - could not find match for buffer %p\n",__LINE__, pBuffer);
2043        return OMX_ErrorBadParameter;
2044    }
2045
2046    if (pBuffList->bufferOwner[bufferIndex] == 1)
2047    {
2048            OMX_MEMFREE_STRUCT_DSPALIGN(buffHdr->pBuffer, OMX_U8);
2049#ifdef __PERF_INSTRUMENTATION__
2050            PERF_SendingBuffer(pComponentPrivate->pPERF,
2051                               pBufHdr->pBuffer,
2052                               pBufHdr->nAllocLen,
2053                               PERF_ModuleMemory);
2054#endif
2055    }
2056    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__, buffHdr);
2057    OMX_MEMFREE_STRUCT(buffHdr);
2058    pBuffList->pBufHdr[bufferIndex] = NULL;
2059    pBuffList->numBuffers--;
2060    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: numBuffers = %d \n",__LINE__, pBuffList->numBuffers);
2061    if (pBuffList->numBuffers < pPortDef->nBufferCountActual)
2062    {
2063        pPortDef->bPopulated = OMX_FALSE;
2064    }
2065
2066    if (pPortDef->bEnabled &&
2067        pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
2068        (pComponentPrivate->curState == OMX_StateIdle ||
2069         pComponentPrivate->curState == OMX_StateExecuting ||
2070         pComponentPrivate->curState == OMX_StatePause))
2071    {
2072       OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__);
2073       pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2074                                              pComponentPrivate->pHandle->pApplicationPrivate,
2075                                              OMX_EventError,
2076                                              OMX_ErrorPortUnpopulated,
2077                                              OMX_TI_ErrorMinor,
2078                                              "Port Unpopulated");
2079    }
2080    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
2081         !pComponentPrivate->pOutputBufferList->numBuffers) &&
2082         pComponentPrivate->InIdle_goingtoloaded)
2083    {
2084        pComponentPrivate->InIdle_goingtoloaded = 0;
2085#ifndef UNDER_CE
2086        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
2087        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
2088        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
2089#else
2090        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
2091#endif
2092    }
2093
2094    if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0))
2095    {
2096        SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL);
2097    }
2098
2099EXIT:
2100    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FreeBuffer\n", __LINE__);
2101    return eError;
2102}
2103
2104/* ================================================================================= */
2105/**
2106* @fn UseBuffer() description for UseBuffer
2107UseBuffer().
2108Called by the OMX IL client to pass a buffer to be used.
2109*
2110*  @see         OMX_Core.h
2111*/
2112/* ================================================================================ */
2113static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
2114            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
2115            OMX_IN OMX_U32 nPortIndex,
2116            OMX_IN OMX_PTR pAppPrivate,
2117            OMX_IN OMX_U32 nSizeBytes,
2118            OMX_IN OMX_U8* pBuffer)
2119{
2120    OMX_ERRORTYPE eError = OMX_ErrorNone;
2121    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL;
2122    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
2123    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
2124    BUFFERLIST *pBufferList = NULL;
2125    OMX_CONF_CHECK_CMD(hComponent,ppBufferHdr,pBuffer);
2126
2127    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering UseBuffer\n", __LINE__);
2128    OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer = %p\n", __LINE__,pBuffer);
2129    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
2130    {
2131        OMX_ERROR4(pComponentPrivate->dbg, "UseBuffer: Error - Unknown port index %ld", nPortIndex);
2132        return OMX_ErrorBadPortIndex;
2133    }
2134
2135    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
2136            (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2137
2138#ifdef _ERROR_PROPAGATION__
2139    if (pComponentPrivate->curState == OMX_StateInvalid)
2140    {
2141        eError = OMX_ErrorInvalidState;
2142        goto EXIT;
2143    }
2144
2145#endif
2146
2147#ifdef __PERF_INSTRUMENTATION__
2148        PERF_ReceivedBuffer(pComponentPrivate->pPERF,pBuffer, nSizeBytes,
2149                            PERF_ModuleHLMM);
2150#endif
2151
2152    pPortDef = ((AACENC_COMPONENT_PRIVATE*)
2153                    pComponentPrivate)->pPortDef[nPortIndex];
2154
2155    if(!pPortDef->bEnabled || pPortDef->bPopulated)
2156    {
2157        if (!pPortDef->bEnabled)
2158        {
2159            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UseBuffer - Error: port (%ld) not enabled\n", __LINE__, nPortIndex);
2160        }
2161        if (pPortDef->bPopulated)
2162        {
2163            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UseBuffer - Error: port (%ld) already populated\n", __LINE__, nPortIndex);
2164        }
2165        eError = OMX_ErrorIncorrectStateOperation;
2166        goto EXIT;
2167    }
2168
2169    OMX_PRINT2(pComponentPrivate->dbg, "AACENC: nSizeBytes = %ld\n",nSizeBytes);
2170    OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->nBufferSize = %ld\n",pPortDef->nBufferSize);
2171    OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->bPopulated = %d\n",pPortDef->bPopulated);
2172    if(nSizeBytes != pPortDef->nBufferSize)
2173    {
2174        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: nSizeBytes(%ld) != nBufferSize(%ld)\n", __LINE__, nSizeBytes, pPortDef->nBufferSize);
2175        eError = OMX_ErrorBadParameter;
2176        goto EXIT;
2177    }
2178
2179    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
2180
2181    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [ALLOC] %p\n",__LINE__,pBufferHeader);
2182
2183    if (nPortIndex == OUTPUT_PORT)
2184    {
2185        pBufferList = pComponentPrivate->pOutputBufferList;
2186        pBufferHeader->nInputPortIndex = -1;
2187        pBufferHeader->nOutputPortIndex = nPortIndex;
2188    } else {
2189        pBufferList = pComponentPrivate->pInputBufferList;
2190        pBufferHeader->nInputPortIndex = nPortIndex;
2191        pBufferHeader->nOutputPortIndex = -1;
2192    }
2193    pBufferList->pBufHdr[pBufferList->numBuffers] = pBufferHeader;
2194    pBufferList->bBufferPending[pBufferList->numBuffers] = 0;
2195    pBufferList->bufferOwner[pBufferList->numBuffers++] = 0;
2196    if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
2197    {
2198         pPortDef->bPopulated = OMX_TRUE;
2199    }
2200
2201    if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
2202       (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) &&
2203       (pComponentPrivate->InLoaded_readytoidle))
2204    {
2205       pComponentPrivate->InLoaded_readytoidle = 0;
2206#ifndef UNDER_CE
2207       pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2208       pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2209       pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2210#else
2211       OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2212#endif
2213    }
2214
2215    pBufferHeader->pAppPrivate = pAppPrivate;
2216    pBufferHeader->pPlatformPrivate = pComponentPrivate;
2217    pBufferHeader->nAllocLen = nSizeBytes;
2218    pBufferHeader->nVersion.s.nVersionMajor = AACENC_MAJOR_VER;
2219    pBufferHeader->nVersion.s.nVersionMinor = AACENC_MINOR_VER;
2220    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2221    pBufferHeader->pBuffer = pBuffer;
2222    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2223    *ppBufferHdr = pBufferHeader;
2224    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBufferHeader = %p\n",__LINE__,pBufferHeader);
2225
2226    if (pComponentPrivate->bEnableCommandPending)
2227    {
2228        SendCommand (pComponentPrivate->pHandle,OMX_CommandPortEnable,pComponentPrivate->nEnableCommandParam,NULL);
2229    }
2230
2231EXIT:
2232    if (pComponentPrivate != NULL) {
2233	OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader = %p\n", pBufferHeader);
2234	if (pBufferHeader != NULL) {
2235	    OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader->pBuffer = %p\n", pBufferHeader->pBuffer);
2236	}
2237    }
2238
2239    return eError;
2240}
2241
2242/* ================================================================================= */
2243/**
2244* @fn GetExtensionIndex() description for GetExtensionIndex
2245GetExtensionIndex().
2246Returns index for vendor specific settings.
2247*
2248*  @see         OMX_Core.h
2249*/
2250/* ================================================================================ */
2251static OMX_ERRORTYPE GetExtensionIndex(
2252            OMX_IN  OMX_HANDLETYPE hComponent,
2253            OMX_IN  OMX_STRING cParameterName,
2254            OMX_OUT OMX_INDEXTYPE* pIndexType)
2255{
2256    OMX_ERRORTYPE eError = OMX_ErrorNone;
2257
2258    OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: GetExtensionIndex\n");
2259    if (!(strcmp(cParameterName,"OMX.TI.index.config.aacencHeaderInfo")))
2260    {
2261        *pIndexType = OMX_IndexCustomAacEncHeaderInfoConfig;
2262    }
2263    else if(!(strcmp(cParameterName,"OMX.TI.index.config.aacencstreamIDinfo")))
2264    {
2265        *pIndexType = OMX_IndexCustomAacEncStreamIDConfig;
2266    }
2267    else if(!(strcmp(cParameterName,"OMX.TI.index.config.aac.datapath")))
2268    {
2269        *pIndexType = OMX_IndexCustomAacEncDataPath;
2270    }
2271    else if (!(strcmp(cParameterName,"OMX.TI.index.config.aacencframesPerOutBuf")))
2272    {
2273        *pIndexType =OMX_IndexCustomAacEncFramesPerOutBuf;
2274    }
2275    else if (!(strcmp(cParameterName,"OMX.TI.AAC.Encode.Debug")))
2276    {
2277        *pIndexType =OMX_IndexCustomDebug;
2278    }
2279    else
2280    {
2281        eError = OMX_ErrorBadParameter;
2282    }
2283
2284    return eError;
2285}
2286
2287/* ================================================================================= */
2288/**
2289* @fn ComponentRoleEnum() description for ComponentRoleEnum()
2290
2291Returns the role at the given index
2292*
2293*  @see         OMX_Core.h
2294*/
2295/* ================================================================================ */
2296static OMX_ERRORTYPE ComponentRoleEnum(
2297      OMX_IN OMX_HANDLETYPE hComponent,
2298      OMX_OUT OMX_U8 *cRole,
2299      OMX_IN OMX_U32 nIndex)
2300{
2301    OMX_ERRORTYPE eError = OMX_ErrorNone;
2302    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
2303    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2304    if(nIndex == 0)
2305    {
2306      OMX_CONF_CHECK_CMD(cRole, 1, 1);
2307      memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
2308    }
2309    else
2310    {
2311      eError = OMX_ErrorNoMore;
2312      goto EXIT;
2313    }
2314
2315EXIT:
2316    return eError;
2317};
2318
2319#ifdef UNDER_CE
2320/* ================================================================================= */
2321/**
2322* @fns Sleep replace for WIN CE
2323*/
2324/* ================================================================================ */
2325int OMX_CreateEvent(OMX_Event *event){
2326    int ret = OMX_ErrorNone;
2327    HANDLE createdEvent = NULL;
2328    if(event == NULL){
2329        ret = OMX_ErrorBadParameter;
2330        goto EXIT;
2331    }
2332    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2333    if(event->event == NULL)
2334        ret = (int)GetLastError();
2335EXIT:
2336    return ret;
2337}
2338
2339int OMX_SignalEvent(OMX_Event *event){
2340     int ret = OMX_ErrorNone;
2341     if(event == NULL){
2342        ret = OMX_ErrorBadParameter;
2343        goto EXIT;
2344     }
2345     SetEvent(event->event);
2346     ret = (int)GetLastError();
2347EXIT:
2348    return ret;
2349}
2350
2351int OMX_WaitForEvent(OMX_Event *event) {
2352     int ret = OMX_ErrorNone;
2353     if(event == NULL){
2354        ret = OMX_ErrorBadParameter;
2355        goto EXIT;
2356     }
2357     WaitForSingleObject(event->event, INFINITE);
2358     ret = (int)GetLastError();
2359EXIT:
2360     return ret;
2361}
2362
2363int OMX_DestroyEvent(OMX_Event *event) {
2364     int ret = OMX_ErrorNone;
2365     if(event == NULL){
2366        ret = OMX_ErrorBadParameter;
2367        goto EXIT;
2368     }
2369     CloseHandle(event->event);
2370EXIT:
2371     return ret;
2372}
2373#endif
2374