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;
46 VADisplay *va_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->va_display = vaGetDisplay(priv->x11_display);
151 return priv->va_display != NULL;
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;
171 priv->va_display = NULL;
175 gst_vaapi_display_x11_get_va_display(GstVaapiDisplay *display)
177 return GST_VAAPI_DISPLAY_X11(display)->priv->va_display;
181 gst_vaapi_display_x11_class_init(GstVaapiDisplayX11Class *klass)
183 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
184 GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
186 g_type_class_add_private(klass, sizeof(GstVaapiDisplayX11Private));
188 object_class->finalize = gst_vaapi_display_x11_finalize;
189 object_class->set_property = gst_vaapi_display_x11_set_property;
190 object_class->get_property = gst_vaapi_display_x11_get_property;
191 object_class->constructed = gst_vaapi_display_x11_constructed;
193 dpy_class->open_display = gst_vaapi_display_x11_open_display;
194 dpy_class->close_display = gst_vaapi_display_x11_close_display;
195 dpy_class->get_display = gst_vaapi_display_x11_get_va_display;
198 * GstVaapiDisplayX11:x11-display:
200 * The X11 #Display that was created by gst_vaapi_display_x11_new()
201 * or that was bound from gst_vaapi_display_x11_new_with_display().
203 g_object_class_install_property
206 g_param_spec_pointer("x11-display",
209 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
212 * GstVaapiDisplayX11:display-name:
214 * The X11 display name.
216 g_object_class_install_property
219 g_param_spec_string("display-name",
223 G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
227 gst_vaapi_display_x11_init(GstVaapiDisplayX11 *display)
229 GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
231 display->priv = priv;
232 priv->create_display = TRUE;
233 priv->x11_display = NULL;
234 priv->display_name = NULL;
238 * gst_vaapi_display_x11_new:
239 * @display_name: the X11 display name
241 * Opens an X11 #Display using @display_name and returns a newly
242 * allocated #GstVaapiDisplay object. The X11 display will be cloed
243 * when the reference count of the object reaches zero.
245 * Return value: a newly allocated #GstVaapiDisplay object
248 gst_vaapi_display_x11_new(const gchar *display_name)
250 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
251 "display-name", display_name,
256 * gst_vaapi_display_x11_new_with_display:
257 * @x11_display: an X11 #Display
259 * Creates a #GstVaapiDisplay based on the X11 @x11_display
260 * display. The caller still owns the display and must call
261 * XCloseDisplay() when all #GstVaapiDisplay references are
262 * released. Doing so too early can yield undefined behaviour.
264 * Return value: a newly allocated #GstVaapiDisplay object
267 gst_vaapi_display_x11_new_with_display(Display *x11_display)
269 return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
270 "x11-display", x11_display,
275 * gst_vaapi_display_x11_get_display:
276 * @display: a #GstVaapiDisplayX11
278 * Returns the underlying X11 #Display that was created by
279 * gst_vaapi_display_x11_new() or that was bound from
280 * gst_vaapi_display_x11_new_with_display().
282 * Return value: the X11 #Display attached to @display
285 gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
287 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
289 return display->priv->x11_display;