meta: flesh out the metadata transform

Flesh out the transform method. Add a type and extra info to the transform
function so that implementation can transform the metadata.
Remove the copy function and replace with the more generic transform.
This commit is contained in:
Wim Taymans 2012-02-24 10:23:27 +01:00
parent d6f31dfce5
commit 6b22a63f1b
6 changed files with 71 additions and 49 deletions

View file

@ -359,8 +359,15 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
GstMeta *meta = &walk->meta;
const GstMetaInfo *info = meta->info;
if (info->copy_func)
info->copy_func (dest, meta, src, offset, size);
if (info->transform_func) {
GstMetaTransformCopy copy_data;
copy_data.offset = offset;
copy_data.size = size;
info->transform_func (dest, meta, src,
_gst_meta_transform_copy, &copy_data);
}
}
}
}

View file

@ -35,11 +35,15 @@
static GHashTable *metainfo = NULL;
static GRWLock lock;
GQuark _gst_meta_transform_copy;
void
_priv_gst_meta_initialize (void)
{
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");
}
/**
@ -49,7 +53,6 @@ _priv_gst_meta_initialize (void)
* @size: the size of the #GstMeta structure
* @init_func: a #GstMetaInitFunction
* @free_func: a #GstMetaFreeFunction
* @copy_func: a #GstMetaCopyFunction
* @transform_func: a #GstMetaTransformFunction
*
* Register a new #GstMeta implementation.
@ -63,7 +66,7 @@ _priv_gst_meta_initialize (void)
const GstMetaInfo *
gst_meta_register (const gchar * api, const gchar * impl, gsize size,
GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func, GstMetaTransformFunction transform_func)
GstMetaTransformFunction transform_func)
{
GstMetaInfo *info;
@ -77,7 +80,6 @@ gst_meta_register (const gchar * api, const gchar * impl, gsize size,
info->size = size;
info->init_func = init_func;
info->free_func = free_func;
info->copy_func = copy_func;
info->transform_func = transform_func;
GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT,

View file

@ -113,34 +113,45 @@ typedef gboolean (*GstMetaInitFunction) (GstMeta *meta, gpointer params, GstBuff
typedef void (*GstMetaFreeFunction) (GstMeta *meta, GstBuffer *buffer);
/**
* GstMetaCopyFunction:
* @dest: a destination #GstBuffer
* @meta: a #GstMeta
* @buffer: a #GstBuffer
* @offset: an offset
* @size: a size
* gst_meta_transform_copy:
*
* Function called when the region at @offset and @size in @buffer is copied
* into @dest. The function should update the metadata on @dest using @meta.
* GQuark for the "copy" transform.
*/
typedef void (*GstMetaCopyFunction) (GstBuffer *dest, GstMeta *meta,
GstBuffer *buffer, gsize offset, gsize size);
GST_EXPORT GQuark _gst_meta_transform_copy;
#define GST_META_TRANSFORM_IS_COPY(type) ((type) == _gst_meta_transform_copy)
/**
* GstMetaTransformDataCopy:
* @offset: the offset to copy
* @size: the size to copy
*
* Extra data passed to a "copy" transform #GstMetaTransformFunction.
*/
typedef struct {
gsize offset;
gsize size;
} GstMetaTransformCopy;
/**
* GstMetaTransformFunction:
* @transbuf: a #GstBuffer
* @meta: a #GstMeta
* @buffer: a #GstBuffer
* @type: the transform type
* @data: transform specific data.
*
* Function called for each @meta in @buffer as a result of performing a
* transformation on @transbuf. Additional type specific transform data
* is passed to the function.
* transformation on @transbuf. Additional @type specific transform data
* is passed to the function as @data.
*
* Implementations should check the type of the transform @data and parse
* additional type specific field that should be used to perform the transform.
* Implementations should check the @type of the transform and parse
* additional type specific fields in @data that should be used to update
* the metadata on @transbuf.
*/
typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
GstBuffer *buffer, gpointer data);
typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf,
GstMeta *meta, GstBuffer *buffer,
GQuark type, gpointer data);
/**
* GstMetaInfo:
@ -149,7 +160,6 @@ typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
* @size: size of the metadata
* @init_func: function for initializing the metadata
* @free_func: function for freeing the metadata
* @copy_func: function for copying the metadata
* @transform_func: function for transforming the metadata
*
* The #GstMetaInfo provides information about a specific metadata
@ -162,7 +172,6 @@ struct _GstMetaInfo {
GstMetaInitFunction init_func;
GstMetaFreeFunction free_func;
GstMetaCopyFunction copy_func;
GstMetaTransformFunction transform_func;
/*< private >*/
@ -173,7 +182,6 @@ const GstMetaInfo * gst_meta_register (const gchar *api, const gchar *im
gsize size,
GstMetaInitFunction init_func,
GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func,
GstMetaTransformFunction transform_func);
const GstMetaInfo * gst_meta_get_info (const gchar * impl);

View file

@ -42,10 +42,11 @@ net_address_meta_init (GstNetAddressMeta * meta, gpointer params,
}
static void
net_address_meta_copy (GstBuffer * copybuf, GstNetAddressMeta * meta,
GstBuffer * buffer, gsize offset, gsize size)
net_address_meta_transform (GstBuffer * transbuf, GstNetAddressMeta * meta,
GstBuffer * buffer, GQuark type, gpointer data)
{
gst_buffer_add_net_address_meta (copybuf, meta->addr);
/* we always copy no matter what transform */
gst_buffer_add_net_address_meta (transbuf, meta->addr);
}
static void
@ -66,8 +67,7 @@ gst_net_address_meta_get_info (void)
sizeof (GstNetAddressMeta),
(GstMetaInitFunction) net_address_meta_init,
(GstMetaFreeFunction) net_address_meta_free,
(GstMetaCopyFunction) net_address_meta_copy,
(GstMetaTransformFunction) NULL);
(GstMetaTransformFunction) net_address_meta_transform);
}
return meta_info;
}

View file

@ -80,32 +80,36 @@ test_free_func (GstMetaTest * meta, GstBuffer * buffer)
}
static void
test_copy_func (GstBuffer * copybuf, GstMetaTest * meta,
GstBuffer * buffer, gsize offset, gsize size)
test_transform_func (GstBuffer * transbuf, GstMetaTest * meta,
GstBuffer * buffer, GQuark type, gpointer data)
{
GstMetaTest *test;
GST_DEBUG ("copy called from buffer %p to %p, meta %p, %u-%u", buffer,
copybuf, meta, offset, size);
GST_DEBUG ("transform %s called from buffer %p to %p, meta %p",
g_quark_to_string (type), buffer, transbuf, meta);
test = GST_META_TEST_ADD (copybuf);
if (offset == 0) {
/* same offset, copy timestamps */
test->pts = meta->pts;
test->dts = meta->dts;
if (size == gst_buffer_get_size (buffer)) {
/* same size, copy duration */
test->duration = meta->duration;
if (GST_META_TRANSFORM_IS_COPY (type)) {
GstMetaTransformCopy *copy_data = data;
test = GST_META_TEST_ADD (transbuf);
if (copy_data->offset == 0) {
/* same offset, copy timestamps */
test->pts = meta->pts;
test->dts = meta->dts;
if (copy_data->size == gst_buffer_get_size (buffer)) {
/* same size, copy duration */
test->duration = meta->duration;
} else {
/* else clear */
test->duration = GST_CLOCK_TIME_NONE;
}
} else {
/* else clear */
test->duration = GST_CLOCK_TIME_NONE;
test->pts = -1;
test->dts = -1;
test->duration = -1;
}
} else {
test->pts = -1;
test->dts = -1;
test->duration = -1;
test->clock_rate = meta->clock_rate;
}
test->clock_rate = meta->clock_rate;
}
static const GstMetaInfo *
@ -118,7 +122,7 @@ gst_meta_test_get_info (void)
sizeof (GstMetaTest),
(GstMetaInitFunction) test_init_func,
(GstMetaFreeFunction) test_free_func,
(GstMetaCopyFunction) test_copy_func, (GstMetaTransformFunction) NULL);
(GstMetaTransformFunction) test_transform_func);
}
return meta_test_info;
}

View file

@ -43,6 +43,7 @@ EXPORTS
_gst_disable_registry_cache DATA
_gst_element_error_printf
_gst_event_type DATA
_gst_meta_transform_copy DATA
_gst_plugin_loader_client_run
_gst_sample_type DATA
_gst_structure_type DATA