+2009-01-17 Tim-Philipp Müller <tim.muller at collabora co uk>
+
+ * gst/gstbus.c: (gst_bus_set_main_context), (gst_bus_create_watch):
+ Fix order of members in GstBusSource structure - the first member
+ must be the parent structure ie. GSource. Should make bus sources
+ attached to non-default main contexts work in all cases now (ie.
+ primarily in cases where the callback has a non-NULL user data
+ argument). Fixes #562170.
+
+ * tests/check/gst/gstbus.c: (test_custom_main_context):
+ Add unit test for the above, based on code by
+ Justin Karneges <justin at affinix com>.
+
2009-01-15 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Jonas Holmberg <jonas dot holmberg at axis dot com>
bus->priv->main_context = g_main_context_ref (ctx);
}
+ GST_DEBUG_OBJECT (bus, "setting main context to %p, GLib default context: %p",
+ ctx, g_main_context_default ());
+
GST_OBJECT_UNLOCK (bus);
}
*/
typedef struct
{
- gboolean inited;
GSource source;
GstBus *bus;
+ gboolean inited;
} GstBusSource;
static gboolean
source = (GstBusSource *) g_source_new (&gst_bus_source_funcs,
sizeof (GstBusSource));
source->bus = gst_object_ref (bus);
+ source->inited = FALSE;
return (GSource *) source;
}
GST_END_TEST;
+static gboolean
+cb_bus_call (GstBus * bus, GstMessage * msg, gpointer data)
+{
+ GMainLoop *loop = data;
+
+ switch (GST_MESSAGE_TYPE (msg)) {
+ case GST_MESSAGE_EOS:
+ {
+ GST_INFO ("End-of-stream");
+ g_main_loop_quit (loop);
+ break;
+ }
+ case GST_MESSAGE_ERROR:
+ {
+ GError *err = NULL;
+
+ gst_message_parse_error (msg, &err, NULL);
+ g_error ("Error: %s", err->message);
+ g_error_free (err);
+
+ g_main_loop_quit (loop);
+ break;
+ }
+ default:
+ {
+ GST_LOG ("BUS MESSAGE: type=%s", GST_MESSAGE_TYPE_NAME (msg));
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+GST_START_TEST (test_custom_main_context)
+{
+ GMainContext *ctx;
+ GMainLoop *loop;
+ GstElement *pipeline;
+ GstElement *src;
+ GstElement *sink;
+ GSource *source;
+ GstBus *bus;
+
+ ctx = g_main_context_new ();
+ loop = g_main_loop_new (ctx, FALSE);
+
+ pipeline = gst_pipeline_new (NULL);
+ src = gst_element_factory_make ("fakesrc", NULL);
+ g_object_set (src, "num-buffers", 2000, NULL);
+
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ fail_unless (gst_bin_add (GST_BIN (pipeline), src));
+ fail_unless (gst_bin_add (GST_BIN (pipeline), sink));
+ fail_unless (gst_element_link (src, sink));
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ source = gst_bus_create_watch (bus);
+ g_source_attach (source, ctx);
+ g_source_set_callback (source, (GSourceFunc) cb_bus_call, loop, NULL);
+ gst_object_unref (bus);
+
+ GST_INFO ("starting pipeline");
+
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
+
+ GST_INFO ("running event loop, ctx=%p", ctx);
+ g_main_loop_run (loop);
+
+ /* clean up */
+ if (ctx)
+ g_main_context_unref (ctx);
+ g_main_loop_unref (loop);
+}
+
+GST_END_TEST;
+
static Suite *
gst_bus_suite (void)
{
tcase_add_test (tc_chain, test_timed_pop_thread);
tcase_add_test (tc_chain, test_timed_pop_filtered);
tcase_add_test (tc_chain, test_timed_pop_filtered_with_timeout);
+ tcase_add_test (tc_chain, test_custom_main_context);
return s;
}