bus: Add private API to set a GstBus in child mode
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 6 Apr 2011 12:06:49 +0000 (14:06 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 6 Apr 2011 12:18:35 +0000 (14:18 +0200)
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
gst/gstbin.c
gst/gstbus.c

index 2cafbee..487a547 100644 (file)
@@ -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                                                  \
index 7375821..ee8c98b 100644 (file)
@@ -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;
index 78396f4..e2d6220 100644 (file)
@@ -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;
+}