Make it possible to bin an X11 window to GstVaapiWindowX11 with plain
authorgb <gb@5584edef-b1fe-4b99-b61b-dd2bab72e969>
Thu, 18 Mar 2010 13:49:50 +0000 (13:49 +0000)
committergb <gb@5584edef-b1fe-4b99-b61b-dd2bab72e969>
Thu, 18 Mar 2010 13:49:50 +0000 (13:49 +0000)
g_object_new() and "xid" property. i.e. get foreign window size in
gst_vaapi_window_x11_create().

gst-libs/gst/vaapi/gstvaapiwindow.c
gst-libs/gst/vaapi/gstvaapiwindow.h
gst-libs/gst/vaapi/gstvaapiwindow_x11.c

index 191cbf5..d927ad3 100644 (file)
@@ -51,12 +51,23 @@ gst_vaapi_window_destroy(GstVaapiWindow *window)
 }
 
 static gboolean
-gst_vaapi_window_create(GstVaapiWindow *window, guint width, guint height)
+gst_vaapi_window_create(GstVaapiWindow *window)
 {
-    if (width == 0 || height == 0)
+    GstVaapiWindowPrivate * const priv = window->priv;
+    guint width, height;
+
+    width  = priv->width;
+    height = priv->height;
+
+    if (!GST_VAAPI_WINDOW_GET_CLASS(window)->create(window, &width, &height))
         return FALSE;
 
-    return GST_VAAPI_WINDOW_GET_CLASS(window)->create(window, width, height);
+    if (width != priv->width || height != priv->height) {
+        GST_DEBUG("backend resized window to %ux%u", width, height);
+        priv->width  = width;
+        priv->height = height;
+    }
+    return TRUE;
 }
 
 static void
@@ -119,11 +130,7 @@ gst_vaapi_window_constructed(GObject *object)
     GstVaapiWindow * const window = GST_VAAPI_WINDOW(object);
     GObjectClass *parent_class;
 
-    window->priv->is_constructed = gst_vaapi_window_create(
-        window,
-        window->priv->width,
-        window->priv->height
-    );
+    window->priv->is_constructed = gst_vaapi_window_create(window);
 
     parent_class = G_OBJECT_CLASS(gst_vaapi_window_parent_class);
     if (parent_class->constructed)
index 1095f7a..7c2fb56 100644 (file)
@@ -78,7 +78,7 @@ struct _GstVaapiWindowClass {
     /*< private >*/
     GObjectClass parent_class;
 
-    gboolean    (*create) (GstVaapiWindow *window, guint width, guint height);
+    gboolean    (*create) (GstVaapiWindow *window, guint *width, guint *height);
     void        (*destroy)(GstVaapiWindow *window);
     gboolean    (*show)   (GstVaapiWindow *window);
     gboolean    (*hide)   (GstVaapiWindow *window);
index 58fe7f9..1063920 100644 (file)
@@ -96,18 +96,21 @@ gst_vaapi_window_x11_hide(GstVaapiWindow *window)
 }
 
 static gboolean
-gst_vaapi_window_x11_create(GstVaapiWindow *window, guint width, guint height)
+gst_vaapi_window_x11_create(GstVaapiWindow *window, guint *width, guint *height)
 {
     GstVaapiWindowX11Private * const priv = GST_VAAPI_WINDOW_X11(window)->priv;
-    Display *dpy;
-
-    if (!priv->create_window && priv->xid)
-        return TRUE;
+    Display * const dpy = GST_VAAPI_DISPLAY_XDISPLAY(priv->display);
+    gboolean ok;
 
-    dpy = GST_VAAPI_DISPLAY_XDISPLAY(priv->display);
+    if (!priv->create_window && priv->xid) {
+        GST_VAAPI_DISPLAY_LOCK(priv->display);
+        ok = x11_get_geometry(dpy, priv->xid, NULL, NULL, width, height);
+        GST_VAAPI_DISPLAY_UNLOCK(priv->display);
+        return ok;
+    }
 
     GST_VAAPI_DISPLAY_LOCK(priv->display);
-    priv->xid = x11_create_window(dpy, width, height);
+    priv->xid = x11_create_window(dpy, *width, *height);
     if (priv->xid)
         XRaiseWindow(dpy, priv->xid);
     GST_VAAPI_DISPLAY_UNLOCK(priv->display);
@@ -349,22 +352,14 @@ gst_vaapi_window_x11_new(GstVaapiDisplay *display, guint width, guint height)
 GstVaapiWindow *
 gst_vaapi_window_x11_new_with_xid(GstVaapiDisplay *display, Window xid)
 {
-    Display *dpy;
-    guint width, height;
-
     GST_DEBUG("new window from xid 0x%08x", xid);
 
     g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
-
-    dpy = GST_VAAPI_DISPLAY_XDISPLAY(display);
-    if (!dpy || !x11_get_geometry(dpy, xid, NULL, NULL, &width, &height))
-        return NULL;
+    g_return_val_if_fail(xid != None, NULL);
 
     return g_object_new(GST_VAAPI_TYPE_WINDOW_X11,
                         "display", display,
                         "xid",     xid,
-                        "width",   width,
-                        "height",  height,
                         NULL);
 }