mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-24 08:08:22 +00:00
inter: Clean up surfaces after the last user is gone
This commit is contained in:
parent
f3ce87d1bd
commit
211a39e55e
2 changed files with 26 additions and 2 deletions
|
@ -35,16 +35,17 @@ gst_inter_surface_get (const char *name)
|
||||||
GstInterSurface *surface;
|
GstInterSurface *surface;
|
||||||
|
|
||||||
g_mutex_lock (&mutex);
|
g_mutex_lock (&mutex);
|
||||||
|
|
||||||
for (g = list; g; g = g_list_next (g)) {
|
for (g = list; g; g = g_list_next (g)) {
|
||||||
surface = (GstInterSurface *) g->data;
|
surface = g->data;
|
||||||
if (strcmp (name, surface->name) == 0) {
|
if (strcmp (name, surface->name) == 0) {
|
||||||
|
surface->ref_count++;
|
||||||
g_mutex_unlock (&mutex);
|
g_mutex_unlock (&mutex);
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
surface = g_malloc0 (sizeof (GstInterSurface));
|
surface = g_malloc0 (sizeof (GstInterSurface));
|
||||||
|
surface->ref_count = 1;
|
||||||
surface->name = g_strdup (name);
|
surface->name = g_strdup (name);
|
||||||
g_mutex_init (&surface->mutex);
|
g_mutex_init (&surface->mutex);
|
||||||
surface->audio_adapter = gst_adapter_new ();
|
surface->audio_adapter = gst_adapter_new ();
|
||||||
|
@ -58,5 +59,26 @@ gst_inter_surface_get (const char *name)
|
||||||
void
|
void
|
||||||
gst_inter_surface_unref (GstInterSurface * surface)
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ typedef struct _GstInterSurface GstInterSurface;
|
||||||
struct _GstInterSurface
|
struct _GstInterSurface
|
||||||
{
|
{
|
||||||
GMutex mutex;
|
GMutex mutex;
|
||||||
|
gint ref_count;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
/* video */
|
/* video */
|
||||||
|
|
Loading…
Reference in a new issue