alternative to assert
[gtkD.git] / gtkD / srcgstreamer / gstreamer / Bus.d
blobe2015520ae18d7328e8aca041f1165f4fc013443
1 /*
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
26 * outPack = gstreamer
27 * outFile = Bus
28 * strct = GstBus
29 * realStrct=
30 * ctorStrct=
31 * clss = Bus
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gst_bus_
40 * - gst_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * - gst_bus_add_watch
45 * imports:
46 * - glib.Str
47 * - gstreamer.Message
48 * - glib.Source
49 * structWrap:
50 * - GSource* -> Source
51 * - GstBus* -> Bus
52 * - GstMessage* -> Message
53 * module aliases:
54 * local aliases:
57 module gstreamer.Bus;
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;
69 /**
70 * Description
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
87 * bus to handle them.
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()
113 return gstBus;
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
136 * from func.
137 * bus:
138 * a GstBus to create the watch for
139 * func:
140 * A function to call when a message is received.
141 * user_data:
142 * user data passed to func.
143 * Returns:
144 * The event source id.
145 * MT safe.
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) )
175 Signals.connectData(
176 getStruct(),
177 "message",
178 cast(GCallback)&callBackMessage,
179 cast(void*)this,
180 null,
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);
195 return consumed;
198 void delegate(Message, Bus)[] onSyncMessageListeners;
199 void addOnSyncMessage(void delegate(Message, Bus) dlg)
201 if ( !("sync-message" in connectedSignals) )
203 Signals.connectData(
204 getStruct(),
205 "sync-message",
206 cast(GCallback)&callBackSyncMessage,
207 cast(void*)this,
208 null,
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);
223 return consumed;
233 * Creates a new GstBus instance.
234 * Returns:
235 * a new GstBus instance
237 public this ()
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.
246 * bus:
247 * a GstBus to post on
248 * message:
249 * The GstMessage to post
250 * Returns:
251 * TRUE if the message could be posted, FALSE if the bus is flushing.
252 * MT safe.
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
262 * should be handled.
263 * bus:
264 * a GstBus to check
265 * Returns:
266 * TRUE if there are messages on the bus to be handled, FALSE
267 * otherwise.
268 * MT safe.
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
279 * by the caller.
280 * bus:
281 * a GstBus
282 * Returns:
283 * The GstMessage that is on the bus, or NULL if the bus is empty.
284 * MT safe.
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.
294 * bus:
295 * a GstBus to pop
296 * Returns:
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.
300 * MT safe.
302 public Message pop()
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
312 * posted on the bus.
313 * bus:
314 * a GstBus to pop
315 * timeout:
316 * a timeout
317 * Returns:
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.
322 * MT safe.
323 * Since 0.10.12
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.
335 * MT safe.
336 * bus:
337 * a GstBus
338 * flushing:
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
353 * functions.
354 * You cannot replace an existing sync_handler. You can pass NULL to this
355 * function, which will clear the existing handler.
356 * bus:
357 * a GstBus to install the handler on
358 * func:
359 * The handler function to install
360 * data:
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.
372 * bus:
373 * a GstBus
374 * message:
375 * the GstMessage received
376 * data:
377 * user data
378 * Returns:
379 * GST_BUS_PASS
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.
391 * bus:
392 * a GstBus to create the watch for
393 * Returns:
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
408 * from func.
409 * bus:
410 * a GstBus to create the watch for.
411 * priority:
412 * The priority of the watch.
413 * func:
414 * A function to call when a message is received.
415 * user_data:
416 * user data passed to func.
417 * notify:
418 * the function to call when the source is removed.
419 * Returns:
420 * The event source id.
421 * MT safe.
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
438 * disable.
439 * MT safe.
440 * bus:
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
454 * handler is.
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.
464 * MT safe.
465 * bus:
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
476 * into signals.
477 * bus:
478 * a GstBus
479 * message:
480 * the GstMessage received
481 * data:
482 * user data
483 * Returns:
484 * TRUE
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
494 * priority.
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.
500 * MT safe.
501 * bus:
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.
517 * MT safe.
518 * bus:
519 * a GstBus on which you want to receive the "message" signal
520 * priority:
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().
531 * MT safe.
532 * bus:
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
552 * polling.
553 * bus:
554 * a GstBus
555 * events:
556 * a mask of GstMessageType, representing the set of message types to
557 * poll for.
558 * timeout:
559 * the poll timeout, as a GstClockTimeDiff, or -1 to poll indefinitely.
560 * Returns:
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.
564 * Signal Details
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.
572 * bus:
573 * the object which received the signal
574 * message:
575 * the message that has been posted asynchronously
576 * user_data:
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) );