plugins: add gst_vaapi_plugin_base_set_srcpad_can_dmabuf()
[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
89 #define GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin) \
90   (GST_VAAPI_PLUGIN_BASE(plugin)->display)
91 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(plugin) \
92   (GST_VAAPI_PLUGIN_BASE(plugin)->display_type)
93 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_NAME(plugin) \
94   (GST_VAAPI_PLUGIN_BASE(plugin)->display_name)
95 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(plugin, new_display) \
96   (gst_vaapi_display_replace(&GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin), \
97        (new_display)))
98
99 #define GST_VAAPI_PLUGIN_BASE_DEFINE_SET_CONTEXT(parent_class) \
100   static void \
101   gst_vaapi_base_set_context (GstElement * element, GstContext * context) \
102   { \
103     GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); \
104     \
105     gst_vaapi_plugin_base_set_context (plugin, context); \
106     GST_ELEMENT_CLASS (parent_class)->set_context (element, context); \
107   }
108
109 struct _GstVaapiPluginBase
110 {
111   /*< private >*/
112   union
113   {
114     GstElement element;
115     GstVideoDecoder decoder;
116     GstVideoEncoder encoder;
117     GstBaseTransform transform;
118     GstVideoSink sink;
119   } parent_instance;
120
121   GstDebugCategory *debug_category;
122
123   GstPad *sinkpad;
124   GstCaps *sinkpad_caps;
125   gboolean sinkpad_caps_is_raw;
126   GstVideoInfo sinkpad_info;
127   GstBufferPool *sinkpad_buffer_pool;
128   guint sinkpad_buffer_size;
129
130   GstPad *srcpad;
131   GstCaps *srcpad_caps;
132   GstVideoInfo srcpad_info;
133   GstBufferPool *srcpad_buffer_pool;
134
135   GstVaapiDisplay *display;
136   GstVaapiDisplayType display_type;
137   GstVaapiDisplayType display_type_req;
138   gchar *display_name;
139
140   GstObject *gl_context;
141   GstObject *gl_display;
142   GstObject *gl_other_context;
143
144   GstCaps *allowed_raw_caps;
145   GstAllocator *sinkpad_allocator;
146   GstAllocator *srcpad_allocator;
147   gboolean srcpad_can_dmabuf;
148
149   gboolean enable_direct_rendering;
150 };
151
152 struct _GstVaapiPluginBaseClass
153 {
154   /*< private >*/
155   union
156   {
157     GstElementClass element;
158     GstVideoDecoderClass decoder;
159     GstVideoEncoderClass encoder;
160     GstBaseTransformClass transform;
161     GstVideoSinkClass sink;
162   } parent_class;
163
164   gboolean  (*has_interface) (GstVaapiPluginBase * plugin, GType type);
165   void (*display_changed) (GstVaapiPluginBase * plugin);
166 };
167
168 G_GNUC_INTERNAL
169 void
170 gst_vaapi_plugin_base_init_interfaces (GType type);
171
172 G_GNUC_INTERNAL
173 void
174 gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass);
175
176 G_GNUC_INTERNAL
177 void
178 gst_vaapi_plugin_base_init (GstVaapiPluginBase * plugin,
179     GstDebugCategory * debug_category);
180
181 G_GNUC_INTERNAL
182 void
183 gst_vaapi_plugin_base_finalize (GstVaapiPluginBase * plugin);
184
185 G_GNUC_INTERNAL
186 gboolean
187 gst_vaapi_plugin_base_open (GstVaapiPluginBase * plugin);
188
189 G_GNUC_INTERNAL
190 void
191 gst_vaapi_plugin_base_close (GstVaapiPluginBase * plugin);
192
193 G_GNUC_INTERNAL
194 gboolean
195 gst_vaapi_plugin_base_has_display_type (GstVaapiPluginBase * plugin,
196     GstVaapiDisplayType display_type_req);
197
198 G_GNUC_INTERNAL
199 void
200 gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
201     GstVaapiDisplayType display_type);
202
203 G_GNUC_INTERNAL
204 void
205 gst_vaapi_plugin_base_set_display_name (GstVaapiPluginBase * plugin,
206     const gchar * display_name);
207
208 G_GNUC_INTERNAL
209 gboolean
210 gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin);
211
212 G_GNUC_INTERNAL
213 gboolean
214 gst_vaapi_plugin_base_set_caps (GstVaapiPluginBase * plugin, GstCaps * incaps,
215     GstCaps * outcaps);
216
217 G_GNUC_INTERNAL
218 gboolean
219 gst_vaapi_plugin_base_propose_allocation (GstVaapiPluginBase * plugin,
220     GstQuery * query);
221
222 G_GNUC_INTERNAL
223 gboolean
224 gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
225     GstQuery * query);
226
227 G_GNUC_INTERNAL
228 GstFlowReturn
229 gst_vaapi_plugin_base_get_input_buffer (GstVaapiPluginBase * plugin,
230     GstBuffer * inbuf, GstBuffer ** outbuf_ptr);
231
232 G_GNUC_INTERNAL
233 void
234 gst_vaapi_plugin_base_set_context (GstVaapiPluginBase * plugin,
235     GstContext * context);
236
237 G_GNUC_INTERNAL
238 void
239 gst_vaapi_plugin_base_set_gl_context (GstVaapiPluginBase * plugin,
240     GstObject * object);
241
242 G_GNUC_INTERNAL
243 GstObject *
244 gst_vaapi_plugin_base_create_gl_context (GstVaapiPluginBase * plugin);
245
246 G_GNUC_INTERNAL
247 GstCaps *
248 gst_vaapi_plugin_base_get_allowed_raw_caps (GstVaapiPluginBase * plugin);
249
250 G_GNUC_INTERNAL
251 void
252 gst_vaapi_plugin_base_set_srcpad_can_dmabuf (GstVaapiPluginBase * plugin,
253     GstObject * object);
254
255 G_END_DECLS
256
257 #endif /* GST_VAAPI_PLUGIN_BASE_H */