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 _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned %TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
144 /* counter of how many idle probes are running directly from the add_probe
145 * call. Used to block any data flowing in the pad while the idle callback
146 * Doesn't finish its work */
149 /* conditional and variable used to ensure pads only get (de)activated
150 * by a single thread at a time. Protected by the object lock */
151 GCond activation_cond;
152 gboolean in_activation;
160 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
161 (((GstPad *)(p))->priv->idle_running > 0)
166 GstPadProbeInfo *info;
172 gulong *called_probes;
173 guint n_called_probes;
174 guint called_probes_size;
178 static void gst_pad_dispose (GObject * object);
179 static void gst_pad_finalize (GObject * object);
180 static void gst_pad_set_property (GObject * object, guint prop_id,
181 const GValue * value, GParamSpec * pspec);
182 static void gst_pad_get_property (GObject * object, guint prop_id,
183 GValue * value, GParamSpec * pspec);
185 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
186 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
187 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
188 GstObject * parent, GstBufferList * list);
190 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
191 GstEvent * event, GstPadProbeType type);
192 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
195 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
196 GstPadMode mode, gboolean active);
198 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
200 static GParamSpec *pspec_caps = NULL;
202 /* quarks for probe signals */
203 static GQuark buffer_quark;
204 static GQuark buffer_list_quark;
205 static GQuark event_quark;
214 static GstFlowQuarks flow_quarks[] = {
215 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
216 {GST_FLOW_OK, "ok", 0},
217 {GST_FLOW_NOT_LINKED, "not-linked", 0},
218 {GST_FLOW_FLUSHING, "flushing", 0},
219 {GST_FLOW_EOS, "eos", 0},
220 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
221 {GST_FLOW_ERROR, "error", 0},
222 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
223 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
228 * @ret: a #GstFlowReturn to get the name of.
230 * Gets a string representing the given flow return.
232 * Returns: a static string with the name of the flow return.
235 gst_flow_get_name (GstFlowReturn ret)
239 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
241 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
242 if (ret == flow_quarks[i].ret)
243 return flow_quarks[i].name;
250 * @ret: a #GstFlowReturn to get the quark of.
252 * Get the unique quark for the given GstFlowReturn.
254 * Returns: the quark associated with the flow return or 0 if an
255 * invalid return was specified.
258 gst_flow_to_quark (GstFlowReturn ret)
262 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
264 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
265 if (ret == flow_quarks[i].ret)
266 return flow_quarks[i].quark;
272 * gst_pad_link_get_name:
273 * @ret: a #GstPadLinkReturn to get the name of.
275 * Gets a string representing the given pad-link return.
277 * Returns: a static string with the name of the pad-link return.
282 gst_pad_link_get_name (GstPadLinkReturn ret)
285 case GST_PAD_LINK_OK:
287 case GST_PAD_LINK_WRONG_HIERARCHY:
288 return "wrong hierarchy";
289 case GST_PAD_LINK_WAS_LINKED:
291 case GST_PAD_LINK_WRONG_DIRECTION:
292 return "wrong direction";
293 case GST_PAD_LINK_NOFORMAT:
294 return "no common format";
295 case GST_PAD_LINK_NOSCHED:
296 return "incompatible scheduling";
297 case GST_PAD_LINK_REFUSED:
300 g_return_val_if_reached ("unknown");
307 buffer_quark = g_quark_from_static_string ("buffer"); \
308 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
309 event_quark = g_quark_from_static_string ("event"); \
311 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
312 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
315 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
316 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
319 #define gst_pad_parent_class parent_class
320 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT,
321 G_ADD_PRIVATE (GstPad) _do_init);
324 gst_pad_class_init (GstPadClass * klass)
326 GObjectClass *gobject_class;
327 GstObjectClass *gstobject_class;
329 gobject_class = G_OBJECT_CLASS (klass);
330 gstobject_class = GST_OBJECT_CLASS (klass);
332 gobject_class->dispose = gst_pad_dispose;
333 gobject_class->finalize = gst_pad_finalize;
334 gobject_class->set_property = gst_pad_set_property;
335 gobject_class->get_property = gst_pad_get_property;
339 * @pad: the pad that emitted the signal
340 * @peer: the peer pad that has been connected
342 * Signals that a pad has been linked to the peer pad.
344 gst_pad_signals[PAD_LINKED] =
345 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
346 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
347 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
350 * @pad: the pad that emitted the signal
351 * @peer: the peer pad that has been disconnected
353 * Signals that a pad has been unlinked from the peer pad.
355 gst_pad_signals[PAD_UNLINKED] =
356 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
357 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
358 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
360 pspec_caps = g_param_spec_boxed ("caps", "Caps",
361 "The capabilities of the pad", GST_TYPE_CAPS,
362 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
363 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
365 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
366 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
367 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
368 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
370 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
371 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
372 g_param_spec_object ("template", "Template",
373 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
374 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
379 * The offset that will be applied to the running time of the pad.
383 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
384 g_param_spec_int64 ("offset", "Offset",
385 "The running time offset of the pad", 0, G_MAXINT64, 0,
386 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
388 gstobject_class->path_string_separator = ".";
390 /* Register common function pointer descriptions */
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
393 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
399 gst_pad_init (GstPad * pad)
401 pad->priv = gst_pad_get_instance_private (pad);
403 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
405 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
406 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
407 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
408 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
409 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
411 GST_PAD_SET_FLUSHING (pad);
413 g_rec_mutex_init (&pad->stream_rec_lock);
415 g_cond_init (&pad->block_cond);
417 g_hook_list_init (&pad->probes, sizeof (GstProbe));
419 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
420 pad->priv->events_cookie = 0;
421 pad->priv->last_cookie = -1;
422 g_cond_init (&pad->priv->activation_cond);
424 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
427 /* called when setting the pad inactive. It removes all sticky events from
428 * the pad. must be called with object lock */
430 remove_events (GstPad * pad)
434 gboolean notify = FALSE;
436 events = pad->priv->events;
439 for (i = 0; i < len; i++) {
440 PadEvent *ev = &g_array_index (events, PadEvent, i);
441 GstEvent *event = ev->event;
445 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
448 gst_event_unref (event);
451 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
452 g_array_set_size (events, 0);
453 pad->priv->events_cookie++;
456 GST_OBJECT_UNLOCK (pad);
458 GST_DEBUG_OBJECT (pad, "notify caps");
459 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
461 GST_OBJECT_LOCK (pad);
465 /* should be called with object lock */
467 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
473 events = pad->priv->events;
476 for (i = 0; i < len; i++) {
477 ev = &g_array_index (events, PadEvent, i);
478 if (ev->event == NULL)
481 if (GST_EVENT_TYPE (ev->event) == type) {
485 } else if (GST_EVENT_TYPE (ev->event) > type) {
494 /* should be called with OBJECT lock */
496 find_event (GstPad * pad, GstEvent * event)
502 events = pad->priv->events;
505 for (i = 0; i < len; i++) {
506 ev = &g_array_index (events, PadEvent, i);
507 if (event == ev->event)
509 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
517 /* should be called with OBJECT lock */
519 remove_event_by_type (GstPad * pad, GstEventType type)
525 events = pad->priv->events;
530 ev = &g_array_index (events, PadEvent, i);
531 if (ev->event == NULL)
534 if (GST_EVENT_TYPE (ev->event) > type)
536 else if (GST_EVENT_TYPE (ev->event) != type)
539 gst_event_unref (ev->event);
540 g_array_remove_index (events, i);
542 pad->priv->events_cookie++;
550 /* check all events on srcpad against those on sinkpad. All events that are not
551 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
552 * srcpad so that the events will be sent next time */
553 /* should be called with srcpad and sinkpad LOCKS */
555 schedule_events (GstPad * srcpad, GstPad * sinkpad)
560 gboolean pending = FALSE;
562 events = srcpad->priv->events;
565 for (i = 0; i < len; i++) {
566 ev = &g_array_index (events, PadEvent, i);
567 if (ev->event == NULL)
570 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
571 ev->received = FALSE;
576 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
579 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
582 /* should be called with pad LOCK */
584 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
591 events = pad->priv->events;
594 cookie = pad->priv->events_cookie;
598 PadEvent *ev, ev_ret;
600 ev = &g_array_index (events, PadEvent, i);
601 if (G_UNLIKELY (ev->event == NULL))
604 /* take additional ref, func might release the lock */
605 ev_ret.event = gst_event_ref (ev->event);
606 ev_ret.received = ev->received;
608 ret = func (pad, &ev_ret, user_data);
610 /* recheck the cookie, lock might have been released and the list could have
612 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
613 if (G_LIKELY (ev_ret.event))
614 gst_event_unref (ev_ret.event);
618 /* store the received state */
619 ev->received = ev_ret.received;
621 /* if the event changed, we need to do something */
622 if (G_UNLIKELY (ev->event != ev_ret.event)) {
623 if (G_UNLIKELY (ev_ret.event == NULL)) {
624 /* function unreffed and set the event to NULL, remove it */
625 gst_event_unref (ev->event);
626 g_array_remove_index (events, i);
628 cookie = ++pad->priv->events_cookie;
631 /* function gave a new event for us */
632 gst_event_take (&ev->event, ev_ret.event);
635 /* just unref, nothing changed */
636 gst_event_unref (ev_ret.event);
645 /* should be called with LOCK */
647 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream,
652 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
653 GST_STIME_ARGS (pad_offset));
655 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
658 g_assert (!upstream);
660 /* copy segment values */
661 gst_event_copy_segment (event, &segment);
662 gst_event_unref (event);
664 gst_segment_offset_running_time (&segment, segment.format, pad_offset);
665 event = gst_event_new_segment (&segment);
668 event = gst_event_make_writable (event);
669 offset = gst_event_get_running_time_offset (event);
671 offset -= pad_offset;
673 offset += pad_offset;
674 gst_event_set_running_time_offset (event, offset);
679 static inline GstEvent *
680 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
682 if (G_UNLIKELY (pad->offset != 0))
683 return _apply_pad_offset (pad, event, upstream, pad->offset);
687 /* should be called with the OBJECT_LOCK */
689 get_pad_caps (GstPad * pad)
691 GstCaps *caps = NULL;
694 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
696 gst_event_parse_caps (ev->event, &caps);
702 gst_pad_dispose (GObject * object)
704 GstPad *pad = GST_PAD_CAST (object);
707 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
709 /* unlink the peer pad */
710 if ((peer = gst_pad_get_peer (pad))) {
711 /* window for MT unsafeness, someone else could unlink here
712 * and then we call unlink with wrong pads. The unlink
713 * function would catch this and safely return failed. */
714 if (GST_PAD_IS_SRC (pad))
715 gst_pad_unlink (pad, peer);
717 gst_pad_unlink (peer, pad);
719 gst_object_unref (peer);
722 gst_pad_set_pad_template (pad, NULL);
724 GST_OBJECT_LOCK (pad);
726 GST_OBJECT_UNLOCK (pad);
728 g_hook_list_clear (&pad->probes);
730 G_OBJECT_CLASS (parent_class)->dispose (object);
734 gst_pad_finalize (GObject * object)
736 GstPad *pad = GST_PAD_CAST (object);
739 /* in case the task is still around, clean it up */
740 if ((task = GST_PAD_TASK (pad))) {
741 gst_task_join (task);
742 GST_PAD_TASK (pad) = NULL;
743 gst_object_unref (task);
746 if (pad->activatenotify)
747 pad->activatenotify (pad->activatedata);
748 if (pad->activatemodenotify)
749 pad->activatemodenotify (pad->activatemodedata);
751 pad->linknotify (pad->linkdata);
752 if (pad->unlinknotify)
753 pad->unlinknotify (pad->unlinkdata);
754 if (pad->chainnotify)
755 pad->chainnotify (pad->chaindata);
756 if (pad->chainlistnotify)
757 pad->chainlistnotify (pad->chainlistdata);
758 if (pad->getrangenotify)
759 pad->getrangenotify (pad->getrangedata);
760 if (pad->eventnotify)
761 pad->eventnotify (pad->eventdata);
762 if (pad->querynotify)
763 pad->querynotify (pad->querydata);
764 if (pad->iterintlinknotify)
765 pad->iterintlinknotify (pad->iterintlinkdata);
767 g_rec_mutex_clear (&pad->stream_rec_lock);
768 g_cond_clear (&pad->block_cond);
769 g_cond_clear (&pad->priv->activation_cond);
770 g_array_free (pad->priv->events, TRUE);
772 G_OBJECT_CLASS (parent_class)->finalize (object);
776 gst_pad_set_property (GObject * object, guint prop_id,
777 const GValue * value, GParamSpec * pspec)
779 g_return_if_fail (GST_IS_PAD (object));
782 case PAD_PROP_DIRECTION:
783 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
785 case PAD_PROP_TEMPLATE:
786 gst_pad_set_pad_template (GST_PAD_CAST (object),
787 (GstPadTemplate *) g_value_get_object (value));
789 case PAD_PROP_OFFSET:
790 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
793 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
799 gst_pad_get_property (GObject * object, guint prop_id,
800 GValue * value, GParamSpec * pspec)
802 g_return_if_fail (GST_IS_PAD (object));
806 GST_OBJECT_LOCK (object);
807 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
808 GST_OBJECT_UNLOCK (object);
810 case PAD_PROP_DIRECTION:
811 g_value_set_enum (value, GST_PAD_DIRECTION (object));
813 case PAD_PROP_TEMPLATE:
814 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
816 case PAD_PROP_OFFSET:
817 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
820 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
827 * @name: (allow-none): the name of the new pad.
828 * @direction: the #GstPadDirection of the pad.
830 * Creates a new pad with the given name in the given direction.
831 * If name is %NULL, a guaranteed unique name (across all pads)
833 * This function makes a copy of the name so you can safely free the name.
835 * Returns: (transfer floating): a new #GstPad.
840 gst_pad_new (const gchar * name, GstPadDirection direction)
842 return g_object_new (GST_TYPE_PAD,
843 "name", name, "direction", direction, NULL);
847 * gst_pad_new_from_template:
848 * @templ: the pad template to use
849 * @name: (allow-none): the name of the pad
851 * Creates a new pad with the given name from the given template.
852 * If name is %NULL, a guaranteed unique name (across all pads)
854 * This function makes a copy of the name so you can safely free the name.
856 * Returns: (transfer floating): a new #GstPad.
859 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
862 GST_PAD_TEMPLATE_GTYPE (templ) ==
863 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
865 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
867 return g_object_new (pad_type,
868 "name", name, "direction", templ->direction, "template", templ, NULL);
872 * gst_pad_new_from_static_template:
873 * @templ: the #GstStaticPadTemplate to use
874 * @name: the name of the pad
876 * Creates a new pad with the given name from the given static template.
877 * If name is %NULL, a guaranteed unique name (across all pads)
879 * This function makes a copy of the name so you can safely free the name.
881 * Returns: (transfer floating): a new #GstPad.
884 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
888 GstPadTemplate *template;
890 template = gst_static_pad_template_get (templ);
891 pad = gst_pad_new_from_template (template, name);
892 gst_object_unref (template);
896 #define ACQUIRE_PARENT(pad, parent, label) \
898 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
899 gst_object_ref (parent); \
900 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
904 #define RELEASE_PARENT(parent) \
906 if (G_LIKELY (parent)) \
907 gst_object_unref (parent); \
911 * gst_pad_get_direction:
912 * @pad: a #GstPad to get the direction of.
914 * Gets the direction of the pad. The direction of the pad is
915 * decided at construction time so this function does not take
918 * Returns: the #GstPadDirection of the pad.
923 gst_pad_get_direction (GstPad * pad)
925 GstPadDirection result;
927 /* PAD_UNKNOWN is a little silly but we need some sort of
928 * error return value */
929 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
931 result = GST_PAD_DIRECTION (pad);
937 gst_pad_activate_default (GstPad * pad, GstObject * parent)
939 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
941 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
945 * gst_pad_mode_get_name:
946 * @mode: the pad mode
948 * Return the name of a pad mode, for use in debug messages mostly.
950 * Returns: short mnemonic for pad mode @mode
953 gst_pad_mode_get_name (GstPadMode mode)
956 case GST_PAD_MODE_NONE:
958 case GST_PAD_MODE_PUSH:
960 case GST_PAD_MODE_PULL:
968 /* Returns TRUE if pad wasn't already in the new_mode */
970 pre_activate (GstPad * pad, GstPadMode new_mode)
973 case GST_PAD_MODE_NONE:
974 GST_OBJECT_LOCK (pad);
975 while (G_UNLIKELY (pad->priv->in_activation))
976 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
977 if (new_mode == GST_PAD_MODE (pad)) {
978 GST_WARNING_OBJECT (pad,
979 "Pad is already in the process of being deactivated");
980 GST_OBJECT_UNLOCK (pad);
983 pad->priv->in_activation = TRUE;
984 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
985 GST_PAD_SET_FLUSHING (pad);
986 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
987 GST_PAD_MODE (pad) = new_mode;
988 /* unlock blocked pads so element can resume and stop */
989 GST_PAD_BLOCK_BROADCAST (pad);
990 GST_OBJECT_UNLOCK (pad);
992 case GST_PAD_MODE_PUSH:
993 case GST_PAD_MODE_PULL:
994 GST_OBJECT_LOCK (pad);
995 while (G_UNLIKELY (pad->priv->in_activation))
996 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
997 if (new_mode == GST_PAD_MODE (pad)) {
998 GST_WARNING_OBJECT (pad,
999 "Pad is already in the process of being activated");
1000 GST_OBJECT_UNLOCK (pad);
1003 pad->priv->in_activation = TRUE;
1004 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1005 gst_pad_mode_get_name (new_mode));
1006 GST_PAD_UNSET_FLUSHING (pad);
1007 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1008 GST_PAD_MODE (pad) = new_mode;
1009 if (GST_PAD_IS_SINK (pad)) {
1011 /* make sure the peer src pad sends us all events */
1012 if ((peer = GST_PAD_PEER (pad))) {
1013 gst_object_ref (peer);
1014 GST_OBJECT_UNLOCK (pad);
1016 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1017 GST_DEBUG_PAD_NAME (peer));
1019 GST_OBJECT_LOCK (peer);
1020 schedule_events (peer, NULL);
1021 GST_OBJECT_UNLOCK (peer);
1023 gst_object_unref (peer);
1025 GST_OBJECT_UNLOCK (pad);
1028 GST_OBJECT_UNLOCK (pad);
1036 post_activate (GstPad * pad, GstPadMode new_mode)
1039 case GST_PAD_MODE_NONE:
1040 GST_OBJECT_LOCK (pad);
1041 pad->priv->in_activation = FALSE;
1042 g_cond_broadcast (&pad->priv->activation_cond);
1043 GST_OBJECT_UNLOCK (pad);
1045 /* ensures that streaming stops */
1046 GST_PAD_STREAM_LOCK (pad);
1047 GST_DEBUG_OBJECT (pad, "stopped streaming");
1048 GST_OBJECT_LOCK (pad);
1049 remove_events (pad);
1050 GST_OBJECT_UNLOCK (pad);
1051 GST_PAD_STREAM_UNLOCK (pad);
1053 case GST_PAD_MODE_PUSH:
1054 case GST_PAD_MODE_PULL:
1055 GST_OBJECT_LOCK (pad);
1056 pad->priv->in_activation = FALSE;
1057 g_cond_broadcast (&pad->priv->activation_cond);
1058 GST_OBJECT_UNLOCK (pad);
1065 * gst_pad_set_active:
1066 * @pad: the #GstPad to activate or deactivate.
1067 * @active: whether or not the pad should be active.
1069 * Activates or deactivates the given pad.
1070 * Normally called from within core state change functions.
1072 * If @active, makes sure the pad is active. If it is already active, either in
1073 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1074 * function to perform the actual activation.
1076 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1077 * and a %FALSE argument.
1079 * Returns: %TRUE if the operation was successful.
1084 gst_pad_set_active (GstPad * pad, gboolean active)
1088 gboolean ret = FALSE;
1090 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1092 GST_OBJECT_LOCK (pad);
1093 old = GST_PAD_MODE (pad);
1094 ACQUIRE_PARENT (pad, parent, no_parent);
1095 GST_OBJECT_UNLOCK (pad);
1098 if (old == GST_PAD_MODE_NONE) {
1099 GST_DEBUG_OBJECT (pad, "activating pad from none");
1100 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1102 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1104 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1105 gst_pad_mode_get_name (old));
1109 if (old == GST_PAD_MODE_NONE) {
1110 GST_DEBUG_OBJECT (pad, "pad was inactive");
1113 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1114 gst_pad_mode_get_name (old));
1115 ret = activate_mode_internal (pad, parent, old, FALSE);
1117 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1121 RELEASE_PARENT (parent);
1123 if (G_UNLIKELY (!ret))
1131 GST_DEBUG_OBJECT (pad, "no parent");
1132 GST_OBJECT_UNLOCK (pad);
1137 GST_OBJECT_LOCK (pad);
1139 g_critical ("Failed to deactivate pad %s:%s, very bad",
1140 GST_DEBUG_PAD_NAME (pad));
1142 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1144 GST_OBJECT_UNLOCK (pad);
1150 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1153 gboolean res = FALSE;
1154 GstPadMode old, new;
1155 GstPadDirection dir;
1158 GST_OBJECT_LOCK (pad);
1159 old = GST_PAD_MODE (pad);
1160 dir = GST_PAD_DIRECTION (pad);
1161 GST_OBJECT_UNLOCK (pad);
1163 new = active ? mode : GST_PAD_MODE_NONE;
1168 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1169 /* pad was activate in the wrong direction, deactivate it
1170 * and reactivate it in the requested mode */
1171 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1172 gst_pad_mode_get_name (old));
1174 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1175 goto deactivate_failed;
1176 old = GST_PAD_MODE_NONE;
1180 case GST_PAD_MODE_PULL:
1182 if (dir == GST_PAD_SINK) {
1183 if ((peer = gst_pad_get_peer (pad))) {
1184 GST_DEBUG_OBJECT (pad, "calling peer");
1185 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1187 gst_object_unref (peer);
1189 /* there is no peer, this is only fatal when we activate. When we
1190 * deactivate, we must assume the application has unlinked the peer and
1191 * will deactivate it eventually. */
1195 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1198 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1199 goto failure; /* Can't activate pull on a src without a
1200 getrange function */
1208 /* Mark pad as needing reconfiguration */
1210 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1212 /* pre_activate returns TRUE if we weren't already in the process of
1213 * switching to the 'new' mode */
1214 if (pre_activate (pad, new)) {
1216 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1217 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1221 /* can happen for sinks of passthrough elements */
1224 post_activate (pad, new);
1227 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1228 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1233 /* Clear sticky flags on deactivation */
1235 GST_OBJECT_LOCK (pad);
1236 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1237 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1238 GST_OBJECT_UNLOCK (pad);
1246 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1247 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1252 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1253 "failed to %s in switch to %s mode from %s mode",
1254 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1255 gst_pad_mode_get_name (old));
1260 GST_OBJECT_LOCK (peer);
1261 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1262 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1263 GST_OBJECT_UNLOCK (peer);
1264 gst_object_unref (peer);
1269 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1270 "pad in pull mode");
1275 GST_OBJECT_LOCK (pad);
1276 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1277 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1278 GST_PAD_SET_FLUSHING (pad);
1279 GST_PAD_MODE (pad) = old;
1280 pad->priv->in_activation = FALSE;
1281 g_cond_broadcast (&pad->priv->activation_cond);
1282 GST_OBJECT_UNLOCK (pad);
1288 * gst_pad_activate_mode:
1289 * @pad: the #GstPad to activate or deactivate.
1290 * @mode: the requested activation mode
1291 * @active: whether or not the pad should be active.
1293 * Activates or deactivates the given pad in @mode via dispatching to the
1294 * pad's activatemodefunc. For use from within pad activation functions only.
1296 * If you don't know what this is, you probably don't want to call it.
1298 * Returns: %TRUE if the operation was successful.
1303 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1307 GstPadMode old, new;
1309 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1311 GST_OBJECT_LOCK (pad);
1313 old = GST_PAD_MODE (pad);
1314 new = active ? mode : GST_PAD_MODE_NONE;
1318 ACQUIRE_PARENT (pad, parent, no_parent);
1320 GST_OBJECT_UNLOCK (pad);
1322 res = activate_mode_internal (pad, parent, mode, active);
1324 RELEASE_PARENT (parent);
1330 GST_OBJECT_UNLOCK (pad);
1331 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1332 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1337 GST_WARNING_OBJECT (pad, "no parent");
1338 GST_OBJECT_UNLOCK (pad);
1344 * gst_pad_is_active:
1345 * @pad: the #GstPad to query
1347 * Query if a pad is active
1349 * Returns: %TRUE if the pad is active.
1354 gst_pad_is_active (GstPad * pad)
1356 gboolean result = FALSE;
1358 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1360 GST_OBJECT_LOCK (pad);
1361 result = GST_PAD_IS_ACTIVE (pad);
1362 GST_OBJECT_UNLOCK (pad);
1368 cleanup_hook (GstPad * pad, GHook * hook)
1370 GstPadProbeType type;
1372 GST_DEBUG_OBJECT (pad,
1373 "cleaning up hook %lu with flags %08x", hook->hook_id, hook->flags);
1375 if (!G_HOOK_IS_VALID (hook))
1378 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1380 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1381 /* unblock when we remove the last blocking probe */
1383 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1386 /* Might have new probes now that want to be called */
1387 GST_PAD_BLOCK_BROADCAST (pad);
1389 if (pad->num_blocked == 0) {
1390 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1391 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1394 g_hook_destroy_link (&pad->probes, hook);
1399 * gst_pad_add_probe:
1400 * @pad: the #GstPad to add the probe to
1401 * @mask: the probe mask
1402 * @callback: #GstPadProbeCallback that will be called with notifications of
1404 * @user_data: (closure): user data passed to the callback
1405 * @destroy_data: #GDestroyNotify for user_data
1407 * Be notified of different states of pads. The provided callback is called for
1408 * every state that matches @mask.
1410 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1411 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1412 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1413 * immediately if the pad is already idle while calling gst_pad_add_probe().
1414 * In each of the groups, probes are called in the order in which they were
1417 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1418 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1419 * happen that the probe can be run immediately and if the probe returns
1420 * GST_PAD_PROBE_REMOVE this functions returns 0.
1425 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1426 GstPadProbeCallback callback, gpointer user_data,
1427 GDestroyNotify destroy_data)
1432 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1433 g_return_val_if_fail (mask != 0, 0);
1435 GST_OBJECT_LOCK (pad);
1437 /* make a new probe */
1438 hook = g_hook_alloc (&pad->probes);
1440 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1443 /* when no constraints are given for the types, assume all types are
1445 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1446 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1447 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1448 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1450 /* store our flags and other fields */
1451 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1452 hook->func = callback;
1453 hook->data = user_data;
1454 hook->destroy = destroy_data;
1457 g_hook_append (&pad->probes, hook);
1459 /* incremenent cookie so that the new hook gets called */
1460 pad->priv->probe_list_cookie++;
1462 /* get the id of the hook, we return this and it can be used to remove the
1464 res = hook->hook_id;
1466 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1468 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1469 /* we have a block probe */
1471 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1473 "now %d blocking probes", pad->num_blocked);
1475 /* Might have new probes now that want to be called */
1476 GST_PAD_BLOCK_BROADCAST (pad);
1479 /* call the callback if we need to be called for idle callbacks */
1480 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1481 if (pad->priv->using > 0) {
1482 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1483 * flag above, the last thread to leave the push will do the callback. New
1484 * threads going into the push will block. */
1485 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1486 "pad is in use, delay idle callback");
1487 GST_OBJECT_UNLOCK (pad);
1489 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1490 GstPadProbeReturn ret;
1492 /* Keep another ref, the callback could destroy the pad */
1493 gst_object_ref (pad);
1494 pad->priv->idle_running++;
1496 /* the pad is idle now, we can signal the idle callback now */
1497 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1498 "pad is idle, trigger idle callback");
1499 GST_OBJECT_UNLOCK (pad);
1501 ret = callback (pad, &info, user_data);
1503 GST_OBJECT_LOCK (pad);
1505 case GST_PAD_PROBE_REMOVE:
1506 /* remove the probe */
1507 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1508 cleanup_hook (pad, hook);
1511 case GST_PAD_PROBE_DROP:
1512 GST_DEBUG_OBJECT (pad, "asked to drop item");
1514 case GST_PAD_PROBE_PASS:
1515 GST_DEBUG_OBJECT (pad, "asked to pass item");
1517 case GST_PAD_PROBE_OK:
1518 GST_DEBUG_OBJECT (pad, "probe returned OK");
1520 case GST_PAD_PROBE_HANDLED:
1521 GST_DEBUG_OBJECT (pad, "probe handled the data");
1524 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1527 pad->priv->idle_running--;
1528 if (pad->priv->idle_running == 0) {
1529 GST_PAD_BLOCK_BROADCAST (pad);
1531 GST_OBJECT_UNLOCK (pad);
1533 gst_object_unref (pad);
1536 GST_OBJECT_UNLOCK (pad);
1542 * gst_pad_remove_probe:
1543 * @pad: the #GstPad with the probe
1544 * @id: the probe id to remove
1546 * Remove the probe with @id from @pad.
1551 gst_pad_remove_probe (GstPad * pad, gulong id)
1555 g_return_if_fail (GST_IS_PAD (pad));
1557 GST_OBJECT_LOCK (pad);
1559 hook = g_hook_get (&pad->probes, id);
1563 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1565 cleanup_hook (pad, hook);
1566 GST_OBJECT_UNLOCK (pad);
1572 GST_OBJECT_UNLOCK (pad);
1573 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1579 * gst_pad_is_blocked:
1580 * @pad: the #GstPad to query
1582 * Checks if the pad is blocked or not. This function returns the
1583 * last requested state of the pad. It is not certain that the pad
1584 * is actually blocking at this point (see gst_pad_is_blocking()).
1586 * Returns: %TRUE if the pad is blocked.
1591 gst_pad_is_blocked (GstPad * pad)
1593 gboolean result = FALSE;
1595 g_return_val_if_fail (GST_IS_PAD (pad), result);
1597 GST_OBJECT_LOCK (pad);
1598 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1599 GST_OBJECT_UNLOCK (pad);
1605 * gst_pad_is_blocking:
1606 * @pad: the #GstPad to query
1608 * Checks if the pad is blocking or not. This is a guaranteed state
1609 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1611 * Returns: %TRUE if the pad is blocking.
1616 gst_pad_is_blocking (GstPad * pad)
1618 gboolean result = FALSE;
1620 g_return_val_if_fail (GST_IS_PAD (pad), result);
1622 GST_OBJECT_LOCK (pad);
1623 /* the blocking flag is only valid if the pad is not flushing */
1624 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1625 GST_OBJECT_UNLOCK (pad);
1631 * gst_pad_needs_reconfigure:
1632 * @pad: the #GstPad to check
1634 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1635 * if the flag was set.
1637 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1640 gst_pad_needs_reconfigure (GstPad * pad)
1642 gboolean reconfigure;
1644 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1646 GST_OBJECT_LOCK (pad);
1647 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1648 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1649 GST_OBJECT_UNLOCK (pad);
1655 * gst_pad_check_reconfigure:
1656 * @pad: the #GstPad to check
1658 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1659 * if the flag was set.
1661 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1664 gst_pad_check_reconfigure (GstPad * pad)
1666 gboolean reconfigure;
1668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1670 GST_OBJECT_LOCK (pad);
1671 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1673 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1674 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1676 GST_OBJECT_UNLOCK (pad);
1682 * gst_pad_mark_reconfigure:
1683 * @pad: the #GstPad to mark
1685 * Mark a pad for needing reconfiguration. The next call to
1686 * gst_pad_check_reconfigure() will return %TRUE after this call.
1689 gst_pad_mark_reconfigure (GstPad * pad)
1691 g_return_if_fail (GST_IS_PAD (pad));
1693 GST_OBJECT_LOCK (pad);
1694 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1695 GST_OBJECT_UNLOCK (pad);
1699 * gst_pad_set_activate_function:
1701 * @f: the #GstPadActivateFunction to set.
1703 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1707 * gst_pad_set_activate_function_full:
1709 * @activate: the #GstPadActivateFunction to set.
1710 * @user_data: user_data passed to @notify
1711 * @notify: notify called when @activate will not be used anymore.
1713 * Sets the given activate function for @pad. The activate function will
1714 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1715 * Only makes sense to set on sink pads.
1717 * Call this function if your sink pad can start a pull-based task.
1720 gst_pad_set_activate_function_full (GstPad * pad,
1721 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1723 g_return_if_fail (GST_IS_PAD (pad));
1725 if (pad->activatenotify)
1726 pad->activatenotify (pad->activatedata);
1727 GST_PAD_ACTIVATEFUNC (pad) = activate;
1728 pad->activatedata = user_data;
1729 pad->activatenotify = notify;
1731 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1732 GST_DEBUG_FUNCPTR_NAME (activate));
1736 * gst_pad_set_activatemode_function:
1738 * @f: the #GstPadActivateModeFunction to set.
1740 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1744 * gst_pad_set_activatemode_function_full:
1746 * @activatemode: the #GstPadActivateModeFunction to set.
1747 * @user_data: user_data passed to @notify
1748 * @notify: notify called when @activatemode will not be used anymore.
1750 * Sets the given activate_mode function for the pad. An activate_mode function
1751 * prepares the element for data passing.
1754 gst_pad_set_activatemode_function_full (GstPad * pad,
1755 GstPadActivateModeFunction activatemode, gpointer user_data,
1756 GDestroyNotify notify)
1758 g_return_if_fail (GST_IS_PAD (pad));
1760 if (pad->activatemodenotify)
1761 pad->activatemodenotify (pad->activatemodedata);
1762 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1763 pad->activatemodedata = user_data;
1764 pad->activatemodenotify = notify;
1766 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1767 GST_DEBUG_FUNCPTR_NAME (activatemode));
1771 * gst_pad_set_chain_function:
1772 * @p: a sink #GstPad.
1773 * @f: the #GstPadChainFunction to set.
1775 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1779 * gst_pad_set_chain_function_full:
1780 * @pad: a sink #GstPad.
1781 * @chain: the #GstPadChainFunction to set.
1782 * @user_data: user_data passed to @notify
1783 * @notify: notify called when @chain will not be used anymore.
1785 * Sets the given chain function for the pad. The chain function is called to
1786 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1789 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1790 gpointer user_data, GDestroyNotify notify)
1792 g_return_if_fail (GST_IS_PAD (pad));
1793 g_return_if_fail (GST_PAD_IS_SINK (pad));
1795 if (pad->chainnotify)
1796 pad->chainnotify (pad->chaindata);
1797 GST_PAD_CHAINFUNC (pad) = chain;
1798 pad->chaindata = user_data;
1799 pad->chainnotify = notify;
1801 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1802 GST_DEBUG_FUNCPTR_NAME (chain));
1806 * gst_pad_set_chain_list_function:
1807 * @p: a sink #GstPad.
1808 * @f: the #GstPadChainListFunction to set.
1810 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1814 * gst_pad_set_chain_list_function_full:
1815 * @pad: a sink #GstPad.
1816 * @chainlist: the #GstPadChainListFunction to set.
1817 * @user_data: user_data passed to @notify
1818 * @notify: notify called when @chainlist will not be used anymore.
1820 * Sets the given chain list function for the pad. The chainlist function is
1821 * called to process a #GstBufferList input buffer list. See
1822 * #GstPadChainListFunction for more details.
1825 gst_pad_set_chain_list_function_full (GstPad * pad,
1826 GstPadChainListFunction chainlist, gpointer user_data,
1827 GDestroyNotify notify)
1829 g_return_if_fail (GST_IS_PAD (pad));
1830 g_return_if_fail (GST_PAD_IS_SINK (pad));
1832 if (pad->chainlistnotify)
1833 pad->chainlistnotify (pad->chainlistdata);
1834 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1835 pad->chainlistdata = user_data;
1836 pad->chainlistnotify = notify;
1838 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1839 GST_DEBUG_FUNCPTR_NAME (chainlist));
1843 * gst_pad_set_getrange_function:
1844 * @p: a source #GstPad.
1845 * @f: the #GstPadGetRangeFunction to set.
1847 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1851 * gst_pad_set_getrange_function_full:
1852 * @pad: a source #GstPad.
1853 * @get: the #GstPadGetRangeFunction to set.
1854 * @user_data: user_data passed to @notify
1855 * @notify: notify called when @get will not be used anymore.
1857 * Sets the given getrange function for the pad. The getrange function is
1858 * called to produce a new #GstBuffer to start the processing pipeline. see
1859 * #GstPadGetRangeFunction for a description of the getrange function.
1862 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1863 gpointer user_data, GDestroyNotify notify)
1865 g_return_if_fail (GST_IS_PAD (pad));
1866 g_return_if_fail (GST_PAD_IS_SRC (pad));
1868 if (pad->getrangenotify)
1869 pad->getrangenotify (pad->getrangedata);
1870 GST_PAD_GETRANGEFUNC (pad) = get;
1871 pad->getrangedata = user_data;
1872 pad->getrangenotify = notify;
1874 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1875 GST_DEBUG_FUNCPTR_NAME (get));
1879 * gst_pad_set_event_function:
1880 * @p: a #GstPad of either direction.
1881 * @f: the #GstPadEventFunction to set.
1883 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1887 * gst_pad_set_event_function_full:
1888 * @pad: a #GstPad of either direction.
1889 * @event: the #GstPadEventFunction to set.
1890 * @user_data: user_data passed to @notify
1891 * @notify: notify called when @event will not be used anymore.
1893 * Sets the given event handler for the pad.
1896 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1897 gpointer user_data, GDestroyNotify notify)
1899 g_return_if_fail (GST_IS_PAD (pad));
1901 if (pad->eventnotify)
1902 pad->eventnotify (pad->eventdata);
1903 GST_PAD_EVENTFUNC (pad) = event;
1904 pad->eventdata = user_data;
1905 pad->eventnotify = notify;
1907 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1908 GST_DEBUG_FUNCPTR_NAME (event));
1912 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1916 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1917 if (ret == GST_FLOW_OK)
1923 * gst_pad_set_event_full_function:
1924 * @p: a #GstPad of either direction.
1925 * @f: the #GstPadEventFullFunction to set.
1927 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1931 * gst_pad_set_event_full_function_full:
1932 * @pad: a #GstPad of either direction.
1933 * @event: the #GstPadEventFullFunction to set.
1934 * @user_data: user_data passed to @notify
1935 * @notify: notify called when @event will not be used anymore.
1937 * Sets the given event handler for the pad.
1942 gst_pad_set_event_full_function_full (GstPad * pad,
1943 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1945 g_return_if_fail (GST_IS_PAD (pad));
1947 if (pad->eventnotify)
1948 pad->eventnotify (pad->eventdata);
1949 GST_PAD_EVENTFULLFUNC (pad) = event;
1950 GST_PAD_EVENTFUNC (pad) = event_wrap;
1951 pad->eventdata = user_data;
1952 pad->eventnotify = notify;
1954 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1955 GST_DEBUG_FUNCPTR_NAME (event));
1959 * gst_pad_set_query_function:
1960 * @p: a #GstPad of either direction.
1961 * @f: the #GstPadQueryFunction to set.
1963 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1967 * gst_pad_set_query_function_full:
1968 * @pad: a #GstPad of either direction.
1969 * @query: the #GstPadQueryFunction to set.
1970 * @user_data: user_data passed to @notify
1971 * @notify: notify called when @query will not be used anymore.
1973 * Set the given query function for the pad.
1976 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1977 gpointer user_data, GDestroyNotify notify)
1979 g_return_if_fail (GST_IS_PAD (pad));
1981 if (pad->querynotify)
1982 pad->querynotify (pad->querydata);
1983 GST_PAD_QUERYFUNC (pad) = query;
1984 pad->querydata = user_data;
1985 pad->querynotify = notify;
1987 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1988 GST_DEBUG_FUNCPTR_NAME (query));
1992 * gst_pad_set_iterate_internal_links_function:
1993 * @p: a #GstPad of either direction.
1994 * @f: the #GstPadIterIntLinkFunction to set.
1996 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1997 * for the user_data and notify.
2000 * gst_pad_set_iterate_internal_links_function_full:
2001 * @pad: a #GstPad of either direction.
2002 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2003 * @user_data: user_data passed to @notify
2004 * @notify: notify called when @iterintlink will not be used anymore.
2006 * Sets the given internal link iterator function for the pad.
2009 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2010 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2011 GDestroyNotify notify)
2013 g_return_if_fail (GST_IS_PAD (pad));
2015 if (pad->iterintlinknotify)
2016 pad->iterintlinknotify (pad->iterintlinkdata);
2017 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2018 pad->iterintlinkdata = user_data;
2019 pad->iterintlinknotify = notify;
2021 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2022 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2026 * gst_pad_set_link_function:
2028 * @f: the #GstPadLinkFunction to set.
2030 * Calls gst_pad_set_link_function_full() with %NULL
2031 * for the user_data and notify.
2034 * gst_pad_set_link_function_full:
2036 * @link: the #GstPadLinkFunction to set.
2037 * @user_data: user_data passed to @notify
2038 * @notify: notify called when @link will not be used anymore.
2040 * Sets the given link function for the pad. It will be called when
2041 * the pad is linked with another pad.
2043 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2046 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2047 * cannot be made for some reason.
2049 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2050 * of the peer sink pad, if present.
2053 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2054 gpointer user_data, GDestroyNotify notify)
2056 g_return_if_fail (GST_IS_PAD (pad));
2058 if (pad->linknotify)
2059 pad->linknotify (pad->linkdata);
2060 GST_PAD_LINKFUNC (pad) = link;
2061 pad->linkdata = user_data;
2062 pad->linknotify = notify;
2064 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2065 GST_DEBUG_FUNCPTR_NAME (link));
2069 * gst_pad_set_unlink_function:
2071 * @f: the #GstPadUnlinkFunction to set.
2073 * Calls gst_pad_set_unlink_function_full() with %NULL
2074 * for the user_data and notify.
2077 * gst_pad_set_unlink_function_full:
2079 * @unlink: the #GstPadUnlinkFunction to set.
2080 * @user_data: user_data passed to @notify
2081 * @notify: notify called when @unlink will not be used anymore.
2083 * Sets the given unlink function for the pad. It will be called
2084 * when the pad is unlinked.
2086 * Note that the pad's lock is already held when the unlink
2087 * function is called, so most pad functions cannot be called
2088 * from within the callback.
2091 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2092 gpointer user_data, GDestroyNotify notify)
2094 g_return_if_fail (GST_IS_PAD (pad));
2096 if (pad->unlinknotify)
2097 pad->unlinknotify (pad->unlinkdata);
2098 GST_PAD_UNLINKFUNC (pad) = unlink;
2099 pad->unlinkdata = user_data;
2100 pad->unlinknotify = notify;
2102 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2103 GST_DEBUG_FUNCPTR_NAME (unlink));
2108 * @srcpad: the source #GstPad to unlink.
2109 * @sinkpad: the sink #GstPad to unlink.
2111 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2112 * signal on both pads.
2114 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2115 * the pads were not linked together.
2120 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2122 gboolean result = FALSE;
2123 GstElement *parent = NULL;
2125 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2126 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2127 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2128 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2130 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2132 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2133 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2134 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2136 /* We need to notify the parent before taking any pad locks as the bin in
2137 * question might be waiting for a lock on the pad while holding its lock
2138 * that our message will try to take. */
2139 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2140 if (GST_IS_ELEMENT (parent)) {
2141 gst_element_post_message (parent,
2142 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2143 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2145 gst_object_unref (parent);
2150 GST_OBJECT_LOCK (srcpad);
2151 GST_OBJECT_LOCK (sinkpad);
2153 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2154 goto not_linked_together;
2156 if (GST_PAD_UNLINKFUNC (srcpad)) {
2157 GstObject *tmpparent;
2159 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2161 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2162 RELEASE_PARENT (tmpparent);
2165 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2166 GstObject *tmpparent;
2168 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2170 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2171 RELEASE_PARENT (tmpparent);
2175 /* first clear peers */
2176 GST_PAD_PEER (srcpad) = NULL;
2177 GST_PAD_PEER (sinkpad) = NULL;
2179 GST_OBJECT_UNLOCK (sinkpad);
2180 GST_OBJECT_UNLOCK (srcpad);
2182 /* fire off a signal to each of the pads telling them
2183 * that they've been unlinked */
2184 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2185 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2187 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2188 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2193 if (parent != NULL) {
2194 gst_element_post_message (parent,
2195 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2196 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2197 gst_object_unref (parent);
2199 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2203 not_linked_together:
2205 /* we do not emit a warning in this case because unlinking cannot
2206 * be made MT safe.*/
2207 GST_OBJECT_UNLOCK (sinkpad);
2208 GST_OBJECT_UNLOCK (srcpad);
2214 * gst_pad_is_linked:
2215 * @pad: pad to check
2217 * Checks if a @pad is linked to another pad or not.
2219 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2224 gst_pad_is_linked (GstPad * pad)
2228 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2230 GST_OBJECT_LOCK (pad);
2231 result = (GST_PAD_PEER (pad) != NULL);
2232 GST_OBJECT_UNLOCK (pad);
2237 /* get the caps from both pads and see if the intersection
2240 * This function should be called with the pad LOCK on both
2244 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2245 GstPadLinkCheck flags)
2247 GstCaps *srccaps = NULL;
2248 GstCaps *sinkcaps = NULL;
2249 gboolean compatible = FALSE;
2251 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2254 /* Doing the expensive caps checking takes priority over only checking the template caps */
2255 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2256 GST_OBJECT_UNLOCK (sink);
2257 GST_OBJECT_UNLOCK (src);
2259 srccaps = gst_pad_query_caps (src, NULL);
2260 sinkcaps = gst_pad_query_caps (sink, NULL);
2262 GST_OBJECT_LOCK (src);
2263 GST_OBJECT_LOCK (sink);
2265 /* If one of the two pads doesn't have a template, consider the intersection
2267 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2268 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2272 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2274 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2277 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2279 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2282 /* if we have caps on both pads we can check the intersection. If one
2283 * of the caps is %NULL, we return %TRUE. */
2284 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2286 gst_caps_unref (srccaps);
2288 gst_caps_unref (sinkcaps);
2292 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2293 gst_caps_unref (srccaps);
2294 gst_caps_unref (sinkcaps);
2297 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2298 (compatible ? "" : "not "));
2303 /* check if the grandparents of both pads are the same.
2304 * This check is required so that we don't try to link
2305 * pads from elements in different bins without ghostpads.
2307 * The LOCK should be held on both pads
2310 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2312 GstObject *psrc, *psink;
2314 psrc = GST_OBJECT_PARENT (src);
2315 psink = GST_OBJECT_PARENT (sink);
2317 /* if one of the pads has no parent, we allow the link */
2318 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2321 /* only care about parents that are elements */
2322 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2323 goto no_element_parent;
2325 /* if the parents are the same, we have a loop */
2326 if (G_UNLIKELY (psrc == psink))
2329 /* if they both have a parent, we check the grandparents. We can not lock
2330 * the parent because we hold on the child (pad) and the locking order is
2331 * parent >> child. */
2332 psrc = GST_OBJECT_PARENT (psrc);
2333 psink = GST_OBJECT_PARENT (psink);
2335 /* if they have grandparents but they are not the same */
2336 if (G_UNLIKELY (psrc != psink))
2337 goto wrong_grandparents;
2344 GST_CAT_DEBUG (GST_CAT_CAPS,
2345 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2346 GST_PTR_FORMAT, psrc, psink);
2351 GST_CAT_DEBUG (GST_CAT_CAPS,
2352 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2353 GST_PTR_FORMAT, psrc, psink);
2358 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2364 GST_CAT_DEBUG (GST_CAT_CAPS,
2365 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2366 GST_PTR_FORMAT, psrc, psink);
2371 /* FIXME leftover from an attempt at refactoring... */
2372 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2373 * the two pads will be locked in the srcpad, sinkpad order. */
2374 static GstPadLinkReturn
2375 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2377 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2378 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2380 GST_OBJECT_LOCK (srcpad);
2382 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2383 goto src_was_linked;
2385 GST_OBJECT_LOCK (sinkpad);
2387 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2388 goto sink_was_linked;
2390 /* check hierarchy, pads can only be linked if the grandparents
2392 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2393 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2394 goto wrong_hierarchy;
2396 /* check pad caps for non-empty intersection */
2397 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2400 /* FIXME check pad scheduling for non-empty intersection */
2402 return GST_PAD_LINK_OK;
2406 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2407 GST_DEBUG_PAD_NAME (srcpad),
2408 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2409 /* we do not emit a warning in this case because unlinking cannot
2410 * be made MT safe.*/
2411 GST_OBJECT_UNLOCK (srcpad);
2412 return GST_PAD_LINK_WAS_LINKED;
2416 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2417 GST_DEBUG_PAD_NAME (sinkpad),
2418 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2419 /* we do not emit a warning in this case because unlinking cannot
2420 * be made MT safe.*/
2421 GST_OBJECT_UNLOCK (sinkpad);
2422 GST_OBJECT_UNLOCK (srcpad);
2423 return GST_PAD_LINK_WAS_LINKED;
2427 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2428 GST_OBJECT_UNLOCK (sinkpad);
2429 GST_OBJECT_UNLOCK (srcpad);
2430 return GST_PAD_LINK_WRONG_HIERARCHY;
2434 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2435 GST_OBJECT_UNLOCK (sinkpad);
2436 GST_OBJECT_UNLOCK (srcpad);
2437 return GST_PAD_LINK_NOFORMAT;
2443 * @srcpad: the source #GstPad.
2444 * @sinkpad: the sink #GstPad.
2446 * Checks if the source pad and the sink pad are compatible so they can be
2449 * Returns: %TRUE if the pads can be linked.
2452 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2454 GstPadLinkReturn result;
2456 /* generic checks */
2457 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2458 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2460 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2461 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2463 /* gst_pad_link_prepare does everything for us, we only release the locks
2464 * on the pads that it gets us. If this function returns !OK the locks are not
2466 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2467 if (result != GST_PAD_LINK_OK)
2470 GST_OBJECT_UNLOCK (srcpad);
2471 GST_OBJECT_UNLOCK (sinkpad);
2474 return result == GST_PAD_LINK_OK;
2478 * gst_pad_link_full:
2479 * @srcpad: the source #GstPad to link.
2480 * @sinkpad: the sink #GstPad to link.
2481 * @flags: the checks to validate when linking
2483 * Links the source pad and the sink pad.
2485 * This variant of #gst_pad_link provides a more granular control on the
2486 * checks being done when linking. While providing some considerable speedups
2487 * the caller of this method must be aware that wrong usage of those flags
2488 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2489 * for more information.
2493 * Returns: A result code indicating if the connection worked or
2497 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2499 GstPadLinkReturn result;
2501 GstPadLinkFunction srcfunc, sinkfunc;
2503 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2504 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2505 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2506 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2507 GST_PAD_LINK_WRONG_DIRECTION);
2509 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2511 /* Notify the parent early. See gst_pad_unlink for details. */
2512 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2513 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2514 gst_element_post_message (parent,
2515 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2516 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2518 gst_object_unref (parent);
2523 /* prepare will also lock the two pads */
2524 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2526 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2527 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2528 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2529 gst_pad_link_get_name (result));
2533 /* must set peers before calling the link function */
2534 GST_PAD_PEER (srcpad) = sinkpad;
2535 GST_PAD_PEER (sinkpad) = srcpad;
2537 /* check events, when something is different, mark pending */
2538 schedule_events (srcpad, sinkpad);
2540 /* get the link functions */
2541 srcfunc = GST_PAD_LINKFUNC (srcpad);
2542 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2544 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2545 /* custom link functions, execute them */
2546 GST_OBJECT_UNLOCK (sinkpad);
2547 GST_OBJECT_UNLOCK (srcpad);
2550 GstObject *tmpparent;
2552 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2553 /* this one will call the peer link function */
2554 result = srcfunc (srcpad, tmpparent, sinkpad);
2555 RELEASE_PARENT (tmpparent);
2556 } else if (sinkfunc) {
2557 GstObject *tmpparent;
2559 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2560 /* if no source link function, we need to call the sink link
2561 * function ourselves. */
2562 result = sinkfunc (sinkpad, tmpparent, srcpad);
2563 RELEASE_PARENT (tmpparent);
2567 GST_OBJECT_LOCK (srcpad);
2568 GST_OBJECT_LOCK (sinkpad);
2570 /* we released the lock, check if the same pads are linked still */
2571 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2572 goto concurrent_link;
2574 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2577 GST_OBJECT_UNLOCK (sinkpad);
2578 GST_OBJECT_UNLOCK (srcpad);
2580 /* fire off a signal to each of the pads telling them
2581 * that they've been linked */
2582 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2583 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2585 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2586 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2588 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2589 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2592 if (G_LIKELY (parent)) {
2593 gst_element_post_message (parent,
2594 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2595 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2596 gst_object_unref (parent);
2599 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2605 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2606 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2607 GST_OBJECT_UNLOCK (sinkpad);
2608 GST_OBJECT_UNLOCK (srcpad);
2610 /* The other link operation succeeded first */
2611 result = GST_PAD_LINK_WAS_LINKED;
2616 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2617 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2618 gst_pad_link_get_name (result));
2620 GST_PAD_PEER (srcpad) = NULL;
2621 GST_PAD_PEER (sinkpad) = NULL;
2623 GST_OBJECT_UNLOCK (sinkpad);
2624 GST_OBJECT_UNLOCK (srcpad);
2632 * @srcpad: the source #GstPad to link.
2633 * @sinkpad: the sink #GstPad to link.
2635 * Links the source pad and the sink pad.
2637 * Returns: A result code indicating if the connection worked or
2643 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2645 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2649 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2651 GstPadTemplate **template_p;
2653 /* this function would need checks if it weren't static */
2655 GST_OBJECT_LOCK (pad);
2656 template_p = &pad->padtemplate;
2657 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2658 GST_OBJECT_UNLOCK (pad);
2661 gst_pad_template_pad_created (templ, pad);
2665 * gst_pad_get_pad_template:
2668 * Gets the template for @pad.
2670 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2671 * this pad was instantiated, or %NULL if this pad has no
2672 * template. Unref after usage.
2675 gst_pad_get_pad_template (GstPad * pad)
2677 GstPadTemplate *templ;
2679 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2681 templ = GST_PAD_PAD_TEMPLATE (pad);
2683 return (templ ? gst_object_ref (templ) : NULL);
2687 * gst_pad_has_current_caps:
2688 * @pad: a #GstPad to check
2690 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2692 * Returns: %TRUE when @pad has caps associated with it.
2695 gst_pad_has_current_caps (GstPad * pad)
2700 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2702 GST_OBJECT_LOCK (pad);
2703 caps = get_pad_caps (pad);
2704 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2705 "check current pad caps %" GST_PTR_FORMAT, caps);
2706 result = (caps != NULL);
2707 GST_OBJECT_UNLOCK (pad);
2713 * gst_pad_get_current_caps:
2714 * @pad: a #GstPad to get the current capabilities of.
2716 * Gets the capabilities currently configured on @pad with the last
2717 * #GST_EVENT_CAPS event.
2719 * Returns: (transfer full) (nullable): the current caps of the pad with
2720 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2723 gst_pad_get_current_caps (GstPad * pad)
2727 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2729 GST_OBJECT_LOCK (pad);
2730 if ((result = get_pad_caps (pad)))
2731 gst_caps_ref (result);
2732 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2733 "get current pad caps %" GST_PTR_FORMAT, result);
2734 GST_OBJECT_UNLOCK (pad);
2740 * gst_pad_get_pad_template_caps:
2741 * @pad: a #GstPad to get the template capabilities from.
2743 * Gets the capabilities for @pad's template.
2745 * Returns: (transfer full): the #GstCaps of this pad template.
2746 * Unref after usage.
2749 gst_pad_get_pad_template_caps (GstPad * pad)
2751 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2753 if (GST_PAD_PAD_TEMPLATE (pad))
2754 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2756 return gst_caps_ref (GST_CAPS_ANY);
2761 * @pad: a #GstPad to get the peer of.
2763 * Gets the peer of @pad. This function refs the peer pad so
2764 * you need to unref it after use.
2766 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2771 gst_pad_get_peer (GstPad * pad)
2775 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2777 GST_OBJECT_LOCK (pad);
2778 result = GST_PAD_PEER (pad);
2780 gst_object_ref (result);
2781 GST_OBJECT_UNLOCK (pad);
2787 * gst_pad_get_allowed_caps:
2790 * Gets the capabilities of the allowed media types that can flow through
2791 * @pad and its peer.
2793 * The allowed capabilities is calculated as the intersection of the results of
2794 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2795 * on the resulting caps.
2797 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2798 * pad link. Unref the caps when you no longer need it. This
2799 * function returns %NULL when @pad has no peer.
2804 gst_pad_get_allowed_caps (GstPad * pad)
2807 GstCaps *caps = NULL;
2810 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2812 GST_OBJECT_LOCK (pad);
2813 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2815 GST_OBJECT_UNLOCK (pad);
2817 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2819 mycaps = gst_pad_query_caps (pad, NULL);
2821 /* Query peer caps */
2822 query = gst_query_new_caps (mycaps);
2823 if (!gst_pad_peer_query (pad, query)) {
2824 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2828 gst_query_parse_caps_result (query, &caps);
2830 g_warn_if_fail (caps != NULL);
2833 gst_caps_ref (caps);
2835 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2839 gst_query_unref (query);
2840 gst_caps_unref (mycaps);
2846 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2847 GST_OBJECT_UNLOCK (pad);
2854 * gst_pad_iterate_internal_links_default:
2855 * @pad: the #GstPad to get the internal links of.
2856 * @parent: (allow-none): the parent of @pad or %NULL
2858 * Iterate the list of pads to which the given pad is linked to inside of
2859 * the parent element.
2860 * This is the default handler, and thus returns an iterator of all of the
2861 * pads inside the parent element with opposite direction.
2863 * The caller must free this iterator after use with gst_iterator_free().
2865 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2866 * has no parent. Unref each returned pad with gst_object_unref().
2869 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2876 GstElement *eparent;
2878 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2880 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2881 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2883 GST_OBJECT_LOCK (pad);
2884 eparent = GST_PAD_PARENT (pad);
2885 if (!eparent || !GST_IS_ELEMENT (eparent))
2888 gst_object_ref (eparent);
2889 GST_OBJECT_UNLOCK (pad);
2892 if (pad->direction == GST_PAD_SRC)
2893 padlist = &eparent->sinkpads;
2895 padlist = &eparent->srcpads;
2897 GST_DEBUG_OBJECT (pad, "Making iterator");
2899 cookie = &eparent->pads_cookie;
2901 lock = GST_OBJECT_GET_LOCK (eparent);
2903 res = gst_iterator_new_list (GST_TYPE_PAD,
2904 lock, cookie, padlist, (GObject *) owner, NULL);
2906 gst_object_unref (owner);
2913 GST_OBJECT_UNLOCK (pad);
2914 GST_DEBUG_OBJECT (pad, "no parent element");
2920 * gst_pad_iterate_internal_links:
2921 * @pad: the GstPad to get the internal links of.
2923 * Gets an iterator for the pads to which the given pad is linked to inside
2924 * of the parent element.
2926 * Each #GstPad element yielded by the iterator will have its refcount increased,
2927 * so unref after use.
2929 * Free-function: gst_iterator_free
2931 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2932 * or %NULL when the pad does not have an iterator function
2933 * configured. Use gst_iterator_free() after usage.
2936 gst_pad_iterate_internal_links (GstPad * pad)
2938 GstIterator *res = NULL;
2941 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2943 GST_OBJECT_LOCK (pad);
2944 ACQUIRE_PARENT (pad, parent, no_parent);
2945 GST_OBJECT_UNLOCK (pad);
2947 if (GST_PAD_ITERINTLINKFUNC (pad))
2948 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2950 RELEASE_PARENT (parent);
2957 GST_DEBUG_OBJECT (pad, "no parent");
2958 GST_OBJECT_UNLOCK (pad);
2966 * @forward: (scope call): a #GstPadForwardFunction
2967 * @user_data: user data passed to @forward
2969 * Calls @forward for all internally linked pads of @pad. This function deals with
2970 * dynamically changing internal pads and will make sure that the @forward
2971 * function is only called once for each pad.
2973 * When @forward returns %TRUE, no further pads will be processed.
2975 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2978 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2981 gboolean result = FALSE;
2983 gboolean done = FALSE;
2984 GValue item = { 0, };
2985 GList *pushed_pads = NULL;
2987 iter = gst_pad_iterate_internal_links (pad);
2993 switch (gst_iterator_next (iter, &item)) {
2994 case GST_ITERATOR_OK:
2998 intpad = g_value_get_object (&item);
3000 /* if already pushed, skip. FIXME, find something faster to tag pads */
3001 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3002 g_value_reset (&item);
3006 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3007 GST_DEBUG_PAD_NAME (intpad));
3008 done = result = forward (intpad, user_data);
3010 pushed_pads = g_list_prepend (pushed_pads, intpad);
3012 g_value_reset (&item);
3015 case GST_ITERATOR_RESYNC:
3016 /* We don't reset the result here because we don't push the event
3017 * again on pads that got the event already and because we need
3018 * to consider the result of the previous pushes */
3019 gst_iterator_resync (iter);
3021 case GST_ITERATOR_ERROR:
3022 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3025 case GST_ITERATOR_DONE:
3030 g_value_unset (&item);
3031 gst_iterator_free (iter);
3033 g_list_free (pushed_pads);
3043 gboolean dispatched;
3047 event_forward_func (GstPad * pad, EventData * data)
3049 /* for each pad we send to, we should ref the event; it's up
3050 * to downstream to unref again when handled. */
3051 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3052 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3054 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3056 data->dispatched = TRUE;
3063 * gst_pad_event_default:
3064 * @pad: a #GstPad to call the default event handler on.
3065 * @parent: (allow-none): the parent of @pad or %NULL
3066 * @event: (transfer full): the #GstEvent to handle.
3068 * Invokes the default event handler for the given pad.
3070 * The EOS event will pause the task associated with @pad before it is forwarded
3071 * to all internally linked pads,
3073 * The event is sent to all pads internally linked to @pad. This function
3074 * takes ownership of @event.
3076 * Returns: %TRUE if the event was sent successfully.
3079 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3081 gboolean result, forward = TRUE;
3083 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3084 g_return_val_if_fail (event != NULL, FALSE);
3086 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3089 switch (GST_EVENT_TYPE (event)) {
3090 case GST_EVENT_CAPS:
3091 forward = GST_PAD_IS_PROXY_CAPS (pad);
3102 data.dispatched = FALSE;
3103 data.result = FALSE;
3105 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3107 /* for sinkpads without a parent element or without internal links, nothing
3108 * will be dispatched but we still want to return TRUE. */
3109 if (data.dispatched)
3110 result = data.result;
3115 gst_event_unref (event);
3120 /* Default accept caps implementation just checks against
3121 * the allowed caps for the pad */
3123 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3125 /* get the caps and see if it intersects to something not empty */
3126 GstCaps *caps, *allowed = NULL;
3129 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3131 /* first forward the query to internally linked pads when we are dealing with
3133 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3134 result = gst_pad_proxy_query_accept_caps (pad, query);
3136 allowed = gst_pad_get_pad_template_caps (pad);
3141 gst_query_parse_accept_caps (query, &caps);
3143 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3144 allowed = gst_pad_get_pad_template_caps (pad);
3146 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3147 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3148 allowed = gst_pad_query_caps (pad, caps);
3153 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3154 GST_DEBUG_OBJECT (pad,
3155 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3157 result = gst_caps_can_intersect (caps, allowed);
3159 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3160 GST_PTR_FORMAT, allowed, caps);
3161 result = gst_caps_is_subset (caps, allowed);
3163 gst_caps_unref (allowed);
3165 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3168 gst_query_set_accept_caps_result (query, result);
3174 /* Default caps implementation */
3176 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3178 GstCaps *result = NULL, *filter;
3179 GstPadTemplate *templ;
3180 gboolean fixed_caps;
3182 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3185 /* first try to proxy if we must */
3186 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3187 if ((gst_pad_proxy_query_caps (pad, query))) {
3192 gst_query_parse_caps (query, &filter);
3194 /* no proxy or it failed, do default handling */
3195 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3197 GST_OBJECT_LOCK (pad);
3199 /* fixed caps, try the negotiated caps first */
3200 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3201 if ((result = get_pad_caps (pad)))
3202 goto filter_done_unlock;
3205 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3206 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3207 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3208 goto filter_done_unlock;
3212 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3213 "non-fixed pad caps: trying pad caps");
3214 /* non fixed caps, try the negotiated caps */
3215 if ((result = get_pad_caps (pad)))
3216 goto filter_done_unlock;
3219 /* this almost never happens */
3220 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3221 result = GST_CAPS_ANY;
3224 GST_OBJECT_UNLOCK (pad);
3226 /* run the filter on the result */
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3229 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3230 GST_PTR_FORMAT, result, result, filter, filter);
3231 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3232 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3235 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3236 "using caps %p %" GST_PTR_FORMAT, result, result);
3237 result = gst_caps_ref (result);
3239 gst_query_set_caps_result (query, result);
3240 gst_caps_unref (result);
3246 /* Default latency implementation */
3250 GstClockTime min, max;
3254 query_latency_default_fold (const GValue * item, GValue * ret,
3257 GstPad *pad = g_value_get_object (item), *peer;
3258 LatencyFoldData *fold_data = user_data;
3260 gboolean res = FALSE;
3262 query = gst_query_new_latency ();
3264 peer = gst_pad_get_peer (pad);
3266 res = gst_pad_peer_query (pad, query);
3268 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3273 GstClockTime min, max;
3275 gst_query_parse_latency (query, &live, &min, &max);
3277 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3278 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3281 if (min > fold_data->min)
3282 fold_data->min = min;
3284 if (fold_data->max == GST_CLOCK_TIME_NONE)
3285 fold_data->max = max;
3286 else if (max < fold_data->max)
3287 fold_data->max = max;
3289 fold_data->live = TRUE;
3292 GST_DEBUG_OBJECT (pad, "latency query failed");
3293 g_value_set_boolean (ret, FALSE);
3296 gst_query_unref (query);
3298 gst_object_unref (peer);
3304 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3307 GstIteratorResult res;
3308 GValue ret = G_VALUE_INIT;
3310 LatencyFoldData fold_data;
3312 it = gst_pad_iterate_internal_links (pad);
3314 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3318 g_value_init (&ret, G_TYPE_BOOLEAN);
3321 fold_data.live = FALSE;
3323 fold_data.max = GST_CLOCK_TIME_NONE;
3325 g_value_set_boolean (&ret, TRUE);
3326 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3328 case GST_ITERATOR_OK:
3329 g_assert_not_reached ();
3331 case GST_ITERATOR_DONE:
3333 case GST_ITERATOR_ERROR:
3334 g_value_set_boolean (&ret, FALSE);
3336 case GST_ITERATOR_RESYNC:
3337 gst_iterator_resync (it);
3340 g_assert_not_reached ();
3343 gst_iterator_free (it);
3345 query_ret = g_value_get_boolean (&ret);
3347 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3348 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3349 fold_data.min, fold_data.max);
3351 if (fold_data.min > fold_data.max) {
3352 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3355 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3357 GST_LOG_OBJECT (pad, "latency query failed");
3367 gboolean dispatched;
3371 query_forward_func (GstPad * pad, QueryData * data)
3373 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3374 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3376 data->result |= gst_pad_peer_query (pad, data->query);
3378 data->dispatched = TRUE;
3380 /* stop on first successful reply */
3381 return data->result;
3385 * gst_pad_query_default:
3386 * @pad: a #GstPad to call the default query handler on.
3387 * @parent: (allow-none): the parent of @pad or %NULL
3388 * @query: (transfer none): the #GstQuery to handle.
3390 * Invokes the default query handler for the given pad.
3391 * The query is sent to all pads internally linked to @pad. Note that
3392 * if there are many possible sink pads that are internally linked to
3393 * @pad, only one will be sent the query.
3394 * Multi-sinkpad elements should implement custom query handlers.
3396 * Returns: %TRUE if the query was performed successfully.
3399 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3401 gboolean forward, ret = FALSE;
3403 switch (GST_QUERY_TYPE (query)) {
3404 case GST_QUERY_SCHEDULING:
3405 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3407 case GST_QUERY_ALLOCATION:
3408 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3410 case GST_QUERY_ACCEPT_CAPS:
3411 ret = gst_pad_query_accept_caps_default (pad, query);
3414 case GST_QUERY_CAPS:
3415 ret = gst_pad_query_caps_default (pad, query);
3418 case GST_QUERY_LATENCY:
3419 ret = gst_pad_query_latency_default (pad, query);
3422 case GST_QUERY_BITRATE:
3423 /* FIXME: better default handling */
3426 case GST_QUERY_POSITION:
3427 case GST_QUERY_SEEKING:
3428 case GST_QUERY_FORMATS:
3429 case GST_QUERY_JITTER:
3430 case GST_QUERY_RATE:
3431 case GST_QUERY_CONVERT:
3437 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3438 query, GST_QUERY_TYPE_NAME (query));
3444 data.dispatched = FALSE;
3445 data.result = FALSE;
3447 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3449 if (data.dispatched) {
3452 /* nothing dispatched, assume drained */
3453 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3462 #define N_STACK_ALLOCATE_PROBES (16)
3465 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3467 GstPad *pad = data->pad;
3468 GstPadProbeInfo *info = data->info;
3469 GstPadProbeType type, flags;
3470 GstPadProbeCallback callback;
3471 GstPadProbeReturn ret;
3472 gpointer original_data;
3475 /* if we have called this callback, do nothing. But only check
3476 * if we're actually calling probes a second time */
3478 for (i = 0; i < data->n_called_probes; i++) {
3479 if (data->called_probes[i] == hook->hook_id) {
3480 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3481 "hook %lu already called", hook->hook_id);
3487 /* reallocate on the heap if we had more than 16 probes */
3488 if (data->n_called_probes == data->called_probes_size) {
3489 if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
3490 data->called_probes_size *= 2;
3491 data->called_probes =
3492 g_renew (gulong, data->called_probes, data->called_probes_size);
3494 gulong *tmp = data->called_probes;
3496 data->called_probes_size *= 2;
3497 data->called_probes = g_new (gulong, data->called_probes_size);
3498 memcpy (data->called_probes, tmp,
3499 N_STACK_ALLOCATE_PROBES * sizeof (gulong));
3502 data->called_probes[data->n_called_probes++] = hook->hook_id;
3504 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3506 original_data = info->data;
3508 /* one of the scheduling types */
3509 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3512 if (G_UNLIKELY (data->handled)) {
3513 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3514 "probe previously returned HANDLED, not calling again");
3516 } else if (G_UNLIKELY (data->dropped)) {
3517 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3518 "probe previously returned DROPPED, not calling again");
3522 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3523 /* one of the data types for non-idle probes */
3524 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3525 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3527 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3528 /* one of the data types for non-idle probes */
3529 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3530 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3533 /* Type must have PULL or PUSH probe types */
3534 g_assert_not_reached ();
3537 /* one of the blocking types must match */
3538 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3539 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3541 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3542 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3544 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3545 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3546 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3549 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3550 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3552 data->marshalled = TRUE;
3554 callback = (GstPadProbeCallback) hook->func;
3555 if (callback == NULL)
3558 info->id = hook->hook_id;
3560 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3561 pad->priv->idle_running++;
3563 GST_OBJECT_UNLOCK (pad);
3565 ret = callback (pad, info, hook->data);
3567 GST_OBJECT_LOCK (pad);
3569 if ((flags & GST_PAD_PROBE_TYPE_IDLE))
3570 pad->priv->idle_running--;
3572 if (ret != GST_PAD_PROBE_HANDLED && original_data != NULL
3573 && info->data == NULL) {
3574 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3575 info->type = GST_PAD_PROBE_TYPE_INVALID;
3576 data->dropped = TRUE;
3580 case GST_PAD_PROBE_REMOVE:
3581 /* remove the probe */
3582 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3583 cleanup_hook (pad, hook);
3585 case GST_PAD_PROBE_DROP:
3586 /* need to drop the data, make sure other probes don't get called
3588 GST_DEBUG_OBJECT (pad, "asked to drop item");
3589 info->type = GST_PAD_PROBE_TYPE_INVALID;
3590 data->dropped = TRUE;
3592 case GST_PAD_PROBE_HANDLED:
3593 GST_DEBUG_OBJECT (pad, "probe handled data");
3594 data->handled = TRUE;
3596 case GST_PAD_PROBE_PASS:
3597 /* inform the pad block to let things pass */
3598 GST_DEBUG_OBJECT (pad, "asked to pass item");
3601 case GST_PAD_PROBE_OK:
3602 GST_DEBUG_OBJECT (pad, "probe returned OK");
3605 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3612 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3613 "hook %lu with flags 0x%08x does not match %08x",
3614 hook->hook_id, flags, info->type);
3619 /* a probe that does not take or return any data */
3620 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3622 if (G_UNLIKELY (pad->num_probes)) { \
3623 GstFlowReturn pval = defaultval; \
3624 /* pass NULL as the data item */ \
3625 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3626 info.ABI.abi.flow_ret = defaultval; \
3627 ret = do_probe_callbacks (pad, &info, defaultval); \
3628 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3633 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3635 if (G_UNLIKELY (pad->num_probes)) { \
3636 /* pass the data item */ \
3637 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3638 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3639 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3640 /* store the possibly updated data item */ \
3641 data = GST_PAD_PROBE_INFO_DATA (&info); \
3642 /* if something went wrong, exit */ \
3643 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3644 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3645 ret = info.ABI.abi.flow_ret; \
3646 goto handle_label; \
3653 #define PROBE_PUSH(pad,mask,data,label) \
3654 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3655 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3656 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3657 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3658 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3660 static GstFlowReturn
3661 do_pad_idle_probe_wait (GstPad * pad)
3663 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3664 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3665 "waiting idle probe to be removed");
3666 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3667 GST_PAD_BLOCK_WAIT (pad);
3668 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3669 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3671 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3672 return GST_FLOW_FLUSHING;
3677 #define PROBE_TYPE_IS_SERIALIZED(i) \
3680 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3681 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3682 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3684 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3685 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3687 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3688 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3692 static GstFlowReturn
3693 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3694 GstFlowReturn defaultval)
3699 gulong called_probes[N_STACK_ALLOCATE_PROBES];
3704 data.handled = FALSE;
3705 data.marshalled = FALSE;
3706 data.dropped = FALSE;
3708 /* We stack-allocate for N_STACK_ALLOCATE_PROBES hooks as a first step. If more are needed,
3709 * we will re-allocate with g_malloc(). This should usually never be needed
3711 data.called_probes = called_probes;
3712 data.n_called_probes = 0;
3713 data.called_probes_size = N_STACK_ALLOCATE_PROBES;
3717 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3719 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3720 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3725 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "do probes");
3726 cookie = pad->priv->probe_list_cookie;
3728 g_hook_list_marshal (&pad->probes, TRUE,
3729 (GHookMarshaller) probe_hook_marshal, &data);
3731 /* if the list changed, call the new callbacks (they will not be in
3732 * called_probes yet) */
3733 if (cookie != pad->priv->probe_list_cookie) {
3734 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3735 "probe list changed, restarting");
3740 /* the first item that dropped will stop the hooks and then we drop here */
3744 /* If one handler took care of it, let the the item pass */
3749 /* if no handler matched and we are blocking, let the item pass */
3750 if (!data.marshalled && is_block)
3753 /* At this point, all handlers returned either OK or PASS. If one handler
3754 * returned PASS, let the item pass */
3759 while (GST_PAD_IS_BLOCKED (pad)) {
3760 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3761 "we are blocked %d times", pad->num_blocked);
3763 /* we might have released the lock */
3764 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3767 /* now we block the streaming thread. It can be unlocked when we
3768 * deactivate the pad (which will also set the FLUSHING flag) or
3769 * when the pad is unblocked. A flushing event will also unblock
3770 * the pad after setting the FLUSHING flag. */
3771 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3772 "Waiting to be unblocked or set flushing");
3773 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3774 GST_PAD_BLOCK_WAIT (pad);
3775 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3776 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3778 /* if the list changed, call the new callbacks (they will not be in
3779 * called_probes yet) */
3780 if (cookie != pad->priv->probe_list_cookie) {
3781 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3782 "probe list changed, restarting");
3787 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3792 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3793 g_free (data.called_probes);
3800 GST_DEBUG_OBJECT (pad, "pad is flushing");
3801 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3802 g_free (data.called_probes);
3803 return GST_FLOW_FLUSHING;
3807 GST_DEBUG_OBJECT (pad, "data is dropped");
3808 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3809 g_free (data.called_probes);
3810 return GST_FLOW_CUSTOM_SUCCESS;
3814 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3815 GST_DEBUG_OBJECT (pad, "data is passed");
3816 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3817 g_free (data.called_probes);
3822 GST_DEBUG_OBJECT (pad, "data was handled");
3823 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3824 g_free (data.called_probes);
3825 return GST_FLOW_CUSTOM_SUCCESS_1;
3832 * gst_pad_get_offset:
3835 * Get the offset applied to the running time of @pad. @pad has to be a source
3838 * Returns: the offset.
3841 gst_pad_get_offset (GstPad * pad)
3845 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3847 GST_OBJECT_LOCK (pad);
3848 result = pad->offset;
3849 GST_OBJECT_UNLOCK (pad);
3855 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3857 ev->received = FALSE;
3862 * gst_pad_set_offset:
3864 * @offset: the offset
3866 * Set the offset that will be applied to the running time of @pad.
3869 gst_pad_set_offset (GstPad * pad, gint64 offset)
3871 g_return_if_fail (GST_IS_PAD (pad));
3873 GST_OBJECT_LOCK (pad);
3874 /* if nothing changed, do nothing */
3875 if (pad->offset == offset)
3878 pad->offset = offset;
3879 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3880 GST_STIME_ARGS (offset));
3882 /* resend all sticky events with updated offset on next buffer push */
3883 events_foreach (pad, mark_event_not_received, NULL);
3884 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3887 GST_OBJECT_UNLOCK (pad);
3894 /* If TRUE and ret is not OK this means
3895 * that pushing the EOS event failed
3899 /* If called for an event this is
3900 * the event that would be pushed
3901 * next. Don't forward sticky events
3902 * that would come after that */
3906 /* should be called with pad LOCK */
3908 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3910 PushStickyData *data = user_data;
3911 GstEvent *event = ev->event;
3914 GST_DEBUG_OBJECT (pad, "event %s was already received",
3915 GST_EVENT_TYPE_NAME (event));
3919 /* If we're called because of an sticky event, only forward
3920 * events that would come before this new event and the
3922 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3923 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3924 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3925 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3927 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3928 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3929 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3930 data->ret = GST_FLOW_OK;
3933 switch (data->ret) {
3935 ev->received = TRUE;
3936 GST_DEBUG_OBJECT (pad, "event %s marked received",
3937 GST_EVENT_TYPE_NAME (event));
3939 case GST_FLOW_CUSTOM_SUCCESS:
3940 /* we can't assume the event is received when it was dropped */
3941 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3942 GST_EVENT_TYPE_NAME (event));
3943 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3944 data->ret = GST_FLOW_OK;
3946 case GST_FLOW_CUSTOM_SUCCESS_1:
3947 /* event was ignored and should be sent later */
3948 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3949 GST_EVENT_TYPE_NAME (event));
3950 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3951 data->ret = GST_FLOW_OK;
3953 case GST_FLOW_NOT_LINKED:
3954 /* not linked is not a problem, we are sticky so the event will be
3955 * rescheduled to be sent later on re-link, but only for non-EOS events */
3956 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3957 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3958 data->ret = GST_FLOW_OK;
3959 ev->received = TRUE;
3963 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3964 gst_flow_get_name (data->ret));
3965 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3969 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3970 data->was_eos = TRUE;
3972 return data->ret == GST_FLOW_OK;
3975 /* check sticky events and push them when needed. should be called
3977 static inline GstFlowReturn
3978 check_sticky (GstPad * pad, GstEvent * event)
3980 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3982 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3983 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3985 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3986 events_foreach (pad, push_sticky, &data);
3988 /* If there's an EOS event we must push it downstream
3989 * even if sending a previous sticky event failed.
3990 * Otherwise the pipeline might wait forever for EOS.
3992 * Only do this if pushing another event than the EOS
3995 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3996 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3998 if (ev && !ev->received) {
3999 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
4000 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4001 /* the event could have been dropped. Because this can only
4002 * happen if the user asked for it, it's not an error */
4003 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
4004 data.ret = GST_FLOW_OK;
4014 * @pad: a #GstPad to invoke the default query on.
4015 * @query: (transfer none): the #GstQuery to perform.
4017 * Dispatches a query to a pad. The query should have been allocated by the
4018 * caller via one of the type-specific allocation functions. The element that
4019 * the pad belongs to is responsible for filling the query with an appropriate
4020 * response, which should then be parsed with a type-specific query parsing
4023 * Again, the caller is responsible for both the allocation and deallocation of
4024 * the query structure.
4026 * Please also note that some queries might need a running pipeline to work.
4028 * Returns: %TRUE if the query could be performed.
4031 gst_pad_query (GstPad * pad, GstQuery * query)
4034 gboolean res, serialized;
4035 GstPadQueryFunction func;
4036 GstPadProbeType type;
4039 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4040 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4042 if (GST_PAD_IS_SRC (pad)) {
4043 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4044 goto wrong_direction;
4045 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4046 } else if (GST_PAD_IS_SINK (pad)) {
4047 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4048 goto wrong_direction;
4049 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4051 goto unknown_direction;
4053 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4054 GST_QUERY_TYPE_NAME (query));
4055 GST_TRACER_PAD_QUERY_PRE (pad, query);
4057 serialized = GST_QUERY_IS_SERIALIZED (query);
4058 if (G_UNLIKELY (serialized))
4059 GST_PAD_STREAM_LOCK (pad);
4061 GST_OBJECT_LOCK (pad);
4062 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4063 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4064 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4066 ACQUIRE_PARENT (pad, parent, no_parent);
4067 GST_OBJECT_UNLOCK (pad);
4069 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4072 res = func (pad, parent, query);
4074 RELEASE_PARENT (parent);
4076 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4077 GST_QUERY_TYPE_NAME (query), res);
4078 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4083 GST_OBJECT_LOCK (pad);
4084 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4085 GST_OBJECT_UNLOCK (pad);
4087 if (G_UNLIKELY (serialized))
4088 GST_PAD_STREAM_UNLOCK (pad);
4095 g_warning ("pad %s:%s query %s in wrong direction",
4096 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4101 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4106 GST_DEBUG_OBJECT (pad, "had no parent");
4107 GST_OBJECT_UNLOCK (pad);
4108 if (G_UNLIKELY (serialized))
4109 GST_PAD_STREAM_UNLOCK (pad);
4114 GST_DEBUG_OBJECT (pad, "had no query function");
4115 RELEASE_PARENT (parent);
4116 if (G_UNLIKELY (serialized))
4117 GST_PAD_STREAM_UNLOCK (pad);
4122 GST_DEBUG_OBJECT (pad, "query failed");
4123 if (G_UNLIKELY (serialized))
4124 GST_PAD_STREAM_UNLOCK (pad);
4129 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4130 GST_OBJECT_UNLOCK (pad);
4131 if (G_UNLIKELY (serialized))
4132 GST_PAD_STREAM_UNLOCK (pad);
4134 /* if a probe dropped without handling, we don't sent it further but assume
4135 * that the probe did not answer the query and return FALSE */
4136 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4146 * gst_pad_peer_query:
4147 * @pad: a #GstPad to invoke the peer query on.
4148 * @query: (transfer none): the #GstQuery to perform.
4150 * Performs gst_pad_query() on the peer of @pad.
4152 * The caller is responsible for both the allocation and deallocation of
4153 * the query structure.
4155 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4156 * if @pad has no peer.
4159 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4162 GstPadProbeType type;
4163 gboolean res, serialized;
4166 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4167 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4169 if (GST_PAD_IS_SRC (pad)) {
4170 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4171 goto wrong_direction;
4172 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4173 } else if (GST_PAD_IS_SINK (pad)) {
4174 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4175 goto wrong_direction;
4176 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4178 goto unknown_direction;
4180 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4181 GST_QUERY_TYPE_NAME (query));
4183 serialized = GST_QUERY_IS_SERIALIZED (query);
4185 GST_OBJECT_LOCK (pad);
4186 if (GST_PAD_IS_SRC (pad) && serialized) {
4187 /* all serialized queries on the srcpad trigger push of
4189 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4193 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4194 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4195 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4197 peerpad = GST_PAD_PEER (pad);
4198 if (G_UNLIKELY (peerpad == NULL))
4201 gst_object_ref (peerpad);
4202 GST_OBJECT_UNLOCK (pad);
4204 res = gst_pad_query (peerpad, query);
4206 gst_object_unref (peerpad);
4211 GST_OBJECT_LOCK (pad);
4212 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4213 GST_OBJECT_UNLOCK (pad);
4220 g_warning ("pad %s:%s query %s in wrong direction",
4221 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4226 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4231 GST_WARNING_OBJECT (pad, "could not send sticky events");
4232 GST_OBJECT_UNLOCK (pad);
4237 GST_INFO_OBJECT (pad, "pad has no peer");
4238 GST_OBJECT_UNLOCK (pad);
4243 GST_DEBUG_OBJECT (pad, "query failed");
4248 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4249 GST_OBJECT_UNLOCK (pad);
4251 /* if a probe dropped without handling, we don't sent it further but
4252 * assume that the probe did not answer the query and return FALSE */
4253 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4262 /**********************************************************************
4263 * Data passing functions
4266 /* this is the chain function that does not perform the additional argument
4267 * checking for that little extra speed.
4269 static inline GstFlowReturn
4270 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4274 gboolean handled = FALSE;
4276 GST_PAD_STREAM_LOCK (pad);
4278 GST_OBJECT_LOCK (pad);
4279 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4282 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4285 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4288 #ifdef GST_ENABLE_EXTRA_CHECKS
4289 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4290 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4292 ":%s:<%s:%s> Got data flow before stream-start event",
4293 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4295 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4297 ":%s:<%s:%s> Got data flow before segment event",
4298 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4300 pad->priv->last_cookie = pad->priv->events_cookie;
4304 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4307 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4309 ACQUIRE_PARENT (pad, parent, no_parent);
4310 GST_OBJECT_UNLOCK (pad);
4312 /* NOTE: we read the chainfunc unlocked.
4313 * we cannot hold the lock for the pad so we might send
4314 * the data to the wrong function. This is not really a
4315 * problem since functions are assigned at creation time
4316 * and don't change that often... */
4317 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4318 GstPadChainFunction chainfunc;
4320 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4323 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4324 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4325 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4327 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4329 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4330 "called chainfunction &%s with buffer %p, returned %s",
4331 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4333 GstPadChainListFunction chainlistfunc;
4335 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4338 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4339 "calling chainlistfunction &%s",
4340 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4342 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4344 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4345 "called chainlistfunction &%s, returned %s",
4346 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4349 RELEASE_PARENT (parent);
4351 GST_PAD_STREAM_UNLOCK (pad);
4358 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4359 "chaining, but pad was flushing");
4360 GST_OBJECT_UNLOCK (pad);
4361 GST_PAD_STREAM_UNLOCK (pad);
4362 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4363 return GST_FLOW_FLUSHING;
4367 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4368 GST_OBJECT_UNLOCK (pad);
4369 GST_PAD_STREAM_UNLOCK (pad);
4370 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4371 return GST_FLOW_EOS;
4375 g_critical ("chain on pad %s:%s but it was not in push mode",
4376 GST_DEBUG_PAD_NAME (pad));
4377 GST_OBJECT_UNLOCK (pad);
4378 GST_PAD_STREAM_UNLOCK (pad);
4379 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4380 return GST_FLOW_ERROR;
4387 GST_OBJECT_UNLOCK (pad);
4388 GST_PAD_STREAM_UNLOCK (pad);
4389 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4391 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4394 case GST_FLOW_CUSTOM_SUCCESS:
4395 case GST_FLOW_CUSTOM_SUCCESS_1:
4396 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4400 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4407 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4408 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4409 GST_OBJECT_UNLOCK (pad);
4410 GST_PAD_STREAM_UNLOCK (pad);
4411 return GST_FLOW_FLUSHING;
4415 RELEASE_PARENT (parent);
4416 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4417 g_critical ("chain on pad %s:%s but it has no chainfunction",
4418 GST_DEBUG_PAD_NAME (pad));
4419 GST_PAD_STREAM_UNLOCK (pad);
4420 return GST_FLOW_NOT_SUPPORTED;
4426 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4427 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4430 * Chain a buffer to @pad.
4432 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4434 * If the buffer type is not acceptable for @pad (as negotiated with a
4435 * preceding GST_EVENT_CAPS event), this function returns
4436 * #GST_FLOW_NOT_NEGOTIATED.
4438 * The function proceeds calling the chain function installed on @pad (see
4439 * gst_pad_set_chain_function()) and the return value of that function is
4440 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4443 * In all cases, success or failure, the caller loses its reference to @buffer
4444 * after calling this function.
4446 * Returns: a #GstFlowReturn from the pad.
4451 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4453 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4454 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4455 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4457 return gst_pad_chain_data_unchecked (pad,
4458 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4461 static GstFlowReturn
4462 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4463 GstBufferList * list)
4469 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4471 len = gst_buffer_list_length (list);
4474 for (i = 0; i < len; i++) {
4475 buffer = gst_buffer_list_get (list, i);
4477 gst_pad_chain_data_unchecked (pad,
4478 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4479 gst_buffer_ref (buffer));
4480 if (ret != GST_FLOW_OK)
4483 gst_buffer_list_unref (list);
4489 * gst_pad_chain_list:
4490 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4491 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4494 * Chain a bufferlist to @pad.
4496 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4498 * If @pad was not negotiated properly with a CAPS event, this function
4499 * returns #GST_FLOW_NOT_NEGOTIATED.
4501 * The function proceeds calling the chainlist function installed on @pad (see
4502 * gst_pad_set_chain_list_function()) and the return value of that function is
4503 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4504 * chainlist function.
4506 * In all cases, success or failure, the caller loses its reference to @list
4507 * after calling this function.
4511 * Returns: a #GstFlowReturn from the pad.
4514 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4516 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4517 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4518 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4520 return gst_pad_chain_data_unchecked (pad,
4521 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4524 static GstFlowReturn
4525 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4529 gboolean handled = FALSE;
4531 GST_OBJECT_LOCK (pad);
4532 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4535 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4538 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4541 #ifdef GST_ENABLE_EXTRA_CHECKS
4542 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4543 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4545 ":%s:<%s:%s> Got data flow before stream-start event",
4546 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4548 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4550 ":%s:<%s:%s> Got data flow before segment event",
4551 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4553 pad->priv->last_cookie = pad->priv->events_cookie;
4557 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4560 /* do block probes */
4561 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4564 /* recheck sticky events because the probe might have cause a relink */
4565 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4568 /* do post-blocking probes */
4569 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4571 /* recheck sticky events because the probe might have cause a relink */
4572 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4575 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4578 /* take ref to peer pad before releasing the lock */
4579 gst_object_ref (peer);
4581 GST_OBJECT_UNLOCK (pad);
4583 ret = gst_pad_chain_data_unchecked (peer, type, data);
4586 gst_object_unref (peer);
4588 GST_OBJECT_LOCK (pad);
4589 pad->ABI.abi.last_flowret = ret;
4591 if (pad->priv->using == 0) {
4592 /* pad is not active anymore, trigger idle callbacks */
4593 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4594 probe_stopped, ret);
4596 GST_OBJECT_UNLOCK (pad);
4600 /* ERROR recovery here */
4604 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4605 "pushing, but pad was flushing");
4606 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4607 GST_OBJECT_UNLOCK (pad);
4608 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4609 return GST_FLOW_FLUSHING;
4613 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4614 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4615 GST_OBJECT_UNLOCK (pad);
4616 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4617 return GST_FLOW_EOS;
4621 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4622 GST_DEBUG_PAD_NAME (pad));
4623 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4624 GST_OBJECT_UNLOCK (pad);
4625 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4626 return GST_FLOW_ERROR;
4630 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4631 "error pushing events, return %s", gst_flow_get_name (ret));
4632 pad->ABI.abi.last_flowret = ret;
4633 GST_OBJECT_UNLOCK (pad);
4634 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4642 GST_OBJECT_UNLOCK (pad);
4643 if (data != NULL && !handled)
4644 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4647 case GST_FLOW_CUSTOM_SUCCESS:
4648 case GST_FLOW_CUSTOM_SUCCESS_1:
4649 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4653 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4656 pad->ABI.abi.last_flowret = ret;
4661 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4662 "pushing, but it was not linked");
4663 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4664 GST_OBJECT_UNLOCK (pad);
4665 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4666 return GST_FLOW_NOT_LINKED;
4672 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4673 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4676 * Pushes a buffer to the peer of @pad.
4678 * This function will call installed block probes before triggering any
4679 * installed data probes.
4681 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4682 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4685 * In all cases, success or failure, the caller loses its reference to @buffer
4686 * after calling this function.
4688 * Returns: a #GstFlowReturn from the peer pad.
4693 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4697 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4698 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4699 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4701 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4702 res = gst_pad_push_data (pad,
4703 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4704 GST_TRACER_PAD_PUSH_POST (pad, res);
4709 * gst_pad_push_list:
4710 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4711 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4714 * Pushes a buffer list to the peer of @pad.
4716 * This function will call installed block probes before triggering any
4717 * installed data probes.
4719 * The function proceeds calling the chain function on the peer pad and returns
4720 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4721 * be returned. If the peer pad does not have any installed chainlist function
4722 * every group buffer of the list will be merged into a normal #GstBuffer and
4723 * chained via gst_pad_chain().
4725 * In all cases, success or failure, the caller loses its reference to @list
4726 * after calling this function.
4728 * Returns: a #GstFlowReturn from the peer pad.
4733 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4737 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4738 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4739 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4741 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4742 res = gst_pad_push_data (pad,
4743 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4744 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4748 static GstFlowReturn
4749 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4750 GstBuffer ** buffer)
4753 GstPadGetRangeFunction getrangefunc;
4757 GST_PAD_STREAM_LOCK (pad);
4759 GST_OBJECT_LOCK (pad);
4760 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4763 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4766 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4771 /* when one of the probes returns DROPPED, probe_stopped will be called
4772 * and we skip calling the getrange function, res_buf should then contain a
4773 * valid result buffer */
4774 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4775 res_buf, offset, size, probe_stopped);
4777 /* recheck sticky events because the probe might have cause a relink */
4778 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4781 ACQUIRE_PARENT (pad, parent, no_parent);
4782 GST_OBJECT_UNLOCK (pad);
4784 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4787 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4788 "calling getrangefunc %s, offset %"
4789 G_GUINT64_FORMAT ", size %u",
4790 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4792 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4794 RELEASE_PARENT (parent);
4796 GST_OBJECT_LOCK (pad);
4797 if (G_UNLIKELY (ret != GST_FLOW_OK))
4798 goto get_range_failed;
4800 /* can only fire the signal if we have a valid buffer */
4802 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4803 res_buf, offset, size, probe_stopped_unref);
4804 pad->ABI.abi.last_flowret = ret;
4805 GST_OBJECT_UNLOCK (pad);
4807 GST_PAD_STREAM_UNLOCK (pad);
4816 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4817 "getrange, but pad was flushing");
4818 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4819 GST_OBJECT_UNLOCK (pad);
4820 GST_PAD_STREAM_UNLOCK (pad);
4821 return GST_FLOW_FLUSHING;
4825 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4826 GST_DEBUG_PAD_NAME (pad));
4827 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4828 GST_OBJECT_UNLOCK (pad);
4829 GST_PAD_STREAM_UNLOCK (pad);
4830 return GST_FLOW_ERROR;
4834 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4835 pad->ABI.abi.last_flowret = ret;
4836 GST_OBJECT_UNLOCK (pad);
4837 GST_PAD_STREAM_UNLOCK (pad);
4842 GST_DEBUG_OBJECT (pad, "no parent");
4843 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4844 GST_OBJECT_UNLOCK (pad);
4845 GST_PAD_STREAM_UNLOCK (pad);
4846 return GST_FLOW_FLUSHING;
4850 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4851 GST_DEBUG_PAD_NAME (pad));
4852 RELEASE_PARENT (parent);
4853 GST_PAD_STREAM_UNLOCK (pad);
4854 return GST_FLOW_NOT_SUPPORTED;
4858 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4859 "probe returned %s", gst_flow_get_name (ret));
4860 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4862 /* the probe filled the buffer and asks us to not call the getrange
4863 * anymore, we continue with the post probes then. */
4864 GST_DEBUG_OBJECT (pad, "handled buffer");
4868 /* no buffer, we are EOS */
4869 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4873 pad->ABI.abi.last_flowret = ret;
4874 GST_OBJECT_UNLOCK (pad);
4875 GST_PAD_STREAM_UNLOCK (pad);
4879 probe_stopped_unref:
4881 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4882 "probe returned %s", gst_flow_get_name (ret));
4883 /* if we drop here, it signals EOS */
4884 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4886 pad->ABI.abi.last_flowret = ret;
4887 GST_OBJECT_UNLOCK (pad);
4888 GST_PAD_STREAM_UNLOCK (pad);
4889 if (*buffer == NULL)
4890 gst_buffer_unref (res_buf);
4895 pad->ABI.abi.last_flowret = ret;
4896 GST_OBJECT_UNLOCK (pad);
4897 GST_PAD_STREAM_UNLOCK (pad);
4898 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4899 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4900 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4906 * gst_pad_get_range:
4907 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4908 * @offset: The start offset of the buffer
4909 * @size: The length of the buffer
4910 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4911 * returns #GST_FLOW_ERROR if %NULL.
4913 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4914 * immediately and @buffer is %NULL.
4916 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4917 * description of a getrange function. If @pad has no getrange function
4918 * installed (see gst_pad_set_getrange_function()) this function returns
4919 * #GST_FLOW_NOT_SUPPORTED.
4921 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4922 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4923 * must be freed with gst_buffer_unref() after usage.
4925 * When @buffer points to a variable that points to a valid #GstBuffer, the
4926 * buffer will be filled with the result data when this function returns
4927 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4928 * @size bytes will be filled in the result buffer and its size will be updated
4931 * Note that less than @size bytes can be returned in @buffer when, for example,
4932 * an EOS condition is near or when @buffer is not large enough to hold @size
4933 * bytes. The caller should check the result buffer size to get the result size.
4935 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4936 * will be unchanged.
4938 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4940 * Returns: a #GstFlowReturn from the pad.
4945 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4946 GstBuffer ** buffer)
4948 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4949 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4950 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4951 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4952 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4954 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4958 * gst_pad_pull_range:
4959 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4960 * @offset: The start offset of the buffer
4961 * @size: The length of the buffer
4962 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4963 * GST_FLOW_ERROR if %NULL.
4965 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4967 * This function will first trigger the pad block signal if it was
4970 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4971 * function returns the result of gst_pad_get_range() on the peer pad.
4972 * See gst_pad_get_range() for a list of return values and for the
4973 * semantics of the arguments of this function.
4975 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4976 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4977 * must be freed with gst_buffer_unref() after usage. When this function
4978 * returns any other result value, @buffer will still point to %NULL.
4980 * When @buffer points to a variable that points to a valid #GstBuffer, the
4981 * buffer will be filled with the result data when this function returns
4982 * #GST_FLOW_OK. When this function returns any other result value,
4983 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4984 * @size bytes will be filled in the result buffer and its size will be updated
4987 * Note that less than @size bytes can be returned in @buffer when, for example,
4988 * an EOS condition is near or when @buffer is not large enough to hold @size
4989 * bytes. The caller should check the result buffer size to get the result size.
4991 * Returns: a #GstFlowReturn from the peer pad.
4996 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4997 GstBuffer ** buffer)
5003 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5004 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
5005 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5006 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5007 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5009 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
5011 GST_OBJECT_LOCK (pad);
5012 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5015 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
5020 /* when one of the probes returns DROPPED, probe_stopped will be
5021 * called and we skip calling the peer getrange function. *buffer should then
5022 * contain a valid buffer */
5023 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
5024 res_buf, offset, size, probe_stopped);
5026 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
5029 gst_object_ref (peer);
5031 GST_OBJECT_UNLOCK (pad);
5033 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5035 gst_object_unref (peer);
5037 GST_OBJECT_LOCK (pad);
5039 pad->ABI.abi.last_flowret = ret;
5040 if (pad->priv->using == 0) {
5041 /* pad is not active anymore, trigger idle callbacks */
5042 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5043 probe_stopped_unref, ret);
5046 if (G_UNLIKELY (ret != GST_FLOW_OK))
5047 goto pull_range_failed;
5050 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5051 res_buf, offset, size, probe_stopped_unref);
5053 GST_OBJECT_UNLOCK (pad);
5057 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5060 /* ERROR recovery here */
5063 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5064 "pullrange, but pad was flushing");
5065 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5066 GST_OBJECT_UNLOCK (pad);
5067 ret = GST_FLOW_FLUSHING;
5072 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5073 GST_DEBUG_PAD_NAME (pad));
5074 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5075 GST_OBJECT_UNLOCK (pad);
5076 ret = GST_FLOW_ERROR;
5081 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5082 gst_flow_get_name (ret));
5083 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5085 /* the probe filled the buffer and asks us to not forward to the peer
5086 * anymore, we continue with the post probes then */
5087 GST_DEBUG_OBJECT (pad, "handled buffer");
5091 /* no buffer, we are EOS then */
5092 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5096 pad->ABI.abi.last_flowret = ret;
5097 GST_OBJECT_UNLOCK (pad);
5102 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5103 "pulling range, but it was not linked");
5104 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5105 GST_OBJECT_UNLOCK (pad);
5106 ret = GST_FLOW_NOT_LINKED;
5111 pad->ABI.abi.last_flowret = ret;
5112 GST_OBJECT_UNLOCK (pad);
5113 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5114 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5115 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5118 probe_stopped_unref:
5120 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5121 "post probe returned %s", gst_flow_get_name (ret));
5123 /* if we drop here, it signals EOS */
5124 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5127 pad->ABI.abi.last_flowret = ret;
5128 GST_OBJECT_UNLOCK (pad);
5130 if (*buffer == NULL)
5131 gst_buffer_unref (res_buf);
5135 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5139 /* must be called with pad object lock */
5140 static GstFlowReturn
5141 store_sticky_event (GstPad * pad, GstEvent * event)
5146 gboolean res = FALSE;
5147 const gchar *name = NULL;
5148 gboolean insert = TRUE;
5150 type = GST_EVENT_TYPE (event);
5152 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5153 * otherwise they can be dropped and nothing would ever resend them.
5154 * Only do that for activated pads though, everything else is a bug!
5156 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5157 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5158 || type == GST_EVENT_EOS))))
5161 /* Unset the EOS flag when received STREAM_START event, so pad can
5162 * store sticky event and then push it later */
5163 if (type == GST_EVENT_STREAM_START) {
5164 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5165 remove_event_by_type (pad, GST_EVENT_EOS);
5166 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5167 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5170 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5173 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5174 name = gst_structure_get_name (gst_event_get_structure (event));
5176 events = pad->priv->events;
5179 for (i = 0; i < len; i++) {
5180 PadEvent *ev = &g_array_index (events, PadEvent, i);
5182 if (ev->event == NULL)
5185 if (type == GST_EVENT_TYPE (ev->event)) {
5186 /* matching types, check matching name if needed */
5187 if (name && !gst_event_has_name (ev->event, name))
5191 if ((res = gst_event_replace (&ev->event, event)))
5192 ev->received = FALSE;
5198 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5199 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5200 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5201 * storing the sticky ordered we can check that this is respected. */
5202 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5203 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5205 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5206 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5207 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5208 gst_event_type_get_name (type));
5214 ev.event = gst_event_ref (event);
5215 ev.received = FALSE;
5216 g_array_insert_val (events, i, ev);
5221 pad->priv->events_cookie++;
5222 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5224 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5226 switch (GST_EVENT_TYPE (event)) {
5227 case GST_EVENT_CAPS:
5228 GST_OBJECT_UNLOCK (pad);
5230 GST_DEBUG_OBJECT (pad, "notify caps");
5231 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5233 GST_OBJECT_LOCK (pad);
5239 if (type == GST_EVENT_EOS) {
5240 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5241 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5244 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5249 GST_DEBUG_OBJECT (pad, "pad is flushing");
5250 return GST_FLOW_FLUSHING;
5254 GST_DEBUG_OBJECT (pad, "pad is EOS");
5255 return GST_FLOW_EOS;
5260 * gst_pad_store_sticky_event:
5262 * @event: (transfer none): a #GstEvent
5264 * Store the sticky @event on @pad
5266 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5267 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5272 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5276 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5277 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5279 GST_OBJECT_LOCK (pad);
5280 ret = store_sticky_event (pad, event);
5281 GST_OBJECT_UNLOCK (pad);
5287 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5289 PushStickyData *data = user_data;
5291 /* Forward all sticky events before our current one that are pending */
5292 if (ev->event != data->event
5293 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5294 return push_sticky (pad, ev, data);
5299 /* should be called with pad LOCK */
5300 static GstFlowReturn
5301 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5302 GstPadProbeType type)
5306 GstEventType event_type;
5307 gint64 old_pad_offset = pad->offset;
5309 /* pass the adjusted event on. We need to do this even if
5310 * there is no peer pad because of the probes. */
5311 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5313 /* Two checks to be made:
5314 * . (un)set the FLUSHING flag for flushing events,
5315 * . handle pad blocking */
5316 event_type = GST_EVENT_TYPE (event);
5317 switch (event_type) {
5318 case GST_EVENT_FLUSH_START:
5319 GST_PAD_SET_FLUSHING (pad);
5321 GST_PAD_BLOCK_BROADCAST (pad);
5322 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5324 case GST_EVENT_FLUSH_STOP:
5325 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5328 GST_PAD_UNSET_FLUSHING (pad);
5330 /* Remove sticky EOS events */
5331 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5332 remove_event_by_type (pad, GST_EVENT_EOS);
5333 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5334 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5335 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5336 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5338 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5342 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5345 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5346 * checked already or this is called as part of pushing sticky events,
5347 * in which case we still want to forward the EOS event downstream.
5350 switch (GST_EVENT_TYPE (event)) {
5351 case GST_EVENT_RECONFIGURE:
5352 if (GST_PAD_IS_SINK (pad))
5353 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5358 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5359 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5360 /* recheck sticky events because the probe might have cause a relink */
5361 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5362 && (GST_EVENT_IS_SERIALIZED (event)
5363 || GST_EVENT_IS_STICKY (event))) {
5364 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5365 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5367 /* Push all sticky events before our current one
5368 * that have changed */
5369 events_foreach (pad, sticky_changed, &data);
5375 /* send probes after modifying the events above */
5376 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5378 /* recheck sticky events because the probe might have cause a relink */
5379 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5380 && (GST_EVENT_IS_SERIALIZED (event)
5381 || GST_EVENT_IS_STICKY (event))) {
5382 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5383 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5385 /* Push all sticky events before our current one
5386 * that have changed */
5387 events_foreach (pad, sticky_changed, &data);
5390 /* the pad offset might've been changed by any of the probes above. It
5391 * would've been taken into account when repushing any of the sticky events
5392 * above but not for our current event here */
5393 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5395 _apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad),
5396 pad->offset - old_pad_offset);
5399 /* now check the peer pad */
5400 peerpad = GST_PAD_PEER (pad);
5401 if (peerpad == NULL)
5404 gst_object_ref (peerpad);
5406 GST_OBJECT_UNLOCK (pad);
5408 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5409 event, gst_event_type_get_name (event_type), peerpad);
5411 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5413 /* Note: we gave away ownership of the event at this point but we can still
5414 * print the old pointer */
5415 GST_LOG_OBJECT (pad,
5416 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5417 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5419 gst_object_unref (peerpad);
5421 GST_OBJECT_LOCK (pad);
5423 if (pad->priv->using == 0) {
5424 /* pad is not active anymore, trigger idle callbacks */
5425 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5426 idle_probe_stopped, ret);
5430 /* ERROR handling */
5433 GST_DEBUG_OBJECT (pad, "We're flushing");
5434 gst_event_unref (event);
5435 return GST_FLOW_FLUSHING;
5439 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5440 gst_event_unref (event);
5441 return GST_FLOW_FLUSHING;
5445 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5446 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5447 gst_event_unref (event);
5450 case GST_FLOW_CUSTOM_SUCCESS_1:
5451 GST_DEBUG_OBJECT (pad, "handled event");
5453 case GST_FLOW_CUSTOM_SUCCESS:
5454 GST_DEBUG_OBJECT (pad, "dropped event");
5457 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5464 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5465 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5466 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5467 gst_event_unref (event);
5469 /* unlinked pads should not influence latency configuration */
5470 if (event_type == GST_EVENT_LATENCY)
5473 return GST_FLOW_NOT_LINKED;
5477 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5483 * gst_pad_push_event:
5484 * @pad: a #GstPad to push the event to.
5485 * @event: (transfer full): the #GstEvent to send to the pad.
5487 * Sends the event to the peer of the given pad. This function is
5488 * mainly used by elements to send events to their peer
5491 * This function takes ownership of the provided event so you should
5492 * gst_event_ref() it if you want to reuse the event after this call.
5494 * Returns: %TRUE if the event was handled.
5499 gst_pad_push_event (GstPad * pad, GstEvent * event)
5501 gboolean res = FALSE;
5502 GstPadProbeType type;
5503 gboolean sticky, serialized;
5505 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5506 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5508 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5510 if (GST_PAD_IS_SRC (pad)) {
5511 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5512 goto wrong_direction;
5513 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5514 } else if (GST_PAD_IS_SINK (pad)) {
5515 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5516 goto wrong_direction;
5517 /* events pushed on sinkpad never are sticky */
5518 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5520 goto unknown_direction;
5522 GST_OBJECT_LOCK (pad);
5523 sticky = GST_EVENT_IS_STICKY (event);
5524 serialized = GST_EVENT_IS_SERIALIZED (event);
5527 /* srcpad sticky events are stored immediately, the received flag is set
5528 * to FALSE and will be set to TRUE when we can successfully push the
5529 * event to the peer pad */
5530 switch (store_sticky_event (pad, event)) {
5531 case GST_FLOW_FLUSHING:
5539 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5540 /* all serialized or sticky events on the srcpad trigger push of
5542 res = (check_sticky (pad, event) == GST_FLOW_OK);
5547 /* other events are pushed right away */
5548 ret = gst_pad_push_event_unchecked (pad, event, type);
5549 /* dropped events by a probe are not an error */
5550 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5551 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5553 /* Errors in sticky event pushing are no problem and ignored here
5554 * as they will cause more meaningful errors during data flow.
5555 * For EOS events, that are not followed by data flow, we still
5556 * return FALSE here though.
5558 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5560 gst_event_unref (event);
5562 GST_OBJECT_UNLOCK (pad);
5564 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5567 /* ERROR handling */
5570 g_warning ("pad %s:%s pushing %s event in wrong direction",
5571 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5572 gst_event_unref (event);
5577 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5578 gst_event_unref (event);
5583 GST_DEBUG_OBJECT (pad, "We're flushing");
5584 GST_OBJECT_UNLOCK (pad);
5585 gst_event_unref (event);
5590 GST_DEBUG_OBJECT (pad, "We're EOS");
5591 GST_OBJECT_UNLOCK (pad);
5592 gst_event_unref (event);
5596 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5600 /* Check if we can call the event function with the given event */
5601 static GstFlowReturn
5602 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5606 switch (GST_EVENT_TYPE (event)) {
5607 case GST_EVENT_CAPS:
5609 /* backwards compatibility mode for caps */
5610 gst_event_parse_caps (event, &caps);
5612 if (!gst_pad_query_accept_caps (pad, caps))
5624 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5625 "caps %" GST_PTR_FORMAT " not accepted", caps);
5626 return GST_FLOW_NOT_NEGOTIATED;
5630 static GstFlowReturn
5631 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5632 GstPadProbeType type)
5635 GstEventType event_type;
5636 gboolean serialized, need_unlock = FALSE, sticky;
5637 GstPadEventFunction eventfunc;
5638 GstPadEventFullFunction eventfullfunc = NULL;
5640 gint64 old_pad_offset;
5642 GST_OBJECT_LOCK (pad);
5644 old_pad_offset = pad->offset;
5645 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5647 if (GST_PAD_IS_SINK (pad))
5648 serialized = GST_EVENT_IS_SERIALIZED (event);
5651 sticky = GST_EVENT_IS_STICKY (event);
5652 event_type = GST_EVENT_TYPE (event);
5653 switch (event_type) {
5654 case GST_EVENT_FLUSH_START:
5655 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5656 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5658 /* can't even accept a flush begin event when flushing */
5659 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5662 GST_PAD_SET_FLUSHING (pad);
5663 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5664 GST_PAD_BLOCK_BROADCAST (pad);
5665 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5667 case GST_EVENT_FLUSH_STOP:
5668 /* we can't accept flush-stop on inactive pads else the flushing flag
5669 * would be cleared and it would look like the pad can accept data.
5670 * Also, some elements restart a streaming thread in flush-stop which we
5671 * can't allow on inactive pads */
5672 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5675 GST_PAD_UNSET_FLUSHING (pad);
5676 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5677 /* Remove pending EOS events */
5678 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5679 remove_event_by_type (pad, GST_EVENT_EOS);
5680 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5681 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5682 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5683 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5685 GST_OBJECT_UNLOCK (pad);
5686 /* grab stream lock */
5687 GST_PAD_STREAM_LOCK (pad);
5689 GST_OBJECT_LOCK (pad);
5690 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5693 case GST_EVENT_RECONFIGURE:
5694 if (GST_PAD_IS_SRC (pad))
5695 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5697 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5698 "have event type %" GST_PTR_FORMAT, event);
5700 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5703 switch (event_type) {
5704 case GST_EVENT_STREAM_START:
5705 /* Remove sticky EOS events */
5706 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5707 remove_event_by_type (pad, GST_EVENT_EOS);
5708 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5709 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5716 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5719 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5720 GST_OBJECT_UNLOCK (pad);
5721 GST_PAD_STREAM_LOCK (pad);
5723 GST_OBJECT_LOCK (pad);
5724 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5727 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5733 /* now do the probe */
5735 type | GST_PAD_PROBE_TYPE_PUSH |
5736 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5738 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5740 /* the pad offset might've been changed by any of the probes above. It
5741 * would've been taken into account when repushing any of the sticky events
5742 * above but not for our current event here */
5743 if (G_UNLIKELY (old_pad_offset != pad->offset)) {
5745 _apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad),
5746 pad->offset - old_pad_offset);
5749 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5750 eventfunc = GST_PAD_EVENTFUNC (pad);
5751 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5754 ACQUIRE_PARENT (pad, parent, no_parent);
5755 GST_OBJECT_UNLOCK (pad);
5757 ret = pre_eventfunc_check (pad, event);
5758 if (G_UNLIKELY (ret != GST_FLOW_OK))
5759 goto precheck_failed;
5762 gst_event_ref (event);
5764 if (eventfullfunc) {
5765 ret = eventfullfunc (pad, parent, event);
5766 } else if (eventfunc (pad, parent, event)) {
5769 /* something went wrong */
5770 switch (event_type) {
5771 case GST_EVENT_CAPS:
5772 ret = GST_FLOW_NOT_NEGOTIATED;
5775 ret = GST_FLOW_ERROR;
5779 RELEASE_PARENT (parent);
5781 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5784 if (ret == GST_FLOW_OK) {
5785 GST_OBJECT_LOCK (pad);
5786 /* after the event function accepted the event, we can store the sticky
5787 * event on the pad */
5788 switch (store_sticky_event (pad, event)) {
5789 case GST_FLOW_FLUSHING:
5796 GST_OBJECT_UNLOCK (pad);
5798 gst_event_unref (event);
5802 GST_PAD_STREAM_UNLOCK (pad);
5806 /* ERROR handling */
5809 GST_OBJECT_UNLOCK (pad);
5811 GST_PAD_STREAM_UNLOCK (pad);
5812 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5813 "Received event on flushing pad. Discarding");
5814 gst_event_unref (event);
5815 return GST_FLOW_FLUSHING;
5819 GST_OBJECT_UNLOCK (pad);
5821 GST_PAD_STREAM_UNLOCK (pad);
5822 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5823 "Received flush-stop on inactive pad. Discarding");
5824 gst_event_unref (event);
5825 return GST_FLOW_FLUSHING;
5829 GST_OBJECT_UNLOCK (pad);
5831 GST_PAD_STREAM_UNLOCK (pad);
5832 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5833 "Received event on EOS pad. Discarding");
5834 gst_event_unref (event);
5835 return GST_FLOW_EOS;
5839 GST_OBJECT_UNLOCK (pad);
5841 GST_PAD_STREAM_UNLOCK (pad);
5842 /* Only unref if unhandled */
5843 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5844 gst_event_unref (event);
5847 case GST_FLOW_CUSTOM_SUCCESS_1:
5848 case GST_FLOW_CUSTOM_SUCCESS:
5849 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5853 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5860 g_warning ("pad %s:%s has no event handler, file a bug.",
5861 GST_DEBUG_PAD_NAME (pad));
5862 GST_OBJECT_UNLOCK (pad);
5864 GST_PAD_STREAM_UNLOCK (pad);
5865 gst_event_unref (event);
5866 return GST_FLOW_NOT_SUPPORTED;
5870 GST_DEBUG_OBJECT (pad, "no parent");
5871 GST_OBJECT_UNLOCK (pad);
5873 GST_PAD_STREAM_UNLOCK (pad);
5874 gst_event_unref (event);
5875 return GST_FLOW_FLUSHING;
5879 GST_DEBUG_OBJECT (pad, "pre event check failed");
5880 RELEASE_PARENT (parent);
5882 GST_PAD_STREAM_UNLOCK (pad);
5883 gst_event_unref (event);
5889 * gst_pad_send_event:
5890 * @pad: a #GstPad to send the event to.
5891 * @event: (transfer full): the #GstEvent to send to the pad.
5893 * Sends the event to the pad. This function can be used
5894 * by applications to send events in the pipeline.
5896 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5897 * sink pad, @event should be a downstream event. For example, you would not
5898 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5899 * Furthermore, some downstream events have to be serialized with data flow,
5900 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5901 * the event needs to be serialized with data flow, this function will take the
5902 * pad's stream lock while calling its event function.
5904 * To find out whether an event type is upstream, downstream, or downstream and
5905 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5906 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5907 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5908 * plugin doesn't need to bother itself with this information; the core handles
5909 * all necessary locks and checks.
5911 * This function takes ownership of the provided event so you should
5912 * gst_event_ref() it if you want to reuse the event after this call.
5914 * Returns: %TRUE if the event was handled.
5917 gst_pad_send_event (GstPad * pad, GstEvent * event)
5920 GstPadProbeType type;
5922 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5923 g_return_val_if_fail (event != NULL, FALSE);
5925 if (GST_PAD_IS_SINK (pad)) {
5926 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5927 goto wrong_direction;
5928 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5929 } else if (GST_PAD_IS_SRC (pad)) {
5930 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5931 goto wrong_direction;
5932 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5934 goto unknown_direction;
5936 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5943 /* ERROR handling */
5946 g_warning ("pad %s:%s sending %s event in wrong direction",
5947 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5948 gst_event_unref (event);
5953 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5954 gst_event_unref (event);
5960 * gst_pad_set_element_private:
5961 * @pad: the #GstPad to set the private data of.
5962 * @priv: The private data to attach to the pad.
5964 * Set the given private data gpointer on the pad.
5965 * This function can only be used by the element that owns the pad.
5966 * No locking is performed in this function.
5969 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5971 pad->element_private = priv;
5975 * gst_pad_get_element_private:
5976 * @pad: the #GstPad to get the private data of.
5978 * Gets the private data of a pad.
5979 * No locking is performed in this function.
5981 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5984 gst_pad_get_element_private (GstPad * pad)
5986 return pad->element_private;
5990 * gst_pad_get_sticky_event:
5991 * @pad: the #GstPad to get the event from.
5992 * @event_type: the #GstEventType that should be retrieved.
5993 * @idx: the index of the event
5995 * Returns a new reference of the sticky event of type @event_type
5998 * Returns: (transfer full) (nullable): a #GstEvent of type
5999 * @event_type or %NULL when no event of @event_type was on
6000 * @pad. Unref after usage.
6003 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
6005 GstEvent *event = NULL;
6008 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
6009 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
6011 GST_OBJECT_LOCK (pad);
6012 ev = find_event_by_type (pad, event_type, idx);
6013 if (ev && (event = ev->event))
6014 gst_event_ref (event);
6015 GST_OBJECT_UNLOCK (pad);
6022 GstPadStickyEventsForeachFunction func;
6027 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
6029 ForeachDispatch *data = user_data;
6030 gboolean ret = TRUE;
6033 GST_OBJECT_UNLOCK (pad);
6035 ret = data->func (pad, &ev->event, data->user_data);
6037 GST_OBJECT_LOCK (pad);
6044 * gst_pad_sticky_events_foreach:
6045 * @pad: the #GstPad that should be used for iteration.
6046 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
6047 * should be called for every event.
6048 * @user_data: (closure): the optional user data.
6050 * Iterates all sticky events on @pad and calls @foreach_func for every
6051 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6054 gst_pad_sticky_events_foreach (GstPad * pad,
6055 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6057 ForeachDispatch data;
6059 g_return_if_fail (GST_IS_PAD (pad));
6060 g_return_if_fail (foreach_func != NULL);
6062 data.func = foreach_func;
6063 data.user_data = user_data;
6065 GST_OBJECT_LOCK (pad);
6066 events_foreach (pad, foreach_dispatch_function, &data);
6067 GST_OBJECT_UNLOCK (pad);
6071 do_stream_status (GstPad * pad, GstStreamStatusType type,
6072 GThread * thread, GstTask * task)
6076 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6078 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6079 if (GST_IS_ELEMENT (parent)) {
6080 GstMessage *message;
6081 GValue value = { 0 };
6083 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6084 gchar *tname, *ename, *pname;
6086 /* create a good task name */
6087 ename = gst_element_get_name (parent);
6088 pname = gst_pad_get_name (pad);
6089 tname = g_strdup_printf ("%s:%s", ename, pname);
6093 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6097 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6100 g_value_init (&value, GST_TYPE_TASK);
6101 g_value_set_object (&value, task);
6102 gst_message_set_stream_status_object (message, &value);
6103 g_value_unset (&value);
6105 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6106 gst_element_post_message (parent, message);
6108 gst_object_unref (parent);
6113 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6115 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6120 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6122 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6127 * gst_pad_start_task:
6128 * @pad: the #GstPad to start the task of
6129 * @func: the task function to call
6130 * @user_data: user data passed to the task function
6131 * @notify: called when @user_data is no longer referenced
6133 * Starts a task that repeatedly calls @func with @user_data. This function
6134 * is mostly used in pad activation functions to start the dataflow.
6135 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6136 * before @func is called.
6138 * Returns: a %TRUE if the task could be started.
6141 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6142 GDestroyNotify notify)
6147 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6148 g_return_val_if_fail (func != NULL, FALSE);
6150 GST_DEBUG_OBJECT (pad, "start task");
6152 GST_OBJECT_LOCK (pad);
6153 task = GST_PAD_TASK (pad);
6155 task = gst_task_new (func, user_data, notify);
6156 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6157 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6158 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6159 GST_INFO_OBJECT (pad, "created task %p", task);
6160 GST_PAD_TASK (pad) = task;
6161 gst_object_ref (task);
6162 /* release lock to post the message */
6163 GST_OBJECT_UNLOCK (pad);
6165 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6167 gst_object_unref (task);
6169 GST_OBJECT_LOCK (pad);
6170 /* nobody else is supposed to have changed the pad now */
6171 if (GST_PAD_TASK (pad) != task)
6172 goto concurrent_stop;
6174 res = gst_task_set_state (task, GST_TASK_STARTED);
6175 GST_OBJECT_UNLOCK (pad);
6182 GST_OBJECT_UNLOCK (pad);
6188 * gst_pad_pause_task:
6189 * @pad: the #GstPad to pause the task of
6191 * Pause the task of @pad. This function will also wait until the
6192 * function executed by the task is finished if this function is not
6193 * called from the task function.
6195 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6199 gst_pad_pause_task (GstPad * pad)
6204 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6206 GST_DEBUG_OBJECT (pad, "pause task");
6208 GST_OBJECT_LOCK (pad);
6209 task = GST_PAD_TASK (pad);
6212 res = gst_task_set_state (task, GST_TASK_PAUSED);
6213 /* unblock activation waits if any */
6214 pad->priv->in_activation = FALSE;
6215 g_cond_broadcast (&pad->priv->activation_cond);
6216 GST_OBJECT_UNLOCK (pad);
6218 /* wait for task function to finish, this lock is recursive so it does nothing
6219 * when the pause is called from the task itself */
6220 GST_PAD_STREAM_LOCK (pad);
6221 GST_PAD_STREAM_UNLOCK (pad);
6227 GST_DEBUG_OBJECT (pad, "pad has no task");
6228 GST_OBJECT_UNLOCK (pad);
6234 * gst_pad_get_task_state:
6235 * @pad: the #GstPad to get task state from
6237 * Get @pad task state. If no task is currently
6238 * set, #GST_TASK_STOPPED is returned.
6240 * Returns: The current state of @pad's task.
6245 gst_pad_get_task_state (GstPad * pad)
6250 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6252 GST_OBJECT_LOCK (pad);
6253 task = GST_PAD_TASK (pad);
6256 res = gst_task_get_state (task);
6257 GST_OBJECT_UNLOCK (pad);
6263 GST_DEBUG_OBJECT (pad, "pad has no task");
6264 GST_OBJECT_UNLOCK (pad);
6265 return GST_TASK_STOPPED;
6270 * gst_pad_stop_task:
6271 * @pad: the #GstPad to stop the task of
6273 * Stop the task of @pad. This function will also make sure that the
6274 * function executed by the task will effectively stop if not called
6275 * from the GstTaskFunction.
6277 * This function will deadlock if called from the GstTaskFunction of
6278 * the task. Use gst_task_pause() instead.
6280 * Regardless of whether the pad has a task, the stream lock is acquired and
6281 * released so as to ensure that streaming through this pad has finished.
6283 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6286 gst_pad_stop_task (GstPad * pad)
6291 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6293 GST_DEBUG_OBJECT (pad, "stop task");
6295 GST_OBJECT_LOCK (pad);
6296 task = GST_PAD_TASK (pad);
6299 GST_PAD_TASK (pad) = NULL;
6300 res = gst_task_set_state (task, GST_TASK_STOPPED);
6301 /* unblock activation waits if any */
6302 pad->priv->in_activation = FALSE;
6303 g_cond_broadcast (&pad->priv->activation_cond);
6304 GST_OBJECT_UNLOCK (pad);
6306 GST_PAD_STREAM_LOCK (pad);
6307 GST_PAD_STREAM_UNLOCK (pad);
6309 if (!gst_task_join (task))
6312 gst_object_unref (task);
6318 GST_DEBUG_OBJECT (pad, "no task");
6319 GST_OBJECT_UNLOCK (pad);
6321 GST_PAD_STREAM_LOCK (pad);
6322 GST_PAD_STREAM_UNLOCK (pad);
6324 /* this is not an error */
6329 /* this is bad, possibly the application tried to join the task from
6330 * the task's thread. We install the task again so that it will be stopped
6331 * again from the right thread next time hopefully. */
6332 GST_OBJECT_LOCK (pad);
6333 GST_DEBUG_OBJECT (pad, "join failed");
6334 /* we can only install this task if there was no other task */
6335 if (GST_PAD_TASK (pad) == NULL)
6336 GST_PAD_TASK (pad) = task;
6337 GST_OBJECT_UNLOCK (pad);
6344 * gst_pad_probe_info_get_event:
6345 * @info: a #GstPadProbeInfo
6347 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6351 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6353 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6354 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6356 return GST_PAD_PROBE_INFO_EVENT (info);
6361 * gst_pad_probe_info_get_query:
6362 * @info: a #GstPadProbeInfo
6364 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6368 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6370 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6371 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6373 return GST_PAD_PROBE_INFO_QUERY (info);
6377 * gst_pad_probe_info_get_buffer:
6378 * @info: a #GstPadProbeInfo
6380 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6384 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6386 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6388 return GST_PAD_PROBE_INFO_BUFFER (info);
6392 * gst_pad_probe_info_get_buffer_list:
6393 * @info: a #GstPadProbeInfo
6395 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6399 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6401 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6403 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6407 * gst_pad_get_last_flow_return:
6410 * Gets the #GstFlowReturn return from the last data passed by this pad.
6415 gst_pad_get_last_flow_return (GstPad * pad)
6419 GST_OBJECT_LOCK (pad);
6420 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6421 GST_OBJECT_UNLOCK (pad);