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
This commit is contained in:
David Svensson Fors 2012-11-19 15:47:08 +01:00 committed by Wim Taymans
parent 65042a9551
commit 01973c924d
2 changed files with 20 additions and 3 deletions

View 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)

View 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;