3 * stepping.c: stepping sample application
5 * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
28 static GMainLoop *loop;
30 static gdouble period = 0.0;
33 do_step (GstElement * bin)
37 length = sin (period);
42 length *= 100 * GST_MSECOND;
44 gst_element_send_event (bin,
45 gst_event_new_step (GST_FORMAT_TIME, length, 1.0, TRUE, FALSE));
51 handle_message (GstBus * bus, GstMessage * message, gpointer data)
53 GstElement *bin = GST_ELEMENT_CAST (data);
55 switch (message->type) {
57 g_message ("got EOS");
58 g_main_loop_quit (loop);
60 case GST_MESSAGE_WARNING:
61 case GST_MESSAGE_ERROR:
66 if (message->type == GST_MESSAGE_ERROR)
67 gst_message_parse_error (message, &gerror, &debug);
69 gst_message_parse_warning (message, &gerror, &debug);
71 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
72 g_error_free (gerror);
74 g_main_loop_quit (loop);
77 case GST_MESSAGE_ASYNC_DONE:
78 g_timeout_add (40, (GSourceFunc) do_step, bin);
87 main (int argc, char *argv[])
92 gst_init (&argc, &argv);
95 g_print ("usage: %s <uri>\n", argv[0]);
99 /* create a new bin to hold the elements */
100 bin = gst_element_factory_make ("playbin2", "bin");
102 g_object_set (bin, "uri", argv[1], NULL);
104 bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
105 gst_bus_add_watch (bus, handle_message, bin);
107 /* go to the PAUSED state and wait for preroll */
108 g_message ("prerolling first frame");
109 gst_element_set_state (bin, GST_STATE_PAUSED);
110 gst_element_get_state (bin, NULL, NULL, -1);
112 loop = g_main_loop_new (NULL, TRUE);
113 g_main_loop_run (loop);
115 g_message ("finished");
118 gst_element_set_state (bin, GST_STATE_NULL);
120 g_main_loop_unref (loop);
121 gst_object_unref (bus);