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 with gst_element_get_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
141 guint probe_list_cookie;
151 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
156 GstPadProbeInfo *info;
163 static void gst_pad_dispose (GObject * object);
164 static void gst_pad_finalize (GObject * object);
165 static void gst_pad_set_property (GObject * object, guint prop_id,
166 const GValue * value, GParamSpec * pspec);
167 static void gst_pad_get_property (GObject * object, guint prop_id,
168 GValue * value, GParamSpec * pspec);
170 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
171 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
172 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
173 GstObject * parent, GstBufferList * list);
175 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
176 GstEvent * event, GstPadProbeType type);
177 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
178 GstEvent * event, GstPadProbeType type);
180 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
182 static GParamSpec *pspec_caps = NULL;
184 /* quarks for probe signals */
185 static GQuark buffer_quark;
186 static GQuark buffer_list_quark;
187 static GQuark event_quark;
196 static GstFlowQuarks flow_quarks[] = {
197 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
198 {GST_FLOW_OK, "ok", 0},
199 {GST_FLOW_NOT_LINKED, "not-linked", 0},
200 {GST_FLOW_FLUSHING, "flushing", 0},
201 {GST_FLOW_EOS, "eos", 0},
202 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
203 {GST_FLOW_ERROR, "error", 0},
204 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
205 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
210 * @ret: a #GstFlowReturn to get the name of.
212 * Gets a string representing the given flow return.
214 * Returns: a static string with the name of the flow return.
217 gst_flow_get_name (GstFlowReturn ret)
221 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
223 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
224 if (ret == flow_quarks[i].ret)
225 return flow_quarks[i].name;
232 * @ret: a #GstFlowReturn to get the quark of.
234 * Get the unique quark for the given GstFlowReturn.
236 * Returns: the quark associated with the flow return or 0 if an
237 * invalid return was specified.
240 gst_flow_to_quark (GstFlowReturn ret)
244 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
246 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
247 if (ret == flow_quarks[i].ret)
248 return flow_quarks[i].quark;
257 buffer_quark = g_quark_from_static_string ("buffer"); \
258 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
259 event_quark = g_quark_from_static_string ("event"); \
261 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
262 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
265 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
266 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
269 #define gst_pad_parent_class parent_class
270 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
273 gst_pad_class_init (GstPadClass * klass)
275 GObjectClass *gobject_class;
276 GstObjectClass *gstobject_class;
278 gobject_class = G_OBJECT_CLASS (klass);
279 gstobject_class = GST_OBJECT_CLASS (klass);
281 g_type_class_add_private (klass, sizeof (GstPadPrivate));
283 gobject_class->dispose = gst_pad_dispose;
284 gobject_class->finalize = gst_pad_finalize;
285 gobject_class->set_property = gst_pad_set_property;
286 gobject_class->get_property = gst_pad_get_property;
290 * @pad: the pad that emitted the signal
291 * @peer: the peer pad that has been connected
293 * Signals that a pad has been linked to the peer pad.
295 gst_pad_signals[PAD_LINKED] =
296 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
297 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
298 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
301 * @pad: the pad that emitted the signal
302 * @peer: the peer pad that has been disconnected
304 * Signals that a pad has been unlinked from the peer pad.
306 gst_pad_signals[PAD_UNLINKED] =
307 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
308 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
309 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
311 pspec_caps = g_param_spec_boxed ("caps", "Caps",
312 "The capabilities of the pad", GST_TYPE_CAPS,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
314 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
316 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
317 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
318 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
319 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
321 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
322 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
323 g_param_spec_object ("template", "Template",
324 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
325 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
327 gstobject_class->path_string_separator = ".";
329 /* Register common function pointer descriptions */
330 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
338 gst_pad_init (GstPad * pad)
340 pad->priv = GST_PAD_GET_PRIVATE (pad);
342 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
344 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
345 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
346 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
347 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
348 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
350 GST_PAD_SET_FLUSHING (pad);
352 g_rec_mutex_init (&pad->stream_rec_lock);
354 g_cond_init (&pad->block_cond);
356 g_hook_list_init (&pad->probes, sizeof (GstProbe));
358 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
361 /* called when setting the pad inactive. It removes all sticky events from
362 * the pad. must be called with object lock */
364 remove_events (GstPad * pad)
369 events = pad->priv->events;
372 for (i = 0; i < len; i++) {
373 PadEvent *ev = &g_array_index (events, PadEvent, i);
374 GstEvent *event = ev->event;
378 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
379 GST_OBJECT_UNLOCK (pad);
381 GST_DEBUG_OBJECT (pad, "notify caps");
382 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
384 GST_OBJECT_LOCK (pad);
386 gst_event_unref (event);
388 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
389 g_array_set_size (events, 0);
390 pad->priv->events_cookie++;
393 /* should be called with object lock */
395 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
401 events = pad->priv->events;
404 for (i = 0; i < len; i++) {
405 ev = &g_array_index (events, PadEvent, i);
406 if (ev->event == NULL)
409 if (GST_EVENT_TYPE (ev->event) == type) {
420 /* should be called with OBJECT lock */
422 find_event (GstPad * pad, GstEvent * event)
428 events = pad->priv->events;
431 for (i = 0; i < len; i++) {
432 ev = &g_array_index (events, PadEvent, i);
433 if (event == ev->event)
441 /* should be called with OBJECT lock */
443 remove_event_by_type (GstPad * pad, GstEventType type)
449 events = pad->priv->events;
454 ev = &g_array_index (events, PadEvent, i);
455 if (ev->event == NULL)
458 if (GST_EVENT_TYPE (ev->event) != type)
461 gst_event_unref (ev->event);
462 g_array_remove_index (events, i);
464 pad->priv->events_cookie++;
472 /* check all events on srcpad against those on sinkpad. All events that are not
473 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
474 * srcpad so that the events will be sent next time */
475 /* should be called with srcpad and sinkpad LOCKS */
477 schedule_events (GstPad * srcpad, GstPad * sinkpad)
482 gboolean pending = FALSE;
484 events = srcpad->priv->events;
487 for (i = 0; i < len; i++) {
488 ev = &g_array_index (events, PadEvent, i);
489 if (ev->event == NULL)
492 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
493 ev->received = FALSE;
498 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
501 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
504 /* should be called with pad LOCK */
506 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
513 events = pad->priv->events;
516 cookie = pad->priv->events_cookie;
520 PadEvent *ev, ev_ret;
522 ev = &g_array_index (events, PadEvent, i);
523 if (G_UNLIKELY (ev->event == NULL))
526 /* take aditional ref, func might release the lock */
527 ev_ret.event = gst_event_ref (ev->event);
528 ev_ret.received = ev->received;
530 ret = func (pad, &ev_ret, user_data);
532 /* recheck the cookie, lock might have been released and the list could have
534 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
535 if (G_LIKELY (ev_ret.event))
536 gst_event_unref (ev_ret.event);
540 /* store the received state */
541 ev->received = ev_ret.received;
543 /* if the event changed, we need to do something */
544 if (G_UNLIKELY (ev->event != ev_ret.event)) {
545 if (G_UNLIKELY (ev_ret.event == NULL)) {
546 /* function unreffed and set the event to NULL, remove it */
547 g_array_remove_index (events, i);
549 cookie = ++pad->priv->events_cookie;
552 /* function gave a new event for us */
553 gst_event_take (&ev->event, ev_ret.event);
556 /* just unref, nothing changed */
557 gst_event_unref (ev_ret.event);
566 /* should be called with LOCK */
568 apply_pad_offset (GstPad * pad, GstEvent * event)
570 /* check if we need to adjust the segment */
571 if (pad->offset != 0) {
574 /* copy segment values */
575 gst_event_copy_segment (event, &segment);
576 gst_event_unref (event);
578 /* adjust and make a new event with the offset applied */
579 segment.base += pad->offset;
580 event = gst_event_new_segment (&segment);
585 /* should be called with the OBJECT_LOCK */
587 get_pad_caps (GstPad * pad)
589 GstCaps *caps = NULL;
592 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
594 gst_event_parse_caps (ev->event, &caps);
600 gst_pad_dispose (GObject * object)
602 GstPad *pad = GST_PAD_CAST (object);
605 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
607 /* unlink the peer pad */
608 if ((peer = gst_pad_get_peer (pad))) {
609 /* window for MT unsafeness, someone else could unlink here
610 * and then we call unlink with wrong pads. The unlink
611 * function would catch this and safely return failed. */
612 if (GST_PAD_IS_SRC (pad))
613 gst_pad_unlink (pad, peer);
615 gst_pad_unlink (peer, pad);
617 gst_object_unref (peer);
620 gst_pad_set_pad_template (pad, NULL);
622 GST_OBJECT_LOCK (pad);
624 GST_OBJECT_UNLOCK (pad);
626 g_hook_list_clear (&pad->probes);
628 G_OBJECT_CLASS (parent_class)->dispose (object);
632 gst_pad_finalize (GObject * object)
634 GstPad *pad = GST_PAD_CAST (object);
637 /* in case the task is still around, clean it up */
638 if ((task = GST_PAD_TASK (pad))) {
639 gst_task_join (task);
640 GST_PAD_TASK (pad) = NULL;
641 gst_object_unref (task);
644 if (pad->activatenotify)
645 pad->activatenotify (pad->activatedata);
646 if (pad->activatemodenotify)
647 pad->activatemodenotify (pad->activatemodedata);
649 pad->linknotify (pad->linkdata);
650 if (pad->unlinknotify)
651 pad->unlinknotify (pad->unlinkdata);
652 if (pad->chainnotify)
653 pad->chainnotify (pad->chaindata);
654 if (pad->chainlistnotify)
655 pad->chainlistnotify (pad->chainlistdata);
656 if (pad->getrangenotify)
657 pad->getrangenotify (pad->getrangedata);
658 if (pad->eventnotify)
659 pad->eventnotify (pad->eventdata);
660 if (pad->querynotify)
661 pad->querynotify (pad->querydata);
662 if (pad->iterintlinknotify)
663 pad->iterintlinknotify (pad->iterintlinkdata);
665 g_rec_mutex_clear (&pad->stream_rec_lock);
666 g_cond_clear (&pad->block_cond);
667 g_array_free (pad->priv->events, TRUE);
669 G_OBJECT_CLASS (parent_class)->finalize (object);
673 gst_pad_set_property (GObject * object, guint prop_id,
674 const GValue * value, GParamSpec * pspec)
676 g_return_if_fail (GST_IS_PAD (object));
679 case PAD_PROP_DIRECTION:
680 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
682 case PAD_PROP_TEMPLATE:
683 gst_pad_set_pad_template (GST_PAD_CAST (object),
684 (GstPadTemplate *) g_value_get_object (value));
687 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
693 gst_pad_get_property (GObject * object, guint prop_id,
694 GValue * value, GParamSpec * pspec)
696 g_return_if_fail (GST_IS_PAD (object));
700 GST_OBJECT_LOCK (object);
701 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
702 GST_OBJECT_UNLOCK (object);
704 case PAD_PROP_DIRECTION:
705 g_value_set_enum (value, GST_PAD_DIRECTION (object));
707 case PAD_PROP_TEMPLATE:
708 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
711 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
718 * @name: the name of the new pad.
719 * @direction: the #GstPadDirection of the pad.
721 * Creates a new pad with the given name in the given direction.
722 * If name is NULL, a guaranteed unique name (across all pads)
724 * This function makes a copy of the name so you can safely free the name.
726 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
731 gst_pad_new (const gchar * name, GstPadDirection direction)
733 return g_object_new (GST_TYPE_PAD,
734 "name", name, "direction", direction, NULL);
738 * gst_pad_new_from_template:
739 * @templ: the pad template to use
740 * @name: the name of the element
742 * Creates a new pad with the given name from the given template.
743 * If name is NULL, a guaranteed unique name (across all pads)
745 * This function makes a copy of the name so you can safely free the name.
747 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
750 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
752 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
754 return g_object_new (GST_TYPE_PAD,
755 "name", name, "direction", templ->direction, "template", templ, NULL);
759 * gst_pad_new_from_static_template:
760 * @templ: the #GstStaticPadTemplate to use
761 * @name: the name of the element
763 * Creates a new pad with the given name from the given static template.
764 * If name is NULL, a guaranteed unique name (across all pads)
766 * This function makes a copy of the name so you can safely free the name.
768 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
771 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
775 GstPadTemplate *template;
777 template = gst_static_pad_template_get (templ);
778 pad = gst_pad_new_from_template (template, name);
779 gst_object_unref (template);
783 #define ACQUIRE_PARENT(pad, parent, label) \
785 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
786 gst_object_ref (parent); \
787 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
791 #define RELEASE_PARENT(parent) \
793 if (G_LIKELY (parent)) \
794 gst_object_unref (parent); \
798 * gst_pad_get_direction:
799 * @pad: a #GstPad to get the direction of.
801 * Gets the direction of the pad. The direction of the pad is
802 * decided at construction time so this function does not take
805 * Returns: the #GstPadDirection of the pad.
810 gst_pad_get_direction (GstPad * pad)
812 GstPadDirection result;
814 /* PAD_UNKNOWN is a little silly but we need some sort of
815 * error return value */
816 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
818 result = GST_PAD_DIRECTION (pad);
824 gst_pad_activate_default (GstPad * pad, GstObject * parent)
826 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
830 * gst_pad_mode_get_name:
831 * @mode: the pad mode
833 * Return the name of a pad mode, for use in debug messages mostly.
835 * Returns: short mnemonic for pad mode @mode
838 gst_pad_mode_get_name (GstPadMode mode)
841 case GST_PAD_MODE_NONE:
843 case GST_PAD_MODE_PUSH:
845 case GST_PAD_MODE_PULL:
854 pre_activate (GstPad * pad, GstPadMode new_mode)
857 case GST_PAD_MODE_NONE:
858 GST_OBJECT_LOCK (pad);
859 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
860 GST_PAD_SET_FLUSHING (pad);
861 GST_PAD_MODE (pad) = new_mode;
862 /* unlock blocked pads so element can resume and stop */
863 GST_PAD_BLOCK_BROADCAST (pad);
864 GST_OBJECT_UNLOCK (pad);
866 case GST_PAD_MODE_PUSH:
867 case GST_PAD_MODE_PULL:
868 GST_OBJECT_LOCK (pad);
869 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
870 gst_pad_mode_get_name (new_mode));
871 GST_PAD_UNSET_FLUSHING (pad);
872 GST_PAD_MODE (pad) = new_mode;
873 if (GST_PAD_IS_SINK (pad)) {
875 /* make sure the peer src pad sends us all events */
876 if ((peer = GST_PAD_PEER (pad))) {
877 gst_object_ref (peer);
878 GST_OBJECT_UNLOCK (pad);
880 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
881 GST_DEBUG_PAD_NAME (peer));
883 GST_OBJECT_LOCK (peer);
884 schedule_events (peer, NULL);
885 GST_OBJECT_UNLOCK (peer);
887 gst_object_unref (peer);
889 GST_OBJECT_UNLOCK (pad);
892 GST_OBJECT_UNLOCK (pad);
899 post_activate (GstPad * pad, GstPadMode new_mode)
902 case GST_PAD_MODE_NONE:
903 /* ensures that streaming stops */
904 GST_PAD_STREAM_LOCK (pad);
905 GST_DEBUG_OBJECT (pad, "stopped streaming");
906 GST_OBJECT_LOCK (pad);
908 GST_OBJECT_UNLOCK (pad);
909 GST_PAD_STREAM_UNLOCK (pad);
911 case GST_PAD_MODE_PUSH:
912 case GST_PAD_MODE_PULL:
919 * gst_pad_set_active:
920 * @pad: the #GstPad to activate or deactivate.
921 * @active: whether or not the pad should be active.
923 * Activates or deactivates the given pad.
924 * Normally called from within core state change functions.
926 * If @active, makes sure the pad is active. If it is already active, either in
927 * push or pull mode, just return. Otherwise dispatches to the pad's activate
928 * function to perform the actual activation.
930 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
931 * and a FALSE argument.
933 * Returns: #TRUE if the operation was successful.
938 gst_pad_set_active (GstPad * pad, gboolean active)
942 gboolean ret = FALSE;
944 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
946 GST_OBJECT_LOCK (pad);
947 old = GST_PAD_MODE (pad);
948 ACQUIRE_PARENT (pad, parent, no_parent);
949 GST_OBJECT_UNLOCK (pad);
952 if (old == GST_PAD_MODE_NONE) {
953 GST_DEBUG_OBJECT (pad, "activating pad from none");
954 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
956 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
957 gst_pad_mode_get_name (old));
961 if (old == GST_PAD_MODE_NONE) {
962 GST_DEBUG_OBJECT (pad, "pad was inactive");
965 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
966 gst_pad_mode_get_name (old));
967 ret = gst_pad_activate_mode (pad, old, FALSE);
971 RELEASE_PARENT (parent);
973 if (G_UNLIKELY (!ret))
981 GST_DEBUG_OBJECT (pad, "no parent");
982 GST_OBJECT_UNLOCK (pad);
987 GST_OBJECT_LOCK (pad);
989 g_critical ("Failed to deactivate pad %s:%s, very bad",
990 GST_DEBUG_PAD_NAME (pad));
992 GST_WARNING_OBJECT (pad, "Failed to activate pad");
994 GST_OBJECT_UNLOCK (pad);
1000 * gst_pad_activate_mode:
1001 * @pad: the #GstPad to activate or deactivate.
1002 * @mode: the requested activation mode
1003 * @active: whether or not the pad should be active.
1005 * Activates or deactivates the given pad in @mode via dispatching to the
1006 * pad's activatemodefunc. For use from within pad activation functions only.
1008 * If you don't know what this is, you probably don't want to call it.
1010 * Returns: TRUE if the operation was successful.
1015 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1017 gboolean res = FALSE;
1019 GstPadMode old, new;
1020 GstPadDirection dir;
1023 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1025 GST_OBJECT_LOCK (pad);
1026 old = GST_PAD_MODE (pad);
1027 dir = GST_PAD_DIRECTION (pad);
1028 ACQUIRE_PARENT (pad, parent, no_parent);
1029 GST_OBJECT_UNLOCK (pad);
1031 new = active ? mode : GST_PAD_MODE_NONE;
1036 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1037 /* pad was activate in the wrong direction, deactivate it
1038 * and reactivate it in the requested mode */
1039 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1040 gst_pad_mode_get_name (old));
1042 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1043 goto deactivate_failed;
1047 case GST_PAD_MODE_PULL:
1049 if (dir == GST_PAD_SINK) {
1050 if ((peer = gst_pad_get_peer (pad))) {
1051 GST_DEBUG_OBJECT (pad, "calling peer");
1052 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1054 gst_object_unref (peer);
1056 /* there is no peer, this is only fatal when we activate. When we
1057 * deactivate, we must assume the application has unlinked the peer and
1058 * will deactivate it eventually. */
1062 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1065 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1066 goto failure; /* Can't activate pull on a src without a
1067 getrange function */
1075 pre_activate (pad, new);
1077 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1078 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1082 /* can happen for sinks of passthrough elements */
1085 post_activate (pad, new);
1087 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1088 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1093 /* Clear sticky flags on deactivation */
1095 GST_OBJECT_LOCK (pad);
1096 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1097 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1098 GST_OBJECT_UNLOCK (pad);
1102 RELEASE_PARENT (parent);
1108 GST_DEBUG_OBJECT (pad, "no parent");
1109 GST_OBJECT_UNLOCK (pad);
1114 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1115 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1120 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1121 "failed to %s in switch to %s mode from %s mode",
1122 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1123 gst_pad_mode_get_name (old));
1128 GST_OBJECT_LOCK (peer);
1129 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1130 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1131 GST_OBJECT_UNLOCK (peer);
1132 gst_object_unref (peer);
1137 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1138 "pad in pull mode");
1143 GST_OBJECT_LOCK (pad);
1144 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1145 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1146 GST_PAD_SET_FLUSHING (pad);
1147 GST_PAD_MODE (pad) = old;
1148 GST_OBJECT_UNLOCK (pad);
1154 * gst_pad_is_active:
1155 * @pad: the #GstPad to query
1157 * Query if a pad is active
1159 * Returns: TRUE if the pad is active.
1164 gst_pad_is_active (GstPad * pad)
1166 gboolean result = FALSE;
1168 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1170 GST_OBJECT_LOCK (pad);
1171 result = GST_PAD_IS_ACTIVE (pad);
1172 GST_OBJECT_UNLOCK (pad);
1178 * gst_pad_add_probe:
1179 * @pad: the #GstPad to add the probe to
1180 * @mask: the probe mask
1181 * @callback: #GstPadProbeCallback that will be called with notifications of
1183 * @user_data: (closure): user data passed to the callback
1184 * @destroy_data: #GDestroyNotify for user_data
1186 * Be notified of different states of pads. The provided callback is called for
1187 * every state that matches @mask.
1189 * Returns: an id or 0 on error. The id can be used to remove the probe with
1190 * gst_pad_remove_probe().
1195 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1196 GstPadProbeCallback callback, gpointer user_data,
1197 GDestroyNotify destroy_data)
1202 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1203 g_return_val_if_fail (mask != 0, 0);
1205 GST_OBJECT_LOCK (pad);
1207 /* make a new probe */
1208 hook = g_hook_alloc (&pad->probes);
1210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1213 /* when no contraints are given for the types, assume all types are
1215 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1216 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1217 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1218 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1220 /* store our flags and other fields */
1221 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1222 hook->func = callback;
1223 hook->data = user_data;
1224 hook->destroy = destroy_data;
1225 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1228 g_hook_prepend (&pad->probes, hook);
1230 /* incremenent cookie so that the new hook get's called */
1231 pad->priv->probe_list_cookie++;
1233 /* get the id of the hook, we return this and it can be used to remove the
1235 res = hook->hook_id;
1237 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1239 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1240 /* we have a block probe */
1242 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1244 "now %d blocking probes", pad->num_blocked);
1247 /* call the callback if we need to be called for idle callbacks */
1248 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1249 if (pad->priv->using > 0) {
1250 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1251 * flag above, the last thread to leave the push will do the callback. New
1252 * threads going into the push will block. */
1253 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1254 "pad is in use, delay idle callback");
1255 GST_OBJECT_UNLOCK (pad);
1257 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1259 /* the pad is idle now, we can signal the idle callback now */
1260 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1261 "pad is idle, trigger idle callback");
1262 GST_OBJECT_UNLOCK (pad);
1264 callback (pad, &info, user_data);
1267 GST_OBJECT_UNLOCK (pad);
1273 cleanup_hook (GstPad * pad, GHook * hook)
1275 GstPadProbeType type;
1277 if (!G_HOOK_IS_VALID (hook))
1280 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1282 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1283 /* unblock when we remove the last blocking probe */
1285 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1287 if (pad->num_blocked == 0) {
1288 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1289 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1290 GST_PAD_BLOCK_BROADCAST (pad);
1293 g_hook_destroy_link (&pad->probes, hook);
1298 * gst_pad_remove_probe:
1299 * @pad: the #GstPad with the probe
1300 * @id: the probe id to remove
1302 * Remove the probe with @id from @pad.
1307 gst_pad_remove_probe (GstPad * pad, gulong id)
1311 g_return_if_fail (GST_IS_PAD (pad));
1313 GST_OBJECT_LOCK (pad);
1315 hook = g_hook_get (&pad->probes, id);
1319 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1321 cleanup_hook (pad, hook);
1322 GST_OBJECT_UNLOCK (pad);
1328 GST_OBJECT_UNLOCK (pad);
1329 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1335 * gst_pad_is_blocked:
1336 * @pad: the #GstPad to query
1338 * Checks if the pad is blocked or not. This function returns the
1339 * last requested state of the pad. It is not certain that the pad
1340 * is actually blocking at this point (see gst_pad_is_blocking()).
1342 * Returns: TRUE if the pad is blocked.
1347 gst_pad_is_blocked (GstPad * pad)
1349 gboolean result = FALSE;
1351 g_return_val_if_fail (GST_IS_PAD (pad), result);
1353 GST_OBJECT_LOCK (pad);
1354 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1355 GST_OBJECT_UNLOCK (pad);
1361 * gst_pad_is_blocking:
1362 * @pad: the #GstPad to query
1364 * Checks if the pad is blocking or not. This is a guaranteed state
1365 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1367 * Returns: TRUE if the pad is blocking.
1372 gst_pad_is_blocking (GstPad * pad)
1374 gboolean result = FALSE;
1376 g_return_val_if_fail (GST_IS_PAD (pad), result);
1378 GST_OBJECT_LOCK (pad);
1379 /* the blocking flag is only valid if the pad is not flushing */
1380 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1381 GST_OBJECT_UNLOCK (pad);
1387 * gst_pad_needs_reconfigure:
1388 * @pad: the #GstPad to check
1390 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1391 * if the flag was set.
1393 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1396 gst_pad_needs_reconfigure (GstPad * pad)
1398 gboolean reconfigure;
1400 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1402 GST_OBJECT_LOCK (pad);
1403 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1404 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1405 GST_OBJECT_UNLOCK (pad);
1411 * gst_pad_check_reconfigure:
1412 * @pad: the #GstPad to check
1414 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1415 * if the flag was set.
1417 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1420 gst_pad_check_reconfigure (GstPad * pad)
1422 gboolean reconfigure;
1424 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1426 GST_OBJECT_LOCK (pad);
1427 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1429 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1430 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1432 GST_OBJECT_UNLOCK (pad);
1438 * gst_pad_mark_reconfigure:
1439 * @pad: the #GstPad to mark
1441 * Mark a pad for needing reconfiguration. The next call to
1442 * gst_pad_check_reconfigure() will return %TRUE after this call.
1445 gst_pad_mark_reconfigure (GstPad * pad)
1447 g_return_if_fail (GST_IS_PAD (pad));
1449 GST_OBJECT_LOCK (pad);
1450 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1451 GST_OBJECT_UNLOCK (pad);
1455 * gst_pad_set_activate_function:
1457 * @f: the #GstPadActivateFunction to set.
1459 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1463 * gst_pad_set_activate_function_full:
1465 * @activate: the #GstPadActivateFunction to set.
1466 * @user_data: user_data passed to @notify
1467 * @notify: notify called when @activate will not be used anymore.
1469 * Sets the given activate function for @pad. The activate function will
1470 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1471 * Only makes sense to set on sink pads.
1473 * Call this function if your sink pad can start a pull-based task.
1476 gst_pad_set_activate_function_full (GstPad * pad,
1477 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1479 g_return_if_fail (GST_IS_PAD (pad));
1481 if (pad->activatenotify)
1482 pad->activatenotify (pad->activatedata);
1483 GST_PAD_ACTIVATEFUNC (pad) = activate;
1484 pad->activatedata = user_data;
1485 pad->activatenotify = notify;
1487 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1488 GST_DEBUG_FUNCPTR_NAME (activate));
1492 * gst_pad_set_activatemode_function:
1494 * @f: the #GstPadActivateModeFunction to set.
1496 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1500 * gst_pad_set_activatemode_function_full:
1502 * @activatemode: the #GstPadActivateModeFunction to set.
1503 * @user_data: user_data passed to @notify
1504 * @notify: notify called when @activatemode will not be used anymore.
1506 * Sets the given activate_mode function for the pad. An activate_mode function
1507 * prepares the element for data passing.
1510 gst_pad_set_activatemode_function_full (GstPad * pad,
1511 GstPadActivateModeFunction activatemode, gpointer user_data,
1512 GDestroyNotify notify)
1514 g_return_if_fail (GST_IS_PAD (pad));
1516 if (pad->activatemodenotify)
1517 pad->activatemodenotify (pad->activatemodedata);
1518 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1519 pad->activatemodedata = user_data;
1520 pad->activatemodenotify = notify;
1522 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1523 GST_DEBUG_FUNCPTR_NAME (activatemode));
1527 * gst_pad_set_chain_function:
1528 * @p: a sink #GstPad.
1529 * @f: the #GstPadChainFunction to set.
1531 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1535 * gst_pad_set_chain_function_full:
1536 * @pad: a sink #GstPad.
1537 * @chain: the #GstPadChainFunction to set.
1538 * @user_data: user_data passed to @notify
1539 * @notify: notify called when @chain will not be used anymore.
1541 * Sets the given chain function for the pad. The chain function is called to
1542 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1545 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1546 gpointer user_data, GDestroyNotify notify)
1548 g_return_if_fail (GST_IS_PAD (pad));
1549 g_return_if_fail (GST_PAD_IS_SINK (pad));
1551 if (pad->chainnotify)
1552 pad->chainnotify (pad->chaindata);
1553 GST_PAD_CHAINFUNC (pad) = chain;
1554 pad->chaindata = user_data;
1555 pad->chainnotify = notify;
1557 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1558 GST_DEBUG_FUNCPTR_NAME (chain));
1562 * gst_pad_set_chain_list_function:
1563 * @p: a sink #GstPad.
1564 * @f: the #GstPadChainListFunction to set.
1566 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1570 * gst_pad_set_chain_list_function_full:
1571 * @pad: a sink #GstPad.
1572 * @chainlist: the #GstPadChainListFunction to set.
1573 * @user_data: user_data passed to @notify
1574 * @notify: notify called when @chainlist will not be used anymore.
1576 * Sets the given chain list function for the pad. The chainlist function is
1577 * called to process a #GstBufferList input buffer list. See
1578 * #GstPadChainListFunction for more details.
1581 gst_pad_set_chain_list_function_full (GstPad * pad,
1582 GstPadChainListFunction chainlist, gpointer user_data,
1583 GDestroyNotify notify)
1585 g_return_if_fail (GST_IS_PAD (pad));
1586 g_return_if_fail (GST_PAD_IS_SINK (pad));
1588 if (pad->chainlistnotify)
1589 pad->chainlistnotify (pad->chainlistdata);
1590 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1591 pad->chainlistdata = user_data;
1592 pad->chainlistnotify = notify;
1594 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1595 GST_DEBUG_FUNCPTR_NAME (chainlist));
1599 * gst_pad_set_getrange_function:
1600 * @p: a source #GstPad.
1601 * @f: the #GstPadGetRangeFunction to set.
1603 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1607 * gst_pad_set_getrange_function_full:
1608 * @pad: a source #GstPad.
1609 * @get: the #GstPadGetRangeFunction to set.
1610 * @user_data: user_data passed to @notify
1611 * @notify: notify called when @get will not be used anymore.
1613 * Sets the given getrange function for the pad. The getrange function is
1614 * called to produce a new #GstBuffer to start the processing pipeline. see
1615 * #GstPadGetRangeFunction for a description of the getrange function.
1618 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1619 gpointer user_data, GDestroyNotify notify)
1621 g_return_if_fail (GST_IS_PAD (pad));
1622 g_return_if_fail (GST_PAD_IS_SRC (pad));
1624 if (pad->getrangenotify)
1625 pad->getrangenotify (pad->getrangedata);
1626 GST_PAD_GETRANGEFUNC (pad) = get;
1627 pad->getrangedata = user_data;
1628 pad->getrangenotify = notify;
1630 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1631 GST_DEBUG_FUNCPTR_NAME (get));
1635 * gst_pad_set_event_function:
1636 * @p: a #GstPad of either direction.
1637 * @f: the #GstPadEventFunction to set.
1639 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1643 * gst_pad_set_event_function_full:
1644 * @pad: a #GstPad of either direction.
1645 * @event: the #GstPadEventFunction to set.
1646 * @user_data: user_data passed to @notify
1647 * @notify: notify called when @event will not be used anymore.
1649 * Sets the given event handler for the pad.
1652 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1653 gpointer user_data, GDestroyNotify notify)
1655 g_return_if_fail (GST_IS_PAD (pad));
1657 if (pad->eventnotify)
1658 pad->eventnotify (pad->eventdata);
1659 GST_PAD_EVENTFUNC (pad) = event;
1660 pad->eventdata = user_data;
1661 pad->eventnotify = notify;
1663 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1664 GST_DEBUG_FUNCPTR_NAME (event));
1668 * gst_pad_set_query_function:
1669 * @p: a #GstPad of either direction.
1670 * @f: the #GstPadQueryFunction to set.
1672 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1676 * gst_pad_set_query_function_full:
1677 * @pad: a #GstPad of either direction.
1678 * @query: the #GstPadQueryFunction to set.
1679 * @user_data: user_data passed to @notify
1680 * @notify: notify called when @query will not be used anymore.
1682 * Set the given query function for the pad.
1685 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1686 gpointer user_data, GDestroyNotify notify)
1688 g_return_if_fail (GST_IS_PAD (pad));
1690 if (pad->querynotify)
1691 pad->querynotify (pad->querydata);
1692 GST_PAD_QUERYFUNC (pad) = query;
1693 pad->querydata = user_data;
1694 pad->querynotify = notify;
1696 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1697 GST_DEBUG_FUNCPTR_NAME (query));
1701 * gst_pad_set_iterate_internal_links_function:
1702 * @p: a #GstPad of either direction.
1703 * @f: the #GstPadIterIntLinkFunction to set.
1705 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1706 * for the user_data and notify.
1709 * gst_pad_set_iterate_internal_links_function_full:
1710 * @pad: a #GstPad of either direction.
1711 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1712 * @user_data: user_data passed to @notify
1713 * @notify: notify called when @iterintlink will not be used anymore.
1715 * Sets the given internal link iterator function for the pad.
1718 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1719 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1720 GDestroyNotify notify)
1722 g_return_if_fail (GST_IS_PAD (pad));
1724 if (pad->iterintlinknotify)
1725 pad->iterintlinknotify (pad->iterintlinkdata);
1726 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1727 pad->iterintlinkdata = user_data;
1728 pad->iterintlinknotify = notify;
1730 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1731 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1735 * gst_pad_set_link_function:
1737 * @f: the #GstPadLinkFunction to set.
1739 * Calls gst_pad_set_link_function_full() with NULL
1740 * for the user_data and notify.
1743 * gst_pad_set_link_function_full:
1745 * @link: the #GstPadLinkFunction to set.
1746 * @user_data: user_data passed to @notify
1747 * @notify: notify called when @link will not be used anymore.
1749 * Sets the given link function for the pad. It will be called when
1750 * the pad is linked with another pad.
1752 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1755 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1756 * cannot be made for some reason.
1758 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1759 * of the peer sink pad, if present.
1762 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1763 gpointer user_data, GDestroyNotify notify)
1765 g_return_if_fail (GST_IS_PAD (pad));
1767 if (pad->linknotify)
1768 pad->linknotify (pad->linkdata);
1769 GST_PAD_LINKFUNC (pad) = link;
1770 pad->linkdata = user_data;
1771 pad->linknotify = notify;
1773 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1774 GST_DEBUG_FUNCPTR_NAME (link));
1778 * gst_pad_set_unlink_function:
1780 * @f: the #GstPadUnlinkFunction to set.
1782 * Calls gst_pad_set_unlink_function_full() with NULL
1783 * for the user_data and notify.
1786 * gst_pad_set_unlink_function_full:
1788 * @unlink: the #GstPadUnlinkFunction to set.
1789 * @user_data: user_data passed to @notify
1790 * @notify: notify called when @unlink will not be used anymore.
1792 * Sets the given unlink function for the pad. It will be called
1793 * when the pad is unlinked.
1796 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1797 gpointer user_data, GDestroyNotify notify)
1799 g_return_if_fail (GST_IS_PAD (pad));
1801 if (pad->unlinknotify)
1802 pad->unlinknotify (pad->unlinkdata);
1803 GST_PAD_UNLINKFUNC (pad) = unlink;
1804 pad->unlinkdata = user_data;
1805 pad->unlinknotify = notify;
1807 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1808 GST_DEBUG_FUNCPTR_NAME (unlink));
1813 * @srcpad: the source #GstPad to unlink.
1814 * @sinkpad: the sink #GstPad to unlink.
1816 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1817 * signal on both pads.
1819 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1820 * the pads were not linked together.
1825 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1827 gboolean result = FALSE;
1828 GstElement *parent = NULL;
1830 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1831 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1832 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1833 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1835 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1836 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1837 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1839 /* We need to notify the parent before taking any pad locks as the bin in
1840 * question might be waiting for a lock on the pad while holding its lock
1841 * that our message will try to take. */
1842 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1843 if (GST_IS_ELEMENT (parent)) {
1844 gst_element_post_message (parent,
1845 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1846 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1848 gst_object_unref (parent);
1853 GST_OBJECT_LOCK (srcpad);
1854 GST_OBJECT_LOCK (sinkpad);
1856 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1857 goto not_linked_together;
1859 if (GST_PAD_UNLINKFUNC (srcpad)) {
1860 GstObject *tmpparent;
1862 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1864 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1865 RELEASE_PARENT (tmpparent);
1868 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1869 GstObject *tmpparent;
1871 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1873 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1874 RELEASE_PARENT (tmpparent);
1878 /* first clear peers */
1879 GST_PAD_PEER (srcpad) = NULL;
1880 GST_PAD_PEER (sinkpad) = NULL;
1882 GST_OBJECT_UNLOCK (sinkpad);
1883 GST_OBJECT_UNLOCK (srcpad);
1885 /* fire off a signal to each of the pads telling them
1886 * that they've been unlinked */
1887 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1888 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1890 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1891 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1896 if (parent != NULL) {
1897 gst_element_post_message (parent,
1898 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1899 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1900 gst_object_unref (parent);
1905 not_linked_together:
1907 /* we do not emit a warning in this case because unlinking cannot
1908 * be made MT safe.*/
1909 GST_OBJECT_UNLOCK (sinkpad);
1910 GST_OBJECT_UNLOCK (srcpad);
1916 * gst_pad_is_linked:
1917 * @pad: pad to check
1919 * Checks if a @pad is linked to another pad or not.
1921 * Returns: TRUE if the pad is linked, FALSE otherwise.
1926 gst_pad_is_linked (GstPad * pad)
1930 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1932 GST_OBJECT_LOCK (pad);
1933 result = (GST_PAD_PEER (pad) != NULL);
1934 GST_OBJECT_UNLOCK (pad);
1939 /* get the caps from both pads and see if the intersection
1942 * This function should be called with the pad LOCK on both
1946 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1947 GstPadLinkCheck flags)
1949 GstCaps *srccaps = NULL;
1950 GstCaps *sinkcaps = NULL;
1951 gboolean compatible = FALSE;
1953 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1956 /* Doing the expensive caps checking takes priority over only checking the template caps */
1957 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1958 GST_OBJECT_UNLOCK (sink);
1959 GST_OBJECT_UNLOCK (src);
1961 srccaps = gst_pad_query_caps (src, NULL);
1962 sinkcaps = gst_pad_query_caps (sink, NULL);
1964 GST_OBJECT_LOCK (src);
1965 GST_OBJECT_LOCK (sink);
1967 /* If one of the two pads doesn't have a template, consider the intersection
1969 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1970 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1974 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1976 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1979 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1981 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1984 /* if we have caps on both pads we can check the intersection. If one
1985 * of the caps is NULL, we return TRUE. */
1986 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1988 gst_caps_unref (srccaps);
1990 gst_caps_unref (sinkcaps);
1994 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1995 gst_caps_unref (srccaps);
1996 gst_caps_unref (sinkcaps);
1999 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2000 (compatible ? "" : "not"));
2005 /* check if the grandparents of both pads are the same.
2006 * This check is required so that we don't try to link
2007 * pads from elements in different bins without ghostpads.
2009 * The LOCK should be held on both pads
2012 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2014 GstObject *psrc, *psink;
2016 psrc = GST_OBJECT_PARENT (src);
2017 psink = GST_OBJECT_PARENT (sink);
2019 /* if one of the pads has no parent, we allow the link */
2020 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2023 /* only care about parents that are elements */
2024 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2025 goto no_element_parent;
2027 /* if the parents are the same, we have a loop */
2028 if (G_UNLIKELY (psrc == psink))
2031 /* if they both have a parent, we check the grandparents. We can not lock
2032 * the parent because we hold on the child (pad) and the locking order is
2033 * parent >> child. */
2034 psrc = GST_OBJECT_PARENT (psrc);
2035 psink = GST_OBJECT_PARENT (psink);
2037 /* if they have grandparents but they are not the same */
2038 if (G_UNLIKELY (psrc != psink))
2039 goto wrong_grandparents;
2046 GST_CAT_DEBUG (GST_CAT_CAPS,
2047 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2048 GST_PTR_FORMAT, psrc, psink);
2053 GST_CAT_DEBUG (GST_CAT_CAPS,
2054 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2055 GST_PTR_FORMAT, psrc, psink);
2060 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2066 GST_CAT_DEBUG (GST_CAT_CAPS,
2067 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2068 GST_PTR_FORMAT, psrc, psink);
2073 /* FIXME leftover from an attempt at refactoring... */
2074 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2075 * the two pads will be locked in the srcpad, sinkpad order. */
2076 static GstPadLinkReturn
2077 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2079 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2080 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2082 GST_OBJECT_LOCK (srcpad);
2084 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2085 goto src_was_linked;
2087 GST_OBJECT_LOCK (sinkpad);
2089 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2090 goto sink_was_linked;
2092 /* check hierarchy, pads can only be linked if the grandparents
2094 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2095 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2096 goto wrong_hierarchy;
2098 /* check pad caps for non-empty intersection */
2099 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2102 /* FIXME check pad scheduling for non-empty intersection */
2104 return GST_PAD_LINK_OK;
2108 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2109 GST_DEBUG_PAD_NAME (srcpad),
2110 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2111 /* we do not emit a warning in this case because unlinking cannot
2112 * be made MT safe.*/
2113 GST_OBJECT_UNLOCK (srcpad);
2114 return GST_PAD_LINK_WAS_LINKED;
2118 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2119 GST_DEBUG_PAD_NAME (sinkpad),
2120 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2121 /* we do not emit a warning in this case because unlinking cannot
2122 * be made MT safe.*/
2123 GST_OBJECT_UNLOCK (sinkpad);
2124 GST_OBJECT_UNLOCK (srcpad);
2125 return GST_PAD_LINK_WAS_LINKED;
2129 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2130 GST_OBJECT_UNLOCK (sinkpad);
2131 GST_OBJECT_UNLOCK (srcpad);
2132 return GST_PAD_LINK_WRONG_HIERARCHY;
2136 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2137 GST_OBJECT_UNLOCK (sinkpad);
2138 GST_OBJECT_UNLOCK (srcpad);
2139 return GST_PAD_LINK_NOFORMAT;
2145 * @srcpad: the source #GstPad.
2146 * @sinkpad: the sink #GstPad.
2148 * Checks if the source pad and the sink pad are compatible so they can be
2151 * Returns: TRUE if the pads can be linked.
2154 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2156 GstPadLinkReturn result;
2158 /* generic checks */
2159 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2160 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2162 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2163 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2165 /* gst_pad_link_prepare does everything for us, we only release the locks
2166 * on the pads that it gets us. If this function returns !OK the locks are not
2168 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2169 if (result != GST_PAD_LINK_OK)
2172 GST_OBJECT_UNLOCK (srcpad);
2173 GST_OBJECT_UNLOCK (sinkpad);
2176 return result == GST_PAD_LINK_OK;
2180 * gst_pad_link_full:
2181 * @srcpad: the source #GstPad to link.
2182 * @sinkpad: the sink #GstPad to link.
2183 * @flags: the checks to validate when linking
2185 * Links the source pad and the sink pad.
2187 * This variant of #gst_pad_link provides a more granular control on the
2188 * checks being done when linking. While providing some considerable speedups
2189 * the caller of this method must be aware that wrong usage of those flags
2190 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2191 * for more information.
2195 * Returns: A result code indicating if the connection worked or
2199 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2201 GstPadLinkReturn result;
2203 GstPadLinkFunction srcfunc, sinkfunc;
2205 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2206 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2207 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2208 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2209 GST_PAD_LINK_WRONG_DIRECTION);
2211 /* Notify the parent early. See gst_pad_unlink for details. */
2212 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2213 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2214 gst_element_post_message (parent,
2215 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2216 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2218 gst_object_unref (parent);
2223 /* prepare will also lock the two pads */
2224 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2226 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2229 /* must set peers before calling the link function */
2230 GST_PAD_PEER (srcpad) = sinkpad;
2231 GST_PAD_PEER (sinkpad) = srcpad;
2233 /* check events, when something is different, mark pending */
2234 schedule_events (srcpad, sinkpad);
2236 /* get the link functions */
2237 srcfunc = GST_PAD_LINKFUNC (srcpad);
2238 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2240 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2241 /* custom link functions, execute them */
2242 GST_OBJECT_UNLOCK (sinkpad);
2243 GST_OBJECT_UNLOCK (srcpad);
2246 GstObject *tmpparent;
2248 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2249 /* this one will call the peer link function */
2250 result = srcfunc (srcpad, tmpparent, sinkpad);
2251 RELEASE_PARENT (tmpparent);
2252 } else if (sinkfunc) {
2253 GstObject *tmpparent;
2255 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2256 /* if no source link function, we need to call the sink link
2257 * function ourselves. */
2258 result = sinkfunc (sinkpad, tmpparent, srcpad);
2259 RELEASE_PARENT (tmpparent);
2263 GST_OBJECT_LOCK (srcpad);
2264 GST_OBJECT_LOCK (sinkpad);
2266 /* we released the lock, check if the same pads are linked still */
2267 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2268 goto concurrent_link;
2270 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2273 GST_OBJECT_UNLOCK (sinkpad);
2274 GST_OBJECT_UNLOCK (srcpad);
2276 /* fire off a signal to each of the pads telling them
2277 * that they've been linked */
2278 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2279 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2281 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2282 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2284 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2287 if (G_LIKELY (parent)) {
2288 gst_element_post_message (parent,
2289 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2290 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2291 gst_object_unref (parent);
2299 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2300 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2301 GST_OBJECT_UNLOCK (sinkpad);
2302 GST_OBJECT_UNLOCK (srcpad);
2304 /* The other link operation succeeded first */
2305 result = GST_PAD_LINK_WAS_LINKED;
2310 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2311 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2313 GST_PAD_PEER (srcpad) = NULL;
2314 GST_PAD_PEER (sinkpad) = NULL;
2316 GST_OBJECT_UNLOCK (sinkpad);
2317 GST_OBJECT_UNLOCK (srcpad);
2325 * @srcpad: the source #GstPad to link.
2326 * @sinkpad: the sink #GstPad to link.
2328 * Links the source pad and the sink pad.
2330 * Returns: A result code indicating if the connection worked or
2336 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2338 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2342 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2344 GstPadTemplate **template_p;
2346 /* this function would need checks if it weren't static */
2348 GST_OBJECT_LOCK (pad);
2349 template_p = &pad->padtemplate;
2350 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2351 GST_OBJECT_UNLOCK (pad);
2354 gst_pad_template_pad_created (templ, pad);
2358 * gst_pad_get_pad_template:
2361 * Gets the template for @pad.
2363 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2364 * instantiated, or %NULL if this pad has no template. Unref after
2368 gst_pad_get_pad_template (GstPad * pad)
2370 GstPadTemplate *templ;
2372 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2374 templ = GST_PAD_PAD_TEMPLATE (pad);
2376 return (templ ? gst_object_ref (templ) : NULL);
2380 * gst_pad_has_current_caps:
2381 * @pad: a #GstPad to check
2383 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2385 * Returns: TRUE when @pad has caps associated with it.
2388 gst_pad_has_current_caps (GstPad * pad)
2393 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2395 GST_OBJECT_LOCK (pad);
2396 caps = get_pad_caps (pad);
2397 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2398 "check current pad caps %" GST_PTR_FORMAT, caps);
2399 result = (caps != NULL);
2400 GST_OBJECT_UNLOCK (pad);
2406 * gst_pad_get_current_caps:
2407 * @pad: a #GstPad to get the current capabilities of.
2409 * Gets the capabilities currently configured on @pad with the last
2410 * #GST_EVENT_CAPS event.
2412 * Returns: the current caps of the pad with incremented ref-count.
2415 gst_pad_get_current_caps (GstPad * pad)
2419 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2421 GST_OBJECT_LOCK (pad);
2422 if ((result = get_pad_caps (pad)))
2423 gst_caps_ref (result);
2424 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2425 "get current pad caps %" GST_PTR_FORMAT, result);
2426 GST_OBJECT_UNLOCK (pad);
2432 * gst_pad_get_pad_template_caps:
2433 * @pad: a #GstPad to get the template capabilities from.
2435 * Gets the capabilities for @pad's template.
2437 * Returns: (transfer full): the #GstCaps of this pad template.
2438 * Unref after usage.
2441 gst_pad_get_pad_template_caps (GstPad * pad)
2443 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2445 if (GST_PAD_PAD_TEMPLATE (pad))
2446 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2448 return gst_caps_ref (GST_CAPS_ANY);
2453 * @pad: a #GstPad to get the peer of.
2455 * Gets the peer of @pad. This function refs the peer pad so
2456 * you need to unref it after use.
2458 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2463 gst_pad_get_peer (GstPad * pad)
2467 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2469 GST_OBJECT_LOCK (pad);
2470 result = GST_PAD_PEER (pad);
2472 gst_object_ref (result);
2473 GST_OBJECT_UNLOCK (pad);
2479 * gst_pad_get_allowed_caps:
2482 * Gets the capabilities of the allowed media types that can flow through
2483 * @pad and its peer.
2485 * The allowed capabilities is calculated as the intersection of the results of
2486 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2487 * on the resulting caps.
2489 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2490 * caps when you no longer need it. This function returns NULL when @pad
2496 gst_pad_get_allowed_caps (GstPad * pad)
2502 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2504 GST_OBJECT_LOCK (pad);
2505 peer = GST_PAD_PEER (pad);
2506 if (G_UNLIKELY (peer == NULL))
2509 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2511 gst_object_ref (peer);
2512 GST_OBJECT_UNLOCK (pad);
2513 mycaps = gst_pad_query_caps (pad, NULL);
2515 caps = gst_pad_query_caps (peer, mycaps);
2516 gst_object_unref (peer);
2518 gst_caps_unref (mycaps);
2520 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2527 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2528 GST_OBJECT_UNLOCK (pad);
2535 * gst_pad_iterate_internal_links_default:
2536 * @pad: the #GstPad to get the internal links of.
2537 * @parent: the parent of @pad or NULL
2539 * Iterate the list of pads to which the given pad is linked to inside of
2540 * the parent element.
2541 * This is the default handler, and thus returns an iterator of all of the
2542 * pads inside the parent element with opposite direction.
2544 * The caller must free this iterator after use with gst_iterator_free().
2546 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2547 * returned pad with gst_object_unref().
2550 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2557 GstElement *eparent;
2559 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2561 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2562 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2564 GST_OBJECT_LOCK (pad);
2565 eparent = GST_PAD_PARENT (pad);
2566 if (!eparent || !GST_IS_ELEMENT (eparent))
2569 gst_object_ref (eparent);
2570 GST_OBJECT_UNLOCK (pad);
2573 if (pad->direction == GST_PAD_SRC)
2574 padlist = &eparent->sinkpads;
2576 padlist = &eparent->srcpads;
2578 GST_DEBUG_OBJECT (pad, "Making iterator");
2580 cookie = &eparent->pads_cookie;
2582 lock = GST_OBJECT_GET_LOCK (eparent);
2584 res = gst_iterator_new_list (GST_TYPE_PAD,
2585 lock, cookie, padlist, (GObject *) owner, NULL);
2587 gst_object_unref (owner);
2594 GST_OBJECT_UNLOCK (pad);
2595 GST_DEBUG_OBJECT (pad, "no parent element");
2601 * gst_pad_iterate_internal_links:
2602 * @pad: the GstPad to get the internal links of.
2604 * Gets an iterator for the pads to which the given pad is linked to inside
2605 * of the parent element.
2607 * Each #GstPad element yielded by the iterator will have its refcount increased,
2608 * so unref after use.
2610 * Free-function: gst_iterator_free
2612 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2613 * pad does not have an iterator function configured. Use
2614 * gst_iterator_free() after usage.
2617 gst_pad_iterate_internal_links (GstPad * pad)
2619 GstIterator *res = NULL;
2622 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2624 GST_OBJECT_LOCK (pad);
2625 ACQUIRE_PARENT (pad, parent, no_parent);
2626 GST_OBJECT_UNLOCK (pad);
2628 if (GST_PAD_ITERINTLINKFUNC (pad))
2629 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2631 RELEASE_PARENT (parent);
2638 GST_DEBUG_OBJECT (pad, "no parent");
2639 GST_OBJECT_UNLOCK (pad);
2647 * @forward: (scope call): a #GstPadForwardFunction
2648 * @user_data: user data passed to @forward
2650 * Calls @forward for all internally linked pads of @pad. This function deals with
2651 * dynamically changing internal pads and will make sure that the @forward
2652 * function is only called once for each pad.
2654 * When @forward returns TRUE, no further pads will be processed.
2656 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2659 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2662 gboolean result = FALSE;
2664 gboolean done = FALSE;
2665 GValue item = { 0, };
2666 GList *pushed_pads = NULL;
2668 iter = gst_pad_iterate_internal_links (pad);
2674 switch (gst_iterator_next (iter, &item)) {
2675 case GST_ITERATOR_OK:
2679 intpad = g_value_get_object (&item);
2681 /* if already pushed, skip. FIXME, find something faster to tag pads */
2682 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2683 g_value_reset (&item);
2687 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2688 GST_DEBUG_PAD_NAME (intpad));
2689 done = result = forward (intpad, user_data);
2691 pushed_pads = g_list_prepend (pushed_pads, intpad);
2693 g_value_reset (&item);
2696 case GST_ITERATOR_RESYNC:
2697 /* We don't reset the result here because we don't push the event
2698 * again on pads that got the event already and because we need
2699 * to consider the result of the previous pushes */
2700 gst_iterator_resync (iter);
2702 case GST_ITERATOR_ERROR:
2703 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2706 case GST_ITERATOR_DONE:
2711 g_value_unset (&item);
2712 gst_iterator_free (iter);
2714 g_list_free (pushed_pads);
2724 gboolean dispatched;
2728 event_forward_func (GstPad * pad, EventData * data)
2730 /* for each pad we send to, we should ref the event; it's up
2731 * to downstream to unref again when handled. */
2732 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2733 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2735 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2737 data->dispatched = TRUE;
2744 * gst_pad_event_default:
2745 * @pad: a #GstPad to call the default event handler on.
2746 * @parent: the parent of @pad or NULL
2747 * @event: (transfer full): the #GstEvent to handle.
2749 * Invokes the default event handler for the given pad.
2751 * The EOS event will pause the task associated with @pad before it is forwarded
2752 * to all internally linked pads,
2754 * The the event is sent to all pads internally linked to @pad. This function
2755 * takes ownership of @event.
2757 * Returns: TRUE if the event was sent successfully.
2760 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2762 gboolean result, forward = TRUE;
2764 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2765 g_return_val_if_fail (event != NULL, FALSE);
2767 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2770 switch (GST_EVENT_TYPE (event)) {
2771 case GST_EVENT_CAPS:
2772 forward = GST_PAD_IS_PROXY_CAPS (pad);
2783 data.dispatched = FALSE;
2784 data.result = FALSE;
2786 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2788 /* for sinkpads without a parent element or without internal links, nothing
2789 * will be dispatched but we still want to return TRUE. */
2790 if (data.dispatched)
2791 result = data.result;
2796 gst_event_unref (event);
2801 /* Default accept caps implementation just checks against
2802 * the allowed caps for the pad */
2804 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2806 /* get the caps and see if it intersects to something not empty */
2807 GstCaps *caps, *allowed;
2810 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2812 /* first forward the query to internally linked pads when we are dealing with
2814 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2815 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2820 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2821 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2823 allowed = gst_pad_query_caps (pad, NULL);
2824 gst_query_parse_accept_caps (query, &caps);
2827 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2828 result = gst_caps_is_subset (caps, allowed);
2829 gst_caps_unref (allowed);
2831 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2834 gst_query_set_accept_caps_result (query, result);
2840 /* Default caps implementation */
2842 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2844 GstCaps *result = NULL, *filter;
2845 GstPadTemplate *templ;
2846 gboolean fixed_caps;
2848 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2851 /* first try to proxy if we must */
2852 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2853 if ((gst_pad_proxy_query_caps (pad, query))) {
2858 gst_query_parse_caps (query, &filter);
2860 /* no proxy or it failed, do default handling */
2861 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2863 GST_OBJECT_LOCK (pad);
2865 /* fixed caps, try the negotiated caps first */
2866 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2867 if ((result = get_pad_caps (pad)))
2868 goto filter_done_unlock;
2871 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2872 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2873 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2874 goto filter_done_unlock;
2878 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2879 "non-fixed pad caps: trying pad caps");
2880 /* non fixed caps, try the negotiated caps */
2881 if ((result = get_pad_caps (pad)))
2882 goto filter_done_unlock;
2885 /* this almost never happens */
2886 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2887 result = GST_CAPS_ANY;
2890 GST_OBJECT_UNLOCK (pad);
2892 /* run the filter on the result */
2894 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2895 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2896 GST_PTR_FORMAT, result, result, filter, filter);
2897 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2898 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2901 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2902 "using caps %p %" GST_PTR_FORMAT, result, result);
2903 result = gst_caps_ref (result);
2905 gst_query_set_caps_result (query, result);
2906 gst_caps_unref (result);
2916 gboolean dispatched;
2920 query_forward_func (GstPad * pad, QueryData * data)
2922 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2923 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2925 data->result |= gst_pad_peer_query (pad, data->query);
2927 data->dispatched = TRUE;
2929 /* stop on first successful reply */
2930 return data->result;
2934 * gst_pad_query_default:
2935 * @pad: a #GstPad to call the default query handler on.
2936 * @parent: the parent of @pad or NULL
2937 * @query: (transfer none): the #GstQuery to handle.
2939 * Invokes the default query handler for the given pad.
2940 * The query is sent to all pads internally linked to @pad. Note that
2941 * if there are many possible sink pads that are internally linked to
2942 * @pad, only one will be sent the query.
2943 * Multi-sinkpad elements should implement custom query handlers.
2945 * Returns: TRUE if the query was performed successfully.
2948 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2950 gboolean forward, ret = FALSE;
2952 switch (GST_QUERY_TYPE (query)) {
2953 case GST_QUERY_SCHEDULING:
2954 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2956 case GST_QUERY_ALLOCATION:
2957 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2959 case GST_QUERY_ACCEPT_CAPS:
2960 ret = gst_pad_query_accept_caps_default (pad, query);
2963 case GST_QUERY_CAPS:
2964 ret = gst_pad_query_caps_default (pad, query);
2967 case GST_QUERY_POSITION:
2968 case GST_QUERY_SEEKING:
2969 case GST_QUERY_FORMATS:
2970 case GST_QUERY_LATENCY:
2971 case GST_QUERY_JITTER:
2972 case GST_QUERY_RATE:
2973 case GST_QUERY_CONVERT:
2979 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2980 query, GST_QUERY_TYPE_NAME (query));
2986 data.dispatched = FALSE;
2987 data.result = FALSE;
2989 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
2991 if (data.dispatched) {
2994 /* nothing dispatched, assume drained */
2995 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3005 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3007 GstPad *pad = data->pad;
3008 GstPadProbeInfo *info = data->info;
3009 GstPadProbeType type, flags;
3010 GstPadProbeCallback callback;
3011 GstPadProbeReturn ret;
3013 /* if we have called this callback, do nothing */
3014 if (PROBE_COOKIE (hook) == data->cookie) {
3015 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3016 "hook %lu, cookie %u already called", hook->hook_id,
3017 PROBE_COOKIE (hook));
3021 PROBE_COOKIE (hook) = data->cookie;
3023 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3026 /* one of the data types */
3027 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3029 /* one of the scheduling types */
3030 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3032 /* one of the blocking types must match */
3033 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3034 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3036 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3037 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3038 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3041 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3042 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3043 PROBE_COOKIE (hook), flags);
3045 data->marshalled = TRUE;
3047 callback = (GstPadProbeCallback) hook->func;
3048 if (callback == NULL)
3051 info->id = hook->hook_id;
3053 GST_OBJECT_UNLOCK (pad);
3055 ret = callback (pad, info, hook->data);
3057 GST_OBJECT_LOCK (pad);
3060 case GST_PAD_PROBE_REMOVE:
3061 /* remove the probe */
3062 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3063 cleanup_hook (pad, hook);
3065 case GST_PAD_PROBE_DROP:
3066 /* need to drop the data, make sure other probes don't get called
3068 GST_DEBUG_OBJECT (pad, "asked to drop item");
3069 info->type = GST_PAD_PROBE_TYPE_INVALID;
3070 data->dropped = TRUE;
3072 case GST_PAD_PROBE_PASS:
3073 /* inform the pad block to let things pass */
3074 GST_DEBUG_OBJECT (pad, "asked to pass item");
3077 case GST_PAD_PROBE_OK:
3078 GST_DEBUG_OBJECT (pad, "probe returned OK");
3081 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3088 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3089 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3090 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3095 /* a probe that does not take or return any data */
3096 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3098 if (G_UNLIKELY (pad->num_probes)) { \
3099 /* pass NULL as the data item */ \
3100 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3101 ret = do_probe_callbacks (pad, &info, defaultval); \
3102 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3107 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3109 if (G_UNLIKELY (pad->num_probes)) { \
3110 /* pass the data item */ \
3111 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3112 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3113 /* store the possibly updated data item */ \
3114 data = GST_PAD_PROBE_INFO_DATA (&info); \
3115 /* if something went wrong, exit */ \
3116 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3121 #define PROBE_PUSH(pad,mask,data,label) \
3122 PROBE_FULL(pad, mask, data, -1, -1, label);
3123 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3124 PROBE_FULL(pad, mask, data, offs, size, label);
3126 static GstFlowReturn
3127 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3128 GstFlowReturn defaultval)
3137 data.marshalled = FALSE;
3138 data.dropped = FALSE;
3139 data.cookie = ++pad->priv->probe_cookie;
3142 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3145 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3146 "do probes cookie %u", data.cookie);
3147 cookie = pad->priv->probe_list_cookie;
3149 g_hook_list_marshal (&pad->probes, TRUE,
3150 (GHookMarshaller) probe_hook_marshal, &data);
3152 /* if the list changed, call the new callbacks (they will not have their
3153 * cookie set to data.cookie */
3154 if (cookie != pad->priv->probe_list_cookie) {
3155 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3156 "probe list changed, restarting");
3160 /* the first item that dropped will stop the hooks and then we drop here */
3164 /* if no handler matched and we are blocking, let the item pass */
3165 if (!data.marshalled && is_block)
3168 /* At this point, all handlers returned either OK or PASS. If one handler
3169 * returned PASS, let the item pass */
3174 while (GST_PAD_IS_BLOCKED (pad)) {
3175 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3176 "we are blocked %d times", pad->num_blocked);
3178 /* we might have released the lock */
3179 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3182 /* now we block the streaming thread. It can be unlocked when we
3183 * deactivate the pad (which will also set the FLUSHING flag) or
3184 * when the pad is unblocked. A flushing event will also unblock
3185 * the pad after setting the FLUSHING flag. */
3186 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3187 "Waiting to be unblocked or set flushing");
3188 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3189 GST_PAD_BLOCK_WAIT (pad);
3190 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3191 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3193 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3203 GST_DEBUG_OBJECT (pad, "pad is flushing");
3204 return GST_FLOW_FLUSHING;
3208 GST_DEBUG_OBJECT (pad, "data is dropped");
3209 return GST_FLOW_CUSTOM_SUCCESS;
3213 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3214 GST_DEBUG_OBJECT (pad, "data is passed");
3222 * gst_pad_get_offset:
3225 * Get the offset applied to the running time of @pad. @pad has to be a source
3228 * Returns: the offset.
3231 gst_pad_get_offset (GstPad * pad)
3235 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3237 GST_OBJECT_LOCK (pad);
3238 result = pad->offset;
3239 GST_OBJECT_UNLOCK (pad);
3245 * gst_pad_set_offset:
3247 * @offset: the offset
3249 * Set the offset that will be applied to the running time of @pad.
3252 gst_pad_set_offset (GstPad * pad, gint64 offset)
3256 g_return_if_fail (GST_IS_PAD (pad));
3258 GST_OBJECT_LOCK (pad);
3259 /* if nothing changed, do nothing */
3260 if (pad->offset == offset)
3263 pad->offset = offset;
3264 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3266 /* sinkpads will apply their offset the next time a segment
3267 * event is received. */
3268 if (GST_PAD_IS_SINK (pad))
3271 /* resend the last segment event on next buffer push */
3272 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3273 ev->received = FALSE;
3274 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3278 GST_OBJECT_UNLOCK (pad);
3285 /* If TRUE and ret is not OK this means
3286 * that pushing the EOS event failed
3290 /* If called for an event this is
3291 * the event that would be pushed
3292 * next. Don't forward sticky events
3293 * that would come after that */
3297 /* should be called with pad LOCK */
3299 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3301 PushStickyData *data = user_data;
3302 GstEvent *event = ev->event;
3305 GST_DEBUG_OBJECT (pad, "event %s was already received",
3306 GST_EVENT_TYPE_NAME (event));
3310 /* If we're called because of an sticky event, only forward
3311 * events that would come before this new event and the
3313 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3314 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3315 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3316 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3318 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3319 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3322 switch (data->ret) {
3324 ev->received = TRUE;
3325 GST_DEBUG_OBJECT (pad, "event %s marked received",
3326 GST_EVENT_TYPE_NAME (event));
3328 case GST_FLOW_CUSTOM_SUCCESS:
3329 /* we can't assume the event is received when it was dropped */
3330 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3331 GST_EVENT_TYPE_NAME (event));
3332 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3333 data->ret = GST_FLOW_OK;
3335 case GST_FLOW_CUSTOM_SUCCESS_1:
3336 /* event was ignored and should be sent later */
3337 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3338 GST_EVENT_TYPE_NAME (event));
3339 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3340 data->ret = GST_FLOW_OK;
3342 case GST_FLOW_NOT_LINKED:
3343 /* not linked is not a problem, we are sticky so the event will be
3344 * sent later but only for non-EOS events */
3345 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3346 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3347 data->ret = GST_FLOW_OK;
3348 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3351 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3352 gst_flow_get_name (data->ret));
3353 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3357 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3358 data->was_eos = TRUE;
3360 return data->ret == GST_FLOW_OK;
3363 /* check sticky events and push them when needed. should be called
3365 static inline GstFlowReturn
3366 check_sticky (GstPad * pad, GstEvent * event)
3368 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3370 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3371 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3373 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3374 events_foreach (pad, push_sticky, &data);
3376 /* If there's an EOS event we must push it downstream
3377 * even if sending a previous sticky event failed.
3378 * Otherwise the pipeline might wait forever for EOS.
3380 * Only do this if pushing another event than the EOS
3383 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3384 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3386 if (ev && !ev->received) {
3387 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3388 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3389 /* the event could have been dropped. Because this can only
3390 * happen if the user asked for it, it's not an error */
3391 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3392 data.ret = GST_FLOW_OK;
3402 * @pad: a #GstPad to invoke the default query on.
3403 * @query: (transfer none): the #GstQuery to perform.
3405 * Dispatches a query to a pad. The query should have been allocated by the
3406 * caller via one of the type-specific allocation functions. The element that
3407 * the pad belongs to is responsible for filling the query with an appropriate
3408 * response, which should then be parsed with a type-specific query parsing
3411 * Again, the caller is responsible for both the allocation and deallocation of
3412 * the query structure.
3414 * Please also note that some queries might need a running pipeline to work.
3416 * Returns: TRUE if the query could be performed.
3419 gst_pad_query (GstPad * pad, GstQuery * query)
3422 gboolean res, serialized;
3423 GstPadQueryFunction func;
3424 GstPadProbeType type;
3427 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3428 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3430 if (GST_PAD_IS_SRC (pad)) {
3431 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3432 goto wrong_direction;
3433 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3434 } else if (GST_PAD_IS_SINK (pad)) {
3435 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3436 goto wrong_direction;
3437 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3439 goto unknown_direction;
3441 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3442 GST_QUERY_TYPE_NAME (query));
3444 serialized = GST_QUERY_IS_SERIALIZED (query);
3445 if (G_UNLIKELY (serialized))
3446 GST_PAD_STREAM_LOCK (pad);
3448 GST_OBJECT_LOCK (pad);
3449 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3450 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3451 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3453 ACQUIRE_PARENT (pad, parent, no_parent);
3454 GST_OBJECT_UNLOCK (pad);
3456 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3459 res = func (pad, parent, query);
3461 RELEASE_PARENT (parent);
3463 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3464 GST_QUERY_TYPE_NAME (query), res);
3469 GST_OBJECT_LOCK (pad);
3470 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3471 GST_OBJECT_UNLOCK (pad);
3473 if (G_UNLIKELY (serialized))
3474 GST_PAD_STREAM_UNLOCK (pad);
3481 g_warning ("pad %s:%s query %s in wrong direction",
3482 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3487 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3492 GST_DEBUG_OBJECT (pad, "had no parent");
3493 GST_OBJECT_UNLOCK (pad);
3494 if (G_UNLIKELY (serialized))
3495 GST_PAD_STREAM_UNLOCK (pad);
3500 GST_DEBUG_OBJECT (pad, "had no query function");
3501 RELEASE_PARENT (parent);
3502 if (G_UNLIKELY (serialized))
3503 GST_PAD_STREAM_UNLOCK (pad);
3508 GST_DEBUG_OBJECT (pad, "query failed");
3509 if (G_UNLIKELY (serialized))
3510 GST_PAD_STREAM_UNLOCK (pad);
3515 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3516 GST_OBJECT_UNLOCK (pad);
3517 if (G_UNLIKELY (serialized))
3518 GST_PAD_STREAM_UNLOCK (pad);
3520 /* if a probe dropped, we don't sent it further but assume that the probe
3521 * answered the query and return TRUE */
3522 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3532 * gst_pad_peer_query:
3533 * @pad: a #GstPad to invoke the peer query on.
3534 * @query: (transfer none): the #GstQuery to perform.
3536 * Performs gst_pad_query() on the peer of @pad.
3538 * The caller is responsible for both the allocation and deallocation of
3539 * the query structure.
3541 * Returns: TRUE if the query could be performed. This function returns %FALSE
3542 * if @pad has no peer.
3545 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3548 GstPadProbeType type;
3549 gboolean res, serialized;
3552 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3553 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3555 if (GST_PAD_IS_SRC (pad)) {
3556 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3557 goto wrong_direction;
3558 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3559 } else if (GST_PAD_IS_SINK (pad)) {
3560 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3561 goto wrong_direction;
3562 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3564 goto unknown_direction;
3566 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3567 GST_QUERY_TYPE_NAME (query));
3569 serialized = GST_QUERY_IS_SERIALIZED (query);
3571 GST_OBJECT_LOCK (pad);
3572 if (GST_PAD_IS_SRC (pad) && serialized) {
3573 /* all serialized queries on the srcpad trigger push of
3575 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3579 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3580 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3581 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3583 peerpad = GST_PAD_PEER (pad);
3584 if (G_UNLIKELY (peerpad == NULL))
3587 gst_object_ref (peerpad);
3588 GST_OBJECT_UNLOCK (pad);
3590 res = gst_pad_query (peerpad, query);
3592 gst_object_unref (peerpad);
3597 GST_OBJECT_LOCK (pad);
3598 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3599 GST_OBJECT_UNLOCK (pad);
3606 g_warning ("pad %s:%s query %s in wrong direction",
3607 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3612 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3617 GST_WARNING_OBJECT (pad, "could not send sticky events");
3618 GST_OBJECT_UNLOCK (pad);
3623 GST_INFO_OBJECT (pad, "pad has no peer");
3624 GST_OBJECT_UNLOCK (pad);
3629 GST_DEBUG_OBJECT (pad, "query failed");
3634 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3635 GST_OBJECT_UNLOCK (pad);
3637 /* if a probe dropped, we don't sent it further but assume that the probe
3638 * answered the query and return TRUE */
3639 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3648 /**********************************************************************
3649 * Data passing functions
3652 /* this is the chain function that does not perform the additional argument
3653 * checking for that little extra speed.
3655 static inline GstFlowReturn
3656 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3661 GST_PAD_STREAM_LOCK (pad);
3663 GST_OBJECT_LOCK (pad);
3664 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3667 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3670 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3673 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3675 PROBE_PUSH (pad, type, data, probe_stopped);
3677 parent = GST_OBJECT_PARENT (pad);
3678 GST_OBJECT_UNLOCK (pad);
3680 /* NOTE: we read the chainfunc unlocked.
3681 * we cannot hold the lock for the pad so we might send
3682 * the data to the wrong function. This is not really a
3683 * problem since functions are assigned at creation time
3684 * and don't change that often... */
3685 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3686 GstPadChainFunction chainfunc;
3688 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3691 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3692 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3693 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3695 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3697 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3698 "called chainfunction &%s with buffer %p, returned %s",
3699 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3701 GstPadChainListFunction chainlistfunc;
3703 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3706 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3707 "calling chainlistfunction &%s",
3708 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3710 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3712 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3713 "called chainlistfunction &%s, returned %s",
3714 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3717 GST_PAD_STREAM_UNLOCK (pad);
3724 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3725 "chaining, but pad was flushing");
3726 GST_OBJECT_UNLOCK (pad);
3727 GST_PAD_STREAM_UNLOCK (pad);
3728 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3729 return GST_FLOW_FLUSHING;
3733 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3734 GST_OBJECT_UNLOCK (pad);
3735 GST_PAD_STREAM_UNLOCK (pad);
3736 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3737 return GST_FLOW_EOS;
3741 g_critical ("chain on pad %s:%s but it was not in push mode",
3742 GST_DEBUG_PAD_NAME (pad));
3743 GST_OBJECT_UNLOCK (pad);
3744 GST_PAD_STREAM_UNLOCK (pad);
3745 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3746 return GST_FLOW_ERROR;
3750 GST_OBJECT_UNLOCK (pad);
3751 GST_PAD_STREAM_UNLOCK (pad);
3752 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3755 case GST_FLOW_CUSTOM_SUCCESS:
3756 GST_DEBUG_OBJECT (pad, "dropped buffer");
3760 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3767 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3768 g_critical ("chain on pad %s:%s but it has no chainfunction",
3769 GST_DEBUG_PAD_NAME (pad));
3770 GST_PAD_STREAM_UNLOCK (pad);
3771 return GST_FLOW_NOT_SUPPORTED;
3777 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3778 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3781 * Chain a buffer to @pad.
3783 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3785 * If the buffer type is not acceptable for @pad (as negotiated with a
3786 * preceeding GST_EVENT_CAPS event), this function returns
3787 * #GST_FLOW_NOT_NEGOTIATED.
3789 * The function proceeds calling the chain function installed on @pad (see
3790 * gst_pad_set_chain_function()) and the return value of that function is
3791 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3794 * In all cases, success or failure, the caller loses its reference to @buffer
3795 * after calling this function.
3797 * Returns: a #GstFlowReturn from the pad.
3802 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3804 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3805 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3806 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3808 return gst_pad_chain_data_unchecked (pad,
3809 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3812 static GstFlowReturn
3813 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3814 GstBufferList * list)
3820 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3822 len = gst_buffer_list_length (list);
3825 for (i = 0; i < len; i++) {
3826 buffer = gst_buffer_list_get (list, i);
3828 gst_pad_chain_data_unchecked (pad,
3829 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3830 gst_buffer_ref (buffer));
3831 if (ret != GST_FLOW_OK)
3834 gst_buffer_list_unref (list);
3840 * gst_pad_chain_list:
3841 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3842 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3845 * Chain a bufferlist to @pad.
3847 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3849 * If @pad was not negotiated properly with a CAPS event, this function
3850 * returns #GST_FLOW_NOT_NEGOTIATED.
3852 * The function proceeds calling the chainlist function installed on @pad (see
3853 * gst_pad_set_chain_list_function()) and the return value of that function is
3854 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3855 * chainlist function.
3857 * In all cases, success or failure, the caller loses its reference to @list
3858 * after calling this function.
3862 * Returns: a #GstFlowReturn from the pad.
3865 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3867 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3868 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3869 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3871 return gst_pad_chain_data_unchecked (pad,
3872 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3875 static GstFlowReturn
3876 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3881 GST_OBJECT_LOCK (pad);
3882 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3885 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3888 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3891 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3894 /* do block probes */
3895 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3897 /* recheck sticky events because the probe might have cause a relink */
3898 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3901 /* do post-blocking probes */
3902 PROBE_PUSH (pad, type, data, probe_stopped);
3904 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3907 /* take ref to peer pad before releasing the lock */
3908 gst_object_ref (peer);
3910 GST_OBJECT_UNLOCK (pad);
3912 ret = gst_pad_chain_data_unchecked (peer, type, data);
3914 gst_object_unref (peer);
3916 GST_OBJECT_LOCK (pad);
3918 if (pad->priv->using == 0) {
3919 /* pad is not active anymore, trigger idle callbacks */
3920 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3921 probe_stopped, ret);
3923 GST_OBJECT_UNLOCK (pad);
3927 /* ERROR recovery here */
3931 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3932 "pushing, but pad was flushing");
3933 GST_OBJECT_UNLOCK (pad);
3934 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3935 return GST_FLOW_FLUSHING;
3939 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3940 GST_OBJECT_UNLOCK (pad);
3941 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3942 return GST_FLOW_EOS;
3946 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3947 GST_DEBUG_PAD_NAME (pad));
3948 GST_OBJECT_UNLOCK (pad);
3949 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3950 return GST_FLOW_ERROR;
3954 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3955 "error pushing events, return %s", gst_flow_get_name (ret));
3956 GST_OBJECT_UNLOCK (pad);
3957 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3962 GST_OBJECT_UNLOCK (pad);
3963 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3966 case GST_FLOW_CUSTOM_SUCCESS:
3967 GST_DEBUG_OBJECT (pad, "dropped buffer");
3971 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3978 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3979 "pushing, but it was not linked");
3980 GST_OBJECT_UNLOCK (pad);
3981 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3982 return GST_FLOW_NOT_LINKED;
3988 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3989 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3992 * Pushes a buffer to the peer of @pad.
3994 * This function will call installed block probes before triggering any
3995 * installed data probes.
3997 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3998 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4001 * In all cases, success or failure, the caller loses its reference to @buffer
4002 * after calling this function.
4004 * Returns: a #GstFlowReturn from the peer pad.
4009 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4011 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4012 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4013 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4015 return gst_pad_push_data (pad,
4016 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4020 * gst_pad_push_list:
4021 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4022 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4025 * Pushes a buffer list to the peer of @pad.
4027 * This function will call installed block probes before triggering any
4028 * installed data probes.
4030 * The function proceeds calling the chain function on the peer pad and returns
4031 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4032 * be returned. If the peer pad does not have any installed chainlist function
4033 * every group buffer of the list will be merged into a normal #GstBuffer and
4034 * chained via gst_pad_chain().
4036 * In all cases, success or failure, the caller loses its reference to @list
4037 * after calling this function.
4039 * Returns: a #GstFlowReturn from the peer pad.
4044 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4046 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4047 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4048 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4050 return gst_pad_push_data (pad,
4051 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4054 static GstFlowReturn
4055 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4056 GstBuffer ** buffer)
4059 GstPadGetRangeFunction getrangefunc;
4063 GST_PAD_STREAM_LOCK (pad);
4065 GST_OBJECT_LOCK (pad);
4066 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4069 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4072 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4077 /* when one of the probes returns DROPPED, probe_stopped will be called
4078 * and we skip calling the getrange function, res_buf should then contain a
4079 * valid result buffer */
4080 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4081 res_buf, offset, size, probe_stopped);
4083 /* recheck sticky events because the probe might have cause a relink */
4084 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4087 ACQUIRE_PARENT (pad, parent, no_parent);
4088 GST_OBJECT_UNLOCK (pad);
4090 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4093 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4094 "calling getrangefunc %s, offset %"
4095 G_GUINT64_FORMAT ", size %u",
4096 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4098 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4100 RELEASE_PARENT (parent);
4102 if (G_UNLIKELY (ret != GST_FLOW_OK))
4103 goto get_range_failed;
4105 /* can only fire the signal if we have a valid buffer */
4106 GST_OBJECT_LOCK (pad);
4108 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4109 res_buf, offset, size, probe_stopped_unref);
4110 GST_OBJECT_UNLOCK (pad);
4112 GST_PAD_STREAM_UNLOCK (pad);
4121 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4122 "getrange, but pad was flushing");
4123 GST_OBJECT_UNLOCK (pad);
4124 GST_PAD_STREAM_UNLOCK (pad);
4125 return GST_FLOW_FLUSHING;
4129 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4130 GST_DEBUG_PAD_NAME (pad));
4131 GST_OBJECT_UNLOCK (pad);
4132 GST_PAD_STREAM_UNLOCK (pad);
4133 return GST_FLOW_ERROR;
4137 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4138 GST_OBJECT_UNLOCK (pad);
4139 GST_PAD_STREAM_UNLOCK (pad);
4144 GST_DEBUG_OBJECT (pad, "no parent");
4145 GST_OBJECT_UNLOCK (pad);
4146 GST_PAD_STREAM_UNLOCK (pad);
4147 return GST_FLOW_FLUSHING;
4151 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4152 GST_DEBUG_PAD_NAME (pad));
4153 RELEASE_PARENT (parent);
4154 GST_PAD_STREAM_UNLOCK (pad);
4155 return GST_FLOW_NOT_SUPPORTED;
4159 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4160 "probe returned %s", gst_flow_get_name (ret));
4161 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4163 /* the probe filled the buffer and asks us to not call the getrange
4164 * anymore, we continue with the post probes then. */
4165 GST_DEBUG_OBJECT (pad, "handled buffer");
4169 /* no buffer, we are EOS */
4170 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4174 GST_OBJECT_UNLOCK (pad);
4175 GST_PAD_STREAM_UNLOCK (pad);
4179 probe_stopped_unref:
4181 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4182 "probe returned %s", gst_flow_get_name (ret));
4183 /* if we drop here, it signals EOS */
4184 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4186 GST_OBJECT_UNLOCK (pad);
4187 GST_PAD_STREAM_UNLOCK (pad);
4188 if (*buffer == NULL)
4189 gst_buffer_unref (res_buf);
4194 GST_PAD_STREAM_UNLOCK (pad);
4195 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4196 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4197 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4203 * gst_pad_get_range:
4204 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4205 * @offset: The start offset of the buffer
4206 * @size: The length of the buffer
4207 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4208 * returns #GST_FLOW_ERROR if %NULL.
4210 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4211 * immediately and @buffer is %NULL.
4213 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4214 * description of a getrange function. If @pad has no getrange function
4215 * installed (see gst_pad_set_getrange_function()) this function returns
4216 * #GST_FLOW_NOT_SUPPORTED.
4218 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4219 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4220 * must be freed with gst_buffer_unref() after usage.
4222 * When @buffer points to a variable that points to a valid #GstBuffer, the
4223 * buffer will be filled with the result data when this function returns
4224 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4225 * @size bytes will be filled in the result buffer and its size will be updated
4228 * Note that less than @size bytes can be returned in @buffer when, for example,
4229 * an EOS condition is near or when @buffer is not large enough to hold @size
4230 * bytes. The caller should check the result buffer size to get the result size.
4232 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4233 * will be unchanged.
4235 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4237 * Returns: a #GstFlowReturn from the pad.
4242 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4243 GstBuffer ** buffer)
4245 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4246 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4247 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4248 g_return_val_if_fail (*buffer == NULL
4249 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4251 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4255 * gst_pad_pull_range:
4256 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4257 * @offset: The start offset of the buffer
4258 * @size: The length of the buffer
4259 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4260 * GST_FLOW_ERROR if %NULL.
4262 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4264 * This function will first trigger the pad block signal if it was
4267 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4268 * function returns the result of gst_pad_get_range() on the peer pad.
4269 * See gst_pad_get_range() for a list of return values and for the
4270 * semantics of the arguments of this function.
4272 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4273 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4274 * must be freed with gst_buffer_unref() after usage. When this function
4275 * returns any other result value, @buffer will still point to NULL.
4277 * When @buffer points to a variable that points to a valid #GstBuffer, the
4278 * buffer will be filled with the result data when this function returns
4279 * #GST_FLOW_OK. When this function returns any other result value,
4280 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4281 * @size bytes will be filled in the result buffer and its size will be updated
4284 * Note that less than @size bytes can be returned in @buffer when, for example,
4285 * an EOS condition is near or when @buffer is not large enough to hold @size
4286 * bytes. The caller should check the result buffer size to get the result size.
4288 * Returns: a #GstFlowReturn from the peer pad.
4293 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4294 GstBuffer ** buffer)
4300 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4301 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4302 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4303 g_return_val_if_fail (*buffer == NULL
4304 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4306 GST_OBJECT_LOCK (pad);
4307 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4310 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4315 /* when one of the probes returns DROPPED, probe_stopped will be
4316 * called and we skip calling the peer getrange function. *buffer should then
4317 * contain a valid buffer */
4318 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4319 res_buf, offset, size, probe_stopped);
4321 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4324 gst_object_ref (peer);
4326 GST_OBJECT_UNLOCK (pad);
4328 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4330 gst_object_unref (peer);
4332 GST_OBJECT_LOCK (pad);
4334 if (pad->priv->using == 0) {
4335 /* pad is not active anymore, trigger idle callbacks */
4336 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4337 probe_stopped_unref, ret);
4340 if (G_UNLIKELY (ret != GST_FLOW_OK))
4341 goto pull_range_failed;
4344 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4345 res_buf, offset, size, probe_stopped_unref);
4347 GST_OBJECT_UNLOCK (pad);
4353 /* ERROR recovery here */
4356 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4357 "pullrange, but pad was flushing");
4358 GST_OBJECT_UNLOCK (pad);
4359 return GST_FLOW_FLUSHING;
4363 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4364 GST_DEBUG_PAD_NAME (pad));
4365 GST_OBJECT_UNLOCK (pad);
4366 return GST_FLOW_ERROR;
4370 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4371 gst_flow_get_name (ret));
4372 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4374 /* the probe filled the buffer and asks us to not forward to the peer
4375 * anymore, we continue with the post probes then */
4376 GST_DEBUG_OBJECT (pad, "handled buffer");
4380 /* no buffer, we are EOS then */
4381 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4385 GST_OBJECT_UNLOCK (pad);
4390 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4391 "pulling range, but it was not linked");
4392 GST_OBJECT_UNLOCK (pad);
4393 return GST_FLOW_NOT_LINKED;
4397 GST_OBJECT_UNLOCK (pad);
4398 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4399 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4400 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4403 probe_stopped_unref:
4405 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4406 "post probe returned %s", gst_flow_get_name (ret));
4407 GST_OBJECT_UNLOCK (pad);
4408 /* if we drop here, it signals EOS */
4409 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4411 if (*buffer == NULL)
4412 gst_buffer_unref (res_buf);
4417 /* must be called with pad object lock */
4418 static GstFlowReturn
4419 store_sticky_event (GstPad * pad, GstEvent * event)
4424 gboolean res = FALSE;
4425 const gchar *name = NULL;
4426 gboolean insert = TRUE;
4428 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4431 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4434 type = GST_EVENT_TYPE (event);
4435 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4436 name = gst_structure_get_name (gst_event_get_structure (event));
4438 events = pad->priv->events;
4441 for (i = 0; i < len; i++) {
4442 PadEvent *ev = &g_array_index (events, PadEvent, i);
4444 if (ev->event == NULL)
4447 if (type == GST_EVENT_TYPE (ev->event)) {
4448 /* matching types, check matching name if needed */
4449 if (name && !gst_event_has_name (ev->event, name))
4453 if ((res = gst_event_replace (&ev->event, event)))
4454 ev->received = FALSE;
4460 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4461 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4462 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4463 * storing the sticky ordered we can check that this is respected. */
4464 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4465 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4467 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4468 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4469 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4470 gst_event_type_get_name (type));
4476 ev.event = gst_event_ref (event);
4477 ev.received = FALSE;
4478 g_array_insert_val (events, i, ev);
4483 pad->priv->events_cookie++;
4484 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4486 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4488 switch (GST_EVENT_TYPE (event)) {
4489 case GST_EVENT_CAPS:
4490 GST_OBJECT_UNLOCK (pad);
4492 GST_DEBUG_OBJECT (pad, "notify caps");
4493 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4495 GST_OBJECT_LOCK (pad);
4501 if (type == GST_EVENT_EOS)
4502 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4509 GST_DEBUG_OBJECT (pad, "pad is flushing");
4510 return GST_FLOW_FLUSHING;
4514 GST_DEBUG_OBJECT (pad, "pad is EOS");
4515 return GST_FLOW_EOS;
4520 * gst_pad_store_sticky_event:
4522 * @event: a #GstEvent
4524 * Store the sticky @event on @pad
4526 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4527 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4532 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4536 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4537 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4539 GST_OBJECT_LOCK (pad);
4540 ret = store_sticky_event (pad, event);
4541 GST_OBJECT_UNLOCK (pad);
4546 /* should be called with pad LOCK */
4547 static GstFlowReturn
4548 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4549 GstPadProbeType type)
4553 GstEventType event_type;
4555 /* Two checks to be made:
4556 * . (un)set the FLUSHING flag for flushing events,
4557 * . handle pad blocking */
4558 event_type = GST_EVENT_TYPE (event);
4559 switch (event_type) {
4560 case GST_EVENT_FLUSH_START:
4561 GST_PAD_SET_FLUSHING (pad);
4563 GST_PAD_BLOCK_BROADCAST (pad);
4564 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4566 case GST_EVENT_FLUSH_STOP:
4567 GST_PAD_UNSET_FLUSHING (pad);
4569 /* Remove sticky EOS events */
4570 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4571 remove_event_by_type (pad, GST_EVENT_EOS);
4572 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4573 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4575 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4579 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4582 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4583 * checked already or this is called as part of pushing sticky events,
4584 * in which case we still want to forward the EOS event downstream.
4587 switch (GST_EVENT_TYPE (event)) {
4588 case GST_EVENT_SEGMENT:
4589 /* pass the adjusted segment event on. We need to do this even if
4590 * there is no peer pad because of the probes. */
4591 event = apply_pad_offset (pad, event);
4593 case GST_EVENT_RECONFIGURE:
4594 if (GST_PAD_IS_SINK (pad))
4595 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4600 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4601 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4606 /* send probes after modifying the events above */
4607 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4609 /* now check the peer pad */
4610 peerpad = GST_PAD_PEER (pad);
4611 if (peerpad == NULL)
4614 gst_object_ref (peerpad);
4616 GST_OBJECT_UNLOCK (pad);
4618 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4619 event, GST_EVENT_TYPE_NAME (event), peerpad);
4621 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4623 /* Note: we gave away ownership of the event at this point but we can still
4624 * print the old pointer */
4625 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4626 event, peerpad, gst_flow_get_name (ret));
4628 gst_object_unref (peerpad);
4630 GST_OBJECT_LOCK (pad);
4632 if (pad->priv->using == 0) {
4633 /* pad is not active anymore, trigger idle callbacks */
4634 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4635 idle_probe_stopped, ret);
4639 /* ERROR handling */
4642 GST_DEBUG_OBJECT (pad, "We're flushing");
4643 gst_event_unref (event);
4644 return GST_FLOW_FLUSHING;
4648 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4649 gst_event_unref (event);
4652 case GST_FLOW_CUSTOM_SUCCESS:
4653 GST_DEBUG_OBJECT (pad, "dropped event");
4656 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4663 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4664 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4665 gst_event_unref (event);
4667 /* unlinked pads should not influence latency configuration */
4668 if (event_type == GST_EVENT_LATENCY)
4671 return GST_FLOW_NOT_LINKED;
4675 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4681 * gst_pad_push_event:
4682 * @pad: a #GstPad to push the event to.
4683 * @event: (transfer full): the #GstEvent to send to the pad.
4685 * Sends the event to the peer of the given pad. This function is
4686 * mainly used by elements to send events to their peer
4689 * This function takes owership of the provided event so you should
4690 * gst_event_ref() it if you want to reuse the event after this call.
4692 * Returns: TRUE if the event was handled.
4697 gst_pad_push_event (GstPad * pad, GstEvent * event)
4699 gboolean res = FALSE;
4700 GstPadProbeType type;
4701 gboolean sticky, serialized;
4703 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4704 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4706 if (GST_PAD_IS_SRC (pad)) {
4707 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4708 goto wrong_direction;
4709 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4710 } else if (GST_PAD_IS_SINK (pad)) {
4711 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4712 goto wrong_direction;
4713 /* events pushed on sinkpad never are sticky */
4714 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4716 goto unknown_direction;
4718 GST_OBJECT_LOCK (pad);
4719 sticky = GST_EVENT_IS_STICKY (event);
4720 serialized = GST_EVENT_IS_SERIALIZED (event);
4723 /* srcpad sticky events are stored immediately, the received flag is set
4724 * to FALSE and will be set to TRUE when we can successfully push the
4725 * event to the peer pad */
4726 switch (store_sticky_event (pad, event)) {
4727 case GST_FLOW_FLUSHING:
4735 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4736 /* all serialized or sticky events on the srcpad trigger push of
4738 res = (check_sticky (pad, event) == GST_FLOW_OK);
4743 /* other events are pushed right away */
4744 ret = gst_pad_push_event_unchecked (pad, event, type);
4745 /* dropped events by a probe are not an error */
4746 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4748 /* Errors in sticky event pushing are no problem and ignored here
4749 * as they will cause more meaningful errors during data flow.
4750 * For EOS events, that are not followed by data flow, we still
4751 * return FALSE here though.
4753 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4755 gst_event_unref (event);
4757 GST_OBJECT_UNLOCK (pad);
4761 /* ERROR handling */
4764 g_warning ("pad %s:%s pushing %s event in wrong direction",
4765 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4766 gst_event_unref (event);
4771 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4772 gst_event_unref (event);
4777 GST_DEBUG_OBJECT (pad, "We're flushing");
4778 GST_OBJECT_UNLOCK (pad);
4779 gst_event_unref (event);
4784 GST_DEBUG_OBJECT (pad, "We're EOS");
4785 GST_OBJECT_UNLOCK (pad);
4786 gst_event_unref (event);
4791 /* Check if we can call the event function with the given event */
4792 static GstFlowReturn
4793 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4797 switch (GST_EVENT_TYPE (event)) {
4798 case GST_EVENT_CAPS:
4800 /* backwards compatibility mode for caps */
4801 gst_event_parse_caps (event, &caps);
4803 if (!gst_pad_query_accept_caps (pad, caps))
4815 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4816 "caps %" GST_PTR_FORMAT " not accepted", caps);
4817 return GST_FLOW_NOT_NEGOTIATED;
4821 static GstFlowReturn
4822 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4823 GstPadProbeType type)
4826 GstEventType event_type;
4827 gboolean serialized, need_unlock = FALSE, sticky;
4828 GstPadEventFunction eventfunc;
4831 GST_OBJECT_LOCK (pad);
4832 if (GST_PAD_IS_SINK (pad))
4833 serialized = GST_EVENT_IS_SERIALIZED (event);
4836 sticky = GST_EVENT_IS_STICKY (event);
4837 event_type = GST_EVENT_TYPE (event);
4838 switch (event_type) {
4839 case GST_EVENT_FLUSH_START:
4840 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4841 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4843 /* can't even accept a flush begin event when flushing */
4844 if (GST_PAD_IS_FLUSHING (pad))
4847 GST_PAD_SET_FLUSHING (pad);
4848 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4850 case GST_EVENT_FLUSH_STOP:
4851 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4852 GST_PAD_UNSET_FLUSHING (pad);
4853 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4855 /* Remove pending EOS events */
4856 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4857 remove_event_by_type (pad, GST_EVENT_EOS);
4858 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4859 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4861 GST_OBJECT_UNLOCK (pad);
4862 /* grab stream lock */
4863 GST_PAD_STREAM_LOCK (pad);
4865 GST_OBJECT_LOCK (pad);
4866 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4869 case GST_EVENT_RECONFIGURE:
4870 if (GST_PAD_IS_SRC (pad))
4871 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4873 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4874 "have event type %" GST_PTR_FORMAT, event);
4876 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4880 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4883 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4884 GST_OBJECT_UNLOCK (pad);
4885 GST_PAD_STREAM_LOCK (pad);
4887 GST_OBJECT_LOCK (pad);
4888 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4891 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4895 switch (GST_EVENT_TYPE (event)) {
4896 case GST_EVENT_SEGMENT:
4897 event = apply_pad_offset (pad, event);
4905 /* now do the probe */
4907 type | GST_PAD_PROBE_TYPE_PUSH |
4908 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4910 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4912 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4915 ACQUIRE_PARENT (pad, parent, no_parent);
4916 GST_OBJECT_UNLOCK (pad);
4918 ret = pre_eventfunc_check (pad, event);
4919 if (G_UNLIKELY (ret != GST_FLOW_OK))
4920 goto precheck_failed;
4923 gst_event_ref (event);
4925 if (eventfunc (pad, parent, event)) {
4928 /* something went wrong */
4929 switch (event_type) {
4930 case GST_EVENT_CAPS:
4931 ret = GST_FLOW_NOT_NEGOTIATED;
4934 ret = GST_FLOW_ERROR;
4938 RELEASE_PARENT (parent);
4940 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4943 if (ret == GST_FLOW_OK) {
4944 GST_OBJECT_LOCK (pad);
4945 /* after the event function accepted the event, we can store the sticky
4946 * event on the pad */
4947 switch (store_sticky_event (pad, event)) {
4948 case GST_FLOW_FLUSHING:
4955 GST_OBJECT_UNLOCK (pad);
4957 gst_event_unref (event);
4961 GST_PAD_STREAM_UNLOCK (pad);
4965 /* ERROR handling */
4968 GST_OBJECT_UNLOCK (pad);
4970 GST_PAD_STREAM_UNLOCK (pad);
4971 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4972 "Received event on flushing pad. Discarding");
4973 gst_event_unref (event);
4974 return GST_FLOW_FLUSHING;
4978 GST_OBJECT_UNLOCK (pad);
4980 GST_PAD_STREAM_UNLOCK (pad);
4981 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4982 "Received event on EOS pad. Discarding");
4983 gst_event_unref (event);
4984 return GST_FLOW_EOS;
4988 GST_OBJECT_UNLOCK (pad);
4990 GST_PAD_STREAM_UNLOCK (pad);
4991 gst_event_unref (event);
4994 case GST_FLOW_CUSTOM_SUCCESS:
4995 GST_DEBUG_OBJECT (pad, "dropped event");
4999 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
5006 g_warning ("pad %s:%s has no event handler, file a bug.",
5007 GST_DEBUG_PAD_NAME (pad));
5008 GST_OBJECT_UNLOCK (pad);
5010 GST_PAD_STREAM_UNLOCK (pad);
5011 gst_event_unref (event);
5012 return GST_FLOW_NOT_SUPPORTED;
5016 GST_DEBUG_OBJECT (pad, "no parent");
5017 GST_OBJECT_UNLOCK (pad);
5019 GST_PAD_STREAM_UNLOCK (pad);
5020 gst_event_unref (event);
5021 return GST_FLOW_FLUSHING;
5025 GST_DEBUG_OBJECT (pad, "pre event check failed");
5026 RELEASE_PARENT (parent);
5028 GST_PAD_STREAM_UNLOCK (pad);
5029 gst_event_unref (event);
5035 * gst_pad_send_event:
5036 * @pad: a #GstPad to send the event to.
5037 * @event: (transfer full): the #GstEvent to send to the pad.
5039 * Sends the event to the pad. This function can be used
5040 * by applications to send events in the pipeline.
5042 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5043 * sink pad, @event should be a downstream event. For example, you would not
5044 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5045 * Furthermore, some downstream events have to be serialized with data flow,
5046 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5047 * the event needs to be serialized with data flow, this function will take the
5048 * pad's stream lock while calling its event function.
5050 * To find out whether an event type is upstream, downstream, or downstream and
5051 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5052 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5053 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5054 * plugin doesn't need to bother itself with this information; the core handles
5055 * all necessary locks and checks.
5057 * This function takes owership of the provided event so you should
5058 * gst_event_ref() it if you want to reuse the event after this call.
5060 * Returns: TRUE if the event was handled.
5063 gst_pad_send_event (GstPad * pad, GstEvent * event)
5066 GstPadProbeType type;
5068 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5069 g_return_val_if_fail (event != NULL, FALSE);
5071 if (GST_PAD_IS_SINK (pad)) {
5072 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5073 goto wrong_direction;
5074 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5075 } else if (GST_PAD_IS_SRC (pad)) {
5076 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5077 goto wrong_direction;
5078 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5080 goto unknown_direction;
5082 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5089 /* ERROR handling */
5092 g_warning ("pad %s:%s sending %s event in wrong direction",
5093 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5094 gst_event_unref (event);
5099 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5100 gst_event_unref (event);
5106 * gst_pad_set_element_private:
5107 * @pad: the #GstPad to set the private data of.
5108 * @priv: The private data to attach to the pad.
5110 * Set the given private data gpointer on the pad.
5111 * This function can only be used by the element that owns the pad.
5112 * No locking is performed in this function.
5115 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5117 pad->element_private = priv;
5121 * gst_pad_get_element_private:
5122 * @pad: the #GstPad to get the private data of.
5124 * Gets the private data of a pad.
5125 * No locking is performed in this function.
5127 * Returns: (transfer none): a #gpointer to the private data.
5130 gst_pad_get_element_private (GstPad * pad)
5132 return pad->element_private;
5136 * gst_pad_get_sticky_event:
5137 * @pad: the #GstPad to get the event from.
5138 * @event_type: the #GstEventType that should be retrieved.
5139 * @idx: the index of the event
5141 * Returns a new reference of the sticky event of type @event_type
5144 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5145 * event of @event_type was on @pad. Unref after usage.
5148 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5150 GstEvent *event = NULL;
5153 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5154 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5156 GST_OBJECT_LOCK (pad);
5157 ev = find_event_by_type (pad, event_type, idx);
5158 if (ev && (event = ev->event))
5159 gst_event_ref (event);
5160 GST_OBJECT_UNLOCK (pad);
5167 GstPadStickyEventsForeachFunction func;
5172 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5174 ForeachDispatch *data = user_data;
5178 GST_OBJECT_UNLOCK (pad);
5180 ret = data->func (pad, &ev->event, data->user_data);
5182 GST_OBJECT_LOCK (pad);
5189 * gst_pad_sticky_events_foreach:
5190 * @pad: the #GstPad that should be used for iteration.
5191 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5192 * should be called for every event.
5193 * @user_data: (closure): the optional user data.
5195 * Iterates all sticky events on @pad and calls @foreach_func for every
5196 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5199 gst_pad_sticky_events_foreach (GstPad * pad,
5200 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5202 ForeachDispatch data;
5204 g_return_if_fail (GST_IS_PAD (pad));
5205 g_return_if_fail (foreach_func != NULL);
5207 data.func = foreach_func;
5208 data.user_data = user_data;
5210 GST_OBJECT_LOCK (pad);
5211 events_foreach (pad, foreach_dispatch_function, &data);
5212 GST_OBJECT_UNLOCK (pad);
5216 do_stream_status (GstPad * pad, GstStreamStatusType type,
5217 GThread * thread, GstTask * task)
5221 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5223 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5224 if (GST_IS_ELEMENT (parent)) {
5225 GstMessage *message;
5226 GValue value = { 0 };
5228 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5229 gchar *tname, *ename, *pname;
5231 /* create a good task name */
5232 ename = gst_element_get_name (parent);
5233 pname = gst_pad_get_name (pad);
5234 tname = g_strdup_printf ("%s:%s", ename, pname);
5238 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5242 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5245 g_value_init (&value, GST_TYPE_TASK);
5246 g_value_set_object (&value, task);
5247 gst_message_set_stream_status_object (message, &value);
5248 g_value_unset (&value);
5250 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5251 gst_element_post_message (parent, message);
5253 gst_object_unref (parent);
5258 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5260 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5265 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5267 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5272 * gst_pad_start_task:
5273 * @pad: the #GstPad to start the task of
5274 * @func: the task function to call
5275 * @user_data: user data passed to the task function
5276 * @notify: called when @user_data is no longer referenced
5278 * Starts a task that repeatedly calls @func with @user_data. This function
5279 * is mostly used in pad activation functions to start the dataflow.
5280 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5281 * before @func is called.
5283 * Returns: a %TRUE if the task could be started.
5286 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5287 GDestroyNotify notify)
5292 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5293 g_return_val_if_fail (func != NULL, FALSE);
5295 GST_DEBUG_OBJECT (pad, "start task");
5297 GST_OBJECT_LOCK (pad);
5298 task = GST_PAD_TASK (pad);
5300 task = gst_task_new (func, user_data, notify);
5301 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5302 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5303 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5304 GST_INFO_OBJECT (pad, "created task %p", task);
5305 GST_PAD_TASK (pad) = task;
5306 gst_object_ref (task);
5307 /* release lock to post the message */
5308 GST_OBJECT_UNLOCK (pad);
5310 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5312 gst_object_unref (task);
5314 GST_OBJECT_LOCK (pad);
5315 /* nobody else is supposed to have changed the pad now */
5316 if (GST_PAD_TASK (pad) != task)
5317 goto concurrent_stop;
5319 res = gst_task_set_state (task, GST_TASK_STARTED);
5320 GST_OBJECT_UNLOCK (pad);
5327 GST_OBJECT_UNLOCK (pad);
5333 * gst_pad_pause_task:
5334 * @pad: the #GstPad to pause the task of
5336 * Pause the task of @pad. This function will also wait until the
5337 * function executed by the task is finished if this function is not
5338 * called from the task function.
5340 * Returns: a TRUE if the task could be paused or FALSE when the pad
5344 gst_pad_pause_task (GstPad * pad)
5349 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5351 GST_DEBUG_OBJECT (pad, "pause task");
5353 GST_OBJECT_LOCK (pad);
5354 task = GST_PAD_TASK (pad);
5357 res = gst_task_set_state (task, GST_TASK_PAUSED);
5358 GST_OBJECT_UNLOCK (pad);
5360 /* wait for task function to finish, this lock is recursive so it does nothing
5361 * when the pause is called from the task itself */
5362 GST_PAD_STREAM_LOCK (pad);
5363 GST_PAD_STREAM_UNLOCK (pad);
5369 GST_DEBUG_OBJECT (pad, "pad has no task");
5370 GST_OBJECT_UNLOCK (pad);
5376 * gst_pad_stop_task:
5377 * @pad: the #GstPad to stop the task of
5379 * Stop the task of @pad. This function will also make sure that the
5380 * function executed by the task will effectively stop if not called
5381 * from the GstTaskFunction.
5383 * This function will deadlock if called from the GstTaskFunction of
5384 * the task. Use gst_task_pause() instead.
5386 * Regardless of whether the pad has a task, the stream lock is acquired and
5387 * released so as to ensure that streaming through this pad has finished.
5389 * Returns: a TRUE if the task could be stopped or FALSE on error.
5392 gst_pad_stop_task (GstPad * pad)
5397 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5399 GST_DEBUG_OBJECT (pad, "stop task");
5401 GST_OBJECT_LOCK (pad);
5402 task = GST_PAD_TASK (pad);
5405 GST_PAD_TASK (pad) = NULL;
5406 res = gst_task_set_state (task, GST_TASK_STOPPED);
5407 GST_OBJECT_UNLOCK (pad);
5409 GST_PAD_STREAM_LOCK (pad);
5410 GST_PAD_STREAM_UNLOCK (pad);
5412 if (!gst_task_join (task))
5415 gst_object_unref (task);
5421 GST_DEBUG_OBJECT (pad, "no task");
5422 GST_OBJECT_UNLOCK (pad);
5424 GST_PAD_STREAM_LOCK (pad);
5425 GST_PAD_STREAM_UNLOCK (pad);
5427 /* this is not an error */
5432 /* this is bad, possibly the application tried to join the task from
5433 * the task's thread. We install the task again so that it will be stopped
5434 * again from the right thread next time hopefully. */
5435 GST_OBJECT_LOCK (pad);
5436 GST_DEBUG_OBJECT (pad, "join failed");
5437 /* we can only install this task if there was no other task */
5438 if (GST_PAD_TASK (pad) == NULL)
5439 GST_PAD_TASK (pad) = task;
5440 GST_OBJECT_UNLOCK (pad);
5447 * gst_pad_probe_info_get_event:
5448 * @info: a #GstPadProbeInfo
5450 * Returns: (transfer none): The #GstEvent from the probe
5454 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5456 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5457 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5459 return GST_PAD_PROBE_INFO_EVENT (info);
5464 * gst_pad_probe_info_get_query:
5465 * @info: a #GstPadProbeInfo
5467 * Returns: (transfer none): The #GstQuery from the probe
5471 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5473 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5474 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5476 return GST_PAD_PROBE_INFO_QUERY (info);
5480 * gst_pad_probe_info_get_buffer:
5481 * @info: a #GstPadProbeInfo
5483 * Returns: (transfer none): The #GstBuffer from the probe
5487 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5489 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5491 return GST_PAD_PROBE_INFO_BUFFER (info);
5495 * gst_pad_probe_info_get_bufferlist:
5496 * @info: a #GstPadProbeInfo
5498 * Returns: (transfer none): The #GstBufferlist from the probe
5502 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5504 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5506 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);