From b778d8a27ece2fb5065f71232313b9cf4e63debb Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 29 Dec 2011 13:30:13 -0300 Subject: [PATCH] examples: camerabin2: add some error handling for format changing Check that the format could be initialized and shows a modal dialog in case it couldn't. --- tests/examples/camerabin2/gst-camera2.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/examples/camerabin2/gst-camera2.c b/tests/examples/camerabin2/gst-camera2.c index e57709487b..13299eac57 100644 --- a/tests/examples/camerabin2/gst-camera2.c +++ b/tests/examples/camerabin2/gst-camera2.c @@ -44,6 +44,7 @@ static GstElement *camera; static GtkBuilder *builder; +static GtkWidget *ui_main_window; typedef struct { @@ -60,10 +61,10 @@ create_ogg_profile (void) gst_caps_new_simple ("application/ogg", NULL), NULL); gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) - gst_encoding_video_profile_new (gst_caps_new_simple ("video/theora", + gst_encoding_video_profile_new (gst_caps_new_simple ("video/x-theora", NULL), NULL, NULL, 1)); gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) - gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/vorbis", + gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/x-vorbis", NULL), NULL, NULL, 1)); return (GstEncodingProfile *) container; @@ -81,7 +82,7 @@ create_webm_profile (void) gst_encoding_video_profile_new (gst_caps_new_simple ("video/x-vp8", NULL), NULL, NULL, 1)); gst_encoding_container_profile_add_profile (container, (GstEncodingProfile *) - gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/vorbis", + gst_encoding_audio_profile_new (gst_caps_new_simple ("audio/x-vorbis", NULL), NULL, NULL, 1)); return (GstEncodingProfile *) container; @@ -171,8 +172,21 @@ on_formatComboBox_changed (GtkWidget * widget, gpointer data) g_return_if_fail (profile != NULL); gst_element_set_state (camera, GST_STATE_NULL); g_object_set (camera, "video-profile", profile, NULL); - gst_element_set_state (camera, GST_STATE_PLAYING); gst_encoding_profile_unref (profile); + + if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (camera, + GST_STATE_PLAYING)) { + GtkWidget *dialog = + gtk_message_dialog_new (GTK_WINDOW (ui_main_window), GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + "Could not initialize camerabin2 with the " + "selected format. Your system might not have the required plugins installed.\n" + "Please select another format."); + + gtk_dialog_run (GTK_DIALOG (dialog)); + + gtk_widget_destroy (dialog); + } } static GstBusSyncReply @@ -265,7 +279,6 @@ int main (int argc, char *argv[]) { int ret = 0; - GtkWidget *ui_main_window; GError *error = NULL; GstBus *bus;