plugins: factor out decide_allocation() hook.
[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 #include "gstvaapiuploader.h"
34
35 G_BEGIN_DECLS
36
37 typedef struct _GstVaapiPluginBase GstVaapiPluginBase;
38 typedef struct _GstVaapiPluginBaseClass GstVaapiPluginBaseClass;
39
40 #define GST_VAAPI_PLUGIN_BASE(plugin) \
41   ((GstVaapiPluginBase *)(plugin))
42 #define GST_VAAPI_PLUGIN_BASE_CLASS(plugin) \
43   ((GstVaapiPluginBaseClass *)(plugin))
44 #define GST_VAAPI_PLUGIN_BASE_GET_CLASS(plugin) \
45   GST_VAAPI_PLUGIN_BASE_CLASS(GST_ELEMENT_GET_CLASS( \
46       GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin)))
47 #define GST_VAAPI_PLUGIN_BASE_PARENT(plugin) \
48   (&GST_VAAPI_PLUGIN_BASE(plugin)->parent_instance)
49 #define GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin) \
50   (&GST_VAAPI_PLUGIN_BASE_CLASS(plugin)->parent_class)
51 #define GST_VAAPI_PLUGIN_BASE_ELEMENT(plugin) \
52   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->element)
53 #define GST_VAAPI_PLUGIN_BASE_ELEMENT_CLASS(plugin) \
54   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->element)
55 #define GST_VAAPI_PLUGIN_BASE_DECODER(plugin) \
56   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->decoder)
57 #define GST_VAAPI_PLUGIN_BASE_DECODER_CLASS(plugin) \
58   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->decoder)
59 #define GST_VAAPI_PLUGIN_BASE_ENCODER(plugin) \
60   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->encoder)
61 #define GST_VAAPI_PLUGIN_BASE_ENCODER_CLASS(plugin) \
62   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->encoder)
63 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM(plugin) \
64   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->transform)
65 #define GST_VAAPI_PLUGIN_BASE_TRANSFORM_CLASS(plugin) \
66   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->transform)
67 #define GST_VAAPI_PLUGIN_BASE_SINK(plugin) \
68   (&GST_VAAPI_PLUGIN_BASE_PARENT(plugin)->sink)
69 #define GST_VAAPI_PLUGIN_BASE_SINK_CLASS(plugin) \
70   (&GST_VAAPI_PLUGIN_BASE_PARENT_CLASS(plugin)->sink)
71
72 #define GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES \
73   gst_vaapi_plugin_base_init_interfaces(g_define_type_id);
74
75 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD(plugin) \
76   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad)
77 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_CAPS(plugin) \
78   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad_caps)
79 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_INFO(plugin) \
80   (&GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad_info)
81 #define GST_VAAPI_PLUGIN_BASE_SINK_PAD_QUERYFUNC(plugin) \
82   (GST_VAAPI_PLUGIN_BASE(plugin)->sinkpad_query)
83 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD(plugin) \
84   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad)
85 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_CAPS(plugin) \
86   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_caps)
87 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_INFO(plugin) \
88   (&GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_info)
89 #define GST_VAAPI_PLUGIN_BASE_SRC_PAD_QUERYFYNC(plugin) \
90   (GST_VAAPI_PLUGIN_BASE(plugin)->srcpad_query)
91
92 #define GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin) \
93   (GST_VAAPI_PLUGIN_BASE(plugin)->display)
94 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_TYPE(plugin) \
95   (GST_VAAPI_PLUGIN_BASE(plugin)->display_type)
96 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_NAME(plugin) \
97   (GST_VAAPI_PLUGIN_BASE(plugin)->display_name)
98 #define GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(plugin, new_display) \
99   (gst_vaapi_display_replace(&GST_VAAPI_PLUGIN_BASE_DISPLAY(plugin), \
100        (new_display)))
101
102 #define GST_VAAPI_PLUGIN_BASE_UPLOADER(plugin) \
103   (GST_VAAPI_PLUGIN_BASE(plugin)->uploader)
104 #define GST_VAAPI_PLUGIN_BASE_UPLOADER_CAPS(plugin) \
105   (gst_vaapi_uploader_get_caps(GST_VAAPI_PLUGIN_BASE_UPLOADER(plugin)))
106 #define GST_VAAPI_PLUGIN_BASE_UPLOADER_USED(plugin) \
107   (GST_VAAPI_PLUGIN_BASE(plugin)->uploader_used)
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_changed;
126   gboolean sinkpad_caps_is_raw;
127   GstVideoInfo sinkpad_info;
128   GstPadQueryFunction sinkpad_query;
129 #if GST_CHECK_VERSION(1,0,0)
130   GstBufferPool *sinkpad_buffer_pool;
131   guint sinkpad_buffer_size;
132 #endif
133
134   GstPad *srcpad;
135   GstCaps *srcpad_caps;
136   gboolean srcpad_caps_changed;
137   GstVideoInfo srcpad_info;
138   GstPadQueryFunction srcpad_query;
139 #if GST_CHECK_VERSION(1,0,0)
140   GstBufferPool *srcpad_buffer_pool;
141 #endif
142
143   GstVaapiDisplay *display;
144   GstVaapiDisplayType display_type;
145   GstVaapiDisplayType display_type_req;
146   gchar *display_name;
147
148   GstVaapiUploader *uploader;
149   gboolean uploader_used;
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 void
195 gst_vaapi_plugin_base_set_display_type (GstVaapiPluginBase * plugin,
196     GstVaapiDisplayType display_type);
197
198 G_GNUC_INTERNAL
199 void
200 gst_vaapi_plugin_base_set_display_name (GstVaapiPluginBase * plugin,
201     const gchar * display_name);
202
203 G_GNUC_INTERNAL
204 gboolean
205 gst_vaapi_plugin_base_ensure_display (GstVaapiPluginBase * plugin);
206
207 G_GNUC_INTERNAL
208 gboolean
209 gst_vaapi_plugin_base_ensure_uploader (GstVaapiPluginBase * plugin);
210
211 G_GNUC_INTERNAL
212 gboolean
213 gst_vaapi_plugin_base_set_caps (GstVaapiPluginBase * plugin, GstCaps * incaps,
214     GstCaps * outcaps);
215
216 G_GNUC_INTERNAL
217 gboolean
218 gst_vaapi_plugin_base_propose_allocation (GstVaapiPluginBase * plugin,
219     GstQuery * query);
220
221 G_GNUC_INTERNAL
222 gboolean
223 gst_vaapi_plugin_base_decide_allocation (GstVaapiPluginBase * plugin,
224     GstQuery * query, guint feature);
225
226 G_GNUC_INTERNAL
227 GstFlowReturn
228 gst_vaapi_plugin_base_allocate_input_buffer (GstVaapiPluginBase * plugin,
229     GstCaps * caps, GstBuffer ** outbuf_ptr);
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_END_DECLS
237
238 #endif /* GST_VAAPI_PLUGIN_BASE_H */