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
49 #include <TargetConditionals.h>
52 #include "gst-play-kb.h"
54 #define VOLUME_STEPS 20
56 static gboolean wait_on_eos = FALSE;
58 GST_DEBUG_CATEGORY (play_debug);
59 #define GST_CAT_DEFAULT play_debug
63 GST_PLAY_TRICK_MODE_NONE = 0,
64 GST_PLAY_TRICK_MODE_DEFAULT,
65 GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO,
66 GST_PLAY_TRICK_MODE_KEY_UNITS,
67 GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO,
68 GST_PLAY_TRICK_MODE_LAST,
70 /* The instant-rate setting is a flag,
71 * applied on top of the trick-mode enum value.
72 * It needs to have a 2^n value bigger than
73 * any of the enum values so setting it
74 * won't affect the trickmode value */
75 GST_PLAY_TRICK_MODE_INSTANT_RATE = (1 << 3)
80 GST_PLAY_TRACK_TYPE_INVALID = 0,
81 GST_PLAY_TRACK_TYPE_AUDIO,
82 GST_PLAY_TRACK_TYPE_VIDEO,
83 GST_PLAY_TRACK_TYPE_SUBTITLE
94 /* playbin3 variables */
96 GstStreamCollection *collection;
100 GMutex selection_lock;
106 /* missing plugin messages */
111 gboolean initial_file;
113 GstState desired_state; /* as per user interaction, PAUSED or PLAYING */
115 gulong deep_notify_id;
119 gboolean instant_uri;
121 GstPlayTrickMode trick_mode;
123 gdouble start_position;
125 /* keyboard state tracking */
126 gboolean shift_pressed;
129 static gboolean quiet = FALSE;
130 static gboolean instant_rate_changes = FALSE;
132 static gboolean play_bus_msg (GstBus * bus, GstMessage * msg, gpointer data);
133 static gboolean play_next (GstPlay * play);
134 static gboolean play_prev (GstPlay * play);
135 static gboolean play_timeout (gpointer user_data);
136 static void play_about_to_finish (GstElement * playbin, gpointer user_data);
137 static void play_reset (GstPlay * play);
138 static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
139 static gboolean play_do_seek (GstPlay * play, gint64 pos, gdouble rate,
140 GstPlayTrickMode mode);
143 static void gst_play_printf (const gchar * format, ...) G_GNUC_PRINTF (1, 2);
146 static void keyboard_cb (const gchar * key_input, gpointer user_data);
147 static void relative_seek (GstPlay * play, gdouble percent);
150 gst_play_printf (const gchar * format, ...)
159 va_start (args, format);
161 len = g_vasprintf (&str, format, args);
165 if (len > 0 && str != NULL)
166 gst_print ("%s", str);
171 #define gst_print gst_play_printf
174 play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
175 gboolean gapless, gboolean instant_uri, gdouble initial_volume,
176 gboolean verbose, const gchar * flags_string, gboolean use_playbin3,
177 gdouble start_position, gboolean no_position)
179 GstElement *sink, *playbin;
184 playbin = gst_element_factory_make ("playbin3", "playbin");
186 playbin = gst_element_factory_make ("playbin", "playbin");
192 play = g_new0 (GstPlay, 1);
195 play->num_uris = g_strv_length (uris);
198 play->playbin = playbin;
201 play->is_playbin3 = TRUE;
203 const gchar *env = g_getenv ("USE_PLAYBIN3");
204 if (env && g_str_has_prefix (env, "1"))
205 play->is_playbin3 = TRUE;
208 g_mutex_init (&play->selection_lock);
210 if (audio_sink != NULL) {
211 if (strchr (audio_sink, ' ') != NULL)
212 sink = gst_parse_bin_from_description (audio_sink, TRUE, NULL);
214 sink = gst_element_factory_make (audio_sink, NULL);
217 g_object_set (play->playbin, "audio-sink", sink, NULL);
219 g_warning ("Couldn't create specified audio sink '%s'", audio_sink);
221 if (video_sink != NULL) {
222 if (strchr (video_sink, ' ') != NULL)
223 sink = gst_parse_bin_from_description (video_sink, TRUE, NULL);
225 sink = gst_element_factory_make (video_sink, NULL);
228 g_object_set (play->playbin, "video-sink", sink, NULL);
230 g_warning ("Couldn't create specified video sink '%s'", video_sink);
233 if (flags_string != NULL) {
238 g_object_class_find_property (G_OBJECT_GET_CLASS (playbin), "flags");
239 g_value_init (&val, pspec->value_type);
240 if (gst_value_deserialize (&val, flags_string))
241 g_object_set_property (G_OBJECT (play->playbin), "flags", &val);
243 gst_printerr ("Couldn't convert '%s' to playbin flags!\n", flags_string);
244 g_value_unset (&val);
248 play->deep_notify_id =
249 gst_element_add_property_deep_notify_watch (play->playbin, NULL, TRUE);
252 play->loop = g_main_loop_new (NULL, FALSE);
254 play->bus_watch = gst_bus_add_watch (GST_ELEMENT_BUS (play->playbin),
258 play->timeout = g_timeout_add (100, play_timeout, play);
261 play->missing = NULL;
262 play->buffering = FALSE;
263 play->is_live = FALSE;
265 play->desired_state = GST_STATE_PLAYING;
267 play->gapless = gapless;
269 g_signal_connect (play->playbin, "about-to-finish",
270 G_CALLBACK (play_about_to_finish), play);
273 play->initial_file = TRUE;
275 play->instant_uri = instant_uri;
276 g_object_set (G_OBJECT (play->playbin), "instant-uri", instant_uri, NULL);
278 if (initial_volume != -1)
279 play_set_relative_volume (play, initial_volume - 1.0);
282 play->trick_mode = GST_PLAY_TRICK_MODE_NONE;
283 play->start_position = start_position;
288 play_free (GstPlay * play)
290 /* No need to see all those pad caps going to NULL etc., it's just noise */
291 if (play->deep_notify_id != 0)
292 g_signal_handler_disconnect (play->playbin, play->deep_notify_id);
296 gst_element_set_state (play->playbin, GST_STATE_NULL);
297 gst_object_unref (play->playbin);
299 g_source_remove (play->bus_watch);
300 if (play->timeout != 0)
301 g_source_remove (play->timeout);
302 g_main_loop_unref (play->loop);
304 g_strfreev (play->uris);
306 if (play->collection)
307 gst_object_unref (play->collection);
308 g_free (play->cur_audio_sid);
309 g_free (play->cur_video_sid);
310 g_free (play->cur_text_sid);
312 g_mutex_clear (&play->selection_lock);
317 /* reset for new file/stream */
319 play_reset (GstPlay * play)
321 g_list_foreach (play->missing, (GFunc) gst_message_unref, NULL);
322 play->missing = NULL;
324 play->buffering = FALSE;
325 play->is_live = FALSE;
329 play_set_relative_volume (GstPlay * play, gdouble volume_step)
333 volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (play->playbin),
334 GST_STREAM_VOLUME_FORMAT_CUBIC);
336 volume = round ((volume + volume_step) * VOLUME_STEPS) / VOLUME_STEPS;
337 volume = CLAMP (volume, 0.0, 10.0);
339 gst_stream_volume_set_volume (GST_STREAM_VOLUME (play->playbin),
340 GST_STREAM_VOLUME_FORMAT_CUBIC, volume);
342 gst_print (_("Volume: %.0f%%"), volume * 100);
347 play_toggle_audio_mute (GstPlay * play)
351 mute = gst_stream_volume_get_mute (GST_STREAM_VOLUME (play->playbin));
354 gst_stream_volume_set_mute (GST_STREAM_VOLUME (play->playbin), mute);
357 gst_print (_("Mute: on"));
359 gst_print (_("Mute: off"));
363 /* returns TRUE if something was installed and we should restart playback */
365 play_install_missing_plugins (GstPlay * play)
367 /* FIXME: implement: try to install any missing plugins we haven't
368 * tried to install before */
373 play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data)
375 GstPlay *play = user_data;
377 switch (GST_MESSAGE_TYPE (msg)) {
378 case GST_MESSAGE_ASYNC_DONE:
380 /* dump graph on preroll */
381 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
382 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.async-done");
384 gst_print ("Prerolled.\r");
385 if (play->missing != NULL && play_install_missing_plugins (play)) {
386 gst_print ("New plugins installed, trying again...\n");
390 if (play->start_position > 0.0) {
391 play_do_seek (play, play->start_position * GST_SECOND,
392 play->rate, play->trick_mode);
393 play->start_position = 0;
396 case GST_MESSAGE_BUFFERING:{
399 if (!play->buffering)
402 gst_message_parse_buffering (msg, &percent);
403 gst_print ("%s %d%% \r", _("Buffering..."), percent);
405 if (percent == 100) {
406 /* a 100% message means buffering is done */
407 if (play->buffering) {
408 play->buffering = FALSE;
409 /* no state management needed for live pipelines */
411 gst_element_set_state (play->playbin, play->desired_state);
415 if (!play->buffering) {
417 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
418 play->buffering = TRUE;
423 case GST_MESSAGE_CLOCK_LOST:{
424 gst_print (_("Clock lost, selecting a new one\n"));
425 gst_element_set_state (play->playbin, GST_STATE_PAUSED);
426 gst_element_set_state (play->playbin, GST_STATE_PLAYING);
429 case GST_MESSAGE_LATENCY:
430 gst_print ("Redistribute latency...\n");
431 gst_bin_recalculate_latency (GST_BIN (play->playbin));
433 case GST_MESSAGE_REQUEST_STATE:{
437 name = gst_object_get_path_string (GST_MESSAGE_SRC (msg));
439 gst_message_parse_request_state (msg, &state);
441 gst_print ("Setting state to %s as requested by %s...\n",
442 gst_element_state_get_name (state), name);
444 gst_element_set_state (play->playbin, state);
448 case GST_MESSAGE_EOS:
449 /* print final position at end */
452 /* and switch to next item in list */
453 if (!wait_on_eos && !play_next (play)) {
454 gst_print ("%s\n", _("Reached end of play list."));
455 g_main_loop_quit (play->loop);
458 case GST_MESSAGE_WARNING:{
462 /* dump graph on warning */
463 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
464 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.warning");
466 gst_message_parse_warning (msg, &err, &dbg);
467 gst_printerr ("WARNING %s\n", err->message);
469 gst_printerr ("WARNING debug information: %s\n", dbg);
470 g_clear_error (&err);
474 case GST_MESSAGE_ERROR:{
478 /* dump graph on error */
479 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin),
480 GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.error");
482 gst_message_parse_error (msg, &err, &dbg);
483 gst_printerr ("ERROR %s for %s\n", err->message,
484 play->uris[play->cur_idx]);
486 gst_printerr ("ERROR debug information: %s\n", dbg);
487 g_clear_error (&err);
490 /* flush any other error messages from the bus and clean up */
491 gst_element_set_state (play->playbin, GST_STATE_NULL);
493 if (play->missing != NULL && play_install_missing_plugins (play)) {
494 gst_print ("New plugins installed, trying again...\n");
499 /* try next item in list then */
500 if (!play_next (play)) {
501 gst_print ("%s\n", _("Reached end of play list."));
502 g_main_loop_quit (play->loop);
506 case GST_MESSAGE_ELEMENT:
508 GstNavigationMessageType mtype = gst_navigation_message_get_type (msg);
509 if (mtype == GST_NAVIGATION_MESSAGE_EVENT) {
512 if (gst_navigation_message_parse_event (msg, &ev)) {
513 GstNavigationEventType e_type = gst_navigation_event_get_type (ev);
515 case GST_NAVIGATION_EVENT_KEY_PRESS:
518 const gchar *key_input;
519 gchar key_adjusted[2];
521 if (gst_navigation_event_parse_key_event (ev, &key)) {
522 GST_INFO ("Key press: %s", key);
524 if (strcmp (key, "Left") == 0)
525 key = GST_PLAY_KB_ARROW_LEFT;
526 else if (strcmp (key, "Right") == 0)
527 key = GST_PLAY_KB_ARROW_RIGHT;
528 else if (strcmp (key, "Up") == 0)
529 key = GST_PLAY_KB_ARROW_UP;
530 else if (strcmp (key, "Down") == 0)
531 key = GST_PLAY_KB_ARROW_DOWN;
532 else if (strncmp (key, "Shift", 5) == 0) {
533 play->shift_pressed = TRUE;
535 } else if (strcmp (key, "space") == 0 ||
536 strcmp (key, "Space") == 0) {
538 } else if (strcmp (key, "minus") == 0) {
540 } else if (strcmp (key, "plus") == 0
541 /* TODO: That's not universally correct at all, but still handy */
542 || (strcmp (key, "equal") == 0 && play->shift_pressed)) {
544 } else if (strlen (key) > 1) {
548 /* In the case of a simple single-char input,
549 * make it lower or upper as needed, and
550 * send that instead */
551 if (key[0] != '\0' && key[1] == '\0') {
552 if (play->shift_pressed)
553 key_adjusted[0] = g_ascii_toupper (key[0]);
555 key_adjusted[0] = g_ascii_tolower (key[0]);
556 key_adjusted[1] = '\0';
557 key_input = key_adjusted;
562 keyboard_cb (key_input, user_data);
566 case GST_NAVIGATION_EVENT_KEY_RELEASE:
570 if (gst_navigation_event_parse_key_event (ev, &key)) {
571 GST_INFO ("Key release: %s", key);
572 if (strncmp (key, "Shift", 5) == 0) {
573 play->shift_pressed = FALSE;
578 case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS:
581 if (gst_navigation_event_parse_mouse_button_event (ev, &button,
585 relative_seek (play, +0.08);
586 } else if (button == 5) {
588 relative_seek (play, -0.01);
598 gst_event_unref (ev);
602 case GST_MESSAGE_PROPERTY_NOTIFY:{
606 gchar *val_str = NULL;
609 gst_message_parse_property_notify (msg, &obj, &name, &val);
611 obj_name = gst_object_get_path_string (GST_OBJECT (obj));
613 if (G_VALUE_HOLDS_STRING (val))
614 val_str = g_value_dup_string (val);
615 else if (G_VALUE_TYPE (val) == GST_TYPE_CAPS)
616 val_str = gst_caps_to_string (g_value_get_boxed (val));
617 else if (G_VALUE_TYPE (val) == GST_TYPE_TAG_LIST)
618 val_str = gst_tag_list_to_string (g_value_get_boxed (val));
620 val_str = gst_value_serialize (val);
622 val_str = g_strdup ("(no value)");
625 gst_play_printf ("%s: %s = %s\n", obj_name, name, val_str);
630 case GST_MESSAGE_STREAM_COLLECTION:
632 GstStreamCollection *collection = NULL;
633 gst_message_parse_stream_collection (msg, &collection);
636 g_mutex_lock (&play->selection_lock);
637 if (play->collection)
638 gst_object_unref (play->collection);
639 play->collection = collection;
640 g_mutex_unlock (&play->selection_lock);
644 case GST_MESSAGE_STREAMS_SELECTED:
646 GstStreamCollection *collection = NULL;
649 gst_message_parse_streams_selected (msg, &collection);
651 g_mutex_lock (&play->selection_lock);
652 gst_object_replace ((GstObject **) & play->collection,
653 (GstObject *) collection);
655 /* Free all last stream-ids */
656 g_free (play->cur_audio_sid);
657 g_free (play->cur_video_sid);
658 g_free (play->cur_text_sid);
659 play->cur_audio_sid = NULL;
660 play->cur_video_sid = NULL;
661 play->cur_text_sid = NULL;
663 len = gst_message_streams_selected_get_size (msg);
664 for (i = 0; i < len; i++) {
665 GstStream *stream = gst_message_streams_selected_get_stream (msg, i);
667 GstStreamType type = gst_stream_get_stream_type (stream);
668 const gchar *stream_id = gst_stream_get_stream_id (stream);
670 if (type & GST_STREAM_TYPE_AUDIO) {
671 play->cur_audio_sid = g_strdup (stream_id);
672 } else if (type & GST_STREAM_TYPE_VIDEO) {
673 play->cur_video_sid = g_strdup (stream_id);
674 } else if (type & GST_STREAM_TYPE_TEXT) {
675 play->cur_text_sid = g_strdup (stream_id);
677 gst_print ("Unknown stream type with stream-id %s\n", stream_id);
679 gst_object_unref (stream);
683 gst_object_unref (collection);
684 g_mutex_unlock (&play->selection_lock);
689 if (gst_is_missing_plugin_message (msg)) {
692 desc = gst_missing_plugin_message_get_description (msg);
693 gst_print ("Missing plugin: %s\n", desc);
695 play->missing = g_list_append (play->missing, gst_message_ref (msg));
704 play_timeout (gpointer user_data)
706 GstPlay *play = user_data;
707 gint64 pos = -1, dur = -1;
708 const gchar *paused = _("Paused");
714 gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos);
715 gst_element_query_duration (play->playbin, GST_FORMAT_TIME, &dur);
717 if (play->desired_state == GST_STATE_PAUSED) {
718 status = (gchar *) paused;
720 gint len = g_utf8_strlen (paused, -1);
721 status = g_newa (gchar, len + 1);
722 memset (status, ' ', len);
727 gchar dstr[32], pstr[32];
729 /* FIXME: pretty print in nicer format */
730 g_snprintf (pstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (pos));
732 g_snprintf (dstr, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (dur));
734 gst_print ("%s / %s %s\r", pstr, dstr, status);
741 play_uri_get_display_name (GstPlay * play, const gchar * uri)
745 if (gst_uri_has_protocol (uri, "file")) {
746 loc = g_filename_from_uri (uri, NULL, NULL);
747 } else if (gst_uri_has_protocol (uri, "pushfile")) {
748 loc = g_filename_from_uri (uri + 4, NULL, NULL);
750 loc = g_strdup (uri);
753 /* Maybe additionally use glib's filename to display name function */
758 play_uri (GstPlay * play, const gchar * next_uri)
762 if (!play->instant_uri || play->initial_file)
763 gst_element_set_state (play->playbin, GST_STATE_READY);
766 loc = play_uri_get_display_name (play, next_uri);
767 gst_print (_("Now playing %s\n"), loc);
770 g_object_set (play->playbin, "uri", next_uri, NULL);
772 if (!play->instant_uri || play->initial_file) {
773 switch (gst_element_set_state (play->playbin, GST_STATE_PAUSED)) {
774 case GST_STATE_CHANGE_FAILURE:
775 /* ignore, we should get an error message posted on the bus */
777 case GST_STATE_CHANGE_NO_PREROLL:
778 gst_print ("Pipeline is live.\n");
779 play->is_live = TRUE;
781 case GST_STATE_CHANGE_ASYNC:
782 gst_print ("Prerolling...\r");
788 if (play->desired_state != GST_STATE_PAUSED)
789 gst_element_set_state (play->playbin, play->desired_state);
791 play->initial_file = FALSE;
794 /* returns FALSE if we have reached the end of the playlist */
796 play_next (GstPlay * play)
798 if ((play->cur_idx + 1) >= play->num_uris)
801 play_uri (play, play->uris[++play->cur_idx]);
805 /* returns FALSE if we have reached the beginning of the playlist */
807 play_prev (GstPlay * play)
809 if (play->cur_idx == 0 || play->num_uris <= 1)
812 play_uri (play, play->uris[--play->cur_idx]);
817 play_about_to_finish (GstElement * playbin, gpointer user_data)
819 GstPlay *play = user_data;
820 const gchar *next_uri;
827 next_idx = play->cur_idx + 1;
828 if (next_idx >= play->num_uris)
831 next_uri = play->uris[next_idx];
832 loc = play_uri_get_display_name (play, next_uri);
833 gst_print (_("About to finish, preparing next title: %s"), loc);
837 g_object_set (play->playbin, "uri", next_uri, NULL);
838 play->cur_idx = next_idx;
842 do_play (GstPlay * play)
847 for (i = 0; i < play->num_uris; ++i)
848 GST_INFO ("%4u : %s", i, play->uris[i]);
850 if (!play_next (play))
853 g_main_loop_run (play->loop);
857 compare (gconstpointer a, gconstpointer b)
862 a1 = g_utf8_collate_key_for_filename ((gchar *) a, -1);
863 b1 = g_utf8_collate_key_for_filename ((gchar *) b, -1);
864 ret = strcmp (a1, b1);
872 add_to_playlist (GPtrArray * playlist, const gchar * filename)
877 if (gst_uri_is_valid (filename)) {
878 g_ptr_array_add (playlist, g_strdup (filename));
882 if ((dir = g_dir_open (filename, 0, NULL))) {
884 GList *l, *files = NULL;
886 while ((entry = g_dir_read_name (dir))) {
889 path = g_build_filename (filename, entry, NULL);
890 files = g_list_insert_sorted (files, path, compare);
895 for (l = files; l != NULL; l = l->next) {
896 gchar *path = (gchar *) l->data;
898 add_to_playlist (playlist, path);
905 uri = gst_filename_to_uri (filename, NULL);
907 g_ptr_array_add (playlist, uri);
909 g_warning ("Could not make URI out of filename '%s'", filename);
913 shuffle_uris (gchar ** uris, guint num)
921 for (i = num - 1; i >= 1; i--) {
922 /* +1 because number returned will be in range [a;b[ so excl. stop */
923 j = g_random_int_range (0, i + 1);
931 restore_terminal (void)
933 gst_play_kb_set_key_handler (NULL, NULL);
937 toggle_paused (GstPlay * play)
939 if (play->desired_state == GST_STATE_PLAYING)
940 play->desired_state = GST_STATE_PAUSED;
942 play->desired_state = GST_STATE_PLAYING;
944 if (!play->buffering) {
945 gst_element_set_state (play->playbin, play->desired_state);
946 } else if (play->desired_state == GST_STATE_PLAYING) {
947 gst_print ("\nWill play as soon as buffering finishes)\n");
952 relative_seek (GstPlay * play, gdouble percent)
955 gboolean seekable = FALSE;
956 gint64 dur = -1, pos = -1, step;
958 g_return_if_fail (percent >= -1.0 && percent <= 1.0);
960 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
963 query = gst_query_new_seeking (GST_FORMAT_TIME);
964 if (!gst_element_query (play->playbin, query)) {
965 gst_query_unref (query);
969 gst_query_parse_seeking (query, NULL, &seekable, NULL, &dur);
970 gst_query_unref (query);
972 if (!seekable || dur <= 0)
975 step = dur * percent;
976 if (ABS (step) < GST_SECOND)
977 step = (percent < 0) ? -GST_SECOND : GST_SECOND;
981 if (!play_next (play)) {
982 gst_print ("\n%s\n", _("Reached end of play list."));
983 g_main_loop_quit (play->loop);
989 play_do_seek (play, pos, play->rate, play->trick_mode);
996 gst_print ("\nCould not seek.\n");
1001 play_set_rate_and_trick_mode (GstPlay * play, gdouble rate,
1002 GstPlayTrickMode mode)
1006 g_return_val_if_fail (rate != 0, FALSE);
1008 if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
1011 return play_do_seek (play, pos, rate, mode);
1015 play_do_seek (GstPlay * play, gint64 pos, gdouble rate, GstPlayTrickMode mode)
1017 GstSeekFlags seek_flags;
1020 gboolean seekable = FALSE;
1022 query = gst_query_new_seeking (GST_FORMAT_TIME);
1023 if (!gst_element_query (play->playbin, query)) {
1024 gst_query_unref (query);
1028 gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
1029 gst_query_unref (query);
1037 case GST_PLAY_TRICK_MODE_DEFAULT:
1038 seek_flags |= GST_SEEK_FLAG_TRICKMODE;
1040 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1041 seek_flags |= GST_SEEK_FLAG_TRICKMODE | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1043 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1044 seek_flags |= GST_SEEK_FLAG_TRICKMODE_KEY_UNITS;
1046 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1048 GST_SEEK_FLAG_TRICKMODE_KEY_UNITS | GST_SEEK_FLAG_TRICKMODE_NO_AUDIO;
1050 case GST_PLAY_TRICK_MODE_NONE:
1055 /* See if we can do an instant rate change (not changing dir) */
1056 if (mode & GST_PLAY_TRICK_MODE_INSTANT_RATE && rate * play->rate > 0) {
1057 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1058 seek_flags | GST_SEEK_FLAG_INSTANT_RATE_CHANGE,
1059 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE,
1060 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
1061 if (gst_element_send_event (play->playbin, seek)) {
1066 /* No instant rate change, need to do a flushing seek */
1067 seek_flags |= GST_SEEK_FLAG_FLUSH;
1069 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1070 seek_flags | GST_SEEK_FLAG_ACCURATE,
1071 /* start */ GST_SEEK_TYPE_SET, pos,
1072 /* stop */ GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1074 seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
1075 seek_flags | GST_SEEK_FLAG_ACCURATE,
1076 /* start */ GST_SEEK_TYPE_SET, 0,
1077 /* stop */ GST_SEEK_TYPE_SET, pos);
1079 if (!gst_element_send_event (play->playbin, seek))
1084 play->trick_mode = mode & ~GST_PLAY_TRICK_MODE_INSTANT_RATE;
1089 play_set_playback_rate (GstPlay * play, gdouble rate)
1091 GstPlayTrickMode mode = play->trick_mode;
1093 if (instant_rate_changes)
1094 mode |= GST_PLAY_TRICK_MODE_INSTANT_RATE;
1096 if (play_set_rate_and_trick_mode (play, rate, mode)) {
1097 gst_print (_("Playback rate: %.2f"), rate);
1101 gst_print (_("Could not change playback rate to %.2f"), rate);
1107 play_set_relative_playback_rate (GstPlay * play, gdouble rate_step,
1108 gboolean reverse_direction)
1110 gdouble new_rate = play->rate + rate_step;
1112 if (reverse_direction)
1115 play_set_playback_rate (play, new_rate);
1118 static const gchar *
1119 trick_mode_get_description (GstPlayTrickMode mode)
1122 case GST_PLAY_TRICK_MODE_NONE:
1123 return "normal playback, trick modes disabled";
1124 case GST_PLAY_TRICK_MODE_DEFAULT:
1125 return "trick mode: default";
1126 case GST_PLAY_TRICK_MODE_DEFAULT_NO_AUDIO:
1127 return "trick mode: default, no audio";
1128 case GST_PLAY_TRICK_MODE_KEY_UNITS:
1129 return "trick mode: key frames only";
1130 case GST_PLAY_TRICK_MODE_KEY_UNITS_NO_AUDIO:
1131 return "trick mode: key frames only, no audio";
1135 return "unknown trick mode";
1139 play_switch_trick_mode (GstPlay * play)
1141 GstPlayTrickMode new_mode = ++play->trick_mode;
1142 const gchar *mode_desc;
1144 if (new_mode == GST_PLAY_TRICK_MODE_LAST)
1145 new_mode = GST_PLAY_TRICK_MODE_NONE;
1147 mode_desc = trick_mode_get_description (new_mode);
1149 if (play_set_rate_and_trick_mode (play, play->rate, new_mode)) {
1150 gst_print ("Rate: %.2f (%s) \n", play->rate,
1153 gst_print ("\nCould not change trick mode to %s.\n", mode_desc);
1158 play_get_nth_stream_in_collection (GstPlay * play, guint index,
1159 GstPlayTrackType track_type)
1161 guint len, i, n_streams = 0;
1162 GstStreamType target_type;
1164 switch (track_type) {
1165 case GST_PLAY_TRACK_TYPE_AUDIO:
1166 target_type = GST_STREAM_TYPE_AUDIO;
1168 case GST_PLAY_TRACK_TYPE_VIDEO:
1169 target_type = GST_STREAM_TYPE_VIDEO;
1171 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1172 target_type = GST_STREAM_TYPE_TEXT;
1178 len = gst_stream_collection_get_size (play->collection);
1180 for (i = 0; i < len; i++) {
1181 GstStream *stream = gst_stream_collection_get_stream (play->collection, i);
1182 GstStreamType type = gst_stream_get_stream_type (stream);
1184 if (type & target_type) {
1185 if (index == n_streams)
1196 play_cycle_track_selection (GstPlay * play, GstPlayTrackType track_type,
1199 const gchar *prop_cur, *prop_n, *prop_get, *name;
1200 gint cur = -1, n = -1;
1201 guint flag, cur_flags;
1203 /* playbin3 variables */
1204 GList *selected_streams = NULL;
1205 gint cur_audio_idx = -1, cur_video_idx = -1, cur_text_idx = -1;
1206 gint nb_audio = 0, nb_video = 0, nb_text = 0;
1209 g_mutex_lock (&play->selection_lock);
1210 if (play->is_playbin3) {
1211 if (!play->collection) {
1212 gst_print ("No stream-collection\n");
1213 g_mutex_unlock (&play->selection_lock);
1217 /* Check the total number of streams of each type */
1218 len = gst_stream_collection_get_size (play->collection);
1219 for (i = 0; i < len; i++) {
1221 gst_stream_collection_get_stream (play->collection, i);
1223 GstStreamType type = gst_stream_get_stream_type (stream);
1224 const gchar *sid = gst_stream_get_stream_id (stream);
1226 if (type & GST_STREAM_TYPE_AUDIO) {
1227 if (play->cur_audio_sid && !g_strcmp0 (play->cur_audio_sid, sid))
1228 cur_audio_idx = nb_audio;
1230 } else if (type & GST_STREAM_TYPE_VIDEO) {
1231 if (play->cur_video_sid && !g_strcmp0 (play->cur_video_sid, sid))
1232 cur_video_idx = nb_video;
1234 } else if (type & GST_STREAM_TYPE_TEXT) {
1235 if (play->cur_text_sid && !g_strcmp0 (play->cur_text_sid, sid))
1236 cur_text_idx = nb_text;
1239 gst_print ("Unknown stream type with stream-id %s", sid);
1245 switch (track_type) {
1246 case GST_PLAY_TRACK_TYPE_AUDIO:
1247 prop_get = "get-audio-tags";
1248 prop_cur = "current-audio";
1252 if (play->is_playbin3) {
1254 cur = cur_audio_idx;
1255 if (play->cur_video_sid) {
1257 g_list_append (selected_streams, play->cur_video_sid);
1259 if (play->cur_text_sid) {
1261 g_list_append (selected_streams, play->cur_text_sid);
1265 case GST_PLAY_TRACK_TYPE_VIDEO:
1266 prop_get = "get-video-tags";
1267 prop_cur = "current-video";
1271 if (play->is_playbin3) {
1273 cur = cur_video_idx;
1274 if (play->cur_audio_sid) {
1276 g_list_append (selected_streams, play->cur_audio_sid);
1278 if (play->cur_text_sid) {
1280 g_list_append (selected_streams, play->cur_text_sid);
1284 case GST_PLAY_TRACK_TYPE_SUBTITLE:
1285 prop_get = "get-text-tags";
1286 prop_cur = "current-text";
1290 if (play->is_playbin3) {
1293 if (play->cur_audio_sid) {
1295 g_list_append (selected_streams, play->cur_audio_sid);
1297 if (play->cur_video_sid) {
1299 g_list_append (selected_streams, play->cur_video_sid);
1307 if (play->is_playbin3) {
1313 cur = (cur + 1) % (n + 1);
1318 cur = (cur - 1) % (n + 1);
1322 g_object_get (play->playbin, prop_cur, &cur, prop_n, &n, "flags",
1326 if (!(cur_flags & flag))
1329 cur = (cur + 1) % (n + 1);
1335 cur = (cur - 1) % (n + 1);
1340 gst_print ("No %s tracks.\n", name);
1341 g_mutex_unlock (&play->selection_lock);
1343 gchar *lcode = NULL, *lname = NULL;
1344 const gchar *lang = NULL;
1345 GstTagList *tags = NULL;
1347 if (cur >= n && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1349 gst_print ("Disabling %s. \n", name);
1350 if (play->is_playbin3) {
1351 /* Just make it empty for the track type */
1352 } else if (cur_flags & flag) {
1354 g_object_set (play->playbin, "flags", cur_flags, NULL);
1357 /* For video we only want to switch between streams, not disable it altogether */
1361 if (play->is_playbin3) {
1364 stream = play_get_nth_stream_in_collection (play, cur, track_type);
1366 selected_streams = g_list_append (selected_streams,
1367 (gchar *) gst_stream_get_stream_id (stream));
1368 tags = gst_stream_get_tags (stream);
1370 gst_print ("Collection has no stream for track %d of %d.\n",
1374 if (!(cur_flags & flag) && track_type != GST_PLAY_TRACK_TYPE_VIDEO) {
1376 g_object_set (play->playbin, "flags", cur_flags, NULL);
1378 g_signal_emit_by_name (play->playbin, prop_get, cur, &tags);
1382 if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lcode))
1383 lang = gst_tag_get_language_name (lcode);
1384 else if (gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_NAME, &lname))
1386 gst_tag_list_unref (tags);
1389 gst_print ("Switching to %s track %d of %d (%s).\n", name, cur + 1, n,
1392 gst_print ("Switching to %s track %d of %d.\n", name, cur + 1, n);
1396 g_mutex_unlock (&play->selection_lock);
1398 if (play->is_playbin3) {
1399 if (selected_streams)
1400 gst_element_send_event (play->playbin,
1401 gst_event_new_select_streams (selected_streams));
1403 gst_print ("Can't disable all streams !\n");
1405 g_object_set (play->playbin, prop_cur, cur, NULL);
1409 if (selected_streams)
1410 g_list_free (selected_streams);
1414 print_keyboard_help (void)
1419 const gchar *key_desc;
1420 const gchar *key_help;
1421 } key_controls[] = {
1423 N_("space"), N_("pause/unpause")}, {
1424 N_("q or ESC"), N_("quit")}, {
1425 N_("> or n"), N_("play next")}, {
1426 N_("< or b"), N_("play previous")}, {
1427 "\342\206\222", N_("seek forward")}, {
1428 "\342\206\220", N_("seek backward")}, {
1429 "\342\206\221", N_("volume up")}, {
1430 "\342\206\223", N_("volume down")}, {
1431 "m", N_("toggle audio mute on/off")}, {
1432 "+", N_("increase playback rate")}, {
1433 "-", N_("decrease playback rate")}, {
1434 "d", N_("change playback direction")}, {
1435 "t", N_("enable/disable trick modes")}, {
1436 "A/a", N_("change to previous/next audio track")}, {
1437 "V/v", N_("change to previous/next video track")}, {
1438 "S/s", N_("change to previous/next subtitle track")}, {
1439 "0", N_("seek to beginning")}, {
1440 "k", N_("show keyboard shortcuts")},};
1442 guint i, chars_to_pad, desc_len, max_desc_len = 0;
1444 gst_print ("\n\n%s\n\n", _("Interactive mode - keyboard controls:"));
1446 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1447 desc_len = g_utf8_strlen (key_controls[i].key_desc, -1);
1448 max_desc_len = MAX (max_desc_len, desc_len);
1452 for (i = 0; i < G_N_ELEMENTS (key_controls); ++i) {
1453 chars_to_pad = max_desc_len - g_utf8_strlen (key_controls[i].key_desc, -1);
1454 gst_print ("\t%s", key_controls[i].key_desc);
1455 gst_print ("%-*s: ", chars_to_pad, "");
1456 gst_print ("%s\n", key_controls[i].key_help);
1462 keyboard_cb (const gchar * key_input, gpointer user_data)
1464 GstPlay *play = (GstPlay *) user_data;
1467 /* Switch on the first char for single char inputs,
1468 * otherwise leave key = '\0' to fall through to
1469 * the default case below */
1470 if (key_input[0] != '\0' && key_input[1] == '\0') {
1476 print_keyboard_help ();
1479 toggle_paused (play);
1483 g_main_loop_quit (play->loop);
1487 if (!play_next (play)) {
1488 gst_print ("\n%s\n", _("Reached end of play list."));
1489 g_main_loop_quit (play->loop);
1497 if (play->rate > -0.2 && play->rate < 0.0)
1498 play_set_relative_playback_rate (play, 0.0, TRUE);
1499 else if (ABS (play->rate) < 2.0)
1500 play_set_relative_playback_rate (play, 0.1, FALSE);
1501 else if (ABS (play->rate) < 4.0)
1502 play_set_relative_playback_rate (play, 0.5, FALSE);
1504 play_set_relative_playback_rate (play, 1.0, FALSE);
1507 if (play->rate > 0.0 && play->rate < 0.20)
1508 play_set_relative_playback_rate (play, 0.0, TRUE);
1509 else if (ABS (play->rate) <= 2.0)
1510 play_set_relative_playback_rate (play, -0.1, FALSE);
1511 else if (ABS (play->rate) <= 4.0)
1512 play_set_relative_playback_rate (play, -0.5, FALSE);
1514 play_set_relative_playback_rate (play, -1.0, FALSE);
1517 play_set_relative_playback_rate (play, 0.0, TRUE);
1520 play_switch_trick_mode (play);
1523 if (key_input[1] == '\0') {
1524 g_main_loop_quit (play->loop);
1529 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO, key == 'a');
1533 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO, key == 'v');
1537 play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE,
1541 play_do_seek (play, 0, play->rate, play->trick_mode);
1544 play_toggle_audio_mute (play);
1547 if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
1548 relative_seek (play, +0.08);
1549 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
1550 relative_seek (play, -0.01);
1551 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
1552 play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
1553 } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
1554 play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
1556 GST_INFO ("keyboard input:");
1557 for (; *key_input != '\0'; ++key_input)
1558 GST_INFO (" code %3d", *key_input);
1566 enable_winmm_timer_resolution (void)
1569 guint resolution = 0;
1572 res = timeGetDevCaps (&time_caps, sizeof (TIMECAPS));
1573 if (res != TIMERR_NOERROR) {
1574 g_warning ("timeGetDevCaps() returned non-zero code %d", res);
1578 resolution = MIN (MAX (time_caps.wPeriodMin, 1), time_caps.wPeriodMax);
1579 res = timeBeginPeriod (resolution);
1580 if (res != TIMERR_NOERROR) {
1581 g_warning ("timeBeginPeriod() returned non-zero code %d", res);
1585 gst_println (_("Use Windows high-resolution clock, precision: %u ms\n"),
1592 clear_winmm_timer_resolution (guint resolution)
1594 if (resolution == 0)
1597 timeEndPeriod (resolution);
1602 real_main (int argc, char **argv)
1605 GPtrArray *playlist;
1606 gboolean verbose = FALSE;
1607 gboolean print_version = FALSE;
1608 gboolean interactive = TRUE;
1609 gboolean gapless = FALSE;
1610 gboolean instant_uri = FALSE;
1611 gboolean shuffle = FALSE;
1612 gdouble volume = -1;
1613 gdouble start_position = 0;
1614 gchar **filenames = NULL;
1615 gchar *audio_sink = NULL;
1616 gchar *video_sink = NULL;
1618 gchar *flags = NULL;
1621 GOptionContext *ctx;
1622 gchar *playlist_file = NULL;
1623 gboolean use_playbin3 = FALSE;
1624 gboolean no_position = FALSE;
1626 guint winmm_timer_resolution = 0;
1628 GOptionEntry options[] = {
1629 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
1630 N_("Output status information and property notifications"), NULL},
1631 {"flags", 0, 0, G_OPTION_ARG_STRING, &flags,
1632 N_("Control playback behaviour setting playbin 'flags' property"),
1634 {"version", 0, 0, G_OPTION_ARG_NONE, &print_version,
1635 N_("Print version information and exit"), NULL},
1636 {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink,
1637 N_("Video sink to use (default is autovideosink)"), NULL},
1638 {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink,
1639 N_("Audio sink to use (default is autoaudiosink)"), NULL},
1640 {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless,
1641 N_("Enable gapless playback"), NULL},
1642 {"instant-uri", 0, 0, G_OPTION_ARG_NONE, &instant_uri,
1643 N_("Enable instantaneous uri changes (only with playbin3)"), NULL},
1644 {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
1645 N_("Shuffle playlist"), NULL},
1646 {"no-interactive", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
1648 N_("Disable interactive control via the keyboard"), NULL},
1649 {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume,
1650 N_("Volume"), NULL},
1651 {"start-position", 's', 0, G_OPTION_ARG_DOUBLE, &start_position,
1652 N_("Start position in seconds."), NULL},
1653 {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file,
1654 N_("Playlist file containing input media files"), NULL},
1655 {"instant-rate-changes", 'i', 0, G_OPTION_ARG_NONE, &instant_rate_changes,
1657 ("Use the experimental instant-rate-change flag when changing rate"),
1659 {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
1660 N_("Do not print any output (apart from errors)"), NULL},
1661 {"use-playbin3", 0, 0, G_OPTION_ARG_NONE, &use_playbin3,
1662 N_("Use playbin3 pipeline "
1663 "(default varies depending on 'USE_PLAYBIN' env variable)"),
1665 {"wait-on-eos", 0, 0, G_OPTION_ARG_NONE, &wait_on_eos,
1667 ("Keep showing the last frame on EOS until quit or playlist change command "
1668 "(gapless is ignored)"),
1670 {"no-position", 0, 0, G_OPTION_ARG_NONE, &no_position,
1671 N_("Do not print current position of pipeline"),
1673 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
1677 setlocale (LC_ALL, "");
1680 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1681 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1682 textdomain (GETTEXT_PACKAGE);
1685 g_set_prgname ("gst-play-" GST_API_VERSION);
1686 /* Ensure XInitThreads() is called if/when needed */
1687 g_setenv ("GST_GL_XINITTHREADS", "1", TRUE);
1688 g_setenv ("GST_XINITTHREADS", "1", TRUE);
1690 ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...");
1691 g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
1692 g_option_context_add_group (ctx, gst_init_get_option_group ());
1693 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
1694 gst_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
1695 g_option_context_free (ctx);
1696 g_clear_error (&err);
1699 g_option_context_free (ctx);
1701 GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play");
1703 if (print_version) {
1706 version_str = gst_version_string ();
1707 gst_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION);
1708 gst_print ("%s\n", version_str);
1709 gst_print ("%s\n", GST_PACKAGE_ORIGIN);
1710 g_free (version_str);
1712 g_free (audio_sink);
1713 g_free (video_sink);
1714 g_free (playlist_file);
1722 playlist = g_ptr_array_new ();
1724 if (playlist_file != NULL) {
1725 gchar *playlist_contents = NULL;
1726 gchar **lines = NULL;
1728 if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) {
1729 lines = g_strsplit (playlist_contents, "\n", 0);
1730 num = g_strv_length (lines);
1732 for (i = 0; i < num; i++) {
1733 if (lines[i][0] != '\0') {
1734 GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]);
1735 add_to_playlist (playlist, lines[i]);
1739 g_free (playlist_contents);
1741 gst_printerr ("Could not read playlist: %s\n", err->message);
1742 g_clear_error (&err);
1744 g_free (playlist_file);
1745 playlist_file = NULL;
1748 if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) {
1749 gst_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."),
1750 "gst-play-" GST_API_VERSION);
1751 gst_printerr ("\n\n"),
1752 gst_printerr ("%s\n\n",
1753 _("You must provide at least one filename or URI to play."));
1754 /* No input provided. Free array */
1755 g_ptr_array_free (playlist, TRUE);
1757 g_free (audio_sink);
1758 g_free (video_sink);
1764 if (filenames != NULL && *filenames != NULL) {
1765 num = g_strv_length (filenames);
1766 for (i = 0; i < num; ++i) {
1767 GST_LOG ("command line argument: %s", filenames[i]);
1768 add_to_playlist (playlist, filenames[i]);
1770 g_strfreev (filenames);
1773 num = playlist->len;
1774 g_ptr_array_add (playlist, NULL);
1776 uris = (gchar **) g_ptr_array_free (playlist, FALSE);
1779 shuffle_uris (uris, num);
1783 play_new (uris, audio_sink, video_sink, gapless, instant_uri, volume,
1784 verbose, flags, use_playbin3, start_position, no_position);
1788 ("Failed to create 'playbin' element. Check your GStreamer installation.\n");
1789 return EXIT_FAILURE;
1792 /* Enable high-precision clock which will improve accuracy of various
1793 * Windows timer APIs (e.g., Sleep()), and it will increase the precision
1794 * of GstSystemClock as well
1797 /* NOTE: Once timer resolution is updated via timeBeginPeriod(),
1798 * application should undo it by calling timeEndPeriod()
1800 * Prior to Windows 10, version 2004, timeBeginPeriod() affects global
1801 * Windows setting (meaning that it will affect other processes),
1802 * but starting with Windows 10, version 2004, this function no longer
1803 * affects global timer resolution
1805 winmm_timer_resolution = enable_winmm_timer_resolution ();
1809 if (gst_play_kb_set_key_handler (keyboard_cb, play)) {
1810 gst_print (_("Press 'k' to see a list of keyboard shortcuts.\n"));
1811 atexit (restore_terminal);
1813 gst_print ("Interactive keyboard handling in terminal not available.\n");
1821 /* Undo timeBeginPeriod() if required */
1822 clear_winmm_timer_resolution (winmm_timer_resolution);
1828 g_free (audio_sink);
1829 g_free (video_sink);
1837 main (int argc, char *argv[])
1839 #if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
1840 return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
1842 return real_main (argc, argv);