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. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
144 /* counter of how many idle probes are running directly from the add_probe
145 * call. Used to block any data flowing in the pad while the idle callback
146 * Doesn't finish its work */
149 /* conditional and variable used to ensure pads only get (de)activated
150 * by a single thread at a time. Protected by the object lock */
151 GCond activation_cond;
152 gboolean in_activation;
160 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
161 (((GstPad *)(p))->priv->idle_running > 0)
166 GstPadProbeInfo *info;
172 gulong *called_probes;
173 guint n_called_probes;
174 guint called_probes_size;
178 static void gst_pad_dispose (GObject * object);
179 static void gst_pad_finalize (GObject * object);
180 static void gst_pad_set_property (GObject * object, guint prop_id,
181 const GValue * value, GParamSpec * pspec);
182 static void gst_pad_get_property (GObject * object, guint prop_id,
183 GValue * value, GParamSpec * pspec);
185 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
186 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
187 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
188 GstObject * parent, GstBufferList * list);
190 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
191 GstEvent * event, GstPadProbeType type);
192 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
195 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
196 GstPadMode mode, gboolean active);
198 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
200 static GParamSpec *pspec_caps = NULL;
202 /* quarks for probe signals */
203 static GQuark buffer_quark;
204 static GQuark buffer_list_quark;
205 static GQuark event_quark;
214 static GstFlowQuarks flow_quarks[] = {
215 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
216 {GST_FLOW_OK, "ok", 0},
217 {GST_FLOW_NOT_LINKED, "not-linked", 0},
218 {GST_FLOW_FLUSHING, "flushing", 0},
219 {GST_FLOW_EOS, "eos", 0},
220 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
221 {GST_FLOW_ERROR, "error", 0},
222 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
223 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
228 * @ret: a #GstFlowReturn to get the name of.
230 * Gets a string representing the given flow return.
232 * Returns: a static string with the name of the flow return.
235 gst_flow_get_name (GstFlowReturn ret)
239 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
241 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
242 if (ret == flow_quarks[i].ret)
243 return flow_quarks[i].name;
250 * @ret: a #GstFlowReturn to get the quark of.
252 * Get the unique quark for the given GstFlowReturn.
254 * Returns: the quark associated with the flow return or 0 if an
255 * invalid return was specified.
258 gst_flow_to_quark (GstFlowReturn ret)
262 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
264 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
265 if (ret == flow_quarks[i].ret)
266 return flow_quarks[i].quark;
272 * gst_pad_link_get_name:
273 * @ret: a #GstPadLinkReturn to get the name of.
275 * Gets a string representing the given pad-link return.
277 * Returns: a static string with the name of the pad-link return.
282 gst_pad_link_get_name (GstPadLinkReturn ret)
285 case GST_PAD_LINK_OK:
287 case GST_PAD_LINK_WRONG_HIERARCHY:
288 return "wrong hierarchy";
289 case GST_PAD_LINK_WAS_LINKED:
291 case GST_PAD_LINK_WRONG_DIRECTION:
292 return "wrong direction";
293 case GST_PAD_LINK_NOFORMAT:
294 return "no common format";
295 case GST_PAD_LINK_NOSCHED:
296 return "incompatible scheduling";
297 case GST_PAD_LINK_REFUSED:
300 g_return_val_if_reached ("unknown");
307 buffer_quark = g_quark_from_static_string ("buffer"); \
308 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
309 event_quark = g_quark_from_static_string ("event"); \
311 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
312 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
317 #define gst_pad_parent_class parent_class
318 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT,
319 G_ADD_PRIVATE (GstPad) _do_init);
322 gst_pad_class_init (GstPadClass * klass)
324 GObjectClass *gobject_class;
325 GstObjectClass *gstobject_class;
327 gobject_class = G_OBJECT_CLASS (klass);
328 gstobject_class = GST_OBJECT_CLASS (klass);
330 gobject_class->dispose = gst_pad_dispose;
331 gobject_class->finalize = gst_pad_finalize;
332 gobject_class->set_property = gst_pad_set_property;
333 gobject_class->get_property = gst_pad_get_property;
337 * @pad: the pad that emitted the signal
338 * @peer: the peer pad that has been connected
340 * Signals that a pad has been linked to the peer pad.
342 gst_pad_signals[PAD_LINKED] =
343 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
344 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
345 NULL, G_TYPE_NONE, 1, GST_TYPE_PAD);
348 * @pad: the pad that emitted the signal
349 * @peer: the peer pad that has been disconnected
351 * Signals that a pad has been unlinked from the peer pad.
353 gst_pad_signals[PAD_UNLINKED] =
354 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
355 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
356 NULL, G_TYPE_NONE, 1, GST_TYPE_PAD);
358 pspec_caps = g_param_spec_boxed ("caps", "Caps",
359 "The capabilities of the pad", GST_TYPE_CAPS,
360 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
361 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
363 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
364 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
365 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
366 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
368 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
369 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
370 g_param_spec_object ("template", "Template",
371 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
372 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
377 * The offset that will be applied to the running time of the pad.
381 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
382 g_param_spec_int64 ("offset", "Offset",
383 "The running time offset of the pad", 0, G_MAXINT64, 0,
384 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
386 gstobject_class->path_string_separator = ".";
388 /* Register common function pointer descriptions */
389 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
393 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
397 gst_pad_init (GstPad * pad)
399 pad->priv = gst_pad_get_instance_private (pad);
401 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
403 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
404 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
405 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
406 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
407 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
409 GST_PAD_SET_FLUSHING (pad);
411 g_rec_mutex_init (&pad->stream_rec_lock);
413 g_cond_init (&pad->block_cond);
415 g_hook_list_init (&pad->probes, sizeof (GstProbe));
417 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
418 pad->priv->events_cookie = 0;
419 pad->priv->last_cookie = -1;
420 g_cond_init (&pad->priv->activation_cond);
422 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
425 /* called when setting the pad inactive. It removes all sticky events from
426 * the pad. must be called with object lock */
428 remove_events (GstPad * pad)
432 gboolean notify = FALSE;
434 events = pad->priv->events;
437 for (i = 0; i < len; i++) {
438 PadEvent *ev = &g_array_index (events, PadEvent, i);
439 GstEvent *event = ev->event;
443 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
446 gst_event_unref (event);
449 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
450 g_array_set_size (events, 0);
451 pad->priv->events_cookie++;
454 GST_OBJECT_UNLOCK (pad);
456 GST_DEBUG_OBJECT (pad, "notify caps");
457 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
459 GST_OBJECT_LOCK (pad);
463 #define _to_sticky_order(t) gst_event_type_to_sticky_ordering(t)
465 /* should be called with object lock */
467 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
472 guint last_sticky_order = _to_sticky_order (type);
474 events = pad->priv->events;
477 for (i = 0; i < len; i++) {
478 ev = &g_array_index (events, PadEvent, i);
479 if (ev->event == NULL)
482 if (GST_EVENT_TYPE (ev->event) == type) {
486 } else if (ev->sticky_order > last_sticky_order) {
495 /* should be called with OBJECT lock */
497 find_event (GstPad * pad, GstEvent * event)
503 events = pad->priv->events;
506 guint sticky_order = _to_sticky_order (GST_EVENT_TYPE (event));
507 for (i = 0; i < len; i++) {
508 ev = &g_array_index (events, PadEvent, i);
509 if (event == ev->event)
511 else if (ev->sticky_order > sticky_order)
519 /* should be called with OBJECT lock */
521 remove_event_by_type (GstPad * pad, GstEventType type)
527 events = pad->priv->events;
530 guint last_sticky_order = _to_sticky_order (type);
534 ev = &g_array_index (events, PadEvent, i);
535 if (ev->event == NULL)
538 if (ev->sticky_order > last_sticky_order)
540 else if (GST_EVENT_TYPE (ev->event) != type)
543 gst_event_unref (ev->event);
544 g_array_remove_index (events, i);
546 pad->priv->events_cookie++;
554 /* check all events on srcpad against those on sinkpad. All events that are not
555 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
556 * srcpad so that the events will be sent next time */
557 /* should be called with srcpad and sinkpad LOCKS */
559 schedule_events (GstPad * srcpad, GstPad * sinkpad)
564 gboolean pending = FALSE;
566 events = srcpad->priv->events;
569 for (i = 0; i < len; i++) {
570 ev = &g_array_index (events, PadEvent, i);
571 if (ev->event == NULL)
574 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
575 ev->received = FALSE;
580 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
583 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
586 /* should be called with pad LOCK */
588 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
595 events = pad->priv->events;
598 cookie = pad->priv->events_cookie;
602 PadEvent *ev, ev_ret;
604 ev = &g_array_index (events, PadEvent, i);
605 if (G_UNLIKELY (ev->event == NULL))
608 /* take additional ref, func might release the lock */
609 ev_ret.sticky_order = ev->sticky_order;
610 ev_ret.event = gst_event_ref (ev->event);
611 ev_ret.received = ev->received;
613 ret = func (pad, &ev_ret, user_data);
615 /* recheck the cookie, lock might have been released and the list could have
617 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
618 if (G_LIKELY (ev_ret.event))
619 gst_event_unref (ev_ret.event);
623 /* store the received state */
624 ev->received = ev_ret.received;
626 /* if the event changed, we need to do something */
627 if (G_UNLIKELY (ev->event != ev_ret.event)) {
628 if (G_UNLIKELY (ev_ret.event == NULL)) {
629 /* function unreffed and set the event to NULL, remove it */
630 gst_event_unref (ev->event);
631 g_array_remove_index (events, i);
633 cookie = ++pad->priv->events_cookie;
636 /* function gave a new event for us */
637 gst_event_take (&ev->event, ev_ret.event);
640 /* just unref, nothing changed */
641 gst_event_unref (ev_ret.event);
650 /* should be called with LOCK */
652 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream,
657 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
658 GST_STIME_ARGS (pad_offset));
660 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
663 g_assert (!upstream);
665 /* copy segment values */
666 gst_event_copy_segment (event, &segment);
667 gst_event_unref (event);
669 gst_segment_offset_running_time (&segment, segment.format, pad_offset);
670 event = gst_event_new_segment (&segment);
673 event = gst_event_make_writable (event);
674 offset = gst_event_get_running_time_offset (event);
676 offset -= pad_offset;
678 offset += pad_offset;
679 gst_event_set_running_time_offset (event, offset);
684 static inline GstEvent *
685 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
687 if (G_UNLIKELY (pad->offset != 0))
688 return _apply_pad_offset (pad, event, upstream, pad->offset);
692 /* should be called with the OBJECT_LOCK */
694 get_pad_caps (GstPad * pad)
696 GstCaps *caps = NULL;
699 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
701 gst_event_parse_caps (ev->event, &caps);
707 gst_pad_dispose (GObject * object)
709 GstPad *pad = GST_PAD_CAST (object);
712 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
714 /* unlink the peer pad */
715 if ((peer = gst_pad_get_peer (pad))) {
716 /* window for MT unsafeness, someone else could unlink here
717 * and then we call unlink with wrong pads. The unlink
718 * function would catch this and safely return failed. */
719 if (GST_PAD_IS_SRC (pad))
720 gst_pad_unlink (pad, peer);
722 gst_pad_unlink (peer, pad);
724 gst_object_unref (peer);
727 gst_pad_set_pad_template (pad, NULL);
729 GST_OBJECT_LOCK (pad);
731 g_hook_list_clear (&pad->probes);
732 GST_OBJECT_UNLOCK (pad);
734 G_OBJECT_CLASS (parent_class)->dispose (object);
738 gst_pad_finalize (GObject * object)
740 GstPad *pad = GST_PAD_CAST (object);
743 /* in case the task is still around, clean it up */
744 if ((task = GST_PAD_TASK (pad))) {
745 gst_task_join (task);
746 GST_PAD_TASK (pad) = NULL;
747 gst_object_unref (task);
750 if (pad->activatenotify)
751 pad->activatenotify (pad->activatedata);
752 if (pad->activatemodenotify)
753 pad->activatemodenotify (pad->activatemodedata);
755 pad->linknotify (pad->linkdata);
756 if (pad->unlinknotify)
757 pad->unlinknotify (pad->unlinkdata);
758 if (pad->chainnotify)
759 pad->chainnotify (pad->chaindata);
760 if (pad->chainlistnotify)
761 pad->chainlistnotify (pad->chainlistdata);
762 if (pad->getrangenotify)
763 pad->getrangenotify (pad->getrangedata);
764 if (pad->eventnotify)
765 pad->eventnotify (pad->eventdata);
766 if (pad->querynotify)
767 pad->querynotify (pad->querydata);
768 if (pad->iterintlinknotify)
769 pad->iterintlinknotify (pad->iterintlinkdata);
771 g_rec_mutex_clear (&pad->stream_rec_lock);
772 g_cond_clear (&pad->block_cond);
773 g_cond_clear (&pad->priv->activation_cond);
774 g_array_free (pad->priv->events, TRUE);
776 G_OBJECT_CLASS (parent_class)->finalize (object);
780 gst_pad_set_property (GObject * object, guint prop_id,
781 const GValue * value, GParamSpec * pspec)
783 g_return_if_fail (GST_IS_PAD (object));
786 case PAD_PROP_DIRECTION:
787 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
789 case PAD_PROP_TEMPLATE:
790 gst_pad_set_pad_template (GST_PAD_CAST (object),
791 (GstPadTemplate *) g_value_get_object (value));
793 case PAD_PROP_OFFSET:
794 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
797 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
803 gst_pad_get_property (GObject * object, guint prop_id,
804 GValue * value, GParamSpec * pspec)
806 g_return_if_fail (GST_IS_PAD (object));
810 GST_OBJECT_LOCK (object);
811 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
812 GST_OBJECT_UNLOCK (object);
814 case PAD_PROP_DIRECTION:
815 g_value_set_enum (value, GST_PAD_DIRECTION (object));
817 case PAD_PROP_TEMPLATE:
818 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
820 case PAD_PROP_OFFSET:
821 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
824 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
831 * @name: (allow-none): the name of the new pad.
832 * @direction: the #GstPadDirection of the pad.
834 * Creates a new pad with the given name in the given direction.
835 * If name is %NULL, a guaranteed unique name (across all pads)
837 * This function makes a copy of the name so you can safely free the name.
839 * Returns: (transfer floating): a new #GstPad.
844 gst_pad_new (const gchar * name, GstPadDirection direction)
846 return g_object_new (GST_TYPE_PAD,
847 "name", name, "direction", direction, NULL);
851 * gst_pad_new_from_template:
852 * @templ: the pad template to use
853 * @name: (allow-none): the name of the pad
855 * Creates a new pad with the given name from the given template.
856 * If name is %NULL, a guaranteed unique name (across all pads)
858 * This function makes a copy of the name so you can safely free the name.
860 * Returns: (transfer floating): a new #GstPad.
863 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
866 GST_PAD_TEMPLATE_GTYPE (templ) ==
867 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
869 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
871 return g_object_new (pad_type,
872 "name", name, "direction", templ->direction, "template", templ, NULL);
876 * gst_pad_new_from_static_template:
877 * @templ: the #GstStaticPadTemplate to use
878 * @name: the name of the pad
880 * Creates a new pad with the given name from the given static template.
881 * If name is %NULL, a guaranteed unique name (across all pads)
883 * This function makes a copy of the name so you can safely free the name.
885 * Returns: (transfer floating): a new #GstPad.
888 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
892 GstPadTemplate *template;
894 template = gst_static_pad_template_get (templ);
895 pad = gst_pad_new_from_template (template, name);
896 gst_object_unref (template);
900 #define ACQUIRE_PARENT(pad, parent, label) \
902 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
903 gst_object_ref (parent); \
904 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
908 #define RELEASE_PARENT(parent) \
910 if (G_LIKELY (parent)) \
911 gst_object_unref (parent); \
915 * gst_pad_get_direction:
916 * @pad: a #GstPad to get the direction of.
918 * Gets the direction of the pad. The direction of the pad is
919 * decided at construction time so this function does not take
922 * Returns: the #GstPadDirection of the pad.
927 gst_pad_get_direction (GstPad * pad)
929 GstPadDirection result;
931 /* PAD_UNKNOWN is a little silly but we need some sort of
932 * error return value */
933 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
935 result = GST_PAD_DIRECTION (pad);
941 gst_pad_activate_default (GstPad * pad, GstObject * parent)
943 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
945 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
949 * gst_pad_mode_get_name:
950 * @mode: the pad mode
952 * Return the name of a pad mode, for use in debug messages mostly.
954 * Returns: short mnemonic for pad mode @mode
957 gst_pad_mode_get_name (GstPadMode mode)
960 case GST_PAD_MODE_NONE:
962 case GST_PAD_MODE_PUSH:
964 case GST_PAD_MODE_PULL:
972 /* Returns TRUE if pad wasn't already in the new_mode */
974 pre_activate (GstPad * pad, GstPadMode new_mode)
977 case GST_PAD_MODE_NONE:
978 GST_OBJECT_LOCK (pad);
979 while (G_UNLIKELY (pad->priv->in_activation))
980 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
981 if (new_mode == GST_PAD_MODE (pad)) {
982 GST_WARNING_OBJECT (pad,
983 "Pad is already in the process of being deactivated");
984 GST_OBJECT_UNLOCK (pad);
987 pad->priv->in_activation = TRUE;
988 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
989 GST_PAD_SET_FLUSHING (pad);
990 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
991 GST_PAD_MODE (pad) = new_mode;
992 /* unlock blocked pads so element can resume and stop */
993 GST_PAD_BLOCK_BROADCAST (pad);
994 GST_OBJECT_UNLOCK (pad);
996 case GST_PAD_MODE_PUSH:
997 case GST_PAD_MODE_PULL:
998 GST_OBJECT_LOCK (pad);
999 while (G_UNLIKELY (pad->priv->in_activation))
1000 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1001 if (new_mode == GST_PAD_MODE (pad)) {
1002 GST_WARNING_OBJECT (pad,
1003 "Pad is already in the process of being activated");
1004 GST_OBJECT_UNLOCK (pad);
1007 pad->priv->in_activation = TRUE;
1008 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1009 gst_pad_mode_get_name (new_mode));
1010 GST_PAD_UNSET_FLUSHING (pad);
1011 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1012 GST_PAD_MODE (pad) = new_mode;
1013 if (GST_PAD_IS_SINK (pad)) {
1015 /* make sure the peer src pad sends us all events */
1016 if ((peer = GST_PAD_PEER (pad))) {
1017 gst_object_ref (peer);
1018 GST_OBJECT_UNLOCK (pad);
1020 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1021 GST_DEBUG_PAD_NAME (peer));
1023 GST_OBJECT_LOCK (peer);
1024 schedule_events (peer, NULL);
1025 GST_OBJECT_UNLOCK (peer);
1027 gst_object_unref (peer);
1029 GST_OBJECT_UNLOCK (pad);
1032 GST_OBJECT_UNLOCK (pad);
1040 post_activate (GstPad * pad, GstPadMode new_mode)
1043 case GST_PAD_MODE_NONE:
1044 GST_OBJECT_LOCK (pad);
1045 pad->priv->in_activation = FALSE;
1046 g_cond_broadcast (&pad->priv->activation_cond);
1047 GST_OBJECT_UNLOCK (pad);
1049 /* ensures that streaming stops */
1050 GST_PAD_STREAM_LOCK (pad);
1051 GST_DEBUG_OBJECT (pad, "stopped streaming");
1052 GST_OBJECT_LOCK (pad);
1053 remove_events (pad);
1054 GST_OBJECT_UNLOCK (pad);
1055 GST_PAD_STREAM_UNLOCK (pad);
1057 case GST_PAD_MODE_PUSH:
1058 case GST_PAD_MODE_PULL:
1059 GST_OBJECT_LOCK (pad);
1060 pad->priv->in_activation = FALSE;
1061 g_cond_broadcast (&pad->priv->activation_cond);
1062 GST_OBJECT_UNLOCK (pad);
1069 * gst_pad_set_active:
1070 * @pad: the #GstPad to activate or deactivate.
1071 * @active: whether or not the pad should be active.
1073 * Activates or deactivates the given pad.
1074 * Normally called from within core state change functions.
1076 * If @active, makes sure the pad is active. If it is already active, either in
1077 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1078 * function to perform the actual activation.
1080 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1081 * and a %FALSE argument.
1083 * Returns: %TRUE if the operation was successful.
1088 gst_pad_set_active (GstPad * pad, gboolean active)
1092 gboolean ret = FALSE;
1094 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1096 GST_OBJECT_LOCK (pad);
1097 old = GST_PAD_MODE (pad);
1098 ACQUIRE_PARENT (pad, parent, no_parent);
1099 GST_OBJECT_UNLOCK (pad);
1102 if (old == GST_PAD_MODE_NONE) {
1103 GST_DEBUG_OBJECT (pad, "activating pad from none");
1104 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1106 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1108 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1109 gst_pad_mode_get_name (old));
1113 if (old == GST_PAD_MODE_NONE) {
1114 GST_DEBUG_OBJECT (pad, "pad was inactive");
1117 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1118 gst_pad_mode_get_name (old));
1119 ret = activate_mode_internal (pad, parent, old, FALSE);
1121 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1125 RELEASE_PARENT (parent);
1127 if (G_UNLIKELY (!ret))
1135 GST_DEBUG_OBJECT (pad, "no parent");
1136 GST_OBJECT_UNLOCK (pad);
1141 GST_OBJECT_LOCK (pad);
1143 g_critical ("Failed to deactivate pad %s:%s, very bad",
1144 GST_DEBUG_PAD_NAME (pad));
1146 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1148 GST_OBJECT_UNLOCK (pad);
1154 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1157 gboolean res = FALSE;
1158 GstPadMode old, new;
1159 GstPadDirection dir;
1162 GST_OBJECT_LOCK (pad);
1163 old = GST_PAD_MODE (pad);
1164 dir = GST_PAD_DIRECTION (pad);
1165 GST_OBJECT_UNLOCK (pad);
1167 new = active ? mode : GST_PAD_MODE_NONE;
1172 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1173 /* pad was activate in the wrong direction, deactivate it
1174 * and reactivate it in the requested mode */
1175 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1176 gst_pad_mode_get_name (old));
1178 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1179 goto deactivate_failed;
1180 old = GST_PAD_MODE_NONE;
1184 case GST_PAD_MODE_PULL:
1186 if (dir == GST_PAD_SINK) {
1187 if ((peer = gst_pad_get_peer (pad))) {
1188 GST_DEBUG_OBJECT (pad, "calling peer");
1189 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1191 gst_object_unref (peer);
1193 /* there is no peer, this is only fatal when we activate. When we
1194 * deactivate, we must assume the application has unlinked the peer and
1195 * will deactivate it eventually. */
1199 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1202 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1203 goto failure; /* Can't activate pull on a src without a
1204 getrange function */
1212 /* Mark pad as needing reconfiguration */
1214 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1216 /* pre_activate returns TRUE if we weren't already in the process of
1217 * switching to the 'new' mode */
1218 if (pre_activate (pad, new)) {
1220 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1221 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1225 /* can happen for sinks of passthrough elements */
1228 post_activate (pad, new);
1231 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1232 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1237 /* Clear sticky flags on deactivation */
1239 GST_OBJECT_LOCK (pad);
1240 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1241 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1242 GST_OBJECT_UNLOCK (pad);
1250 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1251 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1256 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1257 "failed to %s in switch to %s mode from %s mode",
1258 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1259 gst_pad_mode_get_name (old));
1264 GST_OBJECT_LOCK (peer);
1265 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1266 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1267 GST_OBJECT_UNLOCK (peer);
1268 gst_object_unref (peer);
1273 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1274 "pad in pull mode");
1279 GST_OBJECT_LOCK (pad);
1280 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1281 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1282 GST_PAD_SET_FLUSHING (pad);
1283 GST_PAD_MODE (pad) = old;
1284 pad->priv->in_activation = FALSE;
1285 g_cond_broadcast (&pad->priv->activation_cond);
1286 GST_OBJECT_UNLOCK (pad);
1292 * gst_pad_activate_mode:
1293 * @pad: the #GstPad to activate or deactivate.
1294 * @mode: the requested activation mode
1295 * @active: whether or not the pad should be active.
1297 * Activates or deactivates the given pad in @mode via dispatching to the
1298 * pad's activatemodefunc. For use from within pad activation functions only.
1300 * If you don't know what this is, you probably don't want to call it.
1302 * Returns: %TRUE if the operation was successful.
1307 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1311 GstPadMode old, new;
1313 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1315 GST_OBJECT_LOCK (pad);
1317 old = GST_PAD_MODE (pad);
1318 new = active ? mode : GST_PAD_MODE_NONE;
1322 ACQUIRE_PARENT (pad, parent, no_parent);
1324 GST_OBJECT_UNLOCK (pad);
1326 res = activate_mode_internal (pad, parent, mode, active);
1328 RELEASE_PARENT (parent);
1334 GST_OBJECT_UNLOCK (pad);
1335 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1336 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1341 GST_WARNING_OBJECT (pad, "no parent");
1342 GST_OBJECT_UNLOCK (pad);
1348 * gst_pad_is_active:
1349 * @pad: the #GstPad to query
1351 * Query if a pad is active
1353 * Returns: %TRUE if the pad is active.
1358 gst_pad_is_active (GstPad * pad)
1360 gboolean result = FALSE;
1362 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1364 GST_OBJECT_LOCK (pad);
1365 result = GST_PAD_IS_ACTIVE (pad);
1366 GST_OBJECT_UNLOCK (pad);
1372 cleanup_hook (GstPad * pad, GHook * hook)
1374 GstPadProbeType type;
1376 GST_DEBUG_OBJECT (pad,
1377 "cleaning up hook %lu with flags %08x", hook->hook_id, hook->flags);
1379 if (!G_HOOK_IS_VALID (hook)) {
1380 /* We've already destroyed this hook */
1384 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1386 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1387 /* unblock when we remove the last blocking probe */
1389 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1392 /* Might have new probes now that want to be called */
1393 GST_PAD_BLOCK_BROADCAST (pad);
1395 if (pad->num_blocked == 0) {
1396 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1397 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1400 g_hook_destroy_link (&pad->probes, hook);
1405 * gst_pad_add_probe:
1406 * @pad: the #GstPad to add the probe to
1407 * @mask: the probe mask
1408 * @callback: #GstPadProbeCallback that will be called with notifications of
1410 * @user_data: (closure): user data passed to the callback
1411 * @destroy_data: #GDestroyNotify for user_data
1413 * Be notified of different states of pads. The provided callback is called for
1414 * every state that matches @mask.
1416 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1417 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1418 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1419 * immediately if the pad is already idle while calling gst_pad_add_probe().
1420 * In each of the groups, probes are called in the order in which they were
1423 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1424 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1425 * happen that the probe can be run immediately and if the probe returns
1426 * GST_PAD_PROBE_REMOVE this functions returns 0.
1431 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1432 GstPadProbeCallback callback, gpointer user_data,
1433 GDestroyNotify destroy_data)
1438 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1439 g_return_val_if_fail (mask != 0, 0);
1441 GST_OBJECT_LOCK (pad);
1443 /* make a new probe */
1444 hook = g_hook_alloc (&pad->probes);
1446 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1449 /* when no constraints are given for the types, assume all types are
1451 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1452 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1453 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1454 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1456 /* store our flags and other fields */
1457 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1458 hook->func = callback;
1459 hook->data = user_data;
1460 hook->destroy = destroy_data;
1463 g_hook_append (&pad->probes, hook);
1465 /* incremenent cookie so that the new hook gets called */
1466 pad->priv->probe_list_cookie++;
1468 /* get the id of the hook, we return this and it can be used to remove the
1470 res = hook->hook_id;
1472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1474 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1475 /* we have a block probe */
1477 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1478 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1479 "now %d blocking probes", pad->num_blocked);
1481 /* Might have new probes now that want to be called */
1482 GST_PAD_BLOCK_BROADCAST (pad);
1485 /* call the callback if we need to be called for idle callbacks */
1486 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1487 if (pad->priv->using > 0) {
1488 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1489 * flag above, the last thread to leave the push will do the callback. New
1490 * threads going into the push will block. */
1491 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1492 "pad is in use, delay idle callback");
1493 GST_OBJECT_UNLOCK (pad);
1495 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1496 GstPadProbeReturn ret;
1498 /* Keep another ref, the callback could destroy the pad */
1499 gst_object_ref (pad);
1500 pad->priv->idle_running++;
1502 /* Ref the hook, it could be destroyed by the callback or concurrently */
1503 g_hook_ref (&pad->probes, hook);
1505 /* the pad is idle now, we can signal the idle callback now */
1506 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1507 "pad is idle, trigger idle callback");
1508 GST_OBJECT_UNLOCK (pad);
1510 ret = callback (pad, &info, user_data);
1512 GST_OBJECT_LOCK (pad);
1514 case GST_PAD_PROBE_REMOVE:
1515 /* remove the probe */
1516 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1517 cleanup_hook (pad, hook);
1520 case GST_PAD_PROBE_DROP:
1521 GST_DEBUG_OBJECT (pad, "asked to drop item");
1523 case GST_PAD_PROBE_PASS:
1524 GST_DEBUG_OBJECT (pad, "asked to pass item");
1526 case GST_PAD_PROBE_OK:
1527 GST_DEBUG_OBJECT (pad, "probe returned OK");
1529 case GST_PAD_PROBE_HANDLED:
1530 GST_DEBUG_OBJECT (pad, "probe handled the data");
1533 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1536 g_hook_unref (&pad->probes, hook);
1537 pad->priv->idle_running--;
1538 if (pad->priv->idle_running == 0) {
1539 GST_PAD_BLOCK_BROADCAST (pad);
1541 GST_OBJECT_UNLOCK (pad);
1543 gst_object_unref (pad);
1546 GST_OBJECT_UNLOCK (pad);
1552 * gst_pad_remove_probe:
1553 * @pad: the #GstPad with the probe
1554 * @id: the probe id to remove
1556 * Remove the probe with @id from @pad.
1561 gst_pad_remove_probe (GstPad * pad, gulong id)
1565 g_return_if_fail (GST_IS_PAD (pad));
1567 GST_OBJECT_LOCK (pad);
1569 hook = g_hook_get (&pad->probes, id);
1573 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1575 cleanup_hook (pad, hook);
1576 GST_OBJECT_UNLOCK (pad);
1582 GST_OBJECT_UNLOCK (pad);
1583 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1589 * gst_pad_is_blocked:
1590 * @pad: the #GstPad to query
1592 * Checks if the pad is blocked or not. This function returns the
1593 * last requested state of the pad. It is not certain that the pad
1594 * is actually blocking at this point (see gst_pad_is_blocking()).
1596 * Returns: %TRUE if the pad is blocked.
1601 gst_pad_is_blocked (GstPad * pad)
1603 gboolean result = FALSE;
1605 g_return_val_if_fail (GST_IS_PAD (pad), result);
1607 GST_OBJECT_LOCK (pad);
1608 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1609 GST_OBJECT_UNLOCK (pad);
1615 * gst_pad_is_blocking:
1616 * @pad: the #GstPad to query
1618 * Checks if the pad is blocking or not. This is a guaranteed state
1619 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1621 * Returns: %TRUE if the pad is blocking.
1626 gst_pad_is_blocking (GstPad * pad)
1628 gboolean result = FALSE;
1630 g_return_val_if_fail (GST_IS_PAD (pad), result);
1632 GST_OBJECT_LOCK (pad);
1633 /* the blocking flag is only valid if the pad is not flushing */
1634 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1635 GST_OBJECT_UNLOCK (pad);
1641 * gst_pad_needs_reconfigure:
1642 * @pad: the #GstPad to check
1644 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1645 * if the flag was set.
1647 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1650 gst_pad_needs_reconfigure (GstPad * pad)
1652 gboolean reconfigure;
1654 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1656 GST_OBJECT_LOCK (pad);
1657 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1658 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1659 GST_OBJECT_UNLOCK (pad);
1665 * gst_pad_check_reconfigure:
1666 * @pad: the #GstPad to check
1668 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1669 * if the flag was set.
1671 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1674 gst_pad_check_reconfigure (GstPad * pad)
1676 gboolean reconfigure;
1678 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1680 GST_OBJECT_LOCK (pad);
1681 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1683 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1684 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1686 GST_OBJECT_UNLOCK (pad);
1692 * gst_pad_mark_reconfigure:
1693 * @pad: the #GstPad to mark
1695 * Mark a pad for needing reconfiguration. The next call to
1696 * gst_pad_check_reconfigure() will return %TRUE after this call.
1699 gst_pad_mark_reconfigure (GstPad * pad)
1701 g_return_if_fail (GST_IS_PAD (pad));
1703 GST_OBJECT_LOCK (pad);
1704 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1705 GST_OBJECT_UNLOCK (pad);
1709 * gst_pad_set_activate_function:
1711 * @f: the #GstPadActivateFunction to set.
1713 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1717 * gst_pad_set_activate_function_full:
1719 * @activate: the #GstPadActivateFunction to set.
1720 * @user_data: user_data passed to @notify
1721 * @notify: notify called when @activate will not be used anymore.
1723 * Sets the given activate function for @pad. The activate function will
1724 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1725 * Only makes sense to set on sink pads.
1727 * Call this function if your sink pad can start a pull-based task.
1730 gst_pad_set_activate_function_full (GstPad * pad,
1731 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1733 g_return_if_fail (GST_IS_PAD (pad));
1735 if (pad->activatenotify)
1736 pad->activatenotify (pad->activatedata);
1737 GST_PAD_ACTIVATEFUNC (pad) = activate;
1738 pad->activatedata = user_data;
1739 pad->activatenotify = notify;
1741 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1742 GST_DEBUG_FUNCPTR_NAME (activate));
1746 * gst_pad_set_activatemode_function:
1748 * @f: the #GstPadActivateModeFunction to set.
1750 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1754 * gst_pad_set_activatemode_function_full:
1756 * @activatemode: the #GstPadActivateModeFunction to set.
1757 * @user_data: user_data passed to @notify
1758 * @notify: notify called when @activatemode will not be used anymore.
1760 * Sets the given activate_mode function for the pad. An activate_mode function
1761 * prepares the element for data passing.
1764 gst_pad_set_activatemode_function_full (GstPad * pad,
1765 GstPadActivateModeFunction activatemode, gpointer user_data,
1766 GDestroyNotify notify)
1768 g_return_if_fail (GST_IS_PAD (pad));
1770 if (pad->activatemodenotify)
1771 pad->activatemodenotify (pad->activatemodedata);
1772 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1773 pad->activatemodedata = user_data;
1774 pad->activatemodenotify = notify;
1776 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1777 GST_DEBUG_FUNCPTR_NAME (activatemode));
1781 * gst_pad_set_chain_function:
1782 * @p: a sink #GstPad.
1783 * @f: the #GstPadChainFunction to set.
1785 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1789 * gst_pad_set_chain_function_full:
1790 * @pad: a sink #GstPad.
1791 * @chain: the #GstPadChainFunction to set.
1792 * @user_data: user_data passed to @notify
1793 * @notify: notify called when @chain will not be used anymore.
1795 * Sets the given chain function for the pad. The chain function is called to
1796 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1799 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1800 gpointer user_data, GDestroyNotify notify)
1802 g_return_if_fail (GST_IS_PAD (pad));
1803 g_return_if_fail (GST_PAD_IS_SINK (pad));
1805 if (pad->chainnotify)
1806 pad->chainnotify (pad->chaindata);
1807 GST_PAD_CHAINFUNC (pad) = chain;
1808 pad->chaindata = user_data;
1809 pad->chainnotify = notify;
1811 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1812 GST_DEBUG_FUNCPTR_NAME (chain));
1816 * gst_pad_set_chain_list_function:
1817 * @p: a sink #GstPad.
1818 * @f: the #GstPadChainListFunction to set.
1820 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1824 * gst_pad_set_chain_list_function_full:
1825 * @pad: a sink #GstPad.
1826 * @chainlist: the #GstPadChainListFunction to set.
1827 * @user_data: user_data passed to @notify
1828 * @notify: notify called when @chainlist will not be used anymore.
1830 * Sets the given chain list function for the pad. The chainlist function is
1831 * called to process a #GstBufferList input buffer list. See
1832 * #GstPadChainListFunction for more details.
1835 gst_pad_set_chain_list_function_full (GstPad * pad,
1836 GstPadChainListFunction chainlist, gpointer user_data,
1837 GDestroyNotify notify)
1839 g_return_if_fail (GST_IS_PAD (pad));
1840 g_return_if_fail (GST_PAD_IS_SINK (pad));
1842 if (pad->chainlistnotify)
1843 pad->chainlistnotify (pad->chainlistdata);
1844 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1845 pad->chainlistdata = user_data;
1846 pad->chainlistnotify = notify;
1848 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1849 GST_DEBUG_FUNCPTR_NAME (chainlist));
1853 * gst_pad_set_getrange_function:
1854 * @p: a source #GstPad.
1855 * @f: the #GstPadGetRangeFunction to set.
1857 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1861 * gst_pad_set_getrange_function_full:
1862 * @pad: a source #GstPad.
1863 * @get: the #GstPadGetRangeFunction to set.
1864 * @user_data: user_data passed to @notify
1865 * @notify: notify called when @get will not be used anymore.
1867 * Sets the given getrange function for the pad. The getrange function is
1868 * called to produce a new #GstBuffer to start the processing pipeline. see
1869 * #GstPadGetRangeFunction for a description of the getrange function.
1872 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1873 gpointer user_data, GDestroyNotify notify)
1875 g_return_if_fail (GST_IS_PAD (pad));
1876 g_return_if_fail (GST_PAD_IS_SRC (pad));
1878 if (pad->getrangenotify)
1879 pad->getrangenotify (pad->getrangedata);
1880 GST_PAD_GETRANGEFUNC (pad) = get;
1881 pad->getrangedata = user_data;
1882 pad->getrangenotify = notify;
1884 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1885 GST_DEBUG_FUNCPTR_NAME (get));
1889 * gst_pad_set_event_function:
1890 * @p: a #GstPad of either direction.
1891 * @f: the #GstPadEventFunction to set.
1893 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1897 * gst_pad_set_event_function_full:
1898 * @pad: a #GstPad of either direction.
1899 * @event: the #GstPadEventFunction to set.
1900 * @user_data: user_data passed to @notify
1901 * @notify: notify called when @event will not be used anymore.
1903 * Sets the given event handler for the pad.
1906 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1907 gpointer user_data, GDestroyNotify notify)
1909 g_return_if_fail (GST_IS_PAD (pad));
1911 if (pad->eventnotify)
1912 pad->eventnotify (pad->eventdata);
1913 GST_PAD_EVENTFUNC (pad) = event;
1914 pad->eventdata = user_data;
1915 pad->eventnotify = notify;
1917 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1918 GST_DEBUG_FUNCPTR_NAME (event));
1922 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1926 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1927 if (ret == GST_FLOW_OK)
1933 * gst_pad_set_event_full_function:
1934 * @p: a #GstPad of either direction.
1935 * @f: the #GstPadEventFullFunction to set.
1937 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1941 * gst_pad_set_event_full_function_full:
1942 * @pad: a #GstPad of either direction.
1943 * @event: the #GstPadEventFullFunction to set.
1944 * @user_data: user_data passed to @notify
1945 * @notify: notify called when @event will not be used anymore.
1947 * Sets the given event handler for the pad.
1952 gst_pad_set_event_full_function_full (GstPad * pad,
1953 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1955 g_return_if_fail (GST_IS_PAD (pad));
1957 if (pad->eventnotify)
1958 pad->eventnotify (pad->eventdata);
1959 GST_PAD_EVENTFULLFUNC (pad) = event;
1960 GST_PAD_EVENTFUNC (pad) = event_wrap;
1961 pad->eventdata = user_data;
1962 pad->eventnotify = notify;
1964 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1965 GST_DEBUG_FUNCPTR_NAME (event));
1969 * gst_pad_set_query_function:
1970 * @p: a #GstPad of either direction.
1971 * @f: the #GstPadQueryFunction to set.
1973 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1977 * gst_pad_set_query_function_full:
1978 * @pad: a #GstPad of either direction.
1979 * @query: the #GstPadQueryFunction to set.
1980 * @user_data: user_data passed to @notify
1981 * @notify: notify called when @query will not be used anymore.
1983 * Set the given query function for the pad.
1986 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1987 gpointer user_data, GDestroyNotify notify)
1989 g_return_if_fail (GST_IS_PAD (pad));
1991 if (pad->querynotify)
1992 pad->querynotify (pad->querydata);
1993 GST_PAD_QUERYFUNC (pad) = query;
1994 pad->querydata = user_data;
1995 pad->querynotify = notify;
1997 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1998 GST_DEBUG_FUNCPTR_NAME (query));
2002 * gst_pad_set_iterate_internal_links_function:
2003 * @p: a #GstPad of either direction.
2004 * @f: the #GstPadIterIntLinkFunction to set.
2006 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
2007 * for the user_data and notify.
2010 * gst_pad_set_iterate_internal_links_function_full:
2011 * @pad: a #GstPad of either direction.
2012 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2013 * @user_data: user_data passed to @notify
2014 * @notify: notify called when @iterintlink will not be used anymore.
2016 * Sets the given internal link iterator function for the pad.
2019 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2020 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2021 GDestroyNotify notify)
2023 g_return_if_fail (GST_IS_PAD (pad));
2025 if (pad->iterintlinknotify)
2026 pad->iterintlinknotify (pad->iterintlinkdata);
2027 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2028 pad->iterintlinkdata = user_data;
2029 pad->iterintlinknotify = notify;
2031 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2032 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2036 * gst_pad_set_link_function:
2038 * @f: the #GstPadLinkFunction to set.
2040 * Calls gst_pad_set_link_function_full() with %NULL
2041 * for the user_data and notify.
2044 * gst_pad_set_link_function_full:
2046 * @link: the #GstPadLinkFunction to set.
2047 * @user_data: user_data passed to @notify
2048 * @notify: notify called when @link will not be used anymore.
2050 * Sets the given link function for the pad. It will be called when
2051 * the pad is linked with another pad.
2053 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2056 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2057 * cannot be made for some reason.
2059 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2060 * of the peer sink pad, if present.
2063 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2064 gpointer user_data, GDestroyNotify notify)
2066 g_return_if_fail (GST_IS_PAD (pad));
2068 if (pad->linknotify)
2069 pad->linknotify (pad->linkdata);
2070 GST_PAD_LINKFUNC (pad) = link;
2071 pad->linkdata = user_data;
2072 pad->linknotify = notify;
2074 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2075 GST_DEBUG_FUNCPTR_NAME (link));
2079 * gst_pad_set_unlink_function:
2081 * @f: the #GstPadUnlinkFunction to set.
2083 * Calls gst_pad_set_unlink_function_full() with %NULL
2084 * for the user_data and notify.
2087 * gst_pad_set_unlink_function_full:
2089 * @unlink: the #GstPadUnlinkFunction to set.
2090 * @user_data: user_data passed to @notify
2091 * @notify: notify called when @unlink will not be used anymore.
2093 * Sets the given unlink function for the pad. It will be called
2094 * when the pad is unlinked.
2096 * Note that the pad's lock is already held when the unlink
2097 * function is called, so most pad functions cannot be called
2098 * from within the callback.
2101 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2102 gpointer user_data, GDestroyNotify notify)
2104 g_return_if_fail (GST_IS_PAD (pad));
2106 if (pad->unlinknotify)
2107 pad->unlinknotify (pad->unlinkdata);
2108 GST_PAD_UNLINKFUNC (pad) = unlink;
2109 pad->unlinkdata = user_data;
2110 pad->unlinknotify = notify;
2112 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2113 GST_DEBUG_FUNCPTR_NAME (unlink));
2118 * @srcpad: the source #GstPad to unlink.
2119 * @sinkpad: the sink #GstPad to unlink.
2121 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2122 * signal on both pads.
2124 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2125 * the pads were not linked together.
2130 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2132 gboolean result = FALSE;
2133 GstElement *parent = NULL;
2135 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2136 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2137 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2138 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2140 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2142 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2143 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2144 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2146 /* We need to notify the parent before taking any pad locks as the bin in
2147 * question might be waiting for a lock on the pad while holding its lock
2148 * that our message will try to take. */
2149 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2150 if (GST_IS_ELEMENT (parent)) {
2151 gst_element_post_message (parent,
2152 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2153 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2155 gst_object_unref (parent);
2160 GST_OBJECT_LOCK (srcpad);
2161 GST_OBJECT_LOCK (sinkpad);
2163 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2164 goto not_linked_together;
2166 if (GST_PAD_UNLINKFUNC (srcpad)) {
2167 GstObject *tmpparent;
2169 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2171 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2172 RELEASE_PARENT (tmpparent);
2175 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2176 GstObject *tmpparent;
2178 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2180 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2181 RELEASE_PARENT (tmpparent);
2185 /* first clear peers */
2186 GST_PAD_PEER (srcpad) = NULL;
2187 GST_PAD_PEER (sinkpad) = NULL;
2189 GST_OBJECT_UNLOCK (sinkpad);
2190 GST_OBJECT_UNLOCK (srcpad);
2192 /* fire off a signal to each of the pads telling them
2193 * that they've been unlinked */
2194 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2195 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2197 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2198 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2203 if (parent != NULL) {
2204 gst_element_post_message (parent,
2205 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2206 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2207 gst_object_unref (parent);
2209 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2213 not_linked_together:
2215 /* we do not emit a warning in this case because unlinking cannot
2216 * be made MT safe.*/
2217 GST_OBJECT_UNLOCK (sinkpad);
2218 GST_OBJECT_UNLOCK (srcpad);
2224 * gst_pad_is_linked:
2225 * @pad: pad to check
2227 * Checks if a @pad is linked to another pad or not.
2229 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2234 gst_pad_is_linked (GstPad * pad)
2238 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2240 GST_OBJECT_LOCK (pad);
2241 result = (GST_PAD_PEER (pad) != NULL);
2242 GST_OBJECT_UNLOCK (pad);
2247 /* get the caps from both pads and see if the intersection
2250 * This function should be called with the pad LOCK on both
2254 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2255 GstPadLinkCheck flags)
2257 GstCaps *srccaps = NULL;
2258 GstCaps *sinkcaps = NULL;
2259 gboolean compatible = FALSE;
2261 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2264 /* Doing the expensive caps checking takes priority over only checking the template caps */
2265 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2266 GST_OBJECT_UNLOCK (sink);
2267 GST_OBJECT_UNLOCK (src);
2269 srccaps = gst_pad_query_caps (src, NULL);
2270 sinkcaps = gst_pad_query_caps (sink, NULL);
2272 GST_OBJECT_LOCK (src);
2273 GST_OBJECT_LOCK (sink);
2275 /* If one of the two pads doesn't have a template, consider the intersection
2277 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2278 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2282 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2284 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2287 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2289 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2292 /* if we have caps on both pads we can check the intersection. If one
2293 * of the caps is %NULL, we return %TRUE. */
2294 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2296 gst_caps_unref (srccaps);
2298 gst_caps_unref (sinkcaps);
2302 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2303 gst_caps_unref (srccaps);
2304 gst_caps_unref (sinkcaps);
2307 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2308 (compatible ? "" : "not "));
2313 /* check if the grandparents of both pads are the same.
2314 * This check is required so that we don't try to link
2315 * pads from elements in different bins without ghostpads.
2317 * The LOCK should be held on both pads
2320 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2322 GstObject *psrc, *psink;
2324 psrc = GST_OBJECT_PARENT (src);
2325 psink = GST_OBJECT_PARENT (sink);
2327 /* if one of the pads has no parent, we allow the link */
2328 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2331 /* only care about parents that are elements */
2332 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2333 goto no_element_parent;
2335 /* if the parents are the same, we have a loop */
2336 if (G_UNLIKELY (psrc == psink))
2339 /* if they both have a parent, we check the grandparents. We can not lock
2340 * the parent because we hold on the child (pad) and the locking order is
2341 * parent >> child. */
2342 psrc = GST_OBJECT_PARENT (psrc);
2343 psink = GST_OBJECT_PARENT (psink);
2345 /* if they have grandparents but they are not the same */
2346 if (G_UNLIKELY (psrc != psink))
2347 goto wrong_grandparents;
2354 GST_CAT_DEBUG (GST_CAT_CAPS,
2355 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2356 GST_PTR_FORMAT, psrc, psink);
2361 GST_CAT_DEBUG (GST_CAT_CAPS,
2362 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2363 GST_PTR_FORMAT, psrc, psink);
2368 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2374 GST_CAT_DEBUG (GST_CAT_CAPS,
2375 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2376 GST_PTR_FORMAT, psrc, psink);
2381 /* FIXME leftover from an attempt at refactoring... */
2382 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2383 * the two pads will be locked in the srcpad, sinkpad order. */
2384 static GstPadLinkReturn
2385 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2387 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2388 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2390 GST_OBJECT_LOCK (srcpad);
2392 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2393 goto src_was_linked;
2395 GST_OBJECT_LOCK (sinkpad);
2397 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2398 goto sink_was_linked;
2400 /* check hierarchy, pads can only be linked if the grandparents
2402 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2403 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2404 goto wrong_hierarchy;
2406 /* check pad caps for non-empty intersection */
2407 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2410 /* FIXME check pad scheduling for non-empty intersection */
2412 return GST_PAD_LINK_OK;
2416 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2417 GST_DEBUG_PAD_NAME (srcpad),
2418 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2419 /* we do not emit a warning in this case because unlinking cannot
2420 * be made MT safe.*/
2421 GST_OBJECT_UNLOCK (srcpad);
2422 return GST_PAD_LINK_WAS_LINKED;
2426 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2427 GST_DEBUG_PAD_NAME (sinkpad),
2428 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2429 /* we do not emit a warning in this case because unlinking cannot
2430 * be made MT safe.*/
2431 GST_OBJECT_UNLOCK (sinkpad);
2432 GST_OBJECT_UNLOCK (srcpad);
2433 return GST_PAD_LINK_WAS_LINKED;
2437 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2438 GST_OBJECT_UNLOCK (sinkpad);
2439 GST_OBJECT_UNLOCK (srcpad);
2440 return GST_PAD_LINK_WRONG_HIERARCHY;
2444 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2445 GST_OBJECT_UNLOCK (sinkpad);
2446 GST_OBJECT_UNLOCK (srcpad);
2447 return GST_PAD_LINK_NOFORMAT;
2453 * @srcpad: the source #GstPad.
2454 * @sinkpad: the sink #GstPad.
2456 * Checks if the source pad and the sink pad are compatible so they can be
2459 * Returns: %TRUE if the pads can be linked.
2462 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2464 GstPadLinkReturn result;
2466 /* generic checks */
2467 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2468 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2470 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2471 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2473 /* gst_pad_link_prepare does everything for us, we only release the locks
2474 * on the pads that it gets us. If this function returns !OK the locks are not
2476 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2477 if (result != GST_PAD_LINK_OK)
2480 GST_OBJECT_UNLOCK (srcpad);
2481 GST_OBJECT_UNLOCK (sinkpad);
2484 return result == GST_PAD_LINK_OK;
2488 * gst_pad_link_full:
2489 * @srcpad: the source #GstPad to link.
2490 * @sinkpad: the sink #GstPad to link.
2491 * @flags: the checks to validate when linking
2493 * Links the source pad and the sink pad.
2495 * This variant of #gst_pad_link provides a more granular control on the
2496 * checks being done when linking. While providing some considerable speedups
2497 * the caller of this method must be aware that wrong usage of those flags
2498 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2499 * for more information.
2503 * Returns: A result code indicating if the connection worked or
2507 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2509 GstPadLinkReturn result;
2511 GstPadLinkFunction srcfunc, sinkfunc;
2513 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2514 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2515 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2516 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2517 GST_PAD_LINK_WRONG_DIRECTION);
2519 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2521 /* Notify the parent early. See gst_pad_unlink for details. */
2522 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2523 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2524 gst_element_post_message (parent,
2525 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2526 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2528 gst_object_unref (parent);
2533 /* prepare will also lock the two pads */
2534 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2536 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2537 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2538 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2539 gst_pad_link_get_name (result));
2543 /* must set peers before calling the link function */
2544 GST_PAD_PEER (srcpad) = sinkpad;
2545 GST_PAD_PEER (sinkpad) = srcpad;
2547 /* check events, when something is different, mark pending */
2548 schedule_events (srcpad, sinkpad);
2550 /* get the link functions */
2551 srcfunc = GST_PAD_LINKFUNC (srcpad);
2552 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2554 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2555 /* custom link functions, execute them */
2556 GST_OBJECT_UNLOCK (sinkpad);
2557 GST_OBJECT_UNLOCK (srcpad);
2560 GstObject *tmpparent;
2562 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2563 /* this one will call the peer link function */
2564 result = srcfunc (srcpad, tmpparent, sinkpad);
2565 RELEASE_PARENT (tmpparent);
2566 } else if (sinkfunc) {
2567 GstObject *tmpparent;
2569 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2570 /* if no source link function, we need to call the sink link
2571 * function ourselves. */
2572 result = sinkfunc (sinkpad, tmpparent, srcpad);
2573 RELEASE_PARENT (tmpparent);
2577 GST_OBJECT_LOCK (srcpad);
2578 GST_OBJECT_LOCK (sinkpad);
2580 /* we released the lock, check if the same pads are linked still */
2581 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2582 goto concurrent_link;
2584 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2587 GST_OBJECT_UNLOCK (sinkpad);
2588 GST_OBJECT_UNLOCK (srcpad);
2590 /* fire off a signal to each of the pads telling them
2591 * that they've been linked */
2592 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2593 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2595 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2596 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2598 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2599 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2602 if (G_LIKELY (parent)) {
2603 gst_element_post_message (parent,
2604 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2605 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2606 gst_object_unref (parent);
2609 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2615 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2616 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2617 GST_OBJECT_UNLOCK (sinkpad);
2618 GST_OBJECT_UNLOCK (srcpad);
2620 /* The other link operation succeeded first */
2621 result = GST_PAD_LINK_WAS_LINKED;
2626 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2627 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2628 gst_pad_link_get_name (result));
2630 GST_PAD_PEER (srcpad) = NULL;
2631 GST_PAD_PEER (sinkpad) = NULL;
2633 GST_OBJECT_UNLOCK (sinkpad);
2634 GST_OBJECT_UNLOCK (srcpad);
2642 * @srcpad: the source #GstPad to link.
2643 * @sinkpad: the sink #GstPad to link.
2645 * Links the source pad and the sink pad.
2647 * Returns: A result code indicating if the connection worked or
2653 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2655 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2659 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2661 GstPadTemplate **template_p;
2663 /* this function would need checks if it weren't static */
2665 GST_OBJECT_LOCK (pad);
2666 template_p = &pad->padtemplate;
2667 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2668 GST_OBJECT_UNLOCK (pad);
2671 gst_pad_template_pad_created (templ, pad);
2675 * gst_pad_get_pad_template:
2678 * Gets the template for @pad.
2680 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2681 * this pad was instantiated, or %NULL if this pad has no
2682 * template. Unref after usage.
2685 gst_pad_get_pad_template (GstPad * pad)
2687 GstPadTemplate *templ;
2689 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2691 templ = GST_PAD_PAD_TEMPLATE (pad);
2693 return (templ ? gst_object_ref (templ) : NULL);
2697 * gst_pad_has_current_caps:
2698 * @pad: a #GstPad to check
2700 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2702 * Returns: %TRUE when @pad has caps associated with it.
2705 gst_pad_has_current_caps (GstPad * pad)
2710 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2712 GST_OBJECT_LOCK (pad);
2713 caps = get_pad_caps (pad);
2714 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2715 "check current pad caps %" GST_PTR_FORMAT, caps);
2716 result = (caps != NULL);
2717 GST_OBJECT_UNLOCK (pad);
2723 * gst_pad_get_current_caps:
2724 * @pad: a #GstPad to get the current capabilities of.
2726 * Gets the capabilities currently configured on @pad with the last
2727 * #GST_EVENT_CAPS event.
2729 * Returns: (transfer full) (nullable): the current caps of the pad with
2730 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2733 gst_pad_get_current_caps (GstPad * pad)
2737 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2739 GST_OBJECT_LOCK (pad);
2740 if ((result = get_pad_caps (pad)))
2741 gst_caps_ref (result);
2742 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2743 "get current pad caps %" GST_PTR_FORMAT, result);
2744 GST_OBJECT_UNLOCK (pad);
2750 * gst_pad_get_pad_template_caps:
2751 * @pad: a #GstPad to get the template capabilities from.
2753 * Gets the capabilities for @pad's template.
2755 * Returns: (transfer full): the #GstCaps of this pad template.
2756 * Unref after usage.
2759 gst_pad_get_pad_template_caps (GstPad * pad)
2761 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2763 if (GST_PAD_PAD_TEMPLATE (pad))
2764 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2766 return gst_caps_ref (GST_CAPS_ANY);
2771 * @pad: a #GstPad to get the peer of.
2773 * Gets the peer of @pad. This function refs the peer pad so
2774 * you need to unref it after use.
2776 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2781 gst_pad_get_peer (GstPad * pad)
2785 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2787 GST_OBJECT_LOCK (pad);
2788 result = GST_PAD_PEER (pad);
2790 gst_object_ref (result);
2791 GST_OBJECT_UNLOCK (pad);
2797 * gst_pad_get_allowed_caps:
2800 * Gets the capabilities of the allowed media types that can flow through
2801 * @pad and its peer.
2803 * The allowed capabilities is calculated as the intersection of the results of
2804 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2805 * on the resulting caps.
2807 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2808 * pad link. Unref the caps when you no longer need it. This
2809 * function returns %NULL when @pad has no peer.
2814 gst_pad_get_allowed_caps (GstPad * pad)
2817 GstCaps *caps = NULL;
2820 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2822 GST_OBJECT_LOCK (pad);
2823 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2825 GST_OBJECT_UNLOCK (pad);
2827 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2829 mycaps = gst_pad_query_caps (pad, NULL);
2831 /* Query peer caps */
2832 query = gst_query_new_caps (mycaps);
2833 if (!gst_pad_peer_query (pad, query)) {
2834 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2838 gst_query_parse_caps_result (query, &caps);
2840 g_warn_if_fail (caps != NULL);
2843 gst_caps_ref (caps);
2845 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2849 gst_query_unref (query);
2850 gst_caps_unref (mycaps);
2856 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2857 GST_OBJECT_UNLOCK (pad);
2864 * gst_pad_get_single_internal_link:
2865 * @pad: the #GstPad to get the internal link of.
2867 * If there is a single internal link of the given pad, this function will
2868 * return it. Otherwise, it will return NULL.
2870 * Returns: (transfer full) (nullable): a #GstPad, or %NULL if @pad has none
2871 * or more than one internal links. Unref returned pad with
2872 * gst_object_unref().
2877 gst_pad_get_single_internal_link (GstPad * pad)
2880 gboolean done = FALSE;
2881 GValue item = { 0, };
2884 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2886 iter = gst_pad_iterate_internal_links (pad);
2892 switch (gst_iterator_next (iter, &item)) {
2893 case GST_ITERATOR_OK:
2896 ret = g_value_dup_object (&item);
2898 /* More than one internal link found - don't bother reffing */
2899 gst_clear_object (&ret);
2900 GST_DEBUG_OBJECT (pad,
2901 "Requested single internally linked pad, multiple found");
2904 g_value_reset (&item);
2907 case GST_ITERATOR_RESYNC:
2908 gst_clear_object (&ret);
2909 gst_iterator_resync (iter);
2911 case GST_ITERATOR_ERROR:
2912 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2914 case GST_ITERATOR_DONE:
2916 GST_DEBUG_OBJECT (pad,
2917 "Requested single internally linked pad, none found");
2923 g_value_unset (&item);
2924 gst_iterator_free (iter);
2930 * gst_pad_iterate_internal_links_default:
2931 * @pad: the #GstPad to get the internal links of.
2932 * @parent: (allow-none): the parent of @pad or %NULL
2934 * Iterate the list of pads to which the given pad is linked to inside of
2935 * the parent element.
2936 * This is the default handler, and thus returns an iterator of all of the
2937 * pads inside the parent element with opposite direction.
2939 * The caller must free this iterator after use with gst_iterator_free().
2941 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2942 * has no parent. Unref each returned pad with gst_object_unref().
2945 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2952 GstElement *eparent;
2954 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2956 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2957 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2959 GST_OBJECT_LOCK (pad);
2960 eparent = GST_PAD_PARENT (pad);
2961 if (!eparent || !GST_IS_ELEMENT (eparent))
2964 gst_object_ref (eparent);
2965 GST_OBJECT_UNLOCK (pad);
2968 if (pad->direction == GST_PAD_SRC)
2969 padlist = &eparent->sinkpads;
2971 padlist = &eparent->srcpads;
2973 GST_DEBUG_OBJECT (pad, "Making iterator");
2975 cookie = &eparent->pads_cookie;
2977 lock = GST_OBJECT_GET_LOCK (eparent);
2979 res = gst_iterator_new_list (GST_TYPE_PAD,
2980 lock, cookie, padlist, (GObject *) owner, NULL);
2982 gst_object_unref (owner);
2989 GST_OBJECT_UNLOCK (pad);
2990 GST_DEBUG_OBJECT (pad, "no parent element");
2996 * gst_pad_iterate_internal_links:
2997 * @pad: the GstPad to get the internal links of.
2999 * Gets an iterator for the pads to which the given pad is linked to inside
3000 * of the parent element.
3002 * Each #GstPad element yielded by the iterator will have its refcount increased,
3003 * so unref after use.
3005 * Free-function: gst_iterator_free
3007 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
3008 * or %NULL when the pad does not have an iterator function
3009 * configured. Use gst_iterator_free() after usage.
3012 gst_pad_iterate_internal_links (GstPad * pad)
3014 GstIterator *res = NULL;
3017 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3019 GST_OBJECT_LOCK (pad);
3020 ACQUIRE_PARENT (pad, parent, no_parent);
3021 GST_OBJECT_UNLOCK (pad);
3023 if (GST_PAD_ITERINTLINKFUNC (pad))
3024 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
3026 RELEASE_PARENT (parent);
3033 GST_DEBUG_OBJECT (pad, "no parent");
3034 GST_OBJECT_UNLOCK (pad);
3042 * @forward: (scope call): a #GstPadForwardFunction
3043 * @user_data: user data passed to @forward
3045 * Calls @forward for all internally linked pads of @pad. This function deals with
3046 * dynamically changing internal pads and will make sure that the @forward
3047 * function is only called once for each pad.
3049 * When @forward returns %TRUE, no further pads will be processed.
3051 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
3054 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
3057 gboolean result = FALSE;
3059 gboolean done = FALSE;
3060 GValue item = { 0, };
3061 GList *pushed_pads = NULL;
3063 iter = gst_pad_iterate_internal_links (pad);
3069 switch (gst_iterator_next (iter, &item)) {
3070 case GST_ITERATOR_OK:
3074 intpad = g_value_get_object (&item);
3076 /* if already pushed, skip. FIXME, find something faster to tag pads */
3077 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3078 g_value_reset (&item);
3082 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3083 GST_DEBUG_PAD_NAME (intpad));
3084 done = result = forward (intpad, user_data);
3086 pushed_pads = g_list_prepend (pushed_pads, intpad);
3088 g_value_reset (&item);
3091 case GST_ITERATOR_RESYNC:
3092 /* We don't reset the result here because we don't push the event
3093 * again on pads that got the event already and because we need
3094 * to consider the result of the previous pushes */
3095 gst_iterator_resync (iter);
3097 case GST_ITERATOR_ERROR:
3098 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3101 case GST_ITERATOR_DONE:
3106 g_value_unset (&item);
3107 gst_iterator_free (iter);
3109 g_list_free (pushed_pads);
3119 gboolean dispatched;
3123 event_forward_func (GstPad * pad, EventData * data)
3125 /* for each pad we send to, we should ref the event; it's up
3126 * to downstream to unref again when handled. */
3127 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3128 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3130 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3132 data->dispatched = TRUE;
3139 * gst_pad_event_default:
3140 * @pad: a #GstPad to call the default event handler on.
3141 * @parent: (allow-none): the parent of @pad or %NULL
3142 * @event: (transfer full): the #GstEvent to handle.
3144 * Invokes the default event handler for the given pad.
3146 * The EOS event will pause the task associated with @pad before it is forwarded
3147 * to all internally linked pads,
3149 * The event is sent to all pads internally linked to @pad. This function
3150 * takes ownership of @event.
3152 * Returns: %TRUE if the event was sent successfully.
3155 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3157 gboolean result, forward = TRUE;
3159 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3160 g_return_val_if_fail (event != NULL, FALSE);
3162 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3165 switch (GST_EVENT_TYPE (event)) {
3166 case GST_EVENT_CAPS:
3167 forward = GST_PAD_IS_PROXY_CAPS (pad);
3178 data.dispatched = FALSE;
3179 data.result = FALSE;
3181 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3183 /* for sinkpads without a parent element or without internal links, nothing
3184 * will be dispatched but we still want to return TRUE. */
3185 if (data.dispatched)
3186 result = data.result;
3191 gst_event_unref (event);
3196 /* Default accept caps implementation just checks against
3197 * the allowed caps for the pad */
3199 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3201 /* get the caps and see if it intersects to something not empty */
3202 GstCaps *caps, *allowed = NULL;
3205 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3207 /* first forward the query to internally linked pads when we are dealing with
3209 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3210 result = gst_pad_proxy_query_accept_caps (pad, query);
3212 allowed = gst_pad_get_pad_template_caps (pad);
3217 gst_query_parse_accept_caps (query, &caps);
3219 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3220 allowed = gst_pad_get_pad_template_caps (pad);
3222 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3223 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3224 allowed = gst_pad_query_caps (pad, caps);
3229 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3230 GST_DEBUG_OBJECT (pad,
3231 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3233 result = gst_caps_can_intersect (caps, allowed);
3235 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3236 GST_PTR_FORMAT, allowed, caps);
3237 result = gst_caps_is_subset (caps, allowed);
3240 GST_CAT_WARNING_OBJECT (GST_CAT_CAPS, pad, "caps: %" GST_PTR_FORMAT
3241 " were not compatible with: %" GST_PTR_FORMAT, caps, allowed);
3243 gst_caps_unref (allowed);
3245 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3246 "no compatible caps allowed on the pad");
3250 gst_query_set_accept_caps_result (query, result);
3256 /* Default caps implementation */
3258 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3260 GstCaps *result = NULL, *filter;
3261 GstPadTemplate *templ;
3262 gboolean fixed_caps;
3264 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3267 /* first try to proxy if we must */
3268 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3269 if ((gst_pad_proxy_query_caps (pad, query))) {
3274 gst_query_parse_caps (query, &filter);
3276 /* no proxy or it failed, do default handling */
3277 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3279 GST_OBJECT_LOCK (pad);
3281 /* fixed caps, try the negotiated caps first */
3282 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3283 if ((result = get_pad_caps (pad)))
3284 goto filter_done_unlock;
3287 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3288 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3289 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3290 goto filter_done_unlock;
3294 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3295 "non-fixed pad caps: trying pad caps");
3296 /* non fixed caps, try the negotiated caps */
3297 if ((result = get_pad_caps (pad)))
3298 goto filter_done_unlock;
3301 /* this almost never happens */
3302 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3303 result = GST_CAPS_ANY;
3306 GST_OBJECT_UNLOCK (pad);
3308 /* run the filter on the result */
3310 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3311 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3312 GST_PTR_FORMAT, result, result, filter, filter);
3313 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3314 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3317 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3318 "using caps %p %" GST_PTR_FORMAT, result, result);
3319 result = gst_caps_ref (result);
3321 gst_query_set_caps_result (query, result);
3322 gst_caps_unref (result);
3328 /* Default latency implementation */
3332 GstClockTime min, max;
3336 query_latency_default_fold (const GValue * item, GValue * ret,
3339 GstPad *pad = g_value_get_object (item), *peer;
3340 LatencyFoldData *fold_data = user_data;
3342 gboolean res = FALSE;
3344 query = gst_query_new_latency ();
3346 peer = gst_pad_get_peer (pad);
3348 res = gst_pad_peer_query (pad, query);
3350 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3355 GstClockTime min, max;
3357 gst_query_parse_latency (query, &live, &min, &max);
3359 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3360 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3363 if (min > fold_data->min)
3364 fold_data->min = min;
3366 if (fold_data->max == GST_CLOCK_TIME_NONE)
3367 fold_data->max = max;
3368 else if (max < fold_data->max)
3369 fold_data->max = max;
3371 fold_data->live = TRUE;
3374 GST_DEBUG_OBJECT (pad, "latency query failed");
3375 g_value_set_boolean (ret, FALSE);
3378 gst_query_unref (query);
3380 gst_object_unref (peer);
3386 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3389 GstIteratorResult res;
3390 GValue ret = G_VALUE_INIT;
3392 LatencyFoldData fold_data;
3394 it = gst_pad_iterate_internal_links (pad);
3396 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3400 g_value_init (&ret, G_TYPE_BOOLEAN);
3403 fold_data.live = FALSE;
3405 fold_data.max = GST_CLOCK_TIME_NONE;
3407 g_value_set_boolean (&ret, TRUE);
3408 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3410 case GST_ITERATOR_OK:
3411 g_assert_not_reached ();
3413 case GST_ITERATOR_DONE:
3415 case GST_ITERATOR_ERROR:
3416 g_value_set_boolean (&ret, FALSE);
3418 case GST_ITERATOR_RESYNC:
3419 gst_iterator_resync (it);
3422 g_assert_not_reached ();
3425 gst_iterator_free (it);
3427 query_ret = g_value_get_boolean (&ret);
3429 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3430 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3431 fold_data.min, fold_data.max);
3433 if (fold_data.min > fold_data.max) {
3434 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3437 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3439 GST_LOG_OBJECT (pad, "latency query failed");
3449 gboolean dispatched;
3453 query_forward_func (GstPad * pad, QueryData * data)
3455 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3456 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3458 data->result |= gst_pad_peer_query (pad, data->query);
3460 data->dispatched = TRUE;
3462 /* stop on first successful reply */
3463 return data->result;
3467 * gst_pad_query_default:
3468 * @pad: a #GstPad to call the default query handler on.
3469 * @parent: (allow-none): the parent of @pad or %NULL
3470 * @query: (transfer none): the #GstQuery to handle.
3472 * Invokes the default query handler for the given pad.
3473 * The query is sent to all pads internally linked to @pad. Note that
3474 * if there are many possible sink pads that are internally linked to
3475 * @pad, only one will be sent the query.
3476 * Multi-sinkpad elements should implement custom query handlers.
3478 * Returns: %TRUE if the query was performed successfully.
3481 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3483 gboolean forward, ret = FALSE;
3485 switch (GST_QUERY_TYPE (query)) {
3486 case GST_QUERY_SCHEDULING:
3487 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3489 case GST_QUERY_ALLOCATION:
3490 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3492 case GST_QUERY_ACCEPT_CAPS:
3493 ret = gst_pad_query_accept_caps_default (pad, query);
3496 case GST_QUERY_CAPS:
3497 ret = gst_pad_query_caps_default (pad, query);
3500 case GST_QUERY_LATENCY:
3501 ret = gst_pad_query_latency_default (pad, query);
3504 case GST_QUERY_BITRATE:
3505 /* FIXME: better default handling */
3508 case GST_QUERY_POSITION:
3509 case GST_QUERY_SEEKING:
3510 case GST_QUERY_FORMATS:
3511 case GST_QUERY_JITTER:
3512 case GST_QUERY_RATE:
3513 case GST_QUERY_CONVERT:
3519 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3520 query, GST_QUERY_TYPE_NAME (query));
3526 data.dispatched = FALSE;
3527 data.result = FALSE;
3529 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3531 if (data.dispatched) {
3534 /* nothing dispatched, assume drained */
3535 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3544 #define N_STACK_ALLOCATE_PROBES (16)
3546 /* A helper that checks if a probe was already
3547 * in the called_probes list, and adds it if
3548 * not. Used to avoid calling probes a 2nd time when
3549 * looping again after probe removal */
3551 check_probe_already_called (GHook * hook, ProbeMarshall * data)
3555 /* if we have called this callback, do nothing. But only check
3556 * if we're actually calling probes a second time */
3558 for (i = 0; i < data->n_called_probes; i++) {
3559 if (data->called_probes[i] == hook->hook_id) {
3565 /* reallocate on the heap if we had more than 16 probes */
3566 if (data->n_called_probes == data->called_probes_size) {
3567 if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
3568 data->called_probes_size *= 2;
3569 data->called_probes =
3570 g_renew (gulong, data->called_probes, data->called_probes_size);
3572 gulong *tmp = data->called_probes;
3574 data->called_probes_size *= 2;
3575 data->called_probes = g_new (gulong, data->called_probes_size);
3576 memcpy (data->called_probes, tmp,
3577 N_STACK_ALLOCATE_PROBES * sizeof (gulong));
3580 data->called_probes[data->n_called_probes++] = hook->hook_id;
3582 /* This probe was not alraedy called */
3587 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3589 GstPad *pad = data->pad;
3590 GstPadProbeInfo *info = data->info;
3591 GstPadProbeType type, flags;
3592 GstPadProbeCallback callback;
3593 GstPadProbeReturn ret;
3594 gpointer original_data;
3596 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3598 original_data = info->data;
3600 /* one of the scheduling types */
3601 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3604 if (G_UNLIKELY (data->handled)) {
3605 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3606 "probe previously returned HANDLED, not calling again");
3608 } else if (G_UNLIKELY (data->dropped)) {
3609 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3610 "probe previously returned DROPPED, not calling again");
3614 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3615 /* one of the data types for non-idle probes */
3616 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3617 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3619 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3620 /* one of the data types for non-idle probes */
3621 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3622 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3625 /* Type must have PULL or PUSH probe types */
3626 g_assert_not_reached ();
3629 /* one of the blocking types must match */
3630 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3631 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3633 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3634 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3636 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3637 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3638 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3641 if (check_probe_already_called (hook, data)) {
3642 /* Reset marshalled = TRUE here, because the probe
3643 * was already called and set it the first time around,
3644 * and we may want to keep blocking on it.
3646 * https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/658
3648 data->marshalled = TRUE;
3649 goto already_called;
3652 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3653 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3655 callback = (GstPadProbeCallback) hook->func;
3656 if (callback == NULL) {
3657 /* No callback is equivalent to just returning GST_PAD_PROBE_OK */
3658 data->marshalled = TRUE;
3662 info->id = hook->hook_id;
3664 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3665 pad->priv->idle_running++;
3667 GST_OBJECT_UNLOCK (pad);
3669 ret = callback (pad, info, hook->data);
3671 GST_OBJECT_LOCK (pad);
3673 /* If the probe callback asked for the
3674 * probe to be removed, don't set the marshalled flag
3675 * otherwise, you can get a case where you return
3676 * GST_PAD_PROBE_REMOVE from a buffer probe and
3677 * then the pad blocks anyway if there's any other
3678 * blocking probes installed.
3680 * https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/658
3682 if (ret != GST_PAD_PROBE_REMOVE)
3683 data->marshalled = TRUE;
3685 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3686 pad->priv->idle_running--;
3688 if (ret != GST_PAD_PROBE_HANDLED && original_data != NULL
3689 && info->data == NULL) {
3690 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3691 info->type = GST_PAD_PROBE_TYPE_INVALID;
3692 data->dropped = TRUE;
3696 case GST_PAD_PROBE_REMOVE:
3697 /* remove the probe */
3698 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3699 cleanup_hook (pad, hook);
3701 case GST_PAD_PROBE_DROP:
3702 /* need to drop the data, make sure other probes don't get called
3704 GST_DEBUG_OBJECT (pad, "asked to drop item");
3705 info->type = GST_PAD_PROBE_TYPE_INVALID;
3706 data->dropped = TRUE;
3708 case GST_PAD_PROBE_HANDLED:
3709 GST_DEBUG_OBJECT (pad, "probe handled data");
3710 data->handled = TRUE;
3712 case GST_PAD_PROBE_PASS:
3713 /* inform the pad block to let things pass */
3714 GST_DEBUG_OBJECT (pad, "asked to pass item");
3717 case GST_PAD_PROBE_OK:
3718 GST_DEBUG_OBJECT (pad, "probe returned OK");
3721 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "hook %lu with flags 0x%08x does not match %08x",
3730 hook->hook_id, flags, info->type);
3735 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3736 "hook %lu already called", hook->hook_id);
3741 /* a probe that does not take or return any data */
3742 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3744 if (G_UNLIKELY (pad->num_probes)) { \
3745 GstFlowReturn pval = defaultval; \
3746 /* pass NULL as the data item */ \
3747 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3748 info.ABI.abi.flow_ret = defaultval; \
3749 ret = do_probe_callbacks (pad, &info, defaultval); \
3750 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3755 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3757 if (G_UNLIKELY (pad->num_probes)) { \
3758 /* pass the data item */ \
3759 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3760 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3761 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3762 /* store the possibly updated data item */ \
3763 data = GST_PAD_PROBE_INFO_DATA (&info); \
3764 /* if something went wrong, exit */ \
3765 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3766 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3767 ret = info.ABI.abi.flow_ret; \
3768 goto handle_label; \
3775 #define PROBE_PUSH(pad,mask,data,label) \
3776 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3777 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3778 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3779 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3780 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3782 static GstFlowReturn
3783 do_pad_idle_probe_wait (GstPad * pad)
3785 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3786 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3787 "waiting idle probe to be removed");
3788 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3789 GST_PAD_BLOCK_WAIT (pad);
3790 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3791 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3793 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3794 return GST_FLOW_FLUSHING;
3799 #define PROBE_TYPE_IS_SERIALIZED(i) \
3802 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3803 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3804 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3806 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3807 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3809 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3810 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3814 static GstFlowReturn
3815 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3816 GstFlowReturn defaultval)
3821 gulong called_probes[N_STACK_ALLOCATE_PROBES];
3826 data.handled = FALSE;
3827 data.dropped = FALSE;
3829 /* We stack-allocate for N_STACK_ALLOCATE_PROBES hooks as a first step. If more are needed,
3830 * we will re-allocate with g_malloc(). This should usually never be needed
3832 data.called_probes = called_probes;
3833 data.n_called_probes = 0;
3834 data.called_probes_size = N_STACK_ALLOCATE_PROBES;
3838 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3840 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3841 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3846 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "do probes");
3847 cookie = pad->priv->probe_list_cookie;
3849 /* Clear the marshalled flag before doing callbacks. Only if
3850 * there are matching callbacks still will it get set */
3851 data.marshalled = FALSE;
3853 g_hook_list_marshal (&pad->probes, TRUE,
3854 (GHookMarshaller) probe_hook_marshal, &data);
3856 /* if the list changed, call the new callbacks (they will not be in
3857 * called_probes yet) */
3858 if (cookie != pad->priv->probe_list_cookie) {
3859 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3860 "probe list changed, restarting");
3865 /* the first item that dropped will stop the hooks and then we drop here */
3869 /* If one handler took care of it, let the the item pass */
3874 /* if no handler matched and we are blocking, let the item pass */
3875 if (!data.marshalled && is_block)
3878 /* At this point, all handlers returned either OK or PASS. If one handler
3879 * returned PASS, let the item pass */
3884 while (GST_PAD_IS_BLOCKED (pad)) {
3885 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3886 "we are blocked %d times", pad->num_blocked);
3888 /* we might have released the lock */
3889 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3892 /* now we block the streaming thread. It can be unlocked when we
3893 * deactivate the pad (which will also set the FLUSHING flag) or
3894 * when the pad is unblocked. A flushing event will also unblock
3895 * the pad after setting the FLUSHING flag. */
3896 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3897 "Waiting to be unblocked or set flushing");
3898 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3899 GST_PAD_BLOCK_WAIT (pad);
3900 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3901 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3903 /* if the list changed, call the new callbacks (they will not be in
3904 * called_probes yet) */
3905 if (cookie != pad->priv->probe_list_cookie) {
3906 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3907 "probe list changed, restarting");
3912 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3917 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3918 g_free (data.called_probes);
3925 GST_DEBUG_OBJECT (pad, "pad is flushing");
3926 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3927 g_free (data.called_probes);
3928 return GST_FLOW_FLUSHING;
3932 GST_DEBUG_OBJECT (pad, "data is dropped");
3933 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3934 g_free (data.called_probes);
3935 return GST_FLOW_CUSTOM_SUCCESS;
3939 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3940 GST_DEBUG_OBJECT (pad, "data is passed");
3941 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3942 g_free (data.called_probes);
3947 GST_DEBUG_OBJECT (pad, "data was handled");
3948 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3949 g_free (data.called_probes);
3950 return GST_FLOW_CUSTOM_SUCCESS_1;
3957 * gst_pad_get_offset:
3960 * Get the offset applied to the running time of @pad. @pad has to be a source
3963 * Returns: the offset.
3966 gst_pad_get_offset (GstPad * pad)
3970 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3972 GST_OBJECT_LOCK (pad);
3973 result = pad->offset;
3974 GST_OBJECT_UNLOCK (pad);
3980 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3982 ev->received = FALSE;
3987 * gst_pad_set_offset:
3989 * @offset: the offset
3991 * Set the offset that will be applied to the running time of @pad.
3994 gst_pad_set_offset (GstPad * pad, gint64 offset)
3996 g_return_if_fail (GST_IS_PAD (pad));
3998 GST_OBJECT_LOCK (pad);
3999 /* if nothing changed, do nothing */
4000 if (pad->offset == offset)
4003 pad->offset = offset;
4004 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
4005 GST_STIME_ARGS (offset));
4007 /* resend all sticky events with updated offset on next buffer push */
4008 events_foreach (pad, mark_event_not_received, NULL);
4009 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4012 GST_OBJECT_UNLOCK (pad);
4019 /* If TRUE and ret is not OK this means
4020 * that pushing the EOS event failed
4024 /* If called for an event this is
4025 * the event that would be pushed
4026 * next. Don't forward sticky events
4027 * that would come after that */
4031 /* should be called with pad LOCK */
4033 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
4035 PushStickyData *data = user_data;
4036 GstEvent *event = ev->event;
4039 GST_DEBUG_OBJECT (pad, "event %s was already received",
4040 GST_EVENT_TYPE_NAME (event));
4044 guint data_sticky_order = 0;
4046 data_sticky_order = _to_sticky_order (GST_EVENT_TYPE (data->event));
4049 /* If we're called because of an sticky event, only forward
4050 * events that would come before this new event and the
4052 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
4053 data_sticky_order <= _to_sticky_order (GST_EVENT_SEGMENT) &&
4054 data_sticky_order < ev->sticky_order) {
4055 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
4057 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
4058 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4059 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
4060 data->ret = GST_FLOW_OK;
4063 switch (data->ret) {
4065 ev->received = TRUE;
4066 GST_DEBUG_OBJECT (pad, "event %s marked received",
4067 GST_EVENT_TYPE_NAME (event));
4069 case GST_FLOW_CUSTOM_SUCCESS:
4070 /* we can't assume the event is received when it was dropped */
4071 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
4072 GST_EVENT_TYPE_NAME (event));
4073 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4074 data->ret = GST_FLOW_OK;
4076 case GST_FLOW_CUSTOM_SUCCESS_1:
4077 /* event was ignored and should be sent later */
4078 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
4079 GST_EVENT_TYPE_NAME (event));
4080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4081 data->ret = GST_FLOW_OK;
4083 case GST_FLOW_NOT_LINKED:
4084 /* not linked is not a problem, we are sticky so the event will be
4085 * rescheduled to be sent later on re-link, but only for non-EOS events */
4086 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
4087 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
4088 data->ret = GST_FLOW_OK;
4089 ev->received = TRUE;
4093 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
4094 gst_flow_get_name (data->ret));
4095 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4099 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
4100 data->was_eos = TRUE;
4102 return data->ret == GST_FLOW_OK;
4105 /* check sticky events and push them when needed. should be called
4107 static inline GstFlowReturn
4108 check_sticky (GstPad * pad, GstEvent * event)
4110 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4112 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
4113 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4115 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
4116 events_foreach (pad, push_sticky, &data);
4118 /* If there's an EOS event we must push it downstream
4119 * even if sending a previous sticky event failed.
4120 * Otherwise the pipeline might wait forever for EOS.
4122 * Only do this if pushing another event than the EOS
4125 if (data.ret != GST_FLOW_OK && !data.was_eos) {
4126 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
4128 if (ev && !ev->received) {
4129 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
4130 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4131 /* the event could have been dropped. Because this can only
4132 * happen if the user asked for it, it's not an error */
4133 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
4134 data.ret = GST_FLOW_OK;
4144 * @pad: a #GstPad to invoke the default query on.
4145 * @query: (transfer none): the #GstQuery to perform.
4147 * Dispatches a query to a pad. The query should have been allocated by the
4148 * caller via one of the type-specific allocation functions. The element that
4149 * the pad belongs to is responsible for filling the query with an appropriate
4150 * response, which should then be parsed with a type-specific query parsing
4153 * Again, the caller is responsible for both the allocation and deallocation of
4154 * the query structure.
4156 * Please also note that some queries might need a running pipeline to work.
4158 * Returns: %TRUE if the query could be performed.
4161 gst_pad_query (GstPad * pad, GstQuery * query)
4164 gboolean res, serialized;
4165 GstPadQueryFunction func;
4166 GstPadProbeType type;
4169 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4170 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4172 if (GST_PAD_IS_SRC (pad)) {
4173 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4174 goto wrong_direction;
4175 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4176 } else if (GST_PAD_IS_SINK (pad)) {
4177 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4178 goto wrong_direction;
4179 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4181 goto unknown_direction;
4183 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4184 GST_QUERY_TYPE_NAME (query));
4185 GST_TRACER_PAD_QUERY_PRE (pad, query);
4187 serialized = GST_QUERY_IS_SERIALIZED (query);
4188 if (G_UNLIKELY (serialized))
4189 GST_PAD_STREAM_LOCK (pad);
4191 GST_OBJECT_LOCK (pad);
4192 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4193 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4194 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4196 ACQUIRE_PARENT (pad, parent, no_parent);
4197 GST_OBJECT_UNLOCK (pad);
4199 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4202 res = func (pad, parent, query);
4204 RELEASE_PARENT (parent);
4206 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4207 GST_QUERY_TYPE_NAME (query), res);
4208 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4213 GST_OBJECT_LOCK (pad);
4214 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4215 GST_OBJECT_UNLOCK (pad);
4217 if (G_UNLIKELY (serialized))
4218 GST_PAD_STREAM_UNLOCK (pad);
4225 g_warning ("pad %s:%s query %s in wrong direction",
4226 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4231 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4236 GST_DEBUG_OBJECT (pad, "had no parent");
4237 GST_OBJECT_UNLOCK (pad);
4238 if (G_UNLIKELY (serialized))
4239 GST_PAD_STREAM_UNLOCK (pad);
4244 GST_DEBUG_OBJECT (pad, "had no query function");
4245 RELEASE_PARENT (parent);
4246 if (G_UNLIKELY (serialized))
4247 GST_PAD_STREAM_UNLOCK (pad);
4252 GST_DEBUG_OBJECT (pad, "query failed");
4253 if (G_UNLIKELY (serialized))
4254 GST_PAD_STREAM_UNLOCK (pad);
4259 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4260 GST_OBJECT_UNLOCK (pad);
4261 if (G_UNLIKELY (serialized))
4262 GST_PAD_STREAM_UNLOCK (pad);
4264 /* if a probe dropped without handling, we don't sent it further but assume
4265 * that the probe did not answer the query and return FALSE */
4266 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4276 * gst_pad_peer_query:
4277 * @pad: a #GstPad to invoke the peer query on.
4278 * @query: (transfer none): the #GstQuery to perform.
4280 * Performs gst_pad_query() on the peer of @pad.
4282 * The caller is responsible for both the allocation and deallocation of
4283 * the query structure.
4285 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4286 * if @pad has no peer.
4289 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4292 GstPadProbeType type;
4293 gboolean res, serialized;
4296 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4297 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4299 if (GST_PAD_IS_SRC (pad)) {
4300 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4301 goto wrong_direction;
4302 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4303 } else if (GST_PAD_IS_SINK (pad)) {
4304 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4305 goto wrong_direction;
4306 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4308 goto unknown_direction;
4310 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4311 GST_QUERY_TYPE_NAME (query));
4313 serialized = GST_QUERY_IS_SERIALIZED (query);
4315 GST_OBJECT_LOCK (pad);
4316 if (GST_PAD_IS_SRC (pad) && serialized) {
4317 /* all serialized queries on the srcpad trigger push of
4319 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4323 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4324 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4325 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4327 peerpad = GST_PAD_PEER (pad);
4328 if (G_UNLIKELY (peerpad == NULL))
4331 gst_object_ref (peerpad);
4332 GST_OBJECT_UNLOCK (pad);
4334 res = gst_pad_query (peerpad, query);
4336 gst_object_unref (peerpad);
4341 GST_OBJECT_LOCK (pad);
4342 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4343 GST_OBJECT_UNLOCK (pad);
4350 g_warning ("pad %s:%s query %s in wrong direction",
4351 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4356 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4361 GST_WARNING_OBJECT (pad, "could not send sticky events");
4362 GST_OBJECT_UNLOCK (pad);
4367 GST_INFO_OBJECT (pad, "pad has no peer");
4368 GST_OBJECT_UNLOCK (pad);
4373 GST_DEBUG_OBJECT (pad, "query failed");
4378 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4379 GST_OBJECT_UNLOCK (pad);
4381 /* if a probe dropped without handling, we don't sent it further but
4382 * assume that the probe did not answer the query and return FALSE */
4383 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4392 /**********************************************************************
4393 * Data passing functions
4396 /* this is the chain function that does not perform the additional argument
4397 * checking for that little extra speed.
4399 static inline GstFlowReturn
4400 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4404 gboolean handled = FALSE;
4406 if (type & GST_PAD_PROBE_TYPE_BUFFER_LIST) {
4407 GST_TRACER_PAD_CHAIN_LIST_PRE (pad, data);
4409 GST_TRACER_PAD_CHAIN_PRE (pad, data);
4412 GST_PAD_STREAM_LOCK (pad);
4414 GST_OBJECT_LOCK (pad);
4415 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4418 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4421 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4424 #ifdef GST_ENABLE_EXTRA_CHECKS
4425 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4426 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4428 ":%s:<%s:%s> Got data flow before stream-start event",
4429 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4431 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4433 ":%s:<%s:%s> Got data flow before segment event",
4434 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4436 pad->priv->last_cookie = pad->priv->events_cookie;
4440 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4443 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4445 ACQUIRE_PARENT (pad, parent, no_parent);
4446 GST_OBJECT_UNLOCK (pad);
4448 /* NOTE: we read the chainfunc unlocked.
4449 * we cannot hold the lock for the pad so we might send
4450 * the data to the wrong function. This is not really a
4451 * problem since functions are assigned at creation time
4452 * and don't change that often... */
4453 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4454 GstPadChainFunction chainfunc;
4456 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4459 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4460 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4461 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4463 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4465 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4466 "called chainfunction &%s with buffer %p, returned %s",
4467 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4469 GstPadChainListFunction chainlistfunc;
4471 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4474 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4475 "calling chainlistfunction &%s",
4476 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4478 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4480 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4481 "called chainlistfunction &%s, returned %s",
4482 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4485 pad->ABI.abi.last_flowret = ret;
4487 RELEASE_PARENT (parent);
4489 GST_PAD_STREAM_UNLOCK (pad);
4492 if (type & GST_PAD_PROBE_TYPE_BUFFER_LIST) {
4493 GST_TRACER_PAD_CHAIN_LIST_POST (pad, ret);
4495 GST_TRACER_PAD_CHAIN_POST (pad, ret);
4503 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4504 "chaining, but pad was flushing");
4505 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4506 GST_OBJECT_UNLOCK (pad);
4507 GST_PAD_STREAM_UNLOCK (pad);
4508 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4509 ret = GST_FLOW_FLUSHING;
4514 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4515 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4516 GST_OBJECT_UNLOCK (pad);
4517 GST_PAD_STREAM_UNLOCK (pad);
4518 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4524 g_critical ("chain on pad %s:%s but it was not in push mode",
4525 GST_DEBUG_PAD_NAME (pad));
4526 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4527 GST_OBJECT_UNLOCK (pad);
4528 GST_PAD_STREAM_UNLOCK (pad);
4529 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4530 ret = GST_FLOW_ERROR;
4538 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4540 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4543 case GST_FLOW_CUSTOM_SUCCESS:
4544 case GST_FLOW_CUSTOM_SUCCESS_1:
4545 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4549 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4552 pad->ABI.abi.last_flowret = ret;
4553 GST_OBJECT_UNLOCK (pad);
4554 GST_PAD_STREAM_UNLOCK (pad);
4559 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4560 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4561 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4562 GST_OBJECT_UNLOCK (pad);
4563 GST_PAD_STREAM_UNLOCK (pad);
4564 ret = GST_FLOW_FLUSHING;
4569 pad->ABI.abi.last_flowret = GST_FLOW_NOT_SUPPORTED;
4570 RELEASE_PARENT (parent);
4571 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4572 g_critical ("chain on pad %s:%s but it has no chainfunction",
4573 GST_DEBUG_PAD_NAME (pad));
4574 GST_PAD_STREAM_UNLOCK (pad);
4575 ret = GST_FLOW_NOT_SUPPORTED;
4582 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4583 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4586 * Chain a buffer to @pad.
4588 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4590 * If the buffer type is not acceptable for @pad (as negotiated with a
4591 * preceding GST_EVENT_CAPS event), this function returns
4592 * #GST_FLOW_NOT_NEGOTIATED.
4594 * The function proceeds calling the chain function installed on @pad (see
4595 * gst_pad_set_chain_function()) and the return value of that function is
4596 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4599 * In all cases, success or failure, the caller loses its reference to @buffer
4600 * after calling this function.
4602 * Returns: a #GstFlowReturn from the pad.
4607 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4609 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4610 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4611 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4613 return gst_pad_chain_data_unchecked (pad,
4614 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4617 static GstFlowReturn
4618 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4619 GstBufferList * list)
4625 GST_LOG_OBJECT (pad, "chaining each buffer in list individually");
4627 len = gst_buffer_list_length (list);
4630 for (i = 0; i < len; i++) {
4631 buffer = gst_buffer_list_get (list, i);
4633 gst_pad_chain_data_unchecked (pad,
4634 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4635 gst_buffer_ref (buffer));
4636 if (ret != GST_FLOW_OK)
4639 gst_buffer_list_unref (list);
4645 * gst_pad_chain_list:
4646 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4647 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4650 * Chain a bufferlist to @pad.
4652 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4654 * If @pad was not negotiated properly with a CAPS event, this function
4655 * returns #GST_FLOW_NOT_NEGOTIATED.
4657 * The function proceeds calling the chainlist function installed on @pad (see
4658 * gst_pad_set_chain_list_function()) and the return value of that function is
4659 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4660 * chainlist function.
4662 * In all cases, success or failure, the caller loses its reference to @list
4663 * after calling this function.
4667 * Returns: a #GstFlowReturn from the pad.
4670 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4672 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4673 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4674 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4676 return gst_pad_chain_data_unchecked (pad,
4677 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4680 static GstFlowReturn
4681 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4685 gboolean handled = FALSE;
4687 GST_OBJECT_LOCK (pad);
4688 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4691 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4694 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4697 #ifdef GST_ENABLE_EXTRA_CHECKS
4698 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4699 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4701 ":%s:<%s:%s> Got data flow before stream-start event",
4702 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4704 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4706 ":%s:<%s:%s> Got data flow before segment event",
4707 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4709 pad->priv->last_cookie = pad->priv->events_cookie;
4713 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4716 /* do block probes */
4717 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4720 /* recheck sticky events because the probe might have cause a relink */
4721 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4724 /* do post-blocking probes */
4725 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4727 /* recheck sticky events because the probe might have cause a relink */
4728 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4731 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4734 /* take ref to peer pad before releasing the lock */
4735 gst_object_ref (peer);
4737 GST_OBJECT_UNLOCK (pad);
4739 ret = gst_pad_chain_data_unchecked (peer, type, data);
4742 gst_object_unref (peer);
4744 GST_OBJECT_LOCK (pad);
4745 pad->ABI.abi.last_flowret = ret;
4747 if (pad->priv->using == 0) {
4748 /* pad is not active anymore, trigger idle callbacks */
4749 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4750 probe_stopped, ret);
4752 GST_OBJECT_UNLOCK (pad);
4756 /* ERROR recovery here */
4760 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4761 "pushing, but pad was flushing");
4762 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4763 GST_OBJECT_UNLOCK (pad);
4764 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4765 return GST_FLOW_FLUSHING;
4769 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4770 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4771 GST_OBJECT_UNLOCK (pad);
4772 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4773 return GST_FLOW_EOS;
4777 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4778 GST_DEBUG_PAD_NAME (pad));
4779 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4780 GST_OBJECT_UNLOCK (pad);
4781 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4782 return GST_FLOW_ERROR;
4786 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4787 "error pushing events, return %s", gst_flow_get_name (ret));
4788 pad->ABI.abi.last_flowret = ret;
4789 GST_OBJECT_UNLOCK (pad);
4790 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4798 GST_OBJECT_UNLOCK (pad);
4799 if (data != NULL && !handled)
4800 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4803 case GST_FLOW_CUSTOM_SUCCESS:
4804 case GST_FLOW_CUSTOM_SUCCESS_1:
4805 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4809 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4812 pad->ABI.abi.last_flowret = ret;
4817 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4818 "pushing, but it was not linked");
4819 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4820 GST_OBJECT_UNLOCK (pad);
4821 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4822 return GST_FLOW_NOT_LINKED;
4828 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4829 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4832 * Pushes a buffer to the peer of @pad.
4834 * This function will call installed block probes before triggering any
4835 * installed data probes.
4837 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4838 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4841 * In all cases, success or failure, the caller loses its reference to @buffer
4842 * after calling this function.
4844 * Returns: a #GstFlowReturn from the peer pad.
4849 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4853 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4854 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4855 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4857 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4858 res = gst_pad_push_data (pad,
4859 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4860 GST_TRACER_PAD_PUSH_POST (pad, res);
4865 * gst_pad_push_list:
4866 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4867 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4870 * Pushes a buffer list to the peer of @pad.
4872 * This function will call installed block probes before triggering any
4873 * installed data probes.
4875 * The function proceeds calling the chain function on the peer pad and returns
4876 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4877 * be returned. If the peer pad does not have any installed chainlist function
4878 * every group buffer of the list will be merged into a normal #GstBuffer and
4879 * chained via gst_pad_chain().
4881 * In all cases, success or failure, the caller loses its reference to @list
4882 * after calling this function.
4884 * Returns: a #GstFlowReturn from the peer pad.
4889 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4893 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4894 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4895 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4897 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4898 res = gst_pad_push_data (pad,
4899 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4900 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4904 static GstFlowReturn
4905 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4906 GstBuffer ** buffer)
4909 GstPadGetRangeFunction getrangefunc;
4913 GST_PAD_STREAM_LOCK (pad);
4915 GST_OBJECT_LOCK (pad);
4916 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4919 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4922 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4927 /* when one of the probes returns DROPPED, probe_stopped will be called
4928 * and we skip calling the getrange function, res_buf should then contain a
4929 * valid result buffer */
4930 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4931 res_buf, offset, size, probe_stopped);
4933 /* recheck sticky events because the probe might have cause a relink */
4934 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4937 ACQUIRE_PARENT (pad, parent, no_parent);
4938 GST_OBJECT_UNLOCK (pad);
4940 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4943 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4944 "calling getrangefunc %s, offset %"
4945 G_GUINT64_FORMAT ", size %u",
4946 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4948 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4950 RELEASE_PARENT (parent);
4952 GST_OBJECT_LOCK (pad);
4953 if (G_UNLIKELY (ret != GST_FLOW_OK))
4954 goto get_range_failed;
4956 /* can only fire the signal if we have a valid buffer */
4958 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4959 res_buf, offset, size, probe_stopped_unref);
4960 pad->ABI.abi.last_flowret = ret;
4961 GST_OBJECT_UNLOCK (pad);
4963 GST_PAD_STREAM_UNLOCK (pad);
4965 /* If the caller provided a buffer it must be filled by the getrange
4966 * function instead of it returning a new buffer */
4967 g_return_val_if_fail (!*buffer || res_buf == *buffer, GST_FLOW_ERROR);
4976 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4977 "getrange, but pad was flushing");
4978 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4979 GST_OBJECT_UNLOCK (pad);
4980 GST_PAD_STREAM_UNLOCK (pad);
4981 return GST_FLOW_FLUSHING;
4985 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4986 GST_OBJECT_UNLOCK (pad);
4987 GST_PAD_STREAM_UNLOCK (pad);
4988 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4989 GST_DEBUG_PAD_NAME (pad));
4990 return GST_FLOW_ERROR;
4994 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4995 pad->ABI.abi.last_flowret = ret;
4996 GST_OBJECT_UNLOCK (pad);
4997 GST_PAD_STREAM_UNLOCK (pad);
5002 GST_DEBUG_OBJECT (pad, "no parent");
5003 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5004 GST_OBJECT_UNLOCK (pad);
5005 GST_PAD_STREAM_UNLOCK (pad);
5006 return GST_FLOW_FLUSHING;
5010 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
5011 GST_DEBUG_PAD_NAME (pad));
5012 RELEASE_PARENT (parent);
5013 GST_PAD_STREAM_UNLOCK (pad);
5014 return GST_FLOW_NOT_SUPPORTED;
5018 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5019 "probe returned %s", gst_flow_get_name (ret));
5020 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5022 /* the probe filled the buffer and asks us to not call the getrange
5023 * anymore, we continue with the post probes then. */
5024 GST_DEBUG_OBJECT (pad, "handled buffer");
5028 /* no buffer, we are EOS */
5029 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5033 pad->ABI.abi.last_flowret = ret;
5034 GST_OBJECT_UNLOCK (pad);
5035 GST_PAD_STREAM_UNLOCK (pad);
5039 probe_stopped_unref:
5041 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5042 "probe returned %s", gst_flow_get_name (ret));
5043 /* if we drop here, it signals EOS */
5044 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5046 pad->ABI.abi.last_flowret = ret;
5047 GST_OBJECT_UNLOCK (pad);
5048 GST_PAD_STREAM_UNLOCK (pad);
5049 if (*buffer == NULL)
5050 gst_buffer_unref (res_buf);
5055 pad->ABI.abi.last_flowret = ret;
5056 GST_OBJECT_UNLOCK (pad);
5057 GST_PAD_STREAM_UNLOCK (pad);
5058 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5059 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5060 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
5066 * gst_pad_get_range:
5067 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
5068 * @offset: The start offset of the buffer
5069 * @size: The length of the buffer
5070 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
5071 * returns #GST_FLOW_ERROR if %NULL.
5073 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
5074 * immediately and @buffer is %NULL.
5076 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
5077 * description of a getrange function. If @pad has no getrange function
5078 * installed (see gst_pad_set_getrange_function()) this function returns
5079 * #GST_FLOW_NOT_SUPPORTED.
5081 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
5082 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
5083 * must be freed with gst_buffer_unref() after usage.
5085 * When @buffer points to a variable that points to a valid #GstBuffer, the
5086 * buffer will be filled with the result data when this function returns
5087 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
5088 * @size bytes will be filled in the result buffer and its size will be updated
5091 * Note that less than @size bytes can be returned in @buffer when, for example,
5092 * an EOS condition is near or when @buffer is not large enough to hold @size
5093 * bytes. The caller should check the result buffer size to get the result size.
5095 * When this function returns any other result value than #GST_FLOW_OK, @buffer
5096 * will be unchanged.
5098 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
5100 * Returns: a #GstFlowReturn from the pad.
5105 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
5106 GstBuffer ** buffer)
5108 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5109 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
5110 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5111 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5112 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5114 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
5118 * gst_pad_pull_range:
5119 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
5120 * @offset: The start offset of the buffer
5121 * @size: The length of the buffer
5122 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
5123 * GST_FLOW_ERROR if %NULL.
5125 * Pulls a @buffer from the peer pad or fills up a provided buffer.
5127 * This function will first trigger the pad block signal if it was
5130 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
5131 * function returns the result of gst_pad_get_range() on the peer pad.
5132 * See gst_pad_get_range() for a list of return values and for the
5133 * semantics of the arguments of this function.
5135 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
5136 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
5137 * must be freed with gst_buffer_unref() after usage. When this function
5138 * returns any other result value, @buffer will still point to %NULL.
5140 * When @buffer points to a variable that points to a valid #GstBuffer, the
5141 * buffer will be filled with the result data when this function returns
5142 * #GST_FLOW_OK. When this function returns any other result value,
5143 * @buffer will be unchanged. If the provided buffer is larger than @size, only
5144 * @size bytes will be filled in the result buffer and its size will be updated
5147 * Note that less than @size bytes can be returned in @buffer when, for example,
5148 * an EOS condition is near or when @buffer is not large enough to hold @size
5149 * bytes. The caller should check the result buffer size to get the result size.
5151 * Returns: a #GstFlowReturn from the peer pad.
5156 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
5157 GstBuffer ** buffer)
5163 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5164 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
5165 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5166 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5167 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5169 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
5171 GST_OBJECT_LOCK (pad);
5172 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5175 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
5180 /* when one of the probes returns DROPPED, probe_stopped will be
5181 * called and we skip calling the peer getrange function. *buffer should then
5182 * contain a valid buffer */
5183 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
5184 res_buf, offset, size, probe_stopped);
5186 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
5189 gst_object_ref (peer);
5191 GST_OBJECT_UNLOCK (pad);
5193 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5195 gst_object_unref (peer);
5197 GST_OBJECT_LOCK (pad);
5199 pad->ABI.abi.last_flowret = ret;
5200 if (pad->priv->using == 0) {
5201 /* pad is not active anymore, trigger idle callbacks */
5202 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5203 probe_stopped_unref, ret);
5206 if (G_UNLIKELY (ret != GST_FLOW_OK))
5207 goto pull_range_failed;
5210 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5211 res_buf, offset, size, probe_stopped_unref);
5213 GST_OBJECT_UNLOCK (pad);
5217 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5220 /* ERROR recovery here */
5223 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5224 "pullrange, but pad was flushing");
5225 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5226 GST_OBJECT_UNLOCK (pad);
5227 ret = GST_FLOW_FLUSHING;
5232 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5233 GST_DEBUG_PAD_NAME (pad));
5234 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5235 GST_OBJECT_UNLOCK (pad);
5236 ret = GST_FLOW_ERROR;
5241 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5242 gst_flow_get_name (ret));
5243 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5245 /* the probe filled the buffer and asks us to not forward to the peer
5246 * anymore, we continue with the post probes then */
5247 GST_DEBUG_OBJECT (pad, "handled buffer");
5251 /* no buffer, we are EOS then */
5252 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5256 pad->ABI.abi.last_flowret = ret;
5257 GST_OBJECT_UNLOCK (pad);
5262 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5263 "pulling range, but it was not linked");
5264 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5265 GST_OBJECT_UNLOCK (pad);
5266 ret = GST_FLOW_NOT_LINKED;
5271 pad->ABI.abi.last_flowret = ret;
5272 GST_OBJECT_UNLOCK (pad);
5273 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5274 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5275 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5278 probe_stopped_unref:
5280 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5281 "post probe returned %s", gst_flow_get_name (ret));
5283 /* if we drop here, it signals EOS */
5284 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5287 pad->ABI.abi.last_flowret = ret;
5288 GST_OBJECT_UNLOCK (pad);
5290 if (*buffer == NULL)
5291 gst_buffer_unref (res_buf);
5295 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5299 /* must be called with pad object lock */
5300 static GstFlowReturn
5301 store_sticky_event (GstPad * pad, GstEvent * event)
5306 gboolean res = FALSE;
5308 gboolean insert = TRUE;
5310 type = GST_EVENT_TYPE (event);
5311 guint sticky_order = _to_sticky_order (type);
5313 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5314 * otherwise they can be dropped and nothing would ever resend them.
5315 * Only do that for activated pads though, everything else is a bug!
5317 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5318 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5319 || type == GST_EVENT_EOS))))
5322 /* Unset the EOS flag when received STREAM_START event, so pad can
5323 * store sticky event and then push it later */
5324 if (type == GST_EVENT_STREAM_START) {
5325 GST_LOG_OBJECT (pad, "Removing pending EOS, StreamGroupDone, TAG events");
5326 remove_event_by_type (pad, GST_EVENT_EOS);
5327 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5328 remove_event_by_type (pad, GST_EVENT_TAG);
5329 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5332 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5335 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5336 name_id = gst_structure_get_name_id (gst_event_get_structure (event));
5338 events = pad->priv->events;
5341 for (i = 0; i < len; i++) {
5342 PadEvent *ev = &g_array_index (events, PadEvent, i);
5344 if (ev->event == NULL)
5347 if (type == GST_EVENT_TYPE (ev->event)) {
5348 /* matching types, check matching name if needed */
5349 if (name_id && !gst_event_has_name_id (ev->event, name_id))
5353 if ((res = gst_event_replace (&ev->event, event)))
5354 ev->received = FALSE;
5360 if (sticky_order < ev->sticky_order || (type != GST_EVENT_TYPE (ev->event)
5361 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5362 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5363 * storing the sticky ordered we can check that this is respected. */
5364 if (G_UNLIKELY (ev->sticky_order <= _to_sticky_order (GST_EVENT_SEGMENT)
5365 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5367 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5368 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5369 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5370 gst_event_type_get_name (type));
5376 ev.sticky_order = sticky_order;
5377 ev.event = gst_event_ref (event);
5378 ev.received = FALSE;
5379 g_array_insert_val (events, i, ev);
5384 pad->priv->events_cookie++;
5385 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5387 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5389 switch (GST_EVENT_TYPE (event)) {
5390 case GST_EVENT_CAPS:
5391 GST_OBJECT_UNLOCK (pad);
5393 GST_DEBUG_OBJECT (pad, "notify caps");
5394 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5396 GST_OBJECT_LOCK (pad);
5402 if (type == GST_EVENT_EOS) {
5403 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5404 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5407 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5412 GST_DEBUG_OBJECT (pad, "pad is flushing");
5413 return GST_FLOW_FLUSHING;
5417 GST_DEBUG_OBJECT (pad, "pad is EOS");
5418 return GST_FLOW_EOS;
5423 * gst_pad_store_sticky_event:
5425 * @event: (transfer none): a #GstEvent
5427 * Store the sticky @event on @pad
5429 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5430 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5435 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5439 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5440 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5442 GST_OBJECT_LOCK (pad);
5443 ret = store_sticky_event (pad, event);
5444 GST_OBJECT_UNLOCK (pad);
5450 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5452 PushStickyData *data = user_data;
5454 /* Forward all sticky events before our current one that are pending */
5455 if (ev->event != data->event
5456 && ev->sticky_order < _to_sticky_order (GST_EVENT_TYPE (data->event)))
5457 return push_sticky (pad, ev, data);
5462 /* should be called with pad LOCK */
5463 static GstFlowReturn
5464 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5465 GstPadProbeType type)
5469 GstEventType event_type;
5470 gint64 old_pad_offset = pad->offset;
5472 /* pass the adjusted event on. We need to do this even if
5473 * there is no peer pad because of the probes. */
5474 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5476 /* Two checks to be made:
5477 * . (un)set the FLUSHING flag for flushing events,
5478 * . handle pad blocking */
5479 event_type = GST_EVENT_TYPE (event);
5480 switch (event_type) {
5481 case GST_EVENT_FLUSH_START:
5482 GST_PAD_SET_FLUSHING (pad);
5484 GST_PAD_BLOCK_BROADCAST (pad);
5485 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5487 case GST_EVENT_FLUSH_STOP:
5488 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5491 GST_PAD_UNSET_FLUSHING (pad);
5493 /* Remove sticky EOS events */
5494 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5495 remove_event_by_type (pad, GST_EVENT_EOS);
5496 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5497 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5498 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5499 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5501 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5505 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5508 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5509 * checked already or this is called as part of pushing sticky events,
5510 * in which case we still want to forward the EOS event downstream.
5513 switch (GST_EVENT_TYPE (event)) {
5514 case GST_EVENT_RECONFIGURE:
5515 if (GST_PAD_IS_SINK (pad))
5516 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5521 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5522 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5523 /* recheck sticky events because the probe might have cause a relink */
5524 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5525 && (GST_EVENT_IS_SERIALIZED (event))) {
5526 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5527 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5529 /* Push all sticky events before our current one
5530 * that have changed */
5531 events_foreach (pad, sticky_changed, &data);
5537 /* send probes after modifying the events above */
5538 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5540 /* recheck sticky events because the probe might have cause a relink */
5541 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5542 && (GST_EVENT_IS_SERIALIZED (event))) {
5543 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5544 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5546 /* Push all sticky events before our current one
5547 * that have changed */
5548 events_foreach (pad, sticky_changed, &data);
5551 /* the pad offset might've been changed by any of the probes above. It
5552 * would've been taken into account when repushing any of the sticky events
5553 * above but not for our current event here */
5554 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5556 _apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad),
5557 pad->offset - old_pad_offset);
5560 /* now check the peer pad */
5561 peerpad = GST_PAD_PEER (pad);
5562 if (peerpad == NULL)
5565 gst_object_ref (peerpad);
5567 GST_OBJECT_UNLOCK (pad);
5569 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5570 event, gst_event_type_get_name (event_type), peerpad);
5572 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5574 /* Note: we gave away ownership of the event at this point but we can still
5575 * print the old pointer */
5576 GST_LOG_OBJECT (pad,
5577 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5578 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5580 gst_object_unref (peerpad);
5582 GST_OBJECT_LOCK (pad);
5584 if (pad->priv->using == 0) {
5585 /* pad is not active anymore, trigger idle callbacks */
5586 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5587 idle_probe_stopped, ret);
5591 /* ERROR handling */
5594 GST_DEBUG_OBJECT (pad, "We're flushing");
5595 gst_event_unref (event);
5596 return GST_FLOW_FLUSHING;
5600 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5601 gst_event_unref (event);
5602 return GST_FLOW_FLUSHING;
5606 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5607 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5608 gst_event_unref (event);
5611 case GST_FLOW_CUSTOM_SUCCESS_1:
5612 GST_DEBUG_OBJECT (pad, "handled event");
5614 case GST_FLOW_CUSTOM_SUCCESS:
5615 GST_DEBUG_OBJECT (pad, "dropped event");
5618 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5625 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5626 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5627 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5628 gst_event_unref (event);
5630 /* unlinked pads should not influence latency configuration */
5631 if (event_type == GST_EVENT_LATENCY)
5634 return GST_FLOW_NOT_LINKED;
5638 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5644 * gst_pad_push_event:
5645 * @pad: a #GstPad to push the event to.
5646 * @event: (transfer full): the #GstEvent to send to the pad.
5648 * Sends the event to the peer of the given pad. This function is
5649 * mainly used by elements to send events to their peer
5652 * This function takes ownership of the provided event so you should
5653 * gst_event_ref() it if you want to reuse the event after this call.
5655 * Returns: %TRUE if the event was handled.
5660 gst_pad_push_event (GstPad * pad, GstEvent * event)
5662 gboolean res = FALSE;
5663 GstPadProbeType type;
5664 gboolean sticky, serialized;
5666 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5667 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5669 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5671 if (GST_PAD_IS_SRC (pad)) {
5672 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5673 goto wrong_direction;
5674 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5675 } else if (GST_PAD_IS_SINK (pad)) {
5676 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5677 goto wrong_direction;
5678 /* events pushed on sinkpad never are sticky */
5679 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5681 goto unknown_direction;
5683 GST_OBJECT_LOCK (pad);
5684 sticky = GST_EVENT_IS_STICKY (event);
5685 serialized = GST_EVENT_IS_SERIALIZED (event);
5688 /* srcpad sticky events are stored immediately, the received flag is set
5689 * to FALSE and will be set to TRUE when we can successfully push the
5690 * event to the peer pad */
5691 switch (store_sticky_event (pad, event)) {
5692 case GST_FLOW_FLUSHING:
5700 if (GST_PAD_IS_SRC (pad) && serialized) {
5701 /* All serialized events on the srcpad trigger push of sticky events.
5703 * Note that we do not do this for non-serialized sticky events since it
5704 * could potentially block. */
5705 res = (check_sticky (pad, event) == GST_FLOW_OK);
5707 if (!serialized || !sticky) {
5710 /* non-serialized and non-sticky events are pushed right away. */
5711 ret = gst_pad_push_event_unchecked (pad, event, type);
5712 /* dropped events by a probe are not an error */
5713 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5714 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5716 /* Errors in sticky event pushing are no problem and ignored here
5717 * as they will cause more meaningful errors during data flow.
5718 * For EOS events, that are not followed by data flow, we still
5719 * return FALSE here though.
5721 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5723 gst_event_unref (event);
5725 GST_OBJECT_UNLOCK (pad);
5727 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5730 /* ERROR handling */
5733 g_warning ("pad %s:%s pushing %s event in wrong direction",
5734 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5735 gst_event_unref (event);
5740 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5741 gst_event_unref (event);
5746 GST_DEBUG_OBJECT (pad, "We're flushing");
5747 GST_OBJECT_UNLOCK (pad);
5748 gst_event_unref (event);
5753 GST_DEBUG_OBJECT (pad, "We're EOS");
5754 GST_OBJECT_UNLOCK (pad);
5755 gst_event_unref (event);
5759 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5763 /* Check if we can call the event function with the given event */
5764 static GstFlowReturn
5765 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5769 switch (GST_EVENT_TYPE (event)) {
5770 case GST_EVENT_CAPS:
5772 /* backwards compatibility mode for caps */
5773 gst_event_parse_caps (event, &caps);
5775 if (!gst_pad_query_accept_caps (pad, caps))
5787 GST_CAT_WARNING_OBJECT (GST_CAT_CAPS, pad,
5788 "caps %" GST_PTR_FORMAT " not accepted", caps);
5789 return GST_FLOW_NOT_NEGOTIATED;
5793 static GstFlowReturn
5794 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5795 GstPadProbeType type)
5798 GstEventType event_type;
5799 gboolean serialized, need_unlock = FALSE, sticky;
5800 GstPadEventFunction eventfunc;
5801 GstPadEventFullFunction eventfullfunc = NULL;
5803 gint64 old_pad_offset;
5805 GST_OBJECT_LOCK (pad);
5807 old_pad_offset = pad->offset;
5808 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5810 if (GST_PAD_IS_SINK (pad))
5811 serialized = GST_EVENT_IS_SERIALIZED (event);
5814 sticky = GST_EVENT_IS_STICKY (event);
5815 event_type = GST_EVENT_TYPE (event);
5816 switch (event_type) {
5817 case GST_EVENT_FLUSH_START:
5818 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5819 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5821 /* can't even accept a flush begin event when flushing */
5822 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5825 GST_PAD_SET_FLUSHING (pad);
5826 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5827 GST_PAD_BLOCK_BROADCAST (pad);
5828 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5830 case GST_EVENT_FLUSH_STOP:
5831 /* we can't accept flush-stop on inactive pads else the flushing flag
5832 * would be cleared and it would look like the pad can accept data.
5833 * Also, some elements restart a streaming thread in flush-stop which we
5834 * can't allow on inactive pads */
5835 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5838 GST_PAD_UNSET_FLUSHING (pad);
5839 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5840 /* Remove pending EOS events */
5841 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5842 remove_event_by_type (pad, GST_EVENT_EOS);
5843 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5844 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5845 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5846 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5848 GST_OBJECT_UNLOCK (pad);
5849 /* grab stream lock */
5850 GST_PAD_STREAM_LOCK (pad);
5852 GST_OBJECT_LOCK (pad);
5853 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5856 case GST_EVENT_RECONFIGURE:
5857 if (GST_PAD_IS_SRC (pad))
5858 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5860 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5861 "have event type %" GST_PTR_FORMAT, event);
5863 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5866 switch (event_type) {
5867 case GST_EVENT_STREAM_START:
5868 /* Take the stream lock to unset the EOS status. This is to ensure
5869 * there isn't any other serialized event passing through while this
5870 * EOS status is being unset */
5871 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5872 GST_OBJECT_UNLOCK (pad);
5873 GST_PAD_STREAM_LOCK (pad);
5875 GST_OBJECT_LOCK (pad);
5876 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5879 /* Remove sticky EOS events */
5880 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5881 remove_event_by_type (pad, GST_EVENT_EOS);
5882 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5883 remove_event_by_type (pad, GST_EVENT_TAG);
5884 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5888 /* Take the stream lock to check the EOS status and drop the event
5889 * if that is the case. */
5890 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5891 GST_OBJECT_UNLOCK (pad);
5892 GST_PAD_STREAM_LOCK (pad);
5894 GST_OBJECT_LOCK (pad);
5895 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5898 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5906 /* now do the probe */
5908 type | GST_PAD_PROBE_TYPE_PUSH |
5909 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5911 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5913 /* the pad offset might've been changed by any of the probes above. It
5914 * would've been taken into account when repushing any of the sticky events
5915 * above but not for our current event here */
5916 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5918 _apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad),
5919 pad->offset - old_pad_offset);
5922 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5923 eventfunc = GST_PAD_EVENTFUNC (pad);
5924 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5927 ACQUIRE_PARENT (pad, parent, no_parent);
5928 GST_OBJECT_UNLOCK (pad);
5930 ret = pre_eventfunc_check (pad, event);
5931 if (G_UNLIKELY (ret != GST_FLOW_OK))
5932 goto precheck_failed;
5935 gst_event_ref (event);
5937 if (eventfullfunc) {
5938 ret = eventfullfunc (pad, parent, event);
5939 } else if (eventfunc (pad, parent, event)) {
5942 /* something went wrong */
5943 switch (event_type) {
5944 case GST_EVENT_CAPS:
5945 ret = GST_FLOW_NOT_NEGOTIATED;
5948 ret = GST_FLOW_ERROR;
5952 RELEASE_PARENT (parent);
5954 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5957 if (ret == GST_FLOW_OK) {
5958 GST_OBJECT_LOCK (pad);
5959 /* after the event function accepted the event, we can store the sticky
5960 * event on the pad */
5961 switch (store_sticky_event (pad, event)) {
5962 case GST_FLOW_FLUSHING:
5969 GST_OBJECT_UNLOCK (pad);
5971 gst_event_unref (event);
5975 GST_PAD_STREAM_UNLOCK (pad);
5979 /* ERROR handling */
5982 GST_OBJECT_UNLOCK (pad);
5984 GST_PAD_STREAM_UNLOCK (pad);
5985 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5986 "Received event on flushing pad. Discarding");
5987 gst_event_unref (event);
5988 return GST_FLOW_FLUSHING;
5992 GST_OBJECT_UNLOCK (pad);
5994 GST_PAD_STREAM_UNLOCK (pad);
5995 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5996 "Received flush-stop on inactive pad. Discarding");
5997 gst_event_unref (event);
5998 return GST_FLOW_FLUSHING;
6002 GST_OBJECT_UNLOCK (pad);
6004 GST_PAD_STREAM_UNLOCK (pad);
6005 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
6006 "Received event on EOS pad. Discarding");
6007 gst_event_unref (event);
6008 return GST_FLOW_EOS;
6012 GST_OBJECT_UNLOCK (pad);
6014 GST_PAD_STREAM_UNLOCK (pad);
6015 /* Only unref if unhandled */
6016 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
6017 gst_event_unref (event);
6020 case GST_FLOW_CUSTOM_SUCCESS_1:
6021 case GST_FLOW_CUSTOM_SUCCESS:
6022 GST_DEBUG_OBJECT (pad, "dropped or handled event");
6026 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
6033 g_warning ("pad %s:%s has no event handler, file a bug.",
6034 GST_DEBUG_PAD_NAME (pad));
6035 GST_OBJECT_UNLOCK (pad);
6037 GST_PAD_STREAM_UNLOCK (pad);
6038 gst_event_unref (event);
6039 return GST_FLOW_NOT_SUPPORTED;
6043 GST_DEBUG_OBJECT (pad, "no parent");
6044 GST_OBJECT_UNLOCK (pad);
6046 GST_PAD_STREAM_UNLOCK (pad);
6047 gst_event_unref (event);
6048 return GST_FLOW_FLUSHING;
6052 GST_DEBUG_OBJECT (pad, "pre event check failed");
6053 RELEASE_PARENT (parent);
6055 GST_PAD_STREAM_UNLOCK (pad);
6056 gst_event_unref (event);
6062 * gst_pad_send_event:
6063 * @pad: a #GstPad to send the event to.
6064 * @event: (transfer full): the #GstEvent to send to the pad.
6066 * Sends the event to the pad. This function can be used
6067 * by applications to send events in the pipeline.
6069 * If @pad is a source pad, @event should be an upstream event. If @pad is a
6070 * sink pad, @event should be a downstream event. For example, you would not
6071 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
6072 * Furthermore, some downstream events have to be serialized with data flow,
6073 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
6074 * the event needs to be serialized with data flow, this function will take the
6075 * pad's stream lock while calling its event function.
6077 * To find out whether an event type is upstream, downstream, or downstream and
6078 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
6079 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
6080 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
6081 * plugin doesn't need to bother itself with this information; the core handles
6082 * all necessary locks and checks.
6084 * This function takes ownership of the provided event so you should
6085 * gst_event_ref() it if you want to reuse the event after this call.
6087 * Returns: %TRUE if the event was handled.
6090 gst_pad_send_event (GstPad * pad, GstEvent * event)
6093 GstPadProbeType type;
6095 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6096 g_return_val_if_fail (event != NULL, FALSE);
6098 if (GST_PAD_IS_SINK (pad)) {
6099 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
6100 goto wrong_direction;
6101 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
6102 } else if (GST_PAD_IS_SRC (pad)) {
6103 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
6104 goto wrong_direction;
6105 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
6107 goto unknown_direction;
6109 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
6116 /* ERROR handling */
6119 g_warning ("pad %s:%s sending %s event in wrong direction",
6120 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
6121 gst_event_unref (event);
6126 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
6127 gst_event_unref (event);
6133 * gst_pad_set_element_private:
6134 * @pad: the #GstPad to set the private data of.
6135 * @priv: The private data to attach to the pad.
6137 * Set the given private data gpointer on the pad.
6138 * This function can only be used by the element that owns the pad.
6139 * No locking is performed in this function.
6142 gst_pad_set_element_private (GstPad * pad, gpointer priv)
6144 pad->element_private = priv;
6148 * gst_pad_get_element_private:
6149 * @pad: the #GstPad to get the private data of.
6151 * Gets the private data of a pad.
6152 * No locking is performed in this function.
6154 * Returns: (transfer none) (nullable): a #gpointer to the private data.
6157 gst_pad_get_element_private (GstPad * pad)
6159 return pad->element_private;
6163 * gst_pad_get_sticky_event:
6164 * @pad: the #GstPad to get the event from.
6165 * @event_type: the #GstEventType that should be retrieved.
6166 * @idx: the index of the event
6168 * Returns a new reference of the sticky event of type @event_type
6171 * Returns: (transfer full) (nullable): a #GstEvent of type
6172 * @event_type or %NULL when no event of @event_type was on
6173 * @pad. Unref after usage.
6176 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
6178 GstEvent *event = NULL;
6181 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
6182 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
6184 GST_OBJECT_LOCK (pad);
6185 ev = find_event_by_type (pad, event_type, idx);
6186 if (ev && (event = ev->event))
6187 gst_event_ref (event);
6188 GST_OBJECT_UNLOCK (pad);
6195 GstPadStickyEventsForeachFunction func;
6200 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
6202 ForeachDispatch *data = user_data;
6203 gboolean ret = TRUE;
6206 GST_OBJECT_UNLOCK (pad);
6208 ret = data->func (pad, &ev->event, data->user_data);
6210 GST_OBJECT_LOCK (pad);
6217 * gst_pad_sticky_events_foreach:
6218 * @pad: the #GstPad that should be used for iteration.
6219 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
6220 * should be called for every event.
6221 * @user_data: (closure): the optional user data.
6223 * Iterates all sticky events on @pad and calls @foreach_func for every
6224 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6227 gst_pad_sticky_events_foreach (GstPad * pad,
6228 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6230 ForeachDispatch data;
6232 g_return_if_fail (GST_IS_PAD (pad));
6233 g_return_if_fail (foreach_func != NULL);
6235 data.func = foreach_func;
6236 data.user_data = user_data;
6238 GST_OBJECT_LOCK (pad);
6239 events_foreach (pad, foreach_dispatch_function, &data);
6240 GST_OBJECT_UNLOCK (pad);
6244 do_stream_status (GstPad * pad, GstStreamStatusType type,
6245 GThread * thread, GstTask * task)
6249 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6251 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6252 if (GST_IS_ELEMENT (parent)) {
6253 GstMessage *message;
6254 GValue value = { 0 };
6256 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6259 /* create a good task name (we can directly grab the parent and pad
6260 * names since they both exist at this point, and changing the name of
6261 * parent and pad when a pad is activating is a big no-no). */
6262 tname = g_strdup_printf ("%s:%s", GST_DEBUG_PAD_NAME (pad));
6264 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6268 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6271 g_value_init (&value, GST_TYPE_TASK);
6272 g_value_set_object (&value, task);
6273 gst_message_set_stream_status_object (message, &value);
6274 g_value_unset (&value);
6276 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6277 gst_element_post_message (parent, message);
6279 gst_object_unref (parent);
6284 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6286 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6291 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6293 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6298 * gst_pad_start_task:
6299 * @pad: the #GstPad to start the task of
6300 * @func: the task function to call
6301 * @user_data: user data passed to the task function
6302 * @notify: called when @user_data is no longer referenced
6304 * Starts a task that repeatedly calls @func with @user_data. This function
6305 * is mostly used in pad activation functions to start the dataflow.
6306 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6307 * before @func is called.
6309 * Returns: a %TRUE if the task could be started.
6312 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6313 GDestroyNotify notify)
6318 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6319 g_return_val_if_fail (func != NULL, FALSE);
6321 GST_DEBUG_OBJECT (pad, "start task");
6323 GST_OBJECT_LOCK (pad);
6324 task = GST_PAD_TASK (pad);
6326 task = gst_task_new (func, user_data, notify);
6327 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6328 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6329 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6330 GST_INFO_OBJECT (pad, "created task %p", task);
6331 GST_PAD_TASK (pad) = task;
6332 gst_object_ref (task);
6333 /* release lock to post the message */
6334 GST_OBJECT_UNLOCK (pad);
6336 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6338 gst_object_unref (task);
6340 GST_OBJECT_LOCK (pad);
6341 /* nobody else is supposed to have changed the pad now */
6342 if (GST_PAD_TASK (pad) != task)
6343 goto concurrent_stop;
6345 res = gst_task_set_state (task, GST_TASK_STARTED);
6346 GST_OBJECT_UNLOCK (pad);
6353 GST_OBJECT_UNLOCK (pad);
6359 * gst_pad_pause_task:
6360 * @pad: the #GstPad to pause the task of
6362 * Pause the task of @pad. This function will also wait until the
6363 * function executed by the task is finished if this function is not
6364 * called from the task function.
6366 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6370 gst_pad_pause_task (GstPad * pad)
6375 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6377 GST_DEBUG_OBJECT (pad, "pause task");
6379 GST_OBJECT_LOCK (pad);
6380 task = GST_PAD_TASK (pad);
6383 res = gst_task_set_state (task, GST_TASK_PAUSED);
6384 /* unblock activation waits if any */
6385 pad->priv->in_activation = FALSE;
6386 g_cond_broadcast (&pad->priv->activation_cond);
6387 GST_OBJECT_UNLOCK (pad);
6389 /* wait for task function to finish, this lock is recursive so it does nothing
6390 * when the pause is called from the task itself */
6391 GST_PAD_STREAM_LOCK (pad);
6392 GST_PAD_STREAM_UNLOCK (pad);
6398 GST_DEBUG_OBJECT (pad, "pad has no task");
6399 GST_OBJECT_UNLOCK (pad);
6405 * gst_pad_get_task_state:
6406 * @pad: the #GstPad to get task state from
6408 * Get @pad task state. If no task is currently
6409 * set, #GST_TASK_STOPPED is returned.
6411 * Returns: The current state of @pad's task.
6416 gst_pad_get_task_state (GstPad * pad)
6421 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6423 GST_OBJECT_LOCK (pad);
6424 task = GST_PAD_TASK (pad);
6427 res = gst_task_get_state (task);
6428 GST_OBJECT_UNLOCK (pad);
6434 GST_DEBUG_OBJECT (pad, "pad has no task");
6435 GST_OBJECT_UNLOCK (pad);
6436 return GST_TASK_STOPPED;
6441 * gst_pad_stop_task:
6442 * @pad: the #GstPad to stop the task of
6444 * Stop the task of @pad. This function will also make sure that the
6445 * function executed by the task will effectively stop if not called
6446 * from the GstTaskFunction.
6448 * This function will deadlock if called from the GstTaskFunction of
6449 * the task. Use gst_task_pause() instead.
6451 * Regardless of whether the pad has a task, the stream lock is acquired and
6452 * released so as to ensure that streaming through this pad has finished.
6454 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6457 gst_pad_stop_task (GstPad * pad)
6462 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6464 GST_DEBUG_OBJECT (pad, "stop task");
6466 GST_OBJECT_LOCK (pad);
6467 task = GST_PAD_TASK (pad);
6470 GST_PAD_TASK (pad) = NULL;
6471 res = gst_task_set_state (task, GST_TASK_STOPPED);
6472 /* unblock activation waits if any */
6473 pad->priv->in_activation = FALSE;
6474 g_cond_broadcast (&pad->priv->activation_cond);
6475 GST_OBJECT_UNLOCK (pad);
6477 GST_PAD_STREAM_LOCK (pad);
6478 GST_PAD_STREAM_UNLOCK (pad);
6480 if (!gst_task_join (task))
6483 gst_object_unref (task);
6489 GST_DEBUG_OBJECT (pad, "no task");
6490 GST_OBJECT_UNLOCK (pad);
6492 GST_PAD_STREAM_LOCK (pad);
6493 GST_PAD_STREAM_UNLOCK (pad);
6495 /* this is not an error */
6500 /* this is bad, possibly the application tried to join the task from
6501 * the task's thread. We install the task again so that it will be stopped
6502 * again from the right thread next time hopefully. */
6503 GST_OBJECT_LOCK (pad);
6504 GST_DEBUG_OBJECT (pad, "join failed");
6505 /* we can only install this task if there was no other task */
6506 if (GST_PAD_TASK (pad) == NULL)
6507 GST_PAD_TASK (pad) = task;
6508 GST_OBJECT_UNLOCK (pad);
6515 * gst_pad_probe_info_get_event:
6516 * @info: a #GstPadProbeInfo
6518 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6522 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6524 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6525 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6527 return GST_PAD_PROBE_INFO_EVENT (info);
6532 * gst_pad_probe_info_get_query:
6533 * @info: a #GstPadProbeInfo
6535 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6539 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6541 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6542 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6544 return GST_PAD_PROBE_INFO_QUERY (info);
6548 * gst_pad_probe_info_get_buffer:
6549 * @info: a #GstPadProbeInfo
6551 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6555 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6557 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6559 return GST_PAD_PROBE_INFO_BUFFER (info);
6563 * gst_pad_probe_info_get_buffer_list:
6564 * @info: a #GstPadProbeInfo
6566 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6570 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6572 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6574 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6578 * gst_pad_get_last_flow_return:
6581 * Gets the #GstFlowReturn return from the last data passed by this pad.
6586 gst_pad_get_last_flow_return (GstPad * pad)
6590 GST_OBJECT_LOCK (pad);
6591 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6592 GST_OBJECT_UNLOCK (pad);