value: Add deserialization for arrays/lists outside GstStructures

This is mostly useful for properties of those types when used in
gst-launch or similar.

https://bugzilla.gnome.org/show_bug.cgi?id=777375
This commit is contained in:
Vivia Nikolaidou 2017-02-23 20:52:39 +02:00 committed by Sebastian Dröge
parent ba49927aaf
commit 63775ac6e3
2 changed files with 39 additions and 5 deletions

View file

@ -96,6 +96,8 @@ static void gst_value_register_intersect_func (GType type1,
static void gst_value_register_subtract_func (GType minuend_type,
GType subtrahend_type, GstValueSubtractFunc func);
static gboolean _priv_gst_value_parse_list (gchar * s, gchar ** after,
GValue * value, GType type);
static gboolean _priv_gst_value_parse_array (gchar * s, gchar ** after,
GValue * value, GType type);
@ -1047,21 +1049,21 @@ gst_value_serialize_value_list (const GValue * value)
static gboolean
gst_value_deserialize_value_list (GValue * dest, const gchar * s)
{
g_warning ("gst_value_deserialize_list: unimplemented");
return FALSE;
gchar *s2 = (gchar *) s;
return _priv_gst_value_parse_list (s2, &s2, dest, G_TYPE_INVALID);
}
static gchar *
gst_value_serialize_value_array (const GValue * value)
{
return _priv_gst_value_serialize_any_list (value, "{ ", " }", TRUE);
return _priv_gst_value_serialize_any_list (value, "< ", " >", TRUE);
}
static gboolean
gst_value_deserialize_value_array (GValue * dest, const gchar * s)
{
g_warning ("gst_value_deserialize_array: unimplemented");
return FALSE;
gchar *s2 = (gchar *) s;
return _priv_gst_value_parse_array (s2, &s2, dest, G_TYPE_INVALID);
}
static gchar *

View file

@ -2669,6 +2669,37 @@ GST_START_TEST (test_serialize_deserialize_format_enum)
GST_END_TEST;
GST_START_TEST (test_serialize_deserialize_value_array)
{
GValue v = G_VALUE_INIT, v2 = G_VALUE_INIT, v3 = G_VALUE_INIT;
gchar *str = NULL;
g_value_init (&v, GST_TYPE_ARRAY);
g_value_init (&v2, GST_TYPE_ARRAY);
g_value_init (&v3, G_TYPE_DOUBLE);
g_value_set_double (&v3, 1);
gst_value_array_append_value (&v2, &v3);
g_value_unset (&v3);
g_value_init (&v3, G_TYPE_DOUBLE);
g_value_set_double (&v3, 0);
gst_value_array_append_value (&v2, &v3);
g_value_unset (&v3);
gst_value_array_append_value (&v, &v2);
g_value_unset (&v2);
str = gst_value_serialize (&v);
g_value_init (&v2, GST_TYPE_ARRAY);
fail_unless (gst_value_deserialize (&v2, str));
fail_unless (gst_value_compare (&v, &v2) == 0);
g_value_unset (&v2);
g_value_unset (&v);
g_free (str);
}
GST_END_TEST;
GST_START_TEST (test_serialize_deserialize_caps)
{
GValue value = { 0 }
@ -3296,6 +3327,7 @@ gst_value_suite (void)
tcase_add_test (tc_chain, test_serialize_flags);
tcase_add_test (tc_chain, test_deserialize_flags);
tcase_add_test (tc_chain, test_serialize_deserialize_format_enum);
tcase_add_test (tc_chain, test_serialize_deserialize_value_array);
tcase_add_test (tc_chain, test_string);
tcase_add_test (tc_chain, test_deserialize_string);
tcase_add_test (tc_chain, test_value_compare);