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 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
124 #define GST_PAD_GET_PRIVATE(obj) \
125 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
127 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
129 /* we have a pending and an active event on the pad. On source pads only the
130 * active event is used. On sinkpads, events are copied to the pending entry and
131 * moved to the active event when the eventfunc returned %TRUE. */
138 struct _GstPadPrivate
145 guint probe_list_cookie;
148 /* counter of how many idle probes are running directly from the add_probe
149 * call. Used to block any data flowing in the pad while the idle callback
150 * Doesn't finish its work */
153 /* conditional and variable used to ensure pads only get (de)activated
154 * by a single thread at a time. Protected by the object lock */
155 GCond activation_cond;
156 gboolean in_activation;
165 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
166 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
167 (((GstPad *)(p))->priv->idle_running > 0)
172 GstPadProbeInfo *info;
180 static void gst_pad_dispose (GObject * object);
181 static void gst_pad_finalize (GObject * object);
182 static void gst_pad_set_property (GObject * object, guint prop_id,
183 const GValue * value, GParamSpec * pspec);
184 static void gst_pad_get_property (GObject * object, guint prop_id,
185 GValue * value, GParamSpec * pspec);
187 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
188 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
189 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
190 GstObject * parent, GstBufferList * list);
192 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
194 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
195 GstEvent * event, GstPadProbeType type);
197 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
198 GstPadMode mode, gboolean active);
200 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
202 static GParamSpec *pspec_caps = NULL;
204 /* quarks for probe signals */
205 static GQuark buffer_quark;
206 static GQuark buffer_list_quark;
207 static GQuark event_quark;
216 static GstFlowQuarks flow_quarks[] = {
217 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
218 {GST_FLOW_OK, "ok", 0},
219 {GST_FLOW_NOT_LINKED, "not-linked", 0},
220 {GST_FLOW_FLUSHING, "flushing", 0},
221 {GST_FLOW_EOS, "eos", 0},
222 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
223 {GST_FLOW_ERROR, "error", 0},
224 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
225 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
230 * @ret: a #GstFlowReturn to get the name of.
232 * Gets a string representing the given flow return.
234 * Returns: a static string with the name of the flow return.
237 gst_flow_get_name (GstFlowReturn ret)
241 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
243 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
244 if (ret == flow_quarks[i].ret)
245 return flow_quarks[i].name;
252 * @ret: a #GstFlowReturn to get the quark of.
254 * Get the unique quark for the given GstFlowReturn.
256 * Returns: the quark associated with the flow return or 0 if an
257 * invalid return was specified.
260 gst_flow_to_quark (GstFlowReturn ret)
264 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
266 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
267 if (ret == flow_quarks[i].ret)
268 return flow_quarks[i].quark;
274 * gst_pad_link_get_name:
275 * @ret: a #GstPadLinkReturn to get the name of.
277 * Gets a string representing the given pad-link return.
279 * Returns: a static string with the name of the pad-link return.
284 gst_pad_link_get_name (GstPadLinkReturn ret)
287 case GST_PAD_LINK_OK:
289 case GST_PAD_LINK_WRONG_HIERARCHY:
290 return "wrong hierarchy";
291 case GST_PAD_LINK_WAS_LINKED:
293 case GST_PAD_LINK_WRONG_DIRECTION:
294 return "wrong direction";
295 case GST_PAD_LINK_NOFORMAT:
296 return "no common format";
297 case GST_PAD_LINK_NOSCHED:
298 return "incompatible scheduling";
299 case GST_PAD_LINK_REFUSED:
302 g_return_val_if_reached ("unknown");
309 buffer_quark = g_quark_from_static_string ("buffer"); \
310 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
311 event_quark = g_quark_from_static_string ("event"); \
313 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
314 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
317 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
318 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
321 #define gst_pad_parent_class parent_class
322 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
325 gst_pad_class_init (GstPadClass * klass)
327 GObjectClass *gobject_class;
328 GstObjectClass *gstobject_class;
330 gobject_class = G_OBJECT_CLASS (klass);
331 gstobject_class = GST_OBJECT_CLASS (klass);
333 g_type_class_add_private (klass, sizeof (GstPadPrivate));
335 gobject_class->dispose = gst_pad_dispose;
336 gobject_class->finalize = gst_pad_finalize;
337 gobject_class->set_property = gst_pad_set_property;
338 gobject_class->get_property = gst_pad_get_property;
342 * @pad: the pad that emitted the signal
343 * @peer: the peer pad that has been connected
345 * Signals that a pad has been linked to the peer pad.
347 gst_pad_signals[PAD_LINKED] =
348 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
349 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
350 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
353 * @pad: the pad that emitted the signal
354 * @peer: the peer pad that has been disconnected
356 * Signals that a pad has been unlinked from the peer pad.
358 gst_pad_signals[PAD_UNLINKED] =
359 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
360 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
361 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
363 pspec_caps = g_param_spec_boxed ("caps", "Caps",
364 "The capabilities of the pad", GST_TYPE_CAPS,
365 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
368 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
369 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
370 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
371 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
373 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
374 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
375 g_param_spec_object ("template", "Template",
376 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 * The offset that will be applied to the running time of the pad.
386 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
387 g_param_spec_int64 ("offset", "Offset",
388 "The running time offset of the pad", 0, G_MAXINT64, 0,
389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 gstobject_class->path_string_separator = ".";
393 /* Register common function pointer descriptions */
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
396 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
397 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
398 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
402 gst_pad_init (GstPad * pad)
404 pad->priv = GST_PAD_GET_PRIVATE (pad);
406 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
408 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
409 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
410 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
411 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
412 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
414 GST_PAD_SET_FLUSHING (pad);
416 g_rec_mutex_init (&pad->stream_rec_lock);
418 g_cond_init (&pad->block_cond);
420 g_hook_list_init (&pad->probes, sizeof (GstProbe));
422 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
423 pad->priv->events_cookie = 0;
424 pad->priv->last_cookie = -1;
425 g_cond_init (&pad->priv->activation_cond);
427 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
430 /* called when setting the pad inactive. It removes all sticky events from
431 * the pad. must be called with object lock */
433 remove_events (GstPad * pad)
437 gboolean notify = FALSE;
439 events = pad->priv->events;
442 for (i = 0; i < len; i++) {
443 PadEvent *ev = &g_array_index (events, PadEvent, i);
444 GstEvent *event = ev->event;
448 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
451 gst_event_unref (event);
454 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
455 g_array_set_size (events, 0);
456 pad->priv->events_cookie++;
459 GST_OBJECT_UNLOCK (pad);
461 GST_DEBUG_OBJECT (pad, "notify caps");
462 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
464 GST_OBJECT_LOCK (pad);
468 /* should be called with object lock */
470 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
476 events = pad->priv->events;
479 for (i = 0; i < len; i++) {
480 ev = &g_array_index (events, PadEvent, i);
481 if (ev->event == NULL)
484 if (GST_EVENT_TYPE (ev->event) == type) {
488 } else if (GST_EVENT_TYPE (ev->event) > type) {
497 /* should be called with OBJECT lock */
499 find_event (GstPad * pad, GstEvent * event)
505 events = pad->priv->events;
508 for (i = 0; i < len; i++) {
509 ev = &g_array_index (events, PadEvent, i);
510 if (event == ev->event)
512 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
520 /* should be called with OBJECT lock */
522 remove_event_by_type (GstPad * pad, GstEventType type)
528 events = pad->priv->events;
533 ev = &g_array_index (events, PadEvent, i);
534 if (ev->event == NULL)
537 if (GST_EVENT_TYPE (ev->event) > type)
539 else if (GST_EVENT_TYPE (ev->event) != type)
542 gst_event_unref (ev->event);
543 g_array_remove_index (events, i);
545 pad->priv->events_cookie++;
553 /* check all events on srcpad against those on sinkpad. All events that are not
554 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
555 * srcpad so that the events will be sent next time */
556 /* should be called with srcpad and sinkpad LOCKS */
558 schedule_events (GstPad * srcpad, GstPad * sinkpad)
563 gboolean pending = FALSE;
565 events = srcpad->priv->events;
568 for (i = 0; i < len; i++) {
569 ev = &g_array_index (events, PadEvent, i);
570 if (ev->event == NULL)
573 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
574 ev->received = FALSE;
579 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
582 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
585 /* should be called with pad LOCK */
587 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
594 events = pad->priv->events;
597 cookie = pad->priv->events_cookie;
601 PadEvent *ev, ev_ret;
603 ev = &g_array_index (events, PadEvent, i);
604 if (G_UNLIKELY (ev->event == NULL))
607 /* take aditional ref, func might release the lock */
608 ev_ret.event = gst_event_ref (ev->event);
609 ev_ret.received = ev->received;
611 ret = func (pad, &ev_ret, user_data);
613 /* recheck the cookie, lock might have been released and the list could have
615 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
616 if (G_LIKELY (ev_ret.event))
617 gst_event_unref (ev_ret.event);
621 /* store the received state */
622 ev->received = ev_ret.received;
624 /* if the event changed, we need to do something */
625 if (G_UNLIKELY (ev->event != ev_ret.event)) {
626 if (G_UNLIKELY (ev_ret.event == NULL)) {
627 /* function unreffed and set the event to NULL, remove it */
628 gst_event_unref (ev->event);
629 g_array_remove_index (events, i);
631 cookie = ++pad->priv->events_cookie;
634 /* function gave a new event for us */
635 gst_event_take (&ev->event, ev_ret.event);
638 /* just unref, nothing changed */
639 gst_event_unref (ev_ret.event);
648 /* should be called with LOCK */
650 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
654 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
655 GST_STIME_ARGS (pad->offset));
657 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
660 g_assert (!upstream);
662 /* copy segment values */
663 gst_event_copy_segment (event, &segment);
664 gst_event_unref (event);
666 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
667 event = gst_event_new_segment (&segment);
670 event = gst_event_make_writable (event);
671 offset = gst_event_get_running_time_offset (event);
673 offset -= pad->offset;
675 offset += pad->offset;
676 gst_event_set_running_time_offset (event, offset);
681 static inline GstEvent *
682 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
684 if (G_UNLIKELY (pad->offset != 0))
685 return _apply_pad_offset (pad, event, upstream);
690 /* should be called with the OBJECT_LOCK */
692 get_pad_caps (GstPad * pad)
694 GstCaps *caps = NULL;
697 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
699 gst_event_parse_caps (ev->event, &caps);
705 gst_pad_dispose (GObject * object)
707 GstPad *pad = GST_PAD_CAST (object);
710 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
712 /* unlink the peer pad */
713 if ((peer = gst_pad_get_peer (pad))) {
714 /* window for MT unsafeness, someone else could unlink here
715 * and then we call unlink with wrong pads. The unlink
716 * function would catch this and safely return failed. */
717 if (GST_PAD_IS_SRC (pad))
718 gst_pad_unlink (pad, peer);
720 gst_pad_unlink (peer, pad);
722 gst_object_unref (peer);
725 gst_pad_set_pad_template (pad, NULL);
727 GST_OBJECT_LOCK (pad);
729 GST_OBJECT_UNLOCK (pad);
731 g_hook_list_clear (&pad->probes);
733 G_OBJECT_CLASS (parent_class)->dispose (object);
737 gst_pad_finalize (GObject * object)
739 GstPad *pad = GST_PAD_CAST (object);
742 /* in case the task is still around, clean it up */
743 if ((task = GST_PAD_TASK (pad))) {
744 gst_task_join (task);
745 GST_PAD_TASK (pad) = NULL;
746 gst_object_unref (task);
749 if (pad->activatenotify)
750 pad->activatenotify (pad->activatedata);
751 if (pad->activatemodenotify)
752 pad->activatemodenotify (pad->activatemodedata);
754 pad->linknotify (pad->linkdata);
755 if (pad->unlinknotify)
756 pad->unlinknotify (pad->unlinkdata);
757 if (pad->chainnotify)
758 pad->chainnotify (pad->chaindata);
759 if (pad->chainlistnotify)
760 pad->chainlistnotify (pad->chainlistdata);
761 if (pad->getrangenotify)
762 pad->getrangenotify (pad->getrangedata);
763 if (pad->eventnotify)
764 pad->eventnotify (pad->eventdata);
765 if (pad->querynotify)
766 pad->querynotify (pad->querydata);
767 if (pad->iterintlinknotify)
768 pad->iterintlinknotify (pad->iterintlinkdata);
770 g_rec_mutex_clear (&pad->stream_rec_lock);
771 g_cond_clear (&pad->block_cond);
772 g_cond_clear (&pad->priv->activation_cond);
773 g_array_free (pad->priv->events, TRUE);
775 G_OBJECT_CLASS (parent_class)->finalize (object);
779 gst_pad_set_property (GObject * object, guint prop_id,
780 const GValue * value, GParamSpec * pspec)
782 g_return_if_fail (GST_IS_PAD (object));
785 case PAD_PROP_DIRECTION:
786 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
788 case PAD_PROP_TEMPLATE:
789 gst_pad_set_pad_template (GST_PAD_CAST (object),
790 (GstPadTemplate *) g_value_get_object (value));
792 case PAD_PROP_OFFSET:
793 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
796 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
802 gst_pad_get_property (GObject * object, guint prop_id,
803 GValue * value, GParamSpec * pspec)
805 g_return_if_fail (GST_IS_PAD (object));
809 GST_OBJECT_LOCK (object);
810 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
811 GST_OBJECT_UNLOCK (object);
813 case PAD_PROP_DIRECTION:
814 g_value_set_enum (value, GST_PAD_DIRECTION (object));
816 case PAD_PROP_TEMPLATE:
817 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
819 case PAD_PROP_OFFSET:
820 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
823 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
830 * @name: (allow-none): the name of the new pad.
831 * @direction: the #GstPadDirection of the pad.
833 * Creates a new pad with the given name in the given direction.
834 * If name is %NULL, a guaranteed unique name (across all pads)
836 * This function makes a copy of the name so you can safely free the name.
838 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
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) (nullable): a new #GstPad, or %NULL in
864 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
866 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
868 GST_PAD_TEMPLATE_GTYPE (templ) ==
869 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
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) (nullable): a new #GstPad, or %NULL in
889 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
893 GstPadTemplate *template;
895 template = gst_static_pad_template_get (templ);
896 pad = gst_pad_new_from_template (template, name);
897 gst_object_unref (template);
901 #define ACQUIRE_PARENT(pad, parent, label) \
903 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
904 gst_object_ref (parent); \
905 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
909 #define RELEASE_PARENT(parent) \
911 if (G_LIKELY (parent)) \
912 gst_object_unref (parent); \
916 * gst_pad_get_direction:
917 * @pad: a #GstPad to get the direction of.
919 * Gets the direction of the pad. The direction of the pad is
920 * decided at construction time so this function does not take
923 * Returns: the #GstPadDirection of the pad.
928 gst_pad_get_direction (GstPad * pad)
930 GstPadDirection result;
932 /* PAD_UNKNOWN is a little silly but we need some sort of
933 * error return value */
934 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
936 result = GST_PAD_DIRECTION (pad);
942 gst_pad_activate_default (GstPad * pad, GstObject * parent)
944 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
946 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
950 * gst_pad_mode_get_name:
951 * @mode: the pad mode
953 * Return the name of a pad mode, for use in debug messages mostly.
955 * Returns: short mnemonic for pad mode @mode
958 gst_pad_mode_get_name (GstPadMode mode)
961 case GST_PAD_MODE_NONE:
963 case GST_PAD_MODE_PUSH:
965 case GST_PAD_MODE_PULL:
973 /* Returns TRUE if pad wasn't already in the new_mode */
975 pre_activate (GstPad * pad, GstPadMode new_mode)
978 case GST_PAD_MODE_NONE:
979 GST_OBJECT_LOCK (pad);
980 while (G_UNLIKELY (pad->priv->in_activation))
981 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
982 if (new_mode == GST_PAD_MODE (pad)) {
983 GST_WARNING_OBJECT (pad,
984 "Pad is already in the process of being deactivated");
985 GST_OBJECT_UNLOCK (pad);
988 pad->priv->in_activation = TRUE;
989 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
990 GST_PAD_SET_FLUSHING (pad);
991 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
992 GST_PAD_MODE (pad) = new_mode;
993 /* unlock blocked pads so element can resume and stop */
994 GST_PAD_BLOCK_BROADCAST (pad);
995 GST_OBJECT_UNLOCK (pad);
997 case GST_PAD_MODE_PUSH:
998 case GST_PAD_MODE_PULL:
999 GST_OBJECT_LOCK (pad);
1000 while (G_UNLIKELY (pad->priv->in_activation))
1001 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1002 if (new_mode == GST_PAD_MODE (pad)) {
1003 GST_WARNING_OBJECT (pad,
1004 "Pad is already in the process of being activated");
1005 GST_OBJECT_UNLOCK (pad);
1008 pad->priv->in_activation = TRUE;
1009 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1010 gst_pad_mode_get_name (new_mode));
1011 GST_PAD_UNSET_FLUSHING (pad);
1012 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1013 GST_PAD_MODE (pad) = new_mode;
1014 if (GST_PAD_IS_SINK (pad)) {
1016 /* make sure the peer src pad sends us all events */
1017 if ((peer = GST_PAD_PEER (pad))) {
1018 gst_object_ref (peer);
1019 GST_OBJECT_UNLOCK (pad);
1021 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1022 GST_DEBUG_PAD_NAME (peer));
1024 GST_OBJECT_LOCK (peer);
1025 schedule_events (peer, NULL);
1026 GST_OBJECT_UNLOCK (peer);
1028 gst_object_unref (peer);
1030 GST_OBJECT_UNLOCK (pad);
1033 GST_OBJECT_UNLOCK (pad);
1041 post_activate (GstPad * pad, GstPadMode new_mode)
1044 case GST_PAD_MODE_NONE:
1045 GST_OBJECT_LOCK (pad);
1046 pad->priv->in_activation = FALSE;
1047 g_cond_broadcast (&pad->priv->activation_cond);
1048 GST_OBJECT_UNLOCK (pad);
1050 /* ensures that streaming stops */
1051 GST_PAD_STREAM_LOCK (pad);
1052 GST_DEBUG_OBJECT (pad, "stopped streaming");
1053 GST_OBJECT_LOCK (pad);
1054 remove_events (pad);
1055 GST_OBJECT_UNLOCK (pad);
1056 GST_PAD_STREAM_UNLOCK (pad);
1058 case GST_PAD_MODE_PUSH:
1059 case GST_PAD_MODE_PULL:
1060 GST_OBJECT_LOCK (pad);
1061 pad->priv->in_activation = FALSE;
1062 g_cond_broadcast (&pad->priv->activation_cond);
1063 GST_OBJECT_UNLOCK (pad);
1070 * gst_pad_set_active:
1071 * @pad: the #GstPad to activate or deactivate.
1072 * @active: whether or not the pad should be active.
1074 * Activates or deactivates the given pad.
1075 * Normally called from within core state change functions.
1077 * If @active, makes sure the pad is active. If it is already active, either in
1078 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1079 * function to perform the actual activation.
1081 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1082 * and a %FALSE argument.
1084 * Returns: %TRUE if the operation was successful.
1089 gst_pad_set_active (GstPad * pad, gboolean active)
1093 gboolean ret = FALSE;
1095 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1097 GST_OBJECT_LOCK (pad);
1098 old = GST_PAD_MODE (pad);
1099 ACQUIRE_PARENT (pad, parent, no_parent);
1100 GST_OBJECT_UNLOCK (pad);
1103 if (old == GST_PAD_MODE_NONE) {
1104 GST_DEBUG_OBJECT (pad, "activating pad from none");
1105 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1107 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1109 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1110 gst_pad_mode_get_name (old));
1114 if (old == GST_PAD_MODE_NONE) {
1115 GST_DEBUG_OBJECT (pad, "pad was inactive");
1118 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1119 gst_pad_mode_get_name (old));
1120 ret = activate_mode_internal (pad, parent, old, FALSE);
1122 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1126 RELEASE_PARENT (parent);
1128 if (G_UNLIKELY (!ret))
1136 GST_DEBUG_OBJECT (pad, "no parent");
1137 GST_OBJECT_UNLOCK (pad);
1142 GST_OBJECT_LOCK (pad);
1144 g_critical ("Failed to deactivate pad %s:%s, very bad",
1145 GST_DEBUG_PAD_NAME (pad));
1147 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1149 GST_OBJECT_UNLOCK (pad);
1155 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1158 gboolean res = FALSE;
1159 GstPadMode old, new;
1160 GstPadDirection dir;
1163 GST_OBJECT_LOCK (pad);
1164 old = GST_PAD_MODE (pad);
1165 dir = GST_PAD_DIRECTION (pad);
1166 GST_OBJECT_UNLOCK (pad);
1168 new = active ? mode : GST_PAD_MODE_NONE;
1173 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1174 /* pad was activate in the wrong direction, deactivate it
1175 * and reactivate it in the requested mode */
1176 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1177 gst_pad_mode_get_name (old));
1179 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1180 goto deactivate_failed;
1181 old = GST_PAD_MODE_NONE;
1185 case GST_PAD_MODE_PULL:
1187 if (dir == GST_PAD_SINK) {
1188 if ((peer = gst_pad_get_peer (pad))) {
1189 GST_DEBUG_OBJECT (pad, "calling peer");
1190 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1192 gst_object_unref (peer);
1194 /* there is no peer, this is only fatal when we activate. When we
1195 * deactivate, we must assume the application has unlinked the peer and
1196 * will deactivate it eventually. */
1200 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1203 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1204 goto failure; /* Can't activate pull on a src without a
1205 getrange function */
1213 /* Mark pad as needing reconfiguration */
1215 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1217 /* pre_activate returns TRUE if we weren't already in the process of
1218 * switching to the 'new' mode */
1219 if (pre_activate (pad, new)) {
1221 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1222 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1226 /* can happen for sinks of passthrough elements */
1229 post_activate (pad, new);
1232 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1233 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1238 /* Clear sticky flags on deactivation */
1240 GST_OBJECT_LOCK (pad);
1241 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1242 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1243 GST_OBJECT_UNLOCK (pad);
1251 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1252 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1257 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1258 "failed to %s in switch to %s mode from %s mode",
1259 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1260 gst_pad_mode_get_name (old));
1265 GST_OBJECT_LOCK (peer);
1266 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1267 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1268 GST_OBJECT_UNLOCK (peer);
1269 gst_object_unref (peer);
1274 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1275 "pad in pull mode");
1280 GST_OBJECT_LOCK (pad);
1281 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1282 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1283 GST_PAD_SET_FLUSHING (pad);
1284 GST_PAD_MODE (pad) = old;
1285 pad->priv->in_activation = FALSE;
1286 g_cond_broadcast (&pad->priv->activation_cond);
1287 GST_OBJECT_UNLOCK (pad);
1293 * gst_pad_activate_mode:
1294 * @pad: the #GstPad to activate or deactivate.
1295 * @mode: the requested activation mode
1296 * @active: whether or not the pad should be active.
1298 * Activates or deactivates the given pad in @mode via dispatching to the
1299 * pad's activatemodefunc. For use from within pad activation functions only.
1301 * If you don't know what this is, you probably don't want to call it.
1303 * Returns: %TRUE if the operation was successful.
1308 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1312 GstPadMode old, new;
1314 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1316 GST_OBJECT_LOCK (pad);
1318 old = GST_PAD_MODE (pad);
1319 new = active ? mode : GST_PAD_MODE_NONE;
1323 ACQUIRE_PARENT (pad, parent, no_parent);
1325 GST_OBJECT_UNLOCK (pad);
1327 res = activate_mode_internal (pad, parent, mode, active);
1329 RELEASE_PARENT (parent);
1335 GST_OBJECT_UNLOCK (pad);
1336 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1337 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1342 GST_WARNING_OBJECT (pad, "no parent");
1343 GST_OBJECT_UNLOCK (pad);
1349 * gst_pad_is_active:
1350 * @pad: the #GstPad to query
1352 * Query if a pad is active
1354 * Returns: %TRUE if the pad is active.
1359 gst_pad_is_active (GstPad * pad)
1361 gboolean result = FALSE;
1363 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1365 GST_OBJECT_LOCK (pad);
1366 result = GST_PAD_IS_ACTIVE (pad);
1367 GST_OBJECT_UNLOCK (pad);
1373 cleanup_hook (GstPad * pad, GHook * hook)
1375 GstPadProbeType type;
1377 if (!G_HOOK_IS_VALID (hook))
1380 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1382 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1383 /* unblock when we remove the last blocking probe */
1385 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1388 /* Might have new probes now that want to be called */
1389 GST_PAD_BLOCK_BROADCAST (pad);
1391 if (pad->num_blocked == 0) {
1392 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1393 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1396 g_hook_destroy_link (&pad->probes, hook);
1401 * gst_pad_add_probe:
1402 * @pad: the #GstPad to add the probe to
1403 * @mask: the probe mask
1404 * @callback: #GstPadProbeCallback that will be called with notifications of
1406 * @user_data: (closure): user data passed to the callback
1407 * @destroy_data: #GDestroyNotify for user_data
1409 * Be notified of different states of pads. The provided callback is called for
1410 * every state that matches @mask.
1412 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1413 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1414 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1415 * immediately if the pad is already idle while calling gst_pad_add_probe().
1416 * In each of the groups, probes are called in the order in which they were
1419 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1420 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1421 * happen that the probe can be run immediately and if the probe returns
1422 * GST_PAD_PROBE_REMOVE this functions returns 0.
1427 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1428 GstPadProbeCallback callback, gpointer user_data,
1429 GDestroyNotify destroy_data)
1434 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1435 g_return_val_if_fail (mask != 0, 0);
1437 GST_OBJECT_LOCK (pad);
1439 /* make a new probe */
1440 hook = g_hook_alloc (&pad->probes);
1442 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1445 /* when no contraints are given for the types, assume all types are
1447 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1448 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1449 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1450 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1452 /* store our flags and other fields */
1453 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1454 hook->func = callback;
1455 hook->data = user_data;
1456 hook->destroy = destroy_data;
1457 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1460 g_hook_append (&pad->probes, hook);
1462 /* incremenent cookie so that the new hook get's called */
1463 pad->priv->probe_list_cookie++;
1465 /* get the id of the hook, we return this and it can be used to remove the
1467 res = hook->hook_id;
1469 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1471 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1472 /* we have a block probe */
1474 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1475 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1476 "now %d blocking probes", pad->num_blocked);
1478 /* Might have new probes now that want to be called */
1479 GST_PAD_BLOCK_BROADCAST (pad);
1482 /* call the callback if we need to be called for idle callbacks */
1483 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1484 if (pad->priv->using > 0) {
1485 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1486 * flag above, the last thread to leave the push will do the callback. New
1487 * threads going into the push will block. */
1488 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1489 "pad is in use, delay idle callback");
1490 GST_OBJECT_UNLOCK (pad);
1492 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1493 GstPadProbeReturn ret;
1495 /* Keep another ref, the callback could destroy the pad */
1496 gst_object_ref (pad);
1497 pad->priv->idle_running++;
1499 /* the pad is idle now, we can signal the idle callback now */
1500 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1501 "pad is idle, trigger idle callback");
1502 GST_OBJECT_UNLOCK (pad);
1504 ret = callback (pad, &info, user_data);
1506 GST_OBJECT_LOCK (pad);
1508 case GST_PAD_PROBE_REMOVE:
1509 /* remove the probe */
1510 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1511 cleanup_hook (pad, hook);
1514 case GST_PAD_PROBE_DROP:
1515 GST_DEBUG_OBJECT (pad, "asked to drop item");
1517 case GST_PAD_PROBE_PASS:
1518 GST_DEBUG_OBJECT (pad, "asked to pass item");
1520 case GST_PAD_PROBE_OK:
1521 GST_DEBUG_OBJECT (pad, "probe returned OK");
1523 case GST_PAD_PROBE_HANDLED:
1524 GST_DEBUG_OBJECT (pad, "probe handled the data");
1527 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1530 pad->priv->idle_running--;
1531 if (pad->priv->idle_running == 0) {
1532 GST_PAD_BLOCK_BROADCAST (pad);
1534 GST_OBJECT_UNLOCK (pad);
1536 gst_object_unref (pad);
1539 GST_OBJECT_UNLOCK (pad);
1545 * gst_pad_remove_probe:
1546 * @pad: the #GstPad with the probe
1547 * @id: the probe id to remove
1549 * Remove the probe with @id from @pad.
1554 gst_pad_remove_probe (GstPad * pad, gulong id)
1558 g_return_if_fail (GST_IS_PAD (pad));
1560 GST_OBJECT_LOCK (pad);
1562 hook = g_hook_get (&pad->probes, id);
1566 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1568 cleanup_hook (pad, hook);
1569 GST_OBJECT_UNLOCK (pad);
1575 GST_OBJECT_UNLOCK (pad);
1576 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1582 * gst_pad_is_blocked:
1583 * @pad: the #GstPad to query
1585 * Checks if the pad is blocked or not. This function returns the
1586 * last requested state of the pad. It is not certain that the pad
1587 * is actually blocking at this point (see gst_pad_is_blocking()).
1589 * Returns: %TRUE if the pad is blocked.
1594 gst_pad_is_blocked (GstPad * pad)
1596 gboolean result = FALSE;
1598 g_return_val_if_fail (GST_IS_PAD (pad), result);
1600 GST_OBJECT_LOCK (pad);
1601 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1602 GST_OBJECT_UNLOCK (pad);
1608 * gst_pad_is_blocking:
1609 * @pad: the #GstPad to query
1611 * Checks if the pad is blocking or not. This is a guaranteed state
1612 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1614 * Returns: %TRUE if the pad is blocking.
1619 gst_pad_is_blocking (GstPad * pad)
1621 gboolean result = FALSE;
1623 g_return_val_if_fail (GST_IS_PAD (pad), result);
1625 GST_OBJECT_LOCK (pad);
1626 /* the blocking flag is only valid if the pad is not flushing */
1627 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1628 GST_OBJECT_UNLOCK (pad);
1634 * gst_pad_needs_reconfigure:
1635 * @pad: the #GstPad to check
1637 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1638 * if the flag was set.
1640 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1643 gst_pad_needs_reconfigure (GstPad * pad)
1645 gboolean reconfigure;
1647 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1649 GST_OBJECT_LOCK (pad);
1650 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1651 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1652 GST_OBJECT_UNLOCK (pad);
1658 * gst_pad_check_reconfigure:
1659 * @pad: the #GstPad to check
1661 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1662 * if the flag was set.
1664 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1667 gst_pad_check_reconfigure (GstPad * pad)
1669 gboolean reconfigure;
1671 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1673 GST_OBJECT_LOCK (pad);
1674 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1676 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1677 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1679 GST_OBJECT_UNLOCK (pad);
1685 * gst_pad_mark_reconfigure:
1686 * @pad: the #GstPad to mark
1688 * Mark a pad for needing reconfiguration. The next call to
1689 * gst_pad_check_reconfigure() will return %TRUE after this call.
1692 gst_pad_mark_reconfigure (GstPad * pad)
1694 g_return_if_fail (GST_IS_PAD (pad));
1696 GST_OBJECT_LOCK (pad);
1697 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1698 GST_OBJECT_UNLOCK (pad);
1702 * gst_pad_set_activate_function:
1704 * @f: the #GstPadActivateFunction to set.
1706 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1710 * gst_pad_set_activate_function_full:
1712 * @activate: the #GstPadActivateFunction to set.
1713 * @user_data: user_data passed to @notify
1714 * @notify: notify called when @activate will not be used anymore.
1716 * Sets the given activate function for @pad. The activate function will
1717 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1718 * Only makes sense to set on sink pads.
1720 * Call this function if your sink pad can start a pull-based task.
1723 gst_pad_set_activate_function_full (GstPad * pad,
1724 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1726 g_return_if_fail (GST_IS_PAD (pad));
1728 if (pad->activatenotify)
1729 pad->activatenotify (pad->activatedata);
1730 GST_PAD_ACTIVATEFUNC (pad) = activate;
1731 pad->activatedata = user_data;
1732 pad->activatenotify = notify;
1734 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1735 GST_DEBUG_FUNCPTR_NAME (activate));
1739 * gst_pad_set_activatemode_function:
1741 * @f: the #GstPadActivateModeFunction to set.
1743 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1747 * gst_pad_set_activatemode_function_full:
1749 * @activatemode: the #GstPadActivateModeFunction to set.
1750 * @user_data: user_data passed to @notify
1751 * @notify: notify called when @activatemode will not be used anymore.
1753 * Sets the given activate_mode function for the pad. An activate_mode function
1754 * prepares the element for data passing.
1757 gst_pad_set_activatemode_function_full (GstPad * pad,
1758 GstPadActivateModeFunction activatemode, gpointer user_data,
1759 GDestroyNotify notify)
1761 g_return_if_fail (GST_IS_PAD (pad));
1763 if (pad->activatemodenotify)
1764 pad->activatemodenotify (pad->activatemodedata);
1765 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1766 pad->activatemodedata = user_data;
1767 pad->activatemodenotify = notify;
1769 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1770 GST_DEBUG_FUNCPTR_NAME (activatemode));
1774 * gst_pad_set_chain_function:
1775 * @p: a sink #GstPad.
1776 * @f: the #GstPadChainFunction to set.
1778 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1782 * gst_pad_set_chain_function_full:
1783 * @pad: a sink #GstPad.
1784 * @chain: the #GstPadChainFunction to set.
1785 * @user_data: user_data passed to @notify
1786 * @notify: notify called when @chain will not be used anymore.
1788 * Sets the given chain function for the pad. The chain function is called to
1789 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1792 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1793 gpointer user_data, GDestroyNotify notify)
1795 g_return_if_fail (GST_IS_PAD (pad));
1796 g_return_if_fail (GST_PAD_IS_SINK (pad));
1798 if (pad->chainnotify)
1799 pad->chainnotify (pad->chaindata);
1800 GST_PAD_CHAINFUNC (pad) = chain;
1801 pad->chaindata = user_data;
1802 pad->chainnotify = notify;
1804 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1805 GST_DEBUG_FUNCPTR_NAME (chain));
1809 * gst_pad_set_chain_list_function:
1810 * @p: a sink #GstPad.
1811 * @f: the #GstPadChainListFunction to set.
1813 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1817 * gst_pad_set_chain_list_function_full:
1818 * @pad: a sink #GstPad.
1819 * @chainlist: the #GstPadChainListFunction to set.
1820 * @user_data: user_data passed to @notify
1821 * @notify: notify called when @chainlist will not be used anymore.
1823 * Sets the given chain list function for the pad. The chainlist function is
1824 * called to process a #GstBufferList input buffer list. See
1825 * #GstPadChainListFunction for more details.
1828 gst_pad_set_chain_list_function_full (GstPad * pad,
1829 GstPadChainListFunction chainlist, gpointer user_data,
1830 GDestroyNotify notify)
1832 g_return_if_fail (GST_IS_PAD (pad));
1833 g_return_if_fail (GST_PAD_IS_SINK (pad));
1835 if (pad->chainlistnotify)
1836 pad->chainlistnotify (pad->chainlistdata);
1837 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1838 pad->chainlistdata = user_data;
1839 pad->chainlistnotify = notify;
1841 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1842 GST_DEBUG_FUNCPTR_NAME (chainlist));
1846 * gst_pad_set_getrange_function:
1847 * @p: a source #GstPad.
1848 * @f: the #GstPadGetRangeFunction to set.
1850 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1854 * gst_pad_set_getrange_function_full:
1855 * @pad: a source #GstPad.
1856 * @get: the #GstPadGetRangeFunction to set.
1857 * @user_data: user_data passed to @notify
1858 * @notify: notify called when @get will not be used anymore.
1860 * Sets the given getrange function for the pad. The getrange function is
1861 * called to produce a new #GstBuffer to start the processing pipeline. see
1862 * #GstPadGetRangeFunction for a description of the getrange function.
1865 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1866 gpointer user_data, GDestroyNotify notify)
1868 g_return_if_fail (GST_IS_PAD (pad));
1869 g_return_if_fail (GST_PAD_IS_SRC (pad));
1871 if (pad->getrangenotify)
1872 pad->getrangenotify (pad->getrangedata);
1873 GST_PAD_GETRANGEFUNC (pad) = get;
1874 pad->getrangedata = user_data;
1875 pad->getrangenotify = notify;
1877 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1878 GST_DEBUG_FUNCPTR_NAME (get));
1882 * gst_pad_set_event_function:
1883 * @p: a #GstPad of either direction.
1884 * @f: the #GstPadEventFunction to set.
1886 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1890 * gst_pad_set_event_function_full:
1891 * @pad: a #GstPad of either direction.
1892 * @event: the #GstPadEventFunction to set.
1893 * @user_data: user_data passed to @notify
1894 * @notify: notify called when @event will not be used anymore.
1896 * Sets the given event handler for the pad.
1899 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1900 gpointer user_data, GDestroyNotify notify)
1902 g_return_if_fail (GST_IS_PAD (pad));
1904 if (pad->eventnotify)
1905 pad->eventnotify (pad->eventdata);
1906 GST_PAD_EVENTFUNC (pad) = event;
1907 pad->eventdata = user_data;
1908 pad->eventnotify = notify;
1910 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1911 GST_DEBUG_FUNCPTR_NAME (event));
1915 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1919 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1920 if (ret == GST_FLOW_OK)
1926 * gst_pad_set_event_full_function:
1927 * @p: a #GstPad of either direction.
1928 * @f: the #GstPadEventFullFunction to set.
1930 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1934 * gst_pad_set_event_full_function_full:
1935 * @pad: a #GstPad of either direction.
1936 * @event: the #GstPadEventFullFunction to set.
1937 * @user_data: user_data passed to @notify
1938 * @notify: notify called when @event will not be used anymore.
1940 * Sets the given event handler for the pad.
1945 gst_pad_set_event_full_function_full (GstPad * pad,
1946 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1948 g_return_if_fail (GST_IS_PAD (pad));
1950 if (pad->eventnotify)
1951 pad->eventnotify (pad->eventdata);
1952 GST_PAD_EVENTFULLFUNC (pad) = event;
1953 GST_PAD_EVENTFUNC (pad) = event_wrap;
1954 pad->eventdata = user_data;
1955 pad->eventnotify = notify;
1957 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1958 GST_DEBUG_FUNCPTR_NAME (event));
1962 * gst_pad_set_query_function:
1963 * @p: a #GstPad of either direction.
1964 * @f: the #GstPadQueryFunction to set.
1966 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1970 * gst_pad_set_query_function_full:
1971 * @pad: a #GstPad of either direction.
1972 * @query: the #GstPadQueryFunction to set.
1973 * @user_data: user_data passed to @notify
1974 * @notify: notify called when @query will not be used anymore.
1976 * Set the given query function for the pad.
1979 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1980 gpointer user_data, GDestroyNotify notify)
1982 g_return_if_fail (GST_IS_PAD (pad));
1984 if (pad->querynotify)
1985 pad->querynotify (pad->querydata);
1986 GST_PAD_QUERYFUNC (pad) = query;
1987 pad->querydata = user_data;
1988 pad->querynotify = notify;
1990 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1991 GST_DEBUG_FUNCPTR_NAME (query));
1995 * gst_pad_set_iterate_internal_links_function:
1996 * @p: a #GstPad of either direction.
1997 * @f: the #GstPadIterIntLinkFunction to set.
1999 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
2000 * for the user_data and notify.
2003 * gst_pad_set_iterate_internal_links_function_full:
2004 * @pad: a #GstPad of either direction.
2005 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2006 * @user_data: user_data passed to @notify
2007 * @notify: notify called when @iterintlink will not be used anymore.
2009 * Sets the given internal link iterator function for the pad.
2012 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2013 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2014 GDestroyNotify notify)
2016 g_return_if_fail (GST_IS_PAD (pad));
2018 if (pad->iterintlinknotify)
2019 pad->iterintlinknotify (pad->iterintlinkdata);
2020 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2021 pad->iterintlinkdata = user_data;
2022 pad->iterintlinknotify = notify;
2024 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2025 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2029 * gst_pad_set_link_function:
2031 * @f: the #GstPadLinkFunction to set.
2033 * Calls gst_pad_set_link_function_full() with %NULL
2034 * for the user_data and notify.
2037 * gst_pad_set_link_function_full:
2039 * @link: the #GstPadLinkFunction to set.
2040 * @user_data: user_data passed to @notify
2041 * @notify: notify called when @link will not be used anymore.
2043 * Sets the given link function for the pad. It will be called when
2044 * the pad is linked with another pad.
2046 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2049 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2050 * cannot be made for some reason.
2052 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2053 * of the peer sink pad, if present.
2056 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2057 gpointer user_data, GDestroyNotify notify)
2059 g_return_if_fail (GST_IS_PAD (pad));
2061 if (pad->linknotify)
2062 pad->linknotify (pad->linkdata);
2063 GST_PAD_LINKFUNC (pad) = link;
2064 pad->linkdata = user_data;
2065 pad->linknotify = notify;
2067 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2068 GST_DEBUG_FUNCPTR_NAME (link));
2072 * gst_pad_set_unlink_function:
2074 * @f: the #GstPadUnlinkFunction to set.
2076 * Calls gst_pad_set_unlink_function_full() with %NULL
2077 * for the user_data and notify.
2080 * gst_pad_set_unlink_function_full:
2082 * @unlink: the #GstPadUnlinkFunction to set.
2083 * @user_data: user_data passed to @notify
2084 * @notify: notify called when @unlink will not be used anymore.
2086 * Sets the given unlink function for the pad. It will be called
2087 * when the pad is unlinked.
2090 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2091 gpointer user_data, GDestroyNotify notify)
2093 g_return_if_fail (GST_IS_PAD (pad));
2095 if (pad->unlinknotify)
2096 pad->unlinknotify (pad->unlinkdata);
2097 GST_PAD_UNLINKFUNC (pad) = unlink;
2098 pad->unlinkdata = user_data;
2099 pad->unlinknotify = notify;
2101 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2102 GST_DEBUG_FUNCPTR_NAME (unlink));
2107 * @srcpad: the source #GstPad to unlink.
2108 * @sinkpad: the sink #GstPad to unlink.
2110 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2111 * signal on both pads.
2113 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2114 * the pads were not linked together.
2119 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2121 gboolean result = FALSE;
2122 GstElement *parent = NULL;
2124 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2125 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2126 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2127 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2129 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2131 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2132 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2133 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2135 /* We need to notify the parent before taking any pad locks as the bin in
2136 * question might be waiting for a lock on the pad while holding its lock
2137 * that our message will try to take. */
2138 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2139 if (GST_IS_ELEMENT (parent)) {
2140 gst_element_post_message (parent,
2141 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2142 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2144 gst_object_unref (parent);
2149 GST_OBJECT_LOCK (srcpad);
2150 GST_OBJECT_LOCK (sinkpad);
2152 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2153 goto not_linked_together;
2155 if (GST_PAD_UNLINKFUNC (srcpad)) {
2156 GstObject *tmpparent;
2158 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2160 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2161 RELEASE_PARENT (tmpparent);
2164 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2165 GstObject *tmpparent;
2167 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2169 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2170 RELEASE_PARENT (tmpparent);
2174 /* first clear peers */
2175 GST_PAD_PEER (srcpad) = NULL;
2176 GST_PAD_PEER (sinkpad) = NULL;
2178 GST_OBJECT_UNLOCK (sinkpad);
2179 GST_OBJECT_UNLOCK (srcpad);
2181 /* fire off a signal to each of the pads telling them
2182 * that they've been unlinked */
2183 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2184 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2186 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2187 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2192 if (parent != NULL) {
2193 gst_element_post_message (parent,
2194 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2195 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2196 gst_object_unref (parent);
2198 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2202 not_linked_together:
2204 /* we do not emit a warning in this case because unlinking cannot
2205 * be made MT safe.*/
2206 GST_OBJECT_UNLOCK (sinkpad);
2207 GST_OBJECT_UNLOCK (srcpad);
2213 * gst_pad_is_linked:
2214 * @pad: pad to check
2216 * Checks if a @pad is linked to another pad or not.
2218 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2223 gst_pad_is_linked (GstPad * pad)
2227 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2229 GST_OBJECT_LOCK (pad);
2230 result = (GST_PAD_PEER (pad) != NULL);
2231 GST_OBJECT_UNLOCK (pad);
2236 /* get the caps from both pads and see if the intersection
2239 * This function should be called with the pad LOCK on both
2243 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2244 GstPadLinkCheck flags)
2246 GstCaps *srccaps = NULL;
2247 GstCaps *sinkcaps = NULL;
2248 gboolean compatible = FALSE;
2250 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2253 /* Doing the expensive caps checking takes priority over only checking the template caps */
2254 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2255 GST_OBJECT_UNLOCK (sink);
2256 GST_OBJECT_UNLOCK (src);
2258 srccaps = gst_pad_query_caps (src, NULL);
2259 sinkcaps = gst_pad_query_caps (sink, NULL);
2261 GST_OBJECT_LOCK (src);
2262 GST_OBJECT_LOCK (sink);
2264 /* If one of the two pads doesn't have a template, consider the intersection
2266 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2267 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2271 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2273 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2276 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2278 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2281 /* if we have caps on both pads we can check the intersection. If one
2282 * of the caps is %NULL, we return %TRUE. */
2283 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2285 gst_caps_unref (srccaps);
2287 gst_caps_unref (sinkcaps);
2291 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2292 gst_caps_unref (srccaps);
2293 gst_caps_unref (sinkcaps);
2296 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2297 (compatible ? "" : "not "));
2302 /* check if the grandparents of both pads are the same.
2303 * This check is required so that we don't try to link
2304 * pads from elements in different bins without ghostpads.
2306 * The LOCK should be held on both pads
2309 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2311 GstObject *psrc, *psink;
2313 psrc = GST_OBJECT_PARENT (src);
2314 psink = GST_OBJECT_PARENT (sink);
2316 /* if one of the pads has no parent, we allow the link */
2317 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2320 /* only care about parents that are elements */
2321 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2322 goto no_element_parent;
2324 /* if the parents are the same, we have a loop */
2325 if (G_UNLIKELY (psrc == psink))
2328 /* if they both have a parent, we check the grandparents. We can not lock
2329 * the parent because we hold on the child (pad) and the locking order is
2330 * parent >> child. */
2331 psrc = GST_OBJECT_PARENT (psrc);
2332 psink = GST_OBJECT_PARENT (psink);
2334 /* if they have grandparents but they are not the same */
2335 if (G_UNLIKELY (psrc != psink))
2336 goto wrong_grandparents;
2343 GST_CAT_DEBUG (GST_CAT_CAPS,
2344 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2345 GST_PTR_FORMAT, psrc, psink);
2350 GST_CAT_DEBUG (GST_CAT_CAPS,
2351 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2352 GST_PTR_FORMAT, psrc, psink);
2357 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2363 GST_CAT_DEBUG (GST_CAT_CAPS,
2364 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2365 GST_PTR_FORMAT, psrc, psink);
2370 /* FIXME leftover from an attempt at refactoring... */
2371 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2372 * the two pads will be locked in the srcpad, sinkpad order. */
2373 static GstPadLinkReturn
2374 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2376 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2377 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2379 GST_OBJECT_LOCK (srcpad);
2381 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2382 goto src_was_linked;
2384 GST_OBJECT_LOCK (sinkpad);
2386 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2387 goto sink_was_linked;
2389 /* check hierarchy, pads can only be linked if the grandparents
2391 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2392 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2393 goto wrong_hierarchy;
2395 /* check pad caps for non-empty intersection */
2396 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2399 /* FIXME check pad scheduling for non-empty intersection */
2401 return GST_PAD_LINK_OK;
2405 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2406 GST_DEBUG_PAD_NAME (srcpad),
2407 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2408 /* we do not emit a warning in this case because unlinking cannot
2409 * be made MT safe.*/
2410 GST_OBJECT_UNLOCK (srcpad);
2411 return GST_PAD_LINK_WAS_LINKED;
2415 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2416 GST_DEBUG_PAD_NAME (sinkpad),
2417 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2418 /* we do not emit a warning in this case because unlinking cannot
2419 * be made MT safe.*/
2420 GST_OBJECT_UNLOCK (sinkpad);
2421 GST_OBJECT_UNLOCK (srcpad);
2422 return GST_PAD_LINK_WAS_LINKED;
2426 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2427 GST_OBJECT_UNLOCK (sinkpad);
2428 GST_OBJECT_UNLOCK (srcpad);
2429 return GST_PAD_LINK_WRONG_HIERARCHY;
2433 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2434 GST_OBJECT_UNLOCK (sinkpad);
2435 GST_OBJECT_UNLOCK (srcpad);
2436 return GST_PAD_LINK_NOFORMAT;
2442 * @srcpad: the source #GstPad.
2443 * @sinkpad: the sink #GstPad.
2445 * Checks if the source pad and the sink pad are compatible so they can be
2448 * Returns: %TRUE if the pads can be linked.
2451 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2453 GstPadLinkReturn result;
2455 /* generic checks */
2456 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2457 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2459 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2460 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2462 /* gst_pad_link_prepare does everything for us, we only release the locks
2463 * on the pads that it gets us. If this function returns !OK the locks are not
2465 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2466 if (result != GST_PAD_LINK_OK)
2469 GST_OBJECT_UNLOCK (srcpad);
2470 GST_OBJECT_UNLOCK (sinkpad);
2473 return result == GST_PAD_LINK_OK;
2477 * gst_pad_link_full:
2478 * @srcpad: the source #GstPad to link.
2479 * @sinkpad: the sink #GstPad to link.
2480 * @flags: the checks to validate when linking
2482 * Links the source pad and the sink pad.
2484 * This variant of #gst_pad_link provides a more granular control on the
2485 * checks being done when linking. While providing some considerable speedups
2486 * the caller of this method must be aware that wrong usage of those flags
2487 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2488 * for more information.
2492 * Returns: A result code indicating if the connection worked or
2496 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2498 GstPadLinkReturn result;
2500 GstPadLinkFunction srcfunc, sinkfunc;
2502 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2503 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2504 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2505 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2506 GST_PAD_LINK_WRONG_DIRECTION);
2508 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2510 /* Notify the parent early. See gst_pad_unlink for details. */
2511 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2512 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2513 gst_element_post_message (parent,
2514 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2515 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2517 gst_object_unref (parent);
2522 /* prepare will also lock the two pads */
2523 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2525 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2526 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2527 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2528 gst_pad_link_get_name (result));
2532 /* must set peers before calling the link function */
2533 GST_PAD_PEER (srcpad) = sinkpad;
2534 GST_PAD_PEER (sinkpad) = srcpad;
2536 /* check events, when something is different, mark pending */
2537 schedule_events (srcpad, sinkpad);
2539 /* get the link functions */
2540 srcfunc = GST_PAD_LINKFUNC (srcpad);
2541 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2543 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2544 /* custom link functions, execute them */
2545 GST_OBJECT_UNLOCK (sinkpad);
2546 GST_OBJECT_UNLOCK (srcpad);
2549 GstObject *tmpparent;
2551 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2552 /* this one will call the peer link function */
2553 result = srcfunc (srcpad, tmpparent, sinkpad);
2554 RELEASE_PARENT (tmpparent);
2555 } else if (sinkfunc) {
2556 GstObject *tmpparent;
2558 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2559 /* if no source link function, we need to call the sink link
2560 * function ourselves. */
2561 result = sinkfunc (sinkpad, tmpparent, srcpad);
2562 RELEASE_PARENT (tmpparent);
2566 GST_OBJECT_LOCK (srcpad);
2567 GST_OBJECT_LOCK (sinkpad);
2569 /* we released the lock, check if the same pads are linked still */
2570 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2571 goto concurrent_link;
2573 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2576 GST_OBJECT_UNLOCK (sinkpad);
2577 GST_OBJECT_UNLOCK (srcpad);
2579 /* fire off a signal to each of the pads telling them
2580 * that they've been linked */
2581 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2582 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2584 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2585 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2587 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2588 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2591 if (G_LIKELY (parent)) {
2592 gst_element_post_message (parent,
2593 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2594 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2595 gst_object_unref (parent);
2598 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2604 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2605 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2606 GST_OBJECT_UNLOCK (sinkpad);
2607 GST_OBJECT_UNLOCK (srcpad);
2609 /* The other link operation succeeded first */
2610 result = GST_PAD_LINK_WAS_LINKED;
2615 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2616 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2617 gst_pad_link_get_name (result));
2619 GST_PAD_PEER (srcpad) = NULL;
2620 GST_PAD_PEER (sinkpad) = NULL;
2622 GST_OBJECT_UNLOCK (sinkpad);
2623 GST_OBJECT_UNLOCK (srcpad);
2631 * @srcpad: the source #GstPad to link.
2632 * @sinkpad: the sink #GstPad to link.
2634 * Links the source pad and the sink pad.
2636 * Returns: A result code indicating if the connection worked or
2642 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2644 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2648 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2650 GstPadTemplate **template_p;
2652 /* this function would need checks if it weren't static */
2654 GST_OBJECT_LOCK (pad);
2655 template_p = &pad->padtemplate;
2656 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2657 GST_OBJECT_UNLOCK (pad);
2660 gst_pad_template_pad_created (templ, pad);
2664 * gst_pad_get_pad_template:
2667 * Gets the template for @pad.
2669 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2670 * this pad was instantiated, or %NULL if this pad has no
2671 * template. Unref after usage.
2674 gst_pad_get_pad_template (GstPad * pad)
2676 GstPadTemplate *templ;
2678 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2680 templ = GST_PAD_PAD_TEMPLATE (pad);
2682 return (templ ? gst_object_ref (templ) : NULL);
2686 * gst_pad_has_current_caps:
2687 * @pad: a #GstPad to check
2689 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2691 * Returns: %TRUE when @pad has caps associated with it.
2694 gst_pad_has_current_caps (GstPad * pad)
2699 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2701 GST_OBJECT_LOCK (pad);
2702 caps = get_pad_caps (pad);
2703 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2704 "check current pad caps %" GST_PTR_FORMAT, caps);
2705 result = (caps != NULL);
2706 GST_OBJECT_UNLOCK (pad);
2712 * gst_pad_get_current_caps:
2713 * @pad: a #GstPad to get the current capabilities of.
2715 * Gets the capabilities currently configured on @pad with the last
2716 * #GST_EVENT_CAPS event.
2718 * Returns: (transfer full) (nullable): the current caps of the pad with
2719 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2722 gst_pad_get_current_caps (GstPad * pad)
2726 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2728 GST_OBJECT_LOCK (pad);
2729 if ((result = get_pad_caps (pad)))
2730 gst_caps_ref (result);
2731 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2732 "get current pad caps %" GST_PTR_FORMAT, result);
2733 GST_OBJECT_UNLOCK (pad);
2739 * gst_pad_get_pad_template_caps:
2740 * @pad: a #GstPad to get the template capabilities from.
2742 * Gets the capabilities for @pad's template.
2744 * Returns: (transfer full): the #GstCaps of this pad template.
2745 * Unref after usage.
2748 gst_pad_get_pad_template_caps (GstPad * pad)
2750 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2752 if (GST_PAD_PAD_TEMPLATE (pad))
2753 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2755 return gst_caps_ref (GST_CAPS_ANY);
2760 * @pad: a #GstPad to get the peer of.
2762 * Gets the peer of @pad. This function refs the peer pad so
2763 * you need to unref it after use.
2765 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2770 gst_pad_get_peer (GstPad * pad)
2774 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2776 GST_OBJECT_LOCK (pad);
2777 result = GST_PAD_PEER (pad);
2779 gst_object_ref (result);
2780 GST_OBJECT_UNLOCK (pad);
2786 * gst_pad_get_allowed_caps:
2789 * Gets the capabilities of the allowed media types that can flow through
2790 * @pad and its peer.
2792 * The allowed capabilities is calculated as the intersection of the results of
2793 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2794 * on the resulting caps.
2796 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2797 * pad link. Unref the caps when you no longer need it. This
2798 * function returns %NULL when @pad has no peer.
2803 gst_pad_get_allowed_caps (GstPad * pad)
2806 GstCaps *caps = NULL;
2809 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2811 GST_OBJECT_LOCK (pad);
2812 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2814 GST_OBJECT_UNLOCK (pad);
2816 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2818 mycaps = gst_pad_query_caps (pad, NULL);
2820 /* Query peer caps */
2821 query = gst_query_new_caps (mycaps);
2822 if (!gst_pad_peer_query (pad, query)) {
2823 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2827 gst_query_parse_caps_result (query, &caps);
2829 g_warn_if_fail (caps != NULL);
2832 gst_caps_ref (caps);
2834 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2838 gst_query_unref (query);
2839 gst_caps_unref (mycaps);
2845 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2846 GST_OBJECT_UNLOCK (pad);
2853 * gst_pad_iterate_internal_links_default:
2854 * @pad: the #GstPad to get the internal links of.
2855 * @parent: (allow-none): the parent of @pad or %NULL
2857 * Iterate the list of pads to which the given pad is linked to inside of
2858 * the parent element.
2859 * This is the default handler, and thus returns an iterator of all of the
2860 * pads inside the parent element with opposite direction.
2862 * The caller must free this iterator after use with gst_iterator_free().
2864 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2865 * has no parent. Unref each returned pad with gst_object_unref().
2868 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2875 GstElement *eparent;
2877 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2879 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2880 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2882 GST_OBJECT_LOCK (pad);
2883 eparent = GST_PAD_PARENT (pad);
2884 if (!eparent || !GST_IS_ELEMENT (eparent))
2887 gst_object_ref (eparent);
2888 GST_OBJECT_UNLOCK (pad);
2891 if (pad->direction == GST_PAD_SRC)
2892 padlist = &eparent->sinkpads;
2894 padlist = &eparent->srcpads;
2896 GST_DEBUG_OBJECT (pad, "Making iterator");
2898 cookie = &eparent->pads_cookie;
2900 lock = GST_OBJECT_GET_LOCK (eparent);
2902 res = gst_iterator_new_list (GST_TYPE_PAD,
2903 lock, cookie, padlist, (GObject *) owner, NULL);
2905 gst_object_unref (owner);
2912 GST_OBJECT_UNLOCK (pad);
2913 GST_DEBUG_OBJECT (pad, "no parent element");
2919 * gst_pad_iterate_internal_links:
2920 * @pad: the GstPad to get the internal links of.
2922 * Gets an iterator for the pads to which the given pad is linked to inside
2923 * of the parent element.
2925 * Each #GstPad element yielded by the iterator will have its refcount increased,
2926 * so unref after use.
2928 * Free-function: gst_iterator_free
2930 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2931 * or %NULL when the pad does not have an iterator function
2932 * configured. Use gst_iterator_free() after usage.
2935 gst_pad_iterate_internal_links (GstPad * pad)
2937 GstIterator *res = NULL;
2940 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2942 GST_OBJECT_LOCK (pad);
2943 ACQUIRE_PARENT (pad, parent, no_parent);
2944 GST_OBJECT_UNLOCK (pad);
2946 if (GST_PAD_ITERINTLINKFUNC (pad))
2947 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2949 RELEASE_PARENT (parent);
2956 GST_DEBUG_OBJECT (pad, "no parent");
2957 GST_OBJECT_UNLOCK (pad);
2965 * @forward: (scope call): a #GstPadForwardFunction
2966 * @user_data: user data passed to @forward
2968 * Calls @forward for all internally linked pads of @pad. This function deals with
2969 * dynamically changing internal pads and will make sure that the @forward
2970 * function is only called once for each pad.
2972 * When @forward returns %TRUE, no further pads will be processed.
2974 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2977 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2980 gboolean result = FALSE;
2982 gboolean done = FALSE;
2983 GValue item = { 0, };
2984 GList *pushed_pads = NULL;
2986 iter = gst_pad_iterate_internal_links (pad);
2992 switch (gst_iterator_next (iter, &item)) {
2993 case GST_ITERATOR_OK:
2997 intpad = g_value_get_object (&item);
2999 /* if already pushed, skip. FIXME, find something faster to tag pads */
3000 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3001 g_value_reset (&item);
3005 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3006 GST_DEBUG_PAD_NAME (intpad));
3007 done = result = forward (intpad, user_data);
3009 pushed_pads = g_list_prepend (pushed_pads, intpad);
3011 g_value_reset (&item);
3014 case GST_ITERATOR_RESYNC:
3015 /* We don't reset the result here because we don't push the event
3016 * again on pads that got the event already and because we need
3017 * to consider the result of the previous pushes */
3018 gst_iterator_resync (iter);
3020 case GST_ITERATOR_ERROR:
3021 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3024 case GST_ITERATOR_DONE:
3029 g_value_unset (&item);
3030 gst_iterator_free (iter);
3032 g_list_free (pushed_pads);
3042 gboolean dispatched;
3046 event_forward_func (GstPad * pad, EventData * data)
3048 /* for each pad we send to, we should ref the event; it's up
3049 * to downstream to unref again when handled. */
3050 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3051 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3053 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3055 data->dispatched = TRUE;
3062 * gst_pad_event_default:
3063 * @pad: a #GstPad to call the default event handler on.
3064 * @parent: (allow-none): the parent of @pad or %NULL
3065 * @event: (transfer full): the #GstEvent to handle.
3067 * Invokes the default event handler for the given pad.
3069 * The EOS event will pause the task associated with @pad before it is forwarded
3070 * to all internally linked pads,
3072 * The event is sent to all pads internally linked to @pad. This function
3073 * takes ownership of @event.
3075 * Returns: %TRUE if the event was sent successfully.
3078 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3080 gboolean result, forward = TRUE;
3082 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3083 g_return_val_if_fail (event != NULL, FALSE);
3085 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3088 switch (GST_EVENT_TYPE (event)) {
3089 case GST_EVENT_CAPS:
3090 forward = GST_PAD_IS_PROXY_CAPS (pad);
3101 data.dispatched = FALSE;
3102 data.result = FALSE;
3104 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3106 /* for sinkpads without a parent element or without internal links, nothing
3107 * will be dispatched but we still want to return TRUE. */
3108 if (data.dispatched)
3109 result = data.result;
3114 gst_event_unref (event);
3119 /* Default accept caps implementation just checks against
3120 * the allowed caps for the pad */
3122 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3124 /* get the caps and see if it intersects to something not empty */
3125 GstCaps *caps, *allowed = NULL;
3128 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3130 /* first forward the query to internally linked pads when we are dealing with
3132 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3133 result = gst_pad_proxy_query_accept_caps (pad, query);
3135 allowed = gst_pad_get_pad_template_caps (pad);
3140 gst_query_parse_accept_caps (query, &caps);
3142 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3143 allowed = gst_pad_get_pad_template_caps (pad);
3145 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3146 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3147 allowed = gst_pad_query_caps (pad, caps);
3152 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3153 GST_DEBUG_OBJECT (pad,
3154 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3156 result = gst_caps_can_intersect (caps, allowed);
3158 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3159 GST_PTR_FORMAT, allowed, caps);
3160 result = gst_caps_is_subset (caps, allowed);
3162 gst_caps_unref (allowed);
3164 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3167 gst_query_set_accept_caps_result (query, result);
3173 /* Default caps implementation */
3175 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3177 GstCaps *result = NULL, *filter;
3178 GstPadTemplate *templ;
3179 gboolean fixed_caps;
3181 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3184 /* first try to proxy if we must */
3185 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3186 if ((gst_pad_proxy_query_caps (pad, query))) {
3191 gst_query_parse_caps (query, &filter);
3193 /* no proxy or it failed, do default handling */
3194 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3196 GST_OBJECT_LOCK (pad);
3198 /* fixed caps, try the negotiated caps first */
3199 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3200 if ((result = get_pad_caps (pad)))
3201 goto filter_done_unlock;
3204 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3205 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3206 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3207 goto filter_done_unlock;
3211 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3212 "non-fixed pad caps: trying pad caps");
3213 /* non fixed caps, try the negotiated caps */
3214 if ((result = get_pad_caps (pad)))
3215 goto filter_done_unlock;
3218 /* this almost never happens */
3219 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3220 result = GST_CAPS_ANY;
3223 GST_OBJECT_UNLOCK (pad);
3225 /* run the filter on the result */
3227 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3228 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3229 GST_PTR_FORMAT, result, result, filter, filter);
3230 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3231 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3234 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3235 "using caps %p %" GST_PTR_FORMAT, result, result);
3236 result = gst_caps_ref (result);
3238 gst_query_set_caps_result (query, result);
3239 gst_caps_unref (result);
3245 /* Default latency implementation */
3250 GstClockTime min, max;
3254 query_latency_default_fold (const GValue * item, GValue * ret,
3257 GstPad *pad = g_value_get_object (item), *peer;
3258 LatencyFoldData *fold_data = user_data;
3260 gboolean res = FALSE;
3262 query = gst_query_new_latency ();
3264 peer = gst_pad_get_peer (pad);
3266 res = gst_pad_peer_query (pad, query);
3268 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3273 GstClockTime min, max;
3275 gst_query_parse_latency (query, &live, &min, &max);
3277 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3278 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3280 /* FIXME : Why do we only take values into account if it's live ? */
3281 if (live || fold_data->count == 0) {
3282 if (min > fold_data->min)
3283 fold_data->min = min;
3285 if (fold_data->max == GST_CLOCK_TIME_NONE)
3286 fold_data->max = max;
3287 else if (max < fold_data->max)
3288 fold_data->max = max;
3290 fold_data->live = live;
3292 fold_data->count += 1;
3294 GST_DEBUG_OBJECT (pad, "latency query failed");
3295 g_value_set_boolean (ret, FALSE);
3298 gst_query_unref (query);
3300 gst_object_unref (peer);
3306 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3309 GstIteratorResult res;
3310 GValue ret = G_VALUE_INIT;
3312 LatencyFoldData fold_data;
3314 it = gst_pad_iterate_internal_links (pad);
3316 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3320 g_value_init (&ret, G_TYPE_BOOLEAN);
3323 fold_data.count = 0;
3324 fold_data.live = FALSE;
3326 fold_data.max = GST_CLOCK_TIME_NONE;
3328 g_value_set_boolean (&ret, TRUE);
3329 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3331 case GST_ITERATOR_OK:
3332 g_assert_not_reached ();
3334 case GST_ITERATOR_DONE:
3336 case GST_ITERATOR_ERROR:
3337 g_value_set_boolean (&ret, FALSE);
3339 case GST_ITERATOR_RESYNC:
3340 gst_iterator_resync (it);
3343 g_assert_not_reached ();
3346 gst_iterator_free (it);
3348 query_ret = g_value_get_boolean (&ret);
3350 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3351 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3352 fold_data.min, fold_data.max);
3354 if (fold_data.min > fold_data.max) {
3355 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3358 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3360 GST_LOG_OBJECT (pad, "latency query failed");
3370 gboolean dispatched;
3374 query_forward_func (GstPad * pad, QueryData * data)
3376 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3377 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3379 data->result |= gst_pad_peer_query (pad, data->query);
3381 data->dispatched = TRUE;
3383 /* stop on first successful reply */
3384 return data->result;
3388 * gst_pad_query_default:
3389 * @pad: a #GstPad to call the default query handler on.
3390 * @parent: (allow-none): the parent of @pad or %NULL
3391 * @query: (transfer none): the #GstQuery to handle.
3393 * Invokes the default query handler for the given pad.
3394 * The query is sent to all pads internally linked to @pad. Note that
3395 * if there are many possible sink pads that are internally linked to
3396 * @pad, only one will be sent the query.
3397 * Multi-sinkpad elements should implement custom query handlers.
3399 * Returns: %TRUE if the query was performed successfully.
3402 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3404 gboolean forward, ret = FALSE;
3406 switch (GST_QUERY_TYPE (query)) {
3407 case GST_QUERY_SCHEDULING:
3408 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3410 case GST_QUERY_ALLOCATION:
3411 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3413 case GST_QUERY_ACCEPT_CAPS:
3414 ret = gst_pad_query_accept_caps_default (pad, query);
3417 case GST_QUERY_CAPS:
3418 ret = gst_pad_query_caps_default (pad, query);
3421 case GST_QUERY_LATENCY:
3422 ret = gst_pad_query_latency_default (pad, query);
3425 case GST_QUERY_POSITION:
3426 case GST_QUERY_SEEKING:
3427 case GST_QUERY_FORMATS:
3428 case GST_QUERY_JITTER:
3429 case GST_QUERY_RATE:
3430 case GST_QUERY_CONVERT:
3436 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3437 query, GST_QUERY_TYPE_NAME (query));
3443 data.dispatched = FALSE;
3444 data.result = FALSE;
3446 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3448 if (data.dispatched) {
3451 /* nothing dispatched, assume drained */
3452 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3462 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3464 GstPad *pad = data->pad;
3465 GstPadProbeInfo *info = data->info;
3466 GstPadProbeType type, flags;
3467 GstPadProbeCallback callback;
3468 GstPadProbeReturn ret;
3469 gpointer original_data;
3471 /* if we have called this callback, do nothing */
3472 if (PROBE_COOKIE (hook) == data->cookie) {
3473 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3474 "hook %lu, cookie %u already called", hook->hook_id,
3475 PROBE_COOKIE (hook));
3479 PROBE_COOKIE (hook) = data->cookie;
3481 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3483 original_data = info->data;
3485 /* one of the scheduling types */
3486 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3489 if (G_UNLIKELY (data->handled)) {
3490 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3491 "probe previously returned HANDLED, not calling again");
3493 } else if (G_UNLIKELY (data->dropped)) {
3494 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3495 "probe previously returned DROPPED, not calling again");
3499 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3500 /* one of the data types for non-idle probes */
3501 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3502 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3504 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3505 /* one of the data types for non-idle probes */
3506 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3507 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3510 /* Type must have PULL or PUSH probe types */
3511 g_assert_not_reached ();
3514 /* one of the blocking types must match */
3515 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3516 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3518 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3519 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3521 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3522 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3523 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3526 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3527 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3528 PROBE_COOKIE (hook), flags);
3530 data->marshalled = TRUE;
3532 callback = (GstPadProbeCallback) hook->func;
3533 if (callback == NULL)
3536 info->id = hook->hook_id;
3538 GST_OBJECT_UNLOCK (pad);
3540 ret = callback (pad, info, hook->data);
3542 GST_OBJECT_LOCK (pad);
3544 if (original_data != NULL && info->data == NULL) {
3545 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3546 info->type = GST_PAD_PROBE_TYPE_INVALID;
3547 data->dropped = TRUE;
3551 case GST_PAD_PROBE_REMOVE:
3552 /* remove the probe */
3553 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3554 cleanup_hook (pad, hook);
3556 case GST_PAD_PROBE_DROP:
3557 /* need to drop the data, make sure other probes don't get called
3559 GST_DEBUG_OBJECT (pad, "asked to drop item");
3560 info->type = GST_PAD_PROBE_TYPE_INVALID;
3561 data->dropped = TRUE;
3563 case GST_PAD_PROBE_HANDLED:
3564 GST_DEBUG_OBJECT (pad, "probe handled data");
3565 data->handled = TRUE;
3567 case GST_PAD_PROBE_PASS:
3568 /* inform the pad block to let things pass */
3569 GST_DEBUG_OBJECT (pad, "asked to pass item");
3572 case GST_PAD_PROBE_OK:
3573 GST_DEBUG_OBJECT (pad, "probe returned OK");
3576 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3583 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3584 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3585 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3590 /* a probe that does not take or return any data */
3591 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3593 if (G_UNLIKELY (pad->num_probes)) { \
3594 GstFlowReturn pval = defaultval; \
3595 /* pass NULL as the data item */ \
3596 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3597 info.ABI.abi.flow_ret = defaultval; \
3598 ret = do_probe_callbacks (pad, &info, defaultval); \
3599 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3604 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3606 if (G_UNLIKELY (pad->num_probes)) { \
3607 /* pass the data item */ \
3608 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3609 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3610 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3611 /* store the possibly updated data item */ \
3612 data = GST_PAD_PROBE_INFO_DATA (&info); \
3613 /* if something went wrong, exit */ \
3614 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3615 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3616 ret = info.ABI.abi.flow_ret; \
3617 goto handle_label; \
3624 #define PROBE_PUSH(pad,mask,data,label) \
3625 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3626 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3627 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3628 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3629 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3631 static GstFlowReturn
3632 do_pad_idle_probe_wait (GstPad * pad)
3634 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3635 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3636 "waiting idle probe to be removed");
3637 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3638 GST_PAD_BLOCK_WAIT (pad);
3639 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3640 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3642 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3643 return GST_FLOW_FLUSHING;
3648 #define PROBE_TYPE_IS_SERIALIZED(i) \
3651 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3652 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3653 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3655 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3656 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3658 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3659 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3663 static GstFlowReturn
3664 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3665 GstFlowReturn defaultval)
3674 data.handled = FALSE;
3675 data.marshalled = FALSE;
3676 data.dropped = FALSE;
3677 data.cookie = ++pad->priv->probe_cookie;
3680 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3682 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3683 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3688 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3689 "do probes cookie %u", data.cookie);
3690 cookie = pad->priv->probe_list_cookie;
3692 g_hook_list_marshal (&pad->probes, TRUE,
3693 (GHookMarshaller) probe_hook_marshal, &data);
3695 /* if the list changed, call the new callbacks (they will not have their
3696 * cookie set to data.cookie */
3697 if (cookie != pad->priv->probe_list_cookie) {
3698 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3699 "probe list changed, restarting");
3703 /* the first item that dropped will stop the hooks and then we drop here */
3707 /* If one handler took care of it, let the the item pass */
3712 /* if no handler matched and we are blocking, let the item pass */
3713 if (!data.marshalled && is_block)
3716 /* At this point, all handlers returned either OK or PASS. If one handler
3717 * returned PASS, let the item pass */
3722 while (GST_PAD_IS_BLOCKED (pad)) {
3723 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3724 "we are blocked %d times", pad->num_blocked);
3726 /* we might have released the lock */
3727 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3730 /* now we block the streaming thread. It can be unlocked when we
3731 * deactivate the pad (which will also set the FLUSHING flag) or
3732 * when the pad is unblocked. A flushing event will also unblock
3733 * the pad after setting the FLUSHING flag. */
3734 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3735 "Waiting to be unblocked or set flushing");
3736 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3737 GST_PAD_BLOCK_WAIT (pad);
3738 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3739 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3741 /* if the list changed, call the new callbacks (they will not have their
3742 * cookie set to data.cookie */
3743 if (cookie != pad->priv->probe_list_cookie) {
3744 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3745 "probe list changed, restarting");
3749 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3759 GST_DEBUG_OBJECT (pad, "pad is flushing");
3760 return GST_FLOW_FLUSHING;
3764 GST_DEBUG_OBJECT (pad, "data is dropped");
3765 return GST_FLOW_CUSTOM_SUCCESS;
3769 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3770 GST_DEBUG_OBJECT (pad, "data is passed");
3775 GST_DEBUG_OBJECT (pad, "data was handled");
3776 return GST_FLOW_CUSTOM_SUCCESS_1;
3783 * gst_pad_get_offset:
3786 * Get the offset applied to the running time of @pad. @pad has to be a source
3789 * Returns: the offset.
3792 gst_pad_get_offset (GstPad * pad)
3796 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3798 GST_OBJECT_LOCK (pad);
3799 result = pad->offset;
3800 GST_OBJECT_UNLOCK (pad);
3806 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3808 ev->received = FALSE;
3813 * gst_pad_set_offset:
3815 * @offset: the offset
3817 * Set the offset that will be applied to the running time of @pad.
3820 gst_pad_set_offset (GstPad * pad, gint64 offset)
3822 g_return_if_fail (GST_IS_PAD (pad));
3824 GST_OBJECT_LOCK (pad);
3825 /* if nothing changed, do nothing */
3826 if (pad->offset == offset)
3829 pad->offset = offset;
3830 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3831 GST_STIME_ARGS (offset));
3833 /* resend all sticky events with updated offset on next buffer push */
3834 events_foreach (pad, mark_event_not_received, NULL);
3835 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3838 GST_OBJECT_UNLOCK (pad);
3845 /* If TRUE and ret is not OK this means
3846 * that pushing the EOS event failed
3850 /* If called for an event this is
3851 * the event that would be pushed
3852 * next. Don't forward sticky events
3853 * that would come after that */
3857 /* should be called with pad LOCK */
3859 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3861 PushStickyData *data = user_data;
3862 GstEvent *event = ev->event;
3865 GST_DEBUG_OBJECT (pad, "event %s was already received",
3866 GST_EVENT_TYPE_NAME (event));
3870 /* If we're called because of an sticky event, only forward
3871 * events that would come before this new event and the
3873 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3874 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3875 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3876 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3878 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3879 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3880 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3881 data->ret = GST_FLOW_OK;
3884 switch (data->ret) {
3886 ev->received = TRUE;
3887 GST_DEBUG_OBJECT (pad, "event %s marked received",
3888 GST_EVENT_TYPE_NAME (event));
3890 case GST_FLOW_CUSTOM_SUCCESS:
3891 /* we can't assume the event is received when it was dropped */
3892 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3893 GST_EVENT_TYPE_NAME (event));
3894 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3895 data->ret = GST_FLOW_OK;
3897 case GST_FLOW_CUSTOM_SUCCESS_1:
3898 /* event was ignored and should be sent later */
3899 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3900 GST_EVENT_TYPE_NAME (event));
3901 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3902 data->ret = GST_FLOW_OK;
3904 case GST_FLOW_NOT_LINKED:
3905 /* not linked is not a problem, we are sticky so the event will be
3906 * rescheduled to be sent later on re-link, but only for non-EOS events */
3907 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3908 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3909 data->ret = GST_FLOW_OK;
3910 ev->received = TRUE;
3914 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3915 gst_flow_get_name (data->ret));
3916 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3920 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3921 data->was_eos = TRUE;
3923 return data->ret == GST_FLOW_OK;
3926 /* check sticky events and push them when needed. should be called
3928 static inline GstFlowReturn
3929 check_sticky (GstPad * pad, GstEvent * event)
3931 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3933 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3934 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3936 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3937 events_foreach (pad, push_sticky, &data);
3939 /* If there's an EOS event we must push it downstream
3940 * even if sending a previous sticky event failed.
3941 * Otherwise the pipeline might wait forever for EOS.
3943 * Only do this if pushing another event than the EOS
3946 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3947 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3949 if (ev && !ev->received) {
3950 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3951 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3952 /* the event could have been dropped. Because this can only
3953 * happen if the user asked for it, it's not an error */
3954 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3955 data.ret = GST_FLOW_OK;
3965 * @pad: a #GstPad to invoke the default query on.
3966 * @query: (transfer none): the #GstQuery to perform.
3968 * Dispatches a query to a pad. The query should have been allocated by the
3969 * caller via one of the type-specific allocation functions. The element that
3970 * the pad belongs to is responsible for filling the query with an appropriate
3971 * response, which should then be parsed with a type-specific query parsing
3974 * Again, the caller is responsible for both the allocation and deallocation of
3975 * the query structure.
3977 * Please also note that some queries might need a running pipeline to work.
3979 * Returns: %TRUE if the query could be performed.
3982 gst_pad_query (GstPad * pad, GstQuery * query)
3985 gboolean res, serialized;
3986 GstPadQueryFunction func;
3987 GstPadProbeType type;
3990 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3991 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3993 if (GST_PAD_IS_SRC (pad)) {
3994 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3995 goto wrong_direction;
3996 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3997 } else if (GST_PAD_IS_SINK (pad)) {
3998 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3999 goto wrong_direction;
4000 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4002 goto unknown_direction;
4004 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4005 GST_QUERY_TYPE_NAME (query));
4006 GST_TRACER_PAD_QUERY_PRE (pad, query);
4008 serialized = GST_QUERY_IS_SERIALIZED (query);
4009 if (G_UNLIKELY (serialized))
4010 GST_PAD_STREAM_LOCK (pad);
4012 GST_OBJECT_LOCK (pad);
4013 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4014 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4015 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4017 ACQUIRE_PARENT (pad, parent, no_parent);
4018 GST_OBJECT_UNLOCK (pad);
4020 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4023 res = func (pad, parent, query);
4025 RELEASE_PARENT (parent);
4027 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4028 GST_QUERY_TYPE_NAME (query), res);
4029 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4034 GST_OBJECT_LOCK (pad);
4035 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4036 GST_OBJECT_UNLOCK (pad);
4038 if (G_UNLIKELY (serialized))
4039 GST_PAD_STREAM_UNLOCK (pad);
4046 g_warning ("pad %s:%s query %s in wrong direction",
4047 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4052 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4057 GST_DEBUG_OBJECT (pad, "had no parent");
4058 GST_OBJECT_UNLOCK (pad);
4059 if (G_UNLIKELY (serialized))
4060 GST_PAD_STREAM_UNLOCK (pad);
4065 GST_DEBUG_OBJECT (pad, "had no query function");
4066 RELEASE_PARENT (parent);
4067 if (G_UNLIKELY (serialized))
4068 GST_PAD_STREAM_UNLOCK (pad);
4073 GST_DEBUG_OBJECT (pad, "query failed");
4074 if (G_UNLIKELY (serialized))
4075 GST_PAD_STREAM_UNLOCK (pad);
4080 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4081 GST_OBJECT_UNLOCK (pad);
4082 if (G_UNLIKELY (serialized))
4083 GST_PAD_STREAM_UNLOCK (pad);
4085 /* if a probe dropped without handling, we don't sent it further but assume
4086 * that the probe did not answer the query and return FALSE */
4087 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4097 * gst_pad_peer_query:
4098 * @pad: a #GstPad to invoke the peer query on.
4099 * @query: (transfer none): the #GstQuery to perform.
4101 * Performs gst_pad_query() on the peer of @pad.
4103 * The caller is responsible for both the allocation and deallocation of
4104 * the query structure.
4106 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4107 * if @pad has no peer.
4110 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4113 GstPadProbeType type;
4114 gboolean res, serialized;
4117 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4118 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4120 if (GST_PAD_IS_SRC (pad)) {
4121 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4122 goto wrong_direction;
4123 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4124 } else if (GST_PAD_IS_SINK (pad)) {
4125 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4126 goto wrong_direction;
4127 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4129 goto unknown_direction;
4131 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4132 GST_QUERY_TYPE_NAME (query));
4134 serialized = GST_QUERY_IS_SERIALIZED (query);
4136 GST_OBJECT_LOCK (pad);
4137 if (GST_PAD_IS_SRC (pad) && serialized) {
4138 /* all serialized queries on the srcpad trigger push of
4140 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4144 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4145 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4146 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4148 peerpad = GST_PAD_PEER (pad);
4149 if (G_UNLIKELY (peerpad == NULL))
4152 gst_object_ref (peerpad);
4153 GST_OBJECT_UNLOCK (pad);
4155 res = gst_pad_query (peerpad, query);
4157 gst_object_unref (peerpad);
4162 GST_OBJECT_LOCK (pad);
4163 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4164 GST_OBJECT_UNLOCK (pad);
4171 g_warning ("pad %s:%s query %s in wrong direction",
4172 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4177 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4182 GST_WARNING_OBJECT (pad, "could not send sticky events");
4183 GST_OBJECT_UNLOCK (pad);
4188 GST_INFO_OBJECT (pad, "pad has no peer");
4189 GST_OBJECT_UNLOCK (pad);
4194 GST_DEBUG_OBJECT (pad, "query failed");
4199 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4200 GST_OBJECT_UNLOCK (pad);
4202 /* if a probe dropped without handling, we don't sent it further but
4203 * assume that the probe did not answer the query and return FALSE */
4204 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4213 /**********************************************************************
4214 * Data passing functions
4217 /* this is the chain function that does not perform the additional argument
4218 * checking for that little extra speed.
4220 static inline GstFlowReturn
4221 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4225 gboolean handled = FALSE;
4227 GST_PAD_STREAM_LOCK (pad);
4229 GST_OBJECT_LOCK (pad);
4230 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4233 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4236 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4239 #ifdef GST_ENABLE_EXTRA_CHECKS
4240 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4241 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4243 ":%s:<%s:%s> Got data flow before stream-start event",
4244 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4246 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4248 ":%s:<%s:%s> Got data flow before segment event",
4249 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4251 pad->priv->last_cookie = pad->priv->events_cookie;
4255 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4258 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4260 ACQUIRE_PARENT (pad, parent, no_parent);
4261 GST_OBJECT_UNLOCK (pad);
4263 /* NOTE: we read the chainfunc unlocked.
4264 * we cannot hold the lock for the pad so we might send
4265 * the data to the wrong function. This is not really a
4266 * problem since functions are assigned at creation time
4267 * and don't change that often... */
4268 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4269 GstPadChainFunction chainfunc;
4271 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4274 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4275 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4276 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4278 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4280 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4281 "called chainfunction &%s with buffer %p, returned %s",
4282 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4284 GstPadChainListFunction chainlistfunc;
4286 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4289 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4290 "calling chainlistfunction &%s",
4291 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4293 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4295 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4296 "called chainlistfunction &%s, returned %s",
4297 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4300 RELEASE_PARENT (parent);
4302 GST_PAD_STREAM_UNLOCK (pad);
4309 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4310 "chaining, but pad was flushing");
4311 GST_OBJECT_UNLOCK (pad);
4312 GST_PAD_STREAM_UNLOCK (pad);
4313 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4314 return GST_FLOW_FLUSHING;
4318 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4319 GST_OBJECT_UNLOCK (pad);
4320 GST_PAD_STREAM_UNLOCK (pad);
4321 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4322 return GST_FLOW_EOS;
4326 g_critical ("chain on pad %s:%s but it was not in push mode",
4327 GST_DEBUG_PAD_NAME (pad));
4328 GST_OBJECT_UNLOCK (pad);
4329 GST_PAD_STREAM_UNLOCK (pad);
4330 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4331 return GST_FLOW_ERROR;
4338 GST_OBJECT_UNLOCK (pad);
4339 GST_PAD_STREAM_UNLOCK (pad);
4340 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4342 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4345 case GST_FLOW_CUSTOM_SUCCESS:
4346 case GST_FLOW_CUSTOM_SUCCESS_1:
4347 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4351 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4358 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4359 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4360 GST_OBJECT_UNLOCK (pad);
4361 GST_PAD_STREAM_UNLOCK (pad);
4362 return GST_FLOW_FLUSHING;
4366 RELEASE_PARENT (parent);
4367 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4368 g_critical ("chain on pad %s:%s but it has no chainfunction",
4369 GST_DEBUG_PAD_NAME (pad));
4370 GST_PAD_STREAM_UNLOCK (pad);
4371 return GST_FLOW_NOT_SUPPORTED;
4377 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4378 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4381 * Chain a buffer to @pad.
4383 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4385 * If the buffer type is not acceptable for @pad (as negotiated with a
4386 * preceding GST_EVENT_CAPS event), this function returns
4387 * #GST_FLOW_NOT_NEGOTIATED.
4389 * The function proceeds calling the chain function installed on @pad (see
4390 * gst_pad_set_chain_function()) and the return value of that function is
4391 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4394 * In all cases, success or failure, the caller loses its reference to @buffer
4395 * after calling this function.
4397 * Returns: a #GstFlowReturn from the pad.
4402 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4404 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4405 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4406 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4408 return gst_pad_chain_data_unchecked (pad,
4409 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4412 static GstFlowReturn
4413 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4414 GstBufferList * list)
4420 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4422 len = gst_buffer_list_length (list);
4425 for (i = 0; i < len; i++) {
4426 buffer = gst_buffer_list_get (list, i);
4428 gst_pad_chain_data_unchecked (pad,
4429 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4430 gst_buffer_ref (buffer));
4431 if (ret != GST_FLOW_OK)
4434 gst_buffer_list_unref (list);
4440 * gst_pad_chain_list:
4441 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4442 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4445 * Chain a bufferlist to @pad.
4447 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4449 * If @pad was not negotiated properly with a CAPS event, this function
4450 * returns #GST_FLOW_NOT_NEGOTIATED.
4452 * The function proceeds calling the chainlist function installed on @pad (see
4453 * gst_pad_set_chain_list_function()) and the return value of that function is
4454 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4455 * chainlist function.
4457 * In all cases, success or failure, the caller loses its reference to @list
4458 * after calling this function.
4462 * Returns: a #GstFlowReturn from the pad.
4465 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4467 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4468 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4469 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4471 return gst_pad_chain_data_unchecked (pad,
4472 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4475 static GstFlowReturn
4476 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4480 gboolean handled = FALSE;
4482 GST_OBJECT_LOCK (pad);
4483 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4486 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4489 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4492 #ifdef GST_ENABLE_EXTRA_CHECKS
4493 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4494 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4496 ":%s:<%s:%s> Got data flow before stream-start event",
4497 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4499 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4501 ":%s:<%s:%s> Got data flow before segment event",
4502 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4504 pad->priv->last_cookie = pad->priv->events_cookie;
4508 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4511 /* do block probes */
4512 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4515 /* recheck sticky events because the probe might have cause a relink */
4516 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4519 /* do post-blocking probes */
4520 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4522 /* recheck sticky events because the probe might have cause a relink */
4523 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4526 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4529 /* take ref to peer pad before releasing the lock */
4530 gst_object_ref (peer);
4532 GST_OBJECT_UNLOCK (pad);
4534 ret = gst_pad_chain_data_unchecked (peer, type, data);
4537 gst_object_unref (peer);
4539 GST_OBJECT_LOCK (pad);
4540 pad->ABI.abi.last_flowret = ret;
4542 if (pad->priv->using == 0) {
4543 /* pad is not active anymore, trigger idle callbacks */
4544 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4545 probe_stopped, ret);
4547 GST_OBJECT_UNLOCK (pad);
4551 /* ERROR recovery here */
4555 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4556 "pushing, but pad was flushing");
4557 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4558 GST_OBJECT_UNLOCK (pad);
4559 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4560 return GST_FLOW_FLUSHING;
4564 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4565 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4566 GST_OBJECT_UNLOCK (pad);
4567 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4568 return GST_FLOW_EOS;
4572 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4573 GST_DEBUG_PAD_NAME (pad));
4574 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4575 GST_OBJECT_UNLOCK (pad);
4576 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4577 return GST_FLOW_ERROR;
4581 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4582 "error pushing events, return %s", gst_flow_get_name (ret));
4583 pad->ABI.abi.last_flowret = ret;
4584 GST_OBJECT_UNLOCK (pad);
4585 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4593 GST_OBJECT_UNLOCK (pad);
4594 if (data != NULL && !handled)
4595 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4598 case GST_FLOW_CUSTOM_SUCCESS:
4599 case GST_FLOW_CUSTOM_SUCCESS_1:
4600 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4604 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4607 pad->ABI.abi.last_flowret = ret;
4612 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4613 "pushing, but it was not linked");
4614 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4615 GST_OBJECT_UNLOCK (pad);
4616 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4617 return GST_FLOW_NOT_LINKED;
4623 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4624 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4627 * Pushes a buffer to the peer of @pad.
4629 * This function will call installed block probes before triggering any
4630 * installed data probes.
4632 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4633 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4636 * In all cases, success or failure, the caller loses its reference to @buffer
4637 * after calling this function.
4639 * Returns: a #GstFlowReturn from the peer pad.
4644 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4648 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4649 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4650 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4652 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4653 res = gst_pad_push_data (pad,
4654 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4655 GST_TRACER_PAD_PUSH_POST (pad, res);
4660 * gst_pad_push_list:
4661 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4662 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4665 * Pushes a buffer list to the peer of @pad.
4667 * This function will call installed block probes before triggering any
4668 * installed data probes.
4670 * The function proceeds calling the chain function on the peer pad and returns
4671 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4672 * be returned. If the peer pad does not have any installed chainlist function
4673 * every group buffer of the list will be merged into a normal #GstBuffer and
4674 * chained via gst_pad_chain().
4676 * In all cases, success or failure, the caller loses its reference to @list
4677 * after calling this function.
4679 * Returns: a #GstFlowReturn from the peer pad.
4684 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4688 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4689 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4690 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4692 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4693 res = gst_pad_push_data (pad,
4694 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4695 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4699 static GstFlowReturn
4700 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4701 GstBuffer ** buffer)
4704 GstPadGetRangeFunction getrangefunc;
4708 GST_PAD_STREAM_LOCK (pad);
4710 GST_OBJECT_LOCK (pad);
4711 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4714 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4717 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4722 /* when one of the probes returns DROPPED, probe_stopped will be called
4723 * and we skip calling the getrange function, res_buf should then contain a
4724 * valid result buffer */
4725 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4726 res_buf, offset, size, probe_stopped);
4728 /* recheck sticky events because the probe might have cause a relink */
4729 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4732 ACQUIRE_PARENT (pad, parent, no_parent);
4733 GST_OBJECT_UNLOCK (pad);
4735 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4738 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4739 "calling getrangefunc %s, offset %"
4740 G_GUINT64_FORMAT ", size %u",
4741 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4743 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4745 RELEASE_PARENT (parent);
4747 GST_OBJECT_LOCK (pad);
4748 if (G_UNLIKELY (ret != GST_FLOW_OK))
4749 goto get_range_failed;
4751 /* can only fire the signal if we have a valid buffer */
4753 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4754 res_buf, offset, size, probe_stopped_unref);
4755 pad->ABI.abi.last_flowret = ret;
4756 GST_OBJECT_UNLOCK (pad);
4758 GST_PAD_STREAM_UNLOCK (pad);
4767 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4768 "getrange, but pad was flushing");
4769 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4770 GST_OBJECT_UNLOCK (pad);
4771 GST_PAD_STREAM_UNLOCK (pad);
4772 return GST_FLOW_FLUSHING;
4776 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4777 GST_DEBUG_PAD_NAME (pad));
4778 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4779 GST_OBJECT_UNLOCK (pad);
4780 GST_PAD_STREAM_UNLOCK (pad);
4781 return GST_FLOW_ERROR;
4785 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4786 pad->ABI.abi.last_flowret = ret;
4787 GST_OBJECT_UNLOCK (pad);
4788 GST_PAD_STREAM_UNLOCK (pad);
4793 GST_DEBUG_OBJECT (pad, "no parent");
4794 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4795 GST_OBJECT_UNLOCK (pad);
4796 GST_PAD_STREAM_UNLOCK (pad);
4797 return GST_FLOW_FLUSHING;
4801 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4802 GST_DEBUG_PAD_NAME (pad));
4803 RELEASE_PARENT (parent);
4804 GST_PAD_STREAM_UNLOCK (pad);
4805 return GST_FLOW_NOT_SUPPORTED;
4809 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4810 "probe returned %s", gst_flow_get_name (ret));
4811 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4813 /* the probe filled the buffer and asks us to not call the getrange
4814 * anymore, we continue with the post probes then. */
4815 GST_DEBUG_OBJECT (pad, "handled buffer");
4819 /* no buffer, we are EOS */
4820 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4824 pad->ABI.abi.last_flowret = ret;
4825 GST_OBJECT_UNLOCK (pad);
4826 GST_PAD_STREAM_UNLOCK (pad);
4830 probe_stopped_unref:
4832 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4833 "probe returned %s", gst_flow_get_name (ret));
4834 /* if we drop here, it signals EOS */
4835 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4837 pad->ABI.abi.last_flowret = ret;
4838 GST_OBJECT_UNLOCK (pad);
4839 GST_PAD_STREAM_UNLOCK (pad);
4840 if (*buffer == NULL)
4841 gst_buffer_unref (res_buf);
4846 pad->ABI.abi.last_flowret = ret;
4847 GST_OBJECT_UNLOCK (pad);
4848 GST_PAD_STREAM_UNLOCK (pad);
4849 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4850 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4851 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4857 * gst_pad_get_range:
4858 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4859 * @offset: The start offset of the buffer
4860 * @size: The length of the buffer
4861 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4862 * returns #GST_FLOW_ERROR if %NULL.
4864 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4865 * immediately and @buffer is %NULL.
4867 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4868 * description of a getrange function. If @pad has no getrange function
4869 * installed (see gst_pad_set_getrange_function()) this function returns
4870 * #GST_FLOW_NOT_SUPPORTED.
4872 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4873 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4874 * must be freed with gst_buffer_unref() after usage.
4876 * When @buffer points to a variable that points to a valid #GstBuffer, the
4877 * buffer will be filled with the result data when this function returns
4878 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4879 * @size bytes will be filled in the result buffer and its size will be updated
4882 * Note that less than @size bytes can be returned in @buffer when, for example,
4883 * an EOS condition is near or when @buffer is not large enough to hold @size
4884 * bytes. The caller should check the result buffer size to get the result size.
4886 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4887 * will be unchanged.
4889 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4891 * Returns: a #GstFlowReturn from the pad.
4896 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4897 GstBuffer ** buffer)
4899 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4900 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4901 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4902 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4903 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4905 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4909 * gst_pad_pull_range:
4910 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4911 * @offset: The start offset of the buffer
4912 * @size: The length of the buffer
4913 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4914 * GST_FLOW_ERROR if %NULL.
4916 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4918 * This function will first trigger the pad block signal if it was
4921 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4922 * function returns the result of gst_pad_get_range() on the peer pad.
4923 * See gst_pad_get_range() for a list of return values and for the
4924 * semantics of the arguments of this function.
4926 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4927 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4928 * must be freed with gst_buffer_unref() after usage. When this function
4929 * returns any other result value, @buffer will still point to %NULL.
4931 * When @buffer points to a variable that points to a valid #GstBuffer, the
4932 * buffer will be filled with the result data when this function returns
4933 * #GST_FLOW_OK. When this function returns any other result value,
4934 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4935 * @size bytes will be filled in the result buffer and its size will be updated
4938 * Note that less than @size bytes can be returned in @buffer when, for example,
4939 * an EOS condition is near or when @buffer is not large enough to hold @size
4940 * bytes. The caller should check the result buffer size to get the result size.
4942 * Returns: a #GstFlowReturn from the peer pad.
4947 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4948 GstBuffer ** buffer)
4954 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4955 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4956 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4957 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4958 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4960 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4962 GST_OBJECT_LOCK (pad);
4963 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4966 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4971 /* when one of the probes returns DROPPED, probe_stopped will be
4972 * called and we skip calling the peer getrange function. *buffer should then
4973 * contain a valid buffer */
4974 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4975 res_buf, offset, size, probe_stopped);
4977 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4980 gst_object_ref (peer);
4982 GST_OBJECT_UNLOCK (pad);
4984 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4986 gst_object_unref (peer);
4988 GST_OBJECT_LOCK (pad);
4990 pad->ABI.abi.last_flowret = ret;
4991 if (pad->priv->using == 0) {
4992 /* pad is not active anymore, trigger idle callbacks */
4993 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4994 probe_stopped_unref, ret);
4997 if (G_UNLIKELY (ret != GST_FLOW_OK))
4998 goto pull_range_failed;
5001 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5002 res_buf, offset, size, probe_stopped_unref);
5004 GST_OBJECT_UNLOCK (pad);
5008 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5011 /* ERROR recovery here */
5014 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5015 "pullrange, but pad was flushing");
5016 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5017 GST_OBJECT_UNLOCK (pad);
5018 ret = GST_FLOW_FLUSHING;
5023 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5024 GST_DEBUG_PAD_NAME (pad));
5025 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5026 GST_OBJECT_UNLOCK (pad);
5027 ret = GST_FLOW_ERROR;
5032 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5033 gst_flow_get_name (ret));
5034 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5036 /* the probe filled the buffer and asks us to not forward to the peer
5037 * anymore, we continue with the post probes then */
5038 GST_DEBUG_OBJECT (pad, "handled buffer");
5042 /* no buffer, we are EOS then */
5043 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5047 pad->ABI.abi.last_flowret = ret;
5048 GST_OBJECT_UNLOCK (pad);
5053 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5054 "pulling range, but it was not linked");
5055 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5056 GST_OBJECT_UNLOCK (pad);
5057 ret = GST_FLOW_NOT_LINKED;
5062 pad->ABI.abi.last_flowret = ret;
5063 GST_OBJECT_UNLOCK (pad);
5064 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5065 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5066 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5069 probe_stopped_unref:
5071 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5072 "post probe returned %s", gst_flow_get_name (ret));
5074 /* if we drop here, it signals EOS */
5075 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5078 pad->ABI.abi.last_flowret = ret;
5079 GST_OBJECT_UNLOCK (pad);
5081 if (*buffer == NULL)
5082 gst_buffer_unref (res_buf);
5086 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5090 /* must be called with pad object lock */
5091 static GstFlowReturn
5092 store_sticky_event (GstPad * pad, GstEvent * event)
5097 gboolean res = FALSE;
5098 const gchar *name = NULL;
5099 gboolean insert = TRUE;
5101 type = GST_EVENT_TYPE (event);
5103 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5104 * otherwise they can be dropped and nothing would ever resend them.
5105 * Only do that for activated pads though, everything else is a bug!
5107 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5108 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5109 || type == GST_EVENT_EOS))))
5112 /* Unset the EOS flag when received STREAM_START event, so pad can
5113 * store sticky event and then push it later */
5114 if (type == GST_EVENT_STREAM_START) {
5115 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5116 remove_event_by_type (pad, GST_EVENT_EOS);
5117 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5118 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5121 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5124 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5125 name = gst_structure_get_name (gst_event_get_structure (event));
5127 events = pad->priv->events;
5130 for (i = 0; i < len; i++) {
5131 PadEvent *ev = &g_array_index (events, PadEvent, i);
5133 if (ev->event == NULL)
5136 if (type == GST_EVENT_TYPE (ev->event)) {
5137 /* matching types, check matching name if needed */
5138 if (name && !gst_event_has_name (ev->event, name))
5142 if ((res = gst_event_replace (&ev->event, event)))
5143 ev->received = FALSE;
5149 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5150 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5151 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5152 * storing the sticky ordered we can check that this is respected. */
5153 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5154 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5156 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5157 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5158 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5159 gst_event_type_get_name (type));
5165 ev.event = gst_event_ref (event);
5166 ev.received = FALSE;
5167 g_array_insert_val (events, i, ev);
5172 pad->priv->events_cookie++;
5173 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5175 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5177 switch (GST_EVENT_TYPE (event)) {
5178 case GST_EVENT_CAPS:
5179 GST_OBJECT_UNLOCK (pad);
5181 GST_DEBUG_OBJECT (pad, "notify caps");
5182 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5184 GST_OBJECT_LOCK (pad);
5190 if (type == GST_EVENT_EOS) {
5191 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5192 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5195 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5200 GST_DEBUG_OBJECT (pad, "pad is flushing");
5201 return GST_FLOW_FLUSHING;
5205 GST_DEBUG_OBJECT (pad, "pad is EOS");
5206 return GST_FLOW_EOS;
5211 * gst_pad_store_sticky_event:
5213 * @event: (transfer none): a #GstEvent
5215 * Store the sticky @event on @pad
5217 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5218 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5223 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5227 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5228 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5230 GST_OBJECT_LOCK (pad);
5231 ret = store_sticky_event (pad, event);
5232 GST_OBJECT_UNLOCK (pad);
5238 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5240 PushStickyData *data = user_data;
5242 /* Forward all sticky events before our current one that are pending */
5243 if (ev->event != data->event
5244 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5245 return push_sticky (pad, ev, data);
5250 /* should be called with pad LOCK */
5251 static GstFlowReturn
5252 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5253 GstPadProbeType type)
5257 GstEventType event_type;
5259 /* pass the adjusted event on. We need to do this even if
5260 * there is no peer pad because of the probes. */
5261 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5263 /* Two checks to be made:
5264 * . (un)set the FLUSHING flag for flushing events,
5265 * . handle pad blocking */
5266 event_type = GST_EVENT_TYPE (event);
5267 switch (event_type) {
5268 case GST_EVENT_FLUSH_START:
5269 GST_PAD_SET_FLUSHING (pad);
5271 GST_PAD_BLOCK_BROADCAST (pad);
5272 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5274 case GST_EVENT_FLUSH_STOP:
5275 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5278 GST_PAD_UNSET_FLUSHING (pad);
5280 /* Remove sticky EOS events */
5281 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5282 remove_event_by_type (pad, GST_EVENT_EOS);
5283 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5284 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5285 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5286 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5288 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5292 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5295 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5296 * checked already or this is called as part of pushing sticky events,
5297 * in which case we still want to forward the EOS event downstream.
5300 switch (GST_EVENT_TYPE (event)) {
5301 case GST_EVENT_RECONFIGURE:
5302 if (GST_PAD_IS_SINK (pad))
5303 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5308 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5309 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5310 /* recheck sticky events because the probe might have cause a relink */
5311 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5312 && (GST_EVENT_IS_SERIALIZED (event)
5313 || GST_EVENT_IS_STICKY (event))) {
5314 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5315 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5317 /* Push all sticky events before our current one
5318 * that have changed */
5319 events_foreach (pad, sticky_changed, &data);
5325 /* send probes after modifying the events above */
5326 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5328 /* recheck sticky events because the probe might have cause a relink */
5329 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5330 && (GST_EVENT_IS_SERIALIZED (event)
5331 || GST_EVENT_IS_STICKY (event))) {
5332 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5333 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5335 /* Push all sticky events before our current one
5336 * that have changed */
5337 events_foreach (pad, sticky_changed, &data);
5340 /* now check the peer pad */
5341 peerpad = GST_PAD_PEER (pad);
5342 if (peerpad == NULL)
5345 gst_object_ref (peerpad);
5347 GST_OBJECT_UNLOCK (pad);
5349 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5350 event, gst_event_type_get_name (event_type), peerpad);
5352 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5354 /* Note: we gave away ownership of the event at this point but we can still
5355 * print the old pointer */
5356 GST_LOG_OBJECT (pad,
5357 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5358 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5360 gst_object_unref (peerpad);
5362 GST_OBJECT_LOCK (pad);
5364 if (pad->priv->using == 0) {
5365 /* pad is not active anymore, trigger idle callbacks */
5366 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5367 idle_probe_stopped, ret);
5371 /* ERROR handling */
5374 GST_DEBUG_OBJECT (pad, "We're flushing");
5375 gst_event_unref (event);
5376 return GST_FLOW_FLUSHING;
5380 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5381 gst_event_unref (event);
5382 return GST_FLOW_FLUSHING;
5386 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5387 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5388 gst_event_unref (event);
5391 case GST_FLOW_CUSTOM_SUCCESS_1:
5392 GST_DEBUG_OBJECT (pad, "handled event");
5394 case GST_FLOW_CUSTOM_SUCCESS:
5395 GST_DEBUG_OBJECT (pad, "dropped event");
5398 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5405 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5406 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5407 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5408 gst_event_unref (event);
5410 /* unlinked pads should not influence latency configuration */
5411 if (event_type == GST_EVENT_LATENCY)
5414 return GST_FLOW_NOT_LINKED;
5418 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5424 * gst_pad_push_event:
5425 * @pad: a #GstPad to push the event to.
5426 * @event: (transfer full): the #GstEvent to send to the pad.
5428 * Sends the event to the peer of the given pad. This function is
5429 * mainly used by elements to send events to their peer
5432 * This function takes ownership of the provided event so you should
5433 * gst_event_ref() it if you want to reuse the event after this call.
5435 * Returns: %TRUE if the event was handled.
5440 gst_pad_push_event (GstPad * pad, GstEvent * event)
5442 gboolean res = FALSE;
5443 GstPadProbeType type;
5444 gboolean sticky, serialized;
5446 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5447 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5449 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5451 if (GST_PAD_IS_SRC (pad)) {
5452 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5453 goto wrong_direction;
5454 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5455 } else if (GST_PAD_IS_SINK (pad)) {
5456 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5457 goto wrong_direction;
5458 /* events pushed on sinkpad never are sticky */
5459 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5461 goto unknown_direction;
5463 GST_OBJECT_LOCK (pad);
5464 sticky = GST_EVENT_IS_STICKY (event);
5465 serialized = GST_EVENT_IS_SERIALIZED (event);
5468 /* srcpad sticky events are stored immediately, the received flag is set
5469 * to FALSE and will be set to TRUE when we can successfully push the
5470 * event to the peer pad */
5471 switch (store_sticky_event (pad, event)) {
5472 case GST_FLOW_FLUSHING:
5480 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5481 /* all serialized or sticky events on the srcpad trigger push of
5483 res = (check_sticky (pad, event) == GST_FLOW_OK);
5488 /* other events are pushed right away */
5489 ret = gst_pad_push_event_unchecked (pad, event, type);
5490 /* dropped events by a probe are not an error */
5491 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5492 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5494 /* Errors in sticky event pushing are no problem and ignored here
5495 * as they will cause more meaningful errors during data flow.
5496 * For EOS events, that are not followed by data flow, we still
5497 * return FALSE here though.
5499 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5501 gst_event_unref (event);
5503 GST_OBJECT_UNLOCK (pad);
5505 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5508 /* ERROR handling */
5511 g_warning ("pad %s:%s pushing %s event in wrong direction",
5512 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5513 gst_event_unref (event);
5518 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5519 gst_event_unref (event);
5524 GST_DEBUG_OBJECT (pad, "We're flushing");
5525 GST_OBJECT_UNLOCK (pad);
5526 gst_event_unref (event);
5531 GST_DEBUG_OBJECT (pad, "We're EOS");
5532 GST_OBJECT_UNLOCK (pad);
5533 gst_event_unref (event);
5537 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5541 /* Check if we can call the event function with the given event */
5542 static GstFlowReturn
5543 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5547 switch (GST_EVENT_TYPE (event)) {
5548 case GST_EVENT_CAPS:
5550 /* backwards compatibility mode for caps */
5551 gst_event_parse_caps (event, &caps);
5553 if (!gst_pad_query_accept_caps (pad, caps))
5565 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5566 "caps %" GST_PTR_FORMAT " not accepted", caps);
5567 return GST_FLOW_NOT_NEGOTIATED;
5571 static GstFlowReturn
5572 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5573 GstPadProbeType type)
5576 GstEventType event_type;
5577 gboolean serialized, need_unlock = FALSE, sticky;
5578 GstPadEventFunction eventfunc;
5579 GstPadEventFullFunction eventfullfunc = NULL;
5582 GST_OBJECT_LOCK (pad);
5584 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5586 if (GST_PAD_IS_SINK (pad))
5587 serialized = GST_EVENT_IS_SERIALIZED (event);
5590 sticky = GST_EVENT_IS_STICKY (event);
5591 event_type = GST_EVENT_TYPE (event);
5592 switch (event_type) {
5593 case GST_EVENT_FLUSH_START:
5594 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5595 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5597 /* can't even accept a flush begin event when flushing */
5598 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5601 GST_PAD_SET_FLUSHING (pad);
5602 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5603 GST_PAD_BLOCK_BROADCAST (pad);
5604 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5606 case GST_EVENT_FLUSH_STOP:
5607 /* we can't accept flush-stop on inactive pads else the flushing flag
5608 * would be cleared and it would look like the pad can accept data.
5609 * Also, some elements restart a streaming thread in flush-stop which we
5610 * can't allow on inactive pads */
5611 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5614 GST_PAD_UNSET_FLUSHING (pad);
5615 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5616 /* Remove pending EOS events */
5617 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5618 remove_event_by_type (pad, GST_EVENT_EOS);
5619 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5620 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5621 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5622 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5624 GST_OBJECT_UNLOCK (pad);
5625 /* grab stream lock */
5626 GST_PAD_STREAM_LOCK (pad);
5628 GST_OBJECT_LOCK (pad);
5629 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5632 case GST_EVENT_RECONFIGURE:
5633 if (GST_PAD_IS_SRC (pad))
5634 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5636 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5637 "have event type %" GST_PTR_FORMAT, event);
5639 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5642 switch (event_type) {
5643 case GST_EVENT_STREAM_START:
5644 /* Remove sticky EOS events */
5645 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5646 remove_event_by_type (pad, GST_EVENT_EOS);
5647 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5648 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5655 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5658 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5659 GST_OBJECT_UNLOCK (pad);
5660 GST_PAD_STREAM_LOCK (pad);
5662 GST_OBJECT_LOCK (pad);
5663 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5666 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5672 /* now do the probe */
5674 type | GST_PAD_PROBE_TYPE_PUSH |
5675 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5677 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5679 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5680 eventfunc = GST_PAD_EVENTFUNC (pad);
5681 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5684 ACQUIRE_PARENT (pad, parent, no_parent);
5685 GST_OBJECT_UNLOCK (pad);
5687 ret = pre_eventfunc_check (pad, event);
5688 if (G_UNLIKELY (ret != GST_FLOW_OK))
5689 goto precheck_failed;
5692 gst_event_ref (event);
5694 if (eventfullfunc) {
5695 ret = eventfullfunc (pad, parent, event);
5696 } else if (eventfunc (pad, parent, event)) {
5699 /* something went wrong */
5700 switch (event_type) {
5701 case GST_EVENT_CAPS:
5702 ret = GST_FLOW_NOT_NEGOTIATED;
5705 ret = GST_FLOW_ERROR;
5709 RELEASE_PARENT (parent);
5711 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5714 if (ret == GST_FLOW_OK) {
5715 GST_OBJECT_LOCK (pad);
5716 /* after the event function accepted the event, we can store the sticky
5717 * event on the pad */
5718 switch (store_sticky_event (pad, event)) {
5719 case GST_FLOW_FLUSHING:
5726 GST_OBJECT_UNLOCK (pad);
5728 gst_event_unref (event);
5732 GST_PAD_STREAM_UNLOCK (pad);
5736 /* ERROR handling */
5739 GST_OBJECT_UNLOCK (pad);
5741 GST_PAD_STREAM_UNLOCK (pad);
5742 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5743 "Received event on flushing pad. Discarding");
5744 gst_event_unref (event);
5745 return GST_FLOW_FLUSHING;
5749 GST_OBJECT_UNLOCK (pad);
5751 GST_PAD_STREAM_UNLOCK (pad);
5752 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5753 "Received flush-stop on inactive pad. Discarding");
5754 gst_event_unref (event);
5755 return GST_FLOW_FLUSHING;
5759 GST_OBJECT_UNLOCK (pad);
5761 GST_PAD_STREAM_UNLOCK (pad);
5762 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5763 "Received event on EOS pad. Discarding");
5764 gst_event_unref (event);
5765 return GST_FLOW_EOS;
5769 GST_OBJECT_UNLOCK (pad);
5771 GST_PAD_STREAM_UNLOCK (pad);
5772 /* Only unref if unhandled */
5773 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5774 gst_event_unref (event);
5777 case GST_FLOW_CUSTOM_SUCCESS_1:
5778 case GST_FLOW_CUSTOM_SUCCESS:
5779 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5783 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5790 g_warning ("pad %s:%s has no event handler, file a bug.",
5791 GST_DEBUG_PAD_NAME (pad));
5792 GST_OBJECT_UNLOCK (pad);
5794 GST_PAD_STREAM_UNLOCK (pad);
5795 gst_event_unref (event);
5796 return GST_FLOW_NOT_SUPPORTED;
5800 GST_DEBUG_OBJECT (pad, "no parent");
5801 GST_OBJECT_UNLOCK (pad);
5803 GST_PAD_STREAM_UNLOCK (pad);
5804 gst_event_unref (event);
5805 return GST_FLOW_FLUSHING;
5809 GST_DEBUG_OBJECT (pad, "pre event check failed");
5810 RELEASE_PARENT (parent);
5812 GST_PAD_STREAM_UNLOCK (pad);
5813 gst_event_unref (event);
5819 * gst_pad_send_event:
5820 * @pad: a #GstPad to send the event to.
5821 * @event: (transfer full): the #GstEvent to send to the pad.
5823 * Sends the event to the pad. This function can be used
5824 * by applications to send events in the pipeline.
5826 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5827 * sink pad, @event should be a downstream event. For example, you would not
5828 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5829 * Furthermore, some downstream events have to be serialized with data flow,
5830 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5831 * the event needs to be serialized with data flow, this function will take the
5832 * pad's stream lock while calling its event function.
5834 * To find out whether an event type is upstream, downstream, or downstream and
5835 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5836 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5837 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5838 * plugin doesn't need to bother itself with this information; the core handles
5839 * all necessary locks and checks.
5841 * This function takes ownership of the provided event so you should
5842 * gst_event_ref() it if you want to reuse the event after this call.
5844 * Returns: %TRUE if the event was handled.
5847 gst_pad_send_event (GstPad * pad, GstEvent * event)
5850 GstPadProbeType type;
5852 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5853 g_return_val_if_fail (event != NULL, FALSE);
5855 if (GST_PAD_IS_SINK (pad)) {
5856 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5857 goto wrong_direction;
5858 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5859 } else if (GST_PAD_IS_SRC (pad)) {
5860 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5861 goto wrong_direction;
5862 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5864 goto unknown_direction;
5866 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5873 /* ERROR handling */
5876 g_warning ("pad %s:%s sending %s event in wrong direction",
5877 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5878 gst_event_unref (event);
5883 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5884 gst_event_unref (event);
5890 * gst_pad_set_element_private:
5891 * @pad: the #GstPad to set the private data of.
5892 * @priv: The private data to attach to the pad.
5894 * Set the given private data gpointer on the pad.
5895 * This function can only be used by the element that owns the pad.
5896 * No locking is performed in this function.
5899 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5901 pad->element_private = priv;
5905 * gst_pad_get_element_private:
5906 * @pad: the #GstPad to get the private data of.
5908 * Gets the private data of a pad.
5909 * No locking is performed in this function.
5911 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5914 gst_pad_get_element_private (GstPad * pad)
5916 return pad->element_private;
5920 * gst_pad_get_sticky_event:
5921 * @pad: the #GstPad to get the event from.
5922 * @event_type: the #GstEventType that should be retrieved.
5923 * @idx: the index of the event
5925 * Returns a new reference of the sticky event of type @event_type
5928 * Returns: (transfer full) (nullable): a #GstEvent of type
5929 * @event_type or %NULL when no event of @event_type was on
5930 * @pad. Unref after usage.
5933 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5935 GstEvent *event = NULL;
5938 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5939 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5941 GST_OBJECT_LOCK (pad);
5942 ev = find_event_by_type (pad, event_type, idx);
5943 if (ev && (event = ev->event))
5944 gst_event_ref (event);
5945 GST_OBJECT_UNLOCK (pad);
5952 GstPadStickyEventsForeachFunction func;
5957 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5959 ForeachDispatch *data = user_data;
5960 gboolean ret = TRUE;
5963 GST_OBJECT_UNLOCK (pad);
5965 ret = data->func (pad, &ev->event, data->user_data);
5967 GST_OBJECT_LOCK (pad);
5974 * gst_pad_sticky_events_foreach:
5975 * @pad: the #GstPad that should be used for iteration.
5976 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5977 * should be called for every event.
5978 * @user_data: (closure): the optional user data.
5980 * Iterates all sticky events on @pad and calls @foreach_func for every
5981 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5984 gst_pad_sticky_events_foreach (GstPad * pad,
5985 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5987 ForeachDispatch data;
5989 g_return_if_fail (GST_IS_PAD (pad));
5990 g_return_if_fail (foreach_func != NULL);
5992 data.func = foreach_func;
5993 data.user_data = user_data;
5995 GST_OBJECT_LOCK (pad);
5996 events_foreach (pad, foreach_dispatch_function, &data);
5997 GST_OBJECT_UNLOCK (pad);
6001 do_stream_status (GstPad * pad, GstStreamStatusType type,
6002 GThread * thread, GstTask * task)
6006 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6008 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6009 if (GST_IS_ELEMENT (parent)) {
6010 GstMessage *message;
6011 GValue value = { 0 };
6013 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6014 gchar *tname, *ename, *pname;
6016 /* create a good task name */
6017 ename = gst_element_get_name (parent);
6018 pname = gst_pad_get_name (pad);
6019 tname = g_strdup_printf ("%s:%s", ename, pname);
6023 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6027 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6030 g_value_init (&value, GST_TYPE_TASK);
6031 g_value_set_object (&value, task);
6032 gst_message_set_stream_status_object (message, &value);
6033 g_value_unset (&value);
6035 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6036 gst_element_post_message (parent, message);
6038 gst_object_unref (parent);
6043 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6045 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6050 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6052 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6057 * gst_pad_start_task:
6058 * @pad: the #GstPad to start the task of
6059 * @func: the task function to call
6060 * @user_data: user data passed to the task function
6061 * @notify: called when @user_data is no longer referenced
6063 * Starts a task that repeatedly calls @func with @user_data. This function
6064 * is mostly used in pad activation functions to start the dataflow.
6065 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6066 * before @func is called.
6068 * Returns: a %TRUE if the task could be started.
6071 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6072 GDestroyNotify notify)
6077 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6078 g_return_val_if_fail (func != NULL, FALSE);
6080 GST_DEBUG_OBJECT (pad, "start task");
6082 GST_OBJECT_LOCK (pad);
6083 task = GST_PAD_TASK (pad);
6085 task = gst_task_new (func, user_data, notify);
6086 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6087 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6088 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6089 GST_INFO_OBJECT (pad, "created task %p", task);
6090 GST_PAD_TASK (pad) = task;
6091 gst_object_ref (task);
6092 /* release lock to post the message */
6093 GST_OBJECT_UNLOCK (pad);
6095 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6097 gst_object_unref (task);
6099 GST_OBJECT_LOCK (pad);
6100 /* nobody else is supposed to have changed the pad now */
6101 if (GST_PAD_TASK (pad) != task)
6102 goto concurrent_stop;
6104 res = gst_task_set_state (task, GST_TASK_STARTED);
6105 GST_OBJECT_UNLOCK (pad);
6112 GST_OBJECT_UNLOCK (pad);
6118 * gst_pad_pause_task:
6119 * @pad: the #GstPad to pause the task of
6121 * Pause the task of @pad. This function will also wait until the
6122 * function executed by the task is finished if this function is not
6123 * called from the task function.
6125 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6129 gst_pad_pause_task (GstPad * pad)
6134 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6136 GST_DEBUG_OBJECT (pad, "pause task");
6138 GST_OBJECT_LOCK (pad);
6139 task = GST_PAD_TASK (pad);
6142 res = gst_task_set_state (task, GST_TASK_PAUSED);
6143 /* unblock activation waits if any */
6144 pad->priv->in_activation = FALSE;
6145 g_cond_broadcast (&pad->priv->activation_cond);
6146 GST_OBJECT_UNLOCK (pad);
6148 /* wait for task function to finish, this lock is recursive so it does nothing
6149 * when the pause is called from the task itself */
6150 GST_PAD_STREAM_LOCK (pad);
6151 GST_PAD_STREAM_UNLOCK (pad);
6157 GST_DEBUG_OBJECT (pad, "pad has no task");
6158 GST_OBJECT_UNLOCK (pad);
6164 * gst_pad_get_task_state:
6165 * @pad: the #GstPad to get task state from
6167 * Get @pad task state. If no task is currently
6168 * set, #GST_TASK_STOPPED is returned.
6170 * Returns: The current state of @pad's task.
6175 gst_pad_get_task_state (GstPad * pad)
6180 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6182 GST_OBJECT_LOCK (pad);
6183 task = GST_PAD_TASK (pad);
6186 res = gst_task_get_state (task);
6187 GST_OBJECT_UNLOCK (pad);
6193 GST_DEBUG_OBJECT (pad, "pad has no task");
6194 GST_OBJECT_UNLOCK (pad);
6195 return GST_TASK_STOPPED;
6200 * gst_pad_stop_task:
6201 * @pad: the #GstPad to stop the task of
6203 * Stop the task of @pad. This function will also make sure that the
6204 * function executed by the task will effectively stop if not called
6205 * from the GstTaskFunction.
6207 * This function will deadlock if called from the GstTaskFunction of
6208 * the task. Use gst_task_pause() instead.
6210 * Regardless of whether the pad has a task, the stream lock is acquired and
6211 * released so as to ensure that streaming through this pad has finished.
6213 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6216 gst_pad_stop_task (GstPad * pad)
6221 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6223 GST_DEBUG_OBJECT (pad, "stop task");
6225 GST_OBJECT_LOCK (pad);
6226 task = GST_PAD_TASK (pad);
6229 GST_PAD_TASK (pad) = NULL;
6230 res = gst_task_set_state (task, GST_TASK_STOPPED);
6231 /* unblock activation waits if any */
6232 pad->priv->in_activation = FALSE;
6233 g_cond_broadcast (&pad->priv->activation_cond);
6234 GST_OBJECT_UNLOCK (pad);
6236 GST_PAD_STREAM_LOCK (pad);
6237 GST_PAD_STREAM_UNLOCK (pad);
6239 if (!gst_task_join (task))
6242 gst_object_unref (task);
6248 GST_DEBUG_OBJECT (pad, "no task");
6249 GST_OBJECT_UNLOCK (pad);
6251 GST_PAD_STREAM_LOCK (pad);
6252 GST_PAD_STREAM_UNLOCK (pad);
6254 /* this is not an error */
6259 /* this is bad, possibly the application tried to join the task from
6260 * the task's thread. We install the task again so that it will be stopped
6261 * again from the right thread next time hopefully. */
6262 GST_OBJECT_LOCK (pad);
6263 GST_DEBUG_OBJECT (pad, "join failed");
6264 /* we can only install this task if there was no other task */
6265 if (GST_PAD_TASK (pad) == NULL)
6266 GST_PAD_TASK (pad) = task;
6267 GST_OBJECT_UNLOCK (pad);
6274 * gst_pad_probe_info_get_event:
6275 * @info: a #GstPadProbeInfo
6277 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6281 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6283 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6284 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6286 return GST_PAD_PROBE_INFO_EVENT (info);
6291 * gst_pad_probe_info_get_query:
6292 * @info: a #GstPadProbeInfo
6294 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6298 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6300 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6301 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6303 return GST_PAD_PROBE_INFO_QUERY (info);
6307 * gst_pad_probe_info_get_buffer:
6308 * @info: a #GstPadProbeInfo
6310 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6314 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6316 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6318 return GST_PAD_PROBE_INFO_BUFFER (info);
6322 * gst_pad_probe_info_get_buffer_list:
6323 * @info: a #GstPadProbeInfo
6325 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6329 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6331 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6333 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6337 * gst_pad_get_last_flow_return:
6340 * Gets the #GstFlowReturn return from the last data passed by this pad.
6345 gst_pad_get_last_flow_return (GstPad * pad)
6349 GST_OBJECT_LOCK (pad);
6350 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6351 GST_OBJECT_UNLOCK (pad);