rtsp-media: Ensure the bus watch is removed during unprepare
authorDoug Nazar <nazard@nazar.ca>
Thu, 29 Apr 2021 07:07:42 +0000 (03:07 -0400)
committerDoug Nazar <nazard@nazar.ca>
Thu, 29 Apr 2021 07:07:42 +0000 (03:07 -0400)
It's possible for the destruction of the source to be delayed.
Instead of relying on the dispose() to remove the bus watch, do
it ourselves.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/202>

gst/rtsp-server/rtsp-media.c

index 55d2b31..63f43bc 100644 (file)
@@ -131,7 +131,6 @@ struct _GstRTSPMediaPrivate
   /* the pipeline for the media */
   GstElement *pipeline;
   GSource *source;
-  guint id;
   GstRTSPThread *thread;
   GList *pending_pipeline_elements;
 
@@ -3811,7 +3810,7 @@ default_prepare (GstRTSPMedia * media, GstRTSPThread * thread)
   g_source_set_callback (priv->source, (GSourceFunc) bus_message,
       g_object_ref (media), (GDestroyNotify) watch_destroyed);
 
-  priv->id = g_source_attach (priv->source, context);
+  g_source_attach (priv->source, context);
 
   /* add stuff to the bin */
   gst_bin_add (GST_BIN (priv->pipeline), priv->rtpbin);
@@ -4034,9 +4033,17 @@ finish_unprepare (GstRTSPMedia * media)
 
   /* the source has the last ref to the media */
   if (priv->source) {
+    GstBus *bus;
+
+    GST_DEBUG ("removing bus watch");
+    bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (priv->pipeline));
+    gst_bus_remove_watch (bus);
+    gst_object_unref (bus);
+
     GST_DEBUG ("destroy source");
     g_source_destroy (priv->source);
     g_source_unref (priv->source);
+    priv->source = NULL;
   }
   if (priv->thread) {
     GST_DEBUG ("stop thread");