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_WbAmrDecoder.c 30 * 31 * This file implements OMX Component for WbAMR decoder that 32 * is fully compliant with the OMX Audio specification 1.5. 33 * 34 * @path $(CSLPATH)\ 35 * 36 * @rev 0.1 37 */ 38/* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! 12-Sept-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#ifdef DSP_RENDERING_ON 75#include <AudioManagerAPI.h> 76#endif 77 78#ifdef RESOURCE_MANAGER_ENABLED 79#include <ResourceManagerProxyAPI.h> 80#endif 81 82/*-------program files ----------------------------------------*/ 83#include <OMX_Component.h> 84#include <TIDspOmx.h> 85 86#include "OMX_WbAmrDecoder.h" 87#include "OMX_WbAmrDec_Utils.h" 88 89#define AMRWB_DEC_ROLE "audio_decoder.amrwb" 90 91 92/**************************************************************** 93 * EXTERNAL REFERENCES NOTE : only use if not found in header file 94 ****************************************************************/ 95/*--------data declarations -----------------------------------*/ 96 97/*--------function prototypes ---------------------------------*/ 98 99/**************************************************************** 100 * PUBLIC DECLARATIONS Defined here, used elsewhere 101 ****************************************************************/ 102/*--------data declarations -----------------------------------*/ 103 104/*--------function prototypes ---------------------------------*/ 105 106/**************************************************************** 107 * PRIVATE DECLARATIONS Defined here, used only here 108 ****************************************************************/ 109/*--------data declarations -----------------------------------*/ 110 111/*--------function prototypes ---------------------------------*/ 112 113static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp, 114 OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData); 115static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 116 OMX_STRING pComponentName, 117 OMX_VERSIONTYPE* pComponentVersion, 118 OMX_VERSIONTYPE* pSpecVersion, 119 OMX_UUIDTYPE* pComponentUUID); 120 121static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand, 122 OMX_U32 nParam, OMX_PTR pCmdData); 123 124static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, 125 OMX_PTR ComponentParamStruct); 126static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, 127 OMX_INDEXTYPE nParamIndex, 128 OMX_PTR ComponentParamStruct); 129static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 130 OMX_INDEXTYPE nConfigIndex, 131 OMX_PTR pComponentConfigStructure); 132static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 133 OMX_INDEXTYPE nConfigIndex, 134 OMX_PTR pComponentConfigStructure); 135 136static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 137 138static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 139static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState); 140static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 141 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 142 OMX_U32 nTunneledPort, 143 OMX_TUNNELSETUPTYPE* pTunnelSetup); 144 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( 153 OMX_IN OMX_HANDLETYPE hComponent, 154 OMX_IN OMX_U32 nPortIndex, 155 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 156 157static OMX_ERRORTYPE UseBuffer ( 158 OMX_IN OMX_HANDLETYPE hComponent, 159 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 160 OMX_IN OMX_U32 nPortIndex, 161 OMX_IN OMX_PTR pAppPrivate, 162 OMX_IN OMX_U32 nSizeBytes, 163 OMX_IN OMX_U8* pBuffer); 164 165static OMX_ERRORTYPE GetExtensionIndex( 166 OMX_IN OMX_HANDLETYPE hComponent, 167 OMX_IN OMX_STRING cParameterName, 168 OMX_OUT OMX_INDEXTYPE* pIndexType); 169 170static OMX_ERRORTYPE ComponentRoleEnum( 171 OMX_IN OMX_HANDLETYPE hComponent, 172 OMX_OUT OMX_U8 *cRole, 173 OMX_IN OMX_U32 nIndex); 174#ifdef DSP_RENDERING_ON 175#define FIFO1 "/dev/fifo.1" 176#define FIFO2 "/dev/fifo.2" 177#define PERMS 0666 178 179 180AM_COMMANDDATATYPE cmd_data; 181#endif 182/*-------------------------------------------------------------------*/ 183/** 184 * OMX_ComponentInit() Set the all the function pointers of component 185 * 186 * This method will update the component function pointer to the handle 187 * 188 * @param hComp handle for this instance of the component 189 * 190 * @retval OMX_NoError Success, ready to roll 191 * OMX_ErrorInsufficientResources If the newmalloc fails 192 **/ 193/*-------------------------------------------------------------------*/ 194OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp) 195{ 196 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip, *pPortDef_op; 197 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 198 OMX_AUDIO_PARAM_AMRTYPE *amr_ip; 199 OMX_AUDIO_PARAM_PCMMODETYPE *amr_op; 200 OMX_ERRORTYPE error = OMX_ErrorNone; 201 OMX_ERRORTYPE eError = OMX_ErrorNone; 202 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 203 OMX_S16 i; 204 205 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Entering\n"); 206 207 /*Set the all component function pointer to the handle */ 208 pHandle->SetCallbacks = SetCallbacks; 209 pHandle->GetComponentVersion = GetComponentVersion; 210 pHandle->SendCommand = SendCommand; 211 pHandle->GetParameter = GetParameter; 212 pHandle->SetParameter = SetParameter; 213 pHandle->GetConfig = GetConfig; 214 pHandle->SetConfig = SetConfig; 215 pHandle->GetState = GetState; 216 pHandle->EmptyThisBuffer = EmptyThisBuffer; 217 pHandle->FillThisBuffer = FillThisBuffer; 218 pHandle->ComponentTunnelRequest = ComponentTunnelRequest; 219 pHandle->ComponentDeInit = ComponentDeInit; 220 pHandle->AllocateBuffer = AllocateBuffer; 221 pHandle->FreeBuffer = FreeBuffer; 222 pHandle->UseBuffer = UseBuffer; 223 pHandle->GetExtensionIndex= GetExtensionIndex; 224 pHandle->ComponentRoleEnum = ComponentRoleEnum; 225 226 /*Allocate the memory for Component private data area */ 227 OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, WBAMR_DEC_COMPONENT_PRIVATE); 228 229 230 ((WBAMR_DEC_COMPONENT_PRIVATE *) 231 pHandle->pComponentPrivate)->pHandle = pHandle; 232 233 /* Initialize component data structures to default values */ 234 ((WBAMR_DEC_COMPONENT_PRIVATE *) 235 pHandle->pComponentPrivate)->sPortParam.nPorts = 0x2; 236 ((WBAMR_DEC_COMPONENT_PRIVATE *) 237 pHandle->pComponentPrivate)->sPortParam.nStartPortNumber = 0x0; 238 239 OMX_MALLOC_GENERIC(amr_ip , OMX_AUDIO_PARAM_AMRTYPE); 240 OMX_MALLOC_GENERIC(amr_op , OMX_AUDIO_PARAM_PCMMODETYPE); 241 242 ((WBAMR_DEC_COMPONENT_PRIVATE *) 243 pHandle->pComponentPrivate)->wbamrParams[WBAMR_DEC_INPUT_PORT] = amr_ip; 244 ((WBAMR_DEC_COMPONENT_PRIVATE *) 245 pHandle->pComponentPrivate)->wbamrParams[WBAMR_DEC_OUTPUT_PORT] = (OMX_AUDIO_PARAM_AMRTYPE*)amr_op; 246 247 248 249 pComponentPrivate = pHandle->pComponentPrivate; 250 OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_WBAMRDEC"); 251 252#ifdef __PERF_INSTRUMENTATION__ 253 pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('W','B','D','_'), 254 PERF_ModuleLLMM | 255 PERF_ModuleAudioDecode); 256#endif 257 258#ifdef ANDROID /* currently using default values until more is understood */ 259 pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; /* this should be true always for TI components */ 260 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE; 261 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE; 262 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; /* experiment with this */ 263 pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; /* experiment with this */ 264 pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE; /* used only for H.264, leave this as false */ 265 pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE; /* experiment with this */ 266#endif 267 268 OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, WBAMR_DEC_BUFFERLIST); 269 pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */ 270 OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, WBAMR_DEC_BUFFERLIST); 271 OMX_MALLOC_GENERIC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE); 272 pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */ 273 for (i=0; i < WBAMR_DEC_MAX_NUM_OF_BUFS; i++) { 274 pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL; 275 pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL; 276 pComponentPrivate->arrTickCount[i] = 0; 277 pComponentPrivate->arrBufIndex[i] = 0; 278 } 279 280 pComponentPrivate->IpBufindex = 0; 281 pComponentPrivate->OpBufindex = 0; 282 283 OMX_PRINT1(pComponentPrivate->dbg, "Setting dasfmode and mimemode to 0\n"); 284 pComponentPrivate->dasfmode = 0; 285 pComponentPrivate->mimemode = 0; 286 pComponentPrivate->bPortDefsAllocated = 0; 287 pComponentPrivate->bCompThreadStarted = 0; 288 pComponentPrivate->nHoldLength = 0; 289 pComponentPrivate->pHoldBuffer = NULL; 290 pComponentPrivate->bInitParamsInitialized = 0; 291 pComponentPrivate->wbamrMimeBytes[0] = WBAMR_DEC_FRAME_SIZE_18; 292 pComponentPrivate->wbamrMimeBytes[1] = WBAMR_DEC_FRAME_SIZE_24; 293 pComponentPrivate->wbamrMimeBytes[2] = WBAMR_DEC_FRAME_SIZE_33; 294 pComponentPrivate->wbamrMimeBytes[3] = WBAMR_DEC_FRAME_SIZE_37; 295 pComponentPrivate->wbamrMimeBytes[4] = WBAMR_DEC_FRAME_SIZE_41; 296 pComponentPrivate->wbamrMimeBytes[5] = WBAMR_DEC_FRAME_SIZE_47; 297 pComponentPrivate->wbamrMimeBytes[6] = WBAMR_DEC_FRAME_SIZE_51; 298 pComponentPrivate->wbamrMimeBytes[7] = WBAMR_DEC_FRAME_SIZE_59; 299 pComponentPrivate->wbamrMimeBytes[8] = WBAMR_DEC_FRAME_SIZE_61; 300 pComponentPrivate->wbamrMimeBytes[9] = WBAMR_DEC_FRAME_SIZE_6; 301 pComponentPrivate->wbamrMimeBytes[10] = WBAMR_DEC_FRAME_SIZE_0; 302 pComponentPrivate->wbamrMimeBytes[11] = WBAMR_DEC_FRAME_SIZE_0; 303 pComponentPrivate->wbamrMimeBytes[12] = WBAMR_DEC_FRAME_SIZE_0; 304 pComponentPrivate->wbamrMimeBytes[13] = WBAMR_DEC_FRAME_SIZE_0; 305 pComponentPrivate->wbamrMimeBytes[14] = WBAMR_DEC_FRAME_SIZE_1; 306 pComponentPrivate->wbamrMimeBytes[15] = WBAMR_DEC_FRAME_SIZE_1; 307 308 pComponentPrivate->wbamrIf2Bytes[0] = WBAMR_DEC_FRAME_SIZE_18; 309 pComponentPrivate->wbamrIf2Bytes[1] = WBAMR_DEC_FRAME_SIZE_23; 310 pComponentPrivate->wbamrIf2Bytes[2] = WBAMR_DEC_FRAME_SIZE_33; 311 pComponentPrivate->wbamrIf2Bytes[3] = WBAMR_DEC_FRAME_SIZE_37; 312 pComponentPrivate->wbamrIf2Bytes[4] = WBAMR_DEC_FRAME_SIZE_41; 313 pComponentPrivate->wbamrIf2Bytes[5] = WBAMR_DEC_FRAME_SIZE_47; 314 pComponentPrivate->wbamrIf2Bytes[6] = WBAMR_DEC_FRAME_SIZE_51; 315 pComponentPrivate->wbamrIf2Bytes[7] = WBAMR_DEC_FRAME_SIZE_59; 316 pComponentPrivate->wbamrIf2Bytes[8] = WBAMR_DEC_FRAME_SIZE_61; 317 pComponentPrivate->wbamrIf2Bytes[9] = WBAMR_DEC_FRAME_SIZE_6; 318 pComponentPrivate->wbamrIf2Bytes[10] = WBAMR_DEC_FRAME_SIZE_0; 319 pComponentPrivate->wbamrIf2Bytes[11] = WBAMR_DEC_FRAME_SIZE_0; 320 pComponentPrivate->wbamrIf2Bytes[12] = WBAMR_DEC_FRAME_SIZE_0; 321 pComponentPrivate->wbamrIf2Bytes[13] = WBAMR_DEC_FRAME_SIZE_0; 322 pComponentPrivate->wbamrIf2Bytes[14] = WBAMR_DEC_FRAME_SIZE_1; 323 pComponentPrivate->wbamrIf2Bytes[15] = WBAMR_DEC_FRAME_SIZE_1; 324 325 pComponentPrivate->pMarkBuf = NULL; 326 pComponentPrivate->pMarkData = NULL; 327 pComponentPrivate->nEmptyBufferDoneCount = 0; 328 pComponentPrivate->nEmptyThisBufferCount = 0; 329 pComponentPrivate->nFillBufferDoneCount = 0; 330 pComponentPrivate->nFillThisBufferCount = 0; 331 pComponentPrivate->strmAttr = NULL; 332 /* pComponentPrivate->bIdleCommandPending = 0; */ 333 pComponentPrivate->bDisableCommandParam = 0; 334 pComponentPrivate->SendAfterEOS = 0; 335 pComponentPrivate->PendingPausedBufs = 0; 336 for (i=0; i < WBAMR_DEC_MAX_NUM_OF_BUFS; i++) { 337 pComponentPrivate->pInputBufHdrPending[i] = NULL; 338 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 339 } 340 pComponentPrivate->nNumInputBufPending = 0; 341 pComponentPrivate->nNumOutputBufPending = 0; 342 pComponentPrivate->bDisableCommandPending = 0; 343 pComponentPrivate->nOutStandingFillDones = 0; 344 pComponentPrivate->bStopSent=0; 345 pComponentPrivate->bNoIdleOnStop = OMX_FALSE; 346 pComponentPrivate->pParams = NULL; /* Without this initialization repetition cases failed. */ 347 pComponentPrivate->LastOutbuf=NULL; 348 pComponentPrivate->using_rtsp = 0; 349 strcpy((char*)pComponentPrivate->componentRole.cRole, AMRWB_DEC_ROLE); 350 351 352 353 /* Set input port format defaults */ 354 pComponentPrivate->sInPortFormat.nPortIndex = WBAMR_DEC_INPUT_PORT; 355 pComponentPrivate->sInPortFormat.nIndex = OMX_IndexParamAudioAmr; 356 pComponentPrivate->sInPortFormat.eEncoding = OMX_AUDIO_CodingAMR; 357 358 359 /* Set output port format defaults */ 360 pComponentPrivate->sOutPortFormat.nPortIndex = WBAMR_DEC_OUTPUT_PORT; 361 pComponentPrivate->sOutPortFormat.nIndex = OMX_IndexParamAudioPcm; 362 pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM; 363 364 pComponentPrivate->bPreempted = OMX_FALSE; 365 366 amr_ip->nPortIndex = OMX_DirInput; 367 amr_ip->nChannels = 1; 368 amr_ip->nBitRate = 8000; 369 amr_ip->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0; 370 amr_ip->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff; 371 amr_ip->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance; 372 amr_ip->nSize = sizeof (OMX_AUDIO_PARAM_AMRTYPE); 373 374 /* PCM format defaults - These values are required to pass StdAudioDecoderTest*/ 375 amr_op->nPortIndex = OMX_DirOutput; 376 amr_op->nChannels = 1; 377 amr_op->eNumData= OMX_NumericalDataSigned; 378 amr_op->nSamplingRate = 16000; 379 amr_op->nBitPerSample = 16; 380 amr_op->ePCMMode = OMX_AUDIO_PCMModeLinear; 381 382 OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, (100*sizeof(char)),OMX_STRING); 383 pComponentPrivate->IpBufindex = 0; 384 pComponentPrivate->OpBufindex = 0; 385 pComponentPrivate->ptrLibLCML = NULL; 386 387 strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0"); 388#ifndef UNDER_CE 389 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL); 390 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL); 391 pComponentPrivate->AlloBuf_waitingsignal = 0; 392 393 pthread_mutex_init(&pComponentPrivate->codecStop_mutex, NULL); 394 pthread_cond_init (&pComponentPrivate->codecStop_threshold, NULL); 395 pComponentPrivate->codecStop_waitingsignal = 0; 396 397 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL); 398 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL); 399 pComponentPrivate->InLoaded_readytoidle = 0; 400 401 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL); 402 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL); 403 pComponentPrivate->InIdle_goingtoloaded = 0; 404#else 405 OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event)); 406 pComponentPrivate->AlloBuf_waitingsignal = 0; 407 408 OMX_CreateEvent(&(pComponentPrivate->InLoaded_event)); 409 pComponentPrivate->InLoaded_readytoidle = 0; 410 411 OMX_CreateEvent(&(pComponentPrivate->InIdle_event)); 412 pComponentPrivate->InIdle_goingtoloaded = 0; 413#endif 414 OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE); 415 416 OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE); 417 418 OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pPortDef_op); 419 OMX_PRINT1(pComponentPrivate->dbg, "pPortDef_ip = %p\n",pPortDef_ip); 420 OMX_PRINT1(pComponentPrivate->dbg, "pPortDef_op = %p\n",pPortDef_op); 421 422 ((WBAMR_DEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[WBAMR_DEC_INPUT_PORT] 423 = pPortDef_ip; 424 425 ((WBAMR_DEC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pPortDef[WBAMR_DEC_OUTPUT_PORT] 426 = pPortDef_op; 427 pPortDef_ip->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE); 428 pPortDef_ip->nPortIndex = 0x0; 429 pPortDef_ip->nBufferCountActual = NUM_WBAMRDEC_INPUT_BUFFERS; 430 pPortDef_ip->nBufferCountMin = NUM_WBAMRDEC_INPUT_BUFFERS; 431 pPortDef_ip->nBufferAlignment = DSP_CACHE_ALIGNMENT; 432 pPortDef_ip->eDir = OMX_DirInput; 433 pPortDef_ip->bEnabled = OMX_TRUE; 434 /* Use bigger IN buffer size for PV-Android */ 435 pPortDef_ip->nBufferSize = IP_WBAMRDEC_BUFFERSIZE; 436 pPortDef_ip->bPopulated = 0; 437 pPortDef_ip->format.audio.eEncoding = OMX_AUDIO_CodingAMR; 438 439 pPortDef_op->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE); 440 pPortDef_op->nPortIndex = 0x1; 441 pPortDef_op->nBufferCountActual = NUM_WBAMRDEC_OUTPUT_BUFFERS; 442 pPortDef_op->nBufferCountMin = NUM_WBAMRDEC_OUTPUT_BUFFERS; 443 pPortDef_op->nBufferAlignment = DSP_CACHE_ALIGNMENT; 444 pPortDef_op->eDir = OMX_DirOutput; 445 pPortDef_op->bEnabled = OMX_TRUE; 446 pPortDef_op->nBufferSize = OUTPUT_WBAMRDEC_BUFFER_SIZE; 447 pPortDef_op->bPopulated = 0; 448 pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingPCM; 449 pComponentPrivate->bIsInvalidState = OMX_FALSE; 450 451#ifdef RESOURCE_MANAGER_ENABLED 452 error = RMProxy_NewInitalize(); 453 if (error != OMX_ErrorNone) { 454 OMX_ERROR4(pComponentPrivate->dbg, "Error returned from loading ResourceManagerProxy thread\n"); 455 goto EXIT; 456 } 457#endif 458 459 error = WBAMR_DEC_StartComponentThread(pHandle); 460 if (error != OMX_ErrorNone) { 461 OMX_ERROR4(pComponentPrivate->dbg, "Error returned from the Component\n"); 462 goto EXIT; 463 } 464 OMX_PRINT1(pComponentPrivate->dbg, "OMX_ComponentInit\n"); 465 466 467#ifdef DSP_RENDERING_ON 468 OMX_PRINT1(pComponentPrivate->dbg, "OMX_ComponentInit\n"); 469 if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0) { 470 OMX_ERROR4(pComponentPrivate->dbg, "[WBAMR Dec Component] - failure to open WRITE pipe\n"); 471 } 472 473 OMX_PRINT1(pComponentPrivate->dbg, "OMX_ComponentInit\n"); 474 if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0) { 475 OMX_ERROR4(pComponentPrivate->dbg, "[WBAMR Dec Component] - failure to open READ pipe\n"); 476 goto EXIT; 477 } 478 479#endif 480#ifdef __PERF_INSTRUMENTATION__ 481 PERF_ThreadCreated(pComponentPrivate->pPERF, pComponentPrivate->WBAMR_DEC_ComponentThread, 482 PERF_FOURCC('W','B','D','T')); 483#endif 484 EXIT: 485 if (pComponentPrivate != NULL) { 486 OMX_PRINT1(pComponentPrivate->dbg, "Exiting - returning %d\n", error); 487 } 488 return error; 489} 490 491/*-------------------------------------------------------------------*/ 492/** 493 * SetCallbacks() Sets application callbacks to the component 494 * 495 * This method will update application callbacks 496 * to the component. So that component can make use of those call back 497 * while sending buffers to the application. And also it will copy the 498 * application private data to component memory 499 * 500 * @param pComponent handle for this instance of the component 501 * @param pCallBacks application callbacks 502 * @param pAppData Application private data 503 * 504 * @retval OMX_NoError Success, ready to roll 505 * OMX_Error_BadParameter The input parameter pointer is null 506 **/ 507/*-------------------------------------------------------------------*/ 508 509static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent, 510 OMX_CALLBACKTYPE* pCallBacks, 511 OMX_PTR pAppData) 512{ 513 OMX_ERRORTYPE eError = OMX_ErrorNone; 514 515 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent; 516 517 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = 518 (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 519 520 if (pCallBacks == NULL) { 521 OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line\n"); 522 eError = OMX_ErrorBadParameter; 523 OMX_PRDSP1(pComponentPrivate->dbg, "Received the empty callbacks from the \ 524 application\n"); 525 goto EXIT; 526 } 527 528 /*Copy the callbacks of the application to the component private */ 529 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE)); 530 531 /*copy the application private data to component memory */ 532 pHandle->pApplicationPrivate = pAppData; 533 534 pComponentPrivate->curState = OMX_StateLoaded; 535#ifdef __PERF_INSTRUMENTATION__ 536 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup); 537#endif 538 539 EXIT: 540 return eError; 541} 542 543/*-------------------------------------------------------------------*/ 544/** 545 * GetComponentVersion() This will return the component version 546 * 547 * This method will retrun the component version 548 * 549 * @param hComp handle for this instance of the component 550 * @param pCompnentName Name of the component 551 * @param pCompnentVersion handle for this instance of the component 552 * @param pSpecVersion application callbacks 553 * @param pCompnentUUID 554 * 555 * @retval OMX_NoError Success, ready to roll 556 * OMX_Error_BadParameter The input parameter pointer is null 557 **/ 558/*-------------------------------------------------------------------*/ 559 560static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 561 OMX_STRING pComponentName, 562 OMX_VERSIONTYPE* pComponentVersion, 563 OMX_VERSIONTYPE* pSpecVersion, 564 OMX_UUIDTYPE* pComponentUUID) 565{ 566 OMX_ERRORTYPE eError = OMX_ErrorNone; 567 568 eError = OMX_ErrorNotImplemented; 569 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Inside the GetComponentVersion\n"); 570 return eError; 571 572} 573 574 575/*-------------------------------------------------------------------*/ 576/** 577 * SendCommand() used to send the commands to the component 578 * 579 * This method will be used by the application. 580 * 581 * @param phandle handle for this instance of the component 582 * @param Cmd Command to be sent to the component 583 * @param nParam indicates commmad is sent using this method 584 * 585 * @retval OMX_NoError Success, ready to roll 586 * OMX_Error_BadParameter The input parameter pointer is null 587 **/ 588/*-------------------------------------------------------------------*/ 589 590static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle, 591 OMX_COMMANDTYPE Cmd, 592 OMX_U32 nParam,OMX_PTR pCmdData) 593{ 594 OMX_ERRORTYPE eError = OMX_ErrorNone; 595 int nRet; 596 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle; 597 WBAMR_DEC_COMPONENT_PRIVATE *pCompPrivate = 598 (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 599 600 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 601 602 OMX_PRDSP2(pCompPrivate->dbg, "phandle = %p\n",phandle); 603 OMX_PRDSP1(pCompPrivate->dbg, "pCompPrivate = %p\n",pCompPrivate); 604 605 pCompPrivate->pHandle = phandle; 606 607#ifdef _ERROR_PROPAGATION__ 608 if (pCompPrivate->curState == OMX_StateInvalid){ 609 eError = OMX_ErrorInvalidState; 610 goto EXIT; 611 } 612#else 613 if(pCompPrivate->curState == OMX_StateInvalid){ 614 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 615 eError = OMX_ErrorInvalidState; 616 OMX_ERROR4(pCompPrivate->dbg, "Error NotIfication \ 617 Sent to App\n"); 618 pCompPrivate->cbInfo.EventHandler (pHandle, 619 pHandle->pApplicationPrivate, 620 OMX_EventError, 621 OMX_ErrorInvalidState, 622 OMX_TI_ErrorMinor, 623 "Invalid State"); 624 goto EXIT; 625 } 626#endif 627#ifdef __PERF_INSTRUMENTATION__ 628 PERF_SendingCommand(pCompPrivate->pPERF, Cmd, 629 (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam, 630 PERF_ModuleComponent); 631#endif 632 633 switch(Cmd) { 634 case OMX_CommandStateSet: 635 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 636 OMX_PRSTATE1(pCompPrivate->dbg, "pCompPrivate->curState = %d\n",pCompPrivate->curState); 637 if (nParam == OMX_StateLoaded) { 638 pCompPrivate->bLoadedCommandPending = OMX_TRUE; 639 } 640 if(pCompPrivate->curState == OMX_StateLoaded) { 641 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) { 642 pCompPrivate->cbInfo.EventHandler ( 643 pHandle, 644 pHandle->pApplicationPrivate, 645 OMX_EventError, 646 OMX_ErrorIncorrectStateTransition, 647 OMX_TI_ErrorMinor, 648 NULL); 649 goto EXIT; 650 } 651 652 if(nParam == OMX_StateInvalid) { 653 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 654 pCompPrivate->curState = OMX_StateInvalid; 655 pCompPrivate->cbInfo.EventHandler ( 656 pHandle, 657 pHandle->pApplicationPrivate, 658 OMX_EventError, 659 OMX_ErrorInvalidState, 660 OMX_TI_ErrorMinor, 661 NULL); 662 goto EXIT; 663 } 664 } 665 break; 666 case OMX_CommandFlush: 667 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 668 if(nParam > 1 && nParam != -1) { 669 eError = OMX_ErrorBadPortIndex; 670 goto EXIT; 671 } 672 673 break; 674 case OMX_CommandPortDisable: 675 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 676 break; 677 case OMX_CommandPortEnable: 678 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 679 break; 680 case OMX_CommandMarkBuffer: 681 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 682 if (nParam > 0) { 683 eError = OMX_ErrorBadPortIndex; 684 goto EXIT; 685 } 686 break; 687 default: 688 OMX_ERROR2(pCompPrivate->dbg, "Command Received Default \ 689 error\n"); 690 pCompPrivate->cbInfo.EventHandler (pHandle, 691 pHandle->pApplicationPrivate, 692 OMX_EventError, 693 OMX_ErrorUndefined, 694 OMX_TI_ErrorMinor, 695 "Invalid Command"); 696 break; 697 698 } 699 700 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 701 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 702 if (nRet == -1) { 703 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 704 eError = OMX_ErrorInsufficientResources; 705 goto EXIT; 706 } 707 708 if (Cmd == OMX_CommandMarkBuffer) { 709 nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, 710 sizeof(OMX_PTR)); 711 } 712 else { 713 nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, 714 sizeof(OMX_U32)); 715 } 716 717 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 718 OMX_PRINT2(pCompPrivate->dbg, "nRet = %d\n",nRet); 719 if (nRet == -1) { 720 OMX_PRINT1(pCompPrivate->dbg, "Inside SendCommand\n"); 721 eError = OMX_ErrorInsufficientResources; 722 goto EXIT; 723 } 724 725#ifdef DSP_RENDERING_ON 726 if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting) { 727 /* enable Tee device command*/ 728 cmd_data.hComponent = pHandle; 729 cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode; 730 cmd_data.param1 = 0; 731 cmd_data.param2 = 0; 732 cmd_data.streamID = 0; 733 if((write(pCompPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0) { 734 eError = OMX_ErrorHardware; 735 goto EXIT; 736 } 737 } 738#endif 739 740 EXIT: 741 return eError; 742} 743 744/*-------------------------------------------------------------------*/ 745/** 746 * GetParameter() Gets the current configurations of the component 747 * 748 * @param hComp handle for this instance of the component 749 * @param nParamIndex 750 * @param ComponentParameterStructure 751 * 752 * @retval OMX_NoError Success, ready to roll 753 * OMX_Error_BadParameter The input parameter pointer is null 754 **/ 755/*-------------------------------------------------------------------*/ 756 757static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp, 758 OMX_INDEXTYPE nParamIndex, 759 OMX_PTR ComponentParameterStructure) 760{ 761 762 OMX_ERRORTYPE eError = OMX_ErrorNone; 763 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate; 764 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure; 765 766 767 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 768 OMX_PRINT1 (pComponentPrivate->dbg, "Entering with index:: %x\n",nParamIndex); 769 pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure; 770 771 if (pParameterStructure == NULL) { 772 eError = OMX_ErrorBadParameter; 773 goto EXIT; 774 775 } 776 OMX_PRINT2(pComponentPrivate->dbg, "pParameterStructure = %p\n",pParameterStructure); 777 778 779#ifdef _ERROR_PROPAGATION__ 780 if (pComponentPrivate->curState == OMX_StateInvalid){ 781 eError = OMX_ErrorInvalidState; 782 goto EXIT; 783 } 784#else 785 if(pComponentPrivate->curState == OMX_StateInvalid) { 786 pComponentPrivate->cbInfo.EventHandler( 787 hComp, 788 ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate, 789 OMX_EventError, 790 OMX_ErrorIncorrectStateOperation, 791 OMX_TI_ErrorMinor, 792 NULL); 793 } 794#endif 795 switch(nParamIndex){ 796 797 case OMX_IndexParamAudioInit: 798 OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioInit\n"); 799 memcpy(ComponentParameterStructure, &pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE)); 800 break; 801 802 case OMX_IndexParamPortDefinition: 803 OMX_PRDSP2(pComponentPrivate->dbg, "pParameterStructure->nPortIndex = %ld\n",pParameterStructure->nPortIndex); 804 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex = %ld\n",pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex); 805 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 806 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex) { 807 808 memcpy(ComponentParameterStructure, 809 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT], 810 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) 811 ); 812 813 } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 814 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nPortIndex) { 815 816 memcpy(ComponentParameterStructure, 817 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT], 818 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) 819 ); 820 821 } else { 822 823 eError = OMX_ErrorBadPortIndex; 824 } 825 break; 826 827 case OMX_IndexParamAudioPortFormat: 828 OMX_PRCOMM2(pComponentPrivate->dbg, "nPortIndex = %ld\n",((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex); 829 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->sInPortFormat.nPortIndex= %ld\n",pComponentPrivate->sInPortFormat.nPortIndex); 830 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->sOutPortFormat.nPortIndex= %ld\n",pComponentPrivate->sOutPortFormat.nPortIndex); 831 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex) { 832 833 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > 834 pComponentPrivate->sInPortFormat.nPortIndex) { 835 836 eError = OMX_ErrorNoMore; 837 } 838 else { 839 memcpy(ComponentParameterStructure, &pComponentPrivate->sInPortFormat, 840 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 841 } 842 } 843 else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == 844 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nPortIndex){ 845 846 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > pComponentPrivate->sOutPortFormat.nPortIndex) { 847 eError = OMX_ErrorNoMore; 848 } 849 else { 850 memcpy(ComponentParameterStructure, &pComponentPrivate->sOutPortFormat, 851 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 852 } 853 } 854 else { 855 eError = OMX_ErrorBadPortIndex; 856 } 857 break; 858 859 case OMX_IndexParamAudioAmr: 860 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 861 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex) { 862 OMX_PRINT1(pComponentPrivate->dbg, "Inside the GetParameter\n"); 863 memcpy(ComponentParameterStructure,pComponentPrivate->wbamrParams[WBAMR_DEC_INPUT_PORT], 864 sizeof(OMX_AUDIO_PARAM_AMRTYPE)); 865 } 866 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 867 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nPortIndex) { 868 OMX_PRINT1(pComponentPrivate->dbg, "Inside the GetParameter\n"); 869 memcpy(ComponentParameterStructure, pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT], 870 sizeof(OMX_AUDIO_PARAM_AMRTYPE)); 871 } 872 else { 873 eError = OMX_ErrorBadPortIndex; 874 } 875 break; 876 877 878 case OMX_IndexParamAudioPcm: 879 if(((OMX_AUDIO_PARAM_AMRTYPE *)(ComponentParameterStructure))->nPortIndex == WBAMR_DEC_OUTPUT_PORT){ 880 memcpy(ComponentParameterStructure, pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 881 } 882 else { 883 eError = OMX_ErrorBadPortIndex; 884 } 885 break; 886 case OMX_IndexParamPriorityMgmt: 887 if (pComponentPrivate->pPriorityMgmt == NULL) { 888 eError = OMX_ErrorBadPortIndex; 889 break; 890 } 891 memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE)); 892 break; 893 894 case OMX_IndexParamCompBufferSupplier: 895 if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirInput) { 896 OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamCompBufferSupplier \n"); 897 /* memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */ 898 } 899 else if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == OMX_DirOutput) { 900 OMX_PRINT1(pComponentPrivate->dbg, "OMX_IndexParamCompBufferSupplier \n"); 901 /*memcpy(ComponentParameterStructure, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); */ 902 } 903 else { 904 OMX_ERROR2(pComponentPrivate->dbg, "OMX_ErrorBadPortIndex from GetParameter"); 905 eError = OMX_ErrorBadPortIndex; 906 } 907 break; 908 909 case OMX_IndexParamVideoInit: 910 break; 911 912 case OMX_IndexParamImageInit: 913 break; 914 915 case OMX_IndexParamOtherInit: 916 break; 917 case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX: 918 { 919 OMX_PRINT2(pComponentPrivate->dbg, "Entering PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n"); 920 PV_OMXComponentCapabilityFlagsType* pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure; 921 if (NULL == pCap_flags) 922 { 923 OMX_ERROR4(pComponentPrivate->dbg, "ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n"); 924 eError = OMX_ErrorBadParameter; 925 goto EXIT; 926 } 927 OMX_PRINT2(pComponentPrivate->dbg, "Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX\n"); 928 memcpy(pCap_flags, &(pComponentPrivate->iPVCapabilityFlags), sizeof(PV_OMXComponentCapabilityFlagsType)); 929 eError = OMX_ErrorNone; 930 } 931 break; 932 933 default: 934 eError = OMX_ErrorUnsupportedIndex; 935 break; 936 } 937 EXIT: 938 OMX_PRINT1(pComponentPrivate->dbg, "Exiting - %x\n",nParamIndex); 939 return eError; 940} 941 942/*-------------------------------------------------------------------*/ 943/** 944 * SetParameter() Sets configuration paramets to the component 945 * 946 * @param hComp handle for this instance of the component 947 * @param nParamIndex 948 * @param pCompParam 949 * 950 * @retval OMX_NoError Success, ready to roll 951 * OMX_Error_BadParameter The input parameter pointer is null 952 **/ 953/*-------------------------------------------------------------------*/ 954 955static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, 956 OMX_INDEXTYPE nParamIndex, 957 OMX_PTR pCompParam) 958{ 959 OMX_ERRORTYPE eError = OMX_ErrorNone; 960 OMX_BOOL temp_bEnabled,temp_bPopulated; 961 OMX_PARAM_COMPONENTROLETYPE *pRole; 962 OMX_AUDIO_PARAM_PCMMODETYPE *amr_op; 963 OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier; 964 965 OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp; 966 967 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate; 968 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 969 970 if (pCompParam == NULL) { 971 eError = OMX_ErrorBadParameter; 972 goto EXIT; 973 } 974 975#ifdef _ERROR_PROPAGATION__ 976 if (pComponentPrivate->curState == OMX_StateInvalid){ 977 eError = OMX_ErrorInvalidState; 978 goto EXIT; 979 } 980#endif 981 switch(nParamIndex) { 982 case OMX_IndexParamAudioPortFormat: 983 { 984 OMX_PARAM_PORTDEFINITIONTYPE *pComponentParam = 985 (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam; 986 987 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentParam->nPortIndex = %ld\n",pComponentParam->nPortIndex); 988 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentParam->nBufferCountActual= %ld\n",pComponentParam->nBufferCountActual); 989 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentParam->nBufferSize= %ld\n",pComponentParam->nBufferSize); 990 991 /* 0 means Input port */ 992 if (pComponentParam->nPortIndex == 0) { 993 994 memcpy(&pComponentPrivate->sInPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 995 996 } else if (pComponentParam->nPortIndex == 1) { 997 /* 1 means Output port */ 998 memcpy(&pComponentPrivate->sOutPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 999 1000 }else { 1001 OMX_ERROR4(pComponentPrivate->dbg, "Wrong Port Index Parameter\n"); 1002 OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line\n"); 1003 eError = OMX_ErrorBadParameter; 1004 goto EXIT; 1005 } 1006 } 1007 break; 1008 case OMX_IndexParamAudioAmr: 1009 { 1010 OMX_AUDIO_PARAM_AMRTYPE *pCompAmrParam = 1011 (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam; 1012 1013 if (OMX_AUDIO_AMRFrameFormatConformance == pCompAmrParam->eAMRFrameFormat) 1014 pComponentPrivate->mimemode = 0; 1015 else if (OMX_AUDIO_AMRFrameFormatIF2 == pCompAmrParam->eAMRFrameFormat) 1016 pComponentPrivate->mimemode = 2; 1017 else if (OMX_AUDIO_AMRFrameFormatRTPPayload == pCompAmrParam->eAMRFrameFormat){ 1018 pComponentPrivate->mimemode = 1; 1019 pComponentPrivate->using_rtsp = 1; 1020 } 1021 else 1022 pComponentPrivate->mimemode = 1; /*MIME Format*/ 1023 1024 /* 0 means Input port */ 1025 if(pCompAmrParam->nPortIndex == 0) { 1026 memcpy(((WBAMR_DEC_COMPONENT_PRIVATE*) 1027 pHandle->pComponentPrivate)->wbamrParams[WBAMR_DEC_INPUT_PORT], 1028 pCompAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE)); 1029 1030 } else if (pCompAmrParam->nPortIndex == 1) { 1031 /* 1 means Output port */ 1032 memcpy(((WBAMR_DEC_COMPONENT_PRIVATE *) 1033 pHandle->pComponentPrivate)->wbamrParams[WBAMR_DEC_OUTPUT_PORT], 1034 pCompAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE)); 1035 } 1036 else { 1037 eError = OMX_ErrorBadPortIndex; 1038 } 1039 } 1040 break; 1041 1042 case OMX_IndexParamPortDefinition: 1043 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1044 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex) { 1045 temp_bEnabled = pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bEnabled; 1046 temp_bPopulated = pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bPopulated; 1047 memcpy(pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT], 1048 pCompParam, 1049 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) 1050 ); 1051 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bEnabled = temp_bEnabled; 1052 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bPopulated = temp_bPopulated; 1053 } 1054 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1055 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nPortIndex) { 1056 temp_bEnabled = pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled; 1057 temp_bPopulated = pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bPopulated; 1058 memcpy(pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT], 1059 pCompParam, 1060 sizeof(OMX_PARAM_PORTDEFINITIONTYPE) 1061 ); 1062 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled = temp_bEnabled; 1063 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bPopulated = temp_bPopulated; 1064 1065 } 1066 else { 1067 eError = OMX_ErrorBadPortIndex; 1068 } 1069 break; 1070 case OMX_IndexParamPriorityMgmt: 1071 if (pComponentPrivate->curState != OMX_StateLoaded) { 1072 eError = OMX_ErrorIncorrectStateOperation; 1073 } 1074 if (pComponentPrivate->pPriorityMgmt == NULL) { 1075 eError = OMX_ErrorBadParameter; 1076 break; 1077 } 1078 memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE)); 1079 break; 1080 1081 case OMX_IndexParamStandardComponentRole: 1082 if (pCompParam) { 1083 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam; 1084 memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 1085 } else { 1086 eError = OMX_ErrorBadParameter; 1087 } 1088 break; 1089 1090 case OMX_IndexParamAudioPcm: 1091 if(pCompParam){ 1092 amr_op = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam; 1093 memcpy(pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT], amr_op, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 1094 } 1095 else{ 1096 eError = OMX_ErrorBadParameter; 1097 } 1098 break; 1099 1100 case OMX_IndexParamCompBufferSupplier: 1101 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1102 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nPortIndex) { 1103 OMX_PRINT2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n"); 1104 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput; 1105 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1106 1107 } 1108 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 1109 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nPortIndex) { 1110 OMX_PRINT2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamCompBufferSupplier \n"); 1111 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput; 1112 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 1113 } 1114 else { 1115 OMX_ERROR2(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter"); 1116 eError = OMX_ErrorBadPortIndex; 1117 } 1118 break; 1119 1120 default: 1121 break; 1122 1123 } 1124 EXIT: 1125 return eError; 1126} 1127/*-------------------------------------------------------------------*/ 1128/** 1129 * GetConfig() Gets the current configuration of to the component 1130 * 1131 * @param hComp handle for this instance of the component 1132 * @param nConfigIndex 1133 * @param ComponentConfigStructure 1134 * 1135 * @retval OMX_NoError Success, ready to roll 1136 * OMX_Error_BadParameter The input parameter pointer is null 1137 **/ 1138/*-------------------------------------------------------------------*/ 1139 1140static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 1141 OMX_INDEXTYPE nConfigIndex, 1142 OMX_PTR ComponentConfigStructure) 1143{ 1144 OMX_ERRORTYPE eError = OMX_ErrorNone; 1145 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp; 1146 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = 1147 (WBAMR_DEC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 1148 TI_OMX_STREAM_INFO *streamInfo; 1149 1150 OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO); 1151#ifdef _ERROR_PROPAGATION__ 1152 if (pComponentPrivate->curState == OMX_StateInvalid){ 1153 eError = OMX_ErrorInvalidState; 1154 goto EXIT; 1155 } 1156#endif 1157 if(nConfigIndex == OMX_IndexCustomWbAmrDecStreamIDConfig){ 1158 streamInfo->streamId = pComponentPrivate->streamID; 1159 memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO)); 1160 } 1161 else if(nConfigIndex == OMX_IndexCustomDebug){ 1162 OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure); 1163 } 1164 1165 EXIT: 1166 OMX_MEMFREE_STRUCT(streamInfo); 1167 OMX_PRINT1(pComponentPrivate->dbg, "Exiting GetConfig. Returning = 0x%x\n",eError); 1168 return eError; 1169} 1170/*-------------------------------------------------------------------*/ 1171/** 1172 * SetConfig() Sets the configraiton to the component 1173 * 1174 * @param hComp handle for this instance of the component 1175 * @param nConfigIndex 1176 * @param ComponentConfigStructure 1177 * 1178 * @retval OMX_NoError Success, ready to roll 1179 * OMX_Error_BadParameter The input parameter pointer is null 1180 **/ 1181/*-------------------------------------------------------------------*/ 1182 1183static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 1184 OMX_INDEXTYPE nConfigIndex, 1185 OMX_PTR ComponentConfigStructure) 1186{ 1187 OMX_ERRORTYPE eError = OMX_ErrorNone; 1188 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp; 1189 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1190 OMX_S16 *customFlag = NULL; 1191 TI_OMX_DSP_DEFINITION *configData; 1192 TI_OMX_DATAPATH dataPath; 1193#ifdef DSP_RENDERING_ON 1194 OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL; 1195 OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL; 1196#endif 1197 OMX_PRINT1(pComponentPrivate->dbg, "Entering SetConfig\n"); 1198 if (pHandle == NULL) { 1199 OMX_ERROR4(pComponentPrivate->dbg, "Invalid HANDLE OMX_ErrorBadParameter \n"); 1200 eError = OMX_ErrorBadParameter; 1201 goto EXIT; 1202 } 1203 1204 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1205#ifdef _ERROR_PROPAGATION__ 1206 if (pComponentPrivate->curState == OMX_StateInvalid){ 1207 eError = OMX_ErrorInvalidState; 1208 goto EXIT; 1209 } 1210#endif 1211 switch (nConfigIndex) { 1212 case OMX_IndexCustomWbAmrDecHeaderInfoConfig: 1213 { 1214 OMX_PRDSP2(pComponentPrivate->dbg, "SetConfig OMX_IndexCustomWbAmrDecHeaderInfoConfig \n"); 1215 configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure; 1216 if (configData == NULL) { 1217 eError = OMX_ErrorBadParameter; 1218 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter from SetConfig\n"); 1219 goto EXIT; 1220 } 1221 pComponentPrivate->acdnmode = configData->acousticMode; 1222 pComponentPrivate->dasfmode = configData->dasfMode; 1223 if( 2 == pComponentPrivate->dasfmode ){ 1224 pComponentPrivate->dasfmode--; 1225 } 1226 1227 if (pComponentPrivate->dasfmode ){ 1228 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled = 0; 1229 } 1230 1231 pComponentPrivate->streamID = configData->streamId; 1232 break; 1233 } 1234 1235 case OMX_IndexCustomWbAmrDecDataPath: 1236 customFlag = (OMX_S16*)ComponentConfigStructure; 1237 if (customFlag == NULL) { 1238 eError = OMX_ErrorBadParameter; 1239 goto EXIT; 1240 } 1241 1242 switch(dataPath) { 1243 case DATAPATH_APPLICATION: 1244 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, pComponentPrivate->streamID); 1245 break; 1246 1247 case DATAPATH_APPLICATION_RTMIXER: 1248 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING); 1249 break; 1250 1251 case DATAPATH_ACDN: 1252 strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING); 1253 break; 1254 1255 default: 1256 break; 1257 1258 } 1259 break; 1260 1261 case OMX_IndexCustomModeDasfConfig_WBAMRDEC: 1262 { 1263 OMX_PRDSP2(pComponentPrivate->dbg, "SetConfig OMX_IndexCustomModeDasfConfig \n"); 1264 customFlag = (OMX_S16*)ComponentConfigStructure; 1265 if (customFlag == NULL) { 1266 eError = OMX_ErrorBadParameter; 1267 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter from SetConfig\n"); 1268 goto EXIT; 1269 } 1270 pComponentPrivate->dasfmode = *customFlag; 1271 if( 2 == pComponentPrivate->dasfmode ){ 1272 pComponentPrivate->dasfmode--; 1273 } 1274 if (pComponentPrivate->dasfmode){ 1275 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled = 0; 1276 } 1277 break; 1278 } 1279 case OMX_IndexCustomModeMimeConfig_WBAMRDEC: 1280 { 1281 OMX_PRDSP2(pComponentPrivate->dbg, "SetConfig OMX_IndexCustomModeMimeConfig \n"); 1282 customFlag = (OMX_S16*)ComponentConfigStructure; 1283 if (customFlag == NULL) 1284 { 1285 eError = OMX_ErrorBadParameter; 1286 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter from SetConfig\n"); 1287 goto EXIT; 1288 } 1289 pComponentPrivate->mimemode = *customFlag; 1290 break; 1291 } 1292 case OMX_IndexCustomWbAmrDecNextFrameLost: 1293 { 1294 pComponentPrivate->bFrameLost=OMX_TRUE; 1295 break; 1296 } 1297 case OMX_IndexConfigAudioMute: 1298 { 1299#ifdef DSP_RENDERING_ON 1300 pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure; 1301 OMX_PRDSP2(pComponentPrivate->dbg, "Set Mute/Unmute for playback stream\n"); 1302 cmd_data.hComponent = hComp; 1303 if(pMuteStructure->bMute == OMX_TRUE) 1304 { 1305 OMX_PRSTATE2(pComponentPrivate->dbg, "Mute the playback stream\n"); 1306 cmd_data.AM_Cmd = AM_CommandStreamMute; 1307 } 1308 else 1309 { 1310 OMX_PRSTATE2(pComponentPrivate->dbg, "unMute the playback stream\n"); 1311 cmd_data.AM_Cmd = AM_CommandStreamUnMute; 1312 } 1313 cmd_data.param1 = 0; 1314 cmd_data.param2 = 0; 1315 cmd_data.streamID = pComponentPrivate->streamID; 1316 if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0) 1317 { 1318 OMX_ERROR4(pComponentPrivate->dbg, "[WBAMR decoder] - fail to send Mute command to audio manager\n"); 1319 } 1320#endif 1321 break; 1322 } 1323 case OMX_IndexConfigAudioVolume: 1324 { 1325#ifdef DSP_RENDERING_ON 1326 pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure; 1327 OMX_PRDSP2(pComponentPrivate->dbg, "Set volume for playback stream\n"); 1328 cmd_data.hComponent = hComp; 1329 cmd_data.AM_Cmd = AM_CommandSWGain; 1330 cmd_data.param1 = pVolumeStructure->sVolume.nValue; 1331 cmd_data.param2 = 0; 1332 cmd_data.streamID = pComponentPrivate->streamID; 1333 1334 if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0) 1335 { 1336 OMX_ERROR4(pComponentPrivate->dbg, "[WBAMR decoder] - fail to send Volume command to audio manager\n"); 1337 } 1338 1339#endif 1340 break; 1341 } 1342 case OMX_IndexCustomDebug: 1343 { 1344 OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure); 1345 break; 1346 } 1347 default: 1348 eError = OMX_ErrorUnsupportedIndex; 1349 break; 1350 } 1351 EXIT: 1352 OMX_PRINT1(pComponentPrivate->dbg, "Exiting SetConfig\n"); 1353 OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError); 1354 return eError; 1355} 1356 1357/*-------------------------------------------------------------------*/ 1358/** 1359 * GetState() Gets the current state of the component 1360 * 1361 * @param pCompomponent handle for this instance of the component 1362 * @param pState 1363 * 1364 * @retval OMX_NoError Success, ready to roll 1365 * OMX_Error_BadParameter The input parameter pointer is null 1366 **/ 1367/*-------------------------------------------------------------------*/ 1368 1369static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState) 1370{ 1371 OMX_ERRORTYPE error = OMX_ErrorUndefined; 1372 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1373 1374 if (!pState) { 1375 error = OMX_ErrorBadParameter; 1376 OMXDBG_PRINT(stderr, ERROR, 4, 0, "About to return OMX_ErrorBadParameter on line\n"); 1377 goto EXIT; 1378 } 1379 1380 if (pHandle && pHandle->pComponentPrivate) { 1381 *pState = ((WBAMR_DEC_COMPONENT_PRIVATE*) 1382 pHandle->pComponentPrivate)->curState; 1383 } else { 1384 *pState = OMX_StateLoaded; 1385 } 1386 1387 error = OMX_ErrorNone; 1388 1389 EXIT: 1390 return error; 1391} 1392 1393/*-------------------------------------------------------------------*/ 1394/** 1395 * EmptyThisBuffer() This callback is used to send the input buffer to 1396 * component 1397 * 1398 * @param pComponent handle for this instance of the component 1399 * @param nPortIndex input port index 1400 * @param pBuffer buffer to be sent to codec 1401 * 1402 * @retval OMX_NoError Success, ready to roll 1403 * OMX_Error_BadParameter The input parameter pointer is null 1404 **/ 1405/*-------------------------------------------------------------------*/ 1406 1407static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent, 1408 OMX_BUFFERHEADERTYPE* pBuffer) 1409{ 1410 OMX_ERRORTYPE eError = OMX_ErrorNone; 1411 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1412 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = 1413 (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1414 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef; 1415 1416 int ret; 1417 pPortDef = ((WBAMR_DEC_COMPONENT_PRIVATE*) 1418 pComponentPrivate)->pPortDef[WBAMR_DEC_INPUT_PORT]; 1419#ifdef _ERROR_PROPAGATION__ 1420 if (pComponentPrivate->curState == OMX_StateInvalid){ 1421 eError = OMX_ErrorInvalidState; 1422 goto EXIT; 1423 } 1424#endif 1425 1426#ifdef __PERF_INSTRUMENTATION__ 1427 PERF_ReceivedFrame(pComponentPrivate->pPERF, 1428 pBuffer->pBuffer, 1429 pBuffer->nFilledLen, 1430 PERF_ModuleHLMM); 1431#endif 1432 1433 if(!pPortDef->bEnabled) { 1434 eError = OMX_ErrorIncorrectStateOperation; 1435 goto EXIT; 1436 } 1437 1438 if (pBuffer == NULL) { 1439 eError = OMX_ErrorBadParameter; 1440 OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line\n"); 1441 goto EXIT; 1442 } 1443 1444 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1445 eError = OMX_ErrorBadParameter; 1446 goto EXIT; 1447 } 1448 1449 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1450 eError = OMX_ErrorVersionMismatch; 1451 goto EXIT; 1452 } 1453 1454 if (pBuffer->nInputPortIndex != WBAMR_DEC_INPUT_PORT) { 1455 eError = OMX_ErrorBadPortIndex; 1456 goto EXIT; 1457 } 1458 1459 if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) { 1460 eError = OMX_ErrorIncorrectStateOperation; 1461 goto EXIT; 1462 } 1463 1464 1465 1466 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1467 OMX_PRBUFFER2(pComponentPrivate->dbg, "Component Sending Filled ip buff %p \ 1468 to Component Thread\n",pBuffer); 1469 OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1470 1471 1472 pComponentPrivate->app_nBuf--; 1473 1474 pComponentPrivate->pMarkData = pBuffer->pMarkData; 1475 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent; 1476 1477 pComponentPrivate->nUnhandledEmptyThisBuffers++; 1478 1479 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, 1480 sizeof(OMX_BUFFERHEADERTYPE*)); 1481 if (ret == -1) { 1482 OMX_ERROR4(pComponentPrivate->dbg, "Error in Writing to the Data pipe\n"); 1483 eError = OMX_ErrorHardware; 1484 goto EXIT; 1485 } 1486 pComponentPrivate->nEmptyThisBufferCount++; 1487 1488 EXIT: 1489 return eError; 1490} 1491/*-------------------------------------------------------------------*/ 1492/** 1493 * FillThisBuffer() This callback is used to send the output buffer to 1494 * the component 1495 * 1496 * @param pComponent handle for this instance of the component 1497 * @param nPortIndex output port number 1498 * @param pBuffer buffer to be sent to codec 1499 * 1500 * @retval OMX_NoError Success, ready to roll 1501 * OMX_Error_BadParameter The input parameter pointer is null 1502 **/ 1503/*-------------------------------------------------------------------*/ 1504 1505static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent, 1506 OMX_BUFFERHEADERTYPE* pBuffer) 1507{ 1508 OMX_ERRORTYPE eError = OMX_ErrorNone; 1509 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1510 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = 1511 (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1512 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef; 1513 1514 pPortDef = ((WBAMR_DEC_COMPONENT_PRIVATE*) 1515 pComponentPrivate)->pPortDef[WBAMR_DEC_OUTPUT_PORT]; 1516#ifdef _ERROR_PROPAGATION__ 1517 if (pComponentPrivate->curState == OMX_StateInvalid){ 1518 eError = OMX_ErrorInvalidState; 1519 goto EXIT; 1520 } 1521#endif 1522#ifdef __PERF_INSTRUMENTATION__ 1523 PERF_ReceivedFrame(pComponentPrivate->pPERF, 1524 pBuffer->pBuffer, 1525 0, 1526 PERF_ModuleHLMM); 1527#endif 1528 1529 if(!pPortDef->bEnabled) { 1530 eError = OMX_ErrorIncorrectStateOperation; 1531 goto EXIT; 1532 } 1533 1534 if (pBuffer == NULL) { 1535 eError = OMX_ErrorBadParameter; 1536 OMX_ERROR4(pComponentPrivate->dbg, "About to return OMX_ErrorBadParameter on line\n"); 1537 goto EXIT; 1538 } 1539 1540 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1541 eError = OMX_ErrorBadParameter; 1542 goto EXIT; 1543 } 1544 1545 1546 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1547 eError = OMX_ErrorVersionMismatch; 1548 goto EXIT; 1549 } 1550 1551 if (pBuffer->nOutputPortIndex != WBAMR_DEC_OUTPUT_PORT) { 1552 eError = OMX_ErrorBadPortIndex; 1553 goto EXIT; 1554 } 1555 1556 if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) { 1557 eError = OMX_ErrorIncorrectStateOperation; 1558 goto EXIT; 1559 } 1560 1561 1562 pComponentPrivate->app_nBuf--; 1563 OMX_PRBUFFER2(pComponentPrivate->dbg, "Decrementing app_nBuf = %ld\n",pComponentPrivate->app_nBuf); 1564 1565 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pMarkBuf = %p\n",pComponentPrivate->pMarkBuf); 1566 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate->pMarkData = %p\n",pComponentPrivate->pMarkData); 1567 if(pComponentPrivate->pMarkBuf){ 1568 pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent; 1569 pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData; 1570 pComponentPrivate->pMarkBuf = NULL; 1571 } 1572 1573 if (pComponentPrivate->pMarkData) { 1574 pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent; 1575 pBuffer->pMarkData = pComponentPrivate->pMarkData; 1576 pComponentPrivate->pMarkData = NULL; 1577 } 1578 1579 OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1580 OMX_PRBUFFER1(pComponentPrivate->dbg, "Component Sending Emptied op buff %p \ 1581 to Component Thread\n",pBuffer); 1582 OMX_PRBUFFER1(pComponentPrivate->dbg, "\n------------------------------------------\n\n"); 1583 1584 pComponentPrivate->nUnhandledFillThisBuffers++; 1585 1586 write (pComponentPrivate->dataPipe[1], &pBuffer, 1587 sizeof (OMX_BUFFERHEADERTYPE*)); 1588 pComponentPrivate->nFillThisBufferCount++; 1589 1590 EXIT: 1591 return eError; 1592} 1593/*-------------------------------------------------------------------*/ 1594/** 1595 * OMX_ComponentDeinit() this methold will de init the component 1596 * 1597 * @param pComp handle for this instance of the component 1598 * 1599 * @retval OMX_NoError Success, ready to roll 1600 * OMX_Error_BadParameter The input parameter pointer is null 1601 **/ 1602/*-------------------------------------------------------------------*/ 1603 1604static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle) 1605{ 1606 OMX_ERRORTYPE eError = OMX_ErrorNone; 1607 1608 /* inform audio manager to remove the streamID*/ 1609 /* compose the data */ 1610 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 1611 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = 1612 (WBAMR_DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate; 1613 struct OMX_TI_Debug dbg; 1614 dbg = pComponentPrivate->dbg; 1615 1616 OMX_PRINT1(dbg, "ComponentDeInit\n"); 1617 1618#ifdef __PERF_INSTRUMENTATION__ 1619 PERF_Boundary(pComponentPrivate->pPERF, 1620 PERF_BoundaryStart | PERF_BoundaryCleanup); 1621#endif 1622#ifdef DSP_RENDERING_ON 1623 close(pComponentPrivate->fdwrite); 1624 close(pComponentPrivate->fdread); 1625#endif 1626 1627#ifdef RESOURCE_MANAGER_ENABLED 1628 /*RM*/ 1629 eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_WBAMR_Decoder_COMPONENT, 0, 3456, NULL); 1630 1631 if (eError != OMX_ErrorNone) { 1632 OMX_ERROR4(dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 1633 } 1634 eError = RMProxy_Deinitalize(); 1635 if (eError != OMX_ErrorNone) { 1636 OMX_ERROR4(dbg, "Error from RMProxy_Deinitalize\n"); 1637 } 1638 /*RM END*/ 1639#endif 1640 1641 OMX_PRINT1(dbg, "ComponentDeInit\n"); 1642 pComponentPrivate->bIsStopping = 1; 1643 eError = WBAMR_DEC_StopComponentThread(pHandle); 1644 /* Wait for thread to exit so we can get the status into "error" */ 1645 1646 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList); 1647 1648 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 1649 1650 /* close the pipe handles */ 1651 WBAMR_DEC_FreeCompResources(pHandle); 1652 1653#ifdef __PERF_INSTRUMENTATION__ 1654 PERF_Boundary(pComponentPrivate->pPERF, 1655 PERF_BoundaryComplete | PERF_BoundaryCleanup); 1656 PERF_Done(pComponentPrivate->pPERF); 1657#endif 1658 OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString); 1659 OMX_PRINT2(dbg, "After WBAMR_DEC_FreeCompResources\n"); 1660 1661 OMX_MEMFREE_STRUCT(pComponentPrivate); 1662 OMX_DBG_CLOSE(dbg); 1663 return eError; 1664} 1665 1666/*-------------------------------------------------------------------*/ 1667/** 1668 * ComponentTunnelRequest() this method is not implemented in 1.5 1669 * 1670 * This method will update application callbacks 1671 * the application. 1672 * 1673 * @param pComp handle for this instance of the component 1674 * @param pCallBacks application callbacks 1675 * @param ptr 1676 * 1677 * @retval OMX_NoError Success, ready to roll 1678 * OMX_Error_BadParameter The input parameter pointer is null 1679 **/ 1680/*-------------------------------------------------------------------*/ 1681 1682static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 1683 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 1684 OMX_U32 nTunneledPort, 1685 OMX_TUNNELSETUPTYPE* pTunnelSetup) 1686{ 1687 OMX_ERRORTYPE eError = OMX_ErrorNone; 1688 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Inside the ComponentTunnelRequest\n"); 1689 eError = OMX_ErrorNotImplemented; 1690 return eError; 1691} 1692 1693/*-------------------------------------------------------------------*/ 1694/** 1695 * AllocateBuffer() 1696 1697 * @param pComp handle for this instance of the component 1698 * @param pCallBacks application callbacks 1699 * @param ptr 1700 * 1701 * @retval OMX_NoError Success, ready to roll 1702 * OMX_Error_BadParameter The input parameter pointer is null 1703 **/ 1704/*-------------------------------------------------------------------*/ 1705 1706static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 1707 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 1708 OMX_IN OMX_U32 nPortIndex, 1709 OMX_IN OMX_PTR pAppPrivate, 1710 OMX_IN OMX_U32 nSizeBytes) 1711 1712{ 1713 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef; 1714 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate; 1715 OMX_ERRORTYPE eError = OMX_ErrorNone; 1716 OMX_BUFFERHEADERTYPE *pBufferHeader; 1717 1718 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *) 1719 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1720 1721 pPortDef = ((WBAMR_DEC_COMPONENT_PRIVATE*) 1722 pComponentPrivate)->pPortDef[nPortIndex]; 1723#ifdef _ERROR_PROPAGATION__ 1724 if (pComponentPrivate->curState == OMX_StateInvalid){ 1725 eError = OMX_ErrorInvalidState; 1726 goto EXIT; 1727 } 1728#endif 1729 OMX_PRCOMM1(pComponentPrivate->dbg, "pPortDef = %p\n",pPortDef); 1730 OMX_PRCOMM1(pComponentPrivate->dbg, "pPortDef->bEnabled = %d\n",pPortDef->bEnabled); 1731 1732 OMX_PRCOMM2(pComponentPrivate->dbg, "pPortDef->bEnabled = %d\n", pPortDef->bEnabled); 1733 while (!pPortDef->bEnabled) { 1734 pComponentPrivate->AlloBuf_waitingsignal = 1; 1735#ifndef UNDER_CE 1736 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1737 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex); 1738 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1739#else 1740 OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event)); 1741#endif 1742 } 1743 1744 OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE); 1745 OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes,OMX_U8); 1746 1747 if (nPortIndex == WBAMR_DEC_INPUT_PORT) { 1748 pBufferHeader->nInputPortIndex = nPortIndex; 1749 pBufferHeader->nOutputPortIndex = -1; 1750 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 1751 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 1752 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p\n",pComponentPrivate->pInputBufferList->numBuffers,pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]); 1753 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1; 1754 OMX_PRBUFFER2(pComponentPrivate->dbg, "Allocate WBAMR_DEC_Buffer Line\n"); 1755 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %d\n",pComponentPrivate->pInputBufferList->numBuffers); 1756 OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDef->nBufferCountMin = %ld\n",pPortDef->nBufferCountMin); 1757 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1758 OMX_PRCOMM2(pComponentPrivate->dbg, "Setting pPortDef->bPopulated = OMX_TRUE for input port\n"); 1759 pPortDef->bPopulated = OMX_TRUE; 1760 } 1761 } 1762 else if (nPortIndex == WBAMR_DEC_OUTPUT_PORT) { 1763 pBufferHeader->nInputPortIndex = -1; 1764 pBufferHeader->nOutputPortIndex = nPortIndex; 1765 OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, WBAMRDEC_BUFDATA); 1766 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1767 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1768 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p\n",pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]); 1769 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1; 1770 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1771 OMX_PRCOMM2(pComponentPrivate->dbg, "Setting pPortDef->bPopulated = OMX_TRUE for input port\n"); 1772 pPortDef->bPopulated = OMX_TRUE; 1773 } 1774 } 1775 else { 1776 eError = OMX_ErrorBadPortIndex; 1777 goto EXIT; 1778 } 1779 if((pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled)&& 1780 (pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bEnabled) && 1781 (pComponentPrivate->InLoaded_readytoidle)) 1782 { 1783 pComponentPrivate->InLoaded_readytoidle = 0; 1784#ifndef UNDER_CE 1785 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 1786 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 1787 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 1788#else 1789 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 1790#endif 1791 } 1792 pBufferHeader->pAppPrivate = pAppPrivate; 1793 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1794 pBufferHeader->nAllocLen = nSizeBytes; 1795 pBufferHeader->nVersion.s.nVersionMajor = WBAMR_DEC_MAJOR_VER; 1796 pBufferHeader->nVersion.s.nVersionMinor = WBAMR_DEC_MINOR_VER; 1797 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 1798 1799 1800 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 1801 *pBuffer = pBufferHeader; 1802 1803 if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) { 1804 SendCommand (pComponentPrivate->pHandle, 1805 OMX_CommandPortEnable, 1806 pComponentPrivate->bEnableCommandParam,NULL); 1807 } 1808 EXIT: 1809#ifdef __PERF_INSTRUMENTATION__ 1810 PERF_ReceivedBuffer(pComponentPrivate->pPERF, 1811 (*pBuffer)->pBuffer, nSizeBytes, 1812 PERF_ModuleMemory); 1813#endif 1814 OMX_PRINT1(pComponentPrivate->dbg, "AllocateBuffer returning %d\n",eError); 1815 return eError; 1816} 1817 1818/* ================================================================================= */ 1819/** 1820 * @fn FreeBuffer() description for FreeBuffer 1821 FreeBuffer(). 1822 Called by the OMX IL client to newfree a buffer. 1823 * 1824 * @see OMX_Core.h 1825 */ 1826/* ================================================================================ */ 1827 1828static OMX_ERRORTYPE FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 1829 OMX_IN OMX_U32 nPortIndex, 1830 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 1831{ 1832 OMX_ERRORTYPE eError = OMX_ErrorNone; 1833 WBAMR_DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL; 1834 OMX_BUFFERHEADERTYPE* buff; 1835 int i; 1836 int inputIndex = -1; 1837 int outputIndex = -1; 1838 OMX_COMPONENTTYPE *pHandle; 1839 1840 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *) 1841 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1842 1843 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 1844 for (i=0; i < WBAMR_DEC_MAX_NUM_OF_BUFS; i++) { 1845 buff = pComponentPrivate->pInputBufferList->pBufHdr[i]; 1846 if (buff == pBuffer) { 1847 OMX_PRBUFFER2(pComponentPrivate->dbg, "Found matching input buffer\n"); 1848 OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff); 1849 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 1850 inputIndex = i; 1851 break; 1852 } 1853 else { 1854 OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match\n"); 1855 OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff); 1856 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 1857 } 1858 } 1859 1860 for (i=0; i < WBAMR_DEC_MAX_NUM_OF_BUFS; i++) { 1861 buff = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 1862 if (buff == pBuffer) { 1863 OMX_PRBUFFER2(pComponentPrivate->dbg, "Found matching output buffer\n"); 1864 OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff); 1865 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 1866 outputIndex = i; 1867 break; 1868 } 1869 else { 1870 OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match\n"); 1871 OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p\n",buff); 1872 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer); 1873 } 1874 } 1875 1876 1877 if (inputIndex != -1) { 1878#ifdef __PERF_INSTRUMENTATION__ 1879 PERF_SendingBuffer(pComponentPrivate->pPERF, 1880 pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, 1881 pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen, 1882 PERF_ModuleMemory); 1883#endif 1884 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) { 1885 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8); 1886 } 1887 OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]); 1888 pComponentPrivate->pInputBufferList->numBuffers--; 1889 if (pComponentPrivate->pInputBufferList->numBuffers < 1890 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nBufferCountMin) { 1891 1892 pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bPopulated = OMX_FALSE; 1893 } 1894 if(pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bEnabled && 1895 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 1896 (pComponentPrivate->curState == OMX_StateIdle || 1897 pComponentPrivate->curState == OMX_StateExecuting || 1898 pComponentPrivate->curState == OMX_StatePause)) { 1899 pComponentPrivate->cbInfo.EventHandler( 1900 pHandle, pHandle->pApplicationPrivate, 1901 OMX_EventError, OMX_ErrorPortUnpopulated,OMX_TI_ErrorMinor, "Input Port Unpopulated"); 1902 } 1903 } 1904 else if (outputIndex != -1) { 1905#ifdef __PERF_INSTRUMENTATION__ 1906 PERF_SendingBuffer(pComponentPrivate->pPERF, 1907 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, 1908 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen, 1909 PERF_ModuleMemory); 1910#endif 1911 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) { 1912 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8); 1913 } 1914 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate); 1915 OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]); 1916 pComponentPrivate->pOutputBufferList->numBuffers--; 1917 1918 if (pComponentPrivate->pOutputBufferList->numBuffers < 1919 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->nBufferCountMin) { 1920 pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bPopulated = OMX_FALSE; 1921 } 1922 if(pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled && 1923 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 1924 (pComponentPrivate->curState == OMX_StateIdle || 1925 pComponentPrivate->curState == OMX_StateExecuting || 1926 pComponentPrivate->curState == OMX_StatePause)) { 1927 pComponentPrivate->cbInfo.EventHandler( 1928 pHandle, pHandle->pApplicationPrivate, 1929 OMX_EventError, OMX_ErrorPortUnpopulated,OMX_TI_ErrorMinor, "Output Port Unpopulated"); 1930 } 1931 } 1932 else { 1933 OMX_ERROR4(pComponentPrivate->dbg, "Returning OMX_ErrorBadParameter\n"); 1934 eError = OMX_ErrorBadParameter; 1935 } 1936 if ((!pComponentPrivate->pInputBufferList->numBuffers && 1937 !pComponentPrivate->pOutputBufferList->numBuffers) && 1938 pComponentPrivate->InIdle_goingtoloaded) 1939 { 1940 pComponentPrivate->InIdle_goingtoloaded = 0; 1941#ifndef UNDER_CE 1942 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1943 pthread_cond_signal(&pComponentPrivate->InIdle_threshold); 1944 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 1945#else 1946 OMX_SignalEvent(&(pComponentPrivate->InIdle_event)); 1947#endif 1948 } 1949 if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0)) { 1950 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL); 1951 } 1952 1953 OMX_PRINT1(pComponentPrivate->dbg, "Exiting FreeBuffer\n"); 1954 return eError; 1955} 1956 1957/* ================================================================================= */ 1958/** 1959 * @fn UseBuffer() description for UseBuffer 1960 UseBuffer(). 1961 Called by the OMX IL client to pass a buffer to be used. 1962 * 1963 * @see OMX_Core.h 1964 */ 1965/* ================================================================================ */ 1966 1967static OMX_ERRORTYPE UseBuffer (OMX_IN OMX_HANDLETYPE hComponent, 1968 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 1969 OMX_IN OMX_U32 nPortIndex, 1970 OMX_IN OMX_PTR pAppPrivate, 1971 OMX_IN OMX_U32 nSizeBytes, 1972 OMX_IN OMX_U8* pBuffer) 1973{ 1974 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef; 1975 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate; 1976 OMX_ERRORTYPE eError = OMX_ErrorNone; 1977 OMX_BUFFERHEADERTYPE *pBufferHeader; 1978 1979 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *) 1980 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1981 1982#ifdef _ERROR_PROPAGATION__ 1983 if (pComponentPrivate->curState == OMX_StateInvalid){ 1984 eError = OMX_ErrorInvalidState; 1985 goto EXIT; 1986 } 1987#endif 1988 pPortDef = ((WBAMR_DEC_COMPONENT_PRIVATE*) 1989 pComponentPrivate)->pPortDef[nPortIndex]; 1990 OMX_PRCOMM1(pComponentPrivate->dbg, "pPortDef->bPopulated = %d\n",pPortDef->bPopulated); 1991 1992 if(!pPortDef->bEnabled) { 1993 OMX_ERROR4(pComponentPrivate->dbg, "In UseBuffer\n"); 1994 eError = OMX_ErrorIncorrectStateOperation; 1995 goto EXIT; 1996 } 1997 1998 /*if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) { 1999 OMX_PRINT1(pComponentPrivate->dbg, "In UseBuffer\n"); 2000 eError = OMX_ErrorBadParameter; 2001 goto EXIT; 2002 }*/ 2003 2004 OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE); 2005 if (nPortIndex == WBAMR_DEC_OUTPUT_PORT) { 2006 pBufferHeader->nInputPortIndex = -1; 2007 pBufferHeader->nOutputPortIndex = nPortIndex; 2008 OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, WBAMRDEC_BUFDATA); 2009 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 2010 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 2011 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0; 2012 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 2013 pPortDef->bPopulated = OMX_TRUE; 2014 } 2015 } 2016 else { 2017 pBufferHeader->nInputPortIndex = nPortIndex; 2018 pBufferHeader->nOutputPortIndex = -1; 2019 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 2020 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 2021 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0; 2022 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 2023 pPortDef->bPopulated = OMX_TRUE; 2024 } 2025 } 2026 2027 if((pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]->bEnabled)&& 2028 (pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->bEnabled) && 2029 (pComponentPrivate->InLoaded_readytoidle)) 2030 { 2031 pComponentPrivate->InLoaded_readytoidle = 0; 2032#ifndef UNDER_CE 2033 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 2034 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 2035 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 2036#else 2037 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 2038#endif 2039 } 2040 pBufferHeader->pAppPrivate = pAppPrivate; 2041 pBufferHeader->pPlatformPrivate = pComponentPrivate; 2042 pBufferHeader->nAllocLen = nSizeBytes; 2043 pBufferHeader->nVersion.s.nVersionMajor = WBAMR_DEC_MAJOR_VER; 2044 pBufferHeader->nVersion.s.nVersionMinor = WBAMR_DEC_MINOR_VER; 2045 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 2046 pBufferHeader->pBuffer = pBuffer; 2047 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2048 *ppBufferHdr = pBufferHeader; 2049 OMX_PRBUFFER2(pComponentPrivate->dbg, "pBufferHeader = %p\n",pBufferHeader); 2050 EXIT: 2051#ifdef __PERF_INSTRUMENTATION__ 2052 PERF_ReceivedBuffer(pComponentPrivate->pPERF, 2053 pBuffer, nSizeBytes, 2054 PERF_ModuleHLMM); 2055#endif 2056 return eError; 2057} 2058 2059/* ================================================================================= */ 2060/** 2061 * @fn GetExtensionIndex() description for GetExtensionIndex 2062 GetExtensionIndex(). 2063 Returns index for vendor specific settings. 2064 * 2065 * @see OMX_Core.h 2066 */ 2067/* ================================================================================ */ 2068static OMX_ERRORTYPE GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 2069 OMX_IN OMX_STRING cParameterName, 2070 OMX_OUT OMX_INDEXTYPE* pIndexType) 2071{ 2072 OMX_ERRORTYPE eError = OMX_ErrorNone; 2073 2074 if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamrheaderinfo"))) { 2075 *pIndexType = OMX_IndexCustomWbAmrDecHeaderInfoConfig; 2076 } 2077 else if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamrstreamIDinfo"))) { 2078 *pIndexType = OMX_IndexCustomWbAmrDecStreamIDConfig; 2079 } 2080 else if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamr.datapath"))) 2081 { 2082 *pIndexType = OMX_IndexCustomWbAmrDecDataPath; 2083 } 2084 else if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamr.framelost"))) 2085 { 2086 *pIndexType = OMX_IndexCustomWbAmrDecNextFrameLost; 2087 } 2088 else if(!(strcmp(cParameterName,"OMX.TI.WBAMR.Decode.Debug"))) 2089 { 2090 *pIndexType = OMX_IndexCustomDebug; 2091 } 2092 else { 2093 eError = OMX_ErrorBadParameter; 2094 } 2095 2096 return eError; 2097} 2098 2099/* ================================================================================= */ 2100/** 2101 * @fn ComponentRoleEnum() description for ComponentRoleEnum() 2102 2103 Returns the role at the given index 2104 * 2105 * @see OMX_Core.h 2106 */ 2107/* ================================================================================ */ 2108static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent, 2109 OMX_OUT OMX_U8 *cRole, 2110 OMX_IN OMX_U32 nIndex) 2111{ 2112 WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate; 2113 2114 OMX_ERRORTYPE eError = OMX_ErrorNone; 2115 pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 2116 if(nIndex == 0){ 2117 if (cRole == NULL) { 2118 eError = OMX_ErrorBadParameter; 2119 } 2120 else { 2121 memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 2122 OMX_PRINT1(pComponentPrivate->dbg, "In ComponenetRoleEnum: cRole is set to %s\n",cRole); 2123 } 2124 } 2125 else { 2126 eError = OMX_ErrorNoMore; 2127 } 2128 return eError; 2129} 2130 2131#ifdef WBAMRDEC_DEBUGMEM 2132void * mymalloc(int line, char *s, int size) 2133{ 2134 void *p; 2135 int e=0; 2136 p = malloc(size); 2137 if(p==NULL){ 2138 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n"); 2139 /* exit(1); */ 2140 } 2141 else{ 2142 while((lines[e]!=0)&& (e<500) ){ 2143 e++; 2144 } 2145 arr[e]=p; 2146 lines[e]=line; 2147 bytes[e]=size; 2148 strcpy(file[e],s); 2149 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s); 2150 } 2151 return p; 2152} 2153 2154int myfree(void *dp, int line, char *s){ 2155 int q; 2156 if (dp==NULL){ 2157 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Null Memory can not be deleted line: %d file: %s\n", line, s); 2158 return 0; 2159 } 2160 2161 for(q=0;q<500;q++){ 2162 if(arr[q]==dp){ 2163 OMXDBG_PRINT(stderr, PRINT, 1, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s); 2164 free(dp); 2165 dp = NULL; 2166 lines[q]=0; 2167 strcpy(file[q],""); 2168 break; 2169 } 2170 } 2171 if(500==q) 2172 OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n\nPointer not found. Line:%d File%s!!\n\n",line, s); 2173} 2174#endif 2175