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