API: add gst_tag_list_get_buffer{_index}
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 26 Mar 2009 01:09:03 +0000 (01:09 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 26 Mar 2009 14:21:10 +0000 (14:21 +0000)
Convenience API, mostly for image tags, so people don't have to
figure out the whole GValue/GstValue thing just for this.

docs/gst/gstreamer-sections.txt
gst/gsttaglist.c
gst/gsttaglist.h
tests/check/gst/gsttag.c
win32/common/libgstreamer.def

index 63e9799..96cc84f 100644 (file)
@@ -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
 <SUBSECTION Standard>
 GST_TAG_LIST
 GST_IS_TAG_LIST
index 537d538..78ff003 100644 (file)
@@ -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);
+}
index 973a0c6..bfb5a10 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __GST_TAGLIST_H__
 #define __GST_TAGLIST_H__
 
+#include <gst/gstbuffer.h>
 #include <gst/gststructure.h>
 #include <gst/glib-compat.h>
 
@@ -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 */
 /**
index c577c25..4adc59a 100644 (file)
@@ -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;
 }
index f91b80a..e00c644 100644 (file)
@@ -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