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_STIME_FORMAT,
647 GST_STIME_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;
1140 old = GST_PAD_MODE_NONE;
1144 case GST_PAD_MODE_PULL:
1146 if (dir == GST_PAD_SINK) {
1147 if ((peer = gst_pad_get_peer (pad))) {
1148 GST_DEBUG_OBJECT (pad, "calling peer");
1149 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1151 gst_object_unref (peer);
1153 /* there is no peer, this is only fatal when we activate. When we
1154 * deactivate, we must assume the application has unlinked the peer and
1155 * will deactivate it eventually. */
1159 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1162 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1163 goto failure; /* Can't activate pull on a src without a
1164 getrange function */
1172 /* Mark pad as needing reconfiguration */
1174 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1175 pre_activate (pad, new);
1177 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1178 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1182 /* can happen for sinks of passthrough elements */
1185 post_activate (pad, new);
1187 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1188 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1193 /* Clear sticky flags on deactivation */
1195 GST_OBJECT_LOCK (pad);
1196 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1197 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1198 GST_OBJECT_UNLOCK (pad);
1206 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1207 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1212 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1213 "failed to %s in switch to %s mode from %s mode",
1214 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1215 gst_pad_mode_get_name (old));
1220 GST_OBJECT_LOCK (peer);
1221 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1222 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1223 GST_OBJECT_UNLOCK (peer);
1224 gst_object_unref (peer);
1229 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1230 "pad in pull mode");
1235 GST_OBJECT_LOCK (pad);
1236 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1237 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1238 GST_PAD_SET_FLUSHING (pad);
1239 GST_PAD_MODE (pad) = old;
1240 GST_OBJECT_UNLOCK (pad);
1246 * gst_pad_activate_mode:
1247 * @pad: the #GstPad to activate or deactivate.
1248 * @mode: the requested activation mode
1249 * @active: whether or not the pad should be active.
1251 * Activates or deactivates the given pad in @mode via dispatching to the
1252 * pad's activatemodefunc. For use from within pad activation functions only.
1254 * If you don't know what this is, you probably don't want to call it.
1256 * Returns: %TRUE if the operation was successful.
1261 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1266 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1268 GST_OBJECT_LOCK (pad);
1269 ACQUIRE_PARENT (pad, parent, no_parent);
1270 GST_OBJECT_UNLOCK (pad);
1272 res = activate_mode_internal (pad, parent, mode, active);
1274 RELEASE_PARENT (parent);
1280 GST_WARNING_OBJECT (pad, "no parent");
1281 GST_OBJECT_UNLOCK (pad);
1287 * gst_pad_is_active:
1288 * @pad: the #GstPad to query
1290 * Query if a pad is active
1292 * Returns: %TRUE if the pad is active.
1297 gst_pad_is_active (GstPad * pad)
1299 gboolean result = FALSE;
1301 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1303 GST_OBJECT_LOCK (pad);
1304 result = GST_PAD_IS_ACTIVE (pad);
1305 GST_OBJECT_UNLOCK (pad);
1311 cleanup_hook (GstPad * pad, GHook * hook)
1313 GstPadProbeType type;
1315 if (!G_HOOK_IS_VALID (hook))
1318 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1320 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1321 /* unblock when we remove the last blocking probe */
1323 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1326 /* Might have new probes now that want to be called */
1327 GST_PAD_BLOCK_BROADCAST (pad);
1329 if (pad->num_blocked == 0) {
1330 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1331 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1334 g_hook_destroy_link (&pad->probes, hook);
1339 * gst_pad_add_probe:
1340 * @pad: the #GstPad to add the probe to
1341 * @mask: the probe mask
1342 * @callback: #GstPadProbeCallback that will be called with notifications of
1344 * @user_data: (closure): user data passed to the callback
1345 * @destroy_data: #GDestroyNotify for user_data
1347 * Be notified of different states of pads. The provided callback is called for
1348 * every state that matches @mask.
1350 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1351 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1352 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1353 * immediately if the pad is already idle while calling gst_pad_add_probe().
1354 * In each of the groups, probes are called in the order in which they were
1357 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1358 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1359 * happen that the probe can be run immediately and if the probe returns
1360 * GST_PAD_PROBE_REMOVE this functions returns 0.
1365 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1366 GstPadProbeCallback callback, gpointer user_data,
1367 GDestroyNotify destroy_data)
1372 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1373 g_return_val_if_fail (mask != 0, 0);
1375 GST_OBJECT_LOCK (pad);
1377 /* make a new probe */
1378 hook = g_hook_alloc (&pad->probes);
1380 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1383 /* when no contraints are given for the types, assume all types are
1385 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1386 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1387 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1388 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1390 /* store our flags and other fields */
1391 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1392 hook->func = callback;
1393 hook->data = user_data;
1394 hook->destroy = destroy_data;
1395 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1398 g_hook_append (&pad->probes, hook);
1400 /* incremenent cookie so that the new hook get's called */
1401 pad->priv->probe_list_cookie++;
1403 /* get the id of the hook, we return this and it can be used to remove the
1405 res = hook->hook_id;
1407 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1409 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1410 /* we have a block probe */
1412 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1413 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1414 "now %d blocking probes", pad->num_blocked);
1416 /* Might have new probes now that want to be called */
1417 GST_PAD_BLOCK_BROADCAST (pad);
1420 /* call the callback if we need to be called for idle callbacks */
1421 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1422 if (pad->priv->using > 0) {
1423 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1424 * flag above, the last thread to leave the push will do the callback. New
1425 * threads going into the push will block. */
1426 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1427 "pad is in use, delay idle callback");
1428 GST_OBJECT_UNLOCK (pad);
1430 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1431 GstPadProbeReturn ret;
1433 /* Keep another ref, the callback could destroy the pad */
1434 gst_object_ref (pad);
1435 pad->priv->idle_running++;
1437 /* the pad is idle now, we can signal the idle callback now */
1438 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1439 "pad is idle, trigger idle callback");
1440 GST_OBJECT_UNLOCK (pad);
1442 ret = callback (pad, &info, user_data);
1444 GST_OBJECT_LOCK (pad);
1446 case GST_PAD_PROBE_REMOVE:
1447 /* remove the probe */
1448 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1449 cleanup_hook (pad, hook);
1452 case GST_PAD_PROBE_DROP:
1453 GST_DEBUG_OBJECT (pad, "asked to drop item");
1455 case GST_PAD_PROBE_PASS:
1456 GST_DEBUG_OBJECT (pad, "asked to pass item");
1458 case GST_PAD_PROBE_OK:
1459 GST_DEBUG_OBJECT (pad, "probe returned OK");
1461 case GST_PAD_PROBE_HANDLED:
1462 GST_DEBUG_OBJECT (pad, "probe handled the data");
1465 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1468 pad->priv->idle_running--;
1469 if (pad->priv->idle_running == 0) {
1470 GST_PAD_BLOCK_BROADCAST (pad);
1472 GST_OBJECT_UNLOCK (pad);
1474 gst_object_unref (pad);
1477 GST_OBJECT_UNLOCK (pad);
1483 * gst_pad_remove_probe:
1484 * @pad: the #GstPad with the probe
1485 * @id: the probe id to remove
1487 * Remove the probe with @id from @pad.
1492 gst_pad_remove_probe (GstPad * pad, gulong id)
1496 g_return_if_fail (GST_IS_PAD (pad));
1498 GST_OBJECT_LOCK (pad);
1500 hook = g_hook_get (&pad->probes, id);
1504 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1506 cleanup_hook (pad, hook);
1507 GST_OBJECT_UNLOCK (pad);
1513 GST_OBJECT_UNLOCK (pad);
1514 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1520 * gst_pad_is_blocked:
1521 * @pad: the #GstPad to query
1523 * Checks if the pad is blocked or not. This function returns the
1524 * last requested state of the pad. It is not certain that the pad
1525 * is actually blocking at this point (see gst_pad_is_blocking()).
1527 * Returns: %TRUE if the pad is blocked.
1532 gst_pad_is_blocked (GstPad * pad)
1534 gboolean result = FALSE;
1536 g_return_val_if_fail (GST_IS_PAD (pad), result);
1538 GST_OBJECT_LOCK (pad);
1539 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1540 GST_OBJECT_UNLOCK (pad);
1546 * gst_pad_is_blocking:
1547 * @pad: the #GstPad to query
1549 * Checks if the pad is blocking or not. This is a guaranteed state
1550 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1552 * Returns: %TRUE if the pad is blocking.
1557 gst_pad_is_blocking (GstPad * pad)
1559 gboolean result = FALSE;
1561 g_return_val_if_fail (GST_IS_PAD (pad), result);
1563 GST_OBJECT_LOCK (pad);
1564 /* the blocking flag is only valid if the pad is not flushing */
1565 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1566 GST_OBJECT_UNLOCK (pad);
1572 * gst_pad_needs_reconfigure:
1573 * @pad: the #GstPad to check
1575 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1576 * if the flag was set.
1578 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1581 gst_pad_needs_reconfigure (GstPad * pad)
1583 gboolean reconfigure;
1585 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1587 GST_OBJECT_LOCK (pad);
1588 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1589 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1590 GST_OBJECT_UNLOCK (pad);
1596 * gst_pad_check_reconfigure:
1597 * @pad: the #GstPad to check
1599 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1600 * if the flag was set.
1602 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1605 gst_pad_check_reconfigure (GstPad * pad)
1607 gboolean reconfigure;
1609 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1611 GST_OBJECT_LOCK (pad);
1612 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1614 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1615 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1617 GST_OBJECT_UNLOCK (pad);
1623 * gst_pad_mark_reconfigure:
1624 * @pad: the #GstPad to mark
1626 * Mark a pad for needing reconfiguration. The next call to
1627 * gst_pad_check_reconfigure() will return %TRUE after this call.
1630 gst_pad_mark_reconfigure (GstPad * pad)
1632 g_return_if_fail (GST_IS_PAD (pad));
1634 GST_OBJECT_LOCK (pad);
1635 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1636 GST_OBJECT_UNLOCK (pad);
1640 * gst_pad_set_activate_function:
1642 * @f: the #GstPadActivateFunction to set.
1644 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1648 * gst_pad_set_activate_function_full:
1650 * @activate: the #GstPadActivateFunction to set.
1651 * @user_data: user_data passed to @notify
1652 * @notify: notify called when @activate will not be used anymore.
1654 * Sets the given activate function for @pad. The activate function will
1655 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1656 * Only makes sense to set on sink pads.
1658 * Call this function if your sink pad can start a pull-based task.
1661 gst_pad_set_activate_function_full (GstPad * pad,
1662 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1664 g_return_if_fail (GST_IS_PAD (pad));
1666 if (pad->activatenotify)
1667 pad->activatenotify (pad->activatedata);
1668 GST_PAD_ACTIVATEFUNC (pad) = activate;
1669 pad->activatedata = user_data;
1670 pad->activatenotify = notify;
1672 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1673 GST_DEBUG_FUNCPTR_NAME (activate));
1677 * gst_pad_set_activatemode_function:
1679 * @f: the #GstPadActivateModeFunction to set.
1681 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1685 * gst_pad_set_activatemode_function_full:
1687 * @activatemode: the #GstPadActivateModeFunction to set.
1688 * @user_data: user_data passed to @notify
1689 * @notify: notify called when @activatemode will not be used anymore.
1691 * Sets the given activate_mode function for the pad. An activate_mode function
1692 * prepares the element for data passing.
1695 gst_pad_set_activatemode_function_full (GstPad * pad,
1696 GstPadActivateModeFunction activatemode, gpointer user_data,
1697 GDestroyNotify notify)
1699 g_return_if_fail (GST_IS_PAD (pad));
1701 if (pad->activatemodenotify)
1702 pad->activatemodenotify (pad->activatemodedata);
1703 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1704 pad->activatemodedata = user_data;
1705 pad->activatemodenotify = notify;
1707 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1708 GST_DEBUG_FUNCPTR_NAME (activatemode));
1712 * gst_pad_set_chain_function:
1713 * @p: a sink #GstPad.
1714 * @f: the #GstPadChainFunction to set.
1716 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1720 * gst_pad_set_chain_function_full:
1721 * @pad: a sink #GstPad.
1722 * @chain: the #GstPadChainFunction to set.
1723 * @user_data: user_data passed to @notify
1724 * @notify: notify called when @chain will not be used anymore.
1726 * Sets the given chain function for the pad. The chain function is called to
1727 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1730 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1731 gpointer user_data, GDestroyNotify notify)
1733 g_return_if_fail (GST_IS_PAD (pad));
1734 g_return_if_fail (GST_PAD_IS_SINK (pad));
1736 if (pad->chainnotify)
1737 pad->chainnotify (pad->chaindata);
1738 GST_PAD_CHAINFUNC (pad) = chain;
1739 pad->chaindata = user_data;
1740 pad->chainnotify = notify;
1742 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1743 GST_DEBUG_FUNCPTR_NAME (chain));
1747 * gst_pad_set_chain_list_function:
1748 * @p: a sink #GstPad.
1749 * @f: the #GstPadChainListFunction to set.
1751 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1755 * gst_pad_set_chain_list_function_full:
1756 * @pad: a sink #GstPad.
1757 * @chainlist: the #GstPadChainListFunction to set.
1758 * @user_data: user_data passed to @notify
1759 * @notify: notify called when @chainlist will not be used anymore.
1761 * Sets the given chain list function for the pad. The chainlist function is
1762 * called to process a #GstBufferList input buffer list. See
1763 * #GstPadChainListFunction for more details.
1766 gst_pad_set_chain_list_function_full (GstPad * pad,
1767 GstPadChainListFunction chainlist, gpointer user_data,
1768 GDestroyNotify notify)
1770 g_return_if_fail (GST_IS_PAD (pad));
1771 g_return_if_fail (GST_PAD_IS_SINK (pad));
1773 if (pad->chainlistnotify)
1774 pad->chainlistnotify (pad->chainlistdata);
1775 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1776 pad->chainlistdata = user_data;
1777 pad->chainlistnotify = notify;
1779 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1780 GST_DEBUG_FUNCPTR_NAME (chainlist));
1784 * gst_pad_set_getrange_function:
1785 * @p: a source #GstPad.
1786 * @f: the #GstPadGetRangeFunction to set.
1788 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1792 * gst_pad_set_getrange_function_full:
1793 * @pad: a source #GstPad.
1794 * @get: the #GstPadGetRangeFunction to set.
1795 * @user_data: user_data passed to @notify
1796 * @notify: notify called when @get will not be used anymore.
1798 * Sets the given getrange function for the pad. The getrange function is
1799 * called to produce a new #GstBuffer to start the processing pipeline. see
1800 * #GstPadGetRangeFunction for a description of the getrange function.
1803 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1804 gpointer user_data, GDestroyNotify notify)
1806 g_return_if_fail (GST_IS_PAD (pad));
1807 g_return_if_fail (GST_PAD_IS_SRC (pad));
1809 if (pad->getrangenotify)
1810 pad->getrangenotify (pad->getrangedata);
1811 GST_PAD_GETRANGEFUNC (pad) = get;
1812 pad->getrangedata = user_data;
1813 pad->getrangenotify = notify;
1815 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1816 GST_DEBUG_FUNCPTR_NAME (get));
1820 * gst_pad_set_event_function:
1821 * @p: a #GstPad of either direction.
1822 * @f: the #GstPadEventFunction to set.
1824 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1828 * gst_pad_set_event_function_full:
1829 * @pad: a #GstPad of either direction.
1830 * @event: the #GstPadEventFunction to set.
1831 * @user_data: user_data passed to @notify
1832 * @notify: notify called when @event will not be used anymore.
1834 * Sets the given event handler for the pad.
1837 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1838 gpointer user_data, GDestroyNotify notify)
1840 g_return_if_fail (GST_IS_PAD (pad));
1842 if (pad->eventnotify)
1843 pad->eventnotify (pad->eventdata);
1844 GST_PAD_EVENTFUNC (pad) = event;
1845 pad->eventdata = user_data;
1846 pad->eventnotify = notify;
1848 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1849 GST_DEBUG_FUNCPTR_NAME (event));
1853 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1857 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1858 if (ret == GST_FLOW_OK)
1864 * gst_pad_set_event_full_function:
1865 * @p: a #GstPad of either direction.
1866 * @f: the #GstPadEventFullFunction to set.
1868 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1872 * gst_pad_set_event_full_function_full:
1873 * @pad: a #GstPad of either direction.
1874 * @event: the #GstPadEventFullFunction to set.
1875 * @user_data: user_data passed to @notify
1876 * @notify: notify called when @event will not be used anymore.
1878 * Sets the given event handler for the pad.
1883 gst_pad_set_event_full_function_full (GstPad * pad,
1884 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1886 g_return_if_fail (GST_IS_PAD (pad));
1888 if (pad->eventnotify)
1889 pad->eventnotify (pad->eventdata);
1890 GST_PAD_EVENTFULLFUNC (pad) = event;
1891 GST_PAD_EVENTFUNC (pad) = event_wrap;
1892 pad->eventdata = user_data;
1893 pad->eventnotify = notify;
1895 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1896 GST_DEBUG_FUNCPTR_NAME (event));
1900 * gst_pad_set_query_function:
1901 * @p: a #GstPad of either direction.
1902 * @f: the #GstPadQueryFunction to set.
1904 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1908 * gst_pad_set_query_function_full:
1909 * @pad: a #GstPad of either direction.
1910 * @query: the #GstPadQueryFunction to set.
1911 * @user_data: user_data passed to @notify
1912 * @notify: notify called when @query will not be used anymore.
1914 * Set the given query function for the pad.
1917 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1918 gpointer user_data, GDestroyNotify notify)
1920 g_return_if_fail (GST_IS_PAD (pad));
1922 if (pad->querynotify)
1923 pad->querynotify (pad->querydata);
1924 GST_PAD_QUERYFUNC (pad) = query;
1925 pad->querydata = user_data;
1926 pad->querynotify = notify;
1928 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1929 GST_DEBUG_FUNCPTR_NAME (query));
1933 * gst_pad_set_iterate_internal_links_function:
1934 * @p: a #GstPad of either direction.
1935 * @f: the #GstPadIterIntLinkFunction to set.
1937 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1938 * for the user_data and notify.
1941 * gst_pad_set_iterate_internal_links_function_full:
1942 * @pad: a #GstPad of either direction.
1943 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1944 * @user_data: user_data passed to @notify
1945 * @notify: notify called when @iterintlink will not be used anymore.
1947 * Sets the given internal link iterator function for the pad.
1950 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1951 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1952 GDestroyNotify notify)
1954 g_return_if_fail (GST_IS_PAD (pad));
1956 if (pad->iterintlinknotify)
1957 pad->iterintlinknotify (pad->iterintlinkdata);
1958 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1959 pad->iterintlinkdata = user_data;
1960 pad->iterintlinknotify = notify;
1962 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1963 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1967 * gst_pad_set_link_function:
1969 * @f: the #GstPadLinkFunction to set.
1971 * Calls gst_pad_set_link_function_full() with %NULL
1972 * for the user_data and notify.
1975 * gst_pad_set_link_function_full:
1977 * @link: the #GstPadLinkFunction to set.
1978 * @user_data: user_data passed to @notify
1979 * @notify: notify called when @link will not be used anymore.
1981 * Sets the given link function for the pad. It will be called when
1982 * the pad is linked with another pad.
1984 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1987 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1988 * cannot be made for some reason.
1990 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1991 * of the peer sink pad, if present.
1994 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1995 gpointer user_data, GDestroyNotify notify)
1997 g_return_if_fail (GST_IS_PAD (pad));
1999 if (pad->linknotify)
2000 pad->linknotify (pad->linkdata);
2001 GST_PAD_LINKFUNC (pad) = link;
2002 pad->linkdata = user_data;
2003 pad->linknotify = notify;
2005 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2006 GST_DEBUG_FUNCPTR_NAME (link));
2010 * gst_pad_set_unlink_function:
2012 * @f: the #GstPadUnlinkFunction to set.
2014 * Calls gst_pad_set_unlink_function_full() with %NULL
2015 * for the user_data and notify.
2018 * gst_pad_set_unlink_function_full:
2020 * @unlink: the #GstPadUnlinkFunction to set.
2021 * @user_data: user_data passed to @notify
2022 * @notify: notify called when @unlink will not be used anymore.
2024 * Sets the given unlink function for the pad. It will be called
2025 * when the pad is unlinked.
2028 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2029 gpointer user_data, GDestroyNotify notify)
2031 g_return_if_fail (GST_IS_PAD (pad));
2033 if (pad->unlinknotify)
2034 pad->unlinknotify (pad->unlinkdata);
2035 GST_PAD_UNLINKFUNC (pad) = unlink;
2036 pad->unlinkdata = user_data;
2037 pad->unlinknotify = notify;
2039 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2040 GST_DEBUG_FUNCPTR_NAME (unlink));
2045 * @srcpad: the source #GstPad to unlink.
2046 * @sinkpad: the sink #GstPad to unlink.
2048 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2049 * signal on both pads.
2051 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2052 * the pads were not linked together.
2057 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2059 gboolean result = FALSE;
2060 GstElement *parent = NULL;
2062 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2063 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2064 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2065 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2067 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2069 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2070 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2071 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2073 /* We need to notify the parent before taking any pad locks as the bin in
2074 * question might be waiting for a lock on the pad while holding its lock
2075 * that our message will try to take. */
2076 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2077 if (GST_IS_ELEMENT (parent)) {
2078 gst_element_post_message (parent,
2079 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2080 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2082 gst_object_unref (parent);
2087 GST_OBJECT_LOCK (srcpad);
2088 GST_OBJECT_LOCK (sinkpad);
2090 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2091 goto not_linked_together;
2093 if (GST_PAD_UNLINKFUNC (srcpad)) {
2094 GstObject *tmpparent;
2096 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2098 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2099 RELEASE_PARENT (tmpparent);
2102 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2103 GstObject *tmpparent;
2105 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2107 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2108 RELEASE_PARENT (tmpparent);
2112 /* first clear peers */
2113 GST_PAD_PEER (srcpad) = NULL;
2114 GST_PAD_PEER (sinkpad) = NULL;
2116 GST_OBJECT_UNLOCK (sinkpad);
2117 GST_OBJECT_UNLOCK (srcpad);
2119 /* fire off a signal to each of the pads telling them
2120 * that they've been unlinked */
2121 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2122 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2124 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2125 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2130 if (parent != NULL) {
2131 gst_element_post_message (parent,
2132 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2133 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2134 gst_object_unref (parent);
2136 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2140 not_linked_together:
2142 /* we do not emit a warning in this case because unlinking cannot
2143 * be made MT safe.*/
2144 GST_OBJECT_UNLOCK (sinkpad);
2145 GST_OBJECT_UNLOCK (srcpad);
2151 * gst_pad_is_linked:
2152 * @pad: pad to check
2154 * Checks if a @pad is linked to another pad or not.
2156 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2161 gst_pad_is_linked (GstPad * pad)
2165 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2167 GST_OBJECT_LOCK (pad);
2168 result = (GST_PAD_PEER (pad) != NULL);
2169 GST_OBJECT_UNLOCK (pad);
2174 /* get the caps from both pads and see if the intersection
2177 * This function should be called with the pad LOCK on both
2181 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2182 GstPadLinkCheck flags)
2184 GstCaps *srccaps = NULL;
2185 GstCaps *sinkcaps = NULL;
2186 gboolean compatible = FALSE;
2188 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2191 /* Doing the expensive caps checking takes priority over only checking the template caps */
2192 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2193 GST_OBJECT_UNLOCK (sink);
2194 GST_OBJECT_UNLOCK (src);
2196 srccaps = gst_pad_query_caps (src, NULL);
2197 sinkcaps = gst_pad_query_caps (sink, NULL);
2199 GST_OBJECT_LOCK (src);
2200 GST_OBJECT_LOCK (sink);
2202 /* If one of the two pads doesn't have a template, consider the intersection
2204 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2205 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2209 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2211 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2214 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2216 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2219 /* if we have caps on both pads we can check the intersection. If one
2220 * of the caps is %NULL, we return %TRUE. */
2221 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2223 gst_caps_unref (srccaps);
2225 gst_caps_unref (sinkcaps);
2229 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2230 gst_caps_unref (srccaps);
2231 gst_caps_unref (sinkcaps);
2234 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2235 (compatible ? "" : "not "));
2240 /* check if the grandparents of both pads are the same.
2241 * This check is required so that we don't try to link
2242 * pads from elements in different bins without ghostpads.
2244 * The LOCK should be held on both pads
2247 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2249 GstObject *psrc, *psink;
2251 psrc = GST_OBJECT_PARENT (src);
2252 psink = GST_OBJECT_PARENT (sink);
2254 /* if one of the pads has no parent, we allow the link */
2255 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2258 /* only care about parents that are elements */
2259 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2260 goto no_element_parent;
2262 /* if the parents are the same, we have a loop */
2263 if (G_UNLIKELY (psrc == psink))
2266 /* if they both have a parent, we check the grandparents. We can not lock
2267 * the parent because we hold on the child (pad) and the locking order is
2268 * parent >> child. */
2269 psrc = GST_OBJECT_PARENT (psrc);
2270 psink = GST_OBJECT_PARENT (psink);
2272 /* if they have grandparents but they are not the same */
2273 if (G_UNLIKELY (psrc != psink))
2274 goto wrong_grandparents;
2281 GST_CAT_DEBUG (GST_CAT_CAPS,
2282 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2283 GST_PTR_FORMAT, psrc, psink);
2288 GST_CAT_DEBUG (GST_CAT_CAPS,
2289 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2290 GST_PTR_FORMAT, psrc, psink);
2295 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2301 GST_CAT_DEBUG (GST_CAT_CAPS,
2302 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2303 GST_PTR_FORMAT, psrc, psink);
2308 /* FIXME leftover from an attempt at refactoring... */
2309 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2310 * the two pads will be locked in the srcpad, sinkpad order. */
2311 static GstPadLinkReturn
2312 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2314 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2315 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2317 GST_OBJECT_LOCK (srcpad);
2319 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2320 goto src_was_linked;
2322 GST_OBJECT_LOCK (sinkpad);
2324 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2325 goto sink_was_linked;
2327 /* check hierarchy, pads can only be linked if the grandparents
2329 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2330 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2331 goto wrong_hierarchy;
2333 /* check pad caps for non-empty intersection */
2334 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2337 /* FIXME check pad scheduling for non-empty intersection */
2339 return GST_PAD_LINK_OK;
2343 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2344 GST_DEBUG_PAD_NAME (srcpad),
2345 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2346 /* we do not emit a warning in this case because unlinking cannot
2347 * be made MT safe.*/
2348 GST_OBJECT_UNLOCK (srcpad);
2349 return GST_PAD_LINK_WAS_LINKED;
2353 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2354 GST_DEBUG_PAD_NAME (sinkpad),
2355 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2356 /* we do not emit a warning in this case because unlinking cannot
2357 * be made MT safe.*/
2358 GST_OBJECT_UNLOCK (sinkpad);
2359 GST_OBJECT_UNLOCK (srcpad);
2360 return GST_PAD_LINK_WAS_LINKED;
2364 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2365 GST_OBJECT_UNLOCK (sinkpad);
2366 GST_OBJECT_UNLOCK (srcpad);
2367 return GST_PAD_LINK_WRONG_HIERARCHY;
2371 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2372 GST_OBJECT_UNLOCK (sinkpad);
2373 GST_OBJECT_UNLOCK (srcpad);
2374 return GST_PAD_LINK_NOFORMAT;
2380 * @srcpad: the source #GstPad.
2381 * @sinkpad: the sink #GstPad.
2383 * Checks if the source pad and the sink pad are compatible so they can be
2386 * Returns: %TRUE if the pads can be linked.
2389 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2391 GstPadLinkReturn result;
2393 /* generic checks */
2394 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2395 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2397 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2398 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2400 /* gst_pad_link_prepare does everything for us, we only release the locks
2401 * on the pads that it gets us. If this function returns !OK the locks are not
2403 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2404 if (result != GST_PAD_LINK_OK)
2407 GST_OBJECT_UNLOCK (srcpad);
2408 GST_OBJECT_UNLOCK (sinkpad);
2411 return result == GST_PAD_LINK_OK;
2415 * gst_pad_link_full:
2416 * @srcpad: the source #GstPad to link.
2417 * @sinkpad: the sink #GstPad to link.
2418 * @flags: the checks to validate when linking
2420 * Links the source pad and the sink pad.
2422 * This variant of #gst_pad_link provides a more granular control on the
2423 * checks being done when linking. While providing some considerable speedups
2424 * the caller of this method must be aware that wrong usage of those flags
2425 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2426 * for more information.
2430 * Returns: A result code indicating if the connection worked or
2434 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2436 GstPadLinkReturn result;
2438 GstPadLinkFunction srcfunc, sinkfunc;
2440 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2441 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2442 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2443 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2444 GST_PAD_LINK_WRONG_DIRECTION);
2446 /* Notify the parent early. See gst_pad_unlink for details. */
2447 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2448 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2449 gst_element_post_message (parent,
2450 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2451 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2453 gst_object_unref (parent);
2458 /* prepare will also lock the two pads */
2459 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2461 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2462 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2463 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2464 gst_pad_link_get_name (result));
2468 /* must set peers before calling the link function */
2469 GST_PAD_PEER (srcpad) = sinkpad;
2470 GST_PAD_PEER (sinkpad) = srcpad;
2472 /* check events, when something is different, mark pending */
2473 schedule_events (srcpad, sinkpad);
2475 /* get the link functions */
2476 srcfunc = GST_PAD_LINKFUNC (srcpad);
2477 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2479 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2480 /* custom link functions, execute them */
2481 GST_OBJECT_UNLOCK (sinkpad);
2482 GST_OBJECT_UNLOCK (srcpad);
2485 GstObject *tmpparent;
2487 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2488 /* this one will call the peer link function */
2489 result = srcfunc (srcpad, tmpparent, sinkpad);
2490 RELEASE_PARENT (tmpparent);
2491 } else if (sinkfunc) {
2492 GstObject *tmpparent;
2494 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2495 /* if no source link function, we need to call the sink link
2496 * function ourselves. */
2497 result = sinkfunc (sinkpad, tmpparent, srcpad);
2498 RELEASE_PARENT (tmpparent);
2502 GST_OBJECT_LOCK (srcpad);
2503 GST_OBJECT_LOCK (sinkpad);
2505 /* we released the lock, check if the same pads are linked still */
2506 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2507 goto concurrent_link;
2509 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2512 GST_OBJECT_UNLOCK (sinkpad);
2513 GST_OBJECT_UNLOCK (srcpad);
2515 /* fire off a signal to each of the pads telling them
2516 * that they've been linked */
2517 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2518 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2520 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2521 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2523 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2524 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2527 if (G_LIKELY (parent)) {
2528 gst_element_post_message (parent,
2529 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2530 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2531 gst_object_unref (parent);
2539 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2540 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2541 GST_OBJECT_UNLOCK (sinkpad);
2542 GST_OBJECT_UNLOCK (srcpad);
2544 /* The other link operation succeeded first */
2545 result = GST_PAD_LINK_WAS_LINKED;
2550 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2551 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2552 gst_pad_link_get_name (result));
2554 GST_PAD_PEER (srcpad) = NULL;
2555 GST_PAD_PEER (sinkpad) = NULL;
2557 GST_OBJECT_UNLOCK (sinkpad);
2558 GST_OBJECT_UNLOCK (srcpad);
2566 * @srcpad: the source #GstPad to link.
2567 * @sinkpad: the sink #GstPad to link.
2569 * Links the source pad and the sink pad.
2571 * Returns: A result code indicating if the connection worked or
2577 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2579 GstPadLinkReturn ret;
2581 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2582 ret = gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2583 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, ret);
2589 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2591 GstPadTemplate **template_p;
2593 /* this function would need checks if it weren't static */
2595 GST_OBJECT_LOCK (pad);
2596 template_p = &pad->padtemplate;
2597 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2598 GST_OBJECT_UNLOCK (pad);
2601 gst_pad_template_pad_created (templ, pad);
2605 * gst_pad_get_pad_template:
2608 * Gets the template for @pad.
2610 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2611 * this pad was instantiated, or %NULL if this pad has no
2612 * template. Unref after usage.
2615 gst_pad_get_pad_template (GstPad * pad)
2617 GstPadTemplate *templ;
2619 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2621 templ = GST_PAD_PAD_TEMPLATE (pad);
2623 return (templ ? gst_object_ref (templ) : NULL);
2627 * gst_pad_has_current_caps:
2628 * @pad: a #GstPad to check
2630 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2632 * Returns: %TRUE when @pad has caps associated with it.
2635 gst_pad_has_current_caps (GstPad * pad)
2640 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2642 GST_OBJECT_LOCK (pad);
2643 caps = get_pad_caps (pad);
2644 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2645 "check current pad caps %" GST_PTR_FORMAT, caps);
2646 result = (caps != NULL);
2647 GST_OBJECT_UNLOCK (pad);
2653 * gst_pad_get_current_caps:
2654 * @pad: a #GstPad to get the current capabilities of.
2656 * Gets the capabilities currently configured on @pad with the last
2657 * #GST_EVENT_CAPS event.
2659 * Returns: (transfer full) (nullable): the current caps of the pad with
2660 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2663 gst_pad_get_current_caps (GstPad * pad)
2667 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2669 GST_OBJECT_LOCK (pad);
2670 if ((result = get_pad_caps (pad)))
2671 gst_caps_ref (result);
2672 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2673 "get current pad caps %" GST_PTR_FORMAT, result);
2674 GST_OBJECT_UNLOCK (pad);
2680 * gst_pad_get_pad_template_caps:
2681 * @pad: a #GstPad to get the template capabilities from.
2683 * Gets the capabilities for @pad's template.
2685 * Returns: (transfer full): the #GstCaps of this pad template.
2686 * Unref after usage.
2689 gst_pad_get_pad_template_caps (GstPad * pad)
2691 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2693 if (GST_PAD_PAD_TEMPLATE (pad))
2694 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2696 return gst_caps_ref (GST_CAPS_ANY);
2701 * @pad: a #GstPad to get the peer of.
2703 * Gets the peer of @pad. This function refs the peer pad so
2704 * you need to unref it after use.
2706 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2711 gst_pad_get_peer (GstPad * pad)
2715 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2717 GST_OBJECT_LOCK (pad);
2718 result = GST_PAD_PEER (pad);
2720 gst_object_ref (result);
2721 GST_OBJECT_UNLOCK (pad);
2727 * gst_pad_get_allowed_caps:
2730 * Gets the capabilities of the allowed media types that can flow through
2731 * @pad and its peer.
2733 * The allowed capabilities is calculated as the intersection of the results of
2734 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2735 * on the resulting caps.
2737 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2738 * pad link. Unref the caps when you no longer need it. This
2739 * function returns %NULL when @pad has no peer.
2744 gst_pad_get_allowed_caps (GstPad * pad)
2747 GstCaps *caps = NULL;
2750 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2752 GST_OBJECT_LOCK (pad);
2753 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2755 GST_OBJECT_UNLOCK (pad);
2757 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2759 mycaps = gst_pad_query_caps (pad, NULL);
2761 /* Query peer caps */
2762 query = gst_query_new_caps (mycaps);
2763 if (!gst_pad_peer_query (pad, query)) {
2764 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2768 gst_query_parse_caps_result (query, &caps);
2770 g_warn_if_fail (caps != NULL);
2773 gst_caps_ref (caps);
2775 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2779 gst_query_unref (query);
2780 gst_caps_unref (mycaps);
2786 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2787 GST_OBJECT_UNLOCK (pad);
2794 * gst_pad_iterate_internal_links_default:
2795 * @pad: the #GstPad to get the internal links of.
2796 * @parent: (allow-none): the parent of @pad or %NULL
2798 * Iterate the list of pads to which the given pad is linked to inside of
2799 * the parent element.
2800 * This is the default handler, and thus returns an iterator of all of the
2801 * pads inside the parent element with opposite direction.
2803 * The caller must free this iterator after use with gst_iterator_free().
2805 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2806 * has no parent. Unref each returned pad with gst_object_unref().
2809 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2816 GstElement *eparent;
2818 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2820 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2821 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2823 GST_OBJECT_LOCK (pad);
2824 eparent = GST_PAD_PARENT (pad);
2825 if (!eparent || !GST_IS_ELEMENT (eparent))
2828 gst_object_ref (eparent);
2829 GST_OBJECT_UNLOCK (pad);
2832 if (pad->direction == GST_PAD_SRC)
2833 padlist = &eparent->sinkpads;
2835 padlist = &eparent->srcpads;
2837 GST_DEBUG_OBJECT (pad, "Making iterator");
2839 cookie = &eparent->pads_cookie;
2841 lock = GST_OBJECT_GET_LOCK (eparent);
2843 res = gst_iterator_new_list (GST_TYPE_PAD,
2844 lock, cookie, padlist, (GObject *) owner, NULL);
2846 gst_object_unref (owner);
2853 GST_OBJECT_UNLOCK (pad);
2854 GST_DEBUG_OBJECT (pad, "no parent element");
2860 * gst_pad_iterate_internal_links:
2861 * @pad: the GstPad to get the internal links of.
2863 * Gets an iterator for the pads to which the given pad is linked to inside
2864 * of the parent element.
2866 * Each #GstPad element yielded by the iterator will have its refcount increased,
2867 * so unref after use.
2869 * Free-function: gst_iterator_free
2871 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2872 * or %NULL when the pad does not have an iterator function
2873 * configured. Use gst_iterator_free() after usage.
2876 gst_pad_iterate_internal_links (GstPad * pad)
2878 GstIterator *res = NULL;
2881 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2883 GST_OBJECT_LOCK (pad);
2884 ACQUIRE_PARENT (pad, parent, no_parent);
2885 GST_OBJECT_UNLOCK (pad);
2887 if (GST_PAD_ITERINTLINKFUNC (pad))
2888 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2890 RELEASE_PARENT (parent);
2897 GST_DEBUG_OBJECT (pad, "no parent");
2898 GST_OBJECT_UNLOCK (pad);
2906 * @forward: (scope call): a #GstPadForwardFunction
2907 * @user_data: user data passed to @forward
2909 * Calls @forward for all internally linked pads of @pad. This function deals with
2910 * dynamically changing internal pads and will make sure that the @forward
2911 * function is only called once for each pad.
2913 * When @forward returns %TRUE, no further pads will be processed.
2915 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2918 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2921 gboolean result = FALSE;
2923 gboolean done = FALSE;
2924 GValue item = { 0, };
2925 GList *pushed_pads = NULL;
2927 iter = gst_pad_iterate_internal_links (pad);
2933 switch (gst_iterator_next (iter, &item)) {
2934 case GST_ITERATOR_OK:
2938 intpad = g_value_get_object (&item);
2940 /* if already pushed, skip. FIXME, find something faster to tag pads */
2941 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2942 g_value_reset (&item);
2946 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2947 GST_DEBUG_PAD_NAME (intpad));
2948 done = result = forward (intpad, user_data);
2950 pushed_pads = g_list_prepend (pushed_pads, intpad);
2952 g_value_reset (&item);
2955 case GST_ITERATOR_RESYNC:
2956 /* We don't reset the result here because we don't push the event
2957 * again on pads that got the event already and because we need
2958 * to consider the result of the previous pushes */
2959 gst_iterator_resync (iter);
2961 case GST_ITERATOR_ERROR:
2962 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2965 case GST_ITERATOR_DONE:
2970 g_value_unset (&item);
2971 gst_iterator_free (iter);
2973 g_list_free (pushed_pads);
2983 gboolean dispatched;
2987 event_forward_func (GstPad * pad, EventData * data)
2989 /* for each pad we send to, we should ref the event; it's up
2990 * to downstream to unref again when handled. */
2991 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2992 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2994 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2996 data->dispatched = TRUE;
3003 * gst_pad_event_default:
3004 * @pad: a #GstPad to call the default event handler on.
3005 * @parent: (allow-none): the parent of @pad or %NULL
3006 * @event: (transfer full): the #GstEvent to handle.
3008 * Invokes the default event handler for the given pad.
3010 * The EOS event will pause the task associated with @pad before it is forwarded
3011 * to all internally linked pads,
3013 * The event is sent to all pads internally linked to @pad. This function
3014 * takes ownership of @event.
3016 * Returns: %TRUE if the event was sent successfully.
3019 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3021 gboolean result, forward = TRUE;
3023 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3024 g_return_val_if_fail (event != NULL, FALSE);
3026 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3029 switch (GST_EVENT_TYPE (event)) {
3030 case GST_EVENT_CAPS:
3031 forward = GST_PAD_IS_PROXY_CAPS (pad);
3042 data.dispatched = FALSE;
3043 data.result = FALSE;
3045 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3047 /* for sinkpads without a parent element or without internal links, nothing
3048 * will be dispatched but we still want to return TRUE. */
3049 if (data.dispatched)
3050 result = data.result;
3055 gst_event_unref (event);
3060 /* Default accept caps implementation just checks against
3061 * the allowed caps for the pad */
3063 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3065 /* get the caps and see if it intersects to something not empty */
3066 GstCaps *caps, *allowed = NULL;
3069 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3071 /* first forward the query to internally linked pads when we are dealing with
3073 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3074 result = gst_pad_proxy_query_accept_caps (pad, query);
3076 allowed = gst_pad_get_pad_template_caps (pad);
3081 gst_query_parse_accept_caps (query, &caps);
3083 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3084 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3085 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad))
3086 allowed = gst_pad_get_pad_template_caps (pad);
3088 allowed = gst_pad_query_caps (pad, caps);
3092 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3093 GST_DEBUG_OBJECT (pad,
3094 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3096 result = gst_caps_can_intersect (caps, allowed);
3098 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3099 GST_PTR_FORMAT, allowed, caps);
3100 result = gst_caps_is_subset (caps, allowed);
3102 gst_caps_unref (allowed);
3104 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3107 gst_query_set_accept_caps_result (query, result);
3113 /* Default caps implementation */
3115 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3117 GstCaps *result = NULL, *filter;
3118 GstPadTemplate *templ;
3119 gboolean fixed_caps;
3121 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3124 /* first try to proxy if we must */
3125 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3126 if ((gst_pad_proxy_query_caps (pad, query))) {
3131 gst_query_parse_caps (query, &filter);
3133 /* no proxy or it failed, do default handling */
3134 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3136 GST_OBJECT_LOCK (pad);
3138 /* fixed caps, try the negotiated caps first */
3139 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3140 if ((result = get_pad_caps (pad)))
3141 goto filter_done_unlock;
3144 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3145 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3146 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3147 goto filter_done_unlock;
3151 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3152 "non-fixed pad caps: trying pad caps");
3153 /* non fixed caps, try the negotiated caps */
3154 if ((result = get_pad_caps (pad)))
3155 goto filter_done_unlock;
3158 /* this almost never happens */
3159 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3160 result = GST_CAPS_ANY;
3163 GST_OBJECT_UNLOCK (pad);
3165 /* run the filter on the result */
3167 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3168 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3169 GST_PTR_FORMAT, result, result, filter, filter);
3170 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3171 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3174 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3175 "using caps %p %" GST_PTR_FORMAT, result, result);
3176 result = gst_caps_ref (result);
3178 gst_query_set_caps_result (query, result);
3179 gst_caps_unref (result);
3185 /* Default latency implementation */
3190 GstClockTime min, max;
3194 query_latency_default_fold (const GValue * item, GValue * ret,
3197 GstPad *pad = g_value_get_object (item), *peer;
3198 LatencyFoldData *fold_data = user_data;
3200 gboolean res = FALSE;
3202 query = gst_query_new_latency ();
3204 peer = gst_pad_get_peer (pad);
3206 res = gst_pad_peer_query (pad, query);
3208 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3213 GstClockTime min, max;
3215 gst_query_parse_latency (query, &live, &min, &max);
3217 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3218 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3220 /* FIXME : Why do we only take values into account if it's live ? */
3221 if (live || fold_data->count == 0) {
3222 if (min > fold_data->min)
3223 fold_data->min = min;
3225 if (fold_data->max == GST_CLOCK_TIME_NONE)
3226 fold_data->max = max;
3227 else if (max < fold_data->max)
3228 fold_data->max = max;
3230 fold_data->live = live;
3232 fold_data->count += 1;
3234 GST_DEBUG_OBJECT (pad, "latency query failed");
3235 g_value_set_boolean (ret, FALSE);
3238 gst_query_unref (query);
3240 gst_object_unref (peer);
3246 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3249 GstIteratorResult res;
3250 GValue ret = G_VALUE_INIT;
3252 LatencyFoldData fold_data;
3254 it = gst_pad_iterate_internal_links (pad);
3256 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3260 g_value_init (&ret, G_TYPE_BOOLEAN);
3263 fold_data.count = 0;
3264 fold_data.live = FALSE;
3266 fold_data.max = GST_CLOCK_TIME_NONE;
3268 g_value_set_boolean (&ret, TRUE);
3269 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3271 case GST_ITERATOR_OK:
3272 g_assert_not_reached ();
3274 case GST_ITERATOR_DONE:
3276 case GST_ITERATOR_ERROR:
3277 g_value_set_boolean (&ret, FALSE);
3279 case GST_ITERATOR_RESYNC:
3280 gst_iterator_resync (it);
3283 g_assert_not_reached ();
3286 gst_iterator_free (it);
3288 query_ret = g_value_get_boolean (&ret);
3290 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3291 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3292 fold_data.min, fold_data.max);
3294 if (fold_data.min > fold_data.max) {
3295 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3298 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3300 GST_LOG_OBJECT (pad, "latency query failed");
3310 gboolean dispatched;
3314 query_forward_func (GstPad * pad, QueryData * data)
3316 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3317 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3319 data->result |= gst_pad_peer_query (pad, data->query);
3321 data->dispatched = TRUE;
3323 /* stop on first successful reply */
3324 return data->result;
3328 * gst_pad_query_default:
3329 * @pad: a #GstPad to call the default query handler on.
3330 * @parent: (allow-none): the parent of @pad or %NULL
3331 * @query: (transfer none): the #GstQuery to handle.
3333 * Invokes the default query handler for the given pad.
3334 * The query is sent to all pads internally linked to @pad. Note that
3335 * if there are many possible sink pads that are internally linked to
3336 * @pad, only one will be sent the query.
3337 * Multi-sinkpad elements should implement custom query handlers.
3339 * Returns: %TRUE if the query was performed successfully.
3342 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3344 gboolean forward, ret = FALSE;
3346 switch (GST_QUERY_TYPE (query)) {
3347 case GST_QUERY_SCHEDULING:
3348 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3350 case GST_QUERY_ALLOCATION:
3351 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3353 case GST_QUERY_ACCEPT_CAPS:
3354 ret = gst_pad_query_accept_caps_default (pad, query);
3357 case GST_QUERY_CAPS:
3358 ret = gst_pad_query_caps_default (pad, query);
3361 case GST_QUERY_LATENCY:
3362 ret = gst_pad_query_latency_default (pad, query);
3365 case GST_QUERY_POSITION:
3366 case GST_QUERY_SEEKING:
3367 case GST_QUERY_FORMATS:
3368 case GST_QUERY_JITTER:
3369 case GST_QUERY_RATE:
3370 case GST_QUERY_CONVERT:
3376 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3377 query, GST_QUERY_TYPE_NAME (query));
3383 data.dispatched = FALSE;
3384 data.result = FALSE;
3386 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3388 if (data.dispatched) {
3391 /* nothing dispatched, assume drained */
3392 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3402 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3404 GstPad *pad = data->pad;
3405 GstPadProbeInfo *info = data->info;
3406 GstPadProbeType type, flags;
3407 GstPadProbeCallback callback;
3408 GstPadProbeReturn ret;
3409 gpointer original_data;
3411 /* if we have called this callback, do nothing */
3412 if (PROBE_COOKIE (hook) == data->cookie) {
3413 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3414 "hook %lu, cookie %u already called", hook->hook_id,
3415 PROBE_COOKIE (hook));
3419 PROBE_COOKIE (hook) = data->cookie;
3421 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3423 original_data = info->data;
3425 /* one of the scheduling types */
3426 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3429 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3430 /* one of the data types for non-idle probes */
3431 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3432 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3434 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3435 /* one of the data types for non-idle probes */
3436 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3437 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3440 /* Type must have PULL or PUSH probe types */
3441 g_assert_not_reached ();
3444 /* one of the blocking types must match */
3445 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3446 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3448 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3449 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3451 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3452 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3453 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3456 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3457 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3458 PROBE_COOKIE (hook), flags);
3460 data->marshalled = TRUE;
3462 callback = (GstPadProbeCallback) hook->func;
3463 if (callback == NULL)
3466 info->id = hook->hook_id;
3468 GST_OBJECT_UNLOCK (pad);
3470 ret = callback (pad, info, hook->data);
3472 GST_OBJECT_LOCK (pad);
3474 if (original_data != NULL && info->data == NULL) {
3475 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3476 info->type = GST_PAD_PROBE_TYPE_INVALID;
3477 data->dropped = TRUE;
3481 case GST_PAD_PROBE_REMOVE:
3482 /* remove the probe */
3483 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3484 cleanup_hook (pad, hook);
3486 case GST_PAD_PROBE_DROP:
3487 /* need to drop the data, make sure other probes don't get called
3489 GST_DEBUG_OBJECT (pad, "asked to drop item");
3490 info->type = GST_PAD_PROBE_TYPE_INVALID;
3491 data->dropped = TRUE;
3493 case GST_PAD_PROBE_HANDLED:
3494 GST_DEBUG_OBJECT (pad, "probe handled data");
3495 data->handled = TRUE;
3497 case GST_PAD_PROBE_PASS:
3498 /* inform the pad block to let things pass */
3499 GST_DEBUG_OBJECT (pad, "asked to pass item");
3502 case GST_PAD_PROBE_OK:
3503 GST_DEBUG_OBJECT (pad, "probe returned OK");
3506 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3513 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3514 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3515 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3520 /* a probe that does not take or return any data */
3521 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3523 if (G_UNLIKELY (pad->num_probes)) { \
3524 GstFlowReturn pval = defaultval; \
3525 /* pass NULL as the data item */ \
3526 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3527 info.ABI.abi.flow_ret = defaultval; \
3528 ret = do_probe_callbacks (pad, &info, defaultval); \
3529 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3534 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3536 if (G_UNLIKELY (pad->num_probes)) { \
3537 /* pass the data item */ \
3538 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3539 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3540 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3541 /* store the possibly updated data item */ \
3542 data = GST_PAD_PROBE_INFO_DATA (&info); \
3543 /* if something went wrong, exit */ \
3544 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3545 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3546 ret = info.ABI.abi.flow_ret; \
3547 goto handle_label; \
3554 #define PROBE_PUSH(pad,mask,data,label) \
3555 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3556 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3557 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3558 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3559 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3561 static GstFlowReturn
3562 do_pad_idle_probe_wait (GstPad * pad)
3564 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3565 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3566 "waiting idle probe to be removed");
3567 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3568 GST_PAD_BLOCK_WAIT (pad);
3569 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3570 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3572 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3573 return GST_FLOW_FLUSHING;
3578 #define PROBE_TYPE_IS_SERIALIZED(i) \
3581 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3582 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3583 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3585 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3586 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3588 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3589 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3593 static GstFlowReturn
3594 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3595 GstFlowReturn defaultval)
3604 data.handled = FALSE;
3605 data.marshalled = FALSE;
3606 data.dropped = FALSE;
3607 data.cookie = ++pad->priv->probe_cookie;
3610 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3612 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3613 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3618 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3619 "do probes cookie %u", data.cookie);
3620 cookie = pad->priv->probe_list_cookie;
3622 g_hook_list_marshal (&pad->probes, TRUE,
3623 (GHookMarshaller) probe_hook_marshal, &data);
3625 /* if the list changed, call the new callbacks (they will not have their
3626 * cookie set to data.cookie */
3627 if (cookie != pad->priv->probe_list_cookie) {
3628 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3629 "probe list changed, restarting");
3633 /* the first item that dropped will stop the hooks and then we drop here */
3637 /* If one handler took care of it, let the the item pass */
3642 /* if no handler matched and we are blocking, let the item pass */
3643 if (!data.marshalled && is_block)
3646 /* At this point, all handlers returned either OK or PASS. If one handler
3647 * returned PASS, let the item pass */
3652 while (GST_PAD_IS_BLOCKED (pad)) {
3653 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3654 "we are blocked %d times", pad->num_blocked);
3656 /* we might have released the lock */
3657 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3660 /* now we block the streaming thread. It can be unlocked when we
3661 * deactivate the pad (which will also set the FLUSHING flag) or
3662 * when the pad is unblocked. A flushing event will also unblock
3663 * the pad after setting the FLUSHING flag. */
3664 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3665 "Waiting to be unblocked or set flushing");
3666 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3667 GST_PAD_BLOCK_WAIT (pad);
3668 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3669 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3671 /* if the list changed, call the new callbacks (they will not have their
3672 * cookie set to data.cookie */
3673 if (cookie != pad->priv->probe_list_cookie) {
3674 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3675 "probe list changed, restarting");
3679 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3689 GST_DEBUG_OBJECT (pad, "pad is flushing");
3690 return GST_FLOW_FLUSHING;
3694 GST_DEBUG_OBJECT (pad, "data is dropped");
3695 return GST_FLOW_CUSTOM_SUCCESS;
3699 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3700 GST_DEBUG_OBJECT (pad, "data is passed");
3705 GST_DEBUG_OBJECT (pad, "data was handled");
3706 return GST_FLOW_CUSTOM_SUCCESS_1;
3713 * gst_pad_get_offset:
3716 * Get the offset applied to the running time of @pad. @pad has to be a source
3719 * Returns: the offset.
3722 gst_pad_get_offset (GstPad * pad)
3726 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3728 GST_OBJECT_LOCK (pad);
3729 result = pad->offset;
3730 GST_OBJECT_UNLOCK (pad);
3736 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3738 ev->received = FALSE;
3743 * gst_pad_set_offset:
3745 * @offset: the offset
3747 * Set the offset that will be applied to the running time of @pad.
3750 gst_pad_set_offset (GstPad * pad, gint64 offset)
3752 g_return_if_fail (GST_IS_PAD (pad));
3754 GST_OBJECT_LOCK (pad);
3755 /* if nothing changed, do nothing */
3756 if (pad->offset == offset)
3759 pad->offset = offset;
3760 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3761 GST_STIME_ARGS (offset));
3763 /* resend all sticky events with updated offset on next buffer push */
3764 events_foreach (pad, mark_event_not_received, NULL);
3765 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3768 GST_OBJECT_UNLOCK (pad);
3775 /* If TRUE and ret is not OK this means
3776 * that pushing the EOS event failed
3780 /* If called for an event this is
3781 * the event that would be pushed
3782 * next. Don't forward sticky events
3783 * that would come after that */
3787 /* should be called with pad LOCK */
3789 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3791 PushStickyData *data = user_data;
3792 GstEvent *event = ev->event;
3795 GST_DEBUG_OBJECT (pad, "event %s was already received",
3796 GST_EVENT_TYPE_NAME (event));
3800 /* If we're called because of an sticky event, only forward
3801 * events that would come before this new event and the
3803 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3804 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3805 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3806 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3808 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3809 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3812 switch (data->ret) {
3814 ev->received = TRUE;
3815 GST_DEBUG_OBJECT (pad, "event %s marked received",
3816 GST_EVENT_TYPE_NAME (event));
3818 case GST_FLOW_CUSTOM_SUCCESS:
3819 /* we can't assume the event is received when it was dropped */
3820 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3821 GST_EVENT_TYPE_NAME (event));
3822 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3823 data->ret = GST_FLOW_OK;
3825 case GST_FLOW_CUSTOM_SUCCESS_1:
3826 /* event was ignored and should be sent later */
3827 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3828 GST_EVENT_TYPE_NAME (event));
3829 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3830 data->ret = GST_FLOW_OK;
3832 case GST_FLOW_NOT_LINKED:
3833 /* not linked is not a problem, we are sticky so the event will be
3834 * rescheduled to be sent later on re-link, but only for non-EOS events */
3835 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3836 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3837 data->ret = GST_FLOW_OK;
3838 ev->received = TRUE;
3842 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3843 gst_flow_get_name (data->ret));
3844 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3848 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3849 data->was_eos = TRUE;
3851 return data->ret == GST_FLOW_OK;
3854 /* check sticky events and push them when needed. should be called
3856 static inline GstFlowReturn
3857 check_sticky (GstPad * pad, GstEvent * event)
3859 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3861 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3862 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3864 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3865 events_foreach (pad, push_sticky, &data);
3867 /* If there's an EOS event we must push it downstream
3868 * even if sending a previous sticky event failed.
3869 * Otherwise the pipeline might wait forever for EOS.
3871 * Only do this if pushing another event than the EOS
3874 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3875 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3877 if (ev && !ev->received) {
3878 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3879 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3880 /* the event could have been dropped. Because this can only
3881 * happen if the user asked for it, it's not an error */
3882 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3883 data.ret = GST_FLOW_OK;
3893 * @pad: a #GstPad to invoke the default query on.
3894 * @query: (transfer none): the #GstQuery to perform.
3896 * Dispatches a query to a pad. The query should have been allocated by the
3897 * caller via one of the type-specific allocation functions. The element that
3898 * the pad belongs to is responsible for filling the query with an appropriate
3899 * response, which should then be parsed with a type-specific query parsing
3902 * Again, the caller is responsible for both the allocation and deallocation of
3903 * the query structure.
3905 * Please also note that some queries might need a running pipeline to work.
3907 * Returns: %TRUE if the query could be performed.
3910 gst_pad_query (GstPad * pad, GstQuery * query)
3913 gboolean res, serialized;
3914 GstPadQueryFunction func;
3915 GstPadProbeType type;
3918 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3919 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3921 if (GST_PAD_IS_SRC (pad)) {
3922 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3923 goto wrong_direction;
3924 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3925 } else if (GST_PAD_IS_SINK (pad)) {
3926 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3927 goto wrong_direction;
3928 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3930 goto unknown_direction;
3932 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3933 GST_QUERY_TYPE_NAME (query));
3934 GST_TRACER_PAD_QUERY_PRE (pad, query);
3936 serialized = GST_QUERY_IS_SERIALIZED (query);
3937 if (G_UNLIKELY (serialized))
3938 GST_PAD_STREAM_LOCK (pad);
3940 GST_OBJECT_LOCK (pad);
3941 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3942 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3943 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3945 ACQUIRE_PARENT (pad, parent, no_parent);
3946 GST_OBJECT_UNLOCK (pad);
3948 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3951 res = func (pad, parent, query);
3953 RELEASE_PARENT (parent);
3955 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3956 GST_QUERY_TYPE_NAME (query), res);
3957 GST_TRACER_PAD_QUERY_POST (pad, query, res);
3962 GST_OBJECT_LOCK (pad);
3963 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3964 GST_OBJECT_UNLOCK (pad);
3966 if (G_UNLIKELY (serialized))
3967 GST_PAD_STREAM_UNLOCK (pad);
3974 g_warning ("pad %s:%s query %s in wrong direction",
3975 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3980 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3985 GST_DEBUG_OBJECT (pad, "had no parent");
3986 GST_OBJECT_UNLOCK (pad);
3987 if (G_UNLIKELY (serialized))
3988 GST_PAD_STREAM_UNLOCK (pad);
3993 GST_DEBUG_OBJECT (pad, "had no query function");
3994 RELEASE_PARENT (parent);
3995 if (G_UNLIKELY (serialized))
3996 GST_PAD_STREAM_UNLOCK (pad);
4001 GST_DEBUG_OBJECT (pad, "query failed");
4002 if (G_UNLIKELY (serialized))
4003 GST_PAD_STREAM_UNLOCK (pad);
4008 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4009 GST_OBJECT_UNLOCK (pad);
4010 if (G_UNLIKELY (serialized))
4011 GST_PAD_STREAM_UNLOCK (pad);
4013 /* if a probe dropped without handling, we don't sent it further but assume
4014 * that the probe did not answer the query and return FALSE */
4015 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4025 * gst_pad_peer_query:
4026 * @pad: a #GstPad to invoke the peer query on.
4027 * @query: (transfer none): the #GstQuery to perform.
4029 * Performs gst_pad_query() on the peer of @pad.
4031 * The caller is responsible for both the allocation and deallocation of
4032 * the query structure.
4034 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4035 * if @pad has no peer.
4038 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4041 GstPadProbeType type;
4042 gboolean res, serialized;
4045 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4046 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4048 if (GST_PAD_IS_SRC (pad)) {
4049 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4050 goto wrong_direction;
4051 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4052 } else if (GST_PAD_IS_SINK (pad)) {
4053 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4054 goto wrong_direction;
4055 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4057 goto unknown_direction;
4059 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4060 GST_QUERY_TYPE_NAME (query));
4062 serialized = GST_QUERY_IS_SERIALIZED (query);
4064 GST_OBJECT_LOCK (pad);
4065 if (GST_PAD_IS_SRC (pad) && serialized) {
4066 /* all serialized queries on the srcpad trigger push of
4068 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4072 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4073 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4074 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4076 peerpad = GST_PAD_PEER (pad);
4077 if (G_UNLIKELY (peerpad == NULL))
4080 gst_object_ref (peerpad);
4081 GST_OBJECT_UNLOCK (pad);
4083 res = gst_pad_query (peerpad, query);
4085 gst_object_unref (peerpad);
4090 GST_OBJECT_LOCK (pad);
4091 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4092 GST_OBJECT_UNLOCK (pad);
4099 g_warning ("pad %s:%s query %s in wrong direction",
4100 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4105 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4110 GST_WARNING_OBJECT (pad, "could not send sticky events");
4111 GST_OBJECT_UNLOCK (pad);
4116 GST_INFO_OBJECT (pad, "pad has no peer");
4117 GST_OBJECT_UNLOCK (pad);
4122 GST_DEBUG_OBJECT (pad, "query failed");
4127 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4128 GST_OBJECT_UNLOCK (pad);
4130 /* if a probe dropped without handling, we don't sent it further but
4131 * assume that the probe did not answer the query and return FALSE */
4132 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4141 /**********************************************************************
4142 * Data passing functions
4145 /* this is the chain function that does not perform the additional argument
4146 * checking for that little extra speed.
4148 static inline GstFlowReturn
4149 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4153 gboolean handled = FALSE;
4155 GST_PAD_STREAM_LOCK (pad);
4157 GST_OBJECT_LOCK (pad);
4158 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4161 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4164 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4167 #ifdef GST_ENABLE_EXTRA_CHECKS
4168 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4169 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4171 ":%s:<%s:%s> Got data flow before stream-start event",
4172 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4174 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4176 ":%s:<%s:%s> Got data flow before segment event",
4177 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4179 pad->priv->last_cookie = pad->priv->events_cookie;
4183 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4186 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4188 ACQUIRE_PARENT (pad, parent, no_parent);
4189 GST_OBJECT_UNLOCK (pad);
4191 /* NOTE: we read the chainfunc unlocked.
4192 * we cannot hold the lock for the pad so we might send
4193 * the data to the wrong function. This is not really a
4194 * problem since functions are assigned at creation time
4195 * and don't change that often... */
4196 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4197 GstPadChainFunction chainfunc;
4199 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4202 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4203 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4204 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4206 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4208 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4209 "called chainfunction &%s with buffer %p, returned %s",
4210 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4212 GstPadChainListFunction chainlistfunc;
4214 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4217 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4218 "calling chainlistfunction &%s",
4219 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4221 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4223 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4224 "called chainlistfunction &%s, returned %s",
4225 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4228 RELEASE_PARENT (parent);
4230 GST_PAD_STREAM_UNLOCK (pad);
4237 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4238 "chaining, but pad was flushing");
4239 GST_OBJECT_UNLOCK (pad);
4240 GST_PAD_STREAM_UNLOCK (pad);
4241 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4242 return GST_FLOW_FLUSHING;
4246 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4247 GST_OBJECT_UNLOCK (pad);
4248 GST_PAD_STREAM_UNLOCK (pad);
4249 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4250 return GST_FLOW_EOS;
4254 g_critical ("chain on pad %s:%s but it was not in push mode",
4255 GST_DEBUG_PAD_NAME (pad));
4256 GST_OBJECT_UNLOCK (pad);
4257 GST_PAD_STREAM_UNLOCK (pad);
4258 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4259 return GST_FLOW_ERROR;
4266 GST_OBJECT_UNLOCK (pad);
4267 GST_PAD_STREAM_UNLOCK (pad);
4268 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4270 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4273 case GST_FLOW_CUSTOM_SUCCESS:
4274 case GST_FLOW_CUSTOM_SUCCESS_1:
4275 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4279 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4286 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4287 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4288 GST_OBJECT_UNLOCK (pad);
4289 GST_PAD_STREAM_UNLOCK (pad);
4290 return GST_FLOW_FLUSHING;
4294 RELEASE_PARENT (parent);
4295 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4296 g_critical ("chain on pad %s:%s but it has no chainfunction",
4297 GST_DEBUG_PAD_NAME (pad));
4298 GST_PAD_STREAM_UNLOCK (pad);
4299 return GST_FLOW_NOT_SUPPORTED;
4305 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4306 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4309 * Chain a buffer to @pad.
4311 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4313 * If the buffer type is not acceptable for @pad (as negotiated with a
4314 * preceding GST_EVENT_CAPS event), this function returns
4315 * #GST_FLOW_NOT_NEGOTIATED.
4317 * The function proceeds calling the chain function installed on @pad (see
4318 * gst_pad_set_chain_function()) and the return value of that function is
4319 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4322 * In all cases, success or failure, the caller loses its reference to @buffer
4323 * after calling this function.
4325 * Returns: a #GstFlowReturn from the pad.
4330 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4332 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4333 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4334 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4336 return gst_pad_chain_data_unchecked (pad,
4337 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4340 static GstFlowReturn
4341 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4342 GstBufferList * list)
4348 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4350 len = gst_buffer_list_length (list);
4353 for (i = 0; i < len; i++) {
4354 buffer = gst_buffer_list_get (list, i);
4356 gst_pad_chain_data_unchecked (pad,
4357 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4358 gst_buffer_ref (buffer));
4359 if (ret != GST_FLOW_OK)
4362 gst_buffer_list_unref (list);
4368 * gst_pad_chain_list:
4369 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4370 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4373 * Chain a bufferlist to @pad.
4375 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4377 * If @pad was not negotiated properly with a CAPS event, this function
4378 * returns #GST_FLOW_NOT_NEGOTIATED.
4380 * The function proceeds calling the chainlist function installed on @pad (see
4381 * gst_pad_set_chain_list_function()) and the return value of that function is
4382 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4383 * chainlist function.
4385 * In all cases, success or failure, the caller loses its reference to @list
4386 * after calling this function.
4390 * Returns: a #GstFlowReturn from the pad.
4393 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4395 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4396 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4397 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4399 return gst_pad_chain_data_unchecked (pad,
4400 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4403 static GstFlowReturn
4404 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4408 gboolean handled = FALSE;
4410 GST_OBJECT_LOCK (pad);
4411 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4414 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4417 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4420 #ifdef GST_ENABLE_EXTRA_CHECKS
4421 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4422 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4424 ":%s:<%s:%s> Got data flow before stream-start event",
4425 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4427 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4429 ":%s:<%s:%s> Got data flow before segment event",
4430 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4432 pad->priv->last_cookie = pad->priv->events_cookie;
4436 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4439 /* do block probes */
4440 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4443 /* recheck sticky events because the probe might have cause a relink */
4444 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4447 /* do post-blocking probes */
4448 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4450 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4453 /* take ref to peer pad before releasing the lock */
4454 gst_object_ref (peer);
4456 GST_OBJECT_UNLOCK (pad);
4458 ret = gst_pad_chain_data_unchecked (peer, type, data);
4461 gst_object_unref (peer);
4463 GST_OBJECT_LOCK (pad);
4464 pad->ABI.abi.last_flowret = ret;
4466 if (pad->priv->using == 0) {
4467 /* pad is not active anymore, trigger idle callbacks */
4468 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4469 probe_stopped, ret);
4471 GST_OBJECT_UNLOCK (pad);
4475 /* ERROR recovery here */
4479 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4480 "pushing, but pad was flushing");
4481 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4482 GST_OBJECT_UNLOCK (pad);
4483 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4484 return GST_FLOW_FLUSHING;
4488 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4489 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4490 GST_OBJECT_UNLOCK (pad);
4491 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4492 return GST_FLOW_EOS;
4496 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4497 GST_DEBUG_PAD_NAME (pad));
4498 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4499 GST_OBJECT_UNLOCK (pad);
4500 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4501 return GST_FLOW_ERROR;
4505 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4506 "error pushing events, return %s", gst_flow_get_name (ret));
4507 pad->ABI.abi.last_flowret = ret;
4508 GST_OBJECT_UNLOCK (pad);
4509 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4517 GST_OBJECT_UNLOCK (pad);
4518 if (data != NULL && !handled)
4519 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4522 case GST_FLOW_CUSTOM_SUCCESS:
4523 case GST_FLOW_CUSTOM_SUCCESS_1:
4524 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4528 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4531 pad->ABI.abi.last_flowret = ret;
4536 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4537 "pushing, but it was not linked");
4538 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4539 GST_OBJECT_UNLOCK (pad);
4540 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4541 return GST_FLOW_NOT_LINKED;
4547 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4548 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4551 * Pushes a buffer to the peer of @pad.
4553 * This function will call installed block probes before triggering any
4554 * installed data probes.
4556 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4557 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4560 * In all cases, success or failure, the caller loses its reference to @buffer
4561 * after calling this function.
4563 * Returns: a #GstFlowReturn from the peer pad.
4568 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4572 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4573 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4574 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4576 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4577 res = gst_pad_push_data (pad,
4578 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4579 GST_TRACER_PAD_PUSH_POST (pad, res);
4584 * gst_pad_push_list:
4585 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4586 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4589 * Pushes a buffer list to the peer of @pad.
4591 * This function will call installed block probes before triggering any
4592 * installed data probes.
4594 * The function proceeds calling the chain function on the peer pad and returns
4595 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4596 * be returned. If the peer pad does not have any installed chainlist function
4597 * every group buffer of the list will be merged into a normal #GstBuffer and
4598 * chained via gst_pad_chain().
4600 * In all cases, success or failure, the caller loses its reference to @list
4601 * after calling this function.
4603 * Returns: a #GstFlowReturn from the peer pad.
4608 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4612 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4613 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4614 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4616 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4617 res = gst_pad_push_data (pad,
4618 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4619 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4623 static GstFlowReturn
4624 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4625 GstBuffer ** buffer)
4628 GstPadGetRangeFunction getrangefunc;
4632 GST_PAD_STREAM_LOCK (pad);
4634 GST_OBJECT_LOCK (pad);
4635 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4638 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4641 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4646 /* when one of the probes returns DROPPED, probe_stopped will be called
4647 * and we skip calling the getrange function, res_buf should then contain a
4648 * valid result buffer */
4649 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4650 res_buf, offset, size, probe_stopped);
4652 /* recheck sticky events because the probe might have cause a relink */
4653 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4656 ACQUIRE_PARENT (pad, parent, no_parent);
4657 GST_OBJECT_UNLOCK (pad);
4659 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4662 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4663 "calling getrangefunc %s, offset %"
4664 G_GUINT64_FORMAT ", size %u",
4665 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4667 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4669 RELEASE_PARENT (parent);
4671 GST_OBJECT_LOCK (pad);
4672 if (G_UNLIKELY (ret != GST_FLOW_OK))
4673 goto get_range_failed;
4675 /* can only fire the signal if we have a valid buffer */
4677 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4678 res_buf, offset, size, probe_stopped_unref);
4679 pad->ABI.abi.last_flowret = ret;
4680 GST_OBJECT_UNLOCK (pad);
4682 GST_PAD_STREAM_UNLOCK (pad);
4691 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4692 "getrange, but pad was flushing");
4693 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4694 GST_OBJECT_UNLOCK (pad);
4695 GST_PAD_STREAM_UNLOCK (pad);
4696 return GST_FLOW_FLUSHING;
4700 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4701 GST_DEBUG_PAD_NAME (pad));
4702 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4703 GST_OBJECT_UNLOCK (pad);
4704 GST_PAD_STREAM_UNLOCK (pad);
4705 return GST_FLOW_ERROR;
4709 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4710 pad->ABI.abi.last_flowret = ret;
4711 GST_OBJECT_UNLOCK (pad);
4712 GST_PAD_STREAM_UNLOCK (pad);
4717 GST_DEBUG_OBJECT (pad, "no parent");
4718 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4719 GST_OBJECT_UNLOCK (pad);
4720 GST_PAD_STREAM_UNLOCK (pad);
4721 return GST_FLOW_FLUSHING;
4725 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4726 GST_DEBUG_PAD_NAME (pad));
4727 RELEASE_PARENT (parent);
4728 GST_PAD_STREAM_UNLOCK (pad);
4729 return GST_FLOW_NOT_SUPPORTED;
4733 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4734 "probe returned %s", gst_flow_get_name (ret));
4735 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4737 /* the probe filled the buffer and asks us to not call the getrange
4738 * anymore, we continue with the post probes then. */
4739 GST_DEBUG_OBJECT (pad, "handled buffer");
4743 /* no buffer, we are EOS */
4744 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4748 pad->ABI.abi.last_flowret = ret;
4749 GST_OBJECT_UNLOCK (pad);
4750 GST_PAD_STREAM_UNLOCK (pad);
4754 probe_stopped_unref:
4756 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4757 "probe returned %s", gst_flow_get_name (ret));
4758 /* if we drop here, it signals EOS */
4759 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4761 pad->ABI.abi.last_flowret = ret;
4762 GST_OBJECT_UNLOCK (pad);
4763 GST_PAD_STREAM_UNLOCK (pad);
4764 if (*buffer == NULL)
4765 gst_buffer_unref (res_buf);
4770 pad->ABI.abi.last_flowret = ret;
4771 GST_OBJECT_UNLOCK (pad);
4772 GST_PAD_STREAM_UNLOCK (pad);
4773 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4774 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4775 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4781 * gst_pad_get_range:
4782 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4783 * @offset: The start offset of the buffer
4784 * @size: The length of the buffer
4785 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4786 * returns #GST_FLOW_ERROR if %NULL.
4788 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4789 * immediately and @buffer is %NULL.
4791 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4792 * description of a getrange function. If @pad has no getrange function
4793 * installed (see gst_pad_set_getrange_function()) this function returns
4794 * #GST_FLOW_NOT_SUPPORTED.
4796 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4797 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4798 * must be freed with gst_buffer_unref() after usage.
4800 * When @buffer points to a variable that points to a valid #GstBuffer, the
4801 * buffer will be filled with the result data when this function returns
4802 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4803 * @size bytes will be filled in the result buffer and its size will be updated
4806 * Note that less than @size bytes can be returned in @buffer when, for example,
4807 * an EOS condition is near or when @buffer is not large enough to hold @size
4808 * bytes. The caller should check the result buffer size to get the result size.
4810 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4811 * will be unchanged.
4813 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4815 * Returns: a #GstFlowReturn from the pad.
4820 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4821 GstBuffer ** buffer)
4823 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4824 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4825 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4826 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4827 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4829 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4833 * gst_pad_pull_range:
4834 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4835 * @offset: The start offset of the buffer
4836 * @size: The length of the buffer
4837 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4838 * GST_FLOW_ERROR if %NULL.
4840 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4842 * This function will first trigger the pad block signal if it was
4845 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4846 * function returns the result of gst_pad_get_range() on the peer pad.
4847 * See gst_pad_get_range() for a list of return values and for the
4848 * semantics of the arguments of this function.
4850 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4851 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4852 * must be freed with gst_buffer_unref() after usage. When this function
4853 * returns any other result value, @buffer will still point to %NULL.
4855 * When @buffer points to a variable that points to a valid #GstBuffer, the
4856 * buffer will be filled with the result data when this function returns
4857 * #GST_FLOW_OK. When this function returns any other result value,
4858 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4859 * @size bytes will be filled in the result buffer and its size will be updated
4862 * Note that less than @size bytes can be returned in @buffer when, for example,
4863 * an EOS condition is near or when @buffer is not large enough to hold @size
4864 * bytes. The caller should check the result buffer size to get the result size.
4866 * Returns: a #GstFlowReturn from the peer pad.
4871 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4872 GstBuffer ** buffer)
4878 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4879 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4880 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4881 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4882 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4884 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4886 GST_OBJECT_LOCK (pad);
4887 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4890 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4895 /* when one of the probes returns DROPPED, probe_stopped will be
4896 * called and we skip calling the peer getrange function. *buffer should then
4897 * contain a valid buffer */
4898 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4899 res_buf, offset, size, probe_stopped);
4901 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4904 gst_object_ref (peer);
4906 GST_OBJECT_UNLOCK (pad);
4908 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4910 gst_object_unref (peer);
4912 GST_OBJECT_LOCK (pad);
4914 pad->ABI.abi.last_flowret = ret;
4915 if (pad->priv->using == 0) {
4916 /* pad is not active anymore, trigger idle callbacks */
4917 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4918 probe_stopped_unref, ret);
4921 if (G_UNLIKELY (ret != GST_FLOW_OK))
4922 goto pull_range_failed;
4925 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4926 res_buf, offset, size, probe_stopped_unref);
4928 GST_OBJECT_UNLOCK (pad);
4932 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4935 /* ERROR recovery here */
4938 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4939 "pullrange, but pad was flushing");
4940 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4941 GST_OBJECT_UNLOCK (pad);
4942 ret = GST_FLOW_FLUSHING;
4947 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4948 GST_DEBUG_PAD_NAME (pad));
4949 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4950 GST_OBJECT_UNLOCK (pad);
4951 ret = GST_FLOW_ERROR;
4956 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4957 gst_flow_get_name (ret));
4958 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4960 /* the probe filled the buffer and asks us to not forward to the peer
4961 * anymore, we continue with the post probes then */
4962 GST_DEBUG_OBJECT (pad, "handled buffer");
4966 /* no buffer, we are EOS then */
4967 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4971 pad->ABI.abi.last_flowret = ret;
4972 GST_OBJECT_UNLOCK (pad);
4977 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4978 "pulling range, but it was not linked");
4979 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4980 GST_OBJECT_UNLOCK (pad);
4981 ret = GST_FLOW_NOT_LINKED;
4986 pad->ABI.abi.last_flowret = ret;
4987 GST_OBJECT_UNLOCK (pad);
4988 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4989 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4990 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4993 probe_stopped_unref:
4995 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4996 "post probe returned %s", gst_flow_get_name (ret));
4998 /* if we drop here, it signals EOS */
4999 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5002 pad->ABI.abi.last_flowret = ret;
5003 GST_OBJECT_UNLOCK (pad);
5005 if (*buffer == NULL)
5006 gst_buffer_unref (res_buf);
5010 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5014 /* must be called with pad object lock */
5015 static GstFlowReturn
5016 store_sticky_event (GstPad * pad, GstEvent * event)
5021 gboolean res = FALSE;
5022 const gchar *name = NULL;
5023 gboolean insert = TRUE;
5025 type = GST_EVENT_TYPE (event);
5027 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5028 * otherwise they can be dropped and nothing would ever resend them.
5029 * Only do that for activated pads though, everything else is a bug!
5031 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5032 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5033 || type == GST_EVENT_EOS))))
5036 /* Unset the EOS flag when received STREAM_START event, so pad can
5037 * store sticky event and then push it later */
5038 if (type == GST_EVENT_STREAM_START) {
5039 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5040 remove_event_by_type (pad, GST_EVENT_EOS);
5041 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5042 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5045 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5048 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5049 name = gst_structure_get_name (gst_event_get_structure (event));
5051 events = pad->priv->events;
5054 for (i = 0; i < len; i++) {
5055 PadEvent *ev = &g_array_index (events, PadEvent, i);
5057 if (ev->event == NULL)
5060 if (type == GST_EVENT_TYPE (ev->event)) {
5061 /* matching types, check matching name if needed */
5062 if (name && !gst_event_has_name (ev->event, name))
5066 if ((res = gst_event_replace (&ev->event, event)))
5067 ev->received = FALSE;
5073 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5074 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5075 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5076 * storing the sticky ordered we can check that this is respected. */
5077 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5078 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5080 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5081 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5082 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5083 gst_event_type_get_name (type));
5089 ev.event = gst_event_ref (event);
5090 ev.received = FALSE;
5091 g_array_insert_val (events, i, ev);
5096 pad->priv->events_cookie++;
5097 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5099 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5101 switch (GST_EVENT_TYPE (event)) {
5102 case GST_EVENT_CAPS:
5103 GST_OBJECT_UNLOCK (pad);
5105 GST_DEBUG_OBJECT (pad, "notify caps");
5106 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5108 GST_OBJECT_LOCK (pad);
5114 if (type == GST_EVENT_EOS) {
5115 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5116 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5119 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5124 GST_DEBUG_OBJECT (pad, "pad is flushing");
5125 return GST_FLOW_FLUSHING;
5129 GST_DEBUG_OBJECT (pad, "pad is EOS");
5130 return GST_FLOW_EOS;
5135 * gst_pad_store_sticky_event:
5137 * @event: (transfer none): a #GstEvent
5139 * Store the sticky @event on @pad
5141 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5142 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5147 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5151 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5152 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5154 GST_OBJECT_LOCK (pad);
5155 ret = store_sticky_event (pad, event);
5156 GST_OBJECT_UNLOCK (pad);
5162 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5164 PushStickyData *data = user_data;
5166 /* Forward all sticky events before our current one that are pending */
5167 if (ev->event != data->event
5168 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5169 return push_sticky (pad, ev, data);
5174 /* should be called with pad LOCK */
5175 static GstFlowReturn
5176 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5177 GstPadProbeType type)
5181 GstEventType event_type;
5183 /* pass the adjusted event on. We need to do this even if
5184 * there is no peer pad because of the probes. */
5185 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5187 /* Two checks to be made:
5188 * . (un)set the FLUSHING flag for flushing events,
5189 * . handle pad blocking */
5190 event_type = GST_EVENT_TYPE (event);
5191 switch (event_type) {
5192 case GST_EVENT_FLUSH_START:
5193 GST_PAD_SET_FLUSHING (pad);
5195 GST_PAD_BLOCK_BROADCAST (pad);
5196 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5198 case GST_EVENT_FLUSH_STOP:
5199 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5202 GST_PAD_UNSET_FLUSHING (pad);
5204 /* Remove sticky EOS events */
5205 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5206 remove_event_by_type (pad, GST_EVENT_EOS);
5207 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5208 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5209 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5210 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5212 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5216 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5219 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5220 * checked already or this is called as part of pushing sticky events,
5221 * in which case we still want to forward the EOS event downstream.
5224 switch (GST_EVENT_TYPE (event)) {
5225 case GST_EVENT_RECONFIGURE:
5226 if (GST_PAD_IS_SINK (pad))
5227 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5232 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5233 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5238 /* send probes after modifying the events above */
5239 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5241 /* recheck sticky events because the probe might have cause a relink */
5242 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5243 && (GST_EVENT_IS_SERIALIZED (event)
5244 || GST_EVENT_IS_STICKY (event))) {
5245 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5246 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5248 /* Push all sticky events before our current one
5249 * that have changed */
5250 events_foreach (pad, sticky_changed, &data);
5253 /* now check the peer pad */
5254 peerpad = GST_PAD_PEER (pad);
5255 if (peerpad == NULL)
5258 gst_object_ref (peerpad);
5260 GST_OBJECT_UNLOCK (pad);
5262 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5263 event, gst_event_type_get_name (event_type), peerpad);
5265 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5267 /* Note: we gave away ownership of the event at this point but we can still
5268 * print the old pointer */
5269 GST_LOG_OBJECT (pad,
5270 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5271 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5273 gst_object_unref (peerpad);
5275 GST_OBJECT_LOCK (pad);
5277 if (pad->priv->using == 0) {
5278 /* pad is not active anymore, trigger idle callbacks */
5279 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5280 idle_probe_stopped, ret);
5284 /* ERROR handling */
5287 GST_DEBUG_OBJECT (pad, "We're flushing");
5288 gst_event_unref (event);
5289 return GST_FLOW_FLUSHING;
5293 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5294 gst_event_unref (event);
5295 return GST_FLOW_FLUSHING;
5299 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5300 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5301 gst_event_unref (event);
5304 case GST_FLOW_CUSTOM_SUCCESS_1:
5305 GST_DEBUG_OBJECT (pad, "handled event");
5307 case GST_FLOW_CUSTOM_SUCCESS:
5308 GST_DEBUG_OBJECT (pad, "dropped event");
5311 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5318 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5319 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5320 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5321 gst_event_unref (event);
5323 /* unlinked pads should not influence latency configuration */
5324 if (event_type == GST_EVENT_LATENCY)
5327 return GST_FLOW_NOT_LINKED;
5331 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5337 * gst_pad_push_event:
5338 * @pad: a #GstPad to push the event to.
5339 * @event: (transfer full): the #GstEvent to send to the pad.
5341 * Sends the event to the peer of the given pad. This function is
5342 * mainly used by elements to send events to their peer
5345 * This function takes ownership of the provided event so you should
5346 * gst_event_ref() it if you want to reuse the event after this call.
5348 * Returns: %TRUE if the event was handled.
5353 gst_pad_push_event (GstPad * pad, GstEvent * event)
5355 gboolean res = FALSE;
5356 GstPadProbeType type;
5357 gboolean sticky, serialized;
5359 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5360 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5362 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5364 if (GST_PAD_IS_SRC (pad)) {
5365 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5366 goto wrong_direction;
5367 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5368 } else if (GST_PAD_IS_SINK (pad)) {
5369 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5370 goto wrong_direction;
5371 /* events pushed on sinkpad never are sticky */
5372 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5374 goto unknown_direction;
5376 GST_OBJECT_LOCK (pad);
5377 sticky = GST_EVENT_IS_STICKY (event);
5378 serialized = GST_EVENT_IS_SERIALIZED (event);
5381 /* srcpad sticky events are stored immediately, the received flag is set
5382 * to FALSE and will be set to TRUE when we can successfully push the
5383 * event to the peer pad */
5384 switch (store_sticky_event (pad, event)) {
5385 case GST_FLOW_FLUSHING:
5393 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5394 /* all serialized or sticky events on the srcpad trigger push of
5396 res = (check_sticky (pad, event) == GST_FLOW_OK);
5401 /* other events are pushed right away */
5402 ret = gst_pad_push_event_unchecked (pad, event, type);
5403 /* dropped events by a probe are not an error */
5404 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5405 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5407 /* Errors in sticky event pushing are no problem and ignored here
5408 * as they will cause more meaningful errors during data flow.
5409 * For EOS events, that are not followed by data flow, we still
5410 * return FALSE here though.
5412 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5414 gst_event_unref (event);
5416 GST_OBJECT_UNLOCK (pad);
5418 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5421 /* ERROR handling */
5424 g_warning ("pad %s:%s pushing %s event in wrong direction",
5425 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5426 gst_event_unref (event);
5431 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5432 gst_event_unref (event);
5437 GST_DEBUG_OBJECT (pad, "We're flushing");
5438 GST_OBJECT_UNLOCK (pad);
5439 gst_event_unref (event);
5444 GST_DEBUG_OBJECT (pad, "We're EOS");
5445 GST_OBJECT_UNLOCK (pad);
5446 gst_event_unref (event);
5450 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5454 /* Check if we can call the event function with the given event */
5455 static GstFlowReturn
5456 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5460 switch (GST_EVENT_TYPE (event)) {
5461 case GST_EVENT_CAPS:
5463 /* backwards compatibility mode for caps */
5464 gst_event_parse_caps (event, &caps);
5466 if (!gst_pad_query_accept_caps (pad, caps))
5478 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5479 "caps %" GST_PTR_FORMAT " not accepted", caps);
5480 return GST_FLOW_NOT_NEGOTIATED;
5484 static GstFlowReturn
5485 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5486 GstPadProbeType type)
5489 GstEventType event_type;
5490 gboolean serialized, need_unlock = FALSE, sticky;
5491 GstPadEventFunction eventfunc;
5492 GstPadEventFullFunction eventfullfunc = NULL;
5495 GST_OBJECT_LOCK (pad);
5497 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5499 if (GST_PAD_IS_SINK (pad))
5500 serialized = GST_EVENT_IS_SERIALIZED (event);
5503 sticky = GST_EVENT_IS_STICKY (event);
5504 event_type = GST_EVENT_TYPE (event);
5505 switch (event_type) {
5506 case GST_EVENT_FLUSH_START:
5507 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5508 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5510 /* can't even accept a flush begin event when flushing */
5511 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5514 GST_PAD_SET_FLUSHING (pad);
5515 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5516 GST_PAD_BLOCK_BROADCAST (pad);
5517 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5519 case GST_EVENT_FLUSH_STOP:
5520 /* we can't accept flush-stop on inactive pads else the flushing flag
5521 * would be cleared and it would look like the pad can accept data.
5522 * Also, some elements restart a streaming thread in flush-stop which we
5523 * can't allow on inactive pads */
5524 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5527 GST_PAD_UNSET_FLUSHING (pad);
5528 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5529 /* Remove pending EOS events */
5530 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5531 remove_event_by_type (pad, GST_EVENT_EOS);
5532 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5533 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5534 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5535 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5537 GST_OBJECT_UNLOCK (pad);
5538 /* grab stream lock */
5539 GST_PAD_STREAM_LOCK (pad);
5541 GST_OBJECT_LOCK (pad);
5542 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5545 case GST_EVENT_RECONFIGURE:
5546 if (GST_PAD_IS_SRC (pad))
5547 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5549 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5550 "have event type %" GST_PTR_FORMAT, event);
5552 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5555 switch (event_type) {
5556 case GST_EVENT_STREAM_START:
5557 /* Remove sticky EOS events */
5558 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5559 remove_event_by_type (pad, GST_EVENT_EOS);
5560 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5561 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5568 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5571 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5572 GST_OBJECT_UNLOCK (pad);
5573 GST_PAD_STREAM_LOCK (pad);
5575 GST_OBJECT_LOCK (pad);
5576 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5579 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5585 /* now do the probe */
5587 type | GST_PAD_PROBE_TYPE_PUSH |
5588 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5590 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5592 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5593 eventfunc = GST_PAD_EVENTFUNC (pad);
5594 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5597 ACQUIRE_PARENT (pad, parent, no_parent);
5598 GST_OBJECT_UNLOCK (pad);
5600 ret = pre_eventfunc_check (pad, event);
5601 if (G_UNLIKELY (ret != GST_FLOW_OK))
5602 goto precheck_failed;
5605 gst_event_ref (event);
5607 if (eventfullfunc) {
5608 ret = eventfullfunc (pad, parent, event);
5609 } else if (eventfunc (pad, parent, event)) {
5612 /* something went wrong */
5613 switch (event_type) {
5614 case GST_EVENT_CAPS:
5615 ret = GST_FLOW_NOT_NEGOTIATED;
5618 ret = GST_FLOW_ERROR;
5622 RELEASE_PARENT (parent);
5624 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5627 if (ret == GST_FLOW_OK) {
5628 GST_OBJECT_LOCK (pad);
5629 /* after the event function accepted the event, we can store the sticky
5630 * event on the pad */
5631 switch (store_sticky_event (pad, event)) {
5632 case GST_FLOW_FLUSHING:
5639 GST_OBJECT_UNLOCK (pad);
5641 gst_event_unref (event);
5645 GST_PAD_STREAM_UNLOCK (pad);
5649 /* ERROR handling */
5652 GST_OBJECT_UNLOCK (pad);
5654 GST_PAD_STREAM_UNLOCK (pad);
5655 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5656 "Received event on flushing pad. Discarding");
5657 gst_event_unref (event);
5658 return GST_FLOW_FLUSHING;
5662 GST_OBJECT_UNLOCK (pad);
5664 GST_PAD_STREAM_UNLOCK (pad);
5665 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5666 "Received flush-stop on inactive pad. Discarding");
5667 gst_event_unref (event);
5668 return GST_FLOW_FLUSHING;
5672 GST_OBJECT_UNLOCK (pad);
5674 GST_PAD_STREAM_UNLOCK (pad);
5675 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5676 "Received event on EOS pad. Discarding");
5677 gst_event_unref (event);
5678 return GST_FLOW_EOS;
5682 GST_OBJECT_UNLOCK (pad);
5684 GST_PAD_STREAM_UNLOCK (pad);
5685 /* Only unref if unhandled */
5686 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5687 gst_event_unref (event);
5690 case GST_FLOW_CUSTOM_SUCCESS_1:
5691 case GST_FLOW_CUSTOM_SUCCESS:
5692 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5696 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5703 g_warning ("pad %s:%s has no event handler, file a bug.",
5704 GST_DEBUG_PAD_NAME (pad));
5705 GST_OBJECT_UNLOCK (pad);
5707 GST_PAD_STREAM_UNLOCK (pad);
5708 gst_event_unref (event);
5709 return GST_FLOW_NOT_SUPPORTED;
5713 GST_DEBUG_OBJECT (pad, "no parent");
5714 GST_OBJECT_UNLOCK (pad);
5716 GST_PAD_STREAM_UNLOCK (pad);
5717 gst_event_unref (event);
5718 return GST_FLOW_FLUSHING;
5722 GST_DEBUG_OBJECT (pad, "pre event check failed");
5723 RELEASE_PARENT (parent);
5725 GST_PAD_STREAM_UNLOCK (pad);
5726 gst_event_unref (event);
5732 * gst_pad_send_event:
5733 * @pad: a #GstPad to send the event to.
5734 * @event: (transfer full): the #GstEvent to send to the pad.
5736 * Sends the event to the pad. This function can be used
5737 * by applications to send events in the pipeline.
5739 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5740 * sink pad, @event should be a downstream event. For example, you would not
5741 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5742 * Furthermore, some downstream events have to be serialized with data flow,
5743 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5744 * the event needs to be serialized with data flow, this function will take the
5745 * pad's stream lock while calling its event function.
5747 * To find out whether an event type is upstream, downstream, or downstream and
5748 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5749 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5750 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5751 * plugin doesn't need to bother itself with this information; the core handles
5752 * all necessary locks and checks.
5754 * This function takes ownership of the provided event so you should
5755 * gst_event_ref() it if you want to reuse the event after this call.
5757 * Returns: %TRUE if the event was handled.
5760 gst_pad_send_event (GstPad * pad, GstEvent * event)
5763 GstPadProbeType type;
5765 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5766 g_return_val_if_fail (event != NULL, FALSE);
5768 if (GST_PAD_IS_SINK (pad)) {
5769 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5770 goto wrong_direction;
5771 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5772 } else if (GST_PAD_IS_SRC (pad)) {
5773 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5774 goto wrong_direction;
5775 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5777 goto unknown_direction;
5779 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5786 /* ERROR handling */
5789 g_warning ("pad %s:%s sending %s event in wrong direction",
5790 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5791 gst_event_unref (event);
5796 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5797 gst_event_unref (event);
5803 * gst_pad_set_element_private:
5804 * @pad: the #GstPad to set the private data of.
5805 * @priv: The private data to attach to the pad.
5807 * Set the given private data gpointer on the pad.
5808 * This function can only be used by the element that owns the pad.
5809 * No locking is performed in this function.
5812 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5814 pad->element_private = priv;
5818 * gst_pad_get_element_private:
5819 * @pad: the #GstPad to get the private data of.
5821 * Gets the private data of a pad.
5822 * No locking is performed in this function.
5824 * Returns: (transfer none): a #gpointer to the private data.
5827 gst_pad_get_element_private (GstPad * pad)
5829 return pad->element_private;
5833 * gst_pad_get_sticky_event:
5834 * @pad: the #GstPad to get the event from.
5835 * @event_type: the #GstEventType that should be retrieved.
5836 * @idx: the index of the event
5838 * Returns a new reference of the sticky event of type @event_type
5841 * Returns: (transfer full) (nullable): a #GstEvent of type
5842 * @event_type or %NULL when no event of @event_type was on
5843 * @pad. Unref after usage.
5846 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5848 GstEvent *event = NULL;
5851 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5852 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5854 GST_OBJECT_LOCK (pad);
5855 ev = find_event_by_type (pad, event_type, idx);
5856 if (ev && (event = ev->event))
5857 gst_event_ref (event);
5858 GST_OBJECT_UNLOCK (pad);
5865 GstPadStickyEventsForeachFunction func;
5870 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5872 ForeachDispatch *data = user_data;
5873 gboolean ret = TRUE;
5876 GST_OBJECT_UNLOCK (pad);
5878 ret = data->func (pad, &ev->event, data->user_data);
5880 GST_OBJECT_LOCK (pad);
5887 * gst_pad_sticky_events_foreach:
5888 * @pad: the #GstPad that should be used for iteration.
5889 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5890 * should be called for every event.
5891 * @user_data: (closure): the optional user data.
5893 * Iterates all sticky events on @pad and calls @foreach_func for every
5894 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5897 gst_pad_sticky_events_foreach (GstPad * pad,
5898 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5900 ForeachDispatch data;
5902 g_return_if_fail (GST_IS_PAD (pad));
5903 g_return_if_fail (foreach_func != NULL);
5905 data.func = foreach_func;
5906 data.user_data = user_data;
5908 GST_OBJECT_LOCK (pad);
5909 events_foreach (pad, foreach_dispatch_function, &data);
5910 GST_OBJECT_UNLOCK (pad);
5914 do_stream_status (GstPad * pad, GstStreamStatusType type,
5915 GThread * thread, GstTask * task)
5919 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5921 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5922 if (GST_IS_ELEMENT (parent)) {
5923 GstMessage *message;
5924 GValue value = { 0 };
5926 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5927 gchar *tname, *ename, *pname;
5929 /* create a good task name */
5930 ename = gst_element_get_name (parent);
5931 pname = gst_pad_get_name (pad);
5932 tname = g_strdup_printf ("%s:%s", ename, pname);
5936 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5940 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5943 g_value_init (&value, GST_TYPE_TASK);
5944 g_value_set_object (&value, task);
5945 gst_message_set_stream_status_object (message, &value);
5946 g_value_unset (&value);
5948 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5949 gst_element_post_message (parent, message);
5951 gst_object_unref (parent);
5956 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5958 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5963 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5965 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5970 * gst_pad_start_task:
5971 * @pad: the #GstPad to start the task of
5972 * @func: the task function to call
5973 * @user_data: user data passed to the task function
5974 * @notify: called when @user_data is no longer referenced
5976 * Starts a task that repeatedly calls @func with @user_data. This function
5977 * is mostly used in pad activation functions to start the dataflow.
5978 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5979 * before @func is called.
5981 * Returns: a %TRUE if the task could be started.
5984 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5985 GDestroyNotify notify)
5990 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5991 g_return_val_if_fail (func != NULL, FALSE);
5993 GST_DEBUG_OBJECT (pad, "start task");
5995 GST_OBJECT_LOCK (pad);
5996 task = GST_PAD_TASK (pad);
5998 task = gst_task_new (func, user_data, notify);
5999 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6000 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6001 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6002 GST_INFO_OBJECT (pad, "created task %p", task);
6003 GST_PAD_TASK (pad) = task;
6004 gst_object_ref (task);
6005 /* release lock to post the message */
6006 GST_OBJECT_UNLOCK (pad);
6008 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6010 gst_object_unref (task);
6012 GST_OBJECT_LOCK (pad);
6013 /* nobody else is supposed to have changed the pad now */
6014 if (GST_PAD_TASK (pad) != task)
6015 goto concurrent_stop;
6017 res = gst_task_set_state (task, GST_TASK_STARTED);
6018 GST_OBJECT_UNLOCK (pad);
6025 GST_OBJECT_UNLOCK (pad);
6031 * gst_pad_pause_task:
6032 * @pad: the #GstPad to pause the task of
6034 * Pause the task of @pad. This function will also wait until the
6035 * function executed by the task is finished if this function is not
6036 * called from the task function.
6038 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6042 gst_pad_pause_task (GstPad * pad)
6047 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6049 GST_DEBUG_OBJECT (pad, "pause task");
6051 GST_OBJECT_LOCK (pad);
6052 task = GST_PAD_TASK (pad);
6055 res = gst_task_set_state (task, GST_TASK_PAUSED);
6056 GST_OBJECT_UNLOCK (pad);
6058 /* wait for task function to finish, this lock is recursive so it does nothing
6059 * when the pause is called from the task itself */
6060 GST_PAD_STREAM_LOCK (pad);
6061 GST_PAD_STREAM_UNLOCK (pad);
6067 GST_DEBUG_OBJECT (pad, "pad has no task");
6068 GST_OBJECT_UNLOCK (pad);
6074 * gst_pad_stop_task:
6075 * @pad: the #GstPad to stop the task of
6077 * Stop the task of @pad. This function will also make sure that the
6078 * function executed by the task will effectively stop if not called
6079 * from the GstTaskFunction.
6081 * This function will deadlock if called from the GstTaskFunction of
6082 * the task. Use gst_task_pause() instead.
6084 * Regardless of whether the pad has a task, the stream lock is acquired and
6085 * released so as to ensure that streaming through this pad has finished.
6087 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6090 gst_pad_stop_task (GstPad * pad)
6095 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6097 GST_DEBUG_OBJECT (pad, "stop task");
6099 GST_OBJECT_LOCK (pad);
6100 task = GST_PAD_TASK (pad);
6103 GST_PAD_TASK (pad) = NULL;
6104 res = gst_task_set_state (task, GST_TASK_STOPPED);
6105 GST_OBJECT_UNLOCK (pad);
6107 GST_PAD_STREAM_LOCK (pad);
6108 GST_PAD_STREAM_UNLOCK (pad);
6110 if (!gst_task_join (task))
6113 gst_object_unref (task);
6119 GST_DEBUG_OBJECT (pad, "no task");
6120 GST_OBJECT_UNLOCK (pad);
6122 GST_PAD_STREAM_LOCK (pad);
6123 GST_PAD_STREAM_UNLOCK (pad);
6125 /* this is not an error */
6130 /* this is bad, possibly the application tried to join the task from
6131 * the task's thread. We install the task again so that it will be stopped
6132 * again from the right thread next time hopefully. */
6133 GST_OBJECT_LOCK (pad);
6134 GST_DEBUG_OBJECT (pad, "join failed");
6135 /* we can only install this task if there was no other task */
6136 if (GST_PAD_TASK (pad) == NULL)
6137 GST_PAD_TASK (pad) = task;
6138 GST_OBJECT_UNLOCK (pad);
6145 * gst_pad_probe_info_get_event:
6146 * @info: a #GstPadProbeInfo
6148 * Returns: (transfer none): The #GstEvent from the probe
6152 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6154 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6155 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6157 return GST_PAD_PROBE_INFO_EVENT (info);
6162 * gst_pad_probe_info_get_query:
6163 * @info: a #GstPadProbeInfo
6165 * Returns: (transfer none): The #GstQuery from the probe
6169 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6171 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6172 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6174 return GST_PAD_PROBE_INFO_QUERY (info);
6178 * gst_pad_probe_info_get_buffer:
6179 * @info: a #GstPadProbeInfo
6181 * Returns: (transfer none): The #GstBuffer from the probe
6185 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6187 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6189 return GST_PAD_PROBE_INFO_BUFFER (info);
6193 * gst_pad_probe_info_get_buffer_list:
6194 * @info: a #GstPadProbeInfo
6196 * Returns: (transfer none): The #GstBufferList from the probe
6200 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6202 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6204 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6208 * gst_pad_get_last_flow_return:
6211 * Gets the #GstFlowReturn return from the last data passed by this pad.
6216 gst_pad_get_last_flow_return (GstPad * pad)
6220 GST_OBJECT_LOCK (pad);
6221 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6222 GST_OBJECT_UNLOCK (pad);