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 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3675 ":%s:<%s:%s> Got data flow before stream-start event",
3676 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3678 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3680 ":%s:<%s:%s> Got data flow before segment event",
3681 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3684 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3686 PROBE_PUSH (pad, type, data, probe_stopped);
3688 parent = GST_OBJECT_PARENT (pad);
3689 GST_OBJECT_UNLOCK (pad);
3691 /* NOTE: we read the chainfunc unlocked.
3692 * we cannot hold the lock for the pad so we might send
3693 * the data to the wrong function. This is not really a
3694 * problem since functions are assigned at creation time
3695 * and don't change that often... */
3696 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3697 GstPadChainFunction chainfunc;
3699 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3702 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3703 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3704 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3706 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3708 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3709 "called chainfunction &%s with buffer %p, returned %s",
3710 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3712 GstPadChainListFunction chainlistfunc;
3714 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3717 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3718 "calling chainlistfunction &%s",
3719 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3721 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3723 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3724 "called chainlistfunction &%s, returned %s",
3725 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3728 GST_PAD_STREAM_UNLOCK (pad);
3735 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3736 "chaining, but pad was flushing");
3737 GST_OBJECT_UNLOCK (pad);
3738 GST_PAD_STREAM_UNLOCK (pad);
3739 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3740 return GST_FLOW_FLUSHING;
3744 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3745 GST_OBJECT_UNLOCK (pad);
3746 GST_PAD_STREAM_UNLOCK (pad);
3747 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3748 return GST_FLOW_EOS;
3752 g_critical ("chain on pad %s:%s but it was not in push mode",
3753 GST_DEBUG_PAD_NAME (pad));
3754 GST_OBJECT_UNLOCK (pad);
3755 GST_PAD_STREAM_UNLOCK (pad);
3756 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3757 return GST_FLOW_ERROR;
3761 GST_OBJECT_UNLOCK (pad);
3762 GST_PAD_STREAM_UNLOCK (pad);
3763 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3766 case GST_FLOW_CUSTOM_SUCCESS:
3767 GST_DEBUG_OBJECT (pad, "dropped buffer");
3771 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3778 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3779 g_critical ("chain on pad %s:%s but it has no chainfunction",
3780 GST_DEBUG_PAD_NAME (pad));
3781 GST_PAD_STREAM_UNLOCK (pad);
3782 return GST_FLOW_NOT_SUPPORTED;
3788 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3789 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3792 * Chain a buffer to @pad.
3794 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3796 * If the buffer type is not acceptable for @pad (as negotiated with a
3797 * preceeding GST_EVENT_CAPS event), this function returns
3798 * #GST_FLOW_NOT_NEGOTIATED.
3800 * The function proceeds calling the chain function installed on @pad (see
3801 * gst_pad_set_chain_function()) and the return value of that function is
3802 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3805 * In all cases, success or failure, the caller loses its reference to @buffer
3806 * after calling this function.
3808 * Returns: a #GstFlowReturn from the pad.
3813 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3815 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3816 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3817 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3819 return gst_pad_chain_data_unchecked (pad,
3820 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3823 static GstFlowReturn
3824 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3825 GstBufferList * list)
3831 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3833 len = gst_buffer_list_length (list);
3836 for (i = 0; i < len; i++) {
3837 buffer = gst_buffer_list_get (list, i);
3839 gst_pad_chain_data_unchecked (pad,
3840 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3841 gst_buffer_ref (buffer));
3842 if (ret != GST_FLOW_OK)
3845 gst_buffer_list_unref (list);
3851 * gst_pad_chain_list:
3852 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3853 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3856 * Chain a bufferlist to @pad.
3858 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3860 * If @pad was not negotiated properly with a CAPS event, this function
3861 * returns #GST_FLOW_NOT_NEGOTIATED.
3863 * The function proceeds calling the chainlist function installed on @pad (see
3864 * gst_pad_set_chain_list_function()) and the return value of that function is
3865 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3866 * chainlist function.
3868 * In all cases, success or failure, the caller loses its reference to @list
3869 * after calling this function.
3873 * Returns: a #GstFlowReturn from the pad.
3876 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3878 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3879 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3880 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3882 return gst_pad_chain_data_unchecked (pad,
3883 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3886 static GstFlowReturn
3887 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3892 GST_OBJECT_LOCK (pad);
3893 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3896 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3899 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3902 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3904 ":%s:<%s:%s> Got data flow before stream-start event",
3905 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3907 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3909 ":%s:<%s:%s> Got data flow before segment event",
3910 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3913 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3916 /* do block probes */
3917 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3919 /* recheck sticky events because the probe might have cause a relink */
3920 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3923 /* do post-blocking probes */
3924 PROBE_PUSH (pad, type, data, probe_stopped);
3926 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3929 /* take ref to peer pad before releasing the lock */
3930 gst_object_ref (peer);
3932 GST_OBJECT_UNLOCK (pad);
3934 ret = gst_pad_chain_data_unchecked (peer, type, data);
3936 gst_object_unref (peer);
3938 GST_OBJECT_LOCK (pad);
3940 if (pad->priv->using == 0) {
3941 /* pad is not active anymore, trigger idle callbacks */
3942 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3943 probe_stopped, ret);
3945 GST_OBJECT_UNLOCK (pad);
3949 /* ERROR recovery here */
3953 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3954 "pushing, but pad was flushing");
3955 GST_OBJECT_UNLOCK (pad);
3956 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3957 return GST_FLOW_FLUSHING;
3961 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3962 GST_OBJECT_UNLOCK (pad);
3963 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3964 return GST_FLOW_EOS;
3968 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3969 GST_DEBUG_PAD_NAME (pad));
3970 GST_OBJECT_UNLOCK (pad);
3971 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3972 return GST_FLOW_ERROR;
3976 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3977 "error pushing events, return %s", gst_flow_get_name (ret));
3978 GST_OBJECT_UNLOCK (pad);
3979 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3984 GST_OBJECT_UNLOCK (pad);
3985 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3988 case GST_FLOW_CUSTOM_SUCCESS:
3989 GST_DEBUG_OBJECT (pad, "dropped buffer");
3993 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4000 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4001 "pushing, but it was not linked");
4002 GST_OBJECT_UNLOCK (pad);
4003 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4004 return GST_FLOW_NOT_LINKED;
4010 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4011 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4014 * Pushes a buffer to the peer of @pad.
4016 * This function will call installed block probes before triggering any
4017 * installed data probes.
4019 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4020 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4023 * In all cases, success or failure, the caller loses its reference to @buffer
4024 * after calling this function.
4026 * Returns: a #GstFlowReturn from the peer pad.
4031 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4033 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4034 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4035 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4037 return gst_pad_push_data (pad,
4038 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4042 * gst_pad_push_list:
4043 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4044 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4047 * Pushes a buffer list to the peer of @pad.
4049 * This function will call installed block probes before triggering any
4050 * installed data probes.
4052 * The function proceeds calling the chain function on the peer pad and returns
4053 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4054 * be returned. If the peer pad does not have any installed chainlist function
4055 * every group buffer of the list will be merged into a normal #GstBuffer and
4056 * chained via gst_pad_chain().
4058 * In all cases, success or failure, the caller loses its reference to @list
4059 * after calling this function.
4061 * Returns: a #GstFlowReturn from the peer pad.
4066 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4068 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4069 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4070 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4072 return gst_pad_push_data (pad,
4073 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4076 static GstFlowReturn
4077 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4078 GstBuffer ** buffer)
4081 GstPadGetRangeFunction getrangefunc;
4085 GST_PAD_STREAM_LOCK (pad);
4087 GST_OBJECT_LOCK (pad);
4088 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4091 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4094 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4099 /* when one of the probes returns DROPPED, probe_stopped will be called
4100 * and we skip calling the getrange function, res_buf should then contain a
4101 * valid result buffer */
4102 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4103 res_buf, offset, size, probe_stopped);
4105 /* recheck sticky events because the probe might have cause a relink */
4106 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4109 ACQUIRE_PARENT (pad, parent, no_parent);
4110 GST_OBJECT_UNLOCK (pad);
4112 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4115 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4116 "calling getrangefunc %s, offset %"
4117 G_GUINT64_FORMAT ", size %u",
4118 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4120 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4122 RELEASE_PARENT (parent);
4124 if (G_UNLIKELY (ret != GST_FLOW_OK))
4125 goto get_range_failed;
4127 /* can only fire the signal if we have a valid buffer */
4128 GST_OBJECT_LOCK (pad);
4130 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4131 res_buf, offset, size, probe_stopped_unref);
4132 GST_OBJECT_UNLOCK (pad);
4134 GST_PAD_STREAM_UNLOCK (pad);
4143 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4144 "getrange, but pad was flushing");
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 was not activated in pull mode",
4152 GST_DEBUG_PAD_NAME (pad));
4153 GST_OBJECT_UNLOCK (pad);
4154 GST_PAD_STREAM_UNLOCK (pad);
4155 return GST_FLOW_ERROR;
4159 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4160 GST_OBJECT_UNLOCK (pad);
4161 GST_PAD_STREAM_UNLOCK (pad);
4166 GST_DEBUG_OBJECT (pad, "no parent");
4167 GST_OBJECT_UNLOCK (pad);
4168 GST_PAD_STREAM_UNLOCK (pad);
4169 return GST_FLOW_FLUSHING;
4173 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4174 GST_DEBUG_PAD_NAME (pad));
4175 RELEASE_PARENT (parent);
4176 GST_PAD_STREAM_UNLOCK (pad);
4177 return GST_FLOW_NOT_SUPPORTED;
4181 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4182 "probe returned %s", gst_flow_get_name (ret));
4183 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4185 /* the probe filled the buffer and asks us to not call the getrange
4186 * anymore, we continue with the post probes then. */
4187 GST_DEBUG_OBJECT (pad, "handled buffer");
4191 /* no buffer, we are EOS */
4192 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4196 GST_OBJECT_UNLOCK (pad);
4197 GST_PAD_STREAM_UNLOCK (pad);
4201 probe_stopped_unref:
4203 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4204 "probe returned %s", gst_flow_get_name (ret));
4205 /* if we drop here, it signals EOS */
4206 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4208 GST_OBJECT_UNLOCK (pad);
4209 GST_PAD_STREAM_UNLOCK (pad);
4210 if (*buffer == NULL)
4211 gst_buffer_unref (res_buf);
4216 GST_PAD_STREAM_UNLOCK (pad);
4217 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4218 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4219 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4225 * gst_pad_get_range:
4226 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4227 * @offset: The start offset of the buffer
4228 * @size: The length of the buffer
4229 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4230 * returns #GST_FLOW_ERROR if %NULL.
4232 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4233 * immediately and @buffer is %NULL.
4235 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4236 * description of a getrange function. If @pad has no getrange function
4237 * installed (see gst_pad_set_getrange_function()) this function returns
4238 * #GST_FLOW_NOT_SUPPORTED.
4240 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4241 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4242 * must be freed with gst_buffer_unref() after usage.
4244 * When @buffer points to a variable that points to a valid #GstBuffer, the
4245 * buffer will be filled with the result data when this function returns
4246 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4247 * @size bytes will be filled in the result buffer and its size will be updated
4250 * Note that less than @size bytes can be returned in @buffer when, for example,
4251 * an EOS condition is near or when @buffer is not large enough to hold @size
4252 * bytes. The caller should check the result buffer size to get the result size.
4254 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4255 * will be unchanged.
4257 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4259 * Returns: a #GstFlowReturn from the pad.
4264 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4265 GstBuffer ** buffer)
4267 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4268 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4269 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4270 g_return_val_if_fail (*buffer == NULL
4271 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4273 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4277 * gst_pad_pull_range:
4278 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4279 * @offset: The start offset of the buffer
4280 * @size: The length of the buffer
4281 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4282 * GST_FLOW_ERROR if %NULL.
4284 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4286 * This function will first trigger the pad block signal if it was
4289 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4290 * function returns the result of gst_pad_get_range() on the peer pad.
4291 * See gst_pad_get_range() for a list of return values and for the
4292 * semantics of the arguments of this function.
4294 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4295 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4296 * must be freed with gst_buffer_unref() after usage. When this function
4297 * returns any other result value, @buffer will still point to NULL.
4299 * When @buffer points to a variable that points to a valid #GstBuffer, the
4300 * buffer will be filled with the result data when this function returns
4301 * #GST_FLOW_OK. When this function returns any other result value,
4302 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4303 * @size bytes will be filled in the result buffer and its size will be updated
4306 * Note that less than @size bytes can be returned in @buffer when, for example,
4307 * an EOS condition is near or when @buffer is not large enough to hold @size
4308 * bytes. The caller should check the result buffer size to get the result size.
4310 * Returns: a #GstFlowReturn from the peer pad.
4315 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4316 GstBuffer ** buffer)
4322 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4323 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4324 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4325 g_return_val_if_fail (*buffer == NULL
4326 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4328 GST_OBJECT_LOCK (pad);
4329 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4332 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4337 /* when one of the probes returns DROPPED, probe_stopped will be
4338 * called and we skip calling the peer getrange function. *buffer should then
4339 * contain a valid buffer */
4340 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4341 res_buf, offset, size, probe_stopped);
4343 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4346 gst_object_ref (peer);
4348 GST_OBJECT_UNLOCK (pad);
4350 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4352 gst_object_unref (peer);
4354 GST_OBJECT_LOCK (pad);
4356 if (pad->priv->using == 0) {
4357 /* pad is not active anymore, trigger idle callbacks */
4358 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4359 probe_stopped_unref, ret);
4362 if (G_UNLIKELY (ret != GST_FLOW_OK))
4363 goto pull_range_failed;
4366 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4367 res_buf, offset, size, probe_stopped_unref);
4369 GST_OBJECT_UNLOCK (pad);
4375 /* ERROR recovery here */
4378 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4379 "pullrange, but pad was flushing");
4380 GST_OBJECT_UNLOCK (pad);
4381 return GST_FLOW_FLUSHING;
4385 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4386 GST_DEBUG_PAD_NAME (pad));
4387 GST_OBJECT_UNLOCK (pad);
4388 return GST_FLOW_ERROR;
4392 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4393 gst_flow_get_name (ret));
4394 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4396 /* the probe filled the buffer and asks us to not forward to the peer
4397 * anymore, we continue with the post probes then */
4398 GST_DEBUG_OBJECT (pad, "handled buffer");
4402 /* no buffer, we are EOS then */
4403 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4407 GST_OBJECT_UNLOCK (pad);
4412 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4413 "pulling range, but it was not linked");
4414 GST_OBJECT_UNLOCK (pad);
4415 return GST_FLOW_NOT_LINKED;
4419 GST_OBJECT_UNLOCK (pad);
4420 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4421 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4422 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4425 probe_stopped_unref:
4427 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4428 "post probe returned %s", gst_flow_get_name (ret));
4429 GST_OBJECT_UNLOCK (pad);
4430 /* if we drop here, it signals EOS */
4431 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4433 if (*buffer == NULL)
4434 gst_buffer_unref (res_buf);
4439 /* must be called with pad object lock */
4440 static GstFlowReturn
4441 store_sticky_event (GstPad * pad, GstEvent * event)
4446 gboolean res = FALSE;
4447 const gchar *name = NULL;
4448 gboolean insert = TRUE;
4450 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4453 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4456 type = GST_EVENT_TYPE (event);
4457 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4458 name = gst_structure_get_name (gst_event_get_structure (event));
4460 events = pad->priv->events;
4463 for (i = 0; i < len; i++) {
4464 PadEvent *ev = &g_array_index (events, PadEvent, i);
4466 if (ev->event == NULL)
4469 if (type == GST_EVENT_TYPE (ev->event)) {
4470 /* matching types, check matching name if needed */
4471 if (name && !gst_event_has_name (ev->event, name))
4475 if ((res = gst_event_replace (&ev->event, event)))
4476 ev->received = FALSE;
4482 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4483 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4484 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4485 * storing the sticky ordered we can check that this is respected. */
4486 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4487 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4489 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4490 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4491 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4492 gst_event_type_get_name (type));
4498 ev.event = gst_event_ref (event);
4499 ev.received = FALSE;
4500 g_array_insert_val (events, i, ev);
4505 pad->priv->events_cookie++;
4506 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4508 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4510 switch (GST_EVENT_TYPE (event)) {
4511 case GST_EVENT_CAPS:
4512 GST_OBJECT_UNLOCK (pad);
4514 GST_DEBUG_OBJECT (pad, "notify caps");
4515 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4517 GST_OBJECT_LOCK (pad);
4523 if (type == GST_EVENT_EOS)
4524 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4531 GST_DEBUG_OBJECT (pad, "pad is flushing");
4532 return GST_FLOW_FLUSHING;
4536 GST_DEBUG_OBJECT (pad, "pad is EOS");
4537 return GST_FLOW_EOS;
4542 * gst_pad_store_sticky_event:
4544 * @event: a #GstEvent
4546 * Store the sticky @event on @pad
4548 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4549 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4554 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4558 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4559 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4561 GST_OBJECT_LOCK (pad);
4562 ret = store_sticky_event (pad, event);
4563 GST_OBJECT_UNLOCK (pad);
4568 /* should be called with pad LOCK */
4569 static GstFlowReturn
4570 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4571 GstPadProbeType type)
4575 GstEventType event_type;
4577 /* Two checks to be made:
4578 * . (un)set the FLUSHING flag for flushing events,
4579 * . handle pad blocking */
4580 event_type = GST_EVENT_TYPE (event);
4581 switch (event_type) {
4582 case GST_EVENT_FLUSH_START:
4583 GST_PAD_SET_FLUSHING (pad);
4585 GST_PAD_BLOCK_BROADCAST (pad);
4586 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4588 case GST_EVENT_FLUSH_STOP:
4589 GST_PAD_UNSET_FLUSHING (pad);
4591 /* Remove sticky EOS events */
4592 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4593 remove_event_by_type (pad, GST_EVENT_EOS);
4594 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4595 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4597 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4601 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4604 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4605 * checked already or this is called as part of pushing sticky events,
4606 * in which case we still want to forward the EOS event downstream.
4609 switch (GST_EVENT_TYPE (event)) {
4610 case GST_EVENT_SEGMENT:
4611 /* pass the adjusted segment event on. We need to do this even if
4612 * there is no peer pad because of the probes. */
4613 event = apply_pad_offset (pad, event);
4615 case GST_EVENT_RECONFIGURE:
4616 if (GST_PAD_IS_SINK (pad))
4617 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4622 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4623 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4628 /* send probes after modifying the events above */
4629 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4631 /* now check the peer pad */
4632 peerpad = GST_PAD_PEER (pad);
4633 if (peerpad == NULL)
4636 gst_object_ref (peerpad);
4638 GST_OBJECT_UNLOCK (pad);
4640 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4641 event, GST_EVENT_TYPE_NAME (event), peerpad);
4643 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4645 /* Note: we gave away ownership of the event at this point but we can still
4646 * print the old pointer */
4647 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4648 event, peerpad, gst_flow_get_name (ret));
4650 gst_object_unref (peerpad);
4652 GST_OBJECT_LOCK (pad);
4654 if (pad->priv->using == 0) {
4655 /* pad is not active anymore, trigger idle callbacks */
4656 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4657 idle_probe_stopped, ret);
4661 /* ERROR handling */
4664 GST_DEBUG_OBJECT (pad, "We're flushing");
4665 gst_event_unref (event);
4666 return GST_FLOW_FLUSHING;
4670 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4671 gst_event_unref (event);
4674 case GST_FLOW_CUSTOM_SUCCESS:
4675 GST_DEBUG_OBJECT (pad, "dropped event");
4678 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4685 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4686 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4687 gst_event_unref (event);
4689 /* unlinked pads should not influence latency configuration */
4690 if (event_type == GST_EVENT_LATENCY)
4693 return GST_FLOW_NOT_LINKED;
4697 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4703 * gst_pad_push_event:
4704 * @pad: a #GstPad to push the event to.
4705 * @event: (transfer full): the #GstEvent to send to the pad.
4707 * Sends the event to the peer of the given pad. This function is
4708 * mainly used by elements to send events to their peer
4711 * This function takes owership of the provided event so you should
4712 * gst_event_ref() it if you want to reuse the event after this call.
4714 * Returns: TRUE if the event was handled.
4719 gst_pad_push_event (GstPad * pad, GstEvent * event)
4721 gboolean res = FALSE;
4722 GstPadProbeType type;
4723 gboolean sticky, serialized;
4725 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4726 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4728 if (GST_PAD_IS_SRC (pad)) {
4729 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4730 goto wrong_direction;
4731 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4732 } else if (GST_PAD_IS_SINK (pad)) {
4733 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4734 goto wrong_direction;
4735 /* events pushed on sinkpad never are sticky */
4736 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4738 goto unknown_direction;
4740 GST_OBJECT_LOCK (pad);
4741 sticky = GST_EVENT_IS_STICKY (event);
4742 serialized = GST_EVENT_IS_SERIALIZED (event);
4745 /* srcpad sticky events are stored immediately, the received flag is set
4746 * to FALSE and will be set to TRUE when we can successfully push the
4747 * event to the peer pad */
4748 switch (store_sticky_event (pad, event)) {
4749 case GST_FLOW_FLUSHING:
4757 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4758 /* all serialized or sticky events on the srcpad trigger push of
4760 res = (check_sticky (pad, event) == GST_FLOW_OK);
4765 /* other events are pushed right away */
4766 ret = gst_pad_push_event_unchecked (pad, event, type);
4767 /* dropped events by a probe are not an error */
4768 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4770 /* Errors in sticky event pushing are no problem and ignored here
4771 * as they will cause more meaningful errors during data flow.
4772 * For EOS events, that are not followed by data flow, we still
4773 * return FALSE here though.
4775 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4777 gst_event_unref (event);
4779 GST_OBJECT_UNLOCK (pad);
4783 /* ERROR handling */
4786 g_warning ("pad %s:%s pushing %s event in wrong direction",
4787 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4788 gst_event_unref (event);
4793 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4794 gst_event_unref (event);
4799 GST_DEBUG_OBJECT (pad, "We're flushing");
4800 GST_OBJECT_UNLOCK (pad);
4801 gst_event_unref (event);
4806 GST_DEBUG_OBJECT (pad, "We're EOS");
4807 GST_OBJECT_UNLOCK (pad);
4808 gst_event_unref (event);
4813 /* Check if we can call the event function with the given event */
4814 static GstFlowReturn
4815 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4819 switch (GST_EVENT_TYPE (event)) {
4820 case GST_EVENT_CAPS:
4822 /* backwards compatibility mode for caps */
4823 gst_event_parse_caps (event, &caps);
4825 if (!gst_pad_query_accept_caps (pad, caps))
4837 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4838 "caps %" GST_PTR_FORMAT " not accepted", caps);
4839 return GST_FLOW_NOT_NEGOTIATED;
4843 static GstFlowReturn
4844 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4845 GstPadProbeType type)
4848 GstEventType event_type;
4849 gboolean serialized, need_unlock = FALSE, sticky;
4850 GstPadEventFunction eventfunc;
4853 GST_OBJECT_LOCK (pad);
4854 if (GST_PAD_IS_SINK (pad))
4855 serialized = GST_EVENT_IS_SERIALIZED (event);
4858 sticky = GST_EVENT_IS_STICKY (event);
4859 event_type = GST_EVENT_TYPE (event);
4860 switch (event_type) {
4861 case GST_EVENT_FLUSH_START:
4862 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4863 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4865 /* can't even accept a flush begin event when flushing */
4866 if (GST_PAD_IS_FLUSHING (pad))
4869 GST_PAD_SET_FLUSHING (pad);
4870 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4872 case GST_EVENT_FLUSH_STOP:
4873 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4874 GST_PAD_UNSET_FLUSHING (pad);
4875 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4877 /* Remove pending EOS events */
4878 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4879 remove_event_by_type (pad, GST_EVENT_EOS);
4880 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4881 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4883 GST_OBJECT_UNLOCK (pad);
4884 /* grab stream lock */
4885 GST_PAD_STREAM_LOCK (pad);
4887 GST_OBJECT_LOCK (pad);
4888 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4891 case GST_EVENT_RECONFIGURE:
4892 if (GST_PAD_IS_SRC (pad))
4893 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4895 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4896 "have event type %" GST_PTR_FORMAT, event);
4898 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4902 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4905 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4906 GST_OBJECT_UNLOCK (pad);
4907 GST_PAD_STREAM_LOCK (pad);
4909 GST_OBJECT_LOCK (pad);
4910 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4913 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4917 switch (GST_EVENT_TYPE (event)) {
4918 case GST_EVENT_SEGMENT:
4919 event = apply_pad_offset (pad, event);
4927 /* now do the probe */
4929 type | GST_PAD_PROBE_TYPE_PUSH |
4930 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4932 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4934 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4937 ACQUIRE_PARENT (pad, parent, no_parent);
4938 GST_OBJECT_UNLOCK (pad);
4940 ret = pre_eventfunc_check (pad, event);
4941 if (G_UNLIKELY (ret != GST_FLOW_OK))
4942 goto precheck_failed;
4945 gst_event_ref (event);
4947 if (eventfunc (pad, parent, event)) {
4950 /* something went wrong */
4951 switch (event_type) {
4952 case GST_EVENT_CAPS:
4953 ret = GST_FLOW_NOT_NEGOTIATED;
4956 ret = GST_FLOW_ERROR;
4960 RELEASE_PARENT (parent);
4962 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4965 if (ret == GST_FLOW_OK) {
4966 GST_OBJECT_LOCK (pad);
4967 /* after the event function accepted the event, we can store the sticky
4968 * event on the pad */
4969 switch (store_sticky_event (pad, event)) {
4970 case GST_FLOW_FLUSHING:
4977 GST_OBJECT_UNLOCK (pad);
4979 gst_event_unref (event);
4983 GST_PAD_STREAM_UNLOCK (pad);
4987 /* ERROR handling */
4990 GST_OBJECT_UNLOCK (pad);
4992 GST_PAD_STREAM_UNLOCK (pad);
4993 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4994 "Received event on flushing pad. Discarding");
4995 gst_event_unref (event);
4996 return GST_FLOW_FLUSHING;
5000 GST_OBJECT_UNLOCK (pad);
5002 GST_PAD_STREAM_UNLOCK (pad);
5003 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5004 "Received event on EOS pad. Discarding");
5005 gst_event_unref (event);
5006 return GST_FLOW_EOS;
5010 GST_OBJECT_UNLOCK (pad);
5012 GST_PAD_STREAM_UNLOCK (pad);
5013 gst_event_unref (event);
5016 case GST_FLOW_CUSTOM_SUCCESS:
5017 GST_DEBUG_OBJECT (pad, "dropped event");
5021 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
5028 g_warning ("pad %s:%s has no event handler, file a bug.",
5029 GST_DEBUG_PAD_NAME (pad));
5030 GST_OBJECT_UNLOCK (pad);
5032 GST_PAD_STREAM_UNLOCK (pad);
5033 gst_event_unref (event);
5034 return GST_FLOW_NOT_SUPPORTED;
5038 GST_DEBUG_OBJECT (pad, "no parent");
5039 GST_OBJECT_UNLOCK (pad);
5041 GST_PAD_STREAM_UNLOCK (pad);
5042 gst_event_unref (event);
5043 return GST_FLOW_FLUSHING;
5047 GST_DEBUG_OBJECT (pad, "pre event check failed");
5048 RELEASE_PARENT (parent);
5050 GST_PAD_STREAM_UNLOCK (pad);
5051 gst_event_unref (event);
5057 * gst_pad_send_event:
5058 * @pad: a #GstPad to send the event to.
5059 * @event: (transfer full): the #GstEvent to send to the pad.
5061 * Sends the event to the pad. This function can be used
5062 * by applications to send events in the pipeline.
5064 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5065 * sink pad, @event should be a downstream event. For example, you would not
5066 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5067 * Furthermore, some downstream events have to be serialized with data flow,
5068 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5069 * the event needs to be serialized with data flow, this function will take the
5070 * pad's stream lock while calling its event function.
5072 * To find out whether an event type is upstream, downstream, or downstream and
5073 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5074 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5075 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5076 * plugin doesn't need to bother itself with this information; the core handles
5077 * all necessary locks and checks.
5079 * This function takes owership of the provided event so you should
5080 * gst_event_ref() it if you want to reuse the event after this call.
5082 * Returns: TRUE if the event was handled.
5085 gst_pad_send_event (GstPad * pad, GstEvent * event)
5088 GstPadProbeType type;
5090 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5091 g_return_val_if_fail (event != NULL, FALSE);
5093 if (GST_PAD_IS_SINK (pad)) {
5094 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5095 goto wrong_direction;
5096 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5097 } else if (GST_PAD_IS_SRC (pad)) {
5098 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5099 goto wrong_direction;
5100 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5102 goto unknown_direction;
5104 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5111 /* ERROR handling */
5114 g_warning ("pad %s:%s sending %s event in wrong direction",
5115 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5116 gst_event_unref (event);
5121 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5122 gst_event_unref (event);
5128 * gst_pad_set_element_private:
5129 * @pad: the #GstPad to set the private data of.
5130 * @priv: The private data to attach to the pad.
5132 * Set the given private data gpointer on the pad.
5133 * This function can only be used by the element that owns the pad.
5134 * No locking is performed in this function.
5137 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5139 pad->element_private = priv;
5143 * gst_pad_get_element_private:
5144 * @pad: the #GstPad to get the private data of.
5146 * Gets the private data of a pad.
5147 * No locking is performed in this function.
5149 * Returns: (transfer none): a #gpointer to the private data.
5152 gst_pad_get_element_private (GstPad * pad)
5154 return pad->element_private;
5158 * gst_pad_get_sticky_event:
5159 * @pad: the #GstPad to get the event from.
5160 * @event_type: the #GstEventType that should be retrieved.
5161 * @idx: the index of the event
5163 * Returns a new reference of the sticky event of type @event_type
5166 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5167 * event of @event_type was on @pad. Unref after usage.
5170 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5172 GstEvent *event = NULL;
5175 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5176 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5178 GST_OBJECT_LOCK (pad);
5179 ev = find_event_by_type (pad, event_type, idx);
5180 if (ev && (event = ev->event))
5181 gst_event_ref (event);
5182 GST_OBJECT_UNLOCK (pad);
5189 GstPadStickyEventsForeachFunction func;
5194 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5196 ForeachDispatch *data = user_data;
5200 GST_OBJECT_UNLOCK (pad);
5202 ret = data->func (pad, &ev->event, data->user_data);
5204 GST_OBJECT_LOCK (pad);
5211 * gst_pad_sticky_events_foreach:
5212 * @pad: the #GstPad that should be used for iteration.
5213 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5214 * should be called for every event.
5215 * @user_data: (closure): the optional user data.
5217 * Iterates all sticky events on @pad and calls @foreach_func for every
5218 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5221 gst_pad_sticky_events_foreach (GstPad * pad,
5222 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5224 ForeachDispatch data;
5226 g_return_if_fail (GST_IS_PAD (pad));
5227 g_return_if_fail (foreach_func != NULL);
5229 data.func = foreach_func;
5230 data.user_data = user_data;
5232 GST_OBJECT_LOCK (pad);
5233 events_foreach (pad, foreach_dispatch_function, &data);
5234 GST_OBJECT_UNLOCK (pad);
5238 do_stream_status (GstPad * pad, GstStreamStatusType type,
5239 GThread * thread, GstTask * task)
5243 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5245 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5246 if (GST_IS_ELEMENT (parent)) {
5247 GstMessage *message;
5248 GValue value = { 0 };
5250 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5251 gchar *tname, *ename, *pname;
5253 /* create a good task name */
5254 ename = gst_element_get_name (parent);
5255 pname = gst_pad_get_name (pad);
5256 tname = g_strdup_printf ("%s:%s", ename, pname);
5260 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5264 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5267 g_value_init (&value, GST_TYPE_TASK);
5268 g_value_set_object (&value, task);
5269 gst_message_set_stream_status_object (message, &value);
5270 g_value_unset (&value);
5272 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5273 gst_element_post_message (parent, message);
5275 gst_object_unref (parent);
5280 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5282 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5287 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5289 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5294 * gst_pad_start_task:
5295 * @pad: the #GstPad to start the task of
5296 * @func: the task function to call
5297 * @user_data: user data passed to the task function
5298 * @notify: called when @user_data is no longer referenced
5300 * Starts a task that repeatedly calls @func with @user_data. This function
5301 * is mostly used in pad activation functions to start the dataflow.
5302 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5303 * before @func is called.
5305 * Returns: a %TRUE if the task could be started.
5308 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5309 GDestroyNotify notify)
5314 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5315 g_return_val_if_fail (func != NULL, FALSE);
5317 GST_DEBUG_OBJECT (pad, "start task");
5319 GST_OBJECT_LOCK (pad);
5320 task = GST_PAD_TASK (pad);
5322 task = gst_task_new (func, user_data, notify);
5323 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5324 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5325 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5326 GST_INFO_OBJECT (pad, "created task %p", task);
5327 GST_PAD_TASK (pad) = task;
5328 gst_object_ref (task);
5329 /* release lock to post the message */
5330 GST_OBJECT_UNLOCK (pad);
5332 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5334 gst_object_unref (task);
5336 GST_OBJECT_LOCK (pad);
5337 /* nobody else is supposed to have changed the pad now */
5338 if (GST_PAD_TASK (pad) != task)
5339 goto concurrent_stop;
5341 res = gst_task_set_state (task, GST_TASK_STARTED);
5342 GST_OBJECT_UNLOCK (pad);
5349 GST_OBJECT_UNLOCK (pad);
5355 * gst_pad_pause_task:
5356 * @pad: the #GstPad to pause the task of
5358 * Pause the task of @pad. This function will also wait until the
5359 * function executed by the task is finished if this function is not
5360 * called from the task function.
5362 * Returns: a TRUE if the task could be paused or FALSE when the pad
5366 gst_pad_pause_task (GstPad * pad)
5371 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5373 GST_DEBUG_OBJECT (pad, "pause task");
5375 GST_OBJECT_LOCK (pad);
5376 task = GST_PAD_TASK (pad);
5379 res = gst_task_set_state (task, GST_TASK_PAUSED);
5380 GST_OBJECT_UNLOCK (pad);
5382 /* wait for task function to finish, this lock is recursive so it does nothing
5383 * when the pause is called from the task itself */
5384 GST_PAD_STREAM_LOCK (pad);
5385 GST_PAD_STREAM_UNLOCK (pad);
5391 GST_DEBUG_OBJECT (pad, "pad has no task");
5392 GST_OBJECT_UNLOCK (pad);
5398 * gst_pad_stop_task:
5399 * @pad: the #GstPad to stop the task of
5401 * Stop the task of @pad. This function will also make sure that the
5402 * function executed by the task will effectively stop if not called
5403 * from the GstTaskFunction.
5405 * This function will deadlock if called from the GstTaskFunction of
5406 * the task. Use gst_task_pause() instead.
5408 * Regardless of whether the pad has a task, the stream lock is acquired and
5409 * released so as to ensure that streaming through this pad has finished.
5411 * Returns: a TRUE if the task could be stopped or FALSE on error.
5414 gst_pad_stop_task (GstPad * pad)
5419 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5421 GST_DEBUG_OBJECT (pad, "stop task");
5423 GST_OBJECT_LOCK (pad);
5424 task = GST_PAD_TASK (pad);
5427 GST_PAD_TASK (pad) = NULL;
5428 res = gst_task_set_state (task, GST_TASK_STOPPED);
5429 GST_OBJECT_UNLOCK (pad);
5431 GST_PAD_STREAM_LOCK (pad);
5432 GST_PAD_STREAM_UNLOCK (pad);
5434 if (!gst_task_join (task))
5437 gst_object_unref (task);
5443 GST_DEBUG_OBJECT (pad, "no task");
5444 GST_OBJECT_UNLOCK (pad);
5446 GST_PAD_STREAM_LOCK (pad);
5447 GST_PAD_STREAM_UNLOCK (pad);
5449 /* this is not an error */
5454 /* this is bad, possibly the application tried to join the task from
5455 * the task's thread. We install the task again so that it will be stopped
5456 * again from the right thread next time hopefully. */
5457 GST_OBJECT_LOCK (pad);
5458 GST_DEBUG_OBJECT (pad, "join failed");
5459 /* we can only install this task if there was no other task */
5460 if (GST_PAD_TASK (pad) == NULL)
5461 GST_PAD_TASK (pad) = task;
5462 GST_OBJECT_UNLOCK (pad);
5469 * gst_pad_probe_info_get_event:
5470 * @info: a #GstPadProbeInfo
5472 * Returns: (transfer none): The #GstEvent from the probe
5476 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5478 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5479 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5481 return GST_PAD_PROBE_INFO_EVENT (info);
5486 * gst_pad_probe_info_get_query:
5487 * @info: a #GstPadProbeInfo
5489 * Returns: (transfer none): The #GstQuery from the probe
5493 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5495 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5496 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5498 return GST_PAD_PROBE_INFO_QUERY (info);
5502 * gst_pad_probe_info_get_buffer:
5503 * @info: a #GstPadProbeInfo
5505 * Returns: (transfer none): The #GstBuffer from the probe
5509 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5511 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5513 return GST_PAD_PROBE_INFO_BUFFER (info);
5517 * gst_pad_probe_info_get_bufferlist:
5518 * @info: a #GstPadProbeInfo
5520 * Returns: (transfer none): The #GstBufferlist from the probe
5524 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5526 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5528 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);