API: add gst_tag_list_get_buffer{_index}

Convenience API, mostly for image tags, so people don't have to
figure out the whole GValue/GstValue thing just for this.
This commit is contained in:
Tim-Philipp Müller 2009-03-26 01:09:03 +00:00
parent 4ef524f5ec
commit c4e10b9535
5 changed files with 117 additions and 0 deletions

View file

@ -2106,6 +2106,8 @@ gst_tag_list_get_pointer
gst_tag_list_get_pointer_index gst_tag_list_get_pointer_index
gst_tag_list_get_date gst_tag_list_get_date
gst_tag_list_get_date_index gst_tag_list_get_date_index
gst_tag_list_get_buffer
gst_tag_list_get_buffer_index
<SUBSECTION Standard> <SUBSECTION Standard>
GST_TAG_LIST GST_TAG_LIST
GST_IS_TAG_LIST GST_IS_TAG_LIST

View file

@ -1494,3 +1494,67 @@ gst_tag_list_get_date_index (const GstTagList * list,
*value = (GDate *) g_value_dup_boxed (v); *value = (GDate *) g_value_dup_boxed (v);
return (*value != NULL); 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);
}

View file

@ -23,6 +23,7 @@
#ifndef __GST_TAGLIST_H__ #ifndef __GST_TAGLIST_H__
#define __GST_TAGLIST_H__ #define __GST_TAGLIST_H__
#include <gst/gstbuffer.h>
#include <gst/gststructure.h> #include <gst/gststructure.h>
#include <gst/glib-compat.h> #include <gst/glib-compat.h>
@ -338,6 +339,13 @@ gboolean gst_tag_list_get_date_index (const GstTagList * list,
const gchar * tag, const gchar * tag,
guint index, guint index,
GDate ** value); 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 */ /* GStreamer core tags */
/** /**

View file

@ -343,6 +343,46 @@ GST_START_TEST (test_set_non_utf8_string)
GST_END_TEST; 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 * static Suite *
gst_tag_suite (void) 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_date_tags);
tcase_add_test (tc_chain, test_type); tcase_add_test (tc_chain, test_type);
tcase_add_test (tc_chain, test_set_non_utf8_string); tcase_add_test (tc_chain, test_set_non_utf8_string);
tcase_add_test (tc_chain, test_buffer_tags);
return s; return s;
} }

View file

@ -880,6 +880,8 @@ EXPORTS
gst_tag_list_free gst_tag_list_free
gst_tag_list_get_boolean gst_tag_list_get_boolean
gst_tag_list_get_boolean_index 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
gst_tag_list_get_char_index gst_tag_list_get_char_index
gst_tag_list_get_date gst_tag_list_get_date