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 additional 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, gint64 applied_offset,
655 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
656 GST_STIME_ARGS (pad->offset));
658 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
661 g_assert (!upstream);
663 /* copy segment values */
664 gst_event_copy_segment (event, &segment);
665 gst_event_unref (event);
667 gst_segment_offset_running_time (&segment, segment.format, applied_offset);
668 event = gst_event_new_segment (&segment);
671 event = gst_event_make_writable (event);
672 offset = gst_event_get_running_time_offset (event);
674 offset -= applied_offset;
676 offset += applied_offset;
677 gst_event_set_running_time_offset (event, offset);
682 static inline GstEvent *
683 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
685 if (G_UNLIKELY (pad->offset != 0))
686 return _apply_pad_offset (pad, event, pad->offset, upstream);
691 /* should be called with the OBJECT_LOCK */
693 get_pad_caps (GstPad * pad)
695 GstCaps *caps = NULL;
698 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
700 gst_event_parse_caps (ev->event, &caps);
706 gst_pad_dispose (GObject * object)
708 GstPad *pad = GST_PAD_CAST (object);
711 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
713 /* unlink the peer pad */
714 if ((peer = gst_pad_get_peer (pad))) {
715 /* window for MT unsafeness, someone else could unlink here
716 * and then we call unlink with wrong pads. The unlink
717 * function would catch this and safely return failed. */
718 if (GST_PAD_IS_SRC (pad))
719 gst_pad_unlink (pad, peer);
721 gst_pad_unlink (peer, pad);
723 gst_object_unref (peer);
726 gst_pad_set_pad_template (pad, NULL);
728 GST_OBJECT_LOCK (pad);
730 GST_OBJECT_UNLOCK (pad);
732 g_hook_list_clear (&pad->probes);
734 G_OBJECT_CLASS (parent_class)->dispose (object);
738 gst_pad_finalize (GObject * object)
740 GstPad *pad = GST_PAD_CAST (object);
743 /* in case the task is still around, clean it up */
744 if ((task = GST_PAD_TASK (pad))) {
745 gst_task_join (task);
746 GST_PAD_TASK (pad) = NULL;
747 gst_object_unref (task);
750 if (pad->activatenotify)
751 pad->activatenotify (pad->activatedata);
752 if (pad->activatemodenotify)
753 pad->activatemodenotify (pad->activatemodedata);
755 pad->linknotify (pad->linkdata);
756 if (pad->unlinknotify)
757 pad->unlinknotify (pad->unlinkdata);
758 if (pad->chainnotify)
759 pad->chainnotify (pad->chaindata);
760 if (pad->chainlistnotify)
761 pad->chainlistnotify (pad->chainlistdata);
762 if (pad->getrangenotify)
763 pad->getrangenotify (pad->getrangedata);
764 if (pad->eventnotify)
765 pad->eventnotify (pad->eventdata);
766 if (pad->querynotify)
767 pad->querynotify (pad->querydata);
768 if (pad->iterintlinknotify)
769 pad->iterintlinknotify (pad->iterintlinkdata);
771 g_rec_mutex_clear (&pad->stream_rec_lock);
772 g_cond_clear (&pad->block_cond);
773 g_cond_clear (&pad->priv->activation_cond);
774 g_array_free (pad->priv->events, TRUE);
776 G_OBJECT_CLASS (parent_class)->finalize (object);
780 gst_pad_set_property (GObject * object, guint prop_id,
781 const GValue * value, GParamSpec * pspec)
783 g_return_if_fail (GST_IS_PAD (object));
786 case PAD_PROP_DIRECTION:
787 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
789 case PAD_PROP_TEMPLATE:
790 gst_pad_set_pad_template (GST_PAD_CAST (object),
791 (GstPadTemplate *) g_value_get_object (value));
793 case PAD_PROP_OFFSET:
794 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
797 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
803 gst_pad_get_property (GObject * object, guint prop_id,
804 GValue * value, GParamSpec * pspec)
806 g_return_if_fail (GST_IS_PAD (object));
810 GST_OBJECT_LOCK (object);
811 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
812 GST_OBJECT_UNLOCK (object);
814 case PAD_PROP_DIRECTION:
815 g_value_set_enum (value, GST_PAD_DIRECTION (object));
817 case PAD_PROP_TEMPLATE:
818 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
820 case PAD_PROP_OFFSET:
821 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
824 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
831 * @name: (allow-none): the name of the new pad.
832 * @direction: the #GstPadDirection of the pad.
834 * Creates a new pad with the given name in the given direction.
835 * If name is %NULL, a guaranteed unique name (across all pads)
837 * This function makes a copy of the name so you can safely free the name.
839 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
845 gst_pad_new (const gchar * name, GstPadDirection direction)
847 return g_object_new (GST_TYPE_PAD,
848 "name", name, "direction", direction, NULL);
852 * gst_pad_new_from_template:
853 * @templ: the pad template to use
854 * @name: (allow-none): the name of the pad
856 * Creates a new pad with the given name from the given template.
857 * If name is %NULL, a guaranteed unique name (across all pads)
859 * This function makes a copy of the name so you can safely free the name.
861 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
865 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
868 GST_PAD_TEMPLATE_GTYPE (templ) ==
869 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
871 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
873 return g_object_new (pad_type,
874 "name", name, "direction", templ->direction, "template", templ, NULL);
878 * gst_pad_new_from_static_template:
879 * @templ: the #GstStaticPadTemplate to use
880 * @name: the name of the pad
882 * Creates a new pad with the given name from the given static template.
883 * If name is %NULL, a guaranteed unique name (across all pads)
885 * This function makes a copy of the name so you can safely free the name.
887 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
891 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
895 GstPadTemplate *template;
897 template = gst_static_pad_template_get (templ);
898 pad = gst_pad_new_from_template (template, name);
899 gst_object_unref (template);
903 #define ACQUIRE_PARENT(pad, parent, label) \
905 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
906 gst_object_ref (parent); \
907 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
911 #define RELEASE_PARENT(parent) \
913 if (G_LIKELY (parent)) \
914 gst_object_unref (parent); \
918 * gst_pad_get_direction:
919 * @pad: a #GstPad to get the direction of.
921 * Gets the direction of the pad. The direction of the pad is
922 * decided at construction time so this function does not take
925 * Returns: the #GstPadDirection of the pad.
930 gst_pad_get_direction (GstPad * pad)
932 GstPadDirection result;
934 /* PAD_UNKNOWN is a little silly but we need some sort of
935 * error return value */
936 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
938 result = GST_PAD_DIRECTION (pad);
944 gst_pad_activate_default (GstPad * pad, GstObject * parent)
946 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
948 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
952 * gst_pad_mode_get_name:
953 * @mode: the pad mode
955 * Return the name of a pad mode, for use in debug messages mostly.
957 * Returns: short mnemonic for pad mode @mode
960 gst_pad_mode_get_name (GstPadMode mode)
963 case GST_PAD_MODE_NONE:
965 case GST_PAD_MODE_PUSH:
967 case GST_PAD_MODE_PULL:
975 /* Returns TRUE if pad wasn't already in the new_mode */
977 pre_activate (GstPad * pad, GstPadMode new_mode)
980 case GST_PAD_MODE_NONE:
981 GST_OBJECT_LOCK (pad);
982 while (G_UNLIKELY (pad->priv->in_activation))
983 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
984 if (new_mode == GST_PAD_MODE (pad)) {
985 GST_WARNING_OBJECT (pad,
986 "Pad is already in the process of being deactivated");
987 GST_OBJECT_UNLOCK (pad);
990 pad->priv->in_activation = TRUE;
991 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
992 GST_PAD_SET_FLUSHING (pad);
993 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
994 GST_PAD_MODE (pad) = new_mode;
995 /* unlock blocked pads so element can resume and stop */
996 GST_PAD_BLOCK_BROADCAST (pad);
997 GST_OBJECT_UNLOCK (pad);
999 case GST_PAD_MODE_PUSH:
1000 case GST_PAD_MODE_PULL:
1001 GST_OBJECT_LOCK (pad);
1002 while (G_UNLIKELY (pad->priv->in_activation))
1003 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1004 if (new_mode == GST_PAD_MODE (pad)) {
1005 GST_WARNING_OBJECT (pad,
1006 "Pad is already in the process of being activated");
1007 GST_OBJECT_UNLOCK (pad);
1010 pad->priv->in_activation = TRUE;
1011 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1012 gst_pad_mode_get_name (new_mode));
1013 GST_PAD_UNSET_FLUSHING (pad);
1014 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1015 GST_PAD_MODE (pad) = new_mode;
1016 if (GST_PAD_IS_SINK (pad)) {
1018 /* make sure the peer src pad sends us all events */
1019 if ((peer = GST_PAD_PEER (pad))) {
1020 gst_object_ref (peer);
1021 GST_OBJECT_UNLOCK (pad);
1023 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1024 GST_DEBUG_PAD_NAME (peer));
1026 GST_OBJECT_LOCK (peer);
1027 schedule_events (peer, NULL);
1028 GST_OBJECT_UNLOCK (peer);
1030 gst_object_unref (peer);
1032 GST_OBJECT_UNLOCK (pad);
1035 GST_OBJECT_UNLOCK (pad);
1043 post_activate (GstPad * pad, GstPadMode new_mode)
1046 case GST_PAD_MODE_NONE:
1047 GST_OBJECT_LOCK (pad);
1048 pad->priv->in_activation = FALSE;
1049 g_cond_broadcast (&pad->priv->activation_cond);
1050 GST_OBJECT_UNLOCK (pad);
1052 /* ensures that streaming stops */
1053 GST_PAD_STREAM_LOCK (pad);
1054 GST_DEBUG_OBJECT (pad, "stopped streaming");
1055 GST_OBJECT_LOCK (pad);
1056 remove_events (pad);
1057 GST_OBJECT_UNLOCK (pad);
1058 GST_PAD_STREAM_UNLOCK (pad);
1060 case GST_PAD_MODE_PUSH:
1061 case GST_PAD_MODE_PULL:
1062 GST_OBJECT_LOCK (pad);
1063 pad->priv->in_activation = FALSE;
1064 g_cond_broadcast (&pad->priv->activation_cond);
1065 GST_OBJECT_UNLOCK (pad);
1072 * gst_pad_set_active:
1073 * @pad: the #GstPad to activate or deactivate.
1074 * @active: whether or not the pad should be active.
1076 * Activates or deactivates the given pad.
1077 * Normally called from within core state change functions.
1079 * If @active, makes sure the pad is active. If it is already active, either in
1080 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1081 * function to perform the actual activation.
1083 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1084 * and a %FALSE argument.
1086 * Returns: %TRUE if the operation was successful.
1091 gst_pad_set_active (GstPad * pad, gboolean active)
1095 gboolean ret = FALSE;
1097 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1099 GST_OBJECT_LOCK (pad);
1100 old = GST_PAD_MODE (pad);
1101 ACQUIRE_PARENT (pad, parent, no_parent);
1102 GST_OBJECT_UNLOCK (pad);
1105 if (old == GST_PAD_MODE_NONE) {
1106 GST_DEBUG_OBJECT (pad, "activating pad from none");
1107 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1109 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1111 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1112 gst_pad_mode_get_name (old));
1116 if (old == GST_PAD_MODE_NONE) {
1117 GST_DEBUG_OBJECT (pad, "pad was inactive");
1120 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1121 gst_pad_mode_get_name (old));
1122 ret = activate_mode_internal (pad, parent, old, FALSE);
1124 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1128 RELEASE_PARENT (parent);
1130 if (G_UNLIKELY (!ret))
1138 GST_DEBUG_OBJECT (pad, "no parent");
1139 GST_OBJECT_UNLOCK (pad);
1144 GST_OBJECT_LOCK (pad);
1146 g_critical ("Failed to deactivate pad %s:%s, very bad",
1147 GST_DEBUG_PAD_NAME (pad));
1149 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1151 GST_OBJECT_UNLOCK (pad);
1157 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1160 gboolean res = FALSE;
1161 GstPadMode old, new;
1162 GstPadDirection dir;
1165 GST_OBJECT_LOCK (pad);
1166 old = GST_PAD_MODE (pad);
1167 dir = GST_PAD_DIRECTION (pad);
1168 GST_OBJECT_UNLOCK (pad);
1170 new = active ? mode : GST_PAD_MODE_NONE;
1175 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1176 /* pad was activate in the wrong direction, deactivate it
1177 * and reactivate it in the requested mode */
1178 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1179 gst_pad_mode_get_name (old));
1181 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1182 goto deactivate_failed;
1183 old = GST_PAD_MODE_NONE;
1187 case GST_PAD_MODE_PULL:
1189 if (dir == GST_PAD_SINK) {
1190 if ((peer = gst_pad_get_peer (pad))) {
1191 GST_DEBUG_OBJECT (pad, "calling peer");
1192 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1194 gst_object_unref (peer);
1196 /* there is no peer, this is only fatal when we activate. When we
1197 * deactivate, we must assume the application has unlinked the peer and
1198 * will deactivate it eventually. */
1202 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1205 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1206 goto failure; /* Can't activate pull on a src without a
1207 getrange function */
1215 /* Mark pad as needing reconfiguration */
1217 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1219 /* pre_activate returns TRUE if we weren't already in the process of
1220 * switching to the 'new' mode */
1221 if (pre_activate (pad, new)) {
1223 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1224 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1228 /* can happen for sinks of passthrough elements */
1231 post_activate (pad, new);
1234 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1235 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1240 /* Clear sticky flags on deactivation */
1242 GST_OBJECT_LOCK (pad);
1243 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1244 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1245 GST_OBJECT_UNLOCK (pad);
1253 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1254 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1259 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1260 "failed to %s in switch to %s mode from %s mode",
1261 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1262 gst_pad_mode_get_name (old));
1267 GST_OBJECT_LOCK (peer);
1268 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1269 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1270 GST_OBJECT_UNLOCK (peer);
1271 gst_object_unref (peer);
1276 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1277 "pad in pull mode");
1282 GST_OBJECT_LOCK (pad);
1283 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1284 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1285 GST_PAD_SET_FLUSHING (pad);
1286 GST_PAD_MODE (pad) = old;
1287 pad->priv->in_activation = FALSE;
1288 g_cond_broadcast (&pad->priv->activation_cond);
1289 GST_OBJECT_UNLOCK (pad);
1295 * gst_pad_activate_mode:
1296 * @pad: the #GstPad to activate or deactivate.
1297 * @mode: the requested activation mode
1298 * @active: whether or not the pad should be active.
1300 * Activates or deactivates the given pad in @mode via dispatching to the
1301 * pad's activatemodefunc. For use from within pad activation functions only.
1303 * If you don't know what this is, you probably don't want to call it.
1305 * Returns: %TRUE if the operation was successful.
1310 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1314 GstPadMode old, new;
1316 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1318 GST_OBJECT_LOCK (pad);
1320 old = GST_PAD_MODE (pad);
1321 new = active ? mode : GST_PAD_MODE_NONE;
1325 ACQUIRE_PARENT (pad, parent, no_parent);
1327 GST_OBJECT_UNLOCK (pad);
1329 res = activate_mode_internal (pad, parent, mode, active);
1331 RELEASE_PARENT (parent);
1337 GST_OBJECT_UNLOCK (pad);
1338 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1339 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1344 GST_WARNING_OBJECT (pad, "no parent");
1345 GST_OBJECT_UNLOCK (pad);
1351 * gst_pad_is_active:
1352 * @pad: the #GstPad to query
1354 * Query if a pad is active
1356 * Returns: %TRUE if the pad is active.
1361 gst_pad_is_active (GstPad * pad)
1363 gboolean result = FALSE;
1365 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1367 GST_OBJECT_LOCK (pad);
1368 result = GST_PAD_IS_ACTIVE (pad);
1369 GST_OBJECT_UNLOCK (pad);
1375 cleanup_hook (GstPad * pad, GHook * hook)
1377 GstPadProbeType type;
1379 if (!G_HOOK_IS_VALID (hook))
1382 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1384 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1385 /* unblock when we remove the last blocking probe */
1387 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1390 /* Might have new probes now that want to be called */
1391 GST_PAD_BLOCK_BROADCAST (pad);
1393 if (pad->num_blocked == 0) {
1394 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1395 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1398 g_hook_destroy_link (&pad->probes, hook);
1403 * gst_pad_add_probe:
1404 * @pad: the #GstPad to add the probe to
1405 * @mask: the probe mask
1406 * @callback: #GstPadProbeCallback that will be called with notifications of
1408 * @user_data: (closure): user data passed to the callback
1409 * @destroy_data: #GDestroyNotify for user_data
1411 * Be notified of different states of pads. The provided callback is called for
1412 * every state that matches @mask.
1414 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1415 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1416 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1417 * immediately if the pad is already idle while calling gst_pad_add_probe().
1418 * In each of the groups, probes are called in the order in which they were
1421 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1422 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1423 * happen that the probe can be run immediately and if the probe returns
1424 * GST_PAD_PROBE_REMOVE this functions returns 0.
1429 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1430 GstPadProbeCallback callback, gpointer user_data,
1431 GDestroyNotify destroy_data)
1436 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1437 g_return_val_if_fail (mask != 0, 0);
1439 GST_OBJECT_LOCK (pad);
1441 /* make a new probe */
1442 hook = g_hook_alloc (&pad->probes);
1444 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1447 /* when no constraints are given for the types, assume all types are
1449 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1450 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1451 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1452 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1454 /* store our flags and other fields */
1455 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1456 hook->func = callback;
1457 hook->data = user_data;
1458 hook->destroy = destroy_data;
1459 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1462 g_hook_append (&pad->probes, hook);
1464 /* incremenent cookie so that the new hook gets called */
1465 pad->priv->probe_list_cookie++;
1467 /* get the id of the hook, we return this and it can be used to remove the
1469 res = hook->hook_id;
1471 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1473 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1474 /* we have a block probe */
1476 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1477 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1478 "now %d blocking probes", pad->num_blocked);
1480 /* Might have new probes now that want to be called */
1481 GST_PAD_BLOCK_BROADCAST (pad);
1484 /* call the callback if we need to be called for idle callbacks */
1485 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1486 if (pad->priv->using > 0) {
1487 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1488 * flag above, the last thread to leave the push will do the callback. New
1489 * threads going into the push will block. */
1490 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1491 "pad is in use, delay idle callback");
1492 GST_OBJECT_UNLOCK (pad);
1494 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1495 GstPadProbeReturn ret;
1497 /* Keep another ref, the callback could destroy the pad */
1498 gst_object_ref (pad);
1499 pad->priv->idle_running++;
1501 /* the pad is idle now, we can signal the idle callback now */
1502 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1503 "pad is idle, trigger idle callback");
1504 GST_OBJECT_UNLOCK (pad);
1506 ret = callback (pad, &info, user_data);
1508 GST_OBJECT_LOCK (pad);
1510 case GST_PAD_PROBE_REMOVE:
1511 /* remove the probe */
1512 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1513 cleanup_hook (pad, hook);
1516 case GST_PAD_PROBE_DROP:
1517 GST_DEBUG_OBJECT (pad, "asked to drop item");
1519 case GST_PAD_PROBE_PASS:
1520 GST_DEBUG_OBJECT (pad, "asked to pass item");
1522 case GST_PAD_PROBE_OK:
1523 GST_DEBUG_OBJECT (pad, "probe returned OK");
1525 case GST_PAD_PROBE_HANDLED:
1526 GST_DEBUG_OBJECT (pad, "probe handled the data");
1529 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1532 pad->priv->idle_running--;
1533 if (pad->priv->idle_running == 0) {
1534 GST_PAD_BLOCK_BROADCAST (pad);
1536 GST_OBJECT_UNLOCK (pad);
1538 gst_object_unref (pad);
1541 GST_OBJECT_UNLOCK (pad);
1547 * gst_pad_remove_probe:
1548 * @pad: the #GstPad with the probe
1549 * @id: the probe id to remove
1551 * Remove the probe with @id from @pad.
1556 gst_pad_remove_probe (GstPad * pad, gulong id)
1560 g_return_if_fail (GST_IS_PAD (pad));
1562 GST_OBJECT_LOCK (pad);
1564 hook = g_hook_get (&pad->probes, id);
1568 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1570 cleanup_hook (pad, hook);
1571 GST_OBJECT_UNLOCK (pad);
1577 GST_OBJECT_UNLOCK (pad);
1578 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1584 * gst_pad_is_blocked:
1585 * @pad: the #GstPad to query
1587 * Checks if the pad is blocked or not. This function returns the
1588 * last requested state of the pad. It is not certain that the pad
1589 * is actually blocking at this point (see gst_pad_is_blocking()).
1591 * Returns: %TRUE if the pad is blocked.
1596 gst_pad_is_blocked (GstPad * pad)
1598 gboolean result = FALSE;
1600 g_return_val_if_fail (GST_IS_PAD (pad), result);
1602 GST_OBJECT_LOCK (pad);
1603 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1604 GST_OBJECT_UNLOCK (pad);
1610 * gst_pad_is_blocking:
1611 * @pad: the #GstPad to query
1613 * Checks if the pad is blocking or not. This is a guaranteed state
1614 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1616 * Returns: %TRUE if the pad is blocking.
1621 gst_pad_is_blocking (GstPad * pad)
1623 gboolean result = FALSE;
1625 g_return_val_if_fail (GST_IS_PAD (pad), result);
1627 GST_OBJECT_LOCK (pad);
1628 /* the blocking flag is only valid if the pad is not flushing */
1629 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1630 GST_OBJECT_UNLOCK (pad);
1636 * gst_pad_needs_reconfigure:
1637 * @pad: the #GstPad to check
1639 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1640 * if the flag was set.
1642 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1645 gst_pad_needs_reconfigure (GstPad * pad)
1647 gboolean reconfigure;
1649 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1651 GST_OBJECT_LOCK (pad);
1652 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1653 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1654 GST_OBJECT_UNLOCK (pad);
1660 * gst_pad_check_reconfigure:
1661 * @pad: the #GstPad to check
1663 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1664 * if the flag was set.
1666 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1669 gst_pad_check_reconfigure (GstPad * pad)
1671 gboolean reconfigure;
1673 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1675 GST_OBJECT_LOCK (pad);
1676 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1678 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1679 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1681 GST_OBJECT_UNLOCK (pad);
1687 * gst_pad_mark_reconfigure:
1688 * @pad: the #GstPad to mark
1690 * Mark a pad for needing reconfiguration. The next call to
1691 * gst_pad_check_reconfigure() will return %TRUE after this call.
1694 gst_pad_mark_reconfigure (GstPad * pad)
1696 g_return_if_fail (GST_IS_PAD (pad));
1698 GST_OBJECT_LOCK (pad);
1699 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1700 GST_OBJECT_UNLOCK (pad);
1704 * gst_pad_set_activate_function:
1706 * @f: the #GstPadActivateFunction to set.
1708 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1712 * gst_pad_set_activate_function_full:
1714 * @activate: the #GstPadActivateFunction to set.
1715 * @user_data: user_data passed to @notify
1716 * @notify: notify called when @activate will not be used anymore.
1718 * Sets the given activate function for @pad. The activate function will
1719 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1720 * Only makes sense to set on sink pads.
1722 * Call this function if your sink pad can start a pull-based task.
1725 gst_pad_set_activate_function_full (GstPad * pad,
1726 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1728 g_return_if_fail (GST_IS_PAD (pad));
1730 if (pad->activatenotify)
1731 pad->activatenotify (pad->activatedata);
1732 GST_PAD_ACTIVATEFUNC (pad) = activate;
1733 pad->activatedata = user_data;
1734 pad->activatenotify = notify;
1736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1737 GST_DEBUG_FUNCPTR_NAME (activate));
1741 * gst_pad_set_activatemode_function:
1743 * @f: the #GstPadActivateModeFunction to set.
1745 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1749 * gst_pad_set_activatemode_function_full:
1751 * @activatemode: the #GstPadActivateModeFunction to set.
1752 * @user_data: user_data passed to @notify
1753 * @notify: notify called when @activatemode will not be used anymore.
1755 * Sets the given activate_mode function for the pad. An activate_mode function
1756 * prepares the element for data passing.
1759 gst_pad_set_activatemode_function_full (GstPad * pad,
1760 GstPadActivateModeFunction activatemode, gpointer user_data,
1761 GDestroyNotify notify)
1763 g_return_if_fail (GST_IS_PAD (pad));
1765 if (pad->activatemodenotify)
1766 pad->activatemodenotify (pad->activatemodedata);
1767 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1768 pad->activatemodedata = user_data;
1769 pad->activatemodenotify = notify;
1771 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1772 GST_DEBUG_FUNCPTR_NAME (activatemode));
1776 * gst_pad_set_chain_function:
1777 * @p: a sink #GstPad.
1778 * @f: the #GstPadChainFunction to set.
1780 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1784 * gst_pad_set_chain_function_full:
1785 * @pad: a sink #GstPad.
1786 * @chain: the #GstPadChainFunction to set.
1787 * @user_data: user_data passed to @notify
1788 * @notify: notify called when @chain will not be used anymore.
1790 * Sets the given chain function for the pad. The chain function is called to
1791 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1794 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1795 gpointer user_data, GDestroyNotify notify)
1797 g_return_if_fail (GST_IS_PAD (pad));
1798 g_return_if_fail (GST_PAD_IS_SINK (pad));
1800 if (pad->chainnotify)
1801 pad->chainnotify (pad->chaindata);
1802 GST_PAD_CHAINFUNC (pad) = chain;
1803 pad->chaindata = user_data;
1804 pad->chainnotify = notify;
1806 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1807 GST_DEBUG_FUNCPTR_NAME (chain));
1811 * gst_pad_set_chain_list_function:
1812 * @p: a sink #GstPad.
1813 * @f: the #GstPadChainListFunction to set.
1815 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1819 * gst_pad_set_chain_list_function_full:
1820 * @pad: a sink #GstPad.
1821 * @chainlist: the #GstPadChainListFunction to set.
1822 * @user_data: user_data passed to @notify
1823 * @notify: notify called when @chainlist will not be used anymore.
1825 * Sets the given chain list function for the pad. The chainlist function is
1826 * called to process a #GstBufferList input buffer list. See
1827 * #GstPadChainListFunction for more details.
1830 gst_pad_set_chain_list_function_full (GstPad * pad,
1831 GstPadChainListFunction chainlist, gpointer user_data,
1832 GDestroyNotify notify)
1834 g_return_if_fail (GST_IS_PAD (pad));
1835 g_return_if_fail (GST_PAD_IS_SINK (pad));
1837 if (pad->chainlistnotify)
1838 pad->chainlistnotify (pad->chainlistdata);
1839 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1840 pad->chainlistdata = user_data;
1841 pad->chainlistnotify = notify;
1843 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1844 GST_DEBUG_FUNCPTR_NAME (chainlist));
1848 * gst_pad_set_getrange_function:
1849 * @p: a source #GstPad.
1850 * @f: the #GstPadGetRangeFunction to set.
1852 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1856 * gst_pad_set_getrange_function_full:
1857 * @pad: a source #GstPad.
1858 * @get: the #GstPadGetRangeFunction to set.
1859 * @user_data: user_data passed to @notify
1860 * @notify: notify called when @get will not be used anymore.
1862 * Sets the given getrange function for the pad. The getrange function is
1863 * called to produce a new #GstBuffer to start the processing pipeline. see
1864 * #GstPadGetRangeFunction for a description of the getrange function.
1867 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1868 gpointer user_data, GDestroyNotify notify)
1870 g_return_if_fail (GST_IS_PAD (pad));
1871 g_return_if_fail (GST_PAD_IS_SRC (pad));
1873 if (pad->getrangenotify)
1874 pad->getrangenotify (pad->getrangedata);
1875 GST_PAD_GETRANGEFUNC (pad) = get;
1876 pad->getrangedata = user_data;
1877 pad->getrangenotify = notify;
1879 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1880 GST_DEBUG_FUNCPTR_NAME (get));
1884 * gst_pad_set_event_function:
1885 * @p: a #GstPad of either direction.
1886 * @f: the #GstPadEventFunction to set.
1888 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1892 * gst_pad_set_event_function_full:
1893 * @pad: a #GstPad of either direction.
1894 * @event: the #GstPadEventFunction to set.
1895 * @user_data: user_data passed to @notify
1896 * @notify: notify called when @event will not be used anymore.
1898 * Sets the given event handler for the pad.
1901 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1902 gpointer user_data, GDestroyNotify notify)
1904 g_return_if_fail (GST_IS_PAD (pad));
1906 if (pad->eventnotify)
1907 pad->eventnotify (pad->eventdata);
1908 GST_PAD_EVENTFUNC (pad) = event;
1909 pad->eventdata = user_data;
1910 pad->eventnotify = notify;
1912 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1913 GST_DEBUG_FUNCPTR_NAME (event));
1917 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1921 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1922 if (ret == GST_FLOW_OK)
1928 * gst_pad_set_event_full_function:
1929 * @p: a #GstPad of either direction.
1930 * @f: the #GstPadEventFullFunction to set.
1932 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1936 * gst_pad_set_event_full_function_full:
1937 * @pad: a #GstPad of either direction.
1938 * @event: the #GstPadEventFullFunction to set.
1939 * @user_data: user_data passed to @notify
1940 * @notify: notify called when @event will not be used anymore.
1942 * Sets the given event handler for the pad.
1947 gst_pad_set_event_full_function_full (GstPad * pad,
1948 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1950 g_return_if_fail (GST_IS_PAD (pad));
1952 if (pad->eventnotify)
1953 pad->eventnotify (pad->eventdata);
1954 GST_PAD_EVENTFULLFUNC (pad) = event;
1955 GST_PAD_EVENTFUNC (pad) = event_wrap;
1956 pad->eventdata = user_data;
1957 pad->eventnotify = notify;
1959 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1960 GST_DEBUG_FUNCPTR_NAME (event));
1964 * gst_pad_set_query_function:
1965 * @p: a #GstPad of either direction.
1966 * @f: the #GstPadQueryFunction to set.
1968 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1972 * gst_pad_set_query_function_full:
1973 * @pad: a #GstPad of either direction.
1974 * @query: the #GstPadQueryFunction to set.
1975 * @user_data: user_data passed to @notify
1976 * @notify: notify called when @query will not be used anymore.
1978 * Set the given query function for the pad.
1981 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1982 gpointer user_data, GDestroyNotify notify)
1984 g_return_if_fail (GST_IS_PAD (pad));
1986 if (pad->querynotify)
1987 pad->querynotify (pad->querydata);
1988 GST_PAD_QUERYFUNC (pad) = query;
1989 pad->querydata = user_data;
1990 pad->querynotify = notify;
1992 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1993 GST_DEBUG_FUNCPTR_NAME (query));
1997 * gst_pad_set_iterate_internal_links_function:
1998 * @p: a #GstPad of either direction.
1999 * @f: the #GstPadIterIntLinkFunction to set.
2001 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
2002 * for the user_data and notify.
2005 * gst_pad_set_iterate_internal_links_function_full:
2006 * @pad: a #GstPad of either direction.
2007 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2008 * @user_data: user_data passed to @notify
2009 * @notify: notify called when @iterintlink will not be used anymore.
2011 * Sets the given internal link iterator function for the pad.
2014 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2015 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2016 GDestroyNotify notify)
2018 g_return_if_fail (GST_IS_PAD (pad));
2020 if (pad->iterintlinknotify)
2021 pad->iterintlinknotify (pad->iterintlinkdata);
2022 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2023 pad->iterintlinkdata = user_data;
2024 pad->iterintlinknotify = notify;
2026 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2027 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2031 * gst_pad_set_link_function:
2033 * @f: the #GstPadLinkFunction to set.
2035 * Calls gst_pad_set_link_function_full() with %NULL
2036 * for the user_data and notify.
2039 * gst_pad_set_link_function_full:
2041 * @link: the #GstPadLinkFunction to set.
2042 * @user_data: user_data passed to @notify
2043 * @notify: notify called when @link will not be used anymore.
2045 * Sets the given link function for the pad. It will be called when
2046 * the pad is linked with another pad.
2048 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2051 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2052 * cannot be made for some reason.
2054 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2055 * of the peer sink pad, if present.
2058 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2059 gpointer user_data, GDestroyNotify notify)
2061 g_return_if_fail (GST_IS_PAD (pad));
2063 if (pad->linknotify)
2064 pad->linknotify (pad->linkdata);
2065 GST_PAD_LINKFUNC (pad) = link;
2066 pad->linkdata = user_data;
2067 pad->linknotify = notify;
2069 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2070 GST_DEBUG_FUNCPTR_NAME (link));
2074 * gst_pad_set_unlink_function:
2076 * @f: the #GstPadUnlinkFunction to set.
2078 * Calls gst_pad_set_unlink_function_full() with %NULL
2079 * for the user_data and notify.
2082 * gst_pad_set_unlink_function_full:
2084 * @unlink: the #GstPadUnlinkFunction to set.
2085 * @user_data: user_data passed to @notify
2086 * @notify: notify called when @unlink will not be used anymore.
2088 * Sets the given unlink function for the pad. It will be called
2089 * when the pad is unlinked.
2092 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2093 gpointer user_data, GDestroyNotify notify)
2095 g_return_if_fail (GST_IS_PAD (pad));
2097 if (pad->unlinknotify)
2098 pad->unlinknotify (pad->unlinkdata);
2099 GST_PAD_UNLINKFUNC (pad) = unlink;
2100 pad->unlinkdata = user_data;
2101 pad->unlinknotify = notify;
2103 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2104 GST_DEBUG_FUNCPTR_NAME (unlink));
2109 * @srcpad: the source #GstPad to unlink.
2110 * @sinkpad: the sink #GstPad to unlink.
2112 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2113 * signal on both pads.
2115 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2116 * the pads were not linked together.
2121 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2123 gboolean result = FALSE;
2124 GstElement *parent = NULL;
2126 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2127 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2128 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2129 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2131 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2133 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2134 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2135 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2137 /* We need to notify the parent before taking any pad locks as the bin in
2138 * question might be waiting for a lock on the pad while holding its lock
2139 * that our message will try to take. */
2140 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2141 if (GST_IS_ELEMENT (parent)) {
2142 gst_element_post_message (parent,
2143 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2144 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2146 gst_object_unref (parent);
2151 GST_OBJECT_LOCK (srcpad);
2152 GST_OBJECT_LOCK (sinkpad);
2154 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2155 goto not_linked_together;
2157 if (GST_PAD_UNLINKFUNC (srcpad)) {
2158 GstObject *tmpparent;
2160 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2162 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2163 RELEASE_PARENT (tmpparent);
2166 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2167 GstObject *tmpparent;
2169 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2171 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2172 RELEASE_PARENT (tmpparent);
2176 /* first clear peers */
2177 GST_PAD_PEER (srcpad) = NULL;
2178 GST_PAD_PEER (sinkpad) = NULL;
2180 GST_OBJECT_UNLOCK (sinkpad);
2181 GST_OBJECT_UNLOCK (srcpad);
2183 /* fire off a signal to each of the pads telling them
2184 * that they've been unlinked */
2185 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2186 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2188 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2189 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2194 if (parent != NULL) {
2195 gst_element_post_message (parent,
2196 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2197 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2198 gst_object_unref (parent);
2200 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2204 not_linked_together:
2206 /* we do not emit a warning in this case because unlinking cannot
2207 * be made MT safe.*/
2208 GST_OBJECT_UNLOCK (sinkpad);
2209 GST_OBJECT_UNLOCK (srcpad);
2215 * gst_pad_is_linked:
2216 * @pad: pad to check
2218 * Checks if a @pad is linked to another pad or not.
2220 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2225 gst_pad_is_linked (GstPad * pad)
2229 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2231 GST_OBJECT_LOCK (pad);
2232 result = (GST_PAD_PEER (pad) != NULL);
2233 GST_OBJECT_UNLOCK (pad);
2238 /* get the caps from both pads and see if the intersection
2241 * This function should be called with the pad LOCK on both
2245 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2246 GstPadLinkCheck flags)
2248 GstCaps *srccaps = NULL;
2249 GstCaps *sinkcaps = NULL;
2250 gboolean compatible = FALSE;
2252 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2255 /* Doing the expensive caps checking takes priority over only checking the template caps */
2256 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2257 GST_OBJECT_UNLOCK (sink);
2258 GST_OBJECT_UNLOCK (src);
2260 srccaps = gst_pad_query_caps (src, NULL);
2261 sinkcaps = gst_pad_query_caps (sink, NULL);
2263 GST_OBJECT_LOCK (src);
2264 GST_OBJECT_LOCK (sink);
2266 /* If one of the two pads doesn't have a template, consider the intersection
2268 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2269 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2273 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2275 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2278 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2280 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2283 /* if we have caps on both pads we can check the intersection. If one
2284 * of the caps is %NULL, we return %TRUE. */
2285 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2287 gst_caps_unref (srccaps);
2289 gst_caps_unref (sinkcaps);
2293 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2294 gst_caps_unref (srccaps);
2295 gst_caps_unref (sinkcaps);
2298 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2299 (compatible ? "" : "not "));
2304 /* check if the grandparents of both pads are the same.
2305 * This check is required so that we don't try to link
2306 * pads from elements in different bins without ghostpads.
2308 * The LOCK should be held on both pads
2311 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2313 GstObject *psrc, *psink;
2315 psrc = GST_OBJECT_PARENT (src);
2316 psink = GST_OBJECT_PARENT (sink);
2318 /* if one of the pads has no parent, we allow the link */
2319 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2322 /* only care about parents that are elements */
2323 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2324 goto no_element_parent;
2326 /* if the parents are the same, we have a loop */
2327 if (G_UNLIKELY (psrc == psink))
2330 /* if they both have a parent, we check the grandparents. We can not lock
2331 * the parent because we hold on the child (pad) and the locking order is
2332 * parent >> child. */
2333 psrc = GST_OBJECT_PARENT (psrc);
2334 psink = GST_OBJECT_PARENT (psink);
2336 /* if they have grandparents but they are not the same */
2337 if (G_UNLIKELY (psrc != psink))
2338 goto wrong_grandparents;
2345 GST_CAT_DEBUG (GST_CAT_CAPS,
2346 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2347 GST_PTR_FORMAT, psrc, psink);
2352 GST_CAT_DEBUG (GST_CAT_CAPS,
2353 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2354 GST_PTR_FORMAT, psrc, psink);
2359 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2365 GST_CAT_DEBUG (GST_CAT_CAPS,
2366 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2367 GST_PTR_FORMAT, psrc, psink);
2372 /* FIXME leftover from an attempt at refactoring... */
2373 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2374 * the two pads will be locked in the srcpad, sinkpad order. */
2375 static GstPadLinkReturn
2376 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2378 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2379 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2381 GST_OBJECT_LOCK (srcpad);
2383 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2384 goto src_was_linked;
2386 GST_OBJECT_LOCK (sinkpad);
2388 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2389 goto sink_was_linked;
2391 /* check hierarchy, pads can only be linked if the grandparents
2393 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2394 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2395 goto wrong_hierarchy;
2397 /* check pad caps for non-empty intersection */
2398 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2401 /* FIXME check pad scheduling for non-empty intersection */
2403 return GST_PAD_LINK_OK;
2407 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2408 GST_DEBUG_PAD_NAME (srcpad),
2409 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2410 /* we do not emit a warning in this case because unlinking cannot
2411 * be made MT safe.*/
2412 GST_OBJECT_UNLOCK (srcpad);
2413 return GST_PAD_LINK_WAS_LINKED;
2417 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2418 GST_DEBUG_PAD_NAME (sinkpad),
2419 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2420 /* we do not emit a warning in this case because unlinking cannot
2421 * be made MT safe.*/
2422 GST_OBJECT_UNLOCK (sinkpad);
2423 GST_OBJECT_UNLOCK (srcpad);
2424 return GST_PAD_LINK_WAS_LINKED;
2428 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2429 GST_OBJECT_UNLOCK (sinkpad);
2430 GST_OBJECT_UNLOCK (srcpad);
2431 return GST_PAD_LINK_WRONG_HIERARCHY;
2435 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2436 GST_OBJECT_UNLOCK (sinkpad);
2437 GST_OBJECT_UNLOCK (srcpad);
2438 return GST_PAD_LINK_NOFORMAT;
2444 * @srcpad: the source #GstPad.
2445 * @sinkpad: the sink #GstPad.
2447 * Checks if the source pad and the sink pad are compatible so they can be
2450 * Returns: %TRUE if the pads can be linked.
2453 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2455 GstPadLinkReturn result;
2457 /* generic checks */
2458 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2459 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2461 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2462 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2464 /* gst_pad_link_prepare does everything for us, we only release the locks
2465 * on the pads that it gets us. If this function returns !OK the locks are not
2467 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2468 if (result != GST_PAD_LINK_OK)
2471 GST_OBJECT_UNLOCK (srcpad);
2472 GST_OBJECT_UNLOCK (sinkpad);
2475 return result == GST_PAD_LINK_OK;
2479 * gst_pad_link_full:
2480 * @srcpad: the source #GstPad to link.
2481 * @sinkpad: the sink #GstPad to link.
2482 * @flags: the checks to validate when linking
2484 * Links the source pad and the sink pad.
2486 * This variant of #gst_pad_link provides a more granular control on the
2487 * checks being done when linking. While providing some considerable speedups
2488 * the caller of this method must be aware that wrong usage of those flags
2489 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2490 * for more information.
2494 * Returns: A result code indicating if the connection worked or
2498 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2500 GstPadLinkReturn result;
2502 GstPadLinkFunction srcfunc, sinkfunc;
2504 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2505 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2506 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2507 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2508 GST_PAD_LINK_WRONG_DIRECTION);
2510 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2512 /* Notify the parent early. See gst_pad_unlink for details. */
2513 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2514 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2515 gst_element_post_message (parent,
2516 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2517 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2519 gst_object_unref (parent);
2524 /* prepare will also lock the two pads */
2525 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2527 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2528 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2529 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2530 gst_pad_link_get_name (result));
2534 /* must set peers before calling the link function */
2535 GST_PAD_PEER (srcpad) = sinkpad;
2536 GST_PAD_PEER (sinkpad) = srcpad;
2538 /* check events, when something is different, mark pending */
2539 schedule_events (srcpad, sinkpad);
2541 /* get the link functions */
2542 srcfunc = GST_PAD_LINKFUNC (srcpad);
2543 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2545 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2546 /* custom link functions, execute them */
2547 GST_OBJECT_UNLOCK (sinkpad);
2548 GST_OBJECT_UNLOCK (srcpad);
2551 GstObject *tmpparent;
2553 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2554 /* this one will call the peer link function */
2555 result = srcfunc (srcpad, tmpparent, sinkpad);
2556 RELEASE_PARENT (tmpparent);
2557 } else if (sinkfunc) {
2558 GstObject *tmpparent;
2560 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2561 /* if no source link function, we need to call the sink link
2562 * function ourselves. */
2563 result = sinkfunc (sinkpad, tmpparent, srcpad);
2564 RELEASE_PARENT (tmpparent);
2568 GST_OBJECT_LOCK (srcpad);
2569 GST_OBJECT_LOCK (sinkpad);
2571 /* we released the lock, check if the same pads are linked still */
2572 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2573 goto concurrent_link;
2575 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2578 GST_OBJECT_UNLOCK (sinkpad);
2579 GST_OBJECT_UNLOCK (srcpad);
2581 /* fire off a signal to each of the pads telling them
2582 * that they've been linked */
2583 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2584 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2586 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2587 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2589 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2590 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2593 if (G_LIKELY (parent)) {
2594 gst_element_post_message (parent,
2595 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2596 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2597 gst_object_unref (parent);
2600 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2606 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2607 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2608 GST_OBJECT_UNLOCK (sinkpad);
2609 GST_OBJECT_UNLOCK (srcpad);
2611 /* The other link operation succeeded first */
2612 result = GST_PAD_LINK_WAS_LINKED;
2617 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2618 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2619 gst_pad_link_get_name (result));
2621 GST_PAD_PEER (srcpad) = NULL;
2622 GST_PAD_PEER (sinkpad) = NULL;
2624 GST_OBJECT_UNLOCK (sinkpad);
2625 GST_OBJECT_UNLOCK (srcpad);
2633 * @srcpad: the source #GstPad to link.
2634 * @sinkpad: the sink #GstPad to link.
2636 * Links the source pad and the sink pad.
2638 * Returns: A result code indicating if the connection worked or
2644 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2646 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2650 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2652 GstPadTemplate **template_p;
2654 /* this function would need checks if it weren't static */
2656 GST_OBJECT_LOCK (pad);
2657 template_p = &pad->padtemplate;
2658 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2659 GST_OBJECT_UNLOCK (pad);
2662 gst_pad_template_pad_created (templ, pad);
2666 * gst_pad_get_pad_template:
2669 * Gets the template for @pad.
2671 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2672 * this pad was instantiated, or %NULL if this pad has no
2673 * template. Unref after usage.
2676 gst_pad_get_pad_template (GstPad * pad)
2678 GstPadTemplate *templ;
2680 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2682 templ = GST_PAD_PAD_TEMPLATE (pad);
2684 return (templ ? gst_object_ref (templ) : NULL);
2688 * gst_pad_has_current_caps:
2689 * @pad: a #GstPad to check
2691 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2693 * Returns: %TRUE when @pad has caps associated with it.
2696 gst_pad_has_current_caps (GstPad * pad)
2701 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2703 GST_OBJECT_LOCK (pad);
2704 caps = get_pad_caps (pad);
2705 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2706 "check current pad caps %" GST_PTR_FORMAT, caps);
2707 result = (caps != NULL);
2708 GST_OBJECT_UNLOCK (pad);
2714 * gst_pad_get_current_caps:
2715 * @pad: a #GstPad to get the current capabilities of.
2717 * Gets the capabilities currently configured on @pad with the last
2718 * #GST_EVENT_CAPS event.
2720 * Returns: (transfer full) (nullable): the current caps of the pad with
2721 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2724 gst_pad_get_current_caps (GstPad * pad)
2728 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2730 GST_OBJECT_LOCK (pad);
2731 if ((result = get_pad_caps (pad)))
2732 gst_caps_ref (result);
2733 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2734 "get current pad caps %" GST_PTR_FORMAT, result);
2735 GST_OBJECT_UNLOCK (pad);
2741 * gst_pad_get_pad_template_caps:
2742 * @pad: a #GstPad to get the template capabilities from.
2744 * Gets the capabilities for @pad's template.
2746 * Returns: (transfer full): the #GstCaps of this pad template.
2747 * Unref after usage.
2750 gst_pad_get_pad_template_caps (GstPad * pad)
2752 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2754 if (GST_PAD_PAD_TEMPLATE (pad))
2755 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2757 return gst_caps_ref (GST_CAPS_ANY);
2762 * @pad: a #GstPad to get the peer of.
2764 * Gets the peer of @pad. This function refs the peer pad so
2765 * you need to unref it after use.
2767 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2772 gst_pad_get_peer (GstPad * pad)
2776 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2778 GST_OBJECT_LOCK (pad);
2779 result = GST_PAD_PEER (pad);
2781 gst_object_ref (result);
2782 GST_OBJECT_UNLOCK (pad);
2788 * gst_pad_get_allowed_caps:
2791 * Gets the capabilities of the allowed media types that can flow through
2792 * @pad and its peer.
2794 * The allowed capabilities is calculated as the intersection of the results of
2795 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2796 * on the resulting caps.
2798 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2799 * pad link. Unref the caps when you no longer need it. This
2800 * function returns %NULL when @pad has no peer.
2805 gst_pad_get_allowed_caps (GstPad * pad)
2808 GstCaps *caps = NULL;
2811 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2813 GST_OBJECT_LOCK (pad);
2814 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2816 GST_OBJECT_UNLOCK (pad);
2818 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2820 mycaps = gst_pad_query_caps (pad, NULL);
2822 /* Query peer caps */
2823 query = gst_query_new_caps (mycaps);
2824 if (!gst_pad_peer_query (pad, query)) {
2825 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2829 gst_query_parse_caps_result (query, &caps);
2831 g_warn_if_fail (caps != NULL);
2834 gst_caps_ref (caps);
2836 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2840 gst_query_unref (query);
2841 gst_caps_unref (mycaps);
2847 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2848 GST_OBJECT_UNLOCK (pad);
2855 * gst_pad_iterate_internal_links_default:
2856 * @pad: the #GstPad to get the internal links of.
2857 * @parent: (allow-none): the parent of @pad or %NULL
2859 * Iterate the list of pads to which the given pad is linked to inside of
2860 * the parent element.
2861 * This is the default handler, and thus returns an iterator of all of the
2862 * pads inside the parent element with opposite direction.
2864 * The caller must free this iterator after use with gst_iterator_free().
2866 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2867 * has no parent. Unref each returned pad with gst_object_unref().
2870 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2877 GstElement *eparent;
2879 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2881 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2882 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2884 GST_OBJECT_LOCK (pad);
2885 eparent = GST_PAD_PARENT (pad);
2886 if (!eparent || !GST_IS_ELEMENT (eparent))
2889 gst_object_ref (eparent);
2890 GST_OBJECT_UNLOCK (pad);
2893 if (pad->direction == GST_PAD_SRC)
2894 padlist = &eparent->sinkpads;
2896 padlist = &eparent->srcpads;
2898 GST_DEBUG_OBJECT (pad, "Making iterator");
2900 cookie = &eparent->pads_cookie;
2902 lock = GST_OBJECT_GET_LOCK (eparent);
2904 res = gst_iterator_new_list (GST_TYPE_PAD,
2905 lock, cookie, padlist, (GObject *) owner, NULL);
2907 gst_object_unref (owner);
2914 GST_OBJECT_UNLOCK (pad);
2915 GST_DEBUG_OBJECT (pad, "no parent element");
2921 * gst_pad_iterate_internal_links:
2922 * @pad: the GstPad to get the internal links of.
2924 * Gets an iterator for the pads to which the given pad is linked to inside
2925 * of the parent element.
2927 * Each #GstPad element yielded by the iterator will have its refcount increased,
2928 * so unref after use.
2930 * Free-function: gst_iterator_free
2932 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2933 * or %NULL when the pad does not have an iterator function
2934 * configured. Use gst_iterator_free() after usage.
2937 gst_pad_iterate_internal_links (GstPad * pad)
2939 GstIterator *res = NULL;
2942 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2944 GST_OBJECT_LOCK (pad);
2945 ACQUIRE_PARENT (pad, parent, no_parent);
2946 GST_OBJECT_UNLOCK (pad);
2948 if (GST_PAD_ITERINTLINKFUNC (pad))
2949 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2951 RELEASE_PARENT (parent);
2958 GST_DEBUG_OBJECT (pad, "no parent");
2959 GST_OBJECT_UNLOCK (pad);
2967 * @forward: (scope call): a #GstPadForwardFunction
2968 * @user_data: user data passed to @forward
2970 * Calls @forward for all internally linked pads of @pad. This function deals with
2971 * dynamically changing internal pads and will make sure that the @forward
2972 * function is only called once for each pad.
2974 * When @forward returns %TRUE, no further pads will be processed.
2976 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2979 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2982 gboolean result = FALSE;
2984 gboolean done = FALSE;
2985 GValue item = { 0, };
2986 GList *pushed_pads = NULL;
2988 iter = gst_pad_iterate_internal_links (pad);
2994 switch (gst_iterator_next (iter, &item)) {
2995 case GST_ITERATOR_OK:
2999 intpad = g_value_get_object (&item);
3001 /* if already pushed, skip. FIXME, find something faster to tag pads */
3002 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3003 g_value_reset (&item);
3007 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3008 GST_DEBUG_PAD_NAME (intpad));
3009 done = result = forward (intpad, user_data);
3011 pushed_pads = g_list_prepend (pushed_pads, intpad);
3013 g_value_reset (&item);
3016 case GST_ITERATOR_RESYNC:
3017 /* We don't reset the result here because we don't push the event
3018 * again on pads that got the event already and because we need
3019 * to consider the result of the previous pushes */
3020 gst_iterator_resync (iter);
3022 case GST_ITERATOR_ERROR:
3023 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3026 case GST_ITERATOR_DONE:
3031 g_value_unset (&item);
3032 gst_iterator_free (iter);
3034 g_list_free (pushed_pads);
3044 gboolean dispatched;
3048 event_forward_func (GstPad * pad, EventData * data)
3050 /* for each pad we send to, we should ref the event; it's up
3051 * to downstream to unref again when handled. */
3052 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3053 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3055 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3057 data->dispatched = TRUE;
3064 * gst_pad_event_default:
3065 * @pad: a #GstPad to call the default event handler on.
3066 * @parent: (allow-none): the parent of @pad or %NULL
3067 * @event: (transfer full): the #GstEvent to handle.
3069 * Invokes the default event handler for the given pad.
3071 * The EOS event will pause the task associated with @pad before it is forwarded
3072 * to all internally linked pads,
3074 * The event is sent to all pads internally linked to @pad. This function
3075 * takes ownership of @event.
3077 * Returns: %TRUE if the event was sent successfully.
3080 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3082 gboolean result, forward = TRUE;
3084 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3085 g_return_val_if_fail (event != NULL, FALSE);
3087 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3090 switch (GST_EVENT_TYPE (event)) {
3091 case GST_EVENT_CAPS:
3092 forward = GST_PAD_IS_PROXY_CAPS (pad);
3103 data.dispatched = FALSE;
3104 data.result = FALSE;
3106 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3108 /* for sinkpads without a parent element or without internal links, nothing
3109 * will be dispatched but we still want to return TRUE. */
3110 if (data.dispatched)
3111 result = data.result;
3116 gst_event_unref (event);
3121 /* Default accept caps implementation just checks against
3122 * the allowed caps for the pad */
3124 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3126 /* get the caps and see if it intersects to something not empty */
3127 GstCaps *caps, *allowed = NULL;
3130 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3132 /* first forward the query to internally linked pads when we are dealing with
3134 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3135 result = gst_pad_proxy_query_accept_caps (pad, query);
3137 allowed = gst_pad_get_pad_template_caps (pad);
3142 gst_query_parse_accept_caps (query, &caps);
3144 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3145 allowed = gst_pad_get_pad_template_caps (pad);
3147 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3148 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3149 allowed = gst_pad_query_caps (pad, caps);
3154 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3155 GST_DEBUG_OBJECT (pad,
3156 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3158 result = gst_caps_can_intersect (caps, allowed);
3160 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3161 GST_PTR_FORMAT, allowed, caps);
3162 result = gst_caps_is_subset (caps, allowed);
3164 gst_caps_unref (allowed);
3166 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3169 gst_query_set_accept_caps_result (query, result);
3175 /* Default caps implementation */
3177 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3179 GstCaps *result = NULL, *filter;
3180 GstPadTemplate *templ;
3181 gboolean fixed_caps;
3183 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3186 /* first try to proxy if we must */
3187 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3188 if ((gst_pad_proxy_query_caps (pad, query))) {
3193 gst_query_parse_caps (query, &filter);
3195 /* no proxy or it failed, do default handling */
3196 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3198 GST_OBJECT_LOCK (pad);
3200 /* fixed caps, try the negotiated caps first */
3201 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3202 if ((result = get_pad_caps (pad)))
3203 goto filter_done_unlock;
3206 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3207 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3208 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3209 goto filter_done_unlock;
3213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3214 "non-fixed pad caps: trying pad caps");
3215 /* non fixed caps, try the negotiated caps */
3216 if ((result = get_pad_caps (pad)))
3217 goto filter_done_unlock;
3220 /* this almost never happens */
3221 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3222 result = GST_CAPS_ANY;
3225 GST_OBJECT_UNLOCK (pad);
3227 /* run the filter on the result */
3229 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3230 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3231 GST_PTR_FORMAT, result, result, filter, filter);
3232 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3233 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3236 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3237 "using caps %p %" GST_PTR_FORMAT, result, result);
3238 result = gst_caps_ref (result);
3240 gst_query_set_caps_result (query, result);
3241 gst_caps_unref (result);
3247 /* Default latency implementation */
3252 GstClockTime min, max;
3256 query_latency_default_fold (const GValue * item, GValue * ret,
3259 GstPad *pad = g_value_get_object (item), *peer;
3260 LatencyFoldData *fold_data = user_data;
3262 gboolean res = FALSE;
3264 query = gst_query_new_latency ();
3266 peer = gst_pad_get_peer (pad);
3268 res = gst_pad_peer_query (pad, query);
3270 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3275 GstClockTime min, max;
3277 gst_query_parse_latency (query, &live, &min, &max);
3279 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3280 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3282 /* FIXME : Why do we only take values into account if it's live ? */
3283 if (live || fold_data->count == 0) {
3284 if (min > fold_data->min)
3285 fold_data->min = min;
3287 if (fold_data->max == GST_CLOCK_TIME_NONE)
3288 fold_data->max = max;
3289 else if (max < fold_data->max)
3290 fold_data->max = max;
3292 fold_data->live = live;
3294 fold_data->count += 1;
3296 GST_DEBUG_OBJECT (pad, "latency query failed");
3297 g_value_set_boolean (ret, FALSE);
3300 gst_query_unref (query);
3302 gst_object_unref (peer);
3308 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3311 GstIteratorResult res;
3312 GValue ret = G_VALUE_INIT;
3314 LatencyFoldData fold_data;
3316 it = gst_pad_iterate_internal_links (pad);
3318 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3322 g_value_init (&ret, G_TYPE_BOOLEAN);
3325 fold_data.count = 0;
3326 fold_data.live = FALSE;
3328 fold_data.max = GST_CLOCK_TIME_NONE;
3330 g_value_set_boolean (&ret, TRUE);
3331 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3333 case GST_ITERATOR_OK:
3334 g_assert_not_reached ();
3336 case GST_ITERATOR_DONE:
3338 case GST_ITERATOR_ERROR:
3339 g_value_set_boolean (&ret, FALSE);
3341 case GST_ITERATOR_RESYNC:
3342 gst_iterator_resync (it);
3345 g_assert_not_reached ();
3348 gst_iterator_free (it);
3350 query_ret = g_value_get_boolean (&ret);
3352 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3353 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3354 fold_data.min, fold_data.max);
3356 if (fold_data.min > fold_data.max) {
3357 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3360 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3362 GST_LOG_OBJECT (pad, "latency query failed");
3372 gboolean dispatched;
3376 query_forward_func (GstPad * pad, QueryData * data)
3378 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3379 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3381 data->result |= gst_pad_peer_query (pad, data->query);
3383 data->dispatched = TRUE;
3385 /* stop on first successful reply */
3386 return data->result;
3390 * gst_pad_query_default:
3391 * @pad: a #GstPad to call the default query handler on.
3392 * @parent: (allow-none): the parent of @pad or %NULL
3393 * @query: (transfer none): the #GstQuery to handle.
3395 * Invokes the default query handler for the given pad.
3396 * The query is sent to all pads internally linked to @pad. Note that
3397 * if there are many possible sink pads that are internally linked to
3398 * @pad, only one will be sent the query.
3399 * Multi-sinkpad elements should implement custom query handlers.
3401 * Returns: %TRUE if the query was performed successfully.
3404 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3406 gboolean forward, ret = FALSE;
3408 switch (GST_QUERY_TYPE (query)) {
3409 case GST_QUERY_SCHEDULING:
3410 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3412 case GST_QUERY_ALLOCATION:
3413 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3415 case GST_QUERY_ACCEPT_CAPS:
3416 ret = gst_pad_query_accept_caps_default (pad, query);
3419 case GST_QUERY_CAPS:
3420 ret = gst_pad_query_caps_default (pad, query);
3423 case GST_QUERY_LATENCY:
3424 ret = gst_pad_query_latency_default (pad, query);
3427 case GST_QUERY_POSITION:
3428 case GST_QUERY_SEEKING:
3429 case GST_QUERY_FORMATS:
3430 case GST_QUERY_JITTER:
3431 case GST_QUERY_RATE:
3432 case GST_QUERY_CONVERT:
3438 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3439 query, GST_QUERY_TYPE_NAME (query));
3445 data.dispatched = FALSE;
3446 data.result = FALSE;
3448 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3450 if (data.dispatched) {
3453 /* nothing dispatched, assume drained */
3454 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3464 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3466 GstPad *pad = data->pad;
3467 GstPadProbeInfo *info = data->info;
3468 GstPadProbeType type, flags;
3469 GstPadProbeCallback callback;
3470 GstPadProbeReturn ret;
3471 gpointer original_data;
3473 /* if we have called this callback, do nothing */
3474 if (PROBE_COOKIE (hook) == data->cookie) {
3475 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3476 "hook %lu, cookie %u already called", hook->hook_id,
3477 PROBE_COOKIE (hook));
3481 PROBE_COOKIE (hook) = data->cookie;
3483 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3485 original_data = info->data;
3487 /* one of the scheduling types */
3488 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3491 if (G_UNLIKELY (data->handled)) {
3492 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3493 "probe previously returned HANDLED, not calling again");
3495 } else if (G_UNLIKELY (data->dropped)) {
3496 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3497 "probe previously returned DROPPED, not calling again");
3501 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3502 /* one of the data types for non-idle probes */
3503 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3504 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3506 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3507 /* one of the data types for non-idle probes */
3508 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3509 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3512 /* Type must have PULL or PUSH probe types */
3513 g_assert_not_reached ();
3516 /* one of the blocking types must match */
3517 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3518 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3520 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3521 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3523 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3524 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3525 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3528 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3529 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3530 PROBE_COOKIE (hook), flags);
3532 data->marshalled = TRUE;
3534 callback = (GstPadProbeCallback) hook->func;
3535 if (callback == NULL)
3538 info->id = hook->hook_id;
3540 GST_OBJECT_UNLOCK (pad);
3542 ret = callback (pad, info, hook->data);
3544 GST_OBJECT_LOCK (pad);
3546 if (original_data != NULL && info->data == NULL) {
3547 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3548 info->type = GST_PAD_PROBE_TYPE_INVALID;
3549 data->dropped = TRUE;
3553 case GST_PAD_PROBE_REMOVE:
3554 /* remove the probe */
3555 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3556 cleanup_hook (pad, hook);
3558 case GST_PAD_PROBE_DROP:
3559 /* need to drop the data, make sure other probes don't get called
3561 GST_DEBUG_OBJECT (pad, "asked to drop item");
3562 info->type = GST_PAD_PROBE_TYPE_INVALID;
3563 data->dropped = TRUE;
3565 case GST_PAD_PROBE_HANDLED:
3566 GST_DEBUG_OBJECT (pad, "probe handled data");
3567 data->handled = TRUE;
3569 case GST_PAD_PROBE_PASS:
3570 /* inform the pad block to let things pass */
3571 GST_DEBUG_OBJECT (pad, "asked to pass item");
3574 case GST_PAD_PROBE_OK:
3575 GST_DEBUG_OBJECT (pad, "probe returned OK");
3578 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3585 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3586 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3587 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3592 /* a probe that does not take or return any data */
3593 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3595 if (G_UNLIKELY (pad->num_probes)) { \
3596 GstFlowReturn pval = defaultval; \
3597 /* pass NULL as the data item */ \
3598 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3599 info.ABI.abi.flow_ret = defaultval; \
3600 ret = do_probe_callbacks (pad, &info, defaultval); \
3601 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3606 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3608 if (G_UNLIKELY (pad->num_probes)) { \
3609 /* pass the data item */ \
3610 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3611 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3612 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3613 /* store the possibly updated data item */ \
3614 data = GST_PAD_PROBE_INFO_DATA (&info); \
3615 /* if something went wrong, exit */ \
3616 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3617 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3618 ret = info.ABI.abi.flow_ret; \
3619 goto handle_label; \
3626 #define PROBE_PUSH(pad,mask,data,label) \
3627 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3628 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3629 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3630 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3631 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3633 static GstFlowReturn
3634 do_pad_idle_probe_wait (GstPad * pad)
3636 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3637 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3638 "waiting idle probe to be removed");
3639 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3640 GST_PAD_BLOCK_WAIT (pad);
3641 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3642 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3644 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3645 return GST_FLOW_FLUSHING;
3650 #define PROBE_TYPE_IS_SERIALIZED(i) \
3653 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3654 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3655 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3657 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3658 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3660 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3661 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3665 static GstFlowReturn
3666 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3667 GstFlowReturn defaultval)
3676 data.handled = FALSE;
3677 data.marshalled = FALSE;
3678 data.dropped = FALSE;
3679 data.cookie = ++pad->priv->probe_cookie;
3682 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3684 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3685 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3690 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3691 "do probes cookie %u", data.cookie);
3692 cookie = pad->priv->probe_list_cookie;
3694 g_hook_list_marshal (&pad->probes, TRUE,
3695 (GHookMarshaller) probe_hook_marshal, &data);
3697 /* if the list changed, call the new callbacks (they will not have their
3698 * cookie set to data.cookie */
3699 if (cookie != pad->priv->probe_list_cookie) {
3700 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3701 "probe list changed, restarting");
3705 /* the first item that dropped will stop the hooks and then we drop here */
3709 /* If one handler took care of it, let the the item pass */
3714 /* if no handler matched and we are blocking, let the item pass */
3715 if (!data.marshalled && is_block)
3718 /* At this point, all handlers returned either OK or PASS. If one handler
3719 * returned PASS, let the item pass */
3724 while (GST_PAD_IS_BLOCKED (pad)) {
3725 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3726 "we are blocked %d times", pad->num_blocked);
3728 /* we might have released the lock */
3729 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3732 /* now we block the streaming thread. It can be unlocked when we
3733 * deactivate the pad (which will also set the FLUSHING flag) or
3734 * when the pad is unblocked. A flushing event will also unblock
3735 * the pad after setting the FLUSHING flag. */
3736 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3737 "Waiting to be unblocked or set flushing");
3738 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3739 GST_PAD_BLOCK_WAIT (pad);
3740 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3741 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3743 /* if the list changed, call the new callbacks (they will not have their
3744 * cookie set to data.cookie */
3745 if (cookie != pad->priv->probe_list_cookie) {
3746 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3747 "probe list changed, restarting");
3751 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3761 GST_DEBUG_OBJECT (pad, "pad is flushing");
3762 return GST_FLOW_FLUSHING;
3766 GST_DEBUG_OBJECT (pad, "data is dropped");
3767 return GST_FLOW_CUSTOM_SUCCESS;
3771 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3772 GST_DEBUG_OBJECT (pad, "data is passed");
3777 GST_DEBUG_OBJECT (pad, "data was handled");
3778 return GST_FLOW_CUSTOM_SUCCESS_1;
3785 * gst_pad_get_offset:
3788 * Get the offset applied to the running time of @pad. @pad has to be a source
3791 * Returns: the offset.
3794 gst_pad_get_offset (GstPad * pad)
3798 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3800 GST_OBJECT_LOCK (pad);
3801 result = pad->offset;
3802 GST_OBJECT_UNLOCK (pad);
3807 /* This function will make sure that previously set offset is
3808 * reverted as otherwise we would end up applying the new offset
3809 * on top of the previously set one, which is not what we want.
3810 * The event is also marked as not received. */
3812 reschedule_event (GstPad * pad, PadEvent * ev, gint64 * prev_offset)
3814 if (*prev_offset != 0)
3815 ev->event = _apply_pad_offset (pad, ev->event, -*prev_offset, FALSE);
3817 ev->received = FALSE;
3822 * gst_pad_set_offset:
3824 * @offset: the offset
3826 * Set the offset that will be applied to the running time of @pad.
3829 gst_pad_set_offset (GstPad * pad, gint64 offset)
3832 g_return_if_fail (GST_IS_PAD (pad));
3834 GST_OBJECT_LOCK (pad);
3835 /* if nothing changed, do nothing */
3836 if (pad->offset == offset)
3839 prev_offset = pad->offset;
3840 pad->offset = offset;
3841 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3842 GST_STIME_ARGS (offset));
3844 /* resend all sticky events with updated offset on next buffer push */
3845 events_foreach (pad, (PadEventFunction) reschedule_event, &prev_offset);
3846 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3850 GST_OBJECT_UNLOCK (pad);
3857 /* If TRUE and ret is not OK this means
3858 * that pushing the EOS event failed
3862 /* If called for an event this is
3863 * the event that would be pushed
3864 * next. Don't forward sticky events
3865 * that would come after that */
3869 /* should be called with pad LOCK */
3871 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3873 PushStickyData *data = user_data;
3874 GstEvent *event = ev->event;
3877 GST_DEBUG_OBJECT (pad, "event %s was already received",
3878 GST_EVENT_TYPE_NAME (event));
3882 /* If we're called because of an sticky event, only forward
3883 * events that would come before this new event and the
3885 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3886 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3887 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3888 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3890 gst_event_ref (event);
3891 data->ret = gst_pad_push_event_unchecked (pad, &event,
3892 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3893 gst_event_replace (&ev->event, event);
3894 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3895 data->ret = GST_FLOW_OK;
3898 switch (data->ret) {
3900 ev->received = TRUE;
3901 GST_DEBUG_OBJECT (pad, "event %s marked received",
3902 GST_EVENT_TYPE_NAME (event));
3904 case GST_FLOW_CUSTOM_SUCCESS:
3905 /* we can't assume the event is received when it was dropped */
3906 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3907 GST_EVENT_TYPE_NAME (event));
3908 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3909 data->ret = GST_FLOW_OK;
3911 case GST_FLOW_CUSTOM_SUCCESS_1:
3912 /* event was ignored and should be sent later */
3913 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3914 GST_EVENT_TYPE_NAME (event));
3915 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3916 data->ret = GST_FLOW_OK;
3918 case GST_FLOW_NOT_LINKED:
3919 /* not linked is not a problem, we are sticky so the event will be
3920 * rescheduled to be sent later on re-link, but only for non-EOS events */
3921 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3922 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3923 data->ret = GST_FLOW_OK;
3924 ev->received = TRUE;
3928 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3929 gst_flow_get_name (data->ret));
3930 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3934 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3935 data->was_eos = TRUE;
3937 return data->ret == GST_FLOW_OK;
3940 /* check sticky events and push them when needed. should be called
3942 static inline GstFlowReturn
3943 check_sticky (GstPad * pad, GstEvent * event)
3945 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3947 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3948 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3950 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3951 events_foreach (pad, push_sticky, &data);
3953 /* If there's an EOS event we must push it downstream
3954 * even if sending a previous sticky event failed.
3955 * Otherwise the pipeline might wait forever for EOS.
3957 * Only do this if pushing another event than the EOS
3960 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3961 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3963 if (ev && !ev->received) {
3964 gst_event_ref (ev->event);
3965 data.ret = gst_pad_push_event_unchecked (pad, &ev->event,
3966 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3967 /* the event could have been dropped. Because this can only
3968 * happen if the user asked for it, it's not an error */
3969 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3970 data.ret = GST_FLOW_OK;
3980 * @pad: a #GstPad to invoke the default query on.
3981 * @query: (transfer none): the #GstQuery to perform.
3983 * Dispatches a query to a pad. The query should have been allocated by the
3984 * caller via one of the type-specific allocation functions. The element that
3985 * the pad belongs to is responsible for filling the query with an appropriate
3986 * response, which should then be parsed with a type-specific query parsing
3989 * Again, the caller is responsible for both the allocation and deallocation of
3990 * the query structure.
3992 * Please also note that some queries might need a running pipeline to work.
3994 * Returns: %TRUE if the query could be performed.
3997 gst_pad_query (GstPad * pad, GstQuery * query)
4000 gboolean res, serialized;
4001 GstPadQueryFunction func;
4002 GstPadProbeType type;
4005 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4006 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4008 if (GST_PAD_IS_SRC (pad)) {
4009 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4010 goto wrong_direction;
4011 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4012 } else if (GST_PAD_IS_SINK (pad)) {
4013 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4014 goto wrong_direction;
4015 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4017 goto unknown_direction;
4019 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4020 GST_QUERY_TYPE_NAME (query));
4021 GST_TRACER_PAD_QUERY_PRE (pad, query);
4023 serialized = GST_QUERY_IS_SERIALIZED (query);
4024 if (G_UNLIKELY (serialized))
4025 GST_PAD_STREAM_LOCK (pad);
4027 GST_OBJECT_LOCK (pad);
4028 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4029 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4030 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4032 ACQUIRE_PARENT (pad, parent, no_parent);
4033 GST_OBJECT_UNLOCK (pad);
4035 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4038 res = func (pad, parent, query);
4040 RELEASE_PARENT (parent);
4042 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4043 GST_QUERY_TYPE_NAME (query), res);
4044 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4049 GST_OBJECT_LOCK (pad);
4050 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4051 GST_OBJECT_UNLOCK (pad);
4053 if (G_UNLIKELY (serialized))
4054 GST_PAD_STREAM_UNLOCK (pad);
4061 g_warning ("pad %s:%s query %s in wrong direction",
4062 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4067 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4072 GST_DEBUG_OBJECT (pad, "had no parent");
4073 GST_OBJECT_UNLOCK (pad);
4074 if (G_UNLIKELY (serialized))
4075 GST_PAD_STREAM_UNLOCK (pad);
4080 GST_DEBUG_OBJECT (pad, "had no query function");
4081 RELEASE_PARENT (parent);
4082 if (G_UNLIKELY (serialized))
4083 GST_PAD_STREAM_UNLOCK (pad);
4088 GST_DEBUG_OBJECT (pad, "query failed");
4089 if (G_UNLIKELY (serialized))
4090 GST_PAD_STREAM_UNLOCK (pad);
4095 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4096 GST_OBJECT_UNLOCK (pad);
4097 if (G_UNLIKELY (serialized))
4098 GST_PAD_STREAM_UNLOCK (pad);
4100 /* if a probe dropped without handling, we don't sent it further but assume
4101 * that the probe did not answer the query and return FALSE */
4102 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4112 * gst_pad_peer_query:
4113 * @pad: a #GstPad to invoke the peer query on.
4114 * @query: (transfer none): the #GstQuery to perform.
4116 * Performs gst_pad_query() on the peer of @pad.
4118 * The caller is responsible for both the allocation and deallocation of
4119 * the query structure.
4121 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4122 * if @pad has no peer.
4125 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4128 GstPadProbeType type;
4129 gboolean res, serialized;
4132 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4133 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4135 if (GST_PAD_IS_SRC (pad)) {
4136 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4137 goto wrong_direction;
4138 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4139 } else if (GST_PAD_IS_SINK (pad)) {
4140 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4141 goto wrong_direction;
4142 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4144 goto unknown_direction;
4146 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4147 GST_QUERY_TYPE_NAME (query));
4149 serialized = GST_QUERY_IS_SERIALIZED (query);
4151 GST_OBJECT_LOCK (pad);
4152 if (GST_PAD_IS_SRC (pad) && serialized) {
4153 /* all serialized queries on the srcpad trigger push of
4155 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4159 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4160 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4161 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4163 peerpad = GST_PAD_PEER (pad);
4164 if (G_UNLIKELY (peerpad == NULL))
4167 gst_object_ref (peerpad);
4168 GST_OBJECT_UNLOCK (pad);
4170 res = gst_pad_query (peerpad, query);
4172 gst_object_unref (peerpad);
4177 GST_OBJECT_LOCK (pad);
4178 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4179 GST_OBJECT_UNLOCK (pad);
4186 g_warning ("pad %s:%s query %s in wrong direction",
4187 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4192 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4197 GST_WARNING_OBJECT (pad, "could not send sticky events");
4198 GST_OBJECT_UNLOCK (pad);
4203 GST_INFO_OBJECT (pad, "pad has no peer");
4204 GST_OBJECT_UNLOCK (pad);
4209 GST_DEBUG_OBJECT (pad, "query failed");
4214 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4215 GST_OBJECT_UNLOCK (pad);
4217 /* if a probe dropped without handling, we don't sent it further but
4218 * assume that the probe did not answer the query and return FALSE */
4219 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4228 /**********************************************************************
4229 * Data passing functions
4232 /* this is the chain function that does not perform the additional argument
4233 * checking for that little extra speed.
4235 static inline GstFlowReturn
4236 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4240 gboolean handled = FALSE;
4242 GST_PAD_STREAM_LOCK (pad);
4244 GST_OBJECT_LOCK (pad);
4245 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4248 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4251 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4254 #ifdef GST_ENABLE_EXTRA_CHECKS
4255 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4256 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4258 ":%s:<%s:%s> Got data flow before stream-start event",
4259 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4261 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4263 ":%s:<%s:%s> Got data flow before segment event",
4264 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4266 pad->priv->last_cookie = pad->priv->events_cookie;
4270 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4273 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4275 ACQUIRE_PARENT (pad, parent, no_parent);
4276 GST_OBJECT_UNLOCK (pad);
4278 /* NOTE: we read the chainfunc unlocked.
4279 * we cannot hold the lock for the pad so we might send
4280 * the data to the wrong function. This is not really a
4281 * problem since functions are assigned at creation time
4282 * and don't change that often... */
4283 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4284 GstPadChainFunction chainfunc;
4286 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4289 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4290 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4291 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4293 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4295 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4296 "called chainfunction &%s with buffer %p, returned %s",
4297 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4299 GstPadChainListFunction chainlistfunc;
4301 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4304 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4305 "calling chainlistfunction &%s",
4306 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4308 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4310 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4311 "called chainlistfunction &%s, returned %s",
4312 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4315 RELEASE_PARENT (parent);
4317 GST_PAD_STREAM_UNLOCK (pad);
4324 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4325 "chaining, but pad was flushing");
4326 GST_OBJECT_UNLOCK (pad);
4327 GST_PAD_STREAM_UNLOCK (pad);
4328 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4329 return GST_FLOW_FLUSHING;
4333 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4334 GST_OBJECT_UNLOCK (pad);
4335 GST_PAD_STREAM_UNLOCK (pad);
4336 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4337 return GST_FLOW_EOS;
4341 g_critical ("chain on pad %s:%s but it was not in push mode",
4342 GST_DEBUG_PAD_NAME (pad));
4343 GST_OBJECT_UNLOCK (pad);
4344 GST_PAD_STREAM_UNLOCK (pad);
4345 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4346 return GST_FLOW_ERROR;
4353 GST_OBJECT_UNLOCK (pad);
4354 GST_PAD_STREAM_UNLOCK (pad);
4355 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4357 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4360 case GST_FLOW_CUSTOM_SUCCESS:
4361 case GST_FLOW_CUSTOM_SUCCESS_1:
4362 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4366 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4373 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4374 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4375 GST_OBJECT_UNLOCK (pad);
4376 GST_PAD_STREAM_UNLOCK (pad);
4377 return GST_FLOW_FLUSHING;
4381 RELEASE_PARENT (parent);
4382 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4383 g_critical ("chain on pad %s:%s but it has no chainfunction",
4384 GST_DEBUG_PAD_NAME (pad));
4385 GST_PAD_STREAM_UNLOCK (pad);
4386 return GST_FLOW_NOT_SUPPORTED;
4392 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4393 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4396 * Chain a buffer to @pad.
4398 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4400 * If the buffer type is not acceptable for @pad (as negotiated with a
4401 * preceding GST_EVENT_CAPS event), this function returns
4402 * #GST_FLOW_NOT_NEGOTIATED.
4404 * The function proceeds calling the chain function installed on @pad (see
4405 * gst_pad_set_chain_function()) and the return value of that function is
4406 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4409 * In all cases, success or failure, the caller loses its reference to @buffer
4410 * after calling this function.
4412 * Returns: a #GstFlowReturn from the pad.
4417 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4419 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4420 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4421 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4423 return gst_pad_chain_data_unchecked (pad,
4424 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4427 static GstFlowReturn
4428 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4429 GstBufferList * list)
4435 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4437 len = gst_buffer_list_length (list);
4440 for (i = 0; i < len; i++) {
4441 buffer = gst_buffer_list_get (list, i);
4443 gst_pad_chain_data_unchecked (pad,
4444 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4445 gst_buffer_ref (buffer));
4446 if (ret != GST_FLOW_OK)
4449 gst_buffer_list_unref (list);
4455 * gst_pad_chain_list:
4456 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4457 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4460 * Chain a bufferlist to @pad.
4462 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4464 * If @pad was not negotiated properly with a CAPS event, this function
4465 * returns #GST_FLOW_NOT_NEGOTIATED.
4467 * The function proceeds calling the chainlist function installed on @pad (see
4468 * gst_pad_set_chain_list_function()) and the return value of that function is
4469 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4470 * chainlist function.
4472 * In all cases, success or failure, the caller loses its reference to @list
4473 * after calling this function.
4477 * Returns: a #GstFlowReturn from the pad.
4480 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4482 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4483 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4484 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4486 return gst_pad_chain_data_unchecked (pad,
4487 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4490 static GstFlowReturn
4491 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4495 gboolean handled = FALSE;
4497 GST_OBJECT_LOCK (pad);
4498 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4501 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4504 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4507 #ifdef GST_ENABLE_EXTRA_CHECKS
4508 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4509 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4511 ":%s:<%s:%s> Got data flow before stream-start event",
4512 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4514 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4516 ":%s:<%s:%s> Got data flow before segment event",
4517 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4519 pad->priv->last_cookie = pad->priv->events_cookie;
4523 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4526 /* do block probes */
4527 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4530 /* recheck sticky events because the probe might have cause a relink */
4531 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4534 /* do post-blocking probes */
4535 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4537 /* recheck sticky events because the probe might have cause a relink */
4538 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4541 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4544 /* take ref to peer pad before releasing the lock */
4545 gst_object_ref (peer);
4547 GST_OBJECT_UNLOCK (pad);
4549 ret = gst_pad_chain_data_unchecked (peer, type, data);
4552 gst_object_unref (peer);
4554 GST_OBJECT_LOCK (pad);
4555 pad->ABI.abi.last_flowret = ret;
4557 if (pad->priv->using == 0) {
4558 /* pad is not active anymore, trigger idle callbacks */
4559 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4560 probe_stopped, ret);
4562 GST_OBJECT_UNLOCK (pad);
4566 /* ERROR recovery here */
4570 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4571 "pushing, but pad was flushing");
4572 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4573 GST_OBJECT_UNLOCK (pad);
4574 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4575 return GST_FLOW_FLUSHING;
4579 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4580 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4581 GST_OBJECT_UNLOCK (pad);
4582 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4583 return GST_FLOW_EOS;
4587 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4588 GST_DEBUG_PAD_NAME (pad));
4589 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4590 GST_OBJECT_UNLOCK (pad);
4591 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4592 return GST_FLOW_ERROR;
4596 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4597 "error pushing events, return %s", gst_flow_get_name (ret));
4598 pad->ABI.abi.last_flowret = ret;
4599 GST_OBJECT_UNLOCK (pad);
4600 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4608 GST_OBJECT_UNLOCK (pad);
4609 if (data != NULL && !handled)
4610 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4613 case GST_FLOW_CUSTOM_SUCCESS:
4614 case GST_FLOW_CUSTOM_SUCCESS_1:
4615 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4619 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4622 pad->ABI.abi.last_flowret = ret;
4627 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4628 "pushing, but it was not linked");
4629 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4630 GST_OBJECT_UNLOCK (pad);
4631 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4632 return GST_FLOW_NOT_LINKED;
4638 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4639 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4642 * Pushes a buffer to the peer of @pad.
4644 * This function will call installed block probes before triggering any
4645 * installed data probes.
4647 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4648 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4651 * In all cases, success or failure, the caller loses its reference to @buffer
4652 * after calling this function.
4654 * Returns: a #GstFlowReturn from the peer pad.
4659 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4663 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4664 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4665 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4667 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4668 res = gst_pad_push_data (pad,
4669 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4670 GST_TRACER_PAD_PUSH_POST (pad, res);
4675 * gst_pad_push_list:
4676 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4677 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4680 * Pushes a buffer list to the peer of @pad.
4682 * This function will call installed block probes before triggering any
4683 * installed data probes.
4685 * The function proceeds calling the chain function on the peer pad and returns
4686 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4687 * be returned. If the peer pad does not have any installed chainlist function
4688 * every group buffer of the list will be merged into a normal #GstBuffer and
4689 * chained via gst_pad_chain().
4691 * In all cases, success or failure, the caller loses its reference to @list
4692 * after calling this function.
4694 * Returns: a #GstFlowReturn from the peer pad.
4699 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4703 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4704 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4705 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4707 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4708 res = gst_pad_push_data (pad,
4709 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4710 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4714 static GstFlowReturn
4715 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4716 GstBuffer ** buffer)
4719 GstPadGetRangeFunction getrangefunc;
4723 GST_PAD_STREAM_LOCK (pad);
4725 GST_OBJECT_LOCK (pad);
4726 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4729 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4732 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4737 /* when one of the probes returns DROPPED, probe_stopped will be called
4738 * and we skip calling the getrange function, res_buf should then contain a
4739 * valid result buffer */
4740 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4741 res_buf, offset, size, probe_stopped);
4743 /* recheck sticky events because the probe might have cause a relink */
4744 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4747 ACQUIRE_PARENT (pad, parent, no_parent);
4748 GST_OBJECT_UNLOCK (pad);
4750 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4753 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4754 "calling getrangefunc %s, offset %"
4755 G_GUINT64_FORMAT ", size %u",
4756 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4758 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4760 RELEASE_PARENT (parent);
4762 GST_OBJECT_LOCK (pad);
4763 if (G_UNLIKELY (ret != GST_FLOW_OK))
4764 goto get_range_failed;
4766 /* can only fire the signal if we have a valid buffer */
4768 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4769 res_buf, offset, size, probe_stopped_unref);
4770 pad->ABI.abi.last_flowret = ret;
4771 GST_OBJECT_UNLOCK (pad);
4773 GST_PAD_STREAM_UNLOCK (pad);
4782 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4783 "getrange, but pad was flushing");
4784 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4785 GST_OBJECT_UNLOCK (pad);
4786 GST_PAD_STREAM_UNLOCK (pad);
4787 return GST_FLOW_FLUSHING;
4791 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4792 GST_DEBUG_PAD_NAME (pad));
4793 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4794 GST_OBJECT_UNLOCK (pad);
4795 GST_PAD_STREAM_UNLOCK (pad);
4796 return GST_FLOW_ERROR;
4800 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4801 pad->ABI.abi.last_flowret = ret;
4802 GST_OBJECT_UNLOCK (pad);
4803 GST_PAD_STREAM_UNLOCK (pad);
4808 GST_DEBUG_OBJECT (pad, "no parent");
4809 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4810 GST_OBJECT_UNLOCK (pad);
4811 GST_PAD_STREAM_UNLOCK (pad);
4812 return GST_FLOW_FLUSHING;
4816 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4817 GST_DEBUG_PAD_NAME (pad));
4818 RELEASE_PARENT (parent);
4819 GST_PAD_STREAM_UNLOCK (pad);
4820 return GST_FLOW_NOT_SUPPORTED;
4824 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4825 "probe returned %s", gst_flow_get_name (ret));
4826 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4828 /* the probe filled the buffer and asks us to not call the getrange
4829 * anymore, we continue with the post probes then. */
4830 GST_DEBUG_OBJECT (pad, "handled buffer");
4834 /* no buffer, we are EOS */
4835 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4839 pad->ABI.abi.last_flowret = ret;
4840 GST_OBJECT_UNLOCK (pad);
4841 GST_PAD_STREAM_UNLOCK (pad);
4845 probe_stopped_unref:
4847 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4848 "probe returned %s", gst_flow_get_name (ret));
4849 /* if we drop here, it signals EOS */
4850 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4852 pad->ABI.abi.last_flowret = ret;
4853 GST_OBJECT_UNLOCK (pad);
4854 GST_PAD_STREAM_UNLOCK (pad);
4855 if (*buffer == NULL)
4856 gst_buffer_unref (res_buf);
4861 pad->ABI.abi.last_flowret = ret;
4862 GST_OBJECT_UNLOCK (pad);
4863 GST_PAD_STREAM_UNLOCK (pad);
4864 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4865 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4866 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4872 * gst_pad_get_range:
4873 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4874 * @offset: The start offset of the buffer
4875 * @size: The length of the buffer
4876 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4877 * returns #GST_FLOW_ERROR if %NULL.
4879 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4880 * immediately and @buffer is %NULL.
4882 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4883 * description of a getrange function. If @pad has no getrange function
4884 * installed (see gst_pad_set_getrange_function()) this function returns
4885 * #GST_FLOW_NOT_SUPPORTED.
4887 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4888 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4889 * must be freed with gst_buffer_unref() after usage.
4891 * When @buffer points to a variable that points to a valid #GstBuffer, the
4892 * buffer will be filled with the result data when this function returns
4893 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4894 * @size bytes will be filled in the result buffer and its size will be updated
4897 * Note that less than @size bytes can be returned in @buffer when, for example,
4898 * an EOS condition is near or when @buffer is not large enough to hold @size
4899 * bytes. The caller should check the result buffer size to get the result size.
4901 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4902 * will be unchanged.
4904 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4906 * Returns: a #GstFlowReturn from the pad.
4911 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4912 GstBuffer ** buffer)
4914 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4915 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4916 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4917 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4918 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4920 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4924 * gst_pad_pull_range:
4925 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4926 * @offset: The start offset of the buffer
4927 * @size: The length of the buffer
4928 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4929 * GST_FLOW_ERROR if %NULL.
4931 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4933 * This function will first trigger the pad block signal if it was
4936 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4937 * function returns the result of gst_pad_get_range() on the peer pad.
4938 * See gst_pad_get_range() for a list of return values and for the
4939 * semantics of the arguments of this function.
4941 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4942 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4943 * must be freed with gst_buffer_unref() after usage. When this function
4944 * returns any other result value, @buffer will still point to %NULL.
4946 * When @buffer points to a variable that points to a valid #GstBuffer, the
4947 * buffer will be filled with the result data when this function returns
4948 * #GST_FLOW_OK. When this function returns any other result value,
4949 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4950 * @size bytes will be filled in the result buffer and its size will be updated
4953 * Note that less than @size bytes can be returned in @buffer when, for example,
4954 * an EOS condition is near or when @buffer is not large enough to hold @size
4955 * bytes. The caller should check the result buffer size to get the result size.
4957 * Returns: a #GstFlowReturn from the peer pad.
4962 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4963 GstBuffer ** buffer)
4969 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4970 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4971 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4972 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4973 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4975 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4977 GST_OBJECT_LOCK (pad);
4978 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4981 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4986 /* when one of the probes returns DROPPED, probe_stopped will be
4987 * called and we skip calling the peer getrange function. *buffer should then
4988 * contain a valid buffer */
4989 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4990 res_buf, offset, size, probe_stopped);
4992 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4995 gst_object_ref (peer);
4997 GST_OBJECT_UNLOCK (pad);
4999 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5001 gst_object_unref (peer);
5003 GST_OBJECT_LOCK (pad);
5005 pad->ABI.abi.last_flowret = ret;
5006 if (pad->priv->using == 0) {
5007 /* pad is not active anymore, trigger idle callbacks */
5008 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5009 probe_stopped_unref, ret);
5012 if (G_UNLIKELY (ret != GST_FLOW_OK))
5013 goto pull_range_failed;
5016 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5017 res_buf, offset, size, probe_stopped_unref);
5019 GST_OBJECT_UNLOCK (pad);
5023 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5026 /* ERROR recovery here */
5029 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5030 "pullrange, but pad was flushing");
5031 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5032 GST_OBJECT_UNLOCK (pad);
5033 ret = GST_FLOW_FLUSHING;
5038 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5039 GST_DEBUG_PAD_NAME (pad));
5040 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5041 GST_OBJECT_UNLOCK (pad);
5042 ret = GST_FLOW_ERROR;
5047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5048 gst_flow_get_name (ret));
5049 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5051 /* the probe filled the buffer and asks us to not forward to the peer
5052 * anymore, we continue with the post probes then */
5053 GST_DEBUG_OBJECT (pad, "handled buffer");
5057 /* no buffer, we are EOS then */
5058 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5062 pad->ABI.abi.last_flowret = ret;
5063 GST_OBJECT_UNLOCK (pad);
5068 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5069 "pulling range, but it was not linked");
5070 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5071 GST_OBJECT_UNLOCK (pad);
5072 ret = GST_FLOW_NOT_LINKED;
5077 pad->ABI.abi.last_flowret = ret;
5078 GST_OBJECT_UNLOCK (pad);
5079 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5080 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5081 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5084 probe_stopped_unref:
5086 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5087 "post probe returned %s", gst_flow_get_name (ret));
5089 /* if we drop here, it signals EOS */
5090 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5093 pad->ABI.abi.last_flowret = ret;
5094 GST_OBJECT_UNLOCK (pad);
5096 if (*buffer == NULL)
5097 gst_buffer_unref (res_buf);
5101 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5105 /* must be called with pad object lock */
5106 static GstFlowReturn
5107 store_sticky_event (GstPad * pad, GstEvent * event)
5112 gboolean res = FALSE;
5113 const gchar *name = NULL;
5114 gboolean insert = TRUE;
5116 type = GST_EVENT_TYPE (event);
5118 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5119 * otherwise they can be dropped and nothing would ever resend them.
5120 * Only do that for activated pads though, everything else is a bug!
5122 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5123 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5124 || type == GST_EVENT_EOS))))
5127 /* Unset the EOS flag when received STREAM_START event, so pad can
5128 * store sticky event and then push it later */
5129 if (type == GST_EVENT_STREAM_START) {
5130 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5131 remove_event_by_type (pad, GST_EVENT_EOS);
5132 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5133 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5136 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5139 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5140 name = gst_structure_get_name (gst_event_get_structure (event));
5142 events = pad->priv->events;
5145 for (i = 0; i < len; i++) {
5146 PadEvent *ev = &g_array_index (events, PadEvent, i);
5148 if (ev->event == NULL)
5151 if (type == GST_EVENT_TYPE (ev->event)) {
5152 /* matching types, check matching name if needed */
5153 if (name && !gst_event_has_name (ev->event, name))
5157 if ((res = gst_event_replace (&ev->event, event)))
5158 ev->received = FALSE;
5164 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5165 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5166 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5167 * storing the sticky ordered we can check that this is respected. */
5168 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5169 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5171 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5172 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5173 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5174 gst_event_type_get_name (type));
5180 ev.event = gst_event_ref (event);
5181 ev.received = FALSE;
5182 g_array_insert_val (events, i, ev);
5187 pad->priv->events_cookie++;
5188 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5190 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5192 switch (GST_EVENT_TYPE (event)) {
5193 case GST_EVENT_CAPS:
5194 GST_OBJECT_UNLOCK (pad);
5196 GST_DEBUG_OBJECT (pad, "notify caps");
5197 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5199 GST_OBJECT_LOCK (pad);
5205 if (type == GST_EVENT_EOS) {
5206 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5207 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5210 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5215 GST_DEBUG_OBJECT (pad, "pad is flushing");
5216 return GST_FLOW_FLUSHING;
5220 GST_DEBUG_OBJECT (pad, "pad is EOS");
5221 return GST_FLOW_EOS;
5226 * gst_pad_store_sticky_event:
5228 * @event: (transfer none): a #GstEvent
5230 * Store the sticky @event on @pad
5232 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5233 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5238 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5242 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5243 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5245 GST_OBJECT_LOCK (pad);
5246 ret = store_sticky_event (pad, event);
5247 GST_OBJECT_UNLOCK (pad);
5253 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5255 PushStickyData *data = user_data;
5257 /* Forward all sticky events before our current one that are pending */
5258 if (ev->event != data->event
5259 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5260 return push_sticky (pad, ev, data);
5265 /* should be called with pad LOCK */
5266 static GstFlowReturn
5267 gst_pad_push_event_unchecked (GstPad * pad, GstEvent ** in_event,
5268 GstPadProbeType type)
5272 GstEventType event_type;
5273 GstEvent *event = *in_event;
5275 /* pass the adjusted event on. We need to do this even if
5276 * there is no peer pad because of the probes. */
5277 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5279 /* Two checks to be made:
5280 * . (un)set the FLUSHING flag for flushing events,
5281 * . handle pad blocking */
5282 event_type = GST_EVENT_TYPE (event);
5283 switch (event_type) {
5284 case GST_EVENT_FLUSH_START:
5285 GST_PAD_SET_FLUSHING (pad);
5287 GST_PAD_BLOCK_BROADCAST (pad);
5288 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5290 case GST_EVENT_FLUSH_STOP:
5291 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5294 GST_PAD_UNSET_FLUSHING (pad);
5296 /* Remove sticky EOS events */
5297 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5298 remove_event_by_type (pad, GST_EVENT_EOS);
5299 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5300 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5301 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5302 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5304 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5308 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5311 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5312 * checked already or this is called as part of pushing sticky events,
5313 * in which case we still want to forward the EOS event downstream.
5316 switch (GST_EVENT_TYPE (event)) {
5317 case GST_EVENT_RECONFIGURE:
5318 if (GST_PAD_IS_SINK (pad))
5319 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5324 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5325 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5326 /* recheck sticky events because the probe might have cause a relink */
5327 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5328 && (GST_EVENT_IS_SERIALIZED (event)
5329 || GST_EVENT_IS_STICKY (event))) {
5330 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5331 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5333 /* Push all sticky events before our current one
5334 * that have changed */
5335 events_foreach (pad, sticky_changed, &data);
5341 /* send probes after modifying the events above */
5342 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5344 /* recheck sticky events because the probe might have cause a relink */
5345 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5346 && (GST_EVENT_IS_SERIALIZED (event)
5347 || GST_EVENT_IS_STICKY (event))) {
5348 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5349 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5351 /* Push all sticky events before our current one
5352 * that have changed */
5353 events_foreach (pad, sticky_changed, &data);
5356 /* now check the peer pad */
5357 peerpad = GST_PAD_PEER (pad);
5358 if (peerpad == NULL)
5361 gst_object_ref (peerpad);
5363 GST_OBJECT_UNLOCK (pad);
5365 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5366 event, gst_event_type_get_name (event_type), peerpad);
5368 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5370 /* Note: we gave away ownership of the event at this point but we can still
5371 * print the old pointer */
5372 GST_LOG_OBJECT (pad,
5373 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5374 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5376 gst_object_unref (peerpad);
5378 GST_OBJECT_LOCK (pad);
5380 if (pad->priv->using == 0) {
5381 /* pad is not active anymore, trigger idle callbacks */
5382 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5383 idle_probe_stopped, ret);
5390 /* ERROR handling */
5393 GST_DEBUG_OBJECT (pad, "We're flushing");
5394 gst_event_unref (event);
5395 return GST_FLOW_FLUSHING;
5399 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5400 gst_event_unref (event);
5401 return GST_FLOW_FLUSHING;
5405 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5406 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5407 gst_event_unref (event);
5410 case GST_FLOW_CUSTOM_SUCCESS_1:
5411 GST_DEBUG_OBJECT (pad, "handled event");
5413 case GST_FLOW_CUSTOM_SUCCESS:
5414 GST_DEBUG_OBJECT (pad, "dropped event");
5417 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5424 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5425 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5426 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5427 gst_event_unref (event);
5429 /* unlinked pads should not influence latency configuration */
5430 if (event_type == GST_EVENT_LATENCY)
5433 return GST_FLOW_NOT_LINKED;
5437 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5443 * gst_pad_push_event:
5444 * @pad: a #GstPad to push the event to.
5445 * @event: (transfer full): the #GstEvent to send to the pad.
5447 * Sends the event to the peer of the given pad. This function is
5448 * mainly used by elements to send events to their peer
5451 * This function takes ownership of the provided event so you should
5452 * gst_event_ref() it if you want to reuse the event after this call.
5454 * Returns: %TRUE if the event was handled.
5459 gst_pad_push_event (GstPad * pad, GstEvent * event)
5461 gboolean res = FALSE;
5462 GstPadProbeType type;
5463 gboolean sticky, serialized;
5465 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5466 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5468 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5470 if (GST_PAD_IS_SRC (pad)) {
5471 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5472 goto wrong_direction;
5473 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5474 } else if (GST_PAD_IS_SINK (pad)) {
5475 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5476 goto wrong_direction;
5477 /* events pushed on sinkpad never are sticky */
5478 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5480 goto unknown_direction;
5482 GST_OBJECT_LOCK (pad);
5483 sticky = GST_EVENT_IS_STICKY (event);
5484 serialized = GST_EVENT_IS_SERIALIZED (event);
5487 /* srcpad sticky events are stored immediately, the received flag is set
5488 * to FALSE and will be set to TRUE when we can successfully push the
5489 * event to the peer pad */
5490 switch (store_sticky_event (pad, event)) {
5491 case GST_FLOW_FLUSHING:
5499 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5500 /* all serialized or sticky events on the srcpad trigger push of
5502 res = (check_sticky (pad, event) == GST_FLOW_OK);
5507 /* other events are pushed right away */
5508 ret = gst_pad_push_event_unchecked (pad, &event, type);
5509 /* dropped events by a probe are not an error */
5510 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5511 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5513 /* Errors in sticky event pushing are no problem and ignored here
5514 * as they will cause more meaningful errors during data flow.
5515 * For EOS events, that are not followed by data flow, we still
5516 * return FALSE here though.
5518 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5520 gst_event_unref (event);
5522 GST_OBJECT_UNLOCK (pad);
5524 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5527 /* ERROR handling */
5530 g_warning ("pad %s:%s pushing %s event in wrong direction",
5531 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5532 gst_event_unref (event);
5537 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5538 gst_event_unref (event);
5543 GST_DEBUG_OBJECT (pad, "We're flushing");
5544 GST_OBJECT_UNLOCK (pad);
5545 gst_event_unref (event);
5550 GST_DEBUG_OBJECT (pad, "We're EOS");
5551 GST_OBJECT_UNLOCK (pad);
5552 gst_event_unref (event);
5556 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5560 /* Check if we can call the event function with the given event */
5561 static GstFlowReturn
5562 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5566 switch (GST_EVENT_TYPE (event)) {
5567 case GST_EVENT_CAPS:
5569 /* backwards compatibility mode for caps */
5570 gst_event_parse_caps (event, &caps);
5572 if (!gst_pad_query_accept_caps (pad, caps))
5584 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5585 "caps %" GST_PTR_FORMAT " not accepted", caps);
5586 return GST_FLOW_NOT_NEGOTIATED;
5590 static GstFlowReturn
5591 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5592 GstPadProbeType type)
5595 GstEventType event_type;
5596 gboolean serialized, need_unlock = FALSE, sticky;
5597 GstPadEventFunction eventfunc;
5598 GstPadEventFullFunction eventfullfunc = NULL;
5601 GST_OBJECT_LOCK (pad);
5603 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5605 if (GST_PAD_IS_SINK (pad))
5606 serialized = GST_EVENT_IS_SERIALIZED (event);
5609 sticky = GST_EVENT_IS_STICKY (event);
5610 event_type = GST_EVENT_TYPE (event);
5611 switch (event_type) {
5612 case GST_EVENT_FLUSH_START:
5613 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5614 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5616 /* can't even accept a flush begin event when flushing */
5617 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5620 GST_PAD_SET_FLUSHING (pad);
5621 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5622 GST_PAD_BLOCK_BROADCAST (pad);
5623 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5625 case GST_EVENT_FLUSH_STOP:
5626 /* we can't accept flush-stop on inactive pads else the flushing flag
5627 * would be cleared and it would look like the pad can accept data.
5628 * Also, some elements restart a streaming thread in flush-stop which we
5629 * can't allow on inactive pads */
5630 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5633 GST_PAD_UNSET_FLUSHING (pad);
5634 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5635 /* Remove pending EOS events */
5636 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5637 remove_event_by_type (pad, GST_EVENT_EOS);
5638 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5639 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5640 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5641 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5643 GST_OBJECT_UNLOCK (pad);
5644 /* grab stream lock */
5645 GST_PAD_STREAM_LOCK (pad);
5647 GST_OBJECT_LOCK (pad);
5648 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5651 case GST_EVENT_RECONFIGURE:
5652 if (GST_PAD_IS_SRC (pad))
5653 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5655 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5656 "have event type %" GST_PTR_FORMAT, event);
5658 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5661 switch (event_type) {
5662 case GST_EVENT_STREAM_START:
5663 /* Remove sticky EOS events */
5664 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5665 remove_event_by_type (pad, GST_EVENT_EOS);
5666 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5667 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5674 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5677 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5678 GST_OBJECT_UNLOCK (pad);
5679 GST_PAD_STREAM_LOCK (pad);
5681 GST_OBJECT_LOCK (pad);
5682 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5685 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5691 /* now do the probe */
5693 type | GST_PAD_PROBE_TYPE_PUSH |
5694 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5696 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5698 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5699 eventfunc = GST_PAD_EVENTFUNC (pad);
5700 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5703 ACQUIRE_PARENT (pad, parent, no_parent);
5704 GST_OBJECT_UNLOCK (pad);
5706 ret = pre_eventfunc_check (pad, event);
5707 if (G_UNLIKELY (ret != GST_FLOW_OK))
5708 goto precheck_failed;
5711 gst_event_ref (event);
5713 if (eventfullfunc) {
5714 ret = eventfullfunc (pad, parent, event);
5715 } else if (eventfunc (pad, parent, event)) {
5718 /* something went wrong */
5719 switch (event_type) {
5720 case GST_EVENT_CAPS:
5721 ret = GST_FLOW_NOT_NEGOTIATED;
5724 ret = GST_FLOW_ERROR;
5728 RELEASE_PARENT (parent);
5730 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5733 if (ret == GST_FLOW_OK) {
5734 GST_OBJECT_LOCK (pad);
5735 /* after the event function accepted the event, we can store the sticky
5736 * event on the pad */
5737 switch (store_sticky_event (pad, event)) {
5738 case GST_FLOW_FLUSHING:
5745 GST_OBJECT_UNLOCK (pad);
5747 gst_event_unref (event);
5751 GST_PAD_STREAM_UNLOCK (pad);
5755 /* ERROR handling */
5758 GST_OBJECT_UNLOCK (pad);
5760 GST_PAD_STREAM_UNLOCK (pad);
5761 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5762 "Received event on flushing pad. Discarding");
5763 gst_event_unref (event);
5764 return GST_FLOW_FLUSHING;
5768 GST_OBJECT_UNLOCK (pad);
5770 GST_PAD_STREAM_UNLOCK (pad);
5771 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5772 "Received flush-stop on inactive pad. Discarding");
5773 gst_event_unref (event);
5774 return GST_FLOW_FLUSHING;
5778 GST_OBJECT_UNLOCK (pad);
5780 GST_PAD_STREAM_UNLOCK (pad);
5781 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5782 "Received event on EOS pad. Discarding");
5783 gst_event_unref (event);
5784 return GST_FLOW_EOS;
5788 GST_OBJECT_UNLOCK (pad);
5790 GST_PAD_STREAM_UNLOCK (pad);
5791 /* Only unref if unhandled */
5792 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5793 gst_event_unref (event);
5796 case GST_FLOW_CUSTOM_SUCCESS_1:
5797 case GST_FLOW_CUSTOM_SUCCESS:
5798 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5802 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5809 g_warning ("pad %s:%s has no event handler, file a bug.",
5810 GST_DEBUG_PAD_NAME (pad));
5811 GST_OBJECT_UNLOCK (pad);
5813 GST_PAD_STREAM_UNLOCK (pad);
5814 gst_event_unref (event);
5815 return GST_FLOW_NOT_SUPPORTED;
5819 GST_DEBUG_OBJECT (pad, "no parent");
5820 GST_OBJECT_UNLOCK (pad);
5822 GST_PAD_STREAM_UNLOCK (pad);
5823 gst_event_unref (event);
5824 return GST_FLOW_FLUSHING;
5828 GST_DEBUG_OBJECT (pad, "pre event check failed");
5829 RELEASE_PARENT (parent);
5831 GST_PAD_STREAM_UNLOCK (pad);
5832 gst_event_unref (event);
5838 * gst_pad_send_event:
5839 * @pad: a #GstPad to send the event to.
5840 * @event: (transfer full): the #GstEvent to send to the pad.
5842 * Sends the event to the pad. This function can be used
5843 * by applications to send events in the pipeline.
5845 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5846 * sink pad, @event should be a downstream event. For example, you would not
5847 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5848 * Furthermore, some downstream events have to be serialized with data flow,
5849 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5850 * the event needs to be serialized with data flow, this function will take the
5851 * pad's stream lock while calling its event function.
5853 * To find out whether an event type is upstream, downstream, or downstream and
5854 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5855 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5856 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5857 * plugin doesn't need to bother itself with this information; the core handles
5858 * all necessary locks and checks.
5860 * This function takes ownership of the provided event so you should
5861 * gst_event_ref() it if you want to reuse the event after this call.
5863 * Returns: %TRUE if the event was handled.
5866 gst_pad_send_event (GstPad * pad, GstEvent * event)
5869 GstPadProbeType type;
5871 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5872 g_return_val_if_fail (event != NULL, FALSE);
5874 if (GST_PAD_IS_SINK (pad)) {
5875 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5876 goto wrong_direction;
5877 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5878 } else if (GST_PAD_IS_SRC (pad)) {
5879 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5880 goto wrong_direction;
5881 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5883 goto unknown_direction;
5885 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5892 /* ERROR handling */
5895 g_warning ("pad %s:%s sending %s event in wrong direction",
5896 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5897 gst_event_unref (event);
5902 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5903 gst_event_unref (event);
5909 * gst_pad_set_element_private:
5910 * @pad: the #GstPad to set the private data of.
5911 * @priv: The private data to attach to the pad.
5913 * Set the given private data gpointer on the pad.
5914 * This function can only be used by the element that owns the pad.
5915 * No locking is performed in this function.
5918 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5920 pad->element_private = priv;
5924 * gst_pad_get_element_private:
5925 * @pad: the #GstPad to get the private data of.
5927 * Gets the private data of a pad.
5928 * No locking is performed in this function.
5930 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5933 gst_pad_get_element_private (GstPad * pad)
5935 return pad->element_private;
5939 * gst_pad_get_sticky_event:
5940 * @pad: the #GstPad to get the event from.
5941 * @event_type: the #GstEventType that should be retrieved.
5942 * @idx: the index of the event
5944 * Returns a new reference of the sticky event of type @event_type
5947 * Returns: (transfer full) (nullable): a #GstEvent of type
5948 * @event_type or %NULL when no event of @event_type was on
5949 * @pad. Unref after usage.
5952 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5954 GstEvent *event = NULL;
5957 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5958 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5960 GST_OBJECT_LOCK (pad);
5961 ev = find_event_by_type (pad, event_type, idx);
5962 if (ev && (event = ev->event))
5963 gst_event_ref (event);
5964 GST_OBJECT_UNLOCK (pad);
5971 GstPadStickyEventsForeachFunction func;
5976 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5978 ForeachDispatch *data = user_data;
5979 gboolean ret = TRUE;
5982 GST_OBJECT_UNLOCK (pad);
5984 ret = data->func (pad, &ev->event, data->user_data);
5986 GST_OBJECT_LOCK (pad);
5993 * gst_pad_sticky_events_foreach:
5994 * @pad: the #GstPad that should be used for iteration.
5995 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5996 * should be called for every event.
5997 * @user_data: (closure): the optional user data.
5999 * Iterates all sticky events on @pad and calls @foreach_func for every
6000 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6003 gst_pad_sticky_events_foreach (GstPad * pad,
6004 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6006 ForeachDispatch data;
6008 g_return_if_fail (GST_IS_PAD (pad));
6009 g_return_if_fail (foreach_func != NULL);
6011 data.func = foreach_func;
6012 data.user_data = user_data;
6014 GST_OBJECT_LOCK (pad);
6015 events_foreach (pad, foreach_dispatch_function, &data);
6016 GST_OBJECT_UNLOCK (pad);
6020 do_stream_status (GstPad * pad, GstStreamStatusType type,
6021 GThread * thread, GstTask * task)
6025 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6027 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6028 if (GST_IS_ELEMENT (parent)) {
6029 GstMessage *message;
6030 GValue value = { 0 };
6032 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6033 gchar *tname, *ename, *pname;
6035 /* create a good task name */
6036 ename = gst_element_get_name (parent);
6037 pname = gst_pad_get_name (pad);
6038 tname = g_strdup_printf ("%s:%s", ename, pname);
6042 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6046 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6049 g_value_init (&value, GST_TYPE_TASK);
6050 g_value_set_object (&value, task);
6051 gst_message_set_stream_status_object (message, &value);
6052 g_value_unset (&value);
6054 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6055 gst_element_post_message (parent, message);
6057 gst_object_unref (parent);
6062 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6064 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6069 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6071 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6076 * gst_pad_start_task:
6077 * @pad: the #GstPad to start the task of
6078 * @func: the task function to call
6079 * @user_data: user data passed to the task function
6080 * @notify: called when @user_data is no longer referenced
6082 * Starts a task that repeatedly calls @func with @user_data. This function
6083 * is mostly used in pad activation functions to start the dataflow.
6084 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6085 * before @func is called.
6087 * Returns: a %TRUE if the task could be started.
6090 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6091 GDestroyNotify notify)
6096 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6097 g_return_val_if_fail (func != NULL, FALSE);
6099 GST_DEBUG_OBJECT (pad, "start task");
6101 GST_OBJECT_LOCK (pad);
6102 task = GST_PAD_TASK (pad);
6104 task = gst_task_new (func, user_data, notify);
6105 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6106 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6107 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6108 GST_INFO_OBJECT (pad, "created task %p", task);
6109 GST_PAD_TASK (pad) = task;
6110 gst_object_ref (task);
6111 /* release lock to post the message */
6112 GST_OBJECT_UNLOCK (pad);
6114 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6116 gst_object_unref (task);
6118 GST_OBJECT_LOCK (pad);
6119 /* nobody else is supposed to have changed the pad now */
6120 if (GST_PAD_TASK (pad) != task)
6121 goto concurrent_stop;
6123 res = gst_task_set_state (task, GST_TASK_STARTED);
6124 GST_OBJECT_UNLOCK (pad);
6131 GST_OBJECT_UNLOCK (pad);
6137 * gst_pad_pause_task:
6138 * @pad: the #GstPad to pause the task of
6140 * Pause the task of @pad. This function will also wait until the
6141 * function executed by the task is finished if this function is not
6142 * called from the task function.
6144 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6148 gst_pad_pause_task (GstPad * pad)
6153 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6155 GST_DEBUG_OBJECT (pad, "pause task");
6157 GST_OBJECT_LOCK (pad);
6158 task = GST_PAD_TASK (pad);
6161 res = gst_task_set_state (task, GST_TASK_PAUSED);
6162 /* unblock activation waits if any */
6163 pad->priv->in_activation = FALSE;
6164 g_cond_broadcast (&pad->priv->activation_cond);
6165 GST_OBJECT_UNLOCK (pad);
6167 /* wait for task function to finish, this lock is recursive so it does nothing
6168 * when the pause is called from the task itself */
6169 GST_PAD_STREAM_LOCK (pad);
6170 GST_PAD_STREAM_UNLOCK (pad);
6176 GST_DEBUG_OBJECT (pad, "pad has no task");
6177 GST_OBJECT_UNLOCK (pad);
6183 * gst_pad_get_task_state:
6184 * @pad: the #GstPad to get task state from
6186 * Get @pad task state. If no task is currently
6187 * set, #GST_TASK_STOPPED is returned.
6189 * Returns: The current state of @pad's task.
6194 gst_pad_get_task_state (GstPad * pad)
6199 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6201 GST_OBJECT_LOCK (pad);
6202 task = GST_PAD_TASK (pad);
6205 res = gst_task_get_state (task);
6206 GST_OBJECT_UNLOCK (pad);
6212 GST_DEBUG_OBJECT (pad, "pad has no task");
6213 GST_OBJECT_UNLOCK (pad);
6214 return GST_TASK_STOPPED;
6219 * gst_pad_stop_task:
6220 * @pad: the #GstPad to stop the task of
6222 * Stop the task of @pad. This function will also make sure that the
6223 * function executed by the task will effectively stop if not called
6224 * from the GstTaskFunction.
6226 * This function will deadlock if called from the GstTaskFunction of
6227 * the task. Use gst_task_pause() instead.
6229 * Regardless of whether the pad has a task, the stream lock is acquired and
6230 * released so as to ensure that streaming through this pad has finished.
6232 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6235 gst_pad_stop_task (GstPad * pad)
6240 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6242 GST_DEBUG_OBJECT (pad, "stop task");
6244 GST_OBJECT_LOCK (pad);
6245 task = GST_PAD_TASK (pad);
6248 GST_PAD_TASK (pad) = NULL;
6249 res = gst_task_set_state (task, GST_TASK_STOPPED);
6250 /* unblock activation waits if any */
6251 pad->priv->in_activation = FALSE;
6252 g_cond_broadcast (&pad->priv->activation_cond);
6253 GST_OBJECT_UNLOCK (pad);
6255 GST_PAD_STREAM_LOCK (pad);
6256 GST_PAD_STREAM_UNLOCK (pad);
6258 if (!gst_task_join (task))
6261 gst_object_unref (task);
6267 GST_DEBUG_OBJECT (pad, "no task");
6268 GST_OBJECT_UNLOCK (pad);
6270 GST_PAD_STREAM_LOCK (pad);
6271 GST_PAD_STREAM_UNLOCK (pad);
6273 /* this is not an error */
6278 /* this is bad, possibly the application tried to join the task from
6279 * the task's thread. We install the task again so that it will be stopped
6280 * again from the right thread next time hopefully. */
6281 GST_OBJECT_LOCK (pad);
6282 GST_DEBUG_OBJECT (pad, "join failed");
6283 /* we can only install this task if there was no other task */
6284 if (GST_PAD_TASK (pad) == NULL)
6285 GST_PAD_TASK (pad) = task;
6286 GST_OBJECT_UNLOCK (pad);
6293 * gst_pad_probe_info_get_event:
6294 * @info: a #GstPadProbeInfo
6296 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6300 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6302 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6303 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6305 return GST_PAD_PROBE_INFO_EVENT (info);
6310 * gst_pad_probe_info_get_query:
6311 * @info: a #GstPadProbeInfo
6313 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6317 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6319 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6320 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6322 return GST_PAD_PROBE_INFO_QUERY (info);
6326 * gst_pad_probe_info_get_buffer:
6327 * @info: a #GstPadProbeInfo
6329 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6333 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6335 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6337 return GST_PAD_PROBE_INFO_BUFFER (info);
6341 * gst_pad_probe_info_get_buffer_list:
6342 * @info: a #GstPadProbeInfo
6344 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6348 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6350 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6352 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6356 * gst_pad_get_last_flow_return:
6359 * Gets the #GstFlowReturn return from the last data passed by this pad.
6364 gst_pad_get_last_flow_return (GstPad * pad)
6368 GST_OBJECT_LOCK (pad);
6369 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6370 GST_OBJECT_UNLOCK (pad);