Commit cb0980ea authored by Seungha Yang's avatar Seungha Yang Committed by Tim-Philipp Müller

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.
parent d6d47f7d
...@@ -124,8 +124,8 @@ struct _GstDiscovererPrivate ...@@ -124,8 +124,8 @@ struct _GstDiscovererPrivate
/* Custom main context variables */ /* Custom main context variables */
GMainContext *ctx; GMainContext *ctx;
guint sourceid; GSource *bus_source;
guint timeoutid; GSource *timeout_source;
/* reusable queries */ /* reusable queries */
GstQuery *seeking_query; GstQuery *seeking_query;
...@@ -1313,9 +1313,10 @@ discoverer_collect (GstDiscoverer * dc) ...@@ -1313,9 +1313,10 @@ discoverer_collect (GstDiscoverer * dc)
GST_DEBUG ("Collecting information"); GST_DEBUG ("Collecting information");
/* Stop the timeout handler if present */ /* Stop the timeout handler if present */
if (dc->priv->timeoutid) { if (dc->priv->timeout_source) {
g_source_remove (dc->priv->timeoutid); g_source_destroy (dc->priv->timeout_source);
dc->priv->timeoutid = 0; g_source_unref (dc->priv->timeout_source);
dc->priv->timeout_source = NULL;
} }
if (dc->priv->streams) { if (dc->priv->streams) {
...@@ -1447,8 +1448,8 @@ handle_current_async (GstDiscoverer * dc) ...@@ -1447,8 +1448,8 @@ handle_current_async (GstDiscoverer * dc)
/* Attach a timeout to the main context */ /* Attach a timeout to the main context */
source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND); source = g_timeout_source_new (dc->priv->timeout / GST_MSECOND);
g_source_set_callback_indirect (source, g_object_ref (dc), &cb_funcs); g_source_set_callback_indirect (source, g_object_ref (dc), &cb_funcs);
dc->priv->timeoutid = g_source_attach (source, dc->priv->ctx); g_source_attach (source, dc->priv->ctx);
g_source_unref (source); dc->priv->timeout_source = source;
} }
...@@ -1784,12 +1785,13 @@ static gboolean ...@@ -1784,12 +1785,13 @@ static gboolean
async_timeout_cb (GstDiscoverer * dc) async_timeout_cb (GstDiscoverer * dc)
{ {
if (!g_source_is_destroyed (g_main_current_source ())) { if (!g_source_is_destroyed (g_main_current_source ())) {
dc->priv->timeoutid = 0;
GST_DEBUG ("Setting result to TIMEOUT"); GST_DEBUG ("Setting result to TIMEOUT");
dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT; dc->priv->current_info->result = GST_DISCOVERER_TIMEOUT;
dc->priv->processing = FALSE; dc->priv->processing = FALSE;
discoverer_collect (dc); discoverer_collect (dc);
discoverer_cleanup (dc); discoverer_cleanup (dc);
g_source_unref (dc->priv->timeout_source);
dc->priv->timeout_source = NULL;
} }
return FALSE; return FALSE;
} }
...@@ -2188,8 +2190,8 @@ gst_discoverer_start (GstDiscoverer * discoverer) ...@@ -2188,8 +2190,8 @@ gst_discoverer_start (GstDiscoverer * discoverer)
source = gst_bus_create_watch (discoverer->priv->bus); source = gst_bus_create_watch (discoverer->priv->bus);
g_source_set_callback (source, (GSourceFunc) gst_bus_async_signal_func, g_source_set_callback (source, (GSourceFunc) gst_bus_async_signal_func,
NULL, NULL); NULL, NULL);
discoverer->priv->sourceid = g_source_attach (source, ctx); g_source_attach (source, ctx);
g_source_unref (source); discoverer->priv->bus_source = source;
discoverer->priv->ctx = g_main_context_ref (ctx); discoverer->priv->ctx = g_main_context_ref (ctx);
start_discovering (discoverer); start_discovering (discoverer);
...@@ -2231,14 +2233,16 @@ gst_discoverer_stop (GstDiscoverer * discoverer) ...@@ -2231,14 +2233,16 @@ gst_discoverer_stop (GstDiscoverer * discoverer)
DISCO_UNLOCK (discoverer); DISCO_UNLOCK (discoverer);
/* Remove timeout handler */ /* Remove timeout handler */
if (discoverer->priv->timeoutid) { if (discoverer->priv->timeout_source) {
g_source_remove (discoverer->priv->timeoutid); g_source_destroy (discoverer->priv->timeout_source);
discoverer->priv->timeoutid = 0; g_source_unref (discoverer->priv->timeout_source);
discoverer->priv->timeout_source = NULL;
} }
/* Remove signal watch */ /* Remove signal watch */
if (discoverer->priv->sourceid) { if (discoverer->priv->bus_source) {
g_source_remove (discoverer->priv->sourceid); g_source_destroy (discoverer->priv->bus_source);
discoverer->priv->sourceid = 0; g_source_unref (discoverer->priv->bus_source);
discoverer->priv->bus_source = NULL;
} }
/* Unref main context */ /* Unref main context */
if (discoverer->priv->ctx) { if (discoverer->priv->ctx) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment