plugins: base: manage pad-specific data in a single struct
[platform/upstream/gstreamer.git] / gst / vaapi / gstvaapipluginbase.h
1 /*
2  *  gstvaapipluginbase.h - Base GStreamer VA-API Plugin element
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6  *  Copyright (C) 2011-2013 Intel Corporation
7  *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 #ifndef GST_VAAPI_PLUGIN_BASE_H
26 #define GST_VAAPI_PLUGIN_BASE_H
27
28 #include <gst/base/gstbasetransform.h>
29 #include <gst/video/gstvideodecoder.h>
30 #include <gst/video/gstvideoencoder.h>
31 #include <gst/video/gstvideosink.h>
32 #include <gst/vaapi/gstvaapidisplay.h>
33
34 G_BEGIN_DECLS
35
36 typedef struct _GstVaapiPluginBase GstVaapiPluginBase;
37 typedef struct _GstVaapiPluginBaseClass GstVaapiPluginBaseClass;
38 typedef struct _GstVaapiPadPrivate GstVaapiPadPrivate;
39
40 #define GST_VAAPI_PLUGIN_BASE(plugin) \
41   ((GstVaapiPluginBase *)(plugin))
42 #define GST_VAAPI_PLUGIN_BASE_CLASS(plugin) \
43   ((GstVaapiPluginBaseClass *)(plugin))
44 #define GST_VAAPI_PLUGIN_BASE_GET_CLASS(plugin) \
45   GST_VAAPI_PLUGIN_BASE_CLASS(GST_ELEMENT_GET_CLASS( \
46       GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin)))
47 #define GST_VAAPI_PLUGIN_BASE_PARENT(plugin) \
48   (&GST_VAAPI_PLUGIN_BASE(plugin)->parent_instance)
49 #define GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin) \
50   (&GST_VAAPI_PLUGIN_BASE_CLASS(plugin)->parent_class)
51 #define GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin) \
52   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->element)
53 #define GST_VAAPI_PLUGIN_BASE_ELEMENT_CLASS(plugin) \
54   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->element)
55 #define GST_VAAPI_PLUGIN_BASE_DECODER(plugin) \
56   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->decoder)
57 #define GST_VAAPI_PLUGIN_BASE_DECODER_CLASS(plugin) \
58   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->decoder)
59 #define GST_VAAPI_PLUGIN_BASE_ENCODER(plugin) \
60   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->encoder)
61 #define GST_VAAPI_PLUGIN_BASE_ENCODER_CLASS(plugin) \
62   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->encoder)
63 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM(plugin) \
64   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->transform)
65 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM_CLASS(plugin) \
66   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->transform)
67 #define GST_VAAPI_PLUGIN_BASE_SINK(plugin) \
68   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->sink)
69 #define GST_VAAPI_PLUGIN_BASE_SINK_CLASS(plugin) \
70   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->sink)
71
72 #define GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES \
73   gst_vaapi_plugin_base_init_interfaces(g_define_type_id);
74
75 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD(plugin) \
76   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad)
77 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_PRIVATE(plugin) \
78   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpriv)
79 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_CAPS(plugin) \
80   (GST_VAAPI_PLUGIN_BASE_SINK_PAD_PRIVATE(plugin)->caps)
81 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_INFO(plugin) \
82   (&GST_VAAPI_PLUGIN_BASE_SINK_PAD_PRIVATE(plugin)->info)
83
84 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD(plugin) \
85   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad)
86 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin) \
87   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpriv)
88 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAPS(plugin) \
89   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->caps)
90 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_INFO(plugin) \
91   (&GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->info)
92 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAN_DMABUF(plugin) \
93   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->can_dmabuf)
94 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_BUFFER_POOL(plugin) \
95   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->buffer_pool)
96 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_ALLOCATOR(plugin) \
97   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->allocator)
98 #define GST_VAAPI_PLUGIN_BASE_OTHER_ALLOCATOR(plugin) \
99   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->other_allocator)
100 #define GST_VAAPI_PLUGIN_BASE_OTHER_ALLOCATOR_PARAMS(plugin) \
101   (GST_VAAPI_PLUGIN_BASE_SRC_PAD_PRIVATE(plugin)->other_allocator_params)
102
103 #define GST_VAAPI_PLUGIN_BASE_COPY_OUTPUT_FRAME(plugin) \
104   (GST_VAAPI_PLUGIN_BASE(plugin)->copy_output_frame)
105
106 #define GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin) \
107   (GST_VAAPI_PLUGIN_BASE(plugin)->display)
108 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(plugin) \
109   (GST_VAAPI_PLUGIN_BASE(plugin)->display_type)
110 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_NAME(plugin) \
111   (GST_VAAPI_PLUGIN_BASE(plugin)->display_name)
112 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(plugin, new_display) \
113   (gst_vaapi_display_replace(&GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin), \
114        (new_display)))
115
116 #define GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT(parent_class) \
117   static void \
118   gst_vaapi_base_set_context (GstElement * element, GstContext * context) \
119   { \
120     GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); \
121     \
122     gst_vaapi_plugin_base_set_context (plugin, context); \
123     GST_ELEMENT_CLASS (parent_class)->set_context (element, context); \
124   }
125
126 struct _GstVaapiPadPrivate
127 {
128   GstCaps *caps;
129   GstVideoInfo info;
130   GstBufferPool *buffer_pool;
131   GstAllocator *allocator;
132   guint buffer_size;
133   gboolean caps_is_raw;
134
135   gboolean can_dmabuf;
136
137   GstAllocator *other_allocator;
138   GstAllocationParams other_allocator_params;
139 };
140
141 struct _GstVaapiPluginBase
142 {
143   /*< private >*/
144   union
145   {
146     GstElement element;
147     GstVideoDecoder decoder;
148     GstVideoEncoder encoder;
149     GstBaseTransform transform;
150     GstVideoSink sink;
151   } parent_instance;
152
153   GstDebugCategory *debug_category;
154
155   GstPad *sinkpad;
156   GstPad *srcpad;
157
158   GstVaapiPadPrivate *sinkpriv;
159   GstVaapiPadPrivate *srcpriv;
160
161   GstVaapiDisplay *display;
162   GstVaapiDisplayType display_type;
163   GstVaapiDisplayType display_type_req;
164   gchar *display_name;
165
166   GstObject *gl_context;
167   GstObject *gl_display;
168   GstObject *gl_other_context;
169
170   GstCaps *allowed_raw_caps;
171
172   gboolean enable_direct_rendering;
173   gboolean copy_output_frame;
174 };
175
176 struct _GstVaapiPluginBaseClass
177 {
178   /*< private >*/
179   union
180   {
181     GstElementClass element;
182     GstVideoDecoderClass decoder;
183     GstVideoEncoderClass encoder;
184     GstBaseTransformClass transform;
185     GstVideoSinkClass sink;
186   } parent_class;
187
188   gboolean  (*has_interface) (GstVaapiPluginBase * plugin, GType type);
189   void (*display_changed) (GstVaapiPluginBase * plugin);
190   GstVaapiPadPrivate * (*get_vaapi_pad_private) (GstVaapiPluginBase * plugin, GstPad * pad);
191 };
192
193 G_GNUC_INTERNAL
194 void
195 gst_vaapi_plugin_base_init_interfaces (GType type);
196
197 G_GNUC_INTERNAL
198 void
199 gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass);
200
201 G_GNUC_INTERNAL
202 void
203 gst_vaapi_plugin_base_init (GstVaapiPluginBase * plugin,
204     GstDebugCategory * debug_category);
205
206 G_GNUC_INTERNAL
207 void
208 gst_vaapi_plugin_base_finalize (GstVaapiPluginBase * plugin);
209
210 G_GNUC_INTERNAL
211 gboolean
212 gst_vaapi_plugin_base_open (GstVaapiPluginBase * plugin);
213
214 G_GNUC_INTERNAL
215 void
216 gst_vaapi_plugin_base_close (GstVaapiPluginBase * plugin);
217
218 G_GNUC_INTERNAL
219 gboolean
220 gst_vaapi_plugin_base_has_display_type (GstVaapiPluginBase * plugin,
221     GstVaapiDisplayType display_type_req);
222
223 G_GNUC_INTERNAL
224 void
225 gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
226     GstVaapiDisplayType display_type);
227
228 G_GNUC_INTERNAL
229 void
230 gst_vaapi_plugin_base_set_display_name (GstVaapiPluginBase * plugin,
231     const gchar * display_name);
232
233 G_GNUC_INTERNAL
234 gboolean
235 gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin);
236
237 G_GNUC_INTERNAL
238 gboolean
239 gst_vaapi_plugin_base_set_caps (GstVaapiPluginBase * plugin, GstCaps * incaps,
240     GstCaps * outcaps);
241
242 G_GNUC_INTERNAL
243 gboolean
244 gst_vaapi_plugin_base_propose_allocation (GstVaapiPluginBase * plugin,
245     GstQuery * query);
246
247 G_GNUC_INTERNAL
248 gboolean
249 gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
250     GstQuery * query);
251
252 G_GNUC_INTERNAL
253 GstFlowReturn
254 gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin,
255     GstBuffer * inbuf, GstBuffer ** outbuf_ptr);
256
257 G_GNUC_INTERNAL
258 void
259 gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin,
260     GstContext * context);
261
262 G_GNUC_INTERNAL
263 void
264 gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
265     GstObject * object);
266
267 G_GNUC_INTERNAL
268 GstObject *
269 gst_vaapi_plugin_base_create_gl_context (GstVaapiPluginBase * plugin);
270
271 G_GNUC_INTERNAL
272 GstCaps *
273 gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin);
274
275 G_GNUC_INTERNAL
276 GstCaps *
277 gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (
278     GstVaapiPluginBase * plugin, GstVideoFormat format);
279
280 G_GNUC_INTERNAL
281 void
282 gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
283     GstObject * object);
284
285 G_GNUC_INTERNAL
286 gboolean
287 gst_vaapi_plugin_copy_va_buffer (GstVaapiPluginBase * plugin,
288     GstBuffer * inbuf, GstBuffer * outbuf);
289
290
291 G_END_DECLS
292
293 #endif /* GST_VAAPI_PLUGIN_BASE_H */