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_WmaDec_Utils.c
31 * This file implements OMX Component for WMA decoder that
32 * is fully compliant with the OMX Audio specification 1.0.
38 /* ----------------------------------------------------------------------------
41 *! ===================================
42 *! 10-Sept-2005 mf: Initial Version. Change required per OMAPSWxxxxxxxxx
43 *! to provide _________________.
47 *! This is newest file
48 * =========================================================================== */
51 /* ------compilation control switches -------------------------*/
52 /****************************************************************
54 ****************************************************************/
55 /* ----- system and platform files ----------------------------*/
63 #include <sys/types.h>
65 #include <sys/types.h>
78 #include "OMX_WmaDec_Utils.h"
79 #include "wmadecsocket_ti.h"
80 #include <decode_common_ti.h>
84 #define HASHINGENABLE 1
87 void sleep(DWORD Duration)
93 /* ========================================================================== */
95 * @WMADECFill_LCMLInitParams () This function is used by the component thread to
96 * fill the all of its initialization parameters, buffer deatils etc
99 * @param pComponent handle for this instance of the component
100 * @param plcml_Init pointer to LCML structure to be filled
108 /* ========================================================================== */
109 OMX_ERRORTYPE WMADECFill_LCMLInitParams(OMX_COMPONENTTYPE* pComponent,
110 LCML_DSP *plcml_Init, OMX_U16 arr[])
112 OMX_ERRORTYPE eError = OMX_ErrorNone;
113 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
115 OMX_BUFFERHEADERTYPE *pTemp;
118 LCML_WMADEC_BUFHEADERTYPE *pTemp_lcml = NULL;
119 LCML_STRMATTR *strmAttr = NULL;
120 LCML_DSP_INTERFACE *pHandle;
121 WMADEC_COMPONENT_PRIVATE *pComponentPrivate, *pComponentPrivate_CC;
123 pComponentPrivate = pComponent->pComponentPrivate;
124 pComponentPrivate_CC = pComponentPrivate;
125 pHandle = (LCML_DSP_INTERFACE *)pComponent;
127 OMX_PRINT2(pComponentPrivate->dbg, "[WMADECFill_LCMLInitParams] pComponent = %p",pComponent);
128 OMX_PRINT2(pComponentPrivate->dbg, "[WMADECFill_LCMLInitParams] pComponentPrivate = %p",
130 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entered WMADECFill_LCMLInitParams",__LINE__);
131 OMX_PRINT2(pComponentPrivate->dbg, "%d :: WMADECFill_LCMLInitParams - pComponentPrivate = %p",
132 __LINE__,pComponentPrivate);
133 OMX_PRINT2(pComponentPrivate->dbg, "%d :: WMADECFill_LCMLInitParams - pHandle = %p",__LINE__,
136 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
137 pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
138 nIpBufSize = INPUT_WMADEC_BUFFER_SIZE;
139 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
140 pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
141 nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
143 /* Fill Input Buffers Info for LCML */
144 plcml_Init->In_BufInfo.nBuffers = nIpBuf;
145 plcml_Init->In_BufInfo.nSize = nIpBufSize;
146 plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
149 /* Fill Output Buffers Info for LCML */
150 plcml_Init->Out_BufInfo.nBuffers = pComponentPrivate_CC->pOutputBufferList->numBuffers;
151 plcml_Init->Out_BufInfo.nSize = nOpBufSize;
152 plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
154 /*Copy the node information */
155 plcml_Init->NodeInfo.nNumOfDLLs = 3;
157 plcml_Init->NodeInfo.AllUUIDs[0].uuid = &WMADECSOCKET_TI_UUID;
159 strcpy ((char *) plcml_Init->NodeInfo.AllUUIDs[0].DllName,WMADEC_DLL_NAME);
160 plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
162 plcml_Init->NodeInfo.AllUUIDs[1].uuid = &WMADECSOCKET_TI_UUID;
163 strcpy ((char *) plcml_Init->NodeInfo.AllUUIDs[1].DllName,WMADEC_DLL_NAME);
164 plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
166 plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
167 strcpy ((char *) plcml_Init->NodeInfo.AllUUIDs[2].DllName,WMADEC_USN_DLL_NAME);
168 plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
171 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
172 plcml_Init->DeviceInfo.TypeofDevice =0;
174 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pDynParams, sizeof(WMADEC_UALGParams), WMADEC_UALGParams);
176 pComponentPrivate->first_buffer=1;
178 if(pComponentPrivate_CC->dasfmode == 1)
180 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(WMADEC_AudioCodecParams), WMADEC_AudioCodecParams);
182 OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
183 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,strmAttr);
185 if (strmAttr == NULL)
187 OMX_ERROR4(pComponentPrivate->dbg, "strmAttr - failed to malloc");
188 eError = OMX_ErrorInsufficientResources;
191 pComponentPrivate_CC->strmAttr = strmAttr;
192 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,strmAttr);
193 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
195 strmAttr->uSegid = 0;
196 strmAttr->uAlignment = 0;
197 strmAttr->uTimeout = -1;
198 strmAttr->uBufsize = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize;
199 strmAttr->uNumBufs = NUM_WMADEC_OUTPUT_BUFFERS_DASF;
200 strmAttr->lMode = STRMMODE_PROCCOPY;
201 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
203 plcml_Init->DeviceInfo.TypeofDevice =1;
204 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
205 plcml_Init->DeviceInfo.DspStream = strmAttr;
208 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
210 /*copy the other information */
211 plcml_Init->SegID = OMX_WMADEC_DEFAULT_SEGMENT;
212 plcml_Init->Timeout = OMX_WMADEC_SN_TIMEOUT;
213 plcml_Init->Alignment = 0;
214 plcml_Init->Priority = OMX_WMADEC_SN_PRIORITY;
215 plcml_Init->ProfileID = -1;
216 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
217 pComponentPrivate_CC->iWmaSamplingFrequeny = WMADEC_DEFAULT_SAMPLING_FREQUENCY;
219 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
222 /*Accessing these 2 has the problem/creates problem in state transition tests*/
223 pComponentPrivate_CC->iWmaChannels =
224 pComponentPrivate_CC->wmaParams[OUTPUT_PORT]->nChannels;
225 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
227 arr[0] = WMADEC_STREAM_COUNT;
230 if (pComponentPrivate_CC->pInputBufferList->numBuffers)
232 arr[3] = pComponentPrivate_CC->pInputBufferList->numBuffers;
239 arr[4] = OUTPUT_PORT;
241 if(pComponentPrivate_CC->dasfmode == 1)
244 arr[6] = NUM_WMADEC_OUTPUT_BUFFERS_DASF;
248 OMX_PRDSP2(pComponentPrivate->dbg, "FILE MODE");
250 if (pComponentPrivate_CC->pOutputBufferList->numBuffers)
252 arr[6] = pComponentPrivate_CC->pOutputBufferList->numBuffers;
259 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
261 index = WMADEC_STREAM_COUNT * 3 + 1;
262 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
266 arr[index] = END_OF_CR_PHASE_ARGS;
268 for (i=0; i < index+1; i++) {
269 OMX_PRINT2(pComponentPrivate->dbg, "arr[%d] = %d",i,arr[i]);
273 arr[7] = END_OF_CR_PHASE_ARGS;
276 plcml_Init->pCrPhArgs = arr;
278 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
279 size_lcml = nIpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
280 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
281 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
282 OMX_PRDSP2(pComponentPrivate->dbg, "Line %d::pTemp_lcml = %p",__LINE__,pTemp_lcml);
283 if(pTemp_lcml == NULL)
285 /* Free previously allocated memory before bailing */
286 OMX_MEMFREE_STRUCT(strmAttr);
287 eError = OMX_ErrorInsufficientResources;
290 pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
292 OMX_PRBUFFER2(pComponentPrivate->dbg, "nIpBuf = %ld",nIpBuf);
293 for (i=0; i<nIpBuf; i++)
295 pTemp = pComponentPrivate_CC->pInputBufferList->pBufHdr[i];
296 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
297 pTemp->nAllocLen = nIpBufSize;
298 if(pComponentPrivate_CC->dasfmode == 0)
300 pTemp->nFilledLen = nIpBufSize;
304 pTemp->nFilledLen = 0;
306 pTemp->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
307 pTemp->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
308 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
309 pTemp->nTickCount = NOT_USED;
310 pTemp_lcml->buffer = pTemp;
311 pTemp_lcml->eDir = OMX_DirInput;
312 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
313 sizeof(WMADEC_UAlgInBufParamStruct),
314 WMADEC_UAlgInBufParamStruct);
315 if (pTemp_lcml->pIpParam == NULL)
317 /* Free previously allocated memory before bailing */
318 OMX_MEMFREE_STRUCT(strmAttr);
319 OMX_MEMFREE_STRUCT(pTemp_lcml );
323 pTemp_lcml->pIpParam->bLastBuffer = 0;
325 /* This means, it is not a last buffer. This flag is to be modified by
326 * the application to indicate the last buffer */
327 pTemp->nFlags = NORMAL_BUFFER;
332 /* Allocate memory for all output buffer headers..
333 * This memory pointer will be sent to LCML */
334 size_lcml = pComponentPrivate_CC->pOutputBufferList->numBuffers * sizeof(LCML_WMADEC_BUFHEADERTYPE);
335 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
336 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
337 if(pTemp_lcml == NULL)
339 /* Free previously allocated memory before bailing */
340 OMX_MEMFREE_STRUCT(strmAttr);
341 eError = OMX_ErrorInsufficientResources;
344 pComponentPrivate_CC->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
346 pComponentPrivate_CC->pOutputBufferList->EosFlagSent = 0;
347 pComponentPrivate_CC->InputEosSet = 0;
349 for (i=0; i<nOpBuf; i++)
351 pTemp = pComponentPrivate_CC->pOutputBufferList->pBufHdr[i];
352 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
353 pTemp->nAllocLen = nOpBufSize;
354 pTemp->nFilledLen = nOpBufSize;
355 pTemp->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
356 pTemp->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
357 pComponentPrivate_CC->nVersion = pTemp->nVersion.nVersion;
358 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
359 pTemp->nTickCount = NOT_USED;
360 /* This means, it is not a last buffer. This flag is to be modified by
361 * the application to indicate the last buffer */
363 pTemp_lcml->buffer = pTemp;
364 pTemp_lcml->eDir = OMX_DirOutput;
366 pTemp->nFlags = NORMAL_BUFFER;
371 pComponentPrivate_CC->bPortDefsAllocated = 1;
373 #ifdef __PERF_INSTRUMENTATION__
374 pComponentPrivate_CC->nLcml_nCntIp = 0;
375 pComponentPrivate_CC->nLcml_nCntOpReceived = 0;
377 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting WMADECFill_LCMLInitParams",__LINE__);
379 pComponentPrivate_CC->bInitParamsInitialized = 1;
385 /* ========================================================================== */
387 * @WMADEC_StartComponentThread() This function is called by the component to create
388 * the component thread, command pipe, data pipe and LCML Pipe.
390 * @param pComponent handle for this instance of the component
398 /* ========================================================================== */
399 OMX_ERRORTYPE WMADEC_StartComponentThread(OMX_HANDLETYPE pComponent)
402 OMX_ERRORTYPE eError = OMX_ErrorNone;
403 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
404 WMADEC_COMPONENT_PRIVATE *pComponentPrivate =
405 (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
408 memset(&attr, 0, sizeof(attr));
409 attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
410 attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY;
413 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Inside WMADEC_StartComponentThread", __LINE__);
414 /* Initialize all the variables*/
415 pComponentPrivate->bIsStopping = 0;
416 pComponentPrivate->bIsEOFSent = 0;
420 OMX_PRINT2(pComponentPrivate->dbg, "WMADEC_StartComponentThread pComponentPrivate = %p",
422 /* create the pipe used to send buffers to the thread */
423 eError = pipe (pComponentPrivate->cmdDataPipe);
426 eError = OMX_ErrorInsufficientResources;
430 /* create the pipe used to send buffers to the thread */
431 eError = pipe (pComponentPrivate->dataPipe);
434 eError = OMX_ErrorInsufficientResources;
438 /* create the pipe used to send commands to the thread */
439 eError = pipe (pComponentPrivate->cmdPipe);
442 eError = OMX_ErrorInsufficientResources;
446 /* Create the Component Thread */
448 eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr,
449 WMADEC_ComponentThread, pComponentPrivate);
451 eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL,
452 WMADEC_ComponentThread, pComponentPrivate);
454 if (eError || !pComponentPrivate->ComponentThread)
456 eError = OMX_ErrorInsufficientResources;
459 pComponentPrivate->bCompThreadStarted = 1;
461 if (eError != OMX_ErrorNone ) {
462 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
463 pComponentPrivate->pHandle->pApplicationPrivate,
472 /* ========================================================================== */
474 * @Mp3Dec_FreeCompResources() This function is called by the component during
475 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
477 * @param pComponent handle for this instance of the component
485 /* ========================================================================== */
487 OMX_ERRORTYPE WMADEC_FreeCompResources(OMX_HANDLETYPE pComponent)
489 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
490 WMADEC_COMPONENT_PRIVATE *pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
491 pHandle->pComponentPrivate;
493 OMX_ERRORTYPE eError = OMX_ErrorNone;
494 OMX_ERRORTYPE err = OMX_ErrorNone;
498 OMX_PRINT1(pComponentPrivate->dbg, "%d :: WMADEC_FreeCompResources", __LINE__);
500 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d:::pComponentPrivate->bPortDefsAllocated = %ld",
501 __LINE__,pComponentPrivate->bPortDefsAllocated);
502 if (pComponentPrivate->bPortDefsAllocated)
504 nIpBuf = pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountActual;
505 nOpBuf = pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
508 if (pComponentPrivate->bCompThreadStarted)
510 err = close (pComponentPrivate->dataPipe[0]);
512 if (0 != err && OMX_ErrorNone == eError)
514 eError = OMX_ErrorHardware;
517 err = close (pComponentPrivate->dataPipe[1]);
518 if (0 != err && OMX_ErrorNone == eError)
520 eError = OMX_ErrorHardware;
523 err = close (pComponentPrivate->cmdPipe[0]);
524 if (0 != err && OMX_ErrorNone == eError)
526 eError = OMX_ErrorHardware;
529 err = close (pComponentPrivate->cmdPipe[1]);
530 if (0 != err && OMX_ErrorNone == eError)
532 eError = OMX_ErrorHardware;
535 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
536 err = close (pComponentPrivate->cmdDataPipe[0]);
537 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
538 if (0 != err && OMX_ErrorNone == eError)
540 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
541 eError = OMX_ErrorHardware;
542 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error while closing cmdPipe",__LINE__);
545 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
546 err = close (pComponentPrivate->cmdDataPipe[1]);
547 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
548 if (0 != err && OMX_ErrorNone == eError)
550 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
551 eError = OMX_ErrorHardware;
552 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error while closing cmdPipe",__LINE__);
557 if (pComponentPrivate->bPortDefsAllocated)
559 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
560 if (pComponentPrivate->pPortDef[INPUT_PORT])
562 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
563 OMX_PRCOMM2(pComponentPrivate->dbg, "freeing pComponentPrivate->pPortDef[INPUT_PORT] = \
564 %p",pComponentPrivate->pPortDef[INPUT_PORT]);
565 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT]);
567 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
569 if (pComponentPrivate->pPortDef[OUTPUT_PORT])
571 OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
572 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[OUTPUT_PORT] = %p",
573 pComponentPrivate->pPortDef[OUTPUT_PORT]);
574 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT]);
577 if (pComponentPrivate->wmaParams[INPUT_PORT])
579 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->wmaParams[INPUT_PORT] = %p",
580 pComponentPrivate->wmaParams[INPUT_PORT]);
581 OMX_MEMFREE_STRUCT(pComponentPrivate->wmaParams[INPUT_PORT]);
584 if (pComponentPrivate->wmaParams[OUTPUT_PORT])
586 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->wmaParams[OUTPUT_PORT] = %p",
587 pComponentPrivate->wmaParams[OUTPUT_PORT]);
588 OMX_PRCOMM2(pComponentPrivate->dbg, "wmaParams[OUTPUT_PORT]->nPortIndex = %ld",
589 pComponentPrivate->wmaParams[OUTPUT_PORT]->nPortIndex);
590 OMX_MEMFREE_STRUCT(pComponentPrivate->wmaParams[OUTPUT_PORT]);
591 OMX_PRCOMM2(pComponentPrivate->dbg, "after pComponentPrivate->wmaParams[OUTPUT_PORT] = \
592 %p",pComponentPrivate->wmaParams[OUTPUT_PORT]);
595 pComponentPrivate->bPortDefsAllocated = 0;
597 OMX_PRDSP2(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n");
598 pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
599 pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
601 pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
602 pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
604 pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
605 pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
607 OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
608 OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
609 OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
613 OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully WMADEC_FreeCompResources()");
619 /* ========================================================================== */
621 * WMADEC_CleanupInitParams() This functions cleans up initialization
622 * parameters when shutting down
624 * @param pComponent handle for this instance of the component
630 * @return OMX Error code
632 /* ========================================================================== */
633 OMX_ERRORTYPE WMADEC_CleanupInitParams(OMX_HANDLETYPE pComponent)
636 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
637 WMADEC_COMPONENT_PRIVATE *pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
638 pHandle->pComponentPrivate;
640 LCML_WMADEC_BUFHEADERTYPE *pTemp_lcml;
642 OMX_ERRORTYPE eError = OMX_ErrorNone;
646 OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
648 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pDynParams, WMADEC_UALGParams);
650 if (pComponentPrivate->dasfmode == 1)
652 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, WMADEC_AudioCodecParams);
655 nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
657 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[INPUT_PORT];
660 for(i=0; i<nIpBuf; i++)
662 OMX_PRDSP2(pComponentPrivate->dbg, "freeing pTemp_lcml->pIpParam = %p", pTemp_lcml->pIpParam);
663 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, WMADEC_UAlgInBufParamStruct);
667 OMX_PRCOMM2(pComponentPrivate->dbg, "freeing pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = %p",
668 pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
670 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
671 pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
673 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
674 OMX_PRCOMM2(pComponentPrivate->dbg, "freeing pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = %p",
675 pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
677 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
678 pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
680 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
681 OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully WMADEC_CleanupInitParams()");
685 /* ========================================================================== */
687 * @WMADEC_StopComponentThread() This function is called by the component during
688 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
690 * @param pComponent handle for this instance of the component
698 /* ========================================================================== */
700 OMX_ERRORTYPE WMADEC_StopComponentThread(OMX_HANDLETYPE pComponent)
703 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
704 WMADEC_COMPONENT_PRIVATE *pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
705 pHandle->pComponentPrivate;
707 OMX_ERRORTYPE eError = OMX_ErrorNone;
708 OMX_ERRORTYPE threadError = OMX_ErrorNone;
709 int pthreadError = 0;
711 /*Join the component thread */
712 pComponentPrivate->bIsStopping = 1;
713 write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsStopping, sizeof(OMX_U16));
714 OMX_PRINT1(pComponentPrivate->dbg, "%d:::About to call pthread_join",__LINE__);
715 pthreadError = pthread_join (pComponentPrivate->ComponentThread,
716 (void*)&threadError);
717 OMX_PRDSP2(pComponentPrivate->dbg, "%d:::called pthread_join",__LINE__);
718 if (0 != pthreadError)
720 eError = OMX_ErrorHardware;
721 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error while closing Component Thread - pthreadError = %d",
722 __LINE__,pthreadError);
725 /*Check for the errors */
726 if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError)
728 eError = OMX_ErrorInsufficientResources;
729 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error while closing Component Thread",__LINE__);
731 OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully from Stop Component thread");
736 /* ========================================================================== */
738 * @WMADECHandleCommand() This function is called by the component when ever it
739 * receives the command from the application
741 * @param pComponentPrivate Component private data
749 /* ========================================================================== */
751 OMX_U32 WMADECHandleCommand (WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
754 OMX_COMMANDTYPE command;
755 OMX_STATETYPE commandedState;
757 char *pArgs = "damedesuStr";
761 OMX_ERRORTYPE eError = OMX_ErrorNone;
762 LCML_DSP_INTERFACE *pLcmlHandle;
763 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
764 pLcmlHandle = (LCML_DSP_INTERFACE *) pComponentPrivate->pLcmlHandle;
766 OMX_PRINT1(pComponentPrivate->dbg, "WMADECHandleCommand");
767 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering WMADECHandleCommand Function - curState = %d",
768 __LINE__,pComponentPrivate->curState);
769 read (pComponentPrivate->cmdPipe[0], &command, sizeof (command));
770 if ((int)(read) == -1){
771 pComponentPrivate->cbInfo.EventHandler (pHandle,
772 pHandle->pApplicationPrivate,
778 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: Just read from the command pipe",__LINE__);
779 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: command = %d",__LINE__,command);
780 read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
781 if ((int)(read) == -1){
782 pComponentPrivate->cbInfo.EventHandler (pHandle,
783 pHandle->pApplicationPrivate,
790 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: command = %d",__LINE__,command);
791 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: commandData = %ld",__LINE__,commandData);
793 #ifdef __PERF_INSTRUMENTATION__
794 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,
801 if (command == OMX_CommandStateSet)
803 commandedState = (OMX_STATETYPE)commandData;
804 switch(commandedState)
807 eError = WMADEC_CommandToIdle(pComponentPrivate);
810 case OMX_StateExecuting:
812 eError = WMADEC_CommandToExecuting(pComponentPrivate);
815 case OMX_StateLoaded:
817 eError = WMADEC_CommandToLoaded(pComponentPrivate);
822 eError = WMADEC_CommandToPause(pComponentPrivate);
826 case OMX_StateWaitForResources:
828 eError = WMADEC_CommandToWaitForResources(pComponentPrivate);
832 case OMX_StateInvalid:
834 OMX_PRSTATE2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd OMX_StateInvalid:",
837 if (pComponentPrivate->curState == commandedState)
839 pComponentPrivate->cbInfo.EventHandler (pHandle,
840 pHandle->pApplicationPrivate,
845 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",
850 if (pComponentPrivate->curState != OMX_StateWaitForResources &&
851 pComponentPrivate->curState != OMX_StateInvalid &&
852 pComponentPrivate->curState != OMX_StateLoaded)
855 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
856 EMMCodecControlDestroy, (void *)pArgs);
858 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
859 pComponentPrivate->curState = OMX_StateInvalid;
861 pComponentPrivate->cbInfo.EventHandler(pHandle,
862 pHandle->pApplicationPrivate,
864 OMX_ErrorInvalidState,
868 WMADEC_CleanupInitParams(pHandle);
873 OMX_PRSTATE2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd OMX_StateMax::",
877 OMX_PRSTATE2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Unknown::",
880 } /* End of Switch */
883 else if (command == OMX_CommandMarkBuffer)
885 OMX_PRBUFFER2(pComponentPrivate->dbg, "command OMX_CommandMarkBuffer received %d",__LINE__);
886 if(!pComponentPrivate->pMarkBuf)
888 OMX_PRBUFFER2(pComponentPrivate->dbg, "command OMX_CommandMarkBuffer received %d",__LINE__);
889 /* TODO Need to handle multiple marks */
890 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
893 else if (command == OMX_CommandPortDisable)
895 if (!pComponentPrivate->bDisableCommandPending)
896 if(commandData == 0x0){
898 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
899 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->bBufferPending[%d] = %ld",i,
900 pComponentPrivate->pInputBufferList->bBufferPending[i]);
901 if (WMADEC_IsPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],OMX_DirInput)) {
902 /* Real solution is flush buffers from DSP. Until we have the ability to do that
903 we just call EmptyBufferDone() on any pending buffers */
904 OMX_PRBUFFER2(pComponentPrivate->dbg, "Forcing EmptyBufferDone");
905 #ifdef __PERF_INSTRUMENTATION__
906 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
907 PREF(pComponentPrivate->pInputBufferList->pBufHdr[i], pBuffer),
911 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
912 pComponentPrivate->pHandle->pApplicationPrivate,
913 pComponentPrivate->pInputBufferList->pBufHdr[i]);
914 pComponentPrivate->nEmptyBufferDoneCount++;
917 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_FALSE;
920 if(commandData == -1){
922 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_FALSE;
924 if(commandData == 0x1 || commandData == -1)
927 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_FALSE;
928 if (pComponentPrivate->curState == OMX_StateExecuting)
930 pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
931 if (pComponentPrivate->codecStop_waitingsignal == 0){
932 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
934 eError = LCML_ControlCodec(
935 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
936 MMCodecControlStop,(void *)pArgs);
937 if (pComponentPrivate->codecStop_waitingsignal == 0){
938 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
939 pComponentPrivate->codecStop_waitingsignal = 0;
940 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
944 OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %ld",commandData);
945 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = %d",
946 pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
947 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated = %d",
948 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated);
950 if(commandData == 0x0)
952 if(!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
954 /* return cmdcomplete event if input unpopulated */
955 pComponentPrivate->cbInfo.EventHandler(pHandle,
956 pHandle->pApplicationPrivate,
957 OMX_EventCmdComplete,
958 OMX_CommandPortDisable,
961 pComponentPrivate->bDisableCommandPending = 0;
965 pComponentPrivate->bDisableCommandPending = 1;
966 pComponentPrivate->bDisableCommandParam = commandData;
970 if(commandData == 0x1)
972 if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
974 /* return cmdcomplete event if output unpopulated */
975 pComponentPrivate->cbInfo.EventHandler(pHandle,
976 pHandle->pApplicationPrivate,
977 OMX_EventCmdComplete,
978 OMX_CommandPortDisable,
981 pComponentPrivate->bDisableCommandPending = 0;
985 pComponentPrivate->bDisableCommandPending = 1;
986 pComponentPrivate->bDisableCommandParam = commandData;
990 if(commandData == -1){
991 if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
992 !pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
995 /* return cmdcomplete event if inout & output unpopulated */
996 pComponentPrivate->cbInfo.EventHandler(pHandle,
997 pHandle->pApplicationPrivate,
998 OMX_EventCmdComplete,
999 OMX_CommandPortDisable,
1003 pComponentPrivate->cbInfo.EventHandler(pHandle,
1004 pHandle->pApplicationPrivate,
1005 OMX_EventCmdComplete,
1006 OMX_CommandPortDisable,
1009 pComponentPrivate->bDisableCommandPending = 0;
1013 pComponentPrivate->bDisableCommandPending = 1;
1014 pComponentPrivate->bDisableCommandParam = commandData;
1018 else if (command == OMX_CommandPortEnable)
1020 if(!pComponentPrivate->bEnableCommandPending){
1021 if(commandData == 0x0 || commandData == -1)
1023 /* enable in port */
1024 OMX_PRCOMM2(pComponentPrivate->dbg, "setting input port to enabled");
1025 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = OMX_TRUE;
1026 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled = %d",
1027 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
1029 if(commandData == 0x1 || commandData == -1)
1031 /* enable out port */
1032 char *pArgs = "damedesuStr";
1033 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_TRUE;
1034 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = %d",
1035 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
1037 if (pComponentPrivate->curState == OMX_StateExecuting && pComponentPrivate->bDspStoppedWhileExecuting){
1038 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
1040 eError = LCML_ControlCodec(
1041 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1042 EMMCodecControlStart,(void *)pArgs);
1047 OMX_PRSTATE2(pComponentPrivate->dbg, "commandData = %ld",commandData);
1048 OMX_PRSTATE2(pComponentPrivate->dbg, "pComponentPrivate->curState = %d",
1049 pComponentPrivate->curState);
1050 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = %d",
1051 pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
1052 if(commandData == 0x0 )
1054 if(pComponentPrivate->curState == OMX_StateLoaded ||
1055 pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated)
1057 if(pComponentPrivate->AlloBuf_waitingsignal)
1059 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1060 pComponentPrivate->AlloBuf_waitingsignal = 0;
1061 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1062 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1064 pComponentPrivate->cbInfo.EventHandler(pHandle,
1065 pHandle->pApplicationPrivate,
1066 OMX_EventCmdComplete,
1067 OMX_CommandPortEnable,
1069 pComponentPrivate->bEnableCommandPending = 0;
1073 pComponentPrivate->bEnableCommandPending = 1;
1074 pComponentPrivate->bEnableCommandParam = commandData;
1077 else if(commandData == 0x1)
1079 if(pComponentPrivate->curState ==
1081 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated)
1083 if(pComponentPrivate->AlloBuf_waitingsignal){
1084 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1085 pComponentPrivate->AlloBuf_waitingsignal = 0;
1086 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1087 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1089 pComponentPrivate->cbInfo.EventHandler(pHandle,
1090 pHandle->pApplicationPrivate,
1091 OMX_EventCmdComplete,
1092 OMX_CommandPortEnable,
1094 if(pComponentPrivate->reconfigOutputPort){
1095 pComponentPrivate->reconfigOutputPort = 0;
1096 WMADECFill_LCMLInitParamsEx(pHandle,commandData);
1099 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->nNumInputBufPending=%ld",pComponentPrivate->nNumInputBufPending);
1100 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++){
1101 if (pComponentPrivate->pInputBufHdrPending[i]){
1102 LCML_WMADEC_BUFHEADERTYPE *pLcmlHdr;
1103 if (!WMADEC_IsPending(pComponentPrivate,
1104 pComponentPrivate->pInputBufHdrPending[i],
1106 WMADECGetCorresponding_LCMLHeader(
1108 pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
1111 WMADEC_SetPending(pComponentPrivate,
1112 pComponentPrivate->pInputBufHdrPending[i],
1114 OMX_PRBUFFER2(pComponentPrivate->dbg, "QUEUEING INPUT BUFFER");
1115 OMX_PRBUFFER2(pComponentPrivate->dbg, "nfilledLen= %ld",pComponentPrivate->pInputBufHdrPending[i]->nFilledLen);
1116 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1117 EMMCodecInputBuffer,
1118 (OMX_U8 *)pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
1119 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
1120 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
1121 (OMX_U8 *) pLcmlHdr->pIpParam,
1122 sizeof(WMADEC_UAlgInBufParamStruct),
1124 if (eError != OMX_ErrorNone)
1126 OMX_ERROR4(pComponentPrivate->dbg, "ERROR IN QUEUEBUFFER");
1127 eError = OMX_ErrorHardware;
1130 pComponentPrivate->lcml_nCntIp++;
1135 pComponentPrivate->nNumInputBufPending=0;
1136 pComponentPrivate->bEnableCommandPending = 0;
1140 pComponentPrivate->bEnableCommandPending = 1;
1141 pComponentPrivate->bEnableCommandParam = commandData;
1144 else if(commandData == -1 )
1146 if(pComponentPrivate->curState == OMX_StateLoaded ||
1147 (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
1148 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated))
1150 if(pComponentPrivate->AlloBuf_waitingsignal)
1152 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1153 pComponentPrivate->AlloBuf_waitingsignal = 0;
1154 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1155 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1157 pComponentPrivate->cbInfo.EventHandler(pHandle,
1158 pHandle->pApplicationPrivate,
1159 OMX_EventCmdComplete,
1160 OMX_CommandPortEnable,
1163 pComponentPrivate->cbInfo.EventHandler(pHandle,
1164 pHandle->pApplicationPrivate,
1165 OMX_EventCmdComplete,
1166 OMX_CommandPortEnable,
1169 pComponentPrivate->bEnableCommandPending = 0;
1170 pComponentPrivate->reconfigOutputPort = 0;
1171 WMADECFill_LCMLInitParamsEx(pHandle,commandData);
1175 pComponentPrivate->bEnableCommandPending = 1;
1176 pComponentPrivate->bEnableCommandParam = commandData;
1180 else if (command == OMX_CommandFlush)
1182 OMX_U32 aParam[3] = {0};
1183 if(commandData == 0x0 || commandData == -1)
1185 if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0) {
1186 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
1188 aParam[0] = USN_STRMCMD_FLUSH;
1192 if (pComponentPrivate->codecFlush_waitingsignal == 0){
1193 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex);
1195 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1196 EMMCodecControlStrmCtrl, (void*)aParam);
1198 if (pComponentPrivate->codecFlush_waitingsignal == 0){
1199 pthread_cond_wait(&pComponentPrivate->codecFlush_threshold, &pComponentPrivate->codecFlush_mutex);
1200 pComponentPrivate->codecFlush_waitingsignal = 0;
1201 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex);
1203 if (eError != OMX_ErrorNone) {
1207 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
1213 if(commandData == 0x1 || commandData == -1)
1215 if (pComponentPrivate->nUnhandledFillThisBuffers == 0) {
1216 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
1217 //ComponentPrivate->first_buff = 0;
1219 aParam[0] = USN_STRMCMD_FLUSH;
1223 OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port");
1224 if (pComponentPrivate->codecFlush_waitingsignal == 0){
1225 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex);
1227 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1228 EMMCodecControlStrmCtrl, (void*)aParam);
1230 if (pComponentPrivate->codecFlush_waitingsignal == 0){
1231 pthread_cond_wait(&pComponentPrivate->codecFlush_threshold, &pComponentPrivate->codecFlush_mutex);
1232 pComponentPrivate->codecFlush_waitingsignal = 0;
1233 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex);
1235 if (eError != OMX_ErrorNone) {
1239 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
1245 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting WMADECHandleCommand Function",__LINE__);
1246 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning %d",__LINE__,eError);
1247 if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD ) {
1248 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
1249 pComponentPrivate->pHandle->pApplicationPrivate,
1258 /* ========================================================================== */
1260 * @WMADECHandleDataBuf_FromApp() This function is called by the component when ever it
1261 * receives the buffer from the application
1263 * @param pComponentPrivate Component private data
1264 * @param pBufHeader Buffer from the application
1272 /* ========================================================================== */
1274 OMX_ERRORTYPE WMADECHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader,
1275 WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
1277 OMX_PRBUFFER2(pComponentPrivate->dbg, "At handle data buff from app device string is =%p",pComponentPrivate->sDeviceString);
1278 OMX_PRCOMM2(pComponentPrivate->dbg, "At handle databuff from app pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated =%d",
1279 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated);
1280 OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
1281 OMX_ERRORTYPE eError = OMX_ErrorNone;
1283 LCML_WMADEC_BUFHEADERTYPE *pLcmlHdr;
1284 LCML_DSP_INTERFACE *pLcmlHandle;
1285 WMADEC_COMPONENT_PRIVATE *pComponentPrivate_CC;
1286 OMX_U32 cmdValues[3];
1287 char *pArgs = "damedesuStr";
1290 pComponentPrivate_CC = pComponentPrivate;
1291 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
1293 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering WMADECHandleDataBuf_FromApp Function",__LINE__);
1295 /*Find the direction of the received buffer from buffer list */
1296 eError = WMADECGetBufferDirection(pBufHeader, &eDir);
1297 if (eError != OMX_ErrorNone)
1299 OMX_ERROR4(pComponentPrivate->dbg, "%d :: The PBufHeader is not found in the list", __LINE__);
1303 if (eDir == OMX_DirInput)
1305 pComponentPrivate->nUnhandledEmptyThisBuffers--;
1306 if (pComponentPrivate->curState == OMX_StateIdle){
1307 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1308 pComponentPrivate->pHandle->pApplicationPrivate,
1310 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers", __LINE__, __FUNCTION__);
1313 pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
1314 if ( (pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS))
1316 pComponentPrivate->bBypassDSP = 0;
1317 eError = WMADECGetCorresponding_LCMLHeader(pComponentPrivate,
1318 pBufHeader->pBuffer,
1321 if (eError != OMX_ErrorNone)
1323 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid Buffer Came ...",__LINE__);
1327 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d Comp:: Sending Filled Input buffer = %p, %p to LCML",
1328 __LINE__,pBufHeader,pBufHeader->pBuffer);
1330 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBufHeader->nFilledLen :%ld ",pBufHeader->nFilledLen);
1331 pLcmlHdr->pIpParam->bLastBuffer = 0;
1333 #ifdef __PERF_INSTRUMENTATION__
1334 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1335 PREF(pBufHeader,pBuffer),
1336 pPortDefIn->nBufferSize,
1337 PERF_ModuleCommonLayer);
1340 if(pComponentPrivate->SendAfterEOS == 1){
1342 if(pComponentPrivate->dasfmode == 1)
1345 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---",__LINE__);
1346 if (pComponentPrivate->pHeaderInfo->iChannel == 1)
1348 pComponentPrivate->pParams->iAudioFormat = WMA_MONO_CHANNEL;
1352 pComponentPrivate->pParams->iAudioFormat = WMA_STEREO_NON_INTERLEAVED;
1354 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iAudioFormat = %d", pComponentPrivate->pParams->iAudioFormat);
1355 pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
1356 pComponentPrivate->pParams->iSamplingRate =
1357 pComponentPrivate->pHeaderInfo->iSamplePerSec;
1359 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iSamplingRate = %ld",
1360 pComponentPrivate->pParams->iSamplingRate);
1361 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iStrmId = %ld",
1362 pComponentPrivate->pParams->iStrmId);
1363 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iAudioFormat = %d",
1364 pComponentPrivate->pParams->iAudioFormat);
1366 pValues[0] = USN_STRMCMD_SETCODECPARAMS;
1367 pValues[1] = (OMX_U32)pComponentPrivate->pParams;
1368 pValues[2] = sizeof(WMADEC_AudioCodecParams);
1369 pValues[3] = OUTPUT_PORT;
1370 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1371 EMMCodecControlStrmCtrl,(void *)pValues);
1372 if(eError != OMX_ErrorNone)
1374 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..",
1379 #ifdef ANDROID //this is used to separate changes made for integration with opencore 2.1 or later versions
1381 /* check if the buffer contains config data, it should only be the case in the fist input buffer*/
1382 if(pBufHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG){
1383 pComponentPrivate->bConfigData = 1; /* changed the if statement to use the buffer flag, now this flag doesnt do anything
1384 we will leave it for now incase it becomes useful */
1385 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: Before parsing ",__LINE__);
1386 eError=WMADEC_Parser( pBufHeader->pBuffer,pComponentPrivate->rcaheader, pComponentPrivate->dbg);
1387 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: UTIL: After parsing ", __LINE__);
1388 if (eError != OMX_ErrorNone)
1390 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Parsing invalid ...",__LINE__);
1393 /*******************Updating if needed*********************/
1394 OMX_ERROR2(pComponentPrivate->dbg, "OLD: pComponentPrivate->wmaParams[OUTPUT_PORT]->nSamplingRate=%ld ",pComponentPrivate->wmaParams[OUTPUT_PORT]->nSamplingRate);
1395 /* if(pComponentPrivate->wma_op->nSamplingRate != iSamplePerSec){
1396 pComponentPrivate->wma_op->nSamplingRate=iSamplePerSec;
1397 pComponentPrivate->reconfigOutputPort=1;
1398 OMX_ERROR4(pComponentPrivate->dbg, "=================RECONFIGURATION NEEDED===============");
1399 OMX_ERROR4(pComponentPrivate->dbg, "NEW: pComponentPrivate->wmaParams[OUTPUT_PORT]->nSamplingRate=%d ",pComponentPrivate->wmaParams[OUTPUT_PORT]->nSamplingRate);
1401 if(pComponentPrivate->wma_op->nChannels != iChannel){
1402 pComponentPrivate->wma_op->nChannels = iChannel;
1403 pComponentPrivate->reconfigOutputPort=1;
1404 OMX_ERROR4(pComponentPrivate->dbg, "=================RECONFIGURATION NEEDED===============");
1406 if(pComponentPrivate->reconfigOutputPort){
1407 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
1408 pComponentPrivate->pHandle->pApplicationPrivate,
1409 OMX_EventPortSettingsChanged,
1413 OMX_ERROR4(pComponentPrivate->dbg, "================= sent reconfig event to client==============="); */
1414 pBufHeader->nFilledLen = 0;
1415 pComponentPrivate->cbInfo.EmptyBufferDone (
1416 pComponentPrivate->pHandle,
1417 pComponentPrivate->pHandle->pApplicationPrivate,
1420 pComponentPrivate->nEmptyBufferDoneCount++;
1423 pComponentPrivate->bConfigData = 0;
1427 if( pComponentPrivate->dasfmode )
1429 pComponentPrivate->pDynParams->iOutputFormat = WMA_IAUDIO_BLOCK; /* EAUDIO_BLOCKED */
1433 pComponentPrivate->pDynParams->iOutputFormat = WMA_IAUDIO_INTERLEAVED; /* EAUDIO_INTERLEAVED */
1435 pComponentPrivate->pDynParams->size = sizeof( WMADEC_UALGParams );
1437 cmdValues[0] = WMA_IUALG_CMD_SETSTATUS;
1438 cmdValues[1] = (OMX_U32)( pComponentPrivate->pDynParams );
1439 cmdValues[2] = sizeof( WMADEC_UALGParams );
1441 p = (void *)&cmdValues;
1442 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1443 EMMCodecControlAlgCtrl, (void *)p);
1444 if(eError != OMX_ErrorNone){
1445 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec algctrl..", __LINE__);
1448 pComponentPrivate->bBypassDSP = 0;
1450 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)(pComponentPrivate->pLcmlHandle))->pCodecinterfacehandle,
1451 EMMCodecControlStart, (void *)pArgs);
1453 if(eError != OMX_ErrorNone){
1454 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Start..", __LINE__);
1457 pComponentPrivate->SendAfterEOS = 0;
1459 if (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS){
1460 pLcmlHdr->pIpParam->bLastBuffer = 1;
1461 pComponentPrivate->SendAfterEOS = 1;
1462 pComponentPrivate->InputEosSet = 1;
1463 pComponentPrivate->pOutputBufferList->EosFlagSent = 0;
1464 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_WmaDec_Utils.c : pComponentPrivate->SendAfterEOS %d",__LINE__,pComponentPrivate->SendAfterEOS);
1466 /*Store tick count information*/
1467 pComponentPrivate->arrBufIndexTick[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
1468 /* Store time stamp information */
1469 pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
1470 pComponentPrivate->IpBufindex++;
1471 pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
1472 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer TimeStamp %lld", __LINE__, pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex]);
1474 if(pComponentPrivate->first_buffer)
1476 pComponentPrivate->rcaheader->iPayload=pBufHeader->nFilledLen;
1477 pComponentPrivate->rcaheader->iMaxPacketSize = pComponentPrivate->rcaheader->iPayload+31;
1478 memmove(pBufHeader->pBuffer+75,pBufHeader->pBuffer,pBufHeader->nFilledLen);
1479 memset(pBufHeader->pBuffer,0x00,75);
1480 memcpy(pBufHeader->pBuffer + 16, &pComponentPrivate->rcaheader->iMaxPacketSize, 2);
1481 memcpy(pBufHeader->pBuffer + 36, &pComponentPrivate->rcaheader->iTypeSpecific, 4);
1482 memcpy(pBufHeader->pBuffer + 42, &pComponentPrivate->rcaheader->iFormatTag, 2);
1483 memcpy(pBufHeader->pBuffer + 44, &pComponentPrivate->rcaheader->iChannel, 2);
1484 memcpy(pBufHeader->pBuffer + 46, &pComponentPrivate->rcaheader->iSamplePerSec, 4);
1485 memcpy(pBufHeader->pBuffer + 50, &pComponentPrivate->rcaheader->iAvgBytesPerSec, 4);
1486 memcpy(pBufHeader->pBuffer + 54, &pComponentPrivate->rcaheader->iBlockAlign, 2);
1487 memcpy(pBufHeader->pBuffer + 56, &pComponentPrivate->rcaheader->iValidBitsPerSample, 2);
1488 memcpy(pBufHeader->pBuffer + 64, &pComponentPrivate->rcaheader->iEncodeOptV, 2);
1489 memcpy(pBufHeader->pBuffer + 71, &pComponentPrivate->rcaheader->iPayload, 4);
1490 pBufHeader->nFilledLen+=75;
1491 pComponentPrivate->first_buffer=0;
1495 memmove(pBufHeader->pBuffer+5,pBufHeader->pBuffer,pBufHeader->nFilledLen);
1496 memset(pBufHeader->pBuffer,0x00,5);
1497 memcpy(pBufHeader->pBuffer + 1, &pComponentPrivate->rcaheader->iPayload, 4);
1498 pBufHeader->nFilledLen+=5;
1500 OMX_PRBUFFER2(pComponentPrivate->dbg, "Before sending input buffer");
1501 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBufHeader->nFilledLen=%ld",pBufHeader->nFilledLen);
1503 if (pComponentPrivate->curState == OMX_StateExecuting)
1505 if(!pComponentPrivate->bDspStoppedWhileExecuting)
1507 if (!WMADEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput))
1509 if(!pComponentPrivate->reconfigOutputPort){
1510 WMADEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput);
1511 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
1512 EMMCodecInputBuffer,
1513 (OMX_U8 *)pBufHeader->pBuffer,
1514 pBufHeader->nAllocLen,
1515 pBufHeader->nFilledLen,
1516 (OMX_U8 *) pLcmlHdr->pIpParam,
1517 sizeof(WMADEC_UAlgInBufParamStruct),
1519 if (eError != OMX_ErrorNone)
1521 OMX_ERROR4(pComponentPrivate->dbg, "ERROR IN QUEUEBUFFER");
1522 OMX_ERROR4(pComponentPrivate->dbg, "%d ::IssuingDSP IP: Error Occurred",
1524 eError = OMX_ErrorHardware;
1527 pComponentPrivate->lcml_nCntIp++;
1531 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: Bypassing the sending of input buffers to lcml",__LINE__);
1532 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
1533 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: UTIL: pComponentPrivate->nNumInputBufPending=%ld",__LINE__,
1534 pComponentPrivate->nNumInputBufPending);
1535 /*pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1536 pComponentPrivate->pHandle->pApplicationPrivate,
1540 OMX_PRBUFFER2(pComponentPrivate->dbg, "Don't queue buffers during a reconfig");
1546 #ifdef __PERF_INSTRUMENTATION__
1547 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1548 PREF(pBufHeader,pBuffer),
1552 pBufHeader->nFilledLen = 0;
1553 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1554 pComponentPrivate->pHandle->pApplicationPrivate,
1559 else if (pComponentPrivate->curState == OMX_StatePause)
1561 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] =
1567 pComponentPrivate->bBypassDSP = 1;
1568 OMX_PRBUFFER2(pComponentPrivate->dbg, "Forcing EmptyBufferDone");
1569 #ifdef __PERF_INSTRUMENTATION__
1570 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1571 PREF(pComponentPrivate->pInputBufferList->pBufHdr[0], pBuffer),
1572 0, PERF_ModuleHLMM);
1574 pBufHeader->nFilledLen = 0;
1575 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1576 pComponentPrivate->pHandle->pApplicationPrivate,
1577 pComponentPrivate->pInputBufferList->pBufHdr[0]);
1579 pComponentPrivate->nEmptyBufferDoneCount++;
1582 if(pBufHeader->pMarkData)
1584 /* copy mark to output buffer header */
1585 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData =
1586 pBufHeader->pMarkData;
1587 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent =
1588 pBufHeader->hMarkTargetComponent;
1590 /* trigger event handler if we are supposed to */
1591 if (pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle &&
1592 pBufHeader->pMarkData)
1594 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate->pHandle,
1595 pComponentPrivate->pHandle->pApplicationPrivate,
1596 OMX_EventMark, 0, 0, pBufHeader->pMarkData);
1599 if (pComponentPrivate->bFlushInputPortCommandPending)
1601 OMX_SendCommand(pComponentPrivate->pHandle,
1602 OMX_CommandFlush,0,NULL);
1605 else if (eDir == OMX_DirOutput)
1607 pComponentPrivate->nUnhandledFillThisBuffers--;
1608 if (pComponentPrivate->curState == OMX_StateIdle){
1609 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
1610 pComponentPrivate->pHandle->pApplicationPrivate,
1612 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers", __LINE__, __FUNCTION__);
1615 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending output buffer to LCML ");
1616 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d Comp:: Sending Emptied Output buffer=%p to LCML",
1617 __LINE__,pBufHeader);
1619 #ifdef __PERF_INSTRUMENTATION__
1620 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
1621 PREF(pBufHeader,pBuffer),
1623 PERF_ModuleCommonLayer);
1625 if (pComponentPrivate->bBypassDSP == 0) {
1626 if (pComponentPrivate->curState == OMX_StateExecuting) {
1627 if(!(pComponentPrivate->reconfigInputPort || pComponentPrivate->reconfigOutputPort)){
1628 if (!WMADEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)){
1629 if(!pComponentPrivate->bDspStoppedWhileExecuting){
1630 WMADEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput);
1631 pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
1632 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
1633 EMMCodecOuputBuffer,
1634 (OMX_U8 *)pBufHeader->pBuffer,
1635 pBufHeader->nAllocLen,
1636 pBufHeader->nAllocLen,
1639 if (eError != OMX_ErrorNone )
1641 OMX_ERROR4(pComponentPrivate->dbg, "%d :: IssuingDSP OP: Error Occurred",
1643 eError = OMX_ErrorHardware;
1646 pComponentPrivate->lcml_nOpBuf++;
1650 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
1651 OMX_PRBUFFER2(pComponentPrivate->dbg, "Don't queue while doing a reconfig:: output buffer, num pending = %ld", pComponentPrivate->nNumOutputBufPending);
1653 }else if (pComponentPrivate->curState == OMX_StatePause) {
1654 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
1657 if (pComponentPrivate->bFlushOutputPortCommandPending) {
1658 OMX_SendCommand( pComponentPrivate->pHandle, OMX_CommandFlush, 1, NULL);
1663 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d : BufferHeader %p, Buffer %p Unknown ..........",
1664 __LINE__,pBufHeader, pBufHeader->pBuffer);
1665 eError = OMX_ErrorBadParameter;
1668 OMX_PRINT1(pComponentPrivate->dbg, "%d : Exiting from WMADECHandleDataBuf_FromApp ",__LINE__);
1669 if (eError != OMX_ErrorNone ) {
1670 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
1671 pComponentPrivate->pHandle->pApplicationPrivate,
1680 /*-------------------------------------------------------------------*/
1682 * WMADECGetBufferDirection () This function is used by the component thread to
1683 * request a buffer from the application. Since it was called from 2 places,
1684 * it made sense to turn this into a small function.
1686 * @param pData pointer to WMA Decoder Context Structure
1687 * @param pCur pointer to the buffer to be requested to be filled
1691 /*-------------------------------------------------------------------*/
1693 OMX_ERRORTYPE WMADECGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir)
1695 OMX_ERRORTYPE eError = OMX_ErrorNone;
1696 WMADEC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
1698 OMX_BUFFERHEADERTYPE *pBuf = NULL;
1701 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering WMADECGetBufferDirection Function",__LINE__);
1702 OMX_PRINT1(pComponentPrivate->dbg, "%d :: pComponentPrivate = %p",__LINE__,pComponentPrivate);
1703 /*Search this buffer in input buffers list */
1704 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: WMADECGetBufferDirection Function",__LINE__);
1705 OMX_PRINT1(pComponentPrivate->dbg, "%d :: pComponentPrivate = %p",__LINE__,pComponentPrivate);
1706 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: pComponentPrivate->pInputBufferList = %p",
1707 __LINE__,pComponentPrivate->pInputBufferList);
1708 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pComponentPrivate->pInputBufferList->numBuffers = %d",
1709 __LINE__,pComponentPrivate->pInputBufferList->numBuffers);
1711 nBuf = pComponentPrivate->pInputBufferList->numBuffers;
1712 for(i=0; i<nBuf; i++)
1714 pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
1715 if(pBufHeader == pBuf)
1717 *eDir = OMX_DirInput;
1718 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Buffer %p is INPUT BUFFER",__LINE__, pBufHeader);
1724 /*Search this buffer in input buffers list */
1725 nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
1727 for(i=0; i<nBuf; i++)
1729 pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
1730 if(pBufHeader == pBuf)
1732 *eDir = OMX_DirOutput;
1733 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Buffer %p is OUTPUT BUFFER",__LINE__,
1742 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Buffer %p is Not Found in the List",__LINE__,
1744 eError = OMX_ErrorUndefined;
1748 OMX_ERROR1(pComponentPrivate->dbg, "%d :: Exiting WMADECGetBufferDirection Function",__LINE__);
1749 if (eError != OMX_ErrorNone ) {
1750 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
1751 pComponentPrivate->pHandle->pApplicationPrivate,
1760 /*-------------------------------------------------------------------*/
1762 * WMADECHandleDataBuf_FromLCML () This function is used by the component thread to
1763 * request a buffer from the application. Since it was called from 2 places,
1764 * it made sense to turn this into a small function.
1766 * @param pData pointer to WMA Decoder Context Structure
1767 * @param pCur pointer to the buffer to be requested to be filled
1771 /*-------------------------------------------------------------------*/
1772 OMX_ERRORTYPE WMADECHandleDataBuf_FromLCML(WMADEC_COMPONENT_PRIVATE* pComponentPrivate, LCML_WMADEC_BUFHEADERTYPE* msgBuffer)
1774 OMX_ERRORTYPE eError = OMX_ErrorNone;
1777 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
1778 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering WMADECHandleDataBuf_FromLCML Function",__LINE__);
1779 OMX_PRINT2(pComponentPrivate->dbg, "%d :: pComponentPrivate = %p",__LINE__, pComponentPrivate);
1780 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering WMADECHandleDataBuf_FromLCML Function", __LINE__);
1784 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error While reading from the LCML Pipe",__LINE__);
1785 eError = OMX_ErrorHardware;
1789 OMX_PRINT2(pComponentPrivate->dbg, "%d :: Entering WMADECHandleDataBuf_FromLCML Function",__LINE__);
1791 if (!(pComponentPrivate->bIsStopping))
1793 if (msgBuffer->eDir == OMX_DirInput)
1795 OMX_PRCOMM2(pComponentPrivate->dbg, "%d: Component Sending Empty Input buffer%p to App",__LINE__,msgBuffer->buffer);
1796 OMX_PRCOMM2(pComponentPrivate->dbg, "Sending Empty INPUT BUFFER to App = %p", msgBuffer->buffer->pBuffer);
1798 #ifdef __PERF_INSTRUMENTATION__
1799 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1800 PREF(msgBuffer->buffer,pBuffer),
1801 0, PERF_ModuleHLMM);
1803 msgBuffer->buffer->nFilledLen = 0;
1804 pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
1805 pHandle->pApplicationPrivate,
1808 pComponentPrivate->nEmptyBufferDoneCount++;
1810 else if (msgBuffer->eDir == OMX_DirOutput)
1812 OMX_PRCOMM2(pComponentPrivate->dbg, "%d: Component Sending Filled Output buffer%p to App size = %ld",
1813 __LINE__,msgBuffer->buffer,msgBuffer->buffer->nFilledLen);
1814 #ifdef __PERF_INSTRUMENTATION__
1815 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1816 msgBuffer->buffer->pBuffer,
1817 msgBuffer->buffer->nFilledLen,
1821 /*Copying tick count information to output buffer*/
1822 msgBuffer->buffer->nTickCount = (OMX_U32)pComponentPrivate->arrBufIndexTick[pComponentPrivate->OpBufindex];
1824 /* Copying time stamp information to output buffer */
1825 msgBuffer->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->OpBufindex];
1826 pComponentPrivate->OpBufindex++;
1827 pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
1829 pComponentPrivate->cbInfo.FillBufferDone (pHandle,
1830 pHandle->pApplicationPrivate,
1833 pComponentPrivate->nOutStandingFillDones--;
1834 OMX_PRSTATE2(pComponentPrivate->dbg, "nOutstandingFillDones = %ld\n", pComponentPrivate->nOutStandingFillDones);
1838 OMX_PRINT2(pComponentPrivate->dbg, "%d :: Wrong Direction dir = %d", __LINE__,msgBuffer->eDir);
1839 OMX_PRDSP2(pComponentPrivate->dbg, "%d: Component Got buffer %p From LCML", __LINE__,msgBuffer->buffer);
1840 eError = OMX_ErrorBadParameter;
1846 OMX_PRINT2(pComponentPrivate->dbg, "%d :: Entering WMADECHandleDataBuf_FromLCML Function",
1848 if (msgBuffer->eDir == OMX_DirInput)
1850 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d: Component Sending Empty Input buffer%p to App",
1851 __LINE__,msgBuffer->buffer);
1852 OMX_PRCOMM2(pComponentPrivate->dbg, "Sending Empty INPUT BUFFER to App = %p",
1853 msgBuffer->buffer->pBuffer);
1855 #ifdef __PERF_INSTRUMENTATION__
1856 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1857 PREF(msgBuffer->buffer,pBuffer),
1858 0, PERF_ModuleHLMM);
1860 msgBuffer->buffer->nFilledLen = 0;
1861 pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
1862 pHandle->pApplicationPrivate,
1864 pComponentPrivate->nEmptyBufferDoneCount++;
1866 else if (msgBuffer->eDir == OMX_DirOutput)
1868 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d: Component Sending Filled Output buffer%p to App",
1869 __LINE__,msgBuffer->buffer);
1870 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending Filled OUTPUT BUFFER to App = %p",
1871 msgBuffer->buffer->pBuffer);
1873 #ifdef __PERF_INSTRUMENTATION__
1874 PERF_SendingBuffer(pComponentPrivate->pPERFcomp,
1875 msgBuffer->buffer->pBuffer,
1876 msgBuffer->buffer->nFilledLen,
1879 pComponentPrivate->cbInfo.FillBufferDone (pHandle,
1880 pHandle->pApplicationPrivate,
1882 pComponentPrivate->nOutStandingFillDones--;
1883 OMX_PRCOMM2(pComponentPrivate->dbg, "nOutstandingFillDones = %ld\n", pComponentPrivate->nOutStandingFillDones);
1887 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting WMADECHandleDataBuf_FromLCML Function",
1892 /* -------------------------------------------------------------------*/
1894 * Callback() function will be called LCML component to write the msg
1896 * @param msgBuffer This buffer will be returned by the LCML
1898 * @retval OMX_NoError Success, ready to roll
1899 * OMX_Error_BadParameter The input parameter pointer is null
1901 /*-------------------------------------------------------------------*/
1903 OMX_ERRORTYPE WMADECLCML_Callback (TUsnCodecEvent event,void * args [10])
1905 OMX_ERRORTYPE eError = OMX_ErrorNone;
1906 OMX_U8 *pBuffer = args[1];
1907 LCML_WMADEC_BUFHEADERTYPE *pLcmlHdr;
1908 WMADEC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;
1909 OMX_COMPONENTTYPE *pHandle = NULL;
1911 LCML_DSP_INTERFACE *phandle;
1913 LCML_DSP_INTERFACE *pLcmlHandle;
1919 pComponentPrivate_CC =
1920 (WMADEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate;
1921 pHandle = pComponentPrivate_CC->pHandle;
1924 phandle = (LCML_DSP_INTERFACE *)args[6];
1926 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
1930 case EMMCodecDspError:
1931 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecDspError");
1934 case EMMCodecInternalError:
1935 OMX_ERROR4(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecInternalError");
1938 case EMMCodecInitError:
1939 OMX_ERROR4(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecInitError");
1942 case EMMCodecDspMessageRecieved:
1943 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecDspMessageRecieved");
1946 case EMMCodecBufferProcessed:
1947 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferProcessed");
1950 case EMMCodecProcessingStarted:
1951 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStarted");
1954 case EMMCodecProcessingPaused:
1955 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingPaused");
1958 case EMMCodecProcessingStoped:
1959 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStoped");
1962 case EMMCodecProcessingEof:
1963 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingEof");
1966 case EMMCodecBufferNotProcessed:
1967 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferNotProcessed");
1970 case EMMCodecAlgCtrlAck:
1971 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecAlgCtrlAck");
1974 case EMMCodecStrmCtrlAck:
1975 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecStrmCtrlAck");
1979 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] Got event = %d",event);
1982 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Entering the WMADECLCML_Callback Function",__LINE__);
1983 OMX_PRINT2(pComponentPrivate_CC->dbg, "args = %p ",args[0]);
1984 OMX_PRINT2(pComponentPrivate_CC->dbg, "event = %d ",event);
1986 if(event == EMMCodecBufferProcessed) {
1987 if( (OMX_U32)args [0] == EMMCodecInputBuffer) {
1988 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: Input: pBuffer = %p",__LINE__, pBuffer);
1989 eError = WMADECGetCorresponding_LCMLHeader(pComponentPrivate_CC,
1993 #ifdef __PERF_INSTRUMENTATION__
1994 PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
1995 PREF(pLcmlHdr->buffer,pBuffer),
1996 0, PERF_ModuleCommonLayer);
1998 WMADEC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer, OMX_DirInput);
2000 if (eError != OMX_ErrorNone)
2002 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: Error: Invalid Buffer Came ...",__LINE__);
2007 ((OMXBufferStatus*)pLcmlHdr->buffer->pAppPrivate)->EmptyBufferDone = 1;
2009 WMADECHandleDataBuf_FromLCML(pComponentPrivate_CC, pLcmlHdr);
2011 else if ((OMX_U32)args [0] == EMMCodecOuputBuffer)
2013 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: Output: pBuffer = %p",__LINE__, pBuffer);
2014 if (!WMADEC_IsValid(pComponentPrivate_CC,pBuffer,OMX_DirOutput))
2016 /* If the buffer we get back from the DSP is not valid call FillBufferDone
2017 on a valid buffer */
2018 #ifdef __PERF_INSTRUMENTATION__
2019 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2020 pComponentPrivate_CC->pOutputBufferList->pBufHdr[pComponentPrivate_CC->nInvalidFrameCount++]->pBuffer,
2021 pComponentPrivate_CC->pOutputBufferList->pBufHdr[pComponentPrivate_CC->nInvalidFrameCount++]->nFilledLen,
2024 pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
2025 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2026 pComponentPrivate_CC->pOutputBufferList->pBufHdr[pComponentPrivate_CC->nInvalidFrameCount++]
2028 pComponentPrivate_CC->nOutStandingFillDones--;
2032 eError = WMADECGetCorresponding_LCMLHeader(pComponentPrivate_CC,
2036 WMADEC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer, OMX_DirOutput);
2037 if (eError != OMX_ErrorNone)
2039 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: Error: Invalid Buffer Came ...",
2045 if(pComponentPrivate_CC->InputEosSet || pComponentPrivate_CC->pOutputBufferList->EosFlagSent)
2047 OMX_PRDSP2(pComponentPrivate_CC->dbg, " EOS Flag OR INPUT EOS ");
2048 pComponentPrivate_CC->InputEosSet = 0;
2049 pComponentPrivate_CC->pOutputBufferList->EosFlagSent = 0;
2050 pLcmlHdr->buffer->nFlags |= OMX_BUFFERFLAG_EOS;
2053 pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
2055 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "pLcmlHdr->buffer->nFilledLen = %ld", pLcmlHdr->buffer->nFilledLen);
2057 #ifdef __PERF_INSTRUMENTATION__
2058 PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp,
2059 PREF(pLcmlHdr->buffer,pBuffer),
2060 PREF(pLcmlHdr->buffer,nFilledLen),
2061 PERF_ModuleCommonLayer);
2063 pComponentPrivate_CC->lcml_nCntOpReceived++;
2064 OMX_PRDSP2(pComponentPrivate_CC->dbg, "pComponentPrivate_CC->lcml_nCntOpReceived = %ld\n", pComponentPrivate_CC->lcml_nCntOpReceived);
2066 if ((pComponentPrivate_CC->nLcml_nCntIp >= 1) &&
2067 (pComponentPrivate_CC->nLcml_nCntOpReceived == 1))
2069 PERF_Boundary(pComponentPrivate_CC->pPERFcomp,
2070 PERF_BoundaryStart | PERF_BoundarySteadyState);
2075 ((OMXBufferStatus*)pLcmlHdr->buffer->pAppPrivate)->FillBufferDone = 1;
2077 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, " OUTPUT RETURNING pBuffer->nFilledLen =%ld",pLcmlHdr->buffer->nFilledLen);
2078 WMADECHandleDataBuf_FromLCML(pComponentPrivate_CC, pLcmlHdr);
2082 else if (event == EMMCodecStrmCtrlAck)
2084 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----",__LINE__);
2086 if (args[1] == (void *)USN_STRMCMD_FLUSH)
2088 pHandle = pComponentPrivate_CC->pHandle;
2089 if ( args[2] == (void *)EMMCodecInputBuffer)
2091 if (args[0] == (void *)USN_ERR_NONE )
2094 for (i=0; i < pComponentPrivate_CC->nNumInputBufPending; i++) {
2095 #ifdef __PERF_INSTRUMENTATION__
2096 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2097 PREF(pComponentPrivate_CC->pInputBufHdrPending[i],pBuffer),
2101 pComponentPrivate_CC->pInputBufHdrPending[i]->nFilledLen = 0;
2102 pComponentPrivate_CC->cbInfo.EmptyBufferDone (pComponentPrivate_CC->pHandle,
2103 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2104 pComponentPrivate_CC->pInputBufHdrPending[i]);
2105 pComponentPrivate_CC->nEmptyBufferDoneCount++;
2106 pComponentPrivate_CC->pInputBufHdrPending[i] = NULL;
2108 pComponentPrivate_CC->nNumInputBufPending=0;
2110 pthread_mutex_lock(&pComponentPrivate_CC->codecFlush_mutex);
2111 if(pComponentPrivate_CC->codecFlush_waitingsignal == 0){
2112 pComponentPrivate_CC->codecFlush_waitingsignal = 1;
2113 pthread_cond_signal(&pComponentPrivate_CC->codecFlush_threshold);
2114 OMX_PRCOMM2(pComponentPrivate_CC->dbg, "flush ack. received. for input port");
2116 pthread_mutex_unlock(&pComponentPrivate_CC->codecFlush_mutex);
2117 // mutex above signals that the dsp side has finished flushing and processing can continue
2118 pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2119 pHandle->pApplicationPrivate,
2120 OMX_EventCmdComplete,
2130 else if ( args[2] == (void *)EMMCodecOuputBuffer)
2132 if (args[0] == (void *)USN_ERR_NONE )
2134 for (i=0; i < pComponentPrivate_CC->nNumOutputBufPending; i++) {
2135 #ifdef __PERF_INSTRUMENTATION__
2136 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
2137 PREF(pComponentPrivate_CC->pOutputBufHdrPending[i],pBuffer),
2138 PREF(pComponentPrivate_CC->pOutputBufHdrPending[i],nFilledLen),
2141 pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
2142 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2143 pComponentPrivate_CC->pOutputBufHdrPending[i]
2145 pComponentPrivate_CC->nOutStandingFillDones--;
2146 pComponentPrivate_CC->pOutputBufHdrPending[i] = NULL;
2148 pComponentPrivate_CC->nNumOutputBufPending=0;
2150 pthread_mutex_lock(&pComponentPrivate_CC->codecFlush_mutex);
2151 if(pComponentPrivate_CC->codecFlush_waitingsignal == 0){
2152 pComponentPrivate_CC->codecFlush_waitingsignal = 1;
2153 pthread_cond_signal(&pComponentPrivate_CC->codecFlush_threshold);
2154 OMX_PRCOMM2(pComponentPrivate_CC->dbg, "flush ack. received. for output port");
2156 pthread_mutex_unlock(&pComponentPrivate_CC->codecFlush_mutex);
2157 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
2158 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2159 OMX_EventCmdComplete,
2173 else if(event == EMMCodecProcessingStoped)
2176 for (i = 0; i < pComponentPrivate_CC->nNumInputBufPending; i++) {
2177 pComponentPrivate_CC->cbInfo.EmptyBufferDone (pComponentPrivate_CC->pHandle,
2178 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2179 pComponentPrivate_CC->pInputBufHdrPending[i]);
2180 pComponentPrivate_CC->pInputBufHdrPending[i] = NULL;
2182 pComponentPrivate_CC->nNumInputBufPending = 0;
2183 for (i=0; i < pComponentPrivate_CC->nNumOutputBufPending; i++) {
2184 pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
2185 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2186 pComponentPrivate_CC->pOutputBufHdrPending[i]);
2187 pComponentPrivate_CC->nOutStandingFillDones--;
2188 pComponentPrivate_CC->pOutputBufHdrPending[i] = NULL;
2190 pComponentPrivate_CC->nNumOutputBufPending=0;
2191 pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);
2192 if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
2193 pComponentPrivate_CC->codecStop_waitingsignal = 1;
2194 pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
2195 OMX_PRCOMM2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed");
2197 pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
2199 if (!pComponentPrivate_CC->bNoIdleOnStop)
2201 pComponentPrivate_CC->curState = OMX_StateIdle;
2202 #ifdef RESOURCE_MANAGER_ENABLED
2203 eError = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet,
2204 OMX_WMA_Decoder_COMPONENT,
2205 OMX_StateIdle, 1234, NULL);
2207 if (pComponentPrivate_CC->bPreempted == 0) {
2208 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
2209 pComponentPrivate_CC->pHandle->pApplicationPrivate,
2210 OMX_EventCmdComplete,
2211 OMX_CommandStateSet,
2212 pComponentPrivate_CC->curState,
2218 pComponentPrivate_CC->bDspStoppedWhileExecuting = OMX_TRUE;
2219 pComponentPrivate_CC->bNoIdleOnStop= OMX_FALSE;
2223 else if (event == EMMCodecProcessingPaused)
2226 pComponentPrivate_CC->curState = OMX_StatePause;
2228 pComponentPrivate_CC->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
2229 OMX_EventCmdComplete,
2230 OMX_CommandStateSet,
2231 pComponentPrivate_CC->curState,
2234 else if (event == EMMCodecDspError)
2237 switch ( (OMX_U32) args [4])
2239 /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
2240 * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
2241 * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
2242 * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
2243 * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
2244 * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
2245 * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
2246 * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
2248 #ifdef _ERROR_PROPAGATION__
2251 case USN_ERR_ALGCTRL:
2252 case USN_ERR_STRMCTRL:
2253 case USN_ERR_UNKNOWN_MSG:
2256 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2257 pComponentPrivate_CC->curState = OMX_StateInvalid;
2258 pHandle = pComponentPrivate_CC->pHandle;
2259 pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2260 pHandle->pApplicationPrivate,
2262 OMX_ErrorInvalidState,
2269 case USN_ERR_WARNING:
2270 case USN_ERR_PROCESS:
2271 WMADEC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
2278 if(event == EMMCodecDspMessageRecieved) {
2279 OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: commandedState = %p",__LINE__,args[0]);
2280 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg1 = %p",__LINE__,args[1]);
2281 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg2 = %p",__LINE__,args[2]);
2284 #ifdef _ERROR_PROPAGATION__
2286 else if (event ==EMMCodecInitError) {
2287 /* Cheking for MMU_fault */
2288 if((args[4] == (void *)USN_ERR_UNKNOWN_MSG) && (args[5] == NULL)) {
2290 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2291 pComponentPrivate_CC->curState = OMX_StateInvalid;
2292 pHandle = pComponentPrivate_CC->pHandle;
2293 pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2294 pHandle->pApplicationPrivate,
2296 OMX_ErrorInvalidState,
2301 else if (event ==EMMCodecInternalError) {
2303 /* Cheking for MMU_fault */
2304 if((args[4] == (void *)USN_ERR_UNKNOWN_MSG) && (args[5] == NULL)) {
2306 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
2307 pComponentPrivate_CC->curState = OMX_StateInvalid;
2308 pHandle = pComponentPrivate_CC->pHandle;
2309 pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
2310 pHandle->pApplicationPrivate,
2312 OMX_ErrorInvalidState,
2321 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting the WMADECLCML_Callback Function",__LINE__);
2324 /* -------------------------------------------------------------------*/
2326 * WMADEC_GetCorresponding_LCMLHeader() function will be called by WMADEC_LCML_Callback
2327 * component to write the msg
2328 * @param *pBuffer, Event which gives to details about USN status
2329 * @param LCML_NBAMRENC_BUFHEADERTYPE **ppLcmlHdr
2331 * @retval OMX_NoError Success, ready to roll
2332 * OMX_Error_BadParameter The input parameter pointer is null
2334 /* -------------------------------------------------------------------*/
2336 OMX_ERRORTYPE WMADECGetCorresponding_LCMLHeader(WMADEC_COMPONENT_PRIVATE *pComponentPrivate,
2339 LCML_WMADEC_BUFHEADERTYPE **ppLcmlHdr)
2342 OMX_ERRORTYPE eError = OMX_ErrorNone;
2343 LCML_WMADEC_BUFHEADERTYPE *pLcmlBufHeader;
2344 WMADEC_COMPONENT_PRIVATE *pComponentPrivate_CC;
2350 pComponentPrivate_CC = pComponentPrivate;
2351 nIpBuf = pComponentPrivate_CC->pInputBufferList->numBuffers;
2352 nOpBuf = pComponentPrivate_CC->pOutputBufferList->numBuffers;
2354 while (!pComponentPrivate_CC->bInitParamsInitialized)
2362 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Inside WMADECGetCorresponding_LCMLHeader..",__LINE__);
2363 OMX_PRINT2(pComponentPrivate->dbg, "%d :: eDir = %d",__LINE__,eDir);
2365 if(eDir == OMX_DirInput) {
2367 OMX_PRINT1(pComponentPrivate->dbg, "%d :: pComponentPrivate_CC = %p",__LINE__,
2368 pComponentPrivate_CC);
2369 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT] = %p",
2370 __LINE__,pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT]);
2372 pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[INPUT_PORT];
2373 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: nIpBuf = %d",__LINE__,nIpBuf);
2374 for(i=0; i<nIpBuf; i++)
2376 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
2377 OMX_PRBUFFER1(pComponentPrivate->dbg, "pLcmlBufHeader->buffer->pBuffer = %p",
2378 pLcmlBufHeader->buffer->pBuffer);
2379 if(pBuffer == pLcmlBufHeader->buffer->pBuffer)
2381 *ppLcmlHdr = pLcmlBufHeader;
2382 OMX_ERROR2(pComponentPrivate->dbg, "%d::Corresponding LCML Header Found",__LINE__);
2388 else if (eDir == OMX_DirOutput)
2391 pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[OUTPUT_PORT];
2392 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
2393 OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer- = %p",pLcmlBufHeader->buffer);
2394 OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer->pBuffer = %p",
2395 pLcmlBufHeader->buffer->pBuffer);
2396 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: nOpBuf = %d",__LINE__,nOpBuf);
2398 for(i=0; i<nOpBuf; i++)
2400 if(pBuffer == pLcmlBufHeader->buffer->pBuffer)
2402 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
2403 OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->buffer->pBuffer = %p",
2404 pLcmlBufHeader->buffer->pBuffer);
2405 *ppLcmlHdr = pLcmlBufHeader;
2406 OMX_ERROR2(pComponentPrivate->dbg, "%d::Corresponding LCML Header Found",__LINE__);
2414 OMX_PRINT1(pComponentPrivate->dbg, "%d:: Invalid Buffer Type :: exiting...",__LINE__);
2422 /* -------------------------------------------------------------------*/
2424 * WMADEC_GetLCMLHandle()
2426 * @retval OMX_HANDLETYPE
2428 -------------------------------------------------------------------*/
2431 OMX_HANDLETYPE WMADECGetLCMLHandle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2435 OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
2436 OMX_HANDLETYPE pHandle = NULL;
2438 OMX_ERRORTYPE eError;
2440 handle = dlopen("libLCML.so", RTLD_LAZY);
2443 fputs(dlerror(), stderr);
2447 fpGetHandle = dlsym (handle, "GetHandle");
2448 if ((error = dlerror()) != NULL)
2450 fputs(error, stderr);
2454 eError = (*fpGetHandle)(&pHandle);
2455 if(eError != OMX_ErrorNone)
2457 eError = OMX_ErrorUndefined;
2458 OMX_ERROR4(pComponentPrivate->dbg, "eError != OMX_ErrorNone...");
2463 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
2470 /*=================================================================*/
2471 /*WINDOWS Explicit dll load procedure
2472 ===================================================================*/
2473 OMX_HANDLETYPE WMADECGetLCMLHandle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2476 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
2477 OMX_HANDLETYPE pHandle = NULL;
2478 OMX_ERRORTYPE eError;
2479 HINSTANCE hDLL; // Handle to DLL
2480 LPFNDLLFUNC1 fpGetHandle1;
2481 hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0);
2484 OMX_ERROR4(pComponentPrivate->dbg, "BML Load Failed!!!");
2488 fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
2496 // call the function
2497 eError = fpGetHandle1(&pHandle);
2498 if(eError != OMX_ErrorNone) {
2499 eError = OMX_ErrorUndefined;
2500 OMX_ERROR4(pComponentPrivate->dbg, "eError != OMX_ErrorNone...");
2505 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
2515 /*=================================================================*/
2516 /**@FreeLCMLHandle */
2517 /*==================================================================*/
2518 OMX_ERRORTYPE WMADECFreeLCMLHandle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2522 OMX_ERRORTYPE eError = OMX_ErrorNone;
2524 if (pComponentPrivate->bLcmlHandleOpened)
2526 retValue = dlclose(pComponentPrivate->pLcmlHandle);
2530 eError = OMX_ErrorUndefined;
2532 pComponentPrivate->bLcmlHandleOpened = 0;
2538 /*=================================================================*/
2539 /** @ FreeLCMLHandle */
2540 /*==================================================================*/
2541 OMX_ERRORTYPE WMADECFreeLCMLHandle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2545 OMX_ERRORTYPE eError = OMX_ErrorNone;
2547 if (pComponentPrivate->bLcmlHandleOpened)
2550 retValue = FreeLibrary(pComponentPrivate->pLcmlHandle);
2551 if (retValue == 0) /* Zero Indicates failure */
2553 eError = OMX_ErrorUndefined;
2555 pComponentPrivate->bLcmlHandleOpened = 0;
2560 /* ================================================================================= */
2562 * @fn WMADEC_CommandToIdle() description for WMADEC_CommandToIdle
2563 WMADEC_CommandToIdle().
2564 This component is called by HandleCommand() when the component is commanded to Idle
2565 * @param pComponent handle for this instance of the component
2571 * @return OMX_ERRORTYPE
2573 /* ================================================================================ */
2574 OMX_ERRORTYPE WMADEC_CommandToIdle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2576 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
2577 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
2579 #ifdef RESOURCE_MANAGER_ENABLED
2580 OMX_ERRORTYPE rm_error = OMX_ErrorNone;
2582 OMX_ERRORTYPE eError = OMX_ErrorNone;
2585 int inputPortFlag = 0;
2586 int outputPortFlag = 0;
2589 LCML_CALLBACKTYPE cb;
2593 OMX_PRINT1(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Idle ",__LINE__);
2594 OMX_PRINT2(pComponentPrivate->dbg, "curstate = %d",pComponentPrivate->curState);
2595 if (pComponentPrivate->curState == OMX_StateIdle)
2597 pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
2598 OMX_EventError, OMX_ErrorSameState,
2599 OMX_TI_ErrorMinor, NULL);
2600 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",__LINE__);
2602 else if (pComponentPrivate->curState == OMX_StateLoaded)
2604 #ifdef __PERF_INSTRUMENTATION__
2605 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup);
2607 if (pComponentPrivate->dasfmode == 1)
2609 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled= FALSE;
2610 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated= FALSE;
2612 if(pComponentPrivate->streamID == 0)
2614 OMX_ERROR4(pComponentPrivate->dbg, "**************************************");
2615 OMX_ERROR4(pComponentPrivate->dbg, ":: Error = OMX_ErrorInsufficientResources");
2616 OMX_ERROR4(pComponentPrivate->dbg, "**************************************");
2617 eError = OMX_ErrorInsufficientResources;
2618 pComponentPrivate->curState = OMX_StateInvalid;
2620 pComponentPrivate->cbInfo.EventHandler(pHandle,
2621 pHandle->pApplicationPrivate,
2623 OMX_ErrorInvalidState,
2631 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: In while loop OMX_StateLoaded [INPUT_PORT]->bPopulated %d ",
2632 __LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
2633 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: In while loop OMX_StateLoaded [INPUT_PORT]->bEnabled %d ",
2634 __LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled);
2635 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: In while loop OMX_StateLoaded [OUTPUT_PORT]->bPopulated %d ",
2636 __LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated);
2637 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: In while loop OMX_StateLoaded [OUTPUT_PORT]->bEnabled %d ",
2638 __LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
2640 if (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
2641 pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled)
2646 if (!pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated &&
2647 !pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled)
2652 if (pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated &&
2653 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)
2658 if (!pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated &&
2659 !pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)
2664 if (inputPortFlag && outputPortFlag)
2668 /* From Loaded to Idle. All enable ports are populated. */
2669 pComponentPrivate->InLoaded_readytoidle = 1;
2671 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2672 pthread_cond_wait(&pComponentPrivate->InLoaded_threshold,
2673 &pComponentPrivate->InLoaded_mutex);
2674 /*---------------------*/
2675 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2677 OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
2681 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Inside WMADECHandleCommand",__LINE__);
2682 cb.LCML_Callback = (void *) WMADECLCML_Callback;
2683 pLcmlHandle = (OMX_HANDLETYPE) WMADECGetLCMLHandle(pComponentPrivate);
2684 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Inside WMADECHandleCommand",__LINE__);
2685 if (pLcmlHandle == NULL)
2687 OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML Handle is NULL........exiting..",__LINE__);
2691 /* Got handle of dsp via phandle filling information about DSP specific things */
2692 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
2693 eError = WMADECFill_LCMLInitParams(pHandle, pLcmlDsp, arr);
2694 if(eError != OMX_ErrorNone)
2696 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from WMADECFill_LCMLInitParams()",
2701 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
2702 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
2704 /*filling create phase params */
2705 cb.LCML_Callback = (void *) WMADECLCML_Callback;
2706 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Calling LCML_InitMMCodec...",__LINE__);
2709 /* TeeDN will be default for decoder component */
2710 OMX_PRSTATE2(pComponentPrivate->dbg, "WMA decoder support TeeDN");
2711 OMX_PRDSP2(pComponentPrivate->dbg, "pComponentPrivate Before calling InitMMCodec = %p",
2714 OMX_PRINT1(pComponentPrivate->dbg, "&pComponentPrivate = %p",&pComponentPrivate);
2715 OMX_PRDSP2(pComponentPrivate->dbg, "pLcmlHandle = %p",pLcmlHandle);
2716 OMX_PRINT2(pComponentPrivate->dbg, "p = %p",p);
2717 OMX_PRDSP1(pComponentPrivate->dbg, "pLcmlHandle->pCodecinterfacehandle = %p",
2718 ((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle);
2720 eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
2721 p,&pLcmlHandle,(void *)p,&cb,(OMX_STRING)pComponentPrivate->sDeviceString);
2722 OMX_PRDSP2(pComponentPrivate->dbg, "pComponentPrivate After calling InitMMCodec = %p",
2725 if(eError != OMX_ErrorNone)
2727 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from LCML_Init() error = %d",__LINE__, eError);
2728 /* send an event to client */
2729 /* client should unload the component if the codec is not able to load */
2730 pComponentPrivate->cbInfo.EventHandler (pHandle,
2731 pHandle->pApplicationPrivate,
2739 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
2740 p,&pLcmlHandle,(void *)p,&cb);
2741 if (eError != OMX_ErrorNone)
2743 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error : InitMMCodec failed...>>>>>> ",__LINE__);
2749 #ifdef HASHINGENABLE
2750 /* Enable the Hashing Code */
2751 eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, OMX_TRUE);
2752 if (eError != OMX_ErrorNone) {
2753 OMX_ERROR4(pComponentPrivate->dbg, "Failed to set Mapping State");
2758 #ifdef RESOURCE_MANAGER_ENABLED
2759 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: WMADEC: About to call RMProxy_SendCommand", __LINE__);
2760 pComponentPrivate->rmproxyCallback.RMPROXY_Callback =
2761 (void *) WMAD_ResourceManagerCallback;
2763 if (pComponentPrivate->curState != OMX_StateWaitForResources){
2764 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource,
2765 OMX_WMA_Decoder_COMPONENT,
2766 WMA_CPU, 1234, NULL);
2768 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: WMADEC: RMProxy_SendCommand returned %d",
2770 if(rm_error == OMX_ErrorNone)
2772 /* resource is available */
2773 pComponentPrivate->curState = OMX_StateIdle;
2774 pComponentPrivate->cbInfo.EventHandler( pHandle,
2775 pHandle->pApplicationPrivate,
2776 OMX_EventCmdComplete,
2777 OMX_CommandStateSet,
2778 pComponentPrivate->curState,
2780 #ifdef __PERF_INSTRUMENTATION__
2781 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete |
2782 PERF_BoundarySetup);
2784 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet,
2785 OMX_WMA_Decoder_COMPONENT,
2786 OMX_StateIdle,0,NULL);
2789 else if(rm_error == OMX_ErrorInsufficientResources){
2790 /* resource is not available, need set state to OMX_StateWaitForResources */
2791 pComponentPrivate->curState = OMX_StateWaitForResources;
2792 pComponentPrivate->cbInfo.EventHandler(pHandle,
2793 pHandle->pApplicationPrivate,
2794 OMX_EventCmdComplete,
2795 OMX_CommandStateSet,
2796 pComponentPrivate->curState,
2798 OMX_ERROR2(pComponentPrivate->dbg, "%d :: WMADEC: Error - insufficient resources", __LINE__);
2801 OMX_PRSTATE2(pComponentPrivate->dbg, "Setting to OMX_StateIdle - Line %d",__LINE__);
2802 pComponentPrivate->curState = OMX_StateIdle;
2803 pComponentPrivate->cbInfo.EventHandler( pHandle,
2804 pHandle->pApplicationPrivate,
2805 OMX_EventCmdComplete,
2806 OMX_CommandStateSet,
2807 pComponentPrivate->curState,
2811 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: WMADEC: State has been Set to Idle",__LINE__);
2813 #ifdef __PERF_INSTRUMENTATION__
2814 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete |
2815 PERF_BoundarySetup);
2819 else if (pComponentPrivate->curState == OMX_StateExecuting)
2821 char *pArgs = "damedesuStr";
2822 #ifdef HASHINGENABLE
2824 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
2825 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
2826 if (eError != OMX_ErrorNone) {
2827 OMX_ERROR2(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!");
2830 /*Set the bIsStopping bit */
2831 #ifdef __PERF_INSTRUMENTATION__
2832 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete |
2833 PERF_BoundarySteadyState);
2836 OMX_PRINT2(pComponentPrivate->dbg, "%d :: WMADEC: About to set bIsStopping bit", __LINE__);
2837 if (pComponentPrivate->codecStop_waitingsignal == 0){
2838 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
2840 eError = LCML_ControlCodec(
2841 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
2842 MMCodecControlStop,(void *)pArgs);
2843 if (pComponentPrivate->codecStop_waitingsignal == 0){
2844 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
2845 pComponentPrivate->codecStop_waitingsignal = 0; // reset the wait condition for next time
2846 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
2848 if(eError != OMX_ErrorNone)
2850 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..", __LINE__);
2854 OMX_PRSTATE2(pComponentPrivate->dbg, "%d: Codec has been stopped", __LINE__);
2857 else if(pComponentPrivate->curState == OMX_StatePause)
2859 char *pArgs = "damedesuStr";
2860 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Comp: Stop Command Received",__LINE__);
2861 #ifdef HASHINGENABLE
2863 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle;
2864 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle);
2865 if (eError != OMX_ErrorNone) {
2866 OMX_ERROR2(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!");
2870 #ifdef __PERF_INSTRUMENTATION__
2871 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete |
2872 PERF_BoundarySteadyState);
2875 if (pComponentPrivate->codecStop_waitingsignal == 0){
2876 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
2878 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
2881 if (pComponentPrivate->codecStop_waitingsignal == 0){
2882 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
2883 pComponentPrivate->codecStop_waitingsignal = 0;
2884 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
2886 pComponentPrivate->curState = OMX_StateIdle;
2887 #ifdef RESOURCE_MANAGER_ENABLED
2889 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet,
2890 OMX_WMA_Decoder_COMPONENT,
2891 OMX_StateIdle, 1234, NULL);
2892 if(rm_error != OMX_ErrorNone)
2894 OMX_ERROR4(pComponentPrivate->dbg, "%d :: ERROR: Send Comman Failed", __LINE__);
2899 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: The component is stopped",__LINE__);
2900 pComponentPrivate->cbInfo.EventHandler (pHandle,
2901 pHandle->pApplicationPrivate,
2902 OMX_EventCmdComplete,OMX_CommandStateSet,
2903 pComponentPrivate->curState,
2908 /* This means, it is invalid state from application */
2909 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
2910 pComponentPrivate->cbInfo.EventHandler(pHandle,
2911 pHandle->pApplicationPrivate,
2913 OMX_ErrorIncorrectStateTransition,
2919 if (eError != OMX_ErrorNone ) {
2920 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2921 pComponentPrivate->pHandle->pApplicationPrivate,
2929 /* ================================================================================= */
2931 * @fn WMADEC_CommandToLoaded() description for WMADEC_CommandToLoaded
2932 WMADEC_CommandToLoaded().
2933 This component is called by HandleCommand() when the component is commanded to Loaded
2934 * @param pComponent handle for this instance of the component
2940 * @return OMX_ERRORTYPE
2942 /* ================================================================================ */
2943 OMX_ERRORTYPE WMADEC_CommandToLoaded(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
2946 OMX_COMPONENTTYPE *pHandle =
2947 (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
2948 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
2949 OMX_ERRORTYPE eError = OMX_ErrorNone;
2951 OMX_PRINT1(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Loaded - curState = %d",
2952 __LINE__,pComponentPrivate->curState);
2953 if (pComponentPrivate->curState == OMX_StateLoaded)
2955 pComponentPrivate->cbInfo.EventHandler (pHandle,
2956 pHandle->pApplicationPrivate,
2961 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",__LINE__);
2964 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d: pComponentPrivate->pInputBufferList->numBuffers = %d",
2965 __LINE__,pComponentPrivate->pInputBufferList->numBuffers);
2966 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d: pComponentPrivate->pOutputBufferList->numBuffers = %d",
2967 __LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
2969 if (pComponentPrivate->curState == OMX_StateWaitForResources)
2971 OMX_PRDSP2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Loaded",__LINE__);
2973 #ifdef __PERF_INSTRUMENTATION__
2974 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
2976 pComponentPrivate->curState = OMX_StateLoaded;
2978 #ifdef __PERF_INSTRUMENTATION__
2979 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
2981 pComponentPrivate->cbInfo.EventHandler (pHandle,
2982 pHandle->pApplicationPrivate,
2983 OMX_EventCmdComplete,
2984 OMX_CommandStateSet,
2985 pComponentPrivate->curState,
2989 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: In side OMX_StateLoaded State: ",__LINE__);
2990 if (pComponentPrivate->curState != OMX_StateIdle &&
2991 pComponentPrivate->curState != OMX_StateWaitForResources)
2993 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
2994 pComponentPrivate->cbInfo.EventHandler (pHandle,
2995 pHandle->pApplicationPrivate,
2997 OMX_ErrorIncorrectStateTransition,
3000 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application",__LINE__);
3003 #ifdef __PERF_INSTRUMENTATION__
3004 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
3006 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %d",
3007 pComponentPrivate->pInputBufferList->numBuffers);
3008 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->numBuffers = %d",
3009 pComponentPrivate->pOutputBufferList->numBuffers);
3012 OMX_PRDSP2(pComponentPrivate->dbg, "HandleCommand - in while(1) loop");
3013 if (!pComponentPrivate->pInputBufferList->numBuffers &&
3014 !pComponentPrivate->pOutputBufferList->numBuffers)
3018 pComponentPrivate->InIdle_goingtoloaded = 1;
3020 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
3021 pthread_cond_wait(&pComponentPrivate->InIdle_threshold,
3022 &pComponentPrivate->InIdle_mutex);
3023 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
3025 OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
3030 /* Now Deinitialize the component No error should be returned from
3031 * this function. It should clean the system as much as possible */
3032 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: In side OMX_StateLoaded State: ",__LINE__);
3033 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3034 EMMCodecControlDestroy, (void *)p);
3035 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: In side OMX_StateLoaded State: ",__LINE__);
3036 if (eError != OMX_ErrorNone)
3038 OMX_ERROR4(pComponentPrivate->dbg, "%d : Error: in Destroying the codec: no. %x",__LINE__, eError);
3041 OMX_PRDSP1(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Loaded",__LINE__);
3042 #ifdef __PERF_INSTRUMENTATION__
3043 PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
3045 eError = EXIT_COMPONENT_THRD;
3046 pComponentPrivate->bInitParamsInitialized = 0;
3047 /* Send StateChangeNotification to application */
3048 pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
3052 if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD ) {
3053 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3054 pComponentPrivate->pHandle->pApplicationPrivate,
3063 /* ================================================================================= */
3065 * @fn WMADEC_CommandToExecuting() description for WMADEC_CommandToExecuting
3066 WMADEC_CommandToExecuting().
3067 This component is called by HandleCommand() when the component is commanded to Executing
3068 * @param pComponent handle for this instance of the component
3074 * @return OMX_ERRORTYPE
3076 /* ================================================================================ */
3077 OMX_ERRORTYPE WMADEC_CommandToExecuting(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
3080 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
3081 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
3083 OMX_ERRORTYPE eError = OMX_ErrorNone;
3086 LCML_WMADEC_BUFHEADERTYPE *pLcmlHdr = NULL;
3087 OMX_U32 cmdValues[3];
3088 char *pArgs = "damedesuStr";
3090 #ifdef RESOURCE_MANAGER_ENABLED
3093 OMX_PRINT1(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Executing ",__LINE__);
3094 if (pComponentPrivate->curState == OMX_StateExecuting)
3096 pComponentPrivate->cbInfo.EventHandler (pHandle,
3097 pHandle->pApplicationPrivate,
3102 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",__LINE__);
3105 else if (pComponentPrivate->curState == OMX_StateIdle)
3107 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3108 /* Sending commands to DSP via LCML_ControlCodec third argument
3109 is not used for time being */
3111 pComponentPrivate->nNumInputBufPending = 0;
3112 pComponentPrivate->nNumOutputBufPending = 0;
3113 if(pComponentPrivate->dasfmode == 1)
3116 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---",__LINE__);
3117 if (pComponentPrivate->pHeaderInfo->iChannel == 1)
3119 pComponentPrivate->pParams->iAudioFormat = WMA_MONO_CHANNEL;
3123 pComponentPrivate->pParams->iAudioFormat = WMA_STEREO_NON_INTERLEAVED;
3125 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iAudioFormat = %d", pComponentPrivate->pParams->iAudioFormat);
3126 pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
3127 pComponentPrivate->pParams->iSamplingRate =
3128 pComponentPrivate->pHeaderInfo->iSamplePerSec;
3130 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iSamplingRate = %ld",
3131 pComponentPrivate->pParams->iSamplingRate);
3132 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iStrmId = %ld",
3133 pComponentPrivate->pParams->iStrmId);
3134 OMX_PRINT1(pComponentPrivate->dbg, "pParams->iAudioFormat = %d",
3135 pComponentPrivate->pParams->iAudioFormat);
3137 pValues[0] = USN_STRMCMD_SETCODECPARAMS;
3138 pValues[1] = (OMX_U32)pComponentPrivate->pParams;
3139 pValues[2] = sizeof(WMADEC_AudioCodecParams);
3140 pValues[3] = OUTPUT_PORT;
3141 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3142 EMMCodecControlStrmCtrl,(void *)pValues);
3143 if(eError != OMX_ErrorNone)
3145 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..",
3150 if( pComponentPrivate->dasfmode )
3152 OMX_PRDSP2(pComponentPrivate->dbg, "Setting WMA_IAUDIO_BLOCK");
3153 pComponentPrivate->pDynParams->iOutputFormat = WMA_IAUDIO_BLOCK; /* EAUDIO_BLOCKED */
3157 OMX_PRDSP1(pComponentPrivate->dbg, "Setting WMA_IAUDIO_INTERLEAVED");
3158 pComponentPrivate->pDynParams->iOutputFormat = WMA_IAUDIO_INTERLEAVED; /* EAUDIO_INTERLEAVED */
3160 pComponentPrivate->pDynParams->size = sizeof( WMADEC_UALGParams );
3162 cmdValues[0] = WMA_IUALG_CMD_SETSTATUS;
3163 cmdValues[1] = (OMX_U32)( pComponentPrivate->pDynParams );
3164 cmdValues[2] = sizeof( WMADEC_UALGParams );
3166 p = (void *)&cmdValues;
3167 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3168 EMMCodecControlAlgCtrl, (void *)p);
3170 if(eError != OMX_ErrorNone)
3172 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec algctrl..", __LINE__);
3175 pComponentPrivate->bBypassDSP = 0;
3177 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)(pComponentPrivate->pLcmlHandle))->pCodecinterfacehandle,
3178 EMMCodecControlStart, (void *)pArgs);
3180 if(eError != OMX_ErrorNone)
3182 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Start..", __LINE__);
3185 OMX_PRSTATE2(pComponentPrivate->dbg, ": Codec Has Been Started ");
3187 pComponentPrivate->SendAfterEOS = 1; /*Enrique Zertuche, added because it wasnt set compared with the mp3*/
3189 else if (pComponentPrivate->curState == OMX_StatePause)
3191 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3192 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3193 EMMCodecControlStart, (void *)pArgs);
3194 if (eError != OMX_ErrorNone)
3196 OMX_ERROR4(pComponentPrivate->dbg, "Error While Resuming the codec");
3199 if (pComponentPrivate->nNumInputBufPending <
3200 pComponentPrivate->pInputBufferList->numBuffers)
3202 pComponentPrivate->nNumInputBufPending = pComponentPrivate->pInputBufferList->numBuffers;
3205 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++)
3207 if (pComponentPrivate->pInputBufHdrPending[i])
3209 if (!WMADEC_IsPending(pComponentPrivate,
3210 pComponentPrivate->pInputBufHdrPending[i],
3213 WMADECGetCorresponding_LCMLHeader(
3215 pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
3216 OMX_DirInput, &pLcmlHdr);
3218 WMADEC_SetPending(pComponentPrivate,
3219 pComponentPrivate->pInputBufHdrPending[i],
3222 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3223 EMMCodecInputBuffer,
3224 pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
3225 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
3226 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
3227 (OMX_U8 *) pLcmlHdr->pIpParam,
3228 sizeof(WMADEC_UAlgInBufParamStruct),
3233 pComponentPrivate->nNumInputBufPending = 0;
3234 if (pComponentPrivate->nNumOutputBufPending <
3235 pComponentPrivate->pOutputBufferList->numBuffers)
3237 pComponentPrivate->nNumOutputBufPending =
3238 pComponentPrivate->pOutputBufferList->numBuffers;
3240 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++)
3242 if (pComponentPrivate->pOutputBufHdrPending[i])
3244 if (!WMADEC_IsPending(pComponentPrivate,
3245 pComponentPrivate->pOutputBufHdrPending[i],
3248 WMADECGetCorresponding_LCMLHeader(
3250 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
3251 OMX_DirOutput, &pLcmlHdr);
3253 WMADEC_SetPending(pComponentPrivate,
3254 pComponentPrivate->pOutputBufHdrPending[i],
3257 pComponentPrivate->LastOutputBufferHdrQueued =
3258 pComponentPrivate->pOutputBufHdrPending[i];
3260 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3261 EMMCodecOuputBuffer,
3262 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
3263 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
3264 pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen,
3266 sizeof(WMADEC_UAlgInBufParamStruct),
3271 pComponentPrivate->nNumOutputBufPending = 0;
3275 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3276 pComponentPrivate->cbInfo.EventHandler (pHandle,
3277 pHandle->pApplicationPrivate,
3279 OMX_ErrorIncorrectStateTransition,
3282 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application",__LINE__);
3285 #ifdef RESOURCE_MANAGER_ENABLED
3286 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet,
3287 OMX_WMA_Decoder_COMPONENT,
3288 OMX_StateExecuting, 1234, NULL);
3292 pComponentPrivate->curState = OMX_StateExecuting;
3293 #ifdef __PERF_INSTRUMENTATION__
3294 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart |
3295 PERF_BoundarySteadyState);
3297 /*Send state change notificaiton to Application */
3298 OMX_PRINT1(pComponentPrivate->dbg, "About to call EventHandler");
3299 pComponentPrivate->cbInfo.EventHandler( pHandle, pHandle->pApplicationPrivate,
3300 OMX_EventCmdComplete, OMX_CommandStateSet,
3301 pComponentPrivate->curState, NULL);
3303 if (eError != OMX_ErrorNone ) {
3304 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3305 pComponentPrivate->pHandle->pApplicationPrivate,
3314 /* ================================================================================= */
3316 * @fn WMADEC_CommandToPause() description for WMADEC_CommandToPause
3317 WMADEC_CommandToPause().
3318 This component is called by HandleCommand() when the component is commanded to Paused
3319 * @param pComponent handle for this instance of the component
3325 * @return OMX_ERRORTYPE
3327 /* ================================================================================ */
3328 OMX_ERRORTYPE WMADEC_CommandToPause(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
3331 OMX_COMPONENTTYPE *pHandle =
3332 (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
3333 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
3335 OMX_ERRORTYPE eError = OMX_ErrorNone;
3339 OMX_PRINT1(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Pause",__LINE__);
3340 if (pComponentPrivate->curState == OMX_StatePause)
3342 pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate,
3343 OMX_EventError, OMX_ErrorSameState,
3344 OMX_TI_ErrorMinor, NULL);
3346 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",__LINE__);
3349 if (pComponentPrivate->curState != OMX_StateExecuting &&
3350 pComponentPrivate->curState != OMX_StateIdle)
3352 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3354 pComponentPrivate->cbInfo.EventHandler (pHandle,
3355 pHandle->pApplicationPrivate,
3357 OMX_ErrorIncorrectStateTransition,
3361 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid State Given by Application",__LINE__);
3364 #ifdef __PERF_INSTRUMENTATION__
3365 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
3367 OMX_PRSTATE1(pComponentPrivate->dbg, "About to command to pause");
3368 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
3369 EMMCodecControlPause, (void *)p);
3371 if (eError != OMX_ErrorNone)
3373 OMX_ERROR4(pComponentPrivate->dbg, "%d : Error: in Pausing the codec",__LINE__);
3377 #ifdef RESOURCE_MANAGER_ENABLED
3378 /* notify RM that codec is paused, resources can be redistributed if needed */
3379 eError = RMProxy_NewSendCommand(pHandle,
3381 OMX_WMA_Decoder_COMPONENT,
3387 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c\n",__LINE__);
3389 if (eError != OMX_ErrorNone ) {
3390 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3391 pComponentPrivate->pHandle->pApplicationPrivate,
3399 /* ================================================================================= */
3401 * @fn WMADEC_CommandToWaitForResources() description for WMADEC_CommandToWaitForResources
3402 WMADEC_CommandToWaitForResources().
3403 This component is called by HandleCommand() when the component is commanded
3405 * @param pComponent handle for this instance of the component
3411 * @return OMX_ERRORTYPE
3413 /* ================================================================================ */
3414 OMX_ERRORTYPE WMADEC_CommandToWaitForResources(WMADEC_COMPONENT_PRIVATE *pComponentPrivate)
3417 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
3419 OMX_ERRORTYPE eError = OMX_ErrorNone;
3421 if (pComponentPrivate->curState == OMX_StateWaitForResources)
3423 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3425 pComponentPrivate->cbInfo.EventHandler (pHandle,
3426 pHandle->pApplicationPrivate,
3432 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application",__LINE__);
3434 else if (pComponentPrivate->curState == OMX_StateLoaded)
3436 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3437 pComponentPrivate->curState = OMX_StateWaitForResources;
3439 pComponentPrivate->cbInfo.EventHandler(pHandle,
3440 pHandle->pApplicationPrivate,
3441 OMX_EventCmdComplete,
3442 OMX_CommandStateSet,
3443 pComponentPrivate->curState,
3448 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3450 pComponentPrivate->cbInfo.EventHandler(pHandle,
3451 pHandle->pApplicationPrivate,
3453 OMX_ErrorIncorrectStateTransition,
3461 /* ================================================================================= */
3463 * @fn WMADEC_SetPending() description for WMADEC_SetPending
3464 WMADEC_SetPending().
3465 This component is called when a buffer is queued to the LCML
3466 * @param pComponent handle for this instance of the component
3472 * @return OMX_ERRORTYPE
3474 /* ================================================================================ */
3475 void WMADEC_SetPending(WMADEC_COMPONENT_PRIVATE *pComponentPrivate,
3476 OMX_BUFFERHEADERTYPE *pBufHdr,
3482 if (eDir == OMX_DirInput)
3484 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
3486 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i])
3488 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
3489 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS PENDING \
3490 ******************************",i);
3496 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
3498 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i])
3500 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
3501 OMX_PRBUFFER2(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS PENDING \
3502 ******************************",i);
3507 /* ================================================================================= */
3509 * @fn WMADEC_ClearPending() description for WMADEC_ClearPending
3510 WMADEC_ClearPending().
3511 This component is called when a buffer is returned from the LCML
3512 * @param pComponent handle for this instance of the component
3518 * @return OMX_ERRORTYPE
3520 /* ================================================================================ */
3522 void WMADEC_ClearPending(WMADEC_COMPONENT_PRIVATE *pComponentPrivate,
3523 OMX_BUFFERHEADERTYPE *pBufHdr,
3529 if (eDir == OMX_DirInput)
3531 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
3533 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i])
3535 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
3536 OMX_PRBUFFER1(pComponentPrivate->dbg, "*******************INPUT BUFFER %d IS RECLAIMED\
3537 ******************************",i);
3543 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
3545 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i])
3547 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
3548 OMX_PRBUFFER1(pComponentPrivate->dbg, "*******************OUTPUT BUFFER %d IS RECLAIMED******************************",i);
3554 /* ================================================================================= */
3556 * @fn WMADEC_IsPending() description for WMADEC_IsPending
3558 This method returns the pending status to the buffer
3559 * @param pComponent handle for this instance of the component
3565 * @return OMX_ERRORTYPE
3567 /* ================================================================================ */
3568 OMX_U32 WMADEC_IsPending(WMADEC_COMPONENT_PRIVATE *pComponentPrivate,
3569 OMX_BUFFERHEADERTYPE *pBufHdr,
3575 if (eDir == OMX_DirInput)
3577 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
3579 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i])
3581 return pComponentPrivate->pInputBufferList->bBufferPending[i];
3587 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
3589 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i])
3591 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
3598 /* ================================================================================= */
3600 * @fn WMADEC_IsValid() description for WMADEC_Fill_LCMLInitParamsEx
3602 This method checks to see if a buffer returned from the LCML is valid.
3603 * @param pComponent handle for this instance of the component
3609 * @return OMX_ERRORTYPE
3611 /* ================================================================================ */
3612 OMX_U32 WMADEC_IsValid(WMADEC_COMPONENT_PRIVATE *pComponentPrivate,
3619 if (eDir == OMX_DirInput)
3621 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++)
3623 if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer)
3631 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++)
3633 if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer)
3643 /* ================================================================================= */
3645 * @fn WMADEC_Fill_LCMLInitParamsEx() description for WMADEC_Fill_LCMLInitParamsEx
3646 WMADEC_Fill_LCMLInitParamsEx().
3647 This method fills the LCML init parameters.
3648 * @param pComponent handle for this instance of the component
3654 * @return OMX_ERRORTYPE
3656 /* ================================================================================ */
3658 OMX_ERRORTYPE WMADECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport)
3660 OMX_ERRORTYPE eError = OMX_ErrorNone;
3661 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
3663 OMX_BUFFERHEADERTYPE *pTemp;
3665 LCML_WMADEC_BUFHEADERTYPE *pTemp_lcml = NULL;
3666 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
3667 WMADEC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
3669 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entered WMADECFill_LCMLInitParams",__LINE__);
3670 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: WMADECFill_LCMLInitParams - pComponentPrivate = %p",
3671 __LINE__,pComponentPrivate);
3672 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: WMADECFill_LCMLInitParams - pHandle = %p",
3675 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
3676 nIpBufSize = INPUT_WMADEC_BUFFER_SIZE;
3678 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
3679 nOpBufSize = pComponentPrivate->pPortDef[OUTPUT_BUFFER]->nBufferSize;
3682 OMX_PRBUFFER1(pComponentPrivate->dbg, "nIpBuf = %ld",nIpBuf);
3683 OMX_PRBUFFER1(pComponentPrivate->dbg, "nOpBuf = %ld",nOpBuf);
3684 if(indexport == 0 || indexport == -1){
3685 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
3686 size_lcml = nIpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
3687 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
3688 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
3689 OMX_PRDSP1(pComponentPrivate->dbg, "Line %d::pTemp_lcml = %p",__LINE__,pTemp_lcml);
3691 if(pTemp_lcml == NULL)
3693 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Memory Allocation Failed",__LINE__);
3694 eError = OMX_ErrorInsufficientResources;
3698 pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
3700 OMX_PRBUFFER1(pComponentPrivate->dbg, "nIpBuf = %ld",nIpBuf);
3702 for (i=0; i<nIpBuf; i++)
3704 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
3705 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3706 pTemp->nAllocLen = nIpBufSize;
3707 pTemp->nFilledLen = nIpBufSize;
3708 pTemp->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
3709 pTemp->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
3710 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3711 pTemp->nTickCount = NOT_USED;
3712 pTemp_lcml->buffer = pTemp;
3713 pTemp_lcml->eDir = OMX_DirInput;
3715 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
3716 sizeof(WMADEC_UAlgInBufParamStruct),
3717 WMADEC_UAlgInBufParamStruct);
3719 if (pTemp_lcml->pIpParam == NULL)
3721 /* Free previously allocated memory before bailing */
3722 if (pTemp_lcml != NULL) {
3723 OMX_MEMFREE_STRUCT(pTemp_lcml);
3726 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Malloc Failed...Exiting..",__LINE__);
3729 pTemp_lcml->pIpParam->bLastBuffer = 0;
3731 /* This means, it is not a last buffer. This flag is to be modified by
3732 * the application to indicate the last buffer */
3733 pTemp->nFlags = NORMAL_BUFFER;
3737 if(indexport == 1 || indexport == -1){
3738 /* Allocate memory for all output buffer headers..
3739 * This memory pointer will be sent to LCML */
3740 size_lcml = nOpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
3741 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
3742 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
3744 if(pTemp_lcml == NULL)
3746 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Memory Allocation Failed",__LINE__);
3747 eError = OMX_ErrorInsufficientResources;
3751 pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
3753 pComponentPrivate->pOutputBufferList->EosFlagSent = 0;
3754 pComponentPrivate->InputEosSet = 0;
3756 for (i=0; i<nOpBuf; i++)
3758 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
3759 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3760 pTemp->nAllocLen = nOpBufSize;
3761 pTemp->nFilledLen = nOpBufSize;
3762 pTemp->nVersion.s.nVersionMajor = WMADEC_MAJOR_VER;
3763 pTemp->nVersion.s.nVersionMinor = WMADEC_MINOR_VER;
3764 pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
3765 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3766 pTemp->nTickCount = NOT_USED;
3767 /* This means, it is not a last buffer. This flag is to be modified by
3768 * the application to indicate the last buffer */
3770 pTemp_lcml->buffer = pTemp;
3771 pTemp_lcml->eDir = OMX_DirOutput;
3772 pTemp->nFlags = NORMAL_BUFFER;
3777 pComponentPrivate->bPortDefsAllocated = 1;
3779 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting WMADECFill_LCMLInitParams",__LINE__);
3781 pComponentPrivate->bInitParamsInitialized = 1;
3785 /* =========================================================================*/
3788 /* desc Gets aBits number of bits from position aPosition of one buffer */
3789 /* and returns the value in a TUint value. */
3790 /* =========================================================================*/
3791 OMX_U32 WMADEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition)
3793 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: Entering WMADEC_GetBits",__LINE__);
3795 OMX_U32 nNumBitsRead = 0;
3796 OMX_U32 nBytePosition = 0;
3797 OMX_U8 nBitPosition = 0;
3798 nBytePosition = *nPosition / 8;
3799 nBitPosition = *nPosition % 8;
3801 if (bIcreasePosition)
3802 *nPosition += nBits;
3803 nOutput = ((OMX_U32)pBuffer[nBytePosition] << (24+nBitPosition) );
3804 nNumBitsRead = nNumBitsRead + (8 - nBitPosition);
3805 if (nNumBitsRead < nBits)
3807 nOutput = nOutput | ( pBuffer[nBytePosition + 1] << (16+nBitPosition));
3808 nNumBitsRead = nNumBitsRead + 8;
3810 if (nNumBitsRead < nBits)
3812 nOutput = nOutput | ( pBuffer[nBytePosition + 2] << (8+nBitPosition));
3813 nNumBitsRead = nNumBitsRead + 8;
3815 if (nNumBitsRead < nBits)
3817 nOutput = nOutput | ( pBuffer[nBytePosition + 3] << (nBitPosition));
3818 nNumBitsRead = nNumBitsRead + 8;
3820 nOutput = nOutput >> (32 - nBits) ;
3823 /* ==========================================================================*/
3824 /* func WMADEC_Parser */
3826 /* desc Parses the WAVEFORMATEX data structure that is sent in the 1st */
3827 /* buffer and the it creates the RCA header and the block align */
3828 /* ==========================================================================*/
3829 OMX_ERRORTYPE WMADEC_Parser(OMX_U8* pBuffer, RCA_HEADER *pStreamData, struct OMX_TI_Debug dbg)
3831 OMX_ERRORTYPE eError=0;
3832 OMX_PRINT1 (dbg, "Entering WMADEC_Parser function");
3834 //These are the important fields that the socket node needs
3835 pStreamData->iTypeSpecific=0x1c;
3836 pStreamData->iFormatTag= *((OMX_U16*)(pBuffer));
3837 pStreamData->iChannel=*((OMX_U16 *)(pBuffer+2));
3838 pStreamData->iSamplePerSec=*((OMX_U32 *)(pBuffer+4));
3839 pStreamData->iAvgBytesPerSec=*((OMX_U32 *)(pBuffer+8)); //check
3840 pStreamData->iBlockAlign=*((OMX_U16 *)(pBuffer+2+4+4+2));
3841 pStreamData->iValidBitsPerSample=*((OMX_U16 *)(pBuffer+2+4+4+2+2));
3842 pStreamData->iEncodeOptV=*((OMX_U16 *)(pBuffer+2+4+4+2+2+2+2+2+2));
3843 pStreamData->iMaxPacketSize=pStreamData->iBlockAlign+31;
3845 /*After this, the buffer has extra info, the Codc Specific Data Size which has 16 bites of length (2 bytes), and the Codec Specific Data of vari*/
3846 //Parsing information ended.
3848 switch (pStreamData->iFormatTag)
3851 case WAVE_FORMAT_MSAUDIO :
3853 OMX_PRINT2 (dbg, "WAVE_FORMAT_MSAUDIO");
3855 /*Make Necessary validations for supported parameter for specific format here */
3857 case WAVE_FORMAT_MSAUDIO_9 :
3859 OMX_PRINT2 (dbg, "WAVE_FORMAT_MSAUDIO_9");
3861 /*Make Necessary validations for supported parameter for specific format here */
3863 case WAVE_FORMAT_MSAUDIO_9_LOOSELESS :
3865 OMX_PRINT2 (dbg, "WAVE_FORMAT_MSAUDIO_9_LOOSELESS");
3867 /*Make Necessary validations for supported parameter for specific format here */
3875 OMX_PRINT1 (dbg, "Exiting WMADEC_Parser function");
3879 /* =========================================================================*/
3880 /* func WMADEC_HandleUSNError */
3882 /* desc Handles error messages returned by the dsp */
3886 /* =========================================================================*/
3887 void WMADEC_HandleUSNError (WMADEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
3889 OMX_COMPONENTTYPE *pHandle = NULL;
3890 OMX_U8 pending_buffers = OMX_FALSE;
3894 case IUALG_WARN_CONCEALED:
3895 case IUALG_WARN_UNDERFLOW:
3896 case IUALG_WARN_OVERFLOW:
3897 case IUALG_WARN_ENDOFDATA:
3898 OMX_ERROR4(pComponentPrivate->dbg, "Algorithm Error" );
3899 /* all of these are informative messages, Algo can recover, no need to notify the
3900 * IL Client at this stage of the implementation */
3903 case IUALG_WARN_PLAYCOMPLETED:
3905 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n", __LINE__);
3906 pComponentPrivate->pOutputBufferList->EosFlagSent = 1;
3907 pComponentPrivate->cbInfo.EventHandler(
3908 pComponentPrivate->pHandle,
3909 pComponentPrivate->pHandle->pApplicationPrivate,
3910 OMX_EventBufferFlag,
3912 OMX_BUFFERFLAG_EOS, (OMX_PTR)OMX_BUFFERFLAG_EOS);
3916 #ifdef _ERROR_PROPAGATION__
3917 case IUALG_ERR_BAD_HANDLE:
3918 case IUALG_ERR_DATA_CORRUPT:
3919 case IUALG_ERR_NOT_SUPPORTED:
3920 case IUALG_ERR_ARGUMENT:
3921 case IUALG_ERR_NOT_READY:
3922 case IUALG_ERR_GENERAL:
3925 /* all of these are fatal messages, Algo can not recover
3926 * hence return an error */
3927 OMX_ERROR4(pComponentPrivate->dbg, "Algorithm Error, cannot recover" );
3928 pComponentPrivate->bIsInvalidState=OMX_TRUE;
3929 pComponentPrivate->curState = OMX_StateInvalid;
3930 pHandle = pComponentPrivate->pHandle;
3931 pComponentPrivate->cbInfo.EventHandler(pHandle,
3932 pHandle->pApplicationPrivate,
3934 OMX_ErrorInvalidState,
3946 #ifdef RESOURCE_MANAGER_ENABLED
3947 void WMAD_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
3949 OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
3950 OMX_STATETYPE state = OMX_StateIdle;
3951 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
3952 WMADEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
3954 pCompPrivate = (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
3956 if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
3957 if (pCompPrivate->curState == OMX_StateExecuting ||
3958 pCompPrivate->curState == OMX_StatePause) {
3959 write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
3960 write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
3962 pCompPrivate->bPreempted = 1;
3965 else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
3966 pCompPrivate->cbInfo.EventHandler (
3967 pHandle, pHandle->pApplicationPrivate,
3968 OMX_EventResourcesAcquired, 0,0,