2 * gstvaapidisplay.c - VA display abstraction
4 * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "vaapi_utils.h"
23 #include "gstvaapidisplay.h"
24 #include <va/va_backend.h>
27 #include "vaapi_debug.h"
29 G_DEFINE_TYPE(GstVaapiDisplay, gst_vaapi_display, G_TYPE_OBJECT);
31 #define GST_VAAPI_DISPLAY_GET_PRIVATE(obj) \
32 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
33 GST_VAAPI_TYPE_DISPLAY, \
34 GstVaapiDisplayPrivate))
36 struct _GstVaapiDisplayPrivate {
39 unsigned int num_profiles;
40 VAImageFormat *image_formats;
41 unsigned int num_image_formats;
42 VAImageFormat *subpicture_formats;
43 unsigned int *subpicture_flags;
44 unsigned int num_subpicture_formats;
54 gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display);
57 gst_vaapi_display_finalize(GObject *object)
59 GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
60 GstVaapiDisplayPrivate *priv = display->priv;
62 gst_vaapi_display_set_display(display, NULL);
64 G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
68 gst_vaapi_display_set_property(GObject *object,
73 GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
74 GstVaapiDisplayPrivate *priv = display->priv;
78 gst_vaapi_display_set_display(display, g_value_get_pointer(value));
81 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
87 gst_vaapi_display_get_property(GObject *object,
92 GstVaapiDisplay *display = GST_VAAPI_DISPLAY(object);
93 GstVaapiDisplayPrivate *priv = display->priv;
97 g_value_set_pointer(value, gst_vaapi_display_get_display(display));
100 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
106 gst_vaapi_display_class_init(GstVaapiDisplayClass *klass)
108 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
110 g_type_class_add_private(klass, sizeof(GstVaapiDisplayPrivate));
112 object_class->finalize = gst_vaapi_display_finalize;
113 object_class->set_property = gst_vaapi_display_set_property;
114 object_class->get_property = gst_vaapi_display_get_property;
116 g_object_class_install_property
119 g_param_spec_pointer("display",
122 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
126 gst_vaapi_display_init(GstVaapiDisplay *display)
128 GstVaapiDisplayPrivate *priv = GST_VAAPI_DISPLAY_GET_PRIVATE(display);
130 display->priv = priv;
131 priv->display = NULL;
133 priv->num_profiles = 0;
134 priv->image_formats = NULL;
135 priv->num_image_formats = 0;
136 priv->subpicture_formats = NULL;
137 priv->subpicture_flags = NULL;
138 priv->num_subpicture_formats = 0;
142 gst_vaapi_display_get_display(GstVaapiDisplay *display)
144 GstVaapiDisplayPrivate *priv = display->priv;
146 return priv->display;
150 gst_vaapi_display_destroy_resources(GstVaapiDisplay *display)
152 GstVaapiDisplayPrivate *priv = display->priv;
154 if (priv->profiles) {
155 g_free(priv->profiles);
156 priv->profiles = NULL;
159 if (priv->image_formats) {
160 g_free(priv->image_formats);
161 priv->image_formats = NULL;
164 if (priv->subpicture_formats) {
165 g_free(priv->subpicture_formats);
166 priv->subpicture_formats = NULL;
169 if (priv->subpicture_flags) {
170 g_free(priv->subpicture_flags);
171 priv->subpicture_flags = NULL;
176 gst_vaapi_display_create_resources(GstVaapiDisplay *display)
178 GstVaapiDisplayPrivate *priv = display->priv;
183 priv->num_profiles = vaMaxNumProfiles(priv->display);
184 priv->profiles = g_new(VAProfile, priv->num_profiles);
187 status = vaQueryConfigProfiles(priv->display,
189 &priv->num_profiles);
190 if (!vaapi_check_status(status, "vaQueryConfigProfiles()"))
193 D(bug("%d profiles\n", priv->num_profiles));
194 for (i = 0; i < priv->num_profiles; i++)
195 D(bug(" %s\n", string_of_VAProfile(priv->profiles[i])));
197 /* VA image formats */
198 priv->num_image_formats = vaMaxNumImageFormats(priv->display);
199 priv->image_formats = g_new(VAImageFormat, priv->num_image_formats);
200 if (!priv->image_formats)
202 status = vaQueryImageFormats(priv->display,
204 &priv->num_image_formats);
205 if (!vaapi_check_status(status, "vaQueryImageFormats()"))
208 D(bug("%d image formats\n", priv->num_image_formats));
209 for (i = 0; i < priv->num_image_formats; i++)
210 D(bug(" %s\n", string_of_FOURCC(priv->image_formats[i].fourcc)));
212 /* VA subpicture formats */
213 priv->num_subpicture_formats = vaMaxNumSubpictureFormats(priv->display);
214 priv->subpicture_formats = g_new(VAImageFormat, priv->num_subpicture_formats);
215 if (!priv->subpicture_formats)
217 priv->subpicture_flags = g_new(unsigned int, priv->num_subpicture_formats);
218 if (!priv->subpicture_flags)
220 status = vaQuerySubpictureFormats(priv->display,
221 priv->subpicture_formats,
222 priv->subpicture_flags,
223 &priv->num_image_formats);
224 if (!vaapi_check_status(status, "vaQuerySubpictureFormats()"))
227 D(bug("%d subpicture formats\n", priv->num_subpicture_formats));
228 for (i = 0; i < priv->num_subpicture_formats; i++)
229 D(bug(" %s\n", string_of_FOURCC(priv->subpicture_formats[i].fourcc)));
235 gst_vaapi_display_set_display(GstVaapiDisplay *display, VADisplay va_display)
237 GstVaapiDisplayPrivate *priv = display->priv;
239 int major_version, minor_version;
242 gst_vaapi_display_destroy_resources(display);
244 /* XXX: make sure this VADisplay is really the last occurrence */
245 status = vaTerminate(priv->display);
246 if (!vaapi_check_status(status, "vaTerminate()"))
248 priv->display = NULL;
252 status = vaInitialize(va_display, &major_version, &minor_version);
253 if (!vaapi_check_status(status, "vaInitialize()"))
255 priv->display = va_display;
256 D(bug("VA-API version %d.%d\n", major_version, minor_version));
258 if (!gst_vaapi_display_create_resources(display)) {
259 gst_vaapi_display_destroy_resources(display);