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_G726Encoder.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\g726_enc\src 35* 36* @rev 1.0 37*/ 38/* ---------------------------------------------------------------------------- 39*! 40*! Revision History 41*! =================================== 42*! Gyancarlo Garcia: Initial Verision 43*! 05-Oct-2007 44*! 45* =========================================================================== */ 46/* ------compilation control switches -------------------------*/ 47/**************************************************************** 48* INCLUDE FILES 49****************************************************************/ 50/* ----- system and platform files ----------------------------*/ 51#ifdef UNDER_CE 52#include <windows.h> 53#include <oaf_osal.h> 54#include <omx_core.h> 55#else 56#include <unistd.h> 57#include <sys/time.h> 58#include <sys/types.h> 59#include <sys/ioctl.h> 60#include <sys/select.h> 61#include <errno.h> 62#include <pthread.h> 63#endif 64 65#include <string.h> 66#include <fcntl.h> 67#include <stdlib.h> 68#include <stdio.h> 69#include <dbapi.h> 70 71/*-------program files ----------------------------------------*/ 72#include <OMX_Component.h> 73 74#include "OMX_G726Enc_Utils.h" 75 76/**************************************************************** 77* EXTERNAL REFERENCES NOTE : only use if not found in header file 78****************************************************************/ 79/*--------data declarations -----------------------------------*/ 80 81/*--------function prototypes ---------------------------------*/ 82 83/**************************************************************** 84* PUBLIC DECLARATIONS Defined here, used elsewhere 85****************************************************************/ 86/*--------data declarations --------------------------------*/ 87 88/*--------function prototypes ---------------------------------*/ 89 90/**************************************************************** 91* PRIVATE DECLARATIONS Defined here, used only here 92****************************************************************/ 93/*--------data declarations -----------------------------------*/ 94 95/*--------function prototypes ---------------------------------*/ 96#ifdef G726ENC_DEBUGMEM 97extern void * DebugMalloc(int line, char *s, int size); 98extern int DebugFree(void *dp, int line, char *s); 99 100#define SafeMalloc(x) DebugMalloc(__LINE__,__FILE__,x) 101#define SafeFree(z) DebugFree(z,__LINE__,__FILE__) 102#else 103#define SafeMalloc(x) calloc(1,x) 104#define SafeFree(z) free(z) 105#endif 106 107 108static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp, 109 OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData); 110static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 111 OMX_STRING pComponentName, 112 OMX_VERSIONTYPE* pComponentVersion, 113 OMX_VERSIONTYPE* pSpecVersion, 114 OMX_UUIDTYPE* pComponentUUID); 115static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand, 116 OMX_U32 nParam,OMX_PTR pCmdData); 117static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, 118 OMX_PTR ComponentParamStruct); 119static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, 120 OMX_INDEXTYPE nParamIndex, 121 OMX_PTR ComponentParamStruct); 122static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 123 OMX_INDEXTYPE nConfigIndex, 124 OMX_PTR pComponentConfigStructure); 125static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 126 OMX_INDEXTYPE nConfigIndex, 127 OMX_PTR pComponentConfigStructure); 128 129static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 130 131static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer); 132static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState); 133static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 134 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 135 OMX_U32 nTunneledPort, 136 OMX_TUNNELSETUPTYPE* pTunnelSetup); 137static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle); 138static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 139 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 140 OMX_IN OMX_U32 nPortIndex, 141 OMX_IN OMX_PTR pAppPrivate, 142 OMX_IN OMX_U32 nSizeBytes); 143 144static OMX_ERRORTYPE FreeBuffer( 145 OMX_IN OMX_HANDLETYPE hComponent, 146 OMX_IN OMX_U32 nPortIndex, 147 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer); 148 149static OMX_ERRORTYPE UseBuffer ( 150 OMX_IN OMX_HANDLETYPE hComponent, 151 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 152 OMX_IN OMX_U32 nPortIndex, 153 OMX_IN OMX_PTR pAppPrivate, 154 OMX_IN OMX_U32 nSizeBytes, 155 OMX_IN OMX_U8* pBuffer); 156 157static OMX_ERRORTYPE GetExtensionIndex( 158 OMX_IN OMX_HANDLETYPE hComponent, 159 OMX_IN OMX_STRING cParameterName, 160 OMX_OUT OMX_INDEXTYPE* pIndexType); 161 162static OMX_ERRORTYPE ComponentRoleEnum( 163 OMX_IN OMX_HANDLETYPE hComponent, 164 OMX_OUT OMX_U8 *cRole, 165 OMX_IN OMX_U32 nIndex); 166 167/* interface with audio manager*/ 168#define FIFO1 "/dev/fifo.1" 169#define FIFO2 "/dev/fifo.2" 170#define PERMS 0666 171 172/*-------------------------------------------------------------------*/ 173/** 174 * OMX_ComponentInit() Set the all the function pointers of component 175 * 176 * This method will update the component function pointer to the handle 177 * 178 * @param hComp handle for this instance of the component 179 * 180 * @retval OMX_NoError Success, ready to roll 181 * OMX_ErrorInsufficientResources If the malloc fails 182 **/ 183/*-------------------------------------------------------------------*/ 184OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp) 185{ 186 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL; 187 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 188 OMX_AUDIO_PARAM_G726TYPE *G726_op = NULL; 189 OMX_AUDIO_PARAM_G726TYPE *G726_ip = NULL; 190 OMX_ERRORTYPE eError = OMX_ErrorNone; 191 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 192 G726ENC_PORT_TYPE *pCompPort = NULL; 193 OMX_AUDIO_PARAM_PORTFORMATTYPE *pPortFormat = NULL; 194 int i = 0; 195 196 G726ENC_DPRINT("%d :: Entering OMX_ComponentInit\n", __LINE__); 197 /*Set the all component function pointer to the handle */ 198 pHandle->SetCallbacks = SetCallbacks; 199 pHandle->GetComponentVersion = GetComponentVersion; 200 pHandle->SendCommand = SendCommand; 201 pHandle->GetParameter = GetParameter; 202 pHandle->SetParameter = SetParameter; 203 pHandle->GetConfig = GetConfig; 204 pHandle->SetConfig = SetConfig; 205 pHandle->GetState = GetState; 206 pHandle->EmptyThisBuffer = EmptyThisBuffer; 207 pHandle->FillThisBuffer = FillThisBuffer; 208 pHandle->ComponentTunnelRequest = ComponentTunnelRequest; 209 pHandle->ComponentDeInit = ComponentDeInit; 210 pHandle->AllocateBuffer = AllocateBuffer; 211 pHandle->FreeBuffer = FreeBuffer; 212 pHandle->UseBuffer = UseBuffer; 213 pHandle->GetExtensionIndex = GetExtensionIndex; 214 pHandle->ComponentRoleEnum = ComponentRoleEnum; 215 216 /*Allocate the memory for Component private data area */ 217 OMX_NBMALLOC_STRUCT(pHandle->pComponentPrivate, G726ENC_COMPONENT_PRIVATE); 218 memset(pHandle->pComponentPrivate, 0x0, sizeof(G726ENC_COMPONENT_PRIVATE)); 219 220 ((G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle; 221 pComponentPrivate = pHandle->pComponentPrivate; 222 223 OMX_NBMALLOC_STRUCT(pCompPort, G726ENC_PORT_TYPE); 224 pComponentPrivate->pCompPort[G726ENC_INPUT_PORT] = pCompPort; 225 226 OMX_NBMALLOC_STRUCT(pCompPort, G726ENC_PORT_TYPE); 227 pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT] = pCompPort; 228 229 OMX_NBMALLOC_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE); 230 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE); 231 232 /* Initialize sPortParam data structures to default values */ 233 pComponentPrivate->sPortParam->nPorts = 0x2; 234 pComponentPrivate->sPortParam->nStartPortNumber = 0x0; 235 236 /* Malloc and Set pPriorityMgmt defaults */ 237 OMX_NBMALLOC_STRUCT(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE); 238 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE); 239 240 /* Initialize sPriorityMgmt data structures to default values */ 241 pComponentPrivate->sPriorityMgmt->nGroupPriority = -1; 242 pComponentPrivate->sPriorityMgmt->nGroupID = -1; 243 244 OMX_NBMALLOC_STRUCT(G726_op, OMX_AUDIO_PARAM_G726TYPE); 245 OMX_NBCONF_INIT_STRUCT(G726_op, OMX_AUDIO_PARAM_G726TYPE); 246 pComponentPrivate->G726Params[G726ENC_OUTPUT_PORT] = G726_op; 247 G726_op->nPortIndex = G726ENC_OUTPUT_PORT; 248 249 OMX_NBMALLOC_STRUCT(G726_ip, OMX_AUDIO_PARAM_G726TYPE); 250 OMX_NBCONF_INIT_STRUCT(G726_ip, OMX_AUDIO_PARAM_G726TYPE); 251 pComponentPrivate->G726Params[G726ENC_INPUT_PORT] = G726_ip; 252 G726_ip->nPortIndex = G726ENC_INPUT_PORT; 253 254 /* malloc and initialize number of input buffers */ 255 OMX_NBMALLOC_STRUCT(pComponentPrivate->pInputBufferList, G726ENC_BUFFERLIST); 256 pComponentPrivate->pInputBufferList->numBuffers = 0; 257 258 /* malloc and initialize number of output buffers */ 259 OMX_NBMALLOC_STRUCT(pComponentPrivate->pOutputBufferList, G726ENC_BUFFERLIST); 260 pComponentPrivate->pOutputBufferList->numBuffers = 0; 261 262 for (i=0; i < G726ENC_MAX_NUM_OF_BUFS; i++) { 263 pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL; 264 pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL; 265 pComponentPrivate->arrTickCount[i] = 0; 266 pComponentPrivate->arrTimestamp[i] = 0; 267 } 268 pComponentPrivate->IpBufindex = 0; 269 pComponentPrivate->OpBufindex = 0; 270 271 /* Set input port defaults */ 272 OMX_NBMALLOC_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE); 273 OMX_NBCONF_INIT_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE); 274 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT] = pPortDef_ip; 275 276 pPortDef_ip->nPortIndex = G726ENC_INPUT_PORT; 277 pPortDef_ip->eDir = OMX_DirInput; 278 pPortDef_ip->nBufferCountActual = G726ENC_NUM_INPUT_BUFFERS; 279 pPortDef_ip->nBufferCountMin = G726ENC_NUM_INPUT_BUFFERS; 280 pPortDef_ip->nBufferSize = G726ENC_INPUT_BUFFER_SIZE_DASF; 281 pPortDef_ip->bEnabled = OMX_TRUE; 282 pPortDef_ip->bPopulated = OMX_FALSE; 283 pPortDef_ip->eDomain = OMX_PortDomainAudio; 284 pPortDef_ip->format.audio.eEncoding = OMX_AUDIO_CodingPCM; 285 pPortDef_ip->format.audio.pNativeRender = NULL; 286 pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE; 287 288 /* Set output port defaults */ 289 OMX_NBMALLOC_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE); 290 OMX_NBCONF_INIT_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE); 291 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT] = pPortDef_op; 292 293 pPortDef_op->nPortIndex = G726ENC_OUTPUT_PORT; 294 pPortDef_op->eDir = OMX_DirOutput; 295 pPortDef_op->nBufferCountMin = G726ENC_NUM_OUTPUT_BUFFERS; 296 pPortDef_op->nBufferCountActual = G726ENC_NUM_OUTPUT_BUFFERS; 297 pPortDef_op->nBufferSize = G726ENC_OUTPUT_BUFFER_SIZE; 298 pPortDef_op->bEnabled = OMX_TRUE; 299 pPortDef_op->bPopulated = OMX_FALSE; 300 pPortDef_op->eDomain = OMX_PortDomainAudio; 301 pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingG726; 302 pPortDef_op->format.audio.pNativeRender = NULL; 303 pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE; 304 305 OMX_NBMALLOC_STRUCT(pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 306 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 307 /* Set input port format defaults */ 308 pPortFormat = pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat; 309 OMX_NBCONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 310 pPortFormat->nPortIndex = G726ENC_INPUT_PORT; 311 pPortFormat->nIndex = OMX_IndexParamAudioPcm; 312 pPortFormat->eEncoding = OMX_AUDIO_CodingPCM; 313 314 OMX_NBMALLOC_STRUCT(pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 315 OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 316 /* Set output port format defaults */ 317 pPortFormat = pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat; 318 OMX_NBCONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE); 319 pPortFormat->nPortIndex = G726ENC_OUTPUT_PORT; 320 pPortFormat->nIndex = OMX_IndexParamAudioPcm; 321 pPortFormat->eEncoding = OMX_AUDIO_CodingG726; 322 323 G726ENC_DPRINT("%d :: Setting dasf & acdn and MultiFrame modes to 0\n",__LINE__); 324 pComponentPrivate->dasfMode = 0; 325 pComponentPrivate->acdnMode = 0; 326 pComponentPrivate->rtpMode = 0; 327 pComponentPrivate->bPortDefsAllocated = 0; 328 pComponentPrivate->bCompThreadStarted = 0; 329 pComponentPrivate->pParams = NULL; 330 331 pComponentPrivate->bInitParamsInitialized = 0; 332 pComponentPrivate->pMarkBuf = NULL; 333 pComponentPrivate->pMarkData = NULL; 334 pComponentPrivate->nEmptyBufferDoneCount = 0; 335 pComponentPrivate->nEmptyThisBufferCount = 0; 336 pComponentPrivate->nFillBufferDoneCount = 0; 337 pComponentPrivate->nFillThisBufferCount = 0; 338 pComponentPrivate->strmAttr = NULL; 339 pComponentPrivate->bDisableCommandParam = 0; 340 341 342 for (i=0; i < G726ENC_MAX_NUM_OF_BUFS; i++) { 343 pComponentPrivate->pInputBufHdrPending[i] = NULL; 344 pComponentPrivate->pOutputBufHdrPending[i] = NULL; 345 } 346 347 pComponentPrivate->nNumInputBufPending = 0; 348 pComponentPrivate->nNumOutputBufPending = 0; 349 pComponentPrivate->bDisableCommandPending = 0; 350 pComponentPrivate->bNoIdleOnStop= OMX_FALSE; 351 pComponentPrivate->nOutStandingFillDones = 0; 352 pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE; 353 354 pComponentPrivate->G726FrameSize[0] = 24; 355 pComponentPrivate->G726FrameSize[1] = 20; 356 pComponentPrivate->G726FrameSize[2] = 4; 357 pComponentPrivate->G726FrameSize[3] = 1; 358 pComponentPrivate->lastOutBufArrived = NULL; 359 pComponentPrivate->LastBufSent = 0; 360 pComponentPrivate->bPreempted = OMX_FALSE; 361 362 strcpy((char*)pComponentPrivate->componentRole.cRole, "audio_encoder.g726"); 363 pComponentPrivate->sDeviceString = SafeMalloc(100*sizeof(OMX_STRING)); 364 if (pComponentPrivate->sDeviceString == NULL) { 365 G726ENC_DPRINT("%d :: OMX_ErrorInsufficientResources", __LINE__); 366 eError = OMX_ErrorInsufficientResources; 367 goto EXIT; 368 } 369 /* Initialize device string to the default value */ 370 strcpy((char*)pComponentPrivate->sDeviceString,":srcul/codec\0"); 371 372#ifndef UNDER_CE 373 pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL); 374 pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL); 375 pComponentPrivate->AlloBuf_waitingsignal = 0; 376 377 pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL); 378 pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL); 379 pComponentPrivate->InLoaded_readytoidle = 0; 380 381 pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL); 382 pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL); 383 pComponentPrivate->InIdle_goingtoloaded = 0; 384#endif 385 386 eError = G726ENC_StartComponentThread(pHandle); 387 G726ENC_DPRINT("%d :: OMX_ComponentInit\n", __LINE__); 388 if (eError != OMX_ErrorNone) { 389 G726ENC_DPRINT("%d :: Error returned from the Component\n",__LINE__); 390 goto EXIT; 391 } 392 393#ifdef RESOURCE_MANAGER_ENABLED 394 eError = RMProxy_NewInitalize(); 395 G726ENC_DPRINT("%d :: OMX_ComponentInit\n", __LINE__); 396 if (eError != OMX_ErrorNone) { 397 G726ENC_DPRINT("%d :: Error returned from loading ResourceManagerProxy thread\n",__LINE__); 398 goto EXIT; 399 } 400#endif 401 402EXIT: 403 G726ENC_DPRINT("%d :: Exiting OMX_ComponentInit\n", __LINE__); 404 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 405 return eError; 406} 407 408/*-------------------------------------------------------------------*/ 409/** 410 * SetCallbacks() Sets application callbacks to the component 411 * 412 * This method will update application callbacks 413 * to the component. So that component can make use of those call back 414 * while sending buffers to the application. And also it will copy the 415 * application private data to component memory 416 * 417 * @param pComponent handle for this instance of the component 418 * @param pCallBacks application callbacks 419 * @param pAppData Application private data 420 * 421 * @retval OMX_NoError Success, ready to roll 422 * OMX_Error_BadParameter The input parameter pointer is null 423 **/ 424/*-------------------------------------------------------------------*/ 425 426static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent, 427 OMX_CALLBACKTYPE* pCallBacks, 428 OMX_PTR pAppData) 429{ 430 OMX_ERRORTYPE eError = OMX_ErrorNone; 431 432 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent; 433 434 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = 435 (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 436 G726ENC_DPRINT("%d :: Entering SetCallbacks\n", __LINE__); 437 if (pCallBacks == NULL) { 438 eError = OMX_ErrorBadParameter; 439 G726ENC_DPRINT("%d :: Received the empty callbacks from the application\n",__LINE__); 440 goto EXIT; 441 } 442 443 /*Copy the callbacks of the application to the component private*/ 444 memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE)); 445 446 /*copy the application private data to component memory */ 447 pHandle->pApplicationPrivate = pAppData; 448 449 pComponentPrivate->curState = OMX_StateLoaded; 450 451EXIT: 452 G726ENC_DPRINT("%d :: Exiting SetCallbacks\n", __LINE__); 453 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 454 return eError; 455} 456 457/*-------------------------------------------------------------------*/ 458/** 459 * GetComponentVersion() This will return the component version 460 * 461 * This method will retrun the component version 462 * 463 * @param hComp handle for this instance of the component 464 * @param pCompnentName Name of the component 465 * @param pCompnentVersion handle for this instance of the component 466 * @param pSpecVersion application callbacks 467 * @param pCompnentUUID 468 * 469 * @retval OMX_NoError Success, ready to roll 470 * OMX_Error_BadParameter The input parameter pointer is null 471 **/ 472/*-------------------------------------------------------------------*/ 473 474static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 475 OMX_STRING pComponentName, 476 OMX_VERSIONTYPE* pComponentVersion, 477 OMX_VERSIONTYPE* pSpecVersion, 478 OMX_UUIDTYPE* pComponentUUID) 479{ 480 OMX_ERRORTYPE eError = OMX_ErrorNone; 481 482 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp; 483 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 484 G726ENC_DPRINT("%d :: Entering GetComponentVersion\n", __LINE__); 485 /* Copy component version structure */ 486 if(pComponentVersion != NULL && pComponentName != NULL) { 487 strcpy(pComponentName, pComponentPrivate->cComponentName); 488 memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), sizeof(pComponentPrivate->ComponentVersion.s)); 489 } 490 else { 491 G726ENC_DPRINT("%d :: OMX_ErrorBadParameter from GetComponentVersion",__LINE__); 492 eError = OMX_ErrorBadParameter; 493 } 494 495 G726ENC_DPRINT("%d :: Exiting GetComponentVersion\n", __LINE__); 496 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 497 return eError; 498} 499/*-------------------------------------------------------------------*/ 500/** 501 * SendCommand() used to send the commands to the component 502 * 503 * This method will be used by the application. 504 * 505 * @param phandle handle for this instance of the component 506 * @param Cmd Command to be sent to the component 507 * @param nParam indicates commmad is sent using this method 508 * 509 * @retval OMX_NoError Success, ready to roll 510 * OMX_Error_BadParameter The input parameter pointer is null 511 **/ 512/*-------------------------------------------------------------------*/ 513 514static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle, 515 OMX_COMMANDTYPE Cmd, 516 OMX_U32 nParam, 517 OMX_PTR pCmdData) 518{ 519 OMX_ERRORTYPE eError = OMX_ErrorNone; 520 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle; 521 G726ENC_COMPONENT_PRIVATE *pCompPrivate = 522 (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 523 int nRet = 0; 524 G726ENC_DPRINT("%d :: Entering SendCommand()\n", __LINE__); 525 if(pCompPrivate->curState == OMX_StateInvalid) { 526 eError = OMX_ErrorInvalidState; 527 G726ENC_DPRINT("%d :: Error OMX_ErrorInvalidState Sent to App\n",__LINE__); 528 goto EXIT; 529 } 530 531 switch(Cmd) { 532 case OMX_CommandStateSet: 533 G726ENC_DPRINT("%d :: OMX_CommandStateSet SendCommand\n",__LINE__); 534 if(pCompPrivate->curState == OMX_StateLoaded) { 535 if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) { 536 pCompPrivate->cbInfo.EventHandler ( pHandle, 537 pHandle->pApplicationPrivate, 538 OMX_EventError, 539 OMX_ErrorIncorrectStateTransition, 540 0, 541 NULL); 542 goto EXIT; 543 } 544 545 if(nParam == OMX_StateInvalid) { 546 G726ENC_DPRINT("%d :: OMX_CommandStateSet SendCommand\n",__LINE__); 547 pCompPrivate->curState = OMX_StateInvalid; 548 pCompPrivate->cbInfo.EventHandler ( pHandle, 549 pHandle->pApplicationPrivate, 550 OMX_EventError, 551 OMX_ErrorInvalidState, 552 0, 553 NULL); 554 goto EXIT; 555 } 556 } 557 break; 558 case OMX_CommandFlush: 559 G726ENC_DPRINT("%d :: OMX_CommandFlush SendCommand\n",__LINE__); 560 if(nParam > 1 && nParam != -1) { 561 eError = OMX_ErrorBadPortIndex; 562 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from SendCommand",__LINE__); 563 goto EXIT; 564 } 565 break; 566 case OMX_CommandPortDisable: 567 G726ENC_DPRINT("%d :: OMX_CommandPortDisable SendCommand\n",__LINE__); 568 break; 569 case OMX_CommandPortEnable: 570 G726ENC_DPRINT("%d :: OMX_CommandPortEnable SendCommand\n",__LINE__); 571 break; 572 case OMX_CommandMarkBuffer: 573 G726ENC_DPRINT("%d :: OMX_CommandMarkBuffer SendCommand\n",__LINE__); 574 if (nParam > 0) { 575 eError = OMX_ErrorBadPortIndex; 576 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from SendCommand",__LINE__); 577 goto EXIT; 578 } 579 break; 580 default: 581 G726ENC_DPRINT("%d :: Command Received Default eError\n",__LINE__); 582 pCompPrivate->cbInfo.EventHandler ( pHandle, 583 pHandle->pApplicationPrivate, 584 OMX_EventError, 585 OMX_ErrorUndefined, 586 0, 587 "Invalid Command"); 588 break; 589 590 } 591 592 nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd)); 593 if (nRet == -1) { 594 eError = OMX_ErrorInsufficientResources; 595 G726ENC_DPRINT("%d :: OMX_ErrorInsufficientResources from SendCommand",__LINE__); 596 goto EXIT; 597 } 598 599 if (Cmd == OMX_CommandMarkBuffer) { 600 nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, 601 sizeof(OMX_PTR)); 602 } else { 603 nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, 604 sizeof(OMX_U32)); 605 } 606 if (nRet == -1) { 607 G726ENC_DPRINT("%d :: OMX_ErrorInsufficientResources from SendCommand",__LINE__); 608 eError = OMX_ErrorInsufficientResources; 609 goto EXIT; 610 } 611 612EXIT: 613 G726ENC_DPRINT("%d :: Exiting SendCommand()\n", __LINE__); 614 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 615 return eError; 616} 617/*-------------------------------------------------------------------*/ 618/** 619 * GetParameter() Gets the current configurations of the component 620 * 621 * @param hComp handle for this instance of the component 622 * @param nParamIndex 623 * @param ComponentParameterStructure 624 * 625 * @retval OMX_NoError Success, ready to roll 626 * OMX_Error_BadParameter The input parameter pointer is null 627 **/ 628/*-------------------------------------------------------------------*/ 629 630static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp, 631 OMX_INDEXTYPE nParamIndex, 632 OMX_PTR ComponentParameterStructure) 633{ 634 OMX_ERRORTYPE eError = OMX_ErrorNone; 635 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 636 OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL; 637 638 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 639 pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure; 640 G726ENC_DPRINT("%d :: Entering the GetParameter\n",__LINE__); 641 if (pParameterStructure == NULL) { 642 eError = OMX_ErrorBadParameter; 643 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from GetParameter",__LINE__); 644 goto EXIT; 645 } 646 647 if(pComponentPrivate->curState == OMX_StateInvalid) { 648 eError = OMX_ErrorIncorrectStateOperation; 649 G726ENC_DPRINT("%d :: OMX_ErrorIncorrectStateOperation from GetParameter",__LINE__); 650 goto EXIT; 651 } 652 653 switch(nParamIndex){ 654 case OMX_IndexParamAudioInit: 655 if (pComponentPrivate->sPortParam == NULL) { 656 eError = OMX_ErrorBadParameter; 657 break; 658 } 659 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamAudioInit \n",__LINE__); 660 memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE)); 661 break; 662 663 case OMX_IndexParamPortDefinition: 664 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamPortDefinition \n",__LINE__); 665 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 666 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nPortIndex) { 667 memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G726ENC_INPUT_PORT], sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 668 } 669 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex == 670 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nPortIndex) { 671 memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT], sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 672 } 673 else { 674 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from GetParameter \n",__LINE__); 675 eError = OMX_ErrorBadPortIndex; 676 } 677 break; 678 679 case OMX_IndexParamAudioPortFormat: 680 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamAudioPortFormat \n",__LINE__); 681 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == 682 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nPortIndex) { 683 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > 684 pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat->nPortIndex) { 685 eError = OMX_ErrorNoMore; 686 } 687 else { 688 memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 689 } 690 } 691 else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex == 692 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nPortIndex){ 693 if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex > 694 pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat->nPortIndex) { 695 eError = OMX_ErrorNoMore; 696 } 697 else { 698 memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 699 } 700 } 701 else { 702 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from GetParameter \n",__LINE__); 703 eError = OMX_ErrorBadPortIndex; 704 } 705 break; 706 707 case OMX_IndexParamAudioPcm: 708 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamAudioG726 \n",__LINE__); 709 if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex == 710 pComponentPrivate->G726Params[G726ENC_OUTPUT_PORT]->nPortIndex) { 711 memcpy(ComponentParameterStructure, pComponentPrivate->G726Params[G726ENC_OUTPUT_PORT], sizeof(OMX_AUDIO_PARAM_PCMMODETYPE)); 712 713 } 714 else { 715 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from GetParameter \n",__LINE__); 716 eError = OMX_ErrorBadPortIndex; 717 } 718 break; 719 720 case OMX_IndexParamPriorityMgmt: 721 if (pComponentPrivate->sPriorityMgmt == NULL) { 722 eError = OMX_ErrorBadParameter; 723 break; 724 } 725 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamPriorityMgmt \n",__LINE__); 726 memcpy(ComponentParameterStructure, pComponentPrivate->sPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE)); 727 break; 728 729 case OMX_IndexParamVideoInit: 730 break; 731 732 case OMX_IndexParamImageInit: 733 break; 734 735 case OMX_IndexParamOtherInit: 736 break; 737 738 default: 739 G726ENC_DPRINT("%d :: OMX_ErrorUnsupportedIndex GetParameter \n",__LINE__); 740 eError = OMX_ErrorUnsupportedIndex; 741 break; 742 } 743EXIT: 744 G726ENC_DPRINT("%d :: Exiting GetParameter\n",__LINE__); 745 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 746 return eError; 747} 748/*-------------------------------------------------------------------*/ 749/** 750 * SetParameter() Sets configuration paramets to the component 751 * 752 * @param hComp handle for this instance of the component 753 * @param nParamIndex 754 * @param pCompParam 755 * 756 * @retval OMX_NoError Success, ready to roll 757 * OMX_Error_BadParameter The input parameter pointer is null 758 **/ 759/*-------------------------------------------------------------------*/ 760 761static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, 762 OMX_INDEXTYPE nParamIndex, 763 OMX_PTR pCompParam) 764{ 765 OMX_ERRORTYPE eError = OMX_ErrorNone; 766 OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp; 767 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 768 OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL; 769 OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL; 770 OMX_AUDIO_PARAM_G726TYPE *pCompG726Param = NULL; 771 772 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate); 773 774 775 G726ENC_DPRINT("%d :: Entering the SetParameter\n",__LINE__); 776 if (pCompParam == NULL) { 777 eError = OMX_ErrorBadParameter; 778 G726ENC_DPRINT("%d :: OMX_ErrorBadParameter from SetParameter",__LINE__); 779 goto EXIT; 780 } 781 if (pComponentPrivate->curState != OMX_StateLoaded) { 782 eError = OMX_ErrorIncorrectStateOperation; 783 G726ENC_DPRINT("%d :: OMX_ErrorIncorrectStateOperation from SetParameter",__LINE__); 784 goto EXIT; 785 } 786 787 switch(nParamIndex) { 788 case OMX_IndexParamAudioPortFormat: 789 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioPortFormat \n",__LINE__); 790 pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam; 791 if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat->nPortIndex ) { 792 memcpy(pComponentPrivate->pCompPort[G726ENC_INPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 793 } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat->nPortIndex ) { 794 memcpy(pComponentPrivate->pCompPort[G726ENC_OUTPUT_PORT]->pPortFormat, pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE)); 795 } else { 796 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from SetParameter",__LINE__); 797 eError = OMX_ErrorBadPortIndex; 798 } 799 break; 800 case OMX_IndexParamAudioG726: 801 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioG726 \n",__LINE__); 802 pCompG726Param = (OMX_AUDIO_PARAM_G726TYPE *)pCompParam; 803 if (pCompG726Param->nPortIndex == OMX_DirOutput) { 804 if (((G726ENC_COMPONENT_PRIVATE *) 805 pHandle->pComponentPrivate)->G726Params[G726ENC_OUTPUT_PORT] == NULL) { 806 eError = OMX_ErrorBadParameter; 807 break; 808 } 809 memcpy(((G726ENC_COMPONENT_PRIVATE *) 810 pHandle->pComponentPrivate)->G726Params[G726ENC_OUTPUT_PORT], pCompG726Param, sizeof(OMX_AUDIO_PARAM_G726TYPE)); 811 } 812 else if (pCompG726Param->nPortIndex == OMX_DirInput) { 813 if (((G726ENC_COMPONENT_PRIVATE *) 814 pHandle->pComponentPrivate)->G726Params[G726ENC_INPUT_PORT] == NULL) { 815 eError = OMX_ErrorBadParameter; 816 break; 817 } 818 memcpy(((G726ENC_COMPONENT_PRIVATE *) 819 pHandle->pComponentPrivate)->G726Params[G726ENC_INPUT_PORT], pCompG726Param, sizeof(OMX_AUDIO_PARAM_G726TYPE)); 820 } 821 else { 822 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from SetParameter",__LINE__); 823 eError = OMX_ErrorBadPortIndex; 824 } 825 break; 826 case OMX_IndexParamPortDefinition: 827 828 pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam; 829 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamPortDefinition \n",__LINE__); 830 if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nPortIndex) { 831 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamPortDefinition \n",__LINE__); 832 memcpy(pComponentPrivate->pPortDef[G726ENC_INPUT_PORT], pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 833 } 834 else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex == pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nPortIndex) { 835 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamPortDefinition \n",__LINE__); 836 memcpy(pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT], pCompParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 837 } 838 else { 839 G726ENC_DPRINT("%d :: OMX_ErrorBadPortIndex from SetParameter",__LINE__); 840 eError = OMX_ErrorBadPortIndex; 841 } 842 break; 843 case OMX_IndexParamPriorityMgmt: 844 if (pComponentPrivate->sPriorityMgmt == NULL) { 845 eError = OMX_ErrorBadParameter; 846 break; 847 } 848 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamPriorityMgmt \n",__LINE__); 849 memcpy(pComponentPrivate->sPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE)); 850 break; 851 852 case OMX_IndexParamAudioInit: 853 if (pComponentPrivate->sPortParam == NULL) { 854 eError = OMX_ErrorBadParameter; 855 break; 856 } 857 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__); 858 memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE)); 859 break; 860 default: 861 G726ENC_DPRINT("%d :: SetParameter OMX_ErrorUnsupportedIndex \n",__LINE__); 862 eError = OMX_ErrorUnsupportedIndex; 863 break; 864 } 865EXIT: 866 G726ENC_DPRINT("%d :: Exiting SetParameter\n",__LINE__); 867 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 868 return eError; 869} 870 871/*-------------------------------------------------------------------*/ 872/** 873 * GetConfig() Gets the current configuration of to the component 874 * 875 * @param hComp handle for this instance of the component 876 * @param nConfigIndex 877 * @param ComponentConfigStructure 878 * 879 * @retval OMX_NoError Success, ready to roll 880 * OMX_Error_BadParameter The input parameter pointer is null 881 **/ 882/*-------------------------------------------------------------------*/ 883 884static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp, 885 OMX_INDEXTYPE nConfigIndex, 886 OMX_PTR ComponentConfigStructure) 887{ 888 OMX_ERRORTYPE eError = OMX_ErrorNone; 889 TI_OMX_STREAM_INFO *streamInfo = NULL; 890 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp; 891 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = 892 (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 893 894 if(nConfigIndex == OMX_IndexCustomG726ENCStreamIDConfig){ 895 OMX_NBMALLOC_STRUCT(streamInfo, TI_OMX_STREAM_INFO); 896 if(streamInfo == NULL){ 897 eError = OMX_ErrorBadParameter; 898 goto EXIT; 899 } 900 streamInfo->streamId = pComponentPrivate->streamID; 901 memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO)); 902 OMX_NBMEMFREE_STRUCT(streamInfo); 903 } 904EXIT: 905 G726ENC_DPRINT("%d :: Entering GetConfig\n", __LINE__); 906 G726ENC_DPRINT("%d :: Exiting GetConfig\n", __LINE__); 907 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 908 return eError; 909} 910/*-------------------------------------------------------------------*/ 911/** 912 * SetConfig() Sets the configraiton to the component 913 * 914 * @param hComp handle for this instance of the component 915 * @param nConfigIndex 916 * @param ComponentConfigStructure 917 * 918 * @retval OMX_NoError Success, ready to roll 919 * OMX_Error_BadParameter The input parameter pointer is null 920 **/ 921/*-------------------------------------------------------------------*/ 922 923static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp, 924 OMX_INDEXTYPE nConfigIndex, 925 OMX_PTR ComponentConfigStructure) 926{ 927 OMX_ERRORTYPE eError = OMX_ErrorNone; 928 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 929 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp; 930 TI_OMX_DSP_DEFINITION *pTiDspDefinition = NULL; 931 TI_OMX_DATAPATH dataPath; 932 OMX_S16 *customFlag = NULL; 933 OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL; 934 OMX_U32 fdwrite = 0; 935 936#ifdef DSP_RENDERING_ON 937 AM_COMMANDDATATYPE cmd_data; 938#endif 939 G726ENC_DPRINT("%d :: Entering SetConfig\n", __LINE__); 940 if (pHandle == NULL) { 941 G726ENC_DPRINT ("%d :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__); 942 eError = OMX_ErrorBadParameter; 943 goto EXIT; 944 } 945 946 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 947 switch (nConfigIndex) { 948 949 case OMX_IndexCustomG726ENCModeConfig: 950 pTiDspDefinition = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure; 951 if (pTiDspDefinition == NULL) { 952 eError = OMX_ErrorBadParameter; 953 G726ENC_DPRINT("%d :: OMX_ErrorBadParameter from SetConfig\n",__LINE__); 954 goto EXIT; 955 } 956 pComponentPrivate->dasfMode = pTiDspDefinition->dasfMode; 957 pComponentPrivate->acdnMode = pTiDspDefinition->acousticMode; 958 pComponentPrivate->rtpMode = pTiDspDefinition->rtpMode; 959 pComponentPrivate->streamID = pTiDspDefinition->streamId; 960 break; 961 case OMX_IndexCustomG726ENCDataPath: 962 customFlag = (OMX_S16*)ComponentConfigStructure; 963 dataPath = *customFlag; 964 switch(dataPath) { 965 case DATAPATH_APPLICATION: 966 G726ENC_DPRINT("------>Stream ID on SetConfig %d\n", (int)pComponentPrivate->streamID); 967 OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_ENCODER, pComponentPrivate->streamID); 968 break; 969 970 case DATAPATH_APPLICATION_RTMIXER: 971 strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING_ENCODER); 972 break; 973 974 case DATAPATH_ACDN: 975 strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING_ENCODER); 976 break; 977 default: 978 break; 979 980 } 981 break; 982 case OMX_IndexConfigAudioVolume: 983#ifdef DSP_RENDERING_ON 984 if((fdwrite=open(FIFO1,O_WRONLY))<0) { 985 G726ENC_DPRINT("%d :: [NBAMRE Encoder Component] - failure to open WRITE pipe\n",__LINE__); 986 } 987 else{ 988 pGainStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure; 989 cmd_data.hComponent = hComp; 990 cmd_data.AM_Cmd = AM_CommandSWGain; 991 cmd_data.param1 = pGainStructure->sVolume.nValue; 992 cmd_data.param2 = 0; 993 cmd_data.streamID = pComponentPrivate->streamID; 994 995 if((write(fdwrite, &cmd_data, sizeof(cmd_data)))<0) 996 { 997 G726ENC_DPRINT("[G726 encoder] - fail to send command to audio manager\n"); 998 } 999 else 1000 { 1001 G726ENC_DPRINT("[G726 encoder] - ok to send command to audio manager\n"); 1002 } 1003 close(fdwrite); 1004 } 1005#endif 1006 default: 1007 eError = OMX_ErrorUnsupportedIndex; 1008 break; 1009 } 1010EXIT: 1011 G726ENC_DPRINT("%d :: Exiting SetConfig\n", __LINE__); 1012 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1013 return eError; 1014} 1015 1016/*-------------------------------------------------------------------*/ 1017/** 1018 * GetState() Gets the current state of the component 1019 * 1020 * @param pCompomponent handle for this instance of the component 1021 * @param pState 1022 * 1023 * @retval OMX_NoError Success, ready to roll 1024 * OMX_Error_BadParameter The input parameter pointer is null 1025 **/ 1026/*-------------------------------------------------------------------*/ 1027 1028static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState) 1029{ 1030 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 1031 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1032 G726ENC_DPRINT("%d :: Entering GetState\n", __LINE__); 1033 if (!pState) { 1034 eError = OMX_ErrorBadParameter; 1035 G726ENC_DPRINT("%d :: OMX_ErrorBadParameter from GetState\n",__LINE__); 1036 goto EXIT; 1037 } 1038 1039 if (pHandle && pHandle->pComponentPrivate) { 1040 *pState = ((G726ENC_COMPONENT_PRIVATE*) 1041 pHandle->pComponentPrivate)->curState; 1042 } else { 1043 *pState = OMX_StateLoaded; 1044 } 1045 eError = OMX_ErrorNone; 1046 1047EXIT: 1048 G726ENC_DPRINT("%d :: Exiting GetState\n", __LINE__); 1049 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1050 return eError; 1051} 1052 1053/*-------------------------------------------------------------------*/ 1054/** 1055 * EmptyThisBuffer() This callback is used to send the input buffer to 1056 * component 1057 * 1058 * @param pComponent handle for this instance of the component 1059 * @param nPortIndex input port index 1060 * @param pBuffer buffer to be sent to codec 1061 * 1062 * @retval OMX_NoError Success, ready to roll 1063 * OMX_Error_BadParameter The input parameter pointer is null 1064 **/ 1065/*-------------------------------------------------------------------*/ 1066 1067static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent, 1068 OMX_BUFFERHEADERTYPE* pBuffer) 1069{ 1070 OMX_ERRORTYPE eError = OMX_ErrorNone; 1071 int ret = 0; 1072 1073 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1074 1075 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1076 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = 1077 (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1078 pPortDef = ((G726ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[G726ENC_INPUT_PORT]; 1079 1080 G726ENC_DPRINT("%d :: Entering EmptyThisBuffer\n", __LINE__); 1081 if (pBuffer == NULL) { 1082 eError = OMX_ErrorBadParameter; 1083 G726ENC_DPRINT("%d :: About to return OMX_ErrorBadParameter\n",__LINE__); 1084 goto EXIT; 1085 } 1086 1087 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1088 eError = OMX_ErrorBadParameter; 1089 G726ENC_DPRINT("%d :: About to return OMX_ErrorBadParameter\n",__LINE__); 1090 goto EXIT; 1091 } 1092 1093 if (!pPortDef->bEnabled) { 1094 eError = OMX_ErrorIncorrectStateOperation; 1095 G726ENC_DPRINT("%d :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1096 goto EXIT; 1097 } 1098 1099 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1100 eError = OMX_ErrorVersionMismatch; 1101 G726ENC_DPRINT("%d :: About to return OMX_ErrorVersionMismatch\n",__LINE__); 1102 goto EXIT; 1103 } 1104 1105 if (pBuffer->nInputPortIndex != G726ENC_INPUT_PORT) { 1106 eError = OMX_ErrorBadPortIndex; 1107 G726ENC_DPRINT("%d :: About to return OMX_ErrorBadPortIndex\n",__LINE__); 1108 goto EXIT; 1109 } 1110 1111 if (pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) { 1112 eError= OMX_ErrorIncorrectStateOperation; 1113 G726ENC_DPRINT("%d :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1114 goto EXIT; 1115 } 1116 1117 1118 G726ENC_DPRINT("----------------------------------------------------------------\n"); 1119 G726ENC_DPRINT("%d :: Comp Sending Filled ip buff = %p to CompThread\n",__LINE__,pBuffer); 1120 G726ENC_DPRINT("----------------------------------------------------------------\n"); 1121 1122 1123 1124 pComponentPrivate->pMarkData = pBuffer->pMarkData; 1125 pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent; 1126 1127 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof(OMX_BUFFERHEADERTYPE*)); 1128 if (ret == -1) { 1129 G726ENC_DPRINT("%d :: Error in Writing to the Data pipe\n", __LINE__); 1130 eError = OMX_ErrorHardware; 1131 goto EXIT; 1132 } 1133 pComponentPrivate->nEmptyThisBufferCount++; 1134EXIT: 1135 G726ENC_DPRINT("%d :: Exiting EmptyThisBuffer\n", __LINE__); 1136 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1137 return eError; 1138} 1139/*-------------------------------------------------------------------*/ 1140/** 1141 * FillThisBuffer() This callback is used to send the output buffer to 1142 * the component 1143 * 1144 * @param pComponent handle for this instance of the component 1145 * @param nPortIndex output port number 1146 * @param pBuffer buffer to be sent to codec 1147 * 1148 * @retval OMX_NoError Success, ready to roll 1149 * OMX_Error_BadParameter The input parameter pointer is null 1150 **/ 1151/*-------------------------------------------------------------------*/ 1152 1153static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent, 1154 OMX_BUFFERHEADERTYPE* pBuffer) 1155{ 1156 OMX_ERRORTYPE eError = OMX_ErrorNone; 1157 int ret = 0; 1158 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1159 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent; 1160 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = 1161 (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate; 1162 pPortDef = ((G726ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[G726ENC_OUTPUT_PORT]; 1163 G726ENC_DPRINT("%d :: Entering FillThisBuffer\n", __LINE__); 1164 G726ENC_DPRINT("------------------------------------------------------------------\n"); 1165 G726ENC_DPRINT("%d :: Comp Sending Emptied op buff = %p to CompThread\n",__LINE__,pBuffer); 1166 G726ENC_DPRINT("------------------------------------------------------------------\n"); 1167 if (pBuffer == NULL) { 1168 eError = OMX_ErrorBadParameter; 1169 G726ENC_DPRINT(" %d :: About to return OMX_ErrorBadParameter\n",__LINE__); 1170 goto EXIT; 1171 } 1172 1173 if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) { 1174 eError = OMX_ErrorBadParameter; 1175 G726ENC_DPRINT(" %d :: About to return OMX_ErrorBadParameter\n",__LINE__); 1176 goto EXIT; 1177 } 1178 1179 if (!pPortDef->bEnabled) { 1180 eError = OMX_ErrorIncorrectStateOperation; 1181 G726ENC_DPRINT("%d :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1182 goto EXIT; 1183 } 1184 1185 if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) { 1186 eError = OMX_ErrorVersionMismatch; 1187 G726ENC_DPRINT(" %d :: About to return OMX_ErrorVersionMismatch\n",__LINE__); 1188 goto EXIT; 1189 } 1190 1191 if (pBuffer->nOutputPortIndex != G726ENC_OUTPUT_PORT) { 1192 eError = OMX_ErrorBadPortIndex; 1193 G726ENC_DPRINT(" %d :: About to return OMX_ErrorBadPortIndex\n",__LINE__); 1194 goto EXIT; 1195 } 1196 1197 if(pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) { 1198 eError = OMX_ErrorIncorrectStateOperation; 1199 G726ENC_DPRINT("%d :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1200 goto EXIT; 1201 } 1202 1203 pBuffer->nFilledLen = 0; 1204 /*Filling the Output buffer with zero */ 1205 memset(pBuffer->pBuffer, 0, pBuffer->nAllocLen); 1206 1207 1208 if(pComponentPrivate->pMarkBuf != NULL){ 1209 pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent; 1210 pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData; 1211 pComponentPrivate->pMarkBuf = NULL; 1212 } 1213 1214 if (pComponentPrivate->pMarkData != NULL) { 1215 pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent; 1216 pBuffer->pMarkData = pComponentPrivate->pMarkData; 1217 pComponentPrivate->pMarkData = NULL; 1218 } 1219 ret = write (pComponentPrivate->dataPipe[1], &pBuffer, sizeof (OMX_BUFFERHEADERTYPE*)); 1220 if (ret == -1) { 1221 G726ENC_DPRINT("%d :: Error in Writing to the Data pipe\n", __LINE__); 1222 eError = OMX_ErrorHardware; 1223 goto EXIT; 1224 } 1225 pComponentPrivate->nFillThisBufferCount++; 1226EXIT: 1227 G726ENC_DPRINT("%d :: Exiting FillThisBuffer\n", __LINE__); 1228 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1229 return eError; 1230} 1231/*-------------------------------------------------------------------*/ 1232/** 1233 * OMX_ComponentDeinit() this methold will de init the component 1234 * 1235 * @param pComp handle for this instance of the component 1236 * 1237 * @retval OMX_NoError Success, ready to roll 1238 * OMX_Error_BadParameter The input parameter pointer is null 1239 **/ 1240/*-------------------------------------------------------------------*/ 1241 1242static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle) 1243{ 1244 OMX_ERRORTYPE eError = OMX_ErrorNone; 1245 1246 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 1247 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = 1248 (G726ENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate; 1249 G726ENC_DPRINT("%d :: Entering ComponentDeInit\n", __LINE__); 1250 1251#ifdef RESOURCE_MANAGER_ENABLED 1252 eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_G726_Encoder_COMPONENT, 0, 3456,NULL); 1253 if (eError != OMX_ErrorNone) { 1254 G726ENC_DPRINT ("%d ::OMX_G726_Encoder.c :: Error returned from destroy ResourceManagerProxy thread\n", 1255 __LINE__); 1256 } 1257 eError = RMProxy_Deinitalize(); 1258 if (eError != OMX_ErrorNone) { 1259 G726ENC_DPRINT("%d :: Error from RMProxy_Deinitalize\n",__LINE__); 1260 goto EXIT; 1261 } 1262#endif 1263 1264 pComponentPrivate->bIsStopping = 1; 1265 eError = G726ENC_StopComponentThread(pHandle); 1266 if (eError != OMX_ErrorNone) { 1267 G726ENC_DPRINT("%d :: Error from G726ENC_StopComponentThread\n",__LINE__); 1268 goto EXIT; 1269 } 1270 /* Wait for thread to exit so we can get the status into "eError" */ 1271 /* close the pipe handles */ 1272 eError = G726ENC_FreeCompResources(pHandle); 1273 if (eError != OMX_ErrorNone) { 1274 G726ENC_DPRINT("%d :: Error from G726ENC_FreeCompResources\n",__LINE__); 1275 goto EXIT; 1276 } 1277 1278#ifndef UNDER_CE 1279 pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex); 1280 pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold); 1281 1282 pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex); 1283 pthread_cond_destroy(&pComponentPrivate->InIdle_threshold); 1284 1285 pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex); 1286 pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold); 1287#endif 1288 if (pComponentPrivate->sDeviceString != NULL) { 1289 SafeFree(pComponentPrivate->sDeviceString); 1290 } 1291 OMX_NBMEMFREE_STRUCT(pComponentPrivate); 1292EXIT: 1293 G726ENC_DPRINT("%d :: Exiting ComponentDeInit\n", __LINE__); 1294 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1295 return eError; 1296} 1297 1298/*-------------------------------------------------------------------*/ 1299/** 1300 * ComponentTunnelRequest() this method is not implemented in 1.5 1301 * 1302 * This method will update application callbacks 1303 * the application. 1304 * 1305 * @param pComp handle for this instance of the component 1306 * @param pCallBacks application callbacks 1307 * @param ptr 1308 * 1309 * @retval OMX_NoError Success, ready to roll 1310 * OMX_Error_BadParameter The input parameter pointer is null 1311 **/ 1312/*-------------------------------------------------------------------*/ 1313 1314static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp, 1315 OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp, 1316 OMX_U32 nTunneledPort, 1317 OMX_TUNNELSETUPTYPE* pTunnelSetup) 1318{ 1319 OMX_ERRORTYPE eError = OMX_ErrorNone; 1320 eError = OMX_ErrorNotImplemented; 1321 G726ENC_DPRINT("%d :: Entering ComponentTunnelRequest\n", __LINE__); 1322 G726ENC_DPRINT("%d :: Exiting ComponentTunnelRequest\n", __LINE__); 1323 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1324 return eError; 1325} 1326 1327/*-------------------------------------------------------------------*/ 1328/** 1329 * AllocateBuffer() 1330 1331 * @param pComp handle for this instance of the component 1332 * @param pCallBacks application callbacks 1333 * @param ptr 1334 * 1335 * @retval OMX_NoError Success, ready to roll 1336 * OMX_Error_BadParameter The input parameter pointer is null 1337 **/ 1338/*-------------------------------------------------------------------*/ 1339 1340static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent, 1341 OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer, 1342 OMX_IN OMX_U32 nPortIndex, 1343 OMX_IN OMX_PTR pAppPrivate, 1344 OMX_IN OMX_U32 nSizeBytes) 1345 1346{ 1347 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1348 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1349 OMX_ERRORTYPE eError = OMX_ErrorNone; 1350 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 1351 1352 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *) 1353 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1354 1355 pPortDef = ((G726ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex]; 1356 G726ENC_DPRINT("%d :: Entering AllocateBuffer\n", __LINE__); 1357 G726ENC_DPRINT("%d :: pPortDef = %p\n", __LINE__,pPortDef); 1358 G726ENC_DPRINT("%d :: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled); 1359 1360 if(!pPortDef->bEnabled) { 1361 pComponentPrivate->AlloBuf_waitingsignal = 1; 1362#ifndef UNDER_CE 1363 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 1364 pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex); 1365 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex); 1366#endif 1367 } 1368 1369 OMX_NBMALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE); 1370 memset(pBufferHeader, 0x0, sizeof(OMX_BUFFERHEADERTYPE)); 1371 1372 pBufferHeader->pBuffer = (OMX_U8 *)SafeMalloc(nSizeBytes + 256); 1373 G726ENC_MEMPRINT("%d :: ALLOCATING MEMORY = %p\n",__LINE__,pBufferHeader->pBuffer); 1374 if (pBufferHeader->pBuffer == NULL) { 1375 /* Free previously allocated memory before bailing */ 1376 if (pBufferHeader) { 1377 SafeFree(pBufferHeader); 1378 pBufferHeader = NULL; 1379 } 1380 eError = OMX_ErrorInsufficientResources; 1381 goto EXIT; 1382 } 1383 pBufferHeader->pBuffer += 128; 1384 1385 if (nPortIndex == G726ENC_INPUT_PORT) { 1386 pBufferHeader->nInputPortIndex = nPortIndex; 1387 pBufferHeader->nOutputPortIndex = -1; 1388 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 1389 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 1390 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1; 1391 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1392 pPortDef->bPopulated = OMX_TRUE; 1393 G726ENC_DPRINT("%d :: pPortDef->bPopulated = %d\n", __LINE__, pPortDef->bPopulated); 1394 } 1395 } 1396 else if (nPortIndex == G726ENC_OUTPUT_PORT) { 1397 pBufferHeader->nInputPortIndex = -1; 1398 pBufferHeader->nOutputPortIndex = nPortIndex; 1399 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1400 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1401 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1; 1402 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1403 pPortDef->bPopulated = OMX_TRUE; 1404 G726ENC_DPRINT("%d :: pPortDef->bPopulated = %d\n", __LINE__, pPortDef->bPopulated); 1405 } 1406 } 1407 else { 1408 eError = OMX_ErrorBadPortIndex; 1409 G726ENC_DPRINT(" %d :: About to return OMX_ErrorBadPortIndex\n",__LINE__); 1410 goto EXIT; 1411 } 1412 if ((!pComponentPrivate->dasfMode && /*File Mode*/ 1413 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated && 1414 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled && 1415 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated && 1416 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled && 1417 pComponentPrivate->InLoaded_readytoidle) 1418 || 1419 (pComponentPrivate->dasfMode && /*Dasf Mode*/ 1420 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated && 1421 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled && 1422 pComponentPrivate->InLoaded_readytoidle)){ 1423 pComponentPrivate->InLoaded_readytoidle = 0; 1424#ifndef UNDER_CE 1425 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 1426 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 1427 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 1428#else 1429 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 1430#endif 1431 } 1432 pBufferHeader->pAppPrivate = pAppPrivate; 1433 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1434 pBufferHeader->nAllocLen = nSizeBytes; 1435 pBufferHeader->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER; 1436 pBufferHeader->nVersion.s.nVersionMinor = G726ENC_MINOR_VER; 1437 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 1438 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 1439 *pBuffer = pBufferHeader; 1440EXIT: 1441 G726ENC_DPRINT("%d :: Exiting AllocateBuffer\n",__LINE__); 1442 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1443 return eError; 1444} 1445 1446/*-------------------------------------------------------------------*/ 1447/** 1448 * FreeBuffer() 1449 1450 * @param hComponent handle for this instance of the component 1451 * @param pCallBacks application callbacks 1452 * @param ptr 1453 * 1454 * @retval OMX_NoError Success, ready to roll 1455 * OMX_Error_BadParameter The input parameter pointer is null 1456 **/ 1457/*-------------------------------------------------------------------*/ 1458 1459static OMX_ERRORTYPE FreeBuffer( 1460 OMX_IN OMX_HANDLETYPE hComponent, 1461 OMX_IN OMX_U32 nPortIndex, 1462 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) 1463{ 1464 OMX_ERRORTYPE eError = OMX_ErrorNone; 1465 G726ENC_COMPONENT_PRIVATE * pComponentPrivate = NULL; 1466 OMX_BUFFERHEADERTYPE* buff = NULL; 1467 OMX_U8* tempBuff = NULL; 1468 int i = 0; 1469 int inputIndex = -1; 1470 int outputIndex = -1; 1471 OMX_COMPONENTTYPE *pHandle = NULL; 1472 1473 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *) 1474 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1475 1476 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle; 1477 1478 G726ENC_DPRINT("%d :: Entering FreeBuffer\n", __LINE__); 1479 for (i=0; i < G726ENC_MAX_NUM_OF_BUFS; i++) { 1480 buff = pComponentPrivate->pInputBufferList->pBufHdr[i]; 1481 if (buff == pBuffer) { 1482 G726ENC_DPRINT("%d :: Found matching input buffer\n",__LINE__); 1483 G726ENC_DPRINT("%d :: buff = %p\n",__LINE__,buff); 1484 G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer); 1485 inputIndex = i; 1486 break; 1487 } 1488 else { 1489 G726ENC_DPRINT("%d :: This is not a match\n",__LINE__); 1490 G726ENC_DPRINT("%d :: buff = %p\n",__LINE__,buff); 1491 G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer); 1492 } 1493 } 1494 1495 for (i=0; i < G726ENC_MAX_NUM_OF_BUFS; i++) { 1496 buff = pComponentPrivate->pOutputBufferList->pBufHdr[i]; 1497 if (buff == pBuffer) { 1498 G726ENC_DPRINT("%d :: Found matching output buffer\n",__LINE__); 1499 G726ENC_DPRINT("%d :: buff = %p\n",__LINE__,buff); 1500 G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer); 1501 outputIndex = i; 1502 break; 1503 } 1504 else { 1505 G726ENC_DPRINT("%d :: This is not a match\n",__LINE__); 1506 G726ENC_DPRINT("%d :: buff = %p\n",__LINE__,buff); 1507 G726ENC_DPRINT("%d :: pBuffer = %p\n",__LINE__,pBuffer); 1508 } 1509 } 1510 1511 1512 if (inputIndex != -1) { 1513 if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) { 1514 tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer; 1515 tempBuff -= 128; 1516 OMX_NBMEMFREE_STRUCT(tempBuff); 1517 } 1518 1519 OMX_NBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]); 1520 1521 pComponentPrivate->pInputBufferList->numBuffers--; 1522 if (pComponentPrivate->pInputBufferList->numBuffers < 1523 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->nBufferCountMin) { 1524 1525 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated = OMX_FALSE; 1526 } 1527 if(pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled && 1528 (pComponentPrivate->curState == OMX_StateIdle || 1529 pComponentPrivate->curState == OMX_StateExecuting || 1530 pComponentPrivate->curState == OMX_StatePause)) { 1531 pComponentPrivate->cbInfo.EventHandler( pHandle, 1532 pHandle->pApplicationPrivate, 1533 OMX_EventError, 1534 OMX_ErrorPortUnpopulated, 1535 nPortIndex, 1536 NULL); 1537 } 1538 } 1539 else if (outputIndex != -1) { 1540 if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) { 1541 tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer; 1542 tempBuff -= 128; 1543 OMX_NBMEMFREE_STRUCT(tempBuff); 1544 } 1545 OMX_NBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]); 1546 1547 pComponentPrivate->pOutputBufferList->numBuffers--; 1548 if (pComponentPrivate->pOutputBufferList->numBuffers < 1549 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->nBufferCountMin) { 1550 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated = OMX_FALSE; 1551 } 1552 if(pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled && 1553 (pComponentPrivate->curState == OMX_StateIdle || 1554 pComponentPrivate->curState == OMX_StateExecuting || 1555 pComponentPrivate->curState == OMX_StatePause)) { 1556 pComponentPrivate->cbInfo.EventHandler( pHandle, 1557 pHandle->pApplicationPrivate, 1558 OMX_EventError, 1559 OMX_ErrorPortUnpopulated, 1560 nPortIndex, 1561 NULL); 1562 } 1563 } 1564 else { 1565 G726ENC_DPRINT("%d :: Returning OMX_ErrorBadParameter\n",__LINE__); 1566 eError = OMX_ErrorBadParameter; 1567 } 1568 if ((!pComponentPrivate->pInputBufferList->numBuffers && 1569 !pComponentPrivate->pOutputBufferList->numBuffers) && 1570 pComponentPrivate->InIdle_goingtoloaded) 1571 { 1572 pComponentPrivate->InIdle_goingtoloaded = 0; 1573#ifndef UNDER_CE 1574 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex); 1575 pthread_cond_signal(&pComponentPrivate->InIdle_threshold); 1576 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex); 1577#endif 1578 } 1579 if (pComponentPrivate->bDisableCommandPending) { 1580 SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL); 1581 } 1582 G726ENC_DPRINT("%d :: Exiting FreeBuffer\n", __LINE__); 1583 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1584 return eError; 1585} 1586 1587/*-------------------------------------------------------------------*/ 1588/** 1589 * UseBuffer() 1590 1591 * @param pComp handle for this instance of the component 1592 * @param pCallBacks application callbacks 1593 * @param ptr 1594 * 1595 * @retval OMX_NoError Success, ready to roll 1596 * OMX_Error_BadParameter The input parameter pointer is null 1597 **/ 1598/*-------------------------------------------------------------------*/ 1599static OMX_ERRORTYPE UseBuffer ( 1600 OMX_IN OMX_HANDLETYPE hComponent, 1601 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 1602 OMX_IN OMX_U32 nPortIndex, 1603 OMX_IN OMX_PTR pAppPrivate, 1604 OMX_IN OMX_U32 nSizeBytes, 1605 OMX_IN OMX_U8* pBuffer) 1606{ 1607 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; 1608 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1609 OMX_ERRORTYPE eError = OMX_ErrorNone; 1610 OMX_BUFFERHEADERTYPE *pBufferHeader = NULL; 1611 1612 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *) 1613 (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1614 1615 pPortDef = ((G726ENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex]; 1616 G726ENC_DPRINT("%d :: Entering UseBuffer\n", __LINE__); 1617 G726ENC_DPRINT("%d :: pPortDef->bPopulated = %d \n",__LINE__,pPortDef->bPopulated); 1618 1619 if(!pPortDef->bEnabled) { 1620 G726ENC_DPRINT("%d :: About to return OMX_ErrorIncorrectStateOperation\n",__LINE__); 1621 eError = OMX_ErrorIncorrectStateOperation; 1622 goto EXIT; 1623 } 1624 1625 if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) { 1626 G726ENC_DPRINT("%d :: About to return OMX_ErrorBadParameter\n",__LINE__); 1627 eError = OMX_ErrorBadParameter; 1628 goto EXIT; 1629 } 1630 1631 OMX_NBMALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE); 1632 memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE)); 1633 1634 if (nPortIndex == G726ENC_OUTPUT_PORT) { 1635 pBufferHeader->nInputPortIndex = -1; 1636 pBufferHeader->nOutputPortIndex = nPortIndex; 1637 pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader; 1638 pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0; 1639 pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0; 1640 if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1641 pPortDef->bPopulated = OMX_TRUE; 1642 } 1643 } 1644 else { 1645 pBufferHeader->nInputPortIndex = nPortIndex; 1646 pBufferHeader->nOutputPortIndex = -1; 1647 pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader; 1648 pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0; 1649 pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0; 1650 if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) { 1651 pPortDef->bPopulated = OMX_TRUE; 1652 } 1653 } 1654 1655if ((!pComponentPrivate->dasfMode && /*File Mode*/ 1656 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated && 1657 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled && 1658 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bPopulated && 1659 pComponentPrivate->pPortDef[G726ENC_INPUT_PORT]->bEnabled && 1660 pComponentPrivate->InLoaded_readytoidle) 1661 || 1662 (pComponentPrivate->dasfMode && /*Dasf Mode*/ 1663 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bPopulated && 1664 pComponentPrivate->pPortDef[G726ENC_OUTPUT_PORT]->bEnabled && 1665 pComponentPrivate->InLoaded_readytoidle)){ 1666 pComponentPrivate->InLoaded_readytoidle = 0; 1667#ifndef UNDER_CE 1668 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex); 1669 pthread_cond_signal(&pComponentPrivate->InLoaded_threshold); 1670 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex); 1671#else 1672 OMX_SignalEvent(&(pComponentPrivate->InLoaded_event)); 1673#endif 1674 } 1675 pBufferHeader->pAppPrivate = pAppPrivate; 1676 pBufferHeader->pPlatformPrivate = pComponentPrivate; 1677 pBufferHeader->nAllocLen = nSizeBytes; 1678 pBufferHeader->nVersion.s.nVersionMajor = G726ENC_MAJOR_VER; 1679 pBufferHeader->nVersion.s.nVersionMinor = G726ENC_MINOR_VER; 1680 pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion; 1681 pBufferHeader->pBuffer = pBuffer; 1682 pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE); 1683 *ppBufferHdr = pBufferHeader; 1684EXIT: 1685 G726ENC_DPRINT("%d :: Exiting UseBuffer\n", __LINE__); 1686 G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError); 1687 return eError; 1688} 1689 1690/* ================================================================================= */ 1691/** 1692* @fn GetExtensionIndex() description for GetExtensionIndex 1693GetExtensionIndex(). 1694Returns index for vendor specific settings. 1695* 1696* @see OMX_Core.h 1697*/ 1698/* ================================================================================ */ 1699static OMX_ERRORTYPE GetExtensionIndex( 1700 OMX_IN OMX_HANDLETYPE hComponent, 1701 OMX_IN OMX_STRING cParameterName, 1702 OMX_OUT OMX_INDEXTYPE* pIndexType) 1703{ 1704 OMX_ERRORTYPE eError = OMX_ErrorNone; 1705 1706 G726ENC_DPRINT("GetExtensionIndex\n"); 1707 if (!(strcmp(cParameterName,"OMX.TI.index.config.tispecific"))) { 1708 *pIndexType = OMX_IndexCustomG726ENCModeConfig; 1709 G726ENC_DPRINT("OMX.TI.index.config.tispecific\n"); 1710 } 1711 else if (!(strcmp(cParameterName,"OMX.TI.index.config.G726.streamIDinfo"))) { 1712 *pIndexType = OMX_IndexCustomG726ENCStreamIDConfig; 1713 G726ENC_DPRINT("OMX.TI.index.config.G726.streamIDinfo\n"); 1714 } 1715 else if (!(strcmp(cParameterName,"OMX.TI.index.config.G726.datapath"))) { 1716 *pIndexType = OMX_IndexCustomG726ENCDataPath; 1717 G726ENC_DPRINT("OMX.TI.index.config.G726.datapath\n"); 1718 } 1719 else { 1720 eError = OMX_ErrorBadParameter; 1721 } 1722 1723 G726ENC_DPRINT("Exiting GetExtensionIndex\n"); 1724 return eError; 1725} 1726 1727/* ================================================================================= */ 1728/** 1729* @fn ComponentRoleEnum() description for ComponentRoleEnum() 1730 1731Returns the role at the given index 1732* 1733* @see OMX_Core.h 1734*/ 1735/* ================================================================================ */ 1736static OMX_ERRORTYPE ComponentRoleEnum( 1737 OMX_IN OMX_HANDLETYPE hComponent, 1738 OMX_OUT OMX_U8 *cRole, 1739 OMX_IN OMX_U32 nIndex) 1740{ 1741 G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 1742 1743 OMX_ERRORTYPE eError = OMX_ErrorNone; 1744 pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate); 1745 1746 if(nIndex == 0){ 1747 if (cRole == NULL) { 1748 eError = OMX_ErrorBadParameter; 1749 } 1750 else { 1751 memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 1752 G726ENC_DPRINT("::::In ComponenetRoleEnum: cRole is set to %s\n",cRole); 1753 } 1754 } 1755 else { 1756 eError = OMX_ErrorNoMore; 1757 } 1758 return eError; 1759} 1760