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