From a3cfcbfeded337778000ac061c8b6239208f448c Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Thu, 23 Feb 2017 20:47:30 +0200 Subject: [PATCH] value: Always add the type name to elements when serializing arrays/lists But only when serializing outside of GstStructures, because in case of GstStructure the type is already preprended to the array/list and the GstStructure API makes sure that they have the same "generic" type so deserialization works properly. This keeps serialization of GstStructures the same as before, and the GstCaps unit tests already test for that. However when serializing standalone arrays/lists get the types added now. --- gst/gst_private.h | 2 +- gst/gststructure.c | 9 ++++++++- gst/gstvalue.c | 11 ++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gst/gst_private.h b/gst/gst_private.h index 7e4c54c07a..dc2c153536 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -157,7 +157,7 @@ G_GNUC_INTERNAL const char * _priv_gst_value_gtype_to_abbr (GType type); G_GNUC_INTERNAL gboolean _priv_gst_value_parse_string (gchar * s, gchar ** end, gchar ** next, gboolean unescape); G_GNUC_INTERNAL gboolean _priv_gst_value_parse_simple_string (gchar * str, gchar ** end); G_GNUC_INTERNAL gboolean _priv_gst_value_parse_value (gchar * str, gchar ** after, GValue * value, GType default_type); -G_GNUC_INTERNAL gchar * _priv_gst_value_serialize_any_list (const GValue * value, const gchar * begin, const gchar * end); +G_GNUC_INTERNAL gchar * _priv_gst_value_serialize_any_list (const GValue * value, const gchar * begin, const gchar * end, gboolean print_type); /* Used in GstBin for manual state handling */ G_GNUC_INTERNAL void _priv_gst_element_state_changed (GstElement *element, diff --git a/gst/gststructure.c b/gst/gststructure.c index d23ea2e996..81e5b67217 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -1799,7 +1799,14 @@ priv_gst_structure_append_to_gstring (const GstStructure * structure, field = GST_STRUCTURE_FIELD (structure, i); - t = gst_value_serialize (&field->value); + if (G_VALUE_TYPE (&field->value) == GST_TYPE_ARRAY) { + t = _priv_gst_value_serialize_any_list (&field->value, "< ", " >", FALSE); + } else if (G_VALUE_TYPE (&field->value) == GST_TYPE_LIST) { + t = _priv_gst_value_serialize_any_list (&field->value, "{ ", " }", FALSE); + } else { + t = gst_value_serialize (&field->value); + } + type = gst_structure_value_get_generic_type (&field->value); g_string_append_len (s, ", ", 2); diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 5ab312c53e..5c217cd8f1 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -198,7 +198,7 @@ gst_value_hash_add_type (GType type, const GstValueTable * table) */ gchar * _priv_gst_value_serialize_any_list (const GValue * value, const gchar * begin, - const gchar * end) + const gchar * end, gboolean print_type) { guint i; GArray *array = value->data[0].v_pointer; @@ -214,6 +214,11 @@ _priv_gst_value_serialize_any_list (const GValue * value, const gchar * begin, v = &g_array_index (array, GValue, i); s_val = gst_value_serialize (v); if (s_val != NULL) { + if (print_type) { + g_string_append_c (s, '('); + g_string_append (s, _priv_gst_value_gtype_to_abbr (G_VALUE_TYPE (v))); + g_string_append_c (s, ')'); + } g_string_append (s, s_val); g_free (s_val); if (i < alen - 1) { @@ -1036,7 +1041,7 @@ gst_value_compare_g_value_array (const GValue * value1, const GValue * value2) static gchar * gst_value_serialize_value_list (const GValue * value) { - return _priv_gst_value_serialize_any_list (value, "{ ", " }"); + return _priv_gst_value_serialize_any_list (value, "{ ", " }", TRUE); } static gboolean @@ -1049,7 +1054,7 @@ gst_value_deserialize_value_list (GValue * dest, const gchar * s) static gchar * gst_value_serialize_value_array (const GValue * value) { - return _priv_gst_value_serialize_any_list (value, "< ", " >"); + return _priv_gst_value_serialize_any_list (value, "{ ", " }", TRUE); } static gboolean