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 _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned %TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
144 /* counter of how many idle probes are running directly from the add_probe
145 * call. Used to block any data flowing in the pad while the idle callback
146 * Doesn't finish its work */
149 /* conditional and variable used to ensure pads only get (de)activated
150 * by a single thread at a time. Protected by the object lock */
151 GCond activation_cond;
152 gboolean in_activation;
160 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
161 (((GstPad *)(p))->priv->idle_running > 0)
166 GstPadProbeInfo *info;
172 gulong *called_probes;
173 guint n_called_probes;
174 guint called_probes_size;
178 static void gst_pad_dispose (GObject * object);
179 static void gst_pad_finalize (GObject * object);
180 static void gst_pad_set_property (GObject * object, guint prop_id,
181 const GValue * value, GParamSpec * pspec);
182 static void gst_pad_get_property (GObject * object, guint prop_id,
183 GValue * value, GParamSpec * pspec);
185 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
186 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
187 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
188 GstObject * parent, GstBufferList * list);
190 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
191 GstEvent * event, GstPadProbeType type);
192 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
195 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
196 GstPadMode mode, gboolean active);
198 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
200 static GParamSpec *pspec_caps = NULL;
202 /* quarks for probe signals */
203 static GQuark buffer_quark;
204 static GQuark buffer_list_quark;
205 static GQuark event_quark;
214 static GstFlowQuarks flow_quarks[] = {
215 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
216 {GST_FLOW_OK, "ok", 0},
217 {GST_FLOW_NOT_LINKED, "not-linked", 0},
218 {GST_FLOW_FLUSHING, "flushing", 0},
219 {GST_FLOW_EOS, "eos", 0},
220 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
221 {GST_FLOW_ERROR, "error", 0},
222 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
223 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
228 * @ret: a #GstFlowReturn to get the name of.
230 * Gets a string representing the given flow return.
232 * Returns: a static string with the name of the flow return.
235 gst_flow_get_name (GstFlowReturn ret)
239 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
241 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
242 if (ret == flow_quarks[i].ret)
243 return flow_quarks[i].name;
250 * @ret: a #GstFlowReturn to get the quark of.
252 * Get the unique quark for the given GstFlowReturn.
254 * Returns: the quark associated with the flow return or 0 if an
255 * invalid return was specified.
258 gst_flow_to_quark (GstFlowReturn ret)
262 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
264 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
265 if (ret == flow_quarks[i].ret)
266 return flow_quarks[i].quark;
272 * gst_pad_link_get_name:
273 * @ret: a #GstPadLinkReturn to get the name of.
275 * Gets a string representing the given pad-link return.
277 * Returns: a static string with the name of the pad-link return.
282 gst_pad_link_get_name (GstPadLinkReturn ret)
285 case GST_PAD_LINK_OK:
287 case GST_PAD_LINK_WRONG_HIERARCHY:
288 return "wrong hierarchy";
289 case GST_PAD_LINK_WAS_LINKED:
291 case GST_PAD_LINK_WRONG_DIRECTION:
292 return "wrong direction";
293 case GST_PAD_LINK_NOFORMAT:
294 return "no common format";
295 case GST_PAD_LINK_NOSCHED:
296 return "incompatible scheduling";
297 case GST_PAD_LINK_REFUSED:
300 g_return_val_if_reached ("unknown");
307 buffer_quark = g_quark_from_static_string ("buffer"); \
308 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
309 event_quark = g_quark_from_static_string ("event"); \
311 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
312 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
315 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
316 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
319 #define gst_pad_parent_class parent_class
320 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT,
321 G_ADD_PRIVATE (GstPad) _do_init);
324 gst_pad_class_init (GstPadClass * klass)
326 GObjectClass *gobject_class;
327 GstObjectClass *gstobject_class;
329 gobject_class = G_OBJECT_CLASS (klass);
330 gstobject_class = GST_OBJECT_CLASS (klass);
332 gobject_class->dispose = gst_pad_dispose;
333 gobject_class->finalize = gst_pad_finalize;
334 gobject_class->set_property = gst_pad_set_property;
335 gobject_class->get_property = gst_pad_get_property;
339 * @pad: the pad that emitted the signal
340 * @peer: the peer pad that has been connected
342 * Signals that a pad has been linked to the peer pad.
344 gst_pad_signals[PAD_LINKED] =
345 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
346 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
347 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
350 * @pad: the pad that emitted the signal
351 * @peer: the peer pad that has been disconnected
353 * Signals that a pad has been unlinked from the peer pad.
355 gst_pad_signals[PAD_UNLINKED] =
356 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
357 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
358 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
360 pspec_caps = g_param_spec_boxed ("caps", "Caps",
361 "The capabilities of the pad", GST_TYPE_CAPS,
362 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
363 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
365 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
366 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
367 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
368 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
370 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
371 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
372 g_param_spec_object ("template", "Template",
373 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
374 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
379 * The offset that will be applied to the running time of the pad.
383 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
384 g_param_spec_int64 ("offset", "Offset",
385 "The running time offset of the pad", 0, G_MAXINT64, 0,
386 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
388 gstobject_class->path_string_separator = ".";
390 /* Register common function pointer descriptions */
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
393 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
399 gst_pad_init (GstPad * pad)
401 pad->priv = gst_pad_get_instance_private (pad);
403 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
405 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
406 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
407 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
408 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
409 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
411 GST_PAD_SET_FLUSHING (pad);
413 g_rec_mutex_init (&pad->stream_rec_lock);
415 g_cond_init (&pad->block_cond);
417 g_hook_list_init (&pad->probes, sizeof (GstProbe));
419 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
420 pad->priv->events_cookie = 0;
421 pad->priv->last_cookie = -1;
422 g_cond_init (&pad->priv->activation_cond);
424 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
427 /* called when setting the pad inactive. It removes all sticky events from
428 * the pad. must be called with object lock */
430 remove_events (GstPad * pad)
434 gboolean notify = FALSE;
436 events = pad->priv->events;
439 for (i = 0; i < len; i++) {
440 PadEvent *ev = &g_array_index (events, PadEvent, i);
441 GstEvent *event = ev->event;
445 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
448 gst_event_unref (event);
451 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
452 g_array_set_size (events, 0);
453 pad->priv->events_cookie++;
456 GST_OBJECT_UNLOCK (pad);
458 GST_DEBUG_OBJECT (pad, "notify caps");
459 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
461 GST_OBJECT_LOCK (pad);
465 /* should be called with object lock */
467 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
473 events = pad->priv->events;
476 for (i = 0; i < len; i++) {
477 ev = &g_array_index (events, PadEvent, i);
478 if (ev->event == NULL)
481 if (GST_EVENT_TYPE (ev->event) == type) {
485 } else if (GST_EVENT_TYPE (ev->event) > type) {
494 /* should be called with OBJECT lock */
496 find_event (GstPad * pad, GstEvent * event)
502 events = pad->priv->events;
505 for (i = 0; i < len; i++) {
506 ev = &g_array_index (events, PadEvent, i);
507 if (event == ev->event)
509 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
517 /* should be called with OBJECT lock */
519 remove_event_by_type (GstPad * pad, GstEventType type)
525 events = pad->priv->events;
530 ev = &g_array_index (events, PadEvent, i);
531 if (ev->event == NULL)
534 if (GST_EVENT_TYPE (ev->event) > type)
536 else if (GST_EVENT_TYPE (ev->event) != type)
539 gst_event_unref (ev->event);
540 g_array_remove_index (events, i);
542 pad->priv->events_cookie++;
550 /* check all events on srcpad against those on sinkpad. All events that are not
551 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
552 * srcpad so that the events will be sent next time */
553 /* should be called with srcpad and sinkpad LOCKS */
555 schedule_events (GstPad * srcpad, GstPad * sinkpad)
560 gboolean pending = FALSE;
562 events = srcpad->priv->events;
565 for (i = 0; i < len; i++) {
566 ev = &g_array_index (events, PadEvent, i);
567 if (ev->event == NULL)
570 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
571 ev->received = FALSE;
576 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
579 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
582 /* should be called with pad LOCK */
584 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
591 events = pad->priv->events;
594 cookie = pad->priv->events_cookie;
598 PadEvent *ev, ev_ret;
600 ev = &g_array_index (events, PadEvent, i);
601 if (G_UNLIKELY (ev->event == NULL))
604 /* take additional ref, func might release the lock */
605 ev_ret.event = gst_event_ref (ev->event);
606 ev_ret.received = ev->received;
608 ret = func (pad, &ev_ret, user_data);
610 /* recheck the cookie, lock might have been released and the list could have
612 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
613 if (G_LIKELY (ev_ret.event))
614 gst_event_unref (ev_ret.event);
618 /* store the received state */
619 ev->received = ev_ret.received;
621 /* if the event changed, we need to do something */
622 if (G_UNLIKELY (ev->event != ev_ret.event)) {
623 if (G_UNLIKELY (ev_ret.event == NULL)) {
624 /* function unreffed and set the event to NULL, remove it */
625 gst_event_unref (ev->event);
626 g_array_remove_index (events, i);
628 cookie = ++pad->priv->events_cookie;
631 /* function gave a new event for us */
632 gst_event_take (&ev->event, ev_ret.event);
635 /* just unref, nothing changed */
636 gst_event_unref (ev_ret.event);
645 /* should be called with LOCK */
647 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream,
652 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
653 GST_STIME_ARGS (pad_offset));
655 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
658 g_assert (!upstream);
660 /* copy segment values */
661 gst_event_copy_segment (event, &segment);
662 gst_event_unref (event);
664 gst_segment_offset_running_time (&segment, segment.format, pad_offset);
665 event = gst_event_new_segment (&segment);
668 event = gst_event_make_writable (event);
669 offset = gst_event_get_running_time_offset (event);
671 offset -= pad_offset;
673 offset += pad_offset;
674 gst_event_set_running_time_offset (event, offset);
679 static inline GstEvent *
680 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
682 if (G_UNLIKELY (pad->offset != 0))
683 return _apply_pad_offset (pad, event, upstream, pad->offset);
687 /* should be called with the OBJECT_LOCK */
689 get_pad_caps (GstPad * pad)
691 GstCaps *caps = NULL;
694 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
696 gst_event_parse_caps (ev->event, &caps);
702 gst_pad_dispose (GObject * object)
704 GstPad *pad = GST_PAD_CAST (object);
707 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
709 /* unlink the peer pad */
710 if ((peer = gst_pad_get_peer (pad))) {
711 /* window for MT unsafeness, someone else could unlink here
712 * and then we call unlink with wrong pads. The unlink
713 * function would catch this and safely return failed. */
714 if (GST_PAD_IS_SRC (pad))
715 gst_pad_unlink (pad, peer);
717 gst_pad_unlink (peer, pad);
719 gst_object_unref (peer);
722 gst_pad_set_pad_template (pad, NULL);
724 GST_OBJECT_LOCK (pad);
726 GST_OBJECT_UNLOCK (pad);
728 g_hook_list_clear (&pad->probes);
730 G_OBJECT_CLASS (parent_class)->dispose (object);
734 gst_pad_finalize (GObject * object)
736 GstPad *pad = GST_PAD_CAST (object);
739 /* in case the task is still around, clean it up */
740 if ((task = GST_PAD_TASK (pad))) {
741 gst_task_join (task);
742 GST_PAD_TASK (pad) = NULL;
743 gst_object_unref (task);
746 if (pad->activatenotify)
747 pad->activatenotify (pad->activatedata);
748 if (pad->activatemodenotify)
749 pad->activatemodenotify (pad->activatemodedata);
751 pad->linknotify (pad->linkdata);
752 if (pad->unlinknotify)
753 pad->unlinknotify (pad->unlinkdata);
754 if (pad->chainnotify)
755 pad->chainnotify (pad->chaindata);
756 if (pad->chainlistnotify)
757 pad->chainlistnotify (pad->chainlistdata);
758 if (pad->getrangenotify)
759 pad->getrangenotify (pad->getrangedata);
760 if (pad->eventnotify)
761 pad->eventnotify (pad->eventdata);
762 if (pad->querynotify)
763 pad->querynotify (pad->querydata);
764 if (pad->iterintlinknotify)
765 pad->iterintlinknotify (pad->iterintlinkdata);
767 g_rec_mutex_clear (&pad->stream_rec_lock);
768 g_cond_clear (&pad->block_cond);
769 g_cond_clear (&pad->priv->activation_cond);
770 g_array_free (pad->priv->events, TRUE);
772 G_OBJECT_CLASS (parent_class)->finalize (object);
776 gst_pad_set_property (GObject * object, guint prop_id,
777 const GValue * value, GParamSpec * pspec)
779 g_return_if_fail (GST_IS_PAD (object));
782 case PAD_PROP_DIRECTION:
783 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
785 case PAD_PROP_TEMPLATE:
786 gst_pad_set_pad_template (GST_PAD_CAST (object),
787 (GstPadTemplate *) g_value_get_object (value));
789 case PAD_PROP_OFFSET:
790 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
793 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
799 gst_pad_get_property (GObject * object, guint prop_id,
800 GValue * value, GParamSpec * pspec)
802 g_return_if_fail (GST_IS_PAD (object));
806 GST_OBJECT_LOCK (object);
807 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
808 GST_OBJECT_UNLOCK (object);
810 case PAD_PROP_DIRECTION:
811 g_value_set_enum (value, GST_PAD_DIRECTION (object));
813 case PAD_PROP_TEMPLATE:
814 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
816 case PAD_PROP_OFFSET:
817 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
820 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
827 * @name: (allow-none): the name of the new pad.
828 * @direction: the #GstPadDirection of the pad.
830 * Creates a new pad with the given name in the given direction.
831 * If name is %NULL, a guaranteed unique name (across all pads)
833 * This function makes a copy of the name so you can safely free the name.
835 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
841 gst_pad_new (const gchar * name, GstPadDirection direction)
843 return g_object_new (GST_TYPE_PAD,
844 "name", name, "direction", direction, NULL);
848 * gst_pad_new_from_template:
849 * @templ: the pad template to use
850 * @name: (allow-none): the name of the pad
852 * Creates a new pad with the given name from the given template.
853 * If name is %NULL, a guaranteed unique name (across all pads)
855 * This function makes a copy of the name so you can safely free the name.
857 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
861 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
864 GST_PAD_TEMPLATE_GTYPE (templ) ==
865 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
867 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
869 return g_object_new (pad_type,
870 "name", name, "direction", templ->direction, "template", templ, NULL);
874 * gst_pad_new_from_static_template:
875 * @templ: the #GstStaticPadTemplate to use
876 * @name: the name of the pad
878 * Creates a new pad with the given name from the given static template.
879 * If name is %NULL, a guaranteed unique name (across all pads)
881 * This function makes a copy of the name so you can safely free the name.
883 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
887 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
891 GstPadTemplate *template;
893 template = gst_static_pad_template_get (templ);
894 pad = gst_pad_new_from_template (template, name);
895 gst_object_unref (template);
899 #define ACQUIRE_PARENT(pad, parent, label) \
901 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
902 gst_object_ref (parent); \
903 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
907 #define RELEASE_PARENT(parent) \
909 if (G_LIKELY (parent)) \
910 gst_object_unref (parent); \
914 * gst_pad_get_direction:
915 * @pad: a #GstPad to get the direction of.
917 * Gets the direction of the pad. The direction of the pad is
918 * decided at construction time so this function does not take
921 * Returns: the #GstPadDirection of the pad.
926 gst_pad_get_direction (GstPad * pad)
928 GstPadDirection result;
930 /* PAD_UNKNOWN is a little silly but we need some sort of
931 * error return value */
932 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
934 result = GST_PAD_DIRECTION (pad);
940 gst_pad_activate_default (GstPad * pad, GstObject * parent)
942 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
944 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
948 * gst_pad_mode_get_name:
949 * @mode: the pad mode
951 * Return the name of a pad mode, for use in debug messages mostly.
953 * Returns: short mnemonic for pad mode @mode
956 gst_pad_mode_get_name (GstPadMode mode)
959 case GST_PAD_MODE_NONE:
961 case GST_PAD_MODE_PUSH:
963 case GST_PAD_MODE_PULL:
971 /* Returns TRUE if pad wasn't already in the new_mode */
973 pre_activate (GstPad * pad, GstPadMode new_mode)
976 case GST_PAD_MODE_NONE:
977 GST_OBJECT_LOCK (pad);
978 while (G_UNLIKELY (pad->priv->in_activation))
979 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
980 if (new_mode == GST_PAD_MODE (pad)) {
981 GST_WARNING_OBJECT (pad,
982 "Pad is already in the process of being deactivated");
983 GST_OBJECT_UNLOCK (pad);
986 pad->priv->in_activation = TRUE;
987 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
988 GST_PAD_SET_FLUSHING (pad);
989 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
990 GST_PAD_MODE (pad) = new_mode;
991 /* unlock blocked pads so element can resume and stop */
992 GST_PAD_BLOCK_BROADCAST (pad);
993 GST_OBJECT_UNLOCK (pad);
995 case GST_PAD_MODE_PUSH:
996 case GST_PAD_MODE_PULL:
997 GST_OBJECT_LOCK (pad);
998 while (G_UNLIKELY (pad->priv->in_activation))
999 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1000 if (new_mode == GST_PAD_MODE (pad)) {
1001 GST_WARNING_OBJECT (pad,
1002 "Pad is already in the process of being activated");
1003 GST_OBJECT_UNLOCK (pad);
1006 pad->priv->in_activation = TRUE;
1007 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1008 gst_pad_mode_get_name (new_mode));
1009 GST_PAD_UNSET_FLUSHING (pad);
1010 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1011 GST_PAD_MODE (pad) = new_mode;
1012 if (GST_PAD_IS_SINK (pad)) {
1014 /* make sure the peer src pad sends us all events */
1015 if ((peer = GST_PAD_PEER (pad))) {
1016 gst_object_ref (peer);
1017 GST_OBJECT_UNLOCK (pad);
1019 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1020 GST_DEBUG_PAD_NAME (peer));
1022 GST_OBJECT_LOCK (peer);
1023 schedule_events (peer, NULL);
1024 GST_OBJECT_UNLOCK (peer);
1026 gst_object_unref (peer);
1028 GST_OBJECT_UNLOCK (pad);
1031 GST_OBJECT_UNLOCK (pad);
1039 post_activate (GstPad * pad, GstPadMode new_mode)
1042 case GST_PAD_MODE_NONE:
1043 GST_OBJECT_LOCK (pad);
1044 pad->priv->in_activation = FALSE;
1045 g_cond_broadcast (&pad->priv->activation_cond);
1046 GST_OBJECT_UNLOCK (pad);
1048 /* ensures that streaming stops */
1049 GST_PAD_STREAM_LOCK (pad);
1050 GST_DEBUG_OBJECT (pad, "stopped streaming");
1051 GST_OBJECT_LOCK (pad);
1052 remove_events (pad);
1053 GST_OBJECT_UNLOCK (pad);
1054 GST_PAD_STREAM_UNLOCK (pad);
1056 case GST_PAD_MODE_PUSH:
1057 case GST_PAD_MODE_PULL:
1058 GST_OBJECT_LOCK (pad);
1059 pad->priv->in_activation = FALSE;
1060 g_cond_broadcast (&pad->priv->activation_cond);
1061 GST_OBJECT_UNLOCK (pad);
1068 * gst_pad_set_active:
1069 * @pad: the #GstPad to activate or deactivate.
1070 * @active: whether or not the pad should be active.
1072 * Activates or deactivates the given pad.
1073 * Normally called from within core state change functions.
1075 * If @active, makes sure the pad is active. If it is already active, either in
1076 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1077 * function to perform the actual activation.
1079 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1080 * and a %FALSE argument.
1082 * Returns: %TRUE if the operation was successful.
1087 gst_pad_set_active (GstPad * pad, gboolean active)
1091 gboolean ret = FALSE;
1093 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1095 GST_OBJECT_LOCK (pad);
1096 old = GST_PAD_MODE (pad);
1097 ACQUIRE_PARENT (pad, parent, no_parent);
1098 GST_OBJECT_UNLOCK (pad);
1101 if (old == GST_PAD_MODE_NONE) {
1102 GST_DEBUG_OBJECT (pad, "activating pad from none");
1103 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1105 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1107 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1108 gst_pad_mode_get_name (old));
1112 if (old == GST_PAD_MODE_NONE) {
1113 GST_DEBUG_OBJECT (pad, "pad was inactive");
1116 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1117 gst_pad_mode_get_name (old));
1118 ret = activate_mode_internal (pad, parent, old, FALSE);
1120 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1124 RELEASE_PARENT (parent);
1126 if (G_UNLIKELY (!ret))
1134 GST_DEBUG_OBJECT (pad, "no parent");
1135 GST_OBJECT_UNLOCK (pad);
1140 GST_OBJECT_LOCK (pad);
1142 g_critical ("Failed to deactivate pad %s:%s, very bad",
1143 GST_DEBUG_PAD_NAME (pad));
1145 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1147 GST_OBJECT_UNLOCK (pad);
1153 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1156 gboolean res = FALSE;
1157 GstPadMode old, new;
1158 GstPadDirection dir;
1161 GST_OBJECT_LOCK (pad);
1162 old = GST_PAD_MODE (pad);
1163 dir = GST_PAD_DIRECTION (pad);
1164 GST_OBJECT_UNLOCK (pad);
1166 new = active ? mode : GST_PAD_MODE_NONE;
1171 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1172 /* pad was activate in the wrong direction, deactivate it
1173 * and reactivate it in the requested mode */
1174 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1175 gst_pad_mode_get_name (old));
1177 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1178 goto deactivate_failed;
1179 old = GST_PAD_MODE_NONE;
1183 case GST_PAD_MODE_PULL:
1185 if (dir == GST_PAD_SINK) {
1186 if ((peer = gst_pad_get_peer (pad))) {
1187 GST_DEBUG_OBJECT (pad, "calling peer");
1188 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1190 gst_object_unref (peer);
1192 /* there is no peer, this is only fatal when we activate. When we
1193 * deactivate, we must assume the application has unlinked the peer and
1194 * will deactivate it eventually. */
1198 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1201 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1202 goto failure; /* Can't activate pull on a src without a
1203 getrange function */
1211 /* Mark pad as needing reconfiguration */
1213 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1215 /* pre_activate returns TRUE if we weren't already in the process of
1216 * switching to the 'new' mode */
1217 if (pre_activate (pad, new)) {
1219 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1220 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1224 /* can happen for sinks of passthrough elements */
1227 post_activate (pad, new);
1230 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1231 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1236 /* Clear sticky flags on deactivation */
1238 GST_OBJECT_LOCK (pad);
1239 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1240 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1241 GST_OBJECT_UNLOCK (pad);
1249 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1250 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1255 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1256 "failed to %s in switch to %s mode from %s mode",
1257 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1258 gst_pad_mode_get_name (old));
1263 GST_OBJECT_LOCK (peer);
1264 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1265 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1266 GST_OBJECT_UNLOCK (peer);
1267 gst_object_unref (peer);
1272 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1273 "pad in pull mode");
1278 GST_OBJECT_LOCK (pad);
1279 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1280 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1281 GST_PAD_SET_FLUSHING (pad);
1282 GST_PAD_MODE (pad) = old;
1283 pad->priv->in_activation = FALSE;
1284 g_cond_broadcast (&pad->priv->activation_cond);
1285 GST_OBJECT_UNLOCK (pad);
1291 * gst_pad_activate_mode:
1292 * @pad: the #GstPad to activate or deactivate.
1293 * @mode: the requested activation mode
1294 * @active: whether or not the pad should be active.
1296 * Activates or deactivates the given pad in @mode via dispatching to the
1297 * pad's activatemodefunc. For use from within pad activation functions only.
1299 * If you don't know what this is, you probably don't want to call it.
1301 * Returns: %TRUE if the operation was successful.
1306 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1310 GstPadMode old, new;
1312 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1314 GST_OBJECT_LOCK (pad);
1316 old = GST_PAD_MODE (pad);
1317 new = active ? mode : GST_PAD_MODE_NONE;
1321 ACQUIRE_PARENT (pad, parent, no_parent);
1323 GST_OBJECT_UNLOCK (pad);
1325 res = activate_mode_internal (pad, parent, mode, active);
1327 RELEASE_PARENT (parent);
1333 GST_OBJECT_UNLOCK (pad);
1334 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1335 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1340 GST_WARNING_OBJECT (pad, "no parent");
1341 GST_OBJECT_UNLOCK (pad);
1347 * gst_pad_is_active:
1348 * @pad: the #GstPad to query
1350 * Query if a pad is active
1352 * Returns: %TRUE if the pad is active.
1357 gst_pad_is_active (GstPad * pad)
1359 gboolean result = FALSE;
1361 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1363 GST_OBJECT_LOCK (pad);
1364 result = GST_PAD_IS_ACTIVE (pad);
1365 GST_OBJECT_UNLOCK (pad);
1371 cleanup_hook (GstPad * pad, GHook * hook)
1373 GstPadProbeType type;
1375 if (!G_HOOK_IS_VALID (hook))
1378 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1380 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1381 /* unblock when we remove the last blocking probe */
1383 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1386 /* Might have new probes now that want to be called */
1387 GST_PAD_BLOCK_BROADCAST (pad);
1389 if (pad->num_blocked == 0) {
1390 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1391 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1394 g_hook_destroy_link (&pad->probes, hook);
1399 * gst_pad_add_probe:
1400 * @pad: the #GstPad to add the probe to
1401 * @mask: the probe mask
1402 * @callback: #GstPadProbeCallback that will be called with notifications of
1404 * @user_data: (closure): user data passed to the callback
1405 * @destroy_data: #GDestroyNotify for user_data
1407 * Be notified of different states of pads. The provided callback is called for
1408 * every state that matches @mask.
1410 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1411 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1412 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1413 * immediately if the pad is already idle while calling gst_pad_add_probe().
1414 * In each of the groups, probes are called in the order in which they were
1417 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1418 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1419 * happen that the probe can be run immediately and if the probe returns
1420 * GST_PAD_PROBE_REMOVE this functions returns 0.
1425 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1426 GstPadProbeCallback callback, gpointer user_data,
1427 GDestroyNotify destroy_data)
1432 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1433 g_return_val_if_fail (mask != 0, 0);
1435 GST_OBJECT_LOCK (pad);
1437 /* make a new probe */
1438 hook = g_hook_alloc (&pad->probes);
1440 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1443 /* when no constraints are given for the types, assume all types are
1445 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1446 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1447 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1448 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1450 /* store our flags and other fields */
1451 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1452 hook->func = callback;
1453 hook->data = user_data;
1454 hook->destroy = destroy_data;
1457 g_hook_append (&pad->probes, hook);
1459 /* incremenent cookie so that the new hook gets called */
1460 pad->priv->probe_list_cookie++;
1462 /* get the id of the hook, we return this and it can be used to remove the
1464 res = hook->hook_id;
1466 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1468 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1469 /* we have a block probe */
1471 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1473 "now %d blocking probes", pad->num_blocked);
1475 /* Might have new probes now that want to be called */
1476 GST_PAD_BLOCK_BROADCAST (pad);
1479 /* call the callback if we need to be called for idle callbacks */
1480 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1481 if (pad->priv->using > 0) {
1482 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1483 * flag above, the last thread to leave the push will do the callback. New
1484 * threads going into the push will block. */
1485 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1486 "pad is in use, delay idle callback");
1487 GST_OBJECT_UNLOCK (pad);
1489 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1490 GstPadProbeReturn ret;
1492 /* Keep another ref, the callback could destroy the pad */
1493 gst_object_ref (pad);
1494 pad->priv->idle_running++;
1496 /* the pad is idle now, we can signal the idle callback now */
1497 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1498 "pad is idle, trigger idle callback");
1499 GST_OBJECT_UNLOCK (pad);
1501 ret = callback (pad, &info, user_data);
1503 GST_OBJECT_LOCK (pad);
1505 case GST_PAD_PROBE_REMOVE:
1506 /* remove the probe */
1507 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1508 cleanup_hook (pad, hook);
1511 case GST_PAD_PROBE_DROP:
1512 GST_DEBUG_OBJECT (pad, "asked to drop item");
1514 case GST_PAD_PROBE_PASS:
1515 GST_DEBUG_OBJECT (pad, "asked to pass item");
1517 case GST_PAD_PROBE_OK:
1518 GST_DEBUG_OBJECT (pad, "probe returned OK");
1520 case GST_PAD_PROBE_HANDLED:
1521 GST_DEBUG_OBJECT (pad, "probe handled the data");
1524 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1527 pad->priv->idle_running--;
1528 if (pad->priv->idle_running == 0) {
1529 GST_PAD_BLOCK_BROADCAST (pad);
1531 GST_OBJECT_UNLOCK (pad);
1533 gst_object_unref (pad);
1536 GST_OBJECT_UNLOCK (pad);
1542 * gst_pad_remove_probe:
1543 * @pad: the #GstPad with the probe
1544 * @id: the probe id to remove
1546 * Remove the probe with @id from @pad.
1551 gst_pad_remove_probe (GstPad * pad, gulong id)
1555 g_return_if_fail (GST_IS_PAD (pad));
1557 GST_OBJECT_LOCK (pad);
1559 hook = g_hook_get (&pad->probes, id);
1563 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1565 cleanup_hook (pad, hook);
1566 GST_OBJECT_UNLOCK (pad);
1572 GST_OBJECT_UNLOCK (pad);
1573 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1579 * gst_pad_is_blocked:
1580 * @pad: the #GstPad to query
1582 * Checks if the pad is blocked or not. This function returns the
1583 * last requested state of the pad. It is not certain that the pad
1584 * is actually blocking at this point (see gst_pad_is_blocking()).
1586 * Returns: %TRUE if the pad is blocked.
1591 gst_pad_is_blocked (GstPad * pad)
1593 gboolean result = FALSE;
1595 g_return_val_if_fail (GST_IS_PAD (pad), result);
1597 GST_OBJECT_LOCK (pad);
1598 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1599 GST_OBJECT_UNLOCK (pad);
1605 * gst_pad_is_blocking:
1606 * @pad: the #GstPad to query
1608 * Checks if the pad is blocking or not. This is a guaranteed state
1609 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1611 * Returns: %TRUE if the pad is blocking.
1616 gst_pad_is_blocking (GstPad * pad)
1618 gboolean result = FALSE;
1620 g_return_val_if_fail (GST_IS_PAD (pad), result);
1622 GST_OBJECT_LOCK (pad);
1623 /* the blocking flag is only valid if the pad is not flushing */
1624 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1625 GST_OBJECT_UNLOCK (pad);
1631 * gst_pad_needs_reconfigure:
1632 * @pad: the #GstPad to check
1634 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1635 * if the flag was set.
1637 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1640 gst_pad_needs_reconfigure (GstPad * pad)
1642 gboolean reconfigure;
1644 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1646 GST_OBJECT_LOCK (pad);
1647 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1648 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1649 GST_OBJECT_UNLOCK (pad);
1655 * gst_pad_check_reconfigure:
1656 * @pad: the #GstPad to check
1658 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1659 * if the flag was set.
1661 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1664 gst_pad_check_reconfigure (GstPad * pad)
1666 gboolean reconfigure;
1668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1670 GST_OBJECT_LOCK (pad);
1671 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1673 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1674 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1676 GST_OBJECT_UNLOCK (pad);
1682 * gst_pad_mark_reconfigure:
1683 * @pad: the #GstPad to mark
1685 * Mark a pad for needing reconfiguration. The next call to
1686 * gst_pad_check_reconfigure() will return %TRUE after this call.
1689 gst_pad_mark_reconfigure (GstPad * pad)
1691 g_return_if_fail (GST_IS_PAD (pad));
1693 GST_OBJECT_LOCK (pad);
1694 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1695 GST_OBJECT_UNLOCK (pad);
1699 * gst_pad_set_activate_function:
1701 * @f: the #GstPadActivateFunction to set.
1703 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1707 * gst_pad_set_activate_function_full:
1709 * @activate: the #GstPadActivateFunction to set.
1710 * @user_data: user_data passed to @notify
1711 * @notify: notify called when @activate will not be used anymore.
1713 * Sets the given activate function for @pad. The activate function will
1714 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1715 * Only makes sense to set on sink pads.
1717 * Call this function if your sink pad can start a pull-based task.
1720 gst_pad_set_activate_function_full (GstPad * pad,
1721 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1723 g_return_if_fail (GST_IS_PAD (pad));
1725 if (pad->activatenotify)
1726 pad->activatenotify (pad->activatedata);
1727 GST_PAD_ACTIVATEFUNC (pad) = activate;
1728 pad->activatedata = user_data;
1729 pad->activatenotify = notify;
1731 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1732 GST_DEBUG_FUNCPTR_NAME (activate));
1736 * gst_pad_set_activatemode_function:
1738 * @f: the #GstPadActivateModeFunction to set.
1740 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1744 * gst_pad_set_activatemode_function_full:
1746 * @activatemode: the #GstPadActivateModeFunction to set.
1747 * @user_data: user_data passed to @notify
1748 * @notify: notify called when @activatemode will not be used anymore.
1750 * Sets the given activate_mode function for the pad. An activate_mode function
1751 * prepares the element for data passing.
1754 gst_pad_set_activatemode_function_full (GstPad * pad,
1755 GstPadActivateModeFunction activatemode, gpointer user_data,
1756 GDestroyNotify notify)
1758 g_return_if_fail (GST_IS_PAD (pad));
1760 if (pad->activatemodenotify)
1761 pad->activatemodenotify (pad->activatemodedata);
1762 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1763 pad->activatemodedata = user_data;
1764 pad->activatemodenotify = notify;
1766 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1767 GST_DEBUG_FUNCPTR_NAME (activatemode));
1771 * gst_pad_set_chain_function:
1772 * @p: a sink #GstPad.
1773 * @f: the #GstPadChainFunction to set.
1775 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1779 * gst_pad_set_chain_function_full:
1780 * @pad: a sink #GstPad.
1781 * @chain: the #GstPadChainFunction to set.
1782 * @user_data: user_data passed to @notify
1783 * @notify: notify called when @chain will not be used anymore.
1785 * Sets the given chain function for the pad. The chain function is called to
1786 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1789 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1790 gpointer user_data, GDestroyNotify notify)
1792 g_return_if_fail (GST_IS_PAD (pad));
1793 g_return_if_fail (GST_PAD_IS_SINK (pad));
1795 if (pad->chainnotify)
1796 pad->chainnotify (pad->chaindata);
1797 GST_PAD_CHAINFUNC (pad) = chain;
1798 pad->chaindata = user_data;
1799 pad->chainnotify = notify;
1801 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1802 GST_DEBUG_FUNCPTR_NAME (chain));
1806 * gst_pad_set_chain_list_function:
1807 * @p: a sink #GstPad.
1808 * @f: the #GstPadChainListFunction to set.
1810 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1814 * gst_pad_set_chain_list_function_full:
1815 * @pad: a sink #GstPad.
1816 * @chainlist: the #GstPadChainListFunction to set.
1817 * @user_data: user_data passed to @notify
1818 * @notify: notify called when @chainlist will not be used anymore.
1820 * Sets the given chain list function for the pad. The chainlist function is
1821 * called to process a #GstBufferList input buffer list. See
1822 * #GstPadChainListFunction for more details.
1825 gst_pad_set_chain_list_function_full (GstPad * pad,
1826 GstPadChainListFunction chainlist, gpointer user_data,
1827 GDestroyNotify notify)
1829 g_return_if_fail (GST_IS_PAD (pad));
1830 g_return_if_fail (GST_PAD_IS_SINK (pad));
1832 if (pad->chainlistnotify)
1833 pad->chainlistnotify (pad->chainlistdata);
1834 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1835 pad->chainlistdata = user_data;
1836 pad->chainlistnotify = notify;
1838 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1839 GST_DEBUG_FUNCPTR_NAME (chainlist));
1843 * gst_pad_set_getrange_function:
1844 * @p: a source #GstPad.
1845 * @f: the #GstPadGetRangeFunction to set.
1847 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1851 * gst_pad_set_getrange_function_full:
1852 * @pad: a source #GstPad.
1853 * @get: the #GstPadGetRangeFunction to set.
1854 * @user_data: user_data passed to @notify
1855 * @notify: notify called when @get will not be used anymore.
1857 * Sets the given getrange function for the pad. The getrange function is
1858 * called to produce a new #GstBuffer to start the processing pipeline. see
1859 * #GstPadGetRangeFunction for a description of the getrange function.
1862 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1863 gpointer user_data, GDestroyNotify notify)
1865 g_return_if_fail (GST_IS_PAD (pad));
1866 g_return_if_fail (GST_PAD_IS_SRC (pad));
1868 if (pad->getrangenotify)
1869 pad->getrangenotify (pad->getrangedata);
1870 GST_PAD_GETRANGEFUNC (pad) = get;
1871 pad->getrangedata = user_data;
1872 pad->getrangenotify = notify;
1874 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1875 GST_DEBUG_FUNCPTR_NAME (get));
1879 * gst_pad_set_event_function:
1880 * @p: a #GstPad of either direction.
1881 * @f: the #GstPadEventFunction to set.
1883 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1887 * gst_pad_set_event_function_full:
1888 * @pad: a #GstPad of either direction.
1889 * @event: the #GstPadEventFunction to set.
1890 * @user_data: user_data passed to @notify
1891 * @notify: notify called when @event will not be used anymore.
1893 * Sets the given event handler for the pad.
1896 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1897 gpointer user_data, GDestroyNotify notify)
1899 g_return_if_fail (GST_IS_PAD (pad));
1901 if (pad->eventnotify)
1902 pad->eventnotify (pad->eventdata);
1903 GST_PAD_EVENTFUNC (pad) = event;
1904 pad->eventdata = user_data;
1905 pad->eventnotify = notify;
1907 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1908 GST_DEBUG_FUNCPTR_NAME (event));
1912 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1916 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1917 if (ret == GST_FLOW_OK)
1923 * gst_pad_set_event_full_function:
1924 * @p: a #GstPad of either direction.
1925 * @f: the #GstPadEventFullFunction to set.
1927 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1931 * gst_pad_set_event_full_function_full:
1932 * @pad: a #GstPad of either direction.
1933 * @event: the #GstPadEventFullFunction to set.
1934 * @user_data: user_data passed to @notify
1935 * @notify: notify called when @event will not be used anymore.
1937 * Sets the given event handler for the pad.
1942 gst_pad_set_event_full_function_full (GstPad * pad,
1943 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1945 g_return_if_fail (GST_IS_PAD (pad));
1947 if (pad->eventnotify)
1948 pad->eventnotify (pad->eventdata);
1949 GST_PAD_EVENTFULLFUNC (pad) = event;
1950 GST_PAD_EVENTFUNC (pad) = event_wrap;
1951 pad->eventdata = user_data;
1952 pad->eventnotify = notify;
1954 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1955 GST_DEBUG_FUNCPTR_NAME (event));
1959 * gst_pad_set_query_function:
1960 * @p: a #GstPad of either direction.
1961 * @f: the #GstPadQueryFunction to set.
1963 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1967 * gst_pad_set_query_function_full:
1968 * @pad: a #GstPad of either direction.
1969 * @query: the #GstPadQueryFunction to set.
1970 * @user_data: user_data passed to @notify
1971 * @notify: notify called when @query will not be used anymore.
1973 * Set the given query function for the pad.
1976 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1977 gpointer user_data, GDestroyNotify notify)
1979 g_return_if_fail (GST_IS_PAD (pad));
1981 if (pad->querynotify)
1982 pad->querynotify (pad->querydata);
1983 GST_PAD_QUERYFUNC (pad) = query;
1984 pad->querydata = user_data;
1985 pad->querynotify = notify;
1987 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1988 GST_DEBUG_FUNCPTR_NAME (query));
1992 * gst_pad_set_iterate_internal_links_function:
1993 * @p: a #GstPad of either direction.
1994 * @f: the #GstPadIterIntLinkFunction to set.
1996 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1997 * for the user_data and notify.
2000 * gst_pad_set_iterate_internal_links_function_full:
2001 * @pad: a #GstPad of either direction.
2002 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2003 * @user_data: user_data passed to @notify
2004 * @notify: notify called when @iterintlink will not be used anymore.
2006 * Sets the given internal link iterator function for the pad.
2009 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2010 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2011 GDestroyNotify notify)
2013 g_return_if_fail (GST_IS_PAD (pad));
2015 if (pad->iterintlinknotify)
2016 pad->iterintlinknotify (pad->iterintlinkdata);
2017 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2018 pad->iterintlinkdata = user_data;
2019 pad->iterintlinknotify = notify;
2021 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2022 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2026 * gst_pad_set_link_function:
2028 * @f: the #GstPadLinkFunction to set.
2030 * Calls gst_pad_set_link_function_full() with %NULL
2031 * for the user_data and notify.
2034 * gst_pad_set_link_function_full:
2036 * @link: the #GstPadLinkFunction to set.
2037 * @user_data: user_data passed to @notify
2038 * @notify: notify called when @link will not be used anymore.
2040 * Sets the given link function for the pad. It will be called when
2041 * the pad is linked with another pad.
2043 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2046 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2047 * cannot be made for some reason.
2049 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2050 * of the peer sink pad, if present.
2053 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2054 gpointer user_data, GDestroyNotify notify)
2056 g_return_if_fail (GST_IS_PAD (pad));
2058 if (pad->linknotify)
2059 pad->linknotify (pad->linkdata);
2060 GST_PAD_LINKFUNC (pad) = link;
2061 pad->linkdata = user_data;
2062 pad->linknotify = notify;
2064 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2065 GST_DEBUG_FUNCPTR_NAME (link));
2069 * gst_pad_set_unlink_function:
2071 * @f: the #GstPadUnlinkFunction to set.
2073 * Calls gst_pad_set_unlink_function_full() with %NULL
2074 * for the user_data and notify.
2077 * gst_pad_set_unlink_function_full:
2079 * @unlink: the #GstPadUnlinkFunction to set.
2080 * @user_data: user_data passed to @notify
2081 * @notify: notify called when @unlink will not be used anymore.
2083 * Sets the given unlink function for the pad. It will be called
2084 * when the pad is unlinked.
2087 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2088 gpointer user_data, GDestroyNotify notify)
2090 g_return_if_fail (GST_IS_PAD (pad));
2092 if (pad->unlinknotify)
2093 pad->unlinknotify (pad->unlinkdata);
2094 GST_PAD_UNLINKFUNC (pad) = unlink;
2095 pad->unlinkdata = user_data;
2096 pad->unlinknotify = notify;
2098 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2099 GST_DEBUG_FUNCPTR_NAME (unlink));
2104 * @srcpad: the source #GstPad to unlink.
2105 * @sinkpad: the sink #GstPad to unlink.
2107 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2108 * signal on both pads.
2110 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2111 * the pads were not linked together.
2116 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2118 gboolean result = FALSE;
2119 GstElement *parent = NULL;
2121 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2122 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2123 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2124 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2126 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2128 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2129 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2130 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2132 /* We need to notify the parent before taking any pad locks as the bin in
2133 * question might be waiting for a lock on the pad while holding its lock
2134 * that our message will try to take. */
2135 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2136 if (GST_IS_ELEMENT (parent)) {
2137 gst_element_post_message (parent,
2138 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2139 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2141 gst_object_unref (parent);
2146 GST_OBJECT_LOCK (srcpad);
2147 GST_OBJECT_LOCK (sinkpad);
2149 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2150 goto not_linked_together;
2152 if (GST_PAD_UNLINKFUNC (srcpad)) {
2153 GstObject *tmpparent;
2155 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2157 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2158 RELEASE_PARENT (tmpparent);
2161 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2162 GstObject *tmpparent;
2164 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2166 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2167 RELEASE_PARENT (tmpparent);
2171 /* first clear peers */
2172 GST_PAD_PEER (srcpad) = NULL;
2173 GST_PAD_PEER (sinkpad) = NULL;
2175 GST_OBJECT_UNLOCK (sinkpad);
2176 GST_OBJECT_UNLOCK (srcpad);
2178 /* fire off a signal to each of the pads telling them
2179 * that they've been unlinked */
2180 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2181 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2183 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2184 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2189 if (parent != NULL) {
2190 gst_element_post_message (parent,
2191 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2192 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2193 gst_object_unref (parent);
2195 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2199 not_linked_together:
2201 /* we do not emit a warning in this case because unlinking cannot
2202 * be made MT safe.*/
2203 GST_OBJECT_UNLOCK (sinkpad);
2204 GST_OBJECT_UNLOCK (srcpad);
2210 * gst_pad_is_linked:
2211 * @pad: pad to check
2213 * Checks if a @pad is linked to another pad or not.
2215 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2220 gst_pad_is_linked (GstPad * pad)
2224 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2226 GST_OBJECT_LOCK (pad);
2227 result = (GST_PAD_PEER (pad) != NULL);
2228 GST_OBJECT_UNLOCK (pad);
2233 /* get the caps from both pads and see if the intersection
2236 * This function should be called with the pad LOCK on both
2240 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2241 GstPadLinkCheck flags)
2243 GstCaps *srccaps = NULL;
2244 GstCaps *sinkcaps = NULL;
2245 gboolean compatible = FALSE;
2247 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2250 /* Doing the expensive caps checking takes priority over only checking the template caps */
2251 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2252 GST_OBJECT_UNLOCK (sink);
2253 GST_OBJECT_UNLOCK (src);
2255 srccaps = gst_pad_query_caps (src, NULL);
2256 sinkcaps = gst_pad_query_caps (sink, NULL);
2258 GST_OBJECT_LOCK (src);
2259 GST_OBJECT_LOCK (sink);
2261 /* If one of the two pads doesn't have a template, consider the intersection
2263 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2264 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2268 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2270 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2273 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2275 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2278 /* if we have caps on both pads we can check the intersection. If one
2279 * of the caps is %NULL, we return %TRUE. */
2280 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2282 gst_caps_unref (srccaps);
2284 gst_caps_unref (sinkcaps);
2288 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2289 gst_caps_unref (srccaps);
2290 gst_caps_unref (sinkcaps);
2293 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2294 (compatible ? "" : "not "));
2299 /* check if the grandparents of both pads are the same.
2300 * This check is required so that we don't try to link
2301 * pads from elements in different bins without ghostpads.
2303 * The LOCK should be held on both pads
2306 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2308 GstObject *psrc, *psink;
2310 psrc = GST_OBJECT_PARENT (src);
2311 psink = GST_OBJECT_PARENT (sink);
2313 /* if one of the pads has no parent, we allow the link */
2314 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2317 /* only care about parents that are elements */
2318 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2319 goto no_element_parent;
2321 /* if the parents are the same, we have a loop */
2322 if (G_UNLIKELY (psrc == psink))
2325 /* if they both have a parent, we check the grandparents. We can not lock
2326 * the parent because we hold on the child (pad) and the locking order is
2327 * parent >> child. */
2328 psrc = GST_OBJECT_PARENT (psrc);
2329 psink = GST_OBJECT_PARENT (psink);
2331 /* if they have grandparents but they are not the same */
2332 if (G_UNLIKELY (psrc != psink))
2333 goto wrong_grandparents;
2340 GST_CAT_DEBUG (GST_CAT_CAPS,
2341 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2342 GST_PTR_FORMAT, psrc, psink);
2347 GST_CAT_DEBUG (GST_CAT_CAPS,
2348 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2349 GST_PTR_FORMAT, psrc, psink);
2354 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2360 GST_CAT_DEBUG (GST_CAT_CAPS,
2361 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2362 GST_PTR_FORMAT, psrc, psink);
2367 /* FIXME leftover from an attempt at refactoring... */
2368 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2369 * the two pads will be locked in the srcpad, sinkpad order. */
2370 static GstPadLinkReturn
2371 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2373 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2374 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2376 GST_OBJECT_LOCK (srcpad);
2378 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2379 goto src_was_linked;
2381 GST_OBJECT_LOCK (sinkpad);
2383 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2384 goto sink_was_linked;
2386 /* check hierarchy, pads can only be linked if the grandparents
2388 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2389 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2390 goto wrong_hierarchy;
2392 /* check pad caps for non-empty intersection */
2393 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2396 /* FIXME check pad scheduling for non-empty intersection */
2398 return GST_PAD_LINK_OK;
2402 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2403 GST_DEBUG_PAD_NAME (srcpad),
2404 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2405 /* we do not emit a warning in this case because unlinking cannot
2406 * be made MT safe.*/
2407 GST_OBJECT_UNLOCK (srcpad);
2408 return GST_PAD_LINK_WAS_LINKED;
2412 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2413 GST_DEBUG_PAD_NAME (sinkpad),
2414 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2415 /* we do not emit a warning in this case because unlinking cannot
2416 * be made MT safe.*/
2417 GST_OBJECT_UNLOCK (sinkpad);
2418 GST_OBJECT_UNLOCK (srcpad);
2419 return GST_PAD_LINK_WAS_LINKED;
2423 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2424 GST_OBJECT_UNLOCK (sinkpad);
2425 GST_OBJECT_UNLOCK (srcpad);
2426 return GST_PAD_LINK_WRONG_HIERARCHY;
2430 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2431 GST_OBJECT_UNLOCK (sinkpad);
2432 GST_OBJECT_UNLOCK (srcpad);
2433 return GST_PAD_LINK_NOFORMAT;
2439 * @srcpad: the source #GstPad.
2440 * @sinkpad: the sink #GstPad.
2442 * Checks if the source pad and the sink pad are compatible so they can be
2445 * Returns: %TRUE if the pads can be linked.
2448 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2450 GstPadLinkReturn result;
2452 /* generic checks */
2453 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2454 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2456 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2457 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2459 /* gst_pad_link_prepare does everything for us, we only release the locks
2460 * on the pads that it gets us. If this function returns !OK the locks are not
2462 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2463 if (result != GST_PAD_LINK_OK)
2466 GST_OBJECT_UNLOCK (srcpad);
2467 GST_OBJECT_UNLOCK (sinkpad);
2470 return result == GST_PAD_LINK_OK;
2474 * gst_pad_link_full:
2475 * @srcpad: the source #GstPad to link.
2476 * @sinkpad: the sink #GstPad to link.
2477 * @flags: the checks to validate when linking
2479 * Links the source pad and the sink pad.
2481 * This variant of #gst_pad_link provides a more granular control on the
2482 * checks being done when linking. While providing some considerable speedups
2483 * the caller of this method must be aware that wrong usage of those flags
2484 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2485 * for more information.
2489 * Returns: A result code indicating if the connection worked or
2493 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2495 GstPadLinkReturn result;
2497 GstPadLinkFunction srcfunc, sinkfunc;
2499 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2500 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2501 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2502 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2503 GST_PAD_LINK_WRONG_DIRECTION);
2505 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2507 /* Notify the parent early. See gst_pad_unlink for details. */
2508 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2509 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2510 gst_element_post_message (parent,
2511 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2512 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2514 gst_object_unref (parent);
2519 /* prepare will also lock the two pads */
2520 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2522 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2523 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2524 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2525 gst_pad_link_get_name (result));
2529 /* must set peers before calling the link function */
2530 GST_PAD_PEER (srcpad) = sinkpad;
2531 GST_PAD_PEER (sinkpad) = srcpad;
2533 /* check events, when something is different, mark pending */
2534 schedule_events (srcpad, sinkpad);
2536 /* get the link functions */
2537 srcfunc = GST_PAD_LINKFUNC (srcpad);
2538 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2540 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2541 /* custom link functions, execute them */
2542 GST_OBJECT_UNLOCK (sinkpad);
2543 GST_OBJECT_UNLOCK (srcpad);
2546 GstObject *tmpparent;
2548 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2549 /* this one will call the peer link function */
2550 result = srcfunc (srcpad, tmpparent, sinkpad);
2551 RELEASE_PARENT (tmpparent);
2552 } else if (sinkfunc) {
2553 GstObject *tmpparent;
2555 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2556 /* if no source link function, we need to call the sink link
2557 * function ourselves. */
2558 result = sinkfunc (sinkpad, tmpparent, srcpad);
2559 RELEASE_PARENT (tmpparent);
2563 GST_OBJECT_LOCK (srcpad);
2564 GST_OBJECT_LOCK (sinkpad);
2566 /* we released the lock, check if the same pads are linked still */
2567 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2568 goto concurrent_link;
2570 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2573 GST_OBJECT_UNLOCK (sinkpad);
2574 GST_OBJECT_UNLOCK (srcpad);
2576 /* fire off a signal to each of the pads telling them
2577 * that they've been linked */
2578 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2579 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2581 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2582 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2584 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2585 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2588 if (G_LIKELY (parent)) {
2589 gst_element_post_message (parent,
2590 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2591 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2592 gst_object_unref (parent);
2595 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2601 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2602 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2603 GST_OBJECT_UNLOCK (sinkpad);
2604 GST_OBJECT_UNLOCK (srcpad);
2606 /* The other link operation succeeded first */
2607 result = GST_PAD_LINK_WAS_LINKED;
2612 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2613 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2614 gst_pad_link_get_name (result));
2616 GST_PAD_PEER (srcpad) = NULL;
2617 GST_PAD_PEER (sinkpad) = NULL;
2619 GST_OBJECT_UNLOCK (sinkpad);
2620 GST_OBJECT_UNLOCK (srcpad);
2628 * @srcpad: the source #GstPad to link.
2629 * @sinkpad: the sink #GstPad to link.
2631 * Links the source pad and the sink pad.
2633 * Returns: A result code indicating if the connection worked or
2639 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2641 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2645 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2647 GstPadTemplate **template_p;
2649 /* this function would need checks if it weren't static */
2651 GST_OBJECT_LOCK (pad);
2652 template_p = &pad->padtemplate;
2653 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2654 GST_OBJECT_UNLOCK (pad);
2657 gst_pad_template_pad_created (templ, pad);
2661 * gst_pad_get_pad_template:
2664 * Gets the template for @pad.
2666 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2667 * this pad was instantiated, or %NULL if this pad has no
2668 * template. Unref after usage.
2671 gst_pad_get_pad_template (GstPad * pad)
2673 GstPadTemplate *templ;
2675 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2677 templ = GST_PAD_PAD_TEMPLATE (pad);
2679 return (templ ? gst_object_ref (templ) : NULL);
2683 * gst_pad_has_current_caps:
2684 * @pad: a #GstPad to check
2686 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2688 * Returns: %TRUE when @pad has caps associated with it.
2691 gst_pad_has_current_caps (GstPad * pad)
2696 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2698 GST_OBJECT_LOCK (pad);
2699 caps = get_pad_caps (pad);
2700 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2701 "check current pad caps %" GST_PTR_FORMAT, caps);
2702 result = (caps != NULL);
2703 GST_OBJECT_UNLOCK (pad);
2709 * gst_pad_get_current_caps:
2710 * @pad: a #GstPad to get the current capabilities of.
2712 * Gets the capabilities currently configured on @pad with the last
2713 * #GST_EVENT_CAPS event.
2715 * Returns: (transfer full) (nullable): the current caps of the pad with
2716 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2719 gst_pad_get_current_caps (GstPad * pad)
2723 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2725 GST_OBJECT_LOCK (pad);
2726 if ((result = get_pad_caps (pad)))
2727 gst_caps_ref (result);
2728 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2729 "get current pad caps %" GST_PTR_FORMAT, result);
2730 GST_OBJECT_UNLOCK (pad);
2736 * gst_pad_get_pad_template_caps:
2737 * @pad: a #GstPad to get the template capabilities from.
2739 * Gets the capabilities for @pad's template.
2741 * Returns: (transfer full): the #GstCaps of this pad template.
2742 * Unref after usage.
2745 gst_pad_get_pad_template_caps (GstPad * pad)
2747 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2749 if (GST_PAD_PAD_TEMPLATE (pad))
2750 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2752 return gst_caps_ref (GST_CAPS_ANY);
2757 * @pad: a #GstPad to get the peer of.
2759 * Gets the peer of @pad. This function refs the peer pad so
2760 * you need to unref it after use.
2762 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2767 gst_pad_get_peer (GstPad * pad)
2771 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2773 GST_OBJECT_LOCK (pad);
2774 result = GST_PAD_PEER (pad);
2776 gst_object_ref (result);
2777 GST_OBJECT_UNLOCK (pad);
2783 * gst_pad_get_allowed_caps:
2786 * Gets the capabilities of the allowed media types that can flow through
2787 * @pad and its peer.
2789 * The allowed capabilities is calculated as the intersection of the results of
2790 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2791 * on the resulting caps.
2793 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2794 * pad link. Unref the caps when you no longer need it. This
2795 * function returns %NULL when @pad has no peer.
2800 gst_pad_get_allowed_caps (GstPad * pad)
2803 GstCaps *caps = NULL;
2806 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2808 GST_OBJECT_LOCK (pad);
2809 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2811 GST_OBJECT_UNLOCK (pad);
2813 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2815 mycaps = gst_pad_query_caps (pad, NULL);
2817 /* Query peer caps */
2818 query = gst_query_new_caps (mycaps);
2819 if (!gst_pad_peer_query (pad, query)) {
2820 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2824 gst_query_parse_caps_result (query, &caps);
2826 g_warn_if_fail (caps != NULL);
2829 gst_caps_ref (caps);
2831 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2835 gst_query_unref (query);
2836 gst_caps_unref (mycaps);
2842 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2843 GST_OBJECT_UNLOCK (pad);
2850 * gst_pad_iterate_internal_links_default:
2851 * @pad: the #GstPad to get the internal links of.
2852 * @parent: (allow-none): the parent of @pad or %NULL
2854 * Iterate the list of pads to which the given pad is linked to inside of
2855 * the parent element.
2856 * This is the default handler, and thus returns an iterator of all of the
2857 * pads inside the parent element with opposite direction.
2859 * The caller must free this iterator after use with gst_iterator_free().
2861 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2862 * has no parent. Unref each returned pad with gst_object_unref().
2865 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2872 GstElement *eparent;
2874 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2876 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2877 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2879 GST_OBJECT_LOCK (pad);
2880 eparent = GST_PAD_PARENT (pad);
2881 if (!eparent || !GST_IS_ELEMENT (eparent))
2884 gst_object_ref (eparent);
2885 GST_OBJECT_UNLOCK (pad);
2888 if (pad->direction == GST_PAD_SRC)
2889 padlist = &eparent->sinkpads;
2891 padlist = &eparent->srcpads;
2893 GST_DEBUG_OBJECT (pad, "Making iterator");
2895 cookie = &eparent->pads_cookie;
2897 lock = GST_OBJECT_GET_LOCK (eparent);
2899 res = gst_iterator_new_list (GST_TYPE_PAD,
2900 lock, cookie, padlist, (GObject *) owner, NULL);
2902 gst_object_unref (owner);
2909 GST_OBJECT_UNLOCK (pad);
2910 GST_DEBUG_OBJECT (pad, "no parent element");
2916 * gst_pad_iterate_internal_links:
2917 * @pad: the GstPad to get the internal links of.
2919 * Gets an iterator for the pads to which the given pad is linked to inside
2920 * of the parent element.
2922 * Each #GstPad element yielded by the iterator will have its refcount increased,
2923 * so unref after use.
2925 * Free-function: gst_iterator_free
2927 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2928 * or %NULL when the pad does not have an iterator function
2929 * configured. Use gst_iterator_free() after usage.
2932 gst_pad_iterate_internal_links (GstPad * pad)
2934 GstIterator *res = NULL;
2937 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2939 GST_OBJECT_LOCK (pad);
2940 ACQUIRE_PARENT (pad, parent, no_parent);
2941 GST_OBJECT_UNLOCK (pad);
2943 if (GST_PAD_ITERINTLINKFUNC (pad))
2944 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2946 RELEASE_PARENT (parent);
2953 GST_DEBUG_OBJECT (pad, "no parent");
2954 GST_OBJECT_UNLOCK (pad);
2962 * @forward: (scope call): a #GstPadForwardFunction
2963 * @user_data: user data passed to @forward
2965 * Calls @forward for all internally linked pads of @pad. This function deals with
2966 * dynamically changing internal pads and will make sure that the @forward
2967 * function is only called once for each pad.
2969 * When @forward returns %TRUE, no further pads will be processed.
2971 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2974 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2977 gboolean result = FALSE;
2979 gboolean done = FALSE;
2980 GValue item = { 0, };
2981 GList *pushed_pads = NULL;
2983 iter = gst_pad_iterate_internal_links (pad);
2989 switch (gst_iterator_next (iter, &item)) {
2990 case GST_ITERATOR_OK:
2994 intpad = g_value_get_object (&item);
2996 /* if already pushed, skip. FIXME, find something faster to tag pads */
2997 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2998 g_value_reset (&item);
3002 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3003 GST_DEBUG_PAD_NAME (intpad));
3004 done = result = forward (intpad, user_data);
3006 pushed_pads = g_list_prepend (pushed_pads, intpad);
3008 g_value_reset (&item);
3011 case GST_ITERATOR_RESYNC:
3012 /* We don't reset the result here because we don't push the event
3013 * again on pads that got the event already and because we need
3014 * to consider the result of the previous pushes */
3015 gst_iterator_resync (iter);
3017 case GST_ITERATOR_ERROR:
3018 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3021 case GST_ITERATOR_DONE:
3026 g_value_unset (&item);
3027 gst_iterator_free (iter);
3029 g_list_free (pushed_pads);
3039 gboolean dispatched;
3043 event_forward_func (GstPad * pad, EventData * data)
3045 /* for each pad we send to, we should ref the event; it's up
3046 * to downstream to unref again when handled. */
3047 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3048 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3050 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3052 data->dispatched = TRUE;
3059 * gst_pad_event_default:
3060 * @pad: a #GstPad to call the default event handler on.
3061 * @parent: (allow-none): the parent of @pad or %NULL
3062 * @event: (transfer full): the #GstEvent to handle.
3064 * Invokes the default event handler for the given pad.
3066 * The EOS event will pause the task associated with @pad before it is forwarded
3067 * to all internally linked pads,
3069 * The event is sent to all pads internally linked to @pad. This function
3070 * takes ownership of @event.
3072 * Returns: %TRUE if the event was sent successfully.
3075 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3077 gboolean result, forward = TRUE;
3079 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3080 g_return_val_if_fail (event != NULL, FALSE);
3082 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3085 switch (GST_EVENT_TYPE (event)) {
3086 case GST_EVENT_CAPS:
3087 forward = GST_PAD_IS_PROXY_CAPS (pad);
3098 data.dispatched = FALSE;
3099 data.result = FALSE;
3101 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3103 /* for sinkpads without a parent element or without internal links, nothing
3104 * will be dispatched but we still want to return TRUE. */
3105 if (data.dispatched)
3106 result = data.result;
3111 gst_event_unref (event);
3116 /* Default accept caps implementation just checks against
3117 * the allowed caps for the pad */
3119 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3121 /* get the caps and see if it intersects to something not empty */
3122 GstCaps *caps, *allowed = NULL;
3125 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3127 /* first forward the query to internally linked pads when we are dealing with
3129 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3130 result = gst_pad_proxy_query_accept_caps (pad, query);
3132 allowed = gst_pad_get_pad_template_caps (pad);
3137 gst_query_parse_accept_caps (query, &caps);
3139 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3140 allowed = gst_pad_get_pad_template_caps (pad);
3142 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3143 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3144 allowed = gst_pad_query_caps (pad, caps);
3149 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3150 GST_DEBUG_OBJECT (pad,
3151 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3153 result = gst_caps_can_intersect (caps, allowed);
3155 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3156 GST_PTR_FORMAT, allowed, caps);
3157 result = gst_caps_is_subset (caps, allowed);
3159 gst_caps_unref (allowed);
3161 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3164 gst_query_set_accept_caps_result (query, result);
3170 /* Default caps implementation */
3172 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3174 GstCaps *result = NULL, *filter;
3175 GstPadTemplate *templ;
3176 gboolean fixed_caps;
3178 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3181 /* first try to proxy if we must */
3182 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3183 if ((gst_pad_proxy_query_caps (pad, query))) {
3188 gst_query_parse_caps (query, &filter);
3190 /* no proxy or it failed, do default handling */
3191 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3193 GST_OBJECT_LOCK (pad);
3195 /* fixed caps, try the negotiated caps first */
3196 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3197 if ((result = get_pad_caps (pad)))
3198 goto filter_done_unlock;
3201 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3202 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3203 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3204 goto filter_done_unlock;
3208 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3209 "non-fixed pad caps: trying pad caps");
3210 /* non fixed caps, try the negotiated caps */
3211 if ((result = get_pad_caps (pad)))
3212 goto filter_done_unlock;
3215 /* this almost never happens */
3216 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3217 result = GST_CAPS_ANY;
3220 GST_OBJECT_UNLOCK (pad);
3222 /* run the filter on the result */
3224 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3225 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3226 GST_PTR_FORMAT, result, result, filter, filter);
3227 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3231 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3232 "using caps %p %" GST_PTR_FORMAT, result, result);
3233 result = gst_caps_ref (result);
3235 gst_query_set_caps_result (query, result);
3236 gst_caps_unref (result);
3242 /* Default latency implementation */
3246 GstClockTime min, max;
3250 query_latency_default_fold (const GValue * item, GValue * ret,
3253 GstPad *pad = g_value_get_object (item), *peer;
3254 LatencyFoldData *fold_data = user_data;
3256 gboolean res = FALSE;
3258 query = gst_query_new_latency ();
3260 peer = gst_pad_get_peer (pad);
3262 res = gst_pad_peer_query (pad, query);
3264 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3269 GstClockTime min, max;
3271 gst_query_parse_latency (query, &live, &min, &max);
3273 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3274 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3277 if (min > fold_data->min)
3278 fold_data->min = min;
3280 if (fold_data->max == GST_CLOCK_TIME_NONE)
3281 fold_data->max = max;
3282 else if (max < fold_data->max)
3283 fold_data->max = max;
3285 fold_data->live = TRUE;
3288 GST_DEBUG_OBJECT (pad, "latency query failed");
3289 g_value_set_boolean (ret, FALSE);
3292 gst_query_unref (query);
3294 gst_object_unref (peer);
3300 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3303 GstIteratorResult res;
3304 GValue ret = G_VALUE_INIT;
3306 LatencyFoldData fold_data;
3308 it = gst_pad_iterate_internal_links (pad);
3310 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3314 g_value_init (&ret, G_TYPE_BOOLEAN);
3317 fold_data.live = FALSE;
3319 fold_data.max = GST_CLOCK_TIME_NONE;
3321 g_value_set_boolean (&ret, TRUE);
3322 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3324 case GST_ITERATOR_OK:
3325 g_assert_not_reached ();
3327 case GST_ITERATOR_DONE:
3329 case GST_ITERATOR_ERROR:
3330 g_value_set_boolean (&ret, FALSE);
3332 case GST_ITERATOR_RESYNC:
3333 gst_iterator_resync (it);
3336 g_assert_not_reached ();
3339 gst_iterator_free (it);
3341 query_ret = g_value_get_boolean (&ret);
3343 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3344 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3345 fold_data.min, fold_data.max);
3347 if (fold_data.min > fold_data.max) {
3348 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3351 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3353 GST_LOG_OBJECT (pad, "latency query failed");
3363 gboolean dispatched;
3367 query_forward_func (GstPad * pad, QueryData * data)
3369 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3370 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3372 data->result |= gst_pad_peer_query (pad, data->query);
3374 data->dispatched = TRUE;
3376 /* stop on first successful reply */
3377 return data->result;
3381 * gst_pad_query_default:
3382 * @pad: a #GstPad to call the default query handler on.
3383 * @parent: (allow-none): the parent of @pad or %NULL
3384 * @query: (transfer none): the #GstQuery to handle.
3386 * Invokes the default query handler for the given pad.
3387 * The query is sent to all pads internally linked to @pad. Note that
3388 * if there are many possible sink pads that are internally linked to
3389 * @pad, only one will be sent the query.
3390 * Multi-sinkpad elements should implement custom query handlers.
3392 * Returns: %TRUE if the query was performed successfully.
3395 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3397 gboolean forward, ret = FALSE;
3399 switch (GST_QUERY_TYPE (query)) {
3400 case GST_QUERY_SCHEDULING:
3401 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3403 case GST_QUERY_ALLOCATION:
3404 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3406 case GST_QUERY_ACCEPT_CAPS:
3407 ret = gst_pad_query_accept_caps_default (pad, query);
3410 case GST_QUERY_CAPS:
3411 ret = gst_pad_query_caps_default (pad, query);
3414 case GST_QUERY_LATENCY:
3415 ret = gst_pad_query_latency_default (pad, query);
3418 case GST_QUERY_POSITION:
3419 case GST_QUERY_SEEKING:
3420 case GST_QUERY_FORMATS:
3421 case GST_QUERY_JITTER:
3422 case GST_QUERY_RATE:
3423 case GST_QUERY_CONVERT:
3429 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3430 query, GST_QUERY_TYPE_NAME (query));
3436 data.dispatched = FALSE;
3437 data.result = FALSE;
3439 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3441 if (data.dispatched) {
3444 /* nothing dispatched, assume drained */
3445 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3454 #define N_STACK_ALLOCATE_PROBES (16)
3457 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3459 GstPad *pad = data->pad;
3460 GstPadProbeInfo *info = data->info;
3461 GstPadProbeType type, flags;
3462 GstPadProbeCallback callback;
3463 GstPadProbeReturn ret;
3464 gpointer original_data;
3467 /* if we have called this callback, do nothing. But only check
3468 * if we're actually calling probes a second time */
3470 for (i = 0; i < data->n_called_probes; i++) {
3471 if (data->called_probes[i] == hook->hook_id) {
3472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3473 "hook %lu already called", hook->hook_id);
3479 /* reallocate on the heap if we had more than 16 probes */
3480 if (data->n_called_probes == data->called_probes_size) {
3481 if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
3482 data->called_probes_size *= 2;
3483 data->called_probes =
3484 g_renew (gulong, data->called_probes, data->called_probes_size);
3486 gulong *tmp = data->called_probes;
3488 data->called_probes_size *= 2;
3489 data->called_probes = g_new (gulong, data->called_probes_size);
3490 memcpy (data->called_probes, tmp,
3491 N_STACK_ALLOCATE_PROBES * sizeof (gulong));
3494 data->called_probes[data->n_called_probes++] = hook->hook_id;
3496 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3498 original_data = info->data;
3500 /* one of the scheduling types */
3501 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3504 if (G_UNLIKELY (data->handled)) {
3505 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3506 "probe previously returned HANDLED, not calling again");
3508 } else if (G_UNLIKELY (data->dropped)) {
3509 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3510 "probe previously returned DROPPED, not calling again");
3514 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3515 /* one of the data types for non-idle probes */
3516 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3517 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3519 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3520 /* one of the data types for non-idle probes */
3521 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3522 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3525 /* Type must have PULL or PUSH probe types */
3526 g_assert_not_reached ();
3529 /* one of the blocking types must match */
3530 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3531 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3533 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3534 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3536 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3537 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3538 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3541 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3542 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3544 data->marshalled = TRUE;
3546 callback = (GstPadProbeCallback) hook->func;
3547 if (callback == NULL)
3550 info->id = hook->hook_id;
3552 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3553 pad->priv->idle_running++;
3555 GST_OBJECT_UNLOCK (pad);
3557 ret = callback (pad, info, hook->data);
3559 GST_OBJECT_LOCK (pad);
3561 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3562 pad->priv->idle_running--;
3564 if (original_data != NULL && info->data == NULL) {
3565 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3566 info->type = GST_PAD_PROBE_TYPE_INVALID;
3567 data->dropped = TRUE;
3571 case GST_PAD_PROBE_REMOVE:
3572 /* remove the probe */
3573 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3574 cleanup_hook (pad, hook);
3576 case GST_PAD_PROBE_DROP:
3577 /* need to drop the data, make sure other probes don't get called
3579 GST_DEBUG_OBJECT (pad, "asked to drop item");
3580 info->type = GST_PAD_PROBE_TYPE_INVALID;
3581 data->dropped = TRUE;
3583 case GST_PAD_PROBE_HANDLED:
3584 GST_DEBUG_OBJECT (pad, "probe handled data");
3585 data->handled = TRUE;
3587 case GST_PAD_PROBE_PASS:
3588 /* inform the pad block to let things pass */
3589 GST_DEBUG_OBJECT (pad, "asked to pass item");
3592 case GST_PAD_PROBE_OK:
3593 GST_DEBUG_OBJECT (pad, "probe returned OK");
3596 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3603 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3604 "hook %lu with flags 0x%08x does not match %08x",
3605 hook->hook_id, flags, info->type);
3610 /* a probe that does not take or return any data */
3611 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3613 if (G_UNLIKELY (pad->num_probes)) { \
3614 GstFlowReturn pval = defaultval; \
3615 /* pass NULL as the data item */ \
3616 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3617 info.ABI.abi.flow_ret = defaultval; \
3618 ret = do_probe_callbacks (pad, &info, defaultval); \
3619 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3624 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3626 if (G_UNLIKELY (pad->num_probes)) { \
3627 /* pass the data item */ \
3628 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3629 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3630 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3631 /* store the possibly updated data item */ \
3632 data = GST_PAD_PROBE_INFO_DATA (&info); \
3633 /* if something went wrong, exit */ \
3634 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3635 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3636 ret = info.ABI.abi.flow_ret; \
3637 goto handle_label; \
3644 #define PROBE_PUSH(pad,mask,data,label) \
3645 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3646 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3647 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3648 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3649 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3651 static GstFlowReturn
3652 do_pad_idle_probe_wait (GstPad * pad)
3654 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3655 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3656 "waiting idle probe to be removed");
3657 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3658 GST_PAD_BLOCK_WAIT (pad);
3659 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3660 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3662 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3663 return GST_FLOW_FLUSHING;
3668 #define PROBE_TYPE_IS_SERIALIZED(i) \
3671 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3672 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3673 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3675 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3676 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3678 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3679 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3683 static GstFlowReturn
3684 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3685 GstFlowReturn defaultval)
3690 gulong called_probes[N_STACK_ALLOCATE_PROBES];
3695 data.handled = FALSE;
3696 data.marshalled = FALSE;
3697 data.dropped = FALSE;
3699 /* We stack-allocate for N_STACK_ALLOCATE_PROBES hooks as a first step. If more are needed,
3700 * we will re-allocate with g_malloc(). This should usually never be needed
3702 data.called_probes = called_probes;
3703 data.n_called_probes = 0;
3704 data.called_probes_size = N_STACK_ALLOCATE_PROBES;
3708 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3710 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3711 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3716 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "do probes");
3717 cookie = pad->priv->probe_list_cookie;
3719 g_hook_list_marshal (&pad->probes, TRUE,
3720 (GHookMarshaller) probe_hook_marshal, &data);
3722 /* if the list changed, call the new callbacks (they will not be in
3723 * called_probes yet) */
3724 if (cookie != pad->priv->probe_list_cookie) {
3725 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3726 "probe list changed, restarting");
3731 /* the first item that dropped will stop the hooks and then we drop here */
3735 /* If one handler took care of it, let the the item pass */
3740 /* if no handler matched and we are blocking, let the item pass */
3741 if (!data.marshalled && is_block)
3744 /* At this point, all handlers returned either OK or PASS. If one handler
3745 * returned PASS, let the item pass */
3750 while (GST_PAD_IS_BLOCKED (pad)) {
3751 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3752 "we are blocked %d times", pad->num_blocked);
3754 /* we might have released the lock */
3755 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3758 /* now we block the streaming thread. It can be unlocked when we
3759 * deactivate the pad (which will also set the FLUSHING flag) or
3760 * when the pad is unblocked. A flushing event will also unblock
3761 * the pad after setting the FLUSHING flag. */
3762 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3763 "Waiting to be unblocked or set flushing");
3764 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3765 GST_PAD_BLOCK_WAIT (pad);
3766 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3767 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3769 /* if the list changed, call the new callbacks (they will not be in
3770 * called_probes yet) */
3771 if (cookie != pad->priv->probe_list_cookie) {
3772 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3773 "probe list changed, restarting");
3778 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3783 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3784 g_free (data.called_probes);
3791 GST_DEBUG_OBJECT (pad, "pad is flushing");
3792 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3793 g_free (data.called_probes);
3794 return GST_FLOW_FLUSHING;
3798 GST_DEBUG_OBJECT (pad, "data is dropped");
3799 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3800 g_free (data.called_probes);
3801 return GST_FLOW_CUSTOM_SUCCESS;
3805 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3806 GST_DEBUG_OBJECT (pad, "data is passed");
3807 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3808 g_free (data.called_probes);
3813 GST_DEBUG_OBJECT (pad, "data was handled");
3814 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3815 g_free (data.called_probes);
3816 return GST_FLOW_CUSTOM_SUCCESS_1;
3823 * gst_pad_get_offset:
3826 * Get the offset applied to the running time of @pad. @pad has to be a source
3829 * Returns: the offset.
3832 gst_pad_get_offset (GstPad * pad)
3836 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3838 GST_OBJECT_LOCK (pad);
3839 result = pad->offset;
3840 GST_OBJECT_UNLOCK (pad);
3846 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3848 ev->received = FALSE;
3853 * gst_pad_set_offset:
3855 * @offset: the offset
3857 * Set the offset that will be applied to the running time of @pad.
3860 gst_pad_set_offset (GstPad * pad, gint64 offset)
3862 g_return_if_fail (GST_IS_PAD (pad));
3864 GST_OBJECT_LOCK (pad);
3865 /* if nothing changed, do nothing */
3866 if (pad->offset == offset)
3869 pad->offset = offset;
3870 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3871 GST_STIME_ARGS (offset));
3873 /* resend all sticky events with updated offset on next buffer push */
3874 events_foreach (pad, mark_event_not_received, NULL);
3875 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3878 GST_OBJECT_UNLOCK (pad);
3885 /* If TRUE and ret is not OK this means
3886 * that pushing the EOS event failed
3890 /* If called for an event this is
3891 * the event that would be pushed
3892 * next. Don't forward sticky events
3893 * that would come after that */
3897 /* should be called with pad LOCK */
3899 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3901 PushStickyData *data = user_data;
3902 GstEvent *event = ev->event;
3905 GST_DEBUG_OBJECT (pad, "event %s was already received",
3906 GST_EVENT_TYPE_NAME (event));
3910 /* If we're called because of an sticky event, only forward
3911 * events that would come before this new event and the
3913 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3914 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3915 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3916 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3918 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3919 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3920 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3921 data->ret = GST_FLOW_OK;
3924 switch (data->ret) {
3926 ev->received = TRUE;
3927 GST_DEBUG_OBJECT (pad, "event %s marked received",
3928 GST_EVENT_TYPE_NAME (event));
3930 case GST_FLOW_CUSTOM_SUCCESS:
3931 /* we can't assume the event is received when it was dropped */
3932 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3933 GST_EVENT_TYPE_NAME (event));
3934 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3935 data->ret = GST_FLOW_OK;
3937 case GST_FLOW_CUSTOM_SUCCESS_1:
3938 /* event was ignored and should be sent later */
3939 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3940 GST_EVENT_TYPE_NAME (event));
3941 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3942 data->ret = GST_FLOW_OK;
3944 case GST_FLOW_NOT_LINKED:
3945 /* not linked is not a problem, we are sticky so the event will be
3946 * rescheduled to be sent later on re-link, but only for non-EOS events */
3947 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3948 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3949 data->ret = GST_FLOW_OK;
3950 ev->received = TRUE;
3954 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3955 gst_flow_get_name (data->ret));
3956 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3960 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3961 data->was_eos = TRUE;
3963 return data->ret == GST_FLOW_OK;
3966 /* check sticky events and push them when needed. should be called
3968 static inline GstFlowReturn
3969 check_sticky (GstPad * pad, GstEvent * event)
3971 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3973 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3974 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3976 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3977 events_foreach (pad, push_sticky, &data);
3979 /* If there's an EOS event we must push it downstream
3980 * even if sending a previous sticky event failed.
3981 * Otherwise the pipeline might wait forever for EOS.
3983 * Only do this if pushing another event than the EOS
3986 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3987 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3989 if (ev && !ev->received) {
3990 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3991 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3992 /* the event could have been dropped. Because this can only
3993 * happen if the user asked for it, it's not an error */
3994 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3995 data.ret = GST_FLOW_OK;
4005 * @pad: a #GstPad to invoke the default query on.
4006 * @query: (transfer none): the #GstQuery to perform.
4008 * Dispatches a query to a pad. The query should have been allocated by the
4009 * caller via one of the type-specific allocation functions. The element that
4010 * the pad belongs to is responsible for filling the query with an appropriate
4011 * response, which should then be parsed with a type-specific query parsing
4014 * Again, the caller is responsible for both the allocation and deallocation of
4015 * the query structure.
4017 * Please also note that some queries might need a running pipeline to work.
4019 * Returns: %TRUE if the query could be performed.
4022 gst_pad_query (GstPad * pad, GstQuery * query)
4025 gboolean res, serialized;
4026 GstPadQueryFunction func;
4027 GstPadProbeType type;
4030 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4031 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4033 if (GST_PAD_IS_SRC (pad)) {
4034 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4035 goto wrong_direction;
4036 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4037 } else if (GST_PAD_IS_SINK (pad)) {
4038 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4039 goto wrong_direction;
4040 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4042 goto unknown_direction;
4044 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4045 GST_QUERY_TYPE_NAME (query));
4046 GST_TRACER_PAD_QUERY_PRE (pad, query);
4048 serialized = GST_QUERY_IS_SERIALIZED (query);
4049 if (G_UNLIKELY (serialized))
4050 GST_PAD_STREAM_LOCK (pad);
4052 GST_OBJECT_LOCK (pad);
4053 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4054 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4055 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4057 ACQUIRE_PARENT (pad, parent, no_parent);
4058 GST_OBJECT_UNLOCK (pad);
4060 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4063 res = func (pad, parent, query);
4065 RELEASE_PARENT (parent);
4067 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4068 GST_QUERY_TYPE_NAME (query), res);
4069 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4074 GST_OBJECT_LOCK (pad);
4075 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4076 GST_OBJECT_UNLOCK (pad);
4078 if (G_UNLIKELY (serialized))
4079 GST_PAD_STREAM_UNLOCK (pad);
4086 g_warning ("pad %s:%s query %s in wrong direction",
4087 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4092 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4097 GST_DEBUG_OBJECT (pad, "had no parent");
4098 GST_OBJECT_UNLOCK (pad);
4099 if (G_UNLIKELY (serialized))
4100 GST_PAD_STREAM_UNLOCK (pad);
4105 GST_DEBUG_OBJECT (pad, "had no query function");
4106 RELEASE_PARENT (parent);
4107 if (G_UNLIKELY (serialized))
4108 GST_PAD_STREAM_UNLOCK (pad);
4113 GST_DEBUG_OBJECT (pad, "query failed");
4114 if (G_UNLIKELY (serialized))
4115 GST_PAD_STREAM_UNLOCK (pad);
4120 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4121 GST_OBJECT_UNLOCK (pad);
4122 if (G_UNLIKELY (serialized))
4123 GST_PAD_STREAM_UNLOCK (pad);
4125 /* if a probe dropped without handling, we don't sent it further but assume
4126 * that the probe did not answer the query and return FALSE */
4127 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4137 * gst_pad_peer_query:
4138 * @pad: a #GstPad to invoke the peer query on.
4139 * @query: (transfer none): the #GstQuery to perform.
4141 * Performs gst_pad_query() on the peer of @pad.
4143 * The caller is responsible for both the allocation and deallocation of
4144 * the query structure.
4146 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4147 * if @pad has no peer.
4150 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4153 GstPadProbeType type;
4154 gboolean res, serialized;
4157 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4158 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4160 if (GST_PAD_IS_SRC (pad)) {
4161 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4162 goto wrong_direction;
4163 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4164 } else if (GST_PAD_IS_SINK (pad)) {
4165 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4166 goto wrong_direction;
4167 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4169 goto unknown_direction;
4171 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4172 GST_QUERY_TYPE_NAME (query));
4174 serialized = GST_QUERY_IS_SERIALIZED (query);
4176 GST_OBJECT_LOCK (pad);
4177 if (GST_PAD_IS_SRC (pad) && serialized) {
4178 /* all serialized queries on the srcpad trigger push of
4180 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4184 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4185 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4186 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4188 peerpad = GST_PAD_PEER (pad);
4189 if (G_UNLIKELY (peerpad == NULL))
4192 gst_object_ref (peerpad);
4193 GST_OBJECT_UNLOCK (pad);
4195 res = gst_pad_query (peerpad, query);
4197 gst_object_unref (peerpad);
4202 GST_OBJECT_LOCK (pad);
4203 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4204 GST_OBJECT_UNLOCK (pad);
4211 g_warning ("pad %s:%s query %s in wrong direction",
4212 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4217 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4222 GST_WARNING_OBJECT (pad, "could not send sticky events");
4223 GST_OBJECT_UNLOCK (pad);
4228 GST_INFO_OBJECT (pad, "pad has no peer");
4229 GST_OBJECT_UNLOCK (pad);
4234 GST_DEBUG_OBJECT (pad, "query failed");
4239 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4240 GST_OBJECT_UNLOCK (pad);
4242 /* if a probe dropped without handling, we don't sent it further but
4243 * assume that the probe did not answer the query and return FALSE */
4244 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4253 /**********************************************************************
4254 * Data passing functions
4257 /* this is the chain function that does not perform the additional argument
4258 * checking for that little extra speed.
4260 static inline GstFlowReturn
4261 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4265 gboolean handled = FALSE;
4267 GST_PAD_STREAM_LOCK (pad);
4269 GST_OBJECT_LOCK (pad);
4270 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4273 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4276 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4279 #ifdef GST_ENABLE_EXTRA_CHECKS
4280 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4281 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4283 ":%s:<%s:%s> Got data flow before stream-start event",
4284 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4286 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4288 ":%s:<%s:%s> Got data flow before segment event",
4289 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4291 pad->priv->last_cookie = pad->priv->events_cookie;
4295 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4298 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4300 ACQUIRE_PARENT (pad, parent, no_parent);
4301 GST_OBJECT_UNLOCK (pad);
4303 /* NOTE: we read the chainfunc unlocked.
4304 * we cannot hold the lock for the pad so we might send
4305 * the data to the wrong function. This is not really a
4306 * problem since functions are assigned at creation time
4307 * and don't change that often... */
4308 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4309 GstPadChainFunction chainfunc;
4311 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4314 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4315 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4316 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4318 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4320 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4321 "called chainfunction &%s with buffer %p, returned %s",
4322 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4324 GstPadChainListFunction chainlistfunc;
4326 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4329 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4330 "calling chainlistfunction &%s",
4331 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4333 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4335 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4336 "called chainlistfunction &%s, returned %s",
4337 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4340 RELEASE_PARENT (parent);
4342 GST_PAD_STREAM_UNLOCK (pad);
4349 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4350 "chaining, but pad was flushing");
4351 GST_OBJECT_UNLOCK (pad);
4352 GST_PAD_STREAM_UNLOCK (pad);
4353 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4354 return GST_FLOW_FLUSHING;
4358 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4359 GST_OBJECT_UNLOCK (pad);
4360 GST_PAD_STREAM_UNLOCK (pad);
4361 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4362 return GST_FLOW_EOS;
4366 g_critical ("chain on pad %s:%s but it was not in push mode",
4367 GST_DEBUG_PAD_NAME (pad));
4368 GST_OBJECT_UNLOCK (pad);
4369 GST_PAD_STREAM_UNLOCK (pad);
4370 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4371 return GST_FLOW_ERROR;
4378 GST_OBJECT_UNLOCK (pad);
4379 GST_PAD_STREAM_UNLOCK (pad);
4380 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4382 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4385 case GST_FLOW_CUSTOM_SUCCESS:
4386 case GST_FLOW_CUSTOM_SUCCESS_1:
4387 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4391 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4398 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4399 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4400 GST_OBJECT_UNLOCK (pad);
4401 GST_PAD_STREAM_UNLOCK (pad);
4402 return GST_FLOW_FLUSHING;
4406 RELEASE_PARENT (parent);
4407 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4408 g_critical ("chain on pad %s:%s but it has no chainfunction",
4409 GST_DEBUG_PAD_NAME (pad));
4410 GST_PAD_STREAM_UNLOCK (pad);
4411 return GST_FLOW_NOT_SUPPORTED;
4417 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4418 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4421 * Chain a buffer to @pad.
4423 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4425 * If the buffer type is not acceptable for @pad (as negotiated with a
4426 * preceding GST_EVENT_CAPS event), this function returns
4427 * #GST_FLOW_NOT_NEGOTIATED.
4429 * The function proceeds calling the chain function installed on @pad (see
4430 * gst_pad_set_chain_function()) and the return value of that function is
4431 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4434 * In all cases, success or failure, the caller loses its reference to @buffer
4435 * after calling this function.
4437 * Returns: a #GstFlowReturn from the pad.
4442 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4444 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4445 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4446 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4448 return gst_pad_chain_data_unchecked (pad,
4449 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4452 static GstFlowReturn
4453 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4454 GstBufferList * list)
4460 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4462 len = gst_buffer_list_length (list);
4465 for (i = 0; i < len; i++) {
4466 buffer = gst_buffer_list_get (list, i);
4468 gst_pad_chain_data_unchecked (pad,
4469 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4470 gst_buffer_ref (buffer));
4471 if (ret != GST_FLOW_OK)
4474 gst_buffer_list_unref (list);
4480 * gst_pad_chain_list:
4481 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4482 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4485 * Chain a bufferlist to @pad.
4487 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4489 * If @pad was not negotiated properly with a CAPS event, this function
4490 * returns #GST_FLOW_NOT_NEGOTIATED.
4492 * The function proceeds calling the chainlist function installed on @pad (see
4493 * gst_pad_set_chain_list_function()) and the return value of that function is
4494 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4495 * chainlist function.
4497 * In all cases, success or failure, the caller loses its reference to @list
4498 * after calling this function.
4502 * Returns: a #GstFlowReturn from the pad.
4505 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4507 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4508 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4509 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4511 return gst_pad_chain_data_unchecked (pad,
4512 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4515 static GstFlowReturn
4516 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4520 gboolean handled = FALSE;
4522 GST_OBJECT_LOCK (pad);
4523 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4526 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4529 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4532 #ifdef GST_ENABLE_EXTRA_CHECKS
4533 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4534 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4536 ":%s:<%s:%s> Got data flow before stream-start event",
4537 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4539 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4541 ":%s:<%s:%s> Got data flow before segment event",
4542 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4544 pad->priv->last_cookie = pad->priv->events_cookie;
4548 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4551 /* do block probes */
4552 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4555 /* recheck sticky events because the probe might have cause a relink */
4556 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4559 /* do post-blocking probes */
4560 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4562 /* recheck sticky events because the probe might have cause a relink */
4563 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4566 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4569 /* take ref to peer pad before releasing the lock */
4570 gst_object_ref (peer);
4572 GST_OBJECT_UNLOCK (pad);
4574 ret = gst_pad_chain_data_unchecked (peer, type, data);
4577 gst_object_unref (peer);
4579 GST_OBJECT_LOCK (pad);
4580 pad->ABI.abi.last_flowret = ret;
4582 if (pad->priv->using == 0) {
4583 /* pad is not active anymore, trigger idle callbacks */
4584 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4585 probe_stopped, ret);
4587 GST_OBJECT_UNLOCK (pad);
4591 /* ERROR recovery here */
4595 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4596 "pushing, but pad was flushing");
4597 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4598 GST_OBJECT_UNLOCK (pad);
4599 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4600 return GST_FLOW_FLUSHING;
4604 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4605 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4606 GST_OBJECT_UNLOCK (pad);
4607 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4608 return GST_FLOW_EOS;
4612 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4613 GST_DEBUG_PAD_NAME (pad));
4614 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4615 GST_OBJECT_UNLOCK (pad);
4616 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4617 return GST_FLOW_ERROR;
4621 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4622 "error pushing events, return %s", gst_flow_get_name (ret));
4623 pad->ABI.abi.last_flowret = ret;
4624 GST_OBJECT_UNLOCK (pad);
4625 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4633 GST_OBJECT_UNLOCK (pad);
4634 if (data != NULL && !handled)
4635 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4638 case GST_FLOW_CUSTOM_SUCCESS:
4639 case GST_FLOW_CUSTOM_SUCCESS_1:
4640 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4644 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4647 pad->ABI.abi.last_flowret = ret;
4652 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4653 "pushing, but it was not linked");
4654 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4655 GST_OBJECT_UNLOCK (pad);
4656 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4657 return GST_FLOW_NOT_LINKED;
4663 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4664 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4667 * Pushes a buffer to the peer of @pad.
4669 * This function will call installed block probes before triggering any
4670 * installed data probes.
4672 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4673 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4676 * In all cases, success or failure, the caller loses its reference to @buffer
4677 * after calling this function.
4679 * Returns: a #GstFlowReturn from the peer pad.
4684 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4688 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4689 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4690 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4692 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4693 res = gst_pad_push_data (pad,
4694 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4695 GST_TRACER_PAD_PUSH_POST (pad, res);
4700 * gst_pad_push_list:
4701 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4702 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4705 * Pushes a buffer list to the peer of @pad.
4707 * This function will call installed block probes before triggering any
4708 * installed data probes.
4710 * The function proceeds calling the chain function on the peer pad and returns
4711 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4712 * be returned. If the peer pad does not have any installed chainlist function
4713 * every group buffer of the list will be merged into a normal #GstBuffer and
4714 * chained via gst_pad_chain().
4716 * In all cases, success or failure, the caller loses its reference to @list
4717 * after calling this function.
4719 * Returns: a #GstFlowReturn from the peer pad.
4724 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4728 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4729 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4730 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4732 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4733 res = gst_pad_push_data (pad,
4734 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4735 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4739 static GstFlowReturn
4740 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4741 GstBuffer ** buffer)
4744 GstPadGetRangeFunction getrangefunc;
4748 GST_PAD_STREAM_LOCK (pad);
4750 GST_OBJECT_LOCK (pad);
4751 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4754 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4757 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4762 /* when one of the probes returns DROPPED, probe_stopped will be called
4763 * and we skip calling the getrange function, res_buf should then contain a
4764 * valid result buffer */
4765 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4766 res_buf, offset, size, probe_stopped);
4768 /* recheck sticky events because the probe might have cause a relink */
4769 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4772 ACQUIRE_PARENT (pad, parent, no_parent);
4773 GST_OBJECT_UNLOCK (pad);
4775 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4778 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4779 "calling getrangefunc %s, offset %"
4780 G_GUINT64_FORMAT ", size %u",
4781 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4783 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4785 RELEASE_PARENT (parent);
4787 GST_OBJECT_LOCK (pad);
4788 if (G_UNLIKELY (ret != GST_FLOW_OK))
4789 goto get_range_failed;
4791 /* can only fire the signal if we have a valid buffer */
4793 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4794 res_buf, offset, size, probe_stopped_unref);
4795 pad->ABI.abi.last_flowret = ret;
4796 GST_OBJECT_UNLOCK (pad);
4798 GST_PAD_STREAM_UNLOCK (pad);
4807 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4808 "getrange, but pad was flushing");
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 was not activated in pull mode",
4817 GST_DEBUG_PAD_NAME (pad));
4818 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4819 GST_OBJECT_UNLOCK (pad);
4820 GST_PAD_STREAM_UNLOCK (pad);
4821 return GST_FLOW_ERROR;
4825 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4826 pad->ABI.abi.last_flowret = ret;
4827 GST_OBJECT_UNLOCK (pad);
4828 GST_PAD_STREAM_UNLOCK (pad);
4833 GST_DEBUG_OBJECT (pad, "no parent");
4834 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4835 GST_OBJECT_UNLOCK (pad);
4836 GST_PAD_STREAM_UNLOCK (pad);
4837 return GST_FLOW_FLUSHING;
4841 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4842 GST_DEBUG_PAD_NAME (pad));
4843 RELEASE_PARENT (parent);
4844 GST_PAD_STREAM_UNLOCK (pad);
4845 return GST_FLOW_NOT_SUPPORTED;
4849 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4850 "probe returned %s", gst_flow_get_name (ret));
4851 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4853 /* the probe filled the buffer and asks us to not call the getrange
4854 * anymore, we continue with the post probes then. */
4855 GST_DEBUG_OBJECT (pad, "handled buffer");
4859 /* no buffer, we are EOS */
4860 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4864 pad->ABI.abi.last_flowret = ret;
4865 GST_OBJECT_UNLOCK (pad);
4866 GST_PAD_STREAM_UNLOCK (pad);
4870 probe_stopped_unref:
4872 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4873 "probe returned %s", gst_flow_get_name (ret));
4874 /* if we drop here, it signals EOS */
4875 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4877 pad->ABI.abi.last_flowret = ret;
4878 GST_OBJECT_UNLOCK (pad);
4879 GST_PAD_STREAM_UNLOCK (pad);
4880 if (*buffer == NULL)
4881 gst_buffer_unref (res_buf);
4886 pad->ABI.abi.last_flowret = ret;
4887 GST_OBJECT_UNLOCK (pad);
4888 GST_PAD_STREAM_UNLOCK (pad);
4889 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4890 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4891 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4897 * gst_pad_get_range:
4898 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4899 * @offset: The start offset of the buffer
4900 * @size: The length of the buffer
4901 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4902 * returns #GST_FLOW_ERROR if %NULL.
4904 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4905 * immediately and @buffer is %NULL.
4907 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4908 * description of a getrange function. If @pad has no getrange function
4909 * installed (see gst_pad_set_getrange_function()) this function returns
4910 * #GST_FLOW_NOT_SUPPORTED.
4912 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4913 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4914 * must be freed with gst_buffer_unref() after usage.
4916 * When @buffer points to a variable that points to a valid #GstBuffer, the
4917 * buffer will be filled with the result data when this function returns
4918 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4919 * @size bytes will be filled in the result buffer and its size will be updated
4922 * Note that less than @size bytes can be returned in @buffer when, for example,
4923 * an EOS condition is near or when @buffer is not large enough to hold @size
4924 * bytes. The caller should check the result buffer size to get the result size.
4926 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4927 * will be unchanged.
4929 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4931 * Returns: a #GstFlowReturn from the pad.
4936 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4937 GstBuffer ** buffer)
4939 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4940 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4941 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4942 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4943 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4945 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4949 * gst_pad_pull_range:
4950 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4951 * @offset: The start offset of the buffer
4952 * @size: The length of the buffer
4953 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4954 * GST_FLOW_ERROR if %NULL.
4956 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4958 * This function will first trigger the pad block signal if it was
4961 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4962 * function returns the result of gst_pad_get_range() on the peer pad.
4963 * See gst_pad_get_range() for a list of return values and for the
4964 * semantics of the arguments of this function.
4966 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4967 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4968 * must be freed with gst_buffer_unref() after usage. When this function
4969 * returns any other result value, @buffer will still point to %NULL.
4971 * When @buffer points to a variable that points to a valid #GstBuffer, the
4972 * buffer will be filled with the result data when this function returns
4973 * #GST_FLOW_OK. When this function returns any other result value,
4974 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4975 * @size bytes will be filled in the result buffer and its size will be updated
4978 * Note that less than @size bytes can be returned in @buffer when, for example,
4979 * an EOS condition is near or when @buffer is not large enough to hold @size
4980 * bytes. The caller should check the result buffer size to get the result size.
4982 * Returns: a #GstFlowReturn from the peer pad.
4987 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4988 GstBuffer ** buffer)
4994 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4995 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4996 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4997 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4998 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5000 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
5002 GST_OBJECT_LOCK (pad);
5003 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5006 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
5011 /* when one of the probes returns DROPPED, probe_stopped will be
5012 * called and we skip calling the peer getrange function. *buffer should then
5013 * contain a valid buffer */
5014 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
5015 res_buf, offset, size, probe_stopped);
5017 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
5020 gst_object_ref (peer);
5022 GST_OBJECT_UNLOCK (pad);
5024 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5026 gst_object_unref (peer);
5028 GST_OBJECT_LOCK (pad);
5030 pad->ABI.abi.last_flowret = ret;
5031 if (pad->priv->using == 0) {
5032 /* pad is not active anymore, trigger idle callbacks */
5033 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5034 probe_stopped_unref, ret);
5037 if (G_UNLIKELY (ret != GST_FLOW_OK))
5038 goto pull_range_failed;
5041 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5042 res_buf, offset, size, probe_stopped_unref);
5044 GST_OBJECT_UNLOCK (pad);
5048 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5051 /* ERROR recovery here */
5054 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5055 "pullrange, but pad was flushing");
5056 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5057 GST_OBJECT_UNLOCK (pad);
5058 ret = GST_FLOW_FLUSHING;
5063 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5064 GST_DEBUG_PAD_NAME (pad));
5065 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5066 GST_OBJECT_UNLOCK (pad);
5067 ret = GST_FLOW_ERROR;
5072 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5073 gst_flow_get_name (ret));
5074 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5076 /* the probe filled the buffer and asks us to not forward to the peer
5077 * anymore, we continue with the post probes then */
5078 GST_DEBUG_OBJECT (pad, "handled buffer");
5082 /* no buffer, we are EOS then */
5083 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5087 pad->ABI.abi.last_flowret = ret;
5088 GST_OBJECT_UNLOCK (pad);
5093 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5094 "pulling range, but it was not linked");
5095 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5096 GST_OBJECT_UNLOCK (pad);
5097 ret = GST_FLOW_NOT_LINKED;
5102 pad->ABI.abi.last_flowret = ret;
5103 GST_OBJECT_UNLOCK (pad);
5104 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5105 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5106 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5109 probe_stopped_unref:
5111 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5112 "post probe returned %s", gst_flow_get_name (ret));
5114 /* if we drop here, it signals EOS */
5115 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5118 pad->ABI.abi.last_flowret = ret;
5119 GST_OBJECT_UNLOCK (pad);
5121 if (*buffer == NULL)
5122 gst_buffer_unref (res_buf);
5126 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5130 /* must be called with pad object lock */
5131 static GstFlowReturn
5132 store_sticky_event (GstPad * pad, GstEvent * event)
5137 gboolean res = FALSE;
5138 const gchar *name = NULL;
5139 gboolean insert = TRUE;
5141 type = GST_EVENT_TYPE (event);
5143 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5144 * otherwise they can be dropped and nothing would ever resend them.
5145 * Only do that for activated pads though, everything else is a bug!
5147 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5148 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5149 || type == GST_EVENT_EOS))))
5152 /* Unset the EOS flag when received STREAM_START event, so pad can
5153 * store sticky event and then push it later */
5154 if (type == GST_EVENT_STREAM_START) {
5155 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5156 remove_event_by_type (pad, GST_EVENT_EOS);
5157 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5158 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5161 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5164 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5165 name = gst_structure_get_name (gst_event_get_structure (event));
5167 events = pad->priv->events;
5170 for (i = 0; i < len; i++) {
5171 PadEvent *ev = &g_array_index (events, PadEvent, i);
5173 if (ev->event == NULL)
5176 if (type == GST_EVENT_TYPE (ev->event)) {
5177 /* matching types, check matching name if needed */
5178 if (name && !gst_event_has_name (ev->event, name))
5182 if ((res = gst_event_replace (&ev->event, event)))
5183 ev->received = FALSE;
5189 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5190 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5191 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5192 * storing the sticky ordered we can check that this is respected. */
5193 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5194 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5196 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5197 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5198 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5199 gst_event_type_get_name (type));
5205 ev.event = gst_event_ref (event);
5206 ev.received = FALSE;
5207 g_array_insert_val (events, i, ev);
5212 pad->priv->events_cookie++;
5213 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5215 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5217 switch (GST_EVENT_TYPE (event)) {
5218 case GST_EVENT_CAPS:
5219 GST_OBJECT_UNLOCK (pad);
5221 GST_DEBUG_OBJECT (pad, "notify caps");
5222 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5224 GST_OBJECT_LOCK (pad);
5230 if (type == GST_EVENT_EOS) {
5231 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5232 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5235 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5240 GST_DEBUG_OBJECT (pad, "pad is flushing");
5241 return GST_FLOW_FLUSHING;
5245 GST_DEBUG_OBJECT (pad, "pad is EOS");
5246 return GST_FLOW_EOS;
5251 * gst_pad_store_sticky_event:
5253 * @event: (transfer none): a #GstEvent
5255 * Store the sticky @event on @pad
5257 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5258 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5263 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5267 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5268 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5270 GST_OBJECT_LOCK (pad);
5271 ret = store_sticky_event (pad, event);
5272 GST_OBJECT_UNLOCK (pad);
5278 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5280 PushStickyData *data = user_data;
5282 /* Forward all sticky events before our current one that are pending */
5283 if (ev->event != data->event
5284 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5285 return push_sticky (pad, ev, data);
5290 /* should be called with pad LOCK */
5291 static GstFlowReturn
5292 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5293 GstPadProbeType type)
5297 GstEventType event_type;
5298 gint64 old_pad_offset = pad->offset;
5300 /* pass the adjusted event on. We need to do this even if
5301 * there is no peer pad because of the probes. */
5302 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5304 /* Two checks to be made:
5305 * . (un)set the FLUSHING flag for flushing events,
5306 * . handle pad blocking */
5307 event_type = GST_EVENT_TYPE (event);
5308 switch (event_type) {
5309 case GST_EVENT_FLUSH_START:
5310 GST_PAD_SET_FLUSHING (pad);
5312 GST_PAD_BLOCK_BROADCAST (pad);
5313 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5315 case GST_EVENT_FLUSH_STOP:
5316 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5319 GST_PAD_UNSET_FLUSHING (pad);
5321 /* Remove sticky EOS events */
5322 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5323 remove_event_by_type (pad, GST_EVENT_EOS);
5324 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5325 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5326 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5327 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5329 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5333 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5336 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5337 * checked already or this is called as part of pushing sticky events,
5338 * in which case we still want to forward the EOS event downstream.
5341 switch (GST_EVENT_TYPE (event)) {
5342 case GST_EVENT_RECONFIGURE:
5343 if (GST_PAD_IS_SINK (pad))
5344 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5349 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5350 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5351 /* recheck sticky events because the probe might have cause a relink */
5352 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5353 && (GST_EVENT_IS_SERIALIZED (event)
5354 || GST_EVENT_IS_STICKY (event))) {
5355 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5356 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5358 /* Push all sticky events before our current one
5359 * that have changed */
5360 events_foreach (pad, sticky_changed, &data);
5366 /* send probes after modifying the events above */
5367 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5369 /* recheck sticky events because the probe might have cause a relink */
5370 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5371 && (GST_EVENT_IS_SERIALIZED (event)
5372 || GST_EVENT_IS_STICKY (event))) {
5373 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5374 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5376 /* Push all sticky events before our current one
5377 * that have changed */
5378 events_foreach (pad, sticky_changed, &data);
5381 /* the pad offset might've been changed by any of the probes above. It
5382 * would've been taken into account when repushing any of the sticky events
5383 * above but not for our current event here */
5384 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5386 _apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad),
5387 pad->offset - old_pad_offset);
5390 /* now check the peer pad */
5391 peerpad = GST_PAD_PEER (pad);
5392 if (peerpad == NULL)
5395 gst_object_ref (peerpad);
5397 GST_OBJECT_UNLOCK (pad);
5399 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5400 event, gst_event_type_get_name (event_type), peerpad);
5402 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5404 /* Note: we gave away ownership of the event at this point but we can still
5405 * print the old pointer */
5406 GST_LOG_OBJECT (pad,
5407 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5408 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5410 gst_object_unref (peerpad);
5412 GST_OBJECT_LOCK (pad);
5414 if (pad->priv->using == 0) {
5415 /* pad is not active anymore, trigger idle callbacks */
5416 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5417 idle_probe_stopped, ret);
5421 /* ERROR handling */
5424 GST_DEBUG_OBJECT (pad, "We're flushing");
5425 gst_event_unref (event);
5426 return GST_FLOW_FLUSHING;
5430 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5431 gst_event_unref (event);
5432 return GST_FLOW_FLUSHING;
5436 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5437 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5438 gst_event_unref (event);
5441 case GST_FLOW_CUSTOM_SUCCESS_1:
5442 GST_DEBUG_OBJECT (pad, "handled event");
5444 case GST_FLOW_CUSTOM_SUCCESS:
5445 GST_DEBUG_OBJECT (pad, "dropped event");
5448 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5455 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5456 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5457 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5458 gst_event_unref (event);
5460 /* unlinked pads should not influence latency configuration */
5461 if (event_type == GST_EVENT_LATENCY)
5464 return GST_FLOW_NOT_LINKED;
5468 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5474 * gst_pad_push_event:
5475 * @pad: a #GstPad to push the event to.
5476 * @event: (transfer full): the #GstEvent to send to the pad.
5478 * Sends the event to the peer of the given pad. This function is
5479 * mainly used by elements to send events to their peer
5482 * This function takes ownership of the provided event so you should
5483 * gst_event_ref() it if you want to reuse the event after this call.
5485 * Returns: %TRUE if the event was handled.
5490 gst_pad_push_event (GstPad * pad, GstEvent * event)
5492 gboolean res = FALSE;
5493 GstPadProbeType type;
5494 gboolean sticky, serialized;
5496 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5497 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5499 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5501 if (GST_PAD_IS_SRC (pad)) {
5502 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5503 goto wrong_direction;
5504 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5505 } else if (GST_PAD_IS_SINK (pad)) {
5506 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5507 goto wrong_direction;
5508 /* events pushed on sinkpad never are sticky */
5509 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5511 goto unknown_direction;
5513 GST_OBJECT_LOCK (pad);
5514 sticky = GST_EVENT_IS_STICKY (event);
5515 serialized = GST_EVENT_IS_SERIALIZED (event);
5518 /* srcpad sticky events are stored immediately, the received flag is set
5519 * to FALSE and will be set to TRUE when we can successfully push the
5520 * event to the peer pad */
5521 switch (store_sticky_event (pad, event)) {
5522 case GST_FLOW_FLUSHING:
5530 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5531 /* all serialized or sticky events on the srcpad trigger push of
5533 res = (check_sticky (pad, event) == GST_FLOW_OK);
5538 /* other events are pushed right away */
5539 ret = gst_pad_push_event_unchecked (pad, event, type);
5540 /* dropped events by a probe are not an error */
5541 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5542 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5544 /* Errors in sticky event pushing are no problem and ignored here
5545 * as they will cause more meaningful errors during data flow.
5546 * For EOS events, that are not followed by data flow, we still
5547 * return FALSE here though.
5549 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5551 gst_event_unref (event);
5553 GST_OBJECT_UNLOCK (pad);
5555 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5558 /* ERROR handling */
5561 g_warning ("pad %s:%s pushing %s event in wrong direction",
5562 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5563 gst_event_unref (event);
5568 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5569 gst_event_unref (event);
5574 GST_DEBUG_OBJECT (pad, "We're flushing");
5575 GST_OBJECT_UNLOCK (pad);
5576 gst_event_unref (event);
5581 GST_DEBUG_OBJECT (pad, "We're EOS");
5582 GST_OBJECT_UNLOCK (pad);
5583 gst_event_unref (event);
5587 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5591 /* Check if we can call the event function with the given event */
5592 static GstFlowReturn
5593 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5597 switch (GST_EVENT_TYPE (event)) {
5598 case GST_EVENT_CAPS:
5600 /* backwards compatibility mode for caps */
5601 gst_event_parse_caps (event, &caps);
5603 if (!gst_pad_query_accept_caps (pad, caps))
5615 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5616 "caps %" GST_PTR_FORMAT " not accepted", caps);
5617 return GST_FLOW_NOT_NEGOTIATED;
5621 static GstFlowReturn
5622 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5623 GstPadProbeType type)
5626 GstEventType event_type;
5627 gboolean serialized, need_unlock = FALSE, sticky;
5628 GstPadEventFunction eventfunc;
5629 GstPadEventFullFunction eventfullfunc = NULL;
5631 gint64 old_pad_offset;
5633 GST_OBJECT_LOCK (pad);
5635 old_pad_offset = pad->offset;
5636 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5638 if (GST_PAD_IS_SINK (pad))
5639 serialized = GST_EVENT_IS_SERIALIZED (event);
5642 sticky = GST_EVENT_IS_STICKY (event);
5643 event_type = GST_EVENT_TYPE (event);
5644 switch (event_type) {
5645 case GST_EVENT_FLUSH_START:
5646 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5647 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5649 /* can't even accept a flush begin event when flushing */
5650 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5653 GST_PAD_SET_FLUSHING (pad);
5654 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5655 GST_PAD_BLOCK_BROADCAST (pad);
5656 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5658 case GST_EVENT_FLUSH_STOP:
5659 /* we can't accept flush-stop on inactive pads else the flushing flag
5660 * would be cleared and it would look like the pad can accept data.
5661 * Also, some elements restart a streaming thread in flush-stop which we
5662 * can't allow on inactive pads */
5663 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5666 GST_PAD_UNSET_FLUSHING (pad);
5667 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5668 /* Remove pending EOS events */
5669 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5670 remove_event_by_type (pad, GST_EVENT_EOS);
5671 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5672 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5673 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5674 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5676 GST_OBJECT_UNLOCK (pad);
5677 /* grab stream lock */
5678 GST_PAD_STREAM_LOCK (pad);
5680 GST_OBJECT_LOCK (pad);
5681 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5684 case GST_EVENT_RECONFIGURE:
5685 if (GST_PAD_IS_SRC (pad))
5686 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5688 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5689 "have event type %" GST_PTR_FORMAT, event);
5691 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5694 switch (event_type) {
5695 case GST_EVENT_STREAM_START:
5696 /* Remove sticky EOS events */
5697 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5698 remove_event_by_type (pad, GST_EVENT_EOS);
5699 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5700 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5707 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5710 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5711 GST_OBJECT_UNLOCK (pad);
5712 GST_PAD_STREAM_LOCK (pad);
5714 GST_OBJECT_LOCK (pad);
5715 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5718 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5724 /* now do the probe */
5726 type | GST_PAD_PROBE_TYPE_PUSH |
5727 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5729 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5731 /* the pad offset might've been changed by any of the probes above. It
5732 * would've been taken into account when repushing any of the sticky events
5733 * above but not for our current event here */
5734 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5736 _apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad),
5737 pad->offset - old_pad_offset);
5740 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5741 eventfunc = GST_PAD_EVENTFUNC (pad);
5742 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5745 ACQUIRE_PARENT (pad, parent, no_parent);
5746 GST_OBJECT_UNLOCK (pad);
5748 ret = pre_eventfunc_check (pad, event);
5749 if (G_UNLIKELY (ret != GST_FLOW_OK))
5750 goto precheck_failed;
5753 gst_event_ref (event);
5755 if (eventfullfunc) {
5756 ret = eventfullfunc (pad, parent, event);
5757 } else if (eventfunc (pad, parent, event)) {
5760 /* something went wrong */
5761 switch (event_type) {
5762 case GST_EVENT_CAPS:
5763 ret = GST_FLOW_NOT_NEGOTIATED;
5766 ret = GST_FLOW_ERROR;
5770 RELEASE_PARENT (parent);
5772 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5775 if (ret == GST_FLOW_OK) {
5776 GST_OBJECT_LOCK (pad);
5777 /* after the event function accepted the event, we can store the sticky
5778 * event on the pad */
5779 switch (store_sticky_event (pad, event)) {
5780 case GST_FLOW_FLUSHING:
5787 GST_OBJECT_UNLOCK (pad);
5789 gst_event_unref (event);
5793 GST_PAD_STREAM_UNLOCK (pad);
5797 /* ERROR handling */
5800 GST_OBJECT_UNLOCK (pad);
5802 GST_PAD_STREAM_UNLOCK (pad);
5803 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5804 "Received event on flushing pad. Discarding");
5805 gst_event_unref (event);
5806 return GST_FLOW_FLUSHING;
5810 GST_OBJECT_UNLOCK (pad);
5812 GST_PAD_STREAM_UNLOCK (pad);
5813 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5814 "Received flush-stop on inactive pad. Discarding");
5815 gst_event_unref (event);
5816 return GST_FLOW_FLUSHING;
5820 GST_OBJECT_UNLOCK (pad);
5822 GST_PAD_STREAM_UNLOCK (pad);
5823 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5824 "Received event on EOS pad. Discarding");
5825 gst_event_unref (event);
5826 return GST_FLOW_EOS;
5830 GST_OBJECT_UNLOCK (pad);
5832 GST_PAD_STREAM_UNLOCK (pad);
5833 /* Only unref if unhandled */
5834 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5835 gst_event_unref (event);
5838 case GST_FLOW_CUSTOM_SUCCESS_1:
5839 case GST_FLOW_CUSTOM_SUCCESS:
5840 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5844 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5851 g_warning ("pad %s:%s has no event handler, file a bug.",
5852 GST_DEBUG_PAD_NAME (pad));
5853 GST_OBJECT_UNLOCK (pad);
5855 GST_PAD_STREAM_UNLOCK (pad);
5856 gst_event_unref (event);
5857 return GST_FLOW_NOT_SUPPORTED;
5861 GST_DEBUG_OBJECT (pad, "no parent");
5862 GST_OBJECT_UNLOCK (pad);
5864 GST_PAD_STREAM_UNLOCK (pad);
5865 gst_event_unref (event);
5866 return GST_FLOW_FLUSHING;
5870 GST_DEBUG_OBJECT (pad, "pre event check failed");
5871 RELEASE_PARENT (parent);
5873 GST_PAD_STREAM_UNLOCK (pad);
5874 gst_event_unref (event);
5880 * gst_pad_send_event:
5881 * @pad: a #GstPad to send the event to.
5882 * @event: (transfer full): the #GstEvent to send to the pad.
5884 * Sends the event to the pad. This function can be used
5885 * by applications to send events in the pipeline.
5887 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5888 * sink pad, @event should be a downstream event. For example, you would not
5889 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5890 * Furthermore, some downstream events have to be serialized with data flow,
5891 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5892 * the event needs to be serialized with data flow, this function will take the
5893 * pad's stream lock while calling its event function.
5895 * To find out whether an event type is upstream, downstream, or downstream and
5896 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5897 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5898 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5899 * plugin doesn't need to bother itself with this information; the core handles
5900 * all necessary locks and checks.
5902 * This function takes ownership of the provided event so you should
5903 * gst_event_ref() it if you want to reuse the event after this call.
5905 * Returns: %TRUE if the event was handled.
5908 gst_pad_send_event (GstPad * pad, GstEvent * event)
5911 GstPadProbeType type;
5913 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5914 g_return_val_if_fail (event != NULL, FALSE);
5916 if (GST_PAD_IS_SINK (pad)) {
5917 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5918 goto wrong_direction;
5919 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5920 } else if (GST_PAD_IS_SRC (pad)) {
5921 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5922 goto wrong_direction;
5923 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5925 goto unknown_direction;
5927 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5934 /* ERROR handling */
5937 g_warning ("pad %s:%s sending %s event in wrong direction",
5938 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5939 gst_event_unref (event);
5944 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5945 gst_event_unref (event);
5951 * gst_pad_set_element_private:
5952 * @pad: the #GstPad to set the private data of.
5953 * @priv: The private data to attach to the pad.
5955 * Set the given private data gpointer on the pad.
5956 * This function can only be used by the element that owns the pad.
5957 * No locking is performed in this function.
5960 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5962 pad->element_private = priv;
5966 * gst_pad_get_element_private:
5967 * @pad: the #GstPad to get the private data of.
5969 * Gets the private data of a pad.
5970 * No locking is performed in this function.
5972 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5975 gst_pad_get_element_private (GstPad * pad)
5977 return pad->element_private;
5981 * gst_pad_get_sticky_event:
5982 * @pad: the #GstPad to get the event from.
5983 * @event_type: the #GstEventType that should be retrieved.
5984 * @idx: the index of the event
5986 * Returns a new reference of the sticky event of type @event_type
5989 * Returns: (transfer full) (nullable): a #GstEvent of type
5990 * @event_type or %NULL when no event of @event_type was on
5991 * @pad. Unref after usage.
5994 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5996 GstEvent *event = NULL;
5999 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
6000 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
6002 GST_OBJECT_LOCK (pad);
6003 ev = find_event_by_type (pad, event_type, idx);
6004 if (ev && (event = ev->event))
6005 gst_event_ref (event);
6006 GST_OBJECT_UNLOCK (pad);
6013 GstPadStickyEventsForeachFunction func;
6018 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
6020 ForeachDispatch *data = user_data;
6021 gboolean ret = TRUE;
6024 GST_OBJECT_UNLOCK (pad);
6026 ret = data->func (pad, &ev->event, data->user_data);
6028 GST_OBJECT_LOCK (pad);
6035 * gst_pad_sticky_events_foreach:
6036 * @pad: the #GstPad that should be used for iteration.
6037 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
6038 * should be called for every event.
6039 * @user_data: (closure): the optional user data.
6041 * Iterates all sticky events on @pad and calls @foreach_func for every
6042 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6045 gst_pad_sticky_events_foreach (GstPad * pad,
6046 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6048 ForeachDispatch data;
6050 g_return_if_fail (GST_IS_PAD (pad));
6051 g_return_if_fail (foreach_func != NULL);
6053 data.func = foreach_func;
6054 data.user_data = user_data;
6056 GST_OBJECT_LOCK (pad);
6057 events_foreach (pad, foreach_dispatch_function, &data);
6058 GST_OBJECT_UNLOCK (pad);
6062 do_stream_status (GstPad * pad, GstStreamStatusType type,
6063 GThread * thread, GstTask * task)
6067 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6069 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6070 if (GST_IS_ELEMENT (parent)) {
6071 GstMessage *message;
6072 GValue value = { 0 };
6074 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6075 gchar *tname, *ename, *pname;
6077 /* create a good task name */
6078 ename = gst_element_get_name (parent);
6079 pname = gst_pad_get_name (pad);
6080 tname = g_strdup_printf ("%s:%s", ename, pname);
6084 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6088 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6091 g_value_init (&value, GST_TYPE_TASK);
6092 g_value_set_object (&value, task);
6093 gst_message_set_stream_status_object (message, &value);
6094 g_value_unset (&value);
6096 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6097 gst_element_post_message (parent, message);
6099 gst_object_unref (parent);
6104 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6106 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6111 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6113 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6118 * gst_pad_start_task:
6119 * @pad: the #GstPad to start the task of
6120 * @func: the task function to call
6121 * @user_data: user data passed to the task function
6122 * @notify: called when @user_data is no longer referenced
6124 * Starts a task that repeatedly calls @func with @user_data. This function
6125 * is mostly used in pad activation functions to start the dataflow.
6126 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6127 * before @func is called.
6129 * Returns: a %TRUE if the task could be started.
6132 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6133 GDestroyNotify notify)
6138 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6139 g_return_val_if_fail (func != NULL, FALSE);
6141 GST_DEBUG_OBJECT (pad, "start task");
6143 GST_OBJECT_LOCK (pad);
6144 task = GST_PAD_TASK (pad);
6146 task = gst_task_new (func, user_data, notify);
6147 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6148 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6149 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6150 GST_INFO_OBJECT (pad, "created task %p", task);
6151 GST_PAD_TASK (pad) = task;
6152 gst_object_ref (task);
6153 /* release lock to post the message */
6154 GST_OBJECT_UNLOCK (pad);
6156 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6158 gst_object_unref (task);
6160 GST_OBJECT_LOCK (pad);
6161 /* nobody else is supposed to have changed the pad now */
6162 if (GST_PAD_TASK (pad) != task)
6163 goto concurrent_stop;
6165 res = gst_task_set_state (task, GST_TASK_STARTED);
6166 GST_OBJECT_UNLOCK (pad);
6173 GST_OBJECT_UNLOCK (pad);
6179 * gst_pad_pause_task:
6180 * @pad: the #GstPad to pause the task of
6182 * Pause the task of @pad. This function will also wait until the
6183 * function executed by the task is finished if this function is not
6184 * called from the task function.
6186 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6190 gst_pad_pause_task (GstPad * pad)
6195 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6197 GST_DEBUG_OBJECT (pad, "pause task");
6199 GST_OBJECT_LOCK (pad);
6200 task = GST_PAD_TASK (pad);
6203 res = gst_task_set_state (task, GST_TASK_PAUSED);
6204 /* unblock activation waits if any */
6205 pad->priv->in_activation = FALSE;
6206 g_cond_broadcast (&pad->priv->activation_cond);
6207 GST_OBJECT_UNLOCK (pad);
6209 /* wait for task function to finish, this lock is recursive so it does nothing
6210 * when the pause is called from the task itself */
6211 GST_PAD_STREAM_LOCK (pad);
6212 GST_PAD_STREAM_UNLOCK (pad);
6218 GST_DEBUG_OBJECT (pad, "pad has no task");
6219 GST_OBJECT_UNLOCK (pad);
6225 * gst_pad_get_task_state:
6226 * @pad: the #GstPad to get task state from
6228 * Get @pad task state. If no task is currently
6229 * set, #GST_TASK_STOPPED is returned.
6231 * Returns: The current state of @pad's task.
6236 gst_pad_get_task_state (GstPad * pad)
6241 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6243 GST_OBJECT_LOCK (pad);
6244 task = GST_PAD_TASK (pad);
6247 res = gst_task_get_state (task);
6248 GST_OBJECT_UNLOCK (pad);
6254 GST_DEBUG_OBJECT (pad, "pad has no task");
6255 GST_OBJECT_UNLOCK (pad);
6256 return GST_TASK_STOPPED;
6261 * gst_pad_stop_task:
6262 * @pad: the #GstPad to stop the task of
6264 * Stop the task of @pad. This function will also make sure that the
6265 * function executed by the task will effectively stop if not called
6266 * from the GstTaskFunction.
6268 * This function will deadlock if called from the GstTaskFunction of
6269 * the task. Use gst_task_pause() instead.
6271 * Regardless of whether the pad has a task, the stream lock is acquired and
6272 * released so as to ensure that streaming through this pad has finished.
6274 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6277 gst_pad_stop_task (GstPad * pad)
6282 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6284 GST_DEBUG_OBJECT (pad, "stop task");
6286 GST_OBJECT_LOCK (pad);
6287 task = GST_PAD_TASK (pad);
6290 GST_PAD_TASK (pad) = NULL;
6291 res = gst_task_set_state (task, GST_TASK_STOPPED);
6292 /* unblock activation waits if any */
6293 pad->priv->in_activation = FALSE;
6294 g_cond_broadcast (&pad->priv->activation_cond);
6295 GST_OBJECT_UNLOCK (pad);
6297 GST_PAD_STREAM_LOCK (pad);
6298 GST_PAD_STREAM_UNLOCK (pad);
6300 if (!gst_task_join (task))
6303 gst_object_unref (task);
6309 GST_DEBUG_OBJECT (pad, "no task");
6310 GST_OBJECT_UNLOCK (pad);
6312 GST_PAD_STREAM_LOCK (pad);
6313 GST_PAD_STREAM_UNLOCK (pad);
6315 /* this is not an error */
6320 /* this is bad, possibly the application tried to join the task from
6321 * the task's thread. We install the task again so that it will be stopped
6322 * again from the right thread next time hopefully. */
6323 GST_OBJECT_LOCK (pad);
6324 GST_DEBUG_OBJECT (pad, "join failed");
6325 /* we can only install this task if there was no other task */
6326 if (GST_PAD_TASK (pad) == NULL)
6327 GST_PAD_TASK (pad) = task;
6328 GST_OBJECT_UNLOCK (pad);
6335 * gst_pad_probe_info_get_event:
6336 * @info: a #GstPadProbeInfo
6338 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6342 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6344 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6345 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6347 return GST_PAD_PROBE_INFO_EVENT (info);
6352 * gst_pad_probe_info_get_query:
6353 * @info: a #GstPadProbeInfo
6355 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6359 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6361 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6362 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6364 return GST_PAD_PROBE_INFO_QUERY (info);
6368 * gst_pad_probe_info_get_buffer:
6369 * @info: a #GstPadProbeInfo
6371 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6375 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6377 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6379 return GST_PAD_PROBE_INFO_BUFFER (info);
6383 * gst_pad_probe_info_get_buffer_list:
6384 * @info: a #GstPadProbeInfo
6386 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6390 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6392 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6394 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6398 * gst_pad_get_last_flow_return:
6401 * Gets the #GstFlowReturn return from the last data passed by this pad.
6406 gst_pad_get_last_flow_return (GstPad * pad)
6410 GST_OBJECT_LOCK (pad);
6411 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6412 GST_OBJECT_UNLOCK (pad);