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_AmrEnc_Utils.c 30 * 31 * This file implements NBAMR Encoder Component Specific APIs and its functionality 32 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification 33 * 34 * @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\nbamr_enc\src 35 * 36 * @rev 1.0 37 */ 38 /* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! 21-sept-2006 bk: updated review findings for alpha release 43 *! 24-Aug-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests some more 44 *! 18-July-2006 bk: Khronos OpenMAX (TM) 1.0 Conformance tests validated for few cases 45 *! 21-Jun-2006 bk: Khronos OpenMAX (TM) 1.0 migration done 46 *! 22-May-2006 bk: DASF recording quality improved 47 *! 19-Apr-2006 bk: DASF recording speed issue resloved 48 *! 23-Feb-2006 bk: DASF functionality added 49 *! 18-Jan-2006 bk: Repated recording issue fixed and LCML changes taken care 50 *! 14-Dec-2005 bk: Initial Version 51 *! 16-Nov-2005 bk: Initial Version 52 *! 23-Sept-2005 bk: Initial Version 53 *! 10-Sept-2005 bk: Initial Version 54 *! 10-Sept-2005 bk: 55 *! This is newest file 56 * =========================================================================== */ 57 58 /* ------compilation control switches -------------------------*/ 59 /**************************************************************** 60 * INCLUDE FILES 61 ****************************************************************/ 62 /* ----- system and platform files ----------------------------*/ 63 #ifdef UNDER_CE 64 #include <windows.h> 65 #include <oaf_osal.h> 66 #include <omx_core.h> 67 #else 68 #include <wchar.h> 69 #include <unistd.h> 70 #include <sys/types.h> 71 #include <sys/wait.h> 72 #include <sys/types.h> 73 #include <sys/stat.h> 74 #include <dlfcn.h> 75 #include <malloc.h> 76 #include <memory.h> 77 #include <fcntl.h> 78 #include <errno.h> 79 #endif 80 81 #include <dbapi.h> 82 #include <string.h> 83 #include <stdio.h> 84 #include <stdlib.h> 85 /*-------program files ----------------------------------------*/ 86 #include "OMX_AmrEnc_Utils.h" 87 #include "amrencsocket_ti.h" 88 #include <encode_common_ti.h> 89 #include "OMX_AmrEnc_ComponentThread.h" 90 #include "usn.h" 91 #include "LCML_DspCodec.h" 92 93 #ifdef RESOURCE_MANAGER_ENABLED 94 #include <ResourceManagerProxyAPI.h> 95 #endif 96 97 /* ========================================================================== */ 98 /** 99 * @NBAMRENC_FillLCMLInitParams () This function is used by the component thread to 100 * fill the all of its initialization parameters, buffer deatils etc 101 * to LCML structure, 102 * 103 * @param pComponent handle for this instance of the component 104 * @param plcml_Init pointer to LCML structure to be filled 105 * 106 * @pre 107 * 108 * @post 109 * 110 * @return none 111 */ 112 /* ========================================================================== */ 113 114 OMX_ERRORTYPE NBAMRENC_FillLCMLInitParams(OMX_HANDLETYPE pComponent, 115 LCML_DSP *plcml_Init, OMX_U16 arr[]) 116 { 117 OMX_ERRORTYPE eError = OMX_ErrorNone; 118 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize; 119 OMX_BUFFERHEADERTYPE *pTemp; 120 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent; 121 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate; 122 NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL; 123 OMX_U16 i; 124 OMX_U32 size_lcml; 125 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_FillLCMLInitParams\n",__LINE__); 126 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 127 nIpBufSize = pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->nBufferSize; 128 pComponentPrivate->nRuntimeInputBuffers = nIpBuf; 129 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 130 nOpBufSize = pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->nBufferSize; 131 pComponentPrivate->nRuntimeOutputBuffers = nOpBuf; 132 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__); 133 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input Buffer Count = %ld\n",__LINE__,nIpBuf); 134 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Input Buffer Size = %ld\n",__LINE__,nIpBufSize); 135 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf); 136 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize); 137 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__); 138 /* Fill Input Buffers Info for LCML */ 139 plcml_Init->In_BufInfo.nBuffers = nIpBuf; 140 plcml_Init->In_BufInfo.nSize = nIpBufSize; 141 plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD; 142 143 /* Fill Output Buffers Info for LCML */ 144 plcml_Init->Out_BufInfo.nBuffers = nOpBuf; 145 plcml_Init->Out_BufInfo.nSize = nOpBufSize; 146 plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD; 147 148 /*Copy the node information*/ 149 plcml_Init->NodeInfo.nNumOfDLLs = 3; 150 151 plcml_Init->NodeInfo.AllUUIDs[0].uuid = &AMRENCSOCKET_TI_UUID; 152 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,NBAMRENC_DLL_NAME); 153 plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 154 155 plcml_Init->NodeInfo.AllUUIDs[1].uuid = &AMRENCSOCKET_TI_UUID; 156 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,NBAMRENC_DLL_NAME); 157 plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 158 159 plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID; 160 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName,NBAMRENC_USN_DLL_NAME); 161 plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 162 plcml_Init->DeviceInfo.TypeofDevice = 0; 163 164 if(pComponentPrivate->dasfMode == 1) { 165 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to DASF mode\n",__LINE__); 166 OMX_MALLOC_GENERIC(pComponentPrivate->strmAttr, LCML_STRMATTR); 167 pComponentPrivate->strmAttr->uSegid = NBAMRENC_DEFAULT_SEGMENT; 168 pComponentPrivate->strmAttr->uAlignment = 0; 169 pComponentPrivate->strmAttr->uTimeout = NBAMRENC_SN_TIMEOUT; 170 pComponentPrivate->strmAttr->uBufsize = NBAMRENC_INPUT_BUFFER_SIZE_DASF; 171 pComponentPrivate->strmAttr->uNumBufs = NBAMRENC_NUM_INPUT_BUFFERS_DASF; 172 pComponentPrivate->strmAttr->lMode = STRMMODE_PROCCOPY; 173 /* Device is Configuring to DASF Mode */ 174 plcml_Init->DeviceInfo.TypeofDevice = 1; 175 /* Device is Configuring to Record Mode */ 176 plcml_Init->DeviceInfo.TypeofRender = 1; 177 178 if(pComponentPrivate->acdnMode == 1) { 179 /* ACDN mode */ 180 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &ACDN_TI_UUID; 181 } 182 else { 183 /* DASF/TeeDN mode */ 184 if(pComponentPrivate->teeMode!= TEEMODE_NONE) { 185 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &TEEDN_TI_UUID; 186 } 187 else { 188 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID; 189 } 190 } 191 plcml_Init->DeviceInfo.DspStream = pComponentPrivate->strmAttr; 192 } 193 194 /*copy the other information*/ 195 plcml_Init->SegID = NBAMRENC_DEFAULT_SEGMENT; 196 plcml_Init->Timeout = NBAMRENC_SN_TIMEOUT; 197 plcml_Init->Alignment = 0; 198 plcml_Init->Priority = NBAMRENC_SN_PRIORITY; 199 plcml_Init->ProfileID = -1; 200 201 /* Setting Creat Phase Parameters here */ 202 arr[0] = NBAMRENC_STREAM_COUNT; 203 arr[1] = NBAMRENC_INPUT_PORT; 204 205 if(pComponentPrivate->dasfMode == 1) { 206 arr[2] = NBAMRENC_INSTRM; 207 arr[3] = NBAMRENC_NUM_INPUT_BUFFERS_DASF; 208 } 209 else { 210 arr[2] = NBAMRENC_DMM; 211 if (pComponentPrivate->pInputBufferList->numBuffers) { 212 arr[3] = (OMX_U16) pComponentPrivate->pInputBufferList->numBuffers; 213 } 214 else { 215 arr[3] = 1; 216 } 217 } 218 219 arr[4] = NBAMRENC_OUTPUT_PORT; 220 arr[5] = NBAMRENC_DMM; 221 if (pComponentPrivate->pOutputBufferList->numBuffers) { 222 arr[6] = (OMX_U16) pComponentPrivate->pOutputBufferList->numBuffers; 223 } 224 else { 225 arr[6] = 1; 226 } 227 228 if (pComponentPrivate->efrMode == 1) { 229 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to EFR mode\n",__LINE__); 230 arr[7] = NBAMRENC_EFR; 231 } 232 else { 233 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to NBAMR mode\n",__LINE__); 234 arr[7] = NBAMRENC_NBAMR; 235 } 236 237 if(pComponentPrivate->frameMode == NBAMRENC_MIMEMODE ) { 238 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring MIME mode\n",__LINE__); 239 arr[8] = NBAMRENC_MIMEMODE; 240 } 241 else if(pComponentPrivate->frameMode == NBAMRENC_IF2 ){ 242 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring IF2 mode\n",__LINE__); 243 arr[8] = NBAMRENC_IF2; 244 } 245 else { 246 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring FORMAT CONFORMANCE mode\n",__LINE__); 247 arr[8] = NBAMRENC_FORMATCONFORMANCE; 248 } 249 arr[9] = END_OF_CR_PHASE_ARGS; 250 251 plcml_Init->pCrPhArgs = arr; 252 253 /* Allocate memory for all input buffer headers.. 254 * This memory pointer will be sent to LCML */ 255 size_lcml = nIpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE); 256 257 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE); 258 259 pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT] = pTemp_lcml; 260 for (i=0; i<nIpBuf; i++) { 261 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: INPUT--------- Inside Ip Loop\n",__LINE__); 262 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 263 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 264 pTemp->nFilledLen = nIpBufSize; 265 pTemp->nVersion.s.nVersionMajor = NBAMRENC_MAJOR_VER; 266 pTemp->nVersion.s.nVersionMinor = NBAMRENC_MINOR_VER; 267 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 268 pTemp->nTickCount = NBAMRENC_NOT_USED; 269 pTemp_lcml->buffer = pTemp; 270 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer); 271 pTemp_lcml->eDir = OMX_DirInput; 272 273 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, sizeof(NBAMRENC_ParamStruct),OMX_U8); 274 275 pTemp_lcml->pBufferParam->usNbFrames=0; 276 pTemp_lcml->pBufferParam->pParamElem=NULL; 277 pTemp_lcml->pFrameParam=NULL; 278 279 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ); 280 281 /* This means, it is not a last buffer. This flag is to be modified by 282 * the application to indicate the last buffer */ 283 pTemp->nFlags = NBAMRENC_NORMAL_BUFFER; 284 pTemp++; 285 pTemp_lcml++; 286 } 287 288 /* Allocate memory for all output buffer headers.. 289 * This memory pointer will be sent to LCML */ 290 size_lcml = nOpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE); 291 292 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE); 293 294 pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT] = pTemp_lcml; 295 for (i=0; i<nOpBuf; i++) { 296 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OUTPUT--------- Inside Op Loop\n",__LINE__); 297 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 298 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 299 pTemp->nFilledLen = nOpBufSize; 300 pTemp->nVersion.s.nVersionMajor = NBAMRENC_MAJOR_VER; 301 pTemp->nVersion.s.nVersionMinor = NBAMRENC_MINOR_VER; 302 pComponentPrivate->nVersion = pTemp->nVersion.nVersion; 303 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 304 pTemp->nTickCount = NBAMRENC_NOT_USED; 305 pTemp_lcml->buffer = pTemp; 306 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer); 307 pTemp_lcml->eDir = OMX_DirOutput; 308 309 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, 310 sizeof(NBAMRENC_ParamStruct), 311 NBAMRENC_ParamStruct); 312 313 pTemp_lcml->pBufferParam->usNbFrames=0; 314 pTemp_lcml->pBufferParam->pParamElem=NULL; 315 pTemp_lcml->pFrameParam=NULL; 316 317 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ); 318 319 pTemp->nFlags = NBAMRENC_NORMAL_BUFFER; 320 pTemp++; 321 pTemp_lcml++; 322 } 323 #ifdef __PERF_INSTRUMENTATION__ 324 pComponentPrivate->nLcml_nCntIp = 0; 325 pComponentPrivate->nLcml_nCntOpReceived = 0; 326 #endif 327 328 pComponentPrivate->bInitParamsInitialized = 1; 329 EXIT: 330 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_FillLCMLInitParams\n",__LINE__); 331 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 332 return eError; 333 } 334 335 /* ========================================================================== */ 336 /** 337 * @NBAMRENC_StartComponentThread() This function is called by the component to create 338 * the component thread, command pipes, data pipes and LCML Pipes. 339 * 340 * @param pComponent handle for this instance of the component 341 * 342 * @pre 343 * 344 * @post 345 * 346 * @return none 347 */ 348 /* ========================================================================== */ 349 350 OMX_ERRORTYPE NBAMRENC_StartComponentThread(OMX_HANDLETYPE pComponent) 351 { 352 OMX_ERRORTYPE eError = OMX_ErrorNone; 353 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 354 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = 355 (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 356 #ifdef UNDER_CE 357 pthread_attr_t attr; 358 memset(&attr, 0, sizeof(attr)); 359 attr.__inheritsched = PTHREAD_EXPLICIT_SCHED; 360 attr.__schedparam.__sched_priority = OMX_AUDIO_ENCODER_THREAD_PRIORITY; 361 #endif 362 363 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_StartComponentThread\n", __LINE__); 364 /* Initialize all the variables*/ 365 pComponentPrivate->bIsStopping = 0; 366 pComponentPrivate->bIsThreadstop = 0; 367 pComponentPrivate->lcml_nOpBuf = 0; 368 pComponentPrivate->lcml_nIpBuf = 0; 369 pComponentPrivate->app_nBuf = 0; 370 pComponentPrivate->num_Op_Issued = 0; 371 372 373 /* create the pipe used to send buffers to the thread */ 374 eError = pipe (pComponentPrivate->cmdDataPipe); 375 if (eError) { 376 eError = OMX_ErrorInsufficientResources; 377 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while creating cmdDataPipe\n",__LINE__); 378 goto EXIT; 379 } 380 /* create the pipe used to send buffers to the thread */ 381 eError = pipe (pComponentPrivate->dataPipe); 382 if (eError) { 383 eError = OMX_ErrorInsufficientResources; 384 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while creating dataPipe\n",__LINE__); 385 goto EXIT; 386 } 387 388 /* create the pipe used to send commands to the thread */ 389 eError = pipe (pComponentPrivate->cmdPipe); 390 if (eError) { 391 eError = OMX_ErrorInsufficientResources; 392 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while creating cmdPipe\n",__LINE__); 393 goto EXIT; 394 } 395 396 /* Create the Component Thread */ 397 #ifdef UNDER_CE 398 eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, NBAMRENC_CompThread, pComponentPrivate); 399 #else 400 eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, NBAMRENC_CompThread, pComponentPrivate); 401 #endif 402 if (eError || !pComponentPrivate->ComponentThread) { 403 eError = OMX_ErrorInsufficientResources; 404 goto EXIT; 405 } 406 407 pComponentPrivate->bCompThreadStarted = 1; 408 EXIT: 409 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_StartComponentThread\n", __LINE__); 410 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 411 return eError; 412 } 413 414 /* ========================================================================== */ 415 /** 416 * @NBAMRENC_FreeCompResources() This function is called by the component during 417 * de-init , to newfree Command pipe, data pipe & LCML pipe. 418 * 419 * @param pComponent handle for this instance of the component 420 * 421 * @pre 422 * 423 * @post 424 * 425 * @return none 426 */ 427 /* ========================================================================== */ 428 429 OMX_ERRORTYPE NBAMRENC_FreeCompResources(OMX_HANDLETYPE pComponent) 430 { 431 OMX_ERRORTYPE eError = OMX_ErrorNone; 432 OMX_ERRORTYPE err = OMX_ErrorNone; 433 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 434 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *) 435 pHandle->pComponentPrivate; 436 437 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_FreeCompResources\n",__LINE__); 438 439 if (pComponentPrivate->bCompThreadStarted) { 440 OMX_NBCLOSE_PIPE(pComponentPrivate->dataPipe[0],err); 441 OMX_NBCLOSE_PIPE(pComponentPrivate->dataPipe[1],err); 442 OMX_NBCLOSE_PIPE(pComponentPrivate->cmdPipe[0],err); 443 OMX_NBCLOSE_PIPE(pComponentPrivate->cmdPipe[1],err); 444 OMX_NBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[0],err); 445 OMX_NBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err); 446 } 447 448 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl); 449 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX); 450 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, NBAMRENC_AudioCodecParams); 451 452 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]); 453 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]); 454 OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParams); 455 OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams); 456 457 OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat); 458 OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat); 459 OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]); 460 OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]); 461 462 OMX_MEMFREE_STRUCT(pComponentPrivate->sPortParam); 463 OMX_MEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt); 464 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList); 465 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 466 467 EXIT: 468 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_FreeCompResources()\n",__LINE__); 469 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 470 return eError; 471 } 472 473 /* ========================================================================== */ 474 /** 475 * @NBAMRENC_CleanupInitParams() This function is called by the component during 476 * de-init to newfree structues that are been allocated at intialization stage 477 * 478 * @param pComponent handle for this instance of the component 479 * 480 * @pre 481 * 482 * @post 483 * 484 * @return none 485 */ 486 /* ========================================================================== */ 487 488 OMX_ERRORTYPE NBAMRENC_CleanupInitParams(OMX_HANDLETYPE pComponent) 489 { 490 OMX_ERRORTYPE eError = OMX_ErrorNone; 491 OMX_U32 nIpBuf = 0; 492 OMX_U32 nOpBuf = 0; 493 OMX_U16 i = 0; 494 NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml; 495 496 LCML_DSP_INTERFACE *pLcmlHandle; 497 LCML_DSP_INTERFACE *pLcmlHandleAux; 498 499 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 500 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *) 501 pHandle->pComponentPrivate; 502 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_CleanupInitParams()\n", __LINE__); 503 504 if(pComponentPrivate->dasfMode == 1) { 505 506 OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr); 507 } 508 509 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl); 510 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX); 511 512 pComponentPrivate->nHoldLength = 0; 513 OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer); 514 OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer2); 515 OMX_MEMFREE_STRUCT(pComponentPrivate->iHoldBuffer); 516 OMX_MEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer); 517 518 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT]; 519 nIpBuf = pComponentPrivate->nRuntimeInputBuffers; 520 521 for(i=0; i<nIpBuf; i++) { 522 if(pTemp_lcml->pFrameParam!=NULL){ 523 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle; 524 pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec); 525 OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc, 526 (void*)pTemp_lcml->pBufferParam->pParamElem, 527 pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg); 528 529 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRENC_FrameStruct); 530 } 531 532 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRENC_ParamStruct); 533 OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf); 534 pTemp_lcml++; 535 } 536 537 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT]; 538 nOpBuf = pComponentPrivate->nRuntimeOutputBuffers; 539 540 for(i=0; i<nOpBuf; i++) { 541 if(pTemp_lcml->pFrameParam!=NULL){ 542 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle; 543 pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec); 544 #ifndef UNDER_CE 545 OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc, 546 (void*)pTemp_lcml->pBufferParam->pParamElem, 547 pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg); 548 #endif 549 550 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRENC_FrameStruct); 551 } 552 553 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRENC_ParamStruct); 554 OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf); 555 pTemp_lcml++; 556 } 557 558 559 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT]); 560 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT]); 561 562 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_CleanupInitParams()\n",__LINE__); 563 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 564 return eError; 565 } 566 567 /* ========================================================================== */ 568 /** 569 * @NBAMRENC_StopComponentThread() This function is called by the component during 570 * de-init to close component thread. 571 * 572 * @param pComponent handle for this instance of the component 573 * 574 * @pre 575 * 576 * @post 577 * 578 * @return none 579 */ 580 /* ========================================================================== */ 581 582 OMX_ERRORTYPE NBAMRENC_StopComponentThread(OMX_HANDLETYPE pComponent) 583 { 584 OMX_ERRORTYPE eError = OMX_ErrorNone; 585 OMX_ERRORTYPE threadError = OMX_ErrorNone; 586 int pthreadError = 0; 587 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 588 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *) 589 pHandle->pComponentPrivate; 590 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_StopComponentThread\n",__LINE__); 591 pComponentPrivate->bIsThreadstop = 1; 592 write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsThreadstop, sizeof(OMX_U16)); 593 OMX_PRINT2(pComponentPrivate->dbg, "%d :: About to call pthread_join\n",__LINE__); 594 pthreadError = pthread_join (pComponentPrivate->ComponentThread, 595 (void*)&threadError); 596 if (0 != pthreadError) { 597 eError = OMX_ErrorHardware; 598 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error closing ComponentThread - pthreadError = %d\n",__LINE__,pthreadError); 599 goto EXIT; 600 } 601 if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) { 602 eError = OMX_ErrorInsufficientResources; 603 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error while closing Component Thread\n",__LINE__); 604 goto EXIT; 605 } 606 EXIT: 607 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_StopComponentThread\n",__LINE__); 608 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 609 return eError; 610 } 611 612 613 /* ========================================================================== */ 614 /** 615 * @NBAMRENC_HandleCommand() This function is called by the component when ever it 616 * receives the command from the application 617 * 618 * @param pComponentPrivate Component private data 619 * 620 * @pre 621 * 622 * @post 623 * 624 * @return none 625 */ 626 /* ========================================================================== */ 627 628 OMX_U32 NBAMRENC_HandleCommand (AMRENC_COMPONENT_PRIVATE *pComponentPrivate) 629 { 630 OMX_ERRORTYPE eError = OMX_ErrorNone; 631 OMX_COMMANDTYPE command; 632 OMX_STATETYPE commandedState; 633 OMX_HANDLETYPE pLcmlHandle; 634 #ifdef RESOURCE_MANAGER_ENABLED 635 OMX_ERRORTYPE rm_error; 636 #endif 637 LCML_CALLBACKTYPE cb; 638 LCML_DSP *pLcmlDsp; 639 OMX_U32 cmdValues[4]; 640 OMX_U32 pValues[4]; 641 OMX_U32 commandData; 642 OMX_U16 arr[100]; 643 char *pArgs = "damedesuStr"; 644 char *p = "hello"; 645 OMX_U16 i = 0; 646 OMX_U32 ret = 0; 647 OMX_U8 inputPortFlag=0,outputPortFlag=0; 648 NBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr = NULL; 649 #ifdef DSP_RENDERING_ON 650 #if 0 651 AM_COMMANDDATATYPE cmd_data; 652 #endif 653 #endif 654 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 655 pLcmlHandle = pComponentPrivate->pLcmlHandle; 656 657 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENCHandleCommand Function \n",__LINE__); 658 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState); 659 ret = read(pComponentPrivate->cmdPipe[0], &command, sizeof (command)); 660 if (ret == -1) { 661 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__); 662 eError = OMX_ErrorHardware; 663 goto EXIT; 664 } 665 ret = read(pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData)); 666 if (ret == -1) { 667 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Reading from the Data pipe\n", __LINE__); 668 eError = OMX_ErrorHardware; 669 goto EXIT; 670 } 671 672 #ifdef __PERF_INSTRUMENTATION__ 673 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp, 674 command, 675 commandData, 676 PERF_ModuleLLMM); 677 #endif 678 if (command == OMX_CommandStateSet) { 679 commandedState = (OMX_STATETYPE)commandData; 680 switch(commandedState) { 681 case OMX_StateIdle: 682 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StateIdle \n",__LINE__); 683 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate->curState); 684 if (pComponentPrivate->curState == commandedState){ 685 pComponentPrivate->cbInfo.EventHandler ( pHandle, 686 pHandle->pApplicationPrivate, 687 OMX_EventError, 688 OMX_ErrorSameState, 689 OMX_TI_ErrorMinor, 690 NULL); 691 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Same State Given by Application\n",__LINE__); 692 } 693 else if (pComponentPrivate->curState == OMX_StateLoaded) { 694 #ifdef __PERF_INSTRUMENTATION__ 695 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup); 696 #endif 697 698 if(pComponentPrivate->dasfMode == 1) { 699 if(pComponentPrivate->streamID == 0) 700 { 701 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n"); 702 OMX_ERROR4(pComponentPrivate->dbg, ":: Error = OMX_ErrorInsufficientResources\n"); 703 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n"); 704 eError = OMX_ErrorInsufficientResources; 705 pComponentPrivate->curState = OMX_StateInvalid; 706 pComponentPrivate->cbInfo.EventHandler(pHandle, 707 pHandle->pApplicationPrivate, 708 OMX_EventError, 709 OMX_ErrorInvalidState, 710 OMX_TI_ErrorMajor, 711 "No Stream ID Available"); 712 goto EXIT; 713 } 714 } 715 716 if (pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled) { 717 inputPortFlag = 1; 718 } 719 if (pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled) { 720 outputPortFlag = 1; 721 } 722 723 if (!pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled) { 724 inputPortFlag = 1; 725 } 726 727 if (!pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled) { 728 outputPortFlag = 1; 729 } 730 731 if((pComponentPrivate->dasfMode && !outputPortFlag) || 732 (!pComponentPrivate->dasfMode && (!inputPortFlag || !outputPortFlag))) 733 { 734 /* Sleep for a while, so the application thread can allocate buffers */ 735 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: Sleeping...\n",__LINE__); 736 pComponentPrivate->InLoaded_readytoidle = 1; 737 #ifndef UNDER_CE 738 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 739 pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex); 740 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 741 #else 742 OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event)); 743 #endif 744 } 745 746 cb.LCML_Callback = (void *) NBAMRENC_LCMLCallback; 747 pLcmlHandle = (OMX_HANDLETYPE) NBAMRENC_GetLCMLHandle(pComponentPrivate); 748 749 if (pLcmlHandle == NULL) { 750 OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML Handle is NULL........exiting..\n",__LINE__); 751 goto EXIT; 752 } 753 754 755 /* Got handle of dsp via phandle filling information about DSP Specific things */ 756 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 757 eError = NBAMRENC_FillLCMLInitParams(pHandle, pLcmlDsp, arr); 758 if(eError != OMX_ErrorNone) { 759 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from NBAMRENCFill_LCMLInitParams()\n",__LINE__); 760 goto EXIT; 761 } 762 763 764 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle; 765 cb.LCML_Callback = (void *) NBAMRENC_LCMLCallback; 766 767 #ifndef UNDER_CE 768 eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle, 769 p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString); 770 771 #else 772 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 773 p,&pLcmlHandle, (void *)p, &cb); 774 #endif 775 776 if(eError != OMX_ErrorNone) { 777 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from LCML_Init()\n",__LINE__); 778 /* send an event to client */ 779 /* client should unload the component if the codec is not able to load */ 780 eError = OMX_ErrorInvalidState; 781 pComponentPrivate->cbInfo.EventHandler (pHandle, 782 pHandle->pApplicationPrivate, 783 OMX_EventError, 784 eError, 785 OMX_TI_ErrorSevere, 786 NULL); 787 goto EXIT; 788 } 789 790 #ifdef RESOURCE_MANAGER_ENABLED 791 /* Need check the resource with RM */ 792 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) NBAMRENC_ResourceManagerCallback; 793 794 if (pComponentPrivate->curState != OMX_StateWaitForResources){ 795 796 rm_error = RMProxy_NewSendCommand(pHandle, 797 RMProxy_RequestResource, 798 OMX_NBAMR_Encoder_COMPONENT, NBAMRENC_CPU_LOAD, 799 3456, &(pComponentPrivate->rmproxyCallback)); 800 801 if(rm_error == OMX_ErrorNone) { 802 /* resource is available */ 803 #ifdef __PERF_INSTRUMENTATION__ 804 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup); 805 #endif 806 pComponentPrivate->curState = OMX_StateIdle; 807 808 /* Decrement reference count with signal enabled */ 809 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 810 return OMX_ErrorUndefined; 811 } 812 813 pComponentPrivate->cbInfo.EventHandler(pHandle, 814 pHandle->pApplicationPrivate, 815 OMX_EventCmdComplete, 816 OMX_CommandStateSet, 817 pComponentPrivate->curState, 818 NULL); 819 820 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL); 821 } 822 else if(rm_error == OMX_ErrorInsufficientResources) { 823 /* resource is not available, need set state to OMX_StateWaitForResources */ 824 pComponentPrivate->curState = OMX_StateWaitForResources; 825 pComponentPrivate->cbInfo.EventHandler( pHandle, 826 pHandle->pApplicationPrivate, 827 OMX_EventCmdComplete, 828 OMX_CommandStateSet, 829 pComponentPrivate->curState, 830 NULL); 831 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorInsufficientResources\n", __LINE__); 832 } 833 } 834 else { 835 pComponentPrivate->curState = OMX_StateIdle; 836 837 /* Decrement reference count with signal enabled */ 838 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 839 return OMX_ErrorUndefined; 840 } 841 842 pComponentPrivate->cbInfo.EventHandler(pHandle, 843 pHandle->pApplicationPrivate, 844 OMX_EventCmdComplete, 845 OMX_CommandStateSet, 846 pComponentPrivate->curState, 847 NULL); 848 849 rm_error = RMProxy_NewSendCommand(pHandle, 850 RMProxy_StateSet, 851 OMX_NBAMR_Encoder_COMPONENT, 852 OMX_StateIdle, 853 3456, 854 NULL); 855 856 } 857 #else 858 pComponentPrivate->curState = OMX_StateIdle; 859 860 /* Decrement reference count with signal enabled */ 861 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 862 return OMX_ErrorUndefined; 863 } 864 865 pComponentPrivate->cbInfo.EventHandler( pHandle, 866 pHandle->pApplicationPrivate, 867 OMX_EventCmdComplete, 868 OMX_CommandStateSet, 869 pComponentPrivate->curState, 870 NULL); 871 872 #endif 873 874 } 875 else if (pComponentPrivate->curState == OMX_StateExecuting) { 876 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: Setting Component to OMX_StateIdle\n",__LINE__); 877 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AMRENC: About to Call MMCodecControlStop\n", __LINE__); 878 #ifdef __PERF_INSTRUMENTATION__ 879 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 880 #endif 881 pComponentPrivate->bIsStopping = 1; 882 883 if (pComponentPrivate->codecStop_waitingsignal == 0){ 884 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex); 885 } 886 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 887 MMCodecControlStop,(void *)pArgs); 888 889 if (pComponentPrivate->codecStop_waitingsignal == 0){ 890 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex); 891 pComponentPrivate->codecStop_waitingsignal = 0; 892 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex); 893 } 894 895 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl); 896 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX); 897 898 pComponentPrivate->nOutStandingFillDones = 0; 899 pComponentPrivate->nOutStandingEmptyDones = 0; 900 901 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, NBAMRENC_AudioCodecParams); 902 903 if(eError != OMX_ErrorNone) { 904 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec MMCodecControlStop..\n",__LINE__); 905 goto EXIT; 906 } 907 } 908 else if(pComponentPrivate->curState == OMX_StatePause) { 909 910 pComponentPrivate->curState = OMX_StateIdle; 911 #ifdef __PERF_INSTRUMENTATION__ 912 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 913 #endif 914 #ifdef RESOURCE_MANAGER_ENABLED 915 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL); 916 917 #endif 918 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: The component is stopped\n",__LINE__); 919 920 /* Decrement reference count with signal enabled */ 921 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 922 return OMX_ErrorUndefined; 923 } 924 925 pComponentPrivate->cbInfo.EventHandler ( pHandle, 926 pHandle->pApplicationPrivate, 927 OMX_EventCmdComplete, 928 OMX_CommandStateSet, 929 pComponentPrivate->curState, 930 NULL); 931 } else { /* This means, it is invalid state from application */ 932 pComponentPrivate->cbInfo.EventHandler( pHandle, 933 pHandle->pApplicationPrivate, 934 OMX_EventError, 935 OMX_ErrorIncorrectStateTransition, 936 OMX_TI_ErrorMinor, 937 "Invalid State"); 938 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorIncorrectStateTransition\n",__LINE__); 939 } 940 break; 941 942 case OMX_StateExecuting: 943 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StateExecuting \n",__LINE__); 944 if (pComponentPrivate->curState == commandedState){ 945 pComponentPrivate->cbInfo.EventHandler ( pHandle, 946 pHandle->pApplicationPrivate, 947 OMX_EventError, 948 OMX_ErrorSameState, 949 OMX_TI_ErrorMinor, 950 "Invalid State"); 951 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorSameState Given by Comp\n",__LINE__); 952 break; 953 } 954 else if (pComponentPrivate->curState == OMX_StateIdle) { 955 /* Sending commands to DSP via LCML_ControlCodec third argument 956 is not used for time being */ 957 pComponentPrivate->nNumInputBufPending = 0; 958 pComponentPrivate->nNumOutputBufPending = 0; 959 pComponentPrivate->nNumOfFramesSent=0; 960 pComponentPrivate->nEmptyBufferDoneCount = 0; 961 pComponentPrivate->nEmptyThisBufferCount =0; 962 963 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParam, sizeof(NBAMRENC_TALGCtrl),OMX_U8); 964 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParamDTX, sizeof(NBAMRENC_TALGCtrlDTX),OMX_U8); 965 966 pComponentPrivate->pAlgParam->iBitrate = pComponentPrivate->amrParams->eAMRBandMode; 967 968 #ifdef NBAMR_DTX_VAD_MODE_SUPPORT_ENABLED 969 if (pComponentPrivate->amrParams->eAMRDTXMode == OMX_AUDIO_AMRDTXModeOnAuto) { 970 pComponentPrivate->pAlgParamDTX->iVADFlag = OMX_TRUE; 971 } 972 else { 973 pComponentPrivate->pAlgParamDTX->iVADFlag = OMX_FALSE; 974 } 975 #else 976 pComponentPrivate->pAlgParamDTX->iVADFlag = OMX_FALSE; 977 #endif 978 pComponentPrivate->pAlgParam->iSize = sizeof (NBAMRENC_TALGCtrl); 979 pComponentPrivate->pAlgParamDTX->iSize = sizeof (NBAMRENC_TALGCtrlDTX); 980 OMX_PRINT2(pComponentPrivate->dbg, "%d :: pAlgParam->iBitrate = %d\n",__LINE__,pComponentPrivate->pAlgParam->iBitrate); 981 OMX_PRINT2(pComponentPrivate->dbg, "%d :: pAlgParamDTX->iVADFlag = %d\n",__LINE__,pComponentPrivate->pAlgParamDTX->iVADFlag); 982 983 cmdValues[0] = ALGCMD_BITRATE; /*setting the bit-rate*/ 984 cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam; 985 cmdValues[2] = sizeof (NBAMRENC_TALGCtrl); 986 p = (void *)&cmdValues; 987 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: EMMCodecControlAlgCtrl-1 Sending...\n",__LINE__); 988 /* Sending ALGCTRL MESSAGE DTX to DSP via LCML_ControlCodec*/ 989 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 990 EMMCodecControlAlgCtrl, (void *)p); 991 if (eError != OMX_ErrorNone) { 992 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec EMMCodecControlAlgCtrl-1 failed = %x\n",__LINE__,eError); 993 goto EXIT; 994 } 995 cmdValues[0] = ALGCMD_DTX; /*setting DTX mode*/ 996 cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParamDTX; 997 cmdValues[2] = sizeof (NBAMRENC_TALGCtrlDTX); 998 p = (void *)&cmdValues; 999 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: EMMCodecControlAlgCtrl-2 Sending...\n",__LINE__); 1000 /* Sending ALGCTRL MESSAGE BITRATE to DSP via LCML_ControlCodec*/ 1001 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1002 EMMCodecControlAlgCtrl, (void *)p); 1003 if (eError != OMX_ErrorNone) { 1004 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec EMMCodecControlAlgCtrl-2 failed = %x\n",__LINE__,eError); 1005 goto EXIT; 1006 } 1007 if(pComponentPrivate->dasfMode == 1) { 1008 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__); 1009 1010 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(NBAMRENC_AudioCodecParams),OMX_U8); 1011 1012 pComponentPrivate->pParams->iAudioFormat = 1; 1013 pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID; 1014 pComponentPrivate->pParams->iSamplingRate = NBAMRENC_SAMPLING_FREQUENCY; 1015 pValues[0] = USN_STRMCMD_SETCODECPARAMS; 1016 pValues[1] = (OMX_U32)pComponentPrivate->pParams; 1017 pValues[2] = sizeof(NBAMRENC_AudioCodecParams); 1018 /* Sending STRMCTRL MESSAGE to DSP via LCML_ControlCodec*/ 1019 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1020 EMMCodecControlStrmCtrl,(void *)pValues); 1021 if(eError != OMX_ErrorNone) { 1022 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec EMMCodecControlStrmCtrl = %x\n",__LINE__,eError); 1023 goto EXIT; 1024 } 1025 } 1026 /* Sending START MESSAGE to DSP via LCML_ControlCodec*/ 1027 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1028 EMMCodecControlStart, (void *)p); 1029 if(eError != OMX_ErrorNone) { 1030 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec EMMCodecControlStart = %x\n",__LINE__,eError); 1031 goto EXIT; 1032 } 1033 1034 } else if (pComponentPrivate->curState == OMX_StatePause) { 1035 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1036 EMMCodecControlStart, (void *)p); 1037 if (eError != OMX_ErrorNone) { 1038 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error While Resuming the codec = %x\n",__LINE__,eError); 1039 goto EXIT; 1040 } 1041 1042 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) { 1043 if (pComponentPrivate->pInputBufHdrPending[i]) { 1044 NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr); 1045 NBAMRENC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__); 1046 1047 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1048 EMMCodecInputBuffer, 1049 pComponentPrivate->pInputBufHdrPending[i]->pBuffer, 1050 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen, 1051 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen, 1052 (OMX_U8 *) pLcmlHdr->pBufferParam, 1053 sizeof(NBAMRENC_ParamStruct), 1054 NULL); 1055 } 1056 } 1057 pComponentPrivate->nNumInputBufPending = 0; 1058 1059 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) { 1060 if (pComponentPrivate->pOutputBufHdrPending[i]) { 1061 NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr); 1062 NBAMRENC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput,__LINE__); 1063 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1064 EMMCodecOuputBuffer, 1065 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, 1066 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen, 1067 pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen, 1068 (OMX_U8 *) pLcmlHdr->pBufferParam, 1069 sizeof(NBAMRENC_ParamStruct), 1070 NULL); 1071 } 1072 } 1073 pComponentPrivate->nNumOutputBufPending = 0; 1074 } else { 1075 pComponentPrivate->cbInfo.EventHandler( pHandle, 1076 pHandle->pApplicationPrivate, 1077 OMX_EventError, 1078 OMX_ErrorIncorrectStateTransition, 1079 OMX_TI_ErrorMinor, 1080 "Incorrect State Transition"); 1081 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__); 1082 goto EXIT; 1083 1084 } 1085 #ifdef RESOURCE_MANAGER_ENABLED 1086 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateExecuting, 3456, NULL); 1087 #endif 1088 pComponentPrivate->curState = OMX_StateExecuting; 1089 #ifdef __PERF_INSTRUMENTATION__ 1090 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState); 1091 #endif 1092 1093 /* Decrement reference count with signal enabled */ 1094 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 1095 return OMX_ErrorUndefined; 1096 } 1097 1098 pComponentPrivate->cbInfo.EventHandler( pHandle, 1099 pHandle->pApplicationPrivate, 1100 OMX_EventCmdComplete, 1101 OMX_CommandStateSet, 1102 pComponentPrivate->curState, 1103 NULL); 1104 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__); 1105 break; 1106 1107 case OMX_StateLoaded: 1108 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StateLoaded\n",__LINE__); 1109 if (pComponentPrivate->curState == commandedState){ 1110 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1111 pHandle->pApplicationPrivate, 1112 OMX_EventError, 1113 OMX_ErrorSameState, 1114 OMX_TI_ErrorMinor, 1115 "Same State"); 1116 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorSameState Given by Comp\n",__LINE__); 1117 break; 1118 } 1119 if (pComponentPrivate->curState == OMX_StateWaitForResources){ 1120 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StateWaitForResources\n",__LINE__); 1121 #ifdef __PERF_INSTRUMENTATION__ 1122 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup); 1123 #endif 1124 pComponentPrivate->curState = OMX_StateLoaded; 1125 #ifdef __PERF_INSTRUMENTATION__ 1126 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup); 1127 #endif 1128 pComponentPrivate->curState = OMX_StateLoaded; 1129 1130 /* Decrement reference count with signal enabled */ 1131 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) { 1132 return OMX_ErrorUndefined; 1133 } 1134 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1135 pHandle->pApplicationPrivate, 1136 OMX_EventCmdComplete, 1137 OMX_CommandStateSet, 1138 pComponentPrivate->curState, 1139 NULL); 1140 OMX_PRINT2(pComponentPrivate->dbg, "%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__); 1141 break; 1142 } 1143 if (pComponentPrivate->curState != OMX_StateIdle && 1144 pComponentPrivate->curState != OMX_StateWaitForResources) { 1145 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StateIdle && OMX_StateWaitForResources\n",__LINE__); 1146 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1147 pHandle->pApplicationPrivate, 1148 OMX_EventError, 1149 OMX_ErrorIncorrectStateTransition, 1150 OMX_TI_ErrorMinor, 1151 "Incorrect State Transition"); 1152 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__); 1153 goto EXIT; 1154 } 1155 #ifdef __PERF_INSTRUMENTATION__ 1156 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup); 1157 #endif 1158 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand - evaluating if all buffers are free\n",__LINE__); 1159 1160 if (pComponentPrivate->pInputBufferList->numBuffers || 1161 pComponentPrivate->pOutputBufferList->numBuffers) { 1162 1163 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1164 pComponentPrivate->InIdle_goingtoloaded = 1; 1165 pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex); 1166 pthread_mutex_unlock(&pComponentPrivate->ToLoaded_mutex); 1167 } 1168 1169 /* Now Deinitialize the component No error should be returned from 1170 * this function. It should clean the system as much as possible */ 1171 NBAMRENC_CleanupInitParams(pComponentPrivate->pHandle); 1172 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1173 EMMCodecControlDestroy, (void *)p); 1174 if (eError != OMX_ErrorNone) { 1175 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlDestroy = %x\n",__LINE__, eError); 1176 goto EXIT; 1177 } 1178 1179 /*Closing LCML Lib*/ 1180 if (pComponentPrivate->ptrLibLCML != NULL) 1181 { 1182 OMX_PRDSP2(pComponentPrivate->dbg, "%d OMX_AmrEncoder.c Closing LCML library\n",__LINE__); 1183 dlclose( pComponentPrivate->ptrLibLCML); 1184 pComponentPrivate->ptrLibLCML = NULL; 1185 } 1186 1187 1188 #ifdef __PERF_INSTRUMENTATION__ 1189 PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent); 1190 #endif 1191 eError = NBAMRENC_EXIT_COMPONENT_THRD; 1192 pComponentPrivate->bInitParamsInitialized = 0; 1193 pComponentPrivate->bLoadedCommandPending = OMX_FALSE; 1194 pComponentPrivate->bLoadedWaitingFreeBuffers = OMX_FALSE; 1195 break; 1196 1197 case OMX_StatePause: 1198 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: OMX_StatePause\n",__LINE__); 1199 if (pComponentPrivate->curState == commandedState){ 1200 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1201 pHandle->pApplicationPrivate, 1202 OMX_EventError, 1203 OMX_ErrorSameState, 1204 OMX_TI_ErrorMinor, 1205 "Same State"); 1206 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__); 1207 break; 1208 } 1209 if (pComponentPrivate->curState != OMX_StateExecuting && 1210 pComponentPrivate->curState != OMX_StateIdle) { 1211 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1212 pHandle->pApplicationPrivate, 1213 OMX_EventError, 1214 OMX_ErrorIncorrectStateTransition, 1215 OMX_TI_ErrorMinor, 1216 "Incorrect State Transition"); 1217 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__); 1218 goto EXIT; 1219 } 1220 #ifdef __PERF_INSTRUMENTATION__ 1221 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState); 1222 #endif 1223 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1224 EMMCodecControlPause, (void *)p); 1225 if (eError != OMX_ErrorNone) { 1226 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: LCML_ControlCodec EMMCodecControlPause = %x\n",__LINE__,eError); 1227 goto EXIT; 1228 } 1229 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__); 1230 break; 1231 1232 case OMX_StateWaitForResources: 1233 if (pComponentPrivate->curState == commandedState) { 1234 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1235 pHandle->pApplicationPrivate, 1236 OMX_EventError, 1237 OMX_ErrorSameState, 1238 OMX_TI_ErrorMinor, 1239 "Same State"); 1240 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__); 1241 } else if (pComponentPrivate->curState == OMX_StateLoaded) { 1242 1243 #ifdef RESOURCE_MANAGER_ENABLED 1244 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateWaitForResources, 3456, NULL); 1245 #endif 1246 1247 pComponentPrivate->curState = OMX_StateWaitForResources; 1248 pComponentPrivate->cbInfo.EventHandler( pHandle, 1249 pHandle->pApplicationPrivate, 1250 OMX_EventCmdComplete, 1251 OMX_CommandStateSet, 1252 pComponentPrivate->curState, 1253 NULL); 1254 OMX_PRINT2(pComponentPrivate->dbg, "%d :: Comp: OMX_CommandStateSet Given by Comp\n",__LINE__); 1255 } else { 1256 pComponentPrivate->cbInfo.EventHandler( pHandle, 1257 pHandle->pApplicationPrivate, 1258 OMX_EventError, 1259 OMX_ErrorIncorrectStateTransition, 1260 OMX_TI_ErrorMinor, 1261 "Incorrect State Transition"); 1262 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorIncorrectStateTransition Given by Comp\n",__LINE__); 1263 } 1264 break; 1265 1266 case OMX_StateInvalid: 1267 if (pComponentPrivate->curState == commandedState) { 1268 pComponentPrivate->cbInfo.EventHandler ( pHandle, 1269 pHandle->pApplicationPrivate, 1270 OMX_EventError, 1271 OMX_ErrorSameState, 1272 OMX_TI_ErrorSevere, 1273 "Same State"); 1274 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorSameState Given by Comp\n",__LINE__); 1275 } 1276 else { 1277 OMX_PRSTATE2(pComponentPrivate->dbg, "%d: HandleCommand: Cmd OMX_StateInvalid:\n",__LINE__); 1278 if (pComponentPrivate->curState != OMX_StateWaitForResources && 1279 pComponentPrivate->curState != OMX_StateInvalid && 1280 pComponentPrivate->curState != OMX_StateLoaded) { 1281 1282 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1283 EMMCodecControlDestroy, (void *)pArgs); 1284 } 1285 pComponentPrivate->curState = OMX_StateInvalid; 1286 pComponentPrivate->cbInfo.EventHandler( pHandle, 1287 pHandle->pApplicationPrivate, 1288 OMX_EventError, 1289 OMX_ErrorInvalidState, 1290 OMX_TI_ErrorSevere, 1291 "Incorrect State Transition"); 1292 1293 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp: OMX_ErrorInvalidState Given by Comp\n",__LINE__); 1294 NBAMRENC_CleanupInitParams(pHandle); 1295 } 1296 break; 1297 1298 case OMX_StateMax: 1299 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: NBAMRENC_HandleCommand :: Cmd OMX_StateMax\n",__LINE__); 1300 break; 1301 } /* End of Switch */ 1302 } else if (command == OMX_CommandMarkBuffer) { 1303 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: command OMX_CommandMarkBuffer received\n",__LINE__); 1304 if(!pComponentPrivate->pMarkBuf){ 1305 /* TODO Need to handle multiple marks */ 1306 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData); 1307 } 1308 } else if (command == OMX_CommandPortDisable) { 1309 if (!pComponentPrivate->bDisableCommandPending) { 1310 OMX_PRINT2(pComponentPrivate->dbg, "I'm here Line %d\n",__LINE__); 1311 if(commandData == 0x0 || commandData == -1){ 1312 pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled = OMX_FALSE; 1313 } 1314 if(commandData == 0x1 || commandData == -1){ 1315 char *pArgs = "damedesuStr"; 1316 1317 pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled = OMX_FALSE; 1318 if (pComponentPrivate->curState == OMX_StateExecuting) { 1319 pComponentPrivate->bNoIdleOnStop = OMX_TRUE; 1320 pComponentPrivate->bIsStopping = 1; 1321 if (pComponentPrivate->codecStop_waitingsignal == 0){ 1322 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex); 1323 } 1324 eError = LCML_ControlCodec( 1325 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1326 MMCodecControlStop,(void *)pArgs); 1327 if (pComponentPrivate->codecStop_waitingsignal == 0){ 1328 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex); 1329 pComponentPrivate->codecStop_waitingsignal = 0; 1330 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex); 1331 } 1332 1333 } 1334 } 1335 } 1336 1337 OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %d\n",(int)commandData); 1338 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated = %d\n",pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated); 1339 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated = %d\n",pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated); 1340 1341 if(commandData == 0x0) { 1342 if(!pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated){ 1343 /* return cmdcomplete event if input unpopulated */ 1344 pComponentPrivate->cbInfo.EventHandler( 1345 pHandle, pHandle->pApplicationPrivate, 1346 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRENC_INPUT_PORT, NULL); 1347 pComponentPrivate->bDisableCommandPending = 0; 1348 } 1349 else{ 1350 pComponentPrivate->bDisableCommandPending = 1; 1351 pComponentPrivate->bDisableCommandParam = commandData; 1352 } 1353 } 1354 1355 if(commandData == 0x1) { 1356 if (!pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated){ 1357 /* return cmdcomplete event if output unpopulated */ 1358 pComponentPrivate->cbInfo.EventHandler( 1359 pHandle, pHandle->pApplicationPrivate, 1360 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRENC_OUTPUT_PORT, NULL); 1361 pComponentPrivate->bDisableCommandPending = 0; 1362 } 1363 else { 1364 pComponentPrivate->bDisableCommandPending = 1; 1365 pComponentPrivate->bDisableCommandParam = commandData; 1366 } 1367 } 1368 1369 if(commandData == -1) { 1370 if (!pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated && 1371 !pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated){ 1372 1373 /* return cmdcomplete event if inout & output unpopulated */ 1374 pComponentPrivate->cbInfo.EventHandler( 1375 pHandle, pHandle->pApplicationPrivate, 1376 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRENC_INPUT_PORT, NULL); 1377 1378 pComponentPrivate->cbInfo.EventHandler( 1379 pHandle, pHandle->pApplicationPrivate, 1380 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRENC_OUTPUT_PORT, NULL); 1381 pComponentPrivate->bDisableCommandPending = 0; 1382 } 1383 else { 1384 pComponentPrivate->bDisableCommandPending = 1; 1385 pComponentPrivate->bDisableCommandParam = commandData; 1386 } 1387 } 1388 #ifndef UNDER_CE 1389 sched_yield(); 1390 #endif 1391 } 1392 else if (command == OMX_CommandPortEnable) { 1393 if(!pComponentPrivate->bEnableCommandPending) { 1394 if(commandData == 0x0 || commandData == -1){ 1395 /* enable in port */ 1396 OMX_PRCOMM2(pComponentPrivate->dbg, "setting input port to enabled\n"); 1397 pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled = OMX_TRUE; 1398 if(pComponentPrivate->AlloBuf_waitingsignal) 1399 { 1400 pComponentPrivate->AlloBuf_waitingsignal = 0; 1401 1402 } 1403 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bEnabled); 1404 } 1405 if(commandData == 0x1 || commandData == -1){ 1406 char *pArgs = "damedesuStr"; 1407 /* enable out port */ 1408 if(pComponentPrivate->AlloBuf_waitingsignal) 1409 { 1410 pComponentPrivate->AlloBuf_waitingsignal = 0; 1411 #ifndef UNDER_CE 1412 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1413 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); 1414 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1415 #else 1416 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); 1417 #endif 1418 } 1419 if (pComponentPrivate->curState == OMX_StateExecuting) { 1420 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 1421 eError = LCML_ControlCodec( 1422 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 1423 EMMCodecControlStart,(void *)pArgs); 1424 } 1425 OMX_PRCOMM2(pComponentPrivate->dbg, "setting output port to enabled\n"); 1426 pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled = OMX_TRUE; 1427 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled = %d\n",pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bEnabled); 1428 } 1429 } 1430 if(commandData == 0x0 ){ 1431 if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated){ 1432 pComponentPrivate->cbInfo.EventHandler( 1433 pHandle, pHandle->pApplicationPrivate, 1434 OMX_EventCmdComplete, OMX_CommandPortEnable,NBAMRENC_INPUT_PORT, NULL); 1435 pComponentPrivate->bEnableCommandPending = 0; 1436 } 1437 else{ 1438 pComponentPrivate->bEnableCommandPending = 1; 1439 pComponentPrivate->bEnableCommandParam = commandData; 1440 } 1441 } 1442 else if(commandData == 0x1){ 1443 if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated){ 1444 pComponentPrivate->cbInfo.EventHandler( 1445 pHandle, pHandle->pApplicationPrivate, 1446 OMX_EventCmdComplete, OMX_CommandPortEnable,NBAMRENC_OUTPUT_PORT, NULL); 1447 pComponentPrivate->bEnableCommandPending = 0; 1448 } 1449 else{ 1450 pComponentPrivate->bEnableCommandPending = 1; 1451 pComponentPrivate->bEnableCommandParam = commandData; 1452 } 1453 } 1454 else if(commandData == -1){ 1455 if(pComponentPrivate->curState == OMX_StateLoaded || (pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->bPopulated 1456 && pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->bPopulated)){ 1457 pComponentPrivate->cbInfo.EventHandler( 1458 pHandle, pHandle->pApplicationPrivate, 1459 OMX_EventCmdComplete, OMX_CommandPortEnable,NBAMRENC_INPUT_PORT, NULL); 1460 1461 pComponentPrivate->cbInfo.EventHandler( 1462 pHandle, pHandle->pApplicationPrivate, 1463 OMX_EventCmdComplete, OMX_CommandPortEnable,NBAMRENC_OUTPUT_PORT, NULL); 1464 1465 pComponentPrivate->bEnableCommandPending = 0; 1466 NBAMRENC_FillLCMLInitParamsEx(pComponentPrivate->pHandle); 1467 } 1468 else { 1469 pComponentPrivate->bEnableCommandPending = 1; 1470 pComponentPrivate->bEnableCommandParam = commandData; 1471 } 1472 } 1473 #ifndef UNDER_CE 1474 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1475 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold); 1476 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1477 #else 1478 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event)); 1479 #endif 1480 1481 } else if (command == OMX_CommandFlush) { 1482 if(commandData == 0x0 || commandData == -1){/*input*/ 1483 OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing input port %d\n",__LINE__); 1484 for (i=0; i < NBAMRENC_MAX_NUM_OF_BUFS; i++) { 1485 pComponentPrivate->pInputBufHdrPending[i] = NULL; 1486 } 1487 pComponentPrivate->nNumInputBufPending=0; 1488 1489 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 1490 1491 1492 #ifdef __PERF_INSTRUMENTATION__ 1493 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1494 pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer, 1495 0, 1496 PERF_ModuleHLMM); 1497 #endif 1498 pComponentPrivate->cbInfo.EmptyBufferDone ( 1499 pComponentPrivate->pHandle, 1500 pComponentPrivate->pHandle->pApplicationPrivate, 1501 pComponentPrivate->pInputBufferList->pBufHdr[i] 1502 ); 1503 pComponentPrivate->nEmptyBufferDoneCount++; 1504 pComponentPrivate->nOutStandingEmptyDones--; 1505 1506 } 1507 pComponentPrivate->cbInfo.EventHandler( 1508 pHandle, pHandle->pApplicationPrivate, 1509 OMX_EventCmdComplete, OMX_CommandFlush,NBAMRENC_INPUT_PORT, NULL); 1510 } 1511 1512 if(commandData == 0x1 || commandData == -1){/*output*/ 1513 for (i=0; i < NBAMRENC_MAX_NUM_OF_BUFS; i++) { 1514 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 1515 } 1516 pComponentPrivate->nNumOutputBufPending=0; 1517 1518 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 1519 #ifdef __PERF_INSTRUMENTATION__ 1520 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1521 pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer, 1522 pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen, 1523 PERF_ModuleHLMM); 1524 #endif 1525 pComponentPrivate->cbInfo.FillBufferDone ( 1526 pComponentPrivate->pHandle, 1527 pComponentPrivate->pHandle->pApplicationPrivate, 1528 pComponentPrivate->pOutputBufferList->pBufHdr[i] 1529 ); 1530 pComponentPrivate->nFillBufferDoneCount++; 1531 pComponentPrivate->nOutStandingFillDones--; 1532 1533 } 1534 pComponentPrivate->cbInfo.EventHandler( 1535 pHandle, pHandle->pApplicationPrivate, 1536 OMX_EventCmdComplete, OMX_CommandFlush,NBAMRENC_OUTPUT_PORT, NULL); 1537 } 1538 } 1539 1540 EXIT: 1541 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_HandleCommand Function\n",__LINE__); 1542 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 1543 if (eError != OMX_ErrorNone && eError != NBAMRENC_EXIT_COMPONENT_THRD) { 1544 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1545 pComponentPrivate->pHandle->pApplicationPrivate, 1546 OMX_EventError, 1547 eError, 1548 OMX_TI_ErrorSevere, 1549 NULL); 1550 } 1551 return eError; 1552 } 1553 1554 /* ========================================================================== */ 1555 /** 1556 * @NBAMRENC_HandleDataBufFromApp() This function is called by the component when ever it 1557 * receives the buffer from the application 1558 * 1559 * @param pComponentPrivate Component private data 1560 * @param pBufHeader Buffer from the application 1561 * 1562 * @pre 1563 * 1564 * @post 1565 * 1566 * @return none 1567 */ 1568 /* ========================================================================== */ 1569 OMX_ERRORTYPE NBAMRENC_HandleDataBufFromApp(OMX_BUFFERHEADERTYPE* pBufHeader, 1570 AMRENC_COMPONENT_PRIVATE *pComponentPrivate) 1571 { 1572 OMX_ERRORTYPE eError = OMX_ErrorNone; 1573 OMX_DIRTYPE eDir; 1574 NBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr = NULL; 1575 LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *) 1576 pComponentPrivate->pLcmlHandle; 1577 OMX_U32 frameLength, remainingBytes; 1578 OMX_U8* pExtraData = NULL; 1579 OMX_U8 nFrames=0,i; 1580 LCML_DSP_INTERFACE * phandle = NULL; 1581 1582 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_HandleDataBufFromApp Function\n",__LINE__); 1583 /*Find the direction of the received buffer from buffer list */ 1584 eError = NBAMRENC_GetBufferDirection(pBufHeader, &eDir); 1585 if (eError != OMX_ErrorNone) { 1586 OMX_ERROR4(pComponentPrivate->dbg, "%d :: The pBufHeader is not found in the list\n", __LINE__); 1587 goto EXIT; 1588 } 1589 1590 if (eDir == OMX_DirInput) { 1591 pComponentPrivate->nEmptyThisBufferCount++; 1592 pComponentPrivate->nUnhandledEmptyThisBuffers--; 1593 if (pBufHeader->nFilledLen > 0) { 1594 if (pComponentPrivate->nHoldLength == 0) { 1595 frameLength = NBAMRENC_INPUT_FRAME_SIZE; 1596 nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength); 1597 if ( nFrames>=1 ) { /*At least there is 1 frame in the buffer*/ 1598 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames; 1599 if (pComponentPrivate->nHoldLength > 0) {/* something need to be hold in pHoldBuffer */ 1600 if (pComponentPrivate->pHoldBuffer == NULL) { 1601 OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8); 1602 } 1603 1604 /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */ 1605 pExtraData = pBufHeader->pBuffer + frameLength*nFrames; 1606 1607 if(pComponentPrivate->nHoldLength <= NBAMRENC_INPUT_FRAME_SIZE) { 1608 memcpy(pComponentPrivate->pHoldBuffer, pExtraData, pComponentPrivate->nHoldLength); 1609 } 1610 else { 1611 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: pHoldLenght is bigger than the input frame size\n", __LINE__); 1612 goto EXIT; 1613 } 1614 1615 pBufHeader->nFilledLen-=pComponentPrivate->nHoldLength; 1616 } 1617 } 1618 else { 1619 if( !pComponentPrivate->InBuf_Eos_alreadysent ){ 1620 /* received buffer with less than 1 AMR frame length. Save the data in pHoldBuffer.*/ 1621 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen; 1622 /* save the data into pHoldBuffer */ 1623 if (pComponentPrivate->pHoldBuffer == NULL) { 1624 OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8); 1625 } 1626 1627 if(pComponentPrivate->nHoldLength <= NBAMRENC_INPUT_FRAME_SIZE) { 1628 memcpy(pComponentPrivate->pHoldBuffer, pBufHeader->pBuffer, pComponentPrivate->nHoldLength); 1629 } 1630 else { 1631 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: pHoldLenght is bigger than the input frame size\n", __LINE__); 1632 goto EXIT; 1633 } 1634 } 1635 /* since not enough data, we shouldn't send anything to SN, but instead request to EmptyBufferDone again.*/ 1636 if (pComponentPrivate->curState != OMX_StatePause ) { 1637 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Calling EmptyBufferDone\n",__LINE__); 1638 1639 #ifdef __PERF_INSTRUMENTATION__ 1640 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1641 pBufHeader->pBuffer, 1642 0, 1643 PERF_ModuleHLMM); 1644 #endif 1645 1646 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle, 1647 pComponentPrivate->pHandle->pApplicationPrivate, 1648 pBufHeader); 1649 pComponentPrivate->nEmptyBufferDoneCount++; 1650 1651 } 1652 else { 1653 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 1654 } 1655 1656 pComponentPrivate->ProcessingInputBuf--; 1657 goto EXIT; 1658 1659 } 1660 } 1661 else { 1662 if((pComponentPrivate->nHoldLength+pBufHeader->nFilledLen) > pBufHeader->nAllocLen){ 1663 /*means that a second Acumulator must be used to insert holdbuffer to pbuffer and save remaining bytes 1664 into hold buffer*/ 1665 remainingBytes = pComponentPrivate->nHoldLength+pBufHeader->nFilledLen-pBufHeader->nAllocLen; 1666 if (pComponentPrivate->pHoldBuffer2 == NULL) { 1667 OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer2, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8); 1668 } 1669 pExtraData = (pBufHeader->pBuffer)+(pBufHeader->nFilledLen-remainingBytes); 1670 memcpy(pComponentPrivate->pHoldBuffer2,pExtraData,remainingBytes); 1671 pBufHeader->nFilledLen-=remainingBytes; 1672 memmove(pBufHeader->pBuffer+ pComponentPrivate->nHoldLength,pBufHeader->pBuffer,pBufHeader->nFilledLen); 1673 memcpy(pBufHeader->pBuffer,pComponentPrivate->pHoldBuffer,pComponentPrivate->nHoldLength); 1674 pBufHeader->nFilledLen+=pComponentPrivate->nHoldLength; 1675 memcpy(pComponentPrivate->pHoldBuffer, pComponentPrivate->pHoldBuffer2, remainingBytes); 1676 pComponentPrivate->nHoldLength=remainingBytes; 1677 } 1678 else{ 1679 memmove(pBufHeader->pBuffer+pComponentPrivate->nHoldLength, pBufHeader->pBuffer, pBufHeader->nFilledLen); 1680 memcpy(pBufHeader->pBuffer,pComponentPrivate->pHoldBuffer, pComponentPrivate->nHoldLength); 1681 pBufHeader->nFilledLen+=pComponentPrivate->nHoldLength; 1682 pComponentPrivate->nHoldLength=0; 1683 } 1684 frameLength = NBAMRENC_INPUT_FRAME_SIZE; 1685 nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength); 1686 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames; 1687 pExtraData = pBufHeader->pBuffer + pBufHeader->nFilledLen-pComponentPrivate->nHoldLength; 1688 memcpy(pComponentPrivate->pHoldBuffer, pExtraData, pComponentPrivate->nHoldLength); 1689 pBufHeader->nFilledLen-=pComponentPrivate->nHoldLength; 1690 if(nFrames < 1 ){ 1691 if (pComponentPrivate->curState != OMX_StatePause ) { 1692 OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: Calling EmptyBufferDone\n",__LINE__); 1693 1694 #ifdef __PERF_INSTRUMENTATION__ 1695 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1696 pBufHeader->pBuffer, 1697 0, 1698 PERF_ModuleHLMM); 1699 #endif 1700 1701 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle, 1702 pComponentPrivate->pHandle->pApplicationPrivate, 1703 pBufHeader); 1704 pComponentPrivate->nEmptyBufferDoneCount++; 1705 1706 } 1707 else { 1708 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 1709 } 1710 goto EXIT; 1711 } 1712 } 1713 }else{ 1714 if((pBufHeader->nFlags&OMX_BUFFERFLAG_EOS) != OMX_BUFFERFLAG_EOS){ 1715 if (pComponentPrivate->dasfMode == 0 && !pBufHeader->pMarkData) { 1716 #ifdef __PERF_INSTRUMENTATION__ 1717 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1718 pComponentPrivate->pInputBufferList->pBufHdr[0]->pBuffer, 1719 0, 1720 PERF_ModuleHLMM); 1721 #endif 1722 1723 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle, 1724 pComponentPrivate->pHandle->pApplicationPrivate, 1725 pComponentPrivate->pInputBufferList->pBufHdr[0]); 1726 pComponentPrivate->nEmptyBufferDoneCount++; 1727 pComponentPrivate->ProcessingInputBuf--; 1728 1729 } 1730 } 1731 else{ 1732 frameLength = NBAMRENC_INPUT_FRAME_SIZE; 1733 nFrames=1; 1734 } 1735 } 1736 if(nFrames >= 1){ 1737 eError = NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr); 1738 if (eError != OMX_ErrorNone) { 1739 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Invalid Buffer Came ...\n",__LINE__); 1740 goto EXIT; 1741 } 1742 1743 #ifdef __PERF_INSTRUMENTATION__ 1744 /*For Steady State Instumentation*/ 1745 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1746 PREF(pBufHeader,pBuffer), 1747 pComponentPrivate->pPortDef[OMX_DirInput]->nBufferSize, 1748 PERF_ModuleCommonLayer); 1749 #endif 1750 1751 /*---------------------------------------------------------------*/ 1752 1753 pComponentPrivate->nNumOfFramesSent = nFrames; 1754 1755 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec); 1756 1757 if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){ 1758 OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, NBAMRENC_FrameStruct); 1759 OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/ 1760 (void*)pLcmlHdr->pBufferParam->pParamElem, 1761 pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg); 1762 pLcmlHdr->pBufferParam->pParamElem = NULL; 1763 } 1764 1765 if(pLcmlHdr->pFrameParam==NULL ){ 1766 OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(NBAMRENC_FrameStruct)*nFrames),OMX_U8); 1767 eError = OMX_DmmMap(phandle->dspCodec->hProc, 1768 nFrames*sizeof(NBAMRENC_FrameStruct), 1769 (void*)pLcmlHdr->pFrameParam, 1770 (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg); 1771 if (eError != OMX_ErrorNone){ 1772 OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n\n"); 1773 goto EXIT; 1774 } 1775 pLcmlHdr->pBufferParam->pParamElem = (NBAMRENC_FrameStruct *)pLcmlHdr->pDmmBuf->pMapped; /*DSP Address*/ 1776 } 1777 1778 for(i=0;i<nFrames;i++){ 1779 (pLcmlHdr->pFrameParam+i)->usLastFrame = 0; 1780 } 1781 1782 if((pBufHeader->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { 1783 (pLcmlHdr->pFrameParam+(nFrames-1))->usLastFrame = OMX_BUFFERFLAG_EOS; 1784 pComponentPrivate->InBuf_Eos_alreadysent = 1; /*TRUE*/ 1785 if(pComponentPrivate->dasfMode == 0) { 1786 if(!pBufHeader->nFilledLen){ 1787 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS; 1788 } 1789 pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle, 1790 pComponentPrivate->pHandle->pApplicationPrivate, 1791 OMX_EventBufferFlag, 1792 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nOutputPortIndex, 1793 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags, NULL); 1794 } 1795 pBufHeader->nFlags = 0; 1796 } 1797 pLcmlHdr->pBufferParam->usNbFrames = nFrames; 1798 /*---------------------------------------------------------------*/ 1799 /* Store time stamp information */ 1800 /*pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;*/ 1801 if (!pComponentPrivate->bFirstInputBufReceived) { 1802 /* Reset TimeStamp when first input buffer received */ 1803 pComponentPrivate->TimeStamp = 0; 1804 /* First Input buffer received */ 1805 pComponentPrivate->bFirstInputBufReceived = OMX_TRUE; 1806 } 1807 /* Store nTickCount information */ 1808 pComponentPrivate->arrTickCount[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount; 1809 pComponentPrivate->IpBufindex++; 1810 pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual; 1811 1812 if (pComponentPrivate->curState == OMX_StateExecuting) { 1813 if(!pComponentPrivate->bDspStoppedWhileExecuting) 1814 { 1815 if (!NBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) { 1816 NBAMRENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__); 1817 /* if (pLcmlHdr->buffer->nFilledLen != 0) 1818 fwrite(pLcmlHdr->buffer->pBuffer, 1, pLcmlHdr->buffer->nFilledLen, fOut); 1819 */ 1820 /* fflush(fOut); */ 1821 1822 /* 1823 fclose(fOut); 1824 */ 1825 1826 eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle, 1827 EMMCodecInputBuffer, 1828 (OMX_U8 *)pBufHeader->pBuffer, 1829 pBufHeader->nAllocLen, 1830 pBufHeader->nFilledLen, 1831 (OMX_U8 *) pLcmlHdr->pBufferParam, 1832 sizeof(NBAMRENC_ParamStruct), 1833 NULL); 1834 if (eError != OMX_ErrorNone) { 1835 eError = OMX_ErrorHardware; 1836 goto EXIT; 1837 } 1838 pComponentPrivate->lcml_nIpBuf++; 1839 } 1840 } 1841 } 1842 else if(pComponentPrivate->curState == OMX_StatePause){ 1843 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader; 1844 } 1845 pComponentPrivate->ProcessingInputBuf--; 1846 } 1847 /******************************************************************************/ 1848 if(pBufHeader->pMarkData){ 1849 if(pComponentPrivate->pOutputBufferList->pBufHdr[0]!=NULL) { 1850 /* copy mark to output buffer header */ 1851 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData; 1852 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent; 1853 } 1854 /* trigger event handler if we are supposed to */ 1855 if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){ 1856 pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle, 1857 pComponentPrivate->pHandle->pApplicationPrivate, 1858 OMX_EventMark, 1859 0, 1860 0, 1861 pBufHeader->pMarkData); 1862 } 1863 if (pComponentPrivate->curState != OMX_StatePause && !NBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) { 1864 OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: Calling EmptyBufferDone\n",__LINE__); 1865 1866 #ifdef __PERF_INSTRUMENTATION__ 1867 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1868 pBufHeader->pBuffer, 1869 0, 1870 PERF_ModuleHLMM); 1871 #endif 1872 1873 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle, 1874 pComponentPrivate->pHandle->pApplicationPrivate, 1875 pBufHeader); 1876 pComponentPrivate->nEmptyBufferDoneCount++; 1877 1878 } 1879 } 1880 1881 if (pComponentPrivate->bFlushInputPortCommandPending) { 1882 OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL); 1883 } 1884 1885 } else if (eDir == OMX_DirOutput) { 1886 /* Make sure that output buffer is issued to output stream only when 1887 * there is an outstanding input buffer already issued on input stream 1888 */ 1889 1890 /***--------------------------------------****/ 1891 pComponentPrivate->nUnhandledFillThisBuffers--; 1892 nFrames = pComponentPrivate->nNumOfFramesSent; 1893 if(nFrames == 0) 1894 nFrames = 1; 1895 1896 eError = NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr); 1897 1898 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec); 1899 1900 if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){ 1901 OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, NBAMRENC_FrameStruct); 1902 #ifndef UNDER_CE 1903 OMX_DmmUnMap(phandle->dspCodec->hProc, 1904 (void*)pLcmlHdr->pBufferParam->pParamElem, 1905 pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg); 1906 #endif 1907 1908 pLcmlHdr->pBufferParam->pParamElem = NULL; 1909 } 1910 1911 if(pLcmlHdr->pFrameParam==NULL ){ 1912 OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(NBAMRENC_FrameStruct)*nFrames ),OMX_U8); 1913 #ifndef UNDER_CE 1914 eError = OMX_DmmMap(phandle->dspCodec->hProc, 1915 nFrames*sizeof(NBAMRENC_FrameStruct), 1916 (void*)pLcmlHdr->pFrameParam, 1917 (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg); 1918 1919 if (eError != OMX_ErrorNone) 1920 { 1921 OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n"); 1922 goto EXIT; 1923 } 1924 pLcmlHdr->pBufferParam->pParamElem = (NBAMRENC_FrameStruct *)pLcmlHdr->pDmmBuf->pMapped; /*DSP Address*/ 1925 #endif 1926 } 1927 1928 pLcmlHdr->pBufferParam->usNbFrames = nFrames; 1929 1930 if (pComponentPrivate->curState == OMX_StateExecuting) { 1931 if (!NBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) { 1932 NBAMRENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__); 1933 eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle, 1934 EMMCodecOuputBuffer, 1935 (OMX_U8 *)pBufHeader->pBuffer, 1936 NBAMRENC_OUTPUT_FRAME_SIZE * nFrames, 1937 0, 1938 (OMX_U8 *) pLcmlHdr->pBufferParam, 1939 sizeof(NBAMRENC_ParamStruct), 1940 NULL); 1941 OMX_PRBUFFER1(pComponentPrivate->dbg, "After QueueBuffer Line %d\n",__LINE__); 1942 if (eError != OMX_ErrorNone ) { 1943 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Issuing DSP OP: Error Occurred\n",__LINE__); 1944 eError = OMX_ErrorHardware; 1945 goto EXIT; 1946 } 1947 pComponentPrivate->lcml_nOpBuf++; 1948 pComponentPrivate->num_Op_Issued++; 1949 } 1950 } 1951 else if (pComponentPrivate->curState == OMX_StatePause){ 1952 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader; 1953 } 1954 pComponentPrivate->ProcessingOutputBuf--; 1955 1956 if (pComponentPrivate->bFlushOutputPortCommandPending) { 1957 OMX_SendCommand( pComponentPrivate->pHandle, 1958 OMX_CommandFlush, 1959 1,NULL); 1960 } 1961 1962 } 1963 else { 1964 eError = OMX_ErrorBadParameter; 1965 } 1966 1967 EXIT: 1968 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting from NBAMRENC_HandleDataBufFromApp \n",__LINE__); 1969 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning error %d\n",__LINE__,eError); 1970 1971 return eError; 1972 } 1973 1974 /*-------------------------------------------------------------------*/ 1975 /** 1976 * NBAMRENC_GetBufferDirection () This function is used by the component 1977 * to get the direction of the buffer 1978 * @param eDir pointer will be updated with buffer direction 1979 * @param pBufHeader pointer to the buffer to be requested to be filled 1980 * 1981 * @retval none 1982 **/ 1983 /*-------------------------------------------------------------------*/ 1984 1985 OMX_ERRORTYPE NBAMRENC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, 1986 OMX_DIRTYPE *eDir) 1987 { 1988 OMX_ERRORTYPE eError = OMX_ErrorNone; 1989 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate; 1990 OMX_U32 nBuf = 0; 1991 OMX_BUFFERHEADERTYPE *pBuf = NULL; 1992 OMX_U16 flag = 1,i = 0; 1993 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_GetBufferDirection Function\n",__LINE__); 1994 /*Search this buffer in input buffers list */ 1995 nBuf = pComponentPrivate->pInputBufferList->numBuffers; 1996 for(i=0; i<nBuf; i++) { 1997 pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i]; 1998 if(pBufHeader == pBuf) { 1999 *eDir = OMX_DirInput; 2000 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is INPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf); 2001 flag = 0; 2002 goto EXIT; 2003 } 2004 } 2005 /*Search this buffer in output buffers list */ 2006 nBuf = pComponentPrivate->pOutputBufferList->numBuffers; 2007 for(i=0; i<nBuf; i++) { 2008 pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 2009 if(pBufHeader == pBuf) { 2010 *eDir = OMX_DirOutput; 2011 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf); 2012 flag = 0; 2013 goto EXIT; 2014 } 2015 } 2016 2017 if (flag == 1) { 2018 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Buffer %p is Not Found in the List\n",__LINE__, pBufHeader); 2019 eError = OMX_ErrorUndefined; 2020 goto EXIT; 2021 } 2022 EXIT: 2023 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_GetBufferDirection Function\n",__LINE__); 2024 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 2025 return eError; 2026 } 2027 2028 /* -------------------------------------------------------------------*/ 2029 /** 2030 * NBAMRENC_GetCorrespondingLCMLHeader() function will be called by LCML_Callback 2031 * component to write the msg 2032 * @param *pBuffer, Event which gives to details about USN status 2033 * @param NBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr 2034 * @param OMX_DIRTYPE eDir this gives direction of the buffer 2035 * @retval OMX_NoError Success, ready to roll 2036 * OMX_Error_BadParameter The input parameter pointer is null 2037 **/ 2038 /* -------------------------------------------------------------------*/ 2039 OMX_ERRORTYPE NBAMRENC_GetCorrespondingLCMLHeader(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, 2040 OMX_U8 *pBuffer, 2041 OMX_DIRTYPE eDir, 2042 NBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr) 2043 { 2044 OMX_ERRORTYPE eError = OMX_ErrorNone; 2045 NBAMRENC_LCML_BUFHEADERTYPE *pLcmlBufHeader; 2046 OMX_S16 nIpBuf; 2047 OMX_S16 nOpBuf; 2048 OMX_S16 i; 2049 2050 AMRENC_COMPONENT_PRIVATE *pComponentPrivate_CC; 2051 2052 pComponentPrivate_CC = (AMRENC_COMPONENT_PRIVATE*) pComponentPrivate; 2053 nIpBuf = pComponentPrivate_CC->pInputBufferList->numBuffers; 2054 nOpBuf = pComponentPrivate_CC->pOutputBufferList->numBuffers; 2055 2056 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Entering NBAMRENC_GetCorrespondingLCMLHeader..\n",__LINE__); 2057 while (!pComponentPrivate_CC->bInitParamsInitialized) { 2058 OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: Waiting for init to complete........\n",__LINE__); 2059 #ifndef UNDER_CE 2060 sched_yield(); 2061 #else 2062 Sleep(1); 2063 #endif 2064 } 2065 if(eDir == OMX_DirInput) { 2066 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: Entering NBAMRENC_GetCorrespondingLCMLHeader..\n",__LINE__); 2067 pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[NBAMRENC_INPUT_PORT]; 2068 for(i = 0; i < nIpBuf; i++) { 2069 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: pBuffer = %p\n",__LINE__,pBuffer); 2070 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer); 2071 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) { 2072 *ppLcmlHdr = pLcmlBufHeader; 2073 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: Corresponding Input LCML Header Found = %p\n",__LINE__,pLcmlBufHeader); 2074 eError = OMX_ErrorNone; 2075 goto EXIT; 2076 } 2077 pLcmlBufHeader++; 2078 } 2079 } else if (eDir == OMX_DirOutput) { 2080 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Entering NBAMRENC_GetCorrespondingLCMLHeader..\n",__LINE__); 2081 pLcmlBufHeader = pComponentPrivate_CC->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT]; 2082 for(i = 0; i < nOpBuf; i++) { 2083 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: pBuffer = %p\n",__LINE__,pBuffer); 2084 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer); 2085 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) { 2086 *ppLcmlHdr = pLcmlBufHeader; 2087 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: Corresponding Output LCML Header Found = %p\n",__LINE__,pLcmlBufHeader); 2088 eError = OMX_ErrorNone; 2089 goto EXIT; 2090 } 2091 pLcmlBufHeader++; 2092 } 2093 } else { 2094 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: Invalid Buffer Type :: exiting...\n",__LINE__); 2095 eError = OMX_ErrorUndefined; 2096 } 2097 2098 EXIT: 2099 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting NBAMRENC_GetCorrespondingLCMLHeader..\n",__LINE__); 2100 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 2101 return eError; 2102 } 2103 2104 /* -------------------------------------------------------------------*/ 2105 /** 2106 * NBAMRENC_LCMLCallback() will be called LCML component to write the msg 2107 * 2108 * @param event Event which gives to details about USN status 2109 * @param void * args // args [0] //bufType; 2110 // args [1] //arm address fpr buffer 2111 // args [2] //BufferSize; 2112 // args [3] //arm address for param 2113 // args [4] //ParamSize; 2114 // args [6] //LCML Handle 2115 * @retval OMX_NoError Success, ready to roll 2116 * OMX_Error_BadParameter The input parameter pointer is null 2117 **/ 2118 /*-------------------------------------------------------------------*/ 2119 2120 OMX_ERRORTYPE NBAMRENC_LCMLCallback (TUsnCodecEvent event,void * args[10]) 2121 { 2122 OMX_ERRORTYPE eError = OMX_ErrorNone; 2123 OMX_U8 *pBuffer = args[1]; 2124 NBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr; 2125 OMX_U16 i,index,frameLength, length; 2126 OMX_COMPONENTTYPE *pHandle; 2127 LCML_DSP_INTERFACE *pLcmlHandle; 2128 OMX_U8 nFrames; 2129 OMX_U32 buffer_duration = 0; 2130 2131 NBAMRENC_BUFDATA* OutputFrames = NULL; 2132 2133 AMRENC_COMPONENT_PRIVATE* pComponentPrivate_CC = NULL; 2134 pComponentPrivate_CC = (AMRENC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate; 2135 pHandle = pComponentPrivate_CC->pHandle; 2136 2137 2138 #ifdef AMRENC_DEBUG 2139 switch(event) { 2140 2141 case EMMCodecDspError: 2142 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecDspError\n"); 2143 break; 2144 2145 case EMMCodecInternalError: 2146 OMX_ERROR4(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecInternalError\n"); 2147 break; 2148 2149 case EMMCodecInitError: 2150 OMX_ERROR4(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecInitError\n"); 2151 break; 2152 2153 case EMMCodecDspMessageRecieved: 2154 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecDspMessageRecieved\n"); 2155 break; 2156 2157 case EMMCodecBufferProcessed: 2158 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferProcessed\n"); 2159 break; 2160 2161 case EMMCodecProcessingStarted: 2162 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStarted\n"); 2163 break; 2164 2165 case EMMCodecProcessingPaused: 2166 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingPaused\n"); 2167 break; 2168 2169 case EMMCodecProcessingStoped: 2170 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStoped\n"); 2171 break; 2172 2173 case EMMCodecProcessingEof: 2174 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingEof\n"); 2175 break; 2176 2177 case EMMCodecBufferNotProcessed: 2178 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferNotProcessed\n"); 2179 break; 2180 2181 case EMMCodecAlgCtrlAck: 2182 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecAlgCtrlAck\n"); 2183 break; 2184 2185 case EMMCodecStrmCtrlAck: 2186 OMX_PRDSP2(pComponentPrivate_CC->dbg, "[LCML CALLBACK EVENT] EMMCodecStrmCtrlAck\n"); 2187 break; 2188 } 2189 #endif 2190 2191 if(event == EMMCodecBufferProcessed) 2192 { 2193 2194 if((OMX_U32)args[0] == EMMCodecInputBuffer) { 2195 OMX_PRBUFFER1(pComponentPrivate_CC->dbg, "%d :: INPUT: pBuffer = %p\n",__LINE__, pBuffer); 2196 eError = NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate_CC,pBuffer, OMX_DirInput, &pLcmlHdr); 2197 if (eError != OMX_ErrorNone) { 2198 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: Error: Invalid Buffer Came ...\n",__LINE__); 2199 goto EXIT; 2200 } 2201 #ifdef __PERF_INSTRUMENTATION__ 2202 PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp, 2203 PREF(pLcmlHdr->buffer,pBuffer), 2204 0, 2205 PERF_ModuleCommonLayer); 2206 #endif 2207 2208 NBAMRENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirInput,__LINE__); 2209 2210 #ifdef __PERF_INSTRUMENTATION__ 2211 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2212 pLcmlHdr->buffer->pBuffer, 2213 0, 2214 PERF_ModuleHLMM); 2215 #endif 2216 pComponentPrivate_CC->cbInfo.EmptyBufferDone( pHandle, 2217 pHandle->pApplicationPrivate, 2218 pLcmlHdr->buffer); 2219 pComponentPrivate_CC->nEmptyBufferDoneCount++; 2220 pComponentPrivate_CC->nOutStandingEmptyDones--; 2221 pComponentPrivate_CC->lcml_nIpBuf--; 2222 pComponentPrivate_CC->app_nBuf++; 2223 2224 pComponentPrivate_CC->nOutStandingEmptyDones++; 2225 2226 } else if((OMX_U32)args[0] == EMMCodecOuputBuffer) { 2227 2228 if (!NBAMRENC_IsValid(pComponentPrivate_CC,pBuffer,OMX_DirOutput)) { 2229 2230 for (i=0; i < pComponentPrivate_CC->pOutputBufferList->numBuffers; i++) { 2231 #ifdef __PERF_INSTRUMENTATION__ 2232 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2233 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->pBuffer, 2234 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFilledLen, 2235 PERF_ModuleHLMM); 2236 #endif 2237 pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle, 2238 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2239 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i++] 2240 ); 2241 } 2242 } else { 2243 2244 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: OUTPUT: pBuffer = %p\n",__LINE__, pBuffer); 2245 2246 pComponentPrivate_CC->nOutStandingFillDones++; 2247 2248 eError = NBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate_CC, pBuffer, OMX_DirOutput, &pLcmlHdr); 2249 if (eError != OMX_ErrorNone) { 2250 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: Error: Invalid Buffer Came ...\n",__LINE__); 2251 goto EXIT; 2252 } 2253 2254 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: Output: pLcmlHdr->buffer->pBuffer = %p\n",__LINE__, pLcmlHdr->buffer->pBuffer); 2255 pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8]; 2256 OMX_PRBUFFER1(pComponentPrivate_CC->dbg, "%d :: Output: pBuffer = %ld\n",__LINE__, pLcmlHdr->buffer->nFilledLen); 2257 #if 0 2258 pLcmlHdr->buffer->nFilledLen = 32; 2259 OMX_PRBUFFER1(pComponentPrivate_CC->dbg, "%d :: Output: ::RESET:: pBuffer->nFilledLen = %ld\n",__LINE__, pLcmlHdr->buffer->nFilledLen); 2260 #endif 2261 2262 #ifdef __PERF_INSTRUMENTATION__ 2263 PERF_ReceivedFrame(pComponentPrivate_CC->pPERFcomp, 2264 PREF(pLcmlHdr->buffer,pBuffer), 2265 PREF(pLcmlHdr->buffer,nFilledLen), 2266 PERF_ModuleCommonLayer); 2267 2268 pComponentPrivate_CC->nLcml_nCntOpReceived++; 2269 2270 if ((pComponentPrivate_CC->nLcml_nCntIp >= 1) && (pComponentPrivate_CC->nLcml_nCntOpReceived == 1)) { 2271 PERF_Boundary(pComponentPrivate_CC->pPERFcomp, 2272 PERF_BoundaryStart | PERF_BoundarySteadyState); 2273 } 2274 #endif 2275 2276 NBAMRENC_ClearPending(pComponentPrivate_CC,pLcmlHdr->buffer,OMX_DirOutput,__LINE__); 2277 2278 pComponentPrivate_CC->LastOutbuf = pLcmlHdr->buffer; 2279 if(!pLcmlHdr->pBufferParam->usNbFrames){ 2280 pLcmlHdr->pBufferParam->usNbFrames++; 2281 } 2282 if((pComponentPrivate_CC->frameMode == NBAMRENC_MIMEMODE)&&(pLcmlHdr->buffer->nFilledLen)) { 2283 nFrames = (OMX_U8)( pLcmlHdr->buffer->nFilledLen / NBAMRENC_OUTPUT_BUFFER_SIZE_MIME); 2284 frameLength=0; 2285 length=0; 2286 for(i=0;i<nFrames;i++){ 2287 index = (pLcmlHdr->buffer->pBuffer[i*NBAMRENC_OUTPUT_BUFFER_SIZE_MIME] >> 3) & 0x0F; 2288 if(pLcmlHdr->buffer->nFilledLen == 0) 2289 length = 0; 2290 else 2291 length = (OMX_U16)pComponentPrivate_CC->amrMimeBytes[index]; 2292 if (i){ 2293 memmove( pLcmlHdr->buffer->pBuffer + frameLength, 2294 pLcmlHdr->buffer->pBuffer + (i * NBAMRENC_OUTPUT_BUFFER_SIZE_MIME), 2295 length); 2296 } 2297 frameLength += length; 2298 } 2299 pLcmlHdr->buffer->nFilledLen= frameLength; 2300 } 2301 else if((pComponentPrivate_CC->frameMode == NBAMRENC_IF2)&&(pLcmlHdr->buffer->nFilledLen)) { 2302 nFrames = (OMX_U8)( pLcmlHdr->buffer->nFilledLen / NBAMRENC_OUTPUT_BUFFER_SIZE_IF2); 2303 frameLength=0; 2304 length=0; 2305 for(i=0;i<nFrames;i++){ 2306 index = (pLcmlHdr->buffer->pBuffer[i*NBAMRENC_OUTPUT_BUFFER_SIZE_IF2]) & 0x0F; 2307 if(pLcmlHdr->buffer->nFilledLen == 0) 2308 length = 0; 2309 else 2310 length = (OMX_U16)pComponentPrivate_CC->amrIf2Bytes[index]; 2311 if (i){ 2312 memmove( pLcmlHdr->buffer->pBuffer + frameLength, 2313 pLcmlHdr->buffer->pBuffer + (i * NBAMRENC_OUTPUT_BUFFER_SIZE_IF2), 2314 length); 2315 } 2316 frameLength += length; 2317 } 2318 pLcmlHdr->buffer->nFilledLen= frameLength; 2319 } else{ 2320 if ((pComponentPrivate_CC->efrMode == 1)&&(pLcmlHdr->buffer->nFilledLen)){ 2321 nFrames = pLcmlHdr->buffer->nFilledLen/NBAMRENC_OUTPUT_BUFFER_SIZE_EFR; 2322 } 2323 else 2324 nFrames = pLcmlHdr->buffer->nFilledLen/NBAMRENC_OUTPUT_FRAME_SIZE; 2325 } 2326 2327 OutputFrames = pLcmlHdr->buffer->pOutputPortPrivate; 2328 OutputFrames->nFrames = nFrames; 2329 2330 2331 if( !pComponentPrivate_CC->dasfMode){ 2332 /* Copying time stamp information to output buffer */ 2333 /*pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate_CC->arrBufIndex[pComponentPrivate_CC->OpBufindex];*/ 2334 pLcmlHdr->buffer->nTimeStamp = pComponentPrivate_CC->TimeStamp; 2335 buffer_duration = (160*nFrames*1000000) / 2336 (pComponentPrivate_CC->pcmParams->nSamplingRate*pComponentPrivate_CC->pcmParams->nChannels) ; 2337 /* Update time stamp information */ 2338 pComponentPrivate_CC->TimeStamp += (OMX_TICKS)buffer_duration; 2339 /* Copying nTickCount information to output buffer */ 2340 pLcmlHdr->buffer->nTickCount = pComponentPrivate_CC->arrTickCount[pComponentPrivate_CC->OpBufindex]; 2341 pComponentPrivate_CC->OpBufindex++; 2342 pComponentPrivate_CC->OpBufindex %= pComponentPrivate_CC->pPortDef[OMX_DirOutput]->nBufferCountActual; 2343 } 2344 2345 #ifdef __PERF_INSTRUMENTATION__ 2346 PERF_SendingBuffer(pComponentPrivate_CC->pPERFcomp, 2347 pLcmlHdr->buffer->pBuffer, 2348 pLcmlHdr->buffer->nFilledLen, 2349 PERF_ModuleHLMM); 2350 #endif 2351 /* Non Multi Frame Mode has been tested here */ 2352 2353 pComponentPrivate_CC->nFillBufferDoneCount++; 2354 pComponentPrivate_CC->nOutStandingFillDones--; 2355 pComponentPrivate_CC->lcml_nOpBuf--; 2356 pComponentPrivate_CC->app_nBuf++; 2357 2358 pComponentPrivate_CC->cbInfo.FillBufferDone( pHandle, 2359 pHandle->pApplicationPrivate, 2360 pLcmlHdr->buffer); 2361 2362 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: Incrementing app_nBuf = %ld\n",__LINE__,pComponentPrivate_CC->app_nBuf); 2363 } 2364 } 2365 } 2366 else if (event == EMMCodecStrmCtrlAck) { 2367 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE USN_DSPACK_STRMCTRL \n",__LINE__); 2368 if (args[1] == (void *)USN_STRMCMD_FLUSH) { 2369 pHandle = pComponentPrivate_CC->pHandle; 2370 if ( args[2] == (void *)EMMCodecInputBuffer) { 2371 if (args[0] == (void *)USN_ERR_NONE ) { 2372 OMX_PRCOMM1(pComponentPrivate_CC->dbg, "Flushing input port %d\n",__LINE__); 2373 2374 for (i=0; i < pComponentPrivate_CC->nNumInputBufPending; i++) { 2375 2376 #ifdef __PERF_INSTRUMENTATION__ 2377 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2378 pComponentPrivate_CC->pInputBufferList->pBufHdr[i]->pBuffer, 2379 0, 2380 PERF_ModuleHLMM); 2381 #endif 2382 2383 pComponentPrivate_CC->cbInfo.EmptyBufferDone ( 2384 pHandle, 2385 pHandle->pApplicationPrivate, 2386 pComponentPrivate_CC->pInputBufHdrPending[i] 2387 ); 2388 pComponentPrivate_CC->nEmptyBufferDoneCount++; 2389 pComponentPrivate_CC->nOutStandingEmptyDones--; 2390 2391 } 2392 pComponentPrivate_CC->nNumInputBufPending=0; 2393 pComponentPrivate_CC->cbInfo.EventHandler( 2394 pHandle, pHandle->pApplicationPrivate, 2395 OMX_EventCmdComplete, OMX_CommandFlush,NBAMRENC_INPUT_PORT, NULL); 2396 } else { 2397 OMX_ERROR4(pComponentPrivate_CC->dbg, "LCML reported error while flushing input port\n"); 2398 goto EXIT; 2399 } 2400 } 2401 else if ( args[2] == (void *)EMMCodecOuputBuffer) { 2402 if (args[0] == (void *)USN_ERR_NONE ) { 2403 OMX_PRCOMM1(pComponentPrivate_CC->dbg, "Flushing output port %d\n",__LINE__); 2404 2405 for (i=0; i < pComponentPrivate_CC->nNumOutputBufPending; i++) { 2406 #ifdef __PERF_INSTRUMENTATION__ 2407 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2408 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->pBuffer, 2409 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFilledLen, 2410 PERF_ModuleHLMM); 2411 #endif 2412 pComponentPrivate_CC->cbInfo.FillBufferDone ( 2413 pHandle, 2414 pHandle->pApplicationPrivate, 2415 pComponentPrivate_CC->pOutputBufHdrPending[i] 2416 ); 2417 pComponentPrivate_CC->nFillBufferDoneCount++; 2418 pComponentPrivate_CC->nOutStandingFillDones--; 2419 2420 } 2421 pComponentPrivate_CC->nNumOutputBufPending=0; 2422 pComponentPrivate_CC->cbInfo.EventHandler( 2423 pHandle, pHandle->pApplicationPrivate, 2424 OMX_EventCmdComplete, OMX_CommandFlush,NBAMRENC_OUTPUT_PORT, NULL); 2425 } else { 2426 OMX_ERROR4(pComponentPrivate_CC->dbg, "LCML reported error while flushing output port\n"); 2427 goto EXIT; 2428 } 2429 } 2430 } 2431 } 2432 else if(event == EMMCodecProcessingStoped) { 2433 2434 pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex); 2435 if(pComponentPrivate_CC->codecStop_waitingsignal == 0){ 2436 pComponentPrivate_CC->codecStop_waitingsignal = 1; 2437 pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold); 2438 OMX_PRINT2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n"); 2439 } 2440 pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex); 2441 2442 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE USN_DSPACK_STOP \n",__LINE__); 2443 2444 for (i=0; i < pComponentPrivate_CC->pInputBufferList->numBuffers; i++) { 2445 2446 if (pComponentPrivate_CC->pInputBufferList->bBufferPending[i]) { 2447 2448 #ifdef __PERF_INSTRUMENTATION__ 2449 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2450 pComponentPrivate_CC->pInputBufferList->pBufHdr[i]->pBuffer, 2451 0, 2452 PERF_ModuleHLMM); 2453 #endif 2454 2455 pComponentPrivate_CC->cbInfo.EmptyBufferDone ( 2456 pComponentPrivate_CC->pHandle, 2457 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2458 pComponentPrivate_CC->pInputBufferList->pBufHdr[i] 2459 ); 2460 pComponentPrivate_CC->nEmptyBufferDoneCount++; 2461 pComponentPrivate_CC->nOutStandingEmptyDones--; 2462 NBAMRENC_ClearPending(pComponentPrivate_CC, pComponentPrivate_CC->pInputBufferList->pBufHdr[i], OMX_DirInput,__LINE__); 2463 } 2464 } 2465 2466 for (i=0; i < pComponentPrivate_CC->pOutputBufferList->numBuffers; i++) { 2467 if (pComponentPrivate_CC->pOutputBufferList->bBufferPending[i]) { 2468 #ifdef __PERF_INSTRUMENTATION__ 2469 PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp, 2470 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->pBuffer, 2471 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFilledLen, 2472 PERF_ModuleHLMM); 2473 #endif 2474 pComponentPrivate_CC->cbInfo.FillBufferDone ( 2475 pComponentPrivate_CC->pHandle, 2476 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2477 pComponentPrivate_CC->pOutputBufferList->pBufHdr[i] 2478 ); 2479 pComponentPrivate_CC->nFillBufferDoneCount++; 2480 pComponentPrivate_CC->nOutStandingFillDones--; 2481 2482 NBAMRENC_ClearPending(pComponentPrivate_CC, pComponentPrivate_CC->pOutputBufferList->pBufHdr[i], OMX_DirOutput,__LINE__); 2483 } 2484 } 2485 2486 if (!pComponentPrivate_CC->bNoIdleOnStop) { 2487 2488 pComponentPrivate_CC->nNumOutputBufPending=0; 2489 2490 pComponentPrivate_CC->ProcessingInputBuf=0; 2491 pComponentPrivate_CC->ProcessingOutputBuf=0; 2492 2493 pComponentPrivate_CC->nHoldLength = 0; 2494 pComponentPrivate_CC->InBuf_Eos_alreadysent = 0; 2495 2496 OMX_MEMFREE_STRUCT(pComponentPrivate_CC->pHoldBuffer); 2497 OMX_MEMFREE_STRUCT(pComponentPrivate_CC->iMMFDataLastBuffer); 2498 2499 pComponentPrivate_CC->curState = OMX_StateIdle; 2500 #ifdef RESOURCE_MANAGER_ENABLED 2501 eError = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL); 2502 #endif 2503 2504 if (pComponentPrivate_CC->bPreempted == 0) { 2505 /* Decrement reference count with signal enabled */ 2506 if(RemoveStateTransition(pComponentPrivate_CC, OMX_TRUE) != OMX_ErrorNone) { 2507 return OMX_ErrorUndefined; 2508 } 2509 2510 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle, 2511 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2512 OMX_EventCmdComplete, 2513 OMX_CommandStateSet, 2514 pComponentPrivate_CC->curState, 2515 NULL); 2516 } 2517 else{ 2518 pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle, 2519 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2520 OMX_EventError, 2521 OMX_ErrorResourcesPreempted, 2522 OMX_TI_ErrorSevere, 2523 NULL); 2524 } 2525 2526 2527 } 2528 else { 2529 pComponentPrivate_CC->bNoIdleOnStop= OMX_FALSE; 2530 pComponentPrivate_CC->bDspStoppedWhileExecuting = OMX_TRUE; 2531 } 2532 } 2533 else if(event == EMMCodecDspMessageRecieved) { 2534 OMX_PRSTATE1(pComponentPrivate_CC->dbg, "%d :: commandedState = %ld\n",__LINE__,(OMX_U32)args[0]); 2535 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg1 = %ld\n",__LINE__,(OMX_U32)args[1]); 2536 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg2 = %ld\n",__LINE__,(OMX_U32)args[2]); 2537 2538 if(0x0500 == (OMX_U32)args[2]) { 2539 OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: EMMCodecDspMessageRecieved\n",__LINE__); 2540 } 2541 } 2542 else if(event == EMMCodecAlgCtrlAck) { 2543 OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE USN_DSPACK_ALGCTRL \n",__LINE__); 2544 } 2545 else if (event == EMMCodecDspError) { 2546 switch ( (OMX_U32) args [4]) 2547 { 2548 /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully. 2549 * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message. 2550 * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message. 2551 * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error. 2552 * USN_ERR_STOP,: Indicates that execution of stop resulted in error. 2553 * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error. 2554 * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error. 2555 * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */ 2556 2557 #ifdef _ERROR_PROPAGATION__ 2558 case USN_ERR_PAUSE: 2559 case USN_ERR_STOP: 2560 case USN_ERR_ALGCTRL: 2561 case USN_ERR_STRMCTRL: 2562 case USN_ERR_UNKNOWN_MSG: 2563 { 2564 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE; 2565 pComponentPrivate_CC->curState = OMX_StateInvalid; 2566 pHandle = pComponentPrivate_CC->pHandle; 2567 pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 2568 pHandle->pApplicationPrivate, 2569 OMX_EventError, 2570 OMX_ErrorInvalidState, 2571 OMX_TI_ErrorSevere, 2572 NULL); 2573 } 2574 break; 2575 #endif 2576 2577 case USN_ERR_WARNING: 2578 case USN_ERR_PROCESS: 2579 NBAMRENC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]); 2580 break; 2581 default: 2582 break; 2583 } 2584 } 2585 else if (event == EMMCodecProcessingPaused) { 2586 pComponentPrivate_CC->nUnhandledEmptyThisBuffers = 0; 2587 pComponentPrivate_CC->nUnhandledFillThisBuffers = 0; 2588 pComponentPrivate_CC->curState = OMX_StatePause; 2589 2590 /* Decrement reference count with signal enabled */ 2591 if(RemoveStateTransition(pComponentPrivate_CC, OMX_TRUE) != OMX_ErrorNone) { 2592 return OMX_ErrorUndefined; 2593 } 2594 pComponentPrivate_CC->cbInfo.EventHandler( pComponentPrivate_CC->pHandle, 2595 pComponentPrivate_CC->pHandle->pApplicationPrivate, 2596 OMX_EventCmdComplete, 2597 OMX_CommandStateSet, 2598 pComponentPrivate_CC->curState, 2599 NULL); 2600 } 2601 #ifdef _ERROR_PROPAGATION__ 2602 else if (event ==EMMCodecInitError){ 2603 /* Cheking for MMU_fault */ 2604 if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) { 2605 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE; 2606 pComponentPrivate_CC->curState = OMX_StateInvalid; 2607 pHandle = pComponentPrivate_CC->pHandle; 2608 pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 2609 pHandle->pApplicationPrivate, 2610 OMX_EventError, 2611 OMX_ErrorInvalidState, 2612 OMX_TI_ErrorSevere, 2613 NULL); 2614 } 2615 } 2616 else if (event ==EMMCodecInternalError){ 2617 /* Cheking for MMU_fault */ 2618 if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) { 2619 OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__); 2620 pComponentPrivate_CC->bIsInvalidState=OMX_TRUE; 2621 pComponentPrivate_CC->curState = OMX_StateInvalid; 2622 pHandle = pComponentPrivate_CC->pHandle; 2623 pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 2624 pHandle->pApplicationPrivate, 2625 OMX_EventError, 2626 OMX_ErrorInvalidState, 2627 OMX_TI_ErrorSevere, 2628 NULL); 2629 } 2630 2631 } 2632 #endif 2633 EXIT: 2634 if (pComponentPrivate_CC != NULL) { 2635 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting the NBAMRENC_LCMLCallback Function\n", __LINE__); 2636 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Returning = 0x%x\n", __LINE__, eError); 2637 } 2638 2639 return eError; 2640 } 2641 2642 /* ================================================================================= */ 2643 /** 2644 * NBAMRENC_GetLCMLHandle() 2645 * 2646 * @retval OMX_HANDLETYPE 2647 */ 2648 /* ================================================================================= */ 2649 #ifndef UNDER_CE 2650 OMX_HANDLETYPE NBAMRENC_GetLCMLHandle(AMRENC_COMPONENT_PRIVATE *pComponentPrivate) 2651 { 2652 OMX_ERRORTYPE eError = OMX_ErrorNone; 2653 OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE); 2654 OMX_HANDLETYPE pHandle = NULL; 2655 void *handle; 2656 char *error; 2657 AMRENC_COMPONENT_PRIVATE* pComponentPrivate_CC = NULL; 2658 2659 OMX_PRINT1 (pComponentPrivate->dbg, "%d :: Entering NBAMRENC_GetLCMLHandle..\n",__LINE__); 2660 handle = dlopen("libLCML.so", RTLD_LAZY); 2661 if (!handle) { 2662 fputs(dlerror(), stderr); 2663 goto EXIT; 2664 } 2665 fpGetHandle = dlsym (handle, "GetHandle"); 2666 if ((error = dlerror()) != NULL) { 2667 fputs(error, stderr); 2668 goto EXIT; 2669 } 2670 eError = (*fpGetHandle)(&pHandle); 2671 if(eError != OMX_ErrorNone) { 2672 eError = OMX_ErrorUndefined; 2673 OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: OMX_ErrorUndefined...\n",__LINE__); 2674 pHandle = NULL; 2675 goto EXIT; 2676 } 2677 pComponentPrivate_CC = (AMRENC_COMPONENT_PRIVATE*)pComponentPrivate; 2678 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate; 2679 2680 pComponentPrivate->ptrLibLCML=handle; /* saving LCML lib pointer */ 2681 2682 EXIT: 2683 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting NBAMRENC_GetLCMLHandle..\n",__LINE__); 2684 OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 2685 return pHandle; 2686 } 2687 2688 #else 2689 /*WINDOWS Explicit dll load procedure*/ 2690 OMX_HANDLETYPE NBAMRENC_GetLCMLHandle(AMRENC_COMPONENT_PRIVATE *pComponentPrivate) 2691 { 2692 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE); 2693 OMX_HANDLETYPE pHandle = NULL; 2694 OMX_ERRORTYPE eError; 2695 LPFNDLLFUNC1 fpGetHandle1; 2696 2697 2698 if (!fpGetHandle1) { 2699 // handle the error 2700 return pHandle; 2701 } 2702 // call the function 2703 eError = fpGetHandle1(&pHandle); 2704 if(eError != OMX_ErrorNone) { 2705 eError = OMX_ErrorUndefined; 2706 OMXDBG_PRINT(stderr, ERROR, 4, 0, "eError != OMX_ErrorNone...\n"); 2707 pHandle = NULL; 2708 return pHandle; 2709 } 2710 2711 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate; 2712 return pHandle; 2713 } 2714 #endif 2715 2716 /* ================================================================================= */ 2717 /** 2718 * @fn NBAMRENC_SetPending() description for NBAMRENC_SetPending 2719 NBAMRENC_SetPending(). 2720 This component is called when a buffer is queued to the LCML 2721 * @param pComponent handle for this instance of the component 2722 * 2723 * @pre 2724 * 2725 * @post 2726 * 2727 * @return OMX_ERRORTYPE 2728 */ 2729 /* ================================================================================ */ 2730 void NBAMRENC_SetPending(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, 2731 OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) 2732 { 2733 OMX_U16 i; 2734 2735 if (eDir == OMX_DirInput) { 2736 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2737 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2738 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1; 2739 OMX_PRBUFFER2(pComponentPrivate->dbg, "****INPUT BUFFER %d IS PENDING Line %ld******\n",i,lineNumber); 2740 } 2741 } 2742 } 2743 else { 2744 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2745 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2746 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1; 2747 OMX_PRBUFFER2(pComponentPrivate->dbg, "****OUTPUT BUFFER %d IS PENDING Line %ld*****\n",i,lineNumber); 2748 } 2749 } 2750 } 2751 } 2752 /* ================================================================================= */ 2753 /** 2754 * @fn NBAMRENC_ClearPending() description for NBAMRENC_ClearPending 2755 NBAMRENC_ClearPending(). 2756 This component is called when a buffer is returned from the LCML 2757 * @param pComponent handle for this instance of the component 2758 * 2759 * @pre 2760 * 2761 * @post 2762 * 2763 * @return OMX_ERRORTYPE 2764 */ 2765 /* ================================================================================ */ 2766 void NBAMRENC_ClearPending(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, 2767 OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) 2768 { 2769 OMX_U16 i; 2770 2771 if (eDir == OMX_DirInput) { 2772 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2773 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2774 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0; 2775 OMX_PRBUFFER2(pComponentPrivate->dbg, "****INPUT BUFFER %d IS RECLAIMED Line %ld*****\n",i,lineNumber); 2776 } 2777 } 2778 } 2779 else { 2780 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2781 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2782 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0; 2783 OMX_PRBUFFER2(pComponentPrivate->dbg, "****OUTPUT BUFFER %d IS RECLAIMED Line %ld*****\n",i,lineNumber); 2784 } 2785 } 2786 } 2787 } 2788 /* ================================================================================= */ 2789 /** 2790 * @fn NBAMRENC_IsPending() description for NBAMRENC_IsPending 2791 NBAMRENC_IsPending(). 2792 This method returns the pending status to the buffer 2793 * @param pComponent handle for this instance of the component 2794 * 2795 * @pre 2796 * 2797 * @post 2798 * 2799 * @return OMX_ERRORTYPE 2800 */ 2801 /* ================================================================================ */ 2802 OMX_U32 NBAMRENC_IsPending(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, 2803 OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) 2804 { 2805 OMX_U16 i; 2806 2807 if (eDir == OMX_DirInput) { 2808 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2809 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) { 2810 return pComponentPrivate->pInputBufferList->bBufferPending[i]; 2811 } 2812 } 2813 } 2814 else { 2815 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2816 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBufHdr = %p\n",pBufHdr); 2817 OMX_PRBUFFER2(pComponentPrivate->dbg, "pOutputBufferList->pBufHdr[i] = %p\n",pComponentPrivate->pOutputBufferList->pBufHdr[i]); 2818 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) { 2819 OMX_PRBUFFER2(pComponentPrivate->dbg, "returning %lx\n",pComponentPrivate->pOutputBufferList->bBufferPending[i]); 2820 return pComponentPrivate->pOutputBufferList->bBufferPending[i]; 2821 } 2822 } 2823 } 2824 return -1; 2825 } 2826 /* ================================================================================= */ 2827 /** 2828 * @fn NBAMRENC_IsValid() description for NBAMRENC_IsValid 2829 NBAMRENC_IsValid(). 2830 This method checks to see if a buffer returned from the LCML is valid. 2831 * @param pComponent handle for this instance of the component 2832 * 2833 * @pre 2834 * 2835 * @post 2836 * 2837 * @return OMX_ERRORTYPE 2838 */ 2839 /* ================================================================================ */ 2840 OMX_U32 NBAMRENC_IsValid(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, 2841 OMX_U8 *pBuffer, OMX_DIRTYPE eDir) 2842 { 2843 OMX_U16 i; 2844 int found=0; 2845 2846 if (eDir == OMX_DirInput) { 2847 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) { 2848 if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) { 2849 found = 1; 2850 } 2851 } 2852 } 2853 else { 2854 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) { 2855 if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) { 2856 found = 1; 2857 } 2858 } 2859 } 2860 return found; 2861 } 2862 /* ========================================================================== */ 2863 /** 2864 * @NBAMRENC_FillLCMLInitParamsEx() This function is used by the component thread to 2865 * fill the all of its initialization parameters, buffer deatils etc 2866 * to LCML structure, 2867 * 2868 * @param pComponent handle for this instance of the component 2869 * @param plcml_Init pointer to LCML structure to be filled 2870 * 2871 * @pre 2872 * 2873 * @post 2874 * 2875 * @return none 2876 */ 2877 /* ========================================================================== */ 2878 OMX_ERRORTYPE NBAMRENC_FillLCMLInitParamsEx(OMX_HANDLETYPE pComponent) 2879 { 2880 OMX_ERRORTYPE eError = OMX_ErrorNone; 2881 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize; 2882 OMX_BUFFERHEADERTYPE *pTemp; 2883 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent; 2884 AMRENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate; 2885 NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL; 2886 OMX_U16 i; 2887 OMX_U32 size_lcml; 2888 OMX_PRINT1(pComponentPrivate->dbg, "%d :: NBAMRENC_FillLCMLInitParamsEx\n",__LINE__); 2889 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers; 2890 nIpBufSize = pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->nBufferSize; 2891 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers; 2892 nOpBufSize = pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]->nBufferSize; 2893 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: ------ Buffer Details -----------\n",__LINE__); 2894 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Input Buffer Count = %ld\n",__LINE__,nIpBuf); 2895 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Input Buffer Size = %ld\n",__LINE__,nIpBufSize); 2896 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Output Buffer Count = %ld\n",__LINE__,nOpBuf); 2897 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: Output Buffer Size = %ld\n",__LINE__,nOpBufSize); 2898 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__); 2899 /* Allocate memory for all input buffer headers.. 2900 * This memory pointer will be sent to LCML */ 2901 size_lcml = nIpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE); 2902 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE); 2903 2904 pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT] = pTemp_lcml; 2905 for (i=0; i<nIpBuf; i++) { 2906 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: INPUT--------- Inside Ip Loop\n",__LINE__); 2907 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i]; 2908 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2909 pTemp->nFilledLen = nIpBufSize; 2910 pTemp->nVersion.s.nVersionMajor = NBAMRENC_MAJOR_VER; 2911 pTemp->nVersion.s.nVersionMinor = NBAMRENC_MINOR_VER; 2912 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 2913 pTemp->nTickCount = NBAMRENC_NOT_USED; 2914 pTemp_lcml->buffer = pTemp; 2915 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer); 2916 pTemp_lcml->eDir = OMX_DirInput; 2917 2918 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, sizeof(NBAMRENC_ParamStruct), OMX_U8); 2919 pTemp_lcml->pBufferParam->usNbFrames=0; 2920 pTemp_lcml->pBufferParam->pParamElem=NULL; 2921 pTemp_lcml->pFrameParam=NULL; 2922 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ); 2923 2924 pTemp->nFlags = NBAMRENC_NORMAL_BUFFER; 2925 pTemp++; 2926 pTemp_lcml++; 2927 } 2928 2929 /* Allocate memory for all output buffer headers.. 2930 * This memory pointer will be sent to LCML */ 2931 size_lcml = nOpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE); 2932 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE); 2933 2934 pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT] = pTemp_lcml; 2935 for (i=0; i<nOpBuf; i++) { 2936 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OUTPUT--------- Inside Op Loop\n",__LINE__); 2937 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 2938 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2939 pTemp->nFilledLen = nOpBufSize; 2940 pTemp->nVersion.s.nVersionMajor = NBAMRENC_MAJOR_VER; 2941 pTemp->nVersion.s.nVersionMinor = NBAMRENC_MINOR_VER; 2942 pComponentPrivate->nVersion = pTemp->nVersion.nVersion; 2943 pTemp->pPlatformPrivate = pHandle->pComponentPrivate; 2944 pTemp->nTickCount = NBAMRENC_NOT_USED; 2945 pTemp_lcml->buffer = pTemp; 2946 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer); 2947 pTemp_lcml->eDir = OMX_DirOutput; 2948 2949 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, 2950 sizeof(NBAMRENC_ParamStruct), 2951 NBAMRENC_ParamStruct); 2952 pTemp_lcml->pBufferParam->usNbFrames=0; 2953 pTemp_lcml->pBufferParam->pParamElem=NULL; 2954 pTemp_lcml->pFrameParam=NULL; 2955 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ); 2956 2957 pTemp->nFlags = NBAMRENC_NORMAL_BUFFER; 2958 pTemp++; 2959 pTemp_lcml++; 2960 } 2961 2962 pComponentPrivate->bInitParamsInitialized = 1; 2963 EXIT: 2964 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_FillLCMLInitParamsEx\n",__LINE__); 2965 OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError); 2966 return eError; 2967 } 2968 2969 /** ======================================================================== 2970 * OMX_DmmMap () method is used to allocate the memory using DMM. 2971 * 2972 * @param ProcHandle - Component identification number 2973 * @param size - Buffer header address, that needs to be sent to codec 2974 * @param pArmPtr - Message used to send the buffer to codec 2975 * @param pDmmBuf - buffer id 2976 * 2977 * @retval OMX_ErrorNone - Success 2978 * OMX_ErrorHardware - Hardware Error 2979 ** ==========================================================================*/ 2980 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, 2981 int size, 2982 void* pArmPtr, 2983 DMM_BUFFER_OBJ* pDmmBuf, 2984 struct OMX_TI_Debug dbg) 2985 { 2986 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 2987 DSP_STATUS status; 2988 int nSizeReserved = 0; 2989 2990 if(pDmmBuf == NULL) 2991 { 2992 OMX_ERROR4 (dbg, "pBuf is NULL\n"); 2993 eError = OMX_ErrorBadParameter; 2994 goto EXIT; 2995 } 2996 2997 if(pArmPtr == NULL) 2998 { 2999 OMX_ERROR4 (dbg, "pBuf is NULL\n"); 3000 eError = OMX_ErrorBadParameter; 3001 goto EXIT; 3002 } 3003 if(ProcHandle == NULL) 3004 { 3005 OMX_ERROR4 (dbg, "pProcHandle is NULL\n"); 3006 eError = OMX_ErrorBadParameter; 3007 goto EXIT; 3008 } 3009 3010 /* Allocate */ 3011 pDmmBuf->pAllocated = pArmPtr; 3012 3013 /* Reserve */ 3014 nSizeReserved = ROUND_TO_PAGESIZE(size) + 2*DMM_PAGE_SIZE ; 3015 3016 3017 status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved)); 3018 3019 if(DSP_FAILED(status)) 3020 { 3021 OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status); 3022 eError = OMX_ErrorHardware; 3023 goto EXIT; 3024 } 3025 pDmmBuf->nSize = size; 3026 OMX_PRBUFFER2 (dbg, " DMM MAP Reserved: %p, size 0x%x (%d)\n", pDmmBuf->pReserved,nSizeReserved,nSizeReserved); 3027 3028 /* Map */ 3029 status = DSPProcessor_Map(ProcHandle, 3030 pDmmBuf->pAllocated,/* Arm addres of data to Map on DSP*/ 3031 size , /* size to Map on DSP*/ 3032 pDmmBuf->pReserved, /* reserved space */ 3033 &(pDmmBuf->pMapped), /* returned map pointer */ 3034 0); /* final param is reserved. set to zero. */ 3035 if(DSP_FAILED(status)) 3036 { 3037 OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x", (int)status); 3038 eError = OMX_ErrorHardware; 3039 goto EXIT; 3040 } 3041 OMX_PRBUFFER2 (dbg, "DMM Mapped: %p, size 0x%x (%d)\n",pDmmBuf->pMapped, size,size); 3042 3043 /* Issue an initial memory flush to ensure cache coherency */ 3044 status = DSPProcessor_FlushMemory(ProcHandle, pDmmBuf->pAllocated, size, 0); 3045 if(DSP_FAILED(status)) 3046 { 3047 OMX_ERROR4 (dbg, "Unable to flush mapped buffer: error 0x%x",(int)status); 3048 goto EXIT; 3049 } 3050 eError = OMX_ErrorNone; 3051 3052 EXIT: 3053 return eError; 3054 } 3055 3056 /** ======================================================================== 3057 * OMX_DmmUnMap () method is used to de-allocate the memory using DMM. 3058 * 3059 * @param ProcHandle - Component identification number 3060 * @param pMapPtr - Map address 3061 * @param pResPtr - reserve adress 3062 * 3063 * @retval OMX_ErrorNone - Success 3064 * OMX_ErrorHardware - Hardware Error 3065 ** ==========================================================================*/ 3066 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg) 3067 { 3068 DSP_STATUS status = DSP_SOK; 3069 OMX_ERRORTYPE eError = OMX_ErrorNone; 3070 if(pMapPtr == NULL) 3071 { 3072 OMX_ERROR4(dbg, "pMapPtr is NULL\n"); 3073 eError = OMX_ErrorBadParameter; 3074 goto EXIT; 3075 } 3076 if(pResPtr == NULL) 3077 { 3078 OMX_ERROR4(dbg, "pResPtr is NULL\n"); 3079 OMXDBG_PRINT(stderr, ERROR, 4, 0, "pResPtr is NULL\n"); 3080 eError = OMX_ErrorBadParameter; 3081 goto EXIT; 3082 } 3083 if(ProcHandle == NULL) 3084 { 3085 OMX_ERROR4 (dbg, "--ProcHandle is NULL\n"); 3086 eError = OMX_ErrorBadParameter; 3087 goto EXIT; 3088 } 3089 3090 status = DSPProcessor_UnMap(ProcHandle,pMapPtr); 3091 if(DSP_FAILED(status)) 3092 { 3093 OMX_ERROR4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x",(int)status); 3094 } 3095 3096 OMX_PRSTATE2 (dbg, "unreserving structure =0x%p\n",pResPtr); 3097 status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr); 3098 if(DSP_FAILED(status)) 3099 { 3100 OMX_ERROR4 (dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status); 3101 } 3102 3103 EXIT: 3104 return eError; 3105 } 3106 3107 3108 #ifdef RESOURCE_MANAGER_ENABLED 3109 void NBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData) 3110 { 3111 OMX_COMMANDTYPE Cmd = OMX_CommandStateSet; 3112 OMX_STATETYPE state = OMX_StateIdle; 3113 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent; 3114 AMRENC_COMPONENT_PRIVATE *pCompPrivate = NULL; 3115 3116 pCompPrivate = (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 3117 3118 if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) { 3119 if (pCompPrivate->curState == OMX_StateExecuting || 3120 pCompPrivate->curState == OMX_StatePause) { 3121 write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 3122 write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32)); 3123 3124 pCompPrivate->bPreempted = 1; 3125 } 3126 } 3127 else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){ 3128 pCompPrivate->cbInfo.EventHandler ( 3129 pHandle, pHandle->pApplicationPrivate, 3130 OMX_EventResourcesAcquired, 0,0, 3131 NULL); 3132 3133 } 3134 } 3135 #endif 3136 3137 void NBAMRENC_HandleUSNError (AMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg) 3138 { 3139 OMX_COMPONENTTYPE *pHandle = NULL; 3140 OMX_U8 pending_buffers = OMX_FALSE; 3141 OMX_U32 i; 3142 switch (arg) 3143 { 3144 case IUALG_WARN_CONCEALED: 3145 case IUALG_WARN_UNDERFLOW: 3146 case IUALG_WARN_OVERFLOW: 3147 case IUALG_WARN_ENDOFDATA: 3148 /* all of these are informative messages, Algo can recover, no need to notify the 3149 * IL Client at this stage of the implementation */ 3150 break; 3151 3152 case IUALG_WARN_PLAYCOMPLETED: 3153 { 3154 pHandle = pComponentPrivate->pHandle; 3155 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__); 3156 OMX_PRINT2(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED Received\n"); 3157 if(pComponentPrivate->LastOutbuf!=NULL){ 3158 pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS; 3159 } 3160 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3161 pComponentPrivate->pHandle->pApplicationPrivate, 3162 OMX_EventBufferFlag, 3163 (OMX_U32)NULL, 3164 OMX_BUFFERFLAG_EOS, 3165 NULL); 3166 } 3167 break; 3168 3169 #ifdef _ERROR_PROPAGATION__ 3170 case IUALG_ERR_BAD_HANDLE: 3171 case IUALG_ERR_DATA_CORRUPT: 3172 case IUALG_ERR_NOT_SUPPORTED: 3173 case IUALG_ERR_ARGUMENT: 3174 case IUALG_ERR_NOT_READY: 3175 case IUALG_ERR_GENERAL: 3176 { 3177 /* all of these are fatal messages, Algo can not recover 3178 * hence return an error */ 3179 pComponentPrivate->bIsInvalidState=OMX_TRUE; 3180 pComponentPrivate->curState = OMX_StateInvalid; 3181 pHandle = pComponentPrivate->pHandle; 3182 pComponentPrivate->cbInfo.EventHandler(pHandle, 3183 pHandle->pApplicationPrivate, 3184 OMX_EventError, 3185 OMX_ErrorInvalidState, 3186 OMX_TI_ErrorSevere, 3187 NULL); 3188 } 3189 break; 3190 #endif 3191 default: 3192 break; 3193 } 3194 } 3195 OMX_ERRORTYPE AddStateTransition(AMRENC_COMPONENT_PRIVATE *pComponentPrivate) { 3196 OMX_ERRORTYPE eError = OMX_ErrorNone; 3197 3198 if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) { 3199 return OMX_ErrorUndefined; 3200 } 3201 /* Increment state change request reference count */ 3202 pComponentPrivate->nPendingStateChangeRequests++; 3203 ALOGI("addstatetranstion: %ld @ %d", pComponentPrivate->nPendingStateChangeRequests, pComponentPrivate->curState); 3204 3205 if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) { 3206 return OMX_ErrorUndefined; 3207 } 3208 return eError; 3209 } 3210 3211 OMX_ERRORTYPE RemoveStateTransition(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BOOL bEnableSignal) { 3212 OMX_ERRORTYPE eError = OMX_ErrorNone; 3213 3214 /* Decrement state change request reference count*/ 3215 if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) { 3216 return OMX_ErrorUndefined; 3217 } 3218 pComponentPrivate->nPendingStateChangeRequests--; 3219 3220 ALOGI("removestatetransition: %ld @ %d", pComponentPrivate->nPendingStateChangeRequests, pComponentPrivate->curState); 3221 /* If there are no more pending requests, signal the thread waiting on this*/ 3222 if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) { 3223 pthread_cond_signal(&(pComponentPrivate->StateChangeCondition)); 3224 } 3225 if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) { 3226 return OMX_ErrorUndefined; 3227 } 3228 3229 return eError; 3230 } 3231 3232