rtsp-media: remove bus watch before finalizing
authorDavid Svensson Fors <davidsf@axis.com>
Mon, 19 Nov 2012 14:47:08 +0000 (15:47 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 20 Nov 2012 08:46:00 +0000 (09:46 +0100)
* A GDestroyNotify function is set for the bus watch in gst_rtsp_media_prepare.
* An extra media ref is added for the bus watch. This extra ref is unreffed by
the GDestroyNotify function.
* gst_rtsp_media_unprepare destroys the source so the bus watch is removed.
* GstRTSPClient, which calls gst_rtsp_media_prepare, also calls
gst_rtsp_media_unprepare before unreffing the media.

This way, the bus watch will be removed before the media is finalized.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=688707

gst/rtsp-server/rtsp-client.c
gst/rtsp-server/rtsp-media.c

index 799b42e..a0ba3c5 100644 (file)
@@ -230,8 +230,10 @@ gst_rtsp_client_finalize (GObject * obj)
 
   if (client->uri)
     gst_rtsp_url_free (client->uri);
-  if (client->media)
+  if (client->media) {
+    gst_rtsp_media_unprepare (client->media);
     g_object_unref (client->media);
+  }
 
   g_free (client->server_ip);
 
@@ -377,8 +379,10 @@ find_media (GstRTSPClient * client, GstRTSPClientState * state)
     if (client->uri)
       gst_rtsp_url_free (client->uri);
     client->uri = NULL;
-    if (client->media)
+    if (client->media) {
+      gst_rtsp_media_unprepare (client->media);
       g_object_unref (client->media);
+    }
     client->media = NULL;
 
     if (!client->media_mapping)
index dfd89bc..d8191bb 100644 (file)
@@ -1088,6 +1088,13 @@ bus_message (GstBus * bus, GstMessage * message, GstRTSPMedia * media)
   return ret;
 }
 
+static void
+watch_destroyed (GstRTSPMedia * media)
+{
+  GST_DEBUG_OBJECT (media, "source destroyed");
+  gst_object_unref (media);
+}
+
 /* called from streaming threads */
 static void
 pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
@@ -1188,7 +1195,8 @@ gst_rtsp_media_prepare (GstRTSPMedia * media)
   media->source = gst_bus_create_watch (bus);
   gst_object_unref (bus);
 
-  g_source_set_callback (media->source, (GSourceFunc) bus_message, media, NULL);
+  g_source_set_callback (media->source, (GSourceFunc) bus_message,
+      gst_object_ref (media), (GDestroyNotify) watch_destroyed);
 
   klass = GST_RTSP_MEDIA_GET_CLASS (media);
   media->id = g_source_attach (media->source, klass->context);
@@ -1387,6 +1395,11 @@ gst_rtsp_media_unprepare (GstRTSPMedia * media)
   } else {
     finish_unprepare (media);
   }
+  if (media->source) {
+    g_source_destroy (media->source);
+    g_source_unref (media->source);
+    media->source = NULL;
+  }
   g_rec_mutex_unlock (&media->state_lock);
 
   return success;