diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 63e97993d9..96cc84f0d5 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -2106,6 +2106,8 @@ gst_tag_list_get_pointer gst_tag_list_get_pointer_index gst_tag_list_get_date gst_tag_list_get_date_index +gst_tag_list_get_buffer +gst_tag_list_get_buffer_index GST_TAG_LIST GST_IS_TAG_LIST diff --git a/gst/gsttaglist.c b/gst/gsttaglist.c index 537d538f70..78ff0037f9 100644 --- a/gst/gsttaglist.c +++ b/gst/gsttaglist.c @@ -1494,3 +1494,67 @@ gst_tag_list_get_date_index (const GstTagList * list, *value = (GDate *) g_value_dup_boxed (v); return (*value != NULL); } + +/** + * gst_tag_list_get_buffer: + * @list: a #GstTagList to get the tag from + * @tag: tag to read out + * @value: address of a GstBuffer pointer variable to store the result into + * + * Copies the first buffer for the given tag in the taglist into the variable + * pointed to by @value. Free the buffer with gst_buffer_unref() when it is + * no longer needed. + * + * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the + * given list or if it was #NULL. + * + * Since: 0.10.23 + */ +gboolean +gst_tag_list_get_buffer (const GstTagList * list, const gchar * tag, + GstBuffer ** value) +{ + GValue v = { 0, }; + + 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 (!gst_tag_list_copy_value (&v, list, tag)) + return FALSE; + *value = (GstBuffer *) gst_value_dup_mini_object (&v); + g_value_unset (&v); + return (*value != NULL); +} + +/** + * gst_tag_list_get_buffer_index: + * @list: a #GstTagList to get the tag from + * @tag: tag to read out + * @index: number of entry to read out + * @value: address of a GstBuffer pointer variable to store the result into + * + * Gets the buffer that is at the given index for the given tag in the given + * list and copies it into the variable pointed to by @value. Free the buffer + * with gst_buffer_unref() when it is no longer needed. + * + * Returns: TRUE, if a buffer was copied, FALSE if the tag didn't exist in the + * given list or if it was #NULL. + * + * Since: 0.10.23 + */ +gboolean +gst_tag_list_get_buffer_index (const GstTagList * list, + const gchar * tag, guint index, GstBuffer ** 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 = (GstBuffer *) gst_value_dup_mini_object (v); + return (*value != NULL); +} diff --git a/gst/gsttaglist.h b/gst/gsttaglist.h index 973a0c68ab..bfb5a10dd8 100644 --- a/gst/gsttaglist.h +++ b/gst/gsttaglist.h @@ -23,6 +23,7 @@ #ifndef __GST_TAGLIST_H__ #define __GST_TAGLIST_H__ +#include #include #include @@ -338,6 +339,13 @@ gboolean gst_tag_list_get_date_index (const GstTagList * list, const gchar * tag, guint index, GDate ** value); +gboolean gst_tag_list_get_buffer (const GstTagList * list, + const gchar * tag, + GstBuffer ** value); +gboolean gst_tag_list_get_buffer_index (const GstTagList * list, + const gchar * tag, + guint index, + GstBuffer ** value); /* GStreamer core tags */ /** diff --git a/tests/check/gst/gsttag.c b/tests/check/gst/gsttag.c index c577c25daa..4adc59ae79 100644 --- a/tests/check/gst/gsttag.c +++ b/tests/check/gst/gsttag.c @@ -343,6 +343,46 @@ GST_START_TEST (test_set_non_utf8_string) GST_END_TEST; +GST_START_TEST (test_buffer_tags) +{ + GstTagList *tags; + GstBuffer *buf1, *buf2; + + tags = gst_tag_list_new (); + buf1 = gst_buffer_new_and_alloc (222); + buf2 = gst_buffer_new_and_alloc (100); + gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_IMAGE, buf1, + GST_TAG_PREVIEW_IMAGE, buf2, NULL); + gst_buffer_unref (buf1); + gst_buffer_unref (buf2); + + buf1 = buf2 = NULL; + fail_if (!gst_tag_list_get_buffer (tags, GST_TAG_IMAGE, &buf1)); + gst_buffer_unref (buf1); + fail_if (!gst_tag_list_get_buffer (tags, GST_TAG_PREVIEW_IMAGE, &buf2)); + gst_buffer_unref (buf2); + + fail_if (gst_tag_list_get_buffer_index (tags, GST_TAG_IMAGE, 1, &buf1)); + fail_if (gst_tag_list_get_buffer_index (tags, GST_TAG_IMAGE, 2, &buf1)); + fail_if (gst_tag_list_get_buffer_index (tags, GST_TAG_PREVIEW_IMAGE, 1, + &buf1)); + fail_if (gst_tag_list_get_buffer_index (tags, GST_TAG_PREVIEW_IMAGE, 2, + &buf1)); + + fail_if (!gst_tag_list_get_buffer_index (tags, GST_TAG_IMAGE, 0, &buf1)); + fail_if (!gst_tag_list_get_buffer_index (tags, GST_TAG_PREVIEW_IMAGE, 0, + &buf2)); + fail_unless_equals_int (GST_BUFFER_SIZE (buf1), 222); + fail_unless_equals_int (GST_BUFFER_SIZE (buf2), 100); + + gst_buffer_unref (buf1); + gst_buffer_unref (buf2); + + gst_tag_list_free (tags); +} + +GST_END_TEST; + static Suite * gst_tag_suite (void) { @@ -356,6 +396,7 @@ gst_tag_suite (void) tcase_add_test (tc_chain, test_date_tags); tcase_add_test (tc_chain, test_type); tcase_add_test (tc_chain, test_set_non_utf8_string); + tcase_add_test (tc_chain, test_buffer_tags); return s; } diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index f91b80aad1..e00c644798 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -880,6 +880,8 @@ EXPORTS gst_tag_list_free gst_tag_list_get_boolean gst_tag_list_get_boolean_index + gst_tag_list_get_buffer + gst_tag_list_get_buffer_index gst_tag_list_get_char gst_tag_list_get_char_index gst_tag_list_get_date