mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 07:08:23 +00:00
validate: Add a flag to allow defining how to resolve variables in structs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/248>
This commit is contained in:
parent
b3065bb9ec
commit
8b8a6c8a18
6 changed files with 42 additions and 20 deletions
|
@ -101,4 +101,16 @@ typedef enum
|
|||
GST_VALIDATE_VERBOSITY_ALL = GST_VALIDATE_VERBOSITY_POSITION | GST_VALIDATE_VERBOSITY_MESSAGES | GST_VALIDATE_VERBOSITY_PROPS_CHANGES | GST_VALIDATE_VERBOSITY_NEW_ELEMENTS
|
||||
} GstValidateVerbosityFlags;
|
||||
|
||||
#endif /* __GST_VALIDATE_RUNNER_H__ */
|
||||
/**
|
||||
* GstValidateStructureResolveVariablesFlags:
|
||||
*
|
||||
* Since: 1.20
|
||||
*/
|
||||
typedef enum {
|
||||
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL = 0,
|
||||
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY = 1 << 0,
|
||||
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_FAILURE = 1 << 1,
|
||||
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION = 1 << 1,
|
||||
} GstValidateStructureResolveVariablesFlags;
|
||||
|
||||
#endif /* __GST_VALIDATE_ENUMS_H__ */
|
||||
|
|
|
@ -875,7 +875,7 @@ gst_validate_action_get_clocktime (GstValidateScenario * scenario,
|
|||
_update_well_known_vars (scenario);
|
||||
strval =
|
||||
gst_validate_replace_variables_in_string (action, scenario->priv->vars,
|
||||
tmpvalue);
|
||||
tmpvalue, GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
|
||||
if (!strval)
|
||||
return FALSE;
|
||||
|
||||
|
@ -3676,7 +3676,7 @@ gst_validate_action_setup_repeat (GstValidateScenario * scenario,
|
|||
|
||||
repeat_expr = gst_validate_replace_variables_in_string (action,
|
||||
scenario->priv->vars, gst_structure_get_string (action->structure,
|
||||
"repeat"));
|
||||
"repeat"), GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
|
||||
if (!repeat_expr) {
|
||||
gst_validate_error_structure (action, "Invalid value for 'repeat'");
|
||||
return FALSE;
|
||||
|
@ -3731,7 +3731,7 @@ gst_validate_action_default_prepare_func (GstValidateAction * action)
|
|||
GST_VALIDATE_ACTION_RANGE_NAME (action) : "repeat", G_TYPE_INT,
|
||||
action->repeat, NULL);
|
||||
gst_validate_structure_resolve_variables (action, action->structure,
|
||||
scenario->priv->vars);
|
||||
scenario->priv->vars, GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
|
||||
for (i = 0; type->parameters[i].name; i++) {
|
||||
if (type->parameters[i].types
|
||||
&& g_str_has_suffix (type->parameters[i].types, "(GstClockTime)"))
|
||||
|
|
|
@ -1216,7 +1216,8 @@ gst_structure_get_value_as_string (GstStructure * structure,
|
|||
|
||||
gchar *
|
||||
gst_validate_replace_variables_in_string (gpointer source,
|
||||
GstStructure * local_vars, const gchar * in_string)
|
||||
GstStructure * local_vars, const gchar * in_string,
|
||||
GstValidateStructureResolveVariablesFlags flags)
|
||||
{
|
||||
gint varname_len;
|
||||
GMatchInfo *match_info = NULL;
|
||||
|
@ -1246,20 +1247,24 @@ gst_validate_replace_variables_in_string (gpointer source,
|
|||
if (local_vars)
|
||||
var_value = gst_structure_get_value_as_string (local_vars, varname);
|
||||
|
||||
if (!var_value)
|
||||
if (!var_value
|
||||
&& !(flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY))
|
||||
var_value = gst_structure_get_value_as_string (global_vars, varname);
|
||||
}
|
||||
|
||||
if (!var_value) {
|
||||
if (!var_value) {
|
||||
if (!(flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_FAILURE)) {
|
||||
gst_validate_error_structure (source,
|
||||
"Trying to use undefined variable `%s`.\n"
|
||||
" Available vars:\n"
|
||||
" - locals%s\n"
|
||||
" - globals%s\n",
|
||||
varname, gst_structure_to_string (local_vars),
|
||||
gst_structure_to_string (global_vars));
|
||||
|
||||
return NULL;
|
||||
(flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY) ?
|
||||
": unused" : gst_structure_to_string (global_vars));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmp = g_strdup_printf ("\\$\\(%s\\)", varname);
|
||||
|
@ -1290,6 +1295,7 @@ typedef struct
|
|||
{
|
||||
gpointer source;
|
||||
GstStructure *local_vars;
|
||||
GstValidateStructureResolveVariablesFlags flags;
|
||||
} ReplaceData;
|
||||
|
||||
static void
|
||||
|
@ -1354,22 +1360,24 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
|
|||
|
||||
str =
|
||||
gst_validate_replace_variables_in_string (data->source, data->local_vars,
|
||||
g_value_get_string (value));
|
||||
g_value_get_string (value), data->flags);
|
||||
if (str) {
|
||||
g_value_set_string (value, str);
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
_resolve_expression (data->source, value);
|
||||
if (!(data->flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION))
|
||||
_resolve_expression (data->source, value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gst_validate_structure_resolve_variables (gpointer source,
|
||||
GstStructure * structure, GstStructure * local_variables)
|
||||
GstStructure * structure, GstStructure * local_variables,
|
||||
GstValidateStructureResolveVariablesFlags flags)
|
||||
{
|
||||
ReplaceData d = { source ? source : structure, local_variables };
|
||||
ReplaceData d = { source ? source : structure, local_variables, flags };
|
||||
|
||||
gst_structure_filter_and_map_in_place (structure,
|
||||
(GstStructureFilterMapFunc) _structure_set_variables, &d);
|
||||
|
|
|
@ -79,9 +79,11 @@ void gst_validate_spin_on_fault_signals (void);
|
|||
|
||||
GST_VALIDATE_API
|
||||
gboolean gst_validate_element_matches_target (GstElement * element, GstStructure * s);
|
||||
gchar * gst_validate_replace_variables_in_string (gpointer incom, GstStructure * local_vars, const gchar * in_string);
|
||||
gchar * gst_validate_replace_variables_in_string (gpointer incom, GstStructure * local_vars, const gchar * in_string,
|
||||
GstValidateStructureResolveVariablesFlags flags);
|
||||
GST_VALIDATE_API
|
||||
void gst_validate_structure_resolve_variables (gpointer source, GstStructure *structure, GstStructure *local_variables);
|
||||
void gst_validate_structure_resolve_variables (gpointer source, GstStructure *structure, GstStructure *local_variables,
|
||||
GstValidateStructureResolveVariablesFlags flags);
|
||||
void gst_validate_structure_set_variables_from_struct_file(GstStructure* vars, const gchar* struct_file);
|
||||
void gst_validate_set_globals(GstStructure* structure);
|
||||
GST_VALIDATE_API
|
||||
|
|
|
@ -202,11 +202,11 @@ create_config (const gchar * config)
|
|||
gst_structure_free (structure);
|
||||
} else if (!loaded_globals
|
||||
&& gst_structure_has_name (structure, "set-globals")) {
|
||||
gst_validate_structure_resolve_variables (NULL, structure, local_vars);
|
||||
gst_validate_structure_resolve_variables (NULL, structure, local_vars, 0);
|
||||
gst_validate_set_globals (structure);
|
||||
gst_structure_free (structure);
|
||||
} else {
|
||||
gst_validate_structure_resolve_variables (NULL, structure, local_vars);
|
||||
gst_validate_structure_resolve_variables (NULL, structure, local_vars, 0);
|
||||
all_configs = g_list_append (all_configs, structure);
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +621,7 @@ gst_validate_setup_test_file (const gchar * testfile, gboolean use_fakesinks)
|
|||
gst_validate_scenario_check_and_set_needs_clock_sync (testfile_structs, &res);
|
||||
|
||||
gst_validate_set_test_file_globals (res, testfile, use_fakesinks);
|
||||
gst_validate_structure_resolve_variables (NULL, res, NULL);
|
||||
gst_validate_structure_resolve_variables (NULL, res, NULL, 0);
|
||||
|
||||
tool = gst_structure_get_string (res, "tool");
|
||||
if (!tool)
|
||||
|
|
|
@ -8,7 +8,7 @@ GST_START_TEST (test_resolve_variables)
|
|||
gst_structure_from_string ("vars, a=(string)1, b=(string)2", NULL);
|
||||
GstStructure *s2 = gst_structure_from_string ("test, n=\"$(a)/$(b)\"", NULL);
|
||||
|
||||
gst_validate_structure_resolve_variables (NULL, s2, s1);
|
||||
gst_validate_structure_resolve_variables (NULL, s2, s1, 0);
|
||||
fail_unless_equals_string (gst_structure_get_string (s2, "n"), "1/2");
|
||||
gst_structure_free (s1);
|
||||
gst_structure_free (s2);
|
||||
|
|
Loading…
Reference in a new issue