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;
36 static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT;
41 metainfo = g_hash_table_new (g_str_hash, g_str_equal);
45 * gst_meta_register_info:
46 * @info: a #GstMetaInfo
48 * Register a #GstMetaInfo. The same @info can be retrieved later with
49 * gst_meta_get_info() by using @impl as the key.
51 * Returns: a #GstMetaInfo that can be used to access metadata.
55 gst_meta_register (const gchar * api, const gchar * impl, gsize size,
56 GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
57 GstMetaCopyFunction copy_func,
58 GstMetaTransformFunction transform_func,
59 GstMetaSerializeFunction serialize_func,
60 GstMetaDeserializeFunction deserialize_func)
64 g_return_val_if_fail (api != NULL, NULL);
65 g_return_val_if_fail (impl != NULL, NULL);
66 g_return_val_if_fail (size != 0, NULL);
68 info = g_slice_new (GstMetaInfo);
69 info->api = g_quark_from_string (api);
70 info->impl = g_quark_from_string (impl);
72 info->init_func = init_func;
73 info->free_func = free_func;
74 info->copy_func = copy_func;
75 info->transform_func = transform_func;
76 info->serialize_func = serialize_func;
77 info->deserialize_func = deserialize_func;
79 GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,
82 g_static_rw_lock_writer_lock (&lock);
83 g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
84 g_static_rw_lock_writer_unlock (&lock);
93 * Lookup a previously registered meta info structure by its implementor name
96 * Returns: a #GstMetaInfo with @impl or #NULL when no such metainfo
100 gst_meta_get_info (const gchar * impl)
104 g_return_val_if_fail (impl != NULL, NULL);
106 g_static_rw_lock_reader_lock (&lock);
107 info = g_hash_table_lookup (metainfo, impl);
108 g_static_rw_lock_reader_unlock (&lock);
113 /* Timing metadata */
115 meta_timing_copy (GstBuffer * copybuf, GstMetaTiming * meta,
116 GstBuffer * buffer, gsize offset, gsize size)
118 GstMetaTiming *timing;
120 GST_DEBUG ("trans called from buffer %p to %p, meta %p, %u-%u", buffer,
121 copybuf, meta, offset, size);
123 timing = gst_buffer_add_meta_timing (copybuf);
125 /* same offset, copy timestamps */
126 timing->pts = meta->pts;
127 timing->dts = meta->dts;
128 if (size == gst_buffer_get_size (buffer)) {
129 /* same size, copy duration */
130 timing->duration = meta->duration;
133 timing->duration = GST_CLOCK_TIME_NONE;
138 timing->duration = -1;
140 timing->clock_rate = meta->clock_rate;
144 gst_meta_timing_get_info (void)
146 static const GstMetaInfo *meta_info = NULL;
148 if (meta_info == NULL) {
149 meta_info = gst_meta_register ("GstMetaTiming", "GstMetaTiming",
150 sizeof (GstMetaTiming),
151 (GstMetaInitFunction) NULL,
152 (GstMetaFreeFunction) NULL,
153 (GstMetaCopyFunction) meta_timing_copy,
154 (GstMetaTransformFunction) NULL,
155 (GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);