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 {
43 gboolean create_display;
57 gst_vaapi_display_x11_finalize(GObject *object)
59 G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class)->finalize(object);
63 set_display_name(GstVaapiDisplayX11 *display, const gchar *display_name)
65 GstVaapiDisplayX11Private * const priv = display->priv;
67 g_free(priv->display_name);
70 priv->display_name = g_strdup(display_name);
72 priv->display_name = NULL;
76 gst_vaapi_display_x11_set_property(
83 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
86 case PROP_DISPLAY_NAME:
87 set_display_name(display, g_value_get_string(value));
89 case PROP_X11_DISPLAY:
90 display->priv->x11_display = g_value_get_pointer(value);
93 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
99 gst_vaapi_display_x11_get_property(
106 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
109 case PROP_DISPLAY_NAME:
110 g_value_set_string(value, display->priv->display_name);
112 case PROP_X11_DISPLAY:
113 g_value_set_pointer(value, gst_vaapi_display_x11_get_display(display));
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
122 gst_vaapi_display_x11_constructed(GObject *object)
124 GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
125 GObjectClass *parent_class;
127 display->priv->create_display = display->priv->x11_display == NULL;
129 /* Reset display-name if the user provided his own X11 display */
130 if (!display->priv->create_display)
131 set_display_name(display, XDisplayString(display->priv->x11_display));
133 parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
134 if (parent_class->constructed)
135 parent_class->constructed(object);
139 gst_vaapi_display_x11_open_display(GstVaapiDisplay *display)
141 GstVaapiDisplayX11Private * const priv =
142 GST_VAAPI_DISPLAY_X11(display)->priv;
144 /* XXX: maintain an X11 display cache */
145 if (!priv->x11_display && priv->create_display)
146 priv->x11_display = XOpenDisplay(priv->display_name);
147 if (!priv->x11_display)
150 priv->x11_screen = DefaultScreen(priv->x11_display);
155 gst_vaapi_display_x11_close_display(GstVaapiDisplay *display)
157 GstVaapiDisplayX11Private * const priv =
158 GST_VAAPI_DISPLAY_X11(display)->priv;
160 if (priv->x11_display) {
161 if (priv->create_display)
162 XCloseDisplay(priv->x11_display);
163 priv->x11_display = NULL;
166 if (priv->display_name) {
167 g_free(priv->display_name);
168 priv->display_name = NULL;
173 gst_vaapi_display_x11_get_va_display(GstVaapiDisplay *display)
175 return vaGetDisplay(GST_VAAPI_DISPLAY_XDISPLAY(display));
179 gst_vaapi_display_x11_get_size(
180 GstVaapiDisplay *display,
185 GstVaapiDisplayX11Private * const priv =
186 GST_VAAPI_DISPLAY_X11(display)->priv;
188 if (!priv->x11_display)
192 *pwidth = DisplayWidth(priv->x11_display, priv->x11_screen);
195 *pheight = DisplayHeight(priv->x11_display, priv->x11_screen);
199 gst_vaapi_display_x11_get_size_mm(
200 GstVaapiDisplay *display,
205 GstVaapiDisplayX11Private * const priv =
206 GST_VAAPI_DISPLAY_X11(display)->priv;
208 if (!priv->x11_display)
212 *pwidth = DisplayWidthMM(priv->x11_display, priv->x11_screen);
215 *pheight = DisplayHeightMM(priv->x11_display, priv->x11_screen);
219 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
221 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
222 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
224 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
226 object_class->finalize = gst_vaapi_display_x11_finalize;
227 object_class->set_property = gst_vaapi_display_x11_set_property;
228 object_class->get_property = gst_vaapi_display_x11_get_property;
229 object_class->constructed = gst_vaapi_display_x11_constructed;
231 dpy_class->open_display = gst_vaapi_display_x11_open_display;
232 dpy_class->close_display = gst_vaapi_display_x11_close_display;
233 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
234 dpy_class->get_size = gst_vaapi_display_x11_get_size;
235 dpy_class->get_size_mm = gst_vaapi_display_x11_get_size_mm;
238 * GstVaapiDisplayX11:x11-display:
240 * The X11 #Display that was created by gst_vaapi_display_x11_new()
241 * or that was bound from gst_vaapi_display_x11_new_with_display().
243 g_object_class_install_property
246 g_param_spec_pointer("x11-display",
249 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
252 * GstVaapiDisplayX11:display-name:
254 * The X11 display name.
256 g_object_class_install_property
259 g_param_spec_string("display-name",
263 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
267 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
269 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
271 display->priv = priv;
272 priv->create_display = TRUE;
273 priv->x11_display = NULL;
274 priv->x11_screen = 0;
275 priv->display_name = NULL;
279 * gst_vaapi_display_x11_new:
280 * @display_name: the X11 display name
282 * Opens an X11 #Display using @display_name and returns a newly
283 * allocated #GstVaapiDisplay object. The X11 display will be cloed
284 * when the reference count of the object reaches zero.
286 * Return value: a newly allocated #GstVaapiDisplay object
289 gst_vaapi_display_x11_new(const gchar *display_name)
291 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
292 "display-name", display_name,
297 * gst_vaapi_display_x11_new_with_display:
298 * @x11_display: an X11 #Display
300 * Creates a #GstVaapiDisplay based on the X11 @x11_display
301 * display. The caller still owns the display and must call
302 * XCloseDisplay() when all #GstVaapiDisplay references are
303 * released. Doing so too early can yield undefined behaviour.
305 * Return value: a newly allocated #GstVaapiDisplay object
308 gst_vaapi_display_x11_new_with_display(Display *x11_display)
310 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
311 "x11-display", x11_display,
316 * gst_vaapi_display_x11_get_display:
317 * @display: a #GstVaapiDisplayX11
319 * Returns the underlying X11 #Display that was created by
320 * gst_vaapi_display_x11_new() or that was bound from
321 * gst_vaapi_display_x11_new_with_display().
323 * Return value: the X11 #Display attached to @display
326 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
328 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
330 return display->priv->x11_display;