buffer: add gst_buffer_iterate_meta_filtered()

For convenience. Pretty much every user of
gst_buffer_iterate_meta() filters for a specific
api type.

https://bugzilla.gnome.org/show_bug.cgi?id=775727
This commit is contained in:
Tim-Philipp Müller 2016-12-03 13:05:03 +00:00
parent de65b88d13
commit ca4ac71555
4 changed files with 49 additions and 0 deletions

View file

@ -254,6 +254,7 @@ gst_buffer_get_meta
gst_buffer_add_meta
gst_buffer_remove_meta
gst_buffer_iterate_meta
gst_buffer_iterate_meta_filtered
GstBufferForeachMetaFunc
gst_buffer_foreach_meta

View file

@ -2276,6 +2276,49 @@ gst_buffer_iterate_meta (GstBuffer * buffer, gpointer * state)
return NULL;
}
/**
* gst_buffer_iterate_meta_filtered: (skip)
* @buffer: a #GstBuffer
* @state: an opaque state pointer
* @meta_api_type: only return #GstMeta of this type
*
* Retrieve the next #GstMeta of type @meta_api_type after the current one
* according to @state. If @state points to %NULL, the first metadata of
* type @meta_api_type is returned.
*
* @state will be updated with an opaque state pointer
*
* Returns: (transfer none) (nullable): The next #GstMeta of type
* @meta_api_type or %NULL when there are no more items.
*
* Since: 1.12
*/
GstMeta *
gst_buffer_iterate_meta_filtered (GstBuffer * buffer, gpointer * state,
GType meta_api_type)
{
GstMetaItem **meta;
g_return_val_if_fail (buffer != NULL, NULL);
g_return_val_if_fail (state != NULL, NULL);
meta = (GstMetaItem **) state;
if (*meta == NULL)
/* state NULL, move to first item */
*meta = GST_BUFFER_META (buffer);
else
/* state !NULL, move to next item in list */
*meta = (*meta)->next;
while (*meta != NULL && (*meta)->meta.info->api != meta_api_type)
*meta = (*meta)->next;
if (*meta)
return &(*meta)->meta;
else
return NULL;
}
/**
* gst_buffer_foreach_meta:
* @buffer: a #GstBuffer

View file

@ -545,6 +545,10 @@ gboolean gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *met
GstMeta * gst_buffer_iterate_meta (GstBuffer *buffer, gpointer *state);
GstMeta * gst_buffer_iterate_meta_filtered (GstBuffer * buffer,
gpointer * state,
GType meta_api_type);
gboolean gst_buffer_foreach_meta (GstBuffer *buffer,
GstBufferForeachMetaFunc func,
gpointer user_data);

View file

@ -144,6 +144,7 @@ EXPORTS
gst_buffer_is_all_memory_writable
gst_buffer_is_memory_range_writable
gst_buffer_iterate_meta
gst_buffer_iterate_meta_filtered
gst_buffer_list_copy_deep
gst_buffer_list_foreach
gst_buffer_list_get