I've no idea here...
[gtkD.git] / gtkD / srcgstreamer / gstreamer / Bus.d
blobcacbf33986ffe1efdbfd9bcda2af5473f8c3f5e3
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 * - gst_bus_set_sync_handler
46 * imports:
47 * - glib.Str
48 * - gstreamer.Message
49 * - glib.Source
50 * structWrap:
51 * - GSource* -> Source
52 * - GstBus* -> Bus
53 * - GstMessage* -> Message
54 * module aliases:
55 * local aliases:
58 module gstreamer.Bus;
60 version(noAssert)
62 version(Tango)
64 import tango.io.Stdout; // use the tango loging?
68 private import gstreamerc.gstreamertypes;
70 private import gstreamerc.gstreamer;
73 private import glib.Str;
74 private import gstreamer.Message;
75 private import glib.Source;
80 /**
81 * Description
82 * The GstBus is an object responsible for delivering GstMessages in
83 * a first-in first-out way from the streaming threads to the application.
84 * Since the application typically only wants to deal with delivery of these
85 * messages from one thread, the GstBus will marshall the messages between
86 * different threads. This is important since the actual streaming of media
87 * is done in another thread than the application.
88 * The GstBus provides support for GSource based notifications. This makes it
89 * possible to handle the delivery in the glib mainloop.
90 * The GSource callback function gst_bus_async_signal_func() can be used to
91 * convert all bus messages into signal emissions.
92 * A message is posted on the bus with the gst_bus_post() method. With the
93 * gst_bus_peek() and gst_bus_pop() methods one can look at or retrieve a
94 * previously posted message.
95 * The bus can be polled with the gst_bus_poll() method. This methods blocks
96 * up to the specified timeout value until one of the specified messages types
97 * is posted on the bus. The application can then _pop() the messages from the
98 * bus to handle them.
99 * Alternatively the application can register an asynchronous bus function
100 * using gst_bus_add_watch_full() or gst_bus_add_watch(). This function will
101 * install a GSource in the default glib main loop and will deliver messages
102 * a short while after they have been posted. Note that the main loop should
103 * be running for the asynchronous callbacks.
104 * It is also possible to get messages from the bus without any thread
105 * marshalling with the gst_bus_set_sync_handler() method. This makes it
106 * possible to react to a message in the same thread that posted the
107 * message on the bus. This should only be used if the application is able
108 * to deal with messages from different threads.
109 * Every GstPipeline has one bus.
110 * Note that a GstPipeline will set its bus into flushing state when changing
111 * from READY to NULL state.
112 * Last reviewed on 2006-03-12 (0.10.5)
114 private import gstreamer.ObjectGst;
115 public class Bus : ObjectGst
118 /** the main Gtk struct */
119 protected GstBus* gstBus;
122 public GstBus* getBusStruct()
124 return gstBus;
128 /** the main Gtk struct as a void* */
129 protected void* getStruct()
131 return cast(void*)gstBus;
135 * Sets our main struct and passes it to the parent class
137 public this (GstBus* gstBus)
139 version(noAssert)
141 if ( gstBus is null )
143 int zero = 0;
144 version(Tango)
146 Stdout("struct gstBus is null on constructor").newline;
148 else
150 printf("struct gstBus is null on constructor");
152 zero = zero / zero;
155 else
157 assert(gstBus !is null, "struct gstBus is null on constructor");
159 super(cast(GstObject*)gstBus);
160 this.gstBus = gstBus;
164 * Adds a bus watch to the default main context with the default priority.
165 * This function is used to receive asynchronous messages in the main loop.
166 * The watch can be removed using g_source_remove() or by returning FALSE
167 * from func.
168 * bus:
169 * a GstBus to create the watch for
170 * func:
171 * A function to call when a message is received.
172 * user_data:
173 * user data passed to func.
174 * Returns:
175 * The event source id.
176 * MT safe.
178 public uint addWatch( bool delegate(Message) dlg )
180 onWatchListener = dlg;
181 return gst_bus_add_watch(gstBus, cast(GstBusFunc)&watchCallBack, cast(void*)this);
184 bool delegate(Message) onWatchListener;
186 extern(C) static gboolean watchCallBack(GstBus* bus, GstMessage* msg, Bus bus_d )//gpointer data)
188 Message msg_d = new Message( msg );
190 return bus_d.onWatchListener( msg_d );
194 * Use this for making an XOverlay.
195 * Sets the synchronous handler on the bus. The function will be called
196 * every time a new message is posted on the bus. Note that the function
197 * will be called in the same thread context as the posting object. This
198 * function is usually only called by the creator of the bus. Applications
199 * should handle messages asynchronously using the gst_bus watch and poll
200 * functions.
201 * You cannot replace an existing sync_handler. You can pass NULL to this
202 * function, which will clear the existing handler.
203 * bus:
204 * a GstBus to install the handler on
205 * func:
206 * The handler function to install
207 * data:
208 * User data that will be sent to the handler function.
210 public void setSyncHandler( GstBusSyncReply delegate(Message) dlg )
212 onSyncHandlerListener = dlg;
213 gst_bus_set_sync_handler(gstBus, cast(GstBusSyncHandler)&syncHandlerCallBack, cast(void*)this);
216 GstBusSyncReply delegate(Message) onSyncHandlerListener;
218 extern(C) static GstBusSyncReply syncHandlerCallBack(GstBus * bus, GstMessage * msg, Bus bus_d )//GstPipeline * pipeline)
219 //extern(C) static gboolean watchCallBack(GstBus* bus, GstMessage* msg, Bus bus_d )//gpointer data)
221 Message msg_d = new Message( msg );
223 return bus_d.onSyncHandlerListener( msg_d );
229 // imports for the signal processing
230 private import gobject.Signals;
231 private import gtkc.gdktypes;
232 int[char[]] connectedSignals;
234 void delegate(Message, Bus)[] onMessageListeners;
235 void addOnMessage(void delegate(Message, Bus) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
237 if ( !("message" in connectedSignals) )
239 Signals.connectData(
240 getStruct(),
241 "message",
242 cast(GCallback)&callBackMessage,
243 cast(void*)this,
244 null,
245 connectFlags);
246 connectedSignals["message"] = 1;
248 onMessageListeners ~= dlg;
250 extern(C) static void callBackMessage(GstBus* busStruct, GstMessage* message, Bus bus)
252 bool consumed = false;
254 foreach ( void delegate(Message, Bus) dlg ; bus.onMessageListeners )
256 dlg(new Message(message), bus);
259 return consumed;
262 void delegate(Message, Bus)[] onSyncMessageListeners;
263 void addOnSyncMessage(void delegate(Message, Bus) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
265 if ( !("sync-message" in connectedSignals) )
267 Signals.connectData(
268 getStruct(),
269 "sync-message",
270 cast(GCallback)&callBackSyncMessage,
271 cast(void*)this,
272 null,
273 connectFlags);
274 connectedSignals["sync-message"] = 1;
276 onSyncMessageListeners ~= dlg;
278 extern(C) static void callBackSyncMessage(GstBus* busStruct, GstMessage* message, Bus bus)
280 bool consumed = false;
282 foreach ( void delegate(Message, Bus) dlg ; bus.onSyncMessageListeners )
284 dlg(new Message(message), bus);
287 return consumed;
297 * Creates a new GstBus instance.
298 * Returns:
299 * a new GstBus instance
301 public this ()
303 // GstBus* gst_bus_new (void);
304 this(cast(GstBus*)gst_bus_new() );
308 * Post a message on the given bus. Ownership of the message
309 * is taken by the bus.
310 * bus:
311 * a GstBus to post on
312 * message:
313 * The GstMessage to post
314 * Returns:
315 * TRUE if the message could be posted, FALSE if the bus is flushing.
316 * MT safe.
318 public int post(Message message)
320 // gboolean gst_bus_post (GstBus *bus, GstMessage *message);
321 return gst_bus_post(gstBus, (message is null) ? null : message.getMessageStruct());
325 * Check if there are pending messages on the bus that
326 * should be handled.
327 * bus:
328 * a GstBus to check
329 * Returns:
330 * TRUE if there are messages on the bus to be handled, FALSE
331 * otherwise.
332 * MT safe.
334 public int havePending()
336 // gboolean gst_bus_have_pending (GstBus *bus);
337 return gst_bus_have_pending(gstBus);
341 * Peek the message on the top of the bus' queue. The message will remain
342 * on the bus' message queue. A reference is returned, and needs to be unreffed
343 * by the caller.
344 * bus:
345 * a GstBus
346 * Returns:
347 * The GstMessage that is on the bus, or NULL if the bus is empty.
348 * MT safe.
350 public Message peek()
352 // GstMessage* gst_bus_peek (GstBus *bus);
353 return new Message( gst_bus_peek(gstBus) );
357 * Get a message from the bus.
358 * bus:
359 * a GstBus to pop
360 * Returns:
361 * The GstMessage that is on the bus, or NULL if the bus is empty.
362 * The message is taken from the bus and needs to be unreffed with
363 * gst_message_unref() after usage.
364 * MT safe.
366 public Message pop()
368 // GstMessage* gst_bus_pop (GstBus *bus);
369 return new Message( gst_bus_pop(gstBus) );
373 * Get a message from the bus, waiting up to the specified timeout.
374 * If timeout is 0, this function behaves like gst_bus_pop(). If timeout is
375 * GST_CLOCK_TIME_NONE, this function will block forever until a message was
376 * posted on the bus.
377 * bus:
378 * a GstBus to pop
379 * timeout:
380 * a timeout
381 * Returns:
382 * The GstMessage that is on the bus after the specified timeout
383 * or NULL if the bus is empty after the timeout expired.
384 * The message is taken from the bus and needs to be unreffed with
385 * gst_message_unref() after usage.
386 * MT safe.
387 * Since 0.10.12
389 public Message timedPop(GstClockTime timeout)
391 // GstMessage* gst_bus_timed_pop (GstBus *bus, GstClockTime timeout);
392 return new Message( gst_bus_timed_pop(gstBus, timeout) );
396 * If flushing, flush out and unref any messages queued in the bus. Releases
397 * references to the message origin objects. Will flush future messages until
398 * gst_bus_set_flushing() sets flushing to FALSE.
399 * MT safe.
400 * bus:
401 * a GstBus
402 * flushing:
403 * whether or not to flush the bus
405 public void setFlushing(int flushing)
407 // void gst_bus_set_flushing (GstBus *bus, gboolean flushing);
408 gst_bus_set_flushing(gstBus, flushing);
413 * A helper GstBusSyncHandler that can be used to convert all synchronous
414 * messages into signals.
415 * bus:
416 * a GstBus
417 * message:
418 * the GstMessage received
419 * data:
420 * user data
421 * Returns:
422 * GST_BUS_PASS
424 public GstBusSyncReply syncSignalHandler(Message message, void* data)
426 // GstBusSyncReply gst_bus_sync_signal_handler (GstBus *bus, GstMessage *message, gpointer data);
427 return gst_bus_sync_signal_handler(gstBus, (message is null) ? null : message.getMessageStruct(), data);
431 * Create watch for this bus. The GSource will be dispatched whenever
432 * a message is on the bus. After the GSource is dispatched, the
433 * message is popped off the bus and unreffed.
434 * bus:
435 * a GstBus to create the watch for
436 * Returns:
437 * A GSource that can be added to a mainloop.
439 public Source createWatch()
441 // GSource* gst_bus_create_watch (GstBus *bus);
442 return new Source( gst_bus_create_watch(gstBus) );
446 * Adds a bus watch to the default main context with the given priority.
447 * This function is used to receive asynchronous messages in the main loop.
448 * When func is called, the message belongs to the caller; if you want to
449 * keep a copy of it, call gst_message_ref() before leaving func.
450 * The watch can be removed using g_source_remove() or by returning FALSE
451 * from func.
452 * bus:
453 * a GstBus to create the watch for.
454 * priority:
455 * The priority of the watch.
456 * func:
457 * A function to call when a message is received.
458 * user_data:
459 * user data passed to func.
460 * notify:
461 * the function to call when the source is removed.
462 * Returns:
463 * The event source id.
464 * MT safe.
466 public uint addWatchFull(int priority, GstBusFunc func, void* userData, GDestroyNotify notify)
468 // guint gst_bus_add_watch_full (GstBus *bus, gint priority, GstBusFunc func, gpointer user_data, GDestroyNotify notify);
469 return gst_bus_add_watch_full(gstBus, priority, func, userData, notify);
474 * Instructs GStreamer to stop emitting the "sync-message" signal for this bus.
475 * See gst_bus_enable_sync_message_emission() for more information.
476 * In the event that multiple pieces of code have called
477 * gst_bus_enable_sync_message_emission(), the sync-message emissions will only
478 * be stopped after all calls to gst_bus_enable_sync_message_emission() were
479 * "cancelled" by calling this function. In this way the semantics are exactly
480 * the same as gst_object_ref() that which calls enable should also call
481 * disable.
482 * MT safe.
483 * bus:
484 * a GstBus on which you previously called
485 * gst_bus_enable_sync_message_emission()
487 public void disableSyncMessageEmission()
489 // void gst_bus_disable_sync_message_emission (GstBus *bus);
490 gst_bus_disable_sync_message_emission(gstBus);
494 * Instructs GStreamer to emit the "sync-message" signal after running the bus's
495 * sync handler. This function is here so that code can ensure that they can
496 * synchronously receive messages without having to affect what the bin's sync
497 * handler is.
498 * This function may be called multiple times. To clean up, the caller is
499 * responsible for calling gst_bus_disable_sync_message_emission() as many times
500 * as this function is called.
501 * While this function looks similar to gst_bus_add_signal_watch(), it is not
502 * exactly the same -- this function enables synchronous emission of
503 * signals when messages arrive; gst_bus_add_signal_watch() adds an idle callback
504 * to pop messages off the bus asynchronously. The sync-message signal
505 * comes from the thread of whatever object posted the message; the "message"
506 * signal is marshalled to the main thread via the main loop.
507 * MT safe.
508 * bus:
509 * a GstBus on which you want to receive the "sync-message" signal
511 public void enableSyncMessageEmission()
513 // void gst_bus_enable_sync_message_emission (GstBus *bus);
514 gst_bus_enable_sync_message_emission(gstBus);
518 * A helper GstBusFunc that can be used to convert all asynchronous messages
519 * into signals.
520 * bus:
521 * a GstBus
522 * message:
523 * the GstMessage received
524 * data:
525 * user data
526 * Returns:
527 * TRUE
529 public int asyncSignalFunc(Message message, void* data)
531 // gboolean gst_bus_async_signal_func (GstBus *bus, GstMessage *message, gpointer data);
532 return gst_bus_async_signal_func(gstBus, (message is null) ? null : message.getMessageStruct(), data);
536 * Adds a bus signal watch to the default main context with the default
537 * priority.
538 * After calling this statement, the bus will emit the "message" signal for each
539 * message posted on the bus.
540 * This function may be called multiple times. To clean up, the caller is
541 * responsible for calling gst_bus_remove_signal_watch() as many times as this
542 * function is called.
543 * MT safe.
544 * bus:
545 * a GstBus on which you want to receive the "message" signal
547 public void addSignalWatch()
549 // void gst_bus_add_signal_watch (GstBus *bus);
550 gst_bus_add_signal_watch(gstBus);
554 * Adds a bus signal watch to the default main context with the given priority.
555 * After calling this statement, the bus will emit the "message" signal for each
556 * message posted on the bus when the main loop is running.
557 * This function may be called multiple times. To clean up, the caller is
558 * responsible for calling gst_bus_remove_signal_watch() as many times as this
559 * function is called.
560 * MT safe.
561 * bus:
562 * a GstBus on which you want to receive the "message" signal
563 * priority:
564 * The priority of the watch.
566 public void addSignalWatchFull(int priority)
568 // void gst_bus_add_signal_watch_full (GstBus *bus, gint priority);
569 gst_bus_add_signal_watch_full(gstBus, priority);
573 * Removes a signal watch previously added with gst_bus_add_signal_watch().
574 * MT safe.
575 * bus:
576 * a GstBus you previously added a signal watch to
578 public void removeSignalWatch()
580 // void gst_bus_remove_signal_watch (GstBus *bus);
581 gst_bus_remove_signal_watch(gstBus);
585 * Poll the bus for messages. Will block while waiting for messages to come.
586 * You can specify a maximum time to poll with the timeout parameter. If
587 * timeout is negative, this function will block indefinitely.
588 * All messages not in events will be popped off the bus and will be ignored.
589 * Because poll is implemented using the "message" signal enabled by
590 * gst_bus_add_signal_watch(), calling gst_bus_poll() will cause the "message"
591 * signal to be emitted for every message that poll sees. Thus a "message"
592 * signal handler will see the same messages that this function sees -- neither
593 * will steal messages from the other.
594 * This function will run a main loop from the default main context when
595 * polling.
596 * bus:
597 * a GstBus
598 * events:
599 * a mask of GstMessageType, representing the set of message types to
600 * poll for.
601 * timeout:
602 * the poll timeout, as a GstClockTimeDiff, or -1 to poll indefinitely.
603 * Returns:
604 * The message that was received, or NULL if the poll timed out.
605 * The message is taken from the bus and needs to be unreffed with
606 * gst_message_unref() after usage.
607 * Signal Details
608 * The "message" signal
609 * void user_function (GstBus *bus,
610 * GstMessage *message,
611 * gpointer user_data) : Run last / Has details
612 * A message has been posted on the bus. This signal is emitted from a
613 * GSource added to the mainloop. this signal will only be emitted when
614 * there is a mainloop running.
615 * bus:
616 * the object which received the signal
617 * message:
618 * the message that has been posted asynchronously
619 * user_data:
620 * user data set when the signal handler was connected.
622 public Message poll(GstMessageType events, GstClockTimeDiff timeout)
624 // GstMessage* gst_bus_poll (GstBus *bus, GstMessageType events, GstClockTimeDiff timeout);
625 return new Message( gst_bus_poll(gstBus, events, timeout) );