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