2013-07-09 19:08:30 +00:00
|
|
|
/* GStreamer
|
2013-08-28 19:58:11 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Collabora Ltd.
|
|
|
|
* Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>
|
|
|
|
*
|
|
|
|
* gst-validate.c - Validate CLI launch line tool
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2013-07-09 19:08:30 +00:00
|
|
|
*/
|
|
|
|
|
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-08-27 14:56:33 +00:00
|
|
|
#include <gst/validate/gst-validate-scenario.h>
|
2013-07-09 19:08:30 +00:00
|
|
|
|
2013-08-22 13:08:13 +00:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
#include <glib-unix.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-19 18:13:10 +00:00
|
|
|
static gint ret = 0;
|
2013-07-11 16:41:25 +00:00
|
|
|
static GMainLoop *mainloop;
|
|
|
|
static GstElement *pipeline;
|
|
|
|
|
2014-01-24 10:29:50 +00:00
|
|
|
static gboolean buffering = FALSE;
|
|
|
|
static gboolean is_live = FALSE;
|
|
|
|
static guint print_pos_srcid = 0;
|
|
|
|
|
2013-08-22 13:08:13 +00:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
static gboolean
|
|
|
|
intr_handler (gpointer user_data)
|
|
|
|
{
|
|
|
|
g_print ("interrupt received.\n");
|
|
|
|
|
|
|
|
g_main_loop_quit (mainloop);
|
|
|
|
|
|
|
|
/* remove signal handler */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif /* G_OS_UNIX */
|
|
|
|
|
2014-01-09 10:13:40 +00:00
|
|
|
static gboolean
|
|
|
|
print_position (void)
|
|
|
|
{
|
|
|
|
GstQuery *query;
|
|
|
|
gint64 position, duration;
|
|
|
|
|
|
|
|
gdouble rate = 1.0;
|
|
|
|
GstFormat format = GST_FORMAT_TIME;
|
|
|
|
|
|
|
|
gst_element_query_position (pipeline, format, &position);
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
gst_element_query_duration (pipeline, format, &duration);
|
|
|
|
|
|
|
|
query = gst_query_new_segment (GST_FORMAT_DEFAULT);
|
|
|
|
if (gst_element_query (pipeline, query))
|
|
|
|
gst_query_parse_segment (query, &rate, NULL, NULL, NULL);
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
|
|
|
g_print ("<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
|
|
|
|
" speed: %f />\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration),
|
|
|
|
rate);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
static gboolean
|
|
|
|
bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = data;
|
2013-08-15 10:18:56 +00:00
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
{
|
|
|
|
GError *err;
|
|
|
|
gchar *debug;
|
2013-08-19 18:13:10 +00:00
|
|
|
ret = -1;
|
2013-07-09 19:08:30 +00:00
|
|
|
gst_message_parse_error (message, &err, &debug);
|
2014-01-10 17:00:27 +00:00
|
|
|
g_print ("Error: %s -- Setting returncode to -1\n", err->message);
|
2013-07-09 19:08:30 +00:00
|
|
|
g_error_free (err);
|
|
|
|
g_free (debug);
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
g_main_loop_quit (loop);
|
2013-08-22 14:51:49 +00:00
|
|
|
break;
|
2014-03-19 16:43:43 +00:00
|
|
|
case GST_MESSAGE_ASYNC_DONE:
|
|
|
|
if (print_pos_srcid == 0)
|
|
|
|
print_pos_srcid =
|
|
|
|
g_timeout_add (50, (GSourceFunc) print_position, NULL);
|
|
|
|
break;
|
2013-08-22 14:51:49 +00:00
|
|
|
case GST_MESSAGE_STATE_CHANGED:
|
|
|
|
if (GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline)) {
|
|
|
|
GstState oldstate, newstate, pending;
|
|
|
|
|
|
|
|
gst_message_parse_state_changed (message, &oldstate, &newstate,
|
|
|
|
&pending);
|
|
|
|
|
|
|
|
GST_DEBUG ("State changed (old: %s, new: %s, pending: %s)",
|
|
|
|
gst_element_state_get_name (oldstate),
|
|
|
|
gst_element_state_get_name (newstate),
|
|
|
|
gst_element_state_get_name (pending));
|
2014-01-24 10:29:50 +00:00
|
|
|
|
|
|
|
if (newstate == GST_STATE_PLAYING) {
|
|
|
|
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
|
|
|
|
GST_DEBUG_GRAPH_SHOW_ALL, "gst-validate.playing");
|
|
|
|
}
|
2013-08-22 14:51:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
break;
|
2014-01-24 10:29:50 +00:00
|
|
|
case GST_MESSAGE_BUFFERING:{
|
|
|
|
gint percent;
|
|
|
|
|
|
|
|
if (!buffering) {
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_message_parse_buffering (message, &percent);
|
|
|
|
g_print ("%s %d%% \r", "Buffering...", percent);
|
|
|
|
|
|
|
|
/* no state management needed for live pipelines */
|
|
|
|
if (is_live)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (percent == 100) {
|
|
|
|
/* a 100% message means buffering is done */
|
|
|
|
if (buffering) {
|
|
|
|
buffering = FALSE;
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* buffering... */
|
|
|
|
if (!buffering) {
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
if (print_pos_srcid) {
|
|
|
|
if (g_source_remove (print_pos_srcid))
|
|
|
|
print_pos_srcid = 0;
|
|
|
|
}
|
|
|
|
buffering = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-09 19:08:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
2013-10-19 16:41:01 +00:00
|
|
|
const gchar *scenario = NULL, *configs = NULL;
|
2013-08-16 10:50:51 +00:00
|
|
|
gboolean list_scenarios = FALSE;
|
2014-01-24 10:29:50 +00:00
|
|
|
GstStateChangeReturn sret;
|
2014-02-11 23:28:18 +00:00
|
|
|
gchar *output_file = NULL;
|
2014-01-24 10:29:50 +00:00
|
|
|
|
2013-08-22 13:08:13 +00:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
guint signal_watch_id;
|
|
|
|
#endif
|
2013-09-05 08:34:42 +00:00
|
|
|
int rep_err;
|
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-08-16 10:50:51 +00:00
|
|
|
{"list-scenarios", 'l', 0, G_OPTION_ARG_NONE, &list_scenarios,
|
|
|
|
"List the avalaible scenarios that can be run", NULL},
|
2014-02-11 23:28:18 +00:00
|
|
|
{"scenarios-defs-output-file", '\0', 0, G_OPTION_ARG_FILENAME,
|
|
|
|
&output_file, "The output file to store scenarios details. "
|
|
|
|
"Implies --list-scenario",
|
|
|
|
NULL},
|
2013-10-19 16:41:01 +00:00
|
|
|
{"set-configs", '\0', 0, G_OPTION_ARG_STRING, &configs,
|
|
|
|
"Let you set a config scenario, the scenario needs to be set as 'config"
|
|
|
|
"' you can specify a list of scenario separated by ':'"
|
|
|
|
" it will override the GST_VALIDATE_SCENARIO 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"
|
2013-08-21 16:10:42 +00:00
|
|
|
"the env var GST_DEBUG=validate:2 and it will be printed "
|
2013-08-21 15:11:40 +00:00
|
|
|
"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-10-19 16:41:01 +00:00
|
|
|
if (scenario || configs) {
|
|
|
|
gchar *scenarios;
|
|
|
|
|
|
|
|
if (scenario)
|
|
|
|
scenarios = g_strjoin (":", scenario, configs, NULL);
|
|
|
|
else
|
|
|
|
scenarios = g_strdup (configs);
|
|
|
|
|
|
|
|
g_setenv ("GST_VALIDATE_SCENARIO", scenarios, TRUE);
|
|
|
|
g_free (scenarios);
|
2013-07-24 23:09:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 19:08:30 +00:00
|
|
|
gst_init (&argc, &argv);
|
2013-08-14 22:14:18 +00:00
|
|
|
gst_validate_init ();
|
2013-07-09 19:08:30 +00:00
|
|
|
|
2014-02-11 23:28:18 +00:00
|
|
|
if (list_scenarios || output_file) {
|
|
|
|
if (gst_validate_list_scenarios (output_file))
|
|
|
|
return 1;
|
2013-10-25 09:33:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 14:50:11 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
g_print ("%s", g_option_context_get_help (ctx, FALSE, NULL));
|
2013-09-30 13:51:21 +00:00
|
|
|
g_option_context_free (ctx);
|
2013-09-04 14:50:11 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
2013-08-16 10:50:51 +00:00
|
|
|
|
2013-09-30 13:51:21 +00:00
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
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-09-04 15:05:48 +00:00
|
|
|
if (!pipeline) {
|
|
|
|
g_print ("Failed to create pipeline: %s\n",
|
|
|
|
err ? err->message : "unknown reason");
|
|
|
|
exit (1);
|
|
|
|
}
|
2013-09-04 15:09:50 +00:00
|
|
|
if (!GST_IS_PIPELINE (pipeline)) {
|
|
|
|
GstElement *new_pipeline = gst_pipeline_new ("");
|
|
|
|
gst_bin_add (GST_BIN (new_pipeline), pipeline);
|
|
|
|
pipeline = new_pipeline;
|
|
|
|
}
|
2013-08-22 13:08:13 +00:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
signal_watch_id =
|
|
|
|
g_unix_signal_add (SIGINT, (GSourceFunc) intr_handler, pipeline);
|
|
|
|
#endif
|
|
|
|
|
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);
|
2014-04-17 10:17:03 +00:00
|
|
|
gst_validate_reporter_set_handle_g_logs (GST_VALIDATE_REPORTER (monitor));
|
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);
|
2013-08-15 10:18:56 +00:00
|
|
|
gst_bus_add_signal_watch (bus);
|
|
|
|
g_signal_connect (bus, "message", (GCallback) bus_callback, mainloop);
|
2013-07-09 19:08:30 +00:00
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2013-07-11 16:41:25 +00:00
|
|
|
g_print ("Starting pipeline\n");
|
2014-01-24 10:29:50 +00:00
|
|
|
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;
|
2013-08-26 23:31:22 +00:00
|
|
|
}
|
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-09-05 08:34:42 +00:00
|
|
|
rep_err = gst_validate_runner_printf (runner);
|
2014-01-10 17:00:27 +00:00
|
|
|
if (ret == 0) {
|
2013-09-05 08:34:42 +00:00
|
|
|
ret = rep_err;
|
2014-01-24 10:29:50 +00:00
|
|
|
if (rep_err != 0)
|
|
|
|
g_print ("Returning %d as error where found", rep_err);
|
2014-01-10 17:00:27 +00:00
|
|
|
}
|
2013-07-09 19:08:30 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
g_main_loop_unref (mainloop);
|
2013-07-12 05:10:06 +00:00
|
|
|
g_object_unref (pipeline);
|
2014-01-13 08:41:16 +00:00
|
|
|
g_object_unref (runner);
|
|
|
|
g_object_unref (monitor);
|
2013-08-22 13:08:13 +00:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
g_source_remove (signal_watch_id);
|
|
|
|
#endif
|
2013-08-19 18:13:10 +00:00
|
|
|
|
|
|
|
return ret;
|
2013-07-09 19:08:30 +00:00
|
|
|
}
|