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