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_videodecoder.c 35 * This file contains methods that provides the functionality for 36 * the OpenMAX1.1 DOMX Framework Tunnel 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 *! 20-August-2010 Sarthak Aggarwal sarthak@ti.com: Initial Version 53 *================================================================*/ 54 55/****************************************************************** 56 * INCLUDE FILES 57 ******************************************************************/ 58#include <stdio.h> 59#include <string.h> 60#include <assert.h> 61#include "omx_proxy_common.h" 62#include <timm_osal_interfaces.h> 63#include "OMX_TI_IVCommon.h" 64#include "OMX_TI_Video.h" 65#include "OMX_TI_Index.h" 66 67#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 68#define LOG_TAG "OMXPROXYVIDEODEC" 69#include <fcntl.h> 70#include <cutils/properties.h> 71#include <utils/Log.h> 72#endif 73 74#define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.DECODER" 75/* needs to be specific for every configuration wrapper */ 76 77#ifdef USE_ENHANCED_PORTRECONFIG 78//Define port indices in video decoder proxy 79#define OMX_VIDEODECODER_INPUT_PORT 0 80#define OMX_VIDEODECODER_OUTPUT_PORT 1 81#endif 82 83#ifdef SET_STRIDE_PADDING_FROM_PROXY 84 85#define LINUX_PAGE_SIZE (4 * 1024) 86#define TOTAL_DEC_PORTS 2 87#define HAL_NV12_PADDED_PIXEL_FORMAT (OMX_TI_COLOR_FormatYUV420PackedSemiPlanar - OMX_COLOR_FormatVendorStartUnused) 88 89static OMX_ERRORTYPE RPC_UTIL_SetStrideAndPadding(OMX_COMPONENTTYPE * hRemoteComp, PROXY_COMPONENT_PRIVATE * pCompPrv); 90 91OMX_ERRORTYPE PROXY_VIDDEC_SendCommand(OMX_IN OMX_HANDLETYPE hComponent, 92 OMX_IN OMX_COMMANDTYPE eCmd, 93 OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData); 94 95OMX_ERRORTYPE PROXY_VIDDEC_EventHandler(OMX_HANDLETYPE hComponent, 96 OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, 97 OMX_PTR pEventData); 98 99#endif //SET_STRIDE_PADDING_FROM_PROXY 100 101OMX_ERRORTYPE PROXY_VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 102 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType); 103 104#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 105 106OMX_ERRORTYPE PROXY_VIDDEC_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 107 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 108 109OMX_ERRORTYPE PROXY_VIDDEC_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 110 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct); 111 112#endif 113 114#ifdef ANDROID_QUIRK_LOCK_BUFFER 115#include <hardware/gralloc.h> 116#include <hardware/hardware.h> 117#include "hal_public.h" 118 119OMX_ERRORTYPE PROXY_VIDDEC_FillThisBuffer(OMX_HANDLETYPE hComponent, OMX_BUFFERHEADERTYPE * pBufferHdr); 120OMX_ERRORTYPE PROXY_VIDDEC_FillBufferDone(OMX_HANDLETYPE hComponent, 121 OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags, 122 OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent, 123 OMX_PTR pMarkData); 124 125#endif 126extern OMX_ERRORTYPE PrearrageEmptyThisBuffer(OMX_HANDLETYPE hComponent, 127 OMX_BUFFERHEADERTYPE * pBufferHdr); 128 129#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 130extern void DumpVideoFrame(DebugFrame_Dump *frameInfo); 131#endif 132 133OMX_ERRORTYPE OMX_ProxyViddecInit(OMX_HANDLETYPE hComponent); 134 135OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) 136{ 137 OMX_ERRORTYPE eError = OMX_ErrorNone; 138 OMX_COMPONENTTYPE *pHandle = NULL; 139 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 140 pHandle = (OMX_COMPONENTTYPE *) hComponent; 141 142 DOMX_ENTER(""); 143 144 DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME); 145 146 pHandle->pComponentPrivate = 147 (PROXY_COMPONENT_PRIVATE *) 148 TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), TIMM_OSAL_TRUE, 149 0, TIMMOSAL_MEM_SEGMENT_INT); 150 151 PROXY_assert(pHandle->pComponentPrivate != NULL, 152 OMX_ErrorInsufficientResources, 153 "ERROR IN ALLOCATING PROXY COMPONENT PRIVATE STRUCTURE"); 154 155 pComponentPrivate = 156 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 157 158 TIMM_OSAL_Memset(pComponentPrivate, 0, 159 sizeof(PROXY_COMPONENT_PRIVATE)); 160 161 pComponentPrivate->cCompName = 162 TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8), 163 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 164 165 PROXY_assert(pComponentPrivate->cCompName != NULL, 166 OMX_ErrorInsufficientResources, 167 " Error in Allocating space for proxy component table"); 168 169 eError = OMX_ProxyViddecInit(hComponent); 170 171#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 172 if (eError == OMX_ErrorNone) 173 { 174 char value[PROPERTY_VALUE_MAX]; 175 property_get("debug.video.dumpframe", value, "0:0"); 176 /* -ve value for fromFrame would disable this automatically */ 177 pComponentPrivate->debugframeInfo.fromFrame = atoi(strtok(value, ":")); 178 pComponentPrivate->debugframeInfo.toFrame = atoi(strtok(NULL, ":")); 179 pComponentPrivate->debugframeInfo.runningFrame = pComponentPrivate->debugframeInfo.fromFrame; 180 } 181#endif 182 EXIT: 183 if (eError != OMX_ErrorNone) 184 { 185 DOMX_DEBUG("Error in Initializing Proxy"); 186 if (pComponentPrivate->cCompName != NULL) 187 { 188 TIMM_OSAL_Free(pComponentPrivate->cCompName); 189 pComponentPrivate->cCompName = NULL; 190 } 191 if (pComponentPrivate != NULL) 192 { 193 TIMM_OSAL_Free(pComponentPrivate); 194 pComponentPrivate = NULL; 195 } 196 } 197 return eError; 198} 199 200OMX_ERRORTYPE OMX_ProxyViddecInit(OMX_HANDLETYPE hComponent) 201{ 202 OMX_ERRORTYPE eError = OMX_ErrorNone; 203 OMX_COMPONENTTYPE *pHandle = NULL; 204 PROXY_COMPONENT_PRIVATE *pComponentPrivate = NULL; 205 pHandle = (OMX_COMPONENTTYPE *) hComponent; 206 OMX_TI_PARAM_ENHANCEDPORTRECONFIG tParamStruct; 207 208#ifdef ANDROID_QUIRK_LOCK_BUFFER 209 OMX_U32 err; 210 hw_module_t const* module; 211#endif 212 DOMX_ENTER(""); 213 214 DOMX_DEBUG("Component name provided is %s", COMPONENT_NAME); 215 216 pComponentPrivate = 217 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 218 219 // Copying component Name - this will be picked up in the proxy common 220 PROXY_assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH, 221 OMX_ErrorInvalidComponentName, 222 "Length of component name is longer than the max allowed"); 223 TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME, 224 strlen(COMPONENT_NAME) + 1); 225 226 eError = OMX_ProxyCommonInit(hComponent); // Calling Proxy Common Init() 227 PROXY_assert(eError == OMX_ErrorNone, eError, "Proxy common init returned error"); 228#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 229 pHandle->SetParameter = PROXY_VIDDEC_SetParameter; 230 pHandle->GetParameter = PROXY_VIDDEC_GetParameter; 231#endif 232 pHandle->GetExtensionIndex = PROXY_VIDDEC_GetExtensionIndex; 233 234#ifdef SET_STRIDE_PADDING_FROM_PROXY 235 pHandle->SendCommand = PROXY_VIDDEC_SendCommand; 236 pComponentPrivate->proxyEventHandler = PROXY_VIDDEC_EventHandler; 237 pComponentPrivate->IsLoadedState = OMX_TRUE; 238#endif 239 240#ifdef ANDROID_QUIRK_LOCK_BUFFER 241 pComponentPrivate->proxyFillBufferDone = PROXY_VIDDEC_FillBufferDone; 242 pHandle->FillThisBuffer = PROXY_VIDDEC_FillThisBuffer; 243 244 err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); 245 if (err == 0) 246 { 247 pComponentPrivate->grallocModule = (gralloc_module_t const *)module; 248 } 249 else 250 { 251 DOMX_ERROR("FATAL: gralloc api hw_get_module() returned error: Can't find \ 252 %s module err = %x", GRALLOC_HARDWARE_MODULE_ID, err); 253 eError = OMX_ErrorInsufficientResources; 254 return eError; 255 } 256#endif 257 258#ifdef USE_ENHANCED_PORTRECONFIG 259 /*Initializing Structure */ 260 tParamStruct.nSize = sizeof(OMX_TI_PARAM_ENHANCEDPORTRECONFIG); 261 tParamStruct.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 262 tParamStruct.nVersion.s.nVersionMinor = OMX_VER_MINOR; 263 tParamStruct.nVersion.s.nRevision = 0x0; 264 tParamStruct.nVersion.s.nStep = 0x0; 265 tParamStruct.nPortIndex = OMX_VIDEODECODER_OUTPUT_PORT; 266 tParamStruct.bUsePortReconfigForCrop = OMX_TRUE; 267 tParamStruct.bUsePortReconfigForPadding = OMX_TRUE; 268 269 eError = PROXY_SetParameter(hComponent,(OMX_INDEXTYPE)OMX_TI_IndexParamUseEnhancedPortReconfig, 270 &tParamStruct); 271 PROXY_assert(eError == OMX_ErrorNone, 272 eError," Error in Proxy SetParameter for Enhanced port reconfig usage"); 273#endif 274 /* This is required to handle WMV/VC-1 content */ 275 pHandle->EmptyThisBuffer = PrearrageEmptyThisBuffer; 276 277 EXIT: 278 return eError; 279} 280 281/* ===========================================================================*/ 282/** 283 * @name PROXY_VIDDEC_GetExtensionIndex() 284 * @brief 285 * @param void 286 * @return OMX_ErrorNone = Successful 287 * @sa TBD 288 * 289 */ 290/* ===========================================================================*/ 291OMX_ERRORTYPE PROXY_VIDDEC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 292 OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType) 293{ 294 OMX_ERRORTYPE eError = OMX_ErrorNone; 295 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 296 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 297 298 PROXY_require((hComp->pComponentPrivate != NULL), OMX_ErrorBadParameter, NULL); 299 PROXY_require(cParameterName != NULL, OMX_ErrorBadParameter, NULL); 300 PROXY_require(pIndexType != NULL, OMX_ErrorBadParameter, NULL); 301 302 DOMX_ENTER("hComponent = %p, cParameterName = %p", hComponent, cParameterName); 303 304#ifdef ENABLE_GRALLOC_BUFFERS 305 // Ensure that String length is not greater than Max allowed length 306 PROXY_require(strlen(cParameterName) <= 127, OMX_ErrorBadParameter, NULL); 307 308 if (strcmp(cParameterName, "OMX.google.android.index.getAndroidNativeBufferUsage") == 0) 309 { 310 *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexAndroidNativeBufferUsage; 311 } 312 else 313 { 314 eError = PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType); 315 PROXY_assert(eError == OMX_ErrorNone, 316 eError," Error in PROXY_GetExtensionIndex"); 317 } 318#else 319 eError = PROXY_GetExtensionIndex(hComponent, cParameterName, pIndexType); 320 PROXY_assert(eError == OMX_ErrorNone, 321 eError," Error in PROXY_GetExtensionIndex"); 322#endif 323 EXIT: 324 DOMX_EXIT("eError: %d", eError); 325 return eError; 326} 327 328#ifdef ANDROID_QUIRK_CHANGE_PORT_VALUES 329 330/* ===========================================================================*/ 331/** 332 * @name PROXY_GetParameter() 333 * @brief 334 * @param void 335 * @return OMX_ErrorNone = Successful 336 * @sa TBD 337 * 338 */ 339/* ===========================================================================*/ 340OMX_ERRORTYPE PROXY_VIDDEC_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, 341 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct) 342{ 343 OMX_ERRORTYPE eError = OMX_ErrorNone; 344 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 345 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 346 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL; 347 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParam = NULL; 348 OMX_TI_PARAMNATIVEBUFFERUSAGE *pUsage = NULL; 349 350 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 351 PROXY_assert((hComp->pComponentPrivate != NULL), 352 OMX_ErrorBadParameter, NULL); 353 354 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 355 356 DOMX_ENTER 357 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 358 hComponent, pCompPrv, nParamIndex, pParamStruct); 359 360#ifdef ENABLE_GRALLOC_BUFFERS 361 if( nParamIndex == OMX_TI_IndexAndroidNativeBufferUsage) 362 { 363 pUsage = (OMX_TI_PARAMNATIVEBUFFERUSAGE*)pParamStruct; 364 if(pCompPrv->proxyPortBuffers[pUsage->nPortIndex].proxyBufferType == GrallocPointers) 365 { 366 PROXY_CHK_VERSION(pParamStruct, OMX_TI_PARAMNATIVEBUFFERUSAGE); 367 pUsage->nUsage = GRALLOC_USAGE_HW_RENDER; 368#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 369 pUsage->nUsage |= GRALLOC_USAGE_SW_READ_RARELY; 370#endif 371 goto EXIT; 372 } 373 } 374#endif 375 eError = PROXY_GetParameter(hComponent,nParamIndex, pParamStruct); 376 PROXY_assert(eError == OMX_ErrorNone, 377 eError," Error in Proxy GetParameter"); 378 379 if( nParamIndex == OMX_IndexParamPortDefinition) 380 { 381 PROXY_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE); 382 pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 383 if(pPortDef->format.video.eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) 384 { 385 if(pCompPrv->proxyPortBuffers[pPortDef->nPortIndex].proxyBufferType == GrallocPointers) 386 { 387 pPortDef->format.video.eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT; 388 } 389 else 390 { 391 pPortDef->format.video.eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 392 } 393 } 394 } 395 else if ( nParamIndex == OMX_IndexParamVideoPortFormat) 396 { 397 PROXY_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE); 398 pPortParam = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 399 if(pPortParam->eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) 400 { 401 if(pCompPrv->proxyPortBuffers[pPortParam->nPortIndex].proxyBufferType == GrallocPointers) 402 { 403 pPortParam->eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT; 404 } 405 else 406 { 407 pPortParam->eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; 408 } 409 } 410 } 411 412 EXIT: 413 DOMX_EXIT("eError: %d", eError); 414 return eError; 415} 416 417/* ===========================================================================*/ 418/** 419 * @name PROXY_SetParameter() 420 * @brief 421 * @param void 422 * @return OMX_ErrorNone = Successful 423 * @sa TBD 424 * 425 */ 426/* ===========================================================================*/ 427OMX_ERRORTYPE PROXY_VIDDEC_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, 428 OMX_IN OMX_INDEXTYPE nParamIndex, OMX_IN OMX_PTR pParamStruct) 429{ 430 OMX_ERRORTYPE eError = OMX_ErrorNone; 431 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 432 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 433 OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; 434 OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; 435 436 PROXY_require((pParamStruct != NULL), OMX_ErrorBadParameter, NULL); 437 PROXY_require((hComp->pComponentPrivate != NULL), 438 OMX_ErrorBadParameter, NULL); 439 440 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 441 DOMX_ENTER 442 ("hComponent = %p, pCompPrv = %p, nParamIndex = %d, pParamStruct = %p", 443 hComponent, pCompPrv, nParamIndex, pParamStruct); 444 if(nParamIndex == OMX_IndexParamPortDefinition) 445 { 446 if(pPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar 447 || pPortDef->format.video.eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT) 448 { 449 pPortDef->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 450 } 451 } 452 else if(nParamIndex == OMX_IndexParamVideoPortFormat) 453 { 454 if(pPortParams->eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar 455 || pPortParams->eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT) 456 { 457 pPortParams->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; 458 } 459 } 460 461 eError = PROXY_SetParameter(hComponent, nParamIndex, pParamStruct); 462 PROXY_assert(eError == OMX_ErrorNone, 463 eError," Error in Proxy SetParameter"); 464 465 EXIT: 466 DOMX_EXIT("eError: %d", eError); 467 return eError; 468} 469 470#endif 471 472#ifdef SET_STRIDE_PADDING_FROM_PROXY 473/* ===========================================================================*/ 474/** 475 * @name PROXY_VIDDEC_SendCommand() 476 * @brief 477 * @return OMX_ErrorNone = Successful 478 * @sa TBD 479 * 480 */ 481/* ===========================================================================*/ 482OMX_ERRORTYPE PROXY_VIDDEC_SendCommand(OMX_IN OMX_HANDLETYPE hComponent, 483 OMX_IN OMX_COMMANDTYPE eCmd, 484 OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData) 485{ 486 OMX_ERRORTYPE eError = OMX_ErrorNone; 487 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 488 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 489 490 PROXY_require((hComp->pComponentPrivate != NULL), 491 OMX_ErrorBadParameter, NULL); 492 493 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 494 495 DOMX_ENTER 496 ("hComponent = %p, pCompPrv = %p, eCmd = %d, nParam = %d, pCmdData = %p", 497 hComponent, pCompPrv, eCmd, nParam, pCmdData); 498 499 if(eCmd == OMX_CommandStateSet) 500 { 501 //Set appropriate stride before Loaded to Idle transition. 502 if((OMX_STATETYPE)nParam == OMX_StateIdle && pCompPrv->IsLoadedState == OMX_TRUE) 503 { 504 eError = RPC_UTIL_SetStrideAndPadding(hComponent, pCompPrv); 505 PROXY_require(eError == OMX_ErrorNone, eError, 506 "Stride and padding setting from proxy returned"); 507 pCompPrv->IsLoadedState = OMX_FALSE; 508 } 509 } 510 else if(eCmd == OMX_CommandPortEnable) 511 { 512 if(nParam == OMX_ALL || nParam == OMX_VIDEODECODER_OUTPUT_PORT) 513 { 514 eError = RPC_UTIL_SetStrideAndPadding(hComponent, pCompPrv); 515 PROXY_require(eError == OMX_ErrorNone, eError, 516 "Stride and padding setting from proxy returned"); 517 } 518 } 519 520 eError = 521 PROXY_SendCommand(hComponent, eCmd, nParam, pCmdData); 522 523 EXIT: 524 DOMX_EXIT("eError: %d", eError); 525 return eError; 526} 527 528/* ===========================================================================*/ 529/** 530 * @name PROXY_EventHandler() 531 * @brief 532 * @param void 533 * @return OMX_ErrorNone = Successful 534 * @sa TBD 535 * 536 */ 537/* ===========================================================================*/ 538OMX_ERRORTYPE PROXY_VIDDEC_EventHandler(OMX_HANDLETYPE hComponent, 539 OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, 540 OMX_PTR pEventData) 541{ 542 OMX_ERRORTYPE eError = OMX_ErrorNone; 543 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 544 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 545 546 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 547 548 PROXY_require((hComp->pComponentPrivate != NULL), 549 OMX_ErrorBadParameter, 550 "This is fatal error, processing cant proceed - please debug"); 551 552 DOMX_ENTER 553 ("hComponent=%p, pCompPrv=%p, eEvent=%p, nData1=%p, nData2=%p, pEventData=%p", 554 hComponent, pCompPrv, eEvent, nData1, nData2, pEventData); 555 556 if((eEvent == OMX_EventCmdComplete) && ((OMX_COMMANDTYPE)nData1 == OMX_CommandStateSet)) 557 { 558 if((OMX_STATETYPE)nData2 == OMX_StateLoaded) 559 { 560 pCompPrv->IsLoadedState = OMX_TRUE; 561 } 562 } 563 eError = PROXY_EventHandler(hComponent, pAppData, eEvent, nData1, nData2, pEventData); 564 565 EXIT: 566 return eError; 567} 568 569/* ===========================================================================*/ 570/** 571 * @name RPC_UTIL_RPC_UTIL_SetStrideAndPadding() 572 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D 573 * @param hRemoteComp [IN] : Remote component handle. 574 * @return OMX_ErrorNone = Successful 575 */ 576/* ===========================================================================*/ 577OMX_ERRORTYPE RPC_UTIL_SetStrideAndPadding(OMX_COMPONENTTYPE * hComponent,PROXY_COMPONENT_PRIVATE * pCompPrv) 578{ 579 OMX_ERRORTYPE eError = OMX_ErrorNone; 580 OMX_PARAM_PORTDEFINITIONTYPE sPortDef; 581 OMX_CONFIG_RECTTYPE tParamStruct; 582 OMX_U32 nPortIndex = 0; 583 584 for(nPortIndex=0; nPortIndex < TOTAL_DEC_PORTS ;nPortIndex++ ) 585 { 586 /*Initializing Structure */ 587 sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 588 sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 589 sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR; 590 sPortDef.nVersion.s.nRevision = 0x0; 591 sPortDef.nVersion.s.nStep = 0x0; 592 sPortDef.nPortIndex = nPortIndex; 593 594 eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition, 595 &sPortDef); 596 PROXY_assert(eError == OMX_ErrorNone, 597 eError," Error in Proxy GetParameter for Port Def"); 598 599 if (sPortDef.eDomain == OMX_PortDomainVideo && sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingUnused) 600 { 601 if(pCompPrv->proxyPortBuffers[nPortIndex].IsBuffer2D == OMX_TRUE) 602 { 603 sPortDef.format.video.nStride = LINUX_PAGE_SIZE; 604 } 605 else 606 { 607 tParamStruct.nSize = sizeof(OMX_CONFIG_RECTTYPE); 608 tParamStruct.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 609 tParamStruct.nVersion.s.nVersionMinor = OMX_VER_MINOR; 610 tParamStruct.nVersion.s.nRevision = 0x0; 611 tParamStruct.nVersion.s.nStep = 0x0; 612 tParamStruct.nPortIndex = nPortIndex; 613 614 eError = PROXY_GetParameter(hComponent,(OMX_INDEXTYPE)OMX_TI_IndexParam2DBufferAllocDimension, 615 &tParamStruct); 616 PROXY_assert(eError == OMX_ErrorNone, 617 eError," Error in Proxy GetParameter for 2D index"); 618 619 sPortDef.format.video.nStride = tParamStruct.nWidth; 620 } 621 eError = PROXY_SetParameter(hComponent,OMX_IndexParamPortDefinition, 622 &sPortDef); 623 PROXY_assert(eError == OMX_ErrorNone, 624 eError," Error in Proxy SetParameter for Port Def"); 625 } 626 } 627 628 EXIT: 629 return eError; 630} 631 632#endif 633 634#ifdef ANDROID_QUIRK_LOCK_BUFFER 635/* ===========================================================================*/ 636/** 637 * @name PROXY_VIDDEC_FillThisBuffer() 638 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D 639 */ 640/* ===========================================================================*/ 641OMX_ERRORTYPE PROXY_VIDDEC_FillThisBuffer(OMX_HANDLETYPE hComponent, OMX_BUFFERHEADERTYPE * pBufferHdr) 642{ 643 OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone; 644 RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone; 645 PROXY_COMPONENT_PRIVATE *pCompPrv; 646 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 647 OMX_U32 count = 0; 648 IMG_native_handle_t* grallocHandle; 649 OMX_PARAM_PORTDEFINITIONTYPE sPortDef; 650 651 PROXY_require(pBufferHdr != NULL, OMX_ErrorBadParameter, NULL); 652 PROXY_require(hComp->pComponentPrivate != NULL, OMX_ErrorBadParameter, 653 NULL); 654 PROXY_CHK_VERSION(pBufferHdr, OMX_BUFFERHEADERTYPE); 655 656 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 657 658 if(pCompPrv->proxyPortBuffers[OMX_VIDEODECODER_OUTPUT_PORT].proxyBufferType 659 == GrallocPointers) 660 { 661 /* Lock the Gralloc buffer till it gets rendered completely */ 662 /* Extract the Gralloc handle from the Header and then call lock on that */ 663 /* Note# There is no error check for the pBufferHdr here*/ 664 grallocHandle = (IMG_native_handle_t*)pBufferHdr->pBuffer; 665 666 /*Initializing Structure */ 667 sPortDef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 668 sPortDef.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 669 sPortDef.nVersion.s.nVersionMinor = OMX_VER_MINOR; 670 sPortDef.nVersion.s.nRevision = 0x0; 671 sPortDef.nVersion.s.nStep = 0x0; 672 sPortDef.nPortIndex = OMX_VIDEODECODER_INPUT_PORT; 673 eError = PROXY_GetParameter(hComponent,OMX_IndexParamPortDefinition, 674 &sPortDef); 675 PROXY_assert(eError == OMX_ErrorNone, 676 eError," Error in Proxy GetParameter for Port Def"); 677 678#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 679 /* Get the Video frame crop window */ 680 OMX_CONFIG_RECTTYPE rect; 681 rect.nSize = sizeof(rect); 682 rect.nVersion.s.nVersionMajor = OMX_VER_MAJOR; 683 rect.nVersion.s.nVersionMinor = OMX_VER_MINOR; 684 rect.nVersion.s.nRevision = 0x0; 685 rect.nVersion.s.nStep = 0x0; 686 rect.nPortIndex = OMX_VIDEODECODER_OUTPUT_PORT; 687 688 eError = PROXY_GetConfig(hComponent, OMX_IndexConfigCommonOutputCrop, &rect); 689 690 PROXY_assert(eError == OMX_ErrorNone, 691 eError," Error while getting output crop"); 692 pCompPrv->debugframeInfo.frame_width = rect.nWidth; 693 pCompPrv->debugframeInfo.frame_height = rect.nHeight; 694 pCompPrv->debugframeInfo.frame_xoffset = rect.nLeft; 695 pCompPrv->debugframeInfo.frame_yoffset = rect.nTop; 696#endif 697 pCompPrv->grallocModule->lock((gralloc_module_t const *) pCompPrv->grallocModule, 698 (buffer_handle_t)grallocHandle, GRALLOC_USAGE_HW_RENDER, 699 0,0,sPortDef.format.video.nFrameWidth, sPortDef.format.video.nFrameHeight,NULL); 700 } 701 702 eRPCError = PROXY_FillThisBuffer(hComponent, pBufferHdr); 703 704 PROXY_assert(eError == OMX_ErrorNone, 705 eError," Error in Proxy SetParameter for Port Def"); 706 707 EXIT: 708 DOMX_EXIT("eError: %d", eError); 709 return eError; 710} 711 712/* ===========================================================================*/ 713/** 714 * @name PROXY_VIDDEC_FillBufferDone() 715 * @brief Gets stride on this port. Used to set stride on OMX to tell whether buffer is 1D or 2D 716 */ 717/* ===========================================================================*/ 718OMX_ERRORTYPE PROXY_VIDDEC_FillBufferDone(OMX_HANDLETYPE hComponent, 719 OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags, 720 OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent, 721 OMX_PTR pMarkData) 722{ 723 OMX_ERRORTYPE eError = OMX_ErrorNone, eCompReturn = OMX_ErrorNone; 724 RPC_OMX_ERRORTYPE eRPCError = RPC_OMX_ErrorNone; 725 PROXY_COMPONENT_PRIVATE *pCompPrv = NULL; 726 OMX_COMPONENTTYPE *hComp = (OMX_COMPONENTTYPE *) hComponent; 727 OMX_U32 count = 0; 728 IMG_native_handle_t* grallocHandle; 729 730 PROXY_require((hComp->pComponentPrivate != NULL), 731 OMX_ErrorBadParameter, 732 "This is fatal error, processing cant proceed - please debug"); 733 734 pCompPrv = (PROXY_COMPONENT_PRIVATE *) hComp->pComponentPrivate; 735 736 /* Lock the Gralloc buffer till it gets rendered completely */ 737 /* Extract the Gralloc handle from the Header and then call lock on that */ 738 /* Note# There is no error check for the pBufferHdr here*/ 739 740 if(pCompPrv->proxyPortBuffers[OMX_VIDEODECODER_OUTPUT_PORT].proxyBufferType 741 == GrallocPointers) { 742 for (count = 0; count < pCompPrv->nTotalBuffers; ++count) 743 { 744 if (pCompPrv->tBufList[count].pBufHeaderRemote == remoteBufHdr) 745 { 746 grallocHandle = (IMG_native_handle_t*)(pCompPrv->tBufList[count].pBufHeader)->pBuffer; 747 break; 748 } 749 } 750 751 PROXY_assert((count != pCompPrv->nTotalBuffers), 752 OMX_ErrorBadParameter, 753 "Received invalid-buffer header from OMX component"); 754 pCompPrv->grallocModule->unlock((gralloc_module_t const *) pCompPrv->grallocModule, (buffer_handle_t)grallocHandle); 755 756#ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY 757 ALOGV("frm[%u] to[%u] run[%u]", pCompPrv->debugframeInfo.fromFrame, pCompPrv->debugframeInfo.toFrame, pCompPrv->debugframeInfo.runningFrame); 758 /* Fill buffer Done successed, hence start dumping if requested */ 759 OMX_BUFFERHEADERTYPE *pBufHdr = pCompPrv->tBufList[count].pBufHeader; 760 if ((pCompPrv->debugframeInfo.fromFrame == 0) && (pCompPrv->debugframeInfo.runningFrame <= pCompPrv->debugframeInfo.toFrame)) 761 { 762 /* Lock the buffer for SW read usage and then access it */ 763 pCompPrv->grallocModule->lock((gralloc_module_t const*) pCompPrv->grallocModule, 764 (buffer_handle_t)grallocHandle, 765 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_SW_READ_RARELY, 766 pCompPrv->debugframeInfo.frame_xoffset, 767 pCompPrv->debugframeInfo.frame_yoffset, 768 pCompPrv->debugframeInfo.frame_width, 769 pCompPrv->debugframeInfo.frame_height, 770 (void*)pCompPrv->debugframeInfo.y_uv); 771 772 DumpVideoFrame(&pCompPrv->debugframeInfo); 773 774 pCompPrv->grallocModule->unlock((gralloc_module_t const *) pCompPrv->grallocModule, 775 (buffer_handle_t)grallocHandle); 776 pCompPrv->debugframeInfo.runningFrame++; 777 } 778 else if (pCompPrv->debugframeInfo.fromFrame > 0) 779 { 780 pCompPrv->debugframeInfo.fromFrame--; 781 } 782#endif 783 } 784 785 eRPCError = PROXY_FillBufferDone(hComponent,remoteBufHdr, nfilledLen, nOffset, nFlags, 786 nTimeStamp, hMarkTargetComponent, pMarkData); 787 788 PROXY_assert(eError == OMX_ErrorNone, 789 eError," Error in PROXY FillBufferDone for Port Def"); 790 791EXIT: 792 DOMX_EXIT("eError: %d", eError); 793 return eError; 794} 795 796#endif 797 798