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