From ca4ac71555512befd628f9728bbbb0f5c7374d49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 3 Dec 2016 13:05:03 +0000 Subject: [PATCH] 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 --- docs/gst/gstreamer-sections.txt | 1 + gst/gstbuffer.c | 43 +++++++++++++++++++++++++++++++++++++++++ gst/gstbuffer.h | 4 ++++ win32/common/libgstreamer.def | 1 + 4 files changed, 49 insertions(+) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 08534dd..5628d8c 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -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 diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 9fd83be..8252b44 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -2277,6 +2277,49 @@ gst_buffer_iterate_meta (GstBuffer * buffer, gpointer * state) } /** + * 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 * @func: (scope call): a #GstBufferForeachMetaFunc to call diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 41ddbb6..be6fae8 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -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); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index fb37e7e..1f0fe3f 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -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 -- 2.7.4