Debian Codegraph @

gstreamer/src/pad.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/gst.h>
21 #include <gstreamermm/object.h>
22 #include <gstreamermm/miniobject.h>
23 #include <gstreamermm/format.h>
24 #include <gstreamermm/event.h>
25 #include <gstreamermm/bufferlist.h>
26 #include <glibmm/arrayhandle.h>
27
28 _DEFS(gstreamermm,gst)
29
30 namespace Gst
31 {
32
33 class Buffer;
34 class Caps;
35 class Element;
36 class Event;
37 class PadTemplate;
38 class Query;
39 class PadProbeInfo;
40
41 //Gst::Iterator<> forward declaration.
42 template <class CppType>
43 class Iterator;
44
45 _WRAP_ENUM(PadMode, GstPadMode)
46 _WRAP_ENUM(FlowReturn, GstFlowReturn)
47 _WRAP_ENUM(PadDirection, GstPadDirection)
48 _WRAP_ENUM(PadFlags, GstPadFlags)
49 _WRAP_ENUM(PadLinkReturn, GstPadLinkReturn)
50 _WRAP_ENUM(PadLinkCheck, GstPadLinkCheck)
51 _WRAP_ENUM(PadProbeType, GstPadProbeType)
52 _WRAP_ENUM(PadProbeReturn, GstPadProbeReturn)
53
54 /** A class that represents objects contained by elements that allows links to
55 * other elements.
56 * A Gst::Element is linked to other elements via "pads", which are extremely
57 * light-weight generic link points. After two pads are retrieved from an
58 * element with Element::get_pad(), the pads can be link with link(). (For
59 * quick links, you can also use Element::link(), which will make the obvious
60 * link for you if it's straightforward.)
61 *
62 * Pads are typically created from a Gst::PadTemplate with the create() method
63 * that takes a Gst::PadTemplate.
64 *
65 * Pads without pad templates can be created with create(), which takes a
66 * direction and a name as an argument.
67 *
68 * get_parent_element() will retrieve the Gst::Element that owns the pad.
69 *
70 * A Gst::Element creating a pad will typically use the underlying C API to
71 * register callbacks for various events on the pads.
72 *
73 * Elements will use push() and pull_range() to push out or pull in a buffer.
74 *
75 * To send a Gst::Event on a pad, use send_event() and push_event().
76 *
77 * Last reviewed on 2016-06-06 (1.8.0)
78 */
79 class Pad : public Object
80 {
81 _CLASS_GOBJECT(Pad, GstPad, GST_PAD, Object, GstObject)
82
83 protected:
84 /** Constructs a Pad given a name and a direction.
85 * @param name The desired name of the pad.
86 * @param direction The desired direction of the pad.
87 */
88 _WRAP_CTOR(Pad(const Glib::ustring& name, PadDirection direction), gst_pad_new)
89
90 /** Constructs a Pad given a direction without specifying a name. A unique
91 * name will be assigned to the pad.
92 * @param direction the direction of the pad.
93 */
94 explicit Pad(PadDirection direction);
95
96 /** Constructs a Pad from a PadTemplate with the specified name.
97 * @param templ The PadTemplate.
98 * @param name The desired name of the pad.
99 * @throw std::runtime_error if construction fails.
100 */
101 Pad(const Glib::RefPtr<const Gst::PadTemplate>& templ,
102 const Glib::ustring& name);
103
104 /** Constructs a Pad from a PadTemplate without specifying a name. A unique
105 * name will ge assigned to the pad.
106 * @param templ The PadTemplate.
107 * @throw std::runtime_error if construction fails.
108 */
109 explicit Pad(const Glib::RefPtr<const Gst::PadTemplate>& templ);
110
111 public:
112 /** For example,
113 * bool on_have_data(const Glib::RefPtr<Gst::Pad>& pad, const
114 * Glib::RefPtr<Gst::MiniObjec>& data);.
115 */
116 typedef sigc::slot< PadProbeReturn, const Glib::RefPtr<Gst::Pad>&, const Gst::PadProbeInfo& > SlotProbe;
117
118 typedef sigc::slot< Gst::FlowReturn, const Glib::RefPtr<Gst::Pad>&, /*transfer full*/ Glib::RefPtr<Gst::Buffer>& > SlotChain;
119
120 typedef sigc::slot< gboolean, const Glib::RefPtr<Gst::Pad>&, /*transfer full*/Glib::RefPtr<Gst::Event>& > SlotEvent;
121
122 typedef sigc::slot< gboolean, const Glib::RefPtr<Gst::Pad>&, /*transfer none*/ Glib::RefPtr<Gst::Query>& > SlotQuery;
123
124 typedef sigc::slot< bool, const Glib::RefPtr<Gst::Pad>& > SlotActivate;
125
126 typedef sigc::slot< bool, const Glib::RefPtr<Gst::Pad>&, Gst::PadMode, bool > SlotActivatemode;
127
128 typedef sigc::slot< Gst::FlowReturn, const Glib::RefPtr<Gst::Pad>&, guint64, guint, Glib::RefPtr<Gst::Buffer>& > SlotGetrange;
129
130 /** Creates a new pad with the given name in the given direction.
131 *
132 * @param name The name of the new pad.
133 * @param dir The PadDirection of the pad.
134 * @return A new Gst::Pad, or a null RefPtr<> in case of an error. MT safe.
135 */
136 _WRAP_CREATE(const Glib::ustring& name, PadDirection dir)
137
138 /** Creates a new pad with a guaranteed unique name (across all pads) in the
139 * given direction.
140 *
141 * @param dir The PadDirection of the pad.
142 * @return A new Gst::Pad, or a null RefPtr<> in case of an error. MT safe.
143 */
144 _WRAP_CREATE(PadDirection dir)
145
146 /** Creates a new pad with the given name from the given template.
147 *
148 * @param pad_template The pad template to use.
149 *
150 * @return A new Gst::Pad, or a null RefPtr<> in case of an error.
151 * @throw std::runtime_error if construction fails.
152 */
153 _WRAP_CREATE(const Glib::RefPtr<const Gst::PadTemplate>& pad_template)
154
155 /** Creates a new pad with a guaranteed unique name (across all pads) from
156 * the given template.
157 *
158 * @param pad_template The pad template to use.
159 * @param name The name of the pad.
160 *
161 * @return A new Gst::Pad, or a null RefPtr<> in case of an error.
162 * @throw std::runtime_error if construction fails.
163 */
164 _WRAP_CREATE(const Glib::RefPtr<const Gst::PadTemplate>& pad_template, const Glib::ustring& name)
165
166 _MEMBER_GET(mode, mode, Gst::PadMode, GstPadMode)
167
168 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> query_caps(Glib::RefPtr<Gst::Caps> caps), gst_pad_query_caps)
169 _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> query_caps(Glib::RefPtr<Gst::Caps> caps) const, gst_pad_query_caps, constversion)
170
171 _WRAP_METHOD(PadDirection get_direction() const, gst_pad_get_direction)
172 _WRAP_METHOD(Glib::RefPtr<Gst::Element> get_parent_element(), gst_pad_get_parent_element)
173 _WRAP_METHOD(Glib::RefPtr<const Gst::Element> get_parent_element() const, gst_pad_get_parent_element, constversion)
174 _WRAP_METHOD(Glib::RefPtr<Gst::PadTemplate> get_pad_template(), gst_pad_get_pad_template)
175 _WRAP_METHOD(Glib::RefPtr<const Gst::PadTemplate> get_pad_template() const, gst_pad_get_pad_template, constversion)
176 _WRAP_METHOD(PadLinkReturn link(const Glib::RefPtr<Gst::Pad>& sink_pad), gst_pad_link)
177 _WRAP_METHOD(bool unlink(const Glib::RefPtr<Gst::Pad>& sink_pad), gst_pad_unlink)
178 _WRAP_METHOD(bool is_linked() const, gst_pad_is_linked)
179 _WRAP_METHOD(bool can_link(const Glib::RefPtr<const Gst::Pad>& other_pad) const, gst_pad_can_link)
180
181 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_allowed_caps(), gst_pad_get_allowed_caps)
182 _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> get_allowed_caps() const, gst_pad_get_allowed_caps, constversion)
183
184 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_pad_template_caps(), gst_pad_get_pad_template_caps)
185 _WRAP_METHOD(Glib::RefPtr<const Gst::Caps> get_pad_template_caps() const, gst_pad_get_pad_template_caps, constversion)
186
187 gulong add_probe(PadProbeType mask, const SlotProbe& slot);
188 _IGNORE(gst_pad_add_probe)
189 _WRAP_METHOD(void remove_probe(gulong id), gst_pad_remove_probe)
190
191 _WRAP_METHOD(Glib::RefPtr<Gst::Pad> get_peer(), gst_pad_get_peer)
192 _WRAP_METHOD(Glib::RefPtr<const Gst::Pad> get_peer() const, gst_pad_get_peer, constversion)
193
194 _WRAP_METHOD(void use_fixed_caps(), gst_pad_use_fixed_caps)
195 _WRAP_METHOD(bool is_active() const, gst_pad_is_active)
196
197
198 _WRAP_METHOD(bool is_blocked() const, gst_pad_is_blocked)
199 _WRAP_METHOD(bool is_blocking() const, gst_pad_is_blocking)
200
201 _WRAP_METHOD(void mark_reconfigure(), gst_pad_mark_reconfigure)
202 _WRAP_METHOD(bool needs_reconfigure() const, gst_pad_needs_reconfigure)
203 _WRAP_METHOD(bool check_reconfigure(), gst_pad_check_reconfigure)
204
205 _WRAP_METHOD(bool has_current_caps() const, gst_pad_has_current_caps)
206
207 _WRAP_METHOD(Glib::ustring create_stream_id(const Glib::RefPtr<Gst::Element>& parent, const Glib::ustring& stream_id), gst_pad_create_stream_id)
208 _WRAP_METHOD(Glib::ustring get_stream_id() const, gst_pad_get_stream_id)
209
210 _WRAP_METHOD(void set_offset(gint64 offset), gst_pad_set_offset)
211 _WRAP_METHOD(gint64 get_offset() const, gst_pad_get_offset)
212
213 _WRAP_METHOD(void set_element_private(gpointer priv), gst_pad_set_element_private)
214 _WRAP_METHOD(gpointer get_element_private(), gst_pad_get_element_private)
215
216
217
218 //This is handwritten because conversion from Glib::RefPtr<Gst::Buffer>& to
219 //GstBuffer** is difficult.
220 /** When pad is flushing this function returns Gst::FLOW_WRONG_STATE
221 * immediatly. Calls the getrange function of pad. If pad has no getrange
222 * function installed this function returns Gst::FLOW_NOT_SUPPORTED.
223 *
224 * This is a lowlevel function. Usually pull_range() is used. This function
225 * is designed to be used with a source pad only.
226 *
227 * @param offset The start offset of the buffer.
228 * @param size The length of the buffer.
229 * @param buffer An unitialized Glib::RefPtr<> in which to store the
230 * Gst::Buffer.
231 * @return A Gst::FlowReturn from the pad (Gst::FLOW_NOT_SUPPORTED if pad is
232 * not a source pad). MT safe.
233 */
234 FlowReturn get_range(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer);
235 _IGNORE(gst_pad_get_range)
236
237 _WRAP_METHOD(bool query_accept_caps(const Glib::RefPtr<const Gst::Caps>& caps) const, gst_pad_query_accept_caps)
238 _WRAP_METHOD(bool proxy_query_caps(const Glib::RefPtr<Gst::Query>& query) const, gst_pad_proxy_query_caps)
239 _WRAP_METHOD(bool proxy_query_accept_caps(const Glib::RefPtr<Gst::Query>& query) const, gst_pad_proxy_query_accept_caps)
240 _WRAP_METHOD(bool peer_query_accept_caps(const Glib::RefPtr<const Gst::Caps>& caps) const, gst_pad_peer_query_accept_caps)
241 _WRAP_METHOD(bool peer_query_position(Gst::Format format, gint64& cur) const, gst_pad_peer_query_position)
242 _WRAP_METHOD(bool peer_query_duration(Gst::Format format, gint64& duration) const, gst_pad_peer_query_duration)
243 _WRAP_METHOD(FlowReturn push(Glib::RefPtr<Gst::Buffer>&& buffer), gst_pad_push)
244
245 _WRAP_METHOD(bool push_event(Glib::RefPtr<Gst::Event>&& event), gst_pad_push_event)
246
247 /// A push_event() convenience overload. Allows to re-use @a event parameter after function call.
248 bool push_event(const Glib::RefPtr<Gst::Event>& event);
249
250 /** Pulls a buffer from the peer pad. This function will first trigger the
251 * pad block signal if it was installed. This method works only on sink
252 * pads.
253 *
254 * When pad is not linked Gst::FLOW_NOT_LINKED is returned else this function
255 * returns the result of get_range() on the peer pad.
256 *
257 * @a buffer's caps must either be unset or the same as what is already
258 * configured on pad. Renegotiation within a running pull-mode pipeline is
259 * not supported.
260 *
261 * @param offset The start offset of the buffer.
262 * @param size The length of the buffer.
263 * @param buffer An uninitialized Glib::RefPtr<> in which to hold the
264 * Gst::Buffer.
265 * @return A Gst::FlowReturn from the peer pad (Gst::FLOW_ERROR if pad is not
266 * a sink pad). When this function returns Gst::FLOW_OK, buffer will contain
267 * a valid Gst::Buffer. @a buffer may not be used when any other return value
268 * than Gst::FLOW_OK is returned. MT safe.
269 */
270 FlowReturn pull_range(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer);
271 _IGNORE(gst_pad_pull_range)
272
273
274 _WRAP_METHOD(bool send_event(Glib::RefPtr<Gst::Event>&& event), gst_pad_send_event)
275
276 /// A send_event() convenience overload. Allows to re-use @a event parameter after function call.
277 bool send_event(const Glib::RefPtr<Gst::Event>& event);
278
279 _WRAP_METHOD(bool activate_mode(Gst::PadMode mode, bool active = true), gst_pad_activate_mode)
280 _WRAP_METHOD(bool event_default(const Glib::RefPtr<Gst::Object>& parent{?}, Glib::RefPtr<Gst::Event>&& event), gst_pad_event_default)
281 _WRAP_METHOD(bool query(const Glib::RefPtr<Gst::Query>& query) const, gst_pad_query)
282 _WRAP_METHOD(bool peer_query(const Glib::RefPtr<Gst::Query>& query) const, gst_pad_peer_query)
283 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> peer_query_caps(const Glib::RefPtr<Gst::Caps>& filter) const, gst_pad_peer_query_caps)
284 _WRAP_METHOD(bool query_default(const Glib::RefPtr<Gst::Object>& parent{?}, const Glib::RefPtr<Gst::Query>& query) const, gst_pad_query_default)
285 _WRAP_METHOD(bool query_position(Format format, gint64& position) const, gst_pad_query_position)
286
287 /** Queries a pad for the stream position parsing only the format.
288 * @param format A reference to the Gst::Format asked for. On return contains
289 * the Gst::Format used.
290 * @return true if the query could be performed.
291 */
292 bool query_position(Format& format) const;
293
294 _WRAP_METHOD(bool query_duration(Format format, gint64& duration) const, gst_pad_query_duration)
295
296 /** Queries a pad for the total stream duration parsing only the format.
297 * @param format A reference to the Gst::Format asked for. On return contains
298 * the GstFormat used.
299 * @return true if the query could be performed.
300 */
301 bool query_duration(Format& format) const;
302
303 _WRAP_METHOD(bool query_convert(Format src_format, gint64 src_value, Format dst_format, gint64& dst_value) const, gst_pad_query_convert)
304
305
306 _WRAP_METHOD(bool peer_query_convert(Format src_format, gint64 src_value, Format dst_format, gint64& dst_value) const, gst_pad_peer_query_convert)
307
308 _WRAP_METHOD(Gst::Iterator<Gst::Pad> iterate_internal_links(), gst_pad_iterate_internal_links)
309 _WRAP_METHOD(Gst::Iterator<const Gst::Pad> iterate_internal_links() const, gst_pad_iterate_internal_links)
310 _WRAP_METHOD(Gst::Iterator<Gst::Pad> iterate_internal_links_default(const Glib::RefPtr<Gst::Object>& parent{?}), gst_pad_iterate_internal_links_default)
311 _WRAP_METHOD(Gst::Iterator<const Gst::Pad> iterate_internal_links_default(const Glib::RefPtr<Gst::Object>& parent{?}) const, gst_pad_iterate_internal_links_default)
312 _WRAP_METHOD(Gst::FlowReturn chain(Glib::RefPtr<Gst::Buffer>&& buffer), gst_pad_chain)
313
314 _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_current_caps(), gst_pad_get_current_caps)
315 _WRAP_METHOD(bool pause_task() , gst_pad_pause_task)
316 _WRAP_METHOD(bool stop_task() , gst_pad_stop_task)
317 _WRAP_METHOD(bool set_active(bool active = true), gst_pad_set_active)
318
319 _WRAP_METHOD(Gst::FlowReturn get_last_flow_return() const, gst_pad_get_last_flow_return)
320
321 _WRAP_METHOD(Glib::RefPtr<Gst::Event> get_sticky_event(Gst::EventType event_type, guint idx) const, gst_pad_get_sticky_event)
322
323 static GstFlowReturn Pad_Chain_gstreamermm_callback(GstPad* pad, GstObject* parent, GstBuffer *buffer);
324 void set_chain_function(const SlotChain& slot);
325 _IGNORE(gst_pad_set_chain_function_full)
326 static gboolean Pad_Event_gstreamermm_callback(GstPad* pad, GstObject* parent, GstEvent* event);
327 void set_event_function(const SlotEvent& slot);
328 _IGNORE(gst_pad_set_event_full_function_full)
329 static gboolean Pad_Query_gstreamermm_callback(GstPad* pad, GstObject* parent, GstQuery* query);
330 void set_query_function(const SlotQuery& slot);
331 _IGNORE(gst_pad_set_query_function_full)
332 static gboolean Pad_Activate_gstreamermm_callback(GstPad* pad, GstObject* parent);
333 void set_activate_function(const SlotActivate& slot);
334 _IGNORE(gst_pad_set_activate_function_full)
335 static gboolean Pad_Activatemode_gstreamermm_callback(GstPad* pad, GstObject* parent, GstPadMode mode, gboolean active);
336 void set_activatemode_function(const SlotActivatemode& slot);
337 _IGNORE(gst_pad_set_activatemode_function_full)
338 static GstFlowReturn Pad_Getrange_gstreamermm_callback(GstPad* pad, GstObject* parent, guint64 offset, guint length, GstBuffer **buffer);
339 void set_getrange_function(const SlotGetrange& slot);
340 _IGNORE(gst_pad_set_getrange_function_full)
341
342 //C API specific pad callback setting functions are ignored.
343 _IGNORE()
344
345 #m4 _CONVERSION(`GstPad*',`const Glib::RefPtr<Gst::Pad>&',`Glib::wrap($3, true)')
346
347 _WRAP_SIGNAL(void linked(const Glib::RefPtr<Gst::Pad>& peer_pad), "linked")
348
349 _WRAP_SIGNAL(void unlinked(const Glib::RefPtr<Gst::Pad>& peer_pad), "unlinked")
350
351 _WRAP_PROPERTY("caps", Glib::RefPtr<Gst::Caps>)
352 _WRAP_PROPERTY("direction", PadDirection)
353 _WRAP_PROPERTY("template", PadTemplate)
354 _WRAP_PROPERTY("offset", gint64)
355
356 /**
357 * Checks whether pad is a ghostpad.
358 */
359 bool is_ghost_pad() const;
360 bool is_proxy_pad() const;
361
362 /**
363 * Handle exceptions occuring in callback methods
364 */
365 void exception_handler();
366
367 private:
368 SlotChain slot_chain;
369 SlotEvent slot_event;
370 SlotQuery slot_query;
371 SlotActivate slot_activate;
372 SlotActivatemode slot_activatemode;
373 SlotGetrange slot_getrange;
374 };
375
376 /*! A gstreamermm dynamic Gst::Pad example.
377 * @example basics/dynamic_pads.cc
378 */
379
380 class PadProbeInfo
381 {
382 _CLASS_GENERIC(PadProbeInfo, GstPadProbeInfo)
383
384 public:
385 PadProbeInfo();
386 explicit PadProbeInfo(GstPadProbeInfo& castitem,
387 bool take_ownership = false);
388 explicit PadProbeInfo(GstPadProbeInfo* castitem,
389 bool take_copy = false);
390 PadProbeInfo(const PadProbeInfo& other);
391 virtual ~PadProbeInfo();
392
393 GstPadProbeInfo* gobj() { return gobj_; };
394
395 const GstPadProbeInfo* gobj() const { return gobj_; };
396
397 _MEMBER_GET(id, id, gulong, gulong)
398 _WRAP_METHOD(Glib::RefPtr<Gst::Event> get_event(), gst_pad_probe_info_get_event, refreturn)
399 _WRAP_METHOD(const Glib::RefPtr<Gst::Event> get_event() const, gst_pad_probe_info_get_event, constversion, refreturn)
400 _WRAP_METHOD(Glib::RefPtr<Gst::Query> get_query(), gst_pad_probe_info_get_query)
401 _WRAP_METHOD(const Glib::RefPtr<Gst::Query> get_query() const, gst_pad_probe_info_get_query, constversion)
402 _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get_buffer(), gst_pad_probe_info_get_buffer, refreturn)
403 _WRAP_METHOD(const Glib::RefPtr<Gst::Buffer> get_buffer() const, gst_pad_probe_info_get_buffer, refreturn, constversion)
404 _WRAP_METHOD(Glib::RefPtr<Gst::BufferList> get_buffer_list(), gst_pad_probe_info_get_buffer_list)
405 _WRAP_METHOD(const Glib::RefPtr<Gst::BufferList> get_buffer_list() const, gst_pad_probe_info_get_buffer_list, constversion)
406
407 PadProbeType get_type() const;
408 protected:
409 #ifndef DOXYGEN_SHOULD_SKIP_THIS
410 GstPadProbeInfo* gobj_;
411 bool take_ownership;
412 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
413 };
414
415 } // namespace Gst
416
417 namespace Glib
418 {
419 Gst::PadProbeInfo wrap(GstPadProbeInfo* probe_info, bool take_copy);
420
421 } // namespace Glib
422