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:
962 /* Returns TRUE if pad wasn't already in the new_mode */
964 pre_activate (GstPad * pad, GstPadMode new_mode)
967 case GST_PAD_MODE_NONE:
968 GST_OBJECT_LOCK (pad);
969 if (new_mode == GST_PAD_MODE (pad)) {
970 GST_WARNING_OBJECT (pad,
971 "Pad is already in the process of being deactivated");
972 GST_OBJECT_UNLOCK (pad);
975 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
976 GST_PAD_SET_FLUSHING (pad);
977 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
978 GST_PAD_MODE (pad) = new_mode;
979 /* unlock blocked pads so element can resume and stop */
980 GST_PAD_BLOCK_BROADCAST (pad);
981 GST_OBJECT_UNLOCK (pad);
983 case GST_PAD_MODE_PUSH:
984 case GST_PAD_MODE_PULL:
985 GST_OBJECT_LOCK (pad);
986 if (new_mode == GST_PAD_MODE (pad)) {
987 GST_WARNING_OBJECT (pad,
988 "Pad is already in the process of being activated");
989 GST_OBJECT_UNLOCK (pad);
992 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
993 gst_pad_mode_get_name (new_mode));
994 GST_PAD_UNSET_FLUSHING (pad);
995 pad->ABI.abi.last_flowret = GST_FLOW_OK;
996 GST_PAD_MODE (pad) = new_mode;
997 if (GST_PAD_IS_SINK (pad)) {
999 /* make sure the peer src pad sends us all events */
1000 if ((peer = GST_PAD_PEER (pad))) {
1001 gst_object_ref (peer);
1002 GST_OBJECT_UNLOCK (pad);
1004 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
1005 GST_DEBUG_PAD_NAME (peer));
1007 GST_OBJECT_LOCK (peer);
1008 schedule_events (peer, NULL);
1009 GST_OBJECT_UNLOCK (peer);
1011 gst_object_unref (peer);
1013 GST_OBJECT_UNLOCK (pad);
1016 GST_OBJECT_UNLOCK (pad);
1024 post_activate (GstPad * pad, GstPadMode new_mode)
1027 case GST_PAD_MODE_NONE:
1028 /* ensures that streaming stops */
1029 GST_PAD_STREAM_LOCK (pad);
1030 GST_DEBUG_OBJECT (pad, "stopped streaming");
1031 GST_OBJECT_LOCK (pad);
1032 remove_events (pad);
1033 GST_OBJECT_UNLOCK (pad);
1034 GST_PAD_STREAM_UNLOCK (pad);
1036 case GST_PAD_MODE_PUSH:
1037 case GST_PAD_MODE_PULL:
1044 * gst_pad_set_active:
1045 * @pad: the #GstPad to activate or deactivate.
1046 * @active: whether or not the pad should be active.
1048 * Activates or deactivates the given pad.
1049 * Normally called from within core state change functions.
1051 * If @active, makes sure the pad is active. If it is already active, either in
1052 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1053 * function to perform the actual activation.
1055 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1056 * and a %FALSE argument.
1058 * Returns: %TRUE if the operation was successful.
1063 gst_pad_set_active (GstPad * pad, gboolean active)
1067 gboolean ret = FALSE;
1069 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1071 GST_OBJECT_LOCK (pad);
1072 old = GST_PAD_MODE (pad);
1073 ACQUIRE_PARENT (pad, parent, no_parent);
1074 GST_OBJECT_UNLOCK (pad);
1077 if (old == GST_PAD_MODE_NONE) {
1078 GST_DEBUG_OBJECT (pad, "activating pad from none");
1079 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1081 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1083 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1084 gst_pad_mode_get_name (old));
1088 if (old == GST_PAD_MODE_NONE) {
1089 GST_DEBUG_OBJECT (pad, "pad was inactive");
1092 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1093 gst_pad_mode_get_name (old));
1094 ret = activate_mode_internal (pad, parent, old, FALSE);
1096 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1100 RELEASE_PARENT (parent);
1102 if (G_UNLIKELY (!ret))
1110 GST_DEBUG_OBJECT (pad, "no parent");
1111 GST_OBJECT_UNLOCK (pad);
1116 GST_OBJECT_LOCK (pad);
1118 g_critical ("Failed to deactivate pad %s:%s, very bad",
1119 GST_DEBUG_PAD_NAME (pad));
1121 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1123 GST_OBJECT_UNLOCK (pad);
1129 activate_mode_internal (GstPad * pad, GstObject * parent, GstPadMode mode,
1132 gboolean res = FALSE;
1133 GstPadMode old, new;
1134 GstPadDirection dir;
1137 GST_OBJECT_LOCK (pad);
1138 old = GST_PAD_MODE (pad);
1139 dir = GST_PAD_DIRECTION (pad);
1140 GST_OBJECT_UNLOCK (pad);
1142 new = active ? mode : GST_PAD_MODE_NONE;
1147 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1148 /* pad was activate in the wrong direction, deactivate it
1149 * and reactivate it in the requested mode */
1150 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1151 gst_pad_mode_get_name (old));
1153 if (G_UNLIKELY (!activate_mode_internal (pad, parent, old, FALSE)))
1154 goto deactivate_failed;
1155 old = GST_PAD_MODE_NONE;
1159 case GST_PAD_MODE_PULL:
1161 if (dir == GST_PAD_SINK) {
1162 if ((peer = gst_pad_get_peer (pad))) {
1163 GST_DEBUG_OBJECT (pad, "calling peer");
1164 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1166 gst_object_unref (peer);
1168 /* there is no peer, this is only fatal when we activate. When we
1169 * deactivate, we must assume the application has unlinked the peer and
1170 * will deactivate it eventually. */
1174 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1177 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1178 goto failure; /* Can't activate pull on a src without a
1179 getrange function */
1187 /* Mark pad as needing reconfiguration */
1189 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1191 /* pre_activate returns TRUE if we weren't already in the process of
1192 * switching to the 'new' mode */
1193 if (pre_activate (pad, new)) {
1195 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1196 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1200 /* can happen for sinks of passthrough elements */
1203 post_activate (pad, new);
1206 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1207 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1212 /* Clear sticky flags on deactivation */
1214 GST_OBJECT_LOCK (pad);
1215 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1216 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1217 GST_OBJECT_UNLOCK (pad);
1225 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1226 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1231 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1232 "failed to %s in switch to %s mode from %s mode",
1233 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1234 gst_pad_mode_get_name (old));
1239 GST_OBJECT_LOCK (peer);
1240 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1241 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1242 GST_OBJECT_UNLOCK (peer);
1243 gst_object_unref (peer);
1248 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1249 "pad in pull mode");
1254 GST_OBJECT_LOCK (pad);
1255 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1256 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1257 GST_PAD_SET_FLUSHING (pad);
1258 GST_PAD_MODE (pad) = old;
1259 GST_OBJECT_UNLOCK (pad);
1265 * gst_pad_activate_mode:
1266 * @pad: the #GstPad to activate or deactivate.
1267 * @mode: the requested activation mode
1268 * @active: whether or not the pad should be active.
1270 * Activates or deactivates the given pad in @mode via dispatching to the
1271 * pad's activatemodefunc. For use from within pad activation functions only.
1273 * If you don't know what this is, you probably don't want to call it.
1275 * Returns: %TRUE if the operation was successful.
1280 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1285 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1287 GST_OBJECT_LOCK (pad);
1288 ACQUIRE_PARENT (pad, parent, no_parent);
1289 GST_OBJECT_UNLOCK (pad);
1291 res = activate_mode_internal (pad, parent, mode, active);
1293 RELEASE_PARENT (parent);
1299 GST_WARNING_OBJECT (pad, "no parent");
1300 GST_OBJECT_UNLOCK (pad);
1306 * gst_pad_is_active:
1307 * @pad: the #GstPad to query
1309 * Query if a pad is active
1311 * Returns: %TRUE if the pad is active.
1316 gst_pad_is_active (GstPad * pad)
1318 gboolean result = FALSE;
1320 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1322 GST_OBJECT_LOCK (pad);
1323 result = GST_PAD_IS_ACTIVE (pad);
1324 GST_OBJECT_UNLOCK (pad);
1330 cleanup_hook (GstPad * pad, GHook * hook)
1332 GstPadProbeType type;
1334 if (!G_HOOK_IS_VALID (hook))
1337 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1339 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1340 /* unblock when we remove the last blocking probe */
1342 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1345 /* Might have new probes now that want to be called */
1346 GST_PAD_BLOCK_BROADCAST (pad);
1348 if (pad->num_blocked == 0) {
1349 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1350 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1353 g_hook_destroy_link (&pad->probes, hook);
1358 * gst_pad_add_probe:
1359 * @pad: the #GstPad to add the probe to
1360 * @mask: the probe mask
1361 * @callback: #GstPadProbeCallback that will be called with notifications of
1363 * @user_data: (closure): user data passed to the callback
1364 * @destroy_data: #GDestroyNotify for user_data
1366 * Be notified of different states of pads. The provided callback is called for
1367 * every state that matches @mask.
1369 * Probes are called in groups: First GST_PAD_PROBE_TYPE_BLOCK probes are
1370 * called, then others, then finally GST_PAD_PROBE_TYPE_IDLE. The only
1371 * exception here are GST_PAD_PROBE_TYPE_IDLE probes that are called
1372 * immediately if the pad is already idle while calling gst_pad_add_probe().
1373 * In each of the groups, probes are called in the order in which they were
1376 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1377 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1378 * happen that the probe can be run immediately and if the probe returns
1379 * GST_PAD_PROBE_REMOVE this functions returns 0.
1384 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1385 GstPadProbeCallback callback, gpointer user_data,
1386 GDestroyNotify destroy_data)
1391 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1392 g_return_val_if_fail (mask != 0, 0);
1394 GST_OBJECT_LOCK (pad);
1396 /* make a new probe */
1397 hook = g_hook_alloc (&pad->probes);
1399 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1402 /* when no contraints are given for the types, assume all types are
1404 if ((mask & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH) == 0)
1405 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1406 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1407 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1409 /* store our flags and other fields */
1410 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1411 hook->func = callback;
1412 hook->data = user_data;
1413 hook->destroy = destroy_data;
1414 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1417 g_hook_append (&pad->probes, hook);
1419 /* incremenent cookie so that the new hook get's called */
1420 pad->priv->probe_list_cookie++;
1422 /* get the id of the hook, we return this and it can be used to remove the
1424 res = hook->hook_id;
1426 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1428 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1429 /* we have a block probe */
1431 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1432 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1433 "now %d blocking probes", pad->num_blocked);
1435 /* Might have new probes now that want to be called */
1436 GST_PAD_BLOCK_BROADCAST (pad);
1439 /* call the callback if we need to be called for idle callbacks */
1440 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1441 if (pad->priv->using > 0) {
1442 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1443 * flag above, the last thread to leave the push will do the callback. New
1444 * threads going into the push will block. */
1445 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1446 "pad is in use, delay idle callback");
1447 GST_OBJECT_UNLOCK (pad);
1449 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1450 GstPadProbeReturn ret;
1452 /* Keep another ref, the callback could destroy the pad */
1453 gst_object_ref (pad);
1454 pad->priv->idle_running++;
1456 /* the pad is idle now, we can signal the idle callback now */
1457 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1458 "pad is idle, trigger idle callback");
1459 GST_OBJECT_UNLOCK (pad);
1461 ret = callback (pad, &info, user_data);
1463 GST_OBJECT_LOCK (pad);
1465 case GST_PAD_PROBE_REMOVE:
1466 /* remove the probe */
1467 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1468 cleanup_hook (pad, hook);
1471 case GST_PAD_PROBE_DROP:
1472 GST_DEBUG_OBJECT (pad, "asked to drop item");
1474 case GST_PAD_PROBE_PASS:
1475 GST_DEBUG_OBJECT (pad, "asked to pass item");
1477 case GST_PAD_PROBE_OK:
1478 GST_DEBUG_OBJECT (pad, "probe returned OK");
1480 case GST_PAD_PROBE_HANDLED:
1481 GST_DEBUG_OBJECT (pad, "probe handled the data");
1484 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1487 pad->priv->idle_running--;
1488 if (pad->priv->idle_running == 0) {
1489 GST_PAD_BLOCK_BROADCAST (pad);
1491 GST_OBJECT_UNLOCK (pad);
1493 gst_object_unref (pad);
1496 GST_OBJECT_UNLOCK (pad);
1502 * gst_pad_remove_probe:
1503 * @pad: the #GstPad with the probe
1504 * @id: the probe id to remove
1506 * Remove the probe with @id from @pad.
1511 gst_pad_remove_probe (GstPad * pad, gulong id)
1515 g_return_if_fail (GST_IS_PAD (pad));
1517 GST_OBJECT_LOCK (pad);
1519 hook = g_hook_get (&pad->probes, id);
1523 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1525 cleanup_hook (pad, hook);
1526 GST_OBJECT_UNLOCK (pad);
1532 GST_OBJECT_UNLOCK (pad);
1533 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1539 * gst_pad_is_blocked:
1540 * @pad: the #GstPad to query
1542 * Checks if the pad is blocked or not. This function returns the
1543 * last requested state of the pad. It is not certain that the pad
1544 * is actually blocking at this point (see gst_pad_is_blocking()).
1546 * Returns: %TRUE if the pad is blocked.
1551 gst_pad_is_blocked (GstPad * pad)
1553 gboolean result = FALSE;
1555 g_return_val_if_fail (GST_IS_PAD (pad), result);
1557 GST_OBJECT_LOCK (pad);
1558 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1559 GST_OBJECT_UNLOCK (pad);
1565 * gst_pad_is_blocking:
1566 * @pad: the #GstPad to query
1568 * Checks if the pad is blocking or not. This is a guaranteed state
1569 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1571 * Returns: %TRUE if the pad is blocking.
1576 gst_pad_is_blocking (GstPad * pad)
1578 gboolean result = FALSE;
1580 g_return_val_if_fail (GST_IS_PAD (pad), result);
1582 GST_OBJECT_LOCK (pad);
1583 /* the blocking flag is only valid if the pad is not flushing */
1584 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1585 GST_OBJECT_UNLOCK (pad);
1591 * gst_pad_needs_reconfigure:
1592 * @pad: the #GstPad to check
1594 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1595 * if the flag was set.
1597 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1600 gst_pad_needs_reconfigure (GstPad * pad)
1602 gboolean reconfigure;
1604 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1606 GST_OBJECT_LOCK (pad);
1607 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1608 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1609 GST_OBJECT_UNLOCK (pad);
1615 * gst_pad_check_reconfigure:
1616 * @pad: the #GstPad to check
1618 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1619 * if the flag was set.
1621 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1624 gst_pad_check_reconfigure (GstPad * pad)
1626 gboolean reconfigure;
1628 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1630 GST_OBJECT_LOCK (pad);
1631 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1633 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1634 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1636 GST_OBJECT_UNLOCK (pad);
1642 * gst_pad_mark_reconfigure:
1643 * @pad: the #GstPad to mark
1645 * Mark a pad for needing reconfiguration. The next call to
1646 * gst_pad_check_reconfigure() will return %TRUE after this call.
1649 gst_pad_mark_reconfigure (GstPad * pad)
1651 g_return_if_fail (GST_IS_PAD (pad));
1653 GST_OBJECT_LOCK (pad);
1654 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1655 GST_OBJECT_UNLOCK (pad);
1659 * gst_pad_set_activate_function:
1661 * @f: the #GstPadActivateFunction to set.
1663 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1667 * gst_pad_set_activate_function_full:
1669 * @activate: the #GstPadActivateFunction to set.
1670 * @user_data: user_data passed to @notify
1671 * @notify: notify called when @activate will not be used anymore.
1673 * Sets the given activate function for @pad. The activate function will
1674 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1675 * Only makes sense to set on sink pads.
1677 * Call this function if your sink pad can start a pull-based task.
1680 gst_pad_set_activate_function_full (GstPad * pad,
1681 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1683 g_return_if_fail (GST_IS_PAD (pad));
1685 if (pad->activatenotify)
1686 pad->activatenotify (pad->activatedata);
1687 GST_PAD_ACTIVATEFUNC (pad) = activate;
1688 pad->activatedata = user_data;
1689 pad->activatenotify = notify;
1691 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1692 GST_DEBUG_FUNCPTR_NAME (activate));
1696 * gst_pad_set_activatemode_function:
1698 * @f: the #GstPadActivateModeFunction to set.
1700 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1704 * gst_pad_set_activatemode_function_full:
1706 * @activatemode: the #GstPadActivateModeFunction to set.
1707 * @user_data: user_data passed to @notify
1708 * @notify: notify called when @activatemode will not be used anymore.
1710 * Sets the given activate_mode function for the pad. An activate_mode function
1711 * prepares the element for data passing.
1714 gst_pad_set_activatemode_function_full (GstPad * pad,
1715 GstPadActivateModeFunction activatemode, gpointer user_data,
1716 GDestroyNotify notify)
1718 g_return_if_fail (GST_IS_PAD (pad));
1720 if (pad->activatemodenotify)
1721 pad->activatemodenotify (pad->activatemodedata);
1722 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1723 pad->activatemodedata = user_data;
1724 pad->activatemodenotify = notify;
1726 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1727 GST_DEBUG_FUNCPTR_NAME (activatemode));
1731 * gst_pad_set_chain_function:
1732 * @p: a sink #GstPad.
1733 * @f: the #GstPadChainFunction to set.
1735 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1739 * gst_pad_set_chain_function_full:
1740 * @pad: a sink #GstPad.
1741 * @chain: the #GstPadChainFunction to set.
1742 * @user_data: user_data passed to @notify
1743 * @notify: notify called when @chain will not be used anymore.
1745 * Sets the given chain function for the pad. The chain function is called to
1746 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1749 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1750 gpointer user_data, GDestroyNotify notify)
1752 g_return_if_fail (GST_IS_PAD (pad));
1753 g_return_if_fail (GST_PAD_IS_SINK (pad));
1755 if (pad->chainnotify)
1756 pad->chainnotify (pad->chaindata);
1757 GST_PAD_CHAINFUNC (pad) = chain;
1758 pad->chaindata = user_data;
1759 pad->chainnotify = notify;
1761 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1762 GST_DEBUG_FUNCPTR_NAME (chain));
1766 * gst_pad_set_chain_list_function:
1767 * @p: a sink #GstPad.
1768 * @f: the #GstPadChainListFunction to set.
1770 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1774 * gst_pad_set_chain_list_function_full:
1775 * @pad: a sink #GstPad.
1776 * @chainlist: the #GstPadChainListFunction to set.
1777 * @user_data: user_data passed to @notify
1778 * @notify: notify called when @chainlist will not be used anymore.
1780 * Sets the given chain list function for the pad. The chainlist function is
1781 * called to process a #GstBufferList input buffer list. See
1782 * #GstPadChainListFunction for more details.
1785 gst_pad_set_chain_list_function_full (GstPad * pad,
1786 GstPadChainListFunction chainlist, gpointer user_data,
1787 GDestroyNotify notify)
1789 g_return_if_fail (GST_IS_PAD (pad));
1790 g_return_if_fail (GST_PAD_IS_SINK (pad));
1792 if (pad->chainlistnotify)
1793 pad->chainlistnotify (pad->chainlistdata);
1794 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1795 pad->chainlistdata = user_data;
1796 pad->chainlistnotify = notify;
1798 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1799 GST_DEBUG_FUNCPTR_NAME (chainlist));
1803 * gst_pad_set_getrange_function:
1804 * @p: a source #GstPad.
1805 * @f: the #GstPadGetRangeFunction to set.
1807 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1811 * gst_pad_set_getrange_function_full:
1812 * @pad: a source #GstPad.
1813 * @get: the #GstPadGetRangeFunction to set.
1814 * @user_data: user_data passed to @notify
1815 * @notify: notify called when @get will not be used anymore.
1817 * Sets the given getrange function for the pad. The getrange function is
1818 * called to produce a new #GstBuffer to start the processing pipeline. see
1819 * #GstPadGetRangeFunction for a description of the getrange function.
1822 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1823 gpointer user_data, GDestroyNotify notify)
1825 g_return_if_fail (GST_IS_PAD (pad));
1826 g_return_if_fail (GST_PAD_IS_SRC (pad));
1828 if (pad->getrangenotify)
1829 pad->getrangenotify (pad->getrangedata);
1830 GST_PAD_GETRANGEFUNC (pad) = get;
1831 pad->getrangedata = user_data;
1832 pad->getrangenotify = notify;
1834 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1835 GST_DEBUG_FUNCPTR_NAME (get));
1839 * gst_pad_set_event_function:
1840 * @p: a #GstPad of either direction.
1841 * @f: the #GstPadEventFunction to set.
1843 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1847 * gst_pad_set_event_function_full:
1848 * @pad: a #GstPad of either direction.
1849 * @event: the #GstPadEventFunction to set.
1850 * @user_data: user_data passed to @notify
1851 * @notify: notify called when @event will not be used anymore.
1853 * Sets the given event handler for the pad.
1856 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1857 gpointer user_data, GDestroyNotify notify)
1859 g_return_if_fail (GST_IS_PAD (pad));
1861 if (pad->eventnotify)
1862 pad->eventnotify (pad->eventdata);
1863 GST_PAD_EVENTFUNC (pad) = event;
1864 pad->eventdata = user_data;
1865 pad->eventnotify = notify;
1867 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1868 GST_DEBUG_FUNCPTR_NAME (event));
1872 event_wrap (GstPad * pad, GstObject * object, GstEvent * event)
1876 ret = GST_PAD_EVENTFULLFUNC (pad) (pad, object, event);
1877 if (ret == GST_FLOW_OK)
1883 * gst_pad_set_event_full_function:
1884 * @p: a #GstPad of either direction.
1885 * @f: the #GstPadEventFullFunction to set.
1887 * Calls gst_pad_set_event_full_function_full() with %NULL for the user_data and
1891 * gst_pad_set_event_full_function_full:
1892 * @pad: a #GstPad of either direction.
1893 * @event: the #GstPadEventFullFunction to set.
1894 * @user_data: user_data passed to @notify
1895 * @notify: notify called when @event will not be used anymore.
1897 * Sets the given event handler for the pad.
1902 gst_pad_set_event_full_function_full (GstPad * pad,
1903 GstPadEventFullFunction event, gpointer user_data, GDestroyNotify notify)
1905 g_return_if_fail (GST_IS_PAD (pad));
1907 if (pad->eventnotify)
1908 pad->eventnotify (pad->eventdata);
1909 GST_PAD_EVENTFULLFUNC (pad) = event;
1910 GST_PAD_EVENTFUNC (pad) = event_wrap;
1911 pad->eventdata = user_data;
1912 pad->eventnotify = notify;
1914 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfullfunc for set to %s",
1915 GST_DEBUG_FUNCPTR_NAME (event));
1919 * gst_pad_set_query_function:
1920 * @p: a #GstPad of either direction.
1921 * @f: the #GstPadQueryFunction to set.
1923 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1927 * gst_pad_set_query_function_full:
1928 * @pad: a #GstPad of either direction.
1929 * @query: the #GstPadQueryFunction to set.
1930 * @user_data: user_data passed to @notify
1931 * @notify: notify called when @query will not be used anymore.
1933 * Set the given query function for the pad.
1936 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1937 gpointer user_data, GDestroyNotify notify)
1939 g_return_if_fail (GST_IS_PAD (pad));
1941 if (pad->querynotify)
1942 pad->querynotify (pad->querydata);
1943 GST_PAD_QUERYFUNC (pad) = query;
1944 pad->querydata = user_data;
1945 pad->querynotify = notify;
1947 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1948 GST_DEBUG_FUNCPTR_NAME (query));
1952 * gst_pad_set_iterate_internal_links_function:
1953 * @p: a #GstPad of either direction.
1954 * @f: the #GstPadIterIntLinkFunction to set.
1956 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1957 * for the user_data and notify.
1960 * gst_pad_set_iterate_internal_links_function_full:
1961 * @pad: a #GstPad of either direction.
1962 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1963 * @user_data: user_data passed to @notify
1964 * @notify: notify called when @iterintlink will not be used anymore.
1966 * Sets the given internal link iterator function for the pad.
1969 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1970 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1971 GDestroyNotify notify)
1973 g_return_if_fail (GST_IS_PAD (pad));
1975 if (pad->iterintlinknotify)
1976 pad->iterintlinknotify (pad->iterintlinkdata);
1977 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1978 pad->iterintlinkdata = user_data;
1979 pad->iterintlinknotify = notify;
1981 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1982 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1986 * gst_pad_set_link_function:
1988 * @f: the #GstPadLinkFunction to set.
1990 * Calls gst_pad_set_link_function_full() with %NULL
1991 * for the user_data and notify.
1994 * gst_pad_set_link_function_full:
1996 * @link: the #GstPadLinkFunction to set.
1997 * @user_data: user_data passed to @notify
1998 * @notify: notify called when @link will not be used anymore.
2000 * Sets the given link function for the pad. It will be called when
2001 * the pad is linked with another pad.
2003 * The return value #GST_PAD_LINK_OK should be used when the connection can be
2006 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
2007 * cannot be made for some reason.
2009 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
2010 * of the peer sink pad, if present.
2013 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
2014 gpointer user_data, GDestroyNotify notify)
2016 g_return_if_fail (GST_IS_PAD (pad));
2018 if (pad->linknotify)
2019 pad->linknotify (pad->linkdata);
2020 GST_PAD_LINKFUNC (pad) = link;
2021 pad->linkdata = user_data;
2022 pad->linknotify = notify;
2024 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
2025 GST_DEBUG_FUNCPTR_NAME (link));
2029 * gst_pad_set_unlink_function:
2031 * @f: the #GstPadUnlinkFunction to set.
2033 * Calls gst_pad_set_unlink_function_full() with %NULL
2034 * for the user_data and notify.
2037 * gst_pad_set_unlink_function_full:
2039 * @unlink: the #GstPadUnlinkFunction to set.
2040 * @user_data: user_data passed to @notify
2041 * @notify: notify called when @unlink will not be used anymore.
2043 * Sets the given unlink function for the pad. It will be called
2044 * when the pad is unlinked.
2047 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
2048 gpointer user_data, GDestroyNotify notify)
2050 g_return_if_fail (GST_IS_PAD (pad));
2052 if (pad->unlinknotify)
2053 pad->unlinknotify (pad->unlinkdata);
2054 GST_PAD_UNLINKFUNC (pad) = unlink;
2055 pad->unlinkdata = user_data;
2056 pad->unlinknotify = notify;
2058 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
2059 GST_DEBUG_FUNCPTR_NAME (unlink));
2064 * @srcpad: the source #GstPad to unlink.
2065 * @sinkpad: the sink #GstPad to unlink.
2067 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
2068 * signal on both pads.
2070 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
2071 * the pads were not linked together.
2076 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
2078 gboolean result = FALSE;
2079 GstElement *parent = NULL;
2081 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2082 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
2083 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2084 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
2086 GST_TRACER_PAD_UNLINK_PRE (srcpad, sinkpad);
2088 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
2089 GST_DEBUG_PAD_NAME (srcpad), srcpad,
2090 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
2092 /* We need to notify the parent before taking any pad locks as the bin in
2093 * question might be waiting for a lock on the pad while holding its lock
2094 * that our message will try to take. */
2095 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2096 if (GST_IS_ELEMENT (parent)) {
2097 gst_element_post_message (parent,
2098 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2099 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
2101 gst_object_unref (parent);
2106 GST_OBJECT_LOCK (srcpad);
2107 GST_OBJECT_LOCK (sinkpad);
2109 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2110 goto not_linked_together;
2112 if (GST_PAD_UNLINKFUNC (srcpad)) {
2113 GstObject *tmpparent;
2115 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2117 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2118 RELEASE_PARENT (tmpparent);
2121 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2122 GstObject *tmpparent;
2124 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2126 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2127 RELEASE_PARENT (tmpparent);
2131 /* first clear peers */
2132 GST_PAD_PEER (srcpad) = NULL;
2133 GST_PAD_PEER (sinkpad) = NULL;
2135 GST_OBJECT_UNLOCK (sinkpad);
2136 GST_OBJECT_UNLOCK (srcpad);
2138 /* fire off a signal to each of the pads telling them
2139 * that they've been unlinked */
2140 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2141 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2143 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2144 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2149 if (parent != NULL) {
2150 gst_element_post_message (parent,
2151 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2152 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2153 gst_object_unref (parent);
2155 GST_TRACER_PAD_UNLINK_POST (srcpad, sinkpad, result);
2159 not_linked_together:
2161 /* we do not emit a warning in this case because unlinking cannot
2162 * be made MT safe.*/
2163 GST_OBJECT_UNLOCK (sinkpad);
2164 GST_OBJECT_UNLOCK (srcpad);
2170 * gst_pad_is_linked:
2171 * @pad: pad to check
2173 * Checks if a @pad is linked to another pad or not.
2175 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2180 gst_pad_is_linked (GstPad * pad)
2184 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2186 GST_OBJECT_LOCK (pad);
2187 result = (GST_PAD_PEER (pad) != NULL);
2188 GST_OBJECT_UNLOCK (pad);
2193 /* get the caps from both pads and see if the intersection
2196 * This function should be called with the pad LOCK on both
2200 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2201 GstPadLinkCheck flags)
2203 GstCaps *srccaps = NULL;
2204 GstCaps *sinkcaps = NULL;
2205 gboolean compatible = FALSE;
2207 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2210 /* Doing the expensive caps checking takes priority over only checking the template caps */
2211 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2212 GST_OBJECT_UNLOCK (sink);
2213 GST_OBJECT_UNLOCK (src);
2215 srccaps = gst_pad_query_caps (src, NULL);
2216 sinkcaps = gst_pad_query_caps (sink, NULL);
2218 GST_OBJECT_LOCK (src);
2219 GST_OBJECT_LOCK (sink);
2221 /* If one of the two pads doesn't have a template, consider the intersection
2223 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2224 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2228 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2230 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2233 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2235 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2238 /* if we have caps on both pads we can check the intersection. If one
2239 * of the caps is %NULL, we return %TRUE. */
2240 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2242 gst_caps_unref (srccaps);
2244 gst_caps_unref (sinkcaps);
2248 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2249 gst_caps_unref (srccaps);
2250 gst_caps_unref (sinkcaps);
2253 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2254 (compatible ? "" : "not "));
2259 /* check if the grandparents of both pads are the same.
2260 * This check is required so that we don't try to link
2261 * pads from elements in different bins without ghostpads.
2263 * The LOCK should be held on both pads
2266 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2268 GstObject *psrc, *psink;
2270 psrc = GST_OBJECT_PARENT (src);
2271 psink = GST_OBJECT_PARENT (sink);
2273 /* if one of the pads has no parent, we allow the link */
2274 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2277 /* only care about parents that are elements */
2278 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2279 goto no_element_parent;
2281 /* if the parents are the same, we have a loop */
2282 if (G_UNLIKELY (psrc == psink))
2285 /* if they both have a parent, we check the grandparents. We can not lock
2286 * the parent because we hold on the child (pad) and the locking order is
2287 * parent >> child. */
2288 psrc = GST_OBJECT_PARENT (psrc);
2289 psink = GST_OBJECT_PARENT (psink);
2291 /* if they have grandparents but they are not the same */
2292 if (G_UNLIKELY (psrc != psink))
2293 goto wrong_grandparents;
2300 GST_CAT_DEBUG (GST_CAT_CAPS,
2301 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2302 GST_PTR_FORMAT, psrc, psink);
2307 GST_CAT_DEBUG (GST_CAT_CAPS,
2308 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2309 GST_PTR_FORMAT, psrc, psink);
2314 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2320 GST_CAT_DEBUG (GST_CAT_CAPS,
2321 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2322 GST_PTR_FORMAT, psrc, psink);
2327 /* FIXME leftover from an attempt at refactoring... */
2328 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2329 * the two pads will be locked in the srcpad, sinkpad order. */
2330 static GstPadLinkReturn
2331 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2333 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2334 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2336 GST_OBJECT_LOCK (srcpad);
2338 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2339 goto src_was_linked;
2341 GST_OBJECT_LOCK (sinkpad);
2343 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2344 goto sink_was_linked;
2346 /* check hierarchy, pads can only be linked if the grandparents
2348 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2349 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2350 goto wrong_hierarchy;
2352 /* check pad caps for non-empty intersection */
2353 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2356 /* FIXME check pad scheduling for non-empty intersection */
2358 return GST_PAD_LINK_OK;
2362 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2363 GST_DEBUG_PAD_NAME (srcpad),
2364 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2365 /* we do not emit a warning in this case because unlinking cannot
2366 * be made MT safe.*/
2367 GST_OBJECT_UNLOCK (srcpad);
2368 return GST_PAD_LINK_WAS_LINKED;
2372 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2373 GST_DEBUG_PAD_NAME (sinkpad),
2374 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2375 /* we do not emit a warning in this case because unlinking cannot
2376 * be made MT safe.*/
2377 GST_OBJECT_UNLOCK (sinkpad);
2378 GST_OBJECT_UNLOCK (srcpad);
2379 return GST_PAD_LINK_WAS_LINKED;
2383 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2384 GST_OBJECT_UNLOCK (sinkpad);
2385 GST_OBJECT_UNLOCK (srcpad);
2386 return GST_PAD_LINK_WRONG_HIERARCHY;
2390 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2391 GST_OBJECT_UNLOCK (sinkpad);
2392 GST_OBJECT_UNLOCK (srcpad);
2393 return GST_PAD_LINK_NOFORMAT;
2399 * @srcpad: the source #GstPad.
2400 * @sinkpad: the sink #GstPad.
2402 * Checks if the source pad and the sink pad are compatible so they can be
2405 * Returns: %TRUE if the pads can be linked.
2408 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2410 GstPadLinkReturn result;
2412 /* generic checks */
2413 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2414 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2416 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2417 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2419 /* gst_pad_link_prepare does everything for us, we only release the locks
2420 * on the pads that it gets us. If this function returns !OK the locks are not
2422 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2423 if (result != GST_PAD_LINK_OK)
2426 GST_OBJECT_UNLOCK (srcpad);
2427 GST_OBJECT_UNLOCK (sinkpad);
2430 return result == GST_PAD_LINK_OK;
2434 * gst_pad_link_full:
2435 * @srcpad: the source #GstPad to link.
2436 * @sinkpad: the sink #GstPad to link.
2437 * @flags: the checks to validate when linking
2439 * Links the source pad and the sink pad.
2441 * This variant of #gst_pad_link provides a more granular control on the
2442 * checks being done when linking. While providing some considerable speedups
2443 * the caller of this method must be aware that wrong usage of those flags
2444 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2445 * for more information.
2449 * Returns: A result code indicating if the connection worked or
2453 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2455 GstPadLinkReturn result;
2457 GstPadLinkFunction srcfunc, sinkfunc;
2459 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2460 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2461 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2462 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2463 GST_PAD_LINK_WRONG_DIRECTION);
2465 GST_TRACER_PAD_LINK_PRE (srcpad, sinkpad);
2467 /* Notify the parent early. See gst_pad_unlink for details. */
2468 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2469 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2470 gst_element_post_message (parent,
2471 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2472 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2474 gst_object_unref (parent);
2479 /* prepare will also lock the two pads */
2480 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2482 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2483 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2484 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2485 gst_pad_link_get_name (result));
2489 /* must set peers before calling the link function */
2490 GST_PAD_PEER (srcpad) = sinkpad;
2491 GST_PAD_PEER (sinkpad) = srcpad;
2493 /* check events, when something is different, mark pending */
2494 schedule_events (srcpad, sinkpad);
2496 /* get the link functions */
2497 srcfunc = GST_PAD_LINKFUNC (srcpad);
2498 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2500 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2501 /* custom link functions, execute them */
2502 GST_OBJECT_UNLOCK (sinkpad);
2503 GST_OBJECT_UNLOCK (srcpad);
2506 GstObject *tmpparent;
2508 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2509 /* this one will call the peer link function */
2510 result = srcfunc (srcpad, tmpparent, sinkpad);
2511 RELEASE_PARENT (tmpparent);
2512 } else if (sinkfunc) {
2513 GstObject *tmpparent;
2515 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2516 /* if no source link function, we need to call the sink link
2517 * function ourselves. */
2518 result = sinkfunc (sinkpad, tmpparent, srcpad);
2519 RELEASE_PARENT (tmpparent);
2523 GST_OBJECT_LOCK (srcpad);
2524 GST_OBJECT_LOCK (sinkpad);
2526 /* we released the lock, check if the same pads are linked still */
2527 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2528 goto concurrent_link;
2530 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2533 GST_OBJECT_UNLOCK (sinkpad);
2534 GST_OBJECT_UNLOCK (srcpad);
2536 /* fire off a signal to each of the pads telling them
2537 * that they've been linked */
2538 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2539 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2541 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2542 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2544 if (!(flags & GST_PAD_LINK_CHECK_NO_RECONFIGURE))
2545 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2548 if (G_LIKELY (parent)) {
2549 gst_element_post_message (parent,
2550 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2551 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2552 gst_object_unref (parent);
2555 GST_TRACER_PAD_LINK_POST (srcpad, sinkpad, result);
2561 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2562 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2563 GST_OBJECT_UNLOCK (sinkpad);
2564 GST_OBJECT_UNLOCK (srcpad);
2566 /* The other link operation succeeded first */
2567 result = GST_PAD_LINK_WAS_LINKED;
2572 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2573 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2574 gst_pad_link_get_name (result));
2576 GST_PAD_PEER (srcpad) = NULL;
2577 GST_PAD_PEER (sinkpad) = NULL;
2579 GST_OBJECT_UNLOCK (sinkpad);
2580 GST_OBJECT_UNLOCK (srcpad);
2588 * @srcpad: the source #GstPad to link.
2589 * @sinkpad: the sink #GstPad to link.
2591 * Links the source pad and the sink pad.
2593 * Returns: A result code indicating if the connection worked or
2599 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2601 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2605 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2607 GstPadTemplate **template_p;
2609 /* this function would need checks if it weren't static */
2611 GST_OBJECT_LOCK (pad);
2612 template_p = &pad->padtemplate;
2613 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2614 GST_OBJECT_UNLOCK (pad);
2617 gst_pad_template_pad_created (templ, pad);
2621 * gst_pad_get_pad_template:
2624 * Gets the template for @pad.
2626 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2627 * this pad was instantiated, or %NULL if this pad has no
2628 * template. Unref after usage.
2631 gst_pad_get_pad_template (GstPad * pad)
2633 GstPadTemplate *templ;
2635 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2637 templ = GST_PAD_PAD_TEMPLATE (pad);
2639 return (templ ? gst_object_ref (templ) : NULL);
2643 * gst_pad_has_current_caps:
2644 * @pad: a #GstPad to check
2646 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2648 * Returns: %TRUE when @pad has caps associated with it.
2651 gst_pad_has_current_caps (GstPad * pad)
2656 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2658 GST_OBJECT_LOCK (pad);
2659 caps = get_pad_caps (pad);
2660 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2661 "check current pad caps %" GST_PTR_FORMAT, caps);
2662 result = (caps != NULL);
2663 GST_OBJECT_UNLOCK (pad);
2669 * gst_pad_get_current_caps:
2670 * @pad: a #GstPad to get the current capabilities of.
2672 * Gets the capabilities currently configured on @pad with the last
2673 * #GST_EVENT_CAPS event.
2675 * Returns: (transfer full) (nullable): the current caps of the pad with
2676 * incremented ref-count or %NULL when pad has no caps. Unref after usage.
2679 gst_pad_get_current_caps (GstPad * pad)
2683 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2685 GST_OBJECT_LOCK (pad);
2686 if ((result = get_pad_caps (pad)))
2687 gst_caps_ref (result);
2688 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2689 "get current pad caps %" GST_PTR_FORMAT, result);
2690 GST_OBJECT_UNLOCK (pad);
2696 * gst_pad_get_pad_template_caps:
2697 * @pad: a #GstPad to get the template capabilities from.
2699 * Gets the capabilities for @pad's template.
2701 * Returns: (transfer full): the #GstCaps of this pad template.
2702 * Unref after usage.
2705 gst_pad_get_pad_template_caps (GstPad * pad)
2707 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2709 if (GST_PAD_PAD_TEMPLATE (pad))
2710 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2712 return gst_caps_ref (GST_CAPS_ANY);
2717 * @pad: a #GstPad to get the peer of.
2719 * Gets the peer of @pad. This function refs the peer pad so
2720 * you need to unref it after use.
2722 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2727 gst_pad_get_peer (GstPad * pad)
2731 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2733 GST_OBJECT_LOCK (pad);
2734 result = GST_PAD_PEER (pad);
2736 gst_object_ref (result);
2737 GST_OBJECT_UNLOCK (pad);
2743 * gst_pad_get_allowed_caps:
2746 * Gets the capabilities of the allowed media types that can flow through
2747 * @pad and its peer.
2749 * The allowed capabilities is calculated as the intersection of the results of
2750 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2751 * on the resulting caps.
2753 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2754 * pad link. Unref the caps when you no longer need it. This
2755 * function returns %NULL when @pad has no peer.
2760 gst_pad_get_allowed_caps (GstPad * pad)
2763 GstCaps *caps = NULL;
2766 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2768 GST_OBJECT_LOCK (pad);
2769 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2771 GST_OBJECT_UNLOCK (pad);
2773 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2775 mycaps = gst_pad_query_caps (pad, NULL);
2777 /* Query peer caps */
2778 query = gst_query_new_caps (mycaps);
2779 if (!gst_pad_peer_query (pad, query)) {
2780 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "Caps query failed");
2784 gst_query_parse_caps_result (query, &caps);
2786 g_warn_if_fail (caps != NULL);
2789 gst_caps_ref (caps);
2791 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2795 gst_query_unref (query);
2796 gst_caps_unref (mycaps);
2802 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2803 GST_OBJECT_UNLOCK (pad);
2810 * gst_pad_iterate_internal_links_default:
2811 * @pad: the #GstPad to get the internal links of.
2812 * @parent: (allow-none): the parent of @pad or %NULL
2814 * Iterate the list of pads to which the given pad is linked to inside of
2815 * the parent element.
2816 * This is the default handler, and thus returns an iterator of all of the
2817 * pads inside the parent element with opposite direction.
2819 * The caller must free this iterator after use with gst_iterator_free().
2821 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2822 * has no parent. Unref each returned pad with gst_object_unref().
2825 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2832 GstElement *eparent;
2834 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2836 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2837 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2839 GST_OBJECT_LOCK (pad);
2840 eparent = GST_PAD_PARENT (pad);
2841 if (!eparent || !GST_IS_ELEMENT (eparent))
2844 gst_object_ref (eparent);
2845 GST_OBJECT_UNLOCK (pad);
2848 if (pad->direction == GST_PAD_SRC)
2849 padlist = &eparent->sinkpads;
2851 padlist = &eparent->srcpads;
2853 GST_DEBUG_OBJECT (pad, "Making iterator");
2855 cookie = &eparent->pads_cookie;
2857 lock = GST_OBJECT_GET_LOCK (eparent);
2859 res = gst_iterator_new_list (GST_TYPE_PAD,
2860 lock, cookie, padlist, (GObject *) owner, NULL);
2862 gst_object_unref (owner);
2869 GST_OBJECT_UNLOCK (pad);
2870 GST_DEBUG_OBJECT (pad, "no parent element");
2876 * gst_pad_iterate_internal_links:
2877 * @pad: the GstPad to get the internal links of.
2879 * Gets an iterator for the pads to which the given pad is linked to inside
2880 * of the parent element.
2882 * Each #GstPad element yielded by the iterator will have its refcount increased,
2883 * so unref after use.
2885 * Free-function: gst_iterator_free
2887 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2888 * or %NULL when the pad does not have an iterator function
2889 * configured. Use gst_iterator_free() after usage.
2892 gst_pad_iterate_internal_links (GstPad * pad)
2894 GstIterator *res = NULL;
2897 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2899 GST_OBJECT_LOCK (pad);
2900 ACQUIRE_PARENT (pad, parent, no_parent);
2901 GST_OBJECT_UNLOCK (pad);
2903 if (GST_PAD_ITERINTLINKFUNC (pad))
2904 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2906 RELEASE_PARENT (parent);
2913 GST_DEBUG_OBJECT (pad, "no parent");
2914 GST_OBJECT_UNLOCK (pad);
2922 * @forward: (scope call): a #GstPadForwardFunction
2923 * @user_data: user data passed to @forward
2925 * Calls @forward for all internally linked pads of @pad. This function deals with
2926 * dynamically changing internal pads and will make sure that the @forward
2927 * function is only called once for each pad.
2929 * When @forward returns %TRUE, no further pads will be processed.
2931 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2934 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2937 gboolean result = FALSE;
2939 gboolean done = FALSE;
2940 GValue item = { 0, };
2941 GList *pushed_pads = NULL;
2943 iter = gst_pad_iterate_internal_links (pad);
2949 switch (gst_iterator_next (iter, &item)) {
2950 case GST_ITERATOR_OK:
2954 intpad = g_value_get_object (&item);
2956 /* if already pushed, skip. FIXME, find something faster to tag pads */
2957 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2958 g_value_reset (&item);
2962 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2963 GST_DEBUG_PAD_NAME (intpad));
2964 done = result = forward (intpad, user_data);
2966 pushed_pads = g_list_prepend (pushed_pads, intpad);
2968 g_value_reset (&item);
2971 case GST_ITERATOR_RESYNC:
2972 /* We don't reset the result here because we don't push the event
2973 * again on pads that got the event already and because we need
2974 * to consider the result of the previous pushes */
2975 gst_iterator_resync (iter);
2977 case GST_ITERATOR_ERROR:
2978 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2981 case GST_ITERATOR_DONE:
2986 g_value_unset (&item);
2987 gst_iterator_free (iter);
2989 g_list_free (pushed_pads);
2999 gboolean dispatched;
3003 event_forward_func (GstPad * pad, EventData * data)
3005 /* for each pad we send to, we should ref the event; it's up
3006 * to downstream to unref again when handled. */
3007 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3008 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3010 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3012 data->dispatched = TRUE;
3019 * gst_pad_event_default:
3020 * @pad: a #GstPad to call the default event handler on.
3021 * @parent: (allow-none): the parent of @pad or %NULL
3022 * @event: (transfer full): the #GstEvent to handle.
3024 * Invokes the default event handler for the given pad.
3026 * The EOS event will pause the task associated with @pad before it is forwarded
3027 * to all internally linked pads,
3029 * The event is sent to all pads internally linked to @pad. This function
3030 * takes ownership of @event.
3032 * Returns: %TRUE if the event was sent successfully.
3035 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
3037 gboolean result, forward = TRUE;
3039 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3040 g_return_val_if_fail (event != NULL, FALSE);
3042 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
3045 switch (GST_EVENT_TYPE (event)) {
3046 case GST_EVENT_CAPS:
3047 forward = GST_PAD_IS_PROXY_CAPS (pad);
3058 data.dispatched = FALSE;
3059 data.result = FALSE;
3061 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3063 /* for sinkpads without a parent element or without internal links, nothing
3064 * will be dispatched but we still want to return TRUE. */
3065 if (data.dispatched)
3066 result = data.result;
3071 gst_event_unref (event);
3076 /* Default accept caps implementation just checks against
3077 * the allowed caps for the pad */
3079 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
3081 /* get the caps and see if it intersects to something not empty */
3082 GstCaps *caps, *allowed = NULL;
3085 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
3087 /* first forward the query to internally linked pads when we are dealing with
3089 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3090 result = gst_pad_proxy_query_accept_caps (pad, query);
3092 allowed = gst_pad_get_pad_template_caps (pad);
3097 gst_query_parse_accept_caps (query, &caps);
3099 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad)) {
3100 allowed = gst_pad_get_pad_template_caps (pad);
3102 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
3103 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
3104 allowed = gst_pad_query_caps (pad, caps);
3109 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
3110 GST_DEBUG_OBJECT (pad,
3111 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
3113 result = gst_caps_can_intersect (caps, allowed);
3115 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
3116 GST_PTR_FORMAT, allowed, caps);
3117 result = gst_caps_is_subset (caps, allowed);
3119 gst_caps_unref (allowed);
3121 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3124 gst_query_set_accept_caps_result (query, result);
3130 /* Default caps implementation */
3132 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3134 GstCaps *result = NULL, *filter;
3135 GstPadTemplate *templ;
3136 gboolean fixed_caps;
3138 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3141 /* first try to proxy if we must */
3142 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3143 if ((gst_pad_proxy_query_caps (pad, query))) {
3148 gst_query_parse_caps (query, &filter);
3150 /* no proxy or it failed, do default handling */
3151 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3153 GST_OBJECT_LOCK (pad);
3155 /* fixed caps, try the negotiated caps first */
3156 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3157 if ((result = get_pad_caps (pad)))
3158 goto filter_done_unlock;
3161 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3162 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3163 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3164 goto filter_done_unlock;
3168 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3169 "non-fixed pad caps: trying pad caps");
3170 /* non fixed caps, try the negotiated caps */
3171 if ((result = get_pad_caps (pad)))
3172 goto filter_done_unlock;
3175 /* this almost never happens */
3176 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3177 result = GST_CAPS_ANY;
3180 GST_OBJECT_UNLOCK (pad);
3182 /* run the filter on the result */
3184 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3185 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3186 GST_PTR_FORMAT, result, result, filter, filter);
3187 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3188 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3191 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3192 "using caps %p %" GST_PTR_FORMAT, result, result);
3193 result = gst_caps_ref (result);
3195 gst_query_set_caps_result (query, result);
3196 gst_caps_unref (result);
3202 /* Default latency implementation */
3207 GstClockTime min, max;
3211 query_latency_default_fold (const GValue * item, GValue * ret,
3214 GstPad *pad = g_value_get_object (item), *peer;
3215 LatencyFoldData *fold_data = user_data;
3217 gboolean res = FALSE;
3219 query = gst_query_new_latency ();
3221 peer = gst_pad_get_peer (pad);
3223 res = gst_pad_peer_query (pad, query);
3225 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3230 GstClockTime min, max;
3232 gst_query_parse_latency (query, &live, &min, &max);
3234 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3235 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3237 /* FIXME : Why do we only take values into account if it's live ? */
3238 if (live || fold_data->count == 0) {
3239 if (min > fold_data->min)
3240 fold_data->min = min;
3242 if (fold_data->max == GST_CLOCK_TIME_NONE)
3243 fold_data->max = max;
3244 else if (max < fold_data->max)
3245 fold_data->max = max;
3247 fold_data->live = live;
3249 fold_data->count += 1;
3251 GST_DEBUG_OBJECT (pad, "latency query failed");
3252 g_value_set_boolean (ret, FALSE);
3255 gst_query_unref (query);
3257 gst_object_unref (peer);
3263 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3266 GstIteratorResult res;
3267 GValue ret = G_VALUE_INIT;
3269 LatencyFoldData fold_data;
3271 it = gst_pad_iterate_internal_links (pad);
3273 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3277 g_value_init (&ret, G_TYPE_BOOLEAN);
3280 fold_data.count = 0;
3281 fold_data.live = FALSE;
3283 fold_data.max = GST_CLOCK_TIME_NONE;
3285 g_value_set_boolean (&ret, TRUE);
3286 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3288 case GST_ITERATOR_OK:
3289 g_assert_not_reached ();
3291 case GST_ITERATOR_DONE:
3293 case GST_ITERATOR_ERROR:
3294 g_value_set_boolean (&ret, FALSE);
3296 case GST_ITERATOR_RESYNC:
3297 gst_iterator_resync (it);
3300 g_assert_not_reached ();
3303 gst_iterator_free (it);
3305 query_ret = g_value_get_boolean (&ret);
3307 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3308 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3309 fold_data.min, fold_data.max);
3311 if (fold_data.min > fold_data.max) {
3312 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3315 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3317 GST_LOG_OBJECT (pad, "latency query failed");
3327 gboolean dispatched;
3331 query_forward_func (GstPad * pad, QueryData * data)
3333 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3334 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3336 data->result |= gst_pad_peer_query (pad, data->query);
3338 data->dispatched = TRUE;
3340 /* stop on first successful reply */
3341 return data->result;
3345 * gst_pad_query_default:
3346 * @pad: a #GstPad to call the default query handler on.
3347 * @parent: (allow-none): the parent of @pad or %NULL
3348 * @query: (transfer none): the #GstQuery to handle.
3350 * Invokes the default query handler for the given pad.
3351 * The query is sent to all pads internally linked to @pad. Note that
3352 * if there are many possible sink pads that are internally linked to
3353 * @pad, only one will be sent the query.
3354 * Multi-sinkpad elements should implement custom query handlers.
3356 * Returns: %TRUE if the query was performed successfully.
3359 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3361 gboolean forward, ret = FALSE;
3363 switch (GST_QUERY_TYPE (query)) {
3364 case GST_QUERY_SCHEDULING:
3365 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3367 case GST_QUERY_ALLOCATION:
3368 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3370 case GST_QUERY_ACCEPT_CAPS:
3371 ret = gst_pad_query_accept_caps_default (pad, query);
3374 case GST_QUERY_CAPS:
3375 ret = gst_pad_query_caps_default (pad, query);
3378 case GST_QUERY_LATENCY:
3379 ret = gst_pad_query_latency_default (pad, query);
3382 case GST_QUERY_POSITION:
3383 case GST_QUERY_SEEKING:
3384 case GST_QUERY_FORMATS:
3385 case GST_QUERY_JITTER:
3386 case GST_QUERY_RATE:
3387 case GST_QUERY_CONVERT:
3393 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3394 query, GST_QUERY_TYPE_NAME (query));
3400 data.dispatched = FALSE;
3401 data.result = FALSE;
3403 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3405 if (data.dispatched) {
3408 /* nothing dispatched, assume drained */
3409 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3419 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3421 GstPad *pad = data->pad;
3422 GstPadProbeInfo *info = data->info;
3423 GstPadProbeType type, flags;
3424 GstPadProbeCallback callback;
3425 GstPadProbeReturn ret;
3426 gpointer original_data;
3428 /* if we have called this callback, do nothing */
3429 if (PROBE_COOKIE (hook) == data->cookie) {
3430 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3431 "hook %lu, cookie %u already called", hook->hook_id,
3432 PROBE_COOKIE (hook));
3436 PROBE_COOKIE (hook) = data->cookie;
3438 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3440 original_data = info->data;
3442 /* one of the scheduling types */
3443 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3446 if (G_UNLIKELY (data->handled)) {
3447 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3448 "probe previously returned HANDLED, not calling again");
3450 } else if (G_UNLIKELY (data->dropped)) {
3451 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3452 "probe previously returned DROPPED, not calling again");
3456 if (type & GST_PAD_PROBE_TYPE_PUSH) {
3457 /* one of the data types for non-idle probes */
3458 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3459 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3461 } else if (type & GST_PAD_PROBE_TYPE_PULL) {
3462 /* one of the data types for non-idle probes */
3463 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0
3464 && (flags & _PAD_PROBE_TYPE_ALL_BOTH_AND_FLUSH & type) == 0)
3467 /* Type must have PULL or PUSH probe types */
3468 g_assert_not_reached ();
3471 /* one of the blocking types must match */
3472 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3473 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3475 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3476 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3478 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3479 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3480 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3483 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3484 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3485 PROBE_COOKIE (hook), flags);
3487 data->marshalled = TRUE;
3489 callback = (GstPadProbeCallback) hook->func;
3490 if (callback == NULL)
3493 info->id = hook->hook_id;
3495 GST_OBJECT_UNLOCK (pad);
3497 ret = callback (pad, info, hook->data);
3499 GST_OBJECT_LOCK (pad);
3501 if (original_data != NULL && info->data == NULL) {
3502 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3503 info->type = GST_PAD_PROBE_TYPE_INVALID;
3504 data->dropped = TRUE;
3508 case GST_PAD_PROBE_REMOVE:
3509 /* remove the probe */
3510 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3511 cleanup_hook (pad, hook);
3513 case GST_PAD_PROBE_DROP:
3514 /* need to drop the data, make sure other probes don't get called
3516 GST_DEBUG_OBJECT (pad, "asked to drop item");
3517 info->type = GST_PAD_PROBE_TYPE_INVALID;
3518 data->dropped = TRUE;
3520 case GST_PAD_PROBE_HANDLED:
3521 GST_DEBUG_OBJECT (pad, "probe handled data");
3522 data->handled = TRUE;
3524 case GST_PAD_PROBE_PASS:
3525 /* inform the pad block to let things pass */
3526 GST_DEBUG_OBJECT (pad, "asked to pass item");
3529 case GST_PAD_PROBE_OK:
3530 GST_DEBUG_OBJECT (pad, "probe returned OK");
3533 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3540 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3541 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3542 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3547 /* a probe that does not take or return any data */
3548 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3550 if (G_UNLIKELY (pad->num_probes)) { \
3551 GstFlowReturn pval = defaultval; \
3552 /* pass NULL as the data item */ \
3553 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3554 info.ABI.abi.flow_ret = defaultval; \
3555 ret = do_probe_callbacks (pad, &info, defaultval); \
3556 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3561 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3563 if (G_UNLIKELY (pad->num_probes)) { \
3564 /* pass the data item */ \
3565 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3566 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3567 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3568 /* store the possibly updated data item */ \
3569 data = GST_PAD_PROBE_INFO_DATA (&info); \
3570 /* if something went wrong, exit */ \
3571 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3572 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3573 ret = info.ABI.abi.flow_ret; \
3574 goto handle_label; \
3581 #define PROBE_PUSH(pad,mask,data,label) \
3582 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3583 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3584 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3585 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3586 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3588 static GstFlowReturn
3589 do_pad_idle_probe_wait (GstPad * pad)
3591 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3592 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3593 "waiting idle probe to be removed");
3594 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3595 GST_PAD_BLOCK_WAIT (pad);
3596 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3597 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3599 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3600 return GST_FLOW_FLUSHING;
3605 #define PROBE_TYPE_IS_SERIALIZED(i) \
3608 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3609 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3610 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3612 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3613 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3615 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3616 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3620 static GstFlowReturn
3621 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3622 GstFlowReturn defaultval)
3631 data.handled = FALSE;
3632 data.marshalled = FALSE;
3633 data.dropped = FALSE;
3634 data.cookie = ++pad->priv->probe_cookie;
3637 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3639 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3640 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3645 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3646 "do probes cookie %u", data.cookie);
3647 cookie = pad->priv->probe_list_cookie;
3649 g_hook_list_marshal (&pad->probes, TRUE,
3650 (GHookMarshaller) probe_hook_marshal, &data);
3652 /* if the list changed, call the new callbacks (they will not have their
3653 * cookie set to data.cookie */
3654 if (cookie != pad->priv->probe_list_cookie) {
3655 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3656 "probe list changed, restarting");
3660 /* the first item that dropped will stop the hooks and then we drop here */
3664 /* If one handler took care of it, let the the item pass */
3669 /* if no handler matched and we are blocking, let the item pass */
3670 if (!data.marshalled && is_block)
3673 /* At this point, all handlers returned either OK or PASS. If one handler
3674 * returned PASS, let the item pass */
3679 while (GST_PAD_IS_BLOCKED (pad)) {
3680 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3681 "we are blocked %d times", pad->num_blocked);
3683 /* we might have released the lock */
3684 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3687 /* now we block the streaming thread. It can be unlocked when we
3688 * deactivate the pad (which will also set the FLUSHING flag) or
3689 * when the pad is unblocked. A flushing event will also unblock
3690 * the pad after setting the FLUSHING flag. */
3691 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3692 "Waiting to be unblocked or set flushing");
3693 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3694 GST_PAD_BLOCK_WAIT (pad);
3695 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3696 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3698 /* if the list changed, call the new callbacks (they will not have their
3699 * cookie set to data.cookie */
3700 if (cookie != pad->priv->probe_list_cookie) {
3701 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3702 "probe list changed, restarting");
3706 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3716 GST_DEBUG_OBJECT (pad, "pad is flushing");
3717 return GST_FLOW_FLUSHING;
3721 GST_DEBUG_OBJECT (pad, "data is dropped");
3722 return GST_FLOW_CUSTOM_SUCCESS;
3726 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3727 GST_DEBUG_OBJECT (pad, "data is passed");
3732 GST_DEBUG_OBJECT (pad, "data was handled");
3733 return GST_FLOW_CUSTOM_SUCCESS_1;
3740 * gst_pad_get_offset:
3743 * Get the offset applied to the running time of @pad. @pad has to be a source
3746 * Returns: the offset.
3749 gst_pad_get_offset (GstPad * pad)
3753 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3755 GST_OBJECT_LOCK (pad);
3756 result = pad->offset;
3757 GST_OBJECT_UNLOCK (pad);
3763 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3765 ev->received = FALSE;
3770 * gst_pad_set_offset:
3772 * @offset: the offset
3774 * Set the offset that will be applied to the running time of @pad.
3777 gst_pad_set_offset (GstPad * pad, gint64 offset)
3779 g_return_if_fail (GST_IS_PAD (pad));
3781 GST_OBJECT_LOCK (pad);
3782 /* if nothing changed, do nothing */
3783 if (pad->offset == offset)
3786 pad->offset = offset;
3787 GST_DEBUG_OBJECT (pad, "changed offset to %" GST_STIME_FORMAT,
3788 GST_STIME_ARGS (offset));
3790 /* resend all sticky events with updated offset on next buffer push */
3791 events_foreach (pad, mark_event_not_received, NULL);
3792 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3795 GST_OBJECT_UNLOCK (pad);
3802 /* If TRUE and ret is not OK this means
3803 * that pushing the EOS event failed
3807 /* If called for an event this is
3808 * the event that would be pushed
3809 * next. Don't forward sticky events
3810 * that would come after that */
3814 /* should be called with pad LOCK */
3816 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3818 PushStickyData *data = user_data;
3819 GstEvent *event = ev->event;
3822 GST_DEBUG_OBJECT (pad, "event %s was already received",
3823 GST_EVENT_TYPE_NAME (event));
3827 /* If we're called because of an sticky event, only forward
3828 * events that would come before this new event and the
3830 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3831 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3832 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3833 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3835 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3836 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3839 switch (data->ret) {
3841 ev->received = TRUE;
3842 GST_DEBUG_OBJECT (pad, "event %s marked received",
3843 GST_EVENT_TYPE_NAME (event));
3845 case GST_FLOW_CUSTOM_SUCCESS:
3846 /* we can't assume the event is received when it was dropped */
3847 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3848 GST_EVENT_TYPE_NAME (event));
3849 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3850 data->ret = GST_FLOW_OK;
3852 case GST_FLOW_CUSTOM_SUCCESS_1:
3853 /* event was ignored and should be sent later */
3854 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3855 GST_EVENT_TYPE_NAME (event));
3856 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3857 data->ret = GST_FLOW_OK;
3859 case GST_FLOW_NOT_LINKED:
3860 /* not linked is not a problem, we are sticky so the event will be
3861 * rescheduled to be sent later on re-link, but only for non-EOS events */
3862 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3863 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS) {
3864 data->ret = GST_FLOW_OK;
3865 ev->received = TRUE;
3869 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3870 gst_flow_get_name (data->ret));
3871 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3875 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3876 data->was_eos = TRUE;
3878 return data->ret == GST_FLOW_OK;
3881 /* check sticky events and push them when needed. should be called
3883 static inline GstFlowReturn
3884 check_sticky (GstPad * pad, GstEvent * event)
3886 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3888 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3889 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3891 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3892 events_foreach (pad, push_sticky, &data);
3894 /* If there's an EOS event we must push it downstream
3895 * even if sending a previous sticky event failed.
3896 * Otherwise the pipeline might wait forever for EOS.
3898 * Only do this if pushing another event than the EOS
3901 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3902 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3904 if (ev && !ev->received) {
3905 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3906 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3907 /* the event could have been dropped. Because this can only
3908 * happen if the user asked for it, it's not an error */
3909 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3910 data.ret = GST_FLOW_OK;
3920 * @pad: a #GstPad to invoke the default query on.
3921 * @query: (transfer none): the #GstQuery to perform.
3923 * Dispatches a query to a pad. The query should have been allocated by the
3924 * caller via one of the type-specific allocation functions. The element that
3925 * the pad belongs to is responsible for filling the query with an appropriate
3926 * response, which should then be parsed with a type-specific query parsing
3929 * Again, the caller is responsible for both the allocation and deallocation of
3930 * the query structure.
3932 * Please also note that some queries might need a running pipeline to work.
3934 * Returns: %TRUE if the query could be performed.
3937 gst_pad_query (GstPad * pad, GstQuery * query)
3940 gboolean res, serialized;
3941 GstPadQueryFunction func;
3942 GstPadProbeType type;
3945 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3946 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3948 if (GST_PAD_IS_SRC (pad)) {
3949 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3950 goto wrong_direction;
3951 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3952 } else if (GST_PAD_IS_SINK (pad)) {
3953 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3954 goto wrong_direction;
3955 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3957 goto unknown_direction;
3959 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3960 GST_QUERY_TYPE_NAME (query));
3961 GST_TRACER_PAD_QUERY_PRE (pad, query);
3963 serialized = GST_QUERY_IS_SERIALIZED (query);
3964 if (G_UNLIKELY (serialized))
3965 GST_PAD_STREAM_LOCK (pad);
3967 GST_OBJECT_LOCK (pad);
3968 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3969 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3970 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3972 ACQUIRE_PARENT (pad, parent, no_parent);
3973 GST_OBJECT_UNLOCK (pad);
3975 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3978 res = func (pad, parent, query);
3980 RELEASE_PARENT (parent);
3982 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3983 GST_QUERY_TYPE_NAME (query), res);
3984 GST_TRACER_PAD_QUERY_POST (pad, query, res);
3989 GST_OBJECT_LOCK (pad);
3990 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3991 GST_OBJECT_UNLOCK (pad);
3993 if (G_UNLIKELY (serialized))
3994 GST_PAD_STREAM_UNLOCK (pad);
4001 g_warning ("pad %s:%s query %s in wrong direction",
4002 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4007 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4012 GST_DEBUG_OBJECT (pad, "had no parent");
4013 GST_OBJECT_UNLOCK (pad);
4014 if (G_UNLIKELY (serialized))
4015 GST_PAD_STREAM_UNLOCK (pad);
4020 GST_DEBUG_OBJECT (pad, "had no query function");
4021 RELEASE_PARENT (parent);
4022 if (G_UNLIKELY (serialized))
4023 GST_PAD_STREAM_UNLOCK (pad);
4028 GST_DEBUG_OBJECT (pad, "query failed");
4029 if (G_UNLIKELY (serialized))
4030 GST_PAD_STREAM_UNLOCK (pad);
4035 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4036 GST_OBJECT_UNLOCK (pad);
4037 if (G_UNLIKELY (serialized))
4038 GST_PAD_STREAM_UNLOCK (pad);
4040 /* if a probe dropped without handling, we don't sent it further but assume
4041 * that the probe did not answer the query and return FALSE */
4042 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4052 * gst_pad_peer_query:
4053 * @pad: a #GstPad to invoke the peer query on.
4054 * @query: (transfer none): the #GstQuery to perform.
4056 * Performs gst_pad_query() on the peer of @pad.
4058 * The caller is responsible for both the allocation and deallocation of
4059 * the query structure.
4061 * Returns: %TRUE if the query could be performed. This function returns %FALSE
4062 * if @pad has no peer.
4065 gst_pad_peer_query (GstPad * pad, GstQuery * query)
4068 GstPadProbeType type;
4069 gboolean res, serialized;
4072 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4073 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
4075 if (GST_PAD_IS_SRC (pad)) {
4076 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
4077 goto wrong_direction;
4078 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
4079 } else if (GST_PAD_IS_SINK (pad)) {
4080 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
4081 goto wrong_direction;
4082 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
4084 goto unknown_direction;
4086 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
4087 GST_QUERY_TYPE_NAME (query));
4089 serialized = GST_QUERY_IS_SERIALIZED (query);
4091 GST_OBJECT_LOCK (pad);
4092 if (GST_PAD_IS_SRC (pad) && serialized) {
4093 /* all serialized queries on the srcpad trigger push of
4095 if (check_sticky (pad, NULL) != GST_FLOW_OK)
4099 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4100 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
4101 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
4103 peerpad = GST_PAD_PEER (pad);
4104 if (G_UNLIKELY (peerpad == NULL))
4107 gst_object_ref (peerpad);
4108 GST_OBJECT_UNLOCK (pad);
4110 res = gst_pad_query (peerpad, query);
4112 gst_object_unref (peerpad);
4117 GST_OBJECT_LOCK (pad);
4118 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
4119 GST_OBJECT_UNLOCK (pad);
4126 g_warning ("pad %s:%s query %s in wrong direction",
4127 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
4132 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4137 GST_WARNING_OBJECT (pad, "could not send sticky events");
4138 GST_OBJECT_UNLOCK (pad);
4143 GST_INFO_OBJECT (pad, "pad has no peer");
4144 GST_OBJECT_UNLOCK (pad);
4149 GST_DEBUG_OBJECT (pad, "query failed");
4154 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4155 GST_OBJECT_UNLOCK (pad);
4157 /* if a probe dropped without handling, we don't sent it further but
4158 * assume that the probe did not answer the query and return FALSE */
4159 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4168 /**********************************************************************
4169 * Data passing functions
4172 /* this is the chain function that does not perform the additional argument
4173 * checking for that little extra speed.
4175 static inline GstFlowReturn
4176 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4180 gboolean handled = FALSE;
4182 GST_PAD_STREAM_LOCK (pad);
4184 GST_OBJECT_LOCK (pad);
4185 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4188 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4191 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4194 #ifdef GST_ENABLE_EXTRA_CHECKS
4195 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4196 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4198 ":%s:<%s:%s> Got data flow before stream-start event",
4199 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4201 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4203 ":%s:<%s:%s> Got data flow before segment event",
4204 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4206 pad->priv->last_cookie = pad->priv->events_cookie;
4210 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4213 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4215 ACQUIRE_PARENT (pad, parent, no_parent);
4216 GST_OBJECT_UNLOCK (pad);
4218 /* NOTE: we read the chainfunc unlocked.
4219 * we cannot hold the lock for the pad so we might send
4220 * the data to the wrong function. This is not really a
4221 * problem since functions are assigned at creation time
4222 * and don't change that often... */
4223 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4224 GstPadChainFunction chainfunc;
4226 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4229 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4230 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4231 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4233 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4235 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4236 "called chainfunction &%s with buffer %p, returned %s",
4237 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4239 GstPadChainListFunction chainlistfunc;
4241 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4244 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4245 "calling chainlistfunction &%s",
4246 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4248 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4250 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4251 "called chainlistfunction &%s, returned %s",
4252 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4255 RELEASE_PARENT (parent);
4257 GST_PAD_STREAM_UNLOCK (pad);
4264 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4265 "chaining, but pad was flushing");
4266 GST_OBJECT_UNLOCK (pad);
4267 GST_PAD_STREAM_UNLOCK (pad);
4268 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4269 return GST_FLOW_FLUSHING;
4273 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4274 GST_OBJECT_UNLOCK (pad);
4275 GST_PAD_STREAM_UNLOCK (pad);
4276 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4277 return GST_FLOW_EOS;
4281 g_critical ("chain on pad %s:%s but it was not in push mode",
4282 GST_DEBUG_PAD_NAME (pad));
4283 GST_OBJECT_UNLOCK (pad);
4284 GST_PAD_STREAM_UNLOCK (pad);
4285 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4286 return GST_FLOW_ERROR;
4293 GST_OBJECT_UNLOCK (pad);
4294 GST_PAD_STREAM_UNLOCK (pad);
4295 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4297 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4300 case GST_FLOW_CUSTOM_SUCCESS:
4301 case GST_FLOW_CUSTOM_SUCCESS_1:
4302 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4306 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4313 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4314 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4315 GST_OBJECT_UNLOCK (pad);
4316 GST_PAD_STREAM_UNLOCK (pad);
4317 return GST_FLOW_FLUSHING;
4321 RELEASE_PARENT (parent);
4322 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4323 g_critical ("chain on pad %s:%s but it has no chainfunction",
4324 GST_DEBUG_PAD_NAME (pad));
4325 GST_PAD_STREAM_UNLOCK (pad);
4326 return GST_FLOW_NOT_SUPPORTED;
4332 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4333 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4336 * Chain a buffer to @pad.
4338 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4340 * If the buffer type is not acceptable for @pad (as negotiated with a
4341 * preceding GST_EVENT_CAPS event), this function returns
4342 * #GST_FLOW_NOT_NEGOTIATED.
4344 * The function proceeds calling the chain function installed on @pad (see
4345 * gst_pad_set_chain_function()) and the return value of that function is
4346 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4349 * In all cases, success or failure, the caller loses its reference to @buffer
4350 * after calling this function.
4352 * Returns: a #GstFlowReturn from the pad.
4357 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4359 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4360 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4361 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4363 return gst_pad_chain_data_unchecked (pad,
4364 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4367 static GstFlowReturn
4368 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4369 GstBufferList * list)
4375 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4377 len = gst_buffer_list_length (list);
4380 for (i = 0; i < len; i++) {
4381 buffer = gst_buffer_list_get (list, i);
4383 gst_pad_chain_data_unchecked (pad,
4384 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4385 gst_buffer_ref (buffer));
4386 if (ret != GST_FLOW_OK)
4389 gst_buffer_list_unref (list);
4395 * gst_pad_chain_list:
4396 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4397 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4400 * Chain a bufferlist to @pad.
4402 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4404 * If @pad was not negotiated properly with a CAPS event, this function
4405 * returns #GST_FLOW_NOT_NEGOTIATED.
4407 * The function proceeds calling the chainlist function installed on @pad (see
4408 * gst_pad_set_chain_list_function()) and the return value of that function is
4409 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4410 * chainlist function.
4412 * In all cases, success or failure, the caller loses its reference to @list
4413 * after calling this function.
4417 * Returns: a #GstFlowReturn from the pad.
4420 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4422 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4423 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4424 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4426 return gst_pad_chain_data_unchecked (pad,
4427 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4430 static GstFlowReturn
4431 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4435 gboolean handled = FALSE;
4437 GST_OBJECT_LOCK (pad);
4438 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4441 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4444 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4447 #ifdef GST_ENABLE_EXTRA_CHECKS
4448 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4449 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4451 ":%s:<%s:%s> Got data flow before stream-start event",
4452 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4454 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4456 ":%s:<%s:%s> Got data flow before segment event",
4457 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4459 pad->priv->last_cookie = pad->priv->events_cookie;
4463 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4466 /* do block probes */
4467 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4470 /* recheck sticky events because the probe might have cause a relink */
4471 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4474 /* do post-blocking probes */
4475 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4477 /* recheck sticky events because the probe might have cause a relink */
4478 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4481 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4484 /* take ref to peer pad before releasing the lock */
4485 gst_object_ref (peer);
4487 GST_OBJECT_UNLOCK (pad);
4489 ret = gst_pad_chain_data_unchecked (peer, type, data);
4492 gst_object_unref (peer);
4494 GST_OBJECT_LOCK (pad);
4495 pad->ABI.abi.last_flowret = ret;
4497 if (pad->priv->using == 0) {
4498 /* pad is not active anymore, trigger idle callbacks */
4499 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4500 probe_stopped, ret);
4502 GST_OBJECT_UNLOCK (pad);
4506 /* ERROR recovery here */
4510 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4511 "pushing, but pad was flushing");
4512 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4513 GST_OBJECT_UNLOCK (pad);
4514 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4515 return GST_FLOW_FLUSHING;
4519 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4520 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4521 GST_OBJECT_UNLOCK (pad);
4522 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4523 return GST_FLOW_EOS;
4527 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4528 GST_DEBUG_PAD_NAME (pad));
4529 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4530 GST_OBJECT_UNLOCK (pad);
4531 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4532 return GST_FLOW_ERROR;
4536 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4537 "error pushing events, return %s", gst_flow_get_name (ret));
4538 pad->ABI.abi.last_flowret = ret;
4539 GST_OBJECT_UNLOCK (pad);
4540 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4548 GST_OBJECT_UNLOCK (pad);
4549 if (data != NULL && !handled)
4550 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4553 case GST_FLOW_CUSTOM_SUCCESS:
4554 case GST_FLOW_CUSTOM_SUCCESS_1:
4555 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4559 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4562 pad->ABI.abi.last_flowret = ret;
4567 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4568 "pushing, but it was not linked");
4569 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4570 GST_OBJECT_UNLOCK (pad);
4571 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4572 return GST_FLOW_NOT_LINKED;
4578 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4579 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4582 * Pushes a buffer to the peer of @pad.
4584 * This function will call installed block probes before triggering any
4585 * installed data probes.
4587 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4588 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4591 * In all cases, success or failure, the caller loses its reference to @buffer
4592 * after calling this function.
4594 * Returns: a #GstFlowReturn from the peer pad.
4599 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4603 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4604 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4605 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4607 GST_TRACER_PAD_PUSH_PRE (pad, buffer);
4608 res = gst_pad_push_data (pad,
4609 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4610 GST_TRACER_PAD_PUSH_POST (pad, res);
4615 * gst_pad_push_list:
4616 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4617 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4620 * Pushes a buffer list to the peer of @pad.
4622 * This function will call installed block probes before triggering any
4623 * installed data probes.
4625 * The function proceeds calling the chain function on the peer pad and returns
4626 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4627 * be returned. If the peer pad does not have any installed chainlist function
4628 * every group buffer of the list will be merged into a normal #GstBuffer and
4629 * chained via gst_pad_chain().
4631 * In all cases, success or failure, the caller loses its reference to @list
4632 * after calling this function.
4634 * Returns: a #GstFlowReturn from the peer pad.
4639 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4643 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4644 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4645 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4647 GST_TRACER_PAD_PUSH_LIST_PRE (pad, list);
4648 res = gst_pad_push_data (pad,
4649 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4650 GST_TRACER_PAD_PUSH_LIST_POST (pad, res);
4654 static GstFlowReturn
4655 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4656 GstBuffer ** buffer)
4659 GstPadGetRangeFunction getrangefunc;
4663 GST_PAD_STREAM_LOCK (pad);
4665 GST_OBJECT_LOCK (pad);
4666 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4669 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4672 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4677 /* when one of the probes returns DROPPED, probe_stopped will be called
4678 * and we skip calling the getrange function, res_buf should then contain a
4679 * valid result buffer */
4680 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4681 res_buf, offset, size, probe_stopped);
4683 /* recheck sticky events because the probe might have cause a relink */
4684 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4687 ACQUIRE_PARENT (pad, parent, no_parent);
4688 GST_OBJECT_UNLOCK (pad);
4690 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4693 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4694 "calling getrangefunc %s, offset %"
4695 G_GUINT64_FORMAT ", size %u",
4696 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4698 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4700 RELEASE_PARENT (parent);
4702 GST_OBJECT_LOCK (pad);
4703 if (G_UNLIKELY (ret != GST_FLOW_OK))
4704 goto get_range_failed;
4706 /* can only fire the signal if we have a valid buffer */
4708 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4709 res_buf, offset, size, probe_stopped_unref);
4710 pad->ABI.abi.last_flowret = ret;
4711 GST_OBJECT_UNLOCK (pad);
4713 GST_PAD_STREAM_UNLOCK (pad);
4722 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4723 "getrange, but pad was flushing");
4724 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4725 GST_OBJECT_UNLOCK (pad);
4726 GST_PAD_STREAM_UNLOCK (pad);
4727 return GST_FLOW_FLUSHING;
4731 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4732 GST_DEBUG_PAD_NAME (pad));
4733 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4734 GST_OBJECT_UNLOCK (pad);
4735 GST_PAD_STREAM_UNLOCK (pad);
4736 return GST_FLOW_ERROR;
4740 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4741 pad->ABI.abi.last_flowret = ret;
4742 GST_OBJECT_UNLOCK (pad);
4743 GST_PAD_STREAM_UNLOCK (pad);
4748 GST_DEBUG_OBJECT (pad, "no parent");
4749 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4750 GST_OBJECT_UNLOCK (pad);
4751 GST_PAD_STREAM_UNLOCK (pad);
4752 return GST_FLOW_FLUSHING;
4756 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4757 GST_DEBUG_PAD_NAME (pad));
4758 RELEASE_PARENT (parent);
4759 GST_PAD_STREAM_UNLOCK (pad);
4760 return GST_FLOW_NOT_SUPPORTED;
4764 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4765 "probe returned %s", gst_flow_get_name (ret));
4766 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4768 /* the probe filled the buffer and asks us to not call the getrange
4769 * anymore, we continue with the post probes then. */
4770 GST_DEBUG_OBJECT (pad, "handled buffer");
4774 /* no buffer, we are EOS */
4775 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4779 pad->ABI.abi.last_flowret = ret;
4780 GST_OBJECT_UNLOCK (pad);
4781 GST_PAD_STREAM_UNLOCK (pad);
4785 probe_stopped_unref:
4787 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4788 "probe returned %s", gst_flow_get_name (ret));
4789 /* if we drop here, it signals EOS */
4790 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4792 pad->ABI.abi.last_flowret = ret;
4793 GST_OBJECT_UNLOCK (pad);
4794 GST_PAD_STREAM_UNLOCK (pad);
4795 if (*buffer == NULL)
4796 gst_buffer_unref (res_buf);
4801 pad->ABI.abi.last_flowret = ret;
4802 GST_OBJECT_UNLOCK (pad);
4803 GST_PAD_STREAM_UNLOCK (pad);
4804 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4805 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4806 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4812 * gst_pad_get_range:
4813 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4814 * @offset: The start offset of the buffer
4815 * @size: The length of the buffer
4816 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4817 * returns #GST_FLOW_ERROR if %NULL.
4819 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4820 * immediately and @buffer is %NULL.
4822 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4823 * description of a getrange function. If @pad has no getrange function
4824 * installed (see gst_pad_set_getrange_function()) this function returns
4825 * #GST_FLOW_NOT_SUPPORTED.
4827 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4828 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4829 * must be freed with gst_buffer_unref() after usage.
4831 * When @buffer points to a variable that points to a valid #GstBuffer, the
4832 * buffer will be filled with the result data when this function returns
4833 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4834 * @size bytes will be filled in the result buffer and its size will be updated
4837 * Note that less than @size bytes can be returned in @buffer when, for example,
4838 * an EOS condition is near or when @buffer is not large enough to hold @size
4839 * bytes. The caller should check the result buffer size to get the result size.
4841 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4842 * will be unchanged.
4844 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4846 * Returns: a #GstFlowReturn from the pad.
4851 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4852 GstBuffer ** buffer)
4854 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4855 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4856 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4857 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4858 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4860 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4864 * gst_pad_pull_range:
4865 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4866 * @offset: The start offset of the buffer
4867 * @size: The length of the buffer
4868 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4869 * GST_FLOW_ERROR if %NULL.
4871 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4873 * This function will first trigger the pad block signal if it was
4876 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4877 * function returns the result of gst_pad_get_range() on the peer pad.
4878 * See gst_pad_get_range() for a list of return values and for the
4879 * semantics of the arguments of this function.
4881 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4882 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4883 * must be freed with gst_buffer_unref() after usage. When this function
4884 * returns any other result value, @buffer will still point to %NULL.
4886 * When @buffer points to a variable that points to a valid #GstBuffer, the
4887 * buffer will be filled with the result data when this function returns
4888 * #GST_FLOW_OK. When this function returns any other result value,
4889 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4890 * @size bytes will be filled in the result buffer and its size will be updated
4893 * Note that less than @size bytes can be returned in @buffer when, for example,
4894 * an EOS condition is near or when @buffer is not large enough to hold @size
4895 * bytes. The caller should check the result buffer size to get the result size.
4897 * Returns: a #GstFlowReturn from the peer pad.
4902 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4903 GstBuffer ** buffer)
4909 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4910 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4911 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4912 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4913 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4915 GST_TRACER_PAD_PULL_RANGE_PRE (pad, offset, size);
4917 GST_OBJECT_LOCK (pad);
4918 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4921 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4926 /* when one of the probes returns DROPPED, probe_stopped will be
4927 * called and we skip calling the peer getrange function. *buffer should then
4928 * contain a valid buffer */
4929 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4930 res_buf, offset, size, probe_stopped);
4932 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4935 gst_object_ref (peer);
4937 GST_OBJECT_UNLOCK (pad);
4939 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4941 gst_object_unref (peer);
4943 GST_OBJECT_LOCK (pad);
4945 pad->ABI.abi.last_flowret = ret;
4946 if (pad->priv->using == 0) {
4947 /* pad is not active anymore, trigger idle callbacks */
4948 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4949 probe_stopped_unref, ret);
4952 if (G_UNLIKELY (ret != GST_FLOW_OK))
4953 goto pull_range_failed;
4956 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4957 res_buf, offset, size, probe_stopped_unref);
4959 GST_OBJECT_UNLOCK (pad);
4963 GST_TRACER_PAD_PULL_RANGE_POST (pad, *buffer, ret);
4966 /* ERROR recovery here */
4969 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4970 "pullrange, but pad was flushing");
4971 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4972 GST_OBJECT_UNLOCK (pad);
4973 ret = GST_FLOW_FLUSHING;
4978 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4979 GST_DEBUG_PAD_NAME (pad));
4980 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4981 GST_OBJECT_UNLOCK (pad);
4982 ret = GST_FLOW_ERROR;
4987 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4988 gst_flow_get_name (ret));
4989 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4991 /* the probe filled the buffer and asks us to not forward to the peer
4992 * anymore, we continue with the post probes then */
4993 GST_DEBUG_OBJECT (pad, "handled buffer");
4997 /* no buffer, we are EOS then */
4998 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
5002 pad->ABI.abi.last_flowret = ret;
5003 GST_OBJECT_UNLOCK (pad);
5008 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5009 "pulling range, but it was not linked");
5010 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
5011 GST_OBJECT_UNLOCK (pad);
5012 ret = GST_FLOW_NOT_LINKED;
5017 pad->ABI.abi.last_flowret = ret;
5018 GST_OBJECT_UNLOCK (pad);
5019 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
5020 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
5021 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
5024 probe_stopped_unref:
5026 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
5027 "post probe returned %s", gst_flow_get_name (ret));
5029 /* if we drop here, it signals EOS */
5030 if (ret == GST_FLOW_CUSTOM_SUCCESS)
5033 pad->ABI.abi.last_flowret = ret;
5034 GST_OBJECT_UNLOCK (pad);
5036 if (*buffer == NULL)
5037 gst_buffer_unref (res_buf);
5041 GST_TRACER_PAD_PULL_RANGE_POST (pad, NULL, ret);
5045 /* must be called with pad object lock */
5046 static GstFlowReturn
5047 store_sticky_event (GstPad * pad, GstEvent * event)
5052 gboolean res = FALSE;
5053 const gchar *name = NULL;
5054 gboolean insert = TRUE;
5056 type = GST_EVENT_TYPE (event);
5058 /* Store all sticky events except SEGMENT/EOS when we're flushing,
5059 * otherwise they can be dropped and nothing would ever resend them.
5060 * Only do that for activated pads though, everything else is a bug!
5062 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
5063 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
5064 || type == GST_EVENT_EOS))))
5067 /* Unset the EOS flag when received STREAM_START event, so pad can
5068 * store sticky event and then push it later */
5069 if (type == GST_EVENT_STREAM_START) {
5070 GST_LOG_OBJECT (pad, "Removing pending EOS and StreamGroupDone events");
5071 remove_event_by_type (pad, GST_EVENT_EOS);
5072 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5073 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5076 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5079 if (type & GST_EVENT_TYPE_STICKY_MULTI)
5080 name = gst_structure_get_name (gst_event_get_structure (event));
5082 events = pad->priv->events;
5085 for (i = 0; i < len; i++) {
5086 PadEvent *ev = &g_array_index (events, PadEvent, i);
5088 if (ev->event == NULL)
5091 if (type == GST_EVENT_TYPE (ev->event)) {
5092 /* matching types, check matching name if needed */
5093 if (name && !gst_event_has_name (ev->event, name))
5097 if ((res = gst_event_replace (&ev->event, event)))
5098 ev->received = FALSE;
5104 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
5105 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
5106 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
5107 * storing the sticky ordered we can check that this is respected. */
5108 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
5109 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
5111 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
5112 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
5113 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
5114 gst_event_type_get_name (type));
5120 ev.event = gst_event_ref (event);
5121 ev.received = FALSE;
5122 g_array_insert_val (events, i, ev);
5127 pad->priv->events_cookie++;
5128 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5130 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
5132 switch (GST_EVENT_TYPE (event)) {
5133 case GST_EVENT_CAPS:
5134 GST_OBJECT_UNLOCK (pad);
5136 GST_DEBUG_OBJECT (pad, "notify caps");
5137 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
5139 GST_OBJECT_LOCK (pad);
5145 if (type == GST_EVENT_EOS) {
5146 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
5147 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
5150 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
5155 GST_DEBUG_OBJECT (pad, "pad is flushing");
5156 return GST_FLOW_FLUSHING;
5160 GST_DEBUG_OBJECT (pad, "pad is EOS");
5161 return GST_FLOW_EOS;
5166 * gst_pad_store_sticky_event:
5168 * @event: (transfer none): a #GstEvent
5170 * Store the sticky @event on @pad
5172 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
5173 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5178 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5182 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5183 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5185 GST_OBJECT_LOCK (pad);
5186 ret = store_sticky_event (pad, event);
5187 GST_OBJECT_UNLOCK (pad);
5193 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5195 PushStickyData *data = user_data;
5197 /* Forward all sticky events before our current one that are pending */
5198 if (ev->event != data->event
5199 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5200 return push_sticky (pad, ev, data);
5205 /* should be called with pad LOCK */
5206 static GstFlowReturn
5207 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5208 GstPadProbeType type)
5212 GstEventType event_type;
5214 /* pass the adjusted event on. We need to do this even if
5215 * there is no peer pad because of the probes. */
5216 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5218 /* Two checks to be made:
5219 * . (un)set the FLUSHING flag for flushing events,
5220 * . handle pad blocking */
5221 event_type = GST_EVENT_TYPE (event);
5222 switch (event_type) {
5223 case GST_EVENT_FLUSH_START:
5224 GST_PAD_SET_FLUSHING (pad);
5226 GST_PAD_BLOCK_BROADCAST (pad);
5227 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5229 case GST_EVENT_FLUSH_STOP:
5230 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5233 GST_PAD_UNSET_FLUSHING (pad);
5235 /* Remove sticky EOS events */
5236 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5237 remove_event_by_type (pad, GST_EVENT_EOS);
5238 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5239 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5240 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5241 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5243 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5247 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5250 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5251 * checked already or this is called as part of pushing sticky events,
5252 * in which case we still want to forward the EOS event downstream.
5255 switch (GST_EVENT_TYPE (event)) {
5256 case GST_EVENT_RECONFIGURE:
5257 if (GST_PAD_IS_SINK (pad))
5258 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5263 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5264 GST_PAD_PROBE_TYPE_BLOCK, 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);
5280 /* send probes after modifying the events above */
5281 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5283 /* recheck sticky events because the probe might have cause a relink */
5284 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5285 && (GST_EVENT_IS_SERIALIZED (event)
5286 || GST_EVENT_IS_STICKY (event))) {
5287 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5288 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5290 /* Push all sticky events before our current one
5291 * that have changed */
5292 events_foreach (pad, sticky_changed, &data);
5295 /* now check the peer pad */
5296 peerpad = GST_PAD_PEER (pad);
5297 if (peerpad == NULL)
5300 gst_object_ref (peerpad);
5302 GST_OBJECT_UNLOCK (pad);
5304 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5305 event, gst_event_type_get_name (event_type), peerpad);
5307 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5309 /* Note: we gave away ownership of the event at this point but we can still
5310 * print the old pointer */
5311 GST_LOG_OBJECT (pad,
5312 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5313 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5315 gst_object_unref (peerpad);
5317 GST_OBJECT_LOCK (pad);
5319 if (pad->priv->using == 0) {
5320 /* pad is not active anymore, trigger idle callbacks */
5321 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5322 idle_probe_stopped, ret);
5326 /* ERROR handling */
5329 GST_DEBUG_OBJECT (pad, "We're flushing");
5330 gst_event_unref (event);
5331 return GST_FLOW_FLUSHING;
5335 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5336 gst_event_unref (event);
5337 return GST_FLOW_FLUSHING;
5341 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5342 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5343 gst_event_unref (event);
5346 case GST_FLOW_CUSTOM_SUCCESS_1:
5347 GST_DEBUG_OBJECT (pad, "handled event");
5349 case GST_FLOW_CUSTOM_SUCCESS:
5350 GST_DEBUG_OBJECT (pad, "dropped event");
5353 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5360 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5361 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5362 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5363 gst_event_unref (event);
5365 /* unlinked pads should not influence latency configuration */
5366 if (event_type == GST_EVENT_LATENCY)
5369 return GST_FLOW_NOT_LINKED;
5373 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5379 * gst_pad_push_event:
5380 * @pad: a #GstPad to push the event to.
5381 * @event: (transfer full): the #GstEvent to send to the pad.
5383 * Sends the event to the peer of the given pad. This function is
5384 * mainly used by elements to send events to their peer
5387 * This function takes ownership of the provided event so you should
5388 * gst_event_ref() it if you want to reuse the event after this call.
5390 * Returns: %TRUE if the event was handled.
5395 gst_pad_push_event (GstPad * pad, GstEvent * event)
5397 gboolean res = FALSE;
5398 GstPadProbeType type;
5399 gboolean sticky, serialized;
5401 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5402 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5404 GST_TRACER_PAD_PUSH_EVENT_PRE (pad, event);
5406 if (GST_PAD_IS_SRC (pad)) {
5407 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5408 goto wrong_direction;
5409 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5410 } else if (GST_PAD_IS_SINK (pad)) {
5411 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5412 goto wrong_direction;
5413 /* events pushed on sinkpad never are sticky */
5414 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5416 goto unknown_direction;
5418 GST_OBJECT_LOCK (pad);
5419 sticky = GST_EVENT_IS_STICKY (event);
5420 serialized = GST_EVENT_IS_SERIALIZED (event);
5423 /* srcpad sticky events are stored immediately, the received flag is set
5424 * to FALSE and will be set to TRUE when we can successfully push the
5425 * event to the peer pad */
5426 switch (store_sticky_event (pad, event)) {
5427 case GST_FLOW_FLUSHING:
5435 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5436 /* all serialized or sticky events on the srcpad trigger push of
5438 res = (check_sticky (pad, event) == GST_FLOW_OK);
5443 /* other events are pushed right away */
5444 ret = gst_pad_push_event_unchecked (pad, event, type);
5445 /* dropped events by a probe are not an error */
5446 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5447 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5449 /* Errors in sticky event pushing are no problem and ignored here
5450 * as they will cause more meaningful errors during data flow.
5451 * For EOS events, that are not followed by data flow, we still
5452 * return FALSE here though.
5454 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5456 gst_event_unref (event);
5458 GST_OBJECT_UNLOCK (pad);
5460 GST_TRACER_PAD_PUSH_EVENT_POST (pad, res);
5463 /* ERROR handling */
5466 g_warning ("pad %s:%s pushing %s event in wrong direction",
5467 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5468 gst_event_unref (event);
5473 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5474 gst_event_unref (event);
5479 GST_DEBUG_OBJECT (pad, "We're flushing");
5480 GST_OBJECT_UNLOCK (pad);
5481 gst_event_unref (event);
5486 GST_DEBUG_OBJECT (pad, "We're EOS");
5487 GST_OBJECT_UNLOCK (pad);
5488 gst_event_unref (event);
5492 GST_TRACER_PAD_PUSH_EVENT_POST (pad, FALSE);
5496 /* Check if we can call the event function with the given event */
5497 static GstFlowReturn
5498 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5502 switch (GST_EVENT_TYPE (event)) {
5503 case GST_EVENT_CAPS:
5505 /* backwards compatibility mode for caps */
5506 gst_event_parse_caps (event, &caps);
5508 if (!gst_pad_query_accept_caps (pad, caps))
5520 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5521 "caps %" GST_PTR_FORMAT " not accepted", caps);
5522 return GST_FLOW_NOT_NEGOTIATED;
5526 static GstFlowReturn
5527 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5528 GstPadProbeType type)
5531 GstEventType event_type;
5532 gboolean serialized, need_unlock = FALSE, sticky;
5533 GstPadEventFunction eventfunc;
5534 GstPadEventFullFunction eventfullfunc = NULL;
5537 GST_OBJECT_LOCK (pad);
5539 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5541 if (GST_PAD_IS_SINK (pad))
5542 serialized = GST_EVENT_IS_SERIALIZED (event);
5545 sticky = GST_EVENT_IS_STICKY (event);
5546 event_type = GST_EVENT_TYPE (event);
5547 switch (event_type) {
5548 case GST_EVENT_FLUSH_START:
5549 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5550 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5552 /* can't even accept a flush begin event when flushing */
5553 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5556 GST_PAD_SET_FLUSHING (pad);
5557 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5558 GST_PAD_BLOCK_BROADCAST (pad);
5559 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5561 case GST_EVENT_FLUSH_STOP:
5562 /* we can't accept flush-stop on inactive pads else the flushing flag
5563 * would be cleared and it would look like the pad can accept data.
5564 * Also, some elements restart a streaming thread in flush-stop which we
5565 * can't allow on inactive pads */
5566 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5569 GST_PAD_UNSET_FLUSHING (pad);
5570 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5571 /* Remove pending EOS events */
5572 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5573 remove_event_by_type (pad, GST_EVENT_EOS);
5574 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5575 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5576 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5577 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5579 GST_OBJECT_UNLOCK (pad);
5580 /* grab stream lock */
5581 GST_PAD_STREAM_LOCK (pad);
5583 GST_OBJECT_LOCK (pad);
5584 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5587 case GST_EVENT_RECONFIGURE:
5588 if (GST_PAD_IS_SRC (pad))
5589 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5591 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5592 "have event type %" GST_PTR_FORMAT, event);
5594 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5597 switch (event_type) {
5598 case GST_EVENT_STREAM_START:
5599 /* Remove sticky EOS events */
5600 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5601 remove_event_by_type (pad, GST_EVENT_EOS);
5602 remove_event_by_type (pad, GST_EVENT_STREAM_GROUP_DONE);
5603 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5610 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5613 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5614 GST_OBJECT_UNLOCK (pad);
5615 GST_PAD_STREAM_LOCK (pad);
5617 GST_OBJECT_LOCK (pad);
5618 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5621 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5627 /* now do the probe */
5629 type | GST_PAD_PROBE_TYPE_PUSH |
5630 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5632 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5634 eventfullfunc = GST_PAD_EVENTFULLFUNC (pad);
5635 eventfunc = GST_PAD_EVENTFUNC (pad);
5636 if (G_UNLIKELY (eventfunc == NULL && eventfullfunc == NULL))
5639 ACQUIRE_PARENT (pad, parent, no_parent);
5640 GST_OBJECT_UNLOCK (pad);
5642 ret = pre_eventfunc_check (pad, event);
5643 if (G_UNLIKELY (ret != GST_FLOW_OK))
5644 goto precheck_failed;
5647 gst_event_ref (event);
5649 if (eventfullfunc) {
5650 ret = eventfullfunc (pad, parent, event);
5651 } else if (eventfunc (pad, parent, event)) {
5654 /* something went wrong */
5655 switch (event_type) {
5656 case GST_EVENT_CAPS:
5657 ret = GST_FLOW_NOT_NEGOTIATED;
5660 ret = GST_FLOW_ERROR;
5664 RELEASE_PARENT (parent);
5666 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5669 if (ret == GST_FLOW_OK) {
5670 GST_OBJECT_LOCK (pad);
5671 /* after the event function accepted the event, we can store the sticky
5672 * event on the pad */
5673 switch (store_sticky_event (pad, event)) {
5674 case GST_FLOW_FLUSHING:
5681 GST_OBJECT_UNLOCK (pad);
5683 gst_event_unref (event);
5687 GST_PAD_STREAM_UNLOCK (pad);
5691 /* ERROR handling */
5694 GST_OBJECT_UNLOCK (pad);
5696 GST_PAD_STREAM_UNLOCK (pad);
5697 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5698 "Received event on flushing pad. Discarding");
5699 gst_event_unref (event);
5700 return GST_FLOW_FLUSHING;
5704 GST_OBJECT_UNLOCK (pad);
5706 GST_PAD_STREAM_UNLOCK (pad);
5707 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5708 "Received flush-stop on inactive pad. Discarding");
5709 gst_event_unref (event);
5710 return GST_FLOW_FLUSHING;
5714 GST_OBJECT_UNLOCK (pad);
5716 GST_PAD_STREAM_UNLOCK (pad);
5717 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5718 "Received event on EOS pad. Discarding");
5719 gst_event_unref (event);
5720 return GST_FLOW_EOS;
5724 GST_OBJECT_UNLOCK (pad);
5726 GST_PAD_STREAM_UNLOCK (pad);
5727 /* Only unref if unhandled */
5728 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5729 gst_event_unref (event);
5732 case GST_FLOW_CUSTOM_SUCCESS_1:
5733 case GST_FLOW_CUSTOM_SUCCESS:
5734 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5738 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5745 g_warning ("pad %s:%s has no event handler, file a bug.",
5746 GST_DEBUG_PAD_NAME (pad));
5747 GST_OBJECT_UNLOCK (pad);
5749 GST_PAD_STREAM_UNLOCK (pad);
5750 gst_event_unref (event);
5751 return GST_FLOW_NOT_SUPPORTED;
5755 GST_DEBUG_OBJECT (pad, "no parent");
5756 GST_OBJECT_UNLOCK (pad);
5758 GST_PAD_STREAM_UNLOCK (pad);
5759 gst_event_unref (event);
5760 return GST_FLOW_FLUSHING;
5764 GST_DEBUG_OBJECT (pad, "pre event check failed");
5765 RELEASE_PARENT (parent);
5767 GST_PAD_STREAM_UNLOCK (pad);
5768 gst_event_unref (event);
5774 * gst_pad_send_event:
5775 * @pad: a #GstPad to send the event to.
5776 * @event: (transfer full): the #GstEvent to send to the pad.
5778 * Sends the event to the pad. This function can be used
5779 * by applications to send events in the pipeline.
5781 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5782 * sink pad, @event should be a downstream event. For example, you would not
5783 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5784 * Furthermore, some downstream events have to be serialized with data flow,
5785 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5786 * the event needs to be serialized with data flow, this function will take the
5787 * pad's stream lock while calling its event function.
5789 * To find out whether an event type is upstream, downstream, or downstream and
5790 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5791 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5792 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5793 * plugin doesn't need to bother itself with this information; the core handles
5794 * all necessary locks and checks.
5796 * This function takes ownership of the provided event so you should
5797 * gst_event_ref() it if you want to reuse the event after this call.
5799 * Returns: %TRUE if the event was handled.
5802 gst_pad_send_event (GstPad * pad, GstEvent * event)
5805 GstPadProbeType type;
5807 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5808 g_return_val_if_fail (event != NULL, FALSE);
5810 if (GST_PAD_IS_SINK (pad)) {
5811 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5812 goto wrong_direction;
5813 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5814 } else if (GST_PAD_IS_SRC (pad)) {
5815 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5816 goto wrong_direction;
5817 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5819 goto unknown_direction;
5821 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5828 /* ERROR handling */
5831 g_warning ("pad %s:%s sending %s event in wrong direction",
5832 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5833 gst_event_unref (event);
5838 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5839 gst_event_unref (event);
5845 * gst_pad_set_element_private:
5846 * @pad: the #GstPad to set the private data of.
5847 * @priv: The private data to attach to the pad.
5849 * Set the given private data gpointer on the pad.
5850 * This function can only be used by the element that owns the pad.
5851 * No locking is performed in this function.
5854 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5856 pad->element_private = priv;
5860 * gst_pad_get_element_private:
5861 * @pad: the #GstPad to get the private data of.
5863 * Gets the private data of a pad.
5864 * No locking is performed in this function.
5866 * Returns: (transfer none): a #gpointer to the private data.
5869 gst_pad_get_element_private (GstPad * pad)
5871 return pad->element_private;
5875 * gst_pad_get_sticky_event:
5876 * @pad: the #GstPad to get the event from.
5877 * @event_type: the #GstEventType that should be retrieved.
5878 * @idx: the index of the event
5880 * Returns a new reference of the sticky event of type @event_type
5883 * Returns: (transfer full) (nullable): a #GstEvent of type
5884 * @event_type or %NULL when no event of @event_type was on
5885 * @pad. Unref after usage.
5888 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5890 GstEvent *event = NULL;
5893 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5894 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5896 GST_OBJECT_LOCK (pad);
5897 ev = find_event_by_type (pad, event_type, idx);
5898 if (ev && (event = ev->event))
5899 gst_event_ref (event);
5900 GST_OBJECT_UNLOCK (pad);
5907 GstPadStickyEventsForeachFunction func;
5912 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5914 ForeachDispatch *data = user_data;
5915 gboolean ret = TRUE;
5918 GST_OBJECT_UNLOCK (pad);
5920 ret = data->func (pad, &ev->event, data->user_data);
5922 GST_OBJECT_LOCK (pad);
5929 * gst_pad_sticky_events_foreach:
5930 * @pad: the #GstPad that should be used for iteration.
5931 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5932 * should be called for every event.
5933 * @user_data: (closure): the optional user data.
5935 * Iterates all sticky events on @pad and calls @foreach_func for every
5936 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5939 gst_pad_sticky_events_foreach (GstPad * pad,
5940 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5942 ForeachDispatch data;
5944 g_return_if_fail (GST_IS_PAD (pad));
5945 g_return_if_fail (foreach_func != NULL);
5947 data.func = foreach_func;
5948 data.user_data = user_data;
5950 GST_OBJECT_LOCK (pad);
5951 events_foreach (pad, foreach_dispatch_function, &data);
5952 GST_OBJECT_UNLOCK (pad);
5956 do_stream_status (GstPad * pad, GstStreamStatusType type,
5957 GThread * thread, GstTask * task)
5961 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5963 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5964 if (GST_IS_ELEMENT (parent)) {
5965 GstMessage *message;
5966 GValue value = { 0 };
5968 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5969 gchar *tname, *ename, *pname;
5971 /* create a good task name */
5972 ename = gst_element_get_name (parent);
5973 pname = gst_pad_get_name (pad);
5974 tname = g_strdup_printf ("%s:%s", ename, pname);
5978 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5982 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5985 g_value_init (&value, GST_TYPE_TASK);
5986 g_value_set_object (&value, task);
5987 gst_message_set_stream_status_object (message, &value);
5988 g_value_unset (&value);
5990 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5991 gst_element_post_message (parent, message);
5993 gst_object_unref (parent);
5998 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
6000 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
6005 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
6007 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
6012 * gst_pad_start_task:
6013 * @pad: the #GstPad to start the task of
6014 * @func: the task function to call
6015 * @user_data: user data passed to the task function
6016 * @notify: called when @user_data is no longer referenced
6018 * Starts a task that repeatedly calls @func with @user_data. This function
6019 * is mostly used in pad activation functions to start the dataflow.
6020 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
6021 * before @func is called.
6023 * Returns: a %TRUE if the task could be started.
6026 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
6027 GDestroyNotify notify)
6032 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6033 g_return_val_if_fail (func != NULL, FALSE);
6035 GST_DEBUG_OBJECT (pad, "start task");
6037 GST_OBJECT_LOCK (pad);
6038 task = GST_PAD_TASK (pad);
6040 task = gst_task_new (func, user_data, notify);
6041 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
6042 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
6043 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
6044 GST_INFO_OBJECT (pad, "created task %p", task);
6045 GST_PAD_TASK (pad) = task;
6046 gst_object_ref (task);
6047 /* release lock to post the message */
6048 GST_OBJECT_UNLOCK (pad);
6050 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
6052 gst_object_unref (task);
6054 GST_OBJECT_LOCK (pad);
6055 /* nobody else is supposed to have changed the pad now */
6056 if (GST_PAD_TASK (pad) != task)
6057 goto concurrent_stop;
6059 res = gst_task_set_state (task, GST_TASK_STARTED);
6060 GST_OBJECT_UNLOCK (pad);
6067 GST_OBJECT_UNLOCK (pad);
6073 * gst_pad_pause_task:
6074 * @pad: the #GstPad to pause the task of
6076 * Pause the task of @pad. This function will also wait until the
6077 * function executed by the task is finished if this function is not
6078 * called from the task function.
6080 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
6084 gst_pad_pause_task (GstPad * pad)
6089 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6091 GST_DEBUG_OBJECT (pad, "pause task");
6093 GST_OBJECT_LOCK (pad);
6094 task = GST_PAD_TASK (pad);
6097 res = gst_task_set_state (task, GST_TASK_PAUSED);
6098 GST_OBJECT_UNLOCK (pad);
6100 /* wait for task function to finish, this lock is recursive so it does nothing
6101 * when the pause is called from the task itself */
6102 GST_PAD_STREAM_LOCK (pad);
6103 GST_PAD_STREAM_UNLOCK (pad);
6109 GST_DEBUG_OBJECT (pad, "pad has no task");
6110 GST_OBJECT_UNLOCK (pad);
6116 * gst_pad_get_task_state:
6117 * @pad: the #GstPad to get task state from
6119 * Get @pad task state. If no task is currently
6120 * set, #GST_TASK_STOPPED is returned.
6122 * Returns: The current state of @pad's task.
6127 gst_pad_get_task_state (GstPad * pad)
6132 g_return_val_if_fail (GST_IS_PAD (pad), GST_TASK_STOPPED);
6134 GST_OBJECT_LOCK (pad);
6135 task = GST_PAD_TASK (pad);
6138 res = gst_task_get_state (task);
6139 GST_OBJECT_UNLOCK (pad);
6145 GST_DEBUG_OBJECT (pad, "pad has no task");
6146 GST_OBJECT_UNLOCK (pad);
6147 return GST_TASK_STOPPED;
6152 * gst_pad_stop_task:
6153 * @pad: the #GstPad to stop the task of
6155 * Stop the task of @pad. This function will also make sure that the
6156 * function executed by the task will effectively stop if not called
6157 * from the GstTaskFunction.
6159 * This function will deadlock if called from the GstTaskFunction of
6160 * the task. Use gst_task_pause() instead.
6162 * Regardless of whether the pad has a task, the stream lock is acquired and
6163 * released so as to ensure that streaming through this pad has finished.
6165 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
6168 gst_pad_stop_task (GstPad * pad)
6173 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
6175 GST_DEBUG_OBJECT (pad, "stop task");
6177 GST_OBJECT_LOCK (pad);
6178 task = GST_PAD_TASK (pad);
6181 GST_PAD_TASK (pad) = NULL;
6182 res = gst_task_set_state (task, GST_TASK_STOPPED);
6183 GST_OBJECT_UNLOCK (pad);
6185 GST_PAD_STREAM_LOCK (pad);
6186 GST_PAD_STREAM_UNLOCK (pad);
6188 if (!gst_task_join (task))
6191 gst_object_unref (task);
6197 GST_DEBUG_OBJECT (pad, "no task");
6198 GST_OBJECT_UNLOCK (pad);
6200 GST_PAD_STREAM_LOCK (pad);
6201 GST_PAD_STREAM_UNLOCK (pad);
6203 /* this is not an error */
6208 /* this is bad, possibly the application tried to join the task from
6209 * the task's thread. We install the task again so that it will be stopped
6210 * again from the right thread next time hopefully. */
6211 GST_OBJECT_LOCK (pad);
6212 GST_DEBUG_OBJECT (pad, "join failed");
6213 /* we can only install this task if there was no other task */
6214 if (GST_PAD_TASK (pad) == NULL)
6215 GST_PAD_TASK (pad) = task;
6216 GST_OBJECT_UNLOCK (pad);
6223 * gst_pad_probe_info_get_event:
6224 * @info: a #GstPadProbeInfo
6226 * Returns: (transfer none): The #GstEvent from the probe
6230 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
6232 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
6233 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
6235 return GST_PAD_PROBE_INFO_EVENT (info);
6240 * gst_pad_probe_info_get_query:
6241 * @info: a #GstPadProbeInfo
6243 * Returns: (transfer none): The #GstQuery from the probe
6247 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6249 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6250 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6252 return GST_PAD_PROBE_INFO_QUERY (info);
6256 * gst_pad_probe_info_get_buffer:
6257 * @info: a #GstPadProbeInfo
6259 * Returns: (transfer none): The #GstBuffer from the probe
6263 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6265 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6267 return GST_PAD_PROBE_INFO_BUFFER (info);
6271 * gst_pad_probe_info_get_buffer_list:
6272 * @info: a #GstPadProbeInfo
6274 * Returns: (transfer none): The #GstBufferList from the probe
6278 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6280 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6282 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6286 * gst_pad_get_last_flow_return:
6289 * Gets the #GstFlowReturn return from the last data passed by this pad.
6294 gst_pad_get_last_flow_return (GstPad * pad)
6298 GST_OBJECT_LOCK (pad);
6299 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6300 GST_OBJECT_UNLOCK (pad);