gstcaps: New gst_caps_steal_structure() method
authorEdward Hervey <bilboed@bilboed.com>
Mon, 14 Jun 2010 09:39:40 +0000 (11:39 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Mon, 14 Jun 2010 11:16:18 +0000 (13:16 +0200)
This allows removing structures from caps without them being freed. Helpful when
plugins need to move around structures without having to do an expensive structure
copy.

API:gst_caps_steal_structure

https://bugzilla.gnome.org/show_bug.cgi?id=621527

docs/gst/gstreamer-sections.txt
gst/gstcaps.c
gst/gstcaps.h
win32/common/libgstreamer.def

index 692106a..79f6064 100644 (file)
@@ -288,6 +288,7 @@ gst_caps_append
 gst_caps_merge
 gst_caps_append_structure
 gst_caps_remove_structure
+gst_caps_steal_structure
 gst_caps_merge_structure
 gst_caps_get_size
 gst_caps_get_structure
index 7f59aaf..ebc672c 100644 (file)
@@ -529,6 +529,28 @@ gst_caps_remove_and_get_structure (GstCaps * caps, guint idx)
   return s;
 }
 
+/**
+ * gst_caps_steal_structure:
+ * @caps: the #GstCaps to retrieve from
+ * @idx: Index of the structure to retrieve
+ *
+ * Retrieves the stucture with the given index from the list of structures
+ * contained in @caps. The caller becomes the owner of the returned structure.
+ *
+ * Returns: a pointer to the #GstStructure corresponding to @index.
+ */
+GstStructure *
+gst_caps_steal_structure (GstCaps * caps, guint idx)
+{
+  g_return_val_if_fail (caps != NULL, NULL);
+  g_return_val_if_fail (IS_WRITABLE (caps), NULL);
+
+  if (G_UNLIKELY (idx >= caps->structs->len))
+    return NULL;
+
+  return gst_caps_remove_and_get_structure (caps, idx);
+}
+
 static gboolean
 gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
     gpointer data)
index 35a1fde..eca5f17 100644 (file)
@@ -205,6 +205,8 @@ void              gst_caps_merge_structure         (GstCaps       *caps,
 guint             gst_caps_get_size                (const GstCaps *caps);
 GstStructure *    gst_caps_get_structure           (const GstCaps *caps,
                                                     guint          index);
+GstStructure *    gst_caps_steal_structure         (GstCaps *caps,
+                                                    guint          index);
 GstCaps *         gst_caps_copy_nth                (const GstCaps *caps, guint nth);
 void              gst_caps_truncate                (GstCaps       *caps);
 void              gst_caps_set_value               (GstCaps       *caps,
index ad8d573..709f6ff 100644 (file)
@@ -171,6 +171,7 @@ EXPORTS
        gst_caps_new_full_valist
        gst_caps_new_simple
        gst_caps_normalize
+       gst_caps_steal_structure
        gst_caps_ref
        gst_caps_remove_structure
        gst_caps_replace