diff options
Diffstat (limited to 'examples/seeking/cdplayer.c')
-rw-r--r-- | examples/seeking/cdplayer.c | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/examples/seeking/cdplayer.c b/examples/seeking/cdplayer.c index 6ce55471..1e823cc5 100644 --- a/examples/seeking/cdplayer.c +++ b/examples/seeking/cdplayer.c @@ -15,11 +15,11 @@ static guint update_id; #define UPDATE_INTERVAL 500 -static GstElement* -make_cdaudio_pipeline (void) +static GstElement * +make_cdaudio_pipeline (void) { GstElement *cdaudio; - + cdaudio = gst_element_factory_make ("cdaudio", "cdaudio"); g_assert (cdaudio != NULL); @@ -28,9 +28,8 @@ make_cdaudio_pipeline (void) return cdaudio; } -static gchar* -format_value (GtkScale *scale, - gdouble value) +static gchar * +format_value (GtkScale * scale, gdouble value) { gint64 real; gint64 seconds; @@ -41,9 +40,7 @@ format_value (GtkScale *scale, subseconds = (gint64) real / (GST_SECOND / 100); return g_strdup_printf ("%02lld:%02lld:%02lld", - seconds/60, - seconds%60, - subseconds%100); + seconds / 60, seconds % 60, subseconds % 100); } typedef struct @@ -52,13 +49,12 @@ typedef struct 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 }, +static seek_format seek_formats[] = { + {"tim", GST_FORMAT_TIME}, + {"byt", GST_FORMAT_BYTES}, + {"buf", GST_FORMAT_BUFFERS}, + {"def", GST_FORMAT_DEFAULT}, + {NULL, 0}, }; @@ -80,10 +76,9 @@ query_durations () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -110,10 +105,9 @@ query_positions () format = seek_formats[i].format; res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); if (res) { - g_print ("%s %13lld | ", seek_formats[i].name, value); - } - else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); + g_print ("%s %13lld | ", seek_formats[i].name, value); + } else { + g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); } i++; } @@ -123,7 +117,7 @@ query_positions () } static gboolean -update_scale (gpointer data) +update_scale (gpointer data) { GstClock *clock; guint64 position = 0; @@ -134,6 +128,7 @@ update_scale (gpointer data) if (seekable_elements) { GstElement *element = GST_ELEMENT (seekable_elements->data); + gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); } if (clock) @@ -141,7 +136,8 @@ update_scale (gpointer data) if (stats) { if (clock) - g_print ("clock: %13llu (%s)\n", position, gst_object_get_name (GST_OBJECT (clock))); + g_print ("clock: %13llu (%s)\n", position, + gst_object_get_name (GST_OBJECT (clock))); query_durations (); query_positions (); } @@ -167,7 +163,7 @@ iterate (gpointer data) } static gboolean -start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gst_element_set_state (pipeline, GST_STATE_PAUSED); gtk_timeout_remove (update_id); @@ -176,7 +172,7 @@ start_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) } static gboolean -stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) { gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; gboolean res; @@ -188,8 +184,7 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) g_print ("seek to %lld 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); + GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, real); res = gst_element_send_event (seekable, s_event); @@ -199,7 +194,8 @@ stop_seek (GtkWidget *widget, GdkEventButton *event, gpointer user_data) 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); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); return FALSE; } @@ -211,7 +207,8 @@ play_cb (GtkButton * button, gpointer data) 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); + update_id = + gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); } } @@ -236,22 +233,23 @@ stop_cb (GtkButton * button, gpointer data) int main (int argc, char **argv) { - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, - *hscale; + 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 - }; + {"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); + 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); @@ -261,17 +259,18 @@ main (int argc, char **argv) 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)); + 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); + 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); @@ -283,9 +282,12 @@ main (int argc, char **argv) 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 (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. */ |