1 2/* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21#ifndef OMX_VPP_UTILS__H 22#define OMX_VPP_UTILS__H 23 24#include <OMX_Component.h> 25#include "LCML_DspCodec.h" 26#ifdef RESOURCE_MANAGER_ENABLED 27#include <ResourceManagerProxyAPI.h> 28#endif 29#include <OMX_TI_Common.h> 30 31#ifdef __PERF_INSTRUMENTATION__ 32#include "perf.h" 33#endif 34 35#define KHRONOS_1_2 36 37/*Linked List */ 38 39typedef struct Node { 40 struct Node *pNextNode; 41 void *pValue; 42} Node; 43 44typedef struct LinkedList { 45 Node *pRoot; 46} LinkedList; 47 48LinkedList AllocList; 49 50void LinkedList_Create(LinkedList *LinkedList); 51void LinkedList_AddElement(LinkedList *LinkedList, void *pValue); 52void LinkedList_FreeElement(LinkedList *LinkedList, void *pValue); 53void LinkedList_FreeAll(LinkedList *LinkedList); 54void LinkedList_DisplayAll(LinkedList *LinkedList); 55void LinkedList_Destroy(LinkedList *LinkedList); 56 57/* 58 * M A C R O S 59 */ 60/* configuration numbers */ 61 62/*difine for Khronos 1.1*/ 63#define KHRONOS_1_1 64 65/*#define VPP_DEBUG*/ 66 67#define VPP_MAJOR_VER 0x01 68/*#ifdef KHRONOS_1_1 69#define VPP_MINOR_VER 0x01 70#else*/ 71#define VPP_MINOR_VER 0x00 72/*#endif*/ 73#define VPP_REVISION 0x00 74#define VPP_STEP 0x00 75 76#define NORMAL_BUFFER 0 77#define OMX_NOPORT 0xFFFFFFFE 78#define NUM_OF_PORTS 4 79 80#define NUM_OF_VPP_BUFFERS (4) 81#define MAX_VPP_BUFFERS (4) 82#define NUM_OF_VPP_PORTS (4) 83#define MIN_NUM_OF_VPP_BUFFERS 1 84 85#define DEFAULT_WIDTH (176) 86#define DEFAULT_HEIGHT (144) 87 88#define VPP_ZERO 0 89#define VPP_DSPSTOP 0x01 90#define VPP_BUFFERBACK 0x02 91#define VPP_IDLEREADY ( VPP_DSPSTOP | VPP_BUFFERBACK ) 92 93#define DSP_MMU_FAULT_HANDLING 94 95#ifdef UNDER_CE 96#define USN_DLL_NAME "/windows/usn.dll64P" 97#define VPP_NODE_DLL "/windows/vpp_sn.dll64P" 98#else 99#define USN_DLL_NAME "usn.dll64P" 100#define VPP_NODE_DLL "vpp_sn.dll64P" 101#endif 102 103#ifdef UNDER_CE 104 #include <oaf_debug.h> /* defines VPP_DPRINT*/ 105#else 106 #ifdef VPP_DEBUG 107 #define VPP_DPRINT(...) fprintf(stderr,__VA_ARGS__) 108 #else 109 #define VPP_DPRINT(...) 110 #endif 111#endif 112 113#define OMX_INIT_STRUCT(_s_, _name_) \ 114{ \ 115 memset((_s_), 0x0, sizeof(_name_)); \ 116 (_s_)->nSize = sizeof(_name_); \ 117 (_s_)->nVersion.s.nVersionMajor = VPP_MAJOR_VER; \ 118 (_s_)->nVersion.s.nVersionMinor = VPP_MINOR_VER; \ 119 (_s_)->nVersion.s.nRevision = VPP_REVISION; \ 120 (_s_)->nVersion.s.nStep = VPP_STEP; \ 121} 122 123#define OMX_CHECK_CMD(_ptr1, _ptr2, _ptr3) \ 124{ \ 125 if(!_ptr1 || !_ptr2 || !_ptr3){ \ 126 eError = OMX_ErrorBadParameter; \ 127 goto EXIT; \ 128 } \ 129} 130 131#define OMX_SET_ERROR_BAIL(_eError, _eCode)\ 132{ \ 133 _eError = _eCode; \ 134 goto EXIT; \ 135} 136 137#define OMX_MALLOC(_pStruct_, _size_) \ 138 _pStruct_ = malloc(_size_); \ 139 if(_pStruct_ == NULL){ \ 140 eError = OMX_ErrorInsufficientResources; \ 141 goto EXIT; \ 142 } \ 143 memset(_pStruct_, 0, _size_);\ 144 LinkedList_AddElement(&AllocList, _pStruct_); 145 146#define OMX_FREE(_ptr) \ 147{ \ 148 if (_ptr != NULL) { \ 149 LinkedList_FreeElement(&AllocList, _ptr);\ 150 _ptr = NULL; \ 151 } \ 152} 153 154#define OMX_FREEALL() \ 155{ \ 156 LinkedList_FreeAll(&AllocList);\ 157} 158 159 160/********************************************************************** 161 * GPP Internal data type 162 ********************************************************************** 163 */ 164 165typedef enum OMX_VPP_PORT_NUMBER_TYPE { 166 OMX_VPP_INPUT_PORT = 0, 167 OMX_VPP_INPUT_OVERLAY_PORT = 1, 168 OMX_VPP_RGB_OUTPUT_PORT = 2, 169 OMX_VPP_YUV_OUTPUT_PORT = 3, 170 OMX_VPP_MAXPORT_NUM = 3 171} OMX_VPP_PORT_NUMBER_TYPE; 172 173typedef enum { 174 IUALG_CMD_SETCOEFF = 100, 175 IUALG_CMD_SETIO 176}IUALG_VppCmd; 177 178typedef enum VPP_BUFFER_OWNER 179{ 180 VPP_BUFFER_CLIENT = 0x0, 181 VPP_BUFFER_COMPONENT_IN, 182 VPP_BUFFER_COMPONENT_OUT, 183 VPP_BUFFER_DSP, 184 VPP_BUFFER_TUNNEL_COMPONENT 185} VPP_BUFFER_OWNER; 186typedef enum OMX_INDEXVPPTYPE 187{ 188#ifdef KHRONOS_1_2 189 OMX_IndexCustomSetZoomFactor = (OMX_IndexVendorStartUnused + 1), 190#else 191 OMX_IndexCustomSetZoomFactor = (OMX_IndexIndexVendorStartUnused + 1), 192#endif 193 OMX_IndexCustomSetZoomLimit, 194 OMX_IndexCustomSetZoomSpeed, 195 OMX_IndexCustomSetZoomXoffsetFromCenter16, 196 OMX_IndexCustomSetZoomYoffsetFromCenter16, 197 OMX_IndexCustomSetFrostedGlassOvly, 198 OMX_IndexCustomVideoColorRange, 199 OMX_IndexCustomRGB4ColorFormat, 200 OMX_IndexCustomConfigInputSize 201} OMX_INDEXVPPTYPE; 202 203 204typedef enum VGPOP_IORange { 205 VGPOP_IN_16_235_OUT_16_235, /*limited range to limited range*/ 206 VGPOP_IN_00_255_OUT_00_255, /*full range to full range*/ 207 VGPOP_IN_00_255_OUT_16_235, /*full range to limited range*/ 208 VGPOP_IN_16_235_OUT_00_255 /*limited range to full range*/ 209} VGPOP_IORange; 210 211 212 /* Parameter buffer which needs to be passed to DSP */ 213 214typedef struct GPPToVPPInputFrameStatus { 215 216 /* INPUT FRAME */ 217 218 /* input size*/ 219 OMX_U32 ulInWidth; /* picture buffer width */ 220 OMX_U32 ulInHeight; /* picture buffer height */ 221 OMX_U32 ulCInOffset; /* offset of the C frame in the * 222 * buffer (equal to zero if there * 223 * is no C frame) */ 224 225 /* PROCESSING PARAMETERS */ 226 227 /* crop */ 228 OMX_U32 ulInXstart; /* Hin active start */ 229 OMX_U32 ulInXsize; /* Hin active width */ 230 OMX_U32 ulInYstart; /* Vin active start */ 231 OMX_U32 ulInYsize; /* Vin active height */ 232 233 /* zoom */ 234 OMX_U32 ulZoomFactor; /*zooming ratio (/1024) */ 235 OMX_U32 ulZoomLimit; /* zooming ratio limit (/1024) */ 236 OMX_U32 ulZoomSpeed; /* speed of ratio change */ 237 238 /* stabilisation */ 239 OMX_U32 ulXoffsetFromCenter16; /* add 1/16/th accuracy offset */ 240 OMX_U32 ulYoffsetFromCenter16; /* add 1/16/th accuracy offset */ 241 242 /* gain and contrast */ 243 OMX_U32 ulContrastType; /* Contrast method */ 244 OMX_U32 ulVideoGain; /* gain on video (Y and C) */ 245 246 /* effect */ 247 OMX_U32 ulFrostedGlassOvly; /* Frosted glass effect overlay */ 248 OMX_U32 ulLightChroma; /* Light chrominance process */ 249 OMX_U32 ulLockedRatio; /* keep H/V ratio */ 250 OMX_U32 ulMirror; /* to mirror the picture */ 251 OMX_U32 ulRGBRotation; /* 0, 90, 180, 270 deg. */ 252 OMX_U32 ulYUVRotation; /* 0, 90, 180, 270 deg. */ 253 254#ifndef _55_ 255 OMX_U32 eIORange; /* Video Color Range Conversion */ 256 OMX_U32 ulDithering; /* dithering */ 257 OMX_U32 ulOutPitch; /* output pitch (in bytes)*/ 258 OMX_U32 ulAlphaRGB; /* Global A value of an ARGB output*/ 259#endif 260 261}GPPToVPPInputFrameStatus; 262 263 264/* OUTPPUT BUFFER */ 265 266typedef struct GPPToVPPOutputFrameStatus { 267 268 OMX_U32 ulOutWidth; /* RGB/YUV picture buffer width */ 269 OMX_U32 ulOutHeight; /* RGB/YUV picture buffer height */ 270 OMX_U32 ulCOutOffset; /* Offset of the C frame in the buffer (equal to 0 if there is no C frame) */ 271 272}GPPToVPPOutputFrameStatus; 273 274/* ALG CONTROL*/ 275 276typedef struct VPPIOConf { 277 278 /* Optionnal input */ 279 OMX_U32 overlayInputImage; 280 /* Optionnal output */ 281 OMX_U32 RGBOutputImage; 282 OMX_U32 YUVOutputImage; 283 284} VPPIOConf; 285 286/* UUID structure for DSP/BIOS Bridge nodes. COMMON_TI_UUID*/ 287static const struct DSP_UUID COMMON_TI_UUID = { 288 0x79A3C8B3, 0x95F2, 0x403F, 0x9A, 0x4B, { 289 0xCF, 0x80, 0x57, 0x73, 0x05, 0x41 290 } 291}; 292 293 294 295/*===================================================================*/ 296/** 297 * OMX_VPP_PORT_NUMBER_TYPE enumeration for ports supported by 298 * this component. 299 */ 300/*===================================================================*/ 301typedef struct VPP_OVERLAY { 302 OMX_U8 *iRBuff ; 303 OMX_U8 *iGBuff; 304 OMX_U8 *iBBuff ; 305 OMX_U8 *iOvlyConvBufPtr ; 306 OMX_U8 iRKey; 307 OMX_U8 iGKey; 308 OMX_U8 iBKey; 309 OMX_U8 iAlign ; 310}VPP_OVERLAY; 311 312/* Component buffer */ 313typedef struct OMX_VPP_COMPONENT_BUFFER { 314 OMX_BUFFERHEADERTYPE *pBufHeader; 315 OMX_U32 nIndex; 316 OMX_BOOL bSelfAllocated; 317 OMX_BOOL bHolding; 318 VPP_BUFFER_OWNER eBufferOwner; 319 OMX_U8 *pBufferStart; 320} OMX_VPP_COMPONENT_BUFFER; 321 322typedef struct VPP_BUFFERDATA_PROPAGATION { 323 OMX_U32 flag; 324 OMX_U32 buffer_idYUV; 325 OMX_U32 buffer_idRGB; 326 OMX_HANDLETYPE hMarkTargetComponent; 327 OMX_PTR pMarkData; 328 OMX_U32 nTickCount; 329 OMX_TICKS nTimeStamp; 330} VPP_BUFFERDATA_PROPAGATION; 331 332/* Component Port Context */ 333typedef struct VPP_PORT_TYPE 334{ 335 OMX_HANDLETYPE hTunnelComponent; 336 OMX_U32 nTunnelPort; 337 OMX_BUFFERSUPPLIERTYPE eSupplierSetting; 338 OMX_BUFFERSUPPLIERTYPE eSupplierPreference; 339 OMX_U32 nPortIndex; 340 OMX_U32 nBufferCount; 341 OMX_VPP_COMPONENT_BUFFER pVPPBufHeader[NUM_OF_VPP_BUFFERS]; 342 VPP_BUFFERDATA_PROPAGATION sBufferDataProp[NUM_OF_VPP_BUFFERS]; 343 OMX_PARAM_PORTDEFINITIONTYPE pPortDef; 344 OMX_BOOL nBufSupplier; 345 OMX_U32 nReturnedBufferCount; /*For tunneling*/ 346 OMX_MIRRORTYPE eMirror; 347} VPP_PORT_TYPE; 348 349typedef struct VPP_COMPONENT_PRIVATE 350{ 351 /** Array of pointers to BUFFERHEADERTYPE structues 352 This pBufHeader[INPUT_PORT] will point to all the 353 BUFFERHEADERTYPE structures related to input port, 354 not just one structure. Same is for output port 355 also. */ 356 357 358 VPP_PORT_TYPE sCompPorts[NUM_OF_VPP_PORTS]; 359 360 OMX_CALLBACKTYPE cbInfo; 361 /** Handle for use with async callbacks */ 362 363 /** This will contain info like how many buffers 364 are there for input/output ports, their size etc, but not 365 BUFFERHEADERTYPE POINTERS. */ 366 367 OMX_PORT_PARAM_TYPE *pPortParamTypeImage; 368 OMX_PORT_PARAM_TYPE *pPortParamTypeAudio; 369 OMX_PORT_PARAM_TYPE *pPortParamTypeVideo; 370 OMX_PORT_PARAM_TYPE *pPortParamTypeOthers; 371 372 OMX_VIDEO_PARAM_PORTFORMATTYPE *pInPortFormat; 373 OMX_VIDEO_PARAM_PORTFORMATTYPE *pInPortOverlayFormat; 374 OMX_VIDEO_PARAM_PORTFORMATTYPE *pOutPortRGBFormat; 375 OMX_VIDEO_PARAM_PORTFORMATTYPE *pOutPortYUVFormat; 376 OMX_PRIORITYMGMTTYPE *pPriorityMgmt; 377 378 /** This is component handle */ 379 OMX_COMPONENTTYPE *pHandle; 380 381 /** Current state of this component */ 382 OMX_STATETYPE curState; 383 384 /** The state to go **/ 385 OMX_STATETYPE toState; 386 387 OMX_STRING cComponentName; 388 OMX_VERSIONTYPE ComponentVersion; 389 OMX_VERSIONTYPE SpecVersion; 390 391 /** The component thread handle */ 392 pthread_t ComponentThread; 393 LCML_DSP_INTERFACE* pLCML; 394 void * pDllHandle; 395 396 /** The pipes for sending commands to the thread */ 397 int cmdPipe[2]; 398 int nCmdDataPipe[2]; 399 /** The pipes for sending buffers to the thread */ 400 401 /*The Pipe to send empty output buffers to component*/ 402 int nFree_oPipe[2]; 403 /*The pipe for sending Filled Input buffers to component*/ 404 int nFilled_iPipe[2]; 405 406 /** Set to indicate component is stopping */ 407 OMX_U32 bIsStopping; 408 409 OMX_U32 bIsEOFSent; 410 OMX_U32 lcml_compID; 411 OMX_U32 NumofOutputPort; 412 OMX_U32 IsYUVdataout; 413 OMX_U32 IsRGBdataout; 414 OMX_U32 IsOverlay; 415 OMX_CONFIG_RECTTYPE *pCrop; 416 OMX_U8 ExeToIdleFlag; /* StateCheck */ 417 OMX_HANDLETYPE pLcmlHandle; 418 VPP_OVERLAY *overlay; 419 OMX_U8 *RGBbuffer ; 420 OMX_U8 *colorKey; 421 422#ifdef __PERF_INSTRUMENTATION__ 423 PERF_OBJHANDLE pPERF, pPERFcomp; 424#endif 425 426 OMX_U32 lcml_nCntIp; 427 OMX_U32 lcml_nCntOpReceived; 428 OMX_U32 nInputFrame; /*Buffer data propagation*/ 429 OMX_U32 nOverlayFrame; /*Buffer data propagation*/ 430 OMX_U32 nInYUVBufferCount; /*Buffer data propagation*/ 431 OMX_U32 nInRGBBufferCount; /*Buffer data propagation*/ 432 OMX_U32 nOutYUVBufferCount; /*Buffer data propagation*/ 433 OMX_U32 nOutRGBBufferCount; /*Buffer data propagation*/ 434 OMX_PTR pMarkData; /*Buffer data propagation*/ 435 OMX_HANDLETYPE hMarkTargetComponent; /*Buffer data propagation*/ 436 VPPIOConf *tVPPIOConf; 437 GPPToVPPInputFrameStatus *pIpFrameStatus; 438 GPPToVPPOutputFrameStatus *pOpYUVFrameStatus; 439 GPPToVPPOutputFrameStatus *pOpRGBFrameStatus; 440 OMX_CONFIG_SCALEFACTORTYPE sScale; 441 OMX_U8 CodecAlgCtrlAck; 442 OMX_BOOL bFlushComplete; 443 OMX_U32 nFlushPort; 444 OMX_BOOL bDisable; 445 OMX_BOOL bDisableIncomplete[NUM_OF_VPP_PORTS]; 446#ifdef RESOURCE_MANAGER_ENABLED 447 RMPROXY_CALLBACKTYPE rmproxyCallback; 448#endif 449 OMX_BOOL bPreempted; 450 451 452 pthread_mutex_t buf_mutex; 453 pthread_mutex_t vpp_mutex; 454 pthread_cond_t stop_cond; 455 456#ifdef KHRONOS_1_1 457 OMX_PARAM_COMPONENTROLETYPE componentRole; 458#endif 459} VPP_COMPONENT_PRIVATE; 460 461/* structures for custom commands */ 462typedef struct _VPP_CUSTOM_PARAM_DEFINITION 463{ 464 OMX_U8 cCustomParamName[128]; 465 OMX_INDEXTYPE nCustomParamIndex; 466} VPP_CUSTOM_PARAM_DEFINITION; 467 468/* Function ProtoType */ 469 470OMX_ERRORTYPE VPP_Fill_LCMLInitParams(OMX_HANDLETYPE pHandle, OMX_U16 arr[], LCML_DSP *plcml_Init); 471 472OMX_ERRORTYPE VPP_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir, OMX_U32 Index); 473 474OMX_ERRORTYPE VPP_LCML_Callback (TUsnCodecEvent event,void * args [10]); 475 476OMX_ERRORTYPE VPP_HandleCommand (VPP_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1); 477 478OMX_ERRORTYPE VPP_HandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE *pBufHeader, VPP_COMPONENT_PRIVATE *pComponentPrivate); 479 480 481OMX_ERRORTYPE VPP_IsValidBuffer(OMX_BUFFERHEADERTYPE *pBufHeader, 482 VPP_COMPONENT_PRIVATE *pComponentPrivate, 483 OMX_U32 pIndex, 484 OMX_U32 *pCount); 485 486 487OMX_ERRORTYPE VPP_GetPortDefFromBufHeader(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_PARAM_PORTDEFINITIONTYPE **portDef ); 488 489OMX_ERRORTYPE VPP_HandleDataBuf_FromLCML(VPP_COMPONENT_PRIVATE* pComponentPrivate); 490 491OMX_HANDLETYPE VPP_GetLCMLHandle(VPP_COMPONENT_PRIVATE *pComponentPrivate); 492 493OMX_ERRORTYPE VPP_GetCorresponding_LCMLHeader(VPP_COMPONENT_PRIVATE *pComponentPrivate, 494 OMX_U8 *pBuffer, 495 OMX_DIRTYPE eDir, 496 OMX_VPP_COMPONENT_BUFFER **ppCmpBuf, 497 OMX_U32 Index); 498 499OMX_ERRORTYPE VPP_Free_ComponentResources(OMX_HANDLETYPE pComponent); 500 501OMX_ERRORTYPE ComputeTiOverlayImgFormat (VPP_COMPONENT_PRIVATE *pComponentPrivate, 502 OMX_U8* aPictureArray, 503 OMX_U8* aOutImagePtr, 504 OMX_U8* aTransparencyKey); 505 506OMX_ERRORTYPE VPP_Start_ComponentThread(OMX_HANDLETYPE pHandle); 507 508OMX_ERRORTYPE VPP_Stop_ComponentThread(OMX_HANDLETYPE pHandle); 509 510OMX_ERRORTYPE VPP_DisablePort (VPP_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1); 511 512OMX_ERRORTYPE VPP_EnablePort (VPP_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1); 513 514OMX_ERRORTYPE VPP_HandleCommandFlush (VPP_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1, OMX_BOOL return_event); 515 516OMX_ERRORTYPE VPP_Process_FilledInBuf(VPP_COMPONENT_PRIVATE* pComponentPrivate); 517 518OMX_ERRORTYPE VPP_Process_FilledOutBuf(VPP_COMPONENT_PRIVATE* pComponentPrivate, 519 OMX_VPP_COMPONENT_BUFFER *pComponentBuf); 520 521OMX_ERRORTYPE VPP_Process_FreeInBuf(VPP_COMPONENT_PRIVATE* pComponentPrivate, 522 OMX_VPP_COMPONENT_BUFFER *pComponentBuf); 523 524OMX_ERRORTYPE VPP_Process_FreeOutBuf(VPP_COMPONENT_PRIVATE* pComponentPrivate); 525 526OMX_ERRORTYPE VPP_Initialize_PrivateStruct(VPP_COMPONENT_PRIVATE *pComponentPrivate); 527 528OMX_BOOL IsTIOMXComponent(OMX_HANDLETYPE hComp); 529 530void VPP_InitBufferDataPropagation(VPP_COMPONENT_PRIVATE * pComponentPrivate, OMX_U32 nPortIndex); 531 532#endif 533