1 /* GStreamer Editing Services
3 * Copyright (C) <2013> Thibault Saunier <thibault.saunier@collabora.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 #include "ges-validate.h"
31 _print_position (GstElement * pipeline)
33 gint64 position = 0, duration = -1;
36 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
38 gst_element_query_duration (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
41 gst_print ("<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
42 "/>\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration));
48 #ifdef HAVE_GST_VALIDATE
49 #include <gst/validate/gst-validate-scenario.h>
50 #include <gst/validate/validate.h>
51 #include <gst/validate/gst-validate-utils.h>
52 #include <gst/validate/gst-validate-element-monitor.h>
53 #include <gst/validate/gst-validate-bin-monitor.h>
55 #define MONITOR_ON_PIPELINE "validate-monitor"
56 #define RUNNER_ON_PIPELINE "runner-monitor"
57 #define WRONG_DECODER_ADDED g_quark_from_static_string ("ges::wrong-decoder-added")
60 _validate_report_added_cb (GstValidateRunner * runner,
61 GstValidateReport * report, GstPipeline * pipeline)
63 if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) {
64 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
65 GST_DEBUG_GRAPH_SHOW_ALL, "ges-launch--validate-error");
70 bin_element_added (GstTracer * runner, GstClockTime ts,
71 GstBin * bin, GstElement * element, gboolean result)
74 GstValidateElementMonitor *monitor =
75 g_object_get_data (G_OBJECT (element), "validate-monitor");
80 if (!monitor->is_decoder)
83 parent = gst_object_get_parent (GST_OBJECT (element));
85 if (GES_IS_TRACK (parent)) {
86 GstElementClass *klass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
87 const gchar *klassname =
88 gst_element_class_get_metadata (klass, GST_ELEMENT_METADATA_KLASS);
90 if (GES_IS_AUDIO_TRACK (parent) && strstr (klassname, "Audio") == NULL) {
91 GST_VALIDATE_REPORT (monitor, WRONG_DECODER_ADDED,
92 "Adding non audio decoder %s in audio track %s.",
93 GST_OBJECT_NAME (element), GST_OBJECT_NAME (parent));
94 } else if (GES_IS_VIDEO_TRACK (parent)
95 && strstr (klassname, "Video") == NULL
96 && strstr (klassname, "Image") == NULL) {
97 GST_VALIDATE_REPORT (monitor, WRONG_DECODER_ADDED,
98 "Adding non video decoder %s in video track %s.",
99 GST_OBJECT_NAME (element), GST_OBJECT_NAME (parent));
102 gst_object_unref (parent);
106 gst_object_unref (parent);
107 parent = gst_object_get_parent (parent);
112 ges_validate_register_issues (void)
114 gst_validate_issue_register (gst_validate_issue_new (WRONG_DECODER_ADDED,
115 "Wrong decoder type added to track.",
116 "In a specific track type we should never create decoders"
117 " for some other types (No audio decoder should be added"
118 " in a Video track).", GST_VALIDATE_REPORT_LEVEL_CRITICAL));
122 ges_validate_activate (GstPipeline * pipeline, GESLauncher * launcher,
123 GESLauncherParsedOptions * opts)
125 GstValidateRunner *runner = NULL;
126 GstValidateMonitor *monitor = NULL;
128 if (!opts->enable_validate) {
129 opts->needs_set_state = TRUE;
130 g_object_set_data (G_OBJECT (pipeline), "pposition-id",
131 GUINT_TO_POINTER (g_timeout_add (200,
132 (GSourceFunc) _print_position, pipeline)));
136 gst_validate_init_debug ();
138 if (opts->testfile) {
140 g_error ("Can not specify scenario and testfile at the same time");
141 gst_validate_setup_test_file (opts->testfile, opts->mute);
142 } else if (opts->scenario) {
143 if (g_strcmp0 (opts->scenario, "none")) {
144 gchar *scenario_name =
145 g_strconcat (opts->scenario, "->gespipeline*", NULL);
146 g_setenv ("GST_VALIDATE_SCENARIO", scenario_name, TRUE);
147 g_free (scenario_name);
151 ges_validate_register_action_types ();
152 ges_validate_register_issues ();
154 runner = gst_validate_runner_new ();
155 gst_tracing_register_hook (GST_TRACER (runner), "bin-add-post",
156 G_CALLBACK (bin_element_added));
157 g_signal_connect (runner, "report-added",
158 G_CALLBACK (_validate_report_added_cb), pipeline);
160 gst_validate_monitor_factory_create (GST_OBJECT_CAST (pipeline), runner,
162 if (GST_VALIDATE_BIN_MONITOR (monitor)->scenario) {
163 GstStructure *metas =
164 GST_VALIDATE_BIN_MONITOR (monitor)->scenario->description;
167 gchar **ges_options = gst_validate_utils_get_strv (metas, "ges-options");
169 ges_options = gst_validate_utils_get_strv (metas, "args");
171 gst_structure_get_boolean (metas, "ignore-eos", &opts->ignore_eos);
174 gchar **ges_options_full =
175 g_new0 (gchar *, g_strv_length (ges_options) + 2);
177 ges_options_full[0] = g_strdup ("something");
178 for (i = 0; ges_options[i]; i++)
179 ges_options_full[i + 1] = g_strdup (ges_options[i]);
181 ges_launcher_parse_options (launcher, &ges_options_full, NULL, NULL,
183 opts->sanitized_timeline =
184 sanitize_timeline_description (ges_options_full, opts);
185 g_strfreev (ges_options_full);
186 g_strfreev (ges_options);
191 gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
193 g_object_get (monitor, "handles-states", &opts->needs_set_state, NULL);
194 opts->needs_set_state = !opts->needs_set_state;
195 g_object_set_data (G_OBJECT (pipeline), MONITOR_ON_PIPELINE, monitor);
196 g_object_set_data (G_OBJECT (pipeline), RUNNER_ON_PIPELINE, runner);
202 ges_validate_clean (GstPipeline * pipeline)
205 GstValidateMonitor *monitor =
206 g_object_get_data (G_OBJECT (pipeline), MONITOR_ON_PIPELINE);
207 GstValidateRunner *runner =
208 g_object_get_data (G_OBJECT (pipeline), RUNNER_ON_PIPELINE);
211 res = gst_validate_runner_exit (runner, TRUE);
213 g_source_remove (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (pipeline),
216 gst_object_unref (pipeline);
218 gst_object_unref (runner);
220 gst_object_unref (monitor);
226 ges_validate_handle_request_state_change (GstMessage * message,
227 GApplication * application)
231 gst_message_parse_request_state (message, &state);
233 if (GST_IS_VALIDATE_SCENARIO (GST_MESSAGE_SRC (message))
234 && state == GST_STATE_NULL) {
235 gst_validate_printf (GST_MESSAGE_SRC (message),
236 "State change request NULL, " "quitting application\n");
237 g_application_quit (application);
242 ges_validate_print_action_types (const gchar ** types, gint num_types)
244 ges_validate_register_action_types ();
246 if (!gst_validate_print_action_types (types, num_types)) {
247 GST_ERROR ("Could not print all wanted types");
256 ges_validate_activate (GstPipeline * pipeline, GESLauncher * launcher,
257 GESLauncherParsedOptions * opts)
259 if (opts->testfile) {
260 GST_WARNING ("Trying to run testfile %s, but gst-validate not supported",
266 if (opts->scenario) {
267 GST_WARNING ("Trying to run scenario %s, but gst-validate not supported",
273 g_object_set_data (G_OBJECT (pipeline), "pposition-id",
274 GUINT_TO_POINTER (g_timeout_add (200,
275 (GSourceFunc) _print_position, pipeline)));
277 opts->needs_set_state = TRUE;
283 ges_validate_clean (GstPipeline * pipeline)
285 g_source_remove (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (pipeline),
288 gst_object_unref (pipeline);
294 ges_validate_handle_request_state_change (GstMessage * message,
295 GApplication * application)
301 ges_validate_print_action_types (const gchar ** types, gint num_types)