Home | History | Annotate | Download | only in domx
      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_common.h
     35  *         This file contains methods that provides the functionality for
     36  *         the OpenMAX1.1 DOMX Framework OMX Common Proxy.
     37  *
     38  *  @path \WTSD_DucatiMMSW\framework\domx\omx_proxy_common\
     39  *
     40  *  @rev 1.0
     41  */
     42 
     43 /*==============================================================
     44  *! Revision History
     45  *! ============================
     46  *! 29-Mar-2010 Abhishek Ranka : Revamped DOMX implementation
     47  *!
     48  *! 19-August-2009 B Ravi Kiran ravi.kiran (at) ti.com: Initial Version
     49  *================================================================*/
     50 
     51 #ifdef ANDROID_QUIRK_LOCK_BUFFER
     52 #include <hardware/gralloc.h>
     53 #endif
     54 
     55 #ifndef OMX_PROXY_H
     56 #define OMX_PROXY_H
     57 
     58 #ifdef __cplusplus
     59 extern "C"
     60 {
     61 #endif				/* __cplusplus */
     62 
     63 /* ------compilation control switches ----------------------------------------*/
     64 
     65 /******************************************************************
     66  *   INCLUDE FILES
     67  ******************************************************************/
     68 /* ----- system and platform files ----------------------------*/
     69 #include <OMX_Core.h>
     70 /*-------program files ----------------------------------------*/
     71 #include "omx_rpc.h"
     72 #include "omx_rpc_internal.h"
     73 #include "omx_rpc_utils.h"
     74 
     75 /****************************************************************
     76  * PUBLIC DECLARATIONS Defined here, used elsewhere
     77  ****************************************************************/
     78 /*--------data declarations -----------------------------------*/
     79 /*OMX versions supported by DOMX*/
     80 #define OMX_VER_MAJOR 0x1
     81 #define OMX_VER_MINOR 0x1
     82 
     83 #define MAX_NUM_PROXY_BUFFERS             100
     84 #define MAX_COMPONENT_NAME_LENGTH         128
     85 #define PROXY_MAXNUMOFPORTS               8
     86 
     87 /******************************************************************
     88  *   MACROS - ASSERTS
     89  ******************************************************************/
     90 #define PROXY_assert  PROXY_paramCheck
     91 #define PROXY_require PROXY_paramCheck
     92 #define PROXY_ensure  PROXY_paramCheck
     93 
     94 #define PROXY_paramCheck(C, V, S) do {\
     95     if (!(C)) { eError = V;\
     96     if(S) DOMX_ERROR("failed check:" #C" - returning error: 0x%x - %s",V,S);\
     97     else DOMX_ERROR("failed check:" #C" - returning error: 0x%x",V); \
     98     goto EXIT; }\
     99     } while(0)
    100 
    101 #define PROXY_CHK_VERSION(_pStruct_, _sName_) do { \
    102     PROXY_require((((_sName_ *)_pStruct_)->nSize == sizeof(_sName_)), \
    103                   OMX_ErrorBadParameter, "Incorrect nSize"); \
    104     PROXY_require(((((_sName_ *)_pStruct_)->nVersion.s.nVersionMajor == \
    105                   OMX_VER_MAJOR) && \
    106                   ((((_sName_ *)_pStruct_)->nVersion.s.nVersionMinor == \
    107                   OMX_VER_MINOR) || \
    108                   (((_sName_ *)_pStruct_)->nVersion.s.nVersionMinor == \
    109                   0))), \
    110                   OMX_ErrorVersionMismatch, NULL); \
    111     } while(0)
    112 
    113 #define PROXY_checkRpcError() do { \
    114     if (eRPCError == RPC_OMX_ErrorNone) \
    115     { \
    116         DOMX_DEBUG("Corresponding RPC function executed successfully"); \
    117         eError = eCompReturn; \
    118         PROXY_assert((eError == OMX_ErrorNone) || (eError == OMX_ErrorNoMore), eError, "Error returned from OMX API in ducati"); \
    119     } else \
    120     { \
    121         DOMX_ERROR("RPC function returned error 0x%x", eRPCError); \
    122         switch (eRPCError) \
    123         { \
    124             case RPC_OMX_ErrorHardware: \
    125                 eError = OMX_ErrorHardware; \
    126             break; \
    127             case RPC_OMX_ErrorInsufficientResources: \
    128                 eError = OMX_ErrorInsufficientResources; \
    129             break; \
    130             case RPC_OMX_ErrorBadParameter: \
    131                 eError = OMX_ErrorBadParameter; \
    132             break; \
    133             case RPC_OMX_ErrorUnsupportedIndex: \
    134                 eError = OMX_ErrorUnsupportedIndex; \
    135             break; \
    136             case RPC_OMX_ErrorTimeout: \
    137                 eError = OMX_ErrorTimeout; \
    138             break; \
    139             default: \
    140                 eError = OMX_ErrorUndefined; \
    141         } \
    142         PROXY_assert((eError == OMX_ErrorNone), eError, "Error returned from OMX API in ducati"); \
    143     } \
    144 } while(0)
    145 
    146 	typedef OMX_ERRORTYPE(*PROXY_EMPTYBUFFER_DONE) (OMX_HANDLETYPE
    147 	    hComponent, OMX_U32 remoteBufHdr, OMX_U32 nfilledLen,
    148 	    OMX_U32 nOffset, OMX_U32 nFlags);
    149 
    150 	typedef OMX_ERRORTYPE(*PROXY_FILLBUFFER_DONE) (OMX_HANDLETYPE
    151 	    hComponent, OMX_U32 remoteBufHdr, OMX_U32 nfilledLen,
    152 	    OMX_U32 nOffset, OMX_U32 nFlags, OMX_TICKS nTimeStamp,
    153 	    OMX_HANDLETYPE hMarkTargetComponent, OMX_PTR pMarkData);
    154 
    155 	typedef OMX_ERRORTYPE(*PROXY_EVENTHANDLER) (OMX_HANDLETYPE hComponent,
    156 	    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1,
    157 	    OMX_U32 nData2, OMX_PTR pEventData);
    158 
    159 /*******************************************************************************
    160 * Structures
    161 *******************************************************************************/
    162 /*===============================================================*/
    163 /** PROXY_BUFFER_INFO        : This structure maintains a table of A9 and
    164  *                             Ducati side buffers and headers.
    165  *
    166  * @param pBufHeader         : This is a pointer to the A9 bufferheader.
    167  *
    168  * @param pBufHeaderRemote   : This is pointer to Ducati side bufferheader.
    169  *
    170  * @param pRegisteredAufBux0
    171  * @param pRegisteredAufBux1
    172  * @param pRegisteredAufBux2 : These are pointers to buffers registered with rpc driver
    173  *                             They will assigned when registering and used when
    174  *                             unregistering the buffer
    175  */
    176 /*===============================================================*/
    177 	typedef struct PROXY_BUFFER_INFO
    178 	{
    179 		OMX_BUFFERHEADERTYPE *pBufHeader;
    180 		OMX_U32 pBufHeaderRemote;
    181 		OMX_PTR pYBuffer;
    182 		OMX_PTR pMetaDataBuffer;
    183 #ifdef USE_ION
    184 		int mmap_fd;
    185 		int mmap_fd_metadata_buff;
    186 		OMX_PTR pRegisteredAufBux0;
    187 		OMX_PTR pRegisteredAufBux1;
    188 		OMX_PTR pRegisteredAufBux2;
    189 #endif
    190 	} PROXY_BUFFER_INFO;
    191 
    192 /*===============================================================*/
    193 /** PROXY_BUFFER_TYPE        : This enumeration tells the type of buffer pointers coming to OMX in
    194 				UseBuffer call.
    195  */
    196 /*===============================================================*/
    197 	typedef enum PROXY_BUFFER_TYPE
    198 	{
    199 		VirtualPointers,   /*Used when buffer pointers come from the normal A9 virtual space */
    200 		GrallocPointers,   /*Used when buffer pointers come from Gralloc allocations */
    201 		IONPointers,       /*Used when buffer pointers come from ION allocations */
    202 		EncoderMetadataPointers,		/*Used when buffer pointers come from Stagefright in camcorder usecase */
    203 		BufferDescriptorVirtual2D          /*Virtual unpacked buffers passed via OMX_TI_BUFFERDESCRIPTOR_TYPE */
    204 	} PROXY_BUFFER_TYPE;
    205 
    206 /*===============================================================*/
    207 /** PROXY_BUFFER_TYPE        : This enumeration tells the type of buffer pointers coming to OMX in
    208                                UseBuffer call.
    209  */
    210 /*===============================================================*/
    211 	typedef struct PROXY_PORT_TYPE
    212 	{
    213 		PROXY_BUFFER_TYPE proxyBufferType;   /*Used when buffer pointers come from the normal A9 virtual space */
    214 		OMX_U32 IsBuffer2D;   /*Used when buffer pointers come from Gralloc allocations */
    215 	} PROXY_PORT_TYPE;
    216 
    217 #ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY
    218 /*===============================================================*/
    219 /** DebugFrame_Dump     : Structure holding the info about frames to dump
    220  *  @param fromFrame: From which frame to start dumping
    221  *  @param toFrame:  till which frame to dump
    222  *  @param frame_width: Width of the frame
    223  *  @param frame_height: Height of the frame
    224  *  @param padded_width: Width of the buffer
    225  *  @param padded_height: Height of the buffer
    226  *  @param stride: Stride of the Buffer
    227  *  @param runningFrame: running counter to track the frames
    228  */
    229 /*===============================================================*/
    230 	typedef struct DebugFrame_Dump
    231 	{
    232 		OMX_S32 fromFrame;
    233 		OMX_S32 toFrame;
    234 		OMX_U32 frame_width;
    235 		OMX_U32 frame_height;
    236 		OMX_U32 frame_xoffset;
    237 		OMX_U32	frame_yoffset;
    238 		OMX_U32 stride;
    239 		OMX_S32 runningFrame;
    240 		OMX_U32 *y_uv[2];
    241 	}DebugFrame_Dump;
    242 #endif
    243 
    244 /* ========================================================================== */
    245 /**
    246 * PROXY_COMPONENT_PRIVATE
    247 *
    248 */
    249 /* ========================================================================== */
    250 	typedef struct PROXY_COMPONENT_PRIVATE
    251 	{
    252 		/* OMX Related Information */
    253 		OMX_CALLBACKTYPE tCBFunc;
    254 		OMX_PTR pILAppData;
    255 		OMX_HANDLETYPE hRemoteComp;
    256 
    257 		PROXY_BUFFER_INFO tBufList[MAX_NUM_PROXY_BUFFERS];
    258 		PROXY_PORT_TYPE proxyPortBuffers[PROXY_MAXNUMOFPORTS];
    259 		OMX_BOOL IsLoadedState;
    260 		OMX_U32 nTotalBuffers;
    261 		OMX_U32 nAllocatedBuffers;
    262 
    263 		/* PROXY specific data - PROXY PRIVATE DATA */
    264 		OMX_PTR pCompProxyPrv;
    265 		char *cCompName;
    266 
    267 		PROXY_EMPTYBUFFER_DONE proxyEmptyBufferDone;
    268 		PROXY_FILLBUFFER_DONE proxyFillBufferDone;
    269 		PROXY_EVENTHANDLER proxyEventHandler;
    270 
    271 #ifdef ANDROID_QUIRK_LOCK_BUFFER
    272 		gralloc_module_t const *grallocModule;
    273 #endif
    274 #ifdef USE_ION
    275 		int ion_fd;
    276 		OMX_BOOL bUseIon;
    277 		OMX_BOOL bMapIonBuffers;
    278 #endif
    279 #ifdef ENABLE_RAW_BUFFERS_DUMP_UTILITY
    280 		DebugFrame_Dump debugframeInfo;
    281 #endif
    282 		int secure_misc_drv_fd;
    283 	} PROXY_COMPONENT_PRIVATE;
    284 
    285 
    286 
    287 /*===============================================================*/
    288 /** PROXY_MARK_DATA        : A pointer to this structure is sent as mark data to
    289  *                           the remote core when a MarkBuffer command is made.
    290  *
    291  * @param hComponentActual : This is the actual handle of the component to be
    292  *                           marked. When marked buffers come from the remote
    293  *                           to the local core then remote handle of the mark
    294  *                           component is replaced by this in the header.
    295  *
    296  * @param pMarkdataActual : This is the mark data set by the client.
    297  */
    298 /*===============================================================*/
    299 	typedef struct PROXY_MARK_DATA
    300 	{
    301 		OMX_HANDLETYPE hComponentActual;
    302 		OMX_PTR pMarkDataActual;
    303 	} PROXY_MARK_DATA;
    304 /*******************************************************************************
    305 * Functions
    306 *******************************************************************************/
    307 	OMX_ERRORTYPE OMX_ProxyCommonInit(OMX_HANDLETYPE hComponent);
    308 	OMX_ERRORTYPE PROXY_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
    309 	    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
    310 	OMX_ERRORTYPE PROXY_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
    311 	    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
    312 	OMX_ERRORTYPE PROXY_EventHandler(OMX_HANDLETYPE hComponent,
    313 	    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
    314 	    OMX_PTR pEventData);
    315 	OMX_ERRORTYPE PROXY_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,
    316 	    OMX_IN OMX_COMMANDTYPE eCmd,
    317 	    OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData);
    318 	OMX_ERRORTYPE PROXY_EmptyThisBuffer(OMX_HANDLETYPE hComponent,
    319 	    OMX_BUFFERHEADERTYPE * pBufferHdr);
    320 	OMX_ERRORTYPE PROXY_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
    321 	    OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType);
    322 	OMX_ERRORTYPE PROXY_FillBufferDone(OMX_HANDLETYPE hComponent,
    323 	OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags,
    324 	    OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent,
    325 	    OMX_PTR pMarkData);
    326 	OMX_ERRORTYPE PROXY_FillThisBuffer(OMX_HANDLETYPE hComponent,
    327 	    OMX_BUFFERHEADERTYPE * pBufferHdr);
    328 	OMX_ERRORTYPE PROXY_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    329 	    OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,
    330 	    OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes);
    331 	OMX_ERRORTYPE PROXY_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,
    332 	    OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr);
    333 	OMX_ERRORTYPE PROXY_ComponentDeInit(OMX_HANDLETYPE hComponent);
    334 
    335 
    336 #ifdef __cplusplus
    337 }
    338 #endif				/* __cplusplus */
    339 
    340 #endif
    341