gst: suppress some more deprecated thread api until we fix it up
[platform/upstream/gstreamer.git] / gst / gstmeta.c
1 /* GStreamer
2  * Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * gstmeta.c: metadata operations
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /**
23  * SECTION:gstmeta
24  * @short_description: Buffer metadata
25  *
26  * Last reviewed on December 17th, 2009 (0.10.26)
27  */
28 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
29  * with newer GLib versions (>= 2.31.0) */
30 #define GLIB_DISABLE_DEPRECATION_WARNINGS
31 #include "gst_private.h"
32
33 #include "gstbuffer.h"
34 #include "gstmeta.h"
35 #include "gstinfo.h"
36 #include "gstutils.h"
37
38 static GHashTable *metainfo = NULL;
39 static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT;
40
41 void
42 _priv_gst_meta_initialize (void)
43 {
44   metainfo = g_hash_table_new (g_str_hash, g_str_equal);
45 }
46
47 /**
48  * gst_meta_register:
49  * @api: the name of the #GstMeta API
50  * @impl: the name of the #GstMeta implementation
51  * @size: the size of the #GstMeta structure
52  * @init_func: a #GstMetaInitFunction
53  * @free_func: a #GstMetaFreeFunction
54  * @copy_func: a #GstMetaCopyFunction
55  * @transform_func: a #GstMetaTransformFunction
56  *
57  * Register a new #GstMeta implementation.
58  *
59  * The same @info can be retrieved later with gst_meta_get_info() by using
60  * @impl as the key.
61  *
62  * Returns: (transfer none): a #GstMetaInfo that can be used to access metadata.
63  */
64
65 const GstMetaInfo *
66 gst_meta_register (const gchar * api, const gchar * impl, gsize size,
67     GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
68     GstMetaCopyFunction copy_func, GstMetaTransformFunction transform_func)
69 {
70   GstMetaInfo *info;
71
72   g_return_val_if_fail (api != NULL, NULL);
73   g_return_val_if_fail (impl != NULL, NULL);
74   g_return_val_if_fail (size != 0, NULL);
75
76   info = g_slice_new (GstMetaInfo);
77   info->api = g_quark_from_string (api);
78   info->type = g_pointer_type_register_static (impl);
79   info->size = size;
80   info->init_func = init_func;
81   info->free_func = free_func;
82   info->copy_func = copy_func;
83   info->transform_func = transform_func;
84
85   GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,
86       api, impl, size);
87
88   g_static_rw_lock_writer_lock (&lock);
89   g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
90   g_static_rw_lock_writer_unlock (&lock);
91
92   return info;
93 }
94
95 /**
96  * gst_meta_get_info:
97  * @impl: the name
98  *
99  * Lookup a previously registered meta info structure by its implementation name
100  * @impl.
101  *
102  * Returns: (transfer none): a #GstMetaInfo with @impl, or #NULL when no such
103  * metainfo exists.
104  */
105 const GstMetaInfo *
106 gst_meta_get_info (const gchar * impl)
107 {
108   GstMetaInfo *info;
109
110   g_return_val_if_fail (impl != NULL, NULL);
111
112   g_static_rw_lock_reader_lock (&lock);
113   info = g_hash_table_lookup (metainfo, impl);
114   g_static_rw_lock_reader_unlock (&lock);
115
116   return info;
117 }