gstvalue: Add _append_and_take_value() public variants
authorEdward Hervey <edward@collabora.com>
Wed, 5 Jun 2013 09:02:50 +0000 (11:02 +0200)
committerEdward Hervey <edward@collabora.com>
Wed, 5 Jun 2013 10:58:05 +0000 (12:58 +0200)
API: gst_value_array_append_and_take_value
API: gst_value_list_append_and_take_value

We were already using this internally, this makes it public for code
which frequently appends values which are expensive to copy (like
structures, arrays, caps, ...).

Avoids copies of the values for users. The passed GValue will also
be 0-memset'ed for re-use.

New users can replace this kind of code:
gst_value_*_append_value(mycontainer, &myvalue);
g_value_unset(&myvalue);

by:

gst_value_*_append_and_take_value(mycontainer, &myvalue);

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

gst/gstbufferpool.c
gst/gstvalue.c
gst/gstvalue.h
win32/common/libgstreamer.def

index 0ac3490074119ce9fb4cbd7be7c9ab5538eaae8e..edd9ec9cf408311df32742825b5a943b430d9a50 100644 (file)
@@ -825,8 +825,7 @@ gst_buffer_pool_config_add_option (GstStructure * config, const gchar * option)
   }
   g_value_init (&option_value, G_TYPE_STRING);
   g_value_set_string (&option_value, option);
-  gst_value_array_append_value ((GValue *) value, &option_value);
-  g_value_unset (&option_value);
+  gst_value_array_append_and_take_value ((GValue *) value, &option_value);
 }
 
 /**
index 8a55712a810a4cbe94d5c7cbd2db09843c3a2ac0..094064f1b7e65803fc2dc15c751f1c00c0e44435 100644 (file)
@@ -145,9 +145,9 @@ static gchar *gst_string_take_and_wrap (gchar * s);
 static gchar *gst_string_unwrap (const gchar * s);
 
 static void gst_value_move (GValue * dest, GValue * src);
-static void gst_value_list_append_and_take_value (GValue * value,
+static void _gst_value_list_append_and_take_value (GValue * value,
     GValue * append_value);
-static void gst_value_array_append_and_take_value (GValue * value,
+static void _gst_value_array_append_and_take_value (GValue * value,
     GValue * append_value);
 
 static inline GstValueTable *
@@ -413,17 +413,37 @@ gst_value_list_or_array_are_compatible (const GValue * value1,
   return FALSE;
 }
 
-static void
-gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
+static inline void
+_gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
 {
   g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
   memset (append_value, 0, sizeof (GValue));
 }
 
+/**
+ * gst_value_list_append_and_take_value:
+ * @value: a #GValue of type #GST_TYPE_LIST
+ * @append_value: (transfer full): the value to append
+ *
+ * Appends @append_value to the GstValueList in @value.
+ *
+ * Since: 1.2
+ */
+void
+gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
+{
+  g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
+  g_return_if_fail (G_IS_VALUE (append_value));
+  g_return_if_fail (gst_value_list_or_array_are_compatible (value,
+          append_value));
+
+  _gst_value_list_append_and_take_value (value, append_value);
+}
+
 /**
  * gst_value_list_append_value:
  * @value: a #GValue of type #GST_TYPE_LIST
- * @append_value: the value to append
+ * @append_value: (transfer none): the value to append
  *
  * Appends @append_value to the GstValueList in @value.
  */
@@ -672,13 +692,33 @@ gst_value_array_append_value (GValue * value, const GValue * append_value)
   g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
 }
 
-static void
-gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
+static inline void
+_gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
 {
   g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
   memset (append_value, 0, sizeof (GValue));
 }
 
+/**
+ * gst_value_array_append_and_take_value:
+ * @value: a #GValue of type #GST_TYPE_ARRAY
+ * @append_value: (transfer full): the value to append
+ *
+ * Appends @append_value to the GstValueArray in @value.
+ *
+ * Since: 1.2
+ */
+void
+gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
+{
+  g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
+  g_return_if_fail (G_IS_VALUE (append_value));
+  g_return_if_fail (gst_value_list_or_array_are_compatible (value,
+          append_value));
+
+  _gst_value_array_append_and_take_value (value, append_value);
+}
+
 /**
  * gst_value_array_prepend_value:
  * @value: a #GValue of type #GST_TYPE_ARRAY
@@ -3594,7 +3634,7 @@ gst_value_intersect_list (GValue * dest, const GValue * value1,
         gst_value_move (dest, &intersection);
         ret = TRUE;
       } else if (GST_VALUE_HOLDS_LIST (dest)) {
-        gst_value_list_append_and_take_value (dest, &intersection);
+        _gst_value_list_append_and_take_value (dest, &intersection);
       } else {
         GValue temp;
 
@@ -3641,7 +3681,7 @@ gst_value_intersect_array (GValue * dest, const GValue * src1,
       g_value_unset (dest);
       return FALSE;
     }
-    gst_value_array_append_and_take_value (dest, &val);
+    _gst_value_array_append_and_take_value (dest, &val);
   }
 
   return TRUE;
@@ -4118,7 +4158,7 @@ gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
         ret = TRUE;
       } else if (G_VALUE_HOLDS (dest, ltype)
           && !G_VALUE_HOLDS (&subtraction, ltype)) {
-        gst_value_list_append_and_take_value (dest, &subtraction);
+        _gst_value_list_append_and_take_value (dest, &subtraction);
       } else {
         GValue temp;
 
@@ -5089,7 +5129,7 @@ gst_value_fixate (GValue * dest, const GValue * src)
         gst_value_init_and_copy (&kid, orig_kid);
       else
         res = TRUE;
-      gst_value_array_append_and_take_value (dest, &kid);
+      _gst_value_array_append_and_take_value (dest, &kid);
     }
 
     if (!res)
index ed1dcdc308c80f2317814cbf7b3a47c87d6e284a..d03d22e00458a27f3e72ee6231603eefc0c66201 100644 (file)
@@ -418,6 +418,8 @@ gboolean        gst_value_deserialize           (GValue                *dest,
 /* list */
 void            gst_value_list_append_value     (GValue         *value,
                                                  const GValue   *append_value);
+void            gst_value_list_append_and_take_value (GValue         *value,
+                                                 GValue   *append_value);
 void            gst_value_list_prepend_value    (GValue         *value,
                                                  const GValue   *prepend_value);
 void            gst_value_list_concat           (GValue         *dest,
@@ -433,6 +435,8 @@ const GValue *  gst_value_list_get_value        (const GValue   *value,
 /* array */
 void            gst_value_array_append_value    (GValue         *value,
                                                  const GValue   *append_value);
+void            gst_value_array_append_and_take_value    (GValue         *value,
+                                                 GValue   *append_value);
 void            gst_value_array_prepend_value   (GValue         *value,
                                                  const GValue   *prepend_value);
 guint           gst_value_array_get_size        (const GValue   *value);
index 47ac5c183274d4ce6a1e4aaa4a02a470883da052..2ff23622bd99451531d7f2291d23f0a0df4af34d 100644 (file)
@@ -1296,6 +1296,7 @@ EXPORTS
        gst_util_uint64_scale_int_ceil
        gst_util_uint64_scale_int_round
        gst_util_uint64_scale_round
+       gst_value_array_append_and_take_value
        gst_value_array_append_value
        gst_value_array_get_size
        gst_value_array_get_type
@@ -1330,6 +1331,7 @@ EXPORTS
        gst_value_intersect
        gst_value_is_fixed
        gst_value_is_subset
+       gst_value_list_append_and_take_value
        gst_value_list_append_value
        gst_value_list_concat
        gst_value_list_get_size