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