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; GstMeta *meta = &walk->meta;
const GstMetaInfo *info = meta->info; const GstMetaInfo *info = meta->info;
if (info->copy_func) if (info->transform_func) {
info->copy_func (dest, meta, src, offset, size); 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 GHashTable *metainfo = NULL;
static GRWLock lock; static GRWLock lock;
GQuark _gst_meta_transform_copy;
void void
_priv_gst_meta_initialize (void) _priv_gst_meta_initialize (void)
{ {
g_rw_lock_init (&lock); g_rw_lock_init (&lock);
metainfo = g_hash_table_new (g_str_hash, g_str_equal); 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 * @size: the size of the #GstMeta structure
* @init_func: a #GstMetaInitFunction * @init_func: a #GstMetaInitFunction
* @free_func: a #GstMetaFreeFunction * @free_func: a #GstMetaFreeFunction
* @copy_func: a #GstMetaCopyFunction
* @transform_func: a #GstMetaTransformFunction * @transform_func: a #GstMetaTransformFunction
* *
* Register a new #GstMeta implementation. * Register a new #GstMeta implementation.
@ -63,7 +66,7 @@ _priv_gst_meta_initialize (void)
const GstMetaInfo * const GstMetaInfo *
gst_meta_register (const gchar * api, const gchar * impl, gsize size, gst_meta_register (const gchar * api, const gchar * impl, gsize size,
GstMetaInitFunction init_func, GstMetaFreeFunction free_func, GstMetaInitFunction init_func, GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func, GstMetaTransformFunction transform_func) GstMetaTransformFunction transform_func)
{ {
GstMetaInfo *info; GstMetaInfo *info;
@ -77,7 +80,6 @@ gst_meta_register (const gchar * api, const gchar * impl, gsize size,
info->size = size; info->size = size;
info->init_func = init_func; info->init_func = init_func;
info->free_func = free_func; info->free_func = free_func;
info->copy_func = copy_func;
info->transform_func = transform_func; info->transform_func = transform_func;
GST_DEBUG ("register \"%s\" implementing \"%s\" of size %" G_GSIZE_FORMAT, 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); typedef void (*GstMetaFreeFunction) (GstMeta *meta, GstBuffer *buffer);
/** /**
* GstMetaCopyFunction: * gst_meta_transform_copy:
* @dest: a destination #GstBuffer
* @meta: a #GstMeta
* @buffer: a #GstBuffer
* @offset: an offset
* @size: a size
* *
* Function called when the region at @offset and @size in @buffer is copied * GQuark for the "copy" transform.
* into @dest. The function should update the metadata on @dest using @meta.
*/ */
typedef void (*GstMetaCopyFunction) (GstBuffer *dest, GstMeta *meta, GST_EXPORT GQuark _gst_meta_transform_copy;
GstBuffer *buffer, gsize offset, gsize size);
#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: * GstMetaTransformFunction:
* @transbuf: a #GstBuffer * @transbuf: a #GstBuffer
* @meta: a #GstMeta * @meta: a #GstMeta
* @buffer: a #GstBuffer * @buffer: a #GstBuffer
* @type: the transform type
* @data: transform specific data. * @data: transform specific data.
* *
* Function called for each @meta in @buffer as a result of performing a * Function called for each @meta in @buffer as a result of performing a
* transformation on @transbuf. Additional type specific transform data * transformation on @transbuf. Additional @type specific transform data
* is passed to the function. * is passed to the function as @data.
* *
* Implementations should check the type of the transform @data and parse * Implementations should check the @type of the transform and parse
* additional type specific field that should be used to perform the transform. * additional type specific fields in @data that should be used to update
* the metadata on @transbuf.
*/ */
typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta, typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf,
GstBuffer *buffer, gpointer data); GstMeta *meta, GstBuffer *buffer,
GQuark type, gpointer data);
/** /**
* GstMetaInfo: * GstMetaInfo:
@ -149,7 +160,6 @@ typedef void (*GstMetaTransformFunction) (GstBuffer *transbuf, GstMeta *meta,
* @size: size of the metadata * @size: size of the metadata
* @init_func: function for initializing the metadata * @init_func: function for initializing the metadata
* @free_func: function for freeing the metadata * @free_func: function for freeing the metadata
* @copy_func: function for copying the metadata
* @transform_func: function for transforming the metadata * @transform_func: function for transforming the metadata
* *
* The #GstMetaInfo provides information about a specific metadata * The #GstMetaInfo provides information about a specific metadata
@ -162,7 +172,6 @@ struct _GstMetaInfo {
GstMetaInitFunction init_func; GstMetaInitFunction init_func;
GstMetaFreeFunction free_func; GstMetaFreeFunction free_func;
GstMetaCopyFunction copy_func;
GstMetaTransformFunction transform_func; GstMetaTransformFunction transform_func;
/*< private >*/ /*< private >*/
@ -173,7 +182,6 @@ const GstMetaInfo * gst_meta_register (const gchar *api, const gchar *im
gsize size, gsize size,
GstMetaInitFunction init_func, GstMetaInitFunction init_func,
GstMetaFreeFunction free_func, GstMetaFreeFunction free_func,
GstMetaCopyFunction copy_func,
GstMetaTransformFunction transform_func); GstMetaTransformFunction transform_func);
const GstMetaInfo * gst_meta_get_info (const gchar * impl); 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 static void
net_address_meta_copy (GstBuffer * copybuf, GstNetAddressMeta * meta, net_address_meta_transform (GstBuffer * transbuf, GstNetAddressMeta * meta,
GstBuffer * buffer, gsize offset, gsize size) 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 static void
@ -66,8 +67,7 @@ gst_net_address_meta_get_info (void)
sizeof (GstNetAddressMeta), sizeof (GstNetAddressMeta),
(GstMetaInitFunction) net_address_meta_init, (GstMetaInitFunction) net_address_meta_init,
(GstMetaFreeFunction) net_address_meta_free, (GstMetaFreeFunction) net_address_meta_free,
(GstMetaCopyFunction) net_address_meta_copy, (GstMetaTransformFunction) net_address_meta_transform);
(GstMetaTransformFunction) NULL);
} }
return meta_info; return meta_info;
} }

View file

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

View file

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