2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 * @short_description: Object contained by elements that allows links to
27 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
29 * A #GstElement is linked to other elements via "pads", which are extremely
30 * light-weight generic link points.
32 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
37 * happens when the element is created but it can also happen dynamically based
38 * on the data that the element is processing or based on the pads that the
39 * application requests.
41 * Pads without pad templates can be created with gst_pad_new(),
42 * which takes a direction and a name as an argument. If the name is %NULL,
43 * then a guaranteed unique name will be assigned to it.
45 * A #GstElement creating a pad will typically use the various
46 * gst_pad_set_*_function() calls to register callbacks for events, queries or
47 * dataflow on the pads.
49 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
51 * After two pads are retrieved from an element by gst_element_get_static_pad(),
52 * the pads can be linked with gst_pad_link(). (For quick links,
53 * you can also use gst_element_link(), which will make the obvious
54 * link for you if it's straightforward.). Pads can be unlinked again with
55 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
58 * Before dataflow is possible on the pads, they need to be activated with
59 * gst_pad_set_active().
61 * gst_pad_query() and gst_pad_peer_query() can be used to query various
62 * properties of the pad and the stream.
64 * To send a #GstEvent on a pad, use gst_pad_send_event() and
65 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
66 * after they pass on the pad they can be queried later with
67 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
68 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
69 * functions to query the current sticky CAPS event on a pad.
71 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
72 * or pull in a buffer.
74 * The dataflow, events and queries that happen on a pad can be monitored with
75 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
76 * can be used to check if a block probe is installed on the pad.
77 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
78 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
79 * and unblock blocking probes if any.
81 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
82 * offset will be applied to the running_time of all data passing over the pad.
83 * gst_pad_set_offset() can be used to change the offset.
85 * Convenience functions exist to start, pause and stop the task on a pad with
86 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
90 #include "gst_private.h"
93 #include "gstpadtemplate.h"
94 #include "gstenumtypes.h"
98 #include "gsttracerutils.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
124 #define GST_PAD_GET_PRIVATE(obj) \
125 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
127 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
129 /* we have a pending and an active event on the pad. On source pads only the
130 * active event is used. On sinkpads, events are copied to the pending entry and
131 * moved to the active event when the eventfunc returned %TRUE. */
138 struct _GstPadPrivate
145 guint probe_list_cookie;
148 /* counter of how many idle probes are running directly from the add_probe
149 * call. Used to block any data flowing in the pad while the idle callback
150 * Doesn't finish its work */
153 /* conditional and variable used to ensure pads only get (de)activated
154 * by a single thread at a time. Protected by the object lock */
155 GCond activation_cond;
156 gboolean in_activation;
165 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
166 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
167 (((GstPad *)(p))->priv->idle_running > 0)
172 GstPadProbeInfo *info;
180 static void gst_pad_dispose (GObject * object);
181 static void gst_pad_finalize (GObject * object);
182 static void gst_pad_set_property (GObject * object, guint prop_id,
183 const GValue * value, GParamSpec * pspec);
184 static void gst_pad_get_property (GObject * object, guint prop_id,
185 GValue * value, GParamSpec * pspec);
187 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
188 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
189 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
190 GstObject * parent, GstBufferList * list);
192 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
194 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
195 GstEvent * event, GstPadProbeType type);
197 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
198 GstPadMode mode, gboolean active);
200 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
202 static GParamSpec *pspec_caps = NULL;
204 /* quarks for probe signals */
205 static GQuark buffer_quark;
206 static GQuark buffer_list_quark;
207 static GQuark event_quark;
216 static GstFlowQuarks flow_quarks[] = {
217 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
218 {GST_FLOW_OK, "ok", 0},
219 {GST_FLOW_NOT_LINKED, "not-linked", 0},
220 {GST_FLOW_FLUSHING, "flushing", 0},
221 {GST_FLOW_EOS, "eos", 0},
222 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
223 {GST_FLOW_ERROR, "error", 0},
224 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
225 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
230 * @ret: a #GstFlowReturn to get the name of.
232 * Gets a string representing the given flow return.
234 * Returns: a static string with the name of the flow return.
237 gst_flow_get_name (GstFlowReturn ret)
241 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
243 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
244 if (ret == flow_quarks[i].ret)
245 return flow_quarks[i].name;
252 * @ret: a #GstFlowReturn to get the quark of.
254 * Get the unique quark for the given GstFlowReturn.
256 * Returns: the quark associated with the flow return or 0 if an
257 * invalid return was specified.
260 gst_flow_to_quark (GstFlowReturn ret)
264 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
266 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
267 if (ret == flow_quarks[i].ret)
268 return flow_quarks[i].quark;
274 * gst_pad_link_get_name:
275 * @ret: a #GstPadLinkReturn to get the name of.
277 * Gets a string representing the given pad-link return.
279 * Returns: a static string with the name of the pad-link return.
284 gst_pad_link_get_name (GstPadLinkReturn ret)
287 case GST_PAD_LINK_OK:
289 case GST_PAD_LINK_WRONG_HIERARCHY:
290 return "wrong hierarchy";
291 case GST_PAD_LINK_WAS_LINKED:
293 case GST_PAD_LINK_WRONG_DIRECTION:
294 return "wrong direction";
295 case GST_PAD_LINK_NOFORMAT:
296 return "no common format";
297 case GST_PAD_LINK_NOSCHED:
298 return "incompatible scheduling";
299 case GST_PAD_LINK_REFUSED:
302 g_return_val_if_reached ("unknown");
309 buffer_quark = g_quark_from_static_string ("buffer"); \
310 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
311 event_quark = g_quark_from_static_string ("event"); \
313 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
314 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
317 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
318 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
321 #define gst_pad_parent_class parent_class
322 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
325 gst_pad_class_init (GstPadClass * klass)
327 GObjectClass *gobject_class;
328 GstObjectClass *gstobject_class;
330 gobject_class = G_OBJECT_CLASS (klass);
331 gstobject_class = GST_OBJECT_CLASS (klass);
333 g_type_class_add_private (klass, sizeof (GstPadPrivate));
335 gobject_class->dispose = gst_pad_dispose;
336 gobject_class->finalize = gst_pad_finalize;
337 gobject_class->set_property = gst_pad_set_property;
338 gobject_class->get_property = gst_pad_get_property;
342 * @pad: the pad that emitted the signal
343 * @peer: the peer pad that has been connected
345 * Signals that a pad has been linked to the peer pad.
347 gst_pad_signals[PAD_LINKED] =
348 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
349 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
350 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
353 * @pad: the pad that emitted the signal
354 * @peer: the peer pad that has been disconnected
356 * Signals that a pad has been unlinked from the peer pad.
358 gst_pad_signals[PAD_UNLINKED] =
359 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
360 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
361 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
363 pspec_caps = g_param_spec_boxed ("caps", "Caps",
364 "The capabilities of the pad", GST_TYPE_CAPS,
365 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
368 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
369 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
370 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
371 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
373 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
374 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
375 g_param_spec_object ("template", "Template",
376 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 * The offset that will be applied to the running time of the pad.
386 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
387 g_param_spec_int64 ("offset", "Offset",
388 "The running time offset of the pad", 0, G_MAXINT64, 0,
389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 gstobject_class->path_string_separator = ".";
393 /* Register common function pointer descriptions */
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
396 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
397 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
398 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
402 gst_pad_init (GstPad * pad)
404 pad->priv = GST_PAD_GET_PRIVATE (pad);
406 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
408 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
409 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
410 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
411 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
412 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
414 GST_PAD_SET_FLUSHING (pad);
416 g_rec_mutex_init (&pad->stream_rec_lock);
418 g_cond_init (&pad->block_cond);
420 g_hook_list_init (&pad->probes, sizeof (GstProbe));
422 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
423 pad->priv->events_cookie = 0;
424 pad->priv->last_cookie = -1;
425 g_cond_init (&pad->priv->activation_cond);
427 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
430 /* called when setting the pad inactive. It removes all sticky events from
431 * the pad. must be called with object lock */
433 remove_events (GstPad * pad)
437 gboolean notify = FALSE;
439 events = pad->priv->events;
442 for (i = 0; i < len; i++) {
443 PadEvent *ev = &g_array_index (events, PadEvent, i);
444 GstEvent *event = ev->event;
448 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
451 gst_event_unref (event);
454 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
455 g_array_set_size (events, 0);
456 pad->priv->events_cookie++;
459 GST_OBJECT_UNLOCK (pad);
461 GST_DEBUG_OBJECT (pad, "notify caps");
462 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
464 GST_OBJECT_LOCK (pad);
468 /* should be called with object lock */
470 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
476 events = pad->priv->events;
479 for (i = 0; i < len; i++) {
480 ev = &g_array_index (events, PadEvent, i);
481 if (ev->event == NULL)
484 if (GST_EVENT_TYPE (ev->event) == type) {
488 } else if (GST_EVENT_TYPE (ev->event) > type) {
497 /* should be called with OBJECT lock */
499 find_event (GstPad * pad, GstEvent * event)
505 events = pad->priv->events;
508 for (i = 0; i < len; i++) {
509 ev = &g_array_index (events, PadEvent, i);
510 if (event == ev->event)
512 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
520 /* should be called with OBJECT lock */
522 remove_event_by_type (GstPad * pad, GstEventType type)
528 events = pad->priv->events;
533 ev = &g_array_index (events, PadEvent, i);
534 if (ev->event == NULL)
537 if (GST_EVENT_TYPE (ev->event) > type)
539 else if (GST_EVENT_TYPE (ev->event) != type)
542 gst_event_unref (ev->event);
543 g_array_remove_index (events, i);
545 pad->priv->events_cookie++;
553 /* check all events on srcpad against those on sinkpad. All events that are not
554 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
555 * srcpad so that the events will be sent next time */
556 /* should be called with srcpad and sinkpad LOCKS */
558 schedule_events (GstPad * srcpad, GstPad * sinkpad)
563 gboolean pending = FALSE;
565 events = srcpad->priv->events;
568 for (i = 0; i < len; i++) {
569 ev = &g_array_index (events, PadEvent, i);
570 if (ev->event == NULL)
573 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
574 ev->received = FALSE;
579 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
582 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
585 /* should be called with pad LOCK */
587 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
594 events = pad->priv->events;
597 cookie = pad->priv->events_cookie;
601 PadEvent *ev, ev_ret;
603 ev = &g_array_index (events, PadEvent, i);
604 if (G_UNLIKELY (ev->event == NULL))
607 /* take aditional ref, func might release the lock */
608 ev_ret.event = gst_event_ref (ev->event);
609 ev_ret.received = ev->received;
611 ret = func (pad, &ev_ret, user_data);
613 /* recheck the cookie, lock might have been released and the list could have
615 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
616 if (G_LIKELY (ev_ret.event))
617 gst_event_unref (ev_ret.event);
621 /* store the received state */
622 ev->received = ev_ret.received;
624 /* if the event changed, we need to do something */
625 if (G_UNLIKELY (ev->event != ev_ret.event)) {
626 if (G_UNLIKELY (ev_ret.event == NULL)) {
627 /* function unreffed and set the event to NULL, remove it */
628 gst_event_unref (ev->event);
629 g_array_remove_index (events, i);
631 cookie = ++pad->priv->events_cookie;
634 /* function gave a new event for us */
635 gst_event_take (&ev->event, ev_ret.event);
638 /* just unref, nothing changed */
639 gst_event_unref (ev_ret.event);
648 /* should be called with LOCK */
650 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
654 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
655 GST_STIME_ARGS (pad->offset));
657 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
660 g_assert (!upstream);
662 /* copy segment values */
663 gst_event_copy_segment (event, &segment);
664 gst_event_unref (event);
666 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
667 event = gst_event_new_segment (&segment);
670 event = gst_event_make_writable (event);
671 offset = gst_event_get_running_time_offset (event);
673 offset -= pad->offset;
675 offset += pad->offset;
676 gst_event_set_running_time_offset (event, offset);
681 static inline GstEvent *
682 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
684 if (G_UNLIKELY (pad->offset != 0))
685 return _apply_pad_offset (pad, event, upstream);
690 /* should be called with the OBJECT_LOCK */
692 get_pad_caps (GstPad * pad)
694 GstCaps *caps = NULL;
697 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
699 gst_event_parse_caps (ev->event, &caps);
705 gst_pad_dispose (GObject * object)
707 GstPad *pad = GST_PAD_CAST (object);
710 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
712 /* unlink the peer pad */
713 if ((peer = gst_pad_get_peer (pad))) {
714 /* window for MT unsafeness, someone else could unlink here
715 * and then we call unlink with wrong pads. The unlink
716 * function would catch this and safely return failed. */
717 if (GST_PAD_IS_SRC (pad))
718 gst_pad_unlink (pad, peer);
720 gst_pad_unlink (peer, pad);
722 gst_object_unref (peer);
725 gst_pad_set_pad_template (pad, NULL);
727 GST_OBJECT_LOCK (pad);
729 GST_OBJECT_UNLOCK (pad);
731 g_hook_list_clear (&pad->probes);
733 G_OBJECT_CLASS (parent_class)->dispose (object);
737 gst_pad_finalize (GObject * object)
739 GstPad *pad = GST_PAD_CAST (object);
742 /* in case the task is still around, clean it up */
743 if ((task = GST_PAD_TASK (pad))) {
744 gst_task_join (task);
745 GST_PAD_TASK (pad) = NULL;
746 gst_object_unref (task);
749 if (pad->activatenotify)
750 pad->activatenotify (pad->activatedata);
751 if (pad->activatemodenotify)
752 pad->activatemodenotify (pad->activatemodedata);
754 pad->linknotify (pad->linkdata);
755 if (pad->unlinknotify)
756 pad->unlinknotify (pad->unlinkdata);
757 if (pad->chainnotify)
758 pad->chainnotify (pad->chaindata);
759 if (pad->chainlistnotify)
760 pad->chainlistnotify (pad->chainlistdata);
761 if (pad->getrangenotify)
762 pad->getrangenotify (pad->getrangedata);
763 if (pad->eventnotify)
764 pad->eventnotify (pad->eventdata);
765 if (pad->querynotify)
766 pad->querynotify (pad->querydata);
767 if (pad->iterintlinknotify)
768 pad->iterintlinknotify (pad->iterintlinkdata);
770 g_rec_mutex_clear (&pad->stream_rec_lock);
771 g_cond_clear (&pad->block_cond);
772 g_cond_clear (&pad->priv->activation_cond);
773 g_array_free (pad->priv->events, TRUE);
775 G_OBJECT_CLASS (parent_class)->finalize (object);
779 gst_pad_set_property (GObject * object, guint prop_id,
780 const GValue * value, GParamSpec * pspec)
782 g_return_if_fail (GST_IS_PAD (object));
785 case PAD_PROP_DIRECTION:
786 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
788 case PAD_PROP_TEMPLATE:
789 gst_pad_set_pad_template (GST_PAD_CAST (object),
790 (GstPadTemplate *) g_value_get_object (value));
792 case PAD_PROP_OFFSET:
793 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
796 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
802 gst_pad_get_property (GObject * object, guint prop_id,
803 GValue * value, GParamSpec * pspec)
805 g_return_if_fail (GST_IS_PAD (object));
809 GST_OBJECT_LOCK (object);
810 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
811 GST_OBJECT_UNLOCK (object);
813 case PAD_PROP_DIRECTION:
814 g_value_set_enum (value, GST_PAD_DIRECTION (object));
816 case PAD_PROP_TEMPLATE:
817 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
819 case PAD_PROP_OFFSET:
820 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
823 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
830 * @name: (allow-none): the name of the new pad.
831 * @direction: the #GstPadDirection of the pad.
833 * Creates a new pad with the given name in the given direction.
834 * If name is %NULL, a guaranteed unique name (across all pads)
836 * This function makes a copy of the name so you can safely free the name.
838 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
844 gst_pad_new (const gchar * name, GstPadDirection direction)
846 return g_object_new (GST_TYPE_PAD,
847 "name", name, "direction", direction, NULL);
851 * gst_pad_new_from_template:
852 * @templ: the pad template to use
853 * @name: (allow-none): the name of the pad
855 * Creates a new pad with the given name from the given template.
856 * If name is %NULL, a guaranteed unique name (across all pads)
858 * This function makes a copy of the name so you can safely free the name.
860 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
864 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
866 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
868 return g_object_new (GST_TYPE_PAD,
869 "name", name, "direction", templ->direction, "template", templ, NULL);
873 * gst_pad_new_from_static_template:
874 * @templ: the #GstStaticPadTemplate to use
875 * @name: the name of the pad
877 * Creates a new pad with the given name from the given static template.
878 * If name is %NULL, a guaranteed unique name (across all pads)
880 * This function makes a copy of the name so you can safely free the name.
882 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
886 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
890 GstPadTemplate *template;
892 template = gst_static_pad_template_get (templ);
893 pad = gst_pad_new_from_template (template, name);
894 gst_object_unref (template);
898 #define ACQUIRE_PARENT(pad, parent, label) \
900 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
901 gst_object_ref (parent); \
902 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
906 #define RELEASE_PARENT(parent) \
908 if (G_LIKELY (parent)) \
909 gst_object_unref (parent); \
913 * gst_pad_get_direction:
914 * @pad: a #GstPad to get the direction of.
916 * Gets the direction of the pad. The direction of the pad is
917 * decided at construction time so this function does not take
920 * Returns: the #GstPadDirection of the pad.
925 gst_pad_get_direction (GstPad * pad)
927 GstPadDirection result;
929 /* PAD_UNKNOWN is a little silly but we need some sort of
930 * error return value */
931 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
933 result = GST_PAD_DIRECTION (pad);
939 gst_pad_activate_default (GstPad * pad, GstObject * parent)
941 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
943 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
947 * gst_pad_mode_get_name:
948 * @mode: the pad mode
950 * Return the name of a pad mode, for use in debug messages mostly.
952 * Returns: short mnemonic for pad mode @mode
955 gst_pad_mode_get_name (GstPadMode mode)
958 case GST_PAD_MODE_NONE:
960 case GST_PAD_MODE_PUSH:
962 case GST_PAD_MODE_PULL:
970 /* Returns TRUE if pad wasn't already in the new_mode */
972 pre_activate (GstPad * pad, GstPadMode new_mode)
975 case GST_PAD_MODE_NONE:
976 GST_OBJECT_LOCK (pad);
977 while (G_UNLIKELY (pad->priv->in_activation))
978 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
979 if (new_mode == GST_PAD_MODE (pad)) {
980 GST_WARNING_OBJECT (pad,
981 "Pad is already in the process of being deactivated");
982 GST_OBJECT_UNLOCK (pad);
985 pad->priv->in_activation = TRUE;
986 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
987 GST_PAD_SET_FLUSHING (pad);
988 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
989 GST_PAD_MODE (pad) = new_mode;
990 /* unlock blocked pads so element can resume and stop */
991 GST_PAD_BLOCK_BROADCAST (pad);
992 GST_OBJECT_UNLOCK (pad);
994 case GST_PAD_MODE_PUSH:
995 case GST_PAD_MODE_PULL:
996 GST_OBJECT_LOCK (pad);
997 while (G_UNLIKELY (pad->priv->in_activation))
998 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
999 if (new_mode == GST_PAD_MODE (pad)) {
1000 GST_WARNING_OBJECT (pad,
1001 "Pad is already in the process of being activated");
1002 GST_OBJECT_UNLOCK (pad);
1005 pad->priv->in_activation = TRUE;
1006 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1007 gst_pad_mode_get_name (new_mode));
1008 GST_PAD_UNSET_FLUSHING (pad);
1009 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1010 GST_PAD_MODE (pad) = new_mode;
1011 if (GST_PAD_IS_SINK (pad)) {
1013 /* make sure the peer src pad sends us all events */
1014 if ((peer = GST_PAD_PEER (pad))) {
1015 gst_object_ref (peer);
1016 GST_OBJECT_UNLOCK (pad);
1018 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1019 GST_DEBUG_PAD_NAME (peer));
1021 GST_OBJECT_LOCK (peer);
1022 schedule_events (peer, NULL);
1023 GST_OBJECT_UNLOCK (peer);
1025 gst_object_unref (peer);
1027 GST_OBJECT_UNLOCK (pad);
1030 GST_OBJECT_UNLOCK (pad);
1038 post_activate (GstPad * pad, GstPadMode new_mode)
1041 case GST_PAD_MODE_NONE:
1042 GST_OBJECT_LOCK (pad);
1043 pad->priv->in_activation = FALSE;
1044 g_cond_broadcast (&pad->priv->activation_cond);
1045 GST_OBJECT_UNLOCK (pad);
1047 /* ensures that streaming stops */
1048 GST_PAD_STREAM_LOCK (pad);
1049 GST_DEBUG_OBJECT (pad, "stopped streaming");
1050 GST_OBJECT_LOCK (pad);
1051 remove_events (pad);
1052 GST_OBJECT_UNLOCK (pad);
1053 GST_PAD_STREAM_UNLOCK (pad);
1055 case GST_PAD_MODE_PUSH:
1056 case GST_PAD_MODE_PULL:
1057 GST_OBJECT_LOCK (pad);
1058 pad->priv->in_activation = FALSE;
1059 g_cond_broadcast (&pad->priv->activation_cond);
1060 GST_OBJECT_UNLOCK (pad);
1067 * gst_pad_set_active:
1068 * @pad: the #GstPad to activate or deactivate.
1069 * @active: whether or not the pad should be active.
1071 * Activates or deactivates the given pad.
1072 * Normally called from within core state change functions.
1074 * If @active, makes sure the pad is active. If it is already active, either in
1075 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1076 * function to perform the actual activation.
1078 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1079 * and a %FALSE argument.
1081 * Returns: %TRUE if the operation was successful.
1086 gst_pad_set_active (GstPad * pad, gboolean active)
1090 gboolean ret = FALSE;
1092 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1094 GST_OBJECT_LOCK (pad);
1095 old = GST_PAD_MODE (pad);
1096 ACQUIRE_PARENT (pad, parent, no_parent);
1097 GST_OBJECT_UNLOCK (pad);
1100 if (old == GST_PAD_MODE_NONE) {
1101 GST_DEBUG_OBJECT (pad, "activating pad from none");
1102 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1104 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1106 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1107 gst_pad_mode_get_name (old));
1111 if (old == GST_PAD_MODE_NONE) {
1112 GST_DEBUG_OBJECT (pad, "pad was inactive");
1115 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1116 gst_pad_mode_get_name (old));
1117 ret = activate_mode_internal (pad, parent, old, FALSE);
1119 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1123 RELEASE_PARENT (parent);
1125 if (G_UNLIKELY (!ret))
1133 GST_DEBUG_OBJECT (pad, "no parent");
1134 GST_OBJECT_UNLOCK (pad);
1139 GST_OBJECT_LOCK (pad);
1141 g_critical ("Failed to deactivate pad %s:%s, very bad",
1142 GST_DEBUG_PAD_NAME (pad));
1144 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1146 GST_OBJECT_UNLOCK (pad);
1152 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1155 gboolean res = FALSE;
1156 GstPadMode old, new;
1157 GstPadDirection dir;
1160 GST_OBJECT_LOCK (pad);
1161 old = GST_PAD_MODE (pad);
1162 dir = GST_PAD_DIRECTION (pad);
1163 GST_OBJECT_UNLOCK (pad);
1165 new = active ? mode : GST_PAD_MODE_NONE;
1170 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1171 /* pad was activate in the wrong direction, deactivate it
1172 * and reactivate it in the requested mode */
1173 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1174 gst_pad_mode_get_name (old));
1176 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1177 goto deactivate_failed;
1178 old = GST_PAD_MODE_NONE;
1182 case GST_PAD_MODE_PULL:
1184 if (dir == GST_PAD_SINK) {
1185 if ((peer = gst_pad_get_peer (pad))) {
1186 GST_DEBUG_OBJECT (pad, "calling peer");
1187 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1189 gst_object_unref (peer);
1191 /* there is no peer, this is only fatal when we activate. When we
1192 * deactivate, we must assume the application has unlinked the peer and
1193 * will deactivate it eventually. */
1197 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1200 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1201 goto failure; /* Can't activate pull on a src without a
1202 getrange function */
1210 /* Mark pad as needing reconfiguration */
1212 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1214 /* pre_activate returns TRUE if we weren't already in the process of
1215 * switching to the 'new' mode */
1216 if (pre_activate (pad, new)) {
1218 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1219 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1223 /* can happen for sinks of passthrough elements */
1226 post_activate (pad, new);
1229 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1230 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1235 /* Clear sticky flags on deactivation */
1237 GST_OBJECT_LOCK (pad);
1238 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1239 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1240 GST_OBJECT_UNLOCK (pad);
1248 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1249 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1254 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1255 "failed to %s in switch to %s mode from %s mode",
1256 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1257 gst_pad_mode_get_name (old));
1262 GST_OBJECT_LOCK (peer);
1263 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1264 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1265 GST_OBJECT_UNLOCK (peer);
1266 gst_object_unref (peer);
1271 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1272 "pad in pull mode");
1277 GST_OBJECT_LOCK (pad);
1278 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1279 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1280 GST_PAD_SET_FLUSHING (pad);
1281 GST_PAD_MODE (pad) = old;
1282 pad->priv->in_activation = FALSE;
1283 g_cond_broadcast (&pad->priv->activation_cond);
1284 GST_OBJECT_UNLOCK (pad);
1290 * gst_pad_activate_mode:
1291 * @pad: the #GstPad to activate or deactivate.
1292 * @mode: the requested activation mode
1293 * @active: whether or not the pad should be active.
1295 * Activates or deactivates the given pad in @mode via dispatching to the
1296 * pad's activatemodefunc. For use from within pad activation functions only.
1298 * If you don't know what this is, you probably don't want to call it.
1300 * Returns: %TRUE if the operation was successful.
1305 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1309 GstPadMode old, new;
1311 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1313 GST_OBJECT_LOCK (pad);
1315 old = GST_PAD_MODE (pad);
1316 new = active ? mode : GST_PAD_MODE_NONE;
1320 ACQUIRE_PARENT (pad, parent, no_parent);
1322 GST_OBJECT_UNLOCK (pad);
1324 res = activate_mode_internal (pad, parent, mode, active);
1326 RELEASE_PARENT (parent);
1332 GST_OBJECT_UNLOCK (pad);
1333 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1334 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1339 GST_WARNING_OBJECT (pad, "no parent");
1340 GST_OBJECT_UNLOCK (pad);
1346 * gst_pad_is_active:
1347 * @pad: the #GstPad to query
1349 * Query if a pad is active
1351 * Returns: %TRUE if the pad is active.
1356 gst_pad_is_active (GstPad * pad)
1358 gboolean result = FALSE;
1360 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1362 GST_OBJECT_LOCK (pad);
1363 result = GST_PAD_IS_ACTIVE (pad);
1364 GST_OBJECT_UNLOCK (pad);
1370 cleanup_hook (GstPad * pad, GHook * hook)
1372 GstPadProbeType type;
1374 if (!G_HOOK_IS_VALID (hook))
1377 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1379 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1380 /* unblock when we remove the last blocking probe */
1382 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1385 /* Might have new probes now that want to be called */
1386 GST_PAD_BLOCK_BROADCAST (pad);
1388 if (pad->num_blocked == 0) {
1389 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1390 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1393 g_hook_destroy_link (&pad->probes, hook);
1398 * gst_pad_add_probe:
1399 * @pad: the #GstPad to add the probe to
1400 * @mask: the probe mask
1401 * @callback: #GstPadProbeCallback that will be called with notifications of
1403 * @user_data: (closure): user data passed to the callback
1404 * @destroy_data: #GDestroyNotify for user_data
1406 * Be notified of different states of pads. The provided callback is called for
1407 * every state that matches @mask.
1409 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1410 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1411 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1412 * immediately if the pad is already idle while calling gst_pad_add_probe().
1413 * In each of the groups, probes are called in the order in which they were
1416 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1417 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1418 * happen that the probe can be run immediately and if the probe returns
1419 * GST_PAD_PROBE_REMOVE this functions returns 0.
1424 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1425 GstPadProbeCallback callback, gpointer user_data,
1426 GDestroyNotify destroy_data)
1431 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1432 g_return_val_if_fail (mask != 0, 0);
1434 GST_OBJECT_LOCK (pad);
1436 /* make a new probe */
1437 hook = g_hook_alloc (&pad->probes);
1439 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1442 /* when no contraints are given for the types, assume all types are
1444 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1445 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1446 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1447 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1449 /* store our flags and other fields */
1450 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1451 hook->func = callback;
1452 hook->data = user_data;
1453 hook->destroy = destroy_data;
1454 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1457 g_hook_append (&pad->probes, hook);
1459 /* incremenent cookie so that the new hook get's called */
1460 pad->priv->probe_list_cookie++;
1462 /* get the id of the hook, we return this and it can be used to remove the
1464 res = hook->hook_id;
1466 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1468 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1469 /* we have a block probe */
1471 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1473 "now %d blocking probes", pad->num_blocked);
1475 /* Might have new probes now that want to be called */
1476 GST_PAD_BLOCK_BROADCAST (pad);
1479 /* call the callback if we need to be called for idle callbacks */
1480 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1481 if (pad->priv->using > 0) {
1482 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1483 * flag above, the last thread to leave the push will do the callback. New
1484 * threads going into the push will block. */
1485 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1486 "pad is in use, delay idle callback");
1487 GST_OBJECT_UNLOCK (pad);
1489 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1490 GstPadProbeReturn ret;
1492 /* Keep another ref, the callback could destroy the pad */
1493 gst_object_ref (pad);
1494 pad->priv->idle_running++;
1496 /* the pad is idle now, we can signal the idle callback now */
1497 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1498 "pad is idle, trigger idle callback");
1499 GST_OBJECT_UNLOCK (pad);
1501 ret = callback (pad, &info, user_data);
1503 GST_OBJECT_LOCK (pad);
1505 case GST_PAD_PROBE_REMOVE:
1506 /* remove the probe */
1507 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1508 cleanup_hook (pad, hook);
1511 case GST_PAD_PROBE_DROP:
1512 GST_DEBUG_OBJECT (pad, "asked to drop item");
1514 case GST_PAD_PROBE_PASS:
1515 GST_DEBUG_OBJECT (pad, "asked to pass item");
1517 case GST_PAD_PROBE_OK:
1518 GST_DEBUG_OBJECT (pad, "probe returned OK");
1520 case GST_PAD_PROBE_HANDLED:
1521 GST_DEBUG_OBJECT (pad, "probe handled the data");
1524 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1527 pad->priv->idle_running--;
1528 if (pad->priv->idle_running == 0) {
1529 GST_PAD_BLOCK_BROADCAST (pad);
1531 GST_OBJECT_UNLOCK (pad);
1533 gst_object_unref (pad);
1536 GST_OBJECT_UNLOCK (pad);
1542 * gst_pad_remove_probe:
1543 * @pad: the #GstPad with the probe
1544 * @id: the probe id to remove
1546 * Remove the probe with @id from @pad.
1551 gst_pad_remove_probe (GstPad * pad, gulong id)
1555 g_return_if_fail (GST_IS_PAD (pad));
1557 GST_OBJECT_LOCK (pad);
1559 hook = g_hook_get (&pad->probes, id);
1563 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1565 cleanup_hook (pad, hook);
1566 GST_OBJECT_UNLOCK (pad);
1572 GST_OBJECT_UNLOCK (pad);
1573 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1579 * gst_pad_is_blocked:
1580 * @pad: the #GstPad to query
1582 * Checks if the pad is blocked or not. This function returns the
1583 * last requested state of the pad. It is not certain that the pad
1584 * is actually blocking at this point (see gst_pad_is_blocking()).
1586 * Returns: %TRUE if the pad is blocked.
1591 gst_pad_is_blocked (GstPad * pad)
1593 gboolean result = FALSE;
1595 g_return_val_if_fail (GST_IS_PAD (pad), result);
1597 GST_OBJECT_LOCK (pad);
1598 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1599 GST_OBJECT_UNLOCK (pad);
1605 * gst_pad_is_blocking:
1606 * @pad: the #GstPad to query
1608 * Checks if the pad is blocking or not. This is a guaranteed state
1609 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1611 * Returns: %TRUE if the pad is blocking.
1616 gst_pad_is_blocking (GstPad * pad)
1618 gboolean result = FALSE;
1620 g_return_val_if_fail (GST_IS_PAD (pad), result);
1622 GST_OBJECT_LOCK (pad);
1623 /* the blocking flag is only valid if the pad is not flushing */
1624 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1625 GST_OBJECT_UNLOCK (pad);
1631 * gst_pad_needs_reconfigure:
1632 * @pad: the #GstPad to check
1634 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1635 * if the flag was set.
1637 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1640 gst_pad_needs_reconfigure (GstPad * pad)
1642 gboolean reconfigure;
1644 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1646 GST_OBJECT_LOCK (pad);
1647 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1648 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1649 GST_OBJECT_UNLOCK (pad);
1655 * gst_pad_check_reconfigure:
1656 * @pad: the #GstPad to check
1658 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1659 * if the flag was set.
1661 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1664 gst_pad_check_reconfigure (GstPad * pad)
1666 gboolean reconfigure;
1668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1670 GST_OBJECT_LOCK (pad);
1671 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1673 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1674 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1676 GST_OBJECT_UNLOCK (pad);
1682 * gst_pad_mark_reconfigure:
1683 * @pad: the #GstPad to mark
1685 * Mark a pad for needing reconfiguration. The next call to
1686 * gst_pad_check_reconfigure() will return %TRUE after this call.
1689 gst_pad_mark_reconfigure (GstPad * pad)
1691 g_return_if_fail (GST_IS_PAD (pad));
1693 GST_OBJECT_LOCK (pad);
1694 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1695 GST_OBJECT_UNLOCK (pad);
1699 * gst_pad_set_activate_function:
1701 * @f: the #GstPadActivateFunction to set.
1703 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1707 * gst_pad_set_activate_function_full:
1709 * @activate: the #GstPadActivateFunction to set.
1710 * @user_data: user_data passed to @notify
1711 * @notify: notify called when @activate will not be used anymore.
1713 * Sets the given activate function for @pad. The activate function will
1714 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1715 * Only makes sense to set on sink pads.
1717 * Call this function if your sink pad can start a pull-based task.
1720 gst_pad_set_activate_function_full (GstPad * pad,
1721 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1723 g_return_if_fail (GST_IS_PAD (pad));
1725 if (pad->activatenotify)
1726 pad->activatenotify (pad->activatedata);
1727 GST_PAD_ACTIVATEFUNC (pad) = activate;
1728 pad->activatedata = user_data;
1729 pad->activatenotify = notify;
1731 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1732 GST_DEBUG_FUNCPTR_NAME (activate));
1736 * gst_pad_set_activatemode_function:
1738 * @f: the #GstPadActivateModeFunction to set.
1740 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1744 * gst_pad_set_activatemode_function_full:
1746 * @activatemode: the #GstPadActivateModeFunction to set.
1747 * @user_data: user_data passed to @notify
1748 * @notify: notify called when @activatemode will not be used anymore.
1750 * Sets the given activate_mode function for the pad. An activate_mode function
1751 * prepares the element for data passing.
1754 gst_pad_set_activatemode_function_full (GstPad * pad,
1755 GstPadActivateModeFunction activatemode, gpointer user_data,
1756 GDestroyNotify notify)
1758 g_return_if_fail (GST_IS_PAD (pad));
1760 if (pad->activatemodenotify)
1761 pad->activatemodenotify (pad->activatemodedata);
1762 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1763 pad->activatemodedata = user_data;
1764 pad->activatemodenotify = notify;
1766 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1767 GST_DEBUG_FUNCPTR_NAME (activatemode));
1771 * gst_pad_set_chain_function:
1772 * @p: a sink #GstPad.
1773 * @f: the #GstPadChainFunction to set.
1775 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1779 * gst_pad_set_chain_function_full:
1780 * @pad: a sink #GstPad.
1781 * @chain: the #GstPadChainFunction to set.
1782 * @user_data: user_data passed to @notify
1783 * @notify: notify called when @chain will not be used anymore.
1785 * Sets the given chain function for the pad. The chain function is called to
1786 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1789 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1790 gpointer user_data, GDestroyNotify notify)
1792 g_return_if_fail (GST_IS_PAD (pad));
1793 g_return_if_fail (GST_PAD_IS_SINK (pad));
1795 if (pad->chainnotify)
1796 pad->chainnotify (pad->chaindata);
1797 GST_PAD_CHAINFUNC (pad) = chain;
1798 pad->chaindata = user_data;
1799 pad->chainnotify = notify;
1801 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1802 GST_DEBUG_FUNCPTR_NAME (chain));
1806 * gst_pad_set_chain_list_function:
1807 * @p: a sink #GstPad.
1808 * @f: the #GstPadChainListFunction to set.
1810 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1814 * gst_pad_set_chain_list_function_full:
1815 * @pad: a sink #GstPad.
1816 * @chainlist: the #GstPadChainListFunction to set.
1817 * @user_data: user_data passed to @notify
1818 * @notify: notify called when @chainlist will not be used anymore.
1820 * Sets the given chain list function for the pad. The chainlist function is
1821 * called to process a #GstBufferList input buffer list. See
1822 * #GstPadChainListFunction for more details.
1825 gst_pad_set_chain_list_function_full (GstPad * pad,
1826 GstPadChainListFunction chainlist, gpointer user_data,
1827 GDestroyNotify notify)
1829 g_return_if_fail (GST_IS_PAD (pad));
1830 g_return_if_fail (GST_PAD_IS_SINK (pad));
1832 if (pad->chainlistnotify)
1833 pad->chainlistnotify (pad->chainlistdata);
1834 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1835 pad->chainlistdata = user_data;
1836 pad->chainlistnotify = notify;
1838 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1839 GST_DEBUG_FUNCPTR_NAME (chainlist));
1843 * gst_pad_set_getrange_function:
1844 * @p: a source #GstPad.
1845 * @f: the #GstPadGetRangeFunction to set.
1847 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1851 * gst_pad_set_getrange_function_full:
1852 * @pad: a source #GstPad.
1853 * @get: the #GstPadGetRangeFunction to set.
1854 * @user_data: user_data passed to @notify
1855 * @notify: notify called when @get will not be used anymore.
1857 * Sets the given getrange function for the pad. The getrange function is
1858 * called to produce a new #GstBuffer to start the processing pipeline. see
1859 * #GstPadGetRangeFunction for a description of the getrange function.
1862 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1863 gpointer user_data, GDestroyNotify notify)
1865 g_return_if_fail (GST_IS_PAD (pad));
1866 g_return_if_fail (GST_PAD_IS_SRC (pad));
1868 if (pad->getrangenotify)
1869 pad->getrangenotify (pad->getrangedata);
1870 GST_PAD_GETRANGEFUNC (pad) = get;
1871 pad->getrangedata = user_data;
1872 pad->getrangenotify = notify;
1874 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1875 GST_DEBUG_FUNCPTR_NAME (get));
1879 * gst_pad_set_event_function:
1880 * @p: a #GstPad of either direction.
1881 * @f: the #GstPadEventFunction to set.
1883 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1887 * gst_pad_set_event_function_full:
1888 * @pad: a #GstPad of either direction.
1889 * @event: the #GstPadEventFunction to set.
1890 * @user_data: user_data passed to @notify
1891 * @notify: notify called when @event will not be used anymore.
1893 * Sets the given event handler for the pad.
1896 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1897 gpointer user_data, GDestroyNotify notify)
1899 g_return_if_fail (GST_IS_PAD (pad));
1901 if (pad->eventnotify)
1902 pad->eventnotify (pad->eventdata);
1903 GST_PAD_EVENTFUNC (pad) = event;
1904 pad->eventdata = user_data;
1905 pad->eventnotify = notify;
1907 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1908 GST_DEBUG_FUNCPTR_NAME (event));
1912 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1916 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1917 if (ret == GST_FLOW_OK)
1923 * gst_pad_set_event_full_function:
1924 * @p: a #GstPad of either direction.
1925 * @f: the #GstPadEventFullFunction to set.
1927 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1931 * gst_pad_set_event_full_function_full:
1932 * @pad: a #GstPad of either direction.
1933 * @event: the #GstPadEventFullFunction to set.
1934 * @user_data: user_data passed to @notify
1935 * @notify: notify called when @event will not be used anymore.
1937 * Sets the given event handler for the pad.
1942 gst_pad_set_event_full_function_full (GstPad * pad,
1943 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1945 g_return_if_fail (GST_IS_PAD (pad));
1947 if (pad->eventnotify)
1948 pad->eventnotify (pad->eventdata);
1949 GST_PAD_EVENTFULLFUNC (pad) = event;
1950 GST_PAD_EVENTFUNC (pad) = event_wrap;
1951 pad->eventdata = user_data;
1952 pad->eventnotify = notify;
1954 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1955 GST_DEBUG_FUNCPTR_NAME (event));
1959 * gst_pad_set_query_function:
1960 * @p: a #GstPad of either direction.
1961 * @f: the #GstPadQueryFunction to set.
1963 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1967 * gst_pad_set_query_function_full:
1968 * @pad: a #GstPad of either direction.
1969 * @query: the #GstPadQueryFunction to set.
1970 * @user_data: user_data passed to @notify
1971 * @notify: notify called when @query will not be used anymore.
1973 * Set the given query function for the pad.
1976 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1977 gpointer user_data, GDestroyNotify notify)
1979 g_return_if_fail (GST_IS_PAD (pad));
1981 if (pad->querynotify)
1982 pad->querynotify (pad->querydata);
1983 GST_PAD_QUERYFUNC (pad) = query;
1984 pad->querydata = user_data;
1985 pad->querynotify = notify;
1987 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1988 GST_DEBUG_FUNCPTR_NAME (query));
1992 * gst_pad_set_iterate_internal_links_function:
1993 * @p: a #GstPad of either direction.
1994 * @f: the #GstPadIterIntLinkFunction to set.
1996 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1997 * for the user_data and notify.
2000 * gst_pad_set_iterate_internal_links_function_full:
2001 * @pad: a #GstPad of either direction.
2002 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2003 * @user_data: user_data passed to @notify
2004 * @notify: notify called when @iterintlink will not be used anymore.
2006 * Sets the given internal link iterator function for the pad.
2009 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2010 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2011 GDestroyNotify notify)
2013 g_return_if_fail (GST_IS_PAD (pad));
2015 if (pad->iterintlinknotify)
2016 pad->iterintlinknotify (pad->iterintlinkdata);
2017 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2018 pad->iterintlinkdata = user_data;
2019 pad->iterintlinknotify = notify;
2021 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2022 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2026 * gst_pad_set_link_function:
2028 * @f: the #GstPadLinkFunction to set.
2030 * Calls gst_pad_set_link_function_full() with %NULL
2031 * for the user_data and notify.
2034 * gst_pad_set_link_function_full:
2036 * @link: the #GstPadLinkFunction to set.
2037 * @user_data: user_data passed to @notify
2038 * @notify: notify called when @link will not be used anymore.
2040 * Sets the given link function for the pad. It will be called when
2041 * the pad is linked with another pad.
2043 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2046 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2047 * cannot be made for some reason.
2049 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2050 * of the peer sink pad, if present.
2053 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2054 gpointer user_data, GDestroyNotify notify)
2056 g_return_if_fail (GST_IS_PAD (pad));
2058 if (pad->linknotify)
2059 pad->linknotify (pad->linkdata);
2060 GST_PAD_LINKFUNC (pad) = link;
2061 pad->linkdata = user_data;
2062 pad->linknotify = notify;
2064 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2065 GST_DEBUG_FUNCPTR_NAME (link));
2069 * gst_pad_set_unlink_function:
2071 * @f: the #GstPadUnlinkFunction to set.
2073 * Calls gst_pad_set_unlink_function_full() with %NULL
2074 * for the user_data and notify.
2077 * gst_pad_set_unlink_function_full:
2079 * @unlink: the #GstPadUnlinkFunction to set.
2080 * @user_data: user_data passed to @notify
2081 * @notify: notify called when @unlink will not be used anymore.
2083 * Sets the given unlink function for the pad. It will be called
2084 * when the pad is unlinked.
2087 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2088 gpointer user_data, GDestroyNotify notify)
2090 g_return_if_fail (GST_IS_PAD (pad));
2092 if (pad->unlinknotify)
2093 pad->unlinknotify (pad->unlinkdata);
2094 GST_PAD_UNLINKFUNC (pad) = unlink;
2095 pad->unlinkdata = user_data;
2096 pad->unlinknotify = notify;
2098 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2099 GST_DEBUG_FUNCPTR_NAME (unlink));
2104 * @srcpad: the source #GstPad to unlink.
2105 * @sinkpad: the sink #GstPad to unlink.
2107 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2108 * signal on both pads.
2110 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2111 * the pads were not linked together.
2116 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2118 gboolean result = FALSE;
2119 GstElement *parent = NULL;
2121 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2122 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2123 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2124 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2126 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2128 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2129 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2130 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2132 /* We need to notify the parent before taking any pad locks as the bin in
2133 * question might be waiting for a lock on the pad while holding its lock
2134 * that our message will try to take. */
2135 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2136 if (GST_IS_ELEMENT (parent)) {
2137 gst_element_post_message (parent,
2138 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2139 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2141 gst_object_unref (parent);
2146 GST_OBJECT_LOCK (srcpad);
2147 GST_OBJECT_LOCK (sinkpad);
2149 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2150 goto not_linked_together;
2152 if (GST_PAD_UNLINKFUNC (srcpad)) {
2153 GstObject *tmpparent;
2155 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2157 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2158 RELEASE_PARENT (tmpparent);
2161 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2162 GstObject *tmpparent;
2164 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2166 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2167 RELEASE_PARENT (tmpparent);
2171 /* first clear peers */
2172 GST_PAD_PEER (srcpad) = NULL;
2173 GST_PAD_PEER (sinkpad) = NULL;
2175 GST_OBJECT_UNLOCK (sinkpad);
2176 GST_OBJECT_UNLOCK (srcpad);
2178 /* fire off a signal to each of the pads telling them
2179 * that they've been unlinked */
2180 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2181 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2183 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2184 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2189 if (parent != NULL) {
2190 gst_element_post_message (parent,
2191 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2192 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2193 gst_object_unref (parent);
2195 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2199 not_linked_together:
2201 /* we do not emit a warning in this case because unlinking cannot
2202 * be made MT safe.*/
2203 GST_OBJECT_UNLOCK (sinkpad);
2204 GST_OBJECT_UNLOCK (srcpad);
2210 * gst_pad_is_linked:
2211 * @pad: pad to check
2213 * Checks if a @pad is linked to another pad or not.
2215 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2220 gst_pad_is_linked (GstPad * pad)
2224 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2226 GST_OBJECT_LOCK (pad);
2227 result = (GST_PAD_PEER (pad) != NULL);
2228 GST_OBJECT_UNLOCK (pad);
2233 /* get the caps from both pads and see if the intersection
2236 * This function should be called with the pad LOCK on both
2240 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2241 GstPadLinkCheck flags)
2243 GstCaps *srccaps = NULL;
2244 GstCaps *sinkcaps = NULL;
2245 gboolean compatible = FALSE;
2247 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2250 /* Doing the expensive caps checking takes priority over only checking the template caps */
2251 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2252 GST_OBJECT_UNLOCK (sink);
2253 GST_OBJECT_UNLOCK (src);
2255 srccaps = gst_pad_query_caps (src, NULL);
2256 sinkcaps = gst_pad_query_caps (sink, NULL);
2258 GST_OBJECT_LOCK (src);
2259 GST_OBJECT_LOCK (sink);
2261 /* If one of the two pads doesn't have a template, consider the intersection
2263 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2264 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2268 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2270 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2273 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2275 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2278 /* if we have caps on both pads we can check the intersection. If one
2279 * of the caps is %NULL, we return %TRUE. */
2280 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2282 gst_caps_unref (srccaps);
2284 gst_caps_unref (sinkcaps);
2288 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2289 gst_caps_unref (srccaps);
2290 gst_caps_unref (sinkcaps);
2293 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2294 (compatible ? "" : "not "));
2299 /* check if the grandparents of both pads are the same.
2300 * This check is required so that we don't try to link
2301 * pads from elements in different bins without ghostpads.
2303 * The LOCK should be held on both pads
2306 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2308 GstObject *psrc, *psink;
2310 psrc = GST_OBJECT_PARENT (src);
2311 psink = GST_OBJECT_PARENT (sink);
2313 /* if one of the pads has no parent, we allow the link */
2314 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2317 /* only care about parents that are elements */
2318 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2319 goto no_element_parent;
2321 /* if the parents are the same, we have a loop */
2322 if (G_UNLIKELY (psrc == psink))
2325 /* if they both have a parent, we check the grandparents. We can not lock
2326 * the parent because we hold on the child (pad) and the locking order is
2327 * parent >> child. */
2328 psrc = GST_OBJECT_PARENT (psrc);
2329 psink = GST_OBJECT_PARENT (psink);
2331 /* if they have grandparents but they are not the same */
2332 if (G_UNLIKELY (psrc != psink))
2333 goto wrong_grandparents;
2340 GST_CAT_DEBUG (GST_CAT_CAPS,
2341 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2342 GST_PTR_FORMAT, psrc, psink);
2347 GST_CAT_DEBUG (GST_CAT_CAPS,
2348 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2349 GST_PTR_FORMAT, psrc, psink);
2354 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2360 GST_CAT_DEBUG (GST_CAT_CAPS,
2361 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2362 GST_PTR_FORMAT, psrc, psink);
2367 /* FIXME leftover from an attempt at refactoring... */
2368 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2369 * the two pads will be locked in the srcpad, sinkpad order. */
2370 static GstPadLinkReturn
2371 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2373 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2374 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2376 GST_OBJECT_LOCK (srcpad);
2378 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2379 goto src_was_linked;
2381 GST_OBJECT_LOCK (sinkpad);
2383 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2384 goto sink_was_linked;
2386 /* check hierarchy, pads can only be linked if the grandparents
2388 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2389 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2390 goto wrong_hierarchy;
2392 /* check pad caps for non-empty intersection */
2393 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2396 /* FIXME check pad scheduling for non-empty intersection */
2398 return GST_PAD_LINK_OK;
2402 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2403 GST_DEBUG_PAD_NAME (srcpad),
2404 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2405 /* we do not emit a warning in this case because unlinking cannot
2406 * be made MT safe.*/
2407 GST_OBJECT_UNLOCK (srcpad);
2408 return GST_PAD_LINK_WAS_LINKED;
2412 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2413 GST_DEBUG_PAD_NAME (sinkpad),
2414 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2415 /* we do not emit a warning in this case because unlinking cannot
2416 * be made MT safe.*/
2417 GST_OBJECT_UNLOCK (sinkpad);
2418 GST_OBJECT_UNLOCK (srcpad);
2419 return GST_PAD_LINK_WAS_LINKED;
2423 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2424 GST_OBJECT_UNLOCK (sinkpad);
2425 GST_OBJECT_UNLOCK (srcpad);
2426 return GST_PAD_LINK_WRONG_HIERARCHY;
2430 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2431 GST_OBJECT_UNLOCK (sinkpad);
2432 GST_OBJECT_UNLOCK (srcpad);
2433 return GST_PAD_LINK_NOFORMAT;
2439 * @srcpad: the source #GstPad.
2440 * @sinkpad: the sink #GstPad.
2442 * Checks if the source pad and the sink pad are compatible so they can be
2445 * Returns: %TRUE if the pads can be linked.
2448 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2450 GstPadLinkReturn result;
2452 /* generic checks */
2453 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2454 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2456 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2457 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2459 /* gst_pad_link_prepare does everything for us, we only release the locks
2460 * on the pads that it gets us. If this function returns !OK the locks are not
2462 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2463 if (result != GST_PAD_LINK_OK)
2466 GST_OBJECT_UNLOCK (srcpad);
2467 GST_OBJECT_UNLOCK (sinkpad);
2470 return result == GST_PAD_LINK_OK;
2474 * gst_pad_link_full:
2475 * @srcpad: the source #GstPad to link.
2476 * @sinkpad: the sink #GstPad to link.
2477 * @flags: the checks to validate when linking
2479 * Links the source pad and the sink pad.
2481 * This variant of #gst_pad_link provides a more granular control on the
2482 * checks being done when linking. While providing some considerable speedups
2483 * the caller of this method must be aware that wrong usage of those flags
2484 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2485 * for more information.
2489 * Returns: A result code indicating if the connection worked or
2493 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2495 GstPadLinkReturn result;
2497 GstPadLinkFunction srcfunc, sinkfunc;
2499 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2500 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2501 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2502 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2503 GST_PAD_LINK_WRONG_DIRECTION);
2505 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2507 /* Notify the parent early. See gst_pad_unlink for details. */
2508 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2509 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2510 gst_element_post_message (parent,
2511 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2512 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2514 gst_object_unref (parent);
2519 /* prepare will also lock the two pads */
2520 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2522 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2523 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2524 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2525 gst_pad_link_get_name (result));
2529 /* must set peers before calling the link function */
2530 GST_PAD_PEER (srcpad) = sinkpad;
2531 GST_PAD_PEER (sinkpad) = srcpad;
2533 /* check events, when something is different, mark pending */
2534 schedule_events (srcpad, sinkpad);
2536 /* get the link functions */
2537 srcfunc = GST_PAD_LINKFUNC (srcpad);
2538 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2540 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2541 /* custom link functions, execute them */
2542 GST_OBJECT_UNLOCK (sinkpad);
2543 GST_OBJECT_UNLOCK (srcpad);
2546 GstObject *tmpparent;
2548 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2549 /* this one will call the peer link function */
2550 result = srcfunc (srcpad, tmpparent, sinkpad);
2551 RELEASE_PARENT (tmpparent);
2552 } else if (sinkfunc) {
2553 GstObject *tmpparent;
2555 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2556 /* if no source link function, we need to call the sink link
2557 * function ourselves. */
2558 result = sinkfunc (sinkpad, tmpparent, srcpad);
2559 RELEASE_PARENT (tmpparent);
2563 GST_OBJECT_LOCK (srcpad);
2564 GST_OBJECT_LOCK (sinkpad);
2566 /* we released the lock, check if the same pads are linked still */
2567 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2568 goto concurrent_link;
2570 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2573 GST_OBJECT_UNLOCK (sinkpad);
2574 GST_OBJECT_UNLOCK (srcpad);
2576 /* fire off a signal to each of the pads telling them
2577 * that they've been linked */
2578 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2579 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2581 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2582 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2584 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2585 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2588 if (G_LIKELY (parent)) {
2589 gst_element_post_message (parent,
2590 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2591 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2592 gst_object_unref (parent);
2595 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2601 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2602 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2603 GST_OBJECT_UNLOCK (sinkpad);
2604 GST_OBJECT_UNLOCK (srcpad);
2606 /* The other link operation succeeded first */
2607 result = GST_PAD_LINK_WAS_LINKED;
2612 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2613 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2614 gst_pad_link_get_name (result));
2616 GST_PAD_PEER (srcpad) = NULL;
2617 GST_PAD_PEER (sinkpad) = NULL;
2619 GST_OBJECT_UNLOCK (sinkpad);
2620 GST_OBJECT_UNLOCK (srcpad);
2628 * @srcpad: the source #GstPad to link.
2629 * @sinkpad: the sink #GstPad to link.
2631 * Links the source pad and the sink pad.
2633 * Returns: A result code indicating if the connection worked or
2639 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2641 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2645 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2647 GstPadTemplate **template_p;
2649 /* this function would need checks if it weren't static */
2651 GST_OBJECT_LOCK (pad);
2652 template_p = &pad->padtemplate;
2653 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2654 GST_OBJECT_UNLOCK (pad);
2657 gst_pad_template_pad_created (templ, pad);
2661 * gst_pad_get_pad_template:
2664 * Gets the template for @pad.
2666 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2667 * this pad was instantiated, or %NULL if this pad has no
2668 * template. Unref after usage.
2671 gst_pad_get_pad_template (GstPad * pad)
2673 GstPadTemplate *templ;
2675 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2677 templ = GST_PAD_PAD_TEMPLATE (pad);
2679 return (templ ? gst_object_ref (templ) : NULL);
2683 * gst_pad_has_current_caps:
2684 * @pad: a #GstPad to check
2686 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2688 * Returns: %TRUE when @pad has caps associated with it.
2691 gst_pad_has_current_caps (GstPad * pad)
2696 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2698 GST_OBJECT_LOCK (pad);
2699 caps = get_pad_caps (pad);
2700 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2701 "check current pad caps %" GST_PTR_FORMAT, caps);
2702 result = (caps != NULL);
2703 GST_OBJECT_UNLOCK (pad);
2709 * gst_pad_get_current_caps:
2710 * @pad: a #GstPad to get the current capabilities of.
2712 * Gets the capabilities currently configured on @pad with the last
2713 * #GST_EVENT_CAPS event.
2715 * Returns: (transfer full) (nullable): the current caps of the pad with
2716 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2719 gst_pad_get_current_caps (GstPad * pad)
2723 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2725 GST_OBJECT_LOCK (pad);
2726 if ((result = get_pad_caps (pad)))
2727 gst_caps_ref (result);
2728 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2729 "get current pad caps %" GST_PTR_FORMAT, result);
2730 GST_OBJECT_UNLOCK (pad);
2736 * gst_pad_get_pad_template_caps:
2737 * @pad: a #GstPad to get the template capabilities from.
2739 * Gets the capabilities for @pad's template.
2741 * Returns: (transfer full): the #GstCaps of this pad template.
2742 * Unref after usage.
2745 gst_pad_get_pad_template_caps (GstPad * pad)
2747 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2749 if (GST_PAD_PAD_TEMPLATE (pad))
2750 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2752 return gst_caps_ref (GST_CAPS_ANY);
2757 * @pad: a #GstPad to get the peer of.
2759 * Gets the peer of @pad. This function refs the peer pad so
2760 * you need to unref it after use.
2762 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2767 gst_pad_get_peer (GstPad * pad)
2771 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2773 GST_OBJECT_LOCK (pad);
2774 result = GST_PAD_PEER (pad);
2776 gst_object_ref (result);
2777 GST_OBJECT_UNLOCK (pad);
2783 * gst_pad_get_allowed_caps:
2786 * Gets the capabilities of the allowed media types that can flow through
2787 * @pad and its peer.
2789 * The allowed capabilities is calculated as the intersection of the results of
2790 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2791 * on the resulting caps.
2793 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2794 * pad link. Unref the caps when you no longer need it. This
2795 * function returns %NULL when @pad has no peer.
2800 gst_pad_get_allowed_caps (GstPad * pad)
2803 GstCaps *caps = NULL;
2806 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2808 GST_OBJECT_LOCK (pad);
2809 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2811 GST_OBJECT_UNLOCK (pad);
2813 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2815 mycaps = gst_pad_query_caps (pad, NULL);
2817 /* Query peer caps */
2818 query = gst_query_new_caps (mycaps);
2819 if (!gst_pad_peer_query (pad, query)) {
2820 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2824 gst_query_parse_caps_result (query, &caps);
2826 g_warn_if_fail (caps != NULL);
2829 gst_caps_ref (caps);
2831 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2835 gst_query_unref (query);
2836 gst_caps_unref (mycaps);
2842 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2843 GST_OBJECT_UNLOCK (pad);
2850 * gst_pad_iterate_internal_links_default:
2851 * @pad: the #GstPad to get the internal links of.
2852 * @parent: (allow-none): the parent of @pad or %NULL
2854 * Iterate the list of pads to which the given pad is linked to inside of
2855 * the parent element.
2856 * This is the default handler, and thus returns an iterator of all of the
2857 * pads inside the parent element with opposite direction.
2859 * The caller must free this iterator after use with gst_iterator_free().
2861 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2862 * has no parent. Unref each returned pad with gst_object_unref().
2865 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2872 GstElement *eparent;
2874 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2876 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2877 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2879 GST_OBJECT_LOCK (pad);
2880 eparent = GST_PAD_PARENT (pad);
2881 if (!eparent || !GST_IS_ELEMENT (eparent))
2884 gst_object_ref (eparent);
2885 GST_OBJECT_UNLOCK (pad);
2888 if (pad->direction == GST_PAD_SRC)
2889 padlist = &eparent->sinkpads;
2891 padlist = &eparent->srcpads;
2893 GST_DEBUG_OBJECT (pad, "Making iterator");
2895 cookie = &eparent->pads_cookie;
2897 lock = GST_OBJECT_GET_LOCK (eparent);
2899 res = gst_iterator_new_list (GST_TYPE_PAD,
2900 lock, cookie, padlist, (GObject *) owner, NULL);
2902 gst_object_unref (owner);
2909 GST_OBJECT_UNLOCK (pad);
2910 GST_DEBUG_OBJECT (pad, "no parent element");
2916 * gst_pad_iterate_internal_links:
2917 * @pad: the GstPad to get the internal links of.
2919 * Gets an iterator for the pads to which the given pad is linked to inside
2920 * of the parent element.
2922 * Each #GstPad element yielded by the iterator will have its refcount increased,
2923 * so unref after use.
2925 * Free-function: gst_iterator_free
2927 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2928 * or %NULL when the pad does not have an iterator function
2929 * configured. Use gst_iterator_free() after usage.
2932 gst_pad_iterate_internal_links (GstPad * pad)
2934 GstIterator *res = NULL;
2937 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2939 GST_OBJECT_LOCK (pad);
2940 ACQUIRE_PARENT (pad, parent, no_parent);
2941 GST_OBJECT_UNLOCK (pad);
2943 if (GST_PAD_ITERINTLINKFUNC (pad))
2944 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2946 RELEASE_PARENT (parent);
2953 GST_DEBUG_OBJECT (pad, "no parent");
2954 GST_OBJECT_UNLOCK (pad);
2962 * @forward: (scope call): a #GstPadForwardFunction
2963 * @user_data: user data passed to @forward
2965 * Calls @forward for all internally linked pads of @pad. This function deals with
2966 * dynamically changing internal pads and will make sure that the @forward
2967 * function is only called once for each pad.
2969 * When @forward returns %TRUE, no further pads will be processed.
2971 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2974 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2977 gboolean result = FALSE;
2979 gboolean done = FALSE;
2980 GValue item = { 0, };
2981 GList *pushed_pads = NULL;
2983 iter = gst_pad_iterate_internal_links (pad);
2989 switch (gst_iterator_next (iter, &item)) {
2990 case GST_ITERATOR_OK:
2994 intpad = g_value_get_object (&item);
2996 /* if already pushed, skip. FIXME, find something faster to tag pads */
2997 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2998 g_value_reset (&item);
3002 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3003 GST_DEBUG_PAD_NAME (intpad));
3004 done = result = forward (intpad, user_data);
3006 pushed_pads = g_list_prepend (pushed_pads, intpad);
3008 g_value_reset (&item);
3011 case GST_ITERATOR_RESYNC:
3012 /* We don't reset the result here because we don't push the event
3013 * again on pads that got the event already and because we need
3014 * to consider the result of the previous pushes */
3015 gst_iterator_resync (iter);
3017 case GST_ITERATOR_ERROR:
3018 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3021 case GST_ITERATOR_DONE:
3026 g_value_unset (&item);
3027 gst_iterator_free (iter);
3029 g_list_free (pushed_pads);
3039 gboolean dispatched;
3043 event_forward_func (GstPad * pad, EventData * data)
3045 /* for each pad we send to, we should ref the event; it's up
3046 * to downstream to unref again when handled. */
3047 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3048 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3050 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3052 data->dispatched = TRUE;
3059 * gst_pad_event_default:
3060 * @pad: a #GstPad to call the default event handler on.
3061 * @parent: (allow-none): the parent of @pad or %NULL
3062 * @event: (transfer full): the #GstEvent to handle.
3064 * Invokes the default event handler for the given pad.
3066 * The EOS event will pause the task associated with @pad before it is forwarded
3067 * to all internally linked pads,
3069 * The event is sent to all pads internally linked to @pad. This function
3070 * takes ownership of @event.
3072 * Returns: %TRUE if the event was sent successfully.
3075 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3077 gboolean result, forward = TRUE;
3079 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3080 g_return_val_if_fail (event != NULL, FALSE);
3082 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3085 switch (GST_EVENT_TYPE (event)) {
3086 case GST_EVENT_CAPS:
3087 forward = GST_PAD_IS_PROXY_CAPS (pad);
3098 data.dispatched = FALSE;
3099 data.result = FALSE;
3101 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3103 /* for sinkpads without a parent element or without internal links, nothing
3104 * will be dispatched but we still want to return TRUE. */
3105 if (data.dispatched)
3106 result = data.result;
3111 gst_event_unref (event);
3116 /* Default accept caps implementation just checks against
3117 * the allowed caps for the pad */
3119 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3121 /* get the caps and see if it intersects to something not empty */
3122 GstCaps *caps, *allowed = NULL;
3125 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3127 /* first forward the query to internally linked pads when we are dealing with
3129 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3130 result = gst_pad_proxy_query_accept_caps (pad, query);
3132 allowed = gst_pad_get_pad_template_caps (pad);
3137 gst_query_parse_accept_caps (query, &caps);
3139 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3140 allowed = gst_pad_get_pad_template_caps (pad);
3142 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3143 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3144 allowed = gst_pad_query_caps (pad, caps);
3149 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3150 GST_DEBUG_OBJECT (pad,
3151 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3153 result = gst_caps_can_intersect (caps, allowed);
3155 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3156 GST_PTR_FORMAT, allowed, caps);
3157 result = gst_caps_is_subset (caps, allowed);
3159 gst_caps_unref (allowed);
3161 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3164 gst_query_set_accept_caps_result (query, result);
3170 /* Default caps implementation */
3172 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3174 GstCaps *result = NULL, *filter;
3175 GstPadTemplate *templ;
3176 gboolean fixed_caps;
3178 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3181 /* first try to proxy if we must */
3182 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3183 if ((gst_pad_proxy_query_caps (pad, query))) {
3188 gst_query_parse_caps (query, &filter);
3190 /* no proxy or it failed, do default handling */
3191 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3193 GST_OBJECT_LOCK (pad);
3195 /* fixed caps, try the negotiated caps first */
3196 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3197 if ((result = get_pad_caps (pad)))
3198 goto filter_done_unlock;
3201 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3202 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3203 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3204 goto filter_done_unlock;
3208 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3209 "non-fixed pad caps: trying pad caps");
3210 /* non fixed caps, try the negotiated caps */
3211 if ((result = get_pad_caps (pad)))
3212 goto filter_done_unlock;
3215 /* this almost never happens */
3216 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3217 result = GST_CAPS_ANY;
3220 GST_OBJECT_UNLOCK (pad);
3222 /* run the filter on the result */
3224 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3225 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3226 GST_PTR_FORMAT, result, result, filter, filter);
3227 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3231 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3232 "using caps %p %" GST_PTR_FORMAT, result, result);
3233 result = gst_caps_ref (result);
3235 gst_query_set_caps_result (query, result);
3236 gst_caps_unref (result);
3242 /* Default latency implementation */
3247 GstClockTime min, max;
3251 query_latency_default_fold (const GValue * item, GValue * ret,
3254 GstPad *pad = g_value_get_object (item), *peer;
3255 LatencyFoldData *fold_data = user_data;
3257 gboolean res = FALSE;
3259 query = gst_query_new_latency ();
3261 peer = gst_pad_get_peer (pad);
3263 res = gst_pad_peer_query (pad, query);
3265 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3270 GstClockTime min, max;
3272 gst_query_parse_latency (query, &live, &min, &max);
3274 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3275 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3277 /* FIXME : Why do we only take values into account if it's live ? */
3278 if (live || fold_data->count == 0) {
3279 if (min > fold_data->min)
3280 fold_data->min = min;
3282 if (fold_data->max == GST_CLOCK_TIME_NONE)
3283 fold_data->max = max;
3284 else if (max < fold_data->max)
3285 fold_data->max = max;
3287 fold_data->live = live;
3289 fold_data->count += 1;
3291 GST_DEBUG_OBJECT (pad, "latency query failed");
3292 g_value_set_boolean (ret, FALSE);
3295 gst_query_unref (query);
3297 gst_object_unref (peer);
3303 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3306 GstIteratorResult res;
3307 GValue ret = G_VALUE_INIT;
3309 LatencyFoldData fold_data;
3311 it = gst_pad_iterate_internal_links (pad);
3313 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3317 g_value_init (&ret, G_TYPE_BOOLEAN);
3320 fold_data.count = 0;
3321 fold_data.live = FALSE;
3323 fold_data.max = GST_CLOCK_TIME_NONE;
3325 g_value_set_boolean (&ret, TRUE);
3326 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3328 case GST_ITERATOR_OK:
3329 g_assert_not_reached ();
3331 case GST_ITERATOR_DONE:
3333 case GST_ITERATOR_ERROR:
3334 g_value_set_boolean (&ret, FALSE);
3336 case GST_ITERATOR_RESYNC:
3337 gst_iterator_resync (it);
3340 g_assert_not_reached ();
3343 gst_iterator_free (it);
3345 query_ret = g_value_get_boolean (&ret);
3347 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3348 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3349 fold_data.min, fold_data.max);
3351 if (fold_data.min > fold_data.max) {
3352 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3355 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3357 GST_LOG_OBJECT (pad, "latency query failed");
3367 gboolean dispatched;
3371 query_forward_func (GstPad * pad, QueryData * data)
3373 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3374 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3376 data->result |= gst_pad_peer_query (pad, data->query);
3378 data->dispatched = TRUE;
3380 /* stop on first successful reply */
3381 return data->result;
3385 * gst_pad_query_default:
3386 * @pad: a #GstPad to call the default query handler on.
3387 * @parent: (allow-none): the parent of @pad or %NULL
3388 * @query: (transfer none): the #GstQuery to handle.
3390 * Invokes the default query handler for the given pad.
3391 * The query is sent to all pads internally linked to @pad. Note that
3392 * if there are many possible sink pads that are internally linked to
3393 * @pad, only one will be sent the query.
3394 * Multi-sinkpad elements should implement custom query handlers.
3396 * Returns: %TRUE if the query was performed successfully.
3399 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3401 gboolean forward, ret = FALSE;
3403 switch (GST_QUERY_TYPE (query)) {
3404 case GST_QUERY_SCHEDULING:
3405 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3407 case GST_QUERY_ALLOCATION:
3408 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3410 case GST_QUERY_ACCEPT_CAPS:
3411 ret = gst_pad_query_accept_caps_default (pad, query);
3414 case GST_QUERY_CAPS:
3415 ret = gst_pad_query_caps_default (pad, query);
3418 case GST_QUERY_LATENCY:
3419 ret = gst_pad_query_latency_default (pad, query);
3422 case GST_QUERY_POSITION:
3423 case GST_QUERY_SEEKING:
3424 case GST_QUERY_FORMATS:
3425 case GST_QUERY_JITTER:
3426 case GST_QUERY_RATE:
3427 case GST_QUERY_CONVERT:
3433 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3434 query, GST_QUERY_TYPE_NAME (query));
3440 data.dispatched = FALSE;
3441 data.result = FALSE;
3443 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3445 if (data.dispatched) {
3448 /* nothing dispatched, assume drained */
3449 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3459 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3461 GstPad *pad = data->pad;
3462 GstPadProbeInfo *info = data->info;
3463 GstPadProbeType type, flags;
3464 GstPadProbeCallback callback;
3465 GstPadProbeReturn ret;
3466 gpointer original_data;
3468 /* if we have called this callback, do nothing */
3469 if (PROBE_COOKIE (hook) == data->cookie) {
3470 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3471 "hook %lu, cookie %u already called", hook->hook_id,
3472 PROBE_COOKIE (hook));
3476 PROBE_COOKIE (hook) = data->cookie;
3478 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3480 original_data = info->data;
3482 /* one of the scheduling types */
3483 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3486 if (G_UNLIKELY (data->handled)) {
3487 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3488 "probe previously returned HANDLED, not calling again");
3490 } else if (G_UNLIKELY (data->dropped)) {
3491 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3492 "probe previously returned DROPPED, not calling again");
3496 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3497 /* one of the data types for non-idle probes */
3498 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3499 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3501 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3502 /* one of the data types for non-idle probes */
3503 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3504 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3507 /* Type must have PULL or PUSH probe types */
3508 g_assert_not_reached ();
3511 /* one of the blocking types must match */
3512 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3513 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3515 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3516 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3518 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3519 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3520 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3523 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3524 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3525 PROBE_COOKIE (hook), flags);
3527 data->marshalled = TRUE;
3529 callback = (GstPadProbeCallback) hook->func;
3530 if (callback == NULL)
3533 info->id = hook->hook_id;
3535 GST_OBJECT_UNLOCK (pad);
3537 ret = callback (pad, info, hook->data);
3539 GST_OBJECT_LOCK (pad);
3541 if (original_data != NULL && info->data == NULL) {
3542 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3543 info->type = GST_PAD_PROBE_TYPE_INVALID;
3544 data->dropped = TRUE;
3548 case GST_PAD_PROBE_REMOVE:
3549 /* remove the probe */
3550 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3551 cleanup_hook (pad, hook);
3553 case GST_PAD_PROBE_DROP:
3554 /* need to drop the data, make sure other probes don't get called
3556 GST_DEBUG_OBJECT (pad, "asked to drop item");
3557 info->type = GST_PAD_PROBE_TYPE_INVALID;
3558 data->dropped = TRUE;
3560 case GST_PAD_PROBE_HANDLED:
3561 GST_DEBUG_OBJECT (pad, "probe handled data");
3562 data->handled = TRUE;
3564 case GST_PAD_PROBE_PASS:
3565 /* inform the pad block to let things pass */
3566 GST_DEBUG_OBJECT (pad, "asked to pass item");
3569 case GST_PAD_PROBE_OK:
3570 GST_DEBUG_OBJECT (pad, "probe returned OK");
3573 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3580 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3581 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3582 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3587 /* a probe that does not take or return any data */
3588 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3590 if (G_UNLIKELY (pad->num_probes)) { \
3591 GstFlowReturn pval = defaultval; \
3592 /* pass NULL as the data item */ \
3593 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3594 info.ABI.abi.flow_ret = defaultval; \
3595 ret = do_probe_callbacks (pad, &info, defaultval); \
3596 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3601 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3603 if (G_UNLIKELY (pad->num_probes)) { \
3604 /* pass the data item */ \
3605 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3606 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3607 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3608 /* store the possibly updated data item */ \
3609 data = GST_PAD_PROBE_INFO_DATA (&info); \
3610 /* if something went wrong, exit */ \
3611 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3612 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3613 ret = info.ABI.abi.flow_ret; \
3614 goto handle_label; \
3621 #define PROBE_PUSH(pad,mask,data,label) \
3622 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3623 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3624 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3625 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3626 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3628 static GstFlowReturn
3629 do_pad_idle_probe_wait (GstPad * pad)
3631 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3632 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3633 "waiting idle probe to be removed");
3634 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3635 GST_PAD_BLOCK_WAIT (pad);
3636 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3637 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3639 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3640 return GST_FLOW_FLUSHING;
3645 #define PROBE_TYPE_IS_SERIALIZED(i) \
3648 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3649 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3650 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3652 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3653 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3655 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3656 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3660 static GstFlowReturn
3661 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3662 GstFlowReturn defaultval)
3671 data.handled = FALSE;
3672 data.marshalled = FALSE;
3673 data.dropped = FALSE;
3674 data.cookie = ++pad->priv->probe_cookie;
3677 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3679 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3680 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3685 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3686 "do probes cookie %u", data.cookie);
3687 cookie = pad->priv->probe_list_cookie;
3689 g_hook_list_marshal (&pad->probes, TRUE,
3690 (GHookMarshaller) probe_hook_marshal, &data);
3692 /* if the list changed, call the new callbacks (they will not have their
3693 * cookie set to data.cookie */
3694 if (cookie != pad->priv->probe_list_cookie) {
3695 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3696 "probe list changed, restarting");
3700 /* the first item that dropped will stop the hooks and then we drop here */
3704 /* If one handler took care of it, let the the item pass */
3709 /* if no handler matched and we are blocking, let the item pass */
3710 if (!data.marshalled && is_block)
3713 /* At this point, all handlers returned either OK or PASS. If one handler
3714 * returned PASS, let the item pass */
3719 while (GST_PAD_IS_BLOCKED (pad)) {
3720 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3721 "we are blocked %d times", pad->num_blocked);
3723 /* we might have released the lock */
3724 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3727 /* now we block the streaming thread. It can be unlocked when we
3728 * deactivate the pad (which will also set the FLUSHING flag) or
3729 * when the pad is unblocked. A flushing event will also unblock
3730 * the pad after setting the FLUSHING flag. */
3731 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3732 "Waiting to be unblocked or set flushing");
3733 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3734 GST_PAD_BLOCK_WAIT (pad);
3735 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3736 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3738 /* if the list changed, call the new callbacks (they will not have their
3739 * cookie set to data.cookie */
3740 if (cookie != pad->priv->probe_list_cookie) {
3741 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3742 "probe list changed, restarting");
3746 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3756 GST_DEBUG_OBJECT (pad, "pad is flushing");
3757 return GST_FLOW_FLUSHING;
3761 GST_DEBUG_OBJECT (pad, "data is dropped");
3762 return GST_FLOW_CUSTOM_SUCCESS;
3766 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3767 GST_DEBUG_OBJECT (pad, "data is passed");
3772 GST_DEBUG_OBJECT (pad, "data was handled");
3773 return GST_FLOW_CUSTOM_SUCCESS_1;
3780 * gst_pad_get_offset:
3783 * Get the offset applied to the running time of @pad. @pad has to be a source
3786 * Returns: the offset.
3789 gst_pad_get_offset (GstPad * pad)
3793 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3795 GST_OBJECT_LOCK (pad);
3796 result = pad->offset;
3797 GST_OBJECT_UNLOCK (pad);
3803 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3805 ev->received = FALSE;
3810 * gst_pad_set_offset:
3812 * @offset: the offset
3814 * Set the offset that will be applied to the running time of @pad.
3817 gst_pad_set_offset (GstPad * pad, gint64 offset)
3819 g_return_if_fail (GST_IS_PAD (pad));
3821 GST_OBJECT_LOCK (pad);
3822 /* if nothing changed, do nothing */
3823 if (pad->offset == offset)
3826 pad->offset = offset;
3827 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3828 GST_STIME_ARGS (offset));
3830 /* resend all sticky events with updated offset on next buffer push */
3831 events_foreach (pad, mark_event_not_received, NULL);
3832 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3835 GST_OBJECT_UNLOCK (pad);
3842 /* If TRUE and ret is not OK this means
3843 * that pushing the EOS event failed
3847 /* If called for an event this is
3848 * the event that would be pushed
3849 * next. Don't forward sticky events
3850 * that would come after that */
3854 /* should be called with pad LOCK */
3856 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3858 PushStickyData *data = user_data;
3859 GstEvent *event = ev->event;
3862 GST_DEBUG_OBJECT (pad, "event %s was already received",
3863 GST_EVENT_TYPE_NAME (event));
3867 /* If we're called because of an sticky event, only forward
3868 * events that would come before this new event and the
3870 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3871 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3872 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3873 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3875 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3876 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3877 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3878 data->ret = GST_FLOW_OK;
3881 switch (data->ret) {
3883 ev->received = TRUE;
3884 GST_DEBUG_OBJECT (pad, "event %s marked received",
3885 GST_EVENT_TYPE_NAME (event));
3887 case GST_FLOW_CUSTOM_SUCCESS:
3888 /* we can't assume the event is received when it was dropped */
3889 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3890 GST_EVENT_TYPE_NAME (event));
3891 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3892 data->ret = GST_FLOW_OK;
3894 case GST_FLOW_CUSTOM_SUCCESS_1:
3895 /* event was ignored and should be sent later */
3896 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3897 GST_EVENT_TYPE_NAME (event));
3898 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3899 data->ret = GST_FLOW_OK;
3901 case GST_FLOW_NOT_LINKED:
3902 /* not linked is not a problem, we are sticky so the event will be
3903 * rescheduled to be sent later on re-link, but only for non-EOS events */
3904 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3905 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3906 data->ret = GST_FLOW_OK;
3907 ev->received = TRUE;
3911 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3912 gst_flow_get_name (data->ret));
3913 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3917 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3918 data->was_eos = TRUE;
3920 return data->ret == GST_FLOW_OK;
3923 /* check sticky events and push them when needed. should be called
3925 static inline GstFlowReturn
3926 check_sticky (GstPad * pad, GstEvent * event)
3928 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3930 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3931 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3933 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3934 events_foreach (pad, push_sticky, &data);
3936 /* If there's an EOS event we must push it downstream
3937 * even if sending a previous sticky event failed.
3938 * Otherwise the pipeline might wait forever for EOS.
3940 * Only do this if pushing another event than the EOS
3943 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3944 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3946 if (ev && !ev->received) {
3947 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3948 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3949 /* the event could have been dropped. Because this can only
3950 * happen if the user asked for it, it's not an error */
3951 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3952 data.ret = GST_FLOW_OK;
3962 * @pad: a #GstPad to invoke the default query on.
3963 * @query: (transfer none): the #GstQuery to perform.
3965 * Dispatches a query to a pad. The query should have been allocated by the
3966 * caller via one of the type-specific allocation functions. The element that
3967 * the pad belongs to is responsible for filling the query with an appropriate
3968 * response, which should then be parsed with a type-specific query parsing
3971 * Again, the caller is responsible for both the allocation and deallocation of
3972 * the query structure.
3974 * Please also note that some queries might need a running pipeline to work.
3976 * Returns: %TRUE if the query could be performed.
3979 gst_pad_query (GstPad * pad, GstQuery * query)
3982 gboolean res, serialized;
3983 GstPadQueryFunction func;
3984 GstPadProbeType type;
3987 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3988 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3990 if (GST_PAD_IS_SRC (pad)) {
3991 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3992 goto wrong_direction;
3993 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3994 } else if (GST_PAD_IS_SINK (pad)) {
3995 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3996 goto wrong_direction;
3997 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3999 goto unknown_direction;
4001 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4002 GST_QUERY_TYPE_NAME (query));
4003 GST_TRACER_PAD_QUERY_PRE (pad, query);
4005 serialized = GST_QUERY_IS_SERIALIZED (query);
4006 if (G_UNLIKELY (serialized))
4007 GST_PAD_STREAM_LOCK (pad);
4009 GST_OBJECT_LOCK (pad);
4010 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4011 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4012 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4014 ACQUIRE_PARENT (pad, parent, no_parent);
4015 GST_OBJECT_UNLOCK (pad);
4017 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4020 res = func (pad, parent, query);
4022 RELEASE_PARENT (parent);
4024 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4025 GST_QUERY_TYPE_NAME (query), res);
4026 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4031 GST_OBJECT_LOCK (pad);
4032 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4033 GST_OBJECT_UNLOCK (pad);
4035 if (G_UNLIKELY (serialized))
4036 GST_PAD_STREAM_UNLOCK (pad);
4043 g_warning ("pad %s:%s query %s in wrong direction",
4044 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4049 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4054 GST_DEBUG_OBJECT (pad, "had no parent");
4055 GST_OBJECT_UNLOCK (pad);
4056 if (G_UNLIKELY (serialized))
4057 GST_PAD_STREAM_UNLOCK (pad);
4062 GST_DEBUG_OBJECT (pad, "had no query function");
4063 RELEASE_PARENT (parent);
4064 if (G_UNLIKELY (serialized))
4065 GST_PAD_STREAM_UNLOCK (pad);
4070 GST_DEBUG_OBJECT (pad, "query failed");
4071 if (G_UNLIKELY (serialized))
4072 GST_PAD_STREAM_UNLOCK (pad);
4077 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4078 GST_OBJECT_UNLOCK (pad);
4079 if (G_UNLIKELY (serialized))
4080 GST_PAD_STREAM_UNLOCK (pad);
4082 /* if a probe dropped without handling, we don't sent it further but assume
4083 * that the probe did not answer the query and return FALSE */
4084 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4094 * gst_pad_peer_query:
4095 * @pad: a #GstPad to invoke the peer query on.
4096 * @query: (transfer none): the #GstQuery to perform.
4098 * Performs gst_pad_query() on the peer of @pad.
4100 * The caller is responsible for both the allocation and deallocation of
4101 * the query structure.
4103 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4104 * if @pad has no peer.
4107 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4110 GstPadProbeType type;
4111 gboolean res, serialized;
4114 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4115 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4117 if (GST_PAD_IS_SRC (pad)) {
4118 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4119 goto wrong_direction;
4120 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4121 } else if (GST_PAD_IS_SINK (pad)) {
4122 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4123 goto wrong_direction;
4124 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4126 goto unknown_direction;
4128 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4129 GST_QUERY_TYPE_NAME (query));
4131 serialized = GST_QUERY_IS_SERIALIZED (query);
4133 GST_OBJECT_LOCK (pad);
4134 if (GST_PAD_IS_SRC (pad) && serialized) {
4135 /* all serialized queries on the srcpad trigger push of
4137 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4141 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4142 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4143 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4145 peerpad = GST_PAD_PEER (pad);
4146 if (G_UNLIKELY (peerpad == NULL))
4149 gst_object_ref (peerpad);
4150 GST_OBJECT_UNLOCK (pad);
4152 res = gst_pad_query (peerpad, query);
4154 gst_object_unref (peerpad);
4159 GST_OBJECT_LOCK (pad);
4160 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4161 GST_OBJECT_UNLOCK (pad);
4168 g_warning ("pad %s:%s query %s in wrong direction",
4169 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4174 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4179 GST_WARNING_OBJECT (pad, "could not send sticky events");
4180 GST_OBJECT_UNLOCK (pad);
4185 GST_INFO_OBJECT (pad, "pad has no peer");
4186 GST_OBJECT_UNLOCK (pad);
4191 GST_DEBUG_OBJECT (pad, "query failed");
4196 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4197 GST_OBJECT_UNLOCK (pad);
4199 /* if a probe dropped without handling, we don't sent it further but
4200 * assume that the probe did not answer the query and return FALSE */
4201 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4210 /**********************************************************************
4211 * Data passing functions
4214 /* this is the chain function that does not perform the additional argument
4215 * checking for that little extra speed.
4217 static inline GstFlowReturn
4218 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4222 gboolean handled = FALSE;
4224 GST_PAD_STREAM_LOCK (pad);
4226 GST_OBJECT_LOCK (pad);
4227 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4230 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4233 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4236 #ifdef GST_ENABLE_EXTRA_CHECKS
4237 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4238 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4240 ":%s:<%s:%s> Got data flow before stream-start event",
4241 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4243 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4245 ":%s:<%s:%s> Got data flow before segment event",
4246 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4248 pad->priv->last_cookie = pad->priv->events_cookie;
4252 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4255 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4257 ACQUIRE_PARENT (pad, parent, no_parent);
4258 GST_OBJECT_UNLOCK (pad);
4260 /* NOTE: we read the chainfunc unlocked.
4261 * we cannot hold the lock for the pad so we might send
4262 * the data to the wrong function. This is not really a
4263 * problem since functions are assigned at creation time
4264 * and don't change that often... */
4265 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4266 GstPadChainFunction chainfunc;
4268 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4271 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4272 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4273 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4275 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4277 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4278 "called chainfunction &%s with buffer %p, returned %s",
4279 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4281 GstPadChainListFunction chainlistfunc;
4283 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4286 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4287 "calling chainlistfunction &%s",
4288 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4290 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4292 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4293 "called chainlistfunction &%s, returned %s",
4294 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4297 RELEASE_PARENT (parent);
4299 GST_PAD_STREAM_UNLOCK (pad);
4306 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4307 "chaining, but pad was flushing");
4308 GST_OBJECT_UNLOCK (pad);
4309 GST_PAD_STREAM_UNLOCK (pad);
4310 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4311 return GST_FLOW_FLUSHING;
4315 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4316 GST_OBJECT_UNLOCK (pad);
4317 GST_PAD_STREAM_UNLOCK (pad);
4318 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4319 return GST_FLOW_EOS;
4323 g_critical ("chain on pad %s:%s but it was not in push mode",
4324 GST_DEBUG_PAD_NAME (pad));
4325 GST_OBJECT_UNLOCK (pad);
4326 GST_PAD_STREAM_UNLOCK (pad);
4327 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4328 return GST_FLOW_ERROR;
4335 GST_OBJECT_UNLOCK (pad);
4336 GST_PAD_STREAM_UNLOCK (pad);
4337 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4339 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4342 case GST_FLOW_CUSTOM_SUCCESS:
4343 case GST_FLOW_CUSTOM_SUCCESS_1:
4344 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4348 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4355 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4356 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4357 GST_OBJECT_UNLOCK (pad);
4358 GST_PAD_STREAM_UNLOCK (pad);
4359 return GST_FLOW_FLUSHING;
4363 RELEASE_PARENT (parent);
4364 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4365 g_critical ("chain on pad %s:%s but it has no chainfunction",
4366 GST_DEBUG_PAD_NAME (pad));
4367 GST_PAD_STREAM_UNLOCK (pad);
4368 return GST_FLOW_NOT_SUPPORTED;
4374 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4375 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4378 * Chain a buffer to @pad.
4380 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4382 * If the buffer type is not acceptable for @pad (as negotiated with a
4383 * preceding GST_EVENT_CAPS event), this function returns
4384 * #GST_FLOW_NOT_NEGOTIATED.
4386 * The function proceeds calling the chain function installed on @pad (see
4387 * gst_pad_set_chain_function()) and the return value of that function is
4388 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4391 * In all cases, success or failure, the caller loses its reference to @buffer
4392 * after calling this function.
4394 * Returns: a #GstFlowReturn from the pad.
4399 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4401 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4402 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4403 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4405 return gst_pad_chain_data_unchecked (pad,
4406 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4409 static GstFlowReturn
4410 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4411 GstBufferList * list)
4417 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4419 len = gst_buffer_list_length (list);
4422 for (i = 0; i < len; i++) {
4423 buffer = gst_buffer_list_get (list, i);
4425 gst_pad_chain_data_unchecked (pad,
4426 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4427 gst_buffer_ref (buffer));
4428 if (ret != GST_FLOW_OK)
4431 gst_buffer_list_unref (list);
4437 * gst_pad_chain_list:
4438 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4439 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4442 * Chain a bufferlist to @pad.
4444 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4446 * If @pad was not negotiated properly with a CAPS event, this function
4447 * returns #GST_FLOW_NOT_NEGOTIATED.
4449 * The function proceeds calling the chainlist function installed on @pad (see
4450 * gst_pad_set_chain_list_function()) and the return value of that function is
4451 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4452 * chainlist function.
4454 * In all cases, success or failure, the caller loses its reference to @list
4455 * after calling this function.
4459 * Returns: a #GstFlowReturn from the pad.
4462 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4464 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4465 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4466 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4468 return gst_pad_chain_data_unchecked (pad,
4469 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4472 static GstFlowReturn
4473 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4477 gboolean handled = FALSE;
4479 GST_OBJECT_LOCK (pad);
4480 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4483 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4486 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4489 #ifdef GST_ENABLE_EXTRA_CHECKS
4490 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4491 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4493 ":%s:<%s:%s> Got data flow before stream-start event",
4494 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4496 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4498 ":%s:<%s:%s> Got data flow before segment event",
4499 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4501 pad->priv->last_cookie = pad->priv->events_cookie;
4505 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4508 /* do block probes */
4509 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4512 /* recheck sticky events because the probe might have cause a relink */
4513 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4516 /* do post-blocking probes */
4517 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4519 /* recheck sticky events because the probe might have cause a relink */
4520 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4523 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4526 /* take ref to peer pad before releasing the lock */
4527 gst_object_ref (peer);
4529 GST_OBJECT_UNLOCK (pad);
4531 ret = gst_pad_chain_data_unchecked (peer, type, data);
4534 gst_object_unref (peer);
4536 GST_OBJECT_LOCK (pad);
4537 pad->ABI.abi.last_flowret = ret;
4539 if (pad->priv->using == 0) {
4540 /* pad is not active anymore, trigger idle callbacks */
4541 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4542 probe_stopped, ret);
4544 GST_OBJECT_UNLOCK (pad);
4548 /* ERROR recovery here */
4552 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4553 "pushing, but pad was flushing");
4554 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4555 GST_OBJECT_UNLOCK (pad);
4556 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4557 return GST_FLOW_FLUSHING;
4561 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4562 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4563 GST_OBJECT_UNLOCK (pad);
4564 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4565 return GST_FLOW_EOS;
4569 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4570 GST_DEBUG_PAD_NAME (pad));
4571 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4572 GST_OBJECT_UNLOCK (pad);
4573 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4574 return GST_FLOW_ERROR;
4578 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4579 "error pushing events, return %s", gst_flow_get_name (ret));
4580 pad->ABI.abi.last_flowret = ret;
4581 GST_OBJECT_UNLOCK (pad);
4582 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4590 GST_OBJECT_UNLOCK (pad);
4591 if (data != NULL && !handled)
4592 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4595 case GST_FLOW_CUSTOM_SUCCESS:
4596 case GST_FLOW_CUSTOM_SUCCESS_1:
4597 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4601 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4604 pad->ABI.abi.last_flowret = ret;
4609 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4610 "pushing, but it was not linked");
4611 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4612 GST_OBJECT_UNLOCK (pad);
4613 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4614 return GST_FLOW_NOT_LINKED;
4620 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4621 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4624 * Pushes a buffer to the peer of @pad.
4626 * This function will call installed block probes before triggering any
4627 * installed data probes.
4629 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4630 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4633 * In all cases, success or failure, the caller loses its reference to @buffer
4634 * after calling this function.
4636 * Returns: a #GstFlowReturn from the peer pad.
4641 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4645 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4646 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4647 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4649 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4650 res = gst_pad_push_data (pad,
4651 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4652 GST_TRACER_PAD_PUSH_POST (pad, res);
4657 * gst_pad_push_list:
4658 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4659 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4662 * Pushes a buffer list to the peer of @pad.
4664 * This function will call installed block probes before triggering any
4665 * installed data probes.
4667 * The function proceeds calling the chain function on the peer pad and returns
4668 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4669 * be returned. If the peer pad does not have any installed chainlist function
4670 * every group buffer of the list will be merged into a normal #GstBuffer and
4671 * chained via gst_pad_chain().
4673 * In all cases, success or failure, the caller loses its reference to @list
4674 * after calling this function.
4676 * Returns: a #GstFlowReturn from the peer pad.
4681 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4685 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4686 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4687 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4689 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4690 res = gst_pad_push_data (pad,
4691 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4692 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4696 static GstFlowReturn
4697 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4698 GstBuffer ** buffer)
4701 GstPadGetRangeFunction getrangefunc;
4705 GST_PAD_STREAM_LOCK (pad);
4707 GST_OBJECT_LOCK (pad);
4708 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4711 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4714 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4719 /* when one of the probes returns DROPPED, probe_stopped will be called
4720 * and we skip calling the getrange function, res_buf should then contain a
4721 * valid result buffer */
4722 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4723 res_buf, offset, size, probe_stopped);
4725 /* recheck sticky events because the probe might have cause a relink */
4726 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4729 ACQUIRE_PARENT (pad, parent, no_parent);
4730 GST_OBJECT_UNLOCK (pad);
4732 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4735 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4736 "calling getrangefunc %s, offset %"
4737 G_GUINT64_FORMAT ", size %u",
4738 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4740 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4742 RELEASE_PARENT (parent);
4744 GST_OBJECT_LOCK (pad);
4745 if (G_UNLIKELY (ret != GST_FLOW_OK))
4746 goto get_range_failed;
4748 /* can only fire the signal if we have a valid buffer */
4750 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4751 res_buf, offset, size, probe_stopped_unref);
4752 pad->ABI.abi.last_flowret = ret;
4753 GST_OBJECT_UNLOCK (pad);
4755 GST_PAD_STREAM_UNLOCK (pad);
4764 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4765 "getrange, but pad was flushing");
4766 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4767 GST_OBJECT_UNLOCK (pad);
4768 GST_PAD_STREAM_UNLOCK (pad);
4769 return GST_FLOW_FLUSHING;
4773 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4774 GST_DEBUG_PAD_NAME (pad));
4775 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4776 GST_OBJECT_UNLOCK (pad);
4777 GST_PAD_STREAM_UNLOCK (pad);
4778 return GST_FLOW_ERROR;
4782 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4783 pad->ABI.abi.last_flowret = ret;
4784 GST_OBJECT_UNLOCK (pad);
4785 GST_PAD_STREAM_UNLOCK (pad);
4790 GST_DEBUG_OBJECT (pad, "no parent");
4791 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4792 GST_OBJECT_UNLOCK (pad);
4793 GST_PAD_STREAM_UNLOCK (pad);
4794 return GST_FLOW_FLUSHING;
4798 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4799 GST_DEBUG_PAD_NAME (pad));
4800 RELEASE_PARENT (parent);
4801 GST_PAD_STREAM_UNLOCK (pad);
4802 return GST_FLOW_NOT_SUPPORTED;
4806 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4807 "probe returned %s", gst_flow_get_name (ret));
4808 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4810 /* the probe filled the buffer and asks us to not call the getrange
4811 * anymore, we continue with the post probes then. */
4812 GST_DEBUG_OBJECT (pad, "handled buffer");
4816 /* no buffer, we are EOS */
4817 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4821 pad->ABI.abi.last_flowret = ret;
4822 GST_OBJECT_UNLOCK (pad);
4823 GST_PAD_STREAM_UNLOCK (pad);
4827 probe_stopped_unref:
4829 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4830 "probe returned %s", gst_flow_get_name (ret));
4831 /* if we drop here, it signals EOS */
4832 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4834 pad->ABI.abi.last_flowret = ret;
4835 GST_OBJECT_UNLOCK (pad);
4836 GST_PAD_STREAM_UNLOCK (pad);
4837 if (*buffer == NULL)
4838 gst_buffer_unref (res_buf);
4843 pad->ABI.abi.last_flowret = ret;
4844 GST_OBJECT_UNLOCK (pad);
4845 GST_PAD_STREAM_UNLOCK (pad);
4846 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4847 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4848 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4854 * gst_pad_get_range:
4855 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4856 * @offset: The start offset of the buffer
4857 * @size: The length of the buffer
4858 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4859 * returns #GST_FLOW_ERROR if %NULL.
4861 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4862 * immediately and @buffer is %NULL.
4864 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4865 * description of a getrange function. If @pad has no getrange function
4866 * installed (see gst_pad_set_getrange_function()) this function returns
4867 * #GST_FLOW_NOT_SUPPORTED.
4869 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4870 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4871 * must be freed with gst_buffer_unref() after usage.
4873 * When @buffer points to a variable that points to a valid #GstBuffer, the
4874 * buffer will be filled with the result data when this function returns
4875 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4876 * @size bytes will be filled in the result buffer and its size will be updated
4879 * Note that less than @size bytes can be returned in @buffer when, for example,
4880 * an EOS condition is near or when @buffer is not large enough to hold @size
4881 * bytes. The caller should check the result buffer size to get the result size.
4883 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4884 * will be unchanged.
4886 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4888 * Returns: a #GstFlowReturn from the pad.
4893 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4894 GstBuffer ** buffer)
4896 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4897 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4898 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4899 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4900 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4902 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4906 * gst_pad_pull_range:
4907 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4908 * @offset: The start offset of the buffer
4909 * @size: The length of the buffer
4910 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4911 * GST_FLOW_ERROR if %NULL.
4913 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4915 * This function will first trigger the pad block signal if it was
4918 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4919 * function returns the result of gst_pad_get_range() on the peer pad.
4920 * See gst_pad_get_range() for a list of return values and for the
4921 * semantics of the arguments of this function.
4923 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4924 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4925 * must be freed with gst_buffer_unref() after usage. When this function
4926 * returns any other result value, @buffer will still point to %NULL.
4928 * When @buffer points to a variable that points to a valid #GstBuffer, the
4929 * buffer will be filled with the result data when this function returns
4930 * #GST_FLOW_OK. When this function returns any other result value,
4931 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4932 * @size bytes will be filled in the result buffer and its size will be updated
4935 * Note that less than @size bytes can be returned in @buffer when, for example,
4936 * an EOS condition is near or when @buffer is not large enough to hold @size
4937 * bytes. The caller should check the result buffer size to get the result size.
4939 * Returns: a #GstFlowReturn from the peer pad.
4944 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4945 GstBuffer ** buffer)
4951 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4952 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4953 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4954 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4955 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4957 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4959 GST_OBJECT_LOCK (pad);
4960 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4963 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4968 /* when one of the probes returns DROPPED, probe_stopped will be
4969 * called and we skip calling the peer getrange function. *buffer should then
4970 * contain a valid buffer */
4971 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4972 res_buf, offset, size, probe_stopped);
4974 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4977 gst_object_ref (peer);
4979 GST_OBJECT_UNLOCK (pad);
4981 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4983 gst_object_unref (peer);
4985 GST_OBJECT_LOCK (pad);
4987 pad->ABI.abi.last_flowret = ret;
4988 if (pad->priv->using == 0) {
4989 /* pad is not active anymore, trigger idle callbacks */
4990 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4991 probe_stopped_unref, ret);
4994 if (G_UNLIKELY (ret != GST_FLOW_OK))
4995 goto pull_range_failed;
4998 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4999 res_buf, offset, size, probe_stopped_unref);
5001 GST_OBJECT_UNLOCK (pad);
5005 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5008 /* ERROR recovery here */
5011 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5012 "pullrange, but pad was flushing");
5013 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5014 GST_OBJECT_UNLOCK (pad);
5015 ret = GST_FLOW_FLUSHING;
5020 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5021 GST_DEBUG_PAD_NAME (pad));
5022 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5023 GST_OBJECT_UNLOCK (pad);
5024 ret = GST_FLOW_ERROR;
5029 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5030 gst_flow_get_name (ret));
5031 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5033 /* the probe filled the buffer and asks us to not forward to the peer
5034 * anymore, we continue with the post probes then */
5035 GST_DEBUG_OBJECT (pad, "handled buffer");
5039 /* no buffer, we are EOS then */
5040 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5044 pad->ABI.abi.last_flowret = ret;
5045 GST_OBJECT_UNLOCK (pad);
5050 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5051 "pulling range, but it was not linked");
5052 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5053 GST_OBJECT_UNLOCK (pad);
5054 ret = GST_FLOW_NOT_LINKED;
5059 pad->ABI.abi.last_flowret = ret;
5060 GST_OBJECT_UNLOCK (pad);
5061 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5062 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5063 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5066 probe_stopped_unref:
5068 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5069 "post probe returned %s", gst_flow_get_name (ret));
5071 /* if we drop here, it signals EOS */
5072 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5075 pad->ABI.abi.last_flowret = ret;
5076 GST_OBJECT_UNLOCK (pad);
5078 if (*buffer == NULL)
5079 gst_buffer_unref (res_buf);
5083 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5087 /* must be called with pad object lock */
5088 static GstFlowReturn
5089 store_sticky_event (GstPad * pad, GstEvent * event)
5094 gboolean res = FALSE;
5095 const gchar *name = NULL;
5096 gboolean insert = TRUE;
5098 type = GST_EVENT_TYPE (event);
5100 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5101 * otherwise they can be dropped and nothing would ever resend them.
5102 * Only do that for activated pads though, everything else is a bug!
5104 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5105 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5106 || type == GST_EVENT_EOS))))
5109 /* Unset the EOS flag when received STREAM_START event, so pad can
5110 * store sticky event and then push it later */
5111 if (type == GST_EVENT_STREAM_START) {
5112 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5113 remove_event_by_type (pad, GST_EVENT_EOS);
5114 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5115 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5118 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5121 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5122 name = gst_structure_get_name (gst_event_get_structure (event));
5124 events = pad->priv->events;
5127 for (i = 0; i < len; i++) {
5128 PadEvent *ev = &g_array_index (events, PadEvent, i);
5130 if (ev->event == NULL)
5133 if (type == GST_EVENT_TYPE (ev->event)) {
5134 /* matching types, check matching name if needed */
5135 if (name && !gst_event_has_name (ev->event, name))
5139 if ((res = gst_event_replace (&ev->event, event)))
5140 ev->received = FALSE;
5146 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5147 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5148 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5149 * storing the sticky ordered we can check that this is respected. */
5150 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5151 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5153 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5154 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5155 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5156 gst_event_type_get_name (type));
5162 ev.event = gst_event_ref (event);
5163 ev.received = FALSE;
5164 g_array_insert_val (events, i, ev);
5169 pad->priv->events_cookie++;
5170 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5172 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5174 switch (GST_EVENT_TYPE (event)) {
5175 case GST_EVENT_CAPS:
5176 GST_OBJECT_UNLOCK (pad);
5178 GST_DEBUG_OBJECT (pad, "notify caps");
5179 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5181 GST_OBJECT_LOCK (pad);
5187 if (type == GST_EVENT_EOS) {
5188 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5189 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5192 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5197 GST_DEBUG_OBJECT (pad, "pad is flushing");
5198 return GST_FLOW_FLUSHING;
5202 GST_DEBUG_OBJECT (pad, "pad is EOS");
5203 return GST_FLOW_EOS;
5208 * gst_pad_store_sticky_event:
5210 * @event: (transfer none): a #GstEvent
5212 * Store the sticky @event on @pad
5214 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5215 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5220 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5224 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5225 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5227 GST_OBJECT_LOCK (pad);
5228 ret = store_sticky_event (pad, event);
5229 GST_OBJECT_UNLOCK (pad);
5235 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5237 PushStickyData *data = user_data;
5239 /* Forward all sticky events before our current one that are pending */
5240 if (ev->event != data->event
5241 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5242 return push_sticky (pad, ev, data);
5247 /* should be called with pad LOCK */
5248 static GstFlowReturn
5249 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5250 GstPadProbeType type)
5254 GstEventType event_type;
5256 /* pass the adjusted event on. We need to do this even if
5257 * there is no peer pad because of the probes. */
5258 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5260 /* Two checks to be made:
5261 * . (un)set the FLUSHING flag for flushing events,
5262 * . handle pad blocking */
5263 event_type = GST_EVENT_TYPE (event);
5264 switch (event_type) {
5265 case GST_EVENT_FLUSH_START:
5266 GST_PAD_SET_FLUSHING (pad);
5268 GST_PAD_BLOCK_BROADCAST (pad);
5269 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5271 case GST_EVENT_FLUSH_STOP:
5272 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5275 GST_PAD_UNSET_FLUSHING (pad);
5277 /* Remove sticky EOS events */
5278 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5279 remove_event_by_type (pad, GST_EVENT_EOS);
5280 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5281 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5282 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5283 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5285 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5289 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5292 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5293 * checked already or this is called as part of pushing sticky events,
5294 * in which case we still want to forward the EOS event downstream.
5297 switch (GST_EVENT_TYPE (event)) {
5298 case GST_EVENT_RECONFIGURE:
5299 if (GST_PAD_IS_SINK (pad))
5300 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5305 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5306 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5307 /* recheck sticky events because the probe might have cause a relink */
5308 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5309 && (GST_EVENT_IS_SERIALIZED (event)
5310 || GST_EVENT_IS_STICKY (event))) {
5311 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5312 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5314 /* Push all sticky events before our current one
5315 * that have changed */
5316 events_foreach (pad, sticky_changed, &data);
5322 /* send probes after modifying the events above */
5323 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5325 /* recheck sticky events because the probe might have cause a relink */
5326 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5327 && (GST_EVENT_IS_SERIALIZED (event)
5328 || GST_EVENT_IS_STICKY (event))) {
5329 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5330 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5332 /* Push all sticky events before our current one
5333 * that have changed */
5334 events_foreach (pad, sticky_changed, &data);
5337 /* now check the peer pad */
5338 peerpad = GST_PAD_PEER (pad);
5339 if (peerpad == NULL)
5342 gst_object_ref (peerpad);
5344 GST_OBJECT_UNLOCK (pad);
5346 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5347 event, gst_event_type_get_name (event_type), peerpad);
5349 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5351 /* Note: we gave away ownership of the event at this point but we can still
5352 * print the old pointer */
5353 GST_LOG_OBJECT (pad,
5354 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5355 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5357 gst_object_unref (peerpad);
5359 GST_OBJECT_LOCK (pad);
5361 if (pad->priv->using == 0) {
5362 /* pad is not active anymore, trigger idle callbacks */
5363 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5364 idle_probe_stopped, ret);
5368 /* ERROR handling */
5371 GST_DEBUG_OBJECT (pad, "We're flushing");
5372 gst_event_unref (event);
5373 return GST_FLOW_FLUSHING;
5377 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5378 gst_event_unref (event);
5379 return GST_FLOW_FLUSHING;
5383 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5384 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5385 gst_event_unref (event);
5388 case GST_FLOW_CUSTOM_SUCCESS_1:
5389 GST_DEBUG_OBJECT (pad, "handled event");
5391 case GST_FLOW_CUSTOM_SUCCESS:
5392 GST_DEBUG_OBJECT (pad, "dropped event");
5395 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5402 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5403 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5404 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5405 gst_event_unref (event);
5407 /* unlinked pads should not influence latency configuration */
5408 if (event_type == GST_EVENT_LATENCY)
5411 return GST_FLOW_NOT_LINKED;
5415 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5421 * gst_pad_push_event:
5422 * @pad: a #GstPad to push the event to.
5423 * @event: (transfer full): the #GstEvent to send to the pad.
5425 * Sends the event to the peer of the given pad. This function is
5426 * mainly used by elements to send events to their peer
5429 * This function takes ownership of the provided event so you should
5430 * gst_event_ref() it if you want to reuse the event after this call.
5432 * Returns: %TRUE if the event was handled.
5437 gst_pad_push_event (GstPad * pad, GstEvent * event)
5439 gboolean res = FALSE;
5440 GstPadProbeType type;
5441 gboolean sticky, serialized;
5443 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5444 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5446 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5448 if (GST_PAD_IS_SRC (pad)) {
5449 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5450 goto wrong_direction;
5451 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5452 } else if (GST_PAD_IS_SINK (pad)) {
5453 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5454 goto wrong_direction;
5455 /* events pushed on sinkpad never are sticky */
5456 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5458 goto unknown_direction;
5460 GST_OBJECT_LOCK (pad);
5461 sticky = GST_EVENT_IS_STICKY (event);
5462 serialized = GST_EVENT_IS_SERIALIZED (event);
5465 /* srcpad sticky events are stored immediately, the received flag is set
5466 * to FALSE and will be set to TRUE when we can successfully push the
5467 * event to the peer pad */
5468 switch (store_sticky_event (pad, event)) {
5469 case GST_FLOW_FLUSHING:
5477 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5478 /* all serialized or sticky events on the srcpad trigger push of
5480 res = (check_sticky (pad, event) == GST_FLOW_OK);
5485 /* other events are pushed right away */
5486 ret = gst_pad_push_event_unchecked (pad, event, type);
5487 /* dropped events by a probe are not an error */
5488 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5489 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5491 /* Errors in sticky event pushing are no problem and ignored here
5492 * as they will cause more meaningful errors during data flow.
5493 * For EOS events, that are not followed by data flow, we still
5494 * return FALSE here though.
5496 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5498 gst_event_unref (event);
5500 GST_OBJECT_UNLOCK (pad);
5502 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5505 /* ERROR handling */
5508 g_warning ("pad %s:%s pushing %s event in wrong direction",
5509 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5510 gst_event_unref (event);
5515 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5516 gst_event_unref (event);
5521 GST_DEBUG_OBJECT (pad, "We're flushing");
5522 GST_OBJECT_UNLOCK (pad);
5523 gst_event_unref (event);
5528 GST_DEBUG_OBJECT (pad, "We're EOS");
5529 GST_OBJECT_UNLOCK (pad);
5530 gst_event_unref (event);
5534 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5538 /* Check if we can call the event function with the given event */
5539 static GstFlowReturn
5540 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5544 switch (GST_EVENT_TYPE (event)) {
5545 case GST_EVENT_CAPS:
5547 /* backwards compatibility mode for caps */
5548 gst_event_parse_caps (event, &caps);
5550 if (!gst_pad_query_accept_caps (pad, caps))
5562 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5563 "caps %" GST_PTR_FORMAT " not accepted", caps);
5564 return GST_FLOW_NOT_NEGOTIATED;
5568 static GstFlowReturn
5569 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5570 GstPadProbeType type)
5573 GstEventType event_type;
5574 gboolean serialized, need_unlock = FALSE, sticky;
5575 GstPadEventFunction eventfunc;
5576 GstPadEventFullFunction eventfullfunc = NULL;
5579 GST_OBJECT_LOCK (pad);
5581 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5583 if (GST_PAD_IS_SINK (pad))
5584 serialized = GST_EVENT_IS_SERIALIZED (event);
5587 sticky = GST_EVENT_IS_STICKY (event);
5588 event_type = GST_EVENT_TYPE (event);
5589 switch (event_type) {
5590 case GST_EVENT_FLUSH_START:
5591 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5592 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5594 /* can't even accept a flush begin event when flushing */
5595 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5598 GST_PAD_SET_FLUSHING (pad);
5599 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5600 GST_PAD_BLOCK_BROADCAST (pad);
5601 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5603 case GST_EVENT_FLUSH_STOP:
5604 /* we can't accept flush-stop on inactive pads else the flushing flag
5605 * would be cleared and it would look like the pad can accept data.
5606 * Also, some elements restart a streaming thread in flush-stop which we
5607 * can't allow on inactive pads */
5608 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5611 GST_PAD_UNSET_FLUSHING (pad);
5612 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5613 /* Remove pending EOS events */
5614 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5615 remove_event_by_type (pad, GST_EVENT_EOS);
5616 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5617 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5618 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5619 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5621 GST_OBJECT_UNLOCK (pad);
5622 /* grab stream lock */
5623 GST_PAD_STREAM_LOCK (pad);
5625 GST_OBJECT_LOCK (pad);
5626 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5629 case GST_EVENT_RECONFIGURE:
5630 if (GST_PAD_IS_SRC (pad))
5631 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5633 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5634 "have event type %" GST_PTR_FORMAT, event);
5636 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5639 switch (event_type) {
5640 case GST_EVENT_STREAM_START:
5641 /* Remove sticky EOS events */
5642 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5643 remove_event_by_type (pad, GST_EVENT_EOS);
5644 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5645 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5652 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5655 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5656 GST_OBJECT_UNLOCK (pad);
5657 GST_PAD_STREAM_LOCK (pad);
5659 GST_OBJECT_LOCK (pad);
5660 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5663 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5669 /* now do the probe */
5671 type | GST_PAD_PROBE_TYPE_PUSH |
5672 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5674 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5676 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5677 eventfunc = GST_PAD_EVENTFUNC (pad);
5678 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5681 ACQUIRE_PARENT (pad, parent, no_parent);
5682 GST_OBJECT_UNLOCK (pad);
5684 ret = pre_eventfunc_check (pad, event);
5685 if (G_UNLIKELY (ret != GST_FLOW_OK))
5686 goto precheck_failed;
5689 gst_event_ref (event);
5691 if (eventfullfunc) {
5692 ret = eventfullfunc (pad, parent, event);
5693 } else if (eventfunc (pad, parent, event)) {
5696 /* something went wrong */
5697 switch (event_type) {
5698 case GST_EVENT_CAPS:
5699 ret = GST_FLOW_NOT_NEGOTIATED;
5702 ret = GST_FLOW_ERROR;
5706 RELEASE_PARENT (parent);
5708 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5711 if (ret == GST_FLOW_OK) {
5712 GST_OBJECT_LOCK (pad);
5713 /* after the event function accepted the event, we can store the sticky
5714 * event on the pad */
5715 switch (store_sticky_event (pad, event)) {
5716 case GST_FLOW_FLUSHING:
5723 GST_OBJECT_UNLOCK (pad);
5725 gst_event_unref (event);
5729 GST_PAD_STREAM_UNLOCK (pad);
5733 /* ERROR handling */
5736 GST_OBJECT_UNLOCK (pad);
5738 GST_PAD_STREAM_UNLOCK (pad);
5739 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5740 "Received event on flushing pad. Discarding");
5741 gst_event_unref (event);
5742 return GST_FLOW_FLUSHING;
5746 GST_OBJECT_UNLOCK (pad);
5748 GST_PAD_STREAM_UNLOCK (pad);
5749 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5750 "Received flush-stop on inactive pad. Discarding");
5751 gst_event_unref (event);
5752 return GST_FLOW_FLUSHING;
5756 GST_OBJECT_UNLOCK (pad);
5758 GST_PAD_STREAM_UNLOCK (pad);
5759 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5760 "Received event on EOS pad. Discarding");
5761 gst_event_unref (event);
5762 return GST_FLOW_EOS;
5766 GST_OBJECT_UNLOCK (pad);
5768 GST_PAD_STREAM_UNLOCK (pad);
5769 /* Only unref if unhandled */
5770 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5771 gst_event_unref (event);
5774 case GST_FLOW_CUSTOM_SUCCESS_1:
5775 case GST_FLOW_CUSTOM_SUCCESS:
5776 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5780 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5787 g_warning ("pad %s:%s has no event handler, file a bug.",
5788 GST_DEBUG_PAD_NAME (pad));
5789 GST_OBJECT_UNLOCK (pad);
5791 GST_PAD_STREAM_UNLOCK (pad);
5792 gst_event_unref (event);
5793 return GST_FLOW_NOT_SUPPORTED;
5797 GST_DEBUG_OBJECT (pad, "no parent");
5798 GST_OBJECT_UNLOCK (pad);
5800 GST_PAD_STREAM_UNLOCK (pad);
5801 gst_event_unref (event);
5802 return GST_FLOW_FLUSHING;
5806 GST_DEBUG_OBJECT (pad, "pre event check failed");
5807 RELEASE_PARENT (parent);
5809 GST_PAD_STREAM_UNLOCK (pad);
5810 gst_event_unref (event);
5816 * gst_pad_send_event:
5817 * @pad: a #GstPad to send the event to.
5818 * @event: (transfer full): the #GstEvent to send to the pad.
5820 * Sends the event to the pad. This function can be used
5821 * by applications to send events in the pipeline.
5823 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5824 * sink pad, @event should be a downstream event. For example, you would not
5825 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5826 * Furthermore, some downstream events have to be serialized with data flow,
5827 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5828 * the event needs to be serialized with data flow, this function will take the
5829 * pad's stream lock while calling its event function.
5831 * To find out whether an event type is upstream, downstream, or downstream and
5832 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5833 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5834 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5835 * plugin doesn't need to bother itself with this information; the core handles
5836 * all necessary locks and checks.
5838 * This function takes ownership of the provided event so you should
5839 * gst_event_ref() it if you want to reuse the event after this call.
5841 * Returns: %TRUE if the event was handled.
5844 gst_pad_send_event (GstPad * pad, GstEvent * event)
5847 GstPadProbeType type;
5849 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5850 g_return_val_if_fail (event != NULL, FALSE);
5852 if (GST_PAD_IS_SINK (pad)) {
5853 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5854 goto wrong_direction;
5855 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5856 } else if (GST_PAD_IS_SRC (pad)) {
5857 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5858 goto wrong_direction;
5859 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5861 goto unknown_direction;
5863 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5870 /* ERROR handling */
5873 g_warning ("pad %s:%s sending %s event in wrong direction",
5874 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5875 gst_event_unref (event);
5880 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5881 gst_event_unref (event);
5887 * gst_pad_set_element_private:
5888 * @pad: the #GstPad to set the private data of.
5889 * @priv: The private data to attach to the pad.
5891 * Set the given private data gpointer on the pad.
5892 * This function can only be used by the element that owns the pad.
5893 * No locking is performed in this function.
5896 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5898 pad->element_private = priv;
5902 * gst_pad_get_element_private:
5903 * @pad: the #GstPad to get the private data of.
5905 * Gets the private data of a pad.
5906 * No locking is performed in this function.
5908 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5911 gst_pad_get_element_private (GstPad * pad)
5913 return pad->element_private;
5917 * gst_pad_get_sticky_event:
5918 * @pad: the #GstPad to get the event from.
5919 * @event_type: the #GstEventType that should be retrieved.
5920 * @idx: the index of the event
5922 * Returns a new reference of the sticky event of type @event_type
5925 * Returns: (transfer full) (nullable): a #GstEvent of type
5926 * @event_type or %NULL when no event of @event_type was on
5927 * @pad. Unref after usage.
5930 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5932 GstEvent *event = NULL;
5935 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5936 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5938 GST_OBJECT_LOCK (pad);
5939 ev = find_event_by_type (pad, event_type, idx);
5940 if (ev && (event = ev->event))
5941 gst_event_ref (event);
5942 GST_OBJECT_UNLOCK (pad);
5949 GstPadStickyEventsForeachFunction func;
5954 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5956 ForeachDispatch *data = user_data;
5957 gboolean ret = TRUE;
5960 GST_OBJECT_UNLOCK (pad);
5962 ret = data->func (pad, &ev->event, data->user_data);
5964 GST_OBJECT_LOCK (pad);
5971 * gst_pad_sticky_events_foreach:
5972 * @pad: the #GstPad that should be used for iteration.
5973 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5974 * should be called for every event.
5975 * @user_data: (closure): the optional user data.
5977 * Iterates all sticky events on @pad and calls @foreach_func for every
5978 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5981 gst_pad_sticky_events_foreach (GstPad * pad,
5982 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5984 ForeachDispatch data;
5986 g_return_if_fail (GST_IS_PAD (pad));
5987 g_return_if_fail (foreach_func != NULL);
5989 data.func = foreach_func;
5990 data.user_data = user_data;
5992 GST_OBJECT_LOCK (pad);
5993 events_foreach (pad, foreach_dispatch_function, &data);
5994 GST_OBJECT_UNLOCK (pad);
5998 do_stream_status (GstPad * pad, GstStreamStatusType type,
5999 GThread * thread, GstTask * task)
6003 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6005 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6006 if (GST_IS_ELEMENT (parent)) {
6007 GstMessage *message;
6008 GValue value = { 0 };
6010 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6011 gchar *tname, *ename, *pname;
6013 /* create a good task name */
6014 ename = gst_element_get_name (parent);
6015 pname = gst_pad_get_name (pad);
6016 tname = g_strdup_printf ("%s:%s", ename, pname);
6020 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6024 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6027 g_value_init (&value, GST_TYPE_TASK);
6028 g_value_set_object (&value, task);
6029 gst_message_set_stream_status_object (message, &value);
6030 g_value_unset (&value);
6032 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6033 gst_element_post_message (parent, message);
6035 gst_object_unref (parent);
6040 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6042 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6047 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6049 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6054 * gst_pad_start_task:
6055 * @pad: the #GstPad to start the task of
6056 * @func: the task function to call
6057 * @user_data: user data passed to the task function
6058 * @notify: called when @user_data is no longer referenced
6060 * Starts a task that repeatedly calls @func with @user_data. This function
6061 * is mostly used in pad activation functions to start the dataflow.
6062 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6063 * before @func is called.
6065 * Returns: a %TRUE if the task could be started.
6068 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6069 GDestroyNotify notify)
6074 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6075 g_return_val_if_fail (func != NULL, FALSE);
6077 GST_DEBUG_OBJECT (pad, "start task");
6079 GST_OBJECT_LOCK (pad);
6080 task = GST_PAD_TASK (pad);
6082 task = gst_task_new (func, user_data, notify);
6083 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6084 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6085 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6086 GST_INFO_OBJECT (pad, "created task %p", task);
6087 GST_PAD_TASK (pad) = task;
6088 gst_object_ref (task);
6089 /* release lock to post the message */
6090 GST_OBJECT_UNLOCK (pad);
6092 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6094 gst_object_unref (task);
6096 GST_OBJECT_LOCK (pad);
6097 /* nobody else is supposed to have changed the pad now */
6098 if (GST_PAD_TASK (pad) != task)
6099 goto concurrent_stop;
6101 res = gst_task_set_state (task, GST_TASK_STARTED);
6102 GST_OBJECT_UNLOCK (pad);
6109 GST_OBJECT_UNLOCK (pad);
6115 * gst_pad_pause_task:
6116 * @pad: the #GstPad to pause the task of
6118 * Pause the task of @pad. This function will also wait until the
6119 * function executed by the task is finished if this function is not
6120 * called from the task function.
6122 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6126 gst_pad_pause_task (GstPad * pad)
6131 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6133 GST_DEBUG_OBJECT (pad, "pause task");
6135 GST_OBJECT_LOCK (pad);
6136 task = GST_PAD_TASK (pad);
6139 res = gst_task_set_state (task, GST_TASK_PAUSED);
6140 /* unblock activation waits if any */
6141 pad->priv->in_activation = FALSE;
6142 g_cond_broadcast (&pad->priv->activation_cond);
6143 GST_OBJECT_UNLOCK (pad);
6145 /* wait for task function to finish, this lock is recursive so it does nothing
6146 * when the pause is called from the task itself */
6147 GST_PAD_STREAM_LOCK (pad);
6148 GST_PAD_STREAM_UNLOCK (pad);
6154 GST_DEBUG_OBJECT (pad, "pad has no task");
6155 GST_OBJECT_UNLOCK (pad);
6161 * gst_pad_get_task_state:
6162 * @pad: the #GstPad to get task state from
6164 * Get @pad task state. If no task is currently
6165 * set, #GST_TASK_STOPPED is returned.
6167 * Returns: The current state of @pad's task.
6172 gst_pad_get_task_state (GstPad * pad)
6177 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6179 GST_OBJECT_LOCK (pad);
6180 task = GST_PAD_TASK (pad);
6183 res = gst_task_get_state (task);
6184 GST_OBJECT_UNLOCK (pad);
6190 GST_DEBUG_OBJECT (pad, "pad has no task");
6191 GST_OBJECT_UNLOCK (pad);
6192 return GST_TASK_STOPPED;
6197 * gst_pad_stop_task:
6198 * @pad: the #GstPad to stop the task of
6200 * Stop the task of @pad. This function will also make sure that the
6201 * function executed by the task will effectively stop if not called
6202 * from the GstTaskFunction.
6204 * This function will deadlock if called from the GstTaskFunction of
6205 * the task. Use gst_task_pause() instead.
6207 * Regardless of whether the pad has a task, the stream lock is acquired and
6208 * released so as to ensure that streaming through this pad has finished.
6210 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6213 gst_pad_stop_task (GstPad * pad)
6218 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6220 GST_DEBUG_OBJECT (pad, "stop task");
6222 GST_OBJECT_LOCK (pad);
6223 task = GST_PAD_TASK (pad);
6226 GST_PAD_TASK (pad) = NULL;
6227 res = gst_task_set_state (task, GST_TASK_STOPPED);
6228 /* unblock activation waits if any */
6229 pad->priv->in_activation = FALSE;
6230 g_cond_broadcast (&pad->priv->activation_cond);
6231 GST_OBJECT_UNLOCK (pad);
6233 GST_PAD_STREAM_LOCK (pad);
6234 GST_PAD_STREAM_UNLOCK (pad);
6236 if (!gst_task_join (task))
6239 gst_object_unref (task);
6245 GST_DEBUG_OBJECT (pad, "no task");
6246 GST_OBJECT_UNLOCK (pad);
6248 GST_PAD_STREAM_LOCK (pad);
6249 GST_PAD_STREAM_UNLOCK (pad);
6251 /* this is not an error */
6256 /* this is bad, possibly the application tried to join the task from
6257 * the task's thread. We install the task again so that it will be stopped
6258 * again from the right thread next time hopefully. */
6259 GST_OBJECT_LOCK (pad);
6260 GST_DEBUG_OBJECT (pad, "join failed");
6261 /* we can only install this task if there was no other task */
6262 if (GST_PAD_TASK (pad) == NULL)
6263 GST_PAD_TASK (pad) = task;
6264 GST_OBJECT_UNLOCK (pad);
6271 * gst_pad_probe_info_get_event:
6272 * @info: a #GstPadProbeInfo
6274 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6278 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6280 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6281 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6283 return GST_PAD_PROBE_INFO_EVENT (info);
6288 * gst_pad_probe_info_get_query:
6289 * @info: a #GstPadProbeInfo
6291 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6295 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6297 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6298 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6300 return GST_PAD_PROBE_INFO_QUERY (info);
6304 * gst_pad_probe_info_get_buffer:
6305 * @info: a #GstPadProbeInfo
6307 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6311 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6313 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6315 return GST_PAD_PROBE_INFO_BUFFER (info);
6319 * gst_pad_probe_info_get_buffer_list:
6320 * @info: a #GstPadProbeInfo
6322 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6326 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6328 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6330 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6334 * gst_pad_get_last_flow_return:
6337 * Gets the #GstFlowReturn return from the last data passed by this pad.
6342 gst_pad_get_last_flow_return (GstPad * pad)
6346 GST_OBJECT_LOCK (pad);
6347 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6348 GST_OBJECT_UNLOCK (pad);