2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element with gst_element_get_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
141 guint probe_list_cookie;
151 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
156 GstPadProbeInfo *info;
163 static void gst_pad_dispose (GObject * object);
164 static void gst_pad_finalize (GObject * object);
165 static void gst_pad_set_property (GObject * object, guint prop_id,
166 const GValue * value, GParamSpec * pspec);
167 static void gst_pad_get_property (GObject * object, guint prop_id,
168 GValue * value, GParamSpec * pspec);
170 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
171 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
172 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
173 GstObject * parent, GstBufferList * list);
175 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
176 GstEvent * event, GstPadProbeType type);
177 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
178 GstEvent * event, GstPadProbeType type);
180 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
182 static GParamSpec *pspec_caps = NULL;
184 /* quarks for probe signals */
185 static GQuark buffer_quark;
186 static GQuark buffer_list_quark;
187 static GQuark event_quark;
196 static GstFlowQuarks flow_quarks[] = {
197 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
198 {GST_FLOW_OK, "ok", 0},
199 {GST_FLOW_NOT_LINKED, "not-linked", 0},
200 {GST_FLOW_FLUSHING, "flushing", 0},
201 {GST_FLOW_EOS, "eos", 0},
202 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
203 {GST_FLOW_ERROR, "error", 0},
204 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
205 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
210 * @ret: a #GstFlowReturn to get the name of.
212 * Gets a string representing the given flow return.
214 * Returns: a static string with the name of the flow return.
217 gst_flow_get_name (GstFlowReturn ret)
221 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
223 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
224 if (ret == flow_quarks[i].ret)
225 return flow_quarks[i].name;
232 * @ret: a #GstFlowReturn to get the quark of.
234 * Get the unique quark for the given GstFlowReturn.
236 * Returns: the quark associated with the flow return or 0 if an
237 * invalid return was specified.
240 gst_flow_to_quark (GstFlowReturn ret)
244 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
246 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
247 if (ret == flow_quarks[i].ret)
248 return flow_quarks[i].quark;
257 buffer_quark = g_quark_from_static_string ("buffer"); \
258 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
259 event_quark = g_quark_from_static_string ("event"); \
261 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
262 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
265 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
266 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
269 #define gst_pad_parent_class parent_class
270 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
273 gst_pad_class_init (GstPadClass * klass)
275 GObjectClass *gobject_class;
276 GstObjectClass *gstobject_class;
278 gobject_class = G_OBJECT_CLASS (klass);
279 gstobject_class = GST_OBJECT_CLASS (klass);
281 g_type_class_add_private (klass, sizeof (GstPadPrivate));
283 gobject_class->dispose = gst_pad_dispose;
284 gobject_class->finalize = gst_pad_finalize;
285 gobject_class->set_property = gst_pad_set_property;
286 gobject_class->get_property = gst_pad_get_property;
290 * @pad: the pad that emitted the signal
291 * @peer: the peer pad that has been connected
293 * Signals that a pad has been linked to the peer pad.
295 gst_pad_signals[PAD_LINKED] =
296 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
297 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
298 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
301 * @pad: the pad that emitted the signal
302 * @peer: the peer pad that has been disconnected
304 * Signals that a pad has been unlinked from the peer pad.
306 gst_pad_signals[PAD_UNLINKED] =
307 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
308 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
309 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
311 pspec_caps = g_param_spec_boxed ("caps", "Caps",
312 "The capabilities of the pad", GST_TYPE_CAPS,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
314 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
316 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
317 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
318 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
319 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
321 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
322 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
323 g_param_spec_object ("template", "Template",
324 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
325 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
327 gstobject_class->path_string_separator = ".";
329 /* Register common function pointer descriptions */
330 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
338 gst_pad_init (GstPad * pad)
340 pad->priv = GST_PAD_GET_PRIVATE (pad);
342 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
344 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
345 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
346 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
347 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
348 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
350 GST_PAD_SET_FLUSHING (pad);
352 g_rec_mutex_init (&pad->stream_rec_lock);
354 g_cond_init (&pad->block_cond);
356 g_hook_list_init (&pad->probes, sizeof (GstProbe));
358 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
361 /* called when setting the pad inactive. It removes all sticky events from
362 * the pad. must be called with object lock */
364 remove_events (GstPad * pad)
369 events = pad->priv->events;
372 for (i = 0; i < len; i++) {
373 PadEvent *ev = &g_array_index (events, PadEvent, i);
374 GstEvent *event = ev->event;
378 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
379 GST_OBJECT_UNLOCK (pad);
381 GST_DEBUG_OBJECT (pad, "notify caps");
382 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
384 GST_OBJECT_LOCK (pad);
386 gst_event_unref (event);
388 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
389 g_array_set_size (events, 0);
390 pad->priv->events_cookie++;
393 /* should be called with object lock */
395 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
401 events = pad->priv->events;
404 for (i = 0; i < len; i++) {
405 ev = &g_array_index (events, PadEvent, i);
406 if (ev->event == NULL)
409 if (GST_EVENT_TYPE (ev->event) == type) {
420 /* should be called with OBJECT lock */
422 find_event (GstPad * pad, GstEvent * event)
428 events = pad->priv->events;
431 for (i = 0; i < len; i++) {
432 ev = &g_array_index (events, PadEvent, i);
433 if (event == ev->event)
441 /* should be called with OBJECT lock */
443 remove_event_by_type (GstPad * pad, GstEventType type)
449 events = pad->priv->events;
454 ev = &g_array_index (events, PadEvent, i);
455 if (ev->event == NULL)
458 if (GST_EVENT_TYPE (ev->event) != type)
461 gst_event_unref (ev->event);
462 g_array_remove_index (events, i);
464 pad->priv->events_cookie++;
472 /* check all events on srcpad against those on sinkpad. All events that are not
473 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
474 * srcpad so that the events will be sent next time */
475 /* should be called with srcpad and sinkpad LOCKS */
477 schedule_events (GstPad * srcpad, GstPad * sinkpad)
482 gboolean pending = FALSE;
484 events = srcpad->priv->events;
487 for (i = 0; i < len; i++) {
488 ev = &g_array_index (events, PadEvent, i);
489 if (ev->event == NULL)
492 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
493 ev->received = FALSE;
498 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
501 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
504 /* should be called with pad LOCK */
506 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
513 events = pad->priv->events;
516 cookie = pad->priv->events_cookie;
520 PadEvent *ev, ev_ret;
522 ev = &g_array_index (events, PadEvent, i);
523 if (G_UNLIKELY (ev->event == NULL))
526 /* take aditional ref, func might release the lock */
527 ev_ret.event = gst_event_ref (ev->event);
528 ev_ret.received = ev->received;
530 ret = func (pad, &ev_ret, user_data);
532 /* recheck the cookie, lock might have been released and the list could have
534 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
535 if (G_LIKELY (ev_ret.event))
536 gst_event_unref (ev_ret.event);
540 /* store the received state */
541 ev->received = ev_ret.received;
543 /* if the event changed, we need to do something */
544 if (G_UNLIKELY (ev->event != ev_ret.event)) {
545 if (G_UNLIKELY (ev_ret.event == NULL)) {
546 /* function unreffed and set the event to NULL, remove it */
547 g_array_remove_index (events, i);
549 cookie = ++pad->priv->events_cookie;
552 /* function gave a new event for us */
553 gst_event_take (&ev->event, ev_ret.event);
556 /* just unref, nothing changed */
557 gst_event_unref (ev_ret.event);
566 /* should be called with LOCK */
568 apply_pad_offset (GstPad * pad, GstEvent * event)
570 /* check if we need to adjust the segment */
571 if (pad->offset != 0) {
574 /* copy segment values */
575 gst_event_copy_segment (event, &segment);
576 gst_event_unref (event);
578 /* adjust and make a new event with the offset applied */
579 segment.base += pad->offset;
580 event = gst_event_new_segment (&segment);
585 /* should be called with the OBJECT_LOCK */
587 get_pad_caps (GstPad * pad)
589 GstCaps *caps = NULL;
592 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
594 gst_event_parse_caps (ev->event, &caps);
600 gst_pad_dispose (GObject * object)
602 GstPad *pad = GST_PAD_CAST (object);
605 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
607 /* unlink the peer pad */
608 if ((peer = gst_pad_get_peer (pad))) {
609 /* window for MT unsafeness, someone else could unlink here
610 * and then we call unlink with wrong pads. The unlink
611 * function would catch this and safely return failed. */
612 if (GST_PAD_IS_SRC (pad))
613 gst_pad_unlink (pad, peer);
615 gst_pad_unlink (peer, pad);
617 gst_object_unref (peer);
620 gst_pad_set_pad_template (pad, NULL);
622 GST_OBJECT_LOCK (pad);
624 GST_OBJECT_UNLOCK (pad);
626 g_hook_list_clear (&pad->probes);
628 G_OBJECT_CLASS (parent_class)->dispose (object);
632 gst_pad_finalize (GObject * object)
634 GstPad *pad = GST_PAD_CAST (object);
637 /* in case the task is still around, clean it up */
638 if ((task = GST_PAD_TASK (pad))) {
639 gst_task_join (task);
640 GST_PAD_TASK (pad) = NULL;
641 gst_object_unref (task);
644 if (pad->activatenotify)
645 pad->activatenotify (pad->activatedata);
646 if (pad->activatemodenotify)
647 pad->activatemodenotify (pad->activatemodedata);
649 pad->linknotify (pad->linkdata);
650 if (pad->unlinknotify)
651 pad->unlinknotify (pad->unlinkdata);
652 if (pad->chainnotify)
653 pad->chainnotify (pad->chaindata);
654 if (pad->chainlistnotify)
655 pad->chainlistnotify (pad->chainlistdata);
656 if (pad->getrangenotify)
657 pad->getrangenotify (pad->getrangedata);
658 if (pad->eventnotify)
659 pad->eventnotify (pad->eventdata);
660 if (pad->querynotify)
661 pad->querynotify (pad->querydata);
662 if (pad->iterintlinknotify)
663 pad->iterintlinknotify (pad->iterintlinkdata);
665 g_rec_mutex_clear (&pad->stream_rec_lock);
666 g_cond_clear (&pad->block_cond);
667 g_array_free (pad->priv->events, TRUE);
669 G_OBJECT_CLASS (parent_class)->finalize (object);
673 gst_pad_set_property (GObject * object, guint prop_id,
674 const GValue * value, GParamSpec * pspec)
676 g_return_if_fail (GST_IS_PAD (object));
679 case PAD_PROP_DIRECTION:
680 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
682 case PAD_PROP_TEMPLATE:
683 gst_pad_set_pad_template (GST_PAD_CAST (object),
684 (GstPadTemplate *) g_value_get_object (value));
687 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
693 gst_pad_get_property (GObject * object, guint prop_id,
694 GValue * value, GParamSpec * pspec)
696 g_return_if_fail (GST_IS_PAD (object));
700 GST_OBJECT_LOCK (object);
701 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
702 GST_OBJECT_UNLOCK (object);
704 case PAD_PROP_DIRECTION:
705 g_value_set_enum (value, GST_PAD_DIRECTION (object));
707 case PAD_PROP_TEMPLATE:
708 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
711 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
718 * @name: the name of the new pad.
719 * @direction: the #GstPadDirection of the pad.
721 * Creates a new pad with the given name in the given direction.
722 * If name is NULL, a guaranteed unique name (across all pads)
724 * This function makes a copy of the name so you can safely free the name.
726 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
731 gst_pad_new (const gchar * name, GstPadDirection direction)
733 return g_object_new (GST_TYPE_PAD,
734 "name", name, "direction", direction, NULL);
738 * gst_pad_new_from_template:
739 * @templ: the pad template to use
740 * @name: the name of the element
742 * Creates a new pad with the given name from the given template.
743 * If name is NULL, a guaranteed unique name (across all pads)
745 * This function makes a copy of the name so you can safely free the name.
747 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
750 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
752 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
754 return g_object_new (GST_TYPE_PAD,
755 "name", name, "direction", templ->direction, "template", templ, NULL);
759 * gst_pad_new_from_static_template:
760 * @templ: the #GstStaticPadTemplate to use
761 * @name: the name of the element
763 * Creates a new pad with the given name from the given static template.
764 * If name is NULL, a guaranteed unique name (across all pads)
766 * This function makes a copy of the name so you can safely free the name.
768 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
771 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
775 GstPadTemplate *template;
777 template = gst_static_pad_template_get (templ);
778 pad = gst_pad_new_from_template (template, name);
779 gst_object_unref (template);
783 #define ACQUIRE_PARENT(pad, parent, label) \
785 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
786 gst_object_ref (parent); \
787 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
791 #define RELEASE_PARENT(parent) \
793 if (G_LIKELY (parent)) \
794 gst_object_unref (parent); \
798 * gst_pad_get_direction:
799 * @pad: a #GstPad to get the direction of.
801 * Gets the direction of the pad. The direction of the pad is
802 * decided at construction time so this function does not take
805 * Returns: the #GstPadDirection of the pad.
810 gst_pad_get_direction (GstPad * pad)
812 GstPadDirection result;
814 /* PAD_UNKNOWN is a little silly but we need some sort of
815 * error return value */
816 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
818 result = GST_PAD_DIRECTION (pad);
824 gst_pad_activate_default (GstPad * pad, GstObject * parent)
826 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
830 * gst_pad_mode_get_name:
831 * @mode: the pad mode
833 * Return the name of a pad mode, for use in debug messages mostly.
835 * Returns: short mnemonic for pad mode @mode
838 gst_pad_mode_get_name (GstPadMode mode)
841 case GST_PAD_MODE_NONE:
843 case GST_PAD_MODE_PUSH:
845 case GST_PAD_MODE_PULL:
854 pre_activate (GstPad * pad, GstPadMode new_mode)
857 case GST_PAD_MODE_NONE:
858 GST_OBJECT_LOCK (pad);
859 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
860 GST_PAD_SET_FLUSHING (pad);
861 GST_PAD_MODE (pad) = new_mode;
862 /* unlock blocked pads so element can resume and stop */
863 GST_PAD_BLOCK_BROADCAST (pad);
864 GST_OBJECT_UNLOCK (pad);
866 case GST_PAD_MODE_PUSH:
867 case GST_PAD_MODE_PULL:
868 GST_OBJECT_LOCK (pad);
869 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
870 gst_pad_mode_get_name (new_mode));
871 GST_PAD_UNSET_FLUSHING (pad);
872 GST_PAD_MODE (pad) = new_mode;
873 if (GST_PAD_IS_SINK (pad)) {
875 /* make sure the peer src pad sends us all events */
876 if ((peer = GST_PAD_PEER (pad))) {
877 gst_object_ref (peer);
878 GST_OBJECT_UNLOCK (pad);
880 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
881 GST_DEBUG_PAD_NAME (peer));
883 GST_OBJECT_LOCK (peer);
884 schedule_events (peer, NULL);
885 GST_OBJECT_UNLOCK (peer);
887 gst_object_unref (peer);
889 GST_OBJECT_UNLOCK (pad);
892 GST_OBJECT_UNLOCK (pad);
899 post_activate (GstPad * pad, GstPadMode new_mode)
902 case GST_PAD_MODE_NONE:
903 /* ensures that streaming stops */
904 GST_PAD_STREAM_LOCK (pad);
905 GST_DEBUG_OBJECT (pad, "stopped streaming");
906 GST_OBJECT_LOCK (pad);
908 GST_OBJECT_UNLOCK (pad);
909 GST_PAD_STREAM_UNLOCK (pad);
911 case GST_PAD_MODE_PUSH:
912 case GST_PAD_MODE_PULL:
919 * gst_pad_set_active:
920 * @pad: the #GstPad to activate or deactivate.
921 * @active: whether or not the pad should be active.
923 * Activates or deactivates the given pad.
924 * Normally called from within core state change functions.
926 * If @active, makes sure the pad is active. If it is already active, either in
927 * push or pull mode, just return. Otherwise dispatches to the pad's activate
928 * function to perform the actual activation.
930 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
931 * and a FALSE argument.
933 * Returns: #TRUE if the operation was successful.
938 gst_pad_set_active (GstPad * pad, gboolean active)
942 gboolean ret = FALSE;
944 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
946 GST_OBJECT_LOCK (pad);
947 old = GST_PAD_MODE (pad);
948 ACQUIRE_PARENT (pad, parent, no_parent);
949 GST_OBJECT_UNLOCK (pad);
952 if (old == GST_PAD_MODE_NONE) {
953 GST_DEBUG_OBJECT (pad, "activating pad from none");
954 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
956 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
957 gst_pad_mode_get_name (old));
961 if (old == GST_PAD_MODE_NONE) {
962 GST_DEBUG_OBJECT (pad, "pad was inactive");
965 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
966 gst_pad_mode_get_name (old));
967 ret = gst_pad_activate_mode (pad, old, FALSE);
971 RELEASE_PARENT (parent);
973 if (G_UNLIKELY (!ret))
981 GST_DEBUG_OBJECT (pad, "no parent");
982 GST_OBJECT_UNLOCK (pad);
987 GST_OBJECT_LOCK (pad);
989 g_critical ("Failed to deactivate pad %s:%s, very bad",
990 GST_DEBUG_PAD_NAME (pad));
992 GST_WARNING_OBJECT (pad, "Failed to activate pad");
994 GST_OBJECT_UNLOCK (pad);
1000 * gst_pad_activate_mode:
1001 * @pad: the #GstPad to activate or deactivate.
1002 * @mode: the requested activation mode
1003 * @active: whether or not the pad should be active.
1005 * Activates or deactivates the given pad in @mode via dispatching to the
1006 * pad's activatemodefunc. For use from within pad activation functions only.
1008 * If you don't know what this is, you probably don't want to call it.
1010 * Returns: TRUE if the operation was successful.
1015 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1017 gboolean res = FALSE;
1019 GstPadMode old, new;
1020 GstPadDirection dir;
1023 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1025 GST_OBJECT_LOCK (pad);
1026 old = GST_PAD_MODE (pad);
1027 dir = GST_PAD_DIRECTION (pad);
1028 ACQUIRE_PARENT (pad, parent, no_parent);
1029 GST_OBJECT_UNLOCK (pad);
1031 new = active ? mode : GST_PAD_MODE_NONE;
1036 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1037 /* pad was activate in the wrong direction, deactivate it
1038 * and reactivate it in the requested mode */
1039 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1040 gst_pad_mode_get_name (old));
1042 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1043 goto deactivate_failed;
1047 case GST_PAD_MODE_PULL:
1049 if (dir == GST_PAD_SINK) {
1050 if ((peer = gst_pad_get_peer (pad))) {
1051 GST_DEBUG_OBJECT (pad, "calling peer");
1052 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1054 gst_object_unref (peer);
1056 /* there is no peer, this is only fatal when we activate. When we
1057 * deactivate, we must assume the application has unlinked the peer and
1058 * will deactivate it eventually. */
1062 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1065 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1066 goto failure; /* Can't activate pull on a src without a
1067 getrange function */
1075 pre_activate (pad, new);
1077 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1078 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1082 /* can happen for sinks of passthrough elements */
1085 post_activate (pad, new);
1087 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1088 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1093 /* Clear sticky flags on deactivation */
1095 GST_OBJECT_LOCK (pad);
1096 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1097 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1098 GST_OBJECT_UNLOCK (pad);
1102 RELEASE_PARENT (parent);
1108 GST_DEBUG_OBJECT (pad, "no parent");
1109 GST_OBJECT_UNLOCK (pad);
1114 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1115 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1120 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1121 "failed to %s in switch to %s mode from %s mode",
1122 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1123 gst_pad_mode_get_name (old));
1128 GST_OBJECT_LOCK (peer);
1129 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1130 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1131 GST_OBJECT_UNLOCK (peer);
1132 gst_object_unref (peer);
1137 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1138 "pad in pull mode");
1143 GST_OBJECT_LOCK (pad);
1144 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1145 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1146 GST_PAD_SET_FLUSHING (pad);
1147 GST_PAD_MODE (pad) = old;
1148 GST_OBJECT_UNLOCK (pad);
1154 * gst_pad_is_active:
1155 * @pad: the #GstPad to query
1157 * Query if a pad is active
1159 * Returns: TRUE if the pad is active.
1164 gst_pad_is_active (GstPad * pad)
1166 gboolean result = FALSE;
1168 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1170 GST_OBJECT_LOCK (pad);
1171 result = GST_PAD_IS_ACTIVE (pad);
1172 GST_OBJECT_UNLOCK (pad);
1178 * gst_pad_add_probe:
1179 * @pad: the #GstPad to add the probe to
1180 * @mask: the probe mask
1181 * @callback: #GstPadProbeCallback that will be called with notifications of
1183 * @user_data: (closure): user data passed to the callback
1184 * @destroy_data: #GDestroyNotify for user_data
1186 * Be notified of different states of pads. The provided callback is called for
1187 * every state that matches @mask.
1189 * Returns: an id or 0 on error. The id can be used to remove the probe with
1190 * gst_pad_remove_probe().
1195 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1196 GstPadProbeCallback callback, gpointer user_data,
1197 GDestroyNotify destroy_data)
1202 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1203 g_return_val_if_fail (mask != 0, 0);
1205 GST_OBJECT_LOCK (pad);
1207 /* make a new probe */
1208 hook = g_hook_alloc (&pad->probes);
1210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1213 /* when no contraints are given for the types, assume all types are
1215 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1216 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1217 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1218 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1220 /* store our flags and other fields */
1221 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1222 hook->func = callback;
1223 hook->data = user_data;
1224 hook->destroy = destroy_data;
1225 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1228 g_hook_prepend (&pad->probes, hook);
1230 /* incremenent cookie so that the new hook get's called */
1231 pad->priv->probe_list_cookie++;
1233 /* get the id of the hook, we return this and it can be used to remove the
1235 res = hook->hook_id;
1237 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1239 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1240 /* we have a block probe */
1242 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1244 "now %d blocking probes", pad->num_blocked);
1247 /* call the callback if we need to be called for idle callbacks */
1248 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1249 if (pad->priv->using > 0) {
1250 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1251 * flag above, the last thread to leave the push will do the callback. New
1252 * threads going into the push will block. */
1253 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1254 "pad is in use, delay idle callback");
1255 GST_OBJECT_UNLOCK (pad);
1257 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1259 /* the pad is idle now, we can signal the idle callback now */
1260 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1261 "pad is idle, trigger idle callback");
1262 GST_OBJECT_UNLOCK (pad);
1264 callback (pad, &info, user_data);
1267 GST_OBJECT_UNLOCK (pad);
1273 cleanup_hook (GstPad * pad, GHook * hook)
1275 GstPadProbeType type;
1277 if (!G_HOOK_IS_VALID (hook))
1280 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1282 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1283 /* unblock when we remove the last blocking probe */
1285 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1287 if (pad->num_blocked == 0) {
1288 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1289 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1290 GST_PAD_BLOCK_BROADCAST (pad);
1293 g_hook_destroy_link (&pad->probes, hook);
1298 * gst_pad_remove_probe:
1299 * @pad: the #GstPad with the probe
1300 * @id: the probe id to remove
1302 * Remove the probe with @id from @pad.
1307 gst_pad_remove_probe (GstPad * pad, gulong id)
1311 g_return_if_fail (GST_IS_PAD (pad));
1313 GST_OBJECT_LOCK (pad);
1315 hook = g_hook_get (&pad->probes, id);
1319 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1321 cleanup_hook (pad, hook);
1322 GST_OBJECT_UNLOCK (pad);
1328 GST_OBJECT_UNLOCK (pad);
1329 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1335 * gst_pad_is_blocked:
1336 * @pad: the #GstPad to query
1338 * Checks if the pad is blocked or not. This function returns the
1339 * last requested state of the pad. It is not certain that the pad
1340 * is actually blocking at this point (see gst_pad_is_blocking()).
1342 * Returns: TRUE if the pad is blocked.
1347 gst_pad_is_blocked (GstPad * pad)
1349 gboolean result = FALSE;
1351 g_return_val_if_fail (GST_IS_PAD (pad), result);
1353 GST_OBJECT_LOCK (pad);
1354 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1355 GST_OBJECT_UNLOCK (pad);
1361 * gst_pad_is_blocking:
1362 * @pad: the #GstPad to query
1364 * Checks if the pad is blocking or not. This is a guaranteed state
1365 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1367 * Returns: TRUE if the pad is blocking.
1372 gst_pad_is_blocking (GstPad * pad)
1374 gboolean result = FALSE;
1376 g_return_val_if_fail (GST_IS_PAD (pad), result);
1378 GST_OBJECT_LOCK (pad);
1379 /* the blocking flag is only valid if the pad is not flushing */
1380 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1381 GST_OBJECT_UNLOCK (pad);
1387 * gst_pad_needs_reconfigure:
1388 * @pad: the #GstPad to check
1390 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1391 * if the flag was set.
1393 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1396 gst_pad_needs_reconfigure (GstPad * pad)
1398 gboolean reconfigure;
1400 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1402 GST_OBJECT_LOCK (pad);
1403 if (GST_PAD_IS_FLUSHING (pad)) {
1404 GST_DEBUG_OBJECT (pad, "pad is flushing");
1405 reconfigure = FALSE;
1407 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1408 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1410 GST_OBJECT_UNLOCK (pad);
1416 * gst_pad_check_reconfigure:
1417 * @pad: the #GstPad to check
1419 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1420 * if the flag was set.
1422 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1425 gst_pad_check_reconfigure (GstPad * pad)
1427 gboolean reconfigure;
1429 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1431 GST_OBJECT_LOCK (pad);
1432 if (GST_PAD_IS_FLUSHING (pad)) {
1433 GST_DEBUG_OBJECT (pad, "pad is flushing");
1434 reconfigure = FALSE;
1436 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1438 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1439 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1442 GST_OBJECT_UNLOCK (pad);
1448 * gst_pad_mark_reconfigure:
1449 * @pad: the #GstPad to mark
1451 * Mark a pad for needing reconfiguration. The next call to
1452 * gst_pad_check_reconfigure() will return %TRUE after this call.
1455 gst_pad_mark_reconfigure (GstPad * pad)
1457 g_return_if_fail (GST_IS_PAD (pad));
1459 GST_OBJECT_LOCK (pad);
1460 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1461 GST_OBJECT_UNLOCK (pad);
1465 * gst_pad_set_activate_function:
1467 * @f: the #GstPadActivateFunction to set.
1469 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1473 * gst_pad_set_activate_function_full:
1475 * @activate: the #GstPadActivateFunction to set.
1476 * @user_data: user_data passed to @notify
1477 * @notify: notify called when @activate will not be used anymore.
1479 * Sets the given activate function for @pad. The activate function will
1480 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1481 * Only makes sense to set on sink pads.
1483 * Call this function if your sink pad can start a pull-based task.
1486 gst_pad_set_activate_function_full (GstPad * pad,
1487 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1489 g_return_if_fail (GST_IS_PAD (pad));
1491 if (pad->activatenotify)
1492 pad->activatenotify (pad->activatedata);
1493 GST_PAD_ACTIVATEFUNC (pad) = activate;
1494 pad->activatedata = user_data;
1495 pad->activatenotify = notify;
1497 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1498 GST_DEBUG_FUNCPTR_NAME (activate));
1502 * gst_pad_set_activatemode_function:
1504 * @f: the #GstPadActivateModeFunction to set.
1506 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1510 * gst_pad_set_activatemode_function_full:
1512 * @activatemode: the #GstPadActivateModeFunction to set.
1513 * @user_data: user_data passed to @notify
1514 * @notify: notify called when @activatemode will not be used anymore.
1516 * Sets the given activate_mode function for the pad. An activate_mode function
1517 * prepares the element for data passing.
1520 gst_pad_set_activatemode_function_full (GstPad * pad,
1521 GstPadActivateModeFunction activatemode, gpointer user_data,
1522 GDestroyNotify notify)
1524 g_return_if_fail (GST_IS_PAD (pad));
1526 if (pad->activatemodenotify)
1527 pad->activatemodenotify (pad->activatemodedata);
1528 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1529 pad->activatemodedata = user_data;
1530 pad->activatemodenotify = notify;
1532 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1533 GST_DEBUG_FUNCPTR_NAME (activatemode));
1537 * gst_pad_set_chain_function:
1538 * @p: a sink #GstPad.
1539 * @f: the #GstPadChainFunction to set.
1541 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1545 * gst_pad_set_chain_function_full:
1546 * @pad: a sink #GstPad.
1547 * @chain: the #GstPadChainFunction to set.
1548 * @user_data: user_data passed to @notify
1549 * @notify: notify called when @chain will not be used anymore.
1551 * Sets the given chain function for the pad. The chain function is called to
1552 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1555 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1556 gpointer user_data, GDestroyNotify notify)
1558 g_return_if_fail (GST_IS_PAD (pad));
1559 g_return_if_fail (GST_PAD_IS_SINK (pad));
1561 if (pad->chainnotify)
1562 pad->chainnotify (pad->chaindata);
1563 GST_PAD_CHAINFUNC (pad) = chain;
1564 pad->chaindata = user_data;
1565 pad->chainnotify = notify;
1567 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1568 GST_DEBUG_FUNCPTR_NAME (chain));
1572 * gst_pad_set_chain_list_function:
1573 * @p: a sink #GstPad.
1574 * @f: the #GstPadChainListFunction to set.
1576 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1580 * gst_pad_set_chain_list_function_full:
1581 * @pad: a sink #GstPad.
1582 * @chainlist: the #GstPadChainListFunction to set.
1583 * @user_data: user_data passed to @notify
1584 * @notify: notify called when @chainlist will not be used anymore.
1586 * Sets the given chain list function for the pad. The chainlist function is
1587 * called to process a #GstBufferList input buffer list. See
1588 * #GstPadChainListFunction for more details.
1591 gst_pad_set_chain_list_function_full (GstPad * pad,
1592 GstPadChainListFunction chainlist, gpointer user_data,
1593 GDestroyNotify notify)
1595 g_return_if_fail (GST_IS_PAD (pad));
1596 g_return_if_fail (GST_PAD_IS_SINK (pad));
1598 if (pad->chainlistnotify)
1599 pad->chainlistnotify (pad->chainlistdata);
1600 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1601 pad->chainlistdata = user_data;
1602 pad->chainlistnotify = notify;
1604 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1605 GST_DEBUG_FUNCPTR_NAME (chainlist));
1609 * gst_pad_set_getrange_function:
1610 * @p: a source #GstPad.
1611 * @f: the #GstPadGetRangeFunction to set.
1613 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1617 * gst_pad_set_getrange_function_full:
1618 * @pad: a source #GstPad.
1619 * @get: the #GstPadGetRangeFunction to set.
1620 * @user_data: user_data passed to @notify
1621 * @notify: notify called when @get will not be used anymore.
1623 * Sets the given getrange function for the pad. The getrange function is
1624 * called to produce a new #GstBuffer to start the processing pipeline. see
1625 * #GstPadGetRangeFunction for a description of the getrange function.
1628 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1629 gpointer user_data, GDestroyNotify notify)
1631 g_return_if_fail (GST_IS_PAD (pad));
1632 g_return_if_fail (GST_PAD_IS_SRC (pad));
1634 if (pad->getrangenotify)
1635 pad->getrangenotify (pad->getrangedata);
1636 GST_PAD_GETRANGEFUNC (pad) = get;
1637 pad->getrangedata = user_data;
1638 pad->getrangenotify = notify;
1640 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1641 GST_DEBUG_FUNCPTR_NAME (get));
1645 * gst_pad_set_event_function:
1646 * @p: a #GstPad of either direction.
1647 * @f: the #GstPadEventFunction to set.
1649 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1653 * gst_pad_set_event_function_full:
1654 * @pad: a #GstPad of either direction.
1655 * @event: the #GstPadEventFunction to set.
1656 * @user_data: user_data passed to @notify
1657 * @notify: notify called when @event will not be used anymore.
1659 * Sets the given event handler for the pad.
1662 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1663 gpointer user_data, GDestroyNotify notify)
1665 g_return_if_fail (GST_IS_PAD (pad));
1667 if (pad->eventnotify)
1668 pad->eventnotify (pad->eventdata);
1669 GST_PAD_EVENTFUNC (pad) = event;
1670 pad->eventdata = user_data;
1671 pad->eventnotify = notify;
1673 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1674 GST_DEBUG_FUNCPTR_NAME (event));
1678 * gst_pad_set_query_function:
1679 * @p: a #GstPad of either direction.
1680 * @f: the #GstPadQueryFunction to set.
1682 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1686 * gst_pad_set_query_function_full:
1687 * @pad: a #GstPad of either direction.
1688 * @query: the #GstPadQueryFunction to set.
1689 * @user_data: user_data passed to @notify
1690 * @notify: notify called when @query will not be used anymore.
1692 * Set the given query function for the pad.
1695 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1696 gpointer user_data, GDestroyNotify notify)
1698 g_return_if_fail (GST_IS_PAD (pad));
1700 if (pad->querynotify)
1701 pad->querynotify (pad->querydata);
1702 GST_PAD_QUERYFUNC (pad) = query;
1703 pad->querydata = user_data;
1704 pad->querynotify = notify;
1706 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1707 GST_DEBUG_FUNCPTR_NAME (query));
1711 * gst_pad_set_iterate_internal_links_function:
1712 * @p: a #GstPad of either direction.
1713 * @f: the #GstPadIterIntLinkFunction to set.
1715 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1716 * for the user_data and notify.
1719 * gst_pad_set_iterate_internal_links_function_full:
1720 * @pad: a #GstPad of either direction.
1721 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1722 * @user_data: user_data passed to @notify
1723 * @notify: notify called when @iterintlink will not be used anymore.
1725 * Sets the given internal link iterator function for the pad.
1728 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1729 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1730 GDestroyNotify notify)
1732 g_return_if_fail (GST_IS_PAD (pad));
1734 if (pad->iterintlinknotify)
1735 pad->iterintlinknotify (pad->iterintlinkdata);
1736 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1737 pad->iterintlinkdata = user_data;
1738 pad->iterintlinknotify = notify;
1740 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1741 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1745 * gst_pad_set_link_function:
1747 * @f: the #GstPadLinkFunction to set.
1749 * Calls gst_pad_set_link_function_full() with NULL
1750 * for the user_data and notify.
1753 * gst_pad_set_link_function_full:
1755 * @link: the #GstPadLinkFunction to set.
1756 * @user_data: user_data passed to @notify
1757 * @notify: notify called when @link will not be used anymore.
1759 * Sets the given link function for the pad. It will be called when
1760 * the pad is linked with another pad.
1762 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1765 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1766 * cannot be made for some reason.
1768 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1769 * of the peer sink pad, if present.
1772 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1773 gpointer user_data, GDestroyNotify notify)
1775 g_return_if_fail (GST_IS_PAD (pad));
1777 if (pad->linknotify)
1778 pad->linknotify (pad->linkdata);
1779 GST_PAD_LINKFUNC (pad) = link;
1780 pad->linkdata = user_data;
1781 pad->linknotify = notify;
1783 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1784 GST_DEBUG_FUNCPTR_NAME (link));
1788 * gst_pad_set_unlink_function:
1790 * @f: the #GstPadUnlinkFunction to set.
1792 * Calls gst_pad_set_unlink_function_full() with NULL
1793 * for the user_data and notify.
1796 * gst_pad_set_unlink_function_full:
1798 * @unlink: the #GstPadUnlinkFunction to set.
1799 * @user_data: user_data passed to @notify
1800 * @notify: notify called when @unlink will not be used anymore.
1802 * Sets the given unlink function for the pad. It will be called
1803 * when the pad is unlinked.
1806 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1807 gpointer user_data, GDestroyNotify notify)
1809 g_return_if_fail (GST_IS_PAD (pad));
1811 if (pad->unlinknotify)
1812 pad->unlinknotify (pad->unlinkdata);
1813 GST_PAD_UNLINKFUNC (pad) = unlink;
1814 pad->unlinkdata = user_data;
1815 pad->unlinknotify = notify;
1817 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1818 GST_DEBUG_FUNCPTR_NAME (unlink));
1823 * @srcpad: the source #GstPad to unlink.
1824 * @sinkpad: the sink #GstPad to unlink.
1826 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1827 * signal on both pads.
1829 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1830 * the pads were not linked together.
1835 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1837 gboolean result = FALSE;
1838 GstElement *parent = NULL;
1840 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1841 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1842 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1843 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1845 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1846 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1847 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1849 /* We need to notify the parent before taking any pad locks as the bin in
1850 * question might be waiting for a lock on the pad while holding its lock
1851 * that our message will try to take. */
1852 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1853 if (GST_IS_ELEMENT (parent)) {
1854 gst_element_post_message (parent,
1855 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1856 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1858 gst_object_unref (parent);
1863 GST_OBJECT_LOCK (srcpad);
1864 GST_OBJECT_LOCK (sinkpad);
1866 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1867 goto not_linked_together;
1869 if (GST_PAD_UNLINKFUNC (srcpad)) {
1870 GstObject *tmpparent;
1872 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1874 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1875 RELEASE_PARENT (tmpparent);
1878 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1879 GstObject *tmpparent;
1881 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1883 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1884 RELEASE_PARENT (tmpparent);
1888 /* first clear peers */
1889 GST_PAD_PEER (srcpad) = NULL;
1890 GST_PAD_PEER (sinkpad) = NULL;
1892 GST_OBJECT_UNLOCK (sinkpad);
1893 GST_OBJECT_UNLOCK (srcpad);
1895 /* fire off a signal to each of the pads telling them
1896 * that they've been unlinked */
1897 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1898 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1900 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1901 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1906 if (parent != NULL) {
1907 gst_element_post_message (parent,
1908 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1909 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1910 gst_object_unref (parent);
1915 not_linked_together:
1917 /* we do not emit a warning in this case because unlinking cannot
1918 * be made MT safe.*/
1919 GST_OBJECT_UNLOCK (sinkpad);
1920 GST_OBJECT_UNLOCK (srcpad);
1926 * gst_pad_is_linked:
1927 * @pad: pad to check
1929 * Checks if a @pad is linked to another pad or not.
1931 * Returns: TRUE if the pad is linked, FALSE otherwise.
1936 gst_pad_is_linked (GstPad * pad)
1940 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1942 GST_OBJECT_LOCK (pad);
1943 result = (GST_PAD_PEER (pad) != NULL);
1944 GST_OBJECT_UNLOCK (pad);
1949 /* get the caps from both pads and see if the intersection
1952 * This function should be called with the pad LOCK on both
1956 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1957 GstPadLinkCheck flags)
1959 GstCaps *srccaps = NULL;
1960 GstCaps *sinkcaps = NULL;
1961 gboolean compatible = FALSE;
1963 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1966 /* Doing the expensive caps checking takes priority over only checking the template caps */
1967 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1968 GST_OBJECT_UNLOCK (sink);
1969 GST_OBJECT_UNLOCK (src);
1971 srccaps = gst_pad_query_caps (src, NULL);
1972 sinkcaps = gst_pad_query_caps (sink, NULL);
1974 GST_OBJECT_LOCK (src);
1975 GST_OBJECT_LOCK (sink);
1977 /* If one of the two pads doesn't have a template, consider the intersection
1979 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1980 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1984 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1986 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1989 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1991 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1994 /* if we have caps on both pads we can check the intersection. If one
1995 * of the caps is NULL, we return TRUE. */
1996 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1998 gst_caps_unref (srccaps);
2000 gst_caps_unref (sinkcaps);
2004 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2005 gst_caps_unref (srccaps);
2006 gst_caps_unref (sinkcaps);
2009 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2010 (compatible ? "" : "not"));
2015 /* check if the grandparents of both pads are the same.
2016 * This check is required so that we don't try to link
2017 * pads from elements in different bins without ghostpads.
2019 * The LOCK should be held on both pads
2022 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2024 GstObject *psrc, *psink;
2026 psrc = GST_OBJECT_PARENT (src);
2027 psink = GST_OBJECT_PARENT (sink);
2029 /* if one of the pads has no parent, we allow the link */
2030 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2033 /* only care about parents that are elements */
2034 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2035 goto no_element_parent;
2037 /* if the parents are the same, we have a loop */
2038 if (G_UNLIKELY (psrc == psink))
2041 /* if they both have a parent, we check the grandparents. We can not lock
2042 * the parent because we hold on the child (pad) and the locking order is
2043 * parent >> child. */
2044 psrc = GST_OBJECT_PARENT (psrc);
2045 psink = GST_OBJECT_PARENT (psink);
2047 /* if they have grandparents but they are not the same */
2048 if (G_UNLIKELY (psrc != psink))
2049 goto wrong_grandparents;
2056 GST_CAT_DEBUG (GST_CAT_CAPS,
2057 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2058 GST_PTR_FORMAT, psrc, psink);
2063 GST_CAT_DEBUG (GST_CAT_CAPS,
2064 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2065 GST_PTR_FORMAT, psrc, psink);
2070 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2076 GST_CAT_DEBUG (GST_CAT_CAPS,
2077 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2078 GST_PTR_FORMAT, psrc, psink);
2083 /* FIXME leftover from an attempt at refactoring... */
2084 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2085 * the two pads will be locked in the srcpad, sinkpad order. */
2086 static GstPadLinkReturn
2087 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2089 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2090 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2092 GST_OBJECT_LOCK (srcpad);
2094 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2095 goto src_was_linked;
2097 GST_OBJECT_LOCK (sinkpad);
2099 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2100 goto sink_was_linked;
2102 /* check hierarchy, pads can only be linked if the grandparents
2104 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2105 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2106 goto wrong_hierarchy;
2108 /* check pad caps for non-empty intersection */
2109 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2112 /* FIXME check pad scheduling for non-empty intersection */
2114 return GST_PAD_LINK_OK;
2118 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2119 GST_DEBUG_PAD_NAME (srcpad),
2120 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2121 /* we do not emit a warning in this case because unlinking cannot
2122 * be made MT safe.*/
2123 GST_OBJECT_UNLOCK (srcpad);
2124 return GST_PAD_LINK_WAS_LINKED;
2128 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2129 GST_DEBUG_PAD_NAME (sinkpad),
2130 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2131 /* we do not emit a warning in this case because unlinking cannot
2132 * be made MT safe.*/
2133 GST_OBJECT_UNLOCK (sinkpad);
2134 GST_OBJECT_UNLOCK (srcpad);
2135 return GST_PAD_LINK_WAS_LINKED;
2139 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2140 GST_OBJECT_UNLOCK (sinkpad);
2141 GST_OBJECT_UNLOCK (srcpad);
2142 return GST_PAD_LINK_WRONG_HIERARCHY;
2146 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2147 GST_OBJECT_UNLOCK (sinkpad);
2148 GST_OBJECT_UNLOCK (srcpad);
2149 return GST_PAD_LINK_NOFORMAT;
2155 * @srcpad: the source #GstPad.
2156 * @sinkpad: the sink #GstPad.
2158 * Checks if the source pad and the sink pad are compatible so they can be
2161 * Returns: TRUE if the pads can be linked.
2164 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2166 GstPadLinkReturn result;
2168 /* generic checks */
2169 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2170 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2172 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2173 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2175 /* gst_pad_link_prepare does everything for us, we only release the locks
2176 * on the pads that it gets us. If this function returns !OK the locks are not
2178 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2179 if (result != GST_PAD_LINK_OK)
2182 GST_OBJECT_UNLOCK (srcpad);
2183 GST_OBJECT_UNLOCK (sinkpad);
2186 return result == GST_PAD_LINK_OK;
2190 * gst_pad_link_full:
2191 * @srcpad: the source #GstPad to link.
2192 * @sinkpad: the sink #GstPad to link.
2193 * @flags: the checks to validate when linking
2195 * Links the source pad and the sink pad.
2197 * This variant of #gst_pad_link provides a more granular control on the
2198 * checks being done when linking. While providing some considerable speedups
2199 * the caller of this method must be aware that wrong usage of those flags
2200 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2201 * for more information.
2205 * Returns: A result code indicating if the connection worked or
2209 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2211 GstPadLinkReturn result;
2213 GstPadLinkFunction srcfunc, sinkfunc;
2215 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2216 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2217 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2218 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2219 GST_PAD_LINK_WRONG_DIRECTION);
2221 /* Notify the parent early. See gst_pad_unlink for details. */
2222 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2223 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2224 gst_element_post_message (parent,
2225 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2226 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2228 gst_object_unref (parent);
2233 /* prepare will also lock the two pads */
2234 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2236 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2239 /* must set peers before calling the link function */
2240 GST_PAD_PEER (srcpad) = sinkpad;
2241 GST_PAD_PEER (sinkpad) = srcpad;
2243 /* check events, when something is different, mark pending */
2244 schedule_events (srcpad, sinkpad);
2246 /* get the link functions */
2247 srcfunc = GST_PAD_LINKFUNC (srcpad);
2248 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2250 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2251 /* custom link functions, execute them */
2252 GST_OBJECT_UNLOCK (sinkpad);
2253 GST_OBJECT_UNLOCK (srcpad);
2256 GstObject *tmpparent;
2258 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2259 /* this one will call the peer link function */
2260 result = srcfunc (srcpad, tmpparent, sinkpad);
2261 RELEASE_PARENT (tmpparent);
2262 } else if (sinkfunc) {
2263 GstObject *tmpparent;
2265 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2266 /* if no source link function, we need to call the sink link
2267 * function ourselves. */
2268 result = sinkfunc (sinkpad, tmpparent, srcpad);
2269 RELEASE_PARENT (tmpparent);
2273 GST_OBJECT_LOCK (srcpad);
2274 GST_OBJECT_LOCK (sinkpad);
2276 /* we released the lock, check if the same pads are linked still */
2277 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2278 goto concurrent_link;
2280 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2283 GST_OBJECT_UNLOCK (sinkpad);
2284 GST_OBJECT_UNLOCK (srcpad);
2286 /* fire off a signal to each of the pads telling them
2287 * that they've been linked */
2288 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2289 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2291 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2292 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2294 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2297 if (G_LIKELY (parent)) {
2298 gst_element_post_message (parent,
2299 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2300 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2301 gst_object_unref (parent);
2309 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2310 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2311 GST_OBJECT_UNLOCK (sinkpad);
2312 GST_OBJECT_UNLOCK (srcpad);
2314 /* The other link operation succeeded first */
2315 result = GST_PAD_LINK_WAS_LINKED;
2320 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2321 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2323 GST_PAD_PEER (srcpad) = NULL;
2324 GST_PAD_PEER (sinkpad) = NULL;
2326 GST_OBJECT_UNLOCK (sinkpad);
2327 GST_OBJECT_UNLOCK (srcpad);
2335 * @srcpad: the source #GstPad to link.
2336 * @sinkpad: the sink #GstPad to link.
2338 * Links the source pad and the sink pad.
2340 * Returns: A result code indicating if the connection worked or
2346 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2348 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2352 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2354 GstPadTemplate **template_p;
2356 /* this function would need checks if it weren't static */
2358 GST_OBJECT_LOCK (pad);
2359 template_p = &pad->padtemplate;
2360 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2361 GST_OBJECT_UNLOCK (pad);
2364 gst_pad_template_pad_created (templ, pad);
2368 * gst_pad_get_pad_template:
2371 * Gets the template for @pad.
2373 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2374 * instantiated, or %NULL if this pad has no template. Unref after
2378 gst_pad_get_pad_template (GstPad * pad)
2380 GstPadTemplate *templ;
2382 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2384 templ = GST_PAD_PAD_TEMPLATE (pad);
2386 return (templ ? gst_object_ref (templ) : NULL);
2390 * gst_pad_has_current_caps:
2391 * @pad: a #GstPad to check
2393 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2395 * Returns: TRUE when @pad has caps associated with it.
2398 gst_pad_has_current_caps (GstPad * pad)
2403 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2405 GST_OBJECT_LOCK (pad);
2406 caps = get_pad_caps (pad);
2407 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2408 "check current pad caps %" GST_PTR_FORMAT, caps);
2409 result = (caps != NULL);
2410 GST_OBJECT_UNLOCK (pad);
2416 * gst_pad_get_current_caps:
2417 * @pad: a #GstPad to get the current capabilities of.
2419 * Gets the capabilities currently configured on @pad with the last
2420 * #GST_EVENT_CAPS event.
2422 * Returns: the current caps of the pad with incremented ref-count.
2425 gst_pad_get_current_caps (GstPad * pad)
2429 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2431 GST_OBJECT_LOCK (pad);
2432 if ((result = get_pad_caps (pad)))
2433 gst_caps_ref (result);
2434 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2435 "get current pad caps %" GST_PTR_FORMAT, result);
2436 GST_OBJECT_UNLOCK (pad);
2442 * gst_pad_get_pad_template_caps:
2443 * @pad: a #GstPad to get the template capabilities from.
2445 * Gets the capabilities for @pad's template.
2447 * Returns: (transfer full): the #GstCaps of this pad template.
2448 * Unref after usage.
2451 gst_pad_get_pad_template_caps (GstPad * pad)
2453 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2455 if (GST_PAD_PAD_TEMPLATE (pad))
2456 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2458 return gst_caps_ref (GST_CAPS_ANY);
2463 * @pad: a #GstPad to get the peer of.
2465 * Gets the peer of @pad. This function refs the peer pad so
2466 * you need to unref it after use.
2468 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2473 gst_pad_get_peer (GstPad * pad)
2477 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2479 GST_OBJECT_LOCK (pad);
2480 result = GST_PAD_PEER (pad);
2482 gst_object_ref (result);
2483 GST_OBJECT_UNLOCK (pad);
2489 * gst_pad_get_allowed_caps:
2492 * Gets the capabilities of the allowed media types that can flow through
2493 * @pad and its peer.
2495 * The allowed capabilities is calculated as the intersection of the results of
2496 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2497 * on the resulting caps.
2499 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2500 * caps when you no longer need it. This function returns NULL when @pad
2506 gst_pad_get_allowed_caps (GstPad * pad)
2512 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2514 GST_OBJECT_LOCK (pad);
2515 peer = GST_PAD_PEER (pad);
2516 if (G_UNLIKELY (peer == NULL))
2519 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2521 gst_object_ref (peer);
2522 GST_OBJECT_UNLOCK (pad);
2523 mycaps = gst_pad_query_caps (pad, NULL);
2525 caps = gst_pad_query_caps (peer, mycaps);
2526 gst_object_unref (peer);
2528 gst_caps_unref (mycaps);
2530 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2537 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2538 GST_OBJECT_UNLOCK (pad);
2545 * gst_pad_iterate_internal_links_default:
2546 * @pad: the #GstPad to get the internal links of.
2547 * @parent: the parent of @pad or NULL
2549 * Iterate the list of pads to which the given pad is linked to inside of
2550 * the parent element.
2551 * This is the default handler, and thus returns an iterator of all of the
2552 * pads inside the parent element with opposite direction.
2554 * The caller must free this iterator after use with gst_iterator_free().
2556 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2557 * returned pad with gst_object_unref().
2560 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2567 GstElement *eparent;
2569 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2571 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2572 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2574 GST_OBJECT_LOCK (pad);
2575 eparent = GST_PAD_PARENT (pad);
2576 if (!eparent || !GST_IS_ELEMENT (eparent))
2579 gst_object_ref (eparent);
2580 GST_OBJECT_UNLOCK (pad);
2583 if (pad->direction == GST_PAD_SRC)
2584 padlist = &eparent->sinkpads;
2586 padlist = &eparent->srcpads;
2588 GST_DEBUG_OBJECT (pad, "Making iterator");
2590 cookie = &eparent->pads_cookie;
2592 lock = GST_OBJECT_GET_LOCK (eparent);
2594 res = gst_iterator_new_list (GST_TYPE_PAD,
2595 lock, cookie, padlist, (GObject *) owner, NULL);
2597 gst_object_unref (owner);
2604 GST_OBJECT_UNLOCK (pad);
2605 GST_DEBUG_OBJECT (pad, "no parent element");
2611 * gst_pad_iterate_internal_links:
2612 * @pad: the GstPad to get the internal links of.
2614 * Gets an iterator for the pads to which the given pad is linked to inside
2615 * of the parent element.
2617 * Each #GstPad element yielded by the iterator will have its refcount increased,
2618 * so unref after use.
2620 * Free-function: gst_iterator_free
2622 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2623 * pad does not have an iterator function configured. Use
2624 * gst_iterator_free() after usage.
2627 gst_pad_iterate_internal_links (GstPad * pad)
2629 GstIterator *res = NULL;
2632 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2634 GST_OBJECT_LOCK (pad);
2635 ACQUIRE_PARENT (pad, parent, no_parent);
2636 GST_OBJECT_UNLOCK (pad);
2638 if (GST_PAD_ITERINTLINKFUNC (pad))
2639 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2641 RELEASE_PARENT (parent);
2648 GST_DEBUG_OBJECT (pad, "no parent");
2649 GST_OBJECT_UNLOCK (pad);
2657 * @forward: (scope call): a #GstPadForwardFunction
2658 * @user_data: user data passed to @forward
2660 * Calls @forward for all internally linked pads of @pad. This function deals with
2661 * dynamically changing internal pads and will make sure that the @forward
2662 * function is only called once for each pad.
2664 * When @forward returns TRUE, no further pads will be processed.
2666 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2669 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2672 gboolean result = FALSE;
2674 gboolean done = FALSE;
2675 GValue item = { 0, };
2676 GList *pushed_pads = NULL;
2678 iter = gst_pad_iterate_internal_links (pad);
2684 switch (gst_iterator_next (iter, &item)) {
2685 case GST_ITERATOR_OK:
2689 intpad = g_value_get_object (&item);
2691 /* if already pushed, skip. FIXME, find something faster to tag pads */
2692 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2693 g_value_reset (&item);
2697 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2698 GST_DEBUG_PAD_NAME (intpad));
2699 done = result = forward (intpad, user_data);
2701 pushed_pads = g_list_prepend (pushed_pads, intpad);
2703 g_value_reset (&item);
2706 case GST_ITERATOR_RESYNC:
2707 /* We don't reset the result here because we don't push the event
2708 * again on pads that got the event already and because we need
2709 * to consider the result of the previous pushes */
2710 gst_iterator_resync (iter);
2712 case GST_ITERATOR_ERROR:
2713 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2716 case GST_ITERATOR_DONE:
2721 g_value_unset (&item);
2722 gst_iterator_free (iter);
2724 g_list_free (pushed_pads);
2734 gboolean dispatched;
2738 event_forward_func (GstPad * pad, EventData * data)
2740 /* for each pad we send to, we should ref the event; it's up
2741 * to downstream to unref again when handled. */
2742 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2743 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2745 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2747 data->dispatched = TRUE;
2754 * gst_pad_event_default:
2755 * @pad: a #GstPad to call the default event handler on.
2756 * @parent: the parent of @pad or NULL
2757 * @event: (transfer full): the #GstEvent to handle.
2759 * Invokes the default event handler for the given pad.
2761 * The EOS event will pause the task associated with @pad before it is forwarded
2762 * to all internally linked pads,
2764 * The the event is sent to all pads internally linked to @pad. This function
2765 * takes ownership of @event.
2767 * Returns: TRUE if the event was sent successfully.
2770 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2772 gboolean result, forward = TRUE;
2774 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2775 g_return_val_if_fail (event != NULL, FALSE);
2777 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2780 switch (GST_EVENT_TYPE (event)) {
2781 case GST_EVENT_CAPS:
2782 forward = GST_PAD_IS_PROXY_CAPS (pad);
2793 data.dispatched = FALSE;
2794 data.result = FALSE;
2796 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2798 /* for sinkpads without a parent element or without internal links, nothing
2799 * will be dispatched but we still want to return TRUE. */
2800 if (data.dispatched)
2801 result = data.result;
2806 gst_event_unref (event);
2811 /* Default accept caps implementation just checks against
2812 * the allowed caps for the pad */
2814 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2816 /* get the caps and see if it intersects to something not empty */
2817 GstCaps *caps, *allowed;
2820 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2822 /* first forward the query to internally linked pads when we are dealing with
2824 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2825 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2830 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2831 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2833 gst_query_parse_accept_caps (query, &caps);
2834 allowed = gst_pad_query_caps (pad, caps);
2837 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2838 result = gst_caps_is_subset (caps, allowed);
2839 gst_caps_unref (allowed);
2841 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2844 gst_query_set_accept_caps_result (query, result);
2850 /* Default caps implementation */
2852 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2854 GstCaps *result = NULL, *filter;
2855 GstPadTemplate *templ;
2856 gboolean fixed_caps;
2858 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2861 /* first try to proxy if we must */
2862 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2863 if ((gst_pad_proxy_query_caps (pad, query))) {
2868 gst_query_parse_caps (query, &filter);
2870 /* no proxy or it failed, do default handling */
2871 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2873 GST_OBJECT_LOCK (pad);
2875 /* fixed caps, try the negotiated caps first */
2876 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2877 if ((result = get_pad_caps (pad)))
2878 goto filter_done_unlock;
2881 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2882 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2883 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2884 goto filter_done_unlock;
2888 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2889 "non-fixed pad caps: trying pad caps");
2890 /* non fixed caps, try the negotiated caps */
2891 if ((result = get_pad_caps (pad)))
2892 goto filter_done_unlock;
2895 /* this almost never happens */
2896 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2897 result = GST_CAPS_ANY;
2900 GST_OBJECT_UNLOCK (pad);
2902 /* run the filter on the result */
2904 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2905 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2906 GST_PTR_FORMAT, result, result, filter, filter);
2907 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2908 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2911 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2912 "using caps %p %" GST_PTR_FORMAT, result, result);
2913 result = gst_caps_ref (result);
2915 gst_query_set_caps_result (query, result);
2916 gst_caps_unref (result);
2926 gboolean dispatched;
2930 query_forward_func (GstPad * pad, QueryData * data)
2932 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2933 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2935 data->result |= gst_pad_peer_query (pad, data->query);
2937 data->dispatched = TRUE;
2939 /* stop on first successful reply */
2940 return data->result;
2944 * gst_pad_query_default:
2945 * @pad: a #GstPad to call the default query handler on.
2946 * @parent: the parent of @pad or NULL
2947 * @query: (transfer none): the #GstQuery to handle.
2949 * Invokes the default query handler for the given pad.
2950 * The query is sent to all pads internally linked to @pad. Note that
2951 * if there are many possible sink pads that are internally linked to
2952 * @pad, only one will be sent the query.
2953 * Multi-sinkpad elements should implement custom query handlers.
2955 * Returns: TRUE if the query was performed successfully.
2958 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2960 gboolean forward, ret = FALSE;
2962 switch (GST_QUERY_TYPE (query)) {
2963 case GST_QUERY_SCHEDULING:
2964 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2966 case GST_QUERY_ALLOCATION:
2967 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2969 case GST_QUERY_ACCEPT_CAPS:
2970 ret = gst_pad_query_accept_caps_default (pad, query);
2973 case GST_QUERY_CAPS:
2974 ret = gst_pad_query_caps_default (pad, query);
2977 case GST_QUERY_POSITION:
2978 case GST_QUERY_SEEKING:
2979 case GST_QUERY_FORMATS:
2980 case GST_QUERY_LATENCY:
2981 case GST_QUERY_JITTER:
2982 case GST_QUERY_RATE:
2983 case GST_QUERY_CONVERT:
2989 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2990 query, GST_QUERY_TYPE_NAME (query));
2996 data.dispatched = FALSE;
2997 data.result = FALSE;
2999 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3001 if (data.dispatched) {
3004 /* nothing dispatched, assume drained */
3005 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3015 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3017 GstPad *pad = data->pad;
3018 GstPadProbeInfo *info = data->info;
3019 GstPadProbeType type, flags;
3020 GstPadProbeCallback callback;
3021 GstPadProbeReturn ret;
3023 /* if we have called this callback, do nothing */
3024 if (PROBE_COOKIE (hook) == data->cookie) {
3025 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3026 "hook %lu, cookie %u already called", hook->hook_id,
3027 PROBE_COOKIE (hook));
3031 PROBE_COOKIE (hook) = data->cookie;
3033 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3036 /* one of the data types */
3037 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3039 /* one of the scheduling types */
3040 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3042 /* one of the blocking types must match */
3043 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3044 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3046 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3047 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3048 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3051 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3052 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3053 PROBE_COOKIE (hook), flags);
3055 data->marshalled = TRUE;
3057 callback = (GstPadProbeCallback) hook->func;
3058 if (callback == NULL)
3061 info->id = hook->hook_id;
3063 GST_OBJECT_UNLOCK (pad);
3065 ret = callback (pad, info, hook->data);
3067 GST_OBJECT_LOCK (pad);
3070 case GST_PAD_PROBE_REMOVE:
3071 /* remove the probe */
3072 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3073 cleanup_hook (pad, hook);
3075 case GST_PAD_PROBE_DROP:
3076 /* need to drop the data, make sure other probes don't get called
3078 GST_DEBUG_OBJECT (pad, "asked to drop item");
3079 info->type = GST_PAD_PROBE_TYPE_INVALID;
3080 data->dropped = TRUE;
3082 case GST_PAD_PROBE_PASS:
3083 /* inform the pad block to let things pass */
3084 GST_DEBUG_OBJECT (pad, "asked to pass item");
3087 case GST_PAD_PROBE_OK:
3088 GST_DEBUG_OBJECT (pad, "probe returned OK");
3091 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3098 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3099 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3100 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3105 /* a probe that does not take or return any data */
3106 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3108 if (G_UNLIKELY (pad->num_probes)) { \
3109 /* pass NULL as the data item */ \
3110 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3111 ret = do_probe_callbacks (pad, &info, defaultval); \
3112 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3117 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3119 if (G_UNLIKELY (pad->num_probes)) { \
3120 /* pass the data item */ \
3121 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3122 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3123 /* store the possibly updated data item */ \
3124 data = GST_PAD_PROBE_INFO_DATA (&info); \
3125 /* if something went wrong, exit */ \
3126 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3131 #define PROBE_PUSH(pad,mask,data,label) \
3132 PROBE_FULL(pad, mask, data, -1, -1, label);
3133 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3134 PROBE_FULL(pad, mask, data, offs, size, label);
3136 static GstFlowReturn
3137 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3138 GstFlowReturn defaultval)
3147 data.marshalled = FALSE;
3148 data.dropped = FALSE;
3149 data.cookie = ++pad->priv->probe_cookie;
3152 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3155 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3156 "do probes cookie %u", data.cookie);
3157 cookie = pad->priv->probe_list_cookie;
3159 g_hook_list_marshal (&pad->probes, TRUE,
3160 (GHookMarshaller) probe_hook_marshal, &data);
3162 /* if the list changed, call the new callbacks (they will not have their
3163 * cookie set to data.cookie */
3164 if (cookie != pad->priv->probe_list_cookie) {
3165 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3166 "probe list changed, restarting");
3170 /* the first item that dropped will stop the hooks and then we drop here */
3174 /* if no handler matched and we are blocking, let the item pass */
3175 if (!data.marshalled && is_block)
3178 /* At this point, all handlers returned either OK or PASS. If one handler
3179 * returned PASS, let the item pass */
3184 while (GST_PAD_IS_BLOCKED (pad)) {
3185 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3186 "we are blocked %d times", pad->num_blocked);
3188 /* we might have released the lock */
3189 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3192 /* now we block the streaming thread. It can be unlocked when we
3193 * deactivate the pad (which will also set the FLUSHING flag) or
3194 * when the pad is unblocked. A flushing event will also unblock
3195 * the pad after setting the FLUSHING flag. */
3196 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3197 "Waiting to be unblocked or set flushing");
3198 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3199 GST_PAD_BLOCK_WAIT (pad);
3200 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3201 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3203 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3213 GST_DEBUG_OBJECT (pad, "pad is flushing");
3214 return GST_FLOW_FLUSHING;
3218 GST_DEBUG_OBJECT (pad, "data is dropped");
3219 return GST_FLOW_CUSTOM_SUCCESS;
3223 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3224 GST_DEBUG_OBJECT (pad, "data is passed");
3232 * gst_pad_get_offset:
3235 * Get the offset applied to the running time of @pad. @pad has to be a source
3238 * Returns: the offset.
3241 gst_pad_get_offset (GstPad * pad)
3245 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3247 GST_OBJECT_LOCK (pad);
3248 result = pad->offset;
3249 GST_OBJECT_UNLOCK (pad);
3255 * gst_pad_set_offset:
3257 * @offset: the offset
3259 * Set the offset that will be applied to the running time of @pad.
3262 gst_pad_set_offset (GstPad * pad, gint64 offset)
3266 g_return_if_fail (GST_IS_PAD (pad));
3268 GST_OBJECT_LOCK (pad);
3269 /* if nothing changed, do nothing */
3270 if (pad->offset == offset)
3273 pad->offset = offset;
3274 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3276 /* sinkpads will apply their offset the next time a segment
3277 * event is received. */
3278 if (GST_PAD_IS_SINK (pad))
3281 /* resend the last segment event on next buffer push */
3282 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3283 ev->received = FALSE;
3284 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3288 GST_OBJECT_UNLOCK (pad);
3295 /* If TRUE and ret is not OK this means
3296 * that pushing the EOS event failed
3300 /* If called for an event this is
3301 * the event that would be pushed
3302 * next. Don't forward sticky events
3303 * that would come after that */
3307 /* should be called with pad LOCK */
3309 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3311 PushStickyData *data = user_data;
3312 GstEvent *event = ev->event;
3315 GST_DEBUG_OBJECT (pad, "event %s was already received",
3316 GST_EVENT_TYPE_NAME (event));
3320 /* If we're called because of an sticky event, only forward
3321 * events that would come before this new event and the
3323 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3324 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3325 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3326 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3328 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3329 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3332 switch (data->ret) {
3334 ev->received = TRUE;
3335 GST_DEBUG_OBJECT (pad, "event %s marked received",
3336 GST_EVENT_TYPE_NAME (event));
3338 case GST_FLOW_CUSTOM_SUCCESS:
3339 /* we can't assume the event is received when it was dropped */
3340 GST_DEBUG_OBJECT (pad, "event %s was dropped, 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_CUSTOM_SUCCESS_1:
3346 /* event was ignored and should be sent later */
3347 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3348 GST_EVENT_TYPE_NAME (event));
3349 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3350 data->ret = GST_FLOW_OK;
3352 case GST_FLOW_NOT_LINKED:
3353 /* not linked is not a problem, we are sticky so the event will be
3354 * sent later but only for non-EOS events */
3355 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3356 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3357 data->ret = GST_FLOW_OK;
3358 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3361 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3362 gst_flow_get_name (data->ret));
3363 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3367 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3368 data->was_eos = TRUE;
3370 return data->ret == GST_FLOW_OK;
3373 /* check sticky events and push them when needed. should be called
3375 static inline GstFlowReturn
3376 check_sticky (GstPad * pad, GstEvent * event)
3378 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3380 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3381 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3383 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3384 events_foreach (pad, push_sticky, &data);
3386 /* If there's an EOS event we must push it downstream
3387 * even if sending a previous sticky event failed.
3388 * Otherwise the pipeline might wait forever for EOS.
3390 * Only do this if pushing another event than the EOS
3393 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3394 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3396 if (ev && !ev->received) {
3397 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3398 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3399 /* the event could have been dropped. Because this can only
3400 * happen if the user asked for it, it's not an error */
3401 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3402 data.ret = GST_FLOW_OK;
3412 * @pad: a #GstPad to invoke the default query on.
3413 * @query: (transfer none): the #GstQuery to perform.
3415 * Dispatches a query to a pad. The query should have been allocated by the
3416 * caller via one of the type-specific allocation functions. The element that
3417 * the pad belongs to is responsible for filling the query with an appropriate
3418 * response, which should then be parsed with a type-specific query parsing
3421 * Again, the caller is responsible for both the allocation and deallocation of
3422 * the query structure.
3424 * Please also note that some queries might need a running pipeline to work.
3426 * Returns: TRUE if the query could be performed.
3429 gst_pad_query (GstPad * pad, GstQuery * query)
3432 gboolean res, serialized;
3433 GstPadQueryFunction func;
3434 GstPadProbeType type;
3437 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3438 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3440 if (GST_PAD_IS_SRC (pad)) {
3441 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3442 goto wrong_direction;
3443 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3444 } else if (GST_PAD_IS_SINK (pad)) {
3445 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3446 goto wrong_direction;
3447 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3449 goto unknown_direction;
3451 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3452 GST_QUERY_TYPE_NAME (query));
3454 serialized = GST_QUERY_IS_SERIALIZED (query);
3455 if (G_UNLIKELY (serialized))
3456 GST_PAD_STREAM_LOCK (pad);
3458 GST_OBJECT_LOCK (pad);
3459 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3460 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3461 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3463 ACQUIRE_PARENT (pad, parent, no_parent);
3464 GST_OBJECT_UNLOCK (pad);
3466 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3469 res = func (pad, parent, query);
3471 RELEASE_PARENT (parent);
3473 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3474 GST_QUERY_TYPE_NAME (query), res);
3479 GST_OBJECT_LOCK (pad);
3480 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3481 GST_OBJECT_UNLOCK (pad);
3483 if (G_UNLIKELY (serialized))
3484 GST_PAD_STREAM_UNLOCK (pad);
3491 g_warning ("pad %s:%s query %s in wrong direction",
3492 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3497 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3502 GST_DEBUG_OBJECT (pad, "had no parent");
3503 GST_OBJECT_UNLOCK (pad);
3504 if (G_UNLIKELY (serialized))
3505 GST_PAD_STREAM_UNLOCK (pad);
3510 GST_DEBUG_OBJECT (pad, "had no query function");
3511 RELEASE_PARENT (parent);
3512 if (G_UNLIKELY (serialized))
3513 GST_PAD_STREAM_UNLOCK (pad);
3518 GST_DEBUG_OBJECT (pad, "query failed");
3519 if (G_UNLIKELY (serialized))
3520 GST_PAD_STREAM_UNLOCK (pad);
3525 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3526 GST_OBJECT_UNLOCK (pad);
3527 if (G_UNLIKELY (serialized))
3528 GST_PAD_STREAM_UNLOCK (pad);
3530 /* if a probe dropped, we don't sent it further but assume that the probe
3531 * answered the query and return TRUE */
3532 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3542 * gst_pad_peer_query:
3543 * @pad: a #GstPad to invoke the peer query on.
3544 * @query: (transfer none): the #GstQuery to perform.
3546 * Performs gst_pad_query() on the peer of @pad.
3548 * The caller is responsible for both the allocation and deallocation of
3549 * the query structure.
3551 * Returns: TRUE if the query could be performed. This function returns %FALSE
3552 * if @pad has no peer.
3555 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3558 GstPadProbeType type;
3559 gboolean res, serialized;
3562 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3563 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3565 if (GST_PAD_IS_SRC (pad)) {
3566 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3567 goto wrong_direction;
3568 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3569 } else if (GST_PAD_IS_SINK (pad)) {
3570 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3571 goto wrong_direction;
3572 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3574 goto unknown_direction;
3576 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3577 GST_QUERY_TYPE_NAME (query));
3579 serialized = GST_QUERY_IS_SERIALIZED (query);
3581 GST_OBJECT_LOCK (pad);
3582 if (GST_PAD_IS_SRC (pad) && serialized) {
3583 /* all serialized queries on the srcpad trigger push of
3585 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3589 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3590 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3591 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3593 peerpad = GST_PAD_PEER (pad);
3594 if (G_UNLIKELY (peerpad == NULL))
3597 gst_object_ref (peerpad);
3598 GST_OBJECT_UNLOCK (pad);
3600 res = gst_pad_query (peerpad, query);
3602 gst_object_unref (peerpad);
3607 GST_OBJECT_LOCK (pad);
3608 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3609 GST_OBJECT_UNLOCK (pad);
3616 g_warning ("pad %s:%s query %s in wrong direction",
3617 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3622 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3627 GST_WARNING_OBJECT (pad, "could not send sticky events");
3628 GST_OBJECT_UNLOCK (pad);
3633 GST_INFO_OBJECT (pad, "pad has no peer");
3634 GST_OBJECT_UNLOCK (pad);
3639 GST_DEBUG_OBJECT (pad, "query failed");
3644 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3645 GST_OBJECT_UNLOCK (pad);
3647 /* if a probe dropped, we don't sent it further but assume that the probe
3648 * answered the query and return TRUE */
3649 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3658 /**********************************************************************
3659 * Data passing functions
3662 /* this is the chain function that does not perform the additional argument
3663 * checking for that little extra speed.
3665 static inline GstFlowReturn
3666 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3671 GST_PAD_STREAM_LOCK (pad);
3673 GST_OBJECT_LOCK (pad);
3674 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3677 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3680 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3683 #ifndef G_DISABLE_ASSERT
3684 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3686 ":%s:<%s:%s> Got data flow before stream-start event",
3687 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3689 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3691 ":%s:<%s:%s> Got data flow before segment event",
3692 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3696 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3698 PROBE_PUSH (pad, type, data, probe_stopped);
3700 parent = GST_OBJECT_PARENT (pad);
3701 GST_OBJECT_UNLOCK (pad);
3703 /* NOTE: we read the chainfunc unlocked.
3704 * we cannot hold the lock for the pad so we might send
3705 * the data to the wrong function. This is not really a
3706 * problem since functions are assigned at creation time
3707 * and don't change that often... */
3708 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3709 GstPadChainFunction chainfunc;
3711 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3714 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3715 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3716 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3718 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3720 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3721 "called chainfunction &%s with buffer %p, returned %s",
3722 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3724 GstPadChainListFunction chainlistfunc;
3726 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3729 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3730 "calling chainlistfunction &%s",
3731 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3733 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3735 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3736 "called chainlistfunction &%s, returned %s",
3737 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3740 GST_PAD_STREAM_UNLOCK (pad);
3747 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3748 "chaining, but pad was flushing");
3749 GST_OBJECT_UNLOCK (pad);
3750 GST_PAD_STREAM_UNLOCK (pad);
3751 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3752 return GST_FLOW_FLUSHING;
3756 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3757 GST_OBJECT_UNLOCK (pad);
3758 GST_PAD_STREAM_UNLOCK (pad);
3759 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3760 return GST_FLOW_EOS;
3764 g_critical ("chain on pad %s:%s but it was not in push mode",
3765 GST_DEBUG_PAD_NAME (pad));
3766 GST_OBJECT_UNLOCK (pad);
3767 GST_PAD_STREAM_UNLOCK (pad);
3768 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3769 return GST_FLOW_ERROR;
3773 GST_OBJECT_UNLOCK (pad);
3774 GST_PAD_STREAM_UNLOCK (pad);
3775 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3778 case GST_FLOW_CUSTOM_SUCCESS:
3779 GST_DEBUG_OBJECT (pad, "dropped buffer");
3783 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3790 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3791 g_critical ("chain on pad %s:%s but it has no chainfunction",
3792 GST_DEBUG_PAD_NAME (pad));
3793 GST_PAD_STREAM_UNLOCK (pad);
3794 return GST_FLOW_NOT_SUPPORTED;
3800 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3801 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3804 * Chain a buffer to @pad.
3806 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3808 * If the buffer type is not acceptable for @pad (as negotiated with a
3809 * preceeding GST_EVENT_CAPS event), this function returns
3810 * #GST_FLOW_NOT_NEGOTIATED.
3812 * The function proceeds calling the chain function installed on @pad (see
3813 * gst_pad_set_chain_function()) and the return value of that function is
3814 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3817 * In all cases, success or failure, the caller loses its reference to @buffer
3818 * after calling this function.
3820 * Returns: a #GstFlowReturn from the pad.
3825 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3827 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3828 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3829 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3831 return gst_pad_chain_data_unchecked (pad,
3832 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3835 static GstFlowReturn
3836 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3837 GstBufferList * list)
3843 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3845 len = gst_buffer_list_length (list);
3848 for (i = 0; i < len; i++) {
3849 buffer = gst_buffer_list_get (list, i);
3851 gst_pad_chain_data_unchecked (pad,
3852 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3853 gst_buffer_ref (buffer));
3854 if (ret != GST_FLOW_OK)
3857 gst_buffer_list_unref (list);
3863 * gst_pad_chain_list:
3864 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3865 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3868 * Chain a bufferlist to @pad.
3870 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3872 * If @pad was not negotiated properly with a CAPS event, this function
3873 * returns #GST_FLOW_NOT_NEGOTIATED.
3875 * The function proceeds calling the chainlist function installed on @pad (see
3876 * gst_pad_set_chain_list_function()) and the return value of that function is
3877 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3878 * chainlist function.
3880 * In all cases, success or failure, the caller loses its reference to @list
3881 * after calling this function.
3885 * Returns: a #GstFlowReturn from the pad.
3888 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3890 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3891 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3892 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3894 return gst_pad_chain_data_unchecked (pad,
3895 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3898 static GstFlowReturn
3899 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3904 GST_OBJECT_LOCK (pad);
3905 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3908 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3911 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3914 #ifndef G_DISABLE_ASSERT
3915 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3917 ":%s:<%s:%s> Got data flow before stream-start event",
3918 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3920 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3922 ":%s:<%s:%s> Got data flow before segment event",
3923 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3927 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3930 /* do block probes */
3931 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3933 /* recheck sticky events because the probe might have cause a relink */
3934 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3937 /* do post-blocking probes */
3938 PROBE_PUSH (pad, type, data, probe_stopped);
3940 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3943 /* take ref to peer pad before releasing the lock */
3944 gst_object_ref (peer);
3946 GST_OBJECT_UNLOCK (pad);
3948 ret = gst_pad_chain_data_unchecked (peer, type, data);
3950 gst_object_unref (peer);
3952 GST_OBJECT_LOCK (pad);
3954 if (pad->priv->using == 0) {
3955 /* pad is not active anymore, trigger idle callbacks */
3956 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3957 probe_stopped, ret);
3959 GST_OBJECT_UNLOCK (pad);
3963 /* ERROR recovery here */
3967 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3968 "pushing, but pad was flushing");
3969 GST_OBJECT_UNLOCK (pad);
3970 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3971 return GST_FLOW_FLUSHING;
3975 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3976 GST_OBJECT_UNLOCK (pad);
3977 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3978 return GST_FLOW_EOS;
3982 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3983 GST_DEBUG_PAD_NAME (pad));
3984 GST_OBJECT_UNLOCK (pad);
3985 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3986 return GST_FLOW_ERROR;
3990 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3991 "error pushing events, return %s", gst_flow_get_name (ret));
3992 GST_OBJECT_UNLOCK (pad);
3993 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3998 GST_OBJECT_UNLOCK (pad);
3999 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4002 case GST_FLOW_CUSTOM_SUCCESS:
4003 GST_DEBUG_OBJECT (pad, "dropped buffer");
4007 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4014 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4015 "pushing, but it was not linked");
4016 GST_OBJECT_UNLOCK (pad);
4017 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4018 return GST_FLOW_NOT_LINKED;
4024 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4025 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4028 * Pushes a buffer to the peer of @pad.
4030 * This function will call installed block probes before triggering any
4031 * installed data probes.
4033 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4034 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4037 * In all cases, success or failure, the caller loses its reference to @buffer
4038 * after calling this function.
4040 * Returns: a #GstFlowReturn from the peer pad.
4045 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4047 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4048 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4049 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4051 return gst_pad_push_data (pad,
4052 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4056 * gst_pad_push_list:
4057 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4058 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4061 * Pushes a buffer list to the peer of @pad.
4063 * This function will call installed block probes before triggering any
4064 * installed data probes.
4066 * The function proceeds calling the chain function on the peer pad and returns
4067 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4068 * be returned. If the peer pad does not have any installed chainlist function
4069 * every group buffer of the list will be merged into a normal #GstBuffer and
4070 * chained via gst_pad_chain().
4072 * In all cases, success or failure, the caller loses its reference to @list
4073 * after calling this function.
4075 * Returns: a #GstFlowReturn from the peer pad.
4080 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4082 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4083 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4084 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4086 return gst_pad_push_data (pad,
4087 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4090 static GstFlowReturn
4091 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4092 GstBuffer ** buffer)
4095 GstPadGetRangeFunction getrangefunc;
4099 GST_PAD_STREAM_LOCK (pad);
4101 GST_OBJECT_LOCK (pad);
4102 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4105 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4108 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4113 /* when one of the probes returns DROPPED, probe_stopped will be called
4114 * and we skip calling the getrange function, res_buf should then contain a
4115 * valid result buffer */
4116 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4117 res_buf, offset, size, probe_stopped);
4119 /* recheck sticky events because the probe might have cause a relink */
4120 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4123 ACQUIRE_PARENT (pad, parent, no_parent);
4124 GST_OBJECT_UNLOCK (pad);
4126 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4129 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4130 "calling getrangefunc %s, offset %"
4131 G_GUINT64_FORMAT ", size %u",
4132 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4134 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4136 RELEASE_PARENT (parent);
4138 if (G_UNLIKELY (ret != GST_FLOW_OK))
4139 goto get_range_failed;
4141 /* can only fire the signal if we have a valid buffer */
4142 GST_OBJECT_LOCK (pad);
4144 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4145 res_buf, offset, size, probe_stopped_unref);
4146 GST_OBJECT_UNLOCK (pad);
4148 GST_PAD_STREAM_UNLOCK (pad);
4157 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4158 "getrange, but pad was flushing");
4159 GST_OBJECT_UNLOCK (pad);
4160 GST_PAD_STREAM_UNLOCK (pad);
4161 return GST_FLOW_FLUSHING;
4165 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4166 GST_DEBUG_PAD_NAME (pad));
4167 GST_OBJECT_UNLOCK (pad);
4168 GST_PAD_STREAM_UNLOCK (pad);
4169 return GST_FLOW_ERROR;
4173 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4174 GST_OBJECT_UNLOCK (pad);
4175 GST_PAD_STREAM_UNLOCK (pad);
4180 GST_DEBUG_OBJECT (pad, "no parent");
4181 GST_OBJECT_UNLOCK (pad);
4182 GST_PAD_STREAM_UNLOCK (pad);
4183 return GST_FLOW_FLUSHING;
4187 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4188 GST_DEBUG_PAD_NAME (pad));
4189 RELEASE_PARENT (parent);
4190 GST_PAD_STREAM_UNLOCK (pad);
4191 return GST_FLOW_NOT_SUPPORTED;
4195 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4196 "probe returned %s", gst_flow_get_name (ret));
4197 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4199 /* the probe filled the buffer and asks us to not call the getrange
4200 * anymore, we continue with the post probes then. */
4201 GST_DEBUG_OBJECT (pad, "handled buffer");
4205 /* no buffer, we are EOS */
4206 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4210 GST_OBJECT_UNLOCK (pad);
4211 GST_PAD_STREAM_UNLOCK (pad);
4215 probe_stopped_unref:
4217 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4218 "probe returned %s", gst_flow_get_name (ret));
4219 /* if we drop here, it signals EOS */
4220 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4222 GST_OBJECT_UNLOCK (pad);
4223 GST_PAD_STREAM_UNLOCK (pad);
4224 if (*buffer == NULL)
4225 gst_buffer_unref (res_buf);
4230 GST_PAD_STREAM_UNLOCK (pad);
4231 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4232 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4233 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4239 * gst_pad_get_range:
4240 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4241 * @offset: The start offset of the buffer
4242 * @size: The length of the buffer
4243 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4244 * returns #GST_FLOW_ERROR if %NULL.
4246 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4247 * immediately and @buffer is %NULL.
4249 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4250 * description of a getrange function. If @pad has no getrange function
4251 * installed (see gst_pad_set_getrange_function()) this function returns
4252 * #GST_FLOW_NOT_SUPPORTED.
4254 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4255 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4256 * must be freed with gst_buffer_unref() after usage.
4258 * When @buffer points to a variable that points to a valid #GstBuffer, the
4259 * buffer will be filled with the result data when this function returns
4260 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4261 * @size bytes will be filled in the result buffer and its size will be updated
4264 * Note that less than @size bytes can be returned in @buffer when, for example,
4265 * an EOS condition is near or when @buffer is not large enough to hold @size
4266 * bytes. The caller should check the result buffer size to get the result size.
4268 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4269 * will be unchanged.
4271 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4273 * Returns: a #GstFlowReturn from the pad.
4278 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4279 GstBuffer ** buffer)
4281 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4282 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4283 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4284 g_return_val_if_fail (*buffer == NULL
4285 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4287 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4291 * gst_pad_pull_range:
4292 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4293 * @offset: The start offset of the buffer
4294 * @size: The length of the buffer
4295 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4296 * GST_FLOW_ERROR if %NULL.
4298 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4300 * This function will first trigger the pad block signal if it was
4303 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4304 * function returns the result of gst_pad_get_range() on the peer pad.
4305 * See gst_pad_get_range() for a list of return values and for the
4306 * semantics of the arguments of this function.
4308 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4309 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4310 * must be freed with gst_buffer_unref() after usage. When this function
4311 * returns any other result value, @buffer will still point to NULL.
4313 * When @buffer points to a variable that points to a valid #GstBuffer, the
4314 * buffer will be filled with the result data when this function returns
4315 * #GST_FLOW_OK. When this function returns any other result value,
4316 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4317 * @size bytes will be filled in the result buffer and its size will be updated
4320 * Note that less than @size bytes can be returned in @buffer when, for example,
4321 * an EOS condition is near or when @buffer is not large enough to hold @size
4322 * bytes. The caller should check the result buffer size to get the result size.
4324 * Returns: a #GstFlowReturn from the peer pad.
4329 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4330 GstBuffer ** buffer)
4336 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4337 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4338 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4339 g_return_val_if_fail (*buffer == NULL
4340 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4342 GST_OBJECT_LOCK (pad);
4343 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4346 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4351 /* when one of the probes returns DROPPED, probe_stopped will be
4352 * called and we skip calling the peer getrange function. *buffer should then
4353 * contain a valid buffer */
4354 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4355 res_buf, offset, size, probe_stopped);
4357 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4360 gst_object_ref (peer);
4362 GST_OBJECT_UNLOCK (pad);
4364 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4366 gst_object_unref (peer);
4368 GST_OBJECT_LOCK (pad);
4370 if (pad->priv->using == 0) {
4371 /* pad is not active anymore, trigger idle callbacks */
4372 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4373 probe_stopped_unref, ret);
4376 if (G_UNLIKELY (ret != GST_FLOW_OK))
4377 goto pull_range_failed;
4380 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4381 res_buf, offset, size, probe_stopped_unref);
4383 GST_OBJECT_UNLOCK (pad);
4389 /* ERROR recovery here */
4392 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4393 "pullrange, but pad was flushing");
4394 GST_OBJECT_UNLOCK (pad);
4395 return GST_FLOW_FLUSHING;
4399 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4400 GST_DEBUG_PAD_NAME (pad));
4401 GST_OBJECT_UNLOCK (pad);
4402 return GST_FLOW_ERROR;
4406 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4407 gst_flow_get_name (ret));
4408 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4410 /* the probe filled the buffer and asks us to not forward to the peer
4411 * anymore, we continue with the post probes then */
4412 GST_DEBUG_OBJECT (pad, "handled buffer");
4416 /* no buffer, we are EOS then */
4417 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4421 GST_OBJECT_UNLOCK (pad);
4426 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4427 "pulling range, but it was not linked");
4428 GST_OBJECT_UNLOCK (pad);
4429 return GST_FLOW_NOT_LINKED;
4433 GST_OBJECT_UNLOCK (pad);
4434 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4435 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4436 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4439 probe_stopped_unref:
4441 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4442 "post probe returned %s", gst_flow_get_name (ret));
4443 GST_OBJECT_UNLOCK (pad);
4444 /* if we drop here, it signals EOS */
4445 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4447 if (*buffer == NULL)
4448 gst_buffer_unref (res_buf);
4453 /* must be called with pad object lock */
4454 static GstFlowReturn
4455 store_sticky_event (GstPad * pad, GstEvent * event)
4460 gboolean res = FALSE;
4461 const gchar *name = NULL;
4462 gboolean insert = TRUE;
4464 type = GST_EVENT_TYPE (event);
4466 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4467 * otherwise they can be dropped and nothing would ever resend them.
4468 * Only do that for activated pads though, everything else is a bug!
4470 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4471 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4472 || type == GST_EVENT_EOS))))
4475 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4478 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4479 name = gst_structure_get_name (gst_event_get_structure (event));
4481 events = pad->priv->events;
4484 for (i = 0; i < len; i++) {
4485 PadEvent *ev = &g_array_index (events, PadEvent, i);
4487 if (ev->event == NULL)
4490 if (type == GST_EVENT_TYPE (ev->event)) {
4491 /* matching types, check matching name if needed */
4492 if (name && !gst_event_has_name (ev->event, name))
4496 if ((res = gst_event_replace (&ev->event, event)))
4497 ev->received = FALSE;
4503 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4504 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4505 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4506 * storing the sticky ordered we can check that this is respected. */
4507 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4508 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4510 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4511 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4512 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4513 gst_event_type_get_name (type));
4519 ev.event = gst_event_ref (event);
4520 ev.received = FALSE;
4521 g_array_insert_val (events, i, ev);
4526 pad->priv->events_cookie++;
4527 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4529 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4531 switch (GST_EVENT_TYPE (event)) {
4532 case GST_EVENT_CAPS:
4533 GST_OBJECT_UNLOCK (pad);
4535 GST_DEBUG_OBJECT (pad, "notify caps");
4536 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4538 GST_OBJECT_LOCK (pad);
4544 if (type == GST_EVENT_EOS)
4545 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4547 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4552 GST_DEBUG_OBJECT (pad, "pad is flushing");
4553 return GST_FLOW_FLUSHING;
4557 GST_DEBUG_OBJECT (pad, "pad is EOS");
4558 return GST_FLOW_EOS;
4563 * gst_pad_store_sticky_event:
4565 * @event: a #GstEvent
4567 * Store the sticky @event on @pad
4569 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4570 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4575 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4579 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4580 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4582 GST_OBJECT_LOCK (pad);
4583 ret = store_sticky_event (pad, event);
4584 GST_OBJECT_UNLOCK (pad);
4590 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4592 PushStickyData *data = user_data;
4594 /* Forward all sticky events before our current one that are pending */
4595 if (ev->event != data->event
4596 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4597 return push_sticky (pad, ev, data);
4602 /* should be called with pad LOCK */
4603 static GstFlowReturn
4604 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4605 GstPadProbeType type)
4609 GstEventType event_type;
4611 /* Two checks to be made:
4612 * . (un)set the FLUSHING flag for flushing events,
4613 * . handle pad blocking */
4614 event_type = GST_EVENT_TYPE (event);
4615 switch (event_type) {
4616 case GST_EVENT_FLUSH_START:
4617 GST_PAD_SET_FLUSHING (pad);
4619 GST_PAD_BLOCK_BROADCAST (pad);
4620 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4622 case GST_EVENT_FLUSH_STOP:
4623 GST_PAD_UNSET_FLUSHING (pad);
4625 /* Remove sticky EOS events */
4626 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4627 remove_event_by_type (pad, GST_EVENT_EOS);
4628 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4629 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4631 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4635 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4638 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4639 * checked already or this is called as part of pushing sticky events,
4640 * in which case we still want to forward the EOS event downstream.
4643 switch (GST_EVENT_TYPE (event)) {
4644 case GST_EVENT_SEGMENT:
4645 /* pass the adjusted segment event on. We need to do this even if
4646 * there is no peer pad because of the probes. */
4647 event = apply_pad_offset (pad, event);
4649 case GST_EVENT_RECONFIGURE:
4650 if (GST_PAD_IS_SINK (pad))
4651 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4656 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4657 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4662 /* send probes after modifying the events above */
4663 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4665 /* recheck sticky events because the probe might have cause a relink */
4666 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4667 && (GST_EVENT_IS_SERIALIZED (event)
4668 || GST_EVENT_IS_STICKY (event))) {
4669 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4670 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4672 /* Push all sticky events before our current one
4673 * that have changed */
4674 events_foreach (pad, sticky_changed, &data);
4677 /* now check the peer pad */
4678 peerpad = GST_PAD_PEER (pad);
4679 if (peerpad == NULL)
4682 gst_object_ref (peerpad);
4684 GST_OBJECT_UNLOCK (pad);
4686 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4687 event, GST_EVENT_TYPE_NAME (event), peerpad);
4689 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4691 /* Note: we gave away ownership of the event at this point but we can still
4692 * print the old pointer */
4693 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4694 event, peerpad, gst_flow_get_name (ret));
4696 gst_object_unref (peerpad);
4698 GST_OBJECT_LOCK (pad);
4700 if (pad->priv->using == 0) {
4701 /* pad is not active anymore, trigger idle callbacks */
4702 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4703 idle_probe_stopped, ret);
4707 /* ERROR handling */
4710 GST_DEBUG_OBJECT (pad, "We're flushing");
4711 gst_event_unref (event);
4712 return GST_FLOW_FLUSHING;
4716 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4717 gst_event_unref (event);
4720 case GST_FLOW_CUSTOM_SUCCESS:
4721 GST_DEBUG_OBJECT (pad, "dropped event");
4724 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4731 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4732 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4733 gst_event_unref (event);
4735 /* unlinked pads should not influence latency configuration */
4736 if (event_type == GST_EVENT_LATENCY)
4739 return GST_FLOW_NOT_LINKED;
4743 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4749 * gst_pad_push_event:
4750 * @pad: a #GstPad to push the event to.
4751 * @event: (transfer full): the #GstEvent to send to the pad.
4753 * Sends the event to the peer of the given pad. This function is
4754 * mainly used by elements to send events to their peer
4757 * This function takes owership of the provided event so you should
4758 * gst_event_ref() it if you want to reuse the event after this call.
4760 * Returns: TRUE if the event was handled.
4765 gst_pad_push_event (GstPad * pad, GstEvent * event)
4767 gboolean res = FALSE;
4768 GstPadProbeType type;
4769 gboolean sticky, serialized;
4771 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4772 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4774 if (GST_PAD_IS_SRC (pad)) {
4775 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4776 goto wrong_direction;
4777 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4778 } else if (GST_PAD_IS_SINK (pad)) {
4779 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4780 goto wrong_direction;
4781 /* events pushed on sinkpad never are sticky */
4782 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4784 goto unknown_direction;
4786 GST_OBJECT_LOCK (pad);
4787 sticky = GST_EVENT_IS_STICKY (event);
4788 serialized = GST_EVENT_IS_SERIALIZED (event);
4791 /* srcpad sticky events are stored immediately, the received flag is set
4792 * to FALSE and will be set to TRUE when we can successfully push the
4793 * event to the peer pad */
4794 switch (store_sticky_event (pad, event)) {
4795 case GST_FLOW_FLUSHING:
4803 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4804 /* all serialized or sticky events on the srcpad trigger push of
4806 res = (check_sticky (pad, event) == GST_FLOW_OK);
4811 /* other events are pushed right away */
4812 ret = gst_pad_push_event_unchecked (pad, event, type);
4813 /* dropped events by a probe are not an error */
4814 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4816 /* Errors in sticky event pushing are no problem and ignored here
4817 * as they will cause more meaningful errors during data flow.
4818 * For EOS events, that are not followed by data flow, we still
4819 * return FALSE here though.
4821 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4823 gst_event_unref (event);
4825 GST_OBJECT_UNLOCK (pad);
4829 /* ERROR handling */
4832 g_warning ("pad %s:%s pushing %s event in wrong direction",
4833 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4834 gst_event_unref (event);
4839 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4840 gst_event_unref (event);
4845 GST_DEBUG_OBJECT (pad, "We're flushing");
4846 GST_OBJECT_UNLOCK (pad);
4847 gst_event_unref (event);
4852 GST_DEBUG_OBJECT (pad, "We're EOS");
4853 GST_OBJECT_UNLOCK (pad);
4854 gst_event_unref (event);
4859 /* Check if we can call the event function with the given event */
4860 static GstFlowReturn
4861 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4865 switch (GST_EVENT_TYPE (event)) {
4866 case GST_EVENT_CAPS:
4868 /* backwards compatibility mode for caps */
4869 gst_event_parse_caps (event, &caps);
4871 if (!gst_pad_query_accept_caps (pad, caps))
4883 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4884 "caps %" GST_PTR_FORMAT " not accepted", caps);
4885 return GST_FLOW_NOT_NEGOTIATED;
4889 static GstFlowReturn
4890 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4891 GstPadProbeType type)
4894 GstEventType event_type;
4895 gboolean serialized, need_unlock = FALSE, sticky;
4896 GstPadEventFunction eventfunc;
4899 GST_OBJECT_LOCK (pad);
4900 if (GST_PAD_IS_SINK (pad))
4901 serialized = GST_EVENT_IS_SERIALIZED (event);
4904 sticky = GST_EVENT_IS_STICKY (event);
4905 event_type = GST_EVENT_TYPE (event);
4906 switch (event_type) {
4907 case GST_EVENT_FLUSH_START:
4908 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4909 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4911 /* can't even accept a flush begin event when flushing */
4912 if (GST_PAD_IS_FLUSHING (pad))
4915 GST_PAD_SET_FLUSHING (pad);
4916 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4918 case GST_EVENT_FLUSH_STOP:
4919 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4920 GST_PAD_UNSET_FLUSHING (pad);
4921 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4923 /* Remove pending EOS events */
4924 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4925 remove_event_by_type (pad, GST_EVENT_EOS);
4926 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4927 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4929 GST_OBJECT_UNLOCK (pad);
4930 /* grab stream lock */
4931 GST_PAD_STREAM_LOCK (pad);
4933 GST_OBJECT_LOCK (pad);
4934 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4937 case GST_EVENT_RECONFIGURE:
4938 if (GST_PAD_IS_SRC (pad))
4939 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4941 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4942 "have event type %" GST_PTR_FORMAT, event);
4944 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4948 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4951 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4952 GST_OBJECT_UNLOCK (pad);
4953 GST_PAD_STREAM_LOCK (pad);
4955 GST_OBJECT_LOCK (pad);
4956 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4959 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4963 switch (GST_EVENT_TYPE (event)) {
4964 case GST_EVENT_SEGMENT:
4965 event = apply_pad_offset (pad, event);
4973 /* now do the probe */
4975 type | GST_PAD_PROBE_TYPE_PUSH |
4976 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4978 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4980 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4983 ACQUIRE_PARENT (pad, parent, no_parent);
4984 GST_OBJECT_UNLOCK (pad);
4986 ret = pre_eventfunc_check (pad, event);
4987 if (G_UNLIKELY (ret != GST_FLOW_OK))
4988 goto precheck_failed;
4991 gst_event_ref (event);
4993 if (eventfunc (pad, parent, event)) {
4996 /* something went wrong */
4997 switch (event_type) {
4998 case GST_EVENT_CAPS:
4999 ret = GST_FLOW_NOT_NEGOTIATED;
5002 ret = GST_FLOW_ERROR;
5006 RELEASE_PARENT (parent);
5008 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5011 if (ret == GST_FLOW_OK) {
5012 GST_OBJECT_LOCK (pad);
5013 /* after the event function accepted the event, we can store the sticky
5014 * event on the pad */
5015 switch (store_sticky_event (pad, event)) {
5016 case GST_FLOW_FLUSHING:
5023 GST_OBJECT_UNLOCK (pad);
5025 gst_event_unref (event);
5029 GST_PAD_STREAM_UNLOCK (pad);
5033 /* ERROR handling */
5036 GST_OBJECT_UNLOCK (pad);
5038 GST_PAD_STREAM_UNLOCK (pad);
5039 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5040 "Received event on flushing pad. Discarding");
5041 gst_event_unref (event);
5042 return GST_FLOW_FLUSHING;
5046 GST_OBJECT_UNLOCK (pad);
5048 GST_PAD_STREAM_UNLOCK (pad);
5049 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5050 "Received event on EOS pad. Discarding");
5051 gst_event_unref (event);
5052 return GST_FLOW_EOS;
5056 GST_OBJECT_UNLOCK (pad);
5058 GST_PAD_STREAM_UNLOCK (pad);
5059 gst_event_unref (event);
5062 case GST_FLOW_CUSTOM_SUCCESS:
5063 GST_DEBUG_OBJECT (pad, "dropped event");
5067 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
5074 g_warning ("pad %s:%s has no event handler, file a bug.",
5075 GST_DEBUG_PAD_NAME (pad));
5076 GST_OBJECT_UNLOCK (pad);
5078 GST_PAD_STREAM_UNLOCK (pad);
5079 gst_event_unref (event);
5080 return GST_FLOW_NOT_SUPPORTED;
5084 GST_DEBUG_OBJECT (pad, "no parent");
5085 GST_OBJECT_UNLOCK (pad);
5087 GST_PAD_STREAM_UNLOCK (pad);
5088 gst_event_unref (event);
5089 return GST_FLOW_FLUSHING;
5093 GST_DEBUG_OBJECT (pad, "pre event check failed");
5094 RELEASE_PARENT (parent);
5096 GST_PAD_STREAM_UNLOCK (pad);
5097 gst_event_unref (event);
5103 * gst_pad_send_event:
5104 * @pad: a #GstPad to send the event to.
5105 * @event: (transfer full): the #GstEvent to send to the pad.
5107 * Sends the event to the pad. This function can be used
5108 * by applications to send events in the pipeline.
5110 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5111 * sink pad, @event should be a downstream event. For example, you would not
5112 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5113 * Furthermore, some downstream events have to be serialized with data flow,
5114 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5115 * the event needs to be serialized with data flow, this function will take the
5116 * pad's stream lock while calling its event function.
5118 * To find out whether an event type is upstream, downstream, or downstream and
5119 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5120 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5121 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5122 * plugin doesn't need to bother itself with this information; the core handles
5123 * all necessary locks and checks.
5125 * This function takes owership of the provided event so you should
5126 * gst_event_ref() it if you want to reuse the event after this call.
5128 * Returns: TRUE if the event was handled.
5131 gst_pad_send_event (GstPad * pad, GstEvent * event)
5134 GstPadProbeType type;
5136 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5137 g_return_val_if_fail (event != NULL, FALSE);
5139 if (GST_PAD_IS_SINK (pad)) {
5140 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5141 goto wrong_direction;
5142 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5143 } else if (GST_PAD_IS_SRC (pad)) {
5144 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5145 goto wrong_direction;
5146 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5148 goto unknown_direction;
5150 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5157 /* ERROR handling */
5160 g_warning ("pad %s:%s sending %s event in wrong direction",
5161 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5162 gst_event_unref (event);
5167 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5168 gst_event_unref (event);
5174 * gst_pad_set_element_private:
5175 * @pad: the #GstPad to set the private data of.
5176 * @priv: The private data to attach to the pad.
5178 * Set the given private data gpointer on the pad.
5179 * This function can only be used by the element that owns the pad.
5180 * No locking is performed in this function.
5183 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5185 pad->element_private = priv;
5189 * gst_pad_get_element_private:
5190 * @pad: the #GstPad to get the private data of.
5192 * Gets the private data of a pad.
5193 * No locking is performed in this function.
5195 * Returns: (transfer none): a #gpointer to the private data.
5198 gst_pad_get_element_private (GstPad * pad)
5200 return pad->element_private;
5204 * gst_pad_get_sticky_event:
5205 * @pad: the #GstPad to get the event from.
5206 * @event_type: the #GstEventType that should be retrieved.
5207 * @idx: the index of the event
5209 * Returns a new reference of the sticky event of type @event_type
5212 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5213 * event of @event_type was on @pad. Unref after usage.
5216 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5218 GstEvent *event = NULL;
5221 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5222 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5224 GST_OBJECT_LOCK (pad);
5225 ev = find_event_by_type (pad, event_type, idx);
5226 if (ev && (event = ev->event))
5227 gst_event_ref (event);
5228 GST_OBJECT_UNLOCK (pad);
5235 GstPadStickyEventsForeachFunction func;
5240 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5242 ForeachDispatch *data = user_data;
5243 gboolean ret = TRUE;
5246 GST_OBJECT_UNLOCK (pad);
5248 ret = data->func (pad, &ev->event, data->user_data);
5250 GST_OBJECT_LOCK (pad);
5257 * gst_pad_sticky_events_foreach:
5258 * @pad: the #GstPad that should be used for iteration.
5259 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5260 * should be called for every event.
5261 * @user_data: (closure): the optional user data.
5263 * Iterates all sticky events on @pad and calls @foreach_func for every
5264 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5267 gst_pad_sticky_events_foreach (GstPad * pad,
5268 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5270 ForeachDispatch data;
5272 g_return_if_fail (GST_IS_PAD (pad));
5273 g_return_if_fail (foreach_func != NULL);
5275 data.func = foreach_func;
5276 data.user_data = user_data;
5278 GST_OBJECT_LOCK (pad);
5279 events_foreach (pad, foreach_dispatch_function, &data);
5280 GST_OBJECT_UNLOCK (pad);
5284 do_stream_status (GstPad * pad, GstStreamStatusType type,
5285 GThread * thread, GstTask * task)
5289 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5291 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5292 if (GST_IS_ELEMENT (parent)) {
5293 GstMessage *message;
5294 GValue value = { 0 };
5296 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5297 gchar *tname, *ename, *pname;
5299 /* create a good task name */
5300 ename = gst_element_get_name (parent);
5301 pname = gst_pad_get_name (pad);
5302 tname = g_strdup_printf ("%s:%s", ename, pname);
5306 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5310 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5313 g_value_init (&value, GST_TYPE_TASK);
5314 g_value_set_object (&value, task);
5315 gst_message_set_stream_status_object (message, &value);
5316 g_value_unset (&value);
5318 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5319 gst_element_post_message (parent, message);
5321 gst_object_unref (parent);
5326 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5328 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5333 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5335 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5340 * gst_pad_start_task:
5341 * @pad: the #GstPad to start the task of
5342 * @func: the task function to call
5343 * @user_data: user data passed to the task function
5344 * @notify: called when @user_data is no longer referenced
5346 * Starts a task that repeatedly calls @func with @user_data. This function
5347 * is mostly used in pad activation functions to start the dataflow.
5348 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5349 * before @func is called.
5351 * Returns: a %TRUE if the task could be started.
5354 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5355 GDestroyNotify notify)
5360 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5361 g_return_val_if_fail (func != NULL, FALSE);
5363 GST_DEBUG_OBJECT (pad, "start task");
5365 GST_OBJECT_LOCK (pad);
5366 task = GST_PAD_TASK (pad);
5368 task = gst_task_new (func, user_data, notify);
5369 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5370 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5371 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5372 GST_INFO_OBJECT (pad, "created task %p", task);
5373 GST_PAD_TASK (pad) = task;
5374 gst_object_ref (task);
5375 /* release lock to post the message */
5376 GST_OBJECT_UNLOCK (pad);
5378 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5380 gst_object_unref (task);
5382 GST_OBJECT_LOCK (pad);
5383 /* nobody else is supposed to have changed the pad now */
5384 if (GST_PAD_TASK (pad) != task)
5385 goto concurrent_stop;
5387 res = gst_task_set_state (task, GST_TASK_STARTED);
5388 GST_OBJECT_UNLOCK (pad);
5395 GST_OBJECT_UNLOCK (pad);
5401 * gst_pad_pause_task:
5402 * @pad: the #GstPad to pause the task of
5404 * Pause the task of @pad. This function will also wait until the
5405 * function executed by the task is finished if this function is not
5406 * called from the task function.
5408 * Returns: a TRUE if the task could be paused or FALSE when the pad
5412 gst_pad_pause_task (GstPad * pad)
5417 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5419 GST_DEBUG_OBJECT (pad, "pause task");
5421 GST_OBJECT_LOCK (pad);
5422 task = GST_PAD_TASK (pad);
5425 res = gst_task_set_state (task, GST_TASK_PAUSED);
5426 GST_OBJECT_UNLOCK (pad);
5428 /* wait for task function to finish, this lock is recursive so it does nothing
5429 * when the pause is called from the task itself */
5430 GST_PAD_STREAM_LOCK (pad);
5431 GST_PAD_STREAM_UNLOCK (pad);
5437 GST_DEBUG_OBJECT (pad, "pad has no task");
5438 GST_OBJECT_UNLOCK (pad);
5444 * gst_pad_stop_task:
5445 * @pad: the #GstPad to stop the task of
5447 * Stop the task of @pad. This function will also make sure that the
5448 * function executed by the task will effectively stop if not called
5449 * from the GstTaskFunction.
5451 * This function will deadlock if called from the GstTaskFunction of
5452 * the task. Use gst_task_pause() instead.
5454 * Regardless of whether the pad has a task, the stream lock is acquired and
5455 * released so as to ensure that streaming through this pad has finished.
5457 * Returns: a TRUE if the task could be stopped or FALSE on error.
5460 gst_pad_stop_task (GstPad * pad)
5465 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5467 GST_DEBUG_OBJECT (pad, "stop task");
5469 GST_OBJECT_LOCK (pad);
5470 task = GST_PAD_TASK (pad);
5473 GST_PAD_TASK (pad) = NULL;
5474 res = gst_task_set_state (task, GST_TASK_STOPPED);
5475 GST_OBJECT_UNLOCK (pad);
5477 GST_PAD_STREAM_LOCK (pad);
5478 GST_PAD_STREAM_UNLOCK (pad);
5480 if (!gst_task_join (task))
5483 gst_object_unref (task);
5489 GST_DEBUG_OBJECT (pad, "no task");
5490 GST_OBJECT_UNLOCK (pad);
5492 GST_PAD_STREAM_LOCK (pad);
5493 GST_PAD_STREAM_UNLOCK (pad);
5495 /* this is not an error */
5500 /* this is bad, possibly the application tried to join the task from
5501 * the task's thread. We install the task again so that it will be stopped
5502 * again from the right thread next time hopefully. */
5503 GST_OBJECT_LOCK (pad);
5504 GST_DEBUG_OBJECT (pad, "join failed");
5505 /* we can only install this task if there was no other task */
5506 if (GST_PAD_TASK (pad) == NULL)
5507 GST_PAD_TASK (pad) = task;
5508 GST_OBJECT_UNLOCK (pad);
5515 * gst_pad_probe_info_get_event:
5516 * @info: a #GstPadProbeInfo
5518 * Returns: (transfer none): The #GstEvent from the probe
5522 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5524 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5525 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5527 return GST_PAD_PROBE_INFO_EVENT (info);
5532 * gst_pad_probe_info_get_query:
5533 * @info: a #GstPadProbeInfo
5535 * Returns: (transfer none): The #GstQuery from the probe
5539 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5541 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5542 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5544 return GST_PAD_PROBE_INFO_QUERY (info);
5548 * gst_pad_probe_info_get_buffer:
5549 * @info: a #GstPadProbeInfo
5551 * Returns: (transfer none): The #GstBuffer from the probe
5555 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5557 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5559 return GST_PAD_PROBE_INFO_BUFFER (info);
5563 * gst_pad_probe_info_get_bufferlist:
5564 * @info: a #GstPadProbeInfo
5566 * Returns: (transfer none): The #GstBufferlist from the probe
5570 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5572 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5574 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);