summaryrefslogtreecommitdiff
path: root/gst/inter
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2014-10-22 18:13:36 +0200
committerSebastian Dröge <sebastian@centricular.com>2014-10-22 19:09:15 +0200
commit211a39e55e4dda289b45023f46c6fb4aa4f5c12f (patch)
tree782bc381b447b10f61e50f4ef844a13cf7ae34db /gst/inter
parentf3ce87d1bde29f002255dc6f1ca6bf2efa29681b (diff)
inter: Clean up surfaces after the last user is gone
Diffstat (limited to 'gst/inter')
-rw-r--r--gst/inter/gstintersurface.c26
-rw-r--r--gst/inter/gstintersurface.h2
2 files changed, 26 insertions, 2 deletions
diff --git a/gst/inter/gstintersurface.c b/gst/inter/gstintersurface.c
index 243472d66b..0b33e1ab2b 100644
--- a/gst/inter/gstintersurface.c
+++ b/gst/inter/gstintersurface.c
@@ -35,16 +35,17 @@ gst_inter_surface_get (const char *name)
GstInterSurface *surface;
g_mutex_lock (&mutex);
-
for (g = list; g; g = g_list_next (g)) {
- surface = (GstInterSurface *) g->data;
+ surface = g->data;
if (strcmp (name, surface->name) == 0) {
+ surface->ref_count++;
g_mutex_unlock (&mutex);
return surface;
}
}
surface = g_malloc0 (sizeof (GstInterSurface));
+ surface->ref_count = 1;
surface->name = g_strdup (name);
g_mutex_init (&surface->mutex);
surface->audio_adapter = gst_adapter_new ();
@@ -58,5 +59,26 @@ gst_inter_surface_get (const char *name)
void
gst_inter_surface_unref (GstInterSurface * surface)
{
+ /* Mutex needed here, otherwise refcount might become 0
+ * and someone else requests the same surface again before
+ * we remove it from the list */
+ g_mutex_lock (&mutex);
+ if ((--surface->ref_count) == 0) {
+ GList *g;
+
+ for (g = list; g; g = g_list_next (g)) {
+ GstInterSurface *tmp = g->data;
+ if (strcmp (tmp->name, surface->name) == 0) {
+ list = g_list_delete_link (list, g);
+ break;
+ }
+ }
+ g_mutex_clear (&surface->mutex);
+ gst_buffer_replace (&surface->video_buffer, NULL);
+ gst_buffer_replace (&surface->sub_buffer, NULL);
+ gst_object_unref (surface->audio_adapter);
+ g_free (surface);
+ }
+ g_mutex_unlock (&mutex);
}
diff --git a/gst/inter/gstintersurface.h b/gst/inter/gstintersurface.h
index 1ac621d488..10754af5c1 100644
--- a/gst/inter/gstintersurface.h
+++ b/gst/inter/gstintersurface.h
@@ -30,6 +30,8 @@ typedef struct _GstInterSurface GstInterSurface;
struct _GstInterSurface
{
GMutex mutex;
+ gint ref_count;
+
char *name;
/* video */