• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2013 Rockchip Electronics Co., LTD.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /*
19  * @file       Rockchip_OMX_Baseport.h
20  * @brief
21  * @author     csy (csy@rock-chips.com)
22  * @version    1.0.0
23  * @history
24  *    2013.11.26 : Create
25  */
26 
27 #ifndef ROCKCHIP_OMX_BASE_PORT
28 #define ROCKCHIP_OMX_BASE_PORT
29 
30 
31 #include "OMX_Component.h"
32 #include "Rockchip_OMX_Def.h"
33 #include "Rockchip_OSAL_Queue.h"
34 
35 
36 #define BUFFER_STATE_ALLOCATED  (1 << 0)
37 #define BUFFER_STATE_ASSIGNED   (1 << 1)
38 #define HEADER_STATE_ALLOCATED  (1 << 2)
39 #define BUFFER_STATE_FREE        0
40 
41 #define MAX_BUFFER_NUM          40
42 
43 #define INPUT_PORT_INDEX    0
44 #define OUTPUT_PORT_INDEX   1
45 #define ALL_PORT_INDEX     (-1)
46 #define ALL_PORT_NUM        2
47 
48 
49 typedef struct _ROCKCHIP_OMX_BUFFERHEADERTYPE {
50     OMX_BUFFERHEADERTYPE *OMXBufferHeader;
51     OMX_BOOL              bBufferInOMX;
52     OMX_HANDLETYPE        ANBHandle;
53     void                 *pYUVBuf[MAX_BUFFER_PLANE];
54     int                   buf_fd[MAX_BUFFER_PLANE];
55     int                   pRegisterFlag;
56     OMX_PTR               pPrivate;
57 } ROCKCHIP_OMX_BUFFERHEADERTYPE;
58 
59 typedef struct _ROCKCHIP_OMX_DATABUFFER {
60     OMX_HANDLETYPE        bufferMutex;
61     OMX_BUFFERHEADERTYPE* bufferHeader;
62     OMX_BOOL              dataValid;
63     OMX_U32               allocSize;
64     OMX_U32               dataLen;
65     OMX_U32               usedDataLen;
66     OMX_U32               remainDataLen;
67     OMX_U32               nFlags;
68     OMX_TICKS             timeStamp;
69     OMX_PTR               pPrivate;
70 } ROCKCHIP_OMX_DATABUFFER;
71 
72 typedef void* CODEC_EXTRA_BUFFERINFO;
73 
74 typedef struct _ROCKCHIP_OMX_SINGLEPLANE_DATA {
75     OMX_PTR dataBuffer;
76     int fd;
77 } ROCKCHIP_OMX_SINGLEPLANE_DATA;
78 
79 typedef struct _ROCKCHIP_OMX_MULTIPLANE_DATA {
80     OMX_U32 validPlaneNum;
81     OMX_PTR dataBuffer[MAX_BUFFER_PLANE];
82     int fd[MAX_BUFFER_PLANE];
83 } ROCKCHIP_OMX_MULTIPLANE_DATA;
84 
85 typedef struct _ROCKCHIP_OMX_DATA {
86     union {
87         ROCKCHIP_OMX_SINGLEPLANE_DATA singlePlaneBuffer;
88         ROCKCHIP_OMX_MULTIPLANE_DATA multiPlaneBuffer;
89     } buffer;
90     OMX_U32   allocSize;
91     OMX_U32   dataLen;
92     OMX_U32   usedDataLen;
93     OMX_U32   remainDataLen;
94     OMX_U32   nFlags;
95     OMX_TICKS timeStamp;
96     OMX_PTR   pPrivate;
97     CODEC_EXTRA_BUFFERINFO extInfo;
98 
99     /* For Share Buffer */
100     OMX_BUFFERHEADERTYPE* bufferHeader;
101 } ROCKCHIP_OMX_DATA;
102 
103 typedef struct _ROCKCHIP_OMX_WAY1_PORT_DATABUFFER {
104     ROCKCHIP_OMX_DATABUFFER dataBuffer;
105 } ROCKCHIP_OMX_PORT_1WAY_DATABUFFER;
106 
107 typedef struct _ROCKCHIP_OMX_WAY2_PORT_DATABUFFER {
108     ROCKCHIP_OMX_DATABUFFER inputDataBuffer;
109     ROCKCHIP_OMX_DATABUFFER outputDataBuffer;
110 } ROCKCHIP_OMX_PORT_2WAY_DATABUFFER;
111 
112 typedef enum _ROCKCHIP_OMX_PORT_WAY_TYPE {
113     WAY1_PORT = 0x00,
114     WAY2_PORT
115 } ROCKCHIP_OMX_PORT_WAY_TYPE;
116 
117 typedef enum _ROCKCHIP_OMX_EXCEPTION_STATE {
118     GENERAL_STATE = 0x00,
119     NEED_PORT_FLUSH,
120     NEED_PORT_DISABLE,
121     INVALID_STATE,
122 } ROCKCHIP_OMX_EXCEPTION_STATE;
123 
124 typedef enum _ROCKCHIP_OMX_PLANE {
125     ONE_PLANE       = 0x01,
126     TWO_PLANE       = 0x02,
127     THREE_PLANE     = 0x03,
128     /*
129         ANB_START_PLANE = 0x10,
130         ANB_ONE_PLANE   = 0x11,
131         ANB_TWO_PLANE   = 0x12,
132         ANB_THREE_PLANE = 0x13,
133     */
134 } ROCKCHIP_OMX_PLANE;
135 
136 typedef struct _ROCKCHIP_OMX_BASEPORT {
137     ROCKCHIP_OMX_BUFFERHEADERTYPE   *extendBufferHeader;
138     OMX_U32                       *bufferStateAllocate;
139     OMX_PARAM_PORTDEFINITIONTYPE   portDefinition;
140     OMX_HANDLETYPE                 bufferSemID;
141     ROCKCHIP_QUEUE                 bufferQ;
142     ROCKCHIP_QUEUE                 securebufferQ;
143     OMX_U32                        assignedBufferNum;
144     OMX_STATETYPE                  portState;
145     OMX_HANDLETYPE                 loadedResource;
146     OMX_HANDLETYPE                 unloadedResource;
147 
148     OMX_BOOL                       bIsPortFlushed;
149     OMX_BOOL                       bIsPortDisabled;
150     OMX_MARKTYPE                   markType;
151 
152     OMX_CONFIG_RECTTYPE            cropRectangle;
153 
154     /* Tunnel Info */
155     OMX_HANDLETYPE                 tunneledComponent;
156     OMX_U32                        tunneledPort;
157     OMX_U32                        tunnelBufferNum;
158     OMX_BUFFERSUPPLIERTYPE         bufferSupplier;
159     OMX_U32                        tunnelFlags;
160 
161     OMX_BOOL                       bStoreMetaData;
162 
163     ROCKCHIP_OMX_BUFFERPROCESS_TYPE  bufferProcessType;
164     ROCKCHIP_OMX_PORT_WAY_TYPE       portWayType;
165     OMX_HANDLETYPE                 codecSemID;
166     ROCKCHIP_QUEUE                   codecBufferQ;
167 
168     OMX_HANDLETYPE                 pauseEvent;
169 
170     /* Buffer */
171     union {
172         ROCKCHIP_OMX_PORT_1WAY_DATABUFFER port1WayDataBuffer;
173         ROCKCHIP_OMX_PORT_2WAY_DATABUFFER port2WayDataBuffer;
174     } way;
175 
176     /* Data */
177     ROCKCHIP_OMX_DATA                processData;
178 
179     /* for flush of Shared buffer scheme */
180     OMX_HANDLETYPE                 hAllCodecBufferReturnEvent;
181     OMX_HANDLETYPE                 hPortMutex;
182     OMX_HANDLETYPE                 secureBufferMutex;
183     ROCKCHIP_OMX_EXCEPTION_STATE     exceptionFlag;
184 
185     OMX_PARAM_PORTDEFINITIONTYPE   newPortDefinition;
186     OMX_CONFIG_RECTTYPE            newCropRectangle;
187 } ROCKCHIP_OMX_BASEPORT;
188 
189 
190 #ifdef __cplusplus
191 extern "C" {
192 #endif
193 
194 OMX_ERRORTYPE Rockchip_OMX_PortEnableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex);
195 OMX_ERRORTYPE Rockchip_OMX_PortDisableProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex);
196 OMX_ERRORTYPE Rockchip_OMX_BufferFlushProcess(OMX_COMPONENTTYPE *pOMXComponent, OMX_S32 nPortIndex, OMX_BOOL bEvent);
197 OMX_ERRORTYPE Rockchip_OMX_Port_Constructor(OMX_HANDLETYPE hComponent);
198 OMX_ERRORTYPE Rockchip_OMX_Port_Destructor(OMX_HANDLETYPE hComponent);
199 OMX_ERRORTYPE Rockchip_ResetDataBuffer(ROCKCHIP_OMX_DATABUFFER *pDataBuffer);
200 OMX_ERRORTYPE Rockchip_ResetCodecData(ROCKCHIP_OMX_DATA *pData);
201 OMX_ERRORTYPE Rockchip_Shared_BufferToData(ROCKCHIP_OMX_DATABUFFER *pUseBuffer,
202     ROCKCHIP_OMX_DATA *pData, ROCKCHIP_OMX_PLANE nPlane);
203 OMX_ERRORTYPE Rockchip_Shared_DataToBuffer(ROCKCHIP_OMX_DATA *pData, ROCKCHIP_OMX_DATABUFFER *pUseBuffer);
204 OMX_ERRORTYPE Rkvpu_OMX_InputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader);
205 OMX_ERRORTYPE Rockchip_OMX_OutputBufferReturn(OMX_COMPONENTTYPE *pOMXComponent, OMX_BUFFERHEADERTYPE* bufferHeader);
206 #ifdef __cplusplus
207 };
208 #endif
209 #endif