value: Always add the type name to elements when serializing arrays/lists
authorVivia Nikolaidou <vivia@toolsonair.com>
Thu, 23 Feb 2017 18:47:30 +0000 (20:47 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 23 Feb 2017 18:48:40 +0000 (20:48 +0200)
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
gst/gststructure.c
gst/gstvalue.c

index 7e4c54c..dc2c153 100644 (file)
@@ -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,
index d23ea2e..81e5b67 100644 (file)
@@ -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);
index 5ab312c..5c217cd 100644 (file)
@@ -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