2 * gstvaapidisplay_x11.c - VA/X11 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 * SECTION:gst-vaapi-display-x11
27 #include "gstvaapiutils.h"
28 #include "gstvaapidisplay_x11.h"
31 #include "gstvaapidebug.h"
33 G_DEFINE_TYPE(GstVaapiDisplayX11,
34 gst_vaapi_display_x11,
35 GST_VAAPI_TYPE_DISPLAY);
37 #define GST_VAAPI_DISPLAY_X11_GET_PRIVATE(obj) \
38 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
39 GST_VAAPI_TYPE_DISPLAY_X11, \
40 GstVaapiDisplayX11Private))
42 struct _GstVaapiDisplayX11Private {
43 gboolean create_display;
47 VADisplay *va_display;
58 gst_vaapi_display_x11_finalize(GObject *object)
60 G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
64 set_display_name(GstVaapiDisplayX11 *display, const gchar *display_name)
66 GstVaapiDisplayX11Private * const priv = display->priv;
68 g_free(priv->display_name);
71 priv->display_name = g_strdup(display_name);
73 priv->display_name = NULL;
77 gst_vaapi_display_x11_set_property(
84 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
87 case PROP_DISPLAY_NAME:
88 set_display_name(display, g_value_get_string(value));
90 case PROP_X11_DISPLAY:
91 display->priv->x11_display = g_value_get_pointer(value);
94 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
100 gst_vaapi_display_x11_get_property(
107 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
110 case PROP_DISPLAY_NAME:
111 g_value_set_string(value, display->priv->display_name);
113 case PROP_X11_DISPLAY:
114 g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
117 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
123 gst_vaapi_display_x11_constructed(GObject *object)
125 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
126 GObjectClass *parent_class;
128 display->priv->create_display = display->priv->x11_display == NULL;
130 /* Reset display-name if the user provided his own X11 display */
131 if (!display->priv->create_display)
132 set_display_name(display, XDisplayString(display->priv->x11_display));
134 parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
135 if (parent_class->constructed)
136 parent_class->constructed(object);
140 gst_vaapi_display_x11_open_display(GstVaapiDisplay *display)
142 GstVaapiDisplayX11Private * const priv =
143 GST_VAAPI_DISPLAY_X11(display)->priv;
145 /* XXX: maintain an X11 display cache */
146 if (!priv->x11_display && priv->create_display)
147 priv->x11_display = XOpenDisplay(priv->display_name);
148 if (!priv->x11_display)
151 priv->x11_screen = DefaultScreen(priv->x11_display);
152 priv->va_display = vaGetDisplay(priv->x11_display);
153 return priv->va_display != NULL;
157 gst_vaapi_display_x11_close_display(GstVaapiDisplay *display)
159 GstVaapiDisplayX11Private * const priv =
160 GST_VAAPI_DISPLAY_X11(display)->priv;
162 if (priv->x11_display) {
163 if (priv->create_display)
164 XCloseDisplay(priv->x11_display);
165 priv->x11_display = NULL;
168 if (priv->display_name) {
169 g_free(priv->display_name);
170 priv->display_name = NULL;
173 priv->va_display = NULL;
177 gst_vaapi_display_x11_get_va_display(GstVaapiDisplay *display)
179 return GST_VAAPI_DISPLAY_X11(display)->priv->va_display;
183 gst_vaapi_display_x11_get_size(
184 GstVaapiDisplay *display,
189 GstVaapiDisplayX11Private * const priv = GST_VAAPI_DISPLAY_X11(display)->priv;
191 if (!priv->x11_display)
195 *pwidth = DisplayWidth(priv->x11_display, priv->x11_screen);
198 *pheight = DisplayHeight(priv->x11_display, priv->x11_screen);
202 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
204 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
205 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
207 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
209 object_class->finalize = gst_vaapi_display_x11_finalize;
210 object_class->set_property = gst_vaapi_display_x11_set_property;
211 object_class->get_property = gst_vaapi_display_x11_get_property;
212 object_class->constructed = gst_vaapi_display_x11_constructed;
214 dpy_class->open_display = gst_vaapi_display_x11_open_display;
215 dpy_class->close_display = gst_vaapi_display_x11_close_display;
216 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
217 dpy_class->get_size = gst_vaapi_display_x11_get_size;
220 * GstVaapiDisplayX11:x11-display:
222 * The X11 #Display that was created by gst_vaapi_display_x11_new()
223 * or that was bound from gst_vaapi_display_x11_new_with_display().
225 g_object_class_install_property
228 g_param_spec_pointer("x11-display",
231 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
234 * GstVaapiDisplayX11:display-name:
236 * The X11 display name.
238 g_object_class_install_property
241 g_param_spec_string("display-name",
245 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
249 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
251 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
253 display->priv = priv;
254 priv->create_display = TRUE;
255 priv->x11_display = NULL;
256 priv->x11_screen = 0;
257 priv->display_name = NULL;
261 * gst_vaapi_display_x11_new:
262 * @display_name: the X11 display name
264 * Opens an X11 #Display using @display_name and returns a newly
265 * allocated #GstVaapiDisplay object. The X11 display will be cloed
266 * when the reference count of the object reaches zero.
268 * Return value: a newly allocated #GstVaapiDisplay object
271 gst_vaapi_display_x11_new(const gchar *display_name)
273 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
274 "display-name", display_name,
279 * gst_vaapi_display_x11_new_with_display:
280 * @x11_display: an X11 #Display
282 * Creates a #GstVaapiDisplay based on the X11 @x11_display
283 * display. The caller still owns the display and must call
284 * XCloseDisplay() when all #GstVaapiDisplay references are
285 * released. Doing so too early can yield undefined behaviour.
287 * Return value: a newly allocated #GstVaapiDisplay object
290 gst_vaapi_display_x11_new_with_display(Display *x11_display)
292 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
293 "x11-display", x11_display,
298 * gst_vaapi_display_x11_get_display:
299 * @display: a #GstVaapiDisplayX11
301 * Returns the underlying X11 #Display that was created by
302 * gst_vaapi_display_x11_new() or that was bound from
303 * gst_vaapi_display_x11_new_with_display().
305 * Return value: the X11 #Display attached to @display
308 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
310 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
312 return display->priv->x11_display;