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)
43 gst_element_send_event (bin,
44 gst_event_new_step (GST_FORMAT_TIME, 40 * GST_MSECOND, rate, FALSE,
49 handle_sync_message (GstBus * bus, GstMessage * message, gpointer data)
53 bin = GST_ELEMENT_CAST (data);
55 switch (message->type) {
56 case GST_MESSAGE_STEP_DONE:
65 handle_message (GstBus * bus, GstMessage * message, gpointer data)
67 switch (message->type) {
69 g_message ("got EOS");
70 g_main_loop_quit (loop);
72 case GST_MESSAGE_WARNING:
73 case GST_MESSAGE_ERROR:
78 if (message->type == GST_MESSAGE_ERROR)
79 gst_message_parse_error (message, &gerror, &debug);
81 gst_message_parse_warning (message, &gerror, &debug);
83 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
84 g_error_free (gerror);
86 if (message->type == GST_MESSAGE_ERROR)
87 g_main_loop_quit (loop);
96 main (int argc, char *argv[])
101 gst_init (&argc, &argv);
104 g_print ("usage: %s <uri>\n", argv[0]);
108 /* create a new bin to hold the elements */
109 bin = gst_element_factory_make ("playbin2", "bin");
111 g_object_set (bin, "uri", argv[1], NULL);
113 bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
114 gst_bus_add_signal_watch (bus);
115 gst_bus_enable_sync_message_emission (bus);
117 g_signal_connect (bus, "message", (GCallback) handle_message, bin);
118 g_signal_connect (bus, "sync-message", (GCallback) handle_sync_message, bin);
120 /* go to the PAUSED state and wait for preroll */
121 g_message ("prerolling first frame");
122 gst_element_set_state (bin, GST_STATE_PAUSED);
123 gst_element_get_state (bin, NULL, NULL, -1);
128 gst_element_set_state (bin, GST_STATE_PLAYING);
130 loop = g_main_loop_new (NULL, TRUE);
131 g_main_loop_run (loop);
133 g_message ("finished");
136 gst_element_set_state (bin, GST_STATE_NULL);
138 g_main_loop_unref (loop);
139 gst_object_unref (bus);