tools/gst-launch.c: Catch errors during preroll (#320084).
authorTim-Philipp Müller <tim@centricular.net>
Sat, 4 Feb 2006 11:56:18 +0000 (11:56 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Sat, 4 Feb 2006 11:56:18 +0000 (11:56 +0000)
Original commit message from CVS:
* tools/gst-launch.c: (event_loop), (main):
Catch errors during preroll (#320084).

ChangeLog
tools/gst-launch.c

index e494312..5541493 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-02-04  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * tools/gst-launch.c: (event_loop), (main):
+         Catch errors during preroll (#320084).
+
 2006-02-03  Tim-Philipp Müller  <tim at centricular dot net>
 
        * plugins/elements/gsttypefindelement.c:
index 352ba11..2533b89 100644 (file)
@@ -352,7 +352,7 @@ play_signal_setup (void)
 #endif /* DISABLE_FAULT_HANDLER */
 
 static gboolean
-event_loop (GstElement * pipeline, gboolean blocking)
+event_loop (GstElement * pipeline, gboolean blocking, GstState target_state)
 {
   GstBus *bus;
   GstMessage *message = NULL;
@@ -454,6 +454,12 @@ event_loop (GstElement * pipeline, gboolean blocking)
         GstState old, new, pending;
 
         gst_message_parse_state_changed (message, &old, &new, &pending);
+        if (GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline) &&
+            target_state != GST_STATE_VOID_PENDING && new == target_state) {
+          gst_message_unref (message);
+          gst_object_unref (bus);
+          return FALSE;
+        }
         if (!(old == GST_STATE_PLAYING && new == GST_STATE_PAUSED &&
                 GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline))) {
           gst_message_unref (message);
@@ -630,21 +636,26 @@ main (int argc, char *argv[])
       case GST_STATE_CHANGE_FAILURE:
         fprintf (stderr, _("ERROR: Pipeline doesn't want to pause.\n"));
         res = -1;
-        event_loop (pipeline, FALSE);
+        event_loop (pipeline, FALSE, GST_STATE_VOID_PENDING);
         goto end;
       case GST_STATE_CHANGE_NO_PREROLL:
         fprintf (stderr, _("ERROR: Pipeline can't PREROLL ...\n"));
         break;
       case GST_STATE_CHANGE_ASYNC:
         fprintf (stderr, _("Pipeline is PREROLLING ...\n"));
-        gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
+        caught_error = event_loop (pipeline, TRUE, GST_STATE_PAUSED);
+        if (caught_error) {
+          fprintf (stderr, _("ERROR: pipeline doesn't want to preroll.\n"));
+          goto end;
+        }
+        state = GST_STATE_PAUSED;
         /* fallthrough */
       case GST_STATE_CHANGE_SUCCESS:
         fprintf (stderr, _("Pipeline is PREROLLED ...\n"));
         break;
     }
 
-    caught_error = event_loop (pipeline, FALSE);
+    caught_error = event_loop (pipeline, FALSE, GST_STATE_VOID_PENDING);
 
     if (caught_error) {
       fprintf (stderr, _("ERROR: pipeline doesn't want to preroll.\n"));
@@ -661,7 +672,7 @@ main (int argc, char *argv[])
       }
 
       g_get_current_time (&tfthen);
-      caught_error = event_loop (pipeline, TRUE);
+      caught_error = event_loop (pipeline, TRUE, GST_STATE_VOID_PENDING);
       g_get_current_time (&tfnow);
 
       diff = GST_TIMEVAL_TO_TIME (tfnow) - GST_TIMEVAL_TO_TIME (tfthen);