Gst.Bus

g GObject.InitiallyUnowned GObject.InitiallyUnowned Gst.Object Gst.Object GObject.InitiallyUnowned->Gst.Object GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gst.Bus Gst.Bus Gst.Object->Gst.Bus

Subclasses

None

Methods

Inherited

Gst.Object (27), GObject.Object (37)

Structs

GObject.ObjectClass (5)

class

new ()

add_signal_watch ()

add_signal_watch_full (priority)

add_watch (priority, func, *user_data)

async_signal_func (message, data)

create_watch ()

disable_sync_message_emission ()

enable_sync_message_emission ()

get_pollfd ()

have_pending ()

peek ()

poll (events, timeout)

pop ()

pop_filtered (types)

post (message)

remove_signal_watch ()

remove_watch ()

set_flushing (flushing)

set_sync_handler (func, *user_data)

sync_signal_handler (message, data)

timed_pop (timeout)

timed_pop_filtered (timeout, types)

Virtual Methods

Inherited

Gst.Object (1), GObject.Object (7)

do_message (message)

do_sync_message (message)

Properties

Inherited

Gst.Object (2)

Name

Type

Flags

Short Description

enable-async

bool

w/co

Enable async message delivery for bus watches and Gst.Bus.pop()

Signals

Inherited

Gst.Object (1), GObject.Object (1)

Name

Short Description

message

A message has been posted on the bus.

sync-message

A message has been posted on the bus.

Fields

Inherited

Gst.Object (1), GObject.Object (1)

Name

Type

Access

Description

object

Gst.Object

r

the parent structure

Class Details

class Gst.Bus(**kwargs)
Bases

Gst.Object

Abstract

No

Structure

Gst.BusClass

The Gst.Bus is an object responsible for delivering Gst.Message packets in a first-in first-out way from the streaming threads (see Gst.Task) to the application.

Since the application typically only wants to deal with delivery of these messages from one thread, the Gst.Bus will marshall the messages between different threads. This is important since the actual streaming of media is done in another thread than the application.

The Gst.Bus provides support for GLib.Source based notifications. This makes it possible to handle the delivery in the glib GLib.MainLoop.

The GLib.Source callback function Gst.Bus.async_signal_func() can be used to convert all bus messages into signal emissions.

A message is posted on the bus with the Gst.Bus.post() method. With the Gst.Bus.peek() and Gst.Bus.pop() methods one can look at or retrieve a previously posted message.

The bus can be polled with the Gst.Bus.poll() method. This methods blocks up to the specified timeout value until one of the specified messages types is posted on the bus. The application can then Gst.Bus.pop() the messages from the bus to handle them. Alternatively the application can register an asynchronous bus function using Gst.Bus.add_watch() or Gst.Bus.add_watch(). This function will install a GLib.Source in the default glib main loop and will deliver messages a short while after they have been posted. Note that the main loop should be running for the asynchronous callbacks.

It is also possible to get messages from the bus without any thread marshalling with the Gst.Bus.set_sync_handler() method. This makes it possible to react to a message in the same thread that posted the message on the bus. This should only be used if the application is able to deal with messages from different threads.

Every Gst.Pipeline has one bus.

Note that a Gst.Pipeline will set its bus into flushing state when changing from READY to None state.

classmethod new()[source]
Returns

a new Gst.Bus instance

Return type

Gst.Bus

Creates a new Gst.Bus instance.

add_signal_watch()[source]

Adds a bus signal watch to the default main context with the default priority ( GLib.PRIORITY_DEFAULT ). It is also possible to use a non-default main context set up using 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 Gst.Bus.remove_signal_watch() as many times as this function is called.

add_signal_watch_full(priority)[source]
Parameters

priority (int) – The priority of the watch.

Adds a bus signal watch to the default main context with the given priority (e.g. GLib.PRIORITY_DEFAULT). It is also possible to use a non-default main context set up using 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 GLib.MainLoop is running.

This function may be called multiple times. To clean up, the caller is responsible for calling 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.

add_watch(priority, func, *user_data)[source]
Parameters
  • priority (int) – The priority of the watch.

  • func (Gst.BusFunc) – A function to call when a message is received.

  • user_data (object or None) – user data passed to func.

Returns

The event source id or 0 if self already got an event source.

Return type

int

Adds a bus watch to the default main context with the given priority (e.g. GLib.PRIORITY_DEFAULT). It is also possible to use a non-default main context set up using 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 GLib.MainLoop 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 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 GLib.Source.remove().

The bus watch will take its own reference to the self, so it is safe to unref self using Gst.Object.unref() after setting the bus watch.

async_signal_func(message, data)[source]
Parameters
Returns

True

Return type

bool

A helper Gst.BusFunc that can be used to convert all asynchronous messages into signals.

create_watch()[source]
Returns

a GLib.Source that can be added to a GLib.MainLoop.

Return type

GLib.Source or None

Create watch for this bus. The GLib.Source will be dispatched whenever a message is on the bus. After the GLib.Source 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.

disable_sync_message_emission()[source]

Instructs GStreamer to stop emitting the “sync-message” signal for this bus. See Gst.Bus.enable_sync_message_emission() for more information.

In the event that multiple pieces of code have called Gst.Bus.enable_sync_message_emission(), the sync-message emissions will only be stopped after all calls to Gst.Bus.enable_sync_message_emission() were “cancelled” by calling this function. In this way the semantics are exactly the same as Gst.Object.ref() that which calls enable should also call disable.

enable_sync_message_emission()[source]

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 Gst.Bus.disable_sync_message_emission() as many times as this function is called.

While this function looks similar to Gst.Bus.add_signal_watch(), it is not exactly the same – this function enables *synchronous* emission of signals when messages arrive; 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 GLib.MainLoop.

get_pollfd()[source]
Returns

A GLib.PollFD to fill

Return type

fd: GLib.PollFD

Gets the file descriptor from the bus which can be used to get notified about messages being available with functions like GLib.poll(), and allows integration into other event loops based on file descriptors. Whenever a message is available, the POLLIN / GLib.IOCondition.IN event is set.

Warning: NEVER read or write anything to the returned fd but only use it for getting notifications via GLib.poll() or similar and then use the normal Gst.Bus API, e.g. Gst.Bus.pop().

New in version 1.14.

have_pending()[source]
Returns

True if there are messages on the bus to be handled, False otherwise.

Return type

bool

Checks if there are pending messages on the bus that should be handled.

peek()[source]
Returns

the Gst.Message that is on the bus, or None if the bus is empty.

Return type

Gst.Message or None

Peeks the message on the top of the bus’ queue. The message will remain on the bus’ message queue.

poll(events, timeout)[source]
Parameters
  • events (Gst.MessageType) – a mask of Gst.MessageType, representing the set of message types to poll for (note special handling of extended message types below)

  • timeout (int) – the poll timeout, as a #GstClockTime, or Gst.CLOCK_TIME_NONE to poll indefinitely.

Returns

the message that was received, or None if the poll timed out.

Return type

Gst.Message or 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.MessageType.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” 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 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 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 Gst.Bus.pop_filtered() instead of this function; for other short timeouts use Gst.Bus.timed_pop_filtered(); everything else is better handled by setting up an asynchronous bus watch and doing things from there.

pop()[source]
Returns

the Gst.Message that is on the bus, or None if the bus is empty.

Return type

Gst.Message or None

Gets a message from the bus.

pop_filtered(types)[source]
Parameters

types (Gst.MessageType) – message types to take into account

Returns

the next Gst.Message matching type that is on the bus, or None if the bus is empty or there is no message matching type.

Return type

Gst.Message or 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.MessageType.EXTENDED in the events mask.

post(message)[source]
Parameters

message (Gst.Message) – the Gst.Message to post

Returns

True if the message could be posted, False if the bus is flushing.

Return type

bool

Posts a message on the given bus. Ownership of the message is taken by the bus.

remove_signal_watch()[source]

Removes a signal watch previously added with Gst.Bus.add_signal_watch().

remove_watch()[source]
Returns

True on success or False if self has no event source.

Return type

bool

Removes an installed bus watch from self.

New in version 1.6.

set_flushing(flushing)[source]
Parameters

flushing (bool) – whether or not to flush the bus

If flushing, flushes out and unrefs 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.

set_sync_handler(func, *user_data)[source]
Parameters

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 None was not thread-safe.

sync_signal_handler(message, data)[source]
Parameters
Returns

Gst.BusSyncReply.PASS

Return type

Gst.BusSyncReply

A helper Gst.BusSyncHandler that can be used to convert all synchronous messages into signals.

timed_pop(timeout)[source]
Parameters

timeout (int) – a timeout

Returns

the Gst.Message that is on the bus after the specified timeout or None if the bus is empty after the timeout expired.

Return type

Gst.Message or None

Gets a message from the bus, waiting up to the specified timeout.

If timeout is 0, this function behaves like Gst.Bus.pop(). If timeout is Gst.CLOCK_TIME_NONE, this function will block forever until a message was posted on the bus.

timed_pop_filtered(timeout, types)[source]
Parameters
Returns

a Gst.Message matching the filter in types, or None if no matching message was found on the bus until the timeout expired.

Return type

Gst.Message or 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 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.

do_message(message) virtual
Parameters

message (Gst.Message) – the message that has been posted asynchronously

A message has been posted on the bus.

do_sync_message(message) virtual
Parameters

message (Gst.Message) – the message that has been posted synchronously

A message has been posted on the bus.

Signal Details

Gst.Bus.signals.message(bus, message)
Signal Name

message

Flags

RUN_LAST, DETAILED

Parameters
  • bus (Gst.Bus) – The object which received the signal

  • message (Gst.Message) – the message that has been posted asynchronously

A message has been posted on the bus. This signal is emitted from a GLib.Source added to the mainloop. this signal will only be emitted when there is a GLib.MainLoop running.

Gst.Bus.signals.sync_message(bus, message)
Signal Name

sync-message

Flags

RUN_LAST, DETAILED

Parameters
  • bus (Gst.Bus) – The object which received the signal

  • message (Gst.Message) – the message that has been posted synchronously

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 Gst.Bus.enable_sync_message_emission() before.

Property Details

Gst.Bus.props.enable_async
Name

enable-async

Type

bool

Default Value

True

Flags

WRITABLE, CONSTRUCT_ONLY

Enables 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 Gst.Bin.