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 by gst_element_get_static_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()
89 #include "gst_private.h"
92 #include "gstpadtemplate.h"
93 #include "gstenumtypes.h"
97 #include "gsttracerutils.h"
99 #include "glib-compat-private.h"
101 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
102 #define GST_CAT_DEFAULT GST_CAT_PADS
104 /* 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
142 guint probe_list_cookie;
145 /* counter of how many idle probes are running directly from the add_probe
146 * call. Used to block any data flowing in the pad while the idle callback
147 * Doesn't finish its work */
157 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
158 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
159 (((GstPad *)(p))->priv->idle_running > 0)
164 GstPadProbeInfo *info;
172 static void gst_pad_dispose (GObject * object);
173 static void gst_pad_finalize (GObject * object);
174 static void gst_pad_set_property (GObject * object, guint prop_id,
175 const GValue * value, GParamSpec * pspec);
176 static void gst_pad_get_property (GObject * object, guint prop_id,
177 GValue * value, GParamSpec * pspec);
179 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
180 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
181 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
182 GstObject * parent, GstBufferList * list);
184 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
185 GstEvent * event, GstPadProbeType type);
186 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
187 GstEvent * event, GstPadProbeType type);
189 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
191 static GParamSpec *pspec_caps = NULL;
193 /* quarks for probe signals */
194 static GQuark buffer_quark;
195 static GQuark buffer_list_quark;
196 static GQuark event_quark;
205 static GstFlowQuarks flow_quarks[] = {
206 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
207 {GST_FLOW_OK, "ok", 0},
208 {GST_FLOW_NOT_LINKED, "not-linked", 0},
209 {GST_FLOW_FLUSHING, "flushing", 0},
210 {GST_FLOW_EOS, "eos", 0},
211 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
212 {GST_FLOW_ERROR, "error", 0},
213 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
214 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
219 * @ret: a #GstFlowReturn to get the name of.
221 * Gets a string representing the given flow return.
223 * Returns: a static string with the name of the flow return.
226 gst_flow_get_name (GstFlowReturn ret)
230 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
232 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
233 if (ret == flow_quarks[i].ret)
234 return flow_quarks[i].name;
241 * @ret: a #GstFlowReturn to get the quark of.
243 * Get the unique quark for the given GstFlowReturn.
245 * Returns: the quark associated with the flow return or 0 if an
246 * invalid return was specified.
249 gst_flow_to_quark (GstFlowReturn ret)
253 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
255 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
256 if (ret == flow_quarks[i].ret)
257 return flow_quarks[i].quark;
263 * gst_pad_link_get_name:
264 * @ret: a #GstPadLinkReturn to get the name of.
266 * Gets a string representing the given pad-link return.
268 * Returns: a static string with the name of the pad-link return.
273 gst_pad_link_get_name (GstPadLinkReturn ret)
276 case GST_PAD_LINK_OK:
278 case GST_PAD_LINK_WRONG_HIERARCHY:
279 return "wrong hierarchy";
280 case GST_PAD_LINK_WAS_LINKED:
282 case GST_PAD_LINK_WRONG_DIRECTION:
283 return "wrong direction";
284 case GST_PAD_LINK_NOFORMAT:
285 return "no common format";
286 case GST_PAD_LINK_NOSCHED:
287 return "incompatible scheduling";
288 case GST_PAD_LINK_REFUSED:
291 g_return_val_if_reached ("unknown");
298 buffer_quark = g_quark_from_static_string ("buffer"); \
299 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
300 event_quark = g_quark_from_static_string ("event"); \
302 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
303 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
306 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
307 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
310 #define gst_pad_parent_class parent_class
311 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
314 gst_pad_class_init (GstPadClass * klass)
316 GObjectClass *gobject_class;
317 GstObjectClass *gstobject_class;
319 gobject_class = G_OBJECT_CLASS (klass);
320 gstobject_class = GST_OBJECT_CLASS (klass);
322 g_type_class_add_private (klass, sizeof (GstPadPrivate));
324 gobject_class->dispose = gst_pad_dispose;
325 gobject_class->finalize = gst_pad_finalize;
326 gobject_class->set_property = gst_pad_set_property;
327 gobject_class->get_property = gst_pad_get_property;
331 * @pad: the pad that emitted the signal
332 * @peer: the peer pad that has been connected
334 * Signals that a pad has been linked to the peer pad.
336 gst_pad_signals[PAD_LINKED] =
337 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
338 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
339 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
342 * @pad: the pad that emitted the signal
343 * @peer: the peer pad that has been disconnected
345 * Signals that a pad has been unlinked from the peer pad.
347 gst_pad_signals[PAD_UNLINKED] =
348 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
349 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
350 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
352 pspec_caps = g_param_spec_boxed ("caps", "Caps",
353 "The capabilities of the pad", GST_TYPE_CAPS,
354 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
355 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
357 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
358 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
359 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
360 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
362 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
363 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
364 g_param_spec_object ("template", "Template",
365 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
366 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
371 * The offset that will be applied to the running time of the pad.
375 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
376 g_param_spec_int64 ("offset", "Offset",
377 "The running time offset of the pad", 0, G_MAXINT64, 0,
378 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
380 gstobject_class->path_string_separator = ".";
382 /* Register common function pointer descriptions */
383 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
384 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
385 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
386 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
387 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
391 gst_pad_init (GstPad * pad)
393 pad->priv = GST_PAD_GET_PRIVATE (pad);
395 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
397 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
398 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
399 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
400 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
401 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
403 GST_PAD_SET_FLUSHING (pad);
405 g_rec_mutex_init (&pad->stream_rec_lock);
407 g_cond_init (&pad->block_cond);
409 g_hook_list_init (&pad->probes, sizeof (GstProbe));
411 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
412 pad->priv->events_cookie = 0;
413 pad->priv->last_cookie = -1;
414 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
417 /* called when setting the pad inactive. It removes all sticky events from
418 * the pad. must be called with object lock */
420 remove_events (GstPad * pad)
424 gboolean notify = FALSE;
426 events = pad->priv->events;
429 for (i = 0; i < len; i++) {
430 PadEvent *ev = &g_array_index (events, PadEvent, i);
431 GstEvent *event = ev->event;
435 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
438 gst_event_unref (event);
441 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
442 g_array_set_size (events, 0);
443 pad->priv->events_cookie++;
446 GST_OBJECT_UNLOCK (pad);
448 GST_DEBUG_OBJECT (pad, "notify caps");
449 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
451 GST_OBJECT_LOCK (pad);
455 /* should be called with object lock */
457 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
463 events = pad->priv->events;
466 for (i = 0; i < len; i++) {
467 ev = &g_array_index (events, PadEvent, i);
468 if (ev->event == NULL)
471 if (GST_EVENT_TYPE (ev->event) == type) {
475 } else if (GST_EVENT_TYPE (ev->event) > type) {
484 /* should be called with OBJECT lock */
486 find_event (GstPad * pad, GstEvent * event)
492 events = pad->priv->events;
495 for (i = 0; i < len; i++) {
496 ev = &g_array_index (events, PadEvent, i);
497 if (event == ev->event)
499 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
507 /* should be called with OBJECT lock */
509 remove_event_by_type (GstPad * pad, GstEventType type)
515 events = pad->priv->events;
520 ev = &g_array_index (events, PadEvent, i);
521 if (ev->event == NULL)
524 if (GST_EVENT_TYPE (ev->event) > type)
526 else if (GST_EVENT_TYPE (ev->event) != type)
529 gst_event_unref (ev->event);
530 g_array_remove_index (events, i);
532 pad->priv->events_cookie++;
540 /* check all events on srcpad against those on sinkpad. All events that are not
541 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
542 * srcpad so that the events will be sent next time */
543 /* should be called with srcpad and sinkpad LOCKS */
545 schedule_events (GstPad * srcpad, GstPad * sinkpad)
550 gboolean pending = FALSE;
552 events = srcpad->priv->events;
555 for (i = 0; i < len; i++) {
556 ev = &g_array_index (events, PadEvent, i);
557 if (ev->event == NULL)
560 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
561 ev->received = FALSE;
566 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
569 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
572 /* should be called with pad LOCK */
574 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
581 events = pad->priv->events;
584 cookie = pad->priv->events_cookie;
588 PadEvent *ev, ev_ret;
590 ev = &g_array_index (events, PadEvent, i);
591 if (G_UNLIKELY (ev->event == NULL))
594 /* take aditional ref, func might release the lock */
595 ev_ret.event = gst_event_ref (ev->event);
596 ev_ret.received = ev->received;
598 ret = func (pad, &ev_ret, user_data);
600 /* recheck the cookie, lock might have been released and the list could have
602 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
603 if (G_LIKELY (ev_ret.event))
604 gst_event_unref (ev_ret.event);
608 /* store the received state */
609 ev->received = ev_ret.received;
611 /* if the event changed, we need to do something */
612 if (G_UNLIKELY (ev->event != ev_ret.event)) {
613 if (G_UNLIKELY (ev_ret.event == NULL)) {
614 /* function unreffed and set the event to NULL, remove it */
615 gst_event_unref (ev->event);
616 g_array_remove_index (events, i);
618 cookie = ++pad->priv->events_cookie;
621 /* function gave a new event for us */
622 gst_event_take (&ev->event, ev_ret.event);
625 /* just unref, nothing changed */
626 gst_event_unref (ev_ret.event);
635 /* should be called with LOCK */
637 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
641 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
642 GST_TIME_ARGS (pad->offset));
644 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
647 g_assert (!upstream);
649 /* copy segment values */
650 gst_event_copy_segment (event, &segment);
651 gst_event_unref (event);
653 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
654 event = gst_event_new_segment (&segment);
657 event = gst_event_make_writable (event);
658 offset = gst_event_get_running_time_offset (event);
660 offset -= pad->offset;
662 offset += pad->offset;
663 gst_event_set_running_time_offset (event, offset);
668 static inline GstEvent *
669 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
671 if (G_UNLIKELY (pad->offset != 0))
672 return _apply_pad_offset (pad, event, upstream);
677 /* should be called with the OBJECT_LOCK */
679 get_pad_caps (GstPad * pad)
681 GstCaps *caps = NULL;
684 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
686 gst_event_parse_caps (ev->event, &caps);
692 gst_pad_dispose (GObject * object)
694 GstPad *pad = GST_PAD_CAST (object);
697 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
699 /* unlink the peer pad */
700 if ((peer = gst_pad_get_peer (pad))) {
701 /* window for MT unsafeness, someone else could unlink here
702 * and then we call unlink with wrong pads. The unlink
703 * function would catch this and safely return failed. */
704 if (GST_PAD_IS_SRC (pad))
705 gst_pad_unlink (pad, peer);
707 gst_pad_unlink (peer, pad);
709 gst_object_unref (peer);
712 gst_pad_set_pad_template (pad, NULL);
714 GST_OBJECT_LOCK (pad);
716 GST_OBJECT_UNLOCK (pad);
718 g_hook_list_clear (&pad->probes);
720 G_OBJECT_CLASS (parent_class)->dispose (object);
724 gst_pad_finalize (GObject * object)
726 GstPad *pad = GST_PAD_CAST (object);
729 /* in case the task is still around, clean it up */
730 if ((task = GST_PAD_TASK (pad))) {
731 gst_task_join (task);
732 GST_PAD_TASK (pad) = NULL;
733 gst_object_unref (task);
736 if (pad->activatenotify)
737 pad->activatenotify (pad->activatedata);
738 if (pad->activatemodenotify)
739 pad->activatemodenotify (pad->activatemodedata);
741 pad->linknotify (pad->linkdata);
742 if (pad->unlinknotify)
743 pad->unlinknotify (pad->unlinkdata);
744 if (pad->chainnotify)
745 pad->chainnotify (pad->chaindata);
746 if (pad->chainlistnotify)
747 pad->chainlistnotify (pad->chainlistdata);
748 if (pad->getrangenotify)
749 pad->getrangenotify (pad->getrangedata);
750 if (pad->eventnotify)
751 pad->eventnotify (pad->eventdata);
752 if (pad->querynotify)
753 pad->querynotify (pad->querydata);
754 if (pad->iterintlinknotify)
755 pad->iterintlinknotify (pad->iterintlinkdata);
757 g_rec_mutex_clear (&pad->stream_rec_lock);
758 g_cond_clear (&pad->block_cond);
759 g_array_free (pad->priv->events, TRUE);
761 G_OBJECT_CLASS (parent_class)->finalize (object);
765 gst_pad_set_property (GObject * object, guint prop_id,
766 const GValue * value, GParamSpec * pspec)
768 g_return_if_fail (GST_IS_PAD (object));
771 case PAD_PROP_DIRECTION:
772 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
774 case PAD_PROP_TEMPLATE:
775 gst_pad_set_pad_template (GST_PAD_CAST (object),
776 (GstPadTemplate *) g_value_get_object (value));
778 case PAD_PROP_OFFSET:
779 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
782 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
788 gst_pad_get_property (GObject * object, guint prop_id,
789 GValue * value, GParamSpec * pspec)
791 g_return_if_fail (GST_IS_PAD (object));
795 GST_OBJECT_LOCK (object);
796 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
797 GST_OBJECT_UNLOCK (object);
799 case PAD_PROP_DIRECTION:
800 g_value_set_enum (value, GST_PAD_DIRECTION (object));
802 case PAD_PROP_TEMPLATE:
803 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
805 case PAD_PROP_OFFSET:
806 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
809 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
816 * @name: (allow-none): the name of the new pad.
817 * @direction: the #GstPadDirection of the pad.
819 * Creates a new pad with the given name in the given direction.
820 * If name is %NULL, a guaranteed unique name (across all pads)
822 * This function makes a copy of the name so you can safely free the name.
824 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
830 gst_pad_new (const gchar * name, GstPadDirection direction)
832 return g_object_new (GST_TYPE_PAD,
833 "name", name, "direction", direction, NULL);
837 * gst_pad_new_from_template:
838 * @templ: the pad template to use
839 * @name: (allow-none): the name of the pad
841 * Creates a new pad with the given name from the given template.
842 * If name is %NULL, a guaranteed unique name (across all pads)
844 * This function makes a copy of the name so you can safely free the name.
846 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
850 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
852 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
854 return g_object_new (GST_TYPE_PAD,
855 "name", name, "direction", templ->direction, "template", templ, NULL);
859 * gst_pad_new_from_static_template:
860 * @templ: the #GstStaticPadTemplate to use
861 * @name: the name of the pad
863 * Creates a new pad with the given name from the given static template.
864 * If name is %NULL, a guaranteed unique name (across all pads)
866 * This function makes a copy of the name so you can safely free the name.
868 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
872 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
876 GstPadTemplate *template;
878 template = gst_static_pad_template_get (templ);
879 pad = gst_pad_new_from_template (template, name);
880 gst_object_unref (template);
884 #define ACQUIRE_PARENT(pad, parent, label) \
886 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
887 gst_object_ref (parent); \
888 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
892 #define RELEASE_PARENT(parent) \
894 if (G_LIKELY (parent)) \
895 gst_object_unref (parent); \
899 * gst_pad_get_direction:
900 * @pad: a #GstPad to get the direction of.
902 * Gets the direction of the pad. The direction of the pad is
903 * decided at construction time so this function does not take
906 * Returns: the #GstPadDirection of the pad.
911 gst_pad_get_direction (GstPad * pad)
913 GstPadDirection result;
915 /* PAD_UNKNOWN is a little silly but we need some sort of
916 * error return value */
917 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
919 result = GST_PAD_DIRECTION (pad);
925 gst_pad_activate_default (GstPad * pad, GstObject * parent)
927 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
931 * gst_pad_mode_get_name:
932 * @mode: the pad mode
934 * Return the name of a pad mode, for use in debug messages mostly.
936 * Returns: short mnemonic for pad mode @mode
939 gst_pad_mode_get_name (GstPadMode mode)
942 case GST_PAD_MODE_NONE:
944 case GST_PAD_MODE_PUSH:
946 case GST_PAD_MODE_PULL:
955 pre_activate (GstPad * pad, GstPadMode new_mode)
958 case GST_PAD_MODE_NONE:
959 GST_OBJECT_LOCK (pad);
960 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
961 GST_PAD_SET_FLUSHING (pad);
962 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
963 GST_PAD_MODE (pad) = new_mode;
964 /* unlock blocked pads so element can resume and stop */
965 GST_PAD_BLOCK_BROADCAST (pad);
966 GST_OBJECT_UNLOCK (pad);
968 case GST_PAD_MODE_PUSH:
969 case GST_PAD_MODE_PULL:
970 GST_OBJECT_LOCK (pad);
971 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
972 gst_pad_mode_get_name (new_mode));
973 GST_PAD_UNSET_FLUSHING (pad);
974 pad->ABI.abi.last_flowret = GST_FLOW_OK;
975 GST_PAD_MODE (pad) = new_mode;
976 if (GST_PAD_IS_SINK (pad)) {
978 /* make sure the peer src pad sends us all events */
979 if ((peer = GST_PAD_PEER (pad))) {
980 gst_object_ref (peer);
981 GST_OBJECT_UNLOCK (pad);
983 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
984 GST_DEBUG_PAD_NAME (peer));
986 GST_OBJECT_LOCK (peer);
987 schedule_events (peer, NULL);
988 GST_OBJECT_UNLOCK (peer);
990 gst_object_unref (peer);
992 GST_OBJECT_UNLOCK (pad);
995 GST_OBJECT_UNLOCK (pad);
1002 post_activate (GstPad * pad, GstPadMode new_mode)
1005 case GST_PAD_MODE_NONE:
1006 /* ensures that streaming stops */
1007 GST_PAD_STREAM_LOCK (pad);
1008 GST_DEBUG_OBJECT (pad, "stopped streaming");
1009 GST_OBJECT_LOCK (pad);
1010 remove_events (pad);
1011 GST_OBJECT_UNLOCK (pad);
1012 GST_PAD_STREAM_UNLOCK (pad);
1014 case GST_PAD_MODE_PUSH:
1015 case GST_PAD_MODE_PULL:
1022 * gst_pad_set_active:
1023 * @pad: the #GstPad to activate or deactivate.
1024 * @active: whether or not the pad should be active.
1026 * Activates or deactivates the given pad.
1027 * Normally called from within core state change functions.
1029 * If @active, makes sure the pad is active. If it is already active, either in
1030 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1031 * function to perform the actual activation.
1033 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1034 * and a %FALSE argument.
1036 * Returns: %TRUE if the operation was successful.
1041 gst_pad_set_active (GstPad * pad, gboolean active)
1045 gboolean ret = FALSE;
1047 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1049 GST_OBJECT_LOCK (pad);
1050 old = GST_PAD_MODE (pad);
1051 ACQUIRE_PARENT (pad, parent, no_parent);
1052 GST_OBJECT_UNLOCK (pad);
1055 if (old == GST_PAD_MODE_NONE) {
1056 GST_DEBUG_OBJECT (pad, "activating pad from none");
1057 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1059 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1061 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1062 gst_pad_mode_get_name (old));
1066 if (old == GST_PAD_MODE_NONE) {
1067 GST_DEBUG_OBJECT (pad, "pad was inactive");
1070 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1071 gst_pad_mode_get_name (old));
1072 ret = gst_pad_activate_mode (pad, old, FALSE);
1074 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1078 RELEASE_PARENT (parent);
1080 if (G_UNLIKELY (!ret))
1088 GST_DEBUG_OBJECT (pad, "no parent");
1089 GST_OBJECT_UNLOCK (pad);
1094 GST_OBJECT_LOCK (pad);
1096 g_critical ("Failed to deactivate pad %s:%s, very bad",
1097 GST_DEBUG_PAD_NAME (pad));
1099 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1101 GST_OBJECT_UNLOCK (pad);
1107 * gst_pad_activate_mode:
1108 * @pad: the #GstPad to activate or deactivate.
1109 * @mode: the requested activation mode
1110 * @active: whether or not the pad should be active.
1112 * Activates or deactivates the given pad in @mode via dispatching to the
1113 * pad's activatemodefunc. For use from within pad activation functions only.
1115 * If you don't know what this is, you probably don't want to call it.
1117 * Returns: %TRUE if the operation was successful.
1122 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1124 gboolean res = FALSE;
1126 GstPadMode old, new;
1127 GstPadDirection dir;
1130 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1132 GST_OBJECT_LOCK (pad);
1133 old = GST_PAD_MODE (pad);
1134 dir = GST_PAD_DIRECTION (pad);
1135 ACQUIRE_PARENT (pad, parent, no_parent);
1136 GST_OBJECT_UNLOCK (pad);
1138 new = active ? mode : GST_PAD_MODE_NONE;
1143 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1144 /* pad was activate in the wrong direction, deactivate it
1145 * and reactivate it in the requested mode */
1146 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1147 gst_pad_mode_get_name (old));
1149 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1150 goto deactivate_failed;
1154 case GST_PAD_MODE_PULL:
1156 if (dir == GST_PAD_SINK) {
1157 if ((peer = gst_pad_get_peer (pad))) {
1158 GST_DEBUG_OBJECT (pad, "calling peer");
1159 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1161 gst_object_unref (peer);
1163 /* there is no peer, this is only fatal when we activate. When we
1164 * deactivate, we must assume the application has unlinked the peer and
1165 * will deactivate it eventually. */
1169 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1172 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1173 goto failure; /* Can't activate pull on a src without a
1174 getrange function */
1182 /* Mark pad as needing reconfiguration */
1184 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1185 pre_activate (pad, new);
1187 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1188 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1192 /* can happen for sinks of passthrough elements */
1195 post_activate (pad, new);
1197 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1198 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1203 /* Clear sticky flags on deactivation */
1205 GST_OBJECT_LOCK (pad);
1206 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1207 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1208 GST_OBJECT_UNLOCK (pad);
1212 RELEASE_PARENT (parent);
1218 GST_DEBUG_OBJECT (pad, "no parent");
1219 GST_OBJECT_UNLOCK (pad);
1224 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1225 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1230 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1231 "failed to %s in switch to %s mode from %s mode",
1232 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1233 gst_pad_mode_get_name (old));
1238 GST_OBJECT_LOCK (peer);
1239 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1240 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1241 GST_OBJECT_UNLOCK (peer);
1242 gst_object_unref (peer);
1247 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1248 "pad in pull mode");
1253 GST_OBJECT_LOCK (pad);
1254 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1255 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1256 GST_PAD_SET_FLUSHING (pad);
1257 GST_PAD_MODE (pad) = old;
1258 GST_OBJECT_UNLOCK (pad);
1264 * gst_pad_is_active:
1265 * @pad: the #GstPad to query
1267 * Query if a pad is active
1269 * Returns: %TRUE if the pad is active.
1274 gst_pad_is_active (GstPad * pad)
1276 gboolean result = FALSE;
1278 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1280 GST_OBJECT_LOCK (pad);
1281 result = GST_PAD_IS_ACTIVE (pad);
1282 GST_OBJECT_UNLOCK (pad);
1288 cleanup_hook (GstPad * pad, GHook * hook)
1290 GstPadProbeType type;
1292 if (!G_HOOK_IS_VALID (hook))
1295 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1297 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1298 /* unblock when we remove the last blocking probe */
1300 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1303 /* Might have new probes now that want to be called */
1304 GST_PAD_BLOCK_BROADCAST (pad);
1306 if (pad->num_blocked == 0) {
1307 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1308 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1311 g_hook_destroy_link (&pad->probes, hook);
1316 * gst_pad_add_probe:
1317 * @pad: the #GstPad to add the probe to
1318 * @mask: the probe mask
1319 * @callback: #GstPadProbeCallback that will be called with notifications of
1321 * @user_data: (closure): user data passed to the callback
1322 * @destroy_data: #GDestroyNotify for user_data
1324 * Be notified of different states of pads. The provided callback is called for
1325 * every state that matches @mask.
1327 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1328 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1329 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1330 * immediately if the pad is already idle while calling gst_pad_add_probe().
1331 * In each of the groups, probes are called in the order in which they were
1334 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1335 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1336 * happen that the probe can be run immediately and if the probe returns
1337 * GST_PAD_PROBE_REMOVE this functions returns 0.
1342 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1343 GstPadProbeCallback callback, gpointer user_data,
1344 GDestroyNotify destroy_data)
1349 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1350 g_return_val_if_fail (mask != 0, 0);
1352 GST_OBJECT_LOCK (pad);
1354 /* make a new probe */
1355 hook = g_hook_alloc (&pad->probes);
1357 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1360 /* when no contraints are given for the types, assume all types are
1362 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1363 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1364 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1365 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1367 /* store our flags and other fields */
1368 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1369 hook->func = callback;
1370 hook->data = user_data;
1371 hook->destroy = destroy_data;
1372 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1375 g_hook_append (&pad->probes, hook);
1377 /* incremenent cookie so that the new hook get's called */
1378 pad->priv->probe_list_cookie++;
1380 /* get the id of the hook, we return this and it can be used to remove the
1382 res = hook->hook_id;
1384 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1386 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1387 /* we have a block probe */
1389 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1390 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1391 "now %d blocking probes", pad->num_blocked);
1393 /* Might have new probes now that want to be called */
1394 GST_PAD_BLOCK_BROADCAST (pad);
1397 /* call the callback if we need to be called for idle callbacks */
1398 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1399 if (pad->priv->using > 0) {
1400 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1401 * flag above, the last thread to leave the push will do the callback. New
1402 * threads going into the push will block. */
1403 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1404 "pad is in use, delay idle callback");
1405 GST_OBJECT_UNLOCK (pad);
1407 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1408 GstPadProbeReturn ret;
1410 /* Keep another ref, the callback could destroy the pad */
1411 gst_object_ref (pad);
1412 pad->priv->idle_running++;
1414 /* the pad is idle now, we can signal the idle callback now */
1415 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1416 "pad is idle, trigger idle callback");
1417 GST_OBJECT_UNLOCK (pad);
1419 ret = callback (pad, &info, user_data);
1421 GST_OBJECT_LOCK (pad);
1423 case GST_PAD_PROBE_REMOVE:
1424 /* remove the probe */
1425 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1426 cleanup_hook (pad, hook);
1429 case GST_PAD_PROBE_DROP:
1430 GST_DEBUG_OBJECT (pad, "asked to drop item");
1432 case GST_PAD_PROBE_PASS:
1433 GST_DEBUG_OBJECT (pad, "asked to pass item");
1435 case GST_PAD_PROBE_OK:
1436 GST_DEBUG_OBJECT (pad, "probe returned OK");
1438 case GST_PAD_PROBE_HANDLED:
1439 GST_DEBUG_OBJECT (pad, "probe handled the data");
1442 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1445 pad->priv->idle_running--;
1446 if (pad->priv->idle_running == 0) {
1447 GST_PAD_BLOCK_BROADCAST (pad);
1449 GST_OBJECT_UNLOCK (pad);
1451 gst_object_unref (pad);
1454 GST_OBJECT_UNLOCK (pad);
1460 * gst_pad_remove_probe:
1461 * @pad: the #GstPad with the probe
1462 * @id: the probe id to remove
1464 * Remove the probe with @id from @pad.
1469 gst_pad_remove_probe (GstPad * pad, gulong id)
1473 g_return_if_fail (GST_IS_PAD (pad));
1475 GST_OBJECT_LOCK (pad);
1477 hook = g_hook_get (&pad->probes, id);
1481 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1483 cleanup_hook (pad, hook);
1484 GST_OBJECT_UNLOCK (pad);
1490 GST_OBJECT_UNLOCK (pad);
1491 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1497 * gst_pad_is_blocked:
1498 * @pad: the #GstPad to query
1500 * Checks if the pad is blocked or not. This function returns the
1501 * last requested state of the pad. It is not certain that the pad
1502 * is actually blocking at this point (see gst_pad_is_blocking()).
1504 * Returns: %TRUE if the pad is blocked.
1509 gst_pad_is_blocked (GstPad * pad)
1511 gboolean result = FALSE;
1513 g_return_val_if_fail (GST_IS_PAD (pad), result);
1515 GST_OBJECT_LOCK (pad);
1516 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1517 GST_OBJECT_UNLOCK (pad);
1523 * gst_pad_is_blocking:
1524 * @pad: the #GstPad to query
1526 * Checks if the pad is blocking or not. This is a guaranteed state
1527 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1529 * Returns: %TRUE if the pad is blocking.
1534 gst_pad_is_blocking (GstPad * pad)
1536 gboolean result = FALSE;
1538 g_return_val_if_fail (GST_IS_PAD (pad), result);
1540 GST_OBJECT_LOCK (pad);
1541 /* the blocking flag is only valid if the pad is not flushing */
1542 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1543 GST_OBJECT_UNLOCK (pad);
1549 * gst_pad_needs_reconfigure:
1550 * @pad: the #GstPad to check
1552 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1553 * if the flag was set.
1555 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1558 gst_pad_needs_reconfigure (GstPad * pad)
1560 gboolean reconfigure;
1562 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1564 GST_OBJECT_LOCK (pad);
1565 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1566 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1567 GST_OBJECT_UNLOCK (pad);
1573 * gst_pad_check_reconfigure:
1574 * @pad: the #GstPad to check
1576 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1577 * if the flag was set.
1579 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1582 gst_pad_check_reconfigure (GstPad * pad)
1584 gboolean reconfigure;
1586 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1588 GST_OBJECT_LOCK (pad);
1589 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1591 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1592 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1594 GST_OBJECT_UNLOCK (pad);
1600 * gst_pad_mark_reconfigure:
1601 * @pad: the #GstPad to mark
1603 * Mark a pad for needing reconfiguration. The next call to
1604 * gst_pad_check_reconfigure() will return %TRUE after this call.
1607 gst_pad_mark_reconfigure (GstPad * pad)
1609 g_return_if_fail (GST_IS_PAD (pad));
1611 GST_OBJECT_LOCK (pad);
1612 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1613 GST_OBJECT_UNLOCK (pad);
1617 * gst_pad_set_activate_function:
1619 * @f: the #GstPadActivateFunction to set.
1621 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1625 * gst_pad_set_activate_function_full:
1627 * @activate: the #GstPadActivateFunction to set.
1628 * @user_data: user_data passed to @notify
1629 * @notify: notify called when @activate will not be used anymore.
1631 * Sets the given activate function for @pad. The activate function will
1632 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1633 * Only makes sense to set on sink pads.
1635 * Call this function if your sink pad can start a pull-based task.
1638 gst_pad_set_activate_function_full (GstPad * pad,
1639 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1641 g_return_if_fail (GST_IS_PAD (pad));
1643 if (pad->activatenotify)
1644 pad->activatenotify (pad->activatedata);
1645 GST_PAD_ACTIVATEFUNC (pad) = activate;
1646 pad->activatedata = user_data;
1647 pad->activatenotify = notify;
1649 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1650 GST_DEBUG_FUNCPTR_NAME (activate));
1654 * gst_pad_set_activatemode_function:
1656 * @f: the #GstPadActivateModeFunction to set.
1658 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1662 * gst_pad_set_activatemode_function_full:
1664 * @activatemode: the #GstPadActivateModeFunction to set.
1665 * @user_data: user_data passed to @notify
1666 * @notify: notify called when @activatemode will not be used anymore.
1668 * Sets the given activate_mode function for the pad. An activate_mode function
1669 * prepares the element for data passing.
1672 gst_pad_set_activatemode_function_full (GstPad * pad,
1673 GstPadActivateModeFunction activatemode, gpointer user_data,
1674 GDestroyNotify notify)
1676 g_return_if_fail (GST_IS_PAD (pad));
1678 if (pad->activatemodenotify)
1679 pad->activatemodenotify (pad->activatemodedata);
1680 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1681 pad->activatemodedata = user_data;
1682 pad->activatemodenotify = notify;
1684 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1685 GST_DEBUG_FUNCPTR_NAME (activatemode));
1689 * gst_pad_set_chain_function:
1690 * @p: a sink #GstPad.
1691 * @f: the #GstPadChainFunction to set.
1693 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1697 * gst_pad_set_chain_function_full:
1698 * @pad: a sink #GstPad.
1699 * @chain: the #GstPadChainFunction to set.
1700 * @user_data: user_data passed to @notify
1701 * @notify: notify called when @chain will not be used anymore.
1703 * Sets the given chain function for the pad. The chain function is called to
1704 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1707 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1708 gpointer user_data, GDestroyNotify notify)
1710 g_return_if_fail (GST_IS_PAD (pad));
1711 g_return_if_fail (GST_PAD_IS_SINK (pad));
1713 if (pad->chainnotify)
1714 pad->chainnotify (pad->chaindata);
1715 GST_PAD_CHAINFUNC (pad) = chain;
1716 pad->chaindata = user_data;
1717 pad->chainnotify = notify;
1719 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1720 GST_DEBUG_FUNCPTR_NAME (chain));
1724 * gst_pad_set_chain_list_function:
1725 * @p: a sink #GstPad.
1726 * @f: the #GstPadChainListFunction to set.
1728 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1732 * gst_pad_set_chain_list_function_full:
1733 * @pad: a sink #GstPad.
1734 * @chainlist: the #GstPadChainListFunction to set.
1735 * @user_data: user_data passed to @notify
1736 * @notify: notify called when @chainlist will not be used anymore.
1738 * Sets the given chain list function for the pad. The chainlist function is
1739 * called to process a #GstBufferList input buffer list. See
1740 * #GstPadChainListFunction for more details.
1743 gst_pad_set_chain_list_function_full (GstPad * pad,
1744 GstPadChainListFunction chainlist, gpointer user_data,
1745 GDestroyNotify notify)
1747 g_return_if_fail (GST_IS_PAD (pad));
1748 g_return_if_fail (GST_PAD_IS_SINK (pad));
1750 if (pad->chainlistnotify)
1751 pad->chainlistnotify (pad->chainlistdata);
1752 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1753 pad->chainlistdata = user_data;
1754 pad->chainlistnotify = notify;
1756 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1757 GST_DEBUG_FUNCPTR_NAME (chainlist));
1761 * gst_pad_set_getrange_function:
1762 * @p: a source #GstPad.
1763 * @f: the #GstPadGetRangeFunction to set.
1765 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1769 * gst_pad_set_getrange_function_full:
1770 * @pad: a source #GstPad.
1771 * @get: the #GstPadGetRangeFunction to set.
1772 * @user_data: user_data passed to @notify
1773 * @notify: notify called when @get will not be used anymore.
1775 * Sets the given getrange function for the pad. The getrange function is
1776 * called to produce a new #GstBuffer to start the processing pipeline. see
1777 * #GstPadGetRangeFunction for a description of the getrange function.
1780 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1781 gpointer user_data, GDestroyNotify notify)
1783 g_return_if_fail (GST_IS_PAD (pad));
1784 g_return_if_fail (GST_PAD_IS_SRC (pad));
1786 if (pad->getrangenotify)
1787 pad->getrangenotify (pad->getrangedata);
1788 GST_PAD_GETRANGEFUNC (pad) = get;
1789 pad->getrangedata = user_data;
1790 pad->getrangenotify = notify;
1792 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1793 GST_DEBUG_FUNCPTR_NAME (get));
1797 * gst_pad_set_event_function:
1798 * @p: a #GstPad of either direction.
1799 * @f: the #GstPadEventFunction to set.
1801 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1805 * gst_pad_set_event_function_full:
1806 * @pad: a #GstPad of either direction.
1807 * @event: the #GstPadEventFunction to set.
1808 * @user_data: user_data passed to @notify
1809 * @notify: notify called when @event will not be used anymore.
1811 * Sets the given event handler for the pad.
1814 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1815 gpointer user_data, GDestroyNotify notify)
1817 g_return_if_fail (GST_IS_PAD (pad));
1819 if (pad->eventnotify)
1820 pad->eventnotify (pad->eventdata);
1821 GST_PAD_EVENTFUNC (pad) = event;
1822 pad->eventdata = user_data;
1823 pad->eventnotify = notify;
1825 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1826 GST_DEBUG_FUNCPTR_NAME (event));
1830 * gst_pad_set_query_function:
1831 * @p: a #GstPad of either direction.
1832 * @f: the #GstPadQueryFunction to set.
1834 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1838 * gst_pad_set_query_function_full:
1839 * @pad: a #GstPad of either direction.
1840 * @query: the #GstPadQueryFunction to set.
1841 * @user_data: user_data passed to @notify
1842 * @notify: notify called when @query will not be used anymore.
1844 * Set the given query function for the pad.
1847 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1848 gpointer user_data, GDestroyNotify notify)
1850 g_return_if_fail (GST_IS_PAD (pad));
1852 if (pad->querynotify)
1853 pad->querynotify (pad->querydata);
1854 GST_PAD_QUERYFUNC (pad) = query;
1855 pad->querydata = user_data;
1856 pad->querynotify = notify;
1858 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1859 GST_DEBUG_FUNCPTR_NAME (query));
1863 * gst_pad_set_iterate_internal_links_function:
1864 * @p: a #GstPad of either direction.
1865 * @f: the #GstPadIterIntLinkFunction to set.
1867 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1868 * for the user_data and notify.
1871 * gst_pad_set_iterate_internal_links_function_full:
1872 * @pad: a #GstPad of either direction.
1873 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1874 * @user_data: user_data passed to @notify
1875 * @notify: notify called when @iterintlink will not be used anymore.
1877 * Sets the given internal link iterator function for the pad.
1880 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1881 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1882 GDestroyNotify notify)
1884 g_return_if_fail (GST_IS_PAD (pad));
1886 if (pad->iterintlinknotify)
1887 pad->iterintlinknotify (pad->iterintlinkdata);
1888 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1889 pad->iterintlinkdata = user_data;
1890 pad->iterintlinknotify = notify;
1892 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1893 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1897 * gst_pad_set_link_function:
1899 * @f: the #GstPadLinkFunction to set.
1901 * Calls gst_pad_set_link_function_full() with %NULL
1902 * for the user_data and notify.
1905 * gst_pad_set_link_function_full:
1907 * @link: the #GstPadLinkFunction to set.
1908 * @user_data: user_data passed to @notify
1909 * @notify: notify called when @link will not be used anymore.
1911 * Sets the given link function for the pad. It will be called when
1912 * the pad is linked with another pad.
1914 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1917 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1918 * cannot be made for some reason.
1920 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1921 * of the peer sink pad, if present.
1924 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1925 gpointer user_data, GDestroyNotify notify)
1927 g_return_if_fail (GST_IS_PAD (pad));
1929 if (pad->linknotify)
1930 pad->linknotify (pad->linkdata);
1931 GST_PAD_LINKFUNC (pad) = link;
1932 pad->linkdata = user_data;
1933 pad->linknotify = notify;
1935 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1936 GST_DEBUG_FUNCPTR_NAME (link));
1940 * gst_pad_set_unlink_function:
1942 * @f: the #GstPadUnlinkFunction to set.
1944 * Calls gst_pad_set_unlink_function_full() with %NULL
1945 * for the user_data and notify.
1948 * gst_pad_set_unlink_function_full:
1950 * @unlink: the #GstPadUnlinkFunction to set.
1951 * @user_data: user_data passed to @notify
1952 * @notify: notify called when @unlink will not be used anymore.
1954 * Sets the given unlink function for the pad. It will be called
1955 * when the pad is unlinked.
1958 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1959 gpointer user_data, GDestroyNotify notify)
1961 g_return_if_fail (GST_IS_PAD (pad));
1963 if (pad->unlinknotify)
1964 pad->unlinknotify (pad->unlinkdata);
1965 GST_PAD_UNLINKFUNC (pad) = unlink;
1966 pad->unlinkdata = user_data;
1967 pad->unlinknotify = notify;
1969 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1970 GST_DEBUG_FUNCPTR_NAME (unlink));
1975 * @srcpad: the source #GstPad to unlink.
1976 * @sinkpad: the sink #GstPad to unlink.
1978 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1979 * signal on both pads.
1981 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
1982 * the pads were not linked together.
1987 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1989 gboolean result = FALSE;
1990 GstElement *parent = NULL;
1992 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1993 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1994 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1995 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1997 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
1999 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2000 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2001 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2003 /* We need to notify the parent before taking any pad locks as the bin in
2004 * question might be waiting for a lock on the pad while holding its lock
2005 * that our message will try to take. */
2006 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2007 if (GST_IS_ELEMENT (parent)) {
2008 gst_element_post_message (parent,
2009 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2010 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2012 gst_object_unref (parent);
2017 GST_OBJECT_LOCK (srcpad);
2018 GST_OBJECT_LOCK (sinkpad);
2020 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2021 goto not_linked_together;
2023 if (GST_PAD_UNLINKFUNC (srcpad)) {
2024 GstObject *tmpparent;
2026 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2028 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2029 RELEASE_PARENT (tmpparent);
2032 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2033 GstObject *tmpparent;
2035 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2037 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2038 RELEASE_PARENT (tmpparent);
2042 /* first clear peers */
2043 GST_PAD_PEER (srcpad) = NULL;
2044 GST_PAD_PEER (sinkpad) = NULL;
2046 GST_OBJECT_UNLOCK (sinkpad);
2047 GST_OBJECT_UNLOCK (srcpad);
2049 /* fire off a signal to each of the pads telling them
2050 * that they've been unlinked */
2051 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2052 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2054 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2055 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2060 if (parent != NULL) {
2061 gst_element_post_message (parent,
2062 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2063 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2064 gst_object_unref (parent);
2066 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2070 not_linked_together:
2072 /* we do not emit a warning in this case because unlinking cannot
2073 * be made MT safe.*/
2074 GST_OBJECT_UNLOCK (sinkpad);
2075 GST_OBJECT_UNLOCK (srcpad);
2081 * gst_pad_is_linked:
2082 * @pad: pad to check
2084 * Checks if a @pad is linked to another pad or not.
2086 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2091 gst_pad_is_linked (GstPad * pad)
2095 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2097 GST_OBJECT_LOCK (pad);
2098 result = (GST_PAD_PEER (pad) != NULL);
2099 GST_OBJECT_UNLOCK (pad);
2104 /* get the caps from both pads and see if the intersection
2107 * This function should be called with the pad LOCK on both
2111 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2112 GstPadLinkCheck flags)
2114 GstCaps *srccaps = NULL;
2115 GstCaps *sinkcaps = NULL;
2116 gboolean compatible = FALSE;
2118 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2121 /* Doing the expensive caps checking takes priority over only checking the template caps */
2122 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2123 GST_OBJECT_UNLOCK (sink);
2124 GST_OBJECT_UNLOCK (src);
2126 srccaps = gst_pad_query_caps (src, NULL);
2127 sinkcaps = gst_pad_query_caps (sink, NULL);
2129 GST_OBJECT_LOCK (src);
2130 GST_OBJECT_LOCK (sink);
2132 /* If one of the two pads doesn't have a template, consider the intersection
2134 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2135 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2139 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2141 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2144 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2146 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2149 /* if we have caps on both pads we can check the intersection. If one
2150 * of the caps is %NULL, we return %TRUE. */
2151 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2153 gst_caps_unref (srccaps);
2155 gst_caps_unref (sinkcaps);
2159 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2160 gst_caps_unref (srccaps);
2161 gst_caps_unref (sinkcaps);
2164 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2165 (compatible ? "" : "not "));
2170 /* check if the grandparents of both pads are the same.
2171 * This check is required so that we don't try to link
2172 * pads from elements in different bins without ghostpads.
2174 * The LOCK should be held on both pads
2177 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2179 GstObject *psrc, *psink;
2181 psrc = GST_OBJECT_PARENT (src);
2182 psink = GST_OBJECT_PARENT (sink);
2184 /* if one of the pads has no parent, we allow the link */
2185 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2188 /* only care about parents that are elements */
2189 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2190 goto no_element_parent;
2192 /* if the parents are the same, we have a loop */
2193 if (G_UNLIKELY (psrc == psink))
2196 /* if they both have a parent, we check the grandparents. We can not lock
2197 * the parent because we hold on the child (pad) and the locking order is
2198 * parent >> child. */
2199 psrc = GST_OBJECT_PARENT (psrc);
2200 psink = GST_OBJECT_PARENT (psink);
2202 /* if they have grandparents but they are not the same */
2203 if (G_UNLIKELY (psrc != psink))
2204 goto wrong_grandparents;
2211 GST_CAT_DEBUG (GST_CAT_CAPS,
2212 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2213 GST_PTR_FORMAT, psrc, psink);
2218 GST_CAT_DEBUG (GST_CAT_CAPS,
2219 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2220 GST_PTR_FORMAT, psrc, psink);
2225 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2231 GST_CAT_DEBUG (GST_CAT_CAPS,
2232 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2233 GST_PTR_FORMAT, psrc, psink);
2238 /* FIXME leftover from an attempt at refactoring... */
2239 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2240 * the two pads will be locked in the srcpad, sinkpad order. */
2241 static GstPadLinkReturn
2242 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2244 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2245 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2247 GST_OBJECT_LOCK (srcpad);
2249 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2250 goto src_was_linked;
2252 GST_OBJECT_LOCK (sinkpad);
2254 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2255 goto sink_was_linked;
2257 /* check hierarchy, pads can only be linked if the grandparents
2259 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2260 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2261 goto wrong_hierarchy;
2263 /* check pad caps for non-empty intersection */
2264 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2267 /* FIXME check pad scheduling for non-empty intersection */
2269 return GST_PAD_LINK_OK;
2273 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2274 GST_DEBUG_PAD_NAME (srcpad),
2275 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2276 /* we do not emit a warning in this case because unlinking cannot
2277 * be made MT safe.*/
2278 GST_OBJECT_UNLOCK (srcpad);
2279 return GST_PAD_LINK_WAS_LINKED;
2283 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2284 GST_DEBUG_PAD_NAME (sinkpad),
2285 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2286 /* we do not emit a warning in this case because unlinking cannot
2287 * be made MT safe.*/
2288 GST_OBJECT_UNLOCK (sinkpad);
2289 GST_OBJECT_UNLOCK (srcpad);
2290 return GST_PAD_LINK_WAS_LINKED;
2294 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2295 GST_OBJECT_UNLOCK (sinkpad);
2296 GST_OBJECT_UNLOCK (srcpad);
2297 return GST_PAD_LINK_WRONG_HIERARCHY;
2301 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2302 GST_OBJECT_UNLOCK (sinkpad);
2303 GST_OBJECT_UNLOCK (srcpad);
2304 return GST_PAD_LINK_NOFORMAT;
2310 * @srcpad: the source #GstPad.
2311 * @sinkpad: the sink #GstPad.
2313 * Checks if the source pad and the sink pad are compatible so they can be
2316 * Returns: %TRUE if the pads can be linked.
2319 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2321 GstPadLinkReturn result;
2323 /* generic checks */
2324 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2325 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2327 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2328 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2330 /* gst_pad_link_prepare does everything for us, we only release the locks
2331 * on the pads that it gets us. If this function returns !OK the locks are not
2333 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2334 if (result != GST_PAD_LINK_OK)
2337 GST_OBJECT_UNLOCK (srcpad);
2338 GST_OBJECT_UNLOCK (sinkpad);
2341 return result == GST_PAD_LINK_OK;
2345 * gst_pad_link_full:
2346 * @srcpad: the source #GstPad to link.
2347 * @sinkpad: the sink #GstPad to link.
2348 * @flags: the checks to validate when linking
2350 * Links the source pad and the sink pad.
2352 * This variant of #gst_pad_link provides a more granular control on the
2353 * checks being done when linking. While providing some considerable speedups
2354 * the caller of this method must be aware that wrong usage of those flags
2355 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2356 * for more information.
2360 * Returns: A result code indicating if the connection worked or
2364 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2366 GstPadLinkReturn result;
2368 GstPadLinkFunction srcfunc, sinkfunc;
2370 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2371 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2372 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2373 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2374 GST_PAD_LINK_WRONG_DIRECTION);
2376 /* Notify the parent early. See gst_pad_unlink for details. */
2377 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2378 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2379 gst_element_post_message (parent,
2380 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2381 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2383 gst_object_unref (parent);
2388 /* prepare will also lock the two pads */
2389 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2391 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2392 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2393 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2394 gst_pad_link_get_name (result));
2398 /* must set peers before calling the link function */
2399 GST_PAD_PEER (srcpad) = sinkpad;
2400 GST_PAD_PEER (sinkpad) = srcpad;
2402 /* check events, when something is different, mark pending */
2403 schedule_events (srcpad, sinkpad);
2405 /* get the link functions */
2406 srcfunc = GST_PAD_LINKFUNC (srcpad);
2407 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2409 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2410 /* custom link functions, execute them */
2411 GST_OBJECT_UNLOCK (sinkpad);
2412 GST_OBJECT_UNLOCK (srcpad);
2415 GstObject *tmpparent;
2417 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2418 /* this one will call the peer link function */
2419 result = srcfunc (srcpad, tmpparent, sinkpad);
2420 RELEASE_PARENT (tmpparent);
2421 } else if (sinkfunc) {
2422 GstObject *tmpparent;
2424 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2425 /* if no source link function, we need to call the sink link
2426 * function ourselves. */
2427 result = sinkfunc (sinkpad, tmpparent, srcpad);
2428 RELEASE_PARENT (tmpparent);
2432 GST_OBJECT_LOCK (srcpad);
2433 GST_OBJECT_LOCK (sinkpad);
2435 /* we released the lock, check if the same pads are linked still */
2436 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2437 goto concurrent_link;
2439 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2442 GST_OBJECT_UNLOCK (sinkpad);
2443 GST_OBJECT_UNLOCK (srcpad);
2445 /* fire off a signal to each of the pads telling them
2446 * that they've been linked */
2447 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2448 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2450 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2451 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2453 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2456 if (G_LIKELY (parent)) {
2457 gst_element_post_message (parent,
2458 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2459 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2460 gst_object_unref (parent);
2468 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2469 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2470 GST_OBJECT_UNLOCK (sinkpad);
2471 GST_OBJECT_UNLOCK (srcpad);
2473 /* The other link operation succeeded first */
2474 result = GST_PAD_LINK_WAS_LINKED;
2479 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2480 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2481 gst_pad_link_get_name (result));
2483 GST_PAD_PEER (srcpad) = NULL;
2484 GST_PAD_PEER (sinkpad) = NULL;
2486 GST_OBJECT_UNLOCK (sinkpad);
2487 GST_OBJECT_UNLOCK (srcpad);
2495 * @srcpad: the source #GstPad to link.
2496 * @sinkpad: the sink #GstPad to link.
2498 * Links the source pad and the sink pad.
2500 * Returns: A result code indicating if the connection worked or
2506 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2508 GstPadLinkReturn ret;
2510 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2511 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2512 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, ret);
2518 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2520 GstPadTemplate **template_p;
2522 /* this function would need checks if it weren't static */
2524 GST_OBJECT_LOCK (pad);
2525 template_p = &pad->padtemplate;
2526 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2527 GST_OBJECT_UNLOCK (pad);
2530 gst_pad_template_pad_created (templ, pad);
2534 * gst_pad_get_pad_template:
2537 * Gets the template for @pad.
2539 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2540 * this pad was instantiated, or %NULL if this pad has no
2541 * template. Unref after usage.
2544 gst_pad_get_pad_template (GstPad * pad)
2546 GstPadTemplate *templ;
2548 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2550 templ = GST_PAD_PAD_TEMPLATE (pad);
2552 return (templ ? gst_object_ref (templ) : NULL);
2556 * gst_pad_has_current_caps:
2557 * @pad: a #GstPad to check
2559 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2561 * Returns: %TRUE when @pad has caps associated with it.
2564 gst_pad_has_current_caps (GstPad * pad)
2569 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2571 GST_OBJECT_LOCK (pad);
2572 caps = get_pad_caps (pad);
2573 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2574 "check current pad caps %" GST_PTR_FORMAT, caps);
2575 result = (caps != NULL);
2576 GST_OBJECT_UNLOCK (pad);
2582 * gst_pad_get_current_caps:
2583 * @pad: a #GstPad to get the current capabilities of.
2585 * Gets the capabilities currently configured on @pad with the last
2586 * #GST_EVENT_CAPS event.
2588 * Returns: the current caps of the pad with incremented ref-count.
2591 gst_pad_get_current_caps (GstPad * pad)
2595 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2597 GST_OBJECT_LOCK (pad);
2598 if ((result = get_pad_caps (pad)))
2599 gst_caps_ref (result);
2600 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2601 "get current pad caps %" GST_PTR_FORMAT, result);
2602 GST_OBJECT_UNLOCK (pad);
2608 * gst_pad_get_pad_template_caps:
2609 * @pad: a #GstPad to get the template capabilities from.
2611 * Gets the capabilities for @pad's template.
2613 * Returns: (transfer full): the #GstCaps of this pad template.
2614 * Unref after usage.
2617 gst_pad_get_pad_template_caps (GstPad * pad)
2619 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2621 if (GST_PAD_PAD_TEMPLATE (pad))
2622 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2624 return gst_caps_ref (GST_CAPS_ANY);
2629 * @pad: a #GstPad to get the peer of.
2631 * Gets the peer of @pad. This function refs the peer pad so
2632 * you need to unref it after use.
2634 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2639 gst_pad_get_peer (GstPad * pad)
2643 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2645 GST_OBJECT_LOCK (pad);
2646 result = GST_PAD_PEER (pad);
2648 gst_object_ref (result);
2649 GST_OBJECT_UNLOCK (pad);
2655 * gst_pad_get_allowed_caps:
2658 * Gets the capabilities of the allowed media types that can flow through
2659 * @pad and its peer.
2661 * The allowed capabilities is calculated as the intersection of the results of
2662 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2663 * on the resulting caps.
2665 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2666 * pad link. Unref the caps when you no longer need it. This
2667 * function returns %NULL when @pad has no peer.
2672 gst_pad_get_allowed_caps (GstPad * pad)
2675 GstCaps *caps = NULL;
2678 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2680 GST_OBJECT_LOCK (pad);
2681 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2683 GST_OBJECT_UNLOCK (pad);
2685 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2687 mycaps = gst_pad_query_caps (pad, NULL);
2689 /* Query peer caps */
2690 query = gst_query_new_caps (mycaps);
2691 gst_pad_peer_query (pad, query);
2692 gst_query_parse_caps_result (query, &caps);
2693 gst_caps_ref (caps);
2694 gst_query_unref (query);
2696 gst_caps_unref (mycaps);
2698 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2705 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2706 GST_OBJECT_UNLOCK (pad);
2713 * gst_pad_iterate_internal_links_default:
2714 * @pad: the #GstPad to get the internal links of.
2715 * @parent: (allow-none): the parent of @pad or %NULL
2717 * Iterate the list of pads to which the given pad is linked to inside of
2718 * the parent element.
2719 * This is the default handler, and thus returns an iterator of all of the
2720 * pads inside the parent element with opposite direction.
2722 * The caller must free this iterator after use with gst_iterator_free().
2724 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2725 * has no parent. Unref each returned pad with gst_object_unref().
2728 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2735 GstElement *eparent;
2737 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2739 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2740 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2742 GST_OBJECT_LOCK (pad);
2743 eparent = GST_PAD_PARENT (pad);
2744 if (!eparent || !GST_IS_ELEMENT (eparent))
2747 gst_object_ref (eparent);
2748 GST_OBJECT_UNLOCK (pad);
2751 if (pad->direction == GST_PAD_SRC)
2752 padlist = &eparent->sinkpads;
2754 padlist = &eparent->srcpads;
2756 GST_DEBUG_OBJECT (pad, "Making iterator");
2758 cookie = &eparent->pads_cookie;
2760 lock = GST_OBJECT_GET_LOCK (eparent);
2762 res = gst_iterator_new_list (GST_TYPE_PAD,
2763 lock, cookie, padlist, (GObject *) owner, NULL);
2765 gst_object_unref (owner);
2772 GST_OBJECT_UNLOCK (pad);
2773 GST_DEBUG_OBJECT (pad, "no parent element");
2779 * gst_pad_iterate_internal_links:
2780 * @pad: the GstPad to get the internal links of.
2782 * Gets an iterator for the pads to which the given pad is linked to inside
2783 * of the parent element.
2785 * Each #GstPad element yielded by the iterator will have its refcount increased,
2786 * so unref after use.
2788 * Free-function: gst_iterator_free
2790 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2791 * or %NULL when the pad does not have an iterator function
2792 * configured. Use gst_iterator_free() after usage.
2795 gst_pad_iterate_internal_links (GstPad * pad)
2797 GstIterator *res = NULL;
2800 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2802 GST_OBJECT_LOCK (pad);
2803 ACQUIRE_PARENT (pad, parent, no_parent);
2804 GST_OBJECT_UNLOCK (pad);
2806 if (GST_PAD_ITERINTLINKFUNC (pad))
2807 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2809 RELEASE_PARENT (parent);
2816 GST_DEBUG_OBJECT (pad, "no parent");
2817 GST_OBJECT_UNLOCK (pad);
2825 * @forward: (scope call): a #GstPadForwardFunction
2826 * @user_data: user data passed to @forward
2828 * Calls @forward for all internally linked pads of @pad. This function deals with
2829 * dynamically changing internal pads and will make sure that the @forward
2830 * function is only called once for each pad.
2832 * When @forward returns %TRUE, no further pads will be processed.
2834 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2837 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2840 gboolean result = FALSE;
2842 gboolean done = FALSE;
2843 GValue item = { 0, };
2844 GList *pushed_pads = NULL;
2846 iter = gst_pad_iterate_internal_links (pad);
2852 switch (gst_iterator_next (iter, &item)) {
2853 case GST_ITERATOR_OK:
2857 intpad = g_value_get_object (&item);
2859 /* if already pushed, skip. FIXME, find something faster to tag pads */
2860 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2861 g_value_reset (&item);
2865 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2866 GST_DEBUG_PAD_NAME (intpad));
2867 done = result = forward (intpad, user_data);
2869 pushed_pads = g_list_prepend (pushed_pads, intpad);
2871 g_value_reset (&item);
2874 case GST_ITERATOR_RESYNC:
2875 /* We don't reset the result here because we don't push the event
2876 * again on pads that got the event already and because we need
2877 * to consider the result of the previous pushes */
2878 gst_iterator_resync (iter);
2880 case GST_ITERATOR_ERROR:
2881 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2884 case GST_ITERATOR_DONE:
2889 g_value_unset (&item);
2890 gst_iterator_free (iter);
2892 g_list_free (pushed_pads);
2902 gboolean dispatched;
2906 event_forward_func (GstPad * pad, EventData * data)
2908 /* for each pad we send to, we should ref the event; it's up
2909 * to downstream to unref again when handled. */
2910 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2911 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2913 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2915 data->dispatched = TRUE;
2922 * gst_pad_event_default:
2923 * @pad: a #GstPad to call the default event handler on.
2924 * @parent: (allow-none): the parent of @pad or %NULL
2925 * @event: (transfer full): the #GstEvent to handle.
2927 * Invokes the default event handler for the given pad.
2929 * The EOS event will pause the task associated with @pad before it is forwarded
2930 * to all internally linked pads,
2932 * The event is sent to all pads internally linked to @pad. This function
2933 * takes ownership of @event.
2935 * Returns: %TRUE if the event was sent successfully.
2938 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2940 gboolean result, forward = TRUE;
2942 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2943 g_return_val_if_fail (event != NULL, FALSE);
2945 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2948 switch (GST_EVENT_TYPE (event)) {
2949 case GST_EVENT_CAPS:
2950 forward = GST_PAD_IS_PROXY_CAPS (pad);
2961 data.dispatched = FALSE;
2962 data.result = FALSE;
2964 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2966 /* for sinkpads without a parent element or without internal links, nothing
2967 * will be dispatched but we still want to return TRUE. */
2968 if (data.dispatched)
2969 result = data.result;
2974 gst_event_unref (event);
2979 /* Default accept caps implementation just checks against
2980 * the allowed caps for the pad */
2982 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2984 /* get the caps and see if it intersects to something not empty */
2985 GstCaps *caps, *allowed;
2988 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2990 /* first forward the query to internally linked pads when we are dealing with
2992 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2993 result = gst_pad_proxy_query_accept_caps (pad, query);
2997 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2998 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3000 gst_query_parse_accept_caps (query, &caps);
3001 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad))
3002 allowed = gst_pad_get_pad_template_caps (pad);
3004 allowed = gst_pad_query_caps (pad, caps);
3007 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3008 GST_DEBUG_OBJECT (pad,
3009 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3011 result = gst_caps_can_intersect (caps, allowed);
3013 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3014 GST_PTR_FORMAT, allowed, caps);
3015 result = gst_caps_is_subset (caps, allowed);
3017 gst_caps_unref (allowed);
3019 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3022 gst_query_set_accept_caps_result (query, result);
3028 /* Default caps implementation */
3030 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3032 GstCaps *result = NULL, *filter;
3033 GstPadTemplate *templ;
3034 gboolean fixed_caps;
3036 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3039 /* first try to proxy if we must */
3040 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3041 if ((gst_pad_proxy_query_caps (pad, query))) {
3046 gst_query_parse_caps (query, &filter);
3048 /* no proxy or it failed, do default handling */
3049 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3051 GST_OBJECT_LOCK (pad);
3053 /* fixed caps, try the negotiated caps first */
3054 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3055 if ((result = get_pad_caps (pad)))
3056 goto filter_done_unlock;
3059 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3060 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3061 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3062 goto filter_done_unlock;
3066 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3067 "non-fixed pad caps: trying pad caps");
3068 /* non fixed caps, try the negotiated caps */
3069 if ((result = get_pad_caps (pad)))
3070 goto filter_done_unlock;
3073 /* this almost never happens */
3074 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3075 result = GST_CAPS_ANY;
3078 GST_OBJECT_UNLOCK (pad);
3080 /* run the filter on the result */
3082 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3083 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3084 GST_PTR_FORMAT, result, result, filter, filter);
3085 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3086 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3089 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3090 "using caps %p %" GST_PTR_FORMAT, result, result);
3091 result = gst_caps_ref (result);
3093 gst_query_set_caps_result (query, result);
3094 gst_caps_unref (result);
3100 /* Default latency implementation */
3104 GstClockTime min, max;
3108 query_latency_default_fold (const GValue * item, GValue * ret,
3111 GstPad *pad = g_value_get_object (item), *peer;
3112 LatencyFoldData *fold_data = user_data;
3114 gboolean res = FALSE;
3116 query = gst_query_new_latency ();
3118 peer = gst_pad_get_peer (pad);
3120 res = gst_pad_peer_query (pad, query);
3122 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3127 GstClockTime min, max;
3129 gst_query_parse_latency (query, &live, &min, &max);
3131 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3132 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3135 if (min > fold_data->min)
3136 fold_data->min = min;
3138 if (fold_data->max == GST_CLOCK_TIME_NONE)
3139 fold_data->max = max;
3140 else if (max < fold_data->max)
3141 fold_data->max = max;
3143 fold_data->live = TRUE;
3146 GST_DEBUG_OBJECT (pad, "latency query failed");
3147 g_value_set_boolean (ret, FALSE);
3150 gst_query_unref (query);
3152 gst_object_unref (peer);
3158 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3161 GstIteratorResult res;
3162 GValue ret = G_VALUE_INIT;
3164 LatencyFoldData fold_data;
3166 it = gst_pad_iterate_internal_links (pad);
3168 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3172 g_value_init (&ret, G_TYPE_BOOLEAN);
3175 fold_data.live = FALSE;
3177 fold_data.max = GST_CLOCK_TIME_NONE;
3179 g_value_set_boolean (&ret, TRUE);
3180 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3182 case GST_ITERATOR_OK:
3183 g_assert_not_reached ();
3185 case GST_ITERATOR_DONE:
3187 case GST_ITERATOR_ERROR:
3188 g_value_set_boolean (&ret, FALSE);
3190 case GST_ITERATOR_RESYNC:
3191 gst_iterator_resync (it);
3194 g_assert_not_reached ();
3197 gst_iterator_free (it);
3199 query_ret = g_value_get_boolean (&ret);
3201 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3202 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3203 fold_data.min, fold_data.max);
3205 if (fold_data.min > fold_data.max) {
3206 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3209 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3211 GST_LOG_OBJECT (pad, "latency query failed");
3221 gboolean dispatched;
3225 query_forward_func (GstPad * pad, QueryData * data)
3227 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3228 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3230 data->result |= gst_pad_peer_query (pad, data->query);
3232 data->dispatched = TRUE;
3234 /* stop on first successful reply */
3235 return data->result;
3239 * gst_pad_query_default:
3240 * @pad: a #GstPad to call the default query handler on.
3241 * @parent: (allow-none): the parent of @pad or %NULL
3242 * @query: (transfer none): the #GstQuery to handle.
3244 * Invokes the default query handler for the given pad.
3245 * The query is sent to all pads internally linked to @pad. Note that
3246 * if there are many possible sink pads that are internally linked to
3247 * @pad, only one will be sent the query.
3248 * Multi-sinkpad elements should implement custom query handlers.
3250 * Returns: %TRUE if the query was performed successfully.
3253 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3255 gboolean forward, ret = FALSE;
3257 switch (GST_QUERY_TYPE (query)) {
3258 case GST_QUERY_SCHEDULING:
3259 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3261 case GST_QUERY_ALLOCATION:
3262 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3264 case GST_QUERY_ACCEPT_CAPS:
3265 ret = gst_pad_query_accept_caps_default (pad, query);
3268 case GST_QUERY_CAPS:
3269 ret = gst_pad_query_caps_default (pad, query);
3272 case GST_QUERY_LATENCY:
3273 ret = gst_pad_query_latency_default (pad, query);
3276 case GST_QUERY_POSITION:
3277 case GST_QUERY_SEEKING:
3278 case GST_QUERY_FORMATS:
3279 case GST_QUERY_JITTER:
3280 case GST_QUERY_RATE:
3281 case GST_QUERY_CONVERT:
3287 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3288 query, GST_QUERY_TYPE_NAME (query));
3294 data.dispatched = FALSE;
3295 data.result = FALSE;
3297 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3299 if (data.dispatched) {
3302 /* nothing dispatched, assume drained */
3303 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3313 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3315 GstPad *pad = data->pad;
3316 GstPadProbeInfo *info = data->info;
3317 GstPadProbeType type, flags;
3318 GstPadProbeCallback callback;
3319 GstPadProbeReturn ret;
3320 gpointer original_data;
3322 /* if we have called this callback, do nothing */
3323 if (PROBE_COOKIE (hook) == data->cookie) {
3324 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3325 "hook %lu, cookie %u already called", hook->hook_id,
3326 PROBE_COOKIE (hook));
3330 PROBE_COOKIE (hook) = data->cookie;
3332 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3334 original_data = info->data;
3336 /* one of the data types for non-idle probes */
3337 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3338 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3340 /* one of the scheduling types */
3341 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3343 /* one of the blocking types must match */
3344 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3345 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3347 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3348 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3350 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3351 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3352 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3355 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3356 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3357 PROBE_COOKIE (hook), flags);
3359 data->marshalled = TRUE;
3361 callback = (GstPadProbeCallback) hook->func;
3362 if (callback == NULL)
3365 info->id = hook->hook_id;
3367 GST_OBJECT_UNLOCK (pad);
3369 ret = callback (pad, info, hook->data);
3371 GST_OBJECT_LOCK (pad);
3373 if (original_data != NULL && info->data == NULL) {
3374 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3375 info->type = GST_PAD_PROBE_TYPE_INVALID;
3376 data->dropped = TRUE;
3380 case GST_PAD_PROBE_REMOVE:
3381 /* remove the probe */
3382 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3383 cleanup_hook (pad, hook);
3385 case GST_PAD_PROBE_DROP:
3386 /* need to drop the data, make sure other probes don't get called
3388 GST_DEBUG_OBJECT (pad, "asked to drop item");
3389 info->type = GST_PAD_PROBE_TYPE_INVALID;
3390 data->dropped = TRUE;
3392 case GST_PAD_PROBE_HANDLED:
3393 GST_DEBUG_OBJECT (pad, "probe handled data");
3394 data->handled = TRUE;
3396 case GST_PAD_PROBE_PASS:
3397 /* inform the pad block to let things pass */
3398 GST_DEBUG_OBJECT (pad, "asked to pass item");
3401 case GST_PAD_PROBE_OK:
3402 GST_DEBUG_OBJECT (pad, "probe returned OK");
3405 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3412 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3413 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3414 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3419 /* a probe that does not take or return any data */
3420 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3422 if (G_UNLIKELY (pad->num_probes)) { \
3423 GstFlowReturn pval = defaultval; \
3424 /* pass NULL as the data item */ \
3425 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3426 info.ABI.abi.flow_ret = defaultval; \
3427 ret = do_probe_callbacks (pad, &info, defaultval); \
3428 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3433 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3435 if (G_UNLIKELY (pad->num_probes)) { \
3436 /* pass the data item */ \
3437 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3438 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3439 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3440 /* store the possibly updated data item */ \
3441 data = GST_PAD_PROBE_INFO_DATA (&info); \
3442 /* if something went wrong, exit */ \
3443 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3444 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3445 ret = info.ABI.abi.flow_ret; \
3446 goto handle_label; \
3453 #define PROBE_PUSH(pad,mask,data,label) \
3454 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3455 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3456 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3457 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3458 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3460 static GstFlowReturn
3461 do_pad_idle_probe_wait (GstPad * pad)
3463 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3464 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3465 "waiting idle probe to be removed");
3466 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3467 GST_PAD_BLOCK_WAIT (pad);
3468 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3469 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3471 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3472 return GST_FLOW_FLUSHING;
3477 #define PROBE_TYPE_IS_SERIALIZED(i) \
3480 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3481 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3482 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3484 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3485 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3487 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3488 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3492 static GstFlowReturn
3493 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3494 GstFlowReturn defaultval)
3503 data.handled = FALSE;
3504 data.marshalled = FALSE;
3505 data.dropped = FALSE;
3506 data.cookie = ++pad->priv->probe_cookie;
3509 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3511 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3512 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3517 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3518 "do probes cookie %u", data.cookie);
3519 cookie = pad->priv->probe_list_cookie;
3521 g_hook_list_marshal (&pad->probes, TRUE,
3522 (GHookMarshaller) probe_hook_marshal, &data);
3524 /* if the list changed, call the new callbacks (they will not have their
3525 * cookie set to data.cookie */
3526 if (cookie != pad->priv->probe_list_cookie) {
3527 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3528 "probe list changed, restarting");
3532 /* the first item that dropped will stop the hooks and then we drop here */
3536 /* If one handler took care of it, let the the item pass */
3541 /* if no handler matched and we are blocking, let the item pass */
3542 if (!data.marshalled && is_block)
3545 /* At this point, all handlers returned either OK or PASS. If one handler
3546 * returned PASS, let the item pass */
3551 while (GST_PAD_IS_BLOCKED (pad)) {
3552 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3553 "we are blocked %d times", pad->num_blocked);
3555 /* we might have released the lock */
3556 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3559 /* now we block the streaming thread. It can be unlocked when we
3560 * deactivate the pad (which will also set the FLUSHING flag) or
3561 * when the pad is unblocked. A flushing event will also unblock
3562 * the pad after setting the FLUSHING flag. */
3563 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3564 "Waiting to be unblocked or set flushing");
3565 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3566 GST_PAD_BLOCK_WAIT (pad);
3567 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3568 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3570 /* if the list changed, call the new callbacks (they will not have their
3571 * cookie set to data.cookie */
3572 if (cookie != pad->priv->probe_list_cookie) {
3573 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3574 "probe list changed, restarting");
3578 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3588 GST_DEBUG_OBJECT (pad, "pad is flushing");
3589 return GST_FLOW_FLUSHING;
3593 GST_DEBUG_OBJECT (pad, "data is dropped");
3594 return GST_FLOW_CUSTOM_SUCCESS;
3598 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3599 GST_DEBUG_OBJECT (pad, "data is passed");
3604 GST_DEBUG_OBJECT (pad, "data was handled");
3605 return GST_FLOW_CUSTOM_SUCCESS_1;
3612 * gst_pad_get_offset:
3615 * Get the offset applied to the running time of @pad. @pad has to be a source
3618 * Returns: the offset.
3621 gst_pad_get_offset (GstPad * pad)
3625 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3627 GST_OBJECT_LOCK (pad);
3628 result = pad->offset;
3629 GST_OBJECT_UNLOCK (pad);
3635 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3637 ev->received = FALSE;
3642 * gst_pad_set_offset:
3644 * @offset: the offset
3646 * Set the offset that will be applied to the running time of @pad.
3649 gst_pad_set_offset (GstPad * pad, gint64 offset)
3651 g_return_if_fail (GST_IS_PAD (pad));
3653 GST_OBJECT_LOCK (pad);
3654 /* if nothing changed, do nothing */
3655 if (pad->offset == offset)
3658 pad->offset = offset;
3659 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3661 /* resend all sticky events with updated offset on next buffer push */
3662 events_foreach (pad, mark_event_not_received, NULL);
3663 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3666 GST_OBJECT_UNLOCK (pad);
3673 /* If TRUE and ret is not OK this means
3674 * that pushing the EOS event failed
3678 /* If called for an event this is
3679 * the event that would be pushed
3680 * next. Don't forward sticky events
3681 * that would come after that */
3685 /* should be called with pad LOCK */
3687 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3689 PushStickyData *data = user_data;
3690 GstEvent *event = ev->event;
3693 GST_DEBUG_OBJECT (pad, "event %s was already received",
3694 GST_EVENT_TYPE_NAME (event));
3698 /* If we're called because of an sticky event, only forward
3699 * events that would come before this new event and the
3701 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3702 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3703 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3704 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3706 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3707 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3710 switch (data->ret) {
3712 ev->received = TRUE;
3713 GST_DEBUG_OBJECT (pad, "event %s marked received",
3714 GST_EVENT_TYPE_NAME (event));
3716 case GST_FLOW_CUSTOM_SUCCESS:
3717 /* we can't assume the event is received when it was dropped */
3718 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3719 GST_EVENT_TYPE_NAME (event));
3720 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3721 data->ret = GST_FLOW_OK;
3723 case GST_FLOW_CUSTOM_SUCCESS_1:
3724 /* event was ignored and should be sent later */
3725 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3726 GST_EVENT_TYPE_NAME (event));
3727 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3728 data->ret = GST_FLOW_OK;
3730 case GST_FLOW_NOT_LINKED:
3731 /* not linked is not a problem, we are sticky so the event will be
3732 * sent later but only for non-EOS events */
3733 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3734 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3735 data->ret = GST_FLOW_OK;
3736 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3739 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3740 gst_flow_get_name (data->ret));
3741 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3745 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3746 data->was_eos = TRUE;
3748 return data->ret == GST_FLOW_OK;
3751 /* check sticky events and push them when needed. should be called
3753 static inline GstFlowReturn
3754 check_sticky (GstPad * pad, GstEvent * event)
3756 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3758 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3759 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3761 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3762 events_foreach (pad, push_sticky, &data);
3764 /* If there's an EOS event we must push it downstream
3765 * even if sending a previous sticky event failed.
3766 * Otherwise the pipeline might wait forever for EOS.
3768 * Only do this if pushing another event than the EOS
3771 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3772 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3774 if (ev && !ev->received) {
3775 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3776 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3777 /* the event could have been dropped. Because this can only
3778 * happen if the user asked for it, it's not an error */
3779 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3780 data.ret = GST_FLOW_OK;
3790 * @pad: a #GstPad to invoke the default query on.
3791 * @query: (transfer none): the #GstQuery to perform.
3793 * Dispatches a query to a pad. The query should have been allocated by the
3794 * caller via one of the type-specific allocation functions. The element that
3795 * the pad belongs to is responsible for filling the query with an appropriate
3796 * response, which should then be parsed with a type-specific query parsing
3799 * Again, the caller is responsible for both the allocation and deallocation of
3800 * the query structure.
3802 * Please also note that some queries might need a running pipeline to work.
3804 * Returns: %TRUE if the query could be performed.
3807 gst_pad_query (GstPad * pad, GstQuery * query)
3810 gboolean res, serialized;
3811 GstPadQueryFunction func;
3812 GstPadProbeType type;
3815 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3816 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3818 if (GST_PAD_IS_SRC (pad)) {
3819 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3820 goto wrong_direction;
3821 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3822 } else if (GST_PAD_IS_SINK (pad)) {
3823 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3824 goto wrong_direction;
3825 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3827 goto unknown_direction;
3829 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3830 GST_QUERY_TYPE_NAME (query));
3831 GST_TRACER_PAD_QUERY_PRE (pad, query);
3833 serialized = GST_QUERY_IS_SERIALIZED (query);
3834 if (G_UNLIKELY (serialized))
3835 GST_PAD_STREAM_LOCK (pad);
3837 GST_OBJECT_LOCK (pad);
3838 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3839 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3840 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3842 ACQUIRE_PARENT (pad, parent, no_parent);
3843 GST_OBJECT_UNLOCK (pad);
3845 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3848 res = func (pad, parent, query);
3850 RELEASE_PARENT (parent);
3852 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3853 GST_QUERY_TYPE_NAME (query), res);
3854 GST_TRACER_PAD_QUERY_POST (pad, res, query);
3859 GST_OBJECT_LOCK (pad);
3860 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3861 GST_OBJECT_UNLOCK (pad);
3863 if (G_UNLIKELY (serialized))
3864 GST_PAD_STREAM_UNLOCK (pad);
3871 g_warning ("pad %s:%s query %s in wrong direction",
3872 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3877 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3882 GST_DEBUG_OBJECT (pad, "had no parent");
3883 GST_OBJECT_UNLOCK (pad);
3884 if (G_UNLIKELY (serialized))
3885 GST_PAD_STREAM_UNLOCK (pad);
3890 GST_DEBUG_OBJECT (pad, "had no query function");
3891 RELEASE_PARENT (parent);
3892 if (G_UNLIKELY (serialized))
3893 GST_PAD_STREAM_UNLOCK (pad);
3898 GST_DEBUG_OBJECT (pad, "query failed");
3899 if (G_UNLIKELY (serialized))
3900 GST_PAD_STREAM_UNLOCK (pad);
3905 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3906 GST_OBJECT_UNLOCK (pad);
3907 if (G_UNLIKELY (serialized))
3908 GST_PAD_STREAM_UNLOCK (pad);
3910 /* if a probe dropped without handling, we don't sent it further but assume
3911 * that the probe did not answer the query and return FALSE */
3912 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
3922 * gst_pad_peer_query:
3923 * @pad: a #GstPad to invoke the peer query on.
3924 * @query: (transfer none): the #GstQuery to perform.
3926 * Performs gst_pad_query() on the peer of @pad.
3928 * The caller is responsible for both the allocation and deallocation of
3929 * the query structure.
3931 * Returns: %TRUE if the query could be performed. This function returns %FALSE
3932 * if @pad has no peer.
3935 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3938 GstPadProbeType type;
3939 gboolean res, serialized;
3942 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3943 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3945 if (GST_PAD_IS_SRC (pad)) {
3946 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3947 goto wrong_direction;
3948 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3949 } else if (GST_PAD_IS_SINK (pad)) {
3950 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3951 goto wrong_direction;
3952 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3954 goto unknown_direction;
3956 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3957 GST_QUERY_TYPE_NAME (query));
3959 serialized = GST_QUERY_IS_SERIALIZED (query);
3961 GST_OBJECT_LOCK (pad);
3962 if (GST_PAD_IS_SRC (pad) && serialized) {
3963 /* all serialized queries on the srcpad trigger push of
3965 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3969 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3970 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3971 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3973 peerpad = GST_PAD_PEER (pad);
3974 if (G_UNLIKELY (peerpad == NULL))
3977 gst_object_ref (peerpad);
3978 GST_OBJECT_UNLOCK (pad);
3980 res = gst_pad_query (peerpad, query);
3982 gst_object_unref (peerpad);
3987 GST_OBJECT_LOCK (pad);
3988 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3989 GST_OBJECT_UNLOCK (pad);
3996 g_warning ("pad %s:%s query %s in wrong direction",
3997 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4002 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4007 GST_WARNING_OBJECT (pad, "could not send sticky events");
4008 GST_OBJECT_UNLOCK (pad);
4013 GST_INFO_OBJECT (pad, "pad has no peer");
4014 GST_OBJECT_UNLOCK (pad);
4019 GST_DEBUG_OBJECT (pad, "query failed");
4024 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4025 GST_OBJECT_UNLOCK (pad);
4027 /* if a probe dropped without handling, we don't sent it further but
4028 * assume that the probe did not answer the query and return FALSE */
4029 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4038 /**********************************************************************
4039 * Data passing functions
4042 /* this is the chain function that does not perform the additional argument
4043 * checking for that little extra speed.
4045 static inline GstFlowReturn
4046 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4050 gboolean handled = FALSE;
4052 GST_PAD_STREAM_LOCK (pad);
4054 GST_OBJECT_LOCK (pad);
4055 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4058 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4061 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4064 #ifdef GST_ENABLE_EXTRA_CHECKS
4065 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4066 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4068 ":%s:<%s:%s> Got data flow before stream-start event",
4069 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4071 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4073 ":%s:<%s:%s> Got data flow before segment event",
4074 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4076 pad->priv->last_cookie = pad->priv->events_cookie;
4080 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4083 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4085 ACQUIRE_PARENT (pad, parent, no_parent);
4086 GST_OBJECT_UNLOCK (pad);
4088 /* NOTE: we read the chainfunc unlocked.
4089 * we cannot hold the lock for the pad so we might send
4090 * the data to the wrong function. This is not really a
4091 * problem since functions are assigned at creation time
4092 * and don't change that often... */
4093 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4094 GstPadChainFunction chainfunc;
4096 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4099 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4100 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4101 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4103 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4105 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4106 "called chainfunction &%s with buffer %p, returned %s",
4107 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4109 GstPadChainListFunction chainlistfunc;
4111 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4114 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4115 "calling chainlistfunction &%s",
4116 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4118 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4120 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4121 "called chainlistfunction &%s, returned %s",
4122 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4125 RELEASE_PARENT (parent);
4127 GST_PAD_STREAM_UNLOCK (pad);
4134 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4135 "chaining, but pad was flushing");
4136 GST_OBJECT_UNLOCK (pad);
4137 GST_PAD_STREAM_UNLOCK (pad);
4138 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4139 return GST_FLOW_FLUSHING;
4143 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4144 GST_OBJECT_UNLOCK (pad);
4145 GST_PAD_STREAM_UNLOCK (pad);
4146 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4147 return GST_FLOW_EOS;
4151 g_critical ("chain on pad %s:%s but it was not in push mode",
4152 GST_DEBUG_PAD_NAME (pad));
4153 GST_OBJECT_UNLOCK (pad);
4154 GST_PAD_STREAM_UNLOCK (pad);
4155 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4156 return GST_FLOW_ERROR;
4163 GST_OBJECT_UNLOCK (pad);
4164 GST_PAD_STREAM_UNLOCK (pad);
4165 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4167 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4170 case GST_FLOW_CUSTOM_SUCCESS:
4171 case GST_FLOW_CUSTOM_SUCCESS_1:
4172 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4176 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4183 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4184 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4185 GST_OBJECT_UNLOCK (pad);
4186 GST_PAD_STREAM_UNLOCK (pad);
4187 return GST_FLOW_FLUSHING;
4191 RELEASE_PARENT (parent);
4192 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4193 g_critical ("chain on pad %s:%s but it has no chainfunction",
4194 GST_DEBUG_PAD_NAME (pad));
4195 GST_PAD_STREAM_UNLOCK (pad);
4196 return GST_FLOW_NOT_SUPPORTED;
4202 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4203 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4206 * Chain a buffer to @pad.
4208 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4210 * If the buffer type is not acceptable for @pad (as negotiated with a
4211 * preceding GST_EVENT_CAPS event), this function returns
4212 * #GST_FLOW_NOT_NEGOTIATED.
4214 * The function proceeds calling the chain function installed on @pad (see
4215 * gst_pad_set_chain_function()) and the return value of that function is
4216 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4219 * In all cases, success or failure, the caller loses its reference to @buffer
4220 * after calling this function.
4222 * Returns: a #GstFlowReturn from the pad.
4227 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4229 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4230 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4231 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4233 return gst_pad_chain_data_unchecked (pad,
4234 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4237 static GstFlowReturn
4238 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4239 GstBufferList * list)
4245 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4247 len = gst_buffer_list_length (list);
4250 for (i = 0; i < len; i++) {
4251 buffer = gst_buffer_list_get (list, i);
4253 gst_pad_chain_data_unchecked (pad,
4254 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4255 gst_buffer_ref (buffer));
4256 if (ret != GST_FLOW_OK)
4259 gst_buffer_list_unref (list);
4265 * gst_pad_chain_list:
4266 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4267 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4270 * Chain a bufferlist to @pad.
4272 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4274 * If @pad was not negotiated properly with a CAPS event, this function
4275 * returns #GST_FLOW_NOT_NEGOTIATED.
4277 * The function proceeds calling the chainlist function installed on @pad (see
4278 * gst_pad_set_chain_list_function()) and the return value of that function is
4279 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4280 * chainlist function.
4282 * In all cases, success or failure, the caller loses its reference to @list
4283 * after calling this function.
4287 * Returns: a #GstFlowReturn from the pad.
4290 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4292 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4293 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4294 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4296 return gst_pad_chain_data_unchecked (pad,
4297 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4300 static GstFlowReturn
4301 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4305 gboolean handled = FALSE;
4307 GST_OBJECT_LOCK (pad);
4308 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4311 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4314 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4317 #ifdef GST_ENABLE_EXTRA_CHECKS
4318 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4319 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4321 ":%s:<%s:%s> Got data flow before stream-start event",
4322 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4324 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4326 ":%s:<%s:%s> Got data flow before segment event",
4327 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4329 pad->priv->last_cookie = pad->priv->events_cookie;
4333 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4336 /* do block probes */
4337 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4340 /* recheck sticky events because the probe might have cause a relink */
4341 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4344 /* do post-blocking probes */
4345 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4347 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4350 /* take ref to peer pad before releasing the lock */
4351 gst_object_ref (peer);
4353 GST_OBJECT_UNLOCK (pad);
4355 ret = gst_pad_chain_data_unchecked (peer, type, data);
4358 gst_object_unref (peer);
4360 GST_OBJECT_LOCK (pad);
4361 pad->ABI.abi.last_flowret = ret;
4363 if (pad->priv->using == 0) {
4364 /* pad is not active anymore, trigger idle callbacks */
4365 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4366 probe_stopped, ret);
4368 GST_OBJECT_UNLOCK (pad);
4372 /* ERROR recovery here */
4376 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4377 "pushing, but pad was flushing");
4378 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4379 GST_OBJECT_UNLOCK (pad);
4380 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4381 return GST_FLOW_FLUSHING;
4385 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4386 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4387 GST_OBJECT_UNLOCK (pad);
4388 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4389 return GST_FLOW_EOS;
4393 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4394 GST_DEBUG_PAD_NAME (pad));
4395 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4396 GST_OBJECT_UNLOCK (pad);
4397 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4398 return GST_FLOW_ERROR;
4402 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4403 "error pushing events, return %s", gst_flow_get_name (ret));
4404 pad->ABI.abi.last_flowret = ret;
4405 GST_OBJECT_UNLOCK (pad);
4406 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4414 GST_OBJECT_UNLOCK (pad);
4415 if (data != NULL && !handled)
4416 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4419 case GST_FLOW_CUSTOM_SUCCESS:
4420 case GST_FLOW_CUSTOM_SUCCESS_1:
4421 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4425 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4428 pad->ABI.abi.last_flowret = ret;
4433 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4434 "pushing, but it was not linked");
4435 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4436 GST_OBJECT_UNLOCK (pad);
4437 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4438 return GST_FLOW_NOT_LINKED;
4444 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4445 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4448 * Pushes a buffer to the peer of @pad.
4450 * This function will call installed block probes before triggering any
4451 * installed data probes.
4453 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4454 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4457 * In all cases, success or failure, the caller loses its reference to @buffer
4458 * after calling this function.
4460 * Returns: a #GstFlowReturn from the peer pad.
4465 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4469 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4470 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4471 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4473 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4474 res = gst_pad_push_data (pad,
4475 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4476 GST_TRACER_PAD_PUSH_POST (pad, res);
4481 * gst_pad_push_list:
4482 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4483 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4486 * Pushes a buffer list to the peer of @pad.
4488 * This function will call installed block probes before triggering any
4489 * installed data probes.
4491 * The function proceeds calling the chain function on the peer pad and returns
4492 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4493 * be returned. If the peer pad does not have any installed chainlist function
4494 * every group buffer of the list will be merged into a normal #GstBuffer and
4495 * chained via gst_pad_chain().
4497 * In all cases, success or failure, the caller loses its reference to @list
4498 * after calling this function.
4500 * Returns: a #GstFlowReturn from the peer pad.
4505 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4509 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4510 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4511 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4513 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4514 res = gst_pad_push_data (pad,
4515 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4516 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4520 static GstFlowReturn
4521 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4522 GstBuffer ** buffer)
4525 GstPadGetRangeFunction getrangefunc;
4529 GST_PAD_STREAM_LOCK (pad);
4531 GST_OBJECT_LOCK (pad);
4532 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4535 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4538 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4543 /* when one of the probes returns DROPPED, probe_stopped will be called
4544 * and we skip calling the getrange function, res_buf should then contain a
4545 * valid result buffer */
4546 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4547 res_buf, offset, size, probe_stopped);
4549 /* recheck sticky events because the probe might have cause a relink */
4550 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4553 ACQUIRE_PARENT (pad, parent, no_parent);
4554 GST_OBJECT_UNLOCK (pad);
4556 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4559 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4560 "calling getrangefunc %s, offset %"
4561 G_GUINT64_FORMAT ", size %u",
4562 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4564 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4566 RELEASE_PARENT (parent);
4568 GST_OBJECT_LOCK (pad);
4569 if (G_UNLIKELY (ret != GST_FLOW_OK))
4570 goto get_range_failed;
4572 /* can only fire the signal if we have a valid buffer */
4574 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4575 res_buf, offset, size, probe_stopped_unref);
4576 pad->ABI.abi.last_flowret = ret;
4577 GST_OBJECT_UNLOCK (pad);
4579 GST_PAD_STREAM_UNLOCK (pad);
4588 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4589 "getrange, but pad was flushing");
4590 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4591 GST_OBJECT_UNLOCK (pad);
4592 GST_PAD_STREAM_UNLOCK (pad);
4593 return GST_FLOW_FLUSHING;
4597 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4598 GST_DEBUG_PAD_NAME (pad));
4599 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4600 GST_OBJECT_UNLOCK (pad);
4601 GST_PAD_STREAM_UNLOCK (pad);
4602 return GST_FLOW_ERROR;
4606 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4607 pad->ABI.abi.last_flowret = ret;
4608 GST_OBJECT_UNLOCK (pad);
4609 GST_PAD_STREAM_UNLOCK (pad);
4614 GST_DEBUG_OBJECT (pad, "no parent");
4615 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4616 GST_OBJECT_UNLOCK (pad);
4617 GST_PAD_STREAM_UNLOCK (pad);
4618 return GST_FLOW_FLUSHING;
4622 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4623 GST_DEBUG_PAD_NAME (pad));
4624 RELEASE_PARENT (parent);
4625 GST_PAD_STREAM_UNLOCK (pad);
4626 return GST_FLOW_NOT_SUPPORTED;
4630 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4631 "probe returned %s", gst_flow_get_name (ret));
4632 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4634 /* the probe filled the buffer and asks us to not call the getrange
4635 * anymore, we continue with the post probes then. */
4636 GST_DEBUG_OBJECT (pad, "handled buffer");
4640 /* no buffer, we are EOS */
4641 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4645 pad->ABI.abi.last_flowret = ret;
4646 GST_OBJECT_UNLOCK (pad);
4647 GST_PAD_STREAM_UNLOCK (pad);
4651 probe_stopped_unref:
4653 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4654 "probe returned %s", gst_flow_get_name (ret));
4655 /* if we drop here, it signals EOS */
4656 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4658 pad->ABI.abi.last_flowret = ret;
4659 GST_OBJECT_UNLOCK (pad);
4660 GST_PAD_STREAM_UNLOCK (pad);
4661 if (*buffer == NULL)
4662 gst_buffer_unref (res_buf);
4667 pad->ABI.abi.last_flowret = ret;
4668 GST_OBJECT_UNLOCK (pad);
4669 GST_PAD_STREAM_UNLOCK (pad);
4670 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4671 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4672 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4678 * gst_pad_get_range:
4679 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4680 * @offset: The start offset of the buffer
4681 * @size: The length of the buffer
4682 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4683 * returns #GST_FLOW_ERROR if %NULL.
4685 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4686 * immediately and @buffer is %NULL.
4688 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4689 * description of a getrange function. If @pad has no getrange function
4690 * installed (see gst_pad_set_getrange_function()) this function returns
4691 * #GST_FLOW_NOT_SUPPORTED.
4693 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4694 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4695 * must be freed with gst_buffer_unref() after usage.
4697 * When @buffer points to a variable that points to a valid #GstBuffer, the
4698 * buffer will be filled with the result data when this function returns
4699 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4700 * @size bytes will be filled in the result buffer and its size will be updated
4703 * Note that less than @size bytes can be returned in @buffer when, for example,
4704 * an EOS condition is near or when @buffer is not large enough to hold @size
4705 * bytes. The caller should check the result buffer size to get the result size.
4707 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4708 * will be unchanged.
4710 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4712 * Returns: a #GstFlowReturn from the pad.
4717 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4718 GstBuffer ** buffer)
4720 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4721 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4722 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4723 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4724 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4726 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4730 * gst_pad_pull_range:
4731 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4732 * @offset: The start offset of the buffer
4733 * @size: The length of the buffer
4734 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4735 * GST_FLOW_ERROR if %NULL.
4737 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4739 * This function will first trigger the pad block signal if it was
4742 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4743 * function returns the result of gst_pad_get_range() on the peer pad.
4744 * See gst_pad_get_range() for a list of return values and for the
4745 * semantics of the arguments of this function.
4747 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4748 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4749 * must be freed with gst_buffer_unref() after usage. When this function
4750 * returns any other result value, @buffer will still point to %NULL.
4752 * When @buffer points to a variable that points to a valid #GstBuffer, the
4753 * buffer will be filled with the result data when this function returns
4754 * #GST_FLOW_OK. When this function returns any other result value,
4755 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4756 * @size bytes will be filled in the result buffer and its size will be updated
4759 * Note that less than @size bytes can be returned in @buffer when, for example,
4760 * an EOS condition is near or when @buffer is not large enough to hold @size
4761 * bytes. The caller should check the result buffer size to get the result size.
4763 * Returns: a #GstFlowReturn from the peer pad.
4768 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4769 GstBuffer ** buffer)
4775 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4776 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4777 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4778 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4779 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4781 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4783 GST_OBJECT_LOCK (pad);
4784 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4787 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4792 /* when one of the probes returns DROPPED, probe_stopped will be
4793 * called and we skip calling the peer getrange function. *buffer should then
4794 * contain a valid buffer */
4795 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4796 res_buf, offset, size, probe_stopped);
4798 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4801 gst_object_ref (peer);
4803 GST_OBJECT_UNLOCK (pad);
4805 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4807 gst_object_unref (peer);
4809 GST_OBJECT_LOCK (pad);
4811 pad->ABI.abi.last_flowret = ret;
4812 if (pad->priv->using == 0) {
4813 /* pad is not active anymore, trigger idle callbacks */
4814 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4815 probe_stopped_unref, ret);
4818 if (G_UNLIKELY (ret != GST_FLOW_OK))
4819 goto pull_range_failed;
4822 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4823 res_buf, offset, size, probe_stopped_unref);
4825 GST_OBJECT_UNLOCK (pad);
4829 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4832 /* ERROR recovery here */
4835 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4836 "pullrange, but pad was flushing");
4837 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4838 GST_OBJECT_UNLOCK (pad);
4839 ret = GST_FLOW_FLUSHING;
4844 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4845 GST_DEBUG_PAD_NAME (pad));
4846 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4847 GST_OBJECT_UNLOCK (pad);
4848 ret = GST_FLOW_ERROR;
4853 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4854 gst_flow_get_name (ret));
4855 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4857 /* the probe filled the buffer and asks us to not forward to the peer
4858 * anymore, we continue with the post probes then */
4859 GST_DEBUG_OBJECT (pad, "handled buffer");
4863 /* no buffer, we are EOS then */
4864 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4868 pad->ABI.abi.last_flowret = ret;
4869 GST_OBJECT_UNLOCK (pad);
4874 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4875 "pulling range, but it was not linked");
4876 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4877 GST_OBJECT_UNLOCK (pad);
4878 ret = GST_FLOW_NOT_LINKED;
4883 pad->ABI.abi.last_flowret = ret;
4884 GST_OBJECT_UNLOCK (pad);
4885 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4886 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4887 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4890 probe_stopped_unref:
4892 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4893 "post probe returned %s", gst_flow_get_name (ret));
4895 /* if we drop here, it signals EOS */
4896 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4899 pad->ABI.abi.last_flowret = ret;
4900 GST_OBJECT_UNLOCK (pad);
4902 if (*buffer == NULL)
4903 gst_buffer_unref (res_buf);
4907 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
4911 /* must be called with pad object lock */
4912 static GstFlowReturn
4913 store_sticky_event (GstPad * pad, GstEvent * event)
4918 gboolean res = FALSE;
4919 const gchar *name = NULL;
4920 gboolean insert = TRUE;
4922 type = GST_EVENT_TYPE (event);
4924 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4925 * otherwise they can be dropped and nothing would ever resend them.
4926 * Only do that for activated pads though, everything else is a bug!
4928 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4929 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4930 || type == GST_EVENT_EOS))))
4933 /* Unset the EOS flag when received STREAM_START event, so pad can
4934 * store sticky event and then push it later */
4935 if (type == GST_EVENT_STREAM_START) {
4936 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4937 remove_event_by_type (pad, GST_EVENT_EOS);
4938 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4941 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4944 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4945 name = gst_structure_get_name (gst_event_get_structure (event));
4947 events = pad->priv->events;
4950 for (i = 0; i < len; i++) {
4951 PadEvent *ev = &g_array_index (events, PadEvent, i);
4953 if (ev->event == NULL)
4956 if (type == GST_EVENT_TYPE (ev->event)) {
4957 /* matching types, check matching name if needed */
4958 if (name && !gst_event_has_name (ev->event, name))
4962 if ((res = gst_event_replace (&ev->event, event)))
4963 ev->received = FALSE;
4969 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4970 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4971 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4972 * storing the sticky ordered we can check that this is respected. */
4973 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4974 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4976 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4977 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4978 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4979 gst_event_type_get_name (type));
4985 ev.event = gst_event_ref (event);
4986 ev.received = FALSE;
4987 g_array_insert_val (events, i, ev);
4992 pad->priv->events_cookie++;
4993 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4995 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4997 switch (GST_EVENT_TYPE (event)) {
4998 case GST_EVENT_CAPS:
4999 GST_OBJECT_UNLOCK (pad);
5001 GST_DEBUG_OBJECT (pad, "notify caps");
5002 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5004 GST_OBJECT_LOCK (pad);
5010 if (type == GST_EVENT_EOS) {
5011 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5012 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5015 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5020 GST_DEBUG_OBJECT (pad, "pad is flushing");
5021 return GST_FLOW_FLUSHING;
5025 GST_DEBUG_OBJECT (pad, "pad is EOS");
5026 return GST_FLOW_EOS;
5031 * gst_pad_store_sticky_event:
5033 * @event: a #GstEvent
5035 * Store the sticky @event on @pad
5037 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5038 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5043 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5047 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5048 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5050 GST_OBJECT_LOCK (pad);
5051 ret = store_sticky_event (pad, event);
5052 GST_OBJECT_UNLOCK (pad);
5058 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5060 PushStickyData *data = user_data;
5062 /* Forward all sticky events before our current one that are pending */
5063 if (ev->event != data->event
5064 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5065 return push_sticky (pad, ev, data);
5070 /* should be called with pad LOCK */
5071 static GstFlowReturn
5072 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5073 GstPadProbeType type)
5077 GstEventType event_type;
5079 /* pass the adjusted event on. We need to do this even if
5080 * there is no peer pad because of the probes. */
5081 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5083 /* Two checks to be made:
5084 * . (un)set the FLUSHING flag for flushing events,
5085 * . handle pad blocking */
5086 event_type = GST_EVENT_TYPE (event);
5087 switch (event_type) {
5088 case GST_EVENT_FLUSH_START:
5089 GST_PAD_SET_FLUSHING (pad);
5091 GST_PAD_BLOCK_BROADCAST (pad);
5092 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5094 case GST_EVENT_FLUSH_STOP:
5095 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5098 GST_PAD_UNSET_FLUSHING (pad);
5100 /* Remove sticky EOS events */
5101 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5102 remove_event_by_type (pad, GST_EVENT_EOS);
5103 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5104 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5105 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5107 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5111 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5114 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5115 * checked already or this is called as part of pushing sticky events,
5116 * in which case we still want to forward the EOS event downstream.
5119 switch (GST_EVENT_TYPE (event)) {
5120 case GST_EVENT_RECONFIGURE:
5121 if (GST_PAD_IS_SINK (pad))
5122 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5127 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5128 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5133 /* send probes after modifying the events above */
5134 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5136 /* recheck sticky events because the probe might have cause a relink */
5137 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5138 && (GST_EVENT_IS_SERIALIZED (event)
5139 || GST_EVENT_IS_STICKY (event))) {
5140 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5141 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5143 /* Push all sticky events before our current one
5144 * that have changed */
5145 events_foreach (pad, sticky_changed, &data);
5148 /* now check the peer pad */
5149 peerpad = GST_PAD_PEER (pad);
5150 if (peerpad == NULL)
5153 gst_object_ref (peerpad);
5155 GST_OBJECT_UNLOCK (pad);
5157 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5158 event, gst_event_type_get_name (event_type), peerpad);
5160 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5162 /* Note: we gave away ownership of the event at this point but we can still
5163 * print the old pointer */
5164 GST_LOG_OBJECT (pad,
5165 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5166 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5168 gst_object_unref (peerpad);
5170 GST_OBJECT_LOCK (pad);
5172 if (pad->priv->using == 0) {
5173 /* pad is not active anymore, trigger idle callbacks */
5174 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5175 idle_probe_stopped, ret);
5179 /* ERROR handling */
5182 GST_DEBUG_OBJECT (pad, "We're flushing");
5183 gst_event_unref (event);
5184 return GST_FLOW_FLUSHING;
5188 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5189 gst_event_unref (event);
5190 return GST_FLOW_FLUSHING;
5194 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5195 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5196 gst_event_unref (event);
5199 case GST_FLOW_CUSTOM_SUCCESS_1:
5200 GST_DEBUG_OBJECT (pad, "handled event");
5202 case GST_FLOW_CUSTOM_SUCCESS:
5203 GST_DEBUG_OBJECT (pad, "dropped event");
5206 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5213 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5214 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5215 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5216 gst_event_unref (event);
5218 /* unlinked pads should not influence latency configuration */
5219 if (event_type == GST_EVENT_LATENCY)
5222 return GST_FLOW_NOT_LINKED;
5226 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5232 * gst_pad_push_event:
5233 * @pad: a #GstPad to push the event to.
5234 * @event: (transfer full): the #GstEvent to send to the pad.
5236 * Sends the event to the peer of the given pad. This function is
5237 * mainly used by elements to send events to their peer
5240 * This function takes ownership of the provided event so you should
5241 * gst_event_ref() it if you want to reuse the event after this call.
5243 * Returns: %TRUE if the event was handled.
5248 gst_pad_push_event (GstPad * pad, GstEvent * event)
5250 gboolean res = FALSE;
5251 GstPadProbeType type;
5252 gboolean sticky, serialized;
5254 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5255 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5257 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5259 if (GST_PAD_IS_SRC (pad)) {
5260 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5261 goto wrong_direction;
5262 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5263 } else if (GST_PAD_IS_SINK (pad)) {
5264 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5265 goto wrong_direction;
5266 /* events pushed on sinkpad never are sticky */
5267 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5269 goto unknown_direction;
5271 GST_OBJECT_LOCK (pad);
5272 sticky = GST_EVENT_IS_STICKY (event);
5273 serialized = GST_EVENT_IS_SERIALIZED (event);
5276 /* srcpad sticky events are stored immediately, the received flag is set
5277 * to FALSE and will be set to TRUE when we can successfully push the
5278 * event to the peer pad */
5279 switch (store_sticky_event (pad, event)) {
5280 case GST_FLOW_FLUSHING:
5288 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5289 /* all serialized or sticky events on the srcpad trigger push of
5291 res = (check_sticky (pad, event) == GST_FLOW_OK);
5296 /* other events are pushed right away */
5297 ret = gst_pad_push_event_unchecked (pad, event, type);
5298 /* dropped events by a probe are not an error */
5299 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5300 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5302 /* Errors in sticky event pushing are no problem and ignored here
5303 * as they will cause more meaningful errors during data flow.
5304 * For EOS events, that are not followed by data flow, we still
5305 * return FALSE here though.
5307 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5309 gst_event_unref (event);
5311 GST_OBJECT_UNLOCK (pad);
5313 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5316 /* ERROR handling */
5319 g_warning ("pad %s:%s pushing %s event in wrong direction",
5320 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5321 gst_event_unref (event);
5326 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5327 gst_event_unref (event);
5332 GST_DEBUG_OBJECT (pad, "We're flushing");
5333 GST_OBJECT_UNLOCK (pad);
5334 gst_event_unref (event);
5339 GST_DEBUG_OBJECT (pad, "We're EOS");
5340 GST_OBJECT_UNLOCK (pad);
5341 gst_event_unref (event);
5345 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5349 /* Check if we can call the event function with the given event */
5350 static GstFlowReturn
5351 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5355 switch (GST_EVENT_TYPE (event)) {
5356 case GST_EVENT_CAPS:
5358 /* backwards compatibility mode for caps */
5359 gst_event_parse_caps (event, &caps);
5361 if (!gst_pad_query_accept_caps (pad, caps))
5373 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5374 "caps %" GST_PTR_FORMAT " not accepted", caps);
5375 return GST_FLOW_NOT_NEGOTIATED;
5379 static GstFlowReturn
5380 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5381 GstPadProbeType type)
5384 GstEventType event_type;
5385 gboolean serialized, need_unlock = FALSE, sticky;
5386 GstPadEventFunction eventfunc;
5389 GST_OBJECT_LOCK (pad);
5391 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5393 if (GST_PAD_IS_SINK (pad))
5394 serialized = GST_EVENT_IS_SERIALIZED (event);
5397 sticky = GST_EVENT_IS_STICKY (event);
5398 event_type = GST_EVENT_TYPE (event);
5399 switch (event_type) {
5400 case GST_EVENT_FLUSH_START:
5401 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5402 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5404 /* can't even accept a flush begin event when flushing */
5405 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5408 GST_PAD_SET_FLUSHING (pad);
5409 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5411 case GST_EVENT_FLUSH_STOP:
5412 /* we can't accept flush-stop on inactive pads else the flushing flag
5413 * would be cleared and it would look like the pad can accept data.
5414 * Also, some elements restart a streaming thread in flush-stop which we
5415 * can't allow on inactive pads */
5416 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5419 GST_PAD_UNSET_FLUSHING (pad);
5420 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5421 /* Remove pending EOS events */
5422 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5423 remove_event_by_type (pad, GST_EVENT_EOS);
5424 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5425 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5426 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5428 GST_OBJECT_UNLOCK (pad);
5429 /* grab stream lock */
5430 GST_PAD_STREAM_LOCK (pad);
5432 GST_OBJECT_LOCK (pad);
5433 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5436 case GST_EVENT_RECONFIGURE:
5437 if (GST_PAD_IS_SRC (pad))
5438 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5440 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5441 "have event type %" GST_PTR_FORMAT, event);
5443 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5446 switch (event_type) {
5447 case GST_EVENT_STREAM_START:
5448 /* Remove sticky EOS events */
5449 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5450 remove_event_by_type (pad, GST_EVENT_EOS);
5451 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5458 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5461 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5462 GST_OBJECT_UNLOCK (pad);
5463 GST_PAD_STREAM_LOCK (pad);
5465 GST_OBJECT_LOCK (pad);
5466 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5469 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5475 /* now do the probe */
5477 type | GST_PAD_PROBE_TYPE_PUSH |
5478 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5480 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5482 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5485 ACQUIRE_PARENT (pad, parent, no_parent);
5486 GST_OBJECT_UNLOCK (pad);
5488 ret = pre_eventfunc_check (pad, event);
5489 if (G_UNLIKELY (ret != GST_FLOW_OK))
5490 goto precheck_failed;
5493 gst_event_ref (event);
5495 if (eventfunc (pad, parent, event)) {
5498 /* something went wrong */
5499 switch (event_type) {
5500 case GST_EVENT_CAPS:
5501 ret = GST_FLOW_NOT_NEGOTIATED;
5504 ret = GST_FLOW_ERROR;
5508 RELEASE_PARENT (parent);
5510 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5513 if (ret == GST_FLOW_OK) {
5514 GST_OBJECT_LOCK (pad);
5515 /* after the event function accepted the event, we can store the sticky
5516 * event on the pad */
5517 switch (store_sticky_event (pad, event)) {
5518 case GST_FLOW_FLUSHING:
5525 GST_OBJECT_UNLOCK (pad);
5527 gst_event_unref (event);
5531 GST_PAD_STREAM_UNLOCK (pad);
5535 /* ERROR handling */
5538 GST_OBJECT_UNLOCK (pad);
5540 GST_PAD_STREAM_UNLOCK (pad);
5541 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5542 "Received event on flushing pad. Discarding");
5543 gst_event_unref (event);
5544 return GST_FLOW_FLUSHING;
5548 GST_OBJECT_UNLOCK (pad);
5550 GST_PAD_STREAM_UNLOCK (pad);
5551 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5552 "Received flush-stop on inactive pad. Discarding");
5553 gst_event_unref (event);
5554 return GST_FLOW_FLUSHING;
5558 GST_OBJECT_UNLOCK (pad);
5560 GST_PAD_STREAM_UNLOCK (pad);
5561 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5562 "Received event on EOS pad. Discarding");
5563 gst_event_unref (event);
5564 return GST_FLOW_EOS;
5568 GST_OBJECT_UNLOCK (pad);
5570 GST_PAD_STREAM_UNLOCK (pad);
5571 /* Only unref if unhandled */
5572 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5573 gst_event_unref (event);
5576 case GST_FLOW_CUSTOM_SUCCESS_1:
5577 case GST_FLOW_CUSTOM_SUCCESS:
5578 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5582 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5589 g_warning ("pad %s:%s has no event handler, file a bug.",
5590 GST_DEBUG_PAD_NAME (pad));
5591 GST_OBJECT_UNLOCK (pad);
5593 GST_PAD_STREAM_UNLOCK (pad);
5594 gst_event_unref (event);
5595 return GST_FLOW_NOT_SUPPORTED;
5599 GST_DEBUG_OBJECT (pad, "no parent");
5600 GST_OBJECT_UNLOCK (pad);
5602 GST_PAD_STREAM_UNLOCK (pad);
5603 gst_event_unref (event);
5604 return GST_FLOW_FLUSHING;
5608 GST_DEBUG_OBJECT (pad, "pre event check failed");
5609 RELEASE_PARENT (parent);
5611 GST_PAD_STREAM_UNLOCK (pad);
5612 gst_event_unref (event);
5618 * gst_pad_send_event:
5619 * @pad: a #GstPad to send the event to.
5620 * @event: (transfer full): the #GstEvent to send to the pad.
5622 * Sends the event to the pad. This function can be used
5623 * by applications to send events in the pipeline.
5625 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5626 * sink pad, @event should be a downstream event. For example, you would not
5627 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5628 * Furthermore, some downstream events have to be serialized with data flow,
5629 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5630 * the event needs to be serialized with data flow, this function will take the
5631 * pad's stream lock while calling its event function.
5633 * To find out whether an event type is upstream, downstream, or downstream and
5634 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5635 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5636 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5637 * plugin doesn't need to bother itself with this information; the core handles
5638 * all necessary locks and checks.
5640 * This function takes ownership of the provided event so you should
5641 * gst_event_ref() it if you want to reuse the event after this call.
5643 * Returns: %TRUE if the event was handled.
5646 gst_pad_send_event (GstPad * pad, GstEvent * event)
5649 GstPadProbeType type;
5651 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5652 g_return_val_if_fail (event != NULL, FALSE);
5654 if (GST_PAD_IS_SINK (pad)) {
5655 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5656 goto wrong_direction;
5657 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5658 } else if (GST_PAD_IS_SRC (pad)) {
5659 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5660 goto wrong_direction;
5661 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5663 goto unknown_direction;
5665 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5672 /* ERROR handling */
5675 g_warning ("pad %s:%s sending %s event in wrong direction",
5676 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5677 gst_event_unref (event);
5682 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5683 gst_event_unref (event);
5689 * gst_pad_set_element_private:
5690 * @pad: the #GstPad to set the private data of.
5691 * @priv: The private data to attach to the pad.
5693 * Set the given private data gpointer on the pad.
5694 * This function can only be used by the element that owns the pad.
5695 * No locking is performed in this function.
5698 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5700 pad->element_private = priv;
5704 * gst_pad_get_element_private:
5705 * @pad: the #GstPad to get the private data of.
5707 * Gets the private data of a pad.
5708 * No locking is performed in this function.
5710 * Returns: (transfer none): a #gpointer to the private data.
5713 gst_pad_get_element_private (GstPad * pad)
5715 return pad->element_private;
5719 * gst_pad_get_sticky_event:
5720 * @pad: the #GstPad to get the event from.
5721 * @event_type: the #GstEventType that should be retrieved.
5722 * @idx: the index of the event
5724 * Returns a new reference of the sticky event of type @event_type
5727 * Returns: (transfer full) (nullable): a #GstEvent of type
5728 * @event_type or %NULL when no event of @event_type was on
5729 * @pad. Unref after usage.
5732 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5734 GstEvent *event = NULL;
5737 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5738 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5740 GST_OBJECT_LOCK (pad);
5741 ev = find_event_by_type (pad, event_type, idx);
5742 if (ev && (event = ev->event))
5743 gst_event_ref (event);
5744 GST_OBJECT_UNLOCK (pad);
5751 GstPadStickyEventsForeachFunction func;
5756 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5758 ForeachDispatch *data = user_data;
5759 gboolean ret = TRUE;
5762 GST_OBJECT_UNLOCK (pad);
5764 ret = data->func (pad, &ev->event, data->user_data);
5766 GST_OBJECT_LOCK (pad);
5773 * gst_pad_sticky_events_foreach:
5774 * @pad: the #GstPad that should be used for iteration.
5775 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5776 * should be called for every event.
5777 * @user_data: (closure): the optional user data.
5779 * Iterates all sticky events on @pad and calls @foreach_func for every
5780 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5783 gst_pad_sticky_events_foreach (GstPad * pad,
5784 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5786 ForeachDispatch data;
5788 g_return_if_fail (GST_IS_PAD (pad));
5789 g_return_if_fail (foreach_func != NULL);
5791 data.func = foreach_func;
5792 data.user_data = user_data;
5794 GST_OBJECT_LOCK (pad);
5795 events_foreach (pad, foreach_dispatch_function, &data);
5796 GST_OBJECT_UNLOCK (pad);
5800 do_stream_status (GstPad * pad, GstStreamStatusType type,
5801 GThread * thread, GstTask * task)
5805 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5807 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5808 if (GST_IS_ELEMENT (parent)) {
5809 GstMessage *message;
5810 GValue value = { 0 };
5812 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5813 gchar *tname, *ename, *pname;
5815 /* create a good task name */
5816 ename = gst_element_get_name (parent);
5817 pname = gst_pad_get_name (pad);
5818 tname = g_strdup_printf ("%s:%s", ename, pname);
5822 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5826 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5829 g_value_init (&value, GST_TYPE_TASK);
5830 g_value_set_object (&value, task);
5831 gst_message_set_stream_status_object (message, &value);
5832 g_value_unset (&value);
5834 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5835 gst_element_post_message (parent, message);
5837 gst_object_unref (parent);
5842 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5844 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5849 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5851 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5856 * gst_pad_start_task:
5857 * @pad: the #GstPad to start the task of
5858 * @func: the task function to call
5859 * @user_data: user data passed to the task function
5860 * @notify: called when @user_data is no longer referenced
5862 * Starts a task that repeatedly calls @func with @user_data. This function
5863 * is mostly used in pad activation functions to start the dataflow.
5864 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5865 * before @func is called.
5867 * Returns: a %TRUE if the task could be started.
5870 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5871 GDestroyNotify notify)
5876 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5877 g_return_val_if_fail (func != NULL, FALSE);
5879 GST_DEBUG_OBJECT (pad, "start task");
5881 GST_OBJECT_LOCK (pad);
5882 task = GST_PAD_TASK (pad);
5884 task = gst_task_new (func, user_data, notify);
5885 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5886 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5887 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5888 GST_INFO_OBJECT (pad, "created task %p", task);
5889 GST_PAD_TASK (pad) = task;
5890 gst_object_ref (task);
5891 /* release lock to post the message */
5892 GST_OBJECT_UNLOCK (pad);
5894 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5896 gst_object_unref (task);
5898 GST_OBJECT_LOCK (pad);
5899 /* nobody else is supposed to have changed the pad now */
5900 if (GST_PAD_TASK (pad) != task)
5901 goto concurrent_stop;
5903 res = gst_task_set_state (task, GST_TASK_STARTED);
5904 GST_OBJECT_UNLOCK (pad);
5911 GST_OBJECT_UNLOCK (pad);
5917 * gst_pad_pause_task:
5918 * @pad: the #GstPad to pause the task of
5920 * Pause the task of @pad. This function will also wait until the
5921 * function executed by the task is finished if this function is not
5922 * called from the task function.
5924 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
5928 gst_pad_pause_task (GstPad * pad)
5933 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5935 GST_DEBUG_OBJECT (pad, "pause task");
5937 GST_OBJECT_LOCK (pad);
5938 task = GST_PAD_TASK (pad);
5941 res = gst_task_set_state (task, GST_TASK_PAUSED);
5942 GST_OBJECT_UNLOCK (pad);
5944 /* wait for task function to finish, this lock is recursive so it does nothing
5945 * when the pause is called from the task itself */
5946 GST_PAD_STREAM_LOCK (pad);
5947 GST_PAD_STREAM_UNLOCK (pad);
5953 GST_DEBUG_OBJECT (pad, "pad has no task");
5954 GST_OBJECT_UNLOCK (pad);
5960 * gst_pad_stop_task:
5961 * @pad: the #GstPad to stop the task of
5963 * Stop the task of @pad. This function will also make sure that the
5964 * function executed by the task will effectively stop if not called
5965 * from the GstTaskFunction.
5967 * This function will deadlock if called from the GstTaskFunction of
5968 * the task. Use gst_task_pause() instead.
5970 * Regardless of whether the pad has a task, the stream lock is acquired and
5971 * released so as to ensure that streaming through this pad has finished.
5973 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
5976 gst_pad_stop_task (GstPad * pad)
5981 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5983 GST_DEBUG_OBJECT (pad, "stop task");
5985 GST_OBJECT_LOCK (pad);
5986 task = GST_PAD_TASK (pad);
5989 GST_PAD_TASK (pad) = NULL;
5990 res = gst_task_set_state (task, GST_TASK_STOPPED);
5991 GST_OBJECT_UNLOCK (pad);
5993 GST_PAD_STREAM_LOCK (pad);
5994 GST_PAD_STREAM_UNLOCK (pad);
5996 if (!gst_task_join (task))
5999 gst_object_unref (task);
6005 GST_DEBUG_OBJECT (pad, "no task");
6006 GST_OBJECT_UNLOCK (pad);
6008 GST_PAD_STREAM_LOCK (pad);
6009 GST_PAD_STREAM_UNLOCK (pad);
6011 /* this is not an error */
6016 /* this is bad, possibly the application tried to join the task from
6017 * the task's thread. We install the task again so that it will be stopped
6018 * again from the right thread next time hopefully. */
6019 GST_OBJECT_LOCK (pad);
6020 GST_DEBUG_OBJECT (pad, "join failed");
6021 /* we can only install this task if there was no other task */
6022 if (GST_PAD_TASK (pad) == NULL)
6023 GST_PAD_TASK (pad) = task;
6024 GST_OBJECT_UNLOCK (pad);
6031 * gst_pad_probe_info_get_event:
6032 * @info: a #GstPadProbeInfo
6034 * Returns: (transfer none): The #GstEvent from the probe
6038 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6040 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6041 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6043 return GST_PAD_PROBE_INFO_EVENT (info);
6048 * gst_pad_probe_info_get_query:
6049 * @info: a #GstPadProbeInfo
6051 * Returns: (transfer none): The #GstQuery from the probe
6055 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6057 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6058 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6060 return GST_PAD_PROBE_INFO_QUERY (info);
6064 * gst_pad_probe_info_get_buffer:
6065 * @info: a #GstPadProbeInfo
6067 * Returns: (transfer none): The #GstBuffer from the probe
6071 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6073 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6075 return GST_PAD_PROBE_INFO_BUFFER (info);
6079 * gst_pad_probe_info_get_buffer_list:
6080 * @info: a #GstPadProbeInfo
6082 * Returns: (transfer none): The #GstBufferlist from the probe
6086 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6088 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6090 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6094 * gst_pad_get_last_flow_return:
6097 * Gets the #GstFlowReturn return from the last data passed by this pad.
6102 gst_pad_get_last_flow_return (GstPad * pad)
6106 GST_OBJECT_LOCK (pad);
6107 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6108 GST_OBJECT_UNLOCK (pad);