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>
|
|
|
|
#include <gst/qa/qa.h>
|
|
|
|
|
2013-07-11 16:41:25 +00:00
|
|
|
static gboolean seek_tests = FALSE;
|
|
|
|
static gboolean seek_done = FALSE;
|
|
|
|
|
|
|
|
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;
|
2013-07-11 16:41:25 +00:00
|
|
|
case GST_MESSAGE_STATE_CHANGED:
|
|
|
|
{
|
|
|
|
GstState new_state;
|
|
|
|
if (GST_MESSAGE_SRC (message) == (GstObject *) pipeline) {
|
|
|
|
gst_message_parse_state_changed (message, NULL, &new_state, NULL);
|
|
|
|
if (new_state == GST_STATE_PLAYING) {
|
|
|
|
/* pipeline has started, issue seeking */
|
|
|
|
/* TODO define where to seek to with arguments? */
|
|
|
|
if (seek_tests && !seek_done) {
|
|
|
|
g_print ("Performing seek\n");
|
|
|
|
seek_done = TRUE;
|
|
|
|
gst_element_seek_simple (pipeline, GST_FORMAT_TIME,
|
|
|
|
GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-07-09 19:08:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GOptionEntry options[] = {
|
2013-07-11 16:41:25 +00:00
|
|
|
{"seek-test", '\0', 0, G_OPTION_ARG_NONE, &seek_tests,
|
|
|
|
"Perform the seeking use case", NULL},
|
2013-07-09 19:08:30 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GOptionContext *ctx;
|
|
|
|
gchar **argvn;
|
|
|
|
GstQaRunner *runner;
|
|
|
|
GstBus *bus;
|
|
|
|
|
|
|
|
ctx = g_option_context_new ("- runs QA tests for a pipeline.");
|
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
runner = gst_qa_runner_new (pipeline);
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
if (!gst_qa_runner_setup (runner)) {
|
|
|
|
g_printerr ("Failed to setup QA Runner\n");
|
|
|
|
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;
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
|
2013-07-12 05:10:06 +00:00
|
|
|
g_print ("Pipeline finished, printing issues found: \n");
|
2013-07-17 00:15:09 +00:00
|
|
|
gst_qa_runner_print_reports (runner);
|
2013-07-09 19:08:30 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
g_main_loop_unref (mainloop);
|
|
|
|
g_object_unref (runner);
|
2013-07-12 05:10:06 +00:00
|
|
|
g_object_unref (pipeline);
|
2013-07-09 19:08:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|