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.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is %NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
89 #include "gst_private.h"
92 #include "gstpadtemplate.h"
93 #include "gstenumtypes.h"
97 #include "gsttracerutils.h"
99 #include "glib-compat-private.h"
101 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
102 #define GST_CAT_DEFAULT GST_CAT_PADS
104 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
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;
145 /* counter of how many idle probes are running directly from the add_probe
146 * call. Used to block any data flowing in the pad while the idle callback
147 * Doesn't finish its work */
157 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
158 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
159 (((GstPad *)(p))->priv->idle_running > 0)
164 GstPadProbeInfo *info;
172 static void gst_pad_dispose (GObject * object);
173 static void gst_pad_finalize (GObject * object);
174 static void gst_pad_set_property (GObject * object, guint prop_id,
175 const GValue * value, GParamSpec * pspec);
176 static void gst_pad_get_property (GObject * object, guint prop_id,
177 GValue * value, GParamSpec * pspec);
179 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
180 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
181 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
182 GstObject * parent, GstBufferList * list);
184 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
185 GstEvent * event, GstPadProbeType type);
186 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
187 GstEvent * event, GstPadProbeType type);
189 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
190 GstPadMode mode, gboolean active);
192 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
194 static GParamSpec *pspec_caps = NULL;
196 /* quarks for probe signals */
197 static GQuark buffer_quark;
198 static GQuark buffer_list_quark;
199 static GQuark event_quark;
208 static GstFlowQuarks flow_quarks[] = {
209 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
210 {GST_FLOW_OK, "ok", 0},
211 {GST_FLOW_NOT_LINKED, "not-linked", 0},
212 {GST_FLOW_FLUSHING, "flushing", 0},
213 {GST_FLOW_EOS, "eos", 0},
214 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
215 {GST_FLOW_ERROR, "error", 0},
216 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
217 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
222 * @ret: a #GstFlowReturn to get the name of.
224 * Gets a string representing the given flow return.
226 * Returns: a static string with the name of the flow return.
229 gst_flow_get_name (GstFlowReturn ret)
233 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
235 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
236 if (ret == flow_quarks[i].ret)
237 return flow_quarks[i].name;
244 * @ret: a #GstFlowReturn to get the quark of.
246 * Get the unique quark for the given GstFlowReturn.
248 * Returns: the quark associated with the flow return or 0 if an
249 * invalid return was specified.
252 gst_flow_to_quark (GstFlowReturn ret)
256 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
258 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
259 if (ret == flow_quarks[i].ret)
260 return flow_quarks[i].quark;
266 * gst_pad_link_get_name:
267 * @ret: a #GstPadLinkReturn to get the name of.
269 * Gets a string representing the given pad-link return.
271 * Returns: a static string with the name of the pad-link return.
276 gst_pad_link_get_name (GstPadLinkReturn ret)
279 case GST_PAD_LINK_OK:
281 case GST_PAD_LINK_WRONG_HIERARCHY:
282 return "wrong hierarchy";
283 case GST_PAD_LINK_WAS_LINKED:
285 case GST_PAD_LINK_WRONG_DIRECTION:
286 return "wrong direction";
287 case GST_PAD_LINK_NOFORMAT:
288 return "no common format";
289 case GST_PAD_LINK_NOSCHED:
290 return "incompatible scheduling";
291 case GST_PAD_LINK_REFUSED:
294 g_return_val_if_reached ("unknown");
301 buffer_quark = g_quark_from_static_string ("buffer"); \
302 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
303 event_quark = g_quark_from_static_string ("event"); \
305 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
306 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
309 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
310 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
313 #define gst_pad_parent_class parent_class
314 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
317 gst_pad_class_init (GstPadClass * klass)
319 GObjectClass *gobject_class;
320 GstObjectClass *gstobject_class;
322 gobject_class = G_OBJECT_CLASS (klass);
323 gstobject_class = GST_OBJECT_CLASS (klass);
325 g_type_class_add_private (klass, sizeof (GstPadPrivate));
327 gobject_class->dispose = gst_pad_dispose;
328 gobject_class->finalize = gst_pad_finalize;
329 gobject_class->set_property = gst_pad_set_property;
330 gobject_class->get_property = gst_pad_get_property;
334 * @pad: the pad that emitted the signal
335 * @peer: the peer pad that has been connected
337 * Signals that a pad has been linked to the peer pad.
339 gst_pad_signals[PAD_LINKED] =
340 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
341 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
342 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
345 * @pad: the pad that emitted the signal
346 * @peer: the peer pad that has been disconnected
348 * Signals that a pad has been unlinked from the peer pad.
350 gst_pad_signals[PAD_UNLINKED] =
351 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
352 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
353 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
355 pspec_caps = g_param_spec_boxed ("caps", "Caps",
356 "The capabilities of the pad", GST_TYPE_CAPS,
357 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
358 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
360 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
361 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
362 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
363 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
365 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
366 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
367 g_param_spec_object ("template", "Template",
368 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
369 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
374 * The offset that will be applied to the running time of the pad.
378 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
379 g_param_spec_int64 ("offset", "Offset",
380 "The running time offset of the pad", 0, G_MAXINT64, 0,
381 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
383 gstobject_class->path_string_separator = ".";
385 /* Register common function pointer descriptions */
386 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
387 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
388 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
389 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
394 gst_pad_init (GstPad * pad)
396 pad->priv = GST_PAD_GET_PRIVATE (pad);
398 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
400 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
401 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
402 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
403 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
404 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
406 GST_PAD_SET_FLUSHING (pad);
408 g_rec_mutex_init (&pad->stream_rec_lock);
410 g_cond_init (&pad->block_cond);
412 g_hook_list_init (&pad->probes, sizeof (GstProbe));
414 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
415 pad->priv->events_cookie = 0;
416 pad->priv->last_cookie = -1;
417 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
420 /* called when setting the pad inactive. It removes all sticky events from
421 * the pad. must be called with object lock */
423 remove_events (GstPad * pad)
427 gboolean notify = FALSE;
429 events = pad->priv->events;
432 for (i = 0; i < len; i++) {
433 PadEvent *ev = &g_array_index (events, PadEvent, i);
434 GstEvent *event = ev->event;
438 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
441 gst_event_unref (event);
444 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
445 g_array_set_size (events, 0);
446 pad->priv->events_cookie++;
449 GST_OBJECT_UNLOCK (pad);
451 GST_DEBUG_OBJECT (pad, "notify caps");
452 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
454 GST_OBJECT_LOCK (pad);
458 /* should be called with object lock */
460 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
466 events = pad->priv->events;
469 for (i = 0; i < len; i++) {
470 ev = &g_array_index (events, PadEvent, i);
471 if (ev->event == NULL)
474 if (GST_EVENT_TYPE (ev->event) == type) {
478 } else if (GST_EVENT_TYPE (ev->event) > type) {
487 /* should be called with OBJECT lock */
489 find_event (GstPad * pad, GstEvent * event)
495 events = pad->priv->events;
498 for (i = 0; i < len; i++) {
499 ev = &g_array_index (events, PadEvent, i);
500 if (event == ev->event)
502 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
510 /* should be called with OBJECT lock */
512 remove_event_by_type (GstPad * pad, GstEventType type)
518 events = pad->priv->events;
523 ev = &g_array_index (events, PadEvent, i);
524 if (ev->event == NULL)
527 if (GST_EVENT_TYPE (ev->event) > type)
529 else if (GST_EVENT_TYPE (ev->event) != type)
532 gst_event_unref (ev->event);
533 g_array_remove_index (events, i);
535 pad->priv->events_cookie++;
543 /* check all events on srcpad against those on sinkpad. All events that are not
544 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
545 * srcpad so that the events will be sent next time */
546 /* should be called with srcpad and sinkpad LOCKS */
548 schedule_events (GstPad * srcpad, GstPad * sinkpad)
553 gboolean pending = FALSE;
555 events = srcpad->priv->events;
558 for (i = 0; i < len; i++) {
559 ev = &g_array_index (events, PadEvent, i);
560 if (ev->event == NULL)
563 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
564 ev->received = FALSE;
569 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
572 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
575 /* should be called with pad LOCK */
577 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
584 events = pad->priv->events;
587 cookie = pad->priv->events_cookie;
591 PadEvent *ev, ev_ret;
593 ev = &g_array_index (events, PadEvent, i);
594 if (G_UNLIKELY (ev->event == NULL))
597 /* take aditional ref, func might release the lock */
598 ev_ret.event = gst_event_ref (ev->event);
599 ev_ret.received = ev->received;
601 ret = func (pad, &ev_ret, user_data);
603 /* recheck the cookie, lock might have been released and the list could have
605 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
606 if (G_LIKELY (ev_ret.event))
607 gst_event_unref (ev_ret.event);
611 /* store the received state */
612 ev->received = ev_ret.received;
614 /* if the event changed, we need to do something */
615 if (G_UNLIKELY (ev->event != ev_ret.event)) {
616 if (G_UNLIKELY (ev_ret.event == NULL)) {
617 /* function unreffed and set the event to NULL, remove it */
618 gst_event_unref (ev->event);
619 g_array_remove_index (events, i);
621 cookie = ++pad->priv->events_cookie;
624 /* function gave a new event for us */
625 gst_event_take (&ev->event, ev_ret.event);
628 /* just unref, nothing changed */
629 gst_event_unref (ev_ret.event);
638 /* should be called with LOCK */
640 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
644 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
645 GST_TIME_ARGS (pad->offset));
647 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
650 g_assert (!upstream);
652 /* copy segment values */
653 gst_event_copy_segment (event, &segment);
654 gst_event_unref (event);
656 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
657 event = gst_event_new_segment (&segment);
660 event = gst_event_make_writable (event);
661 offset = gst_event_get_running_time_offset (event);
663 offset -= pad->offset;
665 offset += pad->offset;
666 gst_event_set_running_time_offset (event, offset);
671 static inline GstEvent *
672 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
674 if (G_UNLIKELY (pad->offset != 0))
675 return _apply_pad_offset (pad, event, upstream);
680 /* should be called with the OBJECT_LOCK */
682 get_pad_caps (GstPad * pad)
684 GstCaps *caps = NULL;
687 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
689 gst_event_parse_caps (ev->event, &caps);
695 gst_pad_dispose (GObject * object)
697 GstPad *pad = GST_PAD_CAST (object);
700 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
702 /* unlink the peer pad */
703 if ((peer = gst_pad_get_peer (pad))) {
704 /* window for MT unsafeness, someone else could unlink here
705 * and then we call unlink with wrong pads. The unlink
706 * function would catch this and safely return failed. */
707 if (GST_PAD_IS_SRC (pad))
708 gst_pad_unlink (pad, peer);
710 gst_pad_unlink (peer, pad);
712 gst_object_unref (peer);
715 gst_pad_set_pad_template (pad, NULL);
717 GST_OBJECT_LOCK (pad);
719 GST_OBJECT_UNLOCK (pad);
721 g_hook_list_clear (&pad->probes);
723 G_OBJECT_CLASS (parent_class)->dispose (object);
727 gst_pad_finalize (GObject * object)
729 GstPad *pad = GST_PAD_CAST (object);
732 /* in case the task is still around, clean it up */
733 if ((task = GST_PAD_TASK (pad))) {
734 gst_task_join (task);
735 GST_PAD_TASK (pad) = NULL;
736 gst_object_unref (task);
739 if (pad->activatenotify)
740 pad->activatenotify (pad->activatedata);
741 if (pad->activatemodenotify)
742 pad->activatemodenotify (pad->activatemodedata);
744 pad->linknotify (pad->linkdata);
745 if (pad->unlinknotify)
746 pad->unlinknotify (pad->unlinkdata);
747 if (pad->chainnotify)
748 pad->chainnotify (pad->chaindata);
749 if (pad->chainlistnotify)
750 pad->chainlistnotify (pad->chainlistdata);
751 if (pad->getrangenotify)
752 pad->getrangenotify (pad->getrangedata);
753 if (pad->eventnotify)
754 pad->eventnotify (pad->eventdata);
755 if (pad->querynotify)
756 pad->querynotify (pad->querydata);
757 if (pad->iterintlinknotify)
758 pad->iterintlinknotify (pad->iterintlinkdata);
760 g_rec_mutex_clear (&pad->stream_rec_lock);
761 g_cond_clear (&pad->block_cond);
762 g_array_free (pad->priv->events, TRUE);
764 G_OBJECT_CLASS (parent_class)->finalize (object);
768 gst_pad_set_property (GObject * object, guint prop_id,
769 const GValue * value, GParamSpec * pspec)
771 g_return_if_fail (GST_IS_PAD (object));
774 case PAD_PROP_DIRECTION:
775 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
777 case PAD_PROP_TEMPLATE:
778 gst_pad_set_pad_template (GST_PAD_CAST (object),
779 (GstPadTemplate *) g_value_get_object (value));
781 case PAD_PROP_OFFSET:
782 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
785 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
791 gst_pad_get_property (GObject * object, guint prop_id,
792 GValue * value, GParamSpec * pspec)
794 g_return_if_fail (GST_IS_PAD (object));
798 GST_OBJECT_LOCK (object);
799 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
800 GST_OBJECT_UNLOCK (object);
802 case PAD_PROP_DIRECTION:
803 g_value_set_enum (value, GST_PAD_DIRECTION (object));
805 case PAD_PROP_TEMPLATE:
806 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
808 case PAD_PROP_OFFSET:
809 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
812 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
819 * @name: (allow-none): the name of the new pad.
820 * @direction: the #GstPadDirection of the pad.
822 * Creates a new pad with the given name in the given direction.
823 * If name is %NULL, a guaranteed unique name (across all pads)
825 * This function makes a copy of the name so you can safely free the name.
827 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
833 gst_pad_new (const gchar * name, GstPadDirection direction)
835 return g_object_new (GST_TYPE_PAD,
836 "name", name, "direction", direction, NULL);
840 * gst_pad_new_from_template:
841 * @templ: the pad template to use
842 * @name: (allow-none): the name of the pad
844 * Creates a new pad with the given name from the given template.
845 * If name is %NULL, a guaranteed unique name (across all pads)
847 * This function makes a copy of the name so you can safely free the name.
849 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
853 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
855 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
857 return g_object_new (GST_TYPE_PAD,
858 "name", name, "direction", templ->direction, "template", templ, NULL);
862 * gst_pad_new_from_static_template:
863 * @templ: the #GstStaticPadTemplate to use
864 * @name: the name of the pad
866 * Creates a new pad with the given name from the given static template.
867 * If name is %NULL, a guaranteed unique name (across all pads)
869 * This function makes a copy of the name so you can safely free the name.
871 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
875 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
879 GstPadTemplate *template;
881 template = gst_static_pad_template_get (templ);
882 pad = gst_pad_new_from_template (template, name);
883 gst_object_unref (template);
887 #define ACQUIRE_PARENT(pad, parent, label) \
889 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
890 gst_object_ref (parent); \
891 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
895 #define RELEASE_PARENT(parent) \
897 if (G_LIKELY (parent)) \
898 gst_object_unref (parent); \
902 * gst_pad_get_direction:
903 * @pad: a #GstPad to get the direction of.
905 * Gets the direction of the pad. The direction of the pad is
906 * decided at construction time so this function does not take
909 * Returns: the #GstPadDirection of the pad.
914 gst_pad_get_direction (GstPad * pad)
916 GstPadDirection result;
918 /* PAD_UNKNOWN is a little silly but we need some sort of
919 * error return value */
920 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
922 result = GST_PAD_DIRECTION (pad);
928 gst_pad_activate_default (GstPad * pad, GstObject * parent)
930 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
932 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
936 * gst_pad_mode_get_name:
937 * @mode: the pad mode
939 * Return the name of a pad mode, for use in debug messages mostly.
941 * Returns: short mnemonic for pad mode @mode
944 gst_pad_mode_get_name (GstPadMode mode)
947 case GST_PAD_MODE_NONE:
949 case GST_PAD_MODE_PUSH:
951 case GST_PAD_MODE_PULL:
960 pre_activate (GstPad * pad, GstPadMode new_mode)
963 case GST_PAD_MODE_NONE:
964 GST_OBJECT_LOCK (pad);
965 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
966 GST_PAD_SET_FLUSHING (pad);
967 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
968 GST_PAD_MODE (pad) = new_mode;
969 /* unlock blocked pads so element can resume and stop */
970 GST_PAD_BLOCK_BROADCAST (pad);
971 GST_OBJECT_UNLOCK (pad);
973 case GST_PAD_MODE_PUSH:
974 case GST_PAD_MODE_PULL:
975 GST_OBJECT_LOCK (pad);
976 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
977 gst_pad_mode_get_name (new_mode));
978 GST_PAD_UNSET_FLUSHING (pad);
979 pad->ABI.abi.last_flowret = GST_FLOW_OK;
980 GST_PAD_MODE (pad) = new_mode;
981 if (GST_PAD_IS_SINK (pad)) {
983 /* make sure the peer src pad sends us all events */
984 if ((peer = GST_PAD_PEER (pad))) {
985 gst_object_ref (peer);
986 GST_OBJECT_UNLOCK (pad);
988 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
989 GST_DEBUG_PAD_NAME (peer));
991 GST_OBJECT_LOCK (peer);
992 schedule_events (peer, NULL);
993 GST_OBJECT_UNLOCK (peer);
995 gst_object_unref (peer);
997 GST_OBJECT_UNLOCK (pad);
1000 GST_OBJECT_UNLOCK (pad);
1007 post_activate (GstPad * pad, GstPadMode new_mode)
1010 case GST_PAD_MODE_NONE:
1011 /* ensures that streaming stops */
1012 GST_PAD_STREAM_LOCK (pad);
1013 GST_DEBUG_OBJECT (pad, "stopped streaming");
1014 GST_OBJECT_LOCK (pad);
1015 remove_events (pad);
1016 GST_OBJECT_UNLOCK (pad);
1017 GST_PAD_STREAM_UNLOCK (pad);
1019 case GST_PAD_MODE_PUSH:
1020 case GST_PAD_MODE_PULL:
1027 * gst_pad_set_active:
1028 * @pad: the #GstPad to activate or deactivate.
1029 * @active: whether or not the pad should be active.
1031 * Activates or deactivates the given pad.
1032 * Normally called from within core state change functions.
1034 * If @active, makes sure the pad is active. If it is already active, either in
1035 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1036 * function to perform the actual activation.
1038 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1039 * and a %FALSE argument.
1041 * Returns: %TRUE if the operation was successful.
1046 gst_pad_set_active (GstPad * pad, gboolean active)
1050 gboolean ret = FALSE;
1052 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1054 GST_OBJECT_LOCK (pad);
1055 old = GST_PAD_MODE (pad);
1056 ACQUIRE_PARENT (pad, parent, no_parent);
1057 GST_OBJECT_UNLOCK (pad);
1060 if (old == GST_PAD_MODE_NONE) {
1061 GST_DEBUG_OBJECT (pad, "activating pad from none");
1062 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1064 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1066 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1067 gst_pad_mode_get_name (old));
1071 if (old == GST_PAD_MODE_NONE) {
1072 GST_DEBUG_OBJECT (pad, "pad was inactive");
1075 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1076 gst_pad_mode_get_name (old));
1077 ret = activate_mode_internal (pad, parent, old, FALSE);
1079 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1083 RELEASE_PARENT (parent);
1085 if (G_UNLIKELY (!ret))
1093 GST_DEBUG_OBJECT (pad, "no parent");
1094 GST_OBJECT_UNLOCK (pad);
1099 GST_OBJECT_LOCK (pad);
1101 g_critical ("Failed to deactivate pad %s:%s, very bad",
1102 GST_DEBUG_PAD_NAME (pad));
1104 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1106 GST_OBJECT_UNLOCK (pad);
1112 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1115 gboolean res = FALSE;
1116 GstPadMode old, new;
1117 GstPadDirection dir;
1120 GST_OBJECT_LOCK (pad);
1121 old = GST_PAD_MODE (pad);
1122 dir = GST_PAD_DIRECTION (pad);
1123 GST_OBJECT_UNLOCK (pad);
1125 new = active ? mode : GST_PAD_MODE_NONE;
1130 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1131 /* pad was activate in the wrong direction, deactivate it
1132 * and reactivate it in the requested mode */
1133 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1134 gst_pad_mode_get_name (old));
1136 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1137 goto deactivate_failed;
1141 case GST_PAD_MODE_PULL:
1143 if (dir == GST_PAD_SINK) {
1144 if ((peer = gst_pad_get_peer (pad))) {
1145 GST_DEBUG_OBJECT (pad, "calling peer");
1146 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1148 gst_object_unref (peer);
1150 /* there is no peer, this is only fatal when we activate. When we
1151 * deactivate, we must assume the application has unlinked the peer and
1152 * will deactivate it eventually. */
1156 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1159 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1160 goto failure; /* Can't activate pull on a src without a
1161 getrange function */
1169 /* Mark pad as needing reconfiguration */
1171 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1172 pre_activate (pad, new);
1174 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1175 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1179 /* can happen for sinks of passthrough elements */
1182 post_activate (pad, new);
1184 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1185 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1190 /* Clear sticky flags on deactivation */
1192 GST_OBJECT_LOCK (pad);
1193 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1194 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1195 GST_OBJECT_UNLOCK (pad);
1203 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1204 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1209 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1210 "failed to %s in switch to %s mode from %s mode",
1211 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1212 gst_pad_mode_get_name (old));
1217 GST_OBJECT_LOCK (peer);
1218 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1219 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1220 GST_OBJECT_UNLOCK (peer);
1221 gst_object_unref (peer);
1226 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1227 "pad in pull mode");
1232 GST_OBJECT_LOCK (pad);
1233 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1234 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1235 GST_PAD_SET_FLUSHING (pad);
1236 GST_PAD_MODE (pad) = old;
1237 GST_OBJECT_UNLOCK (pad);
1243 * gst_pad_activate_mode:
1244 * @pad: the #GstPad to activate or deactivate.
1245 * @mode: the requested activation mode
1246 * @active: whether or not the pad should be active.
1248 * Activates or deactivates the given pad in @mode via dispatching to the
1249 * pad's activatemodefunc. For use from within pad activation functions only.
1251 * If you don't know what this is, you probably don't want to call it.
1253 * Returns: %TRUE if the operation was successful.
1258 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1263 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1265 GST_OBJECT_LOCK (pad);
1266 ACQUIRE_PARENT (pad, parent, no_parent);
1267 GST_OBJECT_UNLOCK (pad);
1269 res = activate_mode_internal (pad, parent, mode, active);
1271 RELEASE_PARENT (parent);
1277 GST_WARNING_OBJECT (pad, "no parent");
1278 GST_OBJECT_UNLOCK (pad);
1284 * gst_pad_is_active:
1285 * @pad: the #GstPad to query
1287 * Query if a pad is active
1289 * Returns: %TRUE if the pad is active.
1294 gst_pad_is_active (GstPad * pad)
1296 gboolean result = FALSE;
1298 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1300 GST_OBJECT_LOCK (pad);
1301 result = GST_PAD_IS_ACTIVE (pad);
1302 GST_OBJECT_UNLOCK (pad);
1308 cleanup_hook (GstPad * pad, GHook * hook)
1310 GstPadProbeType type;
1312 if (!G_HOOK_IS_VALID (hook))
1315 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1317 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1318 /* unblock when we remove the last blocking probe */
1320 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1323 /* Might have new probes now that want to be called */
1324 GST_PAD_BLOCK_BROADCAST (pad);
1326 if (pad->num_blocked == 0) {
1327 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1328 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1331 g_hook_destroy_link (&pad->probes, hook);
1336 * gst_pad_add_probe:
1337 * @pad: the #GstPad to add the probe to
1338 * @mask: the probe mask
1339 * @callback: #GstPadProbeCallback that will be called with notifications of
1341 * @user_data: (closure): user data passed to the callback
1342 * @destroy_data: #GDestroyNotify for user_data
1344 * Be notified of different states of pads. The provided callback is called for
1345 * every state that matches @mask.
1347 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1348 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1349 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1350 * immediately if the pad is already idle while calling gst_pad_add_probe().
1351 * In each of the groups, probes are called in the order in which they were
1354 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1355 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1356 * happen that the probe can be run immediately and if the probe returns
1357 * GST_PAD_PROBE_REMOVE this functions returns 0.
1362 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1363 GstPadProbeCallback callback, gpointer user_data,
1364 GDestroyNotify destroy_data)
1369 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1370 g_return_val_if_fail (mask != 0, 0);
1372 GST_OBJECT_LOCK (pad);
1374 /* make a new probe */
1375 hook = g_hook_alloc (&pad->probes);
1377 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1380 /* when no contraints are given for the types, assume all types are
1382 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1383 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1384 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1385 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1387 /* store our flags and other fields */
1388 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1389 hook->func = callback;
1390 hook->data = user_data;
1391 hook->destroy = destroy_data;
1392 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1395 g_hook_append (&pad->probes, hook);
1397 /* incremenent cookie so that the new hook get's called */
1398 pad->priv->probe_list_cookie++;
1400 /* get the id of the hook, we return this and it can be used to remove the
1402 res = hook->hook_id;
1404 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1406 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1407 /* we have a block probe */
1409 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1410 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1411 "now %d blocking probes", pad->num_blocked);
1413 /* Might have new probes now that want to be called */
1414 GST_PAD_BLOCK_BROADCAST (pad);
1417 /* call the callback if we need to be called for idle callbacks */
1418 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1419 if (pad->priv->using > 0) {
1420 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1421 * flag above, the last thread to leave the push will do the callback. New
1422 * threads going into the push will block. */
1423 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1424 "pad is in use, delay idle callback");
1425 GST_OBJECT_UNLOCK (pad);
1427 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1428 GstPadProbeReturn ret;
1430 /* Keep another ref, the callback could destroy the pad */
1431 gst_object_ref (pad);
1432 pad->priv->idle_running++;
1434 /* the pad is idle now, we can signal the idle callback now */
1435 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1436 "pad is idle, trigger idle callback");
1437 GST_OBJECT_UNLOCK (pad);
1439 ret = callback (pad, &info, user_data);
1441 GST_OBJECT_LOCK (pad);
1443 case GST_PAD_PROBE_REMOVE:
1444 /* remove the probe */
1445 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1446 cleanup_hook (pad, hook);
1449 case GST_PAD_PROBE_DROP:
1450 GST_DEBUG_OBJECT (pad, "asked to drop item");
1452 case GST_PAD_PROBE_PASS:
1453 GST_DEBUG_OBJECT (pad, "asked to pass item");
1455 case GST_PAD_PROBE_OK:
1456 GST_DEBUG_OBJECT (pad, "probe returned OK");
1458 case GST_PAD_PROBE_HANDLED:
1459 GST_DEBUG_OBJECT (pad, "probe handled the data");
1462 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1465 pad->priv->idle_running--;
1466 if (pad->priv->idle_running == 0) {
1467 GST_PAD_BLOCK_BROADCAST (pad);
1469 GST_OBJECT_UNLOCK (pad);
1471 gst_object_unref (pad);
1474 GST_OBJECT_UNLOCK (pad);
1480 * gst_pad_remove_probe:
1481 * @pad: the #GstPad with the probe
1482 * @id: the probe id to remove
1484 * Remove the probe with @id from @pad.
1489 gst_pad_remove_probe (GstPad * pad, gulong id)
1493 g_return_if_fail (GST_IS_PAD (pad));
1495 GST_OBJECT_LOCK (pad);
1497 hook = g_hook_get (&pad->probes, id);
1501 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1503 cleanup_hook (pad, hook);
1504 GST_OBJECT_UNLOCK (pad);
1510 GST_OBJECT_UNLOCK (pad);
1511 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1517 * gst_pad_is_blocked:
1518 * @pad: the #GstPad to query
1520 * Checks if the pad is blocked or not. This function returns the
1521 * last requested state of the pad. It is not certain that the pad
1522 * is actually blocking at this point (see gst_pad_is_blocking()).
1524 * Returns: %TRUE if the pad is blocked.
1529 gst_pad_is_blocked (GstPad * pad)
1531 gboolean result = FALSE;
1533 g_return_val_if_fail (GST_IS_PAD (pad), result);
1535 GST_OBJECT_LOCK (pad);
1536 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1537 GST_OBJECT_UNLOCK (pad);
1543 * gst_pad_is_blocking:
1544 * @pad: the #GstPad to query
1546 * Checks if the pad is blocking or not. This is a guaranteed state
1547 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1549 * Returns: %TRUE if the pad is blocking.
1554 gst_pad_is_blocking (GstPad * pad)
1556 gboolean result = FALSE;
1558 g_return_val_if_fail (GST_IS_PAD (pad), result);
1560 GST_OBJECT_LOCK (pad);
1561 /* the blocking flag is only valid if the pad is not flushing */
1562 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1563 GST_OBJECT_UNLOCK (pad);
1569 * gst_pad_needs_reconfigure:
1570 * @pad: the #GstPad to check
1572 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1573 * if the flag was set.
1575 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1578 gst_pad_needs_reconfigure (GstPad * pad)
1580 gboolean reconfigure;
1582 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1584 GST_OBJECT_LOCK (pad);
1585 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1586 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1587 GST_OBJECT_UNLOCK (pad);
1593 * gst_pad_check_reconfigure:
1594 * @pad: the #GstPad to check
1596 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1597 * if the flag was set.
1599 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1602 gst_pad_check_reconfigure (GstPad * pad)
1604 gboolean reconfigure;
1606 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1608 GST_OBJECT_LOCK (pad);
1609 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1611 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1612 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1614 GST_OBJECT_UNLOCK (pad);
1620 * gst_pad_mark_reconfigure:
1621 * @pad: the #GstPad to mark
1623 * Mark a pad for needing reconfiguration. The next call to
1624 * gst_pad_check_reconfigure() will return %TRUE after this call.
1627 gst_pad_mark_reconfigure (GstPad * pad)
1629 g_return_if_fail (GST_IS_PAD (pad));
1631 GST_OBJECT_LOCK (pad);
1632 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1633 GST_OBJECT_UNLOCK (pad);
1637 * gst_pad_set_activate_function:
1639 * @f: the #GstPadActivateFunction to set.
1641 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1645 * gst_pad_set_activate_function_full:
1647 * @activate: the #GstPadActivateFunction to set.
1648 * @user_data: user_data passed to @notify
1649 * @notify: notify called when @activate will not be used anymore.
1651 * Sets the given activate function for @pad. The activate function will
1652 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1653 * Only makes sense to set on sink pads.
1655 * Call this function if your sink pad can start a pull-based task.
1658 gst_pad_set_activate_function_full (GstPad * pad,
1659 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1661 g_return_if_fail (GST_IS_PAD (pad));
1663 if (pad->activatenotify)
1664 pad->activatenotify (pad->activatedata);
1665 GST_PAD_ACTIVATEFUNC (pad) = activate;
1666 pad->activatedata = user_data;
1667 pad->activatenotify = notify;
1669 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1670 GST_DEBUG_FUNCPTR_NAME (activate));
1674 * gst_pad_set_activatemode_function:
1676 * @f: the #GstPadActivateModeFunction to set.
1678 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1682 * gst_pad_set_activatemode_function_full:
1684 * @activatemode: the #GstPadActivateModeFunction to set.
1685 * @user_data: user_data passed to @notify
1686 * @notify: notify called when @activatemode will not be used anymore.
1688 * Sets the given activate_mode function for the pad. An activate_mode function
1689 * prepares the element for data passing.
1692 gst_pad_set_activatemode_function_full (GstPad * pad,
1693 GstPadActivateModeFunction activatemode, gpointer user_data,
1694 GDestroyNotify notify)
1696 g_return_if_fail (GST_IS_PAD (pad));
1698 if (pad->activatemodenotify)
1699 pad->activatemodenotify (pad->activatemodedata);
1700 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1701 pad->activatemodedata = user_data;
1702 pad->activatemodenotify = notify;
1704 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1705 GST_DEBUG_FUNCPTR_NAME (activatemode));
1709 * gst_pad_set_chain_function:
1710 * @p: a sink #GstPad.
1711 * @f: the #GstPadChainFunction to set.
1713 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1717 * gst_pad_set_chain_function_full:
1718 * @pad: a sink #GstPad.
1719 * @chain: the #GstPadChainFunction to set.
1720 * @user_data: user_data passed to @notify
1721 * @notify: notify called when @chain will not be used anymore.
1723 * Sets the given chain function for the pad. The chain function is called to
1724 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1727 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1728 gpointer user_data, GDestroyNotify notify)
1730 g_return_if_fail (GST_IS_PAD (pad));
1731 g_return_if_fail (GST_PAD_IS_SINK (pad));
1733 if (pad->chainnotify)
1734 pad->chainnotify (pad->chaindata);
1735 GST_PAD_CHAINFUNC (pad) = chain;
1736 pad->chaindata = user_data;
1737 pad->chainnotify = notify;
1739 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1740 GST_DEBUG_FUNCPTR_NAME (chain));
1744 * gst_pad_set_chain_list_function:
1745 * @p: a sink #GstPad.
1746 * @f: the #GstPadChainListFunction to set.
1748 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1752 * gst_pad_set_chain_list_function_full:
1753 * @pad: a sink #GstPad.
1754 * @chainlist: the #GstPadChainListFunction to set.
1755 * @user_data: user_data passed to @notify
1756 * @notify: notify called when @chainlist will not be used anymore.
1758 * Sets the given chain list function for the pad. The chainlist function is
1759 * called to process a #GstBufferList input buffer list. See
1760 * #GstPadChainListFunction for more details.
1763 gst_pad_set_chain_list_function_full (GstPad * pad,
1764 GstPadChainListFunction chainlist, gpointer user_data,
1765 GDestroyNotify notify)
1767 g_return_if_fail (GST_IS_PAD (pad));
1768 g_return_if_fail (GST_PAD_IS_SINK (pad));
1770 if (pad->chainlistnotify)
1771 pad->chainlistnotify (pad->chainlistdata);
1772 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1773 pad->chainlistdata = user_data;
1774 pad->chainlistnotify = notify;
1776 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1777 GST_DEBUG_FUNCPTR_NAME (chainlist));
1781 * gst_pad_set_getrange_function:
1782 * @p: a source #GstPad.
1783 * @f: the #GstPadGetRangeFunction to set.
1785 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1789 * gst_pad_set_getrange_function_full:
1790 * @pad: a source #GstPad.
1791 * @get: the #GstPadGetRangeFunction to set.
1792 * @user_data: user_data passed to @notify
1793 * @notify: notify called when @get will not be used anymore.
1795 * Sets the given getrange function for the pad. The getrange function is
1796 * called to produce a new #GstBuffer to start the processing pipeline. see
1797 * #GstPadGetRangeFunction for a description of the getrange function.
1800 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1801 gpointer user_data, GDestroyNotify notify)
1803 g_return_if_fail (GST_IS_PAD (pad));
1804 g_return_if_fail (GST_PAD_IS_SRC (pad));
1806 if (pad->getrangenotify)
1807 pad->getrangenotify (pad->getrangedata);
1808 GST_PAD_GETRANGEFUNC (pad) = get;
1809 pad->getrangedata = user_data;
1810 pad->getrangenotify = notify;
1812 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1813 GST_DEBUG_FUNCPTR_NAME (get));
1817 * gst_pad_set_event_function:
1818 * @p: a #GstPad of either direction.
1819 * @f: the #GstPadEventFunction to set.
1821 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1825 * gst_pad_set_event_function_full:
1826 * @pad: a #GstPad of either direction.
1827 * @event: the #GstPadEventFunction to set.
1828 * @user_data: user_data passed to @notify
1829 * @notify: notify called when @event will not be used anymore.
1831 * Sets the given event handler for the pad.
1834 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1835 gpointer user_data, GDestroyNotify notify)
1837 g_return_if_fail (GST_IS_PAD (pad));
1839 if (pad->eventnotify)
1840 pad->eventnotify (pad->eventdata);
1841 GST_PAD_EVENTFUNC (pad) = event;
1842 pad->eventdata = user_data;
1843 pad->eventnotify = notify;
1845 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1846 GST_DEBUG_FUNCPTR_NAME (event));
1850 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1854 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1855 if (ret == GST_FLOW_OK)
1861 * gst_pad_set_event_full_function:
1862 * @p: a #GstPad of either direction.
1863 * @f: the #GstPadEventFullFunction to set.
1865 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1869 * gst_pad_set_event_full_function_full:
1870 * @pad: a #GstPad of either direction.
1871 * @event: the #GstPadEventFullFunction to set.
1872 * @user_data: user_data passed to @notify
1873 * @notify: notify called when @event will not be used anymore.
1875 * Sets the given event handler for the pad.
1880 gst_pad_set_event_full_function_full (GstPad * pad,
1881 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1883 g_return_if_fail (GST_IS_PAD (pad));
1885 if (pad->eventnotify)
1886 pad->eventnotify (pad->eventdata);
1887 GST_PAD_EVENTFULLFUNC (pad) = event;
1888 GST_PAD_EVENTFUNC (pad) = event_wrap;
1889 pad->eventdata = user_data;
1890 pad->eventnotify = notify;
1892 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1893 GST_DEBUG_FUNCPTR_NAME (event));
1897 * gst_pad_set_query_function:
1898 * @p: a #GstPad of either direction.
1899 * @f: the #GstPadQueryFunction to set.
1901 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1905 * gst_pad_set_query_function_full:
1906 * @pad: a #GstPad of either direction.
1907 * @query: the #GstPadQueryFunction to set.
1908 * @user_data: user_data passed to @notify
1909 * @notify: notify called when @query will not be used anymore.
1911 * Set the given query function for the pad.
1914 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1915 gpointer user_data, GDestroyNotify notify)
1917 g_return_if_fail (GST_IS_PAD (pad));
1919 if (pad->querynotify)
1920 pad->querynotify (pad->querydata);
1921 GST_PAD_QUERYFUNC (pad) = query;
1922 pad->querydata = user_data;
1923 pad->querynotify = notify;
1925 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1926 GST_DEBUG_FUNCPTR_NAME (query));
1930 * gst_pad_set_iterate_internal_links_function:
1931 * @p: a #GstPad of either direction.
1932 * @f: the #GstPadIterIntLinkFunction to set.
1934 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1935 * for the user_data and notify.
1938 * gst_pad_set_iterate_internal_links_function_full:
1939 * @pad: a #GstPad of either direction.
1940 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1941 * @user_data: user_data passed to @notify
1942 * @notify: notify called when @iterintlink will not be used anymore.
1944 * Sets the given internal link iterator function for the pad.
1947 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1948 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1949 GDestroyNotify notify)
1951 g_return_if_fail (GST_IS_PAD (pad));
1953 if (pad->iterintlinknotify)
1954 pad->iterintlinknotify (pad->iterintlinkdata);
1955 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1956 pad->iterintlinkdata = user_data;
1957 pad->iterintlinknotify = notify;
1959 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1960 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1964 * gst_pad_set_link_function:
1966 * @f: the #GstPadLinkFunction to set.
1968 * Calls gst_pad_set_link_function_full() with %NULL
1969 * for the user_data and notify.
1972 * gst_pad_set_link_function_full:
1974 * @link: the #GstPadLinkFunction to set.
1975 * @user_data: user_data passed to @notify
1976 * @notify: notify called when @link will not be used anymore.
1978 * Sets the given link function for the pad. It will be called when
1979 * the pad is linked with another pad.
1981 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1984 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1985 * cannot be made for some reason.
1987 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1988 * of the peer sink pad, if present.
1991 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1992 gpointer user_data, GDestroyNotify notify)
1994 g_return_if_fail (GST_IS_PAD (pad));
1996 if (pad->linknotify)
1997 pad->linknotify (pad->linkdata);
1998 GST_PAD_LINKFUNC (pad) = link;
1999 pad->linkdata = user_data;
2000 pad->linknotify = notify;
2002 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2003 GST_DEBUG_FUNCPTR_NAME (link));
2007 * gst_pad_set_unlink_function:
2009 * @f: the #GstPadUnlinkFunction to set.
2011 * Calls gst_pad_set_unlink_function_full() with %NULL
2012 * for the user_data and notify.
2015 * gst_pad_set_unlink_function_full:
2017 * @unlink: the #GstPadUnlinkFunction to set.
2018 * @user_data: user_data passed to @notify
2019 * @notify: notify called when @unlink will not be used anymore.
2021 * Sets the given unlink function for the pad. It will be called
2022 * when the pad is unlinked.
2025 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2026 gpointer user_data, GDestroyNotify notify)
2028 g_return_if_fail (GST_IS_PAD (pad));
2030 if (pad->unlinknotify)
2031 pad->unlinknotify (pad->unlinkdata);
2032 GST_PAD_UNLINKFUNC (pad) = unlink;
2033 pad->unlinkdata = user_data;
2034 pad->unlinknotify = notify;
2036 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2037 GST_DEBUG_FUNCPTR_NAME (unlink));
2042 * @srcpad: the source #GstPad to unlink.
2043 * @sinkpad: the sink #GstPad to unlink.
2045 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2046 * signal on both pads.
2048 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2049 * the pads were not linked together.
2054 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2056 gboolean result = FALSE;
2057 GstElement *parent = NULL;
2059 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2060 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2061 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2062 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2064 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2066 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2067 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2068 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2070 /* We need to notify the parent before taking any pad locks as the bin in
2071 * question might be waiting for a lock on the pad while holding its lock
2072 * that our message will try to take. */
2073 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2074 if (GST_IS_ELEMENT (parent)) {
2075 gst_element_post_message (parent,
2076 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2077 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2079 gst_object_unref (parent);
2084 GST_OBJECT_LOCK (srcpad);
2085 GST_OBJECT_LOCK (sinkpad);
2087 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2088 goto not_linked_together;
2090 if (GST_PAD_UNLINKFUNC (srcpad)) {
2091 GstObject *tmpparent;
2093 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2095 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2096 RELEASE_PARENT (tmpparent);
2099 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2100 GstObject *tmpparent;
2102 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2104 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2105 RELEASE_PARENT (tmpparent);
2109 /* first clear peers */
2110 GST_PAD_PEER (srcpad) = NULL;
2111 GST_PAD_PEER (sinkpad) = NULL;
2113 GST_OBJECT_UNLOCK (sinkpad);
2114 GST_OBJECT_UNLOCK (srcpad);
2116 /* fire off a signal to each of the pads telling them
2117 * that they've been unlinked */
2118 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2119 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2121 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2122 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2127 if (parent != NULL) {
2128 gst_element_post_message (parent,
2129 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2130 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2131 gst_object_unref (parent);
2133 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2137 not_linked_together:
2139 /* we do not emit a warning in this case because unlinking cannot
2140 * be made MT safe.*/
2141 GST_OBJECT_UNLOCK (sinkpad);
2142 GST_OBJECT_UNLOCK (srcpad);
2148 * gst_pad_is_linked:
2149 * @pad: pad to check
2151 * Checks if a @pad is linked to another pad or not.
2153 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2158 gst_pad_is_linked (GstPad * pad)
2162 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2164 GST_OBJECT_LOCK (pad);
2165 result = (GST_PAD_PEER (pad) != NULL);
2166 GST_OBJECT_UNLOCK (pad);
2171 /* get the caps from both pads and see if the intersection
2174 * This function should be called with the pad LOCK on both
2178 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2179 GstPadLinkCheck flags)
2181 GstCaps *srccaps = NULL;
2182 GstCaps *sinkcaps = NULL;
2183 gboolean compatible = FALSE;
2185 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2188 /* Doing the expensive caps checking takes priority over only checking the template caps */
2189 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2190 GST_OBJECT_UNLOCK (sink);
2191 GST_OBJECT_UNLOCK (src);
2193 srccaps = gst_pad_query_caps (src, NULL);
2194 sinkcaps = gst_pad_query_caps (sink, NULL);
2196 GST_OBJECT_LOCK (src);
2197 GST_OBJECT_LOCK (sink);
2199 /* If one of the two pads doesn't have a template, consider the intersection
2201 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2202 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2206 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2208 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2211 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2216 /* if we have caps on both pads we can check the intersection. If one
2217 * of the caps is %NULL, we return %TRUE. */
2218 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2220 gst_caps_unref (srccaps);
2222 gst_caps_unref (sinkcaps);
2226 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2227 gst_caps_unref (srccaps);
2228 gst_caps_unref (sinkcaps);
2231 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2232 (compatible ? "" : "not "));
2237 /* check if the grandparents of both pads are the same.
2238 * This check is required so that we don't try to link
2239 * pads from elements in different bins without ghostpads.
2241 * The LOCK should be held on both pads
2244 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2246 GstObject *psrc, *psink;
2248 psrc = GST_OBJECT_PARENT (src);
2249 psink = GST_OBJECT_PARENT (sink);
2251 /* if one of the pads has no parent, we allow the link */
2252 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2255 /* only care about parents that are elements */
2256 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2257 goto no_element_parent;
2259 /* if the parents are the same, we have a loop */
2260 if (G_UNLIKELY (psrc == psink))
2263 /* if they both have a parent, we check the grandparents. We can not lock
2264 * the parent because we hold on the child (pad) and the locking order is
2265 * parent >> child. */
2266 psrc = GST_OBJECT_PARENT (psrc);
2267 psink = GST_OBJECT_PARENT (psink);
2269 /* if they have grandparents but they are not the same */
2270 if (G_UNLIKELY (psrc != psink))
2271 goto wrong_grandparents;
2278 GST_CAT_DEBUG (GST_CAT_CAPS,
2279 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2280 GST_PTR_FORMAT, psrc, psink);
2285 GST_CAT_DEBUG (GST_CAT_CAPS,
2286 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2287 GST_PTR_FORMAT, psrc, psink);
2292 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2298 GST_CAT_DEBUG (GST_CAT_CAPS,
2299 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2300 GST_PTR_FORMAT, psrc, psink);
2305 /* FIXME leftover from an attempt at refactoring... */
2306 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2307 * the two pads will be locked in the srcpad, sinkpad order. */
2308 static GstPadLinkReturn
2309 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2311 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2312 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2314 GST_OBJECT_LOCK (srcpad);
2316 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2317 goto src_was_linked;
2319 GST_OBJECT_LOCK (sinkpad);
2321 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2322 goto sink_was_linked;
2324 /* check hierarchy, pads can only be linked if the grandparents
2326 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2327 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2328 goto wrong_hierarchy;
2330 /* check pad caps for non-empty intersection */
2331 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2334 /* FIXME check pad scheduling for non-empty intersection */
2336 return GST_PAD_LINK_OK;
2340 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2341 GST_DEBUG_PAD_NAME (srcpad),
2342 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2343 /* we do not emit a warning in this case because unlinking cannot
2344 * be made MT safe.*/
2345 GST_OBJECT_UNLOCK (srcpad);
2346 return GST_PAD_LINK_WAS_LINKED;
2350 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2351 GST_DEBUG_PAD_NAME (sinkpad),
2352 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2353 /* we do not emit a warning in this case because unlinking cannot
2354 * be made MT safe.*/
2355 GST_OBJECT_UNLOCK (sinkpad);
2356 GST_OBJECT_UNLOCK (srcpad);
2357 return GST_PAD_LINK_WAS_LINKED;
2361 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2362 GST_OBJECT_UNLOCK (sinkpad);
2363 GST_OBJECT_UNLOCK (srcpad);
2364 return GST_PAD_LINK_WRONG_HIERARCHY;
2368 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2369 GST_OBJECT_UNLOCK (sinkpad);
2370 GST_OBJECT_UNLOCK (srcpad);
2371 return GST_PAD_LINK_NOFORMAT;
2377 * @srcpad: the source #GstPad.
2378 * @sinkpad: the sink #GstPad.
2380 * Checks if the source pad and the sink pad are compatible so they can be
2383 * Returns: %TRUE if the pads can be linked.
2386 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2388 GstPadLinkReturn result;
2390 /* generic checks */
2391 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2392 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2394 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2395 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2397 /* gst_pad_link_prepare does everything for us, we only release the locks
2398 * on the pads that it gets us. If this function returns !OK the locks are not
2400 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2401 if (result != GST_PAD_LINK_OK)
2404 GST_OBJECT_UNLOCK (srcpad);
2405 GST_OBJECT_UNLOCK (sinkpad);
2408 return result == GST_PAD_LINK_OK;
2412 * gst_pad_link_full:
2413 * @srcpad: the source #GstPad to link.
2414 * @sinkpad: the sink #GstPad to link.
2415 * @flags: the checks to validate when linking
2417 * Links the source pad and the sink pad.
2419 * This variant of #gst_pad_link provides a more granular control on the
2420 * checks being done when linking. While providing some considerable speedups
2421 * the caller of this method must be aware that wrong usage of those flags
2422 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2423 * for more information.
2427 * Returns: A result code indicating if the connection worked or
2431 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2433 GstPadLinkReturn result;
2435 GstPadLinkFunction srcfunc, sinkfunc;
2437 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2438 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2439 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2440 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2441 GST_PAD_LINK_WRONG_DIRECTION);
2443 /* Notify the parent early. See gst_pad_unlink for details. */
2444 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2445 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2446 gst_element_post_message (parent,
2447 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2448 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2450 gst_object_unref (parent);
2455 /* prepare will also lock the two pads */
2456 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2458 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2459 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2460 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2461 gst_pad_link_get_name (result));
2465 /* must set peers before calling the link function */
2466 GST_PAD_PEER (srcpad) = sinkpad;
2467 GST_PAD_PEER (sinkpad) = srcpad;
2469 /* check events, when something is different, mark pending */
2470 schedule_events (srcpad, sinkpad);
2472 /* get the link functions */
2473 srcfunc = GST_PAD_LINKFUNC (srcpad);
2474 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2476 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2477 /* custom link functions, execute them */
2478 GST_OBJECT_UNLOCK (sinkpad);
2479 GST_OBJECT_UNLOCK (srcpad);
2482 GstObject *tmpparent;
2484 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2485 /* this one will call the peer link function */
2486 result = srcfunc (srcpad, tmpparent, sinkpad);
2487 RELEASE_PARENT (tmpparent);
2488 } else if (sinkfunc) {
2489 GstObject *tmpparent;
2491 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2492 /* if no source link function, we need to call the sink link
2493 * function ourselves. */
2494 result = sinkfunc (sinkpad, tmpparent, srcpad);
2495 RELEASE_PARENT (tmpparent);
2499 GST_OBJECT_LOCK (srcpad);
2500 GST_OBJECT_LOCK (sinkpad);
2502 /* we released the lock, check if the same pads are linked still */
2503 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2504 goto concurrent_link;
2506 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2509 GST_OBJECT_UNLOCK (sinkpad);
2510 GST_OBJECT_UNLOCK (srcpad);
2512 /* fire off a signal to each of the pads telling them
2513 * that they've been linked */
2514 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2515 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2517 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2518 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2520 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2523 if (G_LIKELY (parent)) {
2524 gst_element_post_message (parent,
2525 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2526 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2527 gst_object_unref (parent);
2535 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2536 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2537 GST_OBJECT_UNLOCK (sinkpad);
2538 GST_OBJECT_UNLOCK (srcpad);
2540 /* The other link operation succeeded first */
2541 result = GST_PAD_LINK_WAS_LINKED;
2546 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2547 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2548 gst_pad_link_get_name (result));
2550 GST_PAD_PEER (srcpad) = NULL;
2551 GST_PAD_PEER (sinkpad) = NULL;
2553 GST_OBJECT_UNLOCK (sinkpad);
2554 GST_OBJECT_UNLOCK (srcpad);
2562 * @srcpad: the source #GstPad to link.
2563 * @sinkpad: the sink #GstPad to link.
2565 * Links the source pad and the sink pad.
2567 * Returns: A result code indicating if the connection worked or
2573 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2575 GstPadLinkReturn ret;
2577 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2578 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2579 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, ret);
2585 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2587 GstPadTemplate **template_p;
2589 /* this function would need checks if it weren't static */
2591 GST_OBJECT_LOCK (pad);
2592 template_p = &pad->padtemplate;
2593 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2594 GST_OBJECT_UNLOCK (pad);
2597 gst_pad_template_pad_created (templ, pad);
2601 * gst_pad_get_pad_template:
2604 * Gets the template for @pad.
2606 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2607 * this pad was instantiated, or %NULL if this pad has no
2608 * template. Unref after usage.
2611 gst_pad_get_pad_template (GstPad * pad)
2613 GstPadTemplate *templ;
2615 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2617 templ = GST_PAD_PAD_TEMPLATE (pad);
2619 return (templ ? gst_object_ref (templ) : NULL);
2623 * gst_pad_has_current_caps:
2624 * @pad: a #GstPad to check
2626 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2628 * Returns: %TRUE when @pad has caps associated with it.
2631 gst_pad_has_current_caps (GstPad * pad)
2636 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2638 GST_OBJECT_LOCK (pad);
2639 caps = get_pad_caps (pad);
2640 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2641 "check current pad caps %" GST_PTR_FORMAT, caps);
2642 result = (caps != NULL);
2643 GST_OBJECT_UNLOCK (pad);
2649 * gst_pad_get_current_caps:
2650 * @pad: a #GstPad to get the current capabilities of.
2652 * Gets the capabilities currently configured on @pad with the last
2653 * #GST_EVENT_CAPS event.
2655 * Returns: (transfer full) (nullable): the current caps of the pad with
2656 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2659 gst_pad_get_current_caps (GstPad * pad)
2663 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2665 GST_OBJECT_LOCK (pad);
2666 if ((result = get_pad_caps (pad)))
2667 gst_caps_ref (result);
2668 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2669 "get current pad caps %" GST_PTR_FORMAT, result);
2670 GST_OBJECT_UNLOCK (pad);
2676 * gst_pad_get_pad_template_caps:
2677 * @pad: a #GstPad to get the template capabilities from.
2679 * Gets the capabilities for @pad's template.
2681 * Returns: (transfer full): the #GstCaps of this pad template.
2682 * Unref after usage.
2685 gst_pad_get_pad_template_caps (GstPad * pad)
2687 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2689 if (GST_PAD_PAD_TEMPLATE (pad))
2690 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2692 return gst_caps_ref (GST_CAPS_ANY);
2697 * @pad: a #GstPad to get the peer of.
2699 * Gets the peer of @pad. This function refs the peer pad so
2700 * you need to unref it after use.
2702 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2707 gst_pad_get_peer (GstPad * pad)
2711 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2713 GST_OBJECT_LOCK (pad);
2714 result = GST_PAD_PEER (pad);
2716 gst_object_ref (result);
2717 GST_OBJECT_UNLOCK (pad);
2723 * gst_pad_get_allowed_caps:
2726 * Gets the capabilities of the allowed media types that can flow through
2727 * @pad and its peer.
2729 * The allowed capabilities is calculated as the intersection of the results of
2730 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2731 * on the resulting caps.
2733 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2734 * pad link. Unref the caps when you no longer need it. This
2735 * function returns %NULL when @pad has no peer.
2740 gst_pad_get_allowed_caps (GstPad * pad)
2743 GstCaps *caps = NULL;
2746 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2748 GST_OBJECT_LOCK (pad);
2749 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2751 GST_OBJECT_UNLOCK (pad);
2753 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2755 mycaps = gst_pad_query_caps (pad, NULL);
2757 /* Query peer caps */
2758 query = gst_query_new_caps (mycaps);
2759 gst_pad_peer_query (pad, query);
2760 gst_query_parse_caps_result (query, &caps);
2761 gst_caps_ref (caps);
2762 gst_query_unref (query);
2764 gst_caps_unref (mycaps);
2766 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2773 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2774 GST_OBJECT_UNLOCK (pad);
2781 * gst_pad_iterate_internal_links_default:
2782 * @pad: the #GstPad to get the internal links of.
2783 * @parent: (allow-none): the parent of @pad or %NULL
2785 * Iterate the list of pads to which the given pad is linked to inside of
2786 * the parent element.
2787 * This is the default handler, and thus returns an iterator of all of the
2788 * pads inside the parent element with opposite direction.
2790 * The caller must free this iterator after use with gst_iterator_free().
2792 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2793 * has no parent. Unref each returned pad with gst_object_unref().
2796 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2803 GstElement *eparent;
2805 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2807 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2808 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2810 GST_OBJECT_LOCK (pad);
2811 eparent = GST_PAD_PARENT (pad);
2812 if (!eparent || !GST_IS_ELEMENT (eparent))
2815 gst_object_ref (eparent);
2816 GST_OBJECT_UNLOCK (pad);
2819 if (pad->direction == GST_PAD_SRC)
2820 padlist = &eparent->sinkpads;
2822 padlist = &eparent->srcpads;
2824 GST_DEBUG_OBJECT (pad, "Making iterator");
2826 cookie = &eparent->pads_cookie;
2828 lock = GST_OBJECT_GET_LOCK (eparent);
2830 res = gst_iterator_new_list (GST_TYPE_PAD,
2831 lock, cookie, padlist, (GObject *) owner, NULL);
2833 gst_object_unref (owner);
2840 GST_OBJECT_UNLOCK (pad);
2841 GST_DEBUG_OBJECT (pad, "no parent element");
2847 * gst_pad_iterate_internal_links:
2848 * @pad: the GstPad to get the internal links of.
2850 * Gets an iterator for the pads to which the given pad is linked to inside
2851 * of the parent element.
2853 * Each #GstPad element yielded by the iterator will have its refcount increased,
2854 * so unref after use.
2856 * Free-function: gst_iterator_free
2858 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2859 * or %NULL when the pad does not have an iterator function
2860 * configured. Use gst_iterator_free() after usage.
2863 gst_pad_iterate_internal_links (GstPad * pad)
2865 GstIterator *res = NULL;
2868 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2870 GST_OBJECT_LOCK (pad);
2871 ACQUIRE_PARENT (pad, parent, no_parent);
2872 GST_OBJECT_UNLOCK (pad);
2874 if (GST_PAD_ITERINTLINKFUNC (pad))
2875 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2877 RELEASE_PARENT (parent);
2884 GST_DEBUG_OBJECT (pad, "no parent");
2885 GST_OBJECT_UNLOCK (pad);
2893 * @forward: (scope call): a #GstPadForwardFunction
2894 * @user_data: user data passed to @forward
2896 * Calls @forward for all internally linked pads of @pad. This function deals with
2897 * dynamically changing internal pads and will make sure that the @forward
2898 * function is only called once for each pad.
2900 * When @forward returns %TRUE, no further pads will be processed.
2902 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2905 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2908 gboolean result = FALSE;
2910 gboolean done = FALSE;
2911 GValue item = { 0, };
2912 GList *pushed_pads = NULL;
2914 iter = gst_pad_iterate_internal_links (pad);
2920 switch (gst_iterator_next (iter, &item)) {
2921 case GST_ITERATOR_OK:
2925 intpad = g_value_get_object (&item);
2927 /* if already pushed, skip. FIXME, find something faster to tag pads */
2928 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2929 g_value_reset (&item);
2933 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2934 GST_DEBUG_PAD_NAME (intpad));
2935 done = result = forward (intpad, user_data);
2937 pushed_pads = g_list_prepend (pushed_pads, intpad);
2939 g_value_reset (&item);
2942 case GST_ITERATOR_RESYNC:
2943 /* We don't reset the result here because we don't push the event
2944 * again on pads that got the event already and because we need
2945 * to consider the result of the previous pushes */
2946 gst_iterator_resync (iter);
2948 case GST_ITERATOR_ERROR:
2949 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2952 case GST_ITERATOR_DONE:
2957 g_value_unset (&item);
2958 gst_iterator_free (iter);
2960 g_list_free (pushed_pads);
2970 gboolean dispatched;
2974 event_forward_func (GstPad * pad, EventData * data)
2976 /* for each pad we send to, we should ref the event; it's up
2977 * to downstream to unref again when handled. */
2978 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2979 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2981 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2983 data->dispatched = TRUE;
2990 * gst_pad_event_default:
2991 * @pad: a #GstPad to call the default event handler on.
2992 * @parent: (allow-none): the parent of @pad or %NULL
2993 * @event: (transfer full): the #GstEvent to handle.
2995 * Invokes the default event handler for the given pad.
2997 * The EOS event will pause the task associated with @pad before it is forwarded
2998 * to all internally linked pads,
3000 * The event is sent to all pads internally linked to @pad. This function
3001 * takes ownership of @event.
3003 * Returns: %TRUE if the event was sent successfully.
3006 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3008 gboolean result, forward = TRUE;
3010 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3011 g_return_val_if_fail (event != NULL, FALSE);
3013 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3016 switch (GST_EVENT_TYPE (event)) {
3017 case GST_EVENT_CAPS:
3018 forward = GST_PAD_IS_PROXY_CAPS (pad);
3029 data.dispatched = FALSE;
3030 data.result = FALSE;
3032 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3034 /* for sinkpads without a parent element or without internal links, nothing
3035 * will be dispatched but we still want to return TRUE. */
3036 if (data.dispatched)
3037 result = data.result;
3042 gst_event_unref (event);
3047 /* Default accept caps implementation just checks against
3048 * the allowed caps for the pad */
3050 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3052 /* get the caps and see if it intersects to something not empty */
3053 GstCaps *caps, *allowed = NULL;
3056 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3058 /* first forward the query to internally linked pads when we are dealing with
3060 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3061 result = gst_pad_proxy_query_accept_caps (pad, query);
3063 allowed = gst_pad_get_pad_template_caps (pad);
3068 gst_query_parse_accept_caps (query, &caps);
3070 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3071 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3072 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad))
3073 allowed = gst_pad_get_pad_template_caps (pad);
3075 allowed = gst_pad_query_caps (pad, caps);
3079 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3080 GST_DEBUG_OBJECT (pad,
3081 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3083 result = gst_caps_can_intersect (caps, allowed);
3085 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3086 GST_PTR_FORMAT, allowed, caps);
3087 result = gst_caps_is_subset (caps, allowed);
3089 gst_caps_unref (allowed);
3091 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3094 gst_query_set_accept_caps_result (query, result);
3100 /* Default caps implementation */
3102 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3104 GstCaps *result = NULL, *filter;
3105 GstPadTemplate *templ;
3106 gboolean fixed_caps;
3108 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3111 /* first try to proxy if we must */
3112 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3113 if ((gst_pad_proxy_query_caps (pad, query))) {
3118 gst_query_parse_caps (query, &filter);
3120 /* no proxy or it failed, do default handling */
3121 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3123 GST_OBJECT_LOCK (pad);
3125 /* fixed caps, try the negotiated caps first */
3126 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3127 if ((result = get_pad_caps (pad)))
3128 goto filter_done_unlock;
3131 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3132 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3133 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3134 goto filter_done_unlock;
3138 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3139 "non-fixed pad caps: trying pad caps");
3140 /* non fixed caps, try the negotiated caps */
3141 if ((result = get_pad_caps (pad)))
3142 goto filter_done_unlock;
3145 /* this almost never happens */
3146 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3147 result = GST_CAPS_ANY;
3150 GST_OBJECT_UNLOCK (pad);
3152 /* run the filter on the result */
3154 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3155 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3156 GST_PTR_FORMAT, result, result, filter, filter);
3157 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3158 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3161 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3162 "using caps %p %" GST_PTR_FORMAT, result, result);
3163 result = gst_caps_ref (result);
3165 gst_query_set_caps_result (query, result);
3166 gst_caps_unref (result);
3172 /* Default latency implementation */
3176 GstClockTime min, max;
3180 query_latency_default_fold (const GValue * item, GValue * ret,
3183 GstPad *pad = g_value_get_object (item), *peer;
3184 LatencyFoldData *fold_data = user_data;
3186 gboolean res = FALSE;
3188 query = gst_query_new_latency ();
3190 peer = gst_pad_get_peer (pad);
3192 res = gst_pad_peer_query (pad, query);
3194 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3199 GstClockTime min, max;
3201 gst_query_parse_latency (query, &live, &min, &max);
3203 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3204 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3207 if (min > fold_data->min)
3208 fold_data->min = min;
3210 if (fold_data->max == GST_CLOCK_TIME_NONE)
3211 fold_data->max = max;
3212 else if (max < fold_data->max)
3213 fold_data->max = max;
3215 fold_data->live = TRUE;
3218 GST_DEBUG_OBJECT (pad, "latency query failed");
3219 g_value_set_boolean (ret, FALSE);
3222 gst_query_unref (query);
3224 gst_object_unref (peer);
3230 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3233 GstIteratorResult res;
3234 GValue ret = G_VALUE_INIT;
3236 LatencyFoldData fold_data;
3238 it = gst_pad_iterate_internal_links (pad);
3240 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3244 g_value_init (&ret, G_TYPE_BOOLEAN);
3247 fold_data.live = FALSE;
3249 fold_data.max = GST_CLOCK_TIME_NONE;
3251 g_value_set_boolean (&ret, TRUE);
3252 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3254 case GST_ITERATOR_OK:
3255 g_assert_not_reached ();
3257 case GST_ITERATOR_DONE:
3259 case GST_ITERATOR_ERROR:
3260 g_value_set_boolean (&ret, FALSE);
3262 case GST_ITERATOR_RESYNC:
3263 gst_iterator_resync (it);
3266 g_assert_not_reached ();
3269 gst_iterator_free (it);
3271 query_ret = g_value_get_boolean (&ret);
3273 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3274 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3275 fold_data.min, fold_data.max);
3277 if (fold_data.min > fold_data.max) {
3278 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3281 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3283 GST_LOG_OBJECT (pad, "latency query failed");
3293 gboolean dispatched;
3297 query_forward_func (GstPad * pad, QueryData * data)
3299 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3300 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3302 data->result |= gst_pad_peer_query (pad, data->query);
3304 data->dispatched = TRUE;
3306 /* stop on first successful reply */
3307 return data->result;
3311 * gst_pad_query_default:
3312 * @pad: a #GstPad to call the default query handler on.
3313 * @parent: (allow-none): the parent of @pad or %NULL
3314 * @query: (transfer none): the #GstQuery to handle.
3316 * Invokes the default query handler for the given pad.
3317 * The query is sent to all pads internally linked to @pad. Note that
3318 * if there are many possible sink pads that are internally linked to
3319 * @pad, only one will be sent the query.
3320 * Multi-sinkpad elements should implement custom query handlers.
3322 * Returns: %TRUE if the query was performed successfully.
3325 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3327 gboolean forward, ret = FALSE;
3329 switch (GST_QUERY_TYPE (query)) {
3330 case GST_QUERY_SCHEDULING:
3331 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3333 case GST_QUERY_ALLOCATION:
3334 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3336 case GST_QUERY_ACCEPT_CAPS:
3337 ret = gst_pad_query_accept_caps_default (pad, query);
3340 case GST_QUERY_CAPS:
3341 ret = gst_pad_query_caps_default (pad, query);
3344 case GST_QUERY_LATENCY:
3345 ret = gst_pad_query_latency_default (pad, query);
3348 case GST_QUERY_POSITION:
3349 case GST_QUERY_SEEKING:
3350 case GST_QUERY_FORMATS:
3351 case GST_QUERY_JITTER:
3352 case GST_QUERY_RATE:
3353 case GST_QUERY_CONVERT:
3359 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3360 query, GST_QUERY_TYPE_NAME (query));
3366 data.dispatched = FALSE;
3367 data.result = FALSE;
3369 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3371 if (data.dispatched) {
3374 /* nothing dispatched, assume drained */
3375 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3385 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3387 GstPad *pad = data->pad;
3388 GstPadProbeInfo *info = data->info;
3389 GstPadProbeType type, flags;
3390 GstPadProbeCallback callback;
3391 GstPadProbeReturn ret;
3392 gpointer original_data;
3394 /* if we have called this callback, do nothing */
3395 if (PROBE_COOKIE (hook) == data->cookie) {
3396 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3397 "hook %lu, cookie %u already called", hook->hook_id,
3398 PROBE_COOKIE (hook));
3402 PROBE_COOKIE (hook) = data->cookie;
3404 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3406 original_data = info->data;
3408 /* one of the data types for non-idle probes */
3409 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3410 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3412 /* one of the scheduling types */
3413 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3415 /* one of the blocking types must match */
3416 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3417 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3419 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3420 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3422 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3423 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3424 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3427 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3428 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3429 PROBE_COOKIE (hook), flags);
3431 data->marshalled = TRUE;
3433 callback = (GstPadProbeCallback) hook->func;
3434 if (callback == NULL)
3437 info->id = hook->hook_id;
3439 GST_OBJECT_UNLOCK (pad);
3441 ret = callback (pad, info, hook->data);
3443 GST_OBJECT_LOCK (pad);
3445 if (original_data != NULL && info->data == NULL) {
3446 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3447 info->type = GST_PAD_PROBE_TYPE_INVALID;
3448 data->dropped = TRUE;
3452 case GST_PAD_PROBE_REMOVE:
3453 /* remove the probe */
3454 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3455 cleanup_hook (pad, hook);
3457 case GST_PAD_PROBE_DROP:
3458 /* need to drop the data, make sure other probes don't get called
3460 GST_DEBUG_OBJECT (pad, "asked to drop item");
3461 info->type = GST_PAD_PROBE_TYPE_INVALID;
3462 data->dropped = TRUE;
3464 case GST_PAD_PROBE_HANDLED:
3465 GST_DEBUG_OBJECT (pad, "probe handled data");
3466 data->handled = TRUE;
3468 case GST_PAD_PROBE_PASS:
3469 /* inform the pad block to let things pass */
3470 GST_DEBUG_OBJECT (pad, "asked to pass item");
3473 case GST_PAD_PROBE_OK:
3474 GST_DEBUG_OBJECT (pad, "probe returned OK");
3477 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3484 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3485 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3486 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3491 /* a probe that does not take or return any data */
3492 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3494 if (G_UNLIKELY (pad->num_probes)) { \
3495 GstFlowReturn pval = defaultval; \
3496 /* pass NULL as the data item */ \
3497 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3498 info.ABI.abi.flow_ret = defaultval; \
3499 ret = do_probe_callbacks (pad, &info, defaultval); \
3500 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3505 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3507 if (G_UNLIKELY (pad->num_probes)) { \
3508 /* pass the data item */ \
3509 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3510 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3511 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3512 /* store the possibly updated data item */ \
3513 data = GST_PAD_PROBE_INFO_DATA (&info); \
3514 /* if something went wrong, exit */ \
3515 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3516 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3517 ret = info.ABI.abi.flow_ret; \
3518 goto handle_label; \
3525 #define PROBE_PUSH(pad,mask,data,label) \
3526 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3527 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3528 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3529 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3530 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3532 static GstFlowReturn
3533 do_pad_idle_probe_wait (GstPad * pad)
3535 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3536 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3537 "waiting idle probe to be removed");
3538 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3539 GST_PAD_BLOCK_WAIT (pad);
3540 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3541 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3543 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3544 return GST_FLOW_FLUSHING;
3549 #define PROBE_TYPE_IS_SERIALIZED(i) \
3552 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3553 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3554 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3556 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3557 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3559 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3560 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3564 static GstFlowReturn
3565 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3566 GstFlowReturn defaultval)
3575 data.handled = FALSE;
3576 data.marshalled = FALSE;
3577 data.dropped = FALSE;
3578 data.cookie = ++pad->priv->probe_cookie;
3581 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3583 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3584 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3589 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3590 "do probes cookie %u", data.cookie);
3591 cookie = pad->priv->probe_list_cookie;
3593 g_hook_list_marshal (&pad->probes, TRUE,
3594 (GHookMarshaller) probe_hook_marshal, &data);
3596 /* if the list changed, call the new callbacks (they will not have their
3597 * cookie set to data.cookie */
3598 if (cookie != pad->priv->probe_list_cookie) {
3599 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3600 "probe list changed, restarting");
3604 /* the first item that dropped will stop the hooks and then we drop here */
3608 /* If one handler took care of it, let the the item pass */
3613 /* if no handler matched and we are blocking, let the item pass */
3614 if (!data.marshalled && is_block)
3617 /* At this point, all handlers returned either OK or PASS. If one handler
3618 * returned PASS, let the item pass */
3623 while (GST_PAD_IS_BLOCKED (pad)) {
3624 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3625 "we are blocked %d times", pad->num_blocked);
3627 /* we might have released the lock */
3628 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3631 /* now we block the streaming thread. It can be unlocked when we
3632 * deactivate the pad (which will also set the FLUSHING flag) or
3633 * when the pad is unblocked. A flushing event will also unblock
3634 * the pad after setting the FLUSHING flag. */
3635 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3636 "Waiting to be unblocked or set flushing");
3637 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3638 GST_PAD_BLOCK_WAIT (pad);
3639 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3640 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3642 /* if the list changed, call the new callbacks (they will not have their
3643 * cookie set to data.cookie */
3644 if (cookie != pad->priv->probe_list_cookie) {
3645 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3646 "probe list changed, restarting");
3650 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3660 GST_DEBUG_OBJECT (pad, "pad is flushing");
3661 return GST_FLOW_FLUSHING;
3665 GST_DEBUG_OBJECT (pad, "data is dropped");
3666 return GST_FLOW_CUSTOM_SUCCESS;
3670 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3671 GST_DEBUG_OBJECT (pad, "data is passed");
3676 GST_DEBUG_OBJECT (pad, "data was handled");
3677 return GST_FLOW_CUSTOM_SUCCESS_1;
3684 * gst_pad_get_offset:
3687 * Get the offset applied to the running time of @pad. @pad has to be a source
3690 * Returns: the offset.
3693 gst_pad_get_offset (GstPad * pad)
3697 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3699 GST_OBJECT_LOCK (pad);
3700 result = pad->offset;
3701 GST_OBJECT_UNLOCK (pad);
3707 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3709 ev->received = FALSE;
3714 * gst_pad_set_offset:
3716 * @offset: the offset
3718 * Set the offset that will be applied to the running time of @pad.
3721 gst_pad_set_offset (GstPad * pad, gint64 offset)
3723 g_return_if_fail (GST_IS_PAD (pad));
3725 GST_OBJECT_LOCK (pad);
3726 /* if nothing changed, do nothing */
3727 if (pad->offset == offset)
3730 pad->offset = offset;
3731 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3733 /* resend all sticky events with updated offset on next buffer push */
3734 events_foreach (pad, mark_event_not_received, NULL);
3735 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3738 GST_OBJECT_UNLOCK (pad);
3745 /* If TRUE and ret is not OK this means
3746 * that pushing the EOS event failed
3750 /* If called for an event this is
3751 * the event that would be pushed
3752 * next. Don't forward sticky events
3753 * that would come after that */
3757 /* should be called with pad LOCK */
3759 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3761 PushStickyData *data = user_data;
3762 GstEvent *event = ev->event;
3765 GST_DEBUG_OBJECT (pad, "event %s was already received",
3766 GST_EVENT_TYPE_NAME (event));
3770 /* If we're called because of an sticky event, only forward
3771 * events that would come before this new event and the
3773 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3774 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3775 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3776 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3778 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3779 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3782 switch (data->ret) {
3784 ev->received = TRUE;
3785 GST_DEBUG_OBJECT (pad, "event %s marked received",
3786 GST_EVENT_TYPE_NAME (event));
3788 case GST_FLOW_CUSTOM_SUCCESS:
3789 /* we can't assume the event is received when it was dropped */
3790 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3791 GST_EVENT_TYPE_NAME (event));
3792 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3793 data->ret = GST_FLOW_OK;
3795 case GST_FLOW_CUSTOM_SUCCESS_1:
3796 /* event was ignored and should be sent later */
3797 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3798 GST_EVENT_TYPE_NAME (event));
3799 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3800 data->ret = GST_FLOW_OK;
3802 case GST_FLOW_NOT_LINKED:
3803 /* not linked is not a problem, we are sticky so the event will be
3804 * rescheduled to be sent later on re-link, but only for non-EOS events */
3805 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3806 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3807 data->ret = GST_FLOW_OK;
3808 ev->received = TRUE;
3812 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3813 gst_flow_get_name (data->ret));
3814 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3818 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3819 data->was_eos = TRUE;
3821 return data->ret == GST_FLOW_OK;
3824 /* check sticky events and push them when needed. should be called
3826 static inline GstFlowReturn
3827 check_sticky (GstPad * pad, GstEvent * event)
3829 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3831 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3832 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3834 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3835 events_foreach (pad, push_sticky, &data);
3837 /* If there's an EOS event we must push it downstream
3838 * even if sending a previous sticky event failed.
3839 * Otherwise the pipeline might wait forever for EOS.
3841 * Only do this if pushing another event than the EOS
3844 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3845 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3847 if (ev && !ev->received) {
3848 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3849 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3850 /* the event could have been dropped. Because this can only
3851 * happen if the user asked for it, it's not an error */
3852 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3853 data.ret = GST_FLOW_OK;
3863 * @pad: a #GstPad to invoke the default query on.
3864 * @query: (transfer none): the #GstQuery to perform.
3866 * Dispatches a query to a pad. The query should have been allocated by the
3867 * caller via one of the type-specific allocation functions. The element that
3868 * the pad belongs to is responsible for filling the query with an appropriate
3869 * response, which should then be parsed with a type-specific query parsing
3872 * Again, the caller is responsible for both the allocation and deallocation of
3873 * the query structure.
3875 * Please also note that some queries might need a running pipeline to work.
3877 * Returns: %TRUE if the query could be performed.
3880 gst_pad_query (GstPad * pad, GstQuery * query)
3883 gboolean res, serialized;
3884 GstPadQueryFunction func;
3885 GstPadProbeType type;
3888 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3889 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3891 if (GST_PAD_IS_SRC (pad)) {
3892 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3893 goto wrong_direction;
3894 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3895 } else if (GST_PAD_IS_SINK (pad)) {
3896 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3897 goto wrong_direction;
3898 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3900 goto unknown_direction;
3902 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3903 GST_QUERY_TYPE_NAME (query));
3904 GST_TRACER_PAD_QUERY_PRE (pad, query);
3906 serialized = GST_QUERY_IS_SERIALIZED (query);
3907 if (G_UNLIKELY (serialized))
3908 GST_PAD_STREAM_LOCK (pad);
3910 GST_OBJECT_LOCK (pad);
3911 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3912 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3913 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3915 ACQUIRE_PARENT (pad, parent, no_parent);
3916 GST_OBJECT_UNLOCK (pad);
3918 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3921 res = func (pad, parent, query);
3923 RELEASE_PARENT (parent);
3925 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3926 GST_QUERY_TYPE_NAME (query), res);
3927 GST_TRACER_PAD_QUERY_POST (pad, query, res);
3932 GST_OBJECT_LOCK (pad);
3933 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3934 GST_OBJECT_UNLOCK (pad);
3936 if (G_UNLIKELY (serialized))
3937 GST_PAD_STREAM_UNLOCK (pad);
3944 g_warning ("pad %s:%s query %s in wrong direction",
3945 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3950 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3955 GST_DEBUG_OBJECT (pad, "had no parent");
3956 GST_OBJECT_UNLOCK (pad);
3957 if (G_UNLIKELY (serialized))
3958 GST_PAD_STREAM_UNLOCK (pad);
3963 GST_DEBUG_OBJECT (pad, "had no query function");
3964 RELEASE_PARENT (parent);
3965 if (G_UNLIKELY (serialized))
3966 GST_PAD_STREAM_UNLOCK (pad);
3971 GST_DEBUG_OBJECT (pad, "query failed");
3972 if (G_UNLIKELY (serialized))
3973 GST_PAD_STREAM_UNLOCK (pad);
3978 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3979 GST_OBJECT_UNLOCK (pad);
3980 if (G_UNLIKELY (serialized))
3981 GST_PAD_STREAM_UNLOCK (pad);
3983 /* if a probe dropped without handling, we don't sent it further but assume
3984 * that the probe did not answer the query and return FALSE */
3985 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
3995 * gst_pad_peer_query:
3996 * @pad: a #GstPad to invoke the peer query on.
3997 * @query: (transfer none): the #GstQuery to perform.
3999 * Performs gst_pad_query() on the peer of @pad.
4001 * The caller is responsible for both the allocation and deallocation of
4002 * the query structure.
4004 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4005 * if @pad has no peer.
4008 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4011 GstPadProbeType type;
4012 gboolean res, serialized;
4015 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4016 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4018 if (GST_PAD_IS_SRC (pad)) {
4019 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4020 goto wrong_direction;
4021 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4022 } else if (GST_PAD_IS_SINK (pad)) {
4023 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4024 goto wrong_direction;
4025 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4027 goto unknown_direction;
4029 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4030 GST_QUERY_TYPE_NAME (query));
4032 serialized = GST_QUERY_IS_SERIALIZED (query);
4034 GST_OBJECT_LOCK (pad);
4035 if (GST_PAD_IS_SRC (pad) && serialized) {
4036 /* all serialized queries on the srcpad trigger push of
4038 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4042 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4043 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4044 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4046 peerpad = GST_PAD_PEER (pad);
4047 if (G_UNLIKELY (peerpad == NULL))
4050 gst_object_ref (peerpad);
4051 GST_OBJECT_UNLOCK (pad);
4053 res = gst_pad_query (peerpad, query);
4055 gst_object_unref (peerpad);
4060 GST_OBJECT_LOCK (pad);
4061 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4062 GST_OBJECT_UNLOCK (pad);
4069 g_warning ("pad %s:%s query %s in wrong direction",
4070 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4075 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4080 GST_WARNING_OBJECT (pad, "could not send sticky events");
4081 GST_OBJECT_UNLOCK (pad);
4086 GST_INFO_OBJECT (pad, "pad has no peer");
4087 GST_OBJECT_UNLOCK (pad);
4092 GST_DEBUG_OBJECT (pad, "query failed");
4097 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4098 GST_OBJECT_UNLOCK (pad);
4100 /* if a probe dropped without handling, we don't sent it further but
4101 * assume that the probe did not answer the query and return FALSE */
4102 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4111 /**********************************************************************
4112 * Data passing functions
4115 /* this is the chain function that does not perform the additional argument
4116 * checking for that little extra speed.
4118 static inline GstFlowReturn
4119 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4123 gboolean handled = FALSE;
4125 GST_PAD_STREAM_LOCK (pad);
4127 GST_OBJECT_LOCK (pad);
4128 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4131 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4134 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4137 #ifdef GST_ENABLE_EXTRA_CHECKS
4138 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4139 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4141 ":%s:<%s:%s> Got data flow before stream-start event",
4142 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4144 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4146 ":%s:<%s:%s> Got data flow before segment event",
4147 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4149 pad->priv->last_cookie = pad->priv->events_cookie;
4153 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4156 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4158 ACQUIRE_PARENT (pad, parent, no_parent);
4159 GST_OBJECT_UNLOCK (pad);
4161 /* NOTE: we read the chainfunc unlocked.
4162 * we cannot hold the lock for the pad so we might send
4163 * the data to the wrong function. This is not really a
4164 * problem since functions are assigned at creation time
4165 * and don't change that often... */
4166 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4167 GstPadChainFunction chainfunc;
4169 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4172 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4173 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4174 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4176 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4178 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4179 "called chainfunction &%s with buffer %p, returned %s",
4180 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4182 GstPadChainListFunction chainlistfunc;
4184 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4187 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4188 "calling chainlistfunction &%s",
4189 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4191 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4193 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4194 "called chainlistfunction &%s, returned %s",
4195 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4198 RELEASE_PARENT (parent);
4200 GST_PAD_STREAM_UNLOCK (pad);
4207 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4208 "chaining, but pad was flushing");
4209 GST_OBJECT_UNLOCK (pad);
4210 GST_PAD_STREAM_UNLOCK (pad);
4211 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4212 return GST_FLOW_FLUSHING;
4216 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4217 GST_OBJECT_UNLOCK (pad);
4218 GST_PAD_STREAM_UNLOCK (pad);
4219 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4220 return GST_FLOW_EOS;
4224 g_critical ("chain on pad %s:%s but it was not in push mode",
4225 GST_DEBUG_PAD_NAME (pad));
4226 GST_OBJECT_UNLOCK (pad);
4227 GST_PAD_STREAM_UNLOCK (pad);
4228 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4229 return GST_FLOW_ERROR;
4236 GST_OBJECT_UNLOCK (pad);
4237 GST_PAD_STREAM_UNLOCK (pad);
4238 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4240 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4243 case GST_FLOW_CUSTOM_SUCCESS:
4244 case GST_FLOW_CUSTOM_SUCCESS_1:
4245 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4249 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4256 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4257 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4258 GST_OBJECT_UNLOCK (pad);
4259 GST_PAD_STREAM_UNLOCK (pad);
4260 return GST_FLOW_FLUSHING;
4264 RELEASE_PARENT (parent);
4265 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4266 g_critical ("chain on pad %s:%s but it has no chainfunction",
4267 GST_DEBUG_PAD_NAME (pad));
4268 GST_PAD_STREAM_UNLOCK (pad);
4269 return GST_FLOW_NOT_SUPPORTED;
4275 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4276 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4279 * Chain a buffer to @pad.
4281 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4283 * If the buffer type is not acceptable for @pad (as negotiated with a
4284 * preceding GST_EVENT_CAPS event), this function returns
4285 * #GST_FLOW_NOT_NEGOTIATED.
4287 * The function proceeds calling the chain function installed on @pad (see
4288 * gst_pad_set_chain_function()) and the return value of that function is
4289 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4292 * In all cases, success or failure, the caller loses its reference to @buffer
4293 * after calling this function.
4295 * Returns: a #GstFlowReturn from the pad.
4300 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4302 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4303 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4304 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4306 return gst_pad_chain_data_unchecked (pad,
4307 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4310 static GstFlowReturn
4311 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4312 GstBufferList * list)
4318 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4320 len = gst_buffer_list_length (list);
4323 for (i = 0; i < len; i++) {
4324 buffer = gst_buffer_list_get (list, i);
4326 gst_pad_chain_data_unchecked (pad,
4327 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4328 gst_buffer_ref (buffer));
4329 if (ret != GST_FLOW_OK)
4332 gst_buffer_list_unref (list);
4338 * gst_pad_chain_list:
4339 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4340 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4343 * Chain a bufferlist to @pad.
4345 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4347 * If @pad was not negotiated properly with a CAPS event, this function
4348 * returns #GST_FLOW_NOT_NEGOTIATED.
4350 * The function proceeds calling the chainlist function installed on @pad (see
4351 * gst_pad_set_chain_list_function()) and the return value of that function is
4352 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4353 * chainlist function.
4355 * In all cases, success or failure, the caller loses its reference to @list
4356 * after calling this function.
4360 * Returns: a #GstFlowReturn from the pad.
4363 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4365 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4366 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4367 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4369 return gst_pad_chain_data_unchecked (pad,
4370 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4373 static GstFlowReturn
4374 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4378 gboolean handled = FALSE;
4380 GST_OBJECT_LOCK (pad);
4381 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4384 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4387 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4390 #ifdef GST_ENABLE_EXTRA_CHECKS
4391 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4392 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4394 ":%s:<%s:%s> Got data flow before stream-start event",
4395 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4397 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4399 ":%s:<%s:%s> Got data flow before segment event",
4400 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4402 pad->priv->last_cookie = pad->priv->events_cookie;
4406 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4409 /* do block probes */
4410 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4413 /* recheck sticky events because the probe might have cause a relink */
4414 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4417 /* do post-blocking probes */
4418 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4420 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4423 /* take ref to peer pad before releasing the lock */
4424 gst_object_ref (peer);
4426 GST_OBJECT_UNLOCK (pad);
4428 ret = gst_pad_chain_data_unchecked (peer, type, data);
4431 gst_object_unref (peer);
4433 GST_OBJECT_LOCK (pad);
4434 pad->ABI.abi.last_flowret = ret;
4436 if (pad->priv->using == 0) {
4437 /* pad is not active anymore, trigger idle callbacks */
4438 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4439 probe_stopped, ret);
4441 GST_OBJECT_UNLOCK (pad);
4445 /* ERROR recovery here */
4449 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4450 "pushing, but pad was flushing");
4451 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4452 GST_OBJECT_UNLOCK (pad);
4453 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4454 return GST_FLOW_FLUSHING;
4458 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4459 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4460 GST_OBJECT_UNLOCK (pad);
4461 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4462 return GST_FLOW_EOS;
4466 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4467 GST_DEBUG_PAD_NAME (pad));
4468 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4469 GST_OBJECT_UNLOCK (pad);
4470 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4471 return GST_FLOW_ERROR;
4475 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4476 "error pushing events, return %s", gst_flow_get_name (ret));
4477 pad->ABI.abi.last_flowret = ret;
4478 GST_OBJECT_UNLOCK (pad);
4479 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4487 GST_OBJECT_UNLOCK (pad);
4488 if (data != NULL && !handled)
4489 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4492 case GST_FLOW_CUSTOM_SUCCESS:
4493 case GST_FLOW_CUSTOM_SUCCESS_1:
4494 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4498 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4501 pad->ABI.abi.last_flowret = ret;
4506 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4507 "pushing, but it was not linked");
4508 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4509 GST_OBJECT_UNLOCK (pad);
4510 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4511 return GST_FLOW_NOT_LINKED;
4517 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4518 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4521 * Pushes a buffer to the peer of @pad.
4523 * This function will call installed block probes before triggering any
4524 * installed data probes.
4526 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4527 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4530 * In all cases, success or failure, the caller loses its reference to @buffer
4531 * after calling this function.
4533 * Returns: a #GstFlowReturn from the peer pad.
4538 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4542 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4543 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4544 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4546 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4547 res = gst_pad_push_data (pad,
4548 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4549 GST_TRACER_PAD_PUSH_POST (pad, res);
4554 * gst_pad_push_list:
4555 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4556 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4559 * Pushes a buffer list to the peer of @pad.
4561 * This function will call installed block probes before triggering any
4562 * installed data probes.
4564 * The function proceeds calling the chain function on the peer pad and returns
4565 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4566 * be returned. If the peer pad does not have any installed chainlist function
4567 * every group buffer of the list will be merged into a normal #GstBuffer and
4568 * chained via gst_pad_chain().
4570 * In all cases, success or failure, the caller loses its reference to @list
4571 * after calling this function.
4573 * Returns: a #GstFlowReturn from the peer pad.
4578 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4582 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4583 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4584 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4586 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4587 res = gst_pad_push_data (pad,
4588 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4589 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4593 static GstFlowReturn
4594 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4595 GstBuffer ** buffer)
4598 GstPadGetRangeFunction getrangefunc;
4602 GST_PAD_STREAM_LOCK (pad);
4604 GST_OBJECT_LOCK (pad);
4605 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4608 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4611 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4616 /* when one of the probes returns DROPPED, probe_stopped will be called
4617 * and we skip calling the getrange function, res_buf should then contain a
4618 * valid result buffer */
4619 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4620 res_buf, offset, size, probe_stopped);
4622 /* recheck sticky events because the probe might have cause a relink */
4623 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4626 ACQUIRE_PARENT (pad, parent, no_parent);
4627 GST_OBJECT_UNLOCK (pad);
4629 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4632 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4633 "calling getrangefunc %s, offset %"
4634 G_GUINT64_FORMAT ", size %u",
4635 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4637 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4639 RELEASE_PARENT (parent);
4641 GST_OBJECT_LOCK (pad);
4642 if (G_UNLIKELY (ret != GST_FLOW_OK))
4643 goto get_range_failed;
4645 /* can only fire the signal if we have a valid buffer */
4647 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4648 res_buf, offset, size, probe_stopped_unref);
4649 pad->ABI.abi.last_flowret = ret;
4650 GST_OBJECT_UNLOCK (pad);
4652 GST_PAD_STREAM_UNLOCK (pad);
4661 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4662 "getrange, but pad was flushing");
4663 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4664 GST_OBJECT_UNLOCK (pad);
4665 GST_PAD_STREAM_UNLOCK (pad);
4666 return GST_FLOW_FLUSHING;
4670 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4671 GST_DEBUG_PAD_NAME (pad));
4672 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4673 GST_OBJECT_UNLOCK (pad);
4674 GST_PAD_STREAM_UNLOCK (pad);
4675 return GST_FLOW_ERROR;
4679 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4680 pad->ABI.abi.last_flowret = ret;
4681 GST_OBJECT_UNLOCK (pad);
4682 GST_PAD_STREAM_UNLOCK (pad);
4687 GST_DEBUG_OBJECT (pad, "no parent");
4688 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4689 GST_OBJECT_UNLOCK (pad);
4690 GST_PAD_STREAM_UNLOCK (pad);
4691 return GST_FLOW_FLUSHING;
4695 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4696 GST_DEBUG_PAD_NAME (pad));
4697 RELEASE_PARENT (parent);
4698 GST_PAD_STREAM_UNLOCK (pad);
4699 return GST_FLOW_NOT_SUPPORTED;
4703 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4704 "probe returned %s", gst_flow_get_name (ret));
4705 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4707 /* the probe filled the buffer and asks us to not call the getrange
4708 * anymore, we continue with the post probes then. */
4709 GST_DEBUG_OBJECT (pad, "handled buffer");
4713 /* no buffer, we are EOS */
4714 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4718 pad->ABI.abi.last_flowret = ret;
4719 GST_OBJECT_UNLOCK (pad);
4720 GST_PAD_STREAM_UNLOCK (pad);
4724 probe_stopped_unref:
4726 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4727 "probe returned %s", gst_flow_get_name (ret));
4728 /* if we drop here, it signals EOS */
4729 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4731 pad->ABI.abi.last_flowret = ret;
4732 GST_OBJECT_UNLOCK (pad);
4733 GST_PAD_STREAM_UNLOCK (pad);
4734 if (*buffer == NULL)
4735 gst_buffer_unref (res_buf);
4740 pad->ABI.abi.last_flowret = ret;
4741 GST_OBJECT_UNLOCK (pad);
4742 GST_PAD_STREAM_UNLOCK (pad);
4743 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4744 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4745 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4751 * gst_pad_get_range:
4752 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4753 * @offset: The start offset of the buffer
4754 * @size: The length of the buffer
4755 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4756 * returns #GST_FLOW_ERROR if %NULL.
4758 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4759 * immediately and @buffer is %NULL.
4761 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4762 * description of a getrange function. If @pad has no getrange function
4763 * installed (see gst_pad_set_getrange_function()) this function returns
4764 * #GST_FLOW_NOT_SUPPORTED.
4766 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4767 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4768 * must be freed with gst_buffer_unref() after usage.
4770 * When @buffer points to a variable that points to a valid #GstBuffer, the
4771 * buffer will be filled with the result data when this function returns
4772 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4773 * @size bytes will be filled in the result buffer and its size will be updated
4776 * Note that less than @size bytes can be returned in @buffer when, for example,
4777 * an EOS condition is near or when @buffer is not large enough to hold @size
4778 * bytes. The caller should check the result buffer size to get the result size.
4780 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4781 * will be unchanged.
4783 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4785 * Returns: a #GstFlowReturn from the pad.
4790 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4791 GstBuffer ** buffer)
4793 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4794 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4795 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4796 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4797 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4799 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4803 * gst_pad_pull_range:
4804 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4805 * @offset: The start offset of the buffer
4806 * @size: The length of the buffer
4807 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4808 * GST_FLOW_ERROR if %NULL.
4810 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4812 * This function will first trigger the pad block signal if it was
4815 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4816 * function returns the result of gst_pad_get_range() on the peer pad.
4817 * See gst_pad_get_range() for a list of return values and for the
4818 * semantics of the arguments of this function.
4820 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4821 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4822 * must be freed with gst_buffer_unref() after usage. When this function
4823 * returns any other result value, @buffer will still point to %NULL.
4825 * When @buffer points to a variable that points to a valid #GstBuffer, the
4826 * buffer will be filled with the result data when this function returns
4827 * #GST_FLOW_OK. When this function returns any other result value,
4828 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4829 * @size bytes will be filled in the result buffer and its size will be updated
4832 * Note that less than @size bytes can be returned in @buffer when, for example,
4833 * an EOS condition is near or when @buffer is not large enough to hold @size
4834 * bytes. The caller should check the result buffer size to get the result size.
4836 * Returns: a #GstFlowReturn from the peer pad.
4841 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4842 GstBuffer ** buffer)
4848 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4849 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4850 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4851 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4852 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4854 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4856 GST_OBJECT_LOCK (pad);
4857 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4860 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4865 /* when one of the probes returns DROPPED, probe_stopped will be
4866 * called and we skip calling the peer getrange function. *buffer should then
4867 * contain a valid buffer */
4868 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4869 res_buf, offset, size, probe_stopped);
4871 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4874 gst_object_ref (peer);
4876 GST_OBJECT_UNLOCK (pad);
4878 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4880 gst_object_unref (peer);
4882 GST_OBJECT_LOCK (pad);
4884 pad->ABI.abi.last_flowret = ret;
4885 if (pad->priv->using == 0) {
4886 /* pad is not active anymore, trigger idle callbacks */
4887 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4888 probe_stopped_unref, ret);
4891 if (G_UNLIKELY (ret != GST_FLOW_OK))
4892 goto pull_range_failed;
4895 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4896 res_buf, offset, size, probe_stopped_unref);
4898 GST_OBJECT_UNLOCK (pad);
4902 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4905 /* ERROR recovery here */
4908 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4909 "pullrange, but pad was flushing");
4910 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4911 GST_OBJECT_UNLOCK (pad);
4912 ret = GST_FLOW_FLUSHING;
4917 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4918 GST_DEBUG_PAD_NAME (pad));
4919 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4920 GST_OBJECT_UNLOCK (pad);
4921 ret = GST_FLOW_ERROR;
4926 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4927 gst_flow_get_name (ret));
4928 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4930 /* the probe filled the buffer and asks us to not forward to the peer
4931 * anymore, we continue with the post probes then */
4932 GST_DEBUG_OBJECT (pad, "handled buffer");
4936 /* no buffer, we are EOS then */
4937 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4941 pad->ABI.abi.last_flowret = ret;
4942 GST_OBJECT_UNLOCK (pad);
4947 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4948 "pulling range, but it was not linked");
4949 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4950 GST_OBJECT_UNLOCK (pad);
4951 ret = GST_FLOW_NOT_LINKED;
4956 pad->ABI.abi.last_flowret = ret;
4957 GST_OBJECT_UNLOCK (pad);
4958 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4959 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4960 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4963 probe_stopped_unref:
4965 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4966 "post probe returned %s", gst_flow_get_name (ret));
4968 /* if we drop here, it signals EOS */
4969 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4972 pad->ABI.abi.last_flowret = ret;
4973 GST_OBJECT_UNLOCK (pad);
4975 if (*buffer == NULL)
4976 gst_buffer_unref (res_buf);
4980 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
4984 /* must be called with pad object lock */
4985 static GstFlowReturn
4986 store_sticky_event (GstPad * pad, GstEvent * event)
4991 gboolean res = FALSE;
4992 const gchar *name = NULL;
4993 gboolean insert = TRUE;
4995 type = GST_EVENT_TYPE (event);
4997 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4998 * otherwise they can be dropped and nothing would ever resend them.
4999 * Only do that for activated pads though, everything else is a bug!
5001 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5002 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5003 || type == GST_EVENT_EOS))))
5006 /* Unset the EOS flag when received STREAM_START event, so pad can
5007 * store sticky event and then push it later */
5008 if (type == GST_EVENT_STREAM_START) {
5009 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5010 remove_event_by_type (pad, GST_EVENT_EOS);
5011 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5014 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5017 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5018 name = gst_structure_get_name (gst_event_get_structure (event));
5020 events = pad->priv->events;
5023 for (i = 0; i < len; i++) {
5024 PadEvent *ev = &g_array_index (events, PadEvent, i);
5026 if (ev->event == NULL)
5029 if (type == GST_EVENT_TYPE (ev->event)) {
5030 /* matching types, check matching name if needed */
5031 if (name && !gst_event_has_name (ev->event, name))
5035 if ((res = gst_event_replace (&ev->event, event)))
5036 ev->received = FALSE;
5042 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5043 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5044 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5045 * storing the sticky ordered we can check that this is respected. */
5046 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5047 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5049 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5050 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5051 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5052 gst_event_type_get_name (type));
5058 ev.event = gst_event_ref (event);
5059 ev.received = FALSE;
5060 g_array_insert_val (events, i, ev);
5065 pad->priv->events_cookie++;
5066 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5068 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5070 switch (GST_EVENT_TYPE (event)) {
5071 case GST_EVENT_CAPS:
5072 GST_OBJECT_UNLOCK (pad);
5074 GST_DEBUG_OBJECT (pad, "notify caps");
5075 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5077 GST_OBJECT_LOCK (pad);
5083 if (type == GST_EVENT_EOS) {
5084 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5085 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5088 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5093 GST_DEBUG_OBJECT (pad, "pad is flushing");
5094 return GST_FLOW_FLUSHING;
5098 GST_DEBUG_OBJECT (pad, "pad is EOS");
5099 return GST_FLOW_EOS;
5104 * gst_pad_store_sticky_event:
5106 * @event: a #GstEvent
5108 * Store the sticky @event on @pad
5110 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5111 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5116 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5120 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5121 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5123 GST_OBJECT_LOCK (pad);
5124 ret = store_sticky_event (pad, event);
5125 GST_OBJECT_UNLOCK (pad);
5131 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5133 PushStickyData *data = user_data;
5135 /* Forward all sticky events before our current one that are pending */
5136 if (ev->event != data->event
5137 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5138 return push_sticky (pad, ev, data);
5143 /* should be called with pad LOCK */
5144 static GstFlowReturn
5145 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5146 GstPadProbeType type)
5150 GstEventType event_type;
5152 /* pass the adjusted event on. We need to do this even if
5153 * there is no peer pad because of the probes. */
5154 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5156 /* Two checks to be made:
5157 * . (un)set the FLUSHING flag for flushing events,
5158 * . handle pad blocking */
5159 event_type = GST_EVENT_TYPE (event);
5160 switch (event_type) {
5161 case GST_EVENT_FLUSH_START:
5162 GST_PAD_SET_FLUSHING (pad);
5164 GST_PAD_BLOCK_BROADCAST (pad);
5165 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5167 case GST_EVENT_FLUSH_STOP:
5168 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5171 GST_PAD_UNSET_FLUSHING (pad);
5173 /* Remove sticky EOS events */
5174 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5175 remove_event_by_type (pad, GST_EVENT_EOS);
5176 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5177 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5178 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5180 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5184 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5187 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5188 * checked already or this is called as part of pushing sticky events,
5189 * in which case we still want to forward the EOS event downstream.
5192 switch (GST_EVENT_TYPE (event)) {
5193 case GST_EVENT_RECONFIGURE:
5194 if (GST_PAD_IS_SINK (pad))
5195 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5200 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5201 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5206 /* send probes after modifying the events above */
5207 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5209 /* recheck sticky events because the probe might have cause a relink */
5210 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5211 && (GST_EVENT_IS_SERIALIZED (event)
5212 || GST_EVENT_IS_STICKY (event))) {
5213 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5214 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5216 /* Push all sticky events before our current one
5217 * that have changed */
5218 events_foreach (pad, sticky_changed, &data);
5221 /* now check the peer pad */
5222 peerpad = GST_PAD_PEER (pad);
5223 if (peerpad == NULL)
5226 gst_object_ref (peerpad);
5228 GST_OBJECT_UNLOCK (pad);
5230 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5231 event, gst_event_type_get_name (event_type), peerpad);
5233 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5235 /* Note: we gave away ownership of the event at this point but we can still
5236 * print the old pointer */
5237 GST_LOG_OBJECT (pad,
5238 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5239 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5241 gst_object_unref (peerpad);
5243 GST_OBJECT_LOCK (pad);
5245 if (pad->priv->using == 0) {
5246 /* pad is not active anymore, trigger idle callbacks */
5247 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5248 idle_probe_stopped, ret);
5252 /* ERROR handling */
5255 GST_DEBUG_OBJECT (pad, "We're flushing");
5256 gst_event_unref (event);
5257 return GST_FLOW_FLUSHING;
5261 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5262 gst_event_unref (event);
5263 return GST_FLOW_FLUSHING;
5267 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5268 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5269 gst_event_unref (event);
5272 case GST_FLOW_CUSTOM_SUCCESS_1:
5273 GST_DEBUG_OBJECT (pad, "handled event");
5275 case GST_FLOW_CUSTOM_SUCCESS:
5276 GST_DEBUG_OBJECT (pad, "dropped event");
5279 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5286 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5287 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5288 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5289 gst_event_unref (event);
5291 /* unlinked pads should not influence latency configuration */
5292 if (event_type == GST_EVENT_LATENCY)
5295 return GST_FLOW_NOT_LINKED;
5299 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5305 * gst_pad_push_event:
5306 * @pad: a #GstPad to push the event to.
5307 * @event: (transfer full): the #GstEvent to send to the pad.
5309 * Sends the event to the peer of the given pad. This function is
5310 * mainly used by elements to send events to their peer
5313 * This function takes ownership of the provided event so you should
5314 * gst_event_ref() it if you want to reuse the event after this call.
5316 * Returns: %TRUE if the event was handled.
5321 gst_pad_push_event (GstPad * pad, GstEvent * event)
5323 gboolean res = FALSE;
5324 GstPadProbeType type;
5325 gboolean sticky, serialized;
5327 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5328 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5330 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5332 if (GST_PAD_IS_SRC (pad)) {
5333 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5334 goto wrong_direction;
5335 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5336 } else if (GST_PAD_IS_SINK (pad)) {
5337 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5338 goto wrong_direction;
5339 /* events pushed on sinkpad never are sticky */
5340 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5342 goto unknown_direction;
5344 GST_OBJECT_LOCK (pad);
5345 sticky = GST_EVENT_IS_STICKY (event);
5346 serialized = GST_EVENT_IS_SERIALIZED (event);
5349 /* srcpad sticky events are stored immediately, the received flag is set
5350 * to FALSE and will be set to TRUE when we can successfully push the
5351 * event to the peer pad */
5352 switch (store_sticky_event (pad, event)) {
5353 case GST_FLOW_FLUSHING:
5361 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5362 /* all serialized or sticky events on the srcpad trigger push of
5364 res = (check_sticky (pad, event) == GST_FLOW_OK);
5369 /* other events are pushed right away */
5370 ret = gst_pad_push_event_unchecked (pad, event, type);
5371 /* dropped events by a probe are not an error */
5372 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5373 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5375 /* Errors in sticky event pushing are no problem and ignored here
5376 * as they will cause more meaningful errors during data flow.
5377 * For EOS events, that are not followed by data flow, we still
5378 * return FALSE here though.
5380 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5382 gst_event_unref (event);
5384 GST_OBJECT_UNLOCK (pad);
5386 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5389 /* ERROR handling */
5392 g_warning ("pad %s:%s pushing %s event in wrong direction",
5393 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5394 gst_event_unref (event);
5399 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5400 gst_event_unref (event);
5405 GST_DEBUG_OBJECT (pad, "We're flushing");
5406 GST_OBJECT_UNLOCK (pad);
5407 gst_event_unref (event);
5412 GST_DEBUG_OBJECT (pad, "We're EOS");
5413 GST_OBJECT_UNLOCK (pad);
5414 gst_event_unref (event);
5418 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5422 /* Check if we can call the event function with the given event */
5423 static GstFlowReturn
5424 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5428 switch (GST_EVENT_TYPE (event)) {
5429 case GST_EVENT_CAPS:
5431 /* backwards compatibility mode for caps */
5432 gst_event_parse_caps (event, &caps);
5434 if (!gst_pad_query_accept_caps (pad, caps))
5446 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5447 "caps %" GST_PTR_FORMAT " not accepted", caps);
5448 return GST_FLOW_NOT_NEGOTIATED;
5452 static GstFlowReturn
5453 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5454 GstPadProbeType type)
5457 GstEventType event_type;
5458 gboolean serialized, need_unlock = FALSE, sticky;
5459 GstPadEventFunction eventfunc;
5460 GstPadEventFullFunction eventfullfunc = NULL;
5463 GST_OBJECT_LOCK (pad);
5465 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5467 if (GST_PAD_IS_SINK (pad))
5468 serialized = GST_EVENT_IS_SERIALIZED (event);
5471 sticky = GST_EVENT_IS_STICKY (event);
5472 event_type = GST_EVENT_TYPE (event);
5473 switch (event_type) {
5474 case GST_EVENT_FLUSH_START:
5475 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5476 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5478 /* can't even accept a flush begin event when flushing */
5479 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5482 GST_PAD_SET_FLUSHING (pad);
5483 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5484 GST_PAD_BLOCK_BROADCAST (pad);
5485 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5487 case GST_EVENT_FLUSH_STOP:
5488 /* we can't accept flush-stop on inactive pads else the flushing flag
5489 * would be cleared and it would look like the pad can accept data.
5490 * Also, some elements restart a streaming thread in flush-stop which we
5491 * can't allow on inactive pads */
5492 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5495 GST_PAD_UNSET_FLUSHING (pad);
5496 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5497 /* Remove pending EOS events */
5498 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5499 remove_event_by_type (pad, GST_EVENT_EOS);
5500 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5501 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5502 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5504 GST_OBJECT_UNLOCK (pad);
5505 /* grab stream lock */
5506 GST_PAD_STREAM_LOCK (pad);
5508 GST_OBJECT_LOCK (pad);
5509 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5512 case GST_EVENT_RECONFIGURE:
5513 if (GST_PAD_IS_SRC (pad))
5514 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5516 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5517 "have event type %" GST_PTR_FORMAT, event);
5519 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5522 switch (event_type) {
5523 case GST_EVENT_STREAM_START:
5524 /* Remove sticky EOS events */
5525 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5526 remove_event_by_type (pad, GST_EVENT_EOS);
5527 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5534 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5537 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5538 GST_OBJECT_UNLOCK (pad);
5539 GST_PAD_STREAM_LOCK (pad);
5541 GST_OBJECT_LOCK (pad);
5542 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5545 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5551 /* now do the probe */
5553 type | GST_PAD_PROBE_TYPE_PUSH |
5554 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5556 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5558 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5559 eventfunc = GST_PAD_EVENTFUNC (pad);
5560 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5563 ACQUIRE_PARENT (pad, parent, no_parent);
5564 GST_OBJECT_UNLOCK (pad);
5566 ret = pre_eventfunc_check (pad, event);
5567 if (G_UNLIKELY (ret != GST_FLOW_OK))
5568 goto precheck_failed;
5571 gst_event_ref (event);
5573 if (eventfullfunc) {
5574 ret = eventfullfunc (pad, parent, event);
5575 } else if (eventfunc (pad, parent, event)) {
5578 /* something went wrong */
5579 switch (event_type) {
5580 case GST_EVENT_CAPS:
5581 ret = GST_FLOW_NOT_NEGOTIATED;
5584 ret = GST_FLOW_ERROR;
5588 RELEASE_PARENT (parent);
5590 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5593 if (ret == GST_FLOW_OK) {
5594 GST_OBJECT_LOCK (pad);
5595 /* after the event function accepted the event, we can store the sticky
5596 * event on the pad */
5597 switch (store_sticky_event (pad, event)) {
5598 case GST_FLOW_FLUSHING:
5605 GST_OBJECT_UNLOCK (pad);
5607 gst_event_unref (event);
5611 GST_PAD_STREAM_UNLOCK (pad);
5615 /* ERROR handling */
5618 GST_OBJECT_UNLOCK (pad);
5620 GST_PAD_STREAM_UNLOCK (pad);
5621 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5622 "Received event on flushing pad. Discarding");
5623 gst_event_unref (event);
5624 return GST_FLOW_FLUSHING;
5628 GST_OBJECT_UNLOCK (pad);
5630 GST_PAD_STREAM_UNLOCK (pad);
5631 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5632 "Received flush-stop on inactive pad. Discarding");
5633 gst_event_unref (event);
5634 return GST_FLOW_FLUSHING;
5638 GST_OBJECT_UNLOCK (pad);
5640 GST_PAD_STREAM_UNLOCK (pad);
5641 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5642 "Received event on EOS pad. Discarding");
5643 gst_event_unref (event);
5644 return GST_FLOW_EOS;
5648 GST_OBJECT_UNLOCK (pad);
5650 GST_PAD_STREAM_UNLOCK (pad);
5651 /* Only unref if unhandled */
5652 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5653 gst_event_unref (event);
5656 case GST_FLOW_CUSTOM_SUCCESS_1:
5657 case GST_FLOW_CUSTOM_SUCCESS:
5658 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5662 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5669 g_warning ("pad %s:%s has no event handler, file a bug.",
5670 GST_DEBUG_PAD_NAME (pad));
5671 GST_OBJECT_UNLOCK (pad);
5673 GST_PAD_STREAM_UNLOCK (pad);
5674 gst_event_unref (event);
5675 return GST_FLOW_NOT_SUPPORTED;
5679 GST_DEBUG_OBJECT (pad, "no parent");
5680 GST_OBJECT_UNLOCK (pad);
5682 GST_PAD_STREAM_UNLOCK (pad);
5683 gst_event_unref (event);
5684 return GST_FLOW_FLUSHING;
5688 GST_DEBUG_OBJECT (pad, "pre event check failed");
5689 RELEASE_PARENT (parent);
5691 GST_PAD_STREAM_UNLOCK (pad);
5692 gst_event_unref (event);
5698 * gst_pad_send_event:
5699 * @pad: a #GstPad to send the event to.
5700 * @event: (transfer full): the #GstEvent to send to the pad.
5702 * Sends the event to the pad. This function can be used
5703 * by applications to send events in the pipeline.
5705 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5706 * sink pad, @event should be a downstream event. For example, you would not
5707 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5708 * Furthermore, some downstream events have to be serialized with data flow,
5709 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5710 * the event needs to be serialized with data flow, this function will take the
5711 * pad's stream lock while calling its event function.
5713 * To find out whether an event type is upstream, downstream, or downstream and
5714 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5715 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5716 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5717 * plugin doesn't need to bother itself with this information; the core handles
5718 * all necessary locks and checks.
5720 * This function takes ownership of the provided event so you should
5721 * gst_event_ref() it if you want to reuse the event after this call.
5723 * Returns: %TRUE if the event was handled.
5726 gst_pad_send_event (GstPad * pad, GstEvent * event)
5729 GstPadProbeType type;
5731 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5732 g_return_val_if_fail (event != NULL, FALSE);
5734 if (GST_PAD_IS_SINK (pad)) {
5735 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5736 goto wrong_direction;
5737 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5738 } else if (GST_PAD_IS_SRC (pad)) {
5739 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5740 goto wrong_direction;
5741 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5743 goto unknown_direction;
5745 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5752 /* ERROR handling */
5755 g_warning ("pad %s:%s sending %s event in wrong direction",
5756 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5757 gst_event_unref (event);
5762 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5763 gst_event_unref (event);
5769 * gst_pad_set_element_private:
5770 * @pad: the #GstPad to set the private data of.
5771 * @priv: The private data to attach to the pad.
5773 * Set the given private data gpointer on the pad.
5774 * This function can only be used by the element that owns the pad.
5775 * No locking is performed in this function.
5778 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5780 pad->element_private = priv;
5784 * gst_pad_get_element_private:
5785 * @pad: the #GstPad to get the private data of.
5787 * Gets the private data of a pad.
5788 * No locking is performed in this function.
5790 * Returns: (transfer none): a #gpointer to the private data.
5793 gst_pad_get_element_private (GstPad * pad)
5795 return pad->element_private;
5799 * gst_pad_get_sticky_event:
5800 * @pad: the #GstPad to get the event from.
5801 * @event_type: the #GstEventType that should be retrieved.
5802 * @idx: the index of the event
5804 * Returns a new reference of the sticky event of type @event_type
5807 * Returns: (transfer full) (nullable): a #GstEvent of type
5808 * @event_type or %NULL when no event of @event_type was on
5809 * @pad. Unref after usage.
5812 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5814 GstEvent *event = NULL;
5817 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5818 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5820 GST_OBJECT_LOCK (pad);
5821 ev = find_event_by_type (pad, event_type, idx);
5822 if (ev && (event = ev->event))
5823 gst_event_ref (event);
5824 GST_OBJECT_UNLOCK (pad);
5831 GstPadStickyEventsForeachFunction func;
5836 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5838 ForeachDispatch *data = user_data;
5839 gboolean ret = TRUE;
5842 GST_OBJECT_UNLOCK (pad);
5844 ret = data->func (pad, &ev->event, data->user_data);
5846 GST_OBJECT_LOCK (pad);
5853 * gst_pad_sticky_events_foreach:
5854 * @pad: the #GstPad that should be used for iteration.
5855 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5856 * should be called for every event.
5857 * @user_data: (closure): the optional user data.
5859 * Iterates all sticky events on @pad and calls @foreach_func for every
5860 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5863 gst_pad_sticky_events_foreach (GstPad * pad,
5864 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5866 ForeachDispatch data;
5868 g_return_if_fail (GST_IS_PAD (pad));
5869 g_return_if_fail (foreach_func != NULL);
5871 data.func = foreach_func;
5872 data.user_data = user_data;
5874 GST_OBJECT_LOCK (pad);
5875 events_foreach (pad, foreach_dispatch_function, &data);
5876 GST_OBJECT_UNLOCK (pad);
5880 do_stream_status (GstPad * pad, GstStreamStatusType type,
5881 GThread * thread, GstTask * task)
5885 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5887 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5888 if (GST_IS_ELEMENT (parent)) {
5889 GstMessage *message;
5890 GValue value = { 0 };
5892 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5893 gchar *tname, *ename, *pname;
5895 /* create a good task name */
5896 ename = gst_element_get_name (parent);
5897 pname = gst_pad_get_name (pad);
5898 tname = g_strdup_printf ("%s:%s", ename, pname);
5902 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5906 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5909 g_value_init (&value, GST_TYPE_TASK);
5910 g_value_set_object (&value, task);
5911 gst_message_set_stream_status_object (message, &value);
5912 g_value_unset (&value);
5914 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5915 gst_element_post_message (parent, message);
5917 gst_object_unref (parent);
5922 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5924 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5929 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5931 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5936 * gst_pad_start_task:
5937 * @pad: the #GstPad to start the task of
5938 * @func: the task function to call
5939 * @user_data: user data passed to the task function
5940 * @notify: called when @user_data is no longer referenced
5942 * Starts a task that repeatedly calls @func with @user_data. This function
5943 * is mostly used in pad activation functions to start the dataflow.
5944 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5945 * before @func is called.
5947 * Returns: a %TRUE if the task could be started.
5950 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5951 GDestroyNotify notify)
5956 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5957 g_return_val_if_fail (func != NULL, FALSE);
5959 GST_DEBUG_OBJECT (pad, "start task");
5961 GST_OBJECT_LOCK (pad);
5962 task = GST_PAD_TASK (pad);
5964 task = gst_task_new (func, user_data, notify);
5965 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5966 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5967 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5968 GST_INFO_OBJECT (pad, "created task %p", task);
5969 GST_PAD_TASK (pad) = task;
5970 gst_object_ref (task);
5971 /* release lock to post the message */
5972 GST_OBJECT_UNLOCK (pad);
5974 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5976 gst_object_unref (task);
5978 GST_OBJECT_LOCK (pad);
5979 /* nobody else is supposed to have changed the pad now */
5980 if (GST_PAD_TASK (pad) != task)
5981 goto concurrent_stop;
5983 res = gst_task_set_state (task, GST_TASK_STARTED);
5984 GST_OBJECT_UNLOCK (pad);
5991 GST_OBJECT_UNLOCK (pad);
5997 * gst_pad_pause_task:
5998 * @pad: the #GstPad to pause the task of
6000 * Pause the task of @pad. This function will also wait until the
6001 * function executed by the task is finished if this function is not
6002 * called from the task function.
6004 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6008 gst_pad_pause_task (GstPad * pad)
6013 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6015 GST_DEBUG_OBJECT (pad, "pause task");
6017 GST_OBJECT_LOCK (pad);
6018 task = GST_PAD_TASK (pad);
6021 res = gst_task_set_state (task, GST_TASK_PAUSED);
6022 GST_OBJECT_UNLOCK (pad);
6024 /* wait for task function to finish, this lock is recursive so it does nothing
6025 * when the pause is called from the task itself */
6026 GST_PAD_STREAM_LOCK (pad);
6027 GST_PAD_STREAM_UNLOCK (pad);
6033 GST_DEBUG_OBJECT (pad, "pad has no task");
6034 GST_OBJECT_UNLOCK (pad);
6040 * gst_pad_stop_task:
6041 * @pad: the #GstPad to stop the task of
6043 * Stop the task of @pad. This function will also make sure that the
6044 * function executed by the task will effectively stop if not called
6045 * from the GstTaskFunction.
6047 * This function will deadlock if called from the GstTaskFunction of
6048 * the task. Use gst_task_pause() instead.
6050 * Regardless of whether the pad has a task, the stream lock is acquired and
6051 * released so as to ensure that streaming through this pad has finished.
6053 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6056 gst_pad_stop_task (GstPad * pad)
6061 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6063 GST_DEBUG_OBJECT (pad, "stop task");
6065 GST_OBJECT_LOCK (pad);
6066 task = GST_PAD_TASK (pad);
6069 GST_PAD_TASK (pad) = NULL;
6070 res = gst_task_set_state (task, GST_TASK_STOPPED);
6071 GST_OBJECT_UNLOCK (pad);
6073 GST_PAD_STREAM_LOCK (pad);
6074 GST_PAD_STREAM_UNLOCK (pad);
6076 if (!gst_task_join (task))
6079 gst_object_unref (task);
6085 GST_DEBUG_OBJECT (pad, "no task");
6086 GST_OBJECT_UNLOCK (pad);
6088 GST_PAD_STREAM_LOCK (pad);
6089 GST_PAD_STREAM_UNLOCK (pad);
6091 /* this is not an error */
6096 /* this is bad, possibly the application tried to join the task from
6097 * the task's thread. We install the task again so that it will be stopped
6098 * again from the right thread next time hopefully. */
6099 GST_OBJECT_LOCK (pad);
6100 GST_DEBUG_OBJECT (pad, "join failed");
6101 /* we can only install this task if there was no other task */
6102 if (GST_PAD_TASK (pad) == NULL)
6103 GST_PAD_TASK (pad) = task;
6104 GST_OBJECT_UNLOCK (pad);
6111 * gst_pad_probe_info_get_event:
6112 * @info: a #GstPadProbeInfo
6114 * Returns: (transfer none): The #GstEvent from the probe
6118 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6120 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6121 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6123 return GST_PAD_PROBE_INFO_EVENT (info);
6128 * gst_pad_probe_info_get_query:
6129 * @info: a #GstPadProbeInfo
6131 * Returns: (transfer none): The #GstQuery from the probe
6135 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6137 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6138 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6140 return GST_PAD_PROBE_INFO_QUERY (info);
6144 * gst_pad_probe_info_get_buffer:
6145 * @info: a #GstPadProbeInfo
6147 * Returns: (transfer none): The #GstBuffer from the probe
6151 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6153 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6155 return GST_PAD_PROBE_INFO_BUFFER (info);
6159 * gst_pad_probe_info_get_buffer_list:
6160 * @info: a #GstPadProbeInfo
6162 * Returns: (transfer none): The #GstBufferList from the probe
6166 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6168 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6170 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6174 * gst_pad_get_last_flow_return:
6177 * Gets the #GstFlowReturn return from the last data passed by this pad.
6182 gst_pad_get_last_flow_return (GstPad * pad)
6186 GST_OBJECT_LOCK (pad);
6187 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6188 GST_OBJECT_UNLOCK (pad);