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