3 * seek.c: seeking sample application
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * 2006 Stefan Kost <ensonic@users.sf.net>
8 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
29 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
30 * with newer GTK versions (>= 3.3.0) */
31 #define GDK_DISABLE_DEPRECATION_WARNINGS
32 #define GLIB_DISABLE_DEPRECATION_WARNINGS
42 #if defined (GDK_WINDOWING_X11)
44 #elif defined (GDK_WINDOWING_WIN32)
45 #include <gdk/gdkwin32.h>
46 #elif defined (GDK_WINDOWING_QUARTZ)
47 #include <gdk/gdkquartzwindow.h>
50 #include <gst/interfaces/xoverlay.h>
51 #include <gst/interfaces/navigation.h>
52 #include <gst/interfaces/colorbalance.h>
54 GST_DEBUG_CATEGORY_STATIC (seek_debug);
55 #define GST_CAT_DEFAULT (seek_debug)
57 /* Copied from gst-plugins-base/gst/playback/gstplay-enum.h */
60 GST_PLAY_FLAG_VIDEO = (1 << 0),
61 GST_PLAY_FLAG_AUDIO = (1 << 1),
62 GST_PLAY_FLAG_TEXT = (1 << 2),
63 GST_PLAY_FLAG_VIS = (1 << 3),
64 GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4),
65 GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5),
66 GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6),
67 GST_PLAY_FLAG_DOWNLOAD = (1 << 7),
68 GST_PLAY_FLAG_BUFFERING = (1 << 8),
69 GST_PLAY_FLAG_DEINTERLACE = (1 << 9),
70 GST_PLAY_FLAG_SOFT_COLORBALANCE = (1 << 10)
75 #define FILL_INTERVAL 100
76 //#define UPDATE_INTERVAL 500
77 //#define UPDATE_INTERVAL 100
78 #define UPDATE_INTERVAL 40
80 /* number of milliseconds to play for after a seek */
81 #define SCRUB_TIME 100
83 /* timeout for gst_element_get_state() after a seek */
84 #define SEEK_TIMEOUT 40 * GST_MSECOND
86 #define DEFAULT_VIDEO_HEIGHT 300
88 /* the state to go to when stop is pressed */
89 #define STOP_STATE GST_STATE_READY
93 /* we keep an array of the visualisation entries so that we can easily switch
94 * with the combo box index. */
97 GstElementFactory *factory;
104 GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo;
105 GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox;
106 GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton;
107 GtkWidget *video_window;
109 GtkWidget *seek_scale, *statusbar;
112 GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton;
113 GtkWidget *shuttle_scale;
115 GtkWidget *contrast_scale, *brightness_scale, *hue_scale, *saturation_scale;
119 GstNavigationCommand cmd;
121 } navigation_buttons[14];
125 /* GStreamer pipeline */
126 GstElement *pipeline;
128 GstElement *navigation_element;
129 GstElement *colorbalance_element;
130 GstElement *xoverlay_element;
133 gboolean accurate_seek;
134 gboolean keyframe_seek;
142 /* From commandline parameters */
145 const gchar *pipeline_spec;
147 GList *paths, *current_path;
149 gchar *audiosink_str, *videosink_str;
152 gint64 position, duration;
156 GstBufferingMode mode;
157 gint64 buffering_left;
160 guint seek_timeout_id;
164 gboolean need_streams;
165 gint n_video, n_audio, n_text;
167 GStaticMutex state_mutex;
169 GArray *vis_entries; /* Array of VisEntry structs */
172 gdouble shuttle_rate;
176 static void clear_streams (SeekApp * app);
177 static void find_interface_elements (SeekApp * app);
178 static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg,
180 static void mute_notify_cb (GstElement * pipeline, GParamSpec * arg,
183 /* pipeline construction */
187 gst_element_factory_make_or_warn (const gchar * type, const gchar * name)
189 GstElement *element = gst_element_factory_make (type, name);
191 #ifndef GST_DISABLE_PARSE
193 /* Try parsing it as a pipeline description */
194 element = gst_parse_bin_from_description (type, TRUE, NULL);
196 gst_element_set_name (element, name);
202 g_warning ("Failed to create element %s of type %s", name, type);
210 playbin_set_uri (GstElement * playbin, const gchar * location)
214 /* Add "file://" prefix for convenience */
215 if (g_str_has_prefix (location, "/") || !gst_uri_is_valid (location)) {
216 uri = gst_filename_to_uri (location, NULL);
217 g_print ("Setting URI: %s\n", uri);
218 g_object_set (G_OBJECT (playbin), "uri", uri, NULL);
221 g_print ("Setting URI: %s\n", location);
222 g_object_set (G_OBJECT (playbin), "uri", location, NULL);
227 make_playbin2_pipeline (SeekApp * app, const gchar * location)
229 GstElement *pipeline;
231 app->pipeline = pipeline = gst_element_factory_make ("playbin2", "playbin2");
234 playbin_set_uri (pipeline, location);
236 g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb),
238 g_signal_connect (pipeline, "notify::mute", G_CALLBACK (mute_notify_cb), app);
240 app->navigation_element = GST_ELEMENT (gst_object_ref (pipeline));
241 app->colorbalance_element = GST_ELEMENT (gst_object_ref (pipeline));
244 #ifndef GST_DISABLE_PARSE
246 make_parselaunch_pipeline (SeekApp * app, const gchar * description)
248 app->pipeline = gst_parse_launch (description, NULL);
255 void (*func) (SeekApp * app, const gchar * location);
259 static const Pipeline pipelines[] = {
260 {"playbin2", make_playbin2_pipeline},
261 #ifndef GST_DISABLE_PARSE
262 {"parse-launch", make_parselaunch_pipeline},
266 /* ui callbacks and helpers */
269 format_value (GtkScale * scale, gdouble value, SeekApp * app)
275 real = value * app->duration / N_GRAD;
276 seconds = (gint64) real / GST_SECOND;
277 subseconds = (gint64) real / (GST_SECOND / N_GRAD);
279 return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02"
280 G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100);
284 shuttle_format_value (GtkScale * scale, gdouble value)
286 return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value);
292 const GstFormat format;
296 static seek_format seek_formats[] = {
297 {"tim", GST_FORMAT_TIME},
298 {"byt", GST_FORMAT_BYTES},
299 {"buf", GST_FORMAT_BUFFERS},
300 {"def", GST_FORMAT_DEFAULT},
305 query_positions (SeekApp * app)
309 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (app->pipeline));
310 while (seek_formats[i].name) {
311 gint64 position, total;
314 format = seek_formats[i].format;
316 if (gst_element_query_position (app->pipeline, &format, &position) &&
317 gst_element_query_duration (app->pipeline, &format, &total)) {
318 g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ",
319 seek_formats[i].name, position, total);
321 g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*", "*NA*");
325 g_print (" %s\n", GST_ELEMENT_NAME (app->pipeline));
328 static gboolean start_seek (GtkRange * range, GdkEventButton * event,
330 static gboolean stop_seek (GtkRange * range, GdkEventButton * event,
332 static void seek_cb (GtkRange * range, SeekApp * app);
335 set_scale (SeekApp * app, gdouble value)
337 g_signal_handlers_block_by_func (app->seek_scale, start_seek, app);
338 g_signal_handlers_block_by_func (app->seek_scale, stop_seek, app);
339 g_signal_handlers_block_by_func (app->seek_scale, seek_cb, app);
340 gtk_range_set_value (GTK_RANGE (app->seek_scale), value);
341 g_signal_handlers_unblock_by_func (app->seek_scale, start_seek, app);
342 g_signal_handlers_unblock_by_func (app->seek_scale, stop_seek, app);
343 g_signal_handlers_unblock_by_func (app->seek_scale, seek_cb, app);
344 gtk_widget_queue_draw (app->seek_scale);
348 update_fill (SeekApp * app)
352 query = gst_query_new_buffering (GST_FORMAT_PERCENT);
353 if (gst_element_query (app->pipeline, query)) {
354 gint64 start, stop, buffering_total;
359 GstBufferingMode mode;
360 gint avg_in, avg_out;
361 gint64 buffering_left;
363 gst_query_parse_buffering_percent (query, &busy, &percent);
364 gst_query_parse_buffering_range (query, &format, &start, &stop,
366 gst_query_parse_buffering_stats (query, &mode, &avg_in, &avg_out,
369 /* note that we could start the playback when buffering_left < remaining
371 GST_DEBUG ("buffering total %" G_GINT64_FORMAT " ms, left %"
372 G_GINT64_FORMAT " ms", buffering_total, buffering_left);
373 GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT,
377 fill = N_GRAD * stop / GST_FORMAT_PERCENT_MAX;
381 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), fill);
383 gst_query_unref (query);
389 update_scale (SeekApp * app)
391 GstFormat format = GST_FORMAT_TIME;
396 gst_element_query_position (app->pipeline, &format, &app->position);
397 gst_element_query_duration (app->pipeline, &format, &app->duration);
400 query_positions (app);
402 if (app->position >= app->duration)
403 app->duration = app->position;
405 if (app->duration > 0) {
406 set_scale (app, app->position * N_GRAD / app->duration);
412 static void set_update_scale (SeekApp * app, gboolean active);
413 static void set_update_fill (SeekApp * app, gboolean active);
416 end_scrub (SeekApp * app)
418 GST_DEBUG ("end scrub, PAUSE");
419 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
420 app->seek_timeout_id = 0;
426 send_event (SeekApp * app, GstEvent * event)
428 gboolean res = FALSE;
430 GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (app->pipeline));
431 res = gst_element_send_event (app->pipeline, event);
437 do_seek (SeekApp * app)
440 gboolean res = FALSE;
445 gtk_range_get_value (GTK_RANGE (app->seek_scale)) * app->duration /
448 GST_DEBUG ("value=%f, real=%" G_GINT64_FORMAT,
449 gtk_range_get_value (GTK_RANGE (app->seek_scale)), real);
453 flags |= GST_SEEK_FLAG_FLUSH;
454 if (app->accurate_seek)
455 flags |= GST_SEEK_FLAG_ACCURATE;
456 if (app->keyframe_seek)
457 flags |= GST_SEEK_FLAG_KEY_UNIT;
459 flags |= GST_SEEK_FLAG_SEGMENT;
461 flags |= GST_SEEK_FLAG_SKIP;
463 if (app->rate >= 0) {
464 s_event = gst_event_new_seek (app->rate,
465 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET,
466 GST_CLOCK_TIME_NONE);
467 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
468 app->rate, GST_TIME_ARGS (real), GST_TIME_ARGS (app->duration));
470 s_event = gst_event_new_seek (app->rate,
471 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
472 GST_SEEK_TYPE_SET, real);
473 GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT,
474 app->rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real));
477 res = send_event (app, s_event);
480 if (app->flush_seek) {
481 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
484 set_update_scale (app, TRUE);
487 g_print ("seek failed\n");
488 set_update_scale (app, TRUE);
493 seek_cb (GtkRange * range, SeekApp * app)
495 /* If the timer hasn't expired yet, then the pipeline is running */
496 if (app->play_scrub && app->seek_timeout_id != 0) {
497 GST_DEBUG ("do scrub seek, PAUSED");
498 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
501 GST_DEBUG ("do seek");
504 if (app->play_scrub) {
505 GST_DEBUG ("do scrub seek, PLAYING");
506 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
508 if (app->seek_timeout_id == 0) {
509 app->seek_timeout_id =
510 g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, app);
516 set_update_fill (SeekApp * app, gboolean active)
518 GST_DEBUG ("fill scale is %d", active);
521 if (app->fill_id == 0) {
523 g_timeout_add (FILL_INTERVAL, (GSourceFunc) update_fill, app);
527 g_source_remove (app->fill_id);
534 set_update_scale (SeekApp * app, gboolean active)
536 GST_DEBUG ("update scale is %d", active);
539 if (app->update_id == 0) {
541 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, app);
544 if (app->update_id) {
545 g_source_remove (app->update_id);
552 start_seek (GtkRange * range, GdkEventButton * event, SeekApp * app)
554 if (event->type != GDK_BUTTON_PRESS)
557 set_update_scale (app, FALSE);
559 if (app->state == GST_STATE_PLAYING && app->flush_seek && app->scrub) {
560 GST_DEBUG ("start scrub seek, PAUSE");
561 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
564 if (app->changed_id == 0 && app->flush_seek && app->scrub) {
566 g_signal_connect (app->seek_scale, "value-changed",
567 G_CALLBACK (seek_cb), app);
574 stop_seek (GtkRange * range, GdkEventButton * event, SeekApp * app)
576 if (app->changed_id) {
577 g_signal_handler_disconnect (app->seek_scale, app->changed_id);
581 if (!app->flush_seek || !app->scrub) {
582 GST_DEBUG ("do final seek");
586 if (app->seek_timeout_id != 0) {
587 g_source_remove (app->seek_timeout_id);
588 app->seek_timeout_id = 0;
589 /* Still scrubbing, so the pipeline is playing, see if we need PAUSED
591 if (app->state == GST_STATE_PAUSED) {
592 GST_DEBUG ("stop scrub seek, PAUSED");
593 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
596 if (app->state == GST_STATE_PLAYING) {
597 GST_DEBUG ("stop scrub seek, PLAYING");
598 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
606 play_cb (GtkButton * button, SeekApp * app)
608 GstStateChangeReturn ret;
610 if (app->state != GST_STATE_PLAYING) {
611 g_print ("PLAY pipeline\n");
612 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
614 ret = gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
616 case GST_STATE_CHANGE_FAILURE:
618 case GST_STATE_CHANGE_NO_PREROLL:
624 app->state = GST_STATE_PLAYING;
625 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
633 g_print ("PLAY failed\n");
634 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
640 pause_cb (GtkButton * button, SeekApp * app)
642 g_static_mutex_lock (&app->state_mutex);
643 if (app->state != GST_STATE_PAUSED) {
644 GstStateChangeReturn ret;
646 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
647 g_print ("PAUSE pipeline\n");
648 ret = gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
650 case GST_STATE_CHANGE_FAILURE:
652 case GST_STATE_CHANGE_NO_PREROLL:
659 app->state = GST_STATE_PAUSED;
660 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
663 g_static_mutex_unlock (&app->state_mutex);
669 g_static_mutex_unlock (&app->state_mutex);
670 g_print ("PAUSE failed\n");
671 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
677 stop_cb (GtkButton * button, SeekApp * app)
679 if (app->state != STOP_STATE) {
680 GstStateChangeReturn ret;
683 g_print ("READY pipeline\n");
684 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
686 g_static_mutex_lock (&app->state_mutex);
687 ret = gst_element_set_state (app->pipeline, STOP_STATE);
688 if (ret == GST_STATE_CHANGE_FAILURE)
691 app->state = STOP_STATE;
692 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
694 gtk_widget_queue_draw (app->video_window);
696 app->is_live = FALSE;
697 app->buffering = FALSE;
698 set_update_scale (app, FALSE);
699 set_scale (app, 0.0);
700 set_update_fill (app, FALSE);
702 if (app->pipeline_type == 0)
704 g_static_mutex_unlock (&app->state_mutex);
706 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), TRUE);
707 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++)
708 gtk_widget_set_sensitive (app->navigation_buttons[i].button, FALSE);
714 g_static_mutex_unlock (&app->state_mutex);
715 g_print ("STOP failed\n");
716 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
722 accurate_toggle_cb (GtkToggleButton * button, SeekApp * app)
724 app->accurate_seek = gtk_toggle_button_get_active (button);
728 key_toggle_cb (GtkToggleButton * button, SeekApp * app)
730 app->keyframe_seek = gtk_toggle_button_get_active (button);
734 loop_toggle_cb (GtkToggleButton * button, SeekApp * app)
736 app->loop_seek = gtk_toggle_button_get_active (button);
737 if (app->state == GST_STATE_PLAYING) {
743 flush_toggle_cb (GtkToggleButton * button, SeekApp * app)
745 app->flush_seek = gtk_toggle_button_get_active (button);
749 scrub_toggle_cb (GtkToggleButton * button, SeekApp * app)
751 app->scrub = gtk_toggle_button_get_active (button);
755 play_scrub_toggle_cb (GtkToggleButton * button, SeekApp * app)
757 app->play_scrub = gtk_toggle_button_get_active (button);
761 skip_toggle_cb (GtkToggleButton * button, SeekApp * app)
763 app->skip_seek = gtk_toggle_button_get_active (button);
764 if (app->state == GST_STATE_PLAYING) {
770 rate_spinbutton_changed_cb (GtkSpinButton * button, SeekApp * app)
772 gboolean res = FALSE;
776 app->rate = gtk_spin_button_get_value (button);
778 GST_DEBUG ("rate changed to %lf", app->rate);
782 flags |= GST_SEEK_FLAG_FLUSH;
784 flags |= GST_SEEK_FLAG_SEGMENT;
785 if (app->accurate_seek)
786 flags |= GST_SEEK_FLAG_ACCURATE;
787 if (app->keyframe_seek)
788 flags |= GST_SEEK_FLAG_KEY_UNIT;
790 flags |= GST_SEEK_FLAG_SKIP;
792 if (app->rate >= 0.0) {
793 s_event = gst_event_new_seek (app->rate,
794 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
795 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
797 s_event = gst_event_new_seek (app->rate,
798 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
799 GST_SEEK_TYPE_SET, app->position);
802 res = send_event (app, s_event);
805 if (app->flush_seek) {
806 gst_element_get_state (GST_ELEMENT (app->pipeline), NULL, NULL,
810 g_print ("seek failed\n");
814 update_flag (GstElement * pipeline, GstPlayFlags flag, gboolean state)
818 g_print ("%ssetting flag 0x%08x\n", (state ? "" : "un"), flag);
820 g_object_get (pipeline, "flags", &flags, NULL);
825 g_object_set (pipeline, "flags", flags, NULL);
829 vis_toggle_cb (GtkToggleButton * button, SeekApp * app)
833 state = gtk_toggle_button_get_active (button);
834 update_flag (app->pipeline, GST_PLAY_FLAG_VIS, state);
835 gtk_widget_set_sensitive (app->vis_combo, state);
839 audio_toggle_cb (GtkToggleButton * button, SeekApp * app)
843 state = gtk_toggle_button_get_active (button);
844 update_flag (app->pipeline, GST_PLAY_FLAG_AUDIO, state);
845 gtk_widget_set_sensitive (app->audio_combo, state);
849 video_toggle_cb (GtkToggleButton * button, SeekApp * app)
853 state = gtk_toggle_button_get_active (button);
854 update_flag (app->pipeline, GST_PLAY_FLAG_VIDEO, state);
855 gtk_widget_set_sensitive (app->video_combo, state);
859 text_toggle_cb (GtkToggleButton * button, SeekApp * app)
863 state = gtk_toggle_button_get_active (button);
864 update_flag (app->pipeline, GST_PLAY_FLAG_TEXT, state);
865 gtk_widget_set_sensitive (app->text_combo, state);
869 mute_toggle_cb (GtkToggleButton * button, SeekApp * app)
873 mute = gtk_toggle_button_get_active (button);
874 g_object_set (app->pipeline, "mute", mute, NULL);
878 download_toggle_cb (GtkToggleButton * button, SeekApp * app)
882 state = gtk_toggle_button_get_active (button);
883 update_flag (app->pipeline, GST_PLAY_FLAG_DOWNLOAD, state);
887 buffering_toggle_cb (GtkToggleButton * button, SeekApp * app)
891 state = gtk_toggle_button_get_active (button);
892 update_flag (app->pipeline, GST_PLAY_FLAG_BUFFERING, state);
896 soft_volume_toggle_cb (GtkToggleButton * button, SeekApp * app)
900 state = gtk_toggle_button_get_active (button);
901 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_VOLUME, state);
905 native_audio_toggle_cb (GtkToggleButton * button, SeekApp * app)
909 state = gtk_toggle_button_get_active (button);
910 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_AUDIO, state);
914 native_video_toggle_cb (GtkToggleButton * button, SeekApp * app)
918 state = gtk_toggle_button_get_active (button);
919 update_flag (app->pipeline, GST_PLAY_FLAG_NATIVE_VIDEO, state);
923 deinterlace_toggle_cb (GtkToggleButton * button, SeekApp * app)
927 state = gtk_toggle_button_get_active (button);
928 update_flag (app->pipeline, GST_PLAY_FLAG_DEINTERLACE, state);
932 soft_colorbalance_toggle_cb (GtkToggleButton * button, SeekApp * app)
936 state = gtk_toggle_button_get_active (button);
937 update_flag (app->pipeline, GST_PLAY_FLAG_SOFT_COLORBALANCE, state);
941 clear_streams (SeekApp * app)
945 /* remove previous info */
946 for (i = 0; i < app->n_video; i++)
947 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->video_combo), 0);
948 for (i = 0; i < app->n_audio; i++)
949 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->audio_combo), 0);
950 for (i = 0; i < app->n_text; i++)
951 gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT (app->text_combo), 0);
953 app->n_audio = app->n_video = app->n_text = 0;
954 gtk_widget_set_sensitive (app->video_combo, FALSE);
955 gtk_widget_set_sensitive (app->audio_combo, FALSE);
956 gtk_widget_set_sensitive (app->text_combo, FALSE);
958 app->need_streams = TRUE;
962 update_streams (SeekApp * app)
966 if (app->pipeline_type == 0 && app->need_streams) {
972 /* remove previous info */
975 /* here we get and update the different streams detected by playbin2 */
976 g_object_get (app->pipeline, "n-video", &app->n_video, NULL);
977 g_object_get (app->pipeline, "n-audio", &app->n_audio, NULL);
978 g_object_get (app->pipeline, "n-text", &app->n_text, NULL);
980 g_print ("video %d, audio %d, text %d\n", app->n_video, app->n_audio,
984 for (i = 0; i < app->n_video; i++) {
985 g_signal_emit_by_name (app->pipeline, "get-video-tags", i, &tags);
987 str = gst_structure_to_string ((GstStructure *) tags);
988 g_print ("video %d: %s\n", i, str);
991 /* find good name for the label */
992 name = g_strdup_printf ("video %d", i + 1);
993 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->video_combo),
998 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->video_checkbox));
999 gtk_widget_set_sensitive (app->video_combo, state && app->n_video > 0);
1000 gtk_combo_box_set_active (GTK_COMBO_BOX (app->video_combo), active_idx);
1003 for (i = 0; i < app->n_audio; i++) {
1004 g_signal_emit_by_name (app->pipeline, "get-audio-tags", i, &tags);
1006 str = gst_structure_to_string ((GstStructure *) tags);
1007 g_print ("audio %d: %s\n", i, str);
1010 /* find good name for the label */
1011 name = g_strdup_printf ("audio %d", i + 1);
1012 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->audio_combo),
1017 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->audio_checkbox));
1018 gtk_widget_set_sensitive (app->audio_combo, state && app->n_audio > 0);
1019 gtk_combo_box_set_active (GTK_COMBO_BOX (app->audio_combo), active_idx);
1022 for (i = 0; i < app->n_text; i++) {
1023 g_signal_emit_by_name (app->pipeline, "get-text-tags", i, &tags);
1027 const GValue *value;
1029 str = gst_structure_to_string ((GstStructure *) tags);
1030 g_print ("text %d: %s\n", i, str);
1033 /* get the language code if we can */
1034 value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0);
1035 if (value && G_VALUE_HOLDS_STRING (value)) {
1036 name = g_strdup_printf ("text %s", g_value_get_string (value));
1039 /* find good name for the label if we didn't use a tag */
1041 name = g_strdup_printf ("text %d", i + 1);
1043 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->text_combo),
1048 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->text_checkbox));
1049 gtk_widget_set_sensitive (app->text_combo, state && app->n_text > 0);
1050 gtk_combo_box_set_active (GTK_COMBO_BOX (app->text_combo), active_idx);
1052 app->need_streams = FALSE;
1057 video_combo_cb (GtkComboBox * combo, SeekApp * app)
1061 active = gtk_combo_box_get_active (combo);
1063 g_print ("setting current video track %d\n", active);
1064 g_object_set (app->pipeline, "current-video", active, NULL);
1068 audio_combo_cb (GtkComboBox * combo, SeekApp * app)
1072 active = gtk_combo_box_get_active (combo);
1074 g_print ("setting current audio track %d\n", active);
1075 g_object_set (app->pipeline, "current-audio", active, NULL);
1079 text_combo_cb (GtkComboBox * combo, SeekApp * app)
1083 active = gtk_combo_box_get_active (combo);
1085 g_print ("setting current text track %d\n", active);
1086 g_object_set (app->pipeline, "current-text", active, NULL);
1090 filter_vis_features (GstPluginFeature * feature, gpointer data)
1092 GstElementFactory *f;
1094 if (!GST_IS_ELEMENT_FACTORY (feature))
1096 f = GST_ELEMENT_FACTORY (feature);
1097 if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization"))
1104 init_visualization_features (SeekApp * app)
1108 app->vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry));
1110 list = gst_registry_feature_filter (gst_registry_get_default (),
1111 filter_vis_features, FALSE, NULL);
1113 for (walk = list; walk; walk = g_list_next (walk)) {
1117 entry.factory = GST_ELEMENT_FACTORY (walk->data);
1118 name = gst_element_factory_get_longname (entry.factory);
1120 g_array_append_val (app->vis_entries, entry);
1121 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->vis_combo), name);
1123 gtk_combo_box_set_active (GTK_COMBO_BOX (app->vis_combo), 0);
1127 vis_combo_cb (GtkComboBox * combo, SeekApp * app)
1131 GstElement *element;
1133 /* get the selected index and get the factory for this index */
1134 index = gtk_combo_box_get_active (GTK_COMBO_BOX (app->vis_combo));
1135 if (app->vis_entries->len > 0) {
1136 entry = &g_array_index (app->vis_entries, VisEntry, index);
1138 /* create an instance of the element from the factory */
1139 element = gst_element_factory_create (entry->factory, NULL);
1143 /* set vis plugin for playbin2 */
1144 g_object_set (app->pipeline, "vis-plugin", element, NULL);
1149 volume_spinbutton_changed_cb (GtkSpinButton * button, SeekApp * app)
1153 volume = gtk_spin_button_get_value (button);
1155 g_object_set (app->pipeline, "volume", volume, NULL);
1159 volume_notify_idle_cb (SeekApp * app)
1161 gdouble cur_volume, new_volume;
1163 g_object_get (app->pipeline, "volume", &new_volume, NULL);
1165 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->volume_spinbutton));
1166 if (fabs (cur_volume - new_volume) > 0.001) {
1167 g_signal_handlers_block_by_func (app->volume_spinbutton,
1168 volume_spinbutton_changed_cb, app);
1169 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton),
1171 g_signal_handlers_unblock_by_func (app->volume_spinbutton,
1172 volume_spinbutton_changed_cb, app);
1179 volume_notify_cb (GstElement * pipeline, GParamSpec * arg, SeekApp * app)
1181 /* Do this from the main thread */
1182 g_idle_add ((GSourceFunc) volume_notify_idle_cb, app);
1186 mute_notify_idle_cb (SeekApp * app)
1188 gboolean cur_mute, new_mute;
1190 g_object_get (app->pipeline, "mute", &new_mute, NULL);
1192 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (app->mute_checkbox));
1193 if (cur_mute != new_mute) {
1194 g_signal_handlers_block_by_func (app->mute_checkbox, mute_toggle_cb, app);
1195 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
1197 g_signal_handlers_unblock_by_func (app->mute_checkbox, mute_toggle_cb, app);
1204 mute_notify_cb (GstElement * pipeline, GParamSpec * arg, SeekApp * app)
1206 /* Do this from the main thread */
1207 g_idle_add ((GSourceFunc) mute_notify_idle_cb, app);
1211 shot_cb (GtkButton * button, SeekApp * app)
1216 /* convert to our desired format (RGB24) */
1217 caps = gst_caps_new_simple ("video/x-raw-rgb",
1218 "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24,
1219 /* Note: we don't ask for a specific width/height here, so that
1220 * videoscale can adjust dimensions from a non-1/1 pixel aspect
1221 * ratio to a 1/1 pixel-aspect-ratio */
1222 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
1223 "endianness", G_TYPE_INT, G_BIG_ENDIAN,
1224 "red_mask", G_TYPE_INT, 0xff0000,
1225 "green_mask", G_TYPE_INT, 0x00ff00,
1226 "blue_mask", G_TYPE_INT, 0x0000ff, NULL);
1228 /* convert the latest frame to the requested format */
1229 g_signal_emit_by_name (app->pipeline, "convert-frame", caps, &buffer);
1230 gst_caps_unref (caps);
1238 GError *error = NULL;
1240 /* get the snapshot buffer format now. We set the caps on the appsink so
1241 * that it can only be an rgb buffer. The only thing we have not specified
1242 * on the caps is the height, which is dependant on the pixel-aspect-ratio
1243 * of the source material */
1244 caps = GST_BUFFER_CAPS (buffer);
1246 g_warning ("could not get snapshot format\n");
1249 s = gst_caps_get_structure (caps, 0);
1251 /* we need to get the final caps on the buffer to get the size */
1252 res = gst_structure_get_int (s, "width", &width);
1253 res |= gst_structure_get_int (s, "height", &height);
1255 g_warning ("could not get snapshot dimension\n");
1259 /* create pixmap from buffer and save, gstreamer video buffers have a stride
1260 * that is rounded up to the nearest multiple of 4 */
1261 pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer),
1262 GDK_COLORSPACE_RGB, FALSE, 8, width, height,
1263 GST_ROUND_UP_4 (width * 3), NULL, NULL);
1265 /* save the pixbuf */
1266 gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
1269 gst_buffer_unref (buffer);
1273 /* called when the Step button is pressed */
1275 step_cb (GtkButton * button, SeekApp * app)
1281 gboolean flush, res;
1284 active = gtk_combo_box_get_active (GTK_COMBO_BOX (app->format_combo));
1286 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
1287 (app->step_amount_spinbutton));
1289 gtk_spin_button_get_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton));
1294 format = GST_FORMAT_BUFFERS;
1297 format = GST_FORMAT_TIME;
1298 amount *= GST_MSECOND;
1301 format = GST_FORMAT_UNDEFINED;
1305 event = gst_event_new_step (format, amount, rate, flush, FALSE);
1307 res = send_event (app, event);
1310 g_print ("Sending step event failed\n");
1315 message_received (GstBus * bus, GstMessage * message, SeekApp * app)
1317 const GstStructure *s;
1319 switch (GST_MESSAGE_TYPE (message)) {
1320 case GST_MESSAGE_ERROR:
1321 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1322 GST_DEBUG_GRAPH_SHOW_ALL, "seek.error");
1324 case GST_MESSAGE_WARNING:
1325 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1326 GST_DEBUG_GRAPH_SHOW_ALL, "seek.warning");
1332 s = gst_message_get_structure (message);
1333 g_print ("message from \"%s\" (%s): ",
1334 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
1335 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
1339 sstr = gst_structure_to_string (s);
1340 g_print ("%s\n", sstr);
1343 g_print ("no message details\n");
1348 do_shuttle (SeekApp * app)
1353 duration = 40 * GST_MSECOND;
1357 gst_element_send_event (app->pipeline,
1358 gst_event_new_step (GST_FORMAT_TIME, duration, app->shuttle_rate, FALSE,
1363 msg_sync_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
1369 gboolean intermediate;
1373 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
1374 &intermediate, &duration, &eos);
1377 g_print ("stepped till EOS\n");
1381 if (g_static_mutex_trylock (&app->state_mutex)) {
1384 g_static_mutex_unlock (&app->state_mutex);
1386 /* ignore step messages that come while we are doing a state change */
1387 g_print ("state change is busy\n");
1392 shuttle_toggled (GtkToggleButton * button, SeekApp * app)
1396 active = gtk_toggle_button_get_active (button);
1398 if (active != app->shuttling) {
1399 app->shuttling = active;
1400 g_print ("shuttling %s\n", app->shuttling ? "active" : "inactive");
1402 app->shuttle_rate = 0.0;
1403 app->play_rate = 1.0;
1404 pause_cb (NULL, app);
1405 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1411 shuttle_rate_switch (SeekApp * app)
1417 if (app->state == GST_STATE_PLAYING) {
1418 /* pause when we need to */
1419 pause_cb (NULL, app);
1420 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1423 if (app->play_rate == 1.0)
1424 app->play_rate = -1.0;
1426 app->play_rate = 1.0;
1428 g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", app->play_rate,
1429 GST_TIME_ARGS (app->position));
1431 flags = GST_SEEK_FLAG_FLUSH;
1432 flags |= GST_SEEK_FLAG_ACCURATE;
1434 if (app->play_rate >= 0.0) {
1435 s_event = gst_event_new_seek (app->play_rate,
1436 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, app->position,
1437 GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);
1439 s_event = gst_event_new_seek (app->play_rate,
1440 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1441 GST_SEEK_TYPE_SET, app->position);
1443 res = send_event (app, s_event);
1445 gst_element_get_state (app->pipeline, NULL, NULL, SEEK_TIMEOUT);
1447 g_print ("seek failed\n");
1452 shuttle_value_changed (GtkRange * range, SeekApp * app)
1456 rate = gtk_range_get_value (range);
1459 g_print ("rate 0.0, pause\n");
1460 pause_cb (NULL, app);
1461 gst_element_get_state (app->pipeline, NULL, NULL, -1);
1463 g_print ("rate changed %0.3g\n", rate);
1465 if ((rate < 0.0 && app->play_rate > 0.0) || (rate > 0.0
1466 && app->play_rate < 0.0)) {
1467 shuttle_rate_switch (app);
1470 app->shuttle_rate = ABS (rate);
1471 if (app->state != GST_STATE_PLAYING) {
1473 play_cb (NULL, app);
1479 colorbalance_value_changed (GtkRange * range, SeekApp * app)
1484 GstColorBalanceChannel *channel = NULL;
1485 const GList *channels, *l;
1487 if (range == GTK_RANGE (app->contrast_scale))
1489 else if (range == GTK_RANGE (app->brightness_scale))
1490 label = "BRIGHTNESS";
1491 else if (range == GTK_RANGE (app->hue_scale))
1493 else if (range == GTK_RANGE (app->saturation_scale))
1494 label = "SATURATION";
1496 g_assert_not_reached ();
1498 val = gtk_range_get_value (range);
1500 g_print ("colorbalance %s value changed %lf\n", label, val / N_GRAD);
1502 if (!app->colorbalance_element) {
1503 find_interface_elements (app);
1504 if (!app->colorbalance_element)
1509 gst_color_balance_list_channels (GST_COLOR_BALANCE
1510 (app->colorbalance_element));
1511 for (l = channels; l; l = l->next) {
1512 GstColorBalanceChannel *tmp = l->data;
1514 if (g_strrstr (tmp->label, label)) {
1524 (gint) (0.5 + channel->min_value +
1525 (val / N_GRAD) * ((gdouble) channel->max_value -
1526 (gdouble) channel->min_value));
1527 gst_color_balance_set_value (GST_COLOR_BALANCE (app->colorbalance_element),
1532 msg_async_done (GstBus * bus, GstMessage * message, SeekApp * app)
1534 GST_DEBUG ("async done");
1535 /* when we get ASYNC_DONE we can query position, duration and other
1539 /* update the available streams */
1540 update_streams (app);
1542 find_interface_elements (app);
1546 msg_state_changed (GstBus * bus, GstMessage * message, SeekApp * app)
1548 const GstStructure *s;
1550 s = gst_message_get_structure (message);
1552 /* We only care about state changed on the pipeline */
1553 if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (app->pipeline)) {
1554 GstState old, new, pending;
1556 gst_message_parse_state_changed (message, &old, &new, &pending);
1558 /* When state of the pipeline changes to paused or playing we start updating scale */
1559 if (new == GST_STATE_PLAYING) {
1560 set_update_scale (app, TRUE);
1562 set_update_scale (app, FALSE);
1565 /* dump graph for (some) pipeline state changes */
1569 dump_name = g_strdup_printf ("seek.%s_%s",
1570 gst_element_state_get_name (old), gst_element_state_get_name (new));
1572 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (app->pipeline),
1573 GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
1581 msg_segment_done (GstBus * bus, GstMessage * message, SeekApp * app)
1588 GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (app->position));
1589 gst_message_parse_segment_done (message, &format, &app->position);
1590 GST_DEBUG ("end of segment at %" GST_TIME_FORMAT,
1591 GST_TIME_ARGS (app->position));
1594 /* in the segment-done callback we never flush as this would not make sense
1595 * for seamless playback. */
1597 flags |= GST_SEEK_FLAG_SEGMENT;
1599 flags |= GST_SEEK_FLAG_SKIP;
1601 s_event = gst_event_new_seek (app->rate,
1602 GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0),
1603 GST_SEEK_TYPE_SET, app->duration);
1605 GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT,
1606 app->rate, GST_TIME_ARGS (app->duration));
1608 res = send_event (app, s_event);
1610 g_print ("segment seek failed\n");
1613 /* in stream buffering mode we PAUSE the pipeline until we receive a 100%
1616 do_stream_buffering (SeekApp * app, gint percent)
1620 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1621 bufstr = g_strdup_printf ("Buffering...%d", percent);
1622 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1625 if (percent == 100) {
1626 /* a 100% message means buffering is done */
1627 app->buffering = FALSE;
1628 /* if the desired state is playing, go back */
1629 if (app->state == GST_STATE_PLAYING) {
1630 /* no state management needed for live pipelines */
1631 if (!app->is_live) {
1632 fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n");
1633 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1635 gtk_statusbar_pop (GTK_STATUSBAR (app->statusbar), app->status_id);
1636 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
1640 /* buffering busy */
1641 if (app->buffering == FALSE && app->state == GST_STATE_PLAYING) {
1642 /* we were not buffering but PLAYING, PAUSE the pipeline. */
1643 if (!app->is_live) {
1644 fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n");
1645 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1648 app->buffering = TRUE;
1653 do_download_buffering (SeekApp * app, gint percent)
1655 if (!app->buffering && percent < 100) {
1658 app->buffering = TRUE;
1660 bufstr = g_strdup_printf ("Downloading...");
1661 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id, bufstr);
1664 /* once we get a buffering message, we'll do the fill update */
1665 set_update_fill (app, TRUE);
1667 if (app->state == GST_STATE_PLAYING && !app->is_live) {
1668 fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n");
1669 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1670 /* user has to manually start the playback */
1671 app->state = GST_STATE_PAUSED;
1677 msg_buffering (GstBus * bus, GstMessage * message, SeekApp * app)
1681 gst_message_parse_buffering (message, &percent);
1683 /* get more stats */
1684 gst_message_parse_buffering_stats (message, &app->mode, NULL, NULL,
1685 &app->buffering_left);
1687 switch (app->mode) {
1688 case GST_BUFFERING_DOWNLOAD:
1689 do_download_buffering (app, percent);
1691 case GST_BUFFERING_LIVE:
1692 app->is_live = TRUE;
1693 case GST_BUFFERING_TIMESHIFT:
1694 case GST_BUFFERING_STREAM:
1695 do_stream_buffering (app, percent);
1701 msg_clock_lost (GstBus * bus, GstMessage * message, SeekApp * app)
1703 g_print ("clock lost! PAUSE and PLAY to select a new clock\n");
1704 if (app->state == GST_STATE_PLAYING) {
1705 gst_element_set_state (app->pipeline, GST_STATE_PAUSED);
1706 gst_element_set_state (app->pipeline, GST_STATE_PLAYING);
1711 is_valid_color_balance_element (GstElement * element)
1713 GstColorBalance *bal = GST_COLOR_BALANCE (element);
1714 gboolean have_brightness = FALSE;
1715 gboolean have_contrast = FALSE;
1716 gboolean have_hue = FALSE;
1717 gboolean have_saturation = FALSE;
1718 const GList *channels, *l;
1720 channels = gst_color_balance_list_channels (bal);
1721 for (l = channels; l; l = l->next) {
1722 GstColorBalanceChannel *ch = l->data;
1724 if (g_strrstr (ch->label, "BRIGHTNESS"))
1725 have_brightness = TRUE;
1726 else if (g_strrstr (ch->label, "CONTRAST"))
1727 have_contrast = TRUE;
1728 else if (g_strrstr (ch->label, "HUE"))
1730 else if (g_strrstr (ch->label, "SATURATION"))
1731 have_saturation = TRUE;
1734 return have_brightness && have_contrast && have_hue && have_saturation;
1738 find_interface_elements (SeekApp * app)
1742 gboolean done = FALSE, hardware = FALSE;
1744 if (app->pipeline_type == 0)
1747 if (app->navigation_element)
1748 gst_object_unref (app->navigation_element);
1749 app->navigation_element = NULL;
1751 if (app->colorbalance_element)
1752 gst_object_unref (app->colorbalance_element);
1753 app->colorbalance_element = NULL;
1755 app->navigation_element =
1756 gst_bin_get_by_interface (GST_BIN (app->pipeline), GST_TYPE_NAVIGATION);
1758 it = gst_bin_iterate_all_by_interface (GST_BIN (app->pipeline),
1759 GST_TYPE_COLOR_BALANCE);
1761 switch (gst_iterator_next (it, &item)) {
1762 case GST_ITERATOR_OK:{
1763 GstElement *element = GST_ELEMENT (item);
1765 if (is_valid_color_balance_element (element)) {
1766 if (!app->colorbalance_element) {
1767 app->colorbalance_element =
1768 GST_ELEMENT_CAST (gst_object_ref (element));
1770 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1771 (element)) == GST_COLOR_BALANCE_HARDWARE);
1772 } else if (!hardware) {
1774 (gst_color_balance_get_balance_type (GST_COLOR_BALANCE
1775 (element)) == GST_COLOR_BALANCE_HARDWARE);
1778 if (app->colorbalance_element)
1779 gst_object_unref (app->colorbalance_element);
1780 app->colorbalance_element =
1781 GST_ELEMENT_CAST (gst_object_ref (element));
1787 gst_object_unref (element);
1789 if (hardware && app->colorbalance_element)
1793 case GST_ITERATOR_RESYNC:
1794 gst_iterator_resync (it);
1797 if (app->colorbalance_element)
1798 gst_object_unref (app->colorbalance_element);
1799 app->colorbalance_element = NULL;
1801 case GST_ITERATOR_DONE:
1802 case GST_ITERATOR_ERROR:
1808 gst_iterator_free (it);
1811 /* called when Navigation command button is pressed */
1813 navigation_cmd_cb (GtkButton * button, SeekApp * app)
1815 GstNavigationCommand cmd = GST_NAVIGATION_COMMAND_INVALID;
1818 if (!app->navigation_element) {
1819 find_interface_elements (app);
1820 if (!app->navigation_element)
1824 for (i = 0; i < G_N_ELEMENTS (app->navigation_buttons); i++) {
1825 if (app->navigation_buttons[i].button == GTK_WIDGET (button)) {
1826 cmd = app->navigation_buttons[i].cmd;
1831 if (cmd != GST_NAVIGATION_COMMAND_INVALID)
1832 gst_navigation_send_command (GST_NAVIGATION (app->navigation_element), cmd);
1835 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
1836 /* We set the xid here in response to the prepare-xwindow-id message via a
1837 * bus sync handler because we don't know the actual videosink used from the
1838 * start (as we don't know the pipeline, or bin elements such as autovideosink
1839 * or gconfvideosink may be used which create the actual videosink only once
1840 * the pipeline is started) */
1841 static GstBusSyncReply
1842 bus_sync_handler (GstBus * bus, GstMessage * message, SeekApp * app)
1844 if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) &&
1845 gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
1846 GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
1848 if (app->xoverlay_element)
1849 gst_object_unref (app->xoverlay_element);
1850 app->xoverlay_element = GST_ELEMENT (gst_object_ref (element));
1852 g_print ("got prepare-xwindow-id, setting XID %" G_GUINTPTR_FORMAT "\n",
1855 if (g_object_class_find_property (G_OBJECT_GET_CLASS (element),
1856 "force-aspect-ratio")) {
1857 g_object_set (element, "force-aspect-ratio", TRUE, NULL);
1860 /* Should have been initialised from main thread before (can't use
1861 * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will
1862 * be called from a streaming thread and GDK_WINDOW_XID maps to more than
1863 * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that
1864 * shouldn't be done from a non-GUI thread without explicit locking). */
1865 g_assert (app->embed_xid != 0);
1867 gst_x_overlay_set_window_handle (GST_X_OVERLAY (element), app->embed_xid);
1869 find_interface_elements (app);
1871 return GST_BUS_PASS;
1876 draw_cb (GtkWidget * widget, cairo_t * cr, SeekApp * app)
1878 if (app->state < GST_STATE_PAUSED) {
1881 width = gtk_widget_get_allocated_width (widget);
1882 height = gtk_widget_get_allocated_height (widget);
1883 cairo_set_source_rgb (cr, 0, 0, 0);
1884 cairo_rectangle (cr, 0, 0, width, height);
1889 if (app->xoverlay_element)
1890 gst_x_overlay_expose (GST_X_OVERLAY (app->xoverlay_element));
1896 realize_cb (GtkWidget * widget, SeekApp * app)
1898 GdkWindow *window = gtk_widget_get_window (widget);
1900 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
1902 if (!gdk_window_ensure_native (window))
1903 g_error ("Couldn't create native window needed for GstXOverlay!");
1905 #if defined (GDK_WINDOWING_WIN32)
1906 app->embed_xid = GDK_WINDOW_HWND (window);
1907 g_print ("Window realize: video window HWND = %lu\n", app->embed_xid);
1908 #elif defined (GDK_WINDOWING_QUARTZ)
1909 app->embed_xid = gdk_quartz_window_get_nsview (window);
1910 g_print ("Window realize: video window NSView = %p\n", app->embed_xid);
1911 #elif defined (GDK_WINDOWING_X11)
1912 app->embed_xid = GDK_WINDOW_XID (window);
1913 g_print ("Window realize: video window XID = %" G_GUINTPTR_FORMAT "\n",
1919 button_press_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
1921 gtk_widget_grab_focus (widget);
1923 if (app->navigation_element)
1924 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1925 "mouse-button-press", event->button, event->x, event->y);
1931 button_release_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
1933 if (app->navigation_element)
1934 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1935 "mouse-button-release", event->button, event->x, event->y);
1941 key_press_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
1943 if (app->navigation_element)
1944 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
1945 "key-press", gdk_keyval_name (event->keyval));
1951 key_release_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
1953 if (app->navigation_element)
1954 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
1955 "key-release", gdk_keyval_name (event->keyval));
1961 motion_notify_cb (GtkWidget * widget, GdkEventMotion * event, SeekApp * app)
1963 if (app->navigation_element)
1964 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1965 "mouse-move", 0, event->x, event->y);
1971 msg_eos (GstBus * bus, GstMessage * message, SeekApp * app)
1973 message_received (bus, message, app);
1975 /* Set new uri for playerbins and continue playback */
1976 if (app->current_path && app->pipeline_type == 0) {
1977 stop_cb (NULL, app);
1978 app->current_path = g_list_next (app->current_path);
1979 if (app->current_path) {
1980 playbin_set_uri (app->pipeline, app->current_path->data);
1981 play_cb (NULL, app);
1987 msg_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
1989 if (!app->shuttling)
1990 message_received (bus, message, app);
1994 msg (GstBus * bus, GstMessage * message, SeekApp * app)
1996 GstNavigationMessageType nav_type;
1998 nav_type = gst_navigation_message_get_type (message);
2000 case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
2004 /* Heuristic to detect if we're dealing with a DVD menu */
2005 query = gst_navigation_query_new_commands ();
2006 res = gst_element_query (GST_ELEMENT (GST_MESSAGE_SRC (message)), query);
2008 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++)
2009 gtk_widget_set_sensitive (app->navigation_buttons[j].button, FALSE);
2012 gboolean is_menu = FALSE;
2015 if (gst_navigation_query_parse_commands_length (query, &n)) {
2016 for (i = 0; i < n; i++) {
2017 GstNavigationCommand cmd;
2019 if (!gst_navigation_query_parse_commands_nth (query, i, &cmd))
2022 is_menu |= (cmd == GST_NAVIGATION_COMMAND_ACTIVATE);
2023 is_menu |= (cmd == GST_NAVIGATION_COMMAND_LEFT);
2024 is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
2025 is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
2026 is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
2028 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++) {
2029 if (app->navigation_buttons[j].cmd != cmd)
2032 gtk_widget_set_sensitive (app->navigation_buttons[j].button,
2038 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), !is_menu);
2040 g_assert_not_reached ();
2043 gst_query_unref (query);
2044 message_received (bus, message, app);
2053 connect_bus_signals (SeekApp * app)
2055 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
2057 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2058 if (app->pipeline_type != 0) {
2059 /* handle prepare-xwindow-id element message synchronously, but only for non-playbin2 */
2060 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, app);
2064 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2065 gst_bus_enable_sync_message_emission (bus);
2067 g_signal_connect (bus, "message::state-changed",
2068 G_CALLBACK (msg_state_changed), app);
2069 g_signal_connect (bus, "message::segment-done", G_CALLBACK (msg_segment_done),
2071 g_signal_connect (bus, "message::async-done", G_CALLBACK (msg_async_done),
2074 g_signal_connect (bus, "message::new-clock", G_CALLBACK (message_received),
2076 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (msg_clock_lost),
2078 g_signal_connect (bus, "message::error", G_CALLBACK (message_received), app);
2079 g_signal_connect (bus, "message::warning", G_CALLBACK (message_received),
2081 g_signal_connect (bus, "message::eos", G_CALLBACK (msg_eos), app);
2082 g_signal_connect (bus, "message::tag", G_CALLBACK (message_received), app);
2083 g_signal_connect (bus, "message::element", G_CALLBACK (message_received),
2085 g_signal_connect (bus, "message::segment-done", G_CALLBACK (message_received),
2087 g_signal_connect (bus, "message::buffering", G_CALLBACK (msg_buffering), app);
2088 // g_signal_connect (bus, "message::step-done", G_CALLBACK (msg_step_done),
2090 g_signal_connect (bus, "message::step-start", G_CALLBACK (msg_step_done),
2092 g_signal_connect (bus, "sync-message::step-done",
2093 G_CALLBACK (msg_sync_step_done), app);
2094 g_signal_connect (bus, "message", G_CALLBACK (msg), app);
2096 gst_object_unref (bus);
2099 /* Return GList of paths described in location string */
2101 handle_wildcards (const gchar * location)
2104 gchar *path = g_path_get_dirname (location);
2105 gchar *pattern = g_path_get_basename (location);
2106 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2107 GDir *dir = g_dir_open (path, 0, NULL);
2110 g_print ("matching %s from %s\n", pattern, path);
2113 g_print ("opening directory %s failed\n", path);
2117 while ((name = g_dir_read_name (dir)) != NULL) {
2118 if (g_pattern_match_string (pspec, name)) {
2119 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2120 g_print (" found clip %s\n", name);
2126 g_pattern_spec_free (pspec);
2134 delete_event_cb (GtkWidget * widget, GdkEvent * event, SeekApp * app)
2136 stop_cb (NULL, app);
2141 print_usage (int argc, char **argv)
2145 g_print ("usage: %s <type> <filename>\n", argv[0]);
2146 g_print (" possible types:\n");
2148 for (i = 0; i < G_N_ELEMENTS (pipelines); i++) {
2149 g_print (" %d = %s\n", i, pipelines[i].name);
2154 create_ui (SeekApp * app)
2156 GtkWidget *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2157 *flagtable, *boxes2, *seek, *step, *navigation, *colorbalance = NULL;
2158 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2159 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2160 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2161 GtkWidget *rate_label, *volume_label;
2162 GtkWidget *skip_checkbox, *rate_spinbutton, *step_button, *shuttle_checkbox;
2163 GtkWidget *soft_volume_checkbox, *native_audio_checkbox,
2164 *native_video_checkbox;
2165 GtkWidget *download_checkbox, *buffering_checkbox, *deinterlace_checkbox;
2166 GtkWidget *soft_colorbalance_checkbox;
2167 GtkAdjustment *adjustment;
2169 /* initialize gui elements ... */
2170 app->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2171 app->video_window = gtk_drawing_area_new ();
2172 g_signal_connect (app->video_window, "draw", G_CALLBACK (draw_cb), app);
2173 g_signal_connect (app->video_window, "realize", G_CALLBACK (realize_cb), app);
2174 g_signal_connect (app->video_window, "button-press-event",
2175 G_CALLBACK (button_press_cb), app);
2176 g_signal_connect (app->video_window, "button-release-event",
2177 G_CALLBACK (button_release_cb), app);
2178 g_signal_connect (app->video_window, "key-press-event",
2179 G_CALLBACK (key_press_cb), app);
2180 g_signal_connect (app->video_window, "key-release-event",
2181 G_CALLBACK (key_release_cb), app);
2182 g_signal_connect (app->video_window, "motion-notify-event",
2183 G_CALLBACK (motion_notify_cb), app);
2184 gtk_widget_set_can_focus (app->video_window, TRUE);
2185 gtk_widget_set_double_buffered (app->video_window, FALSE);
2186 gtk_widget_add_events (app->video_window,
2187 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
2188 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2190 app->statusbar = gtk_statusbar_new ();
2192 gtk_statusbar_get_context_id (GTK_STATUSBAR (app->statusbar), "seek");
2193 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
2195 hbox = gtk_hbox_new (FALSE, 0);
2196 vbox = gtk_vbox_new (FALSE, 0);
2197 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2199 /* media controls */
2200 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2201 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2202 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2206 seek = gtk_expander_new ("seek options");
2207 flagtable = gtk_grid_new ();
2208 gtk_grid_set_row_spacing (GTK_GRID (flagtable), 2);
2209 gtk_grid_set_row_homogeneous (GTK_GRID (flagtable), TRUE);
2210 gtk_grid_set_column_spacing (GTK_GRID (flagtable), 2);
2211 gtk_grid_set_column_homogeneous (GTK_GRID (flagtable), TRUE);
2213 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2214 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2215 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2216 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2217 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2218 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2219 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2220 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2221 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2222 rate_label = gtk_label_new ("Rate");
2224 gtk_widget_set_tooltip_text (accurate_checkbox,
2225 "accurate position is requested, this might be considerably slower for some formats");
2226 gtk_widget_set_tooltip_text (key_checkbox,
2227 "seek to the nearest keyframe. This might be faster but less accurate");
2228 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2229 gtk_widget_set_tooltip_text (flush_checkbox,
2230 "flush pipeline after seeking");
2231 gtk_widget_set_tooltip_text (rate_spinbutton,
2232 "define the playback rate, " "negative value trigger reverse playback");
2233 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2234 gtk_widget_set_tooltip_text (play_scrub_checkbox,
2235 "play video while seeking");
2236 gtk_widget_set_tooltip_text (skip_checkbox,
2237 "Skip frames while playing at high frame rates");
2239 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2240 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2242 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), app->rate);
2244 gtk_grid_attach (GTK_GRID (flagtable), accurate_checkbox, 0, 0, 1, 1);
2245 gtk_grid_attach (GTK_GRID (flagtable), flush_checkbox, 1, 0, 1, 1);
2246 gtk_grid_attach (GTK_GRID (flagtable), loop_checkbox, 2, 0, 1, 1);
2247 gtk_grid_attach (GTK_GRID (flagtable), key_checkbox, 0, 1, 1, 1);
2248 gtk_grid_attach (GTK_GRID (flagtable), scrub_checkbox, 1, 1, 1, 1);
2249 gtk_grid_attach (GTK_GRID (flagtable), play_scrub_checkbox, 2, 1, 1, 1);
2250 gtk_grid_attach (GTK_GRID (flagtable), skip_checkbox, 3, 0, 1, 1);
2251 gtk_grid_attach (GTK_GRID (flagtable), rate_label, 4, 0, 1, 1);
2252 gtk_grid_attach (GTK_GRID (flagtable), rate_spinbutton, 4, 1, 1, 1);
2260 step = gtk_expander_new ("step options");
2261 hbox = gtk_hbox_new (FALSE, 0);
2263 app->format_combo = gtk_combo_box_text_new ();
2264 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->format_combo),
2266 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->format_combo),
2268 gtk_combo_box_set_active (GTK_COMBO_BOX (app->format_combo), 0);
2269 gtk_box_pack_start (GTK_BOX (hbox), app->format_combo, FALSE, FALSE, 2);
2271 app->step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2272 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2274 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2276 gtk_box_pack_start (GTK_BOX (hbox), app->step_amount_spinbutton, FALSE,
2279 app->step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2280 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_rate_spinbutton), 3);
2281 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton),
2283 gtk_box_pack_start (GTK_BOX (hbox), app->step_rate_spinbutton, FALSE, FALSE,
2286 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2287 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2288 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2290 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2294 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2295 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2296 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2297 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2301 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2302 app->shuttle_scale = gtk_hscale_new (adjustment);
2303 gtk_scale_set_digits (GTK_SCALE (app->shuttle_scale), 2);
2304 gtk_scale_set_value_pos (GTK_SCALE (app->shuttle_scale), GTK_POS_TOP);
2305 g_signal_connect (app->shuttle_scale, "value-changed",
2306 G_CALLBACK (shuttle_value_changed), app);
2307 g_signal_connect (app->shuttle_scale, "format_value",
2308 G_CALLBACK (shuttle_format_value), app);
2310 gtk_box_pack_start (GTK_BOX (hbox), app->shuttle_scale, TRUE, TRUE, 2);
2312 gtk_container_add (GTK_CONTAINER (seek), flagtable);
2315 /* navigation command expander */
2317 GtkWidget *navigation_button;
2321 navigation = gtk_expander_new ("navigation commands");
2322 grid = gtk_grid_new ();
2323 gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
2324 gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
2325 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2326 gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
2328 navigation_button = gtk_button_new_with_label ("Menu 1");
2329 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2330 G_CALLBACK (navigation_cmd_cb), app);
2331 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2332 gtk_widget_set_sensitive (navigation_button, FALSE);
2333 gtk_widget_set_tooltip_text (navigation_button, "DVD Menu");
2334 app->navigation_buttons[i].button = navigation_button;
2335 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU1;
2337 navigation_button = gtk_button_new_with_label ("Menu 2");
2338 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2339 G_CALLBACK (navigation_cmd_cb), app);
2340 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2341 gtk_widget_set_sensitive (navigation_button, FALSE);
2342 gtk_widget_set_tooltip_text (navigation_button, "DVD Title Menu");
2343 app->navigation_buttons[i].button = navigation_button;
2344 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU2;
2346 navigation_button = gtk_button_new_with_label ("Menu 3");
2347 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2348 G_CALLBACK (navigation_cmd_cb), app);
2349 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2350 gtk_widget_set_sensitive (navigation_button, FALSE);
2351 gtk_widget_set_tooltip_text (navigation_button, "DVD Root Menu");
2352 app->navigation_buttons[i].button = navigation_button;
2353 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU3;
2355 navigation_button = gtk_button_new_with_label ("Menu 4");
2356 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2357 G_CALLBACK (navigation_cmd_cb), app);
2358 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2359 gtk_widget_set_sensitive (navigation_button, FALSE);
2360 gtk_widget_set_tooltip_text (navigation_button, "DVD Subpicture Menu");
2361 app->navigation_buttons[i].button = navigation_button;
2362 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU4;
2364 navigation_button = gtk_button_new_with_label ("Menu 5");
2365 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2366 G_CALLBACK (navigation_cmd_cb), app);
2367 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2368 gtk_widget_set_sensitive (navigation_button, FALSE);
2369 gtk_widget_set_tooltip_text (navigation_button, "DVD Audio Menu");
2370 app->navigation_buttons[i].button = navigation_button;
2371 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU5;
2373 navigation_button = gtk_button_new_with_label ("Menu 6");
2374 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2375 G_CALLBACK (navigation_cmd_cb), app);
2376 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2377 gtk_widget_set_sensitive (navigation_button, FALSE);
2378 gtk_widget_set_tooltip_text (navigation_button, "DVD Angle Menu");
2379 app->navigation_buttons[i].button = navigation_button;
2380 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU6;
2382 navigation_button = gtk_button_new_with_label ("Menu 7");
2383 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2384 G_CALLBACK (navigation_cmd_cb), app);
2385 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2386 gtk_widget_set_sensitive (navigation_button, FALSE);
2387 gtk_widget_set_tooltip_text (navigation_button, "DVD Chapter Menu");
2388 app->navigation_buttons[i].button = navigation_button;
2389 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU7;
2391 navigation_button = gtk_button_new_with_label ("Left");
2392 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2393 G_CALLBACK (navigation_cmd_cb), app);
2394 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2395 gtk_widget_set_sensitive (navigation_button, FALSE);
2396 app->navigation_buttons[i].button = navigation_button;
2397 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_LEFT;
2399 navigation_button = gtk_button_new_with_label ("Right");
2400 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2401 G_CALLBACK (navigation_cmd_cb), app);
2402 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2403 gtk_widget_set_sensitive (navigation_button, FALSE);
2404 app->navigation_buttons[i].button = navigation_button;
2405 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_RIGHT;
2407 navigation_button = gtk_button_new_with_label ("Up");
2408 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2409 G_CALLBACK (navigation_cmd_cb), app);
2410 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2411 gtk_widget_set_sensitive (navigation_button, FALSE);
2412 app->navigation_buttons[i].button = navigation_button;
2413 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_UP;
2415 navigation_button = gtk_button_new_with_label ("Down");
2416 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2417 G_CALLBACK (navigation_cmd_cb), app);
2418 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2419 gtk_widget_set_sensitive (navigation_button, FALSE);
2420 app->navigation_buttons[i].button = navigation_button;
2421 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_DOWN;
2423 navigation_button = gtk_button_new_with_label ("Activate");
2424 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2425 G_CALLBACK (navigation_cmd_cb), app);
2426 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2427 gtk_widget_set_sensitive (navigation_button, FALSE);
2428 app->navigation_buttons[i].button = navigation_button;
2429 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_ACTIVATE;
2431 navigation_button = gtk_button_new_with_label ("Prev. Angle");
2432 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2433 G_CALLBACK (navigation_cmd_cb), app);
2434 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2435 gtk_widget_set_sensitive (navigation_button, FALSE);
2436 app->navigation_buttons[i].button = navigation_button;
2437 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_PREV_ANGLE;
2439 navigation_button = gtk_button_new_with_label ("Next. Angle");
2440 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2441 G_CALLBACK (navigation_cmd_cb), app);
2442 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2443 gtk_widget_set_sensitive (navigation_button, FALSE);
2444 app->navigation_buttons[i].button = navigation_button;
2445 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_NEXT_ANGLE;
2447 gtk_container_add (GTK_CONTAINER (navigation), grid);
2450 /* colorbalance expander */
2452 GtkWidget *vbox, *frame;
2454 colorbalance = gtk_expander_new ("color balance options");
2455 vbox = gtk_vbox_new (FALSE, 0);
2457 /* contrast scale */
2458 frame = gtk_frame_new ("Contrast");
2460 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2462 app->contrast_scale = gtk_hscale_new (adjustment);
2463 gtk_scale_set_draw_value (GTK_SCALE (app->contrast_scale), FALSE);
2464 g_signal_connect (app->contrast_scale, "value-changed",
2465 G_CALLBACK (colorbalance_value_changed), app);
2466 gtk_container_add (GTK_CONTAINER (frame), app->contrast_scale);
2467 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2469 /* brightness scale */
2470 frame = gtk_frame_new ("Brightness");
2472 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2474 app->brightness_scale = gtk_hscale_new (adjustment);
2475 gtk_scale_set_draw_value (GTK_SCALE (app->brightness_scale), FALSE);
2476 g_signal_connect (app->brightness_scale, "value-changed",
2477 G_CALLBACK (colorbalance_value_changed), app);
2478 gtk_container_add (GTK_CONTAINER (frame), app->brightness_scale);
2479 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2482 frame = gtk_frame_new ("Hue");
2484 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2486 app->hue_scale = gtk_hscale_new (adjustment);
2487 gtk_scale_set_draw_value (GTK_SCALE (app->hue_scale), FALSE);
2488 g_signal_connect (app->hue_scale, "value-changed",
2489 G_CALLBACK (colorbalance_value_changed), app);
2490 gtk_container_add (GTK_CONTAINER (frame), app->hue_scale);
2491 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2493 /* saturation scale */
2494 frame = gtk_frame_new ("Saturation");
2496 GTK_ADJUSTMENT (gtk_adjustment_new (N_GRAD / 2.0, 0.00, N_GRAD, 0.1,
2498 app->saturation_scale = gtk_hscale_new (adjustment);
2499 gtk_scale_set_draw_value (GTK_SCALE (app->saturation_scale), FALSE);
2500 g_signal_connect (app->saturation_scale, "value-changed",
2501 G_CALLBACK (colorbalance_value_changed), app);
2502 gtk_container_add (GTK_CONTAINER (frame), app->saturation_scale);
2503 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2505 gtk_container_add (GTK_CONTAINER (colorbalance), vbox);
2510 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2511 app->seek_scale = gtk_hscale_new (adjustment);
2512 gtk_scale_set_digits (GTK_SCALE (app->seek_scale), 2);
2513 gtk_scale_set_value_pos (GTK_SCALE (app->seek_scale), GTK_POS_RIGHT);
2514 gtk_range_set_show_fill_level (GTK_RANGE (app->seek_scale), TRUE);
2515 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), N_GRAD);
2517 g_signal_connect (app->seek_scale, "button_press_event",
2518 G_CALLBACK (start_seek), app);
2519 g_signal_connect (app->seek_scale, "button_release_event",
2520 G_CALLBACK (stop_seek), app);
2521 g_signal_connect (app->seek_scale, "format_value", G_CALLBACK (format_value),
2524 if (app->pipeline_type == 0) {
2525 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2526 panel = gtk_hbox_new (FALSE, 0);
2527 app->video_combo = gtk_combo_box_text_new ();
2528 app->audio_combo = gtk_combo_box_text_new ();
2529 app->text_combo = gtk_combo_box_text_new ();
2530 gtk_widget_set_sensitive (app->video_combo, FALSE);
2531 gtk_widget_set_sensitive (app->audio_combo, FALSE);
2532 gtk_widget_set_sensitive (app->text_combo, FALSE);
2533 gtk_box_pack_start (GTK_BOX (panel), app->video_combo, TRUE, TRUE, 2);
2534 gtk_box_pack_start (GTK_BOX (panel), app->audio_combo, TRUE, TRUE, 2);
2535 gtk_box_pack_start (GTK_BOX (panel), app->text_combo, TRUE, TRUE, 2);
2536 g_signal_connect (G_OBJECT (app->video_combo), "changed",
2537 G_CALLBACK (video_combo_cb), app);
2538 g_signal_connect (G_OBJECT (app->audio_combo), "changed",
2539 G_CALLBACK (audio_combo_cb), app);
2540 g_signal_connect (G_OBJECT (app->text_combo), "changed",
2541 G_CALLBACK (text_combo_cb), app);
2542 /* playbin2 panel for flag checkboxes and volume/mute */
2543 boxes = gtk_grid_new ();
2544 gtk_grid_set_row_spacing (GTK_GRID (boxes), 2);
2545 gtk_grid_set_row_homogeneous (GTK_GRID (boxes), TRUE);
2546 gtk_grid_set_column_spacing (GTK_GRID (boxes), 2);
2547 gtk_grid_set_column_homogeneous (GTK_GRID (boxes), TRUE);
2549 app->video_checkbox = gtk_check_button_new_with_label ("Video");
2550 app->audio_checkbox = gtk_check_button_new_with_label ("Audio");
2551 app->text_checkbox = gtk_check_button_new_with_label ("Text");
2552 app->vis_checkbox = gtk_check_button_new_with_label ("Vis");
2553 soft_volume_checkbox = gtk_check_button_new_with_label ("Soft Volume");
2554 native_audio_checkbox = gtk_check_button_new_with_label ("Native Audio");
2555 native_video_checkbox = gtk_check_button_new_with_label ("Native Video");
2556 download_checkbox = gtk_check_button_new_with_label ("Download");
2557 buffering_checkbox = gtk_check_button_new_with_label ("Buffering");
2558 deinterlace_checkbox = gtk_check_button_new_with_label ("Deinterlace");
2559 soft_colorbalance_checkbox =
2560 gtk_check_button_new_with_label ("Soft Colorbalance");
2561 app->mute_checkbox = gtk_check_button_new_with_label ("Mute");
2562 volume_label = gtk_label_new ("Volume");
2563 app->volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2564 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton), 1.0);
2565 gtk_grid_attach (GTK_GRID (boxes), app->video_checkbox, 0, 0, 1, 1);
2566 gtk_grid_attach (GTK_GRID (boxes), app->audio_checkbox, 1, 0, 1, 1);
2567 gtk_grid_attach (GTK_GRID (boxes), app->text_checkbox, 2, 0, 1, 1);
2568 gtk_grid_attach (GTK_GRID (boxes), app->vis_checkbox, 3, 0, 1, 1);
2569 gtk_grid_attach (GTK_GRID (boxes), soft_volume_checkbox, 4, 0, 1, 1);
2570 gtk_grid_attach (GTK_GRID (boxes), native_audio_checkbox, 5, 0, 1, 1);
2571 gtk_grid_attach (GTK_GRID (boxes), native_video_checkbox, 0, 1, 1, 1);
2572 gtk_grid_attach (GTK_GRID (boxes), download_checkbox, 1, 1, 1, 1);
2573 gtk_grid_attach (GTK_GRID (boxes), buffering_checkbox, 2, 1, 1, 1);
2574 gtk_grid_attach (GTK_GRID (boxes), deinterlace_checkbox, 3, 1, 1, 1);
2575 gtk_grid_attach (GTK_GRID (boxes), soft_colorbalance_checkbox, 4, 1, 1, 1);
2577 gtk_grid_attach (GTK_GRID (boxes), app->mute_checkbox, 7, 0, 2, 1);
2578 gtk_grid_attach (GTK_GRID (boxes), volume_label, 6, 1, 1, 1);
2579 gtk_grid_attach (GTK_GRID (boxes), app->volume_spinbutton, 7, 1, 1, 1);
2580 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->video_checkbox),
2582 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->audio_checkbox),
2584 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->text_checkbox), TRUE);
2585 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->vis_checkbox), FALSE);
2586 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (soft_volume_checkbox),
2588 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (native_audio_checkbox),
2590 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (native_video_checkbox),
2592 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2593 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffering_checkbox),
2595 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (deinterlace_checkbox),
2597 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
2598 (soft_colorbalance_checkbox), TRUE);
2599 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
2601 g_signal_connect (G_OBJECT (app->video_checkbox), "toggled",
2602 G_CALLBACK (video_toggle_cb), app);
2603 g_signal_connect (G_OBJECT (app->audio_checkbox), "toggled",
2604 G_CALLBACK (audio_toggle_cb), app);
2605 g_signal_connect (G_OBJECT (app->text_checkbox), "toggled",
2606 G_CALLBACK (text_toggle_cb), app);
2607 g_signal_connect (G_OBJECT (app->vis_checkbox), "toggled",
2608 G_CALLBACK (vis_toggle_cb), app);
2609 g_signal_connect (G_OBJECT (soft_volume_checkbox), "toggled",
2610 G_CALLBACK (soft_volume_toggle_cb), app);
2611 g_signal_connect (G_OBJECT (native_audio_checkbox), "toggled",
2612 G_CALLBACK (native_audio_toggle_cb), app);
2613 g_signal_connect (G_OBJECT (native_video_checkbox), "toggled",
2614 G_CALLBACK (native_video_toggle_cb), app);
2615 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2616 G_CALLBACK (download_toggle_cb), app);
2617 g_signal_connect (G_OBJECT (buffering_checkbox), "toggled",
2618 G_CALLBACK (buffering_toggle_cb), app);
2619 g_signal_connect (G_OBJECT (deinterlace_checkbox), "toggled",
2620 G_CALLBACK (deinterlace_toggle_cb), app);
2621 g_signal_connect (G_OBJECT (soft_colorbalance_checkbox), "toggled",
2622 G_CALLBACK (soft_colorbalance_toggle_cb), app);
2623 g_signal_connect (G_OBJECT (app->mute_checkbox), "toggled",
2624 G_CALLBACK (mute_toggle_cb), app);
2625 g_signal_connect (G_OBJECT (app->volume_spinbutton), "value-changed",
2626 G_CALLBACK (volume_spinbutton_changed_cb), app);
2627 /* playbin2 panel for snapshot */
2628 boxes2 = gtk_hbox_new (FALSE, 0);
2629 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2630 gtk_widget_set_tooltip_text (shot_button,
2631 "save a screenshot .png in the current directory");
2632 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2634 app->vis_combo = gtk_combo_box_text_new ();
2635 g_signal_connect (G_OBJECT (app->vis_combo), "changed",
2636 G_CALLBACK (vis_combo_cb), app);
2637 gtk_widget_set_sensitive (app->vis_combo, FALSE);
2638 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2639 gtk_box_pack_start (GTK_BOX (boxes2), app->vis_combo, TRUE, TRUE, 2);
2641 /* fill the vis combo box and the array of factories */
2642 init_visualization_features (app);
2644 panel = boxes = boxes2 = NULL;
2647 /* do the packing stuff ... */
2648 gtk_window_set_default_size (GTK_WINDOW (app->window), 250, 96);
2649 /* FIXME: can we avoid this for audio only? */
2650 gtk_widget_set_size_request (GTK_WIDGET (app->video_window), -1,
2651 DEFAULT_VIDEO_HEIGHT);
2652 gtk_container_add (GTK_CONTAINER (app->window), vbox);
2653 gtk_box_pack_start (GTK_BOX (vbox), app->video_window, TRUE, TRUE, 2);
2654 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2655 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2656 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2657 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2659 gtk_box_pack_start (GTK_BOX (vbox), seek, FALSE, FALSE, 2);
2660 if (panel && boxes && boxes2) {
2661 expander = gtk_expander_new ("playbin2 options");
2662 pb2vbox = gtk_vbox_new (FALSE, 0);
2663 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2664 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2665 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2666 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2667 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2669 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2670 gtk_box_pack_start (GTK_BOX (vbox), navigation, FALSE, FALSE, 2);
2671 gtk_box_pack_start (GTK_BOX (vbox), colorbalance, FALSE, FALSE, 2);
2672 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 2);
2673 gtk_box_pack_start (GTK_BOX (vbox), app->seek_scale, FALSE, FALSE, 2);
2674 gtk_box_pack_start (GTK_BOX (vbox), app->statusbar, FALSE, FALSE, 2);
2676 /* connect things ... */
2677 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2679 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2681 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2683 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2684 G_CALLBACK (accurate_toggle_cb), app);
2685 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2686 G_CALLBACK (key_toggle_cb), app);
2687 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2688 G_CALLBACK (loop_toggle_cb), app);
2689 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2690 G_CALLBACK (flush_toggle_cb), app);
2691 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2692 G_CALLBACK (scrub_toggle_cb), app);
2693 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2694 G_CALLBACK (play_scrub_toggle_cb), app);
2695 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2696 G_CALLBACK (skip_toggle_cb), app);
2697 g_signal_connect (G_OBJECT (rate_spinbutton), "value-changed",
2698 G_CALLBACK (rate_spinbutton_changed_cb), app);
2700 g_signal_connect (G_OBJECT (app->window), "delete-event",
2701 G_CALLBACK (delete_event_cb), app);
2705 set_defaults (SeekApp * app)
2707 memset (app, 0, sizeof (SeekApp));
2709 app->flush_seek = TRUE;
2713 app->position = app->duration = -1;
2714 app->state = GST_STATE_NULL;
2716 app->need_streams = TRUE;
2718 g_static_mutex_init (&app->state_mutex);
2720 app->play_rate = 1.0;
2724 reset_app (SeekApp * app)
2726 g_free (app->audiosink_str);
2727 g_free (app->videosink_str);
2729 g_static_mutex_free (&app->state_mutex);
2731 if (app->xoverlay_element)
2732 gst_object_unref (app->xoverlay_element);
2733 if (app->navigation_element)
2734 gst_object_unref (app->navigation_element);
2736 g_list_foreach (app->paths, (GFunc) g_free, NULL);
2737 g_list_free (app->paths);
2739 g_print ("free pipeline\n");
2740 gst_object_unref (app->pipeline);
2744 main (int argc, char **argv)
2747 GOptionEntry options[] = {
2748 {"stats", 's', 0, G_OPTION_ARG_NONE, &app.stats,
2749 "Show pad stats", NULL},
2750 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &app.verbose,
2751 "Verbose properties", NULL},
2754 GOptionContext *ctx;
2757 set_defaults (&app);
2759 #if !GLIB_CHECK_VERSION (2, 31, 0)
2760 if (!g_thread_supported ())
2761 g_thread_init (NULL);
2764 ctx = g_option_context_new ("- test seeking in gsteamer");
2765 g_option_context_add_main_entries (ctx, options, NULL);
2766 g_option_context_add_group (ctx, gst_init_get_option_group ());
2767 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2769 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2770 g_print ("Error initializing: %s\n", err->message);
2774 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2777 print_usage (argc, argv);
2781 app.pipeline_type = atoi (argv[1]);
2783 if (app.pipeline_type < 0 || app.pipeline_type >= G_N_ELEMENTS (pipelines)) {
2784 print_usage (argc, argv);
2788 app.pipeline_spec = argv[2];
2790 if (g_path_is_absolute (app.pipeline_spec) &&
2791 (g_strrstr (app.pipeline_spec, "*") != NULL ||
2792 g_strrstr (app.pipeline_spec, "?") != NULL)) {
2793 app.paths = handle_wildcards (app.pipeline_spec);
2795 app.paths = g_list_prepend (app.paths, g_strdup (app.pipeline_spec));
2799 g_print ("opening %s failed\n", app.pipeline_spec);
2803 app.current_path = app.paths;
2805 pipelines[app.pipeline_type].func (&app, app.current_path->data);
2806 g_assert (app.pipeline);
2811 gtk_widget_show_all (app.window);
2813 /* realize window now so that the video window gets created and we can
2814 * obtain its XID before the pipeline is started up and the videosink
2815 * asks for the XID of the window to render onto */
2816 gtk_widget_realize (app.window);
2818 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2819 /* we should have the XID now */
2820 g_assert (app.embed_xid != 0);
2822 if (app.pipeline_type == 0) {
2823 gst_x_overlay_set_window_handle (GST_X_OVERLAY (app.pipeline),
2829 g_signal_connect (app.pipeline, "deep_notify",
2830 G_CALLBACK (gst_object_default_deep_notify), NULL);
2833 connect_bus_signals (&app);
2837 g_print ("NULL pipeline\n");
2838 gst_element_set_state (app.pipeline, GST_STATE_NULL);