2 * Copyright (C) 2011 David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
17 * Boston, MA 02110-1335, USA.
26 #include "gstintersurface.h"
32 gst_inter_surface_get (const char *name)
35 GstInterSurface *surface;
37 g_mutex_lock (&mutex);
38 for (g = list; g; g = g_list_next (g)) {
40 if (strcmp (name, surface->name) == 0) {
42 g_mutex_unlock (&mutex);
47 surface = g_malloc0 (sizeof (GstInterSurface));
48 surface->ref_count = 1;
49 surface->name = g_strdup (name);
50 g_mutex_init (&surface->mutex);
51 surface->audio_adapter = gst_adapter_new ();
52 surface->audio_buffer_time = DEFAULT_AUDIO_BUFFER_TIME;
53 surface->audio_latency_time = DEFAULT_AUDIO_LATENCY_TIME;
54 surface->audio_period_time = DEFAULT_AUDIO_PERIOD_TIME;
56 list = g_list_append (list, surface);
57 g_mutex_unlock (&mutex);
63 gst_inter_surface_unref (GstInterSurface * surface)
65 /* Mutex needed here, otherwise refcount might become 0
66 * and someone else requests the same surface again before
67 * we remove it from the list */
68 g_mutex_lock (&mutex);
69 if ((--surface->ref_count) == 0) {
72 for (g = list; g; g = g_list_next (g)) {
73 GstInterSurface *tmp = g->data;
74 if (strcmp (tmp->name, surface->name) == 0) {
75 list = g_list_delete_link (list, g);
80 g_mutex_clear (&surface->mutex);
81 gst_buffer_replace (&surface->video_buffer, NULL);
82 gst_buffer_replace (&surface->sub_buffer, NULL);
83 gst_object_unref (surface->audio_adapter);
84 g_free (surface->name);
87 g_mutex_unlock (&mutex);