mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-20 11:00:16 +00:00
validate: Move enums and flags deserialization from scenario to utilities
This way it can be reused.
This commit is contained in:
parent
5cfafb4910
commit
04029cb065
3 changed files with 53 additions and 45 deletions
|
@ -91,39 +91,6 @@ typedef struct KeyFileGroupName
|
||||||
gchar *group_name;
|
gchar *group_name;
|
||||||
} KeyFileGroupName;
|
} KeyFileGroupName;
|
||||||
|
|
||||||
static guint
|
|
||||||
get_flags_from_string (GType type, const gchar * str_flags)
|
|
||||||
{
|
|
||||||
guint i;
|
|
||||||
gint flags = 0;
|
|
||||||
GFlagsClass *class = g_type_class_ref (type);
|
|
||||||
|
|
||||||
for (i = 0; i < class->n_values; i++) {
|
|
||||||
if (g_strrstr (str_flags, class->values[i].value_nick)) {
|
|
||||||
flags |= class->values[i].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_type_class_unref (class);
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
get_enum_from_string (GType type, const gchar * str_enum, guint * enum_value)
|
|
||||||
{
|
|
||||||
guint i;
|
|
||||||
GEnumClass *class = g_type_class_ref (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;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_type_class_unref (class);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_free_scenario_action (GstValidateAction * act)
|
_free_scenario_action (GstValidateAction * act)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +146,8 @@ gst_validate_action_get_clocktime (GstValidateScenario * scenario,
|
||||||
GST_DEBUG_OBJECT (scenario, "Could not find %s", name);
|
GST_DEBUG_OBJECT (scenario, "Could not find %s", name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
val = parse_expression (strval, _set_variable_func, scenario, &error);
|
val = gst_validate_utils_parse_expression (strval,
|
||||||
|
_set_variable_func, scenario, &error);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
GST_WARNING ("Error while parsing %s: %s", strval, error);
|
GST_WARNING ("Error while parsing %s: %s", strval, error);
|
||||||
|
@ -219,18 +187,18 @@ _execute_seek (GstValidateScenario * scenario, GstValidateAction * action)
|
||||||
|
|
||||||
gst_structure_get_double (action->structure, "rate", &rate);
|
gst_structure_get_double (action->structure, "rate", &rate);
|
||||||
if ((str_format = gst_structure_get_string (action->structure, "format")))
|
if ((str_format = gst_structure_get_string (action->structure, "format")))
|
||||||
get_enum_from_string (GST_TYPE_FORMAT, str_format, &format);
|
gst_validate_utils_enum_from_str (GST_TYPE_FORMAT, str_format, &format);
|
||||||
|
|
||||||
if ((str_start_type =
|
if ((str_start_type =
|
||||||
gst_structure_get_string (action->structure, "start_type")))
|
gst_structure_get_string (action->structure, "start_type")))
|
||||||
get_enum_from_string (GST_TYPE_SEEK_TYPE, str_start_type, &start_type);
|
gst_validate_utils_enum_from_str (GST_TYPE_SEEK_TYPE, str_start_type, &start_type);
|
||||||
|
|
||||||
if ((str_stop_type =
|
if ((str_stop_type =
|
||||||
gst_structure_get_string (action->structure, "stop_type")))
|
gst_structure_get_string (action->structure, "stop_type")))
|
||||||
get_enum_from_string (GST_TYPE_SEEK_TYPE, str_stop_type, &stop_type);
|
gst_validate_utils_enum_from_str (GST_TYPE_SEEK_TYPE, str_stop_type, &stop_type);
|
||||||
|
|
||||||
if ((str_flags = gst_structure_get_string (action->structure, "flags")))
|
if ((str_flags = gst_structure_get_string (action->structure, "flags")))
|
||||||
flags = get_flags_from_string (GST_TYPE_SEEK_FLAGS, str_flags);
|
flags = gst_validate_utils_flags_from_str (GST_TYPE_SEEK_FLAGS, str_flags);
|
||||||
|
|
||||||
gst_validate_action_get_clocktime (scenario, action, "stop", &stop);
|
gst_validate_action_get_clocktime (scenario, action, "stop", &stop);
|
||||||
|
|
||||||
|
@ -616,8 +584,9 @@ get_position (GstValidateScenario * scenario)
|
||||||
"repeat");
|
"repeat");
|
||||||
|
|
||||||
if (repeat_expr) {
|
if (repeat_expr) {
|
||||||
act->repeat = parse_expression (repeat_expr, _set_variable_func,
|
act->repeat =
|
||||||
scenario, &error);
|
gst_validate_utils_parse_expression (repeat_expr,
|
||||||
|
_set_variable_func, scenario, &error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
|
|
||||||
#include "gst-validate-utils.h"
|
#include "gst-validate-utils.h"
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
#define PARSER_BOOLEAN_EQUALITY_THRESHOLD (1e-10)
|
#define PARSER_BOOLEAN_EQUALITY_THRESHOLD (1e-10)
|
||||||
#define PARSER_MAX_TOKEN_SIZE 256
|
#define PARSER_MAX_TOKEN_SIZE 256
|
||||||
|
@ -444,7 +445,7 @@ _read_power (MathParser * parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
gdouble
|
gdouble
|
||||||
parse_expression (const gchar * expr, ParseVariableFunc variable_func,
|
gst_validate_utils_parse_expression (const gchar * expr, ParseVariableFunc variable_func,
|
||||||
gpointer user_data, gchar ** error)
|
gpointer user_data, gchar ** error)
|
||||||
{
|
{
|
||||||
gdouble val;
|
gdouble val;
|
||||||
|
@ -465,3 +466,36 @@ parse_expression (const gchar * expr, ParseVariableFunc variable_func,
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
for (i = 0; i < class->n_values; i++) {
|
||||||
|
if (g_strrstr (str_flags, class->values[i].value_nick)) {
|
||||||
|
flags |= class->values[i].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_type_class_unref (class);
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_validate_utils_enum_from_str (GType type, const gchar * str_enum, guint * enum_value)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
GEnumClass *class = g_type_class_ref (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;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_type_class_unref (class);
|
||||||
|
}
|
||||||
|
|
|
@ -26,12 +26,17 @@
|
||||||
#include<setjmp.h>
|
#include<setjmp.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<glib.h>
|
#include<glib.h>
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
typedef int (*ParseVariableFunc) (const gchar *name,
|
typedef int (*ParseVariableFunc) (const gchar *name,
|
||||||
double *value, gpointer user_data);
|
double *value, gpointer user_data);
|
||||||
|
|
||||||
gdouble parse_expression (const gchar *expr,
|
gdouble gst_validate_utils_parse_expression (const gchar *expr,
|
||||||
ParseVariableFunc variable_func,
|
ParseVariableFunc variable_func,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
gchar **error);
|
gchar **error);
|
||||||
|
guint gst_validate_utils_flags_from_str (GType type, const gchar * str_flags);
|
||||||
|
void gst_validate_utils_enum_from_str (GType type,
|
||||||
|
const gchar * str_enum,
|
||||||
|
guint * enum_value);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue