2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GstBus.html
50 * - GSource* -> Source
52 * - GstMessage* -> Message
59 private import gstreamerc
.gstreamertypes
;
61 private import gstreamerc
.gstreamer
;
63 private import glib
.Str
;
64 private import gstreamer
.Message
;
65 private import glib
.Source
;
71 * The GstBus is an object responsible for delivering GstMessages in
72 * a first-in first-out way from the streaming threads to the application.
73 * Since the application typically only wants to deal with delivery of these
74 * messages from one thread, the GstBus will marshall the messages between
75 * different threads. This is important since the actual streaming of media
76 * is done in another thread than the application.
77 * The GstBus provides support for GSource based notifications. This makes it
78 * possible to handle the delivery in the glib mainloop.
79 * The GSource callback function gst_bus_async_signal_func() can be used to
80 * convert all bus messages into signal emissions.
81 * A message is posted on the bus with the gst_bus_post() method. With the
82 * gst_bus_peek() and gst_bus_pop() methods one can look at or retrieve a
83 * previously posted message.
84 * The bus can be polled with the gst_bus_poll() method. This methods blocks
85 * up to the specified timeout value until one of the specified messages types
86 * is posted on the bus. The application can then _pop() the messages from the
88 * Alternatively the application can register an asynchronous bus function
89 * using gst_bus_add_watch_full() or gst_bus_add_watch(). This function will
90 * install a GSource in the default glib main loop and will deliver messages
91 * a short while after they have been posted. Note that the main loop should
92 * be running for the asynchronous callbacks.
93 * It is also possible to get messages from the bus without any thread
94 * marshalling with the gst_bus_set_sync_handler() method. This makes it
95 * possible to react to a message in the same thread that posted the
96 * message on the bus. This should only be used if the application is able
97 * to deal with messages from different threads.
98 * Every GstPipeline has one bus.
99 * Note that a GstPipeline will set its bus into flushing state when changing
100 * from READY to NULL state.
101 * Last reviewed on 2006-03-12 (0.10.5)
103 private import gstreamer
.ObjectGst
;
104 public class Bus
: ObjectGst
107 /** the main Gtk struct */
108 protected GstBus
* gstBus
;
111 public GstBus
* getBusStruct()
117 /** the main Gtk struct as a void* */
118 protected void* getStruct()
120 return cast(void*)gstBus
;
124 * Sets our main struct and passes it to the parent class
126 public this (GstBus
* gstBus
)
128 super(cast(GstObject
*)gstBus
);
129 this.gstBus
= gstBus
;
133 * Adds a bus watch to the default main context with the default priority.
134 * This function is used to receive asynchronous messages in the main loop.
135 * The watch can be removed using g_source_remove() or by returning FALSE
138 * a GstBus to create the watch for
140 * A function to call when a message is received.
142 * user data passed to func.
144 * The event source id.
147 public uint addWatch( bool delegate(Message
) dlg
)
149 onWatchListener
= dlg
;
150 return gst_bus_add_watch(gstBus
, cast(GstBusFunc
)&watchCallBack
, this);
153 bool delegate(Message
) onWatchListener
;
155 extern(C
) static gboolean
watchCallBack(GstBus
* bus
, GstMessage
* msg
, Bus bus_d
)//gpointer data)
157 Message msg_d
= new Message( msg
);
159 return bus_d
.onWatchListener( msg_d
);
165 // imports for the signal processing
166 private import gobject
.Signals
;
167 private import gtkc
.gdktypes
;
168 int[char[]] connectedSignals
;
170 void delegate(Message
, Bus
)[] onMessageListeners
;
171 void addOnMessage(void delegate(Message
, Bus
) dlg
)
173 if ( !("message" in connectedSignals
) )
178 cast(GCallback
)&callBackMessage
,
181 cast(ConnectFlags
)0);
182 connectedSignals
["message"] = 1;
184 onMessageListeners
~= dlg
;
186 extern(C
) static void callBackMessage(GstBus
* busStruct
, GstMessage
* message
, Bus bus
)
188 bit consumed
= false;
190 foreach ( void delegate(Message
, Bus
) dlg
; bus
.onMessageListeners
)
192 dlg(new Message(message
), bus
);
198 void delegate(Message
, Bus
)[] onSyncMessageListeners
;
199 void addOnSyncMessage(void delegate(Message
, Bus
) dlg
)
201 if ( !("sync-message" in connectedSignals
) )
206 cast(GCallback
)&callBackSyncMessage
,
209 cast(ConnectFlags
)0);
210 connectedSignals
["sync-message"] = 1;
212 onSyncMessageListeners
~= dlg
;
214 extern(C
) static void callBackSyncMessage(GstBus
* busStruct
, GstMessage
* message
, Bus bus
)
216 bit consumed
= false;
218 foreach ( void delegate(Message
, Bus
) dlg
; bus
.onSyncMessageListeners
)
220 dlg(new Message(message
), bus
);
233 * Creates a new GstBus instance.
235 * a new GstBus instance
239 // GstBus* gst_bus_new (void);
240 this(cast(GstBus
*)gst_bus_new() );
244 * Post a message on the given bus. Ownership of the message
245 * is taken by the bus.
247 * a GstBus to post on
249 * The GstMessage to post
251 * TRUE if the message could be posted, FALSE if the bus is flushing.
254 public int post(Message message
)
256 // gboolean gst_bus_post (GstBus *bus, GstMessage *message);
257 return gst_bus_post(gstBus
, (message
is null) ?
null : message
.getMessageStruct());
261 * Check if there are pending messages on the bus that
266 * TRUE if there are messages on the bus to be handled, FALSE
270 public int havePending()
272 // gboolean gst_bus_have_pending (GstBus *bus);
273 return gst_bus_have_pending(gstBus
);
277 * Peek the message on the top of the bus' queue. The message will remain
278 * on the bus' message queue. A reference is returned, and needs to be unreffed
283 * The GstMessage that is on the bus, or NULL if the bus is empty.
286 public Message
peek()
288 // GstMessage* gst_bus_peek (GstBus *bus);
289 return new Message( gst_bus_peek(gstBus
) );
293 * Get a message from the bus.
297 * The GstMessage that is on the bus, or NULL if the bus is empty.
298 * The message is taken from the bus and needs to be unreffed with
299 * gst_message_unref() after usage.
304 // GstMessage* gst_bus_pop (GstBus *bus);
305 return new Message( gst_bus_pop(gstBus
) );
309 * Get a message from the bus, waiting up to the specified timeout.
310 * If timeout is 0, this function behaves like gst_bus_pop(). If timeout is
311 * GST_CLOCK_TIME_NONE, this function will block forever until a message was
318 * The GstMessage that is on the bus after the specified timeout
319 * or NULL if the bus is empty after the timeout expired.
320 * The message is taken from the bus and needs to be unreffed with
321 * gst_message_unref() after usage.
325 public Message
timedPop(GstClockTime timeout
)
327 // GstMessage* gst_bus_timed_pop (GstBus *bus, GstClockTime timeout);
328 return new Message( gst_bus_timed_pop(gstBus
, timeout
) );
332 * If flushing, flush out and unref any messages queued in the bus. Releases
333 * references to the message origin objects. Will flush future messages until
334 * gst_bus_set_flushing() sets flushing to FALSE.
339 * whether or not to flush the bus
341 public void setFlushing(int flushing
)
343 // void gst_bus_set_flushing (GstBus *bus, gboolean flushing);
344 gst_bus_set_flushing(gstBus
, flushing
);
348 * Sets the synchronous handler on the bus. The function will be called
349 * every time a new message is posted on the bus. Note that the function
350 * will be called in the same thread context as the posting object. This
351 * function is usually only called by the creator of the bus. Applications
352 * should handle messages asynchronously using the gst_bus watch and poll
354 * You cannot replace an existing sync_handler. You can pass NULL to this
355 * function, which will clear the existing handler.
357 * a GstBus to install the handler on
359 * The handler function to install
361 * User data that will be sent to the handler function.
363 public void setSyncHandler(GstBusSyncHandler func
, void* data
)
365 // void gst_bus_set_sync_handler (GstBus *bus, GstBusSyncHandler func, gpointer data);
366 gst_bus_set_sync_handler(gstBus
, func
, data
);
370 * A helper GstBusSyncHandler that can be used to convert all synchronous
371 * messages into signals.
375 * the GstMessage received
381 public GstBusSyncReply
syncSignalHandler(Message message
, void* data
)
383 // GstBusSyncReply gst_bus_sync_signal_handler (GstBus *bus, GstMessage *message, gpointer data);
384 return gst_bus_sync_signal_handler(gstBus
, (message
is null) ?
null : message
.getMessageStruct(), data
);
388 * Create watch for this bus. The GSource will be dispatched whenever
389 * a message is on the bus. After the GSource is dispatched, the
390 * message is popped off the bus and unreffed.
392 * a GstBus to create the watch for
394 * A GSource that can be added to a mainloop.
396 public Source
createWatch()
398 // GSource* gst_bus_create_watch (GstBus *bus);
399 return new Source( gst_bus_create_watch(gstBus
) );
403 * Adds a bus watch to the default main context with the given priority.
404 * This function is used to receive asynchronous messages in the main loop.
405 * When func is called, the message belongs to the caller; if you want to
406 * keep a copy of it, call gst_message_ref() before leaving func.
407 * The watch can be removed using g_source_remove() or by returning FALSE
410 * a GstBus to create the watch for.
412 * The priority of the watch.
414 * A function to call when a message is received.
416 * user data passed to func.
418 * the function to call when the source is removed.
420 * The event source id.
423 public uint addWatchFull(int priority
, GstBusFunc func
, void* userData
, GDestroyNotify notify
)
425 // guint gst_bus_add_watch_full (GstBus *bus, gint priority, GstBusFunc func, gpointer user_data, GDestroyNotify notify);
426 return gst_bus_add_watch_full(gstBus
, priority
, func
, userData
, notify
);
431 * Instructs GStreamer to stop emitting the "sync-message" signal for this bus.
432 * See gst_bus_enable_sync_message_emission() for more information.
433 * In the event that multiple pieces of code have called
434 * gst_bus_enable_sync_message_emission(), the sync-message emissions will only
435 * be stopped after all calls to gst_bus_enable_sync_message_emission() were
436 * "cancelled" by calling this function. In this way the semantics are exactly
437 * the same as gst_object_ref() that which calls enable should also call
441 * a GstBus on which you previously called
442 * gst_bus_enable_sync_message_emission()
444 public void disableSyncMessageEmission()
446 // void gst_bus_disable_sync_message_emission (GstBus *bus);
447 gst_bus_disable_sync_message_emission(gstBus
);
451 * Instructs GStreamer to emit the "sync-message" signal after running the bus's
452 * sync handler. This function is here so that code can ensure that they can
453 * synchronously receive messages without having to affect what the bin's sync
455 * This function may be called multiple times. To clean up, the caller is
456 * responsible for calling gst_bus_disable_sync_message_emission() as many times
457 * as this function is called.
458 * While this function looks similar to gst_bus_add_signal_watch(), it is not
459 * exactly the same -- this function enables synchronous emission of
460 * signals when messages arrive; gst_bus_add_signal_watch() adds an idle callback
461 * to pop messages off the bus asynchronously. The sync-message signal
462 * comes from the thread of whatever object posted the message; the "message"
463 * signal is marshalled to the main thread via the main loop.
466 * a GstBus on which you want to receive the "sync-message" signal
468 public void enableSyncMessageEmission()
470 // void gst_bus_enable_sync_message_emission (GstBus *bus);
471 gst_bus_enable_sync_message_emission(gstBus
);
475 * A helper GstBusFunc that can be used to convert all asynchronous messages
480 * the GstMessage received
486 public int asyncSignalFunc(Message message
, void* data
)
488 // gboolean gst_bus_async_signal_func (GstBus *bus, GstMessage *message, gpointer data);
489 return gst_bus_async_signal_func(gstBus
, (message
is null) ?
null : message
.getMessageStruct(), data
);
493 * Adds a bus signal watch to the default main context with the default
495 * After calling this statement, the bus will emit the "message" signal for each
496 * message posted on the bus.
497 * This function may be called multiple times. To clean up, the caller is
498 * responsible for calling gst_bus_remove_signal_watch() as many times as this
499 * function is called.
502 * a GstBus on which you want to receive the "message" signal
504 public void addSignalWatch()
506 // void gst_bus_add_signal_watch (GstBus *bus);
507 gst_bus_add_signal_watch(gstBus
);
511 * Adds a bus signal watch to the default main context with the given priority.
512 * After calling this statement, the bus will emit the "message" signal for each
513 * message posted on the bus when the main loop is running.
514 * This function may be called multiple times. To clean up, the caller is
515 * responsible for calling gst_bus_remove_signal_watch() as many times as this
516 * function is called.
519 * a GstBus on which you want to receive the "message" signal
521 * The priority of the watch.
523 public void addSignalWatchFull(int priority
)
525 // void gst_bus_add_signal_watch_full (GstBus *bus, gint priority);
526 gst_bus_add_signal_watch_full(gstBus
, priority
);
530 * Removes a signal watch previously added with gst_bus_add_signal_watch().
533 * a GstBus you previously added a signal watch to
535 public void removeSignalWatch()
537 // void gst_bus_remove_signal_watch (GstBus *bus);
538 gst_bus_remove_signal_watch(gstBus
);
542 * Poll the bus for messages. Will block while waiting for messages to come.
543 * You can specify a maximum time to poll with the timeout parameter. If
544 * timeout is negative, this function will block indefinitely.
545 * All messages not in events will be popped off the bus and will be ignored.
546 * Because poll is implemented using the "message" signal enabled by
547 * gst_bus_add_signal_watch(), calling gst_bus_poll() will cause the "message"
548 * signal to be emitted for every message that poll sees. Thus a "message"
549 * signal handler will see the same messages that this function sees -- neither
550 * will steal messages from the other.
551 * This function will run a main loop from the default main context when
556 * a mask of GstMessageType, representing the set of message types to
559 * the poll timeout, as a GstClockTimeDiff, or -1 to poll indefinitely.
561 * The message that was received, or NULL if the poll timed out.
562 * The message is taken from the bus and needs to be unreffed with
563 * gst_message_unref() after usage.
565 * The "message" signal
566 * void user_function (GstBus *bus,
567 * GstMessage *message,
568 * gpointer user_data) : Run last / Has details
569 * A message has been posted on the bus. This signal is emitted from a
570 * GSource added to the mainloop. this signal will only be emitted when
571 * there is a mainloop running.
573 * the object which received the signal
575 * the message that has been posted asynchronously
577 * user data set when the signal handler was connected.
579 public Message
poll(GstMessageType events
, GstClockTimeDiff timeout
)
581 // GstMessage* gst_bus_poll (GstBus *bus, GstMessageType events, GstClockTimeDiff timeout);
582 return new Message( gst_bus_poll(gstBus
, events
, timeout
) );