mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 08:17:01 +00:00
examples: make camerabin test application handle errors when starting up
Instead of hanging forever in a _get_state() in case an error occurs when starting up camerabin, bail out and print an error message. Also remove unnecessary _get_state() when shutting down the pipeline.
This commit is contained in:
parent
7cb7c06b7c
commit
31ab47e03b
1 changed files with 26 additions and 19 deletions
|
@ -326,6 +326,21 @@ my_bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_error_message (GstMessage * msg)
|
||||||
|
{
|
||||||
|
GError *err = NULL;
|
||||||
|
gchar *dbg = NULL;
|
||||||
|
|
||||||
|
gst_message_parse_error (msg, &err, &dbg);
|
||||||
|
|
||||||
|
g_printerr ("Camerabin won't start up!\nError: %s\nDebug Info: %s\n",
|
||||||
|
err->message, (dbg) ? dbg : "None");
|
||||||
|
|
||||||
|
g_error_free (err);
|
||||||
|
g_free (dbg);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -341,14 +356,7 @@ my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_MESSAGE_ERROR:{
|
case GST_MESSAGE_ERROR:{
|
||||||
GError *err;
|
print_error_message (message);
|
||||||
gchar *debug;
|
|
||||||
|
|
||||||
gst_message_parse_error (message, &err, &debug);
|
|
||||||
g_print ("Error: %s\n", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
g_free (debug);
|
|
||||||
|
|
||||||
me_gst_cleanup_element ();
|
me_gst_cleanup_element ();
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
break;
|
break;
|
||||||
|
@ -550,6 +558,7 @@ me_gst_setup_pipeline_create_vid_post_bin (const gchar * videopost)
|
||||||
static gboolean
|
static gboolean
|
||||||
me_gst_setup_pipeline (const gchar * imagepost, const gchar * videopost)
|
me_gst_setup_pipeline (const gchar * imagepost, const gchar * videopost)
|
||||||
{
|
{
|
||||||
|
GstMessage *msg;
|
||||||
GstBus *bus;
|
GstBus *bus;
|
||||||
GstCaps *preview_caps;
|
GstCaps *preview_caps;
|
||||||
|
|
||||||
|
@ -615,19 +624,18 @@ me_gst_setup_pipeline (const gchar * imagepost, const gchar * videopost)
|
||||||
|
|
||||||
init_view_finder_resolution_combobox ();
|
init_view_finder_resolution_combobox ();
|
||||||
|
|
||||||
if (GST_STATE_CHANGE_FAILURE ==
|
gst_element_set_state (gst_camera_bin, GST_STATE_PLAYING);
|
||||||
gst_element_set_state (gst_camera_bin, GST_STATE_PAUSED)) {
|
|
||||||
|
msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (gst_camera_bin),
|
||||||
|
3 * GST_SECOND, GST_MESSAGE_ERROR | GST_MESSAGE_ASYNC_DONE);
|
||||||
|
|
||||||
|
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
|
||||||
|
print_error_message (msg);
|
||||||
|
gst_message_unref (msg);
|
||||||
goto done;
|
goto done;
|
||||||
} else {
|
|
||||||
gst_element_get_state (gst_camera_bin, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GST_STATE_CHANGE_FAILURE ==
|
gst_message_unref (msg);
|
||||||
gst_element_set_state (gst_camera_bin, GST_STATE_PLAYING)) {
|
|
||||||
goto done;
|
|
||||||
} else {
|
|
||||||
gst_element_get_state (gst_camera_bin, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_GST_PHOTO_IFACE_H
|
#ifdef HAVE_GST_PHOTO_IFACE_H
|
||||||
/* Initialize menus to default settings */
|
/* Initialize menus to default settings */
|
||||||
|
@ -653,7 +661,6 @@ me_gst_cleanup_element ()
|
||||||
{
|
{
|
||||||
if (gst_camera_bin) {
|
if (gst_camera_bin) {
|
||||||
gst_element_set_state (gst_camera_bin, GST_STATE_NULL);
|
gst_element_set_state (gst_camera_bin, GST_STATE_NULL);
|
||||||
gst_element_get_state (gst_camera_bin, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
||||||
gst_object_unref (gst_camera_bin);
|
gst_object_unref (gst_camera_bin);
|
||||||
gst_camera_bin = NULL;
|
gst_camera_bin = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue