X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstbus.c;h=df2351f3e94ea73a4e78f2a6145df3fa8dbbab6c;hb=a143d9cb0caee85bbe0c5e8b86e9f05918153c9d;hp=8f6de7e7324baa85c28be8b677e2ac748b922037;hpb=b95ceeb09b3534bfe1cb607e23f9b21adb3202ef;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstbus.c b/gst/gstbus.c index 8f6de7e..df2351f 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -15,12 +15,13 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /** * SECTION:gstbus + * @title: GstBus * @short_description: Asynchronous message bus subsystem * @see_also: #GstMessage, #GstElement * @@ -63,8 +64,6 @@ * * Note that a #GstPipeline will set its bus into flushing state when changing * from READY to NULL state. - * - * Last reviewed on 2006-03-12 (0.10.5) */ #include "gst_private.h" @@ -81,6 +80,12 @@ #include "gstbus.h" #include "glib-compat-private.h" +#ifdef G_OS_WIN32 +# ifndef EWOULDBLOCK +# define EWOULDBLOCK EAGAIN /* This is just to placate gcc */ +# endif +#endif /* G_OS_WIN32 */ + #define GST_CAT_DEFAULT GST_CAT_BUS /* bus signals */ enum @@ -100,6 +105,7 @@ enum }; static void gst_bus_dispose (GObject * object); +static void gst_bus_finalize (GObject * object); static guint gst_bus_signals[LAST_SIGNAL] = { 0 }; @@ -110,12 +116,12 @@ struct _GstBusPrivate GstBusSyncHandler sync_handler; gpointer sync_handler_data; + GDestroyNotify sync_handler_notify; - guint signal_watch_id; guint num_signal_watchers; guint num_sync_message_emitters; - GSource *watch_id; + GSource *signal_watch; gboolean enable_async; GstPoll *poll; @@ -123,7 +129,7 @@ struct _GstBusPrivate }; #define gst_bus_parent_class parent_class -G_DEFINE_TYPE (GstBus, gst_bus, GST_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_PRIVATE (GstBus, gst_bus, GST_TYPE_OBJECT); static void gst_bus_set_property (GObject * object, @@ -150,6 +156,8 @@ gst_bus_constructed (GObject * object) bus->priv->poll = gst_poll_new_timer (); gst_poll_get_read_gpollfd (bus->priv->poll, &bus->priv->pollfd); } + + G_OBJECT_CLASS (gst_bus_parent_class)->constructed (object); } static void @@ -158,10 +166,12 @@ gst_bus_class_init (GstBusClass * klass) GObjectClass *gobject_class = (GObjectClass *) klass; gobject_class->dispose = gst_bus_dispose; + gobject_class->finalize = gst_bus_finalize; gobject_class->set_property = gst_bus_set_property; gobject_class->constructed = gst_bus_constructed; - /* GstBus:enable-async: + /** + * GstBus::enable-async: * * Enable async message delivery support for bus watches, * gst_bus_pop() and similar API. Without this only the @@ -169,8 +179,6 @@ gst_bus_class_init (GstBusClass * klass) * * 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", @@ -186,18 +194,14 @@ gst_bus_class_init (GstBusClass * klass) * A message has been posted on the bus. This signal is emitted from the * thread that posted the message so one has to be careful with locking. * - * This signal will not be emitted by default, you have to set up - * gst_bus_sync_signal_handler() as a sync handler if you want this - * signal to be emitted when a message is posted on the bus, like this: - * - * gst_bus_set_sync_handler (bus, gst_bus_sync_signal_handler, yourdata); - * + * This signal will not be emitted by default, you have to call + * gst_bus_enable_sync_message_emission() before. */ gst_bus_signals[SYNC_MESSAGE] = g_signal_new ("sync-message", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, G_STRUCT_OFFSET (GstBusClass, sync_message), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_MESSAGE); + g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_MESSAGE); /** * GstBus::message: @@ -212,15 +216,13 @@ gst_bus_class_init (GstBusClass * klass) g_signal_new ("message", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, G_STRUCT_OFFSET (GstBusClass, message), NULL, NULL, - g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_MESSAGE); - - g_type_class_add_private (klass, sizeof (GstBusPrivate)); + g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_MESSAGE); } static void gst_bus_init (GstBus * bus) { - bus->priv = G_TYPE_INSTANCE_GET_PRIVATE (bus, GST_TYPE_BUS, GstBusPrivate); + bus->priv = gst_bus_get_instance_private (bus); bus->priv->enable_async = DEFAULT_ENABLE_ASYNC; g_mutex_init (&bus->priv->queue_lock); bus->priv->queue = gst_atomic_queue_new (32); @@ -255,6 +257,17 @@ gst_bus_dispose (GObject * object) G_OBJECT_CLASS (parent_class)->dispose (object); } +static void +gst_bus_finalize (GObject * object) +{ + GstBus *bus = GST_BUS (object); + + if (bus->priv->sync_handler_notify) + bus->priv->sync_handler_notify (bus->priv->sync_handler_data); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + /** * gst_bus_new: * @@ -267,9 +280,12 @@ gst_bus_new (void) { GstBus *result; - result = g_object_newv (gst_bus_get_type (), 0, NULL); + result = g_object_new (gst_bus_get_type (), NULL); GST_DEBUG_OBJECT (result, "created new bus"); + /* clear floating flag */ + gst_object_ref_sink (result); + return result; } @@ -281,7 +297,7 @@ gst_bus_new (void) * Post a message on the given bus. Ownership of the message * is taken by the bus. * - * Returns: TRUE if the message could be posted, FALSE if the bus is flushing. + * Returns: %TRUE if the message could be posted, %FALSE if the bus is flushing. * * MT safe. */ @@ -299,6 +315,10 @@ gst_bus_post (GstBus * bus, GstMessage * message) GST_DEBUG_OBJECT (bus, "[msg %p] posting on bus %" GST_PTR_FORMAT, message, message); + /* check we didn't accidentally add a public flag that maps to same value */ + g_assert (!GST_MINI_OBJECT_FLAG_IS_SET (message, + GST_MESSAGE_FLAG_ASYNC_DELIVERY)); + GST_OBJECT_LOCK (bus); /* check if the bus is flushing */ if (GST_OBJECT_FLAG_IS_SET (bus, GST_BUS_FLUSHING)) @@ -348,6 +368,8 @@ gst_bus_post (GstBus * bus, GstMessage * message) g_cond_init (cond); g_mutex_init (lock); + GST_MINI_OBJECT_FLAG_SET (message, GST_MESSAGE_FLAG_ASYNC_DELIVERY); + GST_DEBUG_OBJECT (bus, "[msg %p] waiting for async delivery", message); /* now we lock the message mutex, send the message to the async @@ -360,12 +382,18 @@ gst_bus_post (GstBus * bus, GstMessage * message) /* now block till the message is freed */ g_cond_wait (cond, lock); + + /* we acquired a new ref from gst_message_dispose() so we can clean up */ g_mutex_unlock (lock); GST_DEBUG_OBJECT (bus, "[msg %p] delivered asynchronously", message); + GST_MINI_OBJECT_FLAG_UNSET (message, GST_MESSAGE_FLAG_ASYNC_DELIVERY); + g_mutex_clear (lock); g_cond_clear (cond); + + gst_message_unref (message); break; } default: @@ -378,8 +406,8 @@ gst_bus_post (GstBus * bus, GstMessage * message) is_flushing: { GST_DEBUG_OBJECT (bus, "bus is flushing"); - gst_message_unref (message); GST_OBJECT_UNLOCK (bus); + gst_message_unref (message); return FALSE; } @@ -392,7 +420,7 @@ is_flushing: * Check if there are pending messages on the bus that * should be handled. * - * Returns: TRUE if there are messages on the bus to be handled, FALSE + * Returns: %TRUE if there are messages on the bus to be handled, %FALSE * otherwise. * * MT safe. @@ -417,7 +445,7 @@ gst_bus_have_pending (GstBus * bus) * * If @flushing, flush out and unref any messages queued in the bus. Releases * references to the message origin objects. Will flush future messages until - * gst_bus_set_flushing() sets @flushing to #FALSE. + * gst_bus_set_flushing() sets @flushing to %FALSE. * * MT safe. */ @@ -425,6 +453,9 @@ void gst_bus_set_flushing (GstBus * bus, gboolean flushing) { GstMessage *message; + GList *message_list = NULL; + + g_return_if_fail (GST_IS_BUS (bus)); GST_OBJECT_LOCK (bus); @@ -434,13 +465,15 @@ gst_bus_set_flushing (GstBus * bus, gboolean flushing) GST_DEBUG_OBJECT (bus, "set bus flushing"); while ((message = gst_bus_pop (bus))) - gst_message_unref (message); + message_list = g_list_prepend (message_list, message); } else { GST_DEBUG_OBJECT (bus, "unset bus flushing"); GST_OBJECT_FLAG_UNSET (bus, GST_BUS_FLUSHING); } GST_OBJECT_UNLOCK (bus); + + g_list_free_full (message_list, (GDestroyNotify) gst_message_unref); } /** @@ -457,14 +490,13 @@ gst_bus_set_flushing (GstBus * bus, gboolean flushing) * @timeout is #GST_CLOCK_TIME_NONE, this function will block forever until a * matching message was posted on the bus. * - * Returns: (transfer full): a #GstMessage matching the filter in @types, - * or NULL if no matching message was found on the bus until the timeout - * expired. The message is taken from the bus and needs to be unreffed - * with gst_message_unref() after usage. + * Returns: (transfer full) (nullable): a #GstMessage matching the + * filter in @types, or %NULL if no matching message was found on + * the bus until the timeout expired. The message is taken from + * the bus and needs to be unreffed with gst_message_unref() after + * usage. * * MT safe. - * - * Since: 0.10.15 */ GstMessage * gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout, @@ -488,20 +520,41 @@ gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout, gst_atomic_queue_length (bus->priv->queue)); while ((message = gst_atomic_queue_pop (bus->priv->queue))) { - if (bus->priv->poll) - gst_poll_read_control (bus->priv->poll); + if (bus->priv->poll) { + while (!gst_poll_read_control (bus->priv->poll)) { + if (errno == EWOULDBLOCK) { + /* Retry, this can happen if pushing to the queue has finished, + * popping here succeeded but writing control did not finish + * before we got to this line. */ + /* Give other threads the chance to do something */ + g_thread_yield (); + continue; + } else { + /* This is a real error and means that either the bus is in an + * inconsistent state, or the GstPoll is invalid. GstPoll already + * prints a critical warning about this, no need to do that again + * ourselves */ + break; + } + } + } GST_DEBUG_OBJECT (bus, "got message %p, %s from %s, type mask is %u", message, GST_MESSAGE_TYPE_NAME (message), GST_MESSAGE_SRC_NAME (message), (guint) types); if ((GST_MESSAGE_TYPE (message) & types) != 0) { - /* exit the loop, we have a message */ - goto beach; - } else { - GST_DEBUG_OBJECT (bus, "discarding message, does not match mask"); - gst_message_unref (message); - message = NULL; + /* Extra check to ensure extended types don't get matched unless + * asked for */ + if ((!GST_MESSAGE_TYPE_IS_EXTENDED (message)) + || (types & GST_MESSAGE_EXTENDED)) { + /* exit the loop, we have a message */ + goto beach; + } } + + GST_DEBUG_OBJECT (bus, "discarding message, does not match mask"); + gst_message_unref (message); + message = NULL; } /* no need to wait, exit loop */ @@ -555,14 +608,12 @@ beach: * #GST_CLOCK_TIME_NONE, this function will block forever until a message was * posted on the bus. * - * Returns: (transfer full): the #GstMessage that is on the bus after the - * specified timeout or NULL if the bus is empty after the timeout expired. - * The message is taken from the bus and needs to be unreffed with - * gst_message_unref() after usage. + * Returns: (transfer full) (nullable): the #GstMessage that is on the + * bus after the specified timeout or %NULL if the bus is empty + * after the timeout expired. The message is taken from the bus + * and needs to be unreffed with gst_message_unref() after usage. * * MT safe. - * - * Since: 0.10.12 */ GstMessage * gst_bus_timed_pop (GstBus * bus, GstClockTime timeout) @@ -580,16 +631,15 @@ gst_bus_timed_pop (GstBus * bus, GstClockTime timeout) * Get a message matching @type from the bus. Will discard all messages on * the bus that do not match @type and that have been posted before the first * message that does match @type. If there is no message matching @type on - * the bus, all messages will be discarded. + * the bus, all messages will be discarded. It is not possible to use message + * enums beyond #GST_MESSAGE_EXTENDED in the @events mask. * - * Returns: (transfer full): the next #GstMessage matching @type that is on - * the bus, or NULL if the bus is empty or there is no message matching - * @type. The message is taken from the bus and needs to be unreffed with - * gst_message_unref() after usage. + * Returns: (transfer full) (nullable): the next #GstMessage matching + * @type that is on the bus, or %NULL if the bus is empty or there + * is no message matching @type. The message is taken from the bus + * and needs to be unreffed with gst_message_unref() after usage. * * MT safe. - * - * Since: 0.10.15 */ GstMessage * gst_bus_pop_filtered (GstBus * bus, GstMessageType types) @@ -606,9 +656,10 @@ gst_bus_pop_filtered (GstBus * bus, GstMessageType types) * * Get a message from the bus. * - * Returns: (transfer full): the #GstMessage that is on the bus, or NULL if the - * bus is empty. The message is taken from the bus and needs to be unreffed - * with gst_message_unref() after usage. + * Returns: (transfer full) (nullable): the #GstMessage that is on the + * bus, or %NULL if the bus is empty. The message is taken from + * the bus and needs to be unreffed with gst_message_unref() after + * usage. * * MT safe. */ @@ -628,8 +679,8 @@ gst_bus_pop (GstBus * bus) * on the bus' message queue. A reference is returned, and needs to be unreffed * by the caller. * - * Returns: (transfer full): the #GstMessage that is on the bus, or NULL if the - * bus is empty. + * Returns: (transfer full) (nullable): the #GstMessage that is on the + * bus, or %NULL if the bus is empty. * * MT safe. */ @@ -654,8 +705,9 @@ gst_bus_peek (GstBus * bus) /** * gst_bus_set_sync_handler: * @bus: a #GstBus to install the handler on - * @func: The handler function to install - * @data: User data that will be sent to the handler function. + * @func: (allow-none): The handler function to install + * @user_data: User data that will be sent to the handler function. + * @notify: called when @user_data becomes unused * * Sets the synchronous handler on the bus. The function will be called * every time a new message is posted on the bus. Note that the function @@ -664,23 +716,37 @@ gst_bus_peek (GstBus * bus) * should handle messages asynchronously using the gst_bus watch and poll * functions. * - * You cannot replace an existing sync_handler. You can pass NULL to this + * You cannot replace an existing sync_handler. You can pass %NULL to this * function, which will clear the existing handler. */ void -gst_bus_set_sync_handler (GstBus * bus, GstBusSyncHandler func, gpointer data) +gst_bus_set_sync_handler (GstBus * bus, GstBusSyncHandler func, + gpointer user_data, GDestroyNotify notify) { + GDestroyNotify old_notify; + g_return_if_fail (GST_IS_BUS (bus)); GST_OBJECT_LOCK (bus); - /* Assert if the user attempts to replace an existing sync_handler, * other than to clear it */ if (func != NULL && bus->priv->sync_handler != NULL) goto no_replace; + if ((old_notify = bus->priv->sync_handler_notify)) { + gpointer old_data = bus->priv->sync_handler_data; + + bus->priv->sync_handler_data = NULL; + bus->priv->sync_handler_notify = NULL; + GST_OBJECT_UNLOCK (bus); + + old_notify (old_data); + + GST_OBJECT_LOCK (bus); + } bus->priv->sync_handler = func; - bus->priv->sync_handler_data = data; + bus->priv->sync_handler_data = user_data; + bus->priv->sync_handler_notify = notify; GST_OBJECT_UNLOCK (bus); return; @@ -693,6 +759,31 @@ no_replace: } } +/** + * gst_bus_get_pollfd: + * @bus: A #GstBus + * @fd: (out): A GPollFD to fill + * + * Gets the file descriptor from the bus which can be used to get notified about + * messages being available with functions like g_poll(), and allows integration + * into other event loops based on file descriptors. + * Whenever a message is available, the POLLIN / %G_IO_IN event is set. + * + * Warning: NEVER read or write anything to the returned fd but only use it + * for getting notifications via g_poll() or similar and then use the normal + * GstBus API, e.g. gst_bus_pop(). + * + * Since: 1.14 + */ +void +gst_bus_get_pollfd (GstBus * bus, GPollFD * fd) +{ + g_return_if_fail (GST_IS_BUS (bus)); + g_return_if_fail (bus->priv->poll != NULL); + + *fd = bus->priv->pollfd; +} + /* GSource for the bus */ typedef struct @@ -772,8 +863,8 @@ gst_bus_source_finalize (GSource * source) GST_DEBUG_OBJECT (bus, "finalize source %p", source); GST_OBJECT_LOCK (bus); - if (bus->priv->watch_id == source) - bus->priv->watch_id = NULL; + if (bus->priv->signal_watch == source) + bus->priv->signal_watch = NULL; GST_OBJECT_UNLOCK (bus); gst_object_unref (bsource->bus); @@ -795,7 +886,7 @@ static GSourceFuncs gst_bus_source_funcs = { * a message is on the bus. After the GSource is dispatched, the * message is popped off the bus and unreffed. * - * Returns: (transfer full): a #GSource that can be added to a mainloop. + * Returns: (transfer full) (nullable): a #GSource that can be added to a mainloop. */ GSource * gst_bus_create_watch (GstBus * bus) @@ -825,13 +916,17 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, guint id; GSource *source; - if (bus->priv->watch_id) { + if (bus->priv->signal_watch) { GST_ERROR_OBJECT (bus, "Tried to add new watch while one was already there"); return 0; } source = gst_bus_create_watch (bus); + if (!source) { + g_critical ("Creating bus watch failed"); + return 0; + } if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); @@ -843,7 +938,7 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, g_source_unref (source); if (id) { - bus->priv->watch_id = source; + bus->priv->signal_watch = source; } GST_DEBUG_OBJECT (bus, "New source %p with id %u", source, id); @@ -851,7 +946,7 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, } /** - * gst_bus_add_watch_full: + * gst_bus_add_watch_full: (rename-to gst_bus_add_watch) * @bus: a #GstBus to create the watch for. * @priority: The priority of the watch. * @func: A function to call when a message is received. @@ -859,8 +954,8 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, * @notify: the function to call when the source is removed. * * Adds a bus watch to the default main context with the given @priority (e.g. - * %G_PRIORITY_DEFAULT). Since 0.10.33 it is also possible to use a non-default - * main context set up using g_main_context_push_thread_default() (before + * %G_PRIORITY_DEFAULT). It is also possible to use a non-default main + * context set up using g_main_context_push_thread_default() (before * one had to create a bus watch source and attach it to the desired main * context 'manually'). * @@ -868,15 +963,21 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, * There can only be a single bus watch per bus, you must remove it before you * can set a new one. * + * The bus watch will only work if a GLib main loop is being run. + * * When @func is called, the message belongs to the caller; if you want to * keep a copy of it, call gst_message_ref() before leaving @func. * - * The watch can be removed using g_source_remove() or by returning FALSE - * from @func. + * The watch can be removed using gst_bus_remove_watch() or by returning %FALSE + * from @func. If the watch was added to the default main context it is also + * possible to remove the watch using g_source_remove(). + * + * The bus watch will take its own reference to the @bus, so it is safe to unref + * @bus using gst_object_unref() after setting the bus watch. * - * Returns: The event source id. - * Rename to: gst_bus_add_watch * MT safe. + * + * Returns: The event source id or 0 if @bus already got an event source. */ guint gst_bus_add_watch_full (GstBus * bus, gint priority, @@ -900,8 +1001,8 @@ gst_bus_add_watch_full (GstBus * bus, gint priority, * @user_data: user data passed to @func. * * Adds a bus watch to the default main context with the default priority - * (%G_PRIORITY_DEFAULT). Since 0.10.33 it is also possible to use a non-default - * main context set up using g_main_context_push_thread_default() (before + * (%G_PRIORITY_DEFAULT). It is also possible to use a non-default main + * context set up using g_main_context_push_thread_default() (before * one had to create a bus watch source and attach it to the desired main * context 'manually'). * @@ -909,12 +1010,18 @@ gst_bus_add_watch_full (GstBus * bus, gint priority, * There can only be a single bus watch per bus, you must remove it before you * can set a new one. * - * The watch can be removed using g_source_remove() or by returning FALSE - * from @func. + * The bus watch will only work if a GLib main loop is being run. + * + * The watch can be removed using gst_bus_remove_watch() or by returning %FALSE + * from @func. If the watch was added to the default main context it is also + * possible to remove the watch using g_source_remove(). * - * Returns: The event source id. + * The bus watch will take its own reference to the @bus, so it is safe to unref + * @bus using gst_object_unref() after setting the bus watch. * * MT safe. + * + * Returns: The event source id or 0 if @bus already got an event source. */ guint gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data) @@ -923,6 +1030,45 @@ gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data) user_data, NULL); } +/** + * gst_bus_remove_watch: + * @bus: a #GstBus to remove the watch from. + * + * Removes an installed bus watch from @bus. + * + * Returns: %TRUE on success or %FALSE if @bus has no event source. + * + * Since: 1.6 + * + */ +gboolean +gst_bus_remove_watch (GstBus * bus) +{ + GSource *watch_id; + + g_return_val_if_fail (GST_IS_BUS (bus), FALSE); + + GST_OBJECT_LOCK (bus); + + if (bus->priv->signal_watch == NULL) { + GST_ERROR_OBJECT (bus, "no bus watch was present"); + goto no_watch; + } + + watch_id = bus->priv->signal_watch; + + GST_OBJECT_UNLOCK (bus); + + g_source_destroy (watch_id); + + return TRUE; + +no_watch: + GST_OBJECT_UNLOCK (bus); + + return FALSE; +} + typedef struct { GMainLoop *loop; @@ -990,8 +1136,8 @@ poll_destroy_timeout (GstBusPollData * poll_data) * gst_bus_poll: * @bus: a #GstBus * @events: a mask of #GstMessageType, representing the set of message types to - * poll for. - * @timeout: the poll timeout, as a #GstClockTimeDiff, or -1 to poll + * poll for (note special handling of extended message types below) + * @timeout: the poll timeout, as a #GstClockTime, or #GST_CLOCK_TIME_NONE to poll * indefinitely. * * Poll the bus for messages. Will block while waiting for messages to come. @@ -999,6 +1145,8 @@ poll_destroy_timeout (GstBusPollData * poll_data) * @timeout is negative, this function will block indefinitely. * * All messages not in @events will be popped off the bus and will be ignored. + * It is not possible to use message enums beyond #GST_MESSAGE_EXTENDED in the + * @events mask * * Because poll is implemented using the "message" signal enabled by * gst_bus_add_signal_watch(), calling gst_bus_poll() will cause the "message" @@ -1026,24 +1174,27 @@ poll_destroy_timeout (GstBusPollData * poll_data) * better handled by setting up an asynchronous bus watch and doing things * from there. * - * Returns: (transfer full): the message that was received, or NULL if the - * poll timed out. The message is taken from the bus and needs to be - * unreffed with gst_message_unref() after usage. + * Returns: (transfer full) (nullable): the message that was received, + * or %NULL if the poll timed out. The message is taken from the + * bus and needs to be unreffed with gst_message_unref() after + * usage. */ GstMessage * -gst_bus_poll (GstBus * bus, GstMessageType events, GstClockTimeDiff timeout) +gst_bus_poll (GstBus * bus, GstMessageType events, GstClockTime timeout) { GstBusPollData *poll_data; GstMessage *ret; gulong id; + g_return_val_if_fail (GST_IS_BUS (bus), NULL); + poll_data = g_slice_new (GstBusPollData); poll_data->source_running = TRUE; poll_data->loop = g_main_loop_new (NULL, FALSE); poll_data->events = events; poll_data->message = NULL; - if (timeout >= 0) + if (timeout != GST_CLOCK_TIME_NONE) poll_data->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, timeout / GST_MSECOND, (GSourceFunc) poll_timeout, poll_data, (GDestroyNotify) poll_destroy_timeout); @@ -1085,7 +1236,7 @@ gst_bus_poll (GstBus * bus, GstMessageType events, GstClockTimeDiff timeout) * A helper #GstBusFunc that can be used to convert all asynchronous messages * into signals. * - * Returns: TRUE + * Returns: %TRUE */ gboolean gst_bus_async_signal_func (GstBus * bus, GstMessage * message, gpointer data) @@ -1182,7 +1333,7 @@ void gst_bus_disable_sync_message_emission (GstBus * bus) { g_return_if_fail (GST_IS_BUS (bus)); - g_return_if_fail (bus->priv->num_signal_watchers == 0); + g_return_if_fail (bus->priv->num_sync_message_emitters > 0); GST_OBJECT_LOCK (bus); bus->priv->num_sync_message_emitters--; @@ -1195,8 +1346,8 @@ gst_bus_disable_sync_message_emission (GstBus * bus) * @priority: The priority of the watch. * * Adds a bus signal watch to the default main context with the given @priority - * (e.g. %G_PRIORITY_DEFAULT). Since 0.10.33 it is also possible to use a - * non-default main context set up using g_main_context_push_thread_default() + * (e.g. %G_PRIORITY_DEFAULT). It is also possible to use a non-default main + * context set up using g_main_context_push_thread_default() * (before one had to create a bus watch source and attach it to the desired * main context 'manually'). * @@ -1224,13 +1375,12 @@ gst_bus_add_signal_watch_full (GstBus * bus, gint priority) goto done; /* this should not fail because the counter above takes care of it */ - g_assert (bus->priv->signal_watch_id == 0); + g_assert (!bus->priv->signal_watch); - bus->priv->signal_watch_id = - gst_bus_add_watch_full_unlocked (bus, priority, gst_bus_async_signal_func, + gst_bus_add_watch_full_unlocked (bus, priority, gst_bus_async_signal_func, NULL, NULL); - if (G_UNLIKELY (bus->priv->signal_watch_id == 0)) + if (G_UNLIKELY (!bus->priv->signal_watch)) goto add_failed; done: @@ -1254,7 +1404,7 @@ add_failed: * @bus: a #GstBus on which you want to receive the "message" signal * * Adds a bus signal watch to the default main context with the default priority - * (%G_PRIORITY_DEFAULT). Since 0.10.33 it is also possible to use a non-default + * (%G_PRIORITY_DEFAULT). It is also possible to use a non-default * main context set up using g_main_context_push_thread_default() (before * one had to create a bus watch source and attach it to the desired main * context 'manually'). @@ -1285,7 +1435,7 @@ gst_bus_add_signal_watch (GstBus * bus) void gst_bus_remove_signal_watch (GstBus * bus) { - guint id = 0; + GSource *source = NULL; g_return_if_fail (GST_IS_BUS (bus)); @@ -1300,16 +1450,16 @@ gst_bus_remove_signal_watch (GstBus * bus) if (bus->priv->num_signal_watchers > 0) goto done; - id = bus->priv->signal_watch_id; - bus->priv->signal_watch_id = 0; + GST_DEBUG_OBJECT (bus, "removing signal watch %u", + g_source_get_id (bus->priv->signal_watch)); - GST_DEBUG_OBJECT (bus, "removing signal watch %u", id); + source = bus->priv->signal_watch; done: GST_OBJECT_UNLOCK (bus); - if (id) - g_source_remove (id); + if (source) + g_source_destroy (source); return;