2 * Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
4 * gstmeta.c: metadata operations
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.
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.
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.
24 * @short_description: Buffer metadata
26 * Last reviewed on December 17th, 2009 (0.10.26)
28 #include "gst_private.h"
30 #include "gstbuffer.h"
35 static GHashTable *metainfo = NULL;
38 GQuark _gst_meta_transform_copy;
41 _priv_gst_meta_initialize (void)
43 g_rw_lock_init (&lock);
44 metainfo = g_hash_table_new (g_str_hash, g_str_equal);
46 _gst_meta_transform_copy = g_quark_from_static_string ("copy");
50 * gst_meta_api_type_register:
51 * @api: an API to register
52 * @tags: tags for @api
54 * Register and return a GType for the @api and associate it with
57 * Returns: a unique GType for @api.
60 gst_meta_api_type_register (const gchar * api, const gchar ** tags)
64 g_return_val_if_fail (api != NULL, 0);
65 g_return_val_if_fail (tags != NULL, 0);
67 type = g_pointer_type_register_static (api);
72 for (i = 0; tags[i]; i++)
73 g_type_set_qdata (type, g_quark_from_string (tags[i]),
74 GINT_TO_POINTER (TRUE));
80 * gst_meta_api_type_has_tag:
82 * @tag: the tag to check
84 * Check if @api was registered with @tag.
86 * Returns: %TRUE if @api was registered with @tag.
89 gst_meta_api_type_has_tag (GType api, GQuark tag)
91 g_return_val_if_fail (api != 0, FALSE);
92 g_return_val_if_fail (tag != 0, FALSE);
94 return g_type_get_qdata (api, tag) != NULL;
99 * @api: the type of the #GstMeta API
100 * @impl: the name of the #GstMeta implementation
101 * @size: the size of the #GstMeta structure
102 * @init_func: a #GstMetaInitFunction
103 * @free_func: a #GstMetaFreeFunction
104 * @transform_func: a #GstMetaTransformFunction
105 * @tags: a NULL terminated array of strings describing what the metadata
106 * contains info about.
108 * Register a new #GstMeta implementation.
110 * The same @info can be retrieved later with gst_meta_get_info() by using
113 * Returns: (transfer none): a #GstMetaInfo that can be used to access metadata.
117 gst_meta_register (GType api, const gchar * impl, gsize size,
118 GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
119 GstMetaTransformFunction transform_func)
123 g_return_val_if_fail (api != 0, NULL);
124 g_return_val_if_fail (impl != NULL, NULL);
125 g_return_val_if_fail (size != 0, NULL);
127 info = g_slice_new (GstMetaInfo);
129 info->type = g_pointer_type_register_static (impl);
131 info->init_func = init_func;
132 info->free_func = free_func;
133 info->transform_func = transform_func;
135 GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,
138 g_rw_lock_writer_lock (&lock);
139 g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
140 g_rw_lock_writer_unlock (&lock);
149 * Lookup a previously registered meta info structure by its implementation name
152 * Returns: (transfer none): a #GstMetaInfo with @impl, or #NULL when no such
156 gst_meta_get_info (const gchar * impl)
160 g_return_val_if_fail (impl != NULL, NULL);
162 g_rw_lock_reader_lock (&lock);
163 info = g_hash_table_lookup (metainfo, impl);
164 g_rw_lock_reader_unlock (&lock);