300
g_object_get (G_OBJECT (playbin), "volume", &cur_volume, NULL);
304
g_object_set (G_OBJECT (playbin), "volume", unmute_volume, NULL);
308
unmute_volume = cur_volume;
309
g_object_set (G_OBJECT (playbin), "volume", 0.0, NULL);
311
g_object_get (G_OBJECT (playbin), "mute", &mute, NULL);
312
g_object_set (G_OBJECT (playbin), "mute", !mute, NULL);
318
gtk_interface.toggle_fullscreen();
324
if (video_size_width > 0 && video_size_height > 0)
325
gtk_interface.resize (video_size_width, video_size_height);
326
gtk_interface.unfullscreen();
447
477
player.last_state = state;
480
case GST_MESSAGE_ELEMENT:
482
if (gst_structure_has_name (message->structure, "prepare-xwindow-id") && gtk_interface.init_ok())
484
// show gtk window to display video in
485
gtk_interface.show();
486
gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
487
GDK_WINDOW_XWINDOW (gtk_interface.window()->window));
489
else if (gst_structure_has_name (message->structure, "playbin2-stream-changed"))
491
// try to figure out the video size
492
GstElement *videosink;
493
g_object_get (G_OBJECT (player.playbin), "video-sink", &videosink, NULL);
494
if (videosink && !options.novideo)
496
// Find an sink element that has "force-aspect-ratio" property & set it
498
GstIterator *iterator = gst_bin_iterate_sinks (GST_BIN (videosink));
499
gst_iterator_foreach (iterator, force_aspect_ratio, NULL);
501
if (GstPad* pad = gst_element_get_static_pad (videosink, "sink"))
503
if (GstCaps *caps = gst_pad_get_negotiated_caps (pad))
505
caps_set_cb (G_OBJECT (pad), NULL, &player);
506
gst_caps_unref (caps);
509
g_signal_connect (pad, "notify::caps", G_CALLBACK (caps_set_cb), &player);
510
gst_object_unref (GST_OBJECT (pad));
512
gst_object_unref (GST_OBJECT (videosink));
451
517
/* unhandled message */
502
567
if (len > 0) /* streams (i.e. http) have len == -1 */
503
568
g_print (" of %01lu:%02lu:%02lu.%02lu", len_min / 60, len_min % 60, tv_len.tv_sec % 60, tv_len.tv_usec / 10000);
570
string status, blanks;
505
571
// Print [MUTED] if sound is muted:
507
g_object_get (G_OBJECT (player.playbin), "volume", &cur_volume, NULL);
510
g_print (" [MUTED]");
573
g_object_get (G_OBJECT (player.playbin), "mute", &mute, NULL);
576
status += " [MUTED]";
580
// Print [PAUSED] if paused:
581
bool pause = (player.last_state == GST_STATE_PAUSED);
584
status += " [PAUSED]";
587
g_print ("%s%s\r", status.c_str(), blanks.c_str());
516
590
/* call me again */
521
check_arg (uint argc,
524
const char *opt, /* for example: --foo */
525
const char **opt_arg = NULL) /* if foo needs an argument, pass a pointer to get the argument */
527
g_return_val_if_fail (opt != NULL, false);
528
g_return_val_if_fail (*nth < argc, false);
530
const char *arg = argv[*nth];
534
uint opt_len = strlen (opt);
535
if (strcmp (arg, opt) == 0)
537
if (opt_arg && *nth + 1 < argc) /* match foo option with argument: --foo bar */
539
argv[(*nth)++] = NULL;
540
*opt_arg = argv[*nth];
544
else if (!opt_arg) /* match foo option without argument: --foo */
549
/* fall through to error message */
551
else if (strncmp (arg, opt, opt_len) == 0 && arg[opt_len] == '=')
553
if (opt_arg) /* match foo option with argument: --foo=bar */
555
*opt_arg = arg + opt_len + 1;
559
/* fall through to error message */
564
Options::print_usage();
569
Options::parse (int *argc_p,
572
guint argc = *argc_p;
573
gchar **argv = *argv_p;
576
g_return_if_fail (argc >= 0);
578
/* I am tired of seeing .libs/lt-gst123 all the time,
579
* but basically this should be done (to allow renaming the binary):
582
program_name = argv[0];
585
for (i = 1; i < argc; i++)
588
if (strcmp (argv[i], "--help") == 0 ||
589
strcmp (argv[i], "-h") == 0)
594
else if (strcmp (argv[i], "--version") == 0 || strcmp (argv[i], "-v") == 0)
596
printf ("%s %s\n", program_name.c_str(), VERSION);
599
else if (check_arg (argc, argv, &i, "--verbose"))
603
else if (check_arg (argc, argv, &i, "--shuffle") || check_arg (argc, argv, &i, "-z"))
607
else if (check_arg (argc, argv, &i, "--list", &opt_arg) || check_arg (argc, argv, &i, "-@", &opt_arg))
609
playlists.push_back (opt_arg);
613
/* resort argc/argv */
615
for (i = 1; i < argc; i++)
626
Options::print_usage ()
628
g_printerr ("usage: %s [ <options> ] <URI> ...\n", options.program_name.c_str());
630
g_printerr ("options:\n");
631
g_printerr (" -h, --help help for %s\n", options.program_name.c_str());
632
g_printerr (" -@, --list <filename> read playlist of files and URIs from \"filename\"\n");
633
g_printerr (" --version print version\n");
634
g_printerr (" --verbose print GStreamer pipeline used to play files\n");
635
g_printerr (" -z, --shuffle play files in pseudo random order\n");
639
595
static inline bool
640
596
is_directory (const string& path)
729
if (!g_thread_supported ())
730
g_thread_init (NULL);
732
options.parse (argc, argv);
761
734
/* init GStreamer */
762
735
gst_init (&argc, &argv);
736
gtk_interface.init (&argc, &argv, &player);
763
738
player.loop = g_main_loop_new (NULL, FALSE);
765
options.parse (&argc, &argv);
768
for (int i = 1; i < argc; i++)
769
player.add_uri_or_directory (argv[i]);
743
for (int i = 0; options.uris[i]; i++)
744
player.add_uri_or_directory (options.uris[i]);
771
747
for (list<string>::iterator pi = options.playlists.begin(); pi != options.playlists.end(); pi++)
800
776
/* make sure we have a URI */
801
777
if (player.uris.empty())
803
options.print_usage();
779
printf ("%s", options.usage.c_str());
806
player.playbin = gst_element_factory_make ("playbin", "play");
782
player.playbin = gst_element_factory_make ("playbin2", "play");
785
GstElement *fakesink = gst_element_factory_make ("fakesink", "novid");
786
g_object_set (G_OBJECT (player.playbin), "video-sink", fakesink, NULL);
807
788
gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (player.playbin)), my_bus_callback, &player);
808
789
g_timeout_add (130, (GSourceFunc) cb_print_position, &player);
809
790
signal (SIGINT, sigint_handler);