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@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
59extern "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             32
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",C, 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
114	typedef OMX_ERRORTYPE(*PROXY_EMPTYBUFFER_DONE) (OMX_HANDLETYPE
115	    hComponent, OMX_U32 remoteBufHdr, OMX_U32 nfilledLen,
116	    OMX_U32 nOffset, OMX_U32 nFlags);
117
118	typedef OMX_ERRORTYPE(*PROXY_FILLBUFFER_DONE) (OMX_HANDLETYPE
119	    hComponent, OMX_U32 remoteBufHdr, OMX_U32 nfilledLen,
120	    OMX_U32 nOffset, OMX_U32 nFlags, OMX_TICKS nTimeStamp,
121	    OMX_HANDLETYPE hMarkTargetComponent, OMX_PTR pMarkData);
122
123	typedef OMX_ERRORTYPE(*PROXY_EVENTHANDLER) (OMX_HANDLETYPE hComponent,
124	    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1,
125	    OMX_U32 nData2, OMX_PTR pEventData);
126
127/*******************************************************************************
128* Structures
129*******************************************************************************/
130/*===============================================================*/
131/** PROXY_BUFFER_INFO        : This structure maintains a table of A9 and
132 *                             Ducati side buffers and headers.
133 *
134 * @param pBufHeader         : This is a pointer to the A9 bufferheader.
135 *
136 * @param pBufHeaderRemote   : This is pointer to Ducati side bufferheader.
137 */
138/*===============================================================*/
139	typedef struct PROXY_BUFFER_INFO
140	{
141		OMX_BUFFERHEADERTYPE *pBufHeader;
142		OMX_U32 pBufHeaderRemote;
143		OMX_PTR pYBuffer;
144		OMX_PTR pMetaDataBuffer;
145#ifdef USE_ION
146		int mmap_fd;
147		int mmap_fd_metadata_buff;
148#endif
149	} PROXY_BUFFER_INFO;
150
151/*===============================================================*/
152/** PROXY_BUFFER_TYPE        : This enumeration tells the type of buffer pointers coming to OMX in
153				UseBuffer call.
154 */
155/*===============================================================*/
156	typedef enum PROXY_BUFFER_TYPE
157	{
158		VirtualPointers,   /*Used when buffer pointers come from the normal A9 virtual space */
159		GrallocPointers,   /*Used when buffer pointers come from Gralloc allocations */
160		IONPointers,       /*Used when buffer pointers come from ION allocations */
161		EncoderMetadataPointers		/*Used when buffer pointers come from Stagefright in camcorder usecase */
162	} PROXY_BUFFER_TYPE;
163
164/*===============================================================*/
165/** PROXY_BUFFER_TYPE        : This enumeration tells the type of buffer pointers coming to OMX in
166                               UseBuffer call.
167 */
168/*===============================================================*/
169	typedef struct PROXY_PORT_TYPE
170	{
171		PROXY_BUFFER_TYPE proxyBufferType;   /*Used when buffer pointers come from the normal A9 virtual space */
172		OMX_U32 IsBuffer2D;   /*Used when buffer pointers come from Gralloc allocations */
173	} PROXY_PORT_TYPE;
174
175/* ========================================================================== */
176/**
177* PROXY_COMPONENT_PRIVATE
178*
179*/
180/* ========================================================================== */
181	typedef struct PROXY_COMPONENT_PRIVATE
182	{
183		/* OMX Related Information */
184		OMX_CALLBACKTYPE tCBFunc;
185		OMX_PTR pILAppData;
186		OMX_HANDLETYPE hRemoteComp;
187
188		PROXY_BUFFER_INFO tBufList[MAX_NUM_PROXY_BUFFERS];
189		PROXY_PORT_TYPE proxyPortBuffers[PROXY_MAXNUMOFPORTS];
190		OMX_BOOL IsLoadedState;
191		OMX_U32 nTotalBuffers;
192		OMX_U32 nAllocatedBuffers;
193
194		/* PROXY specific data - PROXY PRIVATE DATA */
195		OMX_PTR pCompProxyPrv;
196		char *cCompName;
197
198		PROXY_EMPTYBUFFER_DONE proxyEmptyBufferDone;
199		PROXY_FILLBUFFER_DONE proxyFillBufferDone;
200		PROXY_EVENTHANDLER proxyEventHandler;
201
202#ifdef ANDROID_QUIRK_LOCK_BUFFER
203		gralloc_module_t const *grallocModule;
204#endif
205#ifdef USE_ION
206		int ion_fd;
207		OMX_BOOL bUseIon;
208		OMX_BOOL bMapIonBuffers;
209#endif
210		int secure_misc_drv_fd;
211	} PROXY_COMPONENT_PRIVATE;
212
213
214
215/*===============================================================*/
216/** PROXY_MARK_DATA        : A pointer to this structure is sent as mark data to
217 *                           the remote core when a MarkBuffer command is made.
218 *
219 * @param hComponentActual : This is the actual handle of the component to be
220 *                           marked. When marked buffers come from the remote
221 *                           to the local core then remote handle of the mark
222 *                           component is replaced by this in the header.
223 *
224 * @param pMarkdataActual : This is the mark data set by the client.
225 */
226/*===============================================================*/
227	typedef struct PROXY_MARK_DATA
228	{
229		OMX_HANDLETYPE hComponentActual;
230		OMX_PTR pMarkDataActual;
231	} PROXY_MARK_DATA;
232/*******************************************************************************
233* Functions
234*******************************************************************************/
235	OMX_ERRORTYPE OMX_ProxyCommonInit(OMX_HANDLETYPE hComponent);
236	OMX_ERRORTYPE PROXY_GetParameter(OMX_IN OMX_HANDLETYPE hComponent,
237	    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
238	OMX_ERRORTYPE PROXY_SetParameter(OMX_IN OMX_HANDLETYPE hComponent,
239	    OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pParamStruct);
240	OMX_ERRORTYPE PROXY_EventHandler(OMX_HANDLETYPE hComponent,
241	    OMX_PTR pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
242	    OMX_PTR pEventData);
243	OMX_ERRORTYPE PROXY_SendCommand(OMX_IN OMX_HANDLETYPE hComponent,
244	    OMX_IN OMX_COMMANDTYPE eCmd,
245	    OMX_IN OMX_U32 nParam, OMX_IN OMX_PTR pCmdData);
246	OMX_ERRORTYPE PROXY_EmptyThisBuffer(OMX_HANDLETYPE hComponent,
247	    OMX_BUFFERHEADERTYPE * pBufferHdr);
248	OMX_ERRORTYPE PROXY_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
249	    OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE * pIndexType);
250	OMX_ERRORTYPE PROXY_FillBufferDone(OMX_HANDLETYPE hComponent,
251	OMX_U32 remoteBufHdr, OMX_U32 nfilledLen, OMX_U32 nOffset, OMX_U32 nFlags,
252	    OMX_TICKS nTimeStamp, OMX_HANDLETYPE hMarkTargetComponent,
253	    OMX_PTR pMarkData);
254	OMX_ERRORTYPE PROXY_FillThisBuffer(OMX_HANDLETYPE hComponent,
255	    OMX_BUFFERHEADERTYPE * pBufferHdr);
256	OMX_ERRORTYPE PROXY_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,
257	    OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,
258	    OMX_IN OMX_PTR pAppPrivate, OMX_IN OMX_U32 nSizeBytes);
259	OMX_ERRORTYPE PROXY_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,
260	    OMX_IN OMX_U32 nPortIndex, OMX_IN OMX_BUFFERHEADERTYPE * pBufferHdr);
261	OMX_ERRORTYPE PROXY_ComponentDeInit(OMX_HANDLETYPE hComponent);
262
263
264#ifdef __cplusplus
265}
266#endif				/* __cplusplus */
267
268#endif
269