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