:right-sidebar: True Bus =================================================================== .. currentmodule:: gi.repository.Gst .. class:: Bus(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` :Constructors: :: Bus(**properties) new() -> Gst.Bus Constructors ------------ .. rst-class:: interim-class .. class:: Bus :no-index: .. classmethod:: new() -> ~gi.repository.Gst.Bus Creates a new :obj:`~gi.repository.Gst.Bus` instance. Methods ------- .. rst-class:: interim-class .. class:: Bus :no-index: .. method:: add_signal_watch() -> None Adds a bus signal watch to the default main context with the default priority ( ``%G_PRIORITY_DEFAULT`` ). It is also possible to use a non-default main context set up using :func:`~gi.repository.GLib.MainContext.push_thread_default` (before one had to create a bus watch source and attach it to the desired main context 'manually'). After calling this statement, the bus will emit the "message" signal for each message posted on the bus. This function may be called multiple times. To clean up, the caller is responsible for calling :func:`~gi.repository.Gst.Bus.remove_signal_watch` as many times as this function is called. .. method:: add_signal_watch_full(priority: int) -> None Adds a bus signal watch to the default main context with the given ``priority`` (e.g. ``%G_PRIORITY_DEFAULT``). It is also possible to use a non-default main context set up using :func:`~gi.repository.GLib.MainContext.push_thread_default` (before one had to create a bus watch source and attach it to the desired main context 'manually'). After calling this statement, the bus will emit the "message" signal for each message posted on the bus when the :obj:`~gi.repository.GLib.MainLoop` is running. This function may be called multiple times. To clean up, the caller is responsible for calling :func:`~gi.repository.Gst.Bus.remove_signal_watch` as many times as this function is called. There can only be a single bus watch per bus, you must remove any signal watch before you can set another type of watch. :param priority: The priority of the watch. .. method:: add_watch(priority: int, func: ~typing.Callable[[...], bool], *user_data: ~typing.Any) -> int Adds a bus watch to the default main context with the default priority ( ``%G_PRIORITY_DEFAULT`` ). It is also possible to use a non-default main context set up using :func:`~gi.repository.GLib.MainContext.push_thread_default` (before one had to create a bus watch source and attach it to the desired main context 'manually'). This function is used to receive asynchronous messages in the main loop. 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 :obj:`~gi.repository.GLib.MainLoop` is being run. The watch can be removed using :func:`~gi.repository.Gst.Bus.remove_watch` or by returning :const:`False` from ``func``. If the watch was added to the default main context it is also possible to remove the watch using :func:`~gi.repository.GLib.Source.remove`. The bus watch will take its own reference to the ``bus``, so it is safe to unref ``bus`` using :func:`~gi.repository.Gst.Object.unref` after setting the bus watch. :param priority: :param func: A function to call when a message is received. :param user_data: user data passed to ``func``. .. method:: async_signal_func(message: ~gi.repository.Gst.Message, data: None) -> bool A helper :obj:`~gi.repository.Gst.BusFunc` that can be used to convert all asynchronous messages into signals. :param message: the :obj:`~gi.repository.Gst.Message` received :param data: user data .. method:: create_watch() -> ~gi.repository.GLib.Source | None Create watch for this bus. The :obj:`~gi.repository.GLib.Source` will be dispatched whenever a message is on the bus. After the GSource is dispatched, the message is popped off the bus and unreffed. As with other watches, there can only be one watch on the bus, including any signal watch added with ``gst_bus_add_signal_watch``. .. method:: disable_sync_message_emission() -> None Instructs GStreamer to stop emitting the "sync-message" signal for this bus. See :func:`~gi.repository.Gst.Bus.enable_sync_message_emission` for more information. In the event that multiple pieces of code have called :func:`~gi.repository.Gst.Bus.enable_sync_message_emission`, the sync-message emissions will only be stopped after all calls to :func:`~gi.repository.Gst.Bus.enable_sync_message_emission` were "cancelled" by calling this function. In this way the semantics are exactly the same as :func:`~gi.repository.Gst.Object.ref` that which calls enable should also call disable. .. method:: enable_sync_message_emission() -> None Instructs GStreamer to emit the "sync-message" signal after running the bus's sync handler. This function is here so that code can ensure that they can synchronously receive messages without having to affect what the bin's sync handler is. This function may be called multiple times. To clean up, the caller is responsible for calling :func:`~gi.repository.Gst.Bus.disable_sync_message_emission` as many times as this function is called. While this function looks similar to :func:`~gi.repository.Gst.Bus.add_signal_watch`, it is not exactly the same -- this function enables *synchronous* emission of signals when messages arrive; :func:`~gi.repository.Gst.Bus.add_signal_watch` adds an idle callback to pop messages off the bus *asynchronously*. The sync-message signal comes from the thread of whatever object posted the message; the "message" signal is marshalled to the main thread via the :obj:`~gi.repository.GLib.MainLoop`. .. method:: get_pollfd() -> ~gi.repository.GLib.PollFD Gets the file descriptor from the bus which can be used to get notified about messages being available with functions like :func:`~gi.repository.GLib.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 :func:`~gi.repository.GLib.poll` or similar and then use the normal GstBus API, e.g. :func:`~gi.repository.Gst.Bus.pop`. .. versionadded:: 1.14 .. method:: have_pending() -> bool Checks if there are pending messages on the bus that should be handled. .. method:: peek() -> ~gi.repository.Gst.Message | None Peeks the message on the top of the bus' queue. The message will remain on the bus' message queue. .. method:: poll(events: ~gi.repository.Gst.MessageType, timeout: int) -> ~gi.repository.Gst.Message | None Polls the bus for messages. Will block while waiting for messages to come. You can specify a maximum time to poll with the ``timeout`` parameter. If ``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 :func:`~gi.repository.Gst.Bus.add_signal_watch`, calling :func:`~gi.repository.Gst.Bus.poll` will cause the "message" signal to be emitted for every message that poll sees. Thus a "message" signal handler will see the same messages that this function sees -- neither will steal messages from the other. This function will run a :obj:`~gi.repository.GLib.MainLoop` from the default main context when polling. You should never use this function, since it is pure evil. This is especially true for GUI applications based on Gtk+ or Qt, but also for any other non-trivial application that uses the GLib main loop. As this function runs a GLib main loop, any callback attached to the default GLib main context may be invoked. This could be timeouts, GUI events, I/O events etc.; even if :func:`~gi.repository.Gst.Bus.poll` is called with a 0 timeout. Any of these callbacks may do things you do not expect, e.g. destroy the main application window or some other resource; change other application state; display a dialog and run another main loop until the user clicks it away. In short, using this function may add a lot of complexity to your code through unexpected re-entrancy and unexpected changes to your application's state. For 0 timeouts use :func:`~gi.repository.Gst.Bus.pop_filtered` instead of this function; for other short timeouts use :func:`~gi.repository.Gst.Bus.timed_pop_filtered`; everything else is better handled by setting up an asynchronous bus watch and doing things from there. :param events: a mask of :obj:`~gi.repository.Gst.MessageType`, representing the set of message types to poll for (note special handling of extended message types below) :param timeout: the poll timeout, as a :obj:`~gi.repository.Gst.ClockTime`, or ``GST_CLOCK_TIME_NONE`` to poll indefinitely. .. method:: pop() -> ~gi.repository.Gst.Message | None Gets a message from the bus. .. method:: pop_filtered(types: ~gi.repository.Gst.MessageType) -> ~gi.repository.Gst.Message | None Gets 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. It is not possible to use message enums beyond ``GST_MESSAGE_EXTENDED`` in the ``events`` mask. :param types: message types to take into account .. method:: post(message: ~gi.repository.Gst.Message) -> bool Posts a message on the given bus. Ownership of the message is taken by the bus. :param message: the :obj:`~gi.repository.Gst.Message` to post .. method:: remove_signal_watch() -> None Removes a signal watch previously added with :func:`~gi.repository.Gst.Bus.add_signal_watch`. .. method:: remove_watch() -> bool Removes an installed bus watch from ``bus``. .. versionadded:: 1.6 .. method:: set_flushing(flushing: bool) -> None If ``flushing``, flushes out and unrefs any messages queued in the bus. Releases references to the message origin objects. Will flush future messages until :func:`~gi.repository.Gst.Bus.set_flushing` sets ``flushing`` to :const:`False`. :param flushing: whether or not to flush the bus .. method:: set_sync_handler(func: ~typing.Callable[[...], ~gi.repository.Gst.BusSyncReply] | None = None, *user_data: ~typing.Any) -> None 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 will be called in the same thread context as the posting object. This function is usually only called by the creator of the bus. Applications should handle messages asynchronously using the gst_bus watch and poll functions. Before 1.16.3 it was not possible to replace an existing handler and clearing an existing handler with :const:`None` was not thread-safe. :param func: The handler function to install :param user_data: User data that will be sent to the handler function. .. method:: sync_signal_handler(message: ~gi.repository.Gst.Message, data: None) -> ~gi.repository.Gst.BusSyncReply A helper :obj:`~gi.repository.Gst.BusSyncHandler` that can be used to convert all synchronous messages into signals. :param message: the :obj:`~gi.repository.Gst.Message` received :param data: user data .. method:: timed_pop(timeout: int) -> ~gi.repository.Gst.Message | None Gets a message from the bus, waiting up to the specified timeout. If ``timeout`` is 0, this function behaves like :func:`~gi.repository.Gst.Bus.pop`. If ``timeout`` is ``GST_CLOCK_TIME_NONE``, this function will block forever until a message was posted on the bus. :param timeout: a timeout .. method:: timed_pop_filtered(timeout: int, types: ~gi.repository.Gst.MessageType) -> ~gi.repository.Gst.Message | None Gets a message from the bus whose type matches the message type mask ``types``, waiting up to the specified timeout (and discarding any messages that do not match the mask provided). If ``timeout`` is 0, this function behaves like :func:`~gi.repository.Gst.Bus.pop_filtered`. If ``timeout`` is ``GST_CLOCK_TIME_NONE``, this function will block forever until a matching message was posted on the bus. :param timeout: a timeout in nanoseconds, or :const:`~gi.repository.Gst.CLOCK_TIME_NONE` to wait forever :param types: message types to take into account, :const:`~gi.repository.Gst.MessageType.ANY` for any type Properties ---------- .. rst-class:: interim-class .. class:: Bus :no-index: .. attribute:: props.enable_async :type: bool Enables async message delivery support for bus watches, :func:`~gi.repository.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 :obj:`~gi.repository.Gst.Bin`. Signals ------- .. rst-class:: interim-class .. class:: Bus.signals :no-index: .. method:: message(message: ~gi.repository.Gst.Message) -> None A message has been posted on the bus. This signal is emitted from a :obj:`~gi.repository.GLib.Source` added to the mainloop. this signal will only be emitted when there is a :obj:`~gi.repository.GLib.MainLoop` running. :param message: the message that has been posted asynchronously .. method:: sync_message(message: ~gi.repository.Gst.Message) -> None 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 call :func:`~gi.repository.Gst.Bus.enable_sync_message_emission` before. :param message: the message that has been posted synchronously Virtual Methods --------------- .. rst-class:: interim-class .. class:: Bus :no-index: .. method:: do_message(message: ~gi.repository.Gst.Message) -> None A message has been posted on the bus. :param message: the message that has been posted asynchronously .. method:: do_sync_message(message: ~gi.repository.Gst.Message) -> None A message has been posted on the bus. :param message: the message that has been posted synchronously Fields ------ .. rst-class:: interim-class .. class:: Bus :no-index: .. attribute:: object The parent structure .. attribute:: priv