1 /* GStreamer command line playback testing utility
3 * Copyright (C) 2013-2014 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2013 Collabora Ltd.
5 * Copyright (C) 2015 Centricular Ltd
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
30 #include <glib/gi18n.h>
31 #include <gst/audio/audio.h>
32 #include <gst/video/video.h>
33 #include <gst/pbutils/pbutils.h>
34 #include <gst/tag/tag.h>
35 #include <gst/math-compat.h>
40 #include <glib/gprintf.h>
43 #define WIN32_LEAN_AND_MEAN
48 #include "gst-play-kb.h"
50 #define VOLUME_STEPS 20
52 static gboolean wait_on_eos = FALSE;
54 GST_DEBUG_CATEGORY (play_debug);
55 #define GST_CAT_DEFAULT play_debug
59 GST_PLAY_TRICK_MODE_NONE = 0,
60 GST_PLAY_TRICK_MODE_DEFAULT,
61 GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO,
62 GST_PLAY_TRICK_MODE_KEY_UNITS,
63 GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO,
64 GST_PLAY_TRICK_MODE_LAST,
66 /* The instant-rate setting is a flag,
67 * applied on top of the trick-mode enum value.
68 * It needs to have a 2^n value bigger than
69 * any of the enum values so setting it
70 * won't affect the trickmode value */
71 GST_PLAY_TRICK_MODE_INSTANT_RATE = (1 << 3)
76 GST_PLAY_TRACK_TYPE_INVALID = 0,
77 GST_PLAY_TRACK_TYPE_AUDIO,
78 GST_PLAY_TRACK_TYPE_VIDEO,
79 GST_PLAY_TRACK_TYPE_SUBTITLE
90 /* playbin3 variables */
92 GstStreamCollection *collection;
96 GMutex selection_lock;
102 /* missing plugin messages */
107 gboolean initial_file;
109 GstState desired_state; /* as per user interaction, PAUSED or PLAYING */
111 gulong deep_notify_id;
115 gboolean instant_uri;
117 GstPlayTrickMode trick_mode;
119 gdouble start_position;
121 /* keyboard state tracking */
122 gboolean shift_pressed;
125 static gboolean quiet = FALSE;
126 static gboolean instant_rate_changes = FALSE;
128 static gboolean play_bus_msg (GstBus * bus, GstMessage * msg, gpointer data);
129 static gboolean play_next (GstPlay * play);
130 static gboolean play_prev (GstPlay * play);
131 static gboolean play_timeout (gpointer user_data);
132 static void play_about_to_finish (GstElement * playbin, gpointer user_data);
133 static void play_reset (GstPlay * play);
134 static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
135 static gboolean play_do_seek (GstPlay * play, gint64 pos, gdouble rate,
136 GstPlayTrickMode mode);
139 static void gst_play_printf (const gchar * format, ...) G_GNUC_PRINTF (1, 2);
142 static void keyboard_cb (const gchar * key_input, gpointer user_data);
143 static void relative_seek (GstPlay * play, gdouble percent);
146 gst_play_printf (const gchar * format, ...)
155 va_start (args, format);
157 len = g_vasprintf (&str, format, args);
161 if (len > 0 && str != NULL)
162 gst_print ("%s", str);
167 #define gst_print gst_play_printf
170 play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
171 gboolean gapless, gboolean instant_uri, gdouble initial_volume,
172 gboolean verbose, const gchar * flags_string, gboolean use_playbin3,
173 gdouble start_position)
175 GstElement *sink, *playbin;
180 playbin = gst_element_factory_make ("playbin3", "playbin");
182 playbin = gst_element_factory_make ("playbin", "playbin");
188 play = g_new0 (GstPlay, 1);
191 play->num_uris = g_strv_length (uris);
194 play->playbin = playbin;
197 play->is_playbin3 = TRUE;
199 const gchar *env = g_getenv ("USE_PLAYBIN3");
200 if (env && g_str_has_prefix (env, "1"))
201 play->is_playbin3 = TRUE;
204 g_mutex_init (&play->selection_lock);
206 if (audio_sink != NULL) {
207 if (strchr (audio_sink, ' ') != NULL)
208 sink = gst_parse_bin_from_description (audio_sink, TRUE, NULL);
210 sink = gst_element_factory_make (audio_sink, NULL);
213 g_object_set (play->playbin, "audio-sink", sink, NULL);
215 g_warning ("Couldn't create specified audio sink '%s'", audio_sink);
217 if (video_sink != NULL) {
218 if (strchr (video_sink, ' ') != NULL)
219 sink = gst_parse_bin_from_description (video_sink, TRUE, NULL);
221 sink = gst_element_factory_make (video_sink, NULL);
224 g_object_set (play->playbin, "video-sink", sink, NULL);
226 g_warning ("Couldn't create specified video sink '%s'", video_sink);
229 if (flags_string != NULL) {
234 g_object_class_find_property (G_OBJECT_GET_CLASS (playbin), "flags");
235 g_value_init (&val, pspec->value_type);
236 if (gst_value_deserialize (&val, flags_string))
237 g_object_set_property (G_OBJECT (play->playbin), "flags", &val);
239 gst_printerr ("Couldn't convert '%s' to playbin flags!\n", flags_string);
240 g_value_unset (&val);
244 play->deep_notify_id =
245 gst_element_add_property_deep_notify_watch (play->playbin, NULL, TRUE);
248 play->loop = g_main_loop_new (NULL, FALSE);
250 play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin),
253 /* FIXME: make configurable incl. 0 for disable */
254 play->timeout = g_timeout_add (100, play_timeout, play);
256 play->missing = NULL;
257 play->buffering = FALSE;
258 play->is_live = FALSE;
260 play->desired_state = GST_STATE_PLAYING;
262 play->gapless = gapless;
264 g_signal_connect (play->playbin, "about-to-finish",
265 G_CALLBACK (play_about_to_finish), play);
268 play->initial_file = TRUE;
270 play->instant_uri = instant_uri;
271 g_object_set (G_OBJECT (play->playbin), "instant-uri", instant_uri, NULL);
273 if (initial_volume != -1)
274 play_set_relative_volume (play, initial_volume - 1.0);
277 play->trick_mode = GST_PLAY_TRICK_MODE_NONE;
278 play->start_position = start_position;
283 play_free (GstPlay * play)
285 /* No need to see all those pad caps going to NULL etc., it's just noise */
286 if (play->deep_notify_id != 0)
287 g_signal_handler_disconnect (play->playbin, play->deep_notify_id);
291 gst_element_set_state (play->playbin, GST_STATE_NULL);
292 gst_object_unref (play->playbin);
294 g_source_remove (play->bus_watch);
295 g_source_remove (play->timeout);
296 g_main_loop_unref (play->loop);
298 g_strfreev (play->uris);
300 if (play->collection)
301 gst_object_unref (play->collection);
302 g_free (play->cur_audio_sid);
303 g_free (play->cur_video_sid);
304 g_free (play->cur_text_sid);
306 g_mutex_clear (&play->selection_lock);
311 /* reset for new file/stream */
313 play_reset (GstPlay * play)
315 g_list_foreach (play->missing, (GFunc) gst_message_unref, NULL);
316 play->missing = NULL;
318 play->buffering = FALSE;
319 play->is_live = FALSE;
323 play_set_relative_volume (GstPlay * play, gdouble volume_step)
327 volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (play->playbin),
328 GST_STREAM_VOLUME_FORMAT_CUBIC);
330 volume = round ((volume + volume_step) * VOLUME_STEPS) / VOLUME_STEPS;
331 volume = CLAMP (volume, 0.0, 10.0);
333 gst_stream_volume_set_volume (GST_STREAM_VOLUME (play->playbin),
334 GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
336 gst_print (_("Volume: %.0f%%"), volume * 100);
341 play_toggle_audio_mute (GstPlay * play)
345 mute = gst_stream_volume_get_mute (GST_STREAM_VOLUME (play->playbin));
348 gst_stream_volume_set_mute (GST_STREAM_VOLUME (play->playbin), mute);
351 gst_print (_("Mute: on"));
353 gst_print (_("Mute: off"));
357 /* returns TRUE if something was installed and we should restart playback */
359 play_install_missing_plugins (GstPlay * play)
361 /* FIXME: implement: try to install any missing plugins we haven't
362 * tried to install before */
367 play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
369 GstPlay *play = user_data;
371 switch (GST_MESSAGE_TYPE (msg)) {
372 case GST_MESSAGE_ASYNC_DONE:
374 /* dump graph on preroll */
375 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
376 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.async-done");
378 gst_print ("Prerolled.\r");
379 if (play->missing != NULL && play_install_missing_plugins (play)) {
380 gst_print ("New plugins installed, trying again...\n");
384 if (play->start_position > 0.0) {
385 play_do_seek (play, play->start_position * GST_SECOND,
386 play->rate, play->trick_mode);
387 play->start_position = 0;
390 case GST_MESSAGE_BUFFERING:{
393 if (!play->buffering)
396 gst_message_parse_buffering (msg, &percent);
397 gst_print ("%s %d%% \r", _("Buffering..."), percent);
399 if (percent == 100) {
400 /* a 100% message means buffering is done */
401 if (play->buffering) {
402 play->buffering = FALSE;
403 /* no state management needed for live pipelines */
405 gst_element_set_state (play->playbin, play->desired_state);
409 if (!play->buffering) {
411 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
412 play->buffering = TRUE;
417 case GST_MESSAGE_CLOCK_LOST:{
418 gst_print (_("Clock lost, selecting a new one\n"));
419 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
420 gst_element_set_state (play->playbin, GST_STATE_PLAYING);
423 case GST_MESSAGE_LATENCY:
424 gst_print ("Redistribute latency...\n");
425 gst_bin_recalculate_latency (GST_BIN (play->playbin));
427 case GST_MESSAGE_REQUEST_STATE:{
431 name = gst_object_get_path_string (GST_MESSAGE_SRC (msg));
433 gst_message_parse_request_state (msg, &state);
435 gst_print ("Setting state to %s as requested by %s...\n",
436 gst_element_state_get_name (state), name);
438 gst_element_set_state (play->playbin, state);
442 case GST_MESSAGE_EOS:
443 /* print final position at end */
446 /* and switch to next item in list */
447 if (!wait_on_eos && !play_next (play)) {
448 gst_print ("%s\n", _("Reached end of play list."));
449 g_main_loop_quit (play->loop);
452 case GST_MESSAGE_WARNING:{
456 /* dump graph on warning */
457 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
458 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.warning");
460 gst_message_parse_warning (msg, &err, &dbg);
461 gst_printerr ("WARNING %s\n", err->message);
463 gst_printerr ("WARNING debug information: %s\n", dbg);
464 g_clear_error (&err);
468 case GST_MESSAGE_ERROR:{
472 /* dump graph on error */
473 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
474 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.error");
476 gst_message_parse_error (msg, &err, &dbg);
477 gst_printerr ("ERROR %s for %s\n", err->message,
478 play->uris[play->cur_idx]);
480 gst_printerr ("ERROR debug information: %s\n", dbg);
481 g_clear_error (&err);
484 /* flush any other error messages from the bus and clean up */
485 gst_element_set_state (play->playbin, GST_STATE_NULL);
487 if (play->missing != NULL && play_install_missing_plugins (play)) {
488 gst_print ("New plugins installed, trying again...\n");
493 /* try next item in list then */
494 if (!play_next (play)) {
495 gst_print ("%s\n", _("Reached end of play list."));
496 g_main_loop_quit (play->loop);
500 case GST_MESSAGE_ELEMENT:
502 GstNavigationMessageType mtype = gst_navigation_message_get_type (msg);
503 if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
506 if (gst_navigation_message_parse_event (msg, &ev)) {
507 GstNavigationEventType e_type = gst_navigation_event_get_type (ev);
509 case GST_NAVIGATION_EVENT_KEY_PRESS:
512 const gchar *key_input;
513 gchar key_adjusted[2];
515 if (gst_navigation_event_parse_key_event (ev, &key)) {
516 GST_INFO ("Key press: %s", key);
518 if (strcmp (key, "Left") == 0)
519 key = GST_PLAY_KB_ARROW_LEFT;
520 else if (strcmp (key, "Right") == 0)
521 key = GST_PLAY_KB_ARROW_RIGHT;
522 else if (strcmp (key, "Up") == 0)
523 key = GST_PLAY_KB_ARROW_UP;
524 else if (strcmp (key, "Down") == 0)
525 key = GST_PLAY_KB_ARROW_DOWN;
526 else if (strncmp (key, "Shift", 5) == 0) {
527 play->shift_pressed = TRUE;
529 } else if (strcmp (key, "space") == 0 ||
530 strcmp (key, "Space") == 0) {
532 } else if (strcmp (key, "minus") == 0) {
534 } else if (strcmp (key, "plus") == 0
535 /* TODO: That's not universally correct at all, but still handy */
536 || (strcmp (key, "equal") == 0 && play->shift_pressed)) {
538 } else if (strlen (key) > 1) {
542 /* In the case of a simple single-char input,
543 * make it lower or upper as needed, and
544 * send that instead */
545 if (key[0] != '\0' && key[1] == '\0') {
546 if (play->shift_pressed)
547 key_adjusted[0] = g_ascii_toupper (key[0]);
549 key_adjusted[0] = g_ascii_tolower (key[0]);
550 key_adjusted[1] = '\0';
551 key_input = key_adjusted;
556 keyboard_cb (key_input, user_data);
560 case GST_NAVIGATION_EVENT_KEY_RELEASE:
564 if (gst_navigation_event_parse_key_event (ev, &key)) {
565 GST_INFO ("Key release: %s", key);
566 if (strncmp (key, "Shift", 5) == 0) {
567 play->shift_pressed = FALSE;
572 case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
575 if (gst_navigation_event_parse_mouse_button_event (ev, &button,
579 relative_seek (play, +0.08);
580 } else if (button == 5) {
582 relative_seek (play, -0.01);
592 gst_event_unref (ev);
596 case GST_MESSAGE_PROPERTY_NOTIFY:{
600 gchar *val_str = NULL;
603 gst_message_parse_property_notify (msg, &obj, &name, &val);
605 obj_name = gst_object_get_path_string (GST_OBJECT (obj));
607 if (G_VALUE_HOLDS_STRING (val))
608 val_str = g_value_dup_string (val);
609 else if (G_VALUE_TYPE (val) == GST_TYPE_CAPS)
610 val_str = gst_caps_to_string (g_value_get_boxed (val));
611 else if (G_VALUE_TYPE (val) == GST_TYPE_TAG_LIST)
612 val_str = gst_tag_list_to_string (g_value_get_boxed (val));
614 val_str = gst_value_serialize (val);
616 val_str = g_strdup ("(no value)");
619 gst_play_printf ("%s: %s = %s\n", obj_name, name, val_str);
624 case GST_MESSAGE_STREAM_COLLECTION:
626 GstStreamCollection *collection = NULL;
627 gst_message_parse_stream_collection (msg, &collection);
630 g_mutex_lock (&play->selection_lock);
631 if (play->collection)
632 gst_object_unref (play->collection);
633 play->collection = collection;
634 g_mutex_unlock (&play->selection_lock);
638 case GST_MESSAGE_STREAMS_SELECTED:
640 GstStreamCollection *collection = NULL;
643 gst_message_parse_streams_selected (msg, &collection);
645 g_mutex_lock (&play->selection_lock);
646 gst_object_replace ((GstObject **) & play->collection,
647 (GstObject *) collection);
649 /* Free all last stream-ids */
650 g_free (play->cur_audio_sid);
651 g_free (play->cur_video_sid);
652 g_free (play->cur_text_sid);
653 play->cur_audio_sid = NULL;
654 play->cur_video_sid = NULL;
655 play->cur_text_sid = NULL;
657 len = gst_message_streams_selected_get_size (msg);
658 for (i = 0; i < len; i++) {
659 GstStream *stream = gst_message_streams_selected_get_stream (msg, i);
661 GstStreamType type = gst_stream_get_stream_type (stream);
662 const gchar *stream_id = gst_stream_get_stream_id (stream);
664 if (type & GST_STREAM_TYPE_AUDIO) {
665 play->cur_audio_sid = g_strdup (stream_id);
666 } else if (type & GST_STREAM_TYPE_VIDEO) {
667 play->cur_video_sid = g_strdup (stream_id);
668 } else if (type & GST_STREAM_TYPE_TEXT) {
669 play->cur_text_sid = g_strdup (stream_id);
671 gst_print ("Unknown stream type with stream-id %s\n", stream_id);
673 gst_object_unref (stream);
677 gst_object_unref (collection);
678 g_mutex_unlock (&play->selection_lock);
683 if (gst_is_missing_plugin_message (msg)) {
686 desc = gst_missing_plugin_message_get_description (msg);
687 gst_print ("Missing plugin: %s\n", desc);
689 play->missing = g_list_append (play->missing, gst_message_ref (msg));
698 play_timeout (gpointer user_data)
700 GstPlay *play = user_data;
701 gint64 pos = -1, dur = -1;
702 const gchar *paused = _("Paused");
708 gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos);
709 gst_element_query_duration (play->playbin, GST_FORMAT_TIME, &dur);
711 if (play->desired_state == GST_STATE_PAUSED) {
712 status = (gchar *) paused;
714 gint len = g_utf8_strlen (paused, -1);
715 status = g_newa (gchar, len + 1);
716 memset (status, ' ', len);
721 gchar dstr[32], pstr[32];
723 /* FIXME: pretty print in nicer format */
724 g_snprintf (pstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (pos));
726 g_snprintf (dstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
728 gst_print ("%s / %s %s\r", pstr, dstr, status);
735 play_uri_get_display_name (GstPlay * play, const gchar * uri)
739 if (gst_uri_has_protocol (uri, "file")) {
740 loc = g_filename_from_uri (uri, NULL, NULL);
741 } else if (gst_uri_has_protocol (uri, "pushfile")) {
742 loc = g_filename_from_uri (uri + 4, NULL, NULL);
744 loc = g_strdup (uri);
747 /* Maybe additionally use glib's filename to display name function */
752 play_uri (GstPlay * play, const gchar * next_uri)
756 if (!play->instant_uri || play->initial_file)
757 gst_element_set_state (play->playbin, GST_STATE_READY);
760 loc = play_uri_get_display_name (play, next_uri);
761 gst_print (_("Now playing %s\n"), loc);
764 g_object_set (play->playbin, "uri", next_uri, NULL);
766 if (!play->instant_uri || play->initial_file) {
767 switch (gst_element_set_state (play->playbin, GST_STATE_PAUSED)) {
768 case GST_STATE_CHANGE_FAILURE:
769 /* ignore, we should get an error message posted on the bus */
771 case GST_STATE_CHANGE_NO_PREROLL:
772 gst_print ("Pipeline is live.\n");
773 play->is_live = TRUE;
775 case GST_STATE_CHANGE_ASYNC:
776 gst_print ("Prerolling...\r");
782 if (play->desired_state != GST_STATE_PAUSED)
783 gst_element_set_state (play->playbin, play->desired_state);
785 play->initial_file = FALSE;
788 /* returns FALSE if we have reached the end of the playlist */
790 play_next (GstPlay * play)
792 if ((play->cur_idx + 1) >= play->num_uris)
795 play_uri (play, play->uris[++play->cur_idx]);
799 /* returns FALSE if we have reached the beginning of the playlist */
801 play_prev (GstPlay * play)
803 if (play->cur_idx == 0 || play->num_uris <= 1)
806 play_uri (play, play->uris[--play->cur_idx]);
811 play_about_to_finish (GstElement * playbin, gpointer user_data)
813 GstPlay *play = user_data;
814 const gchar *next_uri;
821 next_idx = play->cur_idx + 1;
822 if (next_idx >= play->num_uris)
825 next_uri = play->uris[next_idx];
826 loc = play_uri_get_display_name (play, next_uri);
827 gst_print (_("About to finish, preparing next title: %s"), loc);
831 g_object_set (play->playbin, "uri", next_uri, NULL);
832 play->cur_idx = next_idx;
836 do_play (GstPlay * play)
841 for (i = 0; i < play->num_uris; ++i)
842 GST_INFO ("%4u : %s", i, play->uris[i]);
844 if (!play_next (play))
847 g_main_loop_run (play->loop);
851 compare (gconstpointer a, gconstpointer b)
856 a1 = g_utf8_collate_key_for_filename ((gchar *) a, -1);
857 b1 = g_utf8_collate_key_for_filename ((gchar *) b, -1);
858 ret = strcmp (a1, b1);
866 add_to_playlist (GPtrArray * playlist, const gchar * filename)
871 if (gst_uri_is_valid (filename)) {
872 g_ptr_array_add (playlist, g_strdup (filename));
876 if ((dir = g_dir_open (filename, 0, NULL))) {
878 GList *l, *files = NULL;
880 while ((entry = g_dir_read_name (dir))) {
883 path = g_build_filename (filename, entry, NULL);
884 files = g_list_insert_sorted (files, path, compare);
889 for (l = files; l != NULL; l = l->next) {
890 gchar *path = (gchar *) l->data;
892 add_to_playlist (playlist, path);
899 uri = gst_filename_to_uri (filename, NULL);
901 g_ptr_array_add (playlist, uri);
903 g_warning ("Could not make URI out of filename '%s'", filename);
907 shuffle_uris (gchar ** uris, guint num)
915 for (i = num - 1; i >= 1; i--) {
916 /* +1 because number returned will be in range [a;b[ so excl. stop */
917 j = g_random_int_range (0, i + 1);
925 restore_terminal (void)
927 gst_play_kb_set_key_handler (NULL, NULL);
931 toggle_paused (GstPlay * play)
933 if (play->desired_state == GST_STATE_PLAYING)
934 play->desired_state = GST_STATE_PAUSED;
936 play->desired_state = GST_STATE_PLAYING;
938 if (!play->buffering) {
939 gst_element_set_state (play->playbin, play->desired_state);
940 } else if (play->desired_state == GST_STATE_PLAYING) {
941 gst_print ("\nWill play as soon as buffering finishes)\n");
946 relative_seek (GstPlay * play, gdouble percent)
949 gboolean seekable = FALSE;
950 gint64 dur = -1, pos = -1, step;
952 g_return_if_fail (percent >= -1.0 && percent <= 1.0);
954 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
957 query = gst_query_new_seeking (GST_FORMAT_TIME);
958 if (!gst_element_query (play->playbin, query)) {
959 gst_query_unref (query);
963 gst_query_parse_seeking (query, NULL, &seekable, NULL, &dur);
964 gst_query_unref (query);
966 if (!seekable || dur <= 0)
969 step = dur * percent;
970 if (ABS (step) < GST_SECOND)
971 step = (percent < 0) ? -GST_SECOND : GST_SECOND;
975 if (!play_next (play)) {
976 gst_print ("\n%s\n", _("Reached end of play list."));
977 g_main_loop_quit (play->loop);
983 play_do_seek (play, pos, play->rate, play->trick_mode);
990 gst_print ("\nCould not seek.\n");
995 play_set_rate_and_trick_mode (GstPlay * play, gdouble rate,
996 GstPlayTrickMode mode)
1000 g_return_val_if_fail (rate != 0, FALSE);
1002 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
1005 return play_do_seek (play, pos, rate, mode);
1009 play_do_seek (GstPlay * play, gint64 pos, gdouble rate, GstPlayTrickMode mode)
1011 GstSeekFlags seek_flags;
1014 gboolean seekable = FALSE;
1016 query = gst_query_new_seeking (GST_FORMAT_TIME);
1017 if (!gst_element_query (play->playbin, query)) {
1018 gst_query_unref (query);
1022 gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
1023 gst_query_unref (query);
1031 case GST_PLAY_TRICK_MODE_DEFAULT:
1032 seek_flags |= GST_SEEK_FLAG_TRICKMODE;
1034 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1035 seek_flags |= GST_SEEK_FLAG_TRICKMODE | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1037 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1038 seek_flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
1040 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1042 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1044 case GST_PLAY_TRICK_MODE_NONE:
1049 /* See if we can do an instant rate change (not changing dir) */
1050 if (mode & GST_PLAY_TRICK_MODE_INSTANT_RATE && rate * play->rate > 0) {
1051 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1052 seek_flags | GST_SEEK_FLAG_INSTANT_RATE_CHANGE,
1053 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
1054 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
1055 if (gst_element_send_event (play->playbin, seek)) {
1060 /* No instant rate change, need to do a flushing seek */
1061 seek_flags |= GST_SEEK_FLAG_FLUSH;
1063 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1064 seek_flags | GST_SEEK_FLAG_ACCURATE,
1065 /* start */ GST_SEEK_TYPE_SET, pos,
1066 /* stop */ GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1068 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1069 seek_flags | GST_SEEK_FLAG_ACCURATE,
1070 /* start */ GST_SEEK_TYPE_SET, 0,
1071 /* stop */ GST_SEEK_TYPE_SET, pos);
1073 if (!gst_element_send_event (play->playbin, seek))
1078 play->trick_mode = mode & ~GST_PLAY_TRICK_MODE_INSTANT_RATE;
1083 play_set_playback_rate (GstPlay * play, gdouble rate)
1085 GstPlayTrickMode mode = play->trick_mode;
1087 if (instant_rate_changes)
1088 mode |= GST_PLAY_TRICK_MODE_INSTANT_RATE;
1090 if (play_set_rate_and_trick_mode (play, rate, mode)) {
1091 gst_print (_("Playback rate: %.2f"), rate);
1095 gst_print (_("Could not change playback rate to %.2f"), rate);
1101 play_set_relative_playback_rate (GstPlay * play, gdouble rate_step,
1102 gboolean reverse_direction)
1104 gdouble new_rate = play->rate + rate_step;
1106 if (reverse_direction)
1109 play_set_playback_rate (play, new_rate);
1112 static const gchar *
1113 trick_mode_get_description (GstPlayTrickMode mode)
1116 case GST_PLAY_TRICK_MODE_NONE:
1117 return "normal playback, trick modes disabled";
1118 case GST_PLAY_TRICK_MODE_DEFAULT:
1119 return "trick mode: default";
1120 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1121 return "trick mode: default, no audio";
1122 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1123 return "trick mode: key frames only";
1124 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1125 return "trick mode: key frames only, no audio";
1129 return "unknown trick mode";
1133 play_switch_trick_mode (GstPlay * play)
1135 GstPlayTrickMode new_mode = ++play->trick_mode;
1136 const gchar *mode_desc;
1138 if (new_mode == GST_PLAY_TRICK_MODE_LAST)
1139 new_mode = GST_PLAY_TRICK_MODE_NONE;
1141 mode_desc = trick_mode_get_description (new_mode);
1143 if (play_set_rate_and_trick_mode (play, play->rate, new_mode)) {
1144 gst_print ("Rate: %.2f (%s) \n", play->rate,
1147 gst_print ("\nCould not change trick mode to %s.\n", mode_desc);
1152 play_get_nth_stream_in_collection (GstPlay * play, guint index,
1153 GstPlayTrackType track_type)
1155 guint len, i, n_streams = 0;
1156 GstStreamType target_type;
1158 switch (track_type) {
1159 case GST_PLAY_TRACK_TYPE_AUDIO:
1160 target_type = GST_STREAM_TYPE_AUDIO;
1162 case GST_PLAY_TRACK_TYPE_VIDEO:
1163 target_type = GST_STREAM_TYPE_VIDEO;
1165 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1166 target_type = GST_STREAM_TYPE_TEXT;
1172 len = gst_stream_collection_get_size (play->collection);
1174 for (i = 0; i < len; i++) {
1175 GstStream *stream = gst_stream_collection_get_stream (play->collection, i);
1176 GstStreamType type = gst_stream_get_stream_type (stream);
1178 if (type & target_type) {
1179 if (index == n_streams)
1190 play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type,
1193 const gchar *prop_cur, *prop_n, *prop_get, *name;
1194 gint cur = -1, n = -1;
1195 guint flag, cur_flags;
1197 /* playbin3 variables */
1198 GList *selected_streams = NULL;
1199 gint cur_audio_idx = -1, cur_video_idx = -1, cur_text_idx = -1;
1200 gint nb_audio = 0, nb_video = 0, nb_text = 0;
1203 g_mutex_lock (&play->selection_lock);
1204 if (play->is_playbin3) {
1205 if (!play->collection) {
1206 gst_print ("No stream-collection\n");
1207 g_mutex_unlock (&play->selection_lock);
1211 /* Check the total number of streams of each type */
1212 len = gst_stream_collection_get_size (play->collection);
1213 for (i = 0; i < len; i++) {
1215 gst_stream_collection_get_stream (play->collection, i);
1217 GstStreamType type = gst_stream_get_stream_type (stream);
1218 const gchar *sid = gst_stream_get_stream_id (stream);
1220 if (type & GST_STREAM_TYPE_AUDIO) {
1221 if (play->cur_audio_sid && !g_strcmp0 (play->cur_audio_sid, sid))
1222 cur_audio_idx = nb_audio;
1224 } else if (type & GST_STREAM_TYPE_VIDEO) {
1225 if (play->cur_video_sid && !g_strcmp0 (play->cur_video_sid, sid))
1226 cur_video_idx = nb_video;
1228 } else if (type & GST_STREAM_TYPE_TEXT) {
1229 if (play->cur_text_sid && !g_strcmp0 (play->cur_text_sid, sid))
1230 cur_text_idx = nb_text;
1233 gst_print ("Unknown stream type with stream-id %s", sid);
1239 switch (track_type) {
1240 case GST_PLAY_TRACK_TYPE_AUDIO:
1241 prop_get = "get-audio-tags";
1242 prop_cur = "current-audio";
1246 if (play->is_playbin3) {
1248 cur = cur_audio_idx;
1249 if (play->cur_video_sid) {
1251 g_list_append (selected_streams, play->cur_video_sid);
1253 if (play->cur_text_sid) {
1255 g_list_append (selected_streams, play->cur_text_sid);
1259 case GST_PLAY_TRACK_TYPE_VIDEO:
1260 prop_get = "get-video-tags";
1261 prop_cur = "current-video";
1265 if (play->is_playbin3) {
1267 cur = cur_video_idx;
1268 if (play->cur_audio_sid) {
1270 g_list_append (selected_streams, play->cur_audio_sid);
1272 if (play->cur_text_sid) {
1274 g_list_append (selected_streams, play->cur_text_sid);
1278 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1279 prop_get = "get-text-tags";
1280 prop_cur = "current-text";
1284 if (play->is_playbin3) {
1287 if (play->cur_audio_sid) {
1289 g_list_append (selected_streams, play->cur_audio_sid);
1291 if (play->cur_video_sid) {
1293 g_list_append (selected_streams, play->cur_video_sid);
1301 if (play->is_playbin3) {
1307 cur = (cur + 1) % (n + 1);
1312 cur = (cur - 1) % (n + 1);
1316 g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags",
1320 if (!(cur_flags & flag))
1323 cur = (cur + 1) % (n + 1);
1329 cur = (cur - 1) % (n + 1);
1334 gst_print ("No %s tracks.\n", name);
1335 g_mutex_unlock (&play->selection_lock);
1337 gchar *lcode = NULL, *lname = NULL;
1338 const gchar *lang = NULL;
1339 GstTagList *tags = NULL;
1341 if (cur >= n && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1343 gst_print ("Disabling %s. \n", name);
1344 if (play->is_playbin3) {
1345 /* Just make it empty for the track type */
1346 } else if (cur_flags & flag) {
1348 g_object_set (play->playbin, "flags", cur_flags, NULL);
1351 /* For video we only want to switch between streams, not disable it altogether */
1355 if (play->is_playbin3) {
1358 stream = play_get_nth_stream_in_collection (play, cur, track_type);
1360 selected_streams = g_list_append (selected_streams,
1361 (gchar *) gst_stream_get_stream_id (stream));
1362 tags = gst_stream_get_tags (stream);
1364 gst_print ("Collection has no stream for track %d of %d.\n",
1368 if (!(cur_flags & flag) && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1370 g_object_set (play->playbin, "flags", cur_flags, NULL);
1372 g_signal_emit_by_name (play->playbin, prop_get, cur, &tags);
1376 if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lcode))
1377 lang = gst_tag_get_language_name (lcode);
1378 else if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_NAME, &lname))
1380 gst_tag_list_unref (tags);
1383 gst_print ("Switching to %s track %d of %d (%s).\n", name, cur + 1, n,
1386 gst_print ("Switching to %s track %d of %d.\n", name, cur + 1, n);
1390 g_mutex_unlock (&play->selection_lock);
1392 if (play->is_playbin3) {
1393 if (selected_streams)
1394 gst_element_send_event (play->playbin,
1395 gst_event_new_select_streams (selected_streams));
1397 gst_print ("Can't disable all streams !\n");
1399 g_object_set (play->playbin, prop_cur, cur, NULL);
1403 if (selected_streams)
1404 g_list_free (selected_streams);
1408 print_keyboard_help (void)
1413 const gchar *key_desc;
1414 const gchar *key_help;
1415 } key_controls[] = {
1417 N_("space"), N_("pause/unpause")}, {
1418 N_("q or ESC"), N_("quit")}, {
1419 N_("> or n"), N_("play next")}, {
1420 N_("< or b"), N_("play previous")}, {
1421 "\342\206\222", N_("seek forward")}, {
1422 "\342\206\220", N_("seek backward")}, {
1423 "\342\206\221", N_("volume up")}, {
1424 "\342\206\223", N_("volume down")}, {
1425 "m", N_("toggle audio mute on/off")}, {
1426 "+", N_("increase playback rate")}, {
1427 "-", N_("decrease playback rate")}, {
1428 "d", N_("change playback direction")}, {
1429 "t", N_("enable/disable trick modes")}, {
1430 "A/a", N_("change to previous/next audio track")}, {
1431 "V/v", N_("change to previous/next video track")}, {
1432 "S/s", N_("change to previous/next subtitle track")}, {
1433 "0", N_("seek to beginning")}, {
1434 "k", N_("show keyboard shortcuts")},};
1436 guint i, chars_to_pad, desc_len, max_desc_len = 0;
1438 gst_print ("\n\n%s\n\n", _("Interactive mode - keyboard controls:"));
1440 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1441 desc_len = g_utf8_strlen (key_controls[i].key_desc, -1);
1442 max_desc_len = MAX (max_desc_len, desc_len);
1446 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1447 chars_to_pad = max_desc_len - g_utf8_strlen (key_controls[i].key_desc, -1);
1448 gst_print ("\t%s", key_controls[i].key_desc);
1449 gst_print ("%-*s: ", chars_to_pad, "");
1450 gst_print ("%s\n", key_controls[i].key_help);
1456 keyboard_cb (const gchar * key_input, gpointer user_data)
1458 GstPlay *play = (GstPlay *) user_data;
1461 /* Switch on the first char for single char inputs,
1462 * otherwise leave key = '\0' to fall through to
1463 * the default case below */
1464 if (key_input[0] != '\0' && key_input[1] == '\0') {
1470 print_keyboard_help ();
1473 toggle_paused (play);
1477 g_main_loop_quit (play->loop);
1481 if (!play_next (play)) {
1482 gst_print ("\n%s\n", _("Reached end of play list."));
1483 g_main_loop_quit (play->loop);
1491 if (play->rate > -0.2 && play->rate < 0.0)
1492 play_set_relative_playback_rate (play, 0.0, TRUE);
1493 else if (ABS (play->rate) < 2.0)
1494 play_set_relative_playback_rate (play, 0.1, FALSE);
1495 else if (ABS (play->rate) < 4.0)
1496 play_set_relative_playback_rate (play, 0.5, FALSE);
1498 play_set_relative_playback_rate (play, 1.0, FALSE);
1501 if (play->rate > 0.0 && play->rate < 0.20)
1502 play_set_relative_playback_rate (play, 0.0, TRUE);
1503 else if (ABS (play->rate) <= 2.0)
1504 play_set_relative_playback_rate (play, -0.1, FALSE);
1505 else if (ABS (play->rate) <= 4.0)
1506 play_set_relative_playback_rate (play, -0.5, FALSE);
1508 play_set_relative_playback_rate (play, -1.0, FALSE);
1511 play_set_relative_playback_rate (play, 0.0, TRUE);
1514 play_switch_trick_mode (play);
1517 if (key_input[1] == '\0') {
1518 g_main_loop_quit (play->loop);
1523 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO, key == 'a');
1527 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO, key == 'v');
1531 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE,
1535 play_do_seek (play, 0, play->rate, play->trick_mode);
1538 play_toggle_audio_mute (play);
1541 if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
1542 relative_seek (play, +0.08);
1543 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
1544 relative_seek (play, -0.01);
1545 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
1546 play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
1547 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
1548 play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
1550 GST_INFO ("keyboard input:");
1551 for (; *key_input != '\0'; ++key_input)
1552 GST_INFO (" code %3d", *key_input);
1560 enable_winmm_timer_resolution (void)
1563 guint resolution = 0;
1566 res = timeGetDevCaps (&time_caps, sizeof (TIMECAPS));
1567 if (res != TIMERR_NOERROR) {
1568 g_warning ("timeGetDevCaps() returned non-zero code %d", res);
1572 resolution = MIN (MAX (time_caps.wPeriodMin, 1), time_caps.wPeriodMax);
1573 res = timeBeginPeriod (resolution);
1574 if (res != TIMERR_NOERROR) {
1575 g_warning ("timeBeginPeriod() returned non-zero code %d", res);
1579 gst_println (_("Use Windows high-resolution clock, precision: %u ms\n"),
1586 clear_winmm_timer_resolution (guint resolution)
1588 if (resolution == 0)
1591 timeEndPeriod (resolution);
1596 main (int argc, char **argv)
1599 GPtrArray *playlist;
1600 gboolean verbose = FALSE;
1601 gboolean print_version = FALSE;
1602 gboolean interactive = TRUE;
1603 gboolean gapless = FALSE;
1604 gboolean instant_uri = FALSE;
1605 gboolean shuffle = FALSE;
1606 gdouble volume = -1;
1607 gdouble start_position = 0;
1608 gchar **filenames = NULL;
1609 gchar *audio_sink = NULL;
1610 gchar *video_sink = NULL;
1612 gchar *flags = NULL;
1615 GOptionContext *ctx;
1616 gchar *playlist_file = NULL;
1617 gboolean use_playbin3 = FALSE;
1619 guint winmm_timer_resolution = 0;
1621 GOptionEntry options[] = {
1622 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
1623 N_("Output status information and property notifications"), NULL},
1624 {"flags", 0, 0, G_OPTION_ARG_STRING, &flags,
1625 N_("Control playback behaviour setting playbin 'flags' property"),
1627 {"version", 0, 0, G_OPTION_ARG_NONE, &print_version,
1628 N_("Print version information and exit"), NULL},
1629 {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink,
1630 N_("Video sink to use (default is autovideosink)"), NULL},
1631 {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink,
1632 N_("Audio sink to use (default is autoaudiosink)"), NULL},
1633 {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless,
1634 N_("Enable gapless playback"), NULL},
1635 {"instant-uri", 0, 0, G_OPTION_ARG_NONE, &instant_uri,
1636 N_("Enable instantaneous uri changes (only with playbin3)"), NULL},
1637 {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
1638 N_("Shuffle playlist"), NULL},
1639 {"no-interactive", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1641 N_("Disable interactive control via the keyboard"), NULL},
1642 {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume,
1643 N_("Volume"), NULL},
1644 {"start-position", 's', 0, G_OPTION_ARG_DOUBLE, &start_position,
1645 N_("Start position in seconds."), NULL},
1646 {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file,
1647 N_("Playlist file containing input media files"), NULL},
1648 {"instant-rate-changes", 'i', 0, G_OPTION_ARG_NONE, &instant_rate_changes,
1650 ("Use the experimental instant-rate-change flag when changing rate"),
1652 {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
1653 N_("Do not print any output (apart from errors)"), NULL},
1654 {"use-playbin3", 0, 0, G_OPTION_ARG_NONE, &use_playbin3,
1655 N_("Use playbin3 pipeline "
1656 "(default varies depending on 'USE_PLAYBIN' env variable)"),
1658 {"wait-on-eos", 0, 0, G_OPTION_ARG_NONE, &wait_on_eos,
1660 ("Keep showing the last frame on EOS until quit or playlist change command "
1661 "(gapless is ignored)"),
1663 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
1667 setlocale (LC_ALL, "");
1670 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1671 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1672 textdomain (GETTEXT_PACKAGE);
1675 g_set_prgname ("gst-play-" GST_API_VERSION);
1676 /* Ensure XInitThreads() is called if/when needed */
1677 g_setenv ("GST_GL_XINITTHREADS", "1", TRUE);
1678 g_setenv ("GST_XINITTHREADS", "1", TRUE);
1680 ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...");
1681 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1682 g_option_context_add_group (ctx, gst_init_get_option_group ());
1683 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1684 gst_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
1685 g_option_context_free (ctx);
1686 g_clear_error (&err);
1689 g_option_context_free (ctx);
1691 GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play");
1693 if (print_version) {
1696 version_str = gst_version_string ();
1697 gst_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION);
1698 gst_print ("%s\n", version_str);
1699 gst_print ("%s\n", GST_PACKAGE_ORIGIN);
1700 g_free (version_str);
1702 g_free (audio_sink);
1703 g_free (video_sink);
1704 g_free (playlist_file);
1712 playlist = g_ptr_array_new ();
1714 if (playlist_file != NULL) {
1715 gchar *playlist_contents = NULL;
1716 gchar **lines = NULL;
1718 if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) {
1719 lines = g_strsplit (playlist_contents, "\n", 0);
1720 num = g_strv_length (lines);
1722 for (i = 0; i < num; i++) {
1723 if (lines[i][0] != '\0') {
1724 GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]);
1725 add_to_playlist (playlist, lines[i]);
1729 g_free (playlist_contents);
1731 gst_printerr ("Could not read playlist: %s\n", err->message);
1732 g_clear_error (&err);
1734 g_free (playlist_file);
1735 playlist_file = NULL;
1738 if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) {
1739 gst_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."),
1740 "gst-play-" GST_API_VERSION);
1741 gst_printerr ("\n\n"),
1742 gst_printerr ("%s\n\n",
1743 _("You must provide at least one filename or URI to play."));
1744 /* No input provided. Free array */
1745 g_ptr_array_free (playlist, TRUE);
1747 g_free (audio_sink);
1748 g_free (video_sink);
1754 if (filenames != NULL && *filenames != NULL) {
1755 num = g_strv_length (filenames);
1756 for (i = 0; i < num; ++i) {
1757 GST_LOG ("command line argument: %s", filenames[i]);
1758 add_to_playlist (playlist, filenames[i]);
1760 g_strfreev (filenames);
1763 num = playlist->len;
1764 g_ptr_array_add (playlist, NULL);
1766 uris = (gchar **) g_ptr_array_free (playlist, FALSE);
1769 shuffle_uris (uris, num);
1773 play_new (uris, audio_sink, video_sink, gapless, instant_uri, volume,
1774 verbose, flags, use_playbin3, start_position);
1778 ("Failed to create 'playbin' element. Check your GStreamer installation.\n");
1779 return EXIT_FAILURE;
1782 /* Enable high-precision clock which will improve accuracy of various
1783 * Windows timer APIs (e.g., Sleep()), and it will increase the precision
1784 * of GstSystemClock as well
1787 /* NOTE: Once timer resolution is updated via timeBeginPeriod(),
1788 * application should undo it by calling timeEndPeriod()
1790 * Prior to Windows 10, version 2004, timeBeginPeriod() affects global
1791 * Windows setting (meaning that it will affect other processes),
1792 * but starting with Windows 10, version 2004, this function no longer
1793 * affects global timer resolution
1795 winmm_timer_resolution = enable_winmm_timer_resolution ();
1799 if (gst_play_kb_set_key_handler (keyboard_cb, play)) {
1800 gst_print (_("Press 'k' to see a list of keyboard shortcuts.\n"));
1801 atexit (restore_terminal);
1803 gst_print ("Interactive keyboard handling in terminal not available.\n");
1811 /* Undo timeBeginPeriod() if required */
1812 clear_winmm_timer_resolution (winmm_timer_resolution);
1818 g_free (audio_sink);
1819 g_free (video_sink);