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