From: Linus Svensson Date: Tue, 19 Aug 2014 21:28:52 +0000 (+0200) Subject: bus: Add a function to remove a bus watch X-Git-Tag: 1.6.1~707 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8b512d2f0a468eba940bede3c7d9ce485a2176a;p=platform%2Fupstream%2Fgstreamer.git bus: Add a function to remove a bus watch If a bus watch is added to the non default main context it's not possible to remove it using g_source_remove(). Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=735195 --- diff --git a/gst/gstbus.c b/gst/gstbus.c index 9b64a7f..b9ce67b 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -897,8 +897,9 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, * When @func is called, the message belongs to the caller; if you want to * keep a copy of it, call gst_message_ref() before leaving @func. * - * The watch can be removed using g_source_remove() or by returning %FALSE - * from @func. + * The watch can be removed using gst_bus_remove_watch() or by returning %FALSE + * from @func. If the watch was added to the default main context it is also + * possible to remove the watch using g_source_remove(). * * MT safe. * @@ -936,8 +937,9 @@ gst_bus_add_watch_full (GstBus * bus, gint priority, * There can only be a single bus watch per bus, you must remove it before you * can set a new one. * - * The watch can be removed using g_source_remove() or by returning %FALSE - * from @func. + * The watch can be removed using gst_bus_remove_watch() or by returning %FALSE + * from @func. If the watch was added to the default main context it is also + * possible to remove the watch using g_source_remove(). * * Returns: The event source id or 0 if @bus already got an event source. * @@ -950,6 +952,45 @@ gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data) user_data, NULL); } +/** + * gst_bus_remove_watch: + * @bus: a #GstBus to remove the watch from. + * + * Removes an installed bus watch from @bus. + * + * Returns: %TRUE on success or %FALSE if @bus has no event source. + * + * Since: 1.6 + * + */ +gboolean +gst_bus_remove_watch (GstBus * bus) +{ + GSource *watch_id; + + g_return_val_if_fail (GST_IS_BUS (bus), FALSE); + + GST_OBJECT_LOCK (bus); + + if (bus->priv->signal_watch == NULL) { + GST_ERROR_OBJECT (bus, "no bus watch was present"); + goto no_watch; + } + + watch_id = bus->priv->signal_watch; + + GST_OBJECT_UNLOCK (bus); + + g_source_destroy (watch_id); + + return TRUE; + +no_watch: + GST_OBJECT_UNLOCK (bus); + + return FALSE; +} + typedef struct { GMainLoop *loop; diff --git a/gst/gstbus.h b/gst/gstbus.h index 92d2160..d369682 100644 --- a/gst/gstbus.h +++ b/gst/gstbus.h @@ -159,6 +159,7 @@ guint gst_bus_add_watch_full (GstBus * bus, guint gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data); +gboolean gst_bus_remove_watch (GstBus * bus); /* polling the bus */ GstMessage* gst_bus_poll (GstBus *bus, GstMessageType events, diff --git a/tests/check/gst/gstbus.c b/tests/check/gst/gstbus.c index 5eaa7f1..f7bed46 100644 --- a/tests/check/gst/gstbus.c +++ b/tests/check/gst/gstbus.c @@ -188,7 +188,7 @@ GST_START_TEST (test_watch) fail_unless_equals_int (num_eos, 10); fail_unless_equals_int (num_app, 10); - g_source_remove (id); + fail_unless (gst_bus_remove_watch (test_bus)); g_main_loop_unref (main_loop); gst_object_unref ((GstObject *) test_bus); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index b83293b..99a1568 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -206,6 +206,7 @@ EXPORTS gst_bus_pop_filtered gst_bus_post gst_bus_remove_signal_watch + gst_bus_remove_watch gst_bus_set_flushing gst_bus_set_sync_handler gst_bus_sync_reply_get_type