plugins: use plugin base macros to access pad specific data
[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
39 #define GST_VAAPI_PLUGIN_BASE(plugin) \
40   ((GstVaapiPluginBase *)(plugin))
41 #define GST_VAAPI_PLUGIN_BASE_CLASS(plugin) \
42   ((GstVaapiPluginBaseClass *)(plugin))
43 #define GST_VAAPI_PLUGIN_BASE_GET_CLASS(plugin) \
44   GST_VAAPI_PLUGIN_BASE_CLASS(GST_ELEMENT_GET_CLASS( \
45       GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin)))
46 #define GST_VAAPI_PLUGIN_BASE_PARENT(plugin) \
47   (&GST_VAAPI_PLUGIN_BASE(plugin)->parent_instance)
48 #define GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin) \
49   (&GST_VAAPI_PLUGIN_BASE_CLASS(plugin)->parent_class)
50 #define GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin) \
51   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->element)
52 #define GST_VAAPI_PLUGIN_BASE_ELEMENT_CLASS(plugin) \
53   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->element)
54 #define GST_VAAPI_PLUGIN_BASE_DECODER(plugin) \
55   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->decoder)
56 #define GST_VAAPI_PLUGIN_BASE_DECODER_CLASS(plugin) \
57   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->decoder)
58 #define GST_VAAPI_PLUGIN_BASE_ENCODER(plugin) \
59   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->encoder)
60 #define GST_VAAPI_PLUGIN_BASE_ENCODER_CLASS(plugin) \
61   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->encoder)
62 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM(plugin) \
63   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->transform)
64 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM_CLASS(plugin) \
65   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->transform)
66 #define GST_VAAPI_PLUGIN_BASE_SINK(plugin) \
67   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->sink)
68 #define GST_VAAPI_PLUGIN_BASE_SINK_CLASS(plugin) \
69   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->sink)
70
71 #define GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES \
72   gst_vaapi_plugin_base_init_interfaces(g_define_type_id);
73
74 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD(plugin) \
75   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad)
76 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_CAPS(plugin) \
77   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad_caps)
78 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_INFO(plugin) \
79   (&GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad_info)
80 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD(plugin) \
81   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad)
82 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAPS(plugin) \
83   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_caps)
84 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_INFO(plugin) \
85   (&GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_info)
86 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAN_DMABUF(plugin) \
87   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_can_dmabuf)
88 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_BUFFER_POOL(plugin) \
89   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_buffer_pool)
90 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_ALLOCATOR(plugin) \
91   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_allocator)
92 #define GST_VAAPI_PLUGIN_BASE_OTHER_ALLOCATOR(plugin) \
93   (GST_VAAPI_PLUGIN_BASE(plugin)->other_srcpad_allocator)
94 #define GST_VAAPI_PLUGIN_BASE_OTHER_ALLOCATOR_PARAMS(plugin) \
95   (GST_VAAPI_PLUGIN_BASE(plugin)->other_allocator_params)
96 #define GST_VAAPI_PLUGIN_BASE_COPY_OUTPUT_FRAME(plugin) \
97   (GST_VAAPI_PLUGIN_BASE(plugin)->copy_output_frame)
98
99 #define GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin) \
100   (GST_VAAPI_PLUGIN_BASE(plugin)->display)
101 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(plugin) \
102   (GST_VAAPI_PLUGIN_BASE(plugin)->display_type)
103 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_NAME(plugin) \
104   (GST_VAAPI_PLUGIN_BASE(plugin)->display_name)
105 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(plugin, new_display) \
106   (gst_vaapi_display_replace(&GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin), \
107        (new_display)))
108
109 #define GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT(parent_class) \
110   static void \
111   gst_vaapi_base_set_context (GstElement * element, GstContext * context) \
112   { \
113     GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); \
114     \
115     gst_vaapi_plugin_base_set_context (plugin, context); \
116     GST_ELEMENT_CLASS (parent_class)->set_context (element, context); \
117   }
118
119 struct _GstVaapiPluginBase
120 {
121   /*< private >*/
122   union
123   {
124     GstElement element;
125     GstVideoDecoder decoder;
126     GstVideoEncoder encoder;
127     GstBaseTransform transform;
128     GstVideoSink sink;
129   } parent_instance;
130
131   GstDebugCategory *debug_category;
132
133   GstPad *sinkpad;
134   GstCaps *sinkpad_caps;
135   gboolean sinkpad_caps_is_raw;
136   GstVideoInfo sinkpad_info;
137   GstBufferPool *sinkpad_buffer_pool;
138   guint sinkpad_buffer_size;
139
140   GstPad *srcpad;
141   GstCaps *srcpad_caps;
142   GstVideoInfo srcpad_info;
143   GstBufferPool *srcpad_buffer_pool;
144
145   GstVaapiDisplay *display;
146   GstVaapiDisplayType display_type;
147   GstVaapiDisplayType display_type_req;
148   gchar *display_name;
149
150   GstObject *gl_context;
151   GstObject *gl_display;
152   GstObject *gl_other_context;
153
154   GstCaps *allowed_raw_caps;
155   GstAllocator *sinkpad_allocator;
156   GstAllocator *srcpad_allocator;
157   gboolean srcpad_can_dmabuf;
158
159   gboolean enable_direct_rendering;
160
161   GstAllocator *other_srcpad_allocator;
162   GstAllocationParams other_allocator_params;
163   gboolean copy_output_frame;
164 };
165
166 struct _GstVaapiPluginBaseClass
167 {
168   /*< private >*/
169   union
170   {
171     GstElementClass element;
172     GstVideoDecoderClass decoder;
173     GstVideoEncoderClass encoder;
174     GstBaseTransformClass transform;
175     GstVideoSinkClass sink;
176   } parent_class;
177
178   gboolean  (*has_interface) (GstVaapiPluginBase * plugin, GType type);
179   void (*display_changed) (GstVaapiPluginBase * plugin);
180 };
181
182 G_GNUC_INTERNAL
183 void
184 gst_vaapi_plugin_base_init_interfaces (GType type);
185
186 G_GNUC_INTERNAL
187 void
188 gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass);
189
190 G_GNUC_INTERNAL
191 void
192 gst_vaapi_plugin_base_init (GstVaapiPluginBase * plugin,
193     GstDebugCategory * debug_category);
194
195 G_GNUC_INTERNAL
196 void
197 gst_vaapi_plugin_base_finalize (GstVaapiPluginBase * plugin);
198
199 G_GNUC_INTERNAL
200 gboolean
201 gst_vaapi_plugin_base_open (GstVaapiPluginBase * plugin);
202
203 G_GNUC_INTERNAL
204 void
205 gst_vaapi_plugin_base_close (GstVaapiPluginBase * plugin);
206
207 G_GNUC_INTERNAL
208 gboolean
209 gst_vaapi_plugin_base_has_display_type (GstVaapiPluginBase * plugin,
210     GstVaapiDisplayType display_type_req);
211
212 G_GNUC_INTERNAL
213 void
214 gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
215     GstVaapiDisplayType display_type);
216
217 G_GNUC_INTERNAL
218 void
219 gst_vaapi_plugin_base_set_display_name (GstVaapiPluginBase * plugin,
220     const gchar * display_name);
221
222 G_GNUC_INTERNAL
223 gboolean
224 gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin);
225
226 G_GNUC_INTERNAL
227 gboolean
228 gst_vaapi_plugin_base_set_caps (GstVaapiPluginBase * plugin, GstCaps * incaps,
229     GstCaps * outcaps);
230
231 G_GNUC_INTERNAL
232 gboolean
233 gst_vaapi_plugin_base_propose_allocation (GstVaapiPluginBase * plugin,
234     GstQuery * query);
235
236 G_GNUC_INTERNAL
237 gboolean
238 gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
239     GstQuery * query);
240
241 G_GNUC_INTERNAL
242 GstFlowReturn
243 gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin,
244     GstBuffer * inbuf, GstBuffer ** outbuf_ptr);
245
246 G_GNUC_INTERNAL
247 void
248 gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin,
249     GstContext * context);
250
251 G_GNUC_INTERNAL
252 void
253 gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
254     GstObject * object);
255
256 G_GNUC_INTERNAL
257 GstObject *
258 gst_vaapi_plugin_base_create_gl_context (GstVaapiPluginBase * plugin);
259
260 G_GNUC_INTERNAL
261 GstCaps *
262 gst_vaapi_plugin_base_get_allowed_sinkpad_raw_caps (GstVaapiPluginBase * plugin);
263
264 G_GNUC_INTERNAL
265 GstCaps *
266 gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (
267     GstVaapiPluginBase * plugin, GstVideoFormat format);
268
269 G_GNUC_INTERNAL
270 void
271 gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
272     GstObject * object);
273
274 G_GNUC_INTERNAL
275 gboolean
276 gst_vaapi_plugin_copy_va_buffer (GstVaapiPluginBase * plugin,
277     GstBuffer * inbuf, GstBuffer * outbuf);
278
279
280 G_END_DECLS
281
282 #endif /* GST_VAAPI_PLUGIN_BASE_H */