From 2e1db58e112ef7833a1e8ca34bde7d5740dd481d Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Wed, 5 Jun 2013 11:02:50 +0200 Subject: [PATCH] gstvalue: Add _append_and_take_value() public variants 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 | 3 +- gst/gstvalue.c | 62 ++++++++++++++++++++++++++++------- gst/gstvalue.h | 4 +++ win32/common/libgstreamer.def | 2 ++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/gst/gstbufferpool.c b/gst/gstbufferpool.c index 0ac3490074..edd9ec9cf4 100644 --- a/gst/gstbufferpool.c +++ b/gst/gstbufferpool.c @@ -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); } /** diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 8a55712a81..094064f1b7 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -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) diff --git a/gst/gstvalue.h b/gst/gstvalue.h index ed1dcdc308..d03d22e004 100644 --- a/gst/gstvalue.h +++ b/gst/gstvalue.h @@ -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); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 47ac5c1832..2ff23622bd 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -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