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_G711Decoder.c
31 * This file implements OMX Component for G711 decoder that
32 * is fully compliant with the OMX Audio specification.
38 /* ----------------------------------------------------------------------------*/
40 /* ------compilation control switches -------------------------*/
41 /****************************************************************
43 ****************************************************************/
44 /* ----- system and platform files ----------------------------*/
52 #include <sys/types.h>
53 #include <sys/ioctl.h>
54 #include <sys/select.h>
64 #ifdef DSP_RENDERING_ON
65 #include <AudioManagerAPI.h>
68 #ifdef RESOURCE_MANAGER_ENABLED
69 #include <ResourceManagerProxyAPI.h>
72 /*-------program files ----------------------------------------*/
73 #include <OMX_Component.h>
75 #include "OMX_G711Dec_Utils.h"
77 #ifdef G711DEC_MEMDEBUG
78 extern void *arr[500] = {NULL};
79 extern int lines[500] = {0};
80 extern int bytes[500] = {0};
81 extern char file[500][50] = {""};
83 #define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
84 void * mymalloc(int line, char *s, int size);
85 #define newfree(z) myfree(z,__LINE__,__FILE__)
86 void myfree(void *dp, int line, char *s);
88 #define newmalloc(x) malloc(x)
89 #define newfree(z) free(z)
92 /****************************************************************
93 * EXTERNAL REFERENCES NOTE : only use if not found in header file
94 ****************************************************************/
95 /*--------data declarations -----------------------------------*/
97 /*--------function prototypes ---------------------------------*/
99 /****************************************************************
100 * PUBLIC DECLARATIONS Defined here, used elsewhere
101 ****************************************************************/
102 /*--------data declarations -----------------------------------*/
104 /*--------function prototypes ---------------------------------*/
106 /****************************************************************
107 * PRIVATE DECLARATIONS Defined here, used only here
108 ****************************************************************/
109 /*--------data declarations -----------------------------------*/
111 /*--------function prototypes ---------------------------------*/
113 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
114 OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
115 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
116 OMX_STRING pComponentName,
117 OMX_VERSIONTYPE* pComponentVersion,
118 OMX_VERSIONTYPE* pSpecVersion,
119 OMX_UUIDTYPE* pComponentUUID);
121 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
122 OMX_U32 nParam, OMX_PTR pCmdData);
124 static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex,
125 OMX_PTR ComponentParamStruct);
126 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
127 OMX_INDEXTYPE nParamIndex,
128 OMX_PTR ComponentParamStruct);
129 static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
130 OMX_INDEXTYPE nConfigIndex,
131 OMX_PTR pComponentConfigStructure);
132 static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
133 OMX_INDEXTYPE nConfigIndex,
134 OMX_PTR pComponentConfigStructure);
136 static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
138 static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
139 static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
140 static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
141 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
142 OMX_U32 nTunneledPort,
143 OMX_TUNNELSETUPTYPE* pTunnelSetup);
145 static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
146 static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
147 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
148 OMX_IN OMX_U32 nPortIndex,
149 OMX_IN OMX_PTR pAppPrivate,
150 OMX_IN OMX_U32 nSizeBytes);
152 static OMX_ERRORTYPE FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,
153 OMX_IN OMX_U32 nPortIndex,
154 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
156 static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
157 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
158 OMX_IN OMX_U32 nPortIndex,
159 OMX_IN OMX_PTR pAppPrivate,
160 OMX_IN OMX_U32 nSizeBytes,
161 OMX_IN OMX_U8* pBuffer);
163 static OMX_ERRORTYPE GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
164 OMX_IN OMX_STRING cParameterName,
165 OMX_OUT OMX_INDEXTYPE *pIndexType);
167 static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
168 OMX_OUT OMX_U8 *cRole,
169 OMX_IN OMX_U32 nIndex);
171 /* ======================================================================= */
173 * @def FIFO1, FIFO2 Define Fifo Path
175 /* ======================================================================= */
176 #define FIFO1 "/dev/fifo.1"
177 #define FIFO2 "/dev/fifo.2"
179 /* ======================================================================= */
181 * @def PERMS Define Read and Write Permisions.
183 /* ======================================================================= */
185 #define G711_DEC_ROLE "audio_decoder.g711"
186 #ifdef DSP_RENDERING_ON
187 AM_COMMANDDATATYPE cmd_data;
189 /*-------------------------------------------------------------------*/
191 * OMX_ComponentInit() Set the all the function pointers of component
193 * This method will update the component function pointer to the handle
195 * @param hComp handle for this instance of the component
197 * @retval OMX_NoError Success, ready to roll
198 * OMX_ErrorInsufficientResources If the malloc fails
200 /*-------------------------------------------------------------------*/
201 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
204 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
205 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
206 OMX_AUDIO_PARAM_PCMMODETYPE *g711_ip = NULL, *g711_op = NULL;
207 G711DEC_PORT_TYPE *pCompPort = NULL;
208 OMX_AUDIO_PARAM_PORTFORMATTYPE *pInPortFormatArr = NULL;
209 OMX_AUDIO_PARAM_PORTFORMATTYPE *pOutPortFormatArr = NULL;
210 OMX_ERRORTYPE eError = OMX_ErrorNone;
211 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
214 G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
216 /*Set the all component function pointer to the handle */
217 pHandle->SetCallbacks = SetCallbacks;
218 pHandle->GetComponentVersion = GetComponentVersion;
219 pHandle->SendCommand = SendCommand;
220 pHandle->GetParameter = GetParameter;
221 pHandle->SetParameter = SetParameter;
222 pHandle->GetConfig = GetConfig;
223 pHandle->SetConfig = SetConfig;
224 pHandle->GetState = GetState;
225 pHandle->EmptyThisBuffer = EmptyThisBuffer;
226 pHandle->FillThisBuffer = FillThisBuffer;
227 pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
228 pHandle->ComponentDeInit = ComponentDeInit;
229 pHandle->AllocateBuffer = AllocateBuffer;
230 pHandle->FreeBuffer = FreeBuffer;
231 pHandle->UseBuffer = UseBuffer;
232 pHandle->GetExtensionIndex = GetExtensionIndex;
233 pHandle->ComponentRoleEnum = ComponentRoleEnum;
235 /*Allocate the memory for Component private data area */
236 G711D_OMX_MALLOC(pHandle->pComponentPrivate, G711DEC_COMPONENT_PRIVATE);
238 ((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
240 /* Initialize component data structures to default values */
241 ((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nPorts = 0x2;
242 ((G711DEC_COMPONENT_PRIVATE *)
243 pHandle->pComponentPrivate)->sPortParam.nStartPortNumber = 0x0;
245 eError = OMX_ErrorNone;
247 G711D_OMX_MALLOC(g711_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
248 G711D_OMX_MALLOC(g711_op, OMX_AUDIO_PARAM_PCMMODETYPE);
250 G711DEC_DPRINT ("%d ::LINE \n", __LINE__);
252 ((G711DEC_COMPONENT_PRIVATE *)
253 pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT] = g711_ip;
254 ((G711DEC_COMPONENT_PRIVATE *)
255 pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT] = g711_op;
257 g711_ip->nPortIndex = G711DEC_INPUT_PORT;
258 g711_op->nPortIndex = G711DEC_OUTPUT_PORT;
260 G711DEC_DPRINT("%d Malloced g711Params[G711DEC_INPUT_PORT] = 0x%x\n",__LINE__,
261 (unsigned int)((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT]);
262 G711DEC_DPRINT("%d Malloced g711Params[G711DEC_OUTPUT_PORT] = 0x%x\n",__LINE__,
263 (unsigned int)((G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT]);
266 pComponentPrivate = pHandle->pComponentPrivate;
267 G711D_OMX_MALLOC(pComponentPrivate->pInputBufferList, G711DEC_BUFFERLIST);
268 pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
269 G711D_OMX_MALLOC(pComponentPrivate->pOutputBufferList, G711DEC_BUFFERLIST);
271 G711D_OMX_MALLOC(pCompPort, G711DEC_PORT_TYPE);
272 pComponentPrivate->pCompPort[G711DEC_INPUT_PORT] = pCompPort;
273 G711D_OMX_MALLOC(pCompPort, G711DEC_PORT_TYPE);
274 pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT] = pCompPort;
276 pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
277 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;
284 G711DEC_DPRINT("Setting dasfmode and mimemode to 0\n");
285 pComponentPrivate->dasfmode = 0;
286 pComponentPrivate->bPortDefsAllocated = 1;
287 pComponentPrivate->bCompThreadStarted = 0;
288 pComponentPrivate->nHoldLength = 0;
289 pComponentPrivate->pHoldBuffer = NULL;
290 pComponentPrivate->bInitParamsInitialized = 0;
291 pComponentPrivate->pMarkBuf = NULL;
292 pComponentPrivate->pMarkData = NULL;
293 pComponentPrivate->nEmptyBufferDoneCount = 0;
294 pComponentPrivate->nEmptyThisBufferCount = 0;
295 pComponentPrivate->nFillBufferDoneCount = 0;
296 pComponentPrivate->nFillThisBufferCount = 0;
297 pComponentPrivate->strmAttr = NULL;
298 pComponentPrivate->nDataWritesWhilePaused = 0;
299 pComponentPrivate->bIdleCommandPending = 0;
300 pComponentPrivate->bDisableCommandParam = 0;
301 pComponentPrivate->bEnableCommandParam = 0;
302 pComponentPrivate->nRuntimeInputBuffers = 0;
304 for (i=0; i < MAX_NUM_OF_BUFS; i++) {
305 pComponentPrivate->pInputBufHdrPending[i] = NULL;
306 pComponentPrivate->pOutputBufHdrPending[i] = NULL;
309 pComponentPrivate->bJustReenabled = 0;
310 pComponentPrivate->nInvalidFrameCount = 0;
311 pComponentPrivate->nNumInputBufPending = 0;
312 pComponentPrivate->nNumOutputBufPending = 0;
313 pComponentPrivate->bDisableCommandPending = 0;
314 pComponentPrivate->bEnableCommandPending = 0;
315 pComponentPrivate->nOutStandingFillDones = 0;
316 pComponentPrivate->bStopSent = 0;
317 pComponentPrivate->bBypassDSP = OMX_FALSE;
318 pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
319 pComponentPrivate->bPreempted = OMX_FALSE;
321 G711D_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), OMX_STRING);
322 /* initialize role name */
323 strcpy((char*)pComponentPrivate->componentRole.cRole,G711_DEC_ROLE);
324 /* Initialize device string to the default value */
325 strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
327 /* Removing sleep() calls. Initialization.*/
329 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
330 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
331 pComponentPrivate->AlloBuf_waitingsignal = 0;
333 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
334 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
335 pComponentPrivate->InLoaded_readytoidle = 0;
337 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
338 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
339 pComponentPrivate->InIdle_goingtoloaded = 0;
341 OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
342 pComponentPrivate->AlloBuf_waitingsignal = 0;
344 OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
345 pComponentPrivate->InLoaded_readytoidle = 0;
347 OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
348 pComponentPrivate->InIdle_goingtoloaded = 0;
350 /* Removing sleep() calls. Initialization.*/
351 G711D_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
352 G711D_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
354 G711DEC_DPRINT ("%d ::pPortDef_ip = 0x%x\n", __LINE__,(unsigned int)pPortDef_ip);
355 G711DEC_DPRINT ("%d ::pPortDef_op = 0x%x\n", __LINE__,(unsigned int)pPortDef_op);
357 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT] = pPortDef_ip;
358 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT] = pPortDef_op;
360 pPortDef_ip->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
361 pPortDef_ip->nPortIndex = 0x0;
362 pPortDef_ip->nBufferCountActual = NUM_G711DEC_INPUT_BUFFERS;
363 pPortDef_ip->nBufferCountMin = NUM_G711DEC_INPUT_BUFFERS;
364 pPortDef_ip->eDir = OMX_DirInput;
365 pPortDef_ip->bEnabled = OMX_TRUE;
366 pPortDef_ip->nBufferSize = INPUT_G711DEC_BUFFER_SIZE;
367 pPortDef_ip->bPopulated = 0;
368 pPortDef_ip->eDomain = OMX_PortDomainAudio;
369 pPortDef_ip->format.audio.eEncoding = OMX_AUDIO_CodingG711;
370 pPortDef_ip->format.audio.cMIMEType = NULL;
371 pPortDef_ip->format.audio.pNativeRender = NULL;
372 pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
375 pPortDef_op->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
376 pPortDef_op->nPortIndex = 0x1;
377 pPortDef_op->nBufferCountActual = NUM_G711DEC_OUTPUT_BUFFERS;
378 pPortDef_op->nBufferCountMin = NUM_G711DEC_OUTPUT_BUFFERS;
379 pPortDef_op->eDir = OMX_DirOutput;
380 pPortDef_op->bEnabled = OMX_TRUE;
381 pPortDef_op->nBufferSize = OUTPUT_G711DEC_BUFFER_SIZE;
382 pPortDef_op->bPopulated = 0;
383 pPortDef_op->eDomain = OMX_PortDomainAudio;
384 pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingPCM;
385 pPortDef_op->format.audio.cMIMEType = NULL;
386 pPortDef_op->format.audio.pNativeRender = NULL;
387 pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
389 pComponentPrivate->sInPortFormat.nPortIndex = G711DEC_INPUT_PORT;
390 pComponentPrivate->sInPortFormat.nIndex = OMX_IndexParamAudioPcm;
391 pComponentPrivate->sInPortFormat.eEncoding = OMX_AUDIO_CodingG711;
393 pComponentPrivate->sOutPortFormat.nPortIndex = G711DEC_OUTPUT_PORT;
394 pComponentPrivate->sOutPortFormat.nIndex = OMX_IndexParamAudioPcm;
395 pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM;
397 G711D_OMX_MALLOC(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
398 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
399 /* Set input port format defaults */
400 pInPortFormatArr = pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat;
401 OMX_NBCONF_INIT_STRUCT(pInPortFormatArr, OMX_AUDIO_PARAM_PORTFORMATTYPE);
402 pInPortFormatArr->nPortIndex = G711DEC_INPUT_PORT;
403 pInPortFormatArr->nIndex = OMX_IndexParamAudioPcm;
404 pInPortFormatArr->eEncoding = OMX_AUDIO_CodingG711;
406 G711D_OMX_MALLOC(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
407 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
408 /* Set output port format defaults */
409 pOutPortFormatArr = pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat;
410 OMX_NBCONF_INIT_STRUCT(pOutPortFormatArr, OMX_AUDIO_PARAM_PORTFORMATTYPE);
411 pOutPortFormatArr->nPortIndex = G711DEC_OUTPUT_PORT;
412 pOutPortFormatArr->nIndex = OMX_IndexParamAudioPcm;
413 pOutPortFormatArr->eEncoding = OMX_AUDIO_CodingPCM;
415 #ifdef RESOURCE_MANAGER_ENABLED
416 G711DEC_DPRINT ("%d %s Initialize RM Proxy...\n", __LINE__,__FUNCTION__);
417 eError = RMProxy_NewInitalize();
418 G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
419 if (eError != OMX_ErrorNone) {
420 G711DEC_DPRINT ("%d ::Error returned from loading ResourceManagerProxy thread\n", __LINE__);
421 if( eError == OMX_ErrorInsufficientResources)
422 G711DEC_PRINT("Error OMX_ErrorInsufficientResources\n");
424 G711DEC_PRINT("eError 0x%x\n", eError);
429 eError = G711DEC_StartComponentThread(pHandle);
430 G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
431 if (eError != OMX_ErrorNone) {
432 G711DEC_DPRINT ("%d ::Error returned from the Component\n", __LINE__);
435 G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
437 #ifdef DSP_RENDERING_ON
439 if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0) {
440 G711DEC_DPRINT("[G711 Dec Component] - failure to open WRITE pipe\n");
443 if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0) {
444 G711DEC_DPRINT("[G711 Dec Component] - failure to open READ pipe\n");
447 G711DEC_DPRINT ("%d ::OMX_ComponentInit\n", __LINE__);
451 if(eError == OMX_ErrorInsufficientResources)
453 OMX_G711DECMEMFREE_STRUCT(g711_ip);
454 OMX_G711DECMEMFREE_STRUCT(g711_op);
455 if (pComponentPrivate != NULL) {
456 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
457 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
458 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat);
459 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat);
460 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]);
461 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]);
462 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
464 OMX_G711DECMEMFREE_STRUCT(pHandle->pComponentPrivate);
465 OMX_G711DECMEMFREE_STRUCT(pPortDef_ip);
466 OMX_G711DECMEMFREE_STRUCT(pPortDef_op);
469 G711DEC_DPRINT ("%d ::OMX_ComponentInit - returning %d\n", __LINE__,eError);
473 /*-------------------------------------------------------------------*/
475 * SetCallbacks() Sets application callbacks to the component
477 * This method will update application callbacks
478 * to the component. So that component can make use of those call back
479 * while sending buffers to the application. And also it will copy the
480 * application private data to component memory
482 * @param pComponent handle for this instance of the component
483 * @param pCallBacks application callbacks
484 * @param pAppData Application private data
486 * @retval OMX_NoError Success, ready to roll
487 * OMX_Error_BadParameter The input parameter pointer is null
489 /*-------------------------------------------------------------------*/
491 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
492 OMX_CALLBACKTYPE* pCallBacks,
495 OMX_ERRORTYPE eError = OMX_ErrorNone;
497 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
499 G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
500 (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
502 if (pCallBacks == NULL) {
503 G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
504 eError = OMX_ErrorBadParameter;
505 G711DEC_DPRINT ("%d :: Received the empty callbacks from the application\n",__LINE__);
509 /*Copy the callbacks of the application to the component private */
510 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
512 /*copy the application private data to component memory */
513 pHandle->pApplicationPrivate = pAppData;
515 pComponentPrivate->curState = OMX_StateLoaded;
521 /*-------------------------------------------------------------------*/
523 * GetComponentVersion() This will return the component version
525 * This method will retrun the component version
527 * @param hComp handle for this instance of the component
528 * @param pCompnentName Name of the component
529 * @param pCompnentVersion handle for this instance of the component
530 * @param pSpecVersion application callbacks
531 * @param pCompnentUUID
533 * @retval OMX_NoError Success, ready to roll
534 * OMX_Error_BadParameter The input parameter pointer is null
536 /*-------------------------------------------------------------------*/
538 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
539 OMX_STRING pComponentName,
540 OMX_VERSIONTYPE* pComponentVersion,
541 OMX_VERSIONTYPE* pSpecVersion,
542 OMX_UUIDTYPE* pComponentUUID)
544 OMX_ERRORTYPE eError = OMX_ErrorNone;
546 eError = OMX_ErrorNotImplemented;
547 G711DEC_DPRINT (stderr, "Inside the GetComponentVersion\n");
553 /*-------------------------------------------------------------------*/
555 * SendCommand() used to send the commands to the component
557 * This method will be used by the application.
559 * @param phandle handle for this instance of the component
560 * @param Cmd Command to be sent to the component
561 * @param nParam indicates commmad is sent using this method
563 * @retval OMX_NoError Success, ready to roll
564 * OMX_Error_BadParameter The input parameter pointer is null
566 /*-------------------------------------------------------------------*/
568 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
570 OMX_U32 nParam,OMX_PTR pCmdData)
572 OMX_ERRORTYPE eError = OMX_ErrorNone;
574 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
575 G711DEC_COMPONENT_PRIVATE *pCompPrivate =
576 (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
578 G711DEC_DPRINT ("%d:::Inside SendCommand\n", __LINE__);
580 G711DEC_DPRINT("phandle = %p\n", phandle);
581 G711DEC_DPRINT("pCompPrivate = %p\n", pCompPrivate);
583 pCompPrivate->pHandle = phandle;
585 if(pCompPrivate->curState == OMX_StateInvalid){
586 G711DEC_DPRINT ("%d:::Inside SendCommand\n", __LINE__);
587 eError = OMX_ErrorInvalidState;
588 G711DEC_DPRINT("%d :: G711DEC: Error Notofication \
589 Sent to App\n",__LINE__);
590 pCompPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
591 OMX_EventError, OMX_ErrorInvalidState,
599 case OMX_CommandStateSet:
600 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
601 G711DEC_DPRINT ("%d:::pCompPrivate->curState = %d\n",
602 __LINE__,pCompPrivate->curState);
603 if (nParam == OMX_StateLoaded) {
604 pCompPrivate->bLoadedCommandPending = OMX_TRUE;
606 if(pCompPrivate->curState == OMX_StateLoaded) {
607 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
608 pCompPrivate->cbInfo.EventHandler (pHandle,
609 pHandle->pApplicationPrivate,
611 OMX_ErrorIncorrectStateTransition,
616 if(nParam == OMX_StateInvalid) {
617 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
618 pCompPrivate->curState = OMX_StateInvalid;
619 pCompPrivate->cbInfo.EventHandler (pHandle,
620 pHandle->pApplicationPrivate,
622 OMX_ErrorInvalidState,
628 case OMX_CommandFlush:
629 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
630 if(nParam > 1 && nParam != -1) {
631 eError = OMX_ErrorBadPortIndex;
636 case OMX_CommandPortDisable:
637 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
639 case OMX_CommandPortEnable:
640 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
642 case OMX_CommandMarkBuffer:
643 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
645 eError = OMX_ErrorBadPortIndex;
650 G711DEC_DPRINT("%d :: G711DEC: Command Received Default \
652 pCompPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
653 OMX_EventError, OMX_ErrorUndefined,0,
659 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
660 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
663 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
664 eError = OMX_ErrorInsufficientResources;
668 if (Cmd == OMX_CommandMarkBuffer) {
669 nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
672 nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32));
675 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
676 G711DEC_DPRINT ("%d:::nRet = %d\n",__LINE__,nRet);
678 G711DEC_DPRINT ("%d:::Inside SendCommand\n",__LINE__);
679 eError = OMX_ErrorInsufficientResources;
683 #ifdef DSP_RENDERING_ON
684 if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting)
686 /* enable Tee device command*/
687 cmd_data.hComponent = pHandle;
688 cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode;
691 cmd_data.streamID = 0;
692 if((write(pCompPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
694 eError = OMX_ErrorHardware;
703 /*-------------------------------------------------------------------*/
705 * GetParameter() Gets the current configurations of the component
707 * @param hComp handle for this instance of the component
709 * @param ComponentParameterStructure
711 * @retval OMX_NoError Success, ready to roll
712 * OMX_Error_BadParameter The input parameter pointer is null
714 /*-------------------------------------------------------------------*/
716 static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
717 OMX_INDEXTYPE nParamIndex,
718 OMX_PTR ComponentParameterStructure)
720 OMX_ERRORTYPE eError = OMX_ErrorNone;
721 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
722 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL;
724 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
725 G711DEC_DPRINT("%d :: Inside the GetParameter:: %x\n",__LINE__,nParamIndex);
727 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
728 pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
730 if (pParameterStructure == NULL) {
731 eError = OMX_ErrorBadParameter;
736 G711DEC_DPRINT("pParameterStructure = %p\n",pParameterStructure);
737 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
739 if(pComponentPrivate->curState == OMX_StateInvalid) {
740 pComponentPrivate->cbInfo.EventHandler(
742 ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate,
744 OMX_ErrorIncorrectStateOperation,
747 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
750 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
754 case OMX_IndexParamAudioInit:
755 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
756 G711DEC_DPRINT ("OMX_IndexParamAudioInit\n");
757 memcpy(ComponentParameterStructure,
758 &pComponentPrivate->sPortParam,
759 sizeof(OMX_PORT_PARAM_TYPE));
762 case OMX_IndexParamPortDefinition:
763 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
764 G711DEC_DPRINT ("pParameterStructure->nPortIndex = %d\n",(int)pParameterStructure->nPortIndex);
765 G711DEC_DPRINT ("pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex = %d\n",(int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex);
767 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
768 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex)
770 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
772 memcpy(ComponentParameterStructure,
773 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT],
774 sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
776 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
778 } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
779 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex)
781 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
783 memcpy(ComponentParameterStructure,
784 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT],
785 sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
786 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
789 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
790 eError = OMX_ErrorBadPortIndex;
794 case OMX_IndexParamAudioPortFormat:
795 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
796 G711DEC_DPRINT ("((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex = %d\n",(int)((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex);
797 G711DEC_DPRINT ("pComponentPrivate->sInPortFormat.nPortIndex= %d\n",(int)pComponentPrivate->sInPortFormat.nPortIndex );
798 G711DEC_DPRINT ("pComponentPrivate->sOutPortFormat.nPortIndex= %d\n",(int)pComponentPrivate->sOutPortFormat.nPortIndex);
800 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
801 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex)
804 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
806 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
807 pComponentPrivate->sInPortFormat.nIndex)
809 eError = OMX_ErrorNoMore;
813 memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat,
814 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
817 else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
818 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex){
820 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
822 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
823 pComponentPrivate->sOutPortFormat.nIndex)
825 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
826 eError = OMX_ErrorNoMore;
829 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
830 memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat,
831 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
835 G711DEC_DPRINT ("Inside the GetParameter Line %d\n",__LINE__);
836 eError = OMX_ErrorBadPortIndex;
840 case OMX_IndexParamAudioPcm:
841 G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
842 if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
843 pComponentPrivate->g711Params[G711DEC_INPUT_PORT]->nPortIndex){
844 G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
845 memcpy(ComponentParameterStructure,
846 pComponentPrivate->g711Params[G711DEC_INPUT_PORT],
847 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
849 } else if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
850 pComponentPrivate->g711Params[G711DEC_OUTPUT_PORT]->nPortIndex){
851 G711DEC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPcmG711 \n",__LINE__);
852 memcpy(ComponentParameterStructure,
853 pComponentPrivate->g711Params[G711DEC_OUTPUT_PORT],
854 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
857 eError = OMX_ErrorBadPortIndex;
861 case OMX_IndexParamCompBufferSupplier:
862 if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) {
863 G711DEC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
866 if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) {
867 G711DEC_DPRINT(":: GetParameter OMX_IndexParamCompBufferSupplier \n");
870 G711DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter");
871 eError = OMX_ErrorBadPortIndex;
875 case OMX_IndexParamPriorityMgmt:
878 case OMX_IndexParamVideoInit:
881 case OMX_IndexParamImageInit:
884 case OMX_IndexParamOtherInit:
889 eError = OMX_ErrorUnsupportedIndex;
893 G711DEC_DPRINT("%d :: Exiting GetParameter:: %x\n",__LINE__,nParamIndex);
897 /*-------------------------------------------------------------------*/
899 * SetParameter() Sets configuration paramets to the component
901 * @param hComp handle for this instance of the component
905 * @retval OMX_NoError Success, ready to roll
906 * OMX_Error_BadParameter The input parameter pointer is null
908 /*-------------------------------------------------------------------*/
910 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
911 OMX_INDEXTYPE nParamIndex,
914 OMX_ERRORTYPE eError = OMX_ErrorNone;
916 OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
917 OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
918 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
920 OMX_PARAM_COMPONENTROLETYPE *pRole = NULL;
921 OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
922 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
924 if (pCompParam == NULL) {
925 eError = OMX_ErrorBadParameter;
929 switch(nParamIndex) {
930 case OMX_IndexParamAudioPortFormat:
931 G711DEC_DPRINT("%d :: SetParameter OMX_IndexParamAudioPortFormat \n",__LINE__);
932 pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
933 if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat->nPortIndex )
935 memcpy(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
937 else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat->nPortIndex )
939 memcpy(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
943 G711DEC_DPRINT("%d :: OMX_ErrorBadPortIndex from SetParameter",__LINE__);
944 eError = OMX_ErrorBadPortIndex;
948 case OMX_IndexParamAudioPcm:
950 OMX_AUDIO_PARAM_PCMMODETYPE *pCompG711Param =
951 (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
954 if(pCompG711Param->nPortIndex == OMX_DirInput) {
955 memcpy(((G711DEC_COMPONENT_PRIVATE*)
956 pHandle->pComponentPrivate)->g711Params[G711DEC_INPUT_PORT],
957 pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
959 } else if (pCompG711Param->nPortIndex == OMX_DirOutput) {
961 memcpy(((G711DEC_COMPONENT_PRIVATE *)
962 pHandle->pComponentPrivate)->g711Params[G711DEC_OUTPUT_PORT],
963 pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
966 eError = OMX_ErrorBadPortIndex;
970 case OMX_IndexParamPortDefinition:
971 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
972 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex) {
974 memcpy(pComponentPrivate->pPortDef[G711DEC_INPUT_PORT],
975 pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
978 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
979 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex) {
981 memcpy(pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT],
982 pCompParam,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
986 eError = OMX_ErrorBadPortIndex;
990 case OMX_IndexParamPriorityMgmt:
991 if (pComponentPrivate->curState != OMX_StateLoaded) {
992 eError = OMX_ErrorIncorrectStateOperation;
996 case OMX_IndexParamStandardComponentRole:
998 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
999 memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
1001 eError = OMX_ErrorBadParameter;
1005 case OMX_IndexParamCompBufferSupplier:
1006 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1007 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nPortIndex) {
1008 G711DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1009 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
1010 memcpy(&sBufferSupplier, pCompParam,
1011 sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1013 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
1014 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nPortIndex) {
1015 G711DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
1016 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
1017 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
1020 G711DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
1021 eError = OMX_ErrorBadPortIndex;
1032 /*-------------------------------------------------------------------*/
1034 * GetConfig() Gets the current configuration of to the component
1036 * @param hComp handle for this instance of the component
1037 * @param nConfigIndex
1038 * @param ComponentConfigStructure
1040 * @retval OMX_NoError Success, ready to roll
1041 * OMX_Error_BadParameter The input parameter pointer is null
1043 /*-------------------------------------------------------------------*/
1045 static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1046 OMX_INDEXTYPE nConfigIndex,
1047 OMX_PTR ComponentConfigStructure)
1049 OMX_ERRORTYPE eError = OMX_ErrorNone;
1051 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1053 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1054 (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1055 if ((pComponentPrivate != NULL) && (ComponentConfigStructure != NULL))
1056 memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G711DEC_COMPONENT_PRIVATE));
1060 /*-------------------------------------------------------------------*/
1062 * SetConfig() Sets the configraiton to the component
1064 * @param hComp handle for this instance of the component
1065 * @param nConfigIndex
1066 * @param ComponentConfigStructure
1068 * @retval OMX_NoError Success, ready to roll
1069 * OMX_Error_BadParameter The input parameter pointer is null
1071 /*-------------------------------------------------------------------*/
1073 static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1074 OMX_INDEXTYPE nConfigIndex,
1075 OMX_PTR ComponentConfigStructure)
1077 OMX_ERRORTYPE eError = OMX_ErrorNone;
1078 OMX_S16* deviceString = NULL;
1079 TI_OMX_DATAPATH dataPath;
1080 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
1081 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1083 int *customFlag = NULL;
1084 TI_OMX_DSP_DEFINITION *configData = NULL;
1085 G711DEC_FTYPES *confFrameParams = NULL;
1086 OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
1087 OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
1089 G711DEC_DPRINT("%d :: Entering SetConfig\n", __LINE__);
1091 if (pHandle == NULL) {
1092 G711DEC_DPRINT ("%d :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__);
1093 eError = OMX_ErrorBadParameter;
1097 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1098 switch (nConfigIndex) {
1099 case OMX_IndexCustomG711DecHeaderInfoConfig:
1101 G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecHeaderInfoConfig \n",__LINE__);
1102 configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
1103 if (configData == NULL) {
1104 eError = OMX_ErrorBadParameter;
1105 G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1108 pComponentPrivate->acdnmode = configData->acousticMode;
1109 pComponentPrivate->dasfmode = configData->dasfMode;
1111 if (pComponentPrivate->dasfmode ){
1112 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled = 0;
1115 pComponentPrivate->streamID = configData->streamId;
1116 G711DEC_DPRINT("pComponentPrivate->acdnmode = %d\n",pComponentPrivate->acdnmode);
1117 G711DEC_DPRINT("pComponentPrivate->dasfmode = %d\n",pComponentPrivate->dasfmode);
1121 case OMX_IndexCustomG711DecModeAcdnConfig:
1123 G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecModeAcdnConfig \n",__LINE__);
1124 customFlag = (int*)ComponentConfigStructure;
1125 if (customFlag == NULL) {
1126 eError = OMX_ErrorBadParameter;
1127 G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1130 pComponentPrivate->acdnmode = *customFlag;
1131 G711DEC_DPRINT("pComponentPrivate->acdnmode = %d\n",pComponentPrivate->acdnmode);
1134 case OMX_IndexCustomG711DecModeDasfConfig:
1136 G711DEC_DPRINT("%d :: SetConfig OMX_IndexCustomG711DecModeDasfConfig \n",__LINE__);
1137 customFlag = (int*)ComponentConfigStructure;
1138 if (customFlag == NULL) {
1139 eError = OMX_ErrorBadParameter;
1140 G711DEC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
1143 pComponentPrivate->dasfmode = *customFlag;
1144 G711DEC_DPRINT("pComponentPrivate->dasfmode = %d\n",pComponentPrivate->dasfmode);
1145 if (pComponentPrivate->dasfmode ){
1146 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled = 0;
1151 case OMX_IndexCustomG711DecFrameParams:
1153 confFrameParams = (G711DEC_FTYPES*)ComponentConfigStructure;
1154 pComponentPrivate->ftype = confFrameParams->FrameSizeType;
1155 pComponentPrivate->nmulevel = confFrameParams->NmuNLvl;
1156 pComponentPrivate->noiselp = confFrameParams->NoiseLp;
1157 pComponentPrivate->dbmnoise = confFrameParams->dBmNoise;
1158 pComponentPrivate->packetlostc = confFrameParams->plc;
1162 case OMX_IndexCustomG711DecDataPath:
1163 deviceString = (OMX_S16*)ComponentConfigStructure;
1164 if (deviceString == NULL)
1166 eError = OMX_ErrorBadParameter;
1170 dataPath = *deviceString;
1174 case DATAPATH_APPLICATION:
1175 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID);
1178 case DATAPATH_APPLICATION_RTMIXER:
1179 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1183 strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1191 #ifdef DSP_RENDERING_ON
1192 case OMX_IndexConfigAudioMute:
1194 pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure;
1195 G711DEC_PRINT("Set Mute/Unmute for playback stream\n");
1196 cmd_data.hComponent = hComp;
1197 if(pMuteStructure->bMute == OMX_TRUE)
1199 G711DEC_PRINT("Mute the playback stream\n");
1200 cmd_data.AM_Cmd = AM_CommandStreamMute;
1204 G711DEC_PRINT("unMute the playback stream\n");
1205 cmd_data.AM_Cmd = AM_CommandStreamUnMute;
1207 cmd_data.param1 = 0;
1208 cmd_data.param2 = 0;
1209 cmd_data.streamID = pComponentPrivate->streamID;
1210 if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1212 G711DEC_DPRINT("[G711 decoder] - fail to send Mute command to audio manager\n");
1213 G711DEC_PRINT("No pudo escribir al Pipe del Audio Manager\n");
1218 case OMX_IndexConfigAudioVolume:
1220 pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
1221 G711DEC_PRINT("Set volume for playback stream\n");
1222 cmd_data.hComponent = hComp;
1223 cmd_data.AM_Cmd = AM_CommandSWGain;
1224 cmd_data.param1 = pVolumeStructure->sVolume.nValue;
1225 cmd_data.param2 = 0;
1226 cmd_data.streamID = pComponentPrivate->streamID;
1228 if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
1230 G711DEC_DPRINT("[G711 decoder] - fail to send Volume command to audio manager\n");
1237 eError = OMX_ErrorUnsupportedIndex;
1241 G711DEC_DPRINT("%d :: Exiting SetConfig\n", __LINE__);
1242 G711DEC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
1246 /*-------------------------------------------------------------------*/
1248 * GetState() Gets the current state of the component
1250 * @param pCompomponent handle for this instance of the component
1253 * @retval OMX_NoError Success, ready to roll
1254 * OMX_Error_BadParameter The input parameter pointer is null
1256 /*-------------------------------------------------------------------*/
1258 static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1260 OMX_ERRORTYPE error = OMX_ErrorUndefined;
1261 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1264 error = OMX_ErrorBadParameter;
1265 G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1269 if (pHandle && pHandle->pComponentPrivate) {
1270 *pState = ((G711DEC_COMPONENT_PRIVATE*)
1271 pHandle->pComponentPrivate)->curState;
1273 *pState = OMX_StateLoaded;
1276 error = OMX_ErrorNone;
1282 /*-------------------------------------------------------------------*/
1284 * EmptyThisBuffer() This callback is used to send the input buffer to
1287 * @param pComponent handle for this instance of the component
1288 * @param nPortIndex input port index
1289 * @param pBuffer buffer to be sent to codec
1291 * @retval OMX_NoError Success, ready to roll
1292 * OMX_Error_BadParameter The input parameter pointer is null
1294 /*-------------------------------------------------------------------*/
1296 static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1297 OMX_BUFFERHEADERTYPE* pBuffer)
1299 OMX_ERRORTYPE eError = OMX_ErrorNone;
1300 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1301 G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1302 (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1304 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1307 pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1308 pComponentPrivate)->pPortDef[G711DEC_INPUT_PORT];
1310 if(!pPortDef->bEnabled) {
1311 G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1312 eError = OMX_ErrorIncorrectStateOperation;
1316 if (pBuffer == NULL) {
1317 eError = OMX_ErrorBadParameter;
1318 G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1322 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1323 eError = OMX_ErrorBadParameter;
1327 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1328 eError = OMX_ErrorVersionMismatch;
1332 if (pBuffer->nInputPortIndex != G711DEC_INPUT_PORT) {
1333 eError = OMX_ErrorBadPortIndex;
1337 G711DEC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
1339 if(pComponentPrivate->curState != OMX_StateExecuting &&
1340 pComponentPrivate->curState != OMX_StatePause) {
1341 G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1342 eError = OMX_ErrorIncorrectStateOperation;
1346 G711DEC_DPRINT("\n------------------------------------------\n\n");
1347 G711DEC_DPRINT ("%d :: Component Sending Filled ip buff %p \
1348 to Component Thread\n",__LINE__,pBuffer);
1349 G711DEC_DPRINT("\n------------------------------------------\n\n");
1351 pComponentPrivate->app_nBuf--;
1353 pComponentPrivate->pMarkData = pBuffer->pMarkData;
1354 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1356 ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1357 sizeof(OMX_BUFFERHEADERTYPE*));
1360 G711DEC_DPRINT ("%d :: Error in Writing to the Data pipe\n", __LINE__);
1361 eError = OMX_ErrorHardware;
1364 pComponentPrivate->nEmptyThisBufferCount++;
1369 /*-------------------------------------------------------------------*/
1371 * FillThisBuffer() This callback is used to send the output buffer to
1374 * @param pComponent handle for this instance of the component
1375 * @param nPortIndex output port number
1376 * @param pBuffer buffer to be sent to codec
1378 * @retval OMX_NoError Success, ready to roll
1379 * OMX_Error_BadParameter The input parameter pointer is null
1381 /*-------------------------------------------------------------------*/
1383 static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1384 OMX_BUFFERHEADERTYPE* pBuffer)
1386 OMX_ERRORTYPE eError = OMX_ErrorNone;
1387 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1388 G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1389 (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1391 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1392 G711DEC_DPRINT("\n------------------------------------------\n\n");
1393 G711DEC_DPRINT ("%d :: Component Sending Emptied op buff %p \
1394 to Component Thread\n",__LINE__,pBuffer);
1395 G711DEC_DPRINT("\n------------------------------------------\n\n");
1397 pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1398 pComponentPrivate)->pPortDef[G711DEC_OUTPUT_PORT];
1400 if(!pPortDef->bEnabled) {
1401 G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1402 eError = OMX_ErrorIncorrectStateOperation;
1406 if (pBuffer == NULL) {
1407 eError = OMX_ErrorBadParameter;
1408 G711DEC_DPRINT("About to return OMX_ErrorBadParameter on line %d\n",__LINE__);
1412 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1413 eError = OMX_ErrorBadParameter;
1418 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1419 eError = OMX_ErrorVersionMismatch;
1423 if (pBuffer->nOutputPortIndex != G711DEC_OUTPUT_PORT) {
1424 eError = OMX_ErrorBadPortIndex;
1428 G711DEC_DPRINT("pComponentPrivate->curState = %d\n",pComponentPrivate->curState);
1430 if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
1431 G711DEC_DPRINT("About to return OMX_ErrorIncorrectStateOperation Line %d\n",__LINE__);
1432 eError = OMX_ErrorIncorrectStateOperation;
1436 G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1438 pBuffer->nFilledLen = 0;
1440 G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1442 /*Filling the Output buffer with zero */
1444 memset (pBuffer->pBuffer,0,OUTPUT_G711DEC_BUFFER_SIZE);
1446 memset (pBuffer->pBuffer,0,pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nBufferSize);
1448 G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1450 pComponentPrivate->app_nBuf--;
1452 G711DEC_DPRINT("%d:Decrementing app_nBuf = %d\n",__LINE__,(int)pComponentPrivate->app_nBuf);
1453 G711DEC_DPRINT("pComponentPrivate->pMarkBuf = 0x%x\n",(int)pComponentPrivate->pMarkBuf);
1454 G711DEC_DPRINT("pComponentPrivate->pMarkData = 0x%x\n",(int)pComponentPrivate->pMarkData);
1456 if(pComponentPrivate->pMarkBuf){
1457 G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1458 pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1459 pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1460 pComponentPrivate->pMarkBuf = NULL;
1463 if (pComponentPrivate->pMarkData) {
1464 G711DEC_DPRINT("FillThisBuffer Line %d\n",__LINE__);
1465 pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1466 pBuffer->pMarkData = pComponentPrivate->pMarkData;
1467 pComponentPrivate->pMarkData = NULL;
1470 write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof (OMX_BUFFERHEADERTYPE*));
1471 pComponentPrivate->nFillThisBufferCount++;
1476 /*-------------------------------------------------------------------*/
1478 * OMX_ComponentDeinit() this methold will de init the component
1480 * @param pComp handle for this instance of the component
1482 * @retval OMX_NoError Success, ready to roll
1483 * OMX_Error_BadParameter The input parameter pointer is null
1485 /*-------------------------------------------------------------------*/
1487 static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1489 OMX_ERRORTYPE eError = OMX_ErrorNone;
1491 /* inform audio manager to remove the streamID*/
1492 /* compose the data */
1493 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1494 G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
1495 (G711DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1497 G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1499 #ifdef DSP_RENDERING_ON
1500 close(pComponentPrivate->fdwrite);
1501 close(pComponentPrivate->fdread);
1504 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
1506 #ifdef RESOURCE_MANAGER_ENABLED
1507 RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource,
1508 OMX_G711_Decoder_COMPONENT,
1510 if (eError != OMX_ErrorNone) {
1511 G711DEC_DPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1514 eError = RMProxy_Deinitalize();
1515 if (eError != OMX_ErrorNone) {
1516 G711DEC_DPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1520 G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1522 G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1523 pComponentPrivate->bIsStopping = 1;
1524 eError = G711DEC_StopComponentThread(pHandle);
1525 G711DEC_DPRINT ("%d ::ComponentDeInit\n",__LINE__);
1526 /* Wait for thread to exit so we can get the status into "error" */
1528 /* close the pipe handles */
1529 G711DEC_FreeCompResources(pHandle);
1530 G711DEC_DPRINT ("%d ::After G711DEC_FreeCompResources\n",__LINE__);
1531 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate);
1532 G711DEC_DPRINT ("%d ::After free(pComponentPrivate)\n",__LINE__);
1537 /*-------------------------------------------------------------------*/
1539 * ComponentTunnelRequest() this method is not implemented in 1.5
1541 * This method will update application callbacks
1544 * @param pComp handle for this instance of the component
1545 * @param pCallBacks application callbacks
1548 * @retval OMX_NoError Success, ready to roll
1549 * OMX_Error_BadParameter The input parameter pointer is null
1551 /*-------------------------------------------------------------------*/
1553 static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1554 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1555 OMX_U32 nTunneledPort,
1556 OMX_TUNNELSETUPTYPE* pTunnelSetup)
1558 OMX_ERRORTYPE eError = OMX_ErrorNone;
1559 G711DEC_DPRINT (stderr, "Inside the ComponentTunnelRequest\n");
1560 eError = OMX_ErrorNotImplemented;
1564 /*-------------------------------------------------------------------*/
1568 * @param pComp handle for this instance of the component
1569 * @param pCallBacks application callbacks
1572 * @retval OMX_NoError Success, ready to roll
1573 * OMX_Error_BadParameter The input parameter pointer is null
1575 /*-------------------------------------------------------------------*/
1577 static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1578 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1579 OMX_IN OMX_U32 nPortIndex,
1580 OMX_IN OMX_PTR pAppPrivate,
1581 OMX_IN OMX_U32 nSizeBytes)
1584 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1585 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1586 OMX_ERRORTYPE eError = OMX_ErrorNone;
1587 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1589 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1590 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1592 pPortDef = ((G711DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
1594 G711DEC_DPRINT ("%d :: pPortDef = 0x%x\n", __LINE__,(unsigned int)pPortDef);
1595 G711DEC_DPRINT("%d :: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled);
1596 G711DEC_DPRINT("pPortDef->bEnabled = %d\n", pPortDef->bEnabled);
1598 if(!pPortDef->bEnabled){
1599 G711DEC_DPRINT ("%d :: BLOCK!! AlloBuf_threshold\n", __LINE__);
1600 pComponentPrivate->AlloBuf_waitingsignal = 1;
1602 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1603 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold,
1604 &pComponentPrivate->AlloBuf_mutex);
1605 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1607 OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1611 G711D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1612 G711D_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, (nSizeBytes + EXTRA_BUFFBYTES), OMX_U8 );
1615 memset(pBufferHeader->pBuffer, 0, (nSizeBytes + EXTRA_BUFFBYTES));
1618 pBufferHeader->pBuffer += CACHE_ALIGNMENT;
1620 if (nPortIndex == G711DEC_INPUT_PORT) {
1621 pBufferHeader->nInputPortIndex = nPortIndex;
1622 pBufferHeader->nOutputPortIndex = -1;
1623 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1624 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1625 G711DEC_DPRINT("pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p \n",(int)pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1626 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1627 G711DEC_DPRINT("Allocate Buffer Line %d\n",__LINE__);
1628 G711DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %d\n",(int)pComponentPrivate->pInputBufferList->numBuffers);
1629 G711DEC_DPRINT("pPortDef->nBufferCountMin = %d\n",(int)pPortDef->nBufferCountMin);
1630 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1631 G711DEC_DPRINT("Setting pPortDef->bPopulated = OMX_TRUE for input port\n");
1632 pPortDef->bPopulated = OMX_TRUE;
1635 else if (nPortIndex == G711DEC_OUTPUT_PORT) {
1636 pBufferHeader->nInputPortIndex = -1;
1637 pBufferHeader->nOutputPortIndex = nPortIndex;
1638 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1639 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1640 G711DEC_DPRINT("pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p \n",(int)pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1641 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1642 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1643 G711DEC_DPRINT("Setting pPortDef->bPopulated = OMX_TRUE for input port\n");
1644 pPortDef->bPopulated = OMX_TRUE;
1648 eError = OMX_ErrorBadPortIndex;
1651 if((pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated ==
1652 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled) &&
1653 (pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated ==
1654 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled) &&
1655 (pComponentPrivate->InLoaded_readytoidle))
1657 pComponentPrivate->InLoaded_readytoidle = 0;
1659 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1660 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1661 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1663 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1667 pBufferHeader->pAppPrivate = pAppPrivate;
1668 pBufferHeader->pPlatformPrivate = pComponentPrivate;
1669 pBufferHeader->nAllocLen = nSizeBytes;
1670 pBufferHeader->nVersion.s.nVersionMajor = G711DEC_MAJOR_VER;
1671 pBufferHeader->nVersion.s.nVersionMinor = G711DEC_MINOR_VER;
1672 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1675 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1676 *pBuffer = pBufferHeader;
1678 if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
1680 SendCommand(pComponentPrivate->pHandle,
1681 OMX_CommandPortEnable,
1682 pComponentPrivate->bEnableCommandParam,
1687 G711DEC_DPRINT("AllocateBuffer returning %d\n",eError);
1691 /*------------------------------------------------------------------*/
1695 * @param hComponent handle for this instance of the component
1696 * @param pCallBacks application callbacks
1699 * @retval OMX_NoError Success, ready to roll
1700 * OMX_Error_BadParameter The input parameter pointer is null
1702 /*-------------------------------------------------------------------*/
1703 static OMX_ERRORTYPE FreeBuffer(
1704 OMX_IN OMX_HANDLETYPE hComponent,
1705 OMX_IN OMX_U32 nPortIndex,
1706 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer)
1708 OMX_ERRORTYPE eError = OMX_ErrorNone;
1709 G711DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1710 OMX_BUFFERHEADERTYPE* buff = NULL;
1711 OMX_U8* tempBuff = NULL;
1713 OMX_S16 inputIndex = -1;
1714 OMX_S16 outputIndex = -1;
1715 OMX_COMPONENTTYPE *pHandle = NULL;
1717 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1718 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1720 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
1721 for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1722 buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
1723 if (buff == pBuffer) {
1724 G711DEC_DPRINT("Found matching input buffer\n");
1725 G711DEC_DPRINT("buff = %p\n",buff);
1726 G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1731 G711DEC_DPRINT("This is not a match\n");
1732 G711DEC_DPRINT("buff = %p\n",buff);
1733 G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1737 for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1738 buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
1739 if (buff == pBuffer) {
1740 G711DEC_DPRINT("Found matching output buffer\n");
1741 G711DEC_DPRINT("buff = %p\n",buff);
1742 G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1747 G711DEC_DPRINT("This is not a match\n");
1748 G711DEC_DPRINT("buff = %p\n",buff);
1749 G711DEC_DPRINT("pBuffer = %p\n",pBuffer);
1754 if (inputIndex != -1) {
1755 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
1756 tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
1757 tempBuff -= CACHE_ALIGNMENT;
1758 OMX_G711DECMEMFREE_STRUCT(tempBuff);
1760 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1761 pComponentPrivate->pInputBufferList->numBuffers--;
1762 G711DEC_DPRINT("INPUT :: numBuffers %d, nBufferCountActual %d\n",
1763 (int)pComponentPrivate->pInputBufferList->numBuffers,
1764 (int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual);
1765 if (pComponentPrivate->pInputBufferList->numBuffers <
1766 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual) {
1767 G711DEC_DPRINT("setting input port populated to OMX_FALSE\n");
1768 pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated = OMX_FALSE;
1770 if(pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled &&
1771 pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1772 (pComponentPrivate->curState == OMX_StateIdle ||
1773 pComponentPrivate->curState == OMX_StateExecuting ||
1774 pComponentPrivate->curState == OMX_StatePause))
1776 pComponentPrivate->cbInfo.EventHandler(pHandle,
1777 pHandle->pApplicationPrivate,
1779 OMX_ErrorPortUnpopulated,
1783 else if (outputIndex != -1) {
1784 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
1785 tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
1786 tempBuff -= CACHE_ALIGNMENT;
1787 OMX_G711DECMEMFREE_STRUCT(tempBuff);
1790 OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1791 pComponentPrivate->pOutputBufferList->numBuffers--;
1792 G711DEC_DPRINT("OUTPUT :: numBuffers %d, nBufferCountActual %d\n",
1793 (int)pComponentPrivate->pInputBufferList->numBuffers,
1794 (int)pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferCountActual);
1796 if (pComponentPrivate->pOutputBufferList->numBuffers <
1797 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nBufferCountActual) {
1798 G711DEC_DPRINT("setting output port populated to OMX_FALSE\n");
1799 pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated = OMX_FALSE;
1802 if(pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled &&
1803 pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1804 (pComponentPrivate->curState == OMX_StateIdle ||
1805 pComponentPrivate->curState == OMX_StateExecuting ||
1806 pComponentPrivate->curState == OMX_StatePause))
1808 pComponentPrivate->cbInfo.EventHandler(
1809 pHandle, pHandle->pApplicationPrivate,
1810 OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1814 G711DEC_DPRINT("%d::Returning OMX_ErrorBadParameter\n",__LINE__);
1815 eError = OMX_ErrorBadParameter;
1818 if ((!pComponentPrivate->pInputBufferList->numBuffers &&
1819 !pComponentPrivate->pOutputBufferList->numBuffers) &&
1820 pComponentPrivate->InIdle_goingtoloaded)
1822 pComponentPrivate->InIdle_goingtoloaded = 0;
1824 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1825 pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
1826 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1828 OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
1831 /* Removing sleep() calls. There are no allocated buffers. */
1833 G711DEC_DPRINT("pComponentPrivate->bDisableCommandPending = %d\n",(int)pComponentPrivate->bDisableCommandPending);
1834 if (pComponentPrivate->bDisableCommandPending) {
1835 if (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0) {
1836 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL);
1839 G711DEC_DPRINT ("%d :: Exiting FreeBuffer\n", __LINE__);
1843 /*-------------------------------------------------------------------*/
1847 * @param pComp handle for this instance of the component
1848 * @param pCallBacks application callbacks
1851 * @retval OMX_NoError Success, ready to roll
1852 * OMX_Error_BadParameter The input parameter pointer is null
1854 /*-------------------------------------------------------------------*/
1855 static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1856 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1857 OMX_IN OMX_U32 nPortIndex,
1858 OMX_IN OMX_PTR pAppPrivate,
1859 OMX_IN OMX_U32 nSizeBytes,
1860 OMX_IN OMX_U8* pBuffer)
1862 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1863 G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1864 OMX_ERRORTYPE eError = OMX_ErrorNone;
1865 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1867 pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
1868 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1870 pPortDef = ((G711DEC_COMPONENT_PRIVATE*)
1871 pComponentPrivate)->pPortDef[nPortIndex];
1873 G711DEC_DPRINT("pPortDef->bPopulated = %d\n",pPortDef->bPopulated);
1875 if(!pPortDef->bEnabled) {
1876 G711DEC_DPRINT ("%d :: In AllocateBuffer\n", __LINE__);
1877 eError = OMX_ErrorIncorrectStateOperation;
1881 if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) {
1882 G711DEC_DPRINT ("%d :: In AllocateBuffer\n", __LINE__);
1883 eError = OMX_ErrorBadParameter;
1887 G711D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1889 if (nPortIndex == G711DEC_OUTPUT_PORT) {
1890 pBufferHeader->nInputPortIndex = -1;
1891 pBufferHeader->nOutputPortIndex = nPortIndex;
1892 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1893 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1894 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
1895 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1896 pPortDef->bPopulated = OMX_TRUE;
1900 pBufferHeader->nInputPortIndex = nPortIndex;
1901 pBufferHeader->nOutputPortIndex = -1;
1902 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1903 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1904 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
1906 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1907 pPortDef->bPopulated = OMX_TRUE;
1911 if((pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->bEnabled)&&
1912 (pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->bEnabled) &&
1913 (pComponentPrivate->InLoaded_readytoidle))
1915 pComponentPrivate->InLoaded_readytoidle = 0;
1917 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1918 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1919 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1921 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1925 pBufferHeader->pAppPrivate = pAppPrivate;
1926 pBufferHeader->pPlatformPrivate = pComponentPrivate;
1927 pBufferHeader->nAllocLen = nSizeBytes;
1928 pBufferHeader->nVersion.s.nVersionMajor = G711DEC_MAJOR_VER;
1929 pBufferHeader->nVersion.s.nVersionMinor = G711DEC_MINOR_VER;
1930 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1931 pBufferHeader->pBuffer = pBuffer;
1932 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1933 *ppBufferHdr = pBufferHeader;
1935 G711DEC_DPRINT("pBufferHeader = %p\n",pBufferHeader);
1937 if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
1939 SendCommand(pComponentPrivate->pHandle, OMX_CommandPortEnable,
1940 pComponentPrivate->bEnableCommandParam, NULL);
1947 /* ================================================================================= */
1949 * @fn GetExtensionIndex() description for GetExtensionIndex
1950 GetExtensionIndex().
1951 Returns index for vendor specific settings.
1955 /* ================================================================================ */
1956 static OMX_ERRORTYPE GetExtensionIndex( OMX_IN OMX_HANDLETYPE hComponent,
1957 OMX_IN OMX_STRING cParameterName,
1958 OMX_OUT OMX_INDEXTYPE *pIndexType)
1960 OMX_ERRORTYPE eError = OMX_ErrorNone;
1962 if(!(strcmp(cParameterName,"OMX.TI.index.config.g711headerinfo"))) {
1963 *pIndexType = OMX_IndexCustomG711DecHeaderInfoConfig;
1965 else if(!(strcmp(cParameterName,"OMX.TI.index.config.g711dec.datapath")))
1967 *pIndexType = OMX_IndexCustomG711DecDataPath;
1969 else if(!strcmp(cParameterName,"OMX.TI.index.config.g711dec.frameparams"))
1971 *pIndexType = OMX_IndexCustomG711DecFrameParams;
1976 eError = OMX_ErrorBadParameter;
1981 /* ================================================================================= */
1983 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
1985 Returns the role at the given index
1989 /* ================================================================================ */
1990 static OMX_ERRORTYPE ComponentRoleEnum( OMX_IN OMX_HANDLETYPE hComponent,
1991 OMX_OUT OMX_U8 *cRole,
1992 OMX_IN OMX_U32 nIndex)
1994 /*G711DEC_COMPONENT_PRIVATE *pComponentPrivate;*/
1995 OMX_ERRORTYPE eError = OMX_ErrorNone;
1996 /* This is a non standard component and does not support roles */
1997 eError = OMX_ErrorNotImplemented;
2002 #ifdef G711DEC_MEMDEBUG
2003 void * mymalloc(int line, char *s, int size)
2010 G711DEC_PRINT("Memory not available\n");
2014 while((lines[e]!=0)&& (e<500) ){
2021 G711DEC_PRINT("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
2026 void myfree(void *dp, int line, char *s){
2030 G711DEC_PRINT("Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
2039 G711DEC_PRINT("\n\nPointer not found. Line:%d File%s!!\n\n",line, s);