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:gstvaapidisplay_x11
23 * @short_description: VA/X11 display abstraction
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 {
46 guint create_display : 1;
47 guint synchronous : 1;
59 gst_vaapi_display_x11_finalize(GObject *object)
61 G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
65 set_display_name(GstVaapiDisplayX11 *display, const gchar *display_name)
67 GstVaapiDisplayX11Private * const priv = display->priv;
69 g_free(priv->display_name);
72 priv->display_name = g_strdup(display_name);
74 priv->display_name = NULL;
78 set_synchronous(GstVaapiDisplayX11 *display, gboolean synchronous)
80 GstVaapiDisplayX11Private * const priv = display->priv;
82 if (priv->synchronous != synchronous) {
83 priv->synchronous = synchronous;
84 if (priv->x11_display)
85 XSynchronize(priv->x11_display, synchronous);
90 gst_vaapi_display_x11_set_property(
97 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
100 case PROP_SYNCHRONOUS:
101 set_synchronous(display, g_value_get_boolean(value));
103 case PROP_DISPLAY_NAME:
104 set_display_name(display, g_value_get_string(value));
106 case PROP_X11_DISPLAY:
107 display->priv->x11_display = g_value_get_pointer(value);
110 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
116 gst_vaapi_display_x11_get_property(
123 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
126 case PROP_SYNCHRONOUS:
127 g_value_set_boolean(value, display->priv->synchronous);
129 case PROP_DISPLAY_NAME:
130 g_value_set_string(value, display->priv->display_name);
132 case PROP_X11_DISPLAY:
133 g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
136 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
142 gst_vaapi_display_x11_constructed(GObject *object)
144 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
145 GObjectClass *parent_class;
147 display->priv->create_display = display->priv->x11_display == NULL;
149 /* Reset display-name if the user provided his own X11 display */
150 if (!display->priv->create_display)
151 set_display_name(display, XDisplayString(display->priv->x11_display));
153 parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
154 if (parent_class->constructed)
155 parent_class->constructed(object);
159 gst_vaapi_display_x11_open_display(GstVaapiDisplay *display)
161 GstVaapiDisplayX11Private * const priv =
162 GST_VAAPI_DISPLAY_X11(display)->priv;
164 /* XXX: maintain an X11 display cache */
165 if (!priv->x11_display && priv->create_display)
166 priv->x11_display = XOpenDisplay(priv->display_name);
167 if (!priv->x11_display)
170 if (priv->synchronous)
171 XSynchronize(priv->x11_display, True);
173 priv->x11_screen = DefaultScreen(priv->x11_display);
178 gst_vaapi_display_x11_close_display(GstVaapiDisplay *display)
180 GstVaapiDisplayX11Private * const priv =
181 GST_VAAPI_DISPLAY_X11(display)->priv;
183 if (priv->x11_display) {
184 if (priv->create_display)
185 XCloseDisplay(priv->x11_display);
186 priv->x11_display = NULL;
189 if (priv->display_name) {
190 g_free(priv->display_name);
191 priv->display_name = NULL;
196 gst_vaapi_display_x11_sync(GstVaapiDisplay *display)
198 GstVaapiDisplayX11Private * const priv =
199 GST_VAAPI_DISPLAY_X11(display)->priv;
201 if (priv->x11_display)
202 XSync(priv->x11_display, False);
206 gst_vaapi_display_x11_flush(GstVaapiDisplay *display)
208 GstVaapiDisplayX11Private * const priv =
209 GST_VAAPI_DISPLAY_X11(display)->priv;
211 if (priv->x11_display)
212 XFlush(priv->x11_display);
216 gst_vaapi_display_x11_get_va_display(GstVaapiDisplay *display)
218 return vaGetDisplay(GST_VAAPI_DISPLAY_XDISPLAY(display));
222 gst_vaapi_display_x11_get_size(
223 GstVaapiDisplay *display,
228 GstVaapiDisplayX11Private * const priv =
229 GST_VAAPI_DISPLAY_X11(display)->priv;
231 if (!priv->x11_display)
235 *pwidth = DisplayWidth(priv->x11_display, priv->x11_screen);
238 *pheight = DisplayHeight(priv->x11_display, priv->x11_screen);
242 gst_vaapi_display_x11_get_size_mm(
243 GstVaapiDisplay *display,
248 GstVaapiDisplayX11Private * const priv =
249 GST_VAAPI_DISPLAY_X11(display)->priv;
251 if (!priv->x11_display)
255 *pwidth = DisplayWidthMM(priv->x11_display, priv->x11_screen);
258 *pheight = DisplayHeightMM(priv->x11_display, priv->x11_screen);
262 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
264 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
265 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
267 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
269 object_class->finalize = gst_vaapi_display_x11_finalize;
270 object_class->set_property = gst_vaapi_display_x11_set_property;
271 object_class->get_property = gst_vaapi_display_x11_get_property;
272 object_class->constructed = gst_vaapi_display_x11_constructed;
274 dpy_class->open_display = gst_vaapi_display_x11_open_display;
275 dpy_class->close_display = gst_vaapi_display_x11_close_display;
276 dpy_class->sync = gst_vaapi_display_x11_sync;
277 dpy_class->flush = gst_vaapi_display_x11_flush;
278 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
279 dpy_class->get_size = gst_vaapi_display_x11_get_size;
280 dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm;
283 * GstVaapiDisplayX11:synchronous:
285 * When enabled, runs the X display in synchronous mode. Note that
286 * this is used only for debugging.
288 g_object_class_install_property
291 g_param_spec_boolean("synchronous",
293 "Toggles X display synchronous mode",
298 * GstVaapiDisplayX11:x11-display:
300 * The X11 #Display that was created by gst_vaapi_display_x11_new()
301 * or that was bound from gst_vaapi_display_x11_new_with_display().
303 g_object_class_install_property
306 g_param_spec_pointer("x11-display",
309 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
312 * GstVaapiDisplayX11:display-name:
314 * The X11 display name.
316 g_object_class_install_property
319 g_param_spec_string("display-name",
323 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
327 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
329 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
331 display->priv = priv;
332 priv->create_display = TRUE;
333 priv->x11_display = NULL;
334 priv->x11_screen = 0;
335 priv->display_name = NULL;
339 * gst_vaapi_display_x11_new:
340 * @display_name: the X11 display name
342 * Opens an X11 #Display using @display_name and returns a newly
343 * allocated #GstVaapiDisplay object. The X11 display will be cloed
344 * when the reference count of the object reaches zero.
346 * Return value: a newly allocated #GstVaapiDisplay object
349 gst_vaapi_display_x11_new(const gchar *display_name)
351 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
352 "display-name", display_name,
357 * gst_vaapi_display_x11_new_with_display:
358 * @x11_display: an X11 #Display
360 * Creates a #GstVaapiDisplay based on the X11 @x11_display
361 * display. The caller still owns the display and must call
362 * XCloseDisplay() when all #GstVaapiDisplay references are
363 * released. Doing so too early can yield undefined behaviour.
365 * Return value: a newly allocated #GstVaapiDisplay object
368 gst_vaapi_display_x11_new_with_display(Display *x11_display)
370 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
371 "x11-display", x11_display,
376 * gst_vaapi_display_x11_get_display:
377 * @display: a #GstVaapiDisplayX11
379 * Returns the underlying X11 #Display that was created by
380 * gst_vaapi_display_x11_new() or that was bound from
381 * gst_vaapi_display_x11_new_with_display().
383 * Return value: the X11 #Display attached to @display
386 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
388 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
390 return display->priv->x11_display;