From 6efb5c9b6bbe317861cc0e915ec6ded1b662dc12 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 20 Jun 2012 12:29:35 +0200 Subject: [PATCH] bus: add GDestroyNotify to set_sync_handler() --- gst/gstbin.c | 3 ++- gst/gstbus.c | 37 +++++++++++++++++++++++--- gst/gstbus.h | 2 +- tests/check/generic/sinks.c | 6 +++-- tests/check/gst/gstbin.c | 4 +-- tests/examples/streams/rtpool-test.c | 3 ++- tests/examples/streams/stream-status.c | 3 ++- tools/gst-launch.c | 2 +- 8 files changed, 47 insertions(+), 13 deletions(-) diff --git a/gst/gstbin.c b/gst/gstbin.c index 8f8bd73b49..d8125c0062 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -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; diff --git a/gst/gstbus.c b/gst/gstbus.c index e0a06a2cd1..1a82f5426d 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -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; diff --git a/gst/gstbus.h b/gst/gstbus.h index 04d4d6cd08..ed05ddbab4 100644 --- a/gst/gstbus.h +++ b/gst/gstbus.h @@ -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, diff --git a/tests/check/generic/sinks.c b/tests/check/generic/sinks.c index 84aafacf66..335225efa5 100644 --- a/tests/check/generic/sinks.c +++ b/tests/check/generic/sinks.c @@ -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"); diff --git a/tests/check/gst/gstbin.c b/tests/check/gst/gstbin.c index 7535945bbd..45f17a80bd 100644 --- a/tests/check/gst/gstbin.c +++ b/tests/check/gst/gstbin.c @@ -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, diff --git a/tests/examples/streams/rtpool-test.c b/tests/examples/streams/rtpool-test.c index 960b6ea630..fe129d2bd1 100644 --- a/tests/examples/streams/rtpool-test.c +++ b/tests/examples/streams/rtpool-test.c @@ -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); diff --git a/tests/examples/streams/stream-status.c b/tests/examples/streams/stream-status.c index 0494ebd3b2..1331110a04 100644 --- a/tests/examples/streams/stream-status.c +++ b/tests/examples/streams/stream-status.c @@ -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); diff --git a/tools/gst-launch.c b/tools/gst-launch.c index 4abb429e9c..12472d5246 100644 --- a/tools/gst-launch.c +++ b/tools/gst-launch.c @@ -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"));