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

View file

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

View file

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