Bus
Object Hierarchy:
Description:
public class Bus :
Object
The Bus is an object responsible for delivering Message
packets in a first-in first-out way from the streaming threads (see Task) to the
application. Since the application typically only wants to deal with delivery of these messages from one thread, the GstBus 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 GstBus provides support for Source based notifications. This
makes it possible to handle the delivery in the glib mainloop. The Source
callback function async_signal_func can be used to convert all bus messages
into signal emissions. A message is posted on the bus with the post method. With the
peek and pop methods one can look at or
retrieve a previously posted message. The bus can be polled with the 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
pop the messages from the bus to handle them. Alternatively the application can register an
asynchronous bus function using add_watch_full or gst_bus_add_watch.
This function will install a 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
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 Pipeline has one bus. Note that a
Pipeline will set its bus into flushing state when changing from READY to NULL state. Last reviewed on 2006-03-12 (0.10.5)
Namespace: Gst
Package: gstreamer-0.10
Content:
Creation methods:
-
public Bus ()
Creates a new Bus instance.
Methods:
-
public void add_signal_watch ()
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 main context set up using
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 remove_signal_watch as many times as this function is called. MT
safe.
-
public void add_signal_watch_full (int priority)
Adds a bus signal watch to the default main context with the given priority (e.g.
DEFAULT). Since 0.10.33 it is also possible to use a non-default
main context set up using 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 main loop is running. This function may be called
multiple times. To clean up, the caller is responsible for calling
remove_signal_watch as many times as this function is called. There can only be a single bus watch per bus, you most remove all
signal watch before you can set another type of watch. MT safe.
-
public uint add_watch (owned BusFunc func, int priority = DEFAULT)
-
public uint add_watch_full (int priority, owned BusFunc func)
Adds a bus watch to the default main context with the given priority (e.g.
DEFAULT). Since 0.10.33 it is also possible to use a non-default
main context set up using 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.
When func is called, the message belongs to the caller; if you want to keep a copy of it, call
ref before leaving func. The watch can be removed using
remove or by returning FALSE from func. MT safe.
-
public bool async_signal_func (Bus bus, Message message)
A helper BusFunc that can be used to convert all
asynchronous messages into signals.
-
public TimeoutSource create_watch ()
Create watch for this bus. The GSource will be dispatched whenever a message is on the bus. After the
GSource is dispatched, the message is popped off the bus and unreffed.
-
public void disable_sync_message_emission ()
Instructs GStreamer to stop emitting the "sync-message" signal for this bus. See
enable_sync_message_emission for more information. In the event
that multiple pieces of code have called
enable_sync_message_emission, the sync-message emissions will only be stopped after all calls to
enable_sync_message_emission were "cancelled" by calling this
function. In this way the semantics are exactly the same as ref that which calls
enable should also call disable. MT safe.
-
public void enable_sync_message_emission ()
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
disable_sync_message_emission as many times as this function
is called. While this function looks similar to add_signal_watch, it is not
exactly the same -- this function enables synchronous emission of signals when messages arrive;
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 main loop. MT safe.
-
public bool have_pending ()
Check if there are pending messages on the bus that should be handled. otherwise. MT safe.
-
public Message? peek ()
Peek the message on the top of the bus' queue. The message will remain on the bus' message queue. A
reference is returned, and needs to be unreffed by the caller. bus is empty. MT safe.
-
public Message? poll (MessageType events, ClockTimeDiff timeout)
Poll 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 All messages not in events will be popped off the bus and will be
ignored. Because poll is implemented using the "message" signal enabled by
add_signal_watch, calling 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 main loop 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 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 pop_filtered instead of this function;
for other short timeouts use timed_pop_filtered; everything else is
better handled by setting up an asynchronous bus watch and doing things from there. poll timed out. The message is taken from the bus
and needs to be unreffed with unref after usage.
-
public Message? pop ()
Get a message from the bus. bus is empty. The message is taken from the bus and needs to be unreffed
with unref after usage. MT safe.
-
public Message? pop_filtered (MessageType types)
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, or NULL if the bus is empty or there is no message
matching unref after usage. MT safe.
-
public bool post (owned Message message)
Post a message on the given bus. Ownership of the message is taken by the bus. MT safe.
-
public void remove_signal_watch ()
-
public void set_flushing (bool flushing)
If flushing, flush out and unref any messages queued in the bus. Releases references to the
message origin objects. Will flush future messages until set_flushing sets
flushing to false. MT safe.
-
public void set_sync_handler (BusSyncHandler? func)
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. You
cannot replace an existing sync_handler. You can pass NULL to this function, which will clear the existing handler.
-
public BusSyncReply sync_signal_handler (Bus bus, Message message)
A helper GstBusSyncHandler that can be used to convert all synchronous messages into signals.
-
public Message? timed_pop (ClockTime timeout)
Get a message from the bus, waiting up to the specified timeout. If timeout is 0, this
function behaves like pop. If timeout is
CLOCK_TIME_NONE, this function will block forever until a message was posted
on the bus. 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 unref after usage. MT safe.
-
public Message? timed_pop_filtered (ClockTime timeout, MessageType types)
Get 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 pop_filtered. If matching message was posted on the bus. 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
unref after usage. MT safe.
Signals: