bus: add GDestroyNotify to set_sync_handler()
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 20 Jun 2012 10:29:35 +0000 (12:29 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 20 Jun 2012 10:29:35 +0000 (12:29 +0200)
gst/gstbin.c
gst/gstbus.c
gst/gstbus.h
tests/check/generic/sinks.c
tests/check/gst/gstbin.c
tests/examples/streams/rtpool-test.c
tests/examples/streams/stream-status.c
tools/gst-launch.c

index 8f8bd73..d8125c0 100644 (file)
@@ -500,7 +500,8 @@ gst_bin_init (GstBin * bin)
   bin->child_bus = bus;
   GST_DEBUG_OBJECT (bin, "using bus %" GST_PTR_FORMAT " to listen to children",
       bus);
-  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin);
+  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin,
+      NULL);
 
   bin->priv = GST_BIN_GET_PRIVATE (bin);
   bin->priv->asynchandling = DEFAULT_ASYNC_HANDLING;
index e0a06a2..1a82f54 100644 (file)
@@ -100,6 +100,7 @@ enum
 };
 
 static void gst_bus_dispose (GObject * object);
+static void gst_bus_finalize (GObject * object);
 
 static guint gst_bus_signals[LAST_SIGNAL] = { 0 };
 
@@ -110,6 +111,7 @@ struct _GstBusPrivate
 
   GstBusSyncHandler sync_handler;
   gpointer sync_handler_data;
+  GDestroyNotify sync_handler_notify;
 
   guint signal_watch_id;
   guint num_signal_watchers;
@@ -158,6 +160,7 @@ gst_bus_class_init (GstBusClass * klass)
   GObjectClass *gobject_class = (GObjectClass *) klass;
 
   gobject_class->dispose = gst_bus_dispose;
+  gobject_class->finalize = gst_bus_finalize;
   gobject_class->set_property = gst_bus_set_property;
   gobject_class->constructed = gst_bus_constructed;
 
@@ -255,6 +258,17 @@ gst_bus_dispose (GObject * object)
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
+static void
+gst_bus_finalize (GObject * object)
+{
+  GstBus *bus = GST_BUS (object);
+
+  if (bus->priv->sync_handler_notify)
+    bus->priv->sync_handler_notify (bus->priv->sync_handler_data);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
 /**
  * gst_bus_new:
  *
@@ -655,7 +669,8 @@ gst_bus_peek (GstBus * bus)
  * gst_bus_set_sync_handler:
  * @bus: a #GstBus to install the handler on
  * @func: The handler function to install
- * @data: User data that will be sent to the handler function.
+ * @user_data: User data that will be sent to the handler function.
+ * @notify: called when @user_data becomes unused
  *
  * Sets the synchronous handler on the bus. The function will be called
  * every time a new message is posted on the bus. Note that the function
@@ -668,19 +683,33 @@ gst_bus_peek (GstBus * bus)
  * function, which will clear the existing handler.
  */
 void
-gst_bus_set_sync_handler (GstBus * bus, GstBusSyncHandler func, gpointer data)
+gst_bus_set_sync_handler (GstBus * bus, GstBusSyncHandler func,
+    gpointer user_data, GDestroyNotify notify)
 {
+  GDestroyNotify old_notify;
+
   g_return_if_fail (GST_IS_BUS (bus));
 
   GST_OBJECT_LOCK (bus);
-
   /* Assert if the user attempts to replace an existing sync_handler,
    * other than to clear it */
   if (func != NULL && bus->priv->sync_handler != NULL)
     goto no_replace;
 
+  if ((old_notify = bus->priv->sync_handler_notify)) {
+    gpointer old_data = bus->priv->sync_handler_data;
+
+    bus->priv->sync_handler_data = NULL;
+    bus->priv->sync_handler_notify = NULL;
+    GST_OBJECT_UNLOCK (bus);
+
+    old_notify (old_data);
+
+    GST_OBJECT_LOCK (bus);
+  }
   bus->priv->sync_handler = func;
-  bus->priv->sync_handler_data = data;
+  bus->priv->sync_handler_data = user_data;
+  bus->priv->sync_handler_notify = notify;
   GST_OBJECT_UNLOCK (bus);
 
   return;
index 04d4d6c..ed05ddb 100644 (file)
@@ -148,7 +148,7 @@ void                    gst_bus_set_flushing            (GstBus * bus, gboolean
 
 /* synchronous dispatching */
 void                    gst_bus_set_sync_handler        (GstBus * bus, GstBusSyncHandler func,
-                                                         gpointer data);
+                                                         gpointer user_data, GDestroyNotify notify);
 /* GSource based dispatching */
 GSource *               gst_bus_create_watch            (GstBus * bus);
 guint                   gst_bus_add_watch_full          (GstBus * bus,
index 84aafac..335225e 100644 (file)
@@ -1074,7 +1074,8 @@ GST_START_TEST (test_async_done)
   /* set bus on element synchronously listen for ASYNC_DONE */
   bus = gst_bus_new ();
   gst_element_set_bus (sink, bus);
-  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) async_done_func, sink);
+  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) async_done_func, sink,
+      NULL);
 
   /* make newsegment, this sets the position to 10sec when the buffer prerolls */
   GST_DEBUG ("sending segment");
@@ -1183,7 +1184,8 @@ GST_START_TEST (test_async_done_eos)
   /* set bus on element synchronously listen for ASYNC_DONE */
   bus = gst_bus_new ();
   gst_element_set_bus (sink, bus);
-  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) async_done_eos_func, sink);
+  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) async_done_eos_func, sink,
+      NULL);
 
   /* make newsegment, this sets the position to 10sec when the buffer prerolls */
   GST_DEBUG ("sending segment");
index 7535945..45f17a8 100644 (file)
@@ -989,7 +989,7 @@ GST_START_TEST (test_link_structure_change)
 
   /* use the sync signal handler to link elements while the pipeline is still
    * doing the state change */
-  gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline);
+  gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, pipeline, NULL);
   g_object_connect (bus, "signal::sync-message::state-changed",
       G_CALLBACK (test_link_structure_change_state_changed_sync_cb), pipeline,
       NULL);
@@ -1061,7 +1061,7 @@ GST_START_TEST (test_state_failure_remove)
   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
   fail_unless (bus != NULL, "Could not get bus");
 
-  gst_bus_set_sync_handler (bus, sync_handler_remove_sink, pipeline);
+  gst_bus_set_sync_handler (bus, sync_handler_remove_sink, pipeline, NULL);
 
   ret = gst_element_set_state (pipeline, GST_STATE_READY);
   fail_unless (ret == GST_STATE_CHANGE_SUCCESS,
index 960b6ea..fe129d2 100644 (file)
@@ -154,7 +154,8 @@ main (int argc, char *argv[])
 
   /* get the bus, we need to install a sync handler */
   bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
-  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin);
+  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin,
+      NULL);
 
   /* start playing */
   ret = gst_element_set_state (bin, GST_STATE_PLAYING);
index 0494ebd..1331110 100644 (file)
@@ -130,7 +130,8 @@ main (int argc, char *argv[])
 
   /* get the bus, we need to install a sync handler */
   bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
-  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin);
+  gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin,
+      NULL);
 
   /* start playing */
   gst_element_set_state (bin, GST_STATE_PLAYING);
index 4abb429..12472d5 100644 (file)
@@ -1041,7 +1041,7 @@ main (int argc, char *argv[])
 #endif
 
     bus = gst_element_get_bus (pipeline);
-    gst_bus_set_sync_handler (bus, bus_sync_handler, (gpointer) pipeline);
+    gst_bus_set_sync_handler (bus, bus_sync_handler, (gpointer) pipeline, NULL);
     gst_object_unref (bus);
 
     PRINT (_("Setting pipeline to PAUSED ...\n"));