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