3 * seek.c: seeking sample application
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * 2006 Stefan Kost <ensonic@users.sf.net>
8 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
29 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
30 * with newer GTK versions (>= 3.3.0) */
31 #define GDK_DISABLE_DEPRECATION_WARNINGS
32 #define GLIB_DISABLE_DEPRECATION_WARNINGS
42 #if defined (GDK_WINDOWING_X11)
44 #elif defined (GDK_WINDOWING_WIN32)
45 #include <gdk/gdkwin32.h>
46 #elif defined (GDK_WINDOWING_QUARTZ)
47 #include <gdk/gdkquartzwindow.h>
50 #include <gst/interfaces/xoverlay.h>
51 #include <gst/interfaces/navigation.h>
52 #include <gst/interfaces/colorbalance.h>
54 GST_DEBUG_CATEGORY_STATIC (seek_debug);
55 #define GST_CAT_DEFAULT (seek_debug)
57 /* Copied from gst-plugins-base/gst/playback/gstplay-enum.h */
60 GST_PLAY_FLAG_VIDEO = (1 << 0),
61 GST_PLAY_FLAG_AUDIO = (1 << 1),
62 GST_PLAY_FLAG_TEXT = (1 << 2),
63 GST_PLAY_FLAG_VIS = (1 << 3),
64 GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4),
65 GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5),
66 GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6),
67 GST_PLAY_FLAG_DOWNLOAD = (1 << 7),
68 GST_PLAY_FLAG_BUFFERING = (1 << 8),
69 GST_PLAY_FLAG_DEINTERLACE = (1 << 9),
70 GST_PLAY_FLAG_SOFT_COLORBALANCE = (1 << 10)
75 #define FILL_INTERVAL 100
76 //#define UPDATE_INTERVAL 500
77 //#define UPDATE_INTERVAL 100
78 #define UPDATE_INTERVAL 40
80 /* number of milliseconds to play for after a seek */
81 #define SCRUB_TIME 100
83 /* timeout for gst_element_get_state() after a seek */
84 #define SEEK_TIMEOUT 40 * GST_MSECOND
86 #define DEFAULT_VIDEO_HEIGHT 300
88 /* the state to go to when stop is pressed */
89 #define STOP_STATE GST_STATE_READY
93 /* we keep an array of the visualisation entries so that we can easily switch
94 * with the combo box index. */
97 GstElementFactory *factory;
104 GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
105 GtkWidget *video_window;
107 GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
108 GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
109 GtkWidget *soft_volume_checkbox, *native_audio_checkbox,
110 *native_video_checkbox;
111 GtkWidget *download_checkbox, *buffering_checkbox, *deinterlace_checkbox;
112 GtkWidget *soft_colorbalance_checkbox;
113 GtkWidget *video_sink_entry, *audio_sink_entry, *text_sink_entry;
114 GtkWidget *buffer_size_entry, *buffer_duration_entry;
115 GtkWidget *ringbuffer_maxsize_entry, *connection_speed_entry;
116 GtkWidget *av_offset_entry, *subtitle_encoding_entry;
117 GtkWidget *subtitle_fontdesc_button;
119 GtkWidget *seek_format_combo, *seek_position_label, *seek_duration_label;
120 GtkWidget *seek_entry;
122 GtkWidget *seek_scale, *statusbar;
125 GtkWidget *step_format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
126 GtkWidget *shuttle_scale;
128 GtkWidget *contrast_scale, *brightness_scale, *hue_scale, *saturation_scale;
132 GstNavigationCommand cmd;
134 } navigation_buttons[14];
138 /* GStreamer pipeline */
139 GstElement *pipeline;
141 GstElement *navigation_element;
142 GstElement *colorbalance_element;
143 GstElement *xoverlay_element;
146 gboolean accurate_seek;
147 gboolean keyframe_seek;
155 /* From commandline parameters */
158 const gchar *pipeline_spec;
160 GList *paths, *current_path;
162 gchar *audiosink_str, *videosink_str;
165 gint64 position, duration;
169 GstBufferingMode mode;
170 gint64 buffering_left;
173 guint seek_timeout_id;
177 gboolean need_streams;
178 gint n_video, n_audio, n_text;
180 GStaticMutex state_mutex;
182 GArray *vis_entries; /* Array of VisEntry structs */
185 gdouble shuttle_rate;
188 const GstFormatDefinition *seek_format;
192 static void clear_streams (SeekApp * app);
193 static void find_interface_elements (SeekApp * app);
194 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
196 static void mute_notify_cb (GstElement * pipeline, GParamSpec * arg,
199 static void video_sink_activate_cb (GtkEntry * entry, SeekApp * app);
200 static void text_sink_activate_cb (GtkEntry * entry, SeekApp * app);
201 static void audio_sink_activate_cb (GtkEntry * entry, SeekApp * app);
202 static void buffer_size_activate_cb (GtkEntry * entry, SeekApp * app);
203 static void buffer_duration_activate_cb (GtkEntry * entry, SeekApp * app);
204 static void ringbuffer_maxsize_activate_cb (GtkEntry * entry, SeekApp * app);
205 static void connection_speed_activate_cb (GtkEntry * entry, SeekApp * app);
206 static void av_offset_activate_cb (GtkEntry * entry, SeekApp * app);
207 static void subtitle_encoding_activate_cb (GtkEntry * entry, SeekApp * app);
209 /* pipeline construction */
212 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
214 GstElement *element = gst_element_factory_make (type, name);
216 #ifndef GST_DISABLE_PARSE
218 /* Try parsing it as a pipeline description */
219 element = gst_parse_bin_from_description (type, TRUE, NULL);
221 gst_element_set_name (element, name);
227 g_warning ("Failed to create element %s of type %s", name, type);
234 playbin_set_uri (GstElement * playbin, const gchar * location)
238 /* Add "file://" prefix for convenience */
239 if (g_str_has_prefix (location, "/") || !gst_uri_is_valid (location)) {
240 uri = gst_filename_to_uri (location, NULL);
241 g_print ("Setting URI: %s\n", uri);
242 g_object_set (G_OBJECT (playbin), "uri", uri, NULL);
245 g_print ("Setting URI: %s\n", location);
246 g_object_set (G_OBJECT (playbin), "uri", location, NULL);
251 make_playbin2_pipeline (SeekApp * app, const gchar * location)
253 GstElement *pipeline;
255 app->pipeline = pipeline = gst_element_factory_make ("playbin2", "playbin2");
258 playbin_set_uri (pipeline, location);
260 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
262 g_signal_connect (pipeline, "notify::mute", G_CALLBACK (mute_notify_cb), app);
264 app->navigation_element = GST_ELEMENT (gst_object_ref (pipeline));
265 app->colorbalance_element = GST_ELEMENT (gst_object_ref (pipeline));
268 #ifndef GST_DISABLE_PARSE
270 make_parselaunch_pipeline (SeekApp * app, const gchar * description)
272 app->pipeline = gst_parse_launch (description, NULL);
279 void (*func) (SeekApp * app, const gchar * location);
283 static const Pipeline pipelines[] = {
284 {"playbin2", make_playbin2_pipeline},
285 #ifndef GST_DISABLE_PARSE
286 {"parse-launch", make_parselaunch_pipeline},
290 /* ui callbacks and helpers */
293 format_value (GtkScale * scale, gdouble value, SeekApp * app)
299 real = value * app->duration / N_GRAD;
300 seconds = (gint64) real / GST_SECOND;
301 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
303 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
304 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
308 shuttle_format_value (GtkScale * scale, gdouble value)
310 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
316 const GstFormat format;
320 static seek_format seek_formats[] = {
321 {"tim", GST_FORMAT_TIME},
322 {"byt", GST_FORMAT_BYTES},
323 {"buf", GST_FORMAT_BUFFERS},
324 {"def", GST_FORMAT_DEFAULT},
329 query_positions (SeekApp * app)
333 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (app->pipeline));
334 while (seek_formats[i].name) {
335 gint64 position, total;
338 format = seek_formats[i].format;
340 if (gst_element_query_position (app->pipeline, &format, &position) &&
341 gst_element_query_duration (app->pipeline, &format, &total)) {
342 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
343 seek_formats[i].name, position, total);
345 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*", "*NA*");
349 g_print (" %s\n", GST_ELEMENT_NAME (app->pipeline));
352 static gboolean start_seek (GtkRange * range, GdkEventButton * event,
354 static gboolean stop_seek (GtkRange * range, GdkEventButton * event,
356 static void seek_cb (GtkRange * range, SeekApp * app);
359 set_scale (SeekApp * app, gdouble value)
361 g_signal_handlers_block_by_func (app->seek_scale, start_seek, app);
362 g_signal_handlers_block_by_func (app->seek_scale, stop_seek, app);
363 g_signal_handlers_block_by_func (app->seek_scale, seek_cb, app);
364 gtk_range_set_value (GTK_RANGE (app->seek_scale), value);
365 g_signal_handlers_unblock_by_func (app->seek_scale, start_seek, app);
366 g_signal_handlers_unblock_by_func (app->seek_scale, stop_seek, app);
367 g_signal_handlers_unblock_by_func (app->seek_scale, seek_cb, app);
368 gtk_widget_queue_draw (app->seek_scale);
372 update_fill (SeekApp * app)
376 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
377 if (gst_element_query (app->pipeline, query)) {
378 gint64 start, stop, buffering_total;
383 GstBufferingMode mode;
384 gint avg_in, avg_out;
385 gint64 buffering_left;
387 gst_query_parse_buffering_percent (query, &busy, &percent);
388 gst_query_parse_buffering_range (query, &format, &start, &stop,
390 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
393 /* note that we could start the playback when buffering_left < remaining
395 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
396 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
397 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
401 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
405 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), fill);
407 gst_query_unref (query);
413 update_scale (SeekApp * app)
415 GstFormat format = GST_FORMAT_TIME;
416 gint64 seek_pos, seek_dur;
422 gst_element_query_position (app->pipeline, &format, &app->position);
423 gst_element_query_duration (app->pipeline, &format, &app->duration);
426 query_positions (app);
428 if (app->position >= app->duration)
429 app->duration = app->position;
431 if (app->duration > 0) {
432 set_scale (app, app->position * N_GRAD / app->duration);
435 if (app->seek_format) {
436 format = app->seek_format->value;
437 seek_pos = seek_dur = -1;
438 gst_element_query_position (app->pipeline, &format, &seek_pos);
439 gst_element_query_duration (app->pipeline, &format, &seek_dur);
441 str = g_strdup_printf ("%" G_GINT64_FORMAT, seek_pos);
442 gtk_label_set_text (GTK_LABEL (app->seek_position_label), str);
445 str = g_strdup_printf ("%" G_GINT64_FORMAT, seek_dur);
446 gtk_label_set_text (GTK_LABEL (app->seek_duration_label), str);
453 static void set_update_scale (SeekApp * app, gboolean active);
454 static void set_update_fill (SeekApp * app, gboolean active);
457 end_scrub (SeekApp * app)
459 GST_DEBUG ("end scrub, PAUSE");
460 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
461 app->seek_timeout_id = 0;
467 send_event (SeekApp * app, GstEvent * event)
469 gboolean res = FALSE;
471 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (app->pipeline));
472 res = gst_element_send_event (app->pipeline, event);
478 do_seek (SeekApp * app, GstFormat format, gint64 position)
480 gboolean res = FALSE;
486 flags |= GST_SEEK_FLAG_FLUSH;
487 if (app->accurate_seek)
488 flags |= GST_SEEK_FLAG_ACCURATE;
489 if (app->keyframe_seek)
490 flags |= GST_SEEK_FLAG_KEY_UNIT;
492 flags |= GST_SEEK_FLAG_SEGMENT;
494 flags |= GST_SEEK_FLAG_SKIP;
496 if (app->rate >= 0) {
497 s_event = gst_event_new_seek (app->rate,
498 format, flags, GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_SET,
499 GST_CLOCK_TIME_NONE);
500 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
501 app->rate, GST_TIME_ARGS (position), GST_TIME_ARGS (app->duration));
503 s_event = gst_event_new_seek (app->rate,
504 format, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
505 GST_SEEK_TYPE_SET, position);
506 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
507 app->rate, GST_TIME_ARGS (0), GST_TIME_ARGS (position));
510 res = send_event (app, s_event);
513 if (app->flush_seek) {
514 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
517 set_update_scale (app, TRUE);
520 g_print ("seek failed\n");
521 set_update_scale (app, TRUE);
526 seek_cb (GtkRange * range, SeekApp * app)
529 /* If the timer hasn't expired yet, then the pipeline is running */
530 if (app->play_scrub && app->seek_timeout_id != 0) {
531 GST_DEBUG ("do scrub seek, PAUSED");
532 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
536 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
539 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
540 gtk_range_get_value (GTK_RANGE (app->seek_scale)), real);
542 GST_DEBUG ("do seek");
543 do_seek (app, GST_FORMAT_TIME, real);
545 if (app->play_scrub) {
546 GST_DEBUG ("do scrub seek, PLAYING");
547 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
549 if (app->seek_timeout_id == 0) {
550 app->seek_timeout_id =
551 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, app);
557 advanced_seek_button_cb (GtkButton * button, SeekApp * app)
564 fmt = app->seek_format->value;
566 text = gtk_entry_get_text (GTK_ENTRY (app->seek_entry));
568 pos = g_ascii_strtoll (text, &endptr, 10);
569 if (endptr != text && pos != G_MAXINT64 && pos != G_MININT64) {
570 do_seek (app, fmt, pos);
575 set_update_fill (SeekApp * app, gboolean active)
577 GST_DEBUG ("fill scale is %d", active);
580 if (app->fill_id == 0) {
582 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, app);
586 g_source_remove (app->fill_id);
593 set_update_scale (SeekApp * app, gboolean active)
595 GST_DEBUG ("update scale is %d", active);
598 if (app->update_id == 0) {
600 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, app);
603 if (app->update_id) {
604 g_source_remove (app->update_id);
611 start_seek (GtkRange * range, GdkEventButton * event, SeekApp * app)
613 if (event->type != GDK_BUTTON_PRESS)
616 set_update_scale (app, FALSE);
618 if (app->state == GST_STATE_PLAYING && app->flush_seek && app->scrub) {
619 GST_DEBUG ("start scrub seek, PAUSE");
620 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
623 if (app->changed_id == 0 && app->flush_seek && app->scrub) {
625 g_signal_connect (app->seek_scale, "value-changed",
626 G_CALLBACK (seek_cb), app);
633 stop_seek (GtkRange * range, GdkEventButton * event, SeekApp * app)
635 if (app->changed_id) {
636 g_signal_handler_disconnect (app->seek_scale, app->changed_id);
640 if (!app->flush_seek || !app->scrub) {
643 GST_DEBUG ("do final seek");
645 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
647 do_seek (app, GST_FORMAT_TIME, real);
650 if (app->seek_timeout_id != 0) {
651 g_source_remove (app->seek_timeout_id);
652 app->seek_timeout_id = 0;
653 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
655 if (app->state == GST_STATE_PAUSED) {
656 GST_DEBUG ("stop scrub seek, PAUSED");
657 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
660 if (app->state == GST_STATE_PLAYING) {
661 GST_DEBUG ("stop scrub seek, PLAYING");
662 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
670 play_cb (GtkButton * button, SeekApp * app)
672 GstStateChangeReturn ret;
674 if (app->state != GST_STATE_PLAYING) {
675 g_print ("PLAY pipeline\n");
676 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
678 if (app->pipeline_type == 0) {
679 video_sink_activate_cb (GTK_ENTRY (app->video_sink_entry), app);
680 audio_sink_activate_cb (GTK_ENTRY (app->audio_sink_entry), app);
681 text_sink_activate_cb (GTK_ENTRY (app->text_sink_entry), app);
682 buffer_size_activate_cb (GTK_ENTRY (app->buffer_size_entry), app);
683 buffer_duration_activate_cb (GTK_ENTRY (app->buffer_duration_entry), app);
684 ringbuffer_maxsize_activate_cb (GTK_ENTRY (app->ringbuffer_maxsize_entry),
686 connection_speed_activate_cb (GTK_ENTRY (app->connection_speed_entry),
688 av_offset_activate_cb (GTK_ENTRY (app->av_offset_entry), app);
689 subtitle_encoding_activate_cb (GTK_ENTRY (app->subtitle_encoding_entry),
693 ret = gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
695 case GST_STATE_CHANGE_FAILURE:
697 case GST_STATE_CHANGE_NO_PREROLL:
703 app->state = GST_STATE_PLAYING;
704 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
712 g_print ("PLAY failed\n");
713 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
719 pause_cb (GtkButton * button, SeekApp * app)
721 g_static_mutex_lock (&app->state_mutex);
722 if (app->state != GST_STATE_PAUSED) {
723 GstStateChangeReturn ret;
725 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
726 g_print ("PAUSE pipeline\n");
727 ret = gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
729 case GST_STATE_CHANGE_FAILURE:
731 case GST_STATE_CHANGE_NO_PREROLL:
738 app->state = GST_STATE_PAUSED;
739 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
742 g_static_mutex_unlock (&app->state_mutex);
748 g_static_mutex_unlock (&app->state_mutex);
749 g_print ("PAUSE failed\n");
750 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
756 stop_cb (GtkButton * button, SeekApp * app)
758 if (app->state != STOP_STATE) {
759 GstStateChangeReturn ret;
762 g_print ("READY pipeline\n");
763 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
765 g_static_mutex_lock (&app->state_mutex);
766 ret = gst_element_set_state (app->pipeline, STOP_STATE);
767 if (ret == GST_STATE_CHANGE_FAILURE)
770 app->state = STOP_STATE;
771 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
773 gtk_widget_queue_draw (app->video_window);
775 app->is_live = FALSE;
776 app->buffering = FALSE;
777 set_update_scale (app, FALSE);
778 set_scale (app, 0.0);
779 set_update_fill (app, FALSE);
781 if (app->pipeline_type == 0)
783 g_static_mutex_unlock (&app->state_mutex);
785 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), TRUE);
786 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++)
787 gtk_widget_set_sensitive (app->navigation_buttons[i].button, FALSE);
793 g_static_mutex_unlock (&app->state_mutex);
794 g_print ("STOP failed\n");
795 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
801 accurate_toggle_cb (GtkToggleButton * button, SeekApp * app)
803 app->accurate_seek = gtk_toggle_button_get_active (button);
807 key_toggle_cb (GtkToggleButton * button, SeekApp * app)
809 app->keyframe_seek = gtk_toggle_button_get_active (button);
813 loop_toggle_cb (GtkToggleButton * button, SeekApp * app)
815 app->loop_seek = gtk_toggle_button_get_active (button);
816 if (app->state == GST_STATE_PLAYING) {
820 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
822 do_seek (app, GST_FORMAT_TIME, real);
827 flush_toggle_cb (GtkToggleButton * button, SeekApp * app)
829 app->flush_seek = gtk_toggle_button_get_active (button);
833 scrub_toggle_cb (GtkToggleButton * button, SeekApp * app)
835 app->scrub = gtk_toggle_button_get_active (button);
839 play_scrub_toggle_cb (GtkToggleButton * button, SeekApp * app)
841 app->play_scrub = gtk_toggle_button_get_active (button);
845 skip_toggle_cb (GtkToggleButton * button, SeekApp * app)
847 app->skip_seek = gtk_toggle_button_get_active (button);
848 if (app->state == GST_STATE_PLAYING) {
852 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
854 do_seek (app, GST_FORMAT_TIME, real);
859 rate_spinbutton_changed_cb (GtkSpinButton * button, SeekApp * app)
861 gboolean res = FALSE;
865 app->rate = gtk_spin_button_get_value (button);
867 GST_DEBUG ("rate changed to %lf", app->rate);
871 flags |= GST_SEEK_FLAG_FLUSH;
873 flags |= GST_SEEK_FLAG_SEGMENT;
874 if (app->accurate_seek)
875 flags |= GST_SEEK_FLAG_ACCURATE;
876 if (app->keyframe_seek)
877 flags |= GST_SEEK_FLAG_KEY_UNIT;
879 flags |= GST_SEEK_FLAG_SKIP;
881 if (app->rate >= 0.0) {
882 s_event = gst_event_new_seek (app->rate,
883 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
884 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
886 s_event = gst_event_new_seek (app->rate,
887 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
888 GST_SEEK_TYPE_SET, app->position);
891 res = send_event (app, s_event);
894 if (app->flush_seek) {
895 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
899 g_print ("seek failed\n");
903 update_flag (GstElement * pipeline, GstPlayFlags flag, gboolean state)
907 g_print ("%ssetting flag 0x%08x\n", (state ? "" : "un"), flag);
909 g_object_get (pipeline, "flags", &flags, NULL);
914 g_object_set (pipeline, "flags", flags, NULL);
918 vis_toggle_cb (GtkToggleButton * button, SeekApp * app)
922 state = gtk_toggle_button_get_active (button);
923 update_flag (app->pipeline, GST_PLAY_FLAG_VIS, state);
924 gtk_widget_set_sensitive (app->vis_combo, state);
928 audio_toggle_cb (GtkToggleButton * button, SeekApp * app)
932 state = gtk_toggle_button_get_active (button);
933 update_flag (app->pipeline, GST_PLAY_FLAG_AUDIO, state);
934 gtk_widget_set_sensitive (app->audio_combo, state);
938 video_toggle_cb (GtkToggleButton * button, SeekApp * app)
942 state = gtk_toggle_button_get_active (button);
943 update_flag (app->pipeline, GST_PLAY_FLAG_VIDEO, state);
944 gtk_widget_set_sensitive (app->video_combo, state);
948 text_toggle_cb (GtkToggleButton * button, SeekApp * app)
952 state = gtk_toggle_button_get_active (button);
953 update_flag (app->pipeline, GST_PLAY_FLAG_TEXT, state);
954 gtk_widget_set_sensitive (app->text_combo, state);
958 mute_toggle_cb (GtkToggleButton * button, SeekApp * app)
962 mute = gtk_toggle_button_get_active (button);
963 g_object_set (app->pipeline, "mute", mute, NULL);
967 download_toggle_cb (GtkToggleButton * button, SeekApp * app)
971 state = gtk_toggle_button_get_active (button);
972 update_flag (app->pipeline, GST_PLAY_FLAG_DOWNLOAD, state);
976 buffering_toggle_cb (GtkToggleButton * button, SeekApp * app)
980 state = gtk_toggle_button_get_active (button);
981 update_flag (app->pipeline, GST_PLAY_FLAG_BUFFERING, state);
985 soft_volume_toggle_cb (GtkToggleButton * button, SeekApp * app)
989 state = gtk_toggle_button_get_active (button);
990 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_VOLUME, state);
994 native_audio_toggle_cb (GtkToggleButton * button, SeekApp * app)
998 state = gtk_toggle_button_get_active (button);
999 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_AUDIO, state);
1003 native_video_toggle_cb (GtkToggleButton * button, SeekApp * app)
1007 state = gtk_toggle_button_get_active (button);
1008 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_VIDEO, state);
1012 deinterlace_toggle_cb (GtkToggleButton * button, SeekApp * app)
1016 state = gtk_toggle_button_get_active (button);
1017 update_flag (app->pipeline, GST_PLAY_FLAG_DEINTERLACE, state);
1021 soft_colorbalance_toggle_cb (GtkToggleButton * button, SeekApp * app)
1025 state = gtk_toggle_button_get_active (button);
1026 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_COLORBALANCE, state);
1030 clear_streams (SeekApp * app)
1034 /* remove previous info */
1035 for (i = 0; i < app->n_video; i++)
1036 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->video_combo), 0);
1037 for (i = 0; i < app->n_audio; i++)
1038 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->audio_combo), 0);
1039 for (i = 0; i < app->n_text; i++)
1040 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->text_combo), 0);
1042 app->n_audio = app->n_video = app->n_text = 0;
1043 gtk_widget_set_sensitive (app->video_combo, FALSE);
1044 gtk_widget_set_sensitive (app->audio_combo, FALSE);
1045 gtk_widget_set_sensitive (app->text_combo, FALSE);
1047 app->need_streams = TRUE;
1051 update_streams (SeekApp * app)
1055 if (app->pipeline_type == 0 && app->need_streams) {
1061 /* remove previous info */
1062 clear_streams (app);
1064 /* here we get and update the different streams detected by playbin2 */
1065 g_object_get (app->pipeline, "n-video", &app->n_video, NULL);
1066 g_object_get (app->pipeline, "n-audio", &app->n_audio, NULL);
1067 g_object_get (app->pipeline, "n-text", &app->n_text, NULL);
1069 g_print ("video %d, audio %d, text %d\n", app->n_video, app->n_audio,
1073 for (i = 0; i < app->n_video; i++) {
1074 g_signal_emit_by_name (app->pipeline, "get-video-tags", i, &tags);
1076 str = gst_structure_to_string ((GstStructure *) tags);
1077 g_print ("video %d: %s\n", i, str);
1080 /* find good name for the label */
1081 name = g_strdup_printf ("video %d", i + 1);
1082 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->video_combo),
1087 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->video_checkbox));
1088 gtk_widget_set_sensitive (app->video_combo, state && app->n_video > 0);
1089 gtk_combo_box_set_active (GTK_COMBO_BOX (app->video_combo), active_idx);
1092 for (i = 0; i < app->n_audio; i++) {
1093 g_signal_emit_by_name (app->pipeline, "get-audio-tags", i, &tags);
1095 str = gst_structure_to_string ((GstStructure *) tags);
1096 g_print ("audio %d: %s\n", i, str);
1099 /* find good name for the label */
1100 name = g_strdup_printf ("audio %d", i + 1);
1101 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->audio_combo),
1106 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->audio_checkbox));
1107 gtk_widget_set_sensitive (app->audio_combo, state && app->n_audio > 0);
1108 gtk_combo_box_set_active (GTK_COMBO_BOX (app->audio_combo), active_idx);
1111 for (i = 0; i < app->n_text; i++) {
1112 g_signal_emit_by_name (app->pipeline, "get-text-tags", i, &tags);
1116 const GValue *value;
1118 str = gst_structure_to_string ((GstStructure *) tags);
1119 g_print ("text %d: %s\n", i, str);
1122 /* get the language code if we can */
1123 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1124 if (value && G_VALUE_HOLDS_STRING (value)) {
1125 name = g_strdup_printf ("text %s", g_value_get_string (value));
1128 /* find good name for the label if we didn't use a tag */
1130 name = g_strdup_printf ("text %d", i + 1);
1132 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->text_combo),
1137 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->text_checkbox));
1138 gtk_widget_set_sensitive (app->text_combo, state && app->n_text > 0);
1139 gtk_combo_box_set_active (GTK_COMBO_BOX (app->text_combo), active_idx);
1141 app->need_streams = FALSE;
1146 video_combo_cb (GtkComboBox * combo, SeekApp * app)
1150 active = gtk_combo_box_get_active (combo);
1152 g_print ("setting current video track %d\n", active);
1153 g_object_set (app->pipeline, "current-video", active, NULL);
1157 audio_combo_cb (GtkComboBox * combo, SeekApp * app)
1161 active = gtk_combo_box_get_active (combo);
1163 g_print ("setting current audio track %d\n", active);
1164 g_object_set (app->pipeline, "current-audio", active, NULL);
1168 text_combo_cb (GtkComboBox * combo, SeekApp * app)
1172 active = gtk_combo_box_get_active (combo);
1174 g_print ("setting current text track %d\n", active);
1175 g_object_set (app->pipeline, "current-text", active, NULL);
1179 filter_vis_features (GstPluginFeature * feature, gpointer data)
1181 GstElementFactory *f;
1183 if (!GST_IS_ELEMENT_FACTORY (feature))
1185 f = GST_ELEMENT_FACTORY (feature);
1186 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1193 init_visualization_features (SeekApp * app)
1197 app->vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1199 list = gst_registry_feature_filter (gst_registry_get_default (),
1200 filter_vis_features, FALSE, NULL);
1202 for (walk = list; walk; walk = g_list_next (walk)) {
1206 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1207 name = gst_element_factory_get_longname (entry.factory);
1209 g_array_append_val (app->vis_entries, entry);
1210 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->vis_combo), name);
1212 gtk_combo_box_set_active (GTK_COMBO_BOX (app->vis_combo), 0);
1216 vis_combo_cb (GtkComboBox * combo, SeekApp * app)
1220 GstElement *element;
1222 /* get the selected index and get the factory for this index */
1223 index = gtk_combo_box_get_active (GTK_COMBO_BOX (app->vis_combo));
1224 if (app->vis_entries->len > 0) {
1225 entry = &g_array_index (app->vis_entries, VisEntry, index);
1227 /* create an instance of the element from the factory */
1228 element = gst_element_factory_create (entry->factory, NULL);
1232 /* set vis plugin for playbin2 */
1233 g_object_set (app->pipeline, "vis-plugin", element, NULL);
1238 volume_spinbutton_changed_cb (GtkSpinButton * button, SeekApp * app)
1242 volume = gtk_spin_button_get_value (button);
1244 g_object_set (app->pipeline, "volume", volume, NULL);
1248 volume_notify_idle_cb (SeekApp * app)
1250 gdouble cur_volume, new_volume;
1252 g_object_get (app->pipeline, "volume", &new_volume, NULL);
1254 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->volume_spinbutton));
1255 if (fabs (cur_volume - new_volume) > 0.001) {
1256 g_signal_handlers_block_by_func (app->volume_spinbutton,
1257 volume_spinbutton_changed_cb, app);
1258 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton),
1260 g_signal_handlers_unblock_by_func (app->volume_spinbutton,
1261 volume_spinbutton_changed_cb, app);
1268 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, SeekApp * app)
1270 /* Do this from the main thread */
1271 g_idle_add ((GSourceFunc) volume_notify_idle_cb, app);
1275 mute_notify_idle_cb (SeekApp * app)
1277 gboolean cur_mute, new_mute;
1279 g_object_get (app->pipeline, "mute", &new_mute, NULL);
1281 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->mute_checkbox));
1282 if (cur_mute != new_mute) {
1283 g_signal_handlers_block_by_func (app->mute_checkbox, mute_toggle_cb, app);
1284 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
1286 g_signal_handlers_unblock_by_func (app->mute_checkbox, mute_toggle_cb, app);
1293 mute_notify_cb (GstElement * pipeline, GParamSpec * arg, SeekApp * app)
1295 /* Do this from the main thread */
1296 g_idle_add ((GSourceFunc) mute_notify_idle_cb, app);
1300 shot_cb (GtkButton * button, SeekApp * app)
1305 /* convert to our desired format (RGB24) */
1306 caps = gst_caps_new_simple ("video/x-raw-rgb",
1307 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1308 /* Note: we don't ask for a specific width/height here, so that
1309 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1310 * ratio to a 1/1 pixel-aspect-ratio */
1311 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1312 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1313 "red_mask", G_TYPE_INT, 0xff0000,
1314 "green_mask", G_TYPE_INT, 0x00ff00,
1315 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1317 /* convert the latest frame to the requested format */
1318 g_signal_emit_by_name (app->pipeline, "convert-frame", caps, &buffer);
1319 gst_caps_unref (caps);
1327 GError *error = NULL;
1329 /* get the snapshot buffer format now. We set the caps on the appsink so
1330 * that it can only be an rgb buffer. The only thing we have not specified
1331 * on the caps is the height, which is dependant on the pixel-aspect-ratio
1332 * of the source material */
1333 caps = GST_BUFFER_CAPS (buffer);
1335 g_warning ("could not get snapshot format\n");
1338 s = gst_caps_get_structure (caps, 0);
1340 /* we need to get the final caps on the buffer to get the size */
1341 res = gst_structure_get_int (s, "width", &width);
1342 res |= gst_structure_get_int (s, "height", &height);
1344 g_warning ("could not get snapshot dimension\n");
1348 /* create pixmap from buffer and save, gstreamer video buffers have a stride
1349 * that is rounded up to the nearest multiple of 4 */
1350 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
1351 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
1352 GST_ROUND_UP_4 (width * 3), NULL, NULL);
1354 /* save the pixbuf */
1355 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
1358 gst_buffer_unref (buffer);
1362 /* called when the Step button is pressed */
1364 step_cb (GtkButton * button, SeekApp * app)
1370 gboolean flush, res;
1373 active = gtk_combo_box_get_active (GTK_COMBO_BOX (app->step_format_combo));
1375 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
1376 (app->step_amount_spinbutton));
1378 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton));
1383 format = GST_FORMAT_BUFFERS;
1386 format = GST_FORMAT_TIME;
1387 amount *= GST_MSECOND;
1390 format = GST_FORMAT_UNDEFINED;
1394 event = gst_event_new_step (format, amount, rate, flush, FALSE);
1396 res = send_event (app, event);
1399 g_print ("Sending step event failed\n");
1404 message_received (GstBus * bus, GstMessage * message, SeekApp * app)
1406 const GstStructure *s;
1408 switch (GST_MESSAGE_TYPE (message)) {
1409 case GST_MESSAGE_ERROR:
1410 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1411 GST_DEBUG_GRAPH_SHOW_ALL, "seek.error");
1413 case GST_MESSAGE_WARNING:
1414 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1415 GST_DEBUG_GRAPH_SHOW_ALL, "seek.warning");
1421 s = gst_message_get_structure (message);
1422 g_print ("message from \"%s\" (%s): ",
1423 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
1424 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1428 sstr = gst_structure_to_string (s);
1429 g_print ("%s\n", sstr);
1432 g_print ("no message details\n");
1437 do_shuttle (SeekApp * app)
1442 duration = 40 * GST_MSECOND;
1446 gst_element_send_event (app->pipeline,
1447 gst_event_new_step (GST_FORMAT_TIME, duration, app->shuttle_rate, FALSE,
1452 msg_sync_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
1458 gboolean intermediate;
1462 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
1463 &intermediate, &duration, &eos);
1466 g_print ("stepped till EOS\n");
1470 if (g_static_mutex_trylock (&app->state_mutex)) {
1473 g_static_mutex_unlock (&app->state_mutex);
1475 /* ignore step messages that come while we are doing a state change */
1476 g_print ("state change is busy\n");
1481 shuttle_toggled (GtkToggleButton * button, SeekApp * app)
1485 active = gtk_toggle_button_get_active (button);
1487 if (active != app->shuttling) {
1488 app->shuttling = active;
1489 g_print ("shuttling %s\n", app->shuttling ? "active" : "inactive");
1491 app->shuttle_rate = 0.0;
1492 app->play_rate = 1.0;
1493 pause_cb (NULL, app);
1494 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1500 shuttle_rate_switch (SeekApp * app)
1506 if (app->state == GST_STATE_PLAYING) {
1507 /* pause when we need to */
1508 pause_cb (NULL, app);
1509 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1512 if (app->play_rate == 1.0)
1513 app->play_rate = -1.0;
1515 app->play_rate = 1.0;
1517 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", app->play_rate,
1518 GST_TIME_ARGS (app->position));
1520 flags = GST_SEEK_FLAG_FLUSH;
1521 flags |= GST_SEEK_FLAG_ACCURATE;
1523 if (app->play_rate >= 0.0) {
1524 s_event = gst_event_new_seek (app->play_rate,
1525 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
1526 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1528 s_event = gst_event_new_seek (app->play_rate,
1529 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1530 GST_SEEK_TYPE_SET, app->position);
1532 res = send_event (app, s_event);
1534 gst_element_get_state (app->pipeline, NULL, NULL, SEEK_TIMEOUT);
1536 g_print ("seek failed\n");
1541 shuttle_value_changed (GtkRange * range, SeekApp * app)
1545 rate = gtk_range_get_value (range);
1548 g_print ("rate 0.0, pause\n");
1549 pause_cb (NULL, app);
1550 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1552 g_print ("rate changed %0.3g\n", rate);
1554 if ((rate < 0.0 && app->play_rate > 0.0) || (rate > 0.0
1555 && app->play_rate < 0.0)) {
1556 shuttle_rate_switch (app);
1559 app->shuttle_rate = ABS (rate);
1560 if (app->state != GST_STATE_PLAYING) {
1562 play_cb (NULL, app);
1568 colorbalance_value_changed (GtkRange * range, SeekApp * app)
1573 GstColorBalanceChannel *channel = NULL;
1574 const GList *channels, *l;
1576 if (range == GTK_RANGE (app->contrast_scale))
1578 else if (range == GTK_RANGE (app->brightness_scale))
1579 label = "BRIGHTNESS";
1580 else if (range == GTK_RANGE (app->hue_scale))
1582 else if (range == GTK_RANGE (app->saturation_scale))
1583 label = "SATURATION";
1585 g_assert_not_reached ();
1587 val = gtk_range_get_value (range);
1589 g_print ("colorbalance %s value changed %lf\n", label, val / N_GRAD);
1591 if (!app->colorbalance_element) {
1592 find_interface_elements (app);
1593 if (!app->colorbalance_element)
1598 gst_color_balance_list_channels (GST_COLOR_BALANCE
1599 (app->colorbalance_element));
1600 for (l = channels; l; l = l->next) {
1601 GstColorBalanceChannel *tmp = l->data;
1603 if (g_strrstr (tmp->label, label)) {
1613 (gint) (0.5 + channel->min_value +
1614 (val / N_GRAD) * ((gdouble) channel->max_value -
1615 (gdouble) channel->min_value));
1616 gst_color_balance_set_value (GST_COLOR_BALANCE (app->colorbalance_element),
1621 seek_format_changed_cb (GtkComboBox * box, SeekApp * app)
1625 const GstFormatDefinition *format = NULL;
1627 format_str = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (box));
1629 for (l = app->formats; l; l = l->next) {
1630 const GstFormatDefinition *tmp = l->data;
1632 if (g_strcmp0 (tmp->nick, format_str) == 0) {
1641 app->seek_format = format;
1645 g_free (format_str);
1649 update_formats (SeekApp * app)
1656 gint selected_idx = 0, i;
1659 gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT
1660 (app->seek_format_combo));
1661 if (selected == NULL)
1662 selected = g_strdup ("time");
1664 it = gst_format_iterate_definitions ();
1667 g_list_free (app->formats);
1668 app->formats = NULL;
1671 switch (gst_iterator_next (it, &item)) {
1672 case GST_ITERATOR_OK:
1673 app->formats = g_list_prepend (app->formats, item);
1675 case GST_ITERATOR_RESYNC:
1676 g_list_free (app->formats);
1677 app->formats = NULL;
1678 gst_iterator_resync (it);
1680 case GST_ITERATOR_ERROR:
1681 case GST_ITERATOR_DONE:
1688 app->formats = g_list_reverse (app->formats);
1689 gst_iterator_free (it);
1691 g_signal_handlers_block_by_func (app->seek_format_combo,
1692 seek_format_changed_cb, app);
1693 gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (app->seek_format_combo));
1695 for (i = 0, l = app->formats; l; l = l->next, i++) {
1696 const GstFormatDefinition *def = l->data;
1698 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->seek_format_combo),
1700 if (g_strcmp0 (def->nick, selected) == 0)
1703 g_signal_handlers_unblock_by_func (app->seek_format_combo,
1704 seek_format_changed_cb, app);
1706 gtk_combo_box_set_active (GTK_COMBO_BOX (app->seek_format_combo),
1713 msg_async_done (GstBus * bus, GstMessage * message, SeekApp * app)
1715 GST_DEBUG ("async done");
1717 /* Now query all available GstFormats */
1718 update_formats (app);
1720 /* when we get ASYNC_DONE we can query position, duration and other
1724 /* update the available streams */
1725 update_streams (app);
1727 find_interface_elements (app);
1731 msg_state_changed (GstBus * bus, GstMessage * message, SeekApp * app)
1733 const GstStructure *s;
1735 s = gst_message_get_structure (message);
1737 /* We only care about state changed on the pipeline */
1738 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (app->pipeline)) {
1739 GstState old, new, pending;
1741 gst_message_parse_state_changed (message, &old, &new, &pending);
1743 /* When state of the pipeline changes to paused or playing we start updating scale */
1744 if (new == GST_STATE_PLAYING) {
1745 set_update_scale (app, TRUE);
1747 set_update_scale (app, FALSE);
1750 /* dump graph for (some) pipeline state changes */
1754 dump_name = g_strdup_printf ("seek.%s_%s",
1755 gst_element_state_get_name (old), gst_element_state_get_name (new));
1757 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1758 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
1766 msg_segment_done (GstBus * bus, GstMessage * message, SeekApp * app)
1773 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (app->position));
1774 gst_message_parse_segment_done (message, &format, &app->position);
1775 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT,
1776 GST_TIME_ARGS (app->position));
1779 /* in the segment-done callback we never flush as this would not make sense
1780 * for seamless playback. */
1782 flags |= GST_SEEK_FLAG_SEGMENT;
1784 flags |= GST_SEEK_FLAG_SKIP;
1786 s_event = gst_event_new_seek (app->rate,
1787 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1788 GST_SEEK_TYPE_SET, app->duration);
1790 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
1791 app->rate, GST_TIME_ARGS (app->duration));
1793 res = send_event (app, s_event);
1795 g_print ("segment seek failed\n");
1798 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
1801 do_stream_buffering (SeekApp * app, gint percent)
1805 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1806 bufstr = g_strdup_printf ("Buffering...%d", percent);
1807 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1810 if (percent == 100) {
1811 /* a 100% message means buffering is done */
1812 app->buffering = FALSE;
1813 /* if the desired state is playing, go back */
1814 if (app->state == GST_STATE_PLAYING) {
1815 /* no state management needed for live pipelines */
1816 if (!app->is_live) {
1817 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
1818 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1820 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1821 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
1825 /* buffering busy */
1826 if (app->buffering == FALSE && app->state == GST_STATE_PLAYING) {
1827 /* we were not buffering but PLAYING, PAUSE the pipeline. */
1828 if (!app->is_live) {
1829 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
1830 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1833 app->buffering = TRUE;
1838 do_download_buffering (SeekApp * app, gint percent)
1840 if (!app->buffering && percent < 100) {
1843 app->buffering = TRUE;
1845 bufstr = g_strdup_printf ("Downloading...");
1846 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1849 /* once we get a buffering message, we'll do the fill update */
1850 set_update_fill (app, TRUE);
1852 if (app->state == GST_STATE_PLAYING && !app->is_live) {
1853 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
1854 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1855 /* user has to manually start the playback */
1856 app->state = GST_STATE_PAUSED;
1862 msg_buffering (GstBus * bus, GstMessage * message, SeekApp * app)
1866 gst_message_parse_buffering (message, &percent);
1868 /* get more stats */
1869 gst_message_parse_buffering_stats (message, &app->mode, NULL, NULL,
1870 &app->buffering_left);
1872 switch (app->mode) {
1873 case GST_BUFFERING_DOWNLOAD:
1874 do_download_buffering (app, percent);
1876 case GST_BUFFERING_LIVE:
1877 app->is_live = TRUE;
1878 case GST_BUFFERING_TIMESHIFT:
1879 case GST_BUFFERING_STREAM:
1880 do_stream_buffering (app, percent);
1886 msg_clock_lost (GstBus * bus, GstMessage * message, SeekApp * app)
1888 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
1889 if (app->state == GST_STATE_PLAYING) {
1890 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1891 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1896 is_valid_color_balance_element (GstElement * element)
1898 GstColorBalance *bal = GST_COLOR_BALANCE (element);
1899 gboolean have_brightness = FALSE;
1900 gboolean have_contrast = FALSE;
1901 gboolean have_hue = FALSE;
1902 gboolean have_saturation = FALSE;
1903 const GList *channels, *l;
1905 channels = gst_color_balance_list_channels (bal);
1906 for (l = channels; l; l = l->next) {
1907 GstColorBalanceChannel *ch = l->data;
1909 if (g_strrstr (ch->label, "BRIGHTNESS"))
1910 have_brightness = TRUE;
1911 else if (g_strrstr (ch->label, "CONTRAST"))
1912 have_contrast = TRUE;
1913 else if (g_strrstr (ch->label, "HUE"))
1915 else if (g_strrstr (ch->label, "SATURATION"))
1916 have_saturation = TRUE;
1919 return have_brightness && have_contrast && have_hue && have_saturation;
1923 find_interface_elements (SeekApp * app)
1927 gboolean done = FALSE, hardware = FALSE;
1929 if (app->pipeline_type == 0)
1932 if (app->navigation_element)
1933 gst_object_unref (app->navigation_element);
1934 app->navigation_element = NULL;
1936 if (app->colorbalance_element)
1937 gst_object_unref (app->colorbalance_element);
1938 app->colorbalance_element = NULL;
1940 app->navigation_element =
1941 gst_bin_get_by_interface (GST_BIN (app->pipeline), GST_TYPE_NAVIGATION);
1943 it = gst_bin_iterate_all_by_interface (GST_BIN (app->pipeline),
1944 GST_TYPE_COLOR_BALANCE);
1946 switch (gst_iterator_next (it, &item)) {
1947 case GST_ITERATOR_OK:{
1948 GstElement *element = GST_ELEMENT (item);
1950 if (is_valid_color_balance_element (element)) {
1951 if (!app->colorbalance_element) {
1952 app->colorbalance_element =
1953 GST_ELEMENT_CAST (gst_object_ref (element));
1955 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1956 (element)) == GST_COLOR_BALANCE_HARDWARE);
1957 } else if (!hardware) {
1959 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1960 (element)) == GST_COLOR_BALANCE_HARDWARE);
1963 if (app->colorbalance_element)
1964 gst_object_unref (app->colorbalance_element);
1965 app->colorbalance_element =
1966 GST_ELEMENT_CAST (gst_object_ref (element));
1972 gst_object_unref (element);
1974 if (hardware && app->colorbalance_element)
1978 case GST_ITERATOR_RESYNC:
1979 gst_iterator_resync (it);
1982 if (app->colorbalance_element)
1983 gst_object_unref (app->colorbalance_element);
1984 app->colorbalance_element = NULL;
1986 case GST_ITERATOR_DONE:
1987 case GST_ITERATOR_ERROR:
1993 gst_iterator_free (it);
1996 /* called when Navigation command button is pressed */
1998 navigation_cmd_cb (GtkButton * button, SeekApp * app)
2000 GstNavigationCommand cmd = GST_NAVIGATION_COMMAND_INVALID;
2003 if (!app->navigation_element) {
2004 find_interface_elements (app);
2005 if (!app->navigation_element)
2009 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++) {
2010 if (app->navigation_buttons[i].button == GTK_WIDGET (button)) {
2011 cmd = app->navigation_buttons[i].cmd;
2016 if (cmd != GST_NAVIGATION_COMMAND_INVALID)
2017 gst_navigation_send_command (GST_NAVIGATION (app->navigation_element), cmd);
2020 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2021 /* We set the xid here in response to the prepare-xwindow-id message via a
2022 * bus sync handler because we don't know the actual videosink used from the
2023 * start (as we don't know the pipeline, or bin elements such as autovideosink
2024 * or gconfvideosink may be used which create the actual videosink only once
2025 * the pipeline is started) */
2026 static GstBusSyncReply
2027 bus_sync_handler (GstBus * bus, GstMessage * message, SeekApp * app)
2029 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
2030 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
2031 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2033 if (app->xoverlay_element)
2034 gst_object_unref (app->xoverlay_element);
2035 app->xoverlay_element = GST_ELEMENT (gst_object_ref (element));
2037 g_print ("got prepare-xwindow-id, setting XID %" G_GUINTPTR_FORMAT "\n",
2040 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2041 "force-aspect-ratio")) {
2042 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2045 /* Should have been initialised from main thread before (can't use
2046 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2047 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2048 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2049 * shouldn't be done from a non-GUI thread without explicit locking). */
2050 g_assert (app->embed_xid != 0);
2052 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), app->embed_xid);
2054 find_interface_elements (app);
2056 return GST_BUS_PASS;
2061 draw_cb (GtkWidget * widget, cairo_t * cr, SeekApp * app)
2063 if (app->state < GST_STATE_PAUSED) {
2066 width = gtk_widget_get_allocated_width (widget);
2067 height = gtk_widget_get_allocated_height (widget);
2068 cairo_set_source_rgb (cr, 0, 0, 0);
2069 cairo_rectangle (cr, 0, 0, width, height);
2074 if (app->xoverlay_element)
2075 gst_x_overlay_expose (GST_X_OVERLAY (app->xoverlay_element));
2081 realize_cb (GtkWidget * widget, SeekApp * app)
2083 GdkWindow *window = gtk_widget_get_window (widget);
2085 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2087 if (!gdk_window_ensure_native (window))
2088 g_error ("Couldn't create native window needed for GstXOverlay!");
2090 #if defined (GDK_WINDOWING_WIN32)
2091 app->embed_xid = GDK_WINDOW_HWND (window);
2092 g_print ("Window realize: video window HWND = %lu\n", app->embed_xid);
2093 #elif defined (GDK_WINDOWING_QUARTZ)
2094 app->embed_xid = gdk_quartz_window_get_nsview (window);
2095 g_print ("Window realize: video window NSView = %p\n", app->embed_xid);
2096 #elif defined (GDK_WINDOWING_X11)
2097 app->embed_xid = GDK_WINDOW_XID (window);
2098 g_print ("Window realize: video window XID = %" G_GUINTPTR_FORMAT "\n",
2104 button_press_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
2106 gtk_widget_grab_focus (widget);
2108 if (app->navigation_element)
2109 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2110 "mouse-button-press", event->button, event->x, event->y);
2116 button_release_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
2118 if (app->navigation_element)
2119 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2120 "mouse-button-release", event->button, event->x, event->y);
2126 key_press_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
2128 if (app->navigation_element)
2129 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
2130 "key-press", gdk_keyval_name (event->keyval));
2136 key_release_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
2138 if (app->navigation_element)
2139 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
2140 "key-release", gdk_keyval_name (event->keyval));
2146 motion_notify_cb (GtkWidget * widget, GdkEventMotion * event, SeekApp * app)
2148 if (app->navigation_element)
2149 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2150 "mouse-move", 0, event->x, event->y);
2156 msg_eos (GstBus * bus, GstMessage * message, SeekApp * app)
2158 message_received (bus, message, app);
2160 /* Set new uri for playerbins and continue playback */
2161 if (app->current_path && app->pipeline_type == 0) {
2162 stop_cb (NULL, app);
2163 app->current_path = g_list_next (app->current_path);
2164 if (app->current_path) {
2165 playbin_set_uri (app->pipeline, app->current_path->data);
2166 play_cb (NULL, app);
2172 msg_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
2174 if (!app->shuttling)
2175 message_received (bus, message, app);
2179 msg (GstBus * bus, GstMessage * message, SeekApp * app)
2181 GstNavigationMessageType nav_type;
2183 nav_type = gst_navigation_message_get_type (message);
2185 case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
2189 /* Heuristic to detect if we're dealing with a DVD menu */
2190 query = gst_navigation_query_new_commands ();
2191 res = gst_element_query (GST_ELEMENT (GST_MESSAGE_SRC (message)), query);
2193 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++)
2194 gtk_widget_set_sensitive (app->navigation_buttons[j].button, FALSE);
2197 gboolean is_menu = FALSE;
2200 if (gst_navigation_query_parse_commands_length (query, &n)) {
2201 for (i = 0; i < n; i++) {
2202 GstNavigationCommand cmd;
2204 if (!gst_navigation_query_parse_commands_nth (query, i, &cmd))
2207 is_menu |= (cmd == GST_NAVIGATION_COMMAND_ACTIVATE);
2208 is_menu |= (cmd == GST_NAVIGATION_COMMAND_LEFT);
2209 is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
2210 is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
2211 is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
2213 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++) {
2214 if (app->navigation_buttons[j].cmd != cmd)
2217 gtk_widget_set_sensitive (app->navigation_buttons[j].button,
2223 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), !is_menu);
2225 g_assert_not_reached ();
2228 gst_query_unref (query);
2229 message_received (bus, message, app);
2238 connect_bus_signals (SeekApp * app)
2240 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
2242 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2243 if (app->pipeline_type != 0) {
2244 /* handle prepare-xwindow-id element message synchronously, but only for non-playbin2 */
2245 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, app);
2249 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2250 gst_bus_enable_sync_message_emission (bus);
2252 g_signal_connect (bus, "message::state-changed",
2253 G_CALLBACK (msg_state_changed), app);
2254 g_signal_connect (bus, "message::segment-done", G_CALLBACK (msg_segment_done),
2256 g_signal_connect (bus, "message::async-done", G_CALLBACK (msg_async_done),
2259 g_signal_connect (bus, "message::new-clock", G_CALLBACK (message_received),
2261 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (msg_clock_lost),
2263 g_signal_connect (bus, "message::error", G_CALLBACK (message_received), app);
2264 g_signal_connect (bus, "message::warning", G_CALLBACK (message_received),
2266 g_signal_connect (bus, "message::eos", G_CALLBACK (msg_eos), app);
2267 g_signal_connect (bus, "message::tag", G_CALLBACK (message_received), app);
2268 g_signal_connect (bus, "message::element", G_CALLBACK (message_received),
2270 g_signal_connect (bus, "message::segment-done", G_CALLBACK (message_received),
2272 g_signal_connect (bus, "message::buffering", G_CALLBACK (msg_buffering), app);
2273 // g_signal_connect (bus, "message::step-done", G_CALLBACK (msg_step_done),
2275 g_signal_connect (bus, "message::step-start", G_CALLBACK (msg_step_done),
2277 g_signal_connect (bus, "sync-message::step-done",
2278 G_CALLBACK (msg_sync_step_done), app);
2279 g_signal_connect (bus, "message", G_CALLBACK (msg), app);
2281 gst_object_unref (bus);
2284 /* Return GList of paths described in location string */
2286 handle_wildcards (const gchar * location)
2289 gchar *path = g_path_get_dirname (location);
2290 gchar *pattern = g_path_get_basename (location);
2291 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2292 GDir *dir = g_dir_open (path, 0, NULL);
2295 g_print ("matching %s from %s\n", pattern, path);
2298 g_print ("opening directory %s failed\n", path);
2302 while ((name = g_dir_read_name (dir)) != NULL) {
2303 if (g_pattern_match_string (pspec, name)) {
2304 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2305 g_print (" found clip %s\n", name);
2311 g_pattern_spec_free (pspec);
2319 delete_event_cb (GtkWidget * widget, GdkEvent * event, SeekApp * app)
2321 stop_cb (NULL, app);
2326 video_sink_activate_cb (GtkEntry * entry, SeekApp * app)
2328 GstElement *sink = NULL;
2331 text = gtk_entry_get_text (entry);
2332 if (text != NULL && *text != '\0') {
2333 sink = gst_element_factory_make_or_warn (text, NULL);
2336 g_object_set (app->pipeline, "video-sink", sink, NULL);
2340 audio_sink_activate_cb (GtkEntry * entry, SeekApp * app)
2342 GstElement *sink = NULL;
2345 text = gtk_entry_get_text (entry);
2346 if (text != NULL && *text != '\0') {
2347 sink = gst_element_factory_make_or_warn (text, NULL);
2350 g_object_set (app->pipeline, "audio-sink", sink, NULL);
2354 text_sink_activate_cb (GtkEntry * entry, SeekApp * app)
2356 GstElement *sink = NULL;
2359 text = gtk_entry_get_text (entry);
2360 if (text != NULL && *text != '\0') {
2361 sink = gst_element_factory_make_or_warn (text, NULL);
2364 g_object_set (app->pipeline, "text-sink", sink, NULL);
2368 buffer_size_activate_cb (GtkEntry * entry, SeekApp * app)
2372 text = gtk_entry_get_text (entry);
2373 if (text != NULL && *text != '\0') {
2377 v = g_ascii_strtoll (text, &endptr, 10);
2378 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2379 g_object_set (app->pipeline, "buffer-size", v, NULL);
2385 buffer_duration_activate_cb (GtkEntry * entry, SeekApp * app)
2389 text = gtk_entry_get_text (entry);
2390 if (text != NULL && *text != '\0') {
2394 v = g_ascii_strtoll (text, &endptr, 10);
2395 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2396 g_object_set (app->pipeline, "buffer-duration", v, NULL);
2402 ringbuffer_maxsize_activate_cb (GtkEntry * entry, SeekApp * app)
2406 text = gtk_entry_get_text (entry);
2407 if (text != NULL && *text != '\0') {
2411 v = g_ascii_strtoull (text, &endptr, 10);
2412 if (endptr != text && v != G_MAXUINT64) {
2413 g_object_set (app->pipeline, "ring-buffer-max-size", v, NULL);
2419 connection_speed_activate_cb (GtkEntry * entry, SeekApp * app)
2423 text = gtk_entry_get_text (entry);
2424 if (text != NULL && *text != '\0') {
2428 v = g_ascii_strtoll (text, &endptr, 10);
2429 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2430 g_object_set (app->pipeline, "connection-speed", v, NULL);
2436 subtitle_encoding_activate_cb (GtkEntry * entry, SeekApp * app)
2440 text = gtk_entry_get_text (entry);
2441 g_object_set (app->pipeline, "subtitle-encoding", text, NULL);
2445 subtitle_fontdesc_cb (GtkFontButton * button, SeekApp * app)
2449 text = gtk_font_button_get_font_name (button);
2450 g_object_set (app->pipeline, "subtitle-font-desc", text, NULL);
2454 av_offset_activate_cb (GtkEntry * entry, SeekApp * app)
2458 text = gtk_entry_get_text (entry);
2459 if (text != NULL && *text != '\0') {
2463 v = g_ascii_strtoll (text, &endptr, 10);
2464 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2465 g_object_set (app->pipeline, "av-offset", v, NULL);
2471 print_usage (int argc, char **argv)
2475 g_print ("usage: %s <type> <filename>\n", argv[0]);
2476 g_print (" possible types:\n");
2478 for (i = 0; i < G_N_ELEMENTS (pipelines); i++) {
2479 g_print (" %d = %s\n", i, pipelines[i].name);
2484 create_ui (SeekApp * app)
2486 GtkWidget *hbox, *vbox, *seek, *playbin, *step, *navigation, *colorbalance;
2487 GtkWidget *play_button, *pause_button, *stop_button;
2488 GtkAdjustment *adjustment;
2490 /* initialize gui elements ... */
2491 app->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2492 app->video_window = gtk_drawing_area_new ();
2493 g_signal_connect (app->video_window, "draw", G_CALLBACK (draw_cb), app);
2494 g_signal_connect (app->video_window, "realize", G_CALLBACK (realize_cb), app);
2495 g_signal_connect (app->video_window, "button-press-event",
2496 G_CALLBACK (button_press_cb), app);
2497 g_signal_connect (app->video_window, "button-release-event",
2498 G_CALLBACK (button_release_cb), app);
2499 g_signal_connect (app->video_window, "key-press-event",
2500 G_CALLBACK (key_press_cb), app);
2501 g_signal_connect (app->video_window, "key-release-event",
2502 G_CALLBACK (key_release_cb), app);
2503 g_signal_connect (app->video_window, "motion-notify-event",
2504 G_CALLBACK (motion_notify_cb), app);
2505 gtk_widget_set_can_focus (app->video_window, TRUE);
2506 gtk_widget_set_double_buffered (app->video_window, FALSE);
2507 gtk_widget_add_events (app->video_window,
2508 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
2509 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2511 app->statusbar = gtk_statusbar_new ();
2513 gtk_statusbar_get_context_id (GTK_STATUSBAR (app->statusbar), "seek");
2514 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
2516 hbox = gtk_hbox_new (FALSE, 0);
2517 vbox = gtk_vbox_new (FALSE, 0);
2518 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2520 /* media controls */
2521 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2522 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2523 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2527 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox,
2529 GtkWidget *scrub_checkbox, *play_scrub_checkbox, *rate_label;
2530 GtkWidget *skip_checkbox, *rate_spinbutton;
2531 GtkWidget *flagtable, *advanced_seek, *advanced_seek_grid;
2532 GtkWidget *duration_label, *position_label, *seek_button;
2534 seek = gtk_expander_new ("seek options");
2535 flagtable = gtk_grid_new ();
2536 gtk_grid_set_row_spacing (GTK_GRID (flagtable), 2);
2537 gtk_grid_set_row_homogeneous (GTK_GRID (flagtable), FALSE);
2538 gtk_grid_set_column_spacing (GTK_GRID (flagtable), 2);
2539 gtk_grid_set_column_homogeneous (GTK_GRID (flagtable), TRUE);
2541 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2542 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2543 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2544 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2545 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2546 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2547 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2548 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2549 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2550 rate_label = gtk_label_new ("Rate");
2552 gtk_widget_set_tooltip_text (accurate_checkbox,
2553 "accurate position is requested, this might be considerably slower for some formats");
2554 gtk_widget_set_tooltip_text (key_checkbox,
2555 "seek to the nearest keyframe. This might be faster but less accurate");
2556 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2557 gtk_widget_set_tooltip_text (flush_checkbox,
2558 "flush pipeline after seeking");
2559 gtk_widget_set_tooltip_text (rate_spinbutton,
2560 "define the playback rate, " "negative value trigger reverse playback");
2561 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2562 gtk_widget_set_tooltip_text (play_scrub_checkbox,
2563 "play video while seeking");
2564 gtk_widget_set_tooltip_text (skip_checkbox,
2565 "Skip frames while playing at high frame rates");
2567 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2568 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2570 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), app->rate);
2572 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2573 G_CALLBACK (accurate_toggle_cb), app);
2574 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2575 G_CALLBACK (key_toggle_cb), app);
2576 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2577 G_CALLBACK (loop_toggle_cb), app);
2578 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2579 G_CALLBACK (flush_toggle_cb), app);
2580 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2581 G_CALLBACK (scrub_toggle_cb), app);
2582 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2583 G_CALLBACK (play_scrub_toggle_cb), app);
2584 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2585 G_CALLBACK (skip_toggle_cb), app);
2586 g_signal_connect (G_OBJECT (rate_spinbutton), "value-changed",
2587 G_CALLBACK (rate_spinbutton_changed_cb), app);
2589 gtk_grid_attach (GTK_GRID (flagtable), accurate_checkbox, 0, 0, 1, 1);
2590 gtk_grid_attach (GTK_GRID (flagtable), flush_checkbox, 1, 0, 1, 1);
2591 gtk_grid_attach (GTK_GRID (flagtable), loop_checkbox, 2, 0, 1, 1);
2592 gtk_grid_attach (GTK_GRID (flagtable), key_checkbox, 0, 1, 1, 1);
2593 gtk_grid_attach (GTK_GRID (flagtable), scrub_checkbox, 1, 1, 1, 1);
2594 gtk_grid_attach (GTK_GRID (flagtable), play_scrub_checkbox, 2, 1, 1, 1);
2595 gtk_grid_attach (GTK_GRID (flagtable), skip_checkbox, 3, 0, 1, 1);
2596 gtk_grid_attach (GTK_GRID (flagtable), rate_label, 4, 0, 1, 1);
2597 gtk_grid_attach (GTK_GRID (flagtable), rate_spinbutton, 4, 1, 1, 1);
2599 advanced_seek = gtk_frame_new ("Advanced Seek");
2600 advanced_seek_grid = gtk_grid_new ();
2601 gtk_grid_set_row_spacing (GTK_GRID (advanced_seek_grid), 2);
2602 gtk_grid_set_row_homogeneous (GTK_GRID (advanced_seek_grid), FALSE);
2603 gtk_grid_set_column_spacing (GTK_GRID (advanced_seek_grid), 5);
2604 gtk_grid_set_column_homogeneous (GTK_GRID (advanced_seek_grid), FALSE);
2606 app->seek_format_combo = gtk_combo_box_text_new ();
2607 g_signal_connect (app->seek_format_combo, "changed",
2608 G_CALLBACK (seek_format_changed_cb), app);
2609 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_format_combo, 0,
2612 app->seek_entry = gtk_entry_new ();
2613 gtk_entry_set_width_chars (GTK_ENTRY (app->seek_entry), 12);
2614 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_entry, 0, 1, 1,
2617 seek_button = gtk_button_new_with_label ("Seek");
2618 g_signal_connect (G_OBJECT (seek_button), "clicked",
2619 G_CALLBACK (advanced_seek_button_cb), app);
2620 gtk_grid_attach (GTK_GRID (advanced_seek_grid), seek_button, 1, 0, 1, 1);
2622 position_label = gtk_label_new ("Position:");
2623 gtk_grid_attach (GTK_GRID (advanced_seek_grid), position_label, 2, 0, 1, 1);
2624 duration_label = gtk_label_new ("Duration:");
2625 gtk_grid_attach (GTK_GRID (advanced_seek_grid), duration_label, 2, 1, 1, 1);
2627 app->seek_position_label = gtk_label_new ("-1");
2628 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_position_label, 3,
2630 app->seek_duration_label = gtk_label_new ("-1");
2631 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_duration_label, 3,
2634 gtk_container_add (GTK_CONTAINER (advanced_seek), advanced_seek_grid);
2635 gtk_grid_attach (GTK_GRID (flagtable), advanced_seek, 0, 2, 3, 2);
2636 gtk_container_add (GTK_CONTAINER (seek), flagtable);
2642 GtkWidget *step_button, *shuttle_checkbox;
2644 step = gtk_expander_new ("step options");
2645 hbox = gtk_hbox_new (FALSE, 0);
2647 app->step_format_combo = gtk_combo_box_text_new ();
2648 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->step_format_combo),
2650 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->step_format_combo),
2652 gtk_combo_box_set_active (GTK_COMBO_BOX (app->step_format_combo), 0);
2653 gtk_box_pack_start (GTK_BOX (hbox), app->step_format_combo, FALSE, FALSE,
2656 app->step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2657 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2659 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2661 gtk_box_pack_start (GTK_BOX (hbox), app->step_amount_spinbutton, FALSE,
2664 app->step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2665 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_rate_spinbutton), 3);
2666 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton),
2668 gtk_box_pack_start (GTK_BOX (hbox), app->step_rate_spinbutton, FALSE, FALSE,
2671 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2672 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2673 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2675 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2679 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2680 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2681 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2682 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2686 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2687 app->shuttle_scale = gtk_hscale_new (adjustment);
2688 gtk_scale_set_digits (GTK_SCALE (app->shuttle_scale), 2);
2689 gtk_scale_set_value_pos (GTK_SCALE (app->shuttle_scale), GTK_POS_TOP);
2690 g_signal_connect (app->shuttle_scale, "value-changed",
2691 G_CALLBACK (shuttle_value_changed), app);
2692 g_signal_connect (app->shuttle_scale, "format_value",
2693 G_CALLBACK (shuttle_format_value), app);
2695 gtk_box_pack_start (GTK_BOX (hbox), app->shuttle_scale, TRUE, TRUE, 2);
2697 gtk_container_add (GTK_CONTAINER (step), hbox);
2700 /* navigation command expander */
2702 GtkWidget *navigation_button;
2706 navigation = gtk_expander_new ("navigation commands");
2707 grid = gtk_grid_new ();
2708 gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
2709 gtk_grid_set_row_homogeneous (GTK_GRID (grid), FALSE);
2710 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2711 gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
2713 navigation_button = gtk_button_new_with_label ("Menu 1");
2714 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2715 G_CALLBACK (navigation_cmd_cb), app);
2716 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2717 gtk_widget_set_sensitive (navigation_button, FALSE);
2718 gtk_widget_set_tooltip_text (navigation_button, "DVD Menu");
2719 app->navigation_buttons[i].button = navigation_button;
2720 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU1;
2722 navigation_button = gtk_button_new_with_label ("Menu 2");
2723 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2724 G_CALLBACK (navigation_cmd_cb), app);
2725 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2726 gtk_widget_set_sensitive (navigation_button, FALSE);
2727 gtk_widget_set_tooltip_text (navigation_button, "DVD Title Menu");
2728 app->navigation_buttons[i].button = navigation_button;
2729 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU2;
2731 navigation_button = gtk_button_new_with_label ("Menu 3");
2732 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2733 G_CALLBACK (navigation_cmd_cb), app);
2734 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2735 gtk_widget_set_sensitive (navigation_button, FALSE);
2736 gtk_widget_set_tooltip_text (navigation_button, "DVD Root Menu");
2737 app->navigation_buttons[i].button = navigation_button;
2738 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU3;
2740 navigation_button = gtk_button_new_with_label ("Menu 4");
2741 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2742 G_CALLBACK (navigation_cmd_cb), app);
2743 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2744 gtk_widget_set_sensitive (navigation_button, FALSE);
2745 gtk_widget_set_tooltip_text (navigation_button, "DVD Subpicture Menu");
2746 app->navigation_buttons[i].button = navigation_button;
2747 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU4;
2749 navigation_button = gtk_button_new_with_label ("Menu 5");
2750 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2751 G_CALLBACK (navigation_cmd_cb), app);
2752 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2753 gtk_widget_set_sensitive (navigation_button, FALSE);
2754 gtk_widget_set_tooltip_text (navigation_button, "DVD Audio Menu");
2755 app->navigation_buttons[i].button = navigation_button;
2756 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU5;
2758 navigation_button = gtk_button_new_with_label ("Menu 6");
2759 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2760 G_CALLBACK (navigation_cmd_cb), app);
2761 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2762 gtk_widget_set_sensitive (navigation_button, FALSE);
2763 gtk_widget_set_tooltip_text (navigation_button, "DVD Angle Menu");
2764 app->navigation_buttons[i].button = navigation_button;
2765 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU6;
2767 navigation_button = gtk_button_new_with_label ("Menu 7");
2768 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2769 G_CALLBACK (navigation_cmd_cb), app);
2770 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2771 gtk_widget_set_sensitive (navigation_button, FALSE);
2772 gtk_widget_set_tooltip_text (navigation_button, "DVD Chapter Menu");
2773 app->navigation_buttons[i].button = navigation_button;
2774 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU7;
2776 navigation_button = gtk_button_new_with_label ("Left");
2777 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2778 G_CALLBACK (navigation_cmd_cb), app);
2779 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2780 gtk_widget_set_sensitive (navigation_button, FALSE);
2781 app->navigation_buttons[i].button = navigation_button;
2782 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_LEFT;
2784 navigation_button = gtk_button_new_with_label ("Right");
2785 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2786 G_CALLBACK (navigation_cmd_cb), app);
2787 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2788 gtk_widget_set_sensitive (navigation_button, FALSE);
2789 app->navigation_buttons[i].button = navigation_button;
2790 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_RIGHT;
2792 navigation_button = gtk_button_new_with_label ("Up");
2793 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2794 G_CALLBACK (navigation_cmd_cb), app);
2795 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2796 gtk_widget_set_sensitive (navigation_button, FALSE);
2797 app->navigation_buttons[i].button = navigation_button;
2798 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_UP;
2800 navigation_button = gtk_button_new_with_label ("Down");
2801 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2802 G_CALLBACK (navigation_cmd_cb), app);
2803 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2804 gtk_widget_set_sensitive (navigation_button, FALSE);
2805 app->navigation_buttons[i].button = navigation_button;
2806 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_DOWN;
2808 navigation_button = gtk_button_new_with_label ("Activate");
2809 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2810 G_CALLBACK (navigation_cmd_cb), app);
2811 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2812 gtk_widget_set_sensitive (navigation_button, FALSE);
2813 app->navigation_buttons[i].button = navigation_button;
2814 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_ACTIVATE;
2816 navigation_button = gtk_button_new_with_label ("Prev. Angle");
2817 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2818 G_CALLBACK (navigation_cmd_cb), app);
2819 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2820 gtk_widget_set_sensitive (navigation_button, FALSE);
2821 app->navigation_buttons[i].button = navigation_button;
2822 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_PREV_ANGLE;
2824 navigation_button = gtk_button_new_with_label ("Next. Angle");
2825 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2826 G_CALLBACK (navigation_cmd_cb), app);
2827 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2828 gtk_widget_set_sensitive (navigation_button, FALSE);
2829 app->navigation_buttons[i].button = navigation_button;
2830 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_NEXT_ANGLE;
2832 gtk_container_add (GTK_CONTAINER (navigation), grid);
2835 /* colorbalance expander */
2837 GtkWidget *vbox, *frame;
2839 colorbalance = gtk_expander_new ("color balance options");
2840 vbox = gtk_vbox_new (FALSE, 0);
2842 /* contrast scale */
2843 frame = gtk_frame_new ("Contrast");
2845 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2847 app->contrast_scale = gtk_hscale_new (adjustment);
2848 gtk_scale_set_draw_value (GTK_SCALE (app->contrast_scale), FALSE);
2849 g_signal_connect (app->contrast_scale, "value-changed",
2850 G_CALLBACK (colorbalance_value_changed), app);
2851 gtk_container_add (GTK_CONTAINER (frame), app->contrast_scale);
2852 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2854 /* brightness scale */
2855 frame = gtk_frame_new ("Brightness");
2857 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2859 app->brightness_scale = gtk_hscale_new (adjustment);
2860 gtk_scale_set_draw_value (GTK_SCALE (app->brightness_scale), FALSE);
2861 g_signal_connect (app->brightness_scale, "value-changed",
2862 G_CALLBACK (colorbalance_value_changed), app);
2863 gtk_container_add (GTK_CONTAINER (frame), app->brightness_scale);
2864 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2867 frame = gtk_frame_new ("Hue");
2869 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2871 app->hue_scale = gtk_hscale_new (adjustment);
2872 gtk_scale_set_draw_value (GTK_SCALE (app->hue_scale), FALSE);
2873 g_signal_connect (app->hue_scale, "value-changed",
2874 G_CALLBACK (colorbalance_value_changed), app);
2875 gtk_container_add (GTK_CONTAINER (frame), app->hue_scale);
2876 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2878 /* saturation scale */
2879 frame = gtk_frame_new ("Saturation");
2881 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2883 app->saturation_scale = gtk_hscale_new (adjustment);
2884 gtk_scale_set_draw_value (GTK_SCALE (app->saturation_scale), FALSE);
2885 g_signal_connect (app->saturation_scale, "value-changed",
2886 G_CALLBACK (colorbalance_value_changed), app);
2887 gtk_container_add (GTK_CONTAINER (frame), app->saturation_scale);
2888 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2890 gtk_container_add (GTK_CONTAINER (colorbalance), vbox);
2895 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2896 app->seek_scale = gtk_hscale_new (adjustment);
2897 gtk_scale_set_digits (GTK_SCALE (app->seek_scale), 2);
2898 gtk_scale_set_value_pos (GTK_SCALE (app->seek_scale), GTK_POS_RIGHT);
2899 gtk_range_set_show_fill_level (GTK_RANGE (app->seek_scale), TRUE);
2900 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), N_GRAD);
2902 g_signal_connect (app->seek_scale, "button_press_event",
2903 G_CALLBACK (start_seek), app);
2904 g_signal_connect (app->seek_scale, "button_release_event",
2905 G_CALLBACK (stop_seek), app);
2906 g_signal_connect (app->seek_scale, "format_value", G_CALLBACK (format_value),
2909 if (app->pipeline_type == 0) {
2910 GtkWidget *pb2vbox, *boxes, *boxes2, *panel, *boxes3;
2911 GtkWidget *volume_label, *shot_button;
2914 playbin = gtk_expander_new ("playbin2 options");
2915 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2916 panel = gtk_hbox_new (FALSE, 0);
2917 app->video_combo = gtk_combo_box_text_new ();
2918 app->audio_combo = gtk_combo_box_text_new ();
2919 app->text_combo = gtk_combo_box_text_new ();
2920 gtk_widget_set_sensitive (app->video_combo, FALSE);
2921 gtk_widget_set_sensitive (app->audio_combo, FALSE);
2922 gtk_widget_set_sensitive (app->text_combo, FALSE);
2923 gtk_box_pack_start (GTK_BOX (panel), app->video_combo, TRUE, TRUE, 2);
2924 gtk_box_pack_start (GTK_BOX (panel), app->audio_combo, TRUE, TRUE, 2);
2925 gtk_box_pack_start (GTK_BOX (panel), app->text_combo, TRUE, TRUE, 2);
2926 g_signal_connect (G_OBJECT (app->video_combo), "changed",
2927 G_CALLBACK (video_combo_cb), app);
2928 g_signal_connect (G_OBJECT (app->audio_combo), "changed",
2929 G_CALLBACK (audio_combo_cb), app);
2930 g_signal_connect (G_OBJECT (app->text_combo), "changed",
2931 G_CALLBACK (text_combo_cb), app);
2932 /* playbin2 panel for flag checkboxes and volume/mute */
2933 boxes = gtk_grid_new ();
2934 gtk_grid_set_row_spacing (GTK_GRID (boxes), 2);
2935 gtk_grid_set_row_homogeneous (GTK_GRID (boxes), FALSE);
2936 gtk_grid_set_column_spacing (GTK_GRID (boxes), 2);
2937 gtk_grid_set_column_homogeneous (GTK_GRID (boxes), TRUE);
2939 app->video_checkbox = gtk_check_button_new_with_label ("Video");
2940 app->audio_checkbox = gtk_check_button_new_with_label ("Audio");
2941 app->text_checkbox = gtk_check_button_new_with_label ("Text");
2942 app->vis_checkbox = gtk_check_button_new_with_label ("Vis");
2943 app->soft_volume_checkbox = gtk_check_button_new_with_label ("Soft Volume");
2944 app->native_audio_checkbox =
2945 gtk_check_button_new_with_label ("Native Audio");
2946 app->native_video_checkbox =
2947 gtk_check_button_new_with_label ("Native Video");
2948 app->download_checkbox = gtk_check_button_new_with_label ("Download");
2949 app->buffering_checkbox = gtk_check_button_new_with_label ("Buffering");
2950 app->deinterlace_checkbox = gtk_check_button_new_with_label ("Deinterlace");
2951 app->soft_colorbalance_checkbox =
2952 gtk_check_button_new_with_label ("Soft Colorbalance");
2953 app->mute_checkbox = gtk_check_button_new_with_label ("Mute");
2954 volume_label = gtk_label_new ("Volume");
2955 app->volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2957 gtk_grid_attach (GTK_GRID (boxes), app->video_checkbox, 0, 0, 1, 1);
2958 gtk_grid_attach (GTK_GRID (boxes), app->audio_checkbox, 1, 0, 1, 1);
2959 gtk_grid_attach (GTK_GRID (boxes), app->text_checkbox, 2, 0, 1, 1);
2960 gtk_grid_attach (GTK_GRID (boxes), app->vis_checkbox, 3, 0, 1, 1);
2961 gtk_grid_attach (GTK_GRID (boxes), app->soft_volume_checkbox, 4, 0, 1, 1);
2962 gtk_grid_attach (GTK_GRID (boxes), app->native_audio_checkbox, 5, 0, 1, 1);
2963 gtk_grid_attach (GTK_GRID (boxes), app->native_video_checkbox, 0, 1, 1, 1);
2964 gtk_grid_attach (GTK_GRID (boxes), app->download_checkbox, 1, 1, 1, 1);
2965 gtk_grid_attach (GTK_GRID (boxes), app->buffering_checkbox, 2, 1, 1, 1);
2966 gtk_grid_attach (GTK_GRID (boxes), app->deinterlace_checkbox, 3, 1, 1, 1);
2967 gtk_grid_attach (GTK_GRID (boxes), app->soft_colorbalance_checkbox, 4, 1, 1,
2970 gtk_grid_attach (GTK_GRID (boxes), app->mute_checkbox, 7, 0, 2, 1);
2971 gtk_grid_attach (GTK_GRID (boxes), volume_label, 6, 1, 1, 1);
2972 gtk_grid_attach (GTK_GRID (boxes), app->volume_spinbutton, 7, 1, 1, 1);
2974 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->video_checkbox),
2976 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->audio_checkbox),
2978 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->text_checkbox), TRUE);
2979 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->vis_checkbox), FALSE);
2980 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->soft_volume_checkbox),
2982 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
2983 (app->native_audio_checkbox), FALSE);
2984 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
2985 (app->native_video_checkbox), FALSE);
2986 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->download_checkbox),
2988 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->buffering_checkbox),
2990 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->deinterlace_checkbox),
2992 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
2993 (app->soft_colorbalance_checkbox), TRUE);
2994 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
2996 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton), 1.0);
2998 g_signal_connect (G_OBJECT (app->video_checkbox), "toggled",
2999 G_CALLBACK (video_toggle_cb), app);
3000 g_signal_connect (G_OBJECT (app->audio_checkbox), "toggled",
3001 G_CALLBACK (audio_toggle_cb), app);
3002 g_signal_connect (G_OBJECT (app->text_checkbox), "toggled",
3003 G_CALLBACK (text_toggle_cb), app);
3004 g_signal_connect (G_OBJECT (app->vis_checkbox), "toggled",
3005 G_CALLBACK (vis_toggle_cb), app);
3006 g_signal_connect (G_OBJECT (app->soft_volume_checkbox), "toggled",
3007 G_CALLBACK (soft_volume_toggle_cb), app);
3008 g_signal_connect (G_OBJECT (app->native_audio_checkbox), "toggled",
3009 G_CALLBACK (native_audio_toggle_cb), app);
3010 g_signal_connect (G_OBJECT (app->native_video_checkbox), "toggled",
3011 G_CALLBACK (native_video_toggle_cb), app);
3012 g_signal_connect (G_OBJECT (app->download_checkbox), "toggled",
3013 G_CALLBACK (download_toggle_cb), app);
3014 g_signal_connect (G_OBJECT (app->buffering_checkbox), "toggled",
3015 G_CALLBACK (buffering_toggle_cb), app);
3016 g_signal_connect (G_OBJECT (app->deinterlace_checkbox), "toggled",
3017 G_CALLBACK (deinterlace_toggle_cb), app);
3018 g_signal_connect (G_OBJECT (app->soft_colorbalance_checkbox), "toggled",
3019 G_CALLBACK (soft_colorbalance_toggle_cb), app);
3020 g_signal_connect (G_OBJECT (app->mute_checkbox), "toggled",
3021 G_CALLBACK (mute_toggle_cb), app);
3022 g_signal_connect (G_OBJECT (app->volume_spinbutton), "value-changed",
3023 G_CALLBACK (volume_spinbutton_changed_cb), app);
3024 /* playbin2 panel for snapshot */
3025 boxes2 = gtk_hbox_new (FALSE, 0);
3026 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
3027 gtk_widget_set_tooltip_text (shot_button,
3028 "save a screenshot .png in the current directory");
3029 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
3031 app->vis_combo = gtk_combo_box_text_new ();
3032 g_signal_connect (G_OBJECT (app->vis_combo), "changed",
3033 G_CALLBACK (vis_combo_cb), app);
3034 gtk_widget_set_sensitive (app->vis_combo, FALSE);
3035 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
3036 gtk_box_pack_start (GTK_BOX (boxes2), app->vis_combo, TRUE, TRUE, 2);
3038 /* fill the vis combo box and the array of factories */
3039 init_visualization_features (app);
3041 /* Grid with other properties */
3042 boxes3 = gtk_grid_new ();
3043 gtk_grid_set_row_spacing (GTK_GRID (boxes3), 2);
3044 gtk_grid_set_row_homogeneous (GTK_GRID (boxes3), FALSE);
3045 gtk_grid_set_column_spacing (GTK_GRID (boxes3), 2);
3046 gtk_grid_set_column_homogeneous (GTK_GRID (boxes3), TRUE);
3048 label = gtk_label_new ("Video sink");
3049 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 0, 1, 1);
3050 app->video_sink_entry = gtk_entry_new ();
3051 g_signal_connect (app->video_sink_entry, "activate",
3052 G_CALLBACK (video_sink_activate_cb), app);
3053 gtk_grid_attach (GTK_GRID (boxes3), app->video_sink_entry, 0, 1, 1, 1);
3055 label = gtk_label_new ("Audio sink");
3056 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 0, 1, 1);
3057 app->audio_sink_entry = gtk_entry_new ();
3058 g_signal_connect (app->audio_sink_entry, "activate",
3059 G_CALLBACK (audio_sink_activate_cb), app);
3060 gtk_grid_attach (GTK_GRID (boxes3), app->audio_sink_entry, 1, 1, 1, 1);
3062 label = gtk_label_new ("Text sink");
3063 gtk_grid_attach (GTK_GRID (boxes3), label, 2, 0, 1, 1);
3064 app->text_sink_entry = gtk_entry_new ();
3065 g_signal_connect (app->text_sink_entry, "activate",
3066 G_CALLBACK (text_sink_activate_cb), app);
3067 gtk_grid_attach (GTK_GRID (boxes3), app->text_sink_entry, 2, 1, 1, 1);
3069 label = gtk_label_new ("Buffer Size");
3070 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 2, 1, 1);
3071 app->buffer_size_entry = gtk_entry_new ();
3072 gtk_entry_set_text (GTK_ENTRY (app->buffer_size_entry), "-1");
3073 g_signal_connect (app->buffer_size_entry, "activate",
3074 G_CALLBACK (buffer_size_activate_cb), app);
3075 gtk_grid_attach (GTK_GRID (boxes3), app->buffer_size_entry, 0, 3, 1, 1);
3077 label = gtk_label_new ("Buffer Duration");
3078 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 2, 1, 1);
3079 app->buffer_duration_entry = gtk_entry_new ();
3080 gtk_entry_set_text (GTK_ENTRY (app->buffer_duration_entry), "-1");
3081 g_signal_connect (app->buffer_duration_entry, "activate",
3082 G_CALLBACK (buffer_duration_activate_cb), app);
3083 gtk_grid_attach (GTK_GRID (boxes3), app->buffer_duration_entry, 1, 3, 1, 1);
3085 label = gtk_label_new ("Ringbuffer Max Size");
3086 gtk_grid_attach (GTK_GRID (boxes3), label, 2, 2, 1, 1);
3087 app->ringbuffer_maxsize_entry = gtk_entry_new ();
3088 gtk_entry_set_text (GTK_ENTRY (app->ringbuffer_maxsize_entry), "0");
3089 g_signal_connect (app->ringbuffer_maxsize_entry, "activate",
3090 G_CALLBACK (ringbuffer_maxsize_activate_cb), app);
3091 gtk_grid_attach (GTK_GRID (boxes3), app->ringbuffer_maxsize_entry, 2, 3, 1,
3094 label = gtk_label_new ("Connection Speed");
3095 gtk_grid_attach (GTK_GRID (boxes3), label, 3, 2, 1, 1);
3096 app->connection_speed_entry = gtk_entry_new ();
3097 gtk_entry_set_text (GTK_ENTRY (app->connection_speed_entry), "0");
3098 g_signal_connect (app->connection_speed_entry, "activate",
3099 G_CALLBACK (connection_speed_activate_cb), app);
3100 gtk_grid_attach (GTK_GRID (boxes3), app->connection_speed_entry, 3, 3, 1,
3103 label = gtk_label_new ("A/V offset");
3104 gtk_grid_attach (GTK_GRID (boxes3), label, 4, 2, 1, 1);
3105 app->av_offset_entry = gtk_entry_new ();
3106 g_signal_connect (app->av_offset_entry, "activate",
3107 G_CALLBACK (av_offset_activate_cb), app);
3108 gtk_entry_set_text (GTK_ENTRY (app->av_offset_entry), "0");
3109 g_signal_connect (app->av_offset_entry, "activate",
3110 G_CALLBACK (av_offset_activate_cb), app);
3111 gtk_grid_attach (GTK_GRID (boxes3), app->av_offset_entry, 4, 3, 1, 1);
3113 label = gtk_label_new ("Subtitle Encoding");
3114 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 4, 1, 1);
3115 app->subtitle_encoding_entry = gtk_entry_new ();
3116 g_signal_connect (app->subtitle_encoding_entry, "activate",
3117 G_CALLBACK (subtitle_encoding_activate_cb), app);
3118 gtk_grid_attach (GTK_GRID (boxes3), app->subtitle_encoding_entry, 0, 5, 1,
3121 label = gtk_label_new ("Subtitle Fontdesc");
3122 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 4, 1, 1);
3123 app->subtitle_fontdesc_button = gtk_font_button_new ();
3124 g_signal_connect (app->subtitle_fontdesc_button, "font-set",
3125 G_CALLBACK (subtitle_fontdesc_cb), app);
3126 gtk_grid_attach (GTK_GRID (boxes3), app->subtitle_fontdesc_button, 1, 5, 1,
3129 pb2vbox = gtk_vbox_new (FALSE, 0);
3130 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
3131 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
3132 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
3133 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes3, FALSE, FALSE, 2);
3134 gtk_container_add (GTK_CONTAINER (playbin), pb2vbox);
3139 /* do the packing stuff ... */
3140 gtk_window_set_default_size (GTK_WINDOW (app->window), 250, 96);
3141 /* FIXME: can we avoid this for audio only? */
3142 gtk_widget_set_size_request (GTK_WIDGET (app->video_window), -1,
3143 DEFAULT_VIDEO_HEIGHT);
3144 gtk_container_add (GTK_CONTAINER (app->window), vbox);
3145 gtk_box_pack_start (GTK_BOX (vbox), app->video_window, TRUE, TRUE, 2);
3146 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
3147 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
3148 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
3149 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
3151 gtk_box_pack_start (GTK_BOX (vbox), seek, FALSE, FALSE, 2);
3153 gtk_box_pack_start (GTK_BOX (vbox), playbin, FALSE, FALSE, 2);
3154 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
3155 gtk_box_pack_start (GTK_BOX (vbox), navigation, FALSE, FALSE, 2);
3156 gtk_box_pack_start (GTK_BOX (vbox), colorbalance, FALSE, FALSE, 2);
3157 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 2);
3158 gtk_box_pack_start (GTK_BOX (vbox), app->seek_scale, FALSE, FALSE, 2);
3159 gtk_box_pack_start (GTK_BOX (vbox), app->statusbar, FALSE, FALSE, 2);
3161 /* connect things ... */
3162 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3164 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3166 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3169 g_signal_connect (G_OBJECT (app->window), "delete-event",
3170 G_CALLBACK (delete_event_cb), app);
3174 set_defaults (SeekApp * app)
3176 memset (app, 0, sizeof (SeekApp));
3178 app->flush_seek = TRUE;
3182 app->position = app->duration = -1;
3183 app->state = GST_STATE_NULL;
3185 app->need_streams = TRUE;
3187 g_static_mutex_init (&app->state_mutex);
3189 app->play_rate = 1.0;
3193 reset_app (SeekApp * app)
3195 g_free (app->audiosink_str);
3196 g_free (app->videosink_str);
3198 g_list_free (app->formats);
3200 g_static_mutex_free (&app->state_mutex);
3202 if (app->xoverlay_element)
3203 gst_object_unref (app->xoverlay_element);
3204 if (app->navigation_element)
3205 gst_object_unref (app->navigation_element);
3207 g_list_foreach (app->paths, (GFunc) g_free, NULL);
3208 g_list_free (app->paths);
3210 g_print ("free pipeline\n");
3211 gst_object_unref (app->pipeline);
3215 main (int argc, char **argv)
3218 GOptionEntry options[] = {
3219 {"stats", 's', 0, G_OPTION_ARG_NONE, &app.stats,
3220 "Show pad stats", NULL},
3221 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &app.verbose,
3222 "Verbose properties", NULL},
3225 GOptionContext *ctx;
3228 set_defaults (&app);
3230 #if !GLIB_CHECK_VERSION (2, 31, 0)
3231 if (!g_thread_supported ())
3232 g_thread_init (NULL);
3235 ctx = g_option_context_new ("- test seeking in gsteamer");
3236 g_option_context_add_main_entries (ctx, options, NULL);
3237 g_option_context_add_group (ctx, gst_init_get_option_group ());
3238 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
3240 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
3241 g_print ("Error initializing: %s\n", err->message);
3245 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
3248 print_usage (argc, argv);
3252 app.pipeline_type = atoi (argv[1]);
3254 if (app.pipeline_type < 0 || app.pipeline_type >= G_N_ELEMENTS (pipelines)) {
3255 print_usage (argc, argv);
3259 app.pipeline_spec = argv[2];
3261 if (g_path_is_absolute (app.pipeline_spec) &&
3262 (g_strrstr (app.pipeline_spec, "*") != NULL ||
3263 g_strrstr (app.pipeline_spec, "?") != NULL)) {
3264 app.paths = handle_wildcards (app.pipeline_spec);
3266 app.paths = g_list_prepend (app.paths, g_strdup (app.pipeline_spec));
3270 g_print ("opening %s failed\n", app.pipeline_spec);
3274 app.current_path = app.paths;
3276 pipelines[app.pipeline_type].func (&app, app.current_path->data);
3277 g_assert (app.pipeline);
3282 gtk_widget_show_all (app.window);
3284 /* realize window now so that the video window gets created and we can
3285 * obtain its XID before the pipeline is started up and the videosink
3286 * asks for the XID of the window to render onto */
3287 gtk_widget_realize (app.window);
3289 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
3290 /* we should have the XID now */
3291 g_assert (app.embed_xid != 0);
3293 if (app.pipeline_type == 0) {
3294 gst_x_overlay_set_window_handle (GST_X_OVERLAY (app.pipeline),
3300 g_signal_connect (app.pipeline, "deep_notify",
3301 G_CALLBACK (gst_object_default_deep_notify), NULL);
3304 connect_bus_signals (&app);
3308 g_print ("NULL pipeline\n");
3309 gst_element_set_state (app.pipeline, GST_STATE_NULL);