gstreamer/gst/gstmeta.c

153 lines
4 KiB
C
Raw Normal View History

/* GStreamer
* Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
*
* gstmeta.c: metadata operations
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* SECTION:gstmeta
* @short_description: Buffer metadata
*
* Last reviewed on December 17th, 2009 (0.10.26)
*/
#include "gst_private.h"
#include "gstbuffer.h"
#include "gstmeta.h"
#include "gstinfo.h"
#include "gstutils.h"
static GHashTable *metainfo = NULL;
2012-01-19 08:27:04 +00:00
static GRWLock lock;
GQuark _gst_meta_transform_copy;
void
_priv_gst_meta_initialize (void)
{
2012-01-19 08:27:04 +00:00
g_rw_lock_init (&lock);
metainfo = g_hash_table_new (g_str_hash, g_str_equal);
_gst_meta_transform_copy = g_quark_from_static_string ("copy");
}
/**
2011-11-28 10:15:27 +00:00
* gst_meta_register:
* @api: the name of the #GstMeta API
* @impl: the name of the #GstMeta implementation
* @size: the size of the #GstMeta structure
* @init_func: a #GstMetaInitFunction
* @free_func: a #GstMetaFreeFunction
* @transform_func: a #GstMetaTransformFunction
* @tags: a NULL terminated array of strings describing what the metadata
* contains info about.
*
2011-11-28 10:15:27 +00:00
* Register a new #GstMeta implementation.
*
2011-11-28 10:15:27 +00:00
* The same @info can be retrieved later with gst_meta_get_info() by using
* @impl as the key.
*
* Returns: (transfer none): a #GstMetaInfo that can be used to access metadata.
*/
const GstMetaInfo *
gst_meta_register (const gchar * api, const gchar * impl, gsize size,
GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
GstMetaTransformFunction transform_func, const gchar ** tags)
{
GstMetaInfo *info;
guint len, i;
GQuark *qtags;
g_return_val_if_fail (api != NULL, NULL);
g_return_val_if_fail (impl != NULL, NULL);
g_return_val_if_fail (size != 0, NULL);
g_return_val_if_fail (tags != NULL, NULL);
info = g_slice_new (GstMetaInfo);
info->api = g_quark_from_string (api);
info->type = g_pointer_type_register_static (impl);
info->size = size;
info->init_func = init_func;
info->free_func = free_func;
info->transform_func = transform_func;
len = g_strv_length ((gchar **) tags);
qtags = g_new0 (GQuark, len);
for (i = 0; i < len; i++)
qtags[i] = g_quark_from_static_string (tags[i]);
info->tags = qtags;
GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,
api, impl, size);
2012-01-19 08:27:04 +00:00
g_rw_lock_writer_lock (&lock);
g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
2012-01-19 08:27:04 +00:00
g_rw_lock_writer_unlock (&lock);
return info;
}
/**
* gst_meta_get_info:
2011-03-30 17:01:13 +00:00
* @impl: the name
*
2011-11-28 10:15:27 +00:00
* Lookup a previously registered meta info structure by its implementation name
2011-03-30 17:01:13 +00:00
* @impl.
*
2011-11-28 10:15:27 +00:00
* Returns: (transfer none): a #GstMetaInfo with @impl, or #NULL when no such
* metainfo exists.
*/
const GstMetaInfo *
gst_meta_get_info (const gchar * impl)
{
GstMetaInfo *info;
g_return_val_if_fail (impl != NULL, NULL);
2012-01-19 08:27:04 +00:00
g_rw_lock_reader_lock (&lock);
info = g_hash_table_lookup (metainfo, impl);
2012-01-19 08:27:04 +00:00
g_rw_lock_reader_unlock (&lock);
return info;
}
2012-02-28 11:52:00 +00:00
/*
* gst_meta_info_has_tag:
* @info: a #GstMetaInfo
* @tag: a #GQuark
*
* Check if @info contains @tag.
*
* Returns: %TRUE when @info contains @tag.
*/
gboolean
gst_meta_info_has_tag (const GstMetaInfo * info, GQuark tag)
{
gint i;
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (tag != 0, FALSE);
for (i = 0; info->tags[i]; i++)
if (info->tags[i] == tag)
return TRUE;
return FALSE;
}