[PATCH spice-gtk 2/3] fixup! Gstreamer: Control GstVideoOverlay from the widget

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/channel-display.c   |  2 ++
 src/spice-widget-priv.h |  3 +--
 src/spice-widget.c      | 51 ++++++++++++++++-------------------------
 3 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/src/channel-display.c b/src/channel-display.c
index 6b6a172c..e63fb3bb 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -29,7 +29,9 @@
 #include "spice-session-priv.h"
 #include "channel-display-priv.h"
 #include "decode.h"
+#ifdef HAVE_GSTVIDEO
 #include "gst/gst.h"
+#endif
 
 /**
  * SECTION:channel-display
diff --git a/src/spice-widget-priv.h b/src/spice-widget-priv.h
index 651d306e..0264577d 100644
--- a/src/spice-widget-priv.h
+++ b/src/spice-widget-priv.h
@@ -154,8 +154,7 @@ struct _SpiceDisplayPrivate {
 #endif // HAVE_EGL
     double scroll_delta_y;
 #ifdef HAVE_GSTVIDEO
-    GWeakRef                overlay_element_weak_ref;
-    GstPipeline             *pipeline;
+    GWeakRef overlay_weak_ref;
 #endif
 };
 
diff --git a/src/spice-widget.c b/src/spice-widget.c
index ae834204..e78fab4c 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -2119,14 +2119,12 @@ static void unrealize(GtkWidget *widget)
 
     spice_cairo_image_destroy(display);
 #if HAVE_EGL
-    if (display->priv->egl.context_ready)
+    if (display->priv->egl.context_ready) {
         spice_egl_unrealize_display(display);
+    }
 #endif
 #ifdef HAVE_GSTVIDEO
-    SpiceDisplayPrivate *d = display->priv;
-
-    g_weak_ref_set(&d->overlay_element_weak_ref, NULL);
-    g_clear_weak_pointer(&d->pipeline);
+    g_weak_ref_set(&display->priv->overlay_weak_ref, NULL);
 #endif
 
     GTK_WIDGET_CLASS(spice_display_parent_class)->unrealize(widget);
@@ -2556,27 +2554,23 @@ static void queue_draw_area(SpiceDisplay *display, gint x, gint y,
 }
 
 #if defined(HAVE_GSTVIDEO) && defined(GDK_WINDOWING_X11)
-static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, gpointer data)
+static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, SpiceDisplay *display)
 {
     switch(GST_MESSAGE_TYPE(msg)) {
     case GST_MESSAGE_ELEMENT: {
-        if (gst_is_video_overlay_prepare_window_handle_message(msg)) {
-            if (!g_getenv("DISABLE_GSTVIDEOOVERLAY") &&
-                GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
-                SpiceDisplay *display = data;
-                GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
-
-                if (window && gdk_window_ensure_native(window)) {
-                    SpiceDisplayPrivate *d = display->priv;
-                    GstElement *overlay_element;
-
-                    g_weak_ref_set(&d->overlay_element_weak_ref, GST_ELEMENT(GST_MESSAGE_SRC(msg)));
-                    overlay_element = g_weak_ref_get(&d->overlay_element_weak_ref);
-                    gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(overlay_element), (uintptr_t)GDK_WINDOW_XID(window));
-                    gst_video_overlay_handle_events(GST_VIDEO_OVERLAY(overlay_element), false);
-                    gst_object_unref(overlay_element);
-                    return;
-                }
+        if (gst_is_video_overlay_prepare_window_handle_message(msg) &&
+            !g_getenv("DISABLE_GSTVIDEOOVERLAY") &&
+            GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
+            GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
+
+            if (window && gdk_window_ensure_native(window)) {
+                SpiceDisplayPrivate *d = display->priv;
+
+                GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(msg));
+                g_weak_ref_set(&d->overlay_weak_ref, overlay);
+                gst_video_overlay_set_window_handle(overlay, (uintptr_t)GDK_WINDOW_XID(window));
+                gst_video_overlay_handle_events(overlay, false);
+                return;
             }
         }
         break;
@@ -2588,15 +2582,12 @@ static void gst_sync_bus_call(GstBus *bus, GstMessage *msg, gpointer data)
 }
 #endif
 
-{
-#ifdef GDK_WINDOWING_X11
 /* This callback should pass to the widget a pointer of the pipeline
  * so that we can set pipeline and overlay related calls from here.
  */
-static gboolean set_overlay(SpiceChannel *channel, void* pipeline_ptr, gpointer data)
+static gboolean set_overlay(SpiceChannel *channel, void* pipeline_ptr, SpiceDisplay *display)
 {
 #if defined(HAVE_GSTVIDEO) && defined(GDK_WINDOWING_X11)
-    SpiceDisplay *display = data;
     SpiceDisplayPrivate *d = display->priv;
 
     /* GstVideoOverlay is currently used only under x */
@@ -2609,11 +2600,9 @@ static gboolean set_overlay(SpiceChannel *channel, void* pipeline_ptr, gpointer
             GstBus *bus;
 
             gtk_stack_set_visible_child_name(d->stack, "gst-area");
-            d->pipeline = pipeline_ptr;
-            g_object_add_weak_pointer(pipeline_ptr, (gpointer*)&(d->pipeline)); // Taking a weak ref although pipeline is not used again
-            bus = gst_pipeline_get_bus(GST_PIPELINE(d->pipeline));
+            bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_ptr));
             gst_bus_enable_sync_message_emission(bus);
-            g_signal_connect (bus, "sync-message", G_CALLBACK (gst_sync_bus_call), data);
+            g_signal_connect(bus, "sync-message", G_CALLBACK(gst_sync_bus_call), display);
             gst_object_unref(bus);
             return true;
         }
-- 
2.17.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]