tools: Use a proper implementation of get_flags_from_string
authorThibault Saunier <tsaunier@igalia.com>
Wed, 1 May 2019 21:28:26 +0000 (17:28 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Thu, 23 May 2019 21:16:27 +0000 (17:16 -0400)
tools/ges-launcher.c
tools/utils.c
tools/utils.h

index 972221a..b1b24f2 100644 (file)
@@ -86,9 +86,7 @@ _parse_track_type (const gchar * option_name, const gchar * value,
 {
   ParsedOptions *opts = &self->priv->parsed_options;
 
-  opts->track_types = get_flags_from_string (GES_TYPE_TRACK_TYPE, value);
-
-  if (opts->track_types == 0)
+  if (!get_flags_from_string (GES_TYPE_TRACK_TYPE, value, &opts->track_types))
     return FALSE;
 
   return TRUE;
index 23d7e42..fd6211a 100644 (file)
@@ -84,21 +84,22 @@ sanitize_timeline_description (int argc, char **argv)
   return string;
 }
 
-guint
-get_flags_from_string (GType type, const gchar * str_flags)
+gboolean
+get_flags_from_string (GType type, const gchar * str_flags, guint * flags)
 {
-  guint i;
-  gint flags = 0;
-  GFlagsClass *class = g_type_class_ref (type);
+  GValue value = G_VALUE_INIT;
+  g_value_init (&value, type);
 
-  for (i = 0; i < class->n_values; i++) {
-    if (g_strrstr (str_flags, class->values[i].value_nick)) {
-      flags |= class->values[i].value;
-    }
+  if (!gst_value_deserialize (&value, str_flags)) {
+    g_value_unset (&value);
+
+    return FALSE;
   }
-  g_type_class_unref (class);
 
-  return flags;
+  *flags = g_value_get_flags (&value);
+  g_value_unset (&value);
+
+  return TRUE;
 }
 
 gchar *
index c4e63e9..e381126 100644 (file)
@@ -20,7 +20,7 @@
 #include <gst/pbutils/encoding-profile.h>
 
 gchar * sanitize_timeline_description (int argc, char **argv);
-guint get_flags_from_string (GType type, const gchar * str_flags);
+gboolean get_flags_from_string (GType type, const gchar * str_flags, guint *val);
 gchar * ensure_uri (const gchar * location);
 GstEncodingProfile * parse_encoding_profile (const gchar * format);
 void print_enum (GType enum_type);