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 /* Mark pad as needing reconfiguration */
1077 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1078 pre_activate (pad, new);
1080 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1081 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1085 /* can happen for sinks of passthrough elements */
1088 post_activate (pad, new);
1090 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1091 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1096 /* Clear sticky flags on deactivation */
1098 GST_OBJECT_LOCK (pad);
1099 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1100 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1101 GST_OBJECT_UNLOCK (pad);
1105 RELEASE_PARENT (parent);
1111 GST_DEBUG_OBJECT (pad, "no parent");
1112 GST_OBJECT_UNLOCK (pad);
1117 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1118 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1123 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1124 "failed to %s in switch to %s mode from %s mode",
1125 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1126 gst_pad_mode_get_name (old));
1131 GST_OBJECT_LOCK (peer);
1132 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1133 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1134 GST_OBJECT_UNLOCK (peer);
1135 gst_object_unref (peer);
1140 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1141 "pad in pull mode");
1146 GST_OBJECT_LOCK (pad);
1147 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1148 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1149 GST_PAD_SET_FLUSHING (pad);
1150 GST_PAD_MODE (pad) = old;
1151 GST_OBJECT_UNLOCK (pad);
1157 * gst_pad_is_active:
1158 * @pad: the #GstPad to query
1160 * Query if a pad is active
1162 * Returns: TRUE if the pad is active.
1167 gst_pad_is_active (GstPad * pad)
1169 gboolean result = FALSE;
1171 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1173 GST_OBJECT_LOCK (pad);
1174 result = GST_PAD_IS_ACTIVE (pad);
1175 GST_OBJECT_UNLOCK (pad);
1181 * gst_pad_add_probe:
1182 * @pad: the #GstPad to add the probe to
1183 * @mask: the probe mask
1184 * @callback: #GstPadProbeCallback that will be called with notifications of
1186 * @user_data: (closure): user data passed to the callback
1187 * @destroy_data: #GDestroyNotify for user_data
1189 * Be notified of different states of pads. The provided callback is called for
1190 * every state that matches @mask.
1192 * Returns: an id or 0 on error. The id can be used to remove the probe with
1193 * gst_pad_remove_probe().
1198 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1199 GstPadProbeCallback callback, gpointer user_data,
1200 GDestroyNotify destroy_data)
1205 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1206 g_return_val_if_fail (mask != 0, 0);
1208 GST_OBJECT_LOCK (pad);
1210 /* make a new probe */
1211 hook = g_hook_alloc (&pad->probes);
1213 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1216 /* when no contraints are given for the types, assume all types are
1218 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1219 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1220 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1221 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1223 /* store our flags and other fields */
1224 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1225 hook->func = callback;
1226 hook->data = user_data;
1227 hook->destroy = destroy_data;
1228 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1231 g_hook_prepend (&pad->probes, hook);
1233 /* incremenent cookie so that the new hook get's called */
1234 pad->priv->probe_list_cookie++;
1236 /* get the id of the hook, we return this and it can be used to remove the
1238 res = hook->hook_id;
1240 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1242 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1243 /* we have a block probe */
1245 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1246 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1247 "now %d blocking probes", pad->num_blocked);
1250 /* call the callback if we need to be called for idle callbacks */
1251 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1252 if (pad->priv->using > 0) {
1253 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1254 * flag above, the last thread to leave the push will do the callback. New
1255 * threads going into the push will block. */
1256 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1257 "pad is in use, delay idle callback");
1258 GST_OBJECT_UNLOCK (pad);
1260 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1262 /* the pad is idle now, we can signal the idle callback now */
1263 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1264 "pad is idle, trigger idle callback");
1265 GST_OBJECT_UNLOCK (pad);
1267 callback (pad, &info, user_data);
1270 GST_OBJECT_UNLOCK (pad);
1276 cleanup_hook (GstPad * pad, GHook * hook)
1278 GstPadProbeType type;
1280 if (!G_HOOK_IS_VALID (hook))
1283 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1285 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1286 /* unblock when we remove the last blocking probe */
1288 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1290 if (pad->num_blocked == 0) {
1291 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1292 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1293 GST_PAD_BLOCK_BROADCAST (pad);
1296 g_hook_destroy_link (&pad->probes, hook);
1301 * gst_pad_remove_probe:
1302 * @pad: the #GstPad with the probe
1303 * @id: the probe id to remove
1305 * Remove the probe with @id from @pad.
1310 gst_pad_remove_probe (GstPad * pad, gulong id)
1314 g_return_if_fail (GST_IS_PAD (pad));
1316 GST_OBJECT_LOCK (pad);
1318 hook = g_hook_get (&pad->probes, id);
1322 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1324 cleanup_hook (pad, hook);
1325 GST_OBJECT_UNLOCK (pad);
1331 GST_OBJECT_UNLOCK (pad);
1332 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1338 * gst_pad_is_blocked:
1339 * @pad: the #GstPad to query
1341 * Checks if the pad is blocked or not. This function returns the
1342 * last requested state of the pad. It is not certain that the pad
1343 * is actually blocking at this point (see gst_pad_is_blocking()).
1345 * Returns: TRUE if the pad is blocked.
1350 gst_pad_is_blocked (GstPad * pad)
1352 gboolean result = FALSE;
1354 g_return_val_if_fail (GST_IS_PAD (pad), result);
1356 GST_OBJECT_LOCK (pad);
1357 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1358 GST_OBJECT_UNLOCK (pad);
1364 * gst_pad_is_blocking:
1365 * @pad: the #GstPad to query
1367 * Checks if the pad is blocking or not. This is a guaranteed state
1368 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1370 * Returns: TRUE if the pad is blocking.
1375 gst_pad_is_blocking (GstPad * pad)
1377 gboolean result = FALSE;
1379 g_return_val_if_fail (GST_IS_PAD (pad), result);
1381 GST_OBJECT_LOCK (pad);
1382 /* the blocking flag is only valid if the pad is not flushing */
1383 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1384 GST_OBJECT_UNLOCK (pad);
1390 * gst_pad_needs_reconfigure:
1391 * @pad: the #GstPad to check
1393 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1394 * if the flag was set.
1396 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1399 gst_pad_needs_reconfigure (GstPad * pad)
1401 gboolean reconfigure;
1403 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1405 GST_OBJECT_LOCK (pad);
1406 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1407 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1408 GST_OBJECT_UNLOCK (pad);
1414 * gst_pad_check_reconfigure:
1415 * @pad: the #GstPad to check
1417 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1418 * if the flag was set.
1420 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1423 gst_pad_check_reconfigure (GstPad * pad)
1425 gboolean reconfigure;
1427 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1429 GST_OBJECT_LOCK (pad);
1430 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1432 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1433 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1435 GST_OBJECT_UNLOCK (pad);
1441 * gst_pad_mark_reconfigure:
1442 * @pad: the #GstPad to mark
1444 * Mark a pad for needing reconfiguration. The next call to
1445 * gst_pad_check_reconfigure() will return %TRUE after this call.
1448 gst_pad_mark_reconfigure (GstPad * pad)
1450 g_return_if_fail (GST_IS_PAD (pad));
1452 GST_OBJECT_LOCK (pad);
1453 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1454 GST_OBJECT_UNLOCK (pad);
1458 * gst_pad_set_activate_function:
1460 * @f: the #GstPadActivateFunction to set.
1462 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1466 * gst_pad_set_activate_function_full:
1468 * @activate: the #GstPadActivateFunction to set.
1469 * @user_data: user_data passed to @notify
1470 * @notify: notify called when @activate will not be used anymore.
1472 * Sets the given activate function for @pad. The activate function will
1473 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1474 * Only makes sense to set on sink pads.
1476 * Call this function if your sink pad can start a pull-based task.
1479 gst_pad_set_activate_function_full (GstPad * pad,
1480 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1482 g_return_if_fail (GST_IS_PAD (pad));
1484 if (pad->activatenotify)
1485 pad->activatenotify (pad->activatedata);
1486 GST_PAD_ACTIVATEFUNC (pad) = activate;
1487 pad->activatedata = user_data;
1488 pad->activatenotify = notify;
1490 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1491 GST_DEBUG_FUNCPTR_NAME (activate));
1495 * gst_pad_set_activatemode_function:
1497 * @f: the #GstPadActivateModeFunction to set.
1499 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1503 * gst_pad_set_activatemode_function_full:
1505 * @activatemode: the #GstPadActivateModeFunction to set.
1506 * @user_data: user_data passed to @notify
1507 * @notify: notify called when @activatemode will not be used anymore.
1509 * Sets the given activate_mode function for the pad. An activate_mode function
1510 * prepares the element for data passing.
1513 gst_pad_set_activatemode_function_full (GstPad * pad,
1514 GstPadActivateModeFunction activatemode, gpointer user_data,
1515 GDestroyNotify notify)
1517 g_return_if_fail (GST_IS_PAD (pad));
1519 if (pad->activatemodenotify)
1520 pad->activatemodenotify (pad->activatemodedata);
1521 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1522 pad->activatemodedata = user_data;
1523 pad->activatemodenotify = notify;
1525 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1526 GST_DEBUG_FUNCPTR_NAME (activatemode));
1530 * gst_pad_set_chain_function:
1531 * @p: a sink #GstPad.
1532 * @f: the #GstPadChainFunction to set.
1534 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1538 * gst_pad_set_chain_function_full:
1539 * @pad: a sink #GstPad.
1540 * @chain: the #GstPadChainFunction to set.
1541 * @user_data: user_data passed to @notify
1542 * @notify: notify called when @chain will not be used anymore.
1544 * Sets the given chain function for the pad. The chain function is called to
1545 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1548 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1549 gpointer user_data, GDestroyNotify notify)
1551 g_return_if_fail (GST_IS_PAD (pad));
1552 g_return_if_fail (GST_PAD_IS_SINK (pad));
1554 if (pad->chainnotify)
1555 pad->chainnotify (pad->chaindata);
1556 GST_PAD_CHAINFUNC (pad) = chain;
1557 pad->chaindata = user_data;
1558 pad->chainnotify = notify;
1560 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1561 GST_DEBUG_FUNCPTR_NAME (chain));
1565 * gst_pad_set_chain_list_function:
1566 * @p: a sink #GstPad.
1567 * @f: the #GstPadChainListFunction to set.
1569 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1573 * gst_pad_set_chain_list_function_full:
1574 * @pad: a sink #GstPad.
1575 * @chainlist: the #GstPadChainListFunction to set.
1576 * @user_data: user_data passed to @notify
1577 * @notify: notify called when @chainlist will not be used anymore.
1579 * Sets the given chain list function for the pad. The chainlist function is
1580 * called to process a #GstBufferList input buffer list. See
1581 * #GstPadChainListFunction for more details.
1584 gst_pad_set_chain_list_function_full (GstPad * pad,
1585 GstPadChainListFunction chainlist, gpointer user_data,
1586 GDestroyNotify notify)
1588 g_return_if_fail (GST_IS_PAD (pad));
1589 g_return_if_fail (GST_PAD_IS_SINK (pad));
1591 if (pad->chainlistnotify)
1592 pad->chainlistnotify (pad->chainlistdata);
1593 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1594 pad->chainlistdata = user_data;
1595 pad->chainlistnotify = notify;
1597 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1598 GST_DEBUG_FUNCPTR_NAME (chainlist));
1602 * gst_pad_set_getrange_function:
1603 * @p: a source #GstPad.
1604 * @f: the #GstPadGetRangeFunction to set.
1606 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1610 * gst_pad_set_getrange_function_full:
1611 * @pad: a source #GstPad.
1612 * @get: the #GstPadGetRangeFunction to set.
1613 * @user_data: user_data passed to @notify
1614 * @notify: notify called when @get will not be used anymore.
1616 * Sets the given getrange function for the pad. The getrange function is
1617 * called to produce a new #GstBuffer to start the processing pipeline. see
1618 * #GstPadGetRangeFunction for a description of the getrange function.
1621 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1622 gpointer user_data, GDestroyNotify notify)
1624 g_return_if_fail (GST_IS_PAD (pad));
1625 g_return_if_fail (GST_PAD_IS_SRC (pad));
1627 if (pad->getrangenotify)
1628 pad->getrangenotify (pad->getrangedata);
1629 GST_PAD_GETRANGEFUNC (pad) = get;
1630 pad->getrangedata = user_data;
1631 pad->getrangenotify = notify;
1633 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1634 GST_DEBUG_FUNCPTR_NAME (get));
1638 * gst_pad_set_event_function:
1639 * @p: a #GstPad of either direction.
1640 * @f: the #GstPadEventFunction to set.
1642 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1646 * gst_pad_set_event_function_full:
1647 * @pad: a #GstPad of either direction.
1648 * @event: the #GstPadEventFunction to set.
1649 * @user_data: user_data passed to @notify
1650 * @notify: notify called when @event will not be used anymore.
1652 * Sets the given event handler for the pad.
1655 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1656 gpointer user_data, GDestroyNotify notify)
1658 g_return_if_fail (GST_IS_PAD (pad));
1660 if (pad->eventnotify)
1661 pad->eventnotify (pad->eventdata);
1662 GST_PAD_EVENTFUNC (pad) = event;
1663 pad->eventdata = user_data;
1664 pad->eventnotify = notify;
1666 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1667 GST_DEBUG_FUNCPTR_NAME (event));
1671 * gst_pad_set_query_function:
1672 * @p: a #GstPad of either direction.
1673 * @f: the #GstPadQueryFunction to set.
1675 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1679 * gst_pad_set_query_function_full:
1680 * @pad: a #GstPad of either direction.
1681 * @query: the #GstPadQueryFunction to set.
1682 * @user_data: user_data passed to @notify
1683 * @notify: notify called when @query will not be used anymore.
1685 * Set the given query function for the pad.
1688 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1689 gpointer user_data, GDestroyNotify notify)
1691 g_return_if_fail (GST_IS_PAD (pad));
1693 if (pad->querynotify)
1694 pad->querynotify (pad->querydata);
1695 GST_PAD_QUERYFUNC (pad) = query;
1696 pad->querydata = user_data;
1697 pad->querynotify = notify;
1699 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1700 GST_DEBUG_FUNCPTR_NAME (query));
1704 * gst_pad_set_iterate_internal_links_function:
1705 * @p: a #GstPad of either direction.
1706 * @f: the #GstPadIterIntLinkFunction to set.
1708 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1709 * for the user_data and notify.
1712 * gst_pad_set_iterate_internal_links_function_full:
1713 * @pad: a #GstPad of either direction.
1714 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1715 * @user_data: user_data passed to @notify
1716 * @notify: notify called when @iterintlink will not be used anymore.
1718 * Sets the given internal link iterator function for the pad.
1721 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1722 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1723 GDestroyNotify notify)
1725 g_return_if_fail (GST_IS_PAD (pad));
1727 if (pad->iterintlinknotify)
1728 pad->iterintlinknotify (pad->iterintlinkdata);
1729 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1730 pad->iterintlinkdata = user_data;
1731 pad->iterintlinknotify = notify;
1733 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1734 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1738 * gst_pad_set_link_function:
1740 * @f: the #GstPadLinkFunction to set.
1742 * Calls gst_pad_set_link_function_full() with NULL
1743 * for the user_data and notify.
1746 * gst_pad_set_link_function_full:
1748 * @link: the #GstPadLinkFunction to set.
1749 * @user_data: user_data passed to @notify
1750 * @notify: notify called when @link will not be used anymore.
1752 * Sets the given link function for the pad. It will be called when
1753 * the pad is linked with another pad.
1755 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1758 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1759 * cannot be made for some reason.
1761 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1762 * of the peer sink pad, if present.
1765 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1766 gpointer user_data, GDestroyNotify notify)
1768 g_return_if_fail (GST_IS_PAD (pad));
1770 if (pad->linknotify)
1771 pad->linknotify (pad->linkdata);
1772 GST_PAD_LINKFUNC (pad) = link;
1773 pad->linkdata = user_data;
1774 pad->linknotify = notify;
1776 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1777 GST_DEBUG_FUNCPTR_NAME (link));
1781 * gst_pad_set_unlink_function:
1783 * @f: the #GstPadUnlinkFunction to set.
1785 * Calls gst_pad_set_unlink_function_full() with NULL
1786 * for the user_data and notify.
1789 * gst_pad_set_unlink_function_full:
1791 * @unlink: the #GstPadUnlinkFunction to set.
1792 * @user_data: user_data passed to @notify
1793 * @notify: notify called when @unlink will not be used anymore.
1795 * Sets the given unlink function for the pad. It will be called
1796 * when the pad is unlinked.
1799 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1800 gpointer user_data, GDestroyNotify notify)
1802 g_return_if_fail (GST_IS_PAD (pad));
1804 if (pad->unlinknotify)
1805 pad->unlinknotify (pad->unlinkdata);
1806 GST_PAD_UNLINKFUNC (pad) = unlink;
1807 pad->unlinkdata = user_data;
1808 pad->unlinknotify = notify;
1810 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1811 GST_DEBUG_FUNCPTR_NAME (unlink));
1816 * @srcpad: the source #GstPad to unlink.
1817 * @sinkpad: the sink #GstPad to unlink.
1819 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1820 * signal on both pads.
1822 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1823 * the pads were not linked together.
1828 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1830 gboolean result = FALSE;
1831 GstElement *parent = NULL;
1833 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1834 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1835 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1836 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1838 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1839 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1840 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1842 /* We need to notify the parent before taking any pad locks as the bin in
1843 * question might be waiting for a lock on the pad while holding its lock
1844 * that our message will try to take. */
1845 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1846 if (GST_IS_ELEMENT (parent)) {
1847 gst_element_post_message (parent,
1848 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1849 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1851 gst_object_unref (parent);
1856 GST_OBJECT_LOCK (srcpad);
1857 GST_OBJECT_LOCK (sinkpad);
1859 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1860 goto not_linked_together;
1862 if (GST_PAD_UNLINKFUNC (srcpad)) {
1863 GstObject *tmpparent;
1865 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1867 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1868 RELEASE_PARENT (tmpparent);
1871 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1872 GstObject *tmpparent;
1874 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1876 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1877 RELEASE_PARENT (tmpparent);
1881 /* first clear peers */
1882 GST_PAD_PEER (srcpad) = NULL;
1883 GST_PAD_PEER (sinkpad) = NULL;
1885 GST_OBJECT_UNLOCK (sinkpad);
1886 GST_OBJECT_UNLOCK (srcpad);
1888 /* fire off a signal to each of the pads telling them
1889 * that they've been unlinked */
1890 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1891 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1893 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1894 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1899 if (parent != NULL) {
1900 gst_element_post_message (parent,
1901 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1902 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1903 gst_object_unref (parent);
1908 not_linked_together:
1910 /* we do not emit a warning in this case because unlinking cannot
1911 * be made MT safe.*/
1912 GST_OBJECT_UNLOCK (sinkpad);
1913 GST_OBJECT_UNLOCK (srcpad);
1919 * gst_pad_is_linked:
1920 * @pad: pad to check
1922 * Checks if a @pad is linked to another pad or not.
1924 * Returns: TRUE if the pad is linked, FALSE otherwise.
1929 gst_pad_is_linked (GstPad * pad)
1933 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1935 GST_OBJECT_LOCK (pad);
1936 result = (GST_PAD_PEER (pad) != NULL);
1937 GST_OBJECT_UNLOCK (pad);
1942 /* get the caps from both pads and see if the intersection
1945 * This function should be called with the pad LOCK on both
1949 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1950 GstPadLinkCheck flags)
1952 GstCaps *srccaps = NULL;
1953 GstCaps *sinkcaps = NULL;
1954 gboolean compatible = FALSE;
1956 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1959 /* Doing the expensive caps checking takes priority over only checking the template caps */
1960 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1961 GST_OBJECT_UNLOCK (sink);
1962 GST_OBJECT_UNLOCK (src);
1964 srccaps = gst_pad_query_caps (src, NULL);
1965 sinkcaps = gst_pad_query_caps (sink, NULL);
1967 GST_OBJECT_LOCK (src);
1968 GST_OBJECT_LOCK (sink);
1970 /* If one of the two pads doesn't have a template, consider the intersection
1972 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1973 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1977 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1979 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1982 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1984 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1987 /* if we have caps on both pads we can check the intersection. If one
1988 * of the caps is NULL, we return TRUE. */
1989 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1991 gst_caps_unref (srccaps);
1993 gst_caps_unref (sinkcaps);
1997 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1998 gst_caps_unref (srccaps);
1999 gst_caps_unref (sinkcaps);
2002 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2003 (compatible ? "" : "not"));
2008 /* check if the grandparents of both pads are the same.
2009 * This check is required so that we don't try to link
2010 * pads from elements in different bins without ghostpads.
2012 * The LOCK should be held on both pads
2015 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2017 GstObject *psrc, *psink;
2019 psrc = GST_OBJECT_PARENT (src);
2020 psink = GST_OBJECT_PARENT (sink);
2022 /* if one of the pads has no parent, we allow the link */
2023 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2026 /* only care about parents that are elements */
2027 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2028 goto no_element_parent;
2030 /* if the parents are the same, we have a loop */
2031 if (G_UNLIKELY (psrc == psink))
2034 /* if they both have a parent, we check the grandparents. We can not lock
2035 * the parent because we hold on the child (pad) and the locking order is
2036 * parent >> child. */
2037 psrc = GST_OBJECT_PARENT (psrc);
2038 psink = GST_OBJECT_PARENT (psink);
2040 /* if they have grandparents but they are not the same */
2041 if (G_UNLIKELY (psrc != psink))
2042 goto wrong_grandparents;
2049 GST_CAT_DEBUG (GST_CAT_CAPS,
2050 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2051 GST_PTR_FORMAT, psrc, psink);
2056 GST_CAT_DEBUG (GST_CAT_CAPS,
2057 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2058 GST_PTR_FORMAT, psrc, psink);
2063 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2069 GST_CAT_DEBUG (GST_CAT_CAPS,
2070 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2071 GST_PTR_FORMAT, psrc, psink);
2076 /* FIXME leftover from an attempt at refactoring... */
2077 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2078 * the two pads will be locked in the srcpad, sinkpad order. */
2079 static GstPadLinkReturn
2080 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2082 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2083 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2085 GST_OBJECT_LOCK (srcpad);
2087 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2088 goto src_was_linked;
2090 GST_OBJECT_LOCK (sinkpad);
2092 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2093 goto sink_was_linked;
2095 /* check hierarchy, pads can only be linked if the grandparents
2097 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2098 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2099 goto wrong_hierarchy;
2101 /* check pad caps for non-empty intersection */
2102 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2105 /* FIXME check pad scheduling for non-empty intersection */
2107 return GST_PAD_LINK_OK;
2111 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2112 GST_DEBUG_PAD_NAME (srcpad),
2113 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2114 /* we do not emit a warning in this case because unlinking cannot
2115 * be made MT safe.*/
2116 GST_OBJECT_UNLOCK (srcpad);
2117 return GST_PAD_LINK_WAS_LINKED;
2121 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2122 GST_DEBUG_PAD_NAME (sinkpad),
2123 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2124 /* we do not emit a warning in this case because unlinking cannot
2125 * be made MT safe.*/
2126 GST_OBJECT_UNLOCK (sinkpad);
2127 GST_OBJECT_UNLOCK (srcpad);
2128 return GST_PAD_LINK_WAS_LINKED;
2132 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2133 GST_OBJECT_UNLOCK (sinkpad);
2134 GST_OBJECT_UNLOCK (srcpad);
2135 return GST_PAD_LINK_WRONG_HIERARCHY;
2139 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2140 GST_OBJECT_UNLOCK (sinkpad);
2141 GST_OBJECT_UNLOCK (srcpad);
2142 return GST_PAD_LINK_NOFORMAT;
2148 * @srcpad: the source #GstPad.
2149 * @sinkpad: the sink #GstPad.
2151 * Checks if the source pad and the sink pad are compatible so they can be
2154 * Returns: TRUE if the pads can be linked.
2157 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2159 GstPadLinkReturn result;
2161 /* generic checks */
2162 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2163 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2165 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2166 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2168 /* gst_pad_link_prepare does everything for us, we only release the locks
2169 * on the pads that it gets us. If this function returns !OK the locks are not
2171 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2172 if (result != GST_PAD_LINK_OK)
2175 GST_OBJECT_UNLOCK (srcpad);
2176 GST_OBJECT_UNLOCK (sinkpad);
2179 return result == GST_PAD_LINK_OK;
2183 * gst_pad_link_full:
2184 * @srcpad: the source #GstPad to link.
2185 * @sinkpad: the sink #GstPad to link.
2186 * @flags: the checks to validate when linking
2188 * Links the source pad and the sink pad.
2190 * This variant of #gst_pad_link provides a more granular control on the
2191 * checks being done when linking. While providing some considerable speedups
2192 * the caller of this method must be aware that wrong usage of those flags
2193 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2194 * for more information.
2198 * Returns: A result code indicating if the connection worked or
2202 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2204 GstPadLinkReturn result;
2206 GstPadLinkFunction srcfunc, sinkfunc;
2208 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2209 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2210 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2211 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2212 GST_PAD_LINK_WRONG_DIRECTION);
2214 /* Notify the parent early. See gst_pad_unlink for details. */
2215 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2216 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2217 gst_element_post_message (parent,
2218 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2219 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2221 gst_object_unref (parent);
2226 /* prepare will also lock the two pads */
2227 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2229 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2232 /* must set peers before calling the link function */
2233 GST_PAD_PEER (srcpad) = sinkpad;
2234 GST_PAD_PEER (sinkpad) = srcpad;
2236 /* check events, when something is different, mark pending */
2237 schedule_events (srcpad, sinkpad);
2239 /* get the link functions */
2240 srcfunc = GST_PAD_LINKFUNC (srcpad);
2241 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2243 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2244 /* custom link functions, execute them */
2245 GST_OBJECT_UNLOCK (sinkpad);
2246 GST_OBJECT_UNLOCK (srcpad);
2249 GstObject *tmpparent;
2251 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2252 /* this one will call the peer link function */
2253 result = srcfunc (srcpad, tmpparent, sinkpad);
2254 RELEASE_PARENT (tmpparent);
2255 } else if (sinkfunc) {
2256 GstObject *tmpparent;
2258 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2259 /* if no source link function, we need to call the sink link
2260 * function ourselves. */
2261 result = sinkfunc (sinkpad, tmpparent, srcpad);
2262 RELEASE_PARENT (tmpparent);
2266 GST_OBJECT_LOCK (srcpad);
2267 GST_OBJECT_LOCK (sinkpad);
2269 /* we released the lock, check if the same pads are linked still */
2270 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2271 goto concurrent_link;
2273 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2276 GST_OBJECT_UNLOCK (sinkpad);
2277 GST_OBJECT_UNLOCK (srcpad);
2279 /* fire off a signal to each of the pads telling them
2280 * that they've been linked */
2281 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2282 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2284 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2285 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2287 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2290 if (G_LIKELY (parent)) {
2291 gst_element_post_message (parent,
2292 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2293 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2294 gst_object_unref (parent);
2302 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2303 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2304 GST_OBJECT_UNLOCK (sinkpad);
2305 GST_OBJECT_UNLOCK (srcpad);
2307 /* The other link operation succeeded first */
2308 result = GST_PAD_LINK_WAS_LINKED;
2313 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2314 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2316 GST_PAD_PEER (srcpad) = NULL;
2317 GST_PAD_PEER (sinkpad) = NULL;
2319 GST_OBJECT_UNLOCK (sinkpad);
2320 GST_OBJECT_UNLOCK (srcpad);
2328 * @srcpad: the source #GstPad to link.
2329 * @sinkpad: the sink #GstPad to link.
2331 * Links the source pad and the sink pad.
2333 * Returns: A result code indicating if the connection worked or
2339 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2341 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2345 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2347 GstPadTemplate **template_p;
2349 /* this function would need checks if it weren't static */
2351 GST_OBJECT_LOCK (pad);
2352 template_p = &pad->padtemplate;
2353 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2354 GST_OBJECT_UNLOCK (pad);
2357 gst_pad_template_pad_created (templ, pad);
2361 * gst_pad_get_pad_template:
2364 * Gets the template for @pad.
2366 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2367 * instantiated, or %NULL if this pad has no template. Unref after
2371 gst_pad_get_pad_template (GstPad * pad)
2373 GstPadTemplate *templ;
2375 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2377 templ = GST_PAD_PAD_TEMPLATE (pad);
2379 return (templ ? gst_object_ref (templ) : NULL);
2383 * gst_pad_has_current_caps:
2384 * @pad: a #GstPad to check
2386 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2388 * Returns: TRUE when @pad has caps associated with it.
2391 gst_pad_has_current_caps (GstPad * pad)
2396 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2398 GST_OBJECT_LOCK (pad);
2399 caps = get_pad_caps (pad);
2400 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2401 "check current pad caps %" GST_PTR_FORMAT, caps);
2402 result = (caps != NULL);
2403 GST_OBJECT_UNLOCK (pad);
2409 * gst_pad_get_current_caps:
2410 * @pad: a #GstPad to get the current capabilities of.
2412 * Gets the capabilities currently configured on @pad with the last
2413 * #GST_EVENT_CAPS event.
2415 * Returns: the current caps of the pad with incremented ref-count.
2418 gst_pad_get_current_caps (GstPad * pad)
2422 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2424 GST_OBJECT_LOCK (pad);
2425 if ((result = get_pad_caps (pad)))
2426 gst_caps_ref (result);
2427 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2428 "get current pad caps %" GST_PTR_FORMAT, result);
2429 GST_OBJECT_UNLOCK (pad);
2435 * gst_pad_get_pad_template_caps:
2436 * @pad: a #GstPad to get the template capabilities from.
2438 * Gets the capabilities for @pad's template.
2440 * Returns: (transfer full): the #GstCaps of this pad template.
2441 * Unref after usage.
2444 gst_pad_get_pad_template_caps (GstPad * pad)
2446 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2448 if (GST_PAD_PAD_TEMPLATE (pad))
2449 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2451 return gst_caps_ref (GST_CAPS_ANY);
2456 * @pad: a #GstPad to get the peer of.
2458 * Gets the peer of @pad. This function refs the peer pad so
2459 * you need to unref it after use.
2461 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2466 gst_pad_get_peer (GstPad * pad)
2470 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2472 GST_OBJECT_LOCK (pad);
2473 result = GST_PAD_PEER (pad);
2475 gst_object_ref (result);
2476 GST_OBJECT_UNLOCK (pad);
2482 * gst_pad_get_allowed_caps:
2485 * Gets the capabilities of the allowed media types that can flow through
2486 * @pad and its peer.
2488 * The allowed capabilities is calculated as the intersection of the results of
2489 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2490 * on the resulting caps.
2492 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2493 * caps when you no longer need it. This function returns NULL when @pad
2499 gst_pad_get_allowed_caps (GstPad * pad)
2505 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2507 GST_OBJECT_LOCK (pad);
2508 peer = GST_PAD_PEER (pad);
2509 if (G_UNLIKELY (peer == NULL))
2512 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2514 gst_object_ref (peer);
2515 GST_OBJECT_UNLOCK (pad);
2516 mycaps = gst_pad_query_caps (pad, NULL);
2518 caps = gst_pad_query_caps (peer, mycaps);
2519 gst_object_unref (peer);
2521 gst_caps_unref (mycaps);
2523 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2530 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2531 GST_OBJECT_UNLOCK (pad);
2538 * gst_pad_iterate_internal_links_default:
2539 * @pad: the #GstPad to get the internal links of.
2540 * @parent: (allow-none): the parent of @pad or NULL
2542 * Iterate the list of pads to which the given pad is linked to inside of
2543 * the parent element.
2544 * This is the default handler, and thus returns an iterator of all of the
2545 * pads inside the parent element with opposite direction.
2547 * The caller must free this iterator after use with gst_iterator_free().
2549 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2550 * returned pad with gst_object_unref().
2553 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2560 GstElement *eparent;
2562 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2564 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2565 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2567 GST_OBJECT_LOCK (pad);
2568 eparent = GST_PAD_PARENT (pad);
2569 if (!eparent || !GST_IS_ELEMENT (eparent))
2572 gst_object_ref (eparent);
2573 GST_OBJECT_UNLOCK (pad);
2576 if (pad->direction == GST_PAD_SRC)
2577 padlist = &eparent->sinkpads;
2579 padlist = &eparent->srcpads;
2581 GST_DEBUG_OBJECT (pad, "Making iterator");
2583 cookie = &eparent->pads_cookie;
2585 lock = GST_OBJECT_GET_LOCK (eparent);
2587 res = gst_iterator_new_list (GST_TYPE_PAD,
2588 lock, cookie, padlist, (GObject *) owner, NULL);
2590 gst_object_unref (owner);
2597 GST_OBJECT_UNLOCK (pad);
2598 GST_DEBUG_OBJECT (pad, "no parent element");
2604 * gst_pad_iterate_internal_links:
2605 * @pad: the GstPad to get the internal links of.
2607 * Gets an iterator for the pads to which the given pad is linked to inside
2608 * of the parent element.
2610 * Each #GstPad element yielded by the iterator will have its refcount increased,
2611 * so unref after use.
2613 * Free-function: gst_iterator_free
2615 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2616 * pad does not have an iterator function configured. Use
2617 * gst_iterator_free() after usage.
2620 gst_pad_iterate_internal_links (GstPad * pad)
2622 GstIterator *res = NULL;
2625 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2627 GST_OBJECT_LOCK (pad);
2628 ACQUIRE_PARENT (pad, parent, no_parent);
2629 GST_OBJECT_UNLOCK (pad);
2631 if (GST_PAD_ITERINTLINKFUNC (pad))
2632 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2634 RELEASE_PARENT (parent);
2641 GST_DEBUG_OBJECT (pad, "no parent");
2642 GST_OBJECT_UNLOCK (pad);
2650 * @forward: (scope call): a #GstPadForwardFunction
2651 * @user_data: user data passed to @forward
2653 * Calls @forward for all internally linked pads of @pad. This function deals with
2654 * dynamically changing internal pads and will make sure that the @forward
2655 * function is only called once for each pad.
2657 * When @forward returns TRUE, no further pads will be processed.
2659 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2662 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2665 gboolean result = FALSE;
2667 gboolean done = FALSE;
2668 GValue item = { 0, };
2669 GList *pushed_pads = NULL;
2671 iter = gst_pad_iterate_internal_links (pad);
2677 switch (gst_iterator_next (iter, &item)) {
2678 case GST_ITERATOR_OK:
2682 intpad = g_value_get_object (&item);
2684 /* if already pushed, skip. FIXME, find something faster to tag pads */
2685 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2686 g_value_reset (&item);
2690 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2691 GST_DEBUG_PAD_NAME (intpad));
2692 done = result = forward (intpad, user_data);
2694 pushed_pads = g_list_prepend (pushed_pads, intpad);
2696 g_value_reset (&item);
2699 case GST_ITERATOR_RESYNC:
2700 /* We don't reset the result here because we don't push the event
2701 * again on pads that got the event already and because we need
2702 * to consider the result of the previous pushes */
2703 gst_iterator_resync (iter);
2705 case GST_ITERATOR_ERROR:
2706 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2709 case GST_ITERATOR_DONE:
2714 g_value_unset (&item);
2715 gst_iterator_free (iter);
2717 g_list_free (pushed_pads);
2727 gboolean dispatched;
2731 event_forward_func (GstPad * pad, EventData * data)
2733 /* for each pad we send to, we should ref the event; it's up
2734 * to downstream to unref again when handled. */
2735 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2736 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2738 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2740 data->dispatched = TRUE;
2747 * gst_pad_event_default:
2748 * @pad: a #GstPad to call the default event handler on.
2749 * @parent: (allow-none): the parent of @pad or NULL
2750 * @event: (transfer full): the #GstEvent to handle.
2752 * Invokes the default event handler for the given pad.
2754 * The EOS event will pause the task associated with @pad before it is forwarded
2755 * to all internally linked pads,
2757 * The the event is sent to all pads internally linked to @pad. This function
2758 * takes ownership of @event.
2760 * Returns: TRUE if the event was sent successfully.
2763 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2765 gboolean result, forward = TRUE;
2767 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2768 g_return_val_if_fail (event != NULL, FALSE);
2770 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2773 switch (GST_EVENT_TYPE (event)) {
2774 case GST_EVENT_CAPS:
2775 forward = GST_PAD_IS_PROXY_CAPS (pad);
2786 data.dispatched = FALSE;
2787 data.result = FALSE;
2789 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2791 /* for sinkpads without a parent element or without internal links, nothing
2792 * will be dispatched but we still want to return TRUE. */
2793 if (data.dispatched)
2794 result = data.result;
2799 gst_event_unref (event);
2804 /* Default accept caps implementation just checks against
2805 * the allowed caps for the pad */
2807 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2809 /* get the caps and see if it intersects to something not empty */
2810 GstCaps *caps, *allowed;
2813 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2815 /* first forward the query to internally linked pads when we are dealing with
2817 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2818 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2823 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2824 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2826 gst_query_parse_accept_caps (query, &caps);
2827 allowed = gst_pad_query_caps (pad, caps);
2830 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2831 result = gst_caps_is_subset (caps, allowed);
2832 gst_caps_unref (allowed);
2834 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2837 gst_query_set_accept_caps_result (query, result);
2843 /* Default caps implementation */
2845 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2847 GstCaps *result = NULL, *filter;
2848 GstPadTemplate *templ;
2849 gboolean fixed_caps;
2851 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2854 /* first try to proxy if we must */
2855 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2856 if ((gst_pad_proxy_query_caps (pad, query))) {
2861 gst_query_parse_caps (query, &filter);
2863 /* no proxy or it failed, do default handling */
2864 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2866 GST_OBJECT_LOCK (pad);
2868 /* fixed caps, try the negotiated caps first */
2869 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2870 if ((result = get_pad_caps (pad)))
2871 goto filter_done_unlock;
2874 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2875 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2876 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2877 goto filter_done_unlock;
2881 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2882 "non-fixed pad caps: trying pad caps");
2883 /* non fixed caps, try the negotiated caps */
2884 if ((result = get_pad_caps (pad)))
2885 goto filter_done_unlock;
2888 /* this almost never happens */
2889 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2890 result = GST_CAPS_ANY;
2893 GST_OBJECT_UNLOCK (pad);
2895 /* run the filter on the result */
2897 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2898 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2899 GST_PTR_FORMAT, result, result, filter, filter);
2900 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2901 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2904 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2905 "using caps %p %" GST_PTR_FORMAT, result, result);
2906 result = gst_caps_ref (result);
2908 gst_query_set_caps_result (query, result);
2909 gst_caps_unref (result);
2919 gboolean dispatched;
2923 query_forward_func (GstPad * pad, QueryData * data)
2925 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2926 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2928 data->result |= gst_pad_peer_query (pad, data->query);
2930 data->dispatched = TRUE;
2932 /* stop on first successful reply */
2933 return data->result;
2937 * gst_pad_query_default:
2938 * @pad: a #GstPad to call the default query handler on.
2939 * @parent: (allow-none): the parent of @pad or NULL
2940 * @query: (transfer none): the #GstQuery to handle.
2942 * Invokes the default query handler for the given pad.
2943 * The query is sent to all pads internally linked to @pad. Note that
2944 * if there are many possible sink pads that are internally linked to
2945 * @pad, only one will be sent the query.
2946 * Multi-sinkpad elements should implement custom query handlers.
2948 * Returns: TRUE if the query was performed successfully.
2951 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2953 gboolean forward, ret = FALSE;
2955 switch (GST_QUERY_TYPE (query)) {
2956 case GST_QUERY_SCHEDULING:
2957 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2959 case GST_QUERY_ALLOCATION:
2960 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2962 case GST_QUERY_ACCEPT_CAPS:
2963 ret = gst_pad_query_accept_caps_default (pad, query);
2966 case GST_QUERY_CAPS:
2967 ret = gst_pad_query_caps_default (pad, query);
2970 case GST_QUERY_POSITION:
2971 case GST_QUERY_SEEKING:
2972 case GST_QUERY_FORMATS:
2973 case GST_QUERY_LATENCY:
2974 case GST_QUERY_JITTER:
2975 case GST_QUERY_RATE:
2976 case GST_QUERY_CONVERT:
2982 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2983 query, GST_QUERY_TYPE_NAME (query));
2989 data.dispatched = FALSE;
2990 data.result = FALSE;
2992 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
2994 if (data.dispatched) {
2997 /* nothing dispatched, assume drained */
2998 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3008 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3010 GstPad *pad = data->pad;
3011 GstPadProbeInfo *info = data->info;
3012 GstPadProbeType type, flags;
3013 GstPadProbeCallback callback;
3014 GstPadProbeReturn ret;
3016 /* if we have called this callback, do nothing */
3017 if (PROBE_COOKIE (hook) == data->cookie) {
3018 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3019 "hook %lu, cookie %u already called", hook->hook_id,
3020 PROBE_COOKIE (hook));
3024 PROBE_COOKIE (hook) = data->cookie;
3026 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3029 /* one of the data types */
3030 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3032 /* one of the scheduling types */
3033 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3035 /* one of the blocking types must match */
3036 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3037 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3039 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3040 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3041 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3044 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3045 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3046 PROBE_COOKIE (hook), flags);
3048 data->marshalled = TRUE;
3050 callback = (GstPadProbeCallback) hook->func;
3051 if (callback == NULL)
3054 info->id = hook->hook_id;
3056 GST_OBJECT_UNLOCK (pad);
3058 ret = callback (pad, info, hook->data);
3060 GST_OBJECT_LOCK (pad);
3063 case GST_PAD_PROBE_REMOVE:
3064 /* remove the probe */
3065 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3066 cleanup_hook (pad, hook);
3068 case GST_PAD_PROBE_DROP:
3069 /* need to drop the data, make sure other probes don't get called
3071 GST_DEBUG_OBJECT (pad, "asked to drop item");
3072 info->type = GST_PAD_PROBE_TYPE_INVALID;
3073 data->dropped = TRUE;
3075 case GST_PAD_PROBE_PASS:
3076 /* inform the pad block to let things pass */
3077 GST_DEBUG_OBJECT (pad, "asked to pass item");
3080 case GST_PAD_PROBE_OK:
3081 GST_DEBUG_OBJECT (pad, "probe returned OK");
3084 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3091 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3092 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3093 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3098 /* a probe that does not take or return any data */
3099 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3101 if (G_UNLIKELY (pad->num_probes)) { \
3102 /* pass NULL as the data item */ \
3103 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3104 ret = do_probe_callbacks (pad, &info, defaultval); \
3105 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3110 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3112 if (G_UNLIKELY (pad->num_probes)) { \
3113 /* pass the data item */ \
3114 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3115 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3116 /* store the possibly updated data item */ \
3117 data = GST_PAD_PROBE_INFO_DATA (&info); \
3118 /* if something went wrong, exit */ \
3119 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3124 #define PROBE_PUSH(pad,mask,data,label) \
3125 PROBE_FULL(pad, mask, data, -1, -1, label);
3126 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3127 PROBE_FULL(pad, mask, data, offs, size, label);
3129 static GstFlowReturn
3130 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3131 GstFlowReturn defaultval)
3140 data.marshalled = FALSE;
3141 data.dropped = FALSE;
3142 data.cookie = ++pad->priv->probe_cookie;
3145 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3148 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3149 "do probes cookie %u", data.cookie);
3150 cookie = pad->priv->probe_list_cookie;
3152 g_hook_list_marshal (&pad->probes, TRUE,
3153 (GHookMarshaller) probe_hook_marshal, &data);
3155 /* if the list changed, call the new callbacks (they will not have their
3156 * cookie set to data.cookie */
3157 if (cookie != pad->priv->probe_list_cookie) {
3158 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3159 "probe list changed, restarting");
3163 /* the first item that dropped will stop the hooks and then we drop here */
3167 /* if no handler matched and we are blocking, let the item pass */
3168 if (!data.marshalled && is_block)
3171 /* At this point, all handlers returned either OK or PASS. If one handler
3172 * returned PASS, let the item pass */
3177 while (GST_PAD_IS_BLOCKED (pad)) {
3178 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3179 "we are blocked %d times", pad->num_blocked);
3181 /* we might have released the lock */
3182 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3185 /* now we block the streaming thread. It can be unlocked when we
3186 * deactivate the pad (which will also set the FLUSHING flag) or
3187 * when the pad is unblocked. A flushing event will also unblock
3188 * the pad after setting the FLUSHING flag. */
3189 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3190 "Waiting to be unblocked or set flushing");
3191 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3192 GST_PAD_BLOCK_WAIT (pad);
3193 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3194 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3196 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3206 GST_DEBUG_OBJECT (pad, "pad is flushing");
3207 return GST_FLOW_FLUSHING;
3211 GST_DEBUG_OBJECT (pad, "data is dropped");
3212 return GST_FLOW_CUSTOM_SUCCESS;
3216 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3217 GST_DEBUG_OBJECT (pad, "data is passed");
3225 * gst_pad_get_offset:
3228 * Get the offset applied to the running time of @pad. @pad has to be a source
3231 * Returns: the offset.
3234 gst_pad_get_offset (GstPad * pad)
3238 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3240 GST_OBJECT_LOCK (pad);
3241 result = pad->offset;
3242 GST_OBJECT_UNLOCK (pad);
3248 * gst_pad_set_offset:
3250 * @offset: the offset
3252 * Set the offset that will be applied to the running time of @pad.
3255 gst_pad_set_offset (GstPad * pad, gint64 offset)
3259 g_return_if_fail (GST_IS_PAD (pad));
3261 GST_OBJECT_LOCK (pad);
3262 /* if nothing changed, do nothing */
3263 if (pad->offset == offset)
3266 pad->offset = offset;
3267 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3269 /* sinkpads will apply their offset the next time a segment
3270 * event is received. */
3271 if (GST_PAD_IS_SINK (pad))
3274 /* resend the last segment event on next buffer push */
3275 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3276 ev->received = FALSE;
3277 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3281 GST_OBJECT_UNLOCK (pad);
3288 /* If TRUE and ret is not OK this means
3289 * that pushing the EOS event failed
3293 /* If called for an event this is
3294 * the event that would be pushed
3295 * next. Don't forward sticky events
3296 * that would come after that */
3300 /* should be called with pad LOCK */
3302 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3304 PushStickyData *data = user_data;
3305 GstEvent *event = ev->event;
3308 GST_DEBUG_OBJECT (pad, "event %s was already received",
3309 GST_EVENT_TYPE_NAME (event));
3313 /* If we're called because of an sticky event, only forward
3314 * events that would come before this new event and the
3316 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3317 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3318 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3319 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3321 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3322 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3325 switch (data->ret) {
3327 ev->received = TRUE;
3328 GST_DEBUG_OBJECT (pad, "event %s marked received",
3329 GST_EVENT_TYPE_NAME (event));
3331 case GST_FLOW_CUSTOM_SUCCESS:
3332 /* we can't assume the event is received when it was dropped */
3333 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3334 GST_EVENT_TYPE_NAME (event));
3335 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3336 data->ret = GST_FLOW_OK;
3338 case GST_FLOW_CUSTOM_SUCCESS_1:
3339 /* event was ignored and should be sent later */
3340 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3341 GST_EVENT_TYPE_NAME (event));
3342 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3343 data->ret = GST_FLOW_OK;
3345 case GST_FLOW_NOT_LINKED:
3346 /* not linked is not a problem, we are sticky so the event will be
3347 * sent later but only for non-EOS events */
3348 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3349 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3350 data->ret = GST_FLOW_OK;
3351 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3354 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3355 gst_flow_get_name (data->ret));
3356 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3360 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3361 data->was_eos = TRUE;
3363 return data->ret == GST_FLOW_OK;
3366 /* check sticky events and push them when needed. should be called
3368 static inline GstFlowReturn
3369 check_sticky (GstPad * pad, GstEvent * event)
3371 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3373 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3374 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3376 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3377 events_foreach (pad, push_sticky, &data);
3379 /* If there's an EOS event we must push it downstream
3380 * even if sending a previous sticky event failed.
3381 * Otherwise the pipeline might wait forever for EOS.
3383 * Only do this if pushing another event than the EOS
3386 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3387 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3389 if (ev && !ev->received) {
3390 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3391 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3392 /* the event could have been dropped. Because this can only
3393 * happen if the user asked for it, it's not an error */
3394 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3395 data.ret = GST_FLOW_OK;
3405 * @pad: a #GstPad to invoke the default query on.
3406 * @query: (transfer none): the #GstQuery to perform.
3408 * Dispatches a query to a pad. The query should have been allocated by the
3409 * caller via one of the type-specific allocation functions. The element that
3410 * the pad belongs to is responsible for filling the query with an appropriate
3411 * response, which should then be parsed with a type-specific query parsing
3414 * Again, the caller is responsible for both the allocation and deallocation of
3415 * the query structure.
3417 * Please also note that some queries might need a running pipeline to work.
3419 * Returns: TRUE if the query could be performed.
3422 gst_pad_query (GstPad * pad, GstQuery * query)
3425 gboolean res, serialized;
3426 GstPadQueryFunction func;
3427 GstPadProbeType type;
3430 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3431 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3433 if (GST_PAD_IS_SRC (pad)) {
3434 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3435 goto wrong_direction;
3436 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3437 } else if (GST_PAD_IS_SINK (pad)) {
3438 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3439 goto wrong_direction;
3440 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3442 goto unknown_direction;
3444 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3445 GST_QUERY_TYPE_NAME (query));
3447 serialized = GST_QUERY_IS_SERIALIZED (query);
3448 if (G_UNLIKELY (serialized))
3449 GST_PAD_STREAM_LOCK (pad);
3451 GST_OBJECT_LOCK (pad);
3452 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3453 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3454 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3456 ACQUIRE_PARENT (pad, parent, no_parent);
3457 GST_OBJECT_UNLOCK (pad);
3459 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3462 res = func (pad, parent, query);
3464 RELEASE_PARENT (parent);
3466 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3467 GST_QUERY_TYPE_NAME (query), res);
3472 GST_OBJECT_LOCK (pad);
3473 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3474 GST_OBJECT_UNLOCK (pad);
3476 if (G_UNLIKELY (serialized))
3477 GST_PAD_STREAM_UNLOCK (pad);
3484 g_warning ("pad %s:%s query %s in wrong direction",
3485 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3490 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3495 GST_DEBUG_OBJECT (pad, "had no parent");
3496 GST_OBJECT_UNLOCK (pad);
3497 if (G_UNLIKELY (serialized))
3498 GST_PAD_STREAM_UNLOCK (pad);
3503 GST_DEBUG_OBJECT (pad, "had no query function");
3504 RELEASE_PARENT (parent);
3505 if (G_UNLIKELY (serialized))
3506 GST_PAD_STREAM_UNLOCK (pad);
3511 GST_DEBUG_OBJECT (pad, "query failed");
3512 if (G_UNLIKELY (serialized))
3513 GST_PAD_STREAM_UNLOCK (pad);
3518 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3519 GST_OBJECT_UNLOCK (pad);
3520 if (G_UNLIKELY (serialized))
3521 GST_PAD_STREAM_UNLOCK (pad);
3523 /* if a probe dropped, we don't sent it further but assume that the probe
3524 * answered the query and return TRUE */
3525 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3535 * gst_pad_peer_query:
3536 * @pad: a #GstPad to invoke the peer query on.
3537 * @query: (transfer none): the #GstQuery to perform.
3539 * Performs gst_pad_query() on the peer of @pad.
3541 * The caller is responsible for both the allocation and deallocation of
3542 * the query structure.
3544 * Returns: TRUE if the query could be performed. This function returns %FALSE
3545 * if @pad has no peer.
3548 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3551 GstPadProbeType type;
3552 gboolean res, serialized;
3555 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3556 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3558 if (GST_PAD_IS_SRC (pad)) {
3559 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3560 goto wrong_direction;
3561 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3562 } else if (GST_PAD_IS_SINK (pad)) {
3563 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3564 goto wrong_direction;
3565 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3567 goto unknown_direction;
3569 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3570 GST_QUERY_TYPE_NAME (query));
3572 serialized = GST_QUERY_IS_SERIALIZED (query);
3574 GST_OBJECT_LOCK (pad);
3575 if (GST_PAD_IS_SRC (pad) && serialized) {
3576 /* all serialized queries on the srcpad trigger push of
3578 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3582 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3583 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3584 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3586 peerpad = GST_PAD_PEER (pad);
3587 if (G_UNLIKELY (peerpad == NULL))
3590 gst_object_ref (peerpad);
3591 GST_OBJECT_UNLOCK (pad);
3593 res = gst_pad_query (peerpad, query);
3595 gst_object_unref (peerpad);
3600 GST_OBJECT_LOCK (pad);
3601 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3602 GST_OBJECT_UNLOCK (pad);
3609 g_warning ("pad %s:%s query %s in wrong direction",
3610 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3615 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3620 GST_WARNING_OBJECT (pad, "could not send sticky events");
3621 GST_OBJECT_UNLOCK (pad);
3626 GST_INFO_OBJECT (pad, "pad has no peer");
3627 GST_OBJECT_UNLOCK (pad);
3632 GST_DEBUG_OBJECT (pad, "query failed");
3637 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3638 GST_OBJECT_UNLOCK (pad);
3640 /* if a probe dropped, we don't sent it further but assume that the probe
3641 * answered the query and return TRUE */
3642 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3651 /**********************************************************************
3652 * Data passing functions
3655 /* this is the chain function that does not perform the additional argument
3656 * checking for that little extra speed.
3658 static inline GstFlowReturn
3659 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3664 GST_PAD_STREAM_LOCK (pad);
3666 GST_OBJECT_LOCK (pad);
3667 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3670 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3673 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3676 #ifndef G_DISABLE_ASSERT
3677 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3679 ":%s:<%s:%s> Got data flow before stream-start event",
3680 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3682 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3684 ":%s:<%s:%s> Got data flow before segment event",
3685 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3689 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3691 PROBE_PUSH (pad, type, data, probe_stopped);
3693 parent = GST_OBJECT_PARENT (pad);
3694 GST_OBJECT_UNLOCK (pad);
3696 /* NOTE: we read the chainfunc unlocked.
3697 * we cannot hold the lock for the pad so we might send
3698 * the data to the wrong function. This is not really a
3699 * problem since functions are assigned at creation time
3700 * and don't change that often... */
3701 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3702 GstPadChainFunction chainfunc;
3704 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3707 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3708 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3709 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3711 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3713 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3714 "called chainfunction &%s with buffer %p, returned %s",
3715 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3717 GstPadChainListFunction chainlistfunc;
3719 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3722 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3723 "calling chainlistfunction &%s",
3724 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3726 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "called chainlistfunction &%s, returned %s",
3730 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3733 GST_PAD_STREAM_UNLOCK (pad);
3740 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3741 "chaining, but pad was flushing");
3742 GST_OBJECT_UNLOCK (pad);
3743 GST_PAD_STREAM_UNLOCK (pad);
3744 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3745 return GST_FLOW_FLUSHING;
3749 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3750 GST_OBJECT_UNLOCK (pad);
3751 GST_PAD_STREAM_UNLOCK (pad);
3752 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3753 return GST_FLOW_EOS;
3757 g_critical ("chain on pad %s:%s but it was not in push mode",
3758 GST_DEBUG_PAD_NAME (pad));
3759 GST_OBJECT_UNLOCK (pad);
3760 GST_PAD_STREAM_UNLOCK (pad);
3761 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3762 return GST_FLOW_ERROR;
3766 GST_OBJECT_UNLOCK (pad);
3767 GST_PAD_STREAM_UNLOCK (pad);
3768 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3771 case GST_FLOW_CUSTOM_SUCCESS:
3772 GST_DEBUG_OBJECT (pad, "dropped buffer");
3776 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3783 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3784 g_critical ("chain on pad %s:%s but it has no chainfunction",
3785 GST_DEBUG_PAD_NAME (pad));
3786 GST_PAD_STREAM_UNLOCK (pad);
3787 return GST_FLOW_NOT_SUPPORTED;
3793 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3794 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3797 * Chain a buffer to @pad.
3799 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3801 * If the buffer type is not acceptable for @pad (as negotiated with a
3802 * preceeding GST_EVENT_CAPS event), this function returns
3803 * #GST_FLOW_NOT_NEGOTIATED.
3805 * The function proceeds calling the chain function installed on @pad (see
3806 * gst_pad_set_chain_function()) and the return value of that function is
3807 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3810 * In all cases, success or failure, the caller loses its reference to @buffer
3811 * after calling this function.
3813 * Returns: a #GstFlowReturn from the pad.
3818 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3820 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3821 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3822 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3824 return gst_pad_chain_data_unchecked (pad,
3825 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3828 static GstFlowReturn
3829 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3830 GstBufferList * list)
3836 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3838 len = gst_buffer_list_length (list);
3841 for (i = 0; i < len; i++) {
3842 buffer = gst_buffer_list_get (list, i);
3844 gst_pad_chain_data_unchecked (pad,
3845 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3846 gst_buffer_ref (buffer));
3847 if (ret != GST_FLOW_OK)
3850 gst_buffer_list_unref (list);
3856 * gst_pad_chain_list:
3857 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3858 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3861 * Chain a bufferlist to @pad.
3863 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3865 * If @pad was not negotiated properly with a CAPS event, this function
3866 * returns #GST_FLOW_NOT_NEGOTIATED.
3868 * The function proceeds calling the chainlist function installed on @pad (see
3869 * gst_pad_set_chain_list_function()) and the return value of that function is
3870 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3871 * chainlist function.
3873 * In all cases, success or failure, the caller loses its reference to @list
3874 * after calling this function.
3878 * Returns: a #GstFlowReturn from the pad.
3881 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3883 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3884 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3885 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3887 return gst_pad_chain_data_unchecked (pad,
3888 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3891 static GstFlowReturn
3892 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3897 GST_OBJECT_LOCK (pad);
3898 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3901 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3904 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3907 #ifndef G_DISABLE_ASSERT
3908 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3910 ":%s:<%s:%s> Got data flow before stream-start event",
3911 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3913 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3915 ":%s:<%s:%s> Got data flow before segment event",
3916 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3920 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3923 /* do block probes */
3924 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3926 /* recheck sticky events because the probe might have cause a relink */
3927 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3930 /* do post-blocking probes */
3931 PROBE_PUSH (pad, type, data, probe_stopped);
3933 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3936 /* take ref to peer pad before releasing the lock */
3937 gst_object_ref (peer);
3939 GST_OBJECT_UNLOCK (pad);
3941 ret = gst_pad_chain_data_unchecked (peer, type, data);
3943 gst_object_unref (peer);
3945 GST_OBJECT_LOCK (pad);
3947 if (pad->priv->using == 0) {
3948 /* pad is not active anymore, trigger idle callbacks */
3949 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3950 probe_stopped, ret);
3952 GST_OBJECT_UNLOCK (pad);
3956 /* ERROR recovery here */
3960 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3961 "pushing, but pad was flushing");
3962 GST_OBJECT_UNLOCK (pad);
3963 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3964 return GST_FLOW_FLUSHING;
3968 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3969 GST_OBJECT_UNLOCK (pad);
3970 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3971 return GST_FLOW_EOS;
3975 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3976 GST_DEBUG_PAD_NAME (pad));
3977 GST_OBJECT_UNLOCK (pad);
3978 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3979 return GST_FLOW_ERROR;
3983 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3984 "error pushing events, return %s", gst_flow_get_name (ret));
3985 GST_OBJECT_UNLOCK (pad);
3986 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3991 GST_OBJECT_UNLOCK (pad);
3992 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3995 case GST_FLOW_CUSTOM_SUCCESS:
3996 GST_DEBUG_OBJECT (pad, "dropped buffer");
4000 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4007 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4008 "pushing, but it was not linked");
4009 GST_OBJECT_UNLOCK (pad);
4010 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4011 return GST_FLOW_NOT_LINKED;
4017 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4018 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4021 * Pushes a buffer to the peer of @pad.
4023 * This function will call installed block probes before triggering any
4024 * installed data probes.
4026 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4027 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4030 * In all cases, success or failure, the caller loses its reference to @buffer
4031 * after calling this function.
4033 * Returns: a #GstFlowReturn from the peer pad.
4038 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4040 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4041 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4042 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4044 return gst_pad_push_data (pad,
4045 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4049 * gst_pad_push_list:
4050 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4051 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4054 * Pushes a buffer list to the peer of @pad.
4056 * This function will call installed block probes before triggering any
4057 * installed data probes.
4059 * The function proceeds calling the chain function on the peer pad and returns
4060 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4061 * be returned. If the peer pad does not have any installed chainlist function
4062 * every group buffer of the list will be merged into a normal #GstBuffer and
4063 * chained via gst_pad_chain().
4065 * In all cases, success or failure, the caller loses its reference to @list
4066 * after calling this function.
4068 * Returns: a #GstFlowReturn from the peer pad.
4073 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4075 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4076 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4077 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4079 return gst_pad_push_data (pad,
4080 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4083 static GstFlowReturn
4084 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4085 GstBuffer ** buffer)
4088 GstPadGetRangeFunction getrangefunc;
4092 GST_PAD_STREAM_LOCK (pad);
4094 GST_OBJECT_LOCK (pad);
4095 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4098 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4101 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4106 /* when one of the probes returns DROPPED, probe_stopped will be called
4107 * and we skip calling the getrange function, res_buf should then contain a
4108 * valid result buffer */
4109 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4110 res_buf, offset, size, probe_stopped);
4112 /* recheck sticky events because the probe might have cause a relink */
4113 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4116 ACQUIRE_PARENT (pad, parent, no_parent);
4117 GST_OBJECT_UNLOCK (pad);
4119 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4122 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4123 "calling getrangefunc %s, offset %"
4124 G_GUINT64_FORMAT ", size %u",
4125 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4127 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4129 RELEASE_PARENT (parent);
4131 if (G_UNLIKELY (ret != GST_FLOW_OK))
4132 goto get_range_failed;
4134 /* can only fire the signal if we have a valid buffer */
4135 GST_OBJECT_LOCK (pad);
4137 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4138 res_buf, offset, size, probe_stopped_unref);
4139 GST_OBJECT_UNLOCK (pad);
4141 GST_PAD_STREAM_UNLOCK (pad);
4150 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4151 "getrange, but pad was flushing");
4152 GST_OBJECT_UNLOCK (pad);
4153 GST_PAD_STREAM_UNLOCK (pad);
4154 return GST_FLOW_FLUSHING;
4158 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4159 GST_DEBUG_PAD_NAME (pad));
4160 GST_OBJECT_UNLOCK (pad);
4161 GST_PAD_STREAM_UNLOCK (pad);
4162 return GST_FLOW_ERROR;
4166 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4167 GST_OBJECT_UNLOCK (pad);
4168 GST_PAD_STREAM_UNLOCK (pad);
4173 GST_DEBUG_OBJECT (pad, "no parent");
4174 GST_OBJECT_UNLOCK (pad);
4175 GST_PAD_STREAM_UNLOCK (pad);
4176 return GST_FLOW_FLUSHING;
4180 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4181 GST_DEBUG_PAD_NAME (pad));
4182 RELEASE_PARENT (parent);
4183 GST_PAD_STREAM_UNLOCK (pad);
4184 return GST_FLOW_NOT_SUPPORTED;
4188 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4189 "probe returned %s", gst_flow_get_name (ret));
4190 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4192 /* the probe filled the buffer and asks us to not call the getrange
4193 * anymore, we continue with the post probes then. */
4194 GST_DEBUG_OBJECT (pad, "handled buffer");
4198 /* no buffer, we are EOS */
4199 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4203 GST_OBJECT_UNLOCK (pad);
4204 GST_PAD_STREAM_UNLOCK (pad);
4208 probe_stopped_unref:
4210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4211 "probe returned %s", gst_flow_get_name (ret));
4212 /* if we drop here, it signals EOS */
4213 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4215 GST_OBJECT_UNLOCK (pad);
4216 GST_PAD_STREAM_UNLOCK (pad);
4217 if (*buffer == NULL)
4218 gst_buffer_unref (res_buf);
4223 GST_PAD_STREAM_UNLOCK (pad);
4224 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4225 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4226 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4232 * gst_pad_get_range:
4233 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4234 * @offset: The start offset of the buffer
4235 * @size: The length of the buffer
4236 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4237 * returns #GST_FLOW_ERROR if %NULL.
4239 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4240 * immediately and @buffer is %NULL.
4242 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4243 * description of a getrange function. If @pad has no getrange function
4244 * installed (see gst_pad_set_getrange_function()) this function returns
4245 * #GST_FLOW_NOT_SUPPORTED.
4247 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4248 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4249 * must be freed with gst_buffer_unref() after usage.
4251 * When @buffer points to a variable that points to a valid #GstBuffer, the
4252 * buffer will be filled with the result data when this function returns
4253 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4254 * @size bytes will be filled in the result buffer and its size will be updated
4257 * Note that less than @size bytes can be returned in @buffer when, for example,
4258 * an EOS condition is near or when @buffer is not large enough to hold @size
4259 * bytes. The caller should check the result buffer size to get the result size.
4261 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4262 * will be unchanged.
4264 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4266 * Returns: a #GstFlowReturn from the pad.
4271 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4272 GstBuffer ** buffer)
4274 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4275 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4276 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4277 g_return_val_if_fail (*buffer == NULL
4278 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4280 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4284 * gst_pad_pull_range:
4285 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4286 * @offset: The start offset of the buffer
4287 * @size: The length of the buffer
4288 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4289 * GST_FLOW_ERROR if %NULL.
4291 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4293 * This function will first trigger the pad block signal if it was
4296 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4297 * function returns the result of gst_pad_get_range() on the peer pad.
4298 * See gst_pad_get_range() for a list of return values and for the
4299 * semantics of the arguments of this function.
4301 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4302 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4303 * must be freed with gst_buffer_unref() after usage. When this function
4304 * returns any other result value, @buffer will still point to NULL.
4306 * When @buffer points to a variable that points to a valid #GstBuffer, the
4307 * buffer will be filled with the result data when this function returns
4308 * #GST_FLOW_OK. When this function returns any other result value,
4309 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4310 * @size bytes will be filled in the result buffer and its size will be updated
4313 * Note that less than @size bytes can be returned in @buffer when, for example,
4314 * an EOS condition is near or when @buffer is not large enough to hold @size
4315 * bytes. The caller should check the result buffer size to get the result size.
4317 * Returns: a #GstFlowReturn from the peer pad.
4322 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4323 GstBuffer ** buffer)
4329 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4330 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4331 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4332 g_return_val_if_fail (*buffer == NULL
4333 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4335 GST_OBJECT_LOCK (pad);
4336 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4339 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4344 /* when one of the probes returns DROPPED, probe_stopped will be
4345 * called and we skip calling the peer getrange function. *buffer should then
4346 * contain a valid buffer */
4347 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4348 res_buf, offset, size, probe_stopped);
4350 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4353 gst_object_ref (peer);
4355 GST_OBJECT_UNLOCK (pad);
4357 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4359 gst_object_unref (peer);
4361 GST_OBJECT_LOCK (pad);
4363 if (pad->priv->using == 0) {
4364 /* pad is not active anymore, trigger idle callbacks */
4365 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4366 probe_stopped_unref, ret);
4369 if (G_UNLIKELY (ret != GST_FLOW_OK))
4370 goto pull_range_failed;
4373 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4374 res_buf, offset, size, probe_stopped_unref);
4376 GST_OBJECT_UNLOCK (pad);
4382 /* ERROR recovery here */
4385 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4386 "pullrange, but pad was flushing");
4387 GST_OBJECT_UNLOCK (pad);
4388 return GST_FLOW_FLUSHING;
4392 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4393 GST_DEBUG_PAD_NAME (pad));
4394 GST_OBJECT_UNLOCK (pad);
4395 return GST_FLOW_ERROR;
4399 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4400 gst_flow_get_name (ret));
4401 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4403 /* the probe filled the buffer and asks us to not forward to the peer
4404 * anymore, we continue with the post probes then */
4405 GST_DEBUG_OBJECT (pad, "handled buffer");
4409 /* no buffer, we are EOS then */
4410 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4414 GST_OBJECT_UNLOCK (pad);
4419 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4420 "pulling range, but it was not linked");
4421 GST_OBJECT_UNLOCK (pad);
4422 return GST_FLOW_NOT_LINKED;
4426 GST_OBJECT_UNLOCK (pad);
4427 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4428 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4429 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4432 probe_stopped_unref:
4434 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4435 "post probe returned %s", gst_flow_get_name (ret));
4436 GST_OBJECT_UNLOCK (pad);
4437 /* if we drop here, it signals EOS */
4438 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4440 if (*buffer == NULL)
4441 gst_buffer_unref (res_buf);
4446 /* must be called with pad object lock */
4447 static GstFlowReturn
4448 store_sticky_event (GstPad * pad, GstEvent * event)
4453 gboolean res = FALSE;
4454 const gchar *name = NULL;
4455 gboolean insert = TRUE;
4457 type = GST_EVENT_TYPE (event);
4459 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4460 * otherwise they can be dropped and nothing would ever resend them.
4461 * Only do that for activated pads though, everything else is a bug!
4463 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4464 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4465 || type == GST_EVENT_EOS))))
4468 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4471 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4472 name = gst_structure_get_name (gst_event_get_structure (event));
4474 events = pad->priv->events;
4477 for (i = 0; i < len; i++) {
4478 PadEvent *ev = &g_array_index (events, PadEvent, i);
4480 if (ev->event == NULL)
4483 if (type == GST_EVENT_TYPE (ev->event)) {
4484 /* matching types, check matching name if needed */
4485 if (name && !gst_event_has_name (ev->event, name))
4489 if ((res = gst_event_replace (&ev->event, event)))
4490 ev->received = FALSE;
4496 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4497 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4498 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4499 * storing the sticky ordered we can check that this is respected. */
4500 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4501 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4503 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4504 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4505 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4506 gst_event_type_get_name (type));
4512 ev.event = gst_event_ref (event);
4513 ev.received = FALSE;
4514 g_array_insert_val (events, i, ev);
4519 pad->priv->events_cookie++;
4520 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4522 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4524 switch (GST_EVENT_TYPE (event)) {
4525 case GST_EVENT_CAPS:
4526 GST_OBJECT_UNLOCK (pad);
4528 GST_DEBUG_OBJECT (pad, "notify caps");
4529 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4531 GST_OBJECT_LOCK (pad);
4537 if (type == GST_EVENT_EOS)
4538 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4540 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4545 GST_DEBUG_OBJECT (pad, "pad is flushing");
4546 return GST_FLOW_FLUSHING;
4550 GST_DEBUG_OBJECT (pad, "pad is EOS");
4551 return GST_FLOW_EOS;
4556 * gst_pad_store_sticky_event:
4558 * @event: a #GstEvent
4560 * Store the sticky @event on @pad
4562 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4563 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4568 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4572 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4573 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4575 GST_OBJECT_LOCK (pad);
4576 ret = store_sticky_event (pad, event);
4577 GST_OBJECT_UNLOCK (pad);
4583 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4585 PushStickyData *data = user_data;
4587 /* Forward all sticky events before our current one that are pending */
4588 if (ev->event != data->event
4589 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4590 return push_sticky (pad, ev, data);
4595 /* should be called with pad LOCK */
4596 static GstFlowReturn
4597 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4598 GstPadProbeType type)
4602 GstEventType event_type;
4604 /* Two checks to be made:
4605 * . (un)set the FLUSHING flag for flushing events,
4606 * . handle pad blocking */
4607 event_type = GST_EVENT_TYPE (event);
4608 switch (event_type) {
4609 case GST_EVENT_FLUSH_START:
4610 GST_PAD_SET_FLUSHING (pad);
4612 GST_PAD_BLOCK_BROADCAST (pad);
4613 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4615 case GST_EVENT_FLUSH_STOP:
4616 GST_PAD_UNSET_FLUSHING (pad);
4618 /* Remove sticky EOS events */
4619 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4620 remove_event_by_type (pad, GST_EVENT_EOS);
4621 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4622 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4624 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4628 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4631 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4632 * checked already or this is called as part of pushing sticky events,
4633 * in which case we still want to forward the EOS event downstream.
4636 switch (GST_EVENT_TYPE (event)) {
4637 case GST_EVENT_SEGMENT:
4638 /* pass the adjusted segment event on. We need to do this even if
4639 * there is no peer pad because of the probes. */
4640 event = apply_pad_offset (pad, event);
4642 case GST_EVENT_RECONFIGURE:
4643 if (GST_PAD_IS_SINK (pad))
4644 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4649 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4650 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4655 /* send probes after modifying the events above */
4656 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4658 /* recheck sticky events because the probe might have cause a relink */
4659 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4660 && (GST_EVENT_IS_SERIALIZED (event)
4661 || GST_EVENT_IS_STICKY (event))) {
4662 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4663 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4665 /* Push all sticky events before our current one
4666 * that have changed */
4667 events_foreach (pad, sticky_changed, &data);
4670 /* now check the peer pad */
4671 peerpad = GST_PAD_PEER (pad);
4672 if (peerpad == NULL)
4675 gst_object_ref (peerpad);
4677 GST_OBJECT_UNLOCK (pad);
4679 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4680 event, GST_EVENT_TYPE_NAME (event), peerpad);
4682 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4684 /* Note: we gave away ownership of the event at this point but we can still
4685 * print the old pointer */
4686 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4687 event, peerpad, gst_flow_get_name (ret));
4689 gst_object_unref (peerpad);
4691 GST_OBJECT_LOCK (pad);
4693 if (pad->priv->using == 0) {
4694 /* pad is not active anymore, trigger idle callbacks */
4695 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4696 idle_probe_stopped, ret);
4700 /* ERROR handling */
4703 GST_DEBUG_OBJECT (pad, "We're flushing");
4704 gst_event_unref (event);
4705 return GST_FLOW_FLUSHING;
4709 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4710 gst_event_unref (event);
4713 case GST_FLOW_CUSTOM_SUCCESS:
4714 GST_DEBUG_OBJECT (pad, "dropped event");
4717 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4724 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4725 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4726 gst_event_unref (event);
4728 /* unlinked pads should not influence latency configuration */
4729 if (event_type == GST_EVENT_LATENCY)
4732 return GST_FLOW_NOT_LINKED;
4736 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4742 * gst_pad_push_event:
4743 * @pad: a #GstPad to push the event to.
4744 * @event: (transfer full): the #GstEvent to send to the pad.
4746 * Sends the event to the peer of the given pad. This function is
4747 * mainly used by elements to send events to their peer
4750 * This function takes owership of the provided event so you should
4751 * gst_event_ref() it if you want to reuse the event after this call.
4753 * Returns: TRUE if the event was handled.
4758 gst_pad_push_event (GstPad * pad, GstEvent * event)
4760 gboolean res = FALSE;
4761 GstPadProbeType type;
4762 gboolean sticky, serialized;
4764 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4765 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4767 if (GST_PAD_IS_SRC (pad)) {
4768 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4769 goto wrong_direction;
4770 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4771 } else if (GST_PAD_IS_SINK (pad)) {
4772 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4773 goto wrong_direction;
4774 /* events pushed on sinkpad never are sticky */
4775 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4777 goto unknown_direction;
4779 GST_OBJECT_LOCK (pad);
4780 sticky = GST_EVENT_IS_STICKY (event);
4781 serialized = GST_EVENT_IS_SERIALIZED (event);
4784 /* srcpad sticky events are stored immediately, the received flag is set
4785 * to FALSE and will be set to TRUE when we can successfully push the
4786 * event to the peer pad */
4787 switch (store_sticky_event (pad, event)) {
4788 case GST_FLOW_FLUSHING:
4796 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4797 /* all serialized or sticky events on the srcpad trigger push of
4799 res = (check_sticky (pad, event) == GST_FLOW_OK);
4804 /* other events are pushed right away */
4805 ret = gst_pad_push_event_unchecked (pad, event, type);
4806 /* dropped events by a probe are not an error */
4807 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4809 /* Errors in sticky event pushing are no problem and ignored here
4810 * as they will cause more meaningful errors during data flow.
4811 * For EOS events, that are not followed by data flow, we still
4812 * return FALSE here though.
4814 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4816 gst_event_unref (event);
4818 GST_OBJECT_UNLOCK (pad);
4822 /* ERROR handling */
4825 g_warning ("pad %s:%s pushing %s event in wrong direction",
4826 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4827 gst_event_unref (event);
4832 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4833 gst_event_unref (event);
4838 GST_DEBUG_OBJECT (pad, "We're flushing");
4839 GST_OBJECT_UNLOCK (pad);
4840 gst_event_unref (event);
4845 GST_DEBUG_OBJECT (pad, "We're EOS");
4846 GST_OBJECT_UNLOCK (pad);
4847 gst_event_unref (event);
4852 /* Check if we can call the event function with the given event */
4853 static GstFlowReturn
4854 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4858 switch (GST_EVENT_TYPE (event)) {
4859 case GST_EVENT_CAPS:
4861 /* backwards compatibility mode for caps */
4862 gst_event_parse_caps (event, &caps);
4864 if (!gst_pad_query_accept_caps (pad, caps))
4876 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4877 "caps %" GST_PTR_FORMAT " not accepted", caps);
4878 return GST_FLOW_NOT_NEGOTIATED;
4882 static GstFlowReturn
4883 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4884 GstPadProbeType type)
4887 GstEventType event_type;
4888 gboolean serialized, need_unlock = FALSE, sticky;
4889 GstPadEventFunction eventfunc;
4892 GST_OBJECT_LOCK (pad);
4893 if (GST_PAD_IS_SINK (pad))
4894 serialized = GST_EVENT_IS_SERIALIZED (event);
4897 sticky = GST_EVENT_IS_STICKY (event);
4898 event_type = GST_EVENT_TYPE (event);
4899 switch (event_type) {
4900 case GST_EVENT_FLUSH_START:
4901 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4902 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4904 /* can't even accept a flush begin event when flushing */
4905 if (GST_PAD_IS_FLUSHING (pad))
4908 GST_PAD_SET_FLUSHING (pad);
4909 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4911 case GST_EVENT_FLUSH_STOP:
4912 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4913 GST_PAD_UNSET_FLUSHING (pad);
4914 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4916 /* Remove pending EOS events */
4917 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4918 remove_event_by_type (pad, GST_EVENT_EOS);
4919 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4920 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4922 GST_OBJECT_UNLOCK (pad);
4923 /* grab stream lock */
4924 GST_PAD_STREAM_LOCK (pad);
4926 GST_OBJECT_LOCK (pad);
4927 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4930 case GST_EVENT_RECONFIGURE:
4931 if (GST_PAD_IS_SRC (pad))
4932 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4934 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4935 "have event type %" GST_PTR_FORMAT, event);
4937 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4941 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4944 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4945 GST_OBJECT_UNLOCK (pad);
4946 GST_PAD_STREAM_LOCK (pad);
4948 GST_OBJECT_LOCK (pad);
4949 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4952 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4956 switch (GST_EVENT_TYPE (event)) {
4957 case GST_EVENT_SEGMENT:
4958 event = apply_pad_offset (pad, event);
4966 /* now do the probe */
4968 type | GST_PAD_PROBE_TYPE_PUSH |
4969 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4971 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4973 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4976 ACQUIRE_PARENT (pad, parent, no_parent);
4977 GST_OBJECT_UNLOCK (pad);
4979 ret = pre_eventfunc_check (pad, event);
4980 if (G_UNLIKELY (ret != GST_FLOW_OK))
4981 goto precheck_failed;
4984 gst_event_ref (event);
4986 if (eventfunc (pad, parent, event)) {
4989 /* something went wrong */
4990 switch (event_type) {
4991 case GST_EVENT_CAPS:
4992 ret = GST_FLOW_NOT_NEGOTIATED;
4995 ret = GST_FLOW_ERROR;
4999 RELEASE_PARENT (parent);
5001 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5004 if (ret == GST_FLOW_OK) {
5005 GST_OBJECT_LOCK (pad);
5006 /* after the event function accepted the event, we can store the sticky
5007 * event on the pad */
5008 switch (store_sticky_event (pad, event)) {
5009 case GST_FLOW_FLUSHING:
5016 GST_OBJECT_UNLOCK (pad);
5018 gst_event_unref (event);
5022 GST_PAD_STREAM_UNLOCK (pad);
5026 /* ERROR handling */
5029 GST_OBJECT_UNLOCK (pad);
5031 GST_PAD_STREAM_UNLOCK (pad);
5032 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5033 "Received event on flushing pad. Discarding");
5034 gst_event_unref (event);
5035 return GST_FLOW_FLUSHING;
5039 GST_OBJECT_UNLOCK (pad);
5041 GST_PAD_STREAM_UNLOCK (pad);
5042 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5043 "Received event on EOS pad. Discarding");
5044 gst_event_unref (event);
5045 return GST_FLOW_EOS;
5049 GST_OBJECT_UNLOCK (pad);
5051 GST_PAD_STREAM_UNLOCK (pad);
5052 gst_event_unref (event);
5055 case GST_FLOW_CUSTOM_SUCCESS:
5056 GST_DEBUG_OBJECT (pad, "dropped event");
5060 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
5067 g_warning ("pad %s:%s has no event handler, file a bug.",
5068 GST_DEBUG_PAD_NAME (pad));
5069 GST_OBJECT_UNLOCK (pad);
5071 GST_PAD_STREAM_UNLOCK (pad);
5072 gst_event_unref (event);
5073 return GST_FLOW_NOT_SUPPORTED;
5077 GST_DEBUG_OBJECT (pad, "no parent");
5078 GST_OBJECT_UNLOCK (pad);
5080 GST_PAD_STREAM_UNLOCK (pad);
5081 gst_event_unref (event);
5082 return GST_FLOW_FLUSHING;
5086 GST_DEBUG_OBJECT (pad, "pre event check failed");
5087 RELEASE_PARENT (parent);
5089 GST_PAD_STREAM_UNLOCK (pad);
5090 gst_event_unref (event);
5096 * gst_pad_send_event:
5097 * @pad: a #GstPad to send the event to.
5098 * @event: (transfer full): the #GstEvent to send to the pad.
5100 * Sends the event to the pad. This function can be used
5101 * by applications to send events in the pipeline.
5103 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5104 * sink pad, @event should be a downstream event. For example, you would not
5105 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5106 * Furthermore, some downstream events have to be serialized with data flow,
5107 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5108 * the event needs to be serialized with data flow, this function will take the
5109 * pad's stream lock while calling its event function.
5111 * To find out whether an event type is upstream, downstream, or downstream and
5112 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5113 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5114 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5115 * plugin doesn't need to bother itself with this information; the core handles
5116 * all necessary locks and checks.
5118 * This function takes owership of the provided event so you should
5119 * gst_event_ref() it if you want to reuse the event after this call.
5121 * Returns: TRUE if the event was handled.
5124 gst_pad_send_event (GstPad * pad, GstEvent * event)
5127 GstPadProbeType type;
5129 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5130 g_return_val_if_fail (event != NULL, FALSE);
5132 if (GST_PAD_IS_SINK (pad)) {
5133 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5134 goto wrong_direction;
5135 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5136 } else if (GST_PAD_IS_SRC (pad)) {
5137 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5138 goto wrong_direction;
5139 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5141 goto unknown_direction;
5143 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5150 /* ERROR handling */
5153 g_warning ("pad %s:%s sending %s event in wrong direction",
5154 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5155 gst_event_unref (event);
5160 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5161 gst_event_unref (event);
5167 * gst_pad_set_element_private:
5168 * @pad: the #GstPad to set the private data of.
5169 * @priv: The private data to attach to the pad.
5171 * Set the given private data gpointer on the pad.
5172 * This function can only be used by the element that owns the pad.
5173 * No locking is performed in this function.
5176 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5178 pad->element_private = priv;
5182 * gst_pad_get_element_private:
5183 * @pad: the #GstPad to get the private data of.
5185 * Gets the private data of a pad.
5186 * No locking is performed in this function.
5188 * Returns: (transfer none): a #gpointer to the private data.
5191 gst_pad_get_element_private (GstPad * pad)
5193 return pad->element_private;
5197 * gst_pad_get_sticky_event:
5198 * @pad: the #GstPad to get the event from.
5199 * @event_type: the #GstEventType that should be retrieved.
5200 * @idx: the index of the event
5202 * Returns a new reference of the sticky event of type @event_type
5205 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5206 * event of @event_type was on @pad. Unref after usage.
5209 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5211 GstEvent *event = NULL;
5214 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5215 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5217 GST_OBJECT_LOCK (pad);
5218 ev = find_event_by_type (pad, event_type, idx);
5219 if (ev && (event = ev->event))
5220 gst_event_ref (event);
5221 GST_OBJECT_UNLOCK (pad);
5228 GstPadStickyEventsForeachFunction func;
5233 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5235 ForeachDispatch *data = user_data;
5236 gboolean ret = TRUE;
5239 GST_OBJECT_UNLOCK (pad);
5241 ret = data->func (pad, &ev->event, data->user_data);
5243 GST_OBJECT_LOCK (pad);
5250 * gst_pad_sticky_events_foreach:
5251 * @pad: the #GstPad that should be used for iteration.
5252 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5253 * should be called for every event.
5254 * @user_data: (closure): the optional user data.
5256 * Iterates all sticky events on @pad and calls @foreach_func for every
5257 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5260 gst_pad_sticky_events_foreach (GstPad * pad,
5261 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5263 ForeachDispatch data;
5265 g_return_if_fail (GST_IS_PAD (pad));
5266 g_return_if_fail (foreach_func != NULL);
5268 data.func = foreach_func;
5269 data.user_data = user_data;
5271 GST_OBJECT_LOCK (pad);
5272 events_foreach (pad, foreach_dispatch_function, &data);
5273 GST_OBJECT_UNLOCK (pad);
5277 do_stream_status (GstPad * pad, GstStreamStatusType type,
5278 GThread * thread, GstTask * task)
5282 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5284 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5285 if (GST_IS_ELEMENT (parent)) {
5286 GstMessage *message;
5287 GValue value = { 0 };
5289 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5290 gchar *tname, *ename, *pname;
5292 /* create a good task name */
5293 ename = gst_element_get_name (parent);
5294 pname = gst_pad_get_name (pad);
5295 tname = g_strdup_printf ("%s:%s", ename, pname);
5299 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5303 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5306 g_value_init (&value, GST_TYPE_TASK);
5307 g_value_set_object (&value, task);
5308 gst_message_set_stream_status_object (message, &value);
5309 g_value_unset (&value);
5311 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5312 gst_element_post_message (parent, message);
5314 gst_object_unref (parent);
5319 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5321 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5326 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5328 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5333 * gst_pad_start_task:
5334 * @pad: the #GstPad to start the task of
5335 * @func: the task function to call
5336 * @user_data: user data passed to the task function
5337 * @notify: called when @user_data is no longer referenced
5339 * Starts a task that repeatedly calls @func with @user_data. This function
5340 * is mostly used in pad activation functions to start the dataflow.
5341 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5342 * before @func is called.
5344 * Returns: a %TRUE if the task could be started.
5347 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5348 GDestroyNotify notify)
5353 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5354 g_return_val_if_fail (func != NULL, FALSE);
5356 GST_DEBUG_OBJECT (pad, "start task");
5358 GST_OBJECT_LOCK (pad);
5359 task = GST_PAD_TASK (pad);
5361 task = gst_task_new (func, user_data, notify);
5362 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5363 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5364 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5365 GST_INFO_OBJECT (pad, "created task %p", task);
5366 GST_PAD_TASK (pad) = task;
5367 gst_object_ref (task);
5368 /* release lock to post the message */
5369 GST_OBJECT_UNLOCK (pad);
5371 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5373 gst_object_unref (task);
5375 GST_OBJECT_LOCK (pad);
5376 /* nobody else is supposed to have changed the pad now */
5377 if (GST_PAD_TASK (pad) != task)
5378 goto concurrent_stop;
5380 res = gst_task_set_state (task, GST_TASK_STARTED);
5381 GST_OBJECT_UNLOCK (pad);
5388 GST_OBJECT_UNLOCK (pad);
5394 * gst_pad_pause_task:
5395 * @pad: the #GstPad to pause the task of
5397 * Pause the task of @pad. This function will also wait until the
5398 * function executed by the task is finished if this function is not
5399 * called from the task function.
5401 * Returns: a TRUE if the task could be paused or FALSE when the pad
5405 gst_pad_pause_task (GstPad * pad)
5410 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5412 GST_DEBUG_OBJECT (pad, "pause task");
5414 GST_OBJECT_LOCK (pad);
5415 task = GST_PAD_TASK (pad);
5418 res = gst_task_set_state (task, GST_TASK_PAUSED);
5419 GST_OBJECT_UNLOCK (pad);
5421 /* wait for task function to finish, this lock is recursive so it does nothing
5422 * when the pause is called from the task itself */
5423 GST_PAD_STREAM_LOCK (pad);
5424 GST_PAD_STREAM_UNLOCK (pad);
5430 GST_DEBUG_OBJECT (pad, "pad has no task");
5431 GST_OBJECT_UNLOCK (pad);
5437 * gst_pad_stop_task:
5438 * @pad: the #GstPad to stop the task of
5440 * Stop the task of @pad. This function will also make sure that the
5441 * function executed by the task will effectively stop if not called
5442 * from the GstTaskFunction.
5444 * This function will deadlock if called from the GstTaskFunction of
5445 * the task. Use gst_task_pause() instead.
5447 * Regardless of whether the pad has a task, the stream lock is acquired and
5448 * released so as to ensure that streaming through this pad has finished.
5450 * Returns: a TRUE if the task could be stopped or FALSE on error.
5453 gst_pad_stop_task (GstPad * pad)
5458 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5460 GST_DEBUG_OBJECT (pad, "stop task");
5462 GST_OBJECT_LOCK (pad);
5463 task = GST_PAD_TASK (pad);
5466 GST_PAD_TASK (pad) = NULL;
5467 res = gst_task_set_state (task, GST_TASK_STOPPED);
5468 GST_OBJECT_UNLOCK (pad);
5470 GST_PAD_STREAM_LOCK (pad);
5471 GST_PAD_STREAM_UNLOCK (pad);
5473 if (!gst_task_join (task))
5476 gst_object_unref (task);
5482 GST_DEBUG_OBJECT (pad, "no task");
5483 GST_OBJECT_UNLOCK (pad);
5485 GST_PAD_STREAM_LOCK (pad);
5486 GST_PAD_STREAM_UNLOCK (pad);
5488 /* this is not an error */
5493 /* this is bad, possibly the application tried to join the task from
5494 * the task's thread. We install the task again so that it will be stopped
5495 * again from the right thread next time hopefully. */
5496 GST_OBJECT_LOCK (pad);
5497 GST_DEBUG_OBJECT (pad, "join failed");
5498 /* we can only install this task if there was no other task */
5499 if (GST_PAD_TASK (pad) == NULL)
5500 GST_PAD_TASK (pad) = task;
5501 GST_OBJECT_UNLOCK (pad);
5508 * gst_pad_probe_info_get_event:
5509 * @info: a #GstPadProbeInfo
5511 * Returns: (transfer none): The #GstEvent from the probe
5515 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5517 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5518 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5520 return GST_PAD_PROBE_INFO_EVENT (info);
5525 * gst_pad_probe_info_get_query:
5526 * @info: a #GstPadProbeInfo
5528 * Returns: (transfer none): The #GstQuery from the probe
5532 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5534 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5535 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5537 return GST_PAD_PROBE_INFO_QUERY (info);
5541 * gst_pad_probe_info_get_buffer:
5542 * @info: a #GstPadProbeInfo
5544 * Returns: (transfer none): The #GstBuffer from the probe
5548 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5550 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5552 return GST_PAD_PROBE_INFO_BUFFER (info);
5556 * gst_pad_probe_info_get_bufferlist:
5557 * @info: a #GstPadProbeInfo
5559 * Returns: (transfer none): The #GstBufferlist from the probe
5563 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5565 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5567 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);