5 event_loop (GstElement * pipe)
8 GstMessage *message = NULL;
9 gboolean running = TRUE;
11 bus = gst_element_get_bus (GST_ELEMENT (pipe));
14 message = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_ANY);
16 g_assert (message != NULL);
18 switch (message->type) {
20 g_message ("got EOS");
23 case GST_MESSAGE_WARNING:{
27 gst_message_parse_warning (message, &gerror, &debug);
28 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
29 g_error_free (gerror);
33 case GST_MESSAGE_ERROR:
38 gst_message_parse_error (message, &gerror, &debug);
39 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
40 g_error_free (gerror);
45 case GST_MESSAGE_STEP_DONE:
50 gboolean flush, intermediate;
54 gst_message_parse_step_done (message, &format, &amount, &rate,
55 &flush, &intermediate, &duration, &eos);
57 if (format == GST_FORMAT_DEFAULT) {
58 g_message ("step done: %" GST_TIME_FORMAT " skipped in %"
59 G_GUINT64_FORMAT " frames", GST_TIME_ARGS (duration), amount);
61 g_message ("step done: %" GST_TIME_FORMAT " skipped",
62 GST_TIME_ARGS (duration));
69 gst_message_unref (message);
71 gst_object_unref (bus);
74 /* signalled when a new preroll buffer is available */
76 new_preroll (GstElement * appsink, gpointer user_data)
80 g_signal_emit_by_name (appsink, "pull-preroll", &buffer);
82 g_message ("have new-preroll buffer %p, timestamp %" GST_TIME_FORMAT, buffer,
83 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
85 gst_buffer_unref (buffer);
89 main (int argc, char *argv[])
91 GstElement *bin, *videotestsrc, *appsink;
94 gst_init (&argc, &argv);
96 /* create a new bin to hold the elements */
97 bin = gst_pipeline_new ("pipeline");
100 /* create a fake source */
101 videotestsrc = gst_element_factory_make ("videotestsrc", "videotestsrc");
102 g_assert (videotestsrc);
103 g_object_set (videotestsrc, "num-buffers", 10, NULL);
105 /* and a fake sink */
106 appsink = gst_element_factory_make ("appsink", "appsink");
108 g_object_set (appsink, "emit-signals", TRUE, NULL);
109 g_object_set (appsink, "sync", TRUE, NULL);
110 g_signal_connect (appsink, "new-preroll", (GCallback) new_preroll, NULL);
112 /* add objects to the main pipeline */
113 gst_bin_add (GST_BIN (bin), videotestsrc);
114 gst_bin_add (GST_BIN (bin), appsink);
116 /* link the elements */
117 gst_element_link_many (videotestsrc, appsink, NULL);
119 /* go to the PAUSED state and wait for preroll */
120 g_message ("prerolling first frame");
121 gst_element_set_state (bin, GST_STATE_PAUSED);
122 gst_element_get_state (bin, NULL, NULL, -1);
124 /* step two frames, flush so that new preroll is queued */
125 g_message ("stepping three frames");
126 g_assert (gst_element_send_event (bin,
127 gst_event_new_step (GST_FORMAT_BUFFERS, 2, 1.0, TRUE, FALSE)));
129 /* blocks and returns when we received the step done message */
132 /* wait for step to really complete */
133 gst_element_get_state (bin, NULL, NULL, -1);
135 gst_element_query_position (bin, GST_FORMAT_TIME, &pos);
136 g_message ("stepped two frames, now at %" GST_TIME_FORMAT,
137 GST_TIME_ARGS (pos));
139 /* step 3 frames, flush so that new preroll is queued */
140 g_message ("stepping 120 milliseconds ");
141 g_assert (gst_element_send_event (bin,
142 gst_event_new_step (GST_FORMAT_TIME, 120 * GST_MSECOND, 1.0, TRUE,
145 /* blocks and returns when we received the step done message */
148 /* wait for step to really complete */
149 gst_element_get_state (bin, NULL, NULL, -1);
151 gst_element_query_position (bin, GST_FORMAT_TIME, &pos);
152 g_message ("stepped 120ms frames, now at %" GST_TIME_FORMAT,
153 GST_TIME_ARGS (pos));
155 g_message ("playing until EOS");
156 gst_element_set_state (bin, GST_STATE_PLAYING);
157 /* Run event loop listening for bus messages until EOS or ERROR */
159 g_message ("finished");
162 gst_element_set_state (bin, GST_STATE_NULL);