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.
25 * @short_description: Object contained by elements that allows links to
27 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
29 * A #GstElement is linked to other elements via "pads", which are extremely
30 * light-weight generic link points.
32 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
37 * happens when the element is created but it can also happen dynamically based
38 * on the data that the element is processing or based on the pads that the
39 * application requests.
41 * Pads without pad templates can be created with gst_pad_new(),
42 * which takes a direction and a name as an argument. If the name is %NULL,
43 * then a guaranteed unique name will be assigned to it.
45 * A #GstElement creating a pad will typically use the various
46 * gst_pad_set_*_function\() calls to register callbacks for events, queries or
47 * dataflow on the pads.
49 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
51 * After two pads are retrieved from an element by gst_element_get_static_pad(),
52 * the pads can be linked with gst_pad_link(). (For quick links,
53 * you can also use gst_element_link(), which will make the obvious
54 * link for you if it's straightforward.). Pads can be unlinked again with
55 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
58 * Before dataflow is possible on the pads, they need to be activated with
59 * gst_pad_set_active().
61 * gst_pad_query() and gst_pad_peer_query() can be used to query various
62 * properties of the pad and the stream.
64 * To send a #GstEvent on a pad, use gst_pad_send_event() and
65 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
66 * after they pass on the pad they can be queried later with
67 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
68 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
69 * functions to query the current sticky CAPS event on a pad.
71 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
72 * or pull in a buffer.
74 * The dataflow, events and queries that happen on a pad can be monitored with
75 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
76 * can be used to check if a block probe is installed on the pad.
77 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
78 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
79 * and unblock blocking probes if any.
81 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
82 * offset will be applied to the running_time of all data passing over the pad.
83 * gst_pad_set_offset() can be used to change the offset.
85 * Convenience functions exist to start, pause and stop the task on a pad with
86 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
90 #include "gst_private.h"
93 #include "gstpadtemplate.h"
94 #include "gstenumtypes.h"
98 #include "gsttracerutils.h"
100 #include "glib-compat-private.h"
102 #define GST_CAT_DEFAULT GST_CAT_PADS
104 /* Pad signals and args */
123 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
125 /* we have a pending and an active event on the pad. On source pads only the
126 * active event is used. On sinkpads, events are copied to the pending entry and
127 * moved to the active event when the eventfunc returned %TRUE. */
134 struct _GstPadPrivate
141 guint probe_list_cookie;
143 /* counter of how many idle probes are running directly from the add_probe
144 * call. Used to block any data flowing in the pad while the idle callback
145 * Doesn't finish its work */
148 /* conditional and variable used to ensure pads only get (de)activated
149 * by a single thread at a time. Protected by the object lock */
150 GCond activation_cond;
151 gboolean in_activation;
159 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
160 (((GstPad *)(p))->priv->idle_running > 0)
165 GstPadProbeInfo *info;
171 gulong *called_probes;
172 guint n_called_probes;
173 guint called_probes_size;
177 static void gst_pad_dispose (GObject * object);
178 static void gst_pad_finalize (GObject * object);
179 static void gst_pad_set_property (GObject * object, guint prop_id,
180 const GValue * value, GParamSpec * pspec);
181 static void gst_pad_get_property (GObject * object, guint prop_id,
182 GValue * value, GParamSpec * pspec);
184 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
185 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
186 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
187 GstObject * parent, GstBufferList * list);
189 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
190 GstEvent * event, GstPadProbeType type);
191 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
192 GstEvent * event, GstPadProbeType type);
194 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
195 GstPadMode mode, gboolean active);
197 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
199 static GParamSpec *pspec_caps = NULL;
201 /* quarks for probe signals */
202 static GQuark buffer_quark;
203 static GQuark buffer_list_quark;
204 static GQuark event_quark;
213 static GstFlowQuarks flow_quarks[] = {
214 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
215 {GST_FLOW_OK, "ok", 0},
216 {GST_FLOW_NOT_LINKED, "not-linked", 0},
217 {GST_FLOW_FLUSHING, "flushing", 0},
218 {GST_FLOW_EOS, "eos", 0},
219 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
220 {GST_FLOW_ERROR, "error", 0},
221 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
222 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
227 * @ret: a #GstFlowReturn to get the name of.
229 * Gets a string representing the given flow return.
231 * Returns: a static string with the name of the flow return.
234 gst_flow_get_name (GstFlowReturn ret)
238 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
240 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
241 if (ret == flow_quarks[i].ret)
242 return flow_quarks[i].name;
249 * @ret: a #GstFlowReturn to get the quark of.
251 * Get the unique quark for the given GstFlowReturn.
253 * Returns: the quark associated with the flow return or 0 if an
254 * invalid return was specified.
257 gst_flow_to_quark (GstFlowReturn ret)
261 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
263 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
264 if (ret == flow_quarks[i].ret)
265 return flow_quarks[i].quark;
271 * gst_pad_link_get_name:
272 * @ret: a #GstPadLinkReturn to get the name of.
274 * Gets a string representing the given pad-link return.
276 * Returns: a static string with the name of the pad-link return.
281 gst_pad_link_get_name (GstPadLinkReturn ret)
284 case GST_PAD_LINK_OK:
286 case GST_PAD_LINK_WRONG_HIERARCHY:
287 return "wrong hierarchy";
288 case GST_PAD_LINK_WAS_LINKED:
290 case GST_PAD_LINK_WRONG_DIRECTION:
291 return "wrong direction";
292 case GST_PAD_LINK_NOFORMAT:
293 return "no common format";
294 case GST_PAD_LINK_NOSCHED:
295 return "incompatible scheduling";
296 case GST_PAD_LINK_REFUSED:
299 g_return_val_if_reached ("unknown");
306 buffer_quark = g_quark_from_static_string ("buffer"); \
307 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
308 event_quark = g_quark_from_static_string ("event"); \
310 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
311 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
316 #define gst_pad_parent_class parent_class
317 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT,
318 G_ADD_PRIVATE (GstPad) _do_init);
321 gst_pad_class_init (GstPadClass * klass)
323 GObjectClass *gobject_class;
324 GstObjectClass *gstobject_class;
326 gobject_class = G_OBJECT_CLASS (klass);
327 gstobject_class = GST_OBJECT_CLASS (klass);
329 gobject_class->dispose = gst_pad_dispose;
330 gobject_class->finalize = gst_pad_finalize;
331 gobject_class->set_property = gst_pad_set_property;
332 gobject_class->get_property = gst_pad_get_property;
336 * @pad: the pad that emitted the signal
337 * @peer: the peer pad that has been connected
339 * Signals that a pad has been linked to the peer pad.
341 gst_pad_signals[PAD_LINKED] =
342 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
343 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
344 NULL, G_TYPE_NONE, 1, GST_TYPE_PAD);
347 * @pad: the pad that emitted the signal
348 * @peer: the peer pad that has been disconnected
350 * Signals that a pad has been unlinked from the peer pad.
352 gst_pad_signals[PAD_UNLINKED] =
353 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
354 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
355 NULL, G_TYPE_NONE, 1, GST_TYPE_PAD);
357 pspec_caps = g_param_spec_boxed ("caps", "Caps",
358 "The capabilities of the pad", GST_TYPE_CAPS,
359 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
360 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
362 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
363 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
364 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
365 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
367 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
368 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
369 g_param_spec_object ("template", "Template",
370 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
371 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
376 * The offset that will be applied to the running time of the pad.
380 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
381 g_param_spec_int64 ("offset", "Offset",
382 "The running time offset of the pad", 0, G_MAXINT64, 0,
383 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
385 gstobject_class->path_string_separator = ".";
387 /* Register common function pointer descriptions */
388 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
389 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
396 gst_pad_init (GstPad * pad)
398 pad->priv = gst_pad_get_instance_private (pad);
400 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
402 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
403 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
404 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
405 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
406 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
408 GST_PAD_SET_FLUSHING (pad);
410 g_rec_mutex_init (&pad->stream_rec_lock);
412 g_cond_init (&pad->block_cond);
414 g_hook_list_init (&pad->probes, sizeof (GstProbe));
416 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
417 pad->priv->events_cookie = 0;
418 pad->priv->last_cookie = -1;
419 g_cond_init (&pad->priv->activation_cond);
421 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
424 /* called when setting the pad inactive. It removes all sticky events from
425 * the pad. must be called with object lock */
427 remove_events (GstPad * pad)
431 gboolean notify = FALSE;
433 events = pad->priv->events;
436 for (i = 0; i < len; i++) {
437 PadEvent *ev = &g_array_index (events, PadEvent, i);
438 GstEvent *event = ev->event;
442 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
445 gst_event_unref (event);
448 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
449 g_array_set_size (events, 0);
450 pad->priv->events_cookie++;
453 GST_OBJECT_UNLOCK (pad);
455 GST_DEBUG_OBJECT (pad, "notify caps");
456 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
458 GST_OBJECT_LOCK (pad);
462 /* should be called with object lock */
464 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
470 events = pad->priv->events;
473 for (i = 0; i < len; i++) {
474 ev = &g_array_index (events, PadEvent, i);
475 if (ev->event == NULL)
478 if (GST_EVENT_TYPE (ev->event) == type) {
482 } else if (GST_EVENT_TYPE (ev->event) > type) {
491 /* should be called with OBJECT lock */
493 find_event (GstPad * pad, GstEvent * event)
499 events = pad->priv->events;
502 for (i = 0; i < len; i++) {
503 ev = &g_array_index (events, PadEvent, i);
504 if (event == ev->event)
506 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
514 /* should be called with OBJECT lock */
516 remove_event_by_type (GstPad * pad, GstEventType type)
522 events = pad->priv->events;
527 ev = &g_array_index (events, PadEvent, i);
528 if (ev->event == NULL)
531 if (GST_EVENT_TYPE (ev->event) > type)
533 else if (GST_EVENT_TYPE (ev->event) != type)
536 gst_event_unref (ev->event);
537 g_array_remove_index (events, i);
539 pad->priv->events_cookie++;
547 /* check all events on srcpad against those on sinkpad. All events that are not
548 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
549 * srcpad so that the events will be sent next time */
550 /* should be called with srcpad and sinkpad LOCKS */
552 schedule_events (GstPad * srcpad, GstPad * sinkpad)
557 gboolean pending = FALSE;
559 events = srcpad->priv->events;
562 for (i = 0; i < len; i++) {
563 ev = &g_array_index (events, PadEvent, i);
564 if (ev->event == NULL)
567 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
568 ev->received = FALSE;
573 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
576 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
579 /* should be called with pad LOCK */
581 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
588 events = pad->priv->events;
591 cookie = pad->priv->events_cookie;
595 PadEvent *ev, ev_ret;
597 ev = &g_array_index (events, PadEvent, i);
598 if (G_UNLIKELY (ev->event == NULL))
601 /* take additional ref, func might release the lock */
602 ev_ret.event = gst_event_ref (ev->event);
603 ev_ret.received = ev->received;
605 ret = func (pad, &ev_ret, user_data);
607 /* recheck the cookie, lock might have been released and the list could have
609 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
610 if (G_LIKELY (ev_ret.event))
611 gst_event_unref (ev_ret.event);
615 /* store the received state */
616 ev->received = ev_ret.received;
618 /* if the event changed, we need to do something */
619 if (G_UNLIKELY (ev->event != ev_ret.event)) {
620 if (G_UNLIKELY (ev_ret.event == NULL)) {
621 /* function unreffed and set the event to NULL, remove it */
622 gst_event_unref (ev->event);
623 g_array_remove_index (events, i);
625 cookie = ++pad->priv->events_cookie;
628 /* function gave a new event for us */
629 gst_event_take (&ev->event, ev_ret.event);
632 /* just unref, nothing changed */
633 gst_event_unref (ev_ret.event);
642 /* should be called with LOCK */
644 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream,
649 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
650 GST_STIME_ARGS (pad_offset));
652 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
655 g_assert (!upstream);
657 /* copy segment values */
658 gst_event_copy_segment (event, &segment);
659 gst_event_unref (event);
661 gst_segment_offset_running_time (&segment, segment.format, pad_offset);
662 event = gst_event_new_segment (&segment);
665 event = gst_event_make_writable (event);
666 offset = gst_event_get_running_time_offset (event);
668 offset -= pad_offset;
670 offset += pad_offset;
671 gst_event_set_running_time_offset (event, offset);
676 static inline GstEvent *
677 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
679 if (G_UNLIKELY (pad->offset != 0))
680 return _apply_pad_offset (pad, event, upstream, pad->offset);
684 /* should be called with the OBJECT_LOCK */
686 get_pad_caps (GstPad * pad)
688 GstCaps *caps = NULL;
691 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
693 gst_event_parse_caps (ev->event, &caps);
699 gst_pad_dispose (GObject * object)
701 GstPad *pad = GST_PAD_CAST (object);
704 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
706 /* unlink the peer pad */
707 if ((peer = gst_pad_get_peer (pad))) {
708 /* window for MT unsafeness, someone else could unlink here
709 * and then we call unlink with wrong pads. The unlink
710 * function would catch this and safely return failed. */
711 if (GST_PAD_IS_SRC (pad))
712 gst_pad_unlink (pad, peer);
714 gst_pad_unlink (peer, pad);
716 gst_object_unref (peer);
719 gst_pad_set_pad_template (pad, NULL);
721 GST_OBJECT_LOCK (pad);
723 g_hook_list_clear (&pad->probes);
724 GST_OBJECT_UNLOCK (pad);
726 G_OBJECT_CLASS (parent_class)->dispose (object);
730 gst_pad_finalize (GObject * object)
732 GstPad *pad = GST_PAD_CAST (object);
735 /* in case the task is still around, clean it up */
736 if ((task = GST_PAD_TASK (pad))) {
737 gst_task_join (task);
738 GST_PAD_TASK (pad) = NULL;
739 gst_object_unref (task);
742 if (pad->activatenotify)
743 pad->activatenotify (pad->activatedata);
744 if (pad->activatemodenotify)
745 pad->activatemodenotify (pad->activatemodedata);
747 pad->linknotify (pad->linkdata);
748 if (pad->unlinknotify)
749 pad->unlinknotify (pad->unlinkdata);
750 if (pad->chainnotify)
751 pad->chainnotify (pad->chaindata);
752 if (pad->chainlistnotify)
753 pad->chainlistnotify (pad->chainlistdata);
754 if (pad->getrangenotify)
755 pad->getrangenotify (pad->getrangedata);
756 if (pad->eventnotify)
757 pad->eventnotify (pad->eventdata);
758 if (pad->querynotify)
759 pad->querynotify (pad->querydata);
760 if (pad->iterintlinknotify)
761 pad->iterintlinknotify (pad->iterintlinkdata);
763 g_rec_mutex_clear (&pad->stream_rec_lock);
764 g_cond_clear (&pad->block_cond);
765 g_cond_clear (&pad->priv->activation_cond);
766 g_array_free (pad->priv->events, TRUE);
768 G_OBJECT_CLASS (parent_class)->finalize (object);
772 gst_pad_set_property (GObject * object, guint prop_id,
773 const GValue * value, GParamSpec * pspec)
775 g_return_if_fail (GST_IS_PAD (object));
778 case PAD_PROP_DIRECTION:
779 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
781 case PAD_PROP_TEMPLATE:
782 gst_pad_set_pad_template (GST_PAD_CAST (object),
783 (GstPadTemplate *) g_value_get_object (value));
785 case PAD_PROP_OFFSET:
786 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
789 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
795 gst_pad_get_property (GObject * object, guint prop_id,
796 GValue * value, GParamSpec * pspec)
798 g_return_if_fail (GST_IS_PAD (object));
802 GST_OBJECT_LOCK (object);
803 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
804 GST_OBJECT_UNLOCK (object);
806 case PAD_PROP_DIRECTION:
807 g_value_set_enum (value, GST_PAD_DIRECTION (object));
809 case PAD_PROP_TEMPLATE:
810 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
812 case PAD_PROP_OFFSET:
813 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
816 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
823 * @name: (allow-none): the name of the new pad.
824 * @direction: the #GstPadDirection of the pad.
826 * Creates a new pad with the given name in the given direction.
827 * If name is %NULL, a guaranteed unique name (across all pads)
829 * This function makes a copy of the name so you can safely free the name.
831 * Returns: (transfer floating): a new #GstPad.
836 gst_pad_new (const gchar * name, GstPadDirection direction)
838 return g_object_new (GST_TYPE_PAD,
839 "name", name, "direction", direction, NULL);
843 * gst_pad_new_from_template:
844 * @templ: the pad template to use
845 * @name: (allow-none): the name of the pad
847 * Creates a new pad with the given name from the given template.
848 * If name is %NULL, a guaranteed unique name (across all pads)
850 * This function makes a copy of the name so you can safely free the name.
852 * Returns: (transfer floating): a new #GstPad.
855 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
858 GST_PAD_TEMPLATE_GTYPE (templ) ==
859 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
861 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
863 return g_object_new (pad_type,
864 "name", name, "direction", templ->direction, "template", templ, NULL);
868 * gst_pad_new_from_static_template:
869 * @templ: the #GstStaticPadTemplate to use
870 * @name: the name of the pad
872 * Creates a new pad with the given name from the given static template.
873 * If name is %NULL, a guaranteed unique name (across all pads)
875 * This function makes a copy of the name so you can safely free the name.
877 * Returns: (transfer floating): a new #GstPad.
880 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
884 GstPadTemplate *template;
886 template = gst_static_pad_template_get (templ);
887 pad = gst_pad_new_from_template (template, name);
888 gst_object_unref (template);
892 #define ACQUIRE_PARENT(pad, parent, label) \
894 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
895 gst_object_ref (parent); \
896 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
900 #define RELEASE_PARENT(parent) \
902 if (G_LIKELY (parent)) \
903 gst_object_unref (parent); \
907 * gst_pad_get_direction:
908 * @pad: a #GstPad to get the direction of.
910 * Gets the direction of the pad. The direction of the pad is
911 * decided at construction time so this function does not take
914 * Returns: the #GstPadDirection of the pad.
919 gst_pad_get_direction (GstPad * pad)
921 GstPadDirection result;
923 /* PAD_UNKNOWN is a little silly but we need some sort of
924 * error return value */
925 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
927 result = GST_PAD_DIRECTION (pad);
933 gst_pad_activate_default (GstPad * pad, GstObject * parent)
935 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
937 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
941 * gst_pad_mode_get_name:
942 * @mode: the pad mode
944 * Return the name of a pad mode, for use in debug messages mostly.
946 * Returns: short mnemonic for pad mode @mode
949 gst_pad_mode_get_name (GstPadMode mode)
952 case GST_PAD_MODE_NONE:
954 case GST_PAD_MODE_PUSH:
956 case GST_PAD_MODE_PULL:
964 /* Returns TRUE if pad wasn't already in the new_mode */
966 pre_activate (GstPad * pad, GstPadMode new_mode)
969 case GST_PAD_MODE_NONE:
970 GST_OBJECT_LOCK (pad);
971 while (G_UNLIKELY (pad->priv->in_activation))
972 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
973 if (new_mode == GST_PAD_MODE (pad)) {
974 GST_WARNING_OBJECT (pad,
975 "Pad is already in the process of being deactivated");
976 GST_OBJECT_UNLOCK (pad);
979 pad->priv->in_activation = TRUE;
980 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
981 GST_PAD_SET_FLUSHING (pad);
982 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
983 GST_PAD_MODE (pad) = new_mode;
984 /* unlock blocked pads so element can resume and stop */
985 GST_PAD_BLOCK_BROADCAST (pad);
986 GST_OBJECT_UNLOCK (pad);
988 case GST_PAD_MODE_PUSH:
989 case GST_PAD_MODE_PULL:
990 GST_OBJECT_LOCK (pad);
991 while (G_UNLIKELY (pad->priv->in_activation))
992 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
993 if (new_mode == GST_PAD_MODE (pad)) {
994 GST_WARNING_OBJECT (pad,
995 "Pad is already in the process of being activated");
996 GST_OBJECT_UNLOCK (pad);
999 pad->priv->in_activation = TRUE;
1000 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1001 gst_pad_mode_get_name (new_mode));
1002 GST_PAD_UNSET_FLUSHING (pad);
1003 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1004 GST_PAD_MODE (pad) = new_mode;
1005 if (GST_PAD_IS_SINK (pad)) {
1007 /* make sure the peer src pad sends us all events */
1008 if ((peer = GST_PAD_PEER (pad))) {
1009 gst_object_ref (peer);
1010 GST_OBJECT_UNLOCK (pad);
1012 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1013 GST_DEBUG_PAD_NAME (peer));
1015 GST_OBJECT_LOCK (peer);
1016 schedule_events (peer, NULL);
1017 GST_OBJECT_UNLOCK (peer);
1019 gst_object_unref (peer);
1021 GST_OBJECT_UNLOCK (pad);
1024 GST_OBJECT_UNLOCK (pad);
1032 post_activate (GstPad * pad, GstPadMode new_mode)
1035 case GST_PAD_MODE_NONE:
1036 GST_OBJECT_LOCK (pad);
1037 pad->priv->in_activation = FALSE;
1038 g_cond_broadcast (&pad->priv->activation_cond);
1039 GST_OBJECT_UNLOCK (pad);
1041 /* ensures that streaming stops */
1042 GST_PAD_STREAM_LOCK (pad);
1043 GST_DEBUG_OBJECT (pad, "stopped streaming");
1044 GST_OBJECT_LOCK (pad);
1045 remove_events (pad);
1046 GST_OBJECT_UNLOCK (pad);
1047 GST_PAD_STREAM_UNLOCK (pad);
1049 case GST_PAD_MODE_PUSH:
1050 case GST_PAD_MODE_PULL:
1051 GST_OBJECT_LOCK (pad);
1052 pad->priv->in_activation = FALSE;
1053 g_cond_broadcast (&pad->priv->activation_cond);
1054 GST_OBJECT_UNLOCK (pad);
1061 * gst_pad_set_active:
1062 * @pad: the #GstPad to activate or deactivate.
1063 * @active: whether or not the pad should be active.
1065 * Activates or deactivates the given pad.
1066 * Normally called from within core state change functions.
1068 * If @active, makes sure the pad is active. If it is already active, either in
1069 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1070 * function to perform the actual activation.
1072 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1073 * and a %FALSE argument.
1075 * Returns: %TRUE if the operation was successful.
1080 gst_pad_set_active (GstPad * pad, gboolean active)
1084 gboolean ret = FALSE;
1086 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1088 GST_OBJECT_LOCK (pad);
1089 old = GST_PAD_MODE (pad);
1090 ACQUIRE_PARENT (pad, parent, no_parent);
1091 GST_OBJECT_UNLOCK (pad);
1094 if (old == GST_PAD_MODE_NONE) {
1095 GST_DEBUG_OBJECT (pad, "activating pad from none");
1096 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1098 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1100 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1101 gst_pad_mode_get_name (old));
1105 if (old == GST_PAD_MODE_NONE) {
1106 GST_DEBUG_OBJECT (pad, "pad was inactive");
1109 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1110 gst_pad_mode_get_name (old));
1111 ret = activate_mode_internal (pad, parent, old, FALSE);
1113 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1117 RELEASE_PARENT (parent);
1119 if (G_UNLIKELY (!ret))
1127 GST_DEBUG_OBJECT (pad, "no parent");
1128 GST_OBJECT_UNLOCK (pad);
1133 GST_OBJECT_LOCK (pad);
1135 g_critical ("Failed to deactivate pad %s:%s, very bad",
1136 GST_DEBUG_PAD_NAME (pad));
1138 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1140 GST_OBJECT_UNLOCK (pad);
1146 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1149 gboolean res = FALSE;
1150 GstPadMode old, new;
1151 GstPadDirection dir;
1154 GST_OBJECT_LOCK (pad);
1155 old = GST_PAD_MODE (pad);
1156 dir = GST_PAD_DIRECTION (pad);
1157 GST_OBJECT_UNLOCK (pad);
1159 new = active ? mode : GST_PAD_MODE_NONE;
1164 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1165 /* pad was activate in the wrong direction, deactivate it
1166 * and reactivate it in the requested mode */
1167 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1168 gst_pad_mode_get_name (old));
1170 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1171 goto deactivate_failed;
1172 old = GST_PAD_MODE_NONE;
1176 case GST_PAD_MODE_PULL:
1178 if (dir == GST_PAD_SINK) {
1179 if ((peer = gst_pad_get_peer (pad))) {
1180 GST_DEBUG_OBJECT (pad, "calling peer");
1181 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1183 gst_object_unref (peer);
1185 /* there is no peer, this is only fatal when we activate. When we
1186 * deactivate, we must assume the application has unlinked the peer and
1187 * will deactivate it eventually. */
1191 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1194 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1195 goto failure; /* Can't activate pull on a src without a
1196 getrange function */
1204 /* Mark pad as needing reconfiguration */
1206 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1208 /* pre_activate returns TRUE if we weren't already in the process of
1209 * switching to the 'new' mode */
1210 if (pre_activate (pad, new)) {
1212 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1213 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1217 /* can happen for sinks of passthrough elements */
1220 post_activate (pad, new);
1223 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1224 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1229 /* Clear sticky flags on deactivation */
1231 GST_OBJECT_LOCK (pad);
1232 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1233 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1234 GST_OBJECT_UNLOCK (pad);
1242 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1243 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1248 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1249 "failed to %s in switch to %s mode from %s mode",
1250 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1251 gst_pad_mode_get_name (old));
1256 GST_OBJECT_LOCK (peer);
1257 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1258 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1259 GST_OBJECT_UNLOCK (peer);
1260 gst_object_unref (peer);
1265 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1266 "pad in pull mode");
1271 GST_OBJECT_LOCK (pad);
1272 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1273 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1274 GST_PAD_SET_FLUSHING (pad);
1275 GST_PAD_MODE (pad) = old;
1276 pad->priv->in_activation = FALSE;
1277 g_cond_broadcast (&pad->priv->activation_cond);
1278 GST_OBJECT_UNLOCK (pad);
1284 * gst_pad_activate_mode:
1285 * @pad: the #GstPad to activate or deactivate.
1286 * @mode: the requested activation mode
1287 * @active: whether or not the pad should be active.
1289 * Activates or deactivates the given pad in @mode via dispatching to the
1290 * pad's activatemodefunc. For use from within pad activation functions only.
1292 * If you don't know what this is, you probably don't want to call it.
1294 * Returns: %TRUE if the operation was successful.
1299 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1303 GstPadMode old, new;
1305 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1307 GST_OBJECT_LOCK (pad);
1309 old = GST_PAD_MODE (pad);
1310 new = active ? mode : GST_PAD_MODE_NONE;
1314 ACQUIRE_PARENT (pad, parent, no_parent);
1316 GST_OBJECT_UNLOCK (pad);
1318 res = activate_mode_internal (pad, parent, mode, active);
1320 RELEASE_PARENT (parent);
1326 GST_OBJECT_UNLOCK (pad);
1327 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1328 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1333 GST_WARNING_OBJECT (pad, "no parent");
1334 GST_OBJECT_UNLOCK (pad);
1340 * gst_pad_is_active:
1341 * @pad: the #GstPad to query
1343 * Query if a pad is active
1345 * Returns: %TRUE if the pad is active.
1350 gst_pad_is_active (GstPad * pad)
1352 gboolean result = FALSE;
1354 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1356 GST_OBJECT_LOCK (pad);
1357 result = GST_PAD_IS_ACTIVE (pad);
1358 GST_OBJECT_UNLOCK (pad);
1364 cleanup_hook (GstPad * pad, GHook * hook)
1366 GstPadProbeType type;
1368 GST_DEBUG_OBJECT (pad,
1369 "cleaning up hook %lu with flags %08x", hook->hook_id, hook->flags);
1371 if (!G_HOOK_IS_VALID (hook)) {
1372 /* We've already destroyed this hook */
1376 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1378 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1379 /* unblock when we remove the last blocking probe */
1381 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1384 /* Might have new probes now that want to be called */
1385 GST_PAD_BLOCK_BROADCAST (pad);
1387 if (pad->num_blocked == 0) {
1388 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1389 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1392 g_hook_destroy_link (&pad->probes, hook);
1397 * gst_pad_add_probe:
1398 * @pad: the #GstPad to add the probe to
1399 * @mask: the probe mask
1400 * @callback: #GstPadProbeCallback that will be called with notifications of
1402 * @user_data: (closure): user data passed to the callback
1403 * @destroy_data: #GDestroyNotify for user_data
1405 * Be notified of different states of pads. The provided callback is called for
1406 * every state that matches @mask.
1408 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1409 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1410 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1411 * immediately if the pad is already idle while calling gst_pad_add_probe().
1412 * In each of the groups, probes are called in the order in which they were
1415 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1416 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1417 * happen that the probe can be run immediately and if the probe returns
1418 * GST_PAD_PROBE_REMOVE this functions returns 0.
1423 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1424 GstPadProbeCallback callback, gpointer user_data,
1425 GDestroyNotify destroy_data)
1430 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1431 g_return_val_if_fail (mask != 0, 0);
1433 GST_OBJECT_LOCK (pad);
1435 /* make a new probe */
1436 hook = g_hook_alloc (&pad->probes);
1438 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1441 /* when no constraints are given for the types, assume all types are
1443 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1444 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1445 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1446 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1448 /* store our flags and other fields */
1449 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1450 hook->func = callback;
1451 hook->data = user_data;
1452 hook->destroy = destroy_data;
1455 g_hook_append (&pad->probes, hook);
1457 /* incremenent cookie so that the new hook gets called */
1458 pad->priv->probe_list_cookie++;
1460 /* get the id of the hook, we return this and it can be used to remove the
1462 res = hook->hook_id;
1464 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1466 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1467 /* we have a block probe */
1469 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1470 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1471 "now %d blocking probes", pad->num_blocked);
1473 /* Might have new probes now that want to be called */
1474 GST_PAD_BLOCK_BROADCAST (pad);
1477 /* call the callback if we need to be called for idle callbacks */
1478 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1479 if (pad->priv->using > 0) {
1480 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1481 * flag above, the last thread to leave the push will do the callback. New
1482 * threads going into the push will block. */
1483 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1484 "pad is in use, delay idle callback");
1485 GST_OBJECT_UNLOCK (pad);
1487 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1488 GstPadProbeReturn ret;
1490 /* Keep another ref, the callback could destroy the pad */
1491 gst_object_ref (pad);
1492 pad->priv->idle_running++;
1494 /* Ref the hook, it could be destroyed by the callback or concurrently */
1495 g_hook_ref (&pad->probes, hook);
1497 /* the pad is idle now, we can signal the idle callback now */
1498 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1499 "pad is idle, trigger idle callback");
1500 GST_OBJECT_UNLOCK (pad);
1502 ret = callback (pad, &info, user_data);
1504 GST_OBJECT_LOCK (pad);
1506 case GST_PAD_PROBE_REMOVE:
1507 /* remove the probe */
1508 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1509 cleanup_hook (pad, hook);
1512 case GST_PAD_PROBE_DROP:
1513 GST_DEBUG_OBJECT (pad, "asked to drop item");
1515 case GST_PAD_PROBE_PASS:
1516 GST_DEBUG_OBJECT (pad, "asked to pass item");
1518 case GST_PAD_PROBE_OK:
1519 GST_DEBUG_OBJECT (pad, "probe returned OK");
1521 case GST_PAD_PROBE_HANDLED:
1522 GST_DEBUG_OBJECT (pad, "probe handled the data");
1525 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1528 g_hook_unref (&pad->probes, hook);
1529 pad->priv->idle_running--;
1530 if (pad->priv->idle_running == 0) {
1531 GST_PAD_BLOCK_BROADCAST (pad);
1533 GST_OBJECT_UNLOCK (pad);
1535 gst_object_unref (pad);
1538 GST_OBJECT_UNLOCK (pad);
1544 * gst_pad_remove_probe:
1545 * @pad: the #GstPad with the probe
1546 * @id: the probe id to remove
1548 * Remove the probe with @id from @pad.
1553 gst_pad_remove_probe (GstPad * pad, gulong id)
1557 g_return_if_fail (GST_IS_PAD (pad));
1559 GST_OBJECT_LOCK (pad);
1561 hook = g_hook_get (&pad->probes, id);
1565 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1567 cleanup_hook (pad, hook);
1568 GST_OBJECT_UNLOCK (pad);
1574 GST_OBJECT_UNLOCK (pad);
1575 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1581 * gst_pad_is_blocked:
1582 * @pad: the #GstPad to query
1584 * Checks if the pad is blocked or not. This function returns the
1585 * last requested state of the pad. It is not certain that the pad
1586 * is actually blocking at this point (see gst_pad_is_blocking()).
1588 * Returns: %TRUE if the pad is blocked.
1593 gst_pad_is_blocked (GstPad * pad)
1595 gboolean result = FALSE;
1597 g_return_val_if_fail (GST_IS_PAD (pad), result);
1599 GST_OBJECT_LOCK (pad);
1600 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1601 GST_OBJECT_UNLOCK (pad);
1607 * gst_pad_is_blocking:
1608 * @pad: the #GstPad to query
1610 * Checks if the pad is blocking or not. This is a guaranteed state
1611 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1613 * Returns: %TRUE if the pad is blocking.
1618 gst_pad_is_blocking (GstPad * pad)
1620 gboolean result = FALSE;
1622 g_return_val_if_fail (GST_IS_PAD (pad), result);
1624 GST_OBJECT_LOCK (pad);
1625 /* the blocking flag is only valid if the pad is not flushing */
1626 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1627 GST_OBJECT_UNLOCK (pad);
1633 * gst_pad_needs_reconfigure:
1634 * @pad: the #GstPad to check
1636 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1637 * if the flag was set.
1639 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1642 gst_pad_needs_reconfigure (GstPad * pad)
1644 gboolean reconfigure;
1646 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1648 GST_OBJECT_LOCK (pad);
1649 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1650 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1651 GST_OBJECT_UNLOCK (pad);
1657 * gst_pad_check_reconfigure:
1658 * @pad: the #GstPad to check
1660 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1661 * if the flag was set.
1663 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1666 gst_pad_check_reconfigure (GstPad * pad)
1668 gboolean reconfigure;
1670 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1672 GST_OBJECT_LOCK (pad);
1673 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1675 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1676 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1678 GST_OBJECT_UNLOCK (pad);
1684 * gst_pad_mark_reconfigure:
1685 * @pad: the #GstPad to mark
1687 * Mark a pad for needing reconfiguration. The next call to
1688 * gst_pad_check_reconfigure() will return %TRUE after this call.
1691 gst_pad_mark_reconfigure (GstPad * pad)
1693 g_return_if_fail (GST_IS_PAD (pad));
1695 GST_OBJECT_LOCK (pad);
1696 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1697 GST_OBJECT_UNLOCK (pad);
1701 * gst_pad_set_activate_function:
1703 * @f: the #GstPadActivateFunction to set.
1705 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1709 * gst_pad_set_activate_function_full:
1711 * @activate: the #GstPadActivateFunction to set.
1712 * @user_data: user_data passed to @notify
1713 * @notify: notify called when @activate will not be used anymore.
1715 * Sets the given activate function for @pad. The activate function will
1716 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1717 * Only makes sense to set on sink pads.
1719 * Call this function if your sink pad can start a pull-based task.
1722 gst_pad_set_activate_function_full (GstPad * pad,
1723 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1725 g_return_if_fail (GST_IS_PAD (pad));
1727 if (pad->activatenotify)
1728 pad->activatenotify (pad->activatedata);
1729 GST_PAD_ACTIVATEFUNC (pad) = activate;
1730 pad->activatedata = user_data;
1731 pad->activatenotify = notify;
1733 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1734 GST_DEBUG_FUNCPTR_NAME (activate));
1738 * gst_pad_set_activatemode_function:
1740 * @f: the #GstPadActivateModeFunction to set.
1742 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1746 * gst_pad_set_activatemode_function_full:
1748 * @activatemode: the #GstPadActivateModeFunction to set.
1749 * @user_data: user_data passed to @notify
1750 * @notify: notify called when @activatemode will not be used anymore.
1752 * Sets the given activate_mode function for the pad. An activate_mode function
1753 * prepares the element for data passing.
1756 gst_pad_set_activatemode_function_full (GstPad * pad,
1757 GstPadActivateModeFunction activatemode, gpointer user_data,
1758 GDestroyNotify notify)
1760 g_return_if_fail (GST_IS_PAD (pad));
1762 if (pad->activatemodenotify)
1763 pad->activatemodenotify (pad->activatemodedata);
1764 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1765 pad->activatemodedata = user_data;
1766 pad->activatemodenotify = notify;
1768 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1769 GST_DEBUG_FUNCPTR_NAME (activatemode));
1773 * gst_pad_set_chain_function:
1774 * @p: a sink #GstPad.
1775 * @f: the #GstPadChainFunction to set.
1777 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1781 * gst_pad_set_chain_function_full:
1782 * @pad: a sink #GstPad.
1783 * @chain: the #GstPadChainFunction to set.
1784 * @user_data: user_data passed to @notify
1785 * @notify: notify called when @chain will not be used anymore.
1787 * Sets the given chain function for the pad. The chain function is called to
1788 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1791 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1792 gpointer user_data, GDestroyNotify notify)
1794 g_return_if_fail (GST_IS_PAD (pad));
1795 g_return_if_fail (GST_PAD_IS_SINK (pad));
1797 if (pad->chainnotify)
1798 pad->chainnotify (pad->chaindata);
1799 GST_PAD_CHAINFUNC (pad) = chain;
1800 pad->chaindata = user_data;
1801 pad->chainnotify = notify;
1803 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1804 GST_DEBUG_FUNCPTR_NAME (chain));
1808 * gst_pad_set_chain_list_function:
1809 * @p: a sink #GstPad.
1810 * @f: the #GstPadChainListFunction to set.
1812 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1816 * gst_pad_set_chain_list_function_full:
1817 * @pad: a sink #GstPad.
1818 * @chainlist: the #GstPadChainListFunction to set.
1819 * @user_data: user_data passed to @notify
1820 * @notify: notify called when @chainlist will not be used anymore.
1822 * Sets the given chain list function for the pad. The chainlist function is
1823 * called to process a #GstBufferList input buffer list. See
1824 * #GstPadChainListFunction for more details.
1827 gst_pad_set_chain_list_function_full (GstPad * pad,
1828 GstPadChainListFunction chainlist, gpointer user_data,
1829 GDestroyNotify notify)
1831 g_return_if_fail (GST_IS_PAD (pad));
1832 g_return_if_fail (GST_PAD_IS_SINK (pad));
1834 if (pad->chainlistnotify)
1835 pad->chainlistnotify (pad->chainlistdata);
1836 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1837 pad->chainlistdata = user_data;
1838 pad->chainlistnotify = notify;
1840 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1841 GST_DEBUG_FUNCPTR_NAME (chainlist));
1845 * gst_pad_set_getrange_function:
1846 * @p: a source #GstPad.
1847 * @f: the #GstPadGetRangeFunction to set.
1849 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1853 * gst_pad_set_getrange_function_full:
1854 * @pad: a source #GstPad.
1855 * @get: the #GstPadGetRangeFunction to set.
1856 * @user_data: user_data passed to @notify
1857 * @notify: notify called when @get will not be used anymore.
1859 * Sets the given getrange function for the pad. The getrange function is
1860 * called to produce a new #GstBuffer to start the processing pipeline. see
1861 * #GstPadGetRangeFunction for a description of the getrange function.
1864 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1865 gpointer user_data, GDestroyNotify notify)
1867 g_return_if_fail (GST_IS_PAD (pad));
1868 g_return_if_fail (GST_PAD_IS_SRC (pad));
1870 if (pad->getrangenotify)
1871 pad->getrangenotify (pad->getrangedata);
1872 GST_PAD_GETRANGEFUNC (pad) = get;
1873 pad->getrangedata = user_data;
1874 pad->getrangenotify = notify;
1876 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1877 GST_DEBUG_FUNCPTR_NAME (get));
1881 * gst_pad_set_event_function:
1882 * @p: a #GstPad of either direction.
1883 * @f: the #GstPadEventFunction to set.
1885 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1889 * gst_pad_set_event_function_full:
1890 * @pad: a #GstPad of either direction.
1891 * @event: the #GstPadEventFunction to set.
1892 * @user_data: user_data passed to @notify
1893 * @notify: notify called when @event will not be used anymore.
1895 * Sets the given event handler for the pad.
1898 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1899 gpointer user_data, GDestroyNotify notify)
1901 g_return_if_fail (GST_IS_PAD (pad));
1903 if (pad->eventnotify)
1904 pad->eventnotify (pad->eventdata);
1905 GST_PAD_EVENTFUNC (pad) = event;
1906 pad->eventdata = user_data;
1907 pad->eventnotify = notify;
1909 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1910 GST_DEBUG_FUNCPTR_NAME (event));
1914 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1918 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1919 if (ret == GST_FLOW_OK)
1925 * gst_pad_set_event_full_function:
1926 * @p: a #GstPad of either direction.
1927 * @f: the #GstPadEventFullFunction to set.
1929 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1933 * gst_pad_set_event_full_function_full:
1934 * @pad: a #GstPad of either direction.
1935 * @event: the #GstPadEventFullFunction to set.
1936 * @user_data: user_data passed to @notify
1937 * @notify: notify called when @event will not be used anymore.
1939 * Sets the given event handler for the pad.
1944 gst_pad_set_event_full_function_full (GstPad * pad,
1945 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1947 g_return_if_fail (GST_IS_PAD (pad));
1949 if (pad->eventnotify)
1950 pad->eventnotify (pad->eventdata);
1951 GST_PAD_EVENTFULLFUNC (pad) = event;
1952 GST_PAD_EVENTFUNC (pad) = event_wrap;
1953 pad->eventdata = user_data;
1954 pad->eventnotify = notify;
1956 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1957 GST_DEBUG_FUNCPTR_NAME (event));
1961 * gst_pad_set_query_function:
1962 * @p: a #GstPad of either direction.
1963 * @f: the #GstPadQueryFunction to set.
1965 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1969 * gst_pad_set_query_function_full:
1970 * @pad: a #GstPad of either direction.
1971 * @query: the #GstPadQueryFunction to set.
1972 * @user_data: user_data passed to @notify
1973 * @notify: notify called when @query will not be used anymore.
1975 * Set the given query function for the pad.
1978 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1979 gpointer user_data, GDestroyNotify notify)
1981 g_return_if_fail (GST_IS_PAD (pad));
1983 if (pad->querynotify)
1984 pad->querynotify (pad->querydata);
1985 GST_PAD_QUERYFUNC (pad) = query;
1986 pad->querydata = user_data;
1987 pad->querynotify = notify;
1989 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1990 GST_DEBUG_FUNCPTR_NAME (query));
1994 * gst_pad_set_iterate_internal_links_function:
1995 * @p: a #GstPad of either direction.
1996 * @f: the #GstPadIterIntLinkFunction to set.
1998 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1999 * for the user_data and notify.
2002 * gst_pad_set_iterate_internal_links_function_full:
2003 * @pad: a #GstPad of either direction.
2004 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2005 * @user_data: user_data passed to @notify
2006 * @notify: notify called when @iterintlink will not be used anymore.
2008 * Sets the given internal link iterator function for the pad.
2011 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2012 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2013 GDestroyNotify notify)
2015 g_return_if_fail (GST_IS_PAD (pad));
2017 if (pad->iterintlinknotify)
2018 pad->iterintlinknotify (pad->iterintlinkdata);
2019 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2020 pad->iterintlinkdata = user_data;
2021 pad->iterintlinknotify = notify;
2023 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2024 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2028 * gst_pad_set_link_function:
2030 * @f: the #GstPadLinkFunction to set.
2032 * Calls gst_pad_set_link_function_full() with %NULL
2033 * for the user_data and notify.
2036 * gst_pad_set_link_function_full:
2038 * @link: the #GstPadLinkFunction to set.
2039 * @user_data: user_data passed to @notify
2040 * @notify: notify called when @link will not be used anymore.
2042 * Sets the given link function for the pad. It will be called when
2043 * the pad is linked with another pad.
2045 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2048 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2049 * cannot be made for some reason.
2051 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2052 * of the peer sink pad, if present.
2055 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2056 gpointer user_data, GDestroyNotify notify)
2058 g_return_if_fail (GST_IS_PAD (pad));
2060 if (pad->linknotify)
2061 pad->linknotify (pad->linkdata);
2062 GST_PAD_LINKFUNC (pad) = link;
2063 pad->linkdata = user_data;
2064 pad->linknotify = notify;
2066 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2067 GST_DEBUG_FUNCPTR_NAME (link));
2071 * gst_pad_set_unlink_function:
2073 * @f: the #GstPadUnlinkFunction to set.
2075 * Calls gst_pad_set_unlink_function_full() with %NULL
2076 * for the user_data and notify.
2079 * gst_pad_set_unlink_function_full:
2081 * @unlink: the #GstPadUnlinkFunction to set.
2082 * @user_data: user_data passed to @notify
2083 * @notify: notify called when @unlink will not be used anymore.
2085 * Sets the given unlink function for the pad. It will be called
2086 * when the pad is unlinked.
2088 * Note that the pad's lock is already held when the unlink
2089 * function is called, so most pad functions cannot be called
2090 * from within the callback.
2093 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2094 gpointer user_data, GDestroyNotify notify)
2096 g_return_if_fail (GST_IS_PAD (pad));
2098 if (pad->unlinknotify)
2099 pad->unlinknotify (pad->unlinkdata);
2100 GST_PAD_UNLINKFUNC (pad) = unlink;
2101 pad->unlinkdata = user_data;
2102 pad->unlinknotify = notify;
2104 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2105 GST_DEBUG_FUNCPTR_NAME (unlink));
2110 * @srcpad: the source #GstPad to unlink.
2111 * @sinkpad: the sink #GstPad to unlink.
2113 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2114 * signal on both pads.
2116 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2117 * the pads were not linked together.
2122 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2124 gboolean result = FALSE;
2125 GstElement *parent = NULL;
2127 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2128 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2129 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2130 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2132 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2134 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2135 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2136 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2138 /* We need to notify the parent before taking any pad locks as the bin in
2139 * question might be waiting for a lock on the pad while holding its lock
2140 * that our message will try to take. */
2141 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2142 if (GST_IS_ELEMENT (parent)) {
2143 gst_element_post_message (parent,
2144 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2145 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2147 gst_object_unref (parent);
2152 GST_OBJECT_LOCK (srcpad);
2153 GST_OBJECT_LOCK (sinkpad);
2155 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2156 goto not_linked_together;
2158 if (GST_PAD_UNLINKFUNC (srcpad)) {
2159 GstObject *tmpparent;
2161 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2163 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2164 RELEASE_PARENT (tmpparent);
2167 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2168 GstObject *tmpparent;
2170 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2172 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2173 RELEASE_PARENT (tmpparent);
2177 /* first clear peers */
2178 GST_PAD_PEER (srcpad) = NULL;
2179 GST_PAD_PEER (sinkpad) = NULL;
2181 GST_OBJECT_UNLOCK (sinkpad);
2182 GST_OBJECT_UNLOCK (srcpad);
2184 /* fire off a signal to each of the pads telling them
2185 * that they've been unlinked */
2186 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2187 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2189 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2190 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2195 if (parent != NULL) {
2196 gst_element_post_message (parent,
2197 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2198 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2199 gst_object_unref (parent);
2201 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2205 not_linked_together:
2207 /* we do not emit a warning in this case because unlinking cannot
2208 * be made MT safe.*/
2209 GST_OBJECT_UNLOCK (sinkpad);
2210 GST_OBJECT_UNLOCK (srcpad);
2216 * gst_pad_is_linked:
2217 * @pad: pad to check
2219 * Checks if a @pad is linked to another pad or not.
2221 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2226 gst_pad_is_linked (GstPad * pad)
2230 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2232 GST_OBJECT_LOCK (pad);
2233 result = (GST_PAD_PEER (pad) != NULL);
2234 GST_OBJECT_UNLOCK (pad);
2239 /* get the caps from both pads and see if the intersection
2242 * This function should be called with the pad LOCK on both
2246 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2247 GstPadLinkCheck flags)
2249 GstCaps *srccaps = NULL;
2250 GstCaps *sinkcaps = NULL;
2251 gboolean compatible = FALSE;
2253 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2256 /* Doing the expensive caps checking takes priority over only checking the template caps */
2257 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2258 GST_OBJECT_UNLOCK (sink);
2259 GST_OBJECT_UNLOCK (src);
2261 srccaps = gst_pad_query_caps (src, NULL);
2262 sinkcaps = gst_pad_query_caps (sink, NULL);
2264 GST_OBJECT_LOCK (src);
2265 GST_OBJECT_LOCK (sink);
2267 /* If one of the two pads doesn't have a template, consider the intersection
2269 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2270 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2274 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2276 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2279 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2281 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2284 /* if we have caps on both pads we can check the intersection. If one
2285 * of the caps is %NULL, we return %TRUE. */
2286 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2288 gst_caps_unref (srccaps);
2290 gst_caps_unref (sinkcaps);
2294 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2295 gst_caps_unref (srccaps);
2296 gst_caps_unref (sinkcaps);
2299 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2300 (compatible ? "" : "not "));
2305 /* check if the grandparents of both pads are the same.
2306 * This check is required so that we don't try to link
2307 * pads from elements in different bins without ghostpads.
2309 * The LOCK should be held on both pads
2312 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2314 GstObject *psrc, *psink;
2316 psrc = GST_OBJECT_PARENT (src);
2317 psink = GST_OBJECT_PARENT (sink);
2319 /* if one of the pads has no parent, we allow the link */
2320 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2323 /* only care about parents that are elements */
2324 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2325 goto no_element_parent;
2327 /* if the parents are the same, we have a loop */
2328 if (G_UNLIKELY (psrc == psink))
2331 /* if they both have a parent, we check the grandparents. We can not lock
2332 * the parent because we hold on the child (pad) and the locking order is
2333 * parent >> child. */
2334 psrc = GST_OBJECT_PARENT (psrc);
2335 psink = GST_OBJECT_PARENT (psink);
2337 /* if they have grandparents but they are not the same */
2338 if (G_UNLIKELY (psrc != psink))
2339 goto wrong_grandparents;
2346 GST_CAT_DEBUG (GST_CAT_CAPS,
2347 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2348 GST_PTR_FORMAT, psrc, psink);
2353 GST_CAT_DEBUG (GST_CAT_CAPS,
2354 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2355 GST_PTR_FORMAT, psrc, psink);
2360 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2366 GST_CAT_DEBUG (GST_CAT_CAPS,
2367 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2368 GST_PTR_FORMAT, psrc, psink);
2373 /* FIXME leftover from an attempt at refactoring... */
2374 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2375 * the two pads will be locked in the srcpad, sinkpad order. */
2376 static GstPadLinkReturn
2377 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2379 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2380 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2382 GST_OBJECT_LOCK (srcpad);
2384 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2385 goto src_was_linked;
2387 GST_OBJECT_LOCK (sinkpad);
2389 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2390 goto sink_was_linked;
2392 /* check hierarchy, pads can only be linked if the grandparents
2394 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2395 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2396 goto wrong_hierarchy;
2398 /* check pad caps for non-empty intersection */
2399 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2402 /* FIXME check pad scheduling for non-empty intersection */
2404 return GST_PAD_LINK_OK;
2408 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2409 GST_DEBUG_PAD_NAME (srcpad),
2410 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2411 /* we do not emit a warning in this case because unlinking cannot
2412 * be made MT safe.*/
2413 GST_OBJECT_UNLOCK (srcpad);
2414 return GST_PAD_LINK_WAS_LINKED;
2418 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2419 GST_DEBUG_PAD_NAME (sinkpad),
2420 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2421 /* we do not emit a warning in this case because unlinking cannot
2422 * be made MT safe.*/
2423 GST_OBJECT_UNLOCK (sinkpad);
2424 GST_OBJECT_UNLOCK (srcpad);
2425 return GST_PAD_LINK_WAS_LINKED;
2429 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2430 GST_OBJECT_UNLOCK (sinkpad);
2431 GST_OBJECT_UNLOCK (srcpad);
2432 return GST_PAD_LINK_WRONG_HIERARCHY;
2436 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2437 GST_OBJECT_UNLOCK (sinkpad);
2438 GST_OBJECT_UNLOCK (srcpad);
2439 return GST_PAD_LINK_NOFORMAT;
2445 * @srcpad: the source #GstPad.
2446 * @sinkpad: the sink #GstPad.
2448 * Checks if the source pad and the sink pad are compatible so they can be
2451 * Returns: %TRUE if the pads can be linked.
2454 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2456 GstPadLinkReturn result;
2458 /* generic checks */
2459 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2460 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2462 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2463 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2465 /* gst_pad_link_prepare does everything for us, we only release the locks
2466 * on the pads that it gets us. If this function returns !OK the locks are not
2468 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2469 if (result != GST_PAD_LINK_OK)
2472 GST_OBJECT_UNLOCK (srcpad);
2473 GST_OBJECT_UNLOCK (sinkpad);
2476 return result == GST_PAD_LINK_OK;
2480 * gst_pad_link_full:
2481 * @srcpad: the source #GstPad to link.
2482 * @sinkpad: the sink #GstPad to link.
2483 * @flags: the checks to validate when linking
2485 * Links the source pad and the sink pad.
2487 * This variant of #gst_pad_link provides a more granular control on the
2488 * checks being done when linking. While providing some considerable speedups
2489 * the caller of this method must be aware that wrong usage of those flags
2490 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2491 * for more information.
2495 * Returns: A result code indicating if the connection worked or
2499 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2501 GstPadLinkReturn result;
2503 GstPadLinkFunction srcfunc, sinkfunc;
2505 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2506 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2507 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2508 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2509 GST_PAD_LINK_WRONG_DIRECTION);
2511 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2513 /* Notify the parent early. See gst_pad_unlink for details. */
2514 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2515 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2516 gst_element_post_message (parent,
2517 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2518 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2520 gst_object_unref (parent);
2525 /* prepare will also lock the two pads */
2526 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2528 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2529 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2530 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2531 gst_pad_link_get_name (result));
2535 /* must set peers before calling the link function */
2536 GST_PAD_PEER (srcpad) = sinkpad;
2537 GST_PAD_PEER (sinkpad) = srcpad;
2539 /* check events, when something is different, mark pending */
2540 schedule_events (srcpad, sinkpad);
2542 /* get the link functions */
2543 srcfunc = GST_PAD_LINKFUNC (srcpad);
2544 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2546 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2547 /* custom link functions, execute them */
2548 GST_OBJECT_UNLOCK (sinkpad);
2549 GST_OBJECT_UNLOCK (srcpad);
2552 GstObject *tmpparent;
2554 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2555 /* this one will call the peer link function */
2556 result = srcfunc (srcpad, tmpparent, sinkpad);
2557 RELEASE_PARENT (tmpparent);
2558 } else if (sinkfunc) {
2559 GstObject *tmpparent;
2561 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2562 /* if no source link function, we need to call the sink link
2563 * function ourselves. */
2564 result = sinkfunc (sinkpad, tmpparent, srcpad);
2565 RELEASE_PARENT (tmpparent);
2569 GST_OBJECT_LOCK (srcpad);
2570 GST_OBJECT_LOCK (sinkpad);
2572 /* we released the lock, check if the same pads are linked still */
2573 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2574 goto concurrent_link;
2576 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2579 GST_OBJECT_UNLOCK (sinkpad);
2580 GST_OBJECT_UNLOCK (srcpad);
2582 /* fire off a signal to each of the pads telling them
2583 * that they've been linked */
2584 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2585 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2587 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2588 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2590 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2591 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2594 if (G_LIKELY (parent)) {
2595 gst_element_post_message (parent,
2596 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2597 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2598 gst_object_unref (parent);
2601 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2607 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2608 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2609 GST_OBJECT_UNLOCK (sinkpad);
2610 GST_OBJECT_UNLOCK (srcpad);
2612 /* The other link operation succeeded first */
2613 result = GST_PAD_LINK_WAS_LINKED;
2618 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2619 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2620 gst_pad_link_get_name (result));
2622 GST_PAD_PEER (srcpad) = NULL;
2623 GST_PAD_PEER (sinkpad) = NULL;
2625 GST_OBJECT_UNLOCK (sinkpad);
2626 GST_OBJECT_UNLOCK (srcpad);
2634 * @srcpad: the source #GstPad to link.
2635 * @sinkpad: the sink #GstPad to link.
2637 * Links the source pad and the sink pad.
2639 * Returns: A result code indicating if the connection worked or
2645 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2647 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2651 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2653 GstPadTemplate **template_p;
2655 /* this function would need checks if it weren't static */
2657 GST_OBJECT_LOCK (pad);
2658 template_p = &pad->padtemplate;
2659 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2660 GST_OBJECT_UNLOCK (pad);
2663 gst_pad_template_pad_created (templ, pad);
2667 * gst_pad_get_pad_template:
2670 * Gets the template for @pad.
2672 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2673 * this pad was instantiated, or %NULL if this pad has no
2674 * template. Unref after usage.
2677 gst_pad_get_pad_template (GstPad * pad)
2679 GstPadTemplate *templ;
2681 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2683 templ = GST_PAD_PAD_TEMPLATE (pad);
2685 return (templ ? gst_object_ref (templ) : NULL);
2689 * gst_pad_has_current_caps:
2690 * @pad: a #GstPad to check
2692 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2694 * Returns: %TRUE when @pad has caps associated with it.
2697 gst_pad_has_current_caps (GstPad * pad)
2702 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2704 GST_OBJECT_LOCK (pad);
2705 caps = get_pad_caps (pad);
2706 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2707 "check current pad caps %" GST_PTR_FORMAT, caps);
2708 result = (caps != NULL);
2709 GST_OBJECT_UNLOCK (pad);
2715 * gst_pad_get_current_caps:
2716 * @pad: a #GstPad to get the current capabilities of.
2718 * Gets the capabilities currently configured on @pad with the last
2719 * #GST_EVENT_CAPS event.
2721 * Returns: (transfer full) (nullable): the current caps of the pad with
2722 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2725 gst_pad_get_current_caps (GstPad * pad)
2729 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2731 GST_OBJECT_LOCK (pad);
2732 if ((result = get_pad_caps (pad)))
2733 gst_caps_ref (result);
2734 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2735 "get current pad caps %" GST_PTR_FORMAT, result);
2736 GST_OBJECT_UNLOCK (pad);
2742 * gst_pad_get_pad_template_caps:
2743 * @pad: a #GstPad to get the template capabilities from.
2745 * Gets the capabilities for @pad's template.
2747 * Returns: (transfer full): the #GstCaps of this pad template.
2748 * Unref after usage.
2751 gst_pad_get_pad_template_caps (GstPad * pad)
2753 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2755 if (GST_PAD_PAD_TEMPLATE (pad))
2756 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2758 return gst_caps_ref (GST_CAPS_ANY);
2763 * @pad: a #GstPad to get the peer of.
2765 * Gets the peer of @pad. This function refs the peer pad so
2766 * you need to unref it after use.
2768 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2773 gst_pad_get_peer (GstPad * pad)
2777 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2779 GST_OBJECT_LOCK (pad);
2780 result = GST_PAD_PEER (pad);
2782 gst_object_ref (result);
2783 GST_OBJECT_UNLOCK (pad);
2789 * gst_pad_get_allowed_caps:
2792 * Gets the capabilities of the allowed media types that can flow through
2793 * @pad and its peer.
2795 * The allowed capabilities is calculated as the intersection of the results of
2796 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2797 * on the resulting caps.
2799 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2800 * pad link. Unref the caps when you no longer need it. This
2801 * function returns %NULL when @pad has no peer.
2806 gst_pad_get_allowed_caps (GstPad * pad)
2809 GstCaps *caps = NULL;
2812 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2814 GST_OBJECT_LOCK (pad);
2815 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2817 GST_OBJECT_UNLOCK (pad);
2819 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2821 mycaps = gst_pad_query_caps (pad, NULL);
2823 /* Query peer caps */
2824 query = gst_query_new_caps (mycaps);
2825 if (!gst_pad_peer_query (pad, query)) {
2826 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2830 gst_query_parse_caps_result (query, &caps);
2832 g_warn_if_fail (caps != NULL);
2835 gst_caps_ref (caps);
2837 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2841 gst_query_unref (query);
2842 gst_caps_unref (mycaps);
2848 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2849 GST_OBJECT_UNLOCK (pad);
2856 * gst_pad_get_single_internal_link:
2857 * @pad: the #GstPad to get the internal link of.
2859 * If there is a single internal link of the given pad, this function will
2860 * return it. Otherwise, it will return NULL.
2862 * Returns: (transfer full) (nullable): a #GstPad, or %NULL if @pad has none
2863 * or more than one internal links. Unref returned pad with
2864 * gst_object_unref().
2869 gst_pad_get_single_internal_link (GstPad * pad)
2872 gboolean done = FALSE;
2873 GValue item = { 0, };
2876 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2878 iter = gst_pad_iterate_internal_links (pad);
2884 switch (gst_iterator_next (iter, &item)) {
2885 case GST_ITERATOR_OK:
2888 ret = g_value_dup_object (&item);
2890 /* More than one internal link found - don't bother reffing */
2891 gst_clear_object (&ret);
2892 GST_DEBUG_OBJECT (pad,
2893 "Requested single internally linked pad, multiple found");
2896 g_value_reset (&item);
2899 case GST_ITERATOR_RESYNC:
2900 gst_clear_object (&ret);
2901 gst_iterator_resync (iter);
2903 case GST_ITERATOR_ERROR:
2904 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2906 case GST_ITERATOR_DONE:
2908 GST_DEBUG_OBJECT (pad,
2909 "Requested single internally linked pad, none found");
2915 g_value_unset (&item);
2916 gst_iterator_free (iter);
2922 * gst_pad_iterate_internal_links_default:
2923 * @pad: the #GstPad to get the internal links of.
2924 * @parent: (allow-none): the parent of @pad or %NULL
2926 * Iterate the list of pads to which the given pad is linked to inside of
2927 * the parent element.
2928 * This is the default handler, and thus returns an iterator of all of the
2929 * pads inside the parent element with opposite direction.
2931 * The caller must free this iterator after use with gst_iterator_free().
2933 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2934 * has no parent. Unref each returned pad with gst_object_unref().
2937 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2944 GstElement *eparent;
2946 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2948 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2949 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2951 GST_OBJECT_LOCK (pad);
2952 eparent = GST_PAD_PARENT (pad);
2953 if (!eparent || !GST_IS_ELEMENT (eparent))
2956 gst_object_ref (eparent);
2957 GST_OBJECT_UNLOCK (pad);
2960 if (pad->direction == GST_PAD_SRC)
2961 padlist = &eparent->sinkpads;
2963 padlist = &eparent->srcpads;
2965 GST_DEBUG_OBJECT (pad, "Making iterator");
2967 cookie = &eparent->pads_cookie;
2969 lock = GST_OBJECT_GET_LOCK (eparent);
2971 res = gst_iterator_new_list (GST_TYPE_PAD,
2972 lock, cookie, padlist, (GObject *) owner, NULL);
2974 gst_object_unref (owner);
2981 GST_OBJECT_UNLOCK (pad);
2982 GST_DEBUG_OBJECT (pad, "no parent element");
2988 * gst_pad_iterate_internal_links:
2989 * @pad: the GstPad to get the internal links of.
2991 * Gets an iterator for the pads to which the given pad is linked to inside
2992 * of the parent element.
2994 * Each #GstPad element yielded by the iterator will have its refcount increased,
2995 * so unref after use.
2997 * Free-function: gst_iterator_free
2999 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
3000 * or %NULL when the pad does not have an iterator function
3001 * configured. Use gst_iterator_free() after usage.
3004 gst_pad_iterate_internal_links (GstPad * pad)
3006 GstIterator *res = NULL;
3009 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3011 GST_OBJECT_LOCK (pad);
3012 ACQUIRE_PARENT (pad, parent, no_parent);
3013 GST_OBJECT_UNLOCK (pad);
3015 if (GST_PAD_ITERINTLINKFUNC (pad))
3016 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
3018 RELEASE_PARENT (parent);
3025 GST_DEBUG_OBJECT (pad, "no parent");
3026 GST_OBJECT_UNLOCK (pad);
3034 * @forward: (scope call): a #GstPadForwardFunction
3035 * @user_data: user data passed to @forward
3037 * Calls @forward for all internally linked pads of @pad. This function deals with
3038 * dynamically changing internal pads and will make sure that the @forward
3039 * function is only called once for each pad.
3041 * When @forward returns %TRUE, no further pads will be processed.
3043 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
3046 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
3049 gboolean result = FALSE;
3051 gboolean done = FALSE;
3052 GValue item = { 0, };
3053 GList *pushed_pads = NULL;
3055 iter = gst_pad_iterate_internal_links (pad);
3061 switch (gst_iterator_next (iter, &item)) {
3062 case GST_ITERATOR_OK:
3066 intpad = g_value_get_object (&item);
3068 /* if already pushed, skip. FIXME, find something faster to tag pads */
3069 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3070 g_value_reset (&item);
3074 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3075 GST_DEBUG_PAD_NAME (intpad));
3076 done = result = forward (intpad, user_data);
3078 pushed_pads = g_list_prepend (pushed_pads, intpad);
3080 g_value_reset (&item);
3083 case GST_ITERATOR_RESYNC:
3084 /* We don't reset the result here because we don't push the event
3085 * again on pads that got the event already and because we need
3086 * to consider the result of the previous pushes */
3087 gst_iterator_resync (iter);
3089 case GST_ITERATOR_ERROR:
3090 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3093 case GST_ITERATOR_DONE:
3098 g_value_unset (&item);
3099 gst_iterator_free (iter);
3101 g_list_free (pushed_pads);
3111 gboolean dispatched;
3115 event_forward_func (GstPad * pad, EventData * data)
3117 /* for each pad we send to, we should ref the event; it's up
3118 * to downstream to unref again when handled. */
3119 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3120 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3122 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3124 data->dispatched = TRUE;
3131 * gst_pad_event_default:
3132 * @pad: a #GstPad to call the default event handler on.
3133 * @parent: (allow-none): the parent of @pad or %NULL
3134 * @event: (transfer full): the #GstEvent to handle.
3136 * Invokes the default event handler for the given pad.
3138 * The EOS event will pause the task associated with @pad before it is forwarded
3139 * to all internally linked pads,
3141 * The event is sent to all pads internally linked to @pad. This function
3142 * takes ownership of @event.
3144 * Returns: %TRUE if the event was sent successfully.
3147 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3149 gboolean result, forward = TRUE;
3151 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3152 g_return_val_if_fail (event != NULL, FALSE);
3154 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3157 switch (GST_EVENT_TYPE (event)) {
3158 case GST_EVENT_CAPS:
3159 forward = GST_PAD_IS_PROXY_CAPS (pad);
3170 data.dispatched = FALSE;
3171 data.result = FALSE;
3173 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3175 /* for sinkpads without a parent element or without internal links, nothing
3176 * will be dispatched but we still want to return TRUE. */
3177 if (data.dispatched)
3178 result = data.result;
3183 gst_event_unref (event);
3188 /* Default accept caps implementation just checks against
3189 * the allowed caps for the pad */
3191 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3193 /* get the caps and see if it intersects to something not empty */
3194 GstCaps *caps, *allowed = NULL;
3197 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3199 /* first forward the query to internally linked pads when we are dealing with
3201 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3202 result = gst_pad_proxy_query_accept_caps (pad, query);
3204 allowed = gst_pad_get_pad_template_caps (pad);
3209 gst_query_parse_accept_caps (query, &caps);
3211 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3212 allowed = gst_pad_get_pad_template_caps (pad);
3214 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3215 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3216 allowed = gst_pad_query_caps (pad, caps);
3221 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3222 GST_DEBUG_OBJECT (pad,
3223 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3225 result = gst_caps_can_intersect (caps, allowed);
3227 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3228 GST_PTR_FORMAT, allowed, caps);
3229 result = gst_caps_is_subset (caps, allowed);
3232 GST_CAT_WARNING_OBJECT (GST_CAT_CAPS, pad, "caps: %" GST_PTR_FORMAT
3233 " were not compatible with: %" GST_PTR_FORMAT, caps, allowed);
3235 gst_caps_unref (allowed);
3237 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3238 "no compatible caps allowed on the pad");
3242 gst_query_set_accept_caps_result (query, result);
3248 /* Default caps implementation */
3250 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3252 GstCaps *result = NULL, *filter;
3253 GstPadTemplate *templ;
3254 gboolean fixed_caps;
3256 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3259 /* first try to proxy if we must */
3260 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3261 if ((gst_pad_proxy_query_caps (pad, query))) {
3266 gst_query_parse_caps (query, &filter);
3268 /* no proxy or it failed, do default handling */
3269 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3271 GST_OBJECT_LOCK (pad);
3273 /* fixed caps, try the negotiated caps first */
3274 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3275 if ((result = get_pad_caps (pad)))
3276 goto filter_done_unlock;
3279 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3280 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3281 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3282 goto filter_done_unlock;
3286 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3287 "non-fixed pad caps: trying pad caps");
3288 /* non fixed caps, try the negotiated caps */
3289 if ((result = get_pad_caps (pad)))
3290 goto filter_done_unlock;
3293 /* this almost never happens */
3294 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3295 result = GST_CAPS_ANY;
3298 GST_OBJECT_UNLOCK (pad);
3300 /* run the filter on the result */
3302 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3303 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3304 GST_PTR_FORMAT, result, result, filter, filter);
3305 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3306 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3309 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3310 "using caps %p %" GST_PTR_FORMAT, result, result);
3311 result = gst_caps_ref (result);
3313 gst_query_set_caps_result (query, result);
3314 gst_caps_unref (result);
3320 /* Default latency implementation */
3324 GstClockTime min, max;
3328 query_latency_default_fold (const GValue * item, GValue * ret,
3331 GstPad *pad = g_value_get_object (item), *peer;
3332 LatencyFoldData *fold_data = user_data;
3334 gboolean res = FALSE;
3336 query = gst_query_new_latency ();
3338 peer = gst_pad_get_peer (pad);
3340 res = gst_pad_peer_query (pad, query);
3342 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3347 GstClockTime min, max;
3349 gst_query_parse_latency (query, &live, &min, &max);
3351 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3352 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3355 if (min > fold_data->min)
3356 fold_data->min = min;
3358 if (fold_data->max == GST_CLOCK_TIME_NONE)
3359 fold_data->max = max;
3360 else if (max < fold_data->max)
3361 fold_data->max = max;
3363 fold_data->live = TRUE;
3366 GST_DEBUG_OBJECT (pad, "latency query failed");
3367 g_value_set_boolean (ret, FALSE);
3370 gst_query_unref (query);
3372 gst_object_unref (peer);
3378 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3381 GstIteratorResult res;
3382 GValue ret = G_VALUE_INIT;
3384 LatencyFoldData fold_data;
3386 it = gst_pad_iterate_internal_links (pad);
3388 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3392 g_value_init (&ret, G_TYPE_BOOLEAN);
3395 fold_data.live = FALSE;
3397 fold_data.max = GST_CLOCK_TIME_NONE;
3399 g_value_set_boolean (&ret, TRUE);
3400 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3402 case GST_ITERATOR_OK:
3403 g_assert_not_reached ();
3405 case GST_ITERATOR_DONE:
3407 case GST_ITERATOR_ERROR:
3408 g_value_set_boolean (&ret, FALSE);
3410 case GST_ITERATOR_RESYNC:
3411 gst_iterator_resync (it);
3414 g_assert_not_reached ();
3417 gst_iterator_free (it);
3419 query_ret = g_value_get_boolean (&ret);
3421 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3422 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3423 fold_data.min, fold_data.max);
3425 if (fold_data.min > fold_data.max) {
3426 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3429 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3431 GST_LOG_OBJECT (pad, "latency query failed");
3441 gboolean dispatched;
3445 query_forward_func (GstPad * pad, QueryData * data)
3447 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3448 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3450 data->result |= gst_pad_peer_query (pad, data->query);
3452 data->dispatched = TRUE;
3454 /* stop on first successful reply */
3455 return data->result;
3459 * gst_pad_query_default:
3460 * @pad: a #GstPad to call the default query handler on.
3461 * @parent: (allow-none): the parent of @pad or %NULL
3462 * @query: (transfer none): the #GstQuery to handle.
3464 * Invokes the default query handler for the given pad.
3465 * The query is sent to all pads internally linked to @pad. Note that
3466 * if there are many possible sink pads that are internally linked to
3467 * @pad, only one will be sent the query.
3468 * Multi-sinkpad elements should implement custom query handlers.
3470 * Returns: %TRUE if the query was performed successfully.
3473 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3475 gboolean forward, ret = FALSE;
3477 switch (GST_QUERY_TYPE (query)) {
3478 case GST_QUERY_SCHEDULING:
3479 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3481 case GST_QUERY_ALLOCATION:
3482 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3484 case GST_QUERY_ACCEPT_CAPS:
3485 ret = gst_pad_query_accept_caps_default (pad, query);
3488 case GST_QUERY_CAPS:
3489 ret = gst_pad_query_caps_default (pad, query);
3492 case GST_QUERY_LATENCY:
3493 ret = gst_pad_query_latency_default (pad, query);
3496 case GST_QUERY_BITRATE:
3497 /* FIXME: better default handling */
3500 case GST_QUERY_POSITION:
3501 case GST_QUERY_SEEKING:
3502 case GST_QUERY_FORMATS:
3503 case GST_QUERY_JITTER:
3504 case GST_QUERY_RATE:
3505 case GST_QUERY_CONVERT:
3511 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3512 query, GST_QUERY_TYPE_NAME (query));
3518 data.dispatched = FALSE;
3519 data.result = FALSE;
3521 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3523 if (data.dispatched) {
3526 /* nothing dispatched, assume drained */
3527 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3536 #define N_STACK_ALLOCATE_PROBES (16)
3538 /* A helper that checks if a probe was already
3539 * in the called_probes list, and adds it if
3540 * not. Used to avoid calling probes a 2nd time when
3541 * looping again after probe removal */
3543 check_probe_already_called (GHook * hook, ProbeMarshall * data)
3547 /* if we have called this callback, do nothing. But only check
3548 * if we're actually calling probes a second time */
3550 for (i = 0; i < data->n_called_probes; i++) {
3551 if (data->called_probes[i] == hook->hook_id) {
3557 /* reallocate on the heap if we had more than 16 probes */
3558 if (data->n_called_probes == data->called_probes_size) {
3559 if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
3560 data->called_probes_size *= 2;
3561 data->called_probes =
3562 g_renew (gulong, data->called_probes, data->called_probes_size);
3564 gulong *tmp = data->called_probes;
3566 data->called_probes_size *= 2;
3567 data->called_probes = g_new (gulong, data->called_probes_size);
3568 memcpy (data->called_probes, tmp,
3569 N_STACK_ALLOCATE_PROBES * sizeof (gulong));
3572 data->called_probes[data->n_called_probes++] = hook->hook_id;
3574 /* This probe was not alraedy called */
3579 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3581 GstPad *pad = data->pad;
3582 GstPadProbeInfo *info = data->info;
3583 GstPadProbeType type, flags;
3584 GstPadProbeCallback callback;
3585 GstPadProbeReturn ret;
3586 gpointer original_data;
3588 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3590 original_data = info->data;
3592 /* one of the scheduling types */
3593 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3596 if (G_UNLIKELY (data->handled)) {
3597 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3598 "probe previously returned HANDLED, not calling again");
3600 } else if (G_UNLIKELY (data->dropped)) {
3601 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3602 "probe previously returned DROPPED, not calling again");
3606 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3607 /* one of the data types for non-idle probes */
3608 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3609 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3611 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3612 /* one of the data types for non-idle probes */
3613 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3614 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3617 /* Type must have PULL or PUSH probe types */
3618 g_assert_not_reached ();
3621 /* one of the blocking types must match */
3622 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3623 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3625 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3626 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3628 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3629 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3630 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3633 if (check_probe_already_called (hook, data)) {
3634 /* Reset marshalled = TRUE here, because the probe
3635 * was already called and set it the first time around,
3636 * and we may want to keep blocking on it.
3638 * https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/658
3640 data->marshalled = TRUE;
3641 goto already_called;
3644 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3645 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3647 callback = (GstPadProbeCallback) hook->func;
3648 if (callback == NULL) {
3649 /* No callback is equivalent to just returning GST_PAD_PROBE_OK */
3650 data->marshalled = TRUE;
3654 info->id = hook->hook_id;
3656 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3657 pad->priv->idle_running++;
3659 GST_OBJECT_UNLOCK (pad);
3661 ret = callback (pad, info, hook->data);
3663 GST_OBJECT_LOCK (pad);
3665 /* If the probe callback asked for the
3666 * probe to be removed, don't set the marshalled flag
3667 * otherwise, you can get a case where you return
3668 * GST_PAD_PROBE_REMOVE from a buffer probe and
3669 * then the pad blocks anyway if there's any other
3670 * blocking probes installed.
3672 * https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/658
3674 if (ret != GST_PAD_PROBE_REMOVE)
3675 data->marshalled = TRUE;
3677 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3678 pad->priv->idle_running--;
3680 if (ret != GST_PAD_PROBE_HANDLED && original_data != NULL
3681 && info->data == NULL) {
3682 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3683 info->type = GST_PAD_PROBE_TYPE_INVALID;
3684 data->dropped = TRUE;
3688 case GST_PAD_PROBE_REMOVE:
3689 /* remove the probe */
3690 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3691 cleanup_hook (pad, hook);
3693 case GST_PAD_PROBE_DROP:
3694 /* need to drop the data, make sure other probes don't get called
3696 GST_DEBUG_OBJECT (pad, "asked to drop item");
3697 info->type = GST_PAD_PROBE_TYPE_INVALID;
3698 data->dropped = TRUE;
3700 case GST_PAD_PROBE_HANDLED:
3701 GST_DEBUG_OBJECT (pad, "probe handled data");
3702 data->handled = TRUE;
3704 case GST_PAD_PROBE_PASS:
3705 /* inform the pad block to let things pass */
3706 GST_DEBUG_OBJECT (pad, "asked to pass item");
3709 case GST_PAD_PROBE_OK:
3710 GST_DEBUG_OBJECT (pad, "probe returned OK");
3713 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3720 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3721 "hook %lu with flags 0x%08x does not match %08x",
3722 hook->hook_id, flags, info->type);
3727 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3728 "hook %lu already called", hook->hook_id);
3733 /* a probe that does not take or return any data */
3734 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3736 if (G_UNLIKELY (pad->num_probes)) { \
3737 GstFlowReturn pval = defaultval; \
3738 /* pass NULL as the data item */ \
3739 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3740 info.ABI.abi.flow_ret = defaultval; \
3741 ret = do_probe_callbacks (pad, &info, defaultval); \
3742 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3747 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3749 if (G_UNLIKELY (pad->num_probes)) { \
3750 /* pass the data item */ \
3751 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3752 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3753 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3754 /* store the possibly updated data item */ \
3755 data = GST_PAD_PROBE_INFO_DATA (&info); \
3756 /* if something went wrong, exit */ \
3757 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3758 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3759 ret = info.ABI.abi.flow_ret; \
3760 goto handle_label; \
3767 #define PROBE_PUSH(pad,mask,data,label) \
3768 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3769 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3770 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3771 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3772 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3774 static GstFlowReturn
3775 do_pad_idle_probe_wait (GstPad * pad)
3777 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3778 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3779 "waiting idle probe to be removed");
3780 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3781 GST_PAD_BLOCK_WAIT (pad);
3782 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3783 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3785 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3786 return GST_FLOW_FLUSHING;
3791 #define PROBE_TYPE_IS_SERIALIZED(i) \
3794 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3795 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3796 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3798 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3799 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3801 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3802 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3806 static GstFlowReturn
3807 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3808 GstFlowReturn defaultval)
3813 gulong called_probes[N_STACK_ALLOCATE_PROBES];
3818 data.handled = FALSE;
3819 data.dropped = FALSE;
3821 /* We stack-allocate for N_STACK_ALLOCATE_PROBES hooks as a first step. If more are needed,
3822 * we will re-allocate with g_malloc(). This should usually never be needed
3824 data.called_probes = called_probes;
3825 data.n_called_probes = 0;
3826 data.called_probes_size = N_STACK_ALLOCATE_PROBES;
3830 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3832 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3833 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3838 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "do probes");
3839 cookie = pad->priv->probe_list_cookie;
3841 /* Clear the marshalled flag before doing callbacks. Only if
3842 * there are matching callbacks still will it get set */
3843 data.marshalled = FALSE;
3845 g_hook_list_marshal (&pad->probes, TRUE,
3846 (GHookMarshaller) probe_hook_marshal, &data);
3848 /* if the list changed, call the new callbacks (they will not be in
3849 * called_probes yet) */
3850 if (cookie != pad->priv->probe_list_cookie) {
3851 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3852 "probe list changed, restarting");
3857 /* the first item that dropped will stop the hooks and then we drop here */
3861 /* If one handler took care of it, let the the item pass */
3866 /* if no handler matched and we are blocking, let the item pass */
3867 if (!data.marshalled && is_block)
3870 /* At this point, all handlers returned either OK or PASS. If one handler
3871 * returned PASS, let the item pass */
3876 while (GST_PAD_IS_BLOCKED (pad)) {
3877 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3878 "we are blocked %d times", pad->num_blocked);
3880 /* we might have released the lock */
3881 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3884 /* now we block the streaming thread. It can be unlocked when we
3885 * deactivate the pad (which will also set the FLUSHING flag) or
3886 * when the pad is unblocked. A flushing event will also unblock
3887 * the pad after setting the FLUSHING flag. */
3888 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3889 "Waiting to be unblocked or set flushing");
3890 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3891 GST_PAD_BLOCK_WAIT (pad);
3892 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3893 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3895 /* if the list changed, call the new callbacks (they will not be in
3896 * called_probes yet) */
3897 if (cookie != pad->priv->probe_list_cookie) {
3898 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3899 "probe list changed, restarting");
3904 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3909 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3910 g_free (data.called_probes);
3917 GST_DEBUG_OBJECT (pad, "pad is flushing");
3918 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3919 g_free (data.called_probes);
3920 return GST_FLOW_FLUSHING;
3924 GST_DEBUG_OBJECT (pad, "data is dropped");
3925 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3926 g_free (data.called_probes);
3927 return GST_FLOW_CUSTOM_SUCCESS;
3931 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3932 GST_DEBUG_OBJECT (pad, "data is passed");
3933 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3934 g_free (data.called_probes);
3939 GST_DEBUG_OBJECT (pad, "data was handled");
3940 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3941 g_free (data.called_probes);
3942 return GST_FLOW_CUSTOM_SUCCESS_1;
3949 * gst_pad_get_offset:
3952 * Get the offset applied to the running time of @pad. @pad has to be a source
3955 * Returns: the offset.
3958 gst_pad_get_offset (GstPad * pad)
3962 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3964 GST_OBJECT_LOCK (pad);
3965 result = pad->offset;
3966 GST_OBJECT_UNLOCK (pad);
3972 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3974 ev->received = FALSE;
3979 * gst_pad_set_offset:
3981 * @offset: the offset
3983 * Set the offset that will be applied to the running time of @pad.
3986 gst_pad_set_offset (GstPad * pad, gint64 offset)
3988 g_return_if_fail (GST_IS_PAD (pad));
3990 GST_OBJECT_LOCK (pad);
3991 /* if nothing changed, do nothing */
3992 if (pad->offset == offset)
3995 pad->offset = offset;
3996 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3997 GST_STIME_ARGS (offset));
3999 /* resend all sticky events with updated offset on next buffer push */
4000 events_foreach (pad, mark_event_not_received, NULL);
4001 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4004 GST_OBJECT_UNLOCK (pad);
4011 /* If TRUE and ret is not OK this means
4012 * that pushing the EOS event failed
4016 /* If called for an event this is
4017 * the event that would be pushed
4018 * next. Don't forward sticky events
4019 * that would come after that */
4023 /* should be called with pad LOCK */
4025 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
4027 PushStickyData *data = user_data;
4028 GstEvent *event = ev->event;
4031 GST_DEBUG_OBJECT (pad, "event %s was already received",
4032 GST_EVENT_TYPE_NAME (event));
4036 /* If we're called because of an sticky event, only forward
4037 * events that would come before this new event and the
4039 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
4040 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
4041 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
4042 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
4044 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
4045 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4046 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
4047 data->ret = GST_FLOW_OK;
4050 switch (data->ret) {
4052 ev->received = TRUE;
4053 GST_DEBUG_OBJECT (pad, "event %s marked received",
4054 GST_EVENT_TYPE_NAME (event));
4056 case GST_FLOW_CUSTOM_SUCCESS:
4057 /* we can't assume the event is received when it was dropped */
4058 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
4059 GST_EVENT_TYPE_NAME (event));
4060 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4061 data->ret = GST_FLOW_OK;
4063 case GST_FLOW_CUSTOM_SUCCESS_1:
4064 /* event was ignored and should be sent later */
4065 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
4066 GST_EVENT_TYPE_NAME (event));
4067 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4068 data->ret = GST_FLOW_OK;
4070 case GST_FLOW_NOT_LINKED:
4071 /* not linked is not a problem, we are sticky so the event will be
4072 * rescheduled to be sent later on re-link, but only for non-EOS events */
4073 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
4074 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
4075 data->ret = GST_FLOW_OK;
4076 ev->received = TRUE;
4080 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
4081 gst_flow_get_name (data->ret));
4082 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4086 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
4087 data->was_eos = TRUE;
4089 return data->ret == GST_FLOW_OK;
4092 /* check sticky events and push them when needed. should be called
4094 static inline GstFlowReturn
4095 check_sticky (GstPad * pad, GstEvent * event)
4097 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4099 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
4100 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4102 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
4103 events_foreach (pad, push_sticky, &data);
4105 /* If there's an EOS event we must push it downstream
4106 * even if sending a previous sticky event failed.
4107 * Otherwise the pipeline might wait forever for EOS.
4109 * Only do this if pushing another event than the EOS
4112 if (data.ret != GST_FLOW_OK && !data.was_eos) {
4113 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
4115 if (ev && !ev->received) {
4116 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
4117 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4118 /* the event could have been dropped. Because this can only
4119 * happen if the user asked for it, it's not an error */
4120 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
4121 data.ret = GST_FLOW_OK;
4131 * @pad: a #GstPad to invoke the default query on.
4132 * @query: (transfer none): the #GstQuery to perform.
4134 * Dispatches a query to a pad. The query should have been allocated by the
4135 * caller via one of the type-specific allocation functions. The element that
4136 * the pad belongs to is responsible for filling the query with an appropriate
4137 * response, which should then be parsed with a type-specific query parsing
4140 * Again, the caller is responsible for both the allocation and deallocation of
4141 * the query structure.
4143 * Please also note that some queries might need a running pipeline to work.
4145 * Returns: %TRUE if the query could be performed.
4148 gst_pad_query (GstPad * pad, GstQuery * query)
4151 gboolean res, serialized;
4152 GstPadQueryFunction func;
4153 GstPadProbeType type;
4156 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4157 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4159 if (GST_PAD_IS_SRC (pad)) {
4160 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4161 goto wrong_direction;
4162 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4163 } else if (GST_PAD_IS_SINK (pad)) {
4164 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4165 goto wrong_direction;
4166 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4168 goto unknown_direction;
4170 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4171 GST_QUERY_TYPE_NAME (query));
4172 GST_TRACER_PAD_QUERY_PRE (pad, query);
4174 serialized = GST_QUERY_IS_SERIALIZED (query);
4175 if (G_UNLIKELY (serialized))
4176 GST_PAD_STREAM_LOCK (pad);
4178 GST_OBJECT_LOCK (pad);
4179 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4180 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4181 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4183 ACQUIRE_PARENT (pad, parent, no_parent);
4184 GST_OBJECT_UNLOCK (pad);
4186 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4189 res = func (pad, parent, query);
4191 RELEASE_PARENT (parent);
4193 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4194 GST_QUERY_TYPE_NAME (query), res);
4195 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4200 GST_OBJECT_LOCK (pad);
4201 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4202 GST_OBJECT_UNLOCK (pad);
4204 if (G_UNLIKELY (serialized))
4205 GST_PAD_STREAM_UNLOCK (pad);
4212 g_warning ("pad %s:%s query %s in wrong direction",
4213 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4218 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4223 GST_DEBUG_OBJECT (pad, "had no parent");
4224 GST_OBJECT_UNLOCK (pad);
4225 if (G_UNLIKELY (serialized))
4226 GST_PAD_STREAM_UNLOCK (pad);
4231 GST_DEBUG_OBJECT (pad, "had no query function");
4232 RELEASE_PARENT (parent);
4233 if (G_UNLIKELY (serialized))
4234 GST_PAD_STREAM_UNLOCK (pad);
4239 GST_DEBUG_OBJECT (pad, "query failed");
4240 if (G_UNLIKELY (serialized))
4241 GST_PAD_STREAM_UNLOCK (pad);
4246 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4247 GST_OBJECT_UNLOCK (pad);
4248 if (G_UNLIKELY (serialized))
4249 GST_PAD_STREAM_UNLOCK (pad);
4251 /* if a probe dropped without handling, we don't sent it further but assume
4252 * that the probe did not answer the query and return FALSE */
4253 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4263 * gst_pad_peer_query:
4264 * @pad: a #GstPad to invoke the peer query on.
4265 * @query: (transfer none): the #GstQuery to perform.
4267 * Performs gst_pad_query() on the peer of @pad.
4269 * The caller is responsible for both the allocation and deallocation of
4270 * the query structure.
4272 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4273 * if @pad has no peer.
4276 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4279 GstPadProbeType type;
4280 gboolean res, serialized;
4283 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4284 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4286 if (GST_PAD_IS_SRC (pad)) {
4287 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4288 goto wrong_direction;
4289 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4290 } else if (GST_PAD_IS_SINK (pad)) {
4291 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4292 goto wrong_direction;
4293 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4295 goto unknown_direction;
4297 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4298 GST_QUERY_TYPE_NAME (query));
4300 serialized = GST_QUERY_IS_SERIALIZED (query);
4302 GST_OBJECT_LOCK (pad);
4303 if (GST_PAD_IS_SRC (pad) && serialized) {
4304 /* all serialized queries on the srcpad trigger push of
4306 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4310 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4311 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4312 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4314 peerpad = GST_PAD_PEER (pad);
4315 if (G_UNLIKELY (peerpad == NULL))
4318 gst_object_ref (peerpad);
4319 GST_OBJECT_UNLOCK (pad);
4321 res = gst_pad_query (peerpad, query);
4323 gst_object_unref (peerpad);
4328 GST_OBJECT_LOCK (pad);
4329 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4330 GST_OBJECT_UNLOCK (pad);
4337 g_warning ("pad %s:%s query %s in wrong direction",
4338 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4343 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4348 GST_WARNING_OBJECT (pad, "could not send sticky events");
4349 GST_OBJECT_UNLOCK (pad);
4354 GST_INFO_OBJECT (pad, "pad has no peer");
4355 GST_OBJECT_UNLOCK (pad);
4360 GST_DEBUG_OBJECT (pad, "query failed");
4365 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4366 GST_OBJECT_UNLOCK (pad);
4368 /* if a probe dropped without handling, we don't sent it further but
4369 * assume that the probe did not answer the query and return FALSE */
4370 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4379 /**********************************************************************
4380 * Data passing functions
4383 /* this is the chain function that does not perform the additional argument
4384 * checking for that little extra speed.
4386 static inline GstFlowReturn
4387 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4391 gboolean handled = FALSE;
4393 if (type & GST_PAD_PROBE_TYPE_BUFFER_LIST) {
4394 GST_TRACER_PAD_CHAIN_LIST_PRE (pad, data);
4396 GST_TRACER_PAD_CHAIN_PRE (pad, data);
4399 GST_PAD_STREAM_LOCK (pad);
4401 GST_OBJECT_LOCK (pad);
4402 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4405 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4408 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4411 #ifdef GST_ENABLE_EXTRA_CHECKS
4412 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4413 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4415 ":%s:<%s:%s> Got data flow before stream-start event",
4416 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4418 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4420 ":%s:<%s:%s> Got data flow before segment event",
4421 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4423 pad->priv->last_cookie = pad->priv->events_cookie;
4427 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4430 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4432 ACQUIRE_PARENT (pad, parent, no_parent);
4433 GST_OBJECT_UNLOCK (pad);
4435 /* NOTE: we read the chainfunc unlocked.
4436 * we cannot hold the lock for the pad so we might send
4437 * the data to the wrong function. This is not really a
4438 * problem since functions are assigned at creation time
4439 * and don't change that often... */
4440 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4441 GstPadChainFunction chainfunc;
4443 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4446 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4447 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4448 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4450 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4452 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4453 "called chainfunction &%s with buffer %p, returned %s",
4454 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4456 GstPadChainListFunction chainlistfunc;
4458 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4461 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4462 "calling chainlistfunction &%s",
4463 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4465 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4467 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4468 "called chainlistfunction &%s, returned %s",
4469 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4472 pad->ABI.abi.last_flowret = ret;
4474 RELEASE_PARENT (parent);
4476 GST_PAD_STREAM_UNLOCK (pad);
4479 if (type & GST_PAD_PROBE_TYPE_BUFFER_LIST) {
4480 GST_TRACER_PAD_CHAIN_LIST_POST (pad, ret);
4482 GST_TRACER_PAD_CHAIN_POST (pad, ret);
4490 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4491 "chaining, but pad was flushing");
4492 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4493 GST_OBJECT_UNLOCK (pad);
4494 GST_PAD_STREAM_UNLOCK (pad);
4495 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4496 ret = GST_FLOW_FLUSHING;
4501 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4502 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4503 GST_OBJECT_UNLOCK (pad);
4504 GST_PAD_STREAM_UNLOCK (pad);
4505 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4511 g_critical ("chain on pad %s:%s but it was not in push mode",
4512 GST_DEBUG_PAD_NAME (pad));
4513 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4514 GST_OBJECT_UNLOCK (pad);
4515 GST_PAD_STREAM_UNLOCK (pad);
4516 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4517 ret = GST_FLOW_ERROR;
4525 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4527 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4530 case GST_FLOW_CUSTOM_SUCCESS:
4531 case GST_FLOW_CUSTOM_SUCCESS_1:
4532 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4536 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4539 pad->ABI.abi.last_flowret = ret;
4540 GST_OBJECT_UNLOCK (pad);
4541 GST_PAD_STREAM_UNLOCK (pad);
4546 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4547 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4548 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4549 GST_OBJECT_UNLOCK (pad);
4550 GST_PAD_STREAM_UNLOCK (pad);
4551 ret = GST_FLOW_FLUSHING;
4556 pad->ABI.abi.last_flowret = GST_FLOW_NOT_SUPPORTED;
4557 RELEASE_PARENT (parent);
4558 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4559 g_critical ("chain on pad %s:%s but it has no chainfunction",
4560 GST_DEBUG_PAD_NAME (pad));
4561 GST_PAD_STREAM_UNLOCK (pad);
4562 ret = GST_FLOW_NOT_SUPPORTED;
4569 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4570 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4573 * Chain a buffer to @pad.
4575 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4577 * If the buffer type is not acceptable for @pad (as negotiated with a
4578 * preceding GST_EVENT_CAPS event), this function returns
4579 * #GST_FLOW_NOT_NEGOTIATED.
4581 * The function proceeds calling the chain function installed on @pad (see
4582 * gst_pad_set_chain_function()) and the return value of that function is
4583 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4586 * In all cases, success or failure, the caller loses its reference to @buffer
4587 * after calling this function.
4589 * Returns: a #GstFlowReturn from the pad.
4594 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4596 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4597 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4598 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4600 return gst_pad_chain_data_unchecked (pad,
4601 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4604 static GstFlowReturn
4605 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4606 GstBufferList * list)
4612 GST_LOG_OBJECT (pad, "chaining each buffer in list individually");
4614 len = gst_buffer_list_length (list);
4617 for (i = 0; i < len; i++) {
4618 buffer = gst_buffer_list_get (list, i);
4620 gst_pad_chain_data_unchecked (pad,
4621 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4622 gst_buffer_ref (buffer));
4623 if (ret != GST_FLOW_OK)
4626 gst_buffer_list_unref (list);
4632 * gst_pad_chain_list:
4633 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4634 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4637 * Chain a bufferlist to @pad.
4639 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4641 * If @pad was not negotiated properly with a CAPS event, this function
4642 * returns #GST_FLOW_NOT_NEGOTIATED.
4644 * The function proceeds calling the chainlist function installed on @pad (see
4645 * gst_pad_set_chain_list_function()) and the return value of that function is
4646 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4647 * chainlist function.
4649 * In all cases, success or failure, the caller loses its reference to @list
4650 * after calling this function.
4654 * Returns: a #GstFlowReturn from the pad.
4657 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4659 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4660 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4661 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4663 return gst_pad_chain_data_unchecked (pad,
4664 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4667 static GstFlowReturn
4668 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4672 gboolean handled = FALSE;
4674 GST_OBJECT_LOCK (pad);
4675 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4678 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4681 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4684 #ifdef GST_ENABLE_EXTRA_CHECKS
4685 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4686 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4688 ":%s:<%s:%s> Got data flow before stream-start event",
4689 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4691 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4693 ":%s:<%s:%s> Got data flow before segment event",
4694 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4696 pad->priv->last_cookie = pad->priv->events_cookie;
4700 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4703 /* do block probes */
4704 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4707 /* recheck sticky events because the probe might have cause a relink */
4708 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4711 /* do post-blocking probes */
4712 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4714 /* recheck sticky events because the probe might have cause a relink */
4715 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4718 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4721 /* take ref to peer pad before releasing the lock */
4722 gst_object_ref (peer);
4724 GST_OBJECT_UNLOCK (pad);
4726 ret = gst_pad_chain_data_unchecked (peer, type, data);
4729 gst_object_unref (peer);
4731 GST_OBJECT_LOCK (pad);
4732 pad->ABI.abi.last_flowret = ret;
4734 if (pad->priv->using == 0) {
4735 /* pad is not active anymore, trigger idle callbacks */
4736 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4737 probe_stopped, ret);
4739 GST_OBJECT_UNLOCK (pad);
4743 /* ERROR recovery here */
4747 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4748 "pushing, but pad was flushing");
4749 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4750 GST_OBJECT_UNLOCK (pad);
4751 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4752 return GST_FLOW_FLUSHING;
4756 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4757 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4758 GST_OBJECT_UNLOCK (pad);
4759 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4760 return GST_FLOW_EOS;
4764 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4765 GST_DEBUG_PAD_NAME (pad));
4766 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4767 GST_OBJECT_UNLOCK (pad);
4768 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4769 return GST_FLOW_ERROR;
4773 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4774 "error pushing events, return %s", gst_flow_get_name (ret));
4775 pad->ABI.abi.last_flowret = ret;
4776 GST_OBJECT_UNLOCK (pad);
4777 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4785 GST_OBJECT_UNLOCK (pad);
4786 if (data != NULL && !handled)
4787 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4790 case GST_FLOW_CUSTOM_SUCCESS:
4791 case GST_FLOW_CUSTOM_SUCCESS_1:
4792 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4796 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4799 pad->ABI.abi.last_flowret = ret;
4804 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4805 "pushing, but it was not linked");
4806 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4807 GST_OBJECT_UNLOCK (pad);
4808 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4809 return GST_FLOW_NOT_LINKED;
4815 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4816 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4819 * Pushes a buffer to the peer of @pad.
4821 * This function will call installed block probes before triggering any
4822 * installed data probes.
4824 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4825 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4828 * In all cases, success or failure, the caller loses its reference to @buffer
4829 * after calling this function.
4831 * Returns: a #GstFlowReturn from the peer pad.
4836 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4840 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4841 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4842 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4844 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4845 res = gst_pad_push_data (pad,
4846 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4847 GST_TRACER_PAD_PUSH_POST (pad, res);
4852 * gst_pad_push_list:
4853 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4854 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4857 * Pushes a buffer list to the peer of @pad.
4859 * This function will call installed block probes before triggering any
4860 * installed data probes.
4862 * The function proceeds calling the chain function on the peer pad and returns
4863 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4864 * be returned. If the peer pad does not have any installed chainlist function
4865 * every group buffer of the list will be merged into a normal #GstBuffer and
4866 * chained via gst_pad_chain().
4868 * In all cases, success or failure, the caller loses its reference to @list
4869 * after calling this function.
4871 * Returns: a #GstFlowReturn from the peer pad.
4876 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4880 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4881 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4882 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4884 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4885 res = gst_pad_push_data (pad,
4886 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4887 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4891 static GstFlowReturn
4892 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4893 GstBuffer ** buffer)
4896 GstPadGetRangeFunction getrangefunc;
4900 GST_PAD_STREAM_LOCK (pad);
4902 GST_OBJECT_LOCK (pad);
4903 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4906 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4909 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4914 /* when one of the probes returns DROPPED, probe_stopped will be called
4915 * and we skip calling the getrange function, res_buf should then contain a
4916 * valid result buffer */
4917 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4918 res_buf, offset, size, probe_stopped);
4920 /* recheck sticky events because the probe might have cause a relink */
4921 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4924 ACQUIRE_PARENT (pad, parent, no_parent);
4925 GST_OBJECT_UNLOCK (pad);
4927 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4930 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4931 "calling getrangefunc %s, offset %"
4932 G_GUINT64_FORMAT ", size %u",
4933 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4935 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4937 RELEASE_PARENT (parent);
4939 GST_OBJECT_LOCK (pad);
4940 if (G_UNLIKELY (ret != GST_FLOW_OK))
4941 goto get_range_failed;
4943 /* can only fire the signal if we have a valid buffer */
4945 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4946 res_buf, offset, size, probe_stopped_unref);
4947 pad->ABI.abi.last_flowret = ret;
4948 GST_OBJECT_UNLOCK (pad);
4950 GST_PAD_STREAM_UNLOCK (pad);
4952 /* If the caller provided a buffer it must be filled by the getrange
4953 * function instead of it returning a new buffer */
4954 g_return_val_if_fail (!*buffer || res_buf == *buffer, GST_FLOW_ERROR);
4963 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4964 "getrange, but pad was flushing");
4965 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4966 GST_OBJECT_UNLOCK (pad);
4967 GST_PAD_STREAM_UNLOCK (pad);
4968 return GST_FLOW_FLUSHING;
4972 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4973 GST_DEBUG_PAD_NAME (pad));
4974 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4975 GST_OBJECT_UNLOCK (pad);
4976 GST_PAD_STREAM_UNLOCK (pad);
4977 return GST_FLOW_ERROR;
4981 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4982 pad->ABI.abi.last_flowret = ret;
4983 GST_OBJECT_UNLOCK (pad);
4984 GST_PAD_STREAM_UNLOCK (pad);
4989 GST_DEBUG_OBJECT (pad, "no parent");
4990 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4991 GST_OBJECT_UNLOCK (pad);
4992 GST_PAD_STREAM_UNLOCK (pad);
4993 return GST_FLOW_FLUSHING;
4997 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4998 GST_DEBUG_PAD_NAME (pad));
4999 RELEASE_PARENT (parent);
5000 GST_PAD_STREAM_UNLOCK (pad);
5001 return GST_FLOW_NOT_SUPPORTED;
5005 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5006 "probe returned %s", gst_flow_get_name (ret));
5007 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5009 /* the probe filled the buffer and asks us to not call the getrange
5010 * anymore, we continue with the post probes then. */
5011 GST_DEBUG_OBJECT (pad, "handled buffer");
5015 /* no buffer, we are EOS */
5016 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5020 pad->ABI.abi.last_flowret = ret;
5021 GST_OBJECT_UNLOCK (pad);
5022 GST_PAD_STREAM_UNLOCK (pad);
5026 probe_stopped_unref:
5028 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5029 "probe returned %s", gst_flow_get_name (ret));
5030 /* if we drop here, it signals EOS */
5031 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5033 pad->ABI.abi.last_flowret = ret;
5034 GST_OBJECT_UNLOCK (pad);
5035 GST_PAD_STREAM_UNLOCK (pad);
5036 if (*buffer == NULL)
5037 gst_buffer_unref (res_buf);
5042 pad->ABI.abi.last_flowret = ret;
5043 GST_OBJECT_UNLOCK (pad);
5044 GST_PAD_STREAM_UNLOCK (pad);
5045 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5046 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5047 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
5053 * gst_pad_get_range:
5054 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
5055 * @offset: The start offset of the buffer
5056 * @size: The length of the buffer
5057 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
5058 * returns #GST_FLOW_ERROR if %NULL.
5060 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
5061 * immediately and @buffer is %NULL.
5063 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
5064 * description of a getrange function. If @pad has no getrange function
5065 * installed (see gst_pad_set_getrange_function()) this function returns
5066 * #GST_FLOW_NOT_SUPPORTED.
5068 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
5069 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
5070 * must be freed with gst_buffer_unref() after usage.
5072 * When @buffer points to a variable that points to a valid #GstBuffer, the
5073 * buffer will be filled with the result data when this function returns
5074 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
5075 * @size bytes will be filled in the result buffer and its size will be updated
5078 * Note that less than @size bytes can be returned in @buffer when, for example,
5079 * an EOS condition is near or when @buffer is not large enough to hold @size
5080 * bytes. The caller should check the result buffer size to get the result size.
5082 * When this function returns any other result value than #GST_FLOW_OK, @buffer
5083 * will be unchanged.
5085 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
5087 * Returns: a #GstFlowReturn from the pad.
5092 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
5093 GstBuffer ** buffer)
5095 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5096 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
5097 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5098 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5099 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5101 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
5105 * gst_pad_pull_range:
5106 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
5107 * @offset: The start offset of the buffer
5108 * @size: The length of the buffer
5109 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
5110 * GST_FLOW_ERROR if %NULL.
5112 * Pulls a @buffer from the peer pad or fills up a provided buffer.
5114 * This function will first trigger the pad block signal if it was
5117 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
5118 * function returns the result of gst_pad_get_range() on the peer pad.
5119 * See gst_pad_get_range() for a list of return values and for the
5120 * semantics of the arguments of this function.
5122 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
5123 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
5124 * must be freed with gst_buffer_unref() after usage. When this function
5125 * returns any other result value, @buffer will still point to %NULL.
5127 * When @buffer points to a variable that points to a valid #GstBuffer, the
5128 * buffer will be filled with the result data when this function returns
5129 * #GST_FLOW_OK. When this function returns any other result value,
5130 * @buffer will be unchanged. If the provided buffer is larger than @size, only
5131 * @size bytes will be filled in the result buffer and its size will be updated
5134 * Note that less than @size bytes can be returned in @buffer when, for example,
5135 * an EOS condition is near or when @buffer is not large enough to hold @size
5136 * bytes. The caller should check the result buffer size to get the result size.
5138 * Returns: a #GstFlowReturn from the peer pad.
5143 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
5144 GstBuffer ** buffer)
5150 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5151 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
5152 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5153 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5154 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5156 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
5158 GST_OBJECT_LOCK (pad);
5159 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5162 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
5167 /* when one of the probes returns DROPPED, probe_stopped will be
5168 * called and we skip calling the peer getrange function. *buffer should then
5169 * contain a valid buffer */
5170 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
5171 res_buf, offset, size, probe_stopped);
5173 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
5176 gst_object_ref (peer);
5178 GST_OBJECT_UNLOCK (pad);
5180 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5182 gst_object_unref (peer);
5184 GST_OBJECT_LOCK (pad);
5186 pad->ABI.abi.last_flowret = ret;
5187 if (pad->priv->using == 0) {
5188 /* pad is not active anymore, trigger idle callbacks */
5189 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5190 probe_stopped_unref, ret);
5193 if (G_UNLIKELY (ret != GST_FLOW_OK))
5194 goto pull_range_failed;
5197 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5198 res_buf, offset, size, probe_stopped_unref);
5200 GST_OBJECT_UNLOCK (pad);
5204 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5207 /* ERROR recovery here */
5210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5211 "pullrange, but pad was flushing");
5212 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5213 GST_OBJECT_UNLOCK (pad);
5214 ret = GST_FLOW_FLUSHING;
5219 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5220 GST_DEBUG_PAD_NAME (pad));
5221 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5222 GST_OBJECT_UNLOCK (pad);
5223 ret = GST_FLOW_ERROR;
5228 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5229 gst_flow_get_name (ret));
5230 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5232 /* the probe filled the buffer and asks us to not forward to the peer
5233 * anymore, we continue with the post probes then */
5234 GST_DEBUG_OBJECT (pad, "handled buffer");
5238 /* no buffer, we are EOS then */
5239 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5243 pad->ABI.abi.last_flowret = ret;
5244 GST_OBJECT_UNLOCK (pad);
5249 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5250 "pulling range, but it was not linked");
5251 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5252 GST_OBJECT_UNLOCK (pad);
5253 ret = GST_FLOW_NOT_LINKED;
5258 pad->ABI.abi.last_flowret = ret;
5259 GST_OBJECT_UNLOCK (pad);
5260 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5261 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5262 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5265 probe_stopped_unref:
5267 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5268 "post probe returned %s", gst_flow_get_name (ret));
5270 /* if we drop here, it signals EOS */
5271 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5274 pad->ABI.abi.last_flowret = ret;
5275 GST_OBJECT_UNLOCK (pad);
5277 if (*buffer == NULL)
5278 gst_buffer_unref (res_buf);
5282 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5286 /* must be called with pad object lock */
5287 static GstFlowReturn
5288 store_sticky_event (GstPad * pad, GstEvent * event)
5293 gboolean res = FALSE;
5295 gboolean insert = TRUE;
5297 type = GST_EVENT_TYPE (event);
5299 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5300 * otherwise they can be dropped and nothing would ever resend them.
5301 * Only do that for activated pads though, everything else is a bug!
5303 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5304 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5305 || type == GST_EVENT_EOS))))
5308 /* Unset the EOS flag when received STREAM_START event, so pad can
5309 * store sticky event and then push it later */
5310 if (type == GST_EVENT_STREAM_START) {
5311 GST_LOG_OBJECT (pad, "Removing pending EOS, StreamGroupDone, TAG events");
5312 remove_event_by_type (pad, GST_EVENT_EOS);
5313 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5314 remove_event_by_type (pad, GST_EVENT_TAG);
5315 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5318 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5321 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5322 name_id = gst_structure_get_name_id (gst_event_get_structure (event));
5324 events = pad->priv->events;
5327 for (i = 0; i < len; i++) {
5328 PadEvent *ev = &g_array_index (events, PadEvent, i);
5330 if (ev->event == NULL)
5333 if (type == GST_EVENT_TYPE (ev->event)) {
5334 /* matching types, check matching name if needed */
5335 if (name_id && !gst_event_has_name_id (ev->event, name_id))
5339 if ((res = gst_event_replace (&ev->event, event)))
5340 ev->received = FALSE;
5346 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5347 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5348 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5349 * storing the sticky ordered we can check that this is respected. */
5350 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5351 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5353 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5354 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5355 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5356 gst_event_type_get_name (type));
5362 ev.event = gst_event_ref (event);
5363 ev.received = FALSE;
5364 g_array_insert_val (events, i, ev);
5369 pad->priv->events_cookie++;
5370 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5372 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5374 switch (GST_EVENT_TYPE (event)) {
5375 case GST_EVENT_CAPS:
5376 GST_OBJECT_UNLOCK (pad);
5378 GST_DEBUG_OBJECT (pad, "notify caps");
5379 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5381 GST_OBJECT_LOCK (pad);
5387 if (type == GST_EVENT_EOS) {
5388 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5389 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5392 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5397 GST_DEBUG_OBJECT (pad, "pad is flushing");
5398 return GST_FLOW_FLUSHING;
5402 GST_DEBUG_OBJECT (pad, "pad is EOS");
5403 return GST_FLOW_EOS;
5408 * gst_pad_store_sticky_event:
5410 * @event: (transfer none): a #GstEvent
5412 * Store the sticky @event on @pad
5414 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5415 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5420 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5424 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5425 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5427 GST_OBJECT_LOCK (pad);
5428 ret = store_sticky_event (pad, event);
5429 GST_OBJECT_UNLOCK (pad);
5435 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5437 PushStickyData *data = user_data;
5439 /* Forward all sticky events before our current one that are pending */
5440 if (ev->event != data->event
5441 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5442 return push_sticky (pad, ev, data);
5447 /* should be called with pad LOCK */
5448 static GstFlowReturn
5449 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5450 GstPadProbeType type)
5454 GstEventType event_type;
5455 gint64 old_pad_offset = pad->offset;
5457 /* pass the adjusted event on. We need to do this even if
5458 * there is no peer pad because of the probes. */
5459 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5461 /* Two checks to be made:
5462 * . (un)set the FLUSHING flag for flushing events,
5463 * . handle pad blocking */
5464 event_type = GST_EVENT_TYPE (event);
5465 switch (event_type) {
5466 case GST_EVENT_FLUSH_START:
5467 GST_PAD_SET_FLUSHING (pad);
5469 GST_PAD_BLOCK_BROADCAST (pad);
5470 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5472 case GST_EVENT_FLUSH_STOP:
5473 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5476 GST_PAD_UNSET_FLUSHING (pad);
5478 /* Remove sticky EOS events */
5479 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5480 remove_event_by_type (pad, GST_EVENT_EOS);
5481 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5482 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5483 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5484 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5486 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5490 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5493 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5494 * checked already or this is called as part of pushing sticky events,
5495 * in which case we still want to forward the EOS event downstream.
5498 switch (GST_EVENT_TYPE (event)) {
5499 case GST_EVENT_RECONFIGURE:
5500 if (GST_PAD_IS_SINK (pad))
5501 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5506 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5507 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5508 /* recheck sticky events because the probe might have cause a relink */
5509 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5510 && (GST_EVENT_IS_SERIALIZED (event))) {
5511 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5512 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5514 /* Push all sticky events before our current one
5515 * that have changed */
5516 events_foreach (pad, sticky_changed, &data);
5522 /* send probes after modifying the events above */
5523 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5525 /* recheck sticky events because the probe might have cause a relink */
5526 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5527 && (GST_EVENT_IS_SERIALIZED (event))) {
5528 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5529 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5531 /* Push all sticky events before our current one
5532 * that have changed */
5533 events_foreach (pad, sticky_changed, &data);
5536 /* the pad offset might've been changed by any of the probes above. It
5537 * would've been taken into account when repushing any of the sticky events
5538 * above but not for our current event here */
5539 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5541 _apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad),
5542 pad->offset - old_pad_offset);
5545 /* now check the peer pad */
5546 peerpad = GST_PAD_PEER (pad);
5547 if (peerpad == NULL)
5550 gst_object_ref (peerpad);
5552 GST_OBJECT_UNLOCK (pad);
5554 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5555 event, gst_event_type_get_name (event_type), peerpad);
5557 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5559 /* Note: we gave away ownership of the event at this point but we can still
5560 * print the old pointer */
5561 GST_LOG_OBJECT (pad,
5562 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5563 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5565 gst_object_unref (peerpad);
5567 GST_OBJECT_LOCK (pad);
5569 if (pad->priv->using == 0) {
5570 /* pad is not active anymore, trigger idle callbacks */
5571 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5572 idle_probe_stopped, ret);
5576 /* ERROR handling */
5579 GST_DEBUG_OBJECT (pad, "We're flushing");
5580 gst_event_unref (event);
5581 return GST_FLOW_FLUSHING;
5585 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5586 gst_event_unref (event);
5587 return GST_FLOW_FLUSHING;
5591 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5592 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5593 gst_event_unref (event);
5596 case GST_FLOW_CUSTOM_SUCCESS_1:
5597 GST_DEBUG_OBJECT (pad, "handled event");
5599 case GST_FLOW_CUSTOM_SUCCESS:
5600 GST_DEBUG_OBJECT (pad, "dropped event");
5603 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5610 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5611 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5612 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5613 gst_event_unref (event);
5615 /* unlinked pads should not influence latency configuration */
5616 if (event_type == GST_EVENT_LATENCY)
5619 return GST_FLOW_NOT_LINKED;
5623 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5629 * gst_pad_push_event:
5630 * @pad: a #GstPad to push the event to.
5631 * @event: (transfer full): the #GstEvent to send to the pad.
5633 * Sends the event to the peer of the given pad. This function is
5634 * mainly used by elements to send events to their peer
5637 * This function takes ownership of the provided event so you should
5638 * gst_event_ref() it if you want to reuse the event after this call.
5640 * Returns: %TRUE if the event was handled.
5645 gst_pad_push_event (GstPad * pad, GstEvent * event)
5647 gboolean res = FALSE;
5648 GstPadProbeType type;
5649 gboolean sticky, serialized;
5651 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5652 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5654 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5656 if (GST_PAD_IS_SRC (pad)) {
5657 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5658 goto wrong_direction;
5659 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5660 } else if (GST_PAD_IS_SINK (pad)) {
5661 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5662 goto wrong_direction;
5663 /* events pushed on sinkpad never are sticky */
5664 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5666 goto unknown_direction;
5668 GST_OBJECT_LOCK (pad);
5669 sticky = GST_EVENT_IS_STICKY (event);
5670 serialized = GST_EVENT_IS_SERIALIZED (event);
5673 /* srcpad sticky events are stored immediately, the received flag is set
5674 * to FALSE and will be set to TRUE when we can successfully push the
5675 * event to the peer pad */
5676 switch (store_sticky_event (pad, event)) {
5677 case GST_FLOW_FLUSHING:
5685 if (GST_PAD_IS_SRC (pad) && serialized) {
5686 /* All serialized events on the srcpad trigger push of sticky events.
5688 * Note that we do not do this for non-serialized sticky events since it
5689 * could potentially block. */
5690 res = (check_sticky (pad, event) == GST_FLOW_OK);
5692 if (!serialized || !sticky) {
5695 /* non-serialized and non-sticky events are pushed right away. */
5696 ret = gst_pad_push_event_unchecked (pad, event, type);
5697 /* dropped events by a probe are not an error */
5698 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5699 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5701 /* Errors in sticky event pushing are no problem and ignored here
5702 * as they will cause more meaningful errors during data flow.
5703 * For EOS events, that are not followed by data flow, we still
5704 * return FALSE here though.
5706 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5708 gst_event_unref (event);
5710 GST_OBJECT_UNLOCK (pad);
5712 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5715 /* ERROR handling */
5718 g_warning ("pad %s:%s pushing %s event in wrong direction",
5719 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5720 gst_event_unref (event);
5725 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5726 gst_event_unref (event);
5731 GST_DEBUG_OBJECT (pad, "We're flushing");
5732 GST_OBJECT_UNLOCK (pad);
5733 gst_event_unref (event);
5738 GST_DEBUG_OBJECT (pad, "We're EOS");
5739 GST_OBJECT_UNLOCK (pad);
5740 gst_event_unref (event);
5744 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5748 /* Check if we can call the event function with the given event */
5749 static GstFlowReturn
5750 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5754 switch (GST_EVENT_TYPE (event)) {
5755 case GST_EVENT_CAPS:
5757 /* backwards compatibility mode for caps */
5758 gst_event_parse_caps (event, &caps);
5760 if (!gst_pad_query_accept_caps (pad, caps))
5772 GST_CAT_WARNING_OBJECT (GST_CAT_CAPS, pad,
5773 "caps %" GST_PTR_FORMAT " not accepted", caps);
5774 return GST_FLOW_NOT_NEGOTIATED;
5778 static GstFlowReturn
5779 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5780 GstPadProbeType type)
5783 GstEventType event_type;
5784 gboolean serialized, need_unlock = FALSE, sticky;
5785 GstPadEventFunction eventfunc;
5786 GstPadEventFullFunction eventfullfunc = NULL;
5788 gint64 old_pad_offset;
5790 GST_OBJECT_LOCK (pad);
5792 old_pad_offset = pad->offset;
5793 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5795 if (GST_PAD_IS_SINK (pad))
5796 serialized = GST_EVENT_IS_SERIALIZED (event);
5799 sticky = GST_EVENT_IS_STICKY (event);
5800 event_type = GST_EVENT_TYPE (event);
5801 switch (event_type) {
5802 case GST_EVENT_FLUSH_START:
5803 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5804 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5806 /* can't even accept a flush begin event when flushing */
5807 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5810 GST_PAD_SET_FLUSHING (pad);
5811 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5812 GST_PAD_BLOCK_BROADCAST (pad);
5813 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5815 case GST_EVENT_FLUSH_STOP:
5816 /* we can't accept flush-stop on inactive pads else the flushing flag
5817 * would be cleared and it would look like the pad can accept data.
5818 * Also, some elements restart a streaming thread in flush-stop which we
5819 * can't allow on inactive pads */
5820 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5823 GST_PAD_UNSET_FLUSHING (pad);
5824 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5825 /* Remove pending EOS events */
5826 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5827 remove_event_by_type (pad, GST_EVENT_EOS);
5828 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5829 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5830 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5831 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5833 GST_OBJECT_UNLOCK (pad);
5834 /* grab stream lock */
5835 GST_PAD_STREAM_LOCK (pad);
5837 GST_OBJECT_LOCK (pad);
5838 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5841 case GST_EVENT_RECONFIGURE:
5842 if (GST_PAD_IS_SRC (pad))
5843 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5845 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5846 "have event type %" GST_PTR_FORMAT, event);
5848 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5851 switch (event_type) {
5852 case GST_EVENT_STREAM_START:
5853 /* Take the stream lock to unset the EOS status. This is to ensure
5854 * there isn't any other serialized event passing through while this
5855 * EOS status is being unset */
5856 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5857 GST_OBJECT_UNLOCK (pad);
5858 GST_PAD_STREAM_LOCK (pad);
5860 GST_OBJECT_LOCK (pad);
5861 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5864 /* Remove sticky EOS events */
5865 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5866 remove_event_by_type (pad, GST_EVENT_EOS);
5867 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5868 remove_event_by_type (pad, GST_EVENT_TAG);
5869 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5873 /* Take the stream lock to check the EOS status and drop the event
5874 * if that is the case. */
5875 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5876 GST_OBJECT_UNLOCK (pad);
5877 GST_PAD_STREAM_LOCK (pad);
5879 GST_OBJECT_LOCK (pad);
5880 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5883 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5891 /* now do the probe */
5893 type | GST_PAD_PROBE_TYPE_PUSH |
5894 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5896 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5898 /* the pad offset might've been changed by any of the probes above. It
5899 * would've been taken into account when repushing any of the sticky events
5900 * above but not for our current event here */
5901 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5903 _apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad),
5904 pad->offset - old_pad_offset);
5907 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5908 eventfunc = GST_PAD_EVENTFUNC (pad);
5909 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5912 ACQUIRE_PARENT (pad, parent, no_parent);
5913 GST_OBJECT_UNLOCK (pad);
5915 ret = pre_eventfunc_check (pad, event);
5916 if (G_UNLIKELY (ret != GST_FLOW_OK))
5917 goto precheck_failed;
5920 gst_event_ref (event);
5922 if (eventfullfunc) {
5923 ret = eventfullfunc (pad, parent, event);
5924 } else if (eventfunc (pad, parent, event)) {
5927 /* something went wrong */
5928 switch (event_type) {
5929 case GST_EVENT_CAPS:
5930 ret = GST_FLOW_NOT_NEGOTIATED;
5933 ret = GST_FLOW_ERROR;
5937 RELEASE_PARENT (parent);
5939 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5942 if (ret == GST_FLOW_OK) {
5943 GST_OBJECT_LOCK (pad);
5944 /* after the event function accepted the event, we can store the sticky
5945 * event on the pad */
5946 switch (store_sticky_event (pad, event)) {
5947 case GST_FLOW_FLUSHING:
5954 GST_OBJECT_UNLOCK (pad);
5956 gst_event_unref (event);
5960 GST_PAD_STREAM_UNLOCK (pad);
5964 /* ERROR handling */
5967 GST_OBJECT_UNLOCK (pad);
5969 GST_PAD_STREAM_UNLOCK (pad);
5970 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5971 "Received event on flushing pad. Discarding");
5972 gst_event_unref (event);
5973 return GST_FLOW_FLUSHING;
5977 GST_OBJECT_UNLOCK (pad);
5979 GST_PAD_STREAM_UNLOCK (pad);
5980 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5981 "Received flush-stop on inactive pad. Discarding");
5982 gst_event_unref (event);
5983 return GST_FLOW_FLUSHING;
5987 GST_OBJECT_UNLOCK (pad);
5989 GST_PAD_STREAM_UNLOCK (pad);
5990 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5991 "Received event on EOS pad. Discarding");
5992 gst_event_unref (event);
5993 return GST_FLOW_EOS;
5997 GST_OBJECT_UNLOCK (pad);
5999 GST_PAD_STREAM_UNLOCK (pad);
6000 /* Only unref if unhandled */
6001 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
6002 gst_event_unref (event);
6005 case GST_FLOW_CUSTOM_SUCCESS_1:
6006 case GST_FLOW_CUSTOM_SUCCESS:
6007 GST_DEBUG_OBJECT (pad, "dropped or handled event");
6011 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
6018 g_warning ("pad %s:%s has no event handler, file a bug.",
6019 GST_DEBUG_PAD_NAME (pad));
6020 GST_OBJECT_UNLOCK (pad);
6022 GST_PAD_STREAM_UNLOCK (pad);
6023 gst_event_unref (event);
6024 return GST_FLOW_NOT_SUPPORTED;
6028 GST_DEBUG_OBJECT (pad, "no parent");
6029 GST_OBJECT_UNLOCK (pad);
6031 GST_PAD_STREAM_UNLOCK (pad);
6032 gst_event_unref (event);
6033 return GST_FLOW_FLUSHING;
6037 GST_DEBUG_OBJECT (pad, "pre event check failed");
6038 RELEASE_PARENT (parent);
6040 GST_PAD_STREAM_UNLOCK (pad);
6041 gst_event_unref (event);
6047 * gst_pad_send_event:
6048 * @pad: a #GstPad to send the event to.
6049 * @event: (transfer full): the #GstEvent to send to the pad.
6051 * Sends the event to the pad. This function can be used
6052 * by applications to send events in the pipeline.
6054 * If @pad is a source pad, @event should be an upstream event. If @pad is a
6055 * sink pad, @event should be a downstream event. For example, you would not
6056 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
6057 * Furthermore, some downstream events have to be serialized with data flow,
6058 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
6059 * the event needs to be serialized with data flow, this function will take the
6060 * pad's stream lock while calling its event function.
6062 * To find out whether an event type is upstream, downstream, or downstream and
6063 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
6064 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
6065 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
6066 * plugin doesn't need to bother itself with this information; the core handles
6067 * all necessary locks and checks.
6069 * This function takes ownership of the provided event so you should
6070 * gst_event_ref() it if you want to reuse the event after this call.
6072 * Returns: %TRUE if the event was handled.
6075 gst_pad_send_event (GstPad * pad, GstEvent * event)
6078 GstPadProbeType type;
6080 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6081 g_return_val_if_fail (event != NULL, FALSE);
6083 if (GST_PAD_IS_SINK (pad)) {
6084 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
6085 goto wrong_direction;
6086 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
6087 } else if (GST_PAD_IS_SRC (pad)) {
6088 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
6089 goto wrong_direction;
6090 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
6092 goto unknown_direction;
6094 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
6101 /* ERROR handling */
6104 g_warning ("pad %s:%s sending %s event in wrong direction",
6105 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
6106 gst_event_unref (event);
6111 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
6112 gst_event_unref (event);
6118 * gst_pad_set_element_private:
6119 * @pad: the #GstPad to set the private data of.
6120 * @priv: The private data to attach to the pad.
6122 * Set the given private data gpointer on the pad.
6123 * This function can only be used by the element that owns the pad.
6124 * No locking is performed in this function.
6127 gst_pad_set_element_private (GstPad * pad, gpointer priv)
6129 pad->element_private = priv;
6133 * gst_pad_get_element_private:
6134 * @pad: the #GstPad to get the private data of.
6136 * Gets the private data of a pad.
6137 * No locking is performed in this function.
6139 * Returns: (transfer none) (nullable): a #gpointer to the private data.
6142 gst_pad_get_element_private (GstPad * pad)
6144 return pad->element_private;
6148 * gst_pad_get_sticky_event:
6149 * @pad: the #GstPad to get the event from.
6150 * @event_type: the #GstEventType that should be retrieved.
6151 * @idx: the index of the event
6153 * Returns a new reference of the sticky event of type @event_type
6156 * Returns: (transfer full) (nullable): a #GstEvent of type
6157 * @event_type or %NULL when no event of @event_type was on
6158 * @pad. Unref after usage.
6161 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
6163 GstEvent *event = NULL;
6166 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
6167 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
6169 GST_OBJECT_LOCK (pad);
6170 ev = find_event_by_type (pad, event_type, idx);
6171 if (ev && (event = ev->event))
6172 gst_event_ref (event);
6173 GST_OBJECT_UNLOCK (pad);
6180 GstPadStickyEventsForeachFunction func;
6185 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
6187 ForeachDispatch *data = user_data;
6188 gboolean ret = TRUE;
6191 GST_OBJECT_UNLOCK (pad);
6193 ret = data->func (pad, &ev->event, data->user_data);
6195 GST_OBJECT_LOCK (pad);
6202 * gst_pad_sticky_events_foreach:
6203 * @pad: the #GstPad that should be used for iteration.
6204 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
6205 * should be called for every event.
6206 * @user_data: (closure): the optional user data.
6208 * Iterates all sticky events on @pad and calls @foreach_func for every
6209 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6212 gst_pad_sticky_events_foreach (GstPad * pad,
6213 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6215 ForeachDispatch data;
6217 g_return_if_fail (GST_IS_PAD (pad));
6218 g_return_if_fail (foreach_func != NULL);
6220 data.func = foreach_func;
6221 data.user_data = user_data;
6223 GST_OBJECT_LOCK (pad);
6224 events_foreach (pad, foreach_dispatch_function, &data);
6225 GST_OBJECT_UNLOCK (pad);
6229 do_stream_status (GstPad * pad, GstStreamStatusType type,
6230 GThread * thread, GstTask * task)
6234 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6236 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6237 if (GST_IS_ELEMENT (parent)) {
6238 GstMessage *message;
6239 GValue value = { 0 };
6241 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6244 /* create a good task name (we can directly grab the parent and pad
6245 * names since they both exist at this point, and changing the name of
6246 * parent and pad when a pad is activating is a big no-no). */
6247 tname = g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad));
6249 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6253 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6256 g_value_init (&value, GST_TYPE_TASK);
6257 g_value_set_object (&value, task);
6258 gst_message_set_stream_status_object (message, &value);
6259 g_value_unset (&value);
6261 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6262 gst_element_post_message (parent, message);
6264 gst_object_unref (parent);
6269 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6271 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6276 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6278 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6283 * gst_pad_start_task:
6284 * @pad: the #GstPad to start the task of
6285 * @func: the task function to call
6286 * @user_data: user data passed to the task function
6287 * @notify: called when @user_data is no longer referenced
6289 * Starts a task that repeatedly calls @func with @user_data. This function
6290 * is mostly used in pad activation functions to start the dataflow.
6291 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6292 * before @func is called.
6294 * Returns: a %TRUE if the task could be started.
6297 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6298 GDestroyNotify notify)
6303 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6304 g_return_val_if_fail (func != NULL, FALSE);
6306 GST_DEBUG_OBJECT (pad, "start task");
6308 GST_OBJECT_LOCK (pad);
6309 task = GST_PAD_TASK (pad);
6311 task = gst_task_new (func, user_data, notify);
6312 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6313 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6314 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6315 GST_INFO_OBJECT (pad, "created task %p", task);
6316 GST_PAD_TASK (pad) = task;
6317 gst_object_ref (task);
6318 /* release lock to post the message */
6319 GST_OBJECT_UNLOCK (pad);
6321 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6323 gst_object_unref (task);
6325 GST_OBJECT_LOCK (pad);
6326 /* nobody else is supposed to have changed the pad now */
6327 if (GST_PAD_TASK (pad) != task)
6328 goto concurrent_stop;
6330 res = gst_task_set_state (task, GST_TASK_STARTED);
6331 GST_OBJECT_UNLOCK (pad);
6338 GST_OBJECT_UNLOCK (pad);
6344 * gst_pad_pause_task:
6345 * @pad: the #GstPad to pause the task of
6347 * Pause the task of @pad. This function will also wait until the
6348 * function executed by the task is finished if this function is not
6349 * called from the task function.
6351 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6355 gst_pad_pause_task (GstPad * pad)
6360 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6362 GST_DEBUG_OBJECT (pad, "pause task");
6364 GST_OBJECT_LOCK (pad);
6365 task = GST_PAD_TASK (pad);
6368 res = gst_task_set_state (task, GST_TASK_PAUSED);
6369 /* unblock activation waits if any */
6370 pad->priv->in_activation = FALSE;
6371 g_cond_broadcast (&pad->priv->activation_cond);
6372 GST_OBJECT_UNLOCK (pad);
6374 /* wait for task function to finish, this lock is recursive so it does nothing
6375 * when the pause is called from the task itself */
6376 GST_PAD_STREAM_LOCK (pad);
6377 GST_PAD_STREAM_UNLOCK (pad);
6383 GST_DEBUG_OBJECT (pad, "pad has no task");
6384 GST_OBJECT_UNLOCK (pad);
6390 * gst_pad_get_task_state:
6391 * @pad: the #GstPad to get task state from
6393 * Get @pad task state. If no task is currently
6394 * set, #GST_TASK_STOPPED is returned.
6396 * Returns: The current state of @pad's task.
6401 gst_pad_get_task_state (GstPad * pad)
6406 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6408 GST_OBJECT_LOCK (pad);
6409 task = GST_PAD_TASK (pad);
6412 res = gst_task_get_state (task);
6413 GST_OBJECT_UNLOCK (pad);
6419 GST_DEBUG_OBJECT (pad, "pad has no task");
6420 GST_OBJECT_UNLOCK (pad);
6421 return GST_TASK_STOPPED;
6426 * gst_pad_stop_task:
6427 * @pad: the #GstPad to stop the task of
6429 * Stop the task of @pad. This function will also make sure that the
6430 * function executed by the task will effectively stop if not called
6431 * from the GstTaskFunction.
6433 * This function will deadlock if called from the GstTaskFunction of
6434 * the task. Use gst_task_pause() instead.
6436 * Regardless of whether the pad has a task, the stream lock is acquired and
6437 * released so as to ensure that streaming through this pad has finished.
6439 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6442 gst_pad_stop_task (GstPad * pad)
6447 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6449 GST_DEBUG_OBJECT (pad, "stop task");
6451 GST_OBJECT_LOCK (pad);
6452 task = GST_PAD_TASK (pad);
6455 GST_PAD_TASK (pad) = NULL;
6456 res = gst_task_set_state (task, GST_TASK_STOPPED);
6457 /* unblock activation waits if any */
6458 pad->priv->in_activation = FALSE;
6459 g_cond_broadcast (&pad->priv->activation_cond);
6460 GST_OBJECT_UNLOCK (pad);
6462 GST_PAD_STREAM_LOCK (pad);
6463 GST_PAD_STREAM_UNLOCK (pad);
6465 if (!gst_task_join (task))
6468 gst_object_unref (task);
6474 GST_DEBUG_OBJECT (pad, "no task");
6475 GST_OBJECT_UNLOCK (pad);
6477 GST_PAD_STREAM_LOCK (pad);
6478 GST_PAD_STREAM_UNLOCK (pad);
6480 /* this is not an error */
6485 /* this is bad, possibly the application tried to join the task from
6486 * the task's thread. We install the task again so that it will be stopped
6487 * again from the right thread next time hopefully. */
6488 GST_OBJECT_LOCK (pad);
6489 GST_DEBUG_OBJECT (pad, "join failed");
6490 /* we can only install this task if there was no other task */
6491 if (GST_PAD_TASK (pad) == NULL)
6492 GST_PAD_TASK (pad) = task;
6493 GST_OBJECT_UNLOCK (pad);
6500 * gst_pad_probe_info_get_event:
6501 * @info: a #GstPadProbeInfo
6503 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6507 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6509 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6510 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6512 return GST_PAD_PROBE_INFO_EVENT (info);
6517 * gst_pad_probe_info_get_query:
6518 * @info: a #GstPadProbeInfo
6520 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6524 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6526 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6527 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6529 return GST_PAD_PROBE_INFO_QUERY (info);
6533 * gst_pad_probe_info_get_buffer:
6534 * @info: a #GstPadProbeInfo
6536 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6540 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6542 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6544 return GST_PAD_PROBE_INFO_BUFFER (info);
6548 * gst_pad_probe_info_get_buffer_list:
6549 * @info: a #GstPadProbeInfo
6551 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6555 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6557 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6559 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6563 * gst_pad_get_last_flow_return:
6566 * Gets the #GstFlowReturn return from the last data passed by this pad.
6571 gst_pad_get_last_flow_return (GstPad * pad)
6575 GST_OBJECT_LOCK (pad);
6576 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6577 GST_OBJECT_UNLOCK (pad);