tools: Use a proper implementation of get_flags_from_string

This commit is contained in:
Thibault Saunier 2019-05-01 17:28:26 -04:00
parent dafc1cd8d1
commit ed9cbfed92
3 changed files with 14 additions and 15 deletions

View file

@ -86,9 +86,7 @@ _parse_track_type (const gchar * option_name, const gchar * value,
{ {
ParsedOptions *opts = &self->priv->parsed_options; ParsedOptions *opts = &self->priv->parsed_options;
opts->track_types = get_flags_from_string (GES_TYPE_TRACK_TYPE, value); if (!get_flags_from_string (GES_TYPE_TRACK_TYPE, value, &opts->track_types))
if (opts->track_types == 0)
return FALSE; return FALSE;
return TRUE; return TRUE;

View file

@ -84,21 +84,22 @@ sanitize_timeline_description (int argc, char **argv)
return string; return string;
} }
guint gboolean
get_flags_from_string (GType type, const gchar * str_flags) get_flags_from_string (GType type, const gchar * str_flags, guint * flags)
{ {
guint i; GValue value = G_VALUE_INIT;
gint flags = 0; g_value_init (&value, type);
GFlagsClass *class = g_type_class_ref (type);
for (i = 0; i < class->n_values; i++) { if (!gst_value_deserialize (&value, str_flags)) {
if (g_strrstr (str_flags, class->values[i].value_nick)) { g_value_unset (&value);
flags |= class->values[i].value;
} return FALSE;
} }
g_type_class_unref (class);
return flags; *flags = g_value_get_flags (&value);
g_value_unset (&value);
return TRUE;
} }
gchar * gchar *

View file

@ -20,7 +20,7 @@
#include <gst/pbutils/encoding-profile.h> #include <gst/pbutils/encoding-profile.h>
gchar * sanitize_timeline_description (int argc, char **argv); 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); gchar * ensure_uri (const gchar * location);
GstEncodingProfile * parse_encoding_profile (const gchar * format); GstEncodingProfile * parse_encoding_profile (const gchar * format);
void print_enum (GType enum_type); void print_enum (GType enum_type);