sys/ximage/ximagesink.*: assorted fixes to make (re)embedding work
authorBenjamin Otte <otte@gnome.org>
Sun, 4 Jan 2004 18:53:53 +0000 (18:53 +0000)
committerBenjamin Otte <otte@gnome.org>
Sun, 4 Jan 2004 18:53:53 +0000 (18:53 +0000)
Original commit message from CVS:
2004-01-04  Benjamin Otte  <in7y118@public.uni-hamburg.de>

* sys/ximage/ximagesink.h:
* sys/ximage/ximagesink.c: (gst_ximagesink_xwindow_new),
(gst_ximagesink_xwindow_destroy), (gst_ximagesink_sinkconnect),
(gst_ximagesink_change_state), (gst_ximagesink_set_xwindow_id),
(gst_ximagesink_xoverlay_init):
assorted fixes to make (re)embedding work
* sys/ximage/ximagesink.c: (gst_ximagesink_sinkconnect),
(gst_ximagesink_get_desired_size):
implement desired size additions to XOverlay

ChangeLog
sys/ximage/ximagesink.c
sys/ximage/ximagesink.h

index 86cc7f8..314f394 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2004-01-04  Benjamin Otte  <in7y118@public.uni-hamburg.de>
 
+       * sys/ximage/ximagesink.h:
+       * sys/ximage/ximagesink.c: (gst_ximagesink_xwindow_new),
+       (gst_ximagesink_xwindow_destroy), (gst_ximagesink_sinkconnect),
+       (gst_ximagesink_change_state), (gst_ximagesink_set_xwindow_id),
+       (gst_ximagesink_xoverlay_init):
+         assorted fixes to make (re)embedding work
+       * sys/ximage/ximagesink.c: (gst_ximagesink_sinkconnect),
+       (gst_ximagesink_get_desired_size):
+         implement desired size additions to XOverlay
+
+2004-01-04  Benjamin Otte  <in7y118@public.uni-hamburg.de>
+
        * gst-libs/gst/xoverlay/xoverlay.c: (gst_x_overlay_base_init),
        (gst_x_overlay_got_xwindow_id), (gst_x_overlay_get_desired_size),
        (gst_x_overlay_got_desired_size):
index 8891665..64463b4 100644 (file)
@@ -216,15 +216,19 @@ gst_ximagesink_xwindow_new (GstXImageSink *ximagesink, gint width, gint height)
   
   xwindow->width = width;
   xwindow->height = height;
-  xwindow->internal = TRUE;
   
   g_mutex_lock (ximagesink->x_lock);
   
-  xwindow->win = XCreateSimpleWindow (ximagesink->xcontext->disp,
-                                      ximagesink->xcontext->root, 
-                                      0, 0, xwindow->width, xwindow->height, 
-                                      0, 0, ximagesink->xcontext->black);
-  
+  if (ximagesink->embed_into == 0) {
+    xwindow->win = XCreateSimpleWindow (ximagesink->xcontext->disp,
+                                        ximagesink->xcontext->root, 
+                                       0, 0, xwindow->width, xwindow->height, 
+                                       0, 0, ximagesink->xcontext->black);
+    
+    XMapRaised (ximagesink->xcontext->disp, xwindow->win);
+  } else {
+    xwindow->win = ximagesink->embed_into;
+  }
   XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
                 StructureNotifyMask | PointerMotionMask | KeyPressMask |
                 KeyReleaseMask | ButtonPressMask | ButtonReleaseMask);
@@ -232,7 +236,6 @@ gst_ximagesink_xwindow_new (GstXImageSink *ximagesink, gint width, gint height)
   xwindow->gc = XCreateGC (ximagesink->xcontext->disp,
                            xwindow->win, 0, NULL);
   
-  XMapRaised (ximagesink->xcontext->disp, xwindow->win);
   
   g_mutex_unlock (ximagesink->x_lock);
   
@@ -250,9 +253,12 @@ gst_ximagesink_xwindow_destroy (GstXImageSink *ximagesink, GstXWindow *xwindow)
   g_mutex_lock (ximagesink->x_lock);
   
   /* If we did not create that window we just free the GC and let it live */
-  if (xwindow->internal)
+  if (ximagesink->embed_into == 0) {
     XDestroyWindow (ximagesink->xcontext->disp, xwindow->win);
-  
+  } else {
+    XSelectInput (ximagesink->xcontext->disp, xwindow->win, 0);
+  }
+    
   XFreeGC (ximagesink->xcontext->disp, xwindow->gc);
   
   g_mutex_unlock (ximagesink->x_lock);
@@ -609,6 +615,9 @@ gst_ximagesink_sinkconnect (GstPad *pad, const GstCaps *caps)
                                              GST_VIDEOSINK_WIDTH (ximagesink),
                                              GST_VIDEOSINK_HEIGHT (ximagesink));
   
+  gst_x_overlay_got_desired_size (GST_X_OVERLAY (ximagesink),
+                                 GST_VIDEOSINK_WIDTH (ximagesink),
+                                 GST_VIDEOSINK_HEIGHT (ximagesink));
   gst_video_sink_got_video_size (GST_VIDEOSINK (ximagesink),
                                  GST_VIDEOSINK_WIDTH (ximagesink),
                                  GST_VIDEOSINK_HEIGHT (ximagesink));
@@ -638,6 +647,8 @@ gst_ximagesink_change_state (GstElement *element)
     case GST_STATE_PLAYING_TO_PAUSED:
       break;
     case GST_STATE_PAUSED_TO_READY:
+      GST_VIDEOSINK_WIDTH (ximagesink) = 0;
+      GST_VIDEOSINK_HEIGHT (ximagesink) = 0;
       break;
     case GST_STATE_READY_TO_NULL:
       break;
@@ -880,12 +891,13 @@ static void
 gst_ximagesink_set_xwindow_id (GstXOverlay *overlay, XID xwindow_id)
 {
   GstXImageSink *ximagesink = GST_XIMAGESINK (overlay);
-  GstXWindow *xwindow = NULL;
-  XWindowAttributes attr;
   
   g_return_if_fail (ximagesink != NULL);
   g_return_if_fail (GST_IS_XIMAGESINK (ximagesink));
   
+  if (ximagesink->embed_into == xwindow_id)
+    return;
+  
   if (!ximagesink->xcontext)
     {
       ximagesink->xcontext = gst_ximagesink_xcontext_get (ximagesink);
@@ -899,31 +911,28 @@ gst_ximagesink_set_xwindow_id (GstXOverlay *overlay, XID xwindow_id)
       gst_ximagesink_xwindow_destroy (ximagesink, ximagesink->xwindow);
     }
     
-  xwindow = g_new0 (GstXWindow, 1);
-  
-  xwindow->win = xwindow_id;
-  
-  /* We get window geometry, set the event we want to receive, and create a GC */
-  g_mutex_lock (ximagesink->x_lock);
-  XGetWindowAttributes (ximagesink->xcontext->disp, xwindow->win, &attr);
-  xwindow->width = attr.width;
-  xwindow->height = attr.height;
-  xwindow->internal = FALSE;
-  XSelectInput (ximagesink->xcontext->disp, xwindow->win, ExposureMask |
-                StructureNotifyMask | PointerMotionMask | KeyPressMask |
-                KeyReleaseMask);
+  ximagesink->embed_into = xwindow_id;
   
-  xwindow->gc = XCreateGC (ximagesink->xcontext->disp,
-                           xwindow->win, 0, NULL);
-  g_mutex_unlock (ximagesink->x_lock);
-    
-  ximagesink->xwindow = xwindow;
+  ximagesink->xwindow = gst_ximagesink_xwindow_new (ximagesink, GST_VIDEOSINK_WIDTH (ximagesink), GST_VIDEOSINK_HEIGHT (ximagesink));
+  ximagesink->ximage = gst_ximagesink_ximage_new (ximagesink, 
+      GST_VIDEOSINK_WIDTH (ximagesink), GST_VIDEOSINK_HEIGHT (ximagesink));
+  gst_x_overlay_got_xwindow_id (overlay, xwindow_id);
+}
+
+static void
+gst_ximagesink_get_desired_size (GstXOverlay *overlay, guint *width, guint *height)
+{
+  GstXImageSink *ximagesink = GST_XIMAGESINK (overlay);
+
+  *width = GST_VIDEOSINK_WIDTH (ximagesink);
+  *height = GST_VIDEOSINK_HEIGHT (ximagesink);
 }
 
 static void
 gst_ximagesink_xoverlay_init (GstXOverlayClass *iface)
 {
   iface->set_xwindow_id = gst_ximagesink_set_xwindow_id;
+  iface->get_desired_size = gst_ximagesink_get_desired_size;
 }
 
 /* =========================================== */
index f88a3fe..ad292a9 100644 (file)
@@ -83,7 +83,6 @@ struct _GstXContext {
 struct _GstXWindow {
   Window win;
   gint width, height;
-  gboolean internal;
   GC gc;
 };
 
@@ -102,6 +101,8 @@ struct _GstXImage {
 struct _GstXImageSink {
   /* Our element stuff */
   GstVideoSink videosink;
+
+  XID embed_into;
   
   GstXContext *xcontext;
   GstXWindow *xwindow;