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_get_va_display(GstVaapiDisplay *display)
198 return vaGetDisplay(GST_VAAPI_DISPLAY_XDISPLAY(display));
202 gst_vaapi_display_x11_get_size(
203 GstVaapiDisplay *display,
208 GstVaapiDisplayX11Private * const priv =
209 GST_VAAPI_DISPLAY_X11(display)->priv;
211 if (!priv->x11_display)
215 *pwidth = DisplayWidth(priv->x11_display, priv->x11_screen);
218 *pheight = DisplayHeight(priv->x11_display, priv->x11_screen);
222 gst_vaapi_display_x11_get_size_mm(
223 GstVaapiDisplay *display,
228 GstVaapiDisplayX11Private * const priv =
229 GST_VAAPI_DISPLAY_X11(display)->priv;
231 if (!priv->x11_display)
235 *pwidth = DisplayWidthMM(priv->x11_display, priv->x11_screen);
238 *pheight = DisplayHeightMM(priv->x11_display, priv->x11_screen);
242 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
244 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
245 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
247 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
249 object_class->finalize = gst_vaapi_display_x11_finalize;
250 object_class->set_property = gst_vaapi_display_x11_set_property;
251 object_class->get_property = gst_vaapi_display_x11_get_property;
252 object_class->constructed = gst_vaapi_display_x11_constructed;
254 dpy_class->open_display = gst_vaapi_display_x11_open_display;
255 dpy_class->close_display = gst_vaapi_display_x11_close_display;
256 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
257 dpy_class->get_size = gst_vaapi_display_x11_get_size;
258 dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm;
261 * GstVaapiDisplayX11:synchronous:
263 * When enabled, runs the X display in synchronous mode. Note that
264 * this is used only for debugging.
266 g_object_class_install_property
269 g_param_spec_boolean("synchronous",
271 "Toggles X display synchronous mode",
276 * GstVaapiDisplayX11:x11-display:
278 * The X11 #Display that was created by gst_vaapi_display_x11_new()
279 * or that was bound from gst_vaapi_display_x11_new_with_display().
281 g_object_class_install_property
284 g_param_spec_pointer("x11-display",
287 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
290 * GstVaapiDisplayX11:display-name:
292 * The X11 display name.
294 g_object_class_install_property
297 g_param_spec_string("display-name",
301 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
305 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
307 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
309 display->priv = priv;
310 priv->create_display = TRUE;
311 priv->x11_display = NULL;
312 priv->x11_screen = 0;
313 priv->display_name = NULL;
317 * gst_vaapi_display_x11_new:
318 * @display_name: the X11 display name
320 * Opens an X11 #Display using @display_name and returns a newly
321 * allocated #GstVaapiDisplay object. The X11 display will be cloed
322 * when the reference count of the object reaches zero.
324 * Return value: a newly allocated #GstVaapiDisplay object
327 gst_vaapi_display_x11_new(const gchar *display_name)
329 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
330 "display-name", display_name,
335 * gst_vaapi_display_x11_new_with_display:
336 * @x11_display: an X11 #Display
338 * Creates a #GstVaapiDisplay based on the X11 @x11_display
339 * display. The caller still owns the display and must call
340 * XCloseDisplay() when all #GstVaapiDisplay references are
341 * released. Doing so too early can yield undefined behaviour.
343 * Return value: a newly allocated #GstVaapiDisplay object
346 gst_vaapi_display_x11_new_with_display(Display *x11_display)
348 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
349 "x11-display", x11_display,
354 * gst_vaapi_display_x11_get_display:
355 * @display: a #GstVaapiDisplayX11
357 * Returns the underlying X11 #Display that was created by
358 * gst_vaapi_display_x11_new() or that was bound from
359 * gst_vaapi_display_x11_new_with_display().
361 * Return value: the X11 #Display attached to @display
364 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
366 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
368 return display->priv->x11_display;