From: Sebastian Dröge Date: Thu, 7 Apr 2011 09:19:57 +0000 (+0200) Subject: bus: Use a construct-only property to distinguish between child buses and normal... X-Git-Tag: RELEASE-0.10.33~227 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c41b0ade28790ffdb0e484b41cd7929c4e145dec;p=platform%2Fupstream%2Fgstreamer.git bus: Use a construct-only property to distinguish between child buses and normal buses This allows to only create the socketpair when it is really required instead of always creating it and immediately destroying it again for child buses. https://bugzilla.gnome.org/show_bug.cgi?id=647005 --- diff --git a/gst/gst_private.h b/gst/gst_private.h index 487a547..da8a50a 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -51,9 +51,6 @@ 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 */ @@ -139,11 +136,6 @@ 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 ee8c98b..d4375f8 100644 --- a/gst/gstbin.c +++ b/gst/gstbin.c @@ -540,12 +540,11 @@ gst_bin_init (GstBin * bin, GstBinClass * klass) bin->clock_dirty = FALSE; /* Set up a bus for listening to child elements */ - bus = gst_bus_new (); + bus = g_object_new (GST_TYPE_BUS, "enable-async", FALSE, NULL); bin->child_bus = bus; 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 e2d6220..c102fb9 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -89,6 +89,14 @@ enum LAST_SIGNAL }; +#define DEFAULT_ENABLE_ASYNC (TRUE) + +enum +{ + PROP_0, + PROP_ENABLE_ASYNC +}; + static void gst_bus_dispose (GObject * object); static GstObjectClass *parent_class = NULL; @@ -100,6 +108,7 @@ struct _GstBusPrivate GCond *queue_cond; GSource *watch_id; + gboolean enable_async; GstPoll *poll; GPollFD pollfd; }; @@ -135,6 +144,33 @@ marshal_VOID__MINIOBJECT (GClosure * closure, GValue * return_value, } static void +gst_bus_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec) +{ + GstBus *bus = GST_BUS_CAST (object); + + switch (prop_id) { + case PROP_ENABLE_ASYNC: + bus->priv->enable_async = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_bus_constructed (GObject * object) +{ + GstBus *bus = GST_BUS_CAST (object); + + if (bus->priv->enable_async) { + bus->priv->poll = gst_poll_new_timer (); + gst_poll_get_read_gpollfd (bus->priv->poll, &bus->priv->pollfd); + } +} + +static void gst_bus_class_init (GstBusClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; @@ -142,6 +178,25 @@ gst_bus_class_init (GstBusClass * klass) parent_class = g_type_class_peek_parent (klass); gobject_class->dispose = gst_bus_dispose; + gobject_class->set_property = gst_bus_set_property; + gobject_class->constructed = gst_bus_constructed; + + /* GstBus:enable-async: + * + * Enable async message delivery support for bus watches, + * gst_bus_pop() and similar API. Without this only the + * synchronous message handlers are called. + * + * This property is used to create the child element buses + * in #GstBin. + * + * Since: 0.10.33 + */ + g_object_class_install_property (gobject_class, PROP_ENABLE_ASYNC, + g_param_spec_boolean ("enable-async", "Enable Async", + "Enable async message delivery for bus watches and gst_bus_pop()", + DEFAULT_ENABLE_ASYNC, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); /** * GstBus::sync-message: @@ -191,8 +246,7 @@ gst_bus_init (GstBus * bus) bus->priv = G_TYPE_INSTANCE_GET_PRIVATE (bus, GST_TYPE_BUS, GstBusPrivate); bus->priv->queue_cond = g_cond_new (); - bus->priv->poll = gst_poll_new_timer (); - gst_poll_get_read_gpollfd (bus->priv->poll, &bus->priv->pollfd); + bus->priv->enable_async = DEFAULT_ENABLE_ASYNC; GST_DEBUG_OBJECT (bus, "created"); } @@ -1285,14 +1339,3 @@ 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; -}