7 #include "gst-validate-utils.h"
8 #include "gst-validate-internal.h"
12 #define EXTRA_CHECKS_WRONG_NUMBER_OF_INSTANCES g_quark_from_static_string ("extrachecks::wrong-number-of-instances")
18 gint expected_n_instances;
20 } CheckNumInstanceData;
22 static CheckNumInstanceData *
23 gst_validate_check_num_instances_data_new (GstStructure * check)
25 CheckNumInstanceData *data = g_new0 (CheckNumInstanceData, 1);
27 if (!gst_structure_get_int (check, "num-instances",
28 &data->expected_n_instances)) {
30 ("[CONFIG ERROR] Mandatory field `num-instances` not found in "
31 "extra-check `num-instances`");
35 data->pname = g_strdup (gst_structure_get_string (check, "pipeline-name"));
38 ("[CONFIG ERROR] Mandatory field `pipeline` not found in "
39 "extra-check `num-instances`");
43 data->klass = g_strdup (gst_structure_get_string (check, "element-klass"));
46 ("[CONFIG ERROR] Mandatory field `element-klass` not found in "
47 "extra-check `num-instances`");
61 gst_validate_check_num_instances_data_free (CheckNumInstanceData * data)
68 gst_validate_check_num_instances (GstValidateOverride * o,
69 GstValidateMonitor * monitor, GstElement * nelem)
72 CheckNumInstanceData *data = g_object_get_data (G_OBJECT (o), "check-data");
73 GstPipeline *pipe = gst_validate_monitor_get_pipeline (monitor);
78 pname = gst_object_get_name (GST_OBJECT (pipe));
79 if (g_strcmp0 (data->pname, pname))
82 if (!gst_validate_element_has_klass (nelem, data->klass))
87 if (data->n_instances > data->expected_n_instances) {
88 GST_VALIDATE_REPORT (o, EXTRA_CHECKS_WRONG_NUMBER_OF_INSTANCES,
89 "%d instances allows in pipeline %s but already %d where added.",
90 data->expected_n_instances, pname, data->n_instances);
92 GST_ERROR_OBJECT (nelem, "HERE I AM %d", data->n_instances);
96 gst_object_unref (pipe);
100 runner_stopping (GstValidateRunner * runner, GstValidateOverride * o)
102 CheckNumInstanceData *data = g_object_get_data (G_OBJECT (o), "check-data");
104 if (data->expected_n_instances != data->n_instances) {
105 GST_VALIDATE_REPORT (o, EXTRA_CHECKS_WRONG_NUMBER_OF_INSTANCES,
106 "%d instances expected in pipeline %s but %d where added.",
107 data->expected_n_instances, data->pname, data->n_instances);
112 _runner_set (GObject * object, GParamSpec * pspec, gpointer user_data)
114 GstValidateRunner *runner =
115 gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (object));
117 g_signal_connect (runner, "stopping", G_CALLBACK (runner_stopping), object);
118 gst_object_unref (runner);
122 gst_validate_add_num_instances_check (GstStructure * structure)
124 CheckNumInstanceData *data =
125 gst_validate_check_num_instances_data_new (structure);
126 GstValidateOverride *o = gst_validate_override_new ();
128 g_object_set_data_full (G_OBJECT (o), "check-data", data,
129 (GDestroyNotify) gst_validate_check_num_instances_data_free);
131 gst_validate_override_set_element_added_handler (o,
132 gst_validate_check_num_instances);
134 g_signal_connect (o, "notify::validate-runner", G_CALLBACK (_runner_set),
137 gst_validate_override_register_by_type (GST_TYPE_BIN, o);
138 gst_object_unref (o);
142 gst_validate_extra_checks_init ()
145 config = gst_validate_get_config ("extrachecks");
150 for (tmp = config; tmp; tmp = tmp->next) {
151 GstStructure *check = tmp->data;
153 if (gst_structure_has_field (check, "num-instances"))
154 gst_validate_add_num_instances_check (check);
156 g_list_free (config);
158 gst_validate_issue_register (gst_validate_issue_new
159 (EXTRA_CHECKS_WRONG_NUMBER_OF_INSTANCES,
160 "The configured number of possible instances of an element type"
161 " in a pipeline is not respected.",
162 "The `num-instances` extra checks allow user to make sure that"
163 " a previously defined number of instances of an element is added"
164 " in a given pipeline, that test failed.",
165 GST_VALIDATE_REPORT_LEVEL_CRITICAL));