meta: add default memory metadata

Add a metadata implementation for normall malloced memory.
This commit is contained in:
Wim Taymans 2011-02-27 20:42:15 +01:00
parent 58060d7528
commit 362a724cfb
3 changed files with 105 additions and 3 deletions

View file

@ -107,3 +107,99 @@ gst_meta_get_info (const gchar * impl)
return info;
}
typedef struct
{
guint8 *data;
GFreeFunc free_func;
gsize size;
gsize offset;
} GstMetaMemoryParams;
typedef struct
{
GstMetaMemory memory;
GstMetaMemoryParams params;
} GstMetaMemoryImpl;
static gpointer
meta_memory_mmap (GstMetaMemoryImpl * meta, gsize offset, gsize * size,
GstMetaMapFlags flags)
{
*size = meta->params.size - offset;
return meta->params.data + offset;
}
static gboolean
meta_memory_munmap (GstMetaMemoryImpl * meta, gpointer data, gsize size)
{
return TRUE;
}
static gboolean
meta_memory_init (GstMetaMemoryImpl * meta, GstMetaMemoryParams * params,
GstBuffer * buffer)
{
meta->memory.mmap_func = (GstMetaMapFunc) meta_memory_mmap;
meta->memory.munmap_func = (GstMetaUnmapFunc) meta_memory_munmap;
meta->params = *params;
return TRUE;
}
static void
meta_memory_free (GstMetaMemoryImpl * meta, GstBuffer * buffer)
{
if (meta->params.free_func)
meta->params.free_func (meta->params.data);
}
static void
meta_memory_copy (GstBuffer * copy, GstMetaMemoryImpl * meta,
const GstBuffer * buffer)
{
gst_buffer_add_meta_memory (copy,
g_memdup (meta->params.data, meta->params.size),
g_free, meta->params.size, meta->params.offset);
}
static void
meta_memory_sub (GstBuffer * subbuf, GstMetaMemoryImpl * meta,
GstBuffer * buffer, guint offset, guint size)
{
gst_buffer_add_meta_memory (subbuf,
meta->params.data, NULL, size, meta->params.offset + offset);
}
const GstMetaInfo *
gst_meta_memory_get_info (void)
{
static const GstMetaInfo *meta_info = NULL;
if (meta_info == NULL) {
meta_info = gst_meta_register ("GstMetaMemory", "GstMetaMemoryImpl",
sizeof (GstMetaMemoryImpl),
(GstMetaInitFunction) meta_memory_init,
(GstMetaFreeFunction) meta_memory_free,
(GstMetaCopyFunction) meta_memory_copy,
(GstMetaSubFunction) meta_memory_sub,
(GstMetaSerializeFunction) NULL, (GstMetaDeserializeFunction) NULL);
}
return meta_info;
}
GstMetaMemory *
gst_buffer_add_meta_memory (GstBuffer * buffer, gpointer data,
GFreeFunc free_func, gsize size, gsize offset)
{
GstMeta *meta;
GstMetaMemoryParams params;
params.data = data;
params.free_func = free_func;
params.size = size;
params.offset = offset;
meta = gst_buffer_add_meta (buffer, GST_META_MEMORY_INFO, &params);
return (GstMetaMemory *) meta;
}

View file

@ -148,9 +148,9 @@ const GstMetaInfo * gst_meta_get_info (const gchar * impl);
typedef struct _GstMetaMemory GstMetaMemory;
typedef enum {
GST_META_MAP_NONE,
GST_META_MAP_READ,
GST_META_MAP_WRITE
GST_META_MAP_NONE = 0,
GST_META_MAP_READ = (1 << 0),
GST_META_MAP_WRITE = (1 << 1)
} GstMetaMapFlags;
typedef gpointer (*GstMetaMapFunc) (GstMetaMemory *meta, guint offset, guint *size,
@ -171,6 +171,10 @@ struct _GstMetaMemory
const GstMetaInfo *gst_meta_memory_get_info(void);
#define GST_META_MEMORY_INFO (gst_meta_memory_get_info())
GstMetaMemory * gst_buffer_add_meta_memory (GstBuffer *buffer, gpointer data,
GFreeFunc free_func,
gsize size, gsize offset);
G_END_DECLS
#endif /* __GST_META_H__ */

View file

@ -90,6 +90,7 @@ EXPORTS
gst_bin_remove
gst_bin_remove_many
gst_buffer_add_meta
gst_buffer_add_meta_memory
gst_buffer_copy_flags_get_type
gst_buffer_copy_metadata
gst_buffer_create_sub
@ -573,6 +574,7 @@ EXPORTS
gst_message_type_to_quark
gst_meta_get_info
gst_meta_map_flags_get_type
gst_meta_memory_get_info
gst_meta_register
gst_mini_object_copy
gst_mini_object_flags_get_type