2011-02-25 12:15:25 +00:00
|
|
|
/* 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;
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2012-02-24 09:23:27 +00:00
|
|
|
GQuark _gst_meta_transform_copy;
|
2012-03-01 14:17:37 +00:00
|
|
|
GQuark _gst_meta_tag_memory;
|
2012-02-24 09:23:27 +00:00
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
void
|
2011-08-29 13:34:30 +00:00
|
|
|
_priv_gst_meta_initialize (void)
|
2011-02-25 12:15:25 +00:00
|
|
|
{
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rw_lock_init (&lock);
|
2011-02-25 12:15:25 +00:00
|
|
|
metainfo = g_hash_table_new (g_str_hash, g_str_equal);
|
2012-02-24 09:23:27 +00:00
|
|
|
|
2012-03-02 10:57:52 +00:00
|
|
|
_gst_meta_transform_copy = g_quark_from_static_string ("gst-copy");
|
2012-03-01 14:17:37 +00:00
|
|
|
_gst_meta_tag_memory = g_quark_from_static_string ("memory");
|
2011-02-25 12:15:25 +00:00
|
|
|
}
|
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
/**
|
|
|
|
* gst_meta_api_type_register:
|
|
|
|
* @api: an API to register
|
|
|
|
* @tags: tags for @api
|
|
|
|
*
|
|
|
|
* Register and return a GType for the @api and associate it with
|
|
|
|
* @tags.
|
|
|
|
*
|
|
|
|
* Returns: a unique GType for @api.
|
|
|
|
*/
|
|
|
|
GType
|
|
|
|
gst_meta_api_type_register (const gchar * api, const gchar ** tags)
|
|
|
|
{
|
|
|
|
GType type;
|
|
|
|
|
|
|
|
g_return_val_if_fail (api != NULL, 0);
|
|
|
|
g_return_val_if_fail (tags != NULL, 0);
|
|
|
|
|
2012-03-01 16:39:17 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_META, "register API \"%s\"", api);
|
2012-02-29 16:20:23 +00:00
|
|
|
type = g_pointer_type_register_static (api);
|
|
|
|
|
|
|
|
if (type != 0) {
|
|
|
|
gint i;
|
|
|
|
|
2012-03-01 16:39:17 +00:00
|
|
|
for (i = 0; tags[i]; i++) {
|
|
|
|
GST_CAT_DEBUG (GST_CAT_META, " adding tag \"%s\"", tags[i]);
|
2012-02-29 16:20:23 +00:00
|
|
|
g_type_set_qdata (type, g_quark_from_string (tags[i]),
|
|
|
|
GINT_TO_POINTER (TRUE));
|
2012-03-01 16:39:17 +00:00
|
|
|
}
|
2012-02-29 16:20:23 +00:00
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_meta_api_type_has_tag:
|
|
|
|
* @api: an API
|
|
|
|
* @tag: the tag to check
|
|
|
|
*
|
|
|
|
* Check if @api was registered with @tag.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @api was registered with @tag.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_meta_api_type_has_tag (GType api, GQuark tag)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (api != 0, FALSE);
|
|
|
|
g_return_val_if_fail (tag != 0, FALSE);
|
|
|
|
|
|
|
|
return g_type_get_qdata (api, tag) != NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-25 12:15:25 +00:00
|
|
|
/**
|
2011-11-28 10:15:27 +00:00
|
|
|
* gst_meta_register:
|
2012-02-29 16:20:23 +00:00
|
|
|
* @api: the type of the #GstMeta API
|
2011-11-28 10:15:27 +00:00
|
|
|
* @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
|
2012-02-28 10:34:48 +00:00
|
|
|
* @tags: a NULL terminated array of strings describing what the metadata
|
|
|
|
* contains info about.
|
2011-02-25 12:15:25 +00:00
|
|
|
*
|
2011-11-28 10:15:27 +00:00
|
|
|
* Register a new #GstMeta implementation.
|
2011-02-25 12:15:25 +00:00
|
|
|
*
|
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.
|
2011-02-25 12:15:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const GstMetaInfo *
|
2012-02-29 16:20:23 +00:00
|
|
|
gst_meta_register (GType api, const gchar * impl, gsize size,
|
2011-02-25 12:15:25 +00:00
|
|
|
GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
|
2012-02-29 16:20:23 +00:00
|
|
|
GstMetaTransformFunction transform_func)
|
2011-02-25 12:15:25 +00:00
|
|
|
{
|
|
|
|
GstMetaInfo *info;
|
|
|
|
|
2012-02-29 16:20:23 +00:00
|
|
|
g_return_val_if_fail (api != 0, NULL);
|
2011-02-25 12:15:25 +00:00
|
|
|
g_return_val_if_fail (impl != NULL, NULL);
|
|
|
|
g_return_val_if_fail (size != 0, NULL);
|
|
|
|
|
|
|
|
info = g_slice_new (GstMetaInfo);
|
2012-02-29 16:20:23 +00:00
|
|
|
info->api = api;
|
2011-05-11 17:10:24 +00:00
|
|
|
info->type = g_pointer_type_register_static (impl);
|
2011-02-25 12:15:25 +00:00
|
|
|
info->size = size;
|
|
|
|
info->init_func = init_func;
|
|
|
|
info->free_func = free_func;
|
2011-03-08 16:58:49 +00:00
|
|
|
info->transform_func = transform_func;
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2012-03-01 16:39:17 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_META,
|
|
|
|
"register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT, impl,
|
|
|
|
g_type_name (api), size);
|
2011-02-25 12:15:25 +00:00
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rw_lock_writer_lock (&lock);
|
2011-02-25 12:15:25 +00:00
|
|
|
g_hash_table_insert (metainfo, (gpointer) impl, (gpointer) info);
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rw_lock_writer_unlock (&lock);
|
2011-02-25 12:15:25 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_meta_get_info:
|
2011-03-30 17:01:13 +00:00
|
|
|
* @impl: the name
|
2011-02-25 12:15:25 +00:00
|
|
|
*
|
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-02-25 12:15:25 +00:00
|
|
|
*
|
2011-11-28 10:15:27 +00:00
|
|
|
* Returns: (transfer none): a #GstMetaInfo with @impl, or #NULL when no such
|
|
|
|
* metainfo exists.
|
2011-02-25 12:15:25 +00:00
|
|
|
*/
|
|
|
|
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);
|
2011-02-25 12:15:25 +00:00
|
|
|
info = g_hash_table_lookup (metainfo, impl);
|
2012-01-19 08:27:04 +00:00
|
|
|
g_rw_lock_reader_unlock (&lock);
|
2011-02-25 12:15:25 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|