1 2/* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21/* ============================================================================= 22 * Texas Instruments OMAP (TM) Platform Software 23 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved. 24 * 25 * Use of this software is controlled by the terms and conditions found 26 * in the license agreement under which this software has been supplied. 27 * =========================================================================== */ 28/** 29 * @file OMX_G722Decoder.c 30 * 31 * This file implements OpenMAX (TM) 1.0 Specific APIs and its functionality 32 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification 33 * 34 * @path $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g722_dec\src 35 * 36 * @rev 1.0 37 */ 38/* ---------------------------------------------------------------------------- 39 *! 40 *! Revision History 41 *! =================================== 42 *! This is newest file 43 * =========================================================================== */ 44/* ------compilation control switches -------------------------*/ 45/**************************************************************** 46 * INCLUDE FILES 47 ****************************************************************/ 48/* ----- system and platform files ----------------------------*/ 49 50#ifdef UNDER_CE 51#include <windows.h> 52#include <oaf_osal.h> 53#include <omx_core.h> 54 55#else 56 57#include <unistd.h> 58#include <sys/time.h> 59#include <sys/types.h> 60#include <sys/ioctl.h> 61#include <sys/select.h> 62#include <errno.h> 63#endif 64 65#include <pthread.h> 66#include <string.h> 67#include <fcntl.h> 68#include <stdlib.h> 69#include <stdio.h> 70#include <dbapi.h> 71 72/*------- Program Header Files -----------------------------------------------*/ 73 74#include "LCML_DspCodec.h" 75#include "OMX_G722Dec_Utils.h" 76#include <TIDspOmx.h> 77 78#ifdef DSP_RENDERING_ON 79#include <AudioManagerAPI.h> 80#endif 81 82#ifdef DSP_RENDERING_ON 83 84#define FIFO1 "/dev/fifo.1" 85#define FIFO2 "/dev/fifo.2" 86#define PERMS 0666 87 88AM_COMMANDDATATYPE cmd_data; 89int G722d_fdwrite = 0, G722d_fdread = 0; 90int errno; 91#endif 92/* define component role */ 93#define G722_DEC_ROLE "audio_decoder.g722" 94 95/**************************************************************** 96 * EXTERNAL REFERENCES NOTE : only use if not found in header file 97 ****************************************************************/ 98/*--------data declarations -----------------------------------*/ 99 100/*--------function prototypes ---------------------------------*/ 101 102/**************************************************************** 103 * PUBLIC DECLARATIONS Defined here, used elsewhere 104 ****************************************************************/ 105/*--------data declarations -----------------------------------*/ 106 107/*--------function prototypes ---------------------------------*/ 108 109/**************************************************************** 110 * PRIVATE DECLARATIONS Defined here, used only here 111 ****************************************************************/ 112/*--------data declarations -----------------------------------*/ 113 114/*--------function prototypes ---------------------------------*/ 115 116static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp, 117 OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData); 118static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 119 OMX_STRING pComponentName, 120 OMX_VERSIONTYPE* pComponentVersion, 121 OMX_VERSIONTYPE* pSpecVersion, 122 OMX_UUIDTYPE* pComponentUUID); 123 124static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand, 125 OMX_U32 nParam, OMX_PTR pCmdData); 126 127static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, 128 OMX_PTR ComponentParamStruct); 129static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, 130 OMX_INDEXTYPE nParamIndex, 131 OMX_PTR ComponentParamStruct); 132static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 133 OMX_INDEXTYPE nConfigIndex, 134 OMX_PTR pComponentConfigStructure); 135static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 136 OMX_INDEXTYPE nConfigIndex, 137 OMX_PTR pComponentConfigStructure); 138 139static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 140 141static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 142static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState); 143static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 144 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 145 OMX_U32 nTunneledPort, 146 OMX_TUNNELSETUPTYPE* pTunnelSetup); 147 148static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle); 149 150static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 151 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 152 OMX_IN OMX_U32 nPortIndex, 153 OMX_IN OMX_PTR pAppPrivate, 154 OMX_IN OMX_U32 nSizeBytes); 155 156static OMX_ERRORTYPE FreeBuffer( 157 OMX_IN OMX_HANDLETYPE hComponent, 158 OMX_IN OMX_U32 nPortIndex, 159 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 160 161static OMX_ERRORTYPE UseBuffer ( 162 OMX_IN OMX_HANDLETYPE hComponent, 163 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 164 OMX_IN OMX_U32 nPortIndex, 165 OMX_IN OMX_PTR pAppPrivate, 166 OMX_IN OMX_U32 nSizeBytes, 167 OMX_IN OMX_U8* pBuffer); 168 169static OMX_ERRORTYPE GetExtensionIndex( 170 OMX_IN OMX_HANDLETYPE hComponent, 171 OMX_IN OMX_STRING cParameterName, 172 OMX_OUT OMX_INDEXTYPE* pIndexType); 173 174static OMX_ERRORTYPE ComponentRoleEnum( 175 OMX_IN OMX_HANDLETYPE hComponent, 176 OMX_OUT OMX_U8 *cRole, 177 OMX_IN OMX_U32 nIndex); 178 179/* ================================================================================= * */ 180/** 181 * @fn OMX_ComponentInit() function is called by OMX Core to initialize the component 182 * with default values of the component. Before calling this function OMX_Init 183 * must have been called. 184 * 185 * @param *hComp This is component handle allocated by the OMX core. 186 * 187 * @pre OMX_Init should be called by application. 188 * 189 * @post Component has initialzed with default values. 190 * 191 * @return OMX_ErrorNone = Successful Inirialization of the component\n 192 * OMX_ErrorInsufficientResources = Not enough memory 193 * 194 * @see G722Dec_StartCompThread() 195 */ 196/* ================================================================================ * */ 197OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp) 198{ 199 200 OMX_ERRORTYPE eError = OMX_ErrorNone; 201 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 202 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL; 203 OMX_AUDIO_PARAM_PORTFORMATTYPE *pPortFormat = NULL; 204 OMX_AUDIO_PARAM_PCMMODETYPE *G722_ip = NULL, *G722_op = NULL; 205 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 206 G722D_AUDIODEC_PORT_TYPE *pCompPort = NULL; 207 G722D_BUFFERLIST *pTemp = NULL; 208 int i=0; 209 210 G722DEC_DPRINT ("Entering OMX_ComponentInit\n"); 211 212 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1) 213 214 pHandle->SetCallbacks = SetCallbacks; 215 pHandle->GetComponentVersion = GetComponentVersion; 216 pHandle->SendCommand = SendCommand; 217 pHandle->GetParameter = GetParameter; 218 pHandle->SetParameter = SetParameter; 219 pHandle->GetConfig = GetConfig; 220 pHandle->SetConfig = SetConfig; 221 pHandle->GetState = GetState; 222 pHandle->EmptyThisBuffer = EmptyThisBuffer; 223 pHandle->FillThisBuffer = FillThisBuffer; 224 pHandle->ComponentTunnelRequest = ComponentTunnelRequest; 225 pHandle->ComponentDeInit = ComponentDeInit; 226 pHandle->AllocateBuffer = AllocateBuffer; 227 pHandle->FreeBuffer = FreeBuffer; 228 pHandle->UseBuffer = UseBuffer; 229 pHandle->GetExtensionIndex = GetExtensionIndex; 230 pHandle->ComponentRoleEnum = ComponentRoleEnum; 231 232 G722D_OMX_MALLOC(pHandle->pComponentPrivate,G722DEC_COMPONENT_PRIVATE); 233 234 pComponentPrivate = pHandle->pComponentPrivate; 235 pComponentPrivate->pHandle = pHandle; 236 237 G722D_OMX_MALLOC(pCompPort, G722D_AUDIODEC_PORT_TYPE); 238 pComponentPrivate->pCompPort[G722D_INPUT_PORT] = pCompPort; 239 240 G722D_OMX_MALLOC(pCompPort, G722D_AUDIODEC_PORT_TYPE); 241 pComponentPrivate->pCompPort[G722D_OUTPUT_PORT] = pCompPort; 242 G722D_OMX_MALLOC(pTemp, G722D_BUFFERLIST); 243 pComponentPrivate->pInputBufferList = pTemp; 244 245 G722D_OMX_MALLOC(pTemp, G722D_BUFFERLIST); 246 pComponentPrivate->pOutputBufferList = pTemp; 247 248 pComponentPrivate->pInputBufferList->numBuffers = 0; 249 pComponentPrivate->pOutputBufferList->numBuffers = 0; 250 251 for (i=0; i < MAX_NUM_OF_BUFS; i++) { 252 pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL; 253 pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL; 254 pComponentPrivate->arrTickCount[i] = 0; 255 pComponentPrivate->arrTimestamp[i] = 0; 256 } 257 pComponentPrivate->IpBufindex = 0; 258 pComponentPrivate->OpBufindex = 0; 259 260 pComponentPrivate->bufAlloced = 0; 261 262 G722D_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE); 263 OMX_CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE); 264 G722D_OMX_MALLOC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE); 265 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE); 266 pComponentPrivate->sPortParam->nPorts = 0x2; 267 pComponentPrivate->sPortParam->nStartPortNumber = 0x0; 268 pComponentPrivate->G722Params[G722D_INPUT_PORT] = NULL; 269 pComponentPrivate->G722Params[G722D_OUTPUT_PORT] = NULL; 270 271 G722D_OMX_MALLOC(G722_ip, OMX_AUDIO_PARAM_PCMMODETYPE); 272 G722D_OMX_MALLOC(G722_op, OMX_AUDIO_PARAM_PCMMODETYPE); 273 274 pComponentPrivate->G722Params[G722D_INPUT_PORT] = G722_ip; 275 pComponentPrivate->G722Params[G722D_OUTPUT_PORT] = G722_op; 276 277 pComponentPrivate->dasfmode = 0; 278 pComponentPrivate->bCompThreadStarted = 0; 279 pComponentPrivate->bExitCompThrd = 0; 280 281 pComponentPrivate->bInitParamsInitialized = 0; 282 pComponentPrivate->pMarkBuf = NULL; 283 pComponentPrivate->pMarkData = NULL; 284 pComponentPrivate->nEmptyBufferDoneCount = 0; 285 pComponentPrivate->nEmptyThisBufferCount = 0; 286 pComponentPrivate->nFillBufferDoneCount = 0; 287 pComponentPrivate->nFillThisBufferCount = 0; 288 pComponentPrivate->strmAttr = NULL; 289 pComponentPrivate->bDisableCommandParam = 0; 290 291 /* Initialize device string to the default value */ 292 G722D_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,(100*sizeof(OMX_STRING)),OMX_STRING); 293 strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0"); 294 295 /* initialize role name */ 296 G722D_OMX_MALLOC(pComponentPrivate->componentRole,OMX_PARAM_COMPONENTROLETYPE); 297 strcpy((char*)pComponentPrivate->componentRole->cRole, G722_DEC_ROLE); 298 299 300#ifndef UNDER_CE 301 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL); 302 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL); 303 pComponentPrivate->AlloBuf_waitingsignal = 0; 304 305 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL); 306 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL); 307 pComponentPrivate->InLoaded_readytoidle = 0; 308 309 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL); 310 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL); 311 pComponentPrivate->InIdle_goingtoloaded = 0; 312#else 313 OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event)); 314 pComponentPrivate->AlloBuf_waitingsignal = 0; 315 316 OMX_CreateEvent(&(pComponentPrivate->InLoaded_event)); 317 pComponentPrivate->InLoaded_readytoidle = 0; 318 319 OMX_CreateEvent(&(pComponentPrivate->InIdle_event)); 320 pComponentPrivate->InIdle_goingtoloaded = 0; 321#endif 322 323 for (i=0; i < MAX_NUM_OF_BUFS; i++) { 324 pComponentPrivate->pInputBufHdrPending[i] = NULL; 325 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 326 pComponentPrivate->arrTickCount[i] = 0; 327 pComponentPrivate->arrTimestamp[i] = 0; 328 pComponentPrivate->pOutBufHdrWhilePaused[i] = NULL; 329 } 330 pComponentPrivate->IpBufindex = 0; 331 pComponentPrivate->OpBufindex = 0; 332 333 pComponentPrivate->nPendingOutPausedBufs = 0; 334 335 pComponentPrivate->nInvalidFrameCount = 0; 336 pComponentPrivate->bDisableCommandPending = 0; 337 338 pComponentPrivate->numPendingBuffers = 0; 339 pComponentPrivate->bNoIdleOnStop= OMX_FALSE; 340 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 341 pComponentPrivate->bIdleCommandPending = OMX_FALSE; 342 pComponentPrivate->nOutStandingFillDones = 0; 343 G722D_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE); 344 G722D_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE); 345 346 pComponentPrivate->pPortDef[G722D_INPUT_PORT] = pPortDef_ip; 347 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT] = pPortDef_op; 348 349 /* Set input port defaults */ 350 pPortDef_ip->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE); 351 pPortDef_ip->nPortIndex = G722D_INPUT_PORT; 352 pPortDef_ip->eDir = OMX_DirInput; 353 pPortDef_ip->nBufferCountActual = G722D_NUM_INPUT_BUFFERS; 354 pPortDef_ip->nBufferCountMin = G722D_NUM_INPUT_BUFFERS; 355 pPortDef_ip->nBufferSize = G722D_INPUT_BUFFER_SIZE; 356 pPortDef_ip->bEnabled = OMX_TRUE; 357 pPortDef_ip->bPopulated = OMX_FALSE; 358 pPortDef_ip->eDomain = OMX_PortDomainAudio; 359 pPortDef_ip->format.audio.eEncoding = OMX_AUDIO_CodingPCM; 360 pPortDef_ip->format.audio.cMIMEType = NULL; 361 pPortDef_ip->format.audio.pNativeRender = NULL; 362 pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE; 363 364 /* Set input port defaults */ 365 pPortDef_op->nSize = sizeof (OMX_PARAM_PORTDEFINITIONTYPE); 366 pPortDef_op->nPortIndex = G722D_OUTPUT_PORT; 367 pPortDef_op->eDir = OMX_DirOutput; 368 pPortDef_op->nBufferCountMin = G722D_NUM_OUTPUT_BUFFERS; 369 pPortDef_op->nBufferCountActual = G722D_NUM_OUTPUT_BUFFERS; 370 pPortDef_op->nBufferSize = G722D_OUTPUT_BUFFER_SIZE; 371 pPortDef_op->bEnabled = OMX_TRUE; 372 pPortDef_op->bPopulated = OMX_FALSE; 373 pPortDef_op->eDomain = OMX_PortDomainAudio; 374 pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingPCM; 375 pPortDef_op->format.audio.cMIMEType = NULL; 376 pPortDef_op->format.audio.pNativeRender = NULL; 377 pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE; 378 379 G722D_OMX_MALLOC(pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat, 380 OMX_AUDIO_PARAM_PORTFORMATTYPE); 381 G722D_OMX_MALLOC(pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat, 382 OMX_AUDIO_PARAM_PORTFORMATTYPE); 383 OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat, 384 OMX_AUDIO_PARAM_PORTFORMATTYPE); 385 OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat, 386 OMX_AUDIO_PARAM_PORTFORMATTYPE); 387 388 389 /* Set input port format defaults */ 390 pPortFormat = pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat; 391 OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 392 pPortFormat->nPortIndex = G722D_INPUT_PORT; 393 pPortFormat->nIndex = OMX_IndexParamAudioPcm; 394 pPortFormat->eEncoding = OMX_AUDIO_CodingPCM; 395 396 /* Set output port format defaults */ 397 pPortFormat = pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat; 398 OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 399 pPortFormat->nPortIndex = G722D_OUTPUT_PORT; 400 pPortFormat->nIndex = OMX_IndexParamAudioPcm; 401 pPortFormat->eEncoding = OMX_AUDIO_CodingPCM; 402 403 /* Set input port parameters */ 404 OMX_CONF_INIT_STRUCT(G722_ip, OMX_AUDIO_PARAM_PCMMODETYPE); 405 G722_ip->nPortIndex = G722D_INPUT_PORT; 406 G722_ip->nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); 407 G722_ip->nVersion.s.nVersionMajor = 0xF1; 408 G722_ip->nVersion.s.nVersionMinor = 0xF2; 409 G722_ip->nChannels = 1; /* mono */ 410 G722_ip->nBitPerSample = 8; 411 G722_ip->eNumData = OMX_NumericalDataUnsigned; 412 G722_ip->eEndian = OMX_EndianLittle; 413 G722_ip->bInterleaved = OMX_FALSE; 414 G722_ip->ePCMMode = OMX_AUDIO_PCMModeLinear; 415 G722_ip->nSamplingRate = 64000; 416 417 /* Set output port parameters */ 418 OMX_CONF_INIT_STRUCT(G722_op, OMX_AUDIO_PARAM_PCMMODETYPE); 419 G722_op->nPortIndex = G722D_OUTPUT_PORT; 420 G722_op->nSamplingRate = 16000; 421 G722_op->nChannels = OMX_AUDIO_ChannelModeMono; 422 G722_op->nSize = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE); 423 G722_op->nVersion.s.nVersionMajor = 0xF1; 424 G722_op->nVersion.s.nVersionMinor = 0xF2; 425 G722_op->nBitPerSample = 16; 426 G722_op->eNumData = OMX_NumericalDataUnsigned; 427 G722_op->eEndian = OMX_EndianLittle; 428 G722_op->bInterleaved = OMX_FALSE; 429 G722_op->ePCMMode = OMX_AUDIO_PCMModeLinear; 430 431 pComponentPrivate->bBufferIsAllocated = 1; 432 pComponentPrivate->bPortDefsAllocated = 1; 433 434#ifdef DSP_RENDERING_ON 435 if((G722d_fdwrite=open(FIFO1,O_WRONLY))<0) { 436 G722DEC_DPRINT("[G722 Component] - failure to open WRITE pipe\n"); 437 eError = OMX_ErrorHardware; 438 } 439 if((G722d_fdread=open(FIFO2,O_RDONLY))<0) { 440 G722DEC_DPRINT("[G722 Component] - failure to open READ pipe\n"); 441 eError = OMX_ErrorHardware; 442 } 443#endif 444 445 eError = G722Dec_StartCompThread(pHandle); 446 if (eError != OMX_ErrorNone) { 447 G722DEC_DPRINT ("Error returned from the Component\n"); 448 goto EXIT; 449 } 450 451 EXIT: 452 if(OMX_ErrorNone != eError) { 453 G722DEC_DPRINT(":: ************* ERROR: Freeing Other Malloced Resources\n"); 454 G722D_OMX_FREE(pPortDef_ip); 455 G722D_OMX_FREE(pPortDef_op); 456 G722D_OMX_FREE(G722_ip); 457 G722D_OMX_FREE(G722_op); 458 G722D_OMX_FREE(pTemp); 459 } 460 G722DEC_DPRINT ("Exiting OMX_ComponentInit\n"); 461 return eError; 462} 463 464 465/* ================================================================================= * */ 466/** 467 * @fn SendCommand() function receives all the commands from the application. 468 * 469 * @param phandle This is component handle. 470 * 471 * @param Cmd This is commnad set that came from application. 472 * 473 * @param nParam This is commnad of the commands set that came from application. 474 * 475 * @param G722dData This is command data that came with command. 476 * 477 * @pre OMX_Init should be called by application. 478 * 479 * @post None 480 * 481 * @return OMX_ErrorNone = Successful Inirialization of the component\n 482 * OMX_ErrorBadPortIndex = Bad port index specified by application. 483 */ 484/* ================================================================================ * */ 485static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle, 486 OMX_COMMANDTYPE Cmd, 487 OMX_U32 nParam,OMX_PTR pCmdData) 488{ 489 OMX_ERRORTYPE eError = OMX_ErrorNone; 490 int nRet = 0; 491 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle; 492 G722DEC_COMPONENT_PRIVATE *pCompPrivate = NULL; 493 494 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1); 495 pCompPrivate = (G722DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 496 497 G722DEC_DPRINT("G722DEC: Entered SendCommand\n"); 498 if(pCompPrivate->curState == OMX_StateInvalid){ 499 G722DEC_DPRINT("G722DEC: Error Notofication Sent to App\n"); 500 G722D_OMX_ERROR_EXIT(eError, OMX_ErrorInvalidState,"OMX_ErrorInvalidState"); 501 } 502 503 switch(Cmd) { 504 case OMX_CommandStateSet: 505 G722DEC_DPRINT("G722DEC: Entered switch - Command State Set\n"); 506 if (nParam == OMX_StateLoaded) { 507 pCompPrivate->bLoadedCommandPending = OMX_TRUE; 508 } 509 if(pCompPrivate->curState == OMX_StateLoaded) { 510 G722DEC_DPRINT("G722DEC: Entered switch - curState == OMX_StateLoaded\n"); 511 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) { 512 G722DEC_DPRINT("G722DEC: Entered switch - nParam == StatExecuting \ 513|| OMX_StatePause\n"); 514 pCompPrivate->cbInfo.EventHandler (pHandle, 515 pHandle->pApplicationPrivate, 516 OMX_EventError, 517 OMX_ErrorIncorrectStateTransition, 518 0, 519 NULL); 520 G722DEC_DPRINT("Incorrect St Tr fm Loaded to Executing By App\n"); 521 goto EXIT; 522 } 523 if(nParam == OMX_StateInvalid) { 524 pCompPrivate->curState = OMX_StateInvalid; 525 pCompPrivate->cbInfo.EventHandler (pHandle, 526 pHandle->pApplicationPrivate, 527 OMX_EventError, 528 OMX_ErrorInvalidState, 529 0, 530 NULL); 531 G722DEC_DPRINT("Incorrect State Tr from Loaded to Invalid by Application\n"); 532 goto EXIT; 533 } 534 } 535 break; 536 case OMX_CommandFlush: 537 G722DEC_DPRINT("G722DEC: Entered switch - Command Flush\n"); 538 if(nParam > 1 && nParam != -1) { 539 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex"); 540 } 541 break; 542 case OMX_CommandPortDisable: 543 break; 544 case OMX_CommandPortEnable: 545 G722DEC_DPRINT("G722DEC: Entered switch - Command Port Enable/Disbale\n"); 546 break; 547 case OMX_CommandMarkBuffer: 548 G722DEC_DPRINT("G722DEC: Entered switch - Command Mark Buffer\n"); 549 550 if(nParam > 0) { 551 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex"); 552 } 553 break; 554 default: 555 G722DEC_DPRINT("G722DEC: Command Received Default error\n"); 556 pCompPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate, 557 OMX_EventError, 558 OMX_ErrorUndefined,0, 559 "Invalid Command"); 560 break; 561 } 562 563 564 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 565 if (nRet == -1) { 566 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware"); 567 } 568 569 if (Cmd == OMX_CommandMarkBuffer) { 570 nRet = write (pCompPrivate->cmdDataPipe[1], &pCmdData, 571 sizeof(OMX_PTR)); 572 if (nRet == -1) { 573 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware"); 574 } 575 } 576 else { 577 nRet = write (pCompPrivate->cmdDataPipe[1], &nParam, 578 sizeof(OMX_U32)); 579 if (nRet == -1) { 580 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware"); 581 } 582 } 583 584 585#ifdef DSP_RENDERING_ON 586 if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting){ 587 if(pCompPrivate->acdnmode == 1) { 588 /* enable COMP for ACDN1 */ 589 cmd_data.hComponent = pHandle; 590 cmd_data.AM_Cmd = AM_CommandACDN1CompressorMode; 591 cmd_data.param1 = ECOMPRESSORENABLE; /* mode */ 592 cmd_data.param2 = 0; 593 cmd_data.streamID = 0; 594 595 if((write(G722d_fdwrite, &cmd_data, sizeof(cmd_data)))<0) 596 G722DEC_DPRINT("[G722 decoder] - fail to send command to audio manager\n"); 597 598 /* enable DL EQ for ACDN0 */ 599 cmd_data.hComponent = pHandle; 600 cmd_data.AM_Cmd = AM_CommandACDN0EQDLLMode; 601 cmd_data.param1 = EEQ_DLENABLE; /* mode */ 602 cmd_data.param2 = 0; 603 cmd_data.streamID = 0; 604 605 if((write(G722d_fdwrite, &cmd_data, sizeof(cmd_data)))<0) 606 G722DEC_DPRINT("[G722 decoder] - fail to send command to audio manager\n"); 607 }else { 608 /* enable Tee device command*/ 609 cmd_data.hComponent = pHandle; 610 cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode; 611 cmd_data.param1 = 0; 612 cmd_data.param2 = 0; 613 cmd_data.streamID = 0; 614 615 if((write(G722d_fdwrite, &cmd_data, sizeof(cmd_data)))<0) { 616 eError = OMX_ErrorHardware; 617 goto EXIT; 618 } 619 } 620 } 621#endif 622 623 EXIT: 624 return eError; 625} 626 627 628 629/* ================================================================================= * */ 630/** 631 * @fn GetParameter() function gets the various parameter values of the 632 * component. 633 * 634 * @param hComp This is component handle. 635 * 636 * @param nParamIndex This is enumerate values which specifies what kind of 637 * information is to be retreived form the component. 638 * 639 * @param ComponentParameterStructure This is output argument which is 640 * filled by the component component 641 * 642 * @pre The component should be in loaded state. 643 * 644 * @post None 645 * 646 * @return OMX_ErrorNone = Successful Inirialization of the component\n 647 * OMX_ErrorBadPortIndex = Bad port index specified by application. 648 */ 649/* ================================================================================ * */ 650static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp, 651 OMX_INDEXTYPE nParamIndex, 652 OMX_PTR ComponentParameterStructure) 653{ 654 OMX_ERRORTYPE eError = OMX_ErrorNone; 655 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 656 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL; 657 658 659 G722DEC_DPRINT("Inside the GetParameter:: %x\n",nParamIndex); 660 661 G722D_OMX_CONF_CHECK_CMD(hComp,1,1); 662 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 663 664 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate, ComponentParameterStructure, 1); 665 pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure; 666 667 G722DEC_DPRINT(":: Entering the GetParameter\n"); 668 669 if(pComponentPrivate->curState == OMX_StateInvalid) { 670 eError = OMX_ErrorIncorrectStateOperation; 671 goto EXIT; 672 } 673 674 switch(nParamIndex){ 675 case OMX_IndexParamAudioInit: 676 G722DEC_DPRINT(":: GetParameter OMX_IndexParamAudioInit\n"); 677 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1); 678 memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE)); 679 break; 680 681 case OMX_IndexParamPortDefinition: 682 G722DEC_DPRINT(": GetParameter OMX_IndexParamPortDefinition \n"); 683 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 684 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->nPortIndex) { 685 memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G722D_INPUT_PORT], 686 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 687 } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 688 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nPortIndex) { 689 memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G722D_OUTPUT_PORT], 690 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 691 } else { 692 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter \n"); 693 eError = OMX_ErrorBadPortIndex; 694 } 695 break; 696 697 case OMX_IndexParamAudioPortFormat: 698 G722DEC_DPRINT(":: GetParameter OMX_IndexParamAudioPortFormat \n"); 699 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == 700 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->nPortIndex) { 701 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > 702 pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat->nPortIndex) { 703 eError = OMX_ErrorNoMore; 704 } 705 else { 706 memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat, 707 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 708 } 709 } 710 else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == 711 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nPortIndex){ 712 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > 713 pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat->nPortIndex) { 714 eError = OMX_ErrorNoMore; 715 } 716 else { 717 memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat, 718 sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 719 } 720 } 721 else { 722 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter \n"); 723 eError = OMX_ErrorBadPortIndex; 724 } 725 break; 726 727 case OMX_IndexParamAudioPcm: 728 G722DEC_DPRINT(" :: GetParameter OMX_IndexParamAudioPcm \n"); 729 if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex == 730 pComponentPrivate->G722Params[G722D_INPUT_PORT]->nPortIndex) { 731 memcpy(ComponentParameterStructure, pComponentPrivate->G722Params[G722D_INPUT_PORT], 732 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 733 } else if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex == 734 pComponentPrivate->G722Params[G722D_OUTPUT_PORT]->nPortIndex) { 735 memcpy(ComponentParameterStructure, pComponentPrivate->G722Params[G722D_OUTPUT_PORT], 736 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 737 } else { 738 G722DEC_DPRINT(" :: OMX_ErrorBadPortIndex from GetParameter \n"); 739 eError = OMX_ErrorBadPortIndex; 740 } 741 break; 742 743 case OMX_IndexParamPriorityMgmt: 744 G722DEC_DPRINT(" :: GetParameter OMX_IndexParamPriorityMgmt \n"); 745 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1); 746 memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE)); 747 break; 748 749 case OMX_IndexParamVideoInit: 750 break; 751 752 case OMX_IndexParamImageInit: 753 break; 754 755 case OMX_IndexParamOtherInit: 756 break; 757 758 default: 759 G722DEC_DPRINT(" :: OMX_ErrorUnsupportedIndex GetParameter \n"); 760 eError = OMX_ErrorUnsupportedIndex; 761 break; 762 } 763 EXIT: 764 G722DEC_DPRINT(" :: Exiting GetParameter\n"); 765 G722DEC_DPRINT(" :: Returning = 0x%x\n",eError); 766 return eError; 767} 768 769 770/* ================================================================================= * */ 771/** 772 * @fn SetParameter() function sets the various parameter values of the 773 * component. 774 * 775 * @param hComp This is component handle. 776 * 777 * @param nParamIndex This is enumerate values which specifies what kind of 778 * information is to be set for the component. 779 * 780 * @param ComponentParameterStructure This is input argument which contains 781 * the values to be set for the component. 782 * 783 * @pre The component should be in loaded state. 784 * 785 * @post None 786 * 787 * @return OMX_ErrorNone = Successful Inirialization of the component\n 788 * OMX_ErrorBadPortIndex = Bad port index specified by application. 789 */ 790/* ================================================================================ * */ 791static OMX_ERRORTYPE SetParameter ( 792 OMX_IN OMX_HANDLETYPE hComponent, 793 OMX_IN OMX_INDEXTYPE nIndex, 794 OMX_IN OMX_PTR pCompParam) 795{ 796 OMX_ERRORTYPE eError = OMX_ErrorNone; 797 OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComponent; 798 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 799 OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL; 800 OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL; 801 OMX_AUDIO_PARAM_PCMMODETYPE *pCompG722Param = NULL; 802 OMX_PARAM_COMPONENTROLETYPE *pRole = NULL; 803 OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier; 804 805 G722D_OMX_CONF_CHECK_CMD(hComponent,1,1) 806 807 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 808 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate, pCompParam, 1); 809 810 811 G722DEC_DPRINT(" :: Entering the SetParameter\n"); 812 if (pComponentPrivate->curState != OMX_StateLoaded) { 813 eError = OMX_ErrorIncorrectStateOperation; 814 G722DEC_DPRINT(" :: OMX_ErrorIncorrectStateOperation from SetParameter"); 815 goto EXIT; 816 } 817 818 switch(nIndex) { 819 case OMX_IndexParamAudioPortFormat: 820 G722DEC_DPRINT(":: SetParameter OMX_IndexParamAudioPortFormat \n"); 821 pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam; 822 if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat->nPortIndex ) { 823 memcpy(pComponentPrivate->pCompPort[G722D_INPUT_PORT]->pPortFormat, 824 pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 825 } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat->nPortIndex ) { 826 memcpy(pComponentPrivate->pCompPort[G722D_OUTPUT_PORT]->pPortFormat, 827 pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 828 } else { 829 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter"); 830 eError = OMX_ErrorBadPortIndex; 831 } 832 break; 833 834 case OMX_IndexParamAudioPcm: 835 G722DEC_DPRINT(" :: SetParameter OMX_IndexParamAudioPcm \n"); 836 pCompG722Param = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam; 837 838 /* This if condition is not yet well defined because khronos 839 * test suite does not set the sampling frequency. For component 840 * test application, it is meant to test that component returns 841 * the error on invalid frequecy * 842 if(pCompG722Param->nSamplingRate == INVALID_SAMPLING_FREQ) { 843 eError = OMX_ErrorUnsupportedIndex; 844 G722DEC_DPRINT("Unsupported SampleRate Given By the App\n"); 845 goto EXIT; 846 } 847 *****/ 848 849 if(pCompG722Param->nPortIndex == G722D_INPUT_PORT) { /* means Input port */ 850 memcpy(((G722DEC_COMPONENT_PRIVATE*) 851 pHandle->pComponentPrivate)->G722Params[G722D_INPUT_PORT], pCompG722Param, 852 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 853 } else if (pCompG722Param->nPortIndex == G722D_OUTPUT_PORT) { /* means Output port */ 854 memcpy(((G722DEC_COMPONENT_PRIVATE *) 855 pHandle->pComponentPrivate)->G722Params[G722D_OUTPUT_PORT], pCompG722Param, 856 sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 857 } 858 else { 859 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter"); 860 eError = OMX_ErrorBadPortIndex; 861 } 862 break; 863 864 case OMX_IndexParamPortDefinition: 865 pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam; 866 if (pComponentParamPort->nPortIndex == 0) { 867 if (pComponentParamPort->eDir != OMX_DirInput) { 868 G722DEC_DPRINT(":: Invalid input buffer Direction\n"); 869 eError = OMX_ErrorBadParameter; 870 goto EXIT; 871 } 872 if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingPCM) { 873 G722DEC_DPRINT(":: Invalid format Parameter\n"); 874 eError = OMX_ErrorBadParameter; 875 goto EXIT; 876 } 877 } else if (pComponentParamPort->nPortIndex == 1) { 878 if (pComponentParamPort->eDir != OMX_DirOutput) { 879 G722DEC_DPRINT(" :: Invalid Output buffer Direction\n"); 880 eError = OMX_ErrorBadParameter; 881 goto EXIT; 882 } 883 if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingPCM) { 884 G722DEC_DPRINT(":: Invalid format Parameter\n"); 885 eError = OMX_ErrorBadParameter; 886 goto EXIT; 887 } 888 } else { 889 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter"); 890 eError = OMX_ErrorBadPortIndex; 891 } 892 G722DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition \n"); 893 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 894 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->nPortIndex) { 895 G722DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition input \n"); 896 memcpy(pComponentPrivate->pPortDef[G722D_INPUT_PORT], pCompParam, 897 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 898 } 899 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 900 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nPortIndex) { 901 G722DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition output\n"); 902 memcpy(pComponentPrivate->pPortDef[G722D_OUTPUT_PORT], pCompParam, 903 sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 904 } 905 else { 906 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter"); 907 eError = OMX_ErrorBadPortIndex; 908 } 909 break; 910 911 case OMX_IndexParamPriorityMgmt: 912 G722DEC_DPRINT(":: SetParameter OMX_IndexParamPriorityMgmt \n"); 913 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1); 914 memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, 915 sizeof(OMX_PRIORITYMGMTTYPE)); 916 break; 917 918 case OMX_IndexParamAudioInit: 919 G722DEC_DPRINT(":: SetParameter OMX_IndexParamAudioInit \n"); 920 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1); 921 memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, 922 sizeof(OMX_PORT_PARAM_TYPE)); 923 break; 924 925 case OMX_IndexParamStandardComponentRole: 926 if (pCompParam) { 927 pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam; 928 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->componentRole, 1, 1); 929 memcpy(pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 930 } else { 931 eError = OMX_ErrorBadParameter; 932 } 933 break; 934 935 case OMX_IndexParamCompBufferSupplier: 936 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 937 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->nPortIndex) { 938 G722DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n"); 939 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput; 940 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 941 942 } 943 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == 944 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nPortIndex) { 945 G722DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n"); 946 sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput; 947 memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE)); 948 } 949 else { 950 G722DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter"); 951 eError = OMX_ErrorBadPortIndex; 952 } 953 break; 954 955 default: 956 G722DEC_DPRINT(":: SetParameter OMX_ErrorUnsupportedIndex \n"); 957 eError = OMX_ErrorUnsupportedIndex; 958 break; 959 } 960 961 EXIT: 962 G722DEC_DPRINT(":: Exiting SetParameter\n"); 963 G722DEC_DPRINT(":: Returning = 0x%x\n",eError); 964 return eError; 965 966} 967 968 969/* ================================================================================= * */ 970/** 971 * @fn SetCallbacks() Sets application callbacks to the component 972 * 973 * @param pComponent This is component handle. 974 * 975 * @param pCallBacks Application callbacks 976 * 977 * @param pAppData Application specified private data. 978 * 979 * @pre None 980 * 981 * @post None 982 * 983 * @return OMX_ErrorNone = Successful Inirialization of the component 984 * OMX_ErrorBadParameter = If callback argument is NULL. 985 */ 986/* ================================================================================ * */ 987 988static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent, 989 OMX_CALLBACKTYPE* pCallBacks, 990 OMX_PTR pAppData) 991{ 992 OMX_ERRORTYPE eError = OMX_ErrorNone; 993 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent; 994 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 995 996 997 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1) 998 999 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1000 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) 1001 1002 G722DEC_DPRINT ("Entering SetCallbacks\n"); 1003 1004 G722D_OMX_CONF_CHECK_CMD(pCallBacks, pCallBacks->EventHandler, pCallBacks->EmptyBufferDone) 1005 G722D_OMX_CONF_CHECK_CMD(pCallBacks->FillBufferDone, 1, 1) 1006 1007 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE)); 1008 pHandle->pApplicationPrivate = pAppData; 1009 G722DEC_STATEPRINT("****************** Component State Set to Loaded\n\n"); 1010 pComponentPrivate->curState = OMX_StateLoaded; 1011 1012 EXIT: 1013 G722DEC_DPRINT ("Exiting SetCallbacks\n"); 1014 return eError; 1015} 1016 1017 1018/* ================================================================================= * */ 1019/** 1020 * @fn GetComponentVersion() Sets application callbacks to the component. Currently this 1021 * function is not implemented. 1022 * 1023 * @param hComp This is component handle. 1024 * 1025 * @param pComponentName This is component name. 1026 * 1027 * @param pComponentVersion This output argument will contain the component 1028 * version when this function exits successfully. 1029 * 1030 * @param pSpecVersion This is specification version. 1031 * 1032 * @param pComponentUUID This specifies the UUID of the component. 1033 * 1034 * @pre None 1035 * 1036 * @post None 1037 * 1038 * @return OMX_ErrorNone = Successful Inirialization of the component 1039 */ 1040/* ================================================================================ * */ 1041static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 1042 OMX_STRING pComponentName, 1043 OMX_VERSIONTYPE* pComponentVersion, 1044 OMX_VERSIONTYPE* pSpecVersion, 1045 OMX_UUIDTYPE* pComponentUUID) 1046{ 1047 OMX_ERRORTYPE eError = OMX_ErrorNone; 1048 eError = OMX_ErrorNotImplemented; 1049 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 1050 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = 1051 (G722DEC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 1052 1053 /* Copy component version structure */ 1054 if(pComponentVersion != NULL && pComponentName != NULL) { 1055 strcpy(pComponentName, pComponentPrivate->cComponentName); 1056 memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), 1057 sizeof(pComponentPrivate->ComponentVersion.s)); 1058 } 1059 else { 1060 G722DEC_DPRINT("%d :: OMX_ErrorBadParameter from GetComponentVersion",__LINE__); 1061 eError = OMX_ErrorBadParameter; 1062 } 1063 1064 return eError; 1065} 1066 1067 1068 1069/* ================================================================================= * */ 1070/** 1071 * @fn GetConfig() gets the configuration of the component depending on the value 1072 * of nConfigINdex. This function is currently not implemented. 1073 * 1074 * @param hComp This is component handle. 1075 * 1076 * @param nConfigIndex This is config index to get the configuration of 1077 * component. 1078 * 1079 * @param ComponentConfigStructure This is configuration structure that is filled 1080 * by the component depending on the value of nConfigIndex. 1081 * 1082 * @pre None 1083 * 1084 * @post None 1085 * 1086 * @return OMX_ErrorNone = Successful Inirialization of the component 1087 */ 1088/* ================================================================================ * */ 1089static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 1090 OMX_INDEXTYPE nConfigIndex, 1091 OMX_PTR ComponentConfigStructure) 1092{ 1093 OMX_ERRORTYPE eError = OMX_ErrorNone; 1094 G722DEC_DPRINT ("Entering GetConfig\n"); 1095 G722DEC_DPRINT ("Inside GetConfig\n"); 1096 G722DEC_DPRINT ("Exiting GetConfig\n"); 1097 return eError; 1098} 1099 1100/* ================================================================================= * */ 1101/** 1102 * @fn SetConfig() Sets the configuration of the component depending on the value 1103 * of nConfigINdex. 1104 * 1105 * @param hComp This is component handle. 1106 * 1107 * @param nConfigIndex This is config index to get the configuration of 1108 * component. 1109 * 1110 * @param ComponentConfigStructure This is configuration structure that contains 1111 * the information which the component has to 1112 * configured with. 1113 * 1114 * @pre None 1115 * 1116 * @post None 1117 * 1118 * @return OMX_ErrorNone = Successful Inirialization of the component 1119 */ 1120/* ================================================================================ * */ 1121static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 1122 OMX_INDEXTYPE nConfigIndex, 1123 OMX_PTR ComponentConfigStructure) 1124{ 1125 OMX_ERRORTYPE eError = OMX_ErrorNone; 1126 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1127 OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL; 1128 OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL; 1129 TI_OMX_DSP_DEFINITION* pDspDefinition = NULL; 1130 OMX_S16* deviceString = NULL; 1131 TI_OMX_DATAPATH dataPath; 1132 1133 G722DEC_DPRINT ("Entering SetConfig\n"); 1134 1135 G722D_OMX_CONF_CHECK_CMD(hComp,ComponentConfigStructure,1) 1136 1137 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *) 1138 (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 1139 1140 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) 1141 1142 switch (nConfigIndex){ 1143 case OMX_IndexCustomG722DecHeaderInfoConfig: 1144 pDspDefinition = (TI_OMX_DSP_DEFINITION *)ComponentConfigStructure; 1145 pComponentPrivate->dasfmode = pDspDefinition->dasfMode; 1146 pComponentPrivate->streamID = pDspDefinition->streamId; 1147 break; 1148 1149 /* set mute/unmute for playback stream */ 1150 case OMX_IndexConfigAudioMute: 1151#ifdef DSP_RENDERING_ON 1152 pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure; 1153 printf("Set Mute/Unmute for playback stream\n"); 1154 cmd_data.hComponent = hComp; 1155 if(pMuteStructure->bMute == OMX_TRUE){ 1156 printf("Mute the playback stream\n"); 1157 cmd_data.AM_Cmd = AM_CommandStreamMute; 1158 } 1159 else{ 1160 printf("unMute the playback stream\n"); 1161 cmd_data.AM_Cmd = AM_CommandStreamUnMute; 1162 } 1163 cmd_data.param1 = 0; 1164 cmd_data.param2 = 0; 1165 cmd_data.streamID = pComponentPrivate->streamID; 1166 1167 if((write(G722d_fdwrite, &cmd_data, sizeof(cmd_data)))<0){ 1168 G722DEC_DPRINT("[G722 decoder] - fail to send command to audio manager\n"); 1169 } 1170#endif 1171 break; 1172 1173 /* set volume for playback stream */ 1174 case OMX_IndexConfigAudioVolume: 1175#ifdef DSP_RENDERING_ON 1176 pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure; 1177 printf("Set volume for playback stream\n"); 1178 cmd_data.hComponent = hComp; 1179 cmd_data.AM_Cmd = AM_CommandSWGain; 1180 cmd_data.param1 = pVolumeStructure->sVolume.nValue; 1181 cmd_data.param2 = 0; 1182 cmd_data.streamID = pComponentPrivate->streamID; 1183 1184 if((write(G722d_fdwrite, &cmd_data, sizeof(cmd_data)))<0){ 1185 G722DEC_DPRINT("[G722 decoder] - fail to send command to audio manager\n"); 1186 } 1187#endif 1188 break; 1189 1190 case OMX_IndexCustomG722DecDataPath: 1191 deviceString = (OMX_S16*)ComponentConfigStructure; 1192 if (deviceString == NULL) { 1193 eError = OMX_ErrorBadParameter; 1194 goto EXIT; 1195 } 1196 1197 dataPath = (TI_OMX_DATAPATH)*deviceString; 1198 1199 switch(dataPath) { 1200 case DATAPATH_APPLICATION: 1201 /*strcpy((char*)pComponentPrivate->sDeviceString,(char*)ETEEDN_STRING);*/ 1202 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER, 1203 pComponentPrivate->streamID); 1204 break; 1205 1206 case DATAPATH_APPLICATION_RTMIXER: 1207 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING); 1208 break; 1209 1210 case DATAPATH_ACDN: 1211 strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING); 1212 break; 1213 1214 default: 1215 break; 1216 } 1217 break; 1218 1219 default: 1220 eError = OMX_ErrorUnsupportedIndex; 1221 break; 1222 } 1223 1224 G722DEC_DPRINT ("Exiting SetConfig\n"); 1225 EXIT: 1226 1227 return eError; 1228} 1229 1230/* ================================================================================= * */ 1231/** 1232 * @fn GetState() Gets the current state of the component. 1233 * 1234 * @param pComponent This is component handle. 1235 * 1236 * @param pState This is the output argument that contains the state of the 1237 * component. 1238 * 1239 * @pre None 1240 * 1241 * @post None 1242 * 1243 * @return OMX_ErrorNone = Successful Inirialization of the component 1244 * OMX_ErrorBadParameter = if output argument is NULL. 1245 */ 1246/* ================================================================================ * */ 1247static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState) 1248{ 1249 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 1250 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1251 1252 G722DEC_DPRINT ("Entering GetState\n"); 1253 1254 if (!pState) { 1255 G722DEC_DPRINT (":: About to exit with bad parameter\n"); 1256 eError = OMX_ErrorBadParameter; 1257 goto EXIT; 1258 } 1259 1260 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1) 1261 if (pHandle && pHandle->pComponentPrivate) { 1262 *pState = ((G722DEC_COMPONENT_PRIVATE*) 1263 pHandle->pComponentPrivate)->curState; 1264 } else { 1265 G722DEC_STATEPRINT("Component State Set to Loaded\n\n"); 1266 *pState = OMX_StateLoaded; 1267 } 1268 1269 eError = OMX_ErrorNone; 1270 1271 EXIT: 1272 G722DEC_DPRINT (":: Exiting GetState\n"); 1273 return eError; 1274} 1275 1276/* ================================================================================= * */ 1277/** 1278 * @fn EmptyThisBuffer() This function is used by application to sent the filled 1279 * input buffers to the component. 1280 * 1281 * @param pComponent This is component handle. 1282 * 1283 * @param pBuffer This is poiter to the buffer header that come from the 1284 * application. 1285 * 1286 * @pre None 1287 * 1288 * @post None 1289 * 1290 * @return OMX_ErrorNone = Successful exit of the function 1291 * OMX_ErrorBadParameter = Bad input argument 1292 * OMX_ErrorBadPortIndex = Bad port index supplied by the 1293 * application 1294 */ 1295/* ================================================================================ * */ 1296static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent, 1297 OMX_BUFFERHEADERTYPE* pBuffer) 1298{ 1299 OMX_ERRORTYPE eError = OMX_ErrorNone; 1300 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1301 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1302 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1303 int ret=0; 1304 1305 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1) 1306 1307 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1308 1309 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) 1310 1311 pPortDef = ((G722DEC_COMPONENT_PRIVATE*) 1312 pComponentPrivate)->pPortDef[G722D_INPUT_PORT]; 1313 1314 1315 if(!pPortDef->bEnabled) { 1316 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation, 1317 "OMX_ErrorIncorrectStateOperation"); 1318 } 1319 1320 if (pBuffer == NULL) { 1321 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter"); 1322 } 1323 1324 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1325 G722DEC_DPRINT(":: Error: Bad Size = %ld, Add: %p\n", 1326 pBuffer->nSize,pBuffer); 1327 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"Bad Size"); 1328 } 1329 1330 if (pBuffer->nInputPortIndex != G722D_INPUT_PORT) { 1331 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex"); 1332 } 1333 1334 1335 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1336 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorVersionMismatch,"OMX_ErrorVersionMismatch"); 1337 } 1338 1339 1340 if(pComponentPrivate->curState != OMX_StateExecuting && 1341 pComponentPrivate->curState != OMX_StatePause && 1342 pComponentPrivate->curState != OMX_StateIdle) { 1343 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation, 1344 "OMX_ErrorIncorrectStateOperation"); 1345 } 1346 1347 1348 G722DEC_DPRINT("\n------------------------------------------\n\n"); 1349 G722DEC_DPRINT (":: Component Sending Filled ip buff %p \ 1350 to Component Thread\n",pBuffer); 1351 G722DEC_DPRINT("\n------------------------------------------\n\n"); 1352 1353 if (pComponentPrivate->bBypassDSP == 0) { 1354 pComponentPrivate->app_nBuf--; 1355 } 1356 1357 pComponentPrivate->pMarkData = pBuffer->pMarkData; 1358 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent; 1359 1360 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, 1361 sizeof(OMX_BUFFERHEADERTYPE*)); 1362 if (ret == -1) { 1363 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware"); 1364 } 1365 1366 pComponentPrivate->nEmptyThisBufferCount++; 1367 1368 EXIT: 1369 G722DEC_DPRINT (":: Exiting EmptyThisBuffer, eError = %d\n",eError); 1370 return eError; 1371} 1372 1373/* ================================================================================= * */ 1374/** 1375 * @fn FillThisBuffer() This function is used by application to sent the empty 1376 * output buffers to the component. 1377 * 1378 * @param pComponent This is component handle. 1379 * 1380 * @param pBuffer This is poiter to the output buffer header that come from the 1381 * application. 1382 * 1383 * @pre None 1384 * 1385 * @post None 1386 * 1387 * @return OMX_ErrorNone = Successful exit of the function 1388 * OMX_ErrorBadParameter = Bad input argument 1389 * OMX_ErrorBadPortIndex = Bad port index supplied by the 1390 * application 1391 */ 1392/* ================================================================================ * */ 1393static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent, 1394 OMX_BUFFERHEADERTYPE* pBuffer) 1395{ 1396 OMX_ERRORTYPE eError = OMX_ErrorNone; 1397 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1398 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1399 int nRet=0; 1400 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1401 1402 G722DEC_DPRINT("\n------------------------------------------\n\n"); 1403 G722DEC_DPRINT (" :: Component Sending Emptied op buff %p \ 1404 to Component Thread\n",pBuffer); 1405 G722DEC_DPRINT("\n------------------------------------------\n\n"); 1406 1407 1408 G722D_OMX_CONF_CHECK_CMD(pHandle,1,1) 1409 1410 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1411 1412 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) 1413 1414 1415 pPortDef = ((G722DEC_COMPONENT_PRIVATE*) 1416 pComponentPrivate)->pPortDef[G722D_OUTPUT_PORT]; 1417 1418 if(!pPortDef->bEnabled) { 1419 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation, 1420 "OMX_ErrorIncorrectStateOperation"); 1421 } 1422 1423 if (pBuffer == NULL) { 1424 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter"); 1425 } 1426 1427 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1428 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter"); 1429 } 1430 1431 if (pBuffer->nOutputPortIndex != G722D_OUTPUT_PORT) { 1432 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex"); 1433 } 1434 1435 G722DEC_DPRINT("::pBuffer->nVersion.nVersion:%ld\n",pBuffer->nVersion.nVersion); 1436 G722DEC_DPRINT("::pComponentPrivate->nVersion:%ld\n",pComponentPrivate->nVersion); 1437 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1438 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorVersionMismatch,"OMX_ErrorVersionMismatch"); 1439 } 1440 1441 if(pComponentPrivate->curState != OMX_StateExecuting && 1442 pComponentPrivate->curState != OMX_StatePause && 1443 pComponentPrivate->curState != OMX_StateIdle) { 1444 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation, 1445 "OMX_ErrorIncorrectStateOperation"); 1446 } 1447 1448 1449 pBuffer->nFilledLen = 0; 1450 1451 if (pComponentPrivate->bBypassDSP == 0) { 1452 pComponentPrivate->app_nBuf--; 1453 } 1454 1455 if(pComponentPrivate->pMarkBuf){ 1456 G722DEC_DPRINT("FillThisBuffer Line\n"); 1457 pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent; 1458 pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData; 1459 pComponentPrivate->pMarkBuf = NULL; 1460 } 1461 1462 if (pComponentPrivate->pMarkData) { 1463 G722DEC_DPRINT("FillThisBuffer Line\n"); 1464 pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent; 1465 pBuffer->pMarkData = pComponentPrivate->pMarkData; 1466 pComponentPrivate->pMarkData = NULL; 1467 } 1468 1469 nRet = write (pComponentPrivate->dataPipe[1], &pBuffer, 1470 sizeof (OMX_BUFFERHEADERTYPE*)); 1471 if (nRet == -1) { 1472 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware"); 1473 } 1474 1475 pComponentPrivate->nFillThisBufferCount++; 1476 1477 EXIT: 1478 G722DEC_DPRINT (":: Exiting FillThisBuffer\n"); 1479 return eError; 1480} 1481 1482/* ================================================================================= * */ 1483/** 1484 * @fn ComponentDeInit() This function deinitializes the component. It is called 1485 * from OMX Core, not by application. Albeit, Application does call 1486 * OMX_FreeHandle of OMX Core and which in turn calls this function. 1487 * 1488 * @param pHandle This is component handle. 1489 * 1490 * @pre None 1491 * 1492 * @post This function should clean or free as much resources as 1493 * possible. 1494 * 1495 * @return OMX_ErrorNone = On Success 1496 * Appropriate error number in case any error happens. 1497 */ 1498/* ================================================================================ * */ 1499static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle) 1500{ 1501 OMX_ERRORTYPE eError = OMX_ErrorNone; 1502 OMX_ERRORTYPE eError1 = OMX_ErrorNone; 1503 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 1504 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1505 OMX_ERRORTYPE threadError = OMX_ErrorNone; 1506 int pthreadError = 0; 1507 1508 G722DEC_DPRINT("ComponentDeInit\n"); 1509 G722D_OMX_CONF_CHECK_CMD(pComponent,1,1) 1510 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate; 1511 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1) 1512 1513#ifdef DSP_RENDERING_ON 1514 close(G722d_fdwrite); 1515 close(G722d_fdread); 1516#endif 1517 1518 pComponentPrivate->bExitCompThrd = 1; 1519 1520 pthreadError = pthread_join(pComponentPrivate->ComponentThread, (void*)&threadError); 1521 if(0 != pthreadError) { 1522 G722DEC_DPRINT(":: First Error in ComponentDeinit: From pthread_join\n"); 1523 eError = OMX_ErrorHardware; 1524 goto EXIT; 1525 } 1526 1527 if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) { 1528 eError = OMX_ErrorInsufficientResources; 1529 G722DEC_DPRINT("%d :: Error while closing Component Thread\n",__LINE__); 1530 goto EXIT; 1531 } 1532 1533 eError1 = G722DEC_FreeCompResources(pHandle); 1534 if (OMX_ErrorNone != eError1) { 1535 if (OMX_ErrorNone == eError) { 1536 G722DEC_DPRINT(":: First Error in ComponentDeinit: From FreeCompResources\n"); 1537 eError = eError1; 1538 } 1539 } 1540 1541 if (pComponentPrivate->sDeviceString != NULL) { 1542 G722D_OMX_FREE(pComponentPrivate->sDeviceString); 1543 } 1544 1545 G722DEC_MEMPRINT(":: Freeing: pComponentPrivate = %p\n", pComponentPrivate); 1546 G722D_OMX_FREE(pComponentPrivate); 1547 G722DEC_DPRINT("::*********** ComponentDeinit is Done************** \n"); 1548 1549 EXIT: 1550 return eError; 1551} 1552 1553 1554/* ================================================================================= * */ 1555/** 1556 * @fn ComponentTunnelRequest() This function estabilishes the tunnel between two 1557 * components. This is not implemented currently. 1558 * 1559 * @param hComp Handle of this component. 1560 * 1561 * @param nPort Port of this component on which tunneling has to be done. 1562 * 1563 * @param hTunneledComp Handle of the component with which tunnel has to be 1564 * established. 1565 * 1566 * @param nTunneledPort Port of the tunneling component. 1567 * 1568 * @param pTunnelSetup Tunnel Setuup parameters. 1569 * 1570 * @pre None 1571 * 1572 * @post None 1573 * 1574 * @return OMX_ErrorNone = On Success 1575 * Appropriate error number in case any error happens. 1576 */ 1577/* ================================================================================ * */ 1578static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 1579 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 1580 OMX_U32 nTunneledPort, 1581 OMX_TUNNELSETUPTYPE* pTunnelSetup) 1582{ 1583 OMX_ERRORTYPE eError = OMX_ErrorNone; 1584 G722DEC_DPRINT (":: Entering ComponentTunnelRequest\n"); 1585 G722DEC_DPRINT (":: Inside ComponentTunnelRequest\n"); 1586 eError = OMX_ErrorNotImplemented; 1587 G722DEC_DPRINT (":: Exiting ComponentTunnelRequest\n"); 1588 return eError; 1589} 1590 1591 1592 1593/* ================================================================================= * */ 1594/** 1595 * @fn AllocateBuffer() This function allocated the memory for the buffer onm 1596 * request from application. 1597 * 1598 * @param hComponent Handle of this component. 1599 * 1600 * @param pBuffer Pointer to the buffer header. 1601 * 1602 * @param nPortIndex Input port or Output port 1603 * 1604 * @param pAppPrivate Application private data. 1605 * 1606 * @param nSizeBytes Size of the buffer that is to be allocated. 1607 * 1608 * @pre None 1609 * 1610 * @post Requested buffer should get the memory allocated. 1611 * 1612 * @return OMX_ErrorNone = On Success 1613 * OMX_ErrorBadPortIndex = Bad port index from app 1614 */ 1615/* ================================================================================ * */ 1616static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 1617 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 1618 OMX_IN OMX_U32 nPortIndex, 1619 OMX_IN OMX_PTR pAppPrivate, 1620 OMX_IN OMX_U32 nSizeBytes) 1621{ 1622 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1623 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1624 OMX_ERRORTYPE eError = OMX_ErrorNone; 1625 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 1626 1627 1628 G722DEC_DPRINT (":: Entering AllocateBuffer\n"); 1629 G722D_OMX_CONF_CHECK_CMD(hComponent,1,1) 1630 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *) 1631 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1632 1633 G722D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1) 1634 1635 pPortDef = ((G722DEC_COMPONENT_PRIVATE*) 1636 pComponentPrivate)->pPortDef[nPortIndex]; 1637 1638 G722D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1) 1639 1640 if (!pPortDef->bEnabled) { 1641 pComponentPrivate->AlloBuf_waitingsignal = 1; 1642#ifndef UNDER_CE 1643 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1644 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, 1645 &pComponentPrivate->AlloBuf_mutex); 1646 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1647#else 1648 OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event)); 1649#endif 1650 } 1651 1652 G722D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE); 1653 1654 /* Needed for cache synchronization between ARM and DSP */ 1655 G722D_OMX_MALLOC_SIZE(pBufferHeader->pBuffer,(nSizeBytes + 256),OMX_U8); 1656 pBufferHeader->pBuffer += 128; 1657 /*pBufferHeader->pBuffer = (OMX_U8 *)malloc(nSizeBytes + 256); 1658 if(NULL == pBufferHeader->pBuffer) { 1659 G722DEC_DPRINT(":: Malloc Failed\n"); 1660 eError = OMX_ErrorInsufficientResources; 1661 goto EXIT; 1662 } 1663 memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE)); 1664 G722DEC_MEMPRINT(":: Malloced = %p\n",pBufferHeader->pBuffer);*/ 1665 pBufferHeader->nVersion.nVersion = G722DEC_BUFHEADER_VERSION; 1666 1667 1668 G722DEC_DPRINT("********************************************\n"); 1669 G722DEC_DPRINT(":: Allocated BufHeader %p Buffer = %p, on port %ld\n", 1670 pBufferHeader, 1671 pBufferHeader->pBuffer, nPortIndex); 1672 1673 G722DEC_DPRINT(":: Ip Num = %ld\n",pComponentPrivate->pInputBufferList->numBuffers); 1674 G722DEC_DPRINT(":: Op Num = %ld\n",pComponentPrivate->pOutputBufferList->numBuffers); 1675 G722DEC_DPRINT("********************************************\n"); 1676 1677 1678 pBufferHeader->pAppPrivate = pAppPrivate; 1679 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1680 pBufferHeader->nAllocLen = nSizeBytes; 1681 1682 if (nPortIndex == G722D_INPUT_PORT) { 1683 pBufferHeader->nInputPortIndex = nPortIndex; 1684 pBufferHeader->nOutputPortIndex = -1; 1685 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 1686 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 1687 1688 G722DEC_DPRINT("pComponentPrivate->pInputBufferList->pBufHdr[%ld] = %p\n", 1689 pComponentPrivate->pInputBufferList->numBuffers, 1690 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]); 1691 1692 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1; 1693 1694 G722DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %ld\n", 1695 pComponentPrivate->pInputBufferList->numBuffers); 1696 1697 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1698 pPortDef->bPopulated = 1; 1699 } 1700 } else if (nPortIndex == G722D_OUTPUT_PORT) { 1701 pBufferHeader->nInputPortIndex = -1; 1702 pBufferHeader->nOutputPortIndex = nPortIndex; 1703 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1704 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1705 1706 G722DEC_DPRINT("pComponentPrivate->pOutputBufferList->pBufHdr[%ld] = %p\n", 1707 pComponentPrivate->pOutputBufferList->numBuffers, 1708 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]); 1709 1710 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1; 1711 1712 G722DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %ld\n", 1713 pComponentPrivate->pOutputBufferList->numBuffers); 1714 1715 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1716 pPortDef->bPopulated = 1; 1717 } 1718 } else { 1719 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex"); 1720 } 1721 1722 if((pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bPopulated == 1723 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bEnabled)&& 1724 (pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bPopulated == 1725 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bEnabled) && 1726 (pComponentPrivate->InLoaded_readytoidle)) { 1727 pComponentPrivate->InLoaded_readytoidle = 0; 1728#ifndef UNDER_CE 1729 1730 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 1731 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 1732 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 1733#else 1734 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 1735#endif 1736 } 1737 1738 pBufferHeader->pAppPrivate = pAppPrivate; 1739 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1740 pBufferHeader->nAllocLen = nSizeBytes; 1741 1742 pBufferHeader->nVersion.s.nVersionMajor = G722DEC_MAJOR_VER; 1743 pBufferHeader->nVersion.s.nVersionMinor = G722DEC_MINOR_VER; 1744 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 1745 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 1746 1747 *pBuffer = pBufferHeader; 1748 pComponentPrivate->bufAlloced = 1; 1749 G722DEC_DPRINT("%d:: A Buffer has been alloced\n", __LINE__); 1750 1751 EXIT: 1752 if(OMX_ErrorNone != eError) { 1753 G722DEC_DPRINT("%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__); 1754 if (NULL != pBufferHeader) { 1755 G722D_OMX_FREE(pBufferHeader->pBuffer); 1756 G722D_OMX_FREE(pBufferHeader); 1757 } 1758 } 1759 1760 return eError; 1761} 1762 1763/* ================================================================================= * */ 1764/** 1765 * @fn FreeBuffer() This function frees the meomory of the buffer specified. 1766 * 1767 * @param hComponent Handle of this component. 1768 * 1769 * @param nPortIndex Input port or Output port 1770 * 1771 * @param pBuffer Pointer to the buffer header. 1772 * 1773 * @pre None 1774 * 1775 * @post Requested buffer should get the memory allocated. 1776 * 1777 * @return OMX_ErrorNone = On Success 1778 * OMX_ErrorBadPortIndex = Bad port index from app 1779 */ 1780/* ================================================================================ * */ 1781static OMX_ERRORTYPE FreeBuffer( 1782 OMX_IN OMX_HANDLETYPE hComponent, 1783 OMX_IN OMX_U32 nPortIndex, 1784 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 1785{ 1786 OMX_ERRORTYPE eError = OMX_ErrorNone; 1787 G722DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL; 1788 OMX_U8* buff = NULL; 1789 int i = 0; 1790 int inputIndex = -1; 1791 int outputIndex = -1; 1792 OMX_COMPONENTTYPE *pHandle = NULL; 1793 1794 G722DEC_DPRINT ("Entering FreeBuffer\n"); 1795 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *) (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1796 1797 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 1798 for (i=0; i < MAX_NUM_OF_BUFS; i++) { 1799 buff = (OMX_U8 *)pComponentPrivate->pInputBufferList->pBufHdr[i]; 1800 if (buff == (OMX_U8 *)pBuffer) { 1801 G722DEC_DPRINT("Found matching input buffer\n"); 1802 G722DEC_DPRINT("buff = %p\n",buff); 1803 G722DEC_DPRINT("pBuffer = %p\n",pBuffer); 1804 inputIndex = i; 1805 break; 1806 }else{ 1807 G722DEC_DPRINT("%d:: No matching found for pBuffer %p\n",__LINE__,pBuffer); 1808 } 1809 } 1810 1811 for (i=0; i < MAX_NUM_OF_BUFS; i++) { 1812 buff = (OMX_U8 *)pComponentPrivate->pOutputBufferList->pBufHdr[i]; 1813 if (buff == (OMX_U8 *)pBuffer) { 1814 G722DEC_DPRINT("Found matching output buffer\n"); 1815 G722DEC_DPRINT("buff = %p\n",buff); 1816 G722DEC_DPRINT("pBuffer = %p\n",pBuffer); 1817 outputIndex = i; 1818 break; 1819 }else{ 1820 G722DEC_DPRINT("%d:: No matching found for pBuffer %p\n",__LINE__,pBuffer); 1821 } 1822 } 1823 1824 if (inputIndex != -1) { 1825 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) { 1826 buff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer; 1827 if(buff != 0){ 1828 buff -= 128; 1829 } 1830 G722DEC_MEMPRINT("\n: Freeing: %p IP Buffer\n",buff); 1831 G722D_OMX_FREE(buff); 1832 } 1833 1834 G722DEC_MEMPRINT("Freeing: %p IP Buf Header\n\n", 1835 pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]); 1836 1837 G722D_OMX_FREE(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]); 1838 pComponentPrivate->pInputBufferList->numBuffers--; 1839 1840 if (pComponentPrivate->pInputBufferList->numBuffers < 1841 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->nBufferCountMin) { 1842 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bPopulated = OMX_FALSE; 1843 } 1844 if(pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bEnabled && 1845 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 1846 (pComponentPrivate->curState == OMX_StateIdle || 1847 pComponentPrivate->curState == OMX_StateExecuting || 1848 pComponentPrivate->curState == OMX_StatePause)) { 1849 1850 pComponentPrivate->cbInfo.EventHandler( 1851 pHandle, pHandle->pApplicationPrivate, 1852 OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL); 1853 } 1854 } else if (outputIndex != -1) { 1855 if (pComponentPrivate->pOutputBufferList->bBufferPending[outputIndex]) { 1856 pComponentPrivate->numPendingBuffers++; 1857 } 1858 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) { 1859 buff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer; 1860 if(buff != 0){ 1861 buff -= 128; 1862 } 1863 G722DEC_MEMPRINT("Freeing: %p OP Buffer\n",buff); 1864 G722D_OMX_FREE(buff); 1865 } 1866 1867 G722DEC_MEMPRINT("Freeing: %p OP Buf Header\n\n", 1868 pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]); 1869 1870 G722D_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]); 1871 pComponentPrivate->pOutputBufferList->numBuffers--; 1872 1873 G722DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %ld\n", 1874 pComponentPrivate->pOutputBufferList->numBuffers); 1875 G722DEC_DPRINT("pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nBufferCountMin = %ld\n", 1876 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nBufferCountMin); 1877 1878 if (pComponentPrivate->pOutputBufferList->numBuffers < 1879 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->nBufferCountMin) { 1880 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bPopulated = OMX_FALSE; 1881 } 1882 1883 if(pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bEnabled && 1884 pComponentPrivate->bLoadedCommandPending == OMX_FALSE && 1885 (pComponentPrivate->curState == OMX_StateIdle || 1886 pComponentPrivate->curState == OMX_StateExecuting || 1887 pComponentPrivate->curState == OMX_StatePause)) { 1888 pComponentPrivate->cbInfo.EventHandler( 1889 pHandle, pHandle->pApplicationPrivate, 1890 OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL); 1891 } 1892 } else { 1893 G722DEC_DPRINT("Returning OMX_ErrorBadParameter\n"); 1894 eError = OMX_ErrorBadParameter; 1895 } 1896 1897 if ((!pComponentPrivate->pInputBufferList->numBuffers && 1898 !pComponentPrivate->pOutputBufferList->numBuffers) && 1899 pComponentPrivate->InIdle_goingtoloaded){ 1900 pComponentPrivate->InIdle_goingtoloaded = 0; 1901#ifndef UNDER_CE 1902 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1903 pthread_cond_signal(&pComponentPrivate->InIdle_threshold); 1904 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 1905#else 1906 OMX_SignalEvent(&(pComponentPrivate->InIdle_event)); 1907#endif 1908 } 1909 1910 pComponentPrivate->bufAlloced = 0; 1911 if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers + 1912 pComponentPrivate->pOutputBufferList->numBuffers == 0)) { 1913 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable, 1914 pComponentPrivate->bDisableCommandParam,NULL); 1915 } 1916 1917 G722DEC_DPRINT ("Exiting FreeBuffer\n"); 1918 return eError; 1919} 1920 1921 1922/* ================================================================================= * */ 1923/** 1924 * @fn UseBuffer() This function is called by application when app allocated the 1925 * memory for the buffer and sends it to application for use of component. 1926 * 1927 * @param hComponent Handle of this component. 1928 * 1929 * @param ppBufferHdr Double pointer to the buffer header. 1930 * 1931 * @param nPortIndex Input port or Output port 1932 * 1933 * @param pAppPrivate Application private data. 1934 * 1935 * @param nSizeBytes Size of the buffer that is to be allocated. 1936 * 1937 * @param pBuffer Pointer to data buffer which was allocated by the 1938 * application. 1939 * 1940 * @pre None 1941 * 1942 * @post None 1943 * 1944 * @return OMX_ErrorNone = On Success 1945 * OMX_ErrorBadPortIndex = Bad port index from app 1946 */ 1947/* ================================================================================ * */ 1948static OMX_ERRORTYPE UseBuffer ( 1949 OMX_IN OMX_HANDLETYPE hComponent, 1950 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 1951 OMX_IN OMX_U32 nPortIndex, 1952 OMX_IN OMX_PTR pAppPrivate, 1953 OMX_IN OMX_U32 nSizeBytes, 1954 OMX_IN OMX_U8* pBuffer) 1955{ 1956 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1957 G722DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1958 OMX_ERRORTYPE eError = OMX_ErrorNone; 1959 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 1960 1961 G722DEC_DPRINT ("Entering UseBuffer\n"); 1962 G722DEC_DPRINT ("pBuffer = %p\n",pBuffer); 1963 1964 pComponentPrivate = (G722DEC_COMPONENT_PRIVATE *) 1965 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1966 1967 pPortDef = ((G722DEC_COMPONENT_PRIVATE*) 1968 pComponentPrivate)->pPortDef[nPortIndex]; 1969 G722DEC_DPRINT ("pPortDef = %p\n", pPortDef); 1970 G722DEC_DPRINT ("pPortDef->bEnabled = %d\n",pPortDef->bEnabled); 1971 1972 if(!pPortDef->bEnabled) { 1973 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation, 1974 "Port is Disabled: OMX_ErrorIncorrectStateOperation"); 1975 } 1976#if 1 1977 if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) { 1978 G722D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter, 1979 "Bad Size or Port Disabled : OMX_ErrorBadParameter"); 1980 } 1981#endif 1982 1983 G722D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE); 1984 1985 if (nPortIndex == G722D_OUTPUT_PORT) { 1986 pBufferHeader->nInputPortIndex = -1; 1987 pBufferHeader->nOutputPortIndex = nPortIndex; 1988 1989 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1990 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1991 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0; 1992 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1993 pPortDef->bPopulated = OMX_TRUE; 1994 } 1995 } 1996 else { 1997 pBufferHeader->nInputPortIndex = nPortIndex; 1998 pBufferHeader->nOutputPortIndex = -1; 1999 2000 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 2001 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 2002 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0; 2003 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 2004 pPortDef->bPopulated = OMX_TRUE; 2005 } 2006 } 2007 2008 if((pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bPopulated == 2009 pComponentPrivate->pPortDef[G722D_OUTPUT_PORT]->bEnabled)&& 2010 (pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bPopulated == 2011 pComponentPrivate->pPortDef[G722D_INPUT_PORT]->bEnabled) && 2012 (pComponentPrivate->InLoaded_readytoidle)) { 2013 pComponentPrivate->InLoaded_readytoidle = 0; 2014#ifndef UNDER_CE 2015 2016 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 2017 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 2018 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 2019#else 2020 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 2021#endif 2022 } 2023 2024 pBufferHeader->pAppPrivate = pAppPrivate; 2025 pBufferHeader->pPlatformPrivate = pComponentPrivate; 2026 pBufferHeader->nAllocLen = nSizeBytes; 2027 2028 pBufferHeader->nVersion.s.nVersionMajor = G722DEC_MAJOR_VER; 2029 pBufferHeader->nVersion.s.nVersionMinor = G722DEC_MINOR_VER; 2030 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 2031 2032 pBufferHeader->pBuffer = pBuffer; 2033 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 2034 *ppBufferHdr = pBufferHeader; 2035 pComponentPrivate->bufAlloced = 1; 2036 2037 EXIT: 2038 return eError; 2039} 2040 2041/* ================================================================================= */ 2042/** 2043 * @fn GetExtensionIndex() description for GetExtensionIndex 2044 GetExtensionIndex(). 2045 Returns index for vendor specific settings. 2046 * 2047 * @see OMX_Core.h 2048 */ 2049/* ================================================================================ */ 2050static OMX_ERRORTYPE GetExtensionIndex( 2051 OMX_IN OMX_HANDLETYPE hComponent, 2052 OMX_IN OMX_STRING cParameterName, 2053 OMX_OUT OMX_INDEXTYPE* pIndexType) 2054{ 2055 OMX_ERRORTYPE eError = OMX_ErrorNone; 2056 2057 G722DEC_DPRINT("GetExtensionIndex\n"); 2058 if (!(strcmp(cParameterName,"OMX.TI.index.config.g722headerinfo"))) { 2059 *pIndexType = OMX_IndexCustomG722DecHeaderInfoConfig; 2060 G722DEC_DPRINT("OMX_IndexCustomG722DecHeaderInfoConfig\n"); 2061 } 2062 else if(!(strcmp(cParameterName,"OMX.TI.index.config.g722decstreamIDinfo"))){ 2063 *pIndexType = OMX_IndexCustomG722DecStreamIDConfig; 2064 G722DEC_DPRINT("OMX_IndexCustomG722DecStreamIDConfig\n"); 2065 } 2066 else if(!(strcmp(cParameterName,"OMX.TI.index.config.g722dec.datapath"))) { 2067 *pIndexType = OMX_IndexCustomG722DecDataPath; 2068 G722DEC_DPRINT("OMX_IndexCustomG722DecDataPath\n"); 2069 } 2070 else { 2071 eError = OMX_ErrorBadParameter; 2072 } 2073 2074 G722DEC_DPRINT("Exiting GetExtensionIndex\n"); 2075 return eError; 2076} 2077 2078/* ================================================================================= */ 2079/** 2080 * @fn ComponentRoleEnum() description for ComponentRoleEnum() 2081 2082 Returns the role at the given index 2083 * 2084 * @see OMX_Core.h 2085 */ 2086/* ================================================================================ */ 2087static OMX_ERRORTYPE ComponentRoleEnum( 2088 OMX_IN OMX_HANDLETYPE hComponent, 2089 OMX_OUT OMX_U8 *cRole, 2090 OMX_IN OMX_U32 nIndex) 2091{ 2092 /* This is a non standard component and does not support roles */ 2093 OMX_ERRORTYPE eError = OMX_ErrorNotImplemented; 2094 2095 return eError; 2096} 2097#ifdef UNDER_CE 2098/* ================================================================================= */ 2099/** 2100 * @fns Sleep replace for WIN CE 2101 */ 2102/* ================================================================================ */ 2103int OMX_CreateEvent(OMX_Event *event){ 2104 int ret = OMX_ErrorNone; 2105 HANDLE createdEvent = NULL; 2106 if(event == NULL){ 2107 ret = OMX_ErrorBadParameter; 2108 MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n"); 2109 goto EXIT; 2110 } 2111 event->event = CreateEvent(NULL, TRUE, FALSE, NULL); 2112 if(event->event == NULL) 2113 ret = (int)GetLastError(); 2114 EXIT: 2115 return ret; 2116} 2117 2118int OMX_SignalEvent(OMX_Event *event){ 2119 int ret = OMX_ErrorNone; 2120 if(event == NULL){ 2121 ret = OMX_ErrorBadParameter; 2122 MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n"); 2123 goto EXIT; 2124 } 2125 SetEvent(event->event); 2126 ret = (int)GetLastError(); 2127 EXIT: 2128 return ret; 2129} 2130 2131int OMX_WaitForEvent(OMX_Event *event) { 2132 int ret = OMX_ErrorNone; 2133 if(event == NULL){ 2134 ret = OMX_ErrorBadParameter; 2135 MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n"); 2136 goto EXIT; 2137 } 2138 WaitForSingleObject(event->event, INFINITE); 2139 ret = (int)GetLastError(); 2140 EXIT: 2141 return ret; 2142} 2143 2144int OMX_DestroyEvent(OMX_Event *event) { 2145 int ret = OMX_ErrorNone; 2146 if(event == NULL){ 2147 ret = OMX_ErrorBadParameter; 2148 MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n"); 2149 goto EXIT; 2150 } 2151 CloseHandle(event->event); 2152 EXIT: 2153 return ret; 2154} 2155#endif 2156