| 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/element.h> |
| 21 |
#include <gstreamermm/childproxy.h> |
| 22 |
|
| 23 |
|
| 24 |
_DEFS(gstreamermm,gst) |
| 25 |
|
| 26 |
namespace Gst |
| 27 |
{ |
| 28 |
|
| 29 |
class Pad; |
| 30 |
class GhostPad; |
| 31 |
|
| 32 |
//Gst::Iterator<> forward declaration. |
| 33 |
template <class CppType> |
| 34 |
class Iterator; |
| 35 |
|
| 36 |
_WRAP_ENUM(BinFlags, GstBinFlags) |
| 37 |
|
| 38 |
/** |
| 39 |
* Base class and element that can contain other elements |
| 40 |
* |
| 41 |
* Gst::Bin is an element that can contain other Gst::Element, allowing them to be |
| 42 |
* managed as a group. |
| 43 |
* Pads from the child elements can be ghosted to the bin, see Gst::GhostPad. |
| 44 |
* This makes the bin look like any other elements and enables creation of |
| 45 |
* higher-level abstraction elements. |
| 46 |
* |
| 47 |
* A new Gst::Bin is created with create(). Use a Gst::Pipeline instead if you |
| 48 |
* want to create a toplevel bin because a normal bin doesn't have a bus or |
| 49 |
* handle clock distribution of its own. |
| 50 |
* |
| 51 |
* After the bin has been created you will typically add elements to it with |
| 52 |
* add(). You can remove elements with remove(). |
| 53 |
* |
| 54 |
* An element can be retrieved from a bin with get_element(), using the |
| 55 |
* elements name. get_element_recurse_up() is mainly used for internal |
| 56 |
* purposes and will query the parent bins when the element is not found in the |
| 57 |
* current bin. |
| 58 |
* |
| 59 |
* An iterator of elements in a bin can be retrieved with |
| 60 |
* iterate_elements(). Various other iterators exist to retrieve the |
| 61 |
* elements in a bin. |
| 62 |
* |
| 63 |
* The element-added signal is fired whenever a new element is added to |
| 64 |
* the bin. Likewise the element-removed signal is fired whenever an |
| 65 |
* element is removed from the bin. |
| 66 |
* |
| 67 |
* Notes: |
| 68 |
* |
| 69 |
* A Gst::Bin internally intercepts every Gst::Message posted by its children and |
| 70 |
* implements the following default behaviour for each of them: |
| 71 |
* |
| 72 |
* - Gst::MESSAGE_EOS - This message is only posted by sinks in the PLAYING |
| 73 |
* state. If all sinks posted the EOS message, this bin will post and EOS |
| 74 |
* message upwards. |
| 75 |
* |
| 76 |
* - Gst::MESSAGE_SEGMENT_START - just collected and never forwarded upwards. |
| 77 |
* The messages are used to decide when all elements have completed playback |
| 78 |
* of their segment. |
| 79 |
* |
| 80 |
* - Gst::MESSAGE_SEGMENT_DONE - Is posted by Gst::Bin when all elements that posted |
| 81 |
* a SEGMENT_START have posted a SEGMENT_DONE. |
| 82 |
* |
| 83 |
* - Gst::MESSAGE_DURATION_CHANGED - Is posted by an element that detected a change |
| 84 |
* in the stream duration. The default bin behaviour is to clear any |
| 85 |
* cached duration values so that the next duration query will perform |
| 86 |
* a full duration recalculation. The duration change is posted to the |
| 87 |
* application so that it can refetch the new duration with a duration |
| 88 |
* query. Note that these messages can be posted before the bin is |
| 89 |
* prerolled, in which case the duration query might fail. |
| 90 |
* |
| 91 |
* - Gst::MESSAGE_CLOCK_LOST - This message is posted by an element when it |
| 92 |
* can no longer provide a clock. The default bin behaviour is to |
| 93 |
* check if the lost clock was the one provided by the bin. If so and |
| 94 |
* the bin is currently in the PLAYING state, the message is forwarded to |
| 95 |
* the bin parent. |
| 96 |
* This message is also generated when a clock provider is removed from |
| 97 |
* the bin. If this message is received by the application, it should |
| 98 |
* PAUSE the pipeline and set it back to PLAYING to force a new clock |
| 99 |
* distribution. |
| 100 |
* |
| 101 |
* - Gst::MESSAGE_CLOCK_PROVIDE - This message is generated when an element |
| 102 |
* can provide a clock. This mostly happens when a new clock |
| 103 |
* provider is added to the bin. The default behaviour of the bin is to |
| 104 |
* mark the currently selected clock as dirty, which will perform a clock |
| 105 |
* recalculation the next time the bin is asked to provide a clock. |
| 106 |
* This message is never sent tot the application but is forwarded to |
| 107 |
* the parent of the bin. |
| 108 |
* |
| 109 |
* - OTHERS - posted upwards. |
| 110 |
* |
| 111 |
* A Gst::Bin implements the following default behaviour for answering to a |
| 112 |
* Gst::Query: |
| 113 |
* |
| 114 |
* - Gst::QUERY_DURATION - If the query has been asked before with the same format |
| 115 |
* and the bin is a toplevel bin (ie. has no parent), |
| 116 |
* use the cached previous value. If no previous value was cached, the |
| 117 |
* query is sent to all sink elements in the bin and the MAXIMUM of all |
| 118 |
* values is returned. If the bin is a toplevel bin the value is cached. |
| 119 |
* If no sinks are available in the bin, the query fails. |
| 120 |
* |
| 121 |
* - Gst::QUERY_POSITION - The query is sent to all sink elements in the bin and the |
| 122 |
* MAXIMUM of all values is returned. If no sinks are available in the bin, |
| 123 |
* the query fails. |
| 124 |
* - OTHERS - the query is forwarded to all sink elements, the result |
| 125 |
* of the first sink that answers the query successfully is returned. If no |
| 126 |
* sink is in the bin, the query fails. |
| 127 |
* |
| 128 |
* A Gst::Bin will by default forward any event sent to it to all sink elements. |
| 129 |
* If all the sinks return true, the bin will also return true, else false is |
| 130 |
* returned. If no sinks are in the bin, the event handler will return true. |
| 131 |
* |
| 132 |
* Last reviewed on 2016-05-05 (1.8.0). |
| 133 |
* |
| 134 |
* @ingroup GstBaseClasses |
| 135 |
*/ |
| 136 |
|
| 137 |
class Bin |
| 138 |
: public Element, |
| 139 |
public ChildProxy |
| 140 |
{ |
| 141 |
_CLASS_GOBJECT(Bin, GstBin, GST_BIN, Element, GstElement) |
| 142 |
_IMPLEMENTS_INTERFACE(ChildProxy) |
| 143 |
|
| 144 |
protected: |
| 145 |
_WRAP_CTOR(Bin(const Glib::ustring& name), gst_bin_new) |
| 146 |
Bin(); |
| 147 |
|
| 148 |
public: |
| 149 |
/** Creates a new bin with the given name. |
| 150 |
* |
| 151 |
* @param name The name of the new bin. |
| 152 |
* @return A new Gst::Bin. |
| 153 |
*/ |
| 154 |
_WRAP_CREATE(const Glib::ustring& name) |
| 155 |
|
| 156 |
/** Creates a new bin with a unique generic name. |
| 157 |
* |
| 158 |
* @return A new Gst::Bin. |
| 159 |
*/ |
| 160 |
_WRAP_CREATE() |
| 161 |
|
| 162 |
/** Adds the given element to the bin. Sets the element's parent, and thus |
| 163 |
* takes ownership of the element. An element can only be added to one bin. |
| 164 |
* |
| 165 |
* If the element's pads are linked to other pads, the pads will be unlinked |
| 166 |
* before the element is added to the bin. |
| 167 |
* |
| 168 |
* When you add an element to an already-running pipeline, you will have to |
| 169 |
* take care to set the state of the newly-added element to the desired |
| 170 |
* state (usually PLAYING or PAUSED, same you set the pipeline to originally) |
| 171 |
* with set_state(), or use sync_state_with_parent(). |
| 172 |
* The bin or pipeline will not take care of this for you. |
| 173 |
* |
| 174 |
* MT safe. |
| 175 |
* |
| 176 |
* @param element The Gst::Element to add. |
| 177 |
* @return This Gst::Bin if successful, for chained calls to add(). |
| 178 |
* |
| 179 |
* @throws std::runtime_error if the Bin does not want to accept the Element. |
| 180 |
*/ |
| 181 |
Glib::RefPtr<Gst::Bin> add(const Glib::RefPtr<Gst::Element>& element); |
| 182 |
_IGNORE(gst_bin_add, gst_bin_add_many) |
| 183 |
|
| 184 |
/** Removes the element from the bin, unparenting it as well. |
| 185 |
* Unparenting the element means that the element will be dereferenced, |
| 186 |
* so if the bin holds the only reference to the element, the element |
| 187 |
* will be freed in the process of removing it from the bin. |
| 188 |
* |
| 189 |
* If the element's pads are linked to other pads, the pads will be unlinked |
| 190 |
* before the element is removed from the bin. |
| 191 |
* |
| 192 |
* MT safe. |
| 193 |
* |
| 194 |
* @param element the Gst::Element to remove |
| 195 |
* @return this Gst::Bin if successful, for chained calls to remove(). |
| 196 |
* |
| 197 |
* @throws std::runtime_error if the Bin does not want to remove the Element. |
| 198 |
*/ |
| 199 |
Glib::RefPtr<Gst::Bin> remove(const Glib::RefPtr<Gst::Element>& element); |
| 200 |
_IGNORE(gst_bin_remove, gst_bin_remove_many) |
| 201 |
|
| 202 |
//We could add a bool recurse_up = false parameter, |
| 203 |
//but get_element() and get_element_recurse_up() seem different enough to be separate. |
| 204 |
//One recurses down and the other recurses up, so it's not just additional behaviour. |
| 205 |
_WRAP_METHOD(Glib::RefPtr<Gst::Element> get_element(const Glib::ustring& name), gst_bin_get_by_name) |
| 206 |
_WRAP_METHOD(Glib::RefPtr<const Gst::Element> get_element(const Glib::ustring& name) const, gst_bin_get_by_name, constversion) |
| 207 |
|
| 208 |
_WRAP_METHOD(Glib::RefPtr<Gst::Element> get_element_recurse_up(const Glib::ustring& name), gst_bin_get_by_name_recurse_up) |
| 209 |
_WRAP_METHOD(Glib::RefPtr<const Gst::Element> get_element_recurse_up(const Glib::ustring& name) const, gst_bin_get_by_name_recurse_up, constversion) |
| 210 |
|
| 211 |
_WRAP_METHOD(Glib::RefPtr<Gst::Element> get_element(GType interface), gst_bin_get_by_interface) |
| 212 |
_WRAP_METHOD(Glib::RefPtr<const Gst::Element> get_element(GType interface) const, gst_bin_get_by_interface, constversion) |
| 213 |
|
| 214 |
/** Adds a ghost pad to the bin using an element's static pad as a target. |
| 215 |
* @param element The element with the target static pad. |
| 216 |
* @param pad_name The static pad to use as the target. |
| 217 |
* @param name An optional name for the ghost pad. |
| 218 |
* @return The newly created Gst::GhostPad. |
| 219 |
*/ |
| 220 |
Glib::RefPtr<Gst::GhostPad> add_ghost_pad(const Glib::RefPtr<Gst::Element>& |
| 221 |
element, const Glib::ustring& pad_name, const Glib::ustring& name = |
| 222 |
Glib::ustring()); |
| 223 |
|
| 224 |
_WRAP_METHOD(Glib::RefPtr<Gst::Pad> find_unlinked_pad(PadDirection dir), gst_bin_find_unlinked_pad) |
| 225 |
_WRAP_METHOD(Glib::RefPtr<const Gst::Pad> find_unlinked_pad(PadDirection dir) const, gst_bin_find_unlinked_pad, constversion) |
| 226 |
|
| 227 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_elements(), gst_bin_iterate_elements) |
| 228 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_elements() const, gst_bin_iterate_elements) |
| 229 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_recurse(), gst_bin_iterate_recurse) |
| 230 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_recurse() const, gst_bin_iterate_recurse) |
| 231 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_sorted(), gst_bin_iterate_sorted) |
| 232 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_sorted() const, gst_bin_iterate_sorted) |
| 233 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_sources(), gst_bin_iterate_sources) |
| 234 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_sources() const, gst_bin_iterate_sources) |
| 235 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_sinks(), gst_bin_iterate_sinks) |
| 236 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_sinks() const, gst_bin_iterate_sinks) |
| 237 |
_WRAP_METHOD(Gst::Iterator<Gst::Element> iterate_by_interface(GType iface), gst_bin_iterate_all_by_interface) |
| 238 |
_WRAP_METHOD(Gst::Iterator<const Gst::Element> iterate_by_interface(GType iface) const, gst_bin_iterate_all_by_interface) |
| 239 |
_WRAP_METHOD(bool sync_children_states(), gst_bin_sync_children_states) |
| 240 |
|
| 241 |
_WRAP_METHOD(bool recalculate_latency(), gst_bin_recalculate_latency) |
| 242 |
|
| 243 |
#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<Gst::Element> >',`$2($3, Glib::OWNERSHIP_NONE)') |
| 244 |
/** Gets the bin's list of children. |
| 245 |
*/ |
| 246 |
_MEMBER_GET(children, children, Glib::ListHandle< Glib::RefPtr<Gst::Element> >, GList*) |
| 247 |
|
| 248 |
/** Gets the children cookie. |
| 249 |
*/ |
| 250 |
_MEMBER_GET(children_cookie, children_cookie, guint32, guint32) |
| 251 |
|
| 252 |
/** Gets the number of children in the bin. |
| 253 |
*/ |
| 254 |
_MEMBER_GET(num_children, numchildren, int, int) |
| 255 |
|
| 256 |
/** Gets the internal bus for handling child messages. |
| 257 |
*/ |
| 258 |
_MEMBER_GET_GOBJECT(child_bus,child_bus, Gst::Bus, GstBus*) |
| 259 |
|
| 260 |
#m4 _CONVERSION(`GList*',`Glib::ListHandle< Glib::RefPtr<Gst::Message> >',`$2($3, Glib::OWNERSHIP_NONE)') |
| 261 |
/** Gets the bin's queued and cached messages. |
| 262 |
*/ |
| 263 |
_MEMBER_GET(messages, messages, Glib::ListHandle< Glib::RefPtr<Gst::Message> >, GList*) |
| 264 |
|
| 265 |
/** Gets whether the bin is currently calculating its state. |
| 266 |
*/ |
| 267 |
_MEMBER_GET(polling, polling, bool, gboolean) |
| 268 |
|
| 269 |
/** Gets whether the bin needs to select a new clock. |
| 270 |
*/ |
| 271 |
_MEMBER_GET(clock_dirty, clock_dirty, bool, gboolean) |
| 272 |
|
| 273 |
/** Gets the last clock selected. |
| 274 |
*/ |
| 275 |
_MEMBER_GET_GOBJECT(provided_clock, provided_clock, Gst::Clock, GstClock*) |
| 276 |
|
| 277 |
/** Gets the element that provided @a provided_clock. |
| 278 |
*/ |
| 279 |
_MEMBER_GET_GOBJECT(clock_provider, clock_provider, Gst::Element, GstElement*) |
| 280 |
|
| 281 |
_WRAP_PROPERTY("async-handling", bool) |
| 282 |
_WRAP_PROPERTY("message-forward", bool) |
| 283 |
|
| 284 |
#m4 _CONVERSION(`GstElement*',`const Glib::RefPtr<Gst::Element>&', `Glib::wrap($3, true)') |
| 285 |
|
| 286 |
_WRAP_SIGNAL(void element_added(const Glib::RefPtr<Gst::Element>& element), "element-added") |
| 287 |
_WRAP_SIGNAL(void element_removed(const Glib::RefPtr<Gst::Element>& element), "element-removed") |
| 288 |
|
| 289 |
//TODO: The default signal handler is marked as private in the C header. Is that intendend? |
| 290 |
_WRAP_SIGNAL(bool do_latency(), "do-latency") |
| 291 |
|
| 292 |
/** Method to add an element to a bin. |
| 293 |
*/ |
| 294 |
_WRAP_VFUNC(bool add_element(const Glib::RefPtr<Gst::Element>& element), "add_element") |
| 295 |
|
| 296 |
/** Method to remove an element from a bin. |
| 297 |
*/ |
| 298 |
_WRAP_VFUNC(bool remove_element(const Glib::RefPtr<Gst::Element>& element), "remove_element") |
| 299 |
|
| 300 |
#m4 _CONVERSION(`GstMessage*',`const Glib::RefPtr<Gst::Message>&',`Glib::wrap($3, true)') |
| 301 |
/** Method to handle a message from the children. |
| 302 |
*/ |
| 303 |
_WRAP_VFUNC(void handle_message(const Glib::RefPtr<Gst::Message>& message), "handle_message") |
| 304 |
}; |
| 305 |
|
| 306 |
/*! A gstreamermm Gst::Bin example. |
| 307 |
* @example basics/bin.cc |
| 308 |
*/ |
| 309 |
|
| 310 |
} //namespace Gst |