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)
867 GST_PAD_TEMPLATE_GTYPE (templ) ==
868 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
870 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
872 return g_object_new (pad_type,
873 "name", name, "direction", templ->direction, "template", templ, NULL);
877 * gst_pad_new_from_static_template:
878 * @templ: the #GstStaticPadTemplate to use
879 * @name: the name of the pad
881 * Creates a new pad with the given name from the given static template.
882 * If name is %NULL, a guaranteed unique name (across all pads)
884 * This function makes a copy of the name so you can safely free the name.
886 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
890 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
894 GstPadTemplate *template;
896 template = gst_static_pad_template_get (templ);
897 pad = gst_pad_new_from_template (template, name);
898 gst_object_unref (template);
902 #define ACQUIRE_PARENT(pad, parent, label) \
904 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
905 gst_object_ref (parent); \
906 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
910 #define RELEASE_PARENT(parent) \
912 if (G_LIKELY (parent)) \
913 gst_object_unref (parent); \
917 * gst_pad_get_direction:
918 * @pad: a #GstPad to get the direction of.
920 * Gets the direction of the pad. The direction of the pad is
921 * decided at construction time so this function does not take
924 * Returns: the #GstPadDirection of the pad.
929 gst_pad_get_direction (GstPad * pad)
931 GstPadDirection result;
933 /* PAD_UNKNOWN is a little silly but we need some sort of
934 * error return value */
935 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
937 result = GST_PAD_DIRECTION (pad);
943 gst_pad_activate_default (GstPad * pad, GstObject * parent)
945 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
947 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
951 * gst_pad_mode_get_name:
952 * @mode: the pad mode
954 * Return the name of a pad mode, for use in debug messages mostly.
956 * Returns: short mnemonic for pad mode @mode
959 gst_pad_mode_get_name (GstPadMode mode)
962 case GST_PAD_MODE_NONE:
964 case GST_PAD_MODE_PUSH:
966 case GST_PAD_MODE_PULL:
974 /* Returns TRUE if pad wasn't already in the new_mode */
976 pre_activate (GstPad * pad, GstPadMode new_mode)
979 case GST_PAD_MODE_NONE:
980 GST_OBJECT_LOCK (pad);
981 while (G_UNLIKELY (pad->priv->in_activation))
982 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
983 if (new_mode == GST_PAD_MODE (pad)) {
984 GST_WARNING_OBJECT (pad,
985 "Pad is already in the process of being deactivated");
986 GST_OBJECT_UNLOCK (pad);
989 pad->priv->in_activation = TRUE;
990 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
991 GST_PAD_SET_FLUSHING (pad);
992 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
993 GST_PAD_MODE (pad) = new_mode;
994 /* unlock blocked pads so element can resume and stop */
995 GST_PAD_BLOCK_BROADCAST (pad);
996 GST_OBJECT_UNLOCK (pad);
998 case GST_PAD_MODE_PUSH:
999 case GST_PAD_MODE_PULL:
1000 GST_OBJECT_LOCK (pad);
1001 while (G_UNLIKELY (pad->priv->in_activation))
1002 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1003 if (new_mode == GST_PAD_MODE (pad)) {
1004 GST_WARNING_OBJECT (pad,
1005 "Pad is already in the process of being activated");
1006 GST_OBJECT_UNLOCK (pad);
1009 pad->priv->in_activation = TRUE;
1010 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1011 gst_pad_mode_get_name (new_mode));
1012 GST_PAD_UNSET_FLUSHING (pad);
1013 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1014 GST_PAD_MODE (pad) = new_mode;
1015 if (GST_PAD_IS_SINK (pad)) {
1017 /* make sure the peer src pad sends us all events */
1018 if ((peer = GST_PAD_PEER (pad))) {
1019 gst_object_ref (peer);
1020 GST_OBJECT_UNLOCK (pad);
1022 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1023 GST_DEBUG_PAD_NAME (peer));
1025 GST_OBJECT_LOCK (peer);
1026 schedule_events (peer, NULL);
1027 GST_OBJECT_UNLOCK (peer);
1029 gst_object_unref (peer);
1031 GST_OBJECT_UNLOCK (pad);
1034 GST_OBJECT_UNLOCK (pad);
1042 post_activate (GstPad * pad, GstPadMode new_mode)
1045 case GST_PAD_MODE_NONE:
1046 GST_OBJECT_LOCK (pad);
1047 pad->priv->in_activation = FALSE;
1048 g_cond_broadcast (&pad->priv->activation_cond);
1049 GST_OBJECT_UNLOCK (pad);
1051 /* ensures that streaming stops */
1052 GST_PAD_STREAM_LOCK (pad);
1053 GST_DEBUG_OBJECT (pad, "stopped streaming");
1054 GST_OBJECT_LOCK (pad);
1055 remove_events (pad);
1056 GST_OBJECT_UNLOCK (pad);
1057 GST_PAD_STREAM_UNLOCK (pad);
1059 case GST_PAD_MODE_PUSH:
1060 case GST_PAD_MODE_PULL:
1061 GST_OBJECT_LOCK (pad);
1062 pad->priv->in_activation = FALSE;
1063 g_cond_broadcast (&pad->priv->activation_cond);
1064 GST_OBJECT_UNLOCK (pad);
1071 * gst_pad_set_active:
1072 * @pad: the #GstPad to activate or deactivate.
1073 * @active: whether or not the pad should be active.
1075 * Activates or deactivates the given pad.
1076 * Normally called from within core state change functions.
1078 * If @active, makes sure the pad is active. If it is already active, either in
1079 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1080 * function to perform the actual activation.
1082 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1083 * and a %FALSE argument.
1085 * Returns: %TRUE if the operation was successful.
1090 gst_pad_set_active (GstPad * pad, gboolean active)
1094 gboolean ret = FALSE;
1096 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1098 GST_OBJECT_LOCK (pad);
1099 old = GST_PAD_MODE (pad);
1100 ACQUIRE_PARENT (pad, parent, no_parent);
1101 GST_OBJECT_UNLOCK (pad);
1104 if (old == GST_PAD_MODE_NONE) {
1105 GST_DEBUG_OBJECT (pad, "activating pad from none");
1106 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1108 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1110 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1111 gst_pad_mode_get_name (old));
1115 if (old == GST_PAD_MODE_NONE) {
1116 GST_DEBUG_OBJECT (pad, "pad was inactive");
1119 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1120 gst_pad_mode_get_name (old));
1121 ret = activate_mode_internal (pad, parent, old, FALSE);
1123 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1127 RELEASE_PARENT (parent);
1129 if (G_UNLIKELY (!ret))
1137 GST_DEBUG_OBJECT (pad, "no parent");
1138 GST_OBJECT_UNLOCK (pad);
1143 GST_OBJECT_LOCK (pad);
1145 g_critical ("Failed to deactivate pad %s:%s, very bad",
1146 GST_DEBUG_PAD_NAME (pad));
1148 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1150 GST_OBJECT_UNLOCK (pad);
1156 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1159 gboolean res = FALSE;
1160 GstPadMode old, new;
1161 GstPadDirection dir;
1164 GST_OBJECT_LOCK (pad);
1165 old = GST_PAD_MODE (pad);
1166 dir = GST_PAD_DIRECTION (pad);
1167 GST_OBJECT_UNLOCK (pad);
1169 new = active ? mode : GST_PAD_MODE_NONE;
1174 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1175 /* pad was activate in the wrong direction, deactivate it
1176 * and reactivate it in the requested mode */
1177 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1178 gst_pad_mode_get_name (old));
1180 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1181 goto deactivate_failed;
1182 old = GST_PAD_MODE_NONE;
1186 case GST_PAD_MODE_PULL:
1188 if (dir == GST_PAD_SINK) {
1189 if ((peer = gst_pad_get_peer (pad))) {
1190 GST_DEBUG_OBJECT (pad, "calling peer");
1191 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1193 gst_object_unref (peer);
1195 /* there is no peer, this is only fatal when we activate. When we
1196 * deactivate, we must assume the application has unlinked the peer and
1197 * will deactivate it eventually. */
1201 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1204 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1205 goto failure; /* Can't activate pull on a src without a
1206 getrange function */
1214 /* Mark pad as needing reconfiguration */
1216 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1218 /* pre_activate returns TRUE if we weren't already in the process of
1219 * switching to the 'new' mode */
1220 if (pre_activate (pad, new)) {
1222 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1223 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1227 /* can happen for sinks of passthrough elements */
1230 post_activate (pad, new);
1233 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1234 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1239 /* Clear sticky flags on deactivation */
1241 GST_OBJECT_LOCK (pad);
1242 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1243 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1244 GST_OBJECT_UNLOCK (pad);
1252 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1253 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1258 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1259 "failed to %s in switch to %s mode from %s mode",
1260 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1261 gst_pad_mode_get_name (old));
1266 GST_OBJECT_LOCK (peer);
1267 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1268 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1269 GST_OBJECT_UNLOCK (peer);
1270 gst_object_unref (peer);
1275 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1276 "pad in pull mode");
1281 GST_OBJECT_LOCK (pad);
1282 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1283 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1284 GST_PAD_SET_FLUSHING (pad);
1285 GST_PAD_MODE (pad) = old;
1286 pad->priv->in_activation = FALSE;
1287 g_cond_broadcast (&pad->priv->activation_cond);
1288 GST_OBJECT_UNLOCK (pad);
1294 * gst_pad_activate_mode:
1295 * @pad: the #GstPad to activate or deactivate.
1296 * @mode: the requested activation mode
1297 * @active: whether or not the pad should be active.
1299 * Activates or deactivates the given pad in @mode via dispatching to the
1300 * pad's activatemodefunc. For use from within pad activation functions only.
1302 * If you don't know what this is, you probably don't want to call it.
1304 * Returns: %TRUE if the operation was successful.
1309 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1313 GstPadMode old, new;
1315 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1317 GST_OBJECT_LOCK (pad);
1319 old = GST_PAD_MODE (pad);
1320 new = active ? mode : GST_PAD_MODE_NONE;
1324 ACQUIRE_PARENT (pad, parent, no_parent);
1326 GST_OBJECT_UNLOCK (pad);
1328 res = activate_mode_internal (pad, parent, mode, active);
1330 RELEASE_PARENT (parent);
1336 GST_OBJECT_UNLOCK (pad);
1337 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1338 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1343 GST_WARNING_OBJECT (pad, "no parent");
1344 GST_OBJECT_UNLOCK (pad);
1350 * gst_pad_is_active:
1351 * @pad: the #GstPad to query
1353 * Query if a pad is active
1355 * Returns: %TRUE if the pad is active.
1360 gst_pad_is_active (GstPad * pad)
1362 gboolean result = FALSE;
1364 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1366 GST_OBJECT_LOCK (pad);
1367 result = GST_PAD_IS_ACTIVE (pad);
1368 GST_OBJECT_UNLOCK (pad);
1374 cleanup_hook (GstPad * pad, GHook * hook)
1376 GstPadProbeType type;
1378 if (!G_HOOK_IS_VALID (hook))
1381 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1383 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1384 /* unblock when we remove the last blocking probe */
1386 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1389 /* Might have new probes now that want to be called */
1390 GST_PAD_BLOCK_BROADCAST (pad);
1392 if (pad->num_blocked == 0) {
1393 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1394 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1397 g_hook_destroy_link (&pad->probes, hook);
1402 * gst_pad_add_probe:
1403 * @pad: the #GstPad to add the probe to
1404 * @mask: the probe mask
1405 * @callback: #GstPadProbeCallback that will be called with notifications of
1407 * @user_data: (closure): user data passed to the callback
1408 * @destroy_data: #GDestroyNotify for user_data
1410 * Be notified of different states of pads. The provided callback is called for
1411 * every state that matches @mask.
1413 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1414 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1415 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1416 * immediately if the pad is already idle while calling gst_pad_add_probe().
1417 * In each of the groups, probes are called in the order in which they were
1420 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1421 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1422 * happen that the probe can be run immediately and if the probe returns
1423 * GST_PAD_PROBE_REMOVE this functions returns 0.
1428 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1429 GstPadProbeCallback callback, gpointer user_data,
1430 GDestroyNotify destroy_data)
1435 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1436 g_return_val_if_fail (mask != 0, 0);
1438 GST_OBJECT_LOCK (pad);
1440 /* make a new probe */
1441 hook = g_hook_alloc (&pad->probes);
1443 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1446 /* when no contraints are given for the types, assume all types are
1448 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1449 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1450 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1451 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1453 /* store our flags and other fields */
1454 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1455 hook->func = callback;
1456 hook->data = user_data;
1457 hook->destroy = destroy_data;
1458 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1461 g_hook_append (&pad->probes, hook);
1463 /* incremenent cookie so that the new hook get's called */
1464 pad->priv->probe_list_cookie++;
1466 /* get the id of the hook, we return this and it can be used to remove the
1468 res = hook->hook_id;
1470 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1472 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1473 /* we have a block probe */
1475 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1476 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1477 "now %d blocking probes", pad->num_blocked);
1479 /* Might have new probes now that want to be called */
1480 GST_PAD_BLOCK_BROADCAST (pad);
1483 /* call the callback if we need to be called for idle callbacks */
1484 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1485 if (pad->priv->using > 0) {
1486 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1487 * flag above, the last thread to leave the push will do the callback. New
1488 * threads going into the push will block. */
1489 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1490 "pad is in use, delay idle callback");
1491 GST_OBJECT_UNLOCK (pad);
1493 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1494 GstPadProbeReturn ret;
1496 /* Keep another ref, the callback could destroy the pad */
1497 gst_object_ref (pad);
1498 pad->priv->idle_running++;
1500 /* the pad is idle now, we can signal the idle callback now */
1501 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1502 "pad is idle, trigger idle callback");
1503 GST_OBJECT_UNLOCK (pad);
1505 ret = callback (pad, &info, user_data);
1507 GST_OBJECT_LOCK (pad);
1509 case GST_PAD_PROBE_REMOVE:
1510 /* remove the probe */
1511 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1512 cleanup_hook (pad, hook);
1515 case GST_PAD_PROBE_DROP:
1516 GST_DEBUG_OBJECT (pad, "asked to drop item");
1518 case GST_PAD_PROBE_PASS:
1519 GST_DEBUG_OBJECT (pad, "asked to pass item");
1521 case GST_PAD_PROBE_OK:
1522 GST_DEBUG_OBJECT (pad, "probe returned OK");
1524 case GST_PAD_PROBE_HANDLED:
1525 GST_DEBUG_OBJECT (pad, "probe handled the data");
1528 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1531 pad->priv->idle_running--;
1532 if (pad->priv->idle_running == 0) {
1533 GST_PAD_BLOCK_BROADCAST (pad);
1535 GST_OBJECT_UNLOCK (pad);
1537 gst_object_unref (pad);
1540 GST_OBJECT_UNLOCK (pad);
1546 * gst_pad_remove_probe:
1547 * @pad: the #GstPad with the probe
1548 * @id: the probe id to remove
1550 * Remove the probe with @id from @pad.
1555 gst_pad_remove_probe (GstPad * pad, gulong id)
1559 g_return_if_fail (GST_IS_PAD (pad));
1561 GST_OBJECT_LOCK (pad);
1563 hook = g_hook_get (&pad->probes, id);
1567 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1569 cleanup_hook (pad, hook);
1570 GST_OBJECT_UNLOCK (pad);
1576 GST_OBJECT_UNLOCK (pad);
1577 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1583 * gst_pad_is_blocked:
1584 * @pad: the #GstPad to query
1586 * Checks if the pad is blocked or not. This function returns the
1587 * last requested state of the pad. It is not certain that the pad
1588 * is actually blocking at this point (see gst_pad_is_blocking()).
1590 * Returns: %TRUE if the pad is blocked.
1595 gst_pad_is_blocked (GstPad * pad)
1597 gboolean result = FALSE;
1599 g_return_val_if_fail (GST_IS_PAD (pad), result);
1601 GST_OBJECT_LOCK (pad);
1602 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1603 GST_OBJECT_UNLOCK (pad);
1609 * gst_pad_is_blocking:
1610 * @pad: the #GstPad to query
1612 * Checks if the pad is blocking or not. This is a guaranteed state
1613 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1615 * Returns: %TRUE if the pad is blocking.
1620 gst_pad_is_blocking (GstPad * pad)
1622 gboolean result = FALSE;
1624 g_return_val_if_fail (GST_IS_PAD (pad), result);
1626 GST_OBJECT_LOCK (pad);
1627 /* the blocking flag is only valid if the pad is not flushing */
1628 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1629 GST_OBJECT_UNLOCK (pad);
1635 * gst_pad_needs_reconfigure:
1636 * @pad: the #GstPad to check
1638 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1639 * if the flag was set.
1641 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1644 gst_pad_needs_reconfigure (GstPad * pad)
1646 gboolean reconfigure;
1648 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1650 GST_OBJECT_LOCK (pad);
1651 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1652 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1653 GST_OBJECT_UNLOCK (pad);
1659 * gst_pad_check_reconfigure:
1660 * @pad: the #GstPad to check
1662 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1663 * if the flag was set.
1665 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1668 gst_pad_check_reconfigure (GstPad * pad)
1670 gboolean reconfigure;
1672 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1674 GST_OBJECT_LOCK (pad);
1675 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1677 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1678 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1680 GST_OBJECT_UNLOCK (pad);
1686 * gst_pad_mark_reconfigure:
1687 * @pad: the #GstPad to mark
1689 * Mark a pad for needing reconfiguration. The next call to
1690 * gst_pad_check_reconfigure() will return %TRUE after this call.
1693 gst_pad_mark_reconfigure (GstPad * pad)
1695 g_return_if_fail (GST_IS_PAD (pad));
1697 GST_OBJECT_LOCK (pad);
1698 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1699 GST_OBJECT_UNLOCK (pad);
1703 * gst_pad_set_activate_function:
1705 * @f: the #GstPadActivateFunction to set.
1707 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1711 * gst_pad_set_activate_function_full:
1713 * @activate: the #GstPadActivateFunction to set.
1714 * @user_data: user_data passed to @notify
1715 * @notify: notify called when @activate will not be used anymore.
1717 * Sets the given activate function for @pad. The activate function will
1718 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1719 * Only makes sense to set on sink pads.
1721 * Call this function if your sink pad can start a pull-based task.
1724 gst_pad_set_activate_function_full (GstPad * pad,
1725 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1727 g_return_if_fail (GST_IS_PAD (pad));
1729 if (pad->activatenotify)
1730 pad->activatenotify (pad->activatedata);
1731 GST_PAD_ACTIVATEFUNC (pad) = activate;
1732 pad->activatedata = user_data;
1733 pad->activatenotify = notify;
1735 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1736 GST_DEBUG_FUNCPTR_NAME (activate));
1740 * gst_pad_set_activatemode_function:
1742 * @f: the #GstPadActivateModeFunction to set.
1744 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1748 * gst_pad_set_activatemode_function_full:
1750 * @activatemode: the #GstPadActivateModeFunction to set.
1751 * @user_data: user_data passed to @notify
1752 * @notify: notify called when @activatemode will not be used anymore.
1754 * Sets the given activate_mode function for the pad. An activate_mode function
1755 * prepares the element for data passing.
1758 gst_pad_set_activatemode_function_full (GstPad * pad,
1759 GstPadActivateModeFunction activatemode, gpointer user_data,
1760 GDestroyNotify notify)
1762 g_return_if_fail (GST_IS_PAD (pad));
1764 if (pad->activatemodenotify)
1765 pad->activatemodenotify (pad->activatemodedata);
1766 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1767 pad->activatemodedata = user_data;
1768 pad->activatemodenotify = notify;
1770 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1771 GST_DEBUG_FUNCPTR_NAME (activatemode));
1775 * gst_pad_set_chain_function:
1776 * @p: a sink #GstPad.
1777 * @f: the #GstPadChainFunction to set.
1779 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1783 * gst_pad_set_chain_function_full:
1784 * @pad: a sink #GstPad.
1785 * @chain: the #GstPadChainFunction to set.
1786 * @user_data: user_data passed to @notify
1787 * @notify: notify called when @chain will not be used anymore.
1789 * Sets the given chain function for the pad. The chain function is called to
1790 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1793 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1794 gpointer user_data, GDestroyNotify notify)
1796 g_return_if_fail (GST_IS_PAD (pad));
1797 g_return_if_fail (GST_PAD_IS_SINK (pad));
1799 if (pad->chainnotify)
1800 pad->chainnotify (pad->chaindata);
1801 GST_PAD_CHAINFUNC (pad) = chain;
1802 pad->chaindata = user_data;
1803 pad->chainnotify = notify;
1805 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1806 GST_DEBUG_FUNCPTR_NAME (chain));
1810 * gst_pad_set_chain_list_function:
1811 * @p: a sink #GstPad.
1812 * @f: the #GstPadChainListFunction to set.
1814 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1818 * gst_pad_set_chain_list_function_full:
1819 * @pad: a sink #GstPad.
1820 * @chainlist: the #GstPadChainListFunction to set.
1821 * @user_data: user_data passed to @notify
1822 * @notify: notify called when @chainlist will not be used anymore.
1824 * Sets the given chain list function for the pad. The chainlist function is
1825 * called to process a #GstBufferList input buffer list. See
1826 * #GstPadChainListFunction for more details.
1829 gst_pad_set_chain_list_function_full (GstPad * pad,
1830 GstPadChainListFunction chainlist, gpointer user_data,
1831 GDestroyNotify notify)
1833 g_return_if_fail (GST_IS_PAD (pad));
1834 g_return_if_fail (GST_PAD_IS_SINK (pad));
1836 if (pad->chainlistnotify)
1837 pad->chainlistnotify (pad->chainlistdata);
1838 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1839 pad->chainlistdata = user_data;
1840 pad->chainlistnotify = notify;
1842 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1843 GST_DEBUG_FUNCPTR_NAME (chainlist));
1847 * gst_pad_set_getrange_function:
1848 * @p: a source #GstPad.
1849 * @f: the #GstPadGetRangeFunction to set.
1851 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1855 * gst_pad_set_getrange_function_full:
1856 * @pad: a source #GstPad.
1857 * @get: the #GstPadGetRangeFunction to set.
1858 * @user_data: user_data passed to @notify
1859 * @notify: notify called when @get will not be used anymore.
1861 * Sets the given getrange function for the pad. The getrange function is
1862 * called to produce a new #GstBuffer to start the processing pipeline. see
1863 * #GstPadGetRangeFunction for a description of the getrange function.
1866 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1867 gpointer user_data, GDestroyNotify notify)
1869 g_return_if_fail (GST_IS_PAD (pad));
1870 g_return_if_fail (GST_PAD_IS_SRC (pad));
1872 if (pad->getrangenotify)
1873 pad->getrangenotify (pad->getrangedata);
1874 GST_PAD_GETRANGEFUNC (pad) = get;
1875 pad->getrangedata = user_data;
1876 pad->getrangenotify = notify;
1878 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1879 GST_DEBUG_FUNCPTR_NAME (get));
1883 * gst_pad_set_event_function:
1884 * @p: a #GstPad of either direction.
1885 * @f: the #GstPadEventFunction to set.
1887 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1891 * gst_pad_set_event_function_full:
1892 * @pad: a #GstPad of either direction.
1893 * @event: the #GstPadEventFunction to set.
1894 * @user_data: user_data passed to @notify
1895 * @notify: notify called when @event will not be used anymore.
1897 * Sets the given event handler for the pad.
1900 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1901 gpointer user_data, GDestroyNotify notify)
1903 g_return_if_fail (GST_IS_PAD (pad));
1905 if (pad->eventnotify)
1906 pad->eventnotify (pad->eventdata);
1907 GST_PAD_EVENTFUNC (pad) = event;
1908 pad->eventdata = user_data;
1909 pad->eventnotify = notify;
1911 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1912 GST_DEBUG_FUNCPTR_NAME (event));
1916 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1920 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1921 if (ret == GST_FLOW_OK)
1927 * gst_pad_set_event_full_function:
1928 * @p: a #GstPad of either direction.
1929 * @f: the #GstPadEventFullFunction to set.
1931 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1935 * gst_pad_set_event_full_function_full:
1936 * @pad: a #GstPad of either direction.
1937 * @event: the #GstPadEventFullFunction to set.
1938 * @user_data: user_data passed to @notify
1939 * @notify: notify called when @event will not be used anymore.
1941 * Sets the given event handler for the pad.
1946 gst_pad_set_event_full_function_full (GstPad * pad,
1947 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1949 g_return_if_fail (GST_IS_PAD (pad));
1951 if (pad->eventnotify)
1952 pad->eventnotify (pad->eventdata);
1953 GST_PAD_EVENTFULLFUNC (pad) = event;
1954 GST_PAD_EVENTFUNC (pad) = event_wrap;
1955 pad->eventdata = user_data;
1956 pad->eventnotify = notify;
1958 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1959 GST_DEBUG_FUNCPTR_NAME (event));
1963 * gst_pad_set_query_function:
1964 * @p: a #GstPad of either direction.
1965 * @f: the #GstPadQueryFunction to set.
1967 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1971 * gst_pad_set_query_function_full:
1972 * @pad: a #GstPad of either direction.
1973 * @query: the #GstPadQueryFunction to set.
1974 * @user_data: user_data passed to @notify
1975 * @notify: notify called when @query will not be used anymore.
1977 * Set the given query function for the pad.
1980 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1981 gpointer user_data, GDestroyNotify notify)
1983 g_return_if_fail (GST_IS_PAD (pad));
1985 if (pad->querynotify)
1986 pad->querynotify (pad->querydata);
1987 GST_PAD_QUERYFUNC (pad) = query;
1988 pad->querydata = user_data;
1989 pad->querynotify = notify;
1991 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1992 GST_DEBUG_FUNCPTR_NAME (query));
1996 * gst_pad_set_iterate_internal_links_function:
1997 * @p: a #GstPad of either direction.
1998 * @f: the #GstPadIterIntLinkFunction to set.
2000 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
2001 * for the user_data and notify.
2004 * gst_pad_set_iterate_internal_links_function_full:
2005 * @pad: a #GstPad of either direction.
2006 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2007 * @user_data: user_data passed to @notify
2008 * @notify: notify called when @iterintlink will not be used anymore.
2010 * Sets the given internal link iterator function for the pad.
2013 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2014 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2015 GDestroyNotify notify)
2017 g_return_if_fail (GST_IS_PAD (pad));
2019 if (pad->iterintlinknotify)
2020 pad->iterintlinknotify (pad->iterintlinkdata);
2021 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2022 pad->iterintlinkdata = user_data;
2023 pad->iterintlinknotify = notify;
2025 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2026 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2030 * gst_pad_set_link_function:
2032 * @f: the #GstPadLinkFunction to set.
2034 * Calls gst_pad_set_link_function_full() with %NULL
2035 * for the user_data and notify.
2038 * gst_pad_set_link_function_full:
2040 * @link: the #GstPadLinkFunction to set.
2041 * @user_data: user_data passed to @notify
2042 * @notify: notify called when @link will not be used anymore.
2044 * Sets the given link function for the pad. It will be called when
2045 * the pad is linked with another pad.
2047 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2050 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2051 * cannot be made for some reason.
2053 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2054 * of the peer sink pad, if present.
2057 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2058 gpointer user_data, GDestroyNotify notify)
2060 g_return_if_fail (GST_IS_PAD (pad));
2062 if (pad->linknotify)
2063 pad->linknotify (pad->linkdata);
2064 GST_PAD_LINKFUNC (pad) = link;
2065 pad->linkdata = user_data;
2066 pad->linknotify = notify;
2068 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2069 GST_DEBUG_FUNCPTR_NAME (link));
2073 * gst_pad_set_unlink_function:
2075 * @f: the #GstPadUnlinkFunction to set.
2077 * Calls gst_pad_set_unlink_function_full() with %NULL
2078 * for the user_data and notify.
2081 * gst_pad_set_unlink_function_full:
2083 * @unlink: the #GstPadUnlinkFunction to set.
2084 * @user_data: user_data passed to @notify
2085 * @notify: notify called when @unlink will not be used anymore.
2087 * Sets the given unlink function for the pad. It will be called
2088 * when the pad is unlinked.
2091 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2092 gpointer user_data, GDestroyNotify notify)
2094 g_return_if_fail (GST_IS_PAD (pad));
2096 if (pad->unlinknotify)
2097 pad->unlinknotify (pad->unlinkdata);
2098 GST_PAD_UNLINKFUNC (pad) = unlink;
2099 pad->unlinkdata = user_data;
2100 pad->unlinknotify = notify;
2102 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2103 GST_DEBUG_FUNCPTR_NAME (unlink));
2108 * @srcpad: the source #GstPad to unlink.
2109 * @sinkpad: the sink #GstPad to unlink.
2111 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2112 * signal on both pads.
2114 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2115 * the pads were not linked together.
2120 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2122 gboolean result = FALSE;
2123 GstElement *parent = NULL;
2125 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2126 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2127 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2128 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2130 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2132 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2133 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2134 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2136 /* We need to notify the parent before taking any pad locks as the bin in
2137 * question might be waiting for a lock on the pad while holding its lock
2138 * that our message will try to take. */
2139 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2140 if (GST_IS_ELEMENT (parent)) {
2141 gst_element_post_message (parent,
2142 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2143 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2145 gst_object_unref (parent);
2150 GST_OBJECT_LOCK (srcpad);
2151 GST_OBJECT_LOCK (sinkpad);
2153 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2154 goto not_linked_together;
2156 if (GST_PAD_UNLINKFUNC (srcpad)) {
2157 GstObject *tmpparent;
2159 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2161 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2162 RELEASE_PARENT (tmpparent);
2165 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2166 GstObject *tmpparent;
2168 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2170 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2171 RELEASE_PARENT (tmpparent);
2175 /* first clear peers */
2176 GST_PAD_PEER (srcpad) = NULL;
2177 GST_PAD_PEER (sinkpad) = NULL;
2179 GST_OBJECT_UNLOCK (sinkpad);
2180 GST_OBJECT_UNLOCK (srcpad);
2182 /* fire off a signal to each of the pads telling them
2183 * that they've been unlinked */
2184 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2185 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2187 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2188 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2193 if (parent != NULL) {
2194 gst_element_post_message (parent,
2195 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2196 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2197 gst_object_unref (parent);
2199 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2203 not_linked_together:
2205 /* we do not emit a warning in this case because unlinking cannot
2206 * be made MT safe.*/
2207 GST_OBJECT_UNLOCK (sinkpad);
2208 GST_OBJECT_UNLOCK (srcpad);
2214 * gst_pad_is_linked:
2215 * @pad: pad to check
2217 * Checks if a @pad is linked to another pad or not.
2219 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2224 gst_pad_is_linked (GstPad * pad)
2228 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2230 GST_OBJECT_LOCK (pad);
2231 result = (GST_PAD_PEER (pad) != NULL);
2232 GST_OBJECT_UNLOCK (pad);
2237 /* get the caps from both pads and see if the intersection
2240 * This function should be called with the pad LOCK on both
2244 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2245 GstPadLinkCheck flags)
2247 GstCaps *srccaps = NULL;
2248 GstCaps *sinkcaps = NULL;
2249 gboolean compatible = FALSE;
2251 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2254 /* Doing the expensive caps checking takes priority over only checking the template caps */
2255 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2256 GST_OBJECT_UNLOCK (sink);
2257 GST_OBJECT_UNLOCK (src);
2259 srccaps = gst_pad_query_caps (src, NULL);
2260 sinkcaps = gst_pad_query_caps (sink, NULL);
2262 GST_OBJECT_LOCK (src);
2263 GST_OBJECT_LOCK (sink);
2265 /* If one of the two pads doesn't have a template, consider the intersection
2267 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2268 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2272 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2274 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2277 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2279 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2282 /* if we have caps on both pads we can check the intersection. If one
2283 * of the caps is %NULL, we return %TRUE. */
2284 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2286 gst_caps_unref (srccaps);
2288 gst_caps_unref (sinkcaps);
2292 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2293 gst_caps_unref (srccaps);
2294 gst_caps_unref (sinkcaps);
2297 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2298 (compatible ? "" : "not "));
2303 /* check if the grandparents of both pads are the same.
2304 * This check is required so that we don't try to link
2305 * pads from elements in different bins without ghostpads.
2307 * The LOCK should be held on both pads
2310 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2312 GstObject *psrc, *psink;
2314 psrc = GST_OBJECT_PARENT (src);
2315 psink = GST_OBJECT_PARENT (sink);
2317 /* if one of the pads has no parent, we allow the link */
2318 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2321 /* only care about parents that are elements */
2322 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2323 goto no_element_parent;
2325 /* if the parents are the same, we have a loop */
2326 if (G_UNLIKELY (psrc == psink))
2329 /* if they both have a parent, we check the grandparents. We can not lock
2330 * the parent because we hold on the child (pad) and the locking order is
2331 * parent >> child. */
2332 psrc = GST_OBJECT_PARENT (psrc);
2333 psink = GST_OBJECT_PARENT (psink);
2335 /* if they have grandparents but they are not the same */
2336 if (G_UNLIKELY (psrc != psink))
2337 goto wrong_grandparents;
2344 GST_CAT_DEBUG (GST_CAT_CAPS,
2345 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2346 GST_PTR_FORMAT, psrc, psink);
2351 GST_CAT_DEBUG (GST_CAT_CAPS,
2352 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2353 GST_PTR_FORMAT, psrc, psink);
2358 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2364 GST_CAT_DEBUG (GST_CAT_CAPS,
2365 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2366 GST_PTR_FORMAT, psrc, psink);
2371 /* FIXME leftover from an attempt at refactoring... */
2372 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2373 * the two pads will be locked in the srcpad, sinkpad order. */
2374 static GstPadLinkReturn
2375 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2377 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2378 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2380 GST_OBJECT_LOCK (srcpad);
2382 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2383 goto src_was_linked;
2385 GST_OBJECT_LOCK (sinkpad);
2387 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2388 goto sink_was_linked;
2390 /* check hierarchy, pads can only be linked if the grandparents
2392 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2393 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2394 goto wrong_hierarchy;
2396 /* check pad caps for non-empty intersection */
2397 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2400 /* FIXME check pad scheduling for non-empty intersection */
2402 return GST_PAD_LINK_OK;
2406 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2407 GST_DEBUG_PAD_NAME (srcpad),
2408 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2409 /* we do not emit a warning in this case because unlinking cannot
2410 * be made MT safe.*/
2411 GST_OBJECT_UNLOCK (srcpad);
2412 return GST_PAD_LINK_WAS_LINKED;
2416 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2417 GST_DEBUG_PAD_NAME (sinkpad),
2418 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2419 /* we do not emit a warning in this case because unlinking cannot
2420 * be made MT safe.*/
2421 GST_OBJECT_UNLOCK (sinkpad);
2422 GST_OBJECT_UNLOCK (srcpad);
2423 return GST_PAD_LINK_WAS_LINKED;
2427 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2428 GST_OBJECT_UNLOCK (sinkpad);
2429 GST_OBJECT_UNLOCK (srcpad);
2430 return GST_PAD_LINK_WRONG_HIERARCHY;
2434 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2435 GST_OBJECT_UNLOCK (sinkpad);
2436 GST_OBJECT_UNLOCK (srcpad);
2437 return GST_PAD_LINK_NOFORMAT;
2443 * @srcpad: the source #GstPad.
2444 * @sinkpad: the sink #GstPad.
2446 * Checks if the source pad and the sink pad are compatible so they can be
2449 * Returns: %TRUE if the pads can be linked.
2452 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2454 GstPadLinkReturn result;
2456 /* generic checks */
2457 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2458 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2460 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2461 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2463 /* gst_pad_link_prepare does everything for us, we only release the locks
2464 * on the pads that it gets us. If this function returns !OK the locks are not
2466 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2467 if (result != GST_PAD_LINK_OK)
2470 GST_OBJECT_UNLOCK (srcpad);
2471 GST_OBJECT_UNLOCK (sinkpad);
2474 return result == GST_PAD_LINK_OK;
2478 * gst_pad_link_full:
2479 * @srcpad: the source #GstPad to link.
2480 * @sinkpad: the sink #GstPad to link.
2481 * @flags: the checks to validate when linking
2483 * Links the source pad and the sink pad.
2485 * This variant of #gst_pad_link provides a more granular control on the
2486 * checks being done when linking. While providing some considerable speedups
2487 * the caller of this method must be aware that wrong usage of those flags
2488 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2489 * for more information.
2493 * Returns: A result code indicating if the connection worked or
2497 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2499 GstPadLinkReturn result;
2501 GstPadLinkFunction srcfunc, sinkfunc;
2503 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2504 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2505 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2506 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2507 GST_PAD_LINK_WRONG_DIRECTION);
2509 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2511 /* Notify the parent early. See gst_pad_unlink for details. */
2512 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2513 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2514 gst_element_post_message (parent,
2515 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2516 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2518 gst_object_unref (parent);
2523 /* prepare will also lock the two pads */
2524 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2526 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2527 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2528 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2529 gst_pad_link_get_name (result));
2533 /* must set peers before calling the link function */
2534 GST_PAD_PEER (srcpad) = sinkpad;
2535 GST_PAD_PEER (sinkpad) = srcpad;
2537 /* check events, when something is different, mark pending */
2538 schedule_events (srcpad, sinkpad);
2540 /* get the link functions */
2541 srcfunc = GST_PAD_LINKFUNC (srcpad);
2542 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2544 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2545 /* custom link functions, execute them */
2546 GST_OBJECT_UNLOCK (sinkpad);
2547 GST_OBJECT_UNLOCK (srcpad);
2550 GstObject *tmpparent;
2552 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2553 /* this one will call the peer link function */
2554 result = srcfunc (srcpad, tmpparent, sinkpad);
2555 RELEASE_PARENT (tmpparent);
2556 } else if (sinkfunc) {
2557 GstObject *tmpparent;
2559 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2560 /* if no source link function, we need to call the sink link
2561 * function ourselves. */
2562 result = sinkfunc (sinkpad, tmpparent, srcpad);
2563 RELEASE_PARENT (tmpparent);
2567 GST_OBJECT_LOCK (srcpad);
2568 GST_OBJECT_LOCK (sinkpad);
2570 /* we released the lock, check if the same pads are linked still */
2571 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2572 goto concurrent_link;
2574 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2577 GST_OBJECT_UNLOCK (sinkpad);
2578 GST_OBJECT_UNLOCK (srcpad);
2580 /* fire off a signal to each of the pads telling them
2581 * that they've been linked */
2582 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2583 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2585 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2586 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2588 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2589 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2592 if (G_LIKELY (parent)) {
2593 gst_element_post_message (parent,
2594 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2595 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2596 gst_object_unref (parent);
2599 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2605 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2606 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2607 GST_OBJECT_UNLOCK (sinkpad);
2608 GST_OBJECT_UNLOCK (srcpad);
2610 /* The other link operation succeeded first */
2611 result = GST_PAD_LINK_WAS_LINKED;
2616 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2617 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2618 gst_pad_link_get_name (result));
2620 GST_PAD_PEER (srcpad) = NULL;
2621 GST_PAD_PEER (sinkpad) = NULL;
2623 GST_OBJECT_UNLOCK (sinkpad);
2624 GST_OBJECT_UNLOCK (srcpad);
2632 * @srcpad: the source #GstPad to link.
2633 * @sinkpad: the sink #GstPad to link.
2635 * Links the source pad and the sink pad.
2637 * Returns: A result code indicating if the connection worked or
2643 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2645 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2649 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2651 GstPadTemplate **template_p;
2653 /* this function would need checks if it weren't static */
2655 GST_OBJECT_LOCK (pad);
2656 template_p = &pad->padtemplate;
2657 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2658 GST_OBJECT_UNLOCK (pad);
2661 gst_pad_template_pad_created (templ, pad);
2665 * gst_pad_get_pad_template:
2668 * Gets the template for @pad.
2670 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2671 * this pad was instantiated, or %NULL if this pad has no
2672 * template. Unref after usage.
2675 gst_pad_get_pad_template (GstPad * pad)
2677 GstPadTemplate *templ;
2679 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2681 templ = GST_PAD_PAD_TEMPLATE (pad);
2683 return (templ ? gst_object_ref (templ) : NULL);
2687 * gst_pad_has_current_caps:
2688 * @pad: a #GstPad to check
2690 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2692 * Returns: %TRUE when @pad has caps associated with it.
2695 gst_pad_has_current_caps (GstPad * pad)
2700 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2702 GST_OBJECT_LOCK (pad);
2703 caps = get_pad_caps (pad);
2704 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2705 "check current pad caps %" GST_PTR_FORMAT, caps);
2706 result = (caps != NULL);
2707 GST_OBJECT_UNLOCK (pad);
2713 * gst_pad_get_current_caps:
2714 * @pad: a #GstPad to get the current capabilities of.
2716 * Gets the capabilities currently configured on @pad with the last
2717 * #GST_EVENT_CAPS event.
2719 * Returns: (transfer full) (nullable): the current caps of the pad with
2720 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2723 gst_pad_get_current_caps (GstPad * pad)
2727 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2729 GST_OBJECT_LOCK (pad);
2730 if ((result = get_pad_caps (pad)))
2731 gst_caps_ref (result);
2732 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2733 "get current pad caps %" GST_PTR_FORMAT, result);
2734 GST_OBJECT_UNLOCK (pad);
2740 * gst_pad_get_pad_template_caps:
2741 * @pad: a #GstPad to get the template capabilities from.
2743 * Gets the capabilities for @pad's template.
2745 * Returns: (transfer full): the #GstCaps of this pad template.
2746 * Unref after usage.
2749 gst_pad_get_pad_template_caps (GstPad * pad)
2751 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2753 if (GST_PAD_PAD_TEMPLATE (pad))
2754 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2756 return gst_caps_ref (GST_CAPS_ANY);
2761 * @pad: a #GstPad to get the peer of.
2763 * Gets the peer of @pad. This function refs the peer pad so
2764 * you need to unref it after use.
2766 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2771 gst_pad_get_peer (GstPad * pad)
2775 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2777 GST_OBJECT_LOCK (pad);
2778 result = GST_PAD_PEER (pad);
2780 gst_object_ref (result);
2781 GST_OBJECT_UNLOCK (pad);
2787 * gst_pad_get_allowed_caps:
2790 * Gets the capabilities of the allowed media types that can flow through
2791 * @pad and its peer.
2793 * The allowed capabilities is calculated as the intersection of the results of
2794 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2795 * on the resulting caps.
2797 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2798 * pad link. Unref the caps when you no longer need it. This
2799 * function returns %NULL when @pad has no peer.
2804 gst_pad_get_allowed_caps (GstPad * pad)
2807 GstCaps *caps = NULL;
2810 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2812 GST_OBJECT_LOCK (pad);
2813 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2815 GST_OBJECT_UNLOCK (pad);
2817 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2819 mycaps = gst_pad_query_caps (pad, NULL);
2821 /* Query peer caps */
2822 query = gst_query_new_caps (mycaps);
2823 if (!gst_pad_peer_query (pad, query)) {
2824 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2828 gst_query_parse_caps_result (query, &caps);
2830 g_warn_if_fail (caps != NULL);
2833 gst_caps_ref (caps);
2835 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2839 gst_query_unref (query);
2840 gst_caps_unref (mycaps);
2846 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2847 GST_OBJECT_UNLOCK (pad);
2854 * gst_pad_iterate_internal_links_default:
2855 * @pad: the #GstPad to get the internal links of.
2856 * @parent: (allow-none): the parent of @pad or %NULL
2858 * Iterate the list of pads to which the given pad is linked to inside of
2859 * the parent element.
2860 * This is the default handler, and thus returns an iterator of all of the
2861 * pads inside the parent element with opposite direction.
2863 * The caller must free this iterator after use with gst_iterator_free().
2865 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2866 * has no parent. Unref each returned pad with gst_object_unref().
2869 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2876 GstElement *eparent;
2878 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2880 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2881 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2883 GST_OBJECT_LOCK (pad);
2884 eparent = GST_PAD_PARENT (pad);
2885 if (!eparent || !GST_IS_ELEMENT (eparent))
2888 gst_object_ref (eparent);
2889 GST_OBJECT_UNLOCK (pad);
2892 if (pad->direction == GST_PAD_SRC)
2893 padlist = &eparent->sinkpads;
2895 padlist = &eparent->srcpads;
2897 GST_DEBUG_OBJECT (pad, "Making iterator");
2899 cookie = &eparent->pads_cookie;
2901 lock = GST_OBJECT_GET_LOCK (eparent);
2903 res = gst_iterator_new_list (GST_TYPE_PAD,
2904 lock, cookie, padlist, (GObject *) owner, NULL);
2906 gst_object_unref (owner);
2913 GST_OBJECT_UNLOCK (pad);
2914 GST_DEBUG_OBJECT (pad, "no parent element");
2920 * gst_pad_iterate_internal_links:
2921 * @pad: the GstPad to get the internal links of.
2923 * Gets an iterator for the pads to which the given pad is linked to inside
2924 * of the parent element.
2926 * Each #GstPad element yielded by the iterator will have its refcount increased,
2927 * so unref after use.
2929 * Free-function: gst_iterator_free
2931 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2932 * or %NULL when the pad does not have an iterator function
2933 * configured. Use gst_iterator_free() after usage.
2936 gst_pad_iterate_internal_links (GstPad * pad)
2938 GstIterator *res = NULL;
2941 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2943 GST_OBJECT_LOCK (pad);
2944 ACQUIRE_PARENT (pad, parent, no_parent);
2945 GST_OBJECT_UNLOCK (pad);
2947 if (GST_PAD_ITERINTLINKFUNC (pad))
2948 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2950 RELEASE_PARENT (parent);
2957 GST_DEBUG_OBJECT (pad, "no parent");
2958 GST_OBJECT_UNLOCK (pad);
2966 * @forward: (scope call): a #GstPadForwardFunction
2967 * @user_data: user data passed to @forward
2969 * Calls @forward for all internally linked pads of @pad. This function deals with
2970 * dynamically changing internal pads and will make sure that the @forward
2971 * function is only called once for each pad.
2973 * When @forward returns %TRUE, no further pads will be processed.
2975 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2978 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2981 gboolean result = FALSE;
2983 gboolean done = FALSE;
2984 GValue item = { 0, };
2985 GList *pushed_pads = NULL;
2987 iter = gst_pad_iterate_internal_links (pad);
2993 switch (gst_iterator_next (iter, &item)) {
2994 case GST_ITERATOR_OK:
2998 intpad = g_value_get_object (&item);
3000 /* if already pushed, skip. FIXME, find something faster to tag pads */
3001 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3002 g_value_reset (&item);
3006 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3007 GST_DEBUG_PAD_NAME (intpad));
3008 done = result = forward (intpad, user_data);
3010 pushed_pads = g_list_prepend (pushed_pads, intpad);
3012 g_value_reset (&item);
3015 case GST_ITERATOR_RESYNC:
3016 /* We don't reset the result here because we don't push the event
3017 * again on pads that got the event already and because we need
3018 * to consider the result of the previous pushes */
3019 gst_iterator_resync (iter);
3021 case GST_ITERATOR_ERROR:
3022 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3025 case GST_ITERATOR_DONE:
3030 g_value_unset (&item);
3031 gst_iterator_free (iter);
3033 g_list_free (pushed_pads);
3043 gboolean dispatched;
3047 event_forward_func (GstPad * pad, EventData * data)
3049 /* for each pad we send to, we should ref the event; it's up
3050 * to downstream to unref again when handled. */
3051 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3052 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3054 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3056 data->dispatched = TRUE;
3063 * gst_pad_event_default:
3064 * @pad: a #GstPad to call the default event handler on.
3065 * @parent: (allow-none): the parent of @pad or %NULL
3066 * @event: (transfer full): the #GstEvent to handle.
3068 * Invokes the default event handler for the given pad.
3070 * The EOS event will pause the task associated with @pad before it is forwarded
3071 * to all internally linked pads,
3073 * The event is sent to all pads internally linked to @pad. This function
3074 * takes ownership of @event.
3076 * Returns: %TRUE if the event was sent successfully.
3079 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3081 gboolean result, forward = TRUE;
3083 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3084 g_return_val_if_fail (event != NULL, FALSE);
3086 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3089 switch (GST_EVENT_TYPE (event)) {
3090 case GST_EVENT_CAPS:
3091 forward = GST_PAD_IS_PROXY_CAPS (pad);
3102 data.dispatched = FALSE;
3103 data.result = FALSE;
3105 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3107 /* for sinkpads without a parent element or without internal links, nothing
3108 * will be dispatched but we still want to return TRUE. */
3109 if (data.dispatched)
3110 result = data.result;
3115 gst_event_unref (event);
3120 /* Default accept caps implementation just checks against
3121 * the allowed caps for the pad */
3123 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3125 /* get the caps and see if it intersects to something not empty */
3126 GstCaps *caps, *allowed = NULL;
3129 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3131 /* first forward the query to internally linked pads when we are dealing with
3133 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3134 result = gst_pad_proxy_query_accept_caps (pad, query);
3136 allowed = gst_pad_get_pad_template_caps (pad);
3141 gst_query_parse_accept_caps (query, &caps);
3143 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3144 allowed = gst_pad_get_pad_template_caps (pad);
3146 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3147 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3148 allowed = gst_pad_query_caps (pad, caps);
3153 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3154 GST_DEBUG_OBJECT (pad,
3155 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3157 result = gst_caps_can_intersect (caps, allowed);
3159 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3160 GST_PTR_FORMAT, allowed, caps);
3161 result = gst_caps_is_subset (caps, allowed);
3163 gst_caps_unref (allowed);
3165 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3168 gst_query_set_accept_caps_result (query, result);
3174 /* Default caps implementation */
3176 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3178 GstCaps *result = NULL, *filter;
3179 GstPadTemplate *templ;
3180 gboolean fixed_caps;
3182 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3185 /* first try to proxy if we must */
3186 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3187 if ((gst_pad_proxy_query_caps (pad, query))) {
3192 gst_query_parse_caps (query, &filter);
3194 /* no proxy or it failed, do default handling */
3195 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3197 GST_OBJECT_LOCK (pad);
3199 /* fixed caps, try the negotiated caps first */
3200 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3201 if ((result = get_pad_caps (pad)))
3202 goto filter_done_unlock;
3205 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3206 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3207 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3208 goto filter_done_unlock;
3212 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3213 "non-fixed pad caps: trying pad caps");
3214 /* non fixed caps, try the negotiated caps */
3215 if ((result = get_pad_caps (pad)))
3216 goto filter_done_unlock;
3219 /* this almost never happens */
3220 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3221 result = GST_CAPS_ANY;
3224 GST_OBJECT_UNLOCK (pad);
3226 /* run the filter on the result */
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3229 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3230 GST_PTR_FORMAT, result, result, filter, filter);
3231 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3232 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3235 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3236 "using caps %p %" GST_PTR_FORMAT, result, result);
3237 result = gst_caps_ref (result);
3239 gst_query_set_caps_result (query, result);
3240 gst_caps_unref (result);
3246 /* Default latency implementation */
3251 GstClockTime min, max;
3255 query_latency_default_fold (const GValue * item, GValue * ret,
3258 GstPad *pad = g_value_get_object (item), *peer;
3259 LatencyFoldData *fold_data = user_data;
3261 gboolean res = FALSE;
3263 query = gst_query_new_latency ();
3265 peer = gst_pad_get_peer (pad);
3267 res = gst_pad_peer_query (pad, query);
3269 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3274 GstClockTime min, max;
3276 gst_query_parse_latency (query, &live, &min, &max);
3278 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3279 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3281 /* FIXME : Why do we only take values into account if it's live ? */
3282 if (live || fold_data->count == 0) {
3283 if (min > fold_data->min)
3284 fold_data->min = min;
3286 if (fold_data->max == GST_CLOCK_TIME_NONE)
3287 fold_data->max = max;
3288 else if (max < fold_data->max)
3289 fold_data->max = max;
3291 fold_data->live = live;
3293 fold_data->count += 1;
3295 GST_DEBUG_OBJECT (pad, "latency query failed");
3296 g_value_set_boolean (ret, FALSE);
3299 gst_query_unref (query);
3301 gst_object_unref (peer);
3307 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3310 GstIteratorResult res;
3311 GValue ret = G_VALUE_INIT;
3313 LatencyFoldData fold_data;
3315 it = gst_pad_iterate_internal_links (pad);
3317 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3321 g_value_init (&ret, G_TYPE_BOOLEAN);
3324 fold_data.count = 0;
3325 fold_data.live = FALSE;
3327 fold_data.max = GST_CLOCK_TIME_NONE;
3329 g_value_set_boolean (&ret, TRUE);
3330 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3332 case GST_ITERATOR_OK:
3333 g_assert_not_reached ();
3335 case GST_ITERATOR_DONE:
3337 case GST_ITERATOR_ERROR:
3338 g_value_set_boolean (&ret, FALSE);
3340 case GST_ITERATOR_RESYNC:
3341 gst_iterator_resync (it);
3344 g_assert_not_reached ();
3347 gst_iterator_free (it);
3349 query_ret = g_value_get_boolean (&ret);
3351 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3352 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3353 fold_data.min, fold_data.max);
3355 if (fold_data.min > fold_data.max) {
3356 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3359 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3361 GST_LOG_OBJECT (pad, "latency query failed");
3371 gboolean dispatched;
3375 query_forward_func (GstPad * pad, QueryData * data)
3377 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3378 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3380 data->result |= gst_pad_peer_query (pad, data->query);
3382 data->dispatched = TRUE;
3384 /* stop on first successful reply */
3385 return data->result;
3389 * gst_pad_query_default:
3390 * @pad: a #GstPad to call the default query handler on.
3391 * @parent: (allow-none): the parent of @pad or %NULL
3392 * @query: (transfer none): the #GstQuery to handle.
3394 * Invokes the default query handler for the given pad.
3395 * The query is sent to all pads internally linked to @pad. Note that
3396 * if there are many possible sink pads that are internally linked to
3397 * @pad, only one will be sent the query.
3398 * Multi-sinkpad elements should implement custom query handlers.
3400 * Returns: %TRUE if the query was performed successfully.
3403 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3405 gboolean forward, ret = FALSE;
3407 switch (GST_QUERY_TYPE (query)) {
3408 case GST_QUERY_SCHEDULING:
3409 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3411 case GST_QUERY_ALLOCATION:
3412 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3414 case GST_QUERY_ACCEPT_CAPS:
3415 ret = gst_pad_query_accept_caps_default (pad, query);
3418 case GST_QUERY_CAPS:
3419 ret = gst_pad_query_caps_default (pad, query);
3422 case GST_QUERY_LATENCY:
3423 ret = gst_pad_query_latency_default (pad, query);
3426 case GST_QUERY_POSITION:
3427 case GST_QUERY_SEEKING:
3428 case GST_QUERY_FORMATS:
3429 case GST_QUERY_JITTER:
3430 case GST_QUERY_RATE:
3431 case GST_QUERY_CONVERT:
3437 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3438 query, GST_QUERY_TYPE_NAME (query));
3444 data.dispatched = FALSE;
3445 data.result = FALSE;
3447 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3449 if (data.dispatched) {
3452 /* nothing dispatched, assume drained */
3453 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3463 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3465 GstPad *pad = data->pad;
3466 GstPadProbeInfo *info = data->info;
3467 GstPadProbeType type, flags;
3468 GstPadProbeCallback callback;
3469 GstPadProbeReturn ret;
3470 gpointer original_data;
3472 /* if we have called this callback, do nothing */
3473 if (PROBE_COOKIE (hook) == data->cookie) {
3474 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3475 "hook %lu, cookie %u already called", hook->hook_id,
3476 PROBE_COOKIE (hook));
3480 PROBE_COOKIE (hook) = data->cookie;
3482 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3484 original_data = info->data;
3486 /* one of the scheduling types */
3487 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3490 if (G_UNLIKELY (data->handled)) {
3491 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3492 "probe previously returned HANDLED, not calling again");
3494 } else if (G_UNLIKELY (data->dropped)) {
3495 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3496 "probe previously returned DROPPED, not calling again");
3500 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3501 /* one of the data types for non-idle probes */
3502 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3503 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3505 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3506 /* one of the data types for non-idle probes */
3507 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3508 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3511 /* Type must have PULL or PUSH probe types */
3512 g_assert_not_reached ();
3515 /* one of the blocking types must match */
3516 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3517 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3519 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3520 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3522 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3523 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3524 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3527 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3528 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3529 PROBE_COOKIE (hook), flags);
3531 data->marshalled = TRUE;
3533 callback = (GstPadProbeCallback) hook->func;
3534 if (callback == NULL)
3537 info->id = hook->hook_id;
3539 GST_OBJECT_UNLOCK (pad);
3541 ret = callback (pad, info, hook->data);
3543 GST_OBJECT_LOCK (pad);
3545 if (original_data != NULL && info->data == NULL) {
3546 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3547 info->type = GST_PAD_PROBE_TYPE_INVALID;
3548 data->dropped = TRUE;
3552 case GST_PAD_PROBE_REMOVE:
3553 /* remove the probe */
3554 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3555 cleanup_hook (pad, hook);
3557 case GST_PAD_PROBE_DROP:
3558 /* need to drop the data, make sure other probes don't get called
3560 GST_DEBUG_OBJECT (pad, "asked to drop item");
3561 info->type = GST_PAD_PROBE_TYPE_INVALID;
3562 data->dropped = TRUE;
3564 case GST_PAD_PROBE_HANDLED:
3565 GST_DEBUG_OBJECT (pad, "probe handled data");
3566 data->handled = TRUE;
3568 case GST_PAD_PROBE_PASS:
3569 /* inform the pad block to let things pass */
3570 GST_DEBUG_OBJECT (pad, "asked to pass item");
3573 case GST_PAD_PROBE_OK:
3574 GST_DEBUG_OBJECT (pad, "probe returned OK");
3577 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3584 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3585 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3586 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3591 /* a probe that does not take or return any data */
3592 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3594 if (G_UNLIKELY (pad->num_probes)) { \
3595 GstFlowReturn pval = defaultval; \
3596 /* pass NULL as the data item */ \
3597 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3598 info.ABI.abi.flow_ret = defaultval; \
3599 ret = do_probe_callbacks (pad, &info, defaultval); \
3600 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3605 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3607 if (G_UNLIKELY (pad->num_probes)) { \
3608 /* pass the data item */ \
3609 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3610 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3611 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3612 /* store the possibly updated data item */ \
3613 data = GST_PAD_PROBE_INFO_DATA (&info); \
3614 /* if something went wrong, exit */ \
3615 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3616 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3617 ret = info.ABI.abi.flow_ret; \
3618 goto handle_label; \
3625 #define PROBE_PUSH(pad,mask,data,label) \
3626 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3627 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3628 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3629 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3630 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3632 static GstFlowReturn
3633 do_pad_idle_probe_wait (GstPad * pad)
3635 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3636 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3637 "waiting idle probe to be removed");
3638 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3639 GST_PAD_BLOCK_WAIT (pad);
3640 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3641 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3643 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3644 return GST_FLOW_FLUSHING;
3649 #define PROBE_TYPE_IS_SERIALIZED(i) \
3652 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3653 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3654 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3656 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3657 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3659 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3660 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3664 static GstFlowReturn
3665 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3666 GstFlowReturn defaultval)
3675 data.handled = FALSE;
3676 data.marshalled = FALSE;
3677 data.dropped = FALSE;
3678 data.cookie = ++pad->priv->probe_cookie;
3681 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3683 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3684 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3689 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3690 "do probes cookie %u", data.cookie);
3691 cookie = pad->priv->probe_list_cookie;
3693 g_hook_list_marshal (&pad->probes, TRUE,
3694 (GHookMarshaller) probe_hook_marshal, &data);
3696 /* if the list changed, call the new callbacks (they will not have their
3697 * cookie set to data.cookie */
3698 if (cookie != pad->priv->probe_list_cookie) {
3699 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3700 "probe list changed, restarting");
3704 /* the first item that dropped will stop the hooks and then we drop here */
3708 /* If one handler took care of it, let the the item pass */
3713 /* if no handler matched and we are blocking, let the item pass */
3714 if (!data.marshalled && is_block)
3717 /* At this point, all handlers returned either OK or PASS. If one handler
3718 * returned PASS, let the item pass */
3723 while (GST_PAD_IS_BLOCKED (pad)) {
3724 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3725 "we are blocked %d times", pad->num_blocked);
3727 /* we might have released the lock */
3728 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3731 /* now we block the streaming thread. It can be unlocked when we
3732 * deactivate the pad (which will also set the FLUSHING flag) or
3733 * when the pad is unblocked. A flushing event will also unblock
3734 * the pad after setting the FLUSHING flag. */
3735 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3736 "Waiting to be unblocked or set flushing");
3737 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3738 GST_PAD_BLOCK_WAIT (pad);
3739 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3740 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3742 /* if the list changed, call the new callbacks (they will not have their
3743 * cookie set to data.cookie */
3744 if (cookie != pad->priv->probe_list_cookie) {
3745 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3746 "probe list changed, restarting");
3750 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3760 GST_DEBUG_OBJECT (pad, "pad is flushing");
3761 return GST_FLOW_FLUSHING;
3765 GST_DEBUG_OBJECT (pad, "data is dropped");
3766 return GST_FLOW_CUSTOM_SUCCESS;
3770 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3771 GST_DEBUG_OBJECT (pad, "data is passed");
3776 GST_DEBUG_OBJECT (pad, "data was handled");
3777 return GST_FLOW_CUSTOM_SUCCESS_1;
3784 * gst_pad_get_offset:
3787 * Get the offset applied to the running time of @pad. @pad has to be a source
3790 * Returns: the offset.
3793 gst_pad_get_offset (GstPad * pad)
3797 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3799 GST_OBJECT_LOCK (pad);
3800 result = pad->offset;
3801 GST_OBJECT_UNLOCK (pad);
3807 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3809 ev->received = FALSE;
3814 * gst_pad_set_offset:
3816 * @offset: the offset
3818 * Set the offset that will be applied to the running time of @pad.
3821 gst_pad_set_offset (GstPad * pad, gint64 offset)
3823 g_return_if_fail (GST_IS_PAD (pad));
3825 GST_OBJECT_LOCK (pad);
3826 /* if nothing changed, do nothing */
3827 if (pad->offset == offset)
3830 pad->offset = offset;
3831 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3832 GST_STIME_ARGS (offset));
3834 /* resend all sticky events with updated offset on next buffer push */
3835 events_foreach (pad, mark_event_not_received, NULL);
3836 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3839 GST_OBJECT_UNLOCK (pad);
3846 /* If TRUE and ret is not OK this means
3847 * that pushing the EOS event failed
3851 /* If called for an event this is
3852 * the event that would be pushed
3853 * next. Don't forward sticky events
3854 * that would come after that */
3858 /* should be called with pad LOCK */
3860 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3862 PushStickyData *data = user_data;
3863 GstEvent *event = ev->event;
3866 GST_DEBUG_OBJECT (pad, "event %s was already received",
3867 GST_EVENT_TYPE_NAME (event));
3871 /* If we're called because of an sticky event, only forward
3872 * events that would come before this new event and the
3874 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3875 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3876 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3877 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3879 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3880 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3881 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3882 data->ret = GST_FLOW_OK;
3885 switch (data->ret) {
3887 ev->received = TRUE;
3888 GST_DEBUG_OBJECT (pad, "event %s marked received",
3889 GST_EVENT_TYPE_NAME (event));
3891 case GST_FLOW_CUSTOM_SUCCESS:
3892 /* we can't assume the event is received when it was dropped */
3893 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3894 GST_EVENT_TYPE_NAME (event));
3895 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3896 data->ret = GST_FLOW_OK;
3898 case GST_FLOW_CUSTOM_SUCCESS_1:
3899 /* event was ignored and should be sent later */
3900 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3901 GST_EVENT_TYPE_NAME (event));
3902 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3903 data->ret = GST_FLOW_OK;
3905 case GST_FLOW_NOT_LINKED:
3906 /* not linked is not a problem, we are sticky so the event will be
3907 * rescheduled to be sent later on re-link, but only for non-EOS events */
3908 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3909 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3910 data->ret = GST_FLOW_OK;
3911 ev->received = TRUE;
3915 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3916 gst_flow_get_name (data->ret));
3917 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3921 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3922 data->was_eos = TRUE;
3924 return data->ret == GST_FLOW_OK;
3927 /* check sticky events and push them when needed. should be called
3929 static inline GstFlowReturn
3930 check_sticky (GstPad * pad, GstEvent * event)
3932 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3934 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3935 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3937 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3938 events_foreach (pad, push_sticky, &data);
3940 /* If there's an EOS event we must push it downstream
3941 * even if sending a previous sticky event failed.
3942 * Otherwise the pipeline might wait forever for EOS.
3944 * Only do this if pushing another event than the EOS
3947 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3948 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3950 if (ev && !ev->received) {
3951 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3952 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3953 /* the event could have been dropped. Because this can only
3954 * happen if the user asked for it, it's not an error */
3955 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3956 data.ret = GST_FLOW_OK;
3966 * @pad: a #GstPad to invoke the default query on.
3967 * @query: (transfer none): the #GstQuery to perform.
3969 * Dispatches a query to a pad. The query should have been allocated by the
3970 * caller via one of the type-specific allocation functions. The element that
3971 * the pad belongs to is responsible for filling the query with an appropriate
3972 * response, which should then be parsed with a type-specific query parsing
3975 * Again, the caller is responsible for both the allocation and deallocation of
3976 * the query structure.
3978 * Please also note that some queries might need a running pipeline to work.
3980 * Returns: %TRUE if the query could be performed.
3983 gst_pad_query (GstPad * pad, GstQuery * query)
3986 gboolean res, serialized;
3987 GstPadQueryFunction func;
3988 GstPadProbeType type;
3991 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3992 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3994 if (GST_PAD_IS_SRC (pad)) {
3995 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3996 goto wrong_direction;
3997 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3998 } else if (GST_PAD_IS_SINK (pad)) {
3999 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4000 goto wrong_direction;
4001 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4003 goto unknown_direction;
4005 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4006 GST_QUERY_TYPE_NAME (query));
4007 GST_TRACER_PAD_QUERY_PRE (pad, query);
4009 serialized = GST_QUERY_IS_SERIALIZED (query);
4010 if (G_UNLIKELY (serialized))
4011 GST_PAD_STREAM_LOCK (pad);
4013 GST_OBJECT_LOCK (pad);
4014 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4015 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4016 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4018 ACQUIRE_PARENT (pad, parent, no_parent);
4019 GST_OBJECT_UNLOCK (pad);
4021 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4024 res = func (pad, parent, query);
4026 RELEASE_PARENT (parent);
4028 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4029 GST_QUERY_TYPE_NAME (query), res);
4030 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4035 GST_OBJECT_LOCK (pad);
4036 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4037 GST_OBJECT_UNLOCK (pad);
4039 if (G_UNLIKELY (serialized))
4040 GST_PAD_STREAM_UNLOCK (pad);
4047 g_warning ("pad %s:%s query %s in wrong direction",
4048 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4053 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4058 GST_DEBUG_OBJECT (pad, "had no parent");
4059 GST_OBJECT_UNLOCK (pad);
4060 if (G_UNLIKELY (serialized))
4061 GST_PAD_STREAM_UNLOCK (pad);
4066 GST_DEBUG_OBJECT (pad, "had no query function");
4067 RELEASE_PARENT (parent);
4068 if (G_UNLIKELY (serialized))
4069 GST_PAD_STREAM_UNLOCK (pad);
4074 GST_DEBUG_OBJECT (pad, "query failed");
4075 if (G_UNLIKELY (serialized))
4076 GST_PAD_STREAM_UNLOCK (pad);
4081 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4082 GST_OBJECT_UNLOCK (pad);
4083 if (G_UNLIKELY (serialized))
4084 GST_PAD_STREAM_UNLOCK (pad);
4086 /* if a probe dropped without handling, we don't sent it further but assume
4087 * that the probe did not answer the query and return FALSE */
4088 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4098 * gst_pad_peer_query:
4099 * @pad: a #GstPad to invoke the peer query on.
4100 * @query: (transfer none): the #GstQuery to perform.
4102 * Performs gst_pad_query() on the peer of @pad.
4104 * The caller is responsible for both the allocation and deallocation of
4105 * the query structure.
4107 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4108 * if @pad has no peer.
4111 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4114 GstPadProbeType type;
4115 gboolean res, serialized;
4118 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4119 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4121 if (GST_PAD_IS_SRC (pad)) {
4122 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4123 goto wrong_direction;
4124 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4125 } else if (GST_PAD_IS_SINK (pad)) {
4126 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4127 goto wrong_direction;
4128 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4130 goto unknown_direction;
4132 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4133 GST_QUERY_TYPE_NAME (query));
4135 serialized = GST_QUERY_IS_SERIALIZED (query);
4137 GST_OBJECT_LOCK (pad);
4138 if (GST_PAD_IS_SRC (pad) && serialized) {
4139 /* all serialized queries on the srcpad trigger push of
4141 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4145 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4146 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4147 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4149 peerpad = GST_PAD_PEER (pad);
4150 if (G_UNLIKELY (peerpad == NULL))
4153 gst_object_ref (peerpad);
4154 GST_OBJECT_UNLOCK (pad);
4156 res = gst_pad_query (peerpad, query);
4158 gst_object_unref (peerpad);
4163 GST_OBJECT_LOCK (pad);
4164 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4165 GST_OBJECT_UNLOCK (pad);
4172 g_warning ("pad %s:%s query %s in wrong direction",
4173 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4178 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4183 GST_WARNING_OBJECT (pad, "could not send sticky events");
4184 GST_OBJECT_UNLOCK (pad);
4189 GST_INFO_OBJECT (pad, "pad has no peer");
4190 GST_OBJECT_UNLOCK (pad);
4195 GST_DEBUG_OBJECT (pad, "query failed");
4200 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4201 GST_OBJECT_UNLOCK (pad);
4203 /* if a probe dropped without handling, we don't sent it further but
4204 * assume that the probe did not answer the query and return FALSE */
4205 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4214 /**********************************************************************
4215 * Data passing functions
4218 /* this is the chain function that does not perform the additional argument
4219 * checking for that little extra speed.
4221 static inline GstFlowReturn
4222 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4226 gboolean handled = FALSE;
4228 GST_PAD_STREAM_LOCK (pad);
4230 GST_OBJECT_LOCK (pad);
4231 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4234 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4237 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4240 #ifdef GST_ENABLE_EXTRA_CHECKS
4241 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4242 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4244 ":%s:<%s:%s> Got data flow before stream-start event",
4245 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4247 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4249 ":%s:<%s:%s> Got data flow before segment event",
4250 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4252 pad->priv->last_cookie = pad->priv->events_cookie;
4256 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4259 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4261 ACQUIRE_PARENT (pad, parent, no_parent);
4262 GST_OBJECT_UNLOCK (pad);
4264 /* NOTE: we read the chainfunc unlocked.
4265 * we cannot hold the lock for the pad so we might send
4266 * the data to the wrong function. This is not really a
4267 * problem since functions are assigned at creation time
4268 * and don't change that often... */
4269 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4270 GstPadChainFunction chainfunc;
4272 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4275 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4276 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4277 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4279 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4281 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4282 "called chainfunction &%s with buffer %p, returned %s",
4283 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4285 GstPadChainListFunction chainlistfunc;
4287 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4290 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4291 "calling chainlistfunction &%s",
4292 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4294 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4296 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4297 "called chainlistfunction &%s, returned %s",
4298 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4301 RELEASE_PARENT (parent);
4303 GST_PAD_STREAM_UNLOCK (pad);
4310 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4311 "chaining, but pad was flushing");
4312 GST_OBJECT_UNLOCK (pad);
4313 GST_PAD_STREAM_UNLOCK (pad);
4314 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4315 return GST_FLOW_FLUSHING;
4319 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4320 GST_OBJECT_UNLOCK (pad);
4321 GST_PAD_STREAM_UNLOCK (pad);
4322 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4323 return GST_FLOW_EOS;
4327 g_critical ("chain on pad %s:%s but it was not in push mode",
4328 GST_DEBUG_PAD_NAME (pad));
4329 GST_OBJECT_UNLOCK (pad);
4330 GST_PAD_STREAM_UNLOCK (pad);
4331 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4332 return GST_FLOW_ERROR;
4339 GST_OBJECT_UNLOCK (pad);
4340 GST_PAD_STREAM_UNLOCK (pad);
4341 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4343 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4346 case GST_FLOW_CUSTOM_SUCCESS:
4347 case GST_FLOW_CUSTOM_SUCCESS_1:
4348 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4352 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4359 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4360 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4361 GST_OBJECT_UNLOCK (pad);
4362 GST_PAD_STREAM_UNLOCK (pad);
4363 return GST_FLOW_FLUSHING;
4367 RELEASE_PARENT (parent);
4368 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4369 g_critical ("chain on pad %s:%s but it has no chainfunction",
4370 GST_DEBUG_PAD_NAME (pad));
4371 GST_PAD_STREAM_UNLOCK (pad);
4372 return GST_FLOW_NOT_SUPPORTED;
4378 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4379 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4382 * Chain a buffer to @pad.
4384 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4386 * If the buffer type is not acceptable for @pad (as negotiated with a
4387 * preceding GST_EVENT_CAPS event), this function returns
4388 * #GST_FLOW_NOT_NEGOTIATED.
4390 * The function proceeds calling the chain function installed on @pad (see
4391 * gst_pad_set_chain_function()) and the return value of that function is
4392 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4395 * In all cases, success or failure, the caller loses its reference to @buffer
4396 * after calling this function.
4398 * Returns: a #GstFlowReturn from the pad.
4403 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4405 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4406 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4407 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4409 return gst_pad_chain_data_unchecked (pad,
4410 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4413 static GstFlowReturn
4414 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4415 GstBufferList * list)
4421 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4423 len = gst_buffer_list_length (list);
4426 for (i = 0; i < len; i++) {
4427 buffer = gst_buffer_list_get (list, i);
4429 gst_pad_chain_data_unchecked (pad,
4430 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4431 gst_buffer_ref (buffer));
4432 if (ret != GST_FLOW_OK)
4435 gst_buffer_list_unref (list);
4441 * gst_pad_chain_list:
4442 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4443 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4446 * Chain a bufferlist to @pad.
4448 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4450 * If @pad was not negotiated properly with a CAPS event, this function
4451 * returns #GST_FLOW_NOT_NEGOTIATED.
4453 * The function proceeds calling the chainlist function installed on @pad (see
4454 * gst_pad_set_chain_list_function()) and the return value of that function is
4455 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4456 * chainlist function.
4458 * In all cases, success or failure, the caller loses its reference to @list
4459 * after calling this function.
4463 * Returns: a #GstFlowReturn from the pad.
4466 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4468 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4469 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4470 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4472 return gst_pad_chain_data_unchecked (pad,
4473 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4476 static GstFlowReturn
4477 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4481 gboolean handled = FALSE;
4483 GST_OBJECT_LOCK (pad);
4484 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4487 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4490 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4493 #ifdef GST_ENABLE_EXTRA_CHECKS
4494 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4495 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4497 ":%s:<%s:%s> Got data flow before stream-start event",
4498 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4500 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4502 ":%s:<%s:%s> Got data flow before segment event",
4503 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4505 pad->priv->last_cookie = pad->priv->events_cookie;
4509 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4512 /* do block probes */
4513 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4516 /* recheck sticky events because the probe might have cause a relink */
4517 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4520 /* do post-blocking probes */
4521 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4523 /* recheck sticky events because the probe might have cause a relink */
4524 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4527 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4530 /* take ref to peer pad before releasing the lock */
4531 gst_object_ref (peer);
4533 GST_OBJECT_UNLOCK (pad);
4535 ret = gst_pad_chain_data_unchecked (peer, type, data);
4538 gst_object_unref (peer);
4540 GST_OBJECT_LOCK (pad);
4541 pad->ABI.abi.last_flowret = ret;
4543 if (pad->priv->using == 0) {
4544 /* pad is not active anymore, trigger idle callbacks */
4545 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4546 probe_stopped, ret);
4548 GST_OBJECT_UNLOCK (pad);
4552 /* ERROR recovery here */
4556 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4557 "pushing, but pad was flushing");
4558 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4559 GST_OBJECT_UNLOCK (pad);
4560 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4561 return GST_FLOW_FLUSHING;
4565 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4566 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4567 GST_OBJECT_UNLOCK (pad);
4568 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4569 return GST_FLOW_EOS;
4573 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4574 GST_DEBUG_PAD_NAME (pad));
4575 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4576 GST_OBJECT_UNLOCK (pad);
4577 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4578 return GST_FLOW_ERROR;
4582 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4583 "error pushing events, return %s", gst_flow_get_name (ret));
4584 pad->ABI.abi.last_flowret = ret;
4585 GST_OBJECT_UNLOCK (pad);
4586 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4594 GST_OBJECT_UNLOCK (pad);
4595 if (data != NULL && !handled)
4596 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4599 case GST_FLOW_CUSTOM_SUCCESS:
4600 case GST_FLOW_CUSTOM_SUCCESS_1:
4601 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4605 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4608 pad->ABI.abi.last_flowret = ret;
4613 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4614 "pushing, but it was not linked");
4615 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4616 GST_OBJECT_UNLOCK (pad);
4617 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4618 return GST_FLOW_NOT_LINKED;
4624 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4625 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4628 * Pushes a buffer to the peer of @pad.
4630 * This function will call installed block probes before triggering any
4631 * installed data probes.
4633 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4634 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4637 * In all cases, success or failure, the caller loses its reference to @buffer
4638 * after calling this function.
4640 * Returns: a #GstFlowReturn from the peer pad.
4645 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4649 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4650 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4651 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4653 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4654 res = gst_pad_push_data (pad,
4655 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4656 GST_TRACER_PAD_PUSH_POST (pad, res);
4661 * gst_pad_push_list:
4662 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4663 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4666 * Pushes a buffer list to the peer of @pad.
4668 * This function will call installed block probes before triggering any
4669 * installed data probes.
4671 * The function proceeds calling the chain function on the peer pad and returns
4672 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4673 * be returned. If the peer pad does not have any installed chainlist function
4674 * every group buffer of the list will be merged into a normal #GstBuffer and
4675 * chained via gst_pad_chain().
4677 * In all cases, success or failure, the caller loses its reference to @list
4678 * after calling this function.
4680 * Returns: a #GstFlowReturn from the peer pad.
4685 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4689 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4690 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4691 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4693 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4694 res = gst_pad_push_data (pad,
4695 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4696 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4700 static GstFlowReturn
4701 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4702 GstBuffer ** buffer)
4705 GstPadGetRangeFunction getrangefunc;
4709 GST_PAD_STREAM_LOCK (pad);
4711 GST_OBJECT_LOCK (pad);
4712 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4715 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4718 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4723 /* when one of the probes returns DROPPED, probe_stopped will be called
4724 * and we skip calling the getrange function, res_buf should then contain a
4725 * valid result buffer */
4726 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4727 res_buf, offset, size, probe_stopped);
4729 /* recheck sticky events because the probe might have cause a relink */
4730 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4733 ACQUIRE_PARENT (pad, parent, no_parent);
4734 GST_OBJECT_UNLOCK (pad);
4736 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4739 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4740 "calling getrangefunc %s, offset %"
4741 G_GUINT64_FORMAT ", size %u",
4742 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4744 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4746 RELEASE_PARENT (parent);
4748 GST_OBJECT_LOCK (pad);
4749 if (G_UNLIKELY (ret != GST_FLOW_OK))
4750 goto get_range_failed;
4752 /* can only fire the signal if we have a valid buffer */
4754 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4755 res_buf, offset, size, probe_stopped_unref);
4756 pad->ABI.abi.last_flowret = ret;
4757 GST_OBJECT_UNLOCK (pad);
4759 GST_PAD_STREAM_UNLOCK (pad);
4768 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4769 "getrange, but pad was flushing");
4770 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4771 GST_OBJECT_UNLOCK (pad);
4772 GST_PAD_STREAM_UNLOCK (pad);
4773 return GST_FLOW_FLUSHING;
4777 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4778 GST_DEBUG_PAD_NAME (pad));
4779 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4780 GST_OBJECT_UNLOCK (pad);
4781 GST_PAD_STREAM_UNLOCK (pad);
4782 return GST_FLOW_ERROR;
4786 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4787 pad->ABI.abi.last_flowret = ret;
4788 GST_OBJECT_UNLOCK (pad);
4789 GST_PAD_STREAM_UNLOCK (pad);
4794 GST_DEBUG_OBJECT (pad, "no parent");
4795 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4796 GST_OBJECT_UNLOCK (pad);
4797 GST_PAD_STREAM_UNLOCK (pad);
4798 return GST_FLOW_FLUSHING;
4802 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4803 GST_DEBUG_PAD_NAME (pad));
4804 RELEASE_PARENT (parent);
4805 GST_PAD_STREAM_UNLOCK (pad);
4806 return GST_FLOW_NOT_SUPPORTED;
4810 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4811 "probe returned %s", gst_flow_get_name (ret));
4812 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4814 /* the probe filled the buffer and asks us to not call the getrange
4815 * anymore, we continue with the post probes then. */
4816 GST_DEBUG_OBJECT (pad, "handled buffer");
4820 /* no buffer, we are EOS */
4821 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4825 pad->ABI.abi.last_flowret = ret;
4826 GST_OBJECT_UNLOCK (pad);
4827 GST_PAD_STREAM_UNLOCK (pad);
4831 probe_stopped_unref:
4833 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4834 "probe returned %s", gst_flow_get_name (ret));
4835 /* if we drop here, it signals EOS */
4836 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4838 pad->ABI.abi.last_flowret = ret;
4839 GST_OBJECT_UNLOCK (pad);
4840 GST_PAD_STREAM_UNLOCK (pad);
4841 if (*buffer == NULL)
4842 gst_buffer_unref (res_buf);
4847 pad->ABI.abi.last_flowret = ret;
4848 GST_OBJECT_UNLOCK (pad);
4849 GST_PAD_STREAM_UNLOCK (pad);
4850 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4851 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4852 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4858 * gst_pad_get_range:
4859 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4860 * @offset: The start offset of the buffer
4861 * @size: The length of the buffer
4862 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4863 * returns #GST_FLOW_ERROR if %NULL.
4865 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4866 * immediately and @buffer is %NULL.
4868 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4869 * description of a getrange function. If @pad has no getrange function
4870 * installed (see gst_pad_set_getrange_function()) this function returns
4871 * #GST_FLOW_NOT_SUPPORTED.
4873 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4874 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4875 * must be freed with gst_buffer_unref() after usage.
4877 * When @buffer points to a variable that points to a valid #GstBuffer, the
4878 * buffer will be filled with the result data when this function returns
4879 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4880 * @size bytes will be filled in the result buffer and its size will be updated
4883 * Note that less than @size bytes can be returned in @buffer when, for example,
4884 * an EOS condition is near or when @buffer is not large enough to hold @size
4885 * bytes. The caller should check the result buffer size to get the result size.
4887 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4888 * will be unchanged.
4890 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4892 * Returns: a #GstFlowReturn from the pad.
4897 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4898 GstBuffer ** buffer)
4900 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4901 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4902 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4903 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4904 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4906 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4910 * gst_pad_pull_range:
4911 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4912 * @offset: The start offset of the buffer
4913 * @size: The length of the buffer
4914 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4915 * GST_FLOW_ERROR if %NULL.
4917 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4919 * This function will first trigger the pad block signal if it was
4922 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4923 * function returns the result of gst_pad_get_range() on the peer pad.
4924 * See gst_pad_get_range() for a list of return values and for the
4925 * semantics of the arguments of this function.
4927 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4928 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4929 * must be freed with gst_buffer_unref() after usage. When this function
4930 * returns any other result value, @buffer will still point to %NULL.
4932 * When @buffer points to a variable that points to a valid #GstBuffer, the
4933 * buffer will be filled with the result data when this function returns
4934 * #GST_FLOW_OK. When this function returns any other result value,
4935 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4936 * @size bytes will be filled in the result buffer and its size will be updated
4939 * Note that less than @size bytes can be returned in @buffer when, for example,
4940 * an EOS condition is near or when @buffer is not large enough to hold @size
4941 * bytes. The caller should check the result buffer size to get the result size.
4943 * Returns: a #GstFlowReturn from the peer pad.
4948 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4949 GstBuffer ** buffer)
4955 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4956 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4957 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4958 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4959 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4961 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4963 GST_OBJECT_LOCK (pad);
4964 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4967 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4972 /* when one of the probes returns DROPPED, probe_stopped will be
4973 * called and we skip calling the peer getrange function. *buffer should then
4974 * contain a valid buffer */
4975 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4976 res_buf, offset, size, probe_stopped);
4978 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4981 gst_object_ref (peer);
4983 GST_OBJECT_UNLOCK (pad);
4985 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4987 gst_object_unref (peer);
4989 GST_OBJECT_LOCK (pad);
4991 pad->ABI.abi.last_flowret = ret;
4992 if (pad->priv->using == 0) {
4993 /* pad is not active anymore, trigger idle callbacks */
4994 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4995 probe_stopped_unref, ret);
4998 if (G_UNLIKELY (ret != GST_FLOW_OK))
4999 goto pull_range_failed;
5002 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5003 res_buf, offset, size, probe_stopped_unref);
5005 GST_OBJECT_UNLOCK (pad);
5009 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5012 /* ERROR recovery here */
5015 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5016 "pullrange, but pad was flushing");
5017 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5018 GST_OBJECT_UNLOCK (pad);
5019 ret = GST_FLOW_FLUSHING;
5024 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5025 GST_DEBUG_PAD_NAME (pad));
5026 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5027 GST_OBJECT_UNLOCK (pad);
5028 ret = GST_FLOW_ERROR;
5033 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5034 gst_flow_get_name (ret));
5035 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5037 /* the probe filled the buffer and asks us to not forward to the peer
5038 * anymore, we continue with the post probes then */
5039 GST_DEBUG_OBJECT (pad, "handled buffer");
5043 /* no buffer, we are EOS then */
5044 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5048 pad->ABI.abi.last_flowret = ret;
5049 GST_OBJECT_UNLOCK (pad);
5054 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5055 "pulling range, but it was not linked");
5056 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5057 GST_OBJECT_UNLOCK (pad);
5058 ret = GST_FLOW_NOT_LINKED;
5063 pad->ABI.abi.last_flowret = ret;
5064 GST_OBJECT_UNLOCK (pad);
5065 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5066 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5067 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5070 probe_stopped_unref:
5072 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5073 "post probe returned %s", gst_flow_get_name (ret));
5075 /* if we drop here, it signals EOS */
5076 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5079 pad->ABI.abi.last_flowret = ret;
5080 GST_OBJECT_UNLOCK (pad);
5082 if (*buffer == NULL)
5083 gst_buffer_unref (res_buf);
5087 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5091 /* must be called with pad object lock */
5092 static GstFlowReturn
5093 store_sticky_event (GstPad * pad, GstEvent * event)
5098 gboolean res = FALSE;
5099 const gchar *name = NULL;
5100 gboolean insert = TRUE;
5102 type = GST_EVENT_TYPE (event);
5104 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5105 * otherwise they can be dropped and nothing would ever resend them.
5106 * Only do that for activated pads though, everything else is a bug!
5108 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5109 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5110 || type == GST_EVENT_EOS))))
5113 /* Unset the EOS flag when received STREAM_START event, so pad can
5114 * store sticky event and then push it later */
5115 if (type == GST_EVENT_STREAM_START) {
5116 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5117 remove_event_by_type (pad, GST_EVENT_EOS);
5118 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5119 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5122 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5125 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5126 name = gst_structure_get_name (gst_event_get_structure (event));
5128 events = pad->priv->events;
5131 for (i = 0; i < len; i++) {
5132 PadEvent *ev = &g_array_index (events, PadEvent, i);
5134 if (ev->event == NULL)
5137 if (type == GST_EVENT_TYPE (ev->event)) {
5138 /* matching types, check matching name if needed */
5139 if (name && !gst_event_has_name (ev->event, name))
5143 if ((res = gst_event_replace (&ev->event, event)))
5144 ev->received = FALSE;
5150 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5151 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5152 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5153 * storing the sticky ordered we can check that this is respected. */
5154 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5155 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5157 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5158 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5159 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5160 gst_event_type_get_name (type));
5166 ev.event = gst_event_ref (event);
5167 ev.received = FALSE;
5168 g_array_insert_val (events, i, ev);
5173 pad->priv->events_cookie++;
5174 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5176 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5178 switch (GST_EVENT_TYPE (event)) {
5179 case GST_EVENT_CAPS:
5180 GST_OBJECT_UNLOCK (pad);
5182 GST_DEBUG_OBJECT (pad, "notify caps");
5183 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5185 GST_OBJECT_LOCK (pad);
5191 if (type == GST_EVENT_EOS) {
5192 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5193 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5196 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5201 GST_DEBUG_OBJECT (pad, "pad is flushing");
5202 return GST_FLOW_FLUSHING;
5206 GST_DEBUG_OBJECT (pad, "pad is EOS");
5207 return GST_FLOW_EOS;
5212 * gst_pad_store_sticky_event:
5214 * @event: (transfer none): a #GstEvent
5216 * Store the sticky @event on @pad
5218 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5219 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5224 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5228 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5229 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5231 GST_OBJECT_LOCK (pad);
5232 ret = store_sticky_event (pad, event);
5233 GST_OBJECT_UNLOCK (pad);
5239 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5241 PushStickyData *data = user_data;
5243 /* Forward all sticky events before our current one that are pending */
5244 if (ev->event != data->event
5245 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5246 return push_sticky (pad, ev, data);
5251 /* should be called with pad LOCK */
5252 static GstFlowReturn
5253 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5254 GstPadProbeType type)
5258 GstEventType event_type;
5260 /* pass the adjusted event on. We need to do this even if
5261 * there is no peer pad because of the probes. */
5262 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5264 /* Two checks to be made:
5265 * . (un)set the FLUSHING flag for flushing events,
5266 * . handle pad blocking */
5267 event_type = GST_EVENT_TYPE (event);
5268 switch (event_type) {
5269 case GST_EVENT_FLUSH_START:
5270 GST_PAD_SET_FLUSHING (pad);
5272 GST_PAD_BLOCK_BROADCAST (pad);
5273 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5275 case GST_EVENT_FLUSH_STOP:
5276 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5279 GST_PAD_UNSET_FLUSHING (pad);
5281 /* Remove sticky EOS events */
5282 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5283 remove_event_by_type (pad, GST_EVENT_EOS);
5284 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5285 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5286 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5287 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5289 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5293 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5296 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5297 * checked already or this is called as part of pushing sticky events,
5298 * in which case we still want to forward the EOS event downstream.
5301 switch (GST_EVENT_TYPE (event)) {
5302 case GST_EVENT_RECONFIGURE:
5303 if (GST_PAD_IS_SINK (pad))
5304 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5309 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5310 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5311 /* recheck sticky events because the probe might have cause a relink */
5312 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5313 && (GST_EVENT_IS_SERIALIZED (event)
5314 || GST_EVENT_IS_STICKY (event))) {
5315 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5316 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5318 /* Push all sticky events before our current one
5319 * that have changed */
5320 events_foreach (pad, sticky_changed, &data);
5326 /* send probes after modifying the events above */
5327 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5329 /* recheck sticky events because the probe might have cause a relink */
5330 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5331 && (GST_EVENT_IS_SERIALIZED (event)
5332 || GST_EVENT_IS_STICKY (event))) {
5333 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5334 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5336 /* Push all sticky events before our current one
5337 * that have changed */
5338 events_foreach (pad, sticky_changed, &data);
5341 /* now check the peer pad */
5342 peerpad = GST_PAD_PEER (pad);
5343 if (peerpad == NULL)
5346 gst_object_ref (peerpad);
5348 GST_OBJECT_UNLOCK (pad);
5350 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5351 event, gst_event_type_get_name (event_type), peerpad);
5353 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5355 /* Note: we gave away ownership of the event at this point but we can still
5356 * print the old pointer */
5357 GST_LOG_OBJECT (pad,
5358 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5359 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5361 gst_object_unref (peerpad);
5363 GST_OBJECT_LOCK (pad);
5365 if (pad->priv->using == 0) {
5366 /* pad is not active anymore, trigger idle callbacks */
5367 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5368 idle_probe_stopped, ret);
5372 /* ERROR handling */
5375 GST_DEBUG_OBJECT (pad, "We're flushing");
5376 gst_event_unref (event);
5377 return GST_FLOW_FLUSHING;
5381 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5382 gst_event_unref (event);
5383 return GST_FLOW_FLUSHING;
5387 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5388 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5389 gst_event_unref (event);
5392 case GST_FLOW_CUSTOM_SUCCESS_1:
5393 GST_DEBUG_OBJECT (pad, "handled event");
5395 case GST_FLOW_CUSTOM_SUCCESS:
5396 GST_DEBUG_OBJECT (pad, "dropped event");
5399 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5406 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5407 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5408 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5409 gst_event_unref (event);
5411 /* unlinked pads should not influence latency configuration */
5412 if (event_type == GST_EVENT_LATENCY)
5415 return GST_FLOW_NOT_LINKED;
5419 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5425 * gst_pad_push_event:
5426 * @pad: a #GstPad to push the event to.
5427 * @event: (transfer full): the #GstEvent to send to the pad.
5429 * Sends the event to the peer of the given pad. This function is
5430 * mainly used by elements to send events to their peer
5433 * This function takes ownership of the provided event so you should
5434 * gst_event_ref() it if you want to reuse the event after this call.
5436 * Returns: %TRUE if the event was handled.
5441 gst_pad_push_event (GstPad * pad, GstEvent * event)
5443 gboolean res = FALSE;
5444 GstPadProbeType type;
5445 gboolean sticky, serialized;
5447 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5448 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5450 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5452 if (GST_PAD_IS_SRC (pad)) {
5453 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5454 goto wrong_direction;
5455 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5456 } else if (GST_PAD_IS_SINK (pad)) {
5457 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5458 goto wrong_direction;
5459 /* events pushed on sinkpad never are sticky */
5460 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5462 goto unknown_direction;
5464 GST_OBJECT_LOCK (pad);
5465 sticky = GST_EVENT_IS_STICKY (event);
5466 serialized = GST_EVENT_IS_SERIALIZED (event);
5469 /* srcpad sticky events are stored immediately, the received flag is set
5470 * to FALSE and will be set to TRUE when we can successfully push the
5471 * event to the peer pad */
5472 switch (store_sticky_event (pad, event)) {
5473 case GST_FLOW_FLUSHING:
5481 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5482 /* all serialized or sticky events on the srcpad trigger push of
5484 res = (check_sticky (pad, event) == GST_FLOW_OK);
5489 /* other events are pushed right away */
5490 ret = gst_pad_push_event_unchecked (pad, event, type);
5491 /* dropped events by a probe are not an error */
5492 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5493 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5495 /* Errors in sticky event pushing are no problem and ignored here
5496 * as they will cause more meaningful errors during data flow.
5497 * For EOS events, that are not followed by data flow, we still
5498 * return FALSE here though.
5500 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5502 gst_event_unref (event);
5504 GST_OBJECT_UNLOCK (pad);
5506 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5509 /* ERROR handling */
5512 g_warning ("pad %s:%s pushing %s event in wrong direction",
5513 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5514 gst_event_unref (event);
5519 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5520 gst_event_unref (event);
5525 GST_DEBUG_OBJECT (pad, "We're flushing");
5526 GST_OBJECT_UNLOCK (pad);
5527 gst_event_unref (event);
5532 GST_DEBUG_OBJECT (pad, "We're EOS");
5533 GST_OBJECT_UNLOCK (pad);
5534 gst_event_unref (event);
5538 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5542 /* Check if we can call the event function with the given event */
5543 static GstFlowReturn
5544 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5548 switch (GST_EVENT_TYPE (event)) {
5549 case GST_EVENT_CAPS:
5551 /* backwards compatibility mode for caps */
5552 gst_event_parse_caps (event, &caps);
5554 if (!gst_pad_query_accept_caps (pad, caps))
5566 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5567 "caps %" GST_PTR_FORMAT " not accepted", caps);
5568 return GST_FLOW_NOT_NEGOTIATED;
5572 static GstFlowReturn
5573 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5574 GstPadProbeType type)
5577 GstEventType event_type;
5578 gboolean serialized, need_unlock = FALSE, sticky;
5579 GstPadEventFunction eventfunc;
5580 GstPadEventFullFunction eventfullfunc = NULL;
5583 GST_OBJECT_LOCK (pad);
5585 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5587 if (GST_PAD_IS_SINK (pad))
5588 serialized = GST_EVENT_IS_SERIALIZED (event);
5591 sticky = GST_EVENT_IS_STICKY (event);
5592 event_type = GST_EVENT_TYPE (event);
5593 switch (event_type) {
5594 case GST_EVENT_FLUSH_START:
5595 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5596 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5598 /* can't even accept a flush begin event when flushing */
5599 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5602 GST_PAD_SET_FLUSHING (pad);
5603 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5604 GST_PAD_BLOCK_BROADCAST (pad);
5605 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5607 case GST_EVENT_FLUSH_STOP:
5608 /* we can't accept flush-stop on inactive pads else the flushing flag
5609 * would be cleared and it would look like the pad can accept data.
5610 * Also, some elements restart a streaming thread in flush-stop which we
5611 * can't allow on inactive pads */
5612 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5615 GST_PAD_UNSET_FLUSHING (pad);
5616 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5617 /* Remove pending EOS events */
5618 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5619 remove_event_by_type (pad, GST_EVENT_EOS);
5620 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5621 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5622 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5623 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5625 GST_OBJECT_UNLOCK (pad);
5626 /* grab stream lock */
5627 GST_PAD_STREAM_LOCK (pad);
5629 GST_OBJECT_LOCK (pad);
5630 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5633 case GST_EVENT_RECONFIGURE:
5634 if (GST_PAD_IS_SRC (pad))
5635 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5637 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5638 "have event type %" GST_PTR_FORMAT, event);
5640 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5643 switch (event_type) {
5644 case GST_EVENT_STREAM_START:
5645 /* Remove sticky EOS events */
5646 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5647 remove_event_by_type (pad, GST_EVENT_EOS);
5648 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5649 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5656 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5659 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5660 GST_OBJECT_UNLOCK (pad);
5661 GST_PAD_STREAM_LOCK (pad);
5663 GST_OBJECT_LOCK (pad);
5664 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5667 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5673 /* now do the probe */
5675 type | GST_PAD_PROBE_TYPE_PUSH |
5676 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5678 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5680 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5681 eventfunc = GST_PAD_EVENTFUNC (pad);
5682 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5685 ACQUIRE_PARENT (pad, parent, no_parent);
5686 GST_OBJECT_UNLOCK (pad);
5688 ret = pre_eventfunc_check (pad, event);
5689 if (G_UNLIKELY (ret != GST_FLOW_OK))
5690 goto precheck_failed;
5693 gst_event_ref (event);
5695 if (eventfullfunc) {
5696 ret = eventfullfunc (pad, parent, event);
5697 } else if (eventfunc (pad, parent, event)) {
5700 /* something went wrong */
5701 switch (event_type) {
5702 case GST_EVENT_CAPS:
5703 ret = GST_FLOW_NOT_NEGOTIATED;
5706 ret = GST_FLOW_ERROR;
5710 RELEASE_PARENT (parent);
5712 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5715 if (ret == GST_FLOW_OK) {
5716 GST_OBJECT_LOCK (pad);
5717 /* after the event function accepted the event, we can store the sticky
5718 * event on the pad */
5719 switch (store_sticky_event (pad, event)) {
5720 case GST_FLOW_FLUSHING:
5727 GST_OBJECT_UNLOCK (pad);
5729 gst_event_unref (event);
5733 GST_PAD_STREAM_UNLOCK (pad);
5737 /* ERROR handling */
5740 GST_OBJECT_UNLOCK (pad);
5742 GST_PAD_STREAM_UNLOCK (pad);
5743 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5744 "Received event on flushing pad. Discarding");
5745 gst_event_unref (event);
5746 return GST_FLOW_FLUSHING;
5750 GST_OBJECT_UNLOCK (pad);
5752 GST_PAD_STREAM_UNLOCK (pad);
5753 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5754 "Received flush-stop on inactive pad. Discarding");
5755 gst_event_unref (event);
5756 return GST_FLOW_FLUSHING;
5760 GST_OBJECT_UNLOCK (pad);
5762 GST_PAD_STREAM_UNLOCK (pad);
5763 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5764 "Received event on EOS pad. Discarding");
5765 gst_event_unref (event);
5766 return GST_FLOW_EOS;
5770 GST_OBJECT_UNLOCK (pad);
5772 GST_PAD_STREAM_UNLOCK (pad);
5773 /* Only unref if unhandled */
5774 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5775 gst_event_unref (event);
5778 case GST_FLOW_CUSTOM_SUCCESS_1:
5779 case GST_FLOW_CUSTOM_SUCCESS:
5780 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5784 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5791 g_warning ("pad %s:%s has no event handler, file a bug.",
5792 GST_DEBUG_PAD_NAME (pad));
5793 GST_OBJECT_UNLOCK (pad);
5795 GST_PAD_STREAM_UNLOCK (pad);
5796 gst_event_unref (event);
5797 return GST_FLOW_NOT_SUPPORTED;
5801 GST_DEBUG_OBJECT (pad, "no parent");
5802 GST_OBJECT_UNLOCK (pad);
5804 GST_PAD_STREAM_UNLOCK (pad);
5805 gst_event_unref (event);
5806 return GST_FLOW_FLUSHING;
5810 GST_DEBUG_OBJECT (pad, "pre event check failed");
5811 RELEASE_PARENT (parent);
5813 GST_PAD_STREAM_UNLOCK (pad);
5814 gst_event_unref (event);
5820 * gst_pad_send_event:
5821 * @pad: a #GstPad to send the event to.
5822 * @event: (transfer full): the #GstEvent to send to the pad.
5824 * Sends the event to the pad. This function can be used
5825 * by applications to send events in the pipeline.
5827 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5828 * sink pad, @event should be a downstream event. For example, you would not
5829 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5830 * Furthermore, some downstream events have to be serialized with data flow,
5831 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5832 * the event needs to be serialized with data flow, this function will take the
5833 * pad's stream lock while calling its event function.
5835 * To find out whether an event type is upstream, downstream, or downstream and
5836 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5837 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5838 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5839 * plugin doesn't need to bother itself with this information; the core handles
5840 * all necessary locks and checks.
5842 * This function takes ownership of the provided event so you should
5843 * gst_event_ref() it if you want to reuse the event after this call.
5845 * Returns: %TRUE if the event was handled.
5848 gst_pad_send_event (GstPad * pad, GstEvent * event)
5851 GstPadProbeType type;
5853 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5854 g_return_val_if_fail (event != NULL, FALSE);
5856 if (GST_PAD_IS_SINK (pad)) {
5857 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5858 goto wrong_direction;
5859 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5860 } else if (GST_PAD_IS_SRC (pad)) {
5861 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5862 goto wrong_direction;
5863 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5865 goto unknown_direction;
5867 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5874 /* ERROR handling */
5877 g_warning ("pad %s:%s sending %s event in wrong direction",
5878 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5879 gst_event_unref (event);
5884 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5885 gst_event_unref (event);
5891 * gst_pad_set_element_private:
5892 * @pad: the #GstPad to set the private data of.
5893 * @priv: The private data to attach to the pad.
5895 * Set the given private data gpointer on the pad.
5896 * This function can only be used by the element that owns the pad.
5897 * No locking is performed in this function.
5900 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5902 pad->element_private = priv;
5906 * gst_pad_get_element_private:
5907 * @pad: the #GstPad to get the private data of.
5909 * Gets the private data of a pad.
5910 * No locking is performed in this function.
5912 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5915 gst_pad_get_element_private (GstPad * pad)
5917 return pad->element_private;
5921 * gst_pad_get_sticky_event:
5922 * @pad: the #GstPad to get the event from.
5923 * @event_type: the #GstEventType that should be retrieved.
5924 * @idx: the index of the event
5926 * Returns a new reference of the sticky event of type @event_type
5929 * Returns: (transfer full) (nullable): a #GstEvent of type
5930 * @event_type or %NULL when no event of @event_type was on
5931 * @pad. Unref after usage.
5934 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5936 GstEvent *event = NULL;
5939 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5940 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5942 GST_OBJECT_LOCK (pad);
5943 ev = find_event_by_type (pad, event_type, idx);
5944 if (ev && (event = ev->event))
5945 gst_event_ref (event);
5946 GST_OBJECT_UNLOCK (pad);
5953 GstPadStickyEventsForeachFunction func;
5958 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5960 ForeachDispatch *data = user_data;
5961 gboolean ret = TRUE;
5964 GST_OBJECT_UNLOCK (pad);
5966 ret = data->func (pad, &ev->event, data->user_data);
5968 GST_OBJECT_LOCK (pad);
5975 * gst_pad_sticky_events_foreach:
5976 * @pad: the #GstPad that should be used for iteration.
5977 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5978 * should be called for every event.
5979 * @user_data: (closure): the optional user data.
5981 * Iterates all sticky events on @pad and calls @foreach_func for every
5982 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5985 gst_pad_sticky_events_foreach (GstPad * pad,
5986 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5988 ForeachDispatch data;
5990 g_return_if_fail (GST_IS_PAD (pad));
5991 g_return_if_fail (foreach_func != NULL);
5993 data.func = foreach_func;
5994 data.user_data = user_data;
5996 GST_OBJECT_LOCK (pad);
5997 events_foreach (pad, foreach_dispatch_function, &data);
5998 GST_OBJECT_UNLOCK (pad);
6002 do_stream_status (GstPad * pad, GstStreamStatusType type,
6003 GThread * thread, GstTask * task)
6007 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6009 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6010 if (GST_IS_ELEMENT (parent)) {
6011 GstMessage *message;
6012 GValue value = { 0 };
6014 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6015 gchar *tname, *ename, *pname;
6017 /* create a good task name */
6018 ename = gst_element_get_name (parent);
6019 pname = gst_pad_get_name (pad);
6020 tname = g_strdup_printf ("%s:%s", ename, pname);
6024 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6028 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6031 g_value_init (&value, GST_TYPE_TASK);
6032 g_value_set_object (&value, task);
6033 gst_message_set_stream_status_object (message, &value);
6034 g_value_unset (&value);
6036 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6037 gst_element_post_message (parent, message);
6039 gst_object_unref (parent);
6044 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6046 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6051 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6053 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6058 * gst_pad_start_task:
6059 * @pad: the #GstPad to start the task of
6060 * @func: the task function to call
6061 * @user_data: user data passed to the task function
6062 * @notify: called when @user_data is no longer referenced
6064 * Starts a task that repeatedly calls @func with @user_data. This function
6065 * is mostly used in pad activation functions to start the dataflow.
6066 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6067 * before @func is called.
6069 * Returns: a %TRUE if the task could be started.
6072 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6073 GDestroyNotify notify)
6078 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6079 g_return_val_if_fail (func != NULL, FALSE);
6081 GST_DEBUG_OBJECT (pad, "start task");
6083 GST_OBJECT_LOCK (pad);
6084 task = GST_PAD_TASK (pad);
6086 task = gst_task_new (func, user_data, notify);
6087 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6088 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6089 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6090 GST_INFO_OBJECT (pad, "created task %p", task);
6091 GST_PAD_TASK (pad) = task;
6092 gst_object_ref (task);
6093 /* release lock to post the message */
6094 GST_OBJECT_UNLOCK (pad);
6096 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6098 gst_object_unref (task);
6100 GST_OBJECT_LOCK (pad);
6101 /* nobody else is supposed to have changed the pad now */
6102 if (GST_PAD_TASK (pad) != task)
6103 goto concurrent_stop;
6105 res = gst_task_set_state (task, GST_TASK_STARTED);
6106 GST_OBJECT_UNLOCK (pad);
6113 GST_OBJECT_UNLOCK (pad);
6119 * gst_pad_pause_task:
6120 * @pad: the #GstPad to pause the task of
6122 * Pause the task of @pad. This function will also wait until the
6123 * function executed by the task is finished if this function is not
6124 * called from the task function.
6126 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6130 gst_pad_pause_task (GstPad * pad)
6135 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6137 GST_DEBUG_OBJECT (pad, "pause task");
6139 GST_OBJECT_LOCK (pad);
6140 task = GST_PAD_TASK (pad);
6143 res = gst_task_set_state (task, GST_TASK_PAUSED);
6144 /* unblock activation waits if any */
6145 pad->priv->in_activation = FALSE;
6146 g_cond_broadcast (&pad->priv->activation_cond);
6147 GST_OBJECT_UNLOCK (pad);
6149 /* wait for task function to finish, this lock is recursive so it does nothing
6150 * when the pause is called from the task itself */
6151 GST_PAD_STREAM_LOCK (pad);
6152 GST_PAD_STREAM_UNLOCK (pad);
6158 GST_DEBUG_OBJECT (pad, "pad has no task");
6159 GST_OBJECT_UNLOCK (pad);
6165 * gst_pad_get_task_state:
6166 * @pad: the #GstPad to get task state from
6168 * Get @pad task state. If no task is currently
6169 * set, #GST_TASK_STOPPED is returned.
6171 * Returns: The current state of @pad's task.
6176 gst_pad_get_task_state (GstPad * pad)
6181 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6183 GST_OBJECT_LOCK (pad);
6184 task = GST_PAD_TASK (pad);
6187 res = gst_task_get_state (task);
6188 GST_OBJECT_UNLOCK (pad);
6194 GST_DEBUG_OBJECT (pad, "pad has no task");
6195 GST_OBJECT_UNLOCK (pad);
6196 return GST_TASK_STOPPED;
6201 * gst_pad_stop_task:
6202 * @pad: the #GstPad to stop the task of
6204 * Stop the task of @pad. This function will also make sure that the
6205 * function executed by the task will effectively stop if not called
6206 * from the GstTaskFunction.
6208 * This function will deadlock if called from the GstTaskFunction of
6209 * the task. Use gst_task_pause() instead.
6211 * Regardless of whether the pad has a task, the stream lock is acquired and
6212 * released so as to ensure that streaming through this pad has finished.
6214 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6217 gst_pad_stop_task (GstPad * pad)
6222 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6224 GST_DEBUG_OBJECT (pad, "stop task");
6226 GST_OBJECT_LOCK (pad);
6227 task = GST_PAD_TASK (pad);
6230 GST_PAD_TASK (pad) = NULL;
6231 res = gst_task_set_state (task, GST_TASK_STOPPED);
6232 /* unblock activation waits if any */
6233 pad->priv->in_activation = FALSE;
6234 g_cond_broadcast (&pad->priv->activation_cond);
6235 GST_OBJECT_UNLOCK (pad);
6237 GST_PAD_STREAM_LOCK (pad);
6238 GST_PAD_STREAM_UNLOCK (pad);
6240 if (!gst_task_join (task))
6243 gst_object_unref (task);
6249 GST_DEBUG_OBJECT (pad, "no task");
6250 GST_OBJECT_UNLOCK (pad);
6252 GST_PAD_STREAM_LOCK (pad);
6253 GST_PAD_STREAM_UNLOCK (pad);
6255 /* this is not an error */
6260 /* this is bad, possibly the application tried to join the task from
6261 * the task's thread. We install the task again so that it will be stopped
6262 * again from the right thread next time hopefully. */
6263 GST_OBJECT_LOCK (pad);
6264 GST_DEBUG_OBJECT (pad, "join failed");
6265 /* we can only install this task if there was no other task */
6266 if (GST_PAD_TASK (pad) == NULL)
6267 GST_PAD_TASK (pad) = task;
6268 GST_OBJECT_UNLOCK (pad);
6275 * gst_pad_probe_info_get_event:
6276 * @info: a #GstPadProbeInfo
6278 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6282 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6284 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6285 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6287 return GST_PAD_PROBE_INFO_EVENT (info);
6292 * gst_pad_probe_info_get_query:
6293 * @info: a #GstPadProbeInfo
6295 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6299 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6301 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6302 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6304 return GST_PAD_PROBE_INFO_QUERY (info);
6308 * gst_pad_probe_info_get_buffer:
6309 * @info: a #GstPadProbeInfo
6311 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6315 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6317 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6319 return GST_PAD_PROBE_INFO_BUFFER (info);
6323 * gst_pad_probe_info_get_buffer_list:
6324 * @info: a #GstPadProbeInfo
6326 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6330 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6332 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6334 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6338 * gst_pad_get_last_flow_return:
6341 * Gets the #GstFlowReturn return from the last data passed by this pad.
6346 gst_pad_get_last_flow_return (GstPad * pad)
6350 GST_OBJECT_LOCK (pad);
6351 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6352 GST_OBJECT_UNLOCK (pad);