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 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
128 /* we have a pending and an active event on the pad. On source pads only the
129 * active event is used. On sinkpads, events are copied to the pending entry and
130 * moved to the active event when the eventfunc returned %TRUE. */
137 struct _GstPadPrivate
144 guint probe_list_cookie;
147 /* counter of how many idle probes are running directly from the add_probe
148 * call. Used to block any data flowing in the pad while the idle callback
149 * Doesn't finish its work */
159 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
160 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
161 (((GstPad *)(p))->priv->idle_running > 0)
166 GstPadProbeInfo *info;
174 static void gst_pad_dispose (GObject * object);
175 static void gst_pad_finalize (GObject * object);
176 static void gst_pad_set_property (GObject * object, guint prop_id,
177 const GValue * value, GParamSpec * pspec);
178 static void gst_pad_get_property (GObject * object, guint prop_id,
179 GValue * value, GParamSpec * pspec);
181 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
182 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
183 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
184 GstObject * parent, GstBufferList * list);
186 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
187 GstEvent * event, GstPadProbeType type);
188 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
189 GstEvent * event, GstPadProbeType type);
191 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
192 GstPadMode mode, gboolean active);
194 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
196 static GParamSpec *pspec_caps = NULL;
198 /* quarks for probe signals */
199 static GQuark buffer_quark;
200 static GQuark buffer_list_quark;
201 static GQuark event_quark;
210 static GstFlowQuarks flow_quarks[] = {
211 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
212 {GST_FLOW_OK, "ok", 0},
213 {GST_FLOW_NOT_LINKED, "not-linked", 0},
214 {GST_FLOW_FLUSHING, "flushing", 0},
215 {GST_FLOW_EOS, "eos", 0},
216 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
217 {GST_FLOW_ERROR, "error", 0},
218 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
219 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
224 * @ret: a #GstFlowReturn to get the name of.
226 * Gets a string representing the given flow return.
228 * Returns: a static string with the name of the flow return.
231 gst_flow_get_name (GstFlowReturn ret)
235 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
237 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
238 if (ret == flow_quarks[i].ret)
239 return flow_quarks[i].name;
246 * @ret: a #GstFlowReturn to get the quark of.
248 * Get the unique quark for the given GstFlowReturn.
250 * Returns: the quark associated with the flow return or 0 if an
251 * invalid return was specified.
254 gst_flow_to_quark (GstFlowReturn ret)
258 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
260 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
261 if (ret == flow_quarks[i].ret)
262 return flow_quarks[i].quark;
268 * gst_pad_link_get_name:
269 * @ret: a #GstPadLinkReturn to get the name of.
271 * Gets a string representing the given pad-link return.
273 * Returns: a static string with the name of the pad-link return.
278 gst_pad_link_get_name (GstPadLinkReturn ret)
281 case GST_PAD_LINK_OK:
283 case GST_PAD_LINK_WRONG_HIERARCHY:
284 return "wrong hierarchy";
285 case GST_PAD_LINK_WAS_LINKED:
287 case GST_PAD_LINK_WRONG_DIRECTION:
288 return "wrong direction";
289 case GST_PAD_LINK_NOFORMAT:
290 return "no common format";
291 case GST_PAD_LINK_NOSCHED:
292 return "incompatible scheduling";
293 case GST_PAD_LINK_REFUSED:
296 g_return_val_if_reached ("unknown");
303 buffer_quark = g_quark_from_static_string ("buffer"); \
304 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
305 event_quark = g_quark_from_static_string ("event"); \
307 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
308 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
311 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
312 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
315 #define gst_pad_parent_class parent_class
316 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
319 gst_pad_class_init (GstPadClass * klass)
321 GObjectClass *gobject_class;
322 GstObjectClass *gstobject_class;
324 gobject_class = G_OBJECT_CLASS (klass);
325 gstobject_class = GST_OBJECT_CLASS (klass);
327 g_type_class_add_private (klass, sizeof (GstPadPrivate));
329 gobject_class->dispose = gst_pad_dispose;
330 gobject_class->finalize = gst_pad_finalize;
331 gobject_class->set_property = gst_pad_set_property;
332 gobject_class->get_property = gst_pad_get_property;
336 * @pad: the pad that emitted the signal
337 * @peer: the peer pad that has been connected
339 * Signals that a pad has been linked to the peer pad.
341 gst_pad_signals[PAD_LINKED] =
342 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
343 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
344 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
347 * @pad: the pad that emitted the signal
348 * @peer: the peer pad that has been disconnected
350 * Signals that a pad has been unlinked from the peer pad.
352 gst_pad_signals[PAD_UNLINKED] =
353 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
354 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
355 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
357 pspec_caps = g_param_spec_boxed ("caps", "Caps",
358 "The capabilities of the pad", GST_TYPE_CAPS,
359 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
360 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
362 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
363 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
364 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
365 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
367 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
368 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
369 g_param_spec_object ("template", "Template",
370 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
371 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
376 * The offset that will be applied to the running time of the pad.
380 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
381 g_param_spec_int64 ("offset", "Offset",
382 "The running time offset of the pad", 0, G_MAXINT64, 0,
383 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
385 gstobject_class->path_string_separator = ".";
387 /* Register common function pointer descriptions */
388 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
389 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
396 gst_pad_init (GstPad * pad)
398 pad->priv = GST_PAD_GET_PRIVATE (pad);
400 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
402 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
403 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
404 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
405 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
406 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
408 GST_PAD_SET_FLUSHING (pad);
410 g_rec_mutex_init (&pad->stream_rec_lock);
412 g_cond_init (&pad->block_cond);
414 g_hook_list_init (&pad->probes, sizeof (GstProbe));
416 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
417 pad->priv->events_cookie = 0;
418 pad->priv->last_cookie = -1;
419 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
422 /* called when setting the pad inactive. It removes all sticky events from
423 * the pad. must be called with object lock */
425 remove_events (GstPad * pad)
429 gboolean notify = FALSE;
431 events = pad->priv->events;
434 for (i = 0; i < len; i++) {
435 PadEvent *ev = &g_array_index (events, PadEvent, i);
436 GstEvent *event = ev->event;
440 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
443 gst_event_unref (event);
446 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
447 g_array_set_size (events, 0);
448 pad->priv->events_cookie++;
451 GST_OBJECT_UNLOCK (pad);
453 GST_DEBUG_OBJECT (pad, "notify caps");
454 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
456 GST_OBJECT_LOCK (pad);
460 /* should be called with object lock */
462 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
468 events = pad->priv->events;
471 for (i = 0; i < len; i++) {
472 ev = &g_array_index (events, PadEvent, i);
473 if (ev->event == NULL)
476 if (GST_EVENT_TYPE (ev->event) == type) {
480 } else if (GST_EVENT_TYPE (ev->event) > type) {
489 /* should be called with OBJECT lock */
491 find_event (GstPad * pad, GstEvent * event)
497 events = pad->priv->events;
500 for (i = 0; i < len; i++) {
501 ev = &g_array_index (events, PadEvent, i);
502 if (event == ev->event)
504 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
512 /* should be called with OBJECT lock */
514 remove_event_by_type (GstPad * pad, GstEventType type)
520 events = pad->priv->events;
525 ev = &g_array_index (events, PadEvent, i);
526 if (ev->event == NULL)
529 if (GST_EVENT_TYPE (ev->event) > type)
531 else if (GST_EVENT_TYPE (ev->event) != type)
534 gst_event_unref (ev->event);
535 g_array_remove_index (events, i);
537 pad->priv->events_cookie++;
545 /* check all events on srcpad against those on sinkpad. All events that are not
546 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
547 * srcpad so that the events will be sent next time */
548 /* should be called with srcpad and sinkpad LOCKS */
550 schedule_events (GstPad * srcpad, GstPad * sinkpad)
555 gboolean pending = FALSE;
557 events = srcpad->priv->events;
560 for (i = 0; i < len; i++) {
561 ev = &g_array_index (events, PadEvent, i);
562 if (ev->event == NULL)
565 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
566 ev->received = FALSE;
571 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
574 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
577 /* should be called with pad LOCK */
579 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
586 events = pad->priv->events;
589 cookie = pad->priv->events_cookie;
593 PadEvent *ev, ev_ret;
595 ev = &g_array_index (events, PadEvent, i);
596 if (G_UNLIKELY (ev->event == NULL))
599 /* take aditional ref, func might release the lock */
600 ev_ret.event = gst_event_ref (ev->event);
601 ev_ret.received = ev->received;
603 ret = func (pad, &ev_ret, user_data);
605 /* recheck the cookie, lock might have been released and the list could have
607 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
608 if (G_LIKELY (ev_ret.event))
609 gst_event_unref (ev_ret.event);
613 /* store the received state */
614 ev->received = ev_ret.received;
616 /* if the event changed, we need to do something */
617 if (G_UNLIKELY (ev->event != ev_ret.event)) {
618 if (G_UNLIKELY (ev_ret.event == NULL)) {
619 /* function unreffed and set the event to NULL, remove it */
620 gst_event_unref (ev->event);
621 g_array_remove_index (events, i);
623 cookie = ++pad->priv->events_cookie;
626 /* function gave a new event for us */
627 gst_event_take (&ev->event, ev_ret.event);
630 /* just unref, nothing changed */
631 gst_event_unref (ev_ret.event);
640 /* should be called with LOCK */
642 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
646 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
647 GST_TIME_ARGS (pad->offset));
649 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
652 g_assert (!upstream);
654 /* copy segment values */
655 gst_event_copy_segment (event, &segment);
656 gst_event_unref (event);
658 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
659 event = gst_event_new_segment (&segment);
662 event = gst_event_make_writable (event);
663 offset = gst_event_get_running_time_offset (event);
665 offset -= pad->offset;
667 offset += pad->offset;
668 gst_event_set_running_time_offset (event, offset);
673 static inline GstEvent *
674 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
676 if (G_UNLIKELY (pad->offset != 0))
677 return _apply_pad_offset (pad, event, upstream);
682 /* should be called with the OBJECT_LOCK */
684 get_pad_caps (GstPad * pad)
686 GstCaps *caps = NULL;
689 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
691 gst_event_parse_caps (ev->event, &caps);
697 gst_pad_dispose (GObject * object)
699 GstPad *pad = GST_PAD_CAST (object);
702 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
704 /* unlink the peer pad */
705 if ((peer = gst_pad_get_peer (pad))) {
706 /* window for MT unsafeness, someone else could unlink here
707 * and then we call unlink with wrong pads. The unlink
708 * function would catch this and safely return failed. */
709 if (GST_PAD_IS_SRC (pad))
710 gst_pad_unlink (pad, peer);
712 gst_pad_unlink (peer, pad);
714 gst_object_unref (peer);
717 gst_pad_set_pad_template (pad, NULL);
719 GST_OBJECT_LOCK (pad);
721 GST_OBJECT_UNLOCK (pad);
723 g_hook_list_clear (&pad->probes);
725 G_OBJECT_CLASS (parent_class)->dispose (object);
729 gst_pad_finalize (GObject * object)
731 GstPad *pad = GST_PAD_CAST (object);
734 /* in case the task is still around, clean it up */
735 if ((task = GST_PAD_TASK (pad))) {
736 gst_task_join (task);
737 GST_PAD_TASK (pad) = NULL;
738 gst_object_unref (task);
741 if (pad->activatenotify)
742 pad->activatenotify (pad->activatedata);
743 if (pad->activatemodenotify)
744 pad->activatemodenotify (pad->activatemodedata);
746 pad->linknotify (pad->linkdata);
747 if (pad->unlinknotify)
748 pad->unlinknotify (pad->unlinkdata);
749 if (pad->chainnotify)
750 pad->chainnotify (pad->chaindata);
751 if (pad->chainlistnotify)
752 pad->chainlistnotify (pad->chainlistdata);
753 if (pad->getrangenotify)
754 pad->getrangenotify (pad->getrangedata);
755 if (pad->eventnotify)
756 pad->eventnotify (pad->eventdata);
757 if (pad->querynotify)
758 pad->querynotify (pad->querydata);
759 if (pad->iterintlinknotify)
760 pad->iterintlinknotify (pad->iterintlinkdata);
762 g_rec_mutex_clear (&pad->stream_rec_lock);
763 g_cond_clear (&pad->block_cond);
764 g_array_free (pad->priv->events, TRUE);
766 G_OBJECT_CLASS (parent_class)->finalize (object);
770 gst_pad_set_property (GObject * object, guint prop_id,
771 const GValue * value, GParamSpec * pspec)
773 g_return_if_fail (GST_IS_PAD (object));
776 case PAD_PROP_DIRECTION:
777 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
779 case PAD_PROP_TEMPLATE:
780 gst_pad_set_pad_template (GST_PAD_CAST (object),
781 (GstPadTemplate *) g_value_get_object (value));
783 case PAD_PROP_OFFSET:
784 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
787 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
793 gst_pad_get_property (GObject * object, guint prop_id,
794 GValue * value, GParamSpec * pspec)
796 g_return_if_fail (GST_IS_PAD (object));
800 GST_OBJECT_LOCK (object);
801 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
802 GST_OBJECT_UNLOCK (object);
804 case PAD_PROP_DIRECTION:
805 g_value_set_enum (value, GST_PAD_DIRECTION (object));
807 case PAD_PROP_TEMPLATE:
808 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
810 case PAD_PROP_OFFSET:
811 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
814 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
821 * @name: (allow-none): the name of the new pad.
822 * @direction: the #GstPadDirection of the pad.
824 * Creates a new pad with the given name in the given direction.
825 * If name is %NULL, a guaranteed unique name (across all pads)
827 * This function makes a copy of the name so you can safely free the name.
829 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
835 gst_pad_new (const gchar * name, GstPadDirection direction)
837 return g_object_new (GST_TYPE_PAD,
838 "name", name, "direction", direction, NULL);
842 * gst_pad_new_from_template:
843 * @templ: the pad template to use
844 * @name: (allow-none): the name of the pad
846 * Creates a new pad with the given name from the given template.
847 * If name is %NULL, a guaranteed unique name (across all pads)
849 * This function makes a copy of the name so you can safely free the name.
851 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
855 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
857 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
859 return g_object_new (GST_TYPE_PAD,
860 "name", name, "direction", templ->direction, "template", templ, NULL);
864 * gst_pad_new_from_static_template:
865 * @templ: the #GstStaticPadTemplate to use
866 * @name: the name of the pad
868 * Creates a new pad with the given name from the given static template.
869 * If name is %NULL, a guaranteed unique name (across all pads)
871 * This function makes a copy of the name so you can safely free the name.
873 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
877 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
881 GstPadTemplate *template;
883 template = gst_static_pad_template_get (templ);
884 pad = gst_pad_new_from_template (template, name);
885 gst_object_unref (template);
889 #define ACQUIRE_PARENT(pad, parent, label) \
891 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
892 gst_object_ref (parent); \
893 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
897 #define RELEASE_PARENT(parent) \
899 if (G_LIKELY (parent)) \
900 gst_object_unref (parent); \
904 * gst_pad_get_direction:
905 * @pad: a #GstPad to get the direction of.
907 * Gets the direction of the pad. The direction of the pad is
908 * decided at construction time so this function does not take
911 * Returns: the #GstPadDirection of the pad.
916 gst_pad_get_direction (GstPad * pad)
918 GstPadDirection result;
920 /* PAD_UNKNOWN is a little silly but we need some sort of
921 * error return value */
922 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
924 result = GST_PAD_DIRECTION (pad);
930 gst_pad_activate_default (GstPad * pad, GstObject * parent)
932 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
934 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
938 * gst_pad_mode_get_name:
939 * @mode: the pad mode
941 * Return the name of a pad mode, for use in debug messages mostly.
943 * Returns: short mnemonic for pad mode @mode
946 gst_pad_mode_get_name (GstPadMode mode)
949 case GST_PAD_MODE_NONE:
951 case GST_PAD_MODE_PUSH:
953 case GST_PAD_MODE_PULL:
962 pre_activate (GstPad * pad, GstPadMode new_mode)
965 case GST_PAD_MODE_NONE:
966 GST_OBJECT_LOCK (pad);
967 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
968 GST_PAD_SET_FLUSHING (pad);
969 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
970 GST_PAD_MODE (pad) = new_mode;
971 /* unlock blocked pads so element can resume and stop */
972 GST_PAD_BLOCK_BROADCAST (pad);
973 GST_OBJECT_UNLOCK (pad);
975 case GST_PAD_MODE_PUSH:
976 case GST_PAD_MODE_PULL:
977 GST_OBJECT_LOCK (pad);
978 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
979 gst_pad_mode_get_name (new_mode));
980 GST_PAD_UNSET_FLUSHING (pad);
981 pad->ABI.abi.last_flowret = GST_FLOW_OK;
982 GST_PAD_MODE (pad) = new_mode;
983 if (GST_PAD_IS_SINK (pad)) {
985 /* make sure the peer src pad sends us all events */
986 if ((peer = GST_PAD_PEER (pad))) {
987 gst_object_ref (peer);
988 GST_OBJECT_UNLOCK (pad);
990 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
991 GST_DEBUG_PAD_NAME (peer));
993 GST_OBJECT_LOCK (peer);
994 schedule_events (peer, NULL);
995 GST_OBJECT_UNLOCK (peer);
997 gst_object_unref (peer);
999 GST_OBJECT_UNLOCK (pad);
1002 GST_OBJECT_UNLOCK (pad);
1009 post_activate (GstPad * pad, GstPadMode new_mode)
1012 case GST_PAD_MODE_NONE:
1013 /* ensures that streaming stops */
1014 GST_PAD_STREAM_LOCK (pad);
1015 GST_DEBUG_OBJECT (pad, "stopped streaming");
1016 GST_OBJECT_LOCK (pad);
1017 remove_events (pad);
1018 GST_OBJECT_UNLOCK (pad);
1019 GST_PAD_STREAM_UNLOCK (pad);
1021 case GST_PAD_MODE_PUSH:
1022 case GST_PAD_MODE_PULL:
1029 * gst_pad_set_active:
1030 * @pad: the #GstPad to activate or deactivate.
1031 * @active: whether or not the pad should be active.
1033 * Activates or deactivates the given pad.
1034 * Normally called from within core state change functions.
1036 * If @active, makes sure the pad is active. If it is already active, either in
1037 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1038 * function to perform the actual activation.
1040 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1041 * and a %FALSE argument.
1043 * Returns: %TRUE if the operation was successful.
1048 gst_pad_set_active (GstPad * pad, gboolean active)
1052 gboolean ret = FALSE;
1054 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1056 GST_OBJECT_LOCK (pad);
1057 old = GST_PAD_MODE (pad);
1058 ACQUIRE_PARENT (pad, parent, no_parent);
1059 GST_OBJECT_UNLOCK (pad);
1062 if (old == GST_PAD_MODE_NONE) {
1063 GST_DEBUG_OBJECT (pad, "activating pad from none");
1064 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1066 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1068 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1069 gst_pad_mode_get_name (old));
1073 if (old == GST_PAD_MODE_NONE) {
1074 GST_DEBUG_OBJECT (pad, "pad was inactive");
1077 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1078 gst_pad_mode_get_name (old));
1079 ret = activate_mode_internal (pad, parent, old, FALSE);
1081 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1085 RELEASE_PARENT (parent);
1087 if (G_UNLIKELY (!ret))
1095 GST_DEBUG_OBJECT (pad, "no parent");
1096 GST_OBJECT_UNLOCK (pad);
1101 GST_OBJECT_LOCK (pad);
1103 g_critical ("Failed to deactivate pad %s:%s, very bad",
1104 GST_DEBUG_PAD_NAME (pad));
1106 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1108 GST_OBJECT_UNLOCK (pad);
1114 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1117 gboolean res = FALSE;
1118 GstPadMode old, new;
1119 GstPadDirection dir;
1122 GST_OBJECT_LOCK (pad);
1123 old = GST_PAD_MODE (pad);
1124 dir = GST_PAD_DIRECTION (pad);
1125 GST_OBJECT_UNLOCK (pad);
1127 new = active ? mode : GST_PAD_MODE_NONE;
1132 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1133 /* pad was activate in the wrong direction, deactivate it
1134 * and reactivate it in the requested mode */
1135 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1136 gst_pad_mode_get_name (old));
1138 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1139 goto deactivate_failed;
1143 case GST_PAD_MODE_PULL:
1145 if (dir == GST_PAD_SINK) {
1146 if ((peer = gst_pad_get_peer (pad))) {
1147 GST_DEBUG_OBJECT (pad, "calling peer");
1148 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1150 gst_object_unref (peer);
1152 /* there is no peer, this is only fatal when we activate. When we
1153 * deactivate, we must assume the application has unlinked the peer and
1154 * will deactivate it eventually. */
1158 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1161 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1162 goto failure; /* Can't activate pull on a src without a
1163 getrange function */
1171 /* Mark pad as needing reconfiguration */
1173 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1174 pre_activate (pad, new);
1176 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1177 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1181 /* can happen for sinks of passthrough elements */
1184 post_activate (pad, new);
1186 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1187 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1192 /* Clear sticky flags on deactivation */
1194 GST_OBJECT_LOCK (pad);
1195 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1196 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1197 GST_OBJECT_UNLOCK (pad);
1205 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1206 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1211 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1212 "failed to %s in switch to %s mode from %s mode",
1213 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1214 gst_pad_mode_get_name (old));
1219 GST_OBJECT_LOCK (peer);
1220 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1221 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1222 GST_OBJECT_UNLOCK (peer);
1223 gst_object_unref (peer);
1228 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1229 "pad in pull mode");
1234 GST_OBJECT_LOCK (pad);
1235 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1236 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1237 GST_PAD_SET_FLUSHING (pad);
1238 GST_PAD_MODE (pad) = old;
1239 GST_OBJECT_UNLOCK (pad);
1245 * gst_pad_activate_mode:
1246 * @pad: the #GstPad to activate or deactivate.
1247 * @mode: the requested activation mode
1248 * @active: whether or not the pad should be active.
1250 * Activates or deactivates the given pad in @mode via dispatching to the
1251 * pad's activatemodefunc. For use from within pad activation functions only.
1253 * If you don't know what this is, you probably don't want to call it.
1255 * Returns: %TRUE if the operation was successful.
1260 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1265 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1267 GST_OBJECT_LOCK (pad);
1268 ACQUIRE_PARENT (pad, parent, no_parent);
1269 GST_OBJECT_UNLOCK (pad);
1271 res = activate_mode_internal (pad, parent, mode, active);
1273 RELEASE_PARENT (parent);
1279 GST_WARNING_OBJECT (pad, "no parent");
1280 GST_OBJECT_UNLOCK (pad);
1286 * gst_pad_is_active:
1287 * @pad: the #GstPad to query
1289 * Query if a pad is active
1291 * Returns: %TRUE if the pad is active.
1296 gst_pad_is_active (GstPad * pad)
1298 gboolean result = FALSE;
1300 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1302 GST_OBJECT_LOCK (pad);
1303 result = GST_PAD_IS_ACTIVE (pad);
1304 GST_OBJECT_UNLOCK (pad);
1310 cleanup_hook (GstPad * pad, GHook * hook)
1312 GstPadProbeType type;
1314 if (!G_HOOK_IS_VALID (hook))
1317 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1319 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1320 /* unblock when we remove the last blocking probe */
1322 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1325 /* Might have new probes now that want to be called */
1326 GST_PAD_BLOCK_BROADCAST (pad);
1328 if (pad->num_blocked == 0) {
1329 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1330 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1333 g_hook_destroy_link (&pad->probes, hook);
1338 * gst_pad_add_probe:
1339 * @pad: the #GstPad to add the probe to
1340 * @mask: the probe mask
1341 * @callback: #GstPadProbeCallback that will be called with notifications of
1343 * @user_data: (closure): user data passed to the callback
1344 * @destroy_data: #GDestroyNotify for user_data
1346 * Be notified of different states of pads. The provided callback is called for
1347 * every state that matches @mask.
1349 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1350 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1351 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1352 * immediately if the pad is already idle while calling gst_pad_add_probe().
1353 * In each of the groups, probes are called in the order in which they were
1356 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1357 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1358 * happen that the probe can be run immediately and if the probe returns
1359 * GST_PAD_PROBE_REMOVE this functions returns 0.
1364 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1365 GstPadProbeCallback callback, gpointer user_data,
1366 GDestroyNotify destroy_data)
1371 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1372 g_return_val_if_fail (mask != 0, 0);
1374 GST_OBJECT_LOCK (pad);
1376 /* make a new probe */
1377 hook = g_hook_alloc (&pad->probes);
1379 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1382 /* when no contraints are given for the types, assume all types are
1384 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1385 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1386 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1387 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1389 /* store our flags and other fields */
1390 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1391 hook->func = callback;
1392 hook->data = user_data;
1393 hook->destroy = destroy_data;
1394 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1397 g_hook_append (&pad->probes, hook);
1399 /* incremenent cookie so that the new hook get's called */
1400 pad->priv->probe_list_cookie++;
1402 /* get the id of the hook, we return this and it can be used to remove the
1404 res = hook->hook_id;
1406 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1408 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1409 /* we have a block probe */
1411 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1412 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1413 "now %d blocking probes", pad->num_blocked);
1415 /* Might have new probes now that want to be called */
1416 GST_PAD_BLOCK_BROADCAST (pad);
1419 /* call the callback if we need to be called for idle callbacks */
1420 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1421 if (pad->priv->using > 0) {
1422 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1423 * flag above, the last thread to leave the push will do the callback. New
1424 * threads going into the push will block. */
1425 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1426 "pad is in use, delay idle callback");
1427 GST_OBJECT_UNLOCK (pad);
1429 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1430 GstPadProbeReturn ret;
1432 /* Keep another ref, the callback could destroy the pad */
1433 gst_object_ref (pad);
1434 pad->priv->idle_running++;
1436 /* the pad is idle now, we can signal the idle callback now */
1437 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1438 "pad is idle, trigger idle callback");
1439 GST_OBJECT_UNLOCK (pad);
1441 ret = callback (pad, &info, user_data);
1443 GST_OBJECT_LOCK (pad);
1445 case GST_PAD_PROBE_REMOVE:
1446 /* remove the probe */
1447 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1448 cleanup_hook (pad, hook);
1451 case GST_PAD_PROBE_DROP:
1452 GST_DEBUG_OBJECT (pad, "asked to drop item");
1454 case GST_PAD_PROBE_PASS:
1455 GST_DEBUG_OBJECT (pad, "asked to pass item");
1457 case GST_PAD_PROBE_OK:
1458 GST_DEBUG_OBJECT (pad, "probe returned OK");
1460 case GST_PAD_PROBE_HANDLED:
1461 GST_DEBUG_OBJECT (pad, "probe handled the data");
1464 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1467 pad->priv->idle_running--;
1468 if (pad->priv->idle_running == 0) {
1469 GST_PAD_BLOCK_BROADCAST (pad);
1471 GST_OBJECT_UNLOCK (pad);
1473 gst_object_unref (pad);
1476 GST_OBJECT_UNLOCK (pad);
1482 * gst_pad_remove_probe:
1483 * @pad: the #GstPad with the probe
1484 * @id: the probe id to remove
1486 * Remove the probe with @id from @pad.
1491 gst_pad_remove_probe (GstPad * pad, gulong id)
1495 g_return_if_fail (GST_IS_PAD (pad));
1497 GST_OBJECT_LOCK (pad);
1499 hook = g_hook_get (&pad->probes, id);
1503 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1505 cleanup_hook (pad, hook);
1506 GST_OBJECT_UNLOCK (pad);
1512 GST_OBJECT_UNLOCK (pad);
1513 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1519 * gst_pad_is_blocked:
1520 * @pad: the #GstPad to query
1522 * Checks if the pad is blocked or not. This function returns the
1523 * last requested state of the pad. It is not certain that the pad
1524 * is actually blocking at this point (see gst_pad_is_blocking()).
1526 * Returns: %TRUE if the pad is blocked.
1531 gst_pad_is_blocked (GstPad * pad)
1533 gboolean result = FALSE;
1535 g_return_val_if_fail (GST_IS_PAD (pad), result);
1537 GST_OBJECT_LOCK (pad);
1538 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1539 GST_OBJECT_UNLOCK (pad);
1545 * gst_pad_is_blocking:
1546 * @pad: the #GstPad to query
1548 * Checks if the pad is blocking or not. This is a guaranteed state
1549 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1551 * Returns: %TRUE if the pad is blocking.
1556 gst_pad_is_blocking (GstPad * pad)
1558 gboolean result = FALSE;
1560 g_return_val_if_fail (GST_IS_PAD (pad), result);
1562 GST_OBJECT_LOCK (pad);
1563 /* the blocking flag is only valid if the pad is not flushing */
1564 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1565 GST_OBJECT_UNLOCK (pad);
1571 * gst_pad_needs_reconfigure:
1572 * @pad: the #GstPad to check
1574 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1575 * if the flag was set.
1577 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1580 gst_pad_needs_reconfigure (GstPad * pad)
1582 gboolean reconfigure;
1584 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1586 GST_OBJECT_LOCK (pad);
1587 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1588 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1589 GST_OBJECT_UNLOCK (pad);
1595 * gst_pad_check_reconfigure:
1596 * @pad: the #GstPad to check
1598 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1599 * if the flag was set.
1601 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1604 gst_pad_check_reconfigure (GstPad * pad)
1606 gboolean reconfigure;
1608 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1610 GST_OBJECT_LOCK (pad);
1611 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1613 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1614 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1616 GST_OBJECT_UNLOCK (pad);
1622 * gst_pad_mark_reconfigure:
1623 * @pad: the #GstPad to mark
1625 * Mark a pad for needing reconfiguration. The next call to
1626 * gst_pad_check_reconfigure() will return %TRUE after this call.
1629 gst_pad_mark_reconfigure (GstPad * pad)
1631 g_return_if_fail (GST_IS_PAD (pad));
1633 GST_OBJECT_LOCK (pad);
1634 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1635 GST_OBJECT_UNLOCK (pad);
1639 * gst_pad_set_activate_function:
1641 * @f: the #GstPadActivateFunction to set.
1643 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1647 * gst_pad_set_activate_function_full:
1649 * @activate: the #GstPadActivateFunction to set.
1650 * @user_data: user_data passed to @notify
1651 * @notify: notify called when @activate will not be used anymore.
1653 * Sets the given activate function for @pad. The activate function will
1654 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1655 * Only makes sense to set on sink pads.
1657 * Call this function if your sink pad can start a pull-based task.
1660 gst_pad_set_activate_function_full (GstPad * pad,
1661 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1663 g_return_if_fail (GST_IS_PAD (pad));
1665 if (pad->activatenotify)
1666 pad->activatenotify (pad->activatedata);
1667 GST_PAD_ACTIVATEFUNC (pad) = activate;
1668 pad->activatedata = user_data;
1669 pad->activatenotify = notify;
1671 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1672 GST_DEBUG_FUNCPTR_NAME (activate));
1676 * gst_pad_set_activatemode_function:
1678 * @f: the #GstPadActivateModeFunction to set.
1680 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1684 * gst_pad_set_activatemode_function_full:
1686 * @activatemode: the #GstPadActivateModeFunction to set.
1687 * @user_data: user_data passed to @notify
1688 * @notify: notify called when @activatemode will not be used anymore.
1690 * Sets the given activate_mode function for the pad. An activate_mode function
1691 * prepares the element for data passing.
1694 gst_pad_set_activatemode_function_full (GstPad * pad,
1695 GstPadActivateModeFunction activatemode, gpointer user_data,
1696 GDestroyNotify notify)
1698 g_return_if_fail (GST_IS_PAD (pad));
1700 if (pad->activatemodenotify)
1701 pad->activatemodenotify (pad->activatemodedata);
1702 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1703 pad->activatemodedata = user_data;
1704 pad->activatemodenotify = notify;
1706 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1707 GST_DEBUG_FUNCPTR_NAME (activatemode));
1711 * gst_pad_set_chain_function:
1712 * @p: a sink #GstPad.
1713 * @f: the #GstPadChainFunction to set.
1715 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1719 * gst_pad_set_chain_function_full:
1720 * @pad: a sink #GstPad.
1721 * @chain: the #GstPadChainFunction to set.
1722 * @user_data: user_data passed to @notify
1723 * @notify: notify called when @chain will not be used anymore.
1725 * Sets the given chain function for the pad. The chain function is called to
1726 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1729 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1730 gpointer user_data, GDestroyNotify notify)
1732 g_return_if_fail (GST_IS_PAD (pad));
1733 g_return_if_fail (GST_PAD_IS_SINK (pad));
1735 if (pad->chainnotify)
1736 pad->chainnotify (pad->chaindata);
1737 GST_PAD_CHAINFUNC (pad) = chain;
1738 pad->chaindata = user_data;
1739 pad->chainnotify = notify;
1741 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1742 GST_DEBUG_FUNCPTR_NAME (chain));
1746 * gst_pad_set_chain_list_function:
1747 * @p: a sink #GstPad.
1748 * @f: the #GstPadChainListFunction to set.
1750 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1754 * gst_pad_set_chain_list_function_full:
1755 * @pad: a sink #GstPad.
1756 * @chainlist: the #GstPadChainListFunction to set.
1757 * @user_data: user_data passed to @notify
1758 * @notify: notify called when @chainlist will not be used anymore.
1760 * Sets the given chain list function for the pad. The chainlist function is
1761 * called to process a #GstBufferList input buffer list. See
1762 * #GstPadChainListFunction for more details.
1765 gst_pad_set_chain_list_function_full (GstPad * pad,
1766 GstPadChainListFunction chainlist, gpointer user_data,
1767 GDestroyNotify notify)
1769 g_return_if_fail (GST_IS_PAD (pad));
1770 g_return_if_fail (GST_PAD_IS_SINK (pad));
1772 if (pad->chainlistnotify)
1773 pad->chainlistnotify (pad->chainlistdata);
1774 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1775 pad->chainlistdata = user_data;
1776 pad->chainlistnotify = notify;
1778 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1779 GST_DEBUG_FUNCPTR_NAME (chainlist));
1783 * gst_pad_set_getrange_function:
1784 * @p: a source #GstPad.
1785 * @f: the #GstPadGetRangeFunction to set.
1787 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1791 * gst_pad_set_getrange_function_full:
1792 * @pad: a source #GstPad.
1793 * @get: the #GstPadGetRangeFunction to set.
1794 * @user_data: user_data passed to @notify
1795 * @notify: notify called when @get will not be used anymore.
1797 * Sets the given getrange function for the pad. The getrange function is
1798 * called to produce a new #GstBuffer to start the processing pipeline. see
1799 * #GstPadGetRangeFunction for a description of the getrange function.
1802 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1803 gpointer user_data, GDestroyNotify notify)
1805 g_return_if_fail (GST_IS_PAD (pad));
1806 g_return_if_fail (GST_PAD_IS_SRC (pad));
1808 if (pad->getrangenotify)
1809 pad->getrangenotify (pad->getrangedata);
1810 GST_PAD_GETRANGEFUNC (pad) = get;
1811 pad->getrangedata = user_data;
1812 pad->getrangenotify = notify;
1814 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1815 GST_DEBUG_FUNCPTR_NAME (get));
1819 * gst_pad_set_event_function:
1820 * @p: a #GstPad of either direction.
1821 * @f: the #GstPadEventFunction to set.
1823 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1827 * gst_pad_set_event_function_full:
1828 * @pad: a #GstPad of either direction.
1829 * @event: the #GstPadEventFunction to set.
1830 * @user_data: user_data passed to @notify
1831 * @notify: notify called when @event will not be used anymore.
1833 * Sets the given event handler for the pad.
1836 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1837 gpointer user_data, GDestroyNotify notify)
1839 g_return_if_fail (GST_IS_PAD (pad));
1841 if (pad->eventnotify)
1842 pad->eventnotify (pad->eventdata);
1843 GST_PAD_EVENTFUNC (pad) = event;
1844 pad->eventdata = user_data;
1845 pad->eventnotify = notify;
1847 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1848 GST_DEBUG_FUNCPTR_NAME (event));
1852 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1856 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1857 if (ret == GST_FLOW_OK)
1863 * gst_pad_set_event_full_function:
1864 * @p: a #GstPad of either direction.
1865 * @f: the #GstPadEventFullFunction to set.
1867 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1871 * gst_pad_set_event_full_function_full:
1872 * @pad: a #GstPad of either direction.
1873 * @event: the #GstPadEventFullFunction to set.
1874 * @user_data: user_data passed to @notify
1875 * @notify: notify called when @event will not be used anymore.
1877 * Sets the given event handler for the pad.
1882 gst_pad_set_event_full_function_full (GstPad * pad,
1883 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1885 g_return_if_fail (GST_IS_PAD (pad));
1887 if (pad->eventnotify)
1888 pad->eventnotify (pad->eventdata);
1889 GST_PAD_EVENTFULLFUNC (pad) = event;
1890 GST_PAD_EVENTFUNC (pad) = event_wrap;
1891 pad->eventdata = user_data;
1892 pad->eventnotify = notify;
1894 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1895 GST_DEBUG_FUNCPTR_NAME (event));
1899 * gst_pad_set_query_function:
1900 * @p: a #GstPad of either direction.
1901 * @f: the #GstPadQueryFunction to set.
1903 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1907 * gst_pad_set_query_function_full:
1908 * @pad: a #GstPad of either direction.
1909 * @query: the #GstPadQueryFunction to set.
1910 * @user_data: user_data passed to @notify
1911 * @notify: notify called when @query will not be used anymore.
1913 * Set the given query function for the pad.
1916 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1917 gpointer user_data, GDestroyNotify notify)
1919 g_return_if_fail (GST_IS_PAD (pad));
1921 if (pad->querynotify)
1922 pad->querynotify (pad->querydata);
1923 GST_PAD_QUERYFUNC (pad) = query;
1924 pad->querydata = user_data;
1925 pad->querynotify = notify;
1927 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1928 GST_DEBUG_FUNCPTR_NAME (query));
1932 * gst_pad_set_iterate_internal_links_function:
1933 * @p: a #GstPad of either direction.
1934 * @f: the #GstPadIterIntLinkFunction to set.
1936 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1937 * for the user_data and notify.
1940 * gst_pad_set_iterate_internal_links_function_full:
1941 * @pad: a #GstPad of either direction.
1942 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1943 * @user_data: user_data passed to @notify
1944 * @notify: notify called when @iterintlink will not be used anymore.
1946 * Sets the given internal link iterator function for the pad.
1949 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1950 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1951 GDestroyNotify notify)
1953 g_return_if_fail (GST_IS_PAD (pad));
1955 if (pad->iterintlinknotify)
1956 pad->iterintlinknotify (pad->iterintlinkdata);
1957 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1958 pad->iterintlinkdata = user_data;
1959 pad->iterintlinknotify = notify;
1961 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1962 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1966 * gst_pad_set_link_function:
1968 * @f: the #GstPadLinkFunction to set.
1970 * Calls gst_pad_set_link_function_full() with %NULL
1971 * for the user_data and notify.
1974 * gst_pad_set_link_function_full:
1976 * @link: the #GstPadLinkFunction to set.
1977 * @user_data: user_data passed to @notify
1978 * @notify: notify called when @link will not be used anymore.
1980 * Sets the given link function for the pad. It will be called when
1981 * the pad is linked with another pad.
1983 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1986 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1987 * cannot be made for some reason.
1989 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1990 * of the peer sink pad, if present.
1993 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1994 gpointer user_data, GDestroyNotify notify)
1996 g_return_if_fail (GST_IS_PAD (pad));
1998 if (pad->linknotify)
1999 pad->linknotify (pad->linkdata);
2000 GST_PAD_LINKFUNC (pad) = link;
2001 pad->linkdata = user_data;
2002 pad->linknotify = notify;
2004 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2005 GST_DEBUG_FUNCPTR_NAME (link));
2009 * gst_pad_set_unlink_function:
2011 * @f: the #GstPadUnlinkFunction to set.
2013 * Calls gst_pad_set_unlink_function_full() with %NULL
2014 * for the user_data and notify.
2017 * gst_pad_set_unlink_function_full:
2019 * @unlink: the #GstPadUnlinkFunction to set.
2020 * @user_data: user_data passed to @notify
2021 * @notify: notify called when @unlink will not be used anymore.
2023 * Sets the given unlink function for the pad. It will be called
2024 * when the pad is unlinked.
2027 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2028 gpointer user_data, GDestroyNotify notify)
2030 g_return_if_fail (GST_IS_PAD (pad));
2032 if (pad->unlinknotify)
2033 pad->unlinknotify (pad->unlinkdata);
2034 GST_PAD_UNLINKFUNC (pad) = unlink;
2035 pad->unlinkdata = user_data;
2036 pad->unlinknotify = notify;
2038 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2039 GST_DEBUG_FUNCPTR_NAME (unlink));
2044 * @srcpad: the source #GstPad to unlink.
2045 * @sinkpad: the sink #GstPad to unlink.
2047 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2048 * signal on both pads.
2050 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2051 * the pads were not linked together.
2056 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2058 gboolean result = FALSE;
2059 GstElement *parent = NULL;
2061 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2062 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2063 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2064 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2066 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2068 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2069 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2070 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2072 /* We need to notify the parent before taking any pad locks as the bin in
2073 * question might be waiting for a lock on the pad while holding its lock
2074 * that our message will try to take. */
2075 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2076 if (GST_IS_ELEMENT (parent)) {
2077 gst_element_post_message (parent,
2078 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2079 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2081 gst_object_unref (parent);
2086 GST_OBJECT_LOCK (srcpad);
2087 GST_OBJECT_LOCK (sinkpad);
2089 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2090 goto not_linked_together;
2092 if (GST_PAD_UNLINKFUNC (srcpad)) {
2093 GstObject *tmpparent;
2095 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2097 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2098 RELEASE_PARENT (tmpparent);
2101 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2102 GstObject *tmpparent;
2104 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2106 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2107 RELEASE_PARENT (tmpparent);
2111 /* first clear peers */
2112 GST_PAD_PEER (srcpad) = NULL;
2113 GST_PAD_PEER (sinkpad) = NULL;
2115 GST_OBJECT_UNLOCK (sinkpad);
2116 GST_OBJECT_UNLOCK (srcpad);
2118 /* fire off a signal to each of the pads telling them
2119 * that they've been unlinked */
2120 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2121 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2123 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2124 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2129 if (parent != NULL) {
2130 gst_element_post_message (parent,
2131 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2132 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2133 gst_object_unref (parent);
2135 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2139 not_linked_together:
2141 /* we do not emit a warning in this case because unlinking cannot
2142 * be made MT safe.*/
2143 GST_OBJECT_UNLOCK (sinkpad);
2144 GST_OBJECT_UNLOCK (srcpad);
2150 * gst_pad_is_linked:
2151 * @pad: pad to check
2153 * Checks if a @pad is linked to another pad or not.
2155 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2160 gst_pad_is_linked (GstPad * pad)
2164 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2166 GST_OBJECT_LOCK (pad);
2167 result = (GST_PAD_PEER (pad) != NULL);
2168 GST_OBJECT_UNLOCK (pad);
2173 /* get the caps from both pads and see if the intersection
2176 * This function should be called with the pad LOCK on both
2180 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2181 GstPadLinkCheck flags)
2183 GstCaps *srccaps = NULL;
2184 GstCaps *sinkcaps = NULL;
2185 gboolean compatible = FALSE;
2187 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2190 /* Doing the expensive caps checking takes priority over only checking the template caps */
2191 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2192 GST_OBJECT_UNLOCK (sink);
2193 GST_OBJECT_UNLOCK (src);
2195 srccaps = gst_pad_query_caps (src, NULL);
2196 sinkcaps = gst_pad_query_caps (sink, NULL);
2198 GST_OBJECT_LOCK (src);
2199 GST_OBJECT_LOCK (sink);
2201 /* If one of the two pads doesn't have a template, consider the intersection
2203 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2204 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2208 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2210 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2215 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2218 /* if we have caps on both pads we can check the intersection. If one
2219 * of the caps is %NULL, we return %TRUE. */
2220 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2222 gst_caps_unref (srccaps);
2224 gst_caps_unref (sinkcaps);
2228 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2229 gst_caps_unref (srccaps);
2230 gst_caps_unref (sinkcaps);
2233 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2234 (compatible ? "" : "not "));
2239 /* check if the grandparents of both pads are the same.
2240 * This check is required so that we don't try to link
2241 * pads from elements in different bins without ghostpads.
2243 * The LOCK should be held on both pads
2246 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2248 GstObject *psrc, *psink;
2250 psrc = GST_OBJECT_PARENT (src);
2251 psink = GST_OBJECT_PARENT (sink);
2253 /* if one of the pads has no parent, we allow the link */
2254 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2257 /* only care about parents that are elements */
2258 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2259 goto no_element_parent;
2261 /* if the parents are the same, we have a loop */
2262 if (G_UNLIKELY (psrc == psink))
2265 /* if they both have a parent, we check the grandparents. We can not lock
2266 * the parent because we hold on the child (pad) and the locking order is
2267 * parent >> child. */
2268 psrc = GST_OBJECT_PARENT (psrc);
2269 psink = GST_OBJECT_PARENT (psink);
2271 /* if they have grandparents but they are not the same */
2272 if (G_UNLIKELY (psrc != psink))
2273 goto wrong_grandparents;
2280 GST_CAT_DEBUG (GST_CAT_CAPS,
2281 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2282 GST_PTR_FORMAT, psrc, psink);
2287 GST_CAT_DEBUG (GST_CAT_CAPS,
2288 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2289 GST_PTR_FORMAT, psrc, psink);
2294 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2300 GST_CAT_DEBUG (GST_CAT_CAPS,
2301 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2302 GST_PTR_FORMAT, psrc, psink);
2307 /* FIXME leftover from an attempt at refactoring... */
2308 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2309 * the two pads will be locked in the srcpad, sinkpad order. */
2310 static GstPadLinkReturn
2311 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2313 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2314 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2316 GST_OBJECT_LOCK (srcpad);
2318 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2319 goto src_was_linked;
2321 GST_OBJECT_LOCK (sinkpad);
2323 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2324 goto sink_was_linked;
2326 /* check hierarchy, pads can only be linked if the grandparents
2328 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2329 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2330 goto wrong_hierarchy;
2332 /* check pad caps for non-empty intersection */
2333 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2336 /* FIXME check pad scheduling for non-empty intersection */
2338 return GST_PAD_LINK_OK;
2342 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2343 GST_DEBUG_PAD_NAME (srcpad),
2344 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2345 /* we do not emit a warning in this case because unlinking cannot
2346 * be made MT safe.*/
2347 GST_OBJECT_UNLOCK (srcpad);
2348 return GST_PAD_LINK_WAS_LINKED;
2352 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2353 GST_DEBUG_PAD_NAME (sinkpad),
2354 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2355 /* we do not emit a warning in this case because unlinking cannot
2356 * be made MT safe.*/
2357 GST_OBJECT_UNLOCK (sinkpad);
2358 GST_OBJECT_UNLOCK (srcpad);
2359 return GST_PAD_LINK_WAS_LINKED;
2363 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2364 GST_OBJECT_UNLOCK (sinkpad);
2365 GST_OBJECT_UNLOCK (srcpad);
2366 return GST_PAD_LINK_WRONG_HIERARCHY;
2370 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2371 GST_OBJECT_UNLOCK (sinkpad);
2372 GST_OBJECT_UNLOCK (srcpad);
2373 return GST_PAD_LINK_NOFORMAT;
2379 * @srcpad: the source #GstPad.
2380 * @sinkpad: the sink #GstPad.
2382 * Checks if the source pad and the sink pad are compatible so they can be
2385 * Returns: %TRUE if the pads can be linked.
2388 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2390 GstPadLinkReturn result;
2392 /* generic checks */
2393 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2394 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2396 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2397 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2399 /* gst_pad_link_prepare does everything for us, we only release the locks
2400 * on the pads that it gets us. If this function returns !OK the locks are not
2402 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2403 if (result != GST_PAD_LINK_OK)
2406 GST_OBJECT_UNLOCK (srcpad);
2407 GST_OBJECT_UNLOCK (sinkpad);
2410 return result == GST_PAD_LINK_OK;
2414 * gst_pad_link_full:
2415 * @srcpad: the source #GstPad to link.
2416 * @sinkpad: the sink #GstPad to link.
2417 * @flags: the checks to validate when linking
2419 * Links the source pad and the sink pad.
2421 * This variant of #gst_pad_link provides a more granular control on the
2422 * checks being done when linking. While providing some considerable speedups
2423 * the caller of this method must be aware that wrong usage of those flags
2424 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2425 * for more information.
2429 * Returns: A result code indicating if the connection worked or
2433 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2435 GstPadLinkReturn result;
2437 GstPadLinkFunction srcfunc, sinkfunc;
2439 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2440 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2441 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2442 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2443 GST_PAD_LINK_WRONG_DIRECTION);
2445 /* Notify the parent early. See gst_pad_unlink for details. */
2446 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2447 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2448 gst_element_post_message (parent,
2449 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2450 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2452 gst_object_unref (parent);
2457 /* prepare will also lock the two pads */
2458 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2460 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2461 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2462 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2463 gst_pad_link_get_name (result));
2467 /* must set peers before calling the link function */
2468 GST_PAD_PEER (srcpad) = sinkpad;
2469 GST_PAD_PEER (sinkpad) = srcpad;
2471 /* check events, when something is different, mark pending */
2472 schedule_events (srcpad, sinkpad);
2474 /* get the link functions */
2475 srcfunc = GST_PAD_LINKFUNC (srcpad);
2476 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2478 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2479 /* custom link functions, execute them */
2480 GST_OBJECT_UNLOCK (sinkpad);
2481 GST_OBJECT_UNLOCK (srcpad);
2484 GstObject *tmpparent;
2486 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2487 /* this one will call the peer link function */
2488 result = srcfunc (srcpad, tmpparent, sinkpad);
2489 RELEASE_PARENT (tmpparent);
2490 } else if (sinkfunc) {
2491 GstObject *tmpparent;
2493 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2494 /* if no source link function, we need to call the sink link
2495 * function ourselves. */
2496 result = sinkfunc (sinkpad, tmpparent, srcpad);
2497 RELEASE_PARENT (tmpparent);
2501 GST_OBJECT_LOCK (srcpad);
2502 GST_OBJECT_LOCK (sinkpad);
2504 /* we released the lock, check if the same pads are linked still */
2505 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2506 goto concurrent_link;
2508 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2511 GST_OBJECT_UNLOCK (sinkpad);
2512 GST_OBJECT_UNLOCK (srcpad);
2514 /* fire off a signal to each of the pads telling them
2515 * that they've been linked */
2516 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2517 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2519 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2520 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2522 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2525 if (G_LIKELY (parent)) {
2526 gst_element_post_message (parent,
2527 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2528 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2529 gst_object_unref (parent);
2537 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2538 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2539 GST_OBJECT_UNLOCK (sinkpad);
2540 GST_OBJECT_UNLOCK (srcpad);
2542 /* The other link operation succeeded first */
2543 result = GST_PAD_LINK_WAS_LINKED;
2548 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2549 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2550 gst_pad_link_get_name (result));
2552 GST_PAD_PEER (srcpad) = NULL;
2553 GST_PAD_PEER (sinkpad) = NULL;
2555 GST_OBJECT_UNLOCK (sinkpad);
2556 GST_OBJECT_UNLOCK (srcpad);
2564 * @srcpad: the source #GstPad to link.
2565 * @sinkpad: the sink #GstPad to link.
2567 * Links the source pad and the sink pad.
2569 * Returns: A result code indicating if the connection worked or
2575 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2577 GstPadLinkReturn ret;
2579 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2580 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2581 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, ret);
2587 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2589 GstPadTemplate **template_p;
2591 /* this function would need checks if it weren't static */
2593 GST_OBJECT_LOCK (pad);
2594 template_p = &pad->padtemplate;
2595 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2596 GST_OBJECT_UNLOCK (pad);
2599 gst_pad_template_pad_created (templ, pad);
2603 * gst_pad_get_pad_template:
2606 * Gets the template for @pad.
2608 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2609 * this pad was instantiated, or %NULL if this pad has no
2610 * template. Unref after usage.
2613 gst_pad_get_pad_template (GstPad * pad)
2615 GstPadTemplate *templ;
2617 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2619 templ = GST_PAD_PAD_TEMPLATE (pad);
2621 return (templ ? gst_object_ref (templ) : NULL);
2625 * gst_pad_has_current_caps:
2626 * @pad: a #GstPad to check
2628 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2630 * Returns: %TRUE when @pad has caps associated with it.
2633 gst_pad_has_current_caps (GstPad * pad)
2638 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2640 GST_OBJECT_LOCK (pad);
2641 caps = get_pad_caps (pad);
2642 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2643 "check current pad caps %" GST_PTR_FORMAT, caps);
2644 result = (caps != NULL);
2645 GST_OBJECT_UNLOCK (pad);
2651 * gst_pad_get_current_caps:
2652 * @pad: a #GstPad to get the current capabilities of.
2654 * Gets the capabilities currently configured on @pad with the last
2655 * #GST_EVENT_CAPS event.
2657 * Returns: (transfer full) (nullable): the current caps of the pad with
2658 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2661 gst_pad_get_current_caps (GstPad * pad)
2665 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2667 GST_OBJECT_LOCK (pad);
2668 if ((result = get_pad_caps (pad)))
2669 gst_caps_ref (result);
2670 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2671 "get current pad caps %" GST_PTR_FORMAT, result);
2672 GST_OBJECT_UNLOCK (pad);
2678 * gst_pad_get_pad_template_caps:
2679 * @pad: a #GstPad to get the template capabilities from.
2681 * Gets the capabilities for @pad's template.
2683 * Returns: (transfer full): the #GstCaps of this pad template.
2684 * Unref after usage.
2687 gst_pad_get_pad_template_caps (GstPad * pad)
2689 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2691 if (GST_PAD_PAD_TEMPLATE (pad))
2692 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2694 return gst_caps_ref (GST_CAPS_ANY);
2699 * @pad: a #GstPad to get the peer of.
2701 * Gets the peer of @pad. This function refs the peer pad so
2702 * you need to unref it after use.
2704 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2709 gst_pad_get_peer (GstPad * pad)
2713 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2715 GST_OBJECT_LOCK (pad);
2716 result = GST_PAD_PEER (pad);
2718 gst_object_ref (result);
2719 GST_OBJECT_UNLOCK (pad);
2725 * gst_pad_get_allowed_caps:
2728 * Gets the capabilities of the allowed media types that can flow through
2729 * @pad and its peer.
2731 * The allowed capabilities is calculated as the intersection of the results of
2732 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2733 * on the resulting caps.
2735 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2736 * pad link. Unref the caps when you no longer need it. This
2737 * function returns %NULL when @pad has no peer.
2742 gst_pad_get_allowed_caps (GstPad * pad)
2745 GstCaps *caps = NULL;
2748 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2750 GST_OBJECT_LOCK (pad);
2751 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2753 GST_OBJECT_UNLOCK (pad);
2755 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2757 mycaps = gst_pad_query_caps (pad, NULL);
2759 /* Query peer caps */
2760 query = gst_query_new_caps (mycaps);
2761 gst_pad_peer_query (pad, query);
2762 gst_query_parse_caps_result (query, &caps);
2763 gst_caps_ref (caps);
2764 gst_query_unref (query);
2766 gst_caps_unref (mycaps);
2768 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2775 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2776 GST_OBJECT_UNLOCK (pad);
2783 * gst_pad_iterate_internal_links_default:
2784 * @pad: the #GstPad to get the internal links of.
2785 * @parent: (allow-none): the parent of @pad or %NULL
2787 * Iterate the list of pads to which the given pad is linked to inside of
2788 * the parent element.
2789 * This is the default handler, and thus returns an iterator of all of the
2790 * pads inside the parent element with opposite direction.
2792 * The caller must free this iterator after use with gst_iterator_free().
2794 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2795 * has no parent. Unref each returned pad with gst_object_unref().
2798 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2805 GstElement *eparent;
2807 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2809 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2810 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2812 GST_OBJECT_LOCK (pad);
2813 eparent = GST_PAD_PARENT (pad);
2814 if (!eparent || !GST_IS_ELEMENT (eparent))
2817 gst_object_ref (eparent);
2818 GST_OBJECT_UNLOCK (pad);
2821 if (pad->direction == GST_PAD_SRC)
2822 padlist = &eparent->sinkpads;
2824 padlist = &eparent->srcpads;
2826 GST_DEBUG_OBJECT (pad, "Making iterator");
2828 cookie = &eparent->pads_cookie;
2830 lock = GST_OBJECT_GET_LOCK (eparent);
2832 res = gst_iterator_new_list (GST_TYPE_PAD,
2833 lock, cookie, padlist, (GObject *) owner, NULL);
2835 gst_object_unref (owner);
2842 GST_OBJECT_UNLOCK (pad);
2843 GST_DEBUG_OBJECT (pad, "no parent element");
2849 * gst_pad_iterate_internal_links:
2850 * @pad: the GstPad to get the internal links of.
2852 * Gets an iterator for the pads to which the given pad is linked to inside
2853 * of the parent element.
2855 * Each #GstPad element yielded by the iterator will have its refcount increased,
2856 * so unref after use.
2858 * Free-function: gst_iterator_free
2860 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2861 * or %NULL when the pad does not have an iterator function
2862 * configured. Use gst_iterator_free() after usage.
2865 gst_pad_iterate_internal_links (GstPad * pad)
2867 GstIterator *res = NULL;
2870 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2872 GST_OBJECT_LOCK (pad);
2873 ACQUIRE_PARENT (pad, parent, no_parent);
2874 GST_OBJECT_UNLOCK (pad);
2876 if (GST_PAD_ITERINTLINKFUNC (pad))
2877 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2879 RELEASE_PARENT (parent);
2886 GST_DEBUG_OBJECT (pad, "no parent");
2887 GST_OBJECT_UNLOCK (pad);
2895 * @forward: (scope call): a #GstPadForwardFunction
2896 * @user_data: user data passed to @forward
2898 * Calls @forward for all internally linked pads of @pad. This function deals with
2899 * dynamically changing internal pads and will make sure that the @forward
2900 * function is only called once for each pad.
2902 * When @forward returns %TRUE, no further pads will be processed.
2904 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2907 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2910 gboolean result = FALSE;
2912 gboolean done = FALSE;
2913 GValue item = { 0, };
2914 GList *pushed_pads = NULL;
2916 iter = gst_pad_iterate_internal_links (pad);
2922 switch (gst_iterator_next (iter, &item)) {
2923 case GST_ITERATOR_OK:
2927 intpad = g_value_get_object (&item);
2929 /* if already pushed, skip. FIXME, find something faster to tag pads */
2930 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2931 g_value_reset (&item);
2935 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2936 GST_DEBUG_PAD_NAME (intpad));
2937 done = result = forward (intpad, user_data);
2939 pushed_pads = g_list_prepend (pushed_pads, intpad);
2941 g_value_reset (&item);
2944 case GST_ITERATOR_RESYNC:
2945 /* We don't reset the result here because we don't push the event
2946 * again on pads that got the event already and because we need
2947 * to consider the result of the previous pushes */
2948 gst_iterator_resync (iter);
2950 case GST_ITERATOR_ERROR:
2951 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2954 case GST_ITERATOR_DONE:
2959 g_value_unset (&item);
2960 gst_iterator_free (iter);
2962 g_list_free (pushed_pads);
2972 gboolean dispatched;
2976 event_forward_func (GstPad * pad, EventData * data)
2978 /* for each pad we send to, we should ref the event; it's up
2979 * to downstream to unref again when handled. */
2980 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2981 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2983 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2985 data->dispatched = TRUE;
2992 * gst_pad_event_default:
2993 * @pad: a #GstPad to call the default event handler on.
2994 * @parent: (allow-none): the parent of @pad or %NULL
2995 * @event: (transfer full): the #GstEvent to handle.
2997 * Invokes the default event handler for the given pad.
2999 * The EOS event will pause the task associated with @pad before it is forwarded
3000 * to all internally linked pads,
3002 * The event is sent to all pads internally linked to @pad. This function
3003 * takes ownership of @event.
3005 * Returns: %TRUE if the event was sent successfully.
3008 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3010 gboolean result, forward = TRUE;
3012 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3013 g_return_val_if_fail (event != NULL, FALSE);
3015 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3018 switch (GST_EVENT_TYPE (event)) {
3019 case GST_EVENT_CAPS:
3020 forward = GST_PAD_IS_PROXY_CAPS (pad);
3031 data.dispatched = FALSE;
3032 data.result = FALSE;
3034 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3036 /* for sinkpads without a parent element or without internal links, nothing
3037 * will be dispatched but we still want to return TRUE. */
3038 if (data.dispatched)
3039 result = data.result;
3044 gst_event_unref (event);
3049 /* Default accept caps implementation just checks against
3050 * the allowed caps for the pad */
3052 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3054 /* get the caps and see if it intersects to something not empty */
3055 GstCaps *caps, *allowed = NULL;
3058 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3060 /* first forward the query to internally linked pads when we are dealing with
3062 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3063 result = gst_pad_proxy_query_accept_caps (pad, query);
3065 allowed = gst_pad_get_pad_template_caps (pad);
3070 gst_query_parse_accept_caps (query, &caps);
3072 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3073 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3074 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad))
3075 allowed = gst_pad_get_pad_template_caps (pad);
3077 allowed = gst_pad_query_caps (pad, caps);
3081 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3082 GST_DEBUG_OBJECT (pad,
3083 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3085 result = gst_caps_can_intersect (caps, allowed);
3087 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3088 GST_PTR_FORMAT, allowed, caps);
3089 result = gst_caps_is_subset (caps, allowed);
3091 gst_caps_unref (allowed);
3093 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3096 gst_query_set_accept_caps_result (query, result);
3102 /* Default caps implementation */
3104 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3106 GstCaps *result = NULL, *filter;
3107 GstPadTemplate *templ;
3108 gboolean fixed_caps;
3110 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3113 /* first try to proxy if we must */
3114 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3115 if ((gst_pad_proxy_query_caps (pad, query))) {
3120 gst_query_parse_caps (query, &filter);
3122 /* no proxy or it failed, do default handling */
3123 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3125 GST_OBJECT_LOCK (pad);
3127 /* fixed caps, try the negotiated caps first */
3128 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3129 if ((result = get_pad_caps (pad)))
3130 goto filter_done_unlock;
3133 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3134 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3135 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3136 goto filter_done_unlock;
3140 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3141 "non-fixed pad caps: trying pad caps");
3142 /* non fixed caps, try the negotiated caps */
3143 if ((result = get_pad_caps (pad)))
3144 goto filter_done_unlock;
3147 /* this almost never happens */
3148 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3149 result = GST_CAPS_ANY;
3152 GST_OBJECT_UNLOCK (pad);
3154 /* run the filter on the result */
3156 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3157 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3158 GST_PTR_FORMAT, result, result, filter, filter);
3159 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3160 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3163 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3164 "using caps %p %" GST_PTR_FORMAT, result, result);
3165 result = gst_caps_ref (result);
3167 gst_query_set_caps_result (query, result);
3168 gst_caps_unref (result);
3174 /* Default latency implementation */
3178 GstClockTime min, max;
3182 query_latency_default_fold (const GValue * item, GValue * ret,
3185 GstPad *pad = g_value_get_object (item), *peer;
3186 LatencyFoldData *fold_data = user_data;
3188 gboolean res = FALSE;
3190 query = gst_query_new_latency ();
3192 peer = gst_pad_get_peer (pad);
3194 res = gst_pad_peer_query (pad, query);
3196 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3201 GstClockTime min, max;
3203 gst_query_parse_latency (query, &live, &min, &max);
3205 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3206 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3209 if (min > fold_data->min)
3210 fold_data->min = min;
3212 if (fold_data->max == GST_CLOCK_TIME_NONE)
3213 fold_data->max = max;
3214 else if (max < fold_data->max)
3215 fold_data->max = max;
3217 fold_data->live = TRUE;
3220 GST_DEBUG_OBJECT (pad, "latency query failed");
3221 g_value_set_boolean (ret, FALSE);
3224 gst_query_unref (query);
3226 gst_object_unref (peer);
3232 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3235 GstIteratorResult res;
3236 GValue ret = G_VALUE_INIT;
3238 LatencyFoldData fold_data;
3240 it = gst_pad_iterate_internal_links (pad);
3242 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3246 g_value_init (&ret, G_TYPE_BOOLEAN);
3249 fold_data.live = FALSE;
3251 fold_data.max = GST_CLOCK_TIME_NONE;
3253 g_value_set_boolean (&ret, TRUE);
3254 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3256 case GST_ITERATOR_OK:
3257 g_assert_not_reached ();
3259 case GST_ITERATOR_DONE:
3261 case GST_ITERATOR_ERROR:
3262 g_value_set_boolean (&ret, FALSE);
3264 case GST_ITERATOR_RESYNC:
3265 gst_iterator_resync (it);
3268 g_assert_not_reached ();
3271 gst_iterator_free (it);
3273 query_ret = g_value_get_boolean (&ret);
3275 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3276 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3277 fold_data.min, fold_data.max);
3279 if (fold_data.min > fold_data.max) {
3280 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3283 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3285 GST_LOG_OBJECT (pad, "latency query failed");
3295 gboolean dispatched;
3299 query_forward_func (GstPad * pad, QueryData * data)
3301 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3302 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3304 data->result |= gst_pad_peer_query (pad, data->query);
3306 data->dispatched = TRUE;
3308 /* stop on first successful reply */
3309 return data->result;
3313 * gst_pad_query_default:
3314 * @pad: a #GstPad to call the default query handler on.
3315 * @parent: (allow-none): the parent of @pad or %NULL
3316 * @query: (transfer none): the #GstQuery to handle.
3318 * Invokes the default query handler for the given pad.
3319 * The query is sent to all pads internally linked to @pad. Note that
3320 * if there are many possible sink pads that are internally linked to
3321 * @pad, only one will be sent the query.
3322 * Multi-sinkpad elements should implement custom query handlers.
3324 * Returns: %TRUE if the query was performed successfully.
3327 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3329 gboolean forward, ret = FALSE;
3331 switch (GST_QUERY_TYPE (query)) {
3332 case GST_QUERY_SCHEDULING:
3333 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3335 case GST_QUERY_ALLOCATION:
3336 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3338 case GST_QUERY_ACCEPT_CAPS:
3339 ret = gst_pad_query_accept_caps_default (pad, query);
3342 case GST_QUERY_CAPS:
3343 ret = gst_pad_query_caps_default (pad, query);
3346 case GST_QUERY_LATENCY:
3347 ret = gst_pad_query_latency_default (pad, query);
3350 case GST_QUERY_POSITION:
3351 case GST_QUERY_SEEKING:
3352 case GST_QUERY_FORMATS:
3353 case GST_QUERY_JITTER:
3354 case GST_QUERY_RATE:
3355 case GST_QUERY_CONVERT:
3361 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3362 query, GST_QUERY_TYPE_NAME (query));
3368 data.dispatched = FALSE;
3369 data.result = FALSE;
3371 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3373 if (data.dispatched) {
3376 /* nothing dispatched, assume drained */
3377 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3387 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3389 GstPad *pad = data->pad;
3390 GstPadProbeInfo *info = data->info;
3391 GstPadProbeType type, flags;
3392 GstPadProbeCallback callback;
3393 GstPadProbeReturn ret;
3394 gpointer original_data;
3396 /* if we have called this callback, do nothing */
3397 if (PROBE_COOKIE (hook) == data->cookie) {
3398 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3399 "hook %lu, cookie %u already called", hook->hook_id,
3400 PROBE_COOKIE (hook));
3404 PROBE_COOKIE (hook) = data->cookie;
3406 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3408 original_data = info->data;
3410 /* one of the scheduling types */
3411 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3414 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3415 /* one of the data types for non-idle probes */
3416 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3417 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3419 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3420 /* one of the data types for non-idle probes */
3421 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3422 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3425 /* Type must have PULL or PUSH probe types */
3426 g_assert_not_reached ();
3429 /* one of the blocking types must match */
3430 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3431 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3433 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3434 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3436 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3437 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3438 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3441 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3442 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3443 PROBE_COOKIE (hook), flags);
3445 data->marshalled = TRUE;
3447 callback = (GstPadProbeCallback) hook->func;
3448 if (callback == NULL)
3451 info->id = hook->hook_id;
3453 GST_OBJECT_UNLOCK (pad);
3455 ret = callback (pad, info, hook->data);
3457 GST_OBJECT_LOCK (pad);
3459 if (original_data != NULL && info->data == NULL) {
3460 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3461 info->type = GST_PAD_PROBE_TYPE_INVALID;
3462 data->dropped = TRUE;
3466 case GST_PAD_PROBE_REMOVE:
3467 /* remove the probe */
3468 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3469 cleanup_hook (pad, hook);
3471 case GST_PAD_PROBE_DROP:
3472 /* need to drop the data, make sure other probes don't get called
3474 GST_DEBUG_OBJECT (pad, "asked to drop item");
3475 info->type = GST_PAD_PROBE_TYPE_INVALID;
3476 data->dropped = TRUE;
3478 case GST_PAD_PROBE_HANDLED:
3479 GST_DEBUG_OBJECT (pad, "probe handled data");
3480 data->handled = TRUE;
3482 case GST_PAD_PROBE_PASS:
3483 /* inform the pad block to let things pass */
3484 GST_DEBUG_OBJECT (pad, "asked to pass item");
3487 case GST_PAD_PROBE_OK:
3488 GST_DEBUG_OBJECT (pad, "probe returned OK");
3491 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3498 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3499 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3500 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3505 /* a probe that does not take or return any data */
3506 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3508 if (G_UNLIKELY (pad->num_probes)) { \
3509 GstFlowReturn pval = defaultval; \
3510 /* pass NULL as the data item */ \
3511 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3512 info.ABI.abi.flow_ret = defaultval; \
3513 ret = do_probe_callbacks (pad, &info, defaultval); \
3514 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3519 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3521 if (G_UNLIKELY (pad->num_probes)) { \
3522 /* pass the data item */ \
3523 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3524 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3525 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3526 /* store the possibly updated data item */ \
3527 data = GST_PAD_PROBE_INFO_DATA (&info); \
3528 /* if something went wrong, exit */ \
3529 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3530 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3531 ret = info.ABI.abi.flow_ret; \
3532 goto handle_label; \
3539 #define PROBE_PUSH(pad,mask,data,label) \
3540 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3541 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3542 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3543 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3544 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3546 static GstFlowReturn
3547 do_pad_idle_probe_wait (GstPad * pad)
3549 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3550 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3551 "waiting idle probe to be removed");
3552 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3553 GST_PAD_BLOCK_WAIT (pad);
3554 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3555 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3557 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3558 return GST_FLOW_FLUSHING;
3563 #define PROBE_TYPE_IS_SERIALIZED(i) \
3566 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3567 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3568 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3570 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3571 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3573 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3574 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3578 static GstFlowReturn
3579 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3580 GstFlowReturn defaultval)
3589 data.handled = FALSE;
3590 data.marshalled = FALSE;
3591 data.dropped = FALSE;
3592 data.cookie = ++pad->priv->probe_cookie;
3595 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3597 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3598 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3603 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3604 "do probes cookie %u", data.cookie);
3605 cookie = pad->priv->probe_list_cookie;
3607 g_hook_list_marshal (&pad->probes, TRUE,
3608 (GHookMarshaller) probe_hook_marshal, &data);
3610 /* if the list changed, call the new callbacks (they will not have their
3611 * cookie set to data.cookie */
3612 if (cookie != pad->priv->probe_list_cookie) {
3613 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3614 "probe list changed, restarting");
3618 /* the first item that dropped will stop the hooks and then we drop here */
3622 /* If one handler took care of it, let the the item pass */
3627 /* if no handler matched and we are blocking, let the item pass */
3628 if (!data.marshalled && is_block)
3631 /* At this point, all handlers returned either OK or PASS. If one handler
3632 * returned PASS, let the item pass */
3637 while (GST_PAD_IS_BLOCKED (pad)) {
3638 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3639 "we are blocked %d times", pad->num_blocked);
3641 /* we might have released the lock */
3642 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3645 /* now we block the streaming thread. It can be unlocked when we
3646 * deactivate the pad (which will also set the FLUSHING flag) or
3647 * when the pad is unblocked. A flushing event will also unblock
3648 * the pad after setting the FLUSHING flag. */
3649 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3650 "Waiting to be unblocked or set flushing");
3651 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3652 GST_PAD_BLOCK_WAIT (pad);
3653 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3654 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3656 /* if the list changed, call the new callbacks (they will not have their
3657 * cookie set to data.cookie */
3658 if (cookie != pad->priv->probe_list_cookie) {
3659 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3660 "probe list changed, restarting");
3664 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3674 GST_DEBUG_OBJECT (pad, "pad is flushing");
3675 return GST_FLOW_FLUSHING;
3679 GST_DEBUG_OBJECT (pad, "data is dropped");
3680 return GST_FLOW_CUSTOM_SUCCESS;
3684 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3685 GST_DEBUG_OBJECT (pad, "data is passed");
3690 GST_DEBUG_OBJECT (pad, "data was handled");
3691 return GST_FLOW_CUSTOM_SUCCESS_1;
3698 * gst_pad_get_offset:
3701 * Get the offset applied to the running time of @pad. @pad has to be a source
3704 * Returns: the offset.
3707 gst_pad_get_offset (GstPad * pad)
3711 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3713 GST_OBJECT_LOCK (pad);
3714 result = pad->offset;
3715 GST_OBJECT_UNLOCK (pad);
3721 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3723 ev->received = FALSE;
3728 * gst_pad_set_offset:
3730 * @offset: the offset
3732 * Set the offset that will be applied to the running time of @pad.
3735 gst_pad_set_offset (GstPad * pad, gint64 offset)
3737 g_return_if_fail (GST_IS_PAD (pad));
3739 GST_OBJECT_LOCK (pad);
3740 /* if nothing changed, do nothing */
3741 if (pad->offset == offset)
3744 pad->offset = offset;
3745 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3747 /* resend all sticky events with updated offset on next buffer push */
3748 events_foreach (pad, mark_event_not_received, NULL);
3749 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3752 GST_OBJECT_UNLOCK (pad);
3759 /* If TRUE and ret is not OK this means
3760 * that pushing the EOS event failed
3764 /* If called for an event this is
3765 * the event that would be pushed
3766 * next. Don't forward sticky events
3767 * that would come after that */
3771 /* should be called with pad LOCK */
3773 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3775 PushStickyData *data = user_data;
3776 GstEvent *event = ev->event;
3779 GST_DEBUG_OBJECT (pad, "event %s was already received",
3780 GST_EVENT_TYPE_NAME (event));
3784 /* If we're called because of an sticky event, only forward
3785 * events that would come before this new event and the
3787 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3788 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3789 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3790 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3792 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3793 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3796 switch (data->ret) {
3798 ev->received = TRUE;
3799 GST_DEBUG_OBJECT (pad, "event %s marked received",
3800 GST_EVENT_TYPE_NAME (event));
3802 case GST_FLOW_CUSTOM_SUCCESS:
3803 /* we can't assume the event is received when it was dropped */
3804 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3805 GST_EVENT_TYPE_NAME (event));
3806 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3807 data->ret = GST_FLOW_OK;
3809 case GST_FLOW_CUSTOM_SUCCESS_1:
3810 /* event was ignored and should be sent later */
3811 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3812 GST_EVENT_TYPE_NAME (event));
3813 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3814 data->ret = GST_FLOW_OK;
3816 case GST_FLOW_NOT_LINKED:
3817 /* not linked is not a problem, we are sticky so the event will be
3818 * rescheduled to be sent later on re-link, but only for non-EOS events */
3819 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3820 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3821 data->ret = GST_FLOW_OK;
3822 ev->received = TRUE;
3826 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3827 gst_flow_get_name (data->ret));
3828 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3832 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3833 data->was_eos = TRUE;
3835 return data->ret == GST_FLOW_OK;
3838 /* check sticky events and push them when needed. should be called
3840 static inline GstFlowReturn
3841 check_sticky (GstPad * pad, GstEvent * event)
3843 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3845 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3846 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3848 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3849 events_foreach (pad, push_sticky, &data);
3851 /* If there's an EOS event we must push it downstream
3852 * even if sending a previous sticky event failed.
3853 * Otherwise the pipeline might wait forever for EOS.
3855 * Only do this if pushing another event than the EOS
3858 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3859 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3861 if (ev && !ev->received) {
3862 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3863 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3864 /* the event could have been dropped. Because this can only
3865 * happen if the user asked for it, it's not an error */
3866 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3867 data.ret = GST_FLOW_OK;
3877 * @pad: a #GstPad to invoke the default query on.
3878 * @query: (transfer none): the #GstQuery to perform.
3880 * Dispatches a query to a pad. The query should have been allocated by the
3881 * caller via one of the type-specific allocation functions. The element that
3882 * the pad belongs to is responsible for filling the query with an appropriate
3883 * response, which should then be parsed with a type-specific query parsing
3886 * Again, the caller is responsible for both the allocation and deallocation of
3887 * the query structure.
3889 * Please also note that some queries might need a running pipeline to work.
3891 * Returns: %TRUE if the query could be performed.
3894 gst_pad_query (GstPad * pad, GstQuery * query)
3897 gboolean res, serialized;
3898 GstPadQueryFunction func;
3899 GstPadProbeType type;
3902 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3903 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3905 if (GST_PAD_IS_SRC (pad)) {
3906 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3907 goto wrong_direction;
3908 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3909 } else if (GST_PAD_IS_SINK (pad)) {
3910 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3911 goto wrong_direction;
3912 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3914 goto unknown_direction;
3916 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3917 GST_QUERY_TYPE_NAME (query));
3918 GST_TRACER_PAD_QUERY_PRE (pad, query);
3920 serialized = GST_QUERY_IS_SERIALIZED (query);
3921 if (G_UNLIKELY (serialized))
3922 GST_PAD_STREAM_LOCK (pad);
3924 GST_OBJECT_LOCK (pad);
3925 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3926 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3927 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3929 ACQUIRE_PARENT (pad, parent, no_parent);
3930 GST_OBJECT_UNLOCK (pad);
3932 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3935 res = func (pad, parent, query);
3937 RELEASE_PARENT (parent);
3939 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3940 GST_QUERY_TYPE_NAME (query), res);
3941 GST_TRACER_PAD_QUERY_POST (pad, query, res);
3946 GST_OBJECT_LOCK (pad);
3947 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3948 GST_OBJECT_UNLOCK (pad);
3950 if (G_UNLIKELY (serialized))
3951 GST_PAD_STREAM_UNLOCK (pad);
3958 g_warning ("pad %s:%s query %s in wrong direction",
3959 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3964 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3969 GST_DEBUG_OBJECT (pad, "had no parent");
3970 GST_OBJECT_UNLOCK (pad);
3971 if (G_UNLIKELY (serialized))
3972 GST_PAD_STREAM_UNLOCK (pad);
3977 GST_DEBUG_OBJECT (pad, "had no query function");
3978 RELEASE_PARENT (parent);
3979 if (G_UNLIKELY (serialized))
3980 GST_PAD_STREAM_UNLOCK (pad);
3985 GST_DEBUG_OBJECT (pad, "query failed");
3986 if (G_UNLIKELY (serialized))
3987 GST_PAD_STREAM_UNLOCK (pad);
3992 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3993 GST_OBJECT_UNLOCK (pad);
3994 if (G_UNLIKELY (serialized))
3995 GST_PAD_STREAM_UNLOCK (pad);
3997 /* if a probe dropped without handling, we don't sent it further but assume
3998 * that the probe did not answer the query and return FALSE */
3999 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4009 * gst_pad_peer_query:
4010 * @pad: a #GstPad to invoke the peer query on.
4011 * @query: (transfer none): the #GstQuery to perform.
4013 * Performs gst_pad_query() on the peer of @pad.
4015 * The caller is responsible for both the allocation and deallocation of
4016 * the query structure.
4018 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4019 * if @pad has no peer.
4022 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4025 GstPadProbeType type;
4026 gboolean res, serialized;
4029 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4030 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4032 if (GST_PAD_IS_SRC (pad)) {
4033 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4034 goto wrong_direction;
4035 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4036 } else if (GST_PAD_IS_SINK (pad)) {
4037 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4038 goto wrong_direction;
4039 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4041 goto unknown_direction;
4043 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4044 GST_QUERY_TYPE_NAME (query));
4046 serialized = GST_QUERY_IS_SERIALIZED (query);
4048 GST_OBJECT_LOCK (pad);
4049 if (GST_PAD_IS_SRC (pad) && serialized) {
4050 /* all serialized queries on the srcpad trigger push of
4052 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4056 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4057 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4058 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4060 peerpad = GST_PAD_PEER (pad);
4061 if (G_UNLIKELY (peerpad == NULL))
4064 gst_object_ref (peerpad);
4065 GST_OBJECT_UNLOCK (pad);
4067 res = gst_pad_query (peerpad, query);
4069 gst_object_unref (peerpad);
4074 GST_OBJECT_LOCK (pad);
4075 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4076 GST_OBJECT_UNLOCK (pad);
4083 g_warning ("pad %s:%s query %s in wrong direction",
4084 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4089 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4094 GST_WARNING_OBJECT (pad, "could not send sticky events");
4095 GST_OBJECT_UNLOCK (pad);
4100 GST_INFO_OBJECT (pad, "pad has no peer");
4101 GST_OBJECT_UNLOCK (pad);
4106 GST_DEBUG_OBJECT (pad, "query failed");
4111 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4112 GST_OBJECT_UNLOCK (pad);
4114 /* if a probe dropped without handling, we don't sent it further but
4115 * assume that the probe did not answer the query and return FALSE */
4116 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4125 /**********************************************************************
4126 * Data passing functions
4129 /* this is the chain function that does not perform the additional argument
4130 * checking for that little extra speed.
4132 static inline GstFlowReturn
4133 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4137 gboolean handled = FALSE;
4139 GST_PAD_STREAM_LOCK (pad);
4141 GST_OBJECT_LOCK (pad);
4142 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4145 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4148 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4151 #ifdef GST_ENABLE_EXTRA_CHECKS
4152 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4153 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4155 ":%s:<%s:%s> Got data flow before stream-start event",
4156 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4158 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4160 ":%s:<%s:%s> Got data flow before segment event",
4161 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4163 pad->priv->last_cookie = pad->priv->events_cookie;
4167 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4170 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4172 ACQUIRE_PARENT (pad, parent, no_parent);
4173 GST_OBJECT_UNLOCK (pad);
4175 /* NOTE: we read the chainfunc unlocked.
4176 * we cannot hold the lock for the pad so we might send
4177 * the data to the wrong function. This is not really a
4178 * problem since functions are assigned at creation time
4179 * and don't change that often... */
4180 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4181 GstPadChainFunction chainfunc;
4183 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4186 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4187 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4188 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4190 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4192 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4193 "called chainfunction &%s with buffer %p, returned %s",
4194 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4196 GstPadChainListFunction chainlistfunc;
4198 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4201 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4202 "calling chainlistfunction &%s",
4203 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4205 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4207 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4208 "called chainlistfunction &%s, returned %s",
4209 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4212 RELEASE_PARENT (parent);
4214 GST_PAD_STREAM_UNLOCK (pad);
4221 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4222 "chaining, but pad was flushing");
4223 GST_OBJECT_UNLOCK (pad);
4224 GST_PAD_STREAM_UNLOCK (pad);
4225 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4226 return GST_FLOW_FLUSHING;
4230 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4231 GST_OBJECT_UNLOCK (pad);
4232 GST_PAD_STREAM_UNLOCK (pad);
4233 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4234 return GST_FLOW_EOS;
4238 g_critical ("chain on pad %s:%s but it was not in push mode",
4239 GST_DEBUG_PAD_NAME (pad));
4240 GST_OBJECT_UNLOCK (pad);
4241 GST_PAD_STREAM_UNLOCK (pad);
4242 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4243 return GST_FLOW_ERROR;
4250 GST_OBJECT_UNLOCK (pad);
4251 GST_PAD_STREAM_UNLOCK (pad);
4252 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4254 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4257 case GST_FLOW_CUSTOM_SUCCESS:
4258 case GST_FLOW_CUSTOM_SUCCESS_1:
4259 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4263 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4270 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4271 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4272 GST_OBJECT_UNLOCK (pad);
4273 GST_PAD_STREAM_UNLOCK (pad);
4274 return GST_FLOW_FLUSHING;
4278 RELEASE_PARENT (parent);
4279 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4280 g_critical ("chain on pad %s:%s but it has no chainfunction",
4281 GST_DEBUG_PAD_NAME (pad));
4282 GST_PAD_STREAM_UNLOCK (pad);
4283 return GST_FLOW_NOT_SUPPORTED;
4289 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4290 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4293 * Chain a buffer to @pad.
4295 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4297 * If the buffer type is not acceptable for @pad (as negotiated with a
4298 * preceding GST_EVENT_CAPS event), this function returns
4299 * #GST_FLOW_NOT_NEGOTIATED.
4301 * The function proceeds calling the chain function installed on @pad (see
4302 * gst_pad_set_chain_function()) and the return value of that function is
4303 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4306 * In all cases, success or failure, the caller loses its reference to @buffer
4307 * after calling this function.
4309 * Returns: a #GstFlowReturn from the pad.
4314 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4316 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4317 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4318 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4320 return gst_pad_chain_data_unchecked (pad,
4321 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4324 static GstFlowReturn
4325 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4326 GstBufferList * list)
4332 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4334 len = gst_buffer_list_length (list);
4337 for (i = 0; i < len; i++) {
4338 buffer = gst_buffer_list_get (list, i);
4340 gst_pad_chain_data_unchecked (pad,
4341 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4342 gst_buffer_ref (buffer));
4343 if (ret != GST_FLOW_OK)
4346 gst_buffer_list_unref (list);
4352 * gst_pad_chain_list:
4353 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4354 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4357 * Chain a bufferlist to @pad.
4359 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4361 * If @pad was not negotiated properly with a CAPS event, this function
4362 * returns #GST_FLOW_NOT_NEGOTIATED.
4364 * The function proceeds calling the chainlist function installed on @pad (see
4365 * gst_pad_set_chain_list_function()) and the return value of that function is
4366 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4367 * chainlist function.
4369 * In all cases, success or failure, the caller loses its reference to @list
4370 * after calling this function.
4374 * Returns: a #GstFlowReturn from the pad.
4377 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4379 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4380 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4381 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4383 return gst_pad_chain_data_unchecked (pad,
4384 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4387 static GstFlowReturn
4388 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4392 gboolean handled = FALSE;
4394 GST_OBJECT_LOCK (pad);
4395 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4398 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4401 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4404 #ifdef GST_ENABLE_EXTRA_CHECKS
4405 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4406 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4408 ":%s:<%s:%s> Got data flow before stream-start event",
4409 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4411 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4413 ":%s:<%s:%s> Got data flow before segment event",
4414 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4416 pad->priv->last_cookie = pad->priv->events_cookie;
4420 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4423 /* do block probes */
4424 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4427 /* recheck sticky events because the probe might have cause a relink */
4428 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4431 /* do post-blocking probes */
4432 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4434 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4437 /* take ref to peer pad before releasing the lock */
4438 gst_object_ref (peer);
4440 GST_OBJECT_UNLOCK (pad);
4442 ret = gst_pad_chain_data_unchecked (peer, type, data);
4445 gst_object_unref (peer);
4447 GST_OBJECT_LOCK (pad);
4448 pad->ABI.abi.last_flowret = ret;
4450 if (pad->priv->using == 0) {
4451 /* pad is not active anymore, trigger idle callbacks */
4452 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4453 probe_stopped, ret);
4455 GST_OBJECT_UNLOCK (pad);
4459 /* ERROR recovery here */
4463 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4464 "pushing, but pad was flushing");
4465 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4466 GST_OBJECT_UNLOCK (pad);
4467 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4468 return GST_FLOW_FLUSHING;
4472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4473 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4474 GST_OBJECT_UNLOCK (pad);
4475 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4476 return GST_FLOW_EOS;
4480 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4481 GST_DEBUG_PAD_NAME (pad));
4482 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4483 GST_OBJECT_UNLOCK (pad);
4484 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4485 return GST_FLOW_ERROR;
4489 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4490 "error pushing events, return %s", gst_flow_get_name (ret));
4491 pad->ABI.abi.last_flowret = ret;
4492 GST_OBJECT_UNLOCK (pad);
4493 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4501 GST_OBJECT_UNLOCK (pad);
4502 if (data != NULL && !handled)
4503 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4506 case GST_FLOW_CUSTOM_SUCCESS:
4507 case GST_FLOW_CUSTOM_SUCCESS_1:
4508 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4512 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4515 pad->ABI.abi.last_flowret = ret;
4520 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4521 "pushing, but it was not linked");
4522 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4523 GST_OBJECT_UNLOCK (pad);
4524 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4525 return GST_FLOW_NOT_LINKED;
4531 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4532 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4535 * Pushes a buffer to the peer of @pad.
4537 * This function will call installed block probes before triggering any
4538 * installed data probes.
4540 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4541 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4544 * In all cases, success or failure, the caller loses its reference to @buffer
4545 * after calling this function.
4547 * Returns: a #GstFlowReturn from the peer pad.
4552 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4556 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4557 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4558 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4560 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4561 res = gst_pad_push_data (pad,
4562 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4563 GST_TRACER_PAD_PUSH_POST (pad, res);
4568 * gst_pad_push_list:
4569 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4570 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4573 * Pushes a buffer list to the peer of @pad.
4575 * This function will call installed block probes before triggering any
4576 * installed data probes.
4578 * The function proceeds calling the chain function on the peer pad and returns
4579 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4580 * be returned. If the peer pad does not have any installed chainlist function
4581 * every group buffer of the list will be merged into a normal #GstBuffer and
4582 * chained via gst_pad_chain().
4584 * In all cases, success or failure, the caller loses its reference to @list
4585 * after calling this function.
4587 * Returns: a #GstFlowReturn from the peer pad.
4592 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4596 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4597 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4598 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4600 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4601 res = gst_pad_push_data (pad,
4602 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4603 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4607 static GstFlowReturn
4608 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4609 GstBuffer ** buffer)
4612 GstPadGetRangeFunction getrangefunc;
4616 GST_PAD_STREAM_LOCK (pad);
4618 GST_OBJECT_LOCK (pad);
4619 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4622 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4625 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4630 /* when one of the probes returns DROPPED, probe_stopped will be called
4631 * and we skip calling the getrange function, res_buf should then contain a
4632 * valid result buffer */
4633 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4634 res_buf, offset, size, probe_stopped);
4636 /* recheck sticky events because the probe might have cause a relink */
4637 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4640 ACQUIRE_PARENT (pad, parent, no_parent);
4641 GST_OBJECT_UNLOCK (pad);
4643 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4646 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4647 "calling getrangefunc %s, offset %"
4648 G_GUINT64_FORMAT ", size %u",
4649 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4651 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4653 RELEASE_PARENT (parent);
4655 GST_OBJECT_LOCK (pad);
4656 if (G_UNLIKELY (ret != GST_FLOW_OK))
4657 goto get_range_failed;
4659 /* can only fire the signal if we have a valid buffer */
4661 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4662 res_buf, offset, size, probe_stopped_unref);
4663 pad->ABI.abi.last_flowret = ret;
4664 GST_OBJECT_UNLOCK (pad);
4666 GST_PAD_STREAM_UNLOCK (pad);
4675 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4676 "getrange, but pad was flushing");
4677 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4678 GST_OBJECT_UNLOCK (pad);
4679 GST_PAD_STREAM_UNLOCK (pad);
4680 return GST_FLOW_FLUSHING;
4684 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4685 GST_DEBUG_PAD_NAME (pad));
4686 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4687 GST_OBJECT_UNLOCK (pad);
4688 GST_PAD_STREAM_UNLOCK (pad);
4689 return GST_FLOW_ERROR;
4693 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4694 pad->ABI.abi.last_flowret = ret;
4695 GST_OBJECT_UNLOCK (pad);
4696 GST_PAD_STREAM_UNLOCK (pad);
4701 GST_DEBUG_OBJECT (pad, "no parent");
4702 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4703 GST_OBJECT_UNLOCK (pad);
4704 GST_PAD_STREAM_UNLOCK (pad);
4705 return GST_FLOW_FLUSHING;
4709 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4710 GST_DEBUG_PAD_NAME (pad));
4711 RELEASE_PARENT (parent);
4712 GST_PAD_STREAM_UNLOCK (pad);
4713 return GST_FLOW_NOT_SUPPORTED;
4717 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4718 "probe returned %s", gst_flow_get_name (ret));
4719 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4721 /* the probe filled the buffer and asks us to not call the getrange
4722 * anymore, we continue with the post probes then. */
4723 GST_DEBUG_OBJECT (pad, "handled buffer");
4727 /* no buffer, we are EOS */
4728 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4732 pad->ABI.abi.last_flowret = ret;
4733 GST_OBJECT_UNLOCK (pad);
4734 GST_PAD_STREAM_UNLOCK (pad);
4738 probe_stopped_unref:
4740 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4741 "probe returned %s", gst_flow_get_name (ret));
4742 /* if we drop here, it signals EOS */
4743 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4745 pad->ABI.abi.last_flowret = ret;
4746 GST_OBJECT_UNLOCK (pad);
4747 GST_PAD_STREAM_UNLOCK (pad);
4748 if (*buffer == NULL)
4749 gst_buffer_unref (res_buf);
4754 pad->ABI.abi.last_flowret = ret;
4755 GST_OBJECT_UNLOCK (pad);
4756 GST_PAD_STREAM_UNLOCK (pad);
4757 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4758 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4759 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4765 * gst_pad_get_range:
4766 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4767 * @offset: The start offset of the buffer
4768 * @size: The length of the buffer
4769 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4770 * returns #GST_FLOW_ERROR if %NULL.
4772 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4773 * immediately and @buffer is %NULL.
4775 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4776 * description of a getrange function. If @pad has no getrange function
4777 * installed (see gst_pad_set_getrange_function()) this function returns
4778 * #GST_FLOW_NOT_SUPPORTED.
4780 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4781 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4782 * must be freed with gst_buffer_unref() after usage.
4784 * When @buffer points to a variable that points to a valid #GstBuffer, the
4785 * buffer will be filled with the result data when this function returns
4786 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4787 * @size bytes will be filled in the result buffer and its size will be updated
4790 * Note that less than @size bytes can be returned in @buffer when, for example,
4791 * an EOS condition is near or when @buffer is not large enough to hold @size
4792 * bytes. The caller should check the result buffer size to get the result size.
4794 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4795 * will be unchanged.
4797 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4799 * Returns: a #GstFlowReturn from the pad.
4804 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4805 GstBuffer ** buffer)
4807 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4808 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4809 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4810 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4811 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4813 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4817 * gst_pad_pull_range:
4818 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4819 * @offset: The start offset of the buffer
4820 * @size: The length of the buffer
4821 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4822 * GST_FLOW_ERROR if %NULL.
4824 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4826 * This function will first trigger the pad block signal if it was
4829 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4830 * function returns the result of gst_pad_get_range() on the peer pad.
4831 * See gst_pad_get_range() for a list of return values and for the
4832 * semantics of the arguments of this function.
4834 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4835 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4836 * must be freed with gst_buffer_unref() after usage. When this function
4837 * returns any other result value, @buffer will still point to %NULL.
4839 * When @buffer points to a variable that points to a valid #GstBuffer, the
4840 * buffer will be filled with the result data when this function returns
4841 * #GST_FLOW_OK. When this function returns any other result value,
4842 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4843 * @size bytes will be filled in the result buffer and its size will be updated
4846 * Note that less than @size bytes can be returned in @buffer when, for example,
4847 * an EOS condition is near or when @buffer is not large enough to hold @size
4848 * bytes. The caller should check the result buffer size to get the result size.
4850 * Returns: a #GstFlowReturn from the peer pad.
4855 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4856 GstBuffer ** buffer)
4862 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4863 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4864 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4865 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4866 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4868 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4870 GST_OBJECT_LOCK (pad);
4871 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4874 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4879 /* when one of the probes returns DROPPED, probe_stopped will be
4880 * called and we skip calling the peer getrange function. *buffer should then
4881 * contain a valid buffer */
4882 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4883 res_buf, offset, size, probe_stopped);
4885 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4888 gst_object_ref (peer);
4890 GST_OBJECT_UNLOCK (pad);
4892 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4894 gst_object_unref (peer);
4896 GST_OBJECT_LOCK (pad);
4898 pad->ABI.abi.last_flowret = ret;
4899 if (pad->priv->using == 0) {
4900 /* pad is not active anymore, trigger idle callbacks */
4901 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4902 probe_stopped_unref, ret);
4905 if (G_UNLIKELY (ret != GST_FLOW_OK))
4906 goto pull_range_failed;
4909 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4910 res_buf, offset, size, probe_stopped_unref);
4912 GST_OBJECT_UNLOCK (pad);
4916 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4919 /* ERROR recovery here */
4922 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4923 "pullrange, but pad was flushing");
4924 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4925 GST_OBJECT_UNLOCK (pad);
4926 ret = GST_FLOW_FLUSHING;
4931 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4932 GST_DEBUG_PAD_NAME (pad));
4933 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4934 GST_OBJECT_UNLOCK (pad);
4935 ret = GST_FLOW_ERROR;
4940 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4941 gst_flow_get_name (ret));
4942 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4944 /* the probe filled the buffer and asks us to not forward to the peer
4945 * anymore, we continue with the post probes then */
4946 GST_DEBUG_OBJECT (pad, "handled buffer");
4950 /* no buffer, we are EOS then */
4951 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4955 pad->ABI.abi.last_flowret = ret;
4956 GST_OBJECT_UNLOCK (pad);
4961 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4962 "pulling range, but it was not linked");
4963 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4964 GST_OBJECT_UNLOCK (pad);
4965 ret = GST_FLOW_NOT_LINKED;
4970 pad->ABI.abi.last_flowret = ret;
4971 GST_OBJECT_UNLOCK (pad);
4972 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4973 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4974 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4977 probe_stopped_unref:
4979 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4980 "post probe returned %s", gst_flow_get_name (ret));
4982 /* if we drop here, it signals EOS */
4983 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4986 pad->ABI.abi.last_flowret = ret;
4987 GST_OBJECT_UNLOCK (pad);
4989 if (*buffer == NULL)
4990 gst_buffer_unref (res_buf);
4994 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
4998 /* must be called with pad object lock */
4999 static GstFlowReturn
5000 store_sticky_event (GstPad * pad, GstEvent * event)
5005 gboolean res = FALSE;
5006 const gchar *name = NULL;
5007 gboolean insert = TRUE;
5009 type = GST_EVENT_TYPE (event);
5011 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5012 * otherwise they can be dropped and nothing would ever resend them.
5013 * Only do that for activated pads though, everything else is a bug!
5015 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5016 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5017 || type == GST_EVENT_EOS))))
5020 /* Unset the EOS flag when received STREAM_START event, so pad can
5021 * store sticky event and then push it later */
5022 if (type == GST_EVENT_STREAM_START) {
5023 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5024 remove_event_by_type (pad, GST_EVENT_EOS);
5025 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5028 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5031 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5032 name = gst_structure_get_name (gst_event_get_structure (event));
5034 events = pad->priv->events;
5037 for (i = 0; i < len; i++) {
5038 PadEvent *ev = &g_array_index (events, PadEvent, i);
5040 if (ev->event == NULL)
5043 if (type == GST_EVENT_TYPE (ev->event)) {
5044 /* matching types, check matching name if needed */
5045 if (name && !gst_event_has_name (ev->event, name))
5049 if ((res = gst_event_replace (&ev->event, event)))
5050 ev->received = FALSE;
5056 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5057 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5058 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5059 * storing the sticky ordered we can check that this is respected. */
5060 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5061 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5063 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5064 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5065 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5066 gst_event_type_get_name (type));
5072 ev.event = gst_event_ref (event);
5073 ev.received = FALSE;
5074 g_array_insert_val (events, i, ev);
5079 pad->priv->events_cookie++;
5080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5082 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5084 switch (GST_EVENT_TYPE (event)) {
5085 case GST_EVENT_CAPS:
5086 GST_OBJECT_UNLOCK (pad);
5088 GST_DEBUG_OBJECT (pad, "notify caps");
5089 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5091 GST_OBJECT_LOCK (pad);
5097 if (type == GST_EVENT_EOS) {
5098 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5099 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5102 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5107 GST_DEBUG_OBJECT (pad, "pad is flushing");
5108 return GST_FLOW_FLUSHING;
5112 GST_DEBUG_OBJECT (pad, "pad is EOS");
5113 return GST_FLOW_EOS;
5118 * gst_pad_store_sticky_event:
5120 * @event: a #GstEvent
5122 * Store the sticky @event on @pad
5124 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5125 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5130 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5134 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5135 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5137 GST_OBJECT_LOCK (pad);
5138 ret = store_sticky_event (pad, event);
5139 GST_OBJECT_UNLOCK (pad);
5145 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5147 PushStickyData *data = user_data;
5149 /* Forward all sticky events before our current one that are pending */
5150 if (ev->event != data->event
5151 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5152 return push_sticky (pad, ev, data);
5157 /* should be called with pad LOCK */
5158 static GstFlowReturn
5159 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5160 GstPadProbeType type)
5164 GstEventType event_type;
5166 /* pass the adjusted event on. We need to do this even if
5167 * there is no peer pad because of the probes. */
5168 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5170 /* Two checks to be made:
5171 * . (un)set the FLUSHING flag for flushing events,
5172 * . handle pad blocking */
5173 event_type = GST_EVENT_TYPE (event);
5174 switch (event_type) {
5175 case GST_EVENT_FLUSH_START:
5176 GST_PAD_SET_FLUSHING (pad);
5178 GST_PAD_BLOCK_BROADCAST (pad);
5179 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5181 case GST_EVENT_FLUSH_STOP:
5182 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5185 GST_PAD_UNSET_FLUSHING (pad);
5187 /* Remove sticky EOS events */
5188 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5189 remove_event_by_type (pad, GST_EVENT_EOS);
5190 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5191 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5192 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5194 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5198 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5201 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5202 * checked already or this is called as part of pushing sticky events,
5203 * in which case we still want to forward the EOS event downstream.
5206 switch (GST_EVENT_TYPE (event)) {
5207 case GST_EVENT_RECONFIGURE:
5208 if (GST_PAD_IS_SINK (pad))
5209 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5214 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5215 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5220 /* send probes after modifying the events above */
5221 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5223 /* recheck sticky events because the probe might have cause a relink */
5224 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5225 && (GST_EVENT_IS_SERIALIZED (event)
5226 || GST_EVENT_IS_STICKY (event))) {
5227 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5228 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5230 /* Push all sticky events before our current one
5231 * that have changed */
5232 events_foreach (pad, sticky_changed, &data);
5235 /* now check the peer pad */
5236 peerpad = GST_PAD_PEER (pad);
5237 if (peerpad == NULL)
5240 gst_object_ref (peerpad);
5242 GST_OBJECT_UNLOCK (pad);
5244 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5245 event, gst_event_type_get_name (event_type), peerpad);
5247 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5249 /* Note: we gave away ownership of the event at this point but we can still
5250 * print the old pointer */
5251 GST_LOG_OBJECT (pad,
5252 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5253 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5255 gst_object_unref (peerpad);
5257 GST_OBJECT_LOCK (pad);
5259 if (pad->priv->using == 0) {
5260 /* pad is not active anymore, trigger idle callbacks */
5261 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5262 idle_probe_stopped, ret);
5266 /* ERROR handling */
5269 GST_DEBUG_OBJECT (pad, "We're flushing");
5270 gst_event_unref (event);
5271 return GST_FLOW_FLUSHING;
5275 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5276 gst_event_unref (event);
5277 return GST_FLOW_FLUSHING;
5281 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5282 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5283 gst_event_unref (event);
5286 case GST_FLOW_CUSTOM_SUCCESS_1:
5287 GST_DEBUG_OBJECT (pad, "handled event");
5289 case GST_FLOW_CUSTOM_SUCCESS:
5290 GST_DEBUG_OBJECT (pad, "dropped event");
5293 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5300 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5301 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5302 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5303 gst_event_unref (event);
5305 /* unlinked pads should not influence latency configuration */
5306 if (event_type == GST_EVENT_LATENCY)
5309 return GST_FLOW_NOT_LINKED;
5313 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5319 * gst_pad_push_event:
5320 * @pad: a #GstPad to push the event to.
5321 * @event: (transfer full): the #GstEvent to send to the pad.
5323 * Sends the event to the peer of the given pad. This function is
5324 * mainly used by elements to send events to their peer
5327 * This function takes ownership of the provided event so you should
5328 * gst_event_ref() it if you want to reuse the event after this call.
5330 * Returns: %TRUE if the event was handled.
5335 gst_pad_push_event (GstPad * pad, GstEvent * event)
5337 gboolean res = FALSE;
5338 GstPadProbeType type;
5339 gboolean sticky, serialized;
5341 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5342 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5344 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5346 if (GST_PAD_IS_SRC (pad)) {
5347 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5348 goto wrong_direction;
5349 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5350 } else if (GST_PAD_IS_SINK (pad)) {
5351 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5352 goto wrong_direction;
5353 /* events pushed on sinkpad never are sticky */
5354 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5356 goto unknown_direction;
5358 GST_OBJECT_LOCK (pad);
5359 sticky = GST_EVENT_IS_STICKY (event);
5360 serialized = GST_EVENT_IS_SERIALIZED (event);
5363 /* srcpad sticky events are stored immediately, the received flag is set
5364 * to FALSE and will be set to TRUE when we can successfully push the
5365 * event to the peer pad */
5366 switch (store_sticky_event (pad, event)) {
5367 case GST_FLOW_FLUSHING:
5375 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5376 /* all serialized or sticky events on the srcpad trigger push of
5378 res = (check_sticky (pad, event) == GST_FLOW_OK);
5383 /* other events are pushed right away */
5384 ret = gst_pad_push_event_unchecked (pad, event, type);
5385 /* dropped events by a probe are not an error */
5386 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5387 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5389 /* Errors in sticky event pushing are no problem and ignored here
5390 * as they will cause more meaningful errors during data flow.
5391 * For EOS events, that are not followed by data flow, we still
5392 * return FALSE here though.
5394 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5396 gst_event_unref (event);
5398 GST_OBJECT_UNLOCK (pad);
5400 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5403 /* ERROR handling */
5406 g_warning ("pad %s:%s pushing %s event in wrong direction",
5407 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5408 gst_event_unref (event);
5413 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5414 gst_event_unref (event);
5419 GST_DEBUG_OBJECT (pad, "We're flushing");
5420 GST_OBJECT_UNLOCK (pad);
5421 gst_event_unref (event);
5426 GST_DEBUG_OBJECT (pad, "We're EOS");
5427 GST_OBJECT_UNLOCK (pad);
5428 gst_event_unref (event);
5432 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5436 /* Check if we can call the event function with the given event */
5437 static GstFlowReturn
5438 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5442 switch (GST_EVENT_TYPE (event)) {
5443 case GST_EVENT_CAPS:
5445 /* backwards compatibility mode for caps */
5446 gst_event_parse_caps (event, &caps);
5448 if (!gst_pad_query_accept_caps (pad, caps))
5460 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5461 "caps %" GST_PTR_FORMAT " not accepted", caps);
5462 return GST_FLOW_NOT_NEGOTIATED;
5466 static GstFlowReturn
5467 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5468 GstPadProbeType type)
5471 GstEventType event_type;
5472 gboolean serialized, need_unlock = FALSE, sticky;
5473 GstPadEventFunction eventfunc;
5474 GstPadEventFullFunction eventfullfunc = NULL;
5477 GST_OBJECT_LOCK (pad);
5479 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5481 if (GST_PAD_IS_SINK (pad))
5482 serialized = GST_EVENT_IS_SERIALIZED (event);
5485 sticky = GST_EVENT_IS_STICKY (event);
5486 event_type = GST_EVENT_TYPE (event);
5487 switch (event_type) {
5488 case GST_EVENT_FLUSH_START:
5489 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5490 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5492 /* can't even accept a flush begin event when flushing */
5493 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5496 GST_PAD_SET_FLUSHING (pad);
5497 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5498 GST_PAD_BLOCK_BROADCAST (pad);
5499 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5501 case GST_EVENT_FLUSH_STOP:
5502 /* we can't accept flush-stop on inactive pads else the flushing flag
5503 * would be cleared and it would look like the pad can accept data.
5504 * Also, some elements restart a streaming thread in flush-stop which we
5505 * can't allow on inactive pads */
5506 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5509 GST_PAD_UNSET_FLUSHING (pad);
5510 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5511 /* Remove pending EOS events */
5512 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5513 remove_event_by_type (pad, GST_EVENT_EOS);
5514 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5515 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5516 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5518 GST_OBJECT_UNLOCK (pad);
5519 /* grab stream lock */
5520 GST_PAD_STREAM_LOCK (pad);
5522 GST_OBJECT_LOCK (pad);
5523 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5526 case GST_EVENT_RECONFIGURE:
5527 if (GST_PAD_IS_SRC (pad))
5528 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5530 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5531 "have event type %" GST_PTR_FORMAT, event);
5533 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5536 switch (event_type) {
5537 case GST_EVENT_STREAM_START:
5538 /* Remove sticky EOS events */
5539 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5540 remove_event_by_type (pad, GST_EVENT_EOS);
5541 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5548 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5551 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5552 GST_OBJECT_UNLOCK (pad);
5553 GST_PAD_STREAM_LOCK (pad);
5555 GST_OBJECT_LOCK (pad);
5556 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5559 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5565 /* now do the probe */
5567 type | GST_PAD_PROBE_TYPE_PUSH |
5568 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5570 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5572 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5573 eventfunc = GST_PAD_EVENTFUNC (pad);
5574 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5577 ACQUIRE_PARENT (pad, parent, no_parent);
5578 GST_OBJECT_UNLOCK (pad);
5580 ret = pre_eventfunc_check (pad, event);
5581 if (G_UNLIKELY (ret != GST_FLOW_OK))
5582 goto precheck_failed;
5585 gst_event_ref (event);
5587 if (eventfullfunc) {
5588 ret = eventfullfunc (pad, parent, event);
5589 } else if (eventfunc (pad, parent, event)) {
5592 /* something went wrong */
5593 switch (event_type) {
5594 case GST_EVENT_CAPS:
5595 ret = GST_FLOW_NOT_NEGOTIATED;
5598 ret = GST_FLOW_ERROR;
5602 RELEASE_PARENT (parent);
5604 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5607 if (ret == GST_FLOW_OK) {
5608 GST_OBJECT_LOCK (pad);
5609 /* after the event function accepted the event, we can store the sticky
5610 * event on the pad */
5611 switch (store_sticky_event (pad, event)) {
5612 case GST_FLOW_FLUSHING:
5619 GST_OBJECT_UNLOCK (pad);
5621 gst_event_unref (event);
5625 GST_PAD_STREAM_UNLOCK (pad);
5629 /* ERROR handling */
5632 GST_OBJECT_UNLOCK (pad);
5634 GST_PAD_STREAM_UNLOCK (pad);
5635 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5636 "Received event on flushing pad. Discarding");
5637 gst_event_unref (event);
5638 return GST_FLOW_FLUSHING;
5642 GST_OBJECT_UNLOCK (pad);
5644 GST_PAD_STREAM_UNLOCK (pad);
5645 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5646 "Received flush-stop on inactive pad. Discarding");
5647 gst_event_unref (event);
5648 return GST_FLOW_FLUSHING;
5652 GST_OBJECT_UNLOCK (pad);
5654 GST_PAD_STREAM_UNLOCK (pad);
5655 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5656 "Received event on EOS pad. Discarding");
5657 gst_event_unref (event);
5658 return GST_FLOW_EOS;
5662 GST_OBJECT_UNLOCK (pad);
5664 GST_PAD_STREAM_UNLOCK (pad);
5665 /* Only unref if unhandled */
5666 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5667 gst_event_unref (event);
5670 case GST_FLOW_CUSTOM_SUCCESS_1:
5671 case GST_FLOW_CUSTOM_SUCCESS:
5672 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5676 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5683 g_warning ("pad %s:%s has no event handler, file a bug.",
5684 GST_DEBUG_PAD_NAME (pad));
5685 GST_OBJECT_UNLOCK (pad);
5687 GST_PAD_STREAM_UNLOCK (pad);
5688 gst_event_unref (event);
5689 return GST_FLOW_NOT_SUPPORTED;
5693 GST_DEBUG_OBJECT (pad, "no parent");
5694 GST_OBJECT_UNLOCK (pad);
5696 GST_PAD_STREAM_UNLOCK (pad);
5697 gst_event_unref (event);
5698 return GST_FLOW_FLUSHING;
5702 GST_DEBUG_OBJECT (pad, "pre event check failed");
5703 RELEASE_PARENT (parent);
5705 GST_PAD_STREAM_UNLOCK (pad);
5706 gst_event_unref (event);
5712 * gst_pad_send_event:
5713 * @pad: a #GstPad to send the event to.
5714 * @event: (transfer full): the #GstEvent to send to the pad.
5716 * Sends the event to the pad. This function can be used
5717 * by applications to send events in the pipeline.
5719 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5720 * sink pad, @event should be a downstream event. For example, you would not
5721 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5722 * Furthermore, some downstream events have to be serialized with data flow,
5723 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5724 * the event needs to be serialized with data flow, this function will take the
5725 * pad's stream lock while calling its event function.
5727 * To find out whether an event type is upstream, downstream, or downstream and
5728 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5729 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5730 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5731 * plugin doesn't need to bother itself with this information; the core handles
5732 * all necessary locks and checks.
5734 * This function takes ownership of the provided event so you should
5735 * gst_event_ref() it if you want to reuse the event after this call.
5737 * Returns: %TRUE if the event was handled.
5740 gst_pad_send_event (GstPad * pad, GstEvent * event)
5743 GstPadProbeType type;
5745 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5746 g_return_val_if_fail (event != NULL, FALSE);
5748 if (GST_PAD_IS_SINK (pad)) {
5749 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5750 goto wrong_direction;
5751 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5752 } else if (GST_PAD_IS_SRC (pad)) {
5753 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5754 goto wrong_direction;
5755 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5757 goto unknown_direction;
5759 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5766 /* ERROR handling */
5769 g_warning ("pad %s:%s sending %s event in wrong direction",
5770 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5771 gst_event_unref (event);
5776 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5777 gst_event_unref (event);
5783 * gst_pad_set_element_private:
5784 * @pad: the #GstPad to set the private data of.
5785 * @priv: The private data to attach to the pad.
5787 * Set the given private data gpointer on the pad.
5788 * This function can only be used by the element that owns the pad.
5789 * No locking is performed in this function.
5792 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5794 pad->element_private = priv;
5798 * gst_pad_get_element_private:
5799 * @pad: the #GstPad to get the private data of.
5801 * Gets the private data of a pad.
5802 * No locking is performed in this function.
5804 * Returns: (transfer none): a #gpointer to the private data.
5807 gst_pad_get_element_private (GstPad * pad)
5809 return pad->element_private;
5813 * gst_pad_get_sticky_event:
5814 * @pad: the #GstPad to get the event from.
5815 * @event_type: the #GstEventType that should be retrieved.
5816 * @idx: the index of the event
5818 * Returns a new reference of the sticky event of type @event_type
5821 * Returns: (transfer full) (nullable): a #GstEvent of type
5822 * @event_type or %NULL when no event of @event_type was on
5823 * @pad. Unref after usage.
5826 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5828 GstEvent *event = NULL;
5831 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5832 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5834 GST_OBJECT_LOCK (pad);
5835 ev = find_event_by_type (pad, event_type, idx);
5836 if (ev && (event = ev->event))
5837 gst_event_ref (event);
5838 GST_OBJECT_UNLOCK (pad);
5845 GstPadStickyEventsForeachFunction func;
5850 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5852 ForeachDispatch *data = user_data;
5853 gboolean ret = TRUE;
5856 GST_OBJECT_UNLOCK (pad);
5858 ret = data->func (pad, &ev->event, data->user_data);
5860 GST_OBJECT_LOCK (pad);
5867 * gst_pad_sticky_events_foreach:
5868 * @pad: the #GstPad that should be used for iteration.
5869 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5870 * should be called for every event.
5871 * @user_data: (closure): the optional user data.
5873 * Iterates all sticky events on @pad and calls @foreach_func for every
5874 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5877 gst_pad_sticky_events_foreach (GstPad * pad,
5878 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5880 ForeachDispatch data;
5882 g_return_if_fail (GST_IS_PAD (pad));
5883 g_return_if_fail (foreach_func != NULL);
5885 data.func = foreach_func;
5886 data.user_data = user_data;
5888 GST_OBJECT_LOCK (pad);
5889 events_foreach (pad, foreach_dispatch_function, &data);
5890 GST_OBJECT_UNLOCK (pad);
5894 do_stream_status (GstPad * pad, GstStreamStatusType type,
5895 GThread * thread, GstTask * task)
5899 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5901 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5902 if (GST_IS_ELEMENT (parent)) {
5903 GstMessage *message;
5904 GValue value = { 0 };
5906 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5907 gchar *tname, *ename, *pname;
5909 /* create a good task name */
5910 ename = gst_element_get_name (parent);
5911 pname = gst_pad_get_name (pad);
5912 tname = g_strdup_printf ("%s:%s", ename, pname);
5916 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5920 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5923 g_value_init (&value, GST_TYPE_TASK);
5924 g_value_set_object (&value, task);
5925 gst_message_set_stream_status_object (message, &value);
5926 g_value_unset (&value);
5928 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5929 gst_element_post_message (parent, message);
5931 gst_object_unref (parent);
5936 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5938 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5943 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5945 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5950 * gst_pad_start_task:
5951 * @pad: the #GstPad to start the task of
5952 * @func: the task function to call
5953 * @user_data: user data passed to the task function
5954 * @notify: called when @user_data is no longer referenced
5956 * Starts a task that repeatedly calls @func with @user_data. This function
5957 * is mostly used in pad activation functions to start the dataflow.
5958 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5959 * before @func is called.
5961 * Returns: a %TRUE if the task could be started.
5964 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5965 GDestroyNotify notify)
5970 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5971 g_return_val_if_fail (func != NULL, FALSE);
5973 GST_DEBUG_OBJECT (pad, "start task");
5975 GST_OBJECT_LOCK (pad);
5976 task = GST_PAD_TASK (pad);
5978 task = gst_task_new (func, user_data, notify);
5979 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5980 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5981 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5982 GST_INFO_OBJECT (pad, "created task %p", task);
5983 GST_PAD_TASK (pad) = task;
5984 gst_object_ref (task);
5985 /* release lock to post the message */
5986 GST_OBJECT_UNLOCK (pad);
5988 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5990 gst_object_unref (task);
5992 GST_OBJECT_LOCK (pad);
5993 /* nobody else is supposed to have changed the pad now */
5994 if (GST_PAD_TASK (pad) != task)
5995 goto concurrent_stop;
5997 res = gst_task_set_state (task, GST_TASK_STARTED);
5998 GST_OBJECT_UNLOCK (pad);
6005 GST_OBJECT_UNLOCK (pad);
6011 * gst_pad_pause_task:
6012 * @pad: the #GstPad to pause the task of
6014 * Pause the task of @pad. This function will also wait until the
6015 * function executed by the task is finished if this function is not
6016 * called from the task function.
6018 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6022 gst_pad_pause_task (GstPad * pad)
6027 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6029 GST_DEBUG_OBJECT (pad, "pause task");
6031 GST_OBJECT_LOCK (pad);
6032 task = GST_PAD_TASK (pad);
6035 res = gst_task_set_state (task, GST_TASK_PAUSED);
6036 GST_OBJECT_UNLOCK (pad);
6038 /* wait for task function to finish, this lock is recursive so it does nothing
6039 * when the pause is called from the task itself */
6040 GST_PAD_STREAM_LOCK (pad);
6041 GST_PAD_STREAM_UNLOCK (pad);
6047 GST_DEBUG_OBJECT (pad, "pad has no task");
6048 GST_OBJECT_UNLOCK (pad);
6054 * gst_pad_stop_task:
6055 * @pad: the #GstPad to stop the task of
6057 * Stop the task of @pad. This function will also make sure that the
6058 * function executed by the task will effectively stop if not called
6059 * from the GstTaskFunction.
6061 * This function will deadlock if called from the GstTaskFunction of
6062 * the task. Use gst_task_pause() instead.
6064 * Regardless of whether the pad has a task, the stream lock is acquired and
6065 * released so as to ensure that streaming through this pad has finished.
6067 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6070 gst_pad_stop_task (GstPad * pad)
6075 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6077 GST_DEBUG_OBJECT (pad, "stop task");
6079 GST_OBJECT_LOCK (pad);
6080 task = GST_PAD_TASK (pad);
6083 GST_PAD_TASK (pad) = NULL;
6084 res = gst_task_set_state (task, GST_TASK_STOPPED);
6085 GST_OBJECT_UNLOCK (pad);
6087 GST_PAD_STREAM_LOCK (pad);
6088 GST_PAD_STREAM_UNLOCK (pad);
6090 if (!gst_task_join (task))
6093 gst_object_unref (task);
6099 GST_DEBUG_OBJECT (pad, "no task");
6100 GST_OBJECT_UNLOCK (pad);
6102 GST_PAD_STREAM_LOCK (pad);
6103 GST_PAD_STREAM_UNLOCK (pad);
6105 /* this is not an error */
6110 /* this is bad, possibly the application tried to join the task from
6111 * the task's thread. We install the task again so that it will be stopped
6112 * again from the right thread next time hopefully. */
6113 GST_OBJECT_LOCK (pad);
6114 GST_DEBUG_OBJECT (pad, "join failed");
6115 /* we can only install this task if there was no other task */
6116 if (GST_PAD_TASK (pad) == NULL)
6117 GST_PAD_TASK (pad) = task;
6118 GST_OBJECT_UNLOCK (pad);
6125 * gst_pad_probe_info_get_event:
6126 * @info: a #GstPadProbeInfo
6128 * Returns: (transfer none): The #GstEvent from the probe
6132 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6134 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6135 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6137 return GST_PAD_PROBE_INFO_EVENT (info);
6142 * gst_pad_probe_info_get_query:
6143 * @info: a #GstPadProbeInfo
6145 * Returns: (transfer none): The #GstQuery from the probe
6149 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6151 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6152 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6154 return GST_PAD_PROBE_INFO_QUERY (info);
6158 * gst_pad_probe_info_get_buffer:
6159 * @info: a #GstPadProbeInfo
6161 * Returns: (transfer none): The #GstBuffer from the probe
6165 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6167 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6169 return GST_PAD_PROBE_INFO_BUFFER (info);
6173 * gst_pad_probe_info_get_buffer_list:
6174 * @info: a #GstPadProbeInfo
6176 * Returns: (transfer none): The #GstBufferList from the probe
6180 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6182 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6184 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6188 * gst_pad_get_last_flow_return:
6191 * Gets the #GstFlowReturn return from the last data passed by this pad.
6196 gst_pad_get_last_flow_return (GstPad * pad)
6200 GST_OBJECT_LOCK (pad);
6201 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6202 GST_OBJECT_UNLOCK (pad);