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