2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 * @short_description: Object contained by elements that allows links to
27 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
29 * A #GstElement is linked to other elements via "pads", which are extremely
30 * light-weight generic link points.
32 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
37 * happens when the element is created but it can also happen dynamically based
38 * on the data that the element is processing or based on the pads that the
39 * application requests.
41 * Pads without pad templates can be created with gst_pad_new(),
42 * which takes a direction and a name as an argument. If the name is %NULL,
43 * then a guaranteed unique name will be assigned to it.
45 * A #GstElement creating a pad will typically use the various
46 * gst_pad_set_*_function() calls to register callbacks for events, queries or
47 * dataflow on the pads.
49 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
51 * After two pads are retrieved from an element by gst_element_get_static_pad(),
52 * the pads can be linked with gst_pad_link(). (For quick links,
53 * you can also use gst_element_link(), which will make the obvious
54 * link for you if it's straightforward.). Pads can be unlinked again with
55 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
58 * Before dataflow is possible on the pads, they need to be activated with
59 * gst_pad_set_active().
61 * gst_pad_query() and gst_pad_peer_query() can be used to query various
62 * properties of the pad and the stream.
64 * To send a #GstEvent on a pad, use gst_pad_send_event() and
65 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
66 * after they pass on the pad they can be queried later with
67 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
68 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
69 * functions to query the current sticky CAPS event on a pad.
71 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
72 * or pull in a buffer.
74 * The dataflow, events and queries that happen on a pad can be monitored with
75 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
76 * can be used to check if a block probe is installed on the pad.
77 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
78 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
79 * and unblock blocking probes if any.
81 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
82 * offset will be applied to the running_time of all data passing over the pad.
83 * gst_pad_set_offset() can be used to change the offset.
85 * Convenience functions exist to start, pause and stop the task on a pad with
86 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
90 #include "gst_private.h"
93 #include "gstpadtemplate.h"
94 #include "gstenumtypes.h"
98 #include "gsttracerutils.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
124 #define GST_PAD_GET_PRIVATE(obj) \
125 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
127 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
129 /* we have a pending and an active event on the pad. On source pads only the
130 * active event is used. On sinkpads, events are copied to the pending entry and
131 * moved to the active event when the eventfunc returned %TRUE. */
138 struct _GstPadPrivate
145 guint probe_list_cookie;
148 /* counter of how many idle probes are running directly from the add_probe
149 * call. Used to block any data flowing in the pad while the idle callback
150 * Doesn't finish its work */
153 /* conditional and variable used to ensure pads only get (de)activated
154 * by a single thread at a time. Protected by the object lock */
155 GCond activation_cond;
156 gboolean in_activation;
165 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
166 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
167 (((GstPad *)(p))->priv->idle_running > 0)
172 GstPadProbeInfo *info;
180 static void gst_pad_dispose (GObject * object);
181 static void gst_pad_finalize (GObject * object);
182 static void gst_pad_set_property (GObject * object, guint prop_id,
183 const GValue * value, GParamSpec * pspec);
184 static void gst_pad_get_property (GObject * object, guint prop_id,
185 GValue * value, GParamSpec * pspec);
187 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
188 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
189 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
190 GstObject * parent, GstBufferList * list);
192 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
194 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
195 GstEvent * event, GstPadProbeType type);
197 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
198 GstPadMode mode, gboolean active);
200 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
202 static GParamSpec *pspec_caps = NULL;
204 /* quarks for probe signals */
205 static GQuark buffer_quark;
206 static GQuark buffer_list_quark;
207 static GQuark event_quark;
216 static GstFlowQuarks flow_quarks[] = {
217 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
218 {GST_FLOW_OK, "ok", 0},
219 {GST_FLOW_NOT_LINKED, "not-linked", 0},
220 {GST_FLOW_FLUSHING, "flushing", 0},
221 {GST_FLOW_EOS, "eos", 0},
222 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
223 {GST_FLOW_ERROR, "error", 0},
224 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
225 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
230 * @ret: a #GstFlowReturn to get the name of.
232 * Gets a string representing the given flow return.
234 * Returns: a static string with the name of the flow return.
237 gst_flow_get_name (GstFlowReturn ret)
241 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
243 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
244 if (ret == flow_quarks[i].ret)
245 return flow_quarks[i].name;
252 * @ret: a #GstFlowReturn to get the quark of.
254 * Get the unique quark for the given GstFlowReturn.
256 * Returns: the quark associated with the flow return or 0 if an
257 * invalid return was specified.
260 gst_flow_to_quark (GstFlowReturn ret)
264 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
266 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
267 if (ret == flow_quarks[i].ret)
268 return flow_quarks[i].quark;
274 * gst_pad_link_get_name:
275 * @ret: a #GstPadLinkReturn to get the name of.
277 * Gets a string representing the given pad-link return.
279 * Returns: a static string with the name of the pad-link return.
284 gst_pad_link_get_name (GstPadLinkReturn ret)
287 case GST_PAD_LINK_OK:
289 case GST_PAD_LINK_WRONG_HIERARCHY:
290 return "wrong hierarchy";
291 case GST_PAD_LINK_WAS_LINKED:
293 case GST_PAD_LINK_WRONG_DIRECTION:
294 return "wrong direction";
295 case GST_PAD_LINK_NOFORMAT:
296 return "no common format";
297 case GST_PAD_LINK_NOSCHED:
298 return "incompatible scheduling";
299 case GST_PAD_LINK_REFUSED:
302 g_return_val_if_reached ("unknown");
309 buffer_quark = g_quark_from_static_string ("buffer"); \
310 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
311 event_quark = g_quark_from_static_string ("event"); \
313 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
314 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
317 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
318 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
321 #define gst_pad_parent_class parent_class
322 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
325 gst_pad_class_init (GstPadClass * klass)
327 GObjectClass *gobject_class;
328 GstObjectClass *gstobject_class;
330 gobject_class = G_OBJECT_CLASS (klass);
331 gstobject_class = GST_OBJECT_CLASS (klass);
333 g_type_class_add_private (klass, sizeof (GstPadPrivate));
335 gobject_class->dispose = gst_pad_dispose;
336 gobject_class->finalize = gst_pad_finalize;
337 gobject_class->set_property = gst_pad_set_property;
338 gobject_class->get_property = gst_pad_get_property;
342 * @pad: the pad that emitted the signal
343 * @peer: the peer pad that has been connected
345 * Signals that a pad has been linked to the peer pad.
347 gst_pad_signals[PAD_LINKED] =
348 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
349 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
350 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
353 * @pad: the pad that emitted the signal
354 * @peer: the peer pad that has been disconnected
356 * Signals that a pad has been unlinked from the peer pad.
358 gst_pad_signals[PAD_UNLINKED] =
359 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
360 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
361 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
363 pspec_caps = g_param_spec_boxed ("caps", "Caps",
364 "The capabilities of the pad", GST_TYPE_CAPS,
365 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
368 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
369 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
370 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
371 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
373 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
374 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
375 g_param_spec_object ("template", "Template",
376 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 * The offset that will be applied to the running time of the pad.
386 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
387 g_param_spec_int64 ("offset", "Offset",
388 "The running time offset of the pad", 0, G_MAXINT64, 0,
389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 gstobject_class->path_string_separator = ".";
393 /* Register common function pointer descriptions */
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
396 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
397 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
398 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
402 gst_pad_init (GstPad * pad)
404 pad->priv = GST_PAD_GET_PRIVATE (pad);
406 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
408 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
409 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
410 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
411 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
412 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
414 GST_PAD_SET_FLUSHING (pad);
416 g_rec_mutex_init (&pad->stream_rec_lock);
418 g_cond_init (&pad->block_cond);
420 g_hook_list_init (&pad->probes, sizeof (GstProbe));
422 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
423 pad->priv->events_cookie = 0;
424 pad->priv->last_cookie = -1;
425 g_cond_init (&pad->priv->activation_cond);
427 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
430 /* called when setting the pad inactive. It removes all sticky events from
431 * the pad. must be called with object lock */
433 remove_events (GstPad * pad)
437 gboolean notify = FALSE;
439 events = pad->priv->events;
442 for (i = 0; i < len; i++) {
443 PadEvent *ev = &g_array_index (events, PadEvent, i);
444 GstEvent *event = ev->event;
448 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
451 gst_event_unref (event);
454 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
455 g_array_set_size (events, 0);
456 pad->priv->events_cookie++;
459 GST_OBJECT_UNLOCK (pad);
461 GST_DEBUG_OBJECT (pad, "notify caps");
462 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
464 GST_OBJECT_LOCK (pad);
468 /* should be called with object lock */
470 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
476 events = pad->priv->events;
479 for (i = 0; i < len; i++) {
480 ev = &g_array_index (events, PadEvent, i);
481 if (ev->event == NULL)
484 if (GST_EVENT_TYPE (ev->event) == type) {
488 } else if (GST_EVENT_TYPE (ev->event) > type) {
497 /* should be called with OBJECT lock */
499 find_event (GstPad * pad, GstEvent * event)
505 events = pad->priv->events;
508 for (i = 0; i < len; i++) {
509 ev = &g_array_index (events, PadEvent, i);
510 if (event == ev->event)
512 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
520 /* should be called with OBJECT lock */
522 remove_event_by_type (GstPad * pad, GstEventType type)
528 events = pad->priv->events;
533 ev = &g_array_index (events, PadEvent, i);
534 if (ev->event == NULL)
537 if (GST_EVENT_TYPE (ev->event) > type)
539 else if (GST_EVENT_TYPE (ev->event) != type)
542 gst_event_unref (ev->event);
543 g_array_remove_index (events, i);
545 pad->priv->events_cookie++;
553 /* check all events on srcpad against those on sinkpad. All events that are not
554 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
555 * srcpad so that the events will be sent next time */
556 /* should be called with srcpad and sinkpad LOCKS */
558 schedule_events (GstPad * srcpad, GstPad * sinkpad)
563 gboolean pending = FALSE;
565 events = srcpad->priv->events;
568 for (i = 0; i < len; i++) {
569 ev = &g_array_index (events, PadEvent, i);
570 if (ev->event == NULL)
573 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
574 ev->received = FALSE;
579 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
582 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
585 /* should be called with pad LOCK */
587 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
594 events = pad->priv->events;
597 cookie = pad->priv->events_cookie;
601 PadEvent *ev, ev_ret;
603 ev = &g_array_index (events, PadEvent, i);
604 if (G_UNLIKELY (ev->event == NULL))
607 /* take aditional ref, func might release the lock */
608 ev_ret.event = gst_event_ref (ev->event);
609 ev_ret.received = ev->received;
611 ret = func (pad, &ev_ret, user_data);
613 /* recheck the cookie, lock might have been released and the list could have
615 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
616 if (G_LIKELY (ev_ret.event))
617 gst_event_unref (ev_ret.event);
621 /* store the received state */
622 ev->received = ev_ret.received;
624 /* if the event changed, we need to do something */
625 if (G_UNLIKELY (ev->event != ev_ret.event)) {
626 if (G_UNLIKELY (ev_ret.event == NULL)) {
627 /* function unreffed and set the event to NULL, remove it */
628 gst_event_unref (ev->event);
629 g_array_remove_index (events, i);
631 cookie = ++pad->priv->events_cookie;
634 /* function gave a new event for us */
635 gst_event_take (&ev->event, ev_ret.event);
638 /* just unref, nothing changed */
639 gst_event_unref (ev_ret.event);
648 /* should be called with LOCK */
650 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
654 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
655 GST_STIME_ARGS (pad->offset));
657 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
660 g_assert (!upstream);
662 /* copy segment values */
663 gst_event_copy_segment (event, &segment);
664 gst_event_unref (event);
666 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
667 event = gst_event_new_segment (&segment);
670 event = gst_event_make_writable (event);
671 offset = gst_event_get_running_time_offset (event);
673 offset -= pad->offset;
675 offset += pad->offset;
676 gst_event_set_running_time_offset (event, offset);
681 static inline GstEvent *
682 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
684 if (G_UNLIKELY (pad->offset != 0))
685 return _apply_pad_offset (pad, event, upstream);
690 /* should be called with the OBJECT_LOCK */
692 get_pad_caps (GstPad * pad)
694 GstCaps *caps = NULL;
697 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
699 gst_event_parse_caps (ev->event, &caps);
705 gst_pad_dispose (GObject * object)
707 GstPad *pad = GST_PAD_CAST (object);
710 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
712 /* unlink the peer pad */
713 if ((peer = gst_pad_get_peer (pad))) {
714 /* window for MT unsafeness, someone else could unlink here
715 * and then we call unlink with wrong pads. The unlink
716 * function would catch this and safely return failed. */
717 if (GST_PAD_IS_SRC (pad))
718 gst_pad_unlink (pad, peer);
720 gst_pad_unlink (peer, pad);
722 gst_object_unref (peer);
725 gst_pad_set_pad_template (pad, NULL);
727 GST_OBJECT_LOCK (pad);
729 GST_OBJECT_UNLOCK (pad);
731 g_hook_list_clear (&pad->probes);
733 G_OBJECT_CLASS (parent_class)->dispose (object);
737 gst_pad_finalize (GObject * object)
739 GstPad *pad = GST_PAD_CAST (object);
742 /* in case the task is still around, clean it up */
743 if ((task = GST_PAD_TASK (pad))) {
744 gst_task_join (task);
745 GST_PAD_TASK (pad) = NULL;
746 gst_object_unref (task);
749 if (pad->activatenotify)
750 pad->activatenotify (pad->activatedata);
751 if (pad->activatemodenotify)
752 pad->activatemodenotify (pad->activatemodedata);
754 pad->linknotify (pad->linkdata);
755 if (pad->unlinknotify)
756 pad->unlinknotify (pad->unlinkdata);
757 if (pad->chainnotify)
758 pad->chainnotify (pad->chaindata);
759 if (pad->chainlistnotify)
760 pad->chainlistnotify (pad->chainlistdata);
761 if (pad->getrangenotify)
762 pad->getrangenotify (pad->getrangedata);
763 if (pad->eventnotify)
764 pad->eventnotify (pad->eventdata);
765 if (pad->querynotify)
766 pad->querynotify (pad->querydata);
767 if (pad->iterintlinknotify)
768 pad->iterintlinknotify (pad->iterintlinkdata);
770 g_rec_mutex_clear (&pad->stream_rec_lock);
771 g_cond_clear (&pad->block_cond);
772 g_cond_clear (&pad->priv->activation_cond);
773 g_array_free (pad->priv->events, TRUE);
775 G_OBJECT_CLASS (parent_class)->finalize (object);
779 gst_pad_set_property (GObject * object, guint prop_id,
780 const GValue * value, GParamSpec * pspec)
782 g_return_if_fail (GST_IS_PAD (object));
785 case PAD_PROP_DIRECTION:
786 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
788 case PAD_PROP_TEMPLATE:
789 gst_pad_set_pad_template (GST_PAD_CAST (object),
790 (GstPadTemplate *) g_value_get_object (value));
792 case PAD_PROP_OFFSET:
793 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
796 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
802 gst_pad_get_property (GObject * object, guint prop_id,
803 GValue * value, GParamSpec * pspec)
805 g_return_if_fail (GST_IS_PAD (object));
809 GST_OBJECT_LOCK (object);
810 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
811 GST_OBJECT_UNLOCK (object);
813 case PAD_PROP_DIRECTION:
814 g_value_set_enum (value, GST_PAD_DIRECTION (object));
816 case PAD_PROP_TEMPLATE:
817 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
819 case PAD_PROP_OFFSET:
820 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
823 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
830 * @name: (allow-none): the name of the new pad.
831 * @direction: the #GstPadDirection of the pad.
833 * Creates a new pad with the given name in the given direction.
834 * If name is %NULL, a guaranteed unique name (across all pads)
836 * This function makes a copy of the name so you can safely free the name.
838 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
844 gst_pad_new (const gchar * name, GstPadDirection direction)
846 return g_object_new (GST_TYPE_PAD,
847 "name", name, "direction", direction, NULL);
851 * gst_pad_new_from_template:
852 * @templ: the pad template to use
853 * @name: (allow-none): the name of the pad
855 * Creates a new pad with the given name from the given template.
856 * If name is %NULL, a guaranteed unique name (across all pads)
858 * This function makes a copy of the name so you can safely free the name.
860 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
864 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
866 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
868 return g_object_new (GST_TYPE_PAD,
869 "name", name, "direction", templ->direction, "template", templ, NULL);
873 * gst_pad_new_from_static_template:
874 * @templ: the #GstStaticPadTemplate to use
875 * @name: the name of the pad
877 * Creates a new pad with the given name from the given static template.
878 * If name is %NULL, a guaranteed unique name (across all pads)
880 * This function makes a copy of the name so you can safely free the name.
882 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
886 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
890 GstPadTemplate *template;
892 template = gst_static_pad_template_get (templ);
893 pad = gst_pad_new_from_template (template, name);
894 gst_object_unref (template);
898 #define ACQUIRE_PARENT(pad, parent, label) \
900 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
901 gst_object_ref (parent); \
902 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
906 #define RELEASE_PARENT(parent) \
908 if (G_LIKELY (parent)) \
909 gst_object_unref (parent); \
913 * gst_pad_get_direction:
914 * @pad: a #GstPad to get the direction of.
916 * Gets the direction of the pad. The direction of the pad is
917 * decided at construction time so this function does not take
920 * Returns: the #GstPadDirection of the pad.
925 gst_pad_get_direction (GstPad * pad)
927 GstPadDirection result;
929 /* PAD_UNKNOWN is a little silly but we need some sort of
930 * error return value */
931 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
933 result = GST_PAD_DIRECTION (pad);
939 gst_pad_activate_default (GstPad * pad, GstObject * parent)
941 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
943 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
947 * gst_pad_mode_get_name:
948 * @mode: the pad mode
950 * Return the name of a pad mode, for use in debug messages mostly.
952 * Returns: short mnemonic for pad mode @mode
955 gst_pad_mode_get_name (GstPadMode mode)
958 case GST_PAD_MODE_NONE:
960 case GST_PAD_MODE_PUSH:
962 case GST_PAD_MODE_PULL:
970 /* Returns TRUE if pad wasn't already in the new_mode */
972 pre_activate (GstPad * pad, GstPadMode new_mode)
975 case GST_PAD_MODE_NONE:
976 GST_OBJECT_LOCK (pad);
977 while (G_UNLIKELY (pad->priv->in_activation))
978 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
979 if (new_mode == GST_PAD_MODE (pad)) {
980 GST_WARNING_OBJECT (pad,
981 "Pad is already in the process of being deactivated");
982 GST_OBJECT_UNLOCK (pad);
985 pad->priv->in_activation = TRUE;
986 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
987 GST_PAD_SET_FLUSHING (pad);
988 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
989 GST_PAD_MODE (pad) = new_mode;
990 /* unlock blocked pads so element can resume and stop */
991 GST_PAD_BLOCK_BROADCAST (pad);
992 GST_OBJECT_UNLOCK (pad);
994 case GST_PAD_MODE_PUSH:
995 case GST_PAD_MODE_PULL:
996 GST_OBJECT_LOCK (pad);
997 while (G_UNLIKELY (pad->priv->in_activation))
998 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
999 if (new_mode == GST_PAD_MODE (pad)) {
1000 GST_WARNING_OBJECT (pad,
1001 "Pad is already in the process of being activated");
1002 GST_OBJECT_UNLOCK (pad);
1005 pad->priv->in_activation = TRUE;
1006 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1007 gst_pad_mode_get_name (new_mode));
1008 GST_PAD_UNSET_FLUSHING (pad);
1009 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1010 GST_PAD_MODE (pad) = new_mode;
1011 if (GST_PAD_IS_SINK (pad)) {
1013 /* make sure the peer src pad sends us all events */
1014 if ((peer = GST_PAD_PEER (pad))) {
1015 gst_object_ref (peer);
1016 GST_OBJECT_UNLOCK (pad);
1018 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1019 GST_DEBUG_PAD_NAME (peer));
1021 GST_OBJECT_LOCK (peer);
1022 schedule_events (peer, NULL);
1023 GST_OBJECT_UNLOCK (peer);
1025 gst_object_unref (peer);
1027 GST_OBJECT_UNLOCK (pad);
1030 GST_OBJECT_UNLOCK (pad);
1038 post_activate (GstPad * pad, GstPadMode new_mode)
1041 case GST_PAD_MODE_NONE:
1042 /* ensures that streaming stops */
1043 GST_PAD_STREAM_LOCK (pad);
1044 GST_DEBUG_OBJECT (pad, "stopped streaming");
1045 GST_OBJECT_LOCK (pad);
1046 pad->priv->in_activation = FALSE;
1047 g_cond_broadcast (&pad->priv->activation_cond);
1048 remove_events (pad);
1049 GST_OBJECT_UNLOCK (pad);
1050 GST_PAD_STREAM_UNLOCK (pad);
1052 case GST_PAD_MODE_PUSH:
1053 case GST_PAD_MODE_PULL:
1054 GST_OBJECT_LOCK (pad);
1055 pad->priv->in_activation = FALSE;
1056 g_cond_broadcast (&pad->priv->activation_cond);
1057 GST_OBJECT_UNLOCK (pad);
1064 * gst_pad_set_active:
1065 * @pad: the #GstPad to activate or deactivate.
1066 * @active: whether or not the pad should be active.
1068 * Activates or deactivates the given pad.
1069 * Normally called from within core state change functions.
1071 * If @active, makes sure the pad is active. If it is already active, either in
1072 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1073 * function to perform the actual activation.
1075 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1076 * and a %FALSE argument.
1078 * Returns: %TRUE if the operation was successful.
1083 gst_pad_set_active (GstPad * pad, gboolean active)
1087 gboolean ret = FALSE;
1089 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1091 GST_OBJECT_LOCK (pad);
1092 old = GST_PAD_MODE (pad);
1093 ACQUIRE_PARENT (pad, parent, no_parent);
1094 GST_OBJECT_UNLOCK (pad);
1097 if (old == GST_PAD_MODE_NONE) {
1098 GST_DEBUG_OBJECT (pad, "activating pad from none");
1099 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1101 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1103 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1104 gst_pad_mode_get_name (old));
1108 if (old == GST_PAD_MODE_NONE) {
1109 GST_DEBUG_OBJECT (pad, "pad was inactive");
1112 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1113 gst_pad_mode_get_name (old));
1114 ret = activate_mode_internal (pad, parent, old, FALSE);
1116 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1120 RELEASE_PARENT (parent);
1122 if (G_UNLIKELY (!ret))
1130 GST_DEBUG_OBJECT (pad, "no parent");
1131 GST_OBJECT_UNLOCK (pad);
1136 GST_OBJECT_LOCK (pad);
1138 g_critical ("Failed to deactivate pad %s:%s, very bad",
1139 GST_DEBUG_PAD_NAME (pad));
1141 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1143 GST_OBJECT_UNLOCK (pad);
1149 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1152 gboolean res = FALSE;
1153 GstPadMode old, new;
1154 GstPadDirection dir;
1157 GST_OBJECT_LOCK (pad);
1158 old = GST_PAD_MODE (pad);
1159 dir = GST_PAD_DIRECTION (pad);
1160 GST_OBJECT_UNLOCK (pad);
1162 new = active ? mode : GST_PAD_MODE_NONE;
1167 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1168 /* pad was activate in the wrong direction, deactivate it
1169 * and reactivate it in the requested mode */
1170 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1171 gst_pad_mode_get_name (old));
1173 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1174 goto deactivate_failed;
1175 old = GST_PAD_MODE_NONE;
1179 case GST_PAD_MODE_PULL:
1181 if (dir == GST_PAD_SINK) {
1182 if ((peer = gst_pad_get_peer (pad))) {
1183 GST_DEBUG_OBJECT (pad, "calling peer");
1184 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1186 gst_object_unref (peer);
1188 /* there is no peer, this is only fatal when we activate. When we
1189 * deactivate, we must assume the application has unlinked the peer and
1190 * will deactivate it eventually. */
1194 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1197 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1198 goto failure; /* Can't activate pull on a src without a
1199 getrange function */
1207 /* Mark pad as needing reconfiguration */
1209 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1211 /* pre_activate returns TRUE if we weren't already in the process of
1212 * switching to the 'new' mode */
1213 if (pre_activate (pad, new)) {
1215 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1216 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1220 /* can happen for sinks of passthrough elements */
1223 post_activate (pad, new);
1226 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1227 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1232 /* Clear sticky flags on deactivation */
1234 GST_OBJECT_LOCK (pad);
1235 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1236 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1237 GST_OBJECT_UNLOCK (pad);
1245 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1246 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1251 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1252 "failed to %s in switch to %s mode from %s mode",
1253 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1254 gst_pad_mode_get_name (old));
1259 GST_OBJECT_LOCK (peer);
1260 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1261 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1262 GST_OBJECT_UNLOCK (peer);
1263 gst_object_unref (peer);
1268 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1269 "pad in pull mode");
1274 GST_OBJECT_LOCK (pad);
1275 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1276 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1277 GST_PAD_SET_FLUSHING (pad);
1278 GST_PAD_MODE (pad) = old;
1279 pad->priv->in_activation = FALSE;
1280 g_cond_broadcast (&pad->priv->activation_cond);
1281 GST_OBJECT_UNLOCK (pad);
1287 * gst_pad_activate_mode:
1288 * @pad: the #GstPad to activate or deactivate.
1289 * @mode: the requested activation mode
1290 * @active: whether or not the pad should be active.
1292 * Activates or deactivates the given pad in @mode via dispatching to the
1293 * pad's activatemodefunc. For use from within pad activation functions only.
1295 * If you don't know what this is, you probably don't want to call it.
1297 * Returns: %TRUE if the operation was successful.
1302 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1306 GstPadMode old, new;
1308 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1310 GST_OBJECT_LOCK (pad);
1312 old = GST_PAD_MODE (pad);
1313 new = active ? mode : GST_PAD_MODE_NONE;
1317 ACQUIRE_PARENT (pad, parent, no_parent);
1319 GST_OBJECT_UNLOCK (pad);
1321 res = activate_mode_internal (pad, parent, mode, active);
1323 RELEASE_PARENT (parent);
1329 GST_OBJECT_UNLOCK (pad);
1330 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1331 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1336 GST_WARNING_OBJECT (pad, "no parent");
1337 GST_OBJECT_UNLOCK (pad);
1343 * gst_pad_is_active:
1344 * @pad: the #GstPad to query
1346 * Query if a pad is active
1348 * Returns: %TRUE if the pad is active.
1353 gst_pad_is_active (GstPad * pad)
1355 gboolean result = FALSE;
1357 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1359 GST_OBJECT_LOCK (pad);
1360 result = GST_PAD_IS_ACTIVE (pad);
1361 GST_OBJECT_UNLOCK (pad);
1367 cleanup_hook (GstPad * pad, GHook * hook)
1369 GstPadProbeType type;
1371 if (!G_HOOK_IS_VALID (hook))
1374 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1376 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1377 /* unblock when we remove the last blocking probe */
1379 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1382 /* Might have new probes now that want to be called */
1383 GST_PAD_BLOCK_BROADCAST (pad);
1385 if (pad->num_blocked == 0) {
1386 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1387 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1390 g_hook_destroy_link (&pad->probes, hook);
1395 * gst_pad_add_probe:
1396 * @pad: the #GstPad to add the probe to
1397 * @mask: the probe mask
1398 * @callback: #GstPadProbeCallback that will be called with notifications of
1400 * @user_data: (closure): user data passed to the callback
1401 * @destroy_data: #GDestroyNotify for user_data
1403 * Be notified of different states of pads. The provided callback is called for
1404 * every state that matches @mask.
1406 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1407 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1408 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1409 * immediately if the pad is already idle while calling gst_pad_add_probe().
1410 * In each of the groups, probes are called in the order in which they were
1413 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1414 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1415 * happen that the probe can be run immediately and if the probe returns
1416 * GST_PAD_PROBE_REMOVE this functions returns 0.
1421 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1422 GstPadProbeCallback callback, gpointer user_data,
1423 GDestroyNotify destroy_data)
1428 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1429 g_return_val_if_fail (mask != 0, 0);
1431 GST_OBJECT_LOCK (pad);
1433 /* make a new probe */
1434 hook = g_hook_alloc (&pad->probes);
1436 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1439 /* when no contraints are given for the types, assume all types are
1441 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1442 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1443 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1444 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1446 /* store our flags and other fields */
1447 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1448 hook->func = callback;
1449 hook->data = user_data;
1450 hook->destroy = destroy_data;
1451 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1454 g_hook_append (&pad->probes, hook);
1456 /* incremenent cookie so that the new hook get's called */
1457 pad->priv->probe_list_cookie++;
1459 /* get the id of the hook, we return this and it can be used to remove the
1461 res = hook->hook_id;
1463 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1465 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1466 /* we have a block probe */
1468 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1469 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1470 "now %d blocking probes", pad->num_blocked);
1472 /* Might have new probes now that want to be called */
1473 GST_PAD_BLOCK_BROADCAST (pad);
1476 /* call the callback if we need to be called for idle callbacks */
1477 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1478 if (pad->priv->using > 0) {
1479 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1480 * flag above, the last thread to leave the push will do the callback. New
1481 * threads going into the push will block. */
1482 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1483 "pad is in use, delay idle callback");
1484 GST_OBJECT_UNLOCK (pad);
1486 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1487 GstPadProbeReturn ret;
1489 /* Keep another ref, the callback could destroy the pad */
1490 gst_object_ref (pad);
1491 pad->priv->idle_running++;
1493 /* the pad is idle now, we can signal the idle callback now */
1494 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1495 "pad is idle, trigger idle callback");
1496 GST_OBJECT_UNLOCK (pad);
1498 ret = callback (pad, &info, user_data);
1500 GST_OBJECT_LOCK (pad);
1502 case GST_PAD_PROBE_REMOVE:
1503 /* remove the probe */
1504 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1505 cleanup_hook (pad, hook);
1508 case GST_PAD_PROBE_DROP:
1509 GST_DEBUG_OBJECT (pad, "asked to drop item");
1511 case GST_PAD_PROBE_PASS:
1512 GST_DEBUG_OBJECT (pad, "asked to pass item");
1514 case GST_PAD_PROBE_OK:
1515 GST_DEBUG_OBJECT (pad, "probe returned OK");
1517 case GST_PAD_PROBE_HANDLED:
1518 GST_DEBUG_OBJECT (pad, "probe handled the data");
1521 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1524 pad->priv->idle_running--;
1525 if (pad->priv->idle_running == 0) {
1526 GST_PAD_BLOCK_BROADCAST (pad);
1528 GST_OBJECT_UNLOCK (pad);
1530 gst_object_unref (pad);
1533 GST_OBJECT_UNLOCK (pad);
1539 * gst_pad_remove_probe:
1540 * @pad: the #GstPad with the probe
1541 * @id: the probe id to remove
1543 * Remove the probe with @id from @pad.
1548 gst_pad_remove_probe (GstPad * pad, gulong id)
1552 g_return_if_fail (GST_IS_PAD (pad));
1554 GST_OBJECT_LOCK (pad);
1556 hook = g_hook_get (&pad->probes, id);
1560 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1562 cleanup_hook (pad, hook);
1563 GST_OBJECT_UNLOCK (pad);
1569 GST_OBJECT_UNLOCK (pad);
1570 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1576 * gst_pad_is_blocked:
1577 * @pad: the #GstPad to query
1579 * Checks if the pad is blocked or not. This function returns the
1580 * last requested state of the pad. It is not certain that the pad
1581 * is actually blocking at this point (see gst_pad_is_blocking()).
1583 * Returns: %TRUE if the pad is blocked.
1588 gst_pad_is_blocked (GstPad * pad)
1590 gboolean result = FALSE;
1592 g_return_val_if_fail (GST_IS_PAD (pad), result);
1594 GST_OBJECT_LOCK (pad);
1595 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1596 GST_OBJECT_UNLOCK (pad);
1602 * gst_pad_is_blocking:
1603 * @pad: the #GstPad to query
1605 * Checks if the pad is blocking or not. This is a guaranteed state
1606 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1608 * Returns: %TRUE if the pad is blocking.
1613 gst_pad_is_blocking (GstPad * pad)
1615 gboolean result = FALSE;
1617 g_return_val_if_fail (GST_IS_PAD (pad), result);
1619 GST_OBJECT_LOCK (pad);
1620 /* the blocking flag is only valid if the pad is not flushing */
1621 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1622 GST_OBJECT_UNLOCK (pad);
1628 * gst_pad_needs_reconfigure:
1629 * @pad: the #GstPad to check
1631 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1632 * if the flag was set.
1634 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1637 gst_pad_needs_reconfigure (GstPad * pad)
1639 gboolean reconfigure;
1641 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1643 GST_OBJECT_LOCK (pad);
1644 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1645 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1646 GST_OBJECT_UNLOCK (pad);
1652 * gst_pad_check_reconfigure:
1653 * @pad: the #GstPad to check
1655 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1656 * if the flag was set.
1658 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1661 gst_pad_check_reconfigure (GstPad * pad)
1663 gboolean reconfigure;
1665 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1667 GST_OBJECT_LOCK (pad);
1668 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1670 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1671 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1673 GST_OBJECT_UNLOCK (pad);
1679 * gst_pad_mark_reconfigure:
1680 * @pad: the #GstPad to mark
1682 * Mark a pad for needing reconfiguration. The next call to
1683 * gst_pad_check_reconfigure() will return %TRUE after this call.
1686 gst_pad_mark_reconfigure (GstPad * pad)
1688 g_return_if_fail (GST_IS_PAD (pad));
1690 GST_OBJECT_LOCK (pad);
1691 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1692 GST_OBJECT_UNLOCK (pad);
1696 * gst_pad_set_activate_function:
1698 * @f: the #GstPadActivateFunction to set.
1700 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1704 * gst_pad_set_activate_function_full:
1706 * @activate: the #GstPadActivateFunction to set.
1707 * @user_data: user_data passed to @notify
1708 * @notify: notify called when @activate will not be used anymore.
1710 * Sets the given activate function for @pad. The activate function will
1711 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1712 * Only makes sense to set on sink pads.
1714 * Call this function if your sink pad can start a pull-based task.
1717 gst_pad_set_activate_function_full (GstPad * pad,
1718 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1720 g_return_if_fail (GST_IS_PAD (pad));
1722 if (pad->activatenotify)
1723 pad->activatenotify (pad->activatedata);
1724 GST_PAD_ACTIVATEFUNC (pad) = activate;
1725 pad->activatedata = user_data;
1726 pad->activatenotify = notify;
1728 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1729 GST_DEBUG_FUNCPTR_NAME (activate));
1733 * gst_pad_set_activatemode_function:
1735 * @f: the #GstPadActivateModeFunction to set.
1737 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1741 * gst_pad_set_activatemode_function_full:
1743 * @activatemode: the #GstPadActivateModeFunction to set.
1744 * @user_data: user_data passed to @notify
1745 * @notify: notify called when @activatemode will not be used anymore.
1747 * Sets the given activate_mode function for the pad. An activate_mode function
1748 * prepares the element for data passing.
1751 gst_pad_set_activatemode_function_full (GstPad * pad,
1752 GstPadActivateModeFunction activatemode, gpointer user_data,
1753 GDestroyNotify notify)
1755 g_return_if_fail (GST_IS_PAD (pad));
1757 if (pad->activatemodenotify)
1758 pad->activatemodenotify (pad->activatemodedata);
1759 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1760 pad->activatemodedata = user_data;
1761 pad->activatemodenotify = notify;
1763 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1764 GST_DEBUG_FUNCPTR_NAME (activatemode));
1768 * gst_pad_set_chain_function:
1769 * @p: a sink #GstPad.
1770 * @f: the #GstPadChainFunction to set.
1772 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1776 * gst_pad_set_chain_function_full:
1777 * @pad: a sink #GstPad.
1778 * @chain: the #GstPadChainFunction to set.
1779 * @user_data: user_data passed to @notify
1780 * @notify: notify called when @chain will not be used anymore.
1782 * Sets the given chain function for the pad. The chain function is called to
1783 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1786 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1787 gpointer user_data, GDestroyNotify notify)
1789 g_return_if_fail (GST_IS_PAD (pad));
1790 g_return_if_fail (GST_PAD_IS_SINK (pad));
1792 if (pad->chainnotify)
1793 pad->chainnotify (pad->chaindata);
1794 GST_PAD_CHAINFUNC (pad) = chain;
1795 pad->chaindata = user_data;
1796 pad->chainnotify = notify;
1798 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1799 GST_DEBUG_FUNCPTR_NAME (chain));
1803 * gst_pad_set_chain_list_function:
1804 * @p: a sink #GstPad.
1805 * @f: the #GstPadChainListFunction to set.
1807 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1811 * gst_pad_set_chain_list_function_full:
1812 * @pad: a sink #GstPad.
1813 * @chainlist: the #GstPadChainListFunction to set.
1814 * @user_data: user_data passed to @notify
1815 * @notify: notify called when @chainlist will not be used anymore.
1817 * Sets the given chain list function for the pad. The chainlist function is
1818 * called to process a #GstBufferList input buffer list. See
1819 * #GstPadChainListFunction for more details.
1822 gst_pad_set_chain_list_function_full (GstPad * pad,
1823 GstPadChainListFunction chainlist, gpointer user_data,
1824 GDestroyNotify notify)
1826 g_return_if_fail (GST_IS_PAD (pad));
1827 g_return_if_fail (GST_PAD_IS_SINK (pad));
1829 if (pad->chainlistnotify)
1830 pad->chainlistnotify (pad->chainlistdata);
1831 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1832 pad->chainlistdata = user_data;
1833 pad->chainlistnotify = notify;
1835 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1836 GST_DEBUG_FUNCPTR_NAME (chainlist));
1840 * gst_pad_set_getrange_function:
1841 * @p: a source #GstPad.
1842 * @f: the #GstPadGetRangeFunction to set.
1844 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1848 * gst_pad_set_getrange_function_full:
1849 * @pad: a source #GstPad.
1850 * @get: the #GstPadGetRangeFunction to set.
1851 * @user_data: user_data passed to @notify
1852 * @notify: notify called when @get will not be used anymore.
1854 * Sets the given getrange function for the pad. The getrange function is
1855 * called to produce a new #GstBuffer to start the processing pipeline. see
1856 * #GstPadGetRangeFunction for a description of the getrange function.
1859 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1860 gpointer user_data, GDestroyNotify notify)
1862 g_return_if_fail (GST_IS_PAD (pad));
1863 g_return_if_fail (GST_PAD_IS_SRC (pad));
1865 if (pad->getrangenotify)
1866 pad->getrangenotify (pad->getrangedata);
1867 GST_PAD_GETRANGEFUNC (pad) = get;
1868 pad->getrangedata = user_data;
1869 pad->getrangenotify = notify;
1871 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1872 GST_DEBUG_FUNCPTR_NAME (get));
1876 * gst_pad_set_event_function:
1877 * @p: a #GstPad of either direction.
1878 * @f: the #GstPadEventFunction to set.
1880 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1884 * gst_pad_set_event_function_full:
1885 * @pad: a #GstPad of either direction.
1886 * @event: the #GstPadEventFunction to set.
1887 * @user_data: user_data passed to @notify
1888 * @notify: notify called when @event will not be used anymore.
1890 * Sets the given event handler for the pad.
1893 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1894 gpointer user_data, GDestroyNotify notify)
1896 g_return_if_fail (GST_IS_PAD (pad));
1898 if (pad->eventnotify)
1899 pad->eventnotify (pad->eventdata);
1900 GST_PAD_EVENTFUNC (pad) = event;
1901 pad->eventdata = user_data;
1902 pad->eventnotify = notify;
1904 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1905 GST_DEBUG_FUNCPTR_NAME (event));
1909 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1913 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1914 if (ret == GST_FLOW_OK)
1920 * gst_pad_set_event_full_function:
1921 * @p: a #GstPad of either direction.
1922 * @f: the #GstPadEventFullFunction to set.
1924 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1928 * gst_pad_set_event_full_function_full:
1929 * @pad: a #GstPad of either direction.
1930 * @event: the #GstPadEventFullFunction to set.
1931 * @user_data: user_data passed to @notify
1932 * @notify: notify called when @event will not be used anymore.
1934 * Sets the given event handler for the pad.
1939 gst_pad_set_event_full_function_full (GstPad * pad,
1940 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1942 g_return_if_fail (GST_IS_PAD (pad));
1944 if (pad->eventnotify)
1945 pad->eventnotify (pad->eventdata);
1946 GST_PAD_EVENTFULLFUNC (pad) = event;
1947 GST_PAD_EVENTFUNC (pad) = event_wrap;
1948 pad->eventdata = user_data;
1949 pad->eventnotify = notify;
1951 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1952 GST_DEBUG_FUNCPTR_NAME (event));
1956 * gst_pad_set_query_function:
1957 * @p: a #GstPad of either direction.
1958 * @f: the #GstPadQueryFunction to set.
1960 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1964 * gst_pad_set_query_function_full:
1965 * @pad: a #GstPad of either direction.
1966 * @query: the #GstPadQueryFunction to set.
1967 * @user_data: user_data passed to @notify
1968 * @notify: notify called when @query will not be used anymore.
1970 * Set the given query function for the pad.
1973 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1974 gpointer user_data, GDestroyNotify notify)
1976 g_return_if_fail (GST_IS_PAD (pad));
1978 if (pad->querynotify)
1979 pad->querynotify (pad->querydata);
1980 GST_PAD_QUERYFUNC (pad) = query;
1981 pad->querydata = user_data;
1982 pad->querynotify = notify;
1984 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1985 GST_DEBUG_FUNCPTR_NAME (query));
1989 * gst_pad_set_iterate_internal_links_function:
1990 * @p: a #GstPad of either direction.
1991 * @f: the #GstPadIterIntLinkFunction to set.
1993 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1994 * for the user_data and notify.
1997 * gst_pad_set_iterate_internal_links_function_full:
1998 * @pad: a #GstPad of either direction.
1999 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2000 * @user_data: user_data passed to @notify
2001 * @notify: notify called when @iterintlink will not be used anymore.
2003 * Sets the given internal link iterator function for the pad.
2006 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2007 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2008 GDestroyNotify notify)
2010 g_return_if_fail (GST_IS_PAD (pad));
2012 if (pad->iterintlinknotify)
2013 pad->iterintlinknotify (pad->iterintlinkdata);
2014 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2015 pad->iterintlinkdata = user_data;
2016 pad->iterintlinknotify = notify;
2018 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2019 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2023 * gst_pad_set_link_function:
2025 * @f: the #GstPadLinkFunction to set.
2027 * Calls gst_pad_set_link_function_full() with %NULL
2028 * for the user_data and notify.
2031 * gst_pad_set_link_function_full:
2033 * @link: the #GstPadLinkFunction to set.
2034 * @user_data: user_data passed to @notify
2035 * @notify: notify called when @link will not be used anymore.
2037 * Sets the given link function for the pad. It will be called when
2038 * the pad is linked with another pad.
2040 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2043 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2044 * cannot be made for some reason.
2046 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2047 * of the peer sink pad, if present.
2050 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2051 gpointer user_data, GDestroyNotify notify)
2053 g_return_if_fail (GST_IS_PAD (pad));
2055 if (pad->linknotify)
2056 pad->linknotify (pad->linkdata);
2057 GST_PAD_LINKFUNC (pad) = link;
2058 pad->linkdata = user_data;
2059 pad->linknotify = notify;
2061 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2062 GST_DEBUG_FUNCPTR_NAME (link));
2066 * gst_pad_set_unlink_function:
2068 * @f: the #GstPadUnlinkFunction to set.
2070 * Calls gst_pad_set_unlink_function_full() with %NULL
2071 * for the user_data and notify.
2074 * gst_pad_set_unlink_function_full:
2076 * @unlink: the #GstPadUnlinkFunction to set.
2077 * @user_data: user_data passed to @notify
2078 * @notify: notify called when @unlink will not be used anymore.
2080 * Sets the given unlink function for the pad. It will be called
2081 * when the pad is unlinked.
2084 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2085 gpointer user_data, GDestroyNotify notify)
2087 g_return_if_fail (GST_IS_PAD (pad));
2089 if (pad->unlinknotify)
2090 pad->unlinknotify (pad->unlinkdata);
2091 GST_PAD_UNLINKFUNC (pad) = unlink;
2092 pad->unlinkdata = user_data;
2093 pad->unlinknotify = notify;
2095 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2096 GST_DEBUG_FUNCPTR_NAME (unlink));
2101 * @srcpad: the source #GstPad to unlink.
2102 * @sinkpad: the sink #GstPad to unlink.
2104 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2105 * signal on both pads.
2107 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2108 * the pads were not linked together.
2113 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2115 gboolean result = FALSE;
2116 GstElement *parent = NULL;
2118 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2119 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2120 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2121 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2123 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2125 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2126 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2127 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2129 /* We need to notify the parent before taking any pad locks as the bin in
2130 * question might be waiting for a lock on the pad while holding its lock
2131 * that our message will try to take. */
2132 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2133 if (GST_IS_ELEMENT (parent)) {
2134 gst_element_post_message (parent,
2135 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2136 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2138 gst_object_unref (parent);
2143 GST_OBJECT_LOCK (srcpad);
2144 GST_OBJECT_LOCK (sinkpad);
2146 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2147 goto not_linked_together;
2149 if (GST_PAD_UNLINKFUNC (srcpad)) {
2150 GstObject *tmpparent;
2152 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2154 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2155 RELEASE_PARENT (tmpparent);
2158 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2159 GstObject *tmpparent;
2161 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2163 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2164 RELEASE_PARENT (tmpparent);
2168 /* first clear peers */
2169 GST_PAD_PEER (srcpad) = NULL;
2170 GST_PAD_PEER (sinkpad) = NULL;
2172 GST_OBJECT_UNLOCK (sinkpad);
2173 GST_OBJECT_UNLOCK (srcpad);
2175 /* fire off a signal to each of the pads telling them
2176 * that they've been unlinked */
2177 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2178 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2180 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2181 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2186 if (parent != NULL) {
2187 gst_element_post_message (parent,
2188 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2189 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2190 gst_object_unref (parent);
2192 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2196 not_linked_together:
2198 /* we do not emit a warning in this case because unlinking cannot
2199 * be made MT safe.*/
2200 GST_OBJECT_UNLOCK (sinkpad);
2201 GST_OBJECT_UNLOCK (srcpad);
2207 * gst_pad_is_linked:
2208 * @pad: pad to check
2210 * Checks if a @pad is linked to another pad or not.
2212 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2217 gst_pad_is_linked (GstPad * pad)
2221 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2223 GST_OBJECT_LOCK (pad);
2224 result = (GST_PAD_PEER (pad) != NULL);
2225 GST_OBJECT_UNLOCK (pad);
2230 /* get the caps from both pads and see if the intersection
2233 * This function should be called with the pad LOCK on both
2237 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2238 GstPadLinkCheck flags)
2240 GstCaps *srccaps = NULL;
2241 GstCaps *sinkcaps = NULL;
2242 gboolean compatible = FALSE;
2244 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2247 /* Doing the expensive caps checking takes priority over only checking the template caps */
2248 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2249 GST_OBJECT_UNLOCK (sink);
2250 GST_OBJECT_UNLOCK (src);
2252 srccaps = gst_pad_query_caps (src, NULL);
2253 sinkcaps = gst_pad_query_caps (sink, NULL);
2255 GST_OBJECT_LOCK (src);
2256 GST_OBJECT_LOCK (sink);
2258 /* If one of the two pads doesn't have a template, consider the intersection
2260 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2261 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2265 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2267 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2270 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2272 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2275 /* if we have caps on both pads we can check the intersection. If one
2276 * of the caps is %NULL, we return %TRUE. */
2277 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2279 gst_caps_unref (srccaps);
2281 gst_caps_unref (sinkcaps);
2285 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2286 gst_caps_unref (srccaps);
2287 gst_caps_unref (sinkcaps);
2290 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2291 (compatible ? "" : "not "));
2296 /* check if the grandparents of both pads are the same.
2297 * This check is required so that we don't try to link
2298 * pads from elements in different bins without ghostpads.
2300 * The LOCK should be held on both pads
2303 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2305 GstObject *psrc, *psink;
2307 psrc = GST_OBJECT_PARENT (src);
2308 psink = GST_OBJECT_PARENT (sink);
2310 /* if one of the pads has no parent, we allow the link */
2311 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2314 /* only care about parents that are elements */
2315 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2316 goto no_element_parent;
2318 /* if the parents are the same, we have a loop */
2319 if (G_UNLIKELY (psrc == psink))
2322 /* if they both have a parent, we check the grandparents. We can not lock
2323 * the parent because we hold on the child (pad) and the locking order is
2324 * parent >> child. */
2325 psrc = GST_OBJECT_PARENT (psrc);
2326 psink = GST_OBJECT_PARENT (psink);
2328 /* if they have grandparents but they are not the same */
2329 if (G_UNLIKELY (psrc != psink))
2330 goto wrong_grandparents;
2337 GST_CAT_DEBUG (GST_CAT_CAPS,
2338 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2339 GST_PTR_FORMAT, psrc, psink);
2344 GST_CAT_DEBUG (GST_CAT_CAPS,
2345 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2346 GST_PTR_FORMAT, psrc, psink);
2351 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2357 GST_CAT_DEBUG (GST_CAT_CAPS,
2358 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2359 GST_PTR_FORMAT, psrc, psink);
2364 /* FIXME leftover from an attempt at refactoring... */
2365 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2366 * the two pads will be locked in the srcpad, sinkpad order. */
2367 static GstPadLinkReturn
2368 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2370 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2371 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2373 GST_OBJECT_LOCK (srcpad);
2375 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2376 goto src_was_linked;
2378 GST_OBJECT_LOCK (sinkpad);
2380 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2381 goto sink_was_linked;
2383 /* check hierarchy, pads can only be linked if the grandparents
2385 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2386 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2387 goto wrong_hierarchy;
2389 /* check pad caps for non-empty intersection */
2390 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2393 /* FIXME check pad scheduling for non-empty intersection */
2395 return GST_PAD_LINK_OK;
2399 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2400 GST_DEBUG_PAD_NAME (srcpad),
2401 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2402 /* we do not emit a warning in this case because unlinking cannot
2403 * be made MT safe.*/
2404 GST_OBJECT_UNLOCK (srcpad);
2405 return GST_PAD_LINK_WAS_LINKED;
2409 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2410 GST_DEBUG_PAD_NAME (sinkpad),
2411 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2412 /* we do not emit a warning in this case because unlinking cannot
2413 * be made MT safe.*/
2414 GST_OBJECT_UNLOCK (sinkpad);
2415 GST_OBJECT_UNLOCK (srcpad);
2416 return GST_PAD_LINK_WAS_LINKED;
2420 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2421 GST_OBJECT_UNLOCK (sinkpad);
2422 GST_OBJECT_UNLOCK (srcpad);
2423 return GST_PAD_LINK_WRONG_HIERARCHY;
2427 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2428 GST_OBJECT_UNLOCK (sinkpad);
2429 GST_OBJECT_UNLOCK (srcpad);
2430 return GST_PAD_LINK_NOFORMAT;
2436 * @srcpad: the source #GstPad.
2437 * @sinkpad: the sink #GstPad.
2439 * Checks if the source pad and the sink pad are compatible so they can be
2442 * Returns: %TRUE if the pads can be linked.
2445 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2447 GstPadLinkReturn result;
2449 /* generic checks */
2450 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2451 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2453 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2454 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2456 /* gst_pad_link_prepare does everything for us, we only release the locks
2457 * on the pads that it gets us. If this function returns !OK the locks are not
2459 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2460 if (result != GST_PAD_LINK_OK)
2463 GST_OBJECT_UNLOCK (srcpad);
2464 GST_OBJECT_UNLOCK (sinkpad);
2467 return result == GST_PAD_LINK_OK;
2471 * gst_pad_link_full:
2472 * @srcpad: the source #GstPad to link.
2473 * @sinkpad: the sink #GstPad to link.
2474 * @flags: the checks to validate when linking
2476 * Links the source pad and the sink pad.
2478 * This variant of #gst_pad_link provides a more granular control on the
2479 * checks being done when linking. While providing some considerable speedups
2480 * the caller of this method must be aware that wrong usage of those flags
2481 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2482 * for more information.
2486 * Returns: A result code indicating if the connection worked or
2490 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2492 GstPadLinkReturn result;
2494 GstPadLinkFunction srcfunc, sinkfunc;
2496 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2497 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2498 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2499 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2500 GST_PAD_LINK_WRONG_DIRECTION);
2502 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2504 /* Notify the parent early. See gst_pad_unlink for details. */
2505 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2506 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2507 gst_element_post_message (parent,
2508 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2509 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2511 gst_object_unref (parent);
2516 /* prepare will also lock the two pads */
2517 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2519 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2520 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2521 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2522 gst_pad_link_get_name (result));
2526 /* must set peers before calling the link function */
2527 GST_PAD_PEER (srcpad) = sinkpad;
2528 GST_PAD_PEER (sinkpad) = srcpad;
2530 /* check events, when something is different, mark pending */
2531 schedule_events (srcpad, sinkpad);
2533 /* get the link functions */
2534 srcfunc = GST_PAD_LINKFUNC (srcpad);
2535 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2537 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2538 /* custom link functions, execute them */
2539 GST_OBJECT_UNLOCK (sinkpad);
2540 GST_OBJECT_UNLOCK (srcpad);
2543 GstObject *tmpparent;
2545 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2546 /* this one will call the peer link function */
2547 result = srcfunc (srcpad, tmpparent, sinkpad);
2548 RELEASE_PARENT (tmpparent);
2549 } else if (sinkfunc) {
2550 GstObject *tmpparent;
2552 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2553 /* if no source link function, we need to call the sink link
2554 * function ourselves. */
2555 result = sinkfunc (sinkpad, tmpparent, srcpad);
2556 RELEASE_PARENT (tmpparent);
2560 GST_OBJECT_LOCK (srcpad);
2561 GST_OBJECT_LOCK (sinkpad);
2563 /* we released the lock, check if the same pads are linked still */
2564 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2565 goto concurrent_link;
2567 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2570 GST_OBJECT_UNLOCK (sinkpad);
2571 GST_OBJECT_UNLOCK (srcpad);
2573 /* fire off a signal to each of the pads telling them
2574 * that they've been linked */
2575 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2576 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2578 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2579 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2581 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2582 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2585 if (G_LIKELY (parent)) {
2586 gst_element_post_message (parent,
2587 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2588 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2589 gst_object_unref (parent);
2592 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2598 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2599 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2600 GST_OBJECT_UNLOCK (sinkpad);
2601 GST_OBJECT_UNLOCK (srcpad);
2603 /* The other link operation succeeded first */
2604 result = GST_PAD_LINK_WAS_LINKED;
2609 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2610 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2611 gst_pad_link_get_name (result));
2613 GST_PAD_PEER (srcpad) = NULL;
2614 GST_PAD_PEER (sinkpad) = NULL;
2616 GST_OBJECT_UNLOCK (sinkpad);
2617 GST_OBJECT_UNLOCK (srcpad);
2625 * @srcpad: the source #GstPad to link.
2626 * @sinkpad: the sink #GstPad to link.
2628 * Links the source pad and the sink pad.
2630 * Returns: A result code indicating if the connection worked or
2636 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2638 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2642 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2644 GstPadTemplate **template_p;
2646 /* this function would need checks if it weren't static */
2648 GST_OBJECT_LOCK (pad);
2649 template_p = &pad->padtemplate;
2650 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2651 GST_OBJECT_UNLOCK (pad);
2654 gst_pad_template_pad_created (templ, pad);
2658 * gst_pad_get_pad_template:
2661 * Gets the template for @pad.
2663 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2664 * this pad was instantiated, or %NULL if this pad has no
2665 * template. Unref after usage.
2668 gst_pad_get_pad_template (GstPad * pad)
2670 GstPadTemplate *templ;
2672 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2674 templ = GST_PAD_PAD_TEMPLATE (pad);
2676 return (templ ? gst_object_ref (templ) : NULL);
2680 * gst_pad_has_current_caps:
2681 * @pad: a #GstPad to check
2683 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2685 * Returns: %TRUE when @pad has caps associated with it.
2688 gst_pad_has_current_caps (GstPad * pad)
2693 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2695 GST_OBJECT_LOCK (pad);
2696 caps = get_pad_caps (pad);
2697 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2698 "check current pad caps %" GST_PTR_FORMAT, caps);
2699 result = (caps != NULL);
2700 GST_OBJECT_UNLOCK (pad);
2706 * gst_pad_get_current_caps:
2707 * @pad: a #GstPad to get the current capabilities of.
2709 * Gets the capabilities currently configured on @pad with the last
2710 * #GST_EVENT_CAPS event.
2712 * Returns: (transfer full) (nullable): the current caps of the pad with
2713 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2716 gst_pad_get_current_caps (GstPad * pad)
2720 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2722 GST_OBJECT_LOCK (pad);
2723 if ((result = get_pad_caps (pad)))
2724 gst_caps_ref (result);
2725 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2726 "get current pad caps %" GST_PTR_FORMAT, result);
2727 GST_OBJECT_UNLOCK (pad);
2733 * gst_pad_get_pad_template_caps:
2734 * @pad: a #GstPad to get the template capabilities from.
2736 * Gets the capabilities for @pad's template.
2738 * Returns: (transfer full): the #GstCaps of this pad template.
2739 * Unref after usage.
2742 gst_pad_get_pad_template_caps (GstPad * pad)
2744 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2746 if (GST_PAD_PAD_TEMPLATE (pad))
2747 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2749 return gst_caps_ref (GST_CAPS_ANY);
2754 * @pad: a #GstPad to get the peer of.
2756 * Gets the peer of @pad. This function refs the peer pad so
2757 * you need to unref it after use.
2759 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2764 gst_pad_get_peer (GstPad * pad)
2768 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2770 GST_OBJECT_LOCK (pad);
2771 result = GST_PAD_PEER (pad);
2773 gst_object_ref (result);
2774 GST_OBJECT_UNLOCK (pad);
2780 * gst_pad_get_allowed_caps:
2783 * Gets the capabilities of the allowed media types that can flow through
2784 * @pad and its peer.
2786 * The allowed capabilities is calculated as the intersection of the results of
2787 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2788 * on the resulting caps.
2790 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2791 * pad link. Unref the caps when you no longer need it. This
2792 * function returns %NULL when @pad has no peer.
2797 gst_pad_get_allowed_caps (GstPad * pad)
2800 GstCaps *caps = NULL;
2803 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2805 GST_OBJECT_LOCK (pad);
2806 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2808 GST_OBJECT_UNLOCK (pad);
2810 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2812 mycaps = gst_pad_query_caps (pad, NULL);
2814 /* Query peer caps */
2815 query = gst_query_new_caps (mycaps);
2816 if (!gst_pad_peer_query (pad, query)) {
2817 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2821 gst_query_parse_caps_result (query, &caps);
2823 g_warn_if_fail (caps != NULL);
2826 gst_caps_ref (caps);
2828 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2832 gst_query_unref (query);
2833 gst_caps_unref (mycaps);
2839 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2840 GST_OBJECT_UNLOCK (pad);
2847 * gst_pad_iterate_internal_links_default:
2848 * @pad: the #GstPad to get the internal links of.
2849 * @parent: (allow-none): the parent of @pad or %NULL
2851 * Iterate the list of pads to which the given pad is linked to inside of
2852 * the parent element.
2853 * This is the default handler, and thus returns an iterator of all of the
2854 * pads inside the parent element with opposite direction.
2856 * The caller must free this iterator after use with gst_iterator_free().
2858 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2859 * has no parent. Unref each returned pad with gst_object_unref().
2862 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2869 GstElement *eparent;
2871 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2873 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2874 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2876 GST_OBJECT_LOCK (pad);
2877 eparent = GST_PAD_PARENT (pad);
2878 if (!eparent || !GST_IS_ELEMENT (eparent))
2881 gst_object_ref (eparent);
2882 GST_OBJECT_UNLOCK (pad);
2885 if (pad->direction == GST_PAD_SRC)
2886 padlist = &eparent->sinkpads;
2888 padlist = &eparent->srcpads;
2890 GST_DEBUG_OBJECT (pad, "Making iterator");
2892 cookie = &eparent->pads_cookie;
2894 lock = GST_OBJECT_GET_LOCK (eparent);
2896 res = gst_iterator_new_list (GST_TYPE_PAD,
2897 lock, cookie, padlist, (GObject *) owner, NULL);
2899 gst_object_unref (owner);
2906 GST_OBJECT_UNLOCK (pad);
2907 GST_DEBUG_OBJECT (pad, "no parent element");
2913 * gst_pad_iterate_internal_links:
2914 * @pad: the GstPad to get the internal links of.
2916 * Gets an iterator for the pads to which the given pad is linked to inside
2917 * of the parent element.
2919 * Each #GstPad element yielded by the iterator will have its refcount increased,
2920 * so unref after use.
2922 * Free-function: gst_iterator_free
2924 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2925 * or %NULL when the pad does not have an iterator function
2926 * configured. Use gst_iterator_free() after usage.
2929 gst_pad_iterate_internal_links (GstPad * pad)
2931 GstIterator *res = NULL;
2934 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2936 GST_OBJECT_LOCK (pad);
2937 ACQUIRE_PARENT (pad, parent, no_parent);
2938 GST_OBJECT_UNLOCK (pad);
2940 if (GST_PAD_ITERINTLINKFUNC (pad))
2941 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2943 RELEASE_PARENT (parent);
2950 GST_DEBUG_OBJECT (pad, "no parent");
2951 GST_OBJECT_UNLOCK (pad);
2959 * @forward: (scope call): a #GstPadForwardFunction
2960 * @user_data: user data passed to @forward
2962 * Calls @forward for all internally linked pads of @pad. This function deals with
2963 * dynamically changing internal pads and will make sure that the @forward
2964 * function is only called once for each pad.
2966 * When @forward returns %TRUE, no further pads will be processed.
2968 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2971 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2974 gboolean result = FALSE;
2976 gboolean done = FALSE;
2977 GValue item = { 0, };
2978 GList *pushed_pads = NULL;
2980 iter = gst_pad_iterate_internal_links (pad);
2986 switch (gst_iterator_next (iter, &item)) {
2987 case GST_ITERATOR_OK:
2991 intpad = g_value_get_object (&item);
2993 /* if already pushed, skip. FIXME, find something faster to tag pads */
2994 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2995 g_value_reset (&item);
2999 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3000 GST_DEBUG_PAD_NAME (intpad));
3001 done = result = forward (intpad, user_data);
3003 pushed_pads = g_list_prepend (pushed_pads, intpad);
3005 g_value_reset (&item);
3008 case GST_ITERATOR_RESYNC:
3009 /* We don't reset the result here because we don't push the event
3010 * again on pads that got the event already and because we need
3011 * to consider the result of the previous pushes */
3012 gst_iterator_resync (iter);
3014 case GST_ITERATOR_ERROR:
3015 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3018 case GST_ITERATOR_DONE:
3023 g_value_unset (&item);
3024 gst_iterator_free (iter);
3026 g_list_free (pushed_pads);
3036 gboolean dispatched;
3040 event_forward_func (GstPad * pad, EventData * data)
3042 /* for each pad we send to, we should ref the event; it's up
3043 * to downstream to unref again when handled. */
3044 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3045 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3047 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3049 data->dispatched = TRUE;
3056 * gst_pad_event_default:
3057 * @pad: a #GstPad to call the default event handler on.
3058 * @parent: (allow-none): the parent of @pad or %NULL
3059 * @event: (transfer full): the #GstEvent to handle.
3061 * Invokes the default event handler for the given pad.
3063 * The EOS event will pause the task associated with @pad before it is forwarded
3064 * to all internally linked pads,
3066 * The event is sent to all pads internally linked to @pad. This function
3067 * takes ownership of @event.
3069 * Returns: %TRUE if the event was sent successfully.
3072 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3074 gboolean result, forward = TRUE;
3076 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3077 g_return_val_if_fail (event != NULL, FALSE);
3079 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3082 switch (GST_EVENT_TYPE (event)) {
3083 case GST_EVENT_CAPS:
3084 forward = GST_PAD_IS_PROXY_CAPS (pad);
3095 data.dispatched = FALSE;
3096 data.result = FALSE;
3098 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3100 /* for sinkpads without a parent element or without internal links, nothing
3101 * will be dispatched but we still want to return TRUE. */
3102 if (data.dispatched)
3103 result = data.result;
3108 gst_event_unref (event);
3113 /* Default accept caps implementation just checks against
3114 * the allowed caps for the pad */
3116 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3118 /* get the caps and see if it intersects to something not empty */
3119 GstCaps *caps, *allowed = NULL;
3122 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3124 /* first forward the query to internally linked pads when we are dealing with
3126 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3127 result = gst_pad_proxy_query_accept_caps (pad, query);
3129 allowed = gst_pad_get_pad_template_caps (pad);
3134 gst_query_parse_accept_caps (query, &caps);
3136 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3137 allowed = gst_pad_get_pad_template_caps (pad);
3139 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3140 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3141 allowed = gst_pad_query_caps (pad, caps);
3146 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3147 GST_DEBUG_OBJECT (pad,
3148 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3150 result = gst_caps_can_intersect (caps, allowed);
3152 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3153 GST_PTR_FORMAT, allowed, caps);
3154 result = gst_caps_is_subset (caps, allowed);
3156 gst_caps_unref (allowed);
3158 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3161 gst_query_set_accept_caps_result (query, result);
3167 /* Default caps implementation */
3169 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3171 GstCaps *result = NULL, *filter;
3172 GstPadTemplate *templ;
3173 gboolean fixed_caps;
3175 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3178 /* first try to proxy if we must */
3179 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3180 if ((gst_pad_proxy_query_caps (pad, query))) {
3185 gst_query_parse_caps (query, &filter);
3187 /* no proxy or it failed, do default handling */
3188 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3190 GST_OBJECT_LOCK (pad);
3192 /* fixed caps, try the negotiated caps first */
3193 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3194 if ((result = get_pad_caps (pad)))
3195 goto filter_done_unlock;
3198 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3199 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3200 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3201 goto filter_done_unlock;
3205 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3206 "non-fixed pad caps: trying pad caps");
3207 /* non fixed caps, try the negotiated caps */
3208 if ((result = get_pad_caps (pad)))
3209 goto filter_done_unlock;
3212 /* this almost never happens */
3213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3214 result = GST_CAPS_ANY;
3217 GST_OBJECT_UNLOCK (pad);
3219 /* run the filter on the result */
3221 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3222 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3223 GST_PTR_FORMAT, result, result, filter, filter);
3224 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3225 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3229 "using caps %p %" GST_PTR_FORMAT, result, result);
3230 result = gst_caps_ref (result);
3232 gst_query_set_caps_result (query, result);
3233 gst_caps_unref (result);
3239 /* Default latency implementation */
3244 GstClockTime min, max;
3248 query_latency_default_fold (const GValue * item, GValue * ret,
3251 GstPad *pad = g_value_get_object (item), *peer;
3252 LatencyFoldData *fold_data = user_data;
3254 gboolean res = FALSE;
3256 query = gst_query_new_latency ();
3258 peer = gst_pad_get_peer (pad);
3260 res = gst_pad_peer_query (pad, query);
3262 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3267 GstClockTime min, max;
3269 gst_query_parse_latency (query, &live, &min, &max);
3271 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3272 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3274 /* FIXME : Why do we only take values into account if it's live ? */
3275 if (live || fold_data->count == 0) {
3276 if (min > fold_data->min)
3277 fold_data->min = min;
3279 if (fold_data->max == GST_CLOCK_TIME_NONE)
3280 fold_data->max = max;
3281 else if (max < fold_data->max)
3282 fold_data->max = max;
3284 fold_data->live = live;
3286 fold_data->count += 1;
3288 GST_DEBUG_OBJECT (pad, "latency query failed");
3289 g_value_set_boolean (ret, FALSE);
3292 gst_query_unref (query);
3294 gst_object_unref (peer);
3300 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3303 GstIteratorResult res;
3304 GValue ret = G_VALUE_INIT;
3306 LatencyFoldData fold_data;
3308 it = gst_pad_iterate_internal_links (pad);
3310 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3314 g_value_init (&ret, G_TYPE_BOOLEAN);
3317 fold_data.count = 0;
3318 fold_data.live = FALSE;
3320 fold_data.max = GST_CLOCK_TIME_NONE;
3322 g_value_set_boolean (&ret, TRUE);
3323 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3325 case GST_ITERATOR_OK:
3326 g_assert_not_reached ();
3328 case GST_ITERATOR_DONE:
3330 case GST_ITERATOR_ERROR:
3331 g_value_set_boolean (&ret, FALSE);
3333 case GST_ITERATOR_RESYNC:
3334 gst_iterator_resync (it);
3337 g_assert_not_reached ();
3340 gst_iterator_free (it);
3342 query_ret = g_value_get_boolean (&ret);
3344 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3345 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3346 fold_data.min, fold_data.max);
3348 if (fold_data.min > fold_data.max) {
3349 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3352 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3354 GST_LOG_OBJECT (pad, "latency query failed");
3364 gboolean dispatched;
3368 query_forward_func (GstPad * pad, QueryData * data)
3370 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3371 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3373 data->result |= gst_pad_peer_query (pad, data->query);
3375 data->dispatched = TRUE;
3377 /* stop on first successful reply */
3378 return data->result;
3382 * gst_pad_query_default:
3383 * @pad: a #GstPad to call the default query handler on.
3384 * @parent: (allow-none): the parent of @pad or %NULL
3385 * @query: (transfer none): the #GstQuery to handle.
3387 * Invokes the default query handler for the given pad.
3388 * The query is sent to all pads internally linked to @pad. Note that
3389 * if there are many possible sink pads that are internally linked to
3390 * @pad, only one will be sent the query.
3391 * Multi-sinkpad elements should implement custom query handlers.
3393 * Returns: %TRUE if the query was performed successfully.
3396 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3398 gboolean forward, ret = FALSE;
3400 switch (GST_QUERY_TYPE (query)) {
3401 case GST_QUERY_SCHEDULING:
3402 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3404 case GST_QUERY_ALLOCATION:
3405 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3407 case GST_QUERY_ACCEPT_CAPS:
3408 ret = gst_pad_query_accept_caps_default (pad, query);
3411 case GST_QUERY_CAPS:
3412 ret = gst_pad_query_caps_default (pad, query);
3415 case GST_QUERY_LATENCY:
3416 ret = gst_pad_query_latency_default (pad, query);
3419 case GST_QUERY_POSITION:
3420 case GST_QUERY_SEEKING:
3421 case GST_QUERY_FORMATS:
3422 case GST_QUERY_JITTER:
3423 case GST_QUERY_RATE:
3424 case GST_QUERY_CONVERT:
3430 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3431 query, GST_QUERY_TYPE_NAME (query));
3437 data.dispatched = FALSE;
3438 data.result = FALSE;
3440 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3442 if (data.dispatched) {
3445 /* nothing dispatched, assume drained */
3446 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3456 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3458 GstPad *pad = data->pad;
3459 GstPadProbeInfo *info = data->info;
3460 GstPadProbeType type, flags;
3461 GstPadProbeCallback callback;
3462 GstPadProbeReturn ret;
3463 gpointer original_data;
3465 /* if we have called this callback, do nothing */
3466 if (PROBE_COOKIE (hook) == data->cookie) {
3467 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3468 "hook %lu, cookie %u already called", hook->hook_id,
3469 PROBE_COOKIE (hook));
3473 PROBE_COOKIE (hook) = data->cookie;
3475 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3477 original_data = info->data;
3479 /* one of the scheduling types */
3480 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3483 if (G_UNLIKELY (data->handled)) {
3484 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3485 "probe previously returned HANDLED, not calling again");
3487 } else if (G_UNLIKELY (data->dropped)) {
3488 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3489 "probe previously returned DROPPED, not calling again");
3493 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3494 /* one of the data types for non-idle probes */
3495 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3496 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3498 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3499 /* one of the data types for non-idle probes */
3500 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3501 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3504 /* Type must have PULL or PUSH probe types */
3505 g_assert_not_reached ();
3508 /* one of the blocking types must match */
3509 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3510 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3512 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3513 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3515 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3516 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3517 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3520 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3521 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3522 PROBE_COOKIE (hook), flags);
3524 data->marshalled = TRUE;
3526 callback = (GstPadProbeCallback) hook->func;
3527 if (callback == NULL)
3530 info->id = hook->hook_id;
3532 GST_OBJECT_UNLOCK (pad);
3534 ret = callback (pad, info, hook->data);
3536 GST_OBJECT_LOCK (pad);
3538 if (original_data != NULL && info->data == NULL) {
3539 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3540 info->type = GST_PAD_PROBE_TYPE_INVALID;
3541 data->dropped = TRUE;
3545 case GST_PAD_PROBE_REMOVE:
3546 /* remove the probe */
3547 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3548 cleanup_hook (pad, hook);
3550 case GST_PAD_PROBE_DROP:
3551 /* need to drop the data, make sure other probes don't get called
3553 GST_DEBUG_OBJECT (pad, "asked to drop item");
3554 info->type = GST_PAD_PROBE_TYPE_INVALID;
3555 data->dropped = TRUE;
3557 case GST_PAD_PROBE_HANDLED:
3558 GST_DEBUG_OBJECT (pad, "probe handled data");
3559 data->handled = TRUE;
3561 case GST_PAD_PROBE_PASS:
3562 /* inform the pad block to let things pass */
3563 GST_DEBUG_OBJECT (pad, "asked to pass item");
3566 case GST_PAD_PROBE_OK:
3567 GST_DEBUG_OBJECT (pad, "probe returned OK");
3570 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3577 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3578 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3579 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3584 /* a probe that does not take or return any data */
3585 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3587 if (G_UNLIKELY (pad->num_probes)) { \
3588 GstFlowReturn pval = defaultval; \
3589 /* pass NULL as the data item */ \
3590 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3591 info.ABI.abi.flow_ret = defaultval; \
3592 ret = do_probe_callbacks (pad, &info, defaultval); \
3593 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3598 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3600 if (G_UNLIKELY (pad->num_probes)) { \
3601 /* pass the data item */ \
3602 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3603 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3604 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3605 /* store the possibly updated data item */ \
3606 data = GST_PAD_PROBE_INFO_DATA (&info); \
3607 /* if something went wrong, exit */ \
3608 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3609 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3610 ret = info.ABI.abi.flow_ret; \
3611 goto handle_label; \
3618 #define PROBE_PUSH(pad,mask,data,label) \
3619 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3620 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3621 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3622 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3623 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3625 static GstFlowReturn
3626 do_pad_idle_probe_wait (GstPad * pad)
3628 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3629 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3630 "waiting idle probe to be removed");
3631 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3632 GST_PAD_BLOCK_WAIT (pad);
3633 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3634 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3636 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3637 return GST_FLOW_FLUSHING;
3642 #define PROBE_TYPE_IS_SERIALIZED(i) \
3645 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3646 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3647 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3649 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3650 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3652 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3653 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3657 static GstFlowReturn
3658 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3659 GstFlowReturn defaultval)
3668 data.handled = FALSE;
3669 data.marshalled = FALSE;
3670 data.dropped = FALSE;
3671 data.cookie = ++pad->priv->probe_cookie;
3674 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3676 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3677 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3682 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3683 "do probes cookie %u", data.cookie);
3684 cookie = pad->priv->probe_list_cookie;
3686 g_hook_list_marshal (&pad->probes, TRUE,
3687 (GHookMarshaller) probe_hook_marshal, &data);
3689 /* if the list changed, call the new callbacks (they will not have their
3690 * cookie set to data.cookie */
3691 if (cookie != pad->priv->probe_list_cookie) {
3692 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3693 "probe list changed, restarting");
3697 /* the first item that dropped will stop the hooks and then we drop here */
3701 /* If one handler took care of it, let the the item pass */
3706 /* if no handler matched and we are blocking, let the item pass */
3707 if (!data.marshalled && is_block)
3710 /* At this point, all handlers returned either OK or PASS. If one handler
3711 * returned PASS, let the item pass */
3716 while (GST_PAD_IS_BLOCKED (pad)) {
3717 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3718 "we are blocked %d times", pad->num_blocked);
3720 /* we might have released the lock */
3721 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3724 /* now we block the streaming thread. It can be unlocked when we
3725 * deactivate the pad (which will also set the FLUSHING flag) or
3726 * when the pad is unblocked. A flushing event will also unblock
3727 * the pad after setting the FLUSHING flag. */
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "Waiting to be unblocked or set flushing");
3730 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3731 GST_PAD_BLOCK_WAIT (pad);
3732 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3733 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3735 /* if the list changed, call the new callbacks (they will not have their
3736 * cookie set to data.cookie */
3737 if (cookie != pad->priv->probe_list_cookie) {
3738 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3739 "probe list changed, restarting");
3743 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3753 GST_DEBUG_OBJECT (pad, "pad is flushing");
3754 return GST_FLOW_FLUSHING;
3758 GST_DEBUG_OBJECT (pad, "data is dropped");
3759 return GST_FLOW_CUSTOM_SUCCESS;
3763 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3764 GST_DEBUG_OBJECT (pad, "data is passed");
3769 GST_DEBUG_OBJECT (pad, "data was handled");
3770 return GST_FLOW_CUSTOM_SUCCESS_1;
3777 * gst_pad_get_offset:
3780 * Get the offset applied to the running time of @pad. @pad has to be a source
3783 * Returns: the offset.
3786 gst_pad_get_offset (GstPad * pad)
3790 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3792 GST_OBJECT_LOCK (pad);
3793 result = pad->offset;
3794 GST_OBJECT_UNLOCK (pad);
3800 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3802 ev->received = FALSE;
3807 * gst_pad_set_offset:
3809 * @offset: the offset
3811 * Set the offset that will be applied to the running time of @pad.
3814 gst_pad_set_offset (GstPad * pad, gint64 offset)
3816 g_return_if_fail (GST_IS_PAD (pad));
3818 GST_OBJECT_LOCK (pad);
3819 /* if nothing changed, do nothing */
3820 if (pad->offset == offset)
3823 pad->offset = offset;
3824 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3825 GST_STIME_ARGS (offset));
3827 /* resend all sticky events with updated offset on next buffer push */
3828 events_foreach (pad, mark_event_not_received, NULL);
3829 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3832 GST_OBJECT_UNLOCK (pad);
3839 /* If TRUE and ret is not OK this means
3840 * that pushing the EOS event failed
3844 /* If called for an event this is
3845 * the event that would be pushed
3846 * next. Don't forward sticky events
3847 * that would come after that */
3851 /* should be called with pad LOCK */
3853 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3855 PushStickyData *data = user_data;
3856 GstEvent *event = ev->event;
3859 GST_DEBUG_OBJECT (pad, "event %s was already received",
3860 GST_EVENT_TYPE_NAME (event));
3864 /* If we're called because of an sticky event, only forward
3865 * events that would come before this new event and the
3867 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3868 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3869 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3870 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3872 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3873 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3876 switch (data->ret) {
3878 ev->received = TRUE;
3879 GST_DEBUG_OBJECT (pad, "event %s marked received",
3880 GST_EVENT_TYPE_NAME (event));
3882 case GST_FLOW_CUSTOM_SUCCESS:
3883 /* we can't assume the event is received when it was dropped */
3884 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3885 GST_EVENT_TYPE_NAME (event));
3886 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3887 data->ret = GST_FLOW_OK;
3889 case GST_FLOW_CUSTOM_SUCCESS_1:
3890 /* event was ignored and should be sent later */
3891 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3892 GST_EVENT_TYPE_NAME (event));
3893 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3894 data->ret = GST_FLOW_OK;
3896 case GST_FLOW_NOT_LINKED:
3897 /* not linked is not a problem, we are sticky so the event will be
3898 * rescheduled to be sent later on re-link, but only for non-EOS events */
3899 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3900 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3901 data->ret = GST_FLOW_OK;
3902 ev->received = TRUE;
3906 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3907 gst_flow_get_name (data->ret));
3908 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3912 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3913 data->was_eos = TRUE;
3915 return data->ret == GST_FLOW_OK;
3918 /* check sticky events and push them when needed. should be called
3920 static inline GstFlowReturn
3921 check_sticky (GstPad * pad, GstEvent * event)
3923 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3925 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3926 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3928 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3929 events_foreach (pad, push_sticky, &data);
3931 /* If there's an EOS event we must push it downstream
3932 * even if sending a previous sticky event failed.
3933 * Otherwise the pipeline might wait forever for EOS.
3935 * Only do this if pushing another event than the EOS
3938 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3939 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3941 if (ev && !ev->received) {
3942 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3943 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3944 /* the event could have been dropped. Because this can only
3945 * happen if the user asked for it, it's not an error */
3946 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3947 data.ret = GST_FLOW_OK;
3957 * @pad: a #GstPad to invoke the default query on.
3958 * @query: (transfer none): the #GstQuery to perform.
3960 * Dispatches a query to a pad. The query should have been allocated by the
3961 * caller via one of the type-specific allocation functions. The element that
3962 * the pad belongs to is responsible for filling the query with an appropriate
3963 * response, which should then be parsed with a type-specific query parsing
3966 * Again, the caller is responsible for both the allocation and deallocation of
3967 * the query structure.
3969 * Please also note that some queries might need a running pipeline to work.
3971 * Returns: %TRUE if the query could be performed.
3974 gst_pad_query (GstPad * pad, GstQuery * query)
3977 gboolean res, serialized;
3978 GstPadQueryFunction func;
3979 GstPadProbeType type;
3982 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3983 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3985 if (GST_PAD_IS_SRC (pad)) {
3986 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3987 goto wrong_direction;
3988 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3989 } else if (GST_PAD_IS_SINK (pad)) {
3990 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3991 goto wrong_direction;
3992 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3994 goto unknown_direction;
3996 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3997 GST_QUERY_TYPE_NAME (query));
3998 GST_TRACER_PAD_QUERY_PRE (pad, query);
4000 serialized = GST_QUERY_IS_SERIALIZED (query);
4001 if (G_UNLIKELY (serialized))
4002 GST_PAD_STREAM_LOCK (pad);
4004 GST_OBJECT_LOCK (pad);
4005 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4006 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4007 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4009 ACQUIRE_PARENT (pad, parent, no_parent);
4010 GST_OBJECT_UNLOCK (pad);
4012 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4015 res = func (pad, parent, query);
4017 RELEASE_PARENT (parent);
4019 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4020 GST_QUERY_TYPE_NAME (query), res);
4021 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4026 GST_OBJECT_LOCK (pad);
4027 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4028 GST_OBJECT_UNLOCK (pad);
4030 if (G_UNLIKELY (serialized))
4031 GST_PAD_STREAM_UNLOCK (pad);
4038 g_warning ("pad %s:%s query %s in wrong direction",
4039 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4044 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4049 GST_DEBUG_OBJECT (pad, "had no parent");
4050 GST_OBJECT_UNLOCK (pad);
4051 if (G_UNLIKELY (serialized))
4052 GST_PAD_STREAM_UNLOCK (pad);
4057 GST_DEBUG_OBJECT (pad, "had no query function");
4058 RELEASE_PARENT (parent);
4059 if (G_UNLIKELY (serialized))
4060 GST_PAD_STREAM_UNLOCK (pad);
4065 GST_DEBUG_OBJECT (pad, "query failed");
4066 if (G_UNLIKELY (serialized))
4067 GST_PAD_STREAM_UNLOCK (pad);
4072 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4073 GST_OBJECT_UNLOCK (pad);
4074 if (G_UNLIKELY (serialized))
4075 GST_PAD_STREAM_UNLOCK (pad);
4077 /* if a probe dropped without handling, we don't sent it further but assume
4078 * that the probe did not answer the query and return FALSE */
4079 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4089 * gst_pad_peer_query:
4090 * @pad: a #GstPad to invoke the peer query on.
4091 * @query: (transfer none): the #GstQuery to perform.
4093 * Performs gst_pad_query() on the peer of @pad.
4095 * The caller is responsible for both the allocation and deallocation of
4096 * the query structure.
4098 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4099 * if @pad has no peer.
4102 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4105 GstPadProbeType type;
4106 gboolean res, serialized;
4109 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4110 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4112 if (GST_PAD_IS_SRC (pad)) {
4113 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4114 goto wrong_direction;
4115 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4116 } else if (GST_PAD_IS_SINK (pad)) {
4117 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4118 goto wrong_direction;
4119 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4121 goto unknown_direction;
4123 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4124 GST_QUERY_TYPE_NAME (query));
4126 serialized = GST_QUERY_IS_SERIALIZED (query);
4128 GST_OBJECT_LOCK (pad);
4129 if (GST_PAD_IS_SRC (pad) && serialized) {
4130 /* all serialized queries on the srcpad trigger push of
4132 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4136 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4137 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4138 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4140 peerpad = GST_PAD_PEER (pad);
4141 if (G_UNLIKELY (peerpad == NULL))
4144 gst_object_ref (peerpad);
4145 GST_OBJECT_UNLOCK (pad);
4147 res = gst_pad_query (peerpad, query);
4149 gst_object_unref (peerpad);
4154 GST_OBJECT_LOCK (pad);
4155 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4156 GST_OBJECT_UNLOCK (pad);
4163 g_warning ("pad %s:%s query %s in wrong direction",
4164 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4169 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4174 GST_WARNING_OBJECT (pad, "could not send sticky events");
4175 GST_OBJECT_UNLOCK (pad);
4180 GST_INFO_OBJECT (pad, "pad has no peer");
4181 GST_OBJECT_UNLOCK (pad);
4186 GST_DEBUG_OBJECT (pad, "query failed");
4191 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4192 GST_OBJECT_UNLOCK (pad);
4194 /* if a probe dropped without handling, we don't sent it further but
4195 * assume that the probe did not answer the query and return FALSE */
4196 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4205 /**********************************************************************
4206 * Data passing functions
4209 /* this is the chain function that does not perform the additional argument
4210 * checking for that little extra speed.
4212 static inline GstFlowReturn
4213 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4217 gboolean handled = FALSE;
4219 GST_PAD_STREAM_LOCK (pad);
4221 GST_OBJECT_LOCK (pad);
4222 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4225 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4228 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4231 #ifdef GST_ENABLE_EXTRA_CHECKS
4232 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4233 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4235 ":%s:<%s:%s> Got data flow before stream-start event",
4236 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4238 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4240 ":%s:<%s:%s> Got data flow before segment event",
4241 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4243 pad->priv->last_cookie = pad->priv->events_cookie;
4247 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4250 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4252 ACQUIRE_PARENT (pad, parent, no_parent);
4253 GST_OBJECT_UNLOCK (pad);
4255 /* NOTE: we read the chainfunc unlocked.
4256 * we cannot hold the lock for the pad so we might send
4257 * the data to the wrong function. This is not really a
4258 * problem since functions are assigned at creation time
4259 * and don't change that often... */
4260 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4261 GstPadChainFunction chainfunc;
4263 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4266 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4267 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4268 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4270 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4272 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4273 "called chainfunction &%s with buffer %p, returned %s",
4274 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4276 GstPadChainListFunction chainlistfunc;
4278 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4281 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4282 "calling chainlistfunction &%s",
4283 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4285 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4287 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4288 "called chainlistfunction &%s, returned %s",
4289 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4292 RELEASE_PARENT (parent);
4294 GST_PAD_STREAM_UNLOCK (pad);
4301 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4302 "chaining, but pad was flushing");
4303 GST_OBJECT_UNLOCK (pad);
4304 GST_PAD_STREAM_UNLOCK (pad);
4305 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4306 return GST_FLOW_FLUSHING;
4310 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4311 GST_OBJECT_UNLOCK (pad);
4312 GST_PAD_STREAM_UNLOCK (pad);
4313 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4314 return GST_FLOW_EOS;
4318 g_critical ("chain on pad %s:%s but it was not in push mode",
4319 GST_DEBUG_PAD_NAME (pad));
4320 GST_OBJECT_UNLOCK (pad);
4321 GST_PAD_STREAM_UNLOCK (pad);
4322 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4323 return GST_FLOW_ERROR;
4330 GST_OBJECT_UNLOCK (pad);
4331 GST_PAD_STREAM_UNLOCK (pad);
4332 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4334 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4337 case GST_FLOW_CUSTOM_SUCCESS:
4338 case GST_FLOW_CUSTOM_SUCCESS_1:
4339 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4343 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4350 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4351 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4352 GST_OBJECT_UNLOCK (pad);
4353 GST_PAD_STREAM_UNLOCK (pad);
4354 return GST_FLOW_FLUSHING;
4358 RELEASE_PARENT (parent);
4359 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4360 g_critical ("chain on pad %s:%s but it has no chainfunction",
4361 GST_DEBUG_PAD_NAME (pad));
4362 GST_PAD_STREAM_UNLOCK (pad);
4363 return GST_FLOW_NOT_SUPPORTED;
4369 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4370 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4373 * Chain a buffer to @pad.
4375 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4377 * If the buffer type is not acceptable for @pad (as negotiated with a
4378 * preceding GST_EVENT_CAPS event), this function returns
4379 * #GST_FLOW_NOT_NEGOTIATED.
4381 * The function proceeds calling the chain function installed on @pad (see
4382 * gst_pad_set_chain_function()) and the return value of that function is
4383 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4386 * In all cases, success or failure, the caller loses its reference to @buffer
4387 * after calling this function.
4389 * Returns: a #GstFlowReturn from the pad.
4394 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4396 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4397 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4398 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4400 return gst_pad_chain_data_unchecked (pad,
4401 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4404 static GstFlowReturn
4405 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4406 GstBufferList * list)
4412 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4414 len = gst_buffer_list_length (list);
4417 for (i = 0; i < len; i++) {
4418 buffer = gst_buffer_list_get (list, i);
4420 gst_pad_chain_data_unchecked (pad,
4421 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4422 gst_buffer_ref (buffer));
4423 if (ret != GST_FLOW_OK)
4426 gst_buffer_list_unref (list);
4432 * gst_pad_chain_list:
4433 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4434 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4437 * Chain a bufferlist to @pad.
4439 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4441 * If @pad was not negotiated properly with a CAPS event, this function
4442 * returns #GST_FLOW_NOT_NEGOTIATED.
4444 * The function proceeds calling the chainlist function installed on @pad (see
4445 * gst_pad_set_chain_list_function()) and the return value of that function is
4446 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4447 * chainlist function.
4449 * In all cases, success or failure, the caller loses its reference to @list
4450 * after calling this function.
4454 * Returns: a #GstFlowReturn from the pad.
4457 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4459 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4460 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4461 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4463 return gst_pad_chain_data_unchecked (pad,
4464 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4467 static GstFlowReturn
4468 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4472 gboolean handled = FALSE;
4474 GST_OBJECT_LOCK (pad);
4475 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4478 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4481 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4484 #ifdef GST_ENABLE_EXTRA_CHECKS
4485 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4486 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4488 ":%s:<%s:%s> Got data flow before stream-start event",
4489 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4491 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4493 ":%s:<%s:%s> Got data flow before segment event",
4494 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4496 pad->priv->last_cookie = pad->priv->events_cookie;
4500 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4503 /* do block probes */
4504 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4507 /* recheck sticky events because the probe might have cause a relink */
4508 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4511 /* do post-blocking probes */
4512 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4514 /* recheck sticky events because the probe might have cause a relink */
4515 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4518 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4521 /* take ref to peer pad before releasing the lock */
4522 gst_object_ref (peer);
4524 GST_OBJECT_UNLOCK (pad);
4526 ret = gst_pad_chain_data_unchecked (peer, type, data);
4529 gst_object_unref (peer);
4531 GST_OBJECT_LOCK (pad);
4532 pad->ABI.abi.last_flowret = ret;
4534 if (pad->priv->using == 0) {
4535 /* pad is not active anymore, trigger idle callbacks */
4536 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4537 probe_stopped, ret);
4539 GST_OBJECT_UNLOCK (pad);
4543 /* ERROR recovery here */
4547 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4548 "pushing, but pad was flushing");
4549 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4550 GST_OBJECT_UNLOCK (pad);
4551 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4552 return GST_FLOW_FLUSHING;
4556 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4557 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4558 GST_OBJECT_UNLOCK (pad);
4559 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4560 return GST_FLOW_EOS;
4564 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4565 GST_DEBUG_PAD_NAME (pad));
4566 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4567 GST_OBJECT_UNLOCK (pad);
4568 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4569 return GST_FLOW_ERROR;
4573 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4574 "error pushing events, return %s", gst_flow_get_name (ret));
4575 pad->ABI.abi.last_flowret = ret;
4576 GST_OBJECT_UNLOCK (pad);
4577 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4585 GST_OBJECT_UNLOCK (pad);
4586 if (data != NULL && !handled)
4587 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4590 case GST_FLOW_CUSTOM_SUCCESS:
4591 case GST_FLOW_CUSTOM_SUCCESS_1:
4592 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4596 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4599 pad->ABI.abi.last_flowret = ret;
4604 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4605 "pushing, but it was not linked");
4606 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4607 GST_OBJECT_UNLOCK (pad);
4608 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4609 return GST_FLOW_NOT_LINKED;
4615 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4616 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4619 * Pushes a buffer to the peer of @pad.
4621 * This function will call installed block probes before triggering any
4622 * installed data probes.
4624 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4625 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4628 * In all cases, success or failure, the caller loses its reference to @buffer
4629 * after calling this function.
4631 * Returns: a #GstFlowReturn from the peer pad.
4636 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4640 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4641 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4642 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4644 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4645 res = gst_pad_push_data (pad,
4646 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4647 GST_TRACER_PAD_PUSH_POST (pad, res);
4652 * gst_pad_push_list:
4653 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4654 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4657 * Pushes a buffer list to the peer of @pad.
4659 * This function will call installed block probes before triggering any
4660 * installed data probes.
4662 * The function proceeds calling the chain function on the peer pad and returns
4663 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4664 * be returned. If the peer pad does not have any installed chainlist function
4665 * every group buffer of the list will be merged into a normal #GstBuffer and
4666 * chained via gst_pad_chain().
4668 * In all cases, success or failure, the caller loses its reference to @list
4669 * after calling this function.
4671 * Returns: a #GstFlowReturn from the peer pad.
4676 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4680 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4681 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4682 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4684 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4685 res = gst_pad_push_data (pad,
4686 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4687 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4691 static GstFlowReturn
4692 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4693 GstBuffer ** buffer)
4696 GstPadGetRangeFunction getrangefunc;
4700 GST_PAD_STREAM_LOCK (pad);
4702 GST_OBJECT_LOCK (pad);
4703 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4706 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4709 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4714 /* when one of the probes returns DROPPED, probe_stopped will be called
4715 * and we skip calling the getrange function, res_buf should then contain a
4716 * valid result buffer */
4717 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4718 res_buf, offset, size, probe_stopped);
4720 /* recheck sticky events because the probe might have cause a relink */
4721 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4724 ACQUIRE_PARENT (pad, parent, no_parent);
4725 GST_OBJECT_UNLOCK (pad);
4727 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4730 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4731 "calling getrangefunc %s, offset %"
4732 G_GUINT64_FORMAT ", size %u",
4733 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4735 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4737 RELEASE_PARENT (parent);
4739 GST_OBJECT_LOCK (pad);
4740 if (G_UNLIKELY (ret != GST_FLOW_OK))
4741 goto get_range_failed;
4743 /* can only fire the signal if we have a valid buffer */
4745 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4746 res_buf, offset, size, probe_stopped_unref);
4747 pad->ABI.abi.last_flowret = ret;
4748 GST_OBJECT_UNLOCK (pad);
4750 GST_PAD_STREAM_UNLOCK (pad);
4759 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4760 "getrange, but pad was flushing");
4761 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4762 GST_OBJECT_UNLOCK (pad);
4763 GST_PAD_STREAM_UNLOCK (pad);
4764 return GST_FLOW_FLUSHING;
4768 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4769 GST_DEBUG_PAD_NAME (pad));
4770 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4771 GST_OBJECT_UNLOCK (pad);
4772 GST_PAD_STREAM_UNLOCK (pad);
4773 return GST_FLOW_ERROR;
4777 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4778 pad->ABI.abi.last_flowret = ret;
4779 GST_OBJECT_UNLOCK (pad);
4780 GST_PAD_STREAM_UNLOCK (pad);
4785 GST_DEBUG_OBJECT (pad, "no parent");
4786 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4787 GST_OBJECT_UNLOCK (pad);
4788 GST_PAD_STREAM_UNLOCK (pad);
4789 return GST_FLOW_FLUSHING;
4793 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4794 GST_DEBUG_PAD_NAME (pad));
4795 RELEASE_PARENT (parent);
4796 GST_PAD_STREAM_UNLOCK (pad);
4797 return GST_FLOW_NOT_SUPPORTED;
4801 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4802 "probe returned %s", gst_flow_get_name (ret));
4803 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4805 /* the probe filled the buffer and asks us to not call the getrange
4806 * anymore, we continue with the post probes then. */
4807 GST_DEBUG_OBJECT (pad, "handled buffer");
4811 /* no buffer, we are EOS */
4812 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4816 pad->ABI.abi.last_flowret = ret;
4817 GST_OBJECT_UNLOCK (pad);
4818 GST_PAD_STREAM_UNLOCK (pad);
4822 probe_stopped_unref:
4824 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4825 "probe returned %s", gst_flow_get_name (ret));
4826 /* if we drop here, it signals EOS */
4827 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4829 pad->ABI.abi.last_flowret = ret;
4830 GST_OBJECT_UNLOCK (pad);
4831 GST_PAD_STREAM_UNLOCK (pad);
4832 if (*buffer == NULL)
4833 gst_buffer_unref (res_buf);
4838 pad->ABI.abi.last_flowret = ret;
4839 GST_OBJECT_UNLOCK (pad);
4840 GST_PAD_STREAM_UNLOCK (pad);
4841 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4842 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4843 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4849 * gst_pad_get_range:
4850 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4851 * @offset: The start offset of the buffer
4852 * @size: The length of the buffer
4853 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4854 * returns #GST_FLOW_ERROR if %NULL.
4856 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4857 * immediately and @buffer is %NULL.
4859 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4860 * description of a getrange function. If @pad has no getrange function
4861 * installed (see gst_pad_set_getrange_function()) this function returns
4862 * #GST_FLOW_NOT_SUPPORTED.
4864 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4865 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4866 * must be freed with gst_buffer_unref() after usage.
4868 * When @buffer points to a variable that points to a valid #GstBuffer, the
4869 * buffer will be filled with the result data when this function returns
4870 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4871 * @size bytes will be filled in the result buffer and its size will be updated
4874 * Note that less than @size bytes can be returned in @buffer when, for example,
4875 * an EOS condition is near or when @buffer is not large enough to hold @size
4876 * bytes. The caller should check the result buffer size to get the result size.
4878 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4879 * will be unchanged.
4881 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4883 * Returns: a #GstFlowReturn from the pad.
4888 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4889 GstBuffer ** buffer)
4891 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4892 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4893 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4894 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4895 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4897 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4901 * gst_pad_pull_range:
4902 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4903 * @offset: The start offset of the buffer
4904 * @size: The length of the buffer
4905 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4906 * GST_FLOW_ERROR if %NULL.
4908 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4910 * This function will first trigger the pad block signal if it was
4913 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4914 * function returns the result of gst_pad_get_range() on the peer pad.
4915 * See gst_pad_get_range() for a list of return values and for the
4916 * semantics of the arguments of this function.
4918 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4919 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4920 * must be freed with gst_buffer_unref() after usage. When this function
4921 * returns any other result value, @buffer will still point to %NULL.
4923 * When @buffer points to a variable that points to a valid #GstBuffer, the
4924 * buffer will be filled with the result data when this function returns
4925 * #GST_FLOW_OK. When this function returns any other result value,
4926 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4927 * @size bytes will be filled in the result buffer and its size will be updated
4930 * Note that less than @size bytes can be returned in @buffer when, for example,
4931 * an EOS condition is near or when @buffer is not large enough to hold @size
4932 * bytes. The caller should check the result buffer size to get the result size.
4934 * Returns: a #GstFlowReturn from the peer pad.
4939 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4940 GstBuffer ** buffer)
4946 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4947 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4948 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4949 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4950 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4952 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4954 GST_OBJECT_LOCK (pad);
4955 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4958 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4963 /* when one of the probes returns DROPPED, probe_stopped will be
4964 * called and we skip calling the peer getrange function. *buffer should then
4965 * contain a valid buffer */
4966 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4967 res_buf, offset, size, probe_stopped);
4969 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4972 gst_object_ref (peer);
4974 GST_OBJECT_UNLOCK (pad);
4976 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4978 gst_object_unref (peer);
4980 GST_OBJECT_LOCK (pad);
4982 pad->ABI.abi.last_flowret = ret;
4983 if (pad->priv->using == 0) {
4984 /* pad is not active anymore, trigger idle callbacks */
4985 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4986 probe_stopped_unref, ret);
4989 if (G_UNLIKELY (ret != GST_FLOW_OK))
4990 goto pull_range_failed;
4993 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4994 res_buf, offset, size, probe_stopped_unref);
4996 GST_OBJECT_UNLOCK (pad);
5000 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5003 /* ERROR recovery here */
5006 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5007 "pullrange, but pad was flushing");
5008 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5009 GST_OBJECT_UNLOCK (pad);
5010 ret = GST_FLOW_FLUSHING;
5015 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5016 GST_DEBUG_PAD_NAME (pad));
5017 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5018 GST_OBJECT_UNLOCK (pad);
5019 ret = GST_FLOW_ERROR;
5024 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5025 gst_flow_get_name (ret));
5026 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5028 /* the probe filled the buffer and asks us to not forward to the peer
5029 * anymore, we continue with the post probes then */
5030 GST_DEBUG_OBJECT (pad, "handled buffer");
5034 /* no buffer, we are EOS then */
5035 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5039 pad->ABI.abi.last_flowret = ret;
5040 GST_OBJECT_UNLOCK (pad);
5045 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5046 "pulling range, but it was not linked");
5047 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5048 GST_OBJECT_UNLOCK (pad);
5049 ret = GST_FLOW_NOT_LINKED;
5054 pad->ABI.abi.last_flowret = ret;
5055 GST_OBJECT_UNLOCK (pad);
5056 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5057 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5058 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5061 probe_stopped_unref:
5063 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5064 "post probe returned %s", gst_flow_get_name (ret));
5066 /* if we drop here, it signals EOS */
5067 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5070 pad->ABI.abi.last_flowret = ret;
5071 GST_OBJECT_UNLOCK (pad);
5073 if (*buffer == NULL)
5074 gst_buffer_unref (res_buf);
5078 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5082 /* must be called with pad object lock */
5083 static GstFlowReturn
5084 store_sticky_event (GstPad * pad, GstEvent * event)
5089 gboolean res = FALSE;
5090 const gchar *name = NULL;
5091 gboolean insert = TRUE;
5093 type = GST_EVENT_TYPE (event);
5095 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5096 * otherwise they can be dropped and nothing would ever resend them.
5097 * Only do that for activated pads though, everything else is a bug!
5099 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5100 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5101 || type == GST_EVENT_EOS))))
5104 /* Unset the EOS flag when received STREAM_START event, so pad can
5105 * store sticky event and then push it later */
5106 if (type == GST_EVENT_STREAM_START) {
5107 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5108 remove_event_by_type (pad, GST_EVENT_EOS);
5109 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5110 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5113 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5116 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5117 name = gst_structure_get_name (gst_event_get_structure (event));
5119 events = pad->priv->events;
5122 for (i = 0; i < len; i++) {
5123 PadEvent *ev = &g_array_index (events, PadEvent, i);
5125 if (ev->event == NULL)
5128 if (type == GST_EVENT_TYPE (ev->event)) {
5129 /* matching types, check matching name if needed */
5130 if (name && !gst_event_has_name (ev->event, name))
5134 if ((res = gst_event_replace (&ev->event, event)))
5135 ev->received = FALSE;
5141 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5142 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5143 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5144 * storing the sticky ordered we can check that this is respected. */
5145 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5146 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5148 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5149 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5150 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5151 gst_event_type_get_name (type));
5157 ev.event = gst_event_ref (event);
5158 ev.received = FALSE;
5159 g_array_insert_val (events, i, ev);
5164 pad->priv->events_cookie++;
5165 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5167 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5169 switch (GST_EVENT_TYPE (event)) {
5170 case GST_EVENT_CAPS:
5171 GST_OBJECT_UNLOCK (pad);
5173 GST_DEBUG_OBJECT (pad, "notify caps");
5174 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5176 GST_OBJECT_LOCK (pad);
5182 if (type == GST_EVENT_EOS) {
5183 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5184 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5187 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5192 GST_DEBUG_OBJECT (pad, "pad is flushing");
5193 return GST_FLOW_FLUSHING;
5197 GST_DEBUG_OBJECT (pad, "pad is EOS");
5198 return GST_FLOW_EOS;
5203 * gst_pad_store_sticky_event:
5205 * @event: (transfer none): a #GstEvent
5207 * Store the sticky @event on @pad
5209 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5210 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5215 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5219 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5220 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5222 GST_OBJECT_LOCK (pad);
5223 ret = store_sticky_event (pad, event);
5224 GST_OBJECT_UNLOCK (pad);
5230 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5232 PushStickyData *data = user_data;
5234 /* Forward all sticky events before our current one that are pending */
5235 if (ev->event != data->event
5236 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5237 return push_sticky (pad, ev, data);
5242 /* should be called with pad LOCK */
5243 static GstFlowReturn
5244 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5245 GstPadProbeType type)
5249 GstEventType event_type;
5251 /* pass the adjusted event on. We need to do this even if
5252 * there is no peer pad because of the probes. */
5253 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5255 /* Two checks to be made:
5256 * . (un)set the FLUSHING flag for flushing events,
5257 * . handle pad blocking */
5258 event_type = GST_EVENT_TYPE (event);
5259 switch (event_type) {
5260 case GST_EVENT_FLUSH_START:
5261 GST_PAD_SET_FLUSHING (pad);
5263 GST_PAD_BLOCK_BROADCAST (pad);
5264 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5266 case GST_EVENT_FLUSH_STOP:
5267 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5270 GST_PAD_UNSET_FLUSHING (pad);
5272 /* Remove sticky EOS events */
5273 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5274 remove_event_by_type (pad, GST_EVENT_EOS);
5275 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5276 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5277 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5278 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5280 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5284 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5287 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5288 * checked already or this is called as part of pushing sticky events,
5289 * in which case we still want to forward the EOS event downstream.
5292 switch (GST_EVENT_TYPE (event)) {
5293 case GST_EVENT_RECONFIGURE:
5294 if (GST_PAD_IS_SINK (pad))
5295 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5300 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5301 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5302 /* recheck sticky events because the probe might have cause a relink */
5303 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5304 && (GST_EVENT_IS_SERIALIZED (event)
5305 || GST_EVENT_IS_STICKY (event))) {
5306 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5307 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5309 /* Push all sticky events before our current one
5310 * that have changed */
5311 events_foreach (pad, sticky_changed, &data);
5317 /* send probes after modifying the events above */
5318 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5320 /* recheck sticky events because the probe might have cause a relink */
5321 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5322 && (GST_EVENT_IS_SERIALIZED (event)
5323 || GST_EVENT_IS_STICKY (event))) {
5324 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5325 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5327 /* Push all sticky events before our current one
5328 * that have changed */
5329 events_foreach (pad, sticky_changed, &data);
5332 /* now check the peer pad */
5333 peerpad = GST_PAD_PEER (pad);
5334 if (peerpad == NULL)
5337 gst_object_ref (peerpad);
5339 GST_OBJECT_UNLOCK (pad);
5341 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5342 event, gst_event_type_get_name (event_type), peerpad);
5344 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5346 /* Note: we gave away ownership of the event at this point but we can still
5347 * print the old pointer */
5348 GST_LOG_OBJECT (pad,
5349 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5350 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5352 gst_object_unref (peerpad);
5354 GST_OBJECT_LOCK (pad);
5356 if (pad->priv->using == 0) {
5357 /* pad is not active anymore, trigger idle callbacks */
5358 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5359 idle_probe_stopped, ret);
5363 /* ERROR handling */
5366 GST_DEBUG_OBJECT (pad, "We're flushing");
5367 gst_event_unref (event);
5368 return GST_FLOW_FLUSHING;
5372 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5373 gst_event_unref (event);
5374 return GST_FLOW_FLUSHING;
5378 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5379 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5380 gst_event_unref (event);
5383 case GST_FLOW_CUSTOM_SUCCESS_1:
5384 GST_DEBUG_OBJECT (pad, "handled event");
5386 case GST_FLOW_CUSTOM_SUCCESS:
5387 GST_DEBUG_OBJECT (pad, "dropped event");
5390 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5397 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5398 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5399 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5400 gst_event_unref (event);
5402 /* unlinked pads should not influence latency configuration */
5403 if (event_type == GST_EVENT_LATENCY)
5406 return GST_FLOW_NOT_LINKED;
5410 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5416 * gst_pad_push_event:
5417 * @pad: a #GstPad to push the event to.
5418 * @event: (transfer full): the #GstEvent to send to the pad.
5420 * Sends the event to the peer of the given pad. This function is
5421 * mainly used by elements to send events to their peer
5424 * This function takes ownership of the provided event so you should
5425 * gst_event_ref() it if you want to reuse the event after this call.
5427 * Returns: %TRUE if the event was handled.
5432 gst_pad_push_event (GstPad * pad, GstEvent * event)
5434 gboolean res = FALSE;
5435 GstPadProbeType type;
5436 gboolean sticky, serialized;
5438 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5439 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5441 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5443 if (GST_PAD_IS_SRC (pad)) {
5444 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5445 goto wrong_direction;
5446 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5447 } else if (GST_PAD_IS_SINK (pad)) {
5448 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5449 goto wrong_direction;
5450 /* events pushed on sinkpad never are sticky */
5451 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5453 goto unknown_direction;
5455 GST_OBJECT_LOCK (pad);
5456 sticky = GST_EVENT_IS_STICKY (event);
5457 serialized = GST_EVENT_IS_SERIALIZED (event);
5460 /* srcpad sticky events are stored immediately, the received flag is set
5461 * to FALSE and will be set to TRUE when we can successfully push the
5462 * event to the peer pad */
5463 switch (store_sticky_event (pad, event)) {
5464 case GST_FLOW_FLUSHING:
5472 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5473 /* all serialized or sticky events on the srcpad trigger push of
5475 res = (check_sticky (pad, event) == GST_FLOW_OK);
5480 /* other events are pushed right away */
5481 ret = gst_pad_push_event_unchecked (pad, event, type);
5482 /* dropped events by a probe are not an error */
5483 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5484 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5486 /* Errors in sticky event pushing are no problem and ignored here
5487 * as they will cause more meaningful errors during data flow.
5488 * For EOS events, that are not followed by data flow, we still
5489 * return FALSE here though.
5491 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5493 gst_event_unref (event);
5495 GST_OBJECT_UNLOCK (pad);
5497 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5500 /* ERROR handling */
5503 g_warning ("pad %s:%s pushing %s event in wrong direction",
5504 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5505 gst_event_unref (event);
5510 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5511 gst_event_unref (event);
5516 GST_DEBUG_OBJECT (pad, "We're flushing");
5517 GST_OBJECT_UNLOCK (pad);
5518 gst_event_unref (event);
5523 GST_DEBUG_OBJECT (pad, "We're EOS");
5524 GST_OBJECT_UNLOCK (pad);
5525 gst_event_unref (event);
5529 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5533 /* Check if we can call the event function with the given event */
5534 static GstFlowReturn
5535 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5539 switch (GST_EVENT_TYPE (event)) {
5540 case GST_EVENT_CAPS:
5542 /* backwards compatibility mode for caps */
5543 gst_event_parse_caps (event, &caps);
5545 if (!gst_pad_query_accept_caps (pad, caps))
5557 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5558 "caps %" GST_PTR_FORMAT " not accepted", caps);
5559 return GST_FLOW_NOT_NEGOTIATED;
5563 static GstFlowReturn
5564 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5565 GstPadProbeType type)
5568 GstEventType event_type;
5569 gboolean serialized, need_unlock = FALSE, sticky;
5570 GstPadEventFunction eventfunc;
5571 GstPadEventFullFunction eventfullfunc = NULL;
5574 GST_OBJECT_LOCK (pad);
5576 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5578 if (GST_PAD_IS_SINK (pad))
5579 serialized = GST_EVENT_IS_SERIALIZED (event);
5582 sticky = GST_EVENT_IS_STICKY (event);
5583 event_type = GST_EVENT_TYPE (event);
5584 switch (event_type) {
5585 case GST_EVENT_FLUSH_START:
5586 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5587 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5589 /* can't even accept a flush begin event when flushing */
5590 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5593 GST_PAD_SET_FLUSHING (pad);
5594 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5595 GST_PAD_BLOCK_BROADCAST (pad);
5596 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5598 case GST_EVENT_FLUSH_STOP:
5599 /* we can't accept flush-stop on inactive pads else the flushing flag
5600 * would be cleared and it would look like the pad can accept data.
5601 * Also, some elements restart a streaming thread in flush-stop which we
5602 * can't allow on inactive pads */
5603 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5606 GST_PAD_UNSET_FLUSHING (pad);
5607 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5608 /* Remove pending EOS events */
5609 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5610 remove_event_by_type (pad, GST_EVENT_EOS);
5611 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5612 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5613 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5614 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5616 GST_OBJECT_UNLOCK (pad);
5617 /* grab stream lock */
5618 GST_PAD_STREAM_LOCK (pad);
5620 GST_OBJECT_LOCK (pad);
5621 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5624 case GST_EVENT_RECONFIGURE:
5625 if (GST_PAD_IS_SRC (pad))
5626 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5628 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5629 "have event type %" GST_PTR_FORMAT, event);
5631 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5634 switch (event_type) {
5635 case GST_EVENT_STREAM_START:
5636 /* Remove sticky EOS events */
5637 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5638 remove_event_by_type (pad, GST_EVENT_EOS);
5639 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5640 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5647 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5650 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5651 GST_OBJECT_UNLOCK (pad);
5652 GST_PAD_STREAM_LOCK (pad);
5654 GST_OBJECT_LOCK (pad);
5655 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5658 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5664 /* now do the probe */
5666 type | GST_PAD_PROBE_TYPE_PUSH |
5667 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5669 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5671 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5672 eventfunc = GST_PAD_EVENTFUNC (pad);
5673 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5676 ACQUIRE_PARENT (pad, parent, no_parent);
5677 GST_OBJECT_UNLOCK (pad);
5679 ret = pre_eventfunc_check (pad, event);
5680 if (G_UNLIKELY (ret != GST_FLOW_OK))
5681 goto precheck_failed;
5684 gst_event_ref (event);
5686 if (eventfullfunc) {
5687 ret = eventfullfunc (pad, parent, event);
5688 } else if (eventfunc (pad, parent, event)) {
5691 /* something went wrong */
5692 switch (event_type) {
5693 case GST_EVENT_CAPS:
5694 ret = GST_FLOW_NOT_NEGOTIATED;
5697 ret = GST_FLOW_ERROR;
5701 RELEASE_PARENT (parent);
5703 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5706 if (ret == GST_FLOW_OK) {
5707 GST_OBJECT_LOCK (pad);
5708 /* after the event function accepted the event, we can store the sticky
5709 * event on the pad */
5710 switch (store_sticky_event (pad, event)) {
5711 case GST_FLOW_FLUSHING:
5718 GST_OBJECT_UNLOCK (pad);
5720 gst_event_unref (event);
5724 GST_PAD_STREAM_UNLOCK (pad);
5728 /* ERROR handling */
5731 GST_OBJECT_UNLOCK (pad);
5733 GST_PAD_STREAM_UNLOCK (pad);
5734 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5735 "Received event on flushing pad. Discarding");
5736 gst_event_unref (event);
5737 return GST_FLOW_FLUSHING;
5741 GST_OBJECT_UNLOCK (pad);
5743 GST_PAD_STREAM_UNLOCK (pad);
5744 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5745 "Received flush-stop on inactive pad. Discarding");
5746 gst_event_unref (event);
5747 return GST_FLOW_FLUSHING;
5751 GST_OBJECT_UNLOCK (pad);
5753 GST_PAD_STREAM_UNLOCK (pad);
5754 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5755 "Received event on EOS pad. Discarding");
5756 gst_event_unref (event);
5757 return GST_FLOW_EOS;
5761 GST_OBJECT_UNLOCK (pad);
5763 GST_PAD_STREAM_UNLOCK (pad);
5764 /* Only unref if unhandled */
5765 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5766 gst_event_unref (event);
5769 case GST_FLOW_CUSTOM_SUCCESS_1:
5770 case GST_FLOW_CUSTOM_SUCCESS:
5771 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5775 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5782 g_warning ("pad %s:%s has no event handler, file a bug.",
5783 GST_DEBUG_PAD_NAME (pad));
5784 GST_OBJECT_UNLOCK (pad);
5786 GST_PAD_STREAM_UNLOCK (pad);
5787 gst_event_unref (event);
5788 return GST_FLOW_NOT_SUPPORTED;
5792 GST_DEBUG_OBJECT (pad, "no parent");
5793 GST_OBJECT_UNLOCK (pad);
5795 GST_PAD_STREAM_UNLOCK (pad);
5796 gst_event_unref (event);
5797 return GST_FLOW_FLUSHING;
5801 GST_DEBUG_OBJECT (pad, "pre event check failed");
5802 RELEASE_PARENT (parent);
5804 GST_PAD_STREAM_UNLOCK (pad);
5805 gst_event_unref (event);
5811 * gst_pad_send_event:
5812 * @pad: a #GstPad to send the event to.
5813 * @event: (transfer full): the #GstEvent to send to the pad.
5815 * Sends the event to the pad. This function can be used
5816 * by applications to send events in the pipeline.
5818 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5819 * sink pad, @event should be a downstream event. For example, you would not
5820 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5821 * Furthermore, some downstream events have to be serialized with data flow,
5822 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5823 * the event needs to be serialized with data flow, this function will take the
5824 * pad's stream lock while calling its event function.
5826 * To find out whether an event type is upstream, downstream, or downstream and
5827 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5828 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5829 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5830 * plugin doesn't need to bother itself with this information; the core handles
5831 * all necessary locks and checks.
5833 * This function takes ownership of the provided event so you should
5834 * gst_event_ref() it if you want to reuse the event after this call.
5836 * Returns: %TRUE if the event was handled.
5839 gst_pad_send_event (GstPad * pad, GstEvent * event)
5842 GstPadProbeType type;
5844 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5845 g_return_val_if_fail (event != NULL, FALSE);
5847 if (GST_PAD_IS_SINK (pad)) {
5848 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5849 goto wrong_direction;
5850 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5851 } else if (GST_PAD_IS_SRC (pad)) {
5852 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5853 goto wrong_direction;
5854 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5856 goto unknown_direction;
5858 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5865 /* ERROR handling */
5868 g_warning ("pad %s:%s sending %s event in wrong direction",
5869 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5870 gst_event_unref (event);
5875 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5876 gst_event_unref (event);
5882 * gst_pad_set_element_private:
5883 * @pad: the #GstPad to set the private data of.
5884 * @priv: The private data to attach to the pad.
5886 * Set the given private data gpointer on the pad.
5887 * This function can only be used by the element that owns the pad.
5888 * No locking is performed in this function.
5891 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5893 pad->element_private = priv;
5897 * gst_pad_get_element_private:
5898 * @pad: the #GstPad to get the private data of.
5900 * Gets the private data of a pad.
5901 * No locking is performed in this function.
5903 * Returns: (transfer none): a #gpointer to the private data.
5906 gst_pad_get_element_private (GstPad * pad)
5908 return pad->element_private;
5912 * gst_pad_get_sticky_event:
5913 * @pad: the #GstPad to get the event from.
5914 * @event_type: the #GstEventType that should be retrieved.
5915 * @idx: the index of the event
5917 * Returns a new reference of the sticky event of type @event_type
5920 * Returns: (transfer full) (nullable): a #GstEvent of type
5921 * @event_type or %NULL when no event of @event_type was on
5922 * @pad. Unref after usage.
5925 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5927 GstEvent *event = NULL;
5930 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5931 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5933 GST_OBJECT_LOCK (pad);
5934 ev = find_event_by_type (pad, event_type, idx);
5935 if (ev && (event = ev->event))
5936 gst_event_ref (event);
5937 GST_OBJECT_UNLOCK (pad);
5944 GstPadStickyEventsForeachFunction func;
5949 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5951 ForeachDispatch *data = user_data;
5952 gboolean ret = TRUE;
5955 GST_OBJECT_UNLOCK (pad);
5957 ret = data->func (pad, &ev->event, data->user_data);
5959 GST_OBJECT_LOCK (pad);
5966 * gst_pad_sticky_events_foreach:
5967 * @pad: the #GstPad that should be used for iteration.
5968 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5969 * should be called for every event.
5970 * @user_data: (closure): the optional user data.
5972 * Iterates all sticky events on @pad and calls @foreach_func for every
5973 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5976 gst_pad_sticky_events_foreach (GstPad * pad,
5977 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5979 ForeachDispatch data;
5981 g_return_if_fail (GST_IS_PAD (pad));
5982 g_return_if_fail (foreach_func != NULL);
5984 data.func = foreach_func;
5985 data.user_data = user_data;
5987 GST_OBJECT_LOCK (pad);
5988 events_foreach (pad, foreach_dispatch_function, &data);
5989 GST_OBJECT_UNLOCK (pad);
5993 do_stream_status (GstPad * pad, GstStreamStatusType type,
5994 GThread * thread, GstTask * task)
5998 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6000 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6001 if (GST_IS_ELEMENT (parent)) {
6002 GstMessage *message;
6003 GValue value = { 0 };
6005 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6006 gchar *tname, *ename, *pname;
6008 /* create a good task name */
6009 ename = gst_element_get_name (parent);
6010 pname = gst_pad_get_name (pad);
6011 tname = g_strdup_printf ("%s:%s", ename, pname);
6015 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6019 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6022 g_value_init (&value, GST_TYPE_TASK);
6023 g_value_set_object (&value, task);
6024 gst_message_set_stream_status_object (message, &value);
6025 g_value_unset (&value);
6027 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6028 gst_element_post_message (parent, message);
6030 gst_object_unref (parent);
6035 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6037 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6042 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6044 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6049 * gst_pad_start_task:
6050 * @pad: the #GstPad to start the task of
6051 * @func: the task function to call
6052 * @user_data: user data passed to the task function
6053 * @notify: called when @user_data is no longer referenced
6055 * Starts a task that repeatedly calls @func with @user_data. This function
6056 * is mostly used in pad activation functions to start the dataflow.
6057 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6058 * before @func is called.
6060 * Returns: a %TRUE if the task could be started.
6063 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6064 GDestroyNotify notify)
6069 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6070 g_return_val_if_fail (func != NULL, FALSE);
6072 GST_DEBUG_OBJECT (pad, "start task");
6074 GST_OBJECT_LOCK (pad);
6075 task = GST_PAD_TASK (pad);
6077 task = gst_task_new (func, user_data, notify);
6078 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6079 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6080 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6081 GST_INFO_OBJECT (pad, "created task %p", task);
6082 GST_PAD_TASK (pad) = task;
6083 gst_object_ref (task);
6084 /* release lock to post the message */
6085 GST_OBJECT_UNLOCK (pad);
6087 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6089 gst_object_unref (task);
6091 GST_OBJECT_LOCK (pad);
6092 /* nobody else is supposed to have changed the pad now */
6093 if (GST_PAD_TASK (pad) != task)
6094 goto concurrent_stop;
6096 res = gst_task_set_state (task, GST_TASK_STARTED);
6097 GST_OBJECT_UNLOCK (pad);
6104 GST_OBJECT_UNLOCK (pad);
6110 * gst_pad_pause_task:
6111 * @pad: the #GstPad to pause the task of
6113 * Pause the task of @pad. This function will also wait until the
6114 * function executed by the task is finished if this function is not
6115 * called from the task function.
6117 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6121 gst_pad_pause_task (GstPad * pad)
6126 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6128 GST_DEBUG_OBJECT (pad, "pause task");
6130 GST_OBJECT_LOCK (pad);
6131 task = GST_PAD_TASK (pad);
6134 res = gst_task_set_state (task, GST_TASK_PAUSED);
6135 GST_OBJECT_UNLOCK (pad);
6137 /* wait for task function to finish, this lock is recursive so it does nothing
6138 * when the pause is called from the task itself */
6139 GST_PAD_STREAM_LOCK (pad);
6140 GST_PAD_STREAM_UNLOCK (pad);
6146 GST_DEBUG_OBJECT (pad, "pad has no task");
6147 GST_OBJECT_UNLOCK (pad);
6153 * gst_pad_get_task_state:
6154 * @pad: the #GstPad to get task state from
6156 * Get @pad task state. If no task is currently
6157 * set, #GST_TASK_STOPPED is returned.
6159 * Returns: The current state of @pad's task.
6164 gst_pad_get_task_state (GstPad * pad)
6169 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6171 GST_OBJECT_LOCK (pad);
6172 task = GST_PAD_TASK (pad);
6175 res = gst_task_get_state (task);
6176 GST_OBJECT_UNLOCK (pad);
6182 GST_DEBUG_OBJECT (pad, "pad has no task");
6183 GST_OBJECT_UNLOCK (pad);
6184 return GST_TASK_STOPPED;
6189 * gst_pad_stop_task:
6190 * @pad: the #GstPad to stop the task of
6192 * Stop the task of @pad. This function will also make sure that the
6193 * function executed by the task will effectively stop if not called
6194 * from the GstTaskFunction.
6196 * This function will deadlock if called from the GstTaskFunction of
6197 * the task. Use gst_task_pause() instead.
6199 * Regardless of whether the pad has a task, the stream lock is acquired and
6200 * released so as to ensure that streaming through this pad has finished.
6202 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6205 gst_pad_stop_task (GstPad * pad)
6210 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6212 GST_DEBUG_OBJECT (pad, "stop task");
6214 GST_OBJECT_LOCK (pad);
6215 task = GST_PAD_TASK (pad);
6218 GST_PAD_TASK (pad) = NULL;
6219 res = gst_task_set_state (task, GST_TASK_STOPPED);
6220 GST_OBJECT_UNLOCK (pad);
6222 GST_PAD_STREAM_LOCK (pad);
6223 GST_PAD_STREAM_UNLOCK (pad);
6225 if (!gst_task_join (task))
6228 gst_object_unref (task);
6234 GST_DEBUG_OBJECT (pad, "no task");
6235 GST_OBJECT_UNLOCK (pad);
6237 GST_PAD_STREAM_LOCK (pad);
6238 GST_PAD_STREAM_UNLOCK (pad);
6240 /* this is not an error */
6245 /* this is bad, possibly the application tried to join the task from
6246 * the task's thread. We install the task again so that it will be stopped
6247 * again from the right thread next time hopefully. */
6248 GST_OBJECT_LOCK (pad);
6249 GST_DEBUG_OBJECT (pad, "join failed");
6250 /* we can only install this task if there was no other task */
6251 if (GST_PAD_TASK (pad) == NULL)
6252 GST_PAD_TASK (pad) = task;
6253 GST_OBJECT_UNLOCK (pad);
6260 * gst_pad_probe_info_get_event:
6261 * @info: a #GstPadProbeInfo
6263 * Returns: (transfer none): The #GstEvent from the probe
6267 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6269 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6270 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6272 return GST_PAD_PROBE_INFO_EVENT (info);
6277 * gst_pad_probe_info_get_query:
6278 * @info: a #GstPadProbeInfo
6280 * Returns: (transfer none): The #GstQuery from the probe
6284 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6286 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6287 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6289 return GST_PAD_PROBE_INFO_QUERY (info);
6293 * gst_pad_probe_info_get_buffer:
6294 * @info: a #GstPadProbeInfo
6296 * Returns: (transfer none): The #GstBuffer from the probe
6300 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6302 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6304 return GST_PAD_PROBE_INFO_BUFFER (info);
6308 * gst_pad_probe_info_get_buffer_list:
6309 * @info: a #GstPadProbeInfo
6311 * Returns: (transfer none): The #GstBufferList from the probe
6315 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6317 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6319 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6323 * gst_pad_get_last_flow_return:
6326 * Gets the #GstFlowReturn return from the last data passed by this pad.
6331 gst_pad_get_last_flow_return (GstPad * pad)
6335 GST_OBJECT_LOCK (pad);
6336 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6337 GST_OBJECT_UNLOCK (pad);