[gst-cvs] gstreamer: structure: add gst_structure_{id_}take_value()

Tim Müller tpm at kemper.freedesktop.org
Thu Sep 16 11:43:57 PDT 2010


Module: gstreamer
Branch: master
Commit: 7e5a9580ef2614111ba20e1c473df2fb02be1ef7
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=7e5a9580ef2614111ba20e1c473df2fb02be1ef7

Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
Date:   Wed Sep 15 23:42:43 2010 +0100

structure: add gst_structure_{id_}take_value()

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 |    2 +
 gst/gststructure.c              |   67 +++++++++++++++++++++++++++++++++++++++
 gst/gststructure.h              |    6 +++
 win32/common/libgstreamer.def   |    2 +
 4 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt
index 2f08eed..75acea5 100644
--- a/docs/gst/gstreamer-sections.txt
+++ b/docs/gst/gstreamer-sections.txt
@@ -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
diff --git a/gst/gststructure.c b/gst/gststructure.c
index 12fc954..daf52b8 100644
--- a/gst/gststructure.c
+++ b/gst/gststructure.c
@@ -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
diff --git a/gst/gststructure.h b/gst/gststructure.h
index 98f197b..48c81c4 100644
--- a/gst/gststructure.h
+++ b/gst/gststructure.h
@@ -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;
diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def
index ba11cd7..226d189 100644
--- a/win32/common/libgstreamer.def
+++ b/win32/common/libgstreamer.def
@@ -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





More information about the Gstreamer-commits mailing list