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 =
190 GST_VAAPI_DISPLAY_X11(display)->priv;
192 if (!priv->x11_display)
196 *pwidth = DisplayWidth(priv->x11_display, priv->x11_screen);
199 *pheight = DisplayHeight(priv->x11_display, priv->x11_screen);
203 gst_vaapi_display_x11_get_size_mm(
204 GstVaapiDisplay *display,
209 GstVaapiDisplayX11Private * const priv =
210 GST_VAAPI_DISPLAY_X11(display)->priv;
212 if (!priv->x11_display)
216 *pwidth = DisplayWidthMM(priv->x11_display, priv->x11_screen);
219 *pheight = DisplayHeightMM(priv->x11_display, priv->x11_screen);
223 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
225 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
226 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
228 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
230 object_class->finalize = gst_vaapi_display_x11_finalize;
231 object_class->set_property = gst_vaapi_display_x11_set_property;
232 object_class->get_property = gst_vaapi_display_x11_get_property;
233 object_class->constructed = gst_vaapi_display_x11_constructed;
235 dpy_class->open_display = gst_vaapi_display_x11_open_display;
236 dpy_class->close_display = gst_vaapi_display_x11_close_display;
237 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
238 dpy_class->get_size = gst_vaapi_display_x11_get_size;
239 dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm;
242 * GstVaapiDisplayX11:x11-display:
244 * The X11 #Display that was created by gst_vaapi_display_x11_new()
245 * or that was bound from gst_vaapi_display_x11_new_with_display().
247 g_object_class_install_property
250 g_param_spec_pointer("x11-display",
253 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
256 * GstVaapiDisplayX11:display-name:
258 * The X11 display name.
260 g_object_class_install_property
263 g_param_spec_string("display-name",
267 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
271 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
273 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
275 display->priv = priv;
276 priv->create_display = TRUE;
277 priv->x11_display = NULL;
278 priv->x11_screen = 0;
279 priv->display_name = NULL;
283 * gst_vaapi_display_x11_new:
284 * @display_name: the X11 display name
286 * Opens an X11 #Display using @display_name and returns a newly
287 * allocated #GstVaapiDisplay object. The X11 display will be cloed
288 * when the reference count of the object reaches zero.
290 * Return value: a newly allocated #GstVaapiDisplay object
293 gst_vaapi_display_x11_new(const gchar *display_name)
295 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
296 "display-name", display_name,
301 * gst_vaapi_display_x11_new_with_display:
302 * @x11_display: an X11 #Display
304 * Creates a #GstVaapiDisplay based on the X11 @x11_display
305 * display. The caller still owns the display and must call
306 * XCloseDisplay() when all #GstVaapiDisplay references are
307 * released. Doing so too early can yield undefined behaviour.
309 * Return value: a newly allocated #GstVaapiDisplay object
312 gst_vaapi_display_x11_new_with_display(Display *x11_display)
314 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
315 "x11-display", x11_display,
320 * gst_vaapi_display_x11_get_display:
321 * @display: a #GstVaapiDisplayX11
323 * Returns the underlying X11 #Display that was created by
324 * gst_vaapi_display_x11_new() or that was bound from
325 * gst_vaapi_display_x11_new_with_display().
327 * Return value: the X11 #Display attached to @display
330 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
332 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
334 return display->priv->x11_display;