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