1 2/* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21/* ============================================================================= 22 * Texas Instruments OMAP (TM) Platform Software 23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved. 24 * 25 * Use of this software is controlled by the terms and conditions found 26 * in the license agreement under which this software has been supplied. 27 * =========================================================================== */ 28/** 29 * @file OMX_Mp3Dec_Utils.c 30 * 31 * This file implements various utilitiy functions for various activities 32 * like handling command from application, callback from LCML etc. 33 * 34 * @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\mp3_dec\src 35 * 36 * @rev 1.0 37 */ 38/* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! 21-sept-2006 bk: updated some review findings for alpha release 43 *! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more 44 *! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases 45 *! This is newest file 46 * =========================================================================== */ 47/* ------compilation control switches -------------------------*/ 48/**************************************************************** 49 * INCLUDE FILES 50 ****************************************************************/ 51/* ----- system and platform files ----------------------------*/ 52 53 54 55#ifdef UNDER_CE 56#include <windows.h> 57#include <oaf_osal.h> 58#include <omx_core.h> 59#include <stdlib.h> 60#else 61#include <wchar.h> 62#include <unistd.h> 63#include <sys/types.h> 64#include <sys/wait.h> 65#include <sys/types.h> 66#include <sys/stat.h> 67#include <dlfcn.h> 68#include <malloc.h> 69#include <memory.h> 70#include <fcntl.h> 71#endif 72 73#include <dbapi.h> 74#include <string.h> 75#include <stdio.h> 76#include <pthread.h> 77 78/*------- Program Header Files -----------------------------------------------*/ 79#include "LCML_DspCodec.h" 80#include "OMX_Mp3Dec_Utils.h" 81#include "mp3decsocket_ti.h" 82#include <decode_common_ti.h> 83#include "usn.h" 84 85#ifdef RESOURCE_MANAGER_ENABLED 86#include <ResourceManagerProxyAPI.h> 87#endif 88 89#ifdef UNDER_CE 90#define HASHINGENABLE 1 91HINSTANCE g_hLcmlDllHandle = NULL; 92void sleep(DWORD Duration) 93{ 94 Sleep(Duration); 95 96} 97#endif 98 99/* ================================================================================= * */ 100/** 101 * @fn MP3DEC_Fill_LCMLInitParams() fills the LCML initialization structure. 102 * 103 * @param pHandle This is component handle allocated by the OMX core. 104 * 105 * @param plcml_Init This structure is filled and sent to LCML. 106 * 107 * @pre None 108 * 109 * @post None 110 * 111 * @return OMX_ErrorNone = Successful Inirialization of the LCML struct. 112 * OMX_ErrorInsufficientResources = Not enough memory 113 * 114 * @see None 115 */ 116/* ================================================================================ * */ 117OMX_ERRORTYPE MP3DEC_Fill_LCMLInitParams(OMX_HANDLETYPE pComponent,LCML_DSP *plcml_Init,OMX_U16 arr[]) 118{ 119 OMX_ERRORTYPE eError = OMX_ErrorNone; 120 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize; 121 OMX_U32 i; 122 OMX_BUFFERHEADERTYPE *pTemp = NULL; 123 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 124 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate =(MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 125 MP3D_LCML_BUFHEADERTYPE *pTemp_lcml; 126 OMX_U32 size_lcml; 127 OMX_U8 *ptr; 128 129 pComponentPrivate->nRuntimeInputBuffers = 0; 130 pComponentPrivate->nRuntimeOutputBuffers = 0; 131 132 OMX_PRINT1(pComponentPrivate->dbg, "Entered MP3DEC_Fill_LCMLInitParams\n"); 133 OMX_PRCOMM2(pComponentPrivate->dbg, ":::pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated = %d\n", 134 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated); 135 OMX_PRCOMM2(pComponentPrivate->dbg, ":::pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = %d\n", 136 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled); 137 OMX_PRCOMM2(pComponentPrivate->dbg, ":::pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated = %d\n", 138 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated); 139 OMX_PRCOMM2(pComponentPrivate->dbg, ":::pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = %d\n", 140 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled); 141 142 pComponentPrivate->strmAttr = NULL; 143 144 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 145 pComponentPrivate->nRuntimeInputBuffers = nIpBuf; 146 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 147 pComponentPrivate->nRuntimeOutputBuffers = nOpBuf; 148 nIpBufSize = pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nBufferSize; 149 nOpBufSize = pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nBufferSize; 150 151 152 OMX_PRBUFFER2(pComponentPrivate->dbg, "Input Buffer Count = %ld\n",nIpBuf); 153 OMX_PRBUFFER2(pComponentPrivate->dbg, "Input Buffer Size = %ld\n",nIpBufSize); 154 OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Count = %ld\n",nOpBuf); 155 OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Size = %ld\n",nOpBufSize); 156 157 plcml_Init->In_BufInfo.nBuffers = nIpBuf; 158 plcml_Init->In_BufInfo.nSize = nIpBufSize; 159 plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD; 160 plcml_Init->Out_BufInfo.nBuffers = nOpBuf; 161 plcml_Init->Out_BufInfo.nSize = nOpBufSize; 162 plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD; 163 164 165 plcml_Init->NodeInfo.nNumOfDLLs = 3; 166 167 memset(plcml_Init->NodeInfo.AllUUIDs[0].DllName,0, sizeof(plcml_Init->NodeInfo.AllUUIDs[0].DllName)); 168 memset(plcml_Init->NodeInfo.AllUUIDs[1].DllName,0, sizeof(plcml_Init->NodeInfo.AllUUIDs[1].DllName)); 169 memset(plcml_Init->NodeInfo.AllUUIDs[2].DllName,0, sizeof(plcml_Init->NodeInfo.AllUUIDs[1].DllName)); 170 memset(plcml_Init->NodeInfo.AllUUIDs[0].DllName,0, sizeof(plcml_Init->DeviceInfo.AllUUIDs[1].DllName)); 171 172 plcml_Init->NodeInfo.AllUUIDs[0].uuid = &MP3DECSOCKET_TI_UUID; 173 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName, MP3DEC_DLL_NAME); 174 plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 175 176 plcml_Init->NodeInfo.AllUUIDs[1].uuid = &MP3DECSOCKET_TI_UUID; 177 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName, MP3DEC_DLL_NAME); 178 plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 179 180 plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID; 181 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName, MP3DEC_USN_DLL_NAME); 182 plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 183 184 plcml_Init->SegID = OMX_MP3DEC_DEFAULT_SEGMENT; 185 plcml_Init->Timeout = OMX_MP3DEC_SN_TIMEOUT; 186 plcml_Init->Alignment = 0; 187 plcml_Init->Priority = OMX_MP3DEC_SN_PRIORITY; 188 plcml_Init->ProfileID = -1; 189 190 if(pComponentPrivate->dasfmode == 1) { 191#ifndef DSP_RENDERING_ON 192 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources, 193 "Flag DSP_RENDERING_ON Must Be Defined To Use Rendering"); 194#else 195 LCML_STRMATTR *strmAttr; 196 OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR); 197 OMX_PRBUFFER2(pComponentPrivate->dbg, ": Malloc strmAttr = %p\n",strmAttr); 198 pComponentPrivate->strmAttr = strmAttr; 199 OMX_PRDSP2(pComponentPrivate->dbg, ":: MP3 DECODER IS RUNNING UNDER DASF MODE \n"); 200 201 strmAttr->uSegid = 0; 202 strmAttr->uAlignment = 0; 203 strmAttr->uTimeout = -1; 204 205 strmAttr->uBufsize = MP3D_OUTPUT_BUFFER_SIZE; 206 207 OMX_PRBUFFER2(pComponentPrivate->dbg, "::strmAttr->uBufsize:%d\n",strmAttr->uBufsize); 208 209 strmAttr->uNumBufs = 2; 210 strmAttr->lMode = STRMMODE_PROCCOPY; 211 plcml_Init->DeviceInfo.TypeofDevice = 1; 212 plcml_Init->DeviceInfo.TypeofRender = 0; 213 214 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID; 215 plcml_Init->DeviceInfo.DspStream = strmAttr; 216#endif 217 } else { 218 plcml_Init->DeviceInfo.TypeofDevice = 0; 219 } 220 221 if (pComponentPrivate->dasfmode == 0){ 222 OMX_PRDSP2(pComponentPrivate->dbg, ":: FILE MODE CREATE PHASE PARAMETERS\n"); 223 arr[0] = 2; /* Number of Streams */ 224 arr[1] = 0; /* ID of the Input Stream */ 225 arr[2] = 0; /* Type of Input Stream DMM (0) / STRM (1) */ 226#ifndef UNDER_CE 227 arr[3] = 4; /* Number of buffers for Input Stream */ 228#else 229 arr[3] = 1; /* WinCE Number of buffers for Input Stream */ 230#endif 231 arr[4] = 1; /* ID of the Output Stream */ 232 arr[5] = 0; /* Type of Output Stream */ 233#ifndef UNDER_CE 234 arr[6] = 4; /* Number of buffers for Output Stream */ 235#else 236 arr[6] = 1; /* WinCE Number of buffers for Output Stream */ 237#endif 238 239 if(pComponentPrivate->pcmParams->nBitPerSample == 24){ 240 OMX_PRCOMM2(pComponentPrivate->dbg, " PCM 24 bit output\n"); 241 arr[7] = 24; 242 } else { 243 OMX_PRCOMM2(pComponentPrivate->dbg, " PCM 16 bit output\n"); 244 arr[7] = 16; 245 } 246 247 if(pComponentPrivate->frameMode) { 248 OMX_PRMGR2(pComponentPrivate->dbg, " frame mode is on\n"); 249 arr[8] = 1; /* frame mode is on */ 250 } else { 251 arr[8] = 0; 252 OMX_PRMGR2(pComponentPrivate->dbg, " frame mode is off\n"); 253 } 254 arr[9] = END_OF_CR_PHASE_ARGS; 255 } else { 256 OMX_PRDSP2(pComponentPrivate->dbg, ":: DASF MODE CREATE PHASE PARAMETERS\n"); 257 arr[0] = 2; /* Number of Streams */ 258 arr[1] = 0; /* ID of the Input Stream */ 259 arr[2] = 0; /* Type of Input Stream DMM (0) / STRM (1) */ 260 arr[3] = 4; /* Number of buffers for Input Stream */ 261 arr[4] = 1; /* ID of the Output Stream */ 262 arr[5] = 2; /* Type of Output Stream */ 263 arr[6] = 2; /* Number of buffers for Output Stream */ 264 arr[7] = 16; /*Decoder Output PCM width is 24-bit or 16-bit */ 265 arr[8] = 0; /* frame mode off */ 266 267 arr[9] = END_OF_CR_PHASE_ARGS; 268 } 269 270 plcml_Init->pCrPhArgs = arr; 271 272 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: bufAlloced = %d\n",pComponentPrivate->bufAlloced); 273 size_lcml = nIpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE); 274 OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8); 275 pTemp_lcml = (MP3D_LCML_BUFHEADERTYPE *)ptr; 276 277 pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = pTemp_lcml; 278 279 for (i=0; i<nIpBuf; i++) { 280 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 281 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 282 283 pTemp->nAllocLen = nIpBufSize; 284 pTemp->nFilledLen = nIpBufSize; 285 pTemp->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER; 286 pTemp->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER; 287 288 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 289 pTemp->nTickCount = 0; 290 291 pTemp_lcml->pBufHdr = pTemp; 292 pTemp_lcml->eDir = OMX_DirInput; 293 pTemp_lcml->pOtherParams[i] = NULL; 294 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, 295 sizeof(MP3DEC_UAlgInBufParamStruct), 296 MP3DEC_UAlgInBufParamStruct); 297 pTemp_lcml->pIpParam->bLastBuffer = 0; 298 299 pTemp->nFlags = NORMAL_BUFFER; 300 ((MP3DEC_COMPONENT_PRIVATE *) pTemp->pPlatformPrivate)->pHandle = pHandle; 301 302 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: InBuffHeader[%ld] = %p\n", i, pTemp); 303 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>> InputBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer); 304 OMX_PRDSP2(pComponentPrivate->dbg, "::Comp: Ip : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml); 305 306 pTemp_lcml++; 307 } 308 309 size_lcml = nOpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE); 310 OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE); 311 pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = pTemp_lcml; 312 313 for (i=0; i<nOpBuf; i++) { 314 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 315 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 316 317 pTemp->nAllocLen = nOpBufSize; 318 319 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: nOpBufSize = %ld\n", nOpBufSize); 320 321 pTemp->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER; 322 pTemp->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER; 323 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 324 pTemp->nTickCount = 0; 325 326 pTemp_lcml->pBufHdr = pTemp; 327 pTemp_lcml->eDir = OMX_DirOutput; 328 pTemp_lcml->pOtherParams[i] = NULL; 329 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, 330 sizeof(MP3DEC_UAlgOutBufParamStruct), 331 MP3DEC_UAlgOutBufParamStruct); 332 pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE; 333 pTemp_lcml->pOpParam->ulIsLastBuffer = 0; 334 335 pTemp->nFlags = NORMAL_BUFFER; 336 ((MP3DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle; 337 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>>>>>>>>>>> OutBuffHeader[%ld] = %p\n", i, pTemp); 338 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>> OutBuffHeader[%ld]->pBuffer = %p\n", i, pTemp->pBuffer); 339 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: Op : pTemp_lcml[%ld] = %p\n", i, pTemp_lcml); 340 pTemp_lcml++; 341 } 342 pComponentPrivate->bPortDefsAllocated = 1; 343 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof(USN_AudioCodecParams), 344 USN_AudioCodecParams); 345 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->ptAlgDynParams,sizeof(MP3DEC_UALGParams), 346 MP3DEC_UALGParams); 347 348#ifdef __PERF_INSTRUMENTATION__ 349 pComponentPrivate->nLcml_nCntIp = 0; 350 pComponentPrivate->nLcml_nCntOpReceived = 0; 351#endif 352 353 pComponentPrivate->bInitParamsInitialized = 1; 354 355 EXIT: 356 OMX_PRINT1(pComponentPrivate->dbg, "Exiting MP3DEC_Fill_LCMLInitParams. error=%d\n", eError); 357 358 return eError; 359} 360 361 362/* ================================================================================= * */ 363/** 364 * @fn Mp3Dec_StartCompThread() starts the component thread. This is internal 365 * function of the component. 366 * 367 * @param pHandle This is component handle allocated by the OMX core. 368 * 369 * @pre None 370 * 371 * @post None 372 * 373 * @return OMX_ErrorNone = Successful Inirialization of the component\n 374 * OMX_ErrorInsufficientResources = Not enough memory 375 * 376 * @see None 377 */ 378/* ================================================================================ * */ 379OMX_ERRORTYPE Mp3Dec_StartCompThread(OMX_HANDLETYPE pComponent) 380{ 381 OMX_ERRORTYPE eError = OMX_ErrorNone; 382 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 383 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = 384 (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 385 int nRet = 0; 386 387#ifdef UNDER_CE 388 pthread_attr_t attr; 389 memset(&attr, 0, sizeof(attr)); 390 attr.__inheritsched = PTHREAD_EXPLICIT_SCHED; 391 attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY; 392#endif 393 394 OMX_PRINT1(pComponentPrivate->dbg, ":: Enetering Mp3Dec_StartCompThread()\n"); 395 396 pComponentPrivate->lcml_nOpBuf = 0; 397 pComponentPrivate->lcml_nIpBuf = 0; 398 pComponentPrivate->app_nBuf = 0; 399 pComponentPrivate->num_Op_Issued = 0; 400 pComponentPrivate->num_Sent_Ip_Buff = 0; 401 pComponentPrivate->num_Reclaimed_Op_Buff = 0; 402 pComponentPrivate->bIsEOFSent = 0; 403 404 nRet = pipe (pComponentPrivate->dataPipe); 405 if (0 != nRet) { 406 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources, 407 "Pipe Creation Failed"); 408 } 409 410 nRet = pipe (pComponentPrivate->cmdPipe); 411 if (0 != nRet) { 412 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources, 413 "Pipe Creation Failed"); 414 } 415 416 nRet = pipe (pComponentPrivate->cmdDataPipe); 417 if (0 != nRet) { 418 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources, 419 "Pipe Creation Failed"); 420 } 421 422 423#ifdef UNDER_CE 424 nRet = pthread_create (&(pComponentPrivate->ComponentThread), &attr, 425 MP3DEC_ComponentThread, pComponentPrivate); 426#else 427 nRet = pthread_create (&(pComponentPrivate->ComponentThread), NULL, 428 MP3DEC_ComponentThread, pComponentPrivate); 429#endif 430 if ((0 != nRet) || (!pComponentPrivate->ComponentThread)) { 431 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorInsufficientResources, 432 "Thread Creation Failed"); 433 } 434 435 pComponentPrivate->bCompThreadStarted = 1; 436 437 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting from Mp3Dec_StartCompThread()\n"); 438 439 EXIT: 440 return eError; 441} 442 443 444/* ================================================================================= * */ 445/** 446 * @fn MP3DEC_FreeCompResources() function newfrees the component resources. 447 * 448 * @param pComponent This is the component handle. 449 * 450 * @pre None 451 * 452 * @post None 453 * 454 * @return OMX_ErrorNone = Successful Inirialization of the component\n 455 * OMX_ErrorHardware = Hardware error has occured. 456 * 457 * @see None 458 */ 459/* ================================================================================ * */ 460 461OMX_ERRORTYPE MP3DEC_FreeCompResources(OMX_HANDLETYPE pComponent) 462{ 463 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 464 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *) 465 pHandle->pComponentPrivate; 466 OMX_ERRORTYPE eError = OMX_ErrorNone; 467 OMX_U32 nIpBuf=0, nOpBuf=0; 468 int nRet=0; 469 470 OMX_PRINT1(pComponentPrivate->dbg, ":: Mp3Dec_FreeCompResources\n"); 471 472 OMX_PRBUFFER2(pComponentPrivate->dbg, ":::pComponentPrivate->bPortDefsAllocated = %ld\n",pComponentPrivate->bPortDefsAllocated); 473 if (pComponentPrivate->bPortDefsAllocated) { 474 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 475 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 476 } 477 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Closing pipess.....\n"); 478 479 nRet = close (pComponentPrivate->dataPipe[0]); 480 if (0 != nRet && OMX_ErrorNone == eError) { 481 eError = OMX_ErrorHardware; 482 } 483 484 nRet = close (pComponentPrivate->dataPipe[1]); 485 if (0 != nRet && OMX_ErrorNone == eError) { 486 eError = OMX_ErrorHardware; 487 } 488 489 nRet = close (pComponentPrivate->cmdPipe[0]); 490 if (0 != nRet && OMX_ErrorNone == eError) { 491 eError = OMX_ErrorHardware; 492 } 493 494 nRet = close (pComponentPrivate->cmdPipe[1]); 495 if (0 != nRet && OMX_ErrorNone == eError) { 496 eError = OMX_ErrorHardware; 497 } 498 499 nRet = close (pComponentPrivate->cmdDataPipe[0]); 500 if (0 != nRet && OMX_ErrorNone == eError) { 501 eError = OMX_ErrorHardware; 502 } 503 504 nRet = close (pComponentPrivate->cmdDataPipe[1]); 505 506 507 if (0 != nRet && OMX_ErrorNone == eError) { 508 eError = OMX_ErrorHardware; 509 } 510 511 if (pComponentPrivate->bPortDefsAllocated) { 512 513 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]); 514 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]); 515 OMX_MEMFREE_STRUCT(pComponentPrivate->mp3Params); 516 OMX_MEMFREE_STRUCT (pComponentPrivate->pcmParams); 517 OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat); 518 OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat); 519 OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_INPUT_PORT]); 520 OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]); 521 OMX_MEMFREE_STRUCT (pComponentPrivate->sPortParam); 522 OMX_MEMFREE_STRUCT (pComponentPrivate->pPriorityMgmt); 523 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList); 524 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 525 } 526 527 pComponentPrivate->bPortDefsAllocated = 0; 528 529#ifndef UNDER_CE 530 OMX_PRDSP2(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n\n"); 531 pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex); 532 pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold); 533 534 pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex); 535 pthread_cond_destroy(&pComponentPrivate->InIdle_threshold); 536 537 pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex); 538 pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold); 539 540 pthread_mutex_destroy(&pComponentPrivate->codecStop_mutex); 541 pthread_cond_destroy(&pComponentPrivate->codecStop_threshold); 542 543 pthread_mutex_destroy(&pComponentPrivate->codecFlush_mutex); 544 pthread_cond_destroy(&pComponentPrivate->codecFlush_threshold); 545#else 546 OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event)); 547 OMX_DestroyEvent(&(pComponentPrivate->InIdle_event)); 548 OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event)); 549#endif 550 551 return eError; 552} 553 554static void signalAlloBufThresholdIfNecessary( 555 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) { 556#ifndef UNDER_CE 557 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 558 if (pComponentPrivate->AlloBuf_waitingsignal) { 559 pComponentPrivate->AlloBuf_waitingsignal = 0; 560 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); 561 } 562 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 563#else 564 if (pComponentPrivate->AlloBuf_waitingsignal) { 565 // I am fairly sure this will suffer from similar issues without 566 // proper mutex protection and a loop under WinCE... 567 pComponentPrivate->AlloBuf_waitingsignal = 0; 568 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); 569 } 570#endif 571} 572 573 574/* ================================================================================= * */ 575/** 576 * @fn MP3DEC_HandleCommand() function handles the command sent by the application. 577 * All the state transitions, except from nothing to loaded state, of the 578 * component are done by this function. 579 * 580 * @param pComponentPrivate This is component's private date structure. 581 * 582 * @pre None 583 * 584 * @post None 585 * 586 * @return OMX_ErrorNone = Successful processing. 587 * OMX_ErrorInsufficientResources = Not enough memory 588 * OMX_ErrorHardware = Hardware error has occured lile LCML failed 589 * to do any said operartion. 590 * 591 * @see None 592 */ 593/* ================================================================================ * */ 594 595OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 596{ 597 OMX_U32 i,ret = 0; 598 OMX_U16 arr[24]; 599 OMX_ERRORTYPE eError = OMX_ErrorNone; 600 char *pArgs = "damedesuStr"; 601 OMX_U32 pValues[4]; 602 OMX_U32 pValues1[4]; 603 OMX_COMPONENTTYPE *pHandle =(OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 604 OMX_COMMANDTYPE command; 605 OMX_STATETYPE commandedState; 606 OMX_U32 commandData; 607 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle; 608 609#ifdef RESOURCE_MANAGER_ENABLED 610 OMX_ERRORTYPE rm_error = OMX_ErrorNone; 611#endif 612 613 OMX_PRINT1(pComponentPrivate->dbg, ":: >>> Entering HandleCommand Function\n"); 614 615 ret = read(pComponentPrivate->cmdPipe[0], &command, sizeof (command)); 616 if(ret == -1){ 617 MP3D_OMX_ERROR_EXIT(eError, 618 OMX_ErrorHardware, 619 "Error while reading the command pipe"); 620 pComponentPrivate->cbInfo.EventHandler (pHandle, 621 pHandle->pApplicationPrivate, 622 OMX_EventError, 623 eError, 624 OMX_TI_ErrorSevere, 625 NULL); 626 } 627 ret = read(pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData)); 628 if(ret == -1){ 629 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorHardware, 630 "Error while reading the commandData pipe"); 631 pComponentPrivate->cbInfo.EventHandler (pHandle, 632 pHandle->pApplicationPrivate, 633 OMX_EventError, 634 eError, 635 OMX_TI_ErrorSevere, 636 NULL); 637 } 638 OMX_PRDSP2(pComponentPrivate->dbg, "---------------------------------------------\n"); 639 OMX_PRDSP2(pComponentPrivate->dbg, ":: command = %d\n",command); 640 OMX_PRDSP2(pComponentPrivate->dbg, ":: commandData = %ld\n",commandData); 641 OMX_PRDSP2(pComponentPrivate->dbg, "---------------------------------------------\n"); 642#ifdef __PERF_INSTRUMENTATION__ 643 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp, 644 command, 645 commandData, 646 PERF_ModuleLLMM); 647#endif 648 if (command == OMX_CommandStateSet){ 649 commandedState = (OMX_STATETYPE)commandData; 650 if (pComponentPrivate->curState == commandedState) { 651 pComponentPrivate->cbInfo.EventHandler (pHandle, 652 pHandle->pApplicationPrivate, 653 OMX_EventError, 654 OMX_ErrorSameState, 655 OMX_TI_ErrorMinor, 656 NULL); 657 658 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Same State Given by Application\n"); 659 } else { 660 661 switch(commandedState) { 662 663 case OMX_StateIdle: 664 OMX_PRINT1(pComponentPrivate->dbg, ": HandleCommand: Cmd Idle \n"); 665 if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->curState == OMX_StateWaitForResources) { 666 LCML_CALLBACKTYPE cb; 667 LCML_DSP *pLcmlDsp; 668 char *p = "damedesuStr"; 669#ifdef __PERF_INSTRUMENTATION__ 670 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup); 671#endif 672 int inputPortFlag=0,outputPortFlag=0; 673 674 if (pComponentPrivate->dasfmode == 1) { 675 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled= FALSE; 676 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated= FALSE; 677 if(pComponentPrivate->streamID == 0) { 678 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n"); 679 OMX_ERROR4(pComponentPrivate->dbg, ":: Error = OMX_ErrorInsufficientResources\n"); 680 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n"); 681 pComponentPrivate->curState = OMX_StateInvalid; 682 eError = OMX_ErrorInsufficientResources; 683 pComponentPrivate->cbInfo.EventHandler(pHandle, 684 pHandle->pApplicationPrivate, 685 OMX_EventError, 686 eError, 687 OMX_TI_ErrorMajor, 688 "AM: No Stream ID Available"); 689 goto EXIT; 690 } 691 } 692 693 694 OMX_PRINT2(pComponentPrivate->dbg, "In while loop: IP : %p OP: %p\n",pComponentPrivate->pPortDef[MP3D_INPUT_PORT], 695 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]); 696 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated = %d\n", 697 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated); 698 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated = %d\n", 699 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated); 700 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = %d\n", 701 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled); 702 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = %d\n", 703 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled); 704 705 706 if (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated && 707 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) { 708 inputPortFlag = 1; 709 } 710 711 if (!pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated && 712 !pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled) { 713 inputPortFlag = 1; 714 } 715 716 if (pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated && 717 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled) { 718 outputPortFlag = 1; 719 } 720 721 if (!pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated && 722 !pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled) { 723 outputPortFlag = 1; 724 } 725 726 if(!(inputPortFlag && outputPortFlag)) { 727 pComponentPrivate->InLoaded_readytoidle = 1; 728#ifndef UNDER_CE 729 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 730 pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex); 731 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 732#else 733 OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event)); 734#endif 735 } 736 737 pLcmlHandle = (OMX_HANDLETYPE) MP3DEC_GetLCMLHandle(pComponentPrivate); 738 if (pLcmlHandle == NULL) { 739 OMX_ERROR4(pComponentPrivate->dbg, ":: LCML Handle is NULL........exiting..\n"); 740 pComponentPrivate->curState = OMX_StateInvalid; 741 eError = OMX_ErrorHardware; 742 pComponentPrivate->cbInfo.EventHandler(pHandle, 743 pHandle->pApplicationPrivate, 744 OMX_EventError, 745 OMX_ErrorHardware, 746 OMX_TI_ErrorSevere, 747 "Lcml Handle NULL"); 748 goto EXIT; 749 } 750 751 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 752 eError = MP3DEC_Fill_LCMLInitParams(pHandle, pLcmlDsp,arr); 753 if(eError != OMX_ErrorNone) { 754 OMX_ERROR4(pComponentPrivate->dbg, ":: Error returned from Fill_LCMLInitParams()\n"); 755 pComponentPrivate->curState = OMX_StateInvalid; 756 pComponentPrivate->cbInfo.EventHandler(pHandle, 757 pHandle->pApplicationPrivate, 758 OMX_EventError, 759 eError, 760 OMX_TI_ErrorSevere, 761 NULL); 762 goto EXIT; 763 } 764 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle; 765 cb.LCML_Callback = (void *) MP3DEC_LCML_Callback; 766 767#ifndef UNDER_CE 768 eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle, 769 p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString); 770 if (eError != OMX_ErrorNone){ 771 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__); 772 /* send an event to client */ 773 /* client should unload the component if the codec is not able to load */ 774 pComponentPrivate->cbInfo.EventHandler (pHandle, 775 pHandle->pApplicationPrivate, 776 OMX_EventError, 777 eError, 778 OMX_TI_ErrorSevere, 779 NULL); 780 goto EXIT; 781 } 782#else 783 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle, 784 p,&pLcmlHandle,(void *)p,&cb); 785 if (eError != OMX_ErrorNone){ 786 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__); 787 goto EXIT; 788 } 789 790#endif 791#ifdef HASHINGENABLE 792 /* Enable the Hashing Code */ 793 eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, OMX_TRUE); 794 if (eError != OMX_ErrorNone) { 795 OMX_ERROR4(pComponentPrivate->dbg, "Failed to set Mapping State\n"); 796 goto EXIT; 797 } 798#endif 799 800#ifdef RESOURCE_MANAGER_ENABLED 801 /* Need check the resource with RM */ 802 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = 803 (void *) MP3_ResourceManagerCallback; 804 if (pComponentPrivate->curState != OMX_StateWaitForResources){ 805 rm_error = RMProxy_NewSendCommand(pHandle, 806 RMProxy_RequestResource, 807 OMX_MP3_Decoder_COMPONENT, 808 MP3_CPU, 809 3456, 810 &(pComponentPrivate->rmproxyCallback)); 811 if(rm_error == OMX_ErrorNone) { 812 /* resource is available */ 813#ifdef __PERF_INSTRUMENTATION__ 814 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup); 815#endif 816 pComponentPrivate->curState = OMX_StateIdle; 817 rm_error = RMProxy_NewSendCommand(pHandle, 818 RMProxy_StateSet, 819 OMX_MP3_Decoder_COMPONENT, 820 OMX_StateIdle, 821 3456, 822 NULL); 823 pComponentPrivate->cbInfo.EventHandler(pHandle, 824 pHandle->pApplicationPrivate, 825 OMX_EventCmdComplete, 826 OMX_CommandStateSet, 827 pComponentPrivate->curState, 828 NULL); 829 } 830 else if(rm_error == OMX_ErrorInsufficientResources) { 831 /* resource is not available, need set state to 832 OMX_StateWaitForResources */ 833 pComponentPrivate->curState = OMX_StateWaitForResources; 834 pComponentPrivate->cbInfo.EventHandler(pHandle, 835 pHandle->pApplicationPrivate, 836 OMX_EventCmdComplete, 837 OMX_CommandStateSet, 838 pComponentPrivate->curState, 839 NULL); 840 } 841 }else{ 842 rm_error = RMProxy_NewSendCommand(pHandle, 843 RMProxy_StateSet, 844 OMX_MP3_Decoder_COMPONENT, 845 OMX_StateIdle, 846 3456, 847 NULL); 848 849 pComponentPrivate->curState = OMX_StateIdle; 850 pComponentPrivate->cbInfo.EventHandler(pHandle, 851 pHandle->pApplicationPrivate, 852 OMX_EventCmdComplete, 853 OMX_CommandStateSet, 854 pComponentPrivate->curState, 855 NULL); 856 } 857 858#else 859#ifdef __PERF_INSTRUMENTATION__ 860 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup); 861#endif 862 pComponentPrivate->curState = OMX_StateIdle; 863 pComponentPrivate->cbInfo.EventHandler(pHandle, 864 pHandle->pApplicationPrivate, 865 OMX_EventCmdComplete, 866 OMX_CommandStateSet, 867 pComponentPrivate->curState, 868 NULL); 869#endif 870 871 OMX_PRDSP2(pComponentPrivate->dbg, ":: Control Came Here\n"); 872 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Idle\n\n"); 873 OMX_PRSTATE2(pComponentPrivate->dbg, "MP3DEC: State has been Set to Idle\n"); 874 } else if (pComponentPrivate->curState == OMX_StateExecuting){ 875#ifdef __PERF_INSTRUMENTATION__ 876 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 877#endif 878 pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE; 879 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec STOP %d\n", __LINE__); 880 if (pComponentPrivate->codecStop_waitingsignal == 0){ 881 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex); 882 } 883 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 884 MMCodecControlStop,(void *)pArgs); 885 if (pComponentPrivate->codecStop_waitingsignal == 0){ 886 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex); 887 pComponentPrivate->codecStop_waitingsignal = 0; 888 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex); 889 } 890 891 892 if(eError != OMX_ErrorNone) { 893 OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in Codec Stop..\n"); 894 pComponentPrivate->curState = OMX_StateInvalid; 895 pComponentPrivate->cbInfo.EventHandler(pHandle, 896 pHandle->pApplicationPrivate, 897 OMX_EventError, 898 eError, 899 OMX_TI_ErrorSevere, 900 NULL); 901 goto EXIT; 902 } 903#ifdef HASHINGENABLE 904 /*Hashing Change*/ 905 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle; 906 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle); 907 if (eError != OMX_ErrorNone) { 908 OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n"); 909 break; 910 } 911#endif 912 } else if(pComponentPrivate->curState == OMX_StatePause) { 913 char *pArgs = "damedesuStr"; 914 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Comp: Stop Command Received\n"); 915#ifdef HASHINGENABLE 916 /*Hashing Change*/ 917 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle; 918 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle); 919 if (eError != OMX_ErrorNone) { 920 OMX_ERROR4(pComponentPrivate->dbg, "Error occurred in Codec mapping flush!\n"); 921 break; 922 } 923#endif 924#ifdef __PERF_INSTRUMENTATION__ 925 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 926#endif 927 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec %d\n", __LINE__); 928 if (pComponentPrivate->codecStop_waitingsignal == 0){ 929 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex); 930 } 931 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 932 MMCodecControlStop,(void *)pArgs); 933 // lock mutex here, wait for stop ack. from lcml 934 if (pComponentPrivate->codecStop_waitingsignal == 0){ 935 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex); 936 pComponentPrivate->codecStop_waitingsignal = 0; // reset the wait condition for next time 937 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex); 938 } 939 if(eError != OMX_ErrorNone) { 940 OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in Codec Stop..\n"); 941 pComponentPrivate->curState = OMX_StateInvalid; 942 pComponentPrivate->cbInfo.EventHandler(pHandle, 943 pHandle->pApplicationPrivate, 944 OMX_EventError, 945 eError, 946 OMX_TI_ErrorSevere, 947 NULL); 948 goto EXIT; 949 } 950 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Idle\n\n"); 951 pComponentPrivate->curState = OMX_StateIdle; 952#ifdef RESOURCE_MANAGER_ENABLED 953 rm_error = RMProxy_NewSendCommand(pHandle, 954 RMProxy_StateSet, 955 OMX_MP3_Decoder_COMPONENT, 956 OMX_StateIdle, 957 3456, 958 NULL); 959#endif 960 OMX_PRDSP2(pComponentPrivate->dbg, ":: The component is stopped\n"); 961 pComponentPrivate->cbInfo.EventHandler(pHandle, 962 pHandle->pApplicationPrivate, 963 OMX_EventCmdComplete, 964 OMX_CommandStateSet, 965 pComponentPrivate->curState, 966 NULL); 967 968 } else { 969 OMX_ERROR2(pComponentPrivate->dbg, ": Comp: Sending ErrorNotification: Invalid State\n"); 970 pComponentPrivate->cbInfo.EventHandler(pHandle, 971 pHandle->pApplicationPrivate, 972 OMX_EventError, 973 OMX_ErrorIncorrectStateTransition, 974 OMX_TI_ErrorMinor, 975 "Invalid State Error"); 976 } 977 break; 978 979 case OMX_StateExecuting: 980 OMX_PRDSP2(pComponentPrivate->dbg, ": HandleCommand: Cmd Executing \n"); 981 if (pComponentPrivate->curState == OMX_StateIdle) { 982 char *pArgs = "damedesuStr"; 983 OMX_U32 pValues[4]; 984 OMX_U32 pValues1[4]; 985 986 if(!pComponentPrivate->SendAfterEOS){ 987 if(pComponentPrivate->dasfmode == 1) { 988 pComponentPrivate->pParams->unAudioFormat = (unsigned short)pComponentPrivate->mp3Params->nChannels; 989 if (pComponentPrivate->pParams->unAudioFormat == MP3D_STEREO_STREAM) { 990 pComponentPrivate->pParams->unAudioFormat = MP3D_STEREO_NONINTERLEAVED_STREAM; 991 } 992 993 pComponentPrivate->pParams->ulSamplingFreq = pComponentPrivate->mp3Params->nSampleRate; 994 pComponentPrivate->pParams->unUUID = pComponentPrivate->streamID; 995 996 OMX_PRCOMM2(pComponentPrivate->dbg, "::pParams->unAudioFormat = %ld\n",pComponentPrivate->mp3Params->nChannels); 997 OMX_PRCOMM2(pComponentPrivate->dbg, "::pParams->ulSamplingFreq = %ld\n",pComponentPrivate->mp3Params->nSampleRate); 998 999 pValues[0] = USN_STRMCMD_SETCODECPARAMS; 1000 pValues[1] = (OMX_U32)pComponentPrivate->pParams; 1001 pValues[2] = sizeof(USN_AudioCodecParams); 1002 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec %d\n", __LINE__); 1003 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1004 EMMCodecControlStrmCtrl,(void *)pValues); 1005 if(eError != OMX_ErrorNone) { 1006 OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in Codec StreamControl..\n"); 1007 pComponentPrivate->curState = OMX_StateInvalid; 1008 pComponentPrivate->cbInfo.EventHandler(pHandle, 1009 pHandle->pApplicationPrivate, 1010 OMX_EventError, 1011 eError, 1012 OMX_TI_ErrorSevere, 1013 NULL); 1014 goto EXIT; 1015 } 1016 } 1017 if(pComponentPrivate->dasfmode == 0 && 1018 pComponentPrivate->pcmParams->bInterleaved) { 1019 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_INTERLEAVED; 1020 } else { 1021 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_BLOCK; 1022 } 1023 1024 pComponentPrivate->ptAlgDynParams->lMonoToStereoCopy = 0; 1025 pComponentPrivate->ptAlgDynParams->lStereoToMonoCopy = 0; 1026 pComponentPrivate->ptAlgDynParams->size = sizeof(MP3DEC_UALGParams); 1027 1028 pValues1[0] = IUALG_CMD_SETSTATUS; 1029 pValues1[1] = (OMX_U32) pComponentPrivate->ptAlgDynParams; 1030 pValues1[2] = sizeof(MP3DEC_UALGParams); 1031 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec %d\n", __LINE__); 1032 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1033 EMMCodecControlAlgCtrl,(void *)pValues1); 1034 if(eError != OMX_ErrorNone) { 1035 OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Set Status DynParams..\n"); 1036 pComponentPrivate->curState = OMX_StateInvalid; 1037 pComponentPrivate->cbInfo.EventHandler(pHandle, 1038 pHandle->pApplicationPrivate, 1039 OMX_EventError, 1040 eError, 1041 OMX_TI_ErrorSevere, 1042 NULL); 1043 goto EXIT; 1044 } 1045 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 1046 OMX_PRDSP2(pComponentPrivate->dbg, ":: Algcontrol has been sent to DSP\n"); 1047 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec START %d\n", __LINE__); 1048 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1049 EMMCodecControlStart,(void *)pArgs); 1050 1051 if(eError != OMX_ErrorNone) { 1052 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Start..\n", __LINE__); 1053 goto EXIT; 1054 } 1055 OMX_PRDSP2(pComponentPrivate->dbg, ": Codec Has Been Started \n"); 1056 1057 pComponentPrivate->SendAfterEOS = 1; 1058 } 1059 } else if (pComponentPrivate->curState == OMX_StatePause) { 1060 char *pArgs = "damedesuStr"; 1061 OMX_PRDSP2(pComponentPrivate->dbg, ": Comp: Resume Command Came from App\n"); 1062 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec\n"); 1063 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec START %d\n", __LINE__); 1064 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 1065 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1066 EMMCodecControlStart,(void *)pArgs); 1067 1068 if (eError != OMX_ErrorNone) { 1069 OMX_ERROR4(pComponentPrivate->dbg, "Error While Resuming the codec\n"); 1070 pComponentPrivate->curState = OMX_StateInvalid; 1071 pComponentPrivate->cbInfo.EventHandler(pHandle, 1072 pHandle->pApplicationPrivate, 1073 OMX_EventError, 1074 eError, 1075 OMX_TI_ErrorSevere, 1076 NULL); 1077 goto EXIT; 1078 } 1079 1080 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1081 if (pComponentPrivate->pInputBufHdrPending[i] != NULL) { 1082 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1083 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1084 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 1085 MP3DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__); 1086 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1087 EMMCodecInputBuffer, 1088 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 1089 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 1090 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 1091 (OMX_U8 *) pLcmlHdr->pIpParam, 1092 sizeof(MP3DEC_UAlgInBufParamStruct), 1093 NULL); 1094 } 1095 } 1096 pComponentPrivate->nNumInputBufPending = 0; 1097 1098 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 1099 if (pComponentPrivate->pOutputBufHdrPending[i]) { 1100 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1101 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1102 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1103 OMX_DirOutput, 1104 &pLcmlHdr); 1105 MP3DEC_SetPending(pComponentPrivate, 1106 pComponentPrivate->pOutputBufHdrPending[i], 1107 OMX_DirOutput, 1108 __LINE__); 1109 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1110 EMMCodecOuputBuffer, 1111 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1112 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen, 1113 0, 1114 (OMX_U8 *) pLcmlHdr->pOpParam, 1115 sizeof(MP3DEC_UAlgOutBufParamStruct), 1116 NULL); 1117 } 1118 } 1119 pComponentPrivate->nNumOutputBufPending = 0; 1120 }else { 1121 pComponentPrivate->cbInfo.EventHandler (pHandle, 1122 pHandle->pApplicationPrivate, 1123 OMX_EventError, 1124 OMX_ErrorIncorrectStateTransition, 1125 OMX_TI_ErrorMinor, 1126 "Invalid State"); 1127 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid State Given by Application\n"); 1128 goto EXIT; 1129 } 1130 1131 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Executing\n\n"); 1132#ifdef RESOURCE_MANAGER_ENABLED 1133 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_MP3_Decoder_COMPONENT, OMX_StateExecuting, 3456, NULL); 1134#endif 1135 pComponentPrivate->curState = OMX_StateExecuting; 1136 1137#ifdef __PERF_INSTRUMENTATION__ 1138 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState); 1139#endif 1140 pComponentPrivate->cbInfo.EventHandler(pHandle, 1141 pHandle->pApplicationPrivate, 1142 OMX_EventCmdComplete, 1143 OMX_CommandStateSet, 1144 pComponentPrivate->curState, 1145 NULL); 1146 1147 break; 1148 1149 case OMX_StateLoaded: 1150 OMX_PRDSP2(pComponentPrivate->dbg, ": HandleCommand: Cmd Loaded\n"); 1151 1152 if (pComponentPrivate->curState == OMX_StateWaitForResources ){ 1153 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Loaded\n\n"); 1154#ifdef __PERF_INSTRUMENTATION__ 1155 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup); 1156#endif 1157 pComponentPrivate->curState = OMX_StateLoaded; 1158#ifdef __PERF_INSTRUMENTATION__ 1159 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup); 1160#endif 1161 pComponentPrivate->cbInfo.EventHandler (pHandle, 1162 pHandle->pApplicationPrivate, 1163 OMX_EventCmdComplete, 1164 OMX_CommandStateSet, 1165 pComponentPrivate->curState, 1166 NULL); 1167 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Transitioning from WaitFor to Loaded\n"); 1168 break; 1169 } 1170 1171 if (pComponentPrivate->curState != OMX_StateIdle) { 1172 pComponentPrivate->cbInfo.EventHandler (pHandle, 1173 pHandle->pApplicationPrivate, 1174 OMX_EventError, 1175 OMX_ErrorIncorrectStateTransition, 1176 OMX_TI_ErrorMinor, 1177 "Invalid State"); 1178 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid State Given by \ 1179 Application\n"); 1180 goto EXIT; 1181 } 1182#ifdef __PERF_INSTRUMENTATION__ 1183 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup); 1184#endif 1185 1186 OMX_PRSTATE2(pComponentPrivate->dbg, "Current State = %d\n",pComponentPrivate->curState); 1187 OMX_PRSTATE2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %ld\n",pComponentPrivate->pInputBufferList->numBuffers); 1188 OMX_PRSTATE2(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->numBuffers = %ld\n",pComponentPrivate->pOutputBufferList->numBuffers); 1189 1190 if (pComponentPrivate->pInputBufferList->numBuffers || pComponentPrivate->pOutputBufferList->numBuffers) { 1191 pComponentPrivate->InIdle_goingtoloaded = 1; 1192#ifndef UNDER_CE 1193 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1194 pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex); 1195 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 1196#else 1197 OMX_WaitForEvent(&(pComponentPrivate->InIdle_event)); 1198#endif 1199 /* Send StateChangeNotification to application */ 1200 pComponentPrivate->bLoadedCommandPending = OMX_FALSE; 1201 } 1202 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec DESTROY %d\n", __LINE__); 1203 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1204 EMMCodecControlDestroy,(void *)pArgs); 1205#ifdef UNDER_CE 1206 FreeLibrary(g_hLcmlDllHandle); 1207 g_hLcmlDllHandle = NULL; 1208#endif 1209#ifdef __PERF_INSTRUMENTATION__ 1210 PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent); 1211#endif 1212 eError = EXIT_COMPONENT_THRD; 1213 pComponentPrivate->bInitParamsInitialized = 0; 1214 break; 1215 1216 case OMX_StatePause: 1217 OMX_PRSTATE2(pComponentPrivate->dbg, ": HandleCommand: Cmd Pause: Cur State = %d\n", 1218 pComponentPrivate->curState); 1219 1220 if ((pComponentPrivate->curState != OMX_StateExecuting) && 1221 (pComponentPrivate->curState != OMX_StateIdle)) { 1222 pComponentPrivate->cbInfo.EventHandler (pHandle, 1223 pHandle->pApplicationPrivate, 1224 OMX_EventError, 1225 OMX_ErrorIncorrectStateTransition, 1226 OMX_TI_ErrorMinor, 1227 "Invalid State"); 1228 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid State Given by \ 1229 Application\n"); 1230 goto EXIT; 1231 } 1232#ifdef __PERF_INSTRUMENTATION__ 1233 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 1234#endif 1235 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec\n"); 1236 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec PAUSE %d\n", __LINE__); 1237 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1238 EMMCodecControlPause,(void *)pArgs); 1239 if (eError != OMX_ErrorNone) { 1240 OMX_ERROR4(pComponentPrivate->dbg, ": Error: in Pausing the codec\n"); 1241 pComponentPrivate->curState = OMX_StateInvalid; 1242 pComponentPrivate->cbInfo.EventHandler(pHandle, 1243 pHandle->pApplicationPrivate, 1244 OMX_EventError, 1245 eError, 1246 OMX_TI_ErrorSevere, 1247 NULL); 1248 goto EXIT; 1249 } 1250 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Pause\n\n"); 1251#ifdef RESOURCE_MANAGER_ENABLED 1252 rm_error = RMProxy_NewSendCommand(pHandle, 1253 RMProxy_StateSet, 1254 OMX_MP3_Decoder_COMPONENT, 1255 OMX_StatePause, 1256 3456, 1257 NULL); 1258#endif 1259 1260 break; 1261 1262 case OMX_StateWaitForResources: 1263 OMX_PRDSP2(pComponentPrivate->dbg, ": HandleCommand: Cmd : OMX_StateWaitForResources\n"); 1264 if (pComponentPrivate->curState == OMX_StateLoaded) { 1265#ifdef RESOURCE_MANAGER_ENABLED 1266 rm_error = RMProxy_NewSendCommand(pHandle, 1267 RMProxy_StateSet, 1268 OMX_MP3_Decoder_COMPONENT, 1269 OMX_StateWaitForResources, 1270 3456, 1271 NULL); 1272#endif 1273 1274 pComponentPrivate->curState = OMX_StateWaitForResources; 1275 OMX_PRDSP2(pComponentPrivate->dbg, ": Transitioning from Loaded to OMX_StateWaitForResources\n"); 1276 pComponentPrivate->cbInfo.EventHandler(pHandle, 1277 pHandle->pApplicationPrivate, 1278 OMX_EventCmdComplete, 1279 OMX_CommandStateSet, 1280 pComponentPrivate->curState, 1281 NULL); 1282 } else { 1283 pComponentPrivate->cbInfo.EventHandler(pHandle, 1284 pHandle->pApplicationPrivate, 1285 OMX_EventError, 1286 OMX_ErrorIncorrectStateTransition, 1287 OMX_TI_ErrorMinor, 1288 NULL); 1289 } 1290 break; 1291 1292 case OMX_StateInvalid: 1293 OMX_PRDSP2(pComponentPrivate->dbg, ": HandleCommand: Cmd OMX_StateInvalid:\n"); 1294 if (pComponentPrivate->curState != OMX_StateWaitForResources && 1295 pComponentPrivate->curState != OMX_StateLoaded && 1296 pComponentPrivate->curState != OMX_StateInvalid ) { 1297 1298 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1299 EMMCodecControlDestroy, (void *)pArgs); 1300 } 1301 1302 pComponentPrivate->curState = OMX_StateInvalid; 1303 pComponentPrivate->cbInfo.EventHandler(pHandle, 1304 pHandle->pApplicationPrivate, 1305 OMX_EventError, 1306 OMX_ErrorInvalidState, 1307 OMX_TI_ErrorSevere, 1308 NULL); 1309 MP3DEC_CleanupInitParams(pHandle); 1310 1311 break; 1312 1313 case OMX_StateMax: 1314 OMX_PRSTATE2(pComponentPrivate->dbg, ": HandleCommand: Cmd OMX_StateMax::\n"); 1315 break; 1316 } /* End of Switch */ 1317 } 1318 } 1319 else if (command == OMX_CommandMarkBuffer) { 1320 OMX_PRDSP2(pComponentPrivate->dbg, "command OMX_CommandMarkBuffer received\n"); 1321 if(!pComponentPrivate->pMarkBuf){ 1322 OMX_PRBUFFER2(pComponentPrivate->dbg, "command OMX_CommandMarkBuffer received \n"); 1323 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData); 1324 } 1325 } else if (command == OMX_CommandPortDisable) { 1326 if (!pComponentPrivate->bDisableCommandPending) { 1327 if(commandData == 0x0){ 1328 /* disable port */ 1329 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 1330 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->bBufferPending[%ld] = %ld\n",i, 1331 pComponentPrivate->pInputBufferList->bBufferPending[i]); 1332 if (MP3DEC_IsPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],OMX_DirInput)) { 1333 /* Real solution is flush buffers from DSP. Until we have the ability to do that 1334 we just call EmptyBufferDone() on any pending buffers */ 1335 OMX_PRBUFFER2(pComponentPrivate->dbg, "Forcing EmptyBufferDone\n"); 1336#ifdef __PERF_INSTRUMENTATION__ 1337 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1338 PREF(pComponentPrivate->pInputBufferList->pBufHdr[i], pBuffer), 1339 0, 1340 PERF_ModuleHLMM); 1341#endif 1342 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 1343 pComponentPrivate->pHandle->pApplicationPrivate, 1344 pComponentPrivate->pInputBufferList->pBufHdr[i]); 1345 pComponentPrivate->nEmptyBufferDoneCount++; 1346 SignalIfAllBuffersAreReturned(pComponentPrivate); 1347 } 1348 } 1349 1350 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = OMX_FALSE; 1351 } 1352 if(commandData == -1){ 1353 /* disable port */ 1354 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = OMX_FALSE; 1355 } 1356 if(commandData == 0x1 || commandData == -1){ 1357 char *pArgs = "damedesuStr"; 1358 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = OMX_FALSE; 1359 } 1360 } 1361 OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %ld\n",commandData); 1362 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated = %d\n", 1363 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated); 1364 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated = %d\n", 1365 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated); 1366 if(commandData == 0x0) { 1367 if(!pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated){ 1368 /* return cmdcomplete event if input unpopulated */ 1369 pComponentPrivate->cbInfo.EventHandler(pHandle, 1370 pHandle->pApplicationPrivate, 1371 OMX_EventCmdComplete, 1372 OMX_CommandPortDisable, 1373 MP3D_INPUT_PORT, 1374 NULL); 1375 pComponentPrivate->bDisableCommandPending = 0; 1376 } 1377 else{ 1378 pComponentPrivate->bDisableCommandPending = 1; 1379 pComponentPrivate->bDisableCommandParam = commandData; 1380 } 1381 } 1382 1383 if(commandData == 0x1) { 1384 if (!pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated){ 1385 /* return cmdcomplete event if output unpopulated */ 1386 OMX_PRCOMM2(pComponentPrivate->dbg, "CMD COMPLETE PORT DISABLE OUTPUT\n"); 1387 pComponentPrivate->cbInfo.EventHandler(pHandle, 1388 pHandle->pApplicationPrivate, 1389 OMX_EventCmdComplete, 1390 OMX_CommandPortDisable, 1391 MP3D_OUTPUT_PORT, 1392 NULL); 1393 pComponentPrivate->bDisableCommandPending = 0; 1394 } 1395 else { 1396 pComponentPrivate->bDisableCommandPending = 1; 1397 pComponentPrivate->bDisableCommandParam = commandData; 1398 } 1399 } 1400 1401 if(commandData == -1) { 1402 if (!pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated && 1403 !pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated){ 1404 1405 /* return cmdcomplete event if inout & output unpopulated */ 1406 pComponentPrivate->cbInfo.EventHandler(pHandle, 1407 pHandle->pApplicationPrivate, 1408 OMX_EventCmdComplete, 1409 OMX_CommandPortDisable, 1410 MP3D_INPUT_PORT, 1411 NULL); 1412 1413 pComponentPrivate->cbInfo.EventHandler(pHandle, 1414 pHandle->pApplicationPrivate, 1415 OMX_EventCmdComplete, 1416 OMX_CommandPortDisable, 1417 MP3D_OUTPUT_PORT, 1418 NULL); 1419 pComponentPrivate->bDisableCommandPending = 0; 1420 } 1421 else { 1422 pComponentPrivate->bDisableCommandPending = 1; 1423 pComponentPrivate->bDisableCommandParam = commandData; 1424 } 1425 } 1426 } 1427 else if (command == OMX_CommandPortEnable) { 1428 if (pComponentPrivate->bDspStoppedWhileExecuting){ 1429 // set up the codec with corrected settings 1430 // it was not done in idle->executing transition 1431 if(pComponentPrivate->dasfmode == 0 && 1432 pComponentPrivate->pcmParams->bInterleaved) { 1433 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_INTERLEAVED; 1434 } else { 1435 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_BLOCK; 1436 } 1437 pComponentPrivate->ptAlgDynParams->lMonoToStereoCopy = 0; 1438 pComponentPrivate->ptAlgDynParams->lStereoToMonoCopy = 0; 1439 pComponentPrivate->ptAlgDynParams->size = sizeof(MP3DEC_UALGParams); 1440 1441 pValues1[0] = IUALG_CMD_SETSTATUS; 1442 pValues1[1] = (OMX_U32) pComponentPrivate->ptAlgDynParams; 1443 pValues1[2] = sizeof(MP3DEC_UALGParams); 1444 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec ALG %d\n", __LINE__); 1445 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1446 EMMCodecControlAlgCtrl,(void *)pValues1); 1447 if(eError != OMX_ErrorNone) { 1448 OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Start..\n"); 1449 pComponentPrivate->curState = OMX_StateInvalid; 1450 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1451 pComponentPrivate->pHandle->pApplicationPrivate, 1452 OMX_EventError, 1453 eError, 1454 OMX_TI_ErrorSevere, 1455 NULL); 1456 goto EXIT; 1457 } 1458 1459 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 1460 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec start %d\n", __LINE__); 1461 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1462 EMMCodecControlStart,(void *)pArgs); 1463 1464 if(eError != OMX_ErrorNone) { 1465 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Start..\n", __LINE__); 1466 goto EXIT; 1467 } 1468 OMX_PRDSP1(pComponentPrivate->dbg, ": Codec Has Been Started \n"); 1469 } 1470 else{ 1471 OMX_PRDSP1(pComponentPrivate->dbg, "codec was previusly started! %d\n", __LINE__); 1472 } 1473 if (!pComponentPrivate->bEnableCommandPending) { 1474 if(commandData == 0x0 || commandData == -1){ 1475 /* enable in port */ 1476 OMX_PRCOMM2(pComponentPrivate->dbg, "setting input port to enabled\n"); 1477 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = OMX_TRUE; 1478 OMX_PRSTATE2(pComponentPrivate->dbg, "WAKE UP!! HandleCommand: En utils setting output port to enabled. \n"); 1479 if(pComponentPrivate->AlloBuf_waitingsignal){ 1480 pComponentPrivate->AlloBuf_waitingsignal = 0; 1481 } 1482 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled = %d\n", 1483 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bEnabled); 1484 } 1485 if(commandData == 0x1 || commandData == -1){ 1486 1487 /* enable out port */ 1488 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = OMX_TRUE; 1489 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled = %d\n", 1490 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bEnabled); 1491 1492 signalAlloBufThresholdIfNecessary(pComponentPrivate); 1493 OMX_PRCOMM2(pComponentPrivate->dbg, "setting output port to enabled\n"); 1494 } 1495 } 1496 if(commandData == 0x0){ 1497 if (pComponentPrivate->curState == OMX_StateLoaded || 1498 pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated) { 1499 pComponentPrivate->cbInfo.EventHandler(pHandle, 1500 pHandle->pApplicationPrivate, 1501 OMX_EventCmdComplete, 1502 OMX_CommandPortEnable, 1503 MP3D_INPUT_PORT, 1504 NULL); 1505 1506 signalAlloBufThresholdIfNecessary(pComponentPrivate); 1507 1508 //MP3DECFill_LCMLInitParamsEx(pHandle, 0); 1509 // queue the pending buffers received while doing the config 1510 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1511 OMX_PRCOMM2(pComponentPrivate->dbg, "in queuePending loop INPUT %d\n", __LINE__); 1512 if (pComponentPrivate->pInputBufHdrPending[i] != NULL) { 1513 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1514 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1515 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 1516 MP3DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__); 1517 OMX_PRBUFFER2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d\n", __LINE__); 1518 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1519 EMMCodecInputBuffer, 1520 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 1521 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 1522 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 1523 (OMX_U8 *) pLcmlHdr->pIpParam, 1524 sizeof(MP3DEC_UAlgInBufParamStruct), 1525 NULL); 1526 OMX_PRBUFFER2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d, error = %d\n", __LINE__, eError); 1527 } 1528 } 1529 pComponentPrivate->nNumInputBufPending = 0; 1530 pComponentPrivate->reconfigInputPort = 0; 1531 pComponentPrivate->bEnableCommandPending = 0; 1532 } 1533 else { 1534 pComponentPrivate->bEnableCommandPending = 1; 1535 pComponentPrivate->bEnableCommandParam = commandData; 1536 } 1537 } 1538 else if(commandData == 0x1) { 1539 if (pComponentPrivate->curState == OMX_StateLoaded || 1540 pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated){ 1541 pComponentPrivate->cbInfo.EventHandler( pHandle, 1542 pHandle->pApplicationPrivate, 1543 OMX_EventCmdComplete, 1544 OMX_CommandPortEnable, 1545 MP3D_OUTPUT_PORT, 1546 NULL); 1547 1548 signalAlloBufThresholdIfNecessary(pComponentPrivate); 1549 OMX_PRINT2(pComponentPrivate->dbg, "reconfigOut = %d!, but should be true!\n",pComponentPrivate->reconfigOutputPort); 1550 if(pComponentPrivate->reconfigOutputPort){ 1551 //make sure new VA's are used 1552 MP3DEC_CleanupInitParamsEx(pHandle,commandData); 1553 MP3DECFill_LCMLInitParamsEx(pHandle, 1); 1554 OMX_PRDSP2(pComponentPrivate->dbg, "completed MP3DEC_MapLCMLParamsEx! %d\n", __LINE__); 1555 1556 } 1557 1558 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 1559 if (pComponentPrivate->pOutputBufHdrPending[i]) { 1560 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1561 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1562 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1563 OMX_DirOutput, 1564 &pLcmlHdr); 1565 MP3DEC_SetPending(pComponentPrivate, 1566 pComponentPrivate->pOutputBufHdrPending[i], 1567 OMX_DirOutput, 1568 __LINE__); 1569 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d\n", __LINE__); 1570 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1571 EMMCodecOuputBuffer, 1572 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1573 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen, 1574 0, 1575 (OMX_U8 *) pLcmlHdr->pOpParam, 1576 sizeof(MP3DEC_UAlgOutBufParamStruct), 1577 NULL); 1578 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d, error = %d\n", __LINE__, eError); 1579 } 1580 } 1581 pComponentPrivate->nNumOutputBufPending = 0; 1582 // queue the pending buffers received while doing the config 1583 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1584 OMX_PRCOMM2(pComponentPrivate->dbg, "in queuePending loop INPUT %d\n", __LINE__); 1585 if (pComponentPrivate->pInputBufHdrPending[i] != NULL) { 1586 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1587 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1588 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 1589 MP3DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__); 1590 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d\n", __LINE__); 1591 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1592 EMMCodecInputBuffer, 1593 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 1594 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 1595 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 1596 (OMX_U8 *) pLcmlHdr->pIpParam, 1597 sizeof(MP3DEC_UAlgInBufParamStruct), 1598 NULL); 1599 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d, error = %d\n", __LINE__, eError); 1600 } 1601 } 1602 pComponentPrivate->nNumInputBufPending = 0; 1603 pComponentPrivate->bEnableCommandPending = 0; 1604 pComponentPrivate->reconfigOutputPort = 0; 1605 } 1606 else { 1607 pComponentPrivate->bEnableCommandPending = 1; 1608 pComponentPrivate->bEnableCommandParam = commandData; 1609 } 1610 } 1611 else if(commandData == -1) { 1612 if (pComponentPrivate->curState == OMX_StateLoaded || 1613 (pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->bPopulated 1614 && pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->bPopulated)){ 1615 pComponentPrivate->cbInfo.EventHandler(pHandle, 1616 pHandle->pApplicationPrivate, 1617 OMX_EventCmdComplete, 1618 OMX_CommandPortEnable, 1619 MP3D_INPUT_PORT, 1620 NULL); 1621 pComponentPrivate->cbInfo.EventHandler(pHandle, 1622 pHandle->pApplicationPrivate, 1623 OMX_EventCmdComplete, 1624 OMX_CommandPortEnable, 1625 MP3D_OUTPUT_PORT, 1626 NULL); 1627 1628 signalAlloBufThresholdIfNecessary(pComponentPrivate); 1629 MP3DEC_CleanupInitParamsEx(pHandle,commandData); 1630 MP3DECFill_LCMLInitParamsEx(pHandle, -1); 1631 1632 // queue the pending buffers received while doing the config, output then input 1633 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 1634 if (pComponentPrivate->pOutputBufHdrPending[i]) { 1635 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1636 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1637 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1638 OMX_DirOutput, 1639 &pLcmlHdr); 1640 MP3DEC_SetPending(pComponentPrivate, 1641 pComponentPrivate->pOutputBufHdrPending[i], 1642 OMX_DirOutput, 1643 __LINE__); 1644 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1645 EMMCodecOuputBuffer, 1646 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1647 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen, 1648 0, 1649 (OMX_U8 *) pLcmlHdr->pOpParam, 1650 sizeof(MP3DEC_UAlgOutBufParamStruct), 1651 NULL); 1652 } 1653 } 1654 pComponentPrivate->nNumOutputBufPending = 0; 1655 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1656 OMX_PRCOMM2(pComponentPrivate->dbg, "in queuePending loop INPUT %d\n", __LINE__); 1657 if (pComponentPrivate->pInputBufHdrPending[i] != NULL) { 1658 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1659 MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, 1660 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 1661 MP3DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__); 1662 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d\n", __LINE__); 1663 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1664 EMMCodecInputBuffer, 1665 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 1666 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 1667 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 1668 (OMX_U8 *) pLcmlHdr->pIpParam, 1669 sizeof(MP3DEC_UAlgInBufParamStruct), 1670 NULL); 1671 OMX_PRCOMM2(pComponentPrivate->dbg, "QueueBuffer pending port config line %d, error = %d\n", __LINE__, eError); 1672 } 1673 } 1674 pComponentPrivate->nNumInputBufPending = 0; 1675 pComponentPrivate->bEnableCommandPending = 0; 1676 } 1677 else { 1678 pComponentPrivate->bEnableCommandPending = 1; 1679 pComponentPrivate->bEnableCommandParam = commandData; 1680 } 1681 } 1682 } 1683 else if (command == OMX_CommandFlush) { 1684 OMX_U32 aParam[3] = {0}; 1685 if(commandData == 0x0 || commandData == -1) { 1686 OMX_ERROR2(pComponentPrivate->dbg, "Flushing input port:: unhandled ETB's = %ld, handled ETB's = %ld\n", 1687 pComponentPrivate->nEmptyThisBufferCount, pComponentPrivate->nHandledEmptyThisBuffers); 1688 if (pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nHandledEmptyThisBuffers) { 1689 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE; 1690 pComponentPrivate->first_buff = 0; 1691 OMX_ERROR2(pComponentPrivate->dbg, "in flush IN:lcml_nCntApp && app_nBuf = %ld && %ld\n", pComponentPrivate->lcml_nCntApp, pComponentPrivate->app_nBuf); 1692 if (pComponentPrivate->num_Sent_Ip_Buff){ //no buffers have been sent yet, no need to flush SN 1693 aParam[0] = USN_STRMCMD_FLUSH; 1694 aParam[1] = 0x0; 1695 aParam[2] = 0x0; 1696 1697 OMX_ERROR4(pComponentPrivate->dbg, "Flushing input port\n"); 1698 OMX_ERROR2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec FLUSH in %d\n", __LINE__); 1699 if (pComponentPrivate->codecFlush_waitingsignal == 0){ 1700 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex); 1701 } 1702 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1703 EMMCodecControlStrmCtrl, (void*)aParam); 1704 if (pComponentPrivate->codecFlush_waitingsignal == 0){ 1705 pthread_cond_wait(&pComponentPrivate->codecFlush_threshold, &pComponentPrivate->codecFlush_mutex); 1706 pComponentPrivate->codecFlush_waitingsignal = 0; 1707 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex); 1708 } 1709 if (eError != OMX_ErrorNone) { 1710 goto EXIT; 1711 } 1712 } 1713 else{ 1714 OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing input port %d\n",__LINE__); 1715 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1716#ifdef __PERF_INSTRUMENTATION__ 1717 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1718 PREF(pComponentPrivate->pInputBufHdrPending[i],pBuffer), 1719 0, 1720 PERF_ModuleHLMM); 1721#endif 1722 1723 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 1724 pComponentPrivate->pHandle->pApplicationPrivate, 1725 pComponentPrivate->pInputBufHdrPending[i]); 1726 pComponentPrivate->pInputBufHdrPending[i] = NULL; 1727 pComponentPrivate->nEmptyBufferDoneCount++; 1728 SignalIfAllBuffersAreReturned(pComponentPrivate); 1729 } 1730 pComponentPrivate->nNumInputBufPending=0; 1731 pComponentPrivate->cbInfo.EventHandler(pHandle, 1732 pHandle->pApplicationPrivate, 1733 OMX_EventCmdComplete, 1734 OMX_CommandFlush, 1735 MP3D_INPUT_PORT, 1736 NULL); 1737 } 1738 }else { 1739 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE; 1740 } 1741 } 1742 if(commandData == 0x1 || commandData == -1){ 1743 OMX_ERROR2(pComponentPrivate->dbg, "Flushing output port:: unhandled FTB's = %ld handled FTB's = %ld\n", 1744 pComponentPrivate->nFillThisBufferCount, pComponentPrivate->nHandledFillThisBuffers); 1745 if (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nHandledFillThisBuffers) { 1746 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE; 1747 /*pComponentPrivate->first_buff = 0;*/ 1748 OMX_PRBUFFER2(pComponentPrivate->dbg, "in flush OUT:lcml_nCntApp && app_nBuf = %ld && %ld\n", pComponentPrivate->lcml_nCntApp, pComponentPrivate->app_nBuf); 1749 OMX_PRBUFFER2(pComponentPrivate->dbg, "in flush OUT:lcml_nOpBuf = %ld \n", pComponentPrivate->lcml_nOpBuf); 1750 if (pComponentPrivate->num_Op_Issued && !pComponentPrivate->reconfigOutputPort){ //if no buffers have been sent yet, no need to flush SN 1751 aParam[0] = USN_STRMCMD_FLUSH; 1752 aParam[1] = 0x1; 1753 aParam[2] = 0x0; 1754 1755 OMX_ERROR4(pComponentPrivate->dbg, "Flushing output port\n"); 1756 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec FLUSH out %d\n", __LINE__); 1757 if (pComponentPrivate->codecFlush_waitingsignal == 0){ 1758 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex); 1759 } 1760 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1761 EMMCodecControlStrmCtrl, (void*)aParam); 1762 if (pComponentPrivate->codecFlush_waitingsignal == 0){ 1763 pthread_cond_wait(&pComponentPrivate->codecFlush_threshold, &pComponentPrivate->codecFlush_mutex); 1764 pComponentPrivate->codecFlush_waitingsignal = 0; 1765 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex); 1766 } 1767 if (eError != OMX_ErrorNone) { 1768 goto EXIT; 1769 } 1770 } 1771 else{ 1772 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 1773#ifdef __PERF_INSTRUMENTATION__ 1774 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1775 PREF(pComponentPrivate->pOutputBufHdrPending[i],pBuffer), 1776 PREF(pComponentPrivate->pOutputBufHdrPending[i],nFilledLen), 1777 PERF_ModuleHLMM); 1778#endif 1779 1780 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 1781 pComponentPrivate->pHandle->pApplicationPrivate, 1782 pComponentPrivate->pOutputBufHdrPending[i] 1783 ); 1784 pComponentPrivate->nFillBufferDoneCount++; 1785 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 1786 SignalIfAllBuffersAreReturned(pComponentPrivate); 1787 } 1788 pComponentPrivate->nNumOutputBufPending=0; 1789 1790 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1791 pComponentPrivate->pHandle->pApplicationPrivate, 1792 OMX_EventCmdComplete, 1793 OMX_CommandFlush, 1794 MP3D_OUTPUT_PORT, 1795 NULL); 1796 } 1797 } else { 1798 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE; 1799 } 1800 } 1801 } 1802 EXIT: 1803 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting HandleCommand Function, error = %d\n", eError); 1804 if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD) { 1805 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1806 pComponentPrivate->pHandle->pApplicationPrivate, 1807 OMX_EventError, 1808 eError, 1809 OMX_TI_ErrorSevere, 1810 NULL); 1811 } 1812 return eError; 1813} 1814 1815 1816/* ================================================================================= * */ 1817/** 1818 * @fn MP3DEC_HandleDataBuf_FromApp() function handles the input and output buffers 1819 * that come from the application. It is not direct function wich gets called by 1820 * the application rather, it gets called eventually. 1821 * 1822 * @param *pBufHeader This is the buffer header that needs to be processed. 1823 * 1824 * @param *pComponentPrivate This is component's private date structure. 1825 * 1826 * @pre None 1827 * 1828 * @post None 1829 * 1830 * @return OMX_ErrorNone = Successful processing. 1831 * OMX_ErrorInsufficientResources = Not enough memory 1832 * OMX_ErrorHardware = Hardware error has occured lile LCML failed 1833 * to do any said operartion. 1834 * 1835 * @see None 1836 */ 1837/* ================================================================================ * */ 1838 1839OMX_ERRORTYPE MP3DEC_HandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader, 1840 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 1841{ 1842 OMX_ERRORTYPE eError = OMX_ErrorNone; 1843 OMX_DIRTYPE eDir; 1844 OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL; 1845 char *pArgs = "damedesuStr"; 1846 OMX_U32 pValues[4]; 1847 OMX_U32 pValues1[4]; 1848 OMX_U32 nBitPosition = 0; 1849 OMX_U8* pHeaderStream = (OMX_U8*)pBufHeader->pBuffer; 1850 OMX_U32 temp = -1; 1851 OMX_U32 temp2 = -1; 1852 1853 OMX_PRINT1(pComponentPrivate->dbg, ":: Entering HandleDataBuf_FromApp Function\n"); 1854 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: pBufHeader->pMarkData = %p\n",pBufHeader->pMarkData); 1855 1856 pBufHeader->pPlatformPrivate = pComponentPrivate; 1857 eError = MP3DEC_GetBufferDirection(pBufHeader, &eDir); 1858 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: HandleDataBuf_FromApp Function\n"); 1859 if (eError != OMX_ErrorNone) { 1860 OMX_ERROR4(pComponentPrivate->dbg, ":: The pBufHeader is not found in the list\n"); 1861 goto EXIT; 1862 } 1863 1864 if (eDir == OMX_DirInput) { 1865 pComponentPrivate->nHandledEmptyThisBuffers++; 1866 if (pComponentPrivate->curState == OMX_StateIdle){ 1867 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 1868 pComponentPrivate->pHandle->pApplicationPrivate, 1869 pBufHeader); 1870 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__); 1871 pComponentPrivate->nEmptyBufferDoneCount++; 1872 SignalIfAllBuffersAreReturned(pComponentPrivate); 1873 goto EXIT; 1874 } 1875 LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle; 1876 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 1877 pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput]; 1878 1879 eError = MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr); 1880 if (eError != OMX_ErrorNone) { 1881 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid Buffer Came ...\n"); 1882 goto EXIT; 1883 } 1884 1885 if ((pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)) { 1886 pComponentPrivate->bBypassDSP = 0; 1887 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: HandleDataBuf_FromApp Function\n"); 1888 OMX_PRBUFFER2(pComponentPrivate->dbg, ":::Calling LCML_QueueBuffer\n"); 1889 1890#ifdef __PERF_INSTRUMENTATION__ 1891 /*For Steady State Instumentation*/ 1892 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1893 PREF(pBufHeader,pBuffer), 1894 pPortDefIn->nBufferSize, 1895 PERF_ModuleCommonLayer); 1896#endif 1897 if(pComponentPrivate->SendAfterEOS){ 1898 if(pComponentPrivate->dasfmode == 1) { 1899 pComponentPrivate->pParams->unAudioFormat = 1900 (unsigned short)pComponentPrivate->mp3Params->nChannels; 1901 if (pComponentPrivate->pParams->unAudioFormat == MP3D_STEREO_STREAM) { 1902 pComponentPrivate->pParams->unAudioFormat = MP3D_STEREO_NONINTERLEAVED_STREAM; 1903 } 1904 1905 pComponentPrivate->pParams->ulSamplingFreq = 1906 pComponentPrivate->mp3Params->nSampleRate; 1907 pComponentPrivate->pParams->unUUID = pComponentPrivate->streamID; 1908 1909 pValues[0] = USN_STRMCMD_SETCODECPARAMS; 1910 pValues[1] = (OMX_U32)pComponentPrivate->pParams; 1911 pValues[2] = sizeof(USN_AudioCodecParams); 1912 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec stream control %d\n", __LINE__); 1913 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1914 EMMCodecControlStrmCtrl,(void *)pValues); 1915 if(eError != OMX_ErrorNone) { 1916 OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in Codec StreamControl..\n"); 1917 pComponentPrivate->curState = OMX_StateInvalid; 1918 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1919 pComponentPrivate->pHandle->pApplicationPrivate, 1920 OMX_EventError, 1921 eError, 1922 OMX_TI_ErrorSevere, 1923 NULL); 1924 goto EXIT; 1925 } 1926 } 1927 1928 if(pBufHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG || pComponentPrivate->bConfigData){ 1929 OMX_PRBUFFER2(pComponentPrivate->dbg, "Detected OMX_BUFFERFLAG_CODECCONFIG\n, \tproceed with parsing config data\n"); 1930 // parse the frame header 1931 pComponentPrivate->pStreamData.nSyncWord = MP3DEC_GetBits(&nBitPosition, 11, pHeaderStream, OMX_TRUE); 1932 pComponentPrivate->pStreamData.nMpegVersion = MP3DEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 1933 pComponentPrivate->pStreamData.nLayer = MP3DEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 1934 temp = MP3DEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); // prot. bit 1935 pComponentPrivate->pStreamData.nBitRate = MP3DEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 1936 pComponentPrivate->pStreamData.nFrequency = MP3DEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 1937 temp = MP3DEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); // pad bit, prov. bit 1938 pComponentPrivate->pStreamData.nChannelMode = MP3DEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 1939 1940 //save the current value of pcmParams->nSamplingRate 1941 temp = pComponentPrivate->pcmParams->nSamplingRate; 1942 1943 // parsing completed, now compare to existing values and set port params as needed 1944 switch(pComponentPrivate->pStreamData.nFrequency){ 1945 // these frequency values are based on mpeg1 supported freqs 1946 // if the stream is actually mpeg2 or mpeg2.5, we will divide appropriately below. 1947 case 0: 1948 pComponentPrivate->pcmParams->nSamplingRate = 44100; 1949 break; 1950 case 1: 1951 pComponentPrivate->pcmParams->nSamplingRate = 48000; 1952 break; 1953 case 2: 1954 pComponentPrivate->pcmParams->nSamplingRate = 32000; 1955 break; 1956 default: 1957 OMX_ERROR4(pComponentPrivate->dbg, "Unsupported Frequency\n"); 1958 break; 1959 } 1960 if (pComponentPrivate->pStreamData.nMpegVersion == 2){ 1961 // the actual sampling frequency is dependant upon the mpeg version 1962 // if Mpeg2 is used, divide the sampling rate from above by 2 1963 pComponentPrivate->pcmParams->nSamplingRate /= 2; 1964 } 1965 else if (pComponentPrivate->pStreamData.nMpegVersion == 0){ 1966 // the actual sampling frequency is dependant upon the mpeg version 1967 // divide by 4 for mpeg 2.5 1968 pComponentPrivate->pcmParams->nSamplingRate /= 4; 1969 } 1970 // save the current value of nChannels 1971 temp2 = pComponentPrivate->pcmParams->nChannels; 1972 // value of 3 = mono 1973 if (pComponentPrivate->pStreamData.nChannelMode == 3){ 1974 pComponentPrivate->pcmParams->nChannels = 1; 1975 } 1976 else{ // if stereo,joint stereo or dual channel, then pcm channels is stereo. Otherwise pcm output will be mono 1977 pComponentPrivate->pcmParams->nChannels = MP3D_STEREO_STREAM; 1978 } 1979 // decide if dynamic reconfig is needed 1980 OMX_PRCOMM2(pComponentPrivate->dbg, ": decide on reconfig ports...\n"); 1981 if (temp != pComponentPrivate->pcmParams->nSamplingRate || 1982 temp2 != pComponentPrivate->pcmParams->nChannels){ 1983 pComponentPrivate->reconfigOutputPort = OMX_TRUE; 1984 OMX_PRCOMM2(pComponentPrivate->dbg, ": reconfif output port set to true...\n"); 1985 } 1986 else{ 1987 OMX_PRCOMM2(pComponentPrivate->dbg, ": no port config needed, skip\n"); 1988 } 1989 1990 OMX_PRINT2(pComponentPrivate->dbg, "CODEC CONFIG: \n\tsample rate = %ld\n\tchannels = %ld\n\t channel mode = %ld (0/1 = stereo, 2/3 = mono)\n", 1991 pComponentPrivate->pcmParams->nSamplingRate, 1992 pComponentPrivate->pcmParams->nChannels, 1993 pComponentPrivate->pStreamData.nChannelMode); 1994 // set up the codec with corrected settings 1995 // it was not done in idle->executing transition 1996 if(pComponentPrivate->dasfmode == 0 && 1997 pComponentPrivate->pcmParams->bInterleaved) { 1998 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_INTERLEAVED; 1999 } else { 2000 pComponentPrivate->ptAlgDynParams->lOutputFormat = IAUDIO_BLOCK; 2001 } 2002 2003 pComponentPrivate->ptAlgDynParams->lMonoToStereoCopy = 0; 2004 pComponentPrivate->ptAlgDynParams->lStereoToMonoCopy = 0; 2005 pComponentPrivate->ptAlgDynParams->size = sizeof(MP3DEC_UALGParams); 2006 2007 pValues1[0] = IUALG_CMD_SETSTATUS; 2008 pValues1[1] = (OMX_U32) pComponentPrivate->ptAlgDynParams; 2009 pValues1[2] = sizeof(MP3DEC_UALGParams); 2010 OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec ALG %d\n", __LINE__); 2011 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 2012 EMMCodecControlAlgCtrl,(void *)pValues1); 2013 if(eError != OMX_ErrorNone) { 2014 OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Start..\n"); 2015 pComponentPrivate->curState = OMX_StateInvalid; 2016 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2017 pComponentPrivate->pHandle->pApplicationPrivate, 2018 OMX_EventError, 2019 eError, 2020 OMX_TI_ErrorSevere, 2021 NULL); 2022 goto EXIT; 2023 } 2024 2025 // adding port config 2026 if(pComponentPrivate->reconfigOutputPort){ 2027 OMX_PRCOMM2(pComponentPrivate->dbg, ": send event PortSettingsChanged for ouput port...\n"); 2028 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2029 pComponentPrivate->pHandle->pApplicationPrivate, 2030 OMX_EventPortSettingsChanged, 2031 OUTPUT_PORT_MP3DEC, 2032 0, 2033 NULL); 2034 } 2035 pComponentPrivate->bConfigData = 0; 2036 } 2037 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 2038 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 2039 EMMCodecControlStart, 2040 (void *)pArgs); 2041 if(eError != OMX_ErrorNone) { 2042 OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Start..\n", __LINE__); 2043 goto EXIT; 2044 } 2045 pComponentPrivate->SendAfterEOS = 0; 2046 //pComponentPrivate->first_buff = 0; 2047 } //end SendAfterEOS 2048 2049 pLcmlHdr->pIpParam->bLastBuffer = 0; 2050 2051 if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS) { 2052 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: bLastBuffer Is Set Here....\n"); 2053 pLcmlHdr->pIpParam->bLastBuffer = 1; 2054 pComponentPrivate->bIsEOFSent = 1; 2055 pComponentPrivate->SendAfterEOS = 1; 2056 pBufHeader->nFlags = 0; 2057 } 2058 2059 /* Store time stamp information */ 2060 pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp; 2061 /*add on: Store tic count information*/ 2062 pComponentPrivate->arrBufIndexTick[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount; 2063 pComponentPrivate->IpBufindex++; 2064 pComponentPrivate->IpBufindex %= pPortDefIn->nBufferCountActual; 2065 2066 if(!pComponentPrivate->frameMode){ 2067 if(pComponentPrivate->first_buff == 0){ 2068 pComponentPrivate->first_buff = 1; 2069 pComponentPrivate->first_TS = pBufHeader->nTimeStamp; 2070 } 2071 } 2072 2073 OMX_PRCOMM2(pComponentPrivate->dbg, "Comp:: Sending Filled Input buffer = %p, %ld\ 2074 to LCML\n",pBufHeader,pBufHeader->nFilledLen); 2075 2076 if (pComponentPrivate->curState == OMX_StateExecuting) { 2077 if (!MP3DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) { 2078 if(!pComponentPrivate->bDspStoppedWhileExecuting) { 2079 if(!(pComponentPrivate->reconfigInputPort || pComponentPrivate->reconfigOutputPort)){ 2080 MP3DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__); 2081 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 2082 EMMCodecInputBuffer, 2083 pBufHeader->pBuffer, 2084 pBufHeader->nAllocLen, 2085 pBufHeader->nFilledLen, 2086 (OMX_U8 *) pLcmlHdr->pIpParam, 2087 sizeof(MP3DEC_UAlgInBufParamStruct), 2088 NULL); 2089 if (eError != OMX_ErrorNone) { 2090 OMX_ERROR4(pComponentPrivate->dbg, "::Comp: SetBuff: IP: Error Occurred = %x\n", eError); 2091 eError = OMX_ErrorHardware; 2092 goto EXIT; 2093 } 2094 OMX_PRINT2(pComponentPrivate->dbg, "%d Sent IP %p, len %ld\n",__LINE__ , 2095 pBufHeader->pBuffer, 2096 pBufHeader->nFilledLen); 2097 } 2098 else{ 2099 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 2100 OMX_PRBUFFER2(pComponentPrivate->dbg, "Don't queue buffers during a reconfig, num IN pending is %ld\n", pComponentPrivate->nNumInputBufPending); 2101 } 2102 }else { 2103 OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone from line %d\n",__LINE__); 2104#ifdef __PERF_INSTRUMENTATION__ 2105 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2106 PREF(pBufHeader, pBuffer), 2107 0, 2108 PERF_ModuleHLMM); 2109#endif 2110 pComponentPrivate->cbInfo.EmptyBufferDone ( 2111 pComponentPrivate->pHandle, 2112 pComponentPrivate->pHandle->pApplicationPrivate, 2113 pBufHeader); 2114 pComponentPrivate->nEmptyBufferDoneCount++; 2115 SignalIfAllBuffersAreReturned(pComponentPrivate); 2116 } 2117 pComponentPrivate->lcml_nCntIp++; 2118 pComponentPrivate->lcml_nIpBuf++; 2119 pComponentPrivate->num_Sent_Ip_Buff++; 2120 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending Input buffer to Codec\n"); 2121 } 2122 } 2123 else if (pComponentPrivate->curState == OMX_StatePause) { 2124 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 2125 } 2126 }else { 2127 pComponentPrivate->bBypassDSP = 1; 2128 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Forcing EmptyBufferDone\n",__LINE__); 2129#ifdef __PERF_INSTRUMENTATION__ 2130 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2131 PREF(pComponentPrivate->pInputBufferList->pBufHdr[0], pBuffer), 2132 0, 2133 PERF_ModuleHLMM); 2134#endif 2135 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 2136 pComponentPrivate->pHandle->pApplicationPrivate, 2137 pComponentPrivate->pInputBufferList->pBufHdr[0]); 2138 pComponentPrivate->nEmptyBufferDoneCount++; 2139 SignalIfAllBuffersAreReturned(pComponentPrivate); 2140 } 2141 if(pBufHeader->pMarkData){ 2142 OMX_PRBUFFER2(pComponentPrivate->dbg, ":Detected pBufHeader->pMarkData\n"); 2143 2144 pComponentPrivate->pMarkData = pBufHeader->pMarkData; 2145 pComponentPrivate->hMarkTargetComponent = pBufHeader->hMarkTargetComponent; 2146 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData; 2147 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent; 2148 2149 if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){ 2150 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2151 pComponentPrivate->pHandle->pApplicationPrivate, 2152 OMX_EventMark, 2153 0, 2154 0, 2155 pBufHeader->pMarkData); 2156 } 2157 } 2158 if (pComponentPrivate->bFlushInputPortCommandPending) { 2159 OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL); 2160 } 2161 } 2162 else if (eDir == OMX_DirOutput) { 2163 pComponentPrivate->nHandledFillThisBuffers++; 2164 if (pComponentPrivate->curState == OMX_StateIdle){ 2165 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 2166 pComponentPrivate->pHandle->pApplicationPrivate, 2167 pBufHeader); 2168 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__); 2169 pComponentPrivate->nFillBufferDoneCount++; 2170 SignalIfAllBuffersAreReturned(pComponentPrivate); 2171 goto EXIT; 2172 } 2173 LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle; 2174 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 2175 OMX_PRBUFFER2(pComponentPrivate->dbg, ": pComponentPrivate->lcml_nOpBuf = %ld\n",pComponentPrivate->lcml_nOpBuf); 2176 OMX_PRBUFFER2(pComponentPrivate->dbg, ": pComponentPrivate->lcml_nIpBuf = %ld\n",pComponentPrivate->lcml_nIpBuf); 2177 eError = MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr); 2178 if (eError != OMX_ErrorNone) { 2179 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid Buffer Came ...\n"); 2180 goto EXIT; 2181 } 2182 OMX_PRDSP2(pComponentPrivate->dbg, ":::Calling LCML_QueueBuffer\n"); 2183#ifdef __PERF_INSTRUMENTATION__ 2184 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2185 PREF(pBufHeader,pBuffer), 2186 0, 2187 PERF_ModuleCommonLayer); 2188#endif 2189 if (pComponentPrivate->bBypassDSP == 0) { 2190 if (pComponentPrivate->curState == OMX_StateExecuting) { 2191 if(!(pComponentPrivate->reconfigInputPort || pComponentPrivate->reconfigOutputPort)){ 2192 if (!MP3DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput) && 2193 (pComponentPrivate->numPendingBuffers < pComponentPrivate->pOutputBufferList->numBuffers)){ 2194 if(!pComponentPrivate->bDspStoppedWhileExecuting){ 2195 MP3DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__); 2196 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 2197 EMMCodecOuputBuffer, 2198 pBufHeader->pBuffer, 2199 pBufHeader->nAllocLen, 2200 0, 2201 (OMX_U8 *) pLcmlHdr->pOpParam, 2202 sizeof(MP3DEC_UAlgOutBufParamStruct), 2203 pBufHeader->pBuffer); 2204 if (eError != OMX_ErrorNone ) { 2205 OMX_ERROR4(pComponentPrivate->dbg, ":: Comp:: SetBuff OP: Error Occurred = %d\n", eError); 2206 OMX_ERROR4(pComponentPrivate->dbg, "nFilledLen = %ld\n nAllocLen = %ld\n", pBufHeader->nFilledLen, pBufHeader->nAllocLen); 2207 eError = OMX_ErrorHardware; 2208 goto EXIT; 2209 } 2210 OMX_PRINT2(pComponentPrivate->dbg, "%d Sent OP %p\n",__LINE__,pBufHeader->pBuffer); 2211 pComponentPrivate->lcml_nCntOp++; 2212 pComponentPrivate->lcml_nOpBuf++; 2213 pComponentPrivate->num_Op_Issued++; 2214 } 2215 } 2216 2217 } else{ 2218 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader; 2219 OMX_PRBUFFER2(pComponentPrivate->dbg, "Don't queue while doing a reconfig:: output buffer, num pending = %ld\n", pComponentPrivate->nNumOutputBufPending); 2220 } 2221 }else if (pComponentPrivate->curState == OMX_StatePause) { 2222 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader; 2223 } 2224 } 2225 if (pComponentPrivate->bFlushOutputPortCommandPending) { 2226 OMX_SendCommand( pComponentPrivate->pHandle, OMX_CommandFlush, 1, NULL); 2227 } 2228 } 2229 else { 2230 OMX_ERROR4(pComponentPrivate->dbg, ": BufferHeader %p, Buffer %p Unknown ..........\n",pBufHeader, pBufHeader->pBuffer); 2231 eError = OMX_ErrorBadParameter; 2232 } 2233 EXIT: 2234 OMX_PRINT1(pComponentPrivate->dbg, ": Exiting from HandleDataBuf_FromApp: %x \n",eError); 2235 if (eError != OMX_ErrorNone ) { 2236 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2237 pComponentPrivate->pHandle->pApplicationPrivate, 2238 OMX_EventError, 2239 eError, 2240 OMX_TI_ErrorSevere, 2241 NULL); 2242 } 2243 return eError; 2244} 2245 2246 2247/* ================================================================================= * */ 2248/** 2249 * @fn MP3DEC_GetBufferDirection() function determines whether it is input buffer or 2250 * output buffer. 2251 * 2252 * @param *pBufHeader This is pointer to buffer header whose direction needs to 2253 * be determined. 2254 * 2255 * @param *eDir This is output argument which stores the direction of buffer. 2256 * 2257 * @pre None 2258 * 2259 * @post None 2260 * 2261 * @return OMX_ErrorNone = Successful processing. 2262 * OMX_ErrorBadParameter = In case of invalid buffer 2263 * 2264 * @see None 2265 */ 2266/* ================================================================================ * */ 2267 2268OMX_ERRORTYPE MP3DEC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, 2269 OMX_DIRTYPE *eDir) 2270{ 2271 OMX_ERRORTYPE eError = OMX_ErrorNone; 2272 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate; 2273 OMX_U32 nBuf = pComponentPrivate->pInputBufferList->numBuffers; 2274 OMX_BUFFERHEADERTYPE *pBuf = NULL; 2275 int flag = 1; 2276 OMX_U32 i=0; 2277 2278 OMX_PRINT1(pComponentPrivate->dbg, ":: Entering GetBufferDirection Function\n"); 2279 for(i=0; i<nBuf; i++) { 2280 pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i]; 2281 if(pBufHeader == pBuf) { 2282 *eDir = OMX_DirInput; 2283 OMX_PRINT2(pComponentPrivate->dbg, ":: Buffer %p is INPUT BUFFER\n", pBufHeader); 2284 flag = 0; 2285 goto EXIT; 2286 } 2287 } 2288 2289 nBuf = pComponentPrivate->pOutputBufferList->numBuffers; 2290 2291 for(i=0; i<nBuf; i++) { 2292 pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 2293 if(pBufHeader == pBuf) { 2294 *eDir = OMX_DirOutput; 2295 OMX_PRINT2(pComponentPrivate->dbg, ":: Buffer %p is OUTPUT BUFFER\n", pBufHeader); 2296 flag = 0; 2297 goto EXIT; 2298 } 2299 } 2300 2301 if (flag == 1) { 2302 MP3D_OMX_ERROR_EXIT(eError, OMX_ErrorBadParameter, 2303 "Buffer Not Found in List : OMX_ErrorBadParameter"); 2304 } 2305 EXIT: 2306 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting GetBufferDirection Function\n"); 2307 return eError; 2308} 2309 2310/** ================================================================================= * */ 2311/** 2312 * @fn MP3DEC_LCML_Callback() function is callback which is called by LCML whenever 2313 * there is an even generated for the component. 2314 * 2315 * @param event This is event that was generated. 2316 * 2317 * @param arg This has other needed arguments supplied by LCML like handles 2318 * etc. 2319 * 2320 * @pre None 2321 * 2322 * @post None 2323 * 2324 * @return OMX_ErrorNone = Successful processing. 2325 * OMX_ErrorInsufficientResources = Not enough memory 2326 * 2327 * @see None 2328 */ 2329/* ================================================================================ * */ 2330OMX_ERRORTYPE MP3DEC_LCML_Callback (TUsnCodecEvent event,void * args [10]) 2331{ 2332 OMX_ERRORTYPE eError = OMX_ErrorNone; 2333 OMX_U8 *pBuffer = args[1]; 2334 MP3D_LCML_BUFHEADERTYPE *pLcmlHdr; 2335 OMX_COMPONENTTYPE *pHandle; 2336 LCML_DSP_INTERFACE *pLcmlHandle; 2337 OMX_U32 i; 2338 MP3DEC_BUFDATA *OutputFrames; 2339 MP3DEC_COMPONENT_PRIVATE* pComponentPrivate = NULL; 2340#ifdef RESOURCE_MANAGER_ENABLED 2341 OMX_ERRORTYPE rm_error = OMX_ErrorNone; 2342#endif 2343 static double time_stmp = 0; 2344 2345 pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate; 2346 2347 OMX_PRINT1(pComponentPrivate->dbg, ":: Entering the LCML_Callback() : event = %d\n",event); 2348 2349 switch(event) { 2350 2351 case EMMCodecDspError: 2352 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecDspError\n"); 2353 break; 2354 2355 case EMMCodecInternalError: 2356 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecInternalError\n"); 2357 break; 2358 2359 case EMMCodecInitError: 2360 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecInitError\n"); 2361 break; 2362 2363 case EMMCodecDspMessageRecieved: 2364 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecDspMessageRecieved\n"); 2365 break; 2366 2367 case EMMCodecBufferProcessed: 2368 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferProcessed\n"); 2369 break; 2370 2371 case EMMCodecProcessingStarted: 2372 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStarted\n"); 2373 break; 2374 2375 case EMMCodecProcessingPaused: 2376 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingPaused\n"); 2377 break; 2378 2379 case EMMCodecProcessingStoped: 2380 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStoped\n"); 2381 break; 2382 2383 case EMMCodecProcessingEof: 2384 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingEof\n"); 2385 break; 2386 2387 case EMMCodecBufferNotProcessed: 2388 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferNotProcessed\n"); 2389 break; 2390 2391 case EMMCodecAlgCtrlAck: 2392 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecAlgCtrlAck\n"); 2393 break; 2394 2395 case EMMCodecStrmCtrlAck: 2396 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecStrmCtrlAck\n"); 2397 break; 2398 } 2399 2400 2401 if(event == EMMCodecBufferProcessed) { 2402 if( args[0] == (void *)EMMCodecInputBuffer) { 2403 OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Inside the LCML_Callback EMMCodecInputBuffer\n"); 2404 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Input: pBufferr = %p\n", pBuffer); 2405 2406 eError = MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirInput, &pLcmlHdr); 2407 if (eError != OMX_ErrorNone) { 2408 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid Buffer Came ...\n"); 2409 goto EXIT; 2410 } 2411 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Input: pLcmlHeader = %p\n", pLcmlHdr); 2412 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Input: pLcmlHdr->eDir = %d\n", pLcmlHdr->eDir); 2413 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Input: Filled Len = %ld\n", pLcmlHdr->pBufHdr->nFilledLen); 2414 pLcmlHdr->pBufHdr->nFilledLen = 0; 2415 OMX_PRINT1(pComponentPrivate->dbg, ":: Input: Filled Len = %ld\n", pLcmlHdr->pBufHdr->nFilledLen); 2416#ifdef __PERF_INSTRUMENTATION__ 2417 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 2418 PREF(pLcmlHdr->pBufHdr,pBuffer), 2419 0, 2420 PERF_ModuleCommonLayer); 2421#endif 2422 pComponentPrivate->lcml_nCntIpRes++; 2423 2424 MP3DEC_ClearPending(pComponentPrivate,pLcmlHdr->pBufHdr,OMX_DirInput,__LINE__); 2425 2426#ifdef __PERF_INSTRUMENTATION__ 2427 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2428 PREF(pLcmlHdr->pBufHdr,pBuffer), 2429 0, 2430 PERF_ModuleHLMM); 2431#endif 2432 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 2433 pComponentPrivate->pHandle->pApplicationPrivate, 2434 pLcmlHdr->pBufHdr); 2435 pComponentPrivate->nEmptyBufferDoneCount++; 2436 SignalIfAllBuffersAreReturned(pComponentPrivate); 2437 pComponentPrivate->lcml_nIpBuf--; 2438 pComponentPrivate->app_nBuf++; 2439 2440 } else if (args[0] == (void *)EMMCodecOuputBuffer) { 2441 OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Inside the LCML_Callback EMMCodecOuputBuffer\n"); 2442 2443 OMX_PRINT2(pComponentPrivate->dbg, "%d\t\t\t\t............ Received OP %p, \tlen %d\n", 2444 __LINE__,pBuffer,(int)args[8]); 2445 2446 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Output: pBufferr = %p\n", pBuffer); 2447 if (!MP3DEC_IsValid(pComponentPrivate,pBuffer,OMX_DirOutput)) { 2448 2449 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ############ FillBufferDone Invalid\n",__LINE__); 2450 /* If the buffer we get back from the DSP is not valid call FillBufferDone 2451 on a valid buffer */ 2452#ifdef __PERF_INSTRUMENTATION__ 2453 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2454 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->nInvalidFrameCount]->pBuffer, 2455 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->nInvalidFrameCount]->nFilledLen, 2456 PERF_ModuleHLMM); 2457#endif 2458 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 2459 pComponentPrivate->pHandle->pApplicationPrivate, 2460 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->nInvalidFrameCount++] 2461 ); 2462 pComponentPrivate->nFillBufferDoneCount++; 2463 pComponentPrivate->numPendingBuffers--; 2464 SignalIfAllBuffersAreReturned(pComponentPrivate); 2465 }else { 2466 eError = MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirOutput, &pLcmlHdr); 2467 if (eError != OMX_ErrorNone) { 2468 OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid Buffer Came ...\n"); 2469 goto EXIT; 2470 } 2471 pLcmlHdr->pBufHdr->nFilledLen = (int)args[8]; 2472 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Output: pLcmlHeader = %p\n", pLcmlHdr); 2473 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Output: pLcmlHdr->eDir = %d\n", pLcmlHdr->eDir); 2474 OMX_PRCOMM2(pComponentPrivate->dbg, ":: Output: Filled Len = %ld\n", pLcmlHdr->pBufHdr->nFilledLen); 2475 /* Recover MP3DEC_UAlgOutBufParamStruct from SN*/ 2476 OutputFrames = pLcmlHdr->pBufHdr->pOutputPortPrivate; 2477 OutputFrames->nFrames = (OMX_U8)(pLcmlHdr->pOpParam->ulFrameCount); 2478 2479#ifdef __PERF_INSTRUMENTATION__ 2480 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 2481 PREF(pLcmlHdr->pBufHdr,pBuffer), 2482 PREF(pLcmlHdr->pBufHdr,nFilledLen), 2483 PERF_ModuleCommonLayer); 2484 2485 pComponentPrivate->nLcml_nCntOpReceived++; 2486 2487 if ((pComponentPrivate->nLcml_nCntIp >= 1) && (pComponentPrivate->nLcml_nCntOpReceived == 1)) { 2488 PERF_Boundary(pComponentPrivate->pPERFcomp, 2489 PERF_BoundaryStart | PERF_BoundarySteadyState); 2490 } 2491#endif 2492 MP3DEC_ClearPending(pComponentPrivate,pLcmlHdr->pBufHdr,OMX_DirOutput,__LINE__); 2493 2494 if (pComponentPrivate->pMarkData) { 2495 pLcmlHdr->pBufHdr->pMarkData = pComponentPrivate->pMarkData; 2496 pLcmlHdr->pBufHdr->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent; 2497 } 2498 pComponentPrivate->num_Reclaimed_Op_Buff++; 2499 2500 if (pLcmlHdr->pOpParam->ulIsLastBuffer){ 2501 OMX_PRBUFFER2(pComponentPrivate->dbg, "Adding EOS flag to the output buffer\n"); 2502 pLcmlHdr->pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS; 2503 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2504 pComponentPrivate->pHandle->pApplicationPrivate, 2505 OMX_EventBufferFlag, 2506 pLcmlHdr->pBufHdr->nOutputPortIndex, 2507 pLcmlHdr->pBufHdr->nFlags, NULL); 2508 pComponentPrivate->bIsEOFSent = 0; 2509 pLcmlHdr->pOpParam->ulIsLastBuffer=0; 2510 } 2511 2512 if(pComponentPrivate->frameMode){ 2513 /* Copying time stamp information to output buffer */ 2514 pLcmlHdr->pBufHdr->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->OpBufindex]; 2515 }else{ 2516 if(pComponentPrivate->first_buff == 1){ 2517 pComponentPrivate->first_buff = 2; 2518 pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->first_TS; 2519 pComponentPrivate->temp_TS = pLcmlHdr->pBufHdr->nTimeStamp; 2520 OMX_PRBUFFER2(pComponentPrivate->dbg, "first_ts = %lld\n", 2521 pComponentPrivate->temp_TS); 2522 }else{ 2523 time_stmp = pLcmlHdr->pBufHdr->nFilledLen / (pComponentPrivate->pcmParams->nChannels * 2524 (pComponentPrivate->pcmParams->nBitPerSample / 8)); 2525 time_stmp = (time_stmp / pComponentPrivate->pcmParams->nSamplingRate) * 1000000; 2526 /* Update time stamp information */ 2527 pComponentPrivate->temp_TS += time_stmp; 2528 pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->temp_TS; 2529 OMX_PRBUFFER2(pComponentPrivate->dbg, "out ts = %lld\n", 2530 pComponentPrivate->temp_TS); 2531 } 2532 } 2533 /*add on: Copyint tick count information to output buffer*/ 2534 pLcmlHdr->pBufHdr->nTickCount = (OMX_U32)pComponentPrivate->arrBufIndexTick[pComponentPrivate->OpBufindex]; 2535 pComponentPrivate->OpBufindex++; 2536 pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OMX_DirInput]->nBufferCountActual; 2537 2538 2539#ifdef __PERF_INSTRUMENTATION__ 2540 PERF_SendingBuffer(pComponentPrivate->pPERFcomp, 2541 pLcmlHdr->pBufHdr->pBuffer, 2542 pLcmlHdr->pBufHdr->nFilledLen, 2543 PERF_ModuleHLMM); 2544#endif 2545 2546 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 2547 pComponentPrivate->pHandle->pApplicationPrivate, 2548 pLcmlHdr->pBufHdr); 2549 pComponentPrivate->lcml_nOpBuf--; 2550 pComponentPrivate->app_nBuf++; 2551 pComponentPrivate->nFillBufferDoneCount++; 2552 SignalIfAllBuffersAreReturned(pComponentPrivate); 2553 } 2554 } 2555 }else if(event == EMMCodecProcessingStoped) { 2556 for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) { 2557 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 2558 pComponentPrivate->pHandle->pApplicationPrivate, 2559 pComponentPrivate->pInputBufHdrPending[i]); 2560 pComponentPrivate->nEmptyBufferDoneCount++; 2561 pComponentPrivate->pInputBufHdrPending[i] = NULL; 2562 SignalIfAllBuffersAreReturned(pComponentPrivate); 2563 } 2564 pComponentPrivate->nNumInputBufPending = 0; 2565 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 2566 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 2567 pComponentPrivate->pHandle->pApplicationPrivate, 2568 pComponentPrivate->pOutputBufHdrPending[i] 2569 ); 2570 pComponentPrivate->nFillBufferDoneCount++; 2571 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 2572 SignalIfAllBuffersAreReturned(pComponentPrivate); 2573 } 2574 pComponentPrivate->nNumOutputBufPending=0; 2575 2576 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex); 2577 if(pComponentPrivate->codecStop_waitingsignal == 0){ 2578 pComponentPrivate->codecStop_waitingsignal = 1; 2579 pthread_cond_signal(&pComponentPrivate->codecStop_threshold); 2580 OMX_ERROR4(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n"); 2581 } 2582 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex); 2583 if (!pComponentPrivate->bNoIdleOnStop) { 2584 pComponentPrivate->curState = OMX_StateIdle; 2585 2586#ifdef RESOURCE_MANAGER_ENABLED 2587 rm_error = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 2588 RMProxy_StateSet, 2589 OMX_MP3_Decoder_COMPONENT, 2590 OMX_StateIdle, 2591 3456, 2592 NULL); 2593#endif 2594 if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) { 2595 if(pthread_mutex_lock(&bufferReturned_mutex) != 0) 2596 { 2597 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex lock error\n",__LINE__); 2598 } 2599 OMX_PRINT2(pComponentPrivate->dbg, ":: pthread_cond_waiting for OMX to return all input and outbut buffers\n"); 2600 pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex); 2601 OMX_PRINT2(pComponentPrivate->dbg, ":: OMX has returned all input and output buffers\n"); 2602 if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 2603 { 2604 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex unlock error\n",__LINE__); 2605 } 2606 } 2607 else 2608 { 2609 OMX_PRINT2(pComponentPrivate->dbg, ":: OMX has returned all input and output buffers\n"); 2610 } 2611 if(pComponentPrivate->bPreempted==0){ 2612 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2613 pComponentPrivate->pHandle->pApplicationPrivate, 2614 OMX_EventCmdComplete, 2615 OMX_CommandStateSet, 2616 pComponentPrivate->curState, 2617 NULL); 2618 }else{ 2619 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2620 pComponentPrivate->pHandle->pApplicationPrivate, 2621 OMX_EventError, 2622 OMX_ErrorResourcesPreempted, 2623 OMX_TI_ErrorMajor, 2624 NULL); 2625 } 2626 }else{ 2627 pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE; 2628 pComponentPrivate->bNoIdleOnStop = OMX_FALSE; 2629 } 2630 } 2631 else if(event == EMMCodecAlgCtrlAck) { 2632 OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n"); 2633 } 2634 else if (event == EMMCodecDspError) { 2635 2636 OMX_PRDSP1(pComponentPrivate->dbg, ":: commandedState = %p\n",args[0]); 2637 OMX_PRINT2(pComponentPrivate->dbg, ":: arg4 = %p\n",args[4]); 2638 OMX_PRINT2(pComponentPrivate->dbg, ":: arg5 = %p\n",args[5]); 2639 switch ( (OMX_U32) args [4]) 2640 { 2641 /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully. 2642 * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message. 2643 * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message. 2644 * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error. 2645 * USN_ERR_STOP,: Indicates that execution of stop resulted in error. 2646 * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error. 2647 * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error. 2648 * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */ 2649 2650#ifdef _ERROR_PROPAGATION__ 2651 case USN_ERR_PAUSE: 2652 case USN_ERR_STOP: 2653 case USN_ERR_ALGCTRL: 2654 case USN_ERR_STRMCTRL: 2655 case USN_ERR_UNKNOWN_MSG: 2656 { 2657 pComponentPrivate->bIsInvalidState=OMX_TRUE; 2658 pComponentPrivate->curState = OMX_StateInvalid; 2659 pHandle = pComponentPrivate->pHandle; 2660 pComponentPrivate->cbInfo.EventHandler(pHandle, 2661 pHandle->pApplicationPrivate, 2662 OMX_EventError, 2663 OMX_ErrorInvalidState, 2664 OMX_TI_ErrorSevere, 2665 NULL); 2666 } 2667 break; 2668#endif 2669 2670 case USN_ERR_WARNING: 2671 case USN_ERR_PROCESS: 2672 MP3DEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]); 2673 break; 2674 default: 2675 break; 2676 } 2677 } else if (event == EMMCodecStrmCtrlAck) { 2678 2679 2680 OMX_PRDSP2(pComponentPrivate->dbg, ":: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n"); 2681 if (args[1] == (void *)USN_STRMCMD_FLUSH) { 2682 pHandle = pComponentPrivate->pHandle; 2683 if ( args[2] == (void *)EMMCodecInputBuffer) { 2684 if (args[0] == (void *)USN_ERR_NONE ) { 2685 OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing input port %d\n",__LINE__); 2686 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 2687#ifdef __PERF_INSTRUMENTATION__ 2688 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2689 PREF(pComponentPrivate->pInputBufHdrPending[i],pBuffer), 2690 0, 2691 PERF_ModuleHLMM); 2692#endif 2693 2694 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 2695 pComponentPrivate->pHandle->pApplicationPrivate, 2696 pComponentPrivate->pInputBufHdrPending[i]); 2697 pComponentPrivate->nEmptyBufferDoneCount++; 2698 pComponentPrivate->pInputBufHdrPending[i] = NULL; 2699 SignalIfAllBuffersAreReturned(pComponentPrivate); 2700 } 2701 pComponentPrivate->nNumInputBufPending=0; 2702 2703 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex); 2704 if(pComponentPrivate->codecFlush_waitingsignal == 0){ 2705 pComponentPrivate->codecFlush_waitingsignal = 1; 2706 pthread_cond_signal(&pComponentPrivate->codecFlush_threshold); 2707 OMX_ERROR4(pComponentPrivate->dbg, "flush ack. received. for input port\n"); 2708 } 2709 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex); 2710 2711 pComponentPrivate->cbInfo.EventHandler(pHandle, 2712 pHandle->pApplicationPrivate, 2713 OMX_EventCmdComplete, 2714 OMX_CommandFlush, 2715 MP3D_INPUT_PORT, 2716 NULL); 2717 } else { 2718 OMX_ERROR4(pComponentPrivate->dbg, "LCML reported error while flushing input port\n"); 2719 goto EXIT; 2720 } 2721 } 2722 else if ( args[2] == (void *)EMMCodecOuputBuffer) { 2723 2724 2725 2726 if (args[0] == (void *)USN_ERR_NONE ) { 2727 OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port %d\n",__LINE__); 2728 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 2729#ifdef __PERF_INSTRUMENTATION__ 2730 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2731 PREF(pComponentPrivate->pOutputBufHdrPending[i],pBuffer), 2732 PREF(pComponentPrivate->pOutputBufHdrPending[i],nFilledLen), 2733 PERF_ModuleHLMM); 2734#endif 2735 2736 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle, 2737 pComponentPrivate->pHandle->pApplicationPrivate, 2738 pComponentPrivate->pOutputBufHdrPending[i] 2739 ); 2740 pComponentPrivate->nFillBufferDoneCount++; 2741 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 2742 SignalIfAllBuffersAreReturned(pComponentPrivate); 2743 } 2744 pComponentPrivate->nNumOutputBufPending=0; 2745 2746 pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex); 2747 if(pComponentPrivate->codecFlush_waitingsignal == 0){ 2748 pComponentPrivate->codecFlush_waitingsignal = 1; 2749 pthread_cond_signal(&pComponentPrivate->codecFlush_threshold); 2750 OMX_ERROR4(pComponentPrivate->dbg, "flush ack. received. for output port\n"); 2751 } 2752 pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex); 2753 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2754 pComponentPrivate->pHandle->pApplicationPrivate, 2755 OMX_EventCmdComplete, 2756 OMX_CommandFlush, 2757 MP3D_OUTPUT_PORT, 2758 NULL); 2759 } else { 2760 OMX_ERROR4(pComponentPrivate->dbg, "LCML reported error while flushing output port\n"); 2761 goto EXIT; 2762 } 2763 } 2764 } 2765 } 2766 else if (event == EMMCodecProcessingPaused) { 2767 2768 pComponentPrivate->curState = OMX_StatePause; 2769 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2770 pComponentPrivate->pHandle->pApplicationPrivate, 2771 OMX_EventCmdComplete, OMX_CommandStateSet, 2772 pComponentPrivate->curState, NULL); 2773 } 2774#ifdef _ERROR_PROPAGATION__ 2775 else if (event == EMMCodecInitError){ 2776 2777 2778 /* Cheking for MMU_fault */ 2779 if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) { 2780 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__); 2781 pComponentPrivate->bIsInvalidState = OMX_TRUE; 2782 pComponentPrivate->curState = OMX_StateInvalid; 2783 pHandle = pComponentPrivate->pHandle; 2784 pComponentPrivate->cbInfo.EventHandler(pHandle, 2785 pHandle->pApplicationPrivate, 2786 OMX_EventError, 2787 OMX_ErrorHardware, 2788 OMX_TI_ErrorSevere, 2789 NULL); 2790 } 2791 } 2792 else if (event == EMMCodecInternalError){ 2793 2794 2795 2796 /* Cheking for MMU_fault */ 2797 if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) { 2798 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__); 2799 pComponentPrivate->bIsInvalidState = OMX_TRUE; 2800 pComponentPrivate->curState = OMX_StateInvalid; 2801 pHandle = pComponentPrivate->pHandle; 2802 pComponentPrivate->cbInfo.EventHandler(pHandle, 2803 pHandle->pApplicationPrivate, 2804 OMX_EventError, 2805 OMX_ErrorHardware, 2806 OMX_TI_ErrorSevere, 2807 NULL); 2808 } 2809 2810 } 2811#endif 2812 EXIT: 2813 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting the LCML_Callback() \n"); 2814 2815 return eError; 2816} 2817 2818 2819/* ================================================================================= * */ 2820/** 2821 * @fn MP3DEC_GetCorresponding_LCMLHeader() function gets the corresponding LCML 2822 * header from the actual data buffer for required processing. 2823 * 2824 * @param *pBuffer This is the data buffer pointer. 2825 * 2826 * @param eDir This is direction of buffer. Input/Output. 2827 * 2828 * @param *MP3D_LCML_BUFHEADERTYPE This is pointer to LCML Buffer Header. 2829 * 2830 * @pre None 2831 * 2832 * @post None 2833 * 2834 * @return OMX_ErrorNone = Successful Inirialization of the component\n 2835 * OMX_ErrorHardware = Hardware error has occured. 2836 * 2837 * @see None 2838 */ 2839/* ================================================================================ * */ 2840OMX_ERRORTYPE MP3DEC_GetCorresponding_LCMLHeader(MP3DEC_COMPONENT_PRIVATE* pComponentPrivate, 2841 OMX_U8 *pBuffer, 2842 OMX_DIRTYPE eDir, 2843 MP3D_LCML_BUFHEADERTYPE **ppLcmlHdr) 2844{ 2845 OMX_ERRORTYPE eError = OMX_ErrorNone; 2846 MP3D_LCML_BUFHEADERTYPE *pLcmlBufHeader; 2847 int nIpBuf=0, nOpBuf=0, i=0; 2848 2849 OMX_PRINT1(pComponentPrivate->dbg, ":: Entering the MP3DEC_GetCorresponding_LCMLHeader()\n"); 2850 2851 OMX_PRINT2(pComponentPrivate->dbg, ":: eDir = %d\n",eDir); 2852 2853 while (!pComponentPrivate->bInitParamsInitialized) { 2854#ifndef UNDER_CE 2855 sched_yield(); 2856#else 2857 Sleep(0); 2858#endif 2859 } 2860 2861 2862 if(eDir == OMX_DirInput) { 2863 OMX_PRDSP2(pComponentPrivate->dbg, ":: In GetCorresponding_LCMLHeader()\n"); 2864 2865 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 2866 2867 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]; 2868 2869 for(i=0; i<nIpBuf; i++) { 2870 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 2871 OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->pBufHdr->pBuffer = %p\n",pLcmlBufHeader->pBufHdr->pBuffer); 2872 if(pBuffer == pLcmlBufHeader->pBufHdr->pBuffer) { 2873 *ppLcmlHdr = pLcmlBufHeader; 2874 OMX_PRINT1(pComponentPrivate->dbg, "::Corresponding LCML Header Found\n"); 2875 goto EXIT; 2876 } 2877 pLcmlBufHeader++; 2878 } 2879 } else if (eDir == OMX_DirOutput) { 2880 i = 0; 2881 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 2882 2883 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]; 2884 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: nOpBuf = %d\n",nOpBuf); 2885 2886 for(i=0; i<nOpBuf; i++) { 2887 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 2888 OMX_PRBUFFER2(pComponentPrivate->dbg, "pLcmlBufHeader->pBufHdr->pBuffer = %p\n",pLcmlBufHeader->pBufHdr->pBuffer); 2889 2890 if(pBuffer == pLcmlBufHeader->pBufHdr->pBuffer) { 2891 *ppLcmlHdr = pLcmlBufHeader; 2892 OMX_PRINT1(pComponentPrivate->dbg, "::Corresponding LCML Header Found\n"); 2893 goto EXIT; 2894 } 2895 pLcmlBufHeader++; 2896 } 2897 } else { 2898 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Invalid Buffer Type :: exiting...\n"); 2899 } 2900 2901 EXIT: 2902 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting the GetCorresponding_LCMLHeader() \n"); 2903 return eError; 2904} 2905 2906/* ================================================================================= * */ 2907/** 2908 * @fn MP3DEC_GetLCMLHandle() function gets the LCML handle and interacts with LCML 2909 * by using this LCML Handle. 2910 * 2911 * @param *pBufHeader This is the buffer header that needs to be processed. 2912 * 2913 * @param *pComponentPrivate This is component's private date structure. 2914 * 2915 * @pre None 2916 * 2917 * @post None 2918 * 2919 * @return OMX_HANDLETYPE = Successful loading of LCML library. 2920 * OMX_ErrorHardware = Hardware error has occured. 2921 * 2922 * @see None 2923 */ 2924/* ================================================================================ * */ 2925#ifndef UNDER_CE 2926OMX_HANDLETYPE MP3DEC_GetLCMLHandle(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 2927{ 2928 /* This must be taken care by WinCE */ 2929 OMX_HANDLETYPE pHandle = NULL; 2930 OMX_ERRORTYPE eError; 2931 void *handle; 2932 OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE); 2933 char *error; 2934 2935 handle = dlopen("libLCML.so", RTLD_LAZY); 2936 if (!handle) { 2937 fputs(dlerror(), stderr); 2938 goto EXIT; 2939 } 2940 2941 fpGetHandle = dlsym (handle, "GetHandle"); 2942 if ((error = dlerror()) != NULL) { 2943 fputs(error, stderr); 2944 goto EXIT; 2945 } 2946 eError = (*fpGetHandle)(&pHandle); 2947 if(eError != OMX_ErrorNone) { 2948 eError = OMX_ErrorUndefined; 2949 OMXDBG_PRINT(stderr, ERROR, 4, 0, "eError != OMX_ErrorNone...\n"); 2950 pHandle = NULL; 2951 goto EXIT; 2952 } 2953 2954 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate; 2955 2956 EXIT: 2957 return pHandle; 2958} 2959#else 2960/* WINDOWS Explicit dll load procedure */ 2961OMX_HANDLETYPE MP3DEC_GetLCMLHandle(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 2962{ 2963 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE); 2964 OMX_HANDLETYPE pHandle = NULL; 2965 OMX_ERRORTYPE eError; 2966 LPFNDLLFUNC1 fpGetHandle1; 2967 2968 g_hLcmlDllHandle = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0); 2969 if (g_hLcmlDllHandle == NULL) 2970 { 2971 /* fputs(dlerror(), stderr); */ 2972 OMXDBG_PRINT(stderr, ERROR, 4, 0, "BML Load Failed!!!\n"); 2973 return pHandle; 2974 } 2975 fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(g_hLcmlDllHandle,TEXT("GetHandle")); 2976 if (!fpGetHandle1) 2977 { 2978 /* handle the error*/ 2979 FreeLibrary(g_hLcmlDllHandle); 2980 g_hLcmlDllHandle = NULL; 2981 return pHandle; 2982 } 2983 /* call the function */ 2984 eError = fpGetHandle1(&pHandle); 2985 if(eError != OMX_ErrorNone) 2986 { 2987 eError = OMX_ErrorUndefined; 2988 OMXDBG_PRINT(stderr, ERROR, 4, 0, "eError != OMX_ErrorNone...\n"); 2989 FreeLibrary(g_hLcmlDllHandle); 2990 g_hLcmlDllHandle = NULL; 2991 pHandle = NULL; 2992 return pHandle; 2993 } 2994 2995 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate; 2996 2997 return pHandle; 2998} 2999#endif 3000 3001#ifndef UNDER_CE 3002OMX_ERRORTYPE MP3DECFreeLCMLHandle(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 3003{ 3004 3005 OMX_S16 retValue; 3006 OMX_ERRORTYPE eError = OMX_ErrorNone; 3007 3008 if (pComponentPrivate->bLcmlHandleOpened) { 3009 retValue = dlclose(pComponentPrivate->pLcmlHandle); 3010 3011 if (retValue != 0) { 3012 eError = OMX_ErrorUndefined; 3013 } 3014 pComponentPrivate->bLcmlHandleOpened = 0; 3015 } 3016 3017 return eError; 3018} 3019#else 3020OMX_ERRORTYPE MP3DECFreeLCMLHandle(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 3021{ 3022 3023 OMX_S16 retValue; 3024 OMX_ERRORTYPE eError = OMX_ErrorNone; 3025 3026 if (pComponentPrivate->bLcmlHandleOpened) { 3027 3028 retValue = FreeLibrary(pComponentPrivate->pLcmlHandle); 3029 if (retValue == 0) { /* Zero Indicates failure */ 3030 eError = OMX_ErrorUndefined; 3031 } 3032 pComponentPrivate->bLcmlHandleOpened = 0; 3033 } 3034 3035 return eError; 3036} 3037#endif 3038 3039/* ========================================================================== */ 3040/** 3041 * @MP3DEC_CleanupInitParams() This function is called by the component during 3042 * de-init to close component thread, Command pipe, data pipe & LCML pipe. 3043 * 3044 * @param pComponent handle for this instance of the component 3045 * 3046 * @pre 3047 * 3048 * @post 3049 * 3050 * @return none 3051 */ 3052/* ========================================================================== */ 3053 3054void MP3DEC_CleanupInitParams(OMX_HANDLETYPE pComponent) 3055{ 3056 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 3057 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *) 3058 pHandle->pComponentPrivate; 3059 MP3D_LCML_BUFHEADERTYPE *pTemp_lcml; 3060 3061 OMX_U32 nIpBuf = pComponentPrivate->nRuntimeInputBuffers; 3062 OMX_U32 nOpBuf = pComponentPrivate->nRuntimeOutputBuffers; 3063 3064 OMX_U32 i=0; 3065 3066 OMX_PRINT1(pComponentPrivate->dbg, ":: MP3DEC_CleanupInitParams()\n"); 3067 3068 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pComponentPrivate->strmAttr = %p\n", pComponentPrivate->strmAttr); 3069 OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr); 3070 3071 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]; 3072 3073 for(i=0; i<nIpBuf; i++) { 3074 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pIpParam = %p\n",pTemp_lcml->pIpParam); 3075 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, MP3DEC_UAlgInBufParamStruct); 3076 3077 pTemp_lcml++; 3078 } 3079 3080 3081 3082 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = %p\n", 3083 pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]); 3084 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]); 3085 3086 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]; 3087 for(i=0; i<nOpBuf; i++) { 3088 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pOpParam = %p\n",pTemp_lcml->pOpParam); 3089 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, MP3DEC_UAlgOutBufParamStruct); 3090 pTemp_lcml++; 3091 } 3092 3093 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = %p\n", 3094 pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]); 3095 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]); 3096 3097 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, USN_AudioCodecParams); 3098 3099 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->ptAlgDynParams, MP3DEC_UALGParams); 3100 3101 OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully MP3DEC_CleanupInitParams()\n"); 3102 3103} 3104 3105/* ========================================================================== */ 3106/** 3107* @MP3DEC_CleanupInitParamsEx() This function is called by the component during 3108* portreconfiguration after port disable to free LCML buffers. 3109* 3110* @param pComponent handle for this instance of the component 3111* 3112* @pre 3113* 3114* @post 3115* 3116* @return none 3117*/ 3118/* ========================================================================== */ 3119 3120void MP3DEC_CleanupInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport) 3121{ 3122 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 3123 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = 3124 (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 3125 MP3D_LCML_BUFHEADERTYPE *pTemp_lcml; 3126 OMX_U32 nIpBuf = 0; 3127 OMX_U32 nOpBuf = 0; 3128 OMX_U32 i=0; 3129 3130 if(indexport == 0 || indexport == -1){ 3131 nIpBuf = pComponentPrivate->nRuntimeInputBuffers; 3132 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]; 3133 for(i=0; i<nIpBuf; i++) { 3134 OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pIpParam = %p\n", 3135 pTemp_lcml->pIpParam); 3136 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, MP3DEC_UAlgInBufParamStruct); 3137 pTemp_lcml++; 3138 } 3139 3140 OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing pLcmlBufHeader[MP3D_INPUT_PORT] = %p\n", 3141 pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]); 3142 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]); 3143 3144 }else if(indexport == 1 || indexport == -1){ 3145 nOpBuf = pComponentPrivate->nRuntimeOutputBuffers; 3146 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]; 3147 for(i=0; i<nOpBuf; i++) { 3148 OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pOpParam = %p\n", 3149 pTemp_lcml->pOpParam); 3150 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, MP3DEC_UAlgOutBufParamStruct); 3151 pTemp_lcml++; 3152 } 3153 3154 OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pLcmlBufHeader[MP3D_OUTPUT_PORT] = %p\n", 3155 pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]); 3156 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]); 3157 3158 }else{ 3159 OMX_ERROR4(pComponentPrivate->dbg, "Bad indexport!\n"); 3160 } 3161} 3162 3163/* ========================================================================== */ 3164/** 3165 * @MP3DEC_SetPending() This function marks the buffer as pending when it is sent 3166 * to DSP/ 3167 * 3168 * @param pComponentPrivate This is component's private date area. 3169 * 3170 * @param pBufHdr This is poiter to OMX Buffer header whose buffer is sent to DSP 3171 * 3172 * @param eDir This is direction of buffer i.e. input or output. 3173 * 3174 * @pre None 3175 * 3176 * @post None 3177 * 3178 * @return none 3179 */ 3180/* ========================================================================== */ 3181void MP3DEC_SetPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) 3182{ 3183 OMX_U16 i; 3184 3185 if (eDir == OMX_DirInput) { 3186 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 3187 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 3188 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1; 3189 OMX_PRBUFFER2(pComponentPrivate->dbg, "INPUT BUFFER %d IS PENDING Line %ld\n",i,lineNumber); 3190 } 3191 } 3192 } 3193 else { 3194 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 3195 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 3196 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1; 3197 OMX_PRBUFFER2(pComponentPrivate->dbg, "OUTPUT BUFFER %d IS PENDING Line %ld\n",i,lineNumber); 3198 } 3199 } 3200 } 3201} 3202 3203/* ========================================================================== */ 3204/** 3205 * @MP3DEC_ClearPending() This function clears the buffer status from pending 3206 * when it is received back from DSP. 3207 * 3208 * @param pComponentPrivate This is component's private date area. 3209 * 3210 * @param pBufHdr This is poiter to OMX Buffer header that is received from 3211 * DSP/LCML. 3212 * 3213 * @param eDir This is direction of buffer i.e. input or output. 3214 * 3215 * @pre None 3216 * 3217 * @post None 3218 * 3219 * @return none 3220 */ 3221/* ========================================================================== */ 3222 3223void MP3DEC_ClearPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) 3224{ 3225 OMX_U16 i; 3226 3227 if (eDir == OMX_DirInput) { 3228 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 3229 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 3230 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0; 3231 OMX_PRBUFFER2(pComponentPrivate->dbg, "INPUT BUFFER %d IS RECLAIMED Line %ld\n",i,lineNumber); 3232 } 3233 } 3234 } 3235 else { 3236 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 3237 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 3238 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0; 3239 OMX_PRBUFFER2(pComponentPrivate->dbg, "OUTPUT BUFFER %d IS RECLAIMED Line %ld\n",i,lineNumber); 3240 } 3241 } 3242 } 3243} 3244 3245/* ========================================================================== */ 3246/** 3247 * @MP3DEC_IsPending() This function checks whether or not a buffer is pending. 3248 * 3249 * @param pComponentPrivate This is component's private date area. 3250 * 3251 * @param pBufHdr This is poiter to OMX Buffer header of interest. 3252 * 3253 * @param eDir This is direction of buffer i.e. input or output. 3254 * 3255 * @pre None 3256 * 3257 * @post None 3258 * 3259 * @return none 3260 */ 3261/* ========================================================================== */ 3262 3263OMX_U32 MP3DEC_IsPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) 3264{ 3265 OMX_U16 i; 3266 3267 if (eDir == OMX_DirInput) { 3268 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 3269 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 3270 return pComponentPrivate->pInputBufferList->bBufferPending[i]; 3271 } 3272 } 3273 } 3274 else { 3275 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 3276 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 3277 return pComponentPrivate->pOutputBufferList->bBufferPending[i]; 3278 } 3279 } 3280 } 3281 return -1; 3282} 3283 3284 3285/* ========================================================================== */ 3286/** 3287 * @MP3DEC_IsValid() This function identifies whether or not buffer recieved from 3288 * LCML is valid. It searches in the list of input/output buffers to do this. 3289 * 3290 * @param pComponentPrivate This is component's private date area. 3291 * 3292 * @param pBufHdr This is poiter to OMX Buffer header of interest. 3293 * 3294 * @param eDir This is direction of buffer i.e. input or output. 3295 * 3296 * @pre None 3297 * 3298 * @post None 3299 * 3300 * @return status of the buffer. 3301 */ 3302/* ========================================================================== */ 3303 3304OMX_U32 MP3DEC_IsValid(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) 3305{ 3306 OMX_U16 i; 3307 int found=0; 3308 3309 if (eDir == OMX_DirInput) { 3310 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 3311 if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) { 3312 found = 1; 3313 } 3314 } 3315 } 3316 else { 3317 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 3318 if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) { 3319 found = 1; 3320 } 3321 } 3322 } 3323 return found; 3324} 3325 3326/* ========================================================================== */ 3327/** 3328 * @MP3DECFill_LCMLInitParamsEx() This function initializes the init parameter of 3329 * the LCML structure when a port is enabled and component is in idle state. 3330 * 3331 * @param pComponent This is component handle. 3332 * 3333 * @pre None 3334 * 3335 * @post None 3336 * 3337 * @return appropriate OMX Error. 3338 */ 3339/* ========================================================================== */ 3340 3341OMX_ERRORTYPE MP3DECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent, OMX_U32 indexport) 3342 3343{ 3344 OMX_ERRORTYPE eError = OMX_ErrorNone; 3345 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize; 3346 OMX_U16 i; 3347 OMX_BUFFERHEADERTYPE *pTemp; 3348 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 3349 MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = 3350 (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 3351 MP3D_LCML_BUFHEADERTYPE *pTemp_lcml; 3352 OMX_U32 size_lcml; 3353 OMX_U8 *ptr; 3354 3355 OMX_PRINT1(pComponentPrivate->dbg, ":: Entered Fill_LCMLInitParams"); 3356 3357 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 3358 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 3359 nIpBufSize = pComponentPrivate->pPortDef[MP3D_INPUT_PORT]->nBufferSize; 3360 nOpBufSize = pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]->nBufferSize; 3361 3362 OMX_PRBUFFER2(pComponentPrivate->dbg, "Input Buffer Count = %ld\n",nIpBuf); 3363 OMX_PRBUFFER2(pComponentPrivate->dbg, "Input Buffer Size = %ld\n",nIpBufSize); 3364 OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Count = %ld\n",nOpBuf); 3365 OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Size = %ld\n",nOpBufSize); 3366 3367 if(indexport == 0 || indexport == -1){ 3368 3369 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: bufAlloced = %d\n",pComponentPrivate->bufAlloced); 3370 size_lcml = nIpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE); 3371 3372 OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8); 3373 pTemp_lcml = (MP3D_LCML_BUFHEADERTYPE *)ptr; 3374 3375 pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = pTemp_lcml; 3376 3377 for (i=0; i<nIpBuf; i++) { 3378 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 3379 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 3380 3381 pTemp->nAllocLen = nIpBufSize; 3382 pTemp->nFilledLen = nIpBufSize; 3383 pTemp->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER; 3384 pTemp->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER; 3385 3386 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 3387 pTemp->nTickCount = 0; 3388 3389 pTemp_lcml->pBufHdr = pTemp; 3390 pTemp_lcml->eDir = OMX_DirInput; 3391 pTemp_lcml->pOtherParams[i] = NULL; 3392 3393 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, 3394 sizeof(MP3DEC_UAlgInBufParamStruct), 3395 MP3DEC_UAlgInBufParamStruct); 3396 pTemp_lcml->pIpParam->bLastBuffer = 0; 3397 3398 pTemp->nFlags = NORMAL_BUFFER; 3399 ((MP3DEC_COMPONENT_PRIVATE *) pTemp->pPlatformPrivate)->pHandle = pHandle; 3400 3401 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: InBuffHeader[%d] = %p\n", i, pTemp); 3402 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>> InputBuffHeader[%d]->pBuffer = %p\n", i, pTemp->pBuffer); 3403 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: Ip : pTemp_lcml[%d] = %p\n", i, pTemp_lcml); 3404 3405 pTemp_lcml++; 3406 } 3407 } 3408 3409 if(indexport == 1 || indexport == -1){ 3410 size_lcml = nOpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE); 3411 OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE); 3412 pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = pTemp_lcml; 3413 3414 for (i=0; i<nOpBuf; i++) { 3415 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 3416 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 3417 pTemp->nAllocLen = nOpBufSize; 3418 pTemp->nFilledLen = nOpBufSize; 3419 pTemp->nVersion.s.nVersionMajor = MP3DEC_MAJOR_VER; 3420 pTemp->nVersion.s.nVersionMinor = MP3DEC_MINOR_VER; 3421 3422 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 3423 pTemp->nTickCount = 0; 3424 3425 pTemp_lcml->pBufHdr = pTemp; 3426 pTemp_lcml->eDir = OMX_DirOutput; 3427 pTemp_lcml->pOtherParams[i] = NULL; 3428 3429 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, 3430 sizeof(MP3DEC_UAlgOutBufParamStruct), 3431 MP3DEC_UAlgOutBufParamStruct); 3432 pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE; 3433 pTemp_lcml->pOpParam->ulIsLastBuffer = 0; 3434 3435 pTemp->nFlags = NORMAL_BUFFER; 3436 ((MP3DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle; 3437 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>>>>>>>>>>> OutBuffHeader[%d] = %p\n", i, pTemp); 3438 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: >>>> OutBuffHeader[%d]->pBuffer = %p\n", i, pTemp->pBuffer); 3439 OMX_PRBUFFER2(pComponentPrivate->dbg, "::Comp: Op : pTemp_lcml[%d] = %p\n", i, pTemp_lcml); 3440 pTemp_lcml++; 3441 } 3442 } 3443 pComponentPrivate->bPortDefsAllocated = 1; 3444 3445 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting Fill_LCMLInitParams"); 3446 3447 pComponentPrivate->bInitParamsInitialized = 1; 3448 3449 EXIT: 3450 return eError; 3451} 3452 3453 3454OMX_U32 MP3DEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition) 3455{ 3456 OMX_U32 nOutput; 3457 OMX_U32 nNumBitsRead = 0; 3458 OMX_U32 nBytePosition = 0; 3459 OMX_U8 nBitPosition = 0; 3460 nBytePosition = *nPosition / 8; 3461 nBitPosition = *nPosition % 8; 3462 3463 if (bIcreasePosition) 3464 *nPosition += nBits; 3465 nOutput = ((OMX_U32)pBuffer[nBytePosition] << (24+nBitPosition) ); 3466 nNumBitsRead = nNumBitsRead + (8 - nBitPosition); 3467 if (nNumBitsRead < nBits) 3468 { 3469 nOutput = nOutput | ( pBuffer[nBytePosition + 1] << (16+nBitPosition)); 3470 nNumBitsRead = nNumBitsRead + 8; 3471 } 3472 if (nNumBitsRead < nBits) 3473 { 3474 nOutput = nOutput | ( pBuffer[nBytePosition + 2] << (8+nBitPosition)); 3475 nNumBitsRead = nNumBitsRead + 8; 3476 } 3477 if (nNumBitsRead < nBits) 3478 { 3479 nOutput = nOutput | ( pBuffer[nBytePosition + 3] << (nBitPosition)); 3480 nNumBitsRead = nNumBitsRead + 8; 3481 } 3482 nOutput = nOutput >> (32 - nBits) ; 3483 return nOutput; 3484} 3485 3486/* ========================================================================== */ 3487/** 3488* @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app 3489* 3490* @param AACDEC_COMPONENT_PRIVATE *pComponentPrivate 3491* 3492* @pre None 3493* 3494* @post None 3495* 3496* @return None 3497*/ 3498/* ========================================================================== */ 3499void SignalIfAllBuffersAreReturned(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate) 3500{ 3501 if((pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nEmptyBufferDoneCount) && (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nFillBufferDoneCount)) 3502 { 3503 if(pthread_mutex_lock(&bufferReturned_mutex) != 0) 3504 { 3505 OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex lock error\n",__LINE__); 3506 } 3507 pthread_cond_broadcast(&bufferReturned_condition); 3508 OMX_PRINT2(pComponentPrivate->dbg, ":: Sending pthread signal that OMX has returned all buffers to app\n"); 3509 if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 3510 { 3511 OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__); 3512 } 3513 return; 3514 } 3515} 3516 3517/* =========================================================================*/ 3518/* func MP3DEC_HandleUSNError 3519/* 3520/* desc Handles error messages returned by the dsp 3521/* 3522/*@return n/a 3523/* 3524/* =========================================================================*/ 3525void MP3DEC_HandleUSNError (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg) 3526{ 3527 OMX_COMPONENTTYPE *pHandle = NULL; 3528 OMX_U8 pending_buffers = OMX_FALSE; 3529 OMX_U32 i; 3530 switch (arg) 3531 { 3532 case IUALG_WARN_CONCEALED: 3533 case IUALG_WARN_UNDERFLOW: 3534 case IUALG_WARN_OVERFLOW: 3535 case IUALG_WARN_ENDOFDATA: 3536 OMX_ERROR4(pComponentPrivate->dbg, "Algorithm Error" ); 3537 /* all of these are informative messages, Algo can recover, no need to notify the 3538 * IL Client at this stage of the implementation */ 3539 break; 3540 case IUALG_WARN_PLAYCOMPLETED: 3541 3542 { 3543 OMX_ERROR4(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED!\n"); 3544#ifndef UNDER_CE 3545 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3546 pComponentPrivate->pHandle->pApplicationPrivate, 3547 OMX_EventBufferFlag, 3548 OMX_DirOutput, 3549 OMX_BUFFERFLAG_EOS, 3550 NULL); 3551 if(pComponentPrivate->dasfmode){ 3552 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3553 pComponentPrivate->pHandle->pApplicationPrivate, 3554 OMX_EventBufferFlag, 3555 (OMX_U32)NULL, 3556 OMX_BUFFERFLAG_EOS, 3557 NULL); 3558 } 3559 pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0; 3560#else 3561 /* add callback to application to indicate SN/USN has completed playing of current set of date */ 3562 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3563 pComponentPrivate->pHandle->pApplicationPrivate, 3564 OMX_EventBufferFlag, 3565 (OMX_U32)NULL, 3566 OMX_BUFFERFLAG_EOS, 3567 NULL); 3568#endif 3569 } 3570 break; 3571 3572#ifdef _ERROR_PROPAGATION__ 3573 case IUALG_ERR_BAD_HANDLE: 3574 case IUALG_ERR_DATA_CORRUPT: 3575 case IUALG_ERR_NOT_SUPPORTED: 3576 case IUALG_ERR_ARGUMENT: 3577 case IUALG_ERR_NOT_READY: 3578 case IUALG_ERR_GENERAL: 3579 3580 { 3581 /* all of these are fatal messages, Algo can not recover 3582 * hence return an error */ 3583 OMX_ERROR4(pComponentPrivate->dbg, "Algorithm Error, cannot recover" ); 3584 pComponentPrivate->bIsInvalidState=OMX_TRUE; 3585 pComponentPrivate->curState = OMX_StateInvalid; 3586 pHandle = pComponentPrivate->pHandle; 3587 pComponentPrivate->cbInfo.EventHandler(pHandle, 3588 pHandle->pApplicationPrivate, 3589 OMX_EventError, 3590 OMX_ErrorInvalidState, 3591 OMX_TI_ErrorSevere, 3592 NULL); 3593 } 3594 break; 3595#endif 3596 default: 3597 break; 3598 } 3599} 3600 3601#ifdef RESOURCE_MANAGER_ENABLED 3602void MP3_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData) 3603{ 3604 OMX_COMMANDTYPE Cmd = OMX_CommandStateSet; 3605 OMX_STATETYPE state = OMX_StateIdle; 3606 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent; 3607 MP3DEC_COMPONENT_PRIVATE *pCompPrivate = NULL; 3608 3609 pCompPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 3610 3611 if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) { 3612 if (pCompPrivate->curState == OMX_StateExecuting || 3613 pCompPrivate->curState == OMX_StatePause) { 3614 write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 3615 write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32)); 3616 pCompPrivate->bPreempted = 1; 3617 } 3618 } 3619 else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){ 3620 pCompPrivate->cbInfo.EventHandler (pHandle, 3621 pHandle->pApplicationPrivate, 3622 OMX_EventResourcesAcquired, 0,0, 3623 NULL); 3624 } 3625} 3626#endif 3627