structure: add gst_structure_{id_}take_value()
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Wed, 15 Sep 2010 22:42:43 +0000 (23:42 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 16 Sep 2010 18:39:58 +0000 (19:39 +0100)
Add _set_value() variants that take ownership of the value passed
instead of making a copy of the value. This is useful for setting
values to things that aren't refcounted (e.g. GValueArrays or
strings or string arrays, etc.).

API: gst_structure_take_value()
API: gst_structure_id_take_value()

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

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

index 2f08eed..75acea5 100644 (file)
@@ -2097,10 +2097,12 @@ gst_structure_id_get
 gst_structure_id_get_valist
 gst_structure_id_get_value
 gst_structure_id_set_value
+gst_structure_id_take_value
 gst_structure_get
 gst_structure_get_valist
 gst_structure_get_value
 gst_structure_set_value
+gst_structure_take_value
 gst_structure_set
 gst_structure_set_valist
 gst_structure_id_set
index 12fc954..daf52b8 100644 (file)
@@ -466,6 +466,73 @@ gst_structure_set_value (GstStructure * structure,
       value);
 }
 
+static inline void
+gst_structure_id_take_value_internal (GstStructure * structure, GQuark field,
+    GValue * value)
+{
+  GstStructureField gsfield = { 0, {0,} };
+
+  gsfield.name = field;
+  gsfield.value = *value;
+
+  gst_structure_set_field (structure, &gsfield);
+
+  /* we took ownership */
+#ifdef USE_POISONING
+  memset (value, 0, sizeof (GValue));
+#else
+  value->g_type = G_TYPE_INVALID;
+#endif
+}
+
+/**
+ * gst_structure_id_take_value:
+ * @structure: a #GstStructure
+ * @field: a #GQuark representing a field
+ * @value: (transfer full): the new value of the field
+ *
+ * Sets the field with the given GQuark @field to @value.  If the field
+ * does not exist, it is created.  If the field exists, the previous
+ * value is replaced and freed.
+ *
+ * Since: 0.10.31
+ */
+void
+gst_structure_id_take_value (GstStructure * structure, GQuark field,
+    GValue * value)
+{
+  g_return_if_fail (structure != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+  g_return_if_fail (IS_MUTABLE (structure));
+
+  gst_structure_id_take_value_internal (structure, field, value);
+}
+
+/**
+ * gst_structure_take_value:
+ * @structure: a #GstStructure
+ * @fieldname: the name of the field to set
+ * @value: (transfer full): the new value of the field
+ *
+ * Sets the field with the given name @field to @value.  If the field
+ * does not exist, it is created.  If the field exists, the previous
+ * value is replaced and freed. The function will take ownership of @value.
+ *
+ * Since: 0.10.31
+ */
+void
+gst_structure_take_value (GstStructure * structure, const gchar * fieldname,
+    GValue * value)
+{
+  g_return_if_fail (structure != NULL);
+  g_return_if_fail (fieldname != NULL);
+  g_return_if_fail (G_IS_VALUE (value));
+  g_return_if_fail (IS_MUTABLE (structure));
+
+  gst_structure_id_take_value_internal (structure,
+      g_quark_from_string (fieldname), value);
+}
+
 /**
  * gst_structure_set:
  * @structure: a #GstStructure
index 98f197b..48c81c4 100644 (file)
@@ -117,6 +117,12 @@ void                    gst_structure_id_set_value         (GstStructure
 void                    gst_structure_set_value            (GstStructure            *structure,
                                                            const gchar             *fieldname,
                                                            const GValue            *value);
+void                    gst_structure_id_take_value         (GstStructure            *structure,
+                                                           GQuark                   field,
+                                                           GValue                  *value);
+void                    gst_structure_take_value            (GstStructure            *structure,
+                                                           const gchar             *fieldname,
+                                                           GValue                  *value);
 void                    gst_structure_set                  (GstStructure            *structure,
                                                            const gchar             *fieldname,
                                                            ...) G_GNUC_NULL_TERMINATED;
index ba11cd7..226d189 100644 (file)
@@ -954,6 +954,7 @@ EXPORTS
        gst_structure_id_set
        gst_structure_id_set_valist
        gst_structure_id_set_value
+       gst_structure_id_take_value
        gst_structure_map_in_place
        gst_structure_n_fields
        gst_structure_new
@@ -968,6 +969,7 @@ EXPORTS
        gst_structure_set_parent_refcount
        gst_structure_set_valist
        gst_structure_set_value
+       gst_structure_take_value
        gst_structure_to_string
        gst_system_clock_get_type
        gst_system_clock_obtain