Debian Codegraph @

gstreamer/gstreamermm/bus.h

raw symbols SCIP
1 // Generated by gmmproc 2.50.1 -- DO NOT MODIFY!
2 #ifndef _GSTREAMERMM_BUS_H
3 #define _GSTREAMERMM_BUS_H
4
5
6 #include <glibmm/ustring.h>
7 #include <sigc++/sigc++.h>
8
9 /* gstreamermm - a C++ wrapper for gstreamer
10 *
11 * Copyright 2008-2016 The gstreamermm Development Team
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 - version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28 #include <gstreamermm/object.h>
29 #include <gstreamermm/clock.h>
30 #include <gstreamermm/message.h>
31 #include <glibmm/priorities.h>
32 //#include <glibmm/main.h> //For Glib::Source
33
34
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 using GstBus = struct _GstBus;
37 using GstBusClass = struct _GstBusClass;
38 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
39
40
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 namespace Gst
43 { class Bus_Class; } // namespace Gst
44 #endif //DOXYGEN_SHOULD_SKIP_THIS
45
46 namespace Gst
47 {
48
49 class Message;
50
51 /** @addtogroup gstreamermmEnums gstreamermm Enums and Flags */
52
53 /**
54 * @var BusFlags BUS_FLUSHING
55 * The bus is currently dropping all messages.
56 *
57 * @var BusFlags BUS_FLAG_LAST
58 * Offset to define more flags.
59 *
60 * @enum BusFlags
61 *
62 * The standard flags that a bus may have.
63 *
64 * @ingroup gstreamermmEnums
65 * @par Bitwise operators:
66 * <tt>%BusFlags operator|(BusFlags, BusFlags)</tt><br>
67 * <tt>%BusFlags operator&(BusFlags, BusFlags)</tt><br>
68 * <tt>%BusFlags operator^(BusFlags, BusFlags)</tt><br>
69 * <tt>%BusFlags operator~(BusFlags)</tt><br>
70 * <tt>%BusFlags& operator|=(BusFlags&, BusFlags)</tt><br>
71 * <tt>%BusFlags& operator&=(BusFlags&, BusFlags)</tt><br>
72 * <tt>%BusFlags& operator^=(BusFlags&, BusFlags)</tt><br>
73 */
74 enum BusFlags
75 {
76 BUS_FLUSHING = (GST_OBJECT_FLAG_LAST << 0),
77 BUS_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 1)
78 };
79
80 /** @ingroup gstreamermmEnums */
81 inline BusFlags operator|(BusFlags lhs, BusFlags rhs)
82 { return static_cast<BusFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
83
84 /** @ingroup gstreamermmEnums */
85 inline BusFlags operator&(BusFlags lhs, BusFlags rhs)
86 { return static_cast<BusFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
87
88 /** @ingroup gstreamermmEnums */
89 inline BusFlags operator^(BusFlags lhs, BusFlags rhs)
90 { return static_cast<BusFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
91
92 /** @ingroup gstreamermmEnums */
93 inline BusFlags operator~(BusFlags flags)
94 { return static_cast<BusFlags>(~static_cast<unsigned>(flags)); }
95
96 /** @ingroup gstreamermmEnums */
97 inline BusFlags& operator|=(BusFlags& lhs, BusFlags rhs)
98 { return (lhs = static_cast<BusFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
99
100 /** @ingroup gstreamermmEnums */
101 inline BusFlags& operator&=(BusFlags& lhs, BusFlags rhs)
102 { return (lhs = static_cast<BusFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
103
104 /** @ingroup gstreamermmEnums */
105 inline BusFlags& operator^=(BusFlags& lhs, BusFlags rhs)
106 { return (lhs = static_cast<BusFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
107
108 } // namespace Gst
109
110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111 namespace Glib
112 {
113
114 template <>
115 class Value<Gst::BusFlags> : public Glib::Value_Flags<Gst::BusFlags>
116 {
117 public:
118 static GType value_type() G_GNUC_CONST;
119 };
120
121 } // namespace Glib
122 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
123
124 namespace Gst
125 {
126
127
128 /**
129 * @var BusSyncReply BUS_DROP
130 * Drop the message.
131 *
132 * @var BusSyncReply BUS_PASS
133 * Pass the message to the async queue.
134 *
135 * @var BusSyncReply BUS_ASYNC
136 * Pass message to async queue, continue if message is handled.
137 *
138 * @enum BusSyncReply
139 *
140 * The result values for a GstBusSyncHandler.
141 *
142 * @ingroup gstreamermmEnums
143 */
144 enum BusSyncReply
145 {
146 BUS_DROP,
147 BUS_PASS,
148 BUS_ASYNC
149 };
150
151 } // namespace Gst
152
153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
154 namespace Glib
155 {
156
157 template <>
158 class Value<Gst::BusSyncReply> : public Glib::Value_Enum<Gst::BusSyncReply>
159 {
160 public:
161 static GType value_type() G_GNUC_CONST;
162 };
163
164 } // namespace Glib
165 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
166
167 namespace Gst
168 {
169
170
171 /** A class that encompasses the GStreamer asynchronous message bus subsystem.
172 * The Gst::Bus is an object responsible for delivering Messages in a first-in
173 * first-out way from the streaming threads to the application.
174 *
175 * Since the application typically only wants to deal with delivery of these
176 * messages from one thread, the Gst::Bus will marshall the messages between
177 * different threads. This is important since the actual streaming of media is
178 * done in another thread than the application.
179 *
180 * The Gst::Bus provides support for GSource based notifications. This makes it
181 * possible to handle the delivery in the glib mainloop.
182 *
183 * The GSource callback function gst_bus_async_signal_func() can be used to
184 * convert all bus messages into signal emissions.
185 *
186 * A message is posted on the bus with the post() method. With the peek() and
187 * pop() methods one can look at or retrieve a previously posted message.
188 *
189 * The bus can be polled with the poll() method. This methods blocks up to the
190 * specified timeout value until one of the specified messages types is posted
191 * on the bus. The application can then pop() the messages from the bus to
192 * handle them. Alternatively the application can register an asynchronous bus
193 * function using add_watch(). This function will install a GSource in the
194 * default glib main loop and will deliver messages a short while after they
195 * have been posted. Note that the main loop should be running for the
196 * asynchronous callbacks.
197 *
198 * It is also possible to get messages from the bus without any thread
199 * marshalling with the set_sync_handler() method. This makes it possible to
200 * react to a message in the same thread that posted the message on the bus.
201 * This should only be used if the application is able to deal with messages
202 * from different threads.
203 *
204 * Every Gst::Pipeline has one bus.
205 *
206 * Note that a Gst::Pipeline will set its bus into flushing state when
207 * changing from READY to NULL state.
208 *
209 * Last reviewed on 2016-05-16 (1.8.0)
210 */
211
212 class Bus : public Object
213 {
214
215 #ifndef DOXYGEN_SHOULD_SKIP_THIS
216
217 public:
218 using CppObjectType = Bus;
219 using CppClassType = Bus_Class;
220 using BaseObjectType = GstBus;
221 using BaseClassType = GstBusClass;
222
223 // noncopyable
224 Bus(const Bus&) = delete;
225 Bus& operator=(const Bus&) = delete;
226
227 private: friend class Bus_Class;
228 static CppClassType bus_class_;
229
230 protected:
231 explicit Bus(const Glib::ConstructParams& construct_params);
232 explicit Bus(GstBus* castitem);
233
234 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
235
236 public:
237
238 Bus(Bus&& src) noexcept;
239 Bus& operator=(Bus&& src) noexcept;
240
241 ~Bus() noexcept override;
242
243 /** Get the GType for this class, for use with the underlying GObject type system.
244 */
245 static GType get_type() G_GNUC_CONST;
246
247 #ifndef DOXYGEN_SHOULD_SKIP_THIS
248
249
250 static GType get_base_type() G_GNUC_CONST;
251 #endif
252
253 ///Provides access to the underlying C GObject.
254 GstBus* gobj() { return reinterpret_cast<GstBus*>(gobject_); }
255
256 ///Provides access to the underlying C GObject.
257 const GstBus* gobj() const { return reinterpret_cast<GstBus*>(gobject_); }
258
259 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
260 GstBus* gobj_copy();
261
262 private:
263
264
265 protected:
266 Bus();
267
268 public:
269 /** For example,
270 * bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus, const
271 * Glib::RefPtr<Gst::Message>& message);.
272 * The message function should return true if it wants to continue to receive
273 * messages, or false otherwise.
274 */
275 typedef sigc::slot< bool, const Glib::RefPtr<Gst::Bus>&, const Glib::RefPtr<Gst::Message>& > SlotMessage;
276
277 /** For example,
278 * BusSyncReply on_bus_sync_message(const Glib::RefPtr<Gst::Bus>& bus, const
279 * Glib::RefPtr<Gst::Message>& message);.
280 */
281 typedef sigc::slot< BusSyncReply, const Glib::RefPtr<Gst::Bus>&, const Glib::RefPtr<Gst::Message>& > SlotMessageSync;
282
283 /** Creates a new Gst::Bus instance.
284 *
285 * @return The new Gst::Bus instance.
286 */
287
288 static Glib::RefPtr<Bus> create();
289
290
291 /** Post a message on the given bus. Ownership of the message
292 * is taken by the bus.
293 *
294 * @param message The Gst::Message to post.
295 * @return <tt>true</tt> if the message could be posted, <tt>false</tt> if the bus is flushing.
296 *
297 * MT safe.
298 */
299 bool post(Glib::RefPtr<Gst::Message>&& message);
300
301 /** Check if there are pending messages on the bus that
302 * should be handled.
303 *
304 * @return <tt>true</tt> if there are messages on the bus to be handled, <tt>false</tt>
305 * otherwise.
306 *
307 * MT safe.
308 */
309 bool have_pending() const;
310
311 /** Peek the message on the top of the bus' queue. The message will remain
312 * on the bus' message queue. A reference is returned, and needs to be unreffed
313 * by the caller.
314 *
315 * @return The Gst::Message that is on the
316 * bus, or <tt>nullptr</tt> if the bus is empty.
317 *
318 * MT safe.
319 */
320 Glib::RefPtr<Gst::Message> peek();
321
322 /** Peek the message on the top of the bus' queue. The message will remain
323 * on the bus' message queue. A reference is returned, and needs to be unreffed
324 * by the caller.
325 *
326 * @return The Gst::Message that is on the
327 * bus, or <tt>nullptr</tt> if the bus is empty.
328 *
329 * MT safe.
330 */
331 Glib::RefPtr<const Gst::Message> peek() const;
332
333 /** Get a message from the bus.
334 *
335 * @return The Gst::Message that is on the
336 * bus, or <tt>nullptr</tt> if the bus is empty. The message is taken from
337 * the bus.
338 *
339 * MT safe.
340 */
341 Glib::RefPtr<Gst::Message> pop();
342
343 /** Get a message matching @a type from the bus. Will discard all messages on
344 * the bus that do not match @a type and that have been posted before the first
345 * message that does match @a type. If there is no message matching @a type on
346 * the bus, all messages will be discarded. It is not possible to use message
347 * enums beyond Gst::MESSAGE_EXTENDED in the @a events mask.
348 *
349 * @param message_type Message types to take into account.
350 * @return The next Gst::Message matching
351 * @a type that is on the bus, or <tt>nullptr</tt> if the bus is empty or there
352 * is no message matching @a type. The message is taken from the bus.
353 *
354 * MT safe.
355 */
356 Glib::RefPtr<Gst::Message> pop(MessageType message_type);
357
358 /** Get a message from the bus, waiting up to the specified timeout.
359 *
360 * If @a timeout is 0, this function behaves like pop(). If @a timeout is
361 * Gst::CLOCK_TIME_NONE, this function will block forever until a message was
362 * posted on the bus.
363 *
364 * @param timeout A timeout.
365 * @return The Gst::Message that is on the
366 * bus after the specified timeout or <tt>nullptr</tt> if the bus is empty
367 * after the timeout expired. The message is taken from the bus.
368 *
369 * MT safe.
370 */
371 Glib::RefPtr<Gst::Message> pop(ClockTime timeout);
372
373 /** Get a message from the bus whose type matches the message type mask @a message_type,
374 * waiting up to the specified timeout (and discarding any messages that do not
375 * match the mask provided).
376 *
377 * If @a timeout is 0, this function behaves like pop_filtered(). If
378 * @a timeout is Gst::CLOCK_TIME_NONE, this function will block forever until a
379 * matching message was posted on the bus.
380 *
381 * @param timeout A timeout in nanoseconds, or GST_CLOCK_TIME_NONE to wait forever.
382 * @param message_type Message types to take into account, GST_MESSAGE_ANY for any type.
383 * @return A Gst::Message matching the
384 * filter in @a message_type, or <tt>nullptr</tt> if no matching message was found on
385 * the bus until the timeout expired. The message is taken from
386 * the bus.
387 *
388 * MT safe.
389 */
390 Glib::RefPtr<Gst::Message> pop(ClockTime timeout, MessageType message_type);
391
392 /** If @a flushing, flush out and unref any messages queued in the bus. Releases
393 * references to the message origin objects. Will flush future messages until
394 * set_flushing() sets @a flushing to <tt>false</tt>.
395 *
396 * MT safe.
397 *
398 * @param flushing Whether or not to flush the bus.
399 */
400 void set_flushing(bool flushing = true);
401
402 //TODO Glib::Source has a strange cobject constructor.
403 //#m4 __CONVERSION(`GSource*',`Glib::RefPtr<Glib::Source>', `Glib::wrap($3)')
404 // _WRAP_METHOD(Glib::RefPtr<Glib::Source> create_watch(), gst_bus_create_watch)
405
406 /** Adds a bus watch to the default main context with the given priority.
407 * The slot is used to receive asynchronous messages in the main loop.
408 *
409 * The watch can be removed using remove_watch() or by returning false from
410 * slot.
411 *
412 * @param slot The slot to call when a message is received.
413 * @param priority The priority of the watch.
414 * @return The event source id. MT safe.
415 */
416 guint add_watch(const SlotMessage& slot, int priority = Glib::PRIORITY_DEFAULT);
417
418
419 /** Removes bus watch with event source id from main context.
420 *
421 * @param watch_id The event source id.
422 * @return true if removal was succesful, false otherwise.
423 */
424 bool remove_watch(guint watch_id);
425
426
427 /** Sets the synchronous handler on the bus. The slot will be called every
428 * time a new message is posted on the bus. Note that the function will be
429 * called in the same thread context as the posting object (synchronously).
430 * This function is usually only called by the creator of the bus.
431 * Applications should handle messages asynchronously using the watch and
432 * poll functions or enable the "sync-message" signal emission with
433 * enable_sync_message_emission().
434 *
435 * @param slot The handler slot to install.
436 */
437 void set_sync_handler(const SlotMessageSync& slot);
438
439
440 /** Instructs GStreamer to stop emitting the "sync-message" signal for this bus.
441 * See enable_sync_message_emission() for more information.
442 *
443 * In the event that multiple pieces of code have called
444 * enable_sync_message_emission(), the sync-message emissions will only
445 * be stopped after all calls to enable_sync_message_emission() were
446 * "cancelled" by calling this function. In this way the semantics are exactly
447 * the same as Gst::Object::ref() that which calls enable should also call
448 * disable.
449 *
450 * MT safe.
451 */
452 void disable_sync_message_emission();
453
454 /** Instructs GStreamer to emit the "sync-message" signal after running the bus's
455 * sync handler. This function is here so that code can ensure that they can
456 * synchronously receive messages without having to affect what the bin's sync
457 * handler is.
458 *
459 * This function may be called multiple times. To clean up, the caller is
460 * responsible for calling disable_sync_message_emission() as many times
461 * as this function is called.
462 *
463 * While this function looks similar to add_signal_watch(), it is not
464 * exactly the same -- this function enables <em>synchronous</em> emission of
465 * signals when messages arrive; add_signal_watch() adds an idle callback
466 * to pop messages off the bus <em>asynchronously</em>. The sync-message signal
467 * comes from the thread of whatever object posted the message; the "message"
468 * signal is marshalled to the main thread via the main loop.
469 *
470 * MT safe.
471 */
472 void enable_sync_message_emission();
473
474
475 /** Adds a bus signal watch to the default main context with the given @a priority
476 * (e.g.\ PRIORITY_DEFAULT). It is also possible to use a non-default main
477 * context set up using Glib::main_context_push_thread_default()
478 * (before one had to create a bus watch source and attach it to the desired
479 * main context 'manually').
480 *
481 * After calling this statement, the bus will emit the "message" signal for each
482 * message posted on the bus when the main loop is running.
483 *
484 * This function may be called multiple times. To clean up, the caller is
485 * responsible for calling remove_signal_watch() as many times as this
486 * function is called.
487 *
488 * There can only be a single bus watch per bus, you must remove any signal
489 * watch before you can set another type of watch.
490 *
491 * MT safe.
492 *
493 * @param priority The priority of the watch.
494 */
495 void add_signal_watch(int priority = Glib::PRIORITY_DEFAULT);
496
497
498 /** Removes a signal watch previously added with add_signal_watch().
499 *
500 * MT safe.
501 */
502 void remove_signal_watch();
503
504 /** Poll the bus for messages. Will block while waiting for messages to come.
505 * You can specify a maximum time to poll with the @a timeout parameter. If
506 * @a timeout is negative, this function will block indefinitely.
507 *
508 * All messages not in @a message_type will be popped off the bus and will be ignored.
509 * It is not possible to use message enums beyond Gst::MESSAGE_EXTENDED in the
510 * @a message_type mask
511 *
512 * Because poll is implemented using the "message" signal enabled by
513 * add_signal_watch(), calling poll() will cause the "message"
514 * signal to be emitted for every message that poll sees. Thus a "message"
515 * signal handler will see the same messages that this function sees -- neither
516 * will steal messages from the other.
517 *
518 * This function will run a main loop from the default main context when
519 * polling.
520 *
521 * You should never use this function, since it is pure evil. This is
522 * especially true for GUI applications based on Gtk+ or Qt, but also for any
523 * other non-trivial application that uses the GLib main loop. As this function
524 * runs a GLib main loop, any callback attached to the default GLib main
525 * context may be invoked. This could be timeouts, GUI events, I/O events etc.;
526 * even if poll() is called with a 0 timeout. Any of these callbacks
527 * may do things you do not expect, e.g. destroy the main application window or
528 * some other resource; change other application state; display a dialog and
529 * run another main loop until the user clicks it away. In short, using this
530 * function may add a lot of complexity to your code through unexpected
531 * re-entrancy and unexpected changes to your application's state.
532 *
533 * For 0 timeouts use pop_filtered() instead of this function; for
534 * other short timeouts use timed_pop_filtered(); everything else is
535 * better handled by setting up an asynchronous bus watch and doing things
536 * from there.
537 *
538 * @param message_type A mask of Gst::MessageType, representing the set of message types to
539 * poll for (note special handling of extended message types below).
540 * @param timeout The poll timeout, as a Gst::ClockTime, or Gst::CLOCK_TIME_NONE to poll
541 * indefinitely.
542 * @return The message that was received,
543 * or <tt>nullptr</tt> if the poll timed out. The message is taken from the
544 * bus.
545 */
546 Glib::RefPtr<Gst::Message> poll(MessageType message_type, ClockTime timeout);
547
548
549 /**
550 * @par Slot Prototype:
551 * <tt>void on_my_%message(const Glib::RefPtr<Gst::Message>& message)</tt>
552 *
553 * A message has been posted on the bus. This signal is emitted from a
554 * GSource added to the mainloop. this signal will only be emitted when
555 * there is a mainloop running.
556 *
557 * @param message The message that has been posted asynchronously.
558 */
559
560 Glib::SignalProxy< void,const Glib::RefPtr<Gst::Message>& > signal_message();
561
562
563 /**
564 * @par Slot Prototype:
565 * <tt>void on_my_%sync_message(const Glib::RefPtr<Gst::Message>& message)</tt>
566 *
567 * A message has been posted on the bus. This signal is emitted from the
568 * thread that posted the message so one has to be careful with locking.
569 *
570 * This signal will not be emitted by default, you have to call
571 * Gst::Bus::enable_sync_message_emission() before.
572 *
573 * @param message The message that has been posted synchronously.
574 */
575
576 Glib::SignalProxy< void,const Glib::RefPtr<Gst::Message>& > signal_sync_message();
577
578
579 public:
580
581 public:
582 //C++ methods used to invoke GTK+ virtual functions:
583
584 protected:
585 //GTK+ Virtual Functions (override these to change behaviour):
586
587 //Default Signal Handlers::
588 /// This is a default handler for the signal signal_message().
589 virtual void on_message(const Glib::RefPtr<Gst::Message>& message);
590 /// This is a default handler for the signal signal_sync_message().
591 virtual void on_sync_message(const Glib::RefPtr<Gst::Message>& message);
592
593
594 };
595
596 /*! A gstreamermm Gst::Bus example.
597 * @example basics/bus.cc
598 */
599
600 } //namespace Gst
601
602
603 namespace Glib
604 {
605 /** A Glib::wrap() method for this object.
606 *
607 * @param object The C instance.
608 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
609 * @result A C++ instance that wraps this C instance.
610 *
611 * @relates Gst::Bus
612 */
613 Glib::RefPtr<Gst::Bus> wrap(GstBus* object, bool take_copy = false);
614 }
615
616
617 #endif /* _GSTREAMERMM_BUS_H */
618