2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element with gst_element_get_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
141 guint probe_list_cookie;
151 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
156 GstPadProbeInfo *info;
163 static void gst_pad_dispose (GObject * object);
164 static void gst_pad_finalize (GObject * object);
165 static void gst_pad_set_property (GObject * object, guint prop_id,
166 const GValue * value, GParamSpec * pspec);
167 static void gst_pad_get_property (GObject * object, guint prop_id,
168 GValue * value, GParamSpec * pspec);
170 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
171 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
172 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
173 GstObject * parent, GstBufferList * list);
175 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
176 GstEvent * event, GstPadProbeType type);
177 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
178 GstEvent * event, GstPadProbeType type);
180 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
182 static GParamSpec *pspec_caps = NULL;
184 /* quarks for probe signals */
185 static GQuark buffer_quark;
186 static GQuark buffer_list_quark;
187 static GQuark event_quark;
196 static GstFlowQuarks flow_quarks[] = {
197 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
198 {GST_FLOW_OK, "ok", 0},
199 {GST_FLOW_NOT_LINKED, "not-linked", 0},
200 {GST_FLOW_FLUSHING, "flushing", 0},
201 {GST_FLOW_EOS, "eos", 0},
202 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
203 {GST_FLOW_ERROR, "error", 0},
204 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
205 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
210 * @ret: a #GstFlowReturn to get the name of.
212 * Gets a string representing the given flow return.
214 * Returns: a static string with the name of the flow return.
217 gst_flow_get_name (GstFlowReturn ret)
221 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
223 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
224 if (ret == flow_quarks[i].ret)
225 return flow_quarks[i].name;
232 * @ret: a #GstFlowReturn to get the quark of.
234 * Get the unique quark for the given GstFlowReturn.
236 * Returns: the quark associated with the flow return or 0 if an
237 * invalid return was specified.
240 gst_flow_to_quark (GstFlowReturn ret)
244 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
246 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
247 if (ret == flow_quarks[i].ret)
248 return flow_quarks[i].quark;
257 buffer_quark = g_quark_from_static_string ("buffer"); \
258 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
259 event_quark = g_quark_from_static_string ("event"); \
261 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
262 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
265 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
266 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
269 #define gst_pad_parent_class parent_class
270 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
273 gst_pad_class_init (GstPadClass * klass)
275 GObjectClass *gobject_class;
276 GstObjectClass *gstobject_class;
278 gobject_class = G_OBJECT_CLASS (klass);
279 gstobject_class = GST_OBJECT_CLASS (klass);
281 g_type_class_add_private (klass, sizeof (GstPadPrivate));
283 gobject_class->dispose = gst_pad_dispose;
284 gobject_class->finalize = gst_pad_finalize;
285 gobject_class->set_property = gst_pad_set_property;
286 gobject_class->get_property = gst_pad_get_property;
290 * @pad: the pad that emitted the signal
291 * @peer: the peer pad that has been connected
293 * Signals that a pad has been linked to the peer pad.
295 gst_pad_signals[PAD_LINKED] =
296 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
297 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
298 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
301 * @pad: the pad that emitted the signal
302 * @peer: the peer pad that has been disconnected
304 * Signals that a pad has been unlinked from the peer pad.
306 gst_pad_signals[PAD_UNLINKED] =
307 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
308 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
309 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
311 pspec_caps = g_param_spec_boxed ("caps", "Caps",
312 "The capabilities of the pad", GST_TYPE_CAPS,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
314 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
316 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
317 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
318 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
319 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
321 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
322 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
323 g_param_spec_object ("template", "Template",
324 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
325 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
327 gstobject_class->path_string_separator = ".";
329 /* Register common function pointer descriptions */
330 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
338 gst_pad_init (GstPad * pad)
340 pad->priv = GST_PAD_GET_PRIVATE (pad);
342 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
344 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
345 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
346 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
347 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
348 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
350 GST_PAD_SET_FLUSHING (pad);
352 g_rec_mutex_init (&pad->stream_rec_lock);
354 g_cond_init (&pad->block_cond);
356 g_hook_list_init (&pad->probes, sizeof (GstProbe));
358 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
361 /* called when setting the pad inactive. It removes all sticky events from
362 * the pad. must be called with object lock */
364 remove_events (GstPad * pad)
369 events = pad->priv->events;
372 for (i = 0; i < len; i++) {
373 PadEvent *ev = &g_array_index (events, PadEvent, i);
374 gst_event_unref (ev->event);
376 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
377 g_array_set_size (events, 0);
378 pad->priv->events_cookie++;
381 /* should be called with object lock */
383 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
389 events = pad->priv->events;
392 for (i = 0; i < len; i++) {
393 ev = &g_array_index (events, PadEvent, i);
394 if (ev->event == NULL)
397 if (GST_EVENT_TYPE (ev->event) == type) {
408 /* should be called with OBJECT lock */
410 find_event (GstPad * pad, GstEvent * event)
416 events = pad->priv->events;
419 for (i = 0; i < len; i++) {
420 ev = &g_array_index (events, PadEvent, i);
421 if (event == ev->event)
429 /* should be called with OBJECT lock */
431 remove_event_by_type (GstPad * pad, GstEventType type)
437 events = pad->priv->events;
442 ev = &g_array_index (events, PadEvent, i);
443 if (ev->event == NULL)
446 if (GST_EVENT_TYPE (ev->event) != type)
449 gst_event_unref (ev->event);
450 g_array_remove_index (events, i);
452 pad->priv->events_cookie++;
460 /* check all events on srcpad against those on sinkpad. All events that are not
461 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
462 * srcpad so that the events will be sent next time */
463 /* should be called with srcpad and sinkpad LOCKS */
465 schedule_events (GstPad * srcpad, GstPad * sinkpad)
470 gboolean pending = FALSE;
472 events = srcpad->priv->events;
475 for (i = 0; i < len; i++) {
476 ev = &g_array_index (events, PadEvent, i);
477 if (ev->event == NULL)
480 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
481 ev->received = FALSE;
486 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
489 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
492 /* should be called with pad LOCK */
494 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
501 events = pad->priv->events;
504 cookie = pad->priv->events_cookie;
508 PadEvent *ev, ev_ret;
510 ev = &g_array_index (events, PadEvent, i);
511 if (G_UNLIKELY (ev->event == NULL))
514 /* take aditional ref, func might release the lock */
515 ev_ret.event = gst_event_ref (ev->event);
516 ev_ret.received = ev->received;
518 ret = func (pad, &ev_ret, user_data);
520 /* recheck the cookie, lock might have been released and the list could have
522 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
523 if (G_LIKELY (ev_ret.event))
524 gst_event_unref (ev_ret.event);
528 /* store the received state */
529 ev->received = ev_ret.received;
531 /* if the event changed, we need to do something */
532 if (G_UNLIKELY (ev->event != ev_ret.event)) {
533 if (G_UNLIKELY (ev_ret.event == NULL)) {
534 /* function unreffed and set the event to NULL, remove it */
535 g_array_remove_index (events, i);
537 cookie = ++pad->priv->events_cookie;
540 /* function gave a new event for us */
541 gst_event_take (&ev->event, ev_ret.event);
544 /* just unref, nothing changed */
545 gst_event_unref (ev_ret.event);
554 /* should be called with LOCK */
556 apply_pad_offset (GstPad * pad, GstEvent * event)
558 /* check if we need to adjust the segment */
559 if (pad->offset != 0) {
562 /* copy segment values */
563 gst_event_copy_segment (event, &segment);
564 gst_event_unref (event);
566 /* adjust and make a new event with the offset applied */
567 segment.base += pad->offset;
568 event = gst_event_new_segment (&segment);
573 /* should be called with the OBJECT_LOCK */
575 get_pad_caps (GstPad * pad)
577 GstCaps *caps = NULL;
580 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
582 gst_event_parse_caps (ev->event, &caps);
588 gst_pad_dispose (GObject * object)
590 GstPad *pad = GST_PAD_CAST (object);
593 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
595 /* unlink the peer pad */
596 if ((peer = gst_pad_get_peer (pad))) {
597 /* window for MT unsafeness, someone else could unlink here
598 * and then we call unlink with wrong pads. The unlink
599 * function would catch this and safely return failed. */
600 if (GST_PAD_IS_SRC (pad))
601 gst_pad_unlink (pad, peer);
603 gst_pad_unlink (peer, pad);
605 gst_object_unref (peer);
608 gst_pad_set_pad_template (pad, NULL);
610 GST_OBJECT_LOCK (pad);
612 GST_OBJECT_UNLOCK (pad);
614 g_hook_list_clear (&pad->probes);
616 G_OBJECT_CLASS (parent_class)->dispose (object);
620 gst_pad_finalize (GObject * object)
622 GstPad *pad = GST_PAD_CAST (object);
625 /* in case the task is still around, clean it up */
626 if ((task = GST_PAD_TASK (pad))) {
627 gst_task_join (task);
628 GST_PAD_TASK (pad) = NULL;
629 gst_object_unref (task);
632 if (pad->activatenotify)
633 pad->activatenotify (pad->activatedata);
634 if (pad->activatemodenotify)
635 pad->activatemodenotify (pad->activatemodedata);
637 pad->linknotify (pad->linkdata);
638 if (pad->unlinknotify)
639 pad->unlinknotify (pad->unlinkdata);
640 if (pad->chainnotify)
641 pad->chainnotify (pad->chaindata);
642 if (pad->chainlistnotify)
643 pad->chainlistnotify (pad->chainlistdata);
644 if (pad->getrangenotify)
645 pad->getrangenotify (pad->getrangedata);
646 if (pad->eventnotify)
647 pad->eventnotify (pad->eventdata);
648 if (pad->querynotify)
649 pad->querynotify (pad->querydata);
650 if (pad->iterintlinknotify)
651 pad->iterintlinknotify (pad->iterintlinkdata);
653 g_rec_mutex_clear (&pad->stream_rec_lock);
654 g_cond_clear (&pad->block_cond);
655 g_array_free (pad->priv->events, TRUE);
657 G_OBJECT_CLASS (parent_class)->finalize (object);
661 gst_pad_set_property (GObject * object, guint prop_id,
662 const GValue * value, GParamSpec * pspec)
664 g_return_if_fail (GST_IS_PAD (object));
667 case PAD_PROP_DIRECTION:
668 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
670 case PAD_PROP_TEMPLATE:
671 gst_pad_set_pad_template (GST_PAD_CAST (object),
672 (GstPadTemplate *) g_value_get_object (value));
675 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
681 gst_pad_get_property (GObject * object, guint prop_id,
682 GValue * value, GParamSpec * pspec)
684 g_return_if_fail (GST_IS_PAD (object));
688 GST_OBJECT_LOCK (object);
689 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
690 GST_OBJECT_UNLOCK (object);
692 case PAD_PROP_DIRECTION:
693 g_value_set_enum (value, GST_PAD_DIRECTION (object));
695 case PAD_PROP_TEMPLATE:
696 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
699 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
706 * @name: the name of the new pad.
707 * @direction: the #GstPadDirection of the pad.
709 * Creates a new pad with the given name in the given direction.
710 * If name is NULL, a guaranteed unique name (across all pads)
712 * This function makes a copy of the name so you can safely free the name.
714 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
719 gst_pad_new (const gchar * name, GstPadDirection direction)
721 return g_object_new (GST_TYPE_PAD,
722 "name", name, "direction", direction, NULL);
726 * gst_pad_new_from_template:
727 * @templ: the pad template to use
728 * @name: the name of the element
730 * Creates a new pad with the given name from the given template.
731 * If name is NULL, a guaranteed unique name (across all pads)
733 * This function makes a copy of the name so you can safely free the name.
735 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
738 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
740 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
742 return g_object_new (GST_TYPE_PAD,
743 "name", name, "direction", templ->direction, "template", templ, NULL);
747 * gst_pad_new_from_static_template:
748 * @templ: the #GstStaticPadTemplate to use
749 * @name: the name of the element
751 * Creates a new pad with the given name from the given static template.
752 * If name is NULL, a guaranteed unique name (across all pads)
754 * This function makes a copy of the name so you can safely free the name.
756 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
759 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
763 GstPadTemplate *template;
765 template = gst_static_pad_template_get (templ);
766 pad = gst_pad_new_from_template (template, name);
767 gst_object_unref (template);
771 #define ACQUIRE_PARENT(pad, parent, label) \
773 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
774 gst_object_ref (parent); \
775 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
779 #define RELEASE_PARENT(parent) \
781 if (G_LIKELY (parent)) \
782 gst_object_unref (parent); \
786 * gst_pad_get_direction:
787 * @pad: a #GstPad to get the direction of.
789 * Gets the direction of the pad. The direction of the pad is
790 * decided at construction time so this function does not take
793 * Returns: the #GstPadDirection of the pad.
798 gst_pad_get_direction (GstPad * pad)
800 GstPadDirection result;
802 /* PAD_UNKNOWN is a little silly but we need some sort of
803 * error return value */
804 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
806 result = GST_PAD_DIRECTION (pad);
812 gst_pad_activate_default (GstPad * pad, GstObject * parent)
814 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
818 * gst_pad_mode_get_name:
819 * @mode: the pad mode
821 * Return the name of a pad mode, for use in debug messages mostly.
823 * Returns: short mnemonic for pad mode @mode
826 gst_pad_mode_get_name (GstPadMode mode)
829 case GST_PAD_MODE_NONE:
831 case GST_PAD_MODE_PUSH:
833 case GST_PAD_MODE_PULL:
842 pre_activate (GstPad * pad, GstPadMode new_mode)
845 case GST_PAD_MODE_NONE:
846 GST_OBJECT_LOCK (pad);
847 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
848 GST_PAD_SET_FLUSHING (pad);
849 GST_PAD_MODE (pad) = new_mode;
850 /* unlock blocked pads so element can resume and stop */
851 GST_PAD_BLOCK_BROADCAST (pad);
852 GST_OBJECT_UNLOCK (pad);
854 case GST_PAD_MODE_PUSH:
855 case GST_PAD_MODE_PULL:
856 GST_OBJECT_LOCK (pad);
857 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
858 gst_pad_mode_get_name (new_mode));
859 GST_PAD_UNSET_FLUSHING (pad);
860 GST_PAD_MODE (pad) = new_mode;
861 if (GST_PAD_IS_SINK (pad)) {
863 /* make sure the peer src pad sends us all events */
864 if ((peer = GST_PAD_PEER (pad))) {
865 gst_object_ref (peer);
866 GST_OBJECT_UNLOCK (pad);
868 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
869 GST_DEBUG_PAD_NAME (peer));
871 GST_OBJECT_LOCK (peer);
872 schedule_events (peer, NULL);
873 GST_OBJECT_UNLOCK (peer);
875 gst_object_unref (peer);
877 GST_OBJECT_UNLOCK (pad);
880 GST_OBJECT_UNLOCK (pad);
887 post_activate (GstPad * pad, GstPadMode new_mode)
890 case GST_PAD_MODE_NONE:
891 /* ensures that streaming stops */
892 GST_PAD_STREAM_LOCK (pad);
893 GST_DEBUG_OBJECT (pad, "stopped streaming");
894 GST_OBJECT_LOCK (pad);
896 GST_OBJECT_UNLOCK (pad);
897 GST_PAD_STREAM_UNLOCK (pad);
899 case GST_PAD_MODE_PUSH:
900 case GST_PAD_MODE_PULL:
907 * gst_pad_set_active:
908 * @pad: the #GstPad to activate or deactivate.
909 * @active: whether or not the pad should be active.
911 * Activates or deactivates the given pad.
912 * Normally called from within core state change functions.
914 * If @active, makes sure the pad is active. If it is already active, either in
915 * push or pull mode, just return. Otherwise dispatches to the pad's activate
916 * function to perform the actual activation.
918 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
919 * and a FALSE argument.
921 * Returns: #TRUE if the operation was successful.
926 gst_pad_set_active (GstPad * pad, gboolean active)
930 gboolean ret = FALSE;
932 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
934 GST_OBJECT_LOCK (pad);
935 old = GST_PAD_MODE (pad);
936 ACQUIRE_PARENT (pad, parent, no_parent);
937 GST_OBJECT_UNLOCK (pad);
940 if (old == GST_PAD_MODE_NONE) {
941 GST_DEBUG_OBJECT (pad, "activating pad from none");
942 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
944 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
945 gst_pad_mode_get_name (old));
949 if (old == GST_PAD_MODE_NONE) {
950 GST_DEBUG_OBJECT (pad, "pad was inactive");
953 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
954 gst_pad_mode_get_name (old));
955 ret = gst_pad_activate_mode (pad, old, FALSE);
959 RELEASE_PARENT (parent);
961 if (G_UNLIKELY (!ret))
969 GST_DEBUG_OBJECT (pad, "no parent");
970 GST_OBJECT_UNLOCK (pad);
975 GST_OBJECT_LOCK (pad);
977 g_critical ("Failed to deactivate pad %s:%s, very bad",
978 GST_DEBUG_PAD_NAME (pad));
980 GST_WARNING_OBJECT (pad, "Failed to activate pad");
982 GST_OBJECT_UNLOCK (pad);
988 * gst_pad_activate_mode:
989 * @pad: the #GstPad to activate or deactivate.
990 * @mode: the requested activation mode
991 * @active: whether or not the pad should be active.
993 * Activates or deactivates the given pad in @mode via dispatching to the
994 * pad's activatemodefunc. For use from within pad activation functions only.
996 * If you don't know what this is, you probably don't want to call it.
998 * Returns: TRUE if the operation was successful.
1003 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1005 gboolean res = FALSE;
1007 GstPadMode old, new;
1008 GstPadDirection dir;
1011 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1013 GST_OBJECT_LOCK (pad);
1014 old = GST_PAD_MODE (pad);
1015 dir = GST_PAD_DIRECTION (pad);
1016 ACQUIRE_PARENT (pad, parent, no_parent);
1017 GST_OBJECT_UNLOCK (pad);
1019 new = active ? mode : GST_PAD_MODE_NONE;
1024 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1025 /* pad was activate in the wrong direction, deactivate it
1026 * and reactivate it in the requested mode */
1027 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1028 gst_pad_mode_get_name (old));
1030 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1031 goto deactivate_failed;
1035 case GST_PAD_MODE_PULL:
1037 if (dir == GST_PAD_SINK) {
1038 if ((peer = gst_pad_get_peer (pad))) {
1039 GST_DEBUG_OBJECT (pad, "calling peer");
1040 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1042 gst_object_unref (peer);
1044 /* there is no peer, this is only fatal when we activate. When we
1045 * deactivate, we must assume the application has unlinked the peer and
1046 * will deactivate it eventually. */
1050 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1053 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1054 goto failure; /* Can't activate pull on a src without a
1055 getrange function */
1063 pre_activate (pad, new);
1065 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1066 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1070 /* can happen for sinks of passthrough elements */
1073 post_activate (pad, new);
1075 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1076 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1081 /* Clear sticky flags on deactivation */
1083 GST_OBJECT_LOCK (pad);
1084 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1085 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1086 GST_OBJECT_UNLOCK (pad);
1090 RELEASE_PARENT (parent);
1096 GST_DEBUG_OBJECT (pad, "no parent");
1097 GST_OBJECT_UNLOCK (pad);
1102 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1103 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1108 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1109 "failed to %s in switch to %s mode from %s mode",
1110 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1111 gst_pad_mode_get_name (old));
1116 GST_OBJECT_LOCK (peer);
1117 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1118 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1119 GST_OBJECT_UNLOCK (peer);
1120 gst_object_unref (peer);
1125 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1126 "pad in pull mode");
1131 GST_OBJECT_LOCK (pad);
1132 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1133 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1134 GST_PAD_SET_FLUSHING (pad);
1135 GST_PAD_MODE (pad) = old;
1136 GST_OBJECT_UNLOCK (pad);
1142 * gst_pad_is_active:
1143 * @pad: the #GstPad to query
1145 * Query if a pad is active
1147 * Returns: TRUE if the pad is active.
1152 gst_pad_is_active (GstPad * pad)
1154 gboolean result = FALSE;
1156 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1158 GST_OBJECT_LOCK (pad);
1159 result = GST_PAD_IS_ACTIVE (pad);
1160 GST_OBJECT_UNLOCK (pad);
1166 * gst_pad_add_probe:
1167 * @pad: the #GstPad to add the probe to
1168 * @mask: the probe mask
1169 * @callback: #GstPadProbeCallback that will be called with notifications of
1171 * @user_data: (closure): user data passed to the callback
1172 * @destroy_data: #GDestroyNotify for user_data
1174 * Be notified of different states of pads. The provided callback is called for
1175 * every state that matches @mask.
1177 * Returns: an id or 0 on error. The id can be used to remove the probe with
1178 * gst_pad_remove_probe().
1183 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1184 GstPadProbeCallback callback, gpointer user_data,
1185 GDestroyNotify destroy_data)
1190 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1191 g_return_val_if_fail (mask != 0, 0);
1193 GST_OBJECT_LOCK (pad);
1195 /* make a new probe */
1196 hook = g_hook_alloc (&pad->probes);
1198 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1201 /* when no contraints are given for the types, assume all types are
1203 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1204 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1205 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1206 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1208 /* store our flags and other fields */
1209 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1210 hook->func = callback;
1211 hook->data = user_data;
1212 hook->destroy = destroy_data;
1213 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1216 g_hook_prepend (&pad->probes, hook);
1218 /* incremenent cookie so that the new hook get's called */
1219 pad->priv->probe_list_cookie++;
1221 /* get the id of the hook, we return this and it can be used to remove the
1223 res = hook->hook_id;
1225 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1227 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1228 /* we have a block probe */
1230 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1231 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1232 "now %d blocking probes", pad->num_blocked);
1235 /* call the callback if we need to be called for idle callbacks */
1236 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1237 if (pad->priv->using > 0) {
1238 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1239 * flag above, the last thread to leave the push will do the callback. New
1240 * threads going into the push will block. */
1241 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1242 "pad is in use, delay idle callback");
1243 GST_OBJECT_UNLOCK (pad);
1245 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1247 /* the pad is idle now, we can signal the idle callback now */
1248 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1249 "pad is idle, trigger idle callback");
1250 GST_OBJECT_UNLOCK (pad);
1252 callback (pad, &info, user_data);
1255 GST_OBJECT_UNLOCK (pad);
1261 cleanup_hook (GstPad * pad, GHook * hook)
1263 GstPadProbeType type;
1265 if (!G_HOOK_IS_VALID (hook))
1268 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1270 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1271 /* unblock when we remove the last blocking probe */
1273 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1275 if (pad->num_blocked == 0) {
1276 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1277 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1278 GST_PAD_BLOCK_BROADCAST (pad);
1281 g_hook_destroy_link (&pad->probes, hook);
1286 * gst_pad_remove_probe:
1287 * @pad: the #GstPad with the probe
1288 * @id: the probe id to remove
1290 * Remove the probe with @id from @pad.
1295 gst_pad_remove_probe (GstPad * pad, gulong id)
1299 g_return_if_fail (GST_IS_PAD (pad));
1301 GST_OBJECT_LOCK (pad);
1303 hook = g_hook_get (&pad->probes, id);
1307 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1309 cleanup_hook (pad, hook);
1310 GST_OBJECT_UNLOCK (pad);
1316 GST_OBJECT_UNLOCK (pad);
1317 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1323 * gst_pad_is_blocked:
1324 * @pad: the #GstPad to query
1326 * Checks if the pad is blocked or not. This function returns the
1327 * last requested state of the pad. It is not certain that the pad
1328 * is actually blocking at this point (see gst_pad_is_blocking()).
1330 * Returns: TRUE if the pad is blocked.
1335 gst_pad_is_blocked (GstPad * pad)
1337 gboolean result = FALSE;
1339 g_return_val_if_fail (GST_IS_PAD (pad), result);
1341 GST_OBJECT_LOCK (pad);
1342 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1343 GST_OBJECT_UNLOCK (pad);
1349 * gst_pad_is_blocking:
1350 * @pad: the #GstPad to query
1352 * Checks if the pad is blocking or not. This is a guaranteed state
1353 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1355 * Returns: TRUE if the pad is blocking.
1360 gst_pad_is_blocking (GstPad * pad)
1362 gboolean result = FALSE;
1364 g_return_val_if_fail (GST_IS_PAD (pad), result);
1366 GST_OBJECT_LOCK (pad);
1367 /* the blocking flag is only valid if the pad is not flushing */
1368 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1369 GST_OBJECT_UNLOCK (pad);
1375 * gst_pad_needs_reconfigure:
1376 * @pad: the #GstPad to check
1378 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1379 * if the flag was set.
1381 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1384 gst_pad_needs_reconfigure (GstPad * pad)
1386 gboolean reconfigure;
1388 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1390 GST_OBJECT_LOCK (pad);
1391 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1392 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1393 GST_OBJECT_UNLOCK (pad);
1399 * gst_pad_check_reconfigure:
1400 * @pad: the #GstPad to check
1402 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1403 * if the flag was set.
1405 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1408 gst_pad_check_reconfigure (GstPad * pad)
1410 gboolean reconfigure;
1412 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1414 GST_OBJECT_LOCK (pad);
1415 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1417 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1418 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1420 GST_OBJECT_UNLOCK (pad);
1426 * gst_pad_mark_reconfigure:
1427 * @pad: the #GstPad to mark
1429 * Mark a pad for needing reconfiguration. The next call to
1430 * gst_pad_check_reconfigure() will return %TRUE after this call.
1433 gst_pad_mark_reconfigure (GstPad * pad)
1435 g_return_if_fail (GST_IS_PAD (pad));
1437 GST_OBJECT_LOCK (pad);
1438 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1439 GST_OBJECT_UNLOCK (pad);
1443 * gst_pad_set_activate_function:
1445 * @f: the #GstPadActivateFunction to set.
1447 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1451 * gst_pad_set_activate_function_full:
1453 * @activate: the #GstPadActivateFunction to set.
1454 * @user_data: user_data passed to @notify
1455 * @notify: notify called when @activate will not be used anymore.
1457 * Sets the given activate function for @pad. The activate function will
1458 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1459 * Only makes sense to set on sink pads.
1461 * Call this function if your sink pad can start a pull-based task.
1464 gst_pad_set_activate_function_full (GstPad * pad,
1465 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1467 g_return_if_fail (GST_IS_PAD (pad));
1469 if (pad->activatenotify)
1470 pad->activatenotify (pad->activatedata);
1471 GST_PAD_ACTIVATEFUNC (pad) = activate;
1472 pad->activatedata = user_data;
1473 pad->activatenotify = notify;
1475 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1476 GST_DEBUG_FUNCPTR_NAME (activate));
1480 * gst_pad_set_activatemode_function:
1482 * @f: the #GstPadActivateModeFunction to set.
1484 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1488 * gst_pad_set_activatemode_function_full:
1490 * @activatemode: the #GstPadActivateModeFunction to set.
1491 * @user_data: user_data passed to @notify
1492 * @notify: notify called when @activatemode will not be used anymore.
1494 * Sets the given activate_mode function for the pad. An activate_mode function
1495 * prepares the element for data passing.
1498 gst_pad_set_activatemode_function_full (GstPad * pad,
1499 GstPadActivateModeFunction activatemode, gpointer user_data,
1500 GDestroyNotify notify)
1502 g_return_if_fail (GST_IS_PAD (pad));
1504 if (pad->activatemodenotify)
1505 pad->activatemodenotify (pad->activatemodedata);
1506 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1507 pad->activatemodedata = user_data;
1508 pad->activatemodenotify = notify;
1510 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1511 GST_DEBUG_FUNCPTR_NAME (activatemode));
1515 * gst_pad_set_chain_function:
1516 * @p: a sink #GstPad.
1517 * @f: the #GstPadChainFunction to set.
1519 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1523 * gst_pad_set_chain_function_full:
1524 * @pad: a sink #GstPad.
1525 * @chain: the #GstPadChainFunction to set.
1526 * @user_data: user_data passed to @notify
1527 * @notify: notify called when @chain will not be used anymore.
1529 * Sets the given chain function for the pad. The chain function is called to
1530 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1533 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1534 gpointer user_data, GDestroyNotify notify)
1536 g_return_if_fail (GST_IS_PAD (pad));
1537 g_return_if_fail (GST_PAD_IS_SINK (pad));
1539 if (pad->chainnotify)
1540 pad->chainnotify (pad->chaindata);
1541 GST_PAD_CHAINFUNC (pad) = chain;
1542 pad->chaindata = user_data;
1543 pad->chainnotify = notify;
1545 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1546 GST_DEBUG_FUNCPTR_NAME (chain));
1550 * gst_pad_set_chain_list_function:
1551 * @p: a sink #GstPad.
1552 * @f: the #GstPadChainListFunction to set.
1554 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1558 * gst_pad_set_chain_list_function_full:
1559 * @pad: a sink #GstPad.
1560 * @chainlist: the #GstPadChainListFunction to set.
1561 * @user_data: user_data passed to @notify
1562 * @notify: notify called when @chainlist will not be used anymore.
1564 * Sets the given chain list function for the pad. The chainlist function is
1565 * called to process a #GstBufferList input buffer list. See
1566 * #GstPadChainListFunction for more details.
1569 gst_pad_set_chain_list_function_full (GstPad * pad,
1570 GstPadChainListFunction chainlist, gpointer user_data,
1571 GDestroyNotify notify)
1573 g_return_if_fail (GST_IS_PAD (pad));
1574 g_return_if_fail (GST_PAD_IS_SINK (pad));
1576 if (pad->chainlistnotify)
1577 pad->chainlistnotify (pad->chainlistdata);
1578 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1579 pad->chainlistdata = user_data;
1580 pad->chainlistnotify = notify;
1582 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1583 GST_DEBUG_FUNCPTR_NAME (chainlist));
1587 * gst_pad_set_getrange_function:
1588 * @p: a source #GstPad.
1589 * @f: the #GstPadGetRangeFunction to set.
1591 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1595 * gst_pad_set_getrange_function_full:
1596 * @pad: a source #GstPad.
1597 * @get: the #GstPadGetRangeFunction to set.
1598 * @user_data: user_data passed to @notify
1599 * @notify: notify called when @get will not be used anymore.
1601 * Sets the given getrange function for the pad. The getrange function is
1602 * called to produce a new #GstBuffer to start the processing pipeline. see
1603 * #GstPadGetRangeFunction for a description of the getrange function.
1606 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1607 gpointer user_data, GDestroyNotify notify)
1609 g_return_if_fail (GST_IS_PAD (pad));
1610 g_return_if_fail (GST_PAD_IS_SRC (pad));
1612 if (pad->getrangenotify)
1613 pad->getrangenotify (pad->getrangedata);
1614 GST_PAD_GETRANGEFUNC (pad) = get;
1615 pad->getrangedata = user_data;
1616 pad->getrangenotify = notify;
1618 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1619 GST_DEBUG_FUNCPTR_NAME (get));
1623 * gst_pad_set_event_function:
1624 * @p: a #GstPad of either direction.
1625 * @f: the #GstPadEventFunction to set.
1627 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1631 * gst_pad_set_event_function_full:
1632 * @pad: a #GstPad of either direction.
1633 * @event: the #GstPadEventFunction to set.
1634 * @user_data: user_data passed to @notify
1635 * @notify: notify called when @event will not be used anymore.
1637 * Sets the given event handler for the pad.
1640 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1641 gpointer user_data, GDestroyNotify notify)
1643 g_return_if_fail (GST_IS_PAD (pad));
1645 if (pad->eventnotify)
1646 pad->eventnotify (pad->eventdata);
1647 GST_PAD_EVENTFUNC (pad) = event;
1648 pad->eventdata = user_data;
1649 pad->eventnotify = notify;
1651 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1652 GST_DEBUG_FUNCPTR_NAME (event));
1656 * gst_pad_set_query_function:
1657 * @p: a #GstPad of either direction.
1658 * @f: the #GstPadQueryFunction to set.
1660 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1664 * gst_pad_set_query_function_full:
1665 * @pad: a #GstPad of either direction.
1666 * @query: the #GstPadQueryFunction to set.
1667 * @user_data: user_data passed to @notify
1668 * @notify: notify called when @query will not be used anymore.
1670 * Set the given query function for the pad.
1673 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1674 gpointer user_data, GDestroyNotify notify)
1676 g_return_if_fail (GST_IS_PAD (pad));
1678 if (pad->querynotify)
1679 pad->querynotify (pad->querydata);
1680 GST_PAD_QUERYFUNC (pad) = query;
1681 pad->querydata = user_data;
1682 pad->querynotify = notify;
1684 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1685 GST_DEBUG_FUNCPTR_NAME (query));
1689 * gst_pad_set_iterate_internal_links_function:
1690 * @p: a #GstPad of either direction.
1691 * @f: the #GstPadIterIntLinkFunction to set.
1693 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1694 * for the user_data and notify.
1697 * gst_pad_set_iterate_internal_links_function_full:
1698 * @pad: a #GstPad of either direction.
1699 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1700 * @user_data: user_data passed to @notify
1701 * @notify: notify called when @iterintlink will not be used anymore.
1703 * Sets the given internal link iterator function for the pad.
1706 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1707 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1708 GDestroyNotify notify)
1710 g_return_if_fail (GST_IS_PAD (pad));
1712 if (pad->iterintlinknotify)
1713 pad->iterintlinknotify (pad->iterintlinkdata);
1714 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1715 pad->iterintlinkdata = user_data;
1716 pad->iterintlinknotify = notify;
1718 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1719 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1723 * gst_pad_set_link_function:
1725 * @f: the #GstPadLinkFunction to set.
1727 * Calls gst_pad_set_link_function_full() with NULL
1728 * for the user_data and notify.
1731 * gst_pad_set_link_function_full:
1733 * @link: the #GstPadLinkFunction to set.
1734 * @user_data: user_data passed to @notify
1735 * @notify: notify called when @link will not be used anymore.
1737 * Sets the given link function for the pad. It will be called when
1738 * the pad is linked with another pad.
1740 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1743 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1744 * cannot be made for some reason.
1746 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1747 * of the peer sink pad, if present.
1750 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1751 gpointer user_data, GDestroyNotify notify)
1753 g_return_if_fail (GST_IS_PAD (pad));
1755 if (pad->linknotify)
1756 pad->linknotify (pad->linkdata);
1757 GST_PAD_LINKFUNC (pad) = link;
1758 pad->linkdata = user_data;
1759 pad->linknotify = notify;
1761 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1762 GST_DEBUG_FUNCPTR_NAME (link));
1766 * gst_pad_set_unlink_function:
1768 * @f: the #GstPadUnlinkFunction to set.
1770 * Calls gst_pad_set_unlink_function_full() with NULL
1771 * for the user_data and notify.
1774 * gst_pad_set_unlink_function_full:
1776 * @unlink: the #GstPadUnlinkFunction to set.
1777 * @user_data: user_data passed to @notify
1778 * @notify: notify called when @unlink will not be used anymore.
1780 * Sets the given unlink function for the pad. It will be called
1781 * when the pad is unlinked.
1784 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1785 gpointer user_data, GDestroyNotify notify)
1787 g_return_if_fail (GST_IS_PAD (pad));
1789 if (pad->unlinknotify)
1790 pad->unlinknotify (pad->unlinkdata);
1791 GST_PAD_UNLINKFUNC (pad) = unlink;
1792 pad->unlinkdata = user_data;
1793 pad->unlinknotify = notify;
1795 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1796 GST_DEBUG_FUNCPTR_NAME (unlink));
1801 * @srcpad: the source #GstPad to unlink.
1802 * @sinkpad: the sink #GstPad to unlink.
1804 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1805 * signal on both pads.
1807 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1808 * the pads were not linked together.
1813 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1815 gboolean result = FALSE;
1816 GstElement *parent = NULL;
1818 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1819 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1820 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1821 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1823 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1824 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1825 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1827 /* We need to notify the parent before taking any pad locks as the bin in
1828 * question might be waiting for a lock on the pad while holding its lock
1829 * that our message will try to take. */
1830 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1831 if (GST_IS_ELEMENT (parent)) {
1832 gst_element_post_message (parent,
1833 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1834 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1836 gst_object_unref (parent);
1841 GST_OBJECT_LOCK (srcpad);
1842 GST_OBJECT_LOCK (sinkpad);
1844 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1845 goto not_linked_together;
1847 if (GST_PAD_UNLINKFUNC (srcpad)) {
1848 GstObject *tmpparent;
1850 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1852 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1853 RELEASE_PARENT (tmpparent);
1856 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1857 GstObject *tmpparent;
1859 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1861 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1862 RELEASE_PARENT (tmpparent);
1866 /* first clear peers */
1867 GST_PAD_PEER (srcpad) = NULL;
1868 GST_PAD_PEER (sinkpad) = NULL;
1870 GST_OBJECT_UNLOCK (sinkpad);
1871 GST_OBJECT_UNLOCK (srcpad);
1873 /* fire off a signal to each of the pads telling them
1874 * that they've been unlinked */
1875 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1876 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1878 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1879 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1884 if (parent != NULL) {
1885 gst_element_post_message (parent,
1886 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1887 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1888 gst_object_unref (parent);
1893 not_linked_together:
1895 /* we do not emit a warning in this case because unlinking cannot
1896 * be made MT safe.*/
1897 GST_OBJECT_UNLOCK (sinkpad);
1898 GST_OBJECT_UNLOCK (srcpad);
1904 * gst_pad_is_linked:
1905 * @pad: pad to check
1907 * Checks if a @pad is linked to another pad or not.
1909 * Returns: TRUE if the pad is linked, FALSE otherwise.
1914 gst_pad_is_linked (GstPad * pad)
1918 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1920 GST_OBJECT_LOCK (pad);
1921 result = (GST_PAD_PEER (pad) != NULL);
1922 GST_OBJECT_UNLOCK (pad);
1927 /* get the caps from both pads and see if the intersection
1930 * This function should be called with the pad LOCK on both
1934 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1935 GstPadLinkCheck flags)
1937 GstCaps *srccaps = NULL;
1938 GstCaps *sinkcaps = NULL;
1939 gboolean compatible = FALSE;
1941 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1944 /* Doing the expensive caps checking takes priority over only checking the template caps */
1945 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1946 GST_OBJECT_UNLOCK (sink);
1947 GST_OBJECT_UNLOCK (src);
1949 srccaps = gst_pad_query_caps (src, NULL);
1950 sinkcaps = gst_pad_query_caps (sink, NULL);
1952 GST_OBJECT_LOCK (src);
1953 GST_OBJECT_LOCK (sink);
1955 /* If one of the two pads doesn't have a template, consider the intersection
1957 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1958 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1962 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1964 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1967 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1969 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1972 /* if we have caps on both pads we can check the intersection. If one
1973 * of the caps is NULL, we return TRUE. */
1974 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1976 gst_caps_unref (srccaps);
1978 gst_caps_unref (sinkcaps);
1982 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1983 gst_caps_unref (srccaps);
1984 gst_caps_unref (sinkcaps);
1987 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1988 (compatible ? "" : "not"));
1993 /* check if the grandparents of both pads are the same.
1994 * This check is required so that we don't try to link
1995 * pads from elements in different bins without ghostpads.
1997 * The LOCK should be held on both pads
2000 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2002 GstObject *psrc, *psink;
2004 psrc = GST_OBJECT_PARENT (src);
2005 psink = GST_OBJECT_PARENT (sink);
2007 /* if one of the pads has no parent, we allow the link */
2008 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2011 /* only care about parents that are elements */
2012 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2013 goto no_element_parent;
2015 /* if the parents are the same, we have a loop */
2016 if (G_UNLIKELY (psrc == psink))
2019 /* if they both have a parent, we check the grandparents. We can not lock
2020 * the parent because we hold on the child (pad) and the locking order is
2021 * parent >> child. */
2022 psrc = GST_OBJECT_PARENT (psrc);
2023 psink = GST_OBJECT_PARENT (psink);
2025 /* if they have grandparents but they are not the same */
2026 if (G_UNLIKELY (psrc != psink))
2027 goto wrong_grandparents;
2034 GST_CAT_DEBUG (GST_CAT_CAPS,
2035 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2036 GST_PTR_FORMAT, psrc, psink);
2041 GST_CAT_DEBUG (GST_CAT_CAPS,
2042 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2043 GST_PTR_FORMAT, psrc, psink);
2048 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2054 GST_CAT_DEBUG (GST_CAT_CAPS,
2055 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2056 GST_PTR_FORMAT, psrc, psink);
2061 /* FIXME leftover from an attempt at refactoring... */
2062 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2063 * the two pads will be locked in the srcpad, sinkpad order. */
2064 static GstPadLinkReturn
2065 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2067 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2068 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2070 GST_OBJECT_LOCK (srcpad);
2072 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2073 goto src_was_linked;
2075 GST_OBJECT_LOCK (sinkpad);
2077 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2078 goto sink_was_linked;
2080 /* check hierarchy, pads can only be linked if the grandparents
2082 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2083 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2084 goto wrong_hierarchy;
2086 /* check pad caps for non-empty intersection */
2087 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2090 /* FIXME check pad scheduling for non-empty intersection */
2092 return GST_PAD_LINK_OK;
2096 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2097 GST_DEBUG_PAD_NAME (srcpad),
2098 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2099 /* we do not emit a warning in this case because unlinking cannot
2100 * be made MT safe.*/
2101 GST_OBJECT_UNLOCK (srcpad);
2102 return GST_PAD_LINK_WAS_LINKED;
2106 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2107 GST_DEBUG_PAD_NAME (sinkpad),
2108 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2109 /* we do not emit a warning in this case because unlinking cannot
2110 * be made MT safe.*/
2111 GST_OBJECT_UNLOCK (sinkpad);
2112 GST_OBJECT_UNLOCK (srcpad);
2113 return GST_PAD_LINK_WAS_LINKED;
2117 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2118 GST_OBJECT_UNLOCK (sinkpad);
2119 GST_OBJECT_UNLOCK (srcpad);
2120 return GST_PAD_LINK_WRONG_HIERARCHY;
2124 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2125 GST_OBJECT_UNLOCK (sinkpad);
2126 GST_OBJECT_UNLOCK (srcpad);
2127 return GST_PAD_LINK_NOFORMAT;
2133 * @srcpad: the source #GstPad.
2134 * @sinkpad: the sink #GstPad.
2136 * Checks if the source pad and the sink pad are compatible so they can be
2139 * Returns: TRUE if the pads can be linked.
2142 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2144 GstPadLinkReturn result;
2146 /* generic checks */
2147 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2148 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2150 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2151 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2153 /* gst_pad_link_prepare does everything for us, we only release the locks
2154 * on the pads that it gets us. If this function returns !OK the locks are not
2156 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2157 if (result != GST_PAD_LINK_OK)
2160 GST_OBJECT_UNLOCK (srcpad);
2161 GST_OBJECT_UNLOCK (sinkpad);
2164 return result == GST_PAD_LINK_OK;
2168 * gst_pad_link_full:
2169 * @srcpad: the source #GstPad to link.
2170 * @sinkpad: the sink #GstPad to link.
2171 * @flags: the checks to validate when linking
2173 * Links the source pad and the sink pad.
2175 * This variant of #gst_pad_link provides a more granular control on the
2176 * checks being done when linking. While providing some considerable speedups
2177 * the caller of this method must be aware that wrong usage of those flags
2178 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2179 * for more information.
2183 * Returns: A result code indicating if the connection worked or
2187 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2189 GstPadLinkReturn result;
2191 GstPadLinkFunction srcfunc, sinkfunc;
2193 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2194 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2195 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2196 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2197 GST_PAD_LINK_WRONG_DIRECTION);
2199 /* Notify the parent early. See gst_pad_unlink for details. */
2200 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2201 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2202 gst_element_post_message (parent,
2203 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2204 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2206 gst_object_unref (parent);
2211 /* prepare will also lock the two pads */
2212 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2214 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2217 /* must set peers before calling the link function */
2218 GST_PAD_PEER (srcpad) = sinkpad;
2219 GST_PAD_PEER (sinkpad) = srcpad;
2221 /* check events, when something is different, mark pending */
2222 schedule_events (srcpad, sinkpad);
2224 /* get the link functions */
2225 srcfunc = GST_PAD_LINKFUNC (srcpad);
2226 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2228 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2229 /* custom link functions, execute them */
2230 GST_OBJECT_UNLOCK (sinkpad);
2231 GST_OBJECT_UNLOCK (srcpad);
2234 GstObject *tmpparent;
2236 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2237 /* this one will call the peer link function */
2238 result = srcfunc (srcpad, tmpparent, sinkpad);
2239 RELEASE_PARENT (tmpparent);
2240 } else if (sinkfunc) {
2241 GstObject *tmpparent;
2243 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2244 /* if no source link function, we need to call the sink link
2245 * function ourselves. */
2246 result = sinkfunc (sinkpad, tmpparent, srcpad);
2247 RELEASE_PARENT (tmpparent);
2251 GST_OBJECT_LOCK (srcpad);
2252 GST_OBJECT_LOCK (sinkpad);
2254 /* we released the lock, check if the same pads are linked still */
2255 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2256 goto concurrent_link;
2258 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2261 GST_OBJECT_UNLOCK (sinkpad);
2262 GST_OBJECT_UNLOCK (srcpad);
2264 /* fire off a signal to each of the pads telling them
2265 * that they've been linked */
2266 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2267 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2269 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2270 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2272 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2275 if (G_LIKELY (parent)) {
2276 gst_element_post_message (parent,
2277 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2278 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2279 gst_object_unref (parent);
2287 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2288 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2289 GST_OBJECT_UNLOCK (sinkpad);
2290 GST_OBJECT_UNLOCK (srcpad);
2292 /* The other link operation succeeded first */
2293 result = GST_PAD_LINK_WAS_LINKED;
2298 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2299 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2301 GST_PAD_PEER (srcpad) = NULL;
2302 GST_PAD_PEER (sinkpad) = NULL;
2304 GST_OBJECT_UNLOCK (sinkpad);
2305 GST_OBJECT_UNLOCK (srcpad);
2313 * @srcpad: the source #GstPad to link.
2314 * @sinkpad: the sink #GstPad to link.
2316 * Links the source pad and the sink pad.
2318 * Returns: A result code indicating if the connection worked or
2324 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2326 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2330 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2332 GstPadTemplate **template_p;
2334 /* this function would need checks if it weren't static */
2336 GST_OBJECT_LOCK (pad);
2337 template_p = &pad->padtemplate;
2338 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2339 GST_OBJECT_UNLOCK (pad);
2342 gst_pad_template_pad_created (templ, pad);
2346 * gst_pad_get_pad_template:
2349 * Gets the template for @pad.
2351 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2352 * instantiated, or %NULL if this pad has no template. Unref after
2356 gst_pad_get_pad_template (GstPad * pad)
2358 GstPadTemplate *templ;
2360 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2362 templ = GST_PAD_PAD_TEMPLATE (pad);
2364 return (templ ? gst_object_ref (templ) : NULL);
2368 * gst_pad_has_current_caps:
2369 * @pad: a #GstPad to check
2371 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2373 * Returns: TRUE when @pad has caps associated with it.
2376 gst_pad_has_current_caps (GstPad * pad)
2381 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2383 GST_OBJECT_LOCK (pad);
2384 caps = get_pad_caps (pad);
2385 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2386 "check current pad caps %" GST_PTR_FORMAT, caps);
2387 result = (caps != NULL);
2388 GST_OBJECT_UNLOCK (pad);
2394 * gst_pad_get_current_caps:
2395 * @pad: a #GstPad to get the current capabilities of.
2397 * Gets the capabilities currently configured on @pad with the last
2398 * #GST_EVENT_CAPS event.
2400 * Returns: the current caps of the pad with incremented ref-count.
2403 gst_pad_get_current_caps (GstPad * pad)
2407 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2409 GST_OBJECT_LOCK (pad);
2410 if ((result = get_pad_caps (pad)))
2411 gst_caps_ref (result);
2412 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2413 "get current pad caps %" GST_PTR_FORMAT, result);
2414 GST_OBJECT_UNLOCK (pad);
2420 * gst_pad_get_pad_template_caps:
2421 * @pad: a #GstPad to get the template capabilities from.
2423 * Gets the capabilities for @pad's template.
2425 * Returns: (transfer full): the #GstCaps of this pad template.
2426 * Unref after usage.
2429 gst_pad_get_pad_template_caps (GstPad * pad)
2431 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2433 if (GST_PAD_PAD_TEMPLATE (pad))
2434 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2436 return gst_caps_ref (GST_CAPS_ANY);
2441 * @pad: a #GstPad to get the peer of.
2443 * Gets the peer of @pad. This function refs the peer pad so
2444 * you need to unref it after use.
2446 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2451 gst_pad_get_peer (GstPad * pad)
2455 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2457 GST_OBJECT_LOCK (pad);
2458 result = GST_PAD_PEER (pad);
2460 gst_object_ref (result);
2461 GST_OBJECT_UNLOCK (pad);
2467 * gst_pad_get_allowed_caps:
2470 * Gets the capabilities of the allowed media types that can flow through
2471 * @pad and its peer.
2473 * The allowed capabilities is calculated as the intersection of the results of
2474 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2475 * on the resulting caps.
2477 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2478 * caps when you no longer need it. This function returns NULL when @pad
2484 gst_pad_get_allowed_caps (GstPad * pad)
2490 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2492 GST_OBJECT_LOCK (pad);
2493 peer = GST_PAD_PEER (pad);
2494 if (G_UNLIKELY (peer == NULL))
2497 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2499 gst_object_ref (peer);
2500 GST_OBJECT_UNLOCK (pad);
2501 mycaps = gst_pad_query_caps (pad, NULL);
2503 caps = gst_pad_query_caps (peer, mycaps);
2504 gst_object_unref (peer);
2506 gst_caps_unref (mycaps);
2508 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2515 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2516 GST_OBJECT_UNLOCK (pad);
2523 * gst_pad_iterate_internal_links_default:
2524 * @pad: the #GstPad to get the internal links of.
2525 * @parent: the parent of @pad or NULL
2527 * Iterate the list of pads to which the given pad is linked to inside of
2528 * the parent element.
2529 * This is the default handler, and thus returns an iterator of all of the
2530 * pads inside the parent element with opposite direction.
2532 * The caller must free this iterator after use with gst_iterator_free().
2534 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2535 * returned pad with gst_object_unref().
2538 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2545 GstElement *eparent;
2547 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2549 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2550 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2552 GST_OBJECT_LOCK (pad);
2553 eparent = GST_PAD_PARENT (pad);
2554 if (!eparent || !GST_IS_ELEMENT (eparent))
2557 gst_object_ref (eparent);
2558 GST_OBJECT_UNLOCK (pad);
2561 if (pad->direction == GST_PAD_SRC)
2562 padlist = &eparent->sinkpads;
2564 padlist = &eparent->srcpads;
2566 GST_DEBUG_OBJECT (pad, "Making iterator");
2568 cookie = &eparent->pads_cookie;
2570 lock = GST_OBJECT_GET_LOCK (eparent);
2572 res = gst_iterator_new_list (GST_TYPE_PAD,
2573 lock, cookie, padlist, (GObject *) owner, NULL);
2575 gst_object_unref (owner);
2582 GST_OBJECT_UNLOCK (pad);
2583 GST_DEBUG_OBJECT (pad, "no parent element");
2589 * gst_pad_iterate_internal_links:
2590 * @pad: the GstPad to get the internal links of.
2592 * Gets an iterator for the pads to which the given pad is linked to inside
2593 * of the parent element.
2595 * Each #GstPad element yielded by the iterator will have its refcount increased,
2596 * so unref after use.
2598 * Free-function: gst_iterator_free
2600 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2601 * pad does not have an iterator function configured. Use
2602 * gst_iterator_free() after usage.
2605 gst_pad_iterate_internal_links (GstPad * pad)
2607 GstIterator *res = NULL;
2610 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2612 GST_OBJECT_LOCK (pad);
2613 ACQUIRE_PARENT (pad, parent, no_parent);
2614 GST_OBJECT_UNLOCK (pad);
2616 if (GST_PAD_ITERINTLINKFUNC (pad))
2617 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2619 RELEASE_PARENT (parent);
2626 GST_DEBUG_OBJECT (pad, "no parent");
2627 GST_OBJECT_UNLOCK (pad);
2635 * @forward: (scope call): a #GstPadForwardFunction
2636 * @user_data: user data passed to @forward
2638 * Calls @forward for all internally linked pads of @pad. This function deals with
2639 * dynamically changing internal pads and will make sure that the @forward
2640 * function is only called once for each pad.
2642 * When @forward returns TRUE, no further pads will be processed.
2644 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2647 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2650 gboolean result = FALSE;
2652 gboolean done = FALSE;
2653 GValue item = { 0, };
2654 GList *pushed_pads = NULL;
2656 iter = gst_pad_iterate_internal_links (pad);
2662 switch (gst_iterator_next (iter, &item)) {
2663 case GST_ITERATOR_OK:
2667 intpad = g_value_get_object (&item);
2669 /* if already pushed, skip. FIXME, find something faster to tag pads */
2670 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2671 g_value_reset (&item);
2675 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2676 GST_DEBUG_PAD_NAME (intpad));
2677 done = result = forward (intpad, user_data);
2679 pushed_pads = g_list_prepend (pushed_pads, intpad);
2681 g_value_reset (&item);
2684 case GST_ITERATOR_RESYNC:
2685 /* We don't reset the result here because we don't push the event
2686 * again on pads that got the event already and because we need
2687 * to consider the result of the previous pushes */
2688 gst_iterator_resync (iter);
2690 case GST_ITERATOR_ERROR:
2691 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2694 case GST_ITERATOR_DONE:
2699 g_value_unset (&item);
2700 gst_iterator_free (iter);
2702 g_list_free (pushed_pads);
2712 gboolean dispatched;
2716 event_forward_func (GstPad * pad, EventData * data)
2718 /* for each pad we send to, we should ref the event; it's up
2719 * to downstream to unref again when handled. */
2720 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2721 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2723 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2725 data->dispatched = TRUE;
2732 * gst_pad_event_default:
2733 * @pad: a #GstPad to call the default event handler on.
2734 * @parent: the parent of @pad or NULL
2735 * @event: (transfer full): the #GstEvent to handle.
2737 * Invokes the default event handler for the given pad.
2739 * The EOS event will pause the task associated with @pad before it is forwarded
2740 * to all internally linked pads,
2742 * The the event is sent to all pads internally linked to @pad. This function
2743 * takes ownership of @event.
2745 * Returns: TRUE if the event was sent successfully.
2748 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2750 gboolean result, forward = TRUE;
2752 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2753 g_return_val_if_fail (event != NULL, FALSE);
2755 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2758 switch (GST_EVENT_TYPE (event)) {
2759 case GST_EVENT_CAPS:
2760 forward = GST_PAD_IS_PROXY_CAPS (pad);
2771 data.dispatched = FALSE;
2772 data.result = FALSE;
2774 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2776 /* for sinkpads without a parent element or without internal links, nothing
2777 * will be dispatched but we still want to return TRUE. */
2778 if (data.dispatched)
2779 result = data.result;
2784 gst_event_unref (event);
2789 /* Default accept caps implementation just checks against
2790 * the allowed caps for the pad */
2792 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2794 /* get the caps and see if it intersects to something not empty */
2795 GstCaps *caps, *allowed;
2798 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2800 /* first forward the query to internally linked pads when we are dealing with
2802 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2803 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2808 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2809 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2811 allowed = gst_pad_query_caps (pad, NULL);
2812 gst_query_parse_accept_caps (query, &caps);
2815 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2816 result = gst_caps_is_subset (caps, allowed);
2817 gst_caps_unref (allowed);
2819 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2822 gst_query_set_accept_caps_result (query, result);
2828 /* Default caps implementation */
2830 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2832 GstCaps *result = NULL, *filter;
2833 GstPadTemplate *templ;
2834 gboolean fixed_caps;
2836 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2839 /* first try to proxy if we must */
2840 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2841 if ((gst_pad_proxy_query_caps (pad, query))) {
2846 gst_query_parse_caps (query, &filter);
2848 /* no proxy or it failed, do default handling */
2849 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2851 GST_OBJECT_LOCK (pad);
2853 /* fixed caps, try the negotiated caps first */
2854 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2855 if ((result = get_pad_caps (pad)))
2856 goto filter_done_unlock;
2859 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2860 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2861 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2862 goto filter_done_unlock;
2866 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2867 "non-fixed pad caps: trying pad caps");
2868 /* non fixed caps, try the negotiated caps */
2869 if ((result = get_pad_caps (pad)))
2870 goto filter_done_unlock;
2873 /* this almost never happens */
2874 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2875 result = GST_CAPS_ANY;
2878 GST_OBJECT_UNLOCK (pad);
2880 /* run the filter on the result */
2882 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2883 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2884 GST_PTR_FORMAT, result, result, filter, filter);
2885 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2886 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2889 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2890 "using caps %p %" GST_PTR_FORMAT, result, result);
2891 result = gst_caps_ref (result);
2893 gst_query_set_caps_result (query, result);
2894 gst_caps_unref (result);
2904 gboolean dispatched;
2908 query_forward_func (GstPad * pad, QueryData * data)
2910 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2911 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2913 data->result |= gst_pad_peer_query (pad, data->query);
2915 data->dispatched = TRUE;
2917 /* stop on first successful reply */
2918 return data->result;
2922 * gst_pad_query_default:
2923 * @pad: a #GstPad to call the default query handler on.
2924 * @parent: the parent of @pad or NULL
2925 * @query: (transfer none): the #GstQuery to handle.
2927 * Invokes the default query handler for the given pad.
2928 * The query is sent to all pads internally linked to @pad. Note that
2929 * if there are many possible sink pads that are internally linked to
2930 * @pad, only one will be sent the query.
2931 * Multi-sinkpad elements should implement custom query handlers.
2933 * Returns: TRUE if the query was performed successfully.
2936 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2938 gboolean forward, ret = FALSE;
2940 switch (GST_QUERY_TYPE (query)) {
2941 case GST_QUERY_SCHEDULING:
2942 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2944 case GST_QUERY_ALLOCATION:
2945 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2947 case GST_QUERY_ACCEPT_CAPS:
2948 ret = gst_pad_query_accept_caps_default (pad, query);
2951 case GST_QUERY_CAPS:
2952 ret = gst_pad_query_caps_default (pad, query);
2955 case GST_QUERY_POSITION:
2956 case GST_QUERY_SEEKING:
2957 case GST_QUERY_FORMATS:
2958 case GST_QUERY_LATENCY:
2959 case GST_QUERY_JITTER:
2960 case GST_QUERY_RATE:
2961 case GST_QUERY_CONVERT:
2967 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2968 query, GST_QUERY_TYPE_NAME (query));
2974 data.dispatched = FALSE;
2975 data.result = FALSE;
2977 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
2979 if (data.dispatched) {
2982 /* nothing dispatched, assume drained */
2983 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
2993 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2995 GstPad *pad = data->pad;
2996 GstPadProbeInfo *info = data->info;
2997 GstPadProbeType type, flags;
2998 GstPadProbeCallback callback;
2999 GstPadProbeReturn ret;
3001 /* if we have called this callback, do nothing */
3002 if (PROBE_COOKIE (hook) == data->cookie) {
3003 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3004 "hook %lu, cookie %u already called", hook->hook_id,
3005 PROBE_COOKIE (hook));
3009 PROBE_COOKIE (hook) = data->cookie;
3011 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3014 /* one of the data types */
3015 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3017 /* one of the scheduling types */
3018 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3020 /* one of the blocking types must match */
3021 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3022 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3024 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3025 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3026 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3029 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3030 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3031 PROBE_COOKIE (hook), flags);
3033 data->marshalled = TRUE;
3035 callback = (GstPadProbeCallback) hook->func;
3036 if (callback == NULL)
3039 info->id = hook->hook_id;
3041 GST_OBJECT_UNLOCK (pad);
3043 ret = callback (pad, info, hook->data);
3045 GST_OBJECT_LOCK (pad);
3048 case GST_PAD_PROBE_REMOVE:
3049 /* remove the probe */
3050 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3051 cleanup_hook (pad, hook);
3053 case GST_PAD_PROBE_DROP:
3054 /* need to drop the data, make sure other probes don't get called
3056 GST_DEBUG_OBJECT (pad, "asked to drop item");
3057 info->type = GST_PAD_PROBE_TYPE_INVALID;
3058 data->dropped = TRUE;
3060 case GST_PAD_PROBE_PASS:
3061 /* inform the pad block to let things pass */
3062 GST_DEBUG_OBJECT (pad, "asked to pass item");
3065 case GST_PAD_PROBE_OK:
3066 GST_DEBUG_OBJECT (pad, "probe returned OK");
3069 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3076 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3077 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3078 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3083 /* a probe that does not take or return any data */
3084 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3086 if (G_UNLIKELY (pad->num_probes)) { \
3087 /* pass NULL as the data item */ \
3088 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3089 ret = do_probe_callbacks (pad, &info, defaultval); \
3090 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3095 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3097 if (G_UNLIKELY (pad->num_probes)) { \
3098 /* pass the data item */ \
3099 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3100 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3101 /* store the possibly updated data item */ \
3102 data = GST_PAD_PROBE_INFO_DATA (&info); \
3103 /* if something went wrong, exit */ \
3104 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3109 #define PROBE_PUSH(pad,mask,data,label) \
3110 PROBE_FULL(pad, mask, data, -1, -1, label);
3111 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3112 PROBE_FULL(pad, mask, data, offs, size, label);
3114 static GstFlowReturn
3115 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3116 GstFlowReturn defaultval)
3125 data.marshalled = FALSE;
3126 data.dropped = FALSE;
3127 data.cookie = ++pad->priv->probe_cookie;
3130 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3133 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3134 "do probes cookie %u", data.cookie);
3135 cookie = pad->priv->probe_list_cookie;
3137 g_hook_list_marshal (&pad->probes, TRUE,
3138 (GHookMarshaller) probe_hook_marshal, &data);
3140 /* if the list changed, call the new callbacks (they will not have their
3141 * cookie set to data.cookie */
3142 if (cookie != pad->priv->probe_list_cookie) {
3143 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3144 "probe list changed, restarting");
3148 /* the first item that dropped will stop the hooks and then we drop here */
3152 /* if no handler matched and we are blocking, let the item pass */
3153 if (!data.marshalled && is_block)
3156 /* At this point, all handlers returned either OK or PASS. If one handler
3157 * returned PASS, let the item pass */
3162 while (GST_PAD_IS_BLOCKED (pad)) {
3163 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3164 "we are blocked %d times", pad->num_blocked);
3166 /* we might have released the lock */
3167 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3170 /* now we block the streaming thread. It can be unlocked when we
3171 * deactivate the pad (which will also set the FLUSHING flag) or
3172 * when the pad is unblocked. A flushing event will also unblock
3173 * the pad after setting the FLUSHING flag. */
3174 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3175 "Waiting to be unblocked or set flushing");
3176 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3177 GST_PAD_BLOCK_WAIT (pad);
3178 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3179 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3181 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3191 GST_DEBUG_OBJECT (pad, "pad is flushing");
3192 return GST_FLOW_FLUSHING;
3196 GST_DEBUG_OBJECT (pad, "data is dropped");
3197 return GST_FLOW_CUSTOM_SUCCESS;
3201 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3202 GST_DEBUG_OBJECT (pad, "data is passed");
3210 * gst_pad_get_offset:
3213 * Get the offset applied to the running time of @pad. @pad has to be a source
3216 * Returns: the offset.
3219 gst_pad_get_offset (GstPad * pad)
3223 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3225 GST_OBJECT_LOCK (pad);
3226 result = pad->offset;
3227 GST_OBJECT_UNLOCK (pad);
3233 * gst_pad_set_offset:
3235 * @offset: the offset
3237 * Set the offset that will be applied to the running time of @pad.
3240 gst_pad_set_offset (GstPad * pad, gint64 offset)
3244 g_return_if_fail (GST_IS_PAD (pad));
3246 GST_OBJECT_LOCK (pad);
3247 /* if nothing changed, do nothing */
3248 if (pad->offset == offset)
3251 pad->offset = offset;
3252 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3254 /* sinkpads will apply their offset the next time a segment
3255 * event is received. */
3256 if (GST_PAD_IS_SINK (pad))
3259 /* resend the last segment event on next buffer push */
3260 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3261 ev->received = FALSE;
3262 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3266 GST_OBJECT_UNLOCK (pad);
3273 /* If TRUE and ret is not OK this means
3274 * that pushing the EOS event failed
3279 /* should be called with pad LOCK */
3281 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3283 PushStickyData *data = user_data;
3284 GstEvent *event = ev->event;
3287 GST_DEBUG_OBJECT (pad, "event %s was already received",
3288 GST_EVENT_TYPE_NAME (event));
3292 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3293 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3295 switch (data->ret) {
3297 ev->received = TRUE;
3298 GST_DEBUG_OBJECT (pad, "event %s marked received",
3299 GST_EVENT_TYPE_NAME (event));
3301 case GST_FLOW_CUSTOM_SUCCESS:
3302 /* we can't assume the event is received when it was dropped */
3303 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3304 GST_EVENT_TYPE_NAME (event));
3305 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3306 data->ret = GST_FLOW_OK;
3308 case GST_FLOW_NOT_LINKED:
3309 /* not linked is not a problem, we are sticky so the event will be
3310 * sent later but only for non-EOS events */
3311 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3312 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3313 data->ret = GST_FLOW_OK;
3314 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3317 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3318 gst_flow_get_name (data->ret));
3319 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3323 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3324 data->was_eos = TRUE;
3326 return data->ret == GST_FLOW_OK;
3329 /* check sticky events and push them when needed. should be called
3331 static inline GstFlowReturn
3332 check_sticky (GstPad * pad)
3334 PushStickyData data = { GST_FLOW_OK, FALSE };
3336 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3337 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3339 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3340 events_foreach (pad, push_sticky, &data);
3342 /* If there's an EOS event we must push it downstream
3343 * even if sending a previous sticky event failed.
3344 * Otherwise the pipeline might wait forever for EOS.
3346 * Only do this if pushing another event than the EOS
3349 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3350 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3352 if (ev && !ev->received) {
3353 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3354 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3355 /* the event could have been dropped. Because this can only
3356 * happen if the user asked for it, it's not an error */
3357 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3358 data.ret = GST_FLOW_OK;
3368 * @pad: a #GstPad to invoke the default query on.
3369 * @query: (transfer none): the #GstQuery to perform.
3371 * Dispatches a query to a pad. The query should have been allocated by the
3372 * caller via one of the type-specific allocation functions. The element that
3373 * the pad belongs to is responsible for filling the query with an appropriate
3374 * response, which should then be parsed with a type-specific query parsing
3377 * Again, the caller is responsible for both the allocation and deallocation of
3378 * the query structure.
3380 * Please also note that some queries might need a running pipeline to work.
3382 * Returns: TRUE if the query could be performed.
3385 gst_pad_query (GstPad * pad, GstQuery * query)
3388 gboolean res, serialized;
3389 GstPadQueryFunction func;
3390 GstPadProbeType type;
3393 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3394 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3396 if (GST_PAD_IS_SRC (pad)) {
3397 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3398 goto wrong_direction;
3399 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3400 } else if (GST_PAD_IS_SINK (pad)) {
3401 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3402 goto wrong_direction;
3403 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3405 goto unknown_direction;
3407 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3408 GST_QUERY_TYPE_NAME (query));
3410 serialized = GST_QUERY_IS_SERIALIZED (query);
3411 if (G_UNLIKELY (serialized))
3412 GST_PAD_STREAM_LOCK (pad);
3414 GST_OBJECT_LOCK (pad);
3415 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3416 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3417 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3419 ACQUIRE_PARENT (pad, parent, no_parent);
3420 GST_OBJECT_UNLOCK (pad);
3422 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3425 res = func (pad, parent, query);
3427 RELEASE_PARENT (parent);
3429 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3430 GST_QUERY_TYPE_NAME (query), res);
3435 GST_OBJECT_LOCK (pad);
3436 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3437 GST_OBJECT_UNLOCK (pad);
3439 if (G_UNLIKELY (serialized))
3440 GST_PAD_STREAM_UNLOCK (pad);
3447 g_warning ("pad %s:%s query %s in wrong direction",
3448 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3453 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3458 GST_DEBUG_OBJECT (pad, "had no parent");
3459 GST_OBJECT_UNLOCK (pad);
3460 if (G_UNLIKELY (serialized))
3461 GST_PAD_STREAM_UNLOCK (pad);
3466 GST_DEBUG_OBJECT (pad, "had no query function");
3467 RELEASE_PARENT (parent);
3468 if (G_UNLIKELY (serialized))
3469 GST_PAD_STREAM_UNLOCK (pad);
3474 GST_DEBUG_OBJECT (pad, "query failed");
3475 if (G_UNLIKELY (serialized))
3476 GST_PAD_STREAM_UNLOCK (pad);
3481 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3482 GST_OBJECT_UNLOCK (pad);
3483 if (G_UNLIKELY (serialized))
3484 GST_PAD_STREAM_UNLOCK (pad);
3486 /* if a probe dropped, we don't sent it further but assume that the probe
3487 * answered the query and return TRUE */
3488 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3498 * gst_pad_peer_query:
3499 * @pad: a #GstPad to invoke the peer query on.
3500 * @query: (transfer none): the #GstQuery to perform.
3502 * Performs gst_pad_query() on the peer of @pad.
3504 * The caller is responsible for both the allocation and deallocation of
3505 * the query structure.
3507 * Returns: TRUE if the query could be performed. This function returns %FALSE
3508 * if @pad has no peer.
3511 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3514 GstPadProbeType type;
3515 gboolean res, serialized;
3518 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3519 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3521 if (GST_PAD_IS_SRC (pad)) {
3522 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3523 goto wrong_direction;
3524 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3525 } else if (GST_PAD_IS_SINK (pad)) {
3526 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3527 goto wrong_direction;
3528 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3530 goto unknown_direction;
3532 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3533 GST_QUERY_TYPE_NAME (query));
3535 serialized = GST_QUERY_IS_SERIALIZED (query);
3537 GST_OBJECT_LOCK (pad);
3538 if (GST_PAD_IS_SRC (pad) && serialized) {
3539 /* all serialized queries on the srcpad trigger push of
3541 if (!check_sticky (pad) == GST_FLOW_OK)
3545 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3546 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3547 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3549 peerpad = GST_PAD_PEER (pad);
3550 if (G_UNLIKELY (peerpad == NULL))
3553 gst_object_ref (peerpad);
3554 GST_OBJECT_UNLOCK (pad);
3556 res = gst_pad_query (peerpad, query);
3558 gst_object_unref (peerpad);
3563 GST_OBJECT_LOCK (pad);
3564 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3565 GST_OBJECT_UNLOCK (pad);
3572 g_warning ("pad %s:%s query %s in wrong direction",
3573 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3578 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3583 GST_WARNING_OBJECT (pad, "could not send sticky events");
3584 GST_OBJECT_UNLOCK (pad);
3589 GST_INFO_OBJECT (pad, "pad has no peer");
3590 GST_OBJECT_UNLOCK (pad);
3595 GST_DEBUG_OBJECT (pad, "query failed");
3600 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3601 GST_OBJECT_UNLOCK (pad);
3603 /* if a probe dropped, we don't sent it further but assume that the probe
3604 * answered the query and return TRUE */
3605 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3614 /**********************************************************************
3615 * Data passing functions
3618 /* this is the chain function that does not perform the additional argument
3619 * checking for that little extra speed.
3621 static inline GstFlowReturn
3622 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3627 GST_PAD_STREAM_LOCK (pad);
3629 GST_OBJECT_LOCK (pad);
3630 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3633 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3636 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3639 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3641 PROBE_PUSH (pad, type, data, probe_stopped);
3643 parent = GST_OBJECT_PARENT (pad);
3644 GST_OBJECT_UNLOCK (pad);
3646 /* NOTE: we read the chainfunc unlocked.
3647 * we cannot hold the lock for the pad so we might send
3648 * the data to the wrong function. This is not really a
3649 * problem since functions are assigned at creation time
3650 * and don't change that often... */
3651 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3652 GstPadChainFunction chainfunc;
3654 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3657 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3658 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3659 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3661 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3663 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3664 "called chainfunction &%s with buffer %p, returned %s",
3665 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3667 GstPadChainListFunction chainlistfunc;
3669 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3672 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3673 "calling chainlistfunction &%s",
3674 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3676 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3678 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3679 "called chainlistfunction &%s, returned %s",
3680 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3683 GST_PAD_STREAM_UNLOCK (pad);
3690 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3691 "chaining, but pad was flushing");
3692 GST_OBJECT_UNLOCK (pad);
3693 GST_PAD_STREAM_UNLOCK (pad);
3694 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3695 return GST_FLOW_FLUSHING;
3699 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3700 GST_OBJECT_UNLOCK (pad);
3701 GST_PAD_STREAM_UNLOCK (pad);
3702 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3703 return GST_FLOW_EOS;
3707 g_critical ("chain on pad %s:%s but it was not in push mode",
3708 GST_DEBUG_PAD_NAME (pad));
3709 GST_OBJECT_UNLOCK (pad);
3710 GST_PAD_STREAM_UNLOCK (pad);
3711 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3712 return GST_FLOW_ERROR;
3716 GST_OBJECT_UNLOCK (pad);
3717 GST_PAD_STREAM_UNLOCK (pad);
3718 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3721 case GST_FLOW_CUSTOM_SUCCESS:
3722 GST_DEBUG_OBJECT (pad, "dropped buffer");
3726 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3733 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3734 g_critical ("chain on pad %s:%s but it has no chainfunction",
3735 GST_DEBUG_PAD_NAME (pad));
3736 GST_PAD_STREAM_UNLOCK (pad);
3737 return GST_FLOW_NOT_SUPPORTED;
3743 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3744 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3747 * Chain a buffer to @pad.
3749 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3751 * If the buffer type is not acceptable for @pad (as negotiated with a
3752 * preceeding GST_EVENT_CAPS event), this function returns
3753 * #GST_FLOW_NOT_NEGOTIATED.
3755 * The function proceeds calling the chain function installed on @pad (see
3756 * gst_pad_set_chain_function()) and the return value of that function is
3757 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3760 * In all cases, success or failure, the caller loses its reference to @buffer
3761 * after calling this function.
3763 * Returns: a #GstFlowReturn from the pad.
3768 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3770 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3771 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3772 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3774 return gst_pad_chain_data_unchecked (pad,
3775 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3778 static GstFlowReturn
3779 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3780 GstBufferList * list)
3786 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3788 len = gst_buffer_list_length (list);
3791 for (i = 0; i < len; i++) {
3792 buffer = gst_buffer_list_get (list, i);
3794 gst_pad_chain_data_unchecked (pad,
3795 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3796 gst_buffer_ref (buffer));
3797 if (ret != GST_FLOW_OK)
3800 gst_buffer_list_unref (list);
3806 * gst_pad_chain_list:
3807 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3808 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3811 * Chain a bufferlist to @pad.
3813 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3815 * If @pad was not negotiated properly with a CAPS event, this function
3816 * returns #GST_FLOW_NOT_NEGOTIATED.
3818 * The function proceeds calling the chainlist function installed on @pad (see
3819 * gst_pad_set_chain_list_function()) and the return value of that function is
3820 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3821 * chainlist function.
3823 * In all cases, success or failure, the caller loses its reference to @list
3824 * after calling this function.
3828 * Returns: a #GstFlowReturn from the pad.
3831 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3833 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3834 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3835 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3837 return gst_pad_chain_data_unchecked (pad,
3838 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3841 static GstFlowReturn
3842 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3847 GST_OBJECT_LOCK (pad);
3848 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3851 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3854 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3857 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
3860 /* do block probes */
3861 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3863 /* recheck sticky events because the probe might have cause a relink */
3864 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
3867 /* do post-blocking probes */
3868 PROBE_PUSH (pad, type, data, probe_stopped);
3870 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3873 /* take ref to peer pad before releasing the lock */
3874 gst_object_ref (peer);
3876 GST_OBJECT_UNLOCK (pad);
3878 ret = gst_pad_chain_data_unchecked (peer, type, data);
3880 gst_object_unref (peer);
3882 GST_OBJECT_LOCK (pad);
3884 if (pad->priv->using == 0) {
3885 /* pad is not active anymore, trigger idle callbacks */
3886 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3887 probe_stopped, ret);
3889 GST_OBJECT_UNLOCK (pad);
3893 /* ERROR recovery here */
3897 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3898 "pushing, but pad was flushing");
3899 GST_OBJECT_UNLOCK (pad);
3900 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3901 return GST_FLOW_FLUSHING;
3905 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3906 GST_OBJECT_UNLOCK (pad);
3907 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3908 return GST_FLOW_EOS;
3912 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3913 GST_DEBUG_PAD_NAME (pad));
3914 GST_OBJECT_UNLOCK (pad);
3915 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3916 return GST_FLOW_ERROR;
3920 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3921 "error pushing events, return %s", gst_flow_get_name (ret));
3922 GST_OBJECT_UNLOCK (pad);
3923 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3928 GST_OBJECT_UNLOCK (pad);
3929 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3932 case GST_FLOW_CUSTOM_SUCCESS:
3933 GST_DEBUG_OBJECT (pad, "dropped buffer");
3937 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3944 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3945 "pushing, but it was not linked");
3946 GST_OBJECT_UNLOCK (pad);
3947 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3948 return GST_FLOW_NOT_LINKED;
3954 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3955 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3958 * Pushes a buffer to the peer of @pad.
3960 * This function will call installed block probes before triggering any
3961 * installed data probes.
3963 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3964 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3967 * In all cases, success or failure, the caller loses its reference to @buffer
3968 * after calling this function.
3970 * Returns: a #GstFlowReturn from the peer pad.
3975 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3977 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3978 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3979 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3981 return gst_pad_push_data (pad,
3982 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3986 * gst_pad_push_list:
3987 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3988 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3991 * Pushes a buffer list to the peer of @pad.
3993 * This function will call installed block probes before triggering any
3994 * installed data probes.
3996 * The function proceeds calling the chain function on the peer pad and returns
3997 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3998 * be returned. If the peer pad does not have any installed chainlist function
3999 * every group buffer of the list will be merged into a normal #GstBuffer and
4000 * chained via gst_pad_chain().
4002 * In all cases, success or failure, the caller loses its reference to @list
4003 * after calling this function.
4005 * Returns: a #GstFlowReturn from the peer pad.
4010 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4012 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4013 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4014 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4016 return gst_pad_push_data (pad,
4017 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4020 static GstFlowReturn
4021 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4022 GstBuffer ** buffer)
4025 GstPadGetRangeFunction getrangefunc;
4029 GST_PAD_STREAM_LOCK (pad);
4031 GST_OBJECT_LOCK (pad);
4032 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4035 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4038 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
4043 /* when one of the probes returns DROPPED, probe_stopped will be called
4044 * and we skip calling the getrange function, res_buf should then contain a
4045 * valid result buffer */
4046 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4047 res_buf, offset, size, probe_stopped);
4049 /* recheck sticky events because the probe might have cause a relink */
4050 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
4053 ACQUIRE_PARENT (pad, parent, no_parent);
4054 GST_OBJECT_UNLOCK (pad);
4056 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4059 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4060 "calling getrangefunc %s, offset %"
4061 G_GUINT64_FORMAT ", size %u",
4062 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4064 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4066 RELEASE_PARENT (parent);
4068 if (G_UNLIKELY (ret != GST_FLOW_OK))
4069 goto get_range_failed;
4071 /* can only fire the signal if we have a valid buffer */
4072 GST_OBJECT_LOCK (pad);
4074 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4075 res_buf, offset, size, probe_stopped_unref);
4076 GST_OBJECT_UNLOCK (pad);
4078 GST_PAD_STREAM_UNLOCK (pad);
4087 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4088 "getrange, but pad was flushing");
4089 GST_OBJECT_UNLOCK (pad);
4090 GST_PAD_STREAM_UNLOCK (pad);
4091 return GST_FLOW_FLUSHING;
4095 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4096 GST_DEBUG_PAD_NAME (pad));
4097 GST_OBJECT_UNLOCK (pad);
4098 GST_PAD_STREAM_UNLOCK (pad);
4099 return GST_FLOW_ERROR;
4103 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4104 GST_OBJECT_UNLOCK (pad);
4105 GST_PAD_STREAM_UNLOCK (pad);
4110 GST_DEBUG_OBJECT (pad, "no parent");
4111 GST_OBJECT_UNLOCK (pad);
4112 GST_PAD_STREAM_UNLOCK (pad);
4113 return GST_FLOW_FLUSHING;
4117 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4118 GST_DEBUG_PAD_NAME (pad));
4119 RELEASE_PARENT (parent);
4120 GST_PAD_STREAM_UNLOCK (pad);
4121 return GST_FLOW_NOT_SUPPORTED;
4125 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4126 "probe returned %s", gst_flow_get_name (ret));
4127 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4129 /* the probe filled the buffer and asks us to not call the getrange
4130 * anymore, we continue with the post probes then. */
4131 GST_DEBUG_OBJECT (pad, "handled buffer");
4135 /* no buffer, we are EOS */
4136 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4140 GST_OBJECT_UNLOCK (pad);
4141 GST_PAD_STREAM_UNLOCK (pad);
4145 probe_stopped_unref:
4147 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4148 "probe returned %s", gst_flow_get_name (ret));
4149 /* if we drop here, it signals EOS */
4150 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4152 GST_OBJECT_UNLOCK (pad);
4153 GST_PAD_STREAM_UNLOCK (pad);
4154 if (*buffer == NULL)
4155 gst_buffer_unref (res_buf);
4160 GST_PAD_STREAM_UNLOCK (pad);
4161 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4162 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4163 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4169 * gst_pad_get_range:
4170 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4171 * @offset: The start offset of the buffer
4172 * @size: The length of the buffer
4173 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4174 * returns #GST_FLOW_ERROR if %NULL.
4176 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4177 * immediately and @buffer is %NULL.
4179 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4180 * description of a getrange function. If @pad has no getrange function
4181 * installed (see gst_pad_set_getrange_function()) this function returns
4182 * #GST_FLOW_NOT_SUPPORTED.
4184 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4185 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4186 * must be freed with gst_buffer_unref() after usage.
4188 * When @buffer points to a variable that points to a valid #GstBuffer, the
4189 * buffer will be filled with the result data when this function returns
4190 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4191 * @size bytes will be filled in the result buffer and its size will be updated
4194 * Note that less than @size bytes can be returned in @buffer when, for example,
4195 * an EOS condition is near or when @buffer is not large enough to hold @size
4196 * bytes. The caller should check the result buffer size to get the result size.
4198 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4199 * will be unchanged.
4201 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4203 * Returns: a #GstFlowReturn from the pad.
4208 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4209 GstBuffer ** buffer)
4211 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4212 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4213 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4214 g_return_val_if_fail (*buffer == NULL
4215 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4217 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4221 * gst_pad_pull_range:
4222 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4223 * @offset: The start offset of the buffer
4224 * @size: The length of the buffer
4225 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4226 * GST_FLOW_ERROR if %NULL.
4228 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4230 * This function will first trigger the pad block signal if it was
4233 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4234 * function returns the result of gst_pad_get_range() on the peer pad.
4235 * See gst_pad_get_range() for a list of return values and for the
4236 * semantics of the arguments of this function.
4238 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4239 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4240 * must be freed with gst_buffer_unref() after usage. When this function
4241 * returns any other result value, @buffer will still point to NULL.
4243 * When @buffer points to a variable that points to a valid #GstBuffer, the
4244 * buffer will be filled with the result data when this function returns
4245 * #GST_FLOW_OK. When this function returns any other result value,
4246 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4247 * @size bytes will be filled in the result buffer and its size will be updated
4250 * Note that less than @size bytes can be returned in @buffer when, for example,
4251 * an EOS condition is near or when @buffer is not large enough to hold @size
4252 * bytes. The caller should check the result buffer size to get the result size.
4254 * Returns: a #GstFlowReturn from the peer pad.
4259 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4260 GstBuffer ** buffer)
4266 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4267 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4268 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4269 g_return_val_if_fail (*buffer == NULL
4270 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4272 GST_OBJECT_LOCK (pad);
4273 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4276 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4281 /* when one of the probes returns DROPPED, probe_stopped will be
4282 * called and we skip calling the peer getrange function. *buffer should then
4283 * contain a valid buffer */
4284 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4285 res_buf, offset, size, probe_stopped);
4287 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4290 gst_object_ref (peer);
4292 GST_OBJECT_UNLOCK (pad);
4294 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4296 gst_object_unref (peer);
4298 GST_OBJECT_LOCK (pad);
4300 if (pad->priv->using == 0) {
4301 /* pad is not active anymore, trigger idle callbacks */
4302 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4303 probe_stopped_unref, ret);
4306 if (G_UNLIKELY (ret != GST_FLOW_OK))
4307 goto pull_range_failed;
4310 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4311 res_buf, offset, size, probe_stopped_unref);
4313 GST_OBJECT_UNLOCK (pad);
4319 /* ERROR recovery here */
4322 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4323 "pullrange, but pad was flushing");
4324 GST_OBJECT_UNLOCK (pad);
4325 return GST_FLOW_FLUSHING;
4329 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4330 GST_DEBUG_PAD_NAME (pad));
4331 GST_OBJECT_UNLOCK (pad);
4332 return GST_FLOW_ERROR;
4336 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4337 gst_flow_get_name (ret));
4338 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4340 /* the probe filled the buffer and asks us to not forward to the peer
4341 * anymore, we continue with the post probes then */
4342 GST_DEBUG_OBJECT (pad, "handled buffer");
4346 /* no buffer, we are EOS then */
4347 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4351 GST_OBJECT_UNLOCK (pad);
4356 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4357 "pulling range, but it was not linked");
4358 GST_OBJECT_UNLOCK (pad);
4359 return GST_FLOW_NOT_LINKED;
4363 GST_OBJECT_UNLOCK (pad);
4364 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4365 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4366 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4369 probe_stopped_unref:
4371 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4372 "post probe returned %s", gst_flow_get_name (ret));
4373 GST_OBJECT_UNLOCK (pad);
4374 /* if we drop here, it signals EOS */
4375 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4377 if (*buffer == NULL)
4378 gst_buffer_unref (res_buf);
4383 /* must be called with pad object lock */
4384 static GstFlowReturn
4385 store_sticky_event (GstPad * pad, GstEvent * event)
4390 gboolean res = FALSE;
4391 const gchar *name = NULL;
4393 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4396 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4399 type = GST_EVENT_TYPE (event);
4400 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4401 name = gst_structure_get_name (gst_event_get_structure (event));
4403 events = pad->priv->events;
4406 for (i = 0; i < len; i++) {
4407 PadEvent *ev = &g_array_index (events, PadEvent, i);
4409 if (ev->event == NULL)
4412 if (type == GST_EVENT_TYPE (ev->event)) {
4413 /* matching types, check matching name if needed */
4414 if (name && !gst_event_has_name (ev->event, name))
4418 if ((res = gst_event_replace (&ev->event, event)))
4419 ev->received = FALSE;
4425 ev.event = gst_event_ref (event);
4426 ev.received = FALSE;
4427 g_array_append_val (events, ev);
4432 pad->priv->events_cookie++;
4433 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4435 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4437 switch (GST_EVENT_TYPE (event)) {
4438 case GST_EVENT_CAPS:
4439 GST_OBJECT_UNLOCK (pad);
4441 GST_DEBUG_OBJECT (pad, "notify caps");
4442 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4444 GST_OBJECT_LOCK (pad);
4450 if (type == GST_EVENT_EOS)
4451 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4458 GST_DEBUG_OBJECT (pad, "pad is flushing");
4459 return GST_FLOW_FLUSHING;
4463 GST_DEBUG_OBJECT (pad, "pad is EOS");
4464 return GST_FLOW_EOS;
4469 * gst_pad_store_sticky_event:
4471 * @event: a #GstEvent
4473 * Store the sticky @event on @pad
4475 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4476 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4481 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4485 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4486 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4488 GST_OBJECT_LOCK (pad);
4489 ret = store_sticky_event (pad, event);
4490 GST_OBJECT_UNLOCK (pad);
4495 /* should be called with pad LOCK */
4496 static GstFlowReturn
4497 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4498 GstPadProbeType type)
4502 GstEventType event_type;
4504 /* Two checks to be made:
4505 * . (un)set the FLUSHING flag for flushing events,
4506 * . handle pad blocking */
4507 event_type = GST_EVENT_TYPE (event);
4508 switch (event_type) {
4509 case GST_EVENT_FLUSH_START:
4510 GST_PAD_SET_FLUSHING (pad);
4512 GST_PAD_BLOCK_BROADCAST (pad);
4513 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4515 case GST_EVENT_FLUSH_STOP:
4516 GST_PAD_UNSET_FLUSHING (pad);
4518 /* Remove sticky EOS events */
4519 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4520 remove_event_by_type (pad, GST_EVENT_EOS);
4521 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4522 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4524 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4528 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4531 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4532 * checked already or this is called as part of pushing sticky events,
4533 * in which case we still want to forward the EOS event downstream.
4536 switch (GST_EVENT_TYPE (event)) {
4537 case GST_EVENT_SEGMENT:
4538 /* pass the adjusted segment event on. We need to do this even if
4539 * there is no peer pad because of the probes. */
4540 event = apply_pad_offset (pad, event);
4542 case GST_EVENT_RECONFIGURE:
4543 if (GST_PAD_IS_SINK (pad))
4544 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4549 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4550 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4555 /* send probes after modifying the events above */
4556 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4558 /* now check the peer pad */
4559 peerpad = GST_PAD_PEER (pad);
4560 if (peerpad == NULL)
4563 gst_object_ref (peerpad);
4565 GST_OBJECT_UNLOCK (pad);
4567 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4568 event, GST_EVENT_TYPE_NAME (event), peerpad);
4570 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4572 /* Note: we gave away ownership of the event at this point but we can still
4573 * print the old pointer */
4574 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4575 event, peerpad, gst_flow_get_name (ret));
4577 gst_object_unref (peerpad);
4579 GST_OBJECT_LOCK (pad);
4581 if (pad->priv->using == 0) {
4582 /* pad is not active anymore, trigger idle callbacks */
4583 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4584 idle_probe_stopped, ret);
4588 /* ERROR handling */
4591 GST_DEBUG_OBJECT (pad, "We're flushing");
4592 gst_event_unref (event);
4593 return GST_FLOW_FLUSHING;
4597 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4598 gst_event_unref (event);
4601 case GST_FLOW_CUSTOM_SUCCESS:
4602 GST_DEBUG_OBJECT (pad, "dropped event");
4605 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4612 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4613 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4614 gst_event_unref (event);
4616 /* unlinked pads should not influence latency configuration */
4617 if (event_type == GST_EVENT_LATENCY)
4620 return GST_FLOW_NOT_LINKED;
4624 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4630 * gst_pad_push_event:
4631 * @pad: a #GstPad to push the event to.
4632 * @event: (transfer full): the #GstEvent to send to the pad.
4634 * Sends the event to the peer of the given pad. This function is
4635 * mainly used by elements to send events to their peer
4638 * This function takes owership of the provided event so you should
4639 * gst_event_ref() it if you want to reuse the event after this call.
4641 * Returns: TRUE if the event was handled.
4646 gst_pad_push_event (GstPad * pad, GstEvent * event)
4648 gboolean res = FALSE;
4649 GstPadProbeType type;
4650 gboolean sticky, serialized;
4652 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4653 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4655 if (GST_PAD_IS_SRC (pad)) {
4656 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4657 goto wrong_direction;
4658 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4659 } else if (GST_PAD_IS_SINK (pad)) {
4660 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4661 goto wrong_direction;
4662 /* events pushed on sinkpad never are sticky */
4663 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4665 goto unknown_direction;
4667 GST_OBJECT_LOCK (pad);
4668 sticky = GST_EVENT_IS_STICKY (event);
4669 serialized = GST_EVENT_IS_SERIALIZED (event);
4672 /* srcpad sticky events are stored immediately, the received flag is set
4673 * to FALSE and will be set to TRUE when we can successfully push the
4674 * event to the peer pad */
4675 switch (store_sticky_event (pad, event)) {
4676 case GST_FLOW_FLUSHING:
4684 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4685 /* all serialized or sticky events on the srcpad trigger push of
4687 res = (check_sticky (pad) == GST_FLOW_OK);
4692 /* other events are pushed right away */
4693 ret = gst_pad_push_event_unchecked (pad, event, type);
4694 /* dropped events by a probe are not an error */
4695 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4697 /* Errors in sticky event pushing are no problem and ignored here
4698 * as they will cause more meaningful errors during data flow.
4699 * For EOS events, that are not followed by data flow, we still
4700 * return FALSE here though.
4702 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4704 gst_event_unref (event);
4706 GST_OBJECT_UNLOCK (pad);
4710 /* ERROR handling */
4713 g_warning ("pad %s:%s pushing %s event in wrong direction",
4714 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4715 gst_event_unref (event);
4720 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4721 gst_event_unref (event);
4726 GST_DEBUG_OBJECT (pad, "We're flushing");
4727 GST_OBJECT_UNLOCK (pad);
4728 gst_event_unref (event);
4733 GST_DEBUG_OBJECT (pad, "We're EOS");
4734 GST_OBJECT_UNLOCK (pad);
4735 gst_event_unref (event);
4740 /* Check if we can call the event function with the given event */
4741 static GstFlowReturn
4742 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4746 switch (GST_EVENT_TYPE (event)) {
4747 case GST_EVENT_CAPS:
4749 /* backwards compatibility mode for caps */
4750 gst_event_parse_caps (event, &caps);
4752 if (!gst_pad_query_accept_caps (pad, caps))
4764 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4765 "caps %" GST_PTR_FORMAT " not accepted", caps);
4766 return GST_FLOW_NOT_NEGOTIATED;
4770 static GstFlowReturn
4771 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4772 GstPadProbeType type)
4775 GstEventType event_type;
4776 gboolean serialized, need_unlock = FALSE, sticky;
4777 GstPadEventFunction eventfunc;
4780 GST_OBJECT_LOCK (pad);
4781 if (GST_PAD_IS_SINK (pad))
4782 serialized = GST_EVENT_IS_SERIALIZED (event);
4785 sticky = GST_EVENT_IS_STICKY (event);
4786 event_type = GST_EVENT_TYPE (event);
4787 switch (event_type) {
4788 case GST_EVENT_FLUSH_START:
4789 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4790 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4792 /* can't even accept a flush begin event when flushing */
4793 if (GST_PAD_IS_FLUSHING (pad))
4796 GST_PAD_SET_FLUSHING (pad);
4797 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4799 case GST_EVENT_FLUSH_STOP:
4800 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4801 GST_PAD_UNSET_FLUSHING (pad);
4802 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4804 /* Remove pending EOS events */
4805 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4806 remove_event_by_type (pad, GST_EVENT_EOS);
4807 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4808 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4810 GST_OBJECT_UNLOCK (pad);
4811 /* grab stream lock */
4812 GST_PAD_STREAM_LOCK (pad);
4814 GST_OBJECT_LOCK (pad);
4815 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4818 case GST_EVENT_RECONFIGURE:
4819 if (GST_PAD_IS_SRC (pad))
4820 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4822 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4823 "have event type %" GST_PTR_FORMAT, event);
4825 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4829 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4832 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4833 GST_OBJECT_UNLOCK (pad);
4834 GST_PAD_STREAM_LOCK (pad);
4836 GST_OBJECT_LOCK (pad);
4837 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4840 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4844 switch (GST_EVENT_TYPE (event)) {
4845 case GST_EVENT_SEGMENT:
4846 event = apply_pad_offset (pad, event);
4852 /* now do the probe */
4854 type | GST_PAD_PROBE_TYPE_PUSH |
4855 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4857 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4861 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4864 ACQUIRE_PARENT (pad, parent, no_parent);
4865 GST_OBJECT_UNLOCK (pad);
4867 ret = pre_eventfunc_check (pad, event);
4868 if (G_UNLIKELY (ret != GST_FLOW_OK))
4869 goto precheck_failed;
4872 gst_event_ref (event);
4874 if (eventfunc (pad, parent, event)) {
4877 /* something went wrong */
4878 switch (event_type) {
4879 case GST_EVENT_CAPS:
4880 ret = GST_FLOW_NOT_NEGOTIATED;
4883 ret = GST_FLOW_ERROR;
4887 RELEASE_PARENT (parent);
4889 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4892 if (ret == GST_FLOW_OK) {
4893 GST_OBJECT_LOCK (pad);
4894 /* after the event function accepted the event, we can store the sticky
4895 * event on the pad */
4896 switch (store_sticky_event (pad, event)) {
4897 case GST_FLOW_FLUSHING:
4904 GST_OBJECT_UNLOCK (pad);
4906 gst_event_unref (event);
4910 GST_PAD_STREAM_UNLOCK (pad);
4914 /* ERROR handling */
4917 GST_OBJECT_UNLOCK (pad);
4919 GST_PAD_STREAM_UNLOCK (pad);
4920 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4921 "Received event on flushing pad. Discarding");
4922 gst_event_unref (event);
4923 return GST_FLOW_FLUSHING;
4927 GST_OBJECT_UNLOCK (pad);
4929 GST_PAD_STREAM_UNLOCK (pad);
4930 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4931 "Received event on EOS pad. Discarding");
4932 gst_event_unref (event);
4933 return GST_FLOW_EOS;
4937 GST_OBJECT_UNLOCK (pad);
4939 GST_PAD_STREAM_UNLOCK (pad);
4940 gst_event_unref (event);
4943 case GST_FLOW_CUSTOM_SUCCESS:
4944 GST_DEBUG_OBJECT (pad, "dropped event");
4948 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4955 g_warning ("pad %s:%s has no event handler, file a bug.",
4956 GST_DEBUG_PAD_NAME (pad));
4957 GST_OBJECT_UNLOCK (pad);
4959 GST_PAD_STREAM_UNLOCK (pad);
4960 gst_event_unref (event);
4961 return GST_FLOW_NOT_SUPPORTED;
4965 GST_DEBUG_OBJECT (pad, "no parent");
4966 GST_OBJECT_UNLOCK (pad);
4968 GST_PAD_STREAM_UNLOCK (pad);
4969 gst_event_unref (event);
4970 return GST_FLOW_FLUSHING;
4974 GST_DEBUG_OBJECT (pad, "pre event check failed");
4975 RELEASE_PARENT (parent);
4977 GST_PAD_STREAM_UNLOCK (pad);
4978 gst_event_unref (event);
4984 * gst_pad_send_event:
4985 * @pad: a #GstPad to send the event to.
4986 * @event: (transfer full): the #GstEvent to send to the pad.
4988 * Sends the event to the pad. This function can be used
4989 * by applications to send events in the pipeline.
4991 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4992 * sink pad, @event should be a downstream event. For example, you would not
4993 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4994 * Furthermore, some downstream events have to be serialized with data flow,
4995 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4996 * the event needs to be serialized with data flow, this function will take the
4997 * pad's stream lock while calling its event function.
4999 * To find out whether an event type is upstream, downstream, or downstream and
5000 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5001 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5002 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5003 * plugin doesn't need to bother itself with this information; the core handles
5004 * all necessary locks and checks.
5006 * This function takes owership of the provided event so you should
5007 * gst_event_ref() it if you want to reuse the event after this call.
5009 * Returns: TRUE if the event was handled.
5012 gst_pad_send_event (GstPad * pad, GstEvent * event)
5015 GstPadProbeType type;
5017 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5018 g_return_val_if_fail (event != NULL, FALSE);
5020 if (GST_PAD_IS_SINK (pad)) {
5021 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5022 goto wrong_direction;
5023 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5024 } else if (GST_PAD_IS_SRC (pad)) {
5025 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5026 goto wrong_direction;
5027 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5029 goto unknown_direction;
5031 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5038 /* ERROR handling */
5041 g_warning ("pad %s:%s sending %s event in wrong direction",
5042 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5043 gst_event_unref (event);
5048 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5049 gst_event_unref (event);
5055 * gst_pad_set_element_private:
5056 * @pad: the #GstPad to set the private data of.
5057 * @priv: The private data to attach to the pad.
5059 * Set the given private data gpointer on the pad.
5060 * This function can only be used by the element that owns the pad.
5061 * No locking is performed in this function.
5064 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5066 pad->element_private = priv;
5070 * gst_pad_get_element_private:
5071 * @pad: the #GstPad to get the private data of.
5073 * Gets the private data of a pad.
5074 * No locking is performed in this function.
5076 * Returns: (transfer none): a #gpointer to the private data.
5079 gst_pad_get_element_private (GstPad * pad)
5081 return pad->element_private;
5085 * gst_pad_get_sticky_event:
5086 * @pad: the #GstPad to get the event from.
5087 * @event_type: the #GstEventType that should be retrieved.
5088 * @idx: the index of the event
5090 * Returns a new reference of the sticky event of type @event_type
5093 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5094 * event of @event_type was on @pad. Unref after usage.
5097 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5099 GstEvent *event = NULL;
5102 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5103 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5105 GST_OBJECT_LOCK (pad);
5106 ev = find_event_by_type (pad, event_type, idx);
5107 if (ev && (event = ev->event))
5108 gst_event_ref (event);
5109 GST_OBJECT_UNLOCK (pad);
5116 GstPadStickyEventsForeachFunction func;
5121 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5123 ForeachDispatch *data = user_data;
5126 GST_OBJECT_UNLOCK (pad);
5128 ret = data->func (pad, &ev->event, data->user_data);
5130 GST_OBJECT_LOCK (pad);
5136 * gst_pad_sticky_events_foreach:
5137 * @pad: the #GstPad that should be used for iteration.
5138 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5139 * should be called for every event.
5140 * @user_data: (closure): the optional user data.
5142 * Iterates all sticky events on @pad and calls @foreach_func for every
5143 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5146 gst_pad_sticky_events_foreach (GstPad * pad,
5147 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5149 ForeachDispatch data;
5151 g_return_if_fail (GST_IS_PAD (pad));
5152 g_return_if_fail (foreach_func != NULL);
5154 data.func = foreach_func;
5155 data.user_data = user_data;
5157 GST_OBJECT_LOCK (pad);
5158 events_foreach (pad, foreach_dispatch_function, &data);
5159 GST_OBJECT_UNLOCK (pad);
5163 do_stream_status (GstPad * pad, GstStreamStatusType type,
5164 GThread * thread, GstTask * task)
5168 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5170 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5171 if (GST_IS_ELEMENT (parent)) {
5172 GstMessage *message;
5173 GValue value = { 0 };
5175 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5176 gchar *tname, *ename, *pname;
5178 /* create a good task name */
5179 ename = gst_element_get_name (parent);
5180 pname = gst_pad_get_name (pad);
5181 tname = g_strdup_printf ("%s:%s", ename, pname);
5185 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5189 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5192 g_value_init (&value, GST_TYPE_TASK);
5193 g_value_set_object (&value, task);
5194 gst_message_set_stream_status_object (message, &value);
5195 g_value_unset (&value);
5197 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5198 gst_element_post_message (parent, message);
5200 gst_object_unref (parent);
5205 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5207 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5212 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5214 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5219 * gst_pad_start_task:
5220 * @pad: the #GstPad to start the task of
5221 * @func: the task function to call
5222 * @user_data: user data passed to the task function
5223 * @notify: called when @user_data is no longer referenced
5225 * Starts a task that repeatedly calls @func with @user_data. This function
5226 * is mostly used in pad activation functions to start the dataflow.
5227 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5228 * before @func is called.
5230 * Returns: a %TRUE if the task could be started.
5233 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5234 GDestroyNotify notify)
5239 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5240 g_return_val_if_fail (func != NULL, FALSE);
5242 GST_DEBUG_OBJECT (pad, "start task");
5244 GST_OBJECT_LOCK (pad);
5245 task = GST_PAD_TASK (pad);
5247 task = gst_task_new (func, user_data, notify);
5248 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5249 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5250 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5251 GST_INFO_OBJECT (pad, "created task %p", task);
5252 GST_PAD_TASK (pad) = task;
5253 gst_object_ref (task);
5254 /* release lock to post the message */
5255 GST_OBJECT_UNLOCK (pad);
5257 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5259 gst_object_unref (task);
5261 GST_OBJECT_LOCK (pad);
5262 /* nobody else is supposed to have changed the pad now */
5263 if (GST_PAD_TASK (pad) != task)
5264 goto concurrent_stop;
5266 res = gst_task_set_state (task, GST_TASK_STARTED);
5267 GST_OBJECT_UNLOCK (pad);
5274 GST_OBJECT_UNLOCK (pad);
5280 * gst_pad_pause_task:
5281 * @pad: the #GstPad to pause the task of
5283 * Pause the task of @pad. This function will also wait until the
5284 * function executed by the task is finished if this function is not
5285 * called from the task function.
5287 * Returns: a TRUE if the task could be paused or FALSE when the pad
5291 gst_pad_pause_task (GstPad * pad)
5296 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5298 GST_DEBUG_OBJECT (pad, "pause task");
5300 GST_OBJECT_LOCK (pad);
5301 task = GST_PAD_TASK (pad);
5304 res = gst_task_set_state (task, GST_TASK_PAUSED);
5305 GST_OBJECT_UNLOCK (pad);
5307 /* wait for task function to finish, this lock is recursive so it does nothing
5308 * when the pause is called from the task itself */
5309 GST_PAD_STREAM_LOCK (pad);
5310 GST_PAD_STREAM_UNLOCK (pad);
5316 GST_DEBUG_OBJECT (pad, "pad has no task");
5317 GST_OBJECT_UNLOCK (pad);
5323 * gst_pad_stop_task:
5324 * @pad: the #GstPad to stop the task of
5326 * Stop the task of @pad. This function will also make sure that the
5327 * function executed by the task will effectively stop if not called
5328 * from the GstTaskFunction.
5330 * This function will deadlock if called from the GstTaskFunction of
5331 * the task. Use gst_task_pause() instead.
5333 * Regardless of whether the pad has a task, the stream lock is acquired and
5334 * released so as to ensure that streaming through this pad has finished.
5336 * Returns: a TRUE if the task could be stopped or FALSE on error.
5339 gst_pad_stop_task (GstPad * pad)
5344 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5346 GST_DEBUG_OBJECT (pad, "stop task");
5348 GST_OBJECT_LOCK (pad);
5349 task = GST_PAD_TASK (pad);
5352 GST_PAD_TASK (pad) = NULL;
5353 res = gst_task_set_state (task, GST_TASK_STOPPED);
5354 GST_OBJECT_UNLOCK (pad);
5356 GST_PAD_STREAM_LOCK (pad);
5357 GST_PAD_STREAM_UNLOCK (pad);
5359 if (!gst_task_join (task))
5362 gst_object_unref (task);
5368 GST_DEBUG_OBJECT (pad, "no task");
5369 GST_OBJECT_UNLOCK (pad);
5371 GST_PAD_STREAM_LOCK (pad);
5372 GST_PAD_STREAM_UNLOCK (pad);
5374 /* this is not an error */
5379 /* this is bad, possibly the application tried to join the task from
5380 * the task's thread. We install the task again so that it will be stopped
5381 * again from the right thread next time hopefully. */
5382 GST_OBJECT_LOCK (pad);
5383 GST_DEBUG_OBJECT (pad, "join failed");
5384 /* we can only install this task if there was no other task */
5385 if (GST_PAD_TASK (pad) == NULL)
5386 GST_PAD_TASK (pad) = task;
5387 GST_OBJECT_UNLOCK (pad);
5394 * gst_pad_probe_info_get_event:
5395 * @info: a #GstPadProbeInfo
5397 * Returns: (transfer none): The #GstEvent from the probe
5401 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5403 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5404 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5406 return GST_PAD_PROBE_INFO_EVENT (info);
5411 * gst_pad_probe_info_get_query:
5412 * @info: a #GstPadProbeInfo
5414 * Returns: (transfer none): The #GstQuery from the probe
5418 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5420 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5421 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5423 return GST_PAD_PROBE_INFO_QUERY (info);
5427 * gst_pad_probe_info_get_buffer:
5428 * @info: a #GstPadProbeInfo
5430 * Returns: (transfer none): The #GstBuffer from the probe
5434 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5436 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5438 return GST_PAD_PROBE_INFO_BUFFER (info);
5442 * gst_pad_probe_info_get_bufferlist:
5443 * @info: a #GstPadProbeInfo
5445 * Returns: (transfer none): The #GstBufferlist from the probe
5449 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5451 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5453 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);