mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
gstvalue: add serialisation for GTypes
We need this in the GstTracerRecord. This will serialize GTypes to the typename and vice versa.
This commit is contained in:
parent
97b6d8fb12
commit
96304d613f
3 changed files with 87 additions and 2 deletions
|
@ -1821,6 +1821,8 @@ gst_structure_get_abbrs (gint * n_abbrs)
|
||||||
{"sample", GST_TYPE_SAMPLE}
|
{"sample", GST_TYPE_SAMPLE}
|
||||||
,
|
,
|
||||||
{"taglist", GST_TYPE_TAG_LIST}
|
{"taglist", GST_TYPE_TAG_LIST}
|
||||||
|
,
|
||||||
|
{"type", G_TYPE_GTYPE}
|
||||||
};
|
};
|
||||||
_num = G_N_ELEMENTS (dyn_abbrs);
|
_num = G_N_ELEMENTS (dyn_abbrs);
|
||||||
/* permanently allocate and copy the array now */
|
/* permanently allocate and copy the array now */
|
||||||
|
@ -1982,7 +1984,9 @@ priv__gst_structure_append_template_to_gstring (GQuark field_id,
|
||||||
g_string_append (s, "%" GST_WRAPPED_PTR_FORMAT);
|
g_string_append (s, "%" GST_WRAPPED_PTR_FORMAT);
|
||||||
} else if (g_type_is_a (type, G_TYPE_ENUM)
|
} else if (g_type_is_a (type, G_TYPE_ENUM)
|
||||||
|| g_type_is_a (type, G_TYPE_FLAGS)) {
|
|| g_type_is_a (type, G_TYPE_FLAGS)) {
|
||||||
g_string_append (s, "%i");
|
g_string_append_len (s, "%i", 2);
|
||||||
|
} else if (type == G_TYPE_GTYPE) {
|
||||||
|
g_string_append_len (s, "%s", 2);
|
||||||
} else if (type == G_TYPE_POINTER) {
|
} else if (type == G_TYPE_POINTER) {
|
||||||
g_string_append_len (s, "%p", 2);
|
g_string_append_len (s, "%p", 2);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3427,6 +3427,38 @@ gst_value_deserialize_gflags (GValue * dest, const gchar * s)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********
|
||||||
|
* gtype *
|
||||||
|
*********/
|
||||||
|
|
||||||
|
static gint
|
||||||
|
gst_value_compare_gtype (const GValue * value1, const GValue * value2)
|
||||||
|
{
|
||||||
|
if (value1->data[0].v_pointer == value2->data[0].v_pointer)
|
||||||
|
return GST_VALUE_EQUAL;
|
||||||
|
return GST_VALUE_UNORDERED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
gst_value_serialize_gtype (const GValue * value)
|
||||||
|
{
|
||||||
|
return g_strdup (g_type_name (g_value_get_gtype (value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_value_deserialize_gtype (GValue * dest, const gchar * s)
|
||||||
|
{
|
||||||
|
GType t = g_type_from_name (s);
|
||||||
|
gboolean ret = TRUE;
|
||||||
|
|
||||||
|
if (t == G_TYPE_INVALID)
|
||||||
|
ret = FALSE;
|
||||||
|
if (ret) {
|
||||||
|
g_value_set_gtype (dest, t);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* subset *
|
* subset *
|
||||||
****************/
|
****************/
|
||||||
|
@ -6739,7 +6771,7 @@ G_STMT_START { \
|
||||||
|
|
||||||
/* These initial sizes are used for the tables
|
/* These initial sizes are used for the tables
|
||||||
* below, and save a couple of reallocs at startup */
|
* below, and save a couple of reallocs at startup */
|
||||||
static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 34;
|
static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
|
||||||
static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
|
static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
|
||||||
static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
|
static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
|
||||||
static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
|
static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
|
||||||
|
@ -6804,6 +6836,8 @@ _priv_gst_value_initialize (void)
|
||||||
|
|
||||||
REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
|
REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
|
||||||
|
|
||||||
|
REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
|
||||||
|
|
||||||
g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
|
g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
|
||||||
gst_value_transform_int_range_string);
|
gst_value_transform_int_range_string);
|
||||||
g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
|
g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
|
||||||
|
|
|
@ -489,6 +489,51 @@ GST_START_TEST (test_deserialize_flags)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_deserialize_gtype)
|
||||||
|
{
|
||||||
|
GValue value = { 0 };
|
||||||
|
const char *strings[] = {
|
||||||
|
"gchararray",
|
||||||
|
"gint",
|
||||||
|
};
|
||||||
|
GType results[] = {
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_INT,
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
g_value_init (&value, G_TYPE_GTYPE);
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||||
|
fail_unless (gst_value_deserialize (&value, strings[i]),
|
||||||
|
"could not deserialize %s (%d)", strings[i], i);
|
||||||
|
fail_unless (g_value_get_gtype (&value) == results[i],
|
||||||
|
"resulting value is %" G_GSIZE_FORMAT ", not %" G_GSIZE_FORMAT
|
||||||
|
", for string %s (%d)",
|
||||||
|
g_value_get_gtype (&value), results[i], strings[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_deserialize_gtype_failures)
|
||||||
|
{
|
||||||
|
GValue value = { 0 };
|
||||||
|
const char *strings[] = {
|
||||||
|
"-", /* not a gtype */
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
g_value_init (&value, G_TYPE_GTYPE);
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (strings); ++i) {
|
||||||
|
fail_if (gst_value_deserialize (&value, strings[i]),
|
||||||
|
"deserialized %s (%d), while it should have failed", strings[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
GST_START_TEST (test_deserialize_bitmask)
|
GST_START_TEST (test_deserialize_bitmask)
|
||||||
{
|
{
|
||||||
GValue value = { 0 };
|
GValue value = { 0 };
|
||||||
|
@ -3087,6 +3132,8 @@ gst_value_suite (void)
|
||||||
tcase_add_test (tc_chain, test_deserialize_guint64);
|
tcase_add_test (tc_chain, test_deserialize_guint64);
|
||||||
tcase_add_test (tc_chain, test_deserialize_guchar);
|
tcase_add_test (tc_chain, test_deserialize_guchar);
|
||||||
tcase_add_test (tc_chain, test_deserialize_gstfraction);
|
tcase_add_test (tc_chain, test_deserialize_gstfraction);
|
||||||
|
tcase_add_test (tc_chain, test_deserialize_gtype);
|
||||||
|
tcase_add_test (tc_chain, test_deserialize_gtype_failures);
|
||||||
tcase_add_test (tc_chain, test_deserialize_bitmask);
|
tcase_add_test (tc_chain, test_deserialize_bitmask);
|
||||||
tcase_add_test (tc_chain, test_serialize_flags);
|
tcase_add_test (tc_chain, test_serialize_flags);
|
||||||
tcase_add_test (tc_chain, test_deserialize_flags);
|
tcase_add_test (tc_chain, test_deserialize_flags);
|
||||||
|
|
Loading…
Reference in a new issue