validate:scenario: Make GstValidateAction a GstMiniObject

This commit is contained in:
Thibault Saunier 2014-02-18 18:15:33 +01:00
parent 04029cb065
commit 63f8034bec
2 changed files with 89 additions and 39 deletions

View file

@ -91,15 +91,58 @@ typedef struct KeyFileGroupName
gchar *group_name; gchar *group_name;
} KeyFileGroupName; } KeyFileGroupName;
static void GType _gst_validate_action_type;
_free_scenario_action (GstValidateAction * act) static GType gst_validate_action_get_type (void);
{
if (act->structure)
gst_structure_free (act->structure);
g_slice_free (GstValidateAction, act); GST_DEFINE_MINI_OBJECT_TYPE (GstValidateAction, gst_validate_action);
static GstValidateAction * gst_validate_action_new (void);
static GstValidateAction *
_action_copy (GstValidateAction *act)
{
GstValidateAction *copy = gst_validate_action_new ();
if (act->structure) {
copy->structure = gst_structure_copy (act->structure);
copy->type = gst_structure_get_name (copy->structure);
if (!(act->name = gst_structure_get_string (copy->structure, "name")))
act->name = "";
} }
copy->action_number = act->action_number;
copy->playback_time = act->playback_time;
return copy;
}
static void
_action_free (GstValidateAction *action)
{
if (action->structure)
gst_structure_free (action->structure);
}
static void
gst_validate_action_init (GstValidateAction *action)
{
gst_mini_object_init (((GstMiniObject*) action), 0, _gst_validate_action_type,
(GstMiniObjectCopyFunction) _action_copy,
NULL,
(GstMiniObjectFreeFunction) _action_free);
}
static GstValidateAction *
gst_validate_action_new (void)
{
GstValidateAction *action = g_slice_new0 (GstValidateAction);
gst_validate_action_init (action);
return action;
}
static gboolean static gboolean
_set_variable_func (const gchar * name, double *value, gpointer user_data) _set_variable_func (const gchar * name, double *value, gpointer user_data)
{ {
@ -143,11 +186,12 @@ gst_validate_action_get_clocktime (GstValidateScenario * scenario,
gchar *error = NULL; gchar *error = NULL;
if (!(strval = gst_structure_get_string (action->structure, name))) { if (!(strval = gst_structure_get_string (action->structure, name))) {
GST_DEBUG_OBJECT (scenario, "Could not find %s", name); GST_WARNING_OBJECT (scenario, "Could not find %s", name);
return FALSE; return FALSE;
} }
val = gst_validate_utils_parse_expression (strval, val =
_set_variable_func, scenario, &error); 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);
@ -181,8 +225,7 @@ _execute_seek (GstValidateScenario * scenario, GstValidateAction * action)
GstClockTime stop = GST_CLOCK_TIME_NONE; GstClockTime stop = GST_CLOCK_TIME_NONE;
GstEvent *seek; GstEvent *seek;
if (!gst_validate_action_get_clocktime (scenario, action, "start", if (!gst_validate_action_get_clocktime (scenario, action, "start", &start))
&start))
return FALSE; return FALSE;
gst_structure_get_double (action->structure, "rate", &rate); gst_structure_get_double (action->structure, "rate", &rate);
@ -601,7 +644,7 @@ get_position (GstValidateScenario * scenario)
} else { } else {
tmp = priv->actions; tmp = priv->actions;
priv->actions = g_list_remove_link (priv->actions, tmp); priv->actions = g_list_remove_link (priv->actions, tmp);
_free_scenario_action (act); gst_mini_object_unref (GST_MINI_OBJECT (act));
g_list_free (tmp); g_list_free (tmp);
} }
} }
@ -873,7 +916,7 @@ _load_scenario_file (GstValidateScenario * scenario,
goto failed; goto failed;
} }
action = g_slice_new0 (GstValidateAction); action = gst_validate_action_new ();
action->type = type; action->type = type;
action->repeat = -1; action->repeat = -1;
if (gst_structure_get_double (structure, "playback_time", &playback_time)) { if (gst_structure_get_double (structure, "playback_time", &playback_time)) {
@ -882,16 +925,17 @@ _load_scenario_file (GstValidateScenario * scenario,
gst_structure_get_string (structure, "playback_time"))) { gst_structure_get_string (structure, "playback_time"))) {
priv->needs_parsing = g_list_append (priv->needs_parsing, action); priv->needs_parsing = g_list_append (priv->needs_parsing, action);
} else } else
GST_WARNING_OBJECT (scenario, "No playback time for action %" GST_PTR_FORMAT, GST_WARNING_OBJECT (scenario,
structure); "No playback time for action %" GST_PTR_FORMAT, structure);
if (!(action->name = gst_structure_get_string (structure, "name"))) if (!(action->name = gst_structure_get_string (structure, "name")))
action->name = ""; action->name = "";
action->structure = structure; action->structure = structure;
if (action_type->is_config) { if (action_type->is_config) {
ret = action_type->execute (scenario, action); ret = action_type->execute (scenario, action);
g_slice_free (GstValidateAction, action); gst_mini_object_unref (GST_MINI_OBJECT (action));
if (ret == FALSE) if (ret == FALSE)
goto failed; goto failed;
@ -1080,6 +1124,7 @@ gst_validate_scenario_dispose (GObject * object)
gst_event_unref (priv->last_seek); gst_event_unref (priv->last_seek);
if (GST_VALIDATE_SCENARIO (object)->pipeline) if (GST_VALIDATE_SCENARIO (object)->pipeline)
gst_object_unref (GST_VALIDATE_SCENARIO (object)->pipeline); gst_object_unref (GST_VALIDATE_SCENARIO (object)->pipeline);
g_list_free_full (priv->actions, (GDestroyNotify) gst_mini_object_unref);
G_OBJECT_CLASS (gst_validate_scenario_parent_class)->dispose (object); G_OBJECT_CLASS (gst_validate_scenario_parent_class)->dispose (object);
} }
@ -1173,7 +1218,8 @@ _list_scenarios_in_dir (GFile * dir, GKeyFile *kf)
kfg.group_name = name[0]; kfg.group_name = name[0];
kfg.kf = kf; kfg.kf = kf;
gst_structure_foreach (desc, (GstStructureForeachFunc) _add_description, &kfg); gst_structure_foreach (desc, (GstStructureForeachFunc) _add_description,
&kfg);
} else { } else {
g_key_file_set_string (kf, name[0], "noinfo", "nothing"); g_key_file_set_string (kf, name[0], "noinfo", "nothing");
} }
@ -1273,8 +1319,9 @@ init_scenarios (void)
{ {
const gchar *seek_mandatory_fields[] = { "start", NULL }; const gchar *seek_mandatory_fields[] = { "start", NULL };
clean_action_str = _gst_validate_action_type = gst_validate_action_get_type ();
g_regex_new ("\\\\\n", G_REGEX_CASELESS, 0, NULL);
clean_action_str = g_regex_new ("\\\\\n", G_REGEX_CASELESS, 0, NULL);
gst_validate_add_action_type ("seek", _execute_seek, seek_mandatory_fields, gst_validate_add_action_type ("seek", _execute_seek, seek_mandatory_fields,
"Allows to seek into the files", FALSE); "Allows to seek into the files", FALSE);
gst_validate_add_action_type ("pause", _execute_pause, NULL, gst_validate_add_action_type ("pause", _execute_pause, NULL,
@ -1295,6 +1342,5 @@ init_scenarios (void)
" track'), note that you need to state that it is a string in the scenario file" " track'), note that you need to state that it is a string in the scenario file"
" prefixing it with (string).", FALSE); " prefixing it with (string).", FALSE);
gst_validate_add_action_type ("set-feature-rank", _set_rank, NULL, gst_validate_add_action_type ("set-feature-rank", _set_rank, NULL,
"Allows you to change the ranking of a particular plugin feature", "Allows you to change the ranking of a particular plugin feature", TRUE);
TRUE);
} }

View file

@ -43,8 +43,12 @@ typedef struct _GstValidateAction GstValidateAction;
typedef gboolean (*GstValidateExecuteAction) (GstValidateScenario * scenario, GstValidateAction * action); typedef gboolean (*GstValidateExecuteAction) (GstValidateScenario * scenario, GstValidateAction * action);
GST_EXPORT GType _gst_validate_action_type;
struct _GstValidateAction struct _GstValidateAction
{ {
GstMiniObject mini_object;
const gchar *type; const gchar *type;
const gchar *name; const gchar *name;
guint action_number; guint action_number;