2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 * @short_description: Object contained by elements that allows links to
27 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
29 * A #GstElement is linked to other elements via "pads", which are extremely
30 * light-weight generic link points.
32 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
37 * happens when the element is created but it can also happen dynamically based
38 * on the data that the element is processing or based on the pads that the
39 * application requests.
41 * Pads without pad templates can be created with gst_pad_new(),
42 * which takes a direction and a name as an argument. If the name is %NULL,
43 * then a guaranteed unique name will be assigned to it.
45 * A #GstElement creating a pad will typically use the various
46 * gst_pad_set_*_function() calls to register callbacks for events, queries or
47 * dataflow on the pads.
49 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
51 * After two pads are retrieved from an element by gst_element_get_static_pad(),
52 * the pads can be linked with gst_pad_link(). (For quick links,
53 * you can also use gst_element_link(), which will make the obvious
54 * link for you if it's straightforward.). Pads can be unlinked again with
55 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
58 * Before dataflow is possible on the pads, they need to be activated with
59 * gst_pad_set_active().
61 * gst_pad_query() and gst_pad_peer_query() can be used to query various
62 * properties of the pad and the stream.
64 * To send a #GstEvent on a pad, use gst_pad_send_event() and
65 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
66 * after they pass on the pad they can be queried later with
67 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
68 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
69 * functions to query the current sticky CAPS event on a pad.
71 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
72 * or pull in a buffer.
74 * The dataflow, events and queries that happen on a pad can be monitored with
75 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
76 * can be used to check if a block probe is installed on the pad.
77 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
78 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
79 * and unblock blocking probes if any.
81 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
82 * offset will be applied to the running_time of all data passing over the pad.
83 * gst_pad_set_offset() can be used to change the offset.
85 * Convenience functions exist to start, pause and stop the task on a pad with
86 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
90 #include "gst_private.h"
93 #include "gstpadtemplate.h"
94 #include "gstenumtypes.h"
98 #include "gsttracerutils.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
124 #define GST_PAD_GET_PRIVATE(obj) \
125 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
127 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
129 /* we have a pending and an active event on the pad. On source pads only the
130 * active event is used. On sinkpads, events are copied to the pending entry and
131 * moved to the active event when the eventfunc returned %TRUE. */
138 struct _GstPadPrivate
145 guint probe_list_cookie;
147 /* counter of how many idle probes are running directly from the add_probe
148 * call. Used to block any data flowing in the pad while the idle callback
149 * Doesn't finish its work */
152 /* conditional and variable used to ensure pads only get (de)activated
153 * by a single thread at a time. Protected by the object lock */
154 GCond activation_cond;
155 gboolean in_activation;
163 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
164 (((GstPad *)(p))->priv->idle_running > 0)
169 GstPadProbeInfo *info;
175 GHook **called_probes;
176 guint n_called_probes;
177 guint called_probes_size;
181 static void gst_pad_dispose (GObject * object);
182 static void gst_pad_finalize (GObject * object);
183 static void gst_pad_set_property (GObject * object, guint prop_id,
184 const GValue * value, GParamSpec * pspec);
185 static void gst_pad_get_property (GObject * object, guint prop_id,
186 GValue * value, GParamSpec * pspec);
188 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
189 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
190 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
191 GstObject * parent, GstBufferList * list);
193 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
194 GstEvent * event, GstPadProbeType type);
195 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
196 GstEvent ** event, GstPadProbeType type);
198 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
199 GstPadMode mode, gboolean active);
201 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
203 static GParamSpec *pspec_caps = NULL;
205 /* quarks for probe signals */
206 static GQuark buffer_quark;
207 static GQuark buffer_list_quark;
208 static GQuark event_quark;
217 static GstFlowQuarks flow_quarks[] = {
218 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
219 {GST_FLOW_OK, "ok", 0},
220 {GST_FLOW_NOT_LINKED, "not-linked", 0},
221 {GST_FLOW_FLUSHING, "flushing", 0},
222 {GST_FLOW_EOS, "eos", 0},
223 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
224 {GST_FLOW_ERROR, "error", 0},
225 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
226 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
231 * @ret: a #GstFlowReturn to get the name of.
233 * Gets a string representing the given flow return.
235 * Returns: a static string with the name of the flow return.
238 gst_flow_get_name (GstFlowReturn ret)
242 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
244 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
245 if (ret == flow_quarks[i].ret)
246 return flow_quarks[i].name;
253 * @ret: a #GstFlowReturn to get the quark of.
255 * Get the unique quark for the given GstFlowReturn.
257 * Returns: the quark associated with the flow return or 0 if an
258 * invalid return was specified.
261 gst_flow_to_quark (GstFlowReturn ret)
265 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
267 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
268 if (ret == flow_quarks[i].ret)
269 return flow_quarks[i].quark;
275 * gst_pad_link_get_name:
276 * @ret: a #GstPadLinkReturn to get the name of.
278 * Gets a string representing the given pad-link return.
280 * Returns: a static string with the name of the pad-link return.
285 gst_pad_link_get_name (GstPadLinkReturn ret)
288 case GST_PAD_LINK_OK:
290 case GST_PAD_LINK_WRONG_HIERARCHY:
291 return "wrong hierarchy";
292 case GST_PAD_LINK_WAS_LINKED:
294 case GST_PAD_LINK_WRONG_DIRECTION:
295 return "wrong direction";
296 case GST_PAD_LINK_NOFORMAT:
297 return "no common format";
298 case GST_PAD_LINK_NOSCHED:
299 return "incompatible scheduling";
300 case GST_PAD_LINK_REFUSED:
303 g_return_val_if_reached ("unknown");
310 buffer_quark = g_quark_from_static_string ("buffer"); \
311 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
312 event_quark = g_quark_from_static_string ("event"); \
314 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
315 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
318 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
319 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
322 #define gst_pad_parent_class parent_class
323 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
326 gst_pad_class_init (GstPadClass * klass)
328 GObjectClass *gobject_class;
329 GstObjectClass *gstobject_class;
331 gobject_class = G_OBJECT_CLASS (klass);
332 gstobject_class = GST_OBJECT_CLASS (klass);
334 g_type_class_add_private (klass, sizeof (GstPadPrivate));
336 gobject_class->dispose = gst_pad_dispose;
337 gobject_class->finalize = gst_pad_finalize;
338 gobject_class->set_property = gst_pad_set_property;
339 gobject_class->get_property = gst_pad_get_property;
343 * @pad: the pad that emitted the signal
344 * @peer: the peer pad that has been connected
346 * Signals that a pad has been linked to the peer pad.
348 gst_pad_signals[PAD_LINKED] =
349 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
350 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
351 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
354 * @pad: the pad that emitted the signal
355 * @peer: the peer pad that has been disconnected
357 * Signals that a pad has been unlinked from the peer pad.
359 gst_pad_signals[PAD_UNLINKED] =
360 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
361 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
362 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
364 pspec_caps = g_param_spec_boxed ("caps", "Caps",
365 "The capabilities of the pad", GST_TYPE_CAPS,
366 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
367 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
369 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
370 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
371 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
372 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
374 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
375 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
376 g_param_spec_object ("template", "Template",
377 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
378 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
383 * The offset that will be applied to the running time of the pad.
387 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
388 g_param_spec_int64 ("offset", "Offset",
389 "The running time offset of the pad", 0, G_MAXINT64, 0,
390 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
392 gstobject_class->path_string_separator = ".";
394 /* Register common function pointer descriptions */
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
396 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
397 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
398 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
399 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
403 gst_pad_init (GstPad * pad)
405 pad->priv = GST_PAD_GET_PRIVATE (pad);
407 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
409 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
410 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
411 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
412 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
413 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
415 GST_PAD_SET_FLUSHING (pad);
417 g_rec_mutex_init (&pad->stream_rec_lock);
419 g_cond_init (&pad->block_cond);
421 g_hook_list_init (&pad->probes, sizeof (GstProbe));
423 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
424 pad->priv->events_cookie = 0;
425 pad->priv->last_cookie = -1;
426 g_cond_init (&pad->priv->activation_cond);
428 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
431 /* called when setting the pad inactive. It removes all sticky events from
432 * the pad. must be called with object lock */
434 remove_events (GstPad * pad)
438 gboolean notify = FALSE;
440 events = pad->priv->events;
443 for (i = 0; i < len; i++) {
444 PadEvent *ev = &g_array_index (events, PadEvent, i);
445 GstEvent *event = ev->event;
449 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
452 gst_event_unref (event);
455 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
456 g_array_set_size (events, 0);
457 pad->priv->events_cookie++;
460 GST_OBJECT_UNLOCK (pad);
462 GST_DEBUG_OBJECT (pad, "notify caps");
463 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
465 GST_OBJECT_LOCK (pad);
469 /* should be called with object lock */
471 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
477 events = pad->priv->events;
480 for (i = 0; i < len; i++) {
481 ev = &g_array_index (events, PadEvent, i);
482 if (ev->event == NULL)
485 if (GST_EVENT_TYPE (ev->event) == type) {
489 } else if (GST_EVENT_TYPE (ev->event) > type) {
498 /* should be called with OBJECT lock */
500 find_event (GstPad * pad, GstEvent * event)
506 events = pad->priv->events;
509 for (i = 0; i < len; i++) {
510 ev = &g_array_index (events, PadEvent, i);
511 if (event == ev->event)
513 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
521 /* should be called with OBJECT lock */
523 remove_event_by_type (GstPad * pad, GstEventType type)
529 events = pad->priv->events;
534 ev = &g_array_index (events, PadEvent, i);
535 if (ev->event == NULL)
538 if (GST_EVENT_TYPE (ev->event) > type)
540 else if (GST_EVENT_TYPE (ev->event) != type)
543 gst_event_unref (ev->event);
544 g_array_remove_index (events, i);
546 pad->priv->events_cookie++;
554 /* check all events on srcpad against those on sinkpad. All events that are not
555 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
556 * srcpad so that the events will be sent next time */
557 /* should be called with srcpad and sinkpad LOCKS */
559 schedule_events (GstPad * srcpad, GstPad * sinkpad)
564 gboolean pending = FALSE;
566 events = srcpad->priv->events;
569 for (i = 0; i < len; i++) {
570 ev = &g_array_index (events, PadEvent, i);
571 if (ev->event == NULL)
574 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
575 ev->received = FALSE;
580 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
583 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
586 /* should be called with pad LOCK */
588 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
595 events = pad->priv->events;
598 cookie = pad->priv->events_cookie;
602 PadEvent *ev, ev_ret;
604 ev = &g_array_index (events, PadEvent, i);
605 if (G_UNLIKELY (ev->event == NULL))
608 /* take additional ref, func might release the lock */
609 ev_ret.event = gst_event_ref (ev->event);
610 ev_ret.received = ev->received;
612 ret = func (pad, &ev_ret, user_data);
614 /* recheck the cookie, lock might have been released and the list could have
616 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
617 if (G_LIKELY (ev_ret.event))
618 gst_event_unref (ev_ret.event);
622 /* store the received state */
623 ev->received = ev_ret.received;
625 /* if the event changed, we need to do something */
626 if (G_UNLIKELY (ev->event != ev_ret.event)) {
627 if (G_UNLIKELY (ev_ret.event == NULL)) {
628 /* function unreffed and set the event to NULL, remove it */
629 gst_event_unref (ev->event);
630 g_array_remove_index (events, i);
632 cookie = ++pad->priv->events_cookie;
635 /* function gave a new event for us */
636 gst_event_take (&ev->event, ev_ret.event);
639 /* just unref, nothing changed */
640 gst_event_unref (ev_ret.event);
649 /* should be called with LOCK */
651 _apply_pad_offset (GstPad * pad, GstEvent * event, gint64 applied_offset,
656 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
657 GST_STIME_ARGS (pad->offset));
659 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
662 g_assert (!upstream);
664 /* copy segment values */
665 gst_event_copy_segment (event, &segment);
666 gst_event_unref (event);
668 gst_segment_offset_running_time (&segment, segment.format, applied_offset);
669 event = gst_event_new_segment (&segment);
672 event = gst_event_make_writable (event);
673 offset = gst_event_get_running_time_offset (event);
675 offset -= applied_offset;
677 offset += applied_offset;
678 gst_event_set_running_time_offset (event, offset);
683 static inline GstEvent *
684 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
686 if (G_UNLIKELY (pad->offset != 0))
687 return _apply_pad_offset (pad, event, pad->offset, upstream);
692 /* should be called with the OBJECT_LOCK */
694 get_pad_caps (GstPad * pad)
696 GstCaps *caps = NULL;
699 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
701 gst_event_parse_caps (ev->event, &caps);
707 gst_pad_dispose (GObject * object)
709 GstPad *pad = GST_PAD_CAST (object);
712 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
714 /* unlink the peer pad */
715 if ((peer = gst_pad_get_peer (pad))) {
716 /* window for MT unsafeness, someone else could unlink here
717 * and then we call unlink with wrong pads. The unlink
718 * function would catch this and safely return failed. */
719 if (GST_PAD_IS_SRC (pad))
720 gst_pad_unlink (pad, peer);
722 gst_pad_unlink (peer, pad);
724 gst_object_unref (peer);
727 gst_pad_set_pad_template (pad, NULL);
729 GST_OBJECT_LOCK (pad);
731 GST_OBJECT_UNLOCK (pad);
733 g_hook_list_clear (&pad->probes);
735 G_OBJECT_CLASS (parent_class)->dispose (object);
739 gst_pad_finalize (GObject * object)
741 GstPad *pad = GST_PAD_CAST (object);
744 /* in case the task is still around, clean it up */
745 if ((task = GST_PAD_TASK (pad))) {
746 gst_task_join (task);
747 GST_PAD_TASK (pad) = NULL;
748 gst_object_unref (task);
751 if (pad->activatenotify)
752 pad->activatenotify (pad->activatedata);
753 if (pad->activatemodenotify)
754 pad->activatemodenotify (pad->activatemodedata);
756 pad->linknotify (pad->linkdata);
757 if (pad->unlinknotify)
758 pad->unlinknotify (pad->unlinkdata);
759 if (pad->chainnotify)
760 pad->chainnotify (pad->chaindata);
761 if (pad->chainlistnotify)
762 pad->chainlistnotify (pad->chainlistdata);
763 if (pad->getrangenotify)
764 pad->getrangenotify (pad->getrangedata);
765 if (pad->eventnotify)
766 pad->eventnotify (pad->eventdata);
767 if (pad->querynotify)
768 pad->querynotify (pad->querydata);
769 if (pad->iterintlinknotify)
770 pad->iterintlinknotify (pad->iterintlinkdata);
772 g_rec_mutex_clear (&pad->stream_rec_lock);
773 g_cond_clear (&pad->block_cond);
774 g_cond_clear (&pad->priv->activation_cond);
775 g_array_free (pad->priv->events, TRUE);
777 G_OBJECT_CLASS (parent_class)->finalize (object);
781 gst_pad_set_property (GObject * object, guint prop_id,
782 const GValue * value, GParamSpec * pspec)
784 g_return_if_fail (GST_IS_PAD (object));
787 case PAD_PROP_DIRECTION:
788 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
790 case PAD_PROP_TEMPLATE:
791 gst_pad_set_pad_template (GST_PAD_CAST (object),
792 (GstPadTemplate *) g_value_get_object (value));
794 case PAD_PROP_OFFSET:
795 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
798 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
804 gst_pad_get_property (GObject * object, guint prop_id,
805 GValue * value, GParamSpec * pspec)
807 g_return_if_fail (GST_IS_PAD (object));
811 GST_OBJECT_LOCK (object);
812 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
813 GST_OBJECT_UNLOCK (object);
815 case PAD_PROP_DIRECTION:
816 g_value_set_enum (value, GST_PAD_DIRECTION (object));
818 case PAD_PROP_TEMPLATE:
819 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
821 case PAD_PROP_OFFSET:
822 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
825 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
832 * @name: (allow-none): the name of the new pad.
833 * @direction: the #GstPadDirection of the pad.
835 * Creates a new pad with the given name in the given direction.
836 * If name is %NULL, a guaranteed unique name (across all pads)
838 * This function makes a copy of the name so you can safely free the name.
840 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
846 gst_pad_new (const gchar * name, GstPadDirection direction)
848 return g_object_new (GST_TYPE_PAD,
849 "name", name, "direction", direction, NULL);
853 * gst_pad_new_from_template:
854 * @templ: the pad template to use
855 * @name: (allow-none): the name of the pad
857 * Creates a new pad with the given name from the given template.
858 * If name is %NULL, a guaranteed unique name (across all pads)
860 * This function makes a copy of the name so you can safely free the name.
862 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
866 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
869 GST_PAD_TEMPLATE_GTYPE (templ) ==
870 G_TYPE_NONE ? GST_TYPE_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
872 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
874 return g_object_new (pad_type,
875 "name", name, "direction", templ->direction, "template", templ, NULL);
879 * gst_pad_new_from_static_template:
880 * @templ: the #GstStaticPadTemplate to use
881 * @name: the name of the pad
883 * Creates a new pad with the given name from the given static template.
884 * If name is %NULL, a guaranteed unique name (across all pads)
886 * This function makes a copy of the name so you can safely free the name.
888 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
892 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
896 GstPadTemplate *template;
898 template = gst_static_pad_template_get (templ);
899 pad = gst_pad_new_from_template (template, name);
900 gst_object_unref (template);
904 #define ACQUIRE_PARENT(pad, parent, label) \
906 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
907 gst_object_ref (parent); \
908 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
912 #define RELEASE_PARENT(parent) \
914 if (G_LIKELY (parent)) \
915 gst_object_unref (parent); \
919 * gst_pad_get_direction:
920 * @pad: a #GstPad to get the direction of.
922 * Gets the direction of the pad. The direction of the pad is
923 * decided at construction time so this function does not take
926 * Returns: the #GstPadDirection of the pad.
931 gst_pad_get_direction (GstPad * pad)
933 GstPadDirection result;
935 /* PAD_UNKNOWN is a little silly but we need some sort of
936 * error return value */
937 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
939 result = GST_PAD_DIRECTION (pad);
945 gst_pad_activate_default (GstPad * pad, GstObject * parent)
947 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
949 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
953 * gst_pad_mode_get_name:
954 * @mode: the pad mode
956 * Return the name of a pad mode, for use in debug messages mostly.
958 * Returns: short mnemonic for pad mode @mode
961 gst_pad_mode_get_name (GstPadMode mode)
964 case GST_PAD_MODE_NONE:
966 case GST_PAD_MODE_PUSH:
968 case GST_PAD_MODE_PULL:
976 /* Returns TRUE if pad wasn't already in the new_mode */
978 pre_activate (GstPad * pad, GstPadMode new_mode)
981 case GST_PAD_MODE_NONE:
982 GST_OBJECT_LOCK (pad);
983 while (G_UNLIKELY (pad->priv->in_activation))
984 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
985 if (new_mode == GST_PAD_MODE (pad)) {
986 GST_WARNING_OBJECT (pad,
987 "Pad is already in the process of being deactivated");
988 GST_OBJECT_UNLOCK (pad);
991 pad->priv->in_activation = TRUE;
992 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
993 GST_PAD_SET_FLUSHING (pad);
994 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
995 GST_PAD_MODE (pad) = new_mode;
996 /* unlock blocked pads so element can resume and stop */
997 GST_PAD_BLOCK_BROADCAST (pad);
998 GST_OBJECT_UNLOCK (pad);
1000 case GST_PAD_MODE_PUSH:
1001 case GST_PAD_MODE_PULL:
1002 GST_OBJECT_LOCK (pad);
1003 while (G_UNLIKELY (pad->priv->in_activation))
1004 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
1005 if (new_mode == GST_PAD_MODE (pad)) {
1006 GST_WARNING_OBJECT (pad,
1007 "Pad is already in the process of being activated");
1008 GST_OBJECT_UNLOCK (pad);
1011 pad->priv->in_activation = TRUE;
1012 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1013 gst_pad_mode_get_name (new_mode));
1014 GST_PAD_UNSET_FLUSHING (pad);
1015 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1016 GST_PAD_MODE (pad) = new_mode;
1017 if (GST_PAD_IS_SINK (pad)) {
1019 /* make sure the peer src pad sends us all events */
1020 if ((peer = GST_PAD_PEER (pad))) {
1021 gst_object_ref (peer);
1022 GST_OBJECT_UNLOCK (pad);
1024 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1025 GST_DEBUG_PAD_NAME (peer));
1027 GST_OBJECT_LOCK (peer);
1028 schedule_events (peer, NULL);
1029 GST_OBJECT_UNLOCK (peer);
1031 gst_object_unref (peer);
1033 GST_OBJECT_UNLOCK (pad);
1036 GST_OBJECT_UNLOCK (pad);
1044 post_activate (GstPad * pad, GstPadMode new_mode)
1047 case GST_PAD_MODE_NONE:
1048 GST_OBJECT_LOCK (pad);
1049 pad->priv->in_activation = FALSE;
1050 g_cond_broadcast (&pad->priv->activation_cond);
1051 GST_OBJECT_UNLOCK (pad);
1053 /* ensures that streaming stops */
1054 GST_PAD_STREAM_LOCK (pad);
1055 GST_DEBUG_OBJECT (pad, "stopped streaming");
1056 GST_OBJECT_LOCK (pad);
1057 remove_events (pad);
1058 GST_OBJECT_UNLOCK (pad);
1059 GST_PAD_STREAM_UNLOCK (pad);
1061 case GST_PAD_MODE_PUSH:
1062 case GST_PAD_MODE_PULL:
1063 GST_OBJECT_LOCK (pad);
1064 pad->priv->in_activation = FALSE;
1065 g_cond_broadcast (&pad->priv->activation_cond);
1066 GST_OBJECT_UNLOCK (pad);
1073 * gst_pad_set_active:
1074 * @pad: the #GstPad to activate or deactivate.
1075 * @active: whether or not the pad should be active.
1077 * Activates or deactivates the given pad.
1078 * Normally called from within core state change functions.
1080 * If @active, makes sure the pad is active. If it is already active, either in
1081 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1082 * function to perform the actual activation.
1084 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1085 * and a %FALSE argument.
1087 * Returns: %TRUE if the operation was successful.
1092 gst_pad_set_active (GstPad * pad, gboolean active)
1096 gboolean ret = FALSE;
1098 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1100 GST_OBJECT_LOCK (pad);
1101 old = GST_PAD_MODE (pad);
1102 ACQUIRE_PARENT (pad, parent, no_parent);
1103 GST_OBJECT_UNLOCK (pad);
1106 if (old == GST_PAD_MODE_NONE) {
1107 GST_DEBUG_OBJECT (pad, "activating pad from none");
1108 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1110 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1112 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1113 gst_pad_mode_get_name (old));
1117 if (old == GST_PAD_MODE_NONE) {
1118 GST_DEBUG_OBJECT (pad, "pad was inactive");
1121 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1122 gst_pad_mode_get_name (old));
1123 ret = activate_mode_internal (pad, parent, old, FALSE);
1125 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1129 RELEASE_PARENT (parent);
1131 if (G_UNLIKELY (!ret))
1139 GST_DEBUG_OBJECT (pad, "no parent");
1140 GST_OBJECT_UNLOCK (pad);
1145 GST_OBJECT_LOCK (pad);
1147 g_critical ("Failed to deactivate pad %s:%s, very bad",
1148 GST_DEBUG_PAD_NAME (pad));
1150 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1152 GST_OBJECT_UNLOCK (pad);
1158 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1161 gboolean res = FALSE;
1162 GstPadMode old, new;
1163 GstPadDirection dir;
1166 GST_OBJECT_LOCK (pad);
1167 old = GST_PAD_MODE (pad);
1168 dir = GST_PAD_DIRECTION (pad);
1169 GST_OBJECT_UNLOCK (pad);
1171 new = active ? mode : GST_PAD_MODE_NONE;
1176 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1177 /* pad was activate in the wrong direction, deactivate it
1178 * and reactivate it in the requested mode */
1179 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1180 gst_pad_mode_get_name (old));
1182 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1183 goto deactivate_failed;
1184 old = GST_PAD_MODE_NONE;
1188 case GST_PAD_MODE_PULL:
1190 if (dir == GST_PAD_SINK) {
1191 if ((peer = gst_pad_get_peer (pad))) {
1192 GST_DEBUG_OBJECT (pad, "calling peer");
1193 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1195 gst_object_unref (peer);
1197 /* there is no peer, this is only fatal when we activate. When we
1198 * deactivate, we must assume the application has unlinked the peer and
1199 * will deactivate it eventually. */
1203 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1206 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1207 goto failure; /* Can't activate pull on a src without a
1208 getrange function */
1216 /* Mark pad as needing reconfiguration */
1218 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1220 /* pre_activate returns TRUE if we weren't already in the process of
1221 * switching to the 'new' mode */
1222 if (pre_activate (pad, new)) {
1224 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1225 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1229 /* can happen for sinks of passthrough elements */
1232 post_activate (pad, new);
1235 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1236 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1241 /* Clear sticky flags on deactivation */
1243 GST_OBJECT_LOCK (pad);
1244 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1245 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1246 GST_OBJECT_UNLOCK (pad);
1254 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1255 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1260 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1261 "failed to %s in switch to %s mode from %s mode",
1262 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1263 gst_pad_mode_get_name (old));
1268 GST_OBJECT_LOCK (peer);
1269 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1270 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1271 GST_OBJECT_UNLOCK (peer);
1272 gst_object_unref (peer);
1277 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1278 "pad in pull mode");
1283 GST_OBJECT_LOCK (pad);
1284 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1285 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1286 GST_PAD_SET_FLUSHING (pad);
1287 GST_PAD_MODE (pad) = old;
1288 pad->priv->in_activation = FALSE;
1289 g_cond_broadcast (&pad->priv->activation_cond);
1290 GST_OBJECT_UNLOCK (pad);
1296 * gst_pad_activate_mode:
1297 * @pad: the #GstPad to activate or deactivate.
1298 * @mode: the requested activation mode
1299 * @active: whether or not the pad should be active.
1301 * Activates or deactivates the given pad in @mode via dispatching to the
1302 * pad's activatemodefunc. For use from within pad activation functions only.
1304 * If you don't know what this is, you probably don't want to call it.
1306 * Returns: %TRUE if the operation was successful.
1311 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1315 GstPadMode old, new;
1317 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1319 GST_OBJECT_LOCK (pad);
1321 old = GST_PAD_MODE (pad);
1322 new = active ? mode : GST_PAD_MODE_NONE;
1326 ACQUIRE_PARENT (pad, parent, no_parent);
1328 GST_OBJECT_UNLOCK (pad);
1330 res = activate_mode_internal (pad, parent, mode, active);
1332 RELEASE_PARENT (parent);
1338 GST_OBJECT_UNLOCK (pad);
1339 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1340 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1345 GST_WARNING_OBJECT (pad, "no parent");
1346 GST_OBJECT_UNLOCK (pad);
1352 * gst_pad_is_active:
1353 * @pad: the #GstPad to query
1355 * Query if a pad is active
1357 * Returns: %TRUE if the pad is active.
1362 gst_pad_is_active (GstPad * pad)
1364 gboolean result = FALSE;
1366 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1368 GST_OBJECT_LOCK (pad);
1369 result = GST_PAD_IS_ACTIVE (pad);
1370 GST_OBJECT_UNLOCK (pad);
1376 cleanup_hook (GstPad * pad, GHook * hook)
1378 GstPadProbeType type;
1380 if (!G_HOOK_IS_VALID (hook))
1383 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1385 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1386 /* unblock when we remove the last blocking probe */
1388 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1391 /* Might have new probes now that want to be called */
1392 GST_PAD_BLOCK_BROADCAST (pad);
1394 if (pad->num_blocked == 0) {
1395 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1396 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1399 g_hook_destroy_link (&pad->probes, hook);
1404 * gst_pad_add_probe:
1405 * @pad: the #GstPad to add the probe to
1406 * @mask: the probe mask
1407 * @callback: #GstPadProbeCallback that will be called with notifications of
1409 * @user_data: (closure): user data passed to the callback
1410 * @destroy_data: #GDestroyNotify for user_data
1412 * Be notified of different states of pads. The provided callback is called for
1413 * every state that matches @mask.
1415 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1416 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1417 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1418 * immediately if the pad is already idle while calling gst_pad_add_probe().
1419 * In each of the groups, probes are called in the order in which they were
1422 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1423 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1424 * happen that the probe can be run immediately and if the probe returns
1425 * GST_PAD_PROBE_REMOVE this functions returns 0.
1430 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1431 GstPadProbeCallback callback, gpointer user_data,
1432 GDestroyNotify destroy_data)
1437 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1438 g_return_val_if_fail (mask != 0, 0);
1440 GST_OBJECT_LOCK (pad);
1442 /* make a new probe */
1443 hook = g_hook_alloc (&pad->probes);
1445 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1448 /* when no constraints are given for the types, assume all types are
1450 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1451 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1452 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1453 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1455 /* store our flags and other fields */
1456 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1457 hook->func = callback;
1458 hook->data = user_data;
1459 hook->destroy = destroy_data;
1462 g_hook_append (&pad->probes, hook);
1464 /* incremenent cookie so that the new hook gets called */
1465 pad->priv->probe_list_cookie++;
1467 /* get the id of the hook, we return this and it can be used to remove the
1469 res = hook->hook_id;
1471 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1473 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1474 /* we have a block probe */
1476 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1477 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1478 "now %d blocking probes", pad->num_blocked);
1480 /* Might have new probes now that want to be called */
1481 GST_PAD_BLOCK_BROADCAST (pad);
1484 /* call the callback if we need to be called for idle callbacks */
1485 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1486 if (pad->priv->using > 0) {
1487 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1488 * flag above, the last thread to leave the push will do the callback. New
1489 * threads going into the push will block. */
1490 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1491 "pad is in use, delay idle callback");
1492 GST_OBJECT_UNLOCK (pad);
1494 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1495 GstPadProbeReturn ret;
1497 /* Keep another ref, the callback could destroy the pad */
1498 gst_object_ref (pad);
1499 pad->priv->idle_running++;
1501 /* the pad is idle now, we can signal the idle callback now */
1502 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1503 "pad is idle, trigger idle callback");
1504 GST_OBJECT_UNLOCK (pad);
1506 ret = callback (pad, &info, user_data);
1508 GST_OBJECT_LOCK (pad);
1510 case GST_PAD_PROBE_REMOVE:
1511 /* remove the probe */
1512 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1513 cleanup_hook (pad, hook);
1516 case GST_PAD_PROBE_DROP:
1517 GST_DEBUG_OBJECT (pad, "asked to drop item");
1519 case GST_PAD_PROBE_PASS:
1520 GST_DEBUG_OBJECT (pad, "asked to pass item");
1522 case GST_PAD_PROBE_OK:
1523 GST_DEBUG_OBJECT (pad, "probe returned OK");
1525 case GST_PAD_PROBE_HANDLED:
1526 GST_DEBUG_OBJECT (pad, "probe handled the data");
1529 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1532 pad->priv->idle_running--;
1533 if (pad->priv->idle_running == 0) {
1534 GST_PAD_BLOCK_BROADCAST (pad);
1536 GST_OBJECT_UNLOCK (pad);
1538 gst_object_unref (pad);
1541 GST_OBJECT_UNLOCK (pad);
1547 * gst_pad_remove_probe:
1548 * @pad: the #GstPad with the probe
1549 * @id: the probe id to remove
1551 * Remove the probe with @id from @pad.
1556 gst_pad_remove_probe (GstPad * pad, gulong id)
1560 g_return_if_fail (GST_IS_PAD (pad));
1562 GST_OBJECT_LOCK (pad);
1564 hook = g_hook_get (&pad->probes, id);
1568 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1570 cleanup_hook (pad, hook);
1571 GST_OBJECT_UNLOCK (pad);
1577 GST_OBJECT_UNLOCK (pad);
1578 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1584 * gst_pad_is_blocked:
1585 * @pad: the #GstPad to query
1587 * Checks if the pad is blocked or not. This function returns the
1588 * last requested state of the pad. It is not certain that the pad
1589 * is actually blocking at this point (see gst_pad_is_blocking()).
1591 * Returns: %TRUE if the pad is blocked.
1596 gst_pad_is_blocked (GstPad * pad)
1598 gboolean result = FALSE;
1600 g_return_val_if_fail (GST_IS_PAD (pad), result);
1602 GST_OBJECT_LOCK (pad);
1603 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1604 GST_OBJECT_UNLOCK (pad);
1610 * gst_pad_is_blocking:
1611 * @pad: the #GstPad to query
1613 * Checks if the pad is blocking or not. This is a guaranteed state
1614 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1616 * Returns: %TRUE if the pad is blocking.
1621 gst_pad_is_blocking (GstPad * pad)
1623 gboolean result = FALSE;
1625 g_return_val_if_fail (GST_IS_PAD (pad), result);
1627 GST_OBJECT_LOCK (pad);
1628 /* the blocking flag is only valid if the pad is not flushing */
1629 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1630 GST_OBJECT_UNLOCK (pad);
1636 * gst_pad_needs_reconfigure:
1637 * @pad: the #GstPad to check
1639 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1640 * if the flag was set.
1642 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1645 gst_pad_needs_reconfigure (GstPad * pad)
1647 gboolean reconfigure;
1649 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1651 GST_OBJECT_LOCK (pad);
1652 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1653 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1654 GST_OBJECT_UNLOCK (pad);
1660 * gst_pad_check_reconfigure:
1661 * @pad: the #GstPad to check
1663 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1664 * if the flag was set.
1666 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1669 gst_pad_check_reconfigure (GstPad * pad)
1671 gboolean reconfigure;
1673 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1675 GST_OBJECT_LOCK (pad);
1676 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1678 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1679 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1681 GST_OBJECT_UNLOCK (pad);
1687 * gst_pad_mark_reconfigure:
1688 * @pad: the #GstPad to mark
1690 * Mark a pad for needing reconfiguration. The next call to
1691 * gst_pad_check_reconfigure() will return %TRUE after this call.
1694 gst_pad_mark_reconfigure (GstPad * pad)
1696 g_return_if_fail (GST_IS_PAD (pad));
1698 GST_OBJECT_LOCK (pad);
1699 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1700 GST_OBJECT_UNLOCK (pad);
1704 * gst_pad_set_activate_function:
1706 * @f: the #GstPadActivateFunction to set.
1708 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1712 * gst_pad_set_activate_function_full:
1714 * @activate: the #GstPadActivateFunction to set.
1715 * @user_data: user_data passed to @notify
1716 * @notify: notify called when @activate will not be used anymore.
1718 * Sets the given activate function for @pad. The activate function will
1719 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1720 * Only makes sense to set on sink pads.
1722 * Call this function if your sink pad can start a pull-based task.
1725 gst_pad_set_activate_function_full (GstPad * pad,
1726 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1728 g_return_if_fail (GST_IS_PAD (pad));
1730 if (pad->activatenotify)
1731 pad->activatenotify (pad->activatedata);
1732 GST_PAD_ACTIVATEFUNC (pad) = activate;
1733 pad->activatedata = user_data;
1734 pad->activatenotify = notify;
1736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1737 GST_DEBUG_FUNCPTR_NAME (activate));
1741 * gst_pad_set_activatemode_function:
1743 * @f: the #GstPadActivateModeFunction to set.
1745 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1749 * gst_pad_set_activatemode_function_full:
1751 * @activatemode: the #GstPadActivateModeFunction to set.
1752 * @user_data: user_data passed to @notify
1753 * @notify: notify called when @activatemode will not be used anymore.
1755 * Sets the given activate_mode function for the pad. An activate_mode function
1756 * prepares the element for data passing.
1759 gst_pad_set_activatemode_function_full (GstPad * pad,
1760 GstPadActivateModeFunction activatemode, gpointer user_data,
1761 GDestroyNotify notify)
1763 g_return_if_fail (GST_IS_PAD (pad));
1765 if (pad->activatemodenotify)
1766 pad->activatemodenotify (pad->activatemodedata);
1767 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1768 pad->activatemodedata = user_data;
1769 pad->activatemodenotify = notify;
1771 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1772 GST_DEBUG_FUNCPTR_NAME (activatemode));
1776 * gst_pad_set_chain_function:
1777 * @p: a sink #GstPad.
1778 * @f: the #GstPadChainFunction to set.
1780 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1784 * gst_pad_set_chain_function_full:
1785 * @pad: a sink #GstPad.
1786 * @chain: the #GstPadChainFunction to set.
1787 * @user_data: user_data passed to @notify
1788 * @notify: notify called when @chain will not be used anymore.
1790 * Sets the given chain function for the pad. The chain function is called to
1791 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1794 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1795 gpointer user_data, GDestroyNotify notify)
1797 g_return_if_fail (GST_IS_PAD (pad));
1798 g_return_if_fail (GST_PAD_IS_SINK (pad));
1800 if (pad->chainnotify)
1801 pad->chainnotify (pad->chaindata);
1802 GST_PAD_CHAINFUNC (pad) = chain;
1803 pad->chaindata = user_data;
1804 pad->chainnotify = notify;
1806 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1807 GST_DEBUG_FUNCPTR_NAME (chain));
1811 * gst_pad_set_chain_list_function:
1812 * @p: a sink #GstPad.
1813 * @f: the #GstPadChainListFunction to set.
1815 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1819 * gst_pad_set_chain_list_function_full:
1820 * @pad: a sink #GstPad.
1821 * @chainlist: the #GstPadChainListFunction to set.
1822 * @user_data: user_data passed to @notify
1823 * @notify: notify called when @chainlist will not be used anymore.
1825 * Sets the given chain list function for the pad. The chainlist function is
1826 * called to process a #GstBufferList input buffer list. See
1827 * #GstPadChainListFunction for more details.
1830 gst_pad_set_chain_list_function_full (GstPad * pad,
1831 GstPadChainListFunction chainlist, gpointer user_data,
1832 GDestroyNotify notify)
1834 g_return_if_fail (GST_IS_PAD (pad));
1835 g_return_if_fail (GST_PAD_IS_SINK (pad));
1837 if (pad->chainlistnotify)
1838 pad->chainlistnotify (pad->chainlistdata);
1839 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1840 pad->chainlistdata = user_data;
1841 pad->chainlistnotify = notify;
1843 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1844 GST_DEBUG_FUNCPTR_NAME (chainlist));
1848 * gst_pad_set_getrange_function:
1849 * @p: a source #GstPad.
1850 * @f: the #GstPadGetRangeFunction to set.
1852 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1856 * gst_pad_set_getrange_function_full:
1857 * @pad: a source #GstPad.
1858 * @get: the #GstPadGetRangeFunction to set.
1859 * @user_data: user_data passed to @notify
1860 * @notify: notify called when @get will not be used anymore.
1862 * Sets the given getrange function for the pad. The getrange function is
1863 * called to produce a new #GstBuffer to start the processing pipeline. see
1864 * #GstPadGetRangeFunction for a description of the getrange function.
1867 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1868 gpointer user_data, GDestroyNotify notify)
1870 g_return_if_fail (GST_IS_PAD (pad));
1871 g_return_if_fail (GST_PAD_IS_SRC (pad));
1873 if (pad->getrangenotify)
1874 pad->getrangenotify (pad->getrangedata);
1875 GST_PAD_GETRANGEFUNC (pad) = get;
1876 pad->getrangedata = user_data;
1877 pad->getrangenotify = notify;
1879 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1880 GST_DEBUG_FUNCPTR_NAME (get));
1884 * gst_pad_set_event_function:
1885 * @p: a #GstPad of either direction.
1886 * @f: the #GstPadEventFunction to set.
1888 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1892 * gst_pad_set_event_function_full:
1893 * @pad: a #GstPad of either direction.
1894 * @event: the #GstPadEventFunction to set.
1895 * @user_data: user_data passed to @notify
1896 * @notify: notify called when @event will not be used anymore.
1898 * Sets the given event handler for the pad.
1901 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1902 gpointer user_data, GDestroyNotify notify)
1904 g_return_if_fail (GST_IS_PAD (pad));
1906 if (pad->eventnotify)
1907 pad->eventnotify (pad->eventdata);
1908 GST_PAD_EVENTFUNC (pad) = event;
1909 pad->eventdata = user_data;
1910 pad->eventnotify = notify;
1912 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1913 GST_DEBUG_FUNCPTR_NAME (event));
1917 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1921 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1922 if (ret == GST_FLOW_OK)
1928 * gst_pad_set_event_full_function:
1929 * @p: a #GstPad of either direction.
1930 * @f: the #GstPadEventFullFunction to set.
1932 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1936 * gst_pad_set_event_full_function_full:
1937 * @pad: a #GstPad of either direction.
1938 * @event: the #GstPadEventFullFunction to set.
1939 * @user_data: user_data passed to @notify
1940 * @notify: notify called when @event will not be used anymore.
1942 * Sets the given event handler for the pad.
1947 gst_pad_set_event_full_function_full (GstPad * pad,
1948 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1950 g_return_if_fail (GST_IS_PAD (pad));
1952 if (pad->eventnotify)
1953 pad->eventnotify (pad->eventdata);
1954 GST_PAD_EVENTFULLFUNC (pad) = event;
1955 GST_PAD_EVENTFUNC (pad) = event_wrap;
1956 pad->eventdata = user_data;
1957 pad->eventnotify = notify;
1959 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1960 GST_DEBUG_FUNCPTR_NAME (event));
1964 * gst_pad_set_query_function:
1965 * @p: a #GstPad of either direction.
1966 * @f: the #GstPadQueryFunction to set.
1968 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1972 * gst_pad_set_query_function_full:
1973 * @pad: a #GstPad of either direction.
1974 * @query: the #GstPadQueryFunction to set.
1975 * @user_data: user_data passed to @notify
1976 * @notify: notify called when @query will not be used anymore.
1978 * Set the given query function for the pad.
1981 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1982 gpointer user_data, GDestroyNotify notify)
1984 g_return_if_fail (GST_IS_PAD (pad));
1986 if (pad->querynotify)
1987 pad->querynotify (pad->querydata);
1988 GST_PAD_QUERYFUNC (pad) = query;
1989 pad->querydata = user_data;
1990 pad->querynotify = notify;
1992 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1993 GST_DEBUG_FUNCPTR_NAME (query));
1997 * gst_pad_set_iterate_internal_links_function:
1998 * @p: a #GstPad of either direction.
1999 * @f: the #GstPadIterIntLinkFunction to set.
2001 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
2002 * for the user_data and notify.
2005 * gst_pad_set_iterate_internal_links_function_full:
2006 * @pad: a #GstPad of either direction.
2007 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2008 * @user_data: user_data passed to @notify
2009 * @notify: notify called when @iterintlink will not be used anymore.
2011 * Sets the given internal link iterator function for the pad.
2014 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2015 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2016 GDestroyNotify notify)
2018 g_return_if_fail (GST_IS_PAD (pad));
2020 if (pad->iterintlinknotify)
2021 pad->iterintlinknotify (pad->iterintlinkdata);
2022 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2023 pad->iterintlinkdata = user_data;
2024 pad->iterintlinknotify = notify;
2026 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2027 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2031 * gst_pad_set_link_function:
2033 * @f: the #GstPadLinkFunction to set.
2035 * Calls gst_pad_set_link_function_full() with %NULL
2036 * for the user_data and notify.
2039 * gst_pad_set_link_function_full:
2041 * @link: the #GstPadLinkFunction to set.
2042 * @user_data: user_data passed to @notify
2043 * @notify: notify called when @link will not be used anymore.
2045 * Sets the given link function for the pad. It will be called when
2046 * the pad is linked with another pad.
2048 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2051 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2052 * cannot be made for some reason.
2054 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2055 * of the peer sink pad, if present.
2058 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2059 gpointer user_data, GDestroyNotify notify)
2061 g_return_if_fail (GST_IS_PAD (pad));
2063 if (pad->linknotify)
2064 pad->linknotify (pad->linkdata);
2065 GST_PAD_LINKFUNC (pad) = link;
2066 pad->linkdata = user_data;
2067 pad->linknotify = notify;
2069 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2070 GST_DEBUG_FUNCPTR_NAME (link));
2074 * gst_pad_set_unlink_function:
2076 * @f: the #GstPadUnlinkFunction to set.
2078 * Calls gst_pad_set_unlink_function_full() with %NULL
2079 * for the user_data and notify.
2082 * gst_pad_set_unlink_function_full:
2084 * @unlink: the #GstPadUnlinkFunction to set.
2085 * @user_data: user_data passed to @notify
2086 * @notify: notify called when @unlink will not be used anymore.
2088 * Sets the given unlink function for the pad. It will be called
2089 * when the pad is unlinked.
2092 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2093 gpointer user_data, GDestroyNotify notify)
2095 g_return_if_fail (GST_IS_PAD (pad));
2097 if (pad->unlinknotify)
2098 pad->unlinknotify (pad->unlinkdata);
2099 GST_PAD_UNLINKFUNC (pad) = unlink;
2100 pad->unlinkdata = user_data;
2101 pad->unlinknotify = notify;
2103 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2104 GST_DEBUG_FUNCPTR_NAME (unlink));
2109 * @srcpad: the source #GstPad to unlink.
2110 * @sinkpad: the sink #GstPad to unlink.
2112 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2113 * signal on both pads.
2115 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2116 * the pads were not linked together.
2121 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2123 gboolean result = FALSE;
2124 GstElement *parent = NULL;
2126 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2127 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2128 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2129 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2131 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2133 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2134 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2135 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2137 /* We need to notify the parent before taking any pad locks as the bin in
2138 * question might be waiting for a lock on the pad while holding its lock
2139 * that our message will try to take. */
2140 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2141 if (GST_IS_ELEMENT (parent)) {
2142 gst_element_post_message (parent,
2143 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2144 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2146 gst_object_unref (parent);
2151 GST_OBJECT_LOCK (srcpad);
2152 GST_OBJECT_LOCK (sinkpad);
2154 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2155 goto not_linked_together;
2157 if (GST_PAD_UNLINKFUNC (srcpad)) {
2158 GstObject *tmpparent;
2160 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2162 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2163 RELEASE_PARENT (tmpparent);
2166 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2167 GstObject *tmpparent;
2169 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2171 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2172 RELEASE_PARENT (tmpparent);
2176 /* first clear peers */
2177 GST_PAD_PEER (srcpad) = NULL;
2178 GST_PAD_PEER (sinkpad) = NULL;
2180 GST_OBJECT_UNLOCK (sinkpad);
2181 GST_OBJECT_UNLOCK (srcpad);
2183 /* fire off a signal to each of the pads telling them
2184 * that they've been unlinked */
2185 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2186 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2188 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2189 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2194 if (parent != NULL) {
2195 gst_element_post_message (parent,
2196 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2197 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2198 gst_object_unref (parent);
2200 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2204 not_linked_together:
2206 /* we do not emit a warning in this case because unlinking cannot
2207 * be made MT safe.*/
2208 GST_OBJECT_UNLOCK (sinkpad);
2209 GST_OBJECT_UNLOCK (srcpad);
2215 * gst_pad_is_linked:
2216 * @pad: pad to check
2218 * Checks if a @pad is linked to another pad or not.
2220 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2225 gst_pad_is_linked (GstPad * pad)
2229 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2231 GST_OBJECT_LOCK (pad);
2232 result = (GST_PAD_PEER (pad) != NULL);
2233 GST_OBJECT_UNLOCK (pad);
2238 /* get the caps from both pads and see if the intersection
2241 * This function should be called with the pad LOCK on both
2245 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2246 GstPadLinkCheck flags)
2248 GstCaps *srccaps = NULL;
2249 GstCaps *sinkcaps = NULL;
2250 gboolean compatible = FALSE;
2252 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2255 /* Doing the expensive caps checking takes priority over only checking the template caps */
2256 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2257 GST_OBJECT_UNLOCK (sink);
2258 GST_OBJECT_UNLOCK (src);
2260 srccaps = gst_pad_query_caps (src, NULL);
2261 sinkcaps = gst_pad_query_caps (sink, NULL);
2263 GST_OBJECT_LOCK (src);
2264 GST_OBJECT_LOCK (sink);
2266 /* If one of the two pads doesn't have a template, consider the intersection
2268 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2269 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2273 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2275 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2278 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2280 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2283 /* if we have caps on both pads we can check the intersection. If one
2284 * of the caps is %NULL, we return %TRUE. */
2285 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2287 gst_caps_unref (srccaps);
2289 gst_caps_unref (sinkcaps);
2293 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2294 gst_caps_unref (srccaps);
2295 gst_caps_unref (sinkcaps);
2298 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2299 (compatible ? "" : "not "));
2304 /* check if the grandparents of both pads are the same.
2305 * This check is required so that we don't try to link
2306 * pads from elements in different bins without ghostpads.
2308 * The LOCK should be held on both pads
2311 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2313 GstObject *psrc, *psink;
2315 psrc = GST_OBJECT_PARENT (src);
2316 psink = GST_OBJECT_PARENT (sink);
2318 /* if one of the pads has no parent, we allow the link */
2319 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2322 /* only care about parents that are elements */
2323 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2324 goto no_element_parent;
2326 /* if the parents are the same, we have a loop */
2327 if (G_UNLIKELY (psrc == psink))
2330 /* if they both have a parent, we check the grandparents. We can not lock
2331 * the parent because we hold on the child (pad) and the locking order is
2332 * parent >> child. */
2333 psrc = GST_OBJECT_PARENT (psrc);
2334 psink = GST_OBJECT_PARENT (psink);
2336 /* if they have grandparents but they are not the same */
2337 if (G_UNLIKELY (psrc != psink))
2338 goto wrong_grandparents;
2345 GST_CAT_DEBUG (GST_CAT_CAPS,
2346 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2347 GST_PTR_FORMAT, psrc, psink);
2352 GST_CAT_DEBUG (GST_CAT_CAPS,
2353 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2354 GST_PTR_FORMAT, psrc, psink);
2359 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2365 GST_CAT_DEBUG (GST_CAT_CAPS,
2366 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2367 GST_PTR_FORMAT, psrc, psink);
2372 /* FIXME leftover from an attempt at refactoring... */
2373 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2374 * the two pads will be locked in the srcpad, sinkpad order. */
2375 static GstPadLinkReturn
2376 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2378 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2379 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2381 GST_OBJECT_LOCK (srcpad);
2383 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2384 goto src_was_linked;
2386 GST_OBJECT_LOCK (sinkpad);
2388 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2389 goto sink_was_linked;
2391 /* check hierarchy, pads can only be linked if the grandparents
2393 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2394 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2395 goto wrong_hierarchy;
2397 /* check pad caps for non-empty intersection */
2398 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2401 /* FIXME check pad scheduling for non-empty intersection */
2403 return GST_PAD_LINK_OK;
2407 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2408 GST_DEBUG_PAD_NAME (srcpad),
2409 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2410 /* we do not emit a warning in this case because unlinking cannot
2411 * be made MT safe.*/
2412 GST_OBJECT_UNLOCK (srcpad);
2413 return GST_PAD_LINK_WAS_LINKED;
2417 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2418 GST_DEBUG_PAD_NAME (sinkpad),
2419 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2420 /* we do not emit a warning in this case because unlinking cannot
2421 * be made MT safe.*/
2422 GST_OBJECT_UNLOCK (sinkpad);
2423 GST_OBJECT_UNLOCK (srcpad);
2424 return GST_PAD_LINK_WAS_LINKED;
2428 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2429 GST_OBJECT_UNLOCK (sinkpad);
2430 GST_OBJECT_UNLOCK (srcpad);
2431 return GST_PAD_LINK_WRONG_HIERARCHY;
2435 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2436 GST_OBJECT_UNLOCK (sinkpad);
2437 GST_OBJECT_UNLOCK (srcpad);
2438 return GST_PAD_LINK_NOFORMAT;
2444 * @srcpad: the source #GstPad.
2445 * @sinkpad: the sink #GstPad.
2447 * Checks if the source pad and the sink pad are compatible so they can be
2450 * Returns: %TRUE if the pads can be linked.
2453 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2455 GstPadLinkReturn result;
2457 /* generic checks */
2458 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2459 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2461 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2462 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2464 /* gst_pad_link_prepare does everything for us, we only release the locks
2465 * on the pads that it gets us. If this function returns !OK the locks are not
2467 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2468 if (result != GST_PAD_LINK_OK)
2471 GST_OBJECT_UNLOCK (srcpad);
2472 GST_OBJECT_UNLOCK (sinkpad);
2475 return result == GST_PAD_LINK_OK;
2479 * gst_pad_link_full:
2480 * @srcpad: the source #GstPad to link.
2481 * @sinkpad: the sink #GstPad to link.
2482 * @flags: the checks to validate when linking
2484 * Links the source pad and the sink pad.
2486 * This variant of #gst_pad_link provides a more granular control on the
2487 * checks being done when linking. While providing some considerable speedups
2488 * the caller of this method must be aware that wrong usage of those flags
2489 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2490 * for more information.
2494 * Returns: A result code indicating if the connection worked or
2498 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2500 GstPadLinkReturn result;
2502 GstPadLinkFunction srcfunc, sinkfunc;
2504 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2505 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2506 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2507 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2508 GST_PAD_LINK_WRONG_DIRECTION);
2510 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2512 /* Notify the parent early. See gst_pad_unlink for details. */
2513 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2514 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2515 gst_element_post_message (parent,
2516 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2517 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2519 gst_object_unref (parent);
2524 /* prepare will also lock the two pads */
2525 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2527 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2528 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2529 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2530 gst_pad_link_get_name (result));
2534 /* must set peers before calling the link function */
2535 GST_PAD_PEER (srcpad) = sinkpad;
2536 GST_PAD_PEER (sinkpad) = srcpad;
2538 /* check events, when something is different, mark pending */
2539 schedule_events (srcpad, sinkpad);
2541 /* get the link functions */
2542 srcfunc = GST_PAD_LINKFUNC (srcpad);
2543 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2545 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2546 /* custom link functions, execute them */
2547 GST_OBJECT_UNLOCK (sinkpad);
2548 GST_OBJECT_UNLOCK (srcpad);
2551 GstObject *tmpparent;
2553 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2554 /* this one will call the peer link function */
2555 result = srcfunc (srcpad, tmpparent, sinkpad);
2556 RELEASE_PARENT (tmpparent);
2557 } else if (sinkfunc) {
2558 GstObject *tmpparent;
2560 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2561 /* if no source link function, we need to call the sink link
2562 * function ourselves. */
2563 result = sinkfunc (sinkpad, tmpparent, srcpad);
2564 RELEASE_PARENT (tmpparent);
2568 GST_OBJECT_LOCK (srcpad);
2569 GST_OBJECT_LOCK (sinkpad);
2571 /* we released the lock, check if the same pads are linked still */
2572 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2573 goto concurrent_link;
2575 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2578 GST_OBJECT_UNLOCK (sinkpad);
2579 GST_OBJECT_UNLOCK (srcpad);
2581 /* fire off a signal to each of the pads telling them
2582 * that they've been linked */
2583 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2584 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2586 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2587 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2589 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2590 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2593 if (G_LIKELY (parent)) {
2594 gst_element_post_message (parent,
2595 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2596 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2597 gst_object_unref (parent);
2600 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2606 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2607 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2608 GST_OBJECT_UNLOCK (sinkpad);
2609 GST_OBJECT_UNLOCK (srcpad);
2611 /* The other link operation succeeded first */
2612 result = GST_PAD_LINK_WAS_LINKED;
2617 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2618 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2619 gst_pad_link_get_name (result));
2621 GST_PAD_PEER (srcpad) = NULL;
2622 GST_PAD_PEER (sinkpad) = NULL;
2624 GST_OBJECT_UNLOCK (sinkpad);
2625 GST_OBJECT_UNLOCK (srcpad);
2633 * @srcpad: the source #GstPad to link.
2634 * @sinkpad: the sink #GstPad to link.
2636 * Links the source pad and the sink pad.
2638 * Returns: A result code indicating if the connection worked or
2644 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2646 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2650 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2652 GstPadTemplate **template_p;
2654 /* this function would need checks if it weren't static */
2656 GST_OBJECT_LOCK (pad);
2657 template_p = &pad->padtemplate;
2658 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2659 GST_OBJECT_UNLOCK (pad);
2662 gst_pad_template_pad_created (templ, pad);
2666 * gst_pad_get_pad_template:
2669 * Gets the template for @pad.
2671 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2672 * this pad was instantiated, or %NULL if this pad has no
2673 * template. Unref after usage.
2676 gst_pad_get_pad_template (GstPad * pad)
2678 GstPadTemplate *templ;
2680 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2682 templ = GST_PAD_PAD_TEMPLATE (pad);
2684 return (templ ? gst_object_ref (templ) : NULL);
2688 * gst_pad_has_current_caps:
2689 * @pad: a #GstPad to check
2691 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2693 * Returns: %TRUE when @pad has caps associated with it.
2696 gst_pad_has_current_caps (GstPad * pad)
2701 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2703 GST_OBJECT_LOCK (pad);
2704 caps = get_pad_caps (pad);
2705 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2706 "check current pad caps %" GST_PTR_FORMAT, caps);
2707 result = (caps != NULL);
2708 GST_OBJECT_UNLOCK (pad);
2714 * gst_pad_get_current_caps:
2715 * @pad: a #GstPad to get the current capabilities of.
2717 * Gets the capabilities currently configured on @pad with the last
2718 * #GST_EVENT_CAPS event.
2720 * Returns: (transfer full) (nullable): the current caps of the pad with
2721 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2724 gst_pad_get_current_caps (GstPad * pad)
2728 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2730 GST_OBJECT_LOCK (pad);
2731 if ((result = get_pad_caps (pad)))
2732 gst_caps_ref (result);
2733 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2734 "get current pad caps %" GST_PTR_FORMAT, result);
2735 GST_OBJECT_UNLOCK (pad);
2741 * gst_pad_get_pad_template_caps:
2742 * @pad: a #GstPad to get the template capabilities from.
2744 * Gets the capabilities for @pad's template.
2746 * Returns: (transfer full): the #GstCaps of this pad template.
2747 * Unref after usage.
2750 gst_pad_get_pad_template_caps (GstPad * pad)
2752 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2754 if (GST_PAD_PAD_TEMPLATE (pad))
2755 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2757 return gst_caps_ref (GST_CAPS_ANY);
2762 * @pad: a #GstPad to get the peer of.
2764 * Gets the peer of @pad. This function refs the peer pad so
2765 * you need to unref it after use.
2767 * Returns: (transfer full) (nullable): the peer #GstPad. Unref after usage.
2772 gst_pad_get_peer (GstPad * pad)
2776 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2778 GST_OBJECT_LOCK (pad);
2779 result = GST_PAD_PEER (pad);
2781 gst_object_ref (result);
2782 GST_OBJECT_UNLOCK (pad);
2788 * gst_pad_get_allowed_caps:
2791 * Gets the capabilities of the allowed media types that can flow through
2792 * @pad and its peer.
2794 * The allowed capabilities is calculated as the intersection of the results of
2795 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2796 * on the resulting caps.
2798 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2799 * pad link. Unref the caps when you no longer need it. This
2800 * function returns %NULL when @pad has no peer.
2805 gst_pad_get_allowed_caps (GstPad * pad)
2808 GstCaps *caps = NULL;
2811 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2813 GST_OBJECT_LOCK (pad);
2814 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2816 GST_OBJECT_UNLOCK (pad);
2818 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2820 mycaps = gst_pad_query_caps (pad, NULL);
2822 /* Query peer caps */
2823 query = gst_query_new_caps (mycaps);
2824 if (!gst_pad_peer_query (pad, query)) {
2825 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2829 gst_query_parse_caps_result (query, &caps);
2831 g_warn_if_fail (caps != NULL);
2834 gst_caps_ref (caps);
2836 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2840 gst_query_unref (query);
2841 gst_caps_unref (mycaps);
2847 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2848 GST_OBJECT_UNLOCK (pad);
2855 * gst_pad_iterate_internal_links_default:
2856 * @pad: the #GstPad to get the internal links of.
2857 * @parent: (allow-none): the parent of @pad or %NULL
2859 * Iterate the list of pads to which the given pad is linked to inside of
2860 * the parent element.
2861 * This is the default handler, and thus returns an iterator of all of the
2862 * pads inside the parent element with opposite direction.
2864 * The caller must free this iterator after use with gst_iterator_free().
2866 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2867 * has no parent. Unref each returned pad with gst_object_unref().
2870 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2877 GstElement *eparent;
2879 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2881 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2882 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2884 GST_OBJECT_LOCK (pad);
2885 eparent = GST_PAD_PARENT (pad);
2886 if (!eparent || !GST_IS_ELEMENT (eparent))
2889 gst_object_ref (eparent);
2890 GST_OBJECT_UNLOCK (pad);
2893 if (pad->direction == GST_PAD_SRC)
2894 padlist = &eparent->sinkpads;
2896 padlist = &eparent->srcpads;
2898 GST_DEBUG_OBJECT (pad, "Making iterator");
2900 cookie = &eparent->pads_cookie;
2902 lock = GST_OBJECT_GET_LOCK (eparent);
2904 res = gst_iterator_new_list (GST_TYPE_PAD,
2905 lock, cookie, padlist, (GObject *) owner, NULL);
2907 gst_object_unref (owner);
2914 GST_OBJECT_UNLOCK (pad);
2915 GST_DEBUG_OBJECT (pad, "no parent element");
2921 * gst_pad_iterate_internal_links:
2922 * @pad: the GstPad to get the internal links of.
2924 * Gets an iterator for the pads to which the given pad is linked to inside
2925 * of the parent element.
2927 * Each #GstPad element yielded by the iterator will have its refcount increased,
2928 * so unref after use.
2930 * Free-function: gst_iterator_free
2932 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2933 * or %NULL when the pad does not have an iterator function
2934 * configured. Use gst_iterator_free() after usage.
2937 gst_pad_iterate_internal_links (GstPad * pad)
2939 GstIterator *res = NULL;
2942 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2944 GST_OBJECT_LOCK (pad);
2945 ACQUIRE_PARENT (pad, parent, no_parent);
2946 GST_OBJECT_UNLOCK (pad);
2948 if (GST_PAD_ITERINTLINKFUNC (pad))
2949 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2951 RELEASE_PARENT (parent);
2958 GST_DEBUG_OBJECT (pad, "no parent");
2959 GST_OBJECT_UNLOCK (pad);
2967 * @forward: (scope call): a #GstPadForwardFunction
2968 * @user_data: user data passed to @forward
2970 * Calls @forward for all internally linked pads of @pad. This function deals with
2971 * dynamically changing internal pads and will make sure that the @forward
2972 * function is only called once for each pad.
2974 * When @forward returns %TRUE, no further pads will be processed.
2976 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2979 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2982 gboolean result = FALSE;
2984 gboolean done = FALSE;
2985 GValue item = { 0, };
2986 GList *pushed_pads = NULL;
2988 iter = gst_pad_iterate_internal_links (pad);
2994 switch (gst_iterator_next (iter, &item)) {
2995 case GST_ITERATOR_OK:
2999 intpad = g_value_get_object (&item);
3001 /* if already pushed, skip. FIXME, find something faster to tag pads */
3002 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
3003 g_value_reset (&item);
3007 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3008 GST_DEBUG_PAD_NAME (intpad));
3009 done = result = forward (intpad, user_data);
3011 pushed_pads = g_list_prepend (pushed_pads, intpad);
3013 g_value_reset (&item);
3016 case GST_ITERATOR_RESYNC:
3017 /* We don't reset the result here because we don't push the event
3018 * again on pads that got the event already and because we need
3019 * to consider the result of the previous pushes */
3020 gst_iterator_resync (iter);
3022 case GST_ITERATOR_ERROR:
3023 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3026 case GST_ITERATOR_DONE:
3031 g_value_unset (&item);
3032 gst_iterator_free (iter);
3034 g_list_free (pushed_pads);
3044 gboolean dispatched;
3048 event_forward_func (GstPad * pad, EventData * data)
3050 /* for each pad we send to, we should ref the event; it's up
3051 * to downstream to unref again when handled. */
3052 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3053 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3055 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3057 data->dispatched = TRUE;
3064 * gst_pad_event_default:
3065 * @pad: a #GstPad to call the default event handler on.
3066 * @parent: (allow-none): the parent of @pad or %NULL
3067 * @event: (transfer full): the #GstEvent to handle.
3069 * Invokes the default event handler for the given pad.
3071 * The EOS event will pause the task associated with @pad before it is forwarded
3072 * to all internally linked pads,
3074 * The event is sent to all pads internally linked to @pad. This function
3075 * takes ownership of @event.
3077 * Returns: %TRUE if the event was sent successfully.
3080 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3082 gboolean result, forward = TRUE;
3084 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3085 g_return_val_if_fail (event != NULL, FALSE);
3087 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3090 switch (GST_EVENT_TYPE (event)) {
3091 case GST_EVENT_CAPS:
3092 forward = GST_PAD_IS_PROXY_CAPS (pad);
3103 data.dispatched = FALSE;
3104 data.result = FALSE;
3106 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3108 /* for sinkpads without a parent element or without internal links, nothing
3109 * will be dispatched but we still want to return TRUE. */
3110 if (data.dispatched)
3111 result = data.result;
3116 gst_event_unref (event);
3121 /* Default accept caps implementation just checks against
3122 * the allowed caps for the pad */
3124 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3126 /* get the caps and see if it intersects to something not empty */
3127 GstCaps *caps, *allowed = NULL;
3130 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3132 /* first forward the query to internally linked pads when we are dealing with
3134 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3135 result = gst_pad_proxy_query_accept_caps (pad, query);
3137 allowed = gst_pad_get_pad_template_caps (pad);
3142 gst_query_parse_accept_caps (query, &caps);
3144 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3145 allowed = gst_pad_get_pad_template_caps (pad);
3147 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3148 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3149 allowed = gst_pad_query_caps (pad, caps);
3154 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3155 GST_DEBUG_OBJECT (pad,
3156 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3158 result = gst_caps_can_intersect (caps, allowed);
3160 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3161 GST_PTR_FORMAT, allowed, caps);
3162 result = gst_caps_is_subset (caps, allowed);
3164 gst_caps_unref (allowed);
3166 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3169 gst_query_set_accept_caps_result (query, result);
3175 /* Default caps implementation */
3177 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3179 GstCaps *result = NULL, *filter;
3180 GstPadTemplate *templ;
3181 gboolean fixed_caps;
3183 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3186 /* first try to proxy if we must */
3187 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3188 if ((gst_pad_proxy_query_caps (pad, query))) {
3193 gst_query_parse_caps (query, &filter);
3195 /* no proxy or it failed, do default handling */
3196 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3198 GST_OBJECT_LOCK (pad);
3200 /* fixed caps, try the negotiated caps first */
3201 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3202 if ((result = get_pad_caps (pad)))
3203 goto filter_done_unlock;
3206 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3207 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3208 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3209 goto filter_done_unlock;
3213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3214 "non-fixed pad caps: trying pad caps");
3215 /* non fixed caps, try the negotiated caps */
3216 if ((result = get_pad_caps (pad)))
3217 goto filter_done_unlock;
3220 /* this almost never happens */
3221 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3222 result = GST_CAPS_ANY;
3225 GST_OBJECT_UNLOCK (pad);
3227 /* run the filter on the result */
3229 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3230 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3231 GST_PTR_FORMAT, result, result, filter, filter);
3232 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3233 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3236 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3237 "using caps %p %" GST_PTR_FORMAT, result, result);
3238 result = gst_caps_ref (result);
3240 gst_query_set_caps_result (query, result);
3241 gst_caps_unref (result);
3247 /* Default latency implementation */
3252 GstClockTime min, max;
3256 query_latency_default_fold (const GValue * item, GValue * ret,
3259 GstPad *pad = g_value_get_object (item), *peer;
3260 LatencyFoldData *fold_data = user_data;
3262 gboolean res = FALSE;
3264 query = gst_query_new_latency ();
3266 peer = gst_pad_get_peer (pad);
3268 res = gst_pad_peer_query (pad, query);
3270 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3275 GstClockTime min, max;
3277 gst_query_parse_latency (query, &live, &min, &max);
3279 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3280 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3282 /* FIXME : Why do we only take values into account if it's live ? */
3283 if (live || fold_data->count == 0) {
3284 if (min > fold_data->min)
3285 fold_data->min = min;
3287 if (fold_data->max == GST_CLOCK_TIME_NONE)
3288 fold_data->max = max;
3289 else if (max < fold_data->max)
3290 fold_data->max = max;
3292 fold_data->live = live;
3294 fold_data->count += 1;
3296 GST_DEBUG_OBJECT (pad, "latency query failed");
3297 g_value_set_boolean (ret, FALSE);
3300 gst_query_unref (query);
3302 gst_object_unref (peer);
3308 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3311 GstIteratorResult res;
3312 GValue ret = G_VALUE_INIT;
3314 LatencyFoldData fold_data;
3316 it = gst_pad_iterate_internal_links (pad);
3318 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3322 g_value_init (&ret, G_TYPE_BOOLEAN);
3325 fold_data.count = 0;
3326 fold_data.live = FALSE;
3328 fold_data.max = GST_CLOCK_TIME_NONE;
3330 g_value_set_boolean (&ret, TRUE);
3331 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3333 case GST_ITERATOR_OK:
3334 g_assert_not_reached ();
3336 case GST_ITERATOR_DONE:
3338 case GST_ITERATOR_ERROR:
3339 g_value_set_boolean (&ret, FALSE);
3341 case GST_ITERATOR_RESYNC:
3342 gst_iterator_resync (it);
3345 g_assert_not_reached ();
3348 gst_iterator_free (it);
3350 query_ret = g_value_get_boolean (&ret);
3352 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3353 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3354 fold_data.min, fold_data.max);
3356 if (fold_data.min > fold_data.max) {
3357 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3360 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3362 GST_LOG_OBJECT (pad, "latency query failed");
3372 gboolean dispatched;
3376 query_forward_func (GstPad * pad, QueryData * data)
3378 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3379 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3381 data->result |= gst_pad_peer_query (pad, data->query);
3383 data->dispatched = TRUE;
3385 /* stop on first successful reply */
3386 return data->result;
3390 * gst_pad_query_default:
3391 * @pad: a #GstPad to call the default query handler on.
3392 * @parent: (allow-none): the parent of @pad or %NULL
3393 * @query: (transfer none): the #GstQuery to handle.
3395 * Invokes the default query handler for the given pad.
3396 * The query is sent to all pads internally linked to @pad. Note that
3397 * if there are many possible sink pads that are internally linked to
3398 * @pad, only one will be sent the query.
3399 * Multi-sinkpad elements should implement custom query handlers.
3401 * Returns: %TRUE if the query was performed successfully.
3404 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3406 gboolean forward, ret = FALSE;
3408 switch (GST_QUERY_TYPE (query)) {
3409 case GST_QUERY_SCHEDULING:
3410 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3412 case GST_QUERY_ALLOCATION:
3413 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3415 case GST_QUERY_ACCEPT_CAPS:
3416 ret = gst_pad_query_accept_caps_default (pad, query);
3419 case GST_QUERY_CAPS:
3420 ret = gst_pad_query_caps_default (pad, query);
3423 case GST_QUERY_LATENCY:
3424 ret = gst_pad_query_latency_default (pad, query);
3427 case GST_QUERY_POSITION:
3428 case GST_QUERY_SEEKING:
3429 case GST_QUERY_FORMATS:
3430 case GST_QUERY_JITTER:
3431 case GST_QUERY_RATE:
3432 case GST_QUERY_CONVERT:
3438 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3439 query, GST_QUERY_TYPE_NAME (query));
3445 data.dispatched = FALSE;
3446 data.result = FALSE;
3448 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3450 if (data.dispatched) {
3453 /* nothing dispatched, assume drained */
3454 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3463 #define N_STACK_ALLOCATE_PROBES (16)
3466 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3468 GstPad *pad = data->pad;
3469 GstPadProbeInfo *info = data->info;
3470 GstPadProbeType type, flags;
3471 GstPadProbeCallback callback;
3472 GstPadProbeReturn ret;
3473 gpointer original_data;
3476 /* if we have called this callback, do nothing. But only check
3477 * if we're actually calling probes a second time */
3479 for (i = 0; i < data->n_called_probes; i++) {
3480 if (data->called_probes[i] == hook) {
3481 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3482 "hook %lu already called", hook->hook_id);
3488 /* reallocate on the heap if we had more than 16 probes */
3489 if (data->n_called_probes == data->called_probes_size) {
3490 if (data->called_probes_size > N_STACK_ALLOCATE_PROBES) {
3491 data->called_probes_size *= 2;
3492 data->called_probes =
3493 g_renew (GHook *, data->called_probes, data->called_probes_size);
3495 GHook **tmp = data->called_probes;
3497 data->called_probes_size *= 2;
3498 data->called_probes = g_new (GHook *, data->called_probes_size);
3499 memcpy (data->called_probes, tmp,
3500 N_STACK_ALLOCATE_PROBES * sizeof (GHook *));
3503 data->called_probes[data->n_called_probes++] = hook;
3505 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3507 original_data = info->data;
3509 /* one of the scheduling types */
3510 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3513 if (G_UNLIKELY (data->handled)) {
3514 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3515 "probe previously returned HANDLED, not calling again");
3517 } else if (G_UNLIKELY (data->dropped)) {
3518 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3519 "probe previously returned DROPPED, not calling again");
3523 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3524 /* one of the data types for non-idle probes */
3525 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3526 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3528 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3529 /* one of the data types for non-idle probes */
3530 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3531 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3534 /* Type must have PULL or PUSH probe types */
3535 g_assert_not_reached ();
3538 /* one of the blocking types must match */
3539 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3540 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3542 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3543 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3545 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3546 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3547 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3550 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3551 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3553 data->marshalled = TRUE;
3555 callback = (GstPadProbeCallback) hook->func;
3556 if (callback == NULL)
3559 info->id = hook->hook_id;
3561 GST_OBJECT_UNLOCK (pad);
3563 ret = callback (pad, info, hook->data);
3565 GST_OBJECT_LOCK (pad);
3567 if (original_data != NULL && info->data == NULL) {
3568 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3569 info->type = GST_PAD_PROBE_TYPE_INVALID;
3570 data->dropped = TRUE;
3574 case GST_PAD_PROBE_REMOVE:
3575 /* remove the probe */
3576 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3577 cleanup_hook (pad, hook);
3579 case GST_PAD_PROBE_DROP:
3580 /* need to drop the data, make sure other probes don't get called
3582 GST_DEBUG_OBJECT (pad, "asked to drop item");
3583 info->type = GST_PAD_PROBE_TYPE_INVALID;
3584 data->dropped = TRUE;
3586 case GST_PAD_PROBE_HANDLED:
3587 GST_DEBUG_OBJECT (pad, "probe handled data");
3588 data->handled = TRUE;
3590 case GST_PAD_PROBE_PASS:
3591 /* inform the pad block to let things pass */
3592 GST_DEBUG_OBJECT (pad, "asked to pass item");
3595 case GST_PAD_PROBE_OK:
3596 GST_DEBUG_OBJECT (pad, "probe returned OK");
3599 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3606 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3607 "hook %lu with flags 0x%08x does not match %08x",
3608 hook->hook_id, flags, info->type);
3613 /* a probe that does not take or return any data */
3614 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3616 if (G_UNLIKELY (pad->num_probes)) { \
3617 GstFlowReturn pval = defaultval; \
3618 /* pass NULL as the data item */ \
3619 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3620 info.ABI.abi.flow_ret = defaultval; \
3621 ret = do_probe_callbacks (pad, &info, defaultval); \
3622 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3627 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3629 if (G_UNLIKELY (pad->num_probes)) { \
3630 /* pass the data item */ \
3631 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3632 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3633 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3634 /* store the possibly updated data item */ \
3635 data = GST_PAD_PROBE_INFO_DATA (&info); \
3636 /* if something went wrong, exit */ \
3637 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3638 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3639 ret = info.ABI.abi.flow_ret; \
3640 goto handle_label; \
3647 #define PROBE_PUSH(pad,mask,data,label) \
3648 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3649 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3650 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3651 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3652 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3654 static GstFlowReturn
3655 do_pad_idle_probe_wait (GstPad * pad)
3657 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3658 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3659 "waiting idle probe to be removed");
3660 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3661 GST_PAD_BLOCK_WAIT (pad);
3662 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3663 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3665 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3666 return GST_FLOW_FLUSHING;
3671 #define PROBE_TYPE_IS_SERIALIZED(i) \
3674 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3675 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3676 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3678 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3679 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3681 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3682 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3686 static GstFlowReturn
3687 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3688 GstFlowReturn defaultval)
3693 GHook *called_probes[N_STACK_ALLOCATE_PROBES];
3698 data.handled = FALSE;
3699 data.marshalled = FALSE;
3700 data.dropped = FALSE;
3702 /* We stack-allocate for N_STACK_ALLOCATE_PROBES hooks as a first step. If more are needed,
3703 * we will re-allocate with g_malloc(). This should usually never be needed
3705 data.called_probes = called_probes;
3706 data.n_called_probes = 0;
3707 data.called_probes_size = N_STACK_ALLOCATE_PROBES;
3711 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3713 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3714 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3719 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "do probes");
3720 cookie = pad->priv->probe_list_cookie;
3722 g_hook_list_marshal (&pad->probes, TRUE,
3723 (GHookMarshaller) probe_hook_marshal, &data);
3725 /* if the list changed, call the new callbacks (they will not be in
3726 * called_probes yet) */
3727 if (cookie != pad->priv->probe_list_cookie) {
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "probe list changed, restarting");
3734 /* the first item that dropped will stop the hooks and then we drop here */
3738 /* If one handler took care of it, let the the item pass */
3743 /* if no handler matched and we are blocking, let the item pass */
3744 if (!data.marshalled && is_block)
3747 /* At this point, all handlers returned either OK or PASS. If one handler
3748 * returned PASS, let the item pass */
3753 while (GST_PAD_IS_BLOCKED (pad)) {
3754 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3755 "we are blocked %d times", pad->num_blocked);
3757 /* we might have released the lock */
3758 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3761 /* now we block the streaming thread. It can be unlocked when we
3762 * deactivate the pad (which will also set the FLUSHING flag) or
3763 * when the pad is unblocked. A flushing event will also unblock
3764 * the pad after setting the FLUSHING flag. */
3765 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3766 "Waiting to be unblocked or set flushing");
3767 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3768 GST_PAD_BLOCK_WAIT (pad);
3769 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3770 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3772 /* if the list changed, call the new callbacks (they will not be in
3773 * called_probes yet) */
3774 if (cookie != pad->priv->probe_list_cookie) {
3775 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3776 "probe list changed, restarting");
3781 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3786 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3787 g_free (data.called_probes);
3794 GST_DEBUG_OBJECT (pad, "pad is flushing");
3795 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3796 g_free (data.called_probes);
3797 return GST_FLOW_FLUSHING;
3801 GST_DEBUG_OBJECT (pad, "data is dropped");
3802 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3803 g_free (data.called_probes);
3804 return GST_FLOW_CUSTOM_SUCCESS;
3808 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3809 GST_DEBUG_OBJECT (pad, "data is passed");
3810 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3811 g_free (data.called_probes);
3816 GST_DEBUG_OBJECT (pad, "data was handled");
3817 if (data.called_probes_size > N_STACK_ALLOCATE_PROBES)
3818 g_free (data.called_probes);
3819 return GST_FLOW_CUSTOM_SUCCESS_1;
3826 * gst_pad_get_offset:
3829 * Get the offset applied to the running time of @pad. @pad has to be a source
3832 * Returns: the offset.
3835 gst_pad_get_offset (GstPad * pad)
3839 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3841 GST_OBJECT_LOCK (pad);
3842 result = pad->offset;
3843 GST_OBJECT_UNLOCK (pad);
3848 /* This function will make sure that previously set offset is
3849 * reverted as otherwise we would end up applying the new offset
3850 * on top of the previously set one, which is not what we want.
3851 * The event is also marked as not received. */
3853 reschedule_event (GstPad * pad, PadEvent * ev, gint64 * prev_offset)
3855 if (*prev_offset != 0)
3856 ev->event = _apply_pad_offset (pad, ev->event, -*prev_offset, FALSE);
3858 ev->received = FALSE;
3863 * gst_pad_set_offset:
3865 * @offset: the offset
3867 * Set the offset that will be applied to the running time of @pad.
3870 gst_pad_set_offset (GstPad * pad, gint64 offset)
3873 g_return_if_fail (GST_IS_PAD (pad));
3875 GST_OBJECT_LOCK (pad);
3876 /* if nothing changed, do nothing */
3877 if (pad->offset == offset)
3880 prev_offset = pad->offset;
3881 pad->offset = offset;
3882 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3883 GST_STIME_ARGS (offset));
3885 /* resend all sticky events with updated offset on next buffer push */
3886 events_foreach (pad, (PadEventFunction) reschedule_event, &prev_offset);
3887 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3891 GST_OBJECT_UNLOCK (pad);
3898 /* If TRUE and ret is not OK this means
3899 * that pushing the EOS event failed
3903 /* If called for an event this is
3904 * the event that would be pushed
3905 * next. Don't forward sticky events
3906 * that would come after that */
3910 /* should be called with pad LOCK */
3912 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3914 PushStickyData *data = user_data;
3915 GstEvent *event = ev->event;
3918 GST_DEBUG_OBJECT (pad, "event %s was already received",
3919 GST_EVENT_TYPE_NAME (event));
3923 /* If we're called because of an sticky event, only forward
3924 * events that would come before this new event and the
3926 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3927 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3928 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3929 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3931 gst_event_ref (event);
3932 data->ret = gst_pad_push_event_unchecked (pad, &event,
3933 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3934 gst_event_replace (&ev->event, event);
3935 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3936 data->ret = GST_FLOW_OK;
3939 switch (data->ret) {
3941 ev->received = TRUE;
3942 GST_DEBUG_OBJECT (pad, "event %s marked received",
3943 GST_EVENT_TYPE_NAME (event));
3945 case GST_FLOW_CUSTOM_SUCCESS:
3946 /* we can't assume the event is received when it was dropped */
3947 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3948 GST_EVENT_TYPE_NAME (event));
3949 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3950 data->ret = GST_FLOW_OK;
3952 case GST_FLOW_CUSTOM_SUCCESS_1:
3953 /* event was ignored and should be sent later */
3954 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3955 GST_EVENT_TYPE_NAME (event));
3956 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3957 data->ret = GST_FLOW_OK;
3959 case GST_FLOW_NOT_LINKED:
3960 /* not linked is not a problem, we are sticky so the event will be
3961 * rescheduled to be sent later on re-link, but only for non-EOS events */
3962 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3963 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3964 data->ret = GST_FLOW_OK;
3965 ev->received = TRUE;
3969 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3970 gst_flow_get_name (data->ret));
3971 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3975 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3976 data->was_eos = TRUE;
3978 return data->ret == GST_FLOW_OK;
3981 /* check sticky events and push them when needed. should be called
3983 static inline GstFlowReturn
3984 check_sticky (GstPad * pad, GstEvent * event)
3986 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3988 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3989 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3991 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3992 events_foreach (pad, push_sticky, &data);
3994 /* If there's an EOS event we must push it downstream
3995 * even if sending a previous sticky event failed.
3996 * Otherwise the pipeline might wait forever for EOS.
3998 * Only do this if pushing another event than the EOS
4001 if (data.ret != GST_FLOW_OK && !data.was_eos) {
4002 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
4004 if (ev && !ev->received) {
4005 gst_event_ref (ev->event);
4006 data.ret = gst_pad_push_event_unchecked (pad, &ev->event,
4007 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
4008 /* the event could have been dropped. Because this can only
4009 * happen if the user asked for it, it's not an error */
4010 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
4011 data.ret = GST_FLOW_OK;
4021 * @pad: a #GstPad to invoke the default query on.
4022 * @query: (transfer none): the #GstQuery to perform.
4024 * Dispatches a query to a pad. The query should have been allocated by the
4025 * caller via one of the type-specific allocation functions. The element that
4026 * the pad belongs to is responsible for filling the query with an appropriate
4027 * response, which should then be parsed with a type-specific query parsing
4030 * Again, the caller is responsible for both the allocation and deallocation of
4031 * the query structure.
4033 * Please also note that some queries might need a running pipeline to work.
4035 * Returns: %TRUE if the query could be performed.
4038 gst_pad_query (GstPad * pad, GstQuery * query)
4041 gboolean res, serialized;
4042 GstPadQueryFunction func;
4043 GstPadProbeType type;
4046 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4047 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4049 if (GST_PAD_IS_SRC (pad)) {
4050 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4051 goto wrong_direction;
4052 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4053 } else if (GST_PAD_IS_SINK (pad)) {
4054 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4055 goto wrong_direction;
4056 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4058 goto unknown_direction;
4060 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
4061 GST_QUERY_TYPE_NAME (query));
4062 GST_TRACER_PAD_QUERY_PRE (pad, query);
4064 serialized = GST_QUERY_IS_SERIALIZED (query);
4065 if (G_UNLIKELY (serialized))
4066 GST_PAD_STREAM_LOCK (pad);
4068 GST_OBJECT_LOCK (pad);
4069 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4070 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4071 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4073 ACQUIRE_PARENT (pad, parent, no_parent);
4074 GST_OBJECT_UNLOCK (pad);
4076 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4079 res = func (pad, parent, query);
4081 RELEASE_PARENT (parent);
4083 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4084 GST_QUERY_TYPE_NAME (query), res);
4085 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4090 GST_OBJECT_LOCK (pad);
4091 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4092 GST_OBJECT_UNLOCK (pad);
4094 if (G_UNLIKELY (serialized))
4095 GST_PAD_STREAM_UNLOCK (pad);
4102 g_warning ("pad %s:%s query %s in wrong direction",
4103 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4108 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4113 GST_DEBUG_OBJECT (pad, "had no parent");
4114 GST_OBJECT_UNLOCK (pad);
4115 if (G_UNLIKELY (serialized))
4116 GST_PAD_STREAM_UNLOCK (pad);
4121 GST_DEBUG_OBJECT (pad, "had no query function");
4122 RELEASE_PARENT (parent);
4123 if (G_UNLIKELY (serialized))
4124 GST_PAD_STREAM_UNLOCK (pad);
4129 GST_DEBUG_OBJECT (pad, "query failed");
4130 if (G_UNLIKELY (serialized))
4131 GST_PAD_STREAM_UNLOCK (pad);
4136 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4137 GST_OBJECT_UNLOCK (pad);
4138 if (G_UNLIKELY (serialized))
4139 GST_PAD_STREAM_UNLOCK (pad);
4141 /* if a probe dropped without handling, we don't sent it further but assume
4142 * that the probe did not answer the query and return FALSE */
4143 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4153 * gst_pad_peer_query:
4154 * @pad: a #GstPad to invoke the peer query on.
4155 * @query: (transfer none): the #GstQuery to perform.
4157 * Performs gst_pad_query() on the peer of @pad.
4159 * The caller is responsible for both the allocation and deallocation of
4160 * the query structure.
4162 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4163 * if @pad has no peer.
4166 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4169 GstPadProbeType type;
4170 gboolean res, serialized;
4173 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4174 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4176 if (GST_PAD_IS_SRC (pad)) {
4177 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4178 goto wrong_direction;
4179 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4180 } else if (GST_PAD_IS_SINK (pad)) {
4181 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4182 goto wrong_direction;
4183 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4185 goto unknown_direction;
4187 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4188 GST_QUERY_TYPE_NAME (query));
4190 serialized = GST_QUERY_IS_SERIALIZED (query);
4192 GST_OBJECT_LOCK (pad);
4193 if (GST_PAD_IS_SRC (pad) && serialized) {
4194 /* all serialized queries on the srcpad trigger push of
4196 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4200 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4201 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4202 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4204 peerpad = GST_PAD_PEER (pad);
4205 if (G_UNLIKELY (peerpad == NULL))
4208 gst_object_ref (peerpad);
4209 GST_OBJECT_UNLOCK (pad);
4211 res = gst_pad_query (peerpad, query);
4213 gst_object_unref (peerpad);
4218 GST_OBJECT_LOCK (pad);
4219 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4220 GST_OBJECT_UNLOCK (pad);
4227 g_warning ("pad %s:%s query %s in wrong direction",
4228 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4233 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4238 GST_WARNING_OBJECT (pad, "could not send sticky events");
4239 GST_OBJECT_UNLOCK (pad);
4244 GST_INFO_OBJECT (pad, "pad has no peer");
4245 GST_OBJECT_UNLOCK (pad);
4250 GST_DEBUG_OBJECT (pad, "query failed");
4255 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4256 GST_OBJECT_UNLOCK (pad);
4258 /* if a probe dropped without handling, we don't sent it further but
4259 * assume that the probe did not answer the query and return FALSE */
4260 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4269 /**********************************************************************
4270 * Data passing functions
4273 /* this is the chain function that does not perform the additional argument
4274 * checking for that little extra speed.
4276 static inline GstFlowReturn
4277 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4281 gboolean handled = FALSE;
4283 GST_PAD_STREAM_LOCK (pad);
4285 GST_OBJECT_LOCK (pad);
4286 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4289 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4292 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4295 #ifdef GST_ENABLE_EXTRA_CHECKS
4296 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4297 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4299 ":%s:<%s:%s> Got data flow before stream-start event",
4300 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4302 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4304 ":%s:<%s:%s> Got data flow before segment event",
4305 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4307 pad->priv->last_cookie = pad->priv->events_cookie;
4311 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4314 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4316 ACQUIRE_PARENT (pad, parent, no_parent);
4317 GST_OBJECT_UNLOCK (pad);
4319 /* NOTE: we read the chainfunc unlocked.
4320 * we cannot hold the lock for the pad so we might send
4321 * the data to the wrong function. This is not really a
4322 * problem since functions are assigned at creation time
4323 * and don't change that often... */
4324 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4325 GstPadChainFunction chainfunc;
4327 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4330 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4331 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4332 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4334 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4336 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4337 "called chainfunction &%s with buffer %p, returned %s",
4338 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4340 GstPadChainListFunction chainlistfunc;
4342 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4345 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4346 "calling chainlistfunction &%s",
4347 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4349 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4351 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4352 "called chainlistfunction &%s, returned %s",
4353 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4356 RELEASE_PARENT (parent);
4358 GST_PAD_STREAM_UNLOCK (pad);
4365 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4366 "chaining, but pad was flushing");
4367 GST_OBJECT_UNLOCK (pad);
4368 GST_PAD_STREAM_UNLOCK (pad);
4369 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4370 return GST_FLOW_FLUSHING;
4374 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4375 GST_OBJECT_UNLOCK (pad);
4376 GST_PAD_STREAM_UNLOCK (pad);
4377 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4378 return GST_FLOW_EOS;
4382 g_critical ("chain on pad %s:%s but it was not in push mode",
4383 GST_DEBUG_PAD_NAME (pad));
4384 GST_OBJECT_UNLOCK (pad);
4385 GST_PAD_STREAM_UNLOCK (pad);
4386 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4387 return GST_FLOW_ERROR;
4394 GST_OBJECT_UNLOCK (pad);
4395 GST_PAD_STREAM_UNLOCK (pad);
4396 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4398 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4401 case GST_FLOW_CUSTOM_SUCCESS:
4402 case GST_FLOW_CUSTOM_SUCCESS_1:
4403 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4407 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4414 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4415 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4416 GST_OBJECT_UNLOCK (pad);
4417 GST_PAD_STREAM_UNLOCK (pad);
4418 return GST_FLOW_FLUSHING;
4422 RELEASE_PARENT (parent);
4423 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4424 g_critical ("chain on pad %s:%s but it has no chainfunction",
4425 GST_DEBUG_PAD_NAME (pad));
4426 GST_PAD_STREAM_UNLOCK (pad);
4427 return GST_FLOW_NOT_SUPPORTED;
4433 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4434 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4437 * Chain a buffer to @pad.
4439 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4441 * If the buffer type is not acceptable for @pad (as negotiated with a
4442 * preceding GST_EVENT_CAPS event), this function returns
4443 * #GST_FLOW_NOT_NEGOTIATED.
4445 * The function proceeds calling the chain function installed on @pad (see
4446 * gst_pad_set_chain_function()) and the return value of that function is
4447 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4450 * In all cases, success or failure, the caller loses its reference to @buffer
4451 * after calling this function.
4453 * Returns: a #GstFlowReturn from the pad.
4458 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4460 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4461 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4462 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4464 return gst_pad_chain_data_unchecked (pad,
4465 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4468 static GstFlowReturn
4469 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4470 GstBufferList * list)
4476 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4478 len = gst_buffer_list_length (list);
4481 for (i = 0; i < len; i++) {
4482 buffer = gst_buffer_list_get (list, i);
4484 gst_pad_chain_data_unchecked (pad,
4485 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4486 gst_buffer_ref (buffer));
4487 if (ret != GST_FLOW_OK)
4490 gst_buffer_list_unref (list);
4496 * gst_pad_chain_list:
4497 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4498 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4501 * Chain a bufferlist to @pad.
4503 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4505 * If @pad was not negotiated properly with a CAPS event, this function
4506 * returns #GST_FLOW_NOT_NEGOTIATED.
4508 * The function proceeds calling the chainlist function installed on @pad (see
4509 * gst_pad_set_chain_list_function()) and the return value of that function is
4510 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4511 * chainlist function.
4513 * In all cases, success or failure, the caller loses its reference to @list
4514 * after calling this function.
4518 * Returns: a #GstFlowReturn from the pad.
4521 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4523 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4524 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4525 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4527 return gst_pad_chain_data_unchecked (pad,
4528 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4531 static GstFlowReturn
4532 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4536 gboolean handled = FALSE;
4538 GST_OBJECT_LOCK (pad);
4539 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4542 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4545 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4548 #ifdef GST_ENABLE_EXTRA_CHECKS
4549 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4550 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4552 ":%s:<%s:%s> Got data flow before stream-start event",
4553 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4555 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4557 ":%s:<%s:%s> Got data flow before segment event",
4558 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4560 pad->priv->last_cookie = pad->priv->events_cookie;
4564 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4567 /* do block probes */
4568 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
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 /* do post-blocking probes */
4576 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4578 /* recheck sticky events because the probe might have cause a relink */
4579 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4582 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4585 /* take ref to peer pad before releasing the lock */
4586 gst_object_ref (peer);
4588 GST_OBJECT_UNLOCK (pad);
4590 ret = gst_pad_chain_data_unchecked (peer, type, data);
4593 gst_object_unref (peer);
4595 GST_OBJECT_LOCK (pad);
4596 pad->ABI.abi.last_flowret = ret;
4598 if (pad->priv->using == 0) {
4599 /* pad is not active anymore, trigger idle callbacks */
4600 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4601 probe_stopped, ret);
4603 GST_OBJECT_UNLOCK (pad);
4607 /* ERROR recovery here */
4611 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4612 "pushing, but pad was flushing");
4613 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4614 GST_OBJECT_UNLOCK (pad);
4615 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4616 return GST_FLOW_FLUSHING;
4620 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4621 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4622 GST_OBJECT_UNLOCK (pad);
4623 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4624 return GST_FLOW_EOS;
4628 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4629 GST_DEBUG_PAD_NAME (pad));
4630 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4631 GST_OBJECT_UNLOCK (pad);
4632 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4633 return GST_FLOW_ERROR;
4637 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4638 "error pushing events, return %s", gst_flow_get_name (ret));
4639 pad->ABI.abi.last_flowret = ret;
4640 GST_OBJECT_UNLOCK (pad);
4641 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4649 GST_OBJECT_UNLOCK (pad);
4650 if (data != NULL && !handled)
4651 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4654 case GST_FLOW_CUSTOM_SUCCESS:
4655 case GST_FLOW_CUSTOM_SUCCESS_1:
4656 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4660 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4663 pad->ABI.abi.last_flowret = ret;
4668 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4669 "pushing, but it was not linked");
4670 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4671 GST_OBJECT_UNLOCK (pad);
4672 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4673 return GST_FLOW_NOT_LINKED;
4679 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4680 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4683 * Pushes a buffer to the peer of @pad.
4685 * This function will call installed block probes before triggering any
4686 * installed data probes.
4688 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4689 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4692 * In all cases, success or failure, the caller loses its reference to @buffer
4693 * after calling this function.
4695 * Returns: a #GstFlowReturn from the peer pad.
4700 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4704 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4705 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4706 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4708 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4709 res = gst_pad_push_data (pad,
4710 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4711 GST_TRACER_PAD_PUSH_POST (pad, res);
4716 * gst_pad_push_list:
4717 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4718 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4721 * Pushes a buffer list to the peer of @pad.
4723 * This function will call installed block probes before triggering any
4724 * installed data probes.
4726 * The function proceeds calling the chain function on the peer pad and returns
4727 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4728 * be returned. If the peer pad does not have any installed chainlist function
4729 * every group buffer of the list will be merged into a normal #GstBuffer and
4730 * chained via gst_pad_chain().
4732 * In all cases, success or failure, the caller loses its reference to @list
4733 * after calling this function.
4735 * Returns: a #GstFlowReturn from the peer pad.
4740 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4744 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4745 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4746 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4748 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4749 res = gst_pad_push_data (pad,
4750 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4751 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4755 static GstFlowReturn
4756 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4757 GstBuffer ** buffer)
4760 GstPadGetRangeFunction getrangefunc;
4764 GST_PAD_STREAM_LOCK (pad);
4766 GST_OBJECT_LOCK (pad);
4767 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4770 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4773 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4778 /* when one of the probes returns DROPPED, probe_stopped will be called
4779 * and we skip calling the getrange function, res_buf should then contain a
4780 * valid result buffer */
4781 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4782 res_buf, offset, size, probe_stopped);
4784 /* recheck sticky events because the probe might have cause a relink */
4785 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4788 ACQUIRE_PARENT (pad, parent, no_parent);
4789 GST_OBJECT_UNLOCK (pad);
4791 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4794 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4795 "calling getrangefunc %s, offset %"
4796 G_GUINT64_FORMAT ", size %u",
4797 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4799 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4801 RELEASE_PARENT (parent);
4803 GST_OBJECT_LOCK (pad);
4804 if (G_UNLIKELY (ret != GST_FLOW_OK))
4805 goto get_range_failed;
4807 /* can only fire the signal if we have a valid buffer */
4809 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4810 res_buf, offset, size, probe_stopped_unref);
4811 pad->ABI.abi.last_flowret = ret;
4812 GST_OBJECT_UNLOCK (pad);
4814 GST_PAD_STREAM_UNLOCK (pad);
4823 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4824 "getrange, but pad was flushing");
4825 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4826 GST_OBJECT_UNLOCK (pad);
4827 GST_PAD_STREAM_UNLOCK (pad);
4828 return GST_FLOW_FLUSHING;
4832 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4833 GST_DEBUG_PAD_NAME (pad));
4834 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4835 GST_OBJECT_UNLOCK (pad);
4836 GST_PAD_STREAM_UNLOCK (pad);
4837 return GST_FLOW_ERROR;
4841 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4842 pad->ABI.abi.last_flowret = ret;
4843 GST_OBJECT_UNLOCK (pad);
4844 GST_PAD_STREAM_UNLOCK (pad);
4849 GST_DEBUG_OBJECT (pad, "no parent");
4850 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4851 GST_OBJECT_UNLOCK (pad);
4852 GST_PAD_STREAM_UNLOCK (pad);
4853 return GST_FLOW_FLUSHING;
4857 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4858 GST_DEBUG_PAD_NAME (pad));
4859 RELEASE_PARENT (parent);
4860 GST_PAD_STREAM_UNLOCK (pad);
4861 return GST_FLOW_NOT_SUPPORTED;
4865 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4866 "probe returned %s", gst_flow_get_name (ret));
4867 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4869 /* the probe filled the buffer and asks us to not call the getrange
4870 * anymore, we continue with the post probes then. */
4871 GST_DEBUG_OBJECT (pad, "handled buffer");
4875 /* no buffer, we are EOS */
4876 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4880 pad->ABI.abi.last_flowret = ret;
4881 GST_OBJECT_UNLOCK (pad);
4882 GST_PAD_STREAM_UNLOCK (pad);
4886 probe_stopped_unref:
4888 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4889 "probe returned %s", gst_flow_get_name (ret));
4890 /* if we drop here, it signals EOS */
4891 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4893 pad->ABI.abi.last_flowret = ret;
4894 GST_OBJECT_UNLOCK (pad);
4895 GST_PAD_STREAM_UNLOCK (pad);
4896 if (*buffer == NULL)
4897 gst_buffer_unref (res_buf);
4902 pad->ABI.abi.last_flowret = ret;
4903 GST_OBJECT_UNLOCK (pad);
4904 GST_PAD_STREAM_UNLOCK (pad);
4905 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4906 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4907 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4913 * gst_pad_get_range:
4914 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4915 * @offset: The start offset of the buffer
4916 * @size: The length of the buffer
4917 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4918 * returns #GST_FLOW_ERROR if %NULL.
4920 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4921 * immediately and @buffer is %NULL.
4923 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4924 * description of a getrange function. If @pad has no getrange function
4925 * installed (see gst_pad_set_getrange_function()) this function returns
4926 * #GST_FLOW_NOT_SUPPORTED.
4928 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4929 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4930 * must be freed with gst_buffer_unref() after usage.
4932 * When @buffer points to a variable that points to a valid #GstBuffer, the
4933 * buffer will be filled with the result data when this function returns
4934 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4935 * @size bytes will be filled in the result buffer and its size will be updated
4938 * Note that less than @size bytes can be returned in @buffer when, for example,
4939 * an EOS condition is near or when @buffer is not large enough to hold @size
4940 * bytes. The caller should check the result buffer size to get the result size.
4942 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4943 * will be unchanged.
4945 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4947 * Returns: a #GstFlowReturn from the pad.
4952 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4953 GstBuffer ** buffer)
4955 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4956 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4957 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4958 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4959 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4961 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4965 * gst_pad_pull_range:
4966 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4967 * @offset: The start offset of the buffer
4968 * @size: The length of the buffer
4969 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4970 * GST_FLOW_ERROR if %NULL.
4972 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4974 * This function will first trigger the pad block signal if it was
4977 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4978 * function returns the result of gst_pad_get_range() on the peer pad.
4979 * See gst_pad_get_range() for a list of return values and for the
4980 * semantics of the arguments of this function.
4982 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4983 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4984 * must be freed with gst_buffer_unref() after usage. When this function
4985 * returns any other result value, @buffer will still point to %NULL.
4987 * When @buffer points to a variable that points to a valid #GstBuffer, the
4988 * buffer will be filled with the result data when this function returns
4989 * #GST_FLOW_OK. When this function returns any other result value,
4990 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4991 * @size bytes will be filled in the result buffer and its size will be updated
4994 * Note that less than @size bytes can be returned in @buffer when, for example,
4995 * an EOS condition is near or when @buffer is not large enough to hold @size
4996 * bytes. The caller should check the result buffer size to get the result size.
4998 * Returns: a #GstFlowReturn from the peer pad.
5003 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
5004 GstBuffer ** buffer)
5010 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
5011 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
5012 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
5013 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
5014 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
5016 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
5018 GST_OBJECT_LOCK (pad);
5019 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5022 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
5027 /* when one of the probes returns DROPPED, probe_stopped will be
5028 * called and we skip calling the peer getrange function. *buffer should then
5029 * contain a valid buffer */
5030 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
5031 res_buf, offset, size, probe_stopped);
5033 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
5036 gst_object_ref (peer);
5038 GST_OBJECT_UNLOCK (pad);
5040 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
5042 gst_object_unref (peer);
5044 GST_OBJECT_LOCK (pad);
5046 pad->ABI.abi.last_flowret = ret;
5047 if (pad->priv->using == 0) {
5048 /* pad is not active anymore, trigger idle callbacks */
5049 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
5050 probe_stopped_unref, ret);
5053 if (G_UNLIKELY (ret != GST_FLOW_OK))
5054 goto pull_range_failed;
5057 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
5058 res_buf, offset, size, probe_stopped_unref);
5060 GST_OBJECT_UNLOCK (pad);
5064 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5067 /* ERROR recovery here */
5070 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5071 "pullrange, but pad was flushing");
5072 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5073 GST_OBJECT_UNLOCK (pad);
5074 ret = GST_FLOW_FLUSHING;
5079 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5080 GST_DEBUG_PAD_NAME (pad));
5081 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5082 GST_OBJECT_UNLOCK (pad);
5083 ret = GST_FLOW_ERROR;
5088 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5089 gst_flow_get_name (ret));
5090 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5092 /* the probe filled the buffer and asks us to not forward to the peer
5093 * anymore, we continue with the post probes then */
5094 GST_DEBUG_OBJECT (pad, "handled buffer");
5098 /* no buffer, we are EOS then */
5099 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5103 pad->ABI.abi.last_flowret = ret;
5104 GST_OBJECT_UNLOCK (pad);
5109 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5110 "pulling range, but it was not linked");
5111 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5112 GST_OBJECT_UNLOCK (pad);
5113 ret = GST_FLOW_NOT_LINKED;
5118 pad->ABI.abi.last_flowret = ret;
5119 GST_OBJECT_UNLOCK (pad);
5120 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5121 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5122 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5125 probe_stopped_unref:
5127 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5128 "post probe returned %s", gst_flow_get_name (ret));
5130 /* if we drop here, it signals EOS */
5131 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5134 pad->ABI.abi.last_flowret = ret;
5135 GST_OBJECT_UNLOCK (pad);
5137 if (*buffer == NULL)
5138 gst_buffer_unref (res_buf);
5142 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5146 /* must be called with pad object lock */
5147 static GstFlowReturn
5148 store_sticky_event (GstPad * pad, GstEvent * event)
5153 gboolean res = FALSE;
5154 const gchar *name = NULL;
5155 gboolean insert = TRUE;
5157 type = GST_EVENT_TYPE (event);
5159 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5160 * otherwise they can be dropped and nothing would ever resend them.
5161 * Only do that for activated pads though, everything else is a bug!
5163 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5164 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5165 || type == GST_EVENT_EOS))))
5168 /* Unset the EOS flag when received STREAM_START event, so pad can
5169 * store sticky event and then push it later */
5170 if (type == GST_EVENT_STREAM_START) {
5171 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5172 remove_event_by_type (pad, GST_EVENT_EOS);
5173 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5174 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5177 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5180 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5181 name = gst_structure_get_name (gst_event_get_structure (event));
5183 events = pad->priv->events;
5186 for (i = 0; i < len; i++) {
5187 PadEvent *ev = &g_array_index (events, PadEvent, i);
5189 if (ev->event == NULL)
5192 if (type == GST_EVENT_TYPE (ev->event)) {
5193 /* matching types, check matching name if needed */
5194 if (name && !gst_event_has_name (ev->event, name))
5198 if ((res = gst_event_replace (&ev->event, event)))
5199 ev->received = FALSE;
5205 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5206 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5207 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5208 * storing the sticky ordered we can check that this is respected. */
5209 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5210 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5212 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5213 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5214 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5215 gst_event_type_get_name (type));
5221 ev.event = gst_event_ref (event);
5222 ev.received = FALSE;
5223 g_array_insert_val (events, i, ev);
5228 pad->priv->events_cookie++;
5229 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5231 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5233 switch (GST_EVENT_TYPE (event)) {
5234 case GST_EVENT_CAPS:
5235 GST_OBJECT_UNLOCK (pad);
5237 GST_DEBUG_OBJECT (pad, "notify caps");
5238 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5240 GST_OBJECT_LOCK (pad);
5246 if (type == GST_EVENT_EOS) {
5247 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5248 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5251 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5256 GST_DEBUG_OBJECT (pad, "pad is flushing");
5257 return GST_FLOW_FLUSHING;
5261 GST_DEBUG_OBJECT (pad, "pad is EOS");
5262 return GST_FLOW_EOS;
5267 * gst_pad_store_sticky_event:
5269 * @event: (transfer none): a #GstEvent
5271 * Store the sticky @event on @pad
5273 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5274 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5279 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5283 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5284 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5286 GST_OBJECT_LOCK (pad);
5287 ret = store_sticky_event (pad, event);
5288 GST_OBJECT_UNLOCK (pad);
5294 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5296 PushStickyData *data = user_data;
5298 /* Forward all sticky events before our current one that are pending */
5299 if (ev->event != data->event
5300 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5301 return push_sticky (pad, ev, data);
5306 /* should be called with pad LOCK */
5307 static GstFlowReturn
5308 gst_pad_push_event_unchecked (GstPad * pad, GstEvent ** in_event,
5309 GstPadProbeType type)
5313 GstEventType event_type;
5314 GstEvent *event = *in_event;
5316 /* pass the adjusted event on. We need to do this even if
5317 * there is no peer pad because of the probes. */
5318 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5320 /* Two checks to be made:
5321 * . (un)set the FLUSHING flag for flushing events,
5322 * . handle pad blocking */
5323 event_type = GST_EVENT_TYPE (event);
5324 switch (event_type) {
5325 case GST_EVENT_FLUSH_START:
5326 GST_PAD_SET_FLUSHING (pad);
5328 GST_PAD_BLOCK_BROADCAST (pad);
5329 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5331 case GST_EVENT_FLUSH_STOP:
5332 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5335 GST_PAD_UNSET_FLUSHING (pad);
5337 /* Remove sticky EOS events */
5338 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5339 remove_event_by_type (pad, GST_EVENT_EOS);
5340 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5341 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5342 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5343 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5345 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5349 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5352 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5353 * checked already or this is called as part of pushing sticky events,
5354 * in which case we still want to forward the EOS event downstream.
5357 switch (GST_EVENT_TYPE (event)) {
5358 case GST_EVENT_RECONFIGURE:
5359 if (GST_PAD_IS_SINK (pad))
5360 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5365 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5366 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5367 /* recheck sticky events because the probe might have cause a relink */
5368 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5369 && (GST_EVENT_IS_SERIALIZED (event)
5370 || GST_EVENT_IS_STICKY (event))) {
5371 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5372 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5374 /* Push all sticky events before our current one
5375 * that have changed */
5376 events_foreach (pad, sticky_changed, &data);
5382 /* send probes after modifying the events above */
5383 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5385 /* recheck sticky events because the probe might have cause a relink */
5386 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5387 && (GST_EVENT_IS_SERIALIZED (event)
5388 || GST_EVENT_IS_STICKY (event))) {
5389 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5390 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5392 /* Push all sticky events before our current one
5393 * that have changed */
5394 events_foreach (pad, sticky_changed, &data);
5397 /* now check the peer pad */
5398 peerpad = GST_PAD_PEER (pad);
5399 if (peerpad == NULL)
5402 gst_object_ref (peerpad);
5404 GST_OBJECT_UNLOCK (pad);
5406 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5407 event, gst_event_type_get_name (event_type), peerpad);
5409 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5411 /* Note: we gave away ownership of the event at this point but we can still
5412 * print the old pointer */
5413 GST_LOG_OBJECT (pad,
5414 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5415 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5417 gst_object_unref (peerpad);
5419 GST_OBJECT_LOCK (pad);
5421 if (pad->priv->using == 0) {
5422 /* pad is not active anymore, trigger idle callbacks */
5423 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5424 idle_probe_stopped, ret);
5431 /* ERROR handling */
5434 GST_DEBUG_OBJECT (pad, "We're flushing");
5435 gst_event_unref (event);
5436 return GST_FLOW_FLUSHING;
5440 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5441 gst_event_unref (event);
5442 return GST_FLOW_FLUSHING;
5446 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5447 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5448 gst_event_unref (event);
5451 case GST_FLOW_CUSTOM_SUCCESS_1:
5452 GST_DEBUG_OBJECT (pad, "handled event");
5454 case GST_FLOW_CUSTOM_SUCCESS:
5455 GST_DEBUG_OBJECT (pad, "dropped event");
5458 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5465 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5466 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5467 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5468 gst_event_unref (event);
5470 /* unlinked pads should not influence latency configuration */
5471 if (event_type == GST_EVENT_LATENCY)
5474 return GST_FLOW_NOT_LINKED;
5478 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5484 * gst_pad_push_event:
5485 * @pad: a #GstPad to push the event to.
5486 * @event: (transfer full): the #GstEvent to send to the pad.
5488 * Sends the event to the peer of the given pad. This function is
5489 * mainly used by elements to send events to their peer
5492 * This function takes ownership of the provided event so you should
5493 * gst_event_ref() it if you want to reuse the event after this call.
5495 * Returns: %TRUE if the event was handled.
5500 gst_pad_push_event (GstPad * pad, GstEvent * event)
5502 gboolean res = FALSE;
5503 GstPadProbeType type;
5504 gboolean sticky, serialized;
5506 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5507 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5509 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5511 if (GST_PAD_IS_SRC (pad)) {
5512 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5513 goto wrong_direction;
5514 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5515 } else if (GST_PAD_IS_SINK (pad)) {
5516 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5517 goto wrong_direction;
5518 /* events pushed on sinkpad never are sticky */
5519 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5521 goto unknown_direction;
5523 GST_OBJECT_LOCK (pad);
5524 sticky = GST_EVENT_IS_STICKY (event);
5525 serialized = GST_EVENT_IS_SERIALIZED (event);
5528 /* srcpad sticky events are stored immediately, the received flag is set
5529 * to FALSE and will be set to TRUE when we can successfully push the
5530 * event to the peer pad */
5531 switch (store_sticky_event (pad, event)) {
5532 case GST_FLOW_FLUSHING:
5540 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5541 /* all serialized or sticky events on the srcpad trigger push of
5543 res = (check_sticky (pad, event) == GST_FLOW_OK);
5548 /* other events are pushed right away */
5549 ret = gst_pad_push_event_unchecked (pad, &event, type);
5550 /* dropped events by a probe are not an error */
5551 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5552 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5554 /* Errors in sticky event pushing are no problem and ignored here
5555 * as they will cause more meaningful errors during data flow.
5556 * For EOS events, that are not followed by data flow, we still
5557 * return FALSE here though.
5559 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5561 gst_event_unref (event);
5563 GST_OBJECT_UNLOCK (pad);
5565 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5568 /* ERROR handling */
5571 g_warning ("pad %s:%s pushing %s event in wrong direction",
5572 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5573 gst_event_unref (event);
5578 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5579 gst_event_unref (event);
5584 GST_DEBUG_OBJECT (pad, "We're flushing");
5585 GST_OBJECT_UNLOCK (pad);
5586 gst_event_unref (event);
5591 GST_DEBUG_OBJECT (pad, "We're EOS");
5592 GST_OBJECT_UNLOCK (pad);
5593 gst_event_unref (event);
5597 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5601 /* Check if we can call the event function with the given event */
5602 static GstFlowReturn
5603 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5607 switch (GST_EVENT_TYPE (event)) {
5608 case GST_EVENT_CAPS:
5610 /* backwards compatibility mode for caps */
5611 gst_event_parse_caps (event, &caps);
5613 if (!gst_pad_query_accept_caps (pad, caps))
5625 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5626 "caps %" GST_PTR_FORMAT " not accepted", caps);
5627 return GST_FLOW_NOT_NEGOTIATED;
5631 static GstFlowReturn
5632 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5633 GstPadProbeType type)
5636 GstEventType event_type;
5637 gboolean serialized, need_unlock = FALSE, sticky;
5638 GstPadEventFunction eventfunc;
5639 GstPadEventFullFunction eventfullfunc = NULL;
5642 GST_OBJECT_LOCK (pad);
5644 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5646 if (GST_PAD_IS_SINK (pad))
5647 serialized = GST_EVENT_IS_SERIALIZED (event);
5650 sticky = GST_EVENT_IS_STICKY (event);
5651 event_type = GST_EVENT_TYPE (event);
5652 switch (event_type) {
5653 case GST_EVENT_FLUSH_START:
5654 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5655 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5657 /* can't even accept a flush begin event when flushing */
5658 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5661 GST_PAD_SET_FLUSHING (pad);
5662 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5663 GST_PAD_BLOCK_BROADCAST (pad);
5664 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5666 case GST_EVENT_FLUSH_STOP:
5667 /* we can't accept flush-stop on inactive pads else the flushing flag
5668 * would be cleared and it would look like the pad can accept data.
5669 * Also, some elements restart a streaming thread in flush-stop which we
5670 * can't allow on inactive pads */
5671 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5674 GST_PAD_UNSET_FLUSHING (pad);
5675 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5676 /* Remove pending EOS events */
5677 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5678 remove_event_by_type (pad, GST_EVENT_EOS);
5679 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5680 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5681 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5682 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5684 GST_OBJECT_UNLOCK (pad);
5685 /* grab stream lock */
5686 GST_PAD_STREAM_LOCK (pad);
5688 GST_OBJECT_LOCK (pad);
5689 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5692 case GST_EVENT_RECONFIGURE:
5693 if (GST_PAD_IS_SRC (pad))
5694 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5696 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5697 "have event type %" GST_PTR_FORMAT, event);
5699 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5702 switch (event_type) {
5703 case GST_EVENT_STREAM_START:
5704 /* Remove sticky EOS events */
5705 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5706 remove_event_by_type (pad, GST_EVENT_EOS);
5707 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5708 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5715 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5718 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5719 GST_OBJECT_UNLOCK (pad);
5720 GST_PAD_STREAM_LOCK (pad);
5722 GST_OBJECT_LOCK (pad);
5723 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5726 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5732 /* now do the probe */
5734 type | GST_PAD_PROBE_TYPE_PUSH |
5735 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5737 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5739 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5740 eventfunc = GST_PAD_EVENTFUNC (pad);
5741 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5744 ACQUIRE_PARENT (pad, parent, no_parent);
5745 GST_OBJECT_UNLOCK (pad);
5747 ret = pre_eventfunc_check (pad, event);
5748 if (G_UNLIKELY (ret != GST_FLOW_OK))
5749 goto precheck_failed;
5752 gst_event_ref (event);
5754 if (eventfullfunc) {
5755 ret = eventfullfunc (pad, parent, event);
5756 } else if (eventfunc (pad, parent, event)) {
5759 /* something went wrong */
5760 switch (event_type) {
5761 case GST_EVENT_CAPS:
5762 ret = GST_FLOW_NOT_NEGOTIATED;
5765 ret = GST_FLOW_ERROR;
5769 RELEASE_PARENT (parent);
5771 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5774 if (ret == GST_FLOW_OK) {
5775 GST_OBJECT_LOCK (pad);
5776 /* after the event function accepted the event, we can store the sticky
5777 * event on the pad */
5778 switch (store_sticky_event (pad, event)) {
5779 case GST_FLOW_FLUSHING:
5786 GST_OBJECT_UNLOCK (pad);
5788 gst_event_unref (event);
5792 GST_PAD_STREAM_UNLOCK (pad);
5796 /* ERROR handling */
5799 GST_OBJECT_UNLOCK (pad);
5801 GST_PAD_STREAM_UNLOCK (pad);
5802 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5803 "Received event on flushing pad. Discarding");
5804 gst_event_unref (event);
5805 return GST_FLOW_FLUSHING;
5809 GST_OBJECT_UNLOCK (pad);
5811 GST_PAD_STREAM_UNLOCK (pad);
5812 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5813 "Received flush-stop on inactive 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 event on EOS pad. Discarding");
5824 gst_event_unref (event);
5825 return GST_FLOW_EOS;
5829 GST_OBJECT_UNLOCK (pad);
5831 GST_PAD_STREAM_UNLOCK (pad);
5832 /* Only unref if unhandled */
5833 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5834 gst_event_unref (event);
5837 case GST_FLOW_CUSTOM_SUCCESS_1:
5838 case GST_FLOW_CUSTOM_SUCCESS:
5839 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5843 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5850 g_warning ("pad %s:%s has no event handler, file a bug.",
5851 GST_DEBUG_PAD_NAME (pad));
5852 GST_OBJECT_UNLOCK (pad);
5854 GST_PAD_STREAM_UNLOCK (pad);
5855 gst_event_unref (event);
5856 return GST_FLOW_NOT_SUPPORTED;
5860 GST_DEBUG_OBJECT (pad, "no parent");
5861 GST_OBJECT_UNLOCK (pad);
5863 GST_PAD_STREAM_UNLOCK (pad);
5864 gst_event_unref (event);
5865 return GST_FLOW_FLUSHING;
5869 GST_DEBUG_OBJECT (pad, "pre event check failed");
5870 RELEASE_PARENT (parent);
5872 GST_PAD_STREAM_UNLOCK (pad);
5873 gst_event_unref (event);
5879 * gst_pad_send_event:
5880 * @pad: a #GstPad to send the event to.
5881 * @event: (transfer full): the #GstEvent to send to the pad.
5883 * Sends the event to the pad. This function can be used
5884 * by applications to send events in the pipeline.
5886 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5887 * sink pad, @event should be a downstream event. For example, you would not
5888 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5889 * Furthermore, some downstream events have to be serialized with data flow,
5890 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5891 * the event needs to be serialized with data flow, this function will take the
5892 * pad's stream lock while calling its event function.
5894 * To find out whether an event type is upstream, downstream, or downstream and
5895 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5896 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5897 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5898 * plugin doesn't need to bother itself with this information; the core handles
5899 * all necessary locks and checks.
5901 * This function takes ownership of the provided event so you should
5902 * gst_event_ref() it if you want to reuse the event after this call.
5904 * Returns: %TRUE if the event was handled.
5907 gst_pad_send_event (GstPad * pad, GstEvent * event)
5910 GstPadProbeType type;
5912 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5913 g_return_val_if_fail (event != NULL, FALSE);
5915 if (GST_PAD_IS_SINK (pad)) {
5916 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5917 goto wrong_direction;
5918 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5919 } else if (GST_PAD_IS_SRC (pad)) {
5920 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5921 goto wrong_direction;
5922 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5924 goto unknown_direction;
5926 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5933 /* ERROR handling */
5936 g_warning ("pad %s:%s sending %s event in wrong direction",
5937 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5938 gst_event_unref (event);
5943 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5944 gst_event_unref (event);
5950 * gst_pad_set_element_private:
5951 * @pad: the #GstPad to set the private data of.
5952 * @priv: The private data to attach to the pad.
5954 * Set the given private data gpointer on the pad.
5955 * This function can only be used by the element that owns the pad.
5956 * No locking is performed in this function.
5959 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5961 pad->element_private = priv;
5965 * gst_pad_get_element_private:
5966 * @pad: the #GstPad to get the private data of.
5968 * Gets the private data of a pad.
5969 * No locking is performed in this function.
5971 * Returns: (transfer none) (nullable): a #gpointer to the private data.
5974 gst_pad_get_element_private (GstPad * pad)
5976 return pad->element_private;
5980 * gst_pad_get_sticky_event:
5981 * @pad: the #GstPad to get the event from.
5982 * @event_type: the #GstEventType that should be retrieved.
5983 * @idx: the index of the event
5985 * Returns a new reference of the sticky event of type @event_type
5988 * Returns: (transfer full) (nullable): a #GstEvent of type
5989 * @event_type or %NULL when no event of @event_type was on
5990 * @pad. Unref after usage.
5993 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5995 GstEvent *event = NULL;
5998 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5999 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
6001 GST_OBJECT_LOCK (pad);
6002 ev = find_event_by_type (pad, event_type, idx);
6003 if (ev && (event = ev->event))
6004 gst_event_ref (event);
6005 GST_OBJECT_UNLOCK (pad);
6012 GstPadStickyEventsForeachFunction func;
6017 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
6019 ForeachDispatch *data = user_data;
6020 gboolean ret = TRUE;
6023 GST_OBJECT_UNLOCK (pad);
6025 ret = data->func (pad, &ev->event, data->user_data);
6027 GST_OBJECT_LOCK (pad);
6034 * gst_pad_sticky_events_foreach:
6035 * @pad: the #GstPad that should be used for iteration.
6036 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
6037 * should be called for every event.
6038 * @user_data: (closure): the optional user data.
6040 * Iterates all sticky events on @pad and calls @foreach_func for every
6041 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
6044 gst_pad_sticky_events_foreach (GstPad * pad,
6045 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
6047 ForeachDispatch data;
6049 g_return_if_fail (GST_IS_PAD (pad));
6050 g_return_if_fail (foreach_func != NULL);
6052 data.func = foreach_func;
6053 data.user_data = user_data;
6055 GST_OBJECT_LOCK (pad);
6056 events_foreach (pad, foreach_dispatch_function, &data);
6057 GST_OBJECT_UNLOCK (pad);
6061 do_stream_status (GstPad * pad, GstStreamStatusType type,
6062 GThread * thread, GstTask * task)
6066 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6068 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6069 if (GST_IS_ELEMENT (parent)) {
6070 GstMessage *message;
6071 GValue value = { 0 };
6073 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6074 gchar *tname, *ename, *pname;
6076 /* create a good task name */
6077 ename = gst_element_get_name (parent);
6078 pname = gst_pad_get_name (pad);
6079 tname = g_strdup_printf ("%s:%s", ename, pname);
6083 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6087 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6090 g_value_init (&value, GST_TYPE_TASK);
6091 g_value_set_object (&value, task);
6092 gst_message_set_stream_status_object (message, &value);
6093 g_value_unset (&value);
6095 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6096 gst_element_post_message (parent, message);
6098 gst_object_unref (parent);
6103 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6105 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6110 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6112 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6117 * gst_pad_start_task:
6118 * @pad: the #GstPad to start the task of
6119 * @func: the task function to call
6120 * @user_data: user data passed to the task function
6121 * @notify: called when @user_data is no longer referenced
6123 * Starts a task that repeatedly calls @func with @user_data. This function
6124 * is mostly used in pad activation functions to start the dataflow.
6125 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6126 * before @func is called.
6128 * Returns: a %TRUE if the task could be started.
6131 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6132 GDestroyNotify notify)
6137 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6138 g_return_val_if_fail (func != NULL, FALSE);
6140 GST_DEBUG_OBJECT (pad, "start task");
6142 GST_OBJECT_LOCK (pad);
6143 task = GST_PAD_TASK (pad);
6145 task = gst_task_new (func, user_data, notify);
6146 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6147 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6148 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6149 GST_INFO_OBJECT (pad, "created task %p", task);
6150 GST_PAD_TASK (pad) = task;
6151 gst_object_ref (task);
6152 /* release lock to post the message */
6153 GST_OBJECT_UNLOCK (pad);
6155 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6157 gst_object_unref (task);
6159 GST_OBJECT_LOCK (pad);
6160 /* nobody else is supposed to have changed the pad now */
6161 if (GST_PAD_TASK (pad) != task)
6162 goto concurrent_stop;
6164 res = gst_task_set_state (task, GST_TASK_STARTED);
6165 GST_OBJECT_UNLOCK (pad);
6172 GST_OBJECT_UNLOCK (pad);
6178 * gst_pad_pause_task:
6179 * @pad: the #GstPad to pause the task of
6181 * Pause the task of @pad. This function will also wait until the
6182 * function executed by the task is finished if this function is not
6183 * called from the task function.
6185 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6189 gst_pad_pause_task (GstPad * pad)
6194 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6196 GST_DEBUG_OBJECT (pad, "pause task");
6198 GST_OBJECT_LOCK (pad);
6199 task = GST_PAD_TASK (pad);
6202 res = gst_task_set_state (task, GST_TASK_PAUSED);
6203 /* unblock activation waits if any */
6204 pad->priv->in_activation = FALSE;
6205 g_cond_broadcast (&pad->priv->activation_cond);
6206 GST_OBJECT_UNLOCK (pad);
6208 /* wait for task function to finish, this lock is recursive so it does nothing
6209 * when the pause is called from the task itself */
6210 GST_PAD_STREAM_LOCK (pad);
6211 GST_PAD_STREAM_UNLOCK (pad);
6217 GST_DEBUG_OBJECT (pad, "pad has no task");
6218 GST_OBJECT_UNLOCK (pad);
6224 * gst_pad_get_task_state:
6225 * @pad: the #GstPad to get task state from
6227 * Get @pad task state. If no task is currently
6228 * set, #GST_TASK_STOPPED is returned.
6230 * Returns: The current state of @pad's task.
6235 gst_pad_get_task_state (GstPad * pad)
6240 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6242 GST_OBJECT_LOCK (pad);
6243 task = GST_PAD_TASK (pad);
6246 res = gst_task_get_state (task);
6247 GST_OBJECT_UNLOCK (pad);
6253 GST_DEBUG_OBJECT (pad, "pad has no task");
6254 GST_OBJECT_UNLOCK (pad);
6255 return GST_TASK_STOPPED;
6260 * gst_pad_stop_task:
6261 * @pad: the #GstPad to stop the task of
6263 * Stop the task of @pad. This function will also make sure that the
6264 * function executed by the task will effectively stop if not called
6265 * from the GstTaskFunction.
6267 * This function will deadlock if called from the GstTaskFunction of
6268 * the task. Use gst_task_pause() instead.
6270 * Regardless of whether the pad has a task, the stream lock is acquired and
6271 * released so as to ensure that streaming through this pad has finished.
6273 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6276 gst_pad_stop_task (GstPad * pad)
6281 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6283 GST_DEBUG_OBJECT (pad, "stop task");
6285 GST_OBJECT_LOCK (pad);
6286 task = GST_PAD_TASK (pad);
6289 GST_PAD_TASK (pad) = NULL;
6290 res = gst_task_set_state (task, GST_TASK_STOPPED);
6291 /* unblock activation waits if any */
6292 pad->priv->in_activation = FALSE;
6293 g_cond_broadcast (&pad->priv->activation_cond);
6294 GST_OBJECT_UNLOCK (pad);
6296 GST_PAD_STREAM_LOCK (pad);
6297 GST_PAD_STREAM_UNLOCK (pad);
6299 if (!gst_task_join (task))
6302 gst_object_unref (task);
6308 GST_DEBUG_OBJECT (pad, "no task");
6309 GST_OBJECT_UNLOCK (pad);
6311 GST_PAD_STREAM_LOCK (pad);
6312 GST_PAD_STREAM_UNLOCK (pad);
6314 /* this is not an error */
6319 /* this is bad, possibly the application tried to join the task from
6320 * the task's thread. We install the task again so that it will be stopped
6321 * again from the right thread next time hopefully. */
6322 GST_OBJECT_LOCK (pad);
6323 GST_DEBUG_OBJECT (pad, "join failed");
6324 /* we can only install this task if there was no other task */
6325 if (GST_PAD_TASK (pad) == NULL)
6326 GST_PAD_TASK (pad) = task;
6327 GST_OBJECT_UNLOCK (pad);
6334 * gst_pad_probe_info_get_event:
6335 * @info: a #GstPadProbeInfo
6337 * Returns: (transfer none) (nullable): The #GstEvent from the probe
6341 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6343 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6344 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6346 return GST_PAD_PROBE_INFO_EVENT (info);
6351 * gst_pad_probe_info_get_query:
6352 * @info: a #GstPadProbeInfo
6354 * Returns: (transfer none) (nullable): The #GstQuery from the probe
6358 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6360 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6361 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6363 return GST_PAD_PROBE_INFO_QUERY (info);
6367 * gst_pad_probe_info_get_buffer:
6368 * @info: a #GstPadProbeInfo
6370 * Returns: (transfer none) (nullable): The #GstBuffer from the probe
6374 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6376 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6378 return GST_PAD_PROBE_INFO_BUFFER (info);
6382 * gst_pad_probe_info_get_buffer_list:
6383 * @info: a #GstPadProbeInfo
6385 * Returns: (transfer none) (nullable): The #GstBufferList from the probe
6389 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6391 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6393 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6397 * gst_pad_get_last_flow_return:
6400 * Gets the #GstFlowReturn return from the last data passed by this pad.
6405 gst_pad_get_last_flow_return (GstPad * pad)
6409 GST_OBJECT_LOCK (pad);
6410 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6411 GST_OBJECT_UNLOCK (pad);