benchmark: handle errors from the pipeline

Catch errors and warnings on the bus. This fixes hanging pipelines in the case
of bugs elsewhere. Also print state-change messages to give more detail on the progress.
This commit is contained in:
Stefan Kost 2010-07-08 14:08:27 +03:00
parent ced3d517eb
commit dbe8e5d1ad

View file

@ -132,7 +132,7 @@ create_nodes (GstBin * bin, GstElement * sink, gint depth, gint children,
}
static void
event_loop (GstElement * bin)
event_loop (GstElement * bin, GstClockTime start)
{
GstBus *bus;
GstMessage *msg = NULL;
@ -141,18 +141,58 @@ event_loop (GstElement * bin)
bus = gst_element_get_bus (bin);
while (running) {
msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
msg = gst_bus_poll (bus,
GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_WARNING,
-1);
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_STATE_CHANGED:
if (GST_MESSAGE_SRC (msg) == (GstObject *) bin) {
GstState old_state, new_state;
GstClockTime end;
gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
end = gst_util_get_timestamp ();
g_print ("%" GST_TIME_FORMAT " state change on the bin: %s -> %s\n",
GST_TIME_ARGS (end - start),
gst_element_state_get_name (old_state),
gst_element_state_get_name (new_state));
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
running = FALSE;
}
}
break;
case GST_MESSAGE_WARNING:{
GError *err = NULL;
gchar *dbg = NULL;
gst_message_parse_warning (msg, &err, &dbg);
GST_WARNING_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
(dbg ? dbg : "no details"));
g_error_free (err);
g_free (dbg);
break;
}
case GST_MESSAGE_ERROR:{
GError *err = NULL;
gchar *dbg = NULL;
gst_message_parse_error (msg, &err, &dbg);
GST_ERROR_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
(dbg ? dbg : "no details"));
g_error_free (err);
g_free (dbg);
running = FALSE;
break;
}
default:
break;
}
gst_message_unref (msg);
}
gst_object_unref (bus);
}
@ -216,6 +256,7 @@ main (gint argc, gchar * argv[])
goto Error;
}
end = gst_util_get_timestamp ();
/* num-threads = num-sources = pow (children, depth) */
g_print ("%" GST_TIME_FORMAT " built pipeline with %d elements\n",
GST_TIME_ARGS (end - start), GST_BIN_NUMCHILDREN (bin));
@ -225,7 +266,7 @@ main (gint argc, gchar * argv[])
GST_DEBUG_BIN_TO_DOT_FILE (bin, GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE, "capsnego");
start = gst_util_get_timestamp ();
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
event_loop (GST_ELEMENT (bin));
event_loop (GST_ELEMENT (bin), start);
end = gst_util_get_timestamp ();
g_print ("%" GST_TIME_FORMAT " reached paused\n",
GST_TIME_ARGS (end - start));