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)
1307 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1309 GST_OBJECT_LOCK (pad);
1310 ACQUIRE_PARENT (pad, parent, no_parent);
1311 GST_OBJECT_UNLOCK (pad);
1313 res = activate_mode_internal (pad, parent, mode, active);
1315 RELEASE_PARENT (parent);
1321 GST_WARNING_OBJECT (pad, "no parent");
1322 GST_OBJECT_UNLOCK (pad);
1328 * gst_pad_is_active:
1329 * @pad: the #GstPad to query
1331 * Query if a pad is active
1333 * Returns: %TRUE if the pad is active.
1338 gst_pad_is_active (GstPad * pad)
1340 gboolean result = FALSE;
1342 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1344 GST_OBJECT_LOCK (pad);
1345 result = GST_PAD_IS_ACTIVE (pad);
1346 GST_OBJECT_UNLOCK (pad);
1352 cleanup_hook (GstPad * pad, GHook * hook)
1354 GstPadProbeType type;
1356 if (!G_HOOK_IS_VALID (hook))
1359 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1361 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1362 /* unblock when we remove the last blocking probe */
1364 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1367 /* Might have new probes now that want to be called */
1368 GST_PAD_BLOCK_BROADCAST (pad);
1370 if (pad->num_blocked == 0) {
1371 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1372 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1375 g_hook_destroy_link (&pad->probes, hook);
1380 * gst_pad_add_probe:
1381 * @pad: the #GstPad to add the probe to
1382 * @mask: the probe mask
1383 * @callback: #GstPadProbeCallback that will be called with notifications of
1385 * @user_data: (closure): user data passed to the callback
1386 * @destroy_data: #GDestroyNotify for user_data
1388 * Be notified of different states of pads. The provided callback is called for
1389 * every state that matches @mask.
1391 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1392 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1393 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1394 * immediately if the pad is already idle while calling gst_pad_add_probe().
1395 * In each of the groups, probes are called in the order in which they were
1398 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1399 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1400 * happen that the probe can be run immediately and if the probe returns
1401 * GST_PAD_PROBE_REMOVE this functions returns 0.
1406 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1407 GstPadProbeCallback callback, gpointer user_data,
1408 GDestroyNotify destroy_data)
1413 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1414 g_return_val_if_fail (mask != 0, 0);
1416 GST_OBJECT_LOCK (pad);
1418 /* make a new probe */
1419 hook = g_hook_alloc (&pad->probes);
1421 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1424 /* when no contraints are given for the types, assume all types are
1426 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1427 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1428 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1429 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1431 /* store our flags and other fields */
1432 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1433 hook->func = callback;
1434 hook->data = user_data;
1435 hook->destroy = destroy_data;
1436 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1439 g_hook_append (&pad->probes, hook);
1441 /* incremenent cookie so that the new hook get's called */
1442 pad->priv->probe_list_cookie++;
1444 /* get the id of the hook, we return this and it can be used to remove the
1446 res = hook->hook_id;
1448 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1450 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1451 /* we have a block probe */
1453 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1454 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1455 "now %d blocking probes", pad->num_blocked);
1457 /* Might have new probes now that want to be called */
1458 GST_PAD_BLOCK_BROADCAST (pad);
1461 /* call the callback if we need to be called for idle callbacks */
1462 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1463 if (pad->priv->using > 0) {
1464 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1465 * flag above, the last thread to leave the push will do the callback. New
1466 * threads going into the push will block. */
1467 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1468 "pad is in use, delay idle callback");
1469 GST_OBJECT_UNLOCK (pad);
1471 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1472 GstPadProbeReturn ret;
1474 /* Keep another ref, the callback could destroy the pad */
1475 gst_object_ref (pad);
1476 pad->priv->idle_running++;
1478 /* the pad is idle now, we can signal the idle callback now */
1479 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1480 "pad is idle, trigger idle callback");
1481 GST_OBJECT_UNLOCK (pad);
1483 ret = callback (pad, &info, user_data);
1485 GST_OBJECT_LOCK (pad);
1487 case GST_PAD_PROBE_REMOVE:
1488 /* remove the probe */
1489 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1490 cleanup_hook (pad, hook);
1493 case GST_PAD_PROBE_DROP:
1494 GST_DEBUG_OBJECT (pad, "asked to drop item");
1496 case GST_PAD_PROBE_PASS:
1497 GST_DEBUG_OBJECT (pad, "asked to pass item");
1499 case GST_PAD_PROBE_OK:
1500 GST_DEBUG_OBJECT (pad, "probe returned OK");
1502 case GST_PAD_PROBE_HANDLED:
1503 GST_DEBUG_OBJECT (pad, "probe handled the data");
1506 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1509 pad->priv->idle_running--;
1510 if (pad->priv->idle_running == 0) {
1511 GST_PAD_BLOCK_BROADCAST (pad);
1513 GST_OBJECT_UNLOCK (pad);
1515 gst_object_unref (pad);
1518 GST_OBJECT_UNLOCK (pad);
1524 * gst_pad_remove_probe:
1525 * @pad: the #GstPad with the probe
1526 * @id: the probe id to remove
1528 * Remove the probe with @id from @pad.
1533 gst_pad_remove_probe (GstPad * pad, gulong id)
1537 g_return_if_fail (GST_IS_PAD (pad));
1539 GST_OBJECT_LOCK (pad);
1541 hook = g_hook_get (&pad->probes, id);
1545 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1547 cleanup_hook (pad, hook);
1548 GST_OBJECT_UNLOCK (pad);
1554 GST_OBJECT_UNLOCK (pad);
1555 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1561 * gst_pad_is_blocked:
1562 * @pad: the #GstPad to query
1564 * Checks if the pad is blocked or not. This function returns the
1565 * last requested state of the pad. It is not certain that the pad
1566 * is actually blocking at this point (see gst_pad_is_blocking()).
1568 * Returns: %TRUE if the pad is blocked.
1573 gst_pad_is_blocked (GstPad * pad)
1575 gboolean result = FALSE;
1577 g_return_val_if_fail (GST_IS_PAD (pad), result);
1579 GST_OBJECT_LOCK (pad);
1580 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1581 GST_OBJECT_UNLOCK (pad);
1587 * gst_pad_is_blocking:
1588 * @pad: the #GstPad to query
1590 * Checks if the pad is blocking or not. This is a guaranteed state
1591 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1593 * Returns: %TRUE if the pad is blocking.
1598 gst_pad_is_blocking (GstPad * pad)
1600 gboolean result = FALSE;
1602 g_return_val_if_fail (GST_IS_PAD (pad), result);
1604 GST_OBJECT_LOCK (pad);
1605 /* the blocking flag is only valid if the pad is not flushing */
1606 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1607 GST_OBJECT_UNLOCK (pad);
1613 * gst_pad_needs_reconfigure:
1614 * @pad: the #GstPad to check
1616 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1617 * if the flag was set.
1619 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1622 gst_pad_needs_reconfigure (GstPad * pad)
1624 gboolean reconfigure;
1626 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1628 GST_OBJECT_LOCK (pad);
1629 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1630 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1631 GST_OBJECT_UNLOCK (pad);
1637 * gst_pad_check_reconfigure:
1638 * @pad: the #GstPad to check
1640 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1641 * if the flag was set.
1643 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1646 gst_pad_check_reconfigure (GstPad * pad)
1648 gboolean reconfigure;
1650 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1652 GST_OBJECT_LOCK (pad);
1653 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1655 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1656 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1658 GST_OBJECT_UNLOCK (pad);
1664 * gst_pad_mark_reconfigure:
1665 * @pad: the #GstPad to mark
1667 * Mark a pad for needing reconfiguration. The next call to
1668 * gst_pad_check_reconfigure() will return %TRUE after this call.
1671 gst_pad_mark_reconfigure (GstPad * pad)
1673 g_return_if_fail (GST_IS_PAD (pad));
1675 GST_OBJECT_LOCK (pad);
1676 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1677 GST_OBJECT_UNLOCK (pad);
1681 * gst_pad_set_activate_function:
1683 * @f: the #GstPadActivateFunction to set.
1685 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1689 * gst_pad_set_activate_function_full:
1691 * @activate: the #GstPadActivateFunction to set.
1692 * @user_data: user_data passed to @notify
1693 * @notify: notify called when @activate will not be used anymore.
1695 * Sets the given activate function for @pad. The activate function will
1696 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1697 * Only makes sense to set on sink pads.
1699 * Call this function if your sink pad can start a pull-based task.
1702 gst_pad_set_activate_function_full (GstPad * pad,
1703 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1705 g_return_if_fail (GST_IS_PAD (pad));
1707 if (pad->activatenotify)
1708 pad->activatenotify (pad->activatedata);
1709 GST_PAD_ACTIVATEFUNC (pad) = activate;
1710 pad->activatedata = user_data;
1711 pad->activatenotify = notify;
1713 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1714 GST_DEBUG_FUNCPTR_NAME (activate));
1718 * gst_pad_set_activatemode_function:
1720 * @f: the #GstPadActivateModeFunction to set.
1722 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1726 * gst_pad_set_activatemode_function_full:
1728 * @activatemode: the #GstPadActivateModeFunction to set.
1729 * @user_data: user_data passed to @notify
1730 * @notify: notify called when @activatemode will not be used anymore.
1732 * Sets the given activate_mode function for the pad. An activate_mode function
1733 * prepares the element for data passing.
1736 gst_pad_set_activatemode_function_full (GstPad * pad,
1737 GstPadActivateModeFunction activatemode, gpointer user_data,
1738 GDestroyNotify notify)
1740 g_return_if_fail (GST_IS_PAD (pad));
1742 if (pad->activatemodenotify)
1743 pad->activatemodenotify (pad->activatemodedata);
1744 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1745 pad->activatemodedata = user_data;
1746 pad->activatemodenotify = notify;
1748 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1749 GST_DEBUG_FUNCPTR_NAME (activatemode));
1753 * gst_pad_set_chain_function:
1754 * @p: a sink #GstPad.
1755 * @f: the #GstPadChainFunction to set.
1757 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1761 * gst_pad_set_chain_function_full:
1762 * @pad: a sink #GstPad.
1763 * @chain: the #GstPadChainFunction to set.
1764 * @user_data: user_data passed to @notify
1765 * @notify: notify called when @chain will not be used anymore.
1767 * Sets the given chain function for the pad. The chain function is called to
1768 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1771 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1772 gpointer user_data, GDestroyNotify notify)
1774 g_return_if_fail (GST_IS_PAD (pad));
1775 g_return_if_fail (GST_PAD_IS_SINK (pad));
1777 if (pad->chainnotify)
1778 pad->chainnotify (pad->chaindata);
1779 GST_PAD_CHAINFUNC (pad) = chain;
1780 pad->chaindata = user_data;
1781 pad->chainnotify = notify;
1783 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1784 GST_DEBUG_FUNCPTR_NAME (chain));
1788 * gst_pad_set_chain_list_function:
1789 * @p: a sink #GstPad.
1790 * @f: the #GstPadChainListFunction to set.
1792 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1796 * gst_pad_set_chain_list_function_full:
1797 * @pad: a sink #GstPad.
1798 * @chainlist: the #GstPadChainListFunction to set.
1799 * @user_data: user_data passed to @notify
1800 * @notify: notify called when @chainlist will not be used anymore.
1802 * Sets the given chain list function for the pad. The chainlist function is
1803 * called to process a #GstBufferList input buffer list. See
1804 * #GstPadChainListFunction for more details.
1807 gst_pad_set_chain_list_function_full (GstPad * pad,
1808 GstPadChainListFunction chainlist, gpointer user_data,
1809 GDestroyNotify notify)
1811 g_return_if_fail (GST_IS_PAD (pad));
1812 g_return_if_fail (GST_PAD_IS_SINK (pad));
1814 if (pad->chainlistnotify)
1815 pad->chainlistnotify (pad->chainlistdata);
1816 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1817 pad->chainlistdata = user_data;
1818 pad->chainlistnotify = notify;
1820 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1821 GST_DEBUG_FUNCPTR_NAME (chainlist));
1825 * gst_pad_set_getrange_function:
1826 * @p: a source #GstPad.
1827 * @f: the #GstPadGetRangeFunction to set.
1829 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1833 * gst_pad_set_getrange_function_full:
1834 * @pad: a source #GstPad.
1835 * @get: the #GstPadGetRangeFunction to set.
1836 * @user_data: user_data passed to @notify
1837 * @notify: notify called when @get will not be used anymore.
1839 * Sets the given getrange function for the pad. The getrange function is
1840 * called to produce a new #GstBuffer to start the processing pipeline. see
1841 * #GstPadGetRangeFunction for a description of the getrange function.
1844 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1845 gpointer user_data, GDestroyNotify notify)
1847 g_return_if_fail (GST_IS_PAD (pad));
1848 g_return_if_fail (GST_PAD_IS_SRC (pad));
1850 if (pad->getrangenotify)
1851 pad->getrangenotify (pad->getrangedata);
1852 GST_PAD_GETRANGEFUNC (pad) = get;
1853 pad->getrangedata = user_data;
1854 pad->getrangenotify = notify;
1856 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1857 GST_DEBUG_FUNCPTR_NAME (get));
1861 * gst_pad_set_event_function:
1862 * @p: a #GstPad of either direction.
1863 * @f: the #GstPadEventFunction to set.
1865 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1869 * gst_pad_set_event_function_full:
1870 * @pad: a #GstPad of either direction.
1871 * @event: the #GstPadEventFunction to set.
1872 * @user_data: user_data passed to @notify
1873 * @notify: notify called when @event will not be used anymore.
1875 * Sets the given event handler for the pad.
1878 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1879 gpointer user_data, GDestroyNotify notify)
1881 g_return_if_fail (GST_IS_PAD (pad));
1883 if (pad->eventnotify)
1884 pad->eventnotify (pad->eventdata);
1885 GST_PAD_EVENTFUNC (pad) = event;
1886 pad->eventdata = user_data;
1887 pad->eventnotify = notify;
1889 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1890 GST_DEBUG_FUNCPTR_NAME (event));
1894 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1898 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1899 if (ret == GST_FLOW_OK)
1905 * gst_pad_set_event_full_function:
1906 * @p: a #GstPad of either direction.
1907 * @f: the #GstPadEventFullFunction to set.
1909 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1913 * gst_pad_set_event_full_function_full:
1914 * @pad: a #GstPad of either direction.
1915 * @event: the #GstPadEventFullFunction to set.
1916 * @user_data: user_data passed to @notify
1917 * @notify: notify called when @event will not be used anymore.
1919 * Sets the given event handler for the pad.
1924 gst_pad_set_event_full_function_full (GstPad * pad,
1925 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1927 g_return_if_fail (GST_IS_PAD (pad));
1929 if (pad->eventnotify)
1930 pad->eventnotify (pad->eventdata);
1931 GST_PAD_EVENTFULLFUNC (pad) = event;
1932 GST_PAD_EVENTFUNC (pad) = event_wrap;
1933 pad->eventdata = user_data;
1934 pad->eventnotify = notify;
1936 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1937 GST_DEBUG_FUNCPTR_NAME (event));
1941 * gst_pad_set_query_function:
1942 * @p: a #GstPad of either direction.
1943 * @f: the #GstPadQueryFunction to set.
1945 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1949 * gst_pad_set_query_function_full:
1950 * @pad: a #GstPad of either direction.
1951 * @query: the #GstPadQueryFunction to set.
1952 * @user_data: user_data passed to @notify
1953 * @notify: notify called when @query will not be used anymore.
1955 * Set the given query function for the pad.
1958 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1959 gpointer user_data, GDestroyNotify notify)
1961 g_return_if_fail (GST_IS_PAD (pad));
1963 if (pad->querynotify)
1964 pad->querynotify (pad->querydata);
1965 GST_PAD_QUERYFUNC (pad) = query;
1966 pad->querydata = user_data;
1967 pad->querynotify = notify;
1969 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1970 GST_DEBUG_FUNCPTR_NAME (query));
1974 * gst_pad_set_iterate_internal_links_function:
1975 * @p: a #GstPad of either direction.
1976 * @f: the #GstPadIterIntLinkFunction to set.
1978 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1979 * for the user_data and notify.
1982 * gst_pad_set_iterate_internal_links_function_full:
1983 * @pad: a #GstPad of either direction.
1984 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1985 * @user_data: user_data passed to @notify
1986 * @notify: notify called when @iterintlink will not be used anymore.
1988 * Sets the given internal link iterator function for the pad.
1991 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1992 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1993 GDestroyNotify notify)
1995 g_return_if_fail (GST_IS_PAD (pad));
1997 if (pad->iterintlinknotify)
1998 pad->iterintlinknotify (pad->iterintlinkdata);
1999 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2000 pad->iterintlinkdata = user_data;
2001 pad->iterintlinknotify = notify;
2003 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2004 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2008 * gst_pad_set_link_function:
2010 * @f: the #GstPadLinkFunction to set.
2012 * Calls gst_pad_set_link_function_full() with %NULL
2013 * for the user_data and notify.
2016 * gst_pad_set_link_function_full:
2018 * @link: the #GstPadLinkFunction to set.
2019 * @user_data: user_data passed to @notify
2020 * @notify: notify called when @link will not be used anymore.
2022 * Sets the given link function for the pad. It will be called when
2023 * the pad is linked with another pad.
2025 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2028 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2029 * cannot be made for some reason.
2031 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2032 * of the peer sink pad, if present.
2035 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2036 gpointer user_data, GDestroyNotify notify)
2038 g_return_if_fail (GST_IS_PAD (pad));
2040 if (pad->linknotify)
2041 pad->linknotify (pad->linkdata);
2042 GST_PAD_LINKFUNC (pad) = link;
2043 pad->linkdata = user_data;
2044 pad->linknotify = notify;
2046 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2047 GST_DEBUG_FUNCPTR_NAME (link));
2051 * gst_pad_set_unlink_function:
2053 * @f: the #GstPadUnlinkFunction to set.
2055 * Calls gst_pad_set_unlink_function_full() with %NULL
2056 * for the user_data and notify.
2059 * gst_pad_set_unlink_function_full:
2061 * @unlink: the #GstPadUnlinkFunction to set.
2062 * @user_data: user_data passed to @notify
2063 * @notify: notify called when @unlink will not be used anymore.
2065 * Sets the given unlink function for the pad. It will be called
2066 * when the pad is unlinked.
2069 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2070 gpointer user_data, GDestroyNotify notify)
2072 g_return_if_fail (GST_IS_PAD (pad));
2074 if (pad->unlinknotify)
2075 pad->unlinknotify (pad->unlinkdata);
2076 GST_PAD_UNLINKFUNC (pad) = unlink;
2077 pad->unlinkdata = user_data;
2078 pad->unlinknotify = notify;
2080 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2081 GST_DEBUG_FUNCPTR_NAME (unlink));
2086 * @srcpad: the source #GstPad to unlink.
2087 * @sinkpad: the sink #GstPad to unlink.
2089 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2090 * signal on both pads.
2092 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2093 * the pads were not linked together.
2098 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2100 gboolean result = FALSE;
2101 GstElement *parent = NULL;
2103 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2104 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2105 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2106 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2108 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2110 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2111 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2112 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2114 /* We need to notify the parent before taking any pad locks as the bin in
2115 * question might be waiting for a lock on the pad while holding its lock
2116 * that our message will try to take. */
2117 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2118 if (GST_IS_ELEMENT (parent)) {
2119 gst_element_post_message (parent,
2120 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2121 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2123 gst_object_unref (parent);
2128 GST_OBJECT_LOCK (srcpad);
2129 GST_OBJECT_LOCK (sinkpad);
2131 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2132 goto not_linked_together;
2134 if (GST_PAD_UNLINKFUNC (srcpad)) {
2135 GstObject *tmpparent;
2137 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2139 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2140 RELEASE_PARENT (tmpparent);
2143 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2144 GstObject *tmpparent;
2146 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2148 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2149 RELEASE_PARENT (tmpparent);
2153 /* first clear peers */
2154 GST_PAD_PEER (srcpad) = NULL;
2155 GST_PAD_PEER (sinkpad) = NULL;
2157 GST_OBJECT_UNLOCK (sinkpad);
2158 GST_OBJECT_UNLOCK (srcpad);
2160 /* fire off a signal to each of the pads telling them
2161 * that they've been unlinked */
2162 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2163 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2165 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2166 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2171 if (parent != NULL) {
2172 gst_element_post_message (parent,
2173 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2174 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2175 gst_object_unref (parent);
2177 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2181 not_linked_together:
2183 /* we do not emit a warning in this case because unlinking cannot
2184 * be made MT safe.*/
2185 GST_OBJECT_UNLOCK (sinkpad);
2186 GST_OBJECT_UNLOCK (srcpad);
2192 * gst_pad_is_linked:
2193 * @pad: pad to check
2195 * Checks if a @pad is linked to another pad or not.
2197 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2202 gst_pad_is_linked (GstPad * pad)
2206 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2208 GST_OBJECT_LOCK (pad);
2209 result = (GST_PAD_PEER (pad) != NULL);
2210 GST_OBJECT_UNLOCK (pad);
2215 /* get the caps from both pads and see if the intersection
2218 * This function should be called with the pad LOCK on both
2222 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2223 GstPadLinkCheck flags)
2225 GstCaps *srccaps = NULL;
2226 GstCaps *sinkcaps = NULL;
2227 gboolean compatible = FALSE;
2229 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2232 /* Doing the expensive caps checking takes priority over only checking the template caps */
2233 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2234 GST_OBJECT_UNLOCK (sink);
2235 GST_OBJECT_UNLOCK (src);
2237 srccaps = gst_pad_query_caps (src, NULL);
2238 sinkcaps = gst_pad_query_caps (sink, NULL);
2240 GST_OBJECT_LOCK (src);
2241 GST_OBJECT_LOCK (sink);
2243 /* If one of the two pads doesn't have a template, consider the intersection
2245 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2246 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2250 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2252 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2255 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2257 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2260 /* if we have caps on both pads we can check the intersection. If one
2261 * of the caps is %NULL, we return %TRUE. */
2262 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2264 gst_caps_unref (srccaps);
2266 gst_caps_unref (sinkcaps);
2270 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2271 gst_caps_unref (srccaps);
2272 gst_caps_unref (sinkcaps);
2275 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2276 (compatible ? "" : "not "));
2281 /* check if the grandparents of both pads are the same.
2282 * This check is required so that we don't try to link
2283 * pads from elements in different bins without ghostpads.
2285 * The LOCK should be held on both pads
2288 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2290 GstObject *psrc, *psink;
2292 psrc = GST_OBJECT_PARENT (src);
2293 psink = GST_OBJECT_PARENT (sink);
2295 /* if one of the pads has no parent, we allow the link */
2296 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2299 /* only care about parents that are elements */
2300 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2301 goto no_element_parent;
2303 /* if the parents are the same, we have a loop */
2304 if (G_UNLIKELY (psrc == psink))
2307 /* if they both have a parent, we check the grandparents. We can not lock
2308 * the parent because we hold on the child (pad) and the locking order is
2309 * parent >> child. */
2310 psrc = GST_OBJECT_PARENT (psrc);
2311 psink = GST_OBJECT_PARENT (psink);
2313 /* if they have grandparents but they are not the same */
2314 if (G_UNLIKELY (psrc != psink))
2315 goto wrong_grandparents;
2322 GST_CAT_DEBUG (GST_CAT_CAPS,
2323 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2324 GST_PTR_FORMAT, psrc, psink);
2329 GST_CAT_DEBUG (GST_CAT_CAPS,
2330 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2331 GST_PTR_FORMAT, psrc, psink);
2336 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2342 GST_CAT_DEBUG (GST_CAT_CAPS,
2343 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2344 GST_PTR_FORMAT, psrc, psink);
2349 /* FIXME leftover from an attempt at refactoring... */
2350 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2351 * the two pads will be locked in the srcpad, sinkpad order. */
2352 static GstPadLinkReturn
2353 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2355 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2356 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2358 GST_OBJECT_LOCK (srcpad);
2360 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2361 goto src_was_linked;
2363 GST_OBJECT_LOCK (sinkpad);
2365 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2366 goto sink_was_linked;
2368 /* check hierarchy, pads can only be linked if the grandparents
2370 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2371 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2372 goto wrong_hierarchy;
2374 /* check pad caps for non-empty intersection */
2375 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2378 /* FIXME check pad scheduling for non-empty intersection */
2380 return GST_PAD_LINK_OK;
2384 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2385 GST_DEBUG_PAD_NAME (srcpad),
2386 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2387 /* we do not emit a warning in this case because unlinking cannot
2388 * be made MT safe.*/
2389 GST_OBJECT_UNLOCK (srcpad);
2390 return GST_PAD_LINK_WAS_LINKED;
2394 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2395 GST_DEBUG_PAD_NAME (sinkpad),
2396 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2397 /* we do not emit a warning in this case because unlinking cannot
2398 * be made MT safe.*/
2399 GST_OBJECT_UNLOCK (sinkpad);
2400 GST_OBJECT_UNLOCK (srcpad);
2401 return GST_PAD_LINK_WAS_LINKED;
2405 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2406 GST_OBJECT_UNLOCK (sinkpad);
2407 GST_OBJECT_UNLOCK (srcpad);
2408 return GST_PAD_LINK_WRONG_HIERARCHY;
2412 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2413 GST_OBJECT_UNLOCK (sinkpad);
2414 GST_OBJECT_UNLOCK (srcpad);
2415 return GST_PAD_LINK_NOFORMAT;
2421 * @srcpad: the source #GstPad.
2422 * @sinkpad: the sink #GstPad.
2424 * Checks if the source pad and the sink pad are compatible so they can be
2427 * Returns: %TRUE if the pads can be linked.
2430 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2432 GstPadLinkReturn result;
2434 /* generic checks */
2435 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2436 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2438 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2439 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2441 /* gst_pad_link_prepare does everything for us, we only release the locks
2442 * on the pads that it gets us. If this function returns !OK the locks are not
2444 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2445 if (result != GST_PAD_LINK_OK)
2448 GST_OBJECT_UNLOCK (srcpad);
2449 GST_OBJECT_UNLOCK (sinkpad);
2452 return result == GST_PAD_LINK_OK;
2456 * gst_pad_link_full:
2457 * @srcpad: the source #GstPad to link.
2458 * @sinkpad: the sink #GstPad to link.
2459 * @flags: the checks to validate when linking
2461 * Links the source pad and the sink pad.
2463 * This variant of #gst_pad_link provides a more granular control on the
2464 * checks being done when linking. While providing some considerable speedups
2465 * the caller of this method must be aware that wrong usage of those flags
2466 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2467 * for more information.
2471 * Returns: A result code indicating if the connection worked or
2475 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2477 GstPadLinkReturn result;
2479 GstPadLinkFunction srcfunc, sinkfunc;
2481 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2482 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2483 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2484 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2485 GST_PAD_LINK_WRONG_DIRECTION);
2487 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2489 /* Notify the parent early. See gst_pad_unlink for details. */
2490 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2491 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2492 gst_element_post_message (parent,
2493 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2494 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2496 gst_object_unref (parent);
2501 /* prepare will also lock the two pads */
2502 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2504 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2505 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2506 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2507 gst_pad_link_get_name (result));
2511 /* must set peers before calling the link function */
2512 GST_PAD_PEER (srcpad) = sinkpad;
2513 GST_PAD_PEER (sinkpad) = srcpad;
2515 /* check events, when something is different, mark pending */
2516 schedule_events (srcpad, sinkpad);
2518 /* get the link functions */
2519 srcfunc = GST_PAD_LINKFUNC (srcpad);
2520 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2522 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2523 /* custom link functions, execute them */
2524 GST_OBJECT_UNLOCK (sinkpad);
2525 GST_OBJECT_UNLOCK (srcpad);
2528 GstObject *tmpparent;
2530 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2531 /* this one will call the peer link function */
2532 result = srcfunc (srcpad, tmpparent, sinkpad);
2533 RELEASE_PARENT (tmpparent);
2534 } else if (sinkfunc) {
2535 GstObject *tmpparent;
2537 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2538 /* if no source link function, we need to call the sink link
2539 * function ourselves. */
2540 result = sinkfunc (sinkpad, tmpparent, srcpad);
2541 RELEASE_PARENT (tmpparent);
2545 GST_OBJECT_LOCK (srcpad);
2546 GST_OBJECT_LOCK (sinkpad);
2548 /* we released the lock, check if the same pads are linked still */
2549 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2550 goto concurrent_link;
2552 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2555 GST_OBJECT_UNLOCK (sinkpad);
2556 GST_OBJECT_UNLOCK (srcpad);
2558 /* fire off a signal to each of the pads telling them
2559 * that they've been linked */
2560 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2561 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2563 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2564 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2566 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2567 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2570 if (G_LIKELY (parent)) {
2571 gst_element_post_message (parent,
2572 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2573 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2574 gst_object_unref (parent);
2577 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2583 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2584 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2585 GST_OBJECT_UNLOCK (sinkpad);
2586 GST_OBJECT_UNLOCK (srcpad);
2588 /* The other link operation succeeded first */
2589 result = GST_PAD_LINK_WAS_LINKED;
2594 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2595 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2596 gst_pad_link_get_name (result));
2598 GST_PAD_PEER (srcpad) = NULL;
2599 GST_PAD_PEER (sinkpad) = NULL;
2601 GST_OBJECT_UNLOCK (sinkpad);
2602 GST_OBJECT_UNLOCK (srcpad);
2610 * @srcpad: the source #GstPad to link.
2611 * @sinkpad: the sink #GstPad to link.
2613 * Links the source pad and the sink pad.
2615 * Returns: A result code indicating if the connection worked or
2621 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2623 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2627 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2629 GstPadTemplate **template_p;
2631 /* this function would need checks if it weren't static */
2633 GST_OBJECT_LOCK (pad);
2634 template_p = &pad->padtemplate;
2635 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2636 GST_OBJECT_UNLOCK (pad);
2639 gst_pad_template_pad_created (templ, pad);
2643 * gst_pad_get_pad_template:
2646 * Gets the template for @pad.
2648 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2649 * this pad was instantiated, or %NULL if this pad has no
2650 * template. Unref after usage.
2653 gst_pad_get_pad_template (GstPad * pad)
2655 GstPadTemplate *templ;
2657 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2659 templ = GST_PAD_PAD_TEMPLATE (pad);
2661 return (templ ? gst_object_ref (templ) : NULL);
2665 * gst_pad_has_current_caps:
2666 * @pad: a #GstPad to check
2668 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2670 * Returns: %TRUE when @pad has caps associated with it.
2673 gst_pad_has_current_caps (GstPad * pad)
2678 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2680 GST_OBJECT_LOCK (pad);
2681 caps = get_pad_caps (pad);
2682 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2683 "check current pad caps %" GST_PTR_FORMAT, caps);
2684 result = (caps != NULL);
2685 GST_OBJECT_UNLOCK (pad);
2691 * gst_pad_get_current_caps:
2692 * @pad: a #GstPad to get the current capabilities of.
2694 * Gets the capabilities currently configured on @pad with the last
2695 * #GST_EVENT_CAPS event.
2697 * Returns: (transfer full) (nullable): the current caps of the pad with
2698 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2701 gst_pad_get_current_caps (GstPad * pad)
2705 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2707 GST_OBJECT_LOCK (pad);
2708 if ((result = get_pad_caps (pad)))
2709 gst_caps_ref (result);
2710 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2711 "get current pad caps %" GST_PTR_FORMAT, result);
2712 GST_OBJECT_UNLOCK (pad);
2718 * gst_pad_get_pad_template_caps:
2719 * @pad: a #GstPad to get the template capabilities from.
2721 * Gets the capabilities for @pad's template.
2723 * Returns: (transfer full): the #GstCaps of this pad template.
2724 * Unref after usage.
2727 gst_pad_get_pad_template_caps (GstPad * pad)
2729 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2731 if (GST_PAD_PAD_TEMPLATE (pad))
2732 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2734 return gst_caps_ref (GST_CAPS_ANY);
2739 * @pad: a #GstPad to get the peer of.
2741 * Gets the peer of @pad. This function refs the peer pad so
2742 * you need to unref it after use.
2744 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2749 gst_pad_get_peer (GstPad * pad)
2753 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2755 GST_OBJECT_LOCK (pad);
2756 result = GST_PAD_PEER (pad);
2758 gst_object_ref (result);
2759 GST_OBJECT_UNLOCK (pad);
2765 * gst_pad_get_allowed_caps:
2768 * Gets the capabilities of the allowed media types that can flow through
2769 * @pad and its peer.
2771 * The allowed capabilities is calculated as the intersection of the results of
2772 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2773 * on the resulting caps.
2775 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2776 * pad link. Unref the caps when you no longer need it. This
2777 * function returns %NULL when @pad has no peer.
2782 gst_pad_get_allowed_caps (GstPad * pad)
2785 GstCaps *caps = NULL;
2788 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2790 GST_OBJECT_LOCK (pad);
2791 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2793 GST_OBJECT_UNLOCK (pad);
2795 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2797 mycaps = gst_pad_query_caps (pad, NULL);
2799 /* Query peer caps */
2800 query = gst_query_new_caps (mycaps);
2801 if (!gst_pad_peer_query (pad, query)) {
2802 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2806 gst_query_parse_caps_result (query, &caps);
2808 g_warn_if_fail (caps != NULL);
2811 gst_caps_ref (caps);
2813 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2817 gst_query_unref (query);
2818 gst_caps_unref (mycaps);
2824 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2825 GST_OBJECT_UNLOCK (pad);
2832 * gst_pad_iterate_internal_links_default:
2833 * @pad: the #GstPad to get the internal links of.
2834 * @parent: (allow-none): the parent of @pad or %NULL
2836 * Iterate the list of pads to which the given pad is linked to inside of
2837 * the parent element.
2838 * This is the default handler, and thus returns an iterator of all of the
2839 * pads inside the parent element with opposite direction.
2841 * The caller must free this iterator after use with gst_iterator_free().
2843 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2844 * has no parent. Unref each returned pad with gst_object_unref().
2847 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2854 GstElement *eparent;
2856 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2858 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2859 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2861 GST_OBJECT_LOCK (pad);
2862 eparent = GST_PAD_PARENT (pad);
2863 if (!eparent || !GST_IS_ELEMENT (eparent))
2866 gst_object_ref (eparent);
2867 GST_OBJECT_UNLOCK (pad);
2870 if (pad->direction == GST_PAD_SRC)
2871 padlist = &eparent->sinkpads;
2873 padlist = &eparent->srcpads;
2875 GST_DEBUG_OBJECT (pad, "Making iterator");
2877 cookie = &eparent->pads_cookie;
2879 lock = GST_OBJECT_GET_LOCK (eparent);
2881 res = gst_iterator_new_list (GST_TYPE_PAD,
2882 lock, cookie, padlist, (GObject *) owner, NULL);
2884 gst_object_unref (owner);
2891 GST_OBJECT_UNLOCK (pad);
2892 GST_DEBUG_OBJECT (pad, "no parent element");
2898 * gst_pad_iterate_internal_links:
2899 * @pad: the GstPad to get the internal links of.
2901 * Gets an iterator for the pads to which the given pad is linked to inside
2902 * of the parent element.
2904 * Each #GstPad element yielded by the iterator will have its refcount increased,
2905 * so unref after use.
2907 * Free-function: gst_iterator_free
2909 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2910 * or %NULL when the pad does not have an iterator function
2911 * configured. Use gst_iterator_free() after usage.
2914 gst_pad_iterate_internal_links (GstPad * pad)
2916 GstIterator *res = NULL;
2919 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2921 GST_OBJECT_LOCK (pad);
2922 ACQUIRE_PARENT (pad, parent, no_parent);
2923 GST_OBJECT_UNLOCK (pad);
2925 if (GST_PAD_ITERINTLINKFUNC (pad))
2926 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2928 RELEASE_PARENT (parent);
2935 GST_DEBUG_OBJECT (pad, "no parent");
2936 GST_OBJECT_UNLOCK (pad);
2944 * @forward: (scope call): a #GstPadForwardFunction
2945 * @user_data: user data passed to @forward
2947 * Calls @forward for all internally linked pads of @pad. This function deals with
2948 * dynamically changing internal pads and will make sure that the @forward
2949 * function is only called once for each pad.
2951 * When @forward returns %TRUE, no further pads will be processed.
2953 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2956 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2959 gboolean result = FALSE;
2961 gboolean done = FALSE;
2962 GValue item = { 0, };
2963 GList *pushed_pads = NULL;
2965 iter = gst_pad_iterate_internal_links (pad);
2971 switch (gst_iterator_next (iter, &item)) {
2972 case GST_ITERATOR_OK:
2976 intpad = g_value_get_object (&item);
2978 /* if already pushed, skip. FIXME, find something faster to tag pads */
2979 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2980 g_value_reset (&item);
2984 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2985 GST_DEBUG_PAD_NAME (intpad));
2986 done = result = forward (intpad, user_data);
2988 pushed_pads = g_list_prepend (pushed_pads, intpad);
2990 g_value_reset (&item);
2993 case GST_ITERATOR_RESYNC:
2994 /* We don't reset the result here because we don't push the event
2995 * again on pads that got the event already and because we need
2996 * to consider the result of the previous pushes */
2997 gst_iterator_resync (iter);
2999 case GST_ITERATOR_ERROR:
3000 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3003 case GST_ITERATOR_DONE:
3008 g_value_unset (&item);
3009 gst_iterator_free (iter);
3011 g_list_free (pushed_pads);
3021 gboolean dispatched;
3025 event_forward_func (GstPad * pad, EventData * data)
3027 /* for each pad we send to, we should ref the event; it's up
3028 * to downstream to unref again when handled. */
3029 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3030 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3032 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3034 data->dispatched = TRUE;
3041 * gst_pad_event_default:
3042 * @pad: a #GstPad to call the default event handler on.
3043 * @parent: (allow-none): the parent of @pad or %NULL
3044 * @event: (transfer full): the #GstEvent to handle.
3046 * Invokes the default event handler for the given pad.
3048 * The EOS event will pause the task associated with @pad before it is forwarded
3049 * to all internally linked pads,
3051 * The event is sent to all pads internally linked to @pad. This function
3052 * takes ownership of @event.
3054 * Returns: %TRUE if the event was sent successfully.
3057 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3059 gboolean result, forward = TRUE;
3061 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3062 g_return_val_if_fail (event != NULL, FALSE);
3064 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3067 switch (GST_EVENT_TYPE (event)) {
3068 case GST_EVENT_CAPS:
3069 forward = GST_PAD_IS_PROXY_CAPS (pad);
3080 data.dispatched = FALSE;
3081 data.result = FALSE;
3083 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3085 /* for sinkpads without a parent element or without internal links, nothing
3086 * will be dispatched but we still want to return TRUE. */
3087 if (data.dispatched)
3088 result = data.result;
3093 gst_event_unref (event);
3098 /* Default accept caps implementation just checks against
3099 * the allowed caps for the pad */
3101 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3103 /* get the caps and see if it intersects to something not empty */
3104 GstCaps *caps, *allowed = NULL;
3107 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3109 /* first forward the query to internally linked pads when we are dealing with
3111 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3112 result = gst_pad_proxy_query_accept_caps (pad, query);
3114 allowed = gst_pad_get_pad_template_caps (pad);
3119 gst_query_parse_accept_caps (query, &caps);
3121 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3122 allowed = gst_pad_get_pad_template_caps (pad);
3124 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3125 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3126 allowed = gst_pad_query_caps (pad, caps);
3131 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3132 GST_DEBUG_OBJECT (pad,
3133 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3135 result = gst_caps_can_intersect (caps, allowed);
3137 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3138 GST_PTR_FORMAT, allowed, caps);
3139 result = gst_caps_is_subset (caps, allowed);
3141 gst_caps_unref (allowed);
3143 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3146 gst_query_set_accept_caps_result (query, result);
3152 /* Default caps implementation */
3154 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3156 GstCaps *result = NULL, *filter;
3157 GstPadTemplate *templ;
3158 gboolean fixed_caps;
3160 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3163 /* first try to proxy if we must */
3164 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3165 if ((gst_pad_proxy_query_caps (pad, query))) {
3170 gst_query_parse_caps (query, &filter);
3172 /* no proxy or it failed, do default handling */
3173 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3175 GST_OBJECT_LOCK (pad);
3177 /* fixed caps, try the negotiated caps first */
3178 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3179 if ((result = get_pad_caps (pad)))
3180 goto filter_done_unlock;
3183 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3184 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3185 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3186 goto filter_done_unlock;
3190 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3191 "non-fixed pad caps: trying pad caps");
3192 /* non fixed caps, try the negotiated caps */
3193 if ((result = get_pad_caps (pad)))
3194 goto filter_done_unlock;
3197 /* this almost never happens */
3198 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3199 result = GST_CAPS_ANY;
3202 GST_OBJECT_UNLOCK (pad);
3204 /* run the filter on the result */
3206 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3207 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3208 GST_PTR_FORMAT, result, result, filter, filter);
3209 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3210 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3214 "using caps %p %" GST_PTR_FORMAT, result, result);
3215 result = gst_caps_ref (result);
3217 gst_query_set_caps_result (query, result);
3218 gst_caps_unref (result);
3224 /* Default latency implementation */
3229 GstClockTime min, max;
3233 query_latency_default_fold (const GValue * item, GValue * ret,
3236 GstPad *pad = g_value_get_object (item), *peer;
3237 LatencyFoldData *fold_data = user_data;
3239 gboolean res = FALSE;
3241 query = gst_query_new_latency ();
3243 peer = gst_pad_get_peer (pad);
3245 res = gst_pad_peer_query (pad, query);
3247 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3252 GstClockTime min, max;
3254 gst_query_parse_latency (query, &live, &min, &max);
3256 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3257 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3259 /* FIXME : Why do we only take values into account if it's live ? */
3260 if (live || fold_data->count == 0) {
3261 if (min > fold_data->min)
3262 fold_data->min = min;
3264 if (fold_data->max == GST_CLOCK_TIME_NONE)
3265 fold_data->max = max;
3266 else if (max < fold_data->max)
3267 fold_data->max = max;
3269 fold_data->live = live;
3271 fold_data->count += 1;
3273 GST_DEBUG_OBJECT (pad, "latency query failed");
3274 g_value_set_boolean (ret, FALSE);
3277 gst_query_unref (query);
3279 gst_object_unref (peer);
3285 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3288 GstIteratorResult res;
3289 GValue ret = G_VALUE_INIT;
3291 LatencyFoldData fold_data;
3293 it = gst_pad_iterate_internal_links (pad);
3295 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3299 g_value_init (&ret, G_TYPE_BOOLEAN);
3302 fold_data.count = 0;
3303 fold_data.live = FALSE;
3305 fold_data.max = GST_CLOCK_TIME_NONE;
3307 g_value_set_boolean (&ret, TRUE);
3308 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3310 case GST_ITERATOR_OK:
3311 g_assert_not_reached ();
3313 case GST_ITERATOR_DONE:
3315 case GST_ITERATOR_ERROR:
3316 g_value_set_boolean (&ret, FALSE);
3318 case GST_ITERATOR_RESYNC:
3319 gst_iterator_resync (it);
3322 g_assert_not_reached ();
3325 gst_iterator_free (it);
3327 query_ret = g_value_get_boolean (&ret);
3329 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3330 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3331 fold_data.min, fold_data.max);
3333 if (fold_data.min > fold_data.max) {
3334 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3337 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3339 GST_LOG_OBJECT (pad, "latency query failed");
3349 gboolean dispatched;
3353 query_forward_func (GstPad * pad, QueryData * data)
3355 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3356 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3358 data->result |= gst_pad_peer_query (pad, data->query);
3360 data->dispatched = TRUE;
3362 /* stop on first successful reply */
3363 return data->result;
3367 * gst_pad_query_default:
3368 * @pad: a #GstPad to call the default query handler on.
3369 * @parent: (allow-none): the parent of @pad or %NULL
3370 * @query: (transfer none): the #GstQuery to handle.
3372 * Invokes the default query handler for the given pad.
3373 * The query is sent to all pads internally linked to @pad. Note that
3374 * if there are many possible sink pads that are internally linked to
3375 * @pad, only one will be sent the query.
3376 * Multi-sinkpad elements should implement custom query handlers.
3378 * Returns: %TRUE if the query was performed successfully.
3381 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3383 gboolean forward, ret = FALSE;
3385 switch (GST_QUERY_TYPE (query)) {
3386 case GST_QUERY_SCHEDULING:
3387 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3389 case GST_QUERY_ALLOCATION:
3390 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3392 case GST_QUERY_ACCEPT_CAPS:
3393 ret = gst_pad_query_accept_caps_default (pad, query);
3396 case GST_QUERY_CAPS:
3397 ret = gst_pad_query_caps_default (pad, query);
3400 case GST_QUERY_LATENCY:
3401 ret = gst_pad_query_latency_default (pad, query);
3404 case GST_QUERY_POSITION:
3405 case GST_QUERY_SEEKING:
3406 case GST_QUERY_FORMATS:
3407 case GST_QUERY_JITTER:
3408 case GST_QUERY_RATE:
3409 case GST_QUERY_CONVERT:
3415 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3416 query, GST_QUERY_TYPE_NAME (query));
3422 data.dispatched = FALSE;
3423 data.result = FALSE;
3425 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3427 if (data.dispatched) {
3430 /* nothing dispatched, assume drained */
3431 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3441 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3443 GstPad *pad = data->pad;
3444 GstPadProbeInfo *info = data->info;
3445 GstPadProbeType type, flags;
3446 GstPadProbeCallback callback;
3447 GstPadProbeReturn ret;
3448 gpointer original_data;
3450 /* if we have called this callback, do nothing */
3451 if (PROBE_COOKIE (hook) == data->cookie) {
3452 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3453 "hook %lu, cookie %u already called", hook->hook_id,
3454 PROBE_COOKIE (hook));
3458 PROBE_COOKIE (hook) = data->cookie;
3460 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3462 original_data = info->data;
3464 /* one of the scheduling types */
3465 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3468 if (G_UNLIKELY (data->handled)) {
3469 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3470 "probe previously returned HANDLED, not calling again");
3472 } else if (G_UNLIKELY (data->dropped)) {
3473 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3474 "probe previously returned DROPPED, not calling again");
3478 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3479 /* one of the data types for non-idle probes */
3480 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3481 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3483 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3484 /* one of the data types for non-idle probes */
3485 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3486 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3489 /* Type must have PULL or PUSH probe types */
3490 g_assert_not_reached ();
3493 /* one of the blocking types must match */
3494 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3495 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3497 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3498 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3500 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3501 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3502 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3505 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3506 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3507 PROBE_COOKIE (hook), flags);
3509 data->marshalled = TRUE;
3511 callback = (GstPadProbeCallback) hook->func;
3512 if (callback == NULL)
3515 info->id = hook->hook_id;
3517 GST_OBJECT_UNLOCK (pad);
3519 ret = callback (pad, info, hook->data);
3521 GST_OBJECT_LOCK (pad);
3523 if (original_data != NULL && info->data == NULL) {
3524 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3525 info->type = GST_PAD_PROBE_TYPE_INVALID;
3526 data->dropped = TRUE;
3530 case GST_PAD_PROBE_REMOVE:
3531 /* remove the probe */
3532 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3533 cleanup_hook (pad, hook);
3535 case GST_PAD_PROBE_DROP:
3536 /* need to drop the data, make sure other probes don't get called
3538 GST_DEBUG_OBJECT (pad, "asked to drop item");
3539 info->type = GST_PAD_PROBE_TYPE_INVALID;
3540 data->dropped = TRUE;
3542 case GST_PAD_PROBE_HANDLED:
3543 GST_DEBUG_OBJECT (pad, "probe handled data");
3544 data->handled = TRUE;
3546 case GST_PAD_PROBE_PASS:
3547 /* inform the pad block to let things pass */
3548 GST_DEBUG_OBJECT (pad, "asked to pass item");
3551 case GST_PAD_PROBE_OK:
3552 GST_DEBUG_OBJECT (pad, "probe returned OK");
3555 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3562 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3563 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3564 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3569 /* a probe that does not take or return any data */
3570 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3572 if (G_UNLIKELY (pad->num_probes)) { \
3573 GstFlowReturn pval = defaultval; \
3574 /* pass NULL as the data item */ \
3575 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3576 info.ABI.abi.flow_ret = defaultval; \
3577 ret = do_probe_callbacks (pad, &info, defaultval); \
3578 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3583 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3585 if (G_UNLIKELY (pad->num_probes)) { \
3586 /* pass the data item */ \
3587 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3588 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3589 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3590 /* store the possibly updated data item */ \
3591 data = GST_PAD_PROBE_INFO_DATA (&info); \
3592 /* if something went wrong, exit */ \
3593 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3594 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3595 ret = info.ABI.abi.flow_ret; \
3596 goto handle_label; \
3603 #define PROBE_PUSH(pad,mask,data,label) \
3604 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3605 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3606 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3607 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3608 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3610 static GstFlowReturn
3611 do_pad_idle_probe_wait (GstPad * pad)
3613 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3614 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3615 "waiting idle probe to be removed");
3616 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3617 GST_PAD_BLOCK_WAIT (pad);
3618 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3619 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3621 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3622 return GST_FLOW_FLUSHING;
3627 #define PROBE_TYPE_IS_SERIALIZED(i) \
3630 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3631 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3632 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3634 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3635 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3637 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3638 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3642 static GstFlowReturn
3643 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3644 GstFlowReturn defaultval)
3653 data.handled = FALSE;
3654 data.marshalled = FALSE;
3655 data.dropped = FALSE;
3656 data.cookie = ++pad->priv->probe_cookie;
3659 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3661 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3662 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3667 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3668 "do probes cookie %u", data.cookie);
3669 cookie = pad->priv->probe_list_cookie;
3671 g_hook_list_marshal (&pad->probes, TRUE,
3672 (GHookMarshaller) probe_hook_marshal, &data);
3674 /* if the list changed, call the new callbacks (they will not have their
3675 * cookie set to data.cookie */
3676 if (cookie != pad->priv->probe_list_cookie) {
3677 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3678 "probe list changed, restarting");
3682 /* the first item that dropped will stop the hooks and then we drop here */
3686 /* If one handler took care of it, let the the item pass */
3691 /* if no handler matched and we are blocking, let the item pass */
3692 if (!data.marshalled && is_block)
3695 /* At this point, all handlers returned either OK or PASS. If one handler
3696 * returned PASS, let the item pass */
3701 while (GST_PAD_IS_BLOCKED (pad)) {
3702 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3703 "we are blocked %d times", pad->num_blocked);
3705 /* we might have released the lock */
3706 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3709 /* now we block the streaming thread. It can be unlocked when we
3710 * deactivate the pad (which will also set the FLUSHING flag) or
3711 * when the pad is unblocked. A flushing event will also unblock
3712 * the pad after setting the FLUSHING flag. */
3713 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3714 "Waiting to be unblocked or set flushing");
3715 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3716 GST_PAD_BLOCK_WAIT (pad);
3717 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3718 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3720 /* if the list changed, call the new callbacks (they will not have their
3721 * cookie set to data.cookie */
3722 if (cookie != pad->priv->probe_list_cookie) {
3723 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3724 "probe list changed, restarting");
3728 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3738 GST_DEBUG_OBJECT (pad, "pad is flushing");
3739 return GST_FLOW_FLUSHING;
3743 GST_DEBUG_OBJECT (pad, "data is dropped");
3744 return GST_FLOW_CUSTOM_SUCCESS;
3748 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3749 GST_DEBUG_OBJECT (pad, "data is passed");
3754 GST_DEBUG_OBJECT (pad, "data was handled");
3755 return GST_FLOW_CUSTOM_SUCCESS_1;
3762 * gst_pad_get_offset:
3765 * Get the offset applied to the running time of @pad. @pad has to be a source
3768 * Returns: the offset.
3771 gst_pad_get_offset (GstPad * pad)
3775 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3777 GST_OBJECT_LOCK (pad);
3778 result = pad->offset;
3779 GST_OBJECT_UNLOCK (pad);
3785 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3787 ev->received = FALSE;
3792 * gst_pad_set_offset:
3794 * @offset: the offset
3796 * Set the offset that will be applied to the running time of @pad.
3799 gst_pad_set_offset (GstPad * pad, gint64 offset)
3801 g_return_if_fail (GST_IS_PAD (pad));
3803 GST_OBJECT_LOCK (pad);
3804 /* if nothing changed, do nothing */
3805 if (pad->offset == offset)
3808 pad->offset = offset;
3809 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3810 GST_STIME_ARGS (offset));
3812 /* resend all sticky events with updated offset on next buffer push */
3813 events_foreach (pad, mark_event_not_received, NULL);
3814 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3817 GST_OBJECT_UNLOCK (pad);
3824 /* If TRUE and ret is not OK this means
3825 * that pushing the EOS event failed
3829 /* If called for an event this is
3830 * the event that would be pushed
3831 * next. Don't forward sticky events
3832 * that would come after that */
3836 /* should be called with pad LOCK */
3838 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3840 PushStickyData *data = user_data;
3841 GstEvent *event = ev->event;
3844 GST_DEBUG_OBJECT (pad, "event %s was already received",
3845 GST_EVENT_TYPE_NAME (event));
3849 /* If we're called because of an sticky event, only forward
3850 * events that would come before this new event and the
3852 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3853 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3854 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3855 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3857 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3858 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3861 switch (data->ret) {
3863 ev->received = TRUE;
3864 GST_DEBUG_OBJECT (pad, "event %s marked received",
3865 GST_EVENT_TYPE_NAME (event));
3867 case GST_FLOW_CUSTOM_SUCCESS:
3868 /* we can't assume the event is received when it was dropped */
3869 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3870 GST_EVENT_TYPE_NAME (event));
3871 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3872 data->ret = GST_FLOW_OK;
3874 case GST_FLOW_CUSTOM_SUCCESS_1:
3875 /* event was ignored and should be sent later */
3876 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3877 GST_EVENT_TYPE_NAME (event));
3878 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3879 data->ret = GST_FLOW_OK;
3881 case GST_FLOW_NOT_LINKED:
3882 /* not linked is not a problem, we are sticky so the event will be
3883 * rescheduled to be sent later on re-link, but only for non-EOS events */
3884 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3885 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3886 data->ret = GST_FLOW_OK;
3887 ev->received = TRUE;
3891 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3892 gst_flow_get_name (data->ret));
3893 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3897 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3898 data->was_eos = TRUE;
3900 return data->ret == GST_FLOW_OK;
3903 /* check sticky events and push them when needed. should be called
3905 static inline GstFlowReturn
3906 check_sticky (GstPad * pad, GstEvent * event)
3908 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3910 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3911 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3913 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3914 events_foreach (pad, push_sticky, &data);
3916 /* If there's an EOS event we must push it downstream
3917 * even if sending a previous sticky event failed.
3918 * Otherwise the pipeline might wait forever for EOS.
3920 * Only do this if pushing another event than the EOS
3923 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3924 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3926 if (ev && !ev->received) {
3927 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3928 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3929 /* the event could have been dropped. Because this can only
3930 * happen if the user asked for it, it's not an error */
3931 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3932 data.ret = GST_FLOW_OK;
3942 * @pad: a #GstPad to invoke the default query on.
3943 * @query: (transfer none): the #GstQuery to perform.
3945 * Dispatches a query to a pad. The query should have been allocated by the
3946 * caller via one of the type-specific allocation functions. The element that
3947 * the pad belongs to is responsible for filling the query with an appropriate
3948 * response, which should then be parsed with a type-specific query parsing
3951 * Again, the caller is responsible for both the allocation and deallocation of
3952 * the query structure.
3954 * Please also note that some queries might need a running pipeline to work.
3956 * Returns: %TRUE if the query could be performed.
3959 gst_pad_query (GstPad * pad, GstQuery * query)
3962 gboolean res, serialized;
3963 GstPadQueryFunction func;
3964 GstPadProbeType type;
3967 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3968 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3970 if (GST_PAD_IS_SRC (pad)) {
3971 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3972 goto wrong_direction;
3973 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3974 } else if (GST_PAD_IS_SINK (pad)) {
3975 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3976 goto wrong_direction;
3977 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3979 goto unknown_direction;
3981 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3982 GST_QUERY_TYPE_NAME (query));
3983 GST_TRACER_PAD_QUERY_PRE (pad, query);
3985 serialized = GST_QUERY_IS_SERIALIZED (query);
3986 if (G_UNLIKELY (serialized))
3987 GST_PAD_STREAM_LOCK (pad);
3989 GST_OBJECT_LOCK (pad);
3990 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3991 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3992 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3994 ACQUIRE_PARENT (pad, parent, no_parent);
3995 GST_OBJECT_UNLOCK (pad);
3997 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4000 res = func (pad, parent, query);
4002 RELEASE_PARENT (parent);
4004 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4005 GST_QUERY_TYPE_NAME (query), res);
4006 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4011 GST_OBJECT_LOCK (pad);
4012 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4013 GST_OBJECT_UNLOCK (pad);
4015 if (G_UNLIKELY (serialized))
4016 GST_PAD_STREAM_UNLOCK (pad);
4023 g_warning ("pad %s:%s query %s in wrong direction",
4024 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4029 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4034 GST_DEBUG_OBJECT (pad, "had no parent");
4035 GST_OBJECT_UNLOCK (pad);
4036 if (G_UNLIKELY (serialized))
4037 GST_PAD_STREAM_UNLOCK (pad);
4042 GST_DEBUG_OBJECT (pad, "had no query function");
4043 RELEASE_PARENT (parent);
4044 if (G_UNLIKELY (serialized))
4045 GST_PAD_STREAM_UNLOCK (pad);
4050 GST_DEBUG_OBJECT (pad, "query failed");
4051 if (G_UNLIKELY (serialized))
4052 GST_PAD_STREAM_UNLOCK (pad);
4057 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4058 GST_OBJECT_UNLOCK (pad);
4059 if (G_UNLIKELY (serialized))
4060 GST_PAD_STREAM_UNLOCK (pad);
4062 /* if a probe dropped without handling, we don't sent it further but assume
4063 * that the probe did not answer the query and return FALSE */
4064 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4074 * gst_pad_peer_query:
4075 * @pad: a #GstPad to invoke the peer query on.
4076 * @query: (transfer none): the #GstQuery to perform.
4078 * Performs gst_pad_query() on the peer of @pad.
4080 * The caller is responsible for both the allocation and deallocation of
4081 * the query structure.
4083 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4084 * if @pad has no peer.
4087 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4090 GstPadProbeType type;
4091 gboolean res, serialized;
4094 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4095 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4097 if (GST_PAD_IS_SRC (pad)) {
4098 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4099 goto wrong_direction;
4100 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4101 } else if (GST_PAD_IS_SINK (pad)) {
4102 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4103 goto wrong_direction;
4104 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4106 goto unknown_direction;
4108 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4109 GST_QUERY_TYPE_NAME (query));
4111 serialized = GST_QUERY_IS_SERIALIZED (query);
4113 GST_OBJECT_LOCK (pad);
4114 if (GST_PAD_IS_SRC (pad) && serialized) {
4115 /* all serialized queries on the srcpad trigger push of
4117 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4121 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4122 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4123 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4125 peerpad = GST_PAD_PEER (pad);
4126 if (G_UNLIKELY (peerpad == NULL))
4129 gst_object_ref (peerpad);
4130 GST_OBJECT_UNLOCK (pad);
4132 res = gst_pad_query (peerpad, query);
4134 gst_object_unref (peerpad);
4139 GST_OBJECT_LOCK (pad);
4140 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4141 GST_OBJECT_UNLOCK (pad);
4148 g_warning ("pad %s:%s query %s in wrong direction",
4149 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4154 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4159 GST_WARNING_OBJECT (pad, "could not send sticky events");
4160 GST_OBJECT_UNLOCK (pad);
4165 GST_INFO_OBJECT (pad, "pad has no peer");
4166 GST_OBJECT_UNLOCK (pad);
4171 GST_DEBUG_OBJECT (pad, "query failed");
4176 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4177 GST_OBJECT_UNLOCK (pad);
4179 /* if a probe dropped without handling, we don't sent it further but
4180 * assume that the probe did not answer the query and return FALSE */
4181 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4190 /**********************************************************************
4191 * Data passing functions
4194 /* this is the chain function that does not perform the additional argument
4195 * checking for that little extra speed.
4197 static inline GstFlowReturn
4198 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4202 gboolean handled = FALSE;
4204 GST_PAD_STREAM_LOCK (pad);
4206 GST_OBJECT_LOCK (pad);
4207 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4210 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4213 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4216 #ifdef GST_ENABLE_EXTRA_CHECKS
4217 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4218 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4220 ":%s:<%s:%s> Got data flow before stream-start event",
4221 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4223 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4225 ":%s:<%s:%s> Got data flow before segment event",
4226 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4228 pad->priv->last_cookie = pad->priv->events_cookie;
4232 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4235 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4237 ACQUIRE_PARENT (pad, parent, no_parent);
4238 GST_OBJECT_UNLOCK (pad);
4240 /* NOTE: we read the chainfunc unlocked.
4241 * we cannot hold the lock for the pad so we might send
4242 * the data to the wrong function. This is not really a
4243 * problem since functions are assigned at creation time
4244 * and don't change that often... */
4245 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4246 GstPadChainFunction chainfunc;
4248 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4251 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4252 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4253 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4255 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4257 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4258 "called chainfunction &%s with buffer %p, returned %s",
4259 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4261 GstPadChainListFunction chainlistfunc;
4263 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4266 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4267 "calling chainlistfunction &%s",
4268 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4270 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4272 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4273 "called chainlistfunction &%s, returned %s",
4274 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4277 RELEASE_PARENT (parent);
4279 GST_PAD_STREAM_UNLOCK (pad);
4286 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4287 "chaining, but pad was flushing");
4288 GST_OBJECT_UNLOCK (pad);
4289 GST_PAD_STREAM_UNLOCK (pad);
4290 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4291 return GST_FLOW_FLUSHING;
4295 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4296 GST_OBJECT_UNLOCK (pad);
4297 GST_PAD_STREAM_UNLOCK (pad);
4298 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4299 return GST_FLOW_EOS;
4303 g_critical ("chain on pad %s:%s but it was not in push mode",
4304 GST_DEBUG_PAD_NAME (pad));
4305 GST_OBJECT_UNLOCK (pad);
4306 GST_PAD_STREAM_UNLOCK (pad);
4307 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4308 return GST_FLOW_ERROR;
4315 GST_OBJECT_UNLOCK (pad);
4316 GST_PAD_STREAM_UNLOCK (pad);
4317 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4319 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4322 case GST_FLOW_CUSTOM_SUCCESS:
4323 case GST_FLOW_CUSTOM_SUCCESS_1:
4324 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4328 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4335 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4336 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4337 GST_OBJECT_UNLOCK (pad);
4338 GST_PAD_STREAM_UNLOCK (pad);
4339 return GST_FLOW_FLUSHING;
4343 RELEASE_PARENT (parent);
4344 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4345 g_critical ("chain on pad %s:%s but it has no chainfunction",
4346 GST_DEBUG_PAD_NAME (pad));
4347 GST_PAD_STREAM_UNLOCK (pad);
4348 return GST_FLOW_NOT_SUPPORTED;
4354 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4355 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4358 * Chain a buffer to @pad.
4360 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4362 * If the buffer type is not acceptable for @pad (as negotiated with a
4363 * preceding GST_EVENT_CAPS event), this function returns
4364 * #GST_FLOW_NOT_NEGOTIATED.
4366 * The function proceeds calling the chain function installed on @pad (see
4367 * gst_pad_set_chain_function()) and the return value of that function is
4368 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4371 * In all cases, success or failure, the caller loses its reference to @buffer
4372 * after calling this function.
4374 * Returns: a #GstFlowReturn from the pad.
4379 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4381 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4382 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4383 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4385 return gst_pad_chain_data_unchecked (pad,
4386 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4389 static GstFlowReturn
4390 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4391 GstBufferList * list)
4397 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4399 len = gst_buffer_list_length (list);
4402 for (i = 0; i < len; i++) {
4403 buffer = gst_buffer_list_get (list, i);
4405 gst_pad_chain_data_unchecked (pad,
4406 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4407 gst_buffer_ref (buffer));
4408 if (ret != GST_FLOW_OK)
4411 gst_buffer_list_unref (list);
4417 * gst_pad_chain_list:
4418 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4419 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4422 * Chain a bufferlist to @pad.
4424 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4426 * If @pad was not negotiated properly with a CAPS event, this function
4427 * returns #GST_FLOW_NOT_NEGOTIATED.
4429 * The function proceeds calling the chainlist function installed on @pad (see
4430 * gst_pad_set_chain_list_function()) and the return value of that function is
4431 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4432 * chainlist function.
4434 * In all cases, success or failure, the caller loses its reference to @list
4435 * after calling this function.
4439 * Returns: a #GstFlowReturn from the pad.
4442 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4444 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4445 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4446 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4448 return gst_pad_chain_data_unchecked (pad,
4449 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4452 static GstFlowReturn
4453 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4457 gboolean handled = FALSE;
4459 GST_OBJECT_LOCK (pad);
4460 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4463 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4466 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4469 #ifdef GST_ENABLE_EXTRA_CHECKS
4470 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4471 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4473 ":%s:<%s:%s> Got data flow before stream-start event",
4474 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4476 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4478 ":%s:<%s:%s> Got data flow before segment event",
4479 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4481 pad->priv->last_cookie = pad->priv->events_cookie;
4485 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4488 /* do block probes */
4489 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4492 /* recheck sticky events because the probe might have cause a relink */
4493 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4496 /* do post-blocking probes */
4497 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4499 /* recheck sticky events because the probe might have cause a relink */
4500 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4503 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4506 /* take ref to peer pad before releasing the lock */
4507 gst_object_ref (peer);
4509 GST_OBJECT_UNLOCK (pad);
4511 ret = gst_pad_chain_data_unchecked (peer, type, data);
4514 gst_object_unref (peer);
4516 GST_OBJECT_LOCK (pad);
4517 pad->ABI.abi.last_flowret = ret;
4519 if (pad->priv->using == 0) {
4520 /* pad is not active anymore, trigger idle callbacks */
4521 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4522 probe_stopped, ret);
4524 GST_OBJECT_UNLOCK (pad);
4528 /* ERROR recovery here */
4532 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4533 "pushing, but pad was flushing");
4534 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4535 GST_OBJECT_UNLOCK (pad);
4536 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4537 return GST_FLOW_FLUSHING;
4541 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4542 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4543 GST_OBJECT_UNLOCK (pad);
4544 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4545 return GST_FLOW_EOS;
4549 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4550 GST_DEBUG_PAD_NAME (pad));
4551 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4552 GST_OBJECT_UNLOCK (pad);
4553 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4554 return GST_FLOW_ERROR;
4558 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4559 "error pushing events, return %s", gst_flow_get_name (ret));
4560 pad->ABI.abi.last_flowret = ret;
4561 GST_OBJECT_UNLOCK (pad);
4562 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4570 GST_OBJECT_UNLOCK (pad);
4571 if (data != NULL && !handled)
4572 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4575 case GST_FLOW_CUSTOM_SUCCESS:
4576 case GST_FLOW_CUSTOM_SUCCESS_1:
4577 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4581 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4584 pad->ABI.abi.last_flowret = ret;
4589 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4590 "pushing, but it was not linked");
4591 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4592 GST_OBJECT_UNLOCK (pad);
4593 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4594 return GST_FLOW_NOT_LINKED;
4600 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4601 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4604 * Pushes a buffer to the peer of @pad.
4606 * This function will call installed block probes before triggering any
4607 * installed data probes.
4609 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4610 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4613 * In all cases, success or failure, the caller loses its reference to @buffer
4614 * after calling this function.
4616 * Returns: a #GstFlowReturn from the peer pad.
4621 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4625 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4626 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4627 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4629 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4630 res = gst_pad_push_data (pad,
4631 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4632 GST_TRACER_PAD_PUSH_POST (pad, res);
4637 * gst_pad_push_list:
4638 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4639 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4642 * Pushes a buffer list to the peer of @pad.
4644 * This function will call installed block probes before triggering any
4645 * installed data probes.
4647 * The function proceeds calling the chain function on the peer pad and returns
4648 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4649 * be returned. If the peer pad does not have any installed chainlist function
4650 * every group buffer of the list will be merged into a normal #GstBuffer and
4651 * chained via gst_pad_chain().
4653 * In all cases, success or failure, the caller loses its reference to @list
4654 * after calling this function.
4656 * Returns: a #GstFlowReturn from the peer pad.
4661 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4665 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4666 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4667 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4669 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4670 res = gst_pad_push_data (pad,
4671 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4672 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4676 static GstFlowReturn
4677 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4678 GstBuffer ** buffer)
4681 GstPadGetRangeFunction getrangefunc;
4685 GST_PAD_STREAM_LOCK (pad);
4687 GST_OBJECT_LOCK (pad);
4688 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4691 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4694 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4699 /* when one of the probes returns DROPPED, probe_stopped will be called
4700 * and we skip calling the getrange function, res_buf should then contain a
4701 * valid result buffer */
4702 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4703 res_buf, offset, size, probe_stopped);
4705 /* recheck sticky events because the probe might have cause a relink */
4706 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4709 ACQUIRE_PARENT (pad, parent, no_parent);
4710 GST_OBJECT_UNLOCK (pad);
4712 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4715 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4716 "calling getrangefunc %s, offset %"
4717 G_GUINT64_FORMAT ", size %u",
4718 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4720 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4722 RELEASE_PARENT (parent);
4724 GST_OBJECT_LOCK (pad);
4725 if (G_UNLIKELY (ret != GST_FLOW_OK))
4726 goto get_range_failed;
4728 /* can only fire the signal if we have a valid buffer */
4730 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4731 res_buf, offset, size, probe_stopped_unref);
4732 pad->ABI.abi.last_flowret = ret;
4733 GST_OBJECT_UNLOCK (pad);
4735 GST_PAD_STREAM_UNLOCK (pad);
4744 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4745 "getrange, but pad was flushing");
4746 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4747 GST_OBJECT_UNLOCK (pad);
4748 GST_PAD_STREAM_UNLOCK (pad);
4749 return GST_FLOW_FLUSHING;
4753 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4754 GST_DEBUG_PAD_NAME (pad));
4755 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4756 GST_OBJECT_UNLOCK (pad);
4757 GST_PAD_STREAM_UNLOCK (pad);
4758 return GST_FLOW_ERROR;
4762 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4763 pad->ABI.abi.last_flowret = ret;
4764 GST_OBJECT_UNLOCK (pad);
4765 GST_PAD_STREAM_UNLOCK (pad);
4770 GST_DEBUG_OBJECT (pad, "no parent");
4771 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4772 GST_OBJECT_UNLOCK (pad);
4773 GST_PAD_STREAM_UNLOCK (pad);
4774 return GST_FLOW_FLUSHING;
4778 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4779 GST_DEBUG_PAD_NAME (pad));
4780 RELEASE_PARENT (parent);
4781 GST_PAD_STREAM_UNLOCK (pad);
4782 return GST_FLOW_NOT_SUPPORTED;
4786 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4787 "probe returned %s", gst_flow_get_name (ret));
4788 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4790 /* the probe filled the buffer and asks us to not call the getrange
4791 * anymore, we continue with the post probes then. */
4792 GST_DEBUG_OBJECT (pad, "handled buffer");
4796 /* no buffer, we are EOS */
4797 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4801 pad->ABI.abi.last_flowret = ret;
4802 GST_OBJECT_UNLOCK (pad);
4803 GST_PAD_STREAM_UNLOCK (pad);
4807 probe_stopped_unref:
4809 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4810 "probe returned %s", gst_flow_get_name (ret));
4811 /* if we drop here, it signals EOS */
4812 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4814 pad->ABI.abi.last_flowret = ret;
4815 GST_OBJECT_UNLOCK (pad);
4816 GST_PAD_STREAM_UNLOCK (pad);
4817 if (*buffer == NULL)
4818 gst_buffer_unref (res_buf);
4823 pad->ABI.abi.last_flowret = ret;
4824 GST_OBJECT_UNLOCK (pad);
4825 GST_PAD_STREAM_UNLOCK (pad);
4826 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4827 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4828 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4834 * gst_pad_get_range:
4835 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4836 * @offset: The start offset of the buffer
4837 * @size: The length of the buffer
4838 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4839 * returns #GST_FLOW_ERROR if %NULL.
4841 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4842 * immediately and @buffer is %NULL.
4844 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4845 * description of a getrange function. If @pad has no getrange function
4846 * installed (see gst_pad_set_getrange_function()) this function returns
4847 * #GST_FLOW_NOT_SUPPORTED.
4849 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4850 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4851 * must be freed with gst_buffer_unref() after usage.
4853 * When @buffer points to a variable that points to a valid #GstBuffer, the
4854 * buffer will be filled with the result data when this function returns
4855 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4856 * @size bytes will be filled in the result buffer and its size will be updated
4859 * Note that less than @size bytes can be returned in @buffer when, for example,
4860 * an EOS condition is near or when @buffer is not large enough to hold @size
4861 * bytes. The caller should check the result buffer size to get the result size.
4863 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4864 * will be unchanged.
4866 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4868 * Returns: a #GstFlowReturn from the pad.
4873 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4874 GstBuffer ** buffer)
4876 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4877 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4878 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4879 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4880 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4882 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4886 * gst_pad_pull_range:
4887 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4888 * @offset: The start offset of the buffer
4889 * @size: The length of the buffer
4890 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4891 * GST_FLOW_ERROR if %NULL.
4893 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4895 * This function will first trigger the pad block signal if it was
4898 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4899 * function returns the result of gst_pad_get_range() on the peer pad.
4900 * See gst_pad_get_range() for a list of return values and for the
4901 * semantics of the arguments of this function.
4903 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4904 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4905 * must be freed with gst_buffer_unref() after usage. When this function
4906 * returns any other result value, @buffer will still point to %NULL.
4908 * When @buffer points to a variable that points to a valid #GstBuffer, the
4909 * buffer will be filled with the result data when this function returns
4910 * #GST_FLOW_OK. When this function returns any other result value,
4911 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4912 * @size bytes will be filled in the result buffer and its size will be updated
4915 * Note that less than @size bytes can be returned in @buffer when, for example,
4916 * an EOS condition is near or when @buffer is not large enough to hold @size
4917 * bytes. The caller should check the result buffer size to get the result size.
4919 * Returns: a #GstFlowReturn from the peer pad.
4924 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4925 GstBuffer ** buffer)
4931 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4932 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4933 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4934 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4935 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4937 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4939 GST_OBJECT_LOCK (pad);
4940 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4943 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4948 /* when one of the probes returns DROPPED, probe_stopped will be
4949 * called and we skip calling the peer getrange function. *buffer should then
4950 * contain a valid buffer */
4951 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4952 res_buf, offset, size, probe_stopped);
4954 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4957 gst_object_ref (peer);
4959 GST_OBJECT_UNLOCK (pad);
4961 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4963 gst_object_unref (peer);
4965 GST_OBJECT_LOCK (pad);
4967 pad->ABI.abi.last_flowret = ret;
4968 if (pad->priv->using == 0) {
4969 /* pad is not active anymore, trigger idle callbacks */
4970 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4971 probe_stopped_unref, ret);
4974 if (G_UNLIKELY (ret != GST_FLOW_OK))
4975 goto pull_range_failed;
4978 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4979 res_buf, offset, size, probe_stopped_unref);
4981 GST_OBJECT_UNLOCK (pad);
4985 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4988 /* ERROR recovery here */
4991 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4992 "pullrange, but pad was flushing");
4993 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4994 GST_OBJECT_UNLOCK (pad);
4995 ret = GST_FLOW_FLUSHING;
5000 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5001 GST_DEBUG_PAD_NAME (pad));
5002 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5003 GST_OBJECT_UNLOCK (pad);
5004 ret = GST_FLOW_ERROR;
5009 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5010 gst_flow_get_name (ret));
5011 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5013 /* the probe filled the buffer and asks us to not forward to the peer
5014 * anymore, we continue with the post probes then */
5015 GST_DEBUG_OBJECT (pad, "handled buffer");
5019 /* no buffer, we are EOS then */
5020 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5024 pad->ABI.abi.last_flowret = ret;
5025 GST_OBJECT_UNLOCK (pad);
5030 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5031 "pulling range, but it was not linked");
5032 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5033 GST_OBJECT_UNLOCK (pad);
5034 ret = GST_FLOW_NOT_LINKED;
5039 pad->ABI.abi.last_flowret = ret;
5040 GST_OBJECT_UNLOCK (pad);
5041 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5042 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5043 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5046 probe_stopped_unref:
5048 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5049 "post probe returned %s", gst_flow_get_name (ret));
5051 /* if we drop here, it signals EOS */
5052 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5055 pad->ABI.abi.last_flowret = ret;
5056 GST_OBJECT_UNLOCK (pad);
5058 if (*buffer == NULL)
5059 gst_buffer_unref (res_buf);
5063 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5067 /* must be called with pad object lock */
5068 static GstFlowReturn
5069 store_sticky_event (GstPad * pad, GstEvent * event)
5074 gboolean res = FALSE;
5075 const gchar *name = NULL;
5076 gboolean insert = TRUE;
5078 type = GST_EVENT_TYPE (event);
5080 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5081 * otherwise they can be dropped and nothing would ever resend them.
5082 * Only do that for activated pads though, everything else is a bug!
5084 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5085 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5086 || type == GST_EVENT_EOS))))
5089 /* Unset the EOS flag when received STREAM_START event, so pad can
5090 * store sticky event and then push it later */
5091 if (type == GST_EVENT_STREAM_START) {
5092 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5093 remove_event_by_type (pad, GST_EVENT_EOS);
5094 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5095 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5098 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5101 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5102 name = gst_structure_get_name (gst_event_get_structure (event));
5104 events = pad->priv->events;
5107 for (i = 0; i < len; i++) {
5108 PadEvent *ev = &g_array_index (events, PadEvent, i);
5110 if (ev->event == NULL)
5113 if (type == GST_EVENT_TYPE (ev->event)) {
5114 /* matching types, check matching name if needed */
5115 if (name && !gst_event_has_name (ev->event, name))
5119 if ((res = gst_event_replace (&ev->event, event)))
5120 ev->received = FALSE;
5126 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5127 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5128 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5129 * storing the sticky ordered we can check that this is respected. */
5130 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5131 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5133 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5134 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5135 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5136 gst_event_type_get_name (type));
5142 ev.event = gst_event_ref (event);
5143 ev.received = FALSE;
5144 g_array_insert_val (events, i, ev);
5149 pad->priv->events_cookie++;
5150 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5152 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5154 switch (GST_EVENT_TYPE (event)) {
5155 case GST_EVENT_CAPS:
5156 GST_OBJECT_UNLOCK (pad);
5158 GST_DEBUG_OBJECT (pad, "notify caps");
5159 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5161 GST_OBJECT_LOCK (pad);
5167 if (type == GST_EVENT_EOS) {
5168 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5169 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5172 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5177 GST_DEBUG_OBJECT (pad, "pad is flushing");
5178 return GST_FLOW_FLUSHING;
5182 GST_DEBUG_OBJECT (pad, "pad is EOS");
5183 return GST_FLOW_EOS;
5188 * gst_pad_store_sticky_event:
5190 * @event: (transfer none): a #GstEvent
5192 * Store the sticky @event on @pad
5194 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5195 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5200 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5204 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5205 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5207 GST_OBJECT_LOCK (pad);
5208 ret = store_sticky_event (pad, event);
5209 GST_OBJECT_UNLOCK (pad);
5215 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5217 PushStickyData *data = user_data;
5219 /* Forward all sticky events before our current one that are pending */
5220 if (ev->event != data->event
5221 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5222 return push_sticky (pad, ev, data);
5227 /* should be called with pad LOCK */
5228 static GstFlowReturn
5229 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5230 GstPadProbeType type)
5234 GstEventType event_type;
5236 /* pass the adjusted event on. We need to do this even if
5237 * there is no peer pad because of the probes. */
5238 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5240 /* Two checks to be made:
5241 * . (un)set the FLUSHING flag for flushing events,
5242 * . handle pad blocking */
5243 event_type = GST_EVENT_TYPE (event);
5244 switch (event_type) {
5245 case GST_EVENT_FLUSH_START:
5246 GST_PAD_SET_FLUSHING (pad);
5248 GST_PAD_BLOCK_BROADCAST (pad);
5249 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5251 case GST_EVENT_FLUSH_STOP:
5252 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5255 GST_PAD_UNSET_FLUSHING (pad);
5257 /* Remove sticky EOS events */
5258 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5259 remove_event_by_type (pad, GST_EVENT_EOS);
5260 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5261 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5262 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5263 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5265 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5269 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5272 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5273 * checked already or this is called as part of pushing sticky events,
5274 * in which case we still want to forward the EOS event downstream.
5277 switch (GST_EVENT_TYPE (event)) {
5278 case GST_EVENT_RECONFIGURE:
5279 if (GST_PAD_IS_SINK (pad))
5280 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5285 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5286 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5287 /* recheck sticky events because the probe might have cause a relink */
5288 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5289 && (GST_EVENT_IS_SERIALIZED (event)
5290 || GST_EVENT_IS_STICKY (event))) {
5291 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5292 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5294 /* Push all sticky events before our current one
5295 * that have changed */
5296 events_foreach (pad, sticky_changed, &data);
5302 /* send probes after modifying the events above */
5303 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5305 /* recheck sticky events because the probe might have cause a relink */
5306 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5307 && (GST_EVENT_IS_SERIALIZED (event)
5308 || GST_EVENT_IS_STICKY (event))) {
5309 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5310 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5312 /* Push all sticky events before our current one
5313 * that have changed */
5314 events_foreach (pad, sticky_changed, &data);
5317 /* now check the peer pad */
5318 peerpad = GST_PAD_PEER (pad);
5319 if (peerpad == NULL)
5322 gst_object_ref (peerpad);
5324 GST_OBJECT_UNLOCK (pad);
5326 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5327 event, gst_event_type_get_name (event_type), peerpad);
5329 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5331 /* Note: we gave away ownership of the event at this point but we can still
5332 * print the old pointer */
5333 GST_LOG_OBJECT (pad,
5334 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5335 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5337 gst_object_unref (peerpad);
5339 GST_OBJECT_LOCK (pad);
5341 if (pad->priv->using == 0) {
5342 /* pad is not active anymore, trigger idle callbacks */
5343 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5344 idle_probe_stopped, ret);
5348 /* ERROR handling */
5351 GST_DEBUG_OBJECT (pad, "We're flushing");
5352 gst_event_unref (event);
5353 return GST_FLOW_FLUSHING;
5357 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5358 gst_event_unref (event);
5359 return GST_FLOW_FLUSHING;
5363 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5364 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5365 gst_event_unref (event);
5368 case GST_FLOW_CUSTOM_SUCCESS_1:
5369 GST_DEBUG_OBJECT (pad, "handled event");
5371 case GST_FLOW_CUSTOM_SUCCESS:
5372 GST_DEBUG_OBJECT (pad, "dropped event");
5375 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5382 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5383 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5384 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5385 gst_event_unref (event);
5387 /* unlinked pads should not influence latency configuration */
5388 if (event_type == GST_EVENT_LATENCY)
5391 return GST_FLOW_NOT_LINKED;
5395 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5401 * gst_pad_push_event:
5402 * @pad: a #GstPad to push the event to.
5403 * @event: (transfer full): the #GstEvent to send to the pad.
5405 * Sends the event to the peer of the given pad. This function is
5406 * mainly used by elements to send events to their peer
5409 * This function takes ownership of the provided event so you should
5410 * gst_event_ref() it if you want to reuse the event after this call.
5412 * Returns: %TRUE if the event was handled.
5417 gst_pad_push_event (GstPad * pad, GstEvent * event)
5419 gboolean res = FALSE;
5420 GstPadProbeType type;
5421 gboolean sticky, serialized;
5423 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5424 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5426 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5428 if (GST_PAD_IS_SRC (pad)) {
5429 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5430 goto wrong_direction;
5431 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5432 } else if (GST_PAD_IS_SINK (pad)) {
5433 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5434 goto wrong_direction;
5435 /* events pushed on sinkpad never are sticky */
5436 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5438 goto unknown_direction;
5440 GST_OBJECT_LOCK (pad);
5441 sticky = GST_EVENT_IS_STICKY (event);
5442 serialized = GST_EVENT_IS_SERIALIZED (event);
5445 /* srcpad sticky events are stored immediately, the received flag is set
5446 * to FALSE and will be set to TRUE when we can successfully push the
5447 * event to the peer pad */
5448 switch (store_sticky_event (pad, event)) {
5449 case GST_FLOW_FLUSHING:
5457 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5458 /* all serialized or sticky events on the srcpad trigger push of
5460 res = (check_sticky (pad, event) == GST_FLOW_OK);
5465 /* other events are pushed right away */
5466 ret = gst_pad_push_event_unchecked (pad, event, type);
5467 /* dropped events by a probe are not an error */
5468 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5469 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5471 /* Errors in sticky event pushing are no problem and ignored here
5472 * as they will cause more meaningful errors during data flow.
5473 * For EOS events, that are not followed by data flow, we still
5474 * return FALSE here though.
5476 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5478 gst_event_unref (event);
5480 GST_OBJECT_UNLOCK (pad);
5482 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5485 /* ERROR handling */
5488 g_warning ("pad %s:%s pushing %s event in wrong direction",
5489 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5490 gst_event_unref (event);
5495 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5496 gst_event_unref (event);
5501 GST_DEBUG_OBJECT (pad, "We're flushing");
5502 GST_OBJECT_UNLOCK (pad);
5503 gst_event_unref (event);
5508 GST_DEBUG_OBJECT (pad, "We're EOS");
5509 GST_OBJECT_UNLOCK (pad);
5510 gst_event_unref (event);
5514 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5518 /* Check if we can call the event function with the given event */
5519 static GstFlowReturn
5520 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5524 switch (GST_EVENT_TYPE (event)) {
5525 case GST_EVENT_CAPS:
5527 /* backwards compatibility mode for caps */
5528 gst_event_parse_caps (event, &caps);
5530 if (!gst_pad_query_accept_caps (pad, caps))
5542 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5543 "caps %" GST_PTR_FORMAT " not accepted", caps);
5544 return GST_FLOW_NOT_NEGOTIATED;
5548 static GstFlowReturn
5549 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5550 GstPadProbeType type)
5553 GstEventType event_type;
5554 gboolean serialized, need_unlock = FALSE, sticky;
5555 GstPadEventFunction eventfunc;
5556 GstPadEventFullFunction eventfullfunc = NULL;
5559 GST_OBJECT_LOCK (pad);
5561 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5563 if (GST_PAD_IS_SINK (pad))
5564 serialized = GST_EVENT_IS_SERIALIZED (event);
5567 sticky = GST_EVENT_IS_STICKY (event);
5568 event_type = GST_EVENT_TYPE (event);
5569 switch (event_type) {
5570 case GST_EVENT_FLUSH_START:
5571 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5572 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5574 /* can't even accept a flush begin event when flushing */
5575 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5578 GST_PAD_SET_FLUSHING (pad);
5579 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5580 GST_PAD_BLOCK_BROADCAST (pad);
5581 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5583 case GST_EVENT_FLUSH_STOP:
5584 /* we can't accept flush-stop on inactive pads else the flushing flag
5585 * would be cleared and it would look like the pad can accept data.
5586 * Also, some elements restart a streaming thread in flush-stop which we
5587 * can't allow on inactive pads */
5588 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5591 GST_PAD_UNSET_FLUSHING (pad);
5592 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5593 /* Remove pending EOS events */
5594 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5595 remove_event_by_type (pad, GST_EVENT_EOS);
5596 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5597 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5598 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5599 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5601 GST_OBJECT_UNLOCK (pad);
5602 /* grab stream lock */
5603 GST_PAD_STREAM_LOCK (pad);
5605 GST_OBJECT_LOCK (pad);
5606 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5609 case GST_EVENT_RECONFIGURE:
5610 if (GST_PAD_IS_SRC (pad))
5611 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5613 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5614 "have event type %" GST_PTR_FORMAT, event);
5616 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5619 switch (event_type) {
5620 case GST_EVENT_STREAM_START:
5621 /* Remove sticky EOS events */
5622 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5623 remove_event_by_type (pad, GST_EVENT_EOS);
5624 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5625 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5632 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5635 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5636 GST_OBJECT_UNLOCK (pad);
5637 GST_PAD_STREAM_LOCK (pad);
5639 GST_OBJECT_LOCK (pad);
5640 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5643 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5649 /* now do the probe */
5651 type | GST_PAD_PROBE_TYPE_PUSH |
5652 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5654 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5656 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5657 eventfunc = GST_PAD_EVENTFUNC (pad);
5658 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5661 ACQUIRE_PARENT (pad, parent, no_parent);
5662 GST_OBJECT_UNLOCK (pad);
5664 ret = pre_eventfunc_check (pad, event);
5665 if (G_UNLIKELY (ret != GST_FLOW_OK))
5666 goto precheck_failed;
5669 gst_event_ref (event);
5671 if (eventfullfunc) {
5672 ret = eventfullfunc (pad, parent, event);
5673 } else if (eventfunc (pad, parent, event)) {
5676 /* something went wrong */
5677 switch (event_type) {
5678 case GST_EVENT_CAPS:
5679 ret = GST_FLOW_NOT_NEGOTIATED;
5682 ret = GST_FLOW_ERROR;
5686 RELEASE_PARENT (parent);
5688 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5691 if (ret == GST_FLOW_OK) {
5692 GST_OBJECT_LOCK (pad);
5693 /* after the event function accepted the event, we can store the sticky
5694 * event on the pad */
5695 switch (store_sticky_event (pad, event)) {
5696 case GST_FLOW_FLUSHING:
5703 GST_OBJECT_UNLOCK (pad);
5705 gst_event_unref (event);
5709 GST_PAD_STREAM_UNLOCK (pad);
5713 /* ERROR handling */
5716 GST_OBJECT_UNLOCK (pad);
5718 GST_PAD_STREAM_UNLOCK (pad);
5719 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5720 "Received event on flushing pad. Discarding");
5721 gst_event_unref (event);
5722 return GST_FLOW_FLUSHING;
5726 GST_OBJECT_UNLOCK (pad);
5728 GST_PAD_STREAM_UNLOCK (pad);
5729 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5730 "Received flush-stop on inactive pad. Discarding");
5731 gst_event_unref (event);
5732 return GST_FLOW_FLUSHING;
5736 GST_OBJECT_UNLOCK (pad);
5738 GST_PAD_STREAM_UNLOCK (pad);
5739 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5740 "Received event on EOS pad. Discarding");
5741 gst_event_unref (event);
5742 return GST_FLOW_EOS;
5746 GST_OBJECT_UNLOCK (pad);
5748 GST_PAD_STREAM_UNLOCK (pad);
5749 /* Only unref if unhandled */
5750 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5751 gst_event_unref (event);
5754 case GST_FLOW_CUSTOM_SUCCESS_1:
5755 case GST_FLOW_CUSTOM_SUCCESS:
5756 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5760 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5767 g_warning ("pad %s:%s has no event handler, file a bug.",
5768 GST_DEBUG_PAD_NAME (pad));
5769 GST_OBJECT_UNLOCK (pad);
5771 GST_PAD_STREAM_UNLOCK (pad);
5772 gst_event_unref (event);
5773 return GST_FLOW_NOT_SUPPORTED;
5777 GST_DEBUG_OBJECT (pad, "no parent");
5778 GST_OBJECT_UNLOCK (pad);
5780 GST_PAD_STREAM_UNLOCK (pad);
5781 gst_event_unref (event);
5782 return GST_FLOW_FLUSHING;
5786 GST_DEBUG_OBJECT (pad, "pre event check failed");
5787 RELEASE_PARENT (parent);
5789 GST_PAD_STREAM_UNLOCK (pad);
5790 gst_event_unref (event);
5796 * gst_pad_send_event:
5797 * @pad: a #GstPad to send the event to.
5798 * @event: (transfer full): the #GstEvent to send to the pad.
5800 * Sends the event to the pad. This function can be used
5801 * by applications to send events in the pipeline.
5803 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5804 * sink pad, @event should be a downstream event. For example, you would not
5805 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5806 * Furthermore, some downstream events have to be serialized with data flow,
5807 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5808 * the event needs to be serialized with data flow, this function will take the
5809 * pad's stream lock while calling its event function.
5811 * To find out whether an event type is upstream, downstream, or downstream and
5812 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5813 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5814 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5815 * plugin doesn't need to bother itself with this information; the core handles
5816 * all necessary locks and checks.
5818 * This function takes ownership of the provided event so you should
5819 * gst_event_ref() it if you want to reuse the event after this call.
5821 * Returns: %TRUE if the event was handled.
5824 gst_pad_send_event (GstPad * pad, GstEvent * event)
5827 GstPadProbeType type;
5829 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5830 g_return_val_if_fail (event != NULL, FALSE);
5832 if (GST_PAD_IS_SINK (pad)) {
5833 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5834 goto wrong_direction;
5835 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5836 } else if (GST_PAD_IS_SRC (pad)) {
5837 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5838 goto wrong_direction;
5839 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5841 goto unknown_direction;
5843 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5850 /* ERROR handling */
5853 g_warning ("pad %s:%s sending %s event in wrong direction",
5854 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5855 gst_event_unref (event);
5860 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5861 gst_event_unref (event);
5867 * gst_pad_set_element_private:
5868 * @pad: the #GstPad to set the private data of.
5869 * @priv: The private data to attach to the pad.
5871 * Set the given private data gpointer on the pad.
5872 * This function can only be used by the element that owns the pad.
5873 * No locking is performed in this function.
5876 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5878 pad->element_private = priv;
5882 * gst_pad_get_element_private:
5883 * @pad: the #GstPad to get the private data of.
5885 * Gets the private data of a pad.
5886 * No locking is performed in this function.
5888 * Returns: (transfer none): a #gpointer to the private data.
5891 gst_pad_get_element_private (GstPad * pad)
5893 return pad->element_private;
5897 * gst_pad_get_sticky_event:
5898 * @pad: the #GstPad to get the event from.
5899 * @event_type: the #GstEventType that should be retrieved.
5900 * @idx: the index of the event
5902 * Returns a new reference of the sticky event of type @event_type
5905 * Returns: (transfer full) (nullable): a #GstEvent of type
5906 * @event_type or %NULL when no event of @event_type was on
5907 * @pad. Unref after usage.
5910 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5912 GstEvent *event = NULL;
5915 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5916 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5918 GST_OBJECT_LOCK (pad);
5919 ev = find_event_by_type (pad, event_type, idx);
5920 if (ev && (event = ev->event))
5921 gst_event_ref (event);
5922 GST_OBJECT_UNLOCK (pad);
5929 GstPadStickyEventsForeachFunction func;
5934 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5936 ForeachDispatch *data = user_data;
5937 gboolean ret = TRUE;
5940 GST_OBJECT_UNLOCK (pad);
5942 ret = data->func (pad, &ev->event, data->user_data);
5944 GST_OBJECT_LOCK (pad);
5951 * gst_pad_sticky_events_foreach:
5952 * @pad: the #GstPad that should be used for iteration.
5953 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5954 * should be called for every event.
5955 * @user_data: (closure): the optional user data.
5957 * Iterates all sticky events on @pad and calls @foreach_func for every
5958 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5961 gst_pad_sticky_events_foreach (GstPad * pad,
5962 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5964 ForeachDispatch data;
5966 g_return_if_fail (GST_IS_PAD (pad));
5967 g_return_if_fail (foreach_func != NULL);
5969 data.func = foreach_func;
5970 data.user_data = user_data;
5972 GST_OBJECT_LOCK (pad);
5973 events_foreach (pad, foreach_dispatch_function, &data);
5974 GST_OBJECT_UNLOCK (pad);
5978 do_stream_status (GstPad * pad, GstStreamStatusType type,
5979 GThread * thread, GstTask * task)
5983 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5985 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5986 if (GST_IS_ELEMENT (parent)) {
5987 GstMessage *message;
5988 GValue value = { 0 };
5990 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5991 gchar *tname, *ename, *pname;
5993 /* create a good task name */
5994 ename = gst_element_get_name (parent);
5995 pname = gst_pad_get_name (pad);
5996 tname = g_strdup_printf ("%s:%s", ename, pname);
6000 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6004 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6007 g_value_init (&value, GST_TYPE_TASK);
6008 g_value_set_object (&value, task);
6009 gst_message_set_stream_status_object (message, &value);
6010 g_value_unset (&value);
6012 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6013 gst_element_post_message (parent, message);
6015 gst_object_unref (parent);
6020 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6022 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6027 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6029 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6034 * gst_pad_start_task:
6035 * @pad: the #GstPad to start the task of
6036 * @func: the task function to call
6037 * @user_data: user data passed to the task function
6038 * @notify: called when @user_data is no longer referenced
6040 * Starts a task that repeatedly calls @func with @user_data. This function
6041 * is mostly used in pad activation functions to start the dataflow.
6042 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6043 * before @func is called.
6045 * Returns: a %TRUE if the task could be started.
6048 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6049 GDestroyNotify notify)
6054 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6055 g_return_val_if_fail (func != NULL, FALSE);
6057 GST_DEBUG_OBJECT (pad, "start task");
6059 GST_OBJECT_LOCK (pad);
6060 task = GST_PAD_TASK (pad);
6062 task = gst_task_new (func, user_data, notify);
6063 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6064 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6065 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6066 GST_INFO_OBJECT (pad, "created task %p", task);
6067 GST_PAD_TASK (pad) = task;
6068 gst_object_ref (task);
6069 /* release lock to post the message */
6070 GST_OBJECT_UNLOCK (pad);
6072 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6074 gst_object_unref (task);
6076 GST_OBJECT_LOCK (pad);
6077 /* nobody else is supposed to have changed the pad now */
6078 if (GST_PAD_TASK (pad) != task)
6079 goto concurrent_stop;
6081 res = gst_task_set_state (task, GST_TASK_STARTED);
6082 GST_OBJECT_UNLOCK (pad);
6089 GST_OBJECT_UNLOCK (pad);
6095 * gst_pad_pause_task:
6096 * @pad: the #GstPad to pause the task of
6098 * Pause the task of @pad. This function will also wait until the
6099 * function executed by the task is finished if this function is not
6100 * called from the task function.
6102 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6106 gst_pad_pause_task (GstPad * pad)
6111 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6113 GST_DEBUG_OBJECT (pad, "pause task");
6115 GST_OBJECT_LOCK (pad);
6116 task = GST_PAD_TASK (pad);
6119 res = gst_task_set_state (task, GST_TASK_PAUSED);
6120 GST_OBJECT_UNLOCK (pad);
6122 /* wait for task function to finish, this lock is recursive so it does nothing
6123 * when the pause is called from the task itself */
6124 GST_PAD_STREAM_LOCK (pad);
6125 GST_PAD_STREAM_UNLOCK (pad);
6131 GST_DEBUG_OBJECT (pad, "pad has no task");
6132 GST_OBJECT_UNLOCK (pad);
6138 * gst_pad_get_task_state:
6139 * @pad: the #GstPad to get task state from
6141 * Get @pad task state. If no task is currently
6142 * set, #GST_TASK_STOPPED is returned.
6144 * Returns: The current state of @pad's task.
6149 gst_pad_get_task_state (GstPad * pad)
6154 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6156 GST_OBJECT_LOCK (pad);
6157 task = GST_PAD_TASK (pad);
6160 res = gst_task_get_state (task);
6161 GST_OBJECT_UNLOCK (pad);
6167 GST_DEBUG_OBJECT (pad, "pad has no task");
6168 GST_OBJECT_UNLOCK (pad);
6169 return GST_TASK_STOPPED;
6174 * gst_pad_stop_task:
6175 * @pad: the #GstPad to stop the task of
6177 * Stop the task of @pad. This function will also make sure that the
6178 * function executed by the task will effectively stop if not called
6179 * from the GstTaskFunction.
6181 * This function will deadlock if called from the GstTaskFunction of
6182 * the task. Use gst_task_pause() instead.
6184 * Regardless of whether the pad has a task, the stream lock is acquired and
6185 * released so as to ensure that streaming through this pad has finished.
6187 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6190 gst_pad_stop_task (GstPad * pad)
6195 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6197 GST_DEBUG_OBJECT (pad, "stop task");
6199 GST_OBJECT_LOCK (pad);
6200 task = GST_PAD_TASK (pad);
6203 GST_PAD_TASK (pad) = NULL;
6204 res = gst_task_set_state (task, GST_TASK_STOPPED);
6205 GST_OBJECT_UNLOCK (pad);
6207 GST_PAD_STREAM_LOCK (pad);
6208 GST_PAD_STREAM_UNLOCK (pad);
6210 if (!gst_task_join (task))
6213 gst_object_unref (task);
6219 GST_DEBUG_OBJECT (pad, "no task");
6220 GST_OBJECT_UNLOCK (pad);
6222 GST_PAD_STREAM_LOCK (pad);
6223 GST_PAD_STREAM_UNLOCK (pad);
6225 /* this is not an error */
6230 /* this is bad, possibly the application tried to join the task from
6231 * the task's thread. We install the task again so that it will be stopped
6232 * again from the right thread next time hopefully. */
6233 GST_OBJECT_LOCK (pad);
6234 GST_DEBUG_OBJECT (pad, "join failed");
6235 /* we can only install this task if there was no other task */
6236 if (GST_PAD_TASK (pad) == NULL)
6237 GST_PAD_TASK (pad) = task;
6238 GST_OBJECT_UNLOCK (pad);
6245 * gst_pad_probe_info_get_event:
6246 * @info: a #GstPadProbeInfo
6248 * Returns: (transfer none): The #GstEvent from the probe
6252 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6254 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6255 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6257 return GST_PAD_PROBE_INFO_EVENT (info);
6262 * gst_pad_probe_info_get_query:
6263 * @info: a #GstPadProbeInfo
6265 * Returns: (transfer none): The #GstQuery from the probe
6269 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6271 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6272 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6274 return GST_PAD_PROBE_INFO_QUERY (info);
6278 * gst_pad_probe_info_get_buffer:
6279 * @info: a #GstPadProbeInfo
6281 * Returns: (transfer none): The #GstBuffer from the probe
6285 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6287 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6289 return GST_PAD_PROBE_INFO_BUFFER (info);
6293 * gst_pad_probe_info_get_buffer_list:
6294 * @info: a #GstPadProbeInfo
6296 * Returns: (transfer none): The #GstBufferList from the probe
6300 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6302 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6304 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6308 * gst_pad_get_last_flow_return:
6311 * Gets the #GstFlowReturn return from the last data passed by this pad.
6316 gst_pad_get_last_flow_return (GstPad * pad)
6320 GST_OBJECT_LOCK (pad);
6321 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6322 GST_OBJECT_UNLOCK (pad);