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