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.
This commit is contained in:
Seungha Yang 2019-01-28 18:13:27 +09:00
parent 33680a3800
commit b32b59ce76

View File

@ -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;
@ -1323,9 +1323,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) {
@ -1457,8 +1458,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;
} }
@ -1794,12 +1795,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;
} }
@ -2198,8 +2200,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);
@ -2241,14 +2243,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) {