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 */
160 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
161 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
162 (((GstPad *)(p))->priv->idle_running > 0)
167 GstPadProbeInfo *info;
175 static void gst_pad_dispose (GObject * object);
176 static void gst_pad_finalize (GObject * object);
177 static void gst_pad_set_property (GObject * object, guint prop_id,
178 const GValue * value, GParamSpec * pspec);
179 static void gst_pad_get_property (GObject * object, guint prop_id,
180 GValue * value, GParamSpec * pspec);
182 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
183 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
184 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
185 GstObject * parent, GstBufferList * list);
187 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
188 GstEvent * event, GstPadProbeType type);
189 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
190 GstEvent * event, GstPadProbeType type);
192 static gboolean activate_mode_internal (GstPad * pad, GstObject * parent,
193 GstPadMode mode, gboolean active);
195 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
197 static GParamSpec *pspec_caps = NULL;
199 /* quarks for probe signals */
200 static GQuark buffer_quark;
201 static GQuark buffer_list_quark;
202 static GQuark event_quark;
211 static GstFlowQuarks flow_quarks[] = {
212 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
213 {GST_FLOW_OK, "ok", 0},
214 {GST_FLOW_NOT_LINKED, "not-linked", 0},
215 {GST_FLOW_FLUSHING, "flushing", 0},
216 {GST_FLOW_EOS, "eos", 0},
217 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
218 {GST_FLOW_ERROR, "error", 0},
219 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
220 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
225 * @ret: a #GstFlowReturn to get the name of.
227 * Gets a string representing the given flow return.
229 * Returns: a static string with the name of the flow return.
232 gst_flow_get_name (GstFlowReturn ret)
236 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
238 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
239 if (ret == flow_quarks[i].ret)
240 return flow_quarks[i].name;
247 * @ret: a #GstFlowReturn to get the quark of.
249 * Get the unique quark for the given GstFlowReturn.
251 * Returns: the quark associated with the flow return or 0 if an
252 * invalid return was specified.
255 gst_flow_to_quark (GstFlowReturn ret)
259 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
261 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
262 if (ret == flow_quarks[i].ret)
263 return flow_quarks[i].quark;
269 * gst_pad_link_get_name:
270 * @ret: a #GstPadLinkReturn to get the name of.
272 * Gets a string representing the given pad-link return.
274 * Returns: a static string with the name of the pad-link return.
279 gst_pad_link_get_name (GstPadLinkReturn ret)
282 case GST_PAD_LINK_OK:
284 case GST_PAD_LINK_WRONG_HIERARCHY:
285 return "wrong hierarchy";
286 case GST_PAD_LINK_WAS_LINKED:
288 case GST_PAD_LINK_WRONG_DIRECTION:
289 return "wrong direction";
290 case GST_PAD_LINK_NOFORMAT:
291 return "no common format";
292 case GST_PAD_LINK_NOSCHED:
293 return "incompatible scheduling";
294 case GST_PAD_LINK_REFUSED:
297 g_return_val_if_reached ("unknown");
304 buffer_quark = g_quark_from_static_string ("buffer"); \
305 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
306 event_quark = g_quark_from_static_string ("event"); \
308 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
309 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
312 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
313 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
316 #define gst_pad_parent_class parent_class
317 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
320 gst_pad_class_init (GstPadClass * klass)
322 GObjectClass *gobject_class;
323 GstObjectClass *gstobject_class;
325 gobject_class = G_OBJECT_CLASS (klass);
326 gstobject_class = GST_OBJECT_CLASS (klass);
328 g_type_class_add_private (klass, sizeof (GstPadPrivate));
330 gobject_class->dispose = gst_pad_dispose;
331 gobject_class->finalize = gst_pad_finalize;
332 gobject_class->set_property = gst_pad_set_property;
333 gobject_class->get_property = gst_pad_get_property;
337 * @pad: the pad that emitted the signal
338 * @peer: the peer pad that has been connected
340 * Signals that a pad has been linked to the peer pad.
342 gst_pad_signals[PAD_LINKED] =
343 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
344 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
345 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
348 * @pad: the pad that emitted the signal
349 * @peer: the peer pad that has been disconnected
351 * Signals that a pad has been unlinked from the peer pad.
353 gst_pad_signals[PAD_UNLINKED] =
354 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
355 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
356 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
358 pspec_caps = g_param_spec_boxed ("caps", "Caps",
359 "The capabilities of the pad", GST_TYPE_CAPS,
360 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
361 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
363 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
364 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
365 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
366 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
368 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
369 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
370 g_param_spec_object ("template", "Template",
371 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
372 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
377 * The offset that will be applied to the running time of the pad.
381 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
382 g_param_spec_int64 ("offset", "Offset",
383 "The running time offset of the pad", 0, G_MAXINT64, 0,
384 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
386 gstobject_class->path_string_separator = ".";
388 /* Register common function pointer descriptions */
389 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
390 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
391 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
392 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
393 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
397 gst_pad_init (GstPad * pad)
399 pad->priv = GST_PAD_GET_PRIVATE (pad);
401 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
403 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
404 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
405 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
406 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
407 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
409 GST_PAD_SET_FLUSHING (pad);
411 g_rec_mutex_init (&pad->stream_rec_lock);
413 g_cond_init (&pad->block_cond);
415 g_hook_list_init (&pad->probes, sizeof (GstProbe));
417 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
418 pad->priv->events_cookie = 0;
419 pad->priv->last_cookie = -1;
420 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
423 /* called when setting the pad inactive. It removes all sticky events from
424 * the pad. must be called with object lock */
426 remove_events (GstPad * pad)
430 gboolean notify = FALSE;
432 events = pad->priv->events;
435 for (i = 0; i < len; i++) {
436 PadEvent *ev = &g_array_index (events, PadEvent, i);
437 GstEvent *event = ev->event;
441 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
444 gst_event_unref (event);
447 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
448 g_array_set_size (events, 0);
449 pad->priv->events_cookie++;
452 GST_OBJECT_UNLOCK (pad);
454 GST_DEBUG_OBJECT (pad, "notify caps");
455 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
457 GST_OBJECT_LOCK (pad);
461 /* should be called with object lock */
463 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
469 events = pad->priv->events;
472 for (i = 0; i < len; i++) {
473 ev = &g_array_index (events, PadEvent, i);
474 if (ev->event == NULL)
477 if (GST_EVENT_TYPE (ev->event) == type) {
481 } else if (GST_EVENT_TYPE (ev->event) > type) {
490 /* should be called with OBJECT lock */
492 find_event (GstPad * pad, GstEvent * event)
498 events = pad->priv->events;
501 for (i = 0; i < len; i++) {
502 ev = &g_array_index (events, PadEvent, i);
503 if (event == ev->event)
505 else if (GST_EVENT_TYPE (ev->event) > GST_EVENT_TYPE (event))
513 /* should be called with OBJECT lock */
515 remove_event_by_type (GstPad * pad, GstEventType type)
521 events = pad->priv->events;
526 ev = &g_array_index (events, PadEvent, i);
527 if (ev->event == NULL)
530 if (GST_EVENT_TYPE (ev->event) > type)
532 else if (GST_EVENT_TYPE (ev->event) != type)
535 gst_event_unref (ev->event);
536 g_array_remove_index (events, i);
538 pad->priv->events_cookie++;
546 /* check all events on srcpad against those on sinkpad. All events that are not
547 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
548 * srcpad so that the events will be sent next time */
549 /* should be called with srcpad and sinkpad LOCKS */
551 schedule_events (GstPad * srcpad, GstPad * sinkpad)
556 gboolean pending = FALSE;
558 events = srcpad->priv->events;
561 for (i = 0; i < len; i++) {
562 ev = &g_array_index (events, PadEvent, i);
563 if (ev->event == NULL)
566 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
567 ev->received = FALSE;
572 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
575 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
578 /* should be called with pad LOCK */
580 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
587 events = pad->priv->events;
590 cookie = pad->priv->events_cookie;
594 PadEvent *ev, ev_ret;
596 ev = &g_array_index (events, PadEvent, i);
597 if (G_UNLIKELY (ev->event == NULL))
600 /* take aditional ref, func might release the lock */
601 ev_ret.event = gst_event_ref (ev->event);
602 ev_ret.received = ev->received;
604 ret = func (pad, &ev_ret, user_data);
606 /* recheck the cookie, lock might have been released and the list could have
608 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
609 if (G_LIKELY (ev_ret.event))
610 gst_event_unref (ev_ret.event);
614 /* store the received state */
615 ev->received = ev_ret.received;
617 /* if the event changed, we need to do something */
618 if (G_UNLIKELY (ev->event != ev_ret.event)) {
619 if (G_UNLIKELY (ev_ret.event == NULL)) {
620 /* function unreffed and set the event to NULL, remove it */
621 gst_event_unref (ev->event);
622 g_array_remove_index (events, i);
624 cookie = ++pad->priv->events_cookie;
627 /* function gave a new event for us */
628 gst_event_take (&ev->event, ev_ret.event);
631 /* just unref, nothing changed */
632 gst_event_unref (ev_ret.event);
641 /* should be called with LOCK */
643 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
647 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_STIME_FORMAT,
648 GST_STIME_ARGS (pad->offset));
650 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
653 g_assert (!upstream);
655 /* copy segment values */
656 gst_event_copy_segment (event, &segment);
657 gst_event_unref (event);
659 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
660 event = gst_event_new_segment (&segment);
663 event = gst_event_make_writable (event);
664 offset = gst_event_get_running_time_offset (event);
666 offset -= pad->offset;
668 offset += pad->offset;
669 gst_event_set_running_time_offset (event, offset);
674 static inline GstEvent *
675 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
677 if (G_UNLIKELY (pad->offset != 0))
678 return _apply_pad_offset (pad, event, upstream);
683 /* should be called with the OBJECT_LOCK */
685 get_pad_caps (GstPad * pad)
687 GstCaps *caps = NULL;
690 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
692 gst_event_parse_caps (ev->event, &caps);
698 gst_pad_dispose (GObject * object)
700 GstPad *pad = GST_PAD_CAST (object);
703 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "%p dispose", pad);
705 /* unlink the peer pad */
706 if ((peer = gst_pad_get_peer (pad))) {
707 /* window for MT unsafeness, someone else could unlink here
708 * and then we call unlink with wrong pads. The unlink
709 * function would catch this and safely return failed. */
710 if (GST_PAD_IS_SRC (pad))
711 gst_pad_unlink (pad, peer);
713 gst_pad_unlink (peer, pad);
715 gst_object_unref (peer);
718 gst_pad_set_pad_template (pad, NULL);
720 GST_OBJECT_LOCK (pad);
722 GST_OBJECT_UNLOCK (pad);
724 g_hook_list_clear (&pad->probes);
726 G_OBJECT_CLASS (parent_class)->dispose (object);
730 gst_pad_finalize (GObject * object)
732 GstPad *pad = GST_PAD_CAST (object);
735 /* in case the task is still around, clean it up */
736 if ((task = GST_PAD_TASK (pad))) {
737 gst_task_join (task);
738 GST_PAD_TASK (pad) = NULL;
739 gst_object_unref (task);
742 if (pad->activatenotify)
743 pad->activatenotify (pad->activatedata);
744 if (pad->activatemodenotify)
745 pad->activatemodenotify (pad->activatemodedata);
747 pad->linknotify (pad->linkdata);
748 if (pad->unlinknotify)
749 pad->unlinknotify (pad->unlinkdata);
750 if (pad->chainnotify)
751 pad->chainnotify (pad->chaindata);
752 if (pad->chainlistnotify)
753 pad->chainlistnotify (pad->chainlistdata);
754 if (pad->getrangenotify)
755 pad->getrangenotify (pad->getrangedata);
756 if (pad->eventnotify)
757 pad->eventnotify (pad->eventdata);
758 if (pad->querynotify)
759 pad->querynotify (pad->querydata);
760 if (pad->iterintlinknotify)
761 pad->iterintlinknotify (pad->iterintlinkdata);
763 g_rec_mutex_clear (&pad->stream_rec_lock);
764 g_cond_clear (&pad->block_cond);
765 g_array_free (pad->priv->events, TRUE);
767 G_OBJECT_CLASS (parent_class)->finalize (object);
771 gst_pad_set_property (GObject * object, guint prop_id,
772 const GValue * value, GParamSpec * pspec)
774 g_return_if_fail (GST_IS_PAD (object));
777 case PAD_PROP_DIRECTION:
778 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
780 case PAD_PROP_TEMPLATE:
781 gst_pad_set_pad_template (GST_PAD_CAST (object),
782 (GstPadTemplate *) g_value_get_object (value));
784 case PAD_PROP_OFFSET:
785 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
788 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
794 gst_pad_get_property (GObject * object, guint prop_id,
795 GValue * value, GParamSpec * pspec)
797 g_return_if_fail (GST_IS_PAD (object));
801 GST_OBJECT_LOCK (object);
802 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
803 GST_OBJECT_UNLOCK (object);
805 case PAD_PROP_DIRECTION:
806 g_value_set_enum (value, GST_PAD_DIRECTION (object));
808 case PAD_PROP_TEMPLATE:
809 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
811 case PAD_PROP_OFFSET:
812 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
815 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
822 * @name: (allow-none): the name of the new pad.
823 * @direction: the #GstPadDirection of the pad.
825 * Creates a new pad with the given name in the given direction.
826 * If name is %NULL, a guaranteed unique name (across all pads)
828 * This function makes a copy of the name so you can safely free the name.
830 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
836 gst_pad_new (const gchar * name, GstPadDirection direction)
838 return g_object_new (GST_TYPE_PAD,
839 "name", name, "direction", direction, NULL);
843 * gst_pad_new_from_template:
844 * @templ: the pad template to use
845 * @name: (allow-none): the name of the pad
847 * Creates a new pad with the given name from the given template.
848 * If name is %NULL, a guaranteed unique name (across all pads)
850 * This function makes a copy of the name so you can safely free the name.
852 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
856 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
858 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
860 return g_object_new (GST_TYPE_PAD,
861 "name", name, "direction", templ->direction, "template", templ, NULL);
865 * gst_pad_new_from_static_template:
866 * @templ: the #GstStaticPadTemplate to use
867 * @name: the name of the pad
869 * Creates a new pad with the given name from the given static template.
870 * If name is %NULL, a guaranteed unique name (across all pads)
872 * This function makes a copy of the name so you can safely free the name.
874 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
878 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
882 GstPadTemplate *template;
884 template = gst_static_pad_template_get (templ);
885 pad = gst_pad_new_from_template (template, name);
886 gst_object_unref (template);
890 #define ACQUIRE_PARENT(pad, parent, label) \
892 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
893 gst_object_ref (parent); \
894 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
898 #define RELEASE_PARENT(parent) \
900 if (G_LIKELY (parent)) \
901 gst_object_unref (parent); \
905 * gst_pad_get_direction:
906 * @pad: a #GstPad to get the direction of.
908 * Gets the direction of the pad. The direction of the pad is
909 * decided at construction time so this function does not take
912 * Returns: the #GstPadDirection of the pad.
917 gst_pad_get_direction (GstPad * pad)
919 GstPadDirection result;
921 /* PAD_UNKNOWN is a little silly but we need some sort of
922 * error return value */
923 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
925 result = GST_PAD_DIRECTION (pad);
931 gst_pad_activate_default (GstPad * pad, GstObject * parent)
933 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
935 return activate_mode_internal (pad, parent, GST_PAD_MODE_PUSH, TRUE);
939 * gst_pad_mode_get_name:
940 * @mode: the pad mode
942 * Return the name of a pad mode, for use in debug messages mostly.
944 * Returns: short mnemonic for pad mode @mode
947 gst_pad_mode_get_name (GstPadMode mode)
950 case GST_PAD_MODE_NONE:
952 case GST_PAD_MODE_PUSH:
954 case GST_PAD_MODE_PULL:
963 pre_activate (GstPad * pad, GstPadMode new_mode)
966 case GST_PAD_MODE_NONE:
967 GST_OBJECT_LOCK (pad);
968 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
969 GST_PAD_SET_FLUSHING (pad);
970 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
971 GST_PAD_MODE (pad) = new_mode;
972 /* unlock blocked pads so element can resume and stop */
973 GST_PAD_BLOCK_BROADCAST (pad);
974 GST_OBJECT_UNLOCK (pad);
976 case GST_PAD_MODE_PUSH:
977 case GST_PAD_MODE_PULL:
978 GST_OBJECT_LOCK (pad);
979 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
980 gst_pad_mode_get_name (new_mode));
981 GST_PAD_UNSET_FLUSHING (pad);
982 pad->ABI.abi.last_flowret = GST_FLOW_OK;
983 GST_PAD_MODE (pad) = new_mode;
984 if (GST_PAD_IS_SINK (pad)) {
986 /* make sure the peer src pad sends us all events */
987 if ((peer = GST_PAD_PEER (pad))) {
988 gst_object_ref (peer);
989 GST_OBJECT_UNLOCK (pad);
991 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
992 GST_DEBUG_PAD_NAME (peer));
994 GST_OBJECT_LOCK (peer);
995 schedule_events (peer, NULL);
996 GST_OBJECT_UNLOCK (peer);
998 gst_object_unref (peer);
1000 GST_OBJECT_UNLOCK (pad);
1003 GST_OBJECT_UNLOCK (pad);
1010 post_activate (GstPad * pad, GstPadMode new_mode)
1013 case GST_PAD_MODE_NONE:
1014 /* ensures that streaming stops */
1015 GST_PAD_STREAM_LOCK (pad);
1016 GST_DEBUG_OBJECT (pad, "stopped streaming");
1017 GST_OBJECT_LOCK (pad);
1018 remove_events (pad);
1019 GST_OBJECT_UNLOCK (pad);
1020 GST_PAD_STREAM_UNLOCK (pad);
1022 case GST_PAD_MODE_PUSH:
1023 case GST_PAD_MODE_PULL:
1030 * gst_pad_set_active:
1031 * @pad: the #GstPad to activate or deactivate.
1032 * @active: whether or not the pad should be active.
1034 * Activates or deactivates the given pad.
1035 * Normally called from within core state change functions.
1037 * If @active, makes sure the pad is active. If it is already active, either in
1038 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1039 * function to perform the actual activation.
1041 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1042 * and a %FALSE argument.
1044 * Returns: %TRUE if the operation was successful.
1049 gst_pad_set_active (GstPad * pad, gboolean active)
1053 gboolean ret = FALSE;
1055 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1057 GST_OBJECT_LOCK (pad);
1058 old = GST_PAD_MODE (pad);
1059 ACQUIRE_PARENT (pad, parent, no_parent);
1060 GST_OBJECT_UNLOCK (pad);
1063 if (old == GST_PAD_MODE_NONE) {
1064 GST_DEBUG_OBJECT (pad, "activating pad from none");
1065 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1067 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1069 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1070 gst_pad_mode_get_name (old));
1074 if (old == GST_PAD_MODE_NONE) {
1075 GST_DEBUG_OBJECT (pad, "pad was inactive");
1078 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1079 gst_pad_mode_get_name (old));
1080 ret = activate_mode_internal (pad, parent, old, FALSE);
1082 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1086 RELEASE_PARENT (parent);
1088 if (G_UNLIKELY (!ret))
1096 GST_DEBUG_OBJECT (pad, "no parent");
1097 GST_OBJECT_UNLOCK (pad);
1102 GST_OBJECT_LOCK (pad);
1104 g_critical ("Failed to deactivate pad %s:%s, very bad",
1105 GST_DEBUG_PAD_NAME (pad));
1107 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1109 GST_OBJECT_UNLOCK (pad);
1115 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1118 gboolean res = FALSE;
1119 GstPadMode old, new;
1120 GstPadDirection dir;
1123 GST_OBJECT_LOCK (pad);
1124 old = GST_PAD_MODE (pad);
1125 dir = GST_PAD_DIRECTION (pad);
1126 GST_OBJECT_UNLOCK (pad);
1128 new = active ? mode : GST_PAD_MODE_NONE;
1133 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1134 /* pad was activate in the wrong direction, deactivate it
1135 * and reactivate it in the requested mode */
1136 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1137 gst_pad_mode_get_name (old));
1139 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1140 goto deactivate_failed;
1141 old = GST_PAD_MODE_NONE;
1145 case GST_PAD_MODE_PULL:
1147 if (dir == GST_PAD_SINK) {
1148 if ((peer = gst_pad_get_peer (pad))) {
1149 GST_DEBUG_OBJECT (pad, "calling peer");
1150 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1152 gst_object_unref (peer);
1154 /* there is no peer, this is only fatal when we activate. When we
1155 * deactivate, we must assume the application has unlinked the peer and
1156 * will deactivate it eventually. */
1160 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1163 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1164 goto failure; /* Can't activate pull on a src without a
1165 getrange function */
1173 /* Mark pad as needing reconfiguration */
1175 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1176 pre_activate (pad, new);
1178 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1179 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1183 /* can happen for sinks of passthrough elements */
1186 post_activate (pad, new);
1188 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1189 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1194 /* Clear sticky flags on deactivation */
1196 GST_OBJECT_LOCK (pad);
1197 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1198 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1199 GST_OBJECT_UNLOCK (pad);
1207 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1208 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1213 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1214 "failed to %s in switch to %s mode from %s mode",
1215 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1216 gst_pad_mode_get_name (old));
1221 GST_OBJECT_LOCK (peer);
1222 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1223 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1224 GST_OBJECT_UNLOCK (peer);
1225 gst_object_unref (peer);
1230 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1231 "pad in pull mode");
1236 GST_OBJECT_LOCK (pad);
1237 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1238 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1239 GST_PAD_SET_FLUSHING (pad);
1240 GST_PAD_MODE (pad) = old;
1241 GST_OBJECT_UNLOCK (pad);
1247 * gst_pad_activate_mode:
1248 * @pad: the #GstPad to activate or deactivate.
1249 * @mode: the requested activation mode
1250 * @active: whether or not the pad should be active.
1252 * Activates or deactivates the given pad in @mode via dispatching to the
1253 * pad's activatemodefunc. For use from within pad activation functions only.
1255 * If you don't know what this is, you probably don't want to call it.
1257 * Returns: %TRUE if the operation was successful.
1262 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1267 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1269 GST_OBJECT_LOCK (pad);
1270 ACQUIRE_PARENT (pad, parent, no_parent);
1271 GST_OBJECT_UNLOCK (pad);
1273 res = activate_mode_internal (pad, parent, mode, active);
1275 RELEASE_PARENT (parent);
1281 GST_WARNING_OBJECT (pad, "no parent");
1282 GST_OBJECT_UNLOCK (pad);
1288 * gst_pad_is_active:
1289 * @pad: the #GstPad to query
1291 * Query if a pad is active
1293 * Returns: %TRUE if the pad is active.
1298 gst_pad_is_active (GstPad * pad)
1300 gboolean result = FALSE;
1302 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1304 GST_OBJECT_LOCK (pad);
1305 result = GST_PAD_IS_ACTIVE (pad);
1306 GST_OBJECT_UNLOCK (pad);
1312 cleanup_hook (GstPad * pad, GHook * hook)
1314 GstPadProbeType type;
1316 if (!G_HOOK_IS_VALID (hook))
1319 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1321 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1322 /* unblock when we remove the last blocking probe */
1324 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1327 /* Might have new probes now that want to be called */
1328 GST_PAD_BLOCK_BROADCAST (pad);
1330 if (pad->num_blocked == 0) {
1331 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1332 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1335 g_hook_destroy_link (&pad->probes, hook);
1340 * gst_pad_add_probe:
1341 * @pad: the #GstPad to add the probe to
1342 * @mask: the probe mask
1343 * @callback: #GstPadProbeCallback that will be called with notifications of
1345 * @user_data: (closure): user data passed to the callback
1346 * @destroy_data: #GDestroyNotify for user_data
1348 * Be notified of different states of pads. The provided callback is called for
1349 * every state that matches @mask.
1351 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1352 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1353 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1354 * immediately if the pad is already idle while calling gst_pad_add_probe().
1355 * In each of the groups, probes are called in the order in which they were
1358 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1359 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1360 * happen that the probe can be run immediately and if the probe returns
1361 * GST_PAD_PROBE_REMOVE this functions returns 0.
1366 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1367 GstPadProbeCallback callback, gpointer user_data,
1368 GDestroyNotify destroy_data)
1373 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1374 g_return_val_if_fail (mask != 0, 0);
1376 GST_OBJECT_LOCK (pad);
1378 /* make a new probe */
1379 hook = g_hook_alloc (&pad->probes);
1381 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1384 /* when no contraints are given for the types, assume all types are
1386 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1387 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1388 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1389 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1391 /* store our flags and other fields */
1392 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1393 hook->func = callback;
1394 hook->data = user_data;
1395 hook->destroy = destroy_data;
1396 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1399 g_hook_append (&pad->probes, hook);
1401 /* incremenent cookie so that the new hook get's called */
1402 pad->priv->probe_list_cookie++;
1404 /* get the id of the hook, we return this and it can be used to remove the
1406 res = hook->hook_id;
1408 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1410 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1411 /* we have a block probe */
1413 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1414 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1415 "now %d blocking probes", pad->num_blocked);
1417 /* Might have new probes now that want to be called */
1418 GST_PAD_BLOCK_BROADCAST (pad);
1421 /* call the callback if we need to be called for idle callbacks */
1422 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1423 if (pad->priv->using > 0) {
1424 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1425 * flag above, the last thread to leave the push will do the callback. New
1426 * threads going into the push will block. */
1427 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1428 "pad is in use, delay idle callback");
1429 GST_OBJECT_UNLOCK (pad);
1431 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1432 GstPadProbeReturn ret;
1434 /* Keep another ref, the callback could destroy the pad */
1435 gst_object_ref (pad);
1436 pad->priv->idle_running++;
1438 /* the pad is idle now, we can signal the idle callback now */
1439 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1440 "pad is idle, trigger idle callback");
1441 GST_OBJECT_UNLOCK (pad);
1443 ret = callback (pad, &info, user_data);
1445 GST_OBJECT_LOCK (pad);
1447 case GST_PAD_PROBE_REMOVE:
1448 /* remove the probe */
1449 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1450 cleanup_hook (pad, hook);
1453 case GST_PAD_PROBE_DROP:
1454 GST_DEBUG_OBJECT (pad, "asked to drop item");
1456 case GST_PAD_PROBE_PASS:
1457 GST_DEBUG_OBJECT (pad, "asked to pass item");
1459 case GST_PAD_PROBE_OK:
1460 GST_DEBUG_OBJECT (pad, "probe returned OK");
1462 case GST_PAD_PROBE_HANDLED:
1463 GST_DEBUG_OBJECT (pad, "probe handled the data");
1466 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1469 pad->priv->idle_running--;
1470 if (pad->priv->idle_running == 0) {
1471 GST_PAD_BLOCK_BROADCAST (pad);
1473 GST_OBJECT_UNLOCK (pad);
1475 gst_object_unref (pad);
1478 GST_OBJECT_UNLOCK (pad);
1484 * gst_pad_remove_probe:
1485 * @pad: the #GstPad with the probe
1486 * @id: the probe id to remove
1488 * Remove the probe with @id from @pad.
1493 gst_pad_remove_probe (GstPad * pad, gulong id)
1497 g_return_if_fail (GST_IS_PAD (pad));
1499 GST_OBJECT_LOCK (pad);
1501 hook = g_hook_get (&pad->probes, id);
1505 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1507 cleanup_hook (pad, hook);
1508 GST_OBJECT_UNLOCK (pad);
1514 GST_OBJECT_UNLOCK (pad);
1515 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1521 * gst_pad_is_blocked:
1522 * @pad: the #GstPad to query
1524 * Checks if the pad is blocked or not. This function returns the
1525 * last requested state of the pad. It is not certain that the pad
1526 * is actually blocking at this point (see gst_pad_is_blocking()).
1528 * Returns: %TRUE if the pad is blocked.
1533 gst_pad_is_blocked (GstPad * pad)
1535 gboolean result = FALSE;
1537 g_return_val_if_fail (GST_IS_PAD (pad), result);
1539 GST_OBJECT_LOCK (pad);
1540 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1541 GST_OBJECT_UNLOCK (pad);
1547 * gst_pad_is_blocking:
1548 * @pad: the #GstPad to query
1550 * Checks if the pad is blocking or not. This is a guaranteed state
1551 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1553 * Returns: %TRUE if the pad is blocking.
1558 gst_pad_is_blocking (GstPad * pad)
1560 gboolean result = FALSE;
1562 g_return_val_if_fail (GST_IS_PAD (pad), result);
1564 GST_OBJECT_LOCK (pad);
1565 /* the blocking flag is only valid if the pad is not flushing */
1566 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1567 GST_OBJECT_UNLOCK (pad);
1573 * gst_pad_needs_reconfigure:
1574 * @pad: the #GstPad to check
1576 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1577 * if the flag was set.
1579 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1582 gst_pad_needs_reconfigure (GstPad * pad)
1584 gboolean reconfigure;
1586 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1588 GST_OBJECT_LOCK (pad);
1589 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1590 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1591 GST_OBJECT_UNLOCK (pad);
1597 * gst_pad_check_reconfigure:
1598 * @pad: the #GstPad to check
1600 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1601 * if the flag was set.
1603 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1606 gst_pad_check_reconfigure (GstPad * pad)
1608 gboolean reconfigure;
1610 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1612 GST_OBJECT_LOCK (pad);
1613 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1615 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1616 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1618 GST_OBJECT_UNLOCK (pad);
1624 * gst_pad_mark_reconfigure:
1625 * @pad: the #GstPad to mark
1627 * Mark a pad for needing reconfiguration. The next call to
1628 * gst_pad_check_reconfigure() will return %TRUE after this call.
1631 gst_pad_mark_reconfigure (GstPad * pad)
1633 g_return_if_fail (GST_IS_PAD (pad));
1635 GST_OBJECT_LOCK (pad);
1636 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1637 GST_OBJECT_UNLOCK (pad);
1641 * gst_pad_set_activate_function:
1643 * @f: the #GstPadActivateFunction to set.
1645 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1649 * gst_pad_set_activate_function_full:
1651 * @activate: the #GstPadActivateFunction to set.
1652 * @user_data: user_data passed to @notify
1653 * @notify: notify called when @activate will not be used anymore.
1655 * Sets the given activate function for @pad. The activate function will
1656 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1657 * Only makes sense to set on sink pads.
1659 * Call this function if your sink pad can start a pull-based task.
1662 gst_pad_set_activate_function_full (GstPad * pad,
1663 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1665 g_return_if_fail (GST_IS_PAD (pad));
1667 if (pad->activatenotify)
1668 pad->activatenotify (pad->activatedata);
1669 GST_PAD_ACTIVATEFUNC (pad) = activate;
1670 pad->activatedata = user_data;
1671 pad->activatenotify = notify;
1673 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1674 GST_DEBUG_FUNCPTR_NAME (activate));
1678 * gst_pad_set_activatemode_function:
1680 * @f: the #GstPadActivateModeFunction to set.
1682 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1686 * gst_pad_set_activatemode_function_full:
1688 * @activatemode: the #GstPadActivateModeFunction to set.
1689 * @user_data: user_data passed to @notify
1690 * @notify: notify called when @activatemode will not be used anymore.
1692 * Sets the given activate_mode function for the pad. An activate_mode function
1693 * prepares the element for data passing.
1696 gst_pad_set_activatemode_function_full (GstPad * pad,
1697 GstPadActivateModeFunction activatemode, gpointer user_data,
1698 GDestroyNotify notify)
1700 g_return_if_fail (GST_IS_PAD (pad));
1702 if (pad->activatemodenotify)
1703 pad->activatemodenotify (pad->activatemodedata);
1704 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1705 pad->activatemodedata = user_data;
1706 pad->activatemodenotify = notify;
1708 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1709 GST_DEBUG_FUNCPTR_NAME (activatemode));
1713 * gst_pad_set_chain_function:
1714 * @p: a sink #GstPad.
1715 * @f: the #GstPadChainFunction to set.
1717 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1721 * gst_pad_set_chain_function_full:
1722 * @pad: a sink #GstPad.
1723 * @chain: the #GstPadChainFunction to set.
1724 * @user_data: user_data passed to @notify
1725 * @notify: notify called when @chain will not be used anymore.
1727 * Sets the given chain function for the pad. The chain function is called to
1728 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1731 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1732 gpointer user_data, GDestroyNotify notify)
1734 g_return_if_fail (GST_IS_PAD (pad));
1735 g_return_if_fail (GST_PAD_IS_SINK (pad));
1737 if (pad->chainnotify)
1738 pad->chainnotify (pad->chaindata);
1739 GST_PAD_CHAINFUNC (pad) = chain;
1740 pad->chaindata = user_data;
1741 pad->chainnotify = notify;
1743 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1744 GST_DEBUG_FUNCPTR_NAME (chain));
1748 * gst_pad_set_chain_list_function:
1749 * @p: a sink #GstPad.
1750 * @f: the #GstPadChainListFunction to set.
1752 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1756 * gst_pad_set_chain_list_function_full:
1757 * @pad: a sink #GstPad.
1758 * @chainlist: the #GstPadChainListFunction to set.
1759 * @user_data: user_data passed to @notify
1760 * @notify: notify called when @chainlist will not be used anymore.
1762 * Sets the given chain list function for the pad. The chainlist function is
1763 * called to process a #GstBufferList input buffer list. See
1764 * #GstPadChainListFunction for more details.
1767 gst_pad_set_chain_list_function_full (GstPad * pad,
1768 GstPadChainListFunction chainlist, gpointer user_data,
1769 GDestroyNotify notify)
1771 g_return_if_fail (GST_IS_PAD (pad));
1772 g_return_if_fail (GST_PAD_IS_SINK (pad));
1774 if (pad->chainlistnotify)
1775 pad->chainlistnotify (pad->chainlistdata);
1776 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1777 pad->chainlistdata = user_data;
1778 pad->chainlistnotify = notify;
1780 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1781 GST_DEBUG_FUNCPTR_NAME (chainlist));
1785 * gst_pad_set_getrange_function:
1786 * @p: a source #GstPad.
1787 * @f: the #GstPadGetRangeFunction to set.
1789 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1793 * gst_pad_set_getrange_function_full:
1794 * @pad: a source #GstPad.
1795 * @get: the #GstPadGetRangeFunction to set.
1796 * @user_data: user_data passed to @notify
1797 * @notify: notify called when @get will not be used anymore.
1799 * Sets the given getrange function for the pad. The getrange function is
1800 * called to produce a new #GstBuffer to start the processing pipeline. see
1801 * #GstPadGetRangeFunction for a description of the getrange function.
1804 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1805 gpointer user_data, GDestroyNotify notify)
1807 g_return_if_fail (GST_IS_PAD (pad));
1808 g_return_if_fail (GST_PAD_IS_SRC (pad));
1810 if (pad->getrangenotify)
1811 pad->getrangenotify (pad->getrangedata);
1812 GST_PAD_GETRANGEFUNC (pad) = get;
1813 pad->getrangedata = user_data;
1814 pad->getrangenotify = notify;
1816 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1817 GST_DEBUG_FUNCPTR_NAME (get));
1821 * gst_pad_set_event_function:
1822 * @p: a #GstPad of either direction.
1823 * @f: the #GstPadEventFunction to set.
1825 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1829 * gst_pad_set_event_function_full:
1830 * @pad: a #GstPad of either direction.
1831 * @event: the #GstPadEventFunction to set.
1832 * @user_data: user_data passed to @notify
1833 * @notify: notify called when @event will not be used anymore.
1835 * Sets the given event handler for the pad.
1838 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1839 gpointer user_data, GDestroyNotify notify)
1841 g_return_if_fail (GST_IS_PAD (pad));
1843 if (pad->eventnotify)
1844 pad->eventnotify (pad->eventdata);
1845 GST_PAD_EVENTFUNC (pad) = event;
1846 pad->eventdata = user_data;
1847 pad->eventnotify = notify;
1849 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1850 GST_DEBUG_FUNCPTR_NAME (event));
1854 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1858 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1859 if (ret == GST_FLOW_OK)
1865 * gst_pad_set_event_full_function:
1866 * @p: a #GstPad of either direction.
1867 * @f: the #GstPadEventFullFunction to set.
1869 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1873 * gst_pad_set_event_full_function_full:
1874 * @pad: a #GstPad of either direction.
1875 * @event: the #GstPadEventFullFunction to set.
1876 * @user_data: user_data passed to @notify
1877 * @notify: notify called when @event will not be used anymore.
1879 * Sets the given event handler for the pad.
1884 gst_pad_set_event_full_function_full (GstPad * pad,
1885 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1887 g_return_if_fail (GST_IS_PAD (pad));
1889 if (pad->eventnotify)
1890 pad->eventnotify (pad->eventdata);
1891 GST_PAD_EVENTFULLFUNC (pad) = event;
1892 GST_PAD_EVENTFUNC (pad) = event_wrap;
1893 pad->eventdata = user_data;
1894 pad->eventnotify = notify;
1896 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1897 GST_DEBUG_FUNCPTR_NAME (event));
1901 * gst_pad_set_query_function:
1902 * @p: a #GstPad of either direction.
1903 * @f: the #GstPadQueryFunction to set.
1905 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1909 * gst_pad_set_query_function_full:
1910 * @pad: a #GstPad of either direction.
1911 * @query: the #GstPadQueryFunction to set.
1912 * @user_data: user_data passed to @notify
1913 * @notify: notify called when @query will not be used anymore.
1915 * Set the given query function for the pad.
1918 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1919 gpointer user_data, GDestroyNotify notify)
1921 g_return_if_fail (GST_IS_PAD (pad));
1923 if (pad->querynotify)
1924 pad->querynotify (pad->querydata);
1925 GST_PAD_QUERYFUNC (pad) = query;
1926 pad->querydata = user_data;
1927 pad->querynotify = notify;
1929 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1930 GST_DEBUG_FUNCPTR_NAME (query));
1934 * gst_pad_set_iterate_internal_links_function:
1935 * @p: a #GstPad of either direction.
1936 * @f: the #GstPadIterIntLinkFunction to set.
1938 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1939 * for the user_data and notify.
1942 * gst_pad_set_iterate_internal_links_function_full:
1943 * @pad: a #GstPad of either direction.
1944 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1945 * @user_data: user_data passed to @notify
1946 * @notify: notify called when @iterintlink will not be used anymore.
1948 * Sets the given internal link iterator function for the pad.
1951 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1952 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1953 GDestroyNotify notify)
1955 g_return_if_fail (GST_IS_PAD (pad));
1957 if (pad->iterintlinknotify)
1958 pad->iterintlinknotify (pad->iterintlinkdata);
1959 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1960 pad->iterintlinkdata = user_data;
1961 pad->iterintlinknotify = notify;
1963 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1964 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1968 * gst_pad_set_link_function:
1970 * @f: the #GstPadLinkFunction to set.
1972 * Calls gst_pad_set_link_function_full() with %NULL
1973 * for the user_data and notify.
1976 * gst_pad_set_link_function_full:
1978 * @link: the #GstPadLinkFunction to set.
1979 * @user_data: user_data passed to @notify
1980 * @notify: notify called when @link will not be used anymore.
1982 * Sets the given link function for the pad. It will be called when
1983 * the pad is linked with another pad.
1985 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1988 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1989 * cannot be made for some reason.
1991 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1992 * of the peer sink pad, if present.
1995 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1996 gpointer user_data, GDestroyNotify notify)
1998 g_return_if_fail (GST_IS_PAD (pad));
2000 if (pad->linknotify)
2001 pad->linknotify (pad->linkdata);
2002 GST_PAD_LINKFUNC (pad) = link;
2003 pad->linkdata = user_data;
2004 pad->linknotify = notify;
2006 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2007 GST_DEBUG_FUNCPTR_NAME (link));
2011 * gst_pad_set_unlink_function:
2013 * @f: the #GstPadUnlinkFunction to set.
2015 * Calls gst_pad_set_unlink_function_full() with %NULL
2016 * for the user_data and notify.
2019 * gst_pad_set_unlink_function_full:
2021 * @unlink: the #GstPadUnlinkFunction to set.
2022 * @user_data: user_data passed to @notify
2023 * @notify: notify called when @unlink will not be used anymore.
2025 * Sets the given unlink function for the pad. It will be called
2026 * when the pad is unlinked.
2029 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2030 gpointer user_data, GDestroyNotify notify)
2032 g_return_if_fail (GST_IS_PAD (pad));
2034 if (pad->unlinknotify)
2035 pad->unlinknotify (pad->unlinkdata);
2036 GST_PAD_UNLINKFUNC (pad) = unlink;
2037 pad->unlinkdata = user_data;
2038 pad->unlinknotify = notify;
2040 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2041 GST_DEBUG_FUNCPTR_NAME (unlink));
2046 * @srcpad: the source #GstPad to unlink.
2047 * @sinkpad: the sink #GstPad to unlink.
2049 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2050 * signal on both pads.
2052 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2053 * the pads were not linked together.
2058 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2060 gboolean result = FALSE;
2061 GstElement *parent = NULL;
2063 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2064 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2065 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2066 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2068 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2070 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2071 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2072 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2074 /* We need to notify the parent before taking any pad locks as the bin in
2075 * question might be waiting for a lock on the pad while holding its lock
2076 * that our message will try to take. */
2077 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2078 if (GST_IS_ELEMENT (parent)) {
2079 gst_element_post_message (parent,
2080 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2081 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2083 gst_object_unref (parent);
2088 GST_OBJECT_LOCK (srcpad);
2089 GST_OBJECT_LOCK (sinkpad);
2091 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2092 goto not_linked_together;
2094 if (GST_PAD_UNLINKFUNC (srcpad)) {
2095 GstObject *tmpparent;
2097 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2099 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2100 RELEASE_PARENT (tmpparent);
2103 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2104 GstObject *tmpparent;
2106 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2108 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2109 RELEASE_PARENT (tmpparent);
2113 /* first clear peers */
2114 GST_PAD_PEER (srcpad) = NULL;
2115 GST_PAD_PEER (sinkpad) = NULL;
2117 GST_OBJECT_UNLOCK (sinkpad);
2118 GST_OBJECT_UNLOCK (srcpad);
2120 /* fire off a signal to each of the pads telling them
2121 * that they've been unlinked */
2122 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2123 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2125 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2126 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2131 if (parent != NULL) {
2132 gst_element_post_message (parent,
2133 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2134 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2135 gst_object_unref (parent);
2137 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2141 not_linked_together:
2143 /* we do not emit a warning in this case because unlinking cannot
2144 * be made MT safe.*/
2145 GST_OBJECT_UNLOCK (sinkpad);
2146 GST_OBJECT_UNLOCK (srcpad);
2152 * gst_pad_is_linked:
2153 * @pad: pad to check
2155 * Checks if a @pad is linked to another pad or not.
2157 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2162 gst_pad_is_linked (GstPad * pad)
2166 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2168 GST_OBJECT_LOCK (pad);
2169 result = (GST_PAD_PEER (pad) != NULL);
2170 GST_OBJECT_UNLOCK (pad);
2175 /* get the caps from both pads and see if the intersection
2178 * This function should be called with the pad LOCK on both
2182 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2183 GstPadLinkCheck flags)
2185 GstCaps *srccaps = NULL;
2186 GstCaps *sinkcaps = NULL;
2187 gboolean compatible = FALSE;
2189 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2192 /* Doing the expensive caps checking takes priority over only checking the template caps */
2193 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2194 GST_OBJECT_UNLOCK (sink);
2195 GST_OBJECT_UNLOCK (src);
2197 srccaps = gst_pad_query_caps (src, NULL);
2198 sinkcaps = gst_pad_query_caps (sink, NULL);
2200 GST_OBJECT_LOCK (src);
2201 GST_OBJECT_LOCK (sink);
2203 /* If one of the two pads doesn't have a template, consider the intersection
2205 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2206 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2210 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2212 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2215 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2217 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2220 /* if we have caps on both pads we can check the intersection. If one
2221 * of the caps is %NULL, we return %TRUE. */
2222 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2224 gst_caps_unref (srccaps);
2226 gst_caps_unref (sinkcaps);
2230 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2231 gst_caps_unref (srccaps);
2232 gst_caps_unref (sinkcaps);
2235 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2236 (compatible ? "" : "not "));
2241 /* check if the grandparents of both pads are the same.
2242 * This check is required so that we don't try to link
2243 * pads from elements in different bins without ghostpads.
2245 * The LOCK should be held on both pads
2248 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2250 GstObject *psrc, *psink;
2252 psrc = GST_OBJECT_PARENT (src);
2253 psink = GST_OBJECT_PARENT (sink);
2255 /* if one of the pads has no parent, we allow the link */
2256 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2259 /* only care about parents that are elements */
2260 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2261 goto no_element_parent;
2263 /* if the parents are the same, we have a loop */
2264 if (G_UNLIKELY (psrc == psink))
2267 /* if they both have a parent, we check the grandparents. We can not lock
2268 * the parent because we hold on the child (pad) and the locking order is
2269 * parent >> child. */
2270 psrc = GST_OBJECT_PARENT (psrc);
2271 psink = GST_OBJECT_PARENT (psink);
2273 /* if they have grandparents but they are not the same */
2274 if (G_UNLIKELY (psrc != psink))
2275 goto wrong_grandparents;
2282 GST_CAT_DEBUG (GST_CAT_CAPS,
2283 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2284 GST_PTR_FORMAT, psrc, psink);
2289 GST_CAT_DEBUG (GST_CAT_CAPS,
2290 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2291 GST_PTR_FORMAT, psrc, psink);
2296 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2302 GST_CAT_DEBUG (GST_CAT_CAPS,
2303 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2304 GST_PTR_FORMAT, psrc, psink);
2309 /* FIXME leftover from an attempt at refactoring... */
2310 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2311 * the two pads will be locked in the srcpad, sinkpad order. */
2312 static GstPadLinkReturn
2313 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2315 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2316 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2318 GST_OBJECT_LOCK (srcpad);
2320 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2321 goto src_was_linked;
2323 GST_OBJECT_LOCK (sinkpad);
2325 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2326 goto sink_was_linked;
2328 /* check hierarchy, pads can only be linked if the grandparents
2330 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2331 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2332 goto wrong_hierarchy;
2334 /* check pad caps for non-empty intersection */
2335 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2338 /* FIXME check pad scheduling for non-empty intersection */
2340 return GST_PAD_LINK_OK;
2344 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2345 GST_DEBUG_PAD_NAME (srcpad),
2346 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2347 /* we do not emit a warning in this case because unlinking cannot
2348 * be made MT safe.*/
2349 GST_OBJECT_UNLOCK (srcpad);
2350 return GST_PAD_LINK_WAS_LINKED;
2354 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2355 GST_DEBUG_PAD_NAME (sinkpad),
2356 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2357 /* we do not emit a warning in this case because unlinking cannot
2358 * be made MT safe.*/
2359 GST_OBJECT_UNLOCK (sinkpad);
2360 GST_OBJECT_UNLOCK (srcpad);
2361 return GST_PAD_LINK_WAS_LINKED;
2365 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2366 GST_OBJECT_UNLOCK (sinkpad);
2367 GST_OBJECT_UNLOCK (srcpad);
2368 return GST_PAD_LINK_WRONG_HIERARCHY;
2372 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2373 GST_OBJECT_UNLOCK (sinkpad);
2374 GST_OBJECT_UNLOCK (srcpad);
2375 return GST_PAD_LINK_NOFORMAT;
2381 * @srcpad: the source #GstPad.
2382 * @sinkpad: the sink #GstPad.
2384 * Checks if the source pad and the sink pad are compatible so they can be
2387 * Returns: %TRUE if the pads can be linked.
2390 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2392 GstPadLinkReturn result;
2394 /* generic checks */
2395 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2396 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2398 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2399 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2401 /* gst_pad_link_prepare does everything for us, we only release the locks
2402 * on the pads that it gets us. If this function returns !OK the locks are not
2404 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2405 if (result != GST_PAD_LINK_OK)
2408 GST_OBJECT_UNLOCK (srcpad);
2409 GST_OBJECT_UNLOCK (sinkpad);
2412 return result == GST_PAD_LINK_OK;
2416 * gst_pad_link_full:
2417 * @srcpad: the source #GstPad to link.
2418 * @sinkpad: the sink #GstPad to link.
2419 * @flags: the checks to validate when linking
2421 * Links the source pad and the sink pad.
2423 * This variant of #gst_pad_link provides a more granular control on the
2424 * checks being done when linking. While providing some considerable speedups
2425 * the caller of this method must be aware that wrong usage of those flags
2426 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2427 * for more information.
2431 * Returns: A result code indicating if the connection worked or
2435 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2437 GstPadLinkReturn result;
2439 GstPadLinkFunction srcfunc, sinkfunc;
2441 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2442 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2443 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2444 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2445 GST_PAD_LINK_WRONG_DIRECTION);
2447 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2449 /* Notify the parent early. See gst_pad_unlink for details. */
2450 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2451 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2452 gst_element_post_message (parent,
2453 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2454 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2456 gst_object_unref (parent);
2461 /* prepare will also lock the two pads */
2462 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2464 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2465 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2466 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2467 gst_pad_link_get_name (result));
2471 /* must set peers before calling the link function */
2472 GST_PAD_PEER (srcpad) = sinkpad;
2473 GST_PAD_PEER (sinkpad) = srcpad;
2475 /* check events, when something is different, mark pending */
2476 schedule_events (srcpad, sinkpad);
2478 /* get the link functions */
2479 srcfunc = GST_PAD_LINKFUNC (srcpad);
2480 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2482 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2483 /* custom link functions, execute them */
2484 GST_OBJECT_UNLOCK (sinkpad);
2485 GST_OBJECT_UNLOCK (srcpad);
2488 GstObject *tmpparent;
2490 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2491 /* this one will call the peer link function */
2492 result = srcfunc (srcpad, tmpparent, sinkpad);
2493 RELEASE_PARENT (tmpparent);
2494 } else if (sinkfunc) {
2495 GstObject *tmpparent;
2497 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2498 /* if no source link function, we need to call the sink link
2499 * function ourselves. */
2500 result = sinkfunc (sinkpad, tmpparent, srcpad);
2501 RELEASE_PARENT (tmpparent);
2505 GST_OBJECT_LOCK (srcpad);
2506 GST_OBJECT_LOCK (sinkpad);
2508 /* we released the lock, check if the same pads are linked still */
2509 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2510 goto concurrent_link;
2512 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2515 GST_OBJECT_UNLOCK (sinkpad);
2516 GST_OBJECT_UNLOCK (srcpad);
2518 /* fire off a signal to each of the pads telling them
2519 * that they've been linked */
2520 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2521 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2523 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2524 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2526 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2527 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2530 if (G_LIKELY (parent)) {
2531 gst_element_post_message (parent,
2532 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2533 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2534 gst_object_unref (parent);
2537 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2543 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2544 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2545 GST_OBJECT_UNLOCK (sinkpad);
2546 GST_OBJECT_UNLOCK (srcpad);
2548 /* The other link operation succeeded first */
2549 result = GST_PAD_LINK_WAS_LINKED;
2554 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2555 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2556 gst_pad_link_get_name (result));
2558 GST_PAD_PEER (srcpad) = NULL;
2559 GST_PAD_PEER (sinkpad) = NULL;
2561 GST_OBJECT_UNLOCK (sinkpad);
2562 GST_OBJECT_UNLOCK (srcpad);
2570 * @srcpad: the source #GstPad to link.
2571 * @sinkpad: the sink #GstPad to link.
2573 * Links the source pad and the sink pad.
2575 * Returns: A result code indicating if the connection worked or
2581 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2583 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2587 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2589 GstPadTemplate **template_p;
2591 /* this function would need checks if it weren't static */
2593 GST_OBJECT_LOCK (pad);
2594 template_p = &pad->padtemplate;
2595 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2596 GST_OBJECT_UNLOCK (pad);
2599 gst_pad_template_pad_created (templ, pad);
2603 * gst_pad_get_pad_template:
2606 * Gets the template for @pad.
2608 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2609 * this pad was instantiated, or %NULL if this pad has no
2610 * template. Unref after usage.
2613 gst_pad_get_pad_template (GstPad * pad)
2615 GstPadTemplate *templ;
2617 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2619 templ = GST_PAD_PAD_TEMPLATE (pad);
2621 return (templ ? gst_object_ref (templ) : NULL);
2625 * gst_pad_has_current_caps:
2626 * @pad: a #GstPad to check
2628 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2630 * Returns: %TRUE when @pad has caps associated with it.
2633 gst_pad_has_current_caps (GstPad * pad)
2638 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2640 GST_OBJECT_LOCK (pad);
2641 caps = get_pad_caps (pad);
2642 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2643 "check current pad caps %" GST_PTR_FORMAT, caps);
2644 result = (caps != NULL);
2645 GST_OBJECT_UNLOCK (pad);
2651 * gst_pad_get_current_caps:
2652 * @pad: a #GstPad to get the current capabilities of.
2654 * Gets the capabilities currently configured on @pad with the last
2655 * #GST_EVENT_CAPS event.
2657 * Returns: (transfer full) (nullable): the current caps of the pad with
2658 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2661 gst_pad_get_current_caps (GstPad * pad)
2665 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2667 GST_OBJECT_LOCK (pad);
2668 if ((result = get_pad_caps (pad)))
2669 gst_caps_ref (result);
2670 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2671 "get current pad caps %" GST_PTR_FORMAT, result);
2672 GST_OBJECT_UNLOCK (pad);
2678 * gst_pad_get_pad_template_caps:
2679 * @pad: a #GstPad to get the template capabilities from.
2681 * Gets the capabilities for @pad's template.
2683 * Returns: (transfer full): the #GstCaps of this pad template.
2684 * Unref after usage.
2687 gst_pad_get_pad_template_caps (GstPad * pad)
2689 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2691 if (GST_PAD_PAD_TEMPLATE (pad))
2692 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2694 return gst_caps_ref (GST_CAPS_ANY);
2699 * @pad: a #GstPad to get the peer of.
2701 * Gets the peer of @pad. This function refs the peer pad so
2702 * you need to unref it after use.
2704 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2709 gst_pad_get_peer (GstPad * pad)
2713 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2715 GST_OBJECT_LOCK (pad);
2716 result = GST_PAD_PEER (pad);
2718 gst_object_ref (result);
2719 GST_OBJECT_UNLOCK (pad);
2725 * gst_pad_get_allowed_caps:
2728 * Gets the capabilities of the allowed media types that can flow through
2729 * @pad and its peer.
2731 * The allowed capabilities is calculated as the intersection of the results of
2732 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2733 * on the resulting caps.
2735 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2736 * pad link. Unref the caps when you no longer need it. This
2737 * function returns %NULL when @pad has no peer.
2742 gst_pad_get_allowed_caps (GstPad * pad)
2745 GstCaps *caps = NULL;
2748 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2750 GST_OBJECT_LOCK (pad);
2751 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2753 GST_OBJECT_UNLOCK (pad);
2755 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2757 mycaps = gst_pad_query_caps (pad, NULL);
2759 /* Query peer caps */
2760 query = gst_query_new_caps (mycaps);
2761 if (!gst_pad_peer_query (pad, query)) {
2762 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2766 gst_query_parse_caps_result (query, &caps);
2768 g_warn_if_fail (caps != NULL);
2771 gst_caps_ref (caps);
2773 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2777 gst_query_unref (query);
2778 gst_caps_unref (mycaps);
2784 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2785 GST_OBJECT_UNLOCK (pad);
2792 * gst_pad_iterate_internal_links_default:
2793 * @pad: the #GstPad to get the internal links of.
2794 * @parent: (allow-none): the parent of @pad or %NULL
2796 * Iterate the list of pads to which the given pad is linked to inside of
2797 * the parent element.
2798 * This is the default handler, and thus returns an iterator of all of the
2799 * pads inside the parent element with opposite direction.
2801 * The caller must free this iterator after use with gst_iterator_free().
2803 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2804 * has no parent. Unref each returned pad with gst_object_unref().
2807 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2814 GstElement *eparent;
2816 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2818 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2819 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2821 GST_OBJECT_LOCK (pad);
2822 eparent = GST_PAD_PARENT (pad);
2823 if (!eparent || !GST_IS_ELEMENT (eparent))
2826 gst_object_ref (eparent);
2827 GST_OBJECT_UNLOCK (pad);
2830 if (pad->direction == GST_PAD_SRC)
2831 padlist = &eparent->sinkpads;
2833 padlist = &eparent->srcpads;
2835 GST_DEBUG_OBJECT (pad, "Making iterator");
2837 cookie = &eparent->pads_cookie;
2839 lock = GST_OBJECT_GET_LOCK (eparent);
2841 res = gst_iterator_new_list (GST_TYPE_PAD,
2842 lock, cookie, padlist, (GObject *) owner, NULL);
2844 gst_object_unref (owner);
2851 GST_OBJECT_UNLOCK (pad);
2852 GST_DEBUG_OBJECT (pad, "no parent element");
2858 * gst_pad_iterate_internal_links:
2859 * @pad: the GstPad to get the internal links of.
2861 * Gets an iterator for the pads to which the given pad is linked to inside
2862 * of the parent element.
2864 * Each #GstPad element yielded by the iterator will have its refcount increased,
2865 * so unref after use.
2867 * Free-function: gst_iterator_free
2869 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2870 * or %NULL when the pad does not have an iterator function
2871 * configured. Use gst_iterator_free() after usage.
2874 gst_pad_iterate_internal_links (GstPad * pad)
2876 GstIterator *res = NULL;
2879 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2881 GST_OBJECT_LOCK (pad);
2882 ACQUIRE_PARENT (pad, parent, no_parent);
2883 GST_OBJECT_UNLOCK (pad);
2885 if (GST_PAD_ITERINTLINKFUNC (pad))
2886 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2888 RELEASE_PARENT (parent);
2895 GST_DEBUG_OBJECT (pad, "no parent");
2896 GST_OBJECT_UNLOCK (pad);
2904 * @forward: (scope call): a #GstPadForwardFunction
2905 * @user_data: user data passed to @forward
2907 * Calls @forward for all internally linked pads of @pad. This function deals with
2908 * dynamically changing internal pads and will make sure that the @forward
2909 * function is only called once for each pad.
2911 * When @forward returns %TRUE, no further pads will be processed.
2913 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2916 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2919 gboolean result = FALSE;
2921 gboolean done = FALSE;
2922 GValue item = { 0, };
2923 GList *pushed_pads = NULL;
2925 iter = gst_pad_iterate_internal_links (pad);
2931 switch (gst_iterator_next (iter, &item)) {
2932 case GST_ITERATOR_OK:
2936 intpad = g_value_get_object (&item);
2938 /* if already pushed, skip. FIXME, find something faster to tag pads */
2939 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2940 g_value_reset (&item);
2944 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2945 GST_DEBUG_PAD_NAME (intpad));
2946 done = result = forward (intpad, user_data);
2948 pushed_pads = g_list_prepend (pushed_pads, intpad);
2950 g_value_reset (&item);
2953 case GST_ITERATOR_RESYNC:
2954 /* We don't reset the result here because we don't push the event
2955 * again on pads that got the event already and because we need
2956 * to consider the result of the previous pushes */
2957 gst_iterator_resync (iter);
2959 case GST_ITERATOR_ERROR:
2960 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2963 case GST_ITERATOR_DONE:
2968 g_value_unset (&item);
2969 gst_iterator_free (iter);
2971 g_list_free (pushed_pads);
2981 gboolean dispatched;
2985 event_forward_func (GstPad * pad, EventData * data)
2987 /* for each pad we send to, we should ref the event; it's up
2988 * to downstream to unref again when handled. */
2989 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2990 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2992 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2994 data->dispatched = TRUE;
3001 * gst_pad_event_default:
3002 * @pad: a #GstPad to call the default event handler on.
3003 * @parent: (allow-none): the parent of @pad or %NULL
3004 * @event: (transfer full): the #GstEvent to handle.
3006 * Invokes the default event handler for the given pad.
3008 * The EOS event will pause the task associated with @pad before it is forwarded
3009 * to all internally linked pads,
3011 * The event is sent to all pads internally linked to @pad. This function
3012 * takes ownership of @event.
3014 * Returns: %TRUE if the event was sent successfully.
3017 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3019 gboolean result, forward = TRUE;
3021 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3022 g_return_val_if_fail (event != NULL, FALSE);
3024 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3027 switch (GST_EVENT_TYPE (event)) {
3028 case GST_EVENT_CAPS:
3029 forward = GST_PAD_IS_PROXY_CAPS (pad);
3040 data.dispatched = FALSE;
3041 data.result = FALSE;
3043 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3045 /* for sinkpads without a parent element or without internal links, nothing
3046 * will be dispatched but we still want to return TRUE. */
3047 if (data.dispatched)
3048 result = data.result;
3053 gst_event_unref (event);
3058 /* Default accept caps implementation just checks against
3059 * the allowed caps for the pad */
3061 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3063 /* get the caps and see if it intersects to something not empty */
3064 GstCaps *caps, *allowed = NULL;
3067 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3069 /* first forward the query to internally linked pads when we are dealing with
3071 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3072 result = gst_pad_proxy_query_accept_caps (pad, query);
3074 allowed = gst_pad_get_pad_template_caps (pad);
3079 gst_query_parse_accept_caps (query, &caps);
3081 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3082 allowed = gst_pad_get_pad_template_caps (pad);
3084 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3085 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3086 allowed = gst_pad_query_caps (pad, caps);
3091 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3092 GST_DEBUG_OBJECT (pad,
3093 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3095 result = gst_caps_can_intersect (caps, allowed);
3097 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3098 GST_PTR_FORMAT, allowed, caps);
3099 result = gst_caps_is_subset (caps, allowed);
3101 gst_caps_unref (allowed);
3103 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3106 gst_query_set_accept_caps_result (query, result);
3112 /* Default caps implementation */
3114 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3116 GstCaps *result = NULL, *filter;
3117 GstPadTemplate *templ;
3118 gboolean fixed_caps;
3120 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3123 /* first try to proxy if we must */
3124 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3125 if ((gst_pad_proxy_query_caps (pad, query))) {
3130 gst_query_parse_caps (query, &filter);
3132 /* no proxy or it failed, do default handling */
3133 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3135 GST_OBJECT_LOCK (pad);
3137 /* fixed caps, try the negotiated caps first */
3138 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3139 if ((result = get_pad_caps (pad)))
3140 goto filter_done_unlock;
3143 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3144 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3145 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3146 goto filter_done_unlock;
3150 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3151 "non-fixed pad caps: trying pad caps");
3152 /* non fixed caps, try the negotiated caps */
3153 if ((result = get_pad_caps (pad)))
3154 goto filter_done_unlock;
3157 /* this almost never happens */
3158 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3159 result = GST_CAPS_ANY;
3162 GST_OBJECT_UNLOCK (pad);
3164 /* run the filter on the result */
3166 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3167 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3168 GST_PTR_FORMAT, result, result, filter, filter);
3169 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3170 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3173 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3174 "using caps %p %" GST_PTR_FORMAT, result, result);
3175 result = gst_caps_ref (result);
3177 gst_query_set_caps_result (query, result);
3178 gst_caps_unref (result);
3184 /* Default latency implementation */
3189 GstClockTime min, max;
3193 query_latency_default_fold (const GValue * item, GValue * ret,
3196 GstPad *pad = g_value_get_object (item), *peer;
3197 LatencyFoldData *fold_data = user_data;
3199 gboolean res = FALSE;
3201 query = gst_query_new_latency ();
3203 peer = gst_pad_get_peer (pad);
3205 res = gst_pad_peer_query (pad, query);
3207 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3212 GstClockTime min, max;
3214 gst_query_parse_latency (query, &live, &min, &max);
3216 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3217 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3219 /* FIXME : Why do we only take values into account if it's live ? */
3220 if (live || fold_data->count == 0) {
3221 if (min > fold_data->min)
3222 fold_data->min = min;
3224 if (fold_data->max == GST_CLOCK_TIME_NONE)
3225 fold_data->max = max;
3226 else if (max < fold_data->max)
3227 fold_data->max = max;
3229 fold_data->live = live;
3231 fold_data->count += 1;
3233 GST_DEBUG_OBJECT (pad, "latency query failed");
3234 g_value_set_boolean (ret, FALSE);
3237 gst_query_unref (query);
3239 gst_object_unref (peer);
3245 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3248 GstIteratorResult res;
3249 GValue ret = G_VALUE_INIT;
3251 LatencyFoldData fold_data;
3253 it = gst_pad_iterate_internal_links (pad);
3255 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3259 g_value_init (&ret, G_TYPE_BOOLEAN);
3262 fold_data.count = 0;
3263 fold_data.live = FALSE;
3265 fold_data.max = GST_CLOCK_TIME_NONE;
3267 g_value_set_boolean (&ret, TRUE);
3268 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3270 case GST_ITERATOR_OK:
3271 g_assert_not_reached ();
3273 case GST_ITERATOR_DONE:
3275 case GST_ITERATOR_ERROR:
3276 g_value_set_boolean (&ret, FALSE);
3278 case GST_ITERATOR_RESYNC:
3279 gst_iterator_resync (it);
3282 g_assert_not_reached ();
3285 gst_iterator_free (it);
3287 query_ret = g_value_get_boolean (&ret);
3289 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3290 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3291 fold_data.min, fold_data.max);
3293 if (fold_data.min > fold_data.max) {
3294 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3297 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3299 GST_LOG_OBJECT (pad, "latency query failed");
3309 gboolean dispatched;
3313 query_forward_func (GstPad * pad, QueryData * data)
3315 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3316 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3318 data->result |= gst_pad_peer_query (pad, data->query);
3320 data->dispatched = TRUE;
3322 /* stop on first successful reply */
3323 return data->result;
3327 * gst_pad_query_default:
3328 * @pad: a #GstPad to call the default query handler on.
3329 * @parent: (allow-none): the parent of @pad or %NULL
3330 * @query: (transfer none): the #GstQuery to handle.
3332 * Invokes the default query handler for the given pad.
3333 * The query is sent to all pads internally linked to @pad. Note that
3334 * if there are many possible sink pads that are internally linked to
3335 * @pad, only one will be sent the query.
3336 * Multi-sinkpad elements should implement custom query handlers.
3338 * Returns: %TRUE if the query was performed successfully.
3341 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3343 gboolean forward, ret = FALSE;
3345 switch (GST_QUERY_TYPE (query)) {
3346 case GST_QUERY_SCHEDULING:
3347 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3349 case GST_QUERY_ALLOCATION:
3350 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3352 case GST_QUERY_ACCEPT_CAPS:
3353 ret = gst_pad_query_accept_caps_default (pad, query);
3356 case GST_QUERY_CAPS:
3357 ret = gst_pad_query_caps_default (pad, query);
3360 case GST_QUERY_LATENCY:
3361 ret = gst_pad_query_latency_default (pad, query);
3364 case GST_QUERY_POSITION:
3365 case GST_QUERY_SEEKING:
3366 case GST_QUERY_FORMATS:
3367 case GST_QUERY_JITTER:
3368 case GST_QUERY_RATE:
3369 case GST_QUERY_CONVERT:
3375 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3376 query, GST_QUERY_TYPE_NAME (query));
3382 data.dispatched = FALSE;
3383 data.result = FALSE;
3385 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3387 if (data.dispatched) {
3390 /* nothing dispatched, assume drained */
3391 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3401 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3403 GstPad *pad = data->pad;
3404 GstPadProbeInfo *info = data->info;
3405 GstPadProbeType type, flags;
3406 GstPadProbeCallback callback;
3407 GstPadProbeReturn ret;
3408 gpointer original_data;
3410 /* if we have called this callback, do nothing */
3411 if (PROBE_COOKIE (hook) == data->cookie) {
3412 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3413 "hook %lu, cookie %u already called", hook->hook_id,
3414 PROBE_COOKIE (hook));
3418 PROBE_COOKIE (hook) = data->cookie;
3420 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3422 original_data = info->data;
3424 /* one of the scheduling types */
3425 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3428 if (G_UNLIKELY (data->handled)) {
3429 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3430 "probe previously returned HANDLED, not calling again");
3432 } else if (G_UNLIKELY (data->dropped)) {
3433 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3434 "probe previously returned DROPPED, not calling again");
3438 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3439 /* one of the data types for non-idle probes */
3440 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3441 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3443 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3444 /* one of the data types for non-idle probes */
3445 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3446 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3449 /* Type must have PULL or PUSH probe types */
3450 g_assert_not_reached ();
3453 /* one of the blocking types must match */
3454 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3455 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3457 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3458 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3460 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3461 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3462 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3465 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3466 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3467 PROBE_COOKIE (hook), flags);
3469 data->marshalled = TRUE;
3471 callback = (GstPadProbeCallback) hook->func;
3472 if (callback == NULL)
3475 info->id = hook->hook_id;
3477 GST_OBJECT_UNLOCK (pad);
3479 ret = callback (pad, info, hook->data);
3481 GST_OBJECT_LOCK (pad);
3483 if (original_data != NULL && info->data == NULL) {
3484 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3485 info->type = GST_PAD_PROBE_TYPE_INVALID;
3486 data->dropped = TRUE;
3490 case GST_PAD_PROBE_REMOVE:
3491 /* remove the probe */
3492 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3493 cleanup_hook (pad, hook);
3495 case GST_PAD_PROBE_DROP:
3496 /* need to drop the data, make sure other probes don't get called
3498 GST_DEBUG_OBJECT (pad, "asked to drop item");
3499 info->type = GST_PAD_PROBE_TYPE_INVALID;
3500 data->dropped = TRUE;
3502 case GST_PAD_PROBE_HANDLED:
3503 GST_DEBUG_OBJECT (pad, "probe handled data");
3504 data->handled = TRUE;
3506 case GST_PAD_PROBE_PASS:
3507 /* inform the pad block to let things pass */
3508 GST_DEBUG_OBJECT (pad, "asked to pass item");
3511 case GST_PAD_PROBE_OK:
3512 GST_DEBUG_OBJECT (pad, "probe returned OK");
3515 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3522 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3523 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3524 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3529 /* a probe that does not take or return any data */
3530 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3532 if (G_UNLIKELY (pad->num_probes)) { \
3533 GstFlowReturn pval = defaultval; \
3534 /* pass NULL as the data item */ \
3535 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3536 info.ABI.abi.flow_ret = defaultval; \
3537 ret = do_probe_callbacks (pad, &info, defaultval); \
3538 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3543 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3545 if (G_UNLIKELY (pad->num_probes)) { \
3546 /* pass the data item */ \
3547 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3548 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3549 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3550 /* store the possibly updated data item */ \
3551 data = GST_PAD_PROBE_INFO_DATA (&info); \
3552 /* if something went wrong, exit */ \
3553 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3554 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3555 ret = info.ABI.abi.flow_ret; \
3556 goto handle_label; \
3563 #define PROBE_PUSH(pad,mask,data,label) \
3564 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3565 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3566 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3567 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3568 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3570 static GstFlowReturn
3571 do_pad_idle_probe_wait (GstPad * pad)
3573 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3574 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3575 "waiting idle probe to be removed");
3576 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3577 GST_PAD_BLOCK_WAIT (pad);
3578 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3579 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3581 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3582 return GST_FLOW_FLUSHING;
3587 #define PROBE_TYPE_IS_SERIALIZED(i) \
3590 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3591 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3592 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3594 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3595 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3597 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3598 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3602 static GstFlowReturn
3603 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3604 GstFlowReturn defaultval)
3613 data.handled = FALSE;
3614 data.marshalled = FALSE;
3615 data.dropped = FALSE;
3616 data.cookie = ++pad->priv->probe_cookie;
3619 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3621 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3622 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3627 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3628 "do probes cookie %u", data.cookie);
3629 cookie = pad->priv->probe_list_cookie;
3631 g_hook_list_marshal (&pad->probes, TRUE,
3632 (GHookMarshaller) probe_hook_marshal, &data);
3634 /* if the list changed, call the new callbacks (they will not have their
3635 * cookie set to data.cookie */
3636 if (cookie != pad->priv->probe_list_cookie) {
3637 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3638 "probe list changed, restarting");
3642 /* the first item that dropped will stop the hooks and then we drop here */
3646 /* If one handler took care of it, let the the item pass */
3651 /* if no handler matched and we are blocking, let the item pass */
3652 if (!data.marshalled && is_block)
3655 /* At this point, all handlers returned either OK or PASS. If one handler
3656 * returned PASS, let the item pass */
3661 while (GST_PAD_IS_BLOCKED (pad)) {
3662 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3663 "we are blocked %d times", pad->num_blocked);
3665 /* we might have released the lock */
3666 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3669 /* now we block the streaming thread. It can be unlocked when we
3670 * deactivate the pad (which will also set the FLUSHING flag) or
3671 * when the pad is unblocked. A flushing event will also unblock
3672 * the pad after setting the FLUSHING flag. */
3673 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3674 "Waiting to be unblocked or set flushing");
3675 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3676 GST_PAD_BLOCK_WAIT (pad);
3677 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3678 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3680 /* if the list changed, call the new callbacks (they will not have their
3681 * cookie set to data.cookie */
3682 if (cookie != pad->priv->probe_list_cookie) {
3683 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3684 "probe list changed, restarting");
3688 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3698 GST_DEBUG_OBJECT (pad, "pad is flushing");
3699 return GST_FLOW_FLUSHING;
3703 GST_DEBUG_OBJECT (pad, "data is dropped");
3704 return GST_FLOW_CUSTOM_SUCCESS;
3708 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3709 GST_DEBUG_OBJECT (pad, "data is passed");
3714 GST_DEBUG_OBJECT (pad, "data was handled");
3715 return GST_FLOW_CUSTOM_SUCCESS_1;
3722 * gst_pad_get_offset:
3725 * Get the offset applied to the running time of @pad. @pad has to be a source
3728 * Returns: the offset.
3731 gst_pad_get_offset (GstPad * pad)
3735 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3737 GST_OBJECT_LOCK (pad);
3738 result = pad->offset;
3739 GST_OBJECT_UNLOCK (pad);
3745 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3747 ev->received = FALSE;
3752 * gst_pad_set_offset:
3754 * @offset: the offset
3756 * Set the offset that will be applied to the running time of @pad.
3759 gst_pad_set_offset (GstPad * pad, gint64 offset)
3761 g_return_if_fail (GST_IS_PAD (pad));
3763 GST_OBJECT_LOCK (pad);
3764 /* if nothing changed, do nothing */
3765 if (pad->offset == offset)
3768 pad->offset = offset;
3769 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3770 GST_STIME_ARGS (offset));
3772 /* resend all sticky events with updated offset on next buffer push */
3773 events_foreach (pad, mark_event_not_received, NULL);
3774 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3777 GST_OBJECT_UNLOCK (pad);
3784 /* If TRUE and ret is not OK this means
3785 * that pushing the EOS event failed
3789 /* If called for an event this is
3790 * the event that would be pushed
3791 * next. Don't forward sticky events
3792 * that would come after that */
3796 /* should be called with pad LOCK */
3798 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3800 PushStickyData *data = user_data;
3801 GstEvent *event = ev->event;
3804 GST_DEBUG_OBJECT (pad, "event %s was already received",
3805 GST_EVENT_TYPE_NAME (event));
3809 /* If we're called because of an sticky event, only forward
3810 * events that would come before this new event and the
3812 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3813 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3814 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3815 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3817 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3818 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3821 switch (data->ret) {
3823 ev->received = TRUE;
3824 GST_DEBUG_OBJECT (pad, "event %s marked received",
3825 GST_EVENT_TYPE_NAME (event));
3827 case GST_FLOW_CUSTOM_SUCCESS:
3828 /* we can't assume the event is received when it was dropped */
3829 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3830 GST_EVENT_TYPE_NAME (event));
3831 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3832 data->ret = GST_FLOW_OK;
3834 case GST_FLOW_CUSTOM_SUCCESS_1:
3835 /* event was ignored and should be sent later */
3836 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3837 GST_EVENT_TYPE_NAME (event));
3838 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3839 data->ret = GST_FLOW_OK;
3841 case GST_FLOW_NOT_LINKED:
3842 /* not linked is not a problem, we are sticky so the event will be
3843 * rescheduled to be sent later on re-link, but only for non-EOS events */
3844 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3845 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3846 data->ret = GST_FLOW_OK;
3847 ev->received = TRUE;
3851 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3852 gst_flow_get_name (data->ret));
3853 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3857 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3858 data->was_eos = TRUE;
3860 return data->ret == GST_FLOW_OK;
3863 /* check sticky events and push them when needed. should be called
3865 static inline GstFlowReturn
3866 check_sticky (GstPad * pad, GstEvent * event)
3868 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3870 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3871 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3873 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3874 events_foreach (pad, push_sticky, &data);
3876 /* If there's an EOS event we must push it downstream
3877 * even if sending a previous sticky event failed.
3878 * Otherwise the pipeline might wait forever for EOS.
3880 * Only do this if pushing another event than the EOS
3883 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3884 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3886 if (ev && !ev->received) {
3887 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3888 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3889 /* the event could have been dropped. Because this can only
3890 * happen if the user asked for it, it's not an error */
3891 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3892 data.ret = GST_FLOW_OK;
3902 * @pad: a #GstPad to invoke the default query on.
3903 * @query: (transfer none): the #GstQuery to perform.
3905 * Dispatches a query to a pad. The query should have been allocated by the
3906 * caller via one of the type-specific allocation functions. The element that
3907 * the pad belongs to is responsible for filling the query with an appropriate
3908 * response, which should then be parsed with a type-specific query parsing
3911 * Again, the caller is responsible for both the allocation and deallocation of
3912 * the query structure.
3914 * Please also note that some queries might need a running pipeline to work.
3916 * Returns: %TRUE if the query could be performed.
3919 gst_pad_query (GstPad * pad, GstQuery * query)
3922 gboolean res, serialized;
3923 GstPadQueryFunction func;
3924 GstPadProbeType type;
3927 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3928 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3930 if (GST_PAD_IS_SRC (pad)) {
3931 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3932 goto wrong_direction;
3933 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3934 } else if (GST_PAD_IS_SINK (pad)) {
3935 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3936 goto wrong_direction;
3937 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3939 goto unknown_direction;
3941 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3942 GST_QUERY_TYPE_NAME (query));
3943 GST_TRACER_PAD_QUERY_PRE (pad, query);
3945 serialized = GST_QUERY_IS_SERIALIZED (query);
3946 if (G_UNLIKELY (serialized))
3947 GST_PAD_STREAM_LOCK (pad);
3949 GST_OBJECT_LOCK (pad);
3950 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3951 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3952 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3954 ACQUIRE_PARENT (pad, parent, no_parent);
3955 GST_OBJECT_UNLOCK (pad);
3957 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3960 res = func (pad, parent, query);
3962 RELEASE_PARENT (parent);
3964 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3965 GST_QUERY_TYPE_NAME (query), res);
3966 GST_TRACER_PAD_QUERY_POST (pad, query, res);
3971 GST_OBJECT_LOCK (pad);
3972 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3973 GST_OBJECT_UNLOCK (pad);
3975 if (G_UNLIKELY (serialized))
3976 GST_PAD_STREAM_UNLOCK (pad);
3983 g_warning ("pad %s:%s query %s in wrong direction",
3984 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3989 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3994 GST_DEBUG_OBJECT (pad, "had no parent");
3995 GST_OBJECT_UNLOCK (pad);
3996 if (G_UNLIKELY (serialized))
3997 GST_PAD_STREAM_UNLOCK (pad);
4002 GST_DEBUG_OBJECT (pad, "had no query function");
4003 RELEASE_PARENT (parent);
4004 if (G_UNLIKELY (serialized))
4005 GST_PAD_STREAM_UNLOCK (pad);
4010 GST_DEBUG_OBJECT (pad, "query failed");
4011 if (G_UNLIKELY (serialized))
4012 GST_PAD_STREAM_UNLOCK (pad);
4017 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4018 GST_OBJECT_UNLOCK (pad);
4019 if (G_UNLIKELY (serialized))
4020 GST_PAD_STREAM_UNLOCK (pad);
4022 /* if a probe dropped without handling, we don't sent it further but assume
4023 * that the probe did not answer the query and return FALSE */
4024 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4034 * gst_pad_peer_query:
4035 * @pad: a #GstPad to invoke the peer query on.
4036 * @query: (transfer none): the #GstQuery to perform.
4038 * Performs gst_pad_query() on the peer of @pad.
4040 * The caller is responsible for both the allocation and deallocation of
4041 * the query structure.
4043 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4044 * if @pad has no peer.
4047 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4050 GstPadProbeType type;
4051 gboolean res, serialized;
4054 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4055 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4057 if (GST_PAD_IS_SRC (pad)) {
4058 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4059 goto wrong_direction;
4060 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4061 } else if (GST_PAD_IS_SINK (pad)) {
4062 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4063 goto wrong_direction;
4064 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4066 goto unknown_direction;
4068 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4069 GST_QUERY_TYPE_NAME (query));
4071 serialized = GST_QUERY_IS_SERIALIZED (query);
4073 GST_OBJECT_LOCK (pad);
4074 if (GST_PAD_IS_SRC (pad) && serialized) {
4075 /* all serialized queries on the srcpad trigger push of
4077 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4081 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4082 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4083 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4085 peerpad = GST_PAD_PEER (pad);
4086 if (G_UNLIKELY (peerpad == NULL))
4089 gst_object_ref (peerpad);
4090 GST_OBJECT_UNLOCK (pad);
4092 res = gst_pad_query (peerpad, query);
4094 gst_object_unref (peerpad);
4099 GST_OBJECT_LOCK (pad);
4100 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4101 GST_OBJECT_UNLOCK (pad);
4108 g_warning ("pad %s:%s query %s in wrong direction",
4109 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4114 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4119 GST_WARNING_OBJECT (pad, "could not send sticky events");
4120 GST_OBJECT_UNLOCK (pad);
4125 GST_INFO_OBJECT (pad, "pad has no peer");
4126 GST_OBJECT_UNLOCK (pad);
4131 GST_DEBUG_OBJECT (pad, "query failed");
4136 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4137 GST_OBJECT_UNLOCK (pad);
4139 /* if a probe dropped without handling, we don't sent it further but
4140 * assume that the probe did not answer the query and return FALSE */
4141 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4150 /**********************************************************************
4151 * Data passing functions
4154 /* this is the chain function that does not perform the additional argument
4155 * checking for that little extra speed.
4157 static inline GstFlowReturn
4158 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4162 gboolean handled = FALSE;
4164 GST_PAD_STREAM_LOCK (pad);
4166 GST_OBJECT_LOCK (pad);
4167 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4170 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4173 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4176 #ifdef GST_ENABLE_EXTRA_CHECKS
4177 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4178 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4180 ":%s:<%s:%s> Got data flow before stream-start event",
4181 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4183 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4185 ":%s:<%s:%s> Got data flow before segment event",
4186 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4188 pad->priv->last_cookie = pad->priv->events_cookie;
4192 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4195 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4197 ACQUIRE_PARENT (pad, parent, no_parent);
4198 GST_OBJECT_UNLOCK (pad);
4200 /* NOTE: we read the chainfunc unlocked.
4201 * we cannot hold the lock for the pad so we might send
4202 * the data to the wrong function. This is not really a
4203 * problem since functions are assigned at creation time
4204 * and don't change that often... */
4205 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4206 GstPadChainFunction chainfunc;
4208 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4211 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4212 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4213 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4215 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4217 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4218 "called chainfunction &%s with buffer %p, returned %s",
4219 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4221 GstPadChainListFunction chainlistfunc;
4223 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4226 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4227 "calling chainlistfunction &%s",
4228 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4230 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4232 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4233 "called chainlistfunction &%s, returned %s",
4234 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4237 RELEASE_PARENT (parent);
4239 GST_PAD_STREAM_UNLOCK (pad);
4246 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4247 "chaining, but pad was flushing");
4248 GST_OBJECT_UNLOCK (pad);
4249 GST_PAD_STREAM_UNLOCK (pad);
4250 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4251 return GST_FLOW_FLUSHING;
4255 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4256 GST_OBJECT_UNLOCK (pad);
4257 GST_PAD_STREAM_UNLOCK (pad);
4258 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4259 return GST_FLOW_EOS;
4263 g_critical ("chain on pad %s:%s but it was not in push mode",
4264 GST_DEBUG_PAD_NAME (pad));
4265 GST_OBJECT_UNLOCK (pad);
4266 GST_PAD_STREAM_UNLOCK (pad);
4267 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4268 return GST_FLOW_ERROR;
4275 GST_OBJECT_UNLOCK (pad);
4276 GST_PAD_STREAM_UNLOCK (pad);
4277 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4279 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4282 case GST_FLOW_CUSTOM_SUCCESS:
4283 case GST_FLOW_CUSTOM_SUCCESS_1:
4284 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4288 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4295 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4296 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4297 GST_OBJECT_UNLOCK (pad);
4298 GST_PAD_STREAM_UNLOCK (pad);
4299 return GST_FLOW_FLUSHING;
4303 RELEASE_PARENT (parent);
4304 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4305 g_critical ("chain on pad %s:%s but it has no chainfunction",
4306 GST_DEBUG_PAD_NAME (pad));
4307 GST_PAD_STREAM_UNLOCK (pad);
4308 return GST_FLOW_NOT_SUPPORTED;
4314 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4315 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4318 * Chain a buffer to @pad.
4320 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4322 * If the buffer type is not acceptable for @pad (as negotiated with a
4323 * preceding GST_EVENT_CAPS event), this function returns
4324 * #GST_FLOW_NOT_NEGOTIATED.
4326 * The function proceeds calling the chain function installed on @pad (see
4327 * gst_pad_set_chain_function()) and the return value of that function is
4328 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4331 * In all cases, success or failure, the caller loses its reference to @buffer
4332 * after calling this function.
4334 * Returns: a #GstFlowReturn from the pad.
4339 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4341 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4342 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4343 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4345 return gst_pad_chain_data_unchecked (pad,
4346 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4349 static GstFlowReturn
4350 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4351 GstBufferList * list)
4357 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4359 len = gst_buffer_list_length (list);
4362 for (i = 0; i < len; i++) {
4363 buffer = gst_buffer_list_get (list, i);
4365 gst_pad_chain_data_unchecked (pad,
4366 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4367 gst_buffer_ref (buffer));
4368 if (ret != GST_FLOW_OK)
4371 gst_buffer_list_unref (list);
4377 * gst_pad_chain_list:
4378 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4379 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4382 * Chain a bufferlist to @pad.
4384 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4386 * If @pad was not negotiated properly with a CAPS event, this function
4387 * returns #GST_FLOW_NOT_NEGOTIATED.
4389 * The function proceeds calling the chainlist function installed on @pad (see
4390 * gst_pad_set_chain_list_function()) and the return value of that function is
4391 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4392 * chainlist function.
4394 * In all cases, success or failure, the caller loses its reference to @list
4395 * after calling this function.
4399 * Returns: a #GstFlowReturn from the pad.
4402 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4404 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4405 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4406 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4408 return gst_pad_chain_data_unchecked (pad,
4409 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4412 static GstFlowReturn
4413 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4417 gboolean handled = FALSE;
4419 GST_OBJECT_LOCK (pad);
4420 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4423 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4426 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4429 #ifdef GST_ENABLE_EXTRA_CHECKS
4430 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4431 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4433 ":%s:<%s:%s> Got data flow before stream-start event",
4434 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4436 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4438 ":%s:<%s:%s> Got data flow before segment event",
4439 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4441 pad->priv->last_cookie = pad->priv->events_cookie;
4445 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4448 /* do block probes */
4449 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4452 /* recheck sticky events because the probe might have cause a relink */
4453 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4456 /* do post-blocking probes */
4457 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4459 /* recheck sticky events because the probe might have cause a relink */
4460 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4463 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4466 /* take ref to peer pad before releasing the lock */
4467 gst_object_ref (peer);
4469 GST_OBJECT_UNLOCK (pad);
4471 ret = gst_pad_chain_data_unchecked (peer, type, data);
4474 gst_object_unref (peer);
4476 GST_OBJECT_LOCK (pad);
4477 pad->ABI.abi.last_flowret = ret;
4479 if (pad->priv->using == 0) {
4480 /* pad is not active anymore, trigger idle callbacks */
4481 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4482 probe_stopped, ret);
4484 GST_OBJECT_UNLOCK (pad);
4488 /* ERROR recovery here */
4492 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4493 "pushing, but pad was flushing");
4494 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4495 GST_OBJECT_UNLOCK (pad);
4496 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4497 return GST_FLOW_FLUSHING;
4501 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4502 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4503 GST_OBJECT_UNLOCK (pad);
4504 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4505 return GST_FLOW_EOS;
4509 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4510 GST_DEBUG_PAD_NAME (pad));
4511 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4512 GST_OBJECT_UNLOCK (pad);
4513 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4514 return GST_FLOW_ERROR;
4518 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4519 "error pushing events, return %s", gst_flow_get_name (ret));
4520 pad->ABI.abi.last_flowret = ret;
4521 GST_OBJECT_UNLOCK (pad);
4522 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4530 GST_OBJECT_UNLOCK (pad);
4531 if (data != NULL && !handled)
4532 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4535 case GST_FLOW_CUSTOM_SUCCESS:
4536 case GST_FLOW_CUSTOM_SUCCESS_1:
4537 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4541 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4544 pad->ABI.abi.last_flowret = ret;
4549 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4550 "pushing, but it was not linked");
4551 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4552 GST_OBJECT_UNLOCK (pad);
4553 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4554 return GST_FLOW_NOT_LINKED;
4560 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4561 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4564 * Pushes a buffer to the peer of @pad.
4566 * This function will call installed block probes before triggering any
4567 * installed data probes.
4569 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4570 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4573 * In all cases, success or failure, the caller loses its reference to @buffer
4574 * after calling this function.
4576 * Returns: a #GstFlowReturn from the peer pad.
4581 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4585 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4586 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4587 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4589 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4590 res = gst_pad_push_data (pad,
4591 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4592 GST_TRACER_PAD_PUSH_POST (pad, res);
4597 * gst_pad_push_list:
4598 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4599 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4602 * Pushes a buffer list to the peer of @pad.
4604 * This function will call installed block probes before triggering any
4605 * installed data probes.
4607 * The function proceeds calling the chain function on the peer pad and returns
4608 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4609 * be returned. If the peer pad does not have any installed chainlist function
4610 * every group buffer of the list will be merged into a normal #GstBuffer and
4611 * chained via gst_pad_chain().
4613 * In all cases, success or failure, the caller loses its reference to @list
4614 * after calling this function.
4616 * Returns: a #GstFlowReturn from the peer pad.
4621 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4625 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4626 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4627 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4629 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4630 res = gst_pad_push_data (pad,
4631 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4632 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4636 static GstFlowReturn
4637 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4638 GstBuffer ** buffer)
4641 GstPadGetRangeFunction getrangefunc;
4645 GST_PAD_STREAM_LOCK (pad);
4647 GST_OBJECT_LOCK (pad);
4648 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4651 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4654 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4659 /* when one of the probes returns DROPPED, probe_stopped will be called
4660 * and we skip calling the getrange function, res_buf should then contain a
4661 * valid result buffer */
4662 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4663 res_buf, offset, size, probe_stopped);
4665 /* recheck sticky events because the probe might have cause a relink */
4666 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4669 ACQUIRE_PARENT (pad, parent, no_parent);
4670 GST_OBJECT_UNLOCK (pad);
4672 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4675 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4676 "calling getrangefunc %s, offset %"
4677 G_GUINT64_FORMAT ", size %u",
4678 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4680 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4682 RELEASE_PARENT (parent);
4684 GST_OBJECT_LOCK (pad);
4685 if (G_UNLIKELY (ret != GST_FLOW_OK))
4686 goto get_range_failed;
4688 /* can only fire the signal if we have a valid buffer */
4690 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4691 res_buf, offset, size, probe_stopped_unref);
4692 pad->ABI.abi.last_flowret = ret;
4693 GST_OBJECT_UNLOCK (pad);
4695 GST_PAD_STREAM_UNLOCK (pad);
4704 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4705 "getrange, but pad was flushing");
4706 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4707 GST_OBJECT_UNLOCK (pad);
4708 GST_PAD_STREAM_UNLOCK (pad);
4709 return GST_FLOW_FLUSHING;
4713 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4714 GST_DEBUG_PAD_NAME (pad));
4715 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4716 GST_OBJECT_UNLOCK (pad);
4717 GST_PAD_STREAM_UNLOCK (pad);
4718 return GST_FLOW_ERROR;
4722 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4723 pad->ABI.abi.last_flowret = ret;
4724 GST_OBJECT_UNLOCK (pad);
4725 GST_PAD_STREAM_UNLOCK (pad);
4730 GST_DEBUG_OBJECT (pad, "no parent");
4731 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4732 GST_OBJECT_UNLOCK (pad);
4733 GST_PAD_STREAM_UNLOCK (pad);
4734 return GST_FLOW_FLUSHING;
4738 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4739 GST_DEBUG_PAD_NAME (pad));
4740 RELEASE_PARENT (parent);
4741 GST_PAD_STREAM_UNLOCK (pad);
4742 return GST_FLOW_NOT_SUPPORTED;
4746 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4747 "probe returned %s", gst_flow_get_name (ret));
4748 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4750 /* the probe filled the buffer and asks us to not call the getrange
4751 * anymore, we continue with the post probes then. */
4752 GST_DEBUG_OBJECT (pad, "handled buffer");
4756 /* no buffer, we are EOS */
4757 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4761 pad->ABI.abi.last_flowret = ret;
4762 GST_OBJECT_UNLOCK (pad);
4763 GST_PAD_STREAM_UNLOCK (pad);
4767 probe_stopped_unref:
4769 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4770 "probe returned %s", gst_flow_get_name (ret));
4771 /* if we drop here, it signals EOS */
4772 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4774 pad->ABI.abi.last_flowret = ret;
4775 GST_OBJECT_UNLOCK (pad);
4776 GST_PAD_STREAM_UNLOCK (pad);
4777 if (*buffer == NULL)
4778 gst_buffer_unref (res_buf);
4783 pad->ABI.abi.last_flowret = ret;
4784 GST_OBJECT_UNLOCK (pad);
4785 GST_PAD_STREAM_UNLOCK (pad);
4786 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4787 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4788 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4794 * gst_pad_get_range:
4795 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4796 * @offset: The start offset of the buffer
4797 * @size: The length of the buffer
4798 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4799 * returns #GST_FLOW_ERROR if %NULL.
4801 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4802 * immediately and @buffer is %NULL.
4804 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4805 * description of a getrange function. If @pad has no getrange function
4806 * installed (see gst_pad_set_getrange_function()) this function returns
4807 * #GST_FLOW_NOT_SUPPORTED.
4809 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4810 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4811 * must be freed with gst_buffer_unref() after usage.
4813 * When @buffer points to a variable that points to a valid #GstBuffer, the
4814 * buffer will be filled with the result data when this function returns
4815 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4816 * @size bytes will be filled in the result buffer and its size will be updated
4819 * Note that less than @size bytes can be returned in @buffer when, for example,
4820 * an EOS condition is near or when @buffer is not large enough to hold @size
4821 * bytes. The caller should check the result buffer size to get the result size.
4823 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4824 * will be unchanged.
4826 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4828 * Returns: a #GstFlowReturn from the pad.
4833 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4834 GstBuffer ** buffer)
4836 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4837 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4838 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4839 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4840 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4842 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4846 * gst_pad_pull_range:
4847 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4848 * @offset: The start offset of the buffer
4849 * @size: The length of the buffer
4850 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4851 * GST_FLOW_ERROR if %NULL.
4853 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4855 * This function will first trigger the pad block signal if it was
4858 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4859 * function returns the result of gst_pad_get_range() on the peer pad.
4860 * See gst_pad_get_range() for a list of return values and for the
4861 * semantics of the arguments of this function.
4863 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4864 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4865 * must be freed with gst_buffer_unref() after usage. When this function
4866 * returns any other result value, @buffer will still point to %NULL.
4868 * When @buffer points to a variable that points to a valid #GstBuffer, the
4869 * buffer will be filled with the result data when this function returns
4870 * #GST_FLOW_OK. When this function returns any other result value,
4871 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4872 * @size bytes will be filled in the result buffer and its size will be updated
4875 * Note that less than @size bytes can be returned in @buffer when, for example,
4876 * an EOS condition is near or when @buffer is not large enough to hold @size
4877 * bytes. The caller should check the result buffer size to get the result size.
4879 * Returns: a #GstFlowReturn from the peer pad.
4884 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4885 GstBuffer ** buffer)
4891 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4892 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4893 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4894 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4895 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4897 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4899 GST_OBJECT_LOCK (pad);
4900 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4903 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4908 /* when one of the probes returns DROPPED, probe_stopped will be
4909 * called and we skip calling the peer getrange function. *buffer should then
4910 * contain a valid buffer */
4911 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4912 res_buf, offset, size, probe_stopped);
4914 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4917 gst_object_ref (peer);
4919 GST_OBJECT_UNLOCK (pad);
4921 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4923 gst_object_unref (peer);
4925 GST_OBJECT_LOCK (pad);
4927 pad->ABI.abi.last_flowret = ret;
4928 if (pad->priv->using == 0) {
4929 /* pad is not active anymore, trigger idle callbacks */
4930 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4931 probe_stopped_unref, ret);
4934 if (G_UNLIKELY (ret != GST_FLOW_OK))
4935 goto pull_range_failed;
4938 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4939 res_buf, offset, size, probe_stopped_unref);
4941 GST_OBJECT_UNLOCK (pad);
4945 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4948 /* ERROR recovery here */
4951 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4952 "pullrange, but pad was flushing");
4953 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4954 GST_OBJECT_UNLOCK (pad);
4955 ret = GST_FLOW_FLUSHING;
4960 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4961 GST_DEBUG_PAD_NAME (pad));
4962 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4963 GST_OBJECT_UNLOCK (pad);
4964 ret = GST_FLOW_ERROR;
4969 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4970 gst_flow_get_name (ret));
4971 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4973 /* the probe filled the buffer and asks us to not forward to the peer
4974 * anymore, we continue with the post probes then */
4975 GST_DEBUG_OBJECT (pad, "handled buffer");
4979 /* no buffer, we are EOS then */
4980 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4984 pad->ABI.abi.last_flowret = ret;
4985 GST_OBJECT_UNLOCK (pad);
4990 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4991 "pulling range, but it was not linked");
4992 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4993 GST_OBJECT_UNLOCK (pad);
4994 ret = GST_FLOW_NOT_LINKED;
4999 pad->ABI.abi.last_flowret = ret;
5000 GST_OBJECT_UNLOCK (pad);
5001 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5002 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5003 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5006 probe_stopped_unref:
5008 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5009 "post probe returned %s", gst_flow_get_name (ret));
5011 /* if we drop here, it signals EOS */
5012 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5015 pad->ABI.abi.last_flowret = ret;
5016 GST_OBJECT_UNLOCK (pad);
5018 if (*buffer == NULL)
5019 gst_buffer_unref (res_buf);
5023 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5027 /* must be called with pad object lock */
5028 static GstFlowReturn
5029 store_sticky_event (GstPad * pad, GstEvent * event)
5034 gboolean res = FALSE;
5035 const gchar *name = NULL;
5036 gboolean insert = TRUE;
5038 type = GST_EVENT_TYPE (event);
5040 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5041 * otherwise they can be dropped and nothing would ever resend them.
5042 * Only do that for activated pads though, everything else is a bug!
5044 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5045 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5046 || type == GST_EVENT_EOS))))
5049 /* Unset the EOS flag when received STREAM_START event, so pad can
5050 * store sticky event and then push it later */
5051 if (type == GST_EVENT_STREAM_START) {
5052 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5053 remove_event_by_type (pad, GST_EVENT_EOS);
5054 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5055 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5058 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5061 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5062 name = gst_structure_get_name (gst_event_get_structure (event));
5064 events = pad->priv->events;
5067 for (i = 0; i < len; i++) {
5068 PadEvent *ev = &g_array_index (events, PadEvent, i);
5070 if (ev->event == NULL)
5073 if (type == GST_EVENT_TYPE (ev->event)) {
5074 /* matching types, check matching name if needed */
5075 if (name && !gst_event_has_name (ev->event, name))
5079 if ((res = gst_event_replace (&ev->event, event)))
5080 ev->received = FALSE;
5086 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5087 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5088 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5089 * storing the sticky ordered we can check that this is respected. */
5090 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5091 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5093 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5094 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5095 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5096 gst_event_type_get_name (type));
5102 ev.event = gst_event_ref (event);
5103 ev.received = FALSE;
5104 g_array_insert_val (events, i, ev);
5109 pad->priv->events_cookie++;
5110 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5112 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5114 switch (GST_EVENT_TYPE (event)) {
5115 case GST_EVENT_CAPS:
5116 GST_OBJECT_UNLOCK (pad);
5118 GST_DEBUG_OBJECT (pad, "notify caps");
5119 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5121 GST_OBJECT_LOCK (pad);
5127 if (type == GST_EVENT_EOS) {
5128 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5129 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5132 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5137 GST_DEBUG_OBJECT (pad, "pad is flushing");
5138 return GST_FLOW_FLUSHING;
5142 GST_DEBUG_OBJECT (pad, "pad is EOS");
5143 return GST_FLOW_EOS;
5148 * gst_pad_store_sticky_event:
5150 * @event: (transfer none): a #GstEvent
5152 * Store the sticky @event on @pad
5154 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5155 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5160 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5164 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5165 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5167 GST_OBJECT_LOCK (pad);
5168 ret = store_sticky_event (pad, event);
5169 GST_OBJECT_UNLOCK (pad);
5175 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5177 PushStickyData *data = user_data;
5179 /* Forward all sticky events before our current one that are pending */
5180 if (ev->event != data->event
5181 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5182 return push_sticky (pad, ev, data);
5187 /* should be called with pad LOCK */
5188 static GstFlowReturn
5189 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5190 GstPadProbeType type)
5194 GstEventType event_type;
5196 /* pass the adjusted event on. We need to do this even if
5197 * there is no peer pad because of the probes. */
5198 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5200 /* Two checks to be made:
5201 * . (un)set the FLUSHING flag for flushing events,
5202 * . handle pad blocking */
5203 event_type = GST_EVENT_TYPE (event);
5204 switch (event_type) {
5205 case GST_EVENT_FLUSH_START:
5206 GST_PAD_SET_FLUSHING (pad);
5208 GST_PAD_BLOCK_BROADCAST (pad);
5209 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5211 case GST_EVENT_FLUSH_STOP:
5212 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5215 GST_PAD_UNSET_FLUSHING (pad);
5217 /* Remove sticky EOS events */
5218 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5219 remove_event_by_type (pad, GST_EVENT_EOS);
5220 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5221 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5222 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5223 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5225 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5229 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5232 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5233 * checked already or this is called as part of pushing sticky events,
5234 * in which case we still want to forward the EOS event downstream.
5237 switch (GST_EVENT_TYPE (event)) {
5238 case GST_EVENT_RECONFIGURE:
5239 if (GST_PAD_IS_SINK (pad))
5240 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5245 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5246 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5247 /* recheck sticky events because the probe might have cause a relink */
5248 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5249 && (GST_EVENT_IS_SERIALIZED (event)
5250 || GST_EVENT_IS_STICKY (event))) {
5251 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5252 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5254 /* Push all sticky events before our current one
5255 * that have changed */
5256 events_foreach (pad, sticky_changed, &data);
5262 /* send probes after modifying the events above */
5263 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5265 /* recheck sticky events because the probe might have cause a relink */
5266 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5267 && (GST_EVENT_IS_SERIALIZED (event)
5268 || GST_EVENT_IS_STICKY (event))) {
5269 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5270 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5272 /* Push all sticky events before our current one
5273 * that have changed */
5274 events_foreach (pad, sticky_changed, &data);
5277 /* now check the peer pad */
5278 peerpad = GST_PAD_PEER (pad);
5279 if (peerpad == NULL)
5282 gst_object_ref (peerpad);
5284 GST_OBJECT_UNLOCK (pad);
5286 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5287 event, gst_event_type_get_name (event_type), peerpad);
5289 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5291 /* Note: we gave away ownership of the event at this point but we can still
5292 * print the old pointer */
5293 GST_LOG_OBJECT (pad,
5294 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5295 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5297 gst_object_unref (peerpad);
5299 GST_OBJECT_LOCK (pad);
5301 if (pad->priv->using == 0) {
5302 /* pad is not active anymore, trigger idle callbacks */
5303 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5304 idle_probe_stopped, ret);
5308 /* ERROR handling */
5311 GST_DEBUG_OBJECT (pad, "We're flushing");
5312 gst_event_unref (event);
5313 return GST_FLOW_FLUSHING;
5317 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5318 gst_event_unref (event);
5319 return GST_FLOW_FLUSHING;
5323 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5324 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5325 gst_event_unref (event);
5328 case GST_FLOW_CUSTOM_SUCCESS_1:
5329 GST_DEBUG_OBJECT (pad, "handled event");
5331 case GST_FLOW_CUSTOM_SUCCESS:
5332 GST_DEBUG_OBJECT (pad, "dropped event");
5335 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5342 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5343 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5344 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5345 gst_event_unref (event);
5347 /* unlinked pads should not influence latency configuration */
5348 if (event_type == GST_EVENT_LATENCY)
5351 return GST_FLOW_NOT_LINKED;
5355 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5361 * gst_pad_push_event:
5362 * @pad: a #GstPad to push the event to.
5363 * @event: (transfer full): the #GstEvent to send to the pad.
5365 * Sends the event to the peer of the given pad. This function is
5366 * mainly used by elements to send events to their peer
5369 * This function takes ownership of the provided event so you should
5370 * gst_event_ref() it if you want to reuse the event after this call.
5372 * Returns: %TRUE if the event was handled.
5377 gst_pad_push_event (GstPad * pad, GstEvent * event)
5379 gboolean res = FALSE;
5380 GstPadProbeType type;
5381 gboolean sticky, serialized;
5383 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5384 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5386 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5388 if (GST_PAD_IS_SRC (pad)) {
5389 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5390 goto wrong_direction;
5391 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5392 } else if (GST_PAD_IS_SINK (pad)) {
5393 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5394 goto wrong_direction;
5395 /* events pushed on sinkpad never are sticky */
5396 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5398 goto unknown_direction;
5400 GST_OBJECT_LOCK (pad);
5401 sticky = GST_EVENT_IS_STICKY (event);
5402 serialized = GST_EVENT_IS_SERIALIZED (event);
5405 /* srcpad sticky events are stored immediately, the received flag is set
5406 * to FALSE and will be set to TRUE when we can successfully push the
5407 * event to the peer pad */
5408 switch (store_sticky_event (pad, event)) {
5409 case GST_FLOW_FLUSHING:
5417 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5418 /* all serialized or sticky events on the srcpad trigger push of
5420 res = (check_sticky (pad, event) == GST_FLOW_OK);
5425 /* other events are pushed right away */
5426 ret = gst_pad_push_event_unchecked (pad, event, type);
5427 /* dropped events by a probe are not an error */
5428 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5429 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5431 /* Errors in sticky event pushing are no problem and ignored here
5432 * as they will cause more meaningful errors during data flow.
5433 * For EOS events, that are not followed by data flow, we still
5434 * return FALSE here though.
5436 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5438 gst_event_unref (event);
5440 GST_OBJECT_UNLOCK (pad);
5442 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5445 /* ERROR handling */
5448 g_warning ("pad %s:%s pushing %s event in wrong direction",
5449 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5450 gst_event_unref (event);
5455 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5456 gst_event_unref (event);
5461 GST_DEBUG_OBJECT (pad, "We're flushing");
5462 GST_OBJECT_UNLOCK (pad);
5463 gst_event_unref (event);
5468 GST_DEBUG_OBJECT (pad, "We're EOS");
5469 GST_OBJECT_UNLOCK (pad);
5470 gst_event_unref (event);
5474 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5478 /* Check if we can call the event function with the given event */
5479 static GstFlowReturn
5480 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5484 switch (GST_EVENT_TYPE (event)) {
5485 case GST_EVENT_CAPS:
5487 /* backwards compatibility mode for caps */
5488 gst_event_parse_caps (event, &caps);
5490 if (!gst_pad_query_accept_caps (pad, caps))
5502 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5503 "caps %" GST_PTR_FORMAT " not accepted", caps);
5504 return GST_FLOW_NOT_NEGOTIATED;
5508 static GstFlowReturn
5509 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5510 GstPadProbeType type)
5513 GstEventType event_type;
5514 gboolean serialized, need_unlock = FALSE, sticky;
5515 GstPadEventFunction eventfunc;
5516 GstPadEventFullFunction eventfullfunc = NULL;
5519 GST_OBJECT_LOCK (pad);
5521 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5523 if (GST_PAD_IS_SINK (pad))
5524 serialized = GST_EVENT_IS_SERIALIZED (event);
5527 sticky = GST_EVENT_IS_STICKY (event);
5528 event_type = GST_EVENT_TYPE (event);
5529 switch (event_type) {
5530 case GST_EVENT_FLUSH_START:
5531 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5532 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5534 /* can't even accept a flush begin event when flushing */
5535 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5538 GST_PAD_SET_FLUSHING (pad);
5539 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5540 GST_PAD_BLOCK_BROADCAST (pad);
5541 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5543 case GST_EVENT_FLUSH_STOP:
5544 /* we can't accept flush-stop on inactive pads else the flushing flag
5545 * would be cleared and it would look like the pad can accept data.
5546 * Also, some elements restart a streaming thread in flush-stop which we
5547 * can't allow on inactive pads */
5548 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5551 GST_PAD_UNSET_FLUSHING (pad);
5552 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5553 /* Remove pending EOS events */
5554 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5555 remove_event_by_type (pad, GST_EVENT_EOS);
5556 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5557 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5558 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5559 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5561 GST_OBJECT_UNLOCK (pad);
5562 /* grab stream lock */
5563 GST_PAD_STREAM_LOCK (pad);
5565 GST_OBJECT_LOCK (pad);
5566 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5569 case GST_EVENT_RECONFIGURE:
5570 if (GST_PAD_IS_SRC (pad))
5571 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5573 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5574 "have event type %" GST_PTR_FORMAT, event);
5576 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5579 switch (event_type) {
5580 case GST_EVENT_STREAM_START:
5581 /* Remove sticky EOS events */
5582 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5583 remove_event_by_type (pad, GST_EVENT_EOS);
5584 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5585 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5592 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5595 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5596 GST_OBJECT_UNLOCK (pad);
5597 GST_PAD_STREAM_LOCK (pad);
5599 GST_OBJECT_LOCK (pad);
5600 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5603 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5609 /* now do the probe */
5611 type | GST_PAD_PROBE_TYPE_PUSH |
5612 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5614 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5616 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5617 eventfunc = GST_PAD_EVENTFUNC (pad);
5618 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5621 ACQUIRE_PARENT (pad, parent, no_parent);
5622 GST_OBJECT_UNLOCK (pad);
5624 ret = pre_eventfunc_check (pad, event);
5625 if (G_UNLIKELY (ret != GST_FLOW_OK))
5626 goto precheck_failed;
5629 gst_event_ref (event);
5631 if (eventfullfunc) {
5632 ret = eventfullfunc (pad, parent, event);
5633 } else if (eventfunc (pad, parent, event)) {
5636 /* something went wrong */
5637 switch (event_type) {
5638 case GST_EVENT_CAPS:
5639 ret = GST_FLOW_NOT_NEGOTIATED;
5642 ret = GST_FLOW_ERROR;
5646 RELEASE_PARENT (parent);
5648 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5651 if (ret == GST_FLOW_OK) {
5652 GST_OBJECT_LOCK (pad);
5653 /* after the event function accepted the event, we can store the sticky
5654 * event on the pad */
5655 switch (store_sticky_event (pad, event)) {
5656 case GST_FLOW_FLUSHING:
5663 GST_OBJECT_UNLOCK (pad);
5665 gst_event_unref (event);
5669 GST_PAD_STREAM_UNLOCK (pad);
5673 /* ERROR handling */
5676 GST_OBJECT_UNLOCK (pad);
5678 GST_PAD_STREAM_UNLOCK (pad);
5679 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5680 "Received event on flushing pad. Discarding");
5681 gst_event_unref (event);
5682 return GST_FLOW_FLUSHING;
5686 GST_OBJECT_UNLOCK (pad);
5688 GST_PAD_STREAM_UNLOCK (pad);
5689 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5690 "Received flush-stop on inactive pad. Discarding");
5691 gst_event_unref (event);
5692 return GST_FLOW_FLUSHING;
5696 GST_OBJECT_UNLOCK (pad);
5698 GST_PAD_STREAM_UNLOCK (pad);
5699 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5700 "Received event on EOS pad. Discarding");
5701 gst_event_unref (event);
5702 return GST_FLOW_EOS;
5706 GST_OBJECT_UNLOCK (pad);
5708 GST_PAD_STREAM_UNLOCK (pad);
5709 /* Only unref if unhandled */
5710 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5711 gst_event_unref (event);
5714 case GST_FLOW_CUSTOM_SUCCESS_1:
5715 case GST_FLOW_CUSTOM_SUCCESS:
5716 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5720 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5727 g_warning ("pad %s:%s has no event handler, file a bug.",
5728 GST_DEBUG_PAD_NAME (pad));
5729 GST_OBJECT_UNLOCK (pad);
5731 GST_PAD_STREAM_UNLOCK (pad);
5732 gst_event_unref (event);
5733 return GST_FLOW_NOT_SUPPORTED;
5737 GST_DEBUG_OBJECT (pad, "no parent");
5738 GST_OBJECT_UNLOCK (pad);
5740 GST_PAD_STREAM_UNLOCK (pad);
5741 gst_event_unref (event);
5742 return GST_FLOW_FLUSHING;
5746 GST_DEBUG_OBJECT (pad, "pre event check failed");
5747 RELEASE_PARENT (parent);
5749 GST_PAD_STREAM_UNLOCK (pad);
5750 gst_event_unref (event);
5756 * gst_pad_send_event:
5757 * @pad: a #GstPad to send the event to.
5758 * @event: (transfer full): the #GstEvent to send to the pad.
5760 * Sends the event to the pad. This function can be used
5761 * by applications to send events in the pipeline.
5763 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5764 * sink pad, @event should be a downstream event. For example, you would not
5765 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5766 * Furthermore, some downstream events have to be serialized with data flow,
5767 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5768 * the event needs to be serialized with data flow, this function will take the
5769 * pad's stream lock while calling its event function.
5771 * To find out whether an event type is upstream, downstream, or downstream and
5772 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5773 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5774 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5775 * plugin doesn't need to bother itself with this information; the core handles
5776 * all necessary locks and checks.
5778 * This function takes ownership of the provided event so you should
5779 * gst_event_ref() it if you want to reuse the event after this call.
5781 * Returns: %TRUE if the event was handled.
5784 gst_pad_send_event (GstPad * pad, GstEvent * event)
5787 GstPadProbeType type;
5789 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5790 g_return_val_if_fail (event != NULL, FALSE);
5792 if (GST_PAD_IS_SINK (pad)) {
5793 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5794 goto wrong_direction;
5795 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5796 } else if (GST_PAD_IS_SRC (pad)) {
5797 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5798 goto wrong_direction;
5799 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5801 goto unknown_direction;
5803 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5810 /* ERROR handling */
5813 g_warning ("pad %s:%s sending %s event in wrong direction",
5814 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5815 gst_event_unref (event);
5820 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5821 gst_event_unref (event);
5827 * gst_pad_set_element_private:
5828 * @pad: the #GstPad to set the private data of.
5829 * @priv: The private data to attach to the pad.
5831 * Set the given private data gpointer on the pad.
5832 * This function can only be used by the element that owns the pad.
5833 * No locking is performed in this function.
5836 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5838 pad->element_private = priv;
5842 * gst_pad_get_element_private:
5843 * @pad: the #GstPad to get the private data of.
5845 * Gets the private data of a pad.
5846 * No locking is performed in this function.
5848 * Returns: (transfer none): a #gpointer to the private data.
5851 gst_pad_get_element_private (GstPad * pad)
5853 return pad->element_private;
5857 * gst_pad_get_sticky_event:
5858 * @pad: the #GstPad to get the event from.
5859 * @event_type: the #GstEventType that should be retrieved.
5860 * @idx: the index of the event
5862 * Returns a new reference of the sticky event of type @event_type
5865 * Returns: (transfer full) (nullable): a #GstEvent of type
5866 * @event_type or %NULL when no event of @event_type was on
5867 * @pad. Unref after usage.
5870 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5872 GstEvent *event = NULL;
5875 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5876 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5878 GST_OBJECT_LOCK (pad);
5879 ev = find_event_by_type (pad, event_type, idx);
5880 if (ev && (event = ev->event))
5881 gst_event_ref (event);
5882 GST_OBJECT_UNLOCK (pad);
5889 GstPadStickyEventsForeachFunction func;
5894 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5896 ForeachDispatch *data = user_data;
5897 gboolean ret = TRUE;
5900 GST_OBJECT_UNLOCK (pad);
5902 ret = data->func (pad, &ev->event, data->user_data);
5904 GST_OBJECT_LOCK (pad);
5911 * gst_pad_sticky_events_foreach:
5912 * @pad: the #GstPad that should be used for iteration.
5913 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5914 * should be called for every event.
5915 * @user_data: (closure): the optional user data.
5917 * Iterates all sticky events on @pad and calls @foreach_func for every
5918 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5921 gst_pad_sticky_events_foreach (GstPad * pad,
5922 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5924 ForeachDispatch data;
5926 g_return_if_fail (GST_IS_PAD (pad));
5927 g_return_if_fail (foreach_func != NULL);
5929 data.func = foreach_func;
5930 data.user_data = user_data;
5932 GST_OBJECT_LOCK (pad);
5933 events_foreach (pad, foreach_dispatch_function, &data);
5934 GST_OBJECT_UNLOCK (pad);
5938 do_stream_status (GstPad * pad, GstStreamStatusType type,
5939 GThread * thread, GstTask * task)
5943 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5945 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5946 if (GST_IS_ELEMENT (parent)) {
5947 GstMessage *message;
5948 GValue value = { 0 };
5950 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5951 gchar *tname, *ename, *pname;
5953 /* create a good task name */
5954 ename = gst_element_get_name (parent);
5955 pname = gst_pad_get_name (pad);
5956 tname = g_strdup_printf ("%s:%s", ename, pname);
5960 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5964 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5967 g_value_init (&value, GST_TYPE_TASK);
5968 g_value_set_object (&value, task);
5969 gst_message_set_stream_status_object (message, &value);
5970 g_value_unset (&value);
5972 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5973 gst_element_post_message (parent, message);
5975 gst_object_unref (parent);
5980 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5982 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5987 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5989 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5994 * gst_pad_start_task:
5995 * @pad: the #GstPad to start the task of
5996 * @func: the task function to call
5997 * @user_data: user data passed to the task function
5998 * @notify: called when @user_data is no longer referenced
6000 * Starts a task that repeatedly calls @func with @user_data. This function
6001 * is mostly used in pad activation functions to start the dataflow.
6002 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6003 * before @func is called.
6005 * Returns: a %TRUE if the task could be started.
6008 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6009 GDestroyNotify notify)
6014 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6015 g_return_val_if_fail (func != NULL, FALSE);
6017 GST_DEBUG_OBJECT (pad, "start task");
6019 GST_OBJECT_LOCK (pad);
6020 task = GST_PAD_TASK (pad);
6022 task = gst_task_new (func, user_data, notify);
6023 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6024 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6025 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6026 GST_INFO_OBJECT (pad, "created task %p", task);
6027 GST_PAD_TASK (pad) = task;
6028 gst_object_ref (task);
6029 /* release lock to post the message */
6030 GST_OBJECT_UNLOCK (pad);
6032 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6034 gst_object_unref (task);
6036 GST_OBJECT_LOCK (pad);
6037 /* nobody else is supposed to have changed the pad now */
6038 if (GST_PAD_TASK (pad) != task)
6039 goto concurrent_stop;
6041 res = gst_task_set_state (task, GST_TASK_STARTED);
6042 GST_OBJECT_UNLOCK (pad);
6049 GST_OBJECT_UNLOCK (pad);
6055 * gst_pad_pause_task:
6056 * @pad: the #GstPad to pause the task of
6058 * Pause the task of @pad. This function will also wait until the
6059 * function executed by the task is finished if this function is not
6060 * called from the task function.
6062 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6066 gst_pad_pause_task (GstPad * pad)
6071 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6073 GST_DEBUG_OBJECT (pad, "pause task");
6075 GST_OBJECT_LOCK (pad);
6076 task = GST_PAD_TASK (pad);
6079 res = gst_task_set_state (task, GST_TASK_PAUSED);
6080 GST_OBJECT_UNLOCK (pad);
6082 /* wait for task function to finish, this lock is recursive so it does nothing
6083 * when the pause is called from the task itself */
6084 GST_PAD_STREAM_LOCK (pad);
6085 GST_PAD_STREAM_UNLOCK (pad);
6091 GST_DEBUG_OBJECT (pad, "pad has no task");
6092 GST_OBJECT_UNLOCK (pad);
6098 * gst_pad_get_task_state:
6099 * @pad: the #GstPad to get task state from
6101 * Get @pad task state. If no task is currently
6102 * set, #GST_TASK_STOPPED is returned.
6104 * Returns: The current state of @pad's task.
6109 gst_pad_get_task_state (GstPad * pad)
6114 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6116 GST_OBJECT_LOCK (pad);
6117 task = GST_PAD_TASK (pad);
6120 res = gst_task_get_state (task);
6121 GST_OBJECT_UNLOCK (pad);
6127 GST_DEBUG_OBJECT (pad, "pad has no task");
6128 GST_OBJECT_UNLOCK (pad);
6129 return GST_TASK_STOPPED;
6134 * gst_pad_stop_task:
6135 * @pad: the #GstPad to stop the task of
6137 * Stop the task of @pad. This function will also make sure that the
6138 * function executed by the task will effectively stop if not called
6139 * from the GstTaskFunction.
6141 * This function will deadlock if called from the GstTaskFunction of
6142 * the task. Use gst_task_pause() instead.
6144 * Regardless of whether the pad has a task, the stream lock is acquired and
6145 * released so as to ensure that streaming through this pad has finished.
6147 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6150 gst_pad_stop_task (GstPad * pad)
6155 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6157 GST_DEBUG_OBJECT (pad, "stop task");
6159 GST_OBJECT_LOCK (pad);
6160 task = GST_PAD_TASK (pad);
6163 GST_PAD_TASK (pad) = NULL;
6164 res = gst_task_set_state (task, GST_TASK_STOPPED);
6165 GST_OBJECT_UNLOCK (pad);
6167 GST_PAD_STREAM_LOCK (pad);
6168 GST_PAD_STREAM_UNLOCK (pad);
6170 if (!gst_task_join (task))
6173 gst_object_unref (task);
6179 GST_DEBUG_OBJECT (pad, "no task");
6180 GST_OBJECT_UNLOCK (pad);
6182 GST_PAD_STREAM_LOCK (pad);
6183 GST_PAD_STREAM_UNLOCK (pad);
6185 /* this is not an error */
6190 /* this is bad, possibly the application tried to join the task from
6191 * the task's thread. We install the task again so that it will be stopped
6192 * again from the right thread next time hopefully. */
6193 GST_OBJECT_LOCK (pad);
6194 GST_DEBUG_OBJECT (pad, "join failed");
6195 /* we can only install this task if there was no other task */
6196 if (GST_PAD_TASK (pad) == NULL)
6197 GST_PAD_TASK (pad) = task;
6198 GST_OBJECT_UNLOCK (pad);
6205 * gst_pad_probe_info_get_event:
6206 * @info: a #GstPadProbeInfo
6208 * Returns: (transfer none): The #GstEvent from the probe
6212 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6214 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6215 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6217 return GST_PAD_PROBE_INFO_EVENT (info);
6222 * gst_pad_probe_info_get_query:
6223 * @info: a #GstPadProbeInfo
6225 * Returns: (transfer none): The #GstQuery from the probe
6229 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6231 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6232 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6234 return GST_PAD_PROBE_INFO_QUERY (info);
6238 * gst_pad_probe_info_get_buffer:
6239 * @info: a #GstPadProbeInfo
6241 * Returns: (transfer none): The #GstBuffer from the probe
6245 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6247 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6249 return GST_PAD_PROBE_INFO_BUFFER (info);
6253 * gst_pad_probe_info_get_buffer_list:
6254 * @info: a #GstPadProbeInfo
6256 * Returns: (transfer none): The #GstBufferList from the probe
6260 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6262 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6264 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6268 * gst_pad_get_last_flow_return:
6271 * Gets the #GstFlowReturn return from the last data passed by this pad.
6276 gst_pad_get_last_flow_return (GstPad * pad)
6280 GST_OBJECT_LOCK (pad);
6281 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6282 GST_OBJECT_UNLOCK (pad);