From: Thibault Saunier Date: Thu, 19 Jul 2018 22:27:32 +0000 (-0400) Subject: validate:scenario: Add a way to define constants to be used in actions X-Git-Tag: 1.19.3~491^2~506 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=61a899acf2ed20d970721d8edf527ea308aff5f8;p=platform%2Fupstream%2Fgstreamer.git validate:scenario: Add a way to define constants to be used in actions Allowing writing simpler to read scenarios. --- diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index 72f7749..1836fa0 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -800,7 +800,7 @@ gst_validate_print_action (GstValidateAction * action, const gchar * message) if (gst_structure_get_int (action->structure, "repeat", &nrepeats)) g_string_append_printf (string, "(%d/%d)", action->repeat, nrepeats); - g_string_append_printf (string, " %s", + g_string_append_printf (string, "%s", gst_structure_get_name (action->structure)); g_string_append_len (string, ": ", 2); diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c index fab2c48..41ea07f 100644 --- a/validate/gst/validate/gst-validate-scenario.c +++ b/validate/gst/validate/gst-validate-scenario.c @@ -164,6 +164,8 @@ struct _GstValidateScenarioPrivate * GST_MESSAGE_STREAMS_SELECTED to be completed. */ GstValidateAction *pending_switch_track; + GstStructure *constants; + GWeakRef ref_pipeline; }; @@ -339,6 +341,25 @@ gst_validate_action_unref (GstValidateAction * action) gst_mini_object_unref (GST_MINI_OBJECT (action)); } +static const gchar * +gst_validate_action_get_string (GstValidateAction * action, + const gchar * fieldname) +{ + GstValidateScenario *scenario = gst_validate_action_get_scenario (action); + const gchar *res, *val; + + res = val = gst_structure_get_string (action->structure, fieldname); + if (val && scenario) { + val = gst_structure_get_string (scenario->priv->constants, val); + + if (val) + res = val; + } + g_clear_object (&scenario); + + return res; +} + static GstValidateAction * gst_validate_action_new (GstValidateScenario * scenario, GstValidateActionType * action_type) @@ -701,6 +722,23 @@ _pause_action_restore_playing (GstValidateScenario * scenario) return FALSE; } +static gboolean +_set_const_func (GQuark field_id, const GValue * value, GstStructure * consts) +{ + gst_structure_id_set_value (consts, field_id, value); + + return TRUE; +} + +static GstValidateExecuteActionReturn +_execute_add_consts (GstValidateScenario * scenario, GstValidateAction * action) +{ + gst_structure_foreach (action->structure, + (GstStructureForeachFunc) _set_const_func, scenario->priv->constants); + + return GST_VALIDATE_EXECUTE_ACTION_OK; +} + static GstValidateExecuteActionReturn _execute_set_state (GstValidateScenario * scenario, GstValidateAction * action) { @@ -3123,6 +3161,7 @@ gst_validate_scenario_init (GstValidateScenario * scenario) priv->segment_start = 0; priv->segment_stop = GST_CLOCK_TIME_NONE; priv->action_execution_interval = 10; + priv->constants = gst_structure_new_empty ("constants"); g_weak_ref_init (&scenario->priv->ref_pipeline, NULL); g_mutex_init (&priv->lock); @@ -3164,6 +3203,7 @@ gst_validate_scenario_finalize (GObject * object) g_list_free_full (priv->needs_parsing, (GDestroyNotify) gst_mini_object_unref); g_free (priv->pipeline_name); + gst_structure_free (priv->constants); g_mutex_clear (&priv->lock); G_OBJECT_CLASS (gst_validate_scenario_parent_class)->finalize (object); @@ -4196,6 +4236,19 @@ init_scenarios (void) "Changes the state of the pipeline to any GstState", GST_VALIDATE_ACTION_TYPE_ASYNC & GST_VALIDATE_ACTION_TYPE_NEEDS_CLOCK); + REGISTER_ACTION_TYPE ("define-consts", _execute_add_consts, + ((GstValidateActionParameter []) { + {NULL} + }), + "Define constants to be used in other actions.\n" + "For example you can define constants for buffer checksum" + " to be used in the \"check-last-sample\" action type as follow:\n\n" + "```\n" + " define-consts, frame1=SomeRandomHash1,frame2=Anotherhash...\n" + " check-last-sample, checksum=frame1\n" + "```\n", + GST_VALIDATE_ACTION_TYPE_NONE); + REGISTER_ACTION_TYPE ("set-property", _execute_set_property, ((GstValidateActionParameter []) { {