validate: Handle ERROR on the bus when monitoring the pipeline

This way the user get a  clear information in the report about the issue

+ sensibly cleanup code
This commit is contained in:
Thibault Saunier 2014-04-29 20:00:21 +02:00
parent da42500df7
commit f165fb41d0
5 changed files with 46 additions and 22 deletions

View file

@ -29,6 +29,8 @@
#include "gst-validate-bin-monitor.h"
#include "gst-validate-monitor-factory.h"
#define PRINT_POSITION_TIMEOUT 250
/**
* SECTION:gst-validate-bin-monitor
* @short_description: Class that wraps a #GstBin for Validate checks
@ -119,15 +121,35 @@ print_position (GstValidateMonitor *monitor)
return TRUE;
}
static void
_bus_handler (GstBus * bus, GstMessage * message, GstValidateBinMonitor *monitor)
{
GError *err;
gchar *debug;
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR) {
gst_message_parse_error (message, &err, &debug);
GST_VALIDATE_REPORT (monitor, ERROR_ON_BUS,
"Got error: %s -- Debug message: %s", err->message, debug);
g_error_free (err);
g_free (debug);
} else if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING) {
gst_message_parse_warning (message, &err, &debug);
GST_VALIDATE_REPORT (monitor, WARNING_ON_BUS,
"Got warning: %s -- Debug message: %s", err->message, debug);
g_error_free (err);
g_free (debug);
}
}
static void
gst_validate_bin_monitor_create_scenarios (GstValidateBinMonitor * monitor)
{
/* scenarios currently only make sense for pipelines */
if (GST_IS_PIPELINE (GST_VALIDATE_MONITOR_GET_OBJECT (monitor))) {
const gchar *scenario_name;
GstElement *bin = GST_ELEMENT (GST_VALIDATE_MONITOR_GET_OBJECT (monitor));
monitor->print_pos_srcid =
g_timeout_add (500, (GSourceFunc) print_position, monitor);
/* scenarios currently only make sense for pipelines */
if (GST_IS_PIPELINE (bin)) {
const gchar *scenario_name;
if ((scenario_name = g_getenv ("GST_VALIDATE_SCENARIO"))) {
gchar **scenario_v = g_strsplit (scenario_name, "->", 2);
@ -172,6 +194,19 @@ gst_validate_bin_monitor_new (GstBin * bin, GstValidateRunner * runner,
gst_validate_bin_monitor_create_scenarios (monitor);
if (GST_IS_PIPELINE (bin)) {
GstBus *bus;
monitor->print_pos_srcid =
g_timeout_add (PRINT_POSITION_TIMEOUT, (GSourceFunc) print_position, monitor);
bus = gst_element_get_bus (GST_ELEMENT (bin));
gst_bus_enable_sync_message_emission(bus);
g_signal_connect (bus, "sync-message", (GCallback) _bus_handler, monitor);
gst_object_unref (bus);
}
return monitor;
}

View file

@ -213,6 +213,10 @@ gst_validate_report_load_issues (void)
REGISTER_VALIDATE_ISSUE (CRITICAL, MISSING_PLUGIN,
_("a gstreamer plugin is missing and prevented Validate from running"),
NULL);
REGISTER_VALIDATE_ISSUE (WARNING, WARNING_ON_BUS,
_("We got a WARNING message on the bus"), NULL);
REGISTER_VALIDATE_ISSUE (CRITICAL, ERROR_ON_BUS,
_("We got an ERROR message on the bus"), NULL);
REGISTER_VALIDATE_ISSUE (WARNING, QUERY_POSITION_SUPERIOR_DURATION,
_("Query position reported a value superior than what query duration "
"returned"), NULL);

View file

@ -108,6 +108,8 @@ typedef enum {
#define GST_VALIDATE_ISSUE_ID_ALLOCATION_FAILURE (((GstValidateIssueId) GST_VALIDATE_AREA_RUN_ERROR) << GST_VALIDATE_ISSUE_ID_SHIFT | 1)
#define GST_VALIDATE_ISSUE_ID_MISSING_PLUGIN (((GstValidateIssueId) GST_VALIDATE_AREA_RUN_ERROR) << GST_VALIDATE_ISSUE_ID_SHIFT | 2)
#define GST_VALIDATE_ISSUE_ID_WARNING_ON_BUS (((GstValidateIssueId) GST_VALIDATE_AREA_RUN_ERROR) << GST_VALIDATE_ISSUE_ID_SHIFT | 3)
#define GST_VALIDATE_ISSUE_ID_ERROR_ON_BUS (((GstValidateIssueId) GST_VALIDATE_AREA_RUN_ERROR) << GST_VALIDATE_ISSUE_ID_SHIFT | 4)
#define GST_VALIDATE_ISSUE_ID_QUERY_POSITION_SUPERIOR_DURATION (((GstValidateIssueId) GST_VALIDATE_AREA_QUERY) << GST_VALIDATE_ISSUE_ID_SHIFT | 1)
#define GST_VALIDATE_ISSUE_ID_QUERY_POSITION_OUT_OF_SEGMENT (((GstValidateIssueId) GST_VALIDATE_AREA_QUERY) << GST_VALIDATE_ISSUE_ID_SHIFT | 2)

View file

@ -450,16 +450,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data)
}
case GST_MESSAGE_ERROR:
{
GError *err;
gchar *debug;
ret = -1;
gst_message_parse_error (message, &err, &debug);
g_print ("Error: %s %s\n", GST_OBJECT_NAME (GST_MESSAGE_SRC (message)),
err->message);
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
GST_DEBUG_GRAPH_SHOW_ALL, "gst-validate-transcode.error");
g_error_free (err);
g_free (debug);
g_main_loop_quit (loop);
break;
}

View file

@ -66,13 +66,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data)
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:
{
GError *err;
gchar *debug;
ret = -1;
gst_message_parse_error (message, &err, &debug);
g_print ("Error: %s -- Setting returncode to -1\n", err->message);
g_error_free (err);
g_free (debug);
g_main_loop_quit (loop);
break;
}