validate: Let scenarios tell the apps about whether it handles states

The user only needs to add handles-states=true in the description line
of the scenario
This commit is contained in:
Thibault Saunier 2014-07-02 11:27:22 +02:00
parent 52e39a4fcb
commit 87ae465c77
3 changed files with 56 additions and 47 deletions

View file

@ -41,7 +41,7 @@
enum enum
{ {
PROP_0, PROP_0,
PROP_STATELESS, PROP_HANDLES_STATE,
PROP_LAST PROP_LAST
}; };
@ -68,15 +68,9 @@ static void
gst_validate_bin_monitor_set_property (GObject * object, guint prop_id, gst_validate_bin_monitor_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstValidateBinMonitor *monitor;
monitor = GST_VALIDATE_BIN_MONITOR_CAST (object);
switch (prop_id) { switch (prop_id) {
case PROP_STATELESS: case PROP_HANDLES_STATE:
monitor->stateless = g_value_get_boolean (value); g_assert_not_reached ();
if (monitor->scenario != NULL)
g_object_set (monitor->scenario, "stateless", monitor->stateless, NULL);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -93,8 +87,12 @@ gst_validate_bin_monitor_get_property (GObject * object, guint prop_id,
monitor = GST_VALIDATE_BIN_MONITOR_CAST (object); monitor = GST_VALIDATE_BIN_MONITOR_CAST (object);
switch (prop_id) { switch (prop_id) {
case PROP_STATELESS: case PROP_HANDLES_STATE:
g_value_set_boolean (value, monitor->stateless); if (monitor->scenario == NULL)
g_value_set_boolean (value, FALSE);
else
g_object_get_property (G_OBJECT (monitor->scenario), "handles-states",
value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -138,10 +136,11 @@ gst_validate_bin_monitor_class_init (GstValidateBinMonitorClass * klass)
gobject_class->set_property = gst_validate_bin_monitor_set_property; gobject_class->set_property = gst_validate_bin_monitor_set_property;
gobject_class->dispose = gst_validate_bin_monitor_dispose; gobject_class->dispose = gst_validate_bin_monitor_dispose;
g_object_class_install_property (gobject_class, PROP_STATELESS, g_object_class_install_property (gobject_class, PROP_HANDLES_STATE,
g_param_spec_boolean ("stateless", "Stateless", g_param_spec_boolean ("handles-states", "Handles state",
"True to execute actions as soon as possible, regardless " "True if the application should not set handle the first state change "
"of the initial state of the pipeline", FALSE, G_PARAM_READWRITE)); " False if it is application responsibility",
FALSE, G_PARAM_READABLE));
validatemonitor_class->setup = gst_validate_bin_monitor_setup; validatemonitor_class->setup = gst_validate_bin_monitor_setup;
} }

View file

@ -52,7 +52,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_RUNNER, PROP_RUNNER,
PROP_STATELESS, PROP_HANDLES_STATE,
PROP_LAST PROP_LAST
}; };
@ -89,7 +89,7 @@ struct _GstValidateScenarioPrivate
guint num_actions; guint num_actions;
gboolean stateless; gboolean handles_state;
guint get_pos_id; guint get_pos_id;
guint wait_id; guint wait_id;
@ -1141,6 +1141,8 @@ _load_scenario_file (GstValidateScenario * scenario,
type = gst_structure_get_name (structure); type = gst_structure_get_name (structure);
if (!g_strcmp0 (type, "description")) { if (!g_strcmp0 (type, "description")) {
gst_structure_get_boolean (structure, "is-config", is_config); gst_structure_get_boolean (structure, "is-config", is_config);
gst_structure_get_boolean (structure, "handles-states",
&priv->handles_state);
continue; continue;
} else if (!(action_type = g_hash_table_lookup (action_types_table, type))) { } else if (!(action_type = g_hash_table_lookup (action_types_table, type))) {
GST_ERROR_OBJECT (scenario, "We do not handle action types %s", type); GST_ERROR_OBJECT (scenario, "We do not handle action types %s", type);
@ -1324,8 +1326,6 @@ static void
gst_validate_scenario_set_property (GObject * object, guint prop_id, gst_validate_scenario_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstValidateScenario *self = GST_VALIDATE_SCENARIO (object);
switch (prop_id) { switch (prop_id) {
case PROP_RUNNER: case PROP_RUNNER:
/* we assume the runner is valid as long as this scenario is, /* we assume the runner is valid as long as this scenario is,
@ -1333,10 +1333,8 @@ gst_validate_scenario_set_property (GObject * object, guint prop_id,
gst_validate_reporter_set_runner (GST_VALIDATE_REPORTER (object), gst_validate_reporter_set_runner (GST_VALIDATE_REPORTER (object),
g_value_get_object (value)); g_value_get_object (value));
break; break;
case PROP_STATELESS: case PROP_HANDLES_STATE:
self->priv->stateless = g_value_get_boolean (value); g_assert_not_reached ();
if (self->priv->stateless)
_add_get_position_source (self);
break; break;
default: default:
break; break;
@ -1356,8 +1354,8 @@ gst_validate_scenario_get_property (GObject * object, guint prop_id,
g_value_set_object (value, g_value_set_object (value,
gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (object))); gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (object)));
break; break;
case PROP_STATELESS: case PROP_HANDLES_STATE:
g_value_set_boolean (value, self->priv->stateless); g_value_set_boolean (value, self->priv->handles_state);
break; break;
default: default:
break; break;
@ -1383,10 +1381,11 @@ gst_validate_scenario_class_init (GstValidateScenarioClass * klass)
GST_TYPE_VALIDATE_RUNNER, GST_TYPE_VALIDATE_RUNNER,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_STATELESS, g_object_class_install_property (object_class, PROP_HANDLES_STATE,
g_param_spec_boolean ("stateless", "Stateless", g_param_spec_boolean ("handles-states", "Handles state",
"True to execute actions as soon as possible, regardless " "True if the application should not set handle the first state change "
"of the initial state of the pipeline", FALSE, G_PARAM_READWRITE)); " False if it is application responsibility",
FALSE, G_PARAM_READABLE));
} }
static void static void
@ -1447,6 +1446,12 @@ gst_validate_scenario_factory_create (GstValidateRunner *
g_signal_connect (bus, "message", (GCallback) message_cb, scenario); g_signal_connect (bus, "message", (GCallback) message_cb, scenario);
gst_object_unref (bus); gst_object_unref (bus);
if (scenario->priv->handles_state) {
GST_INFO_OBJECT (scenario, "Scenario handles state,"
" Starting the get position source");
_add_get_position_source (scenario);
}
gst_validate_printf (NULL, gst_validate_printf (NULL,
"\n=========================================\n" "\n=========================================\n"
"Running scenario %s on pipeline %s" "Running scenario %s on pipeline %s"

View file

@ -295,7 +295,7 @@ main (int argc, gchar ** argv)
{ {
GError *err = NULL; GError *err = NULL;
const gchar *scenario = NULL, *configs = NULL; const gchar *scenario = NULL, *configs = NULL;
gboolean list_scenarios = FALSE; gboolean list_scenarios = FALSE, monitor_handles_state;
GstStateChangeReturn sret; GstStateChangeReturn sret;
gchar *output_file = NULL; gchar *output_file = NULL;
gint ret = 0; gint ret = 0;
@ -442,25 +442,30 @@ main (int argc, gchar ** argv)
gst_object_unref (bus); gst_object_unref (bus);
g_print ("Starting pipeline\n"); g_print ("Starting pipeline\n");
sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); g_object_get (monitor, "handles-states", &monitor_handles_state, NULL);
switch (sret) { if (monitor_handles_state == FALSE) {
case GST_STATE_CHANGE_FAILURE: sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* ignore, we should get an error message posted on the bus */ switch (sret) {
g_print ("Pipeline failed to go to PLAYING state\n"); case GST_STATE_CHANGE_FAILURE:
ret = -1; /* ignore, we should get an error message posted on the bus */
goto exit; g_print ("Pipeline failed to go to PLAYING state\n");
case GST_STATE_CHANGE_NO_PREROLL: ret = -1;
g_print ("Pipeline is live.\n"); goto exit;
is_live = TRUE; case GST_STATE_CHANGE_NO_PREROLL:
break; g_print ("Pipeline is live.\n");
case GST_STATE_CHANGE_ASYNC: is_live = TRUE;
g_print ("Prerolling...\r"); break;
break; case GST_STATE_CHANGE_ASYNC:
default: g_print ("Prerolling...\r");
break; break;
default:
break;
}
g_print ("Pipeline started\n");
} else {
g_print ("Letting scenario handle set state\n");
} }
g_print ("Pipeline started\n");
g_main_loop_run (mainloop); g_main_loop_run (mainloop);
rep_err = gst_validate_runner_printf (runner); rep_err = gst_validate_runner_printf (runner);