Commit b23cb623 authored by Thibault Saunier's avatar Thibault Saunier 🌵 Committed by GStreamer Marge Bot

validate: Add a way to use the expression parser in any field

Part-of: <gstreamer/gst-devtools!207>
parent f7aba413
......@@ -1300,6 +1300,42 @@ typedef struct
GstStructure *local_vars;
} ReplaceData;
static void
_resolve_expression (gpointer source, GValue * value)
{
gdouble new_value;
GMatchInfo *match_info = NULL;
gchar *error = NULL;
gchar *v, *expr, *tmp;
g_assert (G_VALUE_HOLDS_STRING (value));
tmp = expr = v = g_value_dup_string (value);
tmp = skip_spaces (tmp);
expr = strstr (v, "expr(");
if (expr != tmp)
return;
expr = &expr[5];
tmp = &expr[strlen (expr) - 1];
while (g_ascii_isspace (*tmp) && tmp != expr)
tmp--;
if (tmp == expr || *tmp != ')')
return;
*tmp = '\0';
new_value = gst_validate_utils_parse_expression (expr, NULL, NULL, &error);
if (error)
gst_validate_error_structure (source, "Could not parse expression %s: %s",
expr, error);
g_value_unset (value);
g_value_init (value, G_TYPE_DOUBLE);
g_value_set_double (value, new_value);
g_free (v);
g_match_info_free (match_info);
}
static gboolean
_structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
{
......@@ -1330,6 +1366,8 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
g_free (str);
}
_resolve_expression (data->source, value);
return TRUE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment