OMX_AacEncoder.c revision b44cdb1b44b144d09e8ec950d1e8e4c280064056
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_AacEncoder.c 30* 31* This file implements OMX Component for AAC Encoder that 32* is fully compliant with the OMX Audio specification 1.5. 33* 34* @path $(CSLPATH)\ 35* 36* @rev 1.0 37*/ 38/* ---------------------------------------------------------------------------- 39*! 40*! Revision History 41*! =================================== 42*! 13-Enc-2005 mf: Initial Version. Change required per OMAPSWxxxxxxxxx 43*! to provide _________________. 44*! 45* ============================================================================= */ 46 47 48/* ------compilation control switches -------------------------*/ 49/**************************************************************** 50* INCLUDE FILES 51****************************************************************/ 52/* ----- system and platform files ----------------------------*/ 53#ifdef UNDER_CE 54#include <windows.h> 55#include <oaf_osal.h> 56#include <omx_core.h> 57#else 58#include <wchar.h> 59#include <unistd.h> 60#include <sys/time.h> 61#include <sys/types.h> 62#include <sys/ioctl.h> 63#include <sys/select.h> 64#include <errno.h> 65#include <pthread.h> 66#endif 67#include <string.h> 68#include <fcntl.h> 69#include <stdlib.h> 70#include <stdio.h> 71#include <dbapi.h> 72#include <dlfcn.h> 73 74/*-------program files ----------------------------------------*/ 75#include "LCML_DspCodec.h" 76 77#ifndef UNDER_CE 78#ifdef DSP_RENDERING_ON 79#include <AudioManagerAPI.h> 80#endif 81#endif 82#ifdef RESOURCE_MANAGER_ENABLED 83#include <ResourceManagerProxyAPI.h> 84#endif 85#include <OMX_Component.h> 86#include "OMX_AacEncoder.h" 87#define AAC_ENC_ROLE "audio_encoder.aac" 88#include "OMX_AacEnc_Utils.h" 89#include <TIDspOmx.h> 90 91/**************************************************************** 92* EXTERNAL REFERENCES NOTE : only use if not found in header file 93****************************************************************/ 94/*--------data declarations -----------------------------------*/ 95 96/*--------function prototypes ---------------------------------*/ 97 98/**************************************************************** 99* PUBLIC DECLARATIONS Defined here, used elsewhere 100****************************************************************/ 101/*--------data declarations -----------------------------------*/ 102 103/*--------function prototypes ---------------------------------*/ 104 105/**************************************************************** 106* PRIVATE DECLARATIONS Defined here, used only here 107****************************************************************/ 108/*--------data declarations -----------------------------------*/ 109 110/*--------function prototypes ---------------------------------*/ 111 112static OMX_ERRORTYPE SetCallbacks(OMX_HANDLETYPE hComp, OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData); 113static OMX_ERRORTYPE GetComponentVersion(OMX_HANDLETYPE hComp, OMX_STRING pComponentName, OMX_VERSIONTYPE* pComponentVersion, OMX_VERSIONTYPE* pSpecVersion, OMX_UUIDTYPE* pComponentUUID); 114static OMX_ERRORTYPE SendCommand(OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand, OMX_U32 nParam,OMX_PTR pCmdData); 115static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParamStruct); 116static OMX_ERRORTYPE SetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParamStruct); 117static OMX_ERRORTYPE GetConfig(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nConfigIndex, OMX_PTR pComponentConfigStructure); 118static OMX_ERRORTYPE SetConfig(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nConfigIndex, OMX_PTR pComponentConfigStructure); 119static OMX_ERRORTYPE EmptyThisBuffer(OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 120static OMX_ERRORTYPE FillThisBuffer(OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 121static OMX_ERRORTYPE GetState(OMX_HANDLETYPE hComp, OMX_STATETYPE* pState); 122static OMX_ERRORTYPE ComponentTunnelRequest(OMX_HANDLETYPE hComp, OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, OMX_U32 nTunneledPort, OMX_TUNNELSETUPTYPE* pTunnelSetup); 123static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle); 124static OMX_ERRORTYPE AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent, OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes); 125static OMX_ERRORTYPE FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 126static OMX_ERRORTYPE UseBuffer(OMX_IN OMX_HANDLETYPE hComponent, OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes, OMX_IN OMX_U8* pBuffer); 127static OMX_ERRORTYPE GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType); 128static OMX_ERRORTYPE ComponentRoleEnum( OMX_IN OMX_HANDLETYPE hComponent, 129 OMX_OUT OMX_U8 *cRole, 130 OMX_IN OMX_U32 nIndex); 131 132 133#ifdef DSP_RENDERING_ON 134 135/* interface with audio manager*/ 136#define FIFO1 "/dev/fifo.1" 137#define FIFO2 "/dev/fifo.2" 138 139int Aacenc_fdwrite, Aacenc_fdread; 140 141#ifndef UNDER_CE 142AM_COMMANDDATATYPE cmd_data; 143#endif 144 145#define PERMS 0666 146int errno; 147#endif 148 149/*-------------------------------------------------------------------*/ 150/** 151 * OMX_ComponentInit() Set the all the function pointers of component 152 * 153 * This method will update the component function pointer to the handle 154 * 155 * @param hComp handle for this instance of the component 156 * 157 * @retval OMX_NoError Success, ready to roll 158 * OMX_ErrorInsufficientResources If the malloc fails 159 **/ 160/*-------------------------------------------------------------------*/ 161OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp) 162{ 163 164 OMX_ERRORTYPE eError = OMX_ErrorNone; 165 OMX_CONF_CHECK_CMD(hComp,1,1); /* checking for NULL pointers */ 166 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL; 167 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_op = NULL; 168 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 169 OMX_AUDIO_PARAM_AACPROFILETYPE *aac_ip = NULL; 170 OMX_AUDIO_PARAM_AACPROFILETYPE *aac_op = NULL; 171 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 172 OMX_AUDIO_PARAM_PCMMODETYPE *aac_pcm_ip = NULL; 173 OMX_AUDIO_PARAM_PCMMODETYPE *aac_pcm_op = NULL; 174 int i; 175 176 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC : Entering OMX_ComponentInit\n", __LINE__); 177 178 /*Set the all component function pointer to the handle*/ 179 pHandle->SetCallbacks = SetCallbacks; 180 pHandle->GetComponentVersion = GetComponentVersion; 181 pHandle->SendCommand = SendCommand; 182 pHandle->GetParameter = GetParameter; 183 pHandle->GetExtensionIndex = GetExtensionIndex; 184 pHandle->SetParameter = SetParameter; 185 pHandle->GetConfig = GetConfig; 186 pHandle->SetConfig = SetConfig; 187 pHandle->GetState = GetState; 188 pHandle->EmptyThisBuffer = EmptyThisBuffer; 189 pHandle->FillThisBuffer = FillThisBuffer; 190 pHandle->ComponentTunnelRequest = ComponentTunnelRequest; 191 pHandle->ComponentDeInit = ComponentDeInit; 192 pHandle->AllocateBuffer = AllocateBuffer; 193 pHandle->FreeBuffer = FreeBuffer; 194 pHandle->UseBuffer = UseBuffer; 195 pHandle->ComponentRoleEnum = ComponentRoleEnum; 196 197 OMX_MALLOC_STRUCT(pHandle->pComponentPrivate, AACENC_COMPONENT_PRIVATE); 198 ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle; 199 OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: pComponentPrivate %p \n",pHandle->pComponentPrivate); 200 201 /* Initialize component data structures to default values */ 202 ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nPorts = 0x2; 203 ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->sPortParam.nStartPortNumber = 0x0; 204 205 206 /* ---------start of OMX_AUDIO_PARAM_AACPROFILETYPE --------- */ 207 208 OMX_MALLOC_STRUCT(aac_ip, OMX_AUDIO_PARAM_AACPROFILETYPE); 209 OMXDBG_PRINT(stderr, PRINT, 2, 0, "AACENC: aac_ip %p \n", aac_ip); 210 OMX_MALLOC_STRUCT(aac_op, OMX_AUDIO_PARAM_AACPROFILETYPE); 211 OMXDBG_PRINT(stderr, PRINT, 2, 0, "AACENC: aac_op %p \n",aac_op); 212 213 ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->aacParams[INPUT_PORT] = aac_ip; 214 ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->aacParams[OUTPUT_PORT] = aac_op; 215 216 aac_op->nSize = sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE); 217 aac_op->nChannels = 2; 218 aac_op->nSampleRate = 44100; 219 aac_op->eAACProfile = OMX_AUDIO_AACObjectLC; 220 aac_op->eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP2ADTS; /* For khronos only : should be MP4ADTS*/ 221 aac_op->nBitRate = 128000; 222 aac_op->eChannelMode = OMX_AUDIO_ChannelModeStereo; 223 aac_op->nPortIndex = 1; 224 aac_op->nFrameLength = 0; 225 aac_op->nAudioBandWidth = 0; 226 227 /* ---------end of MX_AUDIO_PARAM_AACPROFILETYPE --------- */ 228 229 230 /* ---------start of OMX_AUDIO_PARAM_PCMMODETYPE --------- */ 231 232 OMX_MALLOC_STRUCT(aac_pcm_ip, OMX_AUDIO_PARAM_PCMMODETYPE); 233 OMXDBG_PRINT(stderr, PRINT, 2, 0, "AACENC: aac_pcm_ip %p \n ",aac_pcm_ip); 234 OMX_MALLOC_STRUCT(aac_pcm_op, OMX_AUDIO_PARAM_PCMMODETYPE); 235 236 OMXDBG_PRINT(stderr, PRINT, 2, 0, "%d :: AACENC: %p\n",__LINE__,aac_pcm_op); 237 OMXDBG_PRINT(stderr, PRINT, 2, 0, "AACENC: aac_pcm_op%p \n ",aac_pcm_op); 238 239 aac_pcm_ip->nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); 240 aac_pcm_ip->nBitPerSample = 16; /*Will be remapped for SN. 16:2, 24:3*/ 241 aac_pcm_ip->nPortIndex = 0; 242 aac_pcm_ip->nChannels = 1; /*Will be remapped for SN. 0:mono, 1:stereo*/ 243 aac_pcm_ip->eNumData = OMX_NumericalDataSigned; 244 aac_pcm_ip->nSamplingRate = 8000; 245 aac_pcm_ip->ePCMMode = OMX_AUDIO_PCMModeLinear; 246 aac_pcm_ip->bInterleaved = OMX_TRUE; 247 248 ((AACENC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pcmParam[INPUT_PORT] = aac_pcm_ip; 249 ((AACENC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pcmParam[OUTPUT_PORT] = aac_pcm_op; 250 251 /* ---------end of OMX_AUDIO_PARAM_PCMMODETYPE --------- */ 252 253 254 pComponentPrivate = pHandle->pComponentPrivate; 255 OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_AACENC"); 256 257#ifdef ANDROID /* leave this now, we may need them later. */ 258 pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; 259 pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE; 260 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE; 261 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE; 262 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 263 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_TRUE; 264 pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; 265#endif 266 267#ifdef __PERF_INSTRUMENTATION__ 268 pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('A','A','E','_'), 269 PERF_ModuleLLMM | 270 PERF_ModuleAudioDecode); 271#endif 272 273 OMX_MALLOC_STRUCT(pComponentPrivate->pInputBufferList, BUFFERLIST); 274 275 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pInputBufferList %p\n ", pComponentPrivate->pInputBufferList); 276 pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */ 277 278 OMX_MALLOC_STRUCT(pComponentPrivate->pOutputBufferList, BUFFERLIST); 279 pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */ 280 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pOutputBufferList %p\n ", pComponentPrivate->pOutputBufferList); 281 282 for (i=0; i < MAX_NUM_OF_BUFS; i++) 283 { 284 pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL; 285 pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL; 286 pComponentPrivate->tickcountBufIndex[i] = 0; 287 pComponentPrivate->timestampBufIndex[i] = 0; 288 } 289 290 pComponentPrivate->IpBufindex = 0; 291 pComponentPrivate->OpBufindex = 0; 292 293 OMX_MALLOC_STRUCT_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), void); 294 295 /* Initialize device string to the default value */ 296 strcpy((char*)pComponentPrivate->sDeviceString,"/rtmdn:i2:o1/codec\0"); 297 298 /*Safety value for frames per output buffer ( for Khronos) */ 299 pComponentPrivate->FramesPer_OutputBuffer = 1; 300 pComponentPrivate->CustomConfiguration = OMX_FALSE; 301 302 pComponentPrivate->dasfmode = 0; 303 pComponentPrivate->unNumChannels = 2; 304 pComponentPrivate->ulSamplingRate = 44100; 305 pComponentPrivate->unBitrate = 128000; 306 pComponentPrivate->nObjectType = 2; 307 pComponentPrivate->bitRateMode = 0; 308 pComponentPrivate->File_Format = 2; 309 pComponentPrivate->EmptybufferdoneCount = 0; 310 pComponentPrivate->EmptythisbufferCount = 0; 311 pComponentPrivate->FillbufferdoneCount = 0; 312 pComponentPrivate->FillthisbufferCount = 0; 313 314 pComponentPrivate->bPortDefsAllocated = 0; 315 pComponentPrivate->bCompThreadStarted = 0; 316 pComponentPrivate->bPlayCompleteFlag = 0; 317 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->bPlayCompleteFlag = %ld\n",__LINE__,pComponentPrivate->bPlayCompleteFlag); 318 pComponentPrivate->strmAttr = NULL; 319 pComponentPrivate->pMarkBuf = NULL; 320 pComponentPrivate->pMarkData = NULL; 321 pComponentPrivate->pParams = NULL; 322 pComponentPrivate->ptAlgDynParams = NULL; 323 pComponentPrivate->LastOutputBufferHdrQueued = NULL; 324 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 325 pComponentPrivate->nOutStandingEmptyDones = 0; 326 pComponentPrivate->nOutStandingFillDones = 0; 327 pComponentPrivate->bPauseCommandPending = OMX_FALSE; 328 pComponentPrivate->bEnableCommandPending = 0; 329 pComponentPrivate->bDisableCommandPending = 0; 330 pComponentPrivate->nNumOutputBufPending = 0; 331 pComponentPrivate->bLoadedCommandPending = OMX_FALSE; 332 pComponentPrivate->bFirstOutputBuffer = 1; 333 334 pComponentPrivate->nUnhandledFillThisBuffers=0; 335 pComponentPrivate->nUnhandledEmptyThisBuffers = 0; 336 337 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE; 338 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE; 339 340 pComponentPrivate->nNumInputBufPending = 0; 341 pComponentPrivate->nNumOutputBufPending = 0; 342 343 pComponentPrivate->PendingInPausedBufs = 0; 344 pComponentPrivate->PendingOutPausedBufs = 0; 345 346 /* Port format type */ 347 pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingAAC; 348 pComponentPrivate->sOutPortFormat.nIndex = 0;/*OMX_IndexParamAudioAac;*/ 349 pComponentPrivate->sOutPortFormat.nPortIndex = OUTPUT_PORT; 350 351 pComponentPrivate->sInPortFormat.eEncoding = OMX_AUDIO_CodingPCM; 352 pComponentPrivate->sInPortFormat.nIndex = 1;/*OMX_IndexParamAudioPcm; */ 353 pComponentPrivate->sInPortFormat.nPortIndex = INPUT_PORT; 354 355 /*flags that control LCML closing*/ 356 pComponentPrivate->ptrLibLCML = NULL; 357 pComponentPrivate->bGotLCML = OMX_FALSE; 358 pComponentPrivate->bCodecDestroyed = OMX_FALSE; 359 360 361 /* initialize role name */ 362 strcpy((char *)pComponentPrivate->componentRole.cRole, "audio_encoder.aac"); 363 364#ifndef UNDER_CE 365 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL); 366 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL); 367 pComponentPrivate->AlloBuf_waitingsignal = 0; 368 369 pthread_mutex_init(&pComponentPrivate->codecStop_mutex, NULL); 370 pthread_cond_init (&pComponentPrivate->codecStop_threshold, NULL); 371 pComponentPrivate->codecStop_waitingsignal = 0; 372 373 pthread_mutex_init(&pComponentPrivate->codecFlush_mutex, NULL); 374 pthread_cond_init (&pComponentPrivate->codecFlush_threshold, NULL); 375 pComponentPrivate->codecFlush_waitingsignal = 0; 376 377 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL); 378 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL); 379 pComponentPrivate->InLoaded_readytoidle = 0; 380 381 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL); 382 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL); 383 pComponentPrivate->InIdle_goingtoloaded = 0; 384#else 385 OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event)); 386 pComponentPrivate->AlloBuf_waitingsignal = 0; 387 388 OMX_CreateEvent(&(pComponentPrivate->InLoaded_event)); 389 pComponentPrivate->InLoaded_readytoidle = 0; 390 391 OMX_CreateEvent(&(pComponentPrivate->InIdle_event)); 392 pComponentPrivate->InIdle_goingtoloaded = 0; 393#endif 394 395 /* port definition, input port */ 396 OMX_MALLOC_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE); 397 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pPortDef_ip %p \n",pPortDef_ip ); 398 399 400 /* port definition, output port */ 401 OMX_MALLOC_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE); 402 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pPortDef_op %p, size: %x \n",pPortDef_op, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 403 404 405 ((AACENC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[INPUT_PORT] = pPortDef_ip; 406 ((AACENC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[OUTPUT_PORT] = pPortDef_op; 407 408 409 pPortDef_ip->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 410 pPortDef_ip->nPortIndex = 0x0; 411 pPortDef_ip->nBufferCountActual = NUM_AACENC_INPUT_BUFFERS; 412 pPortDef_ip->nBufferCountMin = NUM_AACENC_INPUT_BUFFERS; 413 pPortDef_ip->eDir = OMX_DirInput; 414 pPortDef_ip->bEnabled = OMX_TRUE; 415 pPortDef_ip->nBufferSize = INPUT_AACENC_BUFFER_SIZE; 416 pPortDef_ip->nBufferAlignment = EXTRA_BYTES; 417 pPortDef_ip->bPopulated = 0; 418 pPortDef_ip->format.audio.eEncoding =OMX_AUDIO_CodingPCM; 419 pPortDef_ip->eDomain = OMX_PortDomainAudio; 420 421 pPortDef_op->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 422 pPortDef_op->nPortIndex = 0x1; 423 pPortDef_op->nBufferCountActual = NUM_AACENC_OUTPUT_BUFFERS; 424 pPortDef_op->nBufferCountMin = NUM_AACENC_OUTPUT_BUFFERS; 425 pPortDef_op->eDir = OMX_DirOutput; 426 pPortDef_op->bEnabled = OMX_TRUE; 427 pPortDef_op->nBufferSize = OUTPUT_AACENC_BUFFER_SIZE; 428 pPortDef_op->nBufferAlignment = EXTRA_BYTES; 429 pPortDef_op->bPopulated = 0; 430 pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingAAC; 431 pPortDef_op->eDomain = OMX_PortDomainAudio; 432 433 pComponentPrivate->bIsInvalidState = OMX_FALSE; 434 435 pComponentPrivate->bPreempted = OMX_FALSE; 436 437#ifdef RESOURCE_MANAGER_ENABLED 438 /* start Resource Manager Proxy */ 439 eError = RMProxy_NewInitalize(); 440 if (eError != OMX_ErrorNone) 441 { 442 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from loading ResourceManagerProxy thread\n",__LINE__); 443 goto EXIT; 444 } 445#endif 446#ifndef UNDER_CE 447#ifdef DSP_RENDERING_ON 448 449 /* start Audio Manager to get streamId */ 450 if((Aacenc_fdwrite=open(FIFO1,O_WRONLY))<0) 451 { 452 OMX_ERROR4(pComponentPrivate->dbg, "%d :: [AAC Encoder Component] - failure to open WRITE pipe\n",__LINE__); 453 } 454 455 if((Aacenc_fdread=open(FIFO2,O_RDONLY))<0) 456 { 457 OMX_ERROR4(pComponentPrivate->dbg, "%d :: [AAC Encoder Component] - failure to open READ pipe\n",__LINE__); 458 } 459#endif 460#endif 461 462 eError = AACENC_StartComponentThread(pHandle); 463 if (eError != OMX_ErrorNone) 464 { 465 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from the Component\n",__LINE__); 466 goto EXIT; 467 } 468 469 470#ifdef __PERF_INSTRUMENTATION__ 471 PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->ComponentThread, 472 PERF_FOURCC('A','A','E','T')); 473#endif 474 475EXIT: 476 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting OMX_ComponentInit\n", __LINE__); 477 return eError; 478} 479 480/*-------------------------------------------------------------------*/ 481/** 482 * SetCallbacks() Sets application callbacks to the component 483 * 484 * This method will update application callbacks 485 * to the component. So that component can make use of those call back 486 * while sending buffers to the application. And also it will copy the 487 * application private data to component memory 488 * 489 * @param pComponent handle for this instance of the component 490 * @param pCallBacks application callbacks 491 * @param pAppData Application private data 492 * 493 * @retval OMX_NoError Success, ready to roll 494 * OMX_Error_BadParameter The input parameter pointer is null 495 **/ 496/*-------------------------------------------------------------------*/ 497 498static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent, 499 OMX_CALLBACKTYPE* pCallBacks, 500 OMX_PTR pAppData) 501{ 502 OMX_ERRORTYPE eError = OMX_ErrorNone; 503 OMX_CONF_CHECK_CMD(pComponent,1,1); /* Checking for NULL pointers: pAppData is NULL for Khronos */ 504 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent; 505 506 AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 507 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering SetCallbacks\n", __LINE__); 508 if (pCallBacks == NULL) 509 { 510 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 511 eError = OMX_ErrorBadParameter; 512 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Received the empty callbacks from the application\n",__LINE__); 513 goto EXIT; 514 } 515 516 /*Copy the callbacks of the application to the component private*/ 517 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE)); 518 /*copy the application private data to component memory */ 519 pHandle->pApplicationPrivate = pAppData; 520 pComponentPrivate->curState = OMX_StateLoaded; 521 522EXIT: 523 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetCallbacks\n", __LINE__); 524 return eError; 525} 526 527/*-------------------------------------------------------------------*/ 528/** 529 * GetComponentVersion() This will return the component version 530 * 531 * This method will retrun the component version 532 * 533 * @param hComp handle for this instance of the component 534 * @param pCompnentName Name of the component 535 * @param pCompnentVersion handle for this instance of the component 536 * @param pSpecVersion application callbacks 537 * @param pCompnentUUID 538 * 539 * @retval OMX_NoError Success, ready to roll 540 * OMX_Error_BadParameter The input parameter pointer is null 541 **/ 542/*-------------------------------------------------------------------*/ 543 544static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 545 OMX_STRING pComponentName, 546 OMX_VERSIONTYPE* pComponentVersion, 547 OMX_VERSIONTYPE* pSpecVersion, 548 OMX_UUIDTYPE* pComponentUUID) 549{ 550 OMX_ERRORTYPE eError = OMX_ErrorNone; 551 552 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 553 AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 554 555 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering GetComponentVersion\n", __LINE__); 556 557#ifdef _ERROR_PROPAGATION__ 558 if (pComponentPrivate->curState == OMX_StateInvalid) 559 { 560 eError = OMX_ErrorInvalidState; 561 goto EXIT; 562 } 563#endif 564 565 /* Copy component version structure */ 566 if(pComponentVersion != NULL && pComponentName != NULL) 567 { 568 strcpy(pComponentName, pComponentPrivate->cComponentName); 569 memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), sizeof(pComponentPrivate->ComponentVersion.s)); 570 } 571 else 572 { 573 eError = OMX_ErrorBadParameter; 574 } 575 576EXIT: 577 578 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting GetComponentVersion\n", __LINE__); 579 return eError; 580} 581/*-------------------------------------------------------------------*/ 582/** 583 * SendCommand() used to send the commands to the component 584 * 585 * This method will be used by the application. 586 * 587 * @param phandle handle for this instance of the component 588 * @param Cmd Command to be sent to the component 589 * @param nParam indicates commmad is sent using this method 590 * 591 * @retval OMX_NoError Success, ready to roll 592 * OMX_Error_BadParameter The input parameter pointer is null 593 **/ 594/*-------------------------------------------------------------------*/ 595 596static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle, 597 OMX_COMMANDTYPE Cmd, 598 OMX_U32 nParam,OMX_PTR pCmdData) 599{ 600 OMX_ERRORTYPE eError = OMX_ErrorNone; 601 OMX_CONF_CHECK_CMD(phandle,1,1); /*NOTE: Cmd, pCmdData, nParam are NULL for khronos*/ 602 int nRet = 0; 603 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle; 604 AACENC_COMPONENT_PRIVATE *pCompPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 605 606#ifdef _ERROR_PROPAGATION__ 607 if (pCompPrivate->curState == OMX_StateInvalid) 608 { 609 eError = OMX_ErrorInvalidState; 610 goto EXIT; 611 } 612#else 613 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Entering SendCommand()\n", __LINE__); 614 if(pCompPrivate->curState == OMX_StateInvalid) 615 { 616 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__); 617 eError = OMX_ErrorInvalidState; 618 OMX_ERROR4(pCompPrivate->dbg, "%d :: Error Notofication Sent to App\n",__LINE__); 619 pCompPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 620 OMX_EventError, 621 OMX_ErrorInvalidState, 622 OMX_TI_ErrorMinor, 623 "Invalid State"); 624 goto EXIT; 625 } 626#endif 627 628#ifdef __PERF_INSTRUMENTATION__ 629 PERF_SendingCommand(pCompPrivate->pPERF,Cmd, 630 (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam, 631 PERF_ModuleComponent); 632#endif 633 634 switch(Cmd) 635 { 636 case OMX_CommandStateSet: 637 if (nParam == OMX_StateLoaded) 638 { 639 pCompPrivate->bLoadedCommandPending = OMX_TRUE; 640 } 641 642 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__); 643 OMX_PRSTATE1(pCompPrivate->dbg, "%d :: AACENC: pCompPrivate->curState = %d\n",__LINE__,pCompPrivate->curState); 644 if(pCompPrivate->curState == OMX_StateLoaded) 645 { 646 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) 647 { 648 pCompPrivate->cbInfo.EventHandler(pHandle, 649 pHandle->pApplicationPrivate, 650 OMX_EventError, 651 OMX_ErrorIncorrectStateTransition, 652 OMX_TI_ErrorMinor, 653 NULL); 654 goto EXIT; 655 } 656 657 if(nParam == OMX_StateInvalid) 658 { 659 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__); 660 OMX_PRSTATE2(pCompPrivate->dbg, "AACENC: State changed to OMX_StateInvalid Line %d\n",__LINE__); 661 pCompPrivate->curState = OMX_StateInvalid; 662 pCompPrivate->cbInfo.EventHandler(pHandle, 663 pHandle->pApplicationPrivate, 664 OMX_EventError, 665 OMX_ErrorInvalidState, 666 OMX_TI_ErrorMinor, 667 NULL); 668 goto EXIT; 669 } 670 } 671 break; 672 673 case OMX_CommandFlush: 674 OMX_PRINT1(pCompPrivate->dbg, "%d :: IAACENC: nside SendCommand\n",__LINE__); 675 if(nParam > 1 && nParam != -1) 676 { 677 eError = OMX_ErrorBadPortIndex; 678 goto EXIT; 679 } 680 break; 681 682 case OMX_CommandPortDisable: 683 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandPortDisable\n",__LINE__); 684 break; 685 686 case OMX_CommandPortEnable: 687 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandPortEnable\n",__LINE__); 688 break; 689 690 case OMX_CommandMarkBuffer: 691 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandMarkBuffer\n",__LINE__); 692 if (nParam > 0) 693 { 694 eError = OMX_ErrorBadPortIndex; 695 goto EXIT; 696 } 697 break; 698 699 default: 700 OMX_ERROR4(pCompPrivate->dbg, "%d :: Error: Command Received Default error\n",__LINE__); 701 pCompPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 702 OMX_EventError, 703 OMX_ErrorBadParameter, 704 OMX_TI_ErrorMinor, 705 "Invalid Command"); 706 break; 707 708 } 709 710 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__); 711 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 712 OMX_PRCOMM2(pCompPrivate->dbg, "%d :: AACENC: Cmd pipe has been writen. nRet = %d \n",__LINE__,nRet); 713 OMX_PRCOMM2(pCompPrivate->dbg, "%d :: AACENC: pCompPrivate->cmdPipe[1] = %d \n",__LINE__,pCompPrivate->cmdPipe[1]); 714 OMX_PRCOMM2(pCompPrivate->dbg, "%d :: AACENC: &Cmd = %p \n",__LINE__,&Cmd); 715 716 if (nRet == -1) 717 { 718 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__); 719 eError = OMX_ErrorInsufficientResources; 720 goto EXIT; 721 } 722 723 if (Cmd == OMX_CommandMarkBuffer) 724 { 725 nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR)); 726 } 727 else 728 { 729 nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32)); 730 } 731 732 if (nRet == -1) 733 { 734 eError = OMX_ErrorInsufficientResources; 735 goto EXIT; 736 } 737 738EXIT: 739 OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Exiting SendCommand()\n", __LINE__); 740 return eError; 741} 742/*-------------------------------------------------------------------*/ 743/** 744 * GetParameter() Gets the current configurations of the component 745 * 746 * @param hComp handle for this instance of the component 747 * @param nParamIndex 748 * @param ComponentParameterStructure 749 * 750 * @retval OMX_NoError Success, ready to roll 751 * OMX_Error_BadParameter The input parameter pointer is null 752 **/ 753/*-------------------------------------------------------------------*/ 754 755static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure) 756{ 757 OMX_ERRORTYPE eError = OMX_ErrorNone; 758 OMX_CONF_CHECK_CMD(hComp,1,1); 759 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 760 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL; 761 762 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering GetParameter\n", __LINE__); 763 OMXDBG_PRINT(stderr, PRINT, 2, 0, "%d :: AACENC: Inside the GetParameter nParamIndex = %x\n",__LINE__, nParamIndex); 764 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 765 766 pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure; 767 if (pParameterStructure == NULL) 768 { 769 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorBadParameter Inside the GetParameter Line\n",__LINE__); 770 eError = OMX_ErrorBadParameter; 771 goto EXIT; 772 773 } 774 775#ifdef _ERROR_PROPAGATION__ 776 if (pComponentPrivate->curState == OMX_StateInvalid) 777 { 778 eError = OMX_ErrorInvalidState; 779 goto EXIT; 780 } 781#else 782 if(pComponentPrivate->curState == OMX_StateInvalid) 783 { 784 pComponentPrivate->cbInfo.EventHandler(hComp, 785 ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate, 786 OMX_EventError, 787 OMX_ErrorIncorrectStateOperation, 788 OMX_TI_ErrorMinor, 789 "Invalid State"); 790 OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Inside the GetParameter Line\n",__LINE__); 791 } 792#endif 793 switch(nParamIndex) 794 { 795 796 case OMX_IndexParamAudioInit: 797 memcpy(ComponentParameterStructure, &pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE)); 798 break; 799 800 case OMX_IndexParamPortDefinition: 801 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 802 { 803 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Inside the GetParameter Line\n",__LINE__); 804 memcpy(ComponentParameterStructure,pComponentPrivate->pPortDef[INPUT_PORT], sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 805 } 806 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 807 { 808 memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[OUTPUT_PORT], sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 809 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Inside the GetParameter \n",__LINE__); 810 } 811 else 812 { 813 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: BadPortIndex Inside the GetParameter \n",__LINE__); 814 eError = OMX_ErrorBadPortIndex; 815 } 816 break; 817 818 case OMX_IndexParamAudioPortFormat: 819 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 820 { 821 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > pComponentPrivate->sInPortFormat.nIndex) 822 { 823 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: ErrorNoMore Inside the GetParameter Line\n",__LINE__); 824 eError = OMX_ErrorNoMore; 825 } 826 else 827 { 828 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: About to copy Inside GetParameter \n",__LINE__); 829 memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 830 } 831 } 832 else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 833 { 834 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > pComponentPrivate->sOutPortFormat.nIndex) 835 { 836 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: ErrorNoMore Inside the GetParameter Line\n",__LINE__); 837 eError = OMX_ErrorNoMore; 838 } 839 else 840 { 841 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: About to copy Inside GetParameter \n",__LINE__); 842 memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 843 } 844 } 845 else 846 { 847 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: BadPortIndex Inside the GetParameter Line\n",__LINE__); 848 eError = OMX_ErrorBadPortIndex; 849 } 850 break; 851 852 case OMX_IndexParamAudioAac: 853 OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioAac : nPortIndex = %d\n", (int)((OMX_AUDIO_PARAM_AACPROFILETYPE *)(ComponentParameterStructure))->nPortIndex); 854 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: acParams[INPUT_PORT]->nPortIndex = %d\n", (int)pComponentPrivate->aacParams[INPUT_PORT]->nPortIndex); 855 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: acParams[OUPUT_PORT]->nPortIndex = %d\n", (int)pComponentPrivate->aacParams[OUTPUT_PORT]->nPortIndex); 856 857 if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->aacParams[INPUT_PORT]->nPortIndex) 858 { 859 860 if (pComponentPrivate->CustomConfiguration ) /* For Testapp: An Index was providded. Getting the required Structure */ 861 /* The flag is set in Setconfig() function*/ 862 { 863 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioAac :input port \n"); 864 memcpy(ComponentParameterStructure,pComponentPrivate->aacParams[INPUT_PORT], sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)); 865 866 } 867 else /*for Khronos: Getting the default structure (Ouput) for an index not providded*/ 868 { 869 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioAac :output port \n"); 870 memcpy(ComponentParameterStructure, pComponentPrivate->aacParams[OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)); 871 } 872 } 873 else if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->aacParams[OUTPUT_PORT]->nPortIndex) 874 { 875 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioAac :output port \n"); 876 memcpy(ComponentParameterStructure, pComponentPrivate->aacParams[OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)); 877 878 } 879 else 880 { 881 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: BadPortIndex Inside the GetParameter Line\n",__LINE__); 882 eError = OMX_ErrorBadPortIndex; 883 } 884 break; 885 886 887 case OMX_IndexParamAudioPcm: 888 if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pcmParam[INPUT_PORT]->nPortIndex) 889 { 890 memcpy(ComponentParameterStructure,pComponentPrivate->pcmParam[INPUT_PORT], sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 891 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioPcm :input port \n"); 892 } 893 else if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pcmParam[OUTPUT_PORT]->nPortIndex) 894 { 895 memcpy(ComponentParameterStructure, pComponentPrivate->pcmParam[OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 896 OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: OMX_IndexParamAudioPcm :output port \n"); 897 } 898 else 899 { 900 eError = OMX_ErrorBadPortIndex; 901 } 902 break; 903 904 case OMX_IndexParamCompBufferSupplier: 905 if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) 906 { 907 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: GetParameter OMX_IndexParamCompBufferSupplier \n"); 908 909 } 910 else if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) 911 { 912 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: GetParameter OMX_IndexParamCompBufferSupplier \n"); 913 } 914 else 915 { 916 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorBadPortIndex from GetParameter",__LINE__); 917 eError = OMX_ErrorBadPortIndex; 918 } 919 920 break; 921 922#ifdef ANDROID 923 case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX: 924 { 925 OMX_PRDSP2(pComponentPrivate->dbg, "Entering PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX::%d\n", __LINE__); 926 PV_OMXComponentCapabilityFlagsType* pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure; 927 if (NULL == pCap_flags) 928 { 929 OMX_ERROR4(pComponentPrivate->dbg, "%d :: ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__); 930 eError = OMX_ErrorBadParameter; 931 goto EXIT; 932 } 933 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n", __LINE__); 934 memcpy(pCap_flags, &(pComponentPrivate->iPVCapabilityFlags), sizeof(PV_OMXComponentCapabilityFlagsType)); 935 eError = OMX_ErrorNone; 936 } 937 break; 938#endif 939 940 941 case OMX_IndexParamPriorityMgmt: 942 break; 943 944 945 case OMX_IndexParamVideoInit: 946 break; 947 948 case OMX_IndexParamImageInit: 949 break; 950 951 case OMX_IndexParamOtherInit: 952 break; 953 954 default: 955 eError = OMX_ErrorUnsupportedIndex; 956 break; 957 } 958EXIT: 959 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting GetParameter:: %x error :: %x \n",__LINE__,nParamIndex,eError); 960 return eError; 961} 962 963/*-------------------------------------------------------------------*/ 964/** 965 * SetParameter() Sets configuration paramets to the component 966 * 967 * @param hComp handle for this instance of the component 968 * @param nParamIndex 969 * @param pCompParam 970 * 971 * @retval OMX_NoError Success, ready to roll 972 * OMX_Error_BadParameter The input parameter pointer is null 973 **/ 974/*-------------------------------------------------------------------*/ 975 976static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR pCompParam) 977{ 978 OMX_ERRORTYPE eError = OMX_ErrorNone; 979 OMX_CONF_CHECK_CMD(hComp,1,1); 980 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 981 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 982 OMX_PARAM_COMPONENTROLETYPE *pRole = NULL; 983 OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier; 984 985 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering the SetParameter()\n",__LINE__); 986 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: Inside the SetParameter nParamIndex = %x\n",__LINE__, nParamIndex); 987 988 if (pCompParam == NULL) 989 { 990 eError = OMX_ErrorBadParameter; 991 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter \n",__LINE__); 992 goto EXIT; 993 } 994 995#ifdef _ERROR_PROPAGATION__ 996 if (pComponentPrivate->curState == OMX_StateInvalid) 997 { 998 eError = OMX_ErrorInvalidState; 999 goto EXIT; 1000 } 1001#endif 1002 1003 switch(nParamIndex) 1004 { 1005 case OMX_IndexParamAudioPortFormat: 1006 { 1007 OMX_AUDIO_PARAM_PORTFORMATTYPE *pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam; 1008 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: pCompParam = index %d\n",__LINE__,(int)pComponentParam->nIndex); 1009 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pCompParam = nportindex %d\n",__LINE__,(int)pComponentParam->nPortIndex); 1010 /* for input port */ 1011 if (pComponentParam->nPortIndex == 0) 1012 { 1013 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: OMX_IndexParamAudioPortFormat - index 0 \n",__LINE__); 1014 1015 } 1016 else if (pComponentParam->nPortIndex == 1) 1017 { 1018 OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: OMX_IndexParamAudioPortFormat - index 1 \n",__LINE__); 1019 } 1020 else 1021 { 1022 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Wrong Port Index Parameter\n", __LINE__); 1023 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 1024 eError = OMX_ErrorBadParameter; 1025 goto EXIT; 1026 } 1027 break; 1028 } 1029 1030 case OMX_IndexParamAudioAac: 1031 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AACENC: Inside the SetParameter - OMX_IndexParamAudioAac\n", __LINE__); 1032 if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(pCompParam))->nPortIndex == 1033 pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 1034 { 1035 memcpy(pComponentPrivate->aacParams[OUTPUT_PORT], pCompParam, 1036 sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)); 1037 OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: nSampleRate %ld\n",pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate); 1038 1039 /* check support stereo record support at DASF */ 1040 if(pComponentPrivate->aacParams[OUTPUT_PORT]->nChannels ==2) 1041 { 1042#ifndef UNDER_CE 1043#ifdef DSP_RENDERING_ON 1044 1045 /* inform Audio Manager support DASF stereo record */ 1046 cmd_data.hComponent = hComp; 1047 cmd_data.AM_Cmd = AM_CommandMixerStereoRecordSupport; 1048 cmd_data.param1 = OMX_TRUE; 1049 if((write(Aacenc_fdwrite, &cmd_data, sizeof(cmd_data)))<0) 1050 { 1051 OMX_PRCOMM2(pComponentPrivate->dbg, "[AAC Enc Component] - send command to audio manager\n"); 1052 } 1053#endif 1054#endif 1055 } 1056 } 1057 else if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(pCompParam))->nPortIndex == 1058 pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 1059 { 1060 memcpy(pComponentPrivate->aacParams[INPUT_PORT], pCompParam, 1061 sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE)); 1062 } 1063 else 1064 { 1065 eError = OMX_ErrorBadPortIndex; 1066 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in SetParameter - OMX_IndexParamAudioAac = %x\n", __LINE__, eError); 1067 } 1068 break; 1069 1070 case OMX_IndexParamAudioPcm: 1071 if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(pCompParam))->nPortIndex == 1072 pComponentPrivate->pcmParam[INPUT_PORT]->nPortIndex) 1073 { 1074 memcpy(pComponentPrivate->pcmParam[INPUT_PORT],pCompParam, 1075 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE) 1076 ); 1077 } 1078 else if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(pCompParam))->nPortIndex == 1079 pComponentPrivate->pcmParam[OUTPUT_PORT]->nPortIndex) 1080 { 1081 memcpy(pComponentPrivate->pcmParam[OUTPUT_PORT],pCompParam, 1082 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE) 1083 ); 1084 1085 } 1086 else 1087 { 1088 eError = OMX_ErrorBadPortIndex; 1089 } 1090 break; 1091 1092 case OMX_IndexParamPortDefinition: 1093 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 1094 { 1095 memcpy(pComponentPrivate->pPortDef[INPUT_PORT], pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 1096 } 1097 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 1098 { 1099 memcpy(pComponentPrivate->pPortDef[OUTPUT_PORT], pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 1100 1101 } 1102 else 1103 { 1104 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Wrong Port Index Parameter\n", __LINE__); 1105 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 1106 eError = OMX_ErrorBadPortIndex; 1107 goto EXIT; 1108 } 1109 break; 1110 1111 case OMX_IndexParamPriorityMgmt: 1112 if (pComponentPrivate->curState != OMX_StateLoaded) 1113 { 1114 eError = OMX_ErrorIncorrectStateOperation; 1115 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1116 } 1117 break; 1118 1119 case OMX_IndexParamStandardComponentRole: 1120 if (pCompParam) 1121 { 1122 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam; 1123 memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 1124 } 1125 else 1126 { 1127 eError = OMX_ErrorBadParameter; 1128 } 1129 break; 1130 1131 1132 case OMX_IndexParamCompBufferSupplier: 1133 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1134 pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 1135 { 1136 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: SetParameter OMX_IndexParamCompBufferSupplier \n"); 1137 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput; 1138 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1139 1140 } 1141 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1142 pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 1143 { 1144 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: SetParameter OMX_IndexParamCompBufferSupplier \n"); 1145 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput; 1146 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1147 } 1148 else 1149 { 1150 OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: OMX_ErrorBadPortIndex from SetParameter",__LINE__); 1151 eError = OMX_ErrorBadPortIndex; 1152 } 1153 break; 1154 1155 1156 1157 1158 default: 1159 break; 1160 } 1161EXIT: 1162 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetParameter:: %x\n",__LINE__,nParamIndex); 1163 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting the SetParameter() returned eError = %d\n",__LINE__, eError); 1164 return eError; 1165} 1166/*-------------------------------------------------------------------*/ 1167/** 1168 * GetConfig() Gets the current configuration of to the component 1169 * 1170 * @param hComp handle for this instance of the component 1171 * @param nConfigIndex 1172 * @param ComponentConfigStructure 1173 * 1174 * @retval OMX_NoError Success, ready to roll 1175 * OMX_Error_BadParameter The input parameter pointer is null 1176 **/ 1177/*-------------------------------------------------------------------*/ 1178 1179static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nConfigIndex, OMX_PTR ComponentConfigStructure) 1180{ 1181 OMX_ERRORTYPE eError = OMX_ErrorNone; 1182 1183 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1184 TI_OMX_STREAM_INFO *streamInfo = NULL; 1185 1186 OMX_MALLOC_STRUCT_SIZE(streamInfo, sizeof(TI_OMX_STREAM_INFO), void); 1187 OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: streamInfo %p \n",streamInfo); 1188 1189 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *) 1190 (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 1191 1192#ifdef _ERROR_PROPAGATION__ 1193 if (pComponentPrivate->curState == OMX_StateInvalid) 1194 { 1195 eError = OMX_ErrorInvalidState; 1196 goto EXIT; 1197 } 1198#endif 1199 1200 if(nConfigIndex == OMX_IndexCustomAacEncStreamIDConfig) 1201 { 1202 /* copy component info */ 1203 streamInfo->streamId = pComponentPrivate->streamID; 1204 memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO)); 1205 } 1206 else if(nConfigIndex == OMX_IndexCustomDebug) 1207 { 1208 OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure); 1209 } 1210 1211 if(streamInfo) 1212 { 1213 OMX_MEMFREE_STRUCT(streamInfo); 1214 streamInfo = NULL; 1215 } 1216 1217EXIT: return eError; 1218} 1219/*-------------------------------------------------------------------*/ 1220/** 1221 * SetConfig() Sets the configuration of the component 1222 * 1223 * @param hComp handle for this instance of the component 1224 * @param nConfigIndex 1225 * @param ComponentConfigStructure 1226 * 1227 * @retval OMX_NoError Success, ready to roll 1228 * OMX_Error_BadParameter The input parameter pointer is null 1229 **/ 1230/*-------------------------------------------------------------------*/ 1231 1232static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nConfigIndex, OMX_PTR ComponentConfigStructure) 1233{ 1234 OMX_ERRORTYPE eError = OMX_ErrorNone; 1235 /* OMX_CONF_CHECK_CMD(hComp,1,ComponentConfigStructure);*/ 1236 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp; 1237 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1238 TI_OMX_DSP_DEFINITION* pDspDefinition = NULL; 1239 OMX_U16 FramesPerOutBuf =0 ; 1240 OMX_U16* ptrFramesPerOutBuf =NULL ; 1241 TI_OMX_DATAPATH dataPath; 1242 OMX_S16 *customFlag = NULL; 1243 1244 1245#ifdef DSP_RENDERING_ON 1246 OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL; 1247#endif 1248 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering SetConfig\n", __LINE__); 1249 if (pHandle == NULL) 1250 { 1251 OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: AACENC: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__); 1252 eError = OMX_ErrorBadParameter; 1253 goto EXIT; 1254 } 1255 1256 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1257 1258#ifdef _ERROR_PROPAGATION__ 1259 if (pComponentPrivate->curState == OMX_StateInvalid) 1260 { 1261 eError = OMX_ErrorInvalidState; 1262 goto EXIT; 1263 } 1264#endif 1265 1266 switch (nConfigIndex) 1267 { 1268 case OMX_IndexCustomAacEncHeaderInfoConfig: 1269 { 1270 pDspDefinition = (TI_OMX_DSP_DEFINITION *)ComponentConfigStructure; 1271 if (pDspDefinition == NULL) 1272 { 1273 eError = OMX_ErrorBadParameter; 1274 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorBadParameter from SetConfig\n",__LINE__); 1275 goto EXIT; 1276 } 1277 pComponentPrivate->dasfmode = pDspDefinition->dasfMode; 1278 OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->dasfmode = %d\n",(int)pComponentPrivate->dasfmode); 1279 pComponentPrivate->bitRateMode = pDspDefinition->aacencHeaderInfo->bitratemode; 1280 OMX_PRINT2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->bitRateMode = %d\n",(int)pComponentPrivate->bitRateMode); 1281 pComponentPrivate->streamID = pDspDefinition->streamId; 1282 break; 1283 } 1284 1285 case OMX_IndexCustomAacEncFramesPerOutBuf: 1286 { 1287 ptrFramesPerOutBuf = (OMX_U16*)ComponentConfigStructure; 1288 if (ptrFramesPerOutBuf == NULL) 1289 { 1290 eError = OMX_ErrorBadParameter; 1291 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorBadParameter from SetConfig\n",__LINE__); 1292 1293 } 1294 FramesPerOutBuf = *ptrFramesPerOutBuf; 1295 pComponentPrivate->FramesPer_OutputBuffer= FramesPerOutBuf; 1296 OMX_PRINT1(pComponentPrivate->dbg, "AACENC: pComponentPrivate->FramesPer_OutputBuffer = %d \n",pComponentPrivate->FramesPer_OutputBuffer); 1297 1298 1299 pComponentPrivate->CustomConfiguration = OMX_TRUE; /* Flag specific to test app */ 1300 break; 1301 } 1302 1303 case OMX_IndexConfigAudioVolume: 1304#ifdef DSP_RENDERING_ON 1305 pGainStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure; 1306 cmd_data.hComponent = hComp; 1307 cmd_data.AM_Cmd = AM_CommandSWGain; 1308 cmd_data.param1 = pGainStructure->sVolume.nValue; 1309 cmd_data.param2 = 0; 1310 cmd_data.streamID = pComponentPrivate->streamID; 1311 1312 if((write(Aacenc_fdwrite, &cmd_data, sizeof(cmd_data)))<0) 1313 { 1314 OMX_ERROR4(pComponentPrivate->dbg, "[AAC encoder] - fail to send command to audio manager\n"); 1315 OMX_PRINT2(pComponentPrivate->dbg, "[AAC encoder] - fail to send command to audio manager\n"); 1316 } 1317 else 1318 { 1319 OMX_PRMGR2(pComponentPrivate->dbg, "[AAC encoder] - ok to send command to audio manager\n"); 1320 } 1321#endif 1322 break; 1323 1324 case OMX_IndexCustomAacEncDataPath: 1325 customFlag = (OMX_S16*)ComponentConfigStructure; 1326 if (customFlag == NULL) 1327 { 1328 eError = OMX_ErrorBadParameter; 1329 goto EXIT; 1330 } 1331/* 1332 dataPath = *customFlag; 1333*/ 1334 switch(dataPath) 1335 { 1336 case DATAPATH_APPLICATION: 1337 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_ENCODER, pComponentPrivate->streamID); 1338 break; 1339 1340 case DATAPATH_APPLICATION_RTMIXER: 1341 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING_ENCODER); 1342 break; 1343 1344 default: 1345 break; 1346 1347 } 1348 break; 1349 case OMX_IndexCustomDebug: 1350 OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure); 1351 break; 1352 1353 default: 1354/* eError = OMX_ErrorUnsupportedIndex; */ 1355 break; 1356 } 1357EXIT: 1358 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetConfig\n", __LINE__); 1359 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning = 0x%x\n",__LINE__,eError); 1360 return eError; 1361 1362 1363} 1364/*-------------------------------------------------------------------*/ 1365/** 1366 * GetState() Gets the current state of the component 1367 * 1368 * @param pCompomponent handle for this instance of the component 1369 * @param pState 1370 * 1371 * @retval OMX_NoError Success, ready to roll 1372 * OMX_Error_BadParameter The input parameter pointer is null 1373 **/ 1374/*-------------------------------------------------------------------*/ 1375 1376static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState) 1377{ 1378 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 1379 OMX_CONF_CHECK_CMD(pComponent,1,1); 1380 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1381 1382 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering GetState\n", __LINE__); 1383 if (!pState) 1384 { 1385 eError = OMX_ErrorBadParameter; 1386 OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Error: About to return OMX_ErrorBadParameter \n",__LINE__); 1387 goto EXIT; 1388 } 1389 1390 if (pHandle && pHandle->pComponentPrivate) 1391 { 1392 *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState; 1393 } 1394 else 1395 { 1396 *pState = OMX_StateLoaded; 1397 } 1398 eError = OMX_ErrorNone; 1399 1400EXIT: 1401 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Exiting GetState\n", __LINE__); 1402 return eError; 1403} 1404 1405/*-------------------------------------------------------------------*/ 1406/** 1407 * EmptyThisBuffer() This callback is used to send the input buffer to 1408 * component 1409 * 1410 * @param pComponent handle for this instance of the component 1411 * @param nPortIndex input port index 1412 * @param pBuffer buffer to be sent to codec 1413 * 1414 * @retval OMX_NoError Success, ready to roll 1415 * OMX_Error_BadParameter The input parameter pointer is null 1416 **/ 1417/*-------------------------------------------------------------------*/ 1418 1419static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent, 1420 OMX_BUFFERHEADERTYPE* pBuffer) 1421{ 1422 OMX_ERRORTYPE eError = OMX_ErrorNone; 1423 OMX_CONF_CHECK_CMD(pComponent,pBuffer,1); 1424 int ret = 0; 1425 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1426 AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1427 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1428 1429 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering EmptyThisBuffer\n", __LINE__); 1430 1431 pPortDef = ((AACENC_COMPONENT_PRIVATE*) 1432 pComponentPrivate)->pPortDef[INPUT_PORT]; 1433 1434#ifdef _ERROR_PROPAGATION__ 1435 if (pComponentPrivate->curState == OMX_StateInvalid) 1436 { 1437 eError = OMX_ErrorInvalidState; 1438 goto EXIT; 1439 } 1440#endif 1441 1442#ifdef __PERF_INSTRUMENTATION__ 1443 PERF_ReceivedFrame(pComponentPrivate->pPERF,pBuffer->pBuffer, pBuffer->nFilledLen, 1444 PERF_ModuleHLMM); 1445#endif 1446 1447 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pBuffer->nSize %d \n",(int)pBuffer->nSize); 1448 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: size OMX_BUFFERHEADERTYPE %d \n",sizeof(OMX_BUFFERHEADERTYPE)); 1449 1450 if(!pPortDef->bEnabled) 1451 { 1452 eError = OMX_ErrorIncorrectStateOperation; 1453 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1454 goto EXIT; 1455 } 1456 if (pBuffer == NULL) 1457 { 1458 eError = OMX_ErrorBadParameter; 1459 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 1460 goto EXIT; 1461 } 1462 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) 1463 { 1464 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 1465 eError = OMX_ErrorBadParameter; 1466 goto EXIT; 1467 } 1468 1469 1470 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) 1471 { 1472 eError = OMX_ErrorVersionMismatch; 1473 goto EXIT; 1474 } 1475 1476 if (pBuffer->nInputPortIndex != INPUT_PORT) 1477 { 1478 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadPortIndex\n",__LINE__); 1479 eError = OMX_ErrorBadPortIndex; 1480 goto EXIT; 1481 } 1482 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1483 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Component Sending Filled ip buff %p to Component Thread\n", __LINE__,pBuffer); 1484 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1485 1486 pComponentPrivate->pMarkData = pBuffer->pMarkData; 1487 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent; 1488 1489 pComponentPrivate->nUnhandledEmptyThisBuffers++; 1490 1491 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof(OMX_BUFFERHEADERTYPE*)); 1492 if (ret == -1) 1493 { 1494 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__); 1495 eError = OMX_ErrorHardware; 1496 goto EXIT; 1497 } 1498 pComponentPrivate->EmptythisbufferCount++; 1499 1500EXIT: 1501 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting EmptyThisBuffer\n", __LINE__); 1502 return eError; 1503} 1504/*-------------------------------------------------------------------*/ 1505/** 1506 * FillThisBuffer() This callback is used to send the output buffer to 1507 * the component 1508 * 1509 * @param pComponent handle for this instance of the component 1510 * @param nPortIndex output port number 1511 * @param pBuffer buffer to be sent to codec 1512 * 1513 * @retval OMX_NoError Success, ready to roll 1514 * OMX_Error_BadParameter The input parameter pointer is null 1515 **/ 1516/*-------------------------------------------------------------------*/ 1517 1518static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent, 1519 OMX_BUFFERHEADERTYPE* pBuffer) 1520{ 1521 OMX_ERRORTYPE eError = OMX_ErrorNone; 1522 OMX_CONF_CHECK_CMD(pComponent,pBuffer,1); 1523 int ret = 0; 1524 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1525 AACENC_COMPONENT_PRIVATE *pComponentPrivate = 1526 (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1527 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1528 1529 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering FillThisBuffer\n", __LINE__); 1530 1531 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1532 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Component Sending Emptied op buff %p to Component Thread\n",__LINE__,pBuffer); 1533 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1534 pPortDef = ((AACENC_COMPONENT_PRIVATE*) 1535 pComponentPrivate)->pPortDef[OUTPUT_PORT]; 1536 1537#ifdef _ERROR_PROPAGATION__ 1538 if (pComponentPrivate->curState == OMX_StateInvalid) 1539 { 1540 eError = OMX_ErrorInvalidState; 1541 goto EXIT; 1542 } 1543#endif 1544 1545#ifdef __PERF_INSTRUMENTATION__ 1546 PERF_ReceivedFrame(pComponentPrivate->pPERF,pBuffer->pBuffer,0,PERF_ModuleHLMM); 1547#endif 1548 1549 if(!pPortDef->bEnabled) 1550 { 1551 eError = OMX_ErrorIncorrectStateOperation; 1552 goto EXIT; 1553 } 1554 if (pBuffer == NULL) 1555 { 1556 eError = OMX_ErrorBadParameter; 1557 OMX_ERROR4(pComponentPrivate->dbg, " %d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 1558 goto EXIT; 1559 } 1560 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) 1561 { 1562 eError = OMX_ErrorBadParameter; 1563 goto EXIT; 1564 } 1565 1566 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) 1567 { 1568 eError = OMX_ErrorVersionMismatch; 1569 goto EXIT; 1570 } 1571 1572 if (pBuffer->nOutputPortIndex != OUTPUT_PORT) 1573 { 1574 eError = OMX_ErrorBadPortIndex; 1575 goto EXIT; 1576 } 1577 pBuffer->nFilledLen = 0; 1578 /*Filling the Output buffer with zero */ 1579#ifndef UNDER_CE 1580 /*memset(pBuffer->pBuffer, 0, pBuffer->nAllocLen);*/ 1581#endif 1582 1583 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pMarkBuf = %p\n",__LINE__, pComponentPrivate->pMarkBuf); 1584 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pMarkData = %p\n",__LINE__, pComponentPrivate->pMarkData); 1585 if(pComponentPrivate->pMarkBuf) 1586 { 1587 pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent; 1588 pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData; 1589 pComponentPrivate->pMarkBuf = NULL; 1590 } 1591 1592 if (pComponentPrivate->pMarkData) 1593 { 1594 pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent; 1595 pBuffer->pMarkData = pComponentPrivate->pMarkData; 1596 pComponentPrivate->pMarkData = NULL; 1597 } 1598 1599 pComponentPrivate->nUnhandledFillThisBuffers++; 1600 1601 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof (OMX_BUFFERHEADERTYPE*)); 1602 if (ret == -1) 1603 { 1604 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Writing to the Data pipe\n", __LINE__); 1605 eError = OMX_ErrorHardware; 1606 goto EXIT; 1607 } 1608 pComponentPrivate->FillthisbufferCount++; 1609 1610EXIT: 1611 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FillThisBuffer error= %d \n", __LINE__,eError); 1612 return eError; 1613} 1614/*-------------------------------------------------------------------*/ 1615/** 1616 * OMX_ComponentDeinit() this methold will de init the component 1617 * 1618 * @param pComp handle for this instance of the component 1619 * 1620 * @retval OMX_NoError Success, ready to roll 1621 * OMX_Error_BadParameter The input parameter pointer is null 1622 **/ 1623/*-------------------------------------------------------------------*/ 1624 1625static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle) 1626{ 1627 OMX_ERRORTYPE eError = OMX_ErrorNone; 1628 OMX_CONF_CHECK_CMD(pHandle,1,1); 1629 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 1630 AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate; 1631 struct OMX_TI_Debug dbg; 1632 dbg = pComponentPrivate->dbg; 1633 1634 OMX_PRINT1(dbg, "%d :: AACENC: ComponentDeInit\n",__LINE__); 1635 OMX_PRDSP2(dbg, "AACENC: LCML %p \n",pComponentPrivate->ptrLibLCML); 1636 1637#ifdef __PERF_INSTRUMENTATION__ 1638 PERF_Boundary(pComponentPrivate->pPERF,PERF_BoundaryStart | PERF_BoundaryCleanup); 1639#endif 1640 1641#ifndef UNDER_CE 1642#ifdef DSP_RENDERING_ON 1643 close(Aacenc_fdwrite); 1644 close(Aacenc_fdread); 1645#endif 1646#endif 1647 1648#ifdef RESOURCE_MANAGER_ENABLED 1649 eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_AAC_Encoder_COMPONENT, 0, 3456, NULL); 1650 if (eError != OMX_ErrorNone) 1651 { 1652 OMX_ERROR4(dbg, "%d :: Error returned from destroy ResourceManagerProxy thread\n", 1653 __LINE__); 1654 } 1655 1656 eError = RMProxy_Deinitalize(); 1657 if (eError != OMX_ErrorNone) 1658 { 1659 OMX_ERROR4(dbg, "%d :: Error returned from destroy ResourceManagerProxy thread\n",__LINE__); 1660 } 1661#endif 1662 1663#ifdef SWAT_ANALYSIS 1664 SWATAPI_ReleaseHandle(pComponentPrivate->pSwatInfo->pSwatApiHandle); 1665 SWAT_Boundary(pComponentPrivate->pSwatInfo->pSwatObjHandle, 1666 pComponentPrivate->pSwatInfo->ctUC, 1667 SWAT_BoundaryComplete | SWAT_BoundaryCleanup); 1668 OMX_PRINT2(dbg, "%d :: AACENC: Instrumentation: SWAT_BoundaryComplete Done\n",__LINE__); 1669 SWAT_Done(pComponentPrivate->pSwatInfo->pSwatObjHandle); 1670#endif 1671 1672 OMX_PRINT2(dbg, "%d :: AACENC: Inside ComponentDeInit point A \n",__LINE__); 1673 pComponentPrivate->bIsThreadstop = 1; 1674 eError = AACENC_StopComponentThread(pHandle); 1675 OMX_PRINT2(dbg, "%d :: AACENC: Inside ComponentDeInit Point B \n",__LINE__); 1676 /* Wait for thread to exit so we can get the status into "error" */ 1677 1678 /* close the pipe handles */ 1679 AACENC_FreeCompResources(pHandle); 1680 1681#ifdef __PERF_INSTRUMENTATION__ 1682 PERF_Boundary(pComponentPrivate->pPERF, 1683 PERF_BoundaryComplete | PERF_BoundaryCleanup); 1684 PERF_Done(pComponentPrivate->pPERF); 1685#endif 1686 1687 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList); 1688 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 1689 OMX_PRBUFFER2(dbg, "%d :: AACENC: After AACENC_FreeCompResources\n",__LINE__); 1690 OMX_PRBUFFER2(dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate); 1691 1692 if (pComponentPrivate->sDeviceString != NULL) 1693 { 1694 OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString); 1695 } 1696 1697 /* CLose LCML . - Note: Need to handle better - */ 1698 if ((pComponentPrivate->ptrLibLCML != NULL && pComponentPrivate->bGotLCML) && 1699 (pComponentPrivate->bCodecDestroyed)) 1700 { 1701 OMX_PRDSP2(dbg, "AACENC: About to Close LCML %p \n",pComponentPrivate->ptrLibLCML); 1702 dlclose( pComponentPrivate->ptrLibLCML ); 1703 pComponentPrivate->ptrLibLCML = NULL; 1704 OMX_PRDSP2(dbg, "AACENC: Closed LCML \n"); 1705 1706 pComponentPrivate->bCodecDestroyed = OMX_FALSE; /* restoring flags */ 1707 pComponentPrivate->bGotLCML = OMX_FALSE; 1708 } 1709 1710 OMX_MEMFREE_STRUCT(pComponentPrivate); 1711 pComponentPrivate = NULL; 1712 1713EXIT: 1714 OMX_DBG_CLOSE(dbg); 1715 return eError; 1716} 1717 1718/*-------------------------------------------------------------------*/ 1719/** 1720 * ComponentTunnelRequest() this method is not implemented in 1.5 1721 * 1722 * This method will update application callbacks 1723 * the application. 1724 * 1725 * @param pComp handle for this instance of the component 1726 * @param pCallBacks application callbacks 1727 * @param ptr 1728 * 1729 * @retval OMX_NoError Success, ready to roll 1730 * OMX_Error_BadParameter The input parameter pointer is null 1731 **/ 1732/*-------------------------------------------------------------------*/ 1733 1734static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 1735 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 1736 OMX_U32 nTunneledPort, 1737 OMX_TUNNELSETUPTYPE* pTunnelSetup) 1738{ 1739 OMX_ERRORTYPE eError = OMX_ErrorNone; 1740 eError = OMX_ErrorNotImplemented; 1741 return eError; 1742} 1743 1744/*-------------------------------------------------------------------*/ 1745/** 1746 * AllocateBuffer() 1747 1748 * @param pComp handle for this instance of the component 1749 * @param pCallBacks application callbacks 1750 * @param ptr 1751 * 1752 * @retval OMX_NoError Success, ready to roll 1753 * OMX_Error_BadParameter The input parameter pointer is null 1754 **/ 1755/*-------------------------------------------------------------------*/ 1756 1757static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 1758 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 1759 OMX_IN OMX_U32 nPortIndex, 1760 OMX_IN OMX_PTR pAppPrivate, 1761 OMX_IN OMX_U32 nSizeBytes) 1762 1763{ 1764 OMX_ERRORTYPE eError = OMX_ErrorNone; 1765 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL; 1766 AACENC_COMPONENT_PRIVATE *pComponentPrivate= NULL; 1767 1768 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 1769 OMX_CONF_CHECK_CMD(hComponent,pBuffer,1); 1770 1771 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering AllocateBuffer\n", __LINE__); 1772 OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer = %p\n", __LINE__,pBuffer); 1773 OMXDBG_PRINT(stderr, COMM, 2, 0, "AACENC: nPortIndex = %d - %p \n",(int)nPortIndex,&nPortIndex); 1774 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *) 1775 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1776 1777 pPortDef = ((AACENC_COMPONENT_PRIVATE*) 1778 pComponentPrivate)->pPortDef[nPortIndex]; 1779 1780#ifdef _ERROR_PROPAGATION__ 1781 if (pComponentPrivate->curState == OMX_StateInvalid) 1782 { 1783 eError = OMX_ErrorInvalidState; 1784 goto EXIT; 1785 } 1786#endif 1787 1788#ifdef __PERF_INSTRUMENTATION__ 1789 PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer,nSizeBytes,PERF_ModuleMemory); 1790#endif 1791 1792 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef = %p\n", __LINE__, pPortDef); 1793 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->bEnabled = %d\n", __LINE__, pPortDef->bEnabled); 1794 while (1) 1795 { 1796 if(pPortDef->bEnabled) 1797 { 1798 break; 1799 } 1800 pComponentPrivate->AlloBuf_waitingsignal = 1; 1801 1802#ifndef UNDER_CE 1803 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1804 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex); 1805 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1806#else 1807 OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event)); 1808#endif 1809 break; 1810 1811 } 1812 1813 OMX_MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE); 1814 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader %p\n",pBufferHeader); 1815 1816 OMX_MALLOC_STRUCT_SIZE(pBufferHeader->pBuffer, nSizeBytes + 256, OMX_U8); 1817 1818 pBufferHeader->pBuffer += 128; 1819 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pbuffer %p to %p \n",pBufferHeader->pBuffer,(pBufferHeader->pBuffer + sizeof(pBufferHeader->pBuffer)) ); 1820 1821 if (nPortIndex == INPUT_PORT) 1822 { 1823 pBufferHeader->nInputPortIndex = nPortIndex; 1824 pBufferHeader->nOutputPortIndex = -1; 1825 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 1826 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p\n",__LINE__, pComponentPrivate->pInputBufferList->numBuffers,pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]); 1827 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 1828 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1; 1829 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__, pComponentPrivate->pInputBufferList->numBuffers); 1830 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->nBufferCountMin = %ld \n",__LINE__, pPortDef->nBufferCountMin); 1831 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) 1832 { 1833 pPortDef->bPopulated = OMX_TRUE; 1834 } 1835 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: INPUT PORT - pPortDef->bPopulated = %d\n",__LINE__, pPortDef->bPopulated); 1836 } 1837 else if (nPortIndex == OUTPUT_PORT) 1838 { 1839 pBufferHeader->nInputPortIndex = -1; 1840 pBufferHeader->nOutputPortIndex = nPortIndex; 1841 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1842 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1843 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p\n",__LINE__, pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]); 1844 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1; 1845 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__, pComponentPrivate->pOutputBufferList->numBuffers); 1846 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->nBufferCountMin = %ld \n",__LINE__, pPortDef->nBufferCountMin); 1847 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) 1848 { 1849 pPortDef->bPopulated = OMX_TRUE; 1850 } 1851 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: OUTPUT PORT - pPortDef->bPopulated = %d\n",__LINE__, pPortDef->bPopulated); 1852 } 1853 else 1854 { 1855 eError = OMX_ErrorBadPortIndex; 1856 goto EXIT; 1857 } 1858 1859 if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&& 1860 (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) && 1861 (pComponentPrivate->InLoaded_readytoidle)) 1862 { 1863 pComponentPrivate->InLoaded_readytoidle = 0; 1864#ifndef UNDER_CE 1865 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 1866 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 1867 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 1868#else 1869 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 1870#endif 1871 } 1872 1873 pBufferHeader->pAppPrivate = pAppPrivate; 1874 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1875 pBufferHeader->nAllocLen = nSizeBytes; 1876 pBufferHeader->nVersion.s.nVersionMajor = AACENC_MAJOR_VER; 1877 pBufferHeader->nVersion.s.nVersionMinor = AACENC_MINOR_VER; 1878 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 1879 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 1880 *pBuffer = pBufferHeader; 1881 if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) 1882 { 1883 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortEnable,pComponentPrivate->nEnableCommandParam,NULL); 1884 } 1885 1886#ifdef __PERF_INSTRUMENTATION__ 1887 PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer, nSizeBytes,PERF_ModuleMemory); 1888#endif 1889 1890EXIT: 1891 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: AllocateBuffer returning eError = %d\n",__LINE__,eError); 1892 1893 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader = %p\n",pBufferHeader); 1894 OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pBuffer = %p\n",pBufferHeader->pBuffer); 1895 return eError; 1896} 1897 1898/*-------------------------------------------------------------------*/ 1899/** 1900 * FreeBuffer() 1901 1902 * @param hComponent handle for this instance of the component 1903 * @param pCallBacks application callbacks 1904 * @param ptr 1905 * 1906 * @retval OMX_NoError Success, ready to roll 1907 * OMX_Error_BadParameter The input parameter pointer is null 1908 **/ 1909/*-------------------------------------------------------------------*/ 1910static OMX_ERRORTYPE FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 1911 OMX_IN OMX_U32 nPortIndex, 1912 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 1913{ 1914 OMX_ERRORTYPE eError = OMX_ErrorNone; 1915 OMX_CONF_CHECK_CMD(hComponent,1,pBuffer); 1916 AACENC_COMPONENT_PRIVATE * pComponentPrivate = NULL; 1917 OMX_BUFFERHEADERTYPE* buff = NULL; 1918 OMX_U8* tempBuff = NULL; 1919 int i =0; 1920 int inputIndex = -1; 1921 int outputIndex = -1; 1922 OMX_COMPONENTTYPE *pHandle = NULL; 1923 1924 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: FreeBuffer\n", __LINE__); 1925 OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer); 1926 OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer->pBuffer = %p\n",__LINE__,pBuffer->pBuffer); 1927 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1928 1929 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 1930 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate = %p\n", __LINE__,pComponentPrivate); 1931 for (i=0; i < MAX_NUM_OF_BUFS; i++) 1932 { 1933 buff = pComponentPrivate->pInputBufferList->pBufHdr[i]; 1934 if (buff == pBuffer) 1935 { 1936 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching input buffer\n",__LINE__); 1937 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff); 1938 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer); 1939 inputIndex = i; 1940 break; 1941 } 1942 else 1943 { 1944 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__); 1945 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff); 1946 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer); 1947 } 1948 } 1949 1950 for (i=0; i < MAX_NUM_OF_BUFS; i++) 1951 { 1952 buff = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 1953 if (buff == pBuffer) 1954 { 1955 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching output buffer\n",__LINE__); 1956 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff); 1957 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer); 1958 outputIndex = i; 1959 break; 1960 } 1961 else 1962 { 1963 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__); 1964 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff); 1965 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer); 1966 } 1967 } 1968 1969 1970 if (inputIndex != -1) 1971 { 1972 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) 1973 { 1974 tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer; 1975 if (tempBuff != 0) 1976 { 1977 tempBuff -= 128; 1978 } 1979 OMX_MEMFREE_STRUCT(tempBuff); 1980 } 1981#ifdef __PERF_INSTRUMENTATION__ 1982 PERF_SendingBuffer(pComponentPrivate->pPERF, 1983 pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, 1984 pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen, 1985 PERF_ModuleMemory ); 1986 1987#endif 1988 1989 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate->pBufHeader[INPUT_PORT]); 1990 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]); 1991 pComponentPrivate->pInputBufferList->numBuffers--; 1992 1993 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pInputBufferList->numBuffers); 1994 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountMin = %ld \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountMin); 1995 if (pComponentPrivate->pInputBufferList->numBuffers < pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountActual) 1996 { 1997 1998 pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = OMX_FALSE; 1999 } 2000 2001 if(pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled && 2002 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 2003 (pComponentPrivate->curState == OMX_StateIdle || 2004 pComponentPrivate->curState == OMX_StateExecuting || 2005 pComponentPrivate->curState == OMX_StatePause)) 2006 { 2007 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__); 2008 pComponentPrivate->cbInfo.EventHandler(pHandle, 2009 pHandle->pApplicationPrivate, 2010 OMX_EventError, 2011 OMX_ErrorPortUnpopulated, 2012 OMX_TI_ErrorMinor, 2013 "Input Port Unpopulated"); 2014 } 2015 } 2016 else if (outputIndex != -1) 2017 { 2018 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) 2019 { 2020 tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer; 2021 if (tempBuff != 0) 2022 { 2023 tempBuff -= 128; 2024 } 2025 OMX_MEMFREE_STRUCT(tempBuff); 2026 } 2027#ifdef __PERF_INSTRUMENTATION__ 2028 PERF_SendingBuffer(pComponentPrivate->pPERF, 2029 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, 2030 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen, 2031 PERF_ModuleMemory); 2032 2033#endif 2034 2035 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate->pBufHeader[OUTPUT_PORT]); 2036 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]); 2037 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL; 2038 pComponentPrivate->pOutputBufferList->numBuffers--; 2039 2040 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers); 2041 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountMin = %ld \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountMin); 2042 if (pComponentPrivate->pOutputBufferList->numBuffers < 2043 pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual) 2044 { 2045 2046 pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated = OMX_FALSE; 2047 } 2048 if(pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled && 2049 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 2050 (pComponentPrivate->curState == OMX_StateIdle || 2051 pComponentPrivate->curState == OMX_StateExecuting || 2052 pComponentPrivate->curState == OMX_StatePause)) 2053 { 2054 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__); 2055 pComponentPrivate->cbInfo.EventHandler( pHandle, 2056 pHandle->pApplicationPrivate, 2057 OMX_EventError, 2058 OMX_ErrorPortUnpopulated, 2059 OMX_TI_ErrorMinor, 2060 "Output Port Unpopulated"); 2061 } 2062 } 2063 else 2064 { 2065 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Returning OMX_ErrorBadParameter\n",__LINE__); 2066 eError = OMX_ErrorBadParameter; 2067 } 2068 if ((!pComponentPrivate->pInputBufferList->numBuffers && 2069 !pComponentPrivate->pOutputBufferList->numBuffers) && 2070 pComponentPrivate->InIdle_goingtoloaded) 2071 { 2072 pComponentPrivate->InIdle_goingtoloaded = 0; 2073#ifndef UNDER_CE 2074 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 2075 pthread_cond_signal(&pComponentPrivate->InIdle_threshold); 2076 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 2077#else 2078 OMX_SignalEvent(&(pComponentPrivate->InIdle_event)); 2079#endif 2080 } 2081 2082 if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0)) 2083 { 2084 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL); 2085 } 2086 2087 OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FreeBuffer\n", __LINE__); 2088EXIT: 2089 return eError; 2090} 2091 2092/* ================================================================================= */ 2093/** 2094* @fn UseBuffer() description for UseBuffer 2095UseBuffer(). 2096Called by the OMX IL client to pass a buffer to be used. 2097* 2098* @see OMX_Core.h 2099*/ 2100/* ================================================================================ */ 2101static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent, 2102 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 2103 OMX_IN OMX_U32 nPortIndex, 2104 OMX_IN OMX_PTR pAppPrivate, 2105 OMX_IN OMX_U32 nSizeBytes, 2106 OMX_IN OMX_U8* pBuffer) 2107{ 2108 OMX_ERRORTYPE eError = OMX_ErrorNone; 2109 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL; 2110 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 2111 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 2112 OMX_CONF_CHECK_CMD(hComponent,ppBufferHdr,pBuffer); 2113 2114 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering UseBuffer\n", __LINE__); 2115 OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer = %p\n", __LINE__,pBuffer); 2116 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *) 2117 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 2118 2119#ifdef _ERROR_PROPAGATION__ 2120 if (pComponentPrivate->curState == OMX_StateInvalid) 2121 { 2122 eError = OMX_ErrorInvalidState; 2123 goto EXIT; 2124 } 2125 2126#endif 2127 2128#ifdef __PERF_INSTRUMENTATION__ 2129 PERF_ReceivedBuffer(pComponentPrivate->pPERF,pBuffer, nSizeBytes, 2130 PERF_ModuleHLMM); 2131#endif 2132 2133 pPortDef = ((AACENC_COMPONENT_PRIVATE*) 2134 pComponentPrivate)->pPortDef[nPortIndex]; 2135 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef = %p\n", __LINE__,pPortDef); 2136 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled); 2137 2138 if(!pPortDef->bEnabled) 2139 { 2140 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: In AllocateBuffer\n", __LINE__); 2141 eError = OMX_ErrorIncorrectStateOperation; 2142 goto EXIT; 2143 } 2144 2145 OMX_PRINT2(pComponentPrivate->dbg, "AACENC: nSizeBytes = %ld\n",nSizeBytes); 2146 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->nBufferSize = %ld\n",pPortDef->nBufferSize); 2147 OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->bPopulated = %d\n",pPortDef->bPopulated); 2148 if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) 2149 { 2150 OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error: In AllocateBuffer\n", __LINE__); 2151 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__); 2152 eError = OMX_ErrorBadParameter; 2153 goto EXIT; 2154 } 2155 2156 OMX_MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE); 2157 2158 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [ALLOC] %p\n",__LINE__,pBufferHeader); 2159 2160 if (nPortIndex == OUTPUT_PORT) 2161 { 2162 pBufferHeader->nInputPortIndex = -1; 2163 pBufferHeader->nOutputPortIndex = nPortIndex; 2164 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 2165 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 2166 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0; 2167 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) 2168 { 2169 pPortDef->bPopulated = OMX_TRUE; 2170 } 2171 } 2172 else 2173 { 2174 pBufferHeader->nInputPortIndex = nPortIndex; 2175 pBufferHeader->nOutputPortIndex = -1; 2176 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 2177 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 2178 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0; 2179 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) 2180 { 2181 pPortDef->bPopulated = OMX_TRUE; 2182 } 2183 } 2184 2185 if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&& 2186 (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) && 2187 (pComponentPrivate->InLoaded_readytoidle)) 2188 { 2189 pComponentPrivate->InLoaded_readytoidle = 0; 2190#ifndef UNDER_CE 2191 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 2192 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 2193 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 2194#else 2195 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 2196#endif 2197 } 2198 2199 pBufferHeader->pAppPrivate = pAppPrivate; 2200 pBufferHeader->pPlatformPrivate = pComponentPrivate; 2201 pBufferHeader->nAllocLen = nSizeBytes; 2202 pBufferHeader->nVersion.s.nVersionMajor = AACENC_MAJOR_VER; 2203 pBufferHeader->nVersion.s.nVersionMinor = AACENC_MINOR_VER; 2204 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 2205 pBufferHeader->pBuffer = pBuffer; 2206 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2207 *ppBufferHdr = pBufferHeader; 2208 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBufferHeader = %p\n",__LINE__,pBufferHeader); 2209 2210 if (pComponentPrivate->bEnableCommandPending) 2211 { 2212 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortEnable,pComponentPrivate->nEnableCommandParam,NULL); 2213 } 2214 2215EXIT: 2216 OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader = %p\n",pBufferHeader); 2217 OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader->pBuffer = %p\n",pBufferHeader->pBuffer); 2218 2219 return eError; 2220} 2221 2222/* ================================================================================= */ 2223/** 2224* @fn GetExtensionIndex() description for GetExtensionIndex 2225GetExtensionIndex(). 2226Returns index for vendor specific settings. 2227* 2228* @see OMX_Core.h 2229*/ 2230/* ================================================================================ */ 2231static OMX_ERRORTYPE GetExtensionIndex( 2232 OMX_IN OMX_HANDLETYPE hComponent, 2233 OMX_IN OMX_STRING cParameterName, 2234 OMX_OUT OMX_INDEXTYPE* pIndexType) 2235{ 2236 OMX_ERRORTYPE eError = OMX_ErrorNone; 2237 2238 OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: GetExtensionIndex\n"); 2239 if (!(strcmp(cParameterName,"OMX.TI.index.config.aacencHeaderInfo"))) 2240 { 2241 *pIndexType = OMX_IndexCustomAacEncHeaderInfoConfig; 2242 OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX_IndexCustomAacEncHeaderInfoConfig\n"); 2243 } 2244 else if(!(strcmp(cParameterName,"OMX.TI.index.config.aacencstreamIDinfo"))) 2245 { 2246 *pIndexType = OMX_IndexCustomAacEncStreamIDConfig; 2247 } 2248 else if(!(strcmp(cParameterName,"OMX.TI.index.config.aac.datapath"))) 2249 { 2250 *pIndexType = OMX_IndexCustomAacEncDataPath; 2251 } 2252 else if (!(strcmp(cParameterName,"OMX.TI.index.config.aacencframesPerOutBuf"))) 2253 { 2254 *pIndexType =OMX_IndexCustomAacEncFramesPerOutBuf; 2255 } 2256 else if (!(strcmp(cParameterName,"OMX.TI.AAC.Encode.Debug"))) 2257 { 2258 *pIndexType =OMX_IndexCustomDebug; 2259 } 2260 else 2261 { 2262 eError = OMX_ErrorBadParameter; 2263 } 2264 2265 OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: Exiting GetExtensionIndex\n"); 2266 2267 return eError; 2268} 2269 2270/* ================================================================================= */ 2271/** 2272* @fn ComponentRoleEnum() description for ComponentRoleEnum() 2273 2274Returns the role at the given index 2275* 2276* @see OMX_Core.h 2277*/ 2278/* ================================================================================ */ 2279static OMX_ERRORTYPE ComponentRoleEnum( 2280 OMX_IN OMX_HANDLETYPE hComponent, 2281 OMX_OUT OMX_U8 *cRole, 2282 OMX_IN OMX_U32 nIndex) 2283{ 2284 OMX_ERRORTYPE eError = OMX_ErrorNone; 2285 AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 2286 pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 2287 if(nIndex == 0) 2288 { 2289 memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 2290 } 2291 else 2292 { 2293 eError = OMX_ErrorNoMore; 2294 goto EXIT; 2295 } 2296 2297EXIT: 2298 return eError; 2299}; 2300 2301#ifdef UNDER_CE 2302/* ================================================================================= */ 2303/** 2304* @fns Sleep replace for WIN CE 2305*/ 2306/* ================================================================================ */ 2307int OMX_CreateEvent(OMX_Event *event){ 2308 int ret = OMX_ErrorNone; 2309 HANDLE createdEvent = NULL; 2310 if(event == NULL){ 2311 ret = OMX_ErrorBadParameter; 2312 goto EXIT; 2313 } 2314 event->event = CreateEvent(NULL, TRUE, FALSE, NULL); 2315 if(event->event == NULL) 2316 ret = (int)GetLastError(); 2317EXIT: 2318 return ret; 2319} 2320 2321int OMX_SignalEvent(OMX_Event *event){ 2322 int ret = OMX_ErrorNone; 2323 if(event == NULL){ 2324 ret = OMX_ErrorBadParameter; 2325 goto EXIT; 2326 } 2327 SetEvent(event->event); 2328 ret = (int)GetLastError(); 2329EXIT: 2330 return ret; 2331} 2332 2333int OMX_WaitForEvent(OMX_Event *event) { 2334 int ret = OMX_ErrorNone; 2335 if(event == NULL){ 2336 ret = OMX_ErrorBadParameter; 2337 goto EXIT; 2338 } 2339 WaitForSingleObject(event->event, INFINITE); 2340 ret = (int)GetLastError(); 2341EXIT: 2342 return ret; 2343} 2344 2345int OMX_DestroyEvent(OMX_Event *event) { 2346 int ret = OMX_ErrorNone; 2347 if(event == NULL){ 2348 ret = OMX_ErrorBadParameter; 2349 goto EXIT; 2350 } 2351 CloseHandle(event->event); 2352EXIT: 2353 return ret; 2354} 2355#endif 2356