From 9ee11a2af41ec6f37bbf37e7990d129c357fb809 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 17 Jun 2010 11:39:04 -0300 Subject: [PATCH] taglist: add gst_tag_list_peek_string_index to avoid a copy Adds a variation of the _get_string_index function that doesn't copy the string. API: gst_tag_list_peek_string_index https://bugzilla.gnome.org/show_bug.cgi?id=621896 --- docs/gst/gstreamer-sections.txt | 1 + gst/gsttaglist.c | 38 ++++++++++++++++++++++++++++++++++++++ gst/gsttaglist.h | 4 ++++ win32/common/libgstreamer.def | 1 + 4 files changed, 44 insertions(+) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 79f6064..9be7cb1 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -2255,6 +2255,7 @@ gst_tag_list_get_double gst_tag_list_get_double_index gst_tag_list_get_string gst_tag_list_get_string_index +gst_tag_list_peek_string_index gst_tag_list_get_pointer gst_tag_list_get_pointer_index gst_tag_list_get_date diff --git a/gst/gsttaglist.c b/gst/gsttaglist.c index 644b387..d31787e 100644 --- a/gst/gsttaglist.c +++ b/gst/gsttaglist.c @@ -1601,6 +1601,44 @@ TAG_MERGE_FUNCS (pointer, gpointer, (*value != NULL)) */ TAG_MERGE_FUNCS (string, gchar *, (*value != NULL && **value != '\0')) +/* + *FIXME 0.11: Instead of _peek (non-copy) and _get (copy), we could have + * _get (non-copy) and _dup (copy) for strings, seems more + * widely used + */ +/** + * gst_tag_list_peek_string_index: + * @list: a #GstTagList to get the tag from + * @tag: tag to read out + * @index: number of entry to read out + * @value: location for the result + * + * Peeks at the value that is at the given index for the given tag in the given + * list. + * + * The resulting string in @value will be in UTF-8 encoding and doesn't need + * to be freed by the caller. The returned string is also guaranteed to + * be non-NULL and non-empty. + * + * Returns: TRUE, if a value was set, FALSE if the tag didn't exist in the + * given list. + */ +gboolean +gst_tag_list_peek_string_index (const GstTagList * list, + const gchar * tag, guint index, const gchar ** value) +{ + const GValue *v; + + g_return_val_if_fail (GST_IS_TAG_LIST (list), FALSE); + g_return_val_if_fail (tag != NULL, FALSE); + g_return_val_if_fail (value != NULL, FALSE); + + if ((v = gst_tag_list_get_value_index (list, tag, index)) == NULL) + return FALSE; + *value = g_value_get_string (v); + return *value != NULL && **value != '\0'; +} + /** * gst_tag_list_get_date: * @list: a #GstTagList to get the tag from diff --git a/gst/gsttaglist.h b/gst/gsttaglist.h index 1d0971c..52eb134 100644 --- a/gst/gsttaglist.h +++ b/gst/gsttaglist.h @@ -345,6 +345,10 @@ gboolean gst_tag_list_get_string_index (const GstTagList * list, const gchar * tag, guint index, gchar ** value); +gboolean gst_tag_list_peek_string_index (const GstTagList * list, + const gchar * tag, + guint index, + const gchar ** value); gboolean gst_tag_list_get_pointer (const GstTagList * list, const gchar * tag, gpointer * value); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 1146b2a..91ac1d8 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -991,6 +991,7 @@ EXPORTS gst_tag_list_new gst_tag_list_new_full gst_tag_list_new_full_valist + gst_tag_list_peek_string_index gst_tag_list_remove_tag gst_tag_merge_mode_get_type gst_tag_merge_strings_with_comma -- 2.7.4