mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-02 16:52:42 +00:00
buffer: add foreach function for the metadata
This commit is contained in:
parent
974c708041
commit
87ada5664a
2 changed files with 81 additions and 0 deletions
|
@ -1618,3 +1618,59 @@ gst_buffer_iterate_meta (GstBuffer * buffer, gpointer * state)
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_buffer_foreach_meta:
|
||||||
|
* @buffer: a #GstBuffer
|
||||||
|
* @func: (scope call): a #GstBufferForeachMetaFunc to call
|
||||||
|
* @user_data: (closure): user data passed to @func
|
||||||
|
*
|
||||||
|
* Call @func with @user_data for each meta in @buffer.
|
||||||
|
*
|
||||||
|
* @func can modify the passed meta pointer or its contents. The return value
|
||||||
|
* of @func define if this function returns or if the remaining metadata items
|
||||||
|
* in the buffer should be skipped.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_buffer_foreach_meta (GstBuffer * buffer, GstBufferForeachMetaFunc func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GstMetaItem *walk, *prev, *next;
|
||||||
|
|
||||||
|
g_return_if_fail (buffer != NULL);
|
||||||
|
g_return_if_fail (func != NULL);
|
||||||
|
|
||||||
|
/* find the metadata and delete */
|
||||||
|
prev = GST_BUFFER_META (buffer);
|
||||||
|
for (walk = prev; walk; walk = next) {
|
||||||
|
GstMeta *m, *new;
|
||||||
|
gboolean res;
|
||||||
|
|
||||||
|
m = new = &walk->meta;
|
||||||
|
next = walk->next;
|
||||||
|
|
||||||
|
res = func (buffer, &new, user_data);
|
||||||
|
|
||||||
|
if (new == NULL) {
|
||||||
|
const GstMetaInfo *info = m->info;
|
||||||
|
|
||||||
|
GST_CAT_DEBUG (GST_CAT_BUFFER, "remove metadata %p (%s)", m,
|
||||||
|
g_type_name (info->type));
|
||||||
|
|
||||||
|
/* remove from list */
|
||||||
|
if (GST_BUFFER_META (buffer) == walk)
|
||||||
|
GST_BUFFER_META (buffer) = next;
|
||||||
|
else
|
||||||
|
prev->next = next;
|
||||||
|
|
||||||
|
/* call free_func if any */
|
||||||
|
if (info->free_func)
|
||||||
|
info->free_func (m, buffer);
|
||||||
|
|
||||||
|
/* and free the slice */
|
||||||
|
g_slice_free1 (ITEM_SIZE (info), walk);
|
||||||
|
}
|
||||||
|
if (!res)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -490,6 +490,27 @@ GstBuffer* gst_buffer_span (GstBuffer *buf1, gsize offset,
|
||||||
/* metadata */
|
/* metadata */
|
||||||
#include <gst/gstmeta.h>
|
#include <gst/gstmeta.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstBufferMetaFunc:
|
||||||
|
* @buffer: a #GstBuffer
|
||||||
|
* @meta: a pointer to a #GstMeta
|
||||||
|
* @user_data: user data passed to gst_buffer_foreach_meta()
|
||||||
|
*
|
||||||
|
* A function that will be called from gst_buffer_foreach_meta(). The @meta
|
||||||
|
* field will point to a the reference of the meta.
|
||||||
|
*
|
||||||
|
* @buffer should not be modified from this callback.
|
||||||
|
*
|
||||||
|
* When this function returns %TRUE, the next meta will be
|
||||||
|
* returned. When %FALSE is returned, gst_buffer_foreach_meta() will return.
|
||||||
|
*
|
||||||
|
* When @meta is set to NULL, the item will be removed from the buffer.
|
||||||
|
*
|
||||||
|
* Returns: %FALSE when gst_buffer_foreach_meta() should stop
|
||||||
|
*/
|
||||||
|
typedef gboolean (*GstBufferForeachMetaFunc) (GstBuffer *buffer, GstMeta **meta,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
GstMeta * gst_buffer_get_meta (GstBuffer *buffer, const GstMetaInfo *info);
|
GstMeta * gst_buffer_get_meta (GstBuffer *buffer, const GstMetaInfo *info);
|
||||||
GstMeta * gst_buffer_add_meta (GstBuffer *buffer, const GstMetaInfo *info,
|
GstMeta * gst_buffer_add_meta (GstBuffer *buffer, const GstMetaInfo *info,
|
||||||
gpointer params);
|
gpointer params);
|
||||||
|
@ -497,6 +518,10 @@ gboolean gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *met
|
||||||
|
|
||||||
GstMeta * gst_buffer_iterate_meta (GstBuffer *buffer, gpointer *state);
|
GstMeta * gst_buffer_iterate_meta (GstBuffer *buffer, gpointer *state);
|
||||||
|
|
||||||
|
void gst_buffer_foreach_meta (GstBuffer *buffer,
|
||||||
|
GstBufferForeachMetaFunc func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_value_set_buffer:
|
* gst_value_set_buffer:
|
||||||
* @v: a #GValue to receive the data
|
* @v: a #GValue to receive the data
|
||||||
|
|
Loading…
Reference in a new issue