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_G729Dec_Utils.c 30 * 31 * This file implements OMX Component for G729 decoder that 32 * is fully compliant with the OMX Audio specification . 33 * 34 * @path $(OMAPSW_MPU)\linux\audio\src\openmax_il\g729_dec\src 35 * 36 * @rev 0.5 37 */ 38 /* ----------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! Date Author(s) Version Description 43 *! --------- ------------------- ------- --------------------------------- 44 *! 03-Jan-2007 A.Donjon 0.1 Code update for G729 DECODER 45 *! 16-Feb-2007 A.Donjon 0.2 Frame Lost 46 *! Input buffer size used for buffer check in SN 47 *! 01-Mar-2007 A.Donjon 0.3 RM, DVFS changes 48 *! 08-Jun-2007 A.Donjon 0.4 Variable input buffer size 49 *! 04-Jul-2007 A.Donjon 0.5 Last output frame reset for repeated play wo deleting component 50 *! 51 *! 52 * ================================================================================= */ 53 54 /* ------compilation control switches -------------------------*/ 55 56 /**************************************************************** 57 * INCLUDE FILES 58 ****************************************************************/ 59 /* ----- system and platform files ----------------------------*/ 60 #ifdef UNDER_CE 61 #include <windows.h> 62 #include <oaf_osal.h> 63 #include <omx_core.h> 64 #include <stdlib.h> 65 #else 66 #include <unistd.h> 67 #include <sys/types.h> 68 #include <sys/types.h> 69 #include <sys/stat.h> 70 #include <dlfcn.h> 71 #include <malloc.h> 72 #include <memory.h> 73 #include <fcntl.h> 74 #include <errno.h> 75 #include <dlfcn.h> 76 #endif 77 #include <dbapi.h> 78 #include <string.h> 79 #include <stdio.h> 80 /*-------program files ----------------------------------------*/ 81 #include "OMX_G729Decoder.h" 82 #include "OMX_G729Dec_Utils.h" 83 #include "g729decsocket_ti.h" 84 #include "decode_common_ti.h" 85 #include "OMX_G729Dec_ComponentThread.h" 86 #include "usn.h" 87 #ifdef __PERF_INSTRUMENTATION__ 88 #include "perf.h" 89 #endif 90 91 /* ======================================================================= */ 92 /** 93 * @def DASF Defines the value for identify DASF ON 94 */ 95 /* ======================================================================= */ 96 #define DASF 1 97 98 #ifdef UNDER_CE 99 #define HASHINGENABLE 1 100 HINSTANCE g_hLcmlDllHandle = NULL; 101 102 #endif 103 104 static G729DEC_COMPONENT_PRIVATE *pComponentPrivate_CC; 105 /* ========================================================================== */ 106 /** 107 * @G729DECFill_LCMLInitParams () This function is used by the component thread to 108 * fill the all of its initialization parameters, buffer deatils etc 109 * to LCML structure, 110 * 111 * @param pComponent handle for this instance of the component 112 * @param plcml_Init pointer to LCML structure to be filled 113 * 114 * @pre 115 * 116 * @post 117 * 118 * @return none 119 */ 120 /* ========================================================================== */ 121 122 OMX_ERRORTYPE G729DECFill_LCMLInitParams(OMX_HANDLETYPE pComponent, 123 LCML_DSP *plcml_Init, OMX_U16 arr[]) 124 { 125 126 OMX_ERRORTYPE eError = OMX_ErrorNone; 127 OMX_U32 nIpBuf=0,nIpBufSize=0,nOpBuf=0,nOpBufSize=0; 128 OMX_U32 i=0; 129 OMX_BUFFERHEADERTYPE *pTemp = NULL; 130 OMX_S16 size_lcml=0; 131 LCML_STRMATTR *strmAttr = NULL; 132 133 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent; 134 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 135 LCML_G729DEC_BUFHEADERTYPE *pTemp_lcml = NULL; 136 137 G729DEC_DPRINT("%d :: G729DECFill_LCMLInitParams\n ",__LINE__); 138 G729DEC_DPRINT("%d :: pHandle = %p\n",__LINE__,pHandle); 139 G729DEC_DPRINT("%d :: pHandle->pComponentPrivate = %p\n",__LINE__,pHandle->pComponentPrivate); 140 pComponentPrivate = pHandle->pComponentPrivate; 141 142 pComponentPrivate->bufParamsArray = malloc((10 * sizeof(unsigned long int)) + 256); 143 pComponentPrivate->bufParamsArray += 128; 144 memset(pComponentPrivate->bufParamsArray, 0, 9 * sizeof(unsigned long int)); 145 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 146 pComponentPrivate->nRuntimeInputBuffers = nIpBuf; 147 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 148 pComponentPrivate->nRuntimeOutputBuffers = nOpBuf; 149 nIpBufSize = pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->nBufferSize; 150 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 151 nOpBufSize = pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->nBufferSize; 152 153 G729DEC_DPRINT("------ Buffer Details -----------\n"); 154 G729DEC_DPRINT("Input Buffer Count = %ld\n", nIpBuf); 155 G729DEC_DPRINT("Input Buffer Size = %ld\n", nIpBufSize); 156 G729DEC_DPRINT("Output Buffer Count = %ld\n", nOpBuf); 157 G729DEC_DPRINT("Output Buffer Size = %ld\n", nOpBufSize); 158 G729DEC_DPRINT("------ Buffer Details ------------\n"); 159 160 /* Fill Input Buffers Info for LCML */ 161 plcml_Init->In_BufInfo.nBuffers = nIpBuf; 162 plcml_Init->In_BufInfo.nSize = nIpBufSize; 163 plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD; 164 165 166 /* Fill Output Buffers Info for LCML */ 167 plcml_Init->Out_BufInfo.nBuffers = nOpBuf; 168 plcml_Init->Out_BufInfo.nSize = nOpBufSize; 169 plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD; 170 171 /*Copy the node information */ 172 plcml_Init->NodeInfo.nNumOfDLLs = 3; 173 174 plcml_Init->NodeInfo.AllUUIDs[0].uuid = &G729DECSOCKET_TI_UUID; 175 strcpy ((char *)plcml_Init->NodeInfo.AllUUIDs[0].DllName,G729DEC_DLL_NAME); 176 plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 177 178 plcml_Init->NodeInfo.AllUUIDs[1].uuid = &G729DECSOCKET_TI_UUID; 179 strcpy ((char *)plcml_Init->NodeInfo.AllUUIDs[1].DllName,G729DEC_DLL_NAME); 180 plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 181 182 plcml_Init->NodeInfo.AllUUIDs[2].uuid = &DECODE_COMMON_TI_UUID; 183 strcpy ((char *)plcml_Init->NodeInfo.AllUUIDs[2].DllName,G729DEC_USN_DLL_NAME); 184 plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 185 186 187 if(pComponentPrivate->dasfmode == 1) { 188 G729DEC_DPRINT("pComponentPrivate->dasfmode = %d\n",pComponentPrivate->dasfmode); 189 OMX_G729MALLOC_STRUCT(strmAttr, LCML_STRMATTR); 190 191 pComponentPrivate->strmAttr = strmAttr; 192 G729DEC_MEMPRINT("%d:[ALLOC] %p\n",__LINE__,strmAttr); 193 194 strmAttr->uSegid = 0; 195 strmAttr->uAlignment = 0; 196 strmAttr->uTimeout = G729D_TIMEOUT; 197 strmAttr->uBufsize = nOpBufSize; 198 strmAttr->uNumBufs = 2; 199 strmAttr->lMode = STRMMODE_PROCCOPY; 200 plcml_Init->DeviceInfo.TypeofDevice =1; 201 plcml_Init->DeviceInfo.TypeofRender =0; 202 if(pComponentPrivate->acdnmode == 1) 203 { 204 /* DASF/TeeDN mode */ 205 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &ACDN_TI_UUID; 206 } 207 else 208 { 209 /* ACDN mode */ 210 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID; 211 } 212 plcml_Init->DeviceInfo.DspStream = strmAttr; 213 } 214 else { 215 pComponentPrivate->strmAttr = NULL; 216 } 217 218 219 /*copy the other information */ 220 plcml_Init->SegID = OMX_G729DEC_DEFAULT_SEGMENT; 221 plcml_Init->Timeout = OMX_G729DEC_SN_TIMEOUT; 222 plcml_Init->Alignment = 0; 223 plcml_Init->Priority = OMX_G729DEC_SN_PRIORITY; 224 plcml_Init->ProfileID = -1; 225 226 227 /* TODO: Set this using SetParameter() */ 228 pComponentPrivate->iG729SamplingFrequeny = G729DEC_SAMPLING_FREQUENCY; 229 230 /*Accessing these 2 has the problem/creates problem in state transition tests*/ 231 pComponentPrivate->iG729Channels = 232 (OMX_U16)pComponentPrivate->pcmParams->nChannels; 233 234 /* Set G729 SN create phase arguments */ 235 236 arr[0] = STREAM_COUNT; 237 arr[1] = G729DEC_INPUT_PORT; 238 arr[2] = G729DEC_DMM; 239 if (pComponentPrivate->pInputBufferList->numBuffers) { 240 arr[3] = (OMX_U16)pComponentPrivate->pInputBufferList->numBuffers; 241 242 } 243 else { 244 arr[3] = 1; 245 } 246 247 arr[4] = G729DEC_OUTPUT_PORT; 248 249 if(pComponentPrivate->dasfmode == 1) { 250 G729DEC_DPRINT("Setting up create phase params for DASF mode\n"); 251 arr[5] = G729DEC_OUTSTRM; 252 arr[6] = NUM_G729DEC_OUTPUT_BUFFERS_DASF; 253 } 254 else { 255 256 G729DEC_DPRINT("Setting up create phase params for FILE mode\n"); 257 arr[5] = G729DEC_DMM; 258 if (pComponentPrivate->pOutputBufferList->numBuffers) { 259 arr[6] = (OMX_U16)pComponentPrivate->pOutputBufferList->numBuffers; 260 } 261 else { 262 arr[6] = 1; 263 } 264 265 } 266 267 arr[7] = END_OF_CR_PHASE_ARGS; 268 plcml_Init->pCrPhArgs = arr; 269 size_lcml = (OMX_U16)(nIpBuf * sizeof(LCML_G729DEC_BUFHEADERTYPE)); 270 pTemp_lcml = (LCML_G729DEC_BUFHEADERTYPE *)malloc(size_lcml); 271 G729DEC_MEMPRINT("%d:[ALLOC] %p\n",__LINE__,pTemp_lcml); 272 if(pTemp_lcml == NULL) { 273 G729DEC_DPRINT("%d :: Memory Allocation Failed\n",__LINE__); 274 /* Free previously allocated memory before bailing */ 275 if (strmAttr) { 276 free(strmAttr); 277 strmAttr = NULL; 278 } 279 eError = OMX_ErrorInsufficientResources; 280 goto EXIT; 281 } 282 pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT] = pTemp_lcml; 283 284 for (i=0; i<nIpBuf; i++) { 285 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 286 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 287 pTemp->nAllocLen = nIpBufSize; 288 pTemp->nFilledLen = nIpBufSize; 289 pTemp->nVersion.s.nVersionMajor = G729DEC_MAJOR_VER; 290 pTemp->nVersion.s.nVersionMinor = G729DEC_MINOR_VER; 291 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 292 pTemp_lcml->buffer = pTemp; 293 pTemp_lcml->eDir = OMX_DirInput; 294 OMX_G729MALLOC_STRUCT(pTemp_lcml->pIpParam, G729DEC_UAlgBufParamStruct); 295 pTemp_lcml->pIpParam->usFrameLost = 0; 296 pTemp_lcml->pIpParam->usLastFrame = 0; 297 /* This means, it is not a last buffer. This flag is to be modified by 298 * the application to indicate the last buffer */ 299 pTemp->nFlags = NORMAL_BUFFER; 300 pTemp++; 301 pTemp_lcml++; 302 } 303 304 /* Allocate memory for all output buffer headers.. 305 * This memory pointer will be sent to LCML */ 306 size_lcml = (OMX_U16)(nOpBuf * sizeof(LCML_G729DEC_BUFHEADERTYPE)); 307 pTemp_lcml = (LCML_G729DEC_BUFHEADERTYPE *)malloc(size_lcml); 308 G729DEC_MEMPRINT("%d:[ALLOC] %p\n",__LINE__,pTemp_lcml); 309 if(pTemp_lcml == NULL) { 310 /* Free previously allocated memory before bailing */ 311 if (strmAttr) { 312 free(strmAttr); 313 strmAttr = NULL; 314 } 315 eError = OMX_ErrorInsufficientResources; 316 goto EXIT; 317 } 318 memset(pTemp_lcml, 0x0, size_lcml); 319 pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT] = pTemp_lcml; 320 321 for (i=0; i<nOpBuf; i++) { 322 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 323 pTemp->nSize = (OMX_U16)sizeof(OMX_BUFFERHEADERTYPE); 324 pTemp->nAllocLen = nOpBufSize; 325 pTemp->nFilledLen = nOpBufSize; 326 pTemp->nVersion.s.nVersionMajor = G729DEC_MAJOR_VER; 327 pTemp->nVersion.s.nVersionMinor = G729DEC_MINOR_VER; 328 pComponentPrivate->nVersion = pTemp->nVersion.nVersion; 329 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 330 pTemp->nTickCount = 0; 331 pTemp->nTimeStamp = 0; 332 /* This means, it is not a last buffer. This flag is to be modified by 333 * the application to indicate the last buffer */ 334 pTemp_lcml->buffer = pTemp; 335 pTemp_lcml->eDir = OMX_DirOutput; 336 OMX_G729MALLOC_STRUCT(pTemp_lcml->pIpParam, G729DEC_UAlgBufParamStruct); 337 pTemp_lcml->pIpParam->usFrameLost = 0; 338 pTemp_lcml->pIpParam->usLastFrame = 0; 339 pTemp->nFlags = NORMAL_BUFFER; 340 pTemp++; 341 pTemp_lcml++; 342 } 343 #ifdef __PERF_INSTRUMENTATION__ 344 pComponentPrivate->nLcml_nCntIp = 0; 345 pComponentPrivate->nLcml_nCntOpReceived = 0; 346 #endif 347 pComponentPrivate->bPortDefsAllocated = 1; 348 pComponentPrivate->bInitParamsInitialized = 1; 349 350 351 EXIT: 352 G729DEC_DPRINT("%d :: Exiting G729DECFill_LCMLInitParams",__LINE__); 353 return eError; 354 } 355 356 357 /* ========================================================================== */ 358 /** 359 * @G729DEC_StartComponentThread() This function is called by the component to create 360 * the component thread, command pipe and data pipe. 361 * 362 * @param pComponent handle for this instance of the component 363 * 364 * @pre 365 * 366 * @post 367 * 368 * @return none 369 */ 370 /* ========================================================================== */ 371 372 373 374 OMX_ERRORTYPE G729DEC_StartComponentThread(OMX_HANDLETYPE pComponent) 375 { 376 OMX_ERRORTYPE eError = OMX_ErrorNone; 377 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 378 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = 379 (G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 380 #ifdef UNDER_CE 381 pthread_attr_t attr; 382 memset(&attr, 0, sizeof(attr)); 383 attr.__inheritsched = PTHREAD_EXPLICIT_SCHED; 384 attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY; 385 #endif 386 G729DEC_DPRINT ("%d :: Inside G729DEC_StartComponentThread\n", __LINE__); 387 388 /* Initialize all the variables*/ 389 pComponentPrivate->bIsStopping = 0; 390 pComponentPrivate->bCompThreadStop = 0; 391 pComponentPrivate->lcml_nOpBuf = 0; 392 pComponentPrivate->lcml_nIpBuf = 0; 393 pComponentPrivate->app_nBuf = 0; 394 pComponentPrivate->num_Op_Issued = 0; 395 pComponentPrivate->num_Sent_Ip_Buff = 0; 396 pComponentPrivate->num_Reclaimed_Op_Buff = 0; 397 pComponentPrivate->bIsEOFSent = 0; 398 399 /* create the pipe used to send buffers to the thread */ 400 eError = pipe (pComponentPrivate->cmdDataPipe); 401 if (eError) { 402 eError = OMX_ErrorInsufficientResources; 403 goto EXIT; 404 } 405 406 /* create the pipe used to send buffers to the thread */ 407 eError = pipe (pComponentPrivate->dataPipe); 408 if (eError) { 409 eError = OMX_ErrorInsufficientResources; 410 goto EXIT; 411 } 412 413 /* create the pipe used to send commands to the thread */ 414 eError = pipe (pComponentPrivate->cmdPipe); 415 if (eError) { 416 eError = OMX_ErrorInsufficientResources; 417 goto EXIT; 418 } 419 420 /* Create the Component Thread */ 421 #ifdef UNDER_CE 422 eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, 423 G729DEC_ComponentThread, pComponentPrivate); 424 #else 425 eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, 426 G729DEC_ComponentThread, pComponentPrivate); 427 #endif 428 if (eError || !pComponentPrivate->ComponentThread) { 429 eError = OMX_ErrorInsufficientResources; 430 goto EXIT; 431 } 432 pComponentPrivate_CC = pComponentPrivate; 433 434 pComponentPrivate->bCompThreadStarted = 1; 435 EXIT: 436 return eError; 437 } 438 439 /* ========================================================================== */ 440 /** 441 * @G729DEC_FreeCompResources() This function is called by the component during 442 * de-init to close component thread, Command pipe, data pipe & LCML pipe. 443 * 444 * @param pComponent handle for this instance of the component 445 * 446 * @pre 447 * 448 * @post 449 * 450 * @return none 451 */ 452 /* ========================================================================== */ 453 454 OMX_ERRORTYPE G729DEC_FreeCompResources(OMX_HANDLETYPE pComponent) 455 { 456 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 457 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = (G729DEC_COMPONENT_PRIVATE *) 458 pHandle->pComponentPrivate; 459 460 OMX_ERRORTYPE eError = OMX_ErrorNone; 461 OMX_ERRORTYPE err = OMX_ErrorNone; 462 OMX_U32 nIpBuf = 0; 463 OMX_U32 nOpBuf = 0; 464 465 G729DEC_DPRINT ("%d :: G729DEC_FreeCompResources\n", __LINE__); 466 467 if (pComponentPrivate->bPortDefsAllocated) { 468 nIpBuf = pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->nBufferCountActual; 469 nOpBuf = pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->nBufferCountActual; 470 } 471 472 if (pComponentPrivate->bCompThreadStarted) { 473 err = close (pComponentPrivate->dataPipe[0]); 474 475 if (0 != err && OMX_ErrorNone == eError) { 476 eError = OMX_ErrorHardware; 477 } 478 479 err = close (pComponentPrivate->dataPipe[1]); 480 if (0 != err && OMX_ErrorNone == eError) { 481 eError = OMX_ErrorHardware; 482 } 483 484 err = close (pComponentPrivate->cmdPipe[0]); 485 if (0 != err && OMX_ErrorNone == eError) { 486 eError = OMX_ErrorHardware; 487 } 488 489 err = close (pComponentPrivate->cmdPipe[1]); 490 if (0 != err && OMX_ErrorNone == eError) { 491 eError = OMX_ErrorHardware; 492 } 493 494 err = close (pComponentPrivate->cmdDataPipe[0]); 495 if (0 != err && OMX_ErrorNone == eError) { 496 eError = OMX_ErrorHardware; 497 } 498 499 err = close (pComponentPrivate->cmdDataPipe[1]); 500 if (0 != err && OMX_ErrorNone == eError) { 501 eError = OMX_ErrorHardware; 502 } 503 504 } 505 506 if (pComponentPrivate->bPortDefsAllocated) { 507 if (pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]) { 508 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]); 509 free(pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]); 510 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT] = NULL; 511 } 512 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT] = NULL; 513 514 if (pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]) { 515 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]); 516 free (pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]); 517 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT] = NULL; 518 } 519 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT] = NULL; 520 521 if (pComponentPrivate->g729Params) { 522 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->g729Params); 523 free(pComponentPrivate->g729Params); 524 pComponentPrivate->g729Params = NULL; 525 } 526 527 if (pComponentPrivate->pcmParams) { 528 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->pcmParams); 529 free (pComponentPrivate->pcmParams); 530 pComponentPrivate->pcmParams = NULL; 531 } 532 } 533 pComponentPrivate->bPortDefsAllocated = 0; 534 return eError; 535 } 536 537 538 539 OMX_ERRORTYPE G729DEC_CleanupInitParams(OMX_HANDLETYPE pComponent) 540 { 541 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 542 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = (G729DEC_COMPONENT_PRIVATE *) 543 pHandle->pComponentPrivate; 544 545 LCML_G729DEC_BUFHEADERTYPE *pTemp_lcml = NULL; 546 547 OMX_ERRORTYPE eError = OMX_ErrorNone; 548 OMX_U32 nIpBuf = 0; 549 OMX_U32 nOpBuf = 0; 550 OMX_U32 i=0; 551 552 G729DEC_DPRINT ("%d :: G729DEC_CleanupInitParams()\n", __LINE__); 553 554 if (pComponentPrivate->strmAttr) { 555 free(pComponentPrivate->strmAttr); 556 pComponentPrivate->strmAttr = NULL; 557 } 558 if(pComponentPrivate->pParams!=NULL){ 559 free(pComponentPrivate->pParams); 560 pComponentPrivate->pParams = NULL; 561 } 562 563 nIpBuf = pComponentPrivate->nRuntimeInputBuffers; 564 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT]; 565 566 for(i=0; i<nIpBuf; i++) { 567 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pTemp_lcml->pIpParam); 568 free(pTemp_lcml->pIpParam); 569 pTemp_lcml->pIpParam = NULL; 570 pTemp_lcml++; 571 } 572 573 574 nOpBuf = pComponentPrivate->nRuntimeOutputBuffers; 575 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT]; 576 for(i=0; i<nOpBuf; i++) { 577 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pTemp_lcml->pIpParam); 578 free(pTemp_lcml->pIpParam); 579 pTemp_lcml->pIpParam = NULL; 580 pTemp_lcml++; 581 } 582 583 if(pComponentPrivate->bufParamsArray != NULL){ 584 pComponentPrivate->bufParamsArray -= 128; 585 free(pComponentPrivate->bufParamsArray); 586 pComponentPrivate->bufParamsArray = NULL; 587 } 588 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT]); 589 free(pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT]); 590 pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT] = NULL; 591 592 G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT]); 593 free(pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT]); 594 pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT] = NULL; 595 return eError; 596 } 597 598 /* ========================================================================== */ 599 /** 600 * @G729DEC_StopComponentThread() This function is called by the component during 601 * de-init to close component thread, Command pipe, data pipe & LCML pipe. 602 * 603 * @param pComponent handle for this instance of the component 604 * 605 * @pre 606 * 607 * @post 608 * 609 * @return none 610 */ 611 /* ========================================================================== */ 612 613 OMX_ERRORTYPE G729DEC_StopComponentThread(OMX_HANDLETYPE pComponent) 614 { 615 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 616 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = (G729DEC_COMPONENT_PRIVATE *) 617 pHandle->pComponentPrivate; 618 619 OMX_ERRORTYPE eError = OMX_ErrorNone; 620 OMX_ERRORTYPE threadError = OMX_ErrorNone; 621 OMX_S16 pthreadError = 0; 622 623 /*Join the component thread */ 624 pComponentPrivate->bIsStopping = 1; 625 pComponentPrivate->bCompThreadStop = 1; 626 pthreadError = pthread_join (pComponentPrivate->ComponentThread, 627 (void*)&threadError); 628 if (0 != pthreadError) { 629 eError = OMX_ErrorHardware; 630 } 631 632 /*Check for the errors */ 633 if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) { 634 eError = OMX_ErrorInsufficientResources; 635 G729DEC_DPRINT ("%d :: Error while closing Component Thread\n",__LINE__); 636 } 637 return eError; 638 } 639 640 641 /* ========================================================================== */ 642 /** 643 * @G729DECHandleCommand() This function is called by the component when ever it 644 * receives the command from the application 645 * 646 * @param pComponentPrivate Component private data 647 * 648 * @pre 649 * 650 * @post 651 * 652 * @return none 653 */ 654 /* ========================================================================== */ 655 656 OMX_U32 G729DECHandleCommand (G729DEC_COMPONENT_PRIVATE *pComponentPrivate) 657 { 658 659 OMX_COMPONENTTYPE *pHandle = NULL; 660 OMX_COMMANDTYPE command; 661 OMX_STATETYPE commandedState = OMX_StateInvalid; 662 OMX_U32 commandData = 0; 663 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle; 664 OMX_ERRORTYPE rm_error = OMX_ErrorNone; 665 OMX_U16 i = 0; 666 OMX_ERRORTYPE eError = OMX_ErrorNone; 667 OMX_U32 nBuf = 0; 668 OMX_U16 arr[100] = {0}; 669 OMX_S8 *p = (OMX_S8 *)"hello"; 670 LCML_CALLBACKTYPE cb; 671 LCML_DSP *pLcmlDsp = NULL; 672 G729DEC_AudioCodecParams *pParams = NULL; 673 OMX_S16 ret = 0; 674 LCML_G729DEC_BUFHEADERTYPE *pLcmlHdr = NULL; 675 int inputPortFlag=0,outputPortFlag=0; 676 OMX_U8 frameType = 0; 677 OMX_U32 nOpBuf = 0; 678 679 G729DEC_DPRINT ("%d :: Entering G729DECHandleCommand Function\n", __LINE__); 680 681 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 682 G729DEC_DPRINT("pComponentPrivate->pHandle = %p at HandleCommand\n", pComponentPrivate->pHandle); 683 684 ret = (OMX_U16)(read (pComponentPrivate->cmdPipe[0], &command, sizeof (command))); 685 if (ret == -1) { 686 G729DEC_EPRINT ("%d :: Error While reading from the Pipe\n",__LINE__); 687 eError = OMX_ErrorHardware; 688 goto EXIT; 689 } 690 691 ret = (OMX_U16)(read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData))); 692 if (ret == -1) { 693 G729DEC_EPRINT ("%d :: Error While reading from the Pipe\n",__LINE__); 694 eError = OMX_ErrorHardware; 695 goto EXIT; 696 } 697 698 #ifdef __PERF_INSTRUMENTATION__ 699 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp, command, commandData, 700 PERF_ModuleLLMM); 701 #endif 702 703 if (command == OMX_CommandStateSet) { 704 commandedState = (OMX_STATETYPE)commandData; 705 if (pComponentPrivate->curState == commandedState){ 706 pComponentPrivate->cbInfo.EventHandler ( 707 pHandle, pHandle->pApplicationPrivate, 708 OMX_EventError, OMX_ErrorSameState,0, 709 NULL); 710 goto EXIT; 711 } 712 713 switch(commandedState) { 714 case OMX_StateIdle: 715 716 #ifdef __PERF_INSTRUMENTATION__ 717 PERF_Boundary(pComponentPrivate->pPERFcomp, 718 PERF_BoundaryStart | PERF_BoundarySetup); 719 #endif 720 if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->curState == OMX_StateWaitForResources) { 721 722 if (pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated && 723 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled) { 724 inputPortFlag = 1; 725 } 726 if (!pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated && 727 !pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled) { 728 inputPortFlag = 1; 729 } 730 if (pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated && 731 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled) { 732 outputPortFlag = 1; 733 } 734 if (!pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated && 735 !pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled) { 736 outputPortFlag = 1; 737 } 738 if (!(inputPortFlag && outputPortFlag)) { 739 pComponentPrivate->InLoaded_readytoidle = 1; 740 741 #ifndef UNDER_CE 742 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 743 pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex); 744 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 745 #else 746 OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event)); 747 #endif 748 } 749 750 G729DEC_DPRINT ("%d :: Inside G729DECHandleCommand\n",__LINE__); 751 cb.LCML_Callback = (void *) G729DECLCML_Callback; 752 pLcmlHandle = (OMX_HANDLETYPE) G729DECGetLCMLHandle(pComponentPrivate); 753 if (pLcmlHandle == NULL) { 754 G729DEC_DPRINT("%d :: LCML Handle is NULL........exiting..\n",__LINE__); 755 goto EXIT; 756 } 757 G729DEC_DPRINT("G729DECHandleCommand %d\n",__LINE__); 758 G729DEC_DPRINT("pLcmlHandle = %p\n",pLcmlHandle); 759 760 /* Got handle of dsp via phandle filling information about DSP 761 specific things */ 762 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 763 G729DEC_DPRINT("pLcmlDsp = %p\n",pLcmlDsp); 764 eError = G729DECFill_LCMLInitParams(pHandle, pLcmlDsp, arr); 765 if(eError != OMX_ErrorNone) { 766 G729DEC_DPRINT("%d :: Error returned from\ 767 G729DECFill_LCMLInitParams()\n",__LINE__); 768 goto EXIT; 769 } 770 G729DEC_DPRINT("%d :: Comp: OMX_G729DecUtils.c\n",__LINE__); 771 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle; 772 /*filling create phase params */ 773 /* cb.LCML_Callback = (void *) G729DECLCML_Callback; 774 G729DEC_DPRINT("%d :: Calling LCML_InitMMCodec...\n",__LINE__); */ 775 776 #ifndef UNDER_CE 777 /* TeeDN will be default for decoder component */ 778 G729DEC_DPRINT("G729 decoder support TeeDN\n"); 779 eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle, 780 (void *)p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString); 781 #else 782 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle, 783 (void *)p,&pLcmlHandle,(void *)p,&cb); 784 #endif 785 if(eError != OMX_ErrorNone) { 786 G729DEC_EPRINT("%d :: Error returned from LCML_Init()\n",__LINE__); 787 goto EXIT; 788 } 789 #ifdef HASHINGENABLE 790 /* Enable the Hashing Code */ 791 eError = LCML_SetHashingState(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, OMX_TRUE); 792 if (eError != OMX_ErrorNone) { 793 G729DEC_DPRINT("Failed to set Mapping State\n"); 794 goto EXIT; 795 } 796 #endif 797 798 799 800 #ifdef RESOURCE_MANAGER_ENABLED 801 /* need check the resource with RM */ 802 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) G729DEC_ResourceManagerCallback; 803 rm_error = RMProxy_NewSendCommand(pHandle, 804 RMProxy_RequestResource, 805 OMX_G729_Decoder_COMPONENT, 806 G729DEC_CPU, 807 3456, 808 &(pComponentPrivate->rmproxyCallback)); 809 if(rm_error == OMX_ErrorNone) { 810 /* resource is available */ 811 rm_error = RMProxy_NewSendCommand(pHandle, 812 RMProxy_StateSet, 813 OMX_G729_Decoder_COMPONENT, 814 OMX_StateIdle, 815 3456,NULL); 816 pComponentPrivate->curState = OMX_StateIdle; 817 pComponentPrivate->cbInfo.EventHandler(pHandle, 818 pHandle->pApplicationPrivate, 819 OMX_EventCmdComplete, 820 OMX_CommandStateSet, 821 pComponentPrivate->curState, 822 NULL); 823 } 824 else if(rm_error == OMX_ErrorInsufficientResources) { 825 /* resource is not available, need set state to OMX_StateWaitForResources */ 826 pComponentPrivate->curState = OMX_StateWaitForResources; 827 pComponentPrivate->cbInfo.EventHandler(pHandle, 828 pHandle->pApplicationPrivate, 829 OMX_EventCmdComplete, 830 OMX_CommandStateSet, 831 pComponentPrivate->curState, 832 NULL); 833 G729DEC_DPRINT("%d :: OMX_G729Dec_Utils.c :: Error - insufficient resources\n", __LINE__); 834 } 835 #else 836 pComponentPrivate->curState = OMX_StateIdle; 837 pComponentPrivate->cbInfo.EventHandler(pHandle, 838 pHandle->pApplicationPrivate, 839 OMX_EventCmdComplete, 840 OMX_CommandStateSet, 841 pComponentPrivate->curState, 842 NULL); 843 #endif 844 845 #ifdef __PERF_INSTRUMENTATION__ 846 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup); 847 #endif 848 G729DEC_DPRINT("%d :: G729DEC: State has been Set to Idle\n", 849 __LINE__); 850 851 if(pComponentPrivate->dasfmode == 1) { 852 OMX_U32 pValues[4]; 853 G729DEC_DPRINT("%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__); 854 OMX_G729MALLOC_STRUCT(pParams, G729DEC_AudioCodecParams); 855 G729DEC_DPRINT("Line %d:::pParams = 0x%x\n",__LINE__,pParams ); 856 pComponentPrivate->pParams = pParams; 857 /* TODO: Configure from test app */ 858 pParams->iAudioFormat = 1; 859 pParams->iSamplingRate = 8000; 860 861 /*TODO: get this value from the audio manager */ 862 pParams->iStrmId = pComponentPrivate->streamID; 863 864 pValues[0] = USN_STRMCMD_SETCODECPARAMS; 865 pValues[1] = (OMX_U32)pParams; 866 pValues[2] = sizeof(G729DEC_AudioCodecParams); 867 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 868 EMMCodecControlStrmCtrl,(void *)pValues); 869 870 if(eError != OMX_ErrorNone) { 871 G729DEC_EPRINT("%d: Error Occurred in Codec StreamControl..\n",__LINE__); 872 goto EXIT; 873 } 874 } 875 } 876 else if (pComponentPrivate->curState == OMX_StateExecuting) { 877 OMX_S8 *pArgs = (OMX_S8*)"damedesuStr"; 878 /*Set the bIsStopping bit */ 879 G729DEC_DPRINT("%d :: G729DEC: About to set bIsStopping bit\n", __LINE__); 880 881 #ifdef __PERF_INSTRUMENTATION__ 882 PERF_Boundary(pComponentPrivate->pPERFcomp, 883 PERF_BoundaryComplete | PERF_BoundarySteadyState); 884 #endif 885 G729DEC_DPRINT("About to call LCML_ControlCodec(STOP)\n"); 886 eError = LCML_ControlCodec( 887 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 888 MMCodecControlStop,(void *)pArgs); 889 if(eError != OMX_ErrorNone) { 890 G729DEC_EPRINT("%d: Error Occurred in Codec Stop..\n", __LINE__); 891 goto EXIT; 892 } 893 894 #ifdef HASHINGENABLE 895 /*Hashing Change*/ 896 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle; 897 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle); 898 if (eError != OMX_ErrorNone) { 899 G729DEC_EPRINT("Error occurred in Codec mapping flush!\n"); 900 break; 901 } 902 #endif 903 904 pComponentPrivate->bStopSent=1; 905 if (pComponentPrivate->pHoldBuffer) { 906 free(pComponentPrivate->pHoldBuffer); 907 pComponentPrivate->pHoldBuffer = NULL; 908 } 909 pComponentPrivate->nHoldLength = 0; 910 } 911 else if(pComponentPrivate->curState == OMX_StatePause) { 912 G729DEC_DPRINT("%d :: Comp: Stop Command Received\n",__LINE__); 913 914 #ifdef HASHINGENABLE 915 /*Hashing Change*/ 916 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle; 917 eError = LCML_FlushHashes(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle); 918 if (eError != OMX_ErrorNone) { 919 G729DEC_EPRINT("Error occurred in Codec mapping flush!\n"); 920 break; 921 } 922 #endif 923 G729DEC_DPRINT("Setting to OMX_StateIdle - Line %d\n",__LINE__); 924 pComponentPrivate->curState = OMX_StateIdle; 925 926 #ifdef RESOURCE_MANAGER_ENABLED 927 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G729_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL); 928 #endif 929 G729DEC_DPRINT ("%d :: The component is stopped\n",__LINE__); 930 pComponentPrivate->cbInfo.EventHandler ( 931 pHandle,pHandle->pApplicationPrivate, 932 OMX_EventCmdComplete,OMX_CommandStateSet,pComponentPrivate->curState, 933 NULL); 934 } 935 else { 936 /* This means, it is invalid state from application */ 937 G729DEC_DPRINT("%d :: Comp: OMX_G729DecUtils.c\n",__LINE__); 938 pComponentPrivate->cbInfo.EventHandler( 939 pHandle, 940 pHandle->pApplicationPrivate, 941 OMX_EventError, 942 OMX_ErrorIncorrectStateTransition,0, 943 NULL); 944 } 945 break; 946 947 case OMX_StateExecuting: 948 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd Executing \n",__LINE__); 949 950 if (pComponentPrivate->curState == OMX_StateIdle) { 951 G729DEC_DPRINT("%d :: Comp: OMX_G729DecUtils.c\n",__LINE__); 952 /* Sending commands to DSP via LCML_ControlCodec third argument 953 is not used for time being */ 954 pComponentPrivate->nFillBufferDoneCount = 0; 955 pComponentPrivate->bStopSent=0; 956 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 957 EMMCodecControlStart, NULL); 958 if(eError != OMX_ErrorNone) { 959 G729DEC_EPRINT("%d: Error Occurred in Codec Start..\n",__LINE__); 960 goto EXIT; 961 } 962 /* Send input buffers to application */ 963 nBuf = pComponentPrivate->pInputBufferList->numBuffers; 964 965 966 G729DEC_DPRINT ("nBuf = %d\n",nBuf); 967 /* Send output buffers to codec */ 968 } 969 else if (pComponentPrivate->curState == OMX_StatePause) { 970 G729DEC_DPRINT("%d :: Comp: OMX_G729DecUtils.c\n",__LINE__); 971 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 972 EMMCodecControlStart, (void *)p); 973 if (eError != OMX_ErrorNone) { 974 G729DEC_EPRINT ("Error While Resuming the codec\n"); 975 goto EXIT; 976 } 977 978 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 979 if (pComponentPrivate->pInputBufHdrPending[i]) { 980 frameType = *(pComponentPrivate->pInputBufHdrPending[i]->pBuffer); 981 G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 982 G729DEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput); 983 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 984 EMMCodecInputBuffer, 985 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 986 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 987 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 988 (OMX_U8 *) pLcmlHdr->pIpParam, 989 sizeof(G729DEC_UAlgBufParamStruct), 990 NULL); 991 992 } 993 } 994 pComponentPrivate->nNumInputBufPending = 0; 995 996 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 997 if (pComponentPrivate->pOutputBufHdrPending[i]) { 998 G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr); 999 G729DEC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput); 1000 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1001 EMMCodecOuputBuffer, 1002 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1003 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen, 1004 pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen, 1005 (OMX_U8 *) pLcmlHdr->pIpParam, 1006 sizeof(G729DEC_UAlgBufParamStruct), 1007 NULL); 1008 } 1009 } 1010 pComponentPrivate->nNumOutputBufPending = 0; 1011 1012 } 1013 else { 1014 pComponentPrivate->cbInfo.EventHandler ( 1015 pHandle, 1016 pHandle->pApplicationPrivate, 1017 OMX_EventError, OMX_ErrorIncorrectStateTransition,0, 1018 NULL); 1019 G729DEC_EPRINT("%d :: Error: Invalid State Given by Application\n",__LINE__); 1020 goto EXIT; 1021 1022 } 1023 1024 #ifdef __PERF_INSTRUMENTATION__ 1025 PERF_Boundary(pComponentPrivate->pPERFcomp, 1026 PERF_BoundaryStart | PERF_BoundarySteadyState); 1027 #endif 1028 pComponentPrivate->curState = OMX_StateExecuting; 1029 /*Send state change notificaiton to Application */ 1030 pComponentPrivate->cbInfo.EventHandler( 1031 pHandle, 1032 pHandle->pApplicationPrivate, 1033 OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState, NULL); 1034 1035 #ifdef RESOURCE_MANAGER_ENABLED 1036 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G729_Decoder_COMPONENT, OMX_StateExecuting, 3456,NULL); 1037 #endif 1038 1039 break; 1040 1041 case OMX_StateLoaded: 1042 1043 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd Loaded - curState = %d\n",__LINE__,pComponentPrivate->curState); 1044 if (pComponentPrivate->curState == OMX_StateWaitForResources){ 1045 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd Loaded\n",__LINE__); 1046 1047 #ifdef __PERF_INSTRUMENTATION__ 1048 PERF_Boundary(pComponentPrivate->pPERFcomp, 1049 PERF_BoundaryStart | PERF_BoundaryCleanup); 1050 #endif 1051 1052 pComponentPrivate->curState = OMX_StateLoaded; 1053 1054 #ifdef __PERF_INSTRUMENTATION__ 1055 PERF_Boundary(pComponentPrivate->pPERFcomp, 1056 PERF_BoundaryComplete | PERF_BoundaryCleanup); 1057 #endif 1058 1059 pComponentPrivate->cbInfo.EventHandler ( 1060 pHandle, pHandle->pApplicationPrivate, 1061 OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState, 1062 NULL); 1063 break; 1064 1065 } 1066 1067 if (pComponentPrivate->curState != OMX_StateIdle && 1068 pComponentPrivate->curState != OMX_StateWaitForResources) 1069 { 1070 pComponentPrivate->cbInfo.EventHandler (pHandle, 1071 pHandle->pApplicationPrivate, 1072 OMX_EventError, 1073 OMX_ErrorIncorrectStateTransition,0, 1074 NULL); 1075 G729DEC_EPRINT("%d :: Error: Invalid State Given by Application\n",__LINE__); 1076 goto EXIT; 1077 } 1078 1079 #ifdef __PERF_INSTRUMENTATION__ 1080 PERF_Boundary(pComponentPrivate->pPERFcomp, 1081 PERF_BoundaryStart | PERF_BoundaryCleanup); 1082 #endif 1083 1084 G729DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %d\n",pComponentPrivate->pInputBufferList->numBuffers); 1085 G729DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %d\n",pComponentPrivate->pOutputBufferList->numBuffers); 1086 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 1087 if (pComponentPrivate->pInputBufferList->numBuffers && 1088 pComponentPrivate->pOutputBufferList->numBuffers) 1089 { 1090 pComponentPrivate->InIdle_goingtoloaded = 1; 1091 #ifndef UNDER_CE 1092 1093 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1094 pthread_cond_wait(&pComponentPrivate->InIdle_threshold, 1095 &pComponentPrivate->InIdle_mutex); 1096 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 1097 #else 1098 OMX_WaitForEvent(&(pComponentPrivate->InIdle_event)); 1099 #endif 1100 1101 } 1102 1103 /* Now Deinitialize the component No error should be returned from 1104 * this function. It should clean the system as much as possible */ 1105 G729DEC_DPRINT("%d :: In side OMX_StateLoaded State: \n",__LINE__); 1106 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1107 EMMCodecControlDestroy, (void *)p); 1108 1109 if (eError != OMX_ErrorNone) { 1110 G729DEC_EPRINT("%d : Error: in Destroying the codec: no. %x\n",__LINE__, eError); 1111 goto EXIT; 1112 } 1113 1114 #ifdef __PERF_INSTRUMENTATION__ 1115 PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, 1116 PERF_ModuleComponent); 1117 #endif 1118 1119 eError = EXIT_COMPONENT_THRD; 1120 pComponentPrivate->bInitParamsInitialized = 0; 1121 /* Send StateChangeNotification to application */ 1122 pComponentPrivate->bLoadedCommandPending = OMX_FALSE; 1123 break; 1124 1125 case OMX_StatePause: 1126 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd Pause\n",__LINE__); 1127 1128 if (pComponentPrivate->curState != OMX_StateExecuting && 1129 pComponentPrivate->curState != OMX_StateIdle) { 1130 pComponentPrivate->cbInfo.EventHandler ( 1131 pHandle, 1132 pHandle->pApplicationPrivate, 1133 OMX_EventError, OMX_ErrorIncorrectStateTransition,0, 1134 NULL); 1135 G729DEC_EPRINT("%d :: Error: Invalid State Given by \ 1136 Application\n",__LINE__); 1137 goto EXIT; 1138 } 1139 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1140 EMMCodecControlPause, (void *)p); 1141 1142 if (eError != OMX_ErrorNone) { 1143 G729DEC_EPRINT("%d : Error: in Pausing the codec\n",__LINE__); 1144 goto EXIT; 1145 } 1146 break; 1147 1148 case OMX_StateWaitForResources: 1149 1150 if (pComponentPrivate->curState == OMX_StateLoaded) { 1151 #ifdef RESOURCE_MANAGER_ENABLED 1152 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G729_Decoder_COMPONENT, OMX_StateWaitForResources, 3456,NULL); 1153 #endif 1154 pComponentPrivate->curState = OMX_StateWaitForResources; 1155 pComponentPrivate->cbInfo.EventHandler( 1156 pHandle, pHandle->pApplicationPrivate, 1157 OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState,NULL); 1158 } 1159 else{ 1160 pComponentPrivate->cbInfo.EventHandler( 1161 pHandle, pHandle->pApplicationPrivate, 1162 OMX_EventError, OMX_ErrorIncorrectStateTransition,0, "NULL"); 1163 } 1164 break; 1165 1166 1167 case OMX_StateInvalid: 1168 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd OMX_StateInvalid:\n",__LINE__); 1169 1170 pComponentPrivate->curState = OMX_StateInvalid; 1171 1172 pComponentPrivate->cbInfo.EventHandler( 1173 pHandle, pHandle->pApplicationPrivate, 1174 OMX_EventError, OMX_ErrorInvalidState,0, NULL); 1175 break; 1176 1177 case OMX_StateMax: 1178 G729DEC_DPRINT("%d: G729DECHandleCommand: Cmd OMX_StateMax::\n",__LINE__); 1179 break; 1180 } /* End of Switch */ 1181 } 1182 else if (command == OMX_CommandMarkBuffer) { 1183 G729DEC_DPRINT("command OMX_CommandMarkBuffer received %d\n",__LINE__); 1184 if(!pComponentPrivate->pMarkBuf){ 1185 /* TODO Need to handle multiple marks */ 1186 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData); 1187 } 1188 } 1189 else if (command == OMX_CommandPortDisable) { 1190 if (!pComponentPrivate->bDisableCommandPending) { 1191 1192 if(commandData == 0x0 || commandData == -1){ 1193 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled = OMX_FALSE; 1194 } 1195 1196 1197 1198 } 1199 if(commandData == 0x1 || commandData == -1){ 1200 char *pArgs = "damedesuStr"; 1201 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled = OMX_FALSE; 1202 if (pComponentPrivate->curState == OMX_StateExecuting) { 1203 pComponentPrivate->bNoIdleOnStop = OMX_TRUE; 1204 G729DEC_DPRINT("Calling LCML_ControlCodec() Line %d\n",__LINE__); 1205 eError = LCML_ControlCodec( 1206 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1207 MMCodecControlStop,(void *)pArgs); 1208 } 1209 } 1210 1211 if(commandData == 0x0) { 1212 if(!pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated){ 1213 /* return cmdcomplete event if input unpopulated */ 1214 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 1215 OMX_EventCmdComplete, 1216 OMX_CommandPortDisable, 1217 G729DEC_INPUT_PORT, NULL); 1218 1219 G729DEC_DPRINT("Clearing bDisableCommandPending Line %d\n",__LINE__); 1220 pComponentPrivate->bDisableCommandPending = 0; 1221 } 1222 else{ 1223 pComponentPrivate->bDisableCommandPending = 1; 1224 pComponentPrivate->bDisableCommandParam = commandData; 1225 } 1226 } 1227 1228 if(commandData == 0x1) { 1229 if (!pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated){ 1230 /* return cmdcomplete event if output unpopulated */ 1231 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 1232 OMX_EventCmdComplete, 1233 OMX_CommandPortDisable, 1234 G729DEC_OUTPUT_PORT, NULL); 1235 1236 G729DEC_DPRINT("Clearing bDisableCommandPending Line %d\n",__LINE__); 1237 pComponentPrivate->bDisableCommandPending = 0; 1238 } 1239 else { 1240 pComponentPrivate->bDisableCommandPending = 1; 1241 pComponentPrivate->bDisableCommandParam = commandData; 1242 } 1243 } 1244 1245 if(commandData == -1) { 1246 if (!pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated && 1247 !pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated){ 1248 1249 /* return cmdcomplete event if inout & output unpopulated */ 1250 pComponentPrivate->cbInfo.EventHandler( 1251 pHandle, pHandle->pApplicationPrivate, 1252 OMX_EventCmdComplete, OMX_CommandPortDisable,G729DEC_INPUT_PORT, NULL); 1253 1254 pComponentPrivate->cbInfo.EventHandler( 1255 pHandle, pHandle->pApplicationPrivate, 1256 OMX_EventCmdComplete, OMX_CommandPortDisable,G729DEC_OUTPUT_PORT, NULL); 1257 G729DEC_DPRINT("Clearing bDisableCommandPending Line %d\n",__LINE__); 1258 pComponentPrivate->bDisableCommandPending = 0; 1259 } 1260 else { 1261 pComponentPrivate->bDisableCommandPending = 1; 1262 pComponentPrivate->bDisableCommandParam = commandData; 1263 } 1264 } 1265 } 1266 else if (command == OMX_CommandPortEnable) { 1267 if (!pComponentPrivate->bEnableCommandPending) { 1268 if(commandData == 0x0 || commandData == -1){ 1269 /* enable in port */ 1270 G729DEC_DPRINT("setting input port to enabled\n"); 1271 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled = OMX_TRUE; 1272 G729DEC_DPRINT("pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bEnabled); 1273 1274 if(pComponentPrivate->AlloBuf_waitingsignal) 1275 { 1276 pComponentPrivate->AlloBuf_waitingsignal = 0; 1277 } 1278 } 1279 if(commandData == 0x1 || commandData == -1){ 1280 /* enable out port */ 1281 G729DEC_DPRINT("setting output port to enabled\n"); 1282 1283 if(pComponentPrivate->AlloBuf_waitingsignal) 1284 { 1285 pComponentPrivate->AlloBuf_waitingsignal = 0; 1286 #ifndef UNDER_CE 1287 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1288 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); 1289 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1290 #else 1291 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); 1292 #endif 1293 } 1294 if (pComponentPrivate->curState == OMX_StateExecuting) { 1295 char *pArgs = "damedesuStr"; 1296 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 1297 eError = LCML_ControlCodec( 1298 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1299 EMMCodecControlStart,(void *)pArgs); 1300 } 1301 1302 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled = OMX_TRUE; 1303 G729DEC_DPRINT("pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled = %d\n", 1304 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bEnabled); 1305 } 1306 } 1307 1308 if(commandData == 0x0){ 1309 if(pComponentPrivate->curState == OMX_StateLoaded || 1310 pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated){ 1311 1312 pComponentPrivate->cbInfo.EventHandler( pHandle, 1313 pHandle->pApplicationPrivate, 1314 OMX_EventCmdComplete, 1315 OMX_CommandPortEnable, 1316 G729DEC_INPUT_PORT, 1317 NULL); 1318 pComponentPrivate->bEnableCommandPending = 0; 1319 } 1320 else { 1321 pComponentPrivate->bEnableCommandPending = 1; 1322 pComponentPrivate->bEnableCommandParam = commandData; 1323 } 1324 } 1325 else if(commandData == 0x1){ 1326 if(pComponentPrivate->curState == OMX_StateLoaded || 1327 pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated){ 1328 1329 pComponentPrivate->cbInfo.EventHandler( pHandle, 1330 pHandle->pApplicationPrivate, 1331 OMX_EventCmdComplete, OMX_CommandPortEnable, 1332 G729DEC_OUTPUT_PORT, 1333 NULL); 1334 pComponentPrivate->bEnableCommandPending = 0; 1335 } 1336 else { 1337 pComponentPrivate->bEnableCommandPending = 1; 1338 pComponentPrivate->bEnableCommandParam = commandData; 1339 } 1340 } 1341 else if(commandData == -1){ 1342 if(pComponentPrivate->curState == OMX_StateLoaded || 1343 (pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->bPopulated 1344 && pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->bPopulated)){ 1345 1346 pComponentPrivate->cbInfo.EventHandler( 1347 pHandle, pHandle->pApplicationPrivate, 1348 OMX_EventCmdComplete, OMX_CommandPortEnable,G729DEC_INPUT_PORT, NULL); 1349 1350 pComponentPrivate->cbInfo.EventHandler( 1351 pHandle, pHandle->pApplicationPrivate, 1352 OMX_EventCmdComplete, OMX_CommandPortEnable,G729DEC_OUTPUT_PORT, NULL); 1353 1354 pComponentPrivate->bEnableCommandPending = 0; 1355 G729DECFill_LCMLInitParamsEx(pComponentPrivate->pHandle); 1356 pComponentPrivate->bJustReenabled = 1; 1357 } 1358 else { 1359 pComponentPrivate->bEnableCommandPending = 1; 1360 pComponentPrivate->bEnableCommandParam = commandData; 1361 } 1362 } 1363 #ifndef UNDER_CE 1364 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1365 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); 1366 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1367 #else 1368 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); 1369 #endif 1370 } 1371 else if (command == OMX_CommandFlush) { 1372 G729DEC_DPRINT("%d:: OMX_CommandFlush\n", __LINE__); 1373 OMX_U32 aParam[3] = {0}; 1374 if(commandData == 0x0 || commandData == -1) 1375 { 1376 if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0) { 1377 aParam[0] = USN_STRMCMD_FLUSH; 1378 aParam[1] = 0x0; 1379 aParam[2] = 0x0; 1380 G729DEC_DPRINT("Flushing input port\n"); 1381 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1382 EMMCodecControlStrmCtrl, (void*)aParam); 1383 if (eError != OMX_ErrorNone) 1384 { 1385 G729DEC_EPRINT("Error flushing input port: %d\n", eError); 1386 goto EXIT; 1387 } 1388 } 1389 else{ 1390 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE; 1391 } 1392 } 1393 if(commandData == 0x1 || commandData == -1) 1394 { 1395 if (pComponentPrivate->nUnhandledFillThisBuffers == 0) { 1396 aParam[0] = USN_STRMCMD_FLUSH; 1397 aParam[1] = 0x1; 1398 aParam[2] = 0x0; 1399 G729DEC_DPRINT("Flushing output port\n"); 1400 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1401 EMMCodecControlStrmCtrl, (void*)aParam); 1402 if (eError != OMX_ErrorNone) 1403 { 1404 G729DEC_DPRINT("Error flushing output port: %d\n", eError); 1405 goto EXIT; 1406 } 1407 } 1408 else{ 1409 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE; 1410 } 1411 } 1412 } 1413 EXIT: 1414 G729DEC_DPRINT ("%d :: Exiting G729DECHandleCommand Function\n",__LINE__); 1415 return eError; 1416 } 1417 1418 1419 /* ========================================================================== */ 1420 /** 1421 * @G729DECHandleDataBuf_FromApp() This function is called by the component when ever it 1422 * receives the buffer from the application 1423 * 1424 * @param pComponentPrivate Component private data 1425 * @param pBufHeader Buffer from the application 1426 * 1427 * @pre 1428 * 1429 * @post 1430 * 1431 * @return none 1432 */ 1433 /* ========================================================================== */ 1434 OMX_ERRORTYPE G729DECHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader, 1435 G729DEC_COMPONENT_PRIVATE *pComponentPrivate) 1436 { 1437 OMX_ERRORTYPE eError = OMX_ErrorNone; 1438 OMX_DIRTYPE eDir; 1439 LCML_G729DEC_BUFHEADERTYPE *pLcmlHdr = NULL; 1440 LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *) 1441 pComponentPrivate->pLcmlHandle; 1442 G729DEC_BufParamStruct* pInBufStruct=NULL; 1443 /* unsigned long int* bufParamsArray = NULL; */ 1444 1445 G729DEC_DPRINT ("%d :: Entering G729DECHandleDataBuf_FromApp Function\n",__LINE__); 1446 /*Find the direction of the received buffer from buffer list */ 1447 eError = G729DECGetBufferDirection(pBufHeader, &eDir); 1448 if (eError != OMX_ErrorNone) { 1449 G729DEC_DPRINT ("%d :: The PBufHeader is not found in the list\n", 1450 __LINE__); 1451 goto EXIT; 1452 } 1453 if (eDir == OMX_DirInput) { 1454 pComponentPrivate->nUnhandledEmptyThisBuffers--; 1455 /* bufParamsArray = malloc((10 * sizeof(unsigned long int)) + 256); 1456 bufParamsArray += 128; 1457 memset(bufParamsArray, 0, 9 * sizeof(unsigned long int)); */ 1458 pInBufStruct = (G729DEC_BufParamStruct*)pBufHeader->pInputPortPrivate; 1459 1460 if (pInBufStruct == NULL) { 1461 G729DEC_EPRINT("%d :: Error: input port NULL ...\n", __LINE__); 1462 goto EXIT; 1463 } 1464 /* fill array for SN params */ 1465 if(pInBufStruct->bNoUseDefaults == OMX_TRUE){ /*indicates that khronos conformance tests are NOT running */ 1466 pComponentPrivate->bufParamsArray[0] = 0; 1467 pComponentPrivate->bufParamsArray[1] = pInBufStruct->frameLost; 1468 pComponentPrivate->bufParamsArray[2] = pInBufStruct->numPackets; 1469 pComponentPrivate->bufParamsArray[3] = pInBufStruct->packetLength[0]; 1470 pComponentPrivate->bufParamsArray[4] = pInBufStruct->packetLength[1]; 1471 pComponentPrivate->bufParamsArray[5] = pInBufStruct->packetLength[2]; 1472 pComponentPrivate->bufParamsArray[6] = pInBufStruct->packetLength[3]; 1473 pComponentPrivate->bufParamsArray[7] = pInBufStruct->packetLength[4]; 1474 pComponentPrivate->bufParamsArray[8] = pInBufStruct->packetLength[5]; 1475 } 1476 else 1477 { 1478 pComponentPrivate->bufParamsArray[0] = 0; /* last frame flag */ 1479 pComponentPrivate->bufParamsArray[1] = 0; /* frame lost flag */ 1480 pComponentPrivate->bufParamsArray[2] = 1; /* number of frames in this buffer */ 1481 pComponentPrivate->bufParamsArray[3] = 11; /*lengths of each frame in bytes */ 1482 pComponentPrivate->bufParamsArray[4] = 0; 1483 pComponentPrivate->bufParamsArray[5] = 0; 1484 pComponentPrivate->bufParamsArray[6] = 0; 1485 pComponentPrivate->bufParamsArray[7] = 0; 1486 pComponentPrivate->bufParamsArray[8] = 0; 1487 } 1488 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr); 1489 if (eError != OMX_ErrorNone) { 1490 G729DEC_EPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1491 goto EXIT; 1492 } 1493 if(pBufHeader->nFlags == OMX_BUFFERFLAG_EOS){ /* Last input buffer from App. */ 1494 pBufHeader->nFlags = NORMAL_BUFFER; 1495 pLcmlHdr->pIpParam->usLastFrame = 1; 1496 pComponentPrivate->bufParamsArray[0] = 1; 1497 pComponentPrivate->bIsEOFSent = 1; 1498 } 1499 else{ 1500 pLcmlHdr->pIpParam->usLastFrame = 0; 1501 pComponentPrivate->bufParamsArray[0] = 0; 1502 } 1503 pLcmlHdr->pIpParam->usFrameLost = pInBufStruct->frameLost; 1504 if (pInBufStruct->frameLost == 1) { 1505 G729DEC_PRINT_INFO("Frame LOST event\n"); 1506 } 1507 /* Store time stamp information */ 1508 pComponentPrivate->arrTimestamp[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp; 1509 pComponentPrivate->arrTickCount[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount; 1510 pComponentPrivate->IpBufindex++; 1511 pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->nBufferCountActual; 1512 if (pComponentPrivate->curState == OMX_StateExecuting) { 1513 if (!G729DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) { 1514 G729DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput); 1515 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 1516 EMMCodecInputBuffer, 1517 (OMX_U8 *)pBufHeader->pBuffer, 1518 pBufHeader->nAllocLen, 1519 pBufHeader->nFilledLen, 1520 (OMX_U8 *) pComponentPrivate->bufParamsArray, 1521 sizeof(pComponentPrivate->bufParamsArray), 1522 NULL); 1523 if (eError != OMX_ErrorNone) { 1524 eError = OMX_ErrorHardware; 1525 goto EXIT; 1526 } 1527 pComponentPrivate->lcml_nCntIp++; 1528 pComponentPrivate->lcml_nIpBuf++; 1529 pComponentPrivate->num_Sent_Ip_Buff++; 1530 } 1531 } 1532 else if (pComponentPrivate->curState == OMX_StatePause) { 1533 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 1534 } 1535 if(pBufHeader->pMarkData){ 1536 /* copy mark to output buffer header */ 1537 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData; 1538 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent; 1539 1540 /* trigger event handler if we are supposed to */ 1541 if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){ 1542 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1543 pComponentPrivate->pHandle->pApplicationPrivate, 1544 OMX_EventMark, 1545 0, 1546 0, 1547 pBufHeader->pMarkData); 1548 } 1549 } 1550 if (pComponentPrivate->bFlushInputPortCommandPending) { 1551 OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL); 1552 } 1553 } 1554 1555 else if (eDir == OMX_DirOutput) { 1556 /* Make sure that output buffer is issued to output stream only when 1557 * there is an outstanding input buffer already issued on input stream 1558 */ 1559 pComponentPrivate->nUnhandledFillThisBuffers--; 1560 if (!(pComponentPrivate->bIsStopping)) { 1561 G729DEC_DPRINT ("%d: Sending Empty OUTPUT BUFFER to Codec = %p\n",__LINE__,pBufHeader->pBuffer); 1562 if (pComponentPrivate->curState == OMX_StateExecuting) 1563 { 1564 if (!G729DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) { 1565 G729DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput); 1566 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr); 1567 if (eError != OMX_ErrorNone) { 1568 G729DEC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1569 goto EXIT; 1570 } 1571 G729DEC_DPRINT("%d\n", __LINE__); 1572 pLcmlHdr->pIpParam->usLastFrame = 0; 1573 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 1574 EMMCodecOuputBuffer, 1575 (OMX_U8 *)pBufHeader->pBuffer, 1576 pBufHeader->nAllocLen, 1577 pBufHeader->nAllocLen, 1578 (OMX_U8 *) pLcmlHdr->pIpParam, 1579 sizeof(G729DEC_UAlgBufParamStruct), 1580 NULL); 1581 if (eError != OMX_ErrorNone ) { 1582 G729DEC_EPRINT ("%d :: IssuingDSP OP: Error Occurred\n",__LINE__); 1583 eError = OMX_ErrorHardware; 1584 goto EXIT; 1585 } 1586 G729DEC_DPRINT("%d\n", __LINE__); 1587 pComponentPrivate->lcml_nOpBuf++; 1588 pComponentPrivate->num_Op_Issued++; 1589 G729DEC_DPRINT("%d\n", __LINE__); 1590 } 1591 } 1592 else if (pComponentPrivate->curState == OMX_StatePause) 1593 { 1594 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader; 1595 } 1596 } 1597 else { 1598 if (pComponentPrivate->curState == OMX_StateExecuting) { 1599 if (!G729DEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) { 1600 G729DEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput); 1601 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr); 1602 if (eError != OMX_ErrorNone) { 1603 G729DEC_EPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1604 goto EXIT; 1605 } 1606 pLcmlHdr->pIpParam->usLastFrame = 0; 1607 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 1608 EMMCodecOuputBuffer, 1609 (OMX_U8 *)pBufHeader->pBuffer, 1610 pBufHeader->nAllocLen, 1611 pBufHeader->nAllocLen, 1612 (OMX_U8 *) pLcmlHdr->pIpParam, 1613 sizeof(G729DEC_UAlgBufParamStruct), 1614 NULL); 1615 if (eError != OMX_ErrorNone ) { 1616 G729DEC_EPRINT ("%d :: IssuingDSP OP: Error Occurred\n",__LINE__); 1617 eError = OMX_ErrorHardware; 1618 goto EXIT; 1619 } 1620 pComponentPrivate->lcml_nOpBuf++; 1621 pComponentPrivate->num_Op_Issued++; 1622 } 1623 } 1624 else if (pComponentPrivate->curState == OMX_StatePause){ 1625 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader; 1626 } 1627 } 1628 if (pComponentPrivate->bFlushOutputPortCommandPending) 1629 { 1630 OMX_SendCommand( pComponentPrivate->pHandle, 1631 OMX_CommandFlush, 1632 1,NULL); 1633 } 1634 } 1635 else { 1636 eError = OMX_ErrorBadParameter; 1637 } 1638 1639 EXIT: 1640 1641 G729DEC_DPRINT("%d : Exiting from G729DECHandleDataBuf_FromApp \n",__LINE__); 1642 return eError; 1643 } 1644 1645 /*-------------------------------------------------------------------*/ 1646 /** 1647 * G729DECGetBufferDirection () This function is used by the component thread to 1648 * request a buffer from the application. Since it was called from 2 places, 1649 * it made sense to turn this into a small function. 1650 * 1651 * @param pData pointer to G729 Decoder Context Structure 1652 * @param pCur pointer to the buffer to be requested to be filled 1653 * 1654 * @retval none 1655 **/ 1656 /*-------------------------------------------------------------------*/ 1657 1658 OMX_ERRORTYPE G729DECGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, 1659 OMX_DIRTYPE *eDir) 1660 { 1661 OMX_ERRORTYPE eError = OMX_ErrorNone; 1662 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate; 1663 OMX_U32 nBuf = 0; 1664 OMX_U32 i = 0; 1665 OMX_BUFFERHEADERTYPE *pBuf = NULL; 1666 OMX_S16 flag = 1; 1667 1668 G729DEC_DPRINT ("%d :: Entering G729DECGetBufferDirection Function\n",__LINE__); 1669 1670 /*Search this buffer in input buffers list */ 1671 nBuf = pComponentPrivate->pInputBufferList->numBuffers; 1672 for(i=0; i<nBuf; i++) { 1673 pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i]; 1674 if(pBufHeader == pBuf) { 1675 *eDir = OMX_DirInput; 1676 G729DEC_DPRINT ("%d :: Buffer %p is INPUT BUFFER\n",__LINE__, pBufHeader); 1677 flag = 0; 1678 goto EXIT; 1679 } 1680 } 1681 1682 /*Search this buffer in input buffers list */ 1683 nBuf = pComponentPrivate->pOutputBufferList->numBuffers; 1684 for(i=0; i<nBuf; i++) { 1685 pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 1686 if(pBufHeader == pBuf) { 1687 *eDir = OMX_DirOutput; 1688 G729DEC_DPRINT ("%d :: Buffer %p is OUTPUT BUFFER\n",__LINE__, pBufHeader); 1689 flag = 0; 1690 goto EXIT; 1691 } 1692 } 1693 1694 if (flag == 1) { 1695 G729DEC_DPRINT ("%d :: Buffer %p is Not Found in the List\n",__LINE__,pBufHeader); 1696 eError = OMX_ErrorUndefined; 1697 goto EXIT; 1698 } 1699 EXIT: 1700 G729DEC_DPRINT ("%d :: Exiting G729DECGetBufferDirection Function\n",__LINE__); 1701 return eError; 1702 } 1703 1704 /* -------------------------------------------------------------------*/ 1705 /** 1706 * Callback() function will be called LCML component to write the msg 1707 * 1708 * @param msgBuffer This buffer will be returned by the LCML 1709 * 1710 * @retval OMX_NoError Success, ready to roll 1711 * OMX_Error_BadParameter The input parameter pointer is null 1712 **/ 1713 /*-------------------------------------------------------------------*/ 1714 1715 1716 OMX_ERRORTYPE G729DECLCML_Callback (TUsnCodecEvent event,void * args [10]) 1717 { 1718 OMX_ERRORTYPE eError = OMX_ErrorNone; 1719 OMX_U8 *pBuffer = args[1]; 1720 LCML_G729DEC_BUFHEADERTYPE *pLcmlHdr = NULL; 1721 OMX_COMPONENTTYPE *pHandle = NULL; 1722 OMX_S16 i = 0; 1723 G729DEC_COMPONENT_PRIVATE* pComponentPrivate = NULL; 1724 OMX_ERRORTYPE rm_error = OMX_ErrorNone; 1725 1726 1727 G729DEC_DPRINT ("%d :: Entering the G729DECLCML_Callback Function\n",__LINE__); 1728 pComponentPrivate = pComponentPrivate_CC; 1729 G729DEC_DPRINT("event = %d\n",event); 1730 1731 pHandle = pComponentPrivate->pHandle; 1732 G729DEC_DPRINT("pHandle = %p\n", pHandle); 1733 G729DEC_DPRINT("pComponentPrivate = %p in lcmlCallback()\n", pComponentPrivate); 1734 1735 switch(event) { 1736 1737 case EMMCodecDspError: 1738 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecDspError\n"); 1739 break; 1740 1741 case EMMCodecInternalError: 1742 G729DEC_EPRINT("[LCML CALLBACK EVENT] EMMCodecInternalError\n"); 1743 break; 1744 1745 case EMMCodecInitError: 1746 G729DEC_EPRINT("[LCML CALLBACK EVENT] EMMCodecInitError\n"); 1747 break; 1748 1749 case EMMCodecDspMessageRecieved: 1750 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecDspMessageRecieved\n"); 1751 break; 1752 1753 case EMMCodecBufferProcessed: 1754 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecBufferProcessed\n"); 1755 break; 1756 1757 case EMMCodecProcessingStarted: 1758 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecProcessingStarted\n"); 1759 break; 1760 1761 case EMMCodecProcessingPaused: 1762 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecProcessingPaused\n"); 1763 break; 1764 1765 case EMMCodecProcessingStoped: 1766 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecProcessingStoped\n"); 1767 break; 1768 1769 case EMMCodecProcessingEof: 1770 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecProcessingEof\n"); 1771 break; 1772 1773 case EMMCodecBufferNotProcessed: 1774 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecBufferNotProcessed\n"); 1775 break; 1776 1777 case EMMCodecAlgCtrlAck: 1778 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecAlgCtrlAck\n"); 1779 break; 1780 1781 case EMMCodecStrmCtrlAck: 1782 G729DEC_DPRINT("[LCML CALLBACK EVENT] EMMCodecStrmCtrlAck\n"); 1783 break; 1784 } 1785 1786 if(event == EMMCodecBufferProcessed) 1787 { 1788 if( (OMX_U32)args [0] == EMMCodecInputBuffer) { 1789 1790 G729DEC_DPRINT("%d :: Input: pBufferr = %p\n",__LINE__, pBuffer); 1791 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirInput, &pLcmlHdr); 1792 if (eError != OMX_ErrorNone) { 1793 G729DEC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1794 goto EXIT; 1795 } 1796 1797 #ifdef __PERF_INSTRUMENTATION__ 1798 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 1799 PREF(pLcmlHdr->buffer, pBuffer), 0, 1800 PERF_ModuleCommonLayer); 1801 #endif 1802 1803 G729DEC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirInput); 1804 pComponentPrivate->cbInfo.EmptyBufferDone ( 1805 pComponentPrivate->pHandle, 1806 pComponentPrivate->pHandle->pApplicationPrivate, 1807 pLcmlHdr->buffer); 1808 pComponentPrivate->nEmptyBufferDoneCount++; 1809 pComponentPrivate->lcml_nIpBuf--; 1810 pComponentPrivate->app_nBuf++; 1811 } 1812 else if ((OMX_U32)args [0] == EMMCodecOuputBuffer) { 1813 G729DEC_DPRINT("%d :: Output: pBufferr = %p\n",__LINE__, pBuffer); 1814 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirOutput, &pLcmlHdr); 1815 if (eError != OMX_ErrorNone) { 1816 G729DEC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1817 goto EXIT; 1818 } 1819 pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8]; 1820 1821 #ifdef __PERF_INSTRUMENTATION__ 1822 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 1823 PREF(pLcmlHdr->buffer,pBuffer), 1824 PREF(pLcmlHdr->buffer,nFilledLen), 1825 PERF_ModuleCommonLayer); 1826 pComponentPrivate->nLcml_nCntOpReceived++; 1827 if ((pComponentPrivate->nLcml_nCntIp >= 1) && 1828 (pComponentPrivate->nLcml_nCntOpReceived == 1)) 1829 { 1830 PERF_Boundary(pComponentPrivate->pPERFcomp, 1831 PERF_BoundaryStart | PERF_BoundarySteadyState); 1832 } 1833 #endif 1834 1835 G729DEC_DPRINT("G729DECLCML_Callback::: pLcmlHdr->buffer->nFilledLen = %d\n",pLcmlHdr->buffer->nFilledLen); 1836 pComponentPrivate->lcml_nCntOpReceived++; 1837 1838 G729DEC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirOutput); 1839 pComponentPrivate->nOutStandingFillDones++; 1840 pComponentPrivate->num_Reclaimed_Op_Buff++; 1841 eError = G729DECGetCorresponding_LCMLHeader(pComponentPrivate, pLcmlHdr->buffer->pBuffer, OMX_DirOutput, &pLcmlHdr); 1842 if(pComponentPrivate->bIsEOFSent){ 1843 pLcmlHdr->buffer->nFlags=OMX_BUFFERFLAG_EOS; 1844 pComponentPrivate->bIsEOFSent = 0; 1845 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1846 pComponentPrivate->pHandle->pApplicationPrivate, 1847 OMX_EventBufferFlag, 1848 pLcmlHdr->buffer->nOutputPortIndex, 1849 pLcmlHdr->buffer->nFlags, NULL); 1850 } 1851 else{ 1852 pLcmlHdr->buffer->nFlags=NORMAL_BUFFER; 1853 } 1854 /* Copying time stamp information to output buffer */ 1855 pLcmlHdr->buffer->nTimeStamp = pComponentPrivate->arrTimestamp[pComponentPrivate->OpBufindex]; 1856 pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex]; 1857 pComponentPrivate->OpBufindex++; 1858 pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[G729DEC_DIRECTION_INPUT]->nBufferCountActual; 1859 pComponentPrivate->cbInfo.FillBufferDone ( 1860 pComponentPrivate->pHandle, 1861 pComponentPrivate->pHandle->pApplicationPrivate, 1862 pLcmlHdr->buffer 1863 ); 1864 pComponentPrivate->lcml_nOpBuf--; 1865 pComponentPrivate->app_nBuf++; 1866 pComponentPrivate->nFillBufferDoneCount++; 1867 pComponentPrivate->nOutStandingFillDones--; 1868 } 1869 } 1870 else if (event == EMMCodecStrmCtrlAck) 1871 { 1872 G729DEC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__); 1873 if (args[1] == (void *)USN_STRMCMD_FLUSH) 1874 { 1875 G729DEC_DPRINT("revceived USN_STRMCMD_FLUSH\n"); 1876 pHandle = pComponentPrivate->pHandle; 1877 if ( args[2] == (void *)EMMCodecInputBuffer) 1878 { 1879 if (args[0] == USN_ERR_NONE ) { 1880 G729DEC_DPRINT("Flushing input port %d\n"); 1881 for (i=0; i < MAX_NUM_OF_BUFS; i++) 1882 { 1883 pComponentPrivate->pInputBufHdrPending[i] = NULL; 1884 } 1885 pComponentPrivate->nNumInputBufPending=0; 1886 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) 1887 { 1888 pComponentPrivate->cbInfo.EmptyBufferDone ( 1889 pComponentPrivate->pHandle, 1890 pComponentPrivate->pHandle->pApplicationPrivate, 1891 pComponentPrivate->pInputBufferList->pBufHdr[i] 1892 ); 1893 } 1894 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 1895 OMX_EventCmdComplete, 1896 OMX_CommandFlush, 1897 G729DEC_INPUT_PORT, 1898 NULL); 1899 } 1900 else 1901 { 1902 G729DEC_EPRINT("error flushing input port.\n"); 1903 goto EXIT; 1904 } 1905 } 1906 else if ( args[2] == (void *)EMMCodecOuputBuffer) 1907 { 1908 if (args[0] == USN_ERR_NONE ) 1909 { 1910 G729DEC_DPRINT("Flushing output port %d\n"); 1911 for (i=0; i < MAX_NUM_OF_BUFS; i++) 1912 { 1913 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 1914 } 1915 pComponentPrivate->nNumOutputBufPending=0; 1916 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) 1917 { 1918 1919 #ifdef __PERF_INSTRUMENTATION__ 1920 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1921 pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer, 1922 pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen, 1923 PERF_ModuleHLMM); 1924 #endif 1925 1926 pComponentPrivate->cbInfo.FillBufferDone ( 1927 pComponentPrivate->pHandle, 1928 pComponentPrivate->pHandle->pApplicationPrivate, 1929 pComponentPrivate->pOutputBufferList->pBufHdr[i] 1930 ); 1931 } 1932 pComponentPrivate->cbInfo.EventHandler( 1933 pHandle, pHandle->pApplicationPrivate, 1934 OMX_EventCmdComplete, OMX_CommandFlush,G729DEC_OUTPUT_PORT, NULL); 1935 } 1936 else 1937 { 1938 G729DEC_EPRINT("error flushing output port.\n"); 1939 goto EXIT; 1940 } 1941 } 1942 } 1943 1944 1945 } 1946 else if(event == EMMCodecProcessingStoped) { 1947 G729DEC_DPRINT("pComponentPrivate->bNoIdleOnStop = %d\n",pComponentPrivate->bNoIdleOnStop); 1948 if (!pComponentPrivate->bNoIdleOnStop) { 1949 pComponentPrivate->bIdleCommandPending = OMX_TRUE; 1950 G729DEC_TransitionToIdle(pComponentPrivate); 1951 } 1952 else { 1953 pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE; 1954 int i; 1955 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 1956 G729DEC_DPRINT("pComponentPrivate->pInputBufferList->bBufferPending[%d] = %d\n",i,pComponentPrivate->pInputBufferList->bBufferPending[i]); 1957 if (pComponentPrivate->pInputBufferList->bBufferPending[i]) 1958 { 1959 pComponentPrivate->cbInfo.EmptyBufferDone ( 1960 pComponentPrivate->pHandle, 1961 pComponentPrivate->pHandle->pApplicationPrivate, 1962 pComponentPrivate->pInputBufferList->pBufHdr[i] 1963 ); 1964 G729DEC_ClearPending(pComponentPrivate, pComponentPrivate->pInputBufferList->pBufHdr[i], OMX_DirInput); 1965 } 1966 } 1967 pComponentPrivate->bNoIdleOnStop= OMX_FALSE; 1968 } 1969 } 1970 else if (event == EMMCodecProcessingPaused) { 1971 pComponentPrivate->curState = OMX_StatePause; 1972 /* Send StateChangeNotification to application */ 1973 pComponentPrivate->cbInfo.EventHandler( 1974 pComponentPrivate->pHandle, 1975 pComponentPrivate->pHandle->pApplicationPrivate, 1976 OMX_EventCmdComplete, OMX_CommandStateSet, pComponentPrivate->curState,NULL); 1977 1978 } 1979 1980 else if (event == EMMCodecDspError) { 1981 if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) { 1982 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 1983 G729DEC_DPRINT("%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__); 1984 pComponentPrivate->bPlayCompleteFlag = 1; 1985 pComponentPrivate->curState = OMX_StateIdle; 1986 1987 #ifdef RESOURCE_MANAGER_ENABLED 1988 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G729_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL); 1989 #endif 1990 } 1991 if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_OVERFLOW)) { 1992 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 1993 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 1994 OMX_EventError, OMX_ErrorOverflow, 1995 pComponentPrivate->curState, NULL); 1996 G729DEC_DPRINT("%d :: GOT WARNING IUALG_WARN_OVERFLOW\n",__LINE__); 1997 } 1998 if(((int)args[4] == USN_ERR_PROCESS) && ((int)args[5] == IUALG_ERR_DATA_CORRUPT)){ 1999 OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle; 2000 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 2001 OMX_EventError, OMX_ErrorStreamCorrupt, 2002 pComponentPrivate->curState, NULL); 2003 G729DEC_DPRINT("%d :: GOT ERROR IUALG_ERR_DATA_CORRUPT\n",__LINE__); 2004 } 2005 } 2006 2007 if(event == EMMCodecDspMessageRecieved) { 2008 G729DEC_DPRINT("%d :: commandedState = %d\n",__LINE__,args[0]); 2009 G729DEC_DPRINT("%d :: arg1 = %d\n",__LINE__,args[1]); 2010 G729DEC_DPRINT("%d :: arg2 = %d\n",__LINE__,args[2]); 2011 } 2012 2013 EXIT: 2014 G729DEC_DPRINT ("%d :: Exiting the G729DECLCML_Callback Function\n",__LINE__); 2015 return eError; 2016 } 2017 2018 2019 OMX_ERRORTYPE G729DECGetCorresponding_LCMLHeader(G729DEC_COMPONENT_PRIVATE* pComponentPrivate, 2020 OMX_U8 *pBuffer, 2021 OMX_DIRTYPE eDir, 2022 LCML_G729DEC_BUFHEADERTYPE **ppLcmlHdr) 2023 { 2024 OMX_ERRORTYPE eError = OMX_ErrorNone; 2025 LCML_G729DEC_BUFHEADERTYPE *pLcmlBufHeader = NULL; 2026 OMX_S16 nIpBuf = 0; 2027 OMX_S16 nOpBuf = 0; 2028 OMX_S16 i = 0; 2029 2030 nIpBuf = (OMX_S16)pComponentPrivate->pInputBufferList->numBuffers; 2031 nOpBuf = (OMX_S16)pComponentPrivate->pOutputBufferList->numBuffers; 2032 G729DEC_DPRINT("enter get corresponding LCML header\n"); 2033 G729DEC_DPRINT("pComponentPrivate = %p\n",pComponentPrivate); 2034 G729DEC_DPRINT("eDir = %d\n",eDir); 2035 if(eDir == OMX_DirInput) { 2036 G729DEC_DPRINT("pComponentPrivate = %p\n",pComponentPrivate); 2037 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT]; 2038 for(i=0; i<nIpBuf; i++) { 2039 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) { 2040 *ppLcmlHdr = pLcmlBufHeader; 2041 G729DEC_DPRINT("%d::Corresponding LCML Header Found\n",__LINE__); 2042 goto EXIT; 2043 } 2044 pLcmlBufHeader++; 2045 } 2046 } 2047 else if (eDir == OMX_DirOutput) { 2048 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT]; 2049 for(i=0; i<nOpBuf; i++) { 2050 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) { 2051 G729DEC_DPRINT("pBuffer = %p\n",pBuffer); 2052 G729DEC_DPRINT("pLcmlBufHeader->buffer->pBuffer = %p\n",pLcmlBufHeader->buffer->pBuffer); 2053 *ppLcmlHdr = pLcmlBufHeader; 2054 G729DEC_DPRINT("%d::Corresponding LCML Header Found\n",__LINE__); 2055 goto EXIT; 2056 } 2057 pLcmlBufHeader++; 2058 } 2059 } 2060 else { 2061 G729DEC_DPRINT("%d:: Invalid Buffer Type :: exiting...\n",__LINE__); 2062 } 2063 2064 EXIT: 2065 return eError; 2066 } 2067 2068 2069 #ifndef UNDER_CE 2070 2071 OMX_HANDLETYPE G729DECGetLCMLHandle(G729DEC_COMPONENT_PRIVATE* pComponentPrivate) 2072 { 2073 void *handle = NULL; 2074 OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE); 2075 OMX_HANDLETYPE pHandle = NULL; 2076 OMX_S8 *error = NULL; 2077 OMX_ERRORTYPE eError = OMX_ErrorNone; 2078 2079 G729DEC_DPRINT("G729DECGetLCMLHandle %d\n",__LINE__); 2080 handle = dlopen("libLCML.so", RTLD_LAZY); 2081 if (!handle) { 2082 fputs(dlerror(), stderr); 2083 goto EXIT; 2084 } 2085 2086 fpGetHandle = dlsym (handle, "GetHandle"); 2087 if ((error = (OMX_S8 *)dlerror()) != NULL) { 2088 fputs((char *)error, stderr); 2089 goto EXIT; 2090 } 2091 eError = (*fpGetHandle)(&pHandle); 2092 if(eError != OMX_ErrorNone) { 2093 eError = OMX_ErrorUndefined; 2094 G729DEC_EPRINT("eError != OMX_ErrorNone...\n"); 2095 pHandle = NULL; 2096 goto EXIT; 2097 } 2098 2099 pComponentPrivate->bLcmlHandleOpened = 1; 2100 2101 EXIT: 2102 G729DEC_DPRINT("G729GetLCMLHandle returning %p\n",pHandle); 2103 2104 return pHandle; 2105 } 2106 2107 2108 #else 2109 2110 //WINDOWS Explicit dll load procedure 2111 2112 OMX_HANDLETYPE G729DECGetLCMLHandle(G729DEC_COMPONENT_PRIVATE* pComponentPrivate) 2113 { 2114 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE); 2115 OMX_HANDLETYPE pHandle = NULL; 2116 OMX_ERRORTYPE eError = OMX_ErrorNone; 2117 LPFNDLLFUNC1 fpGetHandle1; 2118 2119 2120 g_hLcmlDllHandle = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0); 2121 if (g_hLcmlDllHandle == NULL) 2122 { 2123 //fputs(dlerror(), stderr); 2124 G729DEC_EPRINT("BML Load Failed!!!\n"); 2125 return pHandle; 2126 } 2127 2128 fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(g_hLcmlDllHandle,TEXT("GetHandle")); 2129 if (!fpGetHandle1) 2130 { 2131 // handle the error 2132 FreeLibrary(g_hLcmlDllHandle); 2133 g_hLcmlDllHandle = NULL; 2134 return pHandle; 2135 } 2136 2137 // call the function 2138 eError = fpGetHandle1(&pHandle); 2139 if(eError != OMX_ErrorNone) { 2140 eError = OMX_ErrorUndefined; 2141 G729DEC_EPRINT("eError != OMX_ErrorNone...\n"); 2142 FreeLibrary(g_hLcmlDllHandle); 2143 g_hLcmlDllHandle = NULL; 2144 pHandle = NULL; 2145 return pHandle; 2146 } 2147 return pHandle; 2148 } 2149 2150 2151 #endif 2152 2153 2154 #ifndef UNDER_CE 2155 2156 OMX_ERRORTYPE G729DECFreeLCMLHandle(G729DEC_COMPONENT_PRIVATE* pComponentPrivate) 2157 { 2158 2159 OMX_S16 retValue = 0; 2160 OMX_ERRORTYPE eError = OMX_ErrorNone; 2161 2162 if (pComponentPrivate->bLcmlHandleOpened) { 2163 retValue = dlclose(pComponentPrivate->pLcmlHandle); 2164 2165 if (retValue != 0) { 2166 eError = OMX_ErrorUndefined; 2167 } 2168 pComponentPrivate->bLcmlHandleOpened = 0; 2169 } 2170 2171 return eError; 2172 } 2173 #else 2174 2175 2176 OMX_ERRORTYPE G729DECFreeLCMLHandle(G729DEC_COMPONENT_PRIVATE* pComponentPrivate) 2177 { 2178 2179 OMX_S16 retValue = 0; 2180 OMX_ERRORTYPE eError = OMX_ErrorNone; 2181 2182 if (pComponentPrivate->bLcmlHandleOpened) { 2183 2184 retValue = FreeLibrary(pComponentPrivate->pLcmlHandle); 2185 if (retValue == 0) { /* Zero Indicates failure */ 2186 eError = OMX_ErrorUndefined; 2187 } 2188 pComponentPrivate->bLcmlHandleOpened = 0; 2189 } 2190 2191 return eError; 2192 } 2193 2194 2195 2196 #endif 2197 2198 void G729DEC_SetPending(G729DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) 2199 { 2200 OMX_U16 i = 0; 2201 2202 if (eDir == OMX_DirInput) { 2203 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2204 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2205 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1; 2206 G729DEC_DPRINT("*******************INPUT BUFFER %d IS PENDING******************************\n",i); 2207 } 2208 } 2209 } 2210 else { 2211 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2212 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2213 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1; 2214 G729DEC_DPRINT("*******************OUTPUT BUFFER %d IS PENDING******************************\n",i); 2215 } 2216 } 2217 } 2218 } 2219 2220 void G729DEC_ClearPending(G729DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) 2221 { 2222 OMX_U16 i = 0; 2223 2224 if (eDir == OMX_DirInput) { 2225 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2226 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2227 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0; 2228 G729DEC_DPRINT("*******************INPUT BUFFER %d IS RECLAIMED******************************\n",i); 2229 } 2230 } 2231 } 2232 else { 2233 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2234 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2235 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0; 2236 G729DEC_DPRINT("*******************OUTPUT BUFFER %d IS RECLAIMED ******************************\n",i); 2237 } 2238 } 2239 } 2240 } 2241 2242 OMX_U32 G729DEC_IsPending(G729DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) 2243 { 2244 OMX_U16 i = 0; 2245 2246 if (eDir == OMX_DirInput) { 2247 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2248 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2249 return pComponentPrivate->pInputBufferList->bBufferPending[i]; 2250 } 2251 } 2252 } 2253 else { 2254 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2255 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2256 return pComponentPrivate->pOutputBufferList->bBufferPending[i]; 2257 } 2258 } 2259 } 2260 return -1; 2261 } 2262 2263 2264 OMX_U32 G729DEC_IsValid(G729DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) 2265 { 2266 OMX_U16 i = 0; 2267 OMX_S16 found=0; 2268 2269 if (eDir == OMX_DirInput) { 2270 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2271 if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) { 2272 found = 1; 2273 } 2274 } 2275 } 2276 else { 2277 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2278 if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) { 2279 found = 1; 2280 } 2281 } 2282 } 2283 return found; 2284 } 2285 2286 2287 OMX_ERRORTYPE G729DECFill_LCMLInitParamsEx (OMX_HANDLETYPE pComponent ) 2288 { 2289 OMX_ERRORTYPE eError = OMX_ErrorNone; 2290 OMX_U32 nIpBuf = 0,nIpBufSize = 0,nOpBuf = 0,nOpBufSize = 0; 2291 OMX_U16 i = 0; 2292 OMX_BUFFERHEADERTYPE *pTemp = NULL; 2293 OMX_S16 size_lcml = 0; 2294 LCML_STRMATTR *strmAttr = NULL; 2295 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent; 2296 G729DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 2297 LCML_G729DEC_BUFHEADERTYPE *pTemp_lcml = NULL; 2298 2299 G729DEC_DPRINT("%d :: G729DECFill_LCMLInitParams\n ",__LINE__); 2300 G729DEC_DPRINT("%d :: pHandle = %p\n",__LINE__,pHandle); 2301 G729DEC_DPRINT("%d :: pHandle->pComponentPrivate = %p\n",__LINE__,pHandle->pComponentPrivate); 2302 pComponentPrivate = pHandle->pComponentPrivate; 2303 2304 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 2305 nIpBufSize = pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]->nBufferSize; 2306 2307 2308 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 2309 nOpBufSize = pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]->nBufferSize; 2310 2311 2312 size_lcml = (OMX_U16)(nIpBuf * sizeof(LCML_G729DEC_BUFHEADERTYPE)); 2313 pTemp_lcml = (LCML_G729DEC_BUFHEADERTYPE *)malloc(size_lcml); 2314 G729DEC_MEMPRINT("%d:[ALLOC] %p\n",__LINE__,pTemp_lcml); 2315 if(pTemp_lcml == NULL) { 2316 G729DEC_EPRINT("%d :: Memory Allocation Failed\n",__LINE__); 2317 /* Free previously allocated memory before bailing */ 2318 if (strmAttr) { 2319 free(strmAttr); 2320 strmAttr = NULL; 2321 } 2322 eError = OMX_ErrorInsufficientResources; 2323 goto EXIT; 2324 } 2325 memset(pTemp_lcml, 0x0, size_lcml); 2326 pComponentPrivate->pLcmlBufHeader[G729DEC_INPUT_PORT] = pTemp_lcml; 2327 2328 for (i=0; i<nIpBuf; i++) { 2329 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 2330 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2331 pTemp->nAllocLen = nIpBufSize; 2332 pTemp->nFilledLen = nIpBufSize; 2333 pTemp->nVersion.s.nVersionMajor = G729DEC_MAJOR_VER; 2334 pTemp->nVersion.s.nVersionMinor = G729DEC_MINOR_VER; 2335 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 2336 pTemp_lcml->buffer = pTemp; 2337 pTemp_lcml->eDir = OMX_DirInput; 2338 2339 OMX_G729MALLOC_STRUCT(pTemp_lcml->pIpParam, G729DEC_UAlgBufParamStruct); 2340 pTemp_lcml->pIpParam->usFrameLost = 0; 2341 pTemp_lcml->pIpParam->usLastFrame = 0; 2342 2343 /* This means, it is not a last buffer. This flag is to be modified by 2344 * the application to indicate the last buffer */ 2345 pTemp->nFlags = NORMAL_BUFFER; 2346 2347 pTemp_lcml++; 2348 } 2349 2350 /* Allocate memory for all output buffer headers.. 2351 * This memory pointer will be sent to LCML */ 2352 size_lcml = (OMX_U16)(nOpBuf * sizeof(LCML_G729DEC_BUFHEADERTYPE)); 2353 pTemp_lcml = (LCML_G729DEC_BUFHEADERTYPE *)malloc(size_lcml); 2354 G729DEC_MEMPRINT("%d:[ALLOC] %p\n",__LINE__,pTemp_lcml); 2355 if(pTemp_lcml == NULL) { 2356 /* Free previously allocated memory before bailing */ 2357 if (strmAttr) { 2358 free(strmAttr); 2359 strmAttr = NULL; 2360 } 2361 eError = OMX_ErrorInsufficientResources; 2362 goto EXIT; 2363 } 2364 memset(pTemp_lcml, 0x0, size_lcml); 2365 pComponentPrivate->pLcmlBufHeader[G729DEC_OUTPUT_PORT] = pTemp_lcml; 2366 2367 for (i=0; i<nOpBuf; i++) { 2368 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 2369 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2370 pTemp->nAllocLen = nOpBufSize; 2371 pTemp->nFilledLen = nOpBufSize; 2372 pTemp->nVersion.s.nVersionMajor = G729DEC_MAJOR_VER; 2373 pTemp->nVersion.s.nVersionMinor = G729DEC_MINOR_VER; 2374 pComponentPrivate->nVersion = pTemp->nVersion.nVersion; 2375 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 2376 pTemp->nTickCount = 0; 2377 pTemp->nTimeStamp = 0; 2378 /* This means, it is not a last buffer. This flag is to be modified by 2379 * the application to indicate the last buffer */ 2380 2381 pTemp_lcml->buffer = pTemp; 2382 pTemp_lcml->eDir = OMX_DirOutput; 2383 G729DEC_DPRINT("%d:::pTemp_lcml = %p\n",__LINE__,pTemp_lcml); 2384 G729DEC_DPRINT("%d:::pTemp_lcml->buffer = %p\n",__LINE__,pTemp_lcml->buffer); 2385 2386 OMX_G729MALLOC_STRUCT(pTemp_lcml->pIpParam, G729DEC_UAlgBufParamStruct); 2387 pTemp_lcml->pIpParam->usFrameLost = 0; 2388 pTemp_lcml->pIpParam->usLastFrame = 0; 2389 2390 pTemp->nFlags = NORMAL_BUFFER; 2391 2392 pTemp++; 2393 pTemp_lcml++; 2394 } 2395 pComponentPrivate->bPortDefsAllocated = 1; 2396 G729DEC_DPRINT("%d :: Exiting G729DECFill_LCMLInitParams",__LINE__); 2397 2398 pComponentPrivate->bInitParamsInitialized = 1; 2399 EXIT: 2400 return eError; 2401 } 2402 /* ================================================================================= */ 2403 /** 2404 * @fn G729DEC_TransitionToIdle() Transition component to OMX_StateIdle 2405 G729DEC_TransitionToIdle(). 2406 This method transitions the component to OMX_StateIdle 2407 * @param pComponent handle for this instance of the component 2408 * 2409 * @pre 2410 * 2411 * @post 2412 * 2413 * @return OMX_ERRORTYPE 2414 */ 2415 /* ================================================================================ */ 2416 OMX_ERRORTYPE G729DEC_TransitionToIdle(G729DEC_COMPONENT_PRIVATE *pComponentPrivate) 2417 { 2418 OMX_ERRORTYPE eError = OMX_ErrorNone; 2419 OMX_ERRORTYPE rm_error = OMX_ErrorNone; 2420 OMX_U16 i = 0; 2421 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 2422 2423 G729DEC_DPRINT("Entered G729DEC_TransitionToIdle\n"); 2424 G729DEC_DPRINT("pComponentPrivate->nOutStandingFillDones = %d\n",pComponentPrivate->nOutStandingFillDones); 2425 2426 2427 if (pComponentPrivate->nOutStandingFillDones <= 0) { 2428 2429 /* If there are any buffers still marked as pending they must have 2430 been queued after the socket node was stopped */ 2431 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2432 if (pComponentPrivate->pInputBufferList->bBufferPending[i]) 2433 { 2434 2435 #ifdef __PERF_INSTRUMENTATION__ 2436 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2437 pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer, 2438 0, 2439 PERF_ModuleHLMM); 2440 #endif 2441 2442 pComponentPrivate->cbInfo.EmptyBufferDone ( 2443 pComponentPrivate->pHandle, 2444 pComponentPrivate->pHandle->pApplicationPrivate, 2445 pComponentPrivate->pInputBufferList->pBufHdr[i] 2446 ); 2447 G729DEC_ClearPending(pComponentPrivate, pComponentPrivate->pInputBufferList->pBufHdr[i], OMX_DirInput); 2448 } 2449 } 2450 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2451 if (pComponentPrivate->pOutputBufferList->bBufferPending[i]) 2452 { 2453 #ifdef __PERF_INSTRUMENTATION__ 2454 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 2455 pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer, 2456 pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen, 2457 PERF_ModuleHLMM); 2458 #endif 2459 pComponentPrivate->cbInfo.FillBufferDone ( 2460 pComponentPrivate->pHandle, 2461 pComponentPrivate->pHandle->pApplicationPrivate, 2462 pComponentPrivate->pOutputBufferList->pBufHdr[i] 2463 ); 2464 pComponentPrivate->nOutStandingFillDones--; 2465 G729DEC_ClearPending(pComponentPrivate, pComponentPrivate->pOutputBufferList->pBufHdr[i], OMX_DirOutput); 2466 } 2467 } 2468 G729DEC_DPRINT("Setting to OMX_StateIdle - Line %d\n",__LINE__); 2469 pComponentPrivate->curState = OMX_StateIdle; 2470 2471 #ifdef RESOURCE_MANAGER_ENABLED 2472 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G729_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL); 2473 #endif 2474 2475 if (pComponentPrivate->bPreempted == 0) 2476 { 2477 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2478 pComponentPrivate->pHandle->pApplicationPrivate, 2479 OMX_EventCmdComplete, 2480 OMX_CommandStateSet, 2481 pComponentPrivate->curState, 2482 NULL); 2483 } 2484 else 2485 { 2486 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2487 pComponentPrivate->pHandle->pApplicationPrivate, 2488 OMX_EventError, 2489 OMX_ErrorResourcesPreempted, 2490 0, 2491 NULL); 2492 2493 } 2494 pComponentPrivate->bIdleCommandPending = OMX_FALSE; 2495 } 2496 return eError; 2497 } 2498 2499 2500 #ifdef RESOURCE_MANAGER_ENABLED 2501 /*********************************** 2502 * Callback to the RM * 2503 ***********************************/ 2504 void G729DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData) 2505 { 2506 OMX_COMMANDTYPE Cmd = OMX_CommandStateSet; 2507 OMX_STATETYPE state = OMX_StateIdle; 2508 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent; 2509 G729DEC_COMPONENT_PRIVATE *pCompPrivate = NULL; 2510 2511 pCompPrivate = (G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 2512 2513 if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){ 2514 if (pCompPrivate->curState == OMX_StateExecuting || 2515 pCompPrivate->curState == OMX_StatePause) { 2516 2517 write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 2518 write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32)); 2519 2520 pCompPrivate->bPreempted = 1; 2521 } 2522 } 2523 else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){ 2524 pCompPrivate->cbInfo.EventHandler ( pHandle, 2525 pHandle->pApplicationPrivate, 2526 OMX_EventResourcesAcquired, 2527 0, 0, NULL); 2528 } 2529 } 2530 #endif 2531