factory: connect to the unprepare signal
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 3 Apr 2009 20:46:22 +0000 (22:46 +0200)
committerWim Taymans <wim@metal.(none)>
Fri, 3 Apr 2009 20:46:22 +0000 (22:46 +0200)
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

index 02614e6..6eb8348 100644 (file)
@@ -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);