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.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.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 */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
152 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 GstPadProbeInfo *info;
164 static void gst_pad_dispose (GObject * object);
165 static void gst_pad_finalize (GObject * object);
166 static void gst_pad_set_property (GObject * object, guint prop_id,
167 const GValue * value, GParamSpec * pspec);
168 static void gst_pad_get_property (GObject * object, guint prop_id,
169 GValue * value, GParamSpec * pspec);
171 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
172 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
173 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
174 GstObject * parent, GstBufferList * list);
176 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
178 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
179 GstEvent * event, GstPadProbeType type);
181 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
183 static GParamSpec *pspec_caps = NULL;
185 /* quarks for probe signals */
186 static GQuark buffer_quark;
187 static GQuark buffer_list_quark;
188 static GQuark event_quark;
197 static GstFlowQuarks flow_quarks[] = {
198 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
199 {GST_FLOW_OK, "ok", 0},
200 {GST_FLOW_NOT_LINKED, "not-linked", 0},
201 {GST_FLOW_FLUSHING, "flushing", 0},
202 {GST_FLOW_EOS, "eos", 0},
203 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
204 {GST_FLOW_ERROR, "error", 0},
205 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
206 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
211 * @ret: a #GstFlowReturn to get the name of.
213 * Gets a string representing the given flow return.
215 * Returns: a static string with the name of the flow return.
218 gst_flow_get_name (GstFlowReturn ret)
222 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
224 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
225 if (ret == flow_quarks[i].ret)
226 return flow_quarks[i].name;
233 * @ret: a #GstFlowReturn to get the quark of.
235 * Get the unique quark for the given GstFlowReturn.
237 * Returns: the quark associated with the flow return or 0 if an
238 * invalid return was specified.
241 gst_flow_to_quark (GstFlowReturn ret)
245 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
247 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
248 if (ret == flow_quarks[i].ret)
249 return flow_quarks[i].quark;
255 * gst_pad_link_get_name:
256 * @ret: a #GstPadLinkReturn to get the name of.
258 * Gets a string representing the given pad-link return.
260 * Returns: a static string with the name of the pad-link return.
265 gst_pad_link_get_name (GstPadLinkReturn ret)
267 static const gchar *names[(-(GST_PAD_LINK_REFUSED)) + 1] = {
268 "ok", "wrong hierarchy", "was linked", "wrong direction", "no format",
269 "incompatible scheduling", "refused"
271 ret = CLAMP (ret, GST_PAD_LINK_REFUSED, GST_PAD_LINK_OK);
279 buffer_quark = g_quark_from_static_string ("buffer"); \
280 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
281 event_quark = g_quark_from_static_string ("event"); \
283 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
284 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
287 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
288 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
291 #define gst_pad_parent_class parent_class
292 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
295 gst_pad_class_init (GstPadClass * klass)
297 GObjectClass *gobject_class;
298 GstObjectClass *gstobject_class;
300 gobject_class = G_OBJECT_CLASS (klass);
301 gstobject_class = GST_OBJECT_CLASS (klass);
303 g_type_class_add_private (klass, sizeof (GstPadPrivate));
305 gobject_class->dispose = gst_pad_dispose;
306 gobject_class->finalize = gst_pad_finalize;
307 gobject_class->set_property = gst_pad_set_property;
308 gobject_class->get_property = gst_pad_get_property;
312 * @pad: the pad that emitted the signal
313 * @peer: the peer pad that has been connected
315 * Signals that a pad has been linked to the peer pad.
317 gst_pad_signals[PAD_LINKED] =
318 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
319 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
320 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
323 * @pad: the pad that emitted the signal
324 * @peer: the peer pad that has been disconnected
326 * Signals that a pad has been unlinked from the peer pad.
328 gst_pad_signals[PAD_UNLINKED] =
329 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
330 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
331 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
333 pspec_caps = g_param_spec_boxed ("caps", "Caps",
334 "The capabilities of the pad", GST_TYPE_CAPS,
335 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
336 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
338 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
339 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
340 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
341 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
343 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
344 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
345 g_param_spec_object ("template", "Template",
346 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
347 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
349 gstobject_class->path_string_separator = ".";
351 /* Register common function pointer descriptions */
352 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
353 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
354 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
355 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
356 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
360 gst_pad_init (GstPad * pad)
362 pad->priv = GST_PAD_GET_PRIVATE (pad);
364 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
366 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
367 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
368 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
369 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
370 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
372 GST_PAD_SET_FLUSHING (pad);
374 g_rec_mutex_init (&pad->stream_rec_lock);
376 g_cond_init (&pad->block_cond);
378 g_hook_list_init (&pad->probes, sizeof (GstProbe));
380 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
381 pad->priv->events_cookie = 0;
382 pad->priv->last_cookie = -1;
385 /* called when setting the pad inactive. It removes all sticky events from
386 * the pad. must be called with object lock */
388 remove_events (GstPad * pad)
393 events = pad->priv->events;
396 for (i = 0; i < len; i++) {
397 PadEvent *ev = &g_array_index (events, PadEvent, i);
398 GstEvent *event = ev->event;
402 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
403 GST_OBJECT_UNLOCK (pad);
405 GST_DEBUG_OBJECT (pad, "notify caps");
406 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
408 GST_OBJECT_LOCK (pad);
410 gst_event_unref (event);
412 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
413 g_array_set_size (events, 0);
414 pad->priv->events_cookie++;
417 /* should be called with object lock */
419 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
425 events = pad->priv->events;
428 for (i = 0; i < len; i++) {
429 ev = &g_array_index (events, PadEvent, i);
430 if (ev->event == NULL)
433 if (GST_EVENT_TYPE (ev->event) == type) {
444 /* should be called with OBJECT lock */
446 find_event (GstPad * pad, GstEvent * event)
452 events = pad->priv->events;
455 for (i = 0; i < len; i++) {
456 ev = &g_array_index (events, PadEvent, i);
457 if (event == ev->event)
465 /* should be called with OBJECT lock */
467 remove_event_by_type (GstPad * pad, GstEventType type)
473 events = pad->priv->events;
478 ev = &g_array_index (events, PadEvent, i);
479 if (ev->event == NULL)
482 if (GST_EVENT_TYPE (ev->event) != type)
485 gst_event_unref (ev->event);
486 g_array_remove_index (events, i);
488 pad->priv->events_cookie++;
496 /* check all events on srcpad against those on sinkpad. All events that are not
497 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
498 * srcpad so that the events will be sent next time */
499 /* should be called with srcpad and sinkpad LOCKS */
501 schedule_events (GstPad * srcpad, GstPad * sinkpad)
506 gboolean pending = FALSE;
508 events = srcpad->priv->events;
511 for (i = 0; i < len; i++) {
512 ev = &g_array_index (events, PadEvent, i);
513 if (ev->event == NULL)
516 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
517 ev->received = FALSE;
522 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
525 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
528 /* should be called with pad LOCK */
530 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
537 events = pad->priv->events;
540 cookie = pad->priv->events_cookie;
544 PadEvent *ev, ev_ret;
546 ev = &g_array_index (events, PadEvent, i);
547 if (G_UNLIKELY (ev->event == NULL))
550 /* take aditional ref, func might release the lock */
551 ev_ret.event = gst_event_ref (ev->event);
552 ev_ret.received = ev->received;
554 ret = func (pad, &ev_ret, user_data);
556 /* recheck the cookie, lock might have been released and the list could have
558 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
559 if (G_LIKELY (ev_ret.event))
560 gst_event_unref (ev_ret.event);
564 /* store the received state */
565 ev->received = ev_ret.received;
567 /* if the event changed, we need to do something */
568 if (G_UNLIKELY (ev->event != ev_ret.event)) {
569 if (G_UNLIKELY (ev_ret.event == NULL)) {
570 /* function unreffed and set the event to NULL, remove it */
571 gst_event_unref (ev->event);
572 g_array_remove_index (events, i);
574 cookie = ++pad->priv->events_cookie;
577 /* function gave a new event for us */
578 gst_event_take (&ev->event, ev_ret.event);
581 /* just unref, nothing changed */
582 gst_event_unref (ev_ret.event);
591 /* should be called with LOCK */
593 apply_pad_offset (GstPad * pad, GstEvent * event)
595 /* check if we need to adjust the segment */
596 if (pad->offset != 0) {
599 /* copy segment values */
600 gst_event_copy_segment (event, &segment);
601 gst_event_unref (event);
603 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
604 GST_TIME_ARGS (pad->offset));
605 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
606 event = gst_event_new_segment (&segment);
611 /* should be called with the OBJECT_LOCK */
613 get_pad_caps (GstPad * pad)
615 GstCaps *caps = NULL;
618 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
620 gst_event_parse_caps (ev->event, &caps);
626 gst_pad_dispose (GObject * object)
628 GstPad *pad = GST_PAD_CAST (object);
631 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
633 /* unlink the peer pad */
634 if ((peer = gst_pad_get_peer (pad))) {
635 /* window for MT unsafeness, someone else could unlink here
636 * and then we call unlink with wrong pads. The unlink
637 * function would catch this and safely return failed. */
638 if (GST_PAD_IS_SRC (pad))
639 gst_pad_unlink (pad, peer);
641 gst_pad_unlink (peer, pad);
643 gst_object_unref (peer);
646 gst_pad_set_pad_template (pad, NULL);
648 GST_OBJECT_LOCK (pad);
650 GST_OBJECT_UNLOCK (pad);
652 g_hook_list_clear (&pad->probes);
654 G_OBJECT_CLASS (parent_class)->dispose (object);
658 gst_pad_finalize (GObject * object)
660 GstPad *pad = GST_PAD_CAST (object);
663 /* in case the task is still around, clean it up */
664 if ((task = GST_PAD_TASK (pad))) {
665 gst_task_join (task);
666 GST_PAD_TASK (pad) = NULL;
667 gst_object_unref (task);
670 if (pad->activatenotify)
671 pad->activatenotify (pad->activatedata);
672 if (pad->activatemodenotify)
673 pad->activatemodenotify (pad->activatemodedata);
675 pad->linknotify (pad->linkdata);
676 if (pad->unlinknotify)
677 pad->unlinknotify (pad->unlinkdata);
678 if (pad->chainnotify)
679 pad->chainnotify (pad->chaindata);
680 if (pad->chainlistnotify)
681 pad->chainlistnotify (pad->chainlistdata);
682 if (pad->getrangenotify)
683 pad->getrangenotify (pad->getrangedata);
684 if (pad->eventnotify)
685 pad->eventnotify (pad->eventdata);
686 if (pad->querynotify)
687 pad->querynotify (pad->querydata);
688 if (pad->iterintlinknotify)
689 pad->iterintlinknotify (pad->iterintlinkdata);
691 g_rec_mutex_clear (&pad->stream_rec_lock);
692 g_cond_clear (&pad->block_cond);
693 g_array_free (pad->priv->events, TRUE);
695 G_OBJECT_CLASS (parent_class)->finalize (object);
699 gst_pad_set_property (GObject * object, guint prop_id,
700 const GValue * value, GParamSpec * pspec)
702 g_return_if_fail (GST_IS_PAD (object));
705 case PAD_PROP_DIRECTION:
706 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
708 case PAD_PROP_TEMPLATE:
709 gst_pad_set_pad_template (GST_PAD_CAST (object),
710 (GstPadTemplate *) g_value_get_object (value));
713 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
719 gst_pad_get_property (GObject * object, guint prop_id,
720 GValue * value, GParamSpec * pspec)
722 g_return_if_fail (GST_IS_PAD (object));
726 GST_OBJECT_LOCK (object);
727 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
728 GST_OBJECT_UNLOCK (object);
730 case PAD_PROP_DIRECTION:
731 g_value_set_enum (value, GST_PAD_DIRECTION (object));
733 case PAD_PROP_TEMPLATE:
734 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
737 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
744 * @name: the name of the new pad.
745 * @direction: the #GstPadDirection of the pad.
747 * Creates a new pad with the given name in the given direction.
748 * If name is NULL, a guaranteed unique name (across all pads)
750 * This function makes a copy of the name so you can safely free the name.
752 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
757 gst_pad_new (const gchar * name, GstPadDirection direction)
759 return g_object_new (GST_TYPE_PAD,
760 "name", name, "direction", direction, NULL);
764 * gst_pad_new_from_template:
765 * @templ: the pad template to use
766 * @name: the name of the element
768 * Creates a new pad with the given name from the given template.
769 * If name is NULL, a guaranteed unique name (across all pads)
771 * This function makes a copy of the name so you can safely free the name.
773 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
776 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
778 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
780 return g_object_new (GST_TYPE_PAD,
781 "name", name, "direction", templ->direction, "template", templ, NULL);
785 * gst_pad_new_from_static_template:
786 * @templ: the #GstStaticPadTemplate to use
787 * @name: the name of the element
789 * Creates a new pad with the given name from the given static template.
790 * If name is NULL, a guaranteed unique name (across all pads)
792 * This function makes a copy of the name so you can safely free the name.
794 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
797 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
801 GstPadTemplate *template;
803 template = gst_static_pad_template_get (templ);
804 pad = gst_pad_new_from_template (template, name);
805 gst_object_unref (template);
809 #define ACQUIRE_PARENT(pad, parent, label) \
811 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
812 gst_object_ref (parent); \
813 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
817 #define RELEASE_PARENT(parent) \
819 if (G_LIKELY (parent)) \
820 gst_object_unref (parent); \
824 * gst_pad_get_direction:
825 * @pad: a #GstPad to get the direction of.
827 * Gets the direction of the pad. The direction of the pad is
828 * decided at construction time so this function does not take
831 * Returns: the #GstPadDirection of the pad.
836 gst_pad_get_direction (GstPad * pad)
838 GstPadDirection result;
840 /* PAD_UNKNOWN is a little silly but we need some sort of
841 * error return value */
842 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
844 result = GST_PAD_DIRECTION (pad);
850 gst_pad_activate_default (GstPad * pad, GstObject * parent)
852 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
856 * gst_pad_mode_get_name:
857 * @mode: the pad mode
859 * Return the name of a pad mode, for use in debug messages mostly.
861 * Returns: short mnemonic for pad mode @mode
864 gst_pad_mode_get_name (GstPadMode mode)
867 case GST_PAD_MODE_NONE:
869 case GST_PAD_MODE_PUSH:
871 case GST_PAD_MODE_PULL:
880 pre_activate (GstPad * pad, GstPadMode new_mode)
883 case GST_PAD_MODE_NONE:
884 GST_OBJECT_LOCK (pad);
885 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
886 GST_PAD_SET_FLUSHING (pad);
887 GST_PAD_MODE (pad) = new_mode;
888 /* unlock blocked pads so element can resume and stop */
889 GST_PAD_BLOCK_BROADCAST (pad);
890 GST_OBJECT_UNLOCK (pad);
892 case GST_PAD_MODE_PUSH:
893 case GST_PAD_MODE_PULL:
894 GST_OBJECT_LOCK (pad);
895 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
896 gst_pad_mode_get_name (new_mode));
897 GST_PAD_UNSET_FLUSHING (pad);
898 GST_PAD_MODE (pad) = new_mode;
899 if (GST_PAD_IS_SINK (pad)) {
901 /* make sure the peer src pad sends us all events */
902 if ((peer = GST_PAD_PEER (pad))) {
903 gst_object_ref (peer);
904 GST_OBJECT_UNLOCK (pad);
906 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
907 GST_DEBUG_PAD_NAME (peer));
909 GST_OBJECT_LOCK (peer);
910 schedule_events (peer, NULL);
911 GST_OBJECT_UNLOCK (peer);
913 gst_object_unref (peer);
915 GST_OBJECT_UNLOCK (pad);
918 GST_OBJECT_UNLOCK (pad);
925 post_activate (GstPad * pad, GstPadMode new_mode)
928 case GST_PAD_MODE_NONE:
929 /* ensures that streaming stops */
930 GST_PAD_STREAM_LOCK (pad);
931 GST_DEBUG_OBJECT (pad, "stopped streaming");
932 GST_OBJECT_LOCK (pad);
934 GST_OBJECT_UNLOCK (pad);
935 GST_PAD_STREAM_UNLOCK (pad);
937 case GST_PAD_MODE_PUSH:
938 case GST_PAD_MODE_PULL:
945 * gst_pad_set_active:
946 * @pad: the #GstPad to activate or deactivate.
947 * @active: whether or not the pad should be active.
949 * Activates or deactivates the given pad.
950 * Normally called from within core state change functions.
952 * If @active, makes sure the pad is active. If it is already active, either in
953 * push or pull mode, just return. Otherwise dispatches to the pad's activate
954 * function to perform the actual activation.
956 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
957 * and a FALSE argument.
959 * Returns: #TRUE if the operation was successful.
964 gst_pad_set_active (GstPad * pad, gboolean active)
968 gboolean ret = FALSE;
970 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
972 GST_OBJECT_LOCK (pad);
973 old = GST_PAD_MODE (pad);
974 ACQUIRE_PARENT (pad, parent, no_parent);
975 GST_OBJECT_UNLOCK (pad);
978 if (old == GST_PAD_MODE_NONE) {
979 GST_DEBUG_OBJECT (pad, "activating pad from none");
980 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
982 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
983 gst_pad_mode_get_name (old));
987 if (old == GST_PAD_MODE_NONE) {
988 GST_DEBUG_OBJECT (pad, "pad was inactive");
991 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
992 gst_pad_mode_get_name (old));
993 ret = gst_pad_activate_mode (pad, old, FALSE);
997 RELEASE_PARENT (parent);
999 if (G_UNLIKELY (!ret))
1007 GST_DEBUG_OBJECT (pad, "no parent");
1008 GST_OBJECT_UNLOCK (pad);
1013 GST_OBJECT_LOCK (pad);
1015 g_critical ("Failed to deactivate pad %s:%s, very bad",
1016 GST_DEBUG_PAD_NAME (pad));
1018 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1020 GST_OBJECT_UNLOCK (pad);
1026 * gst_pad_activate_mode:
1027 * @pad: the #GstPad to activate or deactivate.
1028 * @mode: the requested activation mode
1029 * @active: whether or not the pad should be active.
1031 * Activates or deactivates the given pad in @mode via dispatching to the
1032 * pad's activatemodefunc. For use from within pad activation functions only.
1034 * If you don't know what this is, you probably don't want to call it.
1036 * Returns: TRUE if the operation was successful.
1041 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1043 gboolean res = FALSE;
1045 GstPadMode old, new;
1046 GstPadDirection dir;
1049 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1051 GST_OBJECT_LOCK (pad);
1052 old = GST_PAD_MODE (pad);
1053 dir = GST_PAD_DIRECTION (pad);
1054 ACQUIRE_PARENT (pad, parent, no_parent);
1055 GST_OBJECT_UNLOCK (pad);
1057 new = active ? mode : GST_PAD_MODE_NONE;
1062 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1063 /* pad was activate in the wrong direction, deactivate it
1064 * and reactivate it in the requested mode */
1065 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1066 gst_pad_mode_get_name (old));
1068 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1069 goto deactivate_failed;
1073 case GST_PAD_MODE_PULL:
1075 if (dir == GST_PAD_SINK) {
1076 if ((peer = gst_pad_get_peer (pad))) {
1077 GST_DEBUG_OBJECT (pad, "calling peer");
1078 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1080 gst_object_unref (peer);
1082 /* there is no peer, this is only fatal when we activate. When we
1083 * deactivate, we must assume the application has unlinked the peer and
1084 * will deactivate it eventually. */
1088 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1091 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1092 goto failure; /* Can't activate pull on a src without a
1093 getrange function */
1101 /* Mark pad as needing reconfiguration */
1103 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1104 pre_activate (pad, new);
1106 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1107 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1111 /* can happen for sinks of passthrough elements */
1114 post_activate (pad, new);
1116 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1117 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1122 /* Clear sticky flags on deactivation */
1124 GST_OBJECT_LOCK (pad);
1125 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1126 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1127 GST_OBJECT_UNLOCK (pad);
1131 RELEASE_PARENT (parent);
1137 GST_DEBUG_OBJECT (pad, "no parent");
1138 GST_OBJECT_UNLOCK (pad);
1143 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1144 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1149 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1150 "failed to %s in switch to %s mode from %s mode",
1151 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1152 gst_pad_mode_get_name (old));
1157 GST_OBJECT_LOCK (peer);
1158 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1159 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1160 GST_OBJECT_UNLOCK (peer);
1161 gst_object_unref (peer);
1166 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1167 "pad in pull mode");
1172 GST_OBJECT_LOCK (pad);
1173 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1174 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1175 GST_PAD_SET_FLUSHING (pad);
1176 GST_PAD_MODE (pad) = old;
1177 GST_OBJECT_UNLOCK (pad);
1183 * gst_pad_is_active:
1184 * @pad: the #GstPad to query
1186 * Query if a pad is active
1188 * Returns: TRUE if the pad is active.
1193 gst_pad_is_active (GstPad * pad)
1195 gboolean result = FALSE;
1197 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1199 GST_OBJECT_LOCK (pad);
1200 result = GST_PAD_IS_ACTIVE (pad);
1201 GST_OBJECT_UNLOCK (pad);
1207 cleanup_hook (GstPad * pad, GHook * hook)
1209 GstPadProbeType type;
1211 if (!G_HOOK_IS_VALID (hook))
1214 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1216 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1217 /* unblock when we remove the last blocking probe */
1219 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1222 /* Might have new probes now that want to be called */
1223 GST_PAD_BLOCK_BROADCAST (pad);
1225 if (pad->num_blocked == 0) {
1226 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1227 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1230 g_hook_destroy_link (&pad->probes, hook);
1235 * gst_pad_add_probe:
1236 * @pad: the #GstPad to add the probe to
1237 * @mask: the probe mask
1238 * @callback: #GstPadProbeCallback that will be called with notifications of
1240 * @user_data: (closure): user data passed to the callback
1241 * @destroy_data: #GDestroyNotify for user_data
1243 * Be notified of different states of pads. The provided callback is called for
1244 * every state that matches @mask.
1246 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1247 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1248 * happend that the probe can be run immediately and if the probe returns
1249 * GST_PAD_PROBE_REMOVE this functions returns 0.
1254 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1255 GstPadProbeCallback callback, gpointer user_data,
1256 GDestroyNotify destroy_data)
1261 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1262 g_return_val_if_fail (mask != 0, 0);
1264 GST_OBJECT_LOCK (pad);
1266 /* make a new probe */
1267 hook = g_hook_alloc (&pad->probes);
1269 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1272 /* when no contraints are given for the types, assume all types are
1274 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1275 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1276 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1277 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1279 /* store our flags and other fields */
1280 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1281 hook->func = callback;
1282 hook->data = user_data;
1283 hook->destroy = destroy_data;
1284 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1287 g_hook_prepend (&pad->probes, hook);
1289 /* incremenent cookie so that the new hook get's called */
1290 pad->priv->probe_list_cookie++;
1292 /* get the id of the hook, we return this and it can be used to remove the
1294 res = hook->hook_id;
1296 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1298 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1299 /* we have a block probe */
1301 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1303 "now %d blocking probes", pad->num_blocked);
1305 /* Might have new probes now that want to be called */
1306 GST_PAD_BLOCK_BROADCAST (pad);
1309 /* call the callback if we need to be called for idle callbacks */
1310 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1311 if (pad->priv->using > 0) {
1312 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1313 * flag above, the last thread to leave the push will do the callback. New
1314 * threads going into the push will block. */
1315 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1316 "pad is in use, delay idle callback");
1317 GST_OBJECT_UNLOCK (pad);
1319 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1320 GstPadProbeReturn ret;
1322 /* Keep another ref, the callback could destroy the pad */
1323 gst_object_ref (pad);
1325 /* the pad is idle now, we can signal the idle callback now */
1326 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1327 "pad is idle, trigger idle callback");
1328 GST_OBJECT_UNLOCK (pad);
1330 ret = callback (pad, &info, user_data);
1332 GST_OBJECT_LOCK (pad);
1334 case GST_PAD_PROBE_REMOVE:
1335 /* remove the probe */
1336 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1337 cleanup_hook (pad, hook);
1340 case GST_PAD_PROBE_DROP:
1341 GST_DEBUG_OBJECT (pad, "asked to drop item");
1343 case GST_PAD_PROBE_PASS:
1344 GST_DEBUG_OBJECT (pad, "asked to pass item");
1346 case GST_PAD_PROBE_OK:
1347 GST_DEBUG_OBJECT (pad, "probe returned OK");
1350 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1353 GST_OBJECT_UNLOCK (pad);
1355 gst_object_unref (pad);
1358 GST_OBJECT_UNLOCK (pad);
1364 * gst_pad_remove_probe:
1365 * @pad: the #GstPad with the probe
1366 * @id: the probe id to remove
1368 * Remove the probe with @id from @pad.
1373 gst_pad_remove_probe (GstPad * pad, gulong id)
1377 g_return_if_fail (GST_IS_PAD (pad));
1379 GST_OBJECT_LOCK (pad);
1381 hook = g_hook_get (&pad->probes, id);
1385 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1387 cleanup_hook (pad, hook);
1388 GST_OBJECT_UNLOCK (pad);
1394 GST_OBJECT_UNLOCK (pad);
1395 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1401 * gst_pad_is_blocked:
1402 * @pad: the #GstPad to query
1404 * Checks if the pad is blocked or not. This function returns the
1405 * last requested state of the pad. It is not certain that the pad
1406 * is actually blocking at this point (see gst_pad_is_blocking()).
1408 * Returns: TRUE if the pad is blocked.
1413 gst_pad_is_blocked (GstPad * pad)
1415 gboolean result = FALSE;
1417 g_return_val_if_fail (GST_IS_PAD (pad), result);
1419 GST_OBJECT_LOCK (pad);
1420 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1421 GST_OBJECT_UNLOCK (pad);
1427 * gst_pad_is_blocking:
1428 * @pad: the #GstPad to query
1430 * Checks if the pad is blocking or not. This is a guaranteed state
1431 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1433 * Returns: TRUE if the pad is blocking.
1438 gst_pad_is_blocking (GstPad * pad)
1440 gboolean result = FALSE;
1442 g_return_val_if_fail (GST_IS_PAD (pad), result);
1444 GST_OBJECT_LOCK (pad);
1445 /* the blocking flag is only valid if the pad is not flushing */
1446 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1447 GST_OBJECT_UNLOCK (pad);
1453 * gst_pad_needs_reconfigure:
1454 * @pad: the #GstPad to check
1456 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1457 * if the flag was set.
1459 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1462 gst_pad_needs_reconfigure (GstPad * pad)
1464 gboolean reconfigure;
1466 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1468 GST_OBJECT_LOCK (pad);
1469 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1470 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1471 GST_OBJECT_UNLOCK (pad);
1477 * gst_pad_check_reconfigure:
1478 * @pad: the #GstPad to check
1480 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1481 * if the flag was set.
1483 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1486 gst_pad_check_reconfigure (GstPad * pad)
1488 gboolean reconfigure;
1490 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1492 GST_OBJECT_LOCK (pad);
1493 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1495 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1496 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1498 GST_OBJECT_UNLOCK (pad);
1504 * gst_pad_mark_reconfigure:
1505 * @pad: the #GstPad to mark
1507 * Mark a pad for needing reconfiguration. The next call to
1508 * gst_pad_check_reconfigure() will return %TRUE after this call.
1511 gst_pad_mark_reconfigure (GstPad * pad)
1513 g_return_if_fail (GST_IS_PAD (pad));
1515 GST_OBJECT_LOCK (pad);
1516 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1517 GST_OBJECT_UNLOCK (pad);
1521 * gst_pad_set_activate_function:
1523 * @f: the #GstPadActivateFunction to set.
1525 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1529 * gst_pad_set_activate_function_full:
1531 * @activate: the #GstPadActivateFunction to set.
1532 * @user_data: user_data passed to @notify
1533 * @notify: notify called when @activate will not be used anymore.
1535 * Sets the given activate function for @pad. The activate function will
1536 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1537 * Only makes sense to set on sink pads.
1539 * Call this function if your sink pad can start a pull-based task.
1542 gst_pad_set_activate_function_full (GstPad * pad,
1543 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1545 g_return_if_fail (GST_IS_PAD (pad));
1547 if (pad->activatenotify)
1548 pad->activatenotify (pad->activatedata);
1549 GST_PAD_ACTIVATEFUNC (pad) = activate;
1550 pad->activatedata = user_data;
1551 pad->activatenotify = notify;
1553 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1554 GST_DEBUG_FUNCPTR_NAME (activate));
1558 * gst_pad_set_activatemode_function:
1560 * @f: the #GstPadActivateModeFunction to set.
1562 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1566 * gst_pad_set_activatemode_function_full:
1568 * @activatemode: the #GstPadActivateModeFunction to set.
1569 * @user_data: user_data passed to @notify
1570 * @notify: notify called when @activatemode will not be used anymore.
1572 * Sets the given activate_mode function for the pad. An activate_mode function
1573 * prepares the element for data passing.
1576 gst_pad_set_activatemode_function_full (GstPad * pad,
1577 GstPadActivateModeFunction activatemode, gpointer user_data,
1578 GDestroyNotify notify)
1580 g_return_if_fail (GST_IS_PAD (pad));
1582 if (pad->activatemodenotify)
1583 pad->activatemodenotify (pad->activatemodedata);
1584 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1585 pad->activatemodedata = user_data;
1586 pad->activatemodenotify = notify;
1588 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1589 GST_DEBUG_FUNCPTR_NAME (activatemode));
1593 * gst_pad_set_chain_function:
1594 * @p: a sink #GstPad.
1595 * @f: the #GstPadChainFunction to set.
1597 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1601 * gst_pad_set_chain_function_full:
1602 * @pad: a sink #GstPad.
1603 * @chain: the #GstPadChainFunction to set.
1604 * @user_data: user_data passed to @notify
1605 * @notify: notify called when @chain will not be used anymore.
1607 * Sets the given chain function for the pad. The chain function is called to
1608 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1611 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1612 gpointer user_data, GDestroyNotify notify)
1614 g_return_if_fail (GST_IS_PAD (pad));
1615 g_return_if_fail (GST_PAD_IS_SINK (pad));
1617 if (pad->chainnotify)
1618 pad->chainnotify (pad->chaindata);
1619 GST_PAD_CHAINFUNC (pad) = chain;
1620 pad->chaindata = user_data;
1621 pad->chainnotify = notify;
1623 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1624 GST_DEBUG_FUNCPTR_NAME (chain));
1628 * gst_pad_set_chain_list_function:
1629 * @p: a sink #GstPad.
1630 * @f: the #GstPadChainListFunction to set.
1632 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1636 * gst_pad_set_chain_list_function_full:
1637 * @pad: a sink #GstPad.
1638 * @chainlist: the #GstPadChainListFunction to set.
1639 * @user_data: user_data passed to @notify
1640 * @notify: notify called when @chainlist will not be used anymore.
1642 * Sets the given chain list function for the pad. The chainlist function is
1643 * called to process a #GstBufferList input buffer list. See
1644 * #GstPadChainListFunction for more details.
1647 gst_pad_set_chain_list_function_full (GstPad * pad,
1648 GstPadChainListFunction chainlist, gpointer user_data,
1649 GDestroyNotify notify)
1651 g_return_if_fail (GST_IS_PAD (pad));
1652 g_return_if_fail (GST_PAD_IS_SINK (pad));
1654 if (pad->chainlistnotify)
1655 pad->chainlistnotify (pad->chainlistdata);
1656 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1657 pad->chainlistdata = user_data;
1658 pad->chainlistnotify = notify;
1660 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1661 GST_DEBUG_FUNCPTR_NAME (chainlist));
1665 * gst_pad_set_getrange_function:
1666 * @p: a source #GstPad.
1667 * @f: the #GstPadGetRangeFunction to set.
1669 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1673 * gst_pad_set_getrange_function_full:
1674 * @pad: a source #GstPad.
1675 * @get: the #GstPadGetRangeFunction to set.
1676 * @user_data: user_data passed to @notify
1677 * @notify: notify called when @get will not be used anymore.
1679 * Sets the given getrange function for the pad. The getrange function is
1680 * called to produce a new #GstBuffer to start the processing pipeline. see
1681 * #GstPadGetRangeFunction for a description of the getrange function.
1684 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1685 gpointer user_data, GDestroyNotify notify)
1687 g_return_if_fail (GST_IS_PAD (pad));
1688 g_return_if_fail (GST_PAD_IS_SRC (pad));
1690 if (pad->getrangenotify)
1691 pad->getrangenotify (pad->getrangedata);
1692 GST_PAD_GETRANGEFUNC (pad) = get;
1693 pad->getrangedata = user_data;
1694 pad->getrangenotify = notify;
1696 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1697 GST_DEBUG_FUNCPTR_NAME (get));
1701 * gst_pad_set_event_function:
1702 * @p: a #GstPad of either direction.
1703 * @f: the #GstPadEventFunction to set.
1705 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1709 * gst_pad_set_event_function_full:
1710 * @pad: a #GstPad of either direction.
1711 * @event: the #GstPadEventFunction to set.
1712 * @user_data: user_data passed to @notify
1713 * @notify: notify called when @event will not be used anymore.
1715 * Sets the given event handler for the pad.
1718 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1719 gpointer user_data, GDestroyNotify notify)
1721 g_return_if_fail (GST_IS_PAD (pad));
1723 if (pad->eventnotify)
1724 pad->eventnotify (pad->eventdata);
1725 GST_PAD_EVENTFUNC (pad) = event;
1726 pad->eventdata = user_data;
1727 pad->eventnotify = notify;
1729 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1730 GST_DEBUG_FUNCPTR_NAME (event));
1734 * gst_pad_set_query_function:
1735 * @p: a #GstPad of either direction.
1736 * @f: the #GstPadQueryFunction to set.
1738 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1742 * gst_pad_set_query_function_full:
1743 * @pad: a #GstPad of either direction.
1744 * @query: the #GstPadQueryFunction to set.
1745 * @user_data: user_data passed to @notify
1746 * @notify: notify called when @query will not be used anymore.
1748 * Set the given query function for the pad.
1751 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1752 gpointer user_data, GDestroyNotify notify)
1754 g_return_if_fail (GST_IS_PAD (pad));
1756 if (pad->querynotify)
1757 pad->querynotify (pad->querydata);
1758 GST_PAD_QUERYFUNC (pad) = query;
1759 pad->querydata = user_data;
1760 pad->querynotify = notify;
1762 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1763 GST_DEBUG_FUNCPTR_NAME (query));
1767 * gst_pad_set_iterate_internal_links_function:
1768 * @p: a #GstPad of either direction.
1769 * @f: the #GstPadIterIntLinkFunction to set.
1771 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1772 * for the user_data and notify.
1775 * gst_pad_set_iterate_internal_links_function_full:
1776 * @pad: a #GstPad of either direction.
1777 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1778 * @user_data: user_data passed to @notify
1779 * @notify: notify called when @iterintlink will not be used anymore.
1781 * Sets the given internal link iterator function for the pad.
1784 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1785 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1786 GDestroyNotify notify)
1788 g_return_if_fail (GST_IS_PAD (pad));
1790 if (pad->iterintlinknotify)
1791 pad->iterintlinknotify (pad->iterintlinkdata);
1792 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1793 pad->iterintlinkdata = user_data;
1794 pad->iterintlinknotify = notify;
1796 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1797 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1801 * gst_pad_set_link_function:
1803 * @f: the #GstPadLinkFunction to set.
1805 * Calls gst_pad_set_link_function_full() with NULL
1806 * for the user_data and notify.
1809 * gst_pad_set_link_function_full:
1811 * @link: the #GstPadLinkFunction to set.
1812 * @user_data: user_data passed to @notify
1813 * @notify: notify called when @link will not be used anymore.
1815 * Sets the given link function for the pad. It will be called when
1816 * the pad is linked with another pad.
1818 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1821 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1822 * cannot be made for some reason.
1824 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1825 * of the peer sink pad, if present.
1828 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1829 gpointer user_data, GDestroyNotify notify)
1831 g_return_if_fail (GST_IS_PAD (pad));
1833 if (pad->linknotify)
1834 pad->linknotify (pad->linkdata);
1835 GST_PAD_LINKFUNC (pad) = link;
1836 pad->linkdata = user_data;
1837 pad->linknotify = notify;
1839 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1840 GST_DEBUG_FUNCPTR_NAME (link));
1844 * gst_pad_set_unlink_function:
1846 * @f: the #GstPadUnlinkFunction to set.
1848 * Calls gst_pad_set_unlink_function_full() with NULL
1849 * for the user_data and notify.
1852 * gst_pad_set_unlink_function_full:
1854 * @unlink: the #GstPadUnlinkFunction to set.
1855 * @user_data: user_data passed to @notify
1856 * @notify: notify called when @unlink will not be used anymore.
1858 * Sets the given unlink function for the pad. It will be called
1859 * when the pad is unlinked.
1862 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1863 gpointer user_data, GDestroyNotify notify)
1865 g_return_if_fail (GST_IS_PAD (pad));
1867 if (pad->unlinknotify)
1868 pad->unlinknotify (pad->unlinkdata);
1869 GST_PAD_UNLINKFUNC (pad) = unlink;
1870 pad->unlinkdata = user_data;
1871 pad->unlinknotify = notify;
1873 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1874 GST_DEBUG_FUNCPTR_NAME (unlink));
1879 * @srcpad: the source #GstPad to unlink.
1880 * @sinkpad: the sink #GstPad to unlink.
1882 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1883 * signal on both pads.
1885 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1886 * the pads were not linked together.
1891 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1893 gboolean result = FALSE;
1894 GstElement *parent = NULL;
1896 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1897 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1898 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1899 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1901 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1902 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1903 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1905 /* We need to notify the parent before taking any pad locks as the bin in
1906 * question might be waiting for a lock on the pad while holding its lock
1907 * that our message will try to take. */
1908 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1909 if (GST_IS_ELEMENT (parent)) {
1910 gst_element_post_message (parent,
1911 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1912 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1914 gst_object_unref (parent);
1919 GST_OBJECT_LOCK (srcpad);
1920 GST_OBJECT_LOCK (sinkpad);
1922 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1923 goto not_linked_together;
1925 if (GST_PAD_UNLINKFUNC (srcpad)) {
1926 GstObject *tmpparent;
1928 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1930 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1931 RELEASE_PARENT (tmpparent);
1934 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1935 GstObject *tmpparent;
1937 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1939 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1940 RELEASE_PARENT (tmpparent);
1944 /* first clear peers */
1945 GST_PAD_PEER (srcpad) = NULL;
1946 GST_PAD_PEER (sinkpad) = NULL;
1948 GST_OBJECT_UNLOCK (sinkpad);
1949 GST_OBJECT_UNLOCK (srcpad);
1951 /* fire off a signal to each of the pads telling them
1952 * that they've been unlinked */
1953 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1954 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1956 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1957 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1962 if (parent != NULL) {
1963 gst_element_post_message (parent,
1964 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1965 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1966 gst_object_unref (parent);
1971 not_linked_together:
1973 /* we do not emit a warning in this case because unlinking cannot
1974 * be made MT safe.*/
1975 GST_OBJECT_UNLOCK (sinkpad);
1976 GST_OBJECT_UNLOCK (srcpad);
1982 * gst_pad_is_linked:
1983 * @pad: pad to check
1985 * Checks if a @pad is linked to another pad or not.
1987 * Returns: TRUE if the pad is linked, FALSE otherwise.
1992 gst_pad_is_linked (GstPad * pad)
1996 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1998 GST_OBJECT_LOCK (pad);
1999 result = (GST_PAD_PEER (pad) != NULL);
2000 GST_OBJECT_UNLOCK (pad);
2005 /* get the caps from both pads and see if the intersection
2008 * This function should be called with the pad LOCK on both
2012 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2013 GstPadLinkCheck flags)
2015 GstCaps *srccaps = NULL;
2016 GstCaps *sinkcaps = NULL;
2017 gboolean compatible = FALSE;
2019 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2022 /* Doing the expensive caps checking takes priority over only checking the template caps */
2023 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2024 GST_OBJECT_UNLOCK (sink);
2025 GST_OBJECT_UNLOCK (src);
2027 srccaps = gst_pad_query_caps (src, NULL);
2028 sinkcaps = gst_pad_query_caps (sink, NULL);
2030 GST_OBJECT_LOCK (src);
2031 GST_OBJECT_LOCK (sink);
2033 /* If one of the two pads doesn't have a template, consider the intersection
2035 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2036 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2040 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2042 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2045 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2047 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2050 /* if we have caps on both pads we can check the intersection. If one
2051 * of the caps is NULL, we return TRUE. */
2052 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2054 gst_caps_unref (srccaps);
2056 gst_caps_unref (sinkcaps);
2060 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2061 gst_caps_unref (srccaps);
2062 gst_caps_unref (sinkcaps);
2065 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2066 (compatible ? "" : "not"));
2071 /* check if the grandparents of both pads are the same.
2072 * This check is required so that we don't try to link
2073 * pads from elements in different bins without ghostpads.
2075 * The LOCK should be held on both pads
2078 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2080 GstObject *psrc, *psink;
2082 psrc = GST_OBJECT_PARENT (src);
2083 psink = GST_OBJECT_PARENT (sink);
2085 /* if one of the pads has no parent, we allow the link */
2086 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2089 /* only care about parents that are elements */
2090 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2091 goto no_element_parent;
2093 /* if the parents are the same, we have a loop */
2094 if (G_UNLIKELY (psrc == psink))
2097 /* if they both have a parent, we check the grandparents. We can not lock
2098 * the parent because we hold on the child (pad) and the locking order is
2099 * parent >> child. */
2100 psrc = GST_OBJECT_PARENT (psrc);
2101 psink = GST_OBJECT_PARENT (psink);
2103 /* if they have grandparents but they are not the same */
2104 if (G_UNLIKELY (psrc != psink))
2105 goto wrong_grandparents;
2112 GST_CAT_DEBUG (GST_CAT_CAPS,
2113 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2114 GST_PTR_FORMAT, psrc, psink);
2119 GST_CAT_DEBUG (GST_CAT_CAPS,
2120 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2121 GST_PTR_FORMAT, psrc, psink);
2126 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2132 GST_CAT_DEBUG (GST_CAT_CAPS,
2133 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2134 GST_PTR_FORMAT, psrc, psink);
2139 /* FIXME leftover from an attempt at refactoring... */
2140 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2141 * the two pads will be locked in the srcpad, sinkpad order. */
2142 static GstPadLinkReturn
2143 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2145 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2146 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2148 GST_OBJECT_LOCK (srcpad);
2150 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2151 goto src_was_linked;
2153 GST_OBJECT_LOCK (sinkpad);
2155 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2156 goto sink_was_linked;
2158 /* check hierarchy, pads can only be linked if the grandparents
2160 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2161 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2162 goto wrong_hierarchy;
2164 /* check pad caps for non-empty intersection */
2165 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2168 /* FIXME check pad scheduling for non-empty intersection */
2170 return GST_PAD_LINK_OK;
2174 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2175 GST_DEBUG_PAD_NAME (srcpad),
2176 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2177 /* we do not emit a warning in this case because unlinking cannot
2178 * be made MT safe.*/
2179 GST_OBJECT_UNLOCK (srcpad);
2180 return GST_PAD_LINK_WAS_LINKED;
2184 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2185 GST_DEBUG_PAD_NAME (sinkpad),
2186 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2187 /* we do not emit a warning in this case because unlinking cannot
2188 * be made MT safe.*/
2189 GST_OBJECT_UNLOCK (sinkpad);
2190 GST_OBJECT_UNLOCK (srcpad);
2191 return GST_PAD_LINK_WAS_LINKED;
2195 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2196 GST_OBJECT_UNLOCK (sinkpad);
2197 GST_OBJECT_UNLOCK (srcpad);
2198 return GST_PAD_LINK_WRONG_HIERARCHY;
2202 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2203 GST_OBJECT_UNLOCK (sinkpad);
2204 GST_OBJECT_UNLOCK (srcpad);
2205 return GST_PAD_LINK_NOFORMAT;
2211 * @srcpad: the source #GstPad.
2212 * @sinkpad: the sink #GstPad.
2214 * Checks if the source pad and the sink pad are compatible so they can be
2217 * Returns: TRUE if the pads can be linked.
2220 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2222 GstPadLinkReturn result;
2224 /* generic checks */
2225 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2226 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2228 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2229 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2231 /* gst_pad_link_prepare does everything for us, we only release the locks
2232 * on the pads that it gets us. If this function returns !OK the locks are not
2234 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2235 if (result != GST_PAD_LINK_OK)
2238 GST_OBJECT_UNLOCK (srcpad);
2239 GST_OBJECT_UNLOCK (sinkpad);
2242 return result == GST_PAD_LINK_OK;
2246 * gst_pad_link_full:
2247 * @srcpad: the source #GstPad to link.
2248 * @sinkpad: the sink #GstPad to link.
2249 * @flags: the checks to validate when linking
2251 * Links the source pad and the sink pad.
2253 * This variant of #gst_pad_link provides a more granular control on the
2254 * checks being done when linking. While providing some considerable speedups
2255 * the caller of this method must be aware that wrong usage of those flags
2256 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2257 * for more information.
2261 * Returns: A result code indicating if the connection worked or
2265 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2267 GstPadLinkReturn result;
2269 GstPadLinkFunction srcfunc, sinkfunc;
2271 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2272 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2273 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2274 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2275 GST_PAD_LINK_WRONG_DIRECTION);
2277 /* Notify the parent early. See gst_pad_unlink for details. */
2278 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2279 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2280 gst_element_post_message (parent,
2281 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2282 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2284 gst_object_unref (parent);
2289 /* prepare will also lock the two pads */
2290 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2292 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2295 /* must set peers before calling the link function */
2296 GST_PAD_PEER (srcpad) = sinkpad;
2297 GST_PAD_PEER (sinkpad) = srcpad;
2299 /* check events, when something is different, mark pending */
2300 schedule_events (srcpad, sinkpad);
2302 /* get the link functions */
2303 srcfunc = GST_PAD_LINKFUNC (srcpad);
2304 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2306 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2307 /* custom link functions, execute them */
2308 GST_OBJECT_UNLOCK (sinkpad);
2309 GST_OBJECT_UNLOCK (srcpad);
2312 GstObject *tmpparent;
2314 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2315 /* this one will call the peer link function */
2316 result = srcfunc (srcpad, tmpparent, sinkpad);
2317 RELEASE_PARENT (tmpparent);
2318 } else if (sinkfunc) {
2319 GstObject *tmpparent;
2321 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2322 /* if no source link function, we need to call the sink link
2323 * function ourselves. */
2324 result = sinkfunc (sinkpad, tmpparent, srcpad);
2325 RELEASE_PARENT (tmpparent);
2329 GST_OBJECT_LOCK (srcpad);
2330 GST_OBJECT_LOCK (sinkpad);
2332 /* we released the lock, check if the same pads are linked still */
2333 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2334 goto concurrent_link;
2336 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2339 GST_OBJECT_UNLOCK (sinkpad);
2340 GST_OBJECT_UNLOCK (srcpad);
2342 /* fire off a signal to each of the pads telling them
2343 * that they've been linked */
2344 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2345 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2347 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2348 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2350 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2353 if (G_LIKELY (parent)) {
2354 gst_element_post_message (parent,
2355 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2356 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2357 gst_object_unref (parent);
2365 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2366 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2367 GST_OBJECT_UNLOCK (sinkpad);
2368 GST_OBJECT_UNLOCK (srcpad);
2370 /* The other link operation succeeded first */
2371 result = GST_PAD_LINK_WAS_LINKED;
2376 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2377 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2378 gst_pad_link_get_name (result));
2380 GST_PAD_PEER (srcpad) = NULL;
2381 GST_PAD_PEER (sinkpad) = NULL;
2383 GST_OBJECT_UNLOCK (sinkpad);
2384 GST_OBJECT_UNLOCK (srcpad);
2392 * @srcpad: the source #GstPad to link.
2393 * @sinkpad: the sink #GstPad to link.
2395 * Links the source pad and the sink pad.
2397 * Returns: A result code indicating if the connection worked or
2403 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2405 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2409 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2411 GstPadTemplate **template_p;
2413 /* this function would need checks if it weren't static */
2415 GST_OBJECT_LOCK (pad);
2416 template_p = &pad->padtemplate;
2417 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2418 GST_OBJECT_UNLOCK (pad);
2421 gst_pad_template_pad_created (templ, pad);
2425 * gst_pad_get_pad_template:
2428 * Gets the template for @pad.
2430 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2431 * instantiated, or %NULL if this pad has no template. Unref after
2435 gst_pad_get_pad_template (GstPad * pad)
2437 GstPadTemplate *templ;
2439 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2441 templ = GST_PAD_PAD_TEMPLATE (pad);
2443 return (templ ? gst_object_ref (templ) : NULL);
2447 * gst_pad_has_current_caps:
2448 * @pad: a #GstPad to check
2450 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2452 * Returns: TRUE when @pad has caps associated with it.
2455 gst_pad_has_current_caps (GstPad * pad)
2460 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2462 GST_OBJECT_LOCK (pad);
2463 caps = get_pad_caps (pad);
2464 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2465 "check current pad caps %" GST_PTR_FORMAT, caps);
2466 result = (caps != NULL);
2467 GST_OBJECT_UNLOCK (pad);
2473 * gst_pad_get_current_caps:
2474 * @pad: a #GstPad to get the current capabilities of.
2476 * Gets the capabilities currently configured on @pad with the last
2477 * #GST_EVENT_CAPS event.
2479 * Returns: the current caps of the pad with incremented ref-count.
2482 gst_pad_get_current_caps (GstPad * pad)
2486 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2488 GST_OBJECT_LOCK (pad);
2489 if ((result = get_pad_caps (pad)))
2490 gst_caps_ref (result);
2491 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2492 "get current pad caps %" GST_PTR_FORMAT, result);
2493 GST_OBJECT_UNLOCK (pad);
2499 * gst_pad_get_pad_template_caps:
2500 * @pad: a #GstPad to get the template capabilities from.
2502 * Gets the capabilities for @pad's template.
2504 * Returns: (transfer full): the #GstCaps of this pad template.
2505 * Unref after usage.
2508 gst_pad_get_pad_template_caps (GstPad * pad)
2510 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2512 if (GST_PAD_PAD_TEMPLATE (pad))
2513 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2515 return gst_caps_ref (GST_CAPS_ANY);
2520 * @pad: a #GstPad to get the peer of.
2522 * Gets the peer of @pad. This function refs the peer pad so
2523 * you need to unref it after use.
2525 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2530 gst_pad_get_peer (GstPad * pad)
2534 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2536 GST_OBJECT_LOCK (pad);
2537 result = GST_PAD_PEER (pad);
2539 gst_object_ref (result);
2540 GST_OBJECT_UNLOCK (pad);
2546 * gst_pad_get_allowed_caps:
2549 * Gets the capabilities of the allowed media types that can flow through
2550 * @pad and its peer.
2552 * The allowed capabilities is calculated as the intersection of the results of
2553 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2554 * on the resulting caps.
2556 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2557 * caps when you no longer need it. This function returns NULL when @pad
2563 gst_pad_get_allowed_caps (GstPad * pad)
2569 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2571 GST_OBJECT_LOCK (pad);
2572 peer = GST_PAD_PEER (pad);
2573 if (G_UNLIKELY (peer == NULL))
2576 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2578 gst_object_ref (peer);
2579 GST_OBJECT_UNLOCK (pad);
2580 mycaps = gst_pad_query_caps (pad, NULL);
2582 caps = gst_pad_query_caps (peer, mycaps);
2583 gst_object_unref (peer);
2585 gst_caps_unref (mycaps);
2587 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2594 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2595 GST_OBJECT_UNLOCK (pad);
2602 * gst_pad_iterate_internal_links_default:
2603 * @pad: the #GstPad to get the internal links of.
2604 * @parent: (allow-none): the parent of @pad or NULL
2606 * Iterate the list of pads to which the given pad is linked to inside of
2607 * the parent element.
2608 * This is the default handler, and thus returns an iterator of all of the
2609 * pads inside the parent element with opposite direction.
2611 * The caller must free this iterator after use with gst_iterator_free().
2613 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2614 * returned pad with gst_object_unref().
2617 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2624 GstElement *eparent;
2626 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2628 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2629 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2631 GST_OBJECT_LOCK (pad);
2632 eparent = GST_PAD_PARENT (pad);
2633 if (!eparent || !GST_IS_ELEMENT (eparent))
2636 gst_object_ref (eparent);
2637 GST_OBJECT_UNLOCK (pad);
2640 if (pad->direction == GST_PAD_SRC)
2641 padlist = &eparent->sinkpads;
2643 padlist = &eparent->srcpads;
2645 GST_DEBUG_OBJECT (pad, "Making iterator");
2647 cookie = &eparent->pads_cookie;
2649 lock = GST_OBJECT_GET_LOCK (eparent);
2651 res = gst_iterator_new_list (GST_TYPE_PAD,
2652 lock, cookie, padlist, (GObject *) owner, NULL);
2654 gst_object_unref (owner);
2661 GST_OBJECT_UNLOCK (pad);
2662 GST_DEBUG_OBJECT (pad, "no parent element");
2668 * gst_pad_iterate_internal_links:
2669 * @pad: the GstPad to get the internal links of.
2671 * Gets an iterator for the pads to which the given pad is linked to inside
2672 * of the parent element.
2674 * Each #GstPad element yielded by the iterator will have its refcount increased,
2675 * so unref after use.
2677 * Free-function: gst_iterator_free
2679 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2680 * pad does not have an iterator function configured. Use
2681 * gst_iterator_free() after usage.
2684 gst_pad_iterate_internal_links (GstPad * pad)
2686 GstIterator *res = NULL;
2689 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2691 GST_OBJECT_LOCK (pad);
2692 ACQUIRE_PARENT (pad, parent, no_parent);
2693 GST_OBJECT_UNLOCK (pad);
2695 if (GST_PAD_ITERINTLINKFUNC (pad))
2696 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2698 RELEASE_PARENT (parent);
2705 GST_DEBUG_OBJECT (pad, "no parent");
2706 GST_OBJECT_UNLOCK (pad);
2714 * @forward: (scope call): a #GstPadForwardFunction
2715 * @user_data: user data passed to @forward
2717 * Calls @forward for all internally linked pads of @pad. This function deals with
2718 * dynamically changing internal pads and will make sure that the @forward
2719 * function is only called once for each pad.
2721 * When @forward returns TRUE, no further pads will be processed.
2723 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2726 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2729 gboolean result = FALSE;
2731 gboolean done = FALSE;
2732 GValue item = { 0, };
2733 GList *pushed_pads = NULL;
2735 iter = gst_pad_iterate_internal_links (pad);
2741 switch (gst_iterator_next (iter, &item)) {
2742 case GST_ITERATOR_OK:
2746 intpad = g_value_get_object (&item);
2748 /* if already pushed, skip. FIXME, find something faster to tag pads */
2749 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2750 g_value_reset (&item);
2754 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2755 GST_DEBUG_PAD_NAME (intpad));
2756 done = result = forward (intpad, user_data);
2758 pushed_pads = g_list_prepend (pushed_pads, intpad);
2760 g_value_reset (&item);
2763 case GST_ITERATOR_RESYNC:
2764 /* We don't reset the result here because we don't push the event
2765 * again on pads that got the event already and because we need
2766 * to consider the result of the previous pushes */
2767 gst_iterator_resync (iter);
2769 case GST_ITERATOR_ERROR:
2770 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2773 case GST_ITERATOR_DONE:
2778 g_value_unset (&item);
2779 gst_iterator_free (iter);
2781 g_list_free (pushed_pads);
2791 gboolean dispatched;
2795 event_forward_func (GstPad * pad, EventData * data)
2797 /* for each pad we send to, we should ref the event; it's up
2798 * to downstream to unref again when handled. */
2799 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2800 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2802 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2804 data->dispatched = TRUE;
2811 * gst_pad_event_default:
2812 * @pad: a #GstPad to call the default event handler on.
2813 * @parent: (allow-none): the parent of @pad or NULL
2814 * @event: (transfer full): the #GstEvent to handle.
2816 * Invokes the default event handler for the given pad.
2818 * The EOS event will pause the task associated with @pad before it is forwarded
2819 * to all internally linked pads,
2821 * The the event is sent to all pads internally linked to @pad. This function
2822 * takes ownership of @event.
2824 * Returns: TRUE if the event was sent successfully.
2827 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2829 gboolean result, forward = TRUE;
2831 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2832 g_return_val_if_fail (event != NULL, FALSE);
2834 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2837 switch (GST_EVENT_TYPE (event)) {
2838 case GST_EVENT_CAPS:
2839 forward = GST_PAD_IS_PROXY_CAPS (pad);
2850 data.dispatched = FALSE;
2851 data.result = FALSE;
2853 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2855 /* for sinkpads without a parent element or without internal links, nothing
2856 * will be dispatched but we still want to return TRUE. */
2857 if (data.dispatched)
2858 result = data.result;
2863 gst_event_unref (event);
2868 /* Default accept caps implementation just checks against
2869 * the allowed caps for the pad */
2871 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2873 /* get the caps and see if it intersects to something not empty */
2874 GstCaps *caps, *allowed;
2877 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2879 /* first forward the query to internally linked pads when we are dealing with
2881 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2882 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2887 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2888 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2890 gst_query_parse_accept_caps (query, &caps);
2891 allowed = gst_pad_query_caps (pad, caps);
2894 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2895 GST_DEBUG_OBJECT (pad,
2896 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2898 result = gst_caps_can_intersect (caps, allowed);
2900 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2901 GST_PTR_FORMAT, allowed, caps);
2902 result = gst_caps_is_subset (caps, allowed);
2904 gst_caps_unref (allowed);
2906 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2909 gst_query_set_accept_caps_result (query, result);
2915 /* Default caps implementation */
2917 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2919 GstCaps *result = NULL, *filter;
2920 GstPadTemplate *templ;
2921 gboolean fixed_caps;
2923 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2926 /* first try to proxy if we must */
2927 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2928 if ((gst_pad_proxy_query_caps (pad, query))) {
2933 gst_query_parse_caps (query, &filter);
2935 /* no proxy or it failed, do default handling */
2936 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2938 GST_OBJECT_LOCK (pad);
2940 /* fixed caps, try the negotiated caps first */
2941 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2942 if ((result = get_pad_caps (pad)))
2943 goto filter_done_unlock;
2946 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2947 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2948 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2949 goto filter_done_unlock;
2953 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2954 "non-fixed pad caps: trying pad caps");
2955 /* non fixed caps, try the negotiated caps */
2956 if ((result = get_pad_caps (pad)))
2957 goto filter_done_unlock;
2960 /* this almost never happens */
2961 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2962 result = GST_CAPS_ANY;
2965 GST_OBJECT_UNLOCK (pad);
2967 /* run the filter on the result */
2969 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2970 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2971 GST_PTR_FORMAT, result, result, filter, filter);
2972 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2973 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2976 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2977 "using caps %p %" GST_PTR_FORMAT, result, result);
2978 result = gst_caps_ref (result);
2980 gst_query_set_caps_result (query, result);
2981 gst_caps_unref (result);
2991 gboolean dispatched;
2995 query_forward_func (GstPad * pad, QueryData * data)
2997 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2998 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3000 data->result |= gst_pad_peer_query (pad, data->query);
3002 data->dispatched = TRUE;
3004 /* stop on first successful reply */
3005 return data->result;
3009 * gst_pad_query_default:
3010 * @pad: a #GstPad to call the default query handler on.
3011 * @parent: (allow-none): the parent of @pad or NULL
3012 * @query: (transfer none): the #GstQuery to handle.
3014 * Invokes the default query handler for the given pad.
3015 * The query is sent to all pads internally linked to @pad. Note that
3016 * if there are many possible sink pads that are internally linked to
3017 * @pad, only one will be sent the query.
3018 * Multi-sinkpad elements should implement custom query handlers.
3020 * Returns: TRUE if the query was performed successfully.
3023 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3025 gboolean forward, ret = FALSE;
3027 switch (GST_QUERY_TYPE (query)) {
3028 case GST_QUERY_SCHEDULING:
3029 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3031 case GST_QUERY_ALLOCATION:
3032 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3034 case GST_QUERY_ACCEPT_CAPS:
3035 ret = gst_pad_query_accept_caps_default (pad, query);
3038 case GST_QUERY_CAPS:
3039 ret = gst_pad_query_caps_default (pad, query);
3042 case GST_QUERY_POSITION:
3043 case GST_QUERY_SEEKING:
3044 case GST_QUERY_FORMATS:
3045 case GST_QUERY_LATENCY:
3046 case GST_QUERY_JITTER:
3047 case GST_QUERY_RATE:
3048 case GST_QUERY_CONVERT:
3054 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3055 query, GST_QUERY_TYPE_NAME (query));
3061 data.dispatched = FALSE;
3062 data.result = FALSE;
3064 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3066 if (data.dispatched) {
3069 /* nothing dispatched, assume drained */
3070 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3080 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3082 GstPad *pad = data->pad;
3083 GstPadProbeInfo *info = data->info;
3084 GstPadProbeType type, flags;
3085 GstPadProbeCallback callback;
3086 GstPadProbeReturn ret;
3088 /* if we have called this callback, do nothing */
3089 if (PROBE_COOKIE (hook) == data->cookie) {
3090 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3091 "hook %lu, cookie %u already called", hook->hook_id,
3092 PROBE_COOKIE (hook));
3096 PROBE_COOKIE (hook) = data->cookie;
3098 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3101 /* one of the data types for non-idle probes */
3102 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3103 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3105 /* one of the scheduling types */
3106 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3108 /* one of the blocking types must match */
3109 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3110 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3112 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3113 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3115 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3116 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3117 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3120 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3121 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3122 PROBE_COOKIE (hook), flags);
3124 data->marshalled = TRUE;
3126 callback = (GstPadProbeCallback) hook->func;
3127 if (callback == NULL)
3130 info->id = hook->hook_id;
3132 GST_OBJECT_UNLOCK (pad);
3134 ret = callback (pad, info, hook->data);
3136 GST_OBJECT_LOCK (pad);
3139 case GST_PAD_PROBE_REMOVE:
3140 /* remove the probe */
3141 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3142 cleanup_hook (pad, hook);
3144 case GST_PAD_PROBE_DROP:
3145 /* need to drop the data, make sure other probes don't get called
3147 GST_DEBUG_OBJECT (pad, "asked to drop item");
3148 info->type = GST_PAD_PROBE_TYPE_INVALID;
3149 data->dropped = TRUE;
3151 case GST_PAD_PROBE_PASS:
3152 /* inform the pad block to let things pass */
3153 GST_DEBUG_OBJECT (pad, "asked to pass item");
3156 case GST_PAD_PROBE_OK:
3157 GST_DEBUG_OBJECT (pad, "probe returned OK");
3160 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3167 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3168 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3169 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3174 /* a probe that does not take or return any data */
3175 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3177 if (G_UNLIKELY (pad->num_probes)) { \
3178 /* pass NULL as the data item */ \
3179 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3180 ret = do_probe_callbacks (pad, &info, defaultval); \
3181 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3186 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3188 if (G_UNLIKELY (pad->num_probes)) { \
3189 /* pass the data item */ \
3190 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3191 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3192 /* store the possibly updated data item */ \
3193 data = GST_PAD_PROBE_INFO_DATA (&info); \
3194 /* if something went wrong, exit */ \
3195 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3200 #define PROBE_PUSH(pad,mask,data,label) \
3201 PROBE_FULL(pad, mask, data, -1, -1, label);
3202 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3203 PROBE_FULL(pad, mask, data, offs, size, label);
3205 static GstFlowReturn
3206 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3207 GstFlowReturn defaultval)
3216 data.marshalled = FALSE;
3217 data.dropped = FALSE;
3218 data.cookie = ++pad->priv->probe_cookie;
3221 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3224 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3225 "do probes cookie %u", data.cookie);
3226 cookie = pad->priv->probe_list_cookie;
3228 g_hook_list_marshal (&pad->probes, TRUE,
3229 (GHookMarshaller) probe_hook_marshal, &data);
3231 /* if the list changed, call the new callbacks (they will not have their
3232 * cookie set to data.cookie */
3233 if (cookie != pad->priv->probe_list_cookie) {
3234 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3235 "probe list changed, restarting");
3239 /* the first item that dropped will stop the hooks and then we drop here */
3243 /* if no handler matched and we are blocking, let the item pass */
3244 if (!data.marshalled && is_block)
3247 /* At this point, all handlers returned either OK or PASS. If one handler
3248 * returned PASS, let the item pass */
3253 while (GST_PAD_IS_BLOCKED (pad)) {
3254 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3255 "we are blocked %d times", pad->num_blocked);
3257 /* we might have released the lock */
3258 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3261 /* now we block the streaming thread. It can be unlocked when we
3262 * deactivate the pad (which will also set the FLUSHING flag) or
3263 * when the pad is unblocked. A flushing event will also unblock
3264 * the pad after setting the FLUSHING flag. */
3265 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3266 "Waiting to be unblocked or set flushing");
3267 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3268 GST_PAD_BLOCK_WAIT (pad);
3269 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3270 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3272 /* if the list changed, call the new callbacks (they will not have their
3273 * cookie set to data.cookie */
3274 if (cookie != pad->priv->probe_list_cookie) {
3275 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3276 "probe list changed, restarting");
3280 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3290 GST_DEBUG_OBJECT (pad, "pad is flushing");
3291 return GST_FLOW_FLUSHING;
3295 GST_DEBUG_OBJECT (pad, "data is dropped");
3296 return GST_FLOW_CUSTOM_SUCCESS;
3300 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3301 GST_DEBUG_OBJECT (pad, "data is passed");
3309 * gst_pad_get_offset:
3312 * Get the offset applied to the running time of @pad. @pad has to be a source
3315 * Returns: the offset.
3318 gst_pad_get_offset (GstPad * pad)
3322 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3324 GST_OBJECT_LOCK (pad);
3325 result = pad->offset;
3326 GST_OBJECT_UNLOCK (pad);
3332 * gst_pad_set_offset:
3334 * @offset: the offset
3336 * Set the offset that will be applied to the running time of @pad.
3339 gst_pad_set_offset (GstPad * pad, gint64 offset)
3343 g_return_if_fail (GST_IS_PAD (pad));
3345 GST_OBJECT_LOCK (pad);
3346 /* if nothing changed, do nothing */
3347 if (pad->offset == offset)
3350 pad->offset = offset;
3351 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3353 /* sinkpads will apply their offset the next time a segment
3354 * event is received. */
3355 if (GST_PAD_IS_SINK (pad))
3358 /* resend the last segment event on next buffer push */
3359 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3360 ev->received = FALSE;
3361 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3365 GST_OBJECT_UNLOCK (pad);
3372 /* If TRUE and ret is not OK this means
3373 * that pushing the EOS event failed
3377 /* If called for an event this is
3378 * the event that would be pushed
3379 * next. Don't forward sticky events
3380 * that would come after that */
3384 /* should be called with pad LOCK */
3386 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3388 PushStickyData *data = user_data;
3389 GstEvent *event = ev->event;
3392 GST_DEBUG_OBJECT (pad, "event %s was already received",
3393 GST_EVENT_TYPE_NAME (event));
3397 /* If we're called because of an sticky event, only forward
3398 * events that would come before this new event and the
3400 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3401 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3402 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3403 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3405 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3406 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3409 switch (data->ret) {
3411 ev->received = TRUE;
3412 GST_DEBUG_OBJECT (pad, "event %s marked received",
3413 GST_EVENT_TYPE_NAME (event));
3415 case GST_FLOW_CUSTOM_SUCCESS:
3416 /* we can't assume the event is received when it was dropped */
3417 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3418 GST_EVENT_TYPE_NAME (event));
3419 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3420 data->ret = GST_FLOW_OK;
3422 case GST_FLOW_CUSTOM_SUCCESS_1:
3423 /* event was ignored and should be sent later */
3424 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3425 GST_EVENT_TYPE_NAME (event));
3426 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3427 data->ret = GST_FLOW_OK;
3429 case GST_FLOW_NOT_LINKED:
3430 /* not linked is not a problem, we are sticky so the event will be
3431 * sent later but only for non-EOS events */
3432 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3433 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3434 data->ret = GST_FLOW_OK;
3435 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3438 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3439 gst_flow_get_name (data->ret));
3440 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3444 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3445 data->was_eos = TRUE;
3447 return data->ret == GST_FLOW_OK;
3450 /* check sticky events and push them when needed. should be called
3452 static inline GstFlowReturn
3453 check_sticky (GstPad * pad, GstEvent * event)
3455 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3457 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3458 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3460 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3461 events_foreach (pad, push_sticky, &data);
3463 /* If there's an EOS event we must push it downstream
3464 * even if sending a previous sticky event failed.
3465 * Otherwise the pipeline might wait forever for EOS.
3467 * Only do this if pushing another event than the EOS
3470 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3471 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3473 if (ev && !ev->received) {
3474 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3475 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3476 /* the event could have been dropped. Because this can only
3477 * happen if the user asked for it, it's not an error */
3478 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3479 data.ret = GST_FLOW_OK;
3489 * @pad: a #GstPad to invoke the default query on.
3490 * @query: (transfer none): the #GstQuery to perform.
3492 * Dispatches a query to a pad. The query should have been allocated by the
3493 * caller via one of the type-specific allocation functions. The element that
3494 * the pad belongs to is responsible for filling the query with an appropriate
3495 * response, which should then be parsed with a type-specific query parsing
3498 * Again, the caller is responsible for both the allocation and deallocation of
3499 * the query structure.
3501 * Please also note that some queries might need a running pipeline to work.
3503 * Returns: TRUE if the query could be performed.
3506 gst_pad_query (GstPad * pad, GstQuery * query)
3509 gboolean res, serialized;
3510 GstPadQueryFunction func;
3511 GstPadProbeType type;
3514 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3515 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3517 if (GST_PAD_IS_SRC (pad)) {
3518 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3519 goto wrong_direction;
3520 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3521 } else if (GST_PAD_IS_SINK (pad)) {
3522 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3523 goto wrong_direction;
3524 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3526 goto unknown_direction;
3528 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3529 GST_QUERY_TYPE_NAME (query));
3531 serialized = GST_QUERY_IS_SERIALIZED (query);
3532 if (G_UNLIKELY (serialized))
3533 GST_PAD_STREAM_LOCK (pad);
3535 GST_OBJECT_LOCK (pad);
3536 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3537 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3538 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3540 ACQUIRE_PARENT (pad, parent, no_parent);
3541 GST_OBJECT_UNLOCK (pad);
3543 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3546 res = func (pad, parent, query);
3548 RELEASE_PARENT (parent);
3550 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3551 GST_QUERY_TYPE_NAME (query), res);
3556 GST_OBJECT_LOCK (pad);
3557 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3558 GST_OBJECT_UNLOCK (pad);
3560 if (G_UNLIKELY (serialized))
3561 GST_PAD_STREAM_UNLOCK (pad);
3568 g_warning ("pad %s:%s query %s in wrong direction",
3569 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3574 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3579 GST_DEBUG_OBJECT (pad, "had no parent");
3580 GST_OBJECT_UNLOCK (pad);
3581 if (G_UNLIKELY (serialized))
3582 GST_PAD_STREAM_UNLOCK (pad);
3587 GST_DEBUG_OBJECT (pad, "had no query function");
3588 RELEASE_PARENT (parent);
3589 if (G_UNLIKELY (serialized))
3590 GST_PAD_STREAM_UNLOCK (pad);
3595 GST_DEBUG_OBJECT (pad, "query failed");
3596 if (G_UNLIKELY (serialized))
3597 GST_PAD_STREAM_UNLOCK (pad);
3602 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3603 GST_OBJECT_UNLOCK (pad);
3604 if (G_UNLIKELY (serialized))
3605 GST_PAD_STREAM_UNLOCK (pad);
3607 /* if a probe dropped, we don't sent it further but assume that the probe
3608 * answered the query and return TRUE */
3609 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3619 * gst_pad_peer_query:
3620 * @pad: a #GstPad to invoke the peer query on.
3621 * @query: (transfer none): the #GstQuery to perform.
3623 * Performs gst_pad_query() on the peer of @pad.
3625 * The caller is responsible for both the allocation and deallocation of
3626 * the query structure.
3628 * Returns: TRUE if the query could be performed. This function returns %FALSE
3629 * if @pad has no peer.
3632 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3635 GstPadProbeType type;
3636 gboolean res, serialized;
3639 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3640 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3642 if (GST_PAD_IS_SRC (pad)) {
3643 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3644 goto wrong_direction;
3645 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3646 } else if (GST_PAD_IS_SINK (pad)) {
3647 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3648 goto wrong_direction;
3649 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3651 goto unknown_direction;
3653 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3654 GST_QUERY_TYPE_NAME (query));
3656 serialized = GST_QUERY_IS_SERIALIZED (query);
3658 GST_OBJECT_LOCK (pad);
3659 if (GST_PAD_IS_SRC (pad) && serialized) {
3660 /* all serialized queries on the srcpad trigger push of
3662 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3666 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3667 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3668 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3670 peerpad = GST_PAD_PEER (pad);
3671 if (G_UNLIKELY (peerpad == NULL))
3674 gst_object_ref (peerpad);
3675 GST_OBJECT_UNLOCK (pad);
3677 res = gst_pad_query (peerpad, query);
3679 gst_object_unref (peerpad);
3684 GST_OBJECT_LOCK (pad);
3685 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3686 GST_OBJECT_UNLOCK (pad);
3693 g_warning ("pad %s:%s query %s in wrong direction",
3694 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3699 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3704 GST_WARNING_OBJECT (pad, "could not send sticky events");
3705 GST_OBJECT_UNLOCK (pad);
3710 GST_INFO_OBJECT (pad, "pad has no peer");
3711 GST_OBJECT_UNLOCK (pad);
3716 GST_DEBUG_OBJECT (pad, "query failed");
3721 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3722 GST_OBJECT_UNLOCK (pad);
3724 /* if a probe dropped, we don't sent it further but assume that the probe
3725 * answered the query and return TRUE */
3726 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3735 /**********************************************************************
3736 * Data passing functions
3739 /* this is the chain function that does not perform the additional argument
3740 * checking for that little extra speed.
3742 static inline GstFlowReturn
3743 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3748 GST_PAD_STREAM_LOCK (pad);
3750 GST_OBJECT_LOCK (pad);
3751 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3754 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3757 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3760 #ifndef G_DISABLE_ASSERT
3761 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3762 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3764 ":%s:<%s:%s> Got data flow before stream-start event",
3765 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3767 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3769 ":%s:<%s:%s> Got data flow before segment event",
3770 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3772 pad->priv->last_cookie = pad->priv->events_cookie;
3776 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3778 PROBE_PUSH (pad, type, data, probe_stopped);
3780 parent = GST_OBJECT_PARENT (pad);
3781 GST_OBJECT_UNLOCK (pad);
3783 /* NOTE: we read the chainfunc unlocked.
3784 * we cannot hold the lock for the pad so we might send
3785 * the data to the wrong function. This is not really a
3786 * problem since functions are assigned at creation time
3787 * and don't change that often... */
3788 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3789 GstPadChainFunction chainfunc;
3791 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3794 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3795 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3796 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3798 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3800 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3801 "called chainfunction &%s with buffer %p, returned %s",
3802 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3804 GstPadChainListFunction chainlistfunc;
3806 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3809 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3810 "calling chainlistfunction &%s",
3811 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3813 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3815 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3816 "called chainlistfunction &%s, returned %s",
3817 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3820 GST_PAD_STREAM_UNLOCK (pad);
3827 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3828 "chaining, but pad was flushing");
3829 GST_OBJECT_UNLOCK (pad);
3830 GST_PAD_STREAM_UNLOCK (pad);
3831 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3832 return GST_FLOW_FLUSHING;
3836 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3837 GST_OBJECT_UNLOCK (pad);
3838 GST_PAD_STREAM_UNLOCK (pad);
3839 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3840 return GST_FLOW_EOS;
3844 g_critical ("chain on pad %s:%s but it was not in push mode",
3845 GST_DEBUG_PAD_NAME (pad));
3846 GST_OBJECT_UNLOCK (pad);
3847 GST_PAD_STREAM_UNLOCK (pad);
3848 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3849 return GST_FLOW_ERROR;
3853 GST_OBJECT_UNLOCK (pad);
3854 GST_PAD_STREAM_UNLOCK (pad);
3855 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3858 case GST_FLOW_CUSTOM_SUCCESS:
3859 GST_DEBUG_OBJECT (pad, "dropped buffer");
3863 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3870 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3871 g_critical ("chain on pad %s:%s but it has no chainfunction",
3872 GST_DEBUG_PAD_NAME (pad));
3873 GST_PAD_STREAM_UNLOCK (pad);
3874 return GST_FLOW_NOT_SUPPORTED;
3880 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3881 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3884 * Chain a buffer to @pad.
3886 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3888 * If the buffer type is not acceptable for @pad (as negotiated with a
3889 * preceding GST_EVENT_CAPS event), this function returns
3890 * #GST_FLOW_NOT_NEGOTIATED.
3892 * The function proceeds calling the chain function installed on @pad (see
3893 * gst_pad_set_chain_function()) and the return value of that function is
3894 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3897 * In all cases, success or failure, the caller loses its reference to @buffer
3898 * after calling this function.
3900 * Returns: a #GstFlowReturn from the pad.
3905 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3907 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3908 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3909 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3911 return gst_pad_chain_data_unchecked (pad,
3912 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3915 static GstFlowReturn
3916 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3917 GstBufferList * list)
3923 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3925 len = gst_buffer_list_length (list);
3928 for (i = 0; i < len; i++) {
3929 buffer = gst_buffer_list_get (list, i);
3931 gst_pad_chain_data_unchecked (pad,
3932 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3933 gst_buffer_ref (buffer));
3934 if (ret != GST_FLOW_OK)
3937 gst_buffer_list_unref (list);
3943 * gst_pad_chain_list:
3944 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3945 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3948 * Chain a bufferlist to @pad.
3950 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3952 * If @pad was not negotiated properly with a CAPS event, this function
3953 * returns #GST_FLOW_NOT_NEGOTIATED.
3955 * The function proceeds calling the chainlist function installed on @pad (see
3956 * gst_pad_set_chain_list_function()) and the return value of that function is
3957 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3958 * chainlist function.
3960 * In all cases, success or failure, the caller loses its reference to @list
3961 * after calling this function.
3965 * Returns: a #GstFlowReturn from the pad.
3968 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3970 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3971 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3972 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3974 return gst_pad_chain_data_unchecked (pad,
3975 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3978 static GstFlowReturn
3979 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3984 GST_OBJECT_LOCK (pad);
3985 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3988 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3991 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3994 #ifndef G_DISABLE_ASSERT
3995 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3996 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3998 ":%s:<%s:%s> Got data flow before stream-start event",
3999 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4001 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4003 ":%s:<%s:%s> Got data flow before segment event",
4004 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4006 pad->priv->last_cookie = pad->priv->events_cookie;
4010 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4013 /* do block probes */
4014 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4016 /* recheck sticky events because the probe might have cause a relink */
4017 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4020 /* do post-blocking probes */
4021 PROBE_PUSH (pad, type, data, probe_stopped);
4023 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4026 /* take ref to peer pad before releasing the lock */
4027 gst_object_ref (peer);
4029 GST_OBJECT_UNLOCK (pad);
4031 ret = gst_pad_chain_data_unchecked (peer, type, data);
4033 gst_object_unref (peer);
4035 GST_OBJECT_LOCK (pad);
4037 if (pad->priv->using == 0) {
4038 /* pad is not active anymore, trigger idle callbacks */
4039 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4040 probe_stopped, ret);
4042 GST_OBJECT_UNLOCK (pad);
4046 /* ERROR recovery here */
4050 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4051 "pushing, but pad was flushing");
4052 GST_OBJECT_UNLOCK (pad);
4053 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4054 return GST_FLOW_FLUSHING;
4058 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4059 GST_OBJECT_UNLOCK (pad);
4060 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4061 return GST_FLOW_EOS;
4065 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4066 GST_DEBUG_PAD_NAME (pad));
4067 GST_OBJECT_UNLOCK (pad);
4068 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4069 return GST_FLOW_ERROR;
4073 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4074 "error pushing events, return %s", gst_flow_get_name (ret));
4075 GST_OBJECT_UNLOCK (pad);
4076 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4081 GST_OBJECT_UNLOCK (pad);
4082 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4085 case GST_FLOW_CUSTOM_SUCCESS:
4086 GST_DEBUG_OBJECT (pad, "dropped buffer");
4090 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4097 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4098 "pushing, but it was not linked");
4099 GST_OBJECT_UNLOCK (pad);
4100 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4101 return GST_FLOW_NOT_LINKED;
4107 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4108 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4111 * Pushes a buffer to the peer of @pad.
4113 * This function will call installed block probes before triggering any
4114 * installed data probes.
4116 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4117 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4120 * In all cases, success or failure, the caller loses its reference to @buffer
4121 * after calling this function.
4123 * Returns: a #GstFlowReturn from the peer pad.
4128 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4130 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4131 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4132 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4134 return gst_pad_push_data (pad,
4135 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4139 * gst_pad_push_list:
4140 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4141 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4144 * Pushes a buffer list to the peer of @pad.
4146 * This function will call installed block probes before triggering any
4147 * installed data probes.
4149 * The function proceeds calling the chain function on the peer pad and returns
4150 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4151 * be returned. If the peer pad does not have any installed chainlist function
4152 * every group buffer of the list will be merged into a normal #GstBuffer and
4153 * chained via gst_pad_chain().
4155 * In all cases, success or failure, the caller loses its reference to @list
4156 * after calling this function.
4158 * Returns: a #GstFlowReturn from the peer pad.
4163 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4165 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4166 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4167 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4169 return gst_pad_push_data (pad,
4170 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4173 static GstFlowReturn
4174 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4175 GstBuffer ** buffer)
4178 GstPadGetRangeFunction getrangefunc;
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_MODE (pad) != GST_PAD_MODE_PULL))
4191 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4196 /* when one of the probes returns DROPPED, probe_stopped will be called
4197 * and we skip calling the getrange function, res_buf should then contain a
4198 * valid result buffer */
4199 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4200 res_buf, offset, size, probe_stopped);
4202 /* recheck sticky events because the probe might have cause a relink */
4203 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4206 ACQUIRE_PARENT (pad, parent, no_parent);
4207 GST_OBJECT_UNLOCK (pad);
4209 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4212 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4213 "calling getrangefunc %s, offset %"
4214 G_GUINT64_FORMAT ", size %u",
4215 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4217 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4219 RELEASE_PARENT (parent);
4221 if (G_UNLIKELY (ret != GST_FLOW_OK))
4222 goto get_range_failed;
4224 /* can only fire the signal if we have a valid buffer */
4225 GST_OBJECT_LOCK (pad);
4227 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4228 res_buf, offset, size, probe_stopped_unref);
4229 GST_OBJECT_UNLOCK (pad);
4231 GST_PAD_STREAM_UNLOCK (pad);
4240 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4241 "getrange, but pad was flushing");
4242 GST_OBJECT_UNLOCK (pad);
4243 GST_PAD_STREAM_UNLOCK (pad);
4244 return GST_FLOW_FLUSHING;
4248 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4249 GST_DEBUG_PAD_NAME (pad));
4250 GST_OBJECT_UNLOCK (pad);
4251 GST_PAD_STREAM_UNLOCK (pad);
4252 return GST_FLOW_ERROR;
4256 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4257 GST_OBJECT_UNLOCK (pad);
4258 GST_PAD_STREAM_UNLOCK (pad);
4263 GST_DEBUG_OBJECT (pad, "no parent");
4264 GST_OBJECT_UNLOCK (pad);
4265 GST_PAD_STREAM_UNLOCK (pad);
4266 return GST_FLOW_FLUSHING;
4270 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4271 GST_DEBUG_PAD_NAME (pad));
4272 RELEASE_PARENT (parent);
4273 GST_PAD_STREAM_UNLOCK (pad);
4274 return GST_FLOW_NOT_SUPPORTED;
4278 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4279 "probe returned %s", gst_flow_get_name (ret));
4280 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4282 /* the probe filled the buffer and asks us to not call the getrange
4283 * anymore, we continue with the post probes then. */
4284 GST_DEBUG_OBJECT (pad, "handled buffer");
4288 /* no buffer, we are EOS */
4289 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4293 GST_OBJECT_UNLOCK (pad);
4294 GST_PAD_STREAM_UNLOCK (pad);
4298 probe_stopped_unref:
4300 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4301 "probe returned %s", gst_flow_get_name (ret));
4302 /* if we drop here, it signals EOS */
4303 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4305 GST_OBJECT_UNLOCK (pad);
4306 GST_PAD_STREAM_UNLOCK (pad);
4307 if (*buffer == NULL)
4308 gst_buffer_unref (res_buf);
4313 GST_PAD_STREAM_UNLOCK (pad);
4314 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4315 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4316 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4322 * gst_pad_get_range:
4323 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4324 * @offset: The start offset of the buffer
4325 * @size: The length of the buffer
4326 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4327 * returns #GST_FLOW_ERROR if %NULL.
4329 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4330 * immediately and @buffer is %NULL.
4332 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4333 * description of a getrange function. If @pad has no getrange function
4334 * installed (see gst_pad_set_getrange_function()) this function returns
4335 * #GST_FLOW_NOT_SUPPORTED.
4337 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4338 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4339 * must be freed with gst_buffer_unref() after usage.
4341 * When @buffer points to a variable that points to a valid #GstBuffer, the
4342 * buffer will be filled with the result data when this function returns
4343 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4344 * @size bytes will be filled in the result buffer and its size will be updated
4347 * Note that less than @size bytes can be returned in @buffer when, for example,
4348 * an EOS condition is near or when @buffer is not large enough to hold @size
4349 * bytes. The caller should check the result buffer size to get the result size.
4351 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4352 * will be unchanged.
4354 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4356 * Returns: a #GstFlowReturn from the pad.
4361 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4362 GstBuffer ** buffer)
4364 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4365 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4366 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4367 g_return_val_if_fail (*buffer == NULL
4368 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4370 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4374 * gst_pad_pull_range:
4375 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4376 * @offset: The start offset of the buffer
4377 * @size: The length of the buffer
4378 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4379 * GST_FLOW_ERROR if %NULL.
4381 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4383 * This function will first trigger the pad block signal if it was
4386 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4387 * function returns the result of gst_pad_get_range() on the peer pad.
4388 * See gst_pad_get_range() for a list of return values and for the
4389 * semantics of the arguments of this function.
4391 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4392 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4393 * must be freed with gst_buffer_unref() after usage. When this function
4394 * returns any other result value, @buffer will still point to NULL.
4396 * When @buffer points to a variable that points to a valid #GstBuffer, the
4397 * buffer will be filled with the result data when this function returns
4398 * #GST_FLOW_OK. When this function returns any other result value,
4399 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4400 * @size bytes will be filled in the result buffer and its size will be updated
4403 * Note that less than @size bytes can be returned in @buffer when, for example,
4404 * an EOS condition is near or when @buffer is not large enough to hold @size
4405 * bytes. The caller should check the result buffer size to get the result size.
4407 * Returns: a #GstFlowReturn from the peer pad.
4412 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4413 GstBuffer ** buffer)
4419 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4420 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4421 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4422 g_return_val_if_fail (*buffer == NULL
4423 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4425 GST_OBJECT_LOCK (pad);
4426 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4429 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4434 /* when one of the probes returns DROPPED, probe_stopped will be
4435 * called and we skip calling the peer getrange function. *buffer should then
4436 * contain a valid buffer */
4437 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4438 res_buf, offset, size, probe_stopped);
4440 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4443 gst_object_ref (peer);
4445 GST_OBJECT_UNLOCK (pad);
4447 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4449 gst_object_unref (peer);
4451 GST_OBJECT_LOCK (pad);
4453 if (pad->priv->using == 0) {
4454 /* pad is not active anymore, trigger idle callbacks */
4455 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4456 probe_stopped_unref, ret);
4459 if (G_UNLIKELY (ret != GST_FLOW_OK))
4460 goto pull_range_failed;
4463 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4464 res_buf, offset, size, probe_stopped_unref);
4466 GST_OBJECT_UNLOCK (pad);
4472 /* ERROR recovery here */
4475 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4476 "pullrange, but pad was flushing");
4477 GST_OBJECT_UNLOCK (pad);
4478 return GST_FLOW_FLUSHING;
4482 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4483 GST_DEBUG_PAD_NAME (pad));
4484 GST_OBJECT_UNLOCK (pad);
4485 return GST_FLOW_ERROR;
4489 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4490 gst_flow_get_name (ret));
4491 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4493 /* the probe filled the buffer and asks us to not forward to the peer
4494 * anymore, we continue with the post probes then */
4495 GST_DEBUG_OBJECT (pad, "handled buffer");
4499 /* no buffer, we are EOS then */
4500 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4504 GST_OBJECT_UNLOCK (pad);
4509 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4510 "pulling range, but it was not linked");
4511 GST_OBJECT_UNLOCK (pad);
4512 return GST_FLOW_NOT_LINKED;
4516 GST_OBJECT_UNLOCK (pad);
4517 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4518 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4519 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4522 probe_stopped_unref:
4524 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4525 "post probe returned %s", gst_flow_get_name (ret));
4526 GST_OBJECT_UNLOCK (pad);
4527 /* if we drop here, it signals EOS */
4528 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4530 if (*buffer == NULL)
4531 gst_buffer_unref (res_buf);
4536 /* must be called with pad object lock */
4537 static GstFlowReturn
4538 store_sticky_event (GstPad * pad, GstEvent * event)
4543 gboolean res = FALSE;
4544 const gchar *name = NULL;
4545 gboolean insert = TRUE;
4547 type = GST_EVENT_TYPE (event);
4549 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4550 * otherwise they can be dropped and nothing would ever resend them.
4551 * Only do that for activated pads though, everything else is a bug!
4553 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4554 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4555 || type == GST_EVENT_EOS))))
4558 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4561 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4562 name = gst_structure_get_name (gst_event_get_structure (event));
4564 events = pad->priv->events;
4567 for (i = 0; i < len; i++) {
4568 PadEvent *ev = &g_array_index (events, PadEvent, i);
4570 if (ev->event == NULL)
4573 if (type == GST_EVENT_TYPE (ev->event)) {
4574 /* matching types, check matching name if needed */
4575 if (name && !gst_event_has_name (ev->event, name))
4579 if ((res = gst_event_replace (&ev->event, event)))
4580 ev->received = FALSE;
4586 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4587 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4588 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4589 * storing the sticky ordered we can check that this is respected. */
4590 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4591 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4593 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4594 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4595 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4596 gst_event_type_get_name (type));
4602 ev.event = gst_event_ref (event);
4603 ev.received = FALSE;
4604 g_array_insert_val (events, i, ev);
4609 pad->priv->events_cookie++;
4610 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4612 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4614 switch (GST_EVENT_TYPE (event)) {
4615 case GST_EVENT_CAPS:
4616 GST_OBJECT_UNLOCK (pad);
4618 GST_DEBUG_OBJECT (pad, "notify caps");
4619 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4621 GST_OBJECT_LOCK (pad);
4627 if (type == GST_EVENT_EOS)
4628 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4630 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4635 GST_DEBUG_OBJECT (pad, "pad is flushing");
4636 return GST_FLOW_FLUSHING;
4640 GST_DEBUG_OBJECT (pad, "pad is EOS");
4641 return GST_FLOW_EOS;
4646 * gst_pad_store_sticky_event:
4648 * @event: a #GstEvent
4650 * Store the sticky @event on @pad
4652 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4653 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4658 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4662 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4663 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4665 GST_OBJECT_LOCK (pad);
4666 ret = store_sticky_event (pad, event);
4667 GST_OBJECT_UNLOCK (pad);
4673 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4675 PushStickyData *data = user_data;
4677 /* Forward all sticky events before our current one that are pending */
4678 if (ev->event != data->event
4679 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4680 return push_sticky (pad, ev, data);
4685 /* should be called with pad LOCK */
4686 static GstFlowReturn
4687 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4688 GstPadProbeType type)
4692 GstEventType event_type;
4694 /* Two checks to be made:
4695 * . (un)set the FLUSHING flag for flushing events,
4696 * . handle pad blocking */
4697 event_type = GST_EVENT_TYPE (event);
4698 switch (event_type) {
4699 case GST_EVENT_FLUSH_START:
4700 GST_PAD_SET_FLUSHING (pad);
4702 GST_PAD_BLOCK_BROADCAST (pad);
4703 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4705 case GST_EVENT_FLUSH_STOP:
4706 GST_PAD_UNSET_FLUSHING (pad);
4708 /* Remove sticky EOS events */
4709 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4710 remove_event_by_type (pad, GST_EVENT_EOS);
4711 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4712 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4714 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4718 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4721 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4722 * checked already or this is called as part of pushing sticky events,
4723 * in which case we still want to forward the EOS event downstream.
4726 switch (GST_EVENT_TYPE (event)) {
4727 case GST_EVENT_SEGMENT:
4728 /* pass the adjusted segment event on. We need to do this even if
4729 * there is no peer pad because of the probes. */
4730 event = apply_pad_offset (pad, event);
4732 case GST_EVENT_RECONFIGURE:
4733 if (GST_PAD_IS_SINK (pad))
4734 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4739 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4740 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4745 /* send probes after modifying the events above */
4746 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4748 /* recheck sticky events because the probe might have cause a relink */
4749 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4750 && (GST_EVENT_IS_SERIALIZED (event)
4751 || GST_EVENT_IS_STICKY (event))) {
4752 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4753 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4755 /* Push all sticky events before our current one
4756 * that have changed */
4757 events_foreach (pad, sticky_changed, &data);
4760 /* now check the peer pad */
4761 peerpad = GST_PAD_PEER (pad);
4762 if (peerpad == NULL)
4765 gst_object_ref (peerpad);
4767 GST_OBJECT_UNLOCK (pad);
4769 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4770 event, GST_EVENT_TYPE_NAME (event), peerpad);
4772 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4774 /* Note: we gave away ownership of the event at this point but we can still
4775 * print the old pointer */
4776 GST_LOG_OBJECT (pad,
4777 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
4778 GST_EVENT_TYPE_NAME (event), peerpad, gst_flow_get_name (ret));
4780 gst_object_unref (peerpad);
4782 GST_OBJECT_LOCK (pad);
4784 if (pad->priv->using == 0) {
4785 /* pad is not active anymore, trigger idle callbacks */
4786 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4787 idle_probe_stopped, ret);
4791 /* ERROR handling */
4794 GST_DEBUG_OBJECT (pad, "We're flushing");
4795 gst_event_unref (event);
4796 return GST_FLOW_FLUSHING;
4800 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4801 gst_event_unref (event);
4804 case GST_FLOW_CUSTOM_SUCCESS:
4805 GST_DEBUG_OBJECT (pad, "dropped event");
4808 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4815 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4816 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4817 gst_event_unref (event);
4819 /* unlinked pads should not influence latency configuration */
4820 if (event_type == GST_EVENT_LATENCY)
4823 return GST_FLOW_NOT_LINKED;
4827 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4833 * gst_pad_push_event:
4834 * @pad: a #GstPad to push the event to.
4835 * @event: (transfer full): the #GstEvent to send to the pad.
4837 * Sends the event to the peer of the given pad. This function is
4838 * mainly used by elements to send events to their peer
4841 * This function takes ownership of the provided event so you should
4842 * gst_event_ref() it if you want to reuse the event after this call.
4844 * Returns: TRUE if the event was handled.
4849 gst_pad_push_event (GstPad * pad, GstEvent * event)
4851 gboolean res = FALSE;
4852 GstPadProbeType type;
4853 gboolean sticky, serialized;
4855 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4856 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4858 if (GST_PAD_IS_SRC (pad)) {
4859 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4860 goto wrong_direction;
4861 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4862 } else if (GST_PAD_IS_SINK (pad)) {
4863 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4864 goto wrong_direction;
4865 /* events pushed on sinkpad never are sticky */
4866 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4868 goto unknown_direction;
4870 GST_OBJECT_LOCK (pad);
4871 sticky = GST_EVENT_IS_STICKY (event);
4872 serialized = GST_EVENT_IS_SERIALIZED (event);
4875 /* srcpad sticky events are stored immediately, the received flag is set
4876 * to FALSE and will be set to TRUE when we can successfully push the
4877 * event to the peer pad */
4878 switch (store_sticky_event (pad, event)) {
4879 case GST_FLOW_FLUSHING:
4887 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4888 /* all serialized or sticky events on the srcpad trigger push of
4890 res = (check_sticky (pad, event) == GST_FLOW_OK);
4895 /* other events are pushed right away */
4896 ret = gst_pad_push_event_unchecked (pad, event, type);
4897 /* dropped events by a probe are not an error */
4898 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4900 /* Errors in sticky event pushing are no problem and ignored here
4901 * as they will cause more meaningful errors during data flow.
4902 * For EOS events, that are not followed by data flow, we still
4903 * return FALSE here though.
4905 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4907 gst_event_unref (event);
4909 GST_OBJECT_UNLOCK (pad);
4913 /* ERROR handling */
4916 g_warning ("pad %s:%s pushing %s event in wrong direction",
4917 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4918 gst_event_unref (event);
4923 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4924 gst_event_unref (event);
4929 GST_DEBUG_OBJECT (pad, "We're flushing");
4930 GST_OBJECT_UNLOCK (pad);
4931 gst_event_unref (event);
4936 GST_DEBUG_OBJECT (pad, "We're EOS");
4937 GST_OBJECT_UNLOCK (pad);
4938 gst_event_unref (event);
4943 /* Check if we can call the event function with the given event */
4944 static GstFlowReturn
4945 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4949 switch (GST_EVENT_TYPE (event)) {
4950 case GST_EVENT_CAPS:
4952 /* backwards compatibility mode for caps */
4953 gst_event_parse_caps (event, &caps);
4955 if (!gst_pad_query_accept_caps (pad, caps))
4967 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4968 "caps %" GST_PTR_FORMAT " not accepted", caps);
4969 return GST_FLOW_NOT_NEGOTIATED;
4973 static GstFlowReturn
4974 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4975 GstPadProbeType type)
4978 GstEventType event_type;
4979 gboolean serialized, need_unlock = FALSE, sticky;
4980 GstPadEventFunction eventfunc;
4983 GST_OBJECT_LOCK (pad);
4984 if (GST_PAD_IS_SINK (pad))
4985 serialized = GST_EVENT_IS_SERIALIZED (event);
4988 sticky = GST_EVENT_IS_STICKY (event);
4989 event_type = GST_EVENT_TYPE (event);
4990 switch (event_type) {
4991 case GST_EVENT_FLUSH_START:
4992 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4993 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4995 /* can't even accept a flush begin event when flushing */
4996 if (GST_PAD_IS_FLUSHING (pad))
4999 GST_PAD_SET_FLUSHING (pad);
5000 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5002 case GST_EVENT_FLUSH_STOP:
5003 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
5004 GST_PAD_UNSET_FLUSHING (pad);
5005 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5007 /* Remove pending EOS events */
5008 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5009 remove_event_by_type (pad, GST_EVENT_EOS);
5010 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5011 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5013 GST_OBJECT_UNLOCK (pad);
5014 /* grab stream lock */
5015 GST_PAD_STREAM_LOCK (pad);
5017 GST_OBJECT_LOCK (pad);
5018 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5021 case GST_EVENT_RECONFIGURE:
5022 if (GST_PAD_IS_SRC (pad))
5023 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5025 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5026 "have event type %" GST_PTR_FORMAT, event);
5028 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5032 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5035 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5036 GST_OBJECT_UNLOCK (pad);
5037 GST_PAD_STREAM_LOCK (pad);
5039 GST_OBJECT_LOCK (pad);
5040 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5043 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5047 switch (GST_EVENT_TYPE (event)) {
5048 case GST_EVENT_SEGMENT:
5049 event = apply_pad_offset (pad, event);
5057 /* now do the probe */
5059 type | GST_PAD_PROBE_TYPE_PUSH |
5060 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5062 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5064 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5067 ACQUIRE_PARENT (pad, parent, no_parent);
5068 GST_OBJECT_UNLOCK (pad);
5070 ret = pre_eventfunc_check (pad, event);
5071 if (G_UNLIKELY (ret != GST_FLOW_OK))
5072 goto precheck_failed;
5075 gst_event_ref (event);
5077 if (eventfunc (pad, parent, event)) {
5080 /* something went wrong */
5081 switch (event_type) {
5082 case GST_EVENT_CAPS:
5083 ret = GST_FLOW_NOT_NEGOTIATED;
5086 ret = GST_FLOW_ERROR;
5090 RELEASE_PARENT (parent);
5092 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5095 if (ret == GST_FLOW_OK) {
5096 GST_OBJECT_LOCK (pad);
5097 /* after the event function accepted the event, we can store the sticky
5098 * event on the pad */
5099 switch (store_sticky_event (pad, event)) {
5100 case GST_FLOW_FLUSHING:
5107 GST_OBJECT_UNLOCK (pad);
5109 gst_event_unref (event);
5113 GST_PAD_STREAM_UNLOCK (pad);
5117 /* ERROR handling */
5120 GST_OBJECT_UNLOCK (pad);
5122 GST_PAD_STREAM_UNLOCK (pad);
5123 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5124 "Received event on flushing pad. Discarding");
5125 gst_event_unref (event);
5126 return GST_FLOW_FLUSHING;
5130 GST_OBJECT_UNLOCK (pad);
5132 GST_PAD_STREAM_UNLOCK (pad);
5133 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5134 "Received event on EOS pad. Discarding");
5135 gst_event_unref (event);
5136 return GST_FLOW_EOS;
5140 GST_OBJECT_UNLOCK (pad);
5142 GST_PAD_STREAM_UNLOCK (pad);
5143 gst_event_unref (event);
5146 case GST_FLOW_CUSTOM_SUCCESS:
5147 GST_DEBUG_OBJECT (pad, "dropped event");
5151 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5158 g_warning ("pad %s:%s has no event handler, file a bug.",
5159 GST_DEBUG_PAD_NAME (pad));
5160 GST_OBJECT_UNLOCK (pad);
5162 GST_PAD_STREAM_UNLOCK (pad);
5163 gst_event_unref (event);
5164 return GST_FLOW_NOT_SUPPORTED;
5168 GST_DEBUG_OBJECT (pad, "no parent");
5169 GST_OBJECT_UNLOCK (pad);
5171 GST_PAD_STREAM_UNLOCK (pad);
5172 gst_event_unref (event);
5173 return GST_FLOW_FLUSHING;
5177 GST_DEBUG_OBJECT (pad, "pre event check failed");
5178 RELEASE_PARENT (parent);
5180 GST_PAD_STREAM_UNLOCK (pad);
5181 gst_event_unref (event);
5187 * gst_pad_send_event:
5188 * @pad: a #GstPad to send the event to.
5189 * @event: (transfer full): the #GstEvent to send to the pad.
5191 * Sends the event to the pad. This function can be used
5192 * by applications to send events in the pipeline.
5194 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5195 * sink pad, @event should be a downstream event. For example, you would not
5196 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5197 * Furthermore, some downstream events have to be serialized with data flow,
5198 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5199 * the event needs to be serialized with data flow, this function will take the
5200 * pad's stream lock while calling its event function.
5202 * To find out whether an event type is upstream, downstream, or downstream and
5203 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5204 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5205 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5206 * plugin doesn't need to bother itself with this information; the core handles
5207 * all necessary locks and checks.
5209 * This function takes ownership of the provided event so you should
5210 * gst_event_ref() it if you want to reuse the event after this call.
5212 * Returns: TRUE if the event was handled.
5215 gst_pad_send_event (GstPad * pad, GstEvent * event)
5218 GstPadProbeType type;
5220 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5221 g_return_val_if_fail (event != NULL, FALSE);
5223 if (GST_PAD_IS_SINK (pad)) {
5224 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5225 goto wrong_direction;
5226 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5227 } else if (GST_PAD_IS_SRC (pad)) {
5228 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5229 goto wrong_direction;
5230 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5232 goto unknown_direction;
5234 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5241 /* ERROR handling */
5244 g_warning ("pad %s:%s sending %s event in wrong direction",
5245 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5246 gst_event_unref (event);
5251 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5252 gst_event_unref (event);
5258 * gst_pad_set_element_private:
5259 * @pad: the #GstPad to set the private data of.
5260 * @priv: The private data to attach to the pad.
5262 * Set the given private data gpointer on the pad.
5263 * This function can only be used by the element that owns the pad.
5264 * No locking is performed in this function.
5267 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5269 pad->element_private = priv;
5273 * gst_pad_get_element_private:
5274 * @pad: the #GstPad to get the private data of.
5276 * Gets the private data of a pad.
5277 * No locking is performed in this function.
5279 * Returns: (transfer none): a #gpointer to the private data.
5282 gst_pad_get_element_private (GstPad * pad)
5284 return pad->element_private;
5288 * gst_pad_get_sticky_event:
5289 * @pad: the #GstPad to get the event from.
5290 * @event_type: the #GstEventType that should be retrieved.
5291 * @idx: the index of the event
5293 * Returns a new reference of the sticky event of type @event_type
5296 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5297 * event of @event_type was on @pad. Unref after usage.
5300 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5302 GstEvent *event = NULL;
5305 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5306 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5308 GST_OBJECT_LOCK (pad);
5309 ev = find_event_by_type (pad, event_type, idx);
5310 if (ev && (event = ev->event))
5311 gst_event_ref (event);
5312 GST_OBJECT_UNLOCK (pad);
5319 GstPadStickyEventsForeachFunction func;
5324 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5326 ForeachDispatch *data = user_data;
5327 gboolean ret = TRUE;
5330 GST_OBJECT_UNLOCK (pad);
5332 ret = data->func (pad, &ev->event, data->user_data);
5334 GST_OBJECT_LOCK (pad);
5341 * gst_pad_sticky_events_foreach:
5342 * @pad: the #GstPad that should be used for iteration.
5343 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5344 * should be called for every event.
5345 * @user_data: (closure): the optional user data.
5347 * Iterates all sticky events on @pad and calls @foreach_func for every
5348 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5351 gst_pad_sticky_events_foreach (GstPad * pad,
5352 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5354 ForeachDispatch data;
5356 g_return_if_fail (GST_IS_PAD (pad));
5357 g_return_if_fail (foreach_func != NULL);
5359 data.func = foreach_func;
5360 data.user_data = user_data;
5362 GST_OBJECT_LOCK (pad);
5363 events_foreach (pad, foreach_dispatch_function, &data);
5364 GST_OBJECT_UNLOCK (pad);
5368 do_stream_status (GstPad * pad, GstStreamStatusType type,
5369 GThread * thread, GstTask * task)
5373 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5375 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5376 if (GST_IS_ELEMENT (parent)) {
5377 GstMessage *message;
5378 GValue value = { 0 };
5380 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5381 gchar *tname, *ename, *pname;
5383 /* create a good task name */
5384 ename = gst_element_get_name (parent);
5385 pname = gst_pad_get_name (pad);
5386 tname = g_strdup_printf ("%s:%s", ename, pname);
5390 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5394 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5397 g_value_init (&value, GST_TYPE_TASK);
5398 g_value_set_object (&value, task);
5399 gst_message_set_stream_status_object (message, &value);
5400 g_value_unset (&value);
5402 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5403 gst_element_post_message (parent, message);
5405 gst_object_unref (parent);
5410 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5412 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5417 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5419 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5424 * gst_pad_start_task:
5425 * @pad: the #GstPad to start the task of
5426 * @func: the task function to call
5427 * @user_data: user data passed to the task function
5428 * @notify: called when @user_data is no longer referenced
5430 * Starts a task that repeatedly calls @func with @user_data. This function
5431 * is mostly used in pad activation functions to start the dataflow.
5432 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5433 * before @func is called.
5435 * Returns: a %TRUE if the task could be started.
5438 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5439 GDestroyNotify notify)
5444 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5445 g_return_val_if_fail (func != NULL, FALSE);
5447 GST_DEBUG_OBJECT (pad, "start task");
5449 GST_OBJECT_LOCK (pad);
5450 task = GST_PAD_TASK (pad);
5452 task = gst_task_new (func, user_data, notify);
5453 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5454 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5455 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5456 GST_INFO_OBJECT (pad, "created task %p", task);
5457 GST_PAD_TASK (pad) = task;
5458 gst_object_ref (task);
5459 /* release lock to post the message */
5460 GST_OBJECT_UNLOCK (pad);
5462 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5464 gst_object_unref (task);
5466 GST_OBJECT_LOCK (pad);
5467 /* nobody else is supposed to have changed the pad now */
5468 if (GST_PAD_TASK (pad) != task)
5469 goto concurrent_stop;
5471 res = gst_task_set_state (task, GST_TASK_STARTED);
5472 GST_OBJECT_UNLOCK (pad);
5479 GST_OBJECT_UNLOCK (pad);
5485 * gst_pad_pause_task:
5486 * @pad: the #GstPad to pause the task of
5488 * Pause the task of @pad. This function will also wait until the
5489 * function executed by the task is finished if this function is not
5490 * called from the task function.
5492 * Returns: a TRUE if the task could be paused or FALSE when the pad
5496 gst_pad_pause_task (GstPad * pad)
5501 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5503 GST_DEBUG_OBJECT (pad, "pause task");
5505 GST_OBJECT_LOCK (pad);
5506 task = GST_PAD_TASK (pad);
5509 res = gst_task_set_state (task, GST_TASK_PAUSED);
5510 GST_OBJECT_UNLOCK (pad);
5512 /* wait for task function to finish, this lock is recursive so it does nothing
5513 * when the pause is called from the task itself */
5514 GST_PAD_STREAM_LOCK (pad);
5515 GST_PAD_STREAM_UNLOCK (pad);
5521 GST_DEBUG_OBJECT (pad, "pad has no task");
5522 GST_OBJECT_UNLOCK (pad);
5528 * gst_pad_stop_task:
5529 * @pad: the #GstPad to stop the task of
5531 * Stop the task of @pad. This function will also make sure that the
5532 * function executed by the task will effectively stop if not called
5533 * from the GstTaskFunction.
5535 * This function will deadlock if called from the GstTaskFunction of
5536 * the task. Use gst_task_pause() instead.
5538 * Regardless of whether the pad has a task, the stream lock is acquired and
5539 * released so as to ensure that streaming through this pad has finished.
5541 * Returns: a TRUE if the task could be stopped or FALSE on error.
5544 gst_pad_stop_task (GstPad * pad)
5549 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5551 GST_DEBUG_OBJECT (pad, "stop task");
5553 GST_OBJECT_LOCK (pad);
5554 task = GST_PAD_TASK (pad);
5557 GST_PAD_TASK (pad) = NULL;
5558 res = gst_task_set_state (task, GST_TASK_STOPPED);
5559 GST_OBJECT_UNLOCK (pad);
5561 GST_PAD_STREAM_LOCK (pad);
5562 GST_PAD_STREAM_UNLOCK (pad);
5564 if (!gst_task_join (task))
5567 gst_object_unref (task);
5573 GST_DEBUG_OBJECT (pad, "no task");
5574 GST_OBJECT_UNLOCK (pad);
5576 GST_PAD_STREAM_LOCK (pad);
5577 GST_PAD_STREAM_UNLOCK (pad);
5579 /* this is not an error */
5584 /* this is bad, possibly the application tried to join the task from
5585 * the task's thread. We install the task again so that it will be stopped
5586 * again from the right thread next time hopefully. */
5587 GST_OBJECT_LOCK (pad);
5588 GST_DEBUG_OBJECT (pad, "join failed");
5589 /* we can only install this task if there was no other task */
5590 if (GST_PAD_TASK (pad) == NULL)
5591 GST_PAD_TASK (pad) = task;
5592 GST_OBJECT_UNLOCK (pad);
5599 * gst_pad_probe_info_get_event:
5600 * @info: a #GstPadProbeInfo
5602 * Returns: (transfer none): The #GstEvent from the probe
5606 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5608 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5609 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5611 return GST_PAD_PROBE_INFO_EVENT (info);
5616 * gst_pad_probe_info_get_query:
5617 * @info: a #GstPadProbeInfo
5619 * Returns: (transfer none): The #GstQuery from the probe
5623 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5625 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5626 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5628 return GST_PAD_PROBE_INFO_QUERY (info);
5632 * gst_pad_probe_info_get_buffer:
5633 * @info: a #GstPadProbeInfo
5635 * Returns: (transfer none): The #GstBuffer from the probe
5639 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5641 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5643 return GST_PAD_PROBE_INFO_BUFFER (info);
5647 * gst_pad_probe_info_get_bufferlist:
5648 * @info: a #GstPadProbeInfo
5650 * Returns: (transfer none): The #GstBufferlist from the probe
5654 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5656 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5658 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);