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_G711Decoder.c
30 *
31 * This file implements OMX Component for G711 decoder that
32 * is fully compliant with the OMX Audio specification.
33 *
34 * @path  $(CSLPATH)\
35 *
36 * @rev  0.1
37 */
38/* ----------------------------------------------------------------------------*/
39
40/* ------compilation control switches -------------------------*/
41/****************************************************************
42 *  INCLUDE FILES
43 ****************************************************************/
44/* ----- system and platform files ----------------------------*/
45#ifdef UNDER_CE
46#include <windows.h>
47#include <oaf_osal.h>
48#include <omx_core.h>
49#else
50#include <unistd.h>
51#include <sys/time.h>
52#include <sys/types.h>
53#include <sys/ioctl.h>
54#include <sys/select.h>
55#include <errno.h>
56#include <pthread.h>
57#endif
58#include <string.h>
59#include <fcntl.h>
60#include <stdlib.h>
61#include <stdio.h>
62#include <dbapi.h>
63
64#ifdef DSP_RENDERING_ON
65#include <AudioManagerAPI.h>
66#endif
67
68#ifdef RESOURCE_MANAGER_ENABLED
69#include <ResourceManagerProxyAPI.h>
70#endif
71
72/*-------program files ----------------------------------------*/
73#include <OMX_Component.h>
74#include <TIDspOmx.h>
75#include "OMX_G711Dec_Utils.h"
76
77#ifdef G711DEC_MEMDEBUG
78extern void *arr[500] = {NULL};
79extern int lines[500] = {0};
80extern int bytes[500] = {0};
81extern char file[500][50] = {""};
82/*extern int ind=0;*/
83#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
84void * mymalloc(int line, char *s, int size);
85#define newfree(z) myfree(z,__LINE__,__FILE__)
86void myfree(void *dp, int line, char *s);
87#else
88#define newmalloc(x) malloc(x)
89#define newfree(z) free(z)
90#endif
91
92/****************************************************************
93 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
94 ****************************************************************/
95/*--------data declarations -----------------------------------*/
96
97/*--------function prototypes ---------------------------------*/
98
99/****************************************************************
100 *  PUBLIC DECLARATIONS Defined here, used elsewhere
101 ****************************************************************/
102/*--------data declarations -----------------------------------*/
103
104/*--------function prototypes ---------------------------------*/
105
106/****************************************************************
107 *  PRIVATE DECLARATIONS Defined here, used only here
108 ****************************************************************/
109/*--------data declarations -----------------------------------*/
110
111/*--------function prototypes ---------------------------------*/
112
113static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
114                                   OMX_CALLBACKTYPE* pCallBacks, 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);
120
121static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
122                                  OMX_U32 nParam, OMX_PTR pCmdData);
123
124static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, 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);
135
136static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
137
138static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
139static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
140static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
141                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
142                                             OMX_U32 nTunneledPort,
143                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
144
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);
151
152static OMX_ERRORTYPE FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
153                                OMX_IN  OMX_U32 nPortIndex,
154                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
155
156static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
157                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
158                                OMX_IN OMX_U32 nPortIndex,
159                                OMX_IN OMX_PTR pAppPrivate,
160                                OMX_IN OMX_U32 nSizeBytes,
161                                OMX_IN OMX_U8* pBuffer);
162
163static OMX_ERRORTYPE GetExtensionIndex(OMX_IN  OMX_HANDLETYPE hComponent,
164                                       OMX_IN  OMX_STRING cParameterName,
165                                       OMX_OUT OMX_INDEXTYPE *pIndexType);
166
167static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
168                                       OMX_OUT OMX_U8 *cRole,
169                                       OMX_IN OMX_U32 nIndex);
170
171/* ======================================================================= */
172/**
173 * @def    FIFO1, FIFO2              Define Fifo Path
174 */
175/* ======================================================================= */
176#define FIFO1 "/dev/fifo.1"
177#define FIFO2 "/dev/fifo.2"
178
179/* ======================================================================= */
180/**
181 * @def    PERMS                      Define Read and Write Permisions.
182 */
183/* ======================================================================= */
184#define PERMS 0666
185#define G711_DEC_ROLE "audio_decoder.g711"
186#ifdef DSP_RENDERING_ON
187AM_COMMANDDATATYPE cmd_data;
188#endif
189/*-------------------------------------------------------------------*/
190/**
191 * OMX_ComponentInit() Set the all the function pointers of component
192 *
193 * This method will update the component function pointer to the handle
194 *
195 * @param hComp         handle for this instance of the component
196 *
197 * @retval OMX_NoError              Success, ready to roll
198 *         OMX_ErrorInsufficientResources If the malloc fails
199 **/
200/*-------------------------------------------------------------------*/
201OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
202{
203
204    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
205    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
206    OMX_AUDIO_PARAM_PCMMODETYPE *g711_ip = NULL, *g711_op = NULL;
207    G711DEC_PORT_TYPE *pCompPort = NULL;
208    OMX_AUDIO_PARAM_PORTFORMATTYPE *pInPortFormatArr = NULL;
209    OMX_AUDIO_PARAM_PORTFORMATTYPE *pOutPortFormatArr = NULL;
210    OMX_ERRORTYPE eError = OMX_ErrorNone;
211    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
212    OMX_S16 i = 0;
213
214    G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
215
216    /*Set the all component function pointer to the handle */
217    pHandle->SetCallbacks = SetCallbacks;
218    pHandle->GetComponentVersion = GetComponentVersion;
219    pHandle->SendCommand = SendCommand;
220    pHandle->GetParameter = GetParameter;
221    pHandle->SetParameter = SetParameter;
222    pHandle->GetConfig = GetConfig;
223    pHandle->SetConfig = SetConfig;
224    pHandle->GetState = GetState;
225    pHandle->EmptyThisBuffer = EmptyThisBuffer;
226    pHandle->FillThisBuffer = FillThisBuffer;
227    pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
228    pHandle->ComponentDeInit = ComponentDeInit;
229    pHandle->AllocateBuffer = AllocateBuffer;
230    pHandle->FreeBuffer = FreeBuffer;
231    pHandle->UseBuffer = UseBuffer;
232    pHandle->GetExtensionIndex = GetExtensionIndex;
233    pHandle->ComponentRoleEnum = ComponentRoleEnum;
234
235    /*Allocate the memory for Component private data area */
236    G711D_OMX_MALLOC(pHandle->pComponentPrivate, G711DEC_COMPONENT_PRIVATE);
237
238    ((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
239
240    /* Initialize component data structures to default values */
241    ((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nPorts = 0x2;
242    ((G711DEC_COMPONENT_PRIVATE *)
243     pHandle->pComponentPrivate)->sPortParam.nStartPortNumber = 0x0;
244
245    eError = OMX_ErrorNone;
246
247    G711D_OMX_MALLOC(g711_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
248    G711D_OMX_MALLOC(g711_op, OMX_AUDIO_PARAM_PCMMODETYPE);
249
250    G711DEC_DPRINT ("%d ::LINE \n", __LINE__);
251
252    ((G711DEC_COMPONENT_PRIVATE *)
253     pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT] = g711_ip;
254    ((G711DEC_COMPONENT_PRIVATE *)
255     pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT] = g711_op;
256
257    g711_ip->nPortIndex = G711DEC_INPUT_PORT;
258    g711_op->nPortIndex = G711DEC_OUTPUT_PORT;
259
260    G711DEC_DPRINT("%d Malloced g711Params[G711DEC_INPUT_PORT] = 0x%x\n",__LINE__,
261                   (unsigned int)((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT]);
262    G711DEC_DPRINT("%d Malloced g711Params[G711DEC_OUTPUT_PORT] = 0x%x\n",__LINE__,
263                   (unsigned int)((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT]);
264
265
266    pComponentPrivate = pHandle->pComponentPrivate;
267    G711D_OMX_MALLOC(pComponentPrivate->pInputBufferList, G711DEC_BUFFERLIST);
268    pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
269    G711D_OMX_MALLOC(pComponentPrivate->pOutputBufferList, G711DEC_BUFFERLIST);
270
271    G711D_OMX_MALLOC(pCompPort, G711DEC_PORT_TYPE);
272    pComponentPrivate->pCompPort[G711DEC_INPUT_PORT] = pCompPort;
273    G711D_OMX_MALLOC(pCompPort, G711DEC_PORT_TYPE);
274    pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT] = pCompPort;
275
276    pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
277    pComponentPrivate->bPlayCompleteFlag = 0;
278
279    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
280        pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
281        pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
282    }
283
284    G711DEC_DPRINT("Setting dasfmode and mimemode to 0\n");
285    pComponentPrivate->dasfmode = 0;
286    pComponentPrivate->bPortDefsAllocated = 1;
287    pComponentPrivate->bCompThreadStarted = 0;
288    pComponentPrivate->nHoldLength = 0;
289    pComponentPrivate->pHoldBuffer = NULL;
290    pComponentPrivate->bInitParamsInitialized = 0;
291    pComponentPrivate->pMarkBuf = NULL;
292    pComponentPrivate->pMarkData = NULL;
293    pComponentPrivate->nEmptyBufferDoneCount = 0;
294    pComponentPrivate->nEmptyThisBufferCount = 0;
295    pComponentPrivate->nFillBufferDoneCount = 0;
296    pComponentPrivate->nFillThisBufferCount = 0;
297    pComponentPrivate->strmAttr = NULL;
298    pComponentPrivate->nDataWritesWhilePaused = 0;
299    pComponentPrivate->bIdleCommandPending = 0;
300    pComponentPrivate->bDisableCommandParam = 0;
301    pComponentPrivate->bEnableCommandParam = 0;
302    pComponentPrivate->nRuntimeInputBuffers = 0;
303
304    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
305        pComponentPrivate->pInputBufHdrPending[i] = NULL;
306        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
307    }
308
309    pComponentPrivate->bJustReenabled = 0;
310    pComponentPrivate->nInvalidFrameCount = 0;
311    pComponentPrivate->nNumInputBufPending = 0;
312    pComponentPrivate->nNumOutputBufPending = 0;
313    pComponentPrivate->bDisableCommandPending = 0;
314    pComponentPrivate->bEnableCommandPending = 0;
315    pComponentPrivate->nOutStandingFillDones = 0;
316    pComponentPrivate->bStopSent = 0;
317    pComponentPrivate->bBypassDSP = OMX_FALSE;
318    pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
319    pComponentPrivate->bPreempted = OMX_FALSE;
320
321    G711D_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), OMX_STRING);
322    /* initialize role name */
323    strcpy((char*)pComponentPrivate->componentRole.cRole,G711_DEC_ROLE);
324    /* Initialize device string to the default value */
325    strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
326
327    /* Removing sleep() calls. Initialization.*/
328#ifndef UNDER_CE
329    pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
330    pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
331    pComponentPrivate->AlloBuf_waitingsignal = 0;
332
333    pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
334    pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
335    pComponentPrivate->InLoaded_readytoidle = 0;
336
337    pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
338    pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
339    pComponentPrivate->InIdle_goingtoloaded = 0;
340#else
341    OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
342    pComponentPrivate->AlloBuf_waitingsignal = 0;
343
344    OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
345    pComponentPrivate->InLoaded_readytoidle = 0;
346
347    OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
348    pComponentPrivate->InIdle_goingtoloaded = 0;
349#endif
350    /* Removing sleep() calls. Initialization.*/
351    G711D_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
352    G711D_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
353
354    G711DEC_DPRINT ("%d ::pPortDef_ip = 0x%x\n", __LINE__,(unsigned int)pPortDef_ip);
355    G711DEC_DPRINT ("%d ::pPortDef_op = 0x%x\n", __LINE__,(unsigned int)pPortDef_op);
356
357    pComponentPrivate->pPortDef[G711DEC_INPUT_PORT] = pPortDef_ip;
358    pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT] = pPortDef_op;
359
360    pPortDef_ip->nSize                              = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
361    pPortDef_ip->nPortIndex                         = 0x0;
362    pPortDef_ip->nBufferCountActual                 = NUM_G711DEC_INPUT_BUFFERS;
363    pPortDef_ip->nBufferCountMin                    = NUM_G711DEC_INPUT_BUFFERS;
364    pPortDef_ip->eDir                               = OMX_DirInput;
365    pPortDef_ip->bEnabled                           = OMX_TRUE;
366    pPortDef_ip->nBufferSize                        = INPUT_G711DEC_BUFFER_SIZE;
367    pPortDef_ip->bPopulated                         = 0;
368    pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
369    pPortDef_ip->format.audio.eEncoding             = OMX_AUDIO_CodingG711;
370    pPortDef_ip->format.audio.cMIMEType             = NULL;
371    pPortDef_ip->format.audio.pNativeRender         = NULL;
372    pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
373
374
375    pPortDef_op->nSize                              = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
376    pPortDef_op->nPortIndex                         = 0x1;
377    pPortDef_op->nBufferCountActual                 = NUM_G711DEC_OUTPUT_BUFFERS;
378    pPortDef_op->nBufferCountMin                    = NUM_G711DEC_OUTPUT_BUFFERS;
379    pPortDef_op->eDir                               = OMX_DirOutput;
380    pPortDef_op->bEnabled                           = OMX_TRUE;
381    pPortDef_op->nBufferSize                        = OUTPUT_G711DEC_BUFFER_SIZE;
382    pPortDef_op->bPopulated                         = 0;
383    pPortDef_op->eDomain                            = OMX_PortDomainAudio;
384    pPortDef_op->format.audio.eEncoding             = OMX_AUDIO_CodingPCM;
385    pPortDef_op->format.audio.cMIMEType             = NULL;
386    pPortDef_op->format.audio.pNativeRender         = NULL;
387    pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
388
389    pComponentPrivate->sInPortFormat.nPortIndex    = G711DEC_INPUT_PORT;
390    pComponentPrivate->sInPortFormat.nIndex        = OMX_IndexParamAudioPcm;
391    pComponentPrivate->sInPortFormat.eEncoding     = OMX_AUDIO_CodingG711;
392
393    pComponentPrivate->sOutPortFormat.nPortIndex    = G711DEC_OUTPUT_PORT;
394    pComponentPrivate->sOutPortFormat.nIndex        = OMX_IndexParamAudioPcm;
395    pComponentPrivate->sOutPortFormat.eEncoding     = OMX_AUDIO_CodingPCM;
396
397    G711D_OMX_MALLOC(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
398    OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
399    /* Set input port format defaults */
400    pInPortFormatArr = pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat;
401    OMX_NBCONF_INIT_STRUCT(pInPortFormatArr, OMX_AUDIO_PARAM_PORTFORMATTYPE);
402    pInPortFormatArr->nPortIndex         = G711DEC_INPUT_PORT;
403    pInPortFormatArr->nIndex             = OMX_IndexParamAudioPcm;
404    pInPortFormatArr->eEncoding          = OMX_AUDIO_CodingG711;
405
406    G711D_OMX_MALLOC(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
407    OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
408    /* Set output port format defaults */
409    pOutPortFormatArr = pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat;
410    OMX_NBCONF_INIT_STRUCT(pOutPortFormatArr, OMX_AUDIO_PARAM_PORTFORMATTYPE);
411    pOutPortFormatArr->nPortIndex         = G711DEC_OUTPUT_PORT;
412    pOutPortFormatArr->nIndex             = OMX_IndexParamAudioPcm;
413    pOutPortFormatArr->eEncoding          = OMX_AUDIO_CodingPCM;
414
415#ifdef RESOURCE_MANAGER_ENABLED
416    G711DEC_DPRINT ("%d %s Initialize RM Proxy...\n", __LINE__,__FUNCTION__);
417    eError = RMProxy_NewInitalize();
418    G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
419    if (eError != OMX_ErrorNone) {
420        G711DEC_DPRINT ("%d ::Error returned from loading ResourceManagerProxy thread\n", __LINE__);
421        if( eError == OMX_ErrorInsufficientResources)
422            G711DEC_PRINT("Error OMX_ErrorInsufficientResources\n");
423        else
424            G711DEC_PRINT("eError 0x%x\n", eError);
425        goto EXIT;
426    }
427#endif
428
429    eError = G711DEC_StartComponentThread(pHandle);
430    G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
431    if (eError != OMX_ErrorNone) {
432        G711DEC_DPRINT ("%d ::Error returned from the Component\n", __LINE__);
433        goto EXIT;
434    }
435    G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
436
437#ifdef DSP_RENDERING_ON
438
439    if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0) {
440        G711DEC_DPRINT("[G711 Dec Component] - failure to open WRITE pipe\n");
441    }
442
443    if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0) {
444        G711DEC_DPRINT("[G711 Dec Component] - failure to open READ pipe\n");
445        goto EXIT;
446    }
447    G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
448
449#endif
450 EXIT:
451    if(eError == OMX_ErrorInsufficientResources)
452    {
453        OMX_G711DECMEMFREE_STRUCT(g711_ip);
454        OMX_G711DECMEMFREE_STRUCT(g711_op);
455	 if (pComponentPrivate != NULL) {
456	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
457	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
458	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat);
459	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat);
460	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]);
461	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]);
462	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
463	 }
464	 OMX_G711DECMEMFREE_STRUCT(pHandle->pComponentPrivate);
465        OMX_G711DECMEMFREE_STRUCT(pPortDef_ip);
466        OMX_G711DECMEMFREE_STRUCT(pPortDef_op);
467
468    }
469    G711DEC_DPRINT ("%d ::OMX_ComponentInit - returning %d\n", __LINE__,eError);
470    return eError;
471}
472
473/*-------------------------------------------------------------------*/
474/**
475 *  SetCallbacks() Sets application callbacks to the component
476 *
477 * This method will update application callbacks
478 * to the component. So that component can make use of those call back
479 * while sending buffers to the application. And also it will copy the
480 * application private data to component memory
481 *
482 * @param pComponent    handle for this instance of the component
483 * @param pCallBacks    application callbacks
484 * @param pAppData      Application private data
485 *
486 * @retval OMX_NoError              Success, ready to roll
487 *         OMX_Error_BadParameter   The input parameter pointer is null
488 **/
489/*-------------------------------------------------------------------*/
490
491static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
492                                   OMX_CALLBACKTYPE* pCallBacks,
493                                   OMX_PTR pAppData)
494{
495    OMX_ERRORTYPE eError = OMX_ErrorNone;
496
497    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
498
499    G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
500        (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
501
502    if (pCallBacks == NULL) {
503        G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
504        eError = OMX_ErrorBadParameter;
505        G711DEC_DPRINT ("%d :: Received the empty callbacks from the application\n",__LINE__);
506        goto EXIT;
507    }
508
509    /*Copy the callbacks of the application to the component private */
510    memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
511
512    /*copy the application private data to component memory */
513    pHandle->pApplicationPrivate = pAppData;
514
515    pComponentPrivate->curState = OMX_StateLoaded;
516
517 EXIT:
518    return eError;
519}
520
521/*-------------------------------------------------------------------*/
522/**
523 *  GetComponentVersion() This will return the component version
524 *
525 * This method will retrun the component version
526 *
527 * @param hComp               handle for this instance of the component
528 * @param pCompnentName       Name of the component
529 * @param pCompnentVersion    handle for this instance of the component
530 * @param pSpecVersion        application callbacks
531 * @param pCompnentUUID
532 *
533 * @retval OMX_NoError              Success, ready to roll
534 *         OMX_Error_BadParameter   The input parameter pointer is null
535 **/
536/*-------------------------------------------------------------------*/
537
538static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
539                                          OMX_STRING pComponentName,
540                                          OMX_VERSIONTYPE* pComponentVersion,
541                                          OMX_VERSIONTYPE* pSpecVersion,
542                                          OMX_UUIDTYPE* pComponentUUID)
543{
544    OMX_ERRORTYPE eError = OMX_ErrorNone;
545
546    eError = OMX_ErrorNotImplemented;
547    G711DEC_DPRINT (stderr, "Inside the GetComponentVersion\n");
548    return eError;
549
550}
551
552
553/*-------------------------------------------------------------------*/
554/**
555 *  SendCommand() used to send the commands to the component
556 *
557 * This method will be used by the application.
558 *
559 * @param phandle         handle for this instance of the component
560 * @param Cmd             Command to be sent to the component
561 * @param nParam          indicates commmad is sent using this method
562 *
563 * @retval OMX_NoError              Success, ready to roll
564 *         OMX_Error_BadParameter   The input parameter pointer is null
565 **/
566/*-------------------------------------------------------------------*/
567
568static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
569                                  OMX_COMMANDTYPE Cmd,
570                                  OMX_U32 nParam,OMX_PTR pCmdData)
571{
572    OMX_ERRORTYPE eError = OMX_ErrorNone;
573    ssize_t nRet = 0;
574    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
575    G711DEC_COMPONENT_PRIVATE *pCompPrivate =
576        (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
577
578    G711DEC_DPRINT ("%d:::Inside SendCommand\n", __LINE__);
579
580    G711DEC_DPRINT("phandle = %p\n", phandle);
581    G711DEC_DPRINT("pCompPrivate = %p\n", pCompPrivate);
582
583    pCompPrivate->pHandle = phandle;
584
585    if(pCompPrivate->curState == OMX_StateInvalid){
586        G711DEC_DPRINT ("%d:::Inside SendCommand\n", __LINE__);
587        eError = OMX_ErrorInvalidState;
588        G711DEC_DPRINT("%d :: G711DEC: Error Notofication \
589                                         Sent to App\n",__LINE__);
590        pCompPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
591                                           OMX_EventError, OMX_ErrorInvalidState,
592                                           0, "Invalid State");
593
594        goto EXIT;
595    }
596
597
598    switch(Cmd) {
599    case OMX_CommandStateSet:
600        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
601        G711DEC_DPRINT ("%d:::pCompPrivate->curState = %d\n",
602                        __LINE__,pCompPrivate->curState);
603        if (nParam == OMX_StateLoaded) {
604            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
605        }
606        if(pCompPrivate->curState == OMX_StateLoaded) {
607            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
608                pCompPrivate->cbInfo.EventHandler (pHandle,
609                                                   pHandle->pApplicationPrivate,
610                                                   OMX_EventError,
611                                                   OMX_ErrorIncorrectStateTransition,
612                                                   0, NULL);
613                goto EXIT;
614            }
615
616            if(nParam == OMX_StateInvalid) {
617                G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
618                pCompPrivate->curState = OMX_StateInvalid;
619                pCompPrivate->cbInfo.EventHandler (pHandle,
620                                                   pHandle->pApplicationPrivate,
621                                                   OMX_EventError,
622                                                   OMX_ErrorInvalidState,
623                                                   0, NULL);
624                goto EXIT;
625            }
626        }
627        break;
628    case OMX_CommandFlush:
629        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
630        if(nParam > 1 && nParam != -1) {
631            eError = OMX_ErrorBadPortIndex;
632            goto EXIT;
633        }
634
635        break;
636    case OMX_CommandPortDisable:
637        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
638        break;
639    case OMX_CommandPortEnable:
640        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
641        break;
642    case OMX_CommandMarkBuffer:
643        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
644        if (nParam > 0) {
645            eError = OMX_ErrorBadPortIndex;
646            goto EXIT;
647        }
648        break;
649    default:
650        G711DEC_DPRINT("%d :: G711DEC: Command Received Default \
651                                                      error\n",__LINE__);
652        pCompPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
653                                           OMX_EventError, OMX_ErrorUndefined,0,
654                                           "Invalid Command");
655        break;
656
657    }
658
659    G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
660    nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
661
662    if (nRet == -1) {
663        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
664        eError = OMX_ErrorInsufficientResources;
665        goto EXIT;
666    }
667
668    if (Cmd == OMX_CommandMarkBuffer) {
669        nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
670    }
671    else {
672        nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32));
673    }
674
675    G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
676    G711DEC_DPRINT ("%d:::nRet = %d\n",__LINE__,nRet);
677    if (nRet == -1) {
678        G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
679        eError = OMX_ErrorInsufficientResources;
680        goto EXIT;
681    }
682
683#ifdef DSP_RENDERING_ON
684    if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting)
685    {
686        /* enable Tee device command*/
687        cmd_data.hComponent = pHandle;
688        cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode;
689        cmd_data.param1 = 0;
690        cmd_data.param2 = 0;
691        cmd_data.streamID = 0;
692        if((write(pCompPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
693        {
694            eError = OMX_ErrorHardware;
695            goto EXIT;
696        }
697    }
698#endif
699
700 EXIT:
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    G711DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
722    OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL;
723
724    G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
725    G711DEC_DPRINT("%d :: Inside the GetParameter:: %x\n",__LINE__,nParamIndex);
726
727    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
728    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
729
730    if (pParameterStructure == NULL) {
731        eError = OMX_ErrorBadParameter;
732        goto EXIT;
733
734    }
735
736    G711DEC_DPRINT("pParameterStructure = %p\n",pParameterStructure);
737    G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
738
739    if(pComponentPrivate->curState == OMX_StateInvalid) {
740        pComponentPrivate->cbInfo.EventHandler(
741                                               hComp,
742                                               ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate,
743                                               OMX_EventError,
744                                               OMX_ErrorIncorrectStateOperation,
745                                               0, NULL);
746
747        G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
748    }
749
750    G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
751
752    switch(nParamIndex){
753
754    case OMX_IndexParamAudioInit:
755        G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
756        G711DEC_DPRINT ("OMX_IndexParamAudioInit\n");
757        memcpy(ComponentParameterStructure,
758               &pComponentPrivate->sPortParam,
759               sizeof(OMX_PORT_PARAM_TYPE));
760        break;
761
762    case OMX_IndexParamPortDefinition:
763        G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
764        G711DEC_DPRINT ("pParameterStructure->nPortIndex = %d\n",(int)pParameterStructure->nPortIndex);
765        G711DEC_DPRINT ("pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex = %d\n",(int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex);
766
767        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
768           pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex)
769        {
770            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
771
772            memcpy(ComponentParameterStructure,
773                   pComponentPrivate->pPortDef[G711DEC_INPUT_PORT],
774                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
775
776            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
777
778        } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
779                  pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex)
780        {
781            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
782
783            memcpy(ComponentParameterStructure,
784                   pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT],
785                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
786            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
787
788        } else {
789            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
790            eError = OMX_ErrorBadPortIndex;
791        }
792        break;
793
794    case OMX_IndexParamAudioPortFormat:
795        G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
796        G711DEC_DPRINT ("((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex = %d\n",(int)((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex);
797        G711DEC_DPRINT ("pComponentPrivate->sInPortFormat.nPortIndex= %d\n",(int)pComponentPrivate->sInPortFormat.nPortIndex );
798        G711DEC_DPRINT ("pComponentPrivate->sOutPortFormat.nPortIndex= %d\n",(int)pComponentPrivate->sOutPortFormat.nPortIndex);
799
800        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
801           pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex)
802        {
803
804            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
805
806            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
807               pComponentPrivate->sInPortFormat.nIndex)
808            {
809                eError = OMX_ErrorNoMore;
810            }
811
812            else{
813                memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat,
814                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
815            }
816        }
817        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
818                pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex){
819
820            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
821
822            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
823               pComponentPrivate->sOutPortFormat.nIndex)
824            {
825                G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
826                eError = OMX_ErrorNoMore;
827            }
828            else{
829                G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
830                memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat,
831                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
832            }
833        }
834        else{
835            G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
836            eError = OMX_ErrorBadPortIndex;
837        }
838        break;
839
840    case OMX_IndexParamAudioPcm:
841        G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
842        if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
843           pComponentPrivate->g711Params[G711DEC_INPUT_PORT]->nPortIndex){
844            G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
845            memcpy(ComponentParameterStructure,
846                   pComponentPrivate->g711Params[G711DEC_INPUT_PORT],
847                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
848
849        } else if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
850                  pComponentPrivate->g711Params[G711DEC_OUTPUT_PORT]->nPortIndex){
851            G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
852            memcpy(ComponentParameterStructure,
853                   pComponentPrivate->g711Params[G711DEC_OUTPUT_PORT],
854                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
855
856        } else {
857            eError = OMX_ErrorBadPortIndex;
858        }
859        break;
860
861    case OMX_IndexParamCompBufferSupplier:
862        if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) {
863            G711DEC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
864        }
865        else
866            if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) {
867                G711DEC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
868            }
869            else {
870                G711DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter");
871                eError = OMX_ErrorBadPortIndex;
872            }
873        break;
874
875    case OMX_IndexParamPriorityMgmt:
876        break;
877
878    case OMX_IndexParamVideoInit:
879        break;
880
881    case OMX_IndexParamImageInit:
882        break;
883
884    case OMX_IndexParamOtherInit:
885        break;
886
887
888    default:
889        eError = OMX_ErrorUnsupportedIndex;
890        break;
891    }
892 EXIT:
893    G711DEC_DPRINT("%d :: Exiting GetParameter:: %x\n",__LINE__,nParamIndex);
894    return eError;
895}
896
897/*-------------------------------------------------------------------*/
898/**
899 *  SetParameter() Sets configuration paramets to the component
900 *
901 * @param hComp         handle for this instance of the component
902 * @param nParamIndex
903 * @param pCompParam
904 *
905 * @retval OMX_NoError              Success, ready to roll
906 *         OMX_Error_BadParameter   The input parameter pointer is null
907 **/
908/*-------------------------------------------------------------------*/
909
910static OMX_ERRORTYPE    SetParameter (OMX_HANDLETYPE hComp,
911                                      OMX_INDEXTYPE nParamIndex,
912                                      OMX_PTR pCompParam)
913{
914    OMX_ERRORTYPE eError = OMX_ErrorNone;
915
916    OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
917    OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
918    G711DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
919
920    OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL;
921    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
922    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
923
924    if (pCompParam == NULL) {
925        eError = OMX_ErrorBadParameter;
926        goto EXIT;
927    }
928
929    switch(nParamIndex) {
930    case OMX_IndexParamAudioPortFormat:
931        G711DEC_DPRINT("%d :: SetParameter OMX_IndexParamAudioPortFormat \n",__LINE__);
932        pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
933        if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat->nPortIndex )
934        {
935            memcpy(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
936        }
937        else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat->nPortIndex )
938        {
939            memcpy(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
940        }
941        else
942        {
943            G711DEC_DPRINT("%d :: OMX_ErrorBadPortIndex from SetParameter",__LINE__);
944            eError = OMX_ErrorBadPortIndex;
945        }
946
947        break;
948    case OMX_IndexParamAudioPcm:
949        {
950            OMX_AUDIO_PARAM_PCMMODETYPE *pCompG711Param =
951                (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
952
953            /* Input port */
954            if(pCompG711Param->nPortIndex == OMX_DirInput) {
955                memcpy(((G711DEC_COMPONENT_PRIVATE*)
956                        pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT],
957                       pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
958
959            } else if (pCompG711Param->nPortIndex == OMX_DirOutput) {
960                /* Output port */
961                memcpy(((G711DEC_COMPONENT_PRIVATE *)
962                        pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT],
963                       pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
964            }
965            else {
966                eError = OMX_ErrorBadPortIndex;
967            }
968        }
969        break;
970    case OMX_IndexParamPortDefinition:
971        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
972           pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex) {
973
974            memcpy(pComponentPrivate->pPortDef[G711DEC_INPUT_PORT],
975                   pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
976
977        }
978        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
979                pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex) {
980
981            memcpy(pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT],
982                   pCompParam,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
983
984        }
985        else {
986            eError = OMX_ErrorBadPortIndex;
987        }
988        break;
989
990    case OMX_IndexParamPriorityMgmt:
991        if (pComponentPrivate->curState != OMX_StateLoaded) {
992            eError = OMX_ErrorIncorrectStateOperation;
993        }
994        break;
995
996    case OMX_IndexParamStandardComponentRole:
997        if (pCompParam) {
998            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
999            memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1000        } else {
1001            eError = OMX_ErrorBadParameter;
1002        }
1003        break;
1004
1005    case OMX_IndexParamCompBufferSupplier:
1006        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1007           pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex) {
1008            G711DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1009            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
1010            memcpy(&sBufferSupplier, pCompParam,
1011                   sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1012        }
1013        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1014                pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex) {
1015            G711DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1016            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
1017            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1018        }
1019        else {
1020            G711DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
1021            eError = OMX_ErrorBadPortIndex;
1022        }
1023        break;
1024
1025    default:
1026        break;
1027
1028    }
1029 EXIT:
1030    return eError;
1031}
1032/*-------------------------------------------------------------------*/
1033/**
1034 *  GetConfig() Gets the current configuration of to the component
1035 *
1036 * @param hComp         handle for this instance of the component
1037 * @param nConfigIndex
1038 * @param ComponentConfigStructure
1039 *
1040 * @retval OMX_NoError              Success, ready to roll
1041 *         OMX_Error_BadParameter   The input parameter pointer is null
1042 **/
1043/*-------------------------------------------------------------------*/
1044
1045static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1046                                OMX_INDEXTYPE nConfigIndex,
1047                                OMX_PTR ComponentConfigStructure)
1048{
1049    OMX_ERRORTYPE eError = OMX_ErrorNone;
1050
1051    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1052
1053    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1054        (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1055    if ((pComponentPrivate != NULL) && (ComponentConfigStructure != NULL))
1056        memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G711DEC_COMPONENT_PRIVATE));
1057
1058    return eError;
1059}
1060/*-------------------------------------------------------------------*/
1061/**
1062 *  SetConfig() Sets the configraiton to the component
1063 *
1064 * @param hComp         handle for this instance of the component
1065 * @param nConfigIndex
1066 * @param ComponentConfigStructure
1067 *
1068 * @retval OMX_NoError              Success, ready to roll
1069 *         OMX_Error_BadParameter   The input parameter pointer is null
1070 **/
1071/*-------------------------------------------------------------------*/
1072
1073static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1074                                OMX_INDEXTYPE nConfigIndex,
1075                                OMX_PTR ComponentConfigStructure)
1076{
1077    OMX_ERRORTYPE eError = OMX_ErrorNone;
1078    OMX_S16* deviceString = NULL;
1079    TI_OMX_DATAPATH dataPath;
1080    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1081    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1082
1083    int *customFlag = NULL;
1084    TI_OMX_DSP_DEFINITION *configData = NULL;
1085    G711DEC_FTYPES *confFrameParams = NULL;
1086    OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
1087    OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
1088
1089    G711DEC_DPRINT("%d :: Entering SetConfig\n", __LINE__);
1090
1091    if (pHandle == NULL) {
1092        G711DEC_DPRINT ("%d :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__);
1093        eError = OMX_ErrorBadParameter;
1094        goto EXIT;
1095    }
1096
1097    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1098    switch (nConfigIndex) {
1099    case  OMX_IndexCustomG711DecHeaderInfoConfig:
1100        {
1101            G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecHeaderInfoConfig \n",__LINE__);
1102            configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1103            if (configData == NULL) {
1104                eError = OMX_ErrorBadParameter;
1105                G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1106                goto EXIT;
1107            }
1108            pComponentPrivate->acdnmode = configData->acousticMode;
1109            pComponentPrivate->dasfmode = configData->dasfMode;
1110
1111            if (pComponentPrivate->dasfmode ){
1112                pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled = 0;
1113            }
1114
1115            pComponentPrivate->streamID = configData->streamId;
1116            G711DEC_DPRINT("pComponentPrivate->acdnmode = %d\n",pComponentPrivate->acdnmode);
1117            G711DEC_DPRINT("pComponentPrivate->dasfmode = %d\n",pComponentPrivate->dasfmode);
1118
1119            break;
1120        }
1121    case OMX_IndexCustomG711DecModeAcdnConfig:
1122        {
1123            G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecModeAcdnConfig \n",__LINE__);
1124            customFlag = (int*)ComponentConfigStructure;
1125            if (customFlag == NULL) {
1126                eError = OMX_ErrorBadParameter;
1127                G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1128                goto EXIT;
1129            }
1130            pComponentPrivate->acdnmode = *customFlag;
1131            G711DEC_DPRINT("pComponentPrivate->acdnmode = %d\n",pComponentPrivate->acdnmode);
1132            break;
1133        }
1134    case OMX_IndexCustomG711DecModeDasfConfig:
1135        {
1136            G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecModeDasfConfig \n",__LINE__);
1137            customFlag = (int*)ComponentConfigStructure;
1138            if (customFlag == NULL) {
1139                eError = OMX_ErrorBadParameter;
1140                G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1141                goto EXIT;
1142            }
1143            pComponentPrivate->dasfmode = *customFlag;
1144            G711DEC_DPRINT("pComponentPrivate->dasfmode = %d\n",pComponentPrivate->dasfmode);
1145            if (pComponentPrivate->dasfmode ){
1146                pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled = 0;
1147            }
1148            break;
1149        }
1150
1151    case OMX_IndexCustomG711DecFrameParams:
1152        {
1153            confFrameParams = (G711DEC_FTYPES*)ComponentConfigStructure;
1154            pComponentPrivate->ftype = confFrameParams->FrameSizeType;
1155            pComponentPrivate->nmulevel = confFrameParams->NmuNLvl;
1156            pComponentPrivate->noiselp = confFrameParams->NoiseLp;
1157            pComponentPrivate->dbmnoise = confFrameParams->dBmNoise;
1158            pComponentPrivate->packetlostc = confFrameParams->plc;
1159            break;
1160        }
1161
1162    case  OMX_IndexCustomG711DecDataPath:
1163        deviceString = (OMX_S16*)ComponentConfigStructure;
1164        if (deviceString == NULL)
1165        {
1166            eError = OMX_ErrorBadParameter;
1167            goto EXIT;
1168        }
1169
1170        dataPath = *deviceString;
1171
1172        switch(dataPath)
1173        {
1174        case DATAPATH_APPLICATION:
1175            OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID);
1176            break;
1177
1178        case DATAPATH_APPLICATION_RTMIXER:
1179            strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1180            break;
1181
1182        case DATAPATH_ACDN:
1183            strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1184            break;
1185
1186        default:
1187            break;
1188        }
1189        break;
1190
1191#ifdef DSP_RENDERING_ON
1192    case OMX_IndexConfigAudioMute:
1193        {
1194            pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure;
1195            G711DEC_PRINT("Set Mute/Unmute for playback stream\n");
1196            cmd_data.hComponent = hComp;
1197            if(pMuteStructure->bMute == OMX_TRUE)
1198            {
1199                G711DEC_PRINT("Mute the playback stream\n");
1200                cmd_data.AM_Cmd = AM_CommandStreamMute;
1201            }
1202            else
1203            {
1204                G711DEC_PRINT("unMute the playback stream\n");
1205                cmd_data.AM_Cmd = AM_CommandStreamUnMute;
1206            }
1207            cmd_data.param1 = 0;
1208            cmd_data.param2 = 0;
1209            cmd_data.streamID = pComponentPrivate->streamID;
1210            if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1211            {
1212                G711DEC_DPRINT("[G711 decoder] - fail to send Mute command to audio manager\n");
1213                G711DEC_PRINT("No pudo escribir al Pipe del Audio Manager\n");
1214            }
1215
1216            break;
1217        }
1218    case OMX_IndexConfigAudioVolume:
1219        {
1220            pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
1221            G711DEC_PRINT("Set volume for playback stream\n");
1222            cmd_data.hComponent = hComp;
1223            cmd_data.AM_Cmd = AM_CommandSWGain;
1224            cmd_data.param1 = pVolumeStructure->sVolume.nValue;
1225            cmd_data.param2 = 0;
1226            cmd_data.streamID = pComponentPrivate->streamID;
1227
1228            if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1229            {
1230                G711DEC_DPRINT("[G711 decoder] - fail to send Volume command to audio manager\n");
1231            }
1232
1233            break;
1234        }
1235#endif
1236    default:
1237        eError = OMX_ErrorUnsupportedIndex;
1238        break;
1239    }
1240 EXIT:
1241    G711DEC_DPRINT("%d :: Exiting SetConfig\n", __LINE__);
1242    G711DEC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
1243    return eError;
1244
1245}
1246/*-------------------------------------------------------------------*/
1247/**
1248 *  GetState() Gets the current state of the component
1249 *
1250 * @param pCompomponent handle for this instance of the component
1251 * @param pState
1252 *
1253 * @retval OMX_NoError              Success, ready to roll
1254 *         OMX_Error_BadParameter   The input parameter pointer is null
1255 **/
1256/*-------------------------------------------------------------------*/
1257
1258static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1259{
1260    OMX_ERRORTYPE error = OMX_ErrorUndefined;
1261    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1262
1263    if (!pState) {
1264        error = OMX_ErrorBadParameter;
1265        G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1266        goto EXIT;
1267    }
1268
1269    if (pHandle && pHandle->pComponentPrivate) {
1270        *pState =  ((G711DEC_COMPONENT_PRIVATE*)
1271                    pHandle->pComponentPrivate)->curState;
1272    } else {
1273        *pState = OMX_StateLoaded;
1274    }
1275
1276    error = OMX_ErrorNone;
1277
1278 EXIT:
1279    return error;
1280}
1281
1282/*-------------------------------------------------------------------*/
1283/**
1284 *  EmptyThisBuffer() This callback is used to send the input buffer to
1285 *  component
1286 *
1287 * @param pComponent       handle for this instance of the component
1288 * @param nPortIndex       input port index
1289 * @param pBuffer          buffer to be sent to codec
1290 *
1291 * @retval OMX_NoError              Success, ready to roll
1292 *         OMX_Error_BadParameter   The input parameter pointer is null
1293 **/
1294/*-------------------------------------------------------------------*/
1295
1296static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1297                                      OMX_BUFFERHEADERTYPE* pBuffer)
1298{
1299    OMX_ERRORTYPE eError = OMX_ErrorNone;
1300    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1301    G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1302        (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1303
1304    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1305
1306    ssize_t ret = 0;
1307    pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1308                pComponentPrivate)->pPortDef[G711DEC_INPUT_PORT];
1309
1310    if(!pPortDef->bEnabled) {
1311        G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1312        eError = OMX_ErrorIncorrectStateOperation;
1313        goto EXIT;
1314    }
1315
1316    if (pBuffer == NULL) {
1317        eError = OMX_ErrorBadParameter;
1318        G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1319        goto EXIT;
1320    }
1321
1322    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1323        eError = OMX_ErrorBadParameter;
1324        goto EXIT;
1325    }
1326
1327    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1328        eError = OMX_ErrorVersionMismatch;
1329        goto EXIT;
1330    }
1331
1332    if (pBuffer->nInputPortIndex != G711DEC_INPUT_PORT) {
1333        eError  = OMX_ErrorBadPortIndex;
1334        goto EXIT;
1335    }
1336
1337    G711DEC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
1338
1339    if(pComponentPrivate->curState != OMX_StateExecuting &&
1340       pComponentPrivate->curState != OMX_StatePause) {
1341        G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1342        eError = OMX_ErrorIncorrectStateOperation;
1343        goto EXIT;
1344    }
1345
1346    G711DEC_DPRINT("\n------------------------------------------\n\n");
1347    G711DEC_DPRINT ("%d :: Component Sending Filled ip buff %p \
1348                             to Component Thread\n",__LINE__,pBuffer);
1349    G711DEC_DPRINT("\n------------------------------------------\n\n");
1350
1351    pComponentPrivate->app_nBuf--;
1352
1353    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1354    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1355
1356    ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1357                 sizeof(OMX_BUFFERHEADERTYPE*));
1358
1359    if (ret == -1) {
1360        G711DEC_DPRINT ("%d :: Error in Writing to the Data pipe\n", __LINE__);
1361        eError = OMX_ErrorHardware;
1362        goto EXIT;
1363    }
1364    pComponentPrivate->nEmptyThisBufferCount++;
1365
1366 EXIT:
1367    return eError;
1368}
1369/*-------------------------------------------------------------------*/
1370/**
1371 *  FillThisBuffer() This callback is used to send the output buffer to
1372 *  the component
1373 *
1374 * @param pComponent    handle for this instance of the component
1375 * @param nPortIndex    output port number
1376 * @param pBuffer       buffer to be sent to codec
1377 *
1378 * @retval OMX_NoError              Success, ready to roll
1379 *         OMX_Error_BadParameter   The input parameter pointer is null
1380 **/
1381/*-------------------------------------------------------------------*/
1382
1383static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1384                                     OMX_BUFFERHEADERTYPE* pBuffer)
1385{
1386    OMX_ERRORTYPE eError = OMX_ErrorNone;
1387    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1388    G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1389        (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1390
1391    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1392    G711DEC_DPRINT("\n------------------------------------------\n\n");
1393    G711DEC_DPRINT ("%d :: Component Sending Emptied op buff %p \
1394                             to Component Thread\n",__LINE__,pBuffer);
1395    G711DEC_DPRINT("\n------------------------------------------\n\n");
1396
1397    pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1398                pComponentPrivate)->pPortDef[G711DEC_OUTPUT_PORT];
1399
1400    if(!pPortDef->bEnabled) {
1401        G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1402        eError = OMX_ErrorIncorrectStateOperation;
1403        goto EXIT;
1404    }
1405
1406    if (pBuffer == NULL) {
1407        eError = OMX_ErrorBadParameter;
1408        G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1409        goto EXIT;
1410    }
1411
1412    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1413        eError = OMX_ErrorBadParameter;
1414        goto EXIT;
1415    }
1416
1417
1418    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1419        eError = OMX_ErrorVersionMismatch;
1420        goto EXIT;
1421    }
1422
1423    if (pBuffer->nOutputPortIndex != G711DEC_OUTPUT_PORT) {
1424        eError  = OMX_ErrorBadPortIndex;
1425        goto EXIT;
1426    }
1427
1428    G711DEC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
1429
1430    if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
1431        G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1432        eError = OMX_ErrorIncorrectStateOperation;
1433        goto EXIT;
1434    }
1435
1436    G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1437
1438    pBuffer->nFilledLen = 0;
1439
1440    G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1441
1442    /*Filling the Output buffer with zero */
1443#ifndef UNDER_CE
1444    memset (pBuffer->pBuffer,0,OUTPUT_G711DEC_BUFFER_SIZE);
1445#else
1446    memset (pBuffer->pBuffer,0,pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nBufferSize);
1447#endif
1448    G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1449
1450    pComponentPrivate->app_nBuf--;
1451
1452    G711DEC_DPRINT("%d:Decrementing app_nBuf = %d\n",__LINE__,(int)pComponentPrivate->app_nBuf);
1453    G711DEC_DPRINT("pComponentPrivate->pMarkBuf = 0x%x\n",(int)pComponentPrivate->pMarkBuf);
1454    G711DEC_DPRINT("pComponentPrivate->pMarkData = 0x%x\n",(int)pComponentPrivate->pMarkData);
1455
1456    if(pComponentPrivate->pMarkBuf){
1457        G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1458        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1459        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1460        pComponentPrivate->pMarkBuf = NULL;
1461    }
1462
1463    if (pComponentPrivate->pMarkData) {
1464        G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1465        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1466        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1467        pComponentPrivate->pMarkData = NULL;
1468    }
1469
1470    write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof (OMX_BUFFERHEADERTYPE*));
1471    pComponentPrivate->nFillThisBufferCount++;
1472
1473 EXIT:
1474    return eError;
1475}
1476/*-------------------------------------------------------------------*/
1477/**
1478 * OMX_ComponentDeinit() this methold will de init the component
1479 *
1480 * @param pComp         handle for this instance of the component
1481 *
1482 * @retval OMX_NoError              Success, ready to roll
1483 *         OMX_Error_BadParameter   The input parameter pointer is null
1484 **/
1485/*-------------------------------------------------------------------*/
1486
1487static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1488{
1489    OMX_ERRORTYPE eError = OMX_ErrorNone;
1490
1491    /* inform audio manager to remove the streamID*/
1492    /* compose the data */
1493    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1494    G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1495        (G711DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1496
1497    G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1498
1499#ifdef DSP_RENDERING_ON
1500    close(pComponentPrivate->fdwrite);
1501    close(pComponentPrivate->fdread);
1502#endif
1503
1504    OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1505
1506#ifdef RESOURCE_MANAGER_ENABLED
1507    RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource,
1508                           OMX_G711_Decoder_COMPONENT,
1509                           0, 1234, NULL);
1510    if (eError != OMX_ErrorNone) {
1511        G711DEC_DPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1512                        __LINE__);
1513    }
1514    eError = RMProxy_Deinitalize();
1515    if (eError != OMX_ErrorNone) {
1516        G711DEC_DPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1517                        __LINE__);
1518    }
1519#endif
1520    G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1521
1522    G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1523    pComponentPrivate->bIsStopping = 1;
1524    eError = G711DEC_StopComponentThread(pHandle);
1525    G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1526    /* Wait for thread to exit so we can get the status into "error" */
1527
1528    /* close the pipe handles */
1529    G711DEC_FreeCompResources(pHandle);
1530    G711DEC_DPRINT ("%d ::After G711DEC_FreeCompResources\n",__LINE__);
1531    OMX_G711DECMEMFREE_STRUCT(pComponentPrivate);
1532    G711DEC_DPRINT ("%d ::After free(pComponentPrivate)\n",__LINE__);
1533
1534    return eError;
1535}
1536
1537/*-------------------------------------------------------------------*/
1538/**
1539 *  ComponentTunnelRequest() this method is not implemented in 1.5
1540 *
1541 * This method will update application callbacks
1542 * the application.
1543 *
1544 * @param pComp         handle for this instance of the component
1545 * @param pCallBacks    application callbacks
1546 * @param ptr
1547 *
1548 * @retval OMX_NoError              Success, ready to roll
1549 *         OMX_Error_BadParameter   The input parameter pointer is null
1550 **/
1551/*-------------------------------------------------------------------*/
1552
1553static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1554                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1555                                             OMX_U32 nTunneledPort,
1556                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1557{
1558    OMX_ERRORTYPE eError = OMX_ErrorNone;
1559    G711DEC_DPRINT (stderr, "Inside the ComponentTunnelRequest\n");
1560    eError = OMX_ErrorNotImplemented;
1561    return eError;
1562}
1563
1564/*-------------------------------------------------------------------*/
1565/**
1566 *  AllocateBuffer()
1567
1568 * @param pComp         handle for this instance of the component
1569 * @param pCallBacks    application callbacks
1570 * @param ptr
1571 *
1572 * @retval OMX_NoError              Success, ready to roll
1573 *         OMX_Error_BadParameter   The input parameter pointer is null
1574 **/
1575/*-------------------------------------------------------------------*/
1576
1577static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1578                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1579                                     OMX_IN OMX_U32 nPortIndex,
1580                                     OMX_IN OMX_PTR pAppPrivate,
1581                                     OMX_IN OMX_U32 nSizeBytes)
1582
1583{
1584    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1585    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1586    OMX_ERRORTYPE eError = OMX_ErrorNone;
1587    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1588
1589    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1590        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1591
1592    pPortDef = ((G711DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1593
1594    G711DEC_DPRINT ("%d :: pPortDef = 0x%x\n", __LINE__,(unsigned int)pPortDef);
1595    G711DEC_DPRINT("%d :: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled);
1596    G711DEC_DPRINT("pPortDef->bEnabled = %d\n", pPortDef->bEnabled);
1597
1598    if(!pPortDef->bEnabled){
1599        G711DEC_DPRINT ("%d :: BLOCK!! AlloBuf_threshold\n", __LINE__);
1600        pComponentPrivate->AlloBuf_waitingsignal = 1;
1601#ifndef UNDER_CE
1602        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1603        pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold,
1604                          &pComponentPrivate->AlloBuf_mutex);
1605        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1606#else
1607        OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1608#endif
1609    }
1610
1611    G711D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1612    G711D_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, (nSizeBytes + EXTRA_BUFFBYTES), OMX_U8 );
1613
1614#ifdef UNDER_CE
1615    memset(pBufferHeader->pBuffer, 0, (nSizeBytes + EXTRA_BUFFBYTES));
1616#endif
1617
1618    pBufferHeader->pBuffer += CACHE_ALIGNMENT;
1619
1620    if (nPortIndex == G711DEC_INPUT_PORT) {
1621        pBufferHeader->nInputPortIndex = nPortIndex;
1622        pBufferHeader->nOutputPortIndex = -1;
1623        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1624        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1625        G711DEC_DPRINT("pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p \n",(int)pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1626        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1627        G711DEC_DPRINT("Allocate Buffer Line %d\n",__LINE__);
1628        G711DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %d\n",(int)pComponentPrivate->pInputBufferList->numBuffers);
1629        G711DEC_DPRINT("pPortDef->nBufferCountMin = %d\n",(int)pPortDef->nBufferCountMin);
1630        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1631            G711DEC_DPRINT("Setting pPortDef->bPopulated = OMX_TRUE for input port\n");
1632            pPortDef->bPopulated = OMX_TRUE;
1633        }
1634    }
1635    else if (nPortIndex == G711DEC_OUTPUT_PORT) {
1636        pBufferHeader->nInputPortIndex = -1;
1637        pBufferHeader->nOutputPortIndex = nPortIndex;
1638        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1639        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1640        G711DEC_DPRINT("pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p \n",(int)pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1641        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1642        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1643            G711DEC_DPRINT("Setting pPortDef->bPopulated = OMX_TRUE for input port\n");
1644            pPortDef->bPopulated = OMX_TRUE;
1645        }
1646    }
1647    else {
1648        eError = OMX_ErrorBadPortIndex;
1649        goto EXIT;
1650    }
1651    if((pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated ==
1652        pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled) &&
1653       (pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated ==
1654        pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled) &&
1655       (pComponentPrivate->InLoaded_readytoidle))
1656    {
1657        pComponentPrivate->InLoaded_readytoidle = 0;
1658#ifndef UNDER_CE
1659        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1660        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1661        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1662#else
1663        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1664#endif
1665    }
1666
1667    pBufferHeader->pAppPrivate = pAppPrivate;
1668    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1669    pBufferHeader->nAllocLen = nSizeBytes;
1670    pBufferHeader->nVersion.s.nVersionMajor = G711DEC_MAJOR_VER;
1671    pBufferHeader->nVersion.s.nVersionMinor = G711DEC_MINOR_VER;
1672    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1673
1674
1675    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1676    *pBuffer = pBufferHeader;
1677
1678    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
1679    {
1680        SendCommand(pComponentPrivate->pHandle,
1681                    OMX_CommandPortEnable,
1682                    pComponentPrivate->bEnableCommandParam,
1683                    NULL);
1684    }
1685
1686 EXIT:
1687    G711DEC_DPRINT("AllocateBuffer returning %d\n",eError);
1688    return eError;
1689}
1690
1691/*------------------------------------------------------------------*/
1692/**
1693 *  FreeBuffer()
1694
1695 * @param hComponent   handle for this instance of the component
1696 * @param pCallBacks   application callbacks
1697 * @param ptr
1698 *
1699 * @retval OMX_NoError              Success, ready to roll
1700 *         OMX_Error_BadParameter   The input parameter pointer is null
1701 **/
1702/*-------------------------------------------------------------------*/
1703static OMX_ERRORTYPE FreeBuffer(
1704                                OMX_IN  OMX_HANDLETYPE hComponent,
1705                                OMX_IN  OMX_U32 nPortIndex,
1706                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1707{
1708    OMX_ERRORTYPE eError = OMX_ErrorNone;
1709    G711DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1710    OMX_BUFFERHEADERTYPE* buff = NULL;
1711    OMX_U8* tempBuff = NULL;
1712    OMX_S16 i = 0;
1713    OMX_S16 inputIndex = -1;
1714    OMX_S16 outputIndex = -1;
1715    OMX_COMPONENTTYPE *pHandle = NULL;
1716
1717    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1718        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1719
1720    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
1721    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1722        buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
1723        if (buff == pBuffer) {
1724            G711DEC_DPRINT("Found matching input buffer\n");
1725            G711DEC_DPRINT("buff = %p\n",buff);
1726            G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1727            inputIndex = i;
1728            break;
1729        }
1730        else {
1731            G711DEC_DPRINT("This is not a match\n");
1732            G711DEC_DPRINT("buff = %p\n",buff);
1733            G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1734        }
1735    }
1736
1737    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1738        buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
1739        if (buff == pBuffer) {
1740            G711DEC_DPRINT("Found matching output buffer\n");
1741            G711DEC_DPRINT("buff = %p\n",buff);
1742            G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1743            outputIndex = i;
1744            break;
1745        }
1746        else {
1747            G711DEC_DPRINT("This is not a match\n");
1748            G711DEC_DPRINT("buff = %p\n",buff);
1749            G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1750        }
1751    }
1752
1753
1754    if (inputIndex != -1) {
1755        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
1756            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
1757            tempBuff -= CACHE_ALIGNMENT;
1758            OMX_G711DECMEMFREE_STRUCT(tempBuff);
1759        }
1760        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1761        pComponentPrivate->pInputBufferList->numBuffers--;
1762        G711DEC_DPRINT("INPUT :: numBuffers %d, nBufferCountActual %d\n",
1763                       (int)pComponentPrivate->pInputBufferList->numBuffers,
1764                       (int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual);
1765        if (pComponentPrivate->pInputBufferList->numBuffers <
1766            pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual) {
1767            G711DEC_DPRINT("setting input port populated to OMX_FALSE\n");
1768            pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated = OMX_FALSE;
1769        }
1770        if(pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled &&
1771           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1772           (pComponentPrivate->curState == OMX_StateIdle ||
1773            pComponentPrivate->curState == OMX_StateExecuting ||
1774            pComponentPrivate->curState == OMX_StatePause))
1775        {
1776            pComponentPrivate->cbInfo.EventHandler(pHandle,
1777                                                   pHandle->pApplicationPrivate,
1778                                                   OMX_EventError,
1779                                                   OMX_ErrorPortUnpopulated,
1780                                                   nPortIndex, NULL);
1781        }
1782    }
1783    else if (outputIndex != -1) {
1784        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
1785            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
1786            tempBuff -= CACHE_ALIGNMENT;
1787            OMX_G711DECMEMFREE_STRUCT(tempBuff);
1788        }
1789
1790        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1791        pComponentPrivate->pOutputBufferList->numBuffers--;
1792        G711DEC_DPRINT("OUTPUT :: numBuffers %d, nBufferCountActual %d\n",
1793                       (int)pComponentPrivate->pInputBufferList->numBuffers,
1794                       (int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual);
1795
1796        if (pComponentPrivate->pOutputBufferList->numBuffers <
1797            pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nBufferCountActual) {
1798            G711DEC_DPRINT("setting output port populated to OMX_FALSE\n");
1799            pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated = OMX_FALSE;
1800        }
1801
1802        if(pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled &&
1803           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1804           (pComponentPrivate->curState == OMX_StateIdle ||
1805            pComponentPrivate->curState == OMX_StateExecuting ||
1806            pComponentPrivate->curState == OMX_StatePause))
1807        {
1808            pComponentPrivate->cbInfo.EventHandler(
1809                                                   pHandle, pHandle->pApplicationPrivate,
1810                                                   OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1811        }
1812    }
1813    else {
1814        G711DEC_DPRINT("%d::Returning OMX_ErrorBadParameter\n",__LINE__);
1815        eError = OMX_ErrorBadParameter;
1816    }
1817
1818    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
1819         !pComponentPrivate->pOutputBufferList->numBuffers) &&
1820        pComponentPrivate->InIdle_goingtoloaded)
1821    {
1822        pComponentPrivate->InIdle_goingtoloaded = 0;
1823#ifndef UNDER_CE
1824        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1825        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
1826        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1827#else
1828        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
1829#endif
1830    }
1831    /* Removing sleep() calls.  There are no allocated buffers. */
1832
1833    G711DEC_DPRINT("pComponentPrivate->bDisableCommandPending = %d\n",(int)pComponentPrivate->bDisableCommandPending);
1834    if (pComponentPrivate->bDisableCommandPending) {
1835        if (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0) {
1836            SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL);
1837        }
1838    }
1839    G711DEC_DPRINT ("%d :: Exiting FreeBuffer\n", __LINE__);
1840    return eError;
1841}
1842
1843/*-------------------------------------------------------------------*/
1844/**
1845 *  UseBuffer()
1846
1847 * @param pComp         handle for this instance of the component
1848 * @param pCallBacks    application callbacks
1849 * @param ptr
1850 *
1851 * @retval OMX_NoError              Success, ready to roll
1852 *         OMX_Error_BadParameter   The input parameter pointer is null
1853 **/
1854/*-------------------------------------------------------------------*/
1855static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1856                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1857                                OMX_IN OMX_U32 nPortIndex,
1858                                OMX_IN OMX_PTR pAppPrivate,
1859                                OMX_IN OMX_U32 nSizeBytes,
1860                                OMX_IN OMX_U8* pBuffer)
1861{
1862    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1863    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1864    OMX_ERRORTYPE eError = OMX_ErrorNone;
1865    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1866
1867    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1868        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1869
1870    pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1871                pComponentPrivate)->pPortDef[nPortIndex];
1872
1873    G711DEC_DPRINT("pPortDef->bPopulated = %d\n",pPortDef->bPopulated);
1874
1875    if(!pPortDef->bEnabled) {
1876        G711DEC_DPRINT ("%d :: In AllocateBuffer\n", __LINE__);
1877        eError = OMX_ErrorIncorrectStateOperation;
1878        goto EXIT;
1879    }
1880
1881    if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) {
1882        G711DEC_DPRINT ("%d :: In AllocateBuffer\n", __LINE__);
1883        eError = OMX_ErrorBadParameter;
1884        goto EXIT;
1885    }
1886
1887    G711D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1888
1889    if (nPortIndex == G711DEC_OUTPUT_PORT) {
1890        pBufferHeader->nInputPortIndex = -1;
1891        pBufferHeader->nOutputPortIndex = nPortIndex;
1892        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1893        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1894        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
1895        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1896            pPortDef->bPopulated = OMX_TRUE;
1897        }
1898    }
1899    else {
1900        pBufferHeader->nInputPortIndex = nPortIndex;
1901        pBufferHeader->nOutputPortIndex = -1;
1902        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1903        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1904        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
1905
1906        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1907            pPortDef->bPopulated = OMX_TRUE;
1908        }
1909    }
1910
1911    if((pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled)&&
1912       (pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled) &&
1913       (pComponentPrivate->InLoaded_readytoidle))
1914    {
1915        pComponentPrivate->InLoaded_readytoidle = 0;
1916#ifndef UNDER_CE
1917        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1918        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1919        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1920#else
1921        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1922#endif
1923    }
1924
1925    pBufferHeader->pAppPrivate              =   pAppPrivate;
1926    pBufferHeader->pPlatformPrivate         =   pComponentPrivate;
1927    pBufferHeader->nAllocLen                =   nSizeBytes;
1928    pBufferHeader->nVersion.s.nVersionMajor =   G711DEC_MAJOR_VER;
1929    pBufferHeader->nVersion.s.nVersionMinor =   G711DEC_MINOR_VER;
1930    pComponentPrivate->nVersion             =   pBufferHeader->nVersion.nVersion;
1931    pBufferHeader->pBuffer                  =   pBuffer;
1932    pBufferHeader->nSize                    =   sizeof(OMX_BUFFERHEADERTYPE);
1933    *ppBufferHdr                            =   pBufferHeader;
1934
1935    G711DEC_DPRINT("pBufferHeader = %p\n",pBufferHeader);
1936
1937    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
1938    {
1939        SendCommand(pComponentPrivate->pHandle, OMX_CommandPortEnable,
1940                    pComponentPrivate->bEnableCommandParam, NULL);
1941    }
1942
1943 EXIT:
1944    return eError;
1945}
1946
1947/* ================================================================================= */
1948/**
1949 * @fn GetExtensionIndex() description for GetExtensionIndex
1950 GetExtensionIndex().
1951 Returns index for vendor specific settings.
1952 *
1953 *  @see         OMX_Core.h
1954 */
1955/* ================================================================================ */
1956static OMX_ERRORTYPE GetExtensionIndex( OMX_IN  OMX_HANDLETYPE hComponent,
1957                                        OMX_IN  OMX_STRING cParameterName,
1958                                        OMX_OUT OMX_INDEXTYPE *pIndexType)
1959{
1960    OMX_ERRORTYPE eError = OMX_ErrorNone;
1961
1962    if(!(strcmp(cParameterName,"OMX.TI.index.config.g711headerinfo"))) {
1963        *pIndexType = OMX_IndexCustomG711DecHeaderInfoConfig;
1964    }
1965    else if(!(strcmp(cParameterName,"OMX.TI.index.config.g711dec.datapath")))
1966    {
1967        *pIndexType = OMX_IndexCustomG711DecDataPath;
1968    }
1969    else if(!strcmp(cParameterName,"OMX.TI.index.config.g711dec.frameparams"))
1970    {
1971        *pIndexType = OMX_IndexCustomG711DecFrameParams;
1972    }
1973
1974    else
1975    {
1976        eError = OMX_ErrorBadParameter;
1977    }
1978    return eError;
1979}
1980
1981/* ================================================================================= */
1982/**
1983 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
1984
1985 Returns the role at the given index
1986 *
1987 *  @see         OMX_Core.h
1988 */
1989/* ================================================================================ */
1990static OMX_ERRORTYPE ComponentRoleEnum( OMX_IN OMX_HANDLETYPE hComponent,
1991                                        OMX_OUT OMX_U8 *cRole,
1992                                        OMX_IN OMX_U32 nIndex)
1993{
1994    /*G711DEC_COMPONENT_PRIVATE *pComponentPrivate;*/
1995    OMX_ERRORTYPE eError = OMX_ErrorNone;
1996    /* This is a non standard component and does not support roles */
1997    eError = OMX_ErrorNotImplemented;
1998
1999    return eError;
2000}
2001
2002#ifdef G711DEC_MEMDEBUG
2003void * mymalloc(int line, char *s, int size)
2004{
2005    void *p;
2006    int e=0;
2007    p = malloc(size);
2008
2009    if(p==NULL){
2010        G711DEC_PRINT("Memory not available\n");
2011        exit(1);
2012    }
2013    else{
2014        while((lines[e]!=0)&& (e<500) ){
2015            e++;
2016        }
2017        arr[e]=p;
2018        lines[e]=line;
2019        bytes[e]=size;
2020        strcpy(file[e],s);
2021        G711DEC_PRINT("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
2022        return p;
2023    }
2024}
2025
2026void myfree(void *dp, int line, char *s){
2027    int q = 0;
2028    for(q=0;q<500;q++){
2029        if(arr[q]==dp){
2030            G711DEC_PRINT("Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
2031            free(dp);
2032            dp = NULL;
2033            lines[q]=0;
2034            strcpy(file[q],"");
2035            break;
2036        }
2037    }
2038    if(500==q)
2039        G711DEC_PRINT("\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
2040}
2041#endif
2042