GstVaapiDisplayX11Private))
struct _GstVaapiDisplayX11Private {
+ gboolean create_display;
gchar *display_name;
Display *x11_display;
VADisplay *va_display;
case PROP_DISPLAY_NAME:
set_display_name(display, g_value_get_string(value));
break;
+ case PROP_X11_DISPLAY:
+ display->priv->x11_display = g_value_get_pointer(value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
+static void
+gst_vaapi_display_x11_constructed(GObject *object)
+{
+ GstVaapiDisplayX11 * const display = GST_VAAPI_DISPLAY_X11(object);
+ GObjectClass *parent_class;
+
+ display->priv->create_display = display->priv->x11_display == NULL;
+
+ parent_class = G_OBJECT_CLASS(gst_vaapi_display_x11_parent_class);
+ if (parent_class->constructed)
+ parent_class->constructed(object);
+}
+
static gboolean
gst_vaapi_display_x11_open_display(GstVaapiDisplay *display)
{
GST_VAAPI_DISPLAY_X11(display)->priv;
/* XXX: maintain an X11 display cache */
- priv->x11_display = XOpenDisplay(priv->display_name);
+ if (!priv->x11_display && priv->create_display)
+ priv->x11_display = XOpenDisplay(priv->display_name);
if (!priv->x11_display)
return FALSE;
GST_VAAPI_DISPLAY_X11(display)->priv;
if (priv->x11_display) {
- XCloseDisplay(priv->x11_display);
+ if (priv->create_display)
+ XCloseDisplay(priv->x11_display);
priv->x11_display = NULL;
}
object_class->finalize = gst_vaapi_display_x11_finalize;
object_class->set_property = gst_vaapi_display_x11_set_property;
object_class->get_property = gst_vaapi_display_x11_get_property;
+ object_class->constructed = gst_vaapi_display_x11_constructed;
dpy_class->open_display = gst_vaapi_display_x11_open_display;
dpy_class->close_display = gst_vaapi_display_x11_close_display;
g_param_spec_pointer("x11-display",
"X11 display",
"X11 display",
- G_PARAM_READABLE));
+ G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class,
{
GstVaapiDisplayX11Private *priv = GST_VAAPI_DISPLAY_X11_GET_PRIVATE(display);
- display->priv = priv;
- priv->x11_display = NULL;
- priv->display_name = NULL;
+ display->priv = priv;
+ priv->create_display = TRUE;
+ priv->x11_display = NULL;
+ priv->display_name = NULL;
}
GstVaapiDisplay *
NULL);
}
+GstVaapiDisplay *
+gst_vaapi_display_x11_new_with_display(Display *x11_display)
+{
+ return g_object_new(GST_VAAPI_TYPE_DISPLAY_X11,
+ "x11-display", x11_display,
+ NULL);
+}
+
Display *
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
{
}
}
-int
-main(int argc, char *argv[])
+static void
+dump_caps(GstVaapiDisplay *display)
{
- GstVaapiDisplay *display;
GstCaps *caps;
- gst_init(&argc, &argv);
-
- display = gst_vaapi_display_x11_new(NULL);
- if (!display)
- g_error("could not create VA-API display");
-
caps = gst_vaapi_display_get_image_caps(display);
if (!caps)
g_error("could not get VA image caps");
print_caps(caps, "subpicture");
gst_caps_unref(caps);
+}
+
+int
+main(int argc, char *argv[])
+{
+ Display *x11_display;
+ VADisplay va_display;
+ GstVaapiDisplay *display;
+
+ gst_init(&argc, &argv);
+
+ g_print("#\n");
+ g_print("# Create display with gst_vaapi_display_x11_new()\n");
+ g_print("#\n");
+ {
+ display = gst_vaapi_display_x11_new(NULL);
+ if (!display)
+ g_error("could not create Gst/VA display");
+
+ dump_caps(display);
+ g_object_unref(display);
+ }
+ g_print("\n");
+
+ g_print("#\n");
+ g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
+ g_print("#\n");
+ {
+ x11_display = XOpenDisplay(NULL);
+ if (!x11_display)
+ g_error("could not create X11 display");
+
+ display = gst_vaapi_display_x11_new_with_display(x11_display);
+ if (!display)
+ g_error("could not create Gst/VA display");
+
+ dump_caps(display);
+ g_object_unref(display);
+ XCloseDisplay(x11_display);
+ }
+ g_print("\n");
+
+ g_print("#\n");
+ g_print("# Create display with gst_vaapi_display_new_with_display()\n");
+ g_print("#\n");
+ {
+ x11_display = XOpenDisplay(NULL);
+ if (!x11_display)
+ g_error("could not create X11 display");
+
+ va_display = vaGetDisplay(x11_display);
+ if (!va_display)
+ g_error("could not create VA display");
+
+ display = gst_vaapi_display_new_with_display(va_display);
+ if (!display)
+ g_error("could not create Gst/VA display");
+
+ dump_caps(display);
+ g_object_unref(display);
+ XCloseDisplay(x11_display);
+ }
+ g_print("\n");
- g_object_unref(display);
gst_deinit();
return 0;
}