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_G729Encoder.c
30 *
31 * This file implements OpenMAX (TM) 1.0 Specific APIs and its functionality
32 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
33 *
34 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g729_enc\src
35 *
36 * @rev  1.0
37 */
38/* ----------------------------------------------------------------------------
39 *!
40 *! Revision History
41 *! ===================================
42 *! 21-sept-2006 bk: updated review findings for alpha release
43 *! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more
44 *! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases
45 *! 21-Jun-2006 bk: Khronos OpenMAX (TM) 1.0 migration done
46 *! 22-May-2006 bk: DASF recording quality improved
47 *! 19-Apr-2006 bk: DASF recording speed issue resloved
48 *! 23-Feb-2006 bk: DASF functionality added
49 *! 18-Jan-2006 bk: Repated recording issue fixed and LCML changes taken care
50 *! 14-Dec-2005 bk: Initial Version
51 *! 16-Nov-2005 bk: Initial Version
52 *! 23-Sept-2005 bk: Initial Version
53 *! 10-Sept-2005 bk: Initial Version
54 *! 10-Sept-2005 bk:
55 *! This is newest file
56 * =========================================================================== */
57/* ------compilation control switches -------------------------*/
58/****************************************************************
59 *  INCLUDE FILES
60 ****************************************************************/
61/* ----- system and platform files ----------------------------*/
62#ifdef UNDER_CE
63#include <windows.h>
64#include <oaf_osal.h>
65#include <omx_core.h>
66#else
67#include <unistd.h>
68#include <sys/time.h>
69#include <sys/types.h>
70#include <sys/ioctl.h>
71#include <sys/select.h>
72#include <errno.h>
73#include <pthread.h>
74#include <stdarg.h>
75#endif
76
77#include <string.h>
78#include <fcntl.h>
79#include <stdlib.h>
80#include <stdio.h>
81#include <dbapi.h>
82
83#ifdef __PERF_INSTRUMENTATION__
84#include "perf.h"
85#endif
86/*-------program files ----------------------------------------*/
87#include <OMX_Component.h>
88
89#include "OMX_G729Enc_Utils.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,
113                                   OMX_CALLBACKTYPE* pCallBacks,
114                                   OMX_PTR pAppData);
115static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
116                                          OMX_STRING pComponentName,
117                                          OMX_VERSIONTYPE* pComponentVersion,
118                                          OMX_VERSIONTYPE* pSpecVersion,
119                                          OMX_UUIDTYPE* pComponentUUID);
120static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp,
121                                  OMX_COMMANDTYPE nCommand,
122                                  OMX_U32 nParam,OMX_PTR pCmdData);
123static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp,
124                                  OMX_INDEXTYPE nParamIndex,
125                                  OMX_PTR ComponentParamStruct);
126static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
127                                   OMX_INDEXTYPE nParamIndex,
128                                   OMX_PTR ComponentParamStruct);
129static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
130                                OMX_INDEXTYPE nConfigIndex,
131                                OMX_PTR pComponentConfigStructure);
132static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
133                                OMX_INDEXTYPE nConfigIndex,
134                                OMX_PTR pComponentConfigStructure);
135static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp,
136                                      OMX_BUFFERHEADERTYPE* pBuffer);
137static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp,
138                                     OMX_BUFFERHEADERTYPE* pBuffer);
139static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
140static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
141                                             OMX_U32 nPort,
142                                             OMX_HANDLETYPE hTunneledComp,
143                                             OMX_U32 nTunneledPort,
144                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
145static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
146static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
147                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
148                                     OMX_IN OMX_U32 nPortIndex,
149                                     OMX_IN OMX_PTR pAppPrivate,
150                                     OMX_IN OMX_U32 nSizeBytes);
151static OMX_ERRORTYPE FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
152                                OMX_IN  OMX_U32 nPortIndex,
153                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
154static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
155                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
156                                OMX_IN OMX_U32 nPortIndex,
157                                OMX_IN OMX_PTR pAppPrivate,
158                                OMX_IN OMX_U32 nSizeBytes,
159                                OMX_IN OMX_U8* pBuffer);
160static OMX_ERRORTYPE GetExtensionIndex(OMX_IN  OMX_HANDLETYPE hComponent,
161                                       OMX_IN  OMX_STRING cParameterName,
162                                       OMX_OUT OMX_INDEXTYPE* pIndexType);
163
164static OMX_ERRORTYPE ComponentRoleEnum(
165                                       OMX_IN OMX_HANDLETYPE hComponent,
166                                       OMX_OUT OMX_U8 *cRole,
167                                       OMX_IN OMX_U32 nIndex);
168
169/* interface with audio manager*/
170#define FIFO1 "/dev/fifo.1"
171#define FIFO2 "/dev/fifo.2"
172#define PERMS 0666
173
174#ifdef DSP_RENDERING_ON
175AM_COMMANDDATATYPE cmd_data;
176#endif
177
178
179
180/*-------------------------------------------------------------------*/
181/**
182 * OMX_ComponentInit() Set the all the function pointers of component
183 *
184 * This method will update the component function pointer to the handle
185 *
186 * @param hComp         handle for this instance of the component
187 *
188 * @retval OMX_NoError              Success, ready to roll
189 *         OMX_ErrorInsufficientResources If the malloc fails
190 **/
191/*-------------------------------------------------------------------*/
192OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
193{
194    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
195    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
196    OMX_AUDIO_PARAM_G729TYPE *g729_op = NULL;
197    OMX_AUDIO_PARAM_PCMMODETYPE *g729_ip = NULL;
198    OMX_ERRORTYPE eError = OMX_ErrorNone;
199    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
200    G729ENC_PORT_TYPE *pCompPort = NULL;
201    OMX_AUDIO_PARAM_PORTFORMATTYPE *pInPortFormat = NULL;
202    OMX_AUDIO_PARAM_PORTFORMATTYPE *pOutPortFormat = NULL;
203    int i = 0;
204
205    G729ENC_DPRINT("OMX_ComponentInit\n");
206    /*Set the all component function pointer to the handle */
207    pHandle->SetCallbacks = SetCallbacks;
208    pHandle->GetComponentVersion = GetComponentVersion;
209    pHandle->SendCommand = SendCommand;
210    pHandle->GetParameter = GetParameter;
211    pHandle->SetParameter = SetParameter;
212    pHandle->GetConfig = GetConfig;
213    pHandle->SetConfig = SetConfig;
214    pHandle->GetState = GetState;
215    pHandle->EmptyThisBuffer = EmptyThisBuffer;
216    pHandle->FillThisBuffer = FillThisBuffer;
217    pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
218    pHandle->ComponentDeInit = ComponentDeInit;
219    pHandle->AllocateBuffer = AllocateBuffer;
220    pHandle->FreeBuffer = FreeBuffer;
221    pHandle->UseBuffer = UseBuffer;
222    pHandle->GetExtensionIndex = GetExtensionIndex;
223    pHandle->ComponentRoleEnum = ComponentRoleEnum;
224
225    /*Allocate the memory for Component private data area */
226    OMX_G729MALLOC_STRUCT(pHandle->pComponentPrivate, G729ENC_COMPONENT_PRIVATE);
227    ((G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
228    pComponentPrivate = pHandle->pComponentPrivate;
229
230#ifdef __PERF_INSTRUMENTATION__
231    pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('7','2','9',' '),
232                                           PERF_ModuleLLMM |
233                                           PERF_ModuleAudioDecode);
234#endif
235    OMX_G729MALLOC_STRUCT(pCompPort, G729ENC_PORT_TYPE);
236    pComponentPrivate->pCompPort[G729ENC_INPUT_PORT] = pCompPort;
237
238    OMX_G729MALLOC_STRUCT(pCompPort, G729ENC_PORT_TYPE);
239    pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT] = pCompPort;
240
241    OMX_G729MALLOC_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
242    OMX_G729CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
243
244    /* Initialize sPortParam data structures to default values */
245    pComponentPrivate->sPortParam->nPorts = 0x2;
246    pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
247
248    /* Malloc and Set pPriorityMgmt defaults */
249    OMX_G729MALLOC_STRUCT(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
250    OMX_G729CONF_INIT_STRUCT(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
251
252    /* Initialize sPriorityMgmt data structures to default values */
253    pComponentPrivate->sPriorityMgmt->nGroupPriority = -1;
254    pComponentPrivate->sPriorityMgmt->nGroupID = -1;
255
256    OMX_G729MALLOC_STRUCT(g729_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
257    OMX_G729CONF_INIT_STRUCT(g729_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
258    pComponentPrivate->pcmParams = g729_ip;
259
260    /* PCM format defaults */
261    g729_ip->nPortIndex = G729ENC_INPUT_PORT;
262    g729_ip->nChannels = 2;
263    g729_ip->eNumData= OMX_NumericalDataSigned;
264    g729_ip->nBitPerSample = 16;
265    g729_ip->nSamplingRate = 44100;
266    g729_ip->ePCMMode = OMX_AUDIO_PCMModeLinear;
267
268    OMX_G729MALLOC_STRUCT(g729_op, OMX_AUDIO_PARAM_G729TYPE);
269    OMX_G729CONF_INIT_STRUCT(g729_op, OMX_AUDIO_PARAM_G729TYPE);
270    pComponentPrivate->g729Params = g729_op;
271    g729_op->nPortIndex = G729ENC_OUTPUT_PORT;
272
273    /* malloc and initialize number of input buffers */
274    OMX_G729MALLOC_STRUCT(pComponentPrivate->pInputBufferList, G729ENC_BUFFERLIST);
275    pComponentPrivate->pInputBufferList->numBuffers = 0;
276
277    /* malloc and initialize number of output buffers */
278    OMX_G729MALLOC_STRUCT(pComponentPrivate->pOutputBufferList, G729ENC_BUFFERLIST);
279    pComponentPrivate->pOutputBufferList->numBuffers = 0;
280
281    for (i=0; i < G729ENC_MAX_NUM_OF_BUFS; i++)
282    {
283        pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
284        pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
285        pComponentPrivate->arrTickCount[i] = 0;
286        pComponentPrivate->arrTimestamp[i] = 0;
287    }
288
289    /* Set input port defaults */
290    OMX_G729MALLOC_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
291    OMX_G729CONF_INIT_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
292    pComponentPrivate->pPortDef[G729ENC_INPUT_PORT] = pPortDef_ip;
293
294    pPortDef_ip->nPortIndex                         = G729ENC_INPUT_PORT;
295    pPortDef_ip->eDir                               = OMX_DirInput;
296    pPortDef_ip->nBufferCountActual                 = G729ENC_NUM_INPUT_BUFFERS;
297    pPortDef_ip->nBufferCountMin                    = G729ENC_NUM_INPUT_BUFFERS;
298    pPortDef_ip->nBufferSize                        = G729ENC_INPUT_FRAME_SIZE;
299    pPortDef_ip->bEnabled                           = OMX_TRUE;
300    pPortDef_ip->bPopulated                         = OMX_FALSE;
301    pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
302    pPortDef_ip->format.audio.eEncoding             = OMX_AUDIO_CodingPCM;
303    pPortDef_ip->format.audio.cMIMEType             = NULL;
304    pPortDef_ip->format.audio.pNativeRender         = NULL;
305    pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
306
307    /* Set output port defaults */
308    OMX_G729MALLOC_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
309    OMX_G729CONF_INIT_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
310    pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT] = pPortDef_op;
311
312    pPortDef_op->nPortIndex                         = G729ENC_OUTPUT_PORT;
313    pPortDef_op->eDir                               = OMX_DirOutput;
314    pPortDef_op->nBufferCountMin                    = G729ENC_NUM_OUTPUT_BUFFERS;
315    pPortDef_op->nBufferCountActual                 = G729ENC_NUM_OUTPUT_BUFFERS;
316    pPortDef_op->nBufferSize                        = G729ENC_OUTPUT_FRAME_SIZE;
317    pPortDef_op->bEnabled                           = OMX_TRUE;
318    pPortDef_op->bPopulated                         = OMX_FALSE;
319    pPortDef_op->eDomain                            = OMX_PortDomainAudio;
320    pPortDef_op->format.audio.eEncoding             = OMX_AUDIO_CodingG729;
321    pPortDef_op->format.audio.cMIMEType             = NULL;
322    pPortDef_op->format.audio.pNativeRender         = NULL;
323    pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
324
325    OMX_G729MALLOC_STRUCT(pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
326    OMX_G729CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
327    /* Set input port format defaults */
328    pInPortFormat = pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat;
329    OMX_G729CONF_INIT_STRUCT(pInPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
330    pInPortFormat->nPortIndex         = G729ENC_INPUT_PORT;
331    pInPortFormat->nIndex             = OMX_IndexParamAudioPcm;
332    pInPortFormat->eEncoding          = OMX_AUDIO_CodingPCM;
333
334    OMX_G729MALLOC_STRUCT(pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
335    OMX_G729CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
336    /* Set output port format defaults */
337    pOutPortFormat = pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat;
338    OMX_G729CONF_INIT_STRUCT(pOutPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
339    pOutPortFormat->nPortIndex         = G729ENC_OUTPUT_PORT;
340    pOutPortFormat->nIndex             = OMX_IndexParamAudioG729;
341    pOutPortFormat->eEncoding          = OMX_AUDIO_CodingG729;
342
343    G729ENC_DPRINT("Setting dasf & mime & efr & acdn & g729 and MultiFrame modes to 0\n");
344    pComponentPrivate->dasfMode = 0;
345    pComponentPrivate->rtmx = 0;
346    pComponentPrivate->mimeMode = 0;
347    pComponentPrivate->acdnMode = 0;
348    pComponentPrivate->efrMode  = 0;
349    pComponentPrivate->g729Mode  = 0;
350    pComponentPrivate->nMultiFrameMode = 0;
351    pComponentPrivate->bPortDefsAllocated = OMX_TRUE;
352    pComponentPrivate->bCompThreadStarted = 0;
353    pComponentPrivate->bPlayCompleteFlag = 0;
354    pComponentPrivate->pParams = NULL;
355    pComponentPrivate->pAlgParam = NULL;
356    pComponentPrivate->bInitParamsInitialized = 0;
357    pComponentPrivate->pMarkBuf = NULL;
358    pComponentPrivate->pMarkData = NULL;
359    pComponentPrivate->nEmptyBufferDoneCount = 0;
360    pComponentPrivate->nEmptyThisBufferCount = 0;
361    pComponentPrivate->nFillBufferDoneCount = 0;
362    pComponentPrivate->nFillThisBufferCount = 0;
363    pComponentPrivate->strmAttr = NULL;
364    pComponentPrivate->nDataWritesWhilePaused = 0;
365    pComponentPrivate->bIdleCommandPending = 0;
366    pComponentPrivate->bDisableCommandParam = 0;
367    pComponentPrivate->bIsEOFSent = 0;
368    pComponentPrivate->bBypassDSP = 0;
369    pComponentPrivate->iHoldLen = 0;
370    pComponentPrivate->iHoldBuffer = NULL;
371    pComponentPrivate->pHoldBuffer = NULL;
372    pComponentPrivate->nHoldLength = 0;
373    pComponentPrivate->IpBufindex = 0;
374    pComponentPrivate->OpBufindex = 0;
375    pComponentPrivate->bDisableCommandParam = 0;
376    pComponentPrivate->bEnableCommandParam = 0;
377    pComponentPrivate->bDisableCommandPending = 0;
378    pComponentPrivate->bEnableCommandPending = 0;
379    pComponentPrivate->nUnhandledFillThisBuffers=0;
380    pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
381    pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
382    pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
383    pComponentPrivate->bPreempted = OMX_FALSE;
384
385    pComponentPrivate->sDeviceString = malloc(100*sizeof(OMX_STRING));
386    if (pComponentPrivate->sDeviceString == NULL) {
387	G729ENC_EPRINT("OMX_ErrorInsufficientResources.\n");
388	eError = OMX_ErrorInsufficientResources;
389	goto EXIT;
390    }
391
392    strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
393
394
395    for (i=0; i < G729ENC_MAX_NUM_OF_BUFS; i++)
396    {
397        pComponentPrivate->pInputBufHdrPending[i] = NULL;
398        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
399    }
400    pComponentPrivate->bJustReenabled = 0;
401    pComponentPrivate->nInvalidFrameCount = 0;
402    pComponentPrivate->nNumInputBufPending = 0;
403    pComponentPrivate->nNumOutputBufPending = 0;
404    pComponentPrivate->bDisableCommandPending = 0;
405    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
406    pComponentPrivate->bIdleCommandPending = OMX_FALSE;
407    pComponentPrivate->nOutStandingFillDones = 0;
408    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
409    pComponentPrivate->nRuntimeInputBuffers=0;
410    pComponentPrivate->nRuntimeOutputBuffers=0;
411#ifndef UNDER_CE
412    pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
413    pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
414    pComponentPrivate->AlloBuf_waitingsignal = 0;
415    pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
416    pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
417    pComponentPrivate->InLoaded_readytoidle = 0;
418    pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
419    pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
420    pComponentPrivate->InIdle_goingtoloaded = 0;
421#else
422    OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
423    pComponentPrivate->AlloBuf_waitingsignal = 0;
424    OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
425    pComponentPrivate->InLoaded_readytoidle = 0;
426    OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
427    pComponentPrivate->InIdle_goingtoloaded = 0;
428#endif
429
430
431#ifdef RESOURCE_MANAGER_ENABLED
432    eError = RMProxy_NewInitalize();
433    if (eError != OMX_ErrorNone)
434    {
435        G729ENC_EPRINT("From loading ResourceManagerProxy thread.\n");
436        goto EXIT;
437    }
438#endif
439
440    eError = G729ENC_StartComponentThread(pHandle);
441    if (eError != OMX_ErrorNone)
442    {
443        G729ENC_EPRINT("From the Component.\n");
444        goto EXIT;
445    }
446
447#ifdef DSP_RENDERING_ON
448    if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0)
449    {
450        G729ENC_EPRINT("Failure to open WRITE pipe\n");
451    }
452    if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0)
453    {
454        G729ENC_EPRINT("Failure to open READ pipe\n");
455    }
456#endif
457
458#ifdef __PERF_INSTRUMENTATION__
459    PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->ComponentThread,
460                       PERF_FOURCC('7','2','9','T'));
461#endif
462 EXIT:
463    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
464    return eError;
465}
466
467/*-------------------------------------------------------------------*/
468/**
469 *  SetCallbacks() Sets application callbacks to the component
470 *
471 * This method will update application callbacks
472 * to the component. So that component can make use of those call back
473 * while sending buffers to the application. And also it will copy the
474 * application private data to component memory
475 *
476 * @param pComponent    handle for this instance of the component
477 * @param pCallBacks    application callbacks
478 * @param pAppData      Application private data
479 *
480 * @retval OMX_NoError              Success, ready to roll
481 *         OMX_Error_BadParameter   The input parameter pointer is null
482 **/
483/*-------------------------------------------------------------------*/
484
485static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
486                                   OMX_CALLBACKTYPE* pCallBacks,
487                                   OMX_PTR pAppData)
488{
489    OMX_ERRORTYPE eError = OMX_ErrorNone;
490    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
491    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
492        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
493
494    G729ENC_DPRINT("Entering\n");
495    if (pCallBacks == NULL)
496    {
497        eError = OMX_ErrorBadParameter;
498        G729ENC_EPRINT("Received empty callbacks from the application.\n");
499        goto EXIT;
500    }
501    /*Copy the callbacks of the application to the component private*/
502    memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
503    /*copy the application private data to component memory */
504    pHandle->pApplicationPrivate = pAppData;
505    pComponentPrivate->curState = OMX_StateLoaded;
506#ifdef __PERF_INSTRUMENTATION__
507    PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
508#endif
509 EXIT:
510    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
511    return eError;
512}
513
514/*-------------------------------------------------------------------*/
515/**
516 *  GetComponentVersion() This will return the component version
517 *
518 * This method will retrun the component version
519 *
520 * @param hComp               handle for this instance of the component
521 * @param pCompnentName       Name of the component
522 * @param pCompnentVersion    handle for this instance of the component
523 * @param pSpecVersion        application callbacks
524 * @param pCompnentUUID
525 *
526 * @retval OMX_NoError              Success, ready to roll
527 *         OMX_Error_BadParameter   The input parameter pointer is null
528 **/
529/*-------------------------------------------------------------------*/
530
531static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
532                                          OMX_STRING pComponentName,
533                                          OMX_VERSIONTYPE* pComponentVersion,
534                                          OMX_VERSIONTYPE* pSpecVersion,
535                                          OMX_UUIDTYPE* pComponentUUID)
536{
537    OMX_ERRORTYPE eError = OMX_ErrorNone;
538    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
539    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
540
541    G729ENC_DPRINT("Entering\n");
542#ifdef _ERROR_PROPAGATION__
543    if (pComponentPrivate->curState == OMX_StateInvalid)
544    {
545        eError = OMX_ErrorInvalidState;
546        goto EXIT;
547    }
548#endif
549    /* Copy component version structure */
550    if(pComponentVersion != NULL && pComponentName != NULL)
551    {
552        strcpy(pComponentName, pComponentPrivate->cComponentName);
553        memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s),
554               sizeof(pComponentPrivate->ComponentVersion.s));
555    }
556    else
557    {
558        G729ENC_DPRINT("OMX_ErrorBadParameter from GetComponentVersion");
559        eError = OMX_ErrorBadParameter;
560    }
561 EXIT:
562    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
563    return eError;
564}
565/*-------------------------------------------------------------------*/
566/**
567 *  SendCommand() used to send the commands to the component
568 *
569 * This method will be used by the application.
570 *
571 * @param phandle         handle for this instance of the component
572 * @param Cmd             Command to be sent to the component
573 * @param nParam          indicates commmad is sent using this method
574 *
575 * @retval OMX_NoError              Success, ready to roll
576 *         OMX_Error_BadParameter   The input parameter pointer is null
577 **/
578/*-------------------------------------------------------------------*/
579
580static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
581                                  OMX_COMMANDTYPE Cmd,
582                                  OMX_U32 nParam,
583                                  OMX_PTR pCmdData)
584{
585    OMX_ERRORTYPE eError = OMX_ErrorNone;
586    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
587    G729ENC_COMPONENT_PRIVATE *pCompPrivate =
588        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
589    int nRet = 0;
590
591#ifdef _ERROR_PROPAGATION__
592    if (pCompPrivate->curState == OMX_StateInvalid)
593    {
594        eError = OMX_ErrorInvalidState;
595        goto EXIT;
596    }
597#else
598    if(pCompPrivate->curState == OMX_StateInvalid)
599    {
600        eError = OMX_ErrorIncorrectStateOperation;
601        goto EXIT;
602    }
603#endif
604#ifdef __PERF_INSTRUMENTATION__
605    PERF_SendingCommand(pCompPrivate->pPERF,
606                        Cmd,
607                        (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam,
608                        PERF_ModuleComponent);
609#endif
610    G729ENC_DPRINT("Entering\n");
611    switch(Cmd)
612    {
613    case OMX_CommandStateSet:
614        G729ENC_DPRINT("OMX_CommandStateSet SendCommand\n");
615        if (nParam == OMX_StateLoaded) {
616            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
617        }
618        if(pCompPrivate->curState == OMX_StateLoaded)
619        {
620            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause))
621            {
622                pCompPrivate->cbInfo.EventHandler ( pHandle,
623                                                    pHandle->pApplicationPrivate,
624                                                    OMX_EventError,
625                                                    OMX_ErrorIncorrectStateTransition,
626                                                    0,
627                                                    NULL);
628                goto EXIT;
629            }
630            if(nParam == OMX_StateInvalid)
631            {
632                G729ENC_DPRINT("OMX_CommandStateSet SendCommand\n");
633                pCompPrivate->curState = OMX_StateInvalid;
634                pCompPrivate->cbInfo.EventHandler ( pHandle,
635                                                    pHandle->pApplicationPrivate,
636                                                    OMX_EventError,
637                                                    OMX_ErrorInvalidState,
638                                                    0,
639                                                    NULL);
640                goto EXIT;
641            }
642        }
643        break;
644    case OMX_CommandFlush:
645        G729ENC_DPRINT("OMX_CommandFlush SendCommand\n");
646        if(nParam > 1 && nParam != -1)
647        {
648            eError = OMX_ErrorBadPortIndex;
649            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
650            goto EXIT;
651        }
652        break;
653    case OMX_CommandPortDisable:
654        G729ENC_DPRINT("OMX_CommandPortDisable SendCommand\n");
655        break;
656    case OMX_CommandPortEnable:
657        G729ENC_DPRINT("OMX_CommandPortEnable SendCommand\n");
658        break;
659    case OMX_CommandMarkBuffer:
660        G729ENC_DPRINT("OMX_CommandMarkBuffer SendCommand\n");
661        if (nParam > 0)
662        {
663            eError = OMX_ErrorBadPortIndex;
664            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
665            goto EXIT;
666        }
667        break;
668    default:
669        G729ENC_DPRINT("Command Received Default eError\n");
670        pCompPrivate->cbInfo.EventHandler ( pHandle,
671                                            pHandle->pApplicationPrivate,
672                                            OMX_EventError,
673                                            OMX_ErrorUndefined,
674                                            0,
675                                            "Invalid Command");
676        break;
677    }
678    nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
679    if (nRet == -1)
680    {
681        eError = OMX_ErrorInsufficientResources;
682        G729ENC_EPRINT("OMX_ErrorInsufficientResources.\n");
683        goto EXIT;
684    }
685    if (Cmd == OMX_CommandMarkBuffer)
686    {
687        nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
688    }
689    else
690    {
691        nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32));
692    }
693    if (nRet == -1)
694    {
695        eError = OMX_ErrorInsufficientResources;
696        G729ENC_EPRINT("OMX_ErrorInsufficientResources.\n");
697        goto EXIT;
698    }
699 EXIT:
700    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
701    return eError;
702}
703/*-------------------------------------------------------------------*/
704/**
705 *  GetParameter() Gets the current configurations of the component
706 *
707 * @param hComp         handle for this instance of the component
708 * @param nParamIndex
709 * @param ComponentParameterStructure
710 *
711 * @retval OMX_NoError              Success, ready to roll
712 *         OMX_Error_BadParameter   The input parameter pointer is null
713 **/
714/*-------------------------------------------------------------------*/
715
716static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
717                                   OMX_INDEXTYPE nParamIndex,
718                                   OMX_PTR ComponentParameterStructure)
719{
720    OMX_ERRORTYPE eError = OMX_ErrorNone;
721    G729ENC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
722    OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL;
723    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
724    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
725
726    G729ENC_DPRINT("Entering\n");
727    if (pParameterStructure == NULL)
728    {
729        eError = OMX_ErrorBadParameter;
730        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
731        goto EXIT;
732    }
733#ifdef _ERROR_PROPAGATION__
734    if (pComponentPrivate->curState == OMX_StateInvalid)
735    {
736        eError = OMX_ErrorInvalidState;
737        goto EXIT;
738    }
739#else
740    if(pComponentPrivate->curState == OMX_StateInvalid)
741    {
742        eError = OMX_ErrorIncorrectStateOperation;
743        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
744        goto EXIT;
745    }
746#endif
747    switch(nParamIndex)
748    {
749    case OMX_IndexParamAudioInit:
750        G729ENC_DPRINT("case OMX_IndexParamAudioInit\n");
751	if (pComponentPrivate->sPortParam == NULL) {
752            eError = OMX_ErrorBadParameter;
753	    break;
754	}
755        memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam,
756               sizeof(OMX_PORT_PARAM_TYPE));
757        break;
758    case OMX_IndexParamPortDefinition:
759        G729ENC_DPRINT("case OMX_IndexParamPortDefinition \n");
760        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
761           pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->nPortIndex)
762        {
763            memcpy(ComponentParameterStructure,
764                   pComponentPrivate->pPortDef[G729ENC_INPUT_PORT],
765                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
766        }
767        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
768                pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->nPortIndex)
769        {
770            memcpy(ComponentParameterStructure,
771                   pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT],
772                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
773        }
774        else
775        {
776            eError = OMX_ErrorBadPortIndex;
777            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
778        }
779        break;
780    case OMX_IndexParamAudioPortFormat:
781        G729ENC_DPRINT("case OMX_IndexParamAudioPortFormat\n");
782        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
783           pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->nPortIndex)
784        {
785            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
786               pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat->nPortIndex)
787            {
788                eError = OMX_ErrorNoMore;
789            }
790            else
791            {
792                memcpy(ComponentParameterStructure,
793                       pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat,
794                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
795            }
796        }
797        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
798                pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->nPortIndex)
799        {
800            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
801               pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat->nPortIndex)
802            {
803                eError = OMX_ErrorNoMore;
804            }
805            else
806            {
807                memcpy(ComponentParameterStructure,
808                       pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat,
809                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
810            }
811        }
812        else
813        {
814            eError = OMX_ErrorBadPortIndex;
815            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
816        }
817        break;
818    case OMX_IndexParamAudioG729:
819        G729ENC_DPRINT("Case OMX_IndexParamAudioG729\n");
820        if(((OMX_AUDIO_PARAM_G729TYPE *)(ComponentParameterStructure))->nPortIndex ==
821           pComponentPrivate->g729Params->nPortIndex)
822        {
823            memcpy(ComponentParameterStructure,
824                   pComponentPrivate->g729Params, sizeof(OMX_AUDIO_PARAM_G729TYPE));
825        }
826        else
827        {
828            eError = OMX_ErrorBadPortIndex;
829            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
830        }
831        break;
832
833    case OMX_IndexParamAudioPcm:
834        if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
835           pComponentPrivate->pcmParams->nPortIndex) {
836
837            memcpy(ComponentParameterStructure,
838                   pComponentPrivate->pcmParams,
839                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
840        }
841        else {
842            G729ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from GetParameter \n",__LINE__);
843            eError = OMX_ErrorBadPortIndex;
844        }
845        break;
846    case OMX_IndexParamPriorityMgmt:
847	if (pComponentPrivate->sPriorityMgmt == NULL) {
848            eError = OMX_ErrorBadParameter;
849	    break;
850	}
851        G729ENC_DPRINT("Case OMX_IndexParamPriorityMgmt\n");
852        memcpy(ComponentParameterStructure,
853               pComponentPrivate->sPriorityMgmt,
854               sizeof(OMX_PRIORITYMGMTTYPE));
855        break;
856
857    case OMX_IndexParamCompBufferSupplier:
858        if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) {
859            G729ENC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
860            /*  memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
861        }
862        else
863            if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) {
864                G729ENC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
865                /*memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */
866            }
867            else {
868                G729ENC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter");
869                eError = OMX_ErrorBadPortIndex;
870            }
871        break;
872
873    case OMX_IndexParamVideoInit:
874        break;
875
876    case OMX_IndexParamImageInit:
877        break;
878
879    case OMX_IndexParamOtherInit:
880        break;
881
882    default:
883        eError = OMX_ErrorUnsupportedIndex;
884        G729ENC_EPRINT("OMX_ErrorUnsupportedIndex.\n");
885        break;
886    }
887 EXIT:
888    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
889    return eError;
890}
891/*-------------------------------------------------------------------*/
892/**
893 *  SetParameter() Sets configuration paramets to the component
894 *
895 * @param hComp         handle for this instance of the component
896 * @param nParamIndex
897 * @param pCompParam
898 *
899 * @retval OMX_NoError              Success, ready to roll
900 *         OMX_Error_BadParameter   The input parameter pointer is null
901 **/
902/*-------------------------------------------------------------------*/
903
904static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
905                                   OMX_INDEXTYPE nParamIndex,
906                                   OMX_PTR pCompParam)
907{
908    OMX_ERRORTYPE eError = OMX_ErrorNone;
909    OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
910    G729ENC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
911    OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
912    OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL;
913    OMX_AUDIO_PARAM_G729TYPE *pCompG729Param = NULL;
914    /*    OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL; */
915    OMX_AUDIO_PARAM_PCMMODETYPE* pPcmPort = NULL;
916    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
917    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
918
919    G729ENC_DPRINT("Entering\n");
920    if (pCompParam == NULL)
921    {
922        eError = OMX_ErrorBadParameter;
923        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
924        goto EXIT;
925    }
926    if (pComponentPrivate->curState != OMX_StateLoaded)
927    {
928        eError = OMX_ErrorIncorrectStateOperation;
929        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
930        goto EXIT;
931    }
932#ifdef _ERROR_PROPAGATION__
933    if (pComponentPrivate->curState == OMX_StateInvalid)
934    {
935        eError = OMX_ErrorInvalidState;
936        goto EXIT;
937    }
938#endif
939    switch(nParamIndex)
940    {
941    case OMX_IndexParamAudioPortFormat:
942        G729ENC_DPRINT("SetParameter OMX_IndexParamAudioPortFormat\n");
943        pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
944        if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat->nPortIndex )
945        {
946            memcpy(pComponentPrivate->pCompPort[G729ENC_INPUT_PORT]->pPortFormat,
947                   pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
948        }
949        else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat->nPortIndex )
950        {
951            memcpy(pComponentPrivate->pCompPort[G729ENC_OUTPUT_PORT]->pPortFormat,
952                   pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
953        }
954        else
955        {
956            eError = OMX_ErrorBadPortIndex;
957            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
958        }
959        break;
960    case OMX_IndexParamAudioG729:
961        pCompG729Param = (OMX_AUDIO_PARAM_G729TYPE *)pCompParam;
962        if (pCompG729Param->nPortIndex == G729ENC_OUTPUT_PORT)
963        {
964            memcpy(((G729ENC_COMPONENT_PRIVATE *)
965                    pHandle->pComponentPrivate)->g729Params,
966                   pCompG729Param, sizeof(OMX_AUDIO_PARAM_G729TYPE));
967        }
968        else
969        {
970            eError = OMX_ErrorBadPortIndex;
971            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
972        }
973        break;
974    case OMX_IndexParamPortDefinition:
975        pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
976        G729ENC_DPRINT("Case OMX_IndexParamPortDefinition\n");
977        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
978           pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->nPortIndex)
979        {
980            G729ENC_DPRINT("Case OMX_IndexParamPortDefinition\n");
981            memcpy(pComponentPrivate->pPortDef[G729ENC_INPUT_PORT],
982                   pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
983        }
984        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
985                pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->nPortIndex)
986        {
987            G729ENC_DPRINT("Case OMX_IndexParamPortDefinition\n");
988            memcpy(pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT],
989                   pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
990        }
991        else
992        {
993            eError = OMX_ErrorBadPortIndex;
994            G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
995        }
996        break;
997    case OMX_IndexParamPriorityMgmt:
998        if (pComponentPrivate->sPriorityMgmt == NULL) {
999            eError = OMX_ErrorBadParameter;
1000	    break;
1001	}
1002        G729ENC_DPRINT("Case OMX_IndexParamPriorityMgmt\n");
1003        memcpy(pComponentPrivate->sPriorityMgmt,
1004               (OMX_PRIORITYMGMTTYPE*)pCompParam,
1005               sizeof(OMX_PRIORITYMGMTTYPE));
1006        break;
1007    case OMX_IndexParamAudioInit:
1008        if (pComponentPrivate->sPortParam == NULL) {
1009            eError = OMX_ErrorBadParameter;
1010	    break;
1011	}
1012        G729ENC_DPRINT("SetParameter OMX_IndexParamAudioInit\n");
1013        memcpy(pComponentPrivate->sPortParam,
1014               (OMX_PORT_PARAM_TYPE*)pCompParam,
1015               sizeof(OMX_PORT_PARAM_TYPE));
1016        break;
1017
1018    case OMX_IndexParamStandardComponentRole:
1019        /*if (pCompParam) {
1020          pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
1021          memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1022          } else {
1023          eError = OMX_ErrorBadParameter;
1024          }*/
1025        eError = OMX_ErrorBadParameter;
1026        break;
1027
1028    case OMX_IndexParamAudioPcm:
1029        if(pCompParam){
1030        if (pComponentPrivate->pcmParams == NULL) {
1031            eError = OMX_ErrorBadParameter;
1032	    break;
1033	}
1034            pPcmPort= (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
1035            memcpy(pComponentPrivate->pcmParams, pPcmPort, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
1036        }
1037        else{
1038            eError = OMX_ErrorBadParameter;
1039        }
1040        break;
1041
1042    case OMX_IndexParamCompBufferSupplier:
1043        /*      eError = OMX_ErrorBadPortIndex; *//*remove for StdAudioDecoderTest, leave for other tests*/
1044        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1045           pComponentPrivate->pPortDef[OMX_DirInput]->nPortIndex) {
1046            G729ENC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1047            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
1048            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1049
1050        }
1051        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1052                pComponentPrivate->pPortDef[OMX_DirOutput]->nPortIndex) {
1053            G729ENC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1054            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
1055            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1056        }
1057        else {
1058            G729ENC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
1059            eError = OMX_ErrorBadPortIndex;
1060        }
1061        break;
1062    default:
1063        eError = OMX_ErrorUnsupportedIndex;
1064        G729ENC_EPRINT("OMX_ErrorUnsupportedIndex.\n");
1065        break;
1066    }
1067 EXIT:
1068    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1069    return eError;
1070}
1071
1072/*-------------------------------------------------------------------*/
1073/**
1074 *  GetConfig() Gets the current configuration of to the component
1075 *
1076 * @param hComp         handle for this instance of the component
1077 * @param nConfigIndex
1078 * @param ComponentConfigStructure
1079 *
1080 * @retval OMX_NoError              Success, ready to roll
1081 *         OMX_Error_BadParameter   The input parameter pointer is null
1082 **/
1083/*-------------------------------------------------------------------*/
1084
1085static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1086                                OMX_INDEXTYPE nConfigIndex,
1087                                OMX_PTR ComponentConfigStructure)
1088{
1089    OMX_ERRORTYPE eError = OMX_ErrorNone;
1090    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1091    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
1092        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1093
1094    G729ENC_DPRINT("Entering\n");
1095#ifdef _ERROR_PROPAGATION__
1096    if (pComponentPrivate->curState == OMX_StateInvalid)
1097    {
1098        eError = OMX_ErrorInvalidState;
1099        goto EXIT;
1100    }
1101#endif
1102 EXIT:
1103    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1104    return eError;
1105}
1106/*-------------------------------------------------------------------*/
1107/**
1108 *  SetConfig() Sets the configraiton to the component
1109 *
1110 * @param hComp         handle for this instance of the component
1111 * @param nConfigIndex
1112 * @param ComponentConfigStructure
1113 *
1114 * @retval OMX_NoError              Success, ready to roll
1115 *         OMX_Error_BadParameter   The input parameter pointer is null
1116 **/
1117/*-------------------------------------------------------------------*/
1118
1119static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1120                                OMX_INDEXTYPE nConfigIndex,
1121                                OMX_PTR ComponentConfigStructure)
1122{
1123    OMX_ERRORTYPE eError = OMX_ErrorNone;
1124    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1125    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1126    TI_OMX_DSP_DEFINITION *pTiDspDefinition = NULL;
1127    TI_OMX_DSP_DEFINITION *configData = NULL;
1128    OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL;
1129    TI_OMX_DATAPATH dataPath;
1130    OMX_S16 *customFlag = NULL;
1131    G729ENC_DPRINT("Entering\n");
1132    if (pHandle == NULL)
1133    {
1134        eError = OMX_ErrorBadParameter;
1135        G729ENC_EPRINT("Invalid HANDLE OMX_ErrorBadParameter.\n");
1136        goto EXIT;
1137    }
1138
1139    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1140#ifdef _ERROR_PROPAGATION__
1141    if (pComponentPrivate->curState == OMX_StateInvalid)
1142    {
1143        eError = OMX_ErrorInvalidState;
1144        goto EXIT;
1145    }
1146#endif
1147
1148    switch (nConfigIndex)
1149    {
1150    case OMX_IndexCustomG729ENCModeConfig:
1151        pTiDspDefinition = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1152        memcpy(&(pComponentPrivate->tiOmxDspDefinition), pTiDspDefinition,
1153               sizeof(TI_OMX_DSP_DEFINITION));
1154        pComponentPrivate->dasfMode = pComponentPrivate->tiOmxDspDefinition.dasfMode;
1155        pComponentPrivate->acdnMode = pComponentPrivate->tiOmxDspDefinition.acousticMode;
1156        pComponentPrivate->streamID = pComponentPrivate->tiOmxDspDefinition.streamId;
1157        break;
1158    case OMX_IndexConfigAudioVolume:
1159#ifdef DSP_RENDERING_ON
1160        pGainStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
1161        cmd_data.hComponent = hComp;
1162        cmd_data.AM_Cmd = AM_CommandSWGain;
1163        cmd_data.param1 = pGainStructure->sVolume.nValue;
1164        cmd_data.param2 = 0;
1165        cmd_data.streamID = pComponentPrivate->streamID;
1166        if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1167        {
1168            G729ENC_EPRINT("Fail to send command to audio manager.\n");
1169        }
1170        else
1171        {
1172            G729ENC_DPRINT("Ok to send command to audio manager\n");
1173        }
1174#endif
1175        break;
1176    case OMX_IndexCustomG729ENCHeaderInfoConfig:
1177        G729ENC_DPRINT("Case OMX_IndexCustomWbAmrEncHeaderInfoConfig\n");
1178        configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1179        if (configData == NULL)
1180        {
1181            eError = OMX_ErrorBadParameter;
1182            G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1183            goto EXIT;
1184        }
1185
1186        /*pComponentPrivate->amrMode = *customFlag;*/
1187        pComponentPrivate->acdnMode = configData->acousticMode;
1188        pComponentPrivate->dasfMode = configData->dasfMode;
1189        if (2 == pComponentPrivate->dasfMode)
1190        {
1191            pComponentPrivate->dasfMode--;
1192            pComponentPrivate->rtmx = 1;
1193        }
1194        pComponentPrivate->streamID = configData->streamId;
1195
1196        break;
1197
1198    case  OMX_IndexCustomG729ENCDataPath:
1199        customFlag = (OMX_S16*)ComponentConfigStructure;
1200        if (customFlag == NULL) {
1201            eError = OMX_ErrorBadParameter;
1202            goto EXIT;
1203        }
1204
1205        dataPath = *customFlag;
1206
1207        switch(dataPath) {
1208        case DATAPATH_APPLICATION:
1209            OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_ENCODER, pComponentPrivate->streamID);
1210            /*                strcpy((char*)pComponentPrivate->sDeviceString,(char*)ETEEDN_STRING_ENCODER); */
1211            break;
1212
1213        case DATAPATH_APPLICATION_RTMIXER:
1214            strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING_ENCODER);
1215            break;
1216
1217        default:
1218            break;
1219
1220        }
1221        break;
1222
1223    default:
1224        eError = OMX_ErrorUnsupportedIndex;
1225        G729ENC_EPRINT("OMX_ErrorUnsupportedIndex.\n");
1226        break;
1227    }
1228 EXIT:
1229    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1230    return eError;
1231}
1232
1233/*-------------------------------------------------------------------*/
1234/**
1235 *  GetState() Gets the current state of the component
1236 *
1237 * @param pCompomponent handle for this instance of the component
1238 * @param pState
1239 *
1240 * @retval OMX_NoError              Success, ready to roll
1241 *         OMX_Error_BadParameter   The input parameter pointer is null
1242 **/
1243/*-------------------------------------------------------------------*/
1244
1245static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1246{
1247    OMX_ERRORTYPE eError = OMX_ErrorUndefined;
1248    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1249
1250    G729ENC_DPRINT("Entering GetState\n");
1251    if (!pState)
1252    {
1253        eError = OMX_ErrorBadParameter;
1254        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1255        goto EXIT;
1256    }
1257    if (pHandle && pHandle->pComponentPrivate)
1258    {
1259        *pState =  ((G729ENC_COMPONENT_PRIVATE*)
1260                    pHandle->pComponentPrivate)->curState;
1261    }
1262    else
1263    {
1264        *pState = OMX_StateLoaded;
1265    }
1266    eError = OMX_ErrorNone;
1267 EXIT:
1268    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1269    return eError;
1270}
1271
1272/*-------------------------------------------------------------------*/
1273/**
1274 *  EmptyThisBuffer() This callback is used to send the input buffer to
1275 *  component
1276 *
1277 * @param pComponent       handle for this instance of the component
1278 * @param nPortIndex       input port index
1279 * @param pBuffer          buffer to be sent to codec
1280 *
1281 * @retval OMX_NoError              Success, ready to roll
1282 *         OMX_Error_BadParameter   The input parameter pointer is null
1283 **/
1284/*-------------------------------------------------------------------*/
1285
1286static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1287                                      OMX_BUFFERHEADERTYPE* pBuffer)
1288{
1289    OMX_ERRORTYPE eError = OMX_ErrorNone;
1290    int ret = 0;
1291    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1292    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1293    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
1294        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1295    pPortDef = ((G729ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[G729ENC_INPUT_PORT];
1296#ifdef _ERROR_PROPAGATION__
1297    if (pComponentPrivate->curState == OMX_StateInvalid)
1298    {
1299        eError = OMX_ErrorInvalidState;
1300        goto EXIT;
1301    }
1302#endif
1303#ifdef __PERF_INSTRUMENTATION__
1304    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1305                       pBuffer->pBuffer,
1306                       pBuffer->nFilledLen,
1307                       PERF_ModuleHLMM);
1308#endif
1309
1310    G729ENC_DPRINT("Entering EmptyThisBuffer\n");
1311    if (pBuffer == NULL)
1312    {
1313        eError = OMX_ErrorBadParameter;
1314        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1315        goto EXIT;
1316    }
1317    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE))
1318    {
1319        eError = OMX_ErrorBadParameter;
1320        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1321        goto EXIT;
1322    }
1323    if (!pPortDef->bEnabled)
1324    {
1325        eError  = OMX_ErrorIncorrectStateOperation;
1326        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
1327        goto EXIT;
1328    }
1329    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion)
1330    {
1331        eError = OMX_ErrorVersionMismatch;
1332        G729ENC_EPRINT("OMX_ErrorVersionMismatch.\n");
1333        goto EXIT;
1334    }
1335    if (pBuffer->nInputPortIndex != G729ENC_INPUT_PORT)
1336    {
1337        eError  = OMX_ErrorBadPortIndex;
1338        G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
1339        goto EXIT;
1340    }
1341    if (pComponentPrivate->curState != OMX_StateExecuting &&
1342        pComponentPrivate->curState != OMX_StatePause)
1343    {
1344        eError= OMX_ErrorIncorrectStateOperation;
1345        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
1346        goto EXIT;
1347    }
1348    G729ENC_DPRINT("Comp Sending Filled ip buff = %p to CompThread\n", pBuffer);
1349
1350    pComponentPrivate->nUnhandledEmptyThisBuffers++;
1351    pComponentPrivate->app_nBuf--;
1352    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1353    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1354    ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof(OMX_BUFFERHEADERTYPE*));
1355    if (ret == -1)
1356    {
1357        eError = OMX_ErrorHardware;
1358        G729ENC_EPRINT("in Writing to the Data pipe.\n");
1359        goto EXIT;
1360    }
1361    pComponentPrivate->nEmptyThisBufferCount++;
1362 EXIT:
1363    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1364    return eError;
1365}
1366/*-------------------------------------------------------------------*/
1367/**
1368 *  FillThisBuffer() This callback is used to send the output buffer to
1369 *  the component
1370 *
1371 * @param pComponent    handle for this instance of the component
1372 * @param nPortIndex    output port number
1373 * @param pBuffer       buffer to be sent to codec
1374 *
1375 * @retval OMX_NoError              Success, ready to roll
1376 *         OMX_Error_BadParameter   The input parameter pointer is null
1377 **/
1378/*-------------------------------------------------------------------*/
1379
1380static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1381                                     OMX_BUFFERHEADERTYPE* pBuffer)
1382{
1383    OMX_ERRORTYPE eError = OMX_ErrorNone;
1384    int ret = 0;
1385    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1386    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1387    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
1388        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1389    pPortDef = ((G729ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[G729ENC_OUTPUT_PORT];
1390
1391#ifdef _ERROR_PROPAGATION__
1392    if (pComponentPrivate->curState == OMX_StateInvalid)
1393    {
1394        eError = OMX_ErrorInvalidState;
1395        goto EXIT;
1396    }
1397#endif
1398#ifdef __PERF_INSTRUMENTATION__
1399    PERF_ReceivedFrame(pComponentPrivate->pPERF,
1400                       pBuffer->pBuffer,
1401                       pBuffer->nFilledLen,
1402                       PERF_ModuleHLMM);
1403#endif
1404    G729ENC_DPRINT("Entering\n");
1405    G729ENC_DPRINT("Comp Sending Emptied op buff = %p to CompThread\n", pBuffer);
1406    if (pBuffer == NULL)
1407    {
1408        eError = OMX_ErrorBadParameter;
1409        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1410        goto EXIT;
1411    }
1412    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE))
1413    {
1414        eError = OMX_ErrorBadParameter;
1415        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1416        goto EXIT;
1417    }
1418    if (!pPortDef->bEnabled)
1419    {
1420        eError  = OMX_ErrorIncorrectStateOperation;
1421        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
1422        goto EXIT;
1423    }
1424    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion)
1425    {
1426        eError = OMX_ErrorVersionMismatch;
1427        G729ENC_EPRINT("OMX_ErrorVersionMismatch.\n");
1428        goto EXIT;
1429    }
1430    if (pBuffer->nOutputPortIndex != G729ENC_OUTPUT_PORT)
1431    {
1432        eError  = OMX_ErrorBadPortIndex;
1433        G729ENC_EPRINT("OMX_ErrorBadPortIndex.\n");
1434        goto EXIT;
1435    }
1436    if(pComponentPrivate->curState != OMX_StateExecuting &&
1437       pComponentPrivate->curState != OMX_StatePause)
1438    {
1439        eError = OMX_ErrorIncorrectStateOperation;
1440        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
1441        goto EXIT;
1442    }
1443    pBuffer->nFilledLen = 0;
1444    /*Filling the Output buffer with zero */
1445    memset(pBuffer->pBuffer, 0, pBuffer->nAllocLen);
1446    pComponentPrivate->app_nBuf--;
1447    if(pComponentPrivate->pMarkBuf != NULL)
1448    {
1449        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1450        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1451        pComponentPrivate->pMarkBuf = NULL;
1452    }
1453    if (pComponentPrivate->pMarkData != NULL)
1454    {
1455        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1456        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1457        pComponentPrivate->pMarkData = NULL;
1458    }
1459    if (pBuffer->nFlags != OMX_BUFFERFLAG_EOS){
1460        pComponentPrivate->nUnhandledFillThisBuffers++;
1461    }
1462    ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1463                 sizeof (OMX_BUFFERHEADERTYPE*));
1464
1465    if (ret == -1)
1466    {
1467        eError = OMX_ErrorHardware;
1468        G729ENC_EPRINT("in Writing to the Data pipe.\n");
1469        goto EXIT;
1470    }
1471
1472    pComponentPrivate->nFillThisBufferCount++;
1473 EXIT:
1474    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1475    return eError;
1476}
1477/*-------------------------------------------------------------------*/
1478/**
1479 * OMX_ComponentDeinit() this methold will de init the component
1480 *
1481 * @param pComp         handle for this instance of the component
1482 *
1483 * @retval OMX_NoError              Success, ready to roll
1484 *         OMX_Error_BadParameter   The input parameter pointer is null
1485 **/
1486/*-------------------------------------------------------------------*/
1487
1488static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1489{
1490    OMX_ERRORTYPE eError = OMX_ErrorNone;
1491
1492    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1493    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
1494        (G729ENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1495
1496#ifdef __PERF_INSTRUMENTATION__
1497    PERF_Boundary(pComponentPrivate->pPERF,
1498                  PERF_BoundaryStart | PERF_BoundaryCleanup);
1499#endif
1500
1501#ifdef DSP_RENDERING_ON
1502    close(pComponentPrivate->fdwrite);
1503    close(pComponentPrivate->fdread);
1504#endif
1505
1506#ifdef RESOURCE_MANAGER_ENABLED
1507    eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_G729_Encoder_COMPONENT, 0, 3456,NULL);
1508    if (eError != OMX_ErrorNone) {
1509        G729ENC_EPRINT ("%d ::OMX_G729Encoder.c :: Error returned from destroy ResourceManagerProxy thread\n",
1510                        __LINE__);
1511    }
1512    eError = RMProxy_Deinitalize();
1513    if (eError != OMX_ErrorNone)
1514    {
1515        G729ENC_EPRINT("from destroy ResourceManagerProxy thread.\n");
1516    }
1517#endif
1518    pComponentPrivate->bIsThreadstop = 1;
1519    eError = G729ENC_StopComponentThread(pHandle);
1520    if (eError != OMX_ErrorNone)
1521    {
1522        G729ENC_EPRINT("from G729ENC_StopComponentThread.\n");
1523        goto EXIT;
1524    }
1525    /* Wait for thread to exit so we can get the status into "eError" */
1526    /* close the pipe handles */
1527    eError = G729ENC_FreeCompResources(pHandle);
1528    if (eError != OMX_ErrorNone)
1529    {
1530        G729ENC_EPRINT("from G729ENC_FreeCompResources.\n");
1531        goto EXIT;
1532    }
1533
1534#ifndef UNDER_CE
1535    pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
1536    pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
1537    pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
1538    pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
1539    pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
1540    pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
1541#else
1542    OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
1543    OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
1544    OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
1545#endif
1546
1547#ifdef __PERF_INSTRUMENTATION__
1548    PERF_Boundary(pComponentPrivate->pPERF,
1549                  PERF_BoundaryComplete | PERF_BoundaryCleanup);
1550    PERF_Done(pComponentPrivate->pPERF);
1551#endif
1552
1553    if (pComponentPrivate->sDeviceString != NULL) {
1554        free(pComponentPrivate->sDeviceString);
1555    }
1556
1557    OMX_G729MEMFREE_STRUCT(pComponentPrivate);
1558 EXIT:
1559    G729ENC_DPRINT("Exiting ComponentDeInit. Returning = 0x%x\n", eError);
1560    return eError;
1561}
1562
1563/*-------------------------------------------------------------------*/
1564/**
1565 *  ComponentTunnelRequest() this method is not implemented in 1.5
1566 *
1567 * This method will update application callbacks
1568 * the application.
1569 *
1570 * @param pComp         handle for this instance of the component
1571 * @param pCallBacks    application callbacks
1572 * @param ptr
1573 *
1574 * @retval OMX_NoError              Success, ready to roll
1575 *         OMX_Error_BadParameter   The input parameter pointer is null
1576 **/
1577/*-------------------------------------------------------------------*/
1578
1579static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1580                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1581                                             OMX_U32 nTunneledPort,
1582                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1583{
1584    OMX_ERRORTYPE eError = OMX_ErrorNone;
1585
1586    G729ENC_DPRINT("Entering\n");
1587    eError = OMX_ErrorNotImplemented;
1588    G729ENC_EPRINT("OMX_ErrorNotImplemented.\n");
1589    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
1590    return eError;
1591}
1592
1593/*-------------------------------------------------------------------*/
1594/**
1595 *  AllocateBuffer()
1596
1597 * @param pComp         handle for this instance of the component
1598 * @param pCallBacks    application callbacks
1599 * @param ptr
1600 *
1601 * @retval OMX_NoError              Success, ready to roll
1602 *         OMX_Error_BadParameter   The input parameter pointer is null
1603 **/
1604/*-------------------------------------------------------------------*/
1605
1606static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1607                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1608                                     OMX_IN OMX_U32 nPortIndex,
1609                                     OMX_IN OMX_PTR pAppPrivate,
1610                                     OMX_IN OMX_U32 nSizeBytes)
1611
1612{
1613    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1614    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1615    OMX_ERRORTYPE eError = OMX_ErrorNone;
1616    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1617
1618    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)
1619        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1620
1621    pPortDef = ((G729ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1622#ifdef _ERROR_PROPAGATION__
1623    if (pComponentPrivate->curState == OMX_StateInvalid)
1624    {
1625        eError = OMX_ErrorInvalidState;
1626        goto EXIT;
1627    }
1628#endif
1629    G729ENC_DPRINT("Entering AllocateBuffer\n");
1630    G729ENC_DPRINT("pPortDef = %p\n", pPortDef);
1631    G729ENC_DPRINT("pPortDef->bEnabled = %d\n", pPortDef->bEnabled);
1632    if(!(pPortDef->bEnabled))
1633    {
1634        pComponentPrivate->AlloBuf_waitingsignal = 1;
1635#ifndef UNDER_CE
1636        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1637        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold,
1638                          &pComponentPrivate->AlloBuf_mutex);
1639        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1640#else
1641        OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1642#endif
1643    }
1644    OMX_G729MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE);
1645    pBufferHeader->pBuffer = (OMX_U8 *)malloc(nSizeBytes + 256);
1646    G729ENC_MEMPRINT("%d :: [ALLOC]  %p\n",__LINE__,pBufferHeader->pBuffer);
1647    if (pBufferHeader->pBuffer == NULL)
1648    {
1649        /* Free previously allocated memory before bailing */
1650        if (pBufferHeader)
1651        {
1652            free(pBufferHeader);
1653            pBufferHeader = NULL;
1654        }
1655        eError = OMX_ErrorInsufficientResources;
1656        goto EXIT;
1657    }
1658    pBufferHeader->pBuffer += 128;
1659    if (nPortIndex == G729ENC_INPUT_PORT)
1660    {
1661        pBufferHeader->nInputPortIndex = nPortIndex;
1662        pBufferHeader->nOutputPortIndex = -1;
1663        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1664        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1665        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1666        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual)
1667        {
1668            pPortDef->bPopulated = OMX_TRUE;
1669            G729ENC_DPRINT("pPortDef->bPopulated = %d\n", pPortDef->bPopulated);
1670        }
1671    }
1672    else if (nPortIndex == G729ENC_OUTPUT_PORT)
1673    {
1674        pBufferHeader->nInputPortIndex = -1;
1675        pBufferHeader->nOutputPortIndex = nPortIndex;
1676        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1677        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1678        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1679        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual)
1680        {
1681            pPortDef->bPopulated = OMX_TRUE;
1682            G729ENC_DPRINT("pPortDef->bPopulated = %d\n", pPortDef->bPopulated);
1683        }
1684    }
1685    else
1686    {
1687        eError = OMX_ErrorBadPortIndex;
1688        G729ENC_EPRINT("About to return OMX_ErrorBadPortIndex\n");
1689        goto EXIT;
1690    }
1691    /* Removing sleep() calls. Input buffer enabled and populated as well as output buffer. */
1692    if((pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bEnabled)&&
1693       (pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bEnabled) &&
1694       (pComponentPrivate->InLoaded_readytoidle))
1695    {
1696        pComponentPrivate->InLoaded_readytoidle = 0;
1697#ifndef UNDER_CE
1698        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1699        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1700        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1701#else
1702        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1703#endif
1704    }
1705    pBufferHeader->pAppPrivate = pAppPrivate;
1706    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1707    pBufferHeader->nAllocLen = nSizeBytes;
1708    pBufferHeader->nVersion.s.nVersionMajor = G729ENC_MAJOR_VER;
1709    pBufferHeader->nVersion.s.nVersionMinor = G729ENC_MINOR_VER;
1710    pBufferHeader->nVersion.s.nRevision = 0;
1711    pBufferHeader->nVersion.s.nStep = 0;
1712    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1713    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1714    *pBuffer = pBufferHeader;
1715
1716    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
1717        SendCommand (pComponentPrivate->pHandle,
1718                     OMX_CommandPortEnable,
1719                     pComponentPrivate->bEnableCommandParam,NULL);
1720    }
1721
1722#ifdef __PERF_INSTRUMENTATION__
1723    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
1724                        (*pBuffer)->pBuffer, nSizeBytes,
1725                        PERF_ModuleMemory);
1726#endif
1727 EXIT:
1728    G729ENC_DPRINT("Exiting AllocateBuffer. Returning = 0x%x\n", eError);
1729    return eError;
1730}
1731
1732/*-------------------------------------------------------------------*/
1733/**
1734 *  FreeBuffer()
1735
1736 * @param hComponent   handle for this instance of the component
1737 * @param pCallBacks   application callbacks
1738 * @param ptr
1739 *
1740 * @retval OMX_NoError              Success, ready to roll
1741 *         OMX_Error_BadParameter   The input parameter pointer is null
1742 **/
1743/*-------------------------------------------------------------------*/
1744
1745static OMX_ERRORTYPE FreeBuffer(
1746                                OMX_IN  OMX_HANDLETYPE hComponent,
1747                                OMX_IN  OMX_U32 nPortIndex,
1748                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1749{
1750    OMX_ERRORTYPE eError = OMX_ErrorNone;
1751    G729ENC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1752    OMX_BUFFERHEADERTYPE* buff = NULL;
1753    OMX_U8* tempBuff = NULL;
1754    int i = 0;
1755    int inputIndex = -1;
1756    int outputIndex = -1;
1757    OMX_COMPONENTTYPE *pHandle = NULL;
1758
1759    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)
1760        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1761    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
1762
1763    G729ENC_DPRINT("Entering FreeBuffer\n");
1764    if (nPortIndex == G729ENC_INPUT_PORT){
1765        for (i=0; i < G729ENC_MAX_NUM_OF_BUFS; i++)
1766        {
1767            buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
1768            if (buff == pBuffer)
1769            {
1770                G729ENC_DPRINT("Found matching input buffer\n");
1771                G729ENC_DPRINT("buff = %p\n", buff);
1772                G729ENC_DPRINT("pBuffer = %p\n", pBuffer);
1773                inputIndex = i;
1774                break;
1775            }
1776            else
1777            {
1778                G729ENC_DPRINT("This is not a match\n");
1779                G729ENC_DPRINT("buff = %p\n", buff);
1780                G729ENC_DPRINT("pBuffer = %p\n", pBuffer);
1781            }
1782        }
1783    }
1784    else if (nPortIndex == G729ENC_OUTPUT_PORT){
1785        for (i=0; i < G729ENC_MAX_NUM_OF_BUFS; i++)
1786        {
1787            buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
1788            if (buff == pBuffer)
1789            {
1790                G729ENC_DPRINT("Found matching output buffer\n");
1791                G729ENC_DPRINT("buff = %p\n", buff);
1792                G729ENC_DPRINT("pBuffer = %p\n", pBuffer);
1793                outputIndex = i;
1794                break;
1795            }
1796            else
1797            {
1798                G729ENC_DPRINT("This is not a match\n");
1799                G729ENC_DPRINT("buff = %p\n", buff);
1800                G729ENC_DPRINT("pBuffer = %p\n", pBuffer);
1801            }
1802        }
1803    }
1804    if (inputIndex != -1)
1805    {
1806        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1)
1807        {
1808            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
1809            if (tempBuff != 0)
1810            {
1811                tempBuff -= 128;
1812            }
1813            OMX_G729MEMFREE_STRUCT(tempBuff);
1814        }
1815#ifdef __PERF_INSTRUMENTATION__
1816        PERF_SendingBuffer(pComponentPrivate->pPERF,
1817                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,
1818                           pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
1819                           PERF_ModuleMemory );
1820#endif
1821        OMX_G729MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1822        pComponentPrivate->pInputBufferList->numBuffers--;
1823        if (pComponentPrivate->pInputBufferList->numBuffers <
1824            pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->nBufferCountActual)
1825        {
1826            pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bPopulated = OMX_FALSE;
1827        }
1828        if(pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bEnabled &&
1829           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1830           (pComponentPrivate->curState == OMX_StateIdle ||
1831            pComponentPrivate->curState == OMX_StateExecuting ||
1832            pComponentPrivate->curState == OMX_StatePause))
1833        {
1834            pComponentPrivate->cbInfo.EventHandler( pHandle,
1835                                                    pHandle->pApplicationPrivate,
1836                                                    OMX_EventError,
1837                                                    OMX_ErrorPortUnpopulated,
1838                                                    nPortIndex,
1839                                                    NULL);
1840        }
1841    }
1842    else if (outputIndex != -1)
1843    {
1844        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
1845            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
1846            if (tempBuff != 0)
1847            {
1848                tempBuff -= 128;
1849            }
1850            OMX_G729MEMFREE_STRUCT(tempBuff);
1851        }
1852#ifdef __PERF_INSTRUMENTATION__
1853        PERF_SendingBuffer(pComponentPrivate->pPERF,
1854                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,
1855                           pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen,
1856                           PERF_ModuleMemory );
1857#endif
1858        OMX_G729MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1859
1860        pComponentPrivate->pOutputBufferList->numBuffers--;
1861        if (pComponentPrivate->pOutputBufferList->numBuffers <
1862            pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->nBufferCountActual)
1863        {
1864            pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bPopulated = OMX_FALSE;
1865        }
1866        if(pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bEnabled &&
1867           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1868           (pComponentPrivate->curState == OMX_StateIdle ||
1869            pComponentPrivate->curState == OMX_StateExecuting ||
1870            pComponentPrivate->curState == OMX_StatePause))
1871        {
1872            pComponentPrivate->cbInfo.EventHandler( pHandle,
1873                                                    pHandle->pApplicationPrivate,
1874                                                    OMX_EventError,
1875                                                    OMX_ErrorPortUnpopulated,
1876                                                    nPortIndex,
1877                                                    NULL);
1878        }
1879    }
1880    else
1881    {
1882        eError = OMX_ErrorBadParameter;
1883        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1884    }
1885    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
1886         !pComponentPrivate->pOutputBufferList->numBuffers) &&
1887        pComponentPrivate->InIdle_goingtoloaded)
1888    {
1889        pComponentPrivate->InIdle_goingtoloaded = 0;
1890#ifndef UNDER_CE
1891        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1892        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
1893        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1894#else
1895        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
1896#endif
1897    }
1898    if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers +
1899                                                      pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
1900        SendCommand (pComponentPrivate->pHandle, OMX_CommandPortDisable,
1901                     pComponentPrivate->bDisableCommandParam,NULL);
1902    }
1903    G729ENC_DPRINT("Exiting FreeBuffer Returning = 0x%x\n", eError);
1904    return eError;
1905}
1906
1907/*-------------------------------------------------------------------*/
1908/**
1909 *  UseBuffer()
1910
1911 * @param pComp         handle for this instance of the component
1912 * @param pCallBacks    application callbacks
1913 * @param ptr
1914 *
1915 * @retval OMX_NoError              Success, ready to roll
1916 *         OMX_Error_BadParameter   The input parameter pointer is null
1917 **/
1918/*-------------------------------------------------------------------*/
1919static OMX_ERRORTYPE UseBuffer (
1920                                OMX_IN OMX_HANDLETYPE hComponent,
1921                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1922                                OMX_IN OMX_U32 nPortIndex,
1923                                OMX_IN OMX_PTR pAppPrivate,
1924                                OMX_IN OMX_U32 nSizeBytes,
1925                                OMX_IN OMX_U8* pBuffer)
1926{
1927    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1928    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1929    OMX_ERRORTYPE eError = OMX_ErrorNone;
1930    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1931
1932    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)
1933        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1934
1935#ifdef _ERROR_PROPAGATION__
1936    if (pComponentPrivate->curState == OMX_StateInvalid)
1937    {
1938        eError = OMX_ErrorInvalidState;
1939        goto EXIT;
1940    }
1941#endif
1942    pPortDef = ((G729ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1943    G729ENC_DPRINT("Entering\n");
1944    G729ENC_DPRINT("pPortDef->bPopulated = %d \n", pPortDef->bPopulated);
1945    if(!pPortDef->bEnabled)
1946    {
1947        eError = OMX_ErrorIncorrectStateOperation;
1948        G729ENC_EPRINT("OMX_ErrorIncorrectStateOperation.\n");
1949        goto EXIT;
1950    }
1951    if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated)
1952    {
1953        eError = OMX_ErrorBadParameter;
1954        G729ENC_EPRINT("OMX_ErrorBadParameter.\n");
1955        goto EXIT;
1956    }
1957
1958    OMX_G729MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE);
1959    if (nPortIndex == G729ENC_OUTPUT_PORT)
1960    {
1961        pBufferHeader->nInputPortIndex = -1;
1962        pBufferHeader->nOutputPortIndex = nPortIndex;
1963        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1964        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1965        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
1966        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual)
1967        {
1968            pPortDef->bPopulated = OMX_TRUE;
1969        }
1970    }
1971    else
1972    {
1973        pBufferHeader->nInputPortIndex = nPortIndex;
1974        pBufferHeader->nOutputPortIndex = -1;
1975        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1976        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1977        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
1978        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual)
1979        {
1980            pPortDef->bPopulated = OMX_TRUE;
1981        }
1982    }
1983    if((pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G729ENC_OUTPUT_PORT]->bEnabled)&&
1984       (pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]->bEnabled) &&
1985       (pComponentPrivate->InLoaded_readytoidle))
1986    {
1987        pComponentPrivate->InLoaded_readytoidle = 0;
1988#ifndef UNDER_CE
1989        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1990        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1991        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1992#else
1993        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1994#endif
1995    }
1996    pBufferHeader->pAppPrivate = pAppPrivate;
1997    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1998    pBufferHeader->nAllocLen = nSizeBytes;
1999    pBufferHeader->nVersion.s.nVersionMajor = G729ENC_MAJOR_VER;
2000    pBufferHeader->nVersion.s.nVersionMinor = G729ENC_MINOR_VER;
2001    pBufferHeader->nVersion.s.nRevision = 0;
2002    pBufferHeader->nVersion.s.nStep = 0;
2003    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2004    pBufferHeader->pBuffer = pBuffer;
2005    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2006    *ppBufferHdr = pBufferHeader;
2007
2008    if (pComponentPrivate->bEnableCommandPending){
2009        SendCommand (pComponentPrivate->pHandle,
2010                     OMX_CommandPortEnable,
2011                     pComponentPrivate->bEnableCommandParam,NULL);
2012    }
2013#ifdef __PERF_INSTRUMENTATION__
2014    PERF_ReceivedBuffer(pComponentPrivate->pPERF,
2015                        pBuffer, nSizeBytes,
2016                        PERF_ModuleHLMM);
2017#endif
2018 EXIT:
2019    G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
2020    return eError;
2021}
2022
2023/* ================================================================================= */
2024/**
2025 * @fn GetExtensionIndex() description for GetExtensionIndex
2026 GetExtensionIndex().
2027 Returns index for vendor specific settings.
2028 *
2029 *  @see         OMX_Core.h
2030 */
2031/* ================================================================================ */
2032static OMX_ERRORTYPE GetExtensionIndex(
2033                                       OMX_IN  OMX_HANDLETYPE hComponent,
2034                                       OMX_IN  OMX_STRING cParameterName,
2035                                       OMX_OUT OMX_INDEXTYPE* pIndexType)
2036{
2037    OMX_ERRORTYPE eError = OMX_ErrorNone;
2038
2039    G729ENC_DPRINT("Entering\n");
2040    if (!(strcmp(cParameterName,"OMX.TI.index.config.tispecific")))
2041    {
2042        *pIndexType = OMX_IndexCustomG729ENCModeConfig;
2043        G729ENC_DPRINT("OMX_IndexCustomG729ENCModeConfig\n");
2044    }
2045    else if(!(strcmp(cParameterName,"OMX.TI.index.config.g729headerinfo")))
2046    {
2047        *pIndexType = OMX_IndexCustomG729ENCHeaderInfoConfig;
2048    }
2049    else if(!(strcmp(cParameterName,"OMX.TI.index.config.G729streamIDinfo")))
2050    {
2051        *pIndexType = OMX_IndexCustomG729ENCStreamIDConfig;
2052    }
2053    else if(!(strcmp(cParameterName,"OMX.TI.index.config.g729.datapath")))
2054    {
2055        *pIndexType = OMX_IndexCustomG729ENCDataPath;
2056    }
2057
2058    else
2059    {
2060        eError = OMX_ErrorBadParameter;
2061    }
2062    G729ENC_DPRINT("Exiting\n");
2063    return eError;
2064}
2065
2066
2067/* ================================================================================= */
2068/**
2069 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
2070
2071 Returns the role at the given index
2072 *
2073 *  @see         OMX_Core.h
2074 */
2075/* ================================================================================ */
2076static OMX_ERRORTYPE ComponentRoleEnum(
2077                                       OMX_IN OMX_HANDLETYPE hComponent,
2078                                       OMX_OUT OMX_U8 *cRole,
2079                                       OMX_IN OMX_U32 nIndex)
2080{
2081
2082    OMX_ERRORTYPE eError = OMX_ErrorNone;
2083
2084    /* This is a non standard component and does not support roles */
2085    eError = OMX_ErrorNotImplemented;
2086
2087    return eError;
2088}
2089
2090#ifdef UNDER_CE
2091/* ================================================================================= */
2092/**
2093 * @fns Sleep replace for WIN CE
2094 */
2095/* ================================================================================ */
2096int OMX_CreateEvent(OMX_Event *event){
2097    int ret = OMX_ErrorNone;
2098    HANDLE createdEvent = NULL;
2099
2100    if(event == NULL)
2101    {
2102        ret = OMX_ErrorBadParameter;
2103        goto EXIT;
2104    }
2105    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2106    if(event->event == NULL)
2107    {
2108        ret = (int)GetLastError();
2109    }
2110 EXIT:
2111    return ret;
2112}
2113
2114int OMX_SignalEvent(OMX_Event *event){
2115    int ret = OMX_ErrorNone;
2116
2117    if(event == NULL)
2118    {
2119        ret = OMX_ErrorBadParameter;
2120        goto EXIT;
2121    }
2122    SetEvent(event->event);
2123    ret = (int)GetLastError();
2124 EXIT:
2125    return ret;
2126}
2127
2128int OMX_WaitForEvent(OMX_Event *event)
2129{
2130    int ret = OMX_ErrorNone;
2131
2132    if(event == NULL)
2133    {
2134        ret = OMX_ErrorBadParameter;
2135        goto EXIT;
2136    }
2137    WaitForSingleObject(event->event, INFINITE);
2138    ret = (int)GetLastError();
2139 EXIT:
2140    return ret;
2141}
2142
2143int OMX_DestroyEvent(OMX_Event *event)
2144{
2145    int ret = OMX_ErrorNone;
2146
2147    if(event == NULL)
2148    {
2149        ret = OMX_ErrorBadParameter;
2150        goto EXIT;
2151    }
2152    CloseHandle(event->event);
2153 EXIT:
2154    return ret;
2155}
2156#endif
2157
2158void G729ENC_eprint(int iLineNum, const char *szFunctionName, const char *strFormat, ...)
2159{
2160#ifndef UNDER_CE
2161    va_list list;
2162
2163    fprintf(stdout, "ERROR::%s():%d: ", szFunctionName, iLineNum);
2164    fprintf(stdout, "%s", DBG_TEXT_WHITE);
2165    va_start(list, strFormat);
2166    vfprintf(stdout, strFormat, list);
2167    va_end(list);
2168#endif
2169}
2170
2171void G729ENC_Log(const char *szFileName, int iLineNum, const char *szFunctionName, const char *strFormat, ...)
2172{
2173#ifndef UNDER_CE
2174    va_list list;
2175
2176    if (szFileName ==(const char *) "OMX_G729Encoder.c")
2177    {
2178        fprintf(stdout, "%s", DBG_TEXT_GREEN);
2179    }
2180    else if (szFileName == (const char *)"OMX_G729Enc_ComponentThread.c")
2181    {
2182        fprintf(stdout, "%s", DBG_TEXT_YELLOW);
2183    }
2184    else if (szFileName == (const char *)"OMX_G729Enc_Utils.c")
2185    {
2186        fprintf(stdout, "%s", DBG_TEXT_CYAN);
2187    }
2188    else
2189    {
2190        fprintf(stdout, "%s", DBG_TEXT_WHITE);
2191    }
2192    fprintf(stdout, "%s::", szFileName);
2193    fprintf(stdout, "%s", DBG_TEXT_WHITE);
2194    fprintf(stdout, "%s():%d: ", szFunctionName, iLineNum);
2195    fprintf(stdout, "%s", DBG_TEXT_WHITE);
2196    va_start(list, strFormat);
2197    vfprintf(stdout, strFormat, list);
2198    va_end(list);
2199#endif
2200}
2201