3 * Copyright (C) Texas Instruments - http://www.ti.com/
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.
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.
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
21 /* =============================================================================
22 * Texas Instruments OMAP(TM) Platform Software
23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
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 * ============================================================================ */
29 * @file OMX_AmrDecoder.c
31 * This file implements OMX Component for AMR decoder that
32 * is fully compliant with the OMX Audio specification.
38 /* ----------------------------------------------------------------------------*/
39 /* ------compilation control switches -------------------------*/
40 /****************************************************************
42 ****************************************************************/
43 /* ----- system and platform files ----------------------------*/
52 #include <sys/types.h>
53 #include <sys/ioctl.h>
54 #include <sys/select.h>
65 #ifdef DSP_RENDERING_ON
66 #include <AudioManagerAPI.h>
69 #ifdef RESOURCE_MANAGER_ENABLED
70 #include <ResourceManagerProxyAPI.h>
73 /*-------program files ----------------------------------------*/
74 #include <OMX_Component.h>
77 #include "OMX_AmrDecoder.h"
78 #include "OMX_AmrDec_Utils.h"
80 /* Log for Android system*/
81 #include <utils/Log.h>
83 #define AMRNB_DEC_ROLE "audio_decoder.amrnb"
86 /****************************************************************
87 * EXTERNAL REFERENCES NOTE : only use if not found in header file
88 ****************************************************************/
89 /*--------data declarations -----------------------------------*/
91 /*--------function prototypes ---------------------------------*/
93 /****************************************************************
94 * PUBLIC DECLARATIONS Defined here, used elsewhere
95 ****************************************************************/
96 /*--------data declarations -----------------------------------*/
98 /*--------function prototypes ---------------------------------*/
100 /****************************************************************
101 * PRIVATE DECLARATIONS Defined here, used only here
102 ****************************************************************/
103 /*--------data declarations -----------------------------------*/
105 /*--------function prototypes ---------------------------------*/
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);
115 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
116 OMX_U32 nParam, OMX_PTR pCmdData);
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);
130 static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
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);
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);
146 static OMX_ERRORTYPE FreeBuffer(
147 OMX_IN OMX_HANDLETYPE hComponent,
148 OMX_IN OMX_U32 nPortIndex,
149 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
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);
159 static OMX_ERRORTYPE GetExtensionIndex(
160 OMX_IN OMX_HANDLETYPE hComponent,
161 OMX_IN OMX_STRING cParameterName,
162 OMX_OUT OMX_INDEXTYPE *pIndexType);
164 static OMX_ERRORTYPE ComponentRoleEnum(
165 OMX_IN OMX_HANDLETYPE hComponent,
166 OMX_OUT OMX_U8 *cRole,
167 OMX_IN OMX_U32 nIndex);
169 #ifdef DSP_RENDERING_ON
170 /* ======================================================================= */
172 * @def FIFO1, FIFO2 Define Fifo Path
174 /* ======================================================================= */
175 #define FIFO1 "/dev/fifo.1"
176 #define FIFO2 "/dev/fifo.2"
177 /* ======================================================================= */
179 * @def PERMS Define Read and Write Permisions.
181 /* ======================================================================= */
183 AM_COMMANDDATATYPE cmd_data;
186 /*-------------------------------------------------------------------*/
188 * OMX_ComponentInit() Set the all the function pointers of component
190 * This method will update the component function pointer to the handle
192 * @param hComp handle for this instance of the component
194 * @retval OMX_NoError Success, ready to roll
195 * OMX_ErrorInsufficientResources If the newmalloc fails
197 /*-------------------------------------------------------------------*/
198 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
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;
209 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d ::OMX_ComponentInit\n", __LINE__);
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;
230 /*Allocate the memory for Component private data area */
231 OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, AMRDEC_COMPONENT_PRIVATE);
233 ((AMRDEC_COMPONENT_PRIVATE *)
234 pHandle->pComponentPrivate)->pHandle = pHandle;
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;
242 error = OMX_ErrorNone;
244 OMX_MALLOC_GENERIC(amr_ip , OMX_AUDIO_PARAM_AMRTYPE);
245 OMX_MALLOC_GENERIC(amr_op , OMX_AUDIO_PARAM_PCMMODETYPE);
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;
253 pComponentPrivate = pHandle->pComponentPrivate;
254 OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_NBAMRDEC");
256 #ifdef __PERF_INSTRUMENTATION__
257 pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('N','B','D','_'),
259 PERF_ModuleAudioDecode);
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;
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);
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;
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;
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;
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;
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;
338 pComponentPrivate->IpBufindex = 0;
339 pComponentPrivate->OpBufindex = 0;
340 pComponentPrivate->ptrLibLCML = NULL;
341 pComponentPrivate->PendingPausedBufs = 0;
343 pComponentPrivate->nUnhandledFillThisBuffers=0;
344 pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
345 pComponentPrivate->SendAfterEOS = 0;
347 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
348 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
350 pComponentPrivate->first_buff = 0;
351 pComponentPrivate->first_TS = 0;
352 pComponentPrivate->temp_TS = 0;
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;
361 pComponentPrivate->IpBufindex = 0;
362 pComponentPrivate->OpBufindex = 0;
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;
377 OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, (100*sizeof(char)),OMX_STRING);
378 strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
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;
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;
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);
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;
408 strcpy((char*)pComponentPrivate->componentRole.cRole, "audio_decoder.amrnb");
410 /* Removing sleep() calls. Initialization.*/
412 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
413 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
414 pComponentPrivate->AlloBuf_waitingsignal = 0;
416 pthread_mutex_init(&pComponentPrivate->codecStop_mutex, NULL);
417 pthread_cond_init (&pComponentPrivate->codecStop_threshold, NULL);
418 pComponentPrivate->codecStop_waitingsignal = 0;
420 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
421 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
422 pComponentPrivate->InLoaded_readytoidle = 0;
424 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
425 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
426 pComponentPrivate->InIdle_goingtoloaded = 0;
428 OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
429 pComponentPrivate->AlloBuf_waitingsignal = 0;
431 OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
432 pComponentPrivate->InLoaded_readytoidle = 0;
434 OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
435 pComponentPrivate->InIdle_goingtoloaded = 0;
437 OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
438 OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
440 ((AMRDEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[NBAMRDEC_INPUT_PORT]
443 ((AMRDEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[NBAMRDEC_OUTPUT_PORT]
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;
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;
471 /*sPortFormat->eEncoding = OMX_AUDIO_CodingPCM;*/
472 pComponentPrivate->bIsInvalidState = OMX_FALSE;
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",
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",
493 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::OMX_ComponentInit\n", __LINE__);
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");
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");
508 #ifdef __PERF_INSTRUMENTATION__
509 PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->ComponentThread,
510 PERF_FOURCC('N','B','D','T'));
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__);
521 /*-------------------------------------------------------------------*/
523 * SetCallbacks() Sets application callbacks to the component
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
530 * @param pComponent handle for this instance of the component
531 * @param pCallBacks application callbacks
532 * @param pAppData Application private data
534 * @retval OMX_NoError Success, ready to roll
535 * OMX_Error_BadParameter The input parameter pointer is null
537 /*-------------------------------------------------------------------*/
539 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
540 OMX_CALLBACKTYPE* pCallBacks,
543 OMX_ERRORTYPE eError = OMX_ErrorNone;
545 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
547 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate =
548 (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
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__);
558 /*Copy the callbacks of the application to the component private */
559 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
561 /*copy the application private data to component memory */
562 pHandle->pApplicationPrivate = pAppData;
564 pComponentPrivate->curState = OMX_StateLoaded;
570 /*-------------------------------------------------------------------*/
572 * GetComponentVersion() This will return the component version
574 * This method will retrun the component version
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
582 * @retval OMX_NoError Success, ready to roll
583 * OMX_Error_BadParameter The input parameter pointer is null
585 /*-------------------------------------------------------------------*/
587 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
588 OMX_STRING pComponentName,
589 OMX_VERSIONTYPE* pComponentVersion,
590 OMX_VERSIONTYPE* pSpecVersion,
591 OMX_UUIDTYPE* pComponentUUID)
593 OMX_ERRORTYPE eError = OMX_ErrorNone;
595 eError = OMX_ErrorNotImplemented;
596 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Inside the GetComponentVersion\n");
602 /*-------------------------------------------------------------------*/
604 * SendCommand() used to send the commands to the component
606 * This method will be used by the application.
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
612 * @retval OMX_NoError Success, ready to roll
613 * OMX_Error_BadParameter The input parameter pointer is null
615 /*-------------------------------------------------------------------*/
617 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
619 OMX_U32 nParam,OMX_PTR pCmdData)
621 OMX_ERRORTYPE eError = OMX_ErrorNone;
623 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
624 AMRDEC_COMPONENT_PRIVATE *pCompPrivate =
625 (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
627 OMX_PRINT1(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
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);
632 pCompPrivate->pHandle = phandle;
634 #ifdef _ERROR_PROPAGATION__
635 if (pCompPrivate->curState == OMX_StateInvalid){
636 eError = OMX_ErrorInvalidState;
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,
648 OMX_ErrorInvalidState,
655 #ifdef __PERF_INSTRUMENTATION__
656 PERF_SendingCommand(pCompPrivate->pPERF, Cmd,
657 (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam,
658 PERF_ModuleComponent);
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;
669 if(pCompPrivate->curState == OMX_StateLoaded) {
670 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
671 pCompPrivate->cbInfo.EventHandler (
673 pHandle->pApplicationPrivate,
675 OMX_ErrorIncorrectStateTransition,
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 (
686 pHandle->pApplicationPrivate,
688 OMX_ErrorInvalidState,
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;
703 case OMX_CommandPortDisable:
704 OMX_PRCOMM1(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
706 case OMX_CommandPortEnable:
707 OMX_PRCOMM1(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
709 case OMX_CommandMarkBuffer:
710 OMX_PRCOMM1(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
712 eError = OMX_ErrorBadPortIndex;
717 OMX_ERROR2(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c :: AMRDEC: Command Received Default \
719 pCompPrivate->cbInfo.EventHandler (pHandle,
720 pHandle->pApplicationPrivate,
729 OMX_PRINT2(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
730 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
732 OMX_ERROR4(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
733 eError = OMX_ErrorInsufficientResources;
737 if (Cmd == OMX_CommandMarkBuffer) {
738 nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData,
742 nRet = write(pCompPrivate->cmdDataPipe[1], &nParam,
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);
749 OMX_ERROR4(pCompPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside SendCommand\n",__LINE__);
750 eError = OMX_ErrorInsufficientResources;
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;
761 cmd_data.streamID = 0;
762 if((write(pCompPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0) {
763 eError = OMX_ErrorHardware;
770 OMX_PRINT1(pCompPrivate->dbg, "Returning from SendCommand\n");
773 /*-------------------------------------------------------------------*/
775 * GetParameter() Gets the current configurations of the component
777 * @param hComp handle for this instance of the component
779 * @param ComponentParameterStructure
781 * @retval OMX_NoError Success, ready to roll
782 * OMX_Error_BadParameter The input parameter pointer is null
784 /*-------------------------------------------------------------------*/
786 static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
787 OMX_INDEXTYPE nParamIndex,
788 OMX_PTR ComponentParameterStructure)
790 OMX_ERRORTYPE eError = OMX_ErrorNone;
791 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
792 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure;
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;
800 if (pParameterStructure == NULL) {
801 eError = OMX_ErrorBadParameter;
805 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::pParameterStructure = %p\n",__LINE__,pParameterStructure);
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;
815 if(pComponentPrivate->curState == OMX_StateInvalid) {
816 pComponentPrivate->cbInfo.EventHandler(
818 ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate,
820 OMX_ErrorIncorrectStateOperation,
823 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::ide the GetParameter\n",__LINE__);
826 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside the GetParameter\n",__LINE__);
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));
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));
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));
849 eError = OMX_ErrorBadPortIndex;
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;
862 memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat,
863 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
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;
873 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside the GetParameter\n",__LINE__);
874 memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
878 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Inside the GetParameter\n",__LINE__);
879 eError = OMX_ErrorBadPortIndex;
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));
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));
897 eError = OMX_ErrorBadPortIndex;
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));
906 eError = OMX_ErrorBadPortIndex;
911 case OMX_IndexParamPriorityMgmt:
912 if (NULL == pComponentPrivate->pPriorityMgmt) {
913 eError = OMX_ErrorBadParameter;
916 memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
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)); */
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)); */
930 OMX_PRINT2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from GetParameter");
931 eError = OMX_ErrorBadPortIndex;
936 case OMX_IndexParamVideoInit:
939 case OMX_IndexParamImageInit:
942 case OMX_IndexParamOtherInit:
945 case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
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)
951 OMX_ERROR4(pComponentPrivate->dbg, "%d :: ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__);
952 eError = OMX_ErrorBadParameter;
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;
962 eError = OMX_ErrorUnsupportedIndex;
967 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Exiting GetParameter:: %x\n",__LINE__,nParamIndex);
971 /*-------------------------------------------------------------------*/
973 * SetParameter() Sets configuration paramets to the component
975 * @param hComp handle for this instance of the component
979 * @retval OMX_NoError Success, ready to roll
980 * OMX_Error_BadParameter The input parameter pointer is null
982 /*-------------------------------------------------------------------*/
984 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR pCompParam)
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;
994 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
996 if (pCompParam == NULL) {
997 eError = OMX_ErrorBadParameter;
1001 #ifdef _ERROR_PROPAGATION__
1002 if (pComponentPrivate->curState == OMX_StateInvalid){
1003 eError = OMX_ErrorInvalidState;
1008 switch(nParamIndex) {
1009 case OMX_IndexParamAudioPortFormat:
1011 OMX_AUDIO_PARAM_PORTFORMATTYPE *pComponentParam =
1012 (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
1014 OMX_PRCOMM2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::pComponentParam->nPortIndex = %ld\n",__LINE__,pComponentParam->nPortIndex);
1017 /* 0 means Input port */
1018 if (pComponentParam->nPortIndex == 0) {
1020 memcpy(&pComponentPrivate->sInPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
1022 } else if (pComponentParam->nPortIndex == 1) {
1023 /* 1 means Output port */
1024 memcpy(&pComponentPrivate->sOutPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
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__);
1035 case OMX_IndexParamAudioAmr:
1037 OMX_AUDIO_PARAM_AMRTYPE *pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam;
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;
1048 pComponentPrivate->mimemode = 1; /*MIME Format*/
1050 pComponentPrivate->iAmrMode = pCompAmrParam->eAMRDTXMode;
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));
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));
1066 eError = OMX_ErrorBadPortIndex;
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],
1077 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
1079 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled = temp_bEnabled;
1080 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated = temp_bPopulated;
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],
1089 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)
1091 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled = temp_bEnabled;
1092 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated = temp_bPopulated;
1095 eError = OMX_ErrorBadPortIndex;
1098 case OMX_IndexParamPriorityMgmt:
1099 if (pComponentPrivate->curState == OMX_StateIdle ){
1100 eError = OMX_ErrorIncorrectStateOperation;
1103 if (NULL == pComponentPrivate->pPriorityMgmt) {
1104 eError = OMX_ErrorBadParameter;
1107 memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
1111 case OMX_IndexParamStandardComponentRole:
1113 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
1114 memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1116 eError = OMX_ErrorBadParameter;
1120 case OMX_IndexParamAudioPcm:
1122 amr_op = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
1123 memcpy(pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT], amr_op, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
1126 eError = OMX_ErrorBadParameter;
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));
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));
1145 OMX_PRINT2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
1146 eError = OMX_ErrorBadPortIndex;
1157 /*-------------------------------------------------------------------*/
1159 * GetConfig() Gets the current configuration of to the component
1161 * @param hComp handle for this instance of the component
1162 * @param nConfigIndex
1163 * @param ComponentConfigStructure
1165 * @retval OMX_NoError Success, ready to roll
1166 * OMX_Error_BadParameter The input parameter pointer is null
1168 /*-------------------------------------------------------------------*/
1170 static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1171 OMX_INDEXTYPE nConfigIndex,
1172 OMX_PTR ComponentConfigStructure)
1174 OMX_ERRORTYPE eError = OMX_ErrorNone;
1176 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
1177 TI_OMX_STREAM_INFO *streamInfo;
1179 OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO);
1181 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
1182 (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1184 #ifdef _ERROR_PROPAGATION__
1185 if (pComponentPrivate->curState == OMX_StateInvalid){
1186 eError = OMX_ErrorInvalidState;
1190 if (NULL == ComponentConfigStructure) {
1191 eError = OMX_ErrorBadParameter;
1194 if(nConfigIndex == OMX_IndexCustomNbAmrDecStreamIDConfig)
1196 /* copy component info */
1197 streamInfo->streamId = pComponentPrivate->streamID;
1198 memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO));
1200 else if(nConfigIndex == OMX_IndexCustomDebug)
1202 OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1206 OMX_MEMFREE_STRUCT(streamInfo);
1209 /*-------------------------------------------------------------------*/
1211 * SetConfig() Sets the configraiton to the component
1213 * @param hComp handle for this instance of the component
1214 * @param nConfigIndex
1215 * @param ComponentConfigStructure
1217 * @retval OMX_NoError Success, ready to roll
1218 * OMX_Error_BadParameter The input parameter pointer is null
1220 /*-------------------------------------------------------------------*/
1222 static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1223 OMX_INDEXTYPE nConfigIndex,
1224 OMX_PTR ComponentConfigStructure)
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;
1233 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate =
1234 (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1235 OMX_S16 *customFlag = NULL;
1236 TI_OMX_DSP_DEFINITION *configData;
1238 TI_OMX_DATAPATH dataPath;
1239 #ifdef DSP_RENDERING_ON
1240 OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
1241 OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
1243 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Entering SetConfig\n", __LINE__);
1245 #ifdef _ERROR_PROPAGATION__
1246 if (pComponentPrivate->curState == OMX_StateInvalid){
1247 eError = OMX_ErrorInvalidState;
1252 switch (nConfigIndex) {
1253 case OMX_IndexCustomNbAmrDecHeaderInfoConfig:
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__);
1262 pComponentPrivate->acdnmode = configData->acousticMode;
1263 if (configData->dasfMode == 0) {
1264 pComponentPrivate->dasfmode = 0;
1266 else if (configData->dasfMode == 1) {
1267 pComponentPrivate->dasfmode = 1;
1269 else if (configData->dasfMode == 2) {
1270 pComponentPrivate->dasfmode = 1;
1272 if (pComponentPrivate->dasfmode ){
1273 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled = 0;
1276 pComponentPrivate->streamID = configData->streamId;
1280 case OMX_IndexCustomNbAmrDecDataPath:
1281 customFlag = (OMX_S16*)ComponentConfigStructure;
1282 if (customFlag == NULL) {
1283 eError = OMX_ErrorBadParameter;
1287 dataPath = *customFlag;
1290 case DATAPATH_APPLICATION:
1291 /*strcpy((char*)pComponentPrivate->sDeviceString,(char*)ETEEDN_STRING);*/
1292 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID);
1295 case DATAPATH_APPLICATION_RTMIXER:
1296 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1300 strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1308 case OMX_IndexCustomNbAmrDecModeEfrConfig:
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__);
1317 pComponentPrivate->iAmrMode = *customFlag;
1320 case OMX_IndexCustomNbAmrDecModeDasfConfig:
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__);
1330 flagValue = *customFlag;
1331 if (flagValue == 0) {
1332 pComponentPrivate->dasfmode = 0;
1334 else if (flagValue == 1) {
1335 pComponentPrivate->dasfmode = 1;
1337 else if (flagValue == 2) {
1338 pComponentPrivate->dasfmode = 1;
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;
1346 case OMX_IndexCustomNbAmrDecModeMimeConfig:
1348 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: SetConfig OMX_IndexCustomNbAmrDecModeMimeConfig \n",__LINE__);
1349 customFlag = (OMX_S16*)ComponentConfigStructure;
1350 if (customFlag == NULL)
1352 eError = OMX_ErrorBadParameter;
1353 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1356 pComponentPrivate->mimemode = *customFlag;
1357 OMX_PRDSP2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::pComponentPrivate->mimemode = %d\n",__LINE__,pComponentPrivate->mimemode);
1360 case OMX_IndexCustomNbAmrDecNextFrameLost:
1362 pComponentPrivate->bFrameLost=OMX_TRUE;
1365 case OMX_IndexConfigAudioMute:
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)
1373 OMX_PRSTATE2(pComponentPrivate->dbg, "Mute the playback stream\n");
1374 cmd_data.AM_Cmd = AM_CommandStreamMute;
1378 OMX_PRSTATE2(pComponentPrivate->dbg, "unMute the playback stream\n");
1379 cmd_data.AM_Cmd = AM_CommandStreamUnMute;
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)
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");
1393 case OMX_IndexConfigAudioVolume:
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;
1404 if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1406 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::[NBAMR decoder] - fail to send Volume command to audio manager\n",__LINE__);
1413 case OMX_IndexCustomDebug:
1414 OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
1418 eError = OMX_ErrorUnsupportedIndex;
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);
1427 /*-------------------------------------------------------------------*/
1429 * GetState() Gets the current state of the component
1431 * @param pCompomponent handle for this instance of the component
1434 * @retval OMX_NoError Success, ready to roll
1435 * OMX_Error_BadParameter The input parameter pointer is null
1437 /*-------------------------------------------------------------------*/
1439 static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1441 OMX_ERRORTYPE error = OMX_ErrorUndefined;
1442 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1445 error = OMX_ErrorBadParameter;
1446 OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorBadParameter\n",__LINE__);
1450 if (pHandle && pHandle->pComponentPrivate) {
1451 *pState = ((AMRDEC_COMPONENT_PRIVATE*)
1452 pHandle->pComponentPrivate)->curState;
1454 *pState = OMX_StateLoaded;
1457 error = OMX_ErrorNone;
1463 /*-------------------------------------------------------------------*/
1465 * EmptyThisBuffer() This callback is used to send the input buffer to
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
1472 * @retval OMX_NoError Success, ready to roll
1473 * OMX_Error_BadParameter The input parameter pointer is null
1475 /*-------------------------------------------------------------------*/
1477 static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1478 OMX_BUFFERHEADERTYPE* pBuffer)
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;
1487 pPortDef = ((AMRDEC_COMPONENT_PRIVATE*)
1488 pComponentPrivate)->pPortDef[NBAMRDEC_INPUT_PORT];
1491 #ifdef _ERROR_PROPAGATION__
1492 if (pComponentPrivate->curState == OMX_StateInvalid){
1493 eError = OMX_ErrorInvalidState;
1498 #ifdef __PERF_INSTRUMENTATION__
1499 PERF_ReceivedFrame(pComponentPrivate->pPERF,
1501 pBuffer->nFilledLen,
1505 if(!pPortDef->bEnabled) {
1506 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__);
1507 eError = OMX_ErrorIncorrectStateOperation;
1511 if (pBuffer == NULL) {
1512 eError = OMX_ErrorBadParameter;
1513 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorBadParameter\n",__LINE__);
1517 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1518 eError = OMX_ErrorBadParameter;
1522 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1523 eError = OMX_ErrorVersionMismatch;
1527 if (pBuffer->nInputPortIndex != NBAMRDEC_INPUT_PORT) {
1528 eError = OMX_ErrorBadPortIndex;
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;
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");
1547 pComponentPrivate->app_nBuf--;
1549 pComponentPrivate->pMarkData = pBuffer->pMarkData;
1550 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1552 pComponentPrivate->nUnhandledEmptyThisBuffers++;
1554 ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1555 sizeof(OMX_BUFFERHEADERTYPE*));
1557 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Error in Writing to the Data pipe\n", __LINE__);
1558 eError = OMX_ErrorHardware;
1561 pComponentPrivate->nEmptyThisBufferCount++;
1566 /*-------------------------------------------------------------------*/
1568 * FillThisBuffer() This callback is used to send the output buffer to
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
1575 * @retval OMX_NoError Success, ready to roll
1576 * OMX_Error_BadParameter The input parameter pointer is null
1578 /*-------------------------------------------------------------------*/
1580 static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1581 OMX_BUFFERHEADERTYPE* pBuffer)
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");
1593 pPortDef = ((AMRDEC_COMPONENT_PRIVATE*)
1594 pComponentPrivate)->pPortDef[NBAMRDEC_OUTPUT_PORT];
1596 #ifdef _ERROR_PROPAGATION__
1597 if (pComponentPrivate->curState == OMX_StateInvalid){
1598 eError = OMX_ErrorInvalidState;
1602 #ifdef __PERF_INSTRUMENTATION__
1603 PERF_ReceivedFrame(pComponentPrivate->pPERF,
1609 if(!pPortDef->bEnabled) {
1610 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__);
1611 eError = OMX_ErrorIncorrectStateOperation;
1615 if (pBuffer == NULL) {
1616 eError = OMX_ErrorBadParameter;
1617 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorBadParameter\n",__LINE__);
1621 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1622 eError = OMX_ErrorBadParameter;
1627 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1628 eError = OMX_ErrorVersionMismatch;
1632 if (pBuffer->nOutputPortIndex != NBAMRDEC_OUTPUT_PORT) {
1633 eError = OMX_ErrorBadPortIndex;
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;
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);
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;
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;
1664 pComponentPrivate->nUnhandledFillThisBuffers++;
1666 write (pComponentPrivate->dataPipe[1], &pBuffer,
1667 sizeof (OMX_BUFFERHEADERTYPE*));
1668 pComponentPrivate->nFillThisBufferCount++;
1673 /*-------------------------------------------------------------------*/
1675 * OMX_ComponentDeinit() this methold will de init the component
1677 * @param pComp handle for this instance of the component
1679 * @retval OMX_NoError Success, ready to roll
1680 * OMX_Error_BadParameter The input parameter pointer is null
1682 /*-------------------------------------------------------------------*/
1684 static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1686 OMX_ERRORTYPE eError = OMX_ErrorNone;
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;
1696 OMX_PRINT1(dbg, "%d ::OMX_AmrDecoder.c ::ComponentDeInit\n",__LINE__);
1698 #ifdef __PERF_INSTRUMENTATION__
1699 PERF_Boundary(pComponentPrivate->pPERF,
1700 PERF_BoundaryStart | PERF_BoundaryCleanup);
1702 #ifdef DSP_RENDERING_ON
1703 close(pComponentPrivate->fdwrite);
1704 close(pComponentPrivate->fdread);
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",
1712 eError = RMProxy_Deinitalize();
1713 if (eError != OMX_ErrorNone) {
1714 OMX_ERROR4(dbg, "%d ::OMX_AmrDecoder.c :: Error from RMProxy_Deinitalize\n",
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" */
1725 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
1727 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
1729 /* close the pipe handles */
1730 NBAMRDEC_FreeCompResources(pHandle);
1732 #ifdef __PERF_INSTRUMENTATION__
1733 PERF_Boundary(pComponentPrivate->pPERF,
1734 PERF_BoundaryComplete | PERF_BoundaryCleanup);
1735 PERF_Done(pComponentPrivate->pPERF);
1737 OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1738 OMX_PRINT1(dbg, "%d ::After NBAMRDEC_FreeCompResources\n",__LINE__);
1739 OMX_MEMFREE_STRUCT(pComponentPrivate);
1741 OMX_PRINT1(dbg, "%d ::After OMX_MEMFREE_STRUCT(pComponentPrivate)\n",__LINE__);
1746 /*-------------------------------------------------------------------*/
1748 * ComponentTunnelRequest() this method is not implemented in 1.5
1750 * This method will update application callbacks
1753 * @param pComp handle for this instance of the component
1754 * @param pCallBacks application callbacks
1757 * @retval OMX_NoError Success, ready to roll
1758 * OMX_Error_BadParameter The input parameter pointer is null
1760 /*-------------------------------------------------------------------*/
1762 static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1763 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1764 OMX_U32 nTunneledPort,
1765 OMX_TUNNELSETUPTYPE* pTunnelSetup)
1767 OMX_ERRORTYPE eError = OMX_ErrorNone;
1768 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Inside the ComponentTunnelRequest\n");
1769 eError = OMX_ErrorNotImplemented;
1773 /*-------------------------------------------------------------------*/
1777 * @param pComp handle for this instance of the component
1778 * @param pCallBacks application callbacks
1781 * @retval OMX_NoError Success, ready to roll
1782 * OMX_Error_BadParameter The input parameter pointer is null
1784 /*-------------------------------------------------------------------*/
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)
1793 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
1794 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
1795 OMX_ERRORTYPE eError = OMX_ErrorNone;
1796 OMX_BUFFERHEADERTYPE *pBufferHeader;
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__);
1807 eError = OMX_ErrorInvalidState;
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);
1815 OMX_PRCOMM2(pComponentPrivate->dbg, "pPortDef->bEnabled = %d\n", pPortDef->bEnabled);
1817 if(pPortDef->bEnabled) {
1820 pComponentPrivate->AlloBuf_waitingsignal = 1;
1822 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1823 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
1824 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1826 OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1830 OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1832 OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes,OMX_U8);
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;
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;
1863 eError = OMX_ErrorBadPortIndex;
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))
1871 pComponentPrivate->InLoaded_readytoidle = 0;
1873 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1874 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1875 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1877 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
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;
1888 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1889 OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: \n",__LINE__);
1890 *pBuffer = pBufferHeader;
1892 if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
1893 SendCommand (pComponentPrivate->pHandle,
1894 OMX_CommandPortEnable,
1895 pComponentPrivate->bEnableCommandParam,NULL);
1899 #ifdef __PERF_INSTRUMENTATION__
1900 PERF_ReceivedBuffer(pComponentPrivate->pPERF,
1901 (*pBuffer)->pBuffer, nSizeBytes,
1904 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: AllocateBuffer returning %d\n",__LINE__,eError);
1908 /*-------------------------------------------------------------------*/
1912 * @param hComponent handle for this instance of the component
1913 * @param pCallBacks application callbacks
1916 * @retval OMX_NoError Success, ready to roll
1917 * OMX_Error_BadParameter The input parameter pointer is null
1919 /*-------------------------------------------------------------------*/
1921 static OMX_ERRORTYPE FreeBuffer(
1922 OMX_IN OMX_HANDLETYPE hComponent,
1923 OMX_IN OMX_U32 nPortIndex,
1924 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer)
1926 OMX_ERRORTYPE eError = OMX_ErrorNone;
1927 AMRDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1928 OMX_BUFFERHEADERTYPE* buff;
1930 OMX_S16 inputIndex = -1;
1931 OMX_S16 outputIndex = -1;
1932 OMX_COMPONENTTYPE *pHandle;
1934 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
1935 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
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);
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);
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);
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);
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,
1978 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
1979 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
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;
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");
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,
2005 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
2006 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,OMX_U8);
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--;
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;
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");
2029 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::Returning OMX_ErrorBadParameter\n",__LINE__);
2030 eError = OMX_ErrorBadParameter;
2032 /* Removing sleep() calls. There are no allocated buffers. */
2033 if ((!pComponentPrivate->pInputBufferList->numBuffers &&
2034 !pComponentPrivate->pOutputBufferList->numBuffers) &&
2035 pComponentPrivate->InIdle_goingtoloaded)
2038 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
2039 pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
2040 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
2042 OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
2045 pComponentPrivate->InIdle_goingtoloaded = 0;
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);
2055 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Exiting FreeBuffer\n", __LINE__);
2059 /*-------------------------------------------------------------------*/
2063 * @param pComp handle for this instance of the component
2064 * @param pCallBacks application callbacks
2067 * @retval OMX_NoError Success, ready to roll
2068 * OMX_Error_BadParameter The input parameter pointer is null
2070 /*-------------------------------------------------------------------*/
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)
2080 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
2081 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
2082 OMX_ERRORTYPE eError = OMX_ErrorNone;
2083 OMX_BUFFERHEADERTYPE *pBufferHeader;
2085 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
2086 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2088 #ifdef _ERROR_PROPAGATION__
2089 if (pComponentPrivate->curState == OMX_StateInvalid){
2090 eError = OMX_ErrorInvalidState;
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);
2100 if(!pPortDef->bEnabled) {
2101 OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: In AllocateBuffer\n", __LINE__);
2102 eError = OMX_ErrorIncorrectStateOperation;
2106 /*if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) {
2107 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: In AllocateBuffer\n", __LINE__);
2108 eError = OMX_ErrorBadParameter;
2112 OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
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;
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;
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))
2141 pComponentPrivate->InLoaded_readytoidle = 0;
2143 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2144 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2145 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2147 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2150 /* Removing sleep() calls. */
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);
2163 if (pComponentPrivate->bEnableCommandPending){
2164 SendCommand (pComponentPrivate->pHandle,
2165 OMX_CommandPortEnable,
2166 pComponentPrivate->bEnableCommandParam,NULL);
2170 #ifdef __PERF_INSTRUMENTATION__
2171 PERF_ReceivedBuffer(pComponentPrivate->pPERF,
2172 pBuffer, nSizeBytes,
2178 /* ================================================================================= */
2180 * @fn GetExtensionIndex() description for GetExtensionIndex
2181 GetExtensionIndex().
2182 Returns index for vendor specific settings.
2186 /* ================================================================================ */
2187 static OMX_ERRORTYPE GetExtensionIndex(
2188 OMX_IN OMX_HANDLETYPE hComponent,
2189 OMX_IN OMX_STRING cParameterName,
2190 OMX_OUT OMX_INDEXTYPE *pIndexType)
2192 OMX_ERRORTYPE eError = OMX_ErrorNone;
2194 if(!(strcmp(cParameterName,"OMX.TI.index.config.nbamrheaderinfo")))
2196 *pIndexType = OMX_IndexCustomNbAmrDecHeaderInfoConfig;
2198 else if(!(strcmp(cParameterName,"OMX.TI.index.config.nbamrstreamIDinfo")))
2200 *pIndexType = OMX_IndexCustomNbAmrDecStreamIDConfig;
2202 else if(!(strcmp(cParameterName,"OMX.TI.index.config.nbamr.datapath")))
2204 *pIndexType = OMX_IndexCustomNbAmrDecDataPath;
2206 else if(!(strcmp(cParameterName,"OMX.TI.index.config.nbamr.framelost")))
2208 *pIndexType = OMX_IndexCustomNbAmrDecNextFrameLost;
2210 else if(!(strcmp(cParameterName,"OMX.TI.AMR.Decode.Debug")))
2212 *pIndexType = OMX_IndexCustomDebug;
2216 eError = OMX_ErrorBadParameter;
2221 /* ================================================================================= */
2223 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
2225 Returns the role at the given index
2229 /* ================================================================================ */
2230 static OMX_ERRORTYPE ComponentRoleEnum(
2231 OMX_IN OMX_HANDLETYPE hComponent,
2232 OMX_OUT OMX_U8 *cRole,
2233 OMX_IN OMX_U32 nIndex)
2235 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
2237 OMX_ERRORTYPE eError = OMX_ErrorNone;
2238 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2240 if (NULL == cRole) {
2241 eError = OMX_ErrorBadParameter;
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);
2249 eError = OMX_ErrorNoMore;
2254 #ifdef NBAMRDEC_DEBUGMEM
2255 void * mymalloc(int line, char *s, int size)
2261 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
2265 while((lines[e]!=0)&& (e<500) ){
2272 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s);
2277 int myfree(void *dp, int line, char *s){
2281 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
2290 OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n\n%p Pointer not found. Line:%d File%s!!\n\n",dp, line, s);