Debian Codegraph @

gstreamer/src/element.hg

raw
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 <gst/gstelement.h>
21 #include <gstreamermm/object.h>
22 #include <gstreamermm/clock.h>
23 #include <gstreamermm/enums.h>
24 #include <gstreamermm/error.h>
25 #include <gstreamermm/message.h>
26
27 _DEFS(gstreamermm,gst)
28
29 namespace Gst
30 {
31
32 /** @defgroup GstBaseClasses gstreamermm Base Classes
33 * Wrapped GStreamer base classes (plug-ins derrive from these).
34 */
35
36 /** @defgroup GstPlugins gstreamermm Plugins
37 * Wrapped GStreamer plugins.
38 */
39
40 /** @defgroup GstInterfaces gstreamermm Interfaces
41 * Wrapped GStreamer interfaces and classes related to them.
42 */
43
44 class Bus;
45 class Caps;
46 class Context;
47 class ElementFactory;
48 class Event;
49 class Pad;
50 class PadTemplate;
51 class Query;
52
53 //Gst::Iterator<> forward declaration.
54 template <class CppType>
55 class Iterator;
56
57 _WRAP_ENUM(ElementFlags, GstElementFlags)
58 _WRAP_ENUM(StateChange, GstStateChange)
59 _WRAP_ENUM(StateChangeReturn, GstStateChangeReturn)
60
61 namespace Enums
62 {
63
64 /** Gets a string representing the given state.
65 *
66 * @param state A Gst::State to get the name of.
67 * @return A Glib::ustring with the name of the state.
68 */
69 Glib::ustring get_name(State state);
70
71 /** Gets a string representing the given state change result.
72 *
73 * @param state_ret A Gst::StateChangeReturn to get the name of.
74 * @return A Glib::ustring with the name of the state change result.
75 */
76 Glib::ustring get_name(StateChangeReturn state_ret);
77
78 } //namespace Enums
79
80 /** Abstract base class for all pipeline elements
81 *
82 * Gst::Element is the abstract base class needed to construct an element that
83 * can be used in a GStreamer pipeline. Please refer to the plugin writers
84 * guide for more information on creating Gst::Element subclasses.
85 *
86 * The name of a Gst::Element can be get with get_name() and set with
87 * set_name().
88 *
89 * Elements can have pads (of the type Gst::Pad). These pads link to pads on
90 * other elements. Gst::Buffer flow between these linked pads.
91 * A Gst::Element has a GList of Gst::Pad structures for all their input (or sink)
92 * and output (or source) pads.
93 * Core and plug-in writers can add and remove pads with add_pad()
94 * and remove_pad().
95 *
96 * An existing pad of an element can be retrieved by name with
97 * get_static_pad(). A new dynamic pad can be created using
98 * request_pad() with a Gst::PadTemplate.
99 * An iterator of all pads can be retrieved with iterate_pads().
100 *
101 * Elements can be linked through their pads.
102 * If the link is straightforward, use the link()
103 * convenience function to link two elements.
104 * Use link_filtered() to link two elements constrained by
105 * a specified set of Gst::Caps.
106 * For finer control, use link_pads() and
107 * link_pads_filtered() to specify the pads to link on
108 * each element by name.
109 *
110 * Each element has a state (see Gst::State). You can get and set the state
111 * of an element with get_state() and set_state().
112 * Setting a state triggers a Gst::StateChange. To get a string representation
113 * of a Gst::State, use Gst::Enums::get_name().
114 *
115 * You can get and set a Gst::Clock on an element using get_clock()
116 * and set_clock().
117 * Some elements can provide a clock for the pipeline if
118 * the Gst::ELEMENT_FLAG_PROVIDE_CLOCK flag is set. With the
119 * provide_clock() method one can retrieve the clock provided by
120 * such an element.
121 * Not all elements require a clock to operate correctly. If the
122 * Gst::ELEMENT_FLAG_REQUIRE_CLOCK flag is set, a clock should be set on the
123 * element with set_clock().
124 *
125 * Note that clock selection and distribution is normally handled by the
126 * toplevel Gst::Pipeline so the clock functions are only to be used in very
127 * specific situations.
128 *
129 * Last reviewed on 2016-05-18 (1.8.0).
130 *
131 * @ingroup GstBaseClasses
132 */
133 class Element : public Gst::Object
134 {
135 _CLASS_GOBJECT(Element, GstElement, GST_ELEMENT, Gst::Object, GstObject)
136
137 public:
138 /** Links this source element to the @a dest element.
139 * The link must be from source to destination - the other direction will not
140 * be tried. The function looks for existing pads that aren't linked yet. It
141 * will request new pads if necessary. Such pads need to be released manually
142 * when unlinking. If multiple links are possible, only one is established.
143 *
144 * Make sure you have added your elements to a bin or pipeline with
145 * Gst::Bin::add() before trying to link them.
146 *
147 * @param dest the Gst::Element containing the destination pad.
148 * @return the destination element for further linking if desired.
149 * @throws std::runtime_error If the elements could not be linked.
150 */
151 Glib::RefPtr<Gst::Element> link(const Glib::RefPtr<Gst::Element>& dest);
152 _IGNORE(gst_element_link, gst_element_link_many)
153
154 _WRAP_METHOD(bool add_pad(const Glib::RefPtr<Gst::Pad>& pad), gst_element_add_pad)
155 _WRAP_METHOD(void create_all_pads(), gst_element_create_all_pads)
156
157 _WRAP_METHOD(Glib::RefPtr<Gst::Pad> create_compatible_pad(const Glib::RefPtr<const Gst::Pad>& pad, const Glib::RefPtr<const Gst::Caps>& caps), gst_element_get_compatible_pad)
158 _WRAP_METHOD(Glib::RefPtr<Gst::PadTemplate> get_compatible_pad_template(const Glib::RefPtr<const Gst::PadTemplate>& compattempl), gst_element_get_compatible_pad_template, refreturn)
159 _WRAP_METHOD(Glib::RefPtr<const Gst::PadTemplate> get_compatible_pad_template(const Glib::RefPtr<const Gst::PadTemplate>& compattempl) const, gst_element_get_compatible_pad_template, refreturn, constversion)
160
161 //TODO: The documentation says "The pad should be released with gst_element_release_request_pad().", which is odd. murrayc
162 _WRAP_METHOD(Glib::RefPtr<Gst::Pad> get_request_pad(const Glib::ustring& name), gst_element_get_request_pad)
163
164 //TODO: The documentation says "The pad should be released with gst_element_release_request_pad().", which is odd. murrayc
165 _WRAP_METHOD(Glib::RefPtr<Gst::Pad> request_pad(const Glib::RefPtr<Gst::PadTemplate>& templ, const Glib::ustring& name{?}, const Glib::RefPtr<const Gst::Caps>& caps{?}), gst_element_request_pad)
166
167 _WRAP_METHOD(Glib::RefPtr<Gst::Pad> get_static_pad(const Glib::ustring& name), gst_element_get_static_pad)
168 _WRAP_METHOD(Glib::RefPtr<const Gst::Pad> get_static_pad(const Glib::ustring& name) const, gst_element_get_static_pad, constversion)
169
170 _WRAP_METHOD(void no_more_pads(), gst_element_no_more_pads)
171
172 /** Makes the element free the previously requested pad as obtained with
173 * get_request_pad().
174 * MT safe.
175 * @param pad The Gst::Pad to release.
176 */
177 _WRAP_METHOD(void release_request_pad(const Glib::RefPtr<Gst::Pad>& pad), gst_element_release_request_pad)
178
179 _WRAP_METHOD(bool remove_pad(const Glib::RefPtr<Gst::Pad>& pad), gst_element_remove_pad)
180 _WRAP_METHOD(Gst::Iterator<Gst::Pad> iterate_pads(), gst_element_iterate_pads)
181 _WRAP_METHOD(Gst::Iterator<const Gst::Pad> iterate_pads() const, gst_element_iterate_pads)
182 _WRAP_METHOD(Gst::Iterator<Gst::Pad> iterate_sink_pads(), gst_element_iterate_sink_pads)
183 _WRAP_METHOD(Gst::Iterator<const Gst::Pad> iterate_sink_pads() const, gst_element_iterate_sink_pads)
184 _WRAP_METHOD(Gst::Iterator<Gst::Pad> iterate_src_pads(), gst_element_iterate_src_pads)
185 _WRAP_METHOD(Gst::Iterator<const Gst::Pad> iterate_src_pads() const, gst_element_iterate_src_pads)
186 _WRAP_METHOD(void unlink(const Glib::RefPtr<Gst::Element>& dest), gst_element_unlink)
187 _WRAP_METHOD(void set_context(const Glib::RefPtr<Gst::Context>& context), gst_element_set_context)
188 _IGNORE(gst_element_unlink_many)
189
190 //This is not like link() because link() was written to return the
191 //destination element as a convenience for further linking to compensate for
192 //C API's convenience function gst_element_link_many().
193 _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr<Gst::Element>& dest, const Glib::ustring& destpadname), gst_element_link_pads)
194
195 _WRAP_METHOD(void unlink_pads(const Glib::ustring& srcpadname, const Glib::RefPtr<Gst::Element>& dest, const Glib::ustring& destpadname), gst_element_unlink_pads)
196
197 //This is not like link() because link() was written to return the
198 //destination element as a convenience for further linking to compensate for
199 //C API's convenience function gst_element_link_many().
200 _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr<Gst::Element>& dest, const Glib::ustring& destpadname, const Glib::RefPtr<Gst::Caps>& filter), gst_element_link_pads_filtered)
201
202 //This is not like link() because link() was written to return the
203 //destination element as a convenience for further linking to compensate for
204 //C API's convenience function gst_element_link_many().
205 _WRAP_METHOD(bool link_pads(const Glib::ustring& srcpadname, const Glib::RefPtr<Gst::Element>& dest, const Glib::ustring& destpadname, PadLinkCheck flags), gst_element_link_pads_full)
206
207 /** Links @a src to @a dest using the given caps as filtercaps. The link must
208 * be from source to destination; the other direction will not be tried. The
209 * function looks for existing pads that aren't linked yet. It will request
210 * new pads if necessary. If multiple links are possible, only one is
211 * established.
212 *
213 * Make sure you have added your elements to a bin or pipeline with
214 * Gst::Bin::add() before trying to link them.
215 *
216 * @param dest The Gst::Element containing the destination pad.
217 * @param filter The Gst::Caps to filter the link.
218 * @return the destination element for further linking if desired.
219 * @throws std::runtime_error If the elements could not be linked.
220 */
221 Glib::RefPtr<Gst::Element> link(const Glib::RefPtr<Gst::Element>& dest, const Glib::RefPtr<Gst::Caps>& filter);
222 _IGNORE(gst_element_link_filtered)
223
224 _WRAP_METHOD(void set_base_time(ClockTime time), gst_element_set_base_time)
225 _WRAP_METHOD(ClockTime get_base_time() const, gst_element_get_base_time)
226 _WRAP_METHOD(void set_start_time(Gst::ClockTime time), gst_element_set_start_time)
227 _WRAP_METHOD(Gst::ClockTime get_start_time() const, gst_element_get_start_time)
228 _WRAP_METHOD(void set_bus(const Glib::RefPtr<Gst::Bus>& bus), gst_element_set_bus)
229 _WRAP_METHOD(Glib::RefPtr<Gst::Bus> get_bus(), gst_element_get_bus)
230 _WRAP_METHOD(Glib::RefPtr<const Gst::Bus> get_bus() const, gst_element_get_bus, constversion)
231
232 _WRAP_METHOD(Glib::RefPtr<Gst::ElementFactory> get_factory(), gst_element_get_factory, refreturn)
233 _WRAP_METHOD(Glib::RefPtr<const Gst::ElementFactory> get_factory() const, gst_element_get_factory, refreturn, constversion)
234
235 // We don't wrap the gst_element_get_name(), gst_element_set_name(),
236 // gst_element_get_parent(), and gst_element_set_parent() macros because they
237 // just calls the base (GstObject) class's functions anyway.
238
239 _WRAP_METHOD(bool set_clock(const Glib::RefPtr<Gst::Clock>& clock), gst_element_set_clock)
240 _WRAP_METHOD(Glib::RefPtr<Gst::Clock> get_clock(), gst_element_get_clock)
241 _WRAP_METHOD(Glib::RefPtr<const Gst::Clock> get_clock() const, gst_element_get_clock, constversion)
242 _WRAP_METHOD(Glib::RefPtr<Gst::Clock> provide_clock(), gst_element_provide_clock)
243 _WRAP_METHOD(Glib::RefPtr<const Gst::Clock> provide_clock() const, gst_element_provide_clock, constversion)
244 _WRAP_METHOD(StateChangeReturn set_state(State state), gst_element_set_state)
245 _WRAP_METHOD(StateChangeReturn get_state(State& state, State& pending, ClockTime timeout) const, gst_element_get_state)
246 _WRAP_METHOD(bool set_locked_state(gboolean locked_state), gst_element_set_locked_state)
247 _WRAP_METHOD(bool is_locked_state() const, gst_element_is_locked_state)
248 _WRAP_METHOD(void abort_state(), gst_element_abort_state)
249 _WRAP_METHOD(StateChangeReturn continue_state(StateChangeReturn ret), gst_element_continue_state)
250 _WRAP_METHOD(void lost_state(), gst_element_lost_state)
251 _WRAP_METHOD(bool sync_state_with_parent(), gst_element_sync_state_with_parent)
252 _WRAP_METHOD(StateChangeReturn change_state(StateChange transition), gst_element_change_state)
253
254 /** Post an error, warning or info message on the bus from inside an element.
255 *
256 * type must be of Gst::MESSAGE_ERROR, Gst::MESSAGE_WARNING or
257 * Gst::MESSAGE_INFO.
258 *
259 * MT safe.
260 *
261 * @param code The GError code belonging to the domain.
262 * @param line The source code line where the error was generated.
263 * @param type The GstMessageType.
264 * @param domain The GStreamer GError domain this message belongs to.
265 * @param text A text string to be used as a replacement for the default
266 * message connected to code.
267 * @param debug A debug message to be used as a replacement for the default
268 * debugging information.
269 * @param file The source code file where the error was generated.
270 * @param function The source code function where the error was generated.
271 */
272 void post_message(int code, int line, MessageType type = Gst::MESSAGE_INFO,
273 const Glib::QueryQuark& domain = get_core_error_quark(),
274 const Glib::ustring& text = Glib::ustring(),
275 const Glib::ustring& debug = Glib::ustring(),
276 const Glib::ustring& file = Glib::ustring(),
277 const Glib::ustring& function = Glib::ustring());
278 _IGNORE(gst_element_message_full)
279
280 _WRAP_METHOD(bool post_message(Glib::RefPtr<Gst::Message>&& message), gst_element_post_message)
281
282 _WRAP_METHOD(bool query(const Glib::RefPtr<Gst::Query>& query) const, gst_element_query)
283 _WRAP_METHOD(bool query_convert(Gst::Format src_format, gint64 src_val, Format dest_format, gint64& dest_val) const, gst_element_query_convert)
284 _WRAP_METHOD(bool query_position(Gst::Format format, gint64& cur{?}) const, gst_element_query_position)
285 _WRAP_METHOD(bool query_duration(Gst::Format format, gint64& duration{?}) const, gst_element_query_duration)
286
287 _WRAP_METHOD(bool seek(Format format, SeekFlags seek_flags, gint64 seek_pos), gst_element_seek_simple)
288 _WRAP_METHOD(bool seek(double rate, Format format, SeekFlags flags, SeekType cur_type, gint64 cur, SeekType stop_type, gint64 stop), gst_element_seek)
289
290 _WRAP_METHOD(bool send_event(Glib::RefPtr<Gst::Event>&& event), gst_element_send_event)
291 /// A send_event() convenience overload. Allows to re-use @a event parameter after function call.
292 bool send_event(const Glib::RefPtr<Gst::Event>& event);
293
294 _WRAP_METHOD(Glib::RefPtr<Gst::Context> get_context(const Glib::ustring& context_type), gst_element_get_context)
295 _WRAP_METHOD(Glib::RefPtr<Gst::Context> get_context_unlocked(const Glib::ustring& context_type), gst_element_get_context_unlocked)
296
297 #m4 _CONVERSION(`GList*', `std::vector< Glib::RefPtr<Gst::Context> >', `Glib::ListHandler< Glib::RefPtr<Gst::Context> >::list_to_vector(const_cast<GList*>($3), Glib::OWNERSHIP_DEEP)')
298 _WRAP_METHOD(std::vector< Glib::RefPtr<Gst::Context> > get_contexts(), gst_element_get_contexts)
299
300
301 _WRAP_SIGNAL(void no_more_pads(), "no-more-pads")
302
303 #m4 _CONVERSION(`GstPad*',`const Glib::RefPtr<Gst::Pad>&',`Glib::wrap($3, true)')
304
305 _WRAP_SIGNAL(void pad_added(const Glib::RefPtr<Gst::Pad>& new_pad), "pad-added")
306 _WRAP_SIGNAL(void pad_removed(const Glib::RefPtr<Gst::Pad>& old_pad), "pad-removed")
307
308 /** Called when a request pad is to be released.
309 */
310 _WRAP_VFUNC(void release_pad(const Glib::RefPtr<Gst::Pad>& pad), "release_pad")
311
312 /** Called when a new pad is requested.
313 */
314 _WRAP_VFUNC(Glib::RefPtr<Gst::Pad> request_new_pad(Glib::RefPtr<Gst::PadTemplate> templ, const Glib::ustring& name, const Glib::RefPtr<const Gst::Caps>& caps), "request_new_pad")
315
316 /** Get the state of the element.
317 */
318 _WRAP_VFUNC(StateChangeReturn get_state(State& state, State& pending, ClockTime timeout) const, "get_state")
319
320 /** Set a new state on the element.
321 */
322 _WRAP_VFUNC(StateChangeReturn set_state(State state), "set_state")
323
324 /** Called by set_state to perform an incremental state change.
325 */
326 _WRAP_VFUNC(StateChangeReturn change_state(StateChange transition), "change_state")
327
328 /** Called immediately after a new state was set.
329 */
330 _WRAP_VFUNC(void state_changed(Gst::State oldstate, Gst::State newstate, Gst::State pending), "state_changed")
331
332 #m4 _CONVERSION(`GstBus*', `const Glib::RefPtr<Gst::Bus>&', `Glib::wrap($3, true)')
333 /** Set a Gst::Bus on the element.
334 */
335 _WRAP_VFUNC(void set_bus(const Glib::RefPtr<Gst::Bus>& bus), "set_bus")
336
337 /** Gets the Gst::Clock provided by the element.
338 */
339 _WRAP_VFUNC(Glib::RefPtr<Gst::Clock> provide_clock(), "provide_clock")
340
341 #m4 _CONVERSION(`GstClock*', `const Glib::RefPtr<Gst::Clock>&', `Glib::wrap($3, true)')
342 /** Set the Gst::Clock on the element.
343 */
344 _WRAP_VFUNC(bool set_clock(const Glib::RefPtr<Gst::Clock>& clock), "set_clock", return_value true)
345
346 #m4 _CONVERSION(`GstEvent*',`const Glib::RefPtr<Gst::Event>&', `Glib::wrap($3, true)')
347 /** Send a Gst::Event to the element.
348 */
349 _WRAP_VFUNC(bool send_event(const Glib::RefPtr<Gst::Event>& event), "send_event")
350
351 #m4 _CONVERSION(`GstQuery*',`const Glib::RefPtr<Gst::Query>&', `Glib::wrap($3, true)')
352 /** Perform a Gst::Query on the element.
353 */
354 _WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query) const, "query")
355
356 /** Set a Gst::Context on the element
357 */
358 _WRAP_VFUNC(void set_context(const Glib::RefPtr<Gst::Context>& context), "set_context")
359
360 #m4 _CONVERSION(`GstMessage*',`const Glib::RefPtr<Gst::Message>&',`Glib::wrap($3, true)')
361 /** Called when a message is posted on the element.
362 * Chain up to the parent class' handler to have it posted on the bus.
363 */
364 _WRAP_VFUNC(bool post_message(const Glib::RefPtr<Gst::Message>& message), "post_message")
365
366 Glib::RefPtr<Gst::PadTemplate> get_pad_template(const Glib::ustring &factory_name) const;
367
368 /**
369 * Sets specified property. Allows to create property-chain
370 * (e.g. element->property("location", "test.ogg")->property("num_buffers", 20);
371 *
372 * @param name The property name.
373 * @param value The property value.
374 *
375 * @return A this element.
376 */
377 template<typename T>
378 Glib::RefPtr<Gst::Element> property(const Glib::ustring& name, const T& value)
379 {
380 set_property(name, value);
381 return Glib::RefPtr<Gst::Element>( dynamic_cast<Gst::Element*> (Glib::wrap_auto ((GObject*)(gobj()), true)) );
382 }
383 };
384
385 } // namespace Gst