From c05cb9504dca91b32449f36ee80ee1a4f4c4a9bd Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 12 Nov 2019 11:24:45 +0900 Subject: [PATCH] gst-launch: Disable printing current position by default when stdout is not a tty ... and add new option to force-enable printing position even if stdout is not a tty. --- tools/gst-launch-1.0.1 | 9 ++++++++- tools/gst-launch.c | 22 +++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/gst-launch-1.0.1 b/tools/gst-launch-1.0.1 index 48322a9f64..bd3b733810 100644 --- a/tools/gst-launch-1.0.1 +++ b/tools/gst-launch-1.0.1 @@ -56,7 +56,14 @@ Print memory allocation traces. The feature must be enabled at compile time to work. .TP 8 .B \-\-no\-position -Do not print current position of pipeline +Do not print current position of pipeline. +If this option is unspecified, the position will be printed when stdout is a TTY. +To enable printing position when stdout is not a TTY, +use "force-position" option. +.TP 8 +.B \-\-force\-position +Allow printing current position of pipeline even if stdout is not a TTY. +This option has no effect if the "no-position" option is specified. .TP 8 . diff --git a/tools/gst-launch.c b/tools/gst-launch.c index 5b286909cf..cee0d5336b 100644 --- a/tools/gst-launch.c +++ b/tools/gst-launch.c @@ -1041,6 +1041,7 @@ main (int argc, char *argv[]) #endif gchar *savefile = NULL; gboolean no_position = FALSE; + gboolean force_position = FALSE; #ifndef GST_DISABLE_OPTION_PARSING GOptionEntry options[] = { {"tags", 't', 0, G_OPTION_ARG_NONE, &tags, @@ -1067,7 +1068,16 @@ main (int argc, char *argv[]) #endif GST_TOOLS_GOPTION_VERSION, {"no-position", '\0', 0, G_OPTION_ARG_NONE, &no_position, - N_("Do not print current position of pipeline"), NULL}, + N_("Do not print current position of pipeline. " + "If this option is unspecified, the position will be printed " + "when stdout is a TTY. " + "To enable printing position when stdout is not a TTY, " + "use \"force-position\" option"), NULL}, + {"force-position", '\0', 0, G_OPTION_ARG_NONE, &force_position, + N_("Allow printing current position of pipeline even if " + "stdout is not a TTY. This option has no effect if " + "the \"no-position\" option is specified"), + NULL}, {NULL} }; GOptionContext *ctx; @@ -1224,10 +1234,12 @@ main (int argc, char *argv[]) if (!isatty (STDOUT_FILENO)) output_is_tty = FALSE; - position_source = g_timeout_source_new (100); - g_source_set_callback (position_source, query_pipeline_position, - GINT_TO_POINTER (output_is_tty), NULL); - g_source_attach (position_source, NULL); + if (output_is_tty || (!output_is_tty && force_position)) { + position_source = g_timeout_source_new (100); + g_source_set_callback (position_source, query_pipeline_position, + GINT_TO_POINTER (output_is_tty), NULL); + g_source_attach (position_source, NULL); + } } /* playing state will be set on state-changed message handler */