Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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 busAsyncSignalFunc
can be used to
convert all bus messages into signal emissions.
A message is posted on the bus with the busPost
method. With the
busPeek
and busPop
methods one can look at or retrieve a
previously posted message.
The bus can be polled with the busPoll
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 busPop
the messages
from the bus to handle them.
Alternatively the application can register an asynchronous bus function
using busAddWatch
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 busSetSyncHandler
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.
Synopsis
- newtype Bus = Bus (ManagedPtr Bus)
- class (GObject o, IsDescendantOf Bus o) => IsBus o
- toBus :: (MonadIO m, IsBus o) => o -> m Bus
- busAddSignalWatch :: (HasCallStack, MonadIO m, IsBus a) => a -> m ()
- busAddSignalWatchFull :: (HasCallStack, MonadIO m, IsBus a) => a -> Int32 -> m ()
- busAddWatch :: (HasCallStack, MonadIO m, IsBus a) => a -> Int32 -> BusFunc -> m Word32
- busAsyncSignalFunc :: (HasCallStack, MonadIO m, IsBus a) => a -> Message -> Ptr () -> m Bool
- busCreateWatch :: (HasCallStack, MonadIO m, IsBus a) => a -> m (Maybe Source)
- busDisableSyncMessageEmission :: (HasCallStack, MonadIO m, IsBus a) => a -> m ()
- busEnableSyncMessageEmission :: (HasCallStack, MonadIO m, IsBus a) => a -> m ()
- busGetPollfd :: (HasCallStack, MonadIO m, IsBus a) => a -> m PollFD
- busHavePending :: (HasCallStack, MonadIO m, IsBus a) => a -> m Bool
- busNew :: (HasCallStack, MonadIO m) => m Bus
- busPeek :: (HasCallStack, MonadIO m, IsBus a) => a -> m (Maybe Message)
- busPoll :: (HasCallStack, MonadIO m, IsBus a) => a -> [MessageType] -> Word64 -> m (Maybe Message)
- busPop :: (HasCallStack, MonadIO m, IsBus a) => a -> m (Maybe Message)
- busPopFiltered :: (HasCallStack, MonadIO m, IsBus a) => a -> [MessageType] -> m (Maybe Message)
- busPost :: (HasCallStack, MonadIO m, IsBus a) => a -> Message -> m Bool
- busRemoveSignalWatch :: (HasCallStack, MonadIO m, IsBus a) => a -> m ()
- busRemoveWatch :: (HasCallStack, MonadIO m, IsBus a) => a -> m Bool
- busSetFlushing :: (HasCallStack, MonadIO m, IsBus a) => a -> Bool -> m ()
- busSetSyncHandler :: (HasCallStack, MonadIO m, IsBus a) => a -> Maybe BusSyncHandler -> m ()
- busSyncSignalHandler :: (HasCallStack, MonadIO m, IsBus a) => a -> Message -> Ptr () -> m BusSyncReply
- busTimedPop :: (HasCallStack, MonadIO m, IsBus a) => a -> Word64 -> m (Maybe Message)
- busTimedPopFiltered :: (HasCallStack, MonadIO m, IsBus a) => a -> Word64 -> [MessageType] -> m (Maybe Message)
- constructBusEnableAsync :: (IsBus o, MonadIO m) => Bool -> m (GValueConstruct o)
- type BusMessageCallback = Message -> IO ()
- afterBusMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusMessageCallback) -> m SignalHandlerId
- onBusMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusMessageCallback) -> m SignalHandlerId
- type BusSyncMessageCallback = Message -> IO ()
- afterBusSyncMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusSyncMessageCallback) -> m SignalHandlerId
- onBusSyncMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusSyncMessageCallback) -> m SignalHandlerId
Exported types
Memory-managed wrapper type.
Bus (ManagedPtr Bus) |
Instances
Eq Bus Source # | |
GObject Bus Source # | |
Defined in GI.Gst.Objects.Bus | |
ManagedPtrNewtype Bus Source # | |
Defined in GI.Gst.Objects.Bus toManagedPtr :: Bus -> ManagedPtr Bus # | |
TypedObject Bus Source # | |
Defined in GI.Gst.Objects.Bus | |
HasParentTypes Bus Source # | |
Defined in GI.Gst.Objects.Bus | |
IsGValue (Maybe Bus) Source # | Convert |
Defined in GI.Gst.Objects.Bus | |
type ParentTypes Bus Source # | |
Defined in GI.Gst.Objects.Bus |
class (GObject o, IsDescendantOf Bus o) => IsBus o Source #
Instances
(GObject o, IsDescendantOf Bus o) => IsBus o Source # | |
Defined in GI.Gst.Objects.Bus |
Methods
Click to display all available methods, including inherited ones
Methods
addControlBinding, addSignalWatch, addSignalWatchFull, addWatch, asyncSignalFunc, bindProperty, bindPropertyFull, createWatch, defaultError, disableSyncMessageEmission, enableSyncMessageEmission, forceFloating, freezeNotify, getv, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, havePending, isFloating, notify, notifyByPspec, peek, poll, pop, popFiltered, post, ref, refSink, removeControlBinding, removeSignalWatch, removeWatch, runDispose, stealData, stealQdata, suggestNextSync, syncSignalHandler, syncValues, thawNotify, timedPop, timedPopFiltered, unparent, unref, watchClosure.
Getters
getControlBinding, getControlRate, getData, getGValueArray, getName, getParent, getPathString, getPollfd, getProperty, getQdata, getValue.
Setters
setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setData, setDataFull, setFlushing, setName, setParent, setProperty, setSyncHandler.
addSignalWatch
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m () |
Adds a bus signal watch to the default main context with the default priority
( PRIORITY_DEFAULT
). It is also possible to use a non-default
main context set up using mainContextPushThreadDefault
(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 busRemoveSignalWatch
as many times as this
function is called.
addSignalWatchFull
busAddSignalWatchFull Source #
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Int32 |
|
-> m () |
Adds a bus signal watch to the default main context with the given priority
(e.g. PRIORITY_DEFAULT
). It is also possible to use a non-default main
context set up using mainContextPushThreadDefault
(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 MainLoop
is running.
This function may be called multiple times. To clean up, the caller is
responsible for calling busRemoveSignalWatch
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.
addWatch
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Int32 |
|
-> BusFunc |
|
-> m Word32 | Returns: The event source id or 0 if |
Adds a bus watch to the default main context with the given priority
(e.g.
PRIORITY_DEFAULT
). It is also possible to use a non-default main
context set up using mainContextPushThreadDefault
(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 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 busRemoveWatch
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 sourceRemove
.
The bus watch will take its own reference to the bus
, so it is safe to unref
bus
using objectUnref
after setting the bus watch.
asyncSignalFunc
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Message |
|
-> Ptr () |
|
-> m Bool | Returns: |
A helper BusFunc
that can be used to convert all asynchronous messages
into signals.
createWatch
Create watch for this bus. The 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
.
disableSyncMessageEmission
busDisableSyncMessageEmission Source #
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m () |
Instructs GStreamer to stop emitting the "sync-message" signal for this bus.
See busEnableSyncMessageEmission
for more information.
In the event that multiple pieces of code have called
busEnableSyncMessageEmission
, the sync-message emissions will only
be stopped after all calls to busEnableSyncMessageEmission
were
"cancelled" by calling this function. In this way the semantics are exactly
the same as objectRef
that which calls enable should also call
disable.
enableSyncMessageEmission
busEnableSyncMessageEmission Source #
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m () |
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 busDisableSyncMessageEmission
as many times
as this function is called.
While this function looks similar to busAddSignalWatch
, it is not
exactly the same -- this function enables *synchronous* emission of
signals when messages arrive; busAddSignalWatch
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 MainLoop
.
getPollfd
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m PollFD |
Gets the file descriptor from the bus which can be used to get notified about
messages being available with functions like poll
, and allows integration
into other event loops based on file descriptors.
Whenever a message is available, the POLLIN / IOConditionIn
event is set.
Warning: NEVER read or write anything to the returned fd but only use it
for getting notifications via poll
or similar and then use the normal
GstBus API, e.g. busPop
.
Since: 1.14
havePending
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m Bool | Returns: |
Checks if there are pending messages on the bus that should be handled.
new
:: (HasCallStack, MonadIO m) | |
=> m Bus | Returns: a new |
Creates a new Bus
instance.
peek
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m (Maybe Message) | Returns: the |
Peeks the message on the top of the bus' queue. The message will remain on the bus' message queue.
poll
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> [MessageType] |
|
-> Word64 |
|
-> m (Maybe Message) | Returns: the message that was received,
or |
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
busAddSignalWatch
, calling busPoll
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 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 busPoll
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 busPopFiltered
instead of this function; for
other short timeouts use busTimedPopFiltered
; everything else is
better handled by setting up an asynchronous bus watch and doing things
from there.
pop
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m (Maybe Message) | Returns: the |
Gets a message from the bus.
popFiltered
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> [MessageType] |
|
-> m (Maybe Message) | Returns: the next |
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.
post
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Message |
|
-> m Bool | Returns: |
Posts a message on the given bus. Ownership of the message is taken by the bus.
removeSignalWatch
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m () |
Removes a signal watch previously added with busAddSignalWatch
.
removeWatch
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> m Bool | Returns: |
Removes an installed bus watch from bus
.
Since: 1.6
setFlushing
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Bool |
|
-> m () |
If flushing
, flushes out and unrefs any messages queued in the bus. Releases
references to the message origin objects. Will flush future messages until
busSetFlushing
sets flushing
to False
.
setSyncHandler
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Maybe BusSyncHandler |
|
-> m () |
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 Nothing
was not thread-safe.
syncSignalHandler
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Message |
|
-> Ptr () |
|
-> m BusSyncReply | Returns: |
A helper BusSyncHandler
that can be used to convert all synchronous
messages into signals.
timedPop
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Word64 |
|
-> m (Maybe Message) | Returns: the |
Gets a message from the bus, waiting up to the specified timeout.
If timeout
is 0, this function behaves like busPop
. If timeout
is
CLOCK_TIME_NONE
, this function will block forever until a message was
posted on the bus.
timedPopFiltered
:: (HasCallStack, MonadIO m, IsBus a) | |
=> a |
|
-> Word64 |
|
-> [MessageType] |
|
-> m (Maybe Message) | Returns: a |
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 busPopFiltered
. If
timeout
is CLOCK_TIME_NONE
, this function will block forever until a
matching message was posted on the bus.
Properties
enableAsync
Enables async message delivery support for bus watches,
busPop
and similar API. Without this only the
synchronous message handlers are called.
This property is used to create the child element buses
in Bin
.
constructBusEnableAsync :: (IsBus o, MonadIO m) => Bool -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “enable-async
” property. This is rarely needed directly, but it is used by new
.
Signals
message
type BusMessageCallback Source #
afterBusMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusMessageCallback) -> m SignalHandlerId Source #
Connect a signal handler for the message signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
bus #message callback
This signal admits a optional parameter detail
.
If it's not Nothing
, we will connect to “message::detail
” instead.
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onBusMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusMessageCallback) -> m SignalHandlerId Source #
Connect a signal handler for the message signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
bus #message callback
This signal admits a optional parameter detail
.
If it's not Nothing
, we will connect to “message::detail
” instead.
syncMessage
type BusSyncMessageCallback Source #
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
busEnableSyncMessageEmission
before.
afterBusSyncMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusSyncMessageCallback) -> m SignalHandlerId Source #
Connect a signal handler for the syncMessage signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
bus #syncMessage callback
This signal admits a optional parameter detail
.
If it's not Nothing
, we will connect to “sync-message::detail
” instead.
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onBusSyncMessage :: (IsBus a, MonadIO m) => a -> Maybe Text -> ((?self :: a) => BusSyncMessageCallback) -> m SignalHandlerId Source #
Connect a signal handler for the syncMessage signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
bus #syncMessage callback
This signal admits a optional parameter detail
.
If it's not Nothing
, we will connect to “sync-message::detail
” instead.