2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 * @short_description: Object contained by elements that allows links to
27 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
29 * A #GstElement is linked to other elements via "pads", which are extremely
30 * light-weight generic link points.
32 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
37 * happens when the element is created but it can also happen dynamically based
38 * on the data that the element is processing or based on the pads that the
39 * application requests.
41 * Pads without pad templates can be created with gst_pad_new(),
42 * which takes a direction and a name as an argument. If the name is %NULL,
43 * then a guaranteed unique name will be assigned to it.
45 * A #GstElement creating a pad will typically use the various
46 * gst_pad_set_*_function() calls to register callbacks for events, queries or
47 * dataflow on the pads.
49 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
51 * After two pads are retrieved from an element by gst_element_get_static_pad(),
52 * the pads can be linked with gst_pad_link(). (For quick links,
53 * you can also use gst_element_link(), which will make the obvious
54 * link for you if it's straightforward.). Pads can be unlinked again with
55 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
58 * Before dataflow is possible on the pads, they need to be activated with
59 * gst_pad_set_active().
61 * gst_pad_query() and gst_pad_peer_query() can be used to query various
62 * properties of the pad and the stream.
64 * To send a #GstEvent on a pad, use gst_pad_send_event() and
65 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
66 * after they pass on the pad they can be queried later with
67 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
68 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
69 * functions to query the current sticky CAPS event on a pad.
71 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
72 * or pull in a buffer.
74 * The dataflow, events and queries that happen on a pad can be monitored with
75 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
76 * can be used to check if a block probe is installed on the pad.
77 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
78 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
79 * and unblock blocking probes if any.
81 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
82 * offset will be applied to the running_time of all data passing over the pad.
83 * gst_pad_set_offset() can be used to change the offset.
85 * Convenience functions exist to start, pause and stop the task on a pad with
86 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
90 #include "gst_private.h"
93 #include "gstpadtemplate.h"
94 #include "gstenumtypes.h"
98 #include "gsttracerutils.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
124 #define GST_PAD_GET_PRIVATE(obj) \
125 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
127 #define _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH (GST_PAD_PROBE_TYPE_ALL_BOTH | GST_PAD_PROBE_TYPE_EVENT_FLUSH)
129 /* we have a pending and an active event on the pad. On source pads only the
130 * active event is used. On sinkpads, events are copied to the pending entry and
131 * moved to the active event when the eventfunc returned %TRUE. */
138 struct _GstPadPrivate
145 guint probe_list_cookie;
148 /* counter of how many idle probes are running directly from the add_probe
149 * call. Used to block any data flowing in the pad while the idle callback
150 * Doesn't finish its work */
153 /* conditional and variable used to ensure pads only get (de)activated
154 * by a single thread at a time. Protected by the object lock */
155 GCond activation_cond;
156 gboolean in_activation;
165 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
166 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
167 (((GstPad *)(p))->priv->idle_running > 0)
172 GstPadProbeInfo *info;
180 static void gst_pad_dispose (GObject * object);
181 static void gst_pad_finalize (GObject * object);
182 static void gst_pad_set_property (GObject * object, guint prop_id,
183 const GValue * value, GParamSpec * pspec);
184 static void gst_pad_get_property (GObject * object, guint prop_id,
185 GValue * value, GParamSpec * pspec);
187 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
188 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
189 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
190 GstObject * parent, GstBufferList * list);
192 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
193 GstEvent * event, GstPadProbeType type);
194 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
195 GstEvent * event, GstPadProbeType type);
197 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
198 GstPadMode mode, gboolean active);
200 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
202 static GParamSpec *pspec_caps = NULL;
204 /* quarks for probe signals */
205 static GQuark buffer_quark;
206 static GQuark buffer_list_quark;
207 static GQuark event_quark;
216 static GstFlowQuarks flow_quarks[] = {
217 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
218 {GST_FLOW_OK, "ok", 0},
219 {GST_FLOW_NOT_LINKED, "not-linked", 0},
220 {GST_FLOW_FLUSHING, "flushing", 0},
221 {GST_FLOW_EOS, "eos", 0},
222 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
223 {GST_FLOW_ERROR, "error", 0},
224 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
225 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
230 * @ret: a #GstFlowReturn to get the name of.
232 * Gets a string representing the given flow return.
234 * Returns: a static string with the name of the flow return.
237 gst_flow_get_name (GstFlowReturn ret)
241 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
243 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
244 if (ret == flow_quarks[i].ret)
245 return flow_quarks[i].name;
252 * @ret: a #GstFlowReturn to get the quark of.
254 * Get the unique quark for the given GstFlowReturn.
256 * Returns: the quark associated with the flow return or 0 if an
257 * invalid return was specified.
260 gst_flow_to_quark (GstFlowReturn ret)
264 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
266 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
267 if (ret == flow_quarks[i].ret)
268 return flow_quarks[i].quark;
274 * gst_pad_link_get_name:
275 * @ret: a #GstPadLinkReturn to get the name of.
277 * Gets a string representing the given pad-link return.
279 * Returns: a static string with the name of the pad-link return.
284 gst_pad_link_get_name (GstPadLinkReturn ret)
287 case GST_PAD_LINK_OK:
289 case GST_PAD_LINK_WRONG_HIERARCHY:
290 return "wrong hierarchy";
291 case GST_PAD_LINK_WAS_LINKED:
293 case GST_PAD_LINK_WRONG_DIRECTION:
294 return "wrong direction";
295 case GST_PAD_LINK_NOFORMAT:
296 return "no common format";
297 case GST_PAD_LINK_NOSCHED:
298 return "incompatible scheduling";
299 case GST_PAD_LINK_REFUSED:
302 g_return_val_if_reached ("unknown");
309 buffer_quark = g_quark_from_static_string ("buffer"); \
310 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
311 event_quark = g_quark_from_static_string ("event"); \
313 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
314 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
317 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
318 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
321 #define gst_pad_parent_class parent_class
322 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
325 gst_pad_class_init (GstPadClass * klass)
327 GObjectClass *gobject_class;
328 GstObjectClass *gstobject_class;
330 gobject_class = G_OBJECT_CLASS (klass);
331 gstobject_class = GST_OBJECT_CLASS (klass);
333 g_type_class_add_private (klass, sizeof (GstPadPrivate));
335 gobject_class->dispose = gst_pad_dispose;
336 gobject_class->finalize = gst_pad_finalize;
337 gobject_class->set_property = gst_pad_set_property;
338 gobject_class->get_property = gst_pad_get_property;
342 * @pad: the pad that emitted the signal
343 * @peer: the peer pad that has been connected
345 * Signals that a pad has been linked to the peer pad.
347 gst_pad_signals[PAD_LINKED] =
348 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
349 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
350 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
353 * @pad: the pad that emitted the signal
354 * @peer: the peer pad that has been disconnected
356 * Signals that a pad has been unlinked from the peer pad.
358 gst_pad_signals[PAD_UNLINKED] =
359 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
360 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
361 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
363 pspec_caps = g_param_spec_boxed ("caps", "Caps",
364 "The capabilities of the pad", GST_TYPE_CAPS,
365 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
368 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
369 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
370 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
371 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
373 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
374 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
375 g_param_spec_object ("template", "Template",
376 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382 * The offset that will be applied to the running time of the pad.
386 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
387 g_param_spec_int64 ("offset", "Offset",
388 "The running time offset of the pad", 0, G_MAXINT64, 0,
389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 gstobject_class->path_string_separator = ".";
393 /* Register common function pointer descriptions */
394 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
395 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
396 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
397 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
398 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
402 gst_pad_init (GstPad * pad)
404 pad->priv = GST_PAD_GET_PRIVATE (pad);
406 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
408 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
409 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
410 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
411 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
412 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
414 GST_PAD_SET_FLUSHING (pad);
416 g_rec_mutex_init (&pad->stream_rec_lock);
418 g_cond_init (&pad->block_cond);
420 g_hook_list_init (&pad->probes, sizeof (GstProbe));
422 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
423 pad->priv->events_cookie = 0;
424 pad->priv->last_cookie = -1;
425 g_cond_init (&pad->priv->activation_cond);
427 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
430 /* called when setting the pad inactive. It removes all sticky events from
431 * the pad. must be called with object lock */
433 remove_events (GstPad * pad)
437 gboolean notify = FALSE;
439 events = pad->priv->events;
442 for (i = 0; i < len; i++) {
443 PadEvent *ev = &g_array_index (events, PadEvent, i);
444 GstEvent *event = ev->event;
448 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
451 gst_event_unref (event);
454 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
455 g_array_set_size (events, 0);
456 pad->priv->events_cookie++;
459 GST_OBJECT_UNLOCK (pad);
461 GST_DEBUG_OBJECT (pad, "notify caps");
462 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
464 GST_OBJECT_LOCK (pad);
468 /* should be called with object lock */
470 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
476 events = pad->priv->events;
479 for (i = 0; i < len; i++) {
480 ev = &g_array_index (events, PadEvent, i);
481 if (ev->event == NULL)
484 if (GST_EVENT_TYPE (ev->event) == type) {
488 } else if (GST_EVENT_TYPE (ev->event) > type) {
497 /* should be called with OBJECT lock */
499 find_event (GstPad * pad, GstEvent * event)
505 events = pad->priv->events;
508 for (i = 0; i < len; i++) {
509 ev = &g_array_index (events, PadEvent, i);
510 if (event == ev->event)
512 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
520 /* should be called with OBJECT lock */
522 remove_event_by_type (GstPad * pad, GstEventType type)
528 events = pad->priv->events;
533 ev = &g_array_index (events, PadEvent, i);
534 if (ev->event == NULL)
537 if (GST_EVENT_TYPE (ev->event) > type)
539 else if (GST_EVENT_TYPE (ev->event) != type)
542 gst_event_unref (ev->event);
543 g_array_remove_index (events, i);
545 pad->priv->events_cookie++;
553 /* check all events on srcpad against those on sinkpad. All events that are not
554 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
555 * srcpad so that the events will be sent next time */
556 /* should be called with srcpad and sinkpad LOCKS */
558 schedule_events (GstPad * srcpad, GstPad * sinkpad)
563 gboolean pending = FALSE;
565 events = srcpad->priv->events;
568 for (i = 0; i < len; i++) {
569 ev = &g_array_index (events, PadEvent, i);
570 if (ev->event == NULL)
573 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
574 ev->received = FALSE;
579 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
582 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
585 /* should be called with pad LOCK */
587 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
594 events = pad->priv->events;
597 cookie = pad->priv->events_cookie;
601 PadEvent *ev, ev_ret;
603 ev = &g_array_index (events, PadEvent, i);
604 if (G_UNLIKELY (ev->event == NULL))
607 /* take aditional ref, func might release the lock */
608 ev_ret.event = gst_event_ref (ev->event);
609 ev_ret.received = ev->received;
611 ret = func (pad, &ev_ret, user_data);
613 /* recheck the cookie, lock might have been released and the list could have
615 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
616 if (G_LIKELY (ev_ret.event))
617 gst_event_unref (ev_ret.event);
621 /* store the received state */
622 ev->received = ev_ret.received;
624 /* if the event changed, we need to do something */
625 if (G_UNLIKELY (ev->event != ev_ret.event)) {
626 if (G_UNLIKELY (ev_ret.event == NULL)) {
627 /* function unreffed and set the event to NULL, remove it */
628 gst_event_unref (ev->event);
629 g_array_remove_index (events, i);
631 cookie = ++pad->priv->events_cookie;
634 /* function gave a new event for us */
635 gst_event_take (&ev->event, ev_ret.event);
638 /* just unref, nothing changed */
639 gst_event_unref (ev_ret.event);
648 /* should be called with LOCK */
650 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
654 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
655 GST_STIME_ARGS (pad->offset));
657 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
660 g_assert (!upstream);
662 /* copy segment values */
663 gst_event_copy_segment (event, &segment);
664 gst_event_unref (event);
666 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
667 event = gst_event_new_segment (&segment);
670 event = gst_event_make_writable (event);
671 offset = gst_event_get_running_time_offset (event);
673 offset -= pad->offset;
675 offset += pad->offset;
676 gst_event_set_running_time_offset (event, offset);
681 static inline GstEvent *
682 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
684 if (G_UNLIKELY (pad->offset != 0))
685 return _apply_pad_offset (pad, event, upstream);
690 /* should be called with the OBJECT_LOCK */
692 get_pad_caps (GstPad * pad)
694 GstCaps *caps = NULL;
697 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
699 gst_event_parse_caps (ev->event, &caps);
705 gst_pad_dispose (GObject * object)
707 GstPad *pad = GST_PAD_CAST (object);
710 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
712 /* unlink the peer pad */
713 if ((peer = gst_pad_get_peer (pad))) {
714 /* window for MT unsafeness, someone else could unlink here
715 * and then we call unlink with wrong pads. The unlink
716 * function would catch this and safely return failed. */
717 if (GST_PAD_IS_SRC (pad))
718 gst_pad_unlink (pad, peer);
720 gst_pad_unlink (peer, pad);
722 gst_object_unref (peer);
725 gst_pad_set_pad_template (pad, NULL);
727 GST_OBJECT_LOCK (pad);
729 GST_OBJECT_UNLOCK (pad);
731 g_hook_list_clear (&pad->probes);
733 G_OBJECT_CLASS (parent_class)->dispose (object);
737 gst_pad_finalize (GObject * object)
739 GstPad *pad = GST_PAD_CAST (object);
742 /* in case the task is still around, clean it up */
743 if ((task = GST_PAD_TASK (pad))) {
744 gst_task_join (task);
745 GST_PAD_TASK (pad) = NULL;
746 gst_object_unref (task);
749 if (pad->activatenotify)
750 pad->activatenotify (pad->activatedata);
751 if (pad->activatemodenotify)
752 pad->activatemodenotify (pad->activatemodedata);
754 pad->linknotify (pad->linkdata);
755 if (pad->unlinknotify)
756 pad->unlinknotify (pad->unlinkdata);
757 if (pad->chainnotify)
758 pad->chainnotify (pad->chaindata);
759 if (pad->chainlistnotify)
760 pad->chainlistnotify (pad->chainlistdata);
761 if (pad->getrangenotify)
762 pad->getrangenotify (pad->getrangedata);
763 if (pad->eventnotify)
764 pad->eventnotify (pad->eventdata);
765 if (pad->querynotify)
766 pad->querynotify (pad->querydata);
767 if (pad->iterintlinknotify)
768 pad->iterintlinknotify (pad->iterintlinkdata);
770 g_rec_mutex_clear (&pad->stream_rec_lock);
771 g_cond_clear (&pad->block_cond);
772 g_cond_clear (&pad->priv->activation_cond);
773 g_array_free (pad->priv->events, TRUE);
775 G_OBJECT_CLASS (parent_class)->finalize (object);
779 gst_pad_set_property (GObject * object, guint prop_id,
780 const GValue * value, GParamSpec * pspec)
782 g_return_if_fail (GST_IS_PAD (object));
785 case PAD_PROP_DIRECTION:
786 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
788 case PAD_PROP_TEMPLATE:
789 gst_pad_set_pad_template (GST_PAD_CAST (object),
790 (GstPadTemplate *) g_value_get_object (value));
792 case PAD_PROP_OFFSET:
793 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
796 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
802 gst_pad_get_property (GObject * object, guint prop_id,
803 GValue * value, GParamSpec * pspec)
805 g_return_if_fail (GST_IS_PAD (object));
809 GST_OBJECT_LOCK (object);
810 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
811 GST_OBJECT_UNLOCK (object);
813 case PAD_PROP_DIRECTION:
814 g_value_set_enum (value, GST_PAD_DIRECTION (object));
816 case PAD_PROP_TEMPLATE:
817 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
819 case PAD_PROP_OFFSET:
820 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
823 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
830 * @name: (allow-none): the name of the new pad.
831 * @direction: the #GstPadDirection of the pad.
833 * Creates a new pad with the given name in the given direction.
834 * If name is %NULL, a guaranteed unique name (across all pads)
836 * This function makes a copy of the name so you can safely free the name.
838 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
844 gst_pad_new (const gchar * name, GstPadDirection direction)
846 return g_object_new (GST_TYPE_PAD,
847 "name", name, "direction", direction, NULL);
851 * gst_pad_new_from_template:
852 * @templ: the pad template to use
853 * @name: (allow-none): the name of the pad
855 * Creates a new pad with the given name from the given template.
856 * If name is %NULL, a guaranteed unique name (across all pads)
858 * This function makes a copy of the name so you can safely free the name.
860 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
864 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
866 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
868 return g_object_new (GST_TYPE_PAD,
869 "name", name, "direction", templ->direction, "template", templ, NULL);
873 * gst_pad_new_from_static_template:
874 * @templ: the #GstStaticPadTemplate to use
875 * @name: the name of the pad
877 * Creates a new pad with the given name from the given static template.
878 * If name is %NULL, a guaranteed unique name (across all pads)
880 * This function makes a copy of the name so you can safely free the name.
882 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
886 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
890 GstPadTemplate *template;
892 template = gst_static_pad_template_get (templ);
893 pad = gst_pad_new_from_template (template, name);
894 gst_object_unref (template);
898 #define ACQUIRE_PARENT(pad, parent, label) \
900 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
901 gst_object_ref (parent); \
902 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
906 #define RELEASE_PARENT(parent) \
908 if (G_LIKELY (parent)) \
909 gst_object_unref (parent); \
913 * gst_pad_get_direction:
914 * @pad: a #GstPad to get the direction of.
916 * Gets the direction of the pad. The direction of the pad is
917 * decided at construction time so this function does not take
920 * Returns: the #GstPadDirection of the pad.
925 gst_pad_get_direction (GstPad * pad)
927 GstPadDirection result;
929 /* PAD_UNKNOWN is a little silly but we need some sort of
930 * error return value */
931 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
933 result = GST_PAD_DIRECTION (pad);
939 gst_pad_activate_default (GstPad * pad, GstObject * parent)
941 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
943 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
947 * gst_pad_mode_get_name:
948 * @mode: the pad mode
950 * Return the name of a pad mode, for use in debug messages mostly.
952 * Returns: short mnemonic for pad mode @mode
955 gst_pad_mode_get_name (GstPadMode mode)
958 case GST_PAD_MODE_NONE:
960 case GST_PAD_MODE_PUSH:
962 case GST_PAD_MODE_PULL:
970 /* Returns TRUE if pad wasn't already in the new_mode */
972 pre_activate (GstPad * pad, GstPadMode new_mode)
975 case GST_PAD_MODE_NONE:
976 GST_OBJECT_LOCK (pad);
977 while (G_UNLIKELY (pad->priv->in_activation))
978 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
979 if (new_mode == GST_PAD_MODE (pad)) {
980 GST_WARNING_OBJECT (pad,
981 "Pad is already in the process of being deactivated");
982 GST_OBJECT_UNLOCK (pad);
985 pad->priv->in_activation = TRUE;
986 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
987 GST_PAD_SET_FLUSHING (pad);
988 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
989 GST_PAD_MODE (pad) = new_mode;
990 /* unlock blocked pads so element can resume and stop */
991 GST_PAD_BLOCK_BROADCAST (pad);
992 GST_OBJECT_UNLOCK (pad);
994 case GST_PAD_MODE_PUSH:
995 case GST_PAD_MODE_PULL:
996 GST_OBJECT_LOCK (pad);
997 while (G_UNLIKELY (pad->priv->in_activation))
998 g_cond_wait (&pad->priv->activation_cond, GST_OBJECT_GET_LOCK (pad));
999 if (new_mode == GST_PAD_MODE (pad)) {
1000 GST_WARNING_OBJECT (pad,
1001 "Pad is already in the process of being activated");
1002 GST_OBJECT_UNLOCK (pad);
1005 pad->priv->in_activation = TRUE;
1006 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
1007 gst_pad_mode_get_name (new_mode));
1008 GST_PAD_UNSET_FLUSHING (pad);
1009 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1010 GST_PAD_MODE (pad) = new_mode;
1011 if (GST_PAD_IS_SINK (pad)) {
1013 /* make sure the peer src pad sends us all events */
1014 if ((peer = GST_PAD_PEER (pad))) {
1015 gst_object_ref (peer);
1016 GST_OBJECT_UNLOCK (pad);
1018 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1019 GST_DEBUG_PAD_NAME (peer));
1021 GST_OBJECT_LOCK (peer);
1022 schedule_events (peer, NULL);
1023 GST_OBJECT_UNLOCK (peer);
1025 gst_object_unref (peer);
1027 GST_OBJECT_UNLOCK (pad);
1030 GST_OBJECT_UNLOCK (pad);
1038 post_activate (GstPad * pad, GstPadMode new_mode)
1041 case GST_PAD_MODE_NONE:
1042 /* ensures that streaming stops */
1043 GST_PAD_STREAM_LOCK (pad);
1044 GST_DEBUG_OBJECT (pad, "stopped streaming");
1045 GST_OBJECT_LOCK (pad);
1046 pad->priv->in_activation = FALSE;
1047 g_cond_broadcast (&pad->priv->activation_cond);
1048 remove_events (pad);
1049 GST_OBJECT_UNLOCK (pad);
1050 GST_PAD_STREAM_UNLOCK (pad);
1052 case GST_PAD_MODE_PUSH:
1053 case GST_PAD_MODE_PULL:
1054 GST_OBJECT_LOCK (pad);
1055 pad->priv->in_activation = FALSE;
1056 g_cond_broadcast (&pad->priv->activation_cond);
1057 GST_OBJECT_UNLOCK (pad);
1064 * gst_pad_set_active:
1065 * @pad: the #GstPad to activate or deactivate.
1066 * @active: whether or not the pad should be active.
1068 * Activates or deactivates the given pad.
1069 * Normally called from within core state change functions.
1071 * If @active, makes sure the pad is active. If it is already active, either in
1072 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1073 * function to perform the actual activation.
1075 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1076 * and a %FALSE argument.
1078 * Returns: %TRUE if the operation was successful.
1083 gst_pad_set_active (GstPad * pad, gboolean active)
1087 gboolean ret = FALSE;
1089 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1091 GST_OBJECT_LOCK (pad);
1092 old = GST_PAD_MODE (pad);
1093 ACQUIRE_PARENT (pad, parent, no_parent);
1094 GST_OBJECT_UNLOCK (pad);
1097 if (old == GST_PAD_MODE_NONE) {
1098 GST_DEBUG_OBJECT (pad, "activating pad from none");
1099 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1101 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1103 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1104 gst_pad_mode_get_name (old));
1108 if (old == GST_PAD_MODE_NONE) {
1109 GST_DEBUG_OBJECT (pad, "pad was inactive");
1112 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1113 gst_pad_mode_get_name (old));
1114 ret = activate_mode_internal (pad, parent, old, FALSE);
1116 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1120 RELEASE_PARENT (parent);
1122 if (G_UNLIKELY (!ret))
1130 GST_DEBUG_OBJECT (pad, "no parent");
1131 GST_OBJECT_UNLOCK (pad);
1136 GST_OBJECT_LOCK (pad);
1138 g_critical ("Failed to deactivate pad %s:%s, very bad",
1139 GST_DEBUG_PAD_NAME (pad));
1141 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1143 GST_OBJECT_UNLOCK (pad);
1149 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1152 gboolean res = FALSE;
1153 GstPadMode old, new;
1154 GstPadDirection dir;
1157 GST_OBJECT_LOCK (pad);
1158 old = GST_PAD_MODE (pad);
1159 dir = GST_PAD_DIRECTION (pad);
1160 GST_OBJECT_UNLOCK (pad);
1162 new = active ? mode : GST_PAD_MODE_NONE;
1167 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1168 /* pad was activate in the wrong direction, deactivate it
1169 * and reactivate it in the requested mode */
1170 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1171 gst_pad_mode_get_name (old));
1173 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1174 goto deactivate_failed;
1175 old = GST_PAD_MODE_NONE;
1179 case GST_PAD_MODE_PULL:
1181 if (dir == GST_PAD_SINK) {
1182 if ((peer = gst_pad_get_peer (pad))) {
1183 GST_DEBUG_OBJECT (pad, "calling peer");
1184 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1186 gst_object_unref (peer);
1188 /* there is no peer, this is only fatal when we activate. When we
1189 * deactivate, we must assume the application has unlinked the peer and
1190 * will deactivate it eventually. */
1194 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1197 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1198 goto failure; /* Can't activate pull on a src without a
1199 getrange function */
1207 /* Mark pad as needing reconfiguration */
1209 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1211 /* pre_activate returns TRUE if we weren't already in the process of
1212 * switching to the 'new' mode */
1213 if (pre_activate (pad, new)) {
1215 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1216 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1220 /* can happen for sinks of passthrough elements */
1223 post_activate (pad, new);
1226 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1227 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1232 /* Clear sticky flags on deactivation */
1234 GST_OBJECT_LOCK (pad);
1235 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1236 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1237 GST_OBJECT_UNLOCK (pad);
1245 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1246 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1251 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1252 "failed to %s in switch to %s mode from %s mode",
1253 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1254 gst_pad_mode_get_name (old));
1259 GST_OBJECT_LOCK (peer);
1260 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1261 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1262 GST_OBJECT_UNLOCK (peer);
1263 gst_object_unref (peer);
1268 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1269 "pad in pull mode");
1274 GST_OBJECT_LOCK (pad);
1275 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1276 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1277 GST_PAD_SET_FLUSHING (pad);
1278 GST_PAD_MODE (pad) = old;
1279 pad->priv->in_activation = FALSE;
1280 g_cond_broadcast (&pad->priv->activation_cond);
1281 GST_OBJECT_UNLOCK (pad);
1287 * gst_pad_activate_mode:
1288 * @pad: the #GstPad to activate or deactivate.
1289 * @mode: the requested activation mode
1290 * @active: whether or not the pad should be active.
1292 * Activates or deactivates the given pad in @mode via dispatching to the
1293 * pad's activatemodefunc. For use from within pad activation functions only.
1295 * If you don't know what this is, you probably don't want to call it.
1297 * Returns: %TRUE if the operation was successful.
1302 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1306 GstPadMode old, new;
1308 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1310 GST_OBJECT_LOCK (pad);
1312 old = GST_PAD_MODE (pad);
1313 new = active ? mode : GST_PAD_MODE_NONE;
1317 ACQUIRE_PARENT (pad, parent, no_parent);
1319 GST_OBJECT_UNLOCK (pad);
1321 res = activate_mode_internal (pad, parent, mode, active);
1323 RELEASE_PARENT (parent);
1329 GST_OBJECT_UNLOCK (pad);
1330 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1331 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1336 GST_WARNING_OBJECT (pad, "no parent");
1337 GST_OBJECT_UNLOCK (pad);
1343 * gst_pad_is_active:
1344 * @pad: the #GstPad to query
1346 * Query if a pad is active
1348 * Returns: %TRUE if the pad is active.
1353 gst_pad_is_active (GstPad * pad)
1355 gboolean result = FALSE;
1357 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1359 GST_OBJECT_LOCK (pad);
1360 result = GST_PAD_IS_ACTIVE (pad);
1361 GST_OBJECT_UNLOCK (pad);
1367 cleanup_hook (GstPad * pad, GHook * hook)
1369 GstPadProbeType type;
1371 if (!G_HOOK_IS_VALID (hook))
1374 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1376 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1377 /* unblock when we remove the last blocking probe */
1379 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1382 /* Might have new probes now that want to be called */
1383 GST_PAD_BLOCK_BROADCAST (pad);
1385 if (pad->num_blocked == 0) {
1386 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1387 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1390 g_hook_destroy_link (&pad->probes, hook);
1395 * gst_pad_add_probe:
1396 * @pad: the #GstPad to add the probe to
1397 * @mask: the probe mask
1398 * @callback: #GstPadProbeCallback that will be called with notifications of
1400 * @user_data: (closure): user data passed to the callback
1401 * @destroy_data: #GDestroyNotify for user_data
1403 * Be notified of different states of pads. The provided callback is called for
1404 * every state that matches @mask.
1406 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1407 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1408 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1409 * immediately if the pad is already idle while calling gst_pad_add_probe().
1410 * In each of the groups, probes are called in the order in which they were
1413 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1414 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1415 * happen that the probe can be run immediately and if the probe returns
1416 * GST_PAD_PROBE_REMOVE this functions returns 0.
1421 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1422 GstPadProbeCallback callback, gpointer user_data,
1423 GDestroyNotify destroy_data)
1428 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1429 g_return_val_if_fail (mask != 0, 0);
1431 GST_OBJECT_LOCK (pad);
1433 /* make a new probe */
1434 hook = g_hook_alloc (&pad->probes);
1436 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1439 /* when no contraints are given for the types, assume all types are
1441 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1442 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1443 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1444 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1446 /* store our flags and other fields */
1447 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1448 hook->func = callback;
1449 hook->data = user_data;
1450 hook->destroy = destroy_data;
1451 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1454 g_hook_append (&pad->probes, hook);
1456 /* incremenent cookie so that the new hook get's called */
1457 pad->priv->probe_list_cookie++;
1459 /* get the id of the hook, we return this and it can be used to remove the
1461 res = hook->hook_id;
1463 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1465 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1466 /* we have a block probe */
1468 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1469 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1470 "now %d blocking probes", pad->num_blocked);
1472 /* Might have new probes now that want to be called */
1473 GST_PAD_BLOCK_BROADCAST (pad);
1476 /* call the callback if we need to be called for idle callbacks */
1477 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1478 if (pad->priv->using > 0) {
1479 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1480 * flag above, the last thread to leave the push will do the callback. New
1481 * threads going into the push will block. */
1482 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1483 "pad is in use, delay idle callback");
1484 GST_OBJECT_UNLOCK (pad);
1486 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1487 GstPadProbeReturn ret;
1489 /* Keep another ref, the callback could destroy the pad */
1490 gst_object_ref (pad);
1491 pad->priv->idle_running++;
1493 /* the pad is idle now, we can signal the idle callback now */
1494 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1495 "pad is idle, trigger idle callback");
1496 GST_OBJECT_UNLOCK (pad);
1498 ret = callback (pad, &info, user_data);
1500 GST_OBJECT_LOCK (pad);
1502 case GST_PAD_PROBE_REMOVE:
1503 /* remove the probe */
1504 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1505 cleanup_hook (pad, hook);
1508 case GST_PAD_PROBE_DROP:
1509 GST_DEBUG_OBJECT (pad, "asked to drop item");
1511 case GST_PAD_PROBE_PASS:
1512 GST_DEBUG_OBJECT (pad, "asked to pass item");
1514 case GST_PAD_PROBE_OK:
1515 GST_DEBUG_OBJECT (pad, "probe returned OK");
1517 case GST_PAD_PROBE_HANDLED:
1518 GST_DEBUG_OBJECT (pad, "probe handled the data");
1521 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1524 pad->priv->idle_running--;
1525 if (pad->priv->idle_running == 0) {
1526 GST_PAD_BLOCK_BROADCAST (pad);
1528 GST_OBJECT_UNLOCK (pad);
1530 gst_object_unref (pad);
1533 GST_OBJECT_UNLOCK (pad);
1539 * gst_pad_remove_probe:
1540 * @pad: the #GstPad with the probe
1541 * @id: the probe id to remove
1543 * Remove the probe with @id from @pad.
1548 gst_pad_remove_probe (GstPad * pad, gulong id)
1552 g_return_if_fail (GST_IS_PAD (pad));
1554 GST_OBJECT_LOCK (pad);
1556 hook = g_hook_get (&pad->probes, id);
1560 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1562 cleanup_hook (pad, hook);
1563 GST_OBJECT_UNLOCK (pad);
1569 GST_OBJECT_UNLOCK (pad);
1570 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1576 * gst_pad_is_blocked:
1577 * @pad: the #GstPad to query
1579 * Checks if the pad is blocked or not. This function returns the
1580 * last requested state of the pad. It is not certain that the pad
1581 * is actually blocking at this point (see gst_pad_is_blocking()).
1583 * Returns: %TRUE if the pad is blocked.
1588 gst_pad_is_blocked (GstPad * pad)
1590 gboolean result = FALSE;
1592 g_return_val_if_fail (GST_IS_PAD (pad), result);
1594 GST_OBJECT_LOCK (pad);
1595 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1596 GST_OBJECT_UNLOCK (pad);
1602 * gst_pad_is_blocking:
1603 * @pad: the #GstPad to query
1605 * Checks if the pad is blocking or not. This is a guaranteed state
1606 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1608 * Returns: %TRUE if the pad is blocking.
1613 gst_pad_is_blocking (GstPad * pad)
1615 gboolean result = FALSE;
1617 g_return_val_if_fail (GST_IS_PAD (pad), result);
1619 GST_OBJECT_LOCK (pad);
1620 /* the blocking flag is only valid if the pad is not flushing */
1621 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1622 GST_OBJECT_UNLOCK (pad);
1628 * gst_pad_needs_reconfigure:
1629 * @pad: the #GstPad to check
1631 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1632 * if the flag was set.
1634 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1637 gst_pad_needs_reconfigure (GstPad * pad)
1639 gboolean reconfigure;
1641 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1643 GST_OBJECT_LOCK (pad);
1644 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1645 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1646 GST_OBJECT_UNLOCK (pad);
1652 * gst_pad_check_reconfigure:
1653 * @pad: the #GstPad to check
1655 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1656 * if the flag was set.
1658 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1661 gst_pad_check_reconfigure (GstPad * pad)
1663 gboolean reconfigure;
1665 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1667 GST_OBJECT_LOCK (pad);
1668 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1670 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1671 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1673 GST_OBJECT_UNLOCK (pad);
1679 * gst_pad_mark_reconfigure:
1680 * @pad: the #GstPad to mark
1682 * Mark a pad for needing reconfiguration. The next call to
1683 * gst_pad_check_reconfigure() will return %TRUE after this call.
1686 gst_pad_mark_reconfigure (GstPad * pad)
1688 g_return_if_fail (GST_IS_PAD (pad));
1690 GST_OBJECT_LOCK (pad);
1691 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1692 GST_OBJECT_UNLOCK (pad);
1696 * gst_pad_set_activate_function:
1698 * @f: the #GstPadActivateFunction to set.
1700 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1704 * gst_pad_set_activate_function_full:
1706 * @activate: the #GstPadActivateFunction to set.
1707 * @user_data: user_data passed to @notify
1708 * @notify: notify called when @activate will not be used anymore.
1710 * Sets the given activate function for @pad. The activate function will
1711 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1712 * Only makes sense to set on sink pads.
1714 * Call this function if your sink pad can start a pull-based task.
1717 gst_pad_set_activate_function_full (GstPad * pad,
1718 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1720 g_return_if_fail (GST_IS_PAD (pad));
1722 if (pad->activatenotify)
1723 pad->activatenotify (pad->activatedata);
1724 GST_PAD_ACTIVATEFUNC (pad) = activate;
1725 pad->activatedata = user_data;
1726 pad->activatenotify = notify;
1728 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1729 GST_DEBUG_FUNCPTR_NAME (activate));
1733 * gst_pad_set_activatemode_function:
1735 * @f: the #GstPadActivateModeFunction to set.
1737 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1741 * gst_pad_set_activatemode_function_full:
1743 * @activatemode: the #GstPadActivateModeFunction to set.
1744 * @user_data: user_data passed to @notify
1745 * @notify: notify called when @activatemode will not be used anymore.
1747 * Sets the given activate_mode function for the pad. An activate_mode function
1748 * prepares the element for data passing.
1751 gst_pad_set_activatemode_function_full (GstPad * pad,
1752 GstPadActivateModeFunction activatemode, gpointer user_data,
1753 GDestroyNotify notify)
1755 g_return_if_fail (GST_IS_PAD (pad));
1757 if (pad->activatemodenotify)
1758 pad->activatemodenotify (pad->activatemodedata);
1759 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1760 pad->activatemodedata = user_data;
1761 pad->activatemodenotify = notify;
1763 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1764 GST_DEBUG_FUNCPTR_NAME (activatemode));
1768 * gst_pad_set_chain_function:
1769 * @p: a sink #GstPad.
1770 * @f: the #GstPadChainFunction to set.
1772 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1776 * gst_pad_set_chain_function_full:
1777 * @pad: a sink #GstPad.
1778 * @chain: the #GstPadChainFunction to set.
1779 * @user_data: user_data passed to @notify
1780 * @notify: notify called when @chain will not be used anymore.
1782 * Sets the given chain function for the pad. The chain function is called to
1783 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1786 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1787 gpointer user_data, GDestroyNotify notify)
1789 g_return_if_fail (GST_IS_PAD (pad));
1790 g_return_if_fail (GST_PAD_IS_SINK (pad));
1792 if (pad->chainnotify)
1793 pad->chainnotify (pad->chaindata);
1794 GST_PAD_CHAINFUNC (pad) = chain;
1795 pad->chaindata = user_data;
1796 pad->chainnotify = notify;
1798 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1799 GST_DEBUG_FUNCPTR_NAME (chain));
1803 * gst_pad_set_chain_list_function:
1804 * @p: a sink #GstPad.
1805 * @f: the #GstPadChainListFunction to set.
1807 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1811 * gst_pad_set_chain_list_function_full:
1812 * @pad: a sink #GstPad.
1813 * @chainlist: the #GstPadChainListFunction to set.
1814 * @user_data: user_data passed to @notify
1815 * @notify: notify called when @chainlist will not be used anymore.
1817 * Sets the given chain list function for the pad. The chainlist function is
1818 * called to process a #GstBufferList input buffer list. See
1819 * #GstPadChainListFunction for more details.
1822 gst_pad_set_chain_list_function_full (GstPad * pad,
1823 GstPadChainListFunction chainlist, gpointer user_data,
1824 GDestroyNotify notify)
1826 g_return_if_fail (GST_IS_PAD (pad));
1827 g_return_if_fail (GST_PAD_IS_SINK (pad));
1829 if (pad->chainlistnotify)
1830 pad->chainlistnotify (pad->chainlistdata);
1831 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1832 pad->chainlistdata = user_data;
1833 pad->chainlistnotify = notify;
1835 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1836 GST_DEBUG_FUNCPTR_NAME (chainlist));
1840 * gst_pad_set_getrange_function:
1841 * @p: a source #GstPad.
1842 * @f: the #GstPadGetRangeFunction to set.
1844 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1848 * gst_pad_set_getrange_function_full:
1849 * @pad: a source #GstPad.
1850 * @get: the #GstPadGetRangeFunction to set.
1851 * @user_data: user_data passed to @notify
1852 * @notify: notify called when @get will not be used anymore.
1854 * Sets the given getrange function for the pad. The getrange function is
1855 * called to produce a new #GstBuffer to start the processing pipeline. see
1856 * #GstPadGetRangeFunction for a description of the getrange function.
1859 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1860 gpointer user_data, GDestroyNotify notify)
1862 g_return_if_fail (GST_IS_PAD (pad));
1863 g_return_if_fail (GST_PAD_IS_SRC (pad));
1865 if (pad->getrangenotify)
1866 pad->getrangenotify (pad->getrangedata);
1867 GST_PAD_GETRANGEFUNC (pad) = get;
1868 pad->getrangedata = user_data;
1869 pad->getrangenotify = notify;
1871 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1872 GST_DEBUG_FUNCPTR_NAME (get));
1876 * gst_pad_set_event_function:
1877 * @p: a #GstPad of either direction.
1878 * @f: the #GstPadEventFunction to set.
1880 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1884 * gst_pad_set_event_function_full:
1885 * @pad: a #GstPad of either direction.
1886 * @event: the #GstPadEventFunction to set.
1887 * @user_data: user_data passed to @notify
1888 * @notify: notify called when @event will not be used anymore.
1890 * Sets the given event handler for the pad.
1893 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1894 gpointer user_data, GDestroyNotify notify)
1896 g_return_if_fail (GST_IS_PAD (pad));
1898 if (pad->eventnotify)
1899 pad->eventnotify (pad->eventdata);
1900 GST_PAD_EVENTFUNC (pad) = event;
1901 pad->eventdata = user_data;
1902 pad->eventnotify = notify;
1904 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1905 GST_DEBUG_FUNCPTR_NAME (event));
1909 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1913 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1914 if (ret == GST_FLOW_OK)
1920 * gst_pad_set_event_full_function:
1921 * @p: a #GstPad of either direction.
1922 * @f: the #GstPadEventFullFunction to set.
1924 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1928 * gst_pad_set_event_full_function_full:
1929 * @pad: a #GstPad of either direction.
1930 * @event: the #GstPadEventFullFunction to set.
1931 * @user_data: user_data passed to @notify
1932 * @notify: notify called when @event will not be used anymore.
1934 * Sets the given event handler for the pad.
1939 gst_pad_set_event_full_function_full (GstPad * pad,
1940 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1942 g_return_if_fail (GST_IS_PAD (pad));
1944 if (pad->eventnotify)
1945 pad->eventnotify (pad->eventdata);
1946 GST_PAD_EVENTFULLFUNC (pad) = event;
1947 GST_PAD_EVENTFUNC (pad) = event_wrap;
1948 pad->eventdata = user_data;
1949 pad->eventnotify = notify;
1951 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1952 GST_DEBUG_FUNCPTR_NAME (event));
1956 * gst_pad_set_query_function:
1957 * @p: a #GstPad of either direction.
1958 * @f: the #GstPadQueryFunction to set.
1960 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1964 * gst_pad_set_query_function_full:
1965 * @pad: a #GstPad of either direction.
1966 * @query: the #GstPadQueryFunction to set.
1967 * @user_data: user_data passed to @notify
1968 * @notify: notify called when @query will not be used anymore.
1970 * Set the given query function for the pad.
1973 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1974 gpointer user_data, GDestroyNotify notify)
1976 g_return_if_fail (GST_IS_PAD (pad));
1978 if (pad->querynotify)
1979 pad->querynotify (pad->querydata);
1980 GST_PAD_QUERYFUNC (pad) = query;
1981 pad->querydata = user_data;
1982 pad->querynotify = notify;
1984 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1985 GST_DEBUG_FUNCPTR_NAME (query));
1989 * gst_pad_set_iterate_internal_links_function:
1990 * @p: a #GstPad of either direction.
1991 * @f: the #GstPadIterIntLinkFunction to set.
1993 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1994 * for the user_data and notify.
1997 * gst_pad_set_iterate_internal_links_function_full:
1998 * @pad: a #GstPad of either direction.
1999 * @iterintlink: the #GstPadIterIntLinkFunction to set.
2000 * @user_data: user_data passed to @notify
2001 * @notify: notify called when @iterintlink will not be used anymore.
2003 * Sets the given internal link iterator function for the pad.
2006 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
2007 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
2008 GDestroyNotify notify)
2010 g_return_if_fail (GST_IS_PAD (pad));
2012 if (pad->iterintlinknotify)
2013 pad->iterintlinknotify (pad->iterintlinkdata);
2014 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
2015 pad->iterintlinkdata = user_data;
2016 pad->iterintlinknotify = notify;
2018 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
2019 GST_DEBUG_FUNCPTR_NAME (iterintlink));
2023 * gst_pad_set_link_function:
2025 * @f: the #GstPadLinkFunction to set.
2027 * Calls gst_pad_set_link_function_full() with %NULL
2028 * for the user_data and notify.
2031 * gst_pad_set_link_function_full:
2033 * @link: the #GstPadLinkFunction to set.
2034 * @user_data: user_data passed to @notify
2035 * @notify: notify called when @link will not be used anymore.
2037 * Sets the given link function for the pad. It will be called when
2038 * the pad is linked with another pad.
2040 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2043 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2044 * cannot be made for some reason.
2046 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2047 * of the peer sink pad, if present.
2050 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2051 gpointer user_data, GDestroyNotify notify)
2053 g_return_if_fail (GST_IS_PAD (pad));
2055 if (pad->linknotify)
2056 pad->linknotify (pad->linkdata);
2057 GST_PAD_LINKFUNC (pad) = link;
2058 pad->linkdata = user_data;
2059 pad->linknotify = notify;
2061 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2062 GST_DEBUG_FUNCPTR_NAME (link));
2066 * gst_pad_set_unlink_function:
2068 * @f: the #GstPadUnlinkFunction to set.
2070 * Calls gst_pad_set_unlink_function_full() with %NULL
2071 * for the user_data and notify.
2074 * gst_pad_set_unlink_function_full:
2076 * @unlink: the #GstPadUnlinkFunction to set.
2077 * @user_data: user_data passed to @notify
2078 * @notify: notify called when @unlink will not be used anymore.
2080 * Sets the given unlink function for the pad. It will be called
2081 * when the pad is unlinked.
2084 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2085 gpointer user_data, GDestroyNotify notify)
2087 g_return_if_fail (GST_IS_PAD (pad));
2089 if (pad->unlinknotify)
2090 pad->unlinknotify (pad->unlinkdata);
2091 GST_PAD_UNLINKFUNC (pad) = unlink;
2092 pad->unlinkdata = user_data;
2093 pad->unlinknotify = notify;
2095 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2096 GST_DEBUG_FUNCPTR_NAME (unlink));
2101 * @srcpad: the source #GstPad to unlink.
2102 * @sinkpad: the sink #GstPad to unlink.
2104 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2105 * signal on both pads.
2107 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2108 * the pads were not linked together.
2113 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2115 gboolean result = FALSE;
2116 GstElement *parent = NULL;
2118 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2119 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2120 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2121 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2123 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2125 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2126 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2127 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2129 /* We need to notify the parent before taking any pad locks as the bin in
2130 * question might be waiting for a lock on the pad while holding its lock
2131 * that our message will try to take. */
2132 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2133 if (GST_IS_ELEMENT (parent)) {
2134 gst_element_post_message (parent,
2135 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2136 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2138 gst_object_unref (parent);
2143 GST_OBJECT_LOCK (srcpad);
2144 GST_OBJECT_LOCK (sinkpad);
2146 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2147 goto not_linked_together;
2149 if (GST_PAD_UNLINKFUNC (srcpad)) {
2150 GstObject *tmpparent;
2152 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2154 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2155 RELEASE_PARENT (tmpparent);
2158 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2159 GstObject *tmpparent;
2161 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2163 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2164 RELEASE_PARENT (tmpparent);
2168 /* first clear peers */
2169 GST_PAD_PEER (srcpad) = NULL;
2170 GST_PAD_PEER (sinkpad) = NULL;
2172 GST_OBJECT_UNLOCK (sinkpad);
2173 GST_OBJECT_UNLOCK (srcpad);
2175 /* fire off a signal to each of the pads telling them
2176 * that they've been unlinked */
2177 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2178 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2180 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2181 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2186 if (parent != NULL) {
2187 gst_element_post_message (parent,
2188 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2189 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2190 gst_object_unref (parent);
2192 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2196 not_linked_together:
2198 /* we do not emit a warning in this case because unlinking cannot
2199 * be made MT safe.*/
2200 GST_OBJECT_UNLOCK (sinkpad);
2201 GST_OBJECT_UNLOCK (srcpad);
2207 * gst_pad_is_linked:
2208 * @pad: pad to check
2210 * Checks if a @pad is linked to another pad or not.
2212 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2217 gst_pad_is_linked (GstPad * pad)
2221 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2223 GST_OBJECT_LOCK (pad);
2224 result = (GST_PAD_PEER (pad) != NULL);
2225 GST_OBJECT_UNLOCK (pad);
2230 /* get the caps from both pads and see if the intersection
2233 * This function should be called with the pad LOCK on both
2237 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2238 GstPadLinkCheck flags)
2240 GstCaps *srccaps = NULL;
2241 GstCaps *sinkcaps = NULL;
2242 gboolean compatible = FALSE;
2244 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2247 /* Doing the expensive caps checking takes priority over only checking the template caps */
2248 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2249 GST_OBJECT_UNLOCK (sink);
2250 GST_OBJECT_UNLOCK (src);
2252 srccaps = gst_pad_query_caps (src, NULL);
2253 sinkcaps = gst_pad_query_caps (sink, NULL);
2255 GST_OBJECT_LOCK (src);
2256 GST_OBJECT_LOCK (sink);
2258 /* If one of the two pads doesn't have a template, consider the intersection
2260 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2261 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2265 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2267 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2270 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2272 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2275 /* if we have caps on both pads we can check the intersection. If one
2276 * of the caps is %NULL, we return %TRUE. */
2277 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2279 gst_caps_unref (srccaps);
2281 gst_caps_unref (sinkcaps);
2285 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2286 gst_caps_unref (srccaps);
2287 gst_caps_unref (sinkcaps);
2290 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2291 (compatible ? "" : "not "));
2296 /* check if the grandparents of both pads are the same.
2297 * This check is required so that we don't try to link
2298 * pads from elements in different bins without ghostpads.
2300 * The LOCK should be held on both pads
2303 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2305 GstObject *psrc, *psink;
2307 psrc = GST_OBJECT_PARENT (src);
2308 psink = GST_OBJECT_PARENT (sink);
2310 /* if one of the pads has no parent, we allow the link */
2311 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2314 /* only care about parents that are elements */
2315 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2316 goto no_element_parent;
2318 /* if the parents are the same, we have a loop */
2319 if (G_UNLIKELY (psrc == psink))
2322 /* if they both have a parent, we check the grandparents. We can not lock
2323 * the parent because we hold on the child (pad) and the locking order is
2324 * parent >> child. */
2325 psrc = GST_OBJECT_PARENT (psrc);
2326 psink = GST_OBJECT_PARENT (psink);
2328 /* if they have grandparents but they are not the same */
2329 if (G_UNLIKELY (psrc != psink))
2330 goto wrong_grandparents;
2337 GST_CAT_DEBUG (GST_CAT_CAPS,
2338 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2339 GST_PTR_FORMAT, psrc, psink);
2344 GST_CAT_DEBUG (GST_CAT_CAPS,
2345 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2346 GST_PTR_FORMAT, psrc, psink);
2351 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2357 GST_CAT_DEBUG (GST_CAT_CAPS,
2358 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2359 GST_PTR_FORMAT, psrc, psink);
2364 /* FIXME leftover from an attempt at refactoring... */
2365 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2366 * the two pads will be locked in the srcpad, sinkpad order. */
2367 static GstPadLinkReturn
2368 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2370 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2371 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2373 GST_OBJECT_LOCK (srcpad);
2375 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2376 goto src_was_linked;
2378 GST_OBJECT_LOCK (sinkpad);
2380 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2381 goto sink_was_linked;
2383 /* check hierarchy, pads can only be linked if the grandparents
2385 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2386 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2387 goto wrong_hierarchy;
2389 /* check pad caps for non-empty intersection */
2390 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2393 /* FIXME check pad scheduling for non-empty intersection */
2395 return GST_PAD_LINK_OK;
2399 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2400 GST_DEBUG_PAD_NAME (srcpad),
2401 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2402 /* we do not emit a warning in this case because unlinking cannot
2403 * be made MT safe.*/
2404 GST_OBJECT_UNLOCK (srcpad);
2405 return GST_PAD_LINK_WAS_LINKED;
2409 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2410 GST_DEBUG_PAD_NAME (sinkpad),
2411 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2412 /* we do not emit a warning in this case because unlinking cannot
2413 * be made MT safe.*/
2414 GST_OBJECT_UNLOCK (sinkpad);
2415 GST_OBJECT_UNLOCK (srcpad);
2416 return GST_PAD_LINK_WAS_LINKED;
2420 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2421 GST_OBJECT_UNLOCK (sinkpad);
2422 GST_OBJECT_UNLOCK (srcpad);
2423 return GST_PAD_LINK_WRONG_HIERARCHY;
2427 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2428 GST_OBJECT_UNLOCK (sinkpad);
2429 GST_OBJECT_UNLOCK (srcpad);
2430 return GST_PAD_LINK_NOFORMAT;
2436 * @srcpad: the source #GstPad.
2437 * @sinkpad: the sink #GstPad.
2439 * Checks if the source pad and the sink pad are compatible so they can be
2442 * Returns: %TRUE if the pads can be linked.
2445 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2447 GstPadLinkReturn result;
2449 /* generic checks */
2450 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2451 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2453 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2454 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2456 /* gst_pad_link_prepare does everything for us, we only release the locks
2457 * on the pads that it gets us. If this function returns !OK the locks are not
2459 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2460 if (result != GST_PAD_LINK_OK)
2463 GST_OBJECT_UNLOCK (srcpad);
2464 GST_OBJECT_UNLOCK (sinkpad);
2467 return result == GST_PAD_LINK_OK;
2471 * gst_pad_link_full:
2472 * @srcpad: the source #GstPad to link.
2473 * @sinkpad: the sink #GstPad to link.
2474 * @flags: the checks to validate when linking
2476 * Links the source pad and the sink pad.
2478 * This variant of #gst_pad_link provides a more granular control on the
2479 * checks being done when linking. While providing some considerable speedups
2480 * the caller of this method must be aware that wrong usage of those flags
2481 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2482 * for more information.
2486 * Returns: A result code indicating if the connection worked or
2490 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2492 GstPadLinkReturn result;
2494 GstPadLinkFunction srcfunc, sinkfunc;
2496 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2497 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2498 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2499 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2500 GST_PAD_LINK_WRONG_DIRECTION);
2502 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2504 /* Notify the parent early. See gst_pad_unlink for details. */
2505 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2506 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2507 gst_element_post_message (parent,
2508 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2509 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2511 gst_object_unref (parent);
2516 /* prepare will also lock the two pads */
2517 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2519 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2520 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2521 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2522 gst_pad_link_get_name (result));
2526 /* must set peers before calling the link function */
2527 GST_PAD_PEER (srcpad) = sinkpad;
2528 GST_PAD_PEER (sinkpad) = srcpad;
2530 /* check events, when something is different, mark pending */
2531 schedule_events (srcpad, sinkpad);
2533 /* get the link functions */
2534 srcfunc = GST_PAD_LINKFUNC (srcpad);
2535 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2537 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2538 /* custom link functions, execute them */
2539 GST_OBJECT_UNLOCK (sinkpad);
2540 GST_OBJECT_UNLOCK (srcpad);
2543 GstObject *tmpparent;
2545 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2546 /* this one will call the peer link function */
2547 result = srcfunc (srcpad, tmpparent, sinkpad);
2548 RELEASE_PARENT (tmpparent);
2549 } else if (sinkfunc) {
2550 GstObject *tmpparent;
2552 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2553 /* if no source link function, we need to call the sink link
2554 * function ourselves. */
2555 result = sinkfunc (sinkpad, tmpparent, srcpad);
2556 RELEASE_PARENT (tmpparent);
2560 GST_OBJECT_LOCK (srcpad);
2561 GST_OBJECT_LOCK (sinkpad);
2563 /* we released the lock, check if the same pads are linked still */
2564 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2565 goto concurrent_link;
2567 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2570 GST_OBJECT_UNLOCK (sinkpad);
2571 GST_OBJECT_UNLOCK (srcpad);
2573 /* fire off a signal to each of the pads telling them
2574 * that they've been linked */
2575 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2576 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2578 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2579 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2581 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2582 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2585 if (G_LIKELY (parent)) {
2586 gst_element_post_message (parent,
2587 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2588 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2589 gst_object_unref (parent);
2592 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2598 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2599 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2600 GST_OBJECT_UNLOCK (sinkpad);
2601 GST_OBJECT_UNLOCK (srcpad);
2603 /* The other link operation succeeded first */
2604 result = GST_PAD_LINK_WAS_LINKED;
2609 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2610 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2611 gst_pad_link_get_name (result));
2613 GST_PAD_PEER (srcpad) = NULL;
2614 GST_PAD_PEER (sinkpad) = NULL;
2616 GST_OBJECT_UNLOCK (sinkpad);
2617 GST_OBJECT_UNLOCK (srcpad);
2625 * @srcpad: the source #GstPad to link.
2626 * @sinkpad: the sink #GstPad to link.
2628 * Links the source pad and the sink pad.
2630 * Returns: A result code indicating if the connection worked or
2636 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2638 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2642 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2644 GstPadTemplate **template_p;
2646 /* this function would need checks if it weren't static */
2648 GST_OBJECT_LOCK (pad);
2649 template_p = &pad->padtemplate;
2650 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2651 GST_OBJECT_UNLOCK (pad);
2654 gst_pad_template_pad_created (templ, pad);
2658 * gst_pad_get_pad_template:
2661 * Gets the template for @pad.
2663 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2664 * this pad was instantiated, or %NULL if this pad has no
2665 * template. Unref after usage.
2668 gst_pad_get_pad_template (GstPad * pad)
2670 GstPadTemplate *templ;
2672 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2674 templ = GST_PAD_PAD_TEMPLATE (pad);
2676 return (templ ? gst_object_ref (templ) : NULL);
2680 * gst_pad_has_current_caps:
2681 * @pad: a #GstPad to check
2683 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2685 * Returns: %TRUE when @pad has caps associated with it.
2688 gst_pad_has_current_caps (GstPad * pad)
2693 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2695 GST_OBJECT_LOCK (pad);
2696 caps = get_pad_caps (pad);
2697 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2698 "check current pad caps %" GST_PTR_FORMAT, caps);
2699 result = (caps != NULL);
2700 GST_OBJECT_UNLOCK (pad);
2706 * gst_pad_get_current_caps:
2707 * @pad: a #GstPad to get the current capabilities of.
2709 * Gets the capabilities currently configured on @pad with the last
2710 * #GST_EVENT_CAPS event.
2712 * Returns: (transfer full) (nullable): the current caps of the pad with
2713 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2716 gst_pad_get_current_caps (GstPad * pad)
2720 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2722 GST_OBJECT_LOCK (pad);
2723 if ((result = get_pad_caps (pad)))
2724 gst_caps_ref (result);
2725 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2726 "get current pad caps %" GST_PTR_FORMAT, result);
2727 GST_OBJECT_UNLOCK (pad);
2733 * gst_pad_get_pad_template_caps:
2734 * @pad: a #GstPad to get the template capabilities from.
2736 * Gets the capabilities for @pad's template.
2738 * Returns: (transfer full): the #GstCaps of this pad template.
2739 * Unref after usage.
2742 gst_pad_get_pad_template_caps (GstPad * pad)
2744 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2746 if (GST_PAD_PAD_TEMPLATE (pad))
2747 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2749 return gst_caps_ref (GST_CAPS_ANY);
2754 * @pad: a #GstPad to get the peer of.
2756 * Gets the peer of @pad. This function refs the peer pad so
2757 * you need to unref it after use.
2759 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2764 gst_pad_get_peer (GstPad * pad)
2768 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2770 GST_OBJECT_LOCK (pad);
2771 result = GST_PAD_PEER (pad);
2773 gst_object_ref (result);
2774 GST_OBJECT_UNLOCK (pad);
2780 * gst_pad_get_allowed_caps:
2783 * Gets the capabilities of the allowed media types that can flow through
2784 * @pad and its peer.
2786 * The allowed capabilities is calculated as the intersection of the results of
2787 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2788 * on the resulting caps.
2790 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2791 * pad link. Unref the caps when you no longer need it. This
2792 * function returns %NULL when @pad has no peer.
2797 gst_pad_get_allowed_caps (GstPad * pad)
2800 GstCaps *caps = NULL;
2803 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2805 GST_OBJECT_LOCK (pad);
2806 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2808 GST_OBJECT_UNLOCK (pad);
2810 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2812 mycaps = gst_pad_query_caps (pad, NULL);
2814 /* Query peer caps */
2815 query = gst_query_new_caps (mycaps);
2816 if (!gst_pad_peer_query (pad, query)) {
2817 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2821 gst_query_parse_caps_result (query, &caps);
2823 g_warn_if_fail (caps != NULL);
2826 gst_caps_ref (caps);
2828 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2832 gst_query_unref (query);
2833 gst_caps_unref (mycaps);
2839 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2840 GST_OBJECT_UNLOCK (pad);
2847 * gst_pad_iterate_internal_links_default:
2848 * @pad: the #GstPad to get the internal links of.
2849 * @parent: (allow-none): the parent of @pad or %NULL
2851 * Iterate the list of pads to which the given pad is linked to inside of
2852 * the parent element.
2853 * This is the default handler, and thus returns an iterator of all of the
2854 * pads inside the parent element with opposite direction.
2856 * The caller must free this iterator after use with gst_iterator_free().
2858 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2859 * has no parent. Unref each returned pad with gst_object_unref().
2862 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2869 GstElement *eparent;
2871 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2873 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2874 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2876 GST_OBJECT_LOCK (pad);
2877 eparent = GST_PAD_PARENT (pad);
2878 if (!eparent || !GST_IS_ELEMENT (eparent))
2881 gst_object_ref (eparent);
2882 GST_OBJECT_UNLOCK (pad);
2885 if (pad->direction == GST_PAD_SRC)
2886 padlist = &eparent->sinkpads;
2888 padlist = &eparent->srcpads;
2890 GST_DEBUG_OBJECT (pad, "Making iterator");
2892 cookie = &eparent->pads_cookie;
2894 lock = GST_OBJECT_GET_LOCK (eparent);
2896 res = gst_iterator_new_list (GST_TYPE_PAD,
2897 lock, cookie, padlist, (GObject *) owner, NULL);
2899 gst_object_unref (owner);
2906 GST_OBJECT_UNLOCK (pad);
2907 GST_DEBUG_OBJECT (pad, "no parent element");
2913 * gst_pad_iterate_internal_links:
2914 * @pad: the GstPad to get the internal links of.
2916 * Gets an iterator for the pads to which the given pad is linked to inside
2917 * of the parent element.
2919 * Each #GstPad element yielded by the iterator will have its refcount increased,
2920 * so unref after use.
2922 * Free-function: gst_iterator_free
2924 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2925 * or %NULL when the pad does not have an iterator function
2926 * configured. Use gst_iterator_free() after usage.
2929 gst_pad_iterate_internal_links (GstPad * pad)
2931 GstIterator *res = NULL;
2934 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2936 GST_OBJECT_LOCK (pad);
2937 ACQUIRE_PARENT (pad, parent, no_parent);
2938 GST_OBJECT_UNLOCK (pad);
2940 if (GST_PAD_ITERINTLINKFUNC (pad))
2941 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2943 RELEASE_PARENT (parent);
2950 GST_DEBUG_OBJECT (pad, "no parent");
2951 GST_OBJECT_UNLOCK (pad);
2959 * @forward: (scope call): a #GstPadForwardFunction
2960 * @user_data: user data passed to @forward
2962 * Calls @forward for all internally linked pads of @pad. This function deals with
2963 * dynamically changing internal pads and will make sure that the @forward
2964 * function is only called once for each pad.
2966 * When @forward returns %TRUE, no further pads will be processed.
2968 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2971 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2974 gboolean result = FALSE;
2976 gboolean done = FALSE;
2977 GValue item = { 0, };
2978 GList *pushed_pads = NULL;
2980 iter = gst_pad_iterate_internal_links (pad);
2986 switch (gst_iterator_next (iter, &item)) {
2987 case GST_ITERATOR_OK:
2991 intpad = g_value_get_object (&item);
2993 /* if already pushed, skip. FIXME, find something faster to tag pads */
2994 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2995 g_value_reset (&item);
2999 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3000 GST_DEBUG_PAD_NAME (intpad));
3001 done = result = forward (intpad, user_data);
3003 pushed_pads = g_list_prepend (pushed_pads, intpad);
3005 g_value_reset (&item);
3008 case GST_ITERATOR_RESYNC:
3009 /* We don't reset the result here because we don't push the event
3010 * again on pads that got the event already and because we need
3011 * to consider the result of the previous pushes */
3012 gst_iterator_resync (iter);
3014 case GST_ITERATOR_ERROR:
3015 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3018 case GST_ITERATOR_DONE:
3023 g_value_unset (&item);
3024 gst_iterator_free (iter);
3026 g_list_free (pushed_pads);
3036 gboolean dispatched;
3040 event_forward_func (GstPad * pad, EventData * data)
3042 /* for each pad we send to, we should ref the event; it's up
3043 * to downstream to unref again when handled. */
3044 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3045 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3047 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3049 data->dispatched = TRUE;
3056 * gst_pad_event_default:
3057 * @pad: a #GstPad to call the default event handler on.
3058 * @parent: (allow-none): the parent of @pad or %NULL
3059 * @event: (transfer full): the #GstEvent to handle.
3061 * Invokes the default event handler for the given pad.
3063 * The EOS event will pause the task associated with @pad before it is forwarded
3064 * to all internally linked pads,
3066 * The event is sent to all pads internally linked to @pad. This function
3067 * takes ownership of @event.
3069 * Returns: %TRUE if the event was sent successfully.
3072 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3074 gboolean result, forward = TRUE;
3076 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3077 g_return_val_if_fail (event != NULL, FALSE);
3079 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3082 switch (GST_EVENT_TYPE (event)) {
3083 case GST_EVENT_CAPS:
3084 forward = GST_PAD_IS_PROXY_CAPS (pad);
3095 data.dispatched = FALSE;
3096 data.result = FALSE;
3098 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3100 /* for sinkpads without a parent element or without internal links, nothing
3101 * will be dispatched but we still want to return TRUE. */
3102 if (data.dispatched)
3103 result = data.result;
3108 gst_event_unref (event);
3113 /* Default accept caps implementation just checks against
3114 * the allowed caps for the pad */
3116 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3118 /* get the caps and see if it intersects to something not empty */
3119 GstCaps *caps, *allowed = NULL;
3122 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3124 /* first forward the query to internally linked pads when we are dealing with
3126 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3127 result = gst_pad_proxy_query_accept_caps (pad, query);
3129 allowed = gst_pad_get_pad_template_caps (pad);
3134 gst_query_parse_accept_caps (query, &caps);
3136 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3137 allowed = gst_pad_get_pad_template_caps (pad);
3139 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3140 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3141 allowed = gst_pad_query_caps (pad, caps);
3146 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3147 GST_DEBUG_OBJECT (pad,
3148 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3150 result = gst_caps_can_intersect (caps, allowed);
3152 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3153 GST_PTR_FORMAT, allowed, caps);
3154 result = gst_caps_is_subset (caps, allowed);
3156 gst_caps_unref (allowed);
3158 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3161 gst_query_set_accept_caps_result (query, result);
3167 /* Default caps implementation */
3169 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3171 GstCaps *result = NULL, *filter;
3172 GstPadTemplate *templ;
3173 gboolean fixed_caps;
3175 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3178 /* first try to proxy if we must */
3179 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3180 if ((gst_pad_proxy_query_caps (pad, query))) {
3185 gst_query_parse_caps (query, &filter);
3187 /* no proxy or it failed, do default handling */
3188 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3190 GST_OBJECT_LOCK (pad);
3192 /* fixed caps, try the negotiated caps first */
3193 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3194 if ((result = get_pad_caps (pad)))
3195 goto filter_done_unlock;
3198 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3199 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3200 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3201 goto filter_done_unlock;
3205 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3206 "non-fixed pad caps: trying pad caps");
3207 /* non fixed caps, try the negotiated caps */
3208 if ((result = get_pad_caps (pad)))
3209 goto filter_done_unlock;
3212 /* this almost never happens */
3213 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3214 result = GST_CAPS_ANY;
3217 GST_OBJECT_UNLOCK (pad);
3219 /* run the filter on the result */
3221 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3222 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3223 GST_PTR_FORMAT, result, result, filter, filter);
3224 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3225 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3228 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3229 "using caps %p %" GST_PTR_FORMAT, result, result);
3230 result = gst_caps_ref (result);
3232 gst_query_set_caps_result (query, result);
3233 gst_caps_unref (result);
3239 /* Default latency implementation */
3244 GstClockTime min, max;
3248 query_latency_default_fold (const GValue * item, GValue * ret,
3251 GstPad *pad = g_value_get_object (item), *peer;
3252 LatencyFoldData *fold_data = user_data;
3254 gboolean res = FALSE;
3256 query = gst_query_new_latency ();
3258 peer = gst_pad_get_peer (pad);
3260 res = gst_pad_peer_query (pad, query);
3262 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3267 GstClockTime min, max;
3269 gst_query_parse_latency (query, &live, &min, &max);
3271 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3272 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3274 /* FIXME : Why do we only take values into account if it's live ? */
3275 if (live || fold_data->count == 0) {
3276 if (min > fold_data->min)
3277 fold_data->min = min;
3279 if (fold_data->max == GST_CLOCK_TIME_NONE)
3280 fold_data->max = max;
3281 else if (max < fold_data->max)
3282 fold_data->max = max;
3284 fold_data->live = live;
3286 fold_data->count += 1;
3288 GST_DEBUG_OBJECT (pad, "latency query failed");
3289 g_value_set_boolean (ret, FALSE);
3292 gst_query_unref (query);
3294 gst_object_unref (peer);
3300 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3303 GstIteratorResult res;
3304 GValue ret = G_VALUE_INIT;
3306 LatencyFoldData fold_data;
3308 it = gst_pad_iterate_internal_links (pad);
3310 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3314 g_value_init (&ret, G_TYPE_BOOLEAN);
3317 fold_data.count = 0;
3318 fold_data.live = FALSE;
3320 fold_data.max = GST_CLOCK_TIME_NONE;
3322 g_value_set_boolean (&ret, TRUE);
3323 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3325 case GST_ITERATOR_OK:
3326 g_assert_not_reached ();
3328 case GST_ITERATOR_DONE:
3330 case GST_ITERATOR_ERROR:
3331 g_value_set_boolean (&ret, FALSE);
3333 case GST_ITERATOR_RESYNC:
3334 gst_iterator_resync (it);
3337 g_assert_not_reached ();
3340 gst_iterator_free (it);
3342 query_ret = g_value_get_boolean (&ret);
3344 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3345 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3346 fold_data.min, fold_data.max);
3348 if (fold_data.min > fold_data.max) {
3349 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3352 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3354 GST_LOG_OBJECT (pad, "latency query failed");
3364 gboolean dispatched;
3368 query_forward_func (GstPad * pad, QueryData * data)
3370 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3371 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3373 data->result |= gst_pad_peer_query (pad, data->query);
3375 data->dispatched = TRUE;
3377 /* stop on first successful reply */
3378 return data->result;
3382 * gst_pad_query_default:
3383 * @pad: a #GstPad to call the default query handler on.
3384 * @parent: (allow-none): the parent of @pad or %NULL
3385 * @query: (transfer none): the #GstQuery to handle.
3387 * Invokes the default query handler for the given pad.
3388 * The query is sent to all pads internally linked to @pad. Note that
3389 * if there are many possible sink pads that are internally linked to
3390 * @pad, only one will be sent the query.
3391 * Multi-sinkpad elements should implement custom query handlers.
3393 * Returns: %TRUE if the query was performed successfully.
3396 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3398 gboolean forward, ret = FALSE;
3400 switch (GST_QUERY_TYPE (query)) {
3401 case GST_QUERY_SCHEDULING:
3402 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3404 case GST_QUERY_ALLOCATION:
3405 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3407 case GST_QUERY_ACCEPT_CAPS:
3408 ret = gst_pad_query_accept_caps_default (pad, query);
3411 case GST_QUERY_CAPS:
3412 ret = gst_pad_query_caps_default (pad, query);
3415 case GST_QUERY_LATENCY:
3416 ret = gst_pad_query_latency_default (pad, query);
3419 case GST_QUERY_POSITION:
3420 case GST_QUERY_SEEKING:
3421 case GST_QUERY_FORMATS:
3422 case GST_QUERY_JITTER:
3423 case GST_QUERY_RATE:
3424 case GST_QUERY_CONVERT:
3430 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3431 query, GST_QUERY_TYPE_NAME (query));
3437 data.dispatched = FALSE;
3438 data.result = FALSE;
3440 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3442 if (data.dispatched) {
3445 /* nothing dispatched, assume drained */
3446 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3456 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3458 GstPad *pad = data->pad;
3459 GstPadProbeInfo *info = data->info;
3460 GstPadProbeType type, flags;
3461 GstPadProbeCallback callback;
3462 GstPadProbeReturn ret;
3463 gpointer original_data;
3465 /* if we have called this callback, do nothing */
3466 if (PROBE_COOKIE (hook) == data->cookie) {
3467 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3468 "hook %lu, cookie %u already called", hook->hook_id,
3469 PROBE_COOKIE (hook));
3473 PROBE_COOKIE (hook) = data->cookie;
3475 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3477 original_data = info->data;
3479 /* one of the scheduling types */
3480 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3483 if (G_UNLIKELY (data->handled)) {
3484 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3485 "probe previously returned HANDLED, not calling again");
3487 } else if (G_UNLIKELY (data->dropped)) {
3488 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3489 "probe previously returned DROPPED, not calling again");
3493 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3494 /* one of the data types for non-idle probes */
3495 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3496 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3498 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3499 /* one of the data types for non-idle probes */
3500 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3501 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3504 /* Type must have PULL or PUSH probe types */
3505 g_assert_not_reached ();
3508 /* one of the blocking types must match */
3509 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3510 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3512 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3513 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3515 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3516 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3517 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3520 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3521 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3522 PROBE_COOKIE (hook), flags);
3524 data->marshalled = TRUE;
3526 callback = (GstPadProbeCallback) hook->func;
3527 if (callback == NULL)
3530 info->id = hook->hook_id;
3532 GST_OBJECT_UNLOCK (pad);
3534 ret = callback (pad, info, hook->data);
3536 GST_OBJECT_LOCK (pad);
3538 if (original_data != NULL && info->data == NULL) {
3539 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3540 info->type = GST_PAD_PROBE_TYPE_INVALID;
3541 data->dropped = TRUE;
3545 case GST_PAD_PROBE_REMOVE:
3546 /* remove the probe */
3547 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3548 cleanup_hook (pad, hook);
3550 case GST_PAD_PROBE_DROP:
3551 /* need to drop the data, make sure other probes don't get called
3553 GST_DEBUG_OBJECT (pad, "asked to drop item");
3554 info->type = GST_PAD_PROBE_TYPE_INVALID;
3555 data->dropped = TRUE;
3557 case GST_PAD_PROBE_HANDLED:
3558 GST_DEBUG_OBJECT (pad, "probe handled data");
3559 data->handled = TRUE;
3561 case GST_PAD_PROBE_PASS:
3562 /* inform the pad block to let things pass */
3563 GST_DEBUG_OBJECT (pad, "asked to pass item");
3566 case GST_PAD_PROBE_OK:
3567 GST_DEBUG_OBJECT (pad, "probe returned OK");
3570 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3577 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3578 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3579 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3584 /* a probe that does not take or return any data */
3585 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3587 if (G_UNLIKELY (pad->num_probes)) { \
3588 GstFlowReturn pval = defaultval; \
3589 /* pass NULL as the data item */ \
3590 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3591 info.ABI.abi.flow_ret = defaultval; \
3592 ret = do_probe_callbacks (pad, &info, defaultval); \
3593 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3598 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3600 if (G_UNLIKELY (pad->num_probes)) { \
3601 /* pass the data item */ \
3602 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3603 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3604 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3605 /* store the possibly updated data item */ \
3606 data = GST_PAD_PROBE_INFO_DATA (&info); \
3607 /* if something went wrong, exit */ \
3608 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3609 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3610 ret = info.ABI.abi.flow_ret; \
3611 goto handle_label; \
3618 #define PROBE_PUSH(pad,mask,data,label) \
3619 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3620 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3621 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3622 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3623 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3625 static GstFlowReturn
3626 do_pad_idle_probe_wait (GstPad * pad)
3628 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3629 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3630 "waiting idle probe to be removed");
3631 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3632 GST_PAD_BLOCK_WAIT (pad);
3633 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3634 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3636 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3637 return GST_FLOW_FLUSHING;
3642 #define PROBE_TYPE_IS_SERIALIZED(i) \
3645 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3646 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3647 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3649 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3650 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3652 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3653 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3657 static GstFlowReturn
3658 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3659 GstFlowReturn defaultval)
3668 data.handled = FALSE;
3669 data.marshalled = FALSE;
3670 data.dropped = FALSE;
3671 data.cookie = ++pad->priv->probe_cookie;
3674 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3676 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3677 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3682 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3683 "do probes cookie %u", data.cookie);
3684 cookie = pad->priv->probe_list_cookie;
3686 g_hook_list_marshal (&pad->probes, TRUE,
3687 (GHookMarshaller) probe_hook_marshal, &data);
3689 /* if the list changed, call the new callbacks (they will not have their
3690 * cookie set to data.cookie */
3691 if (cookie != pad->priv->probe_list_cookie) {
3692 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3693 "probe list changed, restarting");
3697 /* the first item that dropped will stop the hooks and then we drop here */
3701 /* If one handler took care of it, let the the item pass */
3706 /* if no handler matched and we are blocking, let the item pass */
3707 if (!data.marshalled && is_block)
3710 /* At this point, all handlers returned either OK or PASS. If one handler
3711 * returned PASS, let the item pass */
3716 while (GST_PAD_IS_BLOCKED (pad)) {
3717 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3718 "we are blocked %d times", pad->num_blocked);
3720 /* we might have released the lock */
3721 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3724 /* now we block the streaming thread. It can be unlocked when we
3725 * deactivate the pad (which will also set the FLUSHING flag) or
3726 * when the pad is unblocked. A flushing event will also unblock
3727 * the pad after setting the FLUSHING flag. */
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "Waiting to be unblocked or set flushing");
3730 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3731 GST_PAD_BLOCK_WAIT (pad);
3732 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3733 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3735 /* if the list changed, call the new callbacks (they will not have their
3736 * cookie set to data.cookie */
3737 if (cookie != pad->priv->probe_list_cookie) {
3738 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3739 "probe list changed, restarting");
3743 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3753 GST_DEBUG_OBJECT (pad, "pad is flushing");
3754 return GST_FLOW_FLUSHING;
3758 GST_DEBUG_OBJECT (pad, "data is dropped");
3759 return GST_FLOW_CUSTOM_SUCCESS;
3763 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3764 GST_DEBUG_OBJECT (pad, "data is passed");
3769 GST_DEBUG_OBJECT (pad, "data was handled");
3770 return GST_FLOW_CUSTOM_SUCCESS_1;
3777 * gst_pad_get_offset:
3780 * Get the offset applied to the running time of @pad. @pad has to be a source
3783 * Returns: the offset.
3786 gst_pad_get_offset (GstPad * pad)
3790 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3792 GST_OBJECT_LOCK (pad);
3793 result = pad->offset;
3794 GST_OBJECT_UNLOCK (pad);
3800 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3802 ev->received = FALSE;
3807 * gst_pad_set_offset:
3809 * @offset: the offset
3811 * Set the offset that will be applied to the running time of @pad.
3814 gst_pad_set_offset (GstPad * pad, gint64 offset)
3816 g_return_if_fail (GST_IS_PAD (pad));
3818 GST_OBJECT_LOCK (pad);
3819 /* if nothing changed, do nothing */
3820 if (pad->offset == offset)
3823 pad->offset = offset;
3824 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3825 GST_STIME_ARGS (offset));
3827 /* resend all sticky events with updated offset on next buffer push */
3828 events_foreach (pad, mark_event_not_received, NULL);
3829 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3832 GST_OBJECT_UNLOCK (pad);
3839 /* If TRUE and ret is not OK this means
3840 * that pushing the EOS event failed
3844 /* If called for an event this is
3845 * the event that would be pushed
3846 * next. Don't forward sticky events
3847 * that would come after that */
3851 /* should be called with pad LOCK */
3853 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3855 PushStickyData *data = user_data;
3856 GstEvent *event = ev->event;
3859 GST_DEBUG_OBJECT (pad, "event %s was already received",
3860 GST_EVENT_TYPE_NAME (event));
3864 /* If we're called because of an sticky event, only forward
3865 * events that would come before this new event and the
3867 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3868 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3869 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3870 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3872 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3873 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3874 if (data->ret == GST_FLOW_CUSTOM_SUCCESS_1)
3875 data->ret = GST_FLOW_OK;
3878 switch (data->ret) {
3880 ev->received = TRUE;
3881 GST_DEBUG_OBJECT (pad, "event %s marked received",
3882 GST_EVENT_TYPE_NAME (event));
3884 case GST_FLOW_CUSTOM_SUCCESS:
3885 /* we can't assume the event is received when it was dropped */
3886 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3887 GST_EVENT_TYPE_NAME (event));
3888 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3889 data->ret = GST_FLOW_OK;
3891 case GST_FLOW_CUSTOM_SUCCESS_1:
3892 /* event was ignored and should be sent later */
3893 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3894 GST_EVENT_TYPE_NAME (event));
3895 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3896 data->ret = GST_FLOW_OK;
3898 case GST_FLOW_NOT_LINKED:
3899 /* not linked is not a problem, we are sticky so the event will be
3900 * rescheduled to be sent later on re-link, but only for non-EOS events */
3901 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3902 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3903 data->ret = GST_FLOW_OK;
3904 ev->received = TRUE;
3908 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3909 gst_flow_get_name (data->ret));
3910 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3914 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3915 data->was_eos = TRUE;
3917 return data->ret == GST_FLOW_OK;
3920 /* check sticky events and push them when needed. should be called
3922 static inline GstFlowReturn
3923 check_sticky (GstPad * pad, GstEvent * event)
3925 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3927 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3928 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3930 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3931 events_foreach (pad, push_sticky, &data);
3933 /* If there's an EOS event we must push it downstream
3934 * even if sending a previous sticky event failed.
3935 * Otherwise the pipeline might wait forever for EOS.
3937 * Only do this if pushing another event than the EOS
3940 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3941 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3943 if (ev && !ev->received) {
3944 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3945 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3946 /* the event could have been dropped. Because this can only
3947 * happen if the user asked for it, it's not an error */
3948 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3949 data.ret = GST_FLOW_OK;
3959 * @pad: a #GstPad to invoke the default query on.
3960 * @query: (transfer none): the #GstQuery to perform.
3962 * Dispatches a query to a pad. The query should have been allocated by the
3963 * caller via one of the type-specific allocation functions. The element that
3964 * the pad belongs to is responsible for filling the query with an appropriate
3965 * response, which should then be parsed with a type-specific query parsing
3968 * Again, the caller is responsible for both the allocation and deallocation of
3969 * the query structure.
3971 * Please also note that some queries might need a running pipeline to work.
3973 * Returns: %TRUE if the query could be performed.
3976 gst_pad_query (GstPad * pad, GstQuery * query)
3979 gboolean res, serialized;
3980 GstPadQueryFunction func;
3981 GstPadProbeType type;
3984 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3985 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3987 if (GST_PAD_IS_SRC (pad)) {
3988 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3989 goto wrong_direction;
3990 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3991 } else if (GST_PAD_IS_SINK (pad)) {
3992 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3993 goto wrong_direction;
3994 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3996 goto unknown_direction;
3998 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3999 GST_QUERY_TYPE_NAME (query));
4000 GST_TRACER_PAD_QUERY_PRE (pad, query);
4002 serialized = GST_QUERY_IS_SERIALIZED (query);
4003 if (G_UNLIKELY (serialized))
4004 GST_PAD_STREAM_LOCK (pad);
4006 GST_OBJECT_LOCK (pad);
4007 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4008 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4009 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4011 ACQUIRE_PARENT (pad, parent, no_parent);
4012 GST_OBJECT_UNLOCK (pad);
4014 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
4017 res = func (pad, parent, query);
4019 RELEASE_PARENT (parent);
4021 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
4022 GST_QUERY_TYPE_NAME (query), res);
4023 GST_TRACER_PAD_QUERY_POST (pad, query, res);
4028 GST_OBJECT_LOCK (pad);
4029 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4030 GST_OBJECT_UNLOCK (pad);
4032 if (G_UNLIKELY (serialized))
4033 GST_PAD_STREAM_UNLOCK (pad);
4040 g_warning ("pad %s:%s query %s in wrong direction",
4041 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4046 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4051 GST_DEBUG_OBJECT (pad, "had no parent");
4052 GST_OBJECT_UNLOCK (pad);
4053 if (G_UNLIKELY (serialized))
4054 GST_PAD_STREAM_UNLOCK (pad);
4059 GST_DEBUG_OBJECT (pad, "had no query function");
4060 RELEASE_PARENT (parent);
4061 if (G_UNLIKELY (serialized))
4062 GST_PAD_STREAM_UNLOCK (pad);
4067 GST_DEBUG_OBJECT (pad, "query failed");
4068 if (G_UNLIKELY (serialized))
4069 GST_PAD_STREAM_UNLOCK (pad);
4074 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4075 GST_OBJECT_UNLOCK (pad);
4076 if (G_UNLIKELY (serialized))
4077 GST_PAD_STREAM_UNLOCK (pad);
4079 /* if a probe dropped without handling, we don't sent it further but assume
4080 * that the probe did not answer the query and return FALSE */
4081 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4091 * gst_pad_peer_query:
4092 * @pad: a #GstPad to invoke the peer query on.
4093 * @query: (transfer none): the #GstQuery to perform.
4095 * Performs gst_pad_query() on the peer of @pad.
4097 * The caller is responsible for both the allocation and deallocation of
4098 * the query structure.
4100 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4101 * if @pad has no peer.
4104 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4107 GstPadProbeType type;
4108 gboolean res, serialized;
4111 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4112 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4114 if (GST_PAD_IS_SRC (pad)) {
4115 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4116 goto wrong_direction;
4117 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4118 } else if (GST_PAD_IS_SINK (pad)) {
4119 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4120 goto wrong_direction;
4121 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4123 goto unknown_direction;
4125 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4126 GST_QUERY_TYPE_NAME (query));
4128 serialized = GST_QUERY_IS_SERIALIZED (query);
4130 GST_OBJECT_LOCK (pad);
4131 if (GST_PAD_IS_SRC (pad) && serialized) {
4132 /* all serialized queries on the srcpad trigger push of
4134 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4138 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4139 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4140 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4142 peerpad = GST_PAD_PEER (pad);
4143 if (G_UNLIKELY (peerpad == NULL))
4146 gst_object_ref (peerpad);
4147 GST_OBJECT_UNLOCK (pad);
4149 res = gst_pad_query (peerpad, query);
4151 gst_object_unref (peerpad);
4156 GST_OBJECT_LOCK (pad);
4157 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4158 GST_OBJECT_UNLOCK (pad);
4165 g_warning ("pad %s:%s query %s in wrong direction",
4166 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4171 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4176 GST_WARNING_OBJECT (pad, "could not send sticky events");
4177 GST_OBJECT_UNLOCK (pad);
4182 GST_INFO_OBJECT (pad, "pad has no peer");
4183 GST_OBJECT_UNLOCK (pad);
4188 GST_DEBUG_OBJECT (pad, "query failed");
4193 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4194 GST_OBJECT_UNLOCK (pad);
4196 /* if a probe dropped without handling, we don't sent it further but
4197 * assume that the probe did not answer the query and return FALSE */
4198 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4207 /**********************************************************************
4208 * Data passing functions
4211 /* this is the chain function that does not perform the additional argument
4212 * checking for that little extra speed.
4214 static inline GstFlowReturn
4215 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4219 gboolean handled = FALSE;
4221 GST_PAD_STREAM_LOCK (pad);
4223 GST_OBJECT_LOCK (pad);
4224 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4227 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4230 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4233 #ifdef GST_ENABLE_EXTRA_CHECKS
4234 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4235 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4237 ":%s:<%s:%s> Got data flow before stream-start event",
4238 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4240 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4242 ":%s:<%s:%s> Got data flow before segment event",
4243 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4245 pad->priv->last_cookie = pad->priv->events_cookie;
4249 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4252 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4254 ACQUIRE_PARENT (pad, parent, no_parent);
4255 GST_OBJECT_UNLOCK (pad);
4257 /* NOTE: we read the chainfunc unlocked.
4258 * we cannot hold the lock for the pad so we might send
4259 * the data to the wrong function. This is not really a
4260 * problem since functions are assigned at creation time
4261 * and don't change that often... */
4262 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4263 GstPadChainFunction chainfunc;
4265 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4268 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4269 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4270 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4272 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4274 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4275 "called chainfunction &%s with buffer %p, returned %s",
4276 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4278 GstPadChainListFunction chainlistfunc;
4280 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4283 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4284 "calling chainlistfunction &%s",
4285 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4287 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4289 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4290 "called chainlistfunction &%s, returned %s",
4291 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4294 RELEASE_PARENT (parent);
4296 GST_PAD_STREAM_UNLOCK (pad);
4303 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4304 "chaining, but pad was flushing");
4305 GST_OBJECT_UNLOCK (pad);
4306 GST_PAD_STREAM_UNLOCK (pad);
4307 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4308 return GST_FLOW_FLUSHING;
4312 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4313 GST_OBJECT_UNLOCK (pad);
4314 GST_PAD_STREAM_UNLOCK (pad);
4315 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4316 return GST_FLOW_EOS;
4320 g_critical ("chain on pad %s:%s but it was not in push mode",
4321 GST_DEBUG_PAD_NAME (pad));
4322 GST_OBJECT_UNLOCK (pad);
4323 GST_PAD_STREAM_UNLOCK (pad);
4324 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4325 return GST_FLOW_ERROR;
4332 GST_OBJECT_UNLOCK (pad);
4333 GST_PAD_STREAM_UNLOCK (pad);
4334 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4336 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4339 case GST_FLOW_CUSTOM_SUCCESS:
4340 case GST_FLOW_CUSTOM_SUCCESS_1:
4341 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4345 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4352 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4353 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4354 GST_OBJECT_UNLOCK (pad);
4355 GST_PAD_STREAM_UNLOCK (pad);
4356 return GST_FLOW_FLUSHING;
4360 RELEASE_PARENT (parent);
4361 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4362 g_critical ("chain on pad %s:%s but it has no chainfunction",
4363 GST_DEBUG_PAD_NAME (pad));
4364 GST_PAD_STREAM_UNLOCK (pad);
4365 return GST_FLOW_NOT_SUPPORTED;
4371 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4372 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4375 * Chain a buffer to @pad.
4377 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4379 * If the buffer type is not acceptable for @pad (as negotiated with a
4380 * preceding GST_EVENT_CAPS event), this function returns
4381 * #GST_FLOW_NOT_NEGOTIATED.
4383 * The function proceeds calling the chain function installed on @pad (see
4384 * gst_pad_set_chain_function()) and the return value of that function is
4385 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4388 * In all cases, success or failure, the caller loses its reference to @buffer
4389 * after calling this function.
4391 * Returns: a #GstFlowReturn from the pad.
4396 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4398 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4399 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4400 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4402 return gst_pad_chain_data_unchecked (pad,
4403 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4406 static GstFlowReturn
4407 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4408 GstBufferList * list)
4414 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4416 len = gst_buffer_list_length (list);
4419 for (i = 0; i < len; i++) {
4420 buffer = gst_buffer_list_get (list, i);
4422 gst_pad_chain_data_unchecked (pad,
4423 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4424 gst_buffer_ref (buffer));
4425 if (ret != GST_FLOW_OK)
4428 gst_buffer_list_unref (list);
4434 * gst_pad_chain_list:
4435 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4436 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4439 * Chain a bufferlist to @pad.
4441 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4443 * If @pad was not negotiated properly with a CAPS event, this function
4444 * returns #GST_FLOW_NOT_NEGOTIATED.
4446 * The function proceeds calling the chainlist function installed on @pad (see
4447 * gst_pad_set_chain_list_function()) and the return value of that function is
4448 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4449 * chainlist function.
4451 * In all cases, success or failure, the caller loses its reference to @list
4452 * after calling this function.
4456 * Returns: a #GstFlowReturn from the pad.
4459 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4461 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4462 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4463 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4465 return gst_pad_chain_data_unchecked (pad,
4466 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4469 static GstFlowReturn
4470 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4474 gboolean handled = FALSE;
4476 GST_OBJECT_LOCK (pad);
4477 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4480 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4483 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4486 #ifdef GST_ENABLE_EXTRA_CHECKS
4487 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4488 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4490 ":%s:<%s:%s> Got data flow before stream-start event",
4491 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4493 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4495 ":%s:<%s:%s> Got data flow before segment event",
4496 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4498 pad->priv->last_cookie = pad->priv->events_cookie;
4502 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4505 /* do block probes */
4506 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4509 /* recheck sticky events because the probe might have cause a relink */
4510 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4513 /* do post-blocking probes */
4514 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4516 /* recheck sticky events because the probe might have cause a relink */
4517 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4520 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4523 /* take ref to peer pad before releasing the lock */
4524 gst_object_ref (peer);
4526 GST_OBJECT_UNLOCK (pad);
4528 ret = gst_pad_chain_data_unchecked (peer, type, data);
4531 gst_object_unref (peer);
4533 GST_OBJECT_LOCK (pad);
4534 pad->ABI.abi.last_flowret = ret;
4536 if (pad->priv->using == 0) {
4537 /* pad is not active anymore, trigger idle callbacks */
4538 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4539 probe_stopped, ret);
4541 GST_OBJECT_UNLOCK (pad);
4545 /* ERROR recovery here */
4549 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4550 "pushing, but pad was flushing");
4551 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4552 GST_OBJECT_UNLOCK (pad);
4553 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4554 return GST_FLOW_FLUSHING;
4558 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4559 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4560 GST_OBJECT_UNLOCK (pad);
4561 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4562 return GST_FLOW_EOS;
4566 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4567 GST_DEBUG_PAD_NAME (pad));
4568 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4569 GST_OBJECT_UNLOCK (pad);
4570 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4571 return GST_FLOW_ERROR;
4575 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4576 "error pushing events, return %s", gst_flow_get_name (ret));
4577 pad->ABI.abi.last_flowret = ret;
4578 GST_OBJECT_UNLOCK (pad);
4579 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4587 GST_OBJECT_UNLOCK (pad);
4588 if (data != NULL && !handled)
4589 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4592 case GST_FLOW_CUSTOM_SUCCESS:
4593 case GST_FLOW_CUSTOM_SUCCESS_1:
4594 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4598 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4601 pad->ABI.abi.last_flowret = ret;
4606 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4607 "pushing, but it was not linked");
4608 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4609 GST_OBJECT_UNLOCK (pad);
4610 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4611 return GST_FLOW_NOT_LINKED;
4617 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4618 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4621 * Pushes a buffer to the peer of @pad.
4623 * This function will call installed block probes before triggering any
4624 * installed data probes.
4626 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4627 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4630 * In all cases, success or failure, the caller loses its reference to @buffer
4631 * after calling this function.
4633 * Returns: a #GstFlowReturn from the peer pad.
4638 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4642 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4643 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4644 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4646 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4647 res = gst_pad_push_data (pad,
4648 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4649 GST_TRACER_PAD_PUSH_POST (pad, res);
4654 * gst_pad_push_list:
4655 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4656 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4659 * Pushes a buffer list to the peer of @pad.
4661 * This function will call installed block probes before triggering any
4662 * installed data probes.
4664 * The function proceeds calling the chain function on the peer pad and returns
4665 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4666 * be returned. If the peer pad does not have any installed chainlist function
4667 * every group buffer of the list will be merged into a normal #GstBuffer and
4668 * chained via gst_pad_chain().
4670 * In all cases, success or failure, the caller loses its reference to @list
4671 * after calling this function.
4673 * Returns: a #GstFlowReturn from the peer pad.
4678 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4682 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4683 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4684 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4686 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4687 res = gst_pad_push_data (pad,
4688 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4689 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4693 static GstFlowReturn
4694 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4695 GstBuffer ** buffer)
4698 GstPadGetRangeFunction getrangefunc;
4702 GST_PAD_STREAM_LOCK (pad);
4704 GST_OBJECT_LOCK (pad);
4705 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4708 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4711 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4716 /* when one of the probes returns DROPPED, probe_stopped will be called
4717 * and we skip calling the getrange function, res_buf should then contain a
4718 * valid result buffer */
4719 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4720 res_buf, offset, size, probe_stopped);
4722 /* recheck sticky events because the probe might have cause a relink */
4723 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4726 ACQUIRE_PARENT (pad, parent, no_parent);
4727 GST_OBJECT_UNLOCK (pad);
4729 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4732 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4733 "calling getrangefunc %s, offset %"
4734 G_GUINT64_FORMAT ", size %u",
4735 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4737 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4739 RELEASE_PARENT (parent);
4741 GST_OBJECT_LOCK (pad);
4742 if (G_UNLIKELY (ret != GST_FLOW_OK))
4743 goto get_range_failed;
4745 /* can only fire the signal if we have a valid buffer */
4747 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4748 res_buf, offset, size, probe_stopped_unref);
4749 pad->ABI.abi.last_flowret = ret;
4750 GST_OBJECT_UNLOCK (pad);
4752 GST_PAD_STREAM_UNLOCK (pad);
4761 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4762 "getrange, but pad was flushing");
4763 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4764 GST_OBJECT_UNLOCK (pad);
4765 GST_PAD_STREAM_UNLOCK (pad);
4766 return GST_FLOW_FLUSHING;
4770 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4771 GST_DEBUG_PAD_NAME (pad));
4772 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4773 GST_OBJECT_UNLOCK (pad);
4774 GST_PAD_STREAM_UNLOCK (pad);
4775 return GST_FLOW_ERROR;
4779 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4780 pad->ABI.abi.last_flowret = ret;
4781 GST_OBJECT_UNLOCK (pad);
4782 GST_PAD_STREAM_UNLOCK (pad);
4787 GST_DEBUG_OBJECT (pad, "no parent");
4788 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4789 GST_OBJECT_UNLOCK (pad);
4790 GST_PAD_STREAM_UNLOCK (pad);
4791 return GST_FLOW_FLUSHING;
4795 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4796 GST_DEBUG_PAD_NAME (pad));
4797 RELEASE_PARENT (parent);
4798 GST_PAD_STREAM_UNLOCK (pad);
4799 return GST_FLOW_NOT_SUPPORTED;
4803 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4804 "probe returned %s", gst_flow_get_name (ret));
4805 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4807 /* the probe filled the buffer and asks us to not call the getrange
4808 * anymore, we continue with the post probes then. */
4809 GST_DEBUG_OBJECT (pad, "handled buffer");
4813 /* no buffer, we are EOS */
4814 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4818 pad->ABI.abi.last_flowret = ret;
4819 GST_OBJECT_UNLOCK (pad);
4820 GST_PAD_STREAM_UNLOCK (pad);
4824 probe_stopped_unref:
4826 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4827 "probe returned %s", gst_flow_get_name (ret));
4828 /* if we drop here, it signals EOS */
4829 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4831 pad->ABI.abi.last_flowret = ret;
4832 GST_OBJECT_UNLOCK (pad);
4833 GST_PAD_STREAM_UNLOCK (pad);
4834 if (*buffer == NULL)
4835 gst_buffer_unref (res_buf);
4840 pad->ABI.abi.last_flowret = ret;
4841 GST_OBJECT_UNLOCK (pad);
4842 GST_PAD_STREAM_UNLOCK (pad);
4843 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4844 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4845 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4851 * gst_pad_get_range:
4852 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4853 * @offset: The start offset of the buffer
4854 * @size: The length of the buffer
4855 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4856 * returns #GST_FLOW_ERROR if %NULL.
4858 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4859 * immediately and @buffer is %NULL.
4861 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4862 * description of a getrange function. If @pad has no getrange function
4863 * installed (see gst_pad_set_getrange_function()) this function returns
4864 * #GST_FLOW_NOT_SUPPORTED.
4866 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4867 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4868 * must be freed with gst_buffer_unref() after usage.
4870 * When @buffer points to a variable that points to a valid #GstBuffer, the
4871 * buffer will be filled with the result data when this function returns
4872 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4873 * @size bytes will be filled in the result buffer and its size will be updated
4876 * Note that less than @size bytes can be returned in @buffer when, for example,
4877 * an EOS condition is near or when @buffer is not large enough to hold @size
4878 * bytes. The caller should check the result buffer size to get the result size.
4880 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4881 * will be unchanged.
4883 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4885 * Returns: a #GstFlowReturn from the pad.
4890 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4891 GstBuffer ** buffer)
4893 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4894 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4895 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4896 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4897 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4899 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4903 * gst_pad_pull_range:
4904 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4905 * @offset: The start offset of the buffer
4906 * @size: The length of the buffer
4907 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4908 * GST_FLOW_ERROR if %NULL.
4910 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4912 * This function will first trigger the pad block signal if it was
4915 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4916 * function returns the result of gst_pad_get_range() on the peer pad.
4917 * See gst_pad_get_range() for a list of return values and for the
4918 * semantics of the arguments of this function.
4920 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4921 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4922 * must be freed with gst_buffer_unref() after usage. When this function
4923 * returns any other result value, @buffer will still point to %NULL.
4925 * When @buffer points to a variable that points to a valid #GstBuffer, the
4926 * buffer will be filled with the result data when this function returns
4927 * #GST_FLOW_OK. When this function returns any other result value,
4928 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4929 * @size bytes will be filled in the result buffer and its size will be updated
4932 * Note that less than @size bytes can be returned in @buffer when, for example,
4933 * an EOS condition is near or when @buffer is not large enough to hold @size
4934 * bytes. The caller should check the result buffer size to get the result size.
4936 * Returns: a #GstFlowReturn from the peer pad.
4941 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4942 GstBuffer ** buffer)
4948 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4949 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4950 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4951 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4952 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4954 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4956 GST_OBJECT_LOCK (pad);
4957 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4960 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4965 /* when one of the probes returns DROPPED, probe_stopped will be
4966 * called and we skip calling the peer getrange function. *buffer should then
4967 * contain a valid buffer */
4968 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4969 res_buf, offset, size, probe_stopped);
4971 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4974 gst_object_ref (peer);
4976 GST_OBJECT_UNLOCK (pad);
4978 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4980 gst_object_unref (peer);
4982 GST_OBJECT_LOCK (pad);
4984 pad->ABI.abi.last_flowret = ret;
4985 if (pad->priv->using == 0) {
4986 /* pad is not active anymore, trigger idle callbacks */
4987 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4988 probe_stopped_unref, ret);
4991 if (G_UNLIKELY (ret != GST_FLOW_OK))
4992 goto pull_range_failed;
4995 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4996 res_buf, offset, size, probe_stopped_unref);
4998 GST_OBJECT_UNLOCK (pad);
5002 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
5005 /* ERROR recovery here */
5008 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5009 "pullrange, but pad was flushing");
5010 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
5011 GST_OBJECT_UNLOCK (pad);
5012 ret = GST_FLOW_FLUSHING;
5017 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
5018 GST_DEBUG_PAD_NAME (pad));
5019 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
5020 GST_OBJECT_UNLOCK (pad);
5021 ret = GST_FLOW_ERROR;
5026 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
5027 gst_flow_get_name (ret));
5028 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
5030 /* the probe filled the buffer and asks us to not forward to the peer
5031 * anymore, we continue with the post probes then */
5032 GST_DEBUG_OBJECT (pad, "handled buffer");
5036 /* no buffer, we are EOS then */
5037 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5041 pad->ABI.abi.last_flowret = ret;
5042 GST_OBJECT_UNLOCK (pad);
5047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5048 "pulling range, but it was not linked");
5049 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5050 GST_OBJECT_UNLOCK (pad);
5051 ret = GST_FLOW_NOT_LINKED;
5056 pad->ABI.abi.last_flowret = ret;
5057 GST_OBJECT_UNLOCK (pad);
5058 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5059 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5060 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5063 probe_stopped_unref:
5065 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5066 "post probe returned %s", gst_flow_get_name (ret));
5068 /* if we drop here, it signals EOS */
5069 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5072 pad->ABI.abi.last_flowret = ret;
5073 GST_OBJECT_UNLOCK (pad);
5075 if (*buffer == NULL)
5076 gst_buffer_unref (res_buf);
5080 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5084 /* must be called with pad object lock */
5085 static GstFlowReturn
5086 store_sticky_event (GstPad * pad, GstEvent * event)
5091 gboolean res = FALSE;
5092 const gchar *name = NULL;
5093 gboolean insert = TRUE;
5095 type = GST_EVENT_TYPE (event);
5097 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5098 * otherwise they can be dropped and nothing would ever resend them.
5099 * Only do that for activated pads though, everything else is a bug!
5101 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5102 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5103 || type == GST_EVENT_EOS))))
5106 /* Unset the EOS flag when received STREAM_START event, so pad can
5107 * store sticky event and then push it later */
5108 if (type == GST_EVENT_STREAM_START) {
5109 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5110 remove_event_by_type (pad, GST_EVENT_EOS);
5111 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5112 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5115 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5118 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5119 name = gst_structure_get_name (gst_event_get_structure (event));
5121 events = pad->priv->events;
5124 for (i = 0; i < len; i++) {
5125 PadEvent *ev = &g_array_index (events, PadEvent, i);
5127 if (ev->event == NULL)
5130 if (type == GST_EVENT_TYPE (ev->event)) {
5131 /* matching types, check matching name if needed */
5132 if (name && !gst_event_has_name (ev->event, name))
5136 if ((res = gst_event_replace (&ev->event, event)))
5137 ev->received = FALSE;
5143 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5144 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5145 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5146 * storing the sticky ordered we can check that this is respected. */
5147 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5148 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5150 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5151 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5152 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5153 gst_event_type_get_name (type));
5159 ev.event = gst_event_ref (event);
5160 ev.received = FALSE;
5161 g_array_insert_val (events, i, ev);
5166 pad->priv->events_cookie++;
5167 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5169 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5171 switch (GST_EVENT_TYPE (event)) {
5172 case GST_EVENT_CAPS:
5173 GST_OBJECT_UNLOCK (pad);
5175 GST_DEBUG_OBJECT (pad, "notify caps");
5176 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5178 GST_OBJECT_LOCK (pad);
5184 if (type == GST_EVENT_EOS) {
5185 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5186 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5189 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5194 GST_DEBUG_OBJECT (pad, "pad is flushing");
5195 return GST_FLOW_FLUSHING;
5199 GST_DEBUG_OBJECT (pad, "pad is EOS");
5200 return GST_FLOW_EOS;
5205 * gst_pad_store_sticky_event:
5207 * @event: (transfer none): a #GstEvent
5209 * Store the sticky @event on @pad
5211 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5212 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5217 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5221 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5222 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5224 GST_OBJECT_LOCK (pad);
5225 ret = store_sticky_event (pad, event);
5226 GST_OBJECT_UNLOCK (pad);
5232 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5234 PushStickyData *data = user_data;
5236 /* Forward all sticky events before our current one that are pending */
5237 if (ev->event != data->event
5238 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5239 return push_sticky (pad, ev, data);
5244 /* should be called with pad LOCK */
5245 static GstFlowReturn
5246 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5247 GstPadProbeType type)
5251 GstEventType event_type;
5253 /* pass the adjusted event on. We need to do this even if
5254 * there is no peer pad because of the probes. */
5255 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5257 /* Two checks to be made:
5258 * . (un)set the FLUSHING flag for flushing events,
5259 * . handle pad blocking */
5260 event_type = GST_EVENT_TYPE (event);
5261 switch (event_type) {
5262 case GST_EVENT_FLUSH_START:
5263 GST_PAD_SET_FLUSHING (pad);
5265 GST_PAD_BLOCK_BROADCAST (pad);
5266 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5268 case GST_EVENT_FLUSH_STOP:
5269 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5272 GST_PAD_UNSET_FLUSHING (pad);
5274 /* Remove sticky EOS events */
5275 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5276 remove_event_by_type (pad, GST_EVENT_EOS);
5277 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5278 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5279 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5280 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5282 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5286 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5289 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5290 * checked already or this is called as part of pushing sticky events,
5291 * in which case we still want to forward the EOS event downstream.
5294 switch (GST_EVENT_TYPE (event)) {
5295 case GST_EVENT_RECONFIGURE:
5296 if (GST_PAD_IS_SINK (pad))
5297 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5302 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5303 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5304 /* recheck sticky events because the probe might have cause a relink */
5305 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5306 && (GST_EVENT_IS_SERIALIZED (event)
5307 || GST_EVENT_IS_STICKY (event))) {
5308 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5309 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5311 /* Push all sticky events before our current one
5312 * that have changed */
5313 events_foreach (pad, sticky_changed, &data);
5319 /* send probes after modifying the events above */
5320 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5322 /* recheck sticky events because the probe might have cause a relink */
5323 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5324 && (GST_EVENT_IS_SERIALIZED (event)
5325 || GST_EVENT_IS_STICKY (event))) {
5326 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5327 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5329 /* Push all sticky events before our current one
5330 * that have changed */
5331 events_foreach (pad, sticky_changed, &data);
5334 /* now check the peer pad */
5335 peerpad = GST_PAD_PEER (pad);
5336 if (peerpad == NULL)
5339 gst_object_ref (peerpad);
5341 GST_OBJECT_UNLOCK (pad);
5343 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5344 event, gst_event_type_get_name (event_type), peerpad);
5346 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5348 /* Note: we gave away ownership of the event at this point but we can still
5349 * print the old pointer */
5350 GST_LOG_OBJECT (pad,
5351 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5352 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5354 gst_object_unref (peerpad);
5356 GST_OBJECT_LOCK (pad);
5358 if (pad->priv->using == 0) {
5359 /* pad is not active anymore, trigger idle callbacks */
5360 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5361 idle_probe_stopped, ret);
5365 /* ERROR handling */
5368 GST_DEBUG_OBJECT (pad, "We're flushing");
5369 gst_event_unref (event);
5370 return GST_FLOW_FLUSHING;
5374 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5375 gst_event_unref (event);
5376 return GST_FLOW_FLUSHING;
5380 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5381 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5382 gst_event_unref (event);
5385 case GST_FLOW_CUSTOM_SUCCESS_1:
5386 GST_DEBUG_OBJECT (pad, "handled event");
5388 case GST_FLOW_CUSTOM_SUCCESS:
5389 GST_DEBUG_OBJECT (pad, "dropped event");
5392 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5399 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5400 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5401 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5402 gst_event_unref (event);
5404 /* unlinked pads should not influence latency configuration */
5405 if (event_type == GST_EVENT_LATENCY)
5408 return GST_FLOW_NOT_LINKED;
5412 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5418 * gst_pad_push_event:
5419 * @pad: a #GstPad to push the event to.
5420 * @event: (transfer full): the #GstEvent to send to the pad.
5422 * Sends the event to the peer of the given pad. This function is
5423 * mainly used by elements to send events to their peer
5426 * This function takes ownership of the provided event so you should
5427 * gst_event_ref() it if you want to reuse the event after this call.
5429 * Returns: %TRUE if the event was handled.
5434 gst_pad_push_event (GstPad * pad, GstEvent * event)
5436 gboolean res = FALSE;
5437 GstPadProbeType type;
5438 gboolean sticky, serialized;
5440 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5441 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5443 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5445 if (GST_PAD_IS_SRC (pad)) {
5446 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5447 goto wrong_direction;
5448 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5449 } else if (GST_PAD_IS_SINK (pad)) {
5450 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5451 goto wrong_direction;
5452 /* events pushed on sinkpad never are sticky */
5453 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5455 goto unknown_direction;
5457 GST_OBJECT_LOCK (pad);
5458 sticky = GST_EVENT_IS_STICKY (event);
5459 serialized = GST_EVENT_IS_SERIALIZED (event);
5462 /* srcpad sticky events are stored immediately, the received flag is set
5463 * to FALSE and will be set to TRUE when we can successfully push the
5464 * event to the peer pad */
5465 switch (store_sticky_event (pad, event)) {
5466 case GST_FLOW_FLUSHING:
5474 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5475 /* all serialized or sticky events on the srcpad trigger push of
5477 res = (check_sticky (pad, event) == GST_FLOW_OK);
5482 /* other events are pushed right away */
5483 ret = gst_pad_push_event_unchecked (pad, event, type);
5484 /* dropped events by a probe are not an error */
5485 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5486 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5488 /* Errors in sticky event pushing are no problem and ignored here
5489 * as they will cause more meaningful errors during data flow.
5490 * For EOS events, that are not followed by data flow, we still
5491 * return FALSE here though.
5493 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5495 gst_event_unref (event);
5497 GST_OBJECT_UNLOCK (pad);
5499 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5502 /* ERROR handling */
5505 g_warning ("pad %s:%s pushing %s event in wrong direction",
5506 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5507 gst_event_unref (event);
5512 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5513 gst_event_unref (event);
5518 GST_DEBUG_OBJECT (pad, "We're flushing");
5519 GST_OBJECT_UNLOCK (pad);
5520 gst_event_unref (event);
5525 GST_DEBUG_OBJECT (pad, "We're EOS");
5526 GST_OBJECT_UNLOCK (pad);
5527 gst_event_unref (event);
5531 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5535 /* Check if we can call the event function with the given event */
5536 static GstFlowReturn
5537 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5541 switch (GST_EVENT_TYPE (event)) {
5542 case GST_EVENT_CAPS:
5544 /* backwards compatibility mode for caps */
5545 gst_event_parse_caps (event, &caps);
5547 if (!gst_pad_query_accept_caps (pad, caps))
5559 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5560 "caps %" GST_PTR_FORMAT " not accepted", caps);
5561 return GST_FLOW_NOT_NEGOTIATED;
5565 static GstFlowReturn
5566 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5567 GstPadProbeType type)
5570 GstEventType event_type;
5571 gboolean serialized, need_unlock = FALSE, sticky;
5572 GstPadEventFunction eventfunc;
5573 GstPadEventFullFunction eventfullfunc = NULL;
5576 GST_OBJECT_LOCK (pad);
5578 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5580 if (GST_PAD_IS_SINK (pad))
5581 serialized = GST_EVENT_IS_SERIALIZED (event);
5584 sticky = GST_EVENT_IS_STICKY (event);
5585 event_type = GST_EVENT_TYPE (event);
5586 switch (event_type) {
5587 case GST_EVENT_FLUSH_START:
5588 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5589 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5591 /* can't even accept a flush begin event when flushing */
5592 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5595 GST_PAD_SET_FLUSHING (pad);
5596 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5597 GST_PAD_BLOCK_BROADCAST (pad);
5598 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5600 case GST_EVENT_FLUSH_STOP:
5601 /* we can't accept flush-stop on inactive pads else the flushing flag
5602 * would be cleared and it would look like the pad can accept data.
5603 * Also, some elements restart a streaming thread in flush-stop which we
5604 * can't allow on inactive pads */
5605 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5608 GST_PAD_UNSET_FLUSHING (pad);
5609 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5610 /* Remove pending EOS events */
5611 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5612 remove_event_by_type (pad, GST_EVENT_EOS);
5613 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5614 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5615 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5616 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5618 GST_OBJECT_UNLOCK (pad);
5619 /* grab stream lock */
5620 GST_PAD_STREAM_LOCK (pad);
5622 GST_OBJECT_LOCK (pad);
5623 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5626 case GST_EVENT_RECONFIGURE:
5627 if (GST_PAD_IS_SRC (pad))
5628 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5630 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5631 "have event type %" GST_PTR_FORMAT, event);
5633 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5636 switch (event_type) {
5637 case GST_EVENT_STREAM_START:
5638 /* Remove sticky EOS events */
5639 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5640 remove_event_by_type (pad, GST_EVENT_EOS);
5641 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5642 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5649 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5652 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5653 GST_OBJECT_UNLOCK (pad);
5654 GST_PAD_STREAM_LOCK (pad);
5656 GST_OBJECT_LOCK (pad);
5657 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5660 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5666 /* now do the probe */
5668 type | GST_PAD_PROBE_TYPE_PUSH |
5669 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5671 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5673 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5674 eventfunc = GST_PAD_EVENTFUNC (pad);
5675 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5678 ACQUIRE_PARENT (pad, parent, no_parent);
5679 GST_OBJECT_UNLOCK (pad);
5681 ret = pre_eventfunc_check (pad, event);
5682 if (G_UNLIKELY (ret != GST_FLOW_OK))
5683 goto precheck_failed;
5686 gst_event_ref (event);
5688 if (eventfullfunc) {
5689 ret = eventfullfunc (pad, parent, event);
5690 } else if (eventfunc (pad, parent, event)) {
5693 /* something went wrong */
5694 switch (event_type) {
5695 case GST_EVENT_CAPS:
5696 ret = GST_FLOW_NOT_NEGOTIATED;
5699 ret = GST_FLOW_ERROR;
5703 RELEASE_PARENT (parent);
5705 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5708 if (ret == GST_FLOW_OK) {
5709 GST_OBJECT_LOCK (pad);
5710 /* after the event function accepted the event, we can store the sticky
5711 * event on the pad */
5712 switch (store_sticky_event (pad, event)) {
5713 case GST_FLOW_FLUSHING:
5720 GST_OBJECT_UNLOCK (pad);
5722 gst_event_unref (event);
5726 GST_PAD_STREAM_UNLOCK (pad);
5730 /* ERROR handling */
5733 GST_OBJECT_UNLOCK (pad);
5735 GST_PAD_STREAM_UNLOCK (pad);
5736 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5737 "Received event on flushing pad. Discarding");
5738 gst_event_unref (event);
5739 return GST_FLOW_FLUSHING;
5743 GST_OBJECT_UNLOCK (pad);
5745 GST_PAD_STREAM_UNLOCK (pad);
5746 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5747 "Received flush-stop on inactive pad. Discarding");
5748 gst_event_unref (event);
5749 return GST_FLOW_FLUSHING;
5753 GST_OBJECT_UNLOCK (pad);
5755 GST_PAD_STREAM_UNLOCK (pad);
5756 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5757 "Received event on EOS pad. Discarding");
5758 gst_event_unref (event);
5759 return GST_FLOW_EOS;
5763 GST_OBJECT_UNLOCK (pad);
5765 GST_PAD_STREAM_UNLOCK (pad);
5766 /* Only unref if unhandled */
5767 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5768 gst_event_unref (event);
5771 case GST_FLOW_CUSTOM_SUCCESS_1:
5772 case GST_FLOW_CUSTOM_SUCCESS:
5773 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5777 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5784 g_warning ("pad %s:%s has no event handler, file a bug.",
5785 GST_DEBUG_PAD_NAME (pad));
5786 GST_OBJECT_UNLOCK (pad);
5788 GST_PAD_STREAM_UNLOCK (pad);
5789 gst_event_unref (event);
5790 return GST_FLOW_NOT_SUPPORTED;
5794 GST_DEBUG_OBJECT (pad, "no parent");
5795 GST_OBJECT_UNLOCK (pad);
5797 GST_PAD_STREAM_UNLOCK (pad);
5798 gst_event_unref (event);
5799 return GST_FLOW_FLUSHING;
5803 GST_DEBUG_OBJECT (pad, "pre event check failed");
5804 RELEASE_PARENT (parent);
5806 GST_PAD_STREAM_UNLOCK (pad);
5807 gst_event_unref (event);
5813 * gst_pad_send_event:
5814 * @pad: a #GstPad to send the event to.
5815 * @event: (transfer full): the #GstEvent to send to the pad.
5817 * Sends the event to the pad. This function can be used
5818 * by applications to send events in the pipeline.
5820 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5821 * sink pad, @event should be a downstream event. For example, you would not
5822 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5823 * Furthermore, some downstream events have to be serialized with data flow,
5824 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5825 * the event needs to be serialized with data flow, this function will take the
5826 * pad's stream lock while calling its event function.
5828 * To find out whether an event type is upstream, downstream, or downstream and
5829 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5830 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5831 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5832 * plugin doesn't need to bother itself with this information; the core handles
5833 * all necessary locks and checks.
5835 * This function takes ownership of the provided event so you should
5836 * gst_event_ref() it if you want to reuse the event after this call.
5838 * Returns: %TRUE if the event was handled.
5841 gst_pad_send_event (GstPad * pad, GstEvent * event)
5844 GstPadProbeType type;
5846 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5847 g_return_val_if_fail (event != NULL, FALSE);
5849 if (GST_PAD_IS_SINK (pad)) {
5850 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5851 goto wrong_direction;
5852 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5853 } else if (GST_PAD_IS_SRC (pad)) {
5854 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5855 goto wrong_direction;
5856 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5858 goto unknown_direction;
5860 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5867 /* ERROR handling */
5870 g_warning ("pad %s:%s sending %s event in wrong direction",
5871 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5872 gst_event_unref (event);
5877 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5878 gst_event_unref (event);
5884 * gst_pad_set_element_private:
5885 * @pad: the #GstPad to set the private data of.
5886 * @priv: The private data to attach to the pad.
5888 * Set the given private data gpointer on the pad.
5889 * This function can only be used by the element that owns the pad.
5890 * No locking is performed in this function.
5893 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5895 pad->element_private = priv;
5899 * gst_pad_get_element_private:
5900 * @pad: the #GstPad to get the private data of.
5902 * Gets the private data of a pad.
5903 * No locking is performed in this function.
5905 * Returns: (transfer none): a #gpointer to the private data.
5908 gst_pad_get_element_private (GstPad * pad)
5910 return pad->element_private;
5914 * gst_pad_get_sticky_event:
5915 * @pad: the #GstPad to get the event from.
5916 * @event_type: the #GstEventType that should be retrieved.
5917 * @idx: the index of the event
5919 * Returns a new reference of the sticky event of type @event_type
5922 * Returns: (transfer full) (nullable): a #GstEvent of type
5923 * @event_type or %NULL when no event of @event_type was on
5924 * @pad. Unref after usage.
5927 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5929 GstEvent *event = NULL;
5932 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5933 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5935 GST_OBJECT_LOCK (pad);
5936 ev = find_event_by_type (pad, event_type, idx);
5937 if (ev && (event = ev->event))
5938 gst_event_ref (event);
5939 GST_OBJECT_UNLOCK (pad);
5946 GstPadStickyEventsForeachFunction func;
5951 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5953 ForeachDispatch *data = user_data;
5954 gboolean ret = TRUE;
5957 GST_OBJECT_UNLOCK (pad);
5959 ret = data->func (pad, &ev->event, data->user_data);
5961 GST_OBJECT_LOCK (pad);
5968 * gst_pad_sticky_events_foreach:
5969 * @pad: the #GstPad that should be used for iteration.
5970 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5971 * should be called for every event.
5972 * @user_data: (closure): the optional user data.
5974 * Iterates all sticky events on @pad and calls @foreach_func for every
5975 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5978 gst_pad_sticky_events_foreach (GstPad * pad,
5979 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5981 ForeachDispatch data;
5983 g_return_if_fail (GST_IS_PAD (pad));
5984 g_return_if_fail (foreach_func != NULL);
5986 data.func = foreach_func;
5987 data.user_data = user_data;
5989 GST_OBJECT_LOCK (pad);
5990 events_foreach (pad, foreach_dispatch_function, &data);
5991 GST_OBJECT_UNLOCK (pad);
5995 do_stream_status (GstPad * pad, GstStreamStatusType type,
5996 GThread * thread, GstTask * task)
6000 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
6002 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
6003 if (GST_IS_ELEMENT (parent)) {
6004 GstMessage *message;
6005 GValue value = { 0 };
6007 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
6008 gchar *tname, *ename, *pname;
6010 /* create a good task name */
6011 ename = gst_element_get_name (parent);
6012 pname = gst_pad_get_name (pad);
6013 tname = g_strdup_printf ("%s:%s", ename, pname);
6017 gst_object_set_name (GST_OBJECT_CAST (task), tname);
6021 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
6024 g_value_init (&value, GST_TYPE_TASK);
6025 g_value_set_object (&value, task);
6026 gst_message_set_stream_status_object (message, &value);
6027 g_value_unset (&value);
6029 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
6030 gst_element_post_message (parent, message);
6032 gst_object_unref (parent);
6037 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6039 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6044 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6046 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6051 * gst_pad_start_task:
6052 * @pad: the #GstPad to start the task of
6053 * @func: the task function to call
6054 * @user_data: user data passed to the task function
6055 * @notify: called when @user_data is no longer referenced
6057 * Starts a task that repeatedly calls @func with @user_data. This function
6058 * is mostly used in pad activation functions to start the dataflow.
6059 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6060 * before @func is called.
6062 * Returns: a %TRUE if the task could be started.
6065 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6066 GDestroyNotify notify)
6071 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6072 g_return_val_if_fail (func != NULL, FALSE);
6074 GST_DEBUG_OBJECT (pad, "start task");
6076 GST_OBJECT_LOCK (pad);
6077 task = GST_PAD_TASK (pad);
6079 task = gst_task_new (func, user_data, notify);
6080 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6081 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6082 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6083 GST_INFO_OBJECT (pad, "created task %p", task);
6084 GST_PAD_TASK (pad) = task;
6085 gst_object_ref (task);
6086 /* release lock to post the message */
6087 GST_OBJECT_UNLOCK (pad);
6089 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6091 gst_object_unref (task);
6093 GST_OBJECT_LOCK (pad);
6094 /* nobody else is supposed to have changed the pad now */
6095 if (GST_PAD_TASK (pad) != task)
6096 goto concurrent_stop;
6098 res = gst_task_set_state (task, GST_TASK_STARTED);
6099 GST_OBJECT_UNLOCK (pad);
6106 GST_OBJECT_UNLOCK (pad);
6112 * gst_pad_pause_task:
6113 * @pad: the #GstPad to pause the task of
6115 * Pause the task of @pad. This function will also wait until the
6116 * function executed by the task is finished if this function is not
6117 * called from the task function.
6119 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6123 gst_pad_pause_task (GstPad * pad)
6128 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6130 GST_DEBUG_OBJECT (pad, "pause task");
6132 GST_OBJECT_LOCK (pad);
6133 task = GST_PAD_TASK (pad);
6136 res = gst_task_set_state (task, GST_TASK_PAUSED);
6137 /* unblock activation waits if any */
6138 pad->priv->in_activation = FALSE;
6139 g_cond_broadcast (&pad->priv->activation_cond);
6140 GST_OBJECT_UNLOCK (pad);
6142 /* wait for task function to finish, this lock is recursive so it does nothing
6143 * when the pause is called from the task itself */
6144 GST_PAD_STREAM_LOCK (pad);
6145 GST_PAD_STREAM_UNLOCK (pad);
6151 GST_DEBUG_OBJECT (pad, "pad has no task");
6152 GST_OBJECT_UNLOCK (pad);
6158 * gst_pad_get_task_state:
6159 * @pad: the #GstPad to get task state from
6161 * Get @pad task state. If no task is currently
6162 * set, #GST_TASK_STOPPED is returned.
6164 * Returns: The current state of @pad's task.
6169 gst_pad_get_task_state (GstPad * pad)
6174 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6176 GST_OBJECT_LOCK (pad);
6177 task = GST_PAD_TASK (pad);
6180 res = gst_task_get_state (task);
6181 GST_OBJECT_UNLOCK (pad);
6187 GST_DEBUG_OBJECT (pad, "pad has no task");
6188 GST_OBJECT_UNLOCK (pad);
6189 return GST_TASK_STOPPED;
6194 * gst_pad_stop_task:
6195 * @pad: the #GstPad to stop the task of
6197 * Stop the task of @pad. This function will also make sure that the
6198 * function executed by the task will effectively stop if not called
6199 * from the GstTaskFunction.
6201 * This function will deadlock if called from the GstTaskFunction of
6202 * the task. Use gst_task_pause() instead.
6204 * Regardless of whether the pad has a task, the stream lock is acquired and
6205 * released so as to ensure that streaming through this pad has finished.
6207 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6210 gst_pad_stop_task (GstPad * pad)
6215 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6217 GST_DEBUG_OBJECT (pad, "stop task");
6219 GST_OBJECT_LOCK (pad);
6220 task = GST_PAD_TASK (pad);
6223 GST_PAD_TASK (pad) = NULL;
6224 res = gst_task_set_state (task, GST_TASK_STOPPED);
6225 /* unblock activation waits if any */
6226 pad->priv->in_activation = FALSE;
6227 g_cond_broadcast (&pad->priv->activation_cond);
6228 GST_OBJECT_UNLOCK (pad);
6230 GST_PAD_STREAM_LOCK (pad);
6231 GST_PAD_STREAM_UNLOCK (pad);
6233 if (!gst_task_join (task))
6236 gst_object_unref (task);
6242 GST_DEBUG_OBJECT (pad, "no task");
6243 GST_OBJECT_UNLOCK (pad);
6245 GST_PAD_STREAM_LOCK (pad);
6246 GST_PAD_STREAM_UNLOCK (pad);
6248 /* this is not an error */
6253 /* this is bad, possibly the application tried to join the task from
6254 * the task's thread. We install the task again so that it will be stopped
6255 * again from the right thread next time hopefully. */
6256 GST_OBJECT_LOCK (pad);
6257 GST_DEBUG_OBJECT (pad, "join failed");
6258 /* we can only install this task if there was no other task */
6259 if (GST_PAD_TASK (pad) == NULL)
6260 GST_PAD_TASK (pad) = task;
6261 GST_OBJECT_UNLOCK (pad);
6268 * gst_pad_probe_info_get_event:
6269 * @info: a #GstPadProbeInfo
6271 * Returns: (transfer none): The #GstEvent from the probe
6275 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6277 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6278 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6280 return GST_PAD_PROBE_INFO_EVENT (info);
6285 * gst_pad_probe_info_get_query:
6286 * @info: a #GstPadProbeInfo
6288 * Returns: (transfer none): The #GstQuery from the probe
6292 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6294 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6295 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6297 return GST_PAD_PROBE_INFO_QUERY (info);
6301 * gst_pad_probe_info_get_buffer:
6302 * @info: a #GstPadProbeInfo
6304 * Returns: (transfer none): The #GstBuffer from the probe
6308 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6310 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6312 return GST_PAD_PROBE_INFO_BUFFER (info);
6316 * gst_pad_probe_info_get_buffer_list:
6317 * @info: a #GstPadProbeInfo
6319 * Returns: (transfer none): The #GstBufferList from the probe
6323 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6325 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6327 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6331 * gst_pad_get_last_flow_return:
6334 * Gets the #GstFlowReturn return from the last data passed by this pad.
6339 gst_pad_get_last_flow_return (GstPad * pad)
6343 GST_OBJECT_LOCK (pad);
6344 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6345 GST_OBJECT_UNLOCK (pad);