3 static GMainLoop *loop;
6 my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
8 g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message));
10 switch (GST_MESSAGE_TYPE (message)) {
11 case GST_MESSAGE_ERROR:{
15 gst_message_parse_error (message, &err, &debug);
16 g_print ("Error: %s\n", err->message);
20 g_main_loop_quit (loop);
25 g_main_loop_quit (loop);
28 /* unhandled message */
32 /* we want to be notified again the next time there is a message
33 * on the bus, so returning TRUE (FALSE means we want to stop watching
34 * for messages on the bus and our callback should not be called again)
40 main (gint argc, gchar * argv[])
47 gst_init (&argc, &argv);
49 /* create pipeline, add handler */
50 pipeline = gst_pipeline_new ("my_pipeline");
52 /* adds a watch for new message on our pipeline's message bus to
53 * the default GLib main context, which is the main context that our
54 * GLib main loop is attached to below
56 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
57 bus_watch_id = gst_bus_add_watch (bus, my_bus_callback, NULL);
58 gst_object_unref (bus);
62 /* create a mainloop that runs/iterates the default GLib main context
63 * (context NULL), in other words: makes the context check if anything
64 * it watches for has happened. When a message has been posted on the
65 * bus, the default main context will automatically call our
66 * my_bus_callback() function to notify us of that message.
67 * The main loop will be run until someone calls g_main_loop_quit()
69 loop = g_main_loop_new (NULL, FALSE);
70 g_main_loop_run (loop);
73 gst_element_set_state (pipeline, GST_STATE_NULL);
74 gst_object_unref (pipeline);
75 g_source_remove (bus_watch_id);
76 g_main_loop_unref (loop);