From: Thibault Saunier Date: Fri, 1 Feb 2019 21:41:07 +0000 (-0300) Subject: validate: Cleanup flags/enum_from_string X-Git-Tag: 1.19.3~491^2~434 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0ee26e9505d7b2bf830c151357addbf5439c973;p=platform%2Fupstream%2Fgstreamer.git validate: Cleanup flags/enum_from_string --- diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c index 9723ff8..74e5d20 100644 --- a/validate/gst/validate/gst-validate-scenario.c +++ b/validate/gst/validate/gst-validate-scenario.c @@ -1123,8 +1123,7 @@ execute_switch_track_pb (GstValidateScenario * scenario, if (!(type = gst_structure_get_string (action->structure, "type"))) type = "audio"; - tflag = - gst_validate_utils_flags_from_str (g_type_from_name ("GstPlayFlags"), + tflag = gst_validate_utils_flags_from_str (g_type_from_name ("GstPlayFlags"), type); current_txt = g_strdup_printf ("current-%s", type); @@ -2897,7 +2896,6 @@ _load_scenario_file (GstValidateScenario * scenario, const gchar *type; GstStructure *structure = (GstStructure *) tmp->data; - type = gst_structure_get_name (structure); if (!g_strcmp0 (type, "description")) { const gchar *pipeline_name; diff --git a/validate/gst/validate/gst-validate-utils.c b/validate/gst/validate/gst-validate-utils.c index af8486b..15de102 100644 --- a/validate/gst/validate/gst-validate-utils.c +++ b/validate/gst/validate/gst-validate-utils.c @@ -495,19 +495,18 @@ gst_validate_utils_parse_expression (const gchar * expr, guint gst_validate_utils_flags_from_str (GType type, const gchar * str_flags) { - guint i; - gint flags = 0; - GFlagsClass *class = g_type_class_ref (type); + guint flags; + GValue value = G_VALUE_INIT; + g_value_init (&value, type); - for (i = 0; i < class->n_values; i++) { - if (class->values[i].value_nick == NULL) - continue; + if (!gst_value_deserialize (&value, str_flags)) { + g_error ("Invalid flags: %s", str_flags); - if (g_strrstr (str_flags, class->values[i].value_nick)) { - flags |= class->values[i].value; - } + return 0; } - g_type_class_unref (class); + + flags = g_value_get_flags (&value); + g_value_unset (&value); return flags; } @@ -524,20 +523,19 @@ gboolean gst_validate_utils_enum_from_str (GType type, const gchar * str_enum, guint * enum_value) { - guint i; - GEnumClass *class = g_type_class_ref (type); - gboolean ret = FALSE; + GValue value = G_VALUE_INIT; + g_value_init (&value, type); - for (i = 0; i < class->n_values; i++) { - if (g_strrstr (str_enum, class->values[i].value_nick)) { - *enum_value = class->values[i].value; - ret = TRUE; - } + if (!gst_value_deserialize (&value, str_enum)) { + g_error ("Invalid enum: %s", str_enum); + + return FALSE; } - g_type_class_unref (class); + *enum_value = g_value_get_enum (&value); + g_value_unset (&value); - return ret; + return TRUE; } /* Parse file that contains a list of GStructures */