mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
gst/gstbus.c: Fix order of members in GstBusSource structure - the first member must be the parent structure ie. GSou...
Original commit message from CVS: * 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>.
This commit is contained in:
parent
732ff5f6fd
commit
0ee5e36cfb
3 changed files with 97 additions and 1 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
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>
|
||||
|
|
|
@ -325,6 +325,9 @@ gst_bus_set_main_context (GstBus * bus, GMainContext * ctx)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -767,9 +770,9 @@ no_replace:
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
gboolean inited;
|
||||
GSource source;
|
||||
GstBus *bus;
|
||||
gboolean inited;
|
||||
} GstBusSource;
|
||||
|
||||
static gboolean
|
||||
|
@ -888,6 +891,7 @@ gst_bus_create_watch (GstBus * bus)
|
|||
source = (GstBusSource *) g_source_new (&gst_bus_source_funcs,
|
||||
sizeof (GstBusSource));
|
||||
source->bus = gst_object_ref (bus);
|
||||
source->inited = FALSE;
|
||||
|
||||
return (GSource *) source;
|
||||
}
|
||||
|
|
|
@ -487,6 +487,84 @@ GST_START_TEST (test_timed_pop_thread)
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -504,6 +582,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue