2013-07-09 19:08:30 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2013 Thiago Santos <thiago.sousa.santos@collabora.com>
|
|
|
|
*/
|
|
|
|
|
2013-07-11 16:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2013-08-14 19:30:39 +00:00
|
|
|
#include <gst/validate/validate.h>
|
2013-07-09 19:08:30 +00:00
|
|
|
|
2013-07-11 16:41:25 +00:00
|
|
|
static GMainLoop *mainloop;
|
|
|
|
static GstElement *pipeline;
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
static gboolean
|
|
|
|
bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = data;
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
{
|
|
|
|
GError *err;
|
|
|
|
gchar *debug;
|
|
|
|
gst_message_parse_error (message, &err, &debug);
|
|
|
|
g_print ("Error: %s\n", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
g_free (debug);
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
2013-07-24 23:09:14 +00:00
|
|
|
const gchar *scenario = NULL;
|
2013-07-30 19:20:49 +00:00
|
|
|
guint count = -1;
|
2013-07-24 23:09:14 +00:00
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
GOptionEntry options[] = {
|
2013-07-24 23:09:14 +00:00
|
|
|
{"set-scenario", '\0', 0, G_OPTION_ARG_STRING, &scenario,
|
2013-08-14 19:30:39 +00:00
|
|
|
"Let you set a scenario, it will override the GST_VALIDATE_SCENARIO "
|
2013-07-24 23:09:14 +00:00
|
|
|
"environment variable", NULL},
|
2013-07-09 19:08:30 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GOptionContext *ctx;
|
|
|
|
gchar **argvn;
|
2013-08-14 19:30:39 +00:00
|
|
|
GstValidateRunner *runner;
|
|
|
|
GstValidateMonitor *monitor;
|
2013-07-09 19:08:30 +00:00
|
|
|
GstBus *bus;
|
|
|
|
|
2013-08-14 21:04:23 +00:00
|
|
|
g_set_prgname ("gst-validate-" GST_API_VERSION);
|
|
|
|
ctx = g_option_context_new ("PIPELINE-DESCRIPTION");
|
2013-07-09 19:08:30 +00:00
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
2013-08-14 21:04:23 +00:00
|
|
|
g_option_context_set_summary (ctx, "Runs a gst launch pipeline, adding "
|
2013-08-21 15:11:40 +00:00
|
|
|
"monitors to it to identify issues in the used elements. At the end"
|
|
|
|
" a report will be printed. To view issues as they are created, set"
|
|
|
|
"the env var GST_DEBUG=gstvalidatereport:2 and it will be printed "
|
|
|
|
"as gstreamer debugging");
|
2013-07-09 19:08:30 +00:00
|
|
|
|
2013-07-23 15:14:26 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
g_print ("%s", g_option_context_get_help (ctx, FALSE, NULL));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_printerr ("Error initializing: %s\n", err->message);
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2013-07-24 23:09:14 +00:00
|
|
|
if (scenario) {
|
2013-08-14 19:30:39 +00:00
|
|
|
g_setenv ("GST_VALIDATE_SCENARIO", scenario, TRUE);
|
2013-07-24 23:09:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
2013-08-14 22:14:18 +00:00
|
|
|
gst_validate_init ();
|
2013-07-09 19:08:30 +00:00
|
|
|
|
|
|
|
/* Create the pipeline */
|
|
|
|
argvn = g_new0 (char *, argc);
|
|
|
|
memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
|
|
|
|
pipeline = (GstElement *) gst_parse_launchv ((const gchar **) argvn, &err);
|
|
|
|
g_free (argvn);
|
|
|
|
|
2013-08-14 19:30:39 +00:00
|
|
|
runner = gst_validate_runner_new ();
|
2013-08-07 19:10:57 +00:00
|
|
|
monitor =
|
2013-08-14 19:30:39 +00:00
|
|
|
gst_validate_monitor_factory_create (GST_OBJECT_CAST (pipeline), runner,
|
|
|
|
NULL);
|
2013-07-09 19:08:30 +00:00
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2013-07-30 13:21:13 +00:00
|
|
|
if (!runner) {
|
2013-08-14 19:30:39 +00:00
|
|
|
g_printerr ("Failed to setup Validate Runner\n");
|
2013-07-09 19:08:30 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bus = gst_element_get_bus (pipeline);
|
|
|
|
gst_bus_add_watch (bus, bus_callback, mainloop);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2013-07-11 16:41:25 +00:00
|
|
|
g_print ("Starting pipeline\n");
|
2013-07-09 19:08:30 +00:00
|
|
|
if (gst_element_set_state (pipeline,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto exit;
|
2013-08-21 15:11:40 +00:00
|
|
|
|
|
|
|
g_print ("Pipeline started\n");
|
2013-07-09 19:08:30 +00:00
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
2013-08-14 19:30:39 +00:00
|
|
|
count = gst_validate_runner_get_reports_count (runner);
|
2013-07-30 19:20:49 +00:00
|
|
|
g_print ("Pipeline finished, issues found: %u\n", count);
|
2013-08-21 15:11:40 +00:00
|
|
|
if (count) {
|
|
|
|
GSList *iter;
|
|
|
|
GSList *issues = gst_validate_runner_get_reports (runner);
|
|
|
|
|
|
|
|
for (iter = issues; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstValidateReport *report = iter->data;
|
|
|
|
gst_validate_report_printf (report);
|
|
|
|
}
|
|
|
|
}
|
2013-07-09 19:08:30 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
g_main_loop_unref (mainloop);
|
2013-08-07 19:10:57 +00:00
|
|
|
g_object_unref (monitor);
|
2013-07-09 19:08:30 +00:00
|
|
|
g_object_unref (runner);
|
2013-07-12 05:10:06 +00:00
|
|
|
g_object_unref (pipeline);
|
2013-07-30 19:20:49 +00:00
|
|
|
if (count)
|
|
|
|
return -1;
|
2013-07-09 19:08:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|