omx_proxy_mpeg4enc.c revision b471a4ea8699f7444612aa9e00fd2724e83a8d08
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_mpeg4enc.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 * 31-August-2011 Lakshman N : Support for color conv at encoder 53 * input port 54 * 55 *! 20-August-2010 Sarthak Aggarwal sarthak@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#define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.MPEG4E" 79/* needs to be specific for every configuration wrapper */ 80 81#define OMX_MPEG4E_INPUT_PORT 0 82#define LINUX_PAGE_SIZE 4096 83 84#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 85/* Opaque color format requires below quirks to be enabled 86 * ENABLE_GRALLOC_BUFFER 87 * ANDROID_QUIRK_CHANGE_PORT_VALUES 88 */ 89OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 90 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 91 92OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 93 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 94 95#endif 96 97#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 98#define OMX_MPEG4E_NUM_INTERNAL_BUF (8) 99#define HAL_PIXEL_FORMAT_TI_NV12 (0x100) 100 101#define COLORCONVERT_MAX_SUB_BUFFERS (3) 102 103#define COLORCONVERT_BUFTYPE_VIRTUAL (0x0) 104#define COLORCONVERT_BUFTYPE_ION (0x1) 105#define COLORCONVERT_BUFTYPE_GRALLOCOPAQUE (0x2) 106 107int COLORCONVERT_open(void **hCC, PROXY_COMPONENT_PRIVATE *pCompPrv); 108int COLORCONVERT_PlatformOpaqueToNV12(void *hCC, void *pSrc[], 109 void *pDst[], int nWidth, 110 int nHeight, int nStride, 111 int nSrcBufType, int nDstBufType); 112int COLORCONVERT_close(void *hCC,PROXY_COMPONENT_PRIVATE *pCompPrv); 113 114static OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent, 115 OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr, OMX_IN OMX_U32 nPortIndex, 116 OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes); 117 118static OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 119 OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr); 120 121static OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_ComponentDeInit(OMX_HANDLETYPE hComponent); 122 123typedef struct _OMX_PROXY_MPEG4E_PRIVATE 124{ 125 OMX_PTR hBufPipe; 126 OMX_BOOL bAndroidOpaqueFormat; 127 OMX_PTR hCC; 128 IMG_native_handle_t* gralloc_handle[OMX_MPEG4E_NUM_INTERNAL_BUF]; 129 OMX_S32 nCurBufIndex; 130 alloc_device_t* mAllocDev; 131}OMX_PROXY_MPEG4E_PRIVATE; 132#endif 133 134OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 135 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType); 136 137OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_EmptyThisBuffer(OMX_HANDLETYPE hComponent, 138 OMX_BUFFERHEADERTYPE * pBufferHdr); 139 140OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) 141{ 142 OMX_ERRORTYPE eError = OMX_ErrorNone; 143 OMX_COMPONENTTYPE *pHandle = NULL; 144 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 145 pHandle = (OMX_COMPONENTTYPE *) hComponent; 146 OMX_TI_PARAM_ENHANCEDPORTRECONFIG tParamStruct; 147#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 148 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 149 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 150#endif 151 152 DOMX_ENTER(""); 153 154 DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME); 155 156 pHandle->pComponentPrivate = 157 (PROXY_COMPONENT_PRIVATE *) 158 TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), TIMM_OSAL_TRUE, 159 0, TIMMOSAL_MEM_SEGMENT_INT); 160 161 PROXY_assert(pHandle->pComponentPrivate != NULL, 162 OMX_ErrorInsufficientResources, 163 "ERROR IN ALLOCATING PROXY COMPONENT PRIVATE STRUCTURE"); 164 165 pComponentPrivate = 166 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 167 168 TIMM_OSAL_Memset(pComponentPrivate, 0, 169 sizeof(PROXY_COMPONENT_PRIVATE)); 170 171 pComponentPrivate->cCompName = 172 TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8), 173 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 174 175 PROXY_assert(pComponentPrivate->cCompName != NULL, 176 OMX_ErrorInsufficientResources, 177 " Error in Allocating space for proxy component table"); 178 179#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 180 pComponentPrivate->pCompProxyPrv = 181 (OMX_PROXY_MPEG4E_PRIVATE *) 182 TIMM_OSAL_Malloc(sizeof(OMX_PROXY_MPEG4E_PRIVATE), TIMM_OSAL_TRUE, 183 0, TIMMOSAL_MEM_SEGMENT_INT); 184 185 PROXY_assert(pComponentPrivate->pCompProxyPrv != NULL, 186 OMX_ErrorInsufficientResources, 187 " Could not allocate proxy component private"); 188 189 TIMM_OSAL_Memset(pComponentPrivate->pCompProxyPrv, 0, 190 sizeof(OMX_PROXY_MPEG4E_PRIVATE)); 191 192 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pComponentPrivate->pCompProxyPrv; 193 194 /* Create Pipe of for encoder input buffers */ 195 eOSALStatus = TIMM_OSAL_CreatePipe(&pProxy->hBufPipe, sizeof(OMX_U32), 196 OMX_MPEG4E_NUM_INTERNAL_BUF, 1); 197 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, 198 OMX_ErrorInsufficientResources, 199 "Pipe creation failed"); 200 201#endif 202 203 // Copying component Name - this will be picked up in the proxy common 204 PROXY_assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH, 205 OMX_ErrorInvalidComponentName, 206 "Length of component name is longer than the max allowed"); 207 TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME, 208 strlen(COMPONENT_NAME) + 1); 209 210 eError = OMX_ProxyCommonInit(hComponent); // Calling Proxy Common Init() 211#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 212 pHandle->SetParameter = LOCAL_PROXY_MPEG4E_SetParameter; 213 pHandle->GetParameter = LOCAL_PROXY_MPEG4E_GetParameter; 214#endif 215 pHandle->ComponentDeInit = LOCAL_PROXY_MPEG4E_ComponentDeInit; 216 pHandle->FreeBuffer = LOCAL_PROXY_MPEG4E_FreeBuffer; 217 pHandle->AllocateBuffer = LOCAL_PROXY_MPEG4E_AllocateBuffer; 218 219 pComponentPrivate->IsLoadedState = OMX_TRUE; 220 pHandle->EmptyThisBuffer = LOCAL_PROXY_MPEG4E_EmptyThisBuffer; 221 pHandle->GetExtensionIndex = LOCAL_PROXY_MPEG4E_GetExtensionIndex; 222 223 EXIT: 224 if (eError != OMX_ErrorNone) 225 { 226 DOMX_DEBUG("Error in Initializing Proxy"); 227 228#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 229 if(pProxy->hBufPipe != NULL) 230 { 231 TIMM_OSAL_DeletePipe(pProxy->hBufPipe); 232 pProxy->hBufPipe = NULL; 233 } 234 235 if(pComponentPrivate->pCompProxyPrv != NULL) 236 { 237 TIMM_OSAL_Free(pComponentPrivate->pCompProxyPrv); 238 pComponentPrivate->pCompProxyPrv = NULL; 239 pProxy = NULL; 240 } 241#endif 242 if (pComponentPrivate->cCompName != NULL) 243 { 244 TIMM_OSAL_Free(pComponentPrivate->cCompName); 245 pComponentPrivate->cCompName = NULL; 246 } 247 if (pComponentPrivate != NULL) 248 { 249 TIMM_OSAL_Free(pComponentPrivate); 250 pComponentPrivate = NULL; 251 } 252 } 253 return eError; 254} 255 256#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 257 258/* ===========================================================================*/ 259/** 260 * @name PROXY_MPEG4E_GetParameter() 261 * @brief 262 * @param void 263 * @return OMX_ErrorNone = Successful 264 * @sa TBD 265 * 266 */ 267/* ===========================================================================*/ 268OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 269 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct) 270{ 271 OMX_ERRORTYPE eError = OMX_ErrorNone; 272 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 273 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 274 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL; 275 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParam = NULL; 276#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 277 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 278#endif 279 280 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 281 PROXY_assert((hComp->pComponentPrivate != NULL), 282 OMX_ErrorBadParameter, NULL); 283 284 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 285#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 286 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 287#endif 288 289 DOMX_ENTER 290 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 291 hComponent, pCompPrv, nParamIndex, pParamStruct); 292 293 eError = PROXY_GetParameter(hComponent,nParamIndex, pParamStruct); 294 295 if(nParamIndex == OMX_IndexParamPortDefinition) 296 { 297 pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 298 299 if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) 300 { 301#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 302 if(pProxy->bAndroidOpaqueFormat == OMX_TRUE) 303 { 304 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatAndroidOpaque; 305 } 306 else 307#endif 308 { 309 pPortDef->format.video.eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 310 } 311 } 312 } 313 else if (nParamIndex == OMX_IndexParamVideoPortFormat) 314 { 315 pPortParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 316 317 if((eError == OMX_ErrorNone) && 318 (pPortParam->eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar)) 319 { 320 pPortParam->eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 321 } 322#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 323 else if ((eError == OMX_ErrorNoMore) && (pPortParam->nIndex == 1)) 324 { 325 /* HACK:Remote OMX-MPEG4E supports only 1 color format (index 0). The 326 * OMX_COLOR_FormatAndroidOpaque is supported only at the proxy. 327 * Call GetParameter() to fill in defaults for parameters and 328 * override color format and index for the additional 329 * OMX_COLOR_FormatAndroidOpaque support*/ 330 pPortParam->nIndex = 0; 331 eError = PROXY_GetParameter(hComponent, nParamIndex, pParamStruct); 332 pPortParam->nIndex = 1; 333 pPortParam->eColorFormat = OMX_COLOR_FormatAndroidOpaque; 334 eError = OMX_ErrorNone; 335 } 336#endif 337 } 338 339 PROXY_assert((eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore), 340 eError," Error in Proxy GetParameter"); 341 342 EXIT: 343 DOMX_EXIT("eError: %d", eError); 344 return eError; 345} 346 347/* ===========================================================================*/ 348/** 349 * @name PROXY_MPEG4E_SetParameter() 350 * @brief 351 * @param void 352 * @return OMX_ErrorNone = Successful 353 * @sa TBD 354 * 355 */ 356/* ===========================================================================*/ 357OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 358 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct) 359{ 360 OMX_ERRORTYPE eError = OMX_ErrorNone; 361 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 362 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 363 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 364 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 365 OMX_VIDEO_STOREMETADATAINBUFFERSPARAMS* pStoreMetaData = (OMX_VIDEO_STOREMETADATAINBUFFERSPARAMS *) pParamStruct; 366 OMX_TI_PARAM_BUFFERPREANNOUNCE tParamSetNPA; 367 OMX_PARAM_PORTDEFINITIONTYPE sPortDef; 368#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 369 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 370#endif 371 372 DOMX_ENTER 373 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 374 hComponent, pCompPrv, nParamIndex, pParamStruct); 375 376 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 377 PROXY_require((hComp->pComponentPrivate != NULL), 378 OMX_ErrorBadParameter, NULL); 379 380 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 381#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 382 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 383#endif 384 385 if(nParamIndex == OMX_IndexParamPortDefinition) 386 { 387 if(pPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) 388 { 389 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 390 } 391#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 392 else if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque) 393 { 394 if(COLORCONVERT_open(&pProxy->hCC,pCompPrv) != 0) 395 { 396 PROXY_assert(0, OMX_ErrorInsufficientResources, 397 "Failed to open Color converting service"); 398 } 399 pProxy->bAndroidOpaqueFormat = OMX_TRUE; 400 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 401 } 402#endif 403 } 404 else if(nParamIndex == OMX_IndexParamVideoPortFormat) 405 { 406 if(pPortParams->eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) 407 { 408 pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 409 } 410#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 411 else if(pPortParams->eColorFormat == OMX_COLOR_FormatAndroidOpaque) 412 { 413 if(COLORCONVERT_open(&pProxy->hCC,pCompPrv) != 0) 414 { 415 PROXY_assert(0, OMX_ErrorInsufficientResources, 416 "Failed to open Color converting service"); 417 } 418 pProxy->bAndroidOpaqueFormat = OMX_TRUE; 419 pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 420 } 421#endif 422 } 423 else if(nParamIndex == (OMX_INDEXTYPE) OMX_TI_IndexEncoderStoreMetadatInBuffers) 424 { 425 DOMX_DEBUG("Moving to Metadatamode"); 426 if (pStoreMetaData->nPortIndex == OMX_MPEG4E_INPUT_PORT && pStoreMetaData->bStoreMetaData == OMX_TRUE) 427 { 428 tParamSetNPA.nSize = sizeof(OMX_TI_PARAM_BUFFERPREANNOUNCE); 429 tParamSetNPA.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 430 tParamSetNPA.nVersion.s.nVersionMinor = OMX_VER_MINOR; 431 tParamSetNPA.nVersion.s.nRevision = 0x0; 432 tParamSetNPA.nVersion.s.nStep = 0x0; 433 tParamSetNPA.nPortIndex = OMX_MPEG4E_INPUT_PORT; 434 tParamSetNPA.bEnabled = OMX_TRUE; 435 //Call NPA on OMX encoder on ducati. 436 PROXY_SetParameter(hComponent,OMX_TI_IndexParamBufferPreAnnouncement, &tParamSetNPA); 437 pCompPrv->proxyPortBuffers[pStoreMetaData->nPortIndex].proxyBufferType = EncoderMetadataPointers; 438 DOMX_DEBUG("Moving to Metadatamode done"); 439 440 /*Initializing Structure */ 441 sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 442 sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 443 sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR; 444 sPortDef.nVersion.s.nRevision = 0x0; 445 sPortDef.nVersion.s.nStep = 0x0; 446 sPortDef.nPortIndex = OMX_MPEG4E_INPUT_PORT; 447 448 eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition, &sPortDef); 449 PROXY_assert(eError == OMX_ErrorNone, eError," Error in Proxy GetParameter for Port Def"); 450 451 sPortDef.format.video.nStride = LINUX_PAGE_SIZE; 452 453 eError = PROXY_SetParameter(hComponent,OMX_IndexParamPortDefinition, &sPortDef); 454 455 PROXY_assert(eError == OMX_ErrorNone, eError," Error in Proxy SetParameter for Port Def"); 456 } 457 goto EXIT; 458 } 459 460 eError = PROXY_SetParameter(hComponent, nParamIndex, pParamStruct); 461 PROXY_assert(eError == OMX_ErrorNone, 462 eError," Error in Proxy SetParameter"); 463 464 EXIT: 465 DOMX_EXIT("eError: %d", eError); 466 return eError; 467} 468 469#endif 470 471 472/* ===========================================================================*/ 473/** 474 * @name PROXY_GetExtensionIndex() 475 * @brief 476 * @param void 477 * @return OMX_ErrorNone = Successful 478 * @sa TBD 479 * 480 */ 481/* ===========================================================================*/ 482OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 483 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType) 484{ 485 OMX_ERRORTYPE eError = OMX_ErrorNone; 486 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 487 OMX_COMPONENTTYPE *hComp = hComponent; 488 489 PROXY_require((hComp->pComponentPrivate != NULL), 490 OMX_ErrorBadParameter, NULL); 491 PROXY_require(cParameterName != NULL, OMX_ErrorBadParameter, NULL); 492 PROXY_require(pIndexType != NULL, OMX_ErrorBadParameter, NULL); 493 494 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 495 496 DOMX_ENTER("%s hComponent = %p, pCompPrv = %p, cParameterName = %s", 497 __FUNCTION__,hComponent, pCompPrv, cParameterName); 498 499 // Check for NULL Parameters 500 PROXY_require((cParameterName != NULL && pIndexType != NULL), 501 OMX_ErrorBadParameter, NULL); 502 503 // Ensure that String length is not greater than Max allowed length 504 PROXY_require(strlen(cParameterName) <= 127, OMX_ErrorBadParameter, NULL); 505 506 if(strcmp(cParameterName, "OMX.google.android.index.storeMetaDataInBuffers") == 0) 507 { 508 // If Index type is 2D Buffer Allocated Dimension 509 *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexEncoderStoreMetadatInBuffers; 510 goto EXIT; 511 } 512 513 PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType); 514 515 EXIT: 516 DOMX_EXIT("%s eError: %d",__FUNCTION__, eError); 517 return eError; 518} 519 520/* ===========================================================================*/ 521/** 522 * @name PROXY_MPEG4E_EmptyThisBuffer() 523 * @brief 524 * @param void 525 * @return OMX_ErrorNone = Successful 526 * @sa TBD 527 * 528 */ 529/* ===========================================================================*/ 530OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_EmptyThisBuffer(OMX_HANDLETYPE hComponent, 531 OMX_BUFFERHEADERTYPE * pBufferHdr) 532{ 533 534 OMX_ERRORTYPE eError = OMX_ErrorNone; 535 PROXY_COMPONENT_PRIVATE *pCompPrv; 536 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 537 OMX_PTR pBufferOrig = NULL; 538 OMX_U32 nStride = 0, nNumLines = 0; 539#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 540 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 541 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 542 OMX_U32 nBufIndex = 0, nSize=0, nRet=0; 543#endif 544 545 PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL); 546 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 547 NULL); 548 PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE); 549 550 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 551#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 552 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 553#endif 554 555 DOMX_DEBUG 556 ("%s hComponent=%p, pCompPrv=%p, nFilledLen=%d, nOffset=%d, nFlags=%08x", 557 __FUNCTION__,hComponent, pCompPrv, pBufferHdr->nFilledLen, 558 pBufferHdr->nOffset, pBufferHdr->nFlags); 559 560 if( pCompPrv->proxyPortBuffers[OMX_MPEG4E_INPUT_PORT].proxyBufferType == EncoderMetadataPointers) 561 { 562 OMX_U32 *pTempBuffer; 563 OMX_U32 nMetadataBufferType; 564 DOMX_DEBUG("Passing meta data to encoder"); 565 566 pBufferOrig = pBufferHdr->pBuffer; 567 568 pTempBuffer = (OMX_U32 *) (pBufferHdr->pBuffer); 569 nMetadataBufferType = *pTempBuffer; 570 571 if(nMetadataBufferType == kMetadataBufferTypeCameraSource) 572 { 573#ifdef ENABLE_GRALLOC_BUFFER 574 IMG_native_handle_t* pGrallocHandle; 575 video_metadata_t* pVideoMetadataBuffer; 576 DOMX_DEBUG("MetadataBufferType is kMetadataBufferTypeCameraSource"); 577 578 pVideoMetadataBuffer = (video_metadata_t*) ((OMX_U32 *)(pBufferHdr->pBuffer)); 579 pGrallocHandle = (IMG_native_handle_t*) (pVideoMetadataBuffer->handle); 580 DOMX_DEBUG("Grallloc buffer recieved in metadata buffer 0x%x",pGrallocHandle ); 581 582 pBufferHdr->pBuffer = (OMX_U8 *)(pGrallocHandle->fd[0]); 583 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)-> 584 pAuxBuf1 = (OMX_PTR) pGrallocHandle->fd[1]; 585 DOMX_DEBUG("%s Gralloc=0x%x, Y-fd=%d, UV-fd=%d", __FUNCTION__, pGrallocHandle, 586 pGrallocHandle->fd[0], pGrallocHandle->fd[1]); 587 588 pBufferHdr->nOffset = pVideoMetadataBuffer->offset; 589#endif 590 } 591 else if(nMetadataBufferType == kMetadataBufferTypeGrallocSource) 592 { 593#ifdef ENABLE_GRALLOC_BUFFER 594 IMG_native_handle_t* pGrallocHandle; 595 buffer_handle_t tBufHandle; 596 DOMX_DEBUG("MetadataBufferType is kMetadataBufferTypeGrallocSource"); 597 598 pTempBuffer++; 599 tBufHandle = *((buffer_handle_t *)pTempBuffer); 600 pGrallocHandle = (IMG_native_handle_t*) tBufHandle; 601 DOMX_DEBUG("Grallloc buffer recieved in metadata buffer 0x%x",pGrallocHandle ); 602 603 pBufferHdr->pBuffer = (OMX_U8 *)(pGrallocHandle->fd[0]); 604 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)-> 605 pAuxBuf1 = (OMX_PTR) pGrallocHandle->fd[1]; 606 DOMX_DEBUG("%s Gralloc=0x%x, Y-fd=%d, UV-fd=%d", __FUNCTION__, pGrallocHandle, 607 pGrallocHandle->fd[0], pGrallocHandle->fd[1]); 608#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 609 if (pProxy->bAndroidOpaqueFormat) 610 { 611 DOMX_DEBUG(" ++TIMM_OSAL_ReadFromPipe() "); 612 /* Dequeue NV12 buffer for encoder */ 613 eOSALStatus = TIMM_OSAL_ReadFromPipe(pProxy->hBufPipe, &nBufIndex, 614 sizeof(OMX_PTR), (TIMM_OSAL_U32 *)(&nSize), 615 TIMM_OSAL_SUSPEND); 616 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, OMX_ErrorBadParameter, NULL); 617 618 /* Get NV12 data after colorconv*/ 619 nRet = COLORCONVERT_PlatformOpaqueToNV12(pProxy->hCC, (void **) &pGrallocHandle, (void **) &pProxy->gralloc_handle[nBufIndex], 620 pGrallocHandle->iWidth, 621 pGrallocHandle->iHeight, 622 4096, COLORCONVERT_BUFTYPE_GRALLOCOPAQUE, 623 COLORCONVERT_BUFTYPE_GRALLOCOPAQUE ); 624 if(nRet != 0) 625 { 626 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &nBufIndex, 627 sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 628 PROXY_assert(0, OMX_ErrorBadParameter, "Color conversion routine failed"); 629 } 630 DOMX_DEBUG(" --COLORCONVERT_PlatformOpaqueToNV12() "); 631 632 /* Update pBufferHdr with NV12 buffers for OMX component */ 633 pBufferHdr->pBuffer= pProxy->gralloc_handle[nBufIndex]->fd[0]; 634 ((OMX_TI_PLATFORMPRIVATE *) pBufferHdr->pPlatformPrivate)->pAuxBuf1 = pProxy->gralloc_handle[nBufIndex]->fd[1]; 635 } 636#endif 637#endif 638 } 639 else 640 { 641 return OMX_ErrorBadParameter; 642 } 643 } 644 645 PROXY_EmptyThisBuffer(hComponent, pBufferHdr); 646#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 647 if (pProxy->bAndroidOpaqueFormat) 648 { 649 /*Write buffer to end of pipe for re-circulation for future ETB()*/ 650 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &nBufIndex, 651 sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 652 PROXY_assert(eOSALStatus == TIMM_OSAL_ERR_NONE, OMX_ErrorBadParameter, "Pipe write failed"); 653 } 654#endif 655 if( pCompPrv->proxyPortBuffers[pBufferHdr->nInputPortIndex].proxyBufferType == EncoderMetadataPointers) 656 pBufferHdr->pBuffer = pBufferOrig; 657 658 EXIT: 659 return eError; 660} 661 662#ifdef ANDROID_CUSTOM_OPAQUECOLORFORMAT 663static OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_AllocateBuffer(OMX_HANDLETYPE hComponent, 664 OMX_BUFFERHEADERTYPE ** ppBufferHdr, OMX_U32 nPortIndex, 665 OMX_PTR pAppPrivate, OMX_U32 nSizeBytes) 666{ 667 OMX_ERRORTYPE eError = OMX_ErrorNone; 668 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 669 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 670 OMX_CONFIG_RECTTYPE tParamRect; 671 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 672 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 673 DOMX_DEBUG(" ++LOCAL_PROXY_MPEG4E_AllocateBuffer"); 674 int err, nStride; 675 676 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 677 NULL); 678 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 679 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 680 681 if((nPortIndex == OMX_MPEG4E_INPUT_PORT) && 682 (pProxy->bAndroidOpaqueFormat)) 683 { 684 tParamRect.nSize = sizeof(OMX_CONFIG_RECTTYPE); 685 tParamRect.nVersion.s.nVersionMajor = 1; 686 tParamRect.nVersion.s.nVersionMinor = 1; 687 tParamRect.nVersion.s.nRevision = 0; 688 tParamRect.nVersion.s.nStep = 0; 689 tParamRect.nPortIndex = nPortIndex; 690 691 eError = PROXY_GetParameter(hComponent, (OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension, &tParamRect); 692 PROXY_assert(eError == OMX_ErrorNone, eError," Error in Proxy GetParameter from 2d index in allocate buffer"); 693 694 err = pProxy->mAllocDev->alloc(pProxy->mAllocDev,(int) tParamRect.nWidth,(int) tParamRect.nHeight, 695 (int) HAL_PIXEL_FORMAT_TI_NV12,(int) GRALLOC_USAGE_HW_RENDER, &(pProxy->gralloc_handle[pProxy->nCurBufIndex]), &nStride); 696 } 697 698 eError = PROXY_AllocateBuffer(hComponent, ppBufferHdr, nPortIndex, 699 pAppPrivate, nSizeBytes); 700EXIT: 701 if((nPortIndex == OMX_MPEG4E_INPUT_PORT) && 702 (pProxy->bAndroidOpaqueFormat)) 703 { 704 if(eError != OMX_ErrorNone) 705 { 706 err = pProxy->mAllocDev->free(pProxy->mAllocDev, pProxy->gralloc_handle[pProxy->nCurBufIndex]); 707 } 708 else 709 { 710 /*Populate buffer to pipe*/ 711 eOSALStatus = TIMM_OSAL_WriteToPipe(pProxy->hBufPipe, (void *) &pProxy->nCurBufIndex, 712 sizeof(OMX_U32), TIMM_OSAL_SUSPEND); 713 pProxy->nCurBufIndex++; 714 } 715 } 716 DOMX_DEBUG(" --LOCAL_PROXY_MPEG4E_AllocateBuffer"); 717 return eError; 718} 719 720static OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, 721 OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr) 722{ 723 OMX_ERRORTYPE eError = OMX_ErrorNone; 724 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 725 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 726 OMX_U32 nBufIndex, nSize, nCount=0; 727 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 728 729 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 730 NULL); 731 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 732 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 733 734 if((nPortIndex == OMX_MPEG4E_INPUT_PORT) && 735 (pProxy->bAndroidOpaqueFormat)) 736 { 737 pProxy->nCurBufIndex--; 738 PROXY_require(pProxy->nCurBufIndex >=0, 739 OMX_ErrorBadParameter, "Buffer index underflow"); 740 741 if(pProxy->gralloc_handle[pProxy->nCurBufIndex]) 742 { 743 pProxy->mAllocDev->free(pProxy->mAllocDev, pProxy->gralloc_handle[pProxy->nCurBufIndex]); 744 pProxy->gralloc_handle[pProxy->nCurBufIndex] = NULL; 745 } 746 747 /*Clear the Bufindex pipe by dummy reads*/ 748 TIMM_OSAL_GetPipeReadyMessageCount(pProxy->hBufPipe, (TIMM_OSAL_U32 *)&nCount); 749 if(nCount) 750 { 751 TIMM_OSAL_ReadFromPipe(pProxy->hBufPipe, &nBufIndex, 752 sizeof(OMX_PTR), (TIMM_OSAL_U32 *)&nSize, TIMM_OSAL_NO_SUSPEND); 753 } 754 } 755 756 eError = PROXY_FreeBuffer(hComponent, nPortIndex, pBufferHdr); 757 758EXIT: 759 return eError; 760} 761 762OMX_ERRORTYPE LOCAL_PROXY_MPEG4E_ComponentDeInit(OMX_HANDLETYPE hComponent) 763{ 764 OMX_ERRORTYPE eError = OMX_ErrorNone; 765 PROXY_COMPONENT_PRIVATE *pCompPrv; 766 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 767 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 768 TIMM_OSAL_ERRORTYPE eOSALStatus = TIMM_OSAL_ERR_NONE; 769 OMX_U32 i; 770 771 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 772 NULL); 773 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 774 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 775 776 if(pProxy->hBufPipe != NULL) 777 { 778 eOSALStatus = TIMM_OSAL_DeletePipe(pProxy->hBufPipe); 779 pProxy->hBufPipe = NULL; 780 781 if(eOSALStatus != TIMM_OSAL_ERR_NONE) 782 { 783 DOMX_ERROR("Pipe deletion failed"); 784 } 785 } 786 787 if(pProxy->bAndroidOpaqueFormat == OMX_TRUE) 788 { 789 /* Cleanup internal buffers in pipe if not freed on FreeBuffer */ 790 for(i=0; i<OMX_MPEG4E_NUM_INTERNAL_BUF; i++) 791 { 792 if(pProxy->gralloc_handle[i]) 793 { 794 pProxy->mAllocDev->free(pProxy->mAllocDev, pProxy->gralloc_handle[i]); 795 pProxy->gralloc_handle[i] = NULL; 796 } 797 } 798 799 COLORCONVERT_close(pProxy->hCC,pCompPrv); 800 pProxy->bAndroidOpaqueFormat = OMX_FALSE; 801 802 if(pCompPrv->pCompProxyPrv != NULL) 803 { 804 TIMM_OSAL_Free(pCompPrv->pCompProxyPrv); 805 pCompPrv->pCompProxyPrv = NULL; 806 } 807 } 808 809 eError = PROXY_ComponentDeInit(hComponent); 810EXIT: 811 DOMX_EXIT("eError: %d", eError); 812 return eError; 813} 814 815int COLORCONVERT_open(void **hCC, PROXY_COMPONENT_PRIVATE *pCompPrv) 816{ 817 int nErr = -1; 818 hw_module_t const* module = NULL; 819 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 820 821 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 822 nErr = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); 823 824 if (nErr == 0) 825 { 826 *hCC = (void *) ((IMG_gralloc_module_public_t const *)module); 827 } 828 else 829 { 830 DOMX_ERROR("FATAL: gralloc api hw_get_module() returned error: Can't find \ 831 %s module err = %x", GRALLOC_HARDWARE_MODULE_ID, nErr); 832 } 833 834 gralloc_open(module, &(pProxy->mAllocDev)); 835 836 return nErr; 837} 838 839int COLORCONVERT_PlatformOpaqueToNV12(void *hCC, 840 void *pSrc[COLORCONVERT_MAX_SUB_BUFFERS], 841 void *pDst[COLORCONVERT_MAX_SUB_BUFFERS], 842 int nWidth, int nHeight, int nStride, 843 int nSrcBufType,int nDstBufType) 844{ 845 IMG_gralloc_module_public_t const* module = hCC; 846 int nErr = -1; 847 848 if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_VIRTUAL)) 849 { 850 nErr = module->Blit(module, pSrc[0], pDst, HAL_PIXEL_FORMAT_TI_NV12); 851 852 } 853 else if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE )) 854 { 855 nErr = module->Blit2(module, pSrc[0], pDst[0], nWidth, nHeight, 0, 0); 856 } 857 858 return nErr; 859} 860 861int COLORCONVERT_close(void *hCC,PROXY_COMPONENT_PRIVATE *pCompPrv) 862{ 863 OMX_PROXY_MPEG4E_PRIVATE *pProxy = NULL; 864 pProxy = (OMX_PROXY_MPEG4E_PRIVATE *) pCompPrv->pCompProxyPrv; 865 if(pProxy && pProxy->mAllocDev) 866 { 867 gralloc_close(pProxy->mAllocDev); 868 } 869 return 0; 870} 871#endif 872