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