From 35a5a709d35be34d411d1a5ac8aa0dd15585980e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 3 Apr 2009 22:46:22 +0200 Subject: [PATCH] factory: connect to the unprepare signal Connect to the unprepare signal for non-reusable media so that we can remove them from the cache. --- gst/rtsp-server/rtsp-media-factory.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gst/rtsp-server/rtsp-media-factory.c b/gst/rtsp-server/rtsp-media-factory.c index 02614e6..6eb8348 100644 --- a/gst/rtsp-server/rtsp-media-factory.c +++ b/gst/rtsp-server/rtsp-media-factory.c @@ -250,6 +250,21 @@ gst_rtsp_media_factory_is_shared (GstRTSPMediaFactory *factory) return result; } +static gboolean +compare_media (gpointer key, GstRTSPMedia *media1, GstRTSPMedia *media2) +{ + return (media1 == media2); +} + +static void +media_unprepared (GstRTSPMedia *media, GstRTSPMediaFactory *factory) +{ + g_mutex_lock (factory->medias_lock); + g_hash_table_foreach_remove (factory->medias, (GHRFunc) compare_media, + media); + g_mutex_unlock (factory->medias_lock); +} + /** * gst_rtsp_media_factory_construct: * @factory: a #GstRTSPMediaFactory @@ -310,6 +325,12 @@ gst_rtsp_media_factory_construct (GstRTSPMediaFactory *factory, const GstRTSPUrl g_hash_table_insert (factory->medias, key, media); key = NULL; } + if (!gst_rtsp_media_is_reusable (media)) { + /* when not reusable, connect to the unprepare signal to remove the item + * from our cache when it gets unprepared */ + g_signal_connect (media, "unprepared", (GCallback) media_unprepared, + factory); + } } } g_mutex_unlock (factory->medias_lock); -- 2.7.4