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