1 /* 2 * Copyright (c) 2010, Texas Instruments Incorporated 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /** 34 * @file omx_proxy_h264enc.c 35 * This file contains methods that provides the functionality for 36 * the OpenMAX1.1 DOMX Framework Proxy component. 37 ********************************************************************************************* 38 This is the proxy specific wrapper that passes the component name to the generic proxy init() 39 The proxy wrapper also does some runtime/static time onfig on per proxy basis 40 This is a thin wrapper that is called when componentiit() of the proxy is called 41 static OMX_ERRORTYPE PROXY_Wrapper_init(OMX_HANDLETYPE hComponent, OMX_PTR pAppData); 42 this layer gets called first whenever a proxy's get handle is called 43 ************************************************************************************************ 44 * @path WTSD_DucatiMMSW\omx\omx_il_1_x\omx_proxy_component\src 45 * 46 * @rev 1.0 47 */ 48 49 /*============================================================== 50 *! Revision History 51 *! ============================ 52 * 26-August-2011 Abhishek Ranka : Support for color conv at encoder 53 * input port 54 * 55 *! 20-August-2010 Sarthak Aggarwal sarthak (at) ti.com: Initial Version 56 *================================================================*/ 57 58 /****************************************************************** 59 * INCLUDE FILES 60 ******************************************************************/ 61 62 #include <stdio.h> 63 #include <string.h> 64 #include <assert.h> 65 #include "omx_proxy_common.h" 66 #include <timm_osal_interfaces.h> 67 #include "OMX_TI_IVCommon.h" 68 #include "OMX_TI_Video.h" 69 #include "OMX_TI_Index.h" 70 71 #include <MetadataBufferType.h> 72 #ifdef ENABLE_GRALLOC_BUFFER 73 #include "native_handle.h" 74 #include <hal_public.h> 75 #include <VideoMetadata.h> 76 #endif 77 78 #include <stdlib.h> 79 #include <cutils/properties.h> 80 81 #define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.H264E" 82 /* needs to be specific for every configuration wrapper */ 83 84 #define OMX_H264E_INPUT_PORT 0 85 #define LINUX_PAGE_SIZE 4096 86 87 #ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 88 89 OMX_ERRORTYPE LOCAL_PROXY_H264E_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 90 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 91 92 OMX_ERRORTYPE LOCAL_PROXY_H264E_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 93 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 94 95 #endif 96 97 98 #define OMX_INIT_STRUCT(_s_, _name_) \ 99 memset(&(_s_), 0x0, sizeof(_name_)); \ 100 (_s_).nSize = sizeof(_name_); \ 101 (_s_).nVersion.s.nVersionMajor = 0x1; \ 102 (_s_).nVersion.s.nVersionMinor = 0x1; \ 103 (_s_).nVersion.s.nRevision = 0x0; \ 104 (_s_).nVersion.s.nStep = 0x0 105 106 107 /* Params needed for Dynamic Frame Rate Control*/ 108 #define FRAME_RATE_THRESHOLD 1 /* Change in Frame rate to configure the encoder */ 109 OMX_U32 nFrameRateThreshold = 0;/* Frame Rate threshold for every frame rate update */ 110 OMX_U32 nPortFrameRate = 0; /* Port FPS initially set to the Encoder */ 111 OMX_U32 nFrameCounter = 0; /* Number of input frames recieved since last framerate calculation */ 112 OMX_TICKS nVideoTime = 0; /* Video duration since last framerate calculation */ 113 OMX_TICKS nLastFrameRateUpdateTime = 0; /*Time stamp at last frame rate update */ 114 OMX_U16 nBFrames = 0; /* Number of B Frames in H264 Encoder */ 115 116 117 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 118 /* Opaque color format requires below quirks to be enabled 119 * ENABLE_GRALLOC_BUFFER 120 * ANDROID_QUIRCK_CHANGE_PORT_VALUES 121 */ 122 #define OMX_H264VE_NUM_INTERNAL_BUF (8) 123 #define HAL_PIXEL_FORMAT_TI_NV12 (0x100) 124 125 #define COLORCONVERT_MAX_SUB_BUFFERS (3) 126 127 #define COLORCONVERT_BUFTYPE_VIRTUAL (0x0) 128 #define COLORCONVERT_BUFTYPE_ION (0x1) 129 #define COLORCONVERT_BUFTYPE_GRALLOCOPAQUE (0x2) 130 131 int COLORCONVERT_open(void **hCC, PROXY_COMPONENT_PRIVATE *pCompPrv); 132 int COLORCONVERT_PlatformOpaqueToNV12(void *hCC, void *pSrc[], 133 void *pDst[], int nWidth, 134 int nHeight, int nStride, 135 int nSrcBufType, int nDstBufType); 136 int COLORCONVERT_close(void *hCC,PROXY_COMPONENT_PRIVATE *pCompPrv); 137 static int COLORCONVERT_AllocateBuffer(OMX_HANDLETYPE hComponent, OMX_U32 nStride); 138 static OMX_ERRORTYPE LOCAL_PROXY_H264E_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent, 139 OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr, OMX_IN OMX_U32 nPortIndex, 140 OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes); 141 142 static OMX_ERRORTYPE LOCAL_PROXY_H264E_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 143 OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr); 144 145 static OMX_ERRORTYPE LOCAL_PROXY_H264E_ComponentDeInit(OMX_HANDLETYPE hComponent); 146 147 typedef struct _OMX_PROXY_H264E_PRIVATE 148 { 149 OMX_PTR hBufPipe; 150 OMX_BOOL bAndroidOpaqueFormat; 151 OMX_PTR hCC; 152 IMG_native_handle_t* gralloc_handle[OMX_H264VE_NUM_INTERNAL_BUF]; 153 OMX_S32 nCurBufIndex; 154 alloc_device_t* mAllocDev; 155 }OMX_PROXY_H264E_PRIVATE; 156 157 RPC_OMX_ERRORTYPE RPC_RegisterBuffer(OMX_HANDLETYPE hRPCCtx, int fd, 158 OMX_PTR *handle1, OMX_PTR *handle2, 159 PROXY_BUFFER_TYPE proxyBufferType); 160 RPC_OMX_ERRORTYPE RPC_UnRegisterBuffer(OMX_HANDLETYPE hRPCCtx, OMX_PTR handle); 161 #endif 162 163 164 OMX_ERRORTYPE LOCAL_PROXY_H264E_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 165 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType); 166 167 OMX_ERRORTYPE LOCAL_PROXY_H264E_EmptyThisBuffer(OMX_HANDLETYPE hComponent, 168 OMX_BUFFERHEADERTYPE * pBufferHdr); 169 170 static OMX_ERRORTYPE OMX_ConfigureDynamicFrameRate( OMX_HANDLETYPE hComponent, 171 OMX_BUFFERHEADERTYPE * pBufferHdr) 172 { 173 OMX_ERRORTYPE eError = OMX_ErrorNone; 174 OMX_U32 nTargetFrameRate = 0; /* Target Frame Rate to be provided to Encoder */ 175 OMX_U32 nCurrentFrameRate = 0; /* Current Frame Rate currently set in Encoder */ 176 OMX_CONFIG_FRAMERATETYPE tFrameRate; 177 OMX_COMPONENTTYPE *pHandle; 178 if (hComponent == NULL){ 179 DOMX_ERROR("Component is invalid/ not present "); 180 return OMX_ErrorBadParameter; 181 } 182 pHandle = (OMX_COMPONENTTYPE *) hComponent; 183 184 /* Initialise the OMX structures */ 185 OMX_INIT_STRUCT(tFrameRate,OMX_CONFIG_FRAMERATETYPE); 186 187 /* Intialise nLastFrameRateUpdateTime for the 1st frame */ 188 if((!nFrameCounter) && (!nLastFrameRateUpdateTime)){ 189 nLastFrameRateUpdateTime = pBufferHdr-> nTimeStamp; 190 } 191 192 /* Increment the Frame Counter and Calculate Frame Rate*/ 193 nFrameCounter++; 194 nVideoTime = pBufferHdr->nTimeStamp - nLastFrameRateUpdateTime; 195 196 if(nVideoTime < 0) { 197 return OMX_ErrorBadParameter; 198 } 199 200 /*Get Port Frame Rate if not read yet*/ 201 if(!nFrameRateThreshold) { 202 tFrameRate.nPortIndex = OMX_H264E_INPUT_PORT; /* As per ducati support-set for input port */ 203 204 /* Read Current FrameRate */ 205 eError = pHandle->GetConfig(hComponent,OMX_IndexConfigVideoFramerate,&tFrameRate); 206 if (eError != OMX_ErrorNone) 207 DOMX_ERROR ("pHandle->GetConfig OMX_IndexConfigVideoFramerate eError :0x%x \n",eError); 208 nFrameRateThreshold = tFrameRate.xEncodeFramerate >>16; 209 nPortFrameRate = nFrameRateThreshold; 210 DOMX_DEBUG(" Port Frame Rate is %d ", nPortFrameRate); 211 } 212 nCurrentFrameRate = nFrameRateThreshold; 213 214 /* If Number of frames is less than the Threshold 215 * Frame Rate udpate is not necessary 216 */ 217 if(nFrameCounter < nFrameRateThreshold){ 218 DOMX_EXIT(" Threshold not reached, no update necessary"); 219 return OMX_ErrorNone; 220 } 221 222 /*Calculate the new target Frame Rate*/ 223 if (nVideoTime != 0) 224 nTargetFrameRate = nFrameCounter * 1000000 / nVideoTime; 225 226 /* For 1080p record, max FPS supported by Codec for profile 4.1 is 30. 227 * When Dynamic Frame Rate is enabled, there might be scenario when FPS 228 * calculated is more than 30. Hence adding the check so that Dynamic Frame 229 * Rate set is never greater than the port FPS initially set. 230 */ 231 if(nTargetFrameRate > nPortFrameRate){ 232 DOMX_DEBUG("Frame Rate Calculated is more than initial port set Frame Rate"); 233 nTargetFrameRate = nPortFrameRate; 234 } 235 236 /* Difference in Frame Rate is more than Threshold - Only then update Frame Rate*/ 237 if((( (OMX_S32)nTargetFrameRate) -((OMX_S32) nCurrentFrameRate) >= FRAME_RATE_THRESHOLD) || 238 (((OMX_S32) nCurrentFrameRate) - ( (OMX_S32)nTargetFrameRate) >= FRAME_RATE_THRESHOLD)) { 239 240 /* Now Send the new Frame Rate */ 241 tFrameRate.nPortIndex = OMX_H264E_INPUT_PORT; /* As per ducati support-set for input port */ 242 tFrameRate.xEncodeFramerate = (OMX_U32)(nTargetFrameRate * (1 << 16)); 243 eError = pHandle->SetConfig(hComponent,OMX_IndexConfigVideoFramerate,&tFrameRate); 244 if(eError != OMX_ErrorNone){ 245 DOMX_ERROR(" Error while configuring Dynamic Frame Rate,Error info = %d",eError); 246 return eError; 247 } else { 248 DOMX_DEBUG("Dynamic Frame Rate configuration successful \n"); 249 } 250 nFrameRateThreshold = nTargetFrameRate; /*Update the threshold */ 251 } 252 253 /* reset all params */ 254 nFrameCounter = 0 ; 255 nVideoTime = 0; 256 nLastFrameRateUpdateTime = pBufferHdr->nTimeStamp; 257 return OMX_ErrorNone; 258 } 259 260 static OMX_ERRORTYPE ComponentPrivateEmptyThisBuffer(OMX_HANDLETYPE hComponent, 261 OMX_BUFFERHEADERTYPE * pBufferHdr) 262 { 263 OMX_ERRORTYPE eError = OMX_ErrorNone; 264 265 eError = OMX_ConfigureDynamicFrameRate(hComponent, pBufferHdr); 266 if( eError != OMX_ErrorNone) 267 DOMX_ERROR(" Error while configuring FrameRate Dynamically.Error info = %d",eError); 268 269 DOMX_DEBUG("Redirection from ComponentPricateEmptyThisBuffer to PROXY_EmptyThisBuffer"); 270 return LOCAL_PROXY_H264E_EmptyThisBuffer (hComponent,pBufferHdr); 271 } 272 273 OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) 274 { 275 OMX_ERRORTYPE eError = OMX_ErrorNone; 276 OMX_COMPONENTTYPE *pHandle = NULL; 277 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 278 pHandle = (OMX_COMPONENTTYPE *) hComponent; 279 OMX_TI_PARAM_ENHANCEDPORTRECONFIG tParamStruct; 280 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 281 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 282 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 283 #endif 284 char value[OMX_MAX_STRINGNAME_SIZE]; 285 OMX_U32 mEnableVFR = 1; /* Flag used to enable/disable VFR for Encoder */ 286 property_get("debug.vfr.enable", value, "1"); 287 mEnableVFR = atoi(value); 288 289 DOMX_ENTER(""); 290 291 DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME); 292 293 pHandle->pComponentPrivate = 294 (PROXY_COMPONENT_PRIVATE *) 295 TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), TIMM_OSAL_TRUE, 296 0, TIMMOSAL_MEM_SEGMENT_INT); 297 298 PROXY_assert(pHandle->pComponentPrivate != NULL, 299 OMX_ErrorInsufficientResources, 300 "ERROR IN ALLOCATING PROXY COMPONENT PRIVATE STRUCTURE"); 301 302 pComponentPrivate = 303 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 304 305 TIMM_OSAL_Memset(pComponentPrivate, 0, 306 sizeof(PROXY_COMPONENT_PRIVATE)); 307 308 pComponentPrivate->cCompName = 309 TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8), 310 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 311 312 PROXY_assert(pComponentPrivate->cCompName != NULL, 313 OMX_ErrorInsufficientResources, 314 " Error in Allocating space for proxy component table"); 315 316 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 317 pComponentPrivate->pCompProxyPrv = 318 (OMX_PROXY_H264E_PRIVATE *) 319 TIMM_OSAL_Malloc(sizeof(OMX_PROXY_H264E_PRIVATE), TIMM_OSAL_TRUE, 320 0, TIMMOSAL_MEM_SEGMENT_INT); 321 322 PROXY_assert(pComponentPrivate->pCompProxyPrv != NULL, 323 OMX_ErrorInsufficientResources, 324 " Could not allocate proxy component private"); 325 326 TIMM_OSAL_Memset(pComponentPrivate->pCompProxyPrv, 0, 327 sizeof(OMX_PROXY_H264E_PRIVATE)); 328 329 pProxy = (OMX_PROXY_H264E_PRIVATE *) pComponentPrivate->pCompProxyPrv; 330 331 /* Create Pipe of for encoder input buffers */ 332 eOSALStatus = TIMM_OSAL_CreatePipe(&pProxy->hBufPipe, sizeof(OMX_U32), 333 OMX_H264VE_NUM_INTERNAL_BUF, 1); 334 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, 335 OMX_ErrorInsufficientResources, 336 "Pipe creation failed"); 337 #endif 338 339 // Copying component Name - this will be picked up in the proxy common 340 PROXY_assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH, 341 OMX_ErrorInvalidComponentName, 342 "Length of component name is longer than the max allowed"); 343 TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME, 344 strlen(COMPONENT_NAME) + 1); 345 346 eError = OMX_ProxyCommonInit(hComponent); // Calling Proxy Common Init() 347 #ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 348 pHandle->SetParameter = LOCAL_PROXY_H264E_SetParameter; 349 pHandle->GetParameter = LOCAL_PROXY_H264E_GetParameter; 350 #endif 351 pComponentPrivate->IsLoadedState = OMX_TRUE; 352 pHandle->EmptyThisBuffer = LOCAL_PROXY_H264E_EmptyThisBuffer; 353 pHandle->GetExtensionIndex = LOCAL_PROXY_H264E_GetExtensionIndex; 354 355 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 356 pHandle->ComponentDeInit = LOCAL_PROXY_H264E_ComponentDeInit; 357 pHandle->FreeBuffer = LOCAL_PROXY_H264E_FreeBuffer; 358 pHandle->AllocateBuffer = LOCAL_PROXY_H264E_AllocateBuffer; 359 #endif 360 361 if(mEnableVFR) 362 pHandle->EmptyThisBuffer = ComponentPrivateEmptyThisBuffer; 363 364 EXIT: 365 if (eError != OMX_ErrorNone) 366 { 367 DOMX_DEBUG("Error in Initializing Proxy"); 368 369 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 370 if(pProxy->hBufPipe != NULL) 371 { 372 TIMM_OSAL_DeletePipe(pProxy->hBufPipe); 373 pProxy->hBufPipe = NULL; 374 } 375 376 if(pComponentPrivate->pCompProxyPrv != NULL) 377 { 378 TIMM_OSAL_Free(pComponentPrivate->pCompProxyPrv); 379 pComponentPrivate->pCompProxyPrv = NULL; 380 pProxy = NULL; 381 } 382 #endif 383 if (pComponentPrivate->cCompName != NULL) 384 { 385 TIMM_OSAL_Free(pComponentPrivate->cCompName); 386 pComponentPrivate->cCompName = NULL; 387 } 388 if (pComponentPrivate != NULL) 389 { 390 TIMM_OSAL_Free(pComponentPrivate); 391 pComponentPrivate = NULL; 392 } 393 } 394 return eError; 395 } 396 397 #ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 398 399 /* ===========================================================================*/ 400 /** 401 * @name PROXY_H264E_GetParameter() 402 * @brief 403 * @param void 404 * @return OMX_ErrorNone = Successful 405 * @sa TBD 406 * 407 */ 408 /* ===========================================================================*/ 409 OMX_ERRORTYPE LOCAL_PROXY_H264E_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 410 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct) 411 { 412 OMX_ERRORTYPE eError = OMX_ErrorNone; 413 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 414 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 415 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL; 416 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParam = NULL; 417 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 418 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 419 #endif 420 421 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 422 PROXY_assert((hComp->pComponentPrivate != NULL), 423 OMX_ErrorBadParameter, NULL); 424 425 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 426 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 427 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 428 #endif 429 430 DOMX_ENTER 431 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 432 hComponent, pCompPrv, nParamIndex, pParamStruct); 433 434 eError = PROXY_GetParameter(hComponent,nParamIndex, pParamStruct); 435 436 if(nParamIndex == OMX_IndexParamPortDefinition) 437 { 438 pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 439 440 if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) 441 { 442 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 443 if(pProxy->bAndroidOpaqueFormat == OMX_TRUE) 444 { 445 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatAndroidOpaque; 446 } 447 else 448 #endif 449 { 450 pPortDef->format.video.eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 451 } 452 } 453 454 if(pPortDef->nPortIndex == OMX_H264E_INPUT_PORT) 455 { 456 if(pCompPrv->proxyPortBuffers[OMX_H264E_INPUT_PORT].proxyBufferType == EncoderMetadataPointers) 457 { 458 pPortDef->nBufferSize = sizeof(video_metadata_t); 459 } 460 } 461 } 462 else if (nParamIndex == OMX_IndexParamVideoPortFormat) 463 { 464 pPortParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 465 466 if((eError == OMX_ErrorNone) && 467 (pPortParam->eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar)) 468 { 469 pPortParam->eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 470 } 471 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 472 else if ((eError == OMX_ErrorNoMore) && 473 (pPortParam->nIndex == 1)) 474 { 475 /* HACK:Remote OMX-H264E supports only 1 color format (index 0). The 476 * OMX_COLOR_FormatAndroidOpaque is supported only at the proxy. 477 * Call GetParameter() to fill in defaults for parameters and 478 * override color format and index for the additional 479 * OMX_COLOR_FormatAndroidOpaque support*/ 480 pPortParam->nIndex = 0; 481 eError = PROXY_GetParameter(hComponent, nParamIndex, pParamStruct); 482 pPortParam->nIndex = 1; 483 pPortParam->eColorFormat = OMX_COLOR_FormatAndroidOpaque; 484 eError = OMX_ErrorNone; 485 } 486 #endif 487 } 488 else if (nParamIndex == OMX_TI_IndexComponentHandle) 489 { 490 OMX_TI_COMPONENT_HANDLE * pCompHandle = pParamStruct; 491 pCompHandle->pHandle = hComponent; 492 eError = OMX_ErrorNone; 493 } 494 495 PROXY_assert((eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore), 496 eError," Error in Proxy GetParameter"); 497 498 EXIT: 499 DOMX_EXIT("eError: %d", eError); 500 return eError; 501 } 502 503 /* ===========================================================================*/ 504 /** 505 * @name PROXY_H264E_SetParameter() 506 * @brief 507 * @param void 508 * @return OMX_ErrorNone = Successful 509 * @sa TBD 510 * 511 */ 512 /* ===========================================================================*/ 513 OMX_ERRORTYPE LOCAL_PROXY_H264E_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 514 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct) 515 { 516 OMX_ERRORTYPE eError = OMX_ErrorNone; 517 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 518 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 519 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL; 520 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParams = NULL; 521 OMX_VIDEO_STOREMETADATAINBUFFERSPARAMS* pStoreMetaData = NULL; 522 OMX_TI_PARAM_BUFFERPREANNOUNCE tParamSetNPA; 523 OMX_PARAM_PORTDEFINITIONTYPE sPortDef; 524 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 525 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 526 #endif 527 528 DOMX_ENTER 529 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 530 hComponent, pCompPrv, nParamIndex, pParamStruct); 531 532 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 533 PROXY_require((hComp->pComponentPrivate != NULL), 534 OMX_ErrorBadParameter, NULL); 535 536 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 537 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 538 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 539 #endif 540 541 if(nParamIndex == OMX_IndexParamPortDefinition) 542 { 543 pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 544 545 if(pPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) 546 { 547 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 548 } 549 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 550 else if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque) 551 { 552 if(COLORCONVERT_open(&pProxy->hCC,pCompPrv) != 0) 553 { 554 PROXY_assert(0, OMX_ErrorInsufficientResources, 555 "Failed to open Color converting service"); 556 } 557 pProxy->bAndroidOpaqueFormat = OMX_TRUE; 558 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 559 } 560 #endif 561 } 562 else if(nParamIndex == OMX_IndexParamVideoPortFormat) 563 { 564 pPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 565 566 if(pPortParams->eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) 567 { 568 pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 569 } 570 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 571 else if(pPortParams->eColorFormat == OMX_COLOR_FormatAndroidOpaque) 572 { 573 if(COLORCONVERT_open(&pProxy->hCC,pCompPrv) != 0) 574 { 575 PROXY_assert(0, OMX_ErrorInsufficientResources, 576 "Failed to open Color converting service"); 577 } 578 pProxy->bAndroidOpaqueFormat = OMX_TRUE; 579 pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 580 } 581 #endif 582 } 583 else if(nParamIndex == (OMX_INDEXTYPE) OMX_TI_IndexEncoderStoreMetadatInBuffers) 584 { 585 pStoreMetaData = (OMX_VIDEO_STOREMETADATAINBUFFERSPARAMS *) pParamStruct; 586 587 DOMX_DEBUG("Moving to Metadatamode"); 588 if (pStoreMetaData->nPortIndex == OMX_H264E_INPUT_PORT && pStoreMetaData->bStoreMetaData == OMX_TRUE) 589 { 590 tParamSetNPA.nSize = sizeof(OMX_TI_PARAM_BUFFERPREANNOUNCE); 591 tParamSetNPA.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 592 tParamSetNPA.nVersion.s.nVersionMinor = OMX_VER_MINOR; 593 tParamSetNPA.nVersion.s.nRevision = 0x0; 594 tParamSetNPA.nVersion.s.nStep = 0x0; 595 tParamSetNPA.nPortIndex = OMX_H264E_INPUT_PORT; 596 tParamSetNPA.bEnabled = OMX_FALSE; 597 //Call NPA on OMX encoder on ducati. 598 PROXY_SetParameter(hComponent,OMX_TI_IndexParamBufferPreAnnouncement, &tParamSetNPA); 599 pCompPrv->proxyPortBuffers[pStoreMetaData->nPortIndex].proxyBufferType = EncoderMetadataPointers; 600 DOMX_DEBUG("Moving to Metadatamode done"); 601 602 /*Initializing Structure */ 603 sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 604 sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 605 sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR; 606 sPortDef.nVersion.s.nRevision = 0x0; 607 sPortDef.nVersion.s.nStep = 0x0; 608 sPortDef.nPortIndex = OMX_H264E_INPUT_PORT; 609 610 eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition, &sPortDef); 611 PROXY_assert(eError == OMX_ErrorNone, eError," Error in Proxy GetParameter for Port Def"); 612 613 sPortDef.format.video.nStride = LINUX_PAGE_SIZE; 614 615 eError = PROXY_SetParameter(hComponent,OMX_IndexParamPortDefinition, &sPortDef); 616 617 PROXY_assert(eError == OMX_ErrorNone, eError," Error in Proxy SetParameter for Port Def"); 618 } 619 goto EXIT; 620 } 621 622 eError = PROXY_SetParameter(hComponent, nParamIndex, pParamStruct); 623 PROXY_assert(eError == OMX_ErrorNone, 624 eError," Error in Proxy SetParameter"); 625 626 EXIT: 627 DOMX_EXIT("eError: %d", eError); 628 return eError; 629 } 630 631 #endif 632 633 634 /* ===========================================================================*/ 635 /** 636 * @name PROXY_GetExtensionIndex() 637 * @brief 638 * @param void 639 * @return OMX_ErrorNone = Successful 640 * @sa TBD 641 * 642 */ 643 /* ===========================================================================*/ 644 OMX_ERRORTYPE LOCAL_PROXY_H264E_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 645 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType) 646 { 647 OMX_ERRORTYPE eError = OMX_ErrorNone; 648 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 649 OMX_COMPONENTTYPE *hComp = hComponent; 650 651 PROXY_require((hComp->pComponentPrivate != NULL), 652 OMX_ErrorBadParameter, NULL); 653 PROXY_require(cParameterName != NULL, OMX_ErrorBadParameter, NULL); 654 PROXY_require(pIndexType != NULL, OMX_ErrorBadParameter, NULL); 655 656 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 657 658 DOMX_ENTER("%s hComponent = %p, pCompPrv = %p, cParameterName = %s", 659 __FUNCTION__,hComponent, pCompPrv, cParameterName); 660 661 // Check for NULL Parameters 662 PROXY_require((cParameterName != NULL && pIndexType != NULL), 663 OMX_ErrorBadParameter, NULL); 664 665 // Ensure that String length is not greater than Max allowed length 666 PROXY_require(strlen(cParameterName) <= 127, OMX_ErrorBadParameter, NULL); 667 668 if(strcmp(cParameterName, "OMX.google.android.index.storeMetaDataInBuffers") == 0) 669 { 670 // If Index type is 2D Buffer Allocated Dimension 671 *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexEncoderStoreMetadatInBuffers; 672 goto EXIT; 673 } 674 675 eError = PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType); 676 677 EXIT: 678 DOMX_EXIT("%s eError: %d",__FUNCTION__, eError); 679 return eError; 680 } 681 682 /* ===========================================================================*/ 683 /** 684 * @name PROXY_H264E_EmptyThisBuffer() 685 * @brief 686 * @param void 687 * @return OMX_ErrorNone = Successful 688 * @sa TBD 689 * 690 */ 691 /* ===========================================================================*/ 692 OMX_ERRORTYPE LOCAL_PROXY_H264E_EmptyThisBuffer(OMX_HANDLETYPE hComponent, 693 OMX_BUFFERHEADERTYPE * pBufferHdr) 694 { 695 696 OMX_ERRORTYPE eError = OMX_ErrorNone; 697 PROXY_COMPONENT_PRIVATE *pCompPrv; 698 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 699 OMX_PTR pBufferOrig = NULL; 700 OMX_U32 nStride = 0, nNumLines = 0; 701 OMX_PARAM_PORTDEFINITIONTYPE tParamStruct; 702 OMX_U32 nFilledLen, nAllocLen; 703 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 704 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 705 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 706 OMX_U32 nBufIndex = 0, nSize=0, nRet=0; 707 #endif 708 #ifdef ENABLE_GRALLOC_BUFFER 709 OMX_PTR pAuxBuf0 = NULL, pAuxBuf1 = NULL; 710 RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone; 711 OMX_ERRORTYPE eCompReturn = OMX_ErrorNone; 712 IMG_native_handle_t* pGrallocHandle=NULL; 713 #endif 714 715 PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL); 716 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 717 NULL); 718 PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE); 719 720 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 721 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 722 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 723 #endif 724 725 tParamStruct.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 726 tParamStruct.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 727 tParamStruct.nVersion.s.nVersionMinor = OMX_VER_MINOR; 728 tParamStruct.nVersion.s.nRevision = 0x0; 729 tParamStruct.nVersion.s.nStep = 0x0; 730 tParamStruct.nPortIndex = OMX_H264E_INPUT_PORT; 731 732 eError = PROXY_GetParameter(hComponent, OMX_IndexParamPortDefinition, &tParamStruct); 733 PROXY_require(eError == OMX_ErrorNone, OMX_ErrorBadParameter, "Error is Get Parameter for port def"); 734 nFilledLen = pBufferHdr->nFilledLen; 735 nAllocLen = pBufferHdr->nAllocLen; 736 if(nFilledLen != 0) 737 { 738 pBufferHdr->nFilledLen = tParamStruct.nBufferSize; 739 } 740 pBufferHdr->nAllocLen = tParamStruct.nBufferSize; 741 742 DOMX_DEBUG 743 ("%s hComponent=%p, pCompPrv=%p, nFilledLen=%d, nOffset=%d, nFlags=%08x", 744 __FUNCTION__,hComponent, pCompPrv, pBufferHdr->nFilledLen, 745 pBufferHdr->nOffset, pBufferHdr->nFlags); 746 747 if( pCompPrv->proxyPortBuffers[OMX_H264E_INPUT_PORT].proxyBufferType == EncoderMetadataPointers ) 748 { 749 OMX_U32 *pTempBuffer; 750 OMX_U32 nMetadataBufferType; 751 DOMX_DEBUG("Passing meta data to encoder"); 752 753 pBufferOrig = pBufferHdr->pBuffer; 754 755 pTempBuffer = (OMX_U32 *) (pBufferHdr->pBuffer); 756 nMetadataBufferType = *pTempBuffer; 757 758 if(nMetadataBufferType == kMetadataBufferTypeCameraSource) 759 { 760 #ifdef ENABLE_GRALLOC_BUFFER 761 video_metadata_t* pVideoMetadataBuffer; 762 DOMX_DEBUG("MetadataBufferType is kMetadataBufferTypeCameraSource"); 763 764 pVideoMetadataBuffer = (video_metadata_t*) ((OMX_U32 *)(pBufferHdr->pBuffer)); 765 pGrallocHandle = (IMG_native_handle_t*) (pVideoMetadataBuffer->handle); 766 DOMX_DEBUG("Grallloc buffer recieved in metadata buffer 0x%x",pGrallocHandle ); 767 if( pGrallocHandle->iFormat != HAL_PIXEL_FORMAT_TI_NV12 && pProxy->gralloc_handle[0] == NULL ) { 768 DOMX_DEBUG("Allocating NV12 buffers internally within DOMX actual count: %d", pCompPrv->nAllocatedBuffers); 769 pProxy->nCurBufIndex = 0; 770 771 while( (unsigned) pProxy->nCurBufIndex < pCompPrv->nAllocatedBuffers ) { 772 eError = COLORCONVERT_AllocateBuffer(hComponent, nStride); 773 PROXY_require(eError == OMX_ErrorNone, eError, "Error allocating buffers for color conversion"); 774 pProxy->nCurBufIndex++; 775 } 776 } 777 pBufferHdr->pBuffer = (OMX_U8 *)(pGrallocHandle->fd[0]); 778 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)-> 779 pAuxBuf1 = (OMX_PTR) pGrallocHandle->fd[1]; 780 DOMX_DEBUG("%s Gralloc=0x%x, Y-fd=%d, UV-fd=%d", __FUNCTION__, pGrallocHandle, 781 pGrallocHandle->fd[0], pGrallocHandle->fd[1]); 782 783 pBufferHdr->nOffset = pVideoMetadataBuffer->offset; 784 #endif 785 } 786 else if(nMetadataBufferType == kMetadataBufferTypeGrallocSource) 787 { 788 #ifdef ENABLE_GRALLOC_BUFFER 789 buffer_handle_t tBufHandle; 790 DOMX_DEBUG("MetadataBufferType is kMetadataBufferTypeGrallocSource"); 791 792 pTempBuffer++; 793 tBufHandle = *((buffer_handle_t *)pTempBuffer); 794 pGrallocHandle = (IMG_native_handle_t*) tBufHandle; 795 DOMX_DEBUG("Grallloc buffer recieved in metadata buffer 0x%x",pGrallocHandle ); 796 if( pGrallocHandle->iFormat != HAL_PIXEL_FORMAT_TI_NV12 && pProxy->gralloc_handle[0] == NULL ) { 797 DOMX_DEBUG("Allocating NV12 buffers internally within DOMX actual count: %d", pCompPrv->nAllocatedBuffers); 798 pProxy->nCurBufIndex = 0; 799 800 while( (unsigned) pProxy->nCurBufIndex < pCompPrv->nAllocatedBuffers ) { 801 eError = COLORCONVERT_AllocateBuffer(hComponent, nStride); 802 PROXY_require(eError == OMX_ErrorNone, eError, "Error allocating buffers for color conversion"); 803 pProxy->nCurBufIndex++; 804 } 805 } 806 807 pBufferHdr->pBuffer = (OMX_U8 *)(pGrallocHandle->fd[0]); 808 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)-> 809 pAuxBuf1 = (OMX_PTR) pGrallocHandle->fd[1]; 810 DOMX_DEBUG("%s Gralloc=0x%x, Y-fd=%d, UV-fd=%d", __FUNCTION__, pGrallocHandle, 811 pGrallocHandle->fd[0], pGrallocHandle->fd[1]); 812 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 813 if (pProxy->bAndroidOpaqueFormat && pGrallocHandle->iFormat != HAL_PIXEL_FORMAT_TI_NV12) 814 { 815 /* Dequeue NV12 buffer for encoder */ 816 eOSALStatus = TIMM_OSAL_ReadFromPipe(pProxy->hBufPipe, &nBufIndex, 817 sizeof(OMX_PTR), (TIMM_OSAL_U32 *)(&nSize), 818 TIMM_OSAL_SUSPEND); 819 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, OMX_ErrorBadParameter, NULL); 820 821 if(nFilledLen != 0) 822 { 823 /* Get NV12 data after colorconv*/ 824 nRet = COLORCONVERT_PlatformOpaqueToNV12(pProxy->hCC, (void **) &pGrallocHandle, (void **) &pProxy->gralloc_handle[nBufIndex], 825 pGrallocHandle->iWidth, 826 pGrallocHandle->iHeight, 827 4096, COLORCONVERT_BUFTYPE_GRALLOCOPAQUE, 828 COLORCONVERT_BUFTYPE_GRALLOCOPAQUE ); 829 830 if(nRet != 0) 831 { 832 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &nBufIndex, 833 sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 834 PROXY_assert(0, OMX_ErrorBadParameter, "Color conversion routine failed"); 835 } 836 } 837 838 /* Update pBufferHdr with NV12 buffers for OMX component */ 839 pBufferHdr->pBuffer= (OMX_U8 *)(pProxy->gralloc_handle[nBufIndex]->fd[0]); 840 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)->pAuxBuf1 = (OMX_PTR)(pProxy->gralloc_handle[nBufIndex]->fd[1]); 841 } 842 #endif 843 #endif 844 } 845 else 846 { 847 DOMX_ERROR("MetadataBufferType is unknow. Returning 'OMX_ErrorBadParameter'"); 848 eError = OMX_ErrorBadParameter; 849 goto EXIT; //need to restore lenght fields in pBufferHdr 850 } 851 #ifdef ENABLE_GRALLOC_BUFFER 852 eRPCError = RPC_RegisterBuffer(pCompPrv->hRemoteComp, pBufferHdr->pBuffer, 853 &pAuxBuf0, &pAuxBuf1, 854 GrallocPointers); 855 PROXY_checkRpcError(); 856 if (pAuxBuf0) 857 pBufferHdr->pBuffer = pAuxBuf0; 858 if (pAuxBuf1) 859 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)->pAuxBuf1 = pAuxBuf1; 860 #endif 861 } 862 863 eError = PROXY_EmptyThisBuffer(hComponent, pBufferHdr); 864 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 865 if (pProxy->bAndroidOpaqueFormat 866 #ifdef ENABLE_GRALLOC_BUFFER 867 && pGrallocHandle != NULL && pGrallocHandle->iFormat != HAL_PIXEL_FORMAT_TI_NV12 868 #endif 869 ) 870 { 871 /*Write buffer to end of pipe for re-circulation for future ETB()*/ 872 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &nBufIndex, 873 sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 874 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, OMX_ErrorBadParameter, "Pipe write failed"); 875 } 876 #endif 877 878 EXIT: 879 if( pBufferHdr!=NULL && pCompPrv->proxyPortBuffers[pBufferHdr->nInputPortIndex].proxyBufferType == EncoderMetadataPointers) 880 { 881 pBufferHdr->pBuffer = pBufferOrig; 882 pBufferHdr->nFilledLen = nFilledLen; 883 pBufferHdr->nAllocLen = nAllocLen; 884 #ifdef ENABLE_GRALLOC_BUFFER 885 RPC_UnRegisterBuffer(pCompPrv->hRemoteComp, pAuxBuf0); 886 RPC_UnRegisterBuffer(pCompPrv->hRemoteComp, pAuxBuf1); 887 #endif 888 } 889 return eError; 890 } 891 892 #ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 893 static OMX_ERRORTYPE LOCAL_PROXY_H264E_AllocateBuffer(OMX_HANDLETYPE hComponent, 894 OMX_BUFFERHEADERTYPE ** ppBufferHdr, OMX_U32 nPortIndex, 895 OMX_PTR pAppPrivate, OMX_U32 nSizeBytes) 896 { 897 OMX_ERRORTYPE eError = OMX_ErrorNone; 898 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 899 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 900 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 901 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 902 int err, nStride; 903 904 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 905 NULL); 906 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 907 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 908 909 910 eError = PROXY_AllocateBuffer(hComponent, ppBufferHdr, nPortIndex, 911 pAppPrivate, nSizeBytes); 912 EXIT: 913 return eError; 914 } 915 916 static OMX_ERRORTYPE LOCAL_PROXY_H264E_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 917 OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr) 918 { 919 OMX_ERRORTYPE eError = OMX_ErrorNone; 920 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 921 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 922 OMX_U32 nBufIndex, nSize, nCount=0; 923 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 924 925 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 926 NULL); 927 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 928 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 929 930 if((nPortIndex == OMX_H264E_INPUT_PORT) && 931 (pProxy->bAndroidOpaqueFormat) && (pProxy->gralloc_handle[0] != NULL)) 932 { 933 pProxy->nCurBufIndex--; 934 PROXY_require(pProxy->nCurBufIndex >=0, 935 OMX_ErrorBadParameter, "Buffer index underflow"); 936 937 if(pProxy->gralloc_handle[pProxy->nCurBufIndex]) 938 { 939 pProxy->mAllocDev->free(pProxy->mAllocDev, (buffer_handle_t)(pProxy->gralloc_handle[pProxy->nCurBufIndex])); 940 pProxy->gralloc_handle[pProxy->nCurBufIndex] = NULL; 941 } 942 943 /*Clear the Bufindex pipe by dummy reads*/ 944 TIMM_OSAL_GetPipeReadyMessageCount(pProxy->hBufPipe, (TIMM_OSAL_U32 *)&nCount); 945 if(nCount) 946 { 947 TIMM_OSAL_ReadFromPipe(pProxy->hBufPipe, &nBufIndex, 948 sizeof(OMX_PTR), (TIMM_OSAL_U32 *)&nSize, TIMM_OSAL_NO_SUSPEND); 949 } 950 } 951 952 eError = PROXY_FreeBuffer(hComponent, nPortIndex, pBufferHdr); 953 954 EXIT: 955 return eError; 956 } 957 958 int COLORCONVERT_AllocateBuffer(OMX_HANDLETYPE hComponent, OMX_U32 nStride) 959 { 960 OMX_CONFIG_RECTTYPE tParam; 961 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 962 OMX_U32 err; 963 OMX_ERRORTYPE eError = OMX_ErrorNone; 964 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 965 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 966 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 967 968 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 969 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 970 971 tParam.nSize = sizeof(OMX_CONFIG_RECTTYPE); 972 tParam.nVersion.s.nVersionMajor = 1; 973 tParam.nVersion.s.nVersionMinor = 1; 974 tParam.nVersion.s.nRevision = 0; 975 tParam.nVersion.s.nStep = 0; 976 tParam.nPortIndex = OMX_H264E_INPUT_PORT; 977 eError = PROXY_GetParameter(hComponent, (OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension, &tParam); 978 PROXY_assert(eError == OMX_ErrorNone, eError, " Error in Proxy GetParameter"); 979 err = pProxy->mAllocDev->alloc(pProxy->mAllocDev, (int) tParam.nWidth, (int) tParam.nHeight, (int) HAL_PIXEL_FORMAT_TI_NV12, (int) GRALLOC_USAGE_HW_RENDER, (const struct native_handle_t * *)(&(pProxy->gralloc_handle[pProxy->nCurBufIndex])), (int *) &nStride); 980 PROXY_assert(!err, err, " Error in allocating Gralloc buffers"); 981 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &pProxy->nCurBufIndex, sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 982 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, OMX_ErrorBadParameter, "Pipe write failed"); 983 984 EXIT: 985 return eError; 986 } 987 OMX_ERRORTYPE LOCAL_PROXY_H264E_ComponentDeInit(OMX_HANDLETYPE hComponent) 988 { 989 OMX_ERRORTYPE eError = OMX_ErrorNone; 990 PROXY_COMPONENT_PRIVATE *pCompPrv; 991 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 992 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 993 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 994 OMX_U32 i; 995 996 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 997 NULL); 998 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 999 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 1000 1001 if(pProxy->hBufPipe != NULL) 1002 { 1003 eOSALStatus = TIMM_OSAL_DeletePipe(pProxy->hBufPipe); 1004 pProxy->hBufPipe = NULL; 1005 1006 if(eOSALStatus != TIMM_OSAL_ERR_NONE) 1007 { 1008 DOMX_ERROR("Pipe deletion failed"); 1009 } 1010 } 1011 1012 if(pProxy->bAndroidOpaqueFormat == OMX_TRUE) 1013 { 1014 /* Cleanup internal buffers in pipe if not freed on FreeBuffer */ 1015 for(i=0; i<OMX_H264VE_NUM_INTERNAL_BUF; i++) 1016 { 1017 if(pProxy->gralloc_handle[i]) 1018 { 1019 pProxy->mAllocDev->free(pProxy->mAllocDev, (buffer_handle_t)(pProxy->gralloc_handle[i])); 1020 pProxy->gralloc_handle[i] = NULL; 1021 } 1022 } 1023 1024 1025 COLORCONVERT_close(pProxy->hCC,pCompPrv); 1026 pProxy->bAndroidOpaqueFormat = OMX_FALSE; 1027 1028 if(pCompPrv->pCompProxyPrv != NULL) 1029 { 1030 TIMM_OSAL_Free(pCompPrv->pCompProxyPrv); 1031 pCompPrv->pCompProxyPrv = NULL; 1032 } 1033 } 1034 1035 eError = PROXY_ComponentDeInit(hComponent); 1036 EXIT: 1037 DOMX_EXIT("eError: %d", eError); 1038 return eError; 1039 } 1040 1041 int COLORCONVERT_open(void **hCC, PROXY_COMPONENT_PRIVATE *pCompPrv) 1042 { 1043 int nErr = -1; 1044 hw_module_t const* module = NULL; 1045 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 1046 1047 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 1048 nErr = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); 1049 1050 if (nErr == 0) 1051 { 1052 *hCC = (void *) ((IMG_gralloc_module_public_t const *)module); 1053 } 1054 else 1055 { 1056 DOMX_ERROR("FATAL: gralloc api hw_get_module() returned error: Can't find \ 1057 %s module err = %x", GRALLOC_HARDWARE_MODULE_ID, nErr); 1058 } 1059 1060 gralloc_open(module, &(pProxy->mAllocDev)); 1061 1062 return nErr; 1063 } 1064 1065 int COLORCONVERT_PlatformOpaqueToNV12(void *hCC, 1066 void *pSrc[COLORCONVERT_MAX_SUB_BUFFERS], 1067 void *pDst[COLORCONVERT_MAX_SUB_BUFFERS], 1068 int nWidth, int nHeight, int nStride, 1069 int nSrcBufType,int nDstBufType) 1070 { 1071 IMG_gralloc_module_public_t const* module = hCC; 1072 int nErr = -1; 1073 1074 if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_VIRTUAL)) 1075 { 1076 nErr = module->Blit(module, pSrc[0], pDst, HAL_PIXEL_FORMAT_TI_NV12); 1077 } 1078 else if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE )) 1079 { 1080 nErr = module->Blit2(module, pSrc[0], pDst[0], nWidth, nHeight, 0, 0); 1081 } 1082 1083 return nErr; 1084 } 1085 1086 int COLORCONVERT_close(void *hCC,PROXY_COMPONENT_PRIVATE *pCompPrv) 1087 { 1088 OMX_PROXY_H264E_PRIVATE *pProxy = NULL; 1089 pProxy = (OMX_PROXY_H264E_PRIVATE *) pCompPrv->pCompProxyPrv; 1090 if(pProxy && pProxy->mAllocDev) 1091 { 1092 gralloc_close(pProxy->mAllocDev); 1093 } 1094 return 0; 1095 } 1096 #endif 1097