2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2004 Thomas Vander Stichele <thomas@apestaart.org>
6 * gst-launch.c: tool to launch GStreamer pipelines from the command line
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
28 /* FIXME: hack alert */
30 #define DISABLE_FAULT_HANDLER
39 #ifndef DISABLE_FAULT_HANDLER
42 #include <locale.h> /* for LC_ALL */
45 /* FIXME: This is just a temporary hack. We should have a better
46 * check for siginfo handling. */
51 extern volatile gboolean glib_on_error_halt;
53 #ifndef DISABLE_FAULT_HANDLER
54 static void fault_restore (void);
55 static void fault_spin (void);
56 static void sigint_restore (void);
57 static gboolean caught_intr = FALSE;
60 /* event_loop return codes */
61 typedef enum _EventLoopResult
68 static GstElement *pipeline;
69 static EventLoopResult caught_error = ELR_NO_ERROR;
70 static gboolean quiet = FALSE;
71 static gboolean tags = FALSE;
72 static gboolean messages = FALSE;
73 static gboolean is_live = FALSE;
74 static gboolean waiting_eos = FALSE;
76 /* convenience macro so we don't have to litter the code with if(!quiet) */
77 #define PRINT if(!quiet)g_print
79 #ifndef DISABLE_FAULT_HANDLER
82 fault_handler_sighandler (int signum)
86 /* printf is used instead of g_print(), since it's less likely to
90 fprintf (stderr, "Caught SIGSEGV\n");
94 printf ("Caught SIGQUIT\n");
97 fprintf (stderr, "signo: %d\n", signum);
104 #else /* USE_SIGINFO */
107 fault_handler_sigaction (int signum, siginfo_t * si, void *misc)
111 /* printf is used instead of g_print(), since it's less likely to
113 switch (si->si_signo) {
115 fprintf (stderr, "Caught SIGSEGV accessing address %p\n", si->si_addr);
119 printf ("Caught SIGQUIT\n");
122 fprintf (stderr, "signo: %d\n", si->si_signo);
123 fprintf (stderr, "errno: %d\n", si->si_errno);
124 fprintf (stderr, "code: %d\n", si->si_code);
130 #endif /* USE_SIGINFO */
137 glib_on_error_halt = FALSE;
138 g_on_error_stack_trace ("gst-launch");
142 /* FIXME how do we know if we were run by libtool? */
144 "Spinning. Please run 'gdb gst-launch %d' to continue debugging, "
145 "Ctrl-C to quit, or Ctrl-\\ to dump core.\n", (gint) getpid ());
153 struct sigaction action;
155 memset (&action, 0, sizeof (action));
156 action.sa_handler = SIG_DFL;
158 sigaction (SIGSEGV, &action, NULL);
159 sigaction (SIGQUIT, &action, NULL);
165 struct sigaction action;
167 memset (&action, 0, sizeof (action));
169 action.sa_sigaction = fault_handler_sigaction;
170 action.sa_flags = SA_SIGINFO;
172 action.sa_handler = fault_handler_sighandler;
175 sigaction (SIGSEGV, &action, NULL);
176 sigaction (SIGQUIT, &action, NULL);
178 #endif /* DISABLE_FAULT_HANDLER */
181 print_error_message (GstMessage * msg)
184 gchar *name, *debug = NULL;
186 name = gst_object_get_path_string (msg->src);
187 gst_message_parse_error (msg, &err, &debug);
189 g_printerr (_("ERROR: from element %s: %s\n"), name, err->message);
191 g_printerr (_("Additional debug info:\n%s\n"), debug);
199 print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
203 count = gst_tag_list_get_tag_size (list, tag);
205 for (i = 0; i < count; i++) {
208 if (gst_tag_get_type (tag) == G_TYPE_STRING) {
209 if (!gst_tag_list_get_string_index (list, tag, i, &str))
210 g_assert_not_reached ();
211 } else if (gst_tag_get_type (tag) == GST_TYPE_BUFFER) {
214 img = gst_value_get_buffer (gst_tag_list_get_value_index (list, tag, i));
218 caps_str = GST_BUFFER_CAPS (img) ?
219 gst_caps_to_string (GST_BUFFER_CAPS (img)) : g_strdup ("unknown");
220 str = g_strdup_printf ("buffer of %u bytes, type: %s",
221 GST_BUFFER_SIZE (img), caps_str);
224 str = g_strdup ("NULL buffer");
226 } else if (gst_tag_get_type (tag) == GST_TYPE_DATE_TIME) {
227 GstDateTime *dt = NULL;
229 gst_tag_list_get_date_time_index (list, tag, i, &dt);
230 if (gst_date_time_get_hour (dt) < 0) {
231 str = g_strdup_printf ("%02u-%02u-%04u", gst_date_time_get_day (dt),
232 gst_date_time_get_month (dt), gst_date_time_get_year (dt));
234 gdouble tz_offset = gst_date_time_get_time_zone_offset (dt);
237 if (tz_offset != 0.0) {
238 g_snprintf (tz_str, sizeof (tz_str), "(UTC %s%gh)",
239 (tz_offset > 0.0) ? "+" : "", tz_offset);
241 g_snprintf (tz_str, sizeof (tz_str), "(UTC)");
244 str = g_strdup_printf ("%04u-%02u-%02u %02u:%02u:%02u %s",
245 gst_date_time_get_year (dt), gst_date_time_get_month (dt),
246 gst_date_time_get_day (dt), gst_date_time_get_hour (dt),
247 gst_date_time_get_minute (dt), gst_date_time_get_second (dt),
250 gst_date_time_unref (dt);
253 g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
257 PRINT ("%16s: %s\n", gst_tag_get_nick (tag), str);
259 PRINT ("%16s: %s\n", "", str);
266 #ifndef DISABLE_FAULT_HANDLER
267 /* we only use sighandler here because the registers are not important */
269 sigint_handler_sighandler (int signum)
271 PRINT ("Caught interrupt -- ");
273 /* If we were waiting for an EOS, we still want to catch
274 * the next signal to shutdown properly (and the following one
275 * will quit the program). */
281 /* we set a flag that is checked by the mainloop, we cannot do much in the
282 * interrupt handler (no mutex or other blocking stuff) */
286 /* is called every 250 milliseconds (4 times a second), the interrupt handler
287 * will set a flag for us. We react to this by posting a message. */
289 check_intr (GstElement * pipeline)
295 PRINT ("handling interrupt.\n");
297 /* post an application specific message */
298 gst_element_post_message (GST_ELEMENT (pipeline),
299 gst_message_new_application (GST_OBJECT (pipeline),
300 gst_structure_new ("GstLaunchInterrupt",
301 "message", G_TYPE_STRING, "Pipeline interrupted", NULL)));
303 /* remove timeout handler */
311 struct sigaction action;
313 memset (&action, 0, sizeof (action));
314 action.sa_handler = sigint_handler_sighandler;
316 sigaction (SIGINT, &action, NULL);
320 sigint_restore (void)
322 struct sigaction action;
324 memset (&action, 0, sizeof (action));
325 action.sa_handler = SIG_DFL;
327 sigaction (SIGINT, &action, NULL);
330 /* FIXME 0.11: remove SIGUSR handling (also from man page) */
332 play_handler (int signum)
336 PRINT ("Caught SIGUSR1 - Play request.\n");
337 gst_element_set_state (pipeline, GST_STATE_PLAYING);
340 PRINT ("Caught SIGUSR2 - Stop request.\n");
341 gst_element_set_state (pipeline, GST_STATE_NULL);
347 play_signal_setup (void)
349 struct sigaction action;
351 memset (&action, 0, sizeof (action));
352 action.sa_handler = play_handler;
353 sigaction (SIGUSR1, &action, NULL);
354 sigaction (SIGUSR2, &action, NULL);
356 #endif /* DISABLE_FAULT_HANDLER */
358 /* returns ELR_ERROR if there was an error
359 * or ELR_INTERRUPT if we caught a keyboard interrupt
360 * or ELR_NO_ERROR otherwise. */
361 static EventLoopResult
362 event_loop (GstElement * pipeline, gboolean blocking, GstState target_state)
364 #ifndef DISABLE_FAULT_HANDLER
368 GstMessage *message = NULL;
369 EventLoopResult res = ELR_NO_ERROR;
370 gboolean buffering = FALSE;
372 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
374 #ifndef DISABLE_FAULT_HANDLER
375 timeout_id = g_timeout_add (250, (GSourceFunc) check_intr, pipeline);
379 message = gst_bus_poll (bus, GST_MESSAGE_ANY, blocking ? -1 : 0);
381 /* if the poll timed out, only when !blocking */
385 /* check if we need to dump messages to the console */
388 const GstStructure *s;
391 seqnum = gst_message_get_seqnum (message);
393 s = gst_message_get_structure (message);
395 src_obj = GST_MESSAGE_SRC (message);
397 if (GST_IS_ELEMENT (src_obj)) {
398 PRINT (_("Got message #%u from element \"%s\" (%s): "),
399 (guint) seqnum, GST_ELEMENT_NAME (src_obj),
400 GST_MESSAGE_TYPE_NAME (message));
401 } else if (GST_IS_PAD (src_obj)) {
402 PRINT (_("Got message #%u from pad \"%s:%s\" (%s): "),
403 (guint) seqnum, GST_DEBUG_PAD_NAME (src_obj),
404 GST_MESSAGE_TYPE_NAME (message));
405 } else if (GST_IS_OBJECT (src_obj)) {
406 PRINT (_("Got message #%u from object \"%s\" (%s): "),
407 (guint) seqnum, GST_OBJECT_NAME (src_obj),
408 GST_MESSAGE_TYPE_NAME (message));
410 PRINT (_("Got message #%u (%s): "), (guint) seqnum,
411 GST_MESSAGE_TYPE_NAME (message));
417 sstr = gst_structure_to_string (s);
418 PRINT ("%s\n", sstr);
421 PRINT ("no message details\n");
425 switch (GST_MESSAGE_TYPE (message)) {
426 case GST_MESSAGE_NEW_CLOCK:
430 gst_message_parse_new_clock (message, &clock);
432 PRINT ("New clock: %s\n", (clock ? GST_OBJECT_NAME (clock) : "NULL"));
435 case GST_MESSAGE_CLOCK_LOST:
436 PRINT ("Clock lost, selecting a new one\n");
437 gst_element_set_state (pipeline, GST_STATE_PAUSED);
438 gst_element_set_state (pipeline, GST_STATE_PLAYING);
440 case GST_MESSAGE_EOS:{
442 PRINT (_("Got EOS from element \"%s\".\n"),
443 GST_MESSAGE_SRC_NAME (message));
446 case GST_MESSAGE_TAG:
450 if (GST_IS_ELEMENT (GST_MESSAGE_SRC (message))) {
451 PRINT (_("FOUND TAG : found by element \"%s\".\n"),
452 GST_MESSAGE_SRC_NAME (message));
453 } else if (GST_IS_PAD (GST_MESSAGE_SRC (message))) {
454 PRINT (_("FOUND TAG : found by pad \"%s:%s\".\n"),
455 GST_DEBUG_PAD_NAME (GST_MESSAGE_SRC (message)));
456 } else if (GST_IS_OBJECT (GST_MESSAGE_SRC (message))) {
457 PRINT (_("FOUND TAG : found by object \"%s\".\n"),
458 GST_MESSAGE_SRC_NAME (message));
460 PRINT (_("FOUND TAG\n"));
463 gst_message_parse_tag (message, &tags);
464 gst_tag_list_foreach (tags, print_tag, NULL);
465 gst_tag_list_free (tags);
468 case GST_MESSAGE_INFO:{
471 gchar *name = gst_object_get_path_string (GST_MESSAGE_SRC (message));
473 gst_message_parse_info (message, &gerror, &debug);
475 PRINT (_("INFO:\n%s\n"), debug);
477 g_error_free (gerror);
482 case GST_MESSAGE_WARNING:{
485 gchar *name = gst_object_get_path_string (GST_MESSAGE_SRC (message));
487 /* dump graph on warning */
488 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
489 GST_DEBUG_GRAPH_SHOW_ALL, "gst-launch.warning");
491 gst_message_parse_warning (message, &gerror, &debug);
492 PRINT (_("WARNING: from element %s: %s\n"), name, gerror->message);
494 PRINT (_("Additional debug info:\n%s\n"), debug);
496 g_error_free (gerror);
501 case GST_MESSAGE_ERROR:{
502 /* dump graph on error */
503 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
504 GST_DEBUG_GRAPH_SHOW_ALL, "gst-launch.error");
506 print_error_message (message);
508 /* we have an error */
512 case GST_MESSAGE_STATE_CHANGED:{
513 GstState old, new, pending;
515 /* we only care about pipeline state change messages */
516 if (GST_MESSAGE_SRC (message) != GST_OBJECT_CAST (pipeline))
519 /* ignore when we are buffering since then we mess with the states
522 PRINT (_("Prerolled, waiting for buffering to finish...\n"));
526 gst_message_parse_state_changed (message, &old, &new, &pending);
528 /* if we reached the final target state, exit */
529 if (target_state == GST_STATE_PAUSED && new == target_state)
532 /* else not an interesting message */
535 case GST_MESSAGE_BUFFERING:{
538 gst_message_parse_buffering (message, &percent);
539 PRINT ("%s %d%% \r", _("buffering..."), percent);
541 /* no state management needed for live pipelines */
545 if (percent == 100) {
546 /* a 100% message means buffering is done */
548 /* if the desired state is playing, go back */
549 if (target_state == GST_STATE_PLAYING) {
550 PRINT (_("Done buffering, setting pipeline to PLAYING ...\n"));
551 gst_element_set_state (pipeline, GST_STATE_PLAYING);
556 if (buffering == FALSE && target_state == GST_STATE_PLAYING) {
557 /* we were not buffering but PLAYING, PAUSE the pipeline. */
558 PRINT (_("Buffering, setting pipeline to PAUSED ...\n"));
559 gst_element_set_state (pipeline, GST_STATE_PAUSED);
565 case GST_MESSAGE_LATENCY:
567 PRINT (_("Redistribute latency...\n"));
568 gst_bin_recalculate_latency (GST_BIN (pipeline));
571 case GST_MESSAGE_REQUEST_STATE:
574 gchar *name = gst_object_get_path_string (GST_MESSAGE_SRC (message));
576 gst_message_parse_request_state (message, &state);
578 PRINT (_("Setting state to %s as requested by %s...\n"),
579 gst_element_state_get_name (state), name);
581 gst_element_set_state (pipeline, state);
586 case GST_MESSAGE_APPLICATION:{
587 const GstStructure *s;
589 s = gst_message_get_structure (message);
591 if (gst_structure_has_name (s, "GstLaunchInterrupt")) {
592 /* this application message is posted when we caught an interrupt and
593 * we need to stop the pipeline. */
594 PRINT (_("Interrupt: Stopping pipeline ...\n"));
600 /* just be quiet by default */
604 gst_message_unref (message);
606 g_assert_not_reached ();
611 gst_message_unref (message);
612 gst_object_unref (bus);
613 #ifndef DISABLE_FAULT_HANDLER
614 g_source_remove (timeout_id);
620 static GstBusSyncReply
621 bus_sync_handler (GstBus * bus, GstMessage * message, gpointer data)
623 GstElement *pipeline = (GstElement *) data;
625 switch (GST_MESSAGE_TYPE (message)) {
626 case GST_MESSAGE_STATE_CHANGED:
627 /* we only care about pipeline state change messages */
628 if (GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
629 GstState old, new, pending;
630 gchar *state_transition_name;
632 gst_message_parse_state_changed (message, &old, &new, &pending);
634 state_transition_name = g_strdup_printf ("%s_%s",
635 gst_element_state_get_name (old), gst_element_state_get_name (new));
637 /* dump graph for (some) pipeline state changes */
639 gchar *dump_name = g_strconcat ("gst-launch.", state_transition_name,
641 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
642 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
646 /* place a marker into e.g. strace logs */
648 gchar *access_name = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S,
649 "gst-launch", G_DIR_SEPARATOR_S, state_transition_name, NULL);
650 g_file_test (access_name, G_FILE_TEST_EXISTS);
651 g_free (access_name);
654 g_free (state_transition_name);
663 main (int argc, char *argv[])
666 gboolean verbose = FALSE;
667 gboolean no_fault = FALSE;
668 gboolean no_sigusr_handler = FALSE;
669 gboolean trace = FALSE;
670 gboolean eos_on_shutdown = FALSE;
671 gchar *savefile = NULL;
672 gchar *exclude_args = NULL;
673 #ifndef GST_DISABLE_OPTION_PARSING
674 GOptionEntry options[] = {
675 {"tags", 't', 0, G_OPTION_ARG_NONE, &tags,
676 N_("Output tags (also known as metadata)"), NULL},
677 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
678 N_("Output status information and property notifications"), NULL},
679 {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
680 N_("Do not print any progress information"), NULL},
681 {"messages", 'm', 0, G_OPTION_ARG_NONE, &messages,
682 N_("Output messages"), NULL},
683 {"exclude", 'X', 0, G_OPTION_ARG_NONE, &exclude_args,
684 N_("Do not output status information of TYPE"), N_("TYPE1,TYPE2,...")},
685 {"no-fault", 'f', 0, G_OPTION_ARG_NONE, &no_fault,
686 N_("Do not install a fault handler"), NULL},
687 {"no-sigusr-handler", '\0', 0, G_OPTION_ARG_NONE, &no_sigusr_handler,
688 N_("Do not install signal handlers for SIGUSR1 and SIGUSR2"), NULL},
689 {"trace", 'T', 0, G_OPTION_ARG_NONE, &trace,
690 N_("Print alloc trace (if enabled at compile time)"), NULL},
691 {"eos-on-shutdown", 'e', 0, G_OPTION_ARG_NONE, &eos_on_shutdown,
692 N_("Force EOS on sources before shutting the pipeline down"), NULL},
693 GST_TOOLS_GOPTION_VERSION,
700 GError *error = NULL;
703 free (malloc (8)); /* -lefence */
706 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
707 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
708 textdomain (GETTEXT_PACKAGE);
711 g_thread_init (NULL);
713 gst_tools_set_prgname ("gst-launch");
715 #ifndef GST_DISABLE_OPTION_PARSING
716 ctx = g_option_context_new ("PIPELINE-DESCRIPTION");
717 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
718 g_option_context_add_group (ctx, gst_init_get_option_group ());
719 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
721 g_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
723 g_printerr ("Error initializing: Unknown error!\n");
726 g_option_context_free (ctx);
728 gst_init (&argc, &argv);
731 gst_tools_print_version ("gst-launch");
733 #ifndef DISABLE_FAULT_HANDLER
739 if (!no_sigusr_handler)
740 play_signal_setup ();
744 if (!gst_alloc_trace_available ()) {
745 g_warning ("Trace not available (recompile with trace enabled).");
747 gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE |
748 GST_ALLOC_TRACE_MEM_LIVE);
749 gst_alloc_trace_print_live ();
752 /* make a null-terminated version of argv */
753 argvn = g_new0 (char *, argc);
754 memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
757 (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
763 g_printerr (_("ERROR: pipeline could not be constructed: %s.\n"),
764 GST_STR_NULL (error->message));
765 g_error_free (error);
767 g_printerr (_("ERROR: pipeline could not be constructed.\n"));
771 g_printerr (_("WARNING: erroneous pipeline: %s\n"),
772 GST_STR_NULL (error->message));
773 g_error_free (error);
778 gchar **exclude_list =
779 exclude_args ? g_strsplit (exclude_args, ",", 0) : NULL;
780 g_signal_connect (pipeline, "deep-notify",
781 G_CALLBACK (gst_object_default_deep_notify), exclude_list);
785 GstState state, pending;
786 GstStateChangeReturn ret;
789 /* If the top-level object is not a pipeline, place it in a pipeline. */
790 if (!GST_IS_PIPELINE (pipeline)) {
791 GstElement *real_pipeline = gst_element_factory_make ("pipeline", NULL);
793 if (real_pipeline == NULL) {
794 g_printerr (_("ERROR: the 'pipeline' element wasn't found.\n"));
797 gst_bin_add (GST_BIN (real_pipeline), pipeline);
798 pipeline = real_pipeline;
801 bus = gst_element_get_bus (pipeline);
802 gst_bus_set_sync_handler (bus, bus_sync_handler, (gpointer) pipeline);
803 gst_object_unref (bus);
805 PRINT (_("Setting pipeline to PAUSED ...\n"));
806 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
809 case GST_STATE_CHANGE_FAILURE:
810 g_printerr (_("ERROR: Pipeline doesn't want to pause.\n"));
812 event_loop (pipeline, FALSE, GST_STATE_VOID_PENDING);
814 case GST_STATE_CHANGE_NO_PREROLL:
815 PRINT (_("Pipeline is live and does not need PREROLL ...\n"));
818 case GST_STATE_CHANGE_ASYNC:
819 PRINT (_("Pipeline is PREROLLING ...\n"));
820 caught_error = event_loop (pipeline, TRUE, GST_STATE_PAUSED);
822 g_printerr (_("ERROR: pipeline doesn't want to preroll.\n"));
825 state = GST_STATE_PAUSED;
827 case GST_STATE_CHANGE_SUCCESS:
828 PRINT (_("Pipeline is PREROLLED ...\n"));
832 caught_error = event_loop (pipeline, FALSE, GST_STATE_PLAYING);
835 g_printerr (_("ERROR: pipeline doesn't want to preroll.\n"));
837 GstClockTime tfthen, tfnow;
838 GstClockTimeDiff diff;
840 PRINT (_("Setting pipeline to PLAYING ...\n"));
842 if (gst_element_set_state (pipeline,
843 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
847 g_printerr (_("ERROR: pipeline doesn't want to play.\n"));
848 bus = gst_element_get_bus (pipeline);
849 if ((err_msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0))) {
850 print_error_message (err_msg);
851 gst_message_unref (err_msg);
853 gst_object_unref (bus);
858 tfthen = gst_util_get_timestamp ();
859 caught_error = event_loop (pipeline, TRUE, GST_STATE_PLAYING);
860 if (eos_on_shutdown && caught_error == ELR_INTERRUPT) {
861 PRINT (_("EOS on shutdown enabled -- Forcing EOS on the pipeline\n"));
863 gst_element_send_event (pipeline, gst_event_new_eos ());
864 PRINT (_("Waiting for EOS...\n"));
865 caught_error = event_loop (pipeline, TRUE, GST_STATE_PLAYING);
867 if (caught_error == ELR_NO_ERROR) {
869 PRINT (_("EOS received - stopping pipeline...\n"));
870 } else if (caught_error == ELR_ERROR) {
871 PRINT (_("An error happened while waiting for EOS\n"));
874 tfnow = gst_util_get_timestamp ();
876 diff = GST_CLOCK_DIFF (tfthen, tfnow);
878 PRINT (_("Execution ended after %" G_GUINT64_FORMAT " ns.\n"), diff);
881 PRINT (_("Setting pipeline to PAUSED ...\n"));
882 gst_element_set_state (pipeline, GST_STATE_PAUSED);
883 if (caught_error == ELR_NO_ERROR)
884 gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
886 /* iterate mainloop to process pending stuff */
887 while (g_main_context_iteration (NULL, FALSE));
889 PRINT (_("Setting pipeline to READY ...\n"));
890 gst_element_set_state (pipeline, GST_STATE_READY);
891 gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
894 PRINT (_("Setting pipeline to NULL ...\n"));
895 gst_element_set_state (pipeline, GST_STATE_NULL);
896 gst_element_get_state (pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
899 PRINT (_("Freeing pipeline ...\n"));
900 gst_object_unref (pipeline);
904 gst_alloc_trace_print_live ();