From 4ff1d2085283f2eb0eac283a991f9a4c177bd2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 25 Aug 2006 16:46:09 +0000 Subject: [PATCH] docs/manual/basics-bus.xml: Docs update: fix wrong callback return value explanation; add some lines about the implic... Original commit message from CVS: * docs/manual/basics-bus.xml: Docs update: fix wrong callback return value explanation; add some lines about the implicit relationship between main loop and main context; remove duplicate main loop variable declaration. --- ChangeLog | 7 +++++++ docs/manual/basics-bus.xml | 27 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3731bd44b..2c9e1fbdb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-08-25 Tim-Philipp Müller + + * docs/manual/basics-bus.xml: + Docs update: fix wrong callback return value explanation; add + some lines about the implicit relationship between main loop + and main context; remove duplicate main loop variable declaration. + 2006-08-24 Tim-Philipp Müller * tests/check/gst/gstcaps.c: (GST_START_TEST): diff --git a/docs/manual/basics-bus.xml b/docs/manual/basics-bus.xml index 3035e17a80..580863bbdd 100644 --- a/docs/manual/basics-bus.xml +++ b/docs/manual/basics-bus.xml @@ -60,6 +60,8 @@ my_bus_callback (GstBus *bus, GstMessage *message, gpointer data) { + g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message)); + switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: { GError *err; @@ -82,7 +84,10 @@ my_bus_callback (GstBus *bus, break; } - /* remove message from the queue */ + /* we want to be notified again the next time there is a message + * on the bus, so returning TRUE (FALSE means we want to stop watching + * for messages on the bus and our callback should not be called again) + */ return TRUE; } @@ -90,7 +95,6 @@ gint main (gint argc, gchar *argv[]) { - GMainLoop *loop; GstElement *pipeline; GstBus *bus; @@ -99,17 +103,32 @@ main (gint argc, /* create pipeline, add handler */ pipeline = gst_pipeline_new ("my_pipeline"); + + /* adds a watch for new message on our pipeline's message bus to + * the default GLib main context, which is the main context that our + * GLib main loop is attached to below + */ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus, my_bus_callback, NULL); gst_object_unref (bus); [..] - /* in the mainloop, all messages posted to the bus by the pipeline - * will automatically be sent to our callback. */ + /* create a mainloop that runs/iterates the default GLib main context + * (context NULL), in other words: makes the context check if anything + * it watches for has happened. When a message has been posted on the + * bus, the default main context will automatically call our + * my_bus_callback() function to notify us of that message. + * The main loop will be run until someone calls g_main_loop_quit() + */ loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); + /* clean up */ + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_element_unref (pipeline); + gst_main_loop_unref (loop) + return 0; }