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 <gst/gst-i18n-app.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 */
108 GstState desired_state; /* as per user interaction, PAUSED or PLAYING */
110 gulong deep_notify_id;
115 GstPlayTrickMode trick_mode;
117 gdouble start_position;
119 /* keyboard state tracking */
120 gboolean shift_pressed;
123 static gboolean quiet = FALSE;
124 static gboolean instant_rate_changes = FALSE;
126 static gboolean play_bus_msg (GstBus * bus, GstMessage * msg, gpointer data);
127 static gboolean play_next (GstPlay * play);
128 static gboolean play_prev (GstPlay * play);
129 static gboolean play_timeout (gpointer user_data);
130 static void play_about_to_finish (GstElement * playbin, gpointer user_data);
131 static void play_reset (GstPlay * play);
132 static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
133 static gboolean play_do_seek (GstPlay * play, gint64 pos, gdouble rate,
134 GstPlayTrickMode mode);
137 static void gst_play_printf (const gchar * format, ...) G_GNUC_PRINTF (1, 2);
140 static void keyboard_cb (const gchar * key_input, gpointer user_data);
141 static void relative_seek (GstPlay * play, gdouble percent);
144 gst_play_printf (const gchar * format, ...)
153 va_start (args, format);
155 len = g_vasprintf (&str, format, args);
159 if (len > 0 && str != NULL)
160 gst_print ("%s", str);
165 #define gst_print gst_play_printf
168 play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
169 gboolean gapless, gdouble initial_volume, gboolean verbose,
170 const gchar * flags_string, gboolean use_playbin3, gdouble start_position)
172 GstElement *sink, *playbin;
177 playbin = gst_element_factory_make ("playbin3", "playbin");
179 playbin = gst_element_factory_make ("playbin", "playbin");
185 play = g_new0 (GstPlay, 1);
188 play->num_uris = g_strv_length (uris);
191 play->playbin = playbin;
194 play->is_playbin3 = TRUE;
196 const gchar *env = g_getenv ("USE_PLAYBIN3");
197 if (env && g_str_has_prefix (env, "1"))
198 play->is_playbin3 = TRUE;
201 g_mutex_init (&play->selection_lock);
203 if (audio_sink != NULL) {
204 if (strchr (audio_sink, ' ') != NULL)
205 sink = gst_parse_bin_from_description (audio_sink, TRUE, NULL);
207 sink = gst_element_factory_make (audio_sink, NULL);
210 g_object_set (play->playbin, "audio-sink", sink, NULL);
212 g_warning ("Couldn't create specified audio sink '%s'", audio_sink);
214 if (video_sink != NULL) {
215 if (strchr (video_sink, ' ') != NULL)
216 sink = gst_parse_bin_from_description (video_sink, TRUE, NULL);
218 sink = gst_element_factory_make (video_sink, NULL);
221 g_object_set (play->playbin, "video-sink", sink, NULL);
223 g_warning ("Couldn't create specified video sink '%s'", video_sink);
226 if (flags_string != NULL) {
231 g_object_class_find_property (G_OBJECT_GET_CLASS (playbin), "flags");
232 g_value_init (&val, pspec->value_type);
233 if (gst_value_deserialize (&val, flags_string))
234 g_object_set_property (G_OBJECT (play->playbin), "flags", &val);
236 gst_printerr ("Couldn't convert '%s' to playbin flags!\n", flags_string);
237 g_value_unset (&val);
241 play->deep_notify_id =
242 gst_element_add_property_deep_notify_watch (play->playbin, NULL, TRUE);
245 play->loop = g_main_loop_new (NULL, FALSE);
247 play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin),
250 /* FIXME: make configurable incl. 0 for disable */
251 play->timeout = g_timeout_add (100, play_timeout, play);
253 play->missing = NULL;
254 play->buffering = FALSE;
255 play->is_live = FALSE;
257 play->desired_state = GST_STATE_PLAYING;
259 play->gapless = gapless;
261 g_signal_connect (play->playbin, "about-to-finish",
262 G_CALLBACK (play_about_to_finish), play);
265 if (initial_volume != -1)
266 play_set_relative_volume (play, initial_volume - 1.0);
269 play->trick_mode = GST_PLAY_TRICK_MODE_NONE;
270 play->start_position = start_position;
275 play_free (GstPlay * play)
277 /* No need to see all those pad caps going to NULL etc., it's just noise */
278 if (play->deep_notify_id != 0)
279 g_signal_handler_disconnect (play->playbin, play->deep_notify_id);
283 gst_element_set_state (play->playbin, GST_STATE_NULL);
284 gst_object_unref (play->playbin);
286 g_source_remove (play->bus_watch);
287 g_source_remove (play->timeout);
288 g_main_loop_unref (play->loop);
290 g_strfreev (play->uris);
292 if (play->collection)
293 gst_object_unref (play->collection);
294 g_free (play->cur_audio_sid);
295 g_free (play->cur_video_sid);
296 g_free (play->cur_text_sid);
298 g_mutex_clear (&play->selection_lock);
303 /* reset for new file/stream */
305 play_reset (GstPlay * play)
307 g_list_foreach (play->missing, (GFunc) gst_message_unref, NULL);
308 play->missing = NULL;
310 play->buffering = FALSE;
311 play->is_live = FALSE;
315 play_set_relative_volume (GstPlay * play, gdouble volume_step)
319 volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (play->playbin),
320 GST_STREAM_VOLUME_FORMAT_CUBIC);
322 volume = round ((volume + volume_step) * VOLUME_STEPS) / VOLUME_STEPS;
323 volume = CLAMP (volume, 0.0, 10.0);
325 gst_stream_volume_set_volume (GST_STREAM_VOLUME (play->playbin),
326 GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
328 gst_print (_("Volume: %.0f%%"), volume * 100);
333 play_toggle_audio_mute (GstPlay * play)
337 mute = gst_stream_volume_get_mute (GST_STREAM_VOLUME (play->playbin));
340 gst_stream_volume_set_mute (GST_STREAM_VOLUME (play->playbin), mute);
343 gst_print (_("Mute: on"));
345 gst_print (_("Mute: off"));
349 /* returns TRUE if something was installed and we should restart playback */
351 play_install_missing_plugins (GstPlay * play)
353 /* FIXME: implement: try to install any missing plugins we haven't
354 * tried to install before */
359 play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
361 GstPlay *play = user_data;
363 switch (GST_MESSAGE_TYPE (msg)) {
364 case GST_MESSAGE_ASYNC_DONE:
366 /* dump graph on preroll */
367 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
368 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.async-done");
370 gst_print ("Prerolled.\r");
371 if (play->missing != NULL && play_install_missing_plugins (play)) {
372 gst_print ("New plugins installed, trying again...\n");
376 if (play->start_position > 0.0) {
377 play_do_seek (play, play->start_position * GST_SECOND,
378 play->rate, play->trick_mode);
379 play->start_position = 0;
382 case GST_MESSAGE_BUFFERING:{
385 if (!play->buffering)
388 gst_message_parse_buffering (msg, &percent);
389 gst_print ("%s %d%% \r", _("Buffering..."), percent);
391 if (percent == 100) {
392 /* a 100% message means buffering is done */
393 if (play->buffering) {
394 play->buffering = FALSE;
395 /* no state management needed for live pipelines */
397 gst_element_set_state (play->playbin, play->desired_state);
401 if (!play->buffering) {
403 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
404 play->buffering = TRUE;
409 case GST_MESSAGE_CLOCK_LOST:{
410 gst_print (_("Clock lost, selecting a new one\n"));
411 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
412 gst_element_set_state (play->playbin, GST_STATE_PLAYING);
415 case GST_MESSAGE_LATENCY:
416 gst_print ("Redistribute latency...\n");
417 gst_bin_recalculate_latency (GST_BIN (play->playbin));
419 case GST_MESSAGE_REQUEST_STATE:{
423 name = gst_object_get_path_string (GST_MESSAGE_SRC (msg));
425 gst_message_parse_request_state (msg, &state);
427 gst_print ("Setting state to %s as requested by %s...\n",
428 gst_element_state_get_name (state), name);
430 gst_element_set_state (play->playbin, state);
434 case GST_MESSAGE_EOS:
435 /* print final position at end */
438 /* and switch to next item in list */
439 if (!wait_on_eos && !play_next (play)) {
440 gst_print ("%s\n", _("Reached end of play list."));
441 g_main_loop_quit (play->loop);
444 case GST_MESSAGE_WARNING:{
448 /* dump graph on warning */
449 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
450 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.warning");
452 gst_message_parse_warning (msg, &err, &dbg);
453 gst_printerr ("WARNING %s\n", err->message);
455 gst_printerr ("WARNING debug information: %s\n", dbg);
456 g_clear_error (&err);
460 case GST_MESSAGE_ERROR:{
464 /* dump graph on error */
465 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
466 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.error");
468 gst_message_parse_error (msg, &err, &dbg);
469 gst_printerr ("ERROR %s for %s\n", err->message,
470 play->uris[play->cur_idx]);
472 gst_printerr ("ERROR debug information: %s\n", dbg);
473 g_clear_error (&err);
476 /* flush any other error messages from the bus and clean up */
477 gst_element_set_state (play->playbin, GST_STATE_NULL);
479 if (play->missing != NULL && play_install_missing_plugins (play)) {
480 gst_print ("New plugins installed, trying again...\n");
485 /* try next item in list then */
486 if (!play_next (play)) {
487 gst_print ("%s\n", _("Reached end of play list."));
488 g_main_loop_quit (play->loop);
492 case GST_MESSAGE_ELEMENT:
494 GstNavigationMessageType mtype = gst_navigation_message_get_type (msg);
495 if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
498 if (gst_navigation_message_parse_event (msg, &ev)) {
499 GstNavigationEventType e_type = gst_navigation_event_get_type (ev);
501 case GST_NAVIGATION_EVENT_KEY_PRESS:
504 const gchar *key_input;
505 gchar key_adjusted[2];
507 if (gst_navigation_event_parse_key_event (ev, &key)) {
508 GST_INFO ("Key press: %s", key);
510 if (strcmp (key, "Left") == 0)
511 key = GST_PLAY_KB_ARROW_LEFT;
512 else if (strcmp (key, "Right") == 0)
513 key = GST_PLAY_KB_ARROW_RIGHT;
514 else if (strcmp (key, "Up") == 0)
515 key = GST_PLAY_KB_ARROW_UP;
516 else if (strcmp (key, "Down") == 0)
517 key = GST_PLAY_KB_ARROW_DOWN;
518 else if (strncmp (key, "Shift", 5) == 0) {
519 play->shift_pressed = TRUE;
521 } else if (strcmp (key, "space") == 0 ||
522 strcmp (key, "Space") == 0) {
524 } else if (strcmp (key, "minus") == 0) {
526 } else if (strcmp (key, "plus") == 0
527 /* TODO: That's not universally correct at all, but still handy */
528 || (strcmp (key, "equal") == 0 && play->shift_pressed)) {
530 } else if (strlen (key) > 1) {
534 /* In the case of a simple single-char input,
535 * make it lower or upper as needed, and
536 * send that instead */
537 if (key[0] != '\0' && key[1] == '\0') {
538 if (play->shift_pressed)
539 key_adjusted[0] = g_ascii_toupper (key[0]);
541 key_adjusted[0] = g_ascii_tolower (key[0]);
542 key_adjusted[1] = '\0';
543 key_input = key_adjusted;
548 keyboard_cb (key_input, user_data);
552 case GST_NAVIGATION_EVENT_KEY_RELEASE:
556 if (gst_navigation_event_parse_key_event (ev, &key)) {
557 GST_INFO ("Key release: %s", key);
558 if (strncmp (key, "Shift", 5) == 0) {
559 play->shift_pressed = FALSE;
564 case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
567 if (gst_navigation_event_parse_mouse_button_event (ev, &button,
571 relative_seek (play, +0.08);
572 } else if (button == 5) {
574 relative_seek (play, -0.01);
584 gst_event_unref (ev);
588 case GST_MESSAGE_PROPERTY_NOTIFY:{
592 gchar *val_str = NULL;
595 gst_message_parse_property_notify (msg, &obj, &name, &val);
597 obj_name = gst_object_get_path_string (GST_OBJECT (obj));
599 if (G_VALUE_HOLDS_STRING (val))
600 val_str = g_value_dup_string (val);
601 else if (G_VALUE_TYPE (val) == GST_TYPE_CAPS)
602 val_str = gst_caps_to_string (g_value_get_boxed (val));
603 else if (G_VALUE_TYPE (val) == GST_TYPE_TAG_LIST)
604 val_str = gst_tag_list_to_string (g_value_get_boxed (val));
606 val_str = gst_value_serialize (val);
608 val_str = g_strdup ("(no value)");
611 gst_play_printf ("%s: %s = %s\n", obj_name, name, val_str);
616 case GST_MESSAGE_STREAM_COLLECTION:
618 GstStreamCollection *collection = NULL;
619 gst_message_parse_stream_collection (msg, &collection);
622 g_mutex_lock (&play->selection_lock);
623 gst_object_replace ((GstObject **) & play->collection,
624 (GstObject *) collection);
625 g_mutex_unlock (&play->selection_lock);
629 case GST_MESSAGE_STREAMS_SELECTED:
631 GstStreamCollection *collection = NULL;
634 gst_message_parse_streams_selected (msg, &collection);
636 g_mutex_lock (&play->selection_lock);
637 gst_object_replace ((GstObject **) & play->collection,
638 (GstObject *) collection);
640 /* Free all last stream-ids */
641 g_free (play->cur_audio_sid);
642 g_free (play->cur_video_sid);
643 g_free (play->cur_text_sid);
644 play->cur_audio_sid = NULL;
645 play->cur_video_sid = NULL;
646 play->cur_text_sid = NULL;
648 len = gst_message_streams_selected_get_size (msg);
649 for (i = 0; i < len; i++) {
650 GstStream *stream = gst_message_streams_selected_get_stream (msg, i);
652 GstStreamType type = gst_stream_get_stream_type (stream);
653 const gchar *stream_id = gst_stream_get_stream_id (stream);
655 if (type & GST_STREAM_TYPE_AUDIO) {
656 play->cur_audio_sid = g_strdup (stream_id);
657 } else if (type & GST_STREAM_TYPE_VIDEO) {
658 play->cur_video_sid = g_strdup (stream_id);
659 } else if (type & GST_STREAM_TYPE_TEXT) {
660 play->cur_text_sid = g_strdup (stream_id);
662 gst_print ("Unknown stream type with stream-id %s", stream_id);
664 gst_object_unref (stream);
668 gst_object_unref (collection);
669 g_mutex_unlock (&play->selection_lock);
674 if (gst_is_missing_plugin_message (msg)) {
677 desc = gst_missing_plugin_message_get_description (msg);
678 gst_print ("Missing plugin: %s\n", desc);
680 play->missing = g_list_append (play->missing, gst_message_ref (msg));
689 play_timeout (gpointer user_data)
691 GstPlay *play = user_data;
692 gint64 pos = -1, dur = -1;
693 const gchar *paused = _("Paused");
699 gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos);
700 gst_element_query_duration (play->playbin, GST_FORMAT_TIME, &dur);
702 if (play->desired_state == GST_STATE_PAUSED) {
703 status = (gchar *) paused;
705 gint len = g_utf8_strlen (paused, -1);
706 status = g_newa (gchar, len + 1);
707 memset (status, ' ', len);
711 if (pos >= 0 && dur > 0) {
712 gchar dstr[32], pstr[32];
714 /* FIXME: pretty print in nicer format */
715 g_snprintf (pstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (pos));
717 g_snprintf (dstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
719 gst_print ("%s / %s %s\r", pstr, dstr, status);
726 play_uri_get_display_name (GstPlay * play, const gchar * uri)
730 if (gst_uri_has_protocol (uri, "file")) {
731 loc = g_filename_from_uri (uri, NULL, NULL);
732 } else if (gst_uri_has_protocol (uri, "pushfile")) {
733 loc = g_filename_from_uri (uri + 4, NULL, NULL);
735 loc = g_strdup (uri);
738 /* Maybe additionally use glib's filename to display name function */
743 play_uri (GstPlay * play, const gchar * next_uri)
747 gst_element_set_state (play->playbin, GST_STATE_READY);
750 loc = play_uri_get_display_name (play, next_uri);
751 gst_print (_("Now playing %s\n"), loc);
754 g_object_set (play->playbin, "uri", next_uri, NULL);
756 switch (gst_element_set_state (play->playbin, GST_STATE_PAUSED)) {
757 case GST_STATE_CHANGE_FAILURE:
758 /* ignore, we should get an error message posted on the bus */
760 case GST_STATE_CHANGE_NO_PREROLL:
761 gst_print ("Pipeline is live.\n");
762 play->is_live = TRUE;
764 case GST_STATE_CHANGE_ASYNC:
765 gst_print ("Prerolling...\r");
771 if (play->desired_state != GST_STATE_PAUSED)
772 gst_element_set_state (play->playbin, play->desired_state);
775 /* returns FALSE if we have reached the end of the playlist */
777 play_next (GstPlay * play)
779 if ((play->cur_idx + 1) >= play->num_uris)
782 play_uri (play, play->uris[++play->cur_idx]);
786 /* returns FALSE if we have reached the beginning of the playlist */
788 play_prev (GstPlay * play)
790 if (play->cur_idx == 0 || play->num_uris <= 1)
793 play_uri (play, play->uris[--play->cur_idx]);
798 play_about_to_finish (GstElement * playbin, gpointer user_data)
800 GstPlay *play = user_data;
801 const gchar *next_uri;
808 next_idx = play->cur_idx + 1;
809 if (next_idx >= play->num_uris)
812 next_uri = play->uris[next_idx];
813 loc = play_uri_get_display_name (play, next_uri);
814 gst_print (_("About to finish, preparing next title: %s"), loc);
818 g_object_set (play->playbin, "uri", next_uri, NULL);
819 play->cur_idx = next_idx;
823 do_play (GstPlay * play)
828 for (i = 0; i < play->num_uris; ++i)
829 GST_INFO ("%4u : %s", i, play->uris[i]);
831 if (!play_next (play))
834 g_main_loop_run (play->loop);
838 compare (gconstpointer a, gconstpointer b)
843 a1 = g_utf8_collate_key_for_filename ((gchar *) a, -1);
844 b1 = g_utf8_collate_key_for_filename ((gchar *) b, -1);
845 ret = strcmp (a1, b1);
853 add_to_playlist (GPtrArray * playlist, const gchar * filename)
858 if (gst_uri_is_valid (filename)) {
859 g_ptr_array_add (playlist, g_strdup (filename));
863 if ((dir = g_dir_open (filename, 0, NULL))) {
865 GList *l, *files = NULL;
867 while ((entry = g_dir_read_name (dir))) {
870 path = g_build_filename (filename, entry, NULL);
871 files = g_list_insert_sorted (files, path, compare);
876 for (l = files; l != NULL; l = l->next) {
877 gchar *path = (gchar *) l->data;
879 add_to_playlist (playlist, path);
886 uri = gst_filename_to_uri (filename, NULL);
888 g_ptr_array_add (playlist, uri);
890 g_warning ("Could not make URI out of filename '%s'", filename);
894 shuffle_uris (gchar ** uris, guint num)
902 for (i = num - 1; i >= 1; i--) {
903 /* +1 because number returned will be in range [a;b[ so excl. stop */
904 j = g_random_int_range (0, i + 1);
912 restore_terminal (void)
914 gst_play_kb_set_key_handler (NULL, NULL);
918 toggle_paused (GstPlay * play)
920 if (play->desired_state == GST_STATE_PLAYING)
921 play->desired_state = GST_STATE_PAUSED;
923 play->desired_state = GST_STATE_PLAYING;
925 if (!play->buffering) {
926 gst_element_set_state (play->playbin, play->desired_state);
927 } else if (play->desired_state == GST_STATE_PLAYING) {
928 gst_print ("\nWill play as soon as buffering finishes)\n");
933 relative_seek (GstPlay * play, gdouble percent)
936 gboolean seekable = FALSE;
937 gint64 dur = -1, pos = -1, step;
939 g_return_if_fail (percent >= -1.0 && percent <= 1.0);
941 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
944 query = gst_query_new_seeking (GST_FORMAT_TIME);
945 if (!gst_element_query (play->playbin, query)) {
946 gst_query_unref (query);
950 gst_query_parse_seeking (query, NULL, &seekable, NULL, &dur);
951 gst_query_unref (query);
953 if (!seekable || dur <= 0)
956 step = dur * percent;
957 if (ABS (step) < GST_SECOND)
958 step = (percent < 0) ? -GST_SECOND : GST_SECOND;
962 if (!play_next (play)) {
963 gst_print ("\n%s\n", _("Reached end of play list."));
964 g_main_loop_quit (play->loop);
970 play_do_seek (play, pos, play->rate, play->trick_mode);
977 gst_print ("\nCould not seek.\n");
982 play_set_rate_and_trick_mode (GstPlay * play, gdouble rate,
983 GstPlayTrickMode mode)
987 g_return_val_if_fail (rate != 0, FALSE);
989 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
992 return play_do_seek (play, pos, rate, mode);
996 play_do_seek (GstPlay * play, gint64 pos, gdouble rate, GstPlayTrickMode mode)
998 GstSeekFlags seek_flags;
1001 gboolean seekable = FALSE;
1003 query = gst_query_new_seeking (GST_FORMAT_TIME);
1004 if (!gst_element_query (play->playbin, query)) {
1005 gst_query_unref (query);
1009 gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
1010 gst_query_unref (query);
1018 case GST_PLAY_TRICK_MODE_DEFAULT:
1019 seek_flags |= GST_SEEK_FLAG_TRICKMODE;
1021 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1022 seek_flags |= GST_SEEK_FLAG_TRICKMODE | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1024 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1025 seek_flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
1027 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1029 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1031 case GST_PLAY_TRICK_MODE_NONE:
1036 /* See if we can do an instant rate change (not changing dir) */
1037 if (mode & GST_PLAY_TRICK_MODE_INSTANT_RATE && rate * play->rate > 0) {
1038 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1039 seek_flags | GST_SEEK_FLAG_INSTANT_RATE_CHANGE,
1040 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
1041 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
1042 if (gst_element_send_event (play->playbin, seek)) {
1047 /* No instant rate change, need to do a flushing seek */
1048 seek_flags |= GST_SEEK_FLAG_FLUSH;
1050 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1051 seek_flags | GST_SEEK_FLAG_ACCURATE,
1052 /* start */ GST_SEEK_TYPE_SET, pos,
1053 /* stop */ GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1055 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1056 seek_flags | GST_SEEK_FLAG_ACCURATE,
1057 /* start */ GST_SEEK_TYPE_SET, 0,
1058 /* stop */ GST_SEEK_TYPE_SET, pos);
1060 if (!gst_element_send_event (play->playbin, seek))
1065 play->trick_mode = mode & ~GST_PLAY_TRICK_MODE_INSTANT_RATE;
1070 play_set_playback_rate (GstPlay * play, gdouble rate)
1072 GstPlayTrickMode mode = play->trick_mode;
1074 if (instant_rate_changes)
1075 mode |= GST_PLAY_TRICK_MODE_INSTANT_RATE;
1077 if (play_set_rate_and_trick_mode (play, rate, mode)) {
1078 gst_print (_("Playback rate: %.2f"), rate);
1082 gst_print (_("Could not change playback rate to %.2f"), rate);
1088 play_set_relative_playback_rate (GstPlay * play, gdouble rate_step,
1089 gboolean reverse_direction)
1091 gdouble new_rate = play->rate + rate_step;
1093 if (reverse_direction)
1096 play_set_playback_rate (play, new_rate);
1099 static const gchar *
1100 trick_mode_get_description (GstPlayTrickMode mode)
1103 case GST_PLAY_TRICK_MODE_NONE:
1104 return "normal playback, trick modes disabled";
1105 case GST_PLAY_TRICK_MODE_DEFAULT:
1106 return "trick mode: default";
1107 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1108 return "trick mode: default, no audio";
1109 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1110 return "trick mode: key frames only";
1111 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1112 return "trick mode: key frames only, no audio";
1116 return "unknown trick mode";
1120 play_switch_trick_mode (GstPlay * play)
1122 GstPlayTrickMode new_mode = ++play->trick_mode;
1123 const gchar *mode_desc;
1125 if (new_mode == GST_PLAY_TRICK_MODE_LAST)
1126 new_mode = GST_PLAY_TRICK_MODE_NONE;
1128 mode_desc = trick_mode_get_description (new_mode);
1130 if (play_set_rate_and_trick_mode (play, play->rate, new_mode)) {
1131 gst_print ("Rate: %.2f (%s) \n", play->rate,
1134 gst_print ("\nCould not change trick mode to %s.\n", mode_desc);
1139 play_get_nth_stream_in_collection (GstPlay * play, guint index,
1140 GstPlayTrackType track_type)
1142 guint len, i, n_streams = 0;
1143 GstStreamType target_type;
1145 switch (track_type) {
1146 case GST_PLAY_TRACK_TYPE_AUDIO:
1147 target_type = GST_STREAM_TYPE_AUDIO;
1149 case GST_PLAY_TRACK_TYPE_VIDEO:
1150 target_type = GST_STREAM_TYPE_VIDEO;
1152 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1153 target_type = GST_STREAM_TYPE_TEXT;
1159 len = gst_stream_collection_get_size (play->collection);
1161 for (i = 0; i < len; i++) {
1162 GstStream *stream = gst_stream_collection_get_stream (play->collection, i);
1163 GstStreamType type = gst_stream_get_stream_type (stream);
1165 if (type & target_type) {
1166 if (index == n_streams)
1177 play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type,
1180 const gchar *prop_cur, *prop_n, *prop_get, *name;
1181 gint cur = -1, n = -1;
1182 guint flag, cur_flags;
1184 /* playbin3 variables */
1185 GList *selected_streams = NULL;
1186 gint cur_audio_idx = -1, cur_video_idx = -1, cur_text_idx = -1;
1187 gint nb_audio = 0, nb_video = 0, nb_text = 0;
1190 g_mutex_lock (&play->selection_lock);
1191 if (play->is_playbin3) {
1192 if (!play->collection) {
1193 gst_print ("No stream-collection\n");
1194 g_mutex_unlock (&play->selection_lock);
1198 /* Check the total number of streams of each type */
1199 len = gst_stream_collection_get_size (play->collection);
1200 for (i = 0; i < len; i++) {
1202 gst_stream_collection_get_stream (play->collection, i);
1204 GstStreamType type = gst_stream_get_stream_type (stream);
1205 const gchar *sid = gst_stream_get_stream_id (stream);
1207 if (type & GST_STREAM_TYPE_AUDIO) {
1208 if (play->cur_audio_sid && !g_strcmp0 (play->cur_audio_sid, sid))
1209 cur_audio_idx = nb_audio;
1211 } else if (type & GST_STREAM_TYPE_VIDEO) {
1212 if (play->cur_video_sid && !g_strcmp0 (play->cur_video_sid, sid))
1213 cur_video_idx = nb_video;
1215 } else if (type & GST_STREAM_TYPE_TEXT) {
1216 if (play->cur_text_sid && !g_strcmp0 (play->cur_text_sid, sid))
1217 cur_text_idx = nb_text;
1220 gst_print ("Unknown stream type with stream-id %s", sid);
1226 switch (track_type) {
1227 case GST_PLAY_TRACK_TYPE_AUDIO:
1228 prop_get = "get-audio-tags";
1229 prop_cur = "current-audio";
1233 if (play->is_playbin3) {
1235 cur = cur_audio_idx;
1236 if (play->cur_video_sid) {
1238 g_list_append (selected_streams, play->cur_video_sid);
1240 if (play->cur_text_sid) {
1242 g_list_append (selected_streams, play->cur_text_sid);
1246 case GST_PLAY_TRACK_TYPE_VIDEO:
1247 prop_get = "get-video-tags";
1248 prop_cur = "current-video";
1252 if (play->is_playbin3) {
1254 cur = cur_video_idx;
1255 if (play->cur_audio_sid) {
1257 g_list_append (selected_streams, play->cur_audio_sid);
1259 if (play->cur_text_sid) {
1261 g_list_append (selected_streams, play->cur_text_sid);
1265 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1266 prop_get = "get-text-tags";
1267 prop_cur = "current-text";
1271 if (play->is_playbin3) {
1274 if (play->cur_audio_sid) {
1276 g_list_append (selected_streams, play->cur_audio_sid);
1278 if (play->cur_video_sid) {
1280 g_list_append (selected_streams, play->cur_video_sid);
1288 if (play->is_playbin3) {
1294 cur = (cur + 1) % (n + 1);
1299 cur = (cur - 1) % (n + 1);
1303 g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags",
1307 if (!(cur_flags & flag))
1310 cur = (cur + 1) % (n + 1);
1316 cur = (cur - 1) % (n + 1);
1321 gst_print ("No %s tracks.\n", name);
1322 g_mutex_unlock (&play->selection_lock);
1324 gchar *lcode = NULL, *lname = NULL;
1325 const gchar *lang = NULL;
1326 GstTagList *tags = NULL;
1328 if (cur >= n && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1330 gst_print ("Disabling %s. \n", name);
1331 if (play->is_playbin3) {
1332 /* Just make it empty for the track type */
1333 } else if (cur_flags & flag) {
1335 g_object_set (play->playbin, "flags", cur_flags, NULL);
1338 /* For video we only want to switch between streams, not disable it altogether */
1342 if (play->is_playbin3) {
1345 stream = play_get_nth_stream_in_collection (play, cur, track_type);
1347 selected_streams = g_list_append (selected_streams,
1348 (gchar *) gst_stream_get_stream_id (stream));
1349 tags = gst_stream_get_tags (stream);
1351 gst_print ("Collection has no stream for track %d of %d.\n",
1355 if (!(cur_flags & flag) && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1357 g_object_set (play->playbin, "flags", cur_flags, NULL);
1359 g_signal_emit_by_name (play->playbin, prop_get, cur, &tags);
1363 if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lcode))
1364 lang = gst_tag_get_language_name (lcode);
1365 else if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_NAME, &lname))
1367 gst_tag_list_unref (tags);
1370 gst_print ("Switching to %s track %d of %d (%s).\n", name, cur + 1, n,
1373 gst_print ("Switching to %s track %d of %d.\n", name, cur + 1, n);
1377 g_mutex_unlock (&play->selection_lock);
1379 if (play->is_playbin3) {
1380 if (selected_streams)
1381 gst_element_send_event (play->playbin,
1382 gst_event_new_select_streams (selected_streams));
1384 gst_print ("Can't disable all streams !\n");
1386 g_object_set (play->playbin, prop_cur, cur, NULL);
1390 if (selected_streams)
1391 g_list_free (selected_streams);
1395 print_keyboard_help (void)
1400 const gchar *key_desc;
1401 const gchar *key_help;
1402 } key_controls[] = {
1404 N_("space"), N_("pause/unpause")}, {
1405 N_("q or ESC"), N_("quit")}, {
1406 N_("> or n"), N_("play next")}, {
1407 N_("< or b"), N_("play previous")}, {
1408 "\342\206\222", N_("seek forward")}, {
1409 "\342\206\220", N_("seek backward")}, {
1410 "\342\206\221", N_("volume up")}, {
1411 "\342\206\223", N_("volume down")}, {
1412 "m", N_("toggle audio mute on/off")}, {
1413 "+", N_("increase playback rate")}, {
1414 "-", N_("decrease playback rate")}, {
1415 "d", N_("change playback direction")}, {
1416 "t", N_("enable/disable trick modes")}, {
1417 "A/a", N_("change to previous/next audio track")}, {
1418 "V/v", N_("change to previous/next video track")}, {
1419 "S/s", N_("change to previous/next subtitle track")}, {
1420 "0", N_("seek to beginning")}, {
1421 "k", N_("show keyboard shortcuts")},};
1423 guint i, chars_to_pad, desc_len, max_desc_len = 0;
1425 gst_print ("\n\n%s\n\n", _("Interactive mode - keyboard controls:"));
1427 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1428 desc_len = g_utf8_strlen (key_controls[i].key_desc, -1);
1429 max_desc_len = MAX (max_desc_len, desc_len);
1433 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1434 chars_to_pad = max_desc_len - g_utf8_strlen (key_controls[i].key_desc, -1);
1435 gst_print ("\t%s", key_controls[i].key_desc);
1436 gst_print ("%-*s: ", chars_to_pad, "");
1437 gst_print ("%s\n", key_controls[i].key_help);
1443 keyboard_cb (const gchar * key_input, gpointer user_data)
1445 GstPlay *play = (GstPlay *) user_data;
1448 /* Switch on the first char for single char inputs,
1449 * otherwise leave key = '\0' to fall through to
1450 * the default case below */
1451 if (key_input[0] != '\0' && key_input[1] == '\0') {
1457 print_keyboard_help ();
1460 toggle_paused (play);
1464 g_main_loop_quit (play->loop);
1468 if (!play_next (play)) {
1469 gst_print ("\n%s\n", _("Reached end of play list."));
1470 g_main_loop_quit (play->loop);
1478 if (play->rate > -0.2 && play->rate < 0.0)
1479 play_set_relative_playback_rate (play, 0.0, TRUE);
1480 else if (ABS (play->rate) < 2.0)
1481 play_set_relative_playback_rate (play, 0.1, FALSE);
1482 else if (ABS (play->rate) < 4.0)
1483 play_set_relative_playback_rate (play, 0.5, FALSE);
1485 play_set_relative_playback_rate (play, 1.0, FALSE);
1488 if (play->rate > 0.0 && play->rate < 0.20)
1489 play_set_relative_playback_rate (play, 0.0, TRUE);
1490 else if (ABS (play->rate) <= 2.0)
1491 play_set_relative_playback_rate (play, -0.1, FALSE);
1492 else if (ABS (play->rate) <= 4.0)
1493 play_set_relative_playback_rate (play, -0.5, FALSE);
1495 play_set_relative_playback_rate (play, -1.0, FALSE);
1498 play_set_relative_playback_rate (play, 0.0, TRUE);
1501 play_switch_trick_mode (play);
1504 if (key_input[1] == '\0') {
1505 g_main_loop_quit (play->loop);
1510 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO, key == 'a');
1514 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO, key == 'v');
1518 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE,
1522 play_do_seek (play, 0, play->rate, play->trick_mode);
1525 play_toggle_audio_mute (play);
1528 if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
1529 relative_seek (play, +0.08);
1530 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
1531 relative_seek (play, -0.01);
1532 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
1533 play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
1534 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
1535 play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
1537 GST_INFO ("keyboard input:");
1538 for (; *key_input != '\0'; ++key_input)
1539 GST_INFO (" code %3d", *key_input);
1547 enable_winmm_timer_resolution (void)
1550 guint resolution = 0;
1553 res = timeGetDevCaps (&time_caps, sizeof (TIMECAPS));
1554 if (res != TIMERR_NOERROR) {
1555 g_warning ("timeGetDevCaps() returned non-zero code %d", res);
1559 resolution = MIN (MAX (time_caps.wPeriodMin, 1), time_caps.wPeriodMax);
1560 res = timeBeginPeriod (resolution);
1561 if (res != TIMERR_NOERROR) {
1562 g_warning ("timeBeginPeriod() returned non-zero code %d", res);
1566 gst_println (_("Use Windows high-resolution clock, precision: %u ms\n"),
1573 clear_winmm_timer_resolution (guint resolution)
1575 if (resolution == 0)
1578 timeEndPeriod (resolution);
1583 main (int argc, char **argv)
1586 GPtrArray *playlist;
1587 gboolean verbose = FALSE;
1588 gboolean print_version = FALSE;
1589 gboolean interactive = TRUE;
1590 gboolean gapless = FALSE;
1591 gboolean shuffle = FALSE;
1592 gdouble volume = -1;
1593 gdouble start_position = 0;
1594 gchar **filenames = NULL;
1595 gchar *audio_sink = NULL;
1596 gchar *video_sink = NULL;
1598 gchar *flags = NULL;
1601 GOptionContext *ctx;
1602 gchar *playlist_file = NULL;
1603 gboolean use_playbin3 = FALSE;
1605 guint winmm_timer_resolution = 0;
1607 GOptionEntry options[] = {
1608 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
1609 N_("Output status information and property notifications"), NULL},
1610 {"flags", 0, 0, G_OPTION_ARG_STRING, &flags,
1611 N_("Control playback behaviour setting playbin 'flags' property"),
1613 {"version", 0, 0, G_OPTION_ARG_NONE, &print_version,
1614 N_("Print version information and exit"), NULL},
1615 {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink,
1616 N_("Video sink to use (default is autovideosink)"), NULL},
1617 {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink,
1618 N_("Audio sink to use (default is autoaudiosink)"), NULL},
1619 {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless,
1620 N_("Enable gapless playback"), NULL},
1621 {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
1622 N_("Shuffle playlist"), NULL},
1623 {"no-interactive", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1625 N_("Disable interactive control via the keyboard"), NULL},
1626 {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume,
1627 N_("Volume"), NULL},
1628 {"start-position", 's', 0, G_OPTION_ARG_DOUBLE, &start_position,
1629 N_("Start position in seconds."), NULL},
1630 {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file,
1631 N_("Playlist file containing input media files"), NULL},
1632 {"instant-rate-changes", 'i', 0, G_OPTION_ARG_NONE, &instant_rate_changes,
1634 ("Use the experimental instant-rate-change flag when changing rate"),
1636 {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
1637 N_("Do not print any output (apart from errors)"), NULL},
1638 {"use-playbin3", 0, 0, G_OPTION_ARG_NONE, &use_playbin3,
1639 N_("Use playbin3 pipeline")
1640 N_("(default varies depending on 'USE_PLAYBIN' env variable)"),
1642 {"wait-on-eos", 0, 0, G_OPTION_ARG_NONE, &wait_on_eos,
1644 ("Keep showing the last frame on EOS until quit or playlist change command "
1645 "(gapless is ignored)"),
1647 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
1651 setlocale (LC_ALL, "");
1654 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1655 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1656 textdomain (GETTEXT_PACKAGE);
1659 g_set_prgname ("gst-play-" GST_API_VERSION);
1660 /* Ensure XInitThreads() is called if/when needed */
1661 g_setenv ("GST_GL_XINITTHREADS", "1", TRUE);
1662 g_setenv ("GST_XINITTHREADS", "1", TRUE);
1664 ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...");
1665 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1666 g_option_context_add_group (ctx, gst_init_get_option_group ());
1667 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1668 gst_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
1669 g_option_context_free (ctx);
1670 g_clear_error (&err);
1673 g_option_context_free (ctx);
1675 GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play");
1677 if (print_version) {
1680 version_str = gst_version_string ();
1681 gst_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION);
1682 gst_print ("%s\n", version_str);
1683 gst_print ("%s\n", GST_PACKAGE_ORIGIN);
1684 g_free (version_str);
1686 g_free (audio_sink);
1687 g_free (video_sink);
1688 g_free (playlist_file);
1696 playlist = g_ptr_array_new ();
1698 if (playlist_file != NULL) {
1699 gchar *playlist_contents = NULL;
1700 gchar **lines = NULL;
1702 if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) {
1703 lines = g_strsplit (playlist_contents, "\n", 0);
1704 num = g_strv_length (lines);
1706 for (i = 0; i < num; i++) {
1707 if (lines[i][0] != '\0') {
1708 GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]);
1709 add_to_playlist (playlist, lines[i]);
1713 g_free (playlist_contents);
1715 gst_printerr ("Could not read playlist: %s\n", err->message);
1716 g_clear_error (&err);
1718 g_free (playlist_file);
1719 playlist_file = NULL;
1722 if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) {
1723 gst_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."),
1724 "gst-play-" GST_API_VERSION);
1725 gst_printerr ("\n\n"),
1726 gst_printerr ("%s\n\n",
1727 _("You must provide at least one filename or URI to play."));
1728 /* No input provided. Free array */
1729 g_ptr_array_free (playlist, TRUE);
1731 g_free (audio_sink);
1732 g_free (video_sink);
1738 if (filenames != NULL && *filenames != NULL) {
1739 num = g_strv_length (filenames);
1740 for (i = 0; i < num; ++i) {
1741 GST_LOG ("command line argument: %s", filenames[i]);
1742 add_to_playlist (playlist, filenames[i]);
1744 g_strfreev (filenames);
1747 num = playlist->len;
1748 g_ptr_array_add (playlist, NULL);
1750 uris = (gchar **) g_ptr_array_free (playlist, FALSE);
1753 shuffle_uris (uris, num);
1756 play = play_new (uris, audio_sink, video_sink, gapless, volume, verbose,
1757 flags, use_playbin3, start_position);
1761 ("Failed to create 'playbin' element. Check your GStreamer installation.\n");
1762 return EXIT_FAILURE;
1765 /* Enable high-precision clock which will improve accuracy of various
1766 * Windows timer APIs (e.g., Sleep()), and it will increase the precision
1767 * of GstSystemClock as well
1770 /* NOTE: Once timer resolution is updated via timeBeginPeriod(),
1771 * application should undo it by calling timeEndPeriod()
1773 * Prior to Windows 10, version 2004, timeBeginPeriod() affects global
1774 * Windows setting (meaning that it will affect other processes),
1775 * but starting with Windows 10, version 2004, this function no longer
1776 * affects global timer resolution
1778 winmm_timer_resolution = enable_winmm_timer_resolution ();
1782 if (gst_play_kb_set_key_handler (keyboard_cb, play)) {
1783 gst_print (_("Press 'k' to see a list of keyboard shortcuts.\n"));
1784 atexit (restore_terminal);
1786 gst_print ("Interactive keyboard handling in terminal not available.\n");
1794 /* Undo timeBeginPeriod() if required */
1795 clear_winmm_timer_resolution (winmm_timer_resolution);
1801 g_free (audio_sink);
1802 g_free (video_sink);