From b01792e15e9e30625a602f776656a8ac8c69e42c Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 16 Aug 2005 13:37:47 +0000 Subject: remove seeking example, they're in gst-plugins-base Original commit message from CVS: remove seeking example, they're in gst-plugins-base --- examples/Makefile.am | 8 +- examples/seeking/.gitignore | 6 - examples/seeking/Makefile.am | 7 - examples/seeking/cdparanoia.c | 214 -------- examples/seeking/cdplayer.c | 303 ------------ examples/seeking/chained.c | 107 ---- examples/seeking/playbin.c | 270 ---------- examples/seeking/seek.c | 1082 ----------------------------------------- examples/seeking/vorbisfile.c | 266 ---------- 9 files changed, 1 insertion(+), 2262 deletions(-) delete mode 100644 examples/seeking/.gitignore delete mode 100644 examples/seeking/Makefile.am delete mode 100644 examples/seeking/cdparanoia.c delete mode 100644 examples/seeking/cdplayer.c delete mode 100644 examples/seeking/chained.c delete mode 100644 examples/seeking/playbin.c delete mode 100644 examples/seeking/seek.c delete mode 100644 examples/seeking/vorbisfile.c (limited to 'examples') diff --git a/examples/Makefile.am b/examples/Makefile.am index 11f92220..4620963e 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,9 +1,3 @@ -if HAVE_FT2 -FT2_SUBDIRS=seeking -else -FT2_SUBDIRS= -endif - if HAVE_GTK GTK_SUBDIRS=dynparams level $(FT2_SUBDIRS) else @@ -17,4 +11,4 @@ GCONF_SUBDIRS= endif SUBDIRS=$(GTK_SUBDIRS) $(GCONF_SUBDIRS) switch -DIST_SUBDIRS=capsfilter dynparams seeking indexing gstplay switch level +DIST_SUBDIRS=capsfilter dynparams indexing gstplay switch level diff --git a/examples/seeking/.gitignore b/examples/seeking/.gitignore deleted file mode 100644 index fcb1d209..00000000 --- a/examples/seeking/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -cdparanoia -cdplayer -seek -spider_seek -vorbisfile - diff --git a/examples/seeking/Makefile.am b/examples/seeking/Makefile.am deleted file mode 100644 index 582306ac..00000000 --- a/examples/seeking/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -examples = seek spider_seek cdplayer cdparanoia vorbisfile playbin chained - -noinst_PROGRAMS = $(examples) - -# we have nothing but apps here, we can do this safely -LIBS = $(GST_LIBS) $(GTK_LIBS) -AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/examples/seeking/cdparanoia.c b/examples/seeking/cdparanoia.c deleted file mode 100644 index d0e7bc94..00000000 --- a/examples/seeking/cdparanoia.c +++ /dev/null @@ -1,214 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include - -static void -get_position_info (GstElement * cdparanoia) -{ - GstFormat track_format; - const GstFormat *formats; - GstPad *pad; - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - formats = gst_pad_get_formats (pad); - - while (*formats) { - const GstFormatDefinition *definition; - GstFormat format; - gint64 position; - gboolean res; - - definition = gst_format_get_details (*formats); - - format = *formats; - res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position); - - if (format == GST_FORMAT_TIME) { - position /= GST_SECOND; - g_print ("%s: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT, - definition->nick, position / 60, position % 60); - } else { - g_print ("%s: %" G_GINT64_FORMAT, definition->nick, position); - } - - formats++; - if (*formats) { - g_print (", "); - } - } - g_print ("\r"); -} - -static void -get_track_info (GstElement * cdparanoia) -{ - GstFormat track_format; - gint64 total_tracks = 0, total_time = 0; - GstPad *pad; - const GstFormat *formats; - gint i; - gint64 time_count = 0; - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - formats = gst_pad_get_formats (pad); - - /* we loop over all supported formats and report the total - * number of them */ - while (*formats) { - const GstFormatDefinition *definition; - gint64 total; - GstFormat format; - gboolean res; - - definition = gst_format_get_details (*formats); - - format = *formats; - res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &total); - if (res) { - if (format == GST_FORMAT_TIME) { - total /= GST_SECOND; - g_print ("%s total: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n", - definition->nick, total / 60, total % 60); - } else - g_print ("%s total: %" G_GINT64_FORMAT "\n", definition->nick, total); - - if (format == track_format) - total_tracks = total; - else if (format == GST_FORMAT_TIME) - total_time = total; - } else - g_print ("failed to get %s total\n", definition->nick); - - formats++; - } - - /* then we loop over all the tracks to get more info. - * since pad_convert always works from 0, the time from track 1 needs - * to be substracted from track 2 */ - for (i = 0; i <= total_tracks; i++) { - gint64 time; - gboolean res; - - if (i < total_tracks) { - GstFormat format; - - format = GST_FORMAT_TIME; - res = gst_pad_convert (pad, track_format, i, &format, &time); - time /= GST_SECOND; - } else { - time = total_time; - res = TRUE; - } - - if (res) { - /* for the first track (i==0) we wait until we have the - * time of the next track */ - if (i > 0) { - gint64 length = time - time_count; - - g_print ("track %d: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT - " -> %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ", length: %" - G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n", - i - 1, - time_count / 60, time_count % 60, - time / 60, time % 60, length / 60, length % 60); - } - } else { - g_print ("could not get time for track %d\n", i); - } - - time_count = time; - } -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstElement *cdparanoia; - GstElement *audiosink; - GstPad *pad; - GstFormat track_format; - GstEvent *event; - gint count; - gboolean res; - - gst_init (&argc, &argv); - - pipeline = gst_pipeline_new ("pipeline"); - - cdparanoia = gst_element_factory_make ("cdparanoia", "cdparanoia"); - g_assert (cdparanoia); - g_object_set (G_OBJECT (cdparanoia), "paranoia_mode", 0, NULL); - - audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK); - g_assert (audiosink); - - gst_bin_add (GST_BIN (pipeline), cdparanoia); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link_pads (cdparanoia, "src", audiosink, "sink"); - - g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - - gst_element_set_state (pipeline, GST_STATE_PAUSED); - - /* now we go into probe mode */ - get_track_info (cdparanoia); - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - g_assert (pad); - - g_print ("playing from track 3\n"); - /* seek to track3 */ - event = gst_event_new_seek (track_format | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 3); - - res = gst_pad_send_event (pad, event); - if (!res) - g_warning ("seek failed"); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - count = 0; - while (gst_bin_iterate (GST_BIN (pipeline))) { - get_position_info (cdparanoia); - if (count++ > 500) - break; - } - gst_element_set_state (pipeline, GST_STATE_PAUSED); - - g_print ("\nplaying from second 25 to second 29\n"); - /* seek to some seconds */ - event = gst_event_new_segment_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, 25 * GST_SECOND, 29 * GST_SECOND); - res = gst_pad_send_event (pad, event); - if (!res) - g_warning ("seek failed"); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - while (gst_bin_iterate (GST_BIN (pipeline))) { - get_position_info (cdparanoia); - } - g_print ("\n"); - - /* shutdown everything again */ - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/examples/seeking/cdplayer.c b/examples/seeking/cdplayer.c deleted file mode 100644 index 21fa302d..00000000 --- a/examples/seeking/cdplayer.c +++ /dev/null @@ -1,303 +0,0 @@ -#include -#include -#include -#include -#include - -static GList *seekable_elements = NULL; - -static GstElement *pipeline; -static GtkAdjustment *adjustment; -static gboolean stats = FALSE; -static guint64 duration; - -static guint update_id; - -#define UPDATE_INTERVAL 500 - -static GstElement * -make_cdaudio_pipeline (void) -{ - GstElement *cdaudio; - - cdaudio = gst_element_factory_make ("cdaudio", "cdaudio"); - g_assert (cdaudio != NULL); - - seekable_elements = g_list_prepend (seekable_elements, cdaudio); - - return cdaudio; -} - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / 100; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / 100); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - -typedef struct -{ - const gchar *name; - const GstFormat format; -} -seek_format; - -static seek_format seek_formats[] = { - {"tim", GST_FORMAT_TIME}, - {"byt", GST_FORMAT_BYTES}, - {"buf", GST_FORMAT_BUFFERS}, - {"def", GST_FORMAT_DEFAULT}, - {NULL, 0}, -}; - - -G_GNUC_UNUSED static void -query_durations () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - walk = g_list_next (walk); - } -} - -static gboolean -update_scale (gpointer data) -{ - GstClock *clock; - guint64 position = 0; - GstFormat format = GST_FORMAT_TIME; - - duration = 0; - clock = gst_bin_get_clock (GST_BIN (pipeline)); - - if (seekable_elements) { - GstElement *element = GST_ELEMENT (seekable_elements->data); - - gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); - gst_element_query (element, GST_QUERY_POSITION, &format, &position); - } - - if (stats) { - if (clock) - g_print ("clock: %13" G_GUINT64_FORMAT " (%s)\n", - position, gst_object_get_name (GST_OBJECT (clock))); - query_durations (); - query_positions (); - } - if (duration > 0) { - gtk_adjustment_set_value (adjustment, position * 100.0 / duration); - } - - return TRUE; -} - -static gboolean -iterate (gpointer data) -{ - gboolean res = TRUE; - - g_print ("iterate\n"); - res = gst_bin_iterate (GST_BIN (data)); - if (!res) { - gtk_timeout_remove (update_id); - g_print ("stopping iterations\n"); - } - return res; -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; - gboolean res; - GstEvent *s_event; - GList *walk = seekable_elements; - - while (walk) { - GstElement *seekable = GST_ELEMENT (walk->data); - - g_print ("seek to %" G_GINT64_FORMAT " on element %s\n", real, - GST_ELEMENT_NAME (seekable)); - s_event = - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); - - res = gst_element_send_event (seekable, s_event); - - walk = g_list_next (walk); - } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - - return FALSE; -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) { - gst_element_set_state (pipeline, GST_STATE_PLAYING); - if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE)) - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_READY) { - gst_element_set_state (pipeline, GST_STATE_READY); - gtk_timeout_remove (update_id); - } -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, *hscale; - struct poptOption options[] = { - {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, - "Show element stats", NULL}, - POPT_TABLEEND - }; - - gst_init_with_popt_table (&argc, &argv, options); - gtk_init (&argc, &argv); - - pipeline = make_cdaudio_pipeline (); - - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), - NULL); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - play_button = gtk_button_new_with_label ("play"); - pause_button = gtk_button_new_with_label ("pause"); - stop_button = gtk_button_new_with_label ("stop"); - - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - gtk_signal_connect (GTK_OBJECT (hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "format_value", G_CALLBACK (format_value), pipeline); - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - gtk_main (); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/examples/seeking/chained.c b/examples/seeking/chained.c deleted file mode 100644 index bf23e05a..00000000 --- a/examples/seeking/chained.c +++ /dev/null @@ -1,107 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include - -static GstElement *bin; - -static void -unlinked (GstPad * pad, GstPad * peerpad, GstElement * pipeline) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_bin_remove (GST_BIN (pipeline), bin); - gst_element_set_state (bin, GST_STATE_READY); - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -static void -new_pad (GstElement * elem, GstPad * newpad, GstElement * pipeline) -{ - GstScheduler *sched; - GstClock *clock; - - g_print ("new pad %s\n", gst_pad_get_name (newpad)); - - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_bin_add (GST_BIN (pipeline), bin); - - sched = gst_element_get_scheduler (GST_ELEMENT (pipeline)); - clock = gst_scheduler_get_clock (sched); - gst_scheduler_set_clock (sched, clock); - - gst_pad_link (newpad, gst_element_get_pad (bin, "sink")); - - g_signal_connect (G_OBJECT (newpad), "unlinked", G_CALLBACK (unlinked), - pipeline); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstElement *filesrc; - GstElement *oggdemux; - GstElement *vorbisdec; - GstElement *audioconvert; - GstElement *audiosink; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s \n", argv[0]); - return (-1); - } - - pipeline = gst_pipeline_new ("pipeline"); - - filesrc = gst_element_factory_make ("filesrc", "filesrc"); - g_assert (filesrc); - g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); - - oggdemux = gst_element_factory_make ("oggdemux", "oggdemux"); - g_assert (oggdemux); - - gst_bin_add (GST_BIN (pipeline), filesrc); - gst_bin_add (GST_BIN (pipeline), oggdemux); - - gst_element_link_pads (filesrc, "src", oggdemux, "sink"); - - g_signal_connect (G_OBJECT (oggdemux), "new_pad", G_CALLBACK (new_pad), - pipeline); - - bin = gst_bin_new ("bin"); - vorbisdec = gst_element_factory_make ("vorbisdec", "vorbisdec"); - g_assert (vorbisdec); - audioconvert = gst_element_factory_make ("audioconvert", "audioconvert"); - g_assert (audioconvert); - audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK); - g_assert (audiosink); - gst_bin_add (GST_BIN (bin), vorbisdec); - gst_bin_add (GST_BIN (bin), audioconvert); - gst_bin_add (GST_BIN (bin), audiosink); - - gst_element_link_pads (vorbisdec, "src", audioconvert, "sink"); - gst_element_link_pads (audioconvert, "src", audiosink, "sink"); - - gst_element_add_ghost_pad (bin, gst_element_get_pad (vorbisdec, "sink"), - "sink"); - - g_object_ref (G_OBJECT (bin)); - - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - while (gst_bin_iterate (GST_BIN (pipeline))) - /* nop */ ; - - /* stop probe */ - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/examples/seeking/playbin.c b/examples/seeking/playbin.c deleted file mode 100644 index b6ff35b8..00000000 --- a/examples/seeking/playbin.c +++ /dev/null @@ -1,270 +0,0 @@ -#include -#include -#include -#include -#include - -static GstElement *playbin = NULL; -static GstElement *pipeline; -static guint64 duration; -static GtkAdjustment *adjustment; -static GtkWidget *hscale; -static gboolean verbose = FALSE; - -static guint update_id; - -#define UPDATE_INTERVAL 500 - -static GstElement * -make_playerbin_pipeline (const gchar * location) -{ - playbin = gst_element_factory_make ("playbin", "player"); - g_assert (playbin); - - g_object_set (G_OBJECT (playbin), "uri", location, NULL); - - return playbin; -} - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / 100; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / 100); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - -static gboolean -update_scale (gpointer data) -{ - GstClock *clock; - guint64 position; - GstFormat format = GST_FORMAT_TIME; - gboolean res; - - duration = 0; - clock = gst_bin_get_clock (GST_BIN (pipeline)); - - res = gst_element_query (playbin, GST_QUERY_TOTAL, &format, &duration); - if (!res) - duration = 0; - res = gst_element_query (playbin, GST_QUERY_POSITION, &format, &position); - if (!res) - position = 0; - - if (position >= duration) - duration = position; - - if (duration > 0) { - gtk_adjustment_set_value (adjustment, position * 100.0 / duration); - gtk_widget_queue_draw (hscale); - } - - return TRUE; -} - -static gboolean -iterate (gpointer data) -{ - gboolean res; - - if (!GST_FLAG_IS_SET (GST_OBJECT (data), GST_BIN_SELF_SCHEDULABLE)) { - res = gst_bin_iterate (GST_BIN (data)); - } else { - g_usleep (UPDATE_INTERVAL); - res = gst_element_get_state (GST_ELEMENT (data)) == GST_STATE_PLAYING; - } - - if (!res) { - gtk_timeout_remove (update_id); - g_print ("stopping iterations\n"); - } - return res; -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; - gboolean res; - GstEvent *s_event; - - g_print ("seek to %" G_GINT64_FORMAT " on element %s\n", real, - gst_element_get_name (playbin)); - s_event = - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); - - res = gst_element_send_event (playbin, s_event); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - - return FALSE; -} - -static void -print_media_info (GstElement * playbin) -{ - GList *streaminfo; - GList *s; - - g_print ("have media info now\n"); - - /* get info about the stream */ - g_object_get (G_OBJECT (playbin), "stream-info", &streaminfo, NULL); - - for (s = streaminfo; s; s = g_list_next (s)) { - GObject *obj = G_OBJECT (s->data); - gint type; - gboolean mute; - - g_object_get (obj, "type", &type, NULL); - g_object_get (obj, "mute", &mute, NULL); - - g_print ("%d %d\n", type, mute); - } -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) { - GstElementStateReturn res; - - res = gst_element_set_state (pipeline, GST_STATE_PAUSED); - if (res == GST_STATE_SUCCESS) { - print_media_info (playbin); - - res = gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, - pipeline); - } else { - g_print ("failed playing\n"); - } - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_READY) { - gst_element_set_state (pipeline, GST_STATE_READY); - gtk_adjustment_set_value (adjustment, 0.0); - gtk_timeout_remove (update_id); - } -} - -static void -print_usage (int argc, char **argv) -{ - g_print ("usage: %s \n", argv[0]); -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button; - struct poptOption options[] = { - {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0, - "Verbose properties", NULL}, - POPT_TABLEEND - }; - - gst_init_with_popt_table (&argc, &argv, options); - gtk_init (&argc, &argv); - - if (argc != 2) { - print_usage (argc, argv); - exit (-1); - } - - pipeline = make_playerbin_pipeline (argv[1]); - g_assert (pipeline); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - play_button = gtk_button_new_with_label ("play"); - pause_button = gtk_button_new_with_label ("pause"); - stop_button = gtk_button_new_with_label ("stop"); - - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - gtk_signal_connect (GTK_OBJECT (hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "format_value", G_CALLBACK (format_value), pipeline); - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - if (verbose) { - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - } - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), - NULL); - - gtk_main (); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - gst_object_unref (GST_OBJECT (pipeline)); - - return 0; -} diff --git a/examples/seeking/seek.c b/examples/seeking/seek.c deleted file mode 100644 index fdd7c45d..00000000 --- a/examples/seeking/seek.c +++ /dev/null @@ -1,1082 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#include -#include - -static GList *seekable_pads = NULL; -static GList *rate_pads = NULL; -static GList *seekable_elements = NULL; - -static GstElement *pipeline; -static guint64 duration; -static GtkAdjustment *adjustment; -static GtkWidget *hscale; -static gboolean stats = FALSE; -static gboolean elem_seek = FALSE; -static gboolean verbose = FALSE; - -static guint update_id; - -//#define SOURCE "gnomevfssrc" -#define SOURCE "filesrc" - -#define UPDATE_INTERVAL 500 - -#define THREAD -#define PAD_SEEK - -typedef struct -{ - const gchar *padname; - GstPad *target; - GstElement *bin; -} -dyn_link; - -static GstElement * -gst_element_factory_make_or_warn (gchar * type, gchar * name) -{ - GstElement *element = gst_element_factory_make (type, name); - - if (!element) { - g_warning ("Failed to create element %s of type %s", name, type); - } - - return element; -} - -static void -dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) -{ - dyn_link *connect = (dyn_link *) data; - - if (!strcmp (gst_pad_get_name (newpad), connect->padname)) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_bin_add (GST_BIN (pipeline), connect->bin); - gst_pad_link (newpad, connect->target); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - seekable_pads = g_list_prepend (seekable_pads, newpad); - rate_pads = g_list_prepend (rate_pads, newpad); - } -} - -static void -setup_dynamic_link (GstElement * element, const gchar * padname, - GstPad * target, GstElement * bin) -{ - dyn_link *connect; - - connect = g_new0 (dyn_link, 1); - connect->padname = g_strdup (padname); - connect->target = target; - connect->bin = bin; - - g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), - connect); -} - -static GstElement * -make_mod_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("modplug", "decoder"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_dv_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink, *videosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("dvdec", "decoder"); - videosink = gst_element_factory_make_or_warn (DEFAULT_VIDEOSINK, "v_sink"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "a_sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - gst_bin_add (GST_BIN (pipeline), videosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - gst_element_link (decoder, videosink); - - seekable = gst_element_get_pad (decoder, "video"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - seekable = gst_element_get_pad (decoder, "audio"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_wav_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("wavparse", "decoder"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_flac_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("flacdec", "decoder"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_sid_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("siddec", "decoder"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_parse_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *parser, *fakesink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - parser = gst_element_factory_make_or_warn ("mpegparse", "parse"); - fakesink = gst_element_factory_make_or_warn ("fakesink", "sink"); - g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL); - g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), parser); - gst_bin_add (GST_BIN (pipeline), fakesink); - - gst_element_link (src, parser); - gst_element_link (parser, fakesink); - - seekable = gst_element_get_pad (parser, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (parser, "sink")); - - return pipeline; -} - -static GstElement * -make_vorbis_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("vorbisfile", "decoder"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_mp3_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink, *queue, *audio_thread; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("mad", "dec"); - queue = gst_element_factory_make_or_warn ("queue", "queue"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "sink"); - - audio_thread = gst_thread_new ("a_decoder_thread"); - - seekable_elements = g_list_prepend (seekable_elements, audiosink); - - g_object_set (G_OBJECT (src), "location", location, NULL); - g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (audio_thread), queue); - gst_bin_add (GST_BIN (audio_thread), audiosink); - gst_bin_add (GST_BIN (pipeline), audio_thread); - - gst_element_link (src, decoder); - gst_element_link (decoder, queue); - gst_element_link (queue, audiosink); - - seekable = gst_element_get_pad (queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = g_list_prepend (rate_pads, gst_element_get_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_avi_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink; - GstElement *a_queue = NULL, *audio_thread = NULL, *v_queue = - NULL, *video_thread = NULL; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("avidemux", "demux"); - seekable_elements = g_list_prepend (seekable_elements, demux); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - audio_thread = gst_thread_new ("a_decoder_thread"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "a_sink"); - //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), audio_thread); - gst_bin_add (GST_BIN (audio_thread), a_queue); - gst_bin_add (GST_BIN (audio_thread), audiosink); - gst_element_set_state (audio_bin, GST_STATE_PAUSED); - - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, - "sink"), audio_bin); - - seekable = gst_element_get_pad (a_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); - - video_bin = gst_bin_new ("v_decoder_bin"); - //v_decoder = gst_element_factory_make_or_warn ("identity", "v_dec"); - //v_decoder = gst_element_factory_make_or_warn ("windec", "v_dec"); - v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec"); - video_thread = gst_thread_new ("v_decoder_thread"); - videosink = gst_element_factory_make_or_warn (DEFAULT_VIDEOSINK, "v_sink"); - //videosink = gst_element_factory_make_or_warn ("fakesink", "v_sink"); - //g_object_set (G_OBJECT (videosink), "sync", TRUE, NULL); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - //g_object_set (G_OBJECT (v_queue), "max_level", 10, NULL); - gst_element_link (v_decoder, v_queue); - gst_element_link (v_queue, videosink); - gst_bin_add (GST_BIN (video_bin), v_decoder); - gst_bin_add (GST_BIN (video_bin), video_thread); - gst_bin_add (GST_BIN (video_thread), v_queue); - gst_bin_add (GST_BIN (video_thread), videosink); - - gst_element_set_state (video_bin, GST_STATE_PAUSED); - - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, - "sink"), video_bin); - - seekable = gst_element_get_pad (v_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_mpeg_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; - GstElement *audiosink, *videosink; - GstElement *a_queue, *audio_thread, *v_queue, *video_thread; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("mpegdemux", "demux"); - g_object_set (G_OBJECT (demux), "sync", FALSE, NULL); - - seekable_elements = g_list_prepend (seekable_elements, demux); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - audio_thread = gst_thread_new ("a_decoder_thread"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "a_sink"); - g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), audio_thread); - gst_bin_add (GST_BIN (audio_thread), a_queue); - gst_bin_add (GST_BIN (audio_thread), audiosink); - - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, - "sink"), audio_bin); - - seekable = gst_element_get_pad (a_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); - video_thread = gst_thread_new ("v_decoder_thread"); - //g_object_set (G_OBJECT (video_thread), "priority", 2, NULL); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter"); - videosink = gst_element_factory_make_or_warn (DEFAULT_VIDEOSINK, "v_sink"); - gst_element_link_many (v_decoder, v_queue, v_filter, NULL); - - gst_element_link (v_filter, videosink); - gst_bin_add_many (GST_BIN (video_bin), v_decoder, video_thread, NULL); - gst_bin_add_many (GST_BIN (video_thread), v_queue, v_filter, videosink, NULL); - - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, - "sink"), video_bin); - - seekable = gst_element_get_pad (v_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_mpegnt_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; - GstElement *audiosink, *videosink; - GstElement *a_queue, *audio_thread; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("mpegdemux", "demux"); - //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL); - - seekable_elements = g_list_prepend (seekable_elements, demux); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - audio_thread = gst_thread_new ("a_decoder_thread"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - audiosink = gst_element_factory_make_or_warn (DEFAULT_AUDIOSINK, "a_sink"); - //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), audio_thread); - gst_bin_add (GST_BIN (audio_thread), a_queue); - gst_bin_add (GST_BIN (audio_thread), audiosink); - - setup_dynamic_link (demux, "audio_00", gst_element_get_pad (a_decoder, - "sink"), audio_bin); - - seekable = gst_element_get_pad (a_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (a_decoder, "sink")); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); - v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter"); - videosink = gst_element_factory_make_or_warn (DEFAULT_VIDEOSINK, "v_sink"); - gst_element_link_many (v_decoder, v_filter, videosink, NULL); - - gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL); - - setup_dynamic_link (demux, "video_00", gst_element_get_pad (v_decoder, - "sink"), video_bin); - - seekable = gst_element_get_pad (v_decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_pad (v_decoder, "sink")); - - return pipeline; -} - -static GstCaps * -fixate (GstPad * pad, const GstCaps * in_caps, gpointer data) -{ - GstCaps *caps; - GstStructure *s; - - if (gst_caps_get_size (in_caps) > 1) - return NULL; - - /* nothing if fixed already */ - s = gst_caps_get_structure (in_caps, 0); - if (gst_structure_has_field_typed (s, "width", G_TYPE_INT) && - gst_structure_has_field_typed (s, "height", G_TYPE_INT) && - gst_structure_has_field_typed (s, "framerate", G_TYPE_DOUBLE)) - return NULL; - - /* fixate */ - caps = gst_caps_copy (in_caps); - s = gst_caps_get_structure (caps, 0); - gst_caps_structure_fixate_field_nearest_int (s, "width", 200); - gst_caps_structure_fixate_field_nearest_int (s, "height", 150); - gst_caps_structure_fixate_field_nearest_double (s, "framerate", 10.0); - - return caps; -} - -static GstElement * -make_playerbin_pipeline (const gchar * location) -{ - GstElement *player, *vis; - - player = gst_element_factory_make ("playbin", "player"); - vis = gst_element_factory_make ("synaesthesia", "vis"); - g_assert (player); - g_assert (vis); - - g_signal_connect (gst_element_get_pad (vis, "src"), "fixate", - G_CALLBACK (fixate), NULL); - g_object_set (G_OBJECT (player), "uri", location, "vis-plugin", vis, NULL); - - seekable_elements = g_list_prepend (seekable_elements, player); - - /* force element seeking on this pipeline */ - elem_seek = TRUE; - - return player; -} - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / 100; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / 100); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - -typedef struct -{ - const gchar *name; - const GstFormat format; -} -seek_format; - -static seek_format seek_formats[] = { - {"tim", GST_FORMAT_TIME}, - {"byt", GST_FORMAT_BYTES}, - {"buf", GST_FORMAT_BUFFERS}, - {"def", GST_FORMAT_DEFAULT}, - {NULL, 0}, -}; - -G_GNUC_UNUSED static void -query_rates (void) -{ - GList *walk = rate_pads; - - while (walk) { - GstPad *pad = GST_PAD (walk->data); - gint i = 0; - - g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad)); - while (seek_formats[i].name) { - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - - if (gst_pad_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, &value)) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - - i++; - } - g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_durations_elems () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_durations_pads () -{ - GList *walk = seekable_pads; - - while (walk) { - GstPad *pad = GST_PAD (walk->data); - gint i = 0; - - g_print ("durations %8.8s: ", GST_PAD_NAME (pad)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions_elems () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions_pads () -{ - GList *walk = seekable_pads; - - while (walk) { - GstPad *pad = GST_PAD (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_PAD_NAME (pad)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - - walk = g_list_next (walk); - } -} - -static gboolean -update_scale (gpointer data) -{ - GstClock *clock; - guint64 position; - GstFormat format = GST_FORMAT_TIME; - gboolean res; - - duration = 0; - clock = gst_bin_get_clock (GST_BIN (pipeline)); - - if (elem_seek) { - if (seekable_elements) { - GstElement *element = GST_ELEMENT (seekable_elements->data); - - res = gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); - if (!res) - duration = 0; - res = gst_element_query (element, GST_QUERY_POSITION, &format, &position); - if (!res) - position = 0; - } - } else { - if (seekable_pads) { - GstPad *pad = GST_PAD (seekable_pads->data); - - res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &duration); - if (!res) - duration = 0; - res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position); - if (!res) - position = 0; - } - } - - if (stats) { - if (clock) { - g_print ("clock: %13" G_GUINT64_FORMAT " (%s)\n", - position, gst_object_get_name (GST_OBJECT (clock))); - } - - if (elem_seek) { - query_durations_elems (); - query_positions_elems (); - } else { - query_durations_pads (); - query_positions_pads (); - } - query_rates (); - } - if (position >= duration) - duration = position; - - if (duration > 0) { - gtk_adjustment_set_value (adjustment, position * 100.0 / duration); - gtk_widget_queue_draw (hscale); - } - - return TRUE; -} - -static gboolean -iterate (gpointer data) -{ - gboolean res; - - if (!GST_FLAG_IS_SET (GST_OBJECT (data), GST_BIN_SELF_SCHEDULABLE)) { - res = gst_bin_iterate (GST_BIN (data)); - } else { - g_usleep (500); - res = gst_element_get_state (GST_ELEMENT (data)) == GST_STATE_PLAYING; - } - - if (!res) { - gtk_timeout_remove (update_id); - g_print ("stopping iterations\n"); - } - return res; -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; - gboolean res; - GstEvent *s_event; - - if (!elem_seek) { - GList *walk = seekable_pads; - - while (walk) { - GstPad *seekable = GST_PAD (walk->data); - - g_print ("seek to %" G_GINT64_FORMAT " on pad %s:%s\n", real, - GST_DEBUG_PAD_NAME (seekable)); - s_event = - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); - - res = gst_pad_send_event (seekable, s_event); - - walk = g_list_next (walk); - } - } else { - GList *walk = seekable_elements; - - while (walk) { - GstElement *seekable = GST_ELEMENT (walk->data); - - g_print ("seek to %" G_GINT64_FORMAT " on element %s\n", real, - gst_element_get_name (seekable)); - s_event = - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); - - res = gst_element_send_event (seekable, s_event); - - walk = g_list_next (walk); - } - } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - - return FALSE; -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) { - gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_idle_add ((GtkFunction) iterate, pipeline); - update_id = - gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gtk_timeout_remove (update_id); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - if (gst_element_get_state (pipeline) != GST_STATE_READY) { - gst_element_set_state (pipeline, GST_STATE_READY); - gtk_adjustment_set_value (adjustment, 0.0); - gtk_timeout_remove (update_id); - } -} - -typedef struct -{ - gchar *name; - GstElement *(*func) (const gchar * location); -} -Pipeline; - -static Pipeline pipelines[] = { - {"mp3", make_mp3_pipeline}, - {"avi", make_avi_pipeline}, - {"mpeg1", make_mpeg_pipeline}, - {"mpegparse", make_parse_pipeline}, - {"vorbis", make_vorbis_pipeline}, - {"sid", make_sid_pipeline}, - {"flac", make_flac_pipeline}, - {"wav", make_wav_pipeline}, - {"mod", make_mod_pipeline}, - {"dv", make_dv_pipeline}, - {"mpeg1nothreads", make_mpegnt_pipeline}, - {"playerbin", make_playerbin_pipeline}, - {NULL, NULL}, -}; - -#define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1) - -static void -print_usage (int argc, char **argv) -{ - gint i; - - g_print ("usage: %s \n", argv[0]); - g_print (" possible types:\n"); - - for (i = 0; i < NUM_TYPES; i++) { - g_print (" %d = %s\n", i, pipelines[i].name); - } -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button; - struct poptOption options[] = { - {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, - "Show pad stats", NULL}, - {"elem", 'e', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &elem_seek, 0, - "Seek on elements instead of pads", NULL}, - {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0, - "Verbose properties", NULL}, - POPT_TABLEEND - }; - gint type; - - gst_init_with_popt_table (&argc, &argv, options); - gtk_init (&argc, &argv); - - if (argc != 3) { - print_usage (argc, argv); - exit (-1); - } - - type = atoi (argv[1]); - - if (type < 0 || type >= NUM_TYPES) { - print_usage (argc, argv); - exit (-1); - } - - pipeline = pipelines[type].func (argv[2]); - g_assert (pipeline); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - play_button = gtk_button_new_with_label ("play"); - pause_button = gtk_button_new_with_label ("pause"); - stop_button = gtk_button_new_with_label ("stop"); - - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - gtk_signal_connect (GTK_OBJECT (hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - gtk_signal_connect (GTK_OBJECT (hscale), - "format_value", G_CALLBACK (format_value), pipeline); - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - if (verbose) { - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - } - g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), - NULL); - - gtk_main (); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - //gst_object_unref (GST_OBJECT (pipeline)); - - //g_mem_chunk_info(); - - return 0; -} diff --git a/examples/seeking/vorbisfile.c b/examples/seeking/vorbisfile.c deleted file mode 100644 index d193642f..00000000 --- a/examples/seeking/vorbisfile.c +++ /dev/null @@ -1,266 +0,0 @@ -#include -#include -#include - -static gboolean ready = FALSE; - -struct probe_context -{ - GstElement *pipeline; - GstElement *element; - GstPad *pad; - GstFormat ls_format; - - gint total_ls; - - GstCaps *metadata; - GstCaps *streaminfo; - GstCaps *caps; -}; - -static void -print_caps (GstCaps * caps) -{ - char *s; - - s = gst_caps_to_string (caps); - g_print (" %s\n", s); - g_free (s); -} - -static void -print_format (GstCaps * caps) -{ - char *s; - - s = gst_caps_to_string (caps); - g_print (" format: %s\n", s); - g_free (s); -} - -static void -print_lbs_info (struct probe_context *context, gint stream) -{ - const GstFormat *formats; - - /* FIXME: need a better name here */ - g_print (" stream info:\n"); - - /* report info in all supported formats */ - formats = gst_pad_get_formats (context->pad); - while (*formats) { - const GstFormatDefinition *definition; - gint64 value_start, value_end; - gboolean res; - GstFormat format; - - format = *formats; - formats++; - - if (format == context->ls_format) { - continue; - } - - definition = gst_format_get_details (format); - - /* get start and end position of this stream */ - res = gst_pad_convert (context->pad, - context->ls_format, stream, &format, &value_start); - res &= gst_pad_convert (context->pad, - context->ls_format, stream + 1, &format, &value_end); - - if (res) { - /* substract to get the length */ - value_end -= value_start; - - if (format == GST_FORMAT_TIME) { - value_end /= (GST_SECOND / 100); - g_print (" %s: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ".%02" - G_GINT64_FORMAT "\n", definition->nick, value_end / 6000, - (value_end / 100) % 60, (value_end % 100)); - } else { - g_print (" %s: %" G_GINT64_FORMAT "\n", definition->nick, value_end); - } - } else - g_print (" could not get logical stream %s\n", definition->nick); - - } -} - -static void -deep_notify (GObject * object, GstObject * origin, - GParamSpec * pspec, gpointer data) -{ - struct probe_context *context = (struct probe_context *) data; - GValue value = { 0, }; - - if (!strcmp (pspec->name, "metadata")) { - - g_value_init (&value, pspec->value_type); - g_object_get_property (G_OBJECT (origin), pspec->name, &value); - context->metadata = g_value_peek_pointer (&value); - } else if (!strcmp (pspec->name, "streaminfo")) { - - g_value_init (&value, pspec->value_type); - g_object_get_property (G_OBJECT (origin), pspec->name, &value); - context->streaminfo = g_value_peek_pointer (&value); - } else if (!strcmp (pspec->name, "caps")) { - if (GST_IS_PAD (origin) && GST_PAD (origin) == context->pad) { - g_value_init (&value, pspec->value_type); - g_object_get_property (G_OBJECT (origin), pspec->name, &value); - context->caps = g_value_peek_pointer (&value); - - ready = TRUE; - } - } -} - -static gboolean -collect_logical_stream_properties (struct probe_context *context, gint stream) -{ - GstEvent *event; - gboolean res; - gint count; - - g_print ("info for logical stream %d:\n", stream); - - /* seek to stream */ - event = gst_event_new_seek (context->ls_format | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, stream); - res = gst_pad_send_event (context->pad, event); - if (!res) { - g_warning ("seek to logical track failed"); - return FALSE; - } - - /* run the pipeline to get the info */ - count = 0; - ready = FALSE; - while (gst_bin_iterate (GST_BIN (context->pipeline)) && !ready) { - count++; - if (count > 10) - break; - } - - print_caps (context->metadata); - print_caps (context->streaminfo); - print_format (context->caps); - print_lbs_info (context, stream); - - g_print ("\n"); - - return TRUE; -} - -static void -collect_stream_properties (struct probe_context *context) -{ - const GstFormat *formats; - - ready = FALSE; - while (gst_bin_iterate (GST_BIN (context->pipeline)) && !ready); - - g_print ("stream info:\n"); - - context->total_ls = -1; - - /* report info in all supported formats */ - formats = gst_pad_get_formats (context->pad); - while (*formats) { - const GstFormatDefinition *definition; - gint64 value; - gboolean res; - GstFormat format; - - format = *formats; - formats++; - - res = gst_pad_query (context->pad, GST_QUERY_TOTAL, &format, &value); - - definition = gst_format_get_details (format); - - if (res) { - if (format == GST_FORMAT_TIME) { - value /= (GST_SECOND / 100); - g_print (" total %s: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ".%02" - G_GINT64_FORMAT "\n", definition->nick, value / 6000, - (value / 100) % 60, (value % 100)); - } else { - if (format == context->ls_format) - context->total_ls = value; - g_print (" total %s: %" G_GINT64_FORMAT "\n", definition->nick, value); - } - } - } - - if (context->total_ls == -1) { - g_warning (" could not get number of logical streams"); - } - g_print ("\n"); -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstElement *filesrc; - GstElement *vorbisfile; - GstPad *pad; - GstFormat logical_stream_format; - struct probe_context *context; - gint stream; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s \n", argv[0]); - return (-1); - } - - pipeline = gst_pipeline_new ("pipeline"); - - filesrc = gst_element_factory_make ("filesrc", "filesrc"); - g_assert (filesrc); - g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); - - vorbisfile = gst_element_factory_make ("vorbisfile", "vorbisfile"); - //vorbisfile = gst_element_factory_make ("mad", "vorbisfile"); - g_assert (vorbisfile); - - gst_bin_add (GST_BIN (pipeline), filesrc); - gst_bin_add (GST_BIN (pipeline), vorbisfile); - - gst_element_link_pads (filesrc, "src", vorbisfile, "sink"); - - pad = gst_element_get_pad (vorbisfile, "src"); - g_assert (pad); - - logical_stream_format = gst_format_get_by_nick ("logical_stream"); - g_assert (logical_stream_format != 0); - - context = g_new0 (struct probe_context, 1); - context->pipeline = pipeline; - context->element = vorbisfile; - context->pad = pad; - context->ls_format = logical_stream_format; - - g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (deep_notify), context); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* at this point we can inspect the stream */ - collect_stream_properties (context); - - /* loop over all logical streams to get info */ - stream = 0; - while (stream < context->total_ls) { - collect_logical_stream_properties (context, stream); - stream++; - } - - /* stop probe */ - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} -- cgit v1.2.1