diff options
author | Seungha Yang <seungha.yang@navercorp.com> | 2019-01-28 18:13:27 +0900 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-05-01 17:39:55 +0100 |
commit | cb0980eae2db7a6a860d621b512995670cdaf2db (patch) | |
tree | 3f588a0ed0fca3975d45b834e6e2e31eb0d7b59a | |
parent | d6d47f7d1dde4597dd070bc798044803ee1aef13 (diff) | |
download | gstreamer-plugins-base-cb0980eae2db7a6a860d621b512995670cdaf2db.tar.gz |
discoverer: Hold GSource object instead of source id
g_source_remove() works only for a GSource which was attached
to default GMainContext, but the GSource might be attached to
custom context depending on how gst_discoverer_start() was called.
Whatever the attached context was, g_source_destroy() can clean it up.
-rw-r--r-- | gst-libs/gst/pbutils/gstdiscoverer.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/gst-libs/gst/pbutils/gstdiscoverer.c b/gst-libs/gst/pbutils/gstdiscoverer.c index 06e03a202..1394a3808 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer.c +++ b/gst-libs/gst/pbutils/gstdiscoverer.c @@ -124,8 +124,8 @@ struct _GstDiscovererPrivate /* Custom main context variables */ GMainContext *ctx; - guint sourceid; - guint timeoutid; + GSource *bus_source; + GSource *timeout_source; /* reusable queries */ GstQuery *seeking_query; @@ -1313,9 +1313,10 @@ discoverer_collect (GstDiscoverer * dc) GST_DEBUG ("Collecting information"); /* Stop the timeout handler if present */ - if (dc->priv->timeoutid) { - g_source_remove (dc->priv->timeoutid); - dc->priv->timeoutid = 0; + if (dc->priv->timeout_source) { + g_source_destroy (dc->priv->timeout_source); + g_source_unref (dc->priv->timeout_source); + dc->priv->timeout_source = NULL; } if (dc->priv->streams) { @@ -1447,8 +1448,8 @@ handle_current_async (GstDiscoverer * dc) /* Attach a timeout to the main context */ source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND); g_source_set_callback_indirect (source, g_object_ref (dc), &cb_funcs); - dc->priv->timeoutid = g_source_attach (source, dc->priv->ctx); - g_source_unref (source); + g_source_attach (source, dc->priv->ctx); + dc->priv->timeout_source = source; } @@ -1784,12 +1785,13 @@ static gboolean async_timeout_cb (GstDiscoverer * dc) { if (!g_source_is_destroyed (g_main_current_source ())) { - dc->priv->timeoutid = 0; GST_DEBUG ("Setting result to TIMEOUT"); dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT; dc->priv->processing = FALSE; discoverer_collect (dc); discoverer_cleanup (dc); + g_source_unref (dc->priv->timeout_source); + dc->priv->timeout_source = NULL; } return FALSE; } @@ -2188,8 +2190,8 @@ gst_discoverer_start (GstDiscoverer * discoverer) source = gst_bus_create_watch (discoverer->priv->bus); g_source_set_callback (source, (GSourceFunc) gst_bus_async_signal_func, NULL, NULL); - discoverer->priv->sourceid = g_source_attach (source, ctx); - g_source_unref (source); + g_source_attach (source, ctx); + discoverer->priv->bus_source = source; discoverer->priv->ctx = g_main_context_ref (ctx); start_discovering (discoverer); @@ -2231,14 +2233,16 @@ gst_discoverer_stop (GstDiscoverer * discoverer) DISCO_UNLOCK (discoverer); /* Remove timeout handler */ - if (discoverer->priv->timeoutid) { - g_source_remove (discoverer->priv->timeoutid); - discoverer->priv->timeoutid = 0; + if (discoverer->priv->timeout_source) { + g_source_destroy (discoverer->priv->timeout_source); + g_source_unref (discoverer->priv->timeout_source); + discoverer->priv->timeout_source = NULL; } /* Remove signal watch */ - if (discoverer->priv->sourceid) { - g_source_remove (discoverer->priv->sourceid); - discoverer->priv->sourceid = 0; + if (discoverer->priv->bus_source) { + g_source_destroy (discoverer->priv->bus_source); + g_source_unref (discoverer->priv->bus_source); + discoverer->priv->bus_source = NULL; } /* Unref main context */ if (discoverer->priv->ctx) { |