3 * playback-test.c: playback 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/gdkquartz.h>
50 #include <gst/video/videooverlay.h>
51 #include <gst/video/colorbalance.h>
52 #include <gst/video/navigation.h>
54 GST_DEBUG_CATEGORY_STATIC (playback_debug);
55 #define GST_CAT_DEFAULT (playback_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 *overlay_element;
146 gboolean accurate_seek;
147 gboolean keyframe_seek;
154 gboolean snap_before;
157 /* From commandline parameters */
160 const gchar *pipeline_spec;
162 GList *paths, *current_path;
163 GList *sub_paths, *current_sub_path;
165 gchar *audiosink_str, *videosink_str;
168 gint64 position, duration;
172 GstBufferingMode mode;
173 gint64 buffering_left;
176 guint seek_timeout_id; /* Used for scrubbing in paused */
180 gboolean need_streams;
181 gint n_video, n_audio, n_text;
185 GArray *vis_entries; /* Array of VisEntry structs */
188 gdouble shuttle_rate;
191 const GstFormatDefinition *seek_format;
195 static void clear_streams (PlaybackApp * app);
196 static void find_interface_elements (PlaybackApp * app);
197 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
199 static void mute_notify_cb (GstElement * pipeline, GParamSpec * arg,
202 static void video_sink_activate_cb (GtkEntry * entry, PlaybackApp * app);
203 static void text_sink_activate_cb (GtkEntry * entry, PlaybackApp * app);
204 static void audio_sink_activate_cb (GtkEntry * entry, PlaybackApp * app);
205 static void buffer_size_activate_cb (GtkEntry * entry, PlaybackApp * app);
206 static void buffer_duration_activate_cb (GtkEntry * entry, PlaybackApp * app);
207 static void ringbuffer_maxsize_activate_cb (GtkEntry * entry,
209 static void connection_speed_activate_cb (GtkEntry * entry, PlaybackApp * app);
210 static void av_offset_activate_cb (GtkEntry * entry, PlaybackApp * app);
211 static void subtitle_encoding_activate_cb (GtkEntry * entry, PlaybackApp * app);
213 /* pipeline construction */
216 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
218 GstElement *element = gst_element_factory_make (type, name);
220 #ifndef GST_DISABLE_PARSE
222 /* Try parsing it as a pipeline description */
223 element = gst_parse_bin_from_description (type, TRUE, NULL);
225 gst_element_set_name (element, name);
231 g_warning ("Failed to create element %s of type %s", name, type);
238 set_uri_property (GObject * object, const gchar * property,
239 const gchar * location)
243 /* Add "file://" prefix for convenience */
244 if (location && (g_str_has_prefix (location, "/")
245 || !gst_uri_is_valid (location))) {
246 uri = gst_filename_to_uri (location, NULL);
247 g_print ("Setting URI: %s\n", uri);
248 g_object_set (object, property, uri, NULL);
251 g_print ("Setting URI: %s\n", location);
252 g_object_set (object, property, location, NULL);
257 playbin_set_uri (GstElement * playbin, const gchar * location,
258 const gchar * sub_location)
260 set_uri_property (G_OBJECT (playbin), "uri", location);
261 set_uri_property (G_OBJECT (playbin), "suburi", sub_location);
265 make_playbin_pipeline (PlaybackApp * app, const gchar * location)
267 GstElement *pipeline;
269 app->pipeline = pipeline = gst_element_factory_make ("playbin", "playbin");
272 playbin_set_uri (pipeline, location,
273 app->current_sub_path ? app->current_sub_path->data : NULL);
275 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
277 g_signal_connect (pipeline, "notify::mute", G_CALLBACK (mute_notify_cb), app);
279 app->navigation_element = GST_ELEMENT (gst_object_ref (pipeline));
280 app->colorbalance_element = GST_ELEMENT (gst_object_ref (pipeline));
283 #ifndef GST_DISABLE_PARSE
285 make_parselaunch_pipeline (PlaybackApp * app, const gchar * description)
287 app->pipeline = gst_parse_launch (description, NULL);
294 void (*func) (PlaybackApp * app, const gchar * location);
298 static const Pipeline pipelines[] = {
299 {"playbin", make_playbin_pipeline},
300 #ifndef GST_DISABLE_PARSE
301 {"parse-launch", make_parselaunch_pipeline},
305 /* ui callbacks and helpers */
308 format_value (GtkScale * scale, gdouble value, PlaybackApp * app)
314 real = value * app->duration / N_GRAD;
315 seconds = (gint64) real / GST_SECOND;
316 subseconds = (gint64) real / (GST_MSECOND);
318 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%03"
319 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 1000);
323 shuttle_format_value (GtkScale * scale, gdouble value)
325 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
331 const GstFormat format;
335 static seek_format seek_formats[] = {
336 {"tim", GST_FORMAT_TIME},
337 {"byt", GST_FORMAT_BYTES},
338 {"buf", GST_FORMAT_BUFFERS},
339 {"def", GST_FORMAT_DEFAULT},
344 query_positions (PlaybackApp * app)
348 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (app->pipeline));
349 while (seek_formats[i].name) {
350 gint64 position, total;
353 format = seek_formats[i].format;
355 if (gst_element_query_position (app->pipeline, format, &position) &&
356 gst_element_query_duration (app->pipeline, format, &total)) {
357 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
358 seek_formats[i].name, position, total);
360 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*", "*NA*");
364 g_print (" %s\n", GST_ELEMENT_NAME (app->pipeline));
367 static gboolean start_seek (GtkRange * range, GdkEventButton * event,
369 static gboolean stop_seek (GtkRange * range, GdkEventButton * event,
371 static void seek_cb (GtkRange * range, PlaybackApp * app);
374 set_scale (PlaybackApp * app, gdouble value)
376 g_signal_handlers_block_by_func (app->seek_scale, start_seek, app);
377 g_signal_handlers_block_by_func (app->seek_scale, stop_seek, app);
378 g_signal_handlers_block_by_func (app->seek_scale, seek_cb, app);
379 gtk_range_set_value (GTK_RANGE (app->seek_scale), value);
380 g_signal_handlers_unblock_by_func (app->seek_scale, start_seek, app);
381 g_signal_handlers_unblock_by_func (app->seek_scale, stop_seek, app);
382 g_signal_handlers_unblock_by_func (app->seek_scale, seek_cb, app);
383 gtk_widget_queue_draw (app->seek_scale);
387 update_fill (PlaybackApp * app)
391 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
392 if (gst_element_query (app->pipeline, query)) {
393 gint64 start, stop, buffering_total;
398 GstBufferingMode mode;
399 gint avg_in, avg_out;
400 gint64 buffering_left;
402 gst_query_parse_buffering_percent (query, &busy, &percent);
403 gst_query_parse_buffering_range (query, &format, &start, &stop,
405 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
408 /* note that we could start the playback when buffering_left < remaining
410 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
411 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
412 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
416 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
420 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), fill);
422 gst_query_unref (query);
428 update_scale (PlaybackApp * app)
430 GstFormat format = GST_FORMAT_TIME;
431 gint64 seek_pos, seek_dur;
437 gst_element_query_position (app->pipeline, format, &app->position);
438 gst_element_query_duration (app->pipeline, format, &app->duration);
441 query_positions (app);
443 if (app->position >= app->duration)
444 app->duration = app->position;
446 if (app->duration > 0) {
447 set_scale (app, app->position * N_GRAD / app->duration);
450 if (app->seek_format) {
451 format = app->seek_format->value;
452 seek_pos = seek_dur = -1;
453 gst_element_query_position (app->pipeline, format, &seek_pos);
454 gst_element_query_duration (app->pipeline, format, &seek_dur);
456 str = g_strdup_printf ("%" G_GINT64_FORMAT, seek_pos);
457 gtk_label_set_text (GTK_LABEL (app->seek_position_label), str);
460 str = g_strdup_printf ("%" G_GINT64_FORMAT, seek_dur);
461 gtk_label_set_text (GTK_LABEL (app->seek_duration_label), str);
468 static void set_update_scale (PlaybackApp * app, gboolean active);
469 static void set_update_fill (PlaybackApp * app, gboolean active);
472 end_scrub (PlaybackApp * app)
474 GST_DEBUG ("end scrub, PAUSE");
475 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
476 app->seek_timeout_id = 0;
482 send_event (PlaybackApp * app, GstEvent * event)
484 gboolean res = FALSE;
486 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (app->pipeline));
487 res = gst_element_send_event (app->pipeline, event);
493 do_seek (PlaybackApp * app, GstFormat format, gint64 position)
495 gboolean res = FALSE;
501 flags |= GST_SEEK_FLAG_FLUSH;
502 if (app->accurate_seek)
503 flags |= GST_SEEK_FLAG_ACCURATE;
504 if (app->keyframe_seek)
505 flags |= GST_SEEK_FLAG_KEY_UNIT;
507 flags |= GST_SEEK_FLAG_SEGMENT;
509 flags |= GST_SEEK_FLAG_SKIP;
510 if (app->snap_before)
511 flags |= GST_SEEK_FLAG_SNAP_BEFORE;
513 flags |= GST_SEEK_FLAG_SNAP_AFTER;
515 if (app->rate >= 0) {
516 s_event = gst_event_new_seek (app->rate,
517 format, flags, GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_SET,
518 GST_CLOCK_TIME_NONE);
519 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
520 app->rate, GST_TIME_ARGS (position), GST_TIME_ARGS (app->duration));
522 s_event = gst_event_new_seek (app->rate,
523 format, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
524 GST_SEEK_TYPE_SET, position);
525 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
526 app->rate, GST_TIME_ARGS (0), GST_TIME_ARGS (position));
529 res = send_event (app, s_event);
532 if (app->flush_seek) {
533 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
536 set_update_scale (app, TRUE);
539 g_print ("seek failed\n");
540 set_update_scale (app, TRUE);
545 seek_cb (GtkRange * range, PlaybackApp * app)
550 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
553 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
554 gtk_range_get_value (GTK_RANGE (app->seek_scale)), real);
556 GST_DEBUG ("do seek");
557 do_seek (app, GST_FORMAT_TIME, real);
559 if (app->play_scrub) {
560 GST_DEBUG ("do scrub seek, PLAYING");
561 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
563 if (app->seek_timeout_id == 0) {
564 app->seek_timeout_id =
565 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, app);
571 advanced_seek_button_cb (GtkButton * button, PlaybackApp * app)
578 fmt = app->seek_format->value;
580 text = gtk_entry_get_text (GTK_ENTRY (app->seek_entry));
582 pos = g_ascii_strtoll (text, &endptr, 10);
583 if (endptr != text && pos != G_MAXINT64 && pos != G_MININT64) {
584 do_seek (app, fmt, pos);
589 set_update_fill (PlaybackApp * app, gboolean active)
591 GST_DEBUG ("fill scale is %d", active);
594 if (app->fill_id == 0) {
596 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, app);
600 g_source_remove (app->fill_id);
607 set_update_scale (PlaybackApp * app, gboolean active)
609 GST_DEBUG ("update scale is %d", active);
612 if (app->update_id == 0) {
614 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, app);
617 if (app->update_id) {
618 g_source_remove (app->update_id);
625 start_seek (GtkRange * range, GdkEventButton * event, PlaybackApp * app)
627 if (event->type != GDK_BUTTON_PRESS)
630 set_update_scale (app, FALSE);
632 if (app->state == GST_STATE_PLAYING && app->flush_seek && app->scrub) {
633 GST_DEBUG ("start scrub seek, PAUSE");
634 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
637 if (app->changed_id == 0 && app->flush_seek && app->scrub) {
639 g_signal_connect (app->seek_scale, "value-changed",
640 G_CALLBACK (seek_cb), app);
647 stop_seek (GtkRange * range, GdkEventButton * event, PlaybackApp * app)
649 if (app->changed_id) {
650 g_signal_handler_disconnect (app->seek_scale, app->changed_id);
654 if (!app->flush_seek || !app->scrub) {
657 GST_DEBUG ("do final seek");
659 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
661 do_seek (app, GST_FORMAT_TIME, real);
664 if (app->seek_timeout_id != 0) {
665 g_source_remove (app->seek_timeout_id);
666 app->seek_timeout_id = 0;
667 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
669 if (app->state == GST_STATE_PAUSED) {
670 GST_DEBUG ("stop scrub seek, PAUSED");
671 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
674 if (app->state == GST_STATE_PLAYING) {
675 GST_DEBUG ("stop scrub seek, PLAYING");
676 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
684 play_cb (GtkButton * button, PlaybackApp * app)
686 GstStateChangeReturn ret;
688 if (app->state != GST_STATE_PLAYING) {
689 g_print ("PLAY pipeline\n");
690 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
692 if (app->pipeline_type == 0) {
693 video_sink_activate_cb (GTK_ENTRY (app->video_sink_entry), app);
694 audio_sink_activate_cb (GTK_ENTRY (app->audio_sink_entry), app);
695 text_sink_activate_cb (GTK_ENTRY (app->text_sink_entry), app);
696 buffer_size_activate_cb (GTK_ENTRY (app->buffer_size_entry), app);
697 buffer_duration_activate_cb (GTK_ENTRY (app->buffer_duration_entry), app);
698 ringbuffer_maxsize_activate_cb (GTK_ENTRY (app->ringbuffer_maxsize_entry),
700 connection_speed_activate_cb (GTK_ENTRY (app->connection_speed_entry),
702 av_offset_activate_cb (GTK_ENTRY (app->av_offset_entry), app);
703 subtitle_encoding_activate_cb (GTK_ENTRY (app->subtitle_encoding_entry),
707 ret = gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
709 case GST_STATE_CHANGE_FAILURE:
711 case GST_STATE_CHANGE_NO_PREROLL:
717 app->state = GST_STATE_PLAYING;
718 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
726 g_print ("PLAY failed\n");
727 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
733 pause_cb (GtkButton * button, PlaybackApp * app)
735 g_mutex_lock (&app->state_mutex);
736 if (app->state != GST_STATE_PAUSED) {
737 GstStateChangeReturn ret;
739 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
740 g_print ("PAUSE pipeline\n");
741 ret = gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
743 case GST_STATE_CHANGE_FAILURE:
745 case GST_STATE_CHANGE_NO_PREROLL:
752 app->state = GST_STATE_PAUSED;
753 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
756 g_mutex_unlock (&app->state_mutex);
762 g_mutex_unlock (&app->state_mutex);
763 g_print ("PAUSE failed\n");
764 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
770 stop_cb (GtkButton * button, PlaybackApp * app)
772 if (app->state != STOP_STATE) {
773 GstStateChangeReturn ret;
776 g_print ("READY pipeline\n");
777 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
779 g_mutex_lock (&app->state_mutex);
780 ret = gst_element_set_state (app->pipeline, STOP_STATE);
781 if (ret == GST_STATE_CHANGE_FAILURE)
784 app->state = STOP_STATE;
785 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
787 gtk_widget_queue_draw (app->video_window);
789 app->is_live = FALSE;
790 app->buffering = FALSE;
791 set_update_scale (app, FALSE);
792 set_scale (app, 0.0);
793 set_update_fill (app, FALSE);
795 if (app->pipeline_type == 0)
797 g_mutex_unlock (&app->state_mutex);
799 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), TRUE);
800 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++)
801 gtk_widget_set_sensitive (app->navigation_buttons[i].button, FALSE);
807 g_mutex_unlock (&app->state_mutex);
808 g_print ("STOP failed\n");
809 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
815 snap_before_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
817 app->snap_before = gtk_toggle_button_get_active (button);
821 snap_after_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
823 app->snap_after = gtk_toggle_button_get_active (button);
827 accurate_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
829 app->accurate_seek = gtk_toggle_button_get_active (button);
833 key_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
835 app->keyframe_seek = gtk_toggle_button_get_active (button);
839 loop_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
841 app->loop_seek = gtk_toggle_button_get_active (button);
842 if (app->state == GST_STATE_PLAYING) {
846 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
848 do_seek (app, GST_FORMAT_TIME, real);
853 flush_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
855 app->flush_seek = gtk_toggle_button_get_active (button);
859 scrub_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
861 app->scrub = gtk_toggle_button_get_active (button);
865 play_scrub_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
867 app->play_scrub = gtk_toggle_button_get_active (button);
871 skip_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
873 app->skip_seek = gtk_toggle_button_get_active (button);
874 if (app->state == GST_STATE_PLAYING) {
878 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
880 do_seek (app, GST_FORMAT_TIME, real);
885 rate_spinbutton_changed_cb (GtkSpinButton * button, PlaybackApp * app)
887 gboolean res = FALSE;
891 app->rate = gtk_spin_button_get_value (button);
893 GST_DEBUG ("rate changed to %lf", app->rate);
897 flags |= GST_SEEK_FLAG_FLUSH;
899 flags |= GST_SEEK_FLAG_SEGMENT;
900 if (app->accurate_seek)
901 flags |= GST_SEEK_FLAG_ACCURATE;
902 if (app->keyframe_seek)
903 flags |= GST_SEEK_FLAG_KEY_UNIT;
905 flags |= GST_SEEK_FLAG_SKIP;
907 if (app->rate >= 0.0) {
908 s_event = gst_event_new_seek (app->rate,
909 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
910 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
912 s_event = gst_event_new_seek (app->rate,
913 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
914 GST_SEEK_TYPE_SET, app->position);
917 res = send_event (app, s_event);
920 if (app->flush_seek) {
921 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
925 g_print ("seek failed\n");
929 update_flag (GstElement * pipeline, GstPlayFlags flag, gboolean state)
933 g_print ("%ssetting flag 0x%08x\n", (state ? "" : "un"), flag);
935 g_object_get (pipeline, "flags", &flags, NULL);
940 g_object_set (pipeline, "flags", flags, NULL);
944 vis_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
948 state = gtk_toggle_button_get_active (button);
949 update_flag (app->pipeline, GST_PLAY_FLAG_VIS, state);
950 gtk_widget_set_sensitive (app->vis_combo, state);
954 audio_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
958 state = gtk_toggle_button_get_active (button);
959 update_flag (app->pipeline, GST_PLAY_FLAG_AUDIO, state);
960 gtk_widget_set_sensitive (app->audio_combo, state);
964 video_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
968 state = gtk_toggle_button_get_active (button);
969 update_flag (app->pipeline, GST_PLAY_FLAG_VIDEO, state);
970 gtk_widget_set_sensitive (app->video_combo, state);
974 text_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
978 state = gtk_toggle_button_get_active (button);
979 update_flag (app->pipeline, GST_PLAY_FLAG_TEXT, state);
980 gtk_widget_set_sensitive (app->text_combo, state);
984 mute_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
988 mute = gtk_toggle_button_get_active (button);
989 g_object_set (app->pipeline, "mute", mute, NULL);
993 download_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
997 state = gtk_toggle_button_get_active (button);
998 update_flag (app->pipeline, GST_PLAY_FLAG_DOWNLOAD, state);
1002 buffering_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1006 state = gtk_toggle_button_get_active (button);
1007 update_flag (app->pipeline, GST_PLAY_FLAG_BUFFERING, state);
1011 soft_volume_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1015 state = gtk_toggle_button_get_active (button);
1016 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_VOLUME, state);
1020 native_audio_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1024 state = gtk_toggle_button_get_active (button);
1025 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_AUDIO, state);
1029 native_video_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1033 state = gtk_toggle_button_get_active (button);
1034 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_VIDEO, state);
1038 deinterlace_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1042 state = gtk_toggle_button_get_active (button);
1043 update_flag (app->pipeline, GST_PLAY_FLAG_DEINTERLACE, state);
1047 soft_colorbalance_toggle_cb (GtkToggleButton * button, PlaybackApp * app)
1051 state = gtk_toggle_button_get_active (button);
1052 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_COLORBALANCE, state);
1056 clear_streams (PlaybackApp * app)
1060 /* remove previous info */
1061 for (i = 0; i < app->n_video; i++)
1062 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->video_combo), 0);
1063 for (i = 0; i < app->n_audio; i++)
1064 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->audio_combo), 0);
1065 for (i = 0; i < app->n_text; i++)
1066 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->text_combo), 0);
1068 app->n_audio = app->n_video = app->n_text = 0;
1069 gtk_widget_set_sensitive (app->video_combo, FALSE);
1070 gtk_widget_set_sensitive (app->audio_combo, FALSE);
1071 gtk_widget_set_sensitive (app->text_combo, FALSE);
1073 app->need_streams = TRUE;
1077 update_streams (PlaybackApp * app)
1081 if (app->pipeline_type == 0 && app->need_streams) {
1087 /* remove previous info */
1088 clear_streams (app);
1090 /* here we get and update the different streams detected by playbin */
1091 g_object_get (app->pipeline, "n-video", &app->n_video, NULL);
1092 g_object_get (app->pipeline, "n-audio", &app->n_audio, NULL);
1093 g_object_get (app->pipeline, "n-text", &app->n_text, NULL);
1095 g_print ("video %d, audio %d, text %d\n", app->n_video, app->n_audio,
1099 for (i = 0; i < app->n_video; i++) {
1100 g_signal_emit_by_name (app->pipeline, "get-video-tags", i, &tags);
1102 str = gst_tag_list_to_string (tags);
1103 g_print ("video %d: %s\n", i, str);
1106 /* find good name for the label */
1107 name = g_strdup_printf ("video %d", i + 1);
1108 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->video_combo),
1113 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->video_checkbox));
1114 gtk_widget_set_sensitive (app->video_combo, state && app->n_video > 0);
1115 gtk_combo_box_set_active (GTK_COMBO_BOX (app->video_combo), active_idx);
1118 for (i = 0; i < app->n_audio; i++) {
1119 g_signal_emit_by_name (app->pipeline, "get-audio-tags", i, &tags);
1121 str = gst_tag_list_to_string (tags);
1122 g_print ("audio %d: %s\n", i, str);
1125 /* find good name for the label */
1126 name = g_strdup_printf ("audio %d", i + 1);
1127 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->audio_combo),
1132 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->audio_checkbox));
1133 gtk_widget_set_sensitive (app->audio_combo, state && app->n_audio > 0);
1134 gtk_combo_box_set_active (GTK_COMBO_BOX (app->audio_combo), active_idx);
1137 for (i = 0; i < app->n_text; i++) {
1138 g_signal_emit_by_name (app->pipeline, "get-text-tags", i, &tags);
1142 const GValue *value;
1144 str = gst_tag_list_to_string (tags);
1145 g_print ("text %d: %s\n", i, str);
1148 /* get the language code if we can */
1149 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1150 if (value && G_VALUE_HOLDS_STRING (value)) {
1151 name = g_strdup_printf ("text %s", g_value_get_string (value));
1154 /* find good name for the label if we didn't use a tag */
1156 name = g_strdup_printf ("text %d", i + 1);
1158 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->text_combo),
1163 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->text_checkbox));
1164 gtk_widget_set_sensitive (app->text_combo, state && app->n_text > 0);
1165 gtk_combo_box_set_active (GTK_COMBO_BOX (app->text_combo), active_idx);
1167 app->need_streams = FALSE;
1172 video_combo_cb (GtkComboBox * combo, PlaybackApp * app)
1176 active = gtk_combo_box_get_active (combo);
1178 g_print ("setting current video track %d\n", active);
1179 g_object_set (app->pipeline, "current-video", active, NULL);
1183 audio_combo_cb (GtkComboBox * combo, PlaybackApp * app)
1187 active = gtk_combo_box_get_active (combo);
1189 g_print ("setting current audio track %d\n", active);
1190 g_object_set (app->pipeline, "current-audio", active, NULL);
1194 text_combo_cb (GtkComboBox * combo, PlaybackApp * app)
1198 active = gtk_combo_box_get_active (combo);
1200 g_print ("setting current text track %d\n", active);
1201 g_object_set (app->pipeline, "current-text", active, NULL);
1205 filter_vis_features (GstPluginFeature * feature, gpointer data)
1207 GstElementFactory *f;
1209 if (!GST_IS_ELEMENT_FACTORY (feature))
1211 f = GST_ELEMENT_FACTORY (feature);
1212 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1219 init_visualization_features (PlaybackApp * app)
1223 app->vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1225 list = gst_registry_feature_filter (gst_registry_get (),
1226 filter_vis_features, FALSE, NULL);
1228 for (walk = list; walk; walk = g_list_next (walk)) {
1232 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1233 name = gst_element_factory_get_longname (entry.factory);
1235 g_array_append_val (app->vis_entries, entry);
1236 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->vis_combo), name);
1238 gtk_combo_box_set_active (GTK_COMBO_BOX (app->vis_combo), 0);
1242 vis_combo_cb (GtkComboBox * combo, PlaybackApp * app)
1246 GstElement *element;
1248 /* get the selected index and get the factory for this index */
1249 index = gtk_combo_box_get_active (GTK_COMBO_BOX (app->vis_combo));
1250 if (app->vis_entries->len > 0) {
1251 entry = &g_array_index (app->vis_entries, VisEntry, index);
1253 /* create an instance of the element from the factory */
1254 element = gst_element_factory_create (entry->factory, NULL);
1258 /* set vis plugin for playbin */
1259 g_object_set (app->pipeline, "vis-plugin", element, NULL);
1264 volume_spinbutton_changed_cb (GtkSpinButton * button, PlaybackApp * app)
1268 volume = gtk_spin_button_get_value (button);
1270 g_object_set (app->pipeline, "volume", volume, NULL);
1274 volume_notify_idle_cb (PlaybackApp * app)
1276 gdouble cur_volume, new_volume;
1278 g_object_get (app->pipeline, "volume", &new_volume, NULL);
1280 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->volume_spinbutton));
1281 if (fabs (cur_volume - new_volume) > 0.001) {
1282 g_signal_handlers_block_by_func (app->volume_spinbutton,
1283 volume_spinbutton_changed_cb, app);
1284 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton),
1286 g_signal_handlers_unblock_by_func (app->volume_spinbutton,
1287 volume_spinbutton_changed_cb, app);
1294 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, PlaybackApp * app)
1296 /* Do this from the main thread */
1297 g_idle_add ((GSourceFunc) volume_notify_idle_cb, app);
1301 mute_notify_idle_cb (PlaybackApp * app)
1303 gboolean cur_mute, new_mute;
1305 g_object_get (app->pipeline, "mute", &new_mute, NULL);
1307 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->mute_checkbox));
1308 if (cur_mute != new_mute) {
1309 g_signal_handlers_block_by_func (app->mute_checkbox, mute_toggle_cb, app);
1310 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
1312 g_signal_handlers_unblock_by_func (app->mute_checkbox, mute_toggle_cb, app);
1319 mute_notify_cb (GstElement * pipeline, GParamSpec * arg, PlaybackApp * app)
1321 /* Do this from the main thread */
1322 g_idle_add ((GSourceFunc) mute_notify_idle_cb, app);
1326 shot_cb (GtkButton * button, PlaybackApp * app)
1328 GstSample *sample = NULL;
1331 GST_DEBUG ("taking snapshot");
1333 /* convert to our desired format (RGB24) */
1334 caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB",
1335 /* Note: we don't ask for a specific width/height here, so that
1336 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1337 * ratio to a 1/1 pixel-aspect-ratio */
1338 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
1340 /* convert the latest sample to the requested format */
1341 g_signal_emit_by_name (app->pipeline, "convert-sample", caps, &sample);
1342 gst_caps_unref (caps);
1351 GError *error = NULL;
1354 /* get the snapshot buffer format now. We set the caps on the appsink so
1355 * that it can only be an rgb buffer. The only thing we have not specified
1356 * on the caps is the height, which is dependant on the pixel-aspect-ratio
1357 * of the source material */
1358 caps = gst_sample_get_caps (sample);
1360 g_warning ("could not get snapshot format\n");
1363 s = gst_caps_get_structure (caps, 0);
1365 /* we need to get the final caps on the buffer to get the size */
1366 res = gst_structure_get_int (s, "width", &width);
1367 res |= gst_structure_get_int (s, "height", &height);
1369 g_warning ("could not get snapshot dimension\n");
1373 /* create pixmap from buffer and save, gstreamer video buffers have a stride
1374 * that is rounded up to the nearest multiple of 4 */
1375 buffer = gst_sample_get_buffer (sample);
1376 gst_buffer_map (buffer, &map, GST_MAP_READ);
1377 pixbuf = gdk_pixbuf_new_from_data (map.data,
1378 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
1379 GST_ROUND_UP_4 (width * 3), NULL, NULL);
1381 /* save the pixbuf */
1382 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
1383 gst_buffer_unmap (buffer, &map);
1386 gst_sample_unref (sample);
1390 /* called when the Step button is pressed */
1392 step_cb (GtkButton * button, PlaybackApp * app)
1398 gboolean flush, res;
1401 active = gtk_combo_box_get_active (GTK_COMBO_BOX (app->step_format_combo));
1403 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
1404 (app->step_amount_spinbutton));
1406 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton));
1411 format = GST_FORMAT_BUFFERS;
1414 format = GST_FORMAT_TIME;
1415 amount *= GST_MSECOND;
1418 format = GST_FORMAT_UNDEFINED;
1422 event = gst_event_new_step (format, amount, rate, flush, FALSE);
1424 res = send_event (app, event);
1427 g_print ("Sending step event failed\n");
1432 message_received (GstBus * bus, GstMessage * message, PlaybackApp * app)
1434 const GstStructure *s;
1436 switch (GST_MESSAGE_TYPE (message)) {
1437 case GST_MESSAGE_ERROR:
1438 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1439 GST_DEBUG_GRAPH_SHOW_ALL, "seek.error");
1441 case GST_MESSAGE_WARNING:
1442 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1443 GST_DEBUG_GRAPH_SHOW_ALL, "seek.warning");
1449 s = gst_message_get_structure (message);
1450 g_print ("message from \"%s\" (%s): ",
1451 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
1452 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1456 sstr = gst_structure_to_string (s);
1457 g_print ("%s\n", sstr);
1460 g_print ("no message details\n");
1465 do_shuttle (PlaybackApp * app)
1470 duration = 40 * GST_MSECOND;
1474 gst_element_send_event (app->pipeline,
1475 gst_event_new_step (GST_FORMAT_TIME, duration, app->shuttle_rate, FALSE,
1480 msg_sync_step_done (GstBus * bus, GstMessage * message, PlaybackApp * app)
1486 gboolean intermediate;
1490 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
1491 &intermediate, &duration, &eos);
1494 g_print ("stepped till EOS\n");
1498 if (g_mutex_trylock (&app->state_mutex)) {
1501 g_mutex_unlock (&app->state_mutex);
1503 /* ignore step messages that come while we are doing a state change */
1504 g_print ("state change is busy\n");
1509 shuttle_toggled (GtkToggleButton * button, PlaybackApp * app)
1513 active = gtk_toggle_button_get_active (button);
1515 if (active != app->shuttling) {
1516 app->shuttling = active;
1517 g_print ("shuttling %s\n", app->shuttling ? "active" : "inactive");
1519 app->shuttle_rate = 0.0;
1520 app->play_rate = 1.0;
1521 pause_cb (NULL, app);
1522 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1528 shuttle_rate_switch (PlaybackApp * app)
1534 if (app->state == GST_STATE_PLAYING) {
1535 /* pause when we need to */
1536 pause_cb (NULL, app);
1537 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1540 if (app->play_rate == 1.0)
1541 app->play_rate = -1.0;
1543 app->play_rate = 1.0;
1545 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", app->play_rate,
1546 GST_TIME_ARGS (app->position));
1548 flags = GST_SEEK_FLAG_FLUSH;
1549 flags |= GST_SEEK_FLAG_ACCURATE;
1551 if (app->play_rate >= 0.0) {
1552 s_event = gst_event_new_seek (app->play_rate,
1553 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
1554 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1556 s_event = gst_event_new_seek (app->play_rate,
1557 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1558 GST_SEEK_TYPE_SET, app->position);
1560 res = send_event (app, s_event);
1562 gst_element_get_state (app->pipeline, NULL, NULL, SEEK_TIMEOUT);
1564 g_print ("seek failed\n");
1569 shuttle_value_changed (GtkRange * range, PlaybackApp * app)
1573 rate = gtk_range_get_value (range);
1576 g_print ("rate 0.0, pause\n");
1577 pause_cb (NULL, app);
1578 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1580 g_print ("rate changed %0.3g\n", rate);
1582 if ((rate < 0.0 && app->play_rate > 0.0) || (rate > 0.0
1583 && app->play_rate < 0.0)) {
1584 shuttle_rate_switch (app);
1587 app->shuttle_rate = ABS (rate);
1588 if (app->state != GST_STATE_PLAYING) {
1590 play_cb (NULL, app);
1596 colorbalance_value_changed (GtkRange * range, PlaybackApp * app)
1601 GstColorBalanceChannel *channel = NULL;
1602 const GList *channels, *l;
1604 if (range == GTK_RANGE (app->contrast_scale))
1606 else if (range == GTK_RANGE (app->brightness_scale))
1607 label = "BRIGHTNESS";
1608 else if (range == GTK_RANGE (app->hue_scale))
1610 else if (range == GTK_RANGE (app->saturation_scale))
1611 label = "SATURATION";
1613 g_assert_not_reached ();
1615 val = gtk_range_get_value (range);
1617 g_print ("colorbalance %s value changed %lf\n", label, val / N_GRAD);
1619 if (!app->colorbalance_element) {
1620 find_interface_elements (app);
1621 if (!app->colorbalance_element)
1626 gst_color_balance_list_channels (GST_COLOR_BALANCE
1627 (app->colorbalance_element));
1628 for (l = channels; l; l = l->next) {
1629 GstColorBalanceChannel *tmp = l->data;
1631 if (g_strrstr (tmp->label, label)) {
1641 (gint) (0.5 + channel->min_value +
1642 (val / N_GRAD) * ((gdouble) channel->max_value -
1643 (gdouble) channel->min_value));
1644 gst_color_balance_set_value (GST_COLOR_BALANCE (app->colorbalance_element),
1649 seek_format_changed_cb (GtkComboBox * box, PlaybackApp * app)
1653 const GstFormatDefinition *format = NULL;
1655 format_str = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (box));
1657 for (l = app->formats; l; l = l->next) {
1658 const GstFormatDefinition *tmp = l->data;
1660 if (g_strcmp0 (tmp->nick, format_str) == 0) {
1669 app->seek_format = format;
1673 g_free (format_str);
1677 update_formats (PlaybackApp * app)
1682 GValue item = { 0, };
1684 gint selected_idx = 0, i;
1687 gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT
1688 (app->seek_format_combo));
1689 if (selected == NULL)
1690 selected = g_strdup ("time");
1692 it = gst_format_iterate_definitions ();
1695 g_list_free (app->formats);
1696 app->formats = NULL;
1699 switch (gst_iterator_next (it, &item)) {
1700 case GST_ITERATOR_OK:{
1701 GstFormatDefinition *def = g_value_get_pointer (&item);
1703 app->formats = g_list_prepend (app->formats, def);
1704 g_value_reset (&item);
1707 case GST_ITERATOR_RESYNC:
1708 g_list_free (app->formats);
1709 app->formats = NULL;
1710 gst_iterator_resync (it);
1712 case GST_ITERATOR_ERROR:
1713 case GST_ITERATOR_DONE:
1719 g_value_unset (&item);
1721 app->formats = g_list_reverse (app->formats);
1722 gst_iterator_free (it);
1724 g_signal_handlers_block_by_func (app->seek_format_combo,
1725 seek_format_changed_cb, app);
1726 gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (app->seek_format_combo));
1728 for (i = 0, l = app->formats; l; l = l->next, i++) {
1729 const GstFormatDefinition *def = l->data;
1731 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->seek_format_combo),
1733 if (g_strcmp0 (def->nick, selected) == 0)
1736 g_signal_handlers_unblock_by_func (app->seek_format_combo,
1737 seek_format_changed_cb, app);
1739 gtk_combo_box_set_active (GTK_COMBO_BOX (app->seek_format_combo),
1746 msg_async_done (GstBus * bus, GstMessage * message, PlaybackApp * app)
1748 GST_DEBUG ("async done");
1750 /* Now query all available GstFormats */
1751 update_formats (app);
1753 /* when we get ASYNC_DONE we can query position, duration and other
1757 /* update the available streams */
1758 update_streams (app);
1760 find_interface_elements (app);
1764 msg_state_changed (GstBus * bus, GstMessage * message, PlaybackApp * app)
1766 const GstStructure *s;
1768 s = gst_message_get_structure (message);
1770 /* We only care about state changed on the pipeline */
1771 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (app->pipeline)) {
1772 GstState old, new, pending;
1774 gst_message_parse_state_changed (message, &old, &new, &pending);
1776 /* When state of the pipeline changes to paused or playing we start updating scale */
1777 if (new == GST_STATE_PLAYING) {
1778 set_update_scale (app, TRUE);
1780 set_update_scale (app, FALSE);
1783 /* dump graph for (some) pipeline state changes */
1787 dump_name = g_strdup_printf ("seek.%s_%s",
1788 gst_element_state_get_name (old), gst_element_state_get_name (new));
1790 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1791 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
1799 msg_segment_done (GstBus * bus, GstMessage * message, PlaybackApp * app)
1806 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (app->position));
1807 gst_message_parse_segment_done (message, &format, &app->position);
1808 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT,
1809 GST_TIME_ARGS (app->position));
1812 /* in the segment-done callback we never flush as this would not make sense
1813 * for seamless playback. */
1815 flags |= GST_SEEK_FLAG_SEGMENT;
1817 flags |= GST_SEEK_FLAG_SKIP;
1819 s_event = gst_event_new_seek (app->rate,
1820 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1821 GST_SEEK_TYPE_SET, app->duration);
1823 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
1824 app->rate, GST_TIME_ARGS (app->duration));
1826 res = send_event (app, s_event);
1828 g_print ("segment seek failed\n");
1831 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
1834 do_stream_buffering (PlaybackApp * app, gint percent)
1838 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1839 bufstr = g_strdup_printf ("Buffering...%d", percent);
1840 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1843 if (percent == 100) {
1844 /* a 100% message means buffering is done */
1845 app->buffering = FALSE;
1846 /* if the desired state is playing, go back */
1847 if (app->state == GST_STATE_PLAYING) {
1848 /* no state management needed for live pipelines */
1849 if (!app->is_live) {
1850 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
1851 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1853 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1854 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
1858 /* buffering busy */
1859 if (app->buffering == FALSE && app->state == GST_STATE_PLAYING) {
1860 /* we were not buffering but PLAYING, PAUSE the pipeline. */
1861 if (!app->is_live) {
1862 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
1863 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1866 app->buffering = TRUE;
1871 do_download_buffering (PlaybackApp * app, gint percent)
1873 if (!app->buffering && percent < 100) {
1876 app->buffering = TRUE;
1878 bufstr = g_strdup_printf ("Downloading...");
1879 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1882 /* once we get a buffering message, we'll do the fill update */
1883 set_update_fill (app, TRUE);
1885 if (app->state == GST_STATE_PLAYING && !app->is_live) {
1886 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
1887 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1888 /* user has to manually start the playback */
1889 app->state = GST_STATE_PAUSED;
1895 msg_buffering (GstBus * bus, GstMessage * message, PlaybackApp * app)
1899 gst_message_parse_buffering (message, &percent);
1901 /* get more stats */
1902 gst_message_parse_buffering_stats (message, &app->mode, NULL, NULL,
1903 &app->buffering_left);
1905 switch (app->mode) {
1906 case GST_BUFFERING_DOWNLOAD:
1907 do_download_buffering (app, percent);
1909 case GST_BUFFERING_LIVE:
1910 app->is_live = TRUE;
1911 case GST_BUFFERING_TIMESHIFT:
1912 case GST_BUFFERING_STREAM:
1913 do_stream_buffering (app, percent);
1919 msg_clock_lost (GstBus * bus, GstMessage * message, PlaybackApp * app)
1921 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
1922 if (app->state == GST_STATE_PLAYING) {
1923 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1924 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1929 is_valid_color_balance_element (GstElement * element)
1931 GstColorBalance *bal = GST_COLOR_BALANCE (element);
1932 gboolean have_brightness = FALSE;
1933 gboolean have_contrast = FALSE;
1934 gboolean have_hue = FALSE;
1935 gboolean have_saturation = FALSE;
1936 const GList *channels, *l;
1938 channels = gst_color_balance_list_channels (bal);
1939 for (l = channels; l; l = l->next) {
1940 GstColorBalanceChannel *ch = l->data;
1942 if (g_strrstr (ch->label, "BRIGHTNESS"))
1943 have_brightness = TRUE;
1944 else if (g_strrstr (ch->label, "CONTRAST"))
1945 have_contrast = TRUE;
1946 else if (g_strrstr (ch->label, "HUE"))
1948 else if (g_strrstr (ch->label, "SATURATION"))
1949 have_saturation = TRUE;
1952 return have_brightness && have_contrast && have_hue && have_saturation;
1956 find_interface_elements (PlaybackApp * app)
1959 GValue item = { 0, };
1960 gboolean done = FALSE, hardware = FALSE;
1962 if (app->pipeline_type == 0)
1965 if (app->navigation_element)
1966 gst_object_unref (app->navigation_element);
1967 app->navigation_element = NULL;
1969 if (app->colorbalance_element)
1970 gst_object_unref (app->colorbalance_element);
1971 app->colorbalance_element = NULL;
1973 app->navigation_element =
1974 gst_bin_get_by_interface (GST_BIN (app->pipeline), GST_TYPE_NAVIGATION);
1976 it = gst_bin_iterate_all_by_interface (GST_BIN (app->pipeline),
1977 GST_TYPE_COLOR_BALANCE);
1979 switch (gst_iterator_next (it, &item)) {
1980 case GST_ITERATOR_OK:{
1981 GstElement *element = GST_ELEMENT (g_value_get_object (&item));
1983 if (is_valid_color_balance_element (element)) {
1984 if (!app->colorbalance_element) {
1985 app->colorbalance_element =
1986 GST_ELEMENT_CAST (gst_object_ref (element));
1988 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1989 (element)) == GST_COLOR_BALANCE_HARDWARE);
1990 } else if (!hardware) {
1992 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1993 (element)) == GST_COLOR_BALANCE_HARDWARE);
1996 if (app->colorbalance_element)
1997 gst_object_unref (app->colorbalance_element);
1998 app->colorbalance_element =
1999 GST_ELEMENT_CAST (gst_object_ref (element));
2005 g_value_reset (&item);
2007 if (hardware && app->colorbalance_element)
2011 case GST_ITERATOR_RESYNC:
2012 gst_iterator_resync (it);
2015 if (app->colorbalance_element)
2016 gst_object_unref (app->colorbalance_element);
2017 app->colorbalance_element = NULL;
2019 case GST_ITERATOR_DONE:
2020 case GST_ITERATOR_ERROR:
2026 g_value_unset (&item);
2027 gst_iterator_free (it);
2030 /* called when Navigation command button is pressed */
2032 navigation_cmd_cb (GtkButton * button, PlaybackApp * app)
2034 GstNavigationCommand cmd = GST_NAVIGATION_COMMAND_INVALID;
2037 if (!app->navigation_element) {
2038 find_interface_elements (app);
2039 if (!app->navigation_element)
2043 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++) {
2044 if (app->navigation_buttons[i].button == GTK_WIDGET (button)) {
2045 cmd = app->navigation_buttons[i].cmd;
2050 if (cmd != GST_NAVIGATION_COMMAND_INVALID)
2051 gst_navigation_send_command (GST_NAVIGATION (app->navigation_element), cmd);
2054 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2055 /* We set the xid here in response to the prepare-xwindow-id message via a
2056 * bus sync handler because we don't know the actual videosink used from the
2057 * start (as we don't know the pipeline, or bin elements such as autovideosink
2058 * or gconfvideosink may be used which create the actual videosink only once
2059 * the pipeline is started) */
2060 static GstBusSyncReply
2061 bus_sync_handler (GstBus * bus, GstMessage * message, PlaybackApp * app)
2063 if (gst_is_video_overlay_prepare_window_handle_message (message)) {
2064 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
2066 if (app->overlay_element)
2067 gst_object_unref (app->overlay_element);
2068 app->overlay_element = GST_ELEMENT (gst_object_ref (element));
2070 g_print ("got prepare-xwindow-id, setting XID %" G_GUINTPTR_FORMAT "\n",
2073 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
2074 "force-aspect-ratio")) {
2075 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
2078 /* Should have been initialised from main thread before (can't use
2079 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
2080 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
2081 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
2082 * shouldn't be done from a non-GUI thread without explicit locking). */
2083 g_assert (app->embed_xid != 0);
2085 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (element),
2088 find_interface_elements (app);
2090 return GST_BUS_PASS;
2095 draw_cb (GtkWidget * widget, cairo_t * cr, PlaybackApp * app)
2097 if (app->state < GST_STATE_PAUSED) {
2100 width = gtk_widget_get_allocated_width (widget);
2101 height = gtk_widget_get_allocated_height (widget);
2102 cairo_set_source_rgb (cr, 0, 0, 0);
2103 cairo_rectangle (cr, 0, 0, width, height);
2108 if (app->overlay_element)
2109 gst_video_overlay_expose (GST_VIDEO_OVERLAY (app->overlay_element));
2115 realize_cb (GtkWidget * widget, PlaybackApp * app)
2117 GdkWindow *window = gtk_widget_get_window (widget);
2119 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
2121 if (!gdk_window_ensure_native (window))
2122 g_error ("Couldn't create native window needed for GstXOverlay!");
2124 #if defined (GDK_WINDOWING_WIN32)
2125 app->embed_xid = GDK_WINDOW_HWND (window);
2126 g_print ("Window realize: video window HWND = %lu\n", app->embed_xid);
2127 #elif defined (GDK_WINDOWING_QUARTZ)
2128 app->embed_xid = (guintptr) gdk_quartz_window_get_nsview (window);
2129 g_print ("Window realize: video window NSView = %p\n", app->embed_xid);
2130 #elif defined (GDK_WINDOWING_X11)
2131 app->embed_xid = GDK_WINDOW_XID (window);
2132 g_print ("Window realize: video window XID = %" G_GUINTPTR_FORMAT "\n",
2138 button_press_cb (GtkWidget * widget, GdkEventButton * event, PlaybackApp * app)
2140 gtk_widget_grab_focus (widget);
2142 if (app->navigation_element)
2143 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2144 "mouse-button-press", event->button, event->x, event->y);
2150 button_release_cb (GtkWidget * widget, GdkEventButton * event,
2153 if (app->navigation_element)
2154 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2155 "mouse-button-release", event->button, event->x, event->y);
2161 key_press_cb (GtkWidget * widget, GdkEventKey * event, PlaybackApp * app)
2163 if (app->navigation_element)
2164 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
2165 "key-press", gdk_keyval_name (event->keyval));
2171 key_release_cb (GtkWidget * widget, GdkEventKey * event, PlaybackApp * app)
2173 if (app->navigation_element)
2174 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
2175 "key-release", gdk_keyval_name (event->keyval));
2181 motion_notify_cb (GtkWidget * widget, GdkEventMotion * event, PlaybackApp * app)
2183 if (app->navigation_element)
2184 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
2185 "mouse-move", 0, event->x, event->y);
2191 msg_eos (GstBus * bus, GstMessage * message, PlaybackApp * app)
2193 message_received (bus, message, app);
2195 /* Set new uri for playerbins and continue playback */
2196 if (app->current_path && app->pipeline_type == 0) {
2197 stop_cb (NULL, app);
2198 app->current_path = g_list_next (app->current_path);
2199 app->current_sub_path = g_list_next (app->current_sub_path);
2200 if (app->current_path) {
2201 playbin_set_uri (app->pipeline, app->current_path->data,
2202 app->current_sub_path ? app->current_sub_path->data : NULL);
2203 play_cb (NULL, app);
2209 msg_step_done (GstBus * bus, GstMessage * message, PlaybackApp * app)
2211 if (!app->shuttling)
2212 message_received (bus, message, app);
2216 msg (GstBus * bus, GstMessage * message, PlaybackApp * app)
2218 GstNavigationMessageType nav_type;
2220 nav_type = gst_navigation_message_get_type (message);
2222 case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
2226 /* Heuristic to detect if we're dealing with a DVD menu */
2227 query = gst_navigation_query_new_commands ();
2228 res = gst_element_query (GST_ELEMENT (GST_MESSAGE_SRC (message)), query);
2230 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++)
2231 gtk_widget_set_sensitive (app->navigation_buttons[j].button, FALSE);
2234 gboolean is_menu = FALSE;
2237 if (gst_navigation_query_parse_commands_length (query, &n)) {
2238 for (i = 0; i < n; i++) {
2239 GstNavigationCommand cmd;
2241 if (!gst_navigation_query_parse_commands_nth (query, i, &cmd))
2244 is_menu |= (cmd == GST_NAVIGATION_COMMAND_ACTIVATE);
2245 is_menu |= (cmd == GST_NAVIGATION_COMMAND_LEFT);
2246 is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
2247 is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
2248 is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
2250 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++) {
2251 if (app->navigation_buttons[j].cmd != cmd)
2254 gtk_widget_set_sensitive (app->navigation_buttons[j].button,
2260 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), !is_menu);
2262 g_assert_not_reached ();
2265 gst_query_unref (query);
2266 message_received (bus, message, app);
2275 connect_bus_signals (PlaybackApp * app)
2277 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
2279 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2280 if (app->pipeline_type != 0) {
2281 /* handle prepare-xwindow-id element message synchronously, but only for non-playbin */
2282 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, app);
2286 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2287 gst_bus_enable_sync_message_emission (bus);
2289 g_signal_connect (bus, "message::state-changed",
2290 G_CALLBACK (msg_state_changed), app);
2291 g_signal_connect (bus, "message::segment-done", G_CALLBACK (msg_segment_done),
2293 g_signal_connect (bus, "message::async-done", G_CALLBACK (msg_async_done),
2296 g_signal_connect (bus, "message::new-clock", G_CALLBACK (message_received),
2298 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (msg_clock_lost),
2300 g_signal_connect (bus, "message::error", G_CALLBACK (message_received), app);
2301 g_signal_connect (bus, "message::warning", G_CALLBACK (message_received),
2303 g_signal_connect (bus, "message::eos", G_CALLBACK (msg_eos), app);
2304 g_signal_connect (bus, "message::tag", G_CALLBACK (message_received), app);
2305 g_signal_connect (bus, "message::element", G_CALLBACK (message_received),
2307 g_signal_connect (bus, "message::segment-done", G_CALLBACK (message_received),
2309 g_signal_connect (bus, "message::buffering", G_CALLBACK (msg_buffering), app);
2310 // g_signal_connect (bus, "message::step-done", G_CALLBACK (msg_step_done),
2312 g_signal_connect (bus, "message::step-start", G_CALLBACK (msg_step_done),
2314 g_signal_connect (bus, "sync-message::step-done",
2315 G_CALLBACK (msg_sync_step_done), app);
2316 g_signal_connect (bus, "message", G_CALLBACK (msg), app);
2318 gst_object_unref (bus);
2321 /* Return GList of paths described in location string */
2323 handle_wildcards (const gchar * location)
2326 gchar *path = g_path_get_dirname (location);
2327 gchar *pattern = g_path_get_basename (location);
2328 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2329 GDir *dir = g_dir_open (path, 0, NULL);
2332 g_print ("matching %s from %s\n", pattern, path);
2335 g_print ("opening directory %s failed\n", path);
2339 while ((name = g_dir_read_name (dir)) != NULL) {
2340 if (g_pattern_match_string (pspec, name)) {
2341 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2342 g_print (" found clip %s\n", name);
2348 g_pattern_spec_free (pspec);
2356 delete_event_cb (GtkWidget * widget, GdkEvent * event, PlaybackApp * app)
2358 stop_cb (NULL, app);
2363 video_sink_activate_cb (GtkEntry * entry, PlaybackApp * app)
2365 GstElement *sink = NULL;
2368 text = gtk_entry_get_text (entry);
2369 if (text != NULL && *text != '\0') {
2370 sink = gst_element_factory_make_or_warn (text, NULL);
2373 g_object_set (app->pipeline, "video-sink", sink, NULL);
2377 audio_sink_activate_cb (GtkEntry * entry, PlaybackApp * app)
2379 GstElement *sink = NULL;
2382 text = gtk_entry_get_text (entry);
2383 if (text != NULL && *text != '\0') {
2384 sink = gst_element_factory_make_or_warn (text, NULL);
2387 g_object_set (app->pipeline, "audio-sink", sink, NULL);
2391 text_sink_activate_cb (GtkEntry * entry, PlaybackApp * app)
2393 GstElement *sink = NULL;
2396 text = gtk_entry_get_text (entry);
2397 if (text != NULL && *text != '\0') {
2398 sink = gst_element_factory_make_or_warn (text, NULL);
2401 g_object_set (app->pipeline, "text-sink", sink, NULL);
2405 buffer_size_activate_cb (GtkEntry * entry, PlaybackApp * app)
2409 text = gtk_entry_get_text (entry);
2410 if (text != NULL && *text != '\0') {
2414 v = g_ascii_strtoll (text, &endptr, 10);
2415 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2416 g_object_set (app->pipeline, "buffer-size", v, NULL);
2422 buffer_duration_activate_cb (GtkEntry * entry, PlaybackApp * app)
2426 text = gtk_entry_get_text (entry);
2427 if (text != NULL && *text != '\0') {
2431 v = g_ascii_strtoll (text, &endptr, 10);
2432 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2433 g_object_set (app->pipeline, "buffer-duration", v, NULL);
2439 ringbuffer_maxsize_activate_cb (GtkEntry * entry, PlaybackApp * app)
2443 text = gtk_entry_get_text (entry);
2444 if (text != NULL && *text != '\0') {
2448 v = g_ascii_strtoull (text, &endptr, 10);
2449 if (endptr != text && v != G_MAXUINT64) {
2450 g_object_set (app->pipeline, "ring-buffer-max-size", v, NULL);
2456 connection_speed_activate_cb (GtkEntry * entry, PlaybackApp * app)
2460 text = gtk_entry_get_text (entry);
2461 if (text != NULL && *text != '\0') {
2465 v = g_ascii_strtoll (text, &endptr, 10);
2466 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2467 g_object_set (app->pipeline, "connection-speed", v, NULL);
2473 subtitle_encoding_activate_cb (GtkEntry * entry, PlaybackApp * app)
2477 text = gtk_entry_get_text (entry);
2478 g_object_set (app->pipeline, "subtitle-encoding", text, NULL);
2482 subtitle_fontdesc_cb (GtkFontButton * button, PlaybackApp * app)
2486 text = gtk_font_button_get_font_name (button);
2487 g_object_set (app->pipeline, "subtitle-font-desc", text, NULL);
2491 av_offset_activate_cb (GtkEntry * entry, PlaybackApp * app)
2495 text = gtk_entry_get_text (entry);
2496 if (text != NULL && *text != '\0') {
2500 v = g_ascii_strtoll (text, &endptr, 10);
2501 if (endptr != text && v != G_MAXINT64 && v != G_MININT64) {
2502 g_object_set (app->pipeline, "av-offset", v, NULL);
2508 print_usage (int argc, char **argv)
2512 g_print ("usage: %s <type> <filename>\n", argv[0]);
2513 g_print (" possible types:\n");
2515 for (i = 0; i < G_N_ELEMENTS (pipelines); i++) {
2516 g_print (" %d = %s\n", i, pipelines[i].name);
2521 create_ui (PlaybackApp * app)
2523 GtkWidget *hbox, *vbox, *seek, *playbin, *step, *navigation, *colorbalance;
2524 GtkWidget *play_button, *pause_button, *stop_button;
2525 GtkAdjustment *adjustment;
2527 /* initialize gui elements ... */
2528 app->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2529 app->video_window = gtk_drawing_area_new ();
2530 g_signal_connect (app->video_window, "draw", G_CALLBACK (draw_cb), app);
2531 g_signal_connect (app->video_window, "realize", G_CALLBACK (realize_cb), app);
2532 g_signal_connect (app->video_window, "button-press-event",
2533 G_CALLBACK (button_press_cb), app);
2534 g_signal_connect (app->video_window, "button-release-event",
2535 G_CALLBACK (button_release_cb), app);
2536 g_signal_connect (app->video_window, "key-press-event",
2537 G_CALLBACK (key_press_cb), app);
2538 g_signal_connect (app->video_window, "key-release-event",
2539 G_CALLBACK (key_release_cb), app);
2540 g_signal_connect (app->video_window, "motion-notify-event",
2541 G_CALLBACK (motion_notify_cb), app);
2542 gtk_widget_set_can_focus (app->video_window, TRUE);
2543 gtk_widget_set_double_buffered (app->video_window, FALSE);
2544 gtk_widget_add_events (app->video_window,
2545 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
2546 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2548 app->statusbar = gtk_statusbar_new ();
2550 gtk_statusbar_get_context_id (GTK_STATUSBAR (app->statusbar),
2552 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
2554 hbox = gtk_hbox_new (FALSE, 0);
2555 vbox = gtk_vbox_new (FALSE, 0);
2556 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2558 /* media controls */
2559 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2560 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2561 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2565 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox,
2566 *flush_checkbox, *snap_before_checkbox, *snap_after_checkbox;
2567 GtkWidget *scrub_checkbox, *play_scrub_checkbox, *rate_label;
2568 GtkWidget *skip_checkbox, *rate_spinbutton;
2569 GtkWidget *flagtable, *advanced_seek, *advanced_seek_grid;
2570 GtkWidget *duration_label, *position_label, *seek_button;
2572 seek = gtk_expander_new ("seek options");
2573 flagtable = gtk_grid_new ();
2574 gtk_grid_set_row_spacing (GTK_GRID (flagtable), 2);
2575 gtk_grid_set_row_homogeneous (GTK_GRID (flagtable), FALSE);
2576 gtk_grid_set_column_spacing (GTK_GRID (flagtable), 2);
2577 gtk_grid_set_column_homogeneous (GTK_GRID (flagtable), FALSE);
2579 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Playback");
2580 key_checkbox = gtk_check_button_new_with_label ("Key-unit Playback");
2581 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2582 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2583 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2584 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2585 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2586 snap_before_checkbox = gtk_check_button_new_with_label ("Snap before");
2587 snap_after_checkbox = gtk_check_button_new_with_label ("Snap after");
2588 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2589 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2590 rate_label = gtk_label_new ("Rate");
2592 gtk_widget_set_tooltip_text (accurate_checkbox,
2593 "accurate position is requested, this might be considerably slower for some formats");
2594 gtk_widget_set_tooltip_text (key_checkbox,
2595 "seek to the nearest keyframe. This might be faster but less accurate");
2596 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2597 gtk_widget_set_tooltip_text (flush_checkbox,
2598 "flush pipeline after seeking");
2599 gtk_widget_set_tooltip_text (rate_spinbutton,
2600 "define the playback rate, " "negative value trigger reverse playback");
2601 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2602 gtk_widget_set_tooltip_text (play_scrub_checkbox,
2603 "play video while seeking");
2604 gtk_widget_set_tooltip_text (skip_checkbox,
2605 "Skip frames while playing at high frame rates");
2606 gtk_widget_set_tooltip_text (snap_before_checkbox,
2607 "Favor snapping to the frame before the seek target");
2608 gtk_widget_set_tooltip_text (snap_after_checkbox,
2609 "Favor snapping to the frame after the seek target");
2611 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2612 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2614 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), app->rate);
2616 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2617 G_CALLBACK (accurate_toggle_cb), app);
2618 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2619 G_CALLBACK (key_toggle_cb), app);
2620 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2621 G_CALLBACK (loop_toggle_cb), app);
2622 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2623 G_CALLBACK (flush_toggle_cb), app);
2624 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2625 G_CALLBACK (scrub_toggle_cb), app);
2626 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2627 G_CALLBACK (play_scrub_toggle_cb), app);
2628 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2629 G_CALLBACK (skip_toggle_cb), app);
2630 g_signal_connect (G_OBJECT (rate_spinbutton), "value-changed",
2631 G_CALLBACK (rate_spinbutton_changed_cb), app);
2632 g_signal_connect (G_OBJECT (snap_before_checkbox), "toggled",
2633 G_CALLBACK (snap_before_toggle_cb), app);
2634 g_signal_connect (G_OBJECT (snap_after_checkbox), "toggled",
2635 G_CALLBACK (snap_after_toggle_cb), app);
2637 gtk_grid_attach (GTK_GRID (flagtable), accurate_checkbox, 0, 0, 1, 1);
2638 gtk_grid_attach (GTK_GRID (flagtable), flush_checkbox, 1, 0, 1, 1);
2639 gtk_grid_attach (GTK_GRID (flagtable), loop_checkbox, 2, 0, 1, 1);
2640 gtk_grid_attach (GTK_GRID (flagtable), key_checkbox, 0, 1, 1, 1);
2641 gtk_grid_attach (GTK_GRID (flagtable), scrub_checkbox, 1, 1, 1, 1);
2642 gtk_grid_attach (GTK_GRID (flagtable), play_scrub_checkbox, 2, 1, 1, 1);
2643 gtk_grid_attach (GTK_GRID (flagtable), skip_checkbox, 3, 0, 1, 1);
2644 gtk_grid_attach (GTK_GRID (flagtable), rate_label, 4, 0, 1, 1);
2645 gtk_grid_attach (GTK_GRID (flagtable), rate_spinbutton, 4, 1, 1, 1);
2646 gtk_grid_attach (GTK_GRID (flagtable), snap_before_checkbox, 0, 2, 1, 1);
2647 gtk_grid_attach (GTK_GRID (flagtable), snap_after_checkbox, 1, 2, 1, 1);
2649 advanced_seek = gtk_frame_new ("Advanced Seeking");
2650 advanced_seek_grid = gtk_grid_new ();
2651 gtk_grid_set_row_spacing (GTK_GRID (advanced_seek_grid), 2);
2652 gtk_grid_set_row_homogeneous (GTK_GRID (advanced_seek_grid), FALSE);
2653 gtk_grid_set_column_spacing (GTK_GRID (advanced_seek_grid), 5);
2654 gtk_grid_set_column_homogeneous (GTK_GRID (advanced_seek_grid), FALSE);
2656 app->seek_format_combo = gtk_combo_box_text_new ();
2657 g_signal_connect (app->seek_format_combo, "changed",
2658 G_CALLBACK (seek_format_changed_cb), app);
2659 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_format_combo, 0,
2662 app->seek_entry = gtk_entry_new ();
2663 gtk_entry_set_width_chars (GTK_ENTRY (app->seek_entry), 12);
2664 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_entry, 0, 1, 1,
2667 seek_button = gtk_button_new_with_label ("Seek");
2668 g_signal_connect (G_OBJECT (seek_button), "clicked",
2669 G_CALLBACK (advanced_seek_button_cb), app);
2670 gtk_grid_attach (GTK_GRID (advanced_seek_grid), seek_button, 1, 0, 1, 1);
2672 position_label = gtk_label_new ("Position:");
2673 gtk_grid_attach (GTK_GRID (advanced_seek_grid), position_label, 2, 0, 1, 1);
2674 duration_label = gtk_label_new ("Duration:");
2675 gtk_grid_attach (GTK_GRID (advanced_seek_grid), duration_label, 2, 1, 1, 1);
2677 app->seek_position_label = gtk_label_new ("-1");
2678 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_position_label, 3,
2680 app->seek_duration_label = gtk_label_new ("-1");
2681 gtk_grid_attach (GTK_GRID (advanced_seek_grid), app->seek_duration_label, 3,
2684 gtk_container_add (GTK_CONTAINER (advanced_seek), advanced_seek_grid);
2685 gtk_grid_attach (GTK_GRID (flagtable), advanced_seek, 0, 3, 3, 2);
2686 gtk_container_add (GTK_CONTAINER (seek), flagtable);
2692 GtkWidget *step_button, *shuttle_checkbox;
2694 step = gtk_expander_new ("step options");
2695 hbox = gtk_hbox_new (FALSE, 0);
2697 app->step_format_combo = gtk_combo_box_text_new ();
2698 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->step_format_combo),
2700 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->step_format_combo),
2702 gtk_combo_box_set_active (GTK_COMBO_BOX (app->step_format_combo), 0);
2703 gtk_box_pack_start (GTK_BOX (hbox), app->step_format_combo, FALSE, FALSE,
2706 app->step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2707 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2709 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2711 gtk_box_pack_start (GTK_BOX (hbox), app->step_amount_spinbutton, FALSE,
2714 app->step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2715 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_rate_spinbutton), 3);
2716 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton),
2718 gtk_box_pack_start (GTK_BOX (hbox), app->step_rate_spinbutton, FALSE, FALSE,
2721 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2722 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2723 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2725 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2729 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2730 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2731 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2732 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2736 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2737 app->shuttle_scale = gtk_hscale_new (adjustment);
2738 gtk_scale_set_digits (GTK_SCALE (app->shuttle_scale), 2);
2739 gtk_scale_set_value_pos (GTK_SCALE (app->shuttle_scale), GTK_POS_TOP);
2740 g_signal_connect (app->shuttle_scale, "value-changed",
2741 G_CALLBACK (shuttle_value_changed), app);
2742 g_signal_connect (app->shuttle_scale, "format_value",
2743 G_CALLBACK (shuttle_format_value), app);
2745 gtk_box_pack_start (GTK_BOX (hbox), app->shuttle_scale, TRUE, TRUE, 2);
2747 gtk_container_add (GTK_CONTAINER (step), hbox);
2750 /* navigation command expander */
2752 GtkWidget *navigation_button;
2756 navigation = gtk_expander_new ("navigation commands");
2757 grid = gtk_grid_new ();
2758 gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
2759 gtk_grid_set_row_homogeneous (GTK_GRID (grid), FALSE);
2760 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2761 gtk_grid_set_column_homogeneous (GTK_GRID (grid), FALSE);
2763 navigation_button = gtk_button_new_with_label ("Menu 1");
2764 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2765 G_CALLBACK (navigation_cmd_cb), app);
2766 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2767 gtk_widget_set_sensitive (navigation_button, FALSE);
2768 gtk_widget_set_tooltip_text (navigation_button, "DVD Menu");
2769 app->navigation_buttons[i].button = navigation_button;
2770 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU1;
2772 navigation_button = gtk_button_new_with_label ("Menu 2");
2773 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2774 G_CALLBACK (navigation_cmd_cb), app);
2775 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2776 gtk_widget_set_sensitive (navigation_button, FALSE);
2777 gtk_widget_set_tooltip_text (navigation_button, "DVD Title Menu");
2778 app->navigation_buttons[i].button = navigation_button;
2779 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU2;
2781 navigation_button = gtk_button_new_with_label ("Menu 3");
2782 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2783 G_CALLBACK (navigation_cmd_cb), app);
2784 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2785 gtk_widget_set_sensitive (navigation_button, FALSE);
2786 gtk_widget_set_tooltip_text (navigation_button, "DVD Root Menu");
2787 app->navigation_buttons[i].button = navigation_button;
2788 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU3;
2790 navigation_button = gtk_button_new_with_label ("Menu 4");
2791 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2792 G_CALLBACK (navigation_cmd_cb), app);
2793 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2794 gtk_widget_set_sensitive (navigation_button, FALSE);
2795 gtk_widget_set_tooltip_text (navigation_button, "DVD Subpicture Menu");
2796 app->navigation_buttons[i].button = navigation_button;
2797 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU4;
2799 navigation_button = gtk_button_new_with_label ("Menu 5");
2800 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2801 G_CALLBACK (navigation_cmd_cb), app);
2802 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2803 gtk_widget_set_sensitive (navigation_button, FALSE);
2804 gtk_widget_set_tooltip_text (navigation_button, "DVD Audio Menu");
2805 app->navigation_buttons[i].button = navigation_button;
2806 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU5;
2808 navigation_button = gtk_button_new_with_label ("Menu 6");
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, 0, 1, 1);
2812 gtk_widget_set_sensitive (navigation_button, FALSE);
2813 gtk_widget_set_tooltip_text (navigation_button, "DVD Angle Menu");
2814 app->navigation_buttons[i].button = navigation_button;
2815 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU6;
2817 navigation_button = gtk_button_new_with_label ("Menu 7");
2818 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2819 G_CALLBACK (navigation_cmd_cb), app);
2820 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2821 gtk_widget_set_sensitive (navigation_button, FALSE);
2822 gtk_widget_set_tooltip_text (navigation_button, "DVD Chapter Menu");
2823 app->navigation_buttons[i].button = navigation_button;
2824 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU7;
2826 navigation_button = gtk_button_new_with_label ("Left");
2827 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2828 G_CALLBACK (navigation_cmd_cb), app);
2829 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2830 gtk_widget_set_sensitive (navigation_button, FALSE);
2831 app->navigation_buttons[i].button = navigation_button;
2832 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_LEFT;
2834 navigation_button = gtk_button_new_with_label ("Right");
2835 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2836 G_CALLBACK (navigation_cmd_cb), app);
2837 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2838 gtk_widget_set_sensitive (navigation_button, FALSE);
2839 app->navigation_buttons[i].button = navigation_button;
2840 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_RIGHT;
2842 navigation_button = gtk_button_new_with_label ("Up");
2843 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2844 G_CALLBACK (navigation_cmd_cb), app);
2845 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2846 gtk_widget_set_sensitive (navigation_button, FALSE);
2847 app->navigation_buttons[i].button = navigation_button;
2848 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_UP;
2850 navigation_button = gtk_button_new_with_label ("Down");
2851 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2852 G_CALLBACK (navigation_cmd_cb), app);
2853 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2854 gtk_widget_set_sensitive (navigation_button, FALSE);
2855 app->navigation_buttons[i].button = navigation_button;
2856 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_DOWN;
2858 navigation_button = gtk_button_new_with_label ("Activate");
2859 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2860 G_CALLBACK (navigation_cmd_cb), app);
2861 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2862 gtk_widget_set_sensitive (navigation_button, FALSE);
2863 app->navigation_buttons[i].button = navigation_button;
2864 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_ACTIVATE;
2866 navigation_button = gtk_button_new_with_label ("Prev. Angle");
2867 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2868 G_CALLBACK (navigation_cmd_cb), app);
2869 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2870 gtk_widget_set_sensitive (navigation_button, FALSE);
2871 app->navigation_buttons[i].button = navigation_button;
2872 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_PREV_ANGLE;
2874 navigation_button = gtk_button_new_with_label ("Next. Angle");
2875 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2876 G_CALLBACK (navigation_cmd_cb), app);
2877 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2878 gtk_widget_set_sensitive (navigation_button, FALSE);
2879 app->navigation_buttons[i].button = navigation_button;
2880 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_NEXT_ANGLE;
2882 gtk_container_add (GTK_CONTAINER (navigation), grid);
2885 /* colorbalance expander */
2887 GtkWidget *vbox, *frame;
2889 colorbalance = gtk_expander_new ("color balance options");
2890 vbox = gtk_vbox_new (FALSE, 0);
2892 /* contrast scale */
2893 frame = gtk_frame_new ("Contrast");
2895 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2897 app->contrast_scale = gtk_hscale_new (adjustment);
2898 gtk_scale_set_draw_value (GTK_SCALE (app->contrast_scale), FALSE);
2899 g_signal_connect (app->contrast_scale, "value-changed",
2900 G_CALLBACK (colorbalance_value_changed), app);
2901 gtk_container_add (GTK_CONTAINER (frame), app->contrast_scale);
2902 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2904 /* brightness scale */
2905 frame = gtk_frame_new ("Brightness");
2907 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2909 app->brightness_scale = gtk_hscale_new (adjustment);
2910 gtk_scale_set_draw_value (GTK_SCALE (app->brightness_scale), FALSE);
2911 g_signal_connect (app->brightness_scale, "value-changed",
2912 G_CALLBACK (colorbalance_value_changed), app);
2913 gtk_container_add (GTK_CONTAINER (frame), app->brightness_scale);
2914 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2917 frame = gtk_frame_new ("Hue");
2919 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2921 app->hue_scale = gtk_hscale_new (adjustment);
2922 gtk_scale_set_draw_value (GTK_SCALE (app->hue_scale), FALSE);
2923 g_signal_connect (app->hue_scale, "value-changed",
2924 G_CALLBACK (colorbalance_value_changed), app);
2925 gtk_container_add (GTK_CONTAINER (frame), app->hue_scale);
2926 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2928 /* saturation scale */
2929 frame = gtk_frame_new ("Saturation");
2931 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2933 app->saturation_scale = gtk_hscale_new (adjustment);
2934 gtk_scale_set_draw_value (GTK_SCALE (app->saturation_scale), FALSE);
2935 g_signal_connect (app->saturation_scale, "value-changed",
2936 G_CALLBACK (colorbalance_value_changed), app);
2937 gtk_container_add (GTK_CONTAINER (frame), app->saturation_scale);
2938 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2940 gtk_container_add (GTK_CONTAINER (colorbalance), vbox);
2945 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2946 app->seek_scale = gtk_hscale_new (adjustment);
2947 gtk_scale_set_digits (GTK_SCALE (app->seek_scale), 2);
2948 gtk_scale_set_value_pos (GTK_SCALE (app->seek_scale), GTK_POS_RIGHT);
2949 gtk_range_set_show_fill_level (GTK_RANGE (app->seek_scale), TRUE);
2950 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), N_GRAD);
2952 g_signal_connect (app->seek_scale, "button_press_event",
2953 G_CALLBACK (start_seek), app);
2954 g_signal_connect (app->seek_scale, "button_release_event",
2955 G_CALLBACK (stop_seek), app);
2956 g_signal_connect (app->seek_scale, "format_value", G_CALLBACK (format_value),
2959 if (app->pipeline_type == 0) {
2960 GtkWidget *pb2vbox, *boxes, *boxes2, *panel, *boxes3;
2961 GtkWidget *volume_label, *shot_button;
2964 playbin = gtk_expander_new ("playbin options");
2965 /* the playbin panel controls for the video/audio/subtitle tracks */
2966 panel = gtk_hbox_new (FALSE, 0);
2967 app->video_combo = gtk_combo_box_text_new ();
2968 app->audio_combo = gtk_combo_box_text_new ();
2969 app->text_combo = gtk_combo_box_text_new ();
2970 gtk_widget_set_sensitive (app->video_combo, FALSE);
2971 gtk_widget_set_sensitive (app->audio_combo, FALSE);
2972 gtk_widget_set_sensitive (app->text_combo, FALSE);
2973 gtk_box_pack_start (GTK_BOX (panel), app->video_combo, TRUE, TRUE, 2);
2974 gtk_box_pack_start (GTK_BOX (panel), app->audio_combo, TRUE, TRUE, 2);
2975 gtk_box_pack_start (GTK_BOX (panel), app->text_combo, TRUE, TRUE, 2);
2976 g_signal_connect (G_OBJECT (app->video_combo), "changed",
2977 G_CALLBACK (video_combo_cb), app);
2978 g_signal_connect (G_OBJECT (app->audio_combo), "changed",
2979 G_CALLBACK (audio_combo_cb), app);
2980 g_signal_connect (G_OBJECT (app->text_combo), "changed",
2981 G_CALLBACK (text_combo_cb), app);
2982 /* playbin panel for flag checkboxes and volume/mute */
2983 boxes = gtk_grid_new ();
2984 gtk_grid_set_row_spacing (GTK_GRID (boxes), 2);
2985 gtk_grid_set_row_homogeneous (GTK_GRID (boxes), FALSE);
2986 gtk_grid_set_column_spacing (GTK_GRID (boxes), 2);
2987 gtk_grid_set_column_homogeneous (GTK_GRID (boxes), FALSE);
2989 app->video_checkbox = gtk_check_button_new_with_label ("Video");
2990 app->audio_checkbox = gtk_check_button_new_with_label ("Audio");
2991 app->text_checkbox = gtk_check_button_new_with_label ("Text");
2992 app->vis_checkbox = gtk_check_button_new_with_label ("Vis");
2993 app->soft_volume_checkbox = gtk_check_button_new_with_label ("Soft Volume");
2994 app->native_audio_checkbox =
2995 gtk_check_button_new_with_label ("Native Audio");
2996 app->native_video_checkbox =
2997 gtk_check_button_new_with_label ("Native Video");
2998 app->download_checkbox = gtk_check_button_new_with_label ("Download");
2999 app->buffering_checkbox = gtk_check_button_new_with_label ("Buffering");
3000 app->deinterlace_checkbox = gtk_check_button_new_with_label ("Deinterlace");
3001 app->soft_colorbalance_checkbox =
3002 gtk_check_button_new_with_label ("Soft Colorbalance");
3003 app->mute_checkbox = gtk_check_button_new_with_label ("Mute");
3004 volume_label = gtk_label_new ("Volume");
3005 app->volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
3007 gtk_grid_attach (GTK_GRID (boxes), app->video_checkbox, 0, 0, 1, 1);
3008 gtk_grid_attach (GTK_GRID (boxes), app->audio_checkbox, 1, 0, 1, 1);
3009 gtk_grid_attach (GTK_GRID (boxes), app->text_checkbox, 2, 0, 1, 1);
3010 gtk_grid_attach (GTK_GRID (boxes), app->vis_checkbox, 3, 0, 1, 1);
3011 gtk_grid_attach (GTK_GRID (boxes), app->soft_volume_checkbox, 4, 0, 1, 1);
3012 gtk_grid_attach (GTK_GRID (boxes), app->native_audio_checkbox, 5, 0, 1, 1);
3013 gtk_grid_attach (GTK_GRID (boxes), app->native_video_checkbox, 0, 1, 1, 1);
3014 gtk_grid_attach (GTK_GRID (boxes), app->download_checkbox, 1, 1, 1, 1);
3015 gtk_grid_attach (GTK_GRID (boxes), app->buffering_checkbox, 2, 1, 1, 1);
3016 gtk_grid_attach (GTK_GRID (boxes), app->deinterlace_checkbox, 3, 1, 1, 1);
3017 gtk_grid_attach (GTK_GRID (boxes), app->soft_colorbalance_checkbox, 4, 1, 1,
3020 gtk_grid_attach (GTK_GRID (boxes), app->mute_checkbox, 6, 0, 1, 1);
3021 gtk_grid_attach (GTK_GRID (boxes), volume_label, 5, 1, 1, 1);
3022 gtk_grid_attach (GTK_GRID (boxes), app->volume_spinbutton, 6, 1, 1, 1);
3024 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->video_checkbox),
3026 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->audio_checkbox),
3028 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->text_checkbox), TRUE);
3029 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->vis_checkbox), FALSE);
3030 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->soft_volume_checkbox),
3032 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
3033 (app->native_audio_checkbox), FALSE);
3034 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
3035 (app->native_video_checkbox), FALSE);
3036 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->download_checkbox),
3038 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->buffering_checkbox),
3040 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->deinterlace_checkbox),
3042 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
3043 (app->soft_colorbalance_checkbox), TRUE);
3044 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
3046 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton), 1.0);
3048 g_signal_connect (G_OBJECT (app->video_checkbox), "toggled",
3049 G_CALLBACK (video_toggle_cb), app);
3050 g_signal_connect (G_OBJECT (app->audio_checkbox), "toggled",
3051 G_CALLBACK (audio_toggle_cb), app);
3052 g_signal_connect (G_OBJECT (app->text_checkbox), "toggled",
3053 G_CALLBACK (text_toggle_cb), app);
3054 g_signal_connect (G_OBJECT (app->vis_checkbox), "toggled",
3055 G_CALLBACK (vis_toggle_cb), app);
3056 g_signal_connect (G_OBJECT (app->soft_volume_checkbox), "toggled",
3057 G_CALLBACK (soft_volume_toggle_cb), app);
3058 g_signal_connect (G_OBJECT (app->native_audio_checkbox), "toggled",
3059 G_CALLBACK (native_audio_toggle_cb), app);
3060 g_signal_connect (G_OBJECT (app->native_video_checkbox), "toggled",
3061 G_CALLBACK (native_video_toggle_cb), app);
3062 g_signal_connect (G_OBJECT (app->download_checkbox), "toggled",
3063 G_CALLBACK (download_toggle_cb), app);
3064 g_signal_connect (G_OBJECT (app->buffering_checkbox), "toggled",
3065 G_CALLBACK (buffering_toggle_cb), app);
3066 g_signal_connect (G_OBJECT (app->deinterlace_checkbox), "toggled",
3067 G_CALLBACK (deinterlace_toggle_cb), app);
3068 g_signal_connect (G_OBJECT (app->soft_colorbalance_checkbox), "toggled",
3069 G_CALLBACK (soft_colorbalance_toggle_cb), app);
3070 g_signal_connect (G_OBJECT (app->mute_checkbox), "toggled",
3071 G_CALLBACK (mute_toggle_cb), app);
3072 g_signal_connect (G_OBJECT (app->volume_spinbutton), "value-changed",
3073 G_CALLBACK (volume_spinbutton_changed_cb), app);
3074 /* playbin panel for snapshot */
3075 boxes2 = gtk_hbox_new (FALSE, 0);
3076 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
3077 gtk_widget_set_tooltip_text (shot_button,
3078 "save a screenshot .png in the current directory");
3079 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
3081 app->vis_combo = gtk_combo_box_text_new ();
3082 g_signal_connect (G_OBJECT (app->vis_combo), "changed",
3083 G_CALLBACK (vis_combo_cb), app);
3084 gtk_widget_set_sensitive (app->vis_combo, FALSE);
3085 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
3086 gtk_box_pack_start (GTK_BOX (boxes2), app->vis_combo, TRUE, TRUE, 2);
3088 /* fill the vis combo box and the array of factories */
3089 init_visualization_features (app);
3091 /* Grid with other properties */
3092 boxes3 = gtk_grid_new ();
3093 gtk_grid_set_row_spacing (GTK_GRID (boxes3), 2);
3094 gtk_grid_set_row_homogeneous (GTK_GRID (boxes3), FALSE);
3095 gtk_grid_set_column_spacing (GTK_GRID (boxes3), 2);
3096 gtk_grid_set_column_homogeneous (GTK_GRID (boxes3), FALSE);
3098 label = gtk_label_new ("Video sink");
3099 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 0, 1, 1);
3100 app->video_sink_entry = gtk_entry_new ();
3101 g_signal_connect (app->video_sink_entry, "activate",
3102 G_CALLBACK (video_sink_activate_cb), app);
3103 gtk_grid_attach (GTK_GRID (boxes3), app->video_sink_entry, 0, 1, 1, 1);
3105 label = gtk_label_new ("Audio sink");
3106 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 0, 1, 1);
3107 app->audio_sink_entry = gtk_entry_new ();
3108 g_signal_connect (app->audio_sink_entry, "activate",
3109 G_CALLBACK (audio_sink_activate_cb), app);
3110 gtk_grid_attach (GTK_GRID (boxes3), app->audio_sink_entry, 1, 1, 1, 1);
3112 label = gtk_label_new ("Text sink");
3113 gtk_grid_attach (GTK_GRID (boxes3), label, 2, 0, 1, 1);
3114 app->text_sink_entry = gtk_entry_new ();
3115 g_signal_connect (app->text_sink_entry, "activate",
3116 G_CALLBACK (text_sink_activate_cb), app);
3117 gtk_grid_attach (GTK_GRID (boxes3), app->text_sink_entry, 2, 1, 1, 1);
3119 label = gtk_label_new ("Buffer Size");
3120 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 2, 1, 1);
3121 app->buffer_size_entry = gtk_entry_new ();
3122 gtk_entry_set_text (GTK_ENTRY (app->buffer_size_entry), "-1");
3123 g_signal_connect (app->buffer_size_entry, "activate",
3124 G_CALLBACK (buffer_size_activate_cb), app);
3125 gtk_grid_attach (GTK_GRID (boxes3), app->buffer_size_entry, 0, 3, 1, 1);
3127 label = gtk_label_new ("Buffer Duration");
3128 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 2, 1, 1);
3129 app->buffer_duration_entry = gtk_entry_new ();
3130 gtk_entry_set_text (GTK_ENTRY (app->buffer_duration_entry), "-1");
3131 g_signal_connect (app->buffer_duration_entry, "activate",
3132 G_CALLBACK (buffer_duration_activate_cb), app);
3133 gtk_grid_attach (GTK_GRID (boxes3), app->buffer_duration_entry, 1, 3, 1, 1);
3135 label = gtk_label_new ("Ringbuffer Max Size");
3136 gtk_grid_attach (GTK_GRID (boxes3), label, 2, 2, 1, 1);
3137 app->ringbuffer_maxsize_entry = gtk_entry_new ();
3138 gtk_entry_set_text (GTK_ENTRY (app->ringbuffer_maxsize_entry), "0");
3139 g_signal_connect (app->ringbuffer_maxsize_entry, "activate",
3140 G_CALLBACK (ringbuffer_maxsize_activate_cb), app);
3141 gtk_grid_attach (GTK_GRID (boxes3), app->ringbuffer_maxsize_entry, 2, 3, 1,
3144 label = gtk_label_new ("Connection Speed");
3145 gtk_grid_attach (GTK_GRID (boxes3), label, 3, 2, 1, 1);
3146 app->connection_speed_entry = gtk_entry_new ();
3147 gtk_entry_set_text (GTK_ENTRY (app->connection_speed_entry), "0");
3148 g_signal_connect (app->connection_speed_entry, "activate",
3149 G_CALLBACK (connection_speed_activate_cb), app);
3150 gtk_grid_attach (GTK_GRID (boxes3), app->connection_speed_entry, 3, 3, 1,
3153 label = gtk_label_new ("A/V offset");
3154 gtk_grid_attach (GTK_GRID (boxes3), label, 4, 2, 1, 1);
3155 app->av_offset_entry = gtk_entry_new ();
3156 g_signal_connect (app->av_offset_entry, "activate",
3157 G_CALLBACK (av_offset_activate_cb), app);
3158 gtk_entry_set_text (GTK_ENTRY (app->av_offset_entry), "0");
3159 g_signal_connect (app->av_offset_entry, "activate",
3160 G_CALLBACK (av_offset_activate_cb), app);
3161 gtk_grid_attach (GTK_GRID (boxes3), app->av_offset_entry, 4, 3, 1, 1);
3163 label = gtk_label_new ("Subtitle Encoding");
3164 gtk_grid_attach (GTK_GRID (boxes3), label, 0, 4, 1, 1);
3165 app->subtitle_encoding_entry = gtk_entry_new ();
3166 g_signal_connect (app->subtitle_encoding_entry, "activate",
3167 G_CALLBACK (subtitle_encoding_activate_cb), app);
3168 gtk_grid_attach (GTK_GRID (boxes3), app->subtitle_encoding_entry, 0, 5, 1,
3171 label = gtk_label_new ("Subtitle Fontdesc");
3172 gtk_grid_attach (GTK_GRID (boxes3), label, 1, 4, 1, 1);
3173 app->subtitle_fontdesc_button = gtk_font_button_new ();
3174 g_signal_connect (app->subtitle_fontdesc_button, "font-set",
3175 G_CALLBACK (subtitle_fontdesc_cb), app);
3176 gtk_grid_attach (GTK_GRID (boxes3), app->subtitle_fontdesc_button, 1, 5, 1,
3179 pb2vbox = gtk_vbox_new (FALSE, 0);
3180 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
3181 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
3182 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
3183 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes3, FALSE, FALSE, 2);
3184 gtk_container_add (GTK_CONTAINER (playbin), pb2vbox);
3189 /* do the packing stuff ... */
3190 gtk_window_set_default_size (GTK_WINDOW (app->window), 250, 96);
3191 /* FIXME: can we avoid this for audio only? */
3192 gtk_widget_set_size_request (GTK_WIDGET (app->video_window), -1,
3193 DEFAULT_VIDEO_HEIGHT);
3194 gtk_container_add (GTK_CONTAINER (app->window), vbox);
3195 gtk_box_pack_start (GTK_BOX (vbox), app->video_window, TRUE, TRUE, 2);
3196 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
3197 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
3198 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
3199 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
3201 gtk_box_pack_start (GTK_BOX (vbox), seek, FALSE, FALSE, 2);
3203 gtk_box_pack_start (GTK_BOX (vbox), playbin, FALSE, FALSE, 2);
3204 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
3205 gtk_box_pack_start (GTK_BOX (vbox), navigation, FALSE, FALSE, 2);
3206 gtk_box_pack_start (GTK_BOX (vbox), colorbalance, FALSE, FALSE, 2);
3207 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 2);
3208 gtk_box_pack_start (GTK_BOX (vbox), app->seek_scale, FALSE, FALSE, 2);
3209 gtk_box_pack_start (GTK_BOX (vbox), app->statusbar, FALSE, FALSE, 2);
3211 /* connect things ... */
3212 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
3214 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
3216 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
3219 g_signal_connect (G_OBJECT (app->window), "delete-event",
3220 G_CALLBACK (delete_event_cb), app);
3224 set_defaults (PlaybackApp * app)
3226 memset (app, 0, sizeof (PlaybackApp));
3228 app->flush_seek = TRUE;
3232 app->position = app->duration = -1;
3233 app->state = GST_STATE_NULL;
3235 app->need_streams = TRUE;
3237 g_mutex_init (&app->state_mutex);
3239 app->play_rate = 1.0;
3243 reset_app (PlaybackApp * app)
3245 g_free (app->audiosink_str);
3246 g_free (app->videosink_str);
3248 g_list_free (app->formats);
3250 g_mutex_clear (&app->state_mutex);
3252 if (app->overlay_element)
3253 gst_object_unref (app->overlay_element);
3254 if (app->navigation_element)
3255 gst_object_unref (app->navigation_element);
3257 g_list_foreach (app->paths, (GFunc) g_free, NULL);
3258 g_list_free (app->paths);
3259 g_list_foreach (app->sub_paths, (GFunc) g_free, NULL);
3260 g_list_free (app->sub_paths);
3262 g_print ("free pipeline\n");
3263 gst_object_unref (app->pipeline);
3267 main (int argc, char **argv)
3270 GOptionEntry options[] = {
3271 {"stats", 's', 0, G_OPTION_ARG_NONE, &app.stats,
3272 "Show pad stats", NULL},
3273 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &app.verbose,
3274 "Verbose properties", NULL},
3277 GOptionContext *ctx;
3280 set_defaults (&app);
3282 ctx = g_option_context_new ("- playback testing in gsteamer");
3283 g_option_context_add_main_entries (ctx, options, NULL);
3284 g_option_context_add_group (ctx, gst_init_get_option_group ());
3285 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
3287 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
3288 g_print ("Error initializing: %s\n", err->message);
3292 GST_DEBUG_CATEGORY_INIT (playback_debug, "playback-test", 0,
3293 "playback example");
3296 print_usage (argc, argv);
3300 app.pipeline_type = atoi (argv[1]);
3302 if (app.pipeline_type < 0 || app.pipeline_type >= G_N_ELEMENTS (pipelines)) {
3303 print_usage (argc, argv);
3307 app.pipeline_spec = argv[2];
3309 if (g_path_is_absolute (app.pipeline_spec) &&
3310 (g_strrstr (app.pipeline_spec, "*") != NULL ||
3311 g_strrstr (app.pipeline_spec, "?") != NULL)) {
3312 app.paths = handle_wildcards (app.pipeline_spec);
3314 app.paths = g_list_prepend (app.paths, g_strdup (app.pipeline_spec));
3318 g_print ("opening %s failed\n", app.pipeline_spec);
3322 app.current_path = app.paths;
3324 if (argc > 3 && argv[3]) {
3325 if (g_path_is_absolute (argv[3]) &&
3326 (g_strrstr (argv[3], "*") != NULL ||
3327 g_strrstr (argv[3], "?") != NULL)) {
3328 app.sub_paths = handle_wildcards (argv[3]);
3330 app.sub_paths = g_list_prepend (app.sub_paths, g_strdup (argv[3]));
3333 if (!app.sub_paths) {
3334 g_print ("opening %s failed\n", argv[3]);
3338 app.current_sub_path = app.sub_paths;
3341 pipelines[app.pipeline_type].func (&app, app.current_path->data);
3342 g_assert (app.pipeline);
3347 gtk_widget_show_all (app.window);
3349 /* realize window now so that the video window gets created and we can
3350 * obtain its XID before the pipeline is started up and the videosink
3351 * asks for the XID of the window to render onto */
3352 gtk_widget_realize (app.window);
3354 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
3355 /* we should have the XID now */
3356 g_assert (app.embed_xid != 0);
3358 if (app.pipeline_type == 0) {
3359 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (app.pipeline),
3365 g_signal_connect (app.pipeline, "deep_notify",
3366 G_CALLBACK (gst_object_default_deep_notify), NULL);
3369 connect_bus_signals (&app);
3373 g_print ("NULL pipeline\n");
3374 gst_element_set_state (app.pipeline, GST_STATE_NULL);