From 874d60e5899dd5b89854679d1a4ad016a58ba4e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 6 Apr 2011 14:06:49 +0200 Subject: [PATCH] bus: Add private API to set a GstBus in child mode This is used by GstBin to create a child bus without a socketpair because child buses will always work synchronous. Otherwise too many sockets could be created and the limit of file descriptors for the process could be reached. Fixes bug #646624. --- gst/gst_private.h | 9 ++++++++- gst/gstbin.c | 1 + gst/gstbus.c | 23 ++++++++++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/gst/gst_private.h b/gst/gst_private.h index 2cafbee..487a547 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -51,6 +51,9 @@ extern const char g_log_domain_gstreamer[]; /* for the pad cache */ #include "gstpad.h" +/* for GstBus */ +#include "gstbus.h" + G_BEGIN_DECLS /* used by gstparse.c and grammar.y */ @@ -123,7 +126,6 @@ gboolean priv_gst_structure_append_to_gstring (const GstStructure * structure, gboolean gst_registry_binary_read_cache (GstRegistry * registry, const char *location); gboolean gst_registry_binary_write_cache (GstRegistry * registry, const char *location); - /* used in gstvalue.c and gststructure.c */ #define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \ ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \ @@ -137,6 +139,11 @@ gint priv_gst_date_time_compare (gconstpointer dt1, gconstpointer dt2); extern gboolean _gst_disable_registry_cache; #endif +/* Secret API used by GstBin to set the bus in child bus mode + * without sockets and everything. See bug #646624. + */ +void _priv_gst_bus_set_child_mode (GstBus * bus); + /* provide inline gst_g_value_get_foo_unchecked(), used in gststructure.c */ #define DEFINE_INLINE_G_VALUE_GET_UNCHECKED(ret_type,name_type,v_field) \ static inline ret_type \ diff --git a/gst/gstbin.c b/gst/gstbin.c index 7375821..ee8c98b 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -545,6 +545,7 @@ gst_bin_init (GstBin * bin, GstBinClass * klass) GST_DEBUG_OBJECT (bin, "using bus %" GST_PTR_FORMAT " to listen to children", bus); gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bin_bus_handler, bin); + _priv_gst_bus_set_child_mode (bus); bin->priv = GST_BIN_GET_PRIVATE (bin); bin->priv->asynchandling = DEFAULT_ASYNC_HANDLING; diff --git a/gst/gstbus.c b/gst/gstbus.c index 78396f4..e2d6220 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -219,7 +219,9 @@ gst_bus_dispose (GObject * object) g_cond_free (bus->priv->queue_cond); bus->priv->queue_cond = NULL; - gst_poll_free (bus->priv->poll); + if (bus->priv->poll) + gst_poll_free (bus->priv->poll); + bus->priv->poll = NULL; } G_OBJECT_CLASS (parent_class)->dispose (object); @@ -301,7 +303,8 @@ gst_bus_post (GstBus * bus, GstMessage * message) /* pass the message to the async queue, refcount passed in the queue */ GST_DEBUG_OBJECT (bus, "[msg %p] pushing on async queue", message); gst_atomic_queue_push (bus->queue, message); - gst_poll_write_control (bus->priv->poll); + if (bus->priv->poll) + gst_poll_write_control (bus->priv->poll); GST_DEBUG_OBJECT (bus, "[msg %p] pushed on async queue", message); break; @@ -323,7 +326,8 @@ gst_bus_post (GstBus * bus, GstMessage * message) g_mutex_lock (lock); gst_atomic_queue_push (bus->queue, message); - gst_poll_write_control (bus->priv->poll); + if (bus->priv->poll) + gst_poll_write_control (bus->priv->poll); /* now block till the message is freed */ g_cond_wait (cond, lock); @@ -443,6 +447,7 @@ gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout, g_return_val_if_fail (GST_IS_BUS (bus), NULL); g_return_val_if_fail (types != 0, NULL); + g_return_val_if_fail (bus->priv->poll != NULL, NULL); g_mutex_lock (bus->queue_lock); @@ -765,6 +770,7 @@ gst_bus_create_watch (GstBus * bus) GstBusSource *source; g_return_val_if_fail (GST_IS_BUS (bus), NULL); + g_return_val_if_fail (bus->priv->poll != NULL, NULL); source = (GstBusSource *) g_source_new (&gst_bus_source_funcs, sizeof (GstBusSource)); @@ -1279,3 +1285,14 @@ error: return; } } + +/* Secret API used by GstBin to set the bus in child bus mode + * without sockets and everything. See bug #646624. + */ +void +_priv_gst_bus_set_child_mode (GstBus * bus) +{ + if (bus->priv->poll) + gst_poll_free (bus->priv->poll); + bus->priv->poll = NULL; +} -- 2.7.4