From 01973c924d3fc850b812a7aaf1b2691a8fd01ae0 Mon Sep 17 00:00:00 2001 From: David Svensson Fors Date: Mon, 19 Nov 2012 15:47:08 +0100 Subject: [PATCH] rtsp-media: remove bus watch before finalizing * 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 | 8 ++++++-- gst/rtsp-server/rtsp-media.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 799b42e512..a0ba3c52e5 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -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) diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c index dfd89bc872..d8191bbf24 100644 --- a/gst/rtsp-server/rtsp-media.c +++ b/gst/rtsp-server/rtsp-media.c @@ -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;