7 static GList *seekable_elements = NULL;
9 static GstElement *pipeline;
10 static GtkAdjustment *adjustment;
11 static gboolean stats = FALSE;
12 static guint64 duration;
14 static guint update_id;
16 #define UPDATE_INTERVAL 500
19 make_cdaudio_pipeline (void)
23 cdaudio = gst_element_factory_make ("cdaudio", "cdaudio");
24 g_assert (cdaudio != NULL);
26 seekable_elements = g_list_prepend (seekable_elements, cdaudio);
32 format_value (GtkScale * scale, gdouble value)
38 real = value * duration / 100;
39 seconds = (gint64) real / GST_SECOND;
40 subseconds = (gint64) real / (GST_SECOND / 100);
42 return g_strdup_printf ("%02lld:%02lld:%02lld",
43 seconds / 60, seconds % 60, subseconds % 100);
49 const GstFormat format;
52 static seek_format seek_formats[] = {
53 {"tim", GST_FORMAT_TIME},
54 {"byt", GST_FORMAT_BYTES},
55 {"buf", GST_FORMAT_BUFFERS},
56 {"def", GST_FORMAT_DEFAULT},
61 G_GNUC_UNUSED static void
64 GList *walk = seekable_elements;
67 GstElement *element = GST_ELEMENT (walk->data);
70 g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element));
71 while (seek_formats[i].name) {
76 format = seek_formats[i].format;
77 res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value);
79 g_print ("%s %13lld | ", seek_formats[i].name, value);
81 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
85 g_print (" %s\n", GST_ELEMENT_NAME (element));
86 walk = g_list_next (walk);
90 G_GNUC_UNUSED static void
93 GList *walk = seekable_elements;
96 GstElement *element = GST_ELEMENT (walk->data);
99 g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element));
100 while (seek_formats[i].name) {
105 format = seek_formats[i].format;
106 res = gst_element_query (element, GST_QUERY_POSITION, &format, &value);
108 g_print ("%s %13lld | ", seek_formats[i].name, value);
110 g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*");
114 g_print (" %s\n", GST_ELEMENT_NAME (element));
115 walk = g_list_next (walk);
120 update_scale (gpointer data)
123 guint64 position = 0;
124 GstFormat format = GST_FORMAT_TIME;
127 clock = gst_bin_get_clock (GST_BIN (pipeline));
129 if (seekable_elements) {
130 GstElement *element = GST_ELEMENT (seekable_elements->data);
132 gst_element_query (element, GST_QUERY_TOTAL, &format, &duration);
135 position = gst_clock_get_time (clock);
139 g_print ("clock: %13llu (%s)\n", position,
140 gst_object_get_name (GST_OBJECT (clock)));
145 gtk_adjustment_set_value (adjustment, position * 100.0 / duration);
152 iterate (gpointer data)
156 g_print ("iterate\n");
157 res = gst_bin_iterate (GST_BIN (data));
159 gtk_timeout_remove (update_id);
160 g_print ("stopping iterations\n");
166 start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
168 gst_element_set_state (pipeline, GST_STATE_PAUSED);
169 gtk_timeout_remove (update_id);
175 stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data)
177 gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100;
180 GList *walk = seekable_elements;
183 GstElement *seekable = GST_ELEMENT (walk->data);
185 g_print ("seek to %lld on element %s\n", real, GST_ELEMENT_NAME (seekable));
186 s_event = gst_event_new_seek (GST_FORMAT_TIME |
187 GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, real);
189 res = gst_element_send_event (seekable, s_event);
191 walk = g_list_next (walk);
194 gst_element_set_state (pipeline, GST_STATE_PLAYING);
195 if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
196 gtk_idle_add ((GtkFunction) iterate, pipeline);
198 gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
204 play_cb (GtkButton * button, gpointer data)
206 if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
207 gst_element_set_state (pipeline, GST_STATE_PLAYING);
208 if (!GST_FLAG_IS_SET (pipeline, GST_BIN_SELF_SCHEDULABLE))
209 gtk_idle_add ((GtkFunction) iterate, pipeline);
211 gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);
216 pause_cb (GtkButton * button, gpointer data)
218 if (gst_element_get_state (pipeline) != GST_STATE_PAUSED) {
219 gst_element_set_state (pipeline, GST_STATE_PAUSED);
220 gtk_timeout_remove (update_id);
225 stop_cb (GtkButton * button, gpointer data)
227 if (gst_element_get_state (pipeline) != GST_STATE_READY) {
228 gst_element_set_state (pipeline, GST_STATE_READY);
229 gtk_timeout_remove (update_id);
234 main (int argc, char **argv)
236 GtkWidget *window, *hbox, *vbox,
237 *play_button, *pause_button, *stop_button, *hscale;
238 struct poptOption options[] = {
239 {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0,
240 "Show element stats", NULL},
244 gst_init_with_popt_table (&argc, &argv, options);
245 gtk_init (&argc, &argv);
247 pipeline = make_cdaudio_pipeline ();
249 g_signal_connect (pipeline, "deep_notify",
250 G_CALLBACK (gst_element_default_deep_notify), NULL);
251 g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error),
254 /* initialize gui elements ... */
255 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
256 hbox = gtk_hbox_new (FALSE, 0);
257 vbox = gtk_vbox_new (FALSE, 0);
258 play_button = gtk_button_new_with_label ("play");
259 pause_button = gtk_button_new_with_label ("pause");
260 stop_button = gtk_button_new_with_label ("stop");
263 GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0));
264 hscale = gtk_hscale_new (adjustment);
265 gtk_scale_set_digits (GTK_SCALE (hscale), 2);
266 gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS);
268 gtk_signal_connect (GTK_OBJECT (hscale),
269 "button_press_event", G_CALLBACK (start_seek), pipeline);
270 gtk_signal_connect (GTK_OBJECT (hscale),
271 "button_release_event", G_CALLBACK (stop_seek), pipeline);
272 gtk_signal_connect (GTK_OBJECT (hscale),
273 "format_value", G_CALLBACK (format_value), pipeline);
275 /* do the packing stuff ... */
276 gtk_window_set_default_size (GTK_WINDOW (window), 96, 96);
277 gtk_container_add (GTK_CONTAINER (window), vbox);
278 gtk_container_add (GTK_CONTAINER (vbox), hbox);
279 gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2);
280 gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2);
281 gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2);
282 gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2);
284 /* connect things ... */
285 g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb),
287 g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb),
289 g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
291 g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL);
294 gtk_widget_show_all (window);
298 gst_element_set_state (pipeline, GST_STATE_NULL);