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 / 100.);
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 / 100.0) * ((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);
1868 gst_x_overlay_handle_events (GST_X_OVERLAY (element), FALSE);
1870 find_interface_elements (app);
1872 return GST_BUS_PASS;
1877 draw_cb (GtkWidget * widget, cairo_t * cr, SeekApp * app)
1879 if (app->state < GST_STATE_PAUSED) {
1882 width = gtk_widget_get_allocated_width (widget);
1883 height = gtk_widget_get_allocated_height (widget);
1884 cairo_set_source_rgb (cr, 0, 0, 0);
1885 cairo_rectangle (cr, 0, 0, width, height);
1890 if (app->xoverlay_element)
1891 gst_x_overlay_expose (GST_X_OVERLAY (app->xoverlay_element));
1897 realize_cb (GtkWidget * widget, SeekApp * app)
1899 GdkWindow *window = gtk_widget_get_window (widget);
1901 /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it
1903 if (!gdk_window_ensure_native (window))
1904 g_error ("Couldn't create native window needed for GstXOverlay!");
1906 #if defined (GDK_WINDOWING_WIN32)
1907 app->embed_xid = GDK_WINDOW_HWND (window);
1908 g_print ("Window realize: video window HWND = %lu\n", app->embed_xid);
1909 #elif defined (GDK_WINDOWING_QUARTZ)
1910 app->embed_xid = gdk_quartz_window_get_nsview (window);
1911 g_print ("Window realize: video window NSView = %p\n", app->embed_xid);
1912 #elif defined (GDK_WINDOWING_X11)
1913 app->embed_xid = GDK_WINDOW_XID (window);
1914 g_print ("Window realize: video window XID = %" G_GUINTPTR_FORMAT "\n",
1920 button_press_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
1922 gtk_widget_grab_focus (widget);
1924 if (app->navigation_element)
1925 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1926 "mouse-button-press", event->button, event->x, event->y);
1932 button_release_cb (GtkWidget * widget, GdkEventButton * event, SeekApp * app)
1934 if (app->navigation_element)
1935 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1936 "mouse-button-release", event->button, event->x, event->y);
1942 key_press_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
1944 if (app->navigation_element)
1945 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
1946 "key-press", gdk_keyval_name (event->keyval));
1952 key_release_cb (GtkWidget * widget, GdkEventKey * event, SeekApp * app)
1954 if (app->navigation_element)
1955 gst_navigation_send_key_event (GST_NAVIGATION (app->navigation_element),
1956 "key-release", gdk_keyval_name (event->keyval));
1962 motion_notify_cb (GtkWidget * widget, GdkEventMotion * event, SeekApp * app)
1964 if (app->navigation_element)
1965 gst_navigation_send_mouse_event (GST_NAVIGATION (app->navigation_element),
1966 "mouse-move", 0, event->x, event->y);
1972 msg_eos (GstBus * bus, GstMessage * message, SeekApp * app)
1974 message_received (bus, message, app);
1976 /* Set new uri for playerbins and continue playback */
1977 if (app->current_path && app->pipeline_type == 0) {
1978 stop_cb (NULL, app);
1979 app->current_path = g_list_next (app->current_path);
1980 if (app->current_path) {
1981 playbin_set_uri (app->pipeline, app->current_path->data);
1982 play_cb (NULL, app);
1988 msg_step_done (GstBus * bus, GstMessage * message, SeekApp * app)
1990 if (!app->shuttling)
1991 message_received (bus, message, app);
1995 msg (GstBus * bus, GstMessage * message, SeekApp * app)
1997 GstNavigationMessageType nav_type;
1999 nav_type = gst_navigation_message_get_type (message);
2001 case GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED:{
2005 /* Heuristic to detect if we're dealing with a DVD menu */
2006 query = gst_navigation_query_new_commands ();
2007 res = gst_element_query (GST_ELEMENT (GST_MESSAGE_SRC (message)), query);
2009 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++)
2010 gtk_widget_set_sensitive (app->navigation_buttons[j].button, FALSE);
2013 gboolean is_menu = FALSE;
2016 if (gst_navigation_query_parse_commands_length (query, &n)) {
2017 for (i = 0; i < n; i++) {
2018 GstNavigationCommand cmd;
2020 if (!gst_navigation_query_parse_commands_nth (query, i, &cmd))
2023 is_menu |= (cmd == GST_NAVIGATION_COMMAND_ACTIVATE);
2024 is_menu |= (cmd == GST_NAVIGATION_COMMAND_LEFT);
2025 is_menu |= (cmd == GST_NAVIGATION_COMMAND_RIGHT);
2026 is_menu |= (cmd == GST_NAVIGATION_COMMAND_UP);
2027 is_menu |= (cmd == GST_NAVIGATION_COMMAND_DOWN);
2029 for (j = 0; j < G_N_ELEMENTS (app->navigation_buttons); j++) {
2030 if (app->navigation_buttons[j].cmd != cmd)
2033 gtk_widget_set_sensitive (app->navigation_buttons[j].button,
2039 gtk_widget_set_sensitive (GTK_WIDGET (app->seek_scale), !is_menu);
2041 g_assert_not_reached ();
2044 gst_query_unref (query);
2045 message_received (bus, message, app);
2054 connect_bus_signals (SeekApp * app)
2056 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (app->pipeline));
2058 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2059 if (app->pipeline_type != 0) {
2060 /* handle prepare-xwindow-id element message synchronously, but only for non-playbin2 */
2061 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, app);
2065 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
2066 gst_bus_enable_sync_message_emission (bus);
2068 g_signal_connect (bus, "message::state-changed",
2069 G_CALLBACK (msg_state_changed), app);
2070 g_signal_connect (bus, "message::segment-done", G_CALLBACK (msg_segment_done),
2072 g_signal_connect (bus, "message::async-done", G_CALLBACK (msg_async_done),
2075 g_signal_connect (bus, "message::new-clock", G_CALLBACK (message_received),
2077 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (msg_clock_lost),
2079 g_signal_connect (bus, "message::error", G_CALLBACK (message_received), app);
2080 g_signal_connect (bus, "message::warning", G_CALLBACK (message_received),
2082 g_signal_connect (bus, "message::eos", G_CALLBACK (msg_eos), app);
2083 g_signal_connect (bus, "message::tag", G_CALLBACK (message_received), app);
2084 g_signal_connect (bus, "message::element", G_CALLBACK (message_received),
2086 g_signal_connect (bus, "message::segment-done", G_CALLBACK (message_received),
2088 g_signal_connect (bus, "message::buffering", G_CALLBACK (msg_buffering), app);
2089 // g_signal_connect (bus, "message::step-done", G_CALLBACK (msg_step_done),
2091 g_signal_connect (bus, "message::step-start", G_CALLBACK (msg_step_done),
2093 g_signal_connect (bus, "sync-message::step-done",
2094 G_CALLBACK (msg_sync_step_done), app);
2095 g_signal_connect (bus, "message", G_CALLBACK (msg), app);
2097 gst_object_unref (bus);
2100 /* Return GList of paths described in location string */
2102 handle_wildcards (const gchar * location)
2105 gchar *path = g_path_get_dirname (location);
2106 gchar *pattern = g_path_get_basename (location);
2107 GPatternSpec *pspec = g_pattern_spec_new (pattern);
2108 GDir *dir = g_dir_open (path, 0, NULL);
2111 g_print ("matching %s from %s\n", pattern, path);
2114 g_print ("opening directory %s failed\n", path);
2118 while ((name = g_dir_read_name (dir)) != NULL) {
2119 if (g_pattern_match_string (pspec, name)) {
2120 res = g_list_append (res, g_strjoin ("/", path, name, NULL));
2121 g_print (" found clip %s\n", name);
2127 g_pattern_spec_free (pspec);
2135 delete_event_cb (GtkWidget * widget, GdkEvent * event, SeekApp * app)
2137 stop_cb (NULL, app);
2142 print_usage (int argc, char **argv)
2146 g_print ("usage: %s <type> <filename>\n", argv[0]);
2147 g_print (" possible types:\n");
2149 for (i = 0; i < G_N_ELEMENTS (pipelines); i++) {
2150 g_print (" %d = %s\n", i, pipelines[i].name);
2155 create_ui (SeekApp * app)
2157 GtkWidget *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes,
2158 *flagtable, *boxes2, *step, *navigation, *colorbalance = NULL;
2159 GtkWidget *play_button, *pause_button, *stop_button, *shot_button;
2160 GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox;
2161 GtkWidget *scrub_checkbox, *play_scrub_checkbox;
2162 GtkWidget *rate_label, *volume_label;
2163 GtkWidget *skip_checkbox, *rate_spinbutton, *step_button, *shuttle_checkbox;
2164 GtkWidget *soft_volume_checkbox, *native_audio_checkbox,
2165 *native_video_checkbox;
2166 GtkWidget *download_checkbox, *buffering_checkbox, *deinterlace_checkbox;
2167 GtkWidget *soft_colorbalance_checkbox;
2168 GtkAdjustment *adjustment;
2170 /* initialize gui elements ... */
2171 app->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2172 app->video_window = gtk_drawing_area_new ();
2173 g_signal_connect (app->video_window, "draw", G_CALLBACK (draw_cb), app);
2174 g_signal_connect (app->video_window, "realize", G_CALLBACK (realize_cb), app);
2175 g_signal_connect (app->video_window, "button-press-event",
2176 G_CALLBACK (button_press_cb), app);
2177 g_signal_connect (app->video_window, "button-release-event",
2178 G_CALLBACK (button_release_cb), app);
2179 g_signal_connect (app->video_window, "key-press-event",
2180 G_CALLBACK (key_press_cb), app);
2181 g_signal_connect (app->video_window, "key-release-event",
2182 G_CALLBACK (key_release_cb), app);
2183 g_signal_connect (app->video_window, "motion-notify-event",
2184 G_CALLBACK (motion_notify_cb), app);
2185 gtk_widget_set_can_focus (app->video_window, TRUE);
2186 gtk_widget_set_double_buffered (app->video_window, FALSE);
2187 gtk_widget_add_events (app->video_window,
2188 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
2189 | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
2191 app->statusbar = gtk_statusbar_new ();
2193 gtk_statusbar_get_context_id (GTK_STATUSBAR (app->statusbar), "seek");
2194 gtk_statusbar_push (GTK_STATUSBAR (app->statusbar), app->status_id,
2196 hbox = gtk_hbox_new (FALSE, 0);
2197 vbox = gtk_vbox_new (FALSE, 0);
2198 flagtable = gtk_table_new (4, 2, FALSE);
2199 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
2201 /* media controls */
2202 play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY);
2203 pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE);
2204 stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP);
2207 accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek");
2208 key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek");
2209 loop_checkbox = gtk_check_button_new_with_label ("Loop");
2210 flush_checkbox = gtk_check_button_new_with_label ("Flush");
2211 scrub_checkbox = gtk_check_button_new_with_label ("Scrub");
2212 play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub");
2213 skip_checkbox = gtk_check_button_new_with_label ("Play Skip");
2214 rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1);
2215 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3);
2216 rate_label = gtk_label_new ("Rate");
2218 gtk_widget_set_tooltip_text (accurate_checkbox,
2219 "accurate position is requested, this might be considerably slower for some formats");
2220 gtk_widget_set_tooltip_text (key_checkbox,
2221 "seek to the nearest keyframe. This might be faster but less accurate");
2222 gtk_widget_set_tooltip_text (loop_checkbox, "loop playback");
2223 gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking");
2224 gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, "
2225 "negative value trigger reverse playback");
2226 gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking");
2227 gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking");
2228 gtk_widget_set_tooltip_text (skip_checkbox,
2229 "Skip frames while playing at high frame rates");
2231 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE);
2232 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE);
2234 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), app->rate);
2240 step = gtk_expander_new ("step options");
2241 hbox = gtk_hbox_new (FALSE, 0);
2243 app->format_combo = gtk_combo_box_text_new ();
2244 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->format_combo),
2246 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (app->format_combo),
2248 gtk_combo_box_set_active (GTK_COMBO_BOX (app->format_combo), 0);
2249 gtk_box_pack_start (GTK_BOX (hbox), app->format_combo, FALSE, FALSE, 2);
2251 app->step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1);
2252 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2254 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_amount_spinbutton),
2256 gtk_box_pack_start (GTK_BOX (hbox), app->step_amount_spinbutton, FALSE,
2259 app->step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1);
2260 gtk_spin_button_set_digits (GTK_SPIN_BUTTON (app->step_rate_spinbutton), 3);
2261 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->step_rate_spinbutton),
2263 gtk_box_pack_start (GTK_BOX (hbox), app->step_rate_spinbutton, FALSE, FALSE,
2266 step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD);
2267 gtk_button_set_label (GTK_BUTTON (step_button), "Step");
2268 gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2);
2270 g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb),
2274 shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle");
2275 gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2);
2276 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE);
2277 g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled),
2281 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0));
2282 app->shuttle_scale = gtk_hscale_new (adjustment);
2283 gtk_scale_set_digits (GTK_SCALE (app->shuttle_scale), 2);
2284 gtk_scale_set_value_pos (GTK_SCALE (app->shuttle_scale), GTK_POS_TOP);
2285 g_signal_connect (app->shuttle_scale, "value-changed",
2286 G_CALLBACK (shuttle_value_changed), app);
2287 g_signal_connect (app->shuttle_scale, "format_value",
2288 G_CALLBACK (shuttle_format_value), app);
2290 gtk_box_pack_start (GTK_BOX (hbox), app->shuttle_scale, TRUE, TRUE, 2);
2292 gtk_container_add (GTK_CONTAINER (step), hbox);
2295 /* navigation command expander */
2297 GtkWidget *navigation_button;
2301 navigation = gtk_expander_new ("navigation commands");
2302 grid = gtk_grid_new ();
2303 gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
2304 gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
2305 gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
2306 gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
2308 navigation_button = gtk_button_new_with_label ("Menu 1");
2309 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2310 G_CALLBACK (navigation_cmd_cb), app);
2311 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2312 gtk_widget_set_sensitive (navigation_button, FALSE);
2313 gtk_widget_set_tooltip_text (navigation_button, "DVD Menu");
2314 app->navigation_buttons[i].button = navigation_button;
2315 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU1;
2317 navigation_button = gtk_button_new_with_label ("Menu 2");
2318 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2319 G_CALLBACK (navigation_cmd_cb), app);
2320 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2321 gtk_widget_set_sensitive (navigation_button, FALSE);
2322 gtk_widget_set_tooltip_text (navigation_button, "DVD Title Menu");
2323 app->navigation_buttons[i].button = navigation_button;
2324 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU2;
2326 navigation_button = gtk_button_new_with_label ("Menu 3");
2327 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2328 G_CALLBACK (navigation_cmd_cb), app);
2329 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2330 gtk_widget_set_sensitive (navigation_button, FALSE);
2331 gtk_widget_set_tooltip_text (navigation_button, "DVD Root Menu");
2332 app->navigation_buttons[i].button = navigation_button;
2333 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU3;
2335 navigation_button = gtk_button_new_with_label ("Menu 4");
2336 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2337 G_CALLBACK (navigation_cmd_cb), app);
2338 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2339 gtk_widget_set_sensitive (navigation_button, FALSE);
2340 gtk_widget_set_tooltip_text (navigation_button, "DVD Subpicture Menu");
2341 app->navigation_buttons[i].button = navigation_button;
2342 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU4;
2344 navigation_button = gtk_button_new_with_label ("Menu 5");
2345 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2346 G_CALLBACK (navigation_cmd_cb), app);
2347 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2348 gtk_widget_set_sensitive (navigation_button, FALSE);
2349 gtk_widget_set_tooltip_text (navigation_button, "DVD Audio Menu");
2350 app->navigation_buttons[i].button = navigation_button;
2351 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU5;
2353 navigation_button = gtk_button_new_with_label ("Menu 6");
2354 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2355 G_CALLBACK (navigation_cmd_cb), app);
2356 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2357 gtk_widget_set_sensitive (navigation_button, FALSE);
2358 gtk_widget_set_tooltip_text (navigation_button, "DVD Angle Menu");
2359 app->navigation_buttons[i].button = navigation_button;
2360 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU6;
2362 navigation_button = gtk_button_new_with_label ("Menu 7");
2363 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2364 G_CALLBACK (navigation_cmd_cb), app);
2365 gtk_grid_attach (GTK_GRID (grid), navigation_button, i, 0, 1, 1);
2366 gtk_widget_set_sensitive (navigation_button, FALSE);
2367 gtk_widget_set_tooltip_text (navigation_button, "DVD Chapter Menu");
2368 app->navigation_buttons[i].button = navigation_button;
2369 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_MENU7;
2371 navigation_button = gtk_button_new_with_label ("Left");
2372 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2373 G_CALLBACK (navigation_cmd_cb), app);
2374 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2375 gtk_widget_set_sensitive (navigation_button, FALSE);
2376 app->navigation_buttons[i].button = navigation_button;
2377 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_LEFT;
2379 navigation_button = gtk_button_new_with_label ("Right");
2380 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2381 G_CALLBACK (navigation_cmd_cb), app);
2382 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2383 gtk_widget_set_sensitive (navigation_button, FALSE);
2384 app->navigation_buttons[i].button = navigation_button;
2385 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_RIGHT;
2387 navigation_button = gtk_button_new_with_label ("Up");
2388 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2389 G_CALLBACK (navigation_cmd_cb), app);
2390 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2391 gtk_widget_set_sensitive (navigation_button, FALSE);
2392 app->navigation_buttons[i].button = navigation_button;
2393 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_UP;
2395 navigation_button = gtk_button_new_with_label ("Down");
2396 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2397 G_CALLBACK (navigation_cmd_cb), app);
2398 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2399 gtk_widget_set_sensitive (navigation_button, FALSE);
2400 app->navigation_buttons[i].button = navigation_button;
2401 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_DOWN;
2403 navigation_button = gtk_button_new_with_label ("Activate");
2404 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2405 G_CALLBACK (navigation_cmd_cb), app);
2406 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2407 gtk_widget_set_sensitive (navigation_button, FALSE);
2408 app->navigation_buttons[i].button = navigation_button;
2409 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_ACTIVATE;
2411 navigation_button = gtk_button_new_with_label ("Prev. Angle");
2412 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2413 G_CALLBACK (navigation_cmd_cb), app);
2414 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2415 gtk_widget_set_sensitive (navigation_button, FALSE);
2416 app->navigation_buttons[i].button = navigation_button;
2417 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_PREV_ANGLE;
2419 navigation_button = gtk_button_new_with_label ("Next. Angle");
2420 g_signal_connect (G_OBJECT (navigation_button), "clicked",
2421 G_CALLBACK (navigation_cmd_cb), app);
2422 gtk_grid_attach (GTK_GRID (grid), navigation_button, i - 7, 1, 1, 1);
2423 gtk_widget_set_sensitive (navigation_button, FALSE);
2424 app->navigation_buttons[i].button = navigation_button;
2425 app->navigation_buttons[i++].cmd = GST_NAVIGATION_COMMAND_NEXT_ANGLE;
2427 gtk_container_add (GTK_CONTAINER (navigation), grid);
2430 /* colorbalance expander */
2432 GtkWidget *vbox, *frame;
2434 colorbalance = gtk_expander_new ("color balance options");
2435 vbox = gtk_vbox_new (FALSE, 0);
2437 /* contrast scale */
2438 frame = gtk_frame_new ("Contrast");
2440 GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 101.0, 1.0, 1.0, 1.0));
2441 app->contrast_scale = gtk_hscale_new (adjustment);
2442 gtk_scale_set_draw_value (GTK_SCALE (app->contrast_scale), FALSE);
2443 g_signal_connect (app->contrast_scale, "value-changed",
2444 G_CALLBACK (colorbalance_value_changed), app);
2445 gtk_container_add (GTK_CONTAINER (frame), app->contrast_scale);
2446 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2448 /* brightness scale */
2449 frame = gtk_frame_new ("Brightness");
2451 GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 101.0, 1.0, 1.0, 1.0));
2452 app->brightness_scale = gtk_hscale_new (adjustment);
2453 gtk_scale_set_draw_value (GTK_SCALE (app->brightness_scale), FALSE);
2454 g_signal_connect (app->brightness_scale, "value-changed",
2455 G_CALLBACK (colorbalance_value_changed), app);
2456 gtk_container_add (GTK_CONTAINER (frame), app->brightness_scale);
2457 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2460 frame = gtk_frame_new ("Hue");
2462 GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 101.0, 1.0, 1.0, 1.0));
2463 app->hue_scale = gtk_hscale_new (adjustment);
2464 gtk_scale_set_draw_value (GTK_SCALE (app->hue_scale), FALSE);
2465 g_signal_connect (app->hue_scale, "value-changed",
2466 G_CALLBACK (colorbalance_value_changed), app);
2467 gtk_container_add (GTK_CONTAINER (frame), app->hue_scale);
2468 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2470 /* saturation scale */
2471 frame = gtk_frame_new ("Saturation");
2473 GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 101.0, 1.0, 1.0, 1.0));
2474 app->saturation_scale = gtk_hscale_new (adjustment);
2475 gtk_scale_set_draw_value (GTK_SCALE (app->saturation_scale), FALSE);
2476 g_signal_connect (app->saturation_scale, "value-changed",
2477 G_CALLBACK (colorbalance_value_changed), app);
2478 gtk_container_add (GTK_CONTAINER (frame), app->saturation_scale);
2479 gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 2);
2481 gtk_container_add (GTK_CONTAINER (colorbalance), vbox);
2486 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, N_GRAD, 0.1, 1.0, 1.0));
2487 app->seek_scale = gtk_hscale_new (adjustment);
2488 gtk_scale_set_digits (GTK_SCALE (app->seek_scale), 2);
2489 gtk_scale_set_value_pos (GTK_SCALE (app->seek_scale), GTK_POS_RIGHT);
2490 gtk_range_set_show_fill_level (GTK_RANGE (app->seek_scale), TRUE);
2491 gtk_range_set_fill_level (GTK_RANGE (app->seek_scale), N_GRAD);
2493 g_signal_connect (app->seek_scale, "button_press_event",
2494 G_CALLBACK (start_seek), app);
2495 g_signal_connect (app->seek_scale, "button_release_event",
2496 G_CALLBACK (stop_seek), app);
2497 g_signal_connect (app->seek_scale, "format_value", G_CALLBACK (format_value),
2500 if (app->pipeline_type == 0) {
2501 /* the playbin2 panel controls for the video/audio/subtitle tracks */
2502 panel = gtk_hbox_new (FALSE, 0);
2503 app->video_combo = gtk_combo_box_text_new ();
2504 app->audio_combo = gtk_combo_box_text_new ();
2505 app->text_combo = gtk_combo_box_text_new ();
2506 gtk_widget_set_sensitive (app->video_combo, FALSE);
2507 gtk_widget_set_sensitive (app->audio_combo, FALSE);
2508 gtk_widget_set_sensitive (app->text_combo, FALSE);
2509 gtk_box_pack_start (GTK_BOX (panel), app->video_combo, TRUE, TRUE, 2);
2510 gtk_box_pack_start (GTK_BOX (panel), app->audio_combo, TRUE, TRUE, 2);
2511 gtk_box_pack_start (GTK_BOX (panel), app->text_combo, TRUE, TRUE, 2);
2512 g_signal_connect (G_OBJECT (app->video_combo), "changed",
2513 G_CALLBACK (video_combo_cb), app);
2514 g_signal_connect (G_OBJECT (app->audio_combo), "changed",
2515 G_CALLBACK (audio_combo_cb), app);
2516 g_signal_connect (G_OBJECT (app->text_combo), "changed",
2517 G_CALLBACK (text_combo_cb), app);
2518 /* playbin2 panel for flag checkboxes and volume/mute */
2519 boxes = gtk_grid_new ();
2520 gtk_grid_set_row_spacing (GTK_GRID (boxes), 2);
2521 gtk_grid_set_row_homogeneous (GTK_GRID (boxes), TRUE);
2522 gtk_grid_set_column_spacing (GTK_GRID (boxes), 2);
2523 gtk_grid_set_column_homogeneous (GTK_GRID (boxes), TRUE);
2525 app->video_checkbox = gtk_check_button_new_with_label ("Video");
2526 app->audio_checkbox = gtk_check_button_new_with_label ("Audio");
2527 app->text_checkbox = gtk_check_button_new_with_label ("Text");
2528 app->vis_checkbox = gtk_check_button_new_with_label ("Vis");
2529 soft_volume_checkbox = gtk_check_button_new_with_label ("Soft Volume");
2530 native_audio_checkbox = gtk_check_button_new_with_label ("Native Audio");
2531 native_video_checkbox = gtk_check_button_new_with_label ("Native Video");
2532 download_checkbox = gtk_check_button_new_with_label ("Download");
2533 buffering_checkbox = gtk_check_button_new_with_label ("Buffering");
2534 deinterlace_checkbox = gtk_check_button_new_with_label ("Deinterlace");
2535 soft_colorbalance_checkbox =
2536 gtk_check_button_new_with_label ("Soft Colorbalance");
2537 app->mute_checkbox = gtk_check_button_new_with_label ("Mute");
2538 volume_label = gtk_label_new ("Volume");
2539 app->volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1);
2540 gtk_spin_button_set_value (GTK_SPIN_BUTTON (app->volume_spinbutton), 1.0);
2541 gtk_grid_attach (GTK_GRID (boxes), app->video_checkbox, 0, 0, 1, 1);
2542 gtk_grid_attach (GTK_GRID (boxes), app->audio_checkbox, 1, 0, 1, 1);
2543 gtk_grid_attach (GTK_GRID (boxes), app->text_checkbox, 2, 0, 1, 1);
2544 gtk_grid_attach (GTK_GRID (boxes), app->vis_checkbox, 3, 0, 1, 1);
2545 gtk_grid_attach (GTK_GRID (boxes), soft_volume_checkbox, 4, 0, 1, 1);
2546 gtk_grid_attach (GTK_GRID (boxes), native_audio_checkbox, 5, 0, 1, 1);
2547 gtk_grid_attach (GTK_GRID (boxes), native_video_checkbox, 0, 1, 1, 1);
2548 gtk_grid_attach (GTK_GRID (boxes), download_checkbox, 1, 1, 1, 1);
2549 gtk_grid_attach (GTK_GRID (boxes), buffering_checkbox, 2, 1, 1, 1);
2550 gtk_grid_attach (GTK_GRID (boxes), deinterlace_checkbox, 3, 1, 1, 1);
2551 gtk_grid_attach (GTK_GRID (boxes), soft_colorbalance_checkbox, 4, 1, 1, 1);
2553 gtk_grid_attach (GTK_GRID (boxes), app->mute_checkbox, 7, 0, 2, 1);
2554 gtk_grid_attach (GTK_GRID (boxes), volume_label, 6, 1, 1, 1);
2555 gtk_grid_attach (GTK_GRID (boxes), app->volume_spinbutton, 7, 1, 1, 1);
2556 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->video_checkbox),
2558 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->audio_checkbox),
2560 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->text_checkbox), TRUE);
2561 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->vis_checkbox), FALSE);
2562 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (soft_volume_checkbox),
2564 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (native_audio_checkbox),
2566 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (native_video_checkbox),
2568 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE);
2569 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffering_checkbox),
2571 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (deinterlace_checkbox),
2573 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
2574 (soft_colorbalance_checkbox), TRUE);
2575 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (app->mute_checkbox),
2577 g_signal_connect (G_OBJECT (app->video_checkbox), "toggled",
2578 G_CALLBACK (video_toggle_cb), app);
2579 g_signal_connect (G_OBJECT (app->audio_checkbox), "toggled",
2580 G_CALLBACK (audio_toggle_cb), app);
2581 g_signal_connect (G_OBJECT (app->text_checkbox), "toggled",
2582 G_CALLBACK (text_toggle_cb), app);
2583 g_signal_connect (G_OBJECT (app->vis_checkbox), "toggled",
2584 G_CALLBACK (vis_toggle_cb), app);
2585 g_signal_connect (G_OBJECT (soft_volume_checkbox), "toggled",
2586 G_CALLBACK (soft_volume_toggle_cb), app);
2587 g_signal_connect (G_OBJECT (native_audio_checkbox), "toggled",
2588 G_CALLBACK (native_audio_toggle_cb), app);
2589 g_signal_connect (G_OBJECT (native_video_checkbox), "toggled",
2590 G_CALLBACK (native_video_toggle_cb), app);
2591 g_signal_connect (G_OBJECT (download_checkbox), "toggled",
2592 G_CALLBACK (download_toggle_cb), app);
2593 g_signal_connect (G_OBJECT (buffering_checkbox), "toggled",
2594 G_CALLBACK (buffering_toggle_cb), app);
2595 g_signal_connect (G_OBJECT (deinterlace_checkbox), "toggled",
2596 G_CALLBACK (deinterlace_toggle_cb), app);
2597 g_signal_connect (G_OBJECT (soft_colorbalance_checkbox), "toggled",
2598 G_CALLBACK (soft_colorbalance_toggle_cb), app);
2599 g_signal_connect (G_OBJECT (app->mute_checkbox), "toggled",
2600 G_CALLBACK (mute_toggle_cb), app);
2601 g_signal_connect (G_OBJECT (app->volume_spinbutton), "value-changed",
2602 G_CALLBACK (volume_spinbutton_changed_cb), app);
2603 /* playbin2 panel for snapshot */
2604 boxes2 = gtk_hbox_new (FALSE, 0);
2605 shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
2606 gtk_widget_set_tooltip_text (shot_button,
2607 "save a screenshot .png in the current directory");
2608 g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb),
2610 app->vis_combo = gtk_combo_box_text_new ();
2611 g_signal_connect (G_OBJECT (app->vis_combo), "changed",
2612 G_CALLBACK (vis_combo_cb), app);
2613 gtk_widget_set_sensitive (app->vis_combo, FALSE);
2614 gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2);
2615 gtk_box_pack_start (GTK_BOX (boxes2), app->vis_combo, TRUE, TRUE, 2);
2617 /* fill the vis combo box and the array of factories */
2618 init_visualization_features (app);
2620 panel = boxes = boxes2 = NULL;
2623 /* do the packing stuff ... */
2624 gtk_window_set_default_size (GTK_WINDOW (app->window), 250, 96);
2625 /* FIXME: can we avoid this for audio only? */
2626 gtk_widget_set_size_request (GTK_WIDGET (app->video_window), -1,
2627 DEFAULT_VIDEO_HEIGHT);
2628 gtk_container_add (GTK_CONTAINER (app->window), vbox);
2629 gtk_box_pack_start (GTK_BOX (vbox), app->video_window, TRUE, TRUE, 2);
2630 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
2631 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
2632 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
2633 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
2634 gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2);
2635 gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0,
2637 gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1);
2638 gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1);
2639 gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2);
2640 gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2);
2641 gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3,
2643 gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1);
2644 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1);
2645 gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1,
2647 if (panel && boxes && boxes2) {
2648 expander = gtk_expander_new ("playbin2 options");
2649 pb2vbox = gtk_vbox_new (FALSE, 0);
2650 gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2);
2651 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2);
2652 gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2);
2653 gtk_container_add (GTK_CONTAINER (expander), pb2vbox);
2654 gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2);
2656 gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2);
2657 gtk_box_pack_start (GTK_BOX (vbox), navigation, FALSE, FALSE, 2);
2658 gtk_box_pack_start (GTK_BOX (vbox), colorbalance, FALSE, FALSE, 2);
2659 gtk_box_pack_start (GTK_BOX (vbox), gtk_hseparator_new (), FALSE, FALSE, 2);
2660 gtk_box_pack_start (GTK_BOX (vbox), app->seek_scale, FALSE, FALSE, 2);
2661 gtk_box_pack_start (GTK_BOX (vbox), app->statusbar, FALSE, FALSE, 2);
2663 /* connect things ... */
2664 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
2666 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
2668 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
2670 g_signal_connect (G_OBJECT (accurate_checkbox), "toggled",
2671 G_CALLBACK (accurate_toggle_cb), app);
2672 g_signal_connect (G_OBJECT (key_checkbox), "toggled",
2673 G_CALLBACK (key_toggle_cb), app);
2674 g_signal_connect (G_OBJECT (loop_checkbox), "toggled",
2675 G_CALLBACK (loop_toggle_cb), app);
2676 g_signal_connect (G_OBJECT (flush_checkbox), "toggled",
2677 G_CALLBACK (flush_toggle_cb), app);
2678 g_signal_connect (G_OBJECT (scrub_checkbox), "toggled",
2679 G_CALLBACK (scrub_toggle_cb), app);
2680 g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled",
2681 G_CALLBACK (play_scrub_toggle_cb), app);
2682 g_signal_connect (G_OBJECT (skip_checkbox), "toggled",
2683 G_CALLBACK (skip_toggle_cb), app);
2684 g_signal_connect (G_OBJECT (rate_spinbutton), "value-changed",
2685 G_CALLBACK (rate_spinbutton_changed_cb), app);
2687 g_signal_connect (G_OBJECT (app->window), "delete-event",
2688 G_CALLBACK (delete_event_cb), app);
2692 set_defaults (SeekApp * app)
2694 memset (app, 0, sizeof (SeekApp));
2696 app->flush_seek = TRUE;
2700 app->position = app->duration = -1;
2701 app->state = GST_STATE_NULL;
2703 app->need_streams = TRUE;
2705 g_static_mutex_init (&app->state_mutex);
2707 app->play_rate = 1.0;
2711 reset_app (SeekApp * app)
2713 g_free (app->audiosink_str);
2714 g_free (app->videosink_str);
2716 g_static_mutex_free (&app->state_mutex);
2718 if (app->xoverlay_element)
2719 gst_object_unref (app->xoverlay_element);
2720 if (app->navigation_element)
2721 gst_object_unref (app->navigation_element);
2723 g_list_foreach (app->paths, (GFunc) g_free, NULL);
2724 g_list_free (app->paths);
2726 g_print ("free pipeline\n");
2727 gst_object_unref (app->pipeline);
2731 main (int argc, char **argv)
2734 GOptionEntry options[] = {
2735 {"stats", 's', 0, G_OPTION_ARG_NONE, &app.stats,
2736 "Show pad stats", NULL},
2737 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &app.verbose,
2738 "Verbose properties", NULL},
2741 GOptionContext *ctx;
2744 set_defaults (&app);
2746 #if !GLIB_CHECK_VERSION (2, 31, 0)
2747 if (!g_thread_supported ())
2748 g_thread_init (NULL);
2751 ctx = g_option_context_new ("- test seeking in gsteamer");
2752 g_option_context_add_main_entries (ctx, options, NULL);
2753 g_option_context_add_group (ctx, gst_init_get_option_group ());
2754 g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
2756 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
2757 g_print ("Error initializing: %s\n", err->message);
2761 GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example");
2764 print_usage (argc, argv);
2768 app.pipeline_type = atoi (argv[1]);
2770 if (app.pipeline_type < 0 || app.pipeline_type >= G_N_ELEMENTS (pipelines)) {
2771 print_usage (argc, argv);
2775 app.pipeline_spec = argv[2];
2777 if (g_path_is_absolute (app.pipeline_spec) &&
2778 (g_strrstr (app.pipeline_spec, "*") != NULL ||
2779 g_strrstr (app.pipeline_spec, "?") != NULL)) {
2780 app.paths = handle_wildcards (app.pipeline_spec);
2782 app.paths = g_list_prepend (app.paths, g_strdup (app.pipeline_spec));
2786 g_print ("opening %s failed\n", app.pipeline_spec);
2790 app.current_path = app.paths;
2792 pipelines[app.pipeline_type].func (&app, app.current_path->data);
2793 g_assert (app.pipeline);
2798 gtk_widget_show_all (app.window);
2800 /* realize window now so that the video window gets created and we can
2801 * obtain its XID before the pipeline is started up and the videosink
2802 * asks for the XID of the window to render onto */
2803 gtk_widget_realize (app.window);
2805 #if defined (GDK_WINDOWING_X11) || defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_QUARTZ)
2806 /* we should have the XID now */
2807 g_assert (app.embed_xid != 0);
2809 if (app.pipeline_type == 0) {
2810 gst_x_overlay_set_window_handle (GST_X_OVERLAY (app.pipeline),
2812 gst_x_overlay_handle_events (GST_X_OVERLAY (app.pipeline), FALSE);
2817 g_signal_connect (app.pipeline, "deep_notify",
2818 G_CALLBACK (gst_object_default_deep_notify), NULL);
2821 connect_bus_signals (&app);
2825 g_print ("NULL pipeline\n");
2826 gst_element_set_state (app.pipeline, GST_STATE_NULL);