| 1 |
/* gstreamermm - a C++ wrapper for gstreamer |
| 2 |
* |
| 3 |
* Copyright 2008-2016 The gstreamermm Development Team |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
- version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <gstreamermm/object.h> |
| 21 |
#include <gstreamermm/clock.h> |
| 22 |
#include <gstreamermm/message.h> |
| 23 |
#include <glibmm/priorities.h> |
| 24 |
//#include <glibmm/main.h> //For Glib::Source |
| 25 |
|
| 26 |
_DEFS(gstreamermm,gst) |
| 27 |
|
| 28 |
namespace Gst |
| 29 |
{ |
| 30 |
|
| 31 |
class Message; |
| 32 |
|
| 33 |
_WRAP_ENUM(BusFlags, GstBusFlags) |
| 34 |
|
| 35 |
_WRAP_ENUM(BusSyncReply, GstBusSyncReply) |
| 36 |
|
| 37 |
/** A class that encompasses the GStreamer asynchronous message bus subsystem. |
| 38 |
* The Gst::Bus is an object responsible for delivering Messages in a first-in |
| 39 |
* first-out way from the streaming threads to the application. |
| 40 |
* |
| 41 |
* Since the application typically only wants to deal with delivery of these |
| 42 |
* messages from one thread, the Gst::Bus will marshall the messages between |
| 43 |
* different threads. This is important since the actual streaming of media is |
| 44 |
* done in another thread than the application. |
| 45 |
* |
| 46 |
* The Gst::Bus provides support for GSource based notifications. This makes it |
| 47 |
* possible to handle the delivery in the glib mainloop. |
| 48 |
* |
| 49 |
* The GSource callback function gst_bus_async_signal_func() can be used to |
| 50 |
* convert all bus messages into signal emissions. |
| 51 |
* |
| 52 |
* A message is posted on the bus with the post() method. With the peek() and |
| 53 |
* pop() methods one can look at or retrieve a previously posted message. |
| 54 |
* |
| 55 |
* The bus can be polled with the poll() method. This methods blocks up to the |
| 56 |
* specified timeout value until one of the specified messages types is posted |
| 57 |
* on the bus. The application can then pop() the messages from the bus to |
| 58 |
* handle them. Alternatively the application can register an asynchronous bus |
| 59 |
* function using add_watch(). This function will install a GSource in the |
| 60 |
* default glib main loop and will deliver messages a short while after they |
| 61 |
* have been posted. Note that the main loop should be running for the |
| 62 |
* asynchronous callbacks. |
| 63 |
* |
| 64 |
* It is also possible to get messages from the bus without any thread |
| 65 |
* marshalling with the set_sync_handler() method. This makes it possible to |
| 66 |
* react to a message in the same thread that posted the message on the bus. |
| 67 |
* This should only be used if the application is able to deal with messages |
| 68 |
* from different threads. |
| 69 |
* |
| 70 |
* Every Gst::Pipeline has one bus. |
| 71 |
* |
| 72 |
* Note that a Gst::Pipeline will set its bus into flushing state when |
| 73 |
* changing from READY to NULL state. |
| 74 |
* |
| 75 |
* Last reviewed on 2016-05-16 (1.8.0) |
| 76 |
*/ |
| 77 |
class Bus : public Object |
| 78 |
{ |
| 79 |
_CLASS_GOBJECT(Bus, GstBus, GST_BUS, Object, GstObject) |
| 80 |
|
| 81 |
protected: |
| 82 |
_CTOR_DEFAULT() |
| 83 |
|
| 84 |
public: |
| 85 |
/** For example, |
| 86 |
* bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus, const |
| 87 |
* Glib::RefPtr<Gst::Message>& message);. |
| 88 |
* The message function should return true if it wants to continue to receive |
| 89 |
* messages, or false otherwise. |
| 90 |
*/ |
| 91 |
typedef sigc::slot< bool, const Glib::RefPtr<Gst::Bus>&, const Glib::RefPtr<Gst::Message>& > SlotMessage; |
| 92 |
|
| 93 |
/** For example, |
| 94 |
* BusSyncReply on_bus_sync_message(const Glib::RefPtr<Gst::Bus>& bus, const |
| 95 |
* Glib::RefPtr<Gst::Message>& message);. |
| 96 |
*/ |
| 97 |
typedef sigc::slot< BusSyncReply, const Glib::RefPtr<Gst::Bus>&, const Glib::RefPtr<Gst::Message>& > SlotMessageSync; |
| 98 |
|
| 99 |
/** Creates a new Gst::Bus instance. |
| 100 |
* |
| 101 |
* @return The new Gst::Bus instance. |
| 102 |
*/ |
| 103 |
_WRAP_CREATE() |
| 104 |
|
| 105 |
_WRAP_METHOD(bool post(Glib::RefPtr<Gst::Message>&& message), gst_bus_post) |
| 106 |
_WRAP_METHOD(bool have_pending() const, gst_bus_have_pending) |
| 107 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> peek(), gst_bus_peek) |
| 108 |
_WRAP_METHOD(Glib::RefPtr<const Gst::Message> peek() const, gst_bus_peek) |
| 109 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> pop(), gst_bus_pop) |
| 110 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> pop(MessageType message_type), gst_bus_pop_filtered) |
| 111 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> pop(ClockTime timeout), gst_bus_timed_pop) |
| 112 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> pop(ClockTime timeout, MessageType message_type), gst_bus_timed_pop_filtered) |
| 113 |
_WRAP_METHOD(void set_flushing(bool flushing = true), gst_bus_set_flushing) |
| 114 |
|
| 115 |
//TODO Glib::Source has a strange cobject constructor. |
| 116 |
//#m4 _CONVERSION(`GSource*',`Glib::RefPtr<Glib::Source>', `Glib::wrap($3)') |
| 117 |
// _WRAP_METHOD(Glib::RefPtr<Glib::Source> create_watch(), gst_bus_create_watch) |
| 118 |
|
| 119 |
/** Adds a bus watch to the default main context with the given priority. |
| 120 |
* The slot is used to receive asynchronous messages in the main loop. |
| 121 |
* |
| 122 |
* The watch can be removed using remove_watch() or by returning false from |
| 123 |
* slot. |
| 124 |
* |
| 125 |
* @param slot The slot to call when a message is received. |
| 126 |
* @param priority The priority of the watch. |
| 127 |
* @return The event source id. MT safe. |
| 128 |
*/ |
| 129 |
guint add_watch(const SlotMessage& slot, int priority = Glib::PRIORITY_DEFAULT); |
| 130 |
_IGNORE(gst_bus_add_watch, gst_bus_add_watch_full) |
| 131 |
|
| 132 |
/** Removes bus watch with event source id from main context. |
| 133 |
* |
| 134 |
* @param watch_id The event source id. |
| 135 |
* @return true if removal was succesful, false otherwise. |
| 136 |
*/ |
| 137 |
bool remove_watch(guint watch_id); |
| 138 |
_IGNORE(gst_bus_remove_watch) |
| 139 |
|
| 140 |
/** Sets the synchronous handler on the bus. The slot will be called every |
| 141 |
* time a new message is posted on the bus. Note that the function will be |
| 142 |
* called in the same thread context as the posting object (synchronously). |
| 143 |
* This function is usually only called by the creator of the bus. |
| 144 |
* Applications should handle messages asynchronously using the watch and |
| 145 |
* poll functions or enable the "sync-message" signal emission with |
| 146 |
* enable_sync_message_emission(). |
| 147 |
* |
| 148 |
* @param slot The handler slot to install. |
| 149 |
*/ |
| 150 |
void set_sync_handler(const SlotMessageSync& slot); |
| 151 |
_IGNORE(gst_bus_set_sync_handler, gst_bus_sync_signal_handler) |
| 152 |
_IGNORE(gst_bus_async_signal_func) |
| 153 |
|
| 154 |
_WRAP_METHOD(void disable_sync_message_emission(), gst_bus_disable_sync_message_emission) |
| 155 |
_WRAP_METHOD(void enable_sync_message_emission(), gst_bus_enable_sync_message_emission) |
| 156 |
|
| 157 |
_WRAP_METHOD(void add_signal_watch(int priority = Glib::PRIORITY_DEFAULT), gst_bus_add_signal_watch_full) |
| 158 |
_IGNORE(gst_bus_add_signal_watch) |
| 159 |
|
| 160 |
_WRAP_METHOD(void remove_signal_watch(), gst_bus_remove_signal_watch) |
| 161 |
_WRAP_METHOD(Glib::RefPtr<Gst::Message> poll(MessageType message_type, ClockTime timeout), gst_bus_poll) |
| 162 |
|
| 163 |
#m4 _CONVERSION(`GstMessage*',`const Glib::RefPtr<Gst::Message>&', `Glib::wrap($3, true)') |
| 164 |
|
| 165 |
_WRAP_SIGNAL(void message(const Glib::RefPtr<Gst::Message>& message), "message") |
| 166 |
_WRAP_SIGNAL(void sync_message(const Glib::RefPtr<Gst::Message>& message), "sync-message") |
| 167 |
}; |
| 168 |
|
| 169 |
/*! A gstreamermm Gst::Bus example. |
| 170 |
* @example basics/bus.cc |
| 171 |
*/ |
| 172 |
|
| 173 |
} //namespace Gst |